Block

public class Block

One Block of a Flow Graph. Blocks contain sequences of elementary instructions that are executed always in sequence from the first to the last. The last instruction may be a test which decides which Flow Arrow (FGArrow) is taken after the end of the Block’s execution. If the last instruction is not a test, then there may be only one flow arrow leaving from the Block.

Fields

analysisIsOutOfDate

public boolean analysisIsOutOfDate

Mark useful in any Data Flow analysis to write whether this Block must be analyzed again at next analysis sweep.

backReachDown

public boolean backReachDown

True iff the exit of this Block can reach exit

backReachUp

public boolean backReachUp

True iff the entry of this Block can reach exit

constantZones

public BoolVector constantZones

The zones that are constant from the beginning of this Block till the exit of the containing Unit. This info is filled by InOutAnalyzer.

controllers

public TapList<Block> controllers

The list of blocks controlling this block, from the most deeply nested up.

controllersZone

public TapIntList controllersZone

The list of the control zones controlling this block.

dominator

public BoolVector dominator

Vector of the ranks of the Blocks that are certainly executed before this one.

immediateDominator

protected Block immediateDominator

The closest Block certainly executed before this one.

immediatePostDominator

protected Block immediatePostDominator

The closest Block certainly executed after this one.

instructions

public TapList<Instruction> instructions

The ordered list of all instructions in this Block.

isFGCycleHead

public boolean isFGCycleHead

True if this Block has an incoming backFlow FGArrow that comes from a Block later or equal (i.e. with a greater or equal rank) in the DFST order.

isFGCycleTail

public boolean isFGCycleTail

True if this Block has an exiting flow FGArrow that goes to a Block earlier or equal (i.e. with a lower or equal rank) in the DFST order.

parallelControls

public TapList<Instruction> parallelControls

The controlling parallel instructions for this Block.

pointerInfosIn

public BoolMatrix pointerInfosIn

The matrix of pointer destinations at the begining of the block.

postDominator

public BoolVector postDominator

Vector of the ranks of the Blocks that are certainly executed after this one.

predecessor

public BoolVector predecessor

Vector of the ranks of the Blocks that are possibly executed before this one.

rank

public int rank

A unique rank of this Block. -1 is for the EntryBlock. Other Blocks are numbered from 0 up, in DFST order.

reachDown

public boolean reachDown

True iff the exit of this Block can be reached from entry

reachUp

public boolean reachUp

True iff the entry of this Block can be reached from entry

reachable

protected boolean reachable

True if this Block is reachable from the Unit’s entry. [llh 9Nov2023]: this info is apparently not used and is different from the info stored in “reachUp” and “reachDown”. Maybe we could use the methods from Unit.computeReachability() to refine our “reachUp” and “reachDown”, then remove computeReachability().

successor

public BoolVector successor

Vector of the ranks of the Blocks that are possibly executed after this one.

symbolTable

public SymbolTable symbolTable

The SymbolTable of symbols visible from this Block.

symbolicRk

public String symbolicRk

May be used to give a symbolic name to this Block. This name will be used when toString() shows this Block.

testZone

public int testZone

When this Blocks end with a test, the associated test zone.

unusedZones

public BoolVector unusedZones

The zones that are unused from the beginning of this Block till the exit of the containing Unit. This info is filled by InOutAnalyzer.

visit

protected int visit

CLEAR, VISITING or VISITED.

Constructors

Block

public Block(SymbolTable symbolTable, TapList<Instruction> parallelControls, TapList<Block> allBlocks)

Create an empty Block, set its SymbolTable, and register it into the list of created Blocks “allBlocks” (if nonempty).

Methods

addBackFlow

protected void addBackFlow(FGArrow arrow)

Adds the given arrow into the flow to this Block.

addFlow

protected void addFlow(FGArrow arrow)

Adds the given arrow into the flow from this Block.

addInstrDeclTl

public void addInstrDeclTl(TapList<Instruction> decls)

Adds instructions “decls” after the declarations in this Block.

addInstrDeclTlBeforeUse

public int addInstrDeclTlBeforeUse(Instruction instr, TapList<SymbolDecl> symbolDecls, TapList<Instruction> usageInstructions, SymbolTable declST, boolean strict)

Adds instruction “instr” after the declarations in this Block BUT before the declarations that depend on this declaration.

Parameters
  • symbolDecls – the symbols that the given “instr” declares or defines.

  • declST – The SymbolTable where the new “symbolDecls” will be.

  • strict – when true, vars in a COMMON must be declared before the COMMON.

Returns

when the instruction was moved some lines before its original location, to be before using declarations or computation instructions, returns the number of locations moved up. Otherwise returns 0.

addInstrHd

public void addInstrHd(Tree tree)

Adds a new Instruction with “tree” at the head of this Block.

addInstrHd

public void addInstrHd(Instruction instr)

Adds instruction “instr” at the head of this Block.

addInstrHdAfterDecls

public Instruction addInstrHdAfterDecls(Tree tree)

Adds a new Instruction with “tree” at the head of this Block BUT after the declarations.

Returns

the new Instruction created.

addInstrHdAfterDecls

public void addInstrHdAfterDecls(Instruction instr)

Adds instruction “instr” at the head of this Block BUT after the declarations.

addInstrHdIfNotPresent

public void addInstrHdIfNotPresent(Instruction instr)

Adds a new use statement Instruction at the head of this Block.

Parameters
  • instr – fortran use statement.

addInstrTl

public void addInstrTl(Tree instr)

Adds instruction tree “instr” at the end of this Block.

addInstrTl

public void addInstrTl(Instruction instr)

Adds instruction “instr” at the end of this Block.

addInstructionAt

public void addInstructionAt(Tree tree, int place)

Add inside this Block a new Instruction containing the given tree, at a location given by “place”. If place is positive or 0, location is counted from the head down, and 0 means before the 1st instruction. Too large place inserts at the tail. If place is negative, location is counted from the tail up, and -1 means after the last instruction. Too large (-)place inserts at head.

addTreeDeclTl

public static TapList<Tree> addTreeDeclTl(TapList<Tree> trees, TapList<Tree> decls)

Adds trees “decls” after the declarations in the list trees.

addUseDecl

public void addUseDecl(Tree tree)

Adds use declaration.

alreadyPresent

public boolean alreadyPresent(Instruction instr)
Returns

true if instr is already in this Block and is not in an include.

backFlow

public TapList<FGArrow> backFlow()
Returns

the list of all Flow Arrows arriving to this Block. For a LoopBlock, returns all FGArrows that leave some Block outside the LoopBlock to some Block inside the LoopBlock.

buildTemporaryVariable

public Tree buildTemporaryVariable(String name, Tree expr, SymbolTable targetSymbolTable, ToObject<NewSymbolHolder> toNSH, boolean reuse, TapList<NewSymbolHolder> excludedReuse, boolean declare, FunctionTypeSpec functionTypeSpec, int argRank, Tree refForHint)

Returns a temporary variable usable to split expression “expr” from this Instruction. This variable should be named after the given “name” (possibly extended as usual if conflicts with some existing variable). It is meant to contain the result of “expr”. This either reuses an existing temporary variable if available, or creates a new one and takes care of its declaration.

Parameters
  • name – The suggested name for the returned temporary variable.

  • expr – The expression that should be precomputed and assigned to the temporary variable.

  • targetSymbolTable – The SymbolTable where the future temporary variable will live.

  • toNSH – When passed non-null, a container that will contain upon return the NewSymbolHolder of the temporary variable.

  • reuse – If passed true, may return an already created temporary variable of same name and type.

  • excludedReuse – when reuse==true, a list of NewSymbolHolder’s that must not be reused here.

  • declare – If passed false, assume the variable is not yet used and needs no declaration. In doubt, pass true.

  • functionTypeSpec – In the case where “expr” is the actual argument or result of some procedure call, the type of this procedure. Else null.

  • argRank – When “expr” is the actual argument or result of some procedure call, the rank of this argument (from 1 up) or 0 when result. Else -1.

  • refForHint – When given non-null, some ref-expression whose dimensions are the same as “expr”, that can be useful to get better hints about the values of ISIZEnOF… dimension sizes.

Returns

The ref-expression Tree of the temporary variable.

checkUnusedDeclaration

public void checkUnusedDeclaration(Unit unit)

Remove instructions containing declaration of unused NewSymbolHolder.

Parameters
  • unit – current Unit.

cite

public void cite()

Prints a short reference to this Block onto TapEnv.curOutputStream().

Throws

citeFlowShort

protected String citeFlowShort()

coherence

protected void coherence()

containsInstructionTree

public boolean containsInstructionTree(Tree tree)

True if this Block already contains an Instruction with the given tree

containsNoCode

public boolean containsNoCode()

Returns true if this block contains no meaningful code, and therefore can be skipped See for instance in FlowGraphDifferentiator.allExitsTurn()

copyInstructions

public void copyInstructions(Block modelBlock, TapList<TapPair<Instruction, Instruction>> copiedIncludes)

Fills this Block with a copy of the modelBlock instructions. Instruction’s are copied too. Tree’s are copied.

copyIntoWithoutArrows

protected void copyIntoWithoutArrows(Block newBlock, TapList<TapPair<Instruction, Instruction>> alreadyCopiedMasks)

Places most elements of this Block into “newBlock”. Copies instructions, labels, rank, and where masks Doesn’t copy Flow Graph arrows. Uses “alreadyCopiedMasks” to make sure that copied whereMask’s keep equal (==) tests.

dump

public void dump(int indent)

Prints in detail the contents of this Block, onto TapEnv.curOutputStream().

Parameters
  • indent – the amount of indentation to be used for this printing.

Throws

dumpInstructions

protected final void dumpInstructions(int indent)

Dumps instructions of this Block.

Parameters
  • indent – indentation.

Throws

enclosedIn

public boolean enclosedIn(LoopBlock loopBlock)

enclosingBlock

protected Block enclosingBlock()

Very temporarily during FlowGraph building, enclosing may be only a Block.

enclosingLoop

public LoopBlock enclosingLoop()
Returns

the container Block in the hierarchy of nested loop Blocks.

enclosingLoops

public TapList<LoopBlock> enclosingLoops()
Returns

the list of all enclosing LoopBlock’s, from the inside out.

exchangeFlowArrowsTo

protected void exchangeFlowArrowsTo(Block dest1, Block dest2)

Exchanges the arrows that flow from current Block to Blocks “dest1” and “dest2”. This only affects operations that sweep all destinations from a block, that would now encounter the two destinations in the other order.

findRankToInsert

public int findRankToInsert(Tree fileTree, Tree tree)
Returns

rank to insert the declaration Tree “tree” after the declarations in this fileTree BUT before the declarations that depends on this declaration. [llh] TODO: I’m not sure this code is right, e.g. dependsOn() test wrongly ordered?

firstInstrAfterDecls

public Instruction firstInstrAfterDecls()
Returns

the first instruction of this Block which is not a declaration.

flow

public TapList<FGArrow> flow()
Returns

the list of all Flow Arrows leaving from this Block. For a LoopBlock, returns all FGArrows that leave some Block inside the LoopBlock to some Block outside the LoopBlock.

flowsOutOfScope

public boolean flowsOutOfScope(SymbolTable symbolTable)
Returns

true when this block flows to a Block that cannot see scope SymbolTable

flowsTo

public boolean flowsTo(Block dest)
Returns

true when there is a FGArrow from this Block to dest

getAssGotoInfoDone

public TapList<Block[]> getAssGotoInfoDone()

Gets the list of AssGotoInfo’s that have already been propagated through this Block.

getControlStruct

public ControlStruct getControlStruct()

Gets this Block’s Tree regeneration ControlStruct (using field “tmp1”).

getDominatorArrows

public BoolVector getDominatorArrows()

Gets this Block’s BoolVector of dominating FGArrow’s (using field “tmp3”).

getFGArrowTestCase

public FGArrow getFGArrowTestCase(int test, int oneCase)
Returns

the FGArrow from this Block and with the given test and case.

getFGArrowTo

public FGArrow getFGArrowTo(Block nextBlock)
Returns

the FGArrow from this Block to the given “nextBlock”.

getFinalGotoRank

public int getFinalGotoRank()

Gets the rank of the variable in the computed GOTO that terminates this block (using field “tmp2”). Must be -1 if no GOTO.

getLabelVariablesEffect

public Block[] getLabelVariablesEffect()
Returns

the effect of this Block with respect to AssGotoInfo’s.

getOperatorDeclarationInstruction

public Instruction getOperatorDeclarationInstruction(SymbolDecl symbolDecl, int operator, SymbolTable symbolTable)
Parameters
  • operator – == op_varDeclaration or op_typeDeclaration or op_interfaceDecl.

Returns

the varDeclaration or typeDeclaration or interfaceDecl Instruction that declares this symbolDecl in this Block.

getPosition

protected int getPosition()
Returns

the position of this Block in its textual file.

getStaticIterationIndices

public TapList<Tree> getStaticIterationIndices()

Same as Block.hasStaticIterationSpace(). For future use.

Returns

the TapList of all the loop indexes of the surrounding loops, which are all assumed of static length.

getStaticIterationSpace

public TapList<Integer> getStaticIterationSpace()

Same as Block.hasStaticIterationSpace(). For future use.

Returns

the TapList of all the enclosing iteration lengths, which are all assumed static.

hasCommentWith

public boolean hasCommentWith(String someText)

Returns true if this Block contains a comment with the given “someText”

hasDeclarationCommentStartingWith

public String hasDeclarationCommentStartingWith(String startString)

If this Block contains declarations and contains inside the declarations part a comment starting with startString, then returns the remaining of the comment. Otherwise returns null.

hasStaticIterationSpace

public boolean hasStaticIterationSpace()

For future use.

Returns

true if the control context of this block allows for a static saving of the tape, i.e. this block is either in the main stream, of inside a nest of loops that all have a static iteration space.

headInstr

public Instruction headInstr()
Returns

the first instruction in this Block.

insertBlockBefore

public void insertBlockBefore(Block block)

Inserts the given “block” before this Block in the Flow Graph. This requires that the given “block” does not end with a test.

isACleanDoLoop

public boolean isACleanDoLoop()
Returns

true if this Block “isALoop” and is the HeaderBlock of a normal DO-loop, which has no dirty jumps in or out of the loop.

isADoLoop

public boolean isADoLoop()
Returns

true if this block “isALoop” and is the Header of a DO-loop.

isALoop

public boolean isALoop()
Returns

true if this Block has a unique instruction which is an op_loop, used to control other Blocks. In particular returns false if it is an op_loop that already contains a body, which means it is a closed instruction that is equivalent in this Flow Graph to an atomic, simple instruction.

isANameSpace

public boolean isANameSpace()
Returns

true if the block terminates with a nameSpace, which is a “true” analyzed nameSpace, meaning that its contents are in the next Block(s).

isATimesLoop

public boolean isATimesLoop()
Returns

true if this block “isALoop” and is the Header of a TIMES-loop.

isAnIf

public boolean isAnIf()
Returns

true if the block terminates with an if test, which is a real “if” that controls the next choice in the control flow.

isControl

public boolean isControl()
Returns

true if this is a control block, i.e a block terminated by a control flow instruction. When this Block is a header, it is a control even if it has no LOOP:exit arrow.

isDoWithIndexUnusedAfterLoop

public boolean isDoWithIndexUnusedAfterLoop()
Returns

true if this is a standard DO loop HeaderBlock, marked as loopIndexUnusedAfterLoop. Do not test on the “enclosing” field, as this method is called on differentiated Blocks, for which the “enclosing” field has not been conputed

isOutsideFlow

public boolean isOutsideFlow()
Returns

true if this block that contains sub-units definitions is outside of the notion of control flow.

isParallelController

public boolean isParallelController()
Returns

true if this Block is the controller of a parallel region or loop e.g. $OMP PARALLEL.

isVarDeclaredInBlock

public boolean isVarDeclaredInBlock(SymbolDecl symbolDecl)

lastInstr

public Instruction lastInstr()
Returns

the last instruction in this Block.

lastTest

public int lastTest()
Returns

the op_code of the tail test of this Block If the last instruction of this block is a test, returns its op_code, otherwise returns -1.

listOfStatements

public TapList<Tree> listOfStatements()
Returns

an ordered list of all statements in this Block.

mergeWithSuccessor

protected void mergeWithSuccessor(Block nextBlock)

Merges current Block with successor “nextBlock”. The result is in the modified current Block.

newDeclarationsBlock

protected void newDeclarationsBlock(Block modelBlock)

When necessary, makes this current Block the new declarationsBlock of its SymbolTable. When “modelBlock” was the declarationsBlock of its own symbolTable, and assuming that “this” new Block is in fact a copy of “modelBlock”, then fills the “declarationsBlock” field of their symbolTable so that it points to “this” new block instead of to the old “modelBlock”.

origLabel

public String origLabel()
Returns

the label that may be attached to the first instruction of this Block.

removeAndShunt

public void removeAndShunt()

Removes this Block from its containing Flow Graph, redirecting all arrows flowing to it towards its unique flow destination. This requires that this Block has only one exiting flow arrow.

removeExternalInstr

protected void removeExternalInstr(SymbolDecl symbolDecl)

Removes external symbolDecl’s declaration-instruction from this Block.

removeInstr

public void removeInstr(Instruction instr)

Removes “instr” from this Block.

replaceInFlowGraph

protected final void replaceInFlowGraph(Block oldBlock)

Replaces oldBlock with this Block and updates all arrows.

Parameters
  • oldBlock – Block to replace.

seesAsShared

public boolean seesAsShared(String varName)

For future use.

Parameters
  • varName

setAssGotoInfoDone

public void setAssGotoInfoDone(TapList<Block[]> assGotoInfoDone)

Sets the list of AssGotoInfo’s that have already been propagated through this Block.

setBackFlow

protected final void setBackFlow(TapList<FGArrow> backFlow)

Set the list of all Flow Arrows arriving to this Block.

Parameters
  • backFlow – TapList of FGArrow.

setControlStruct

public void setControlStruct(ControlStruct controlStruct)

Sets this Block’s Tree regeneration ControlStruct (using field “tmp1”).

setDominatorArrows

protected void setDominatorArrows(BoolVector dominators)

Sets this Block’s BoolVector of dominating FGArrow’s (using field “tmp3”).

setEnclosingBlock

protected void setEnclosingBlock(Block enclosingBlock)

Very temporarily during FlowGraph building, enclosing may be only a Block.

setEnclosingBlockProtected

protected void setEnclosingBlockProtected(Block enclosingBlock)

Sets “enclosingBlock” as the header of the loop directly enclosing this Block. “enclosingBlock” may be a HeaderBlock or a BasicBlock. Protection: this setting is not done if the Block already has an enclosing loop and the new enclosing is not contained in the old enclosing.

setEnclosingLoop

public void setEnclosingLoop(LoopBlock enclosingLoop)

Sets the container Block in the hierarchy of nested loop Blocks.

setFinalGotoRank

public void setFinalGotoRank(int rank)

Sets the rank of the variable in the computed GOTO that terminates this block (using field “tmp2”). Must be -1 if no GOTO.

setFlow

protected final void setFlow(TapList<FGArrow> flow)

Set the list of all Flow Arrows leaving from this Block.

Parameters
  • flow – TapList of FGArrow.

setLabelVariablesEffect

public void setLabelVariablesEffect(Block[] effectAssGoto)

Sets the effect of this Block with respect to AssGotoInfo’s.

setOrigLabel

public void setOrigLabel(String label)

Set the label attached to the first instruction of this Block.

skipEmpty

protected void skipEmpty()

Removes current Block, because we assume it is empty. All flow arrows jump over it.

sortDeclarationsAndOperations

public void sortDeclarationsAndOperations()

splitInstructions

protected void splitInstructions(TapList<Instruction> beforeEntry, TapList<Instruction> beforeCycle)

Split instructions of this Block, e.g. to isolate subroutine and function calls.

symbolDeclDeclared

public TapList<SymbolDecl> symbolDeclDeclared(Instruction instruction)
Returns

the list of all SymbolDecl’s defined in Instruction.

symbolDeclDeclared

public TapList<SymbolDecl> symbolDeclDeclared(Tree tree, SymbolTable inSymbolTable)
Returns

the list of all SymbolDecl’s defined in Tree.

toString

public String toString()

typeCheck

protected void typeCheck(SymbolTable definitionSymbolTable)

TypeChecks this Block.

Parameters
  • definitionSymbolTable – SymbolTable used to typecheck this Block.

unit

public Unit unit()
Returns

the enclosingOrigUnit of this Block. May return null if Flow Graph is not finished building.