Instruction

public final class Instruction

Container for an atomic instruction in a Block in a Flow Graph.

Fields

block

public Block block

The basic block that contains this instruction.

directives

public TapList<Directive> directives

The list of Tapenade Directive’s attached to this instruction, if any.

isDifferentiated

public boolean isDifferentiated

Used during differentiation to mark that this instruction has been differentiated (Specific to AD).

isPhantom

public boolean isPhantom

Set “isPhantom” to true to ensure this Instruction will not be shown.

lineNo

public int lineNo

When not lost by parsing, the line number in the source file. 0 otherwise.

pointerDestsChanges

public TapList<TapPair<TapIntList, BoolVector>> pointerDestsChanges

List of all the modifications brought by this instruction on the current pointers destinations info. List of TapPair’s:

  • first : singleton TapIntList of pointer row index

  • second: BoolVector of the new possible destinations

postComments

public Tree postComments

The “line” comments after this instruction, e.g. comments starting with // and ending with newline.

postCommentsBlock

public Tree postCommentsBlock

The “block” comments after this instruction, which are comments starting with a special code and ending with another special code.

preComments

public Tree preComments

The “line” comments before this instruction, e.g. comments starting with // and ending with newline.

preCommentsBlock

public Tree preCommentsBlock

The “block” comments before this instruction, which are comments starting with a special code and ending with another special code.

syntaxController

public Instruction syntaxController

The deepest instruction syntactically around this instruction, if any. This is the control instruction of the deepest syntactic construct that contains this instruction.

tree

public Tree tree

The instruction’s Abstract Syntax Tree.

Constructors

Instruction

public Instruction()

Create an empty Instruction.

Instruction

public Instruction(Tree tree)

Create an Instruction containing the given tree.

Instruction

public Instruction(Tree tree, Instruction syntaxController)

Create an Instruction containing the given tree, also giving its syntactic controller.

Instruction

public Instruction(Tree tree, Instruction syntaxController, int lineNo)

Create an Instruction containing the given tree, also giving its syntactic controller and source code line number.

Instruction

public Instruction(Tree tree, Instruction syntaxController, Block block)

Create an Instruction containing the given tree, also giving its syntactic controller and containing Block.

Methods

addPreComments

public void addPreComments(String newComment)

Add the comment with text “newComment” in front of this instruction’s preComments.

appendPostComments

public void appendPostComments(TapList<Tree> newComments)

Add the given newComments after this instruction’s postComments.

appendPreComments

public void appendPreComments(TapList<Tree> newComments)

Add the given newComments after this instruction’s preComments.

containsPreComment

public String containsPreComment(String searched)

copy

public Instruction copy(TapList<TapPair<Instruction, Instruction>> alreadyCopiedMasks)
Returns

a copy of this instruction, making sure that the copy’s where mask is a copy of the instruction’s vectorial mask.

copyCommentsToTree

public void copyCommentsToTree(Tree tree)

Copy the comments that were stored in this Instruction, back as “Comments” annotations on the given tree

copyTreePlusComments

public Tree copyTreePlusComments()
Returns

a copy (ILUtils.copy()) of this instruction’s Tree, with all comments present on this instruction copied and attached to the root of the copy tree.

createUnitDefinitionStub

public static Instruction createUnitDefinitionStub(Unit definedUnit, Block containerBlock)
Returns

a new “unit definition stub” Instruction, used to mark the location of this Unit’s definition in the code.

createUnitDefinitionStubTree

public static Tree createUnitDefinitionStubTree(Unit definedUnit)
Returns

a new “unit definition stub” Tree, used to mark the location of the given Unit’s definition in the code.

declareIsMaskDefinition

protected void declareIsMaskDefinition()

States that this instruction is the one that sets the mask of a WHERE.

declaredSymbolDecls

public TapList<SymbolDecl> declaredSymbolDecls(SymbolTable publicSymbolTable, SymbolTable privateSymbolTable)
Returns

the list of all SymbolDecl’s declared by this Instruction.

declaresUnits

public TapList<Unit> declaresUnits(SymbolTable symbolTable)

differentiateChainedIncludes

public static Instruction differentiateChainedIncludes(Instruction includeInstr, String suffix, boolean wait)
Parameters
  • wait – When true, use the existing diff name if exists, but do not create it if it doesn’t exist.

  • suffix – The suffix used for differentiation. May be passed null when wait==true.

dump

public void dump()

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

encloseInWhereMask

public void encloseInWhereMask(InstructionMask enclosingWhereMask)

Connects enclosingWhereMask as an additional enclosing where mask around this Instruction (except if it has already been connected)

forceDiffInclude

public void forceDiffInclude(String suffix)

Modify TapEnv.differentiatedIncludeNames so that this include name will be differentiated in the generated code

fromInclude

public Instruction fromInclude()

When this instruction comes from an INCLUDE file.

Returns

the instruction that does the include.

fromIncludeCopy

public static Instruction fromIncludeCopy(Instruction fromIncludeInstr, boolean copy)
Returns

a copy of this.fromInclude.

fromIncludeRootName

public String fromIncludeRootName()

getPosition

public int getPosition()
Returns

the “position” of this instruction in the file it comes from.

getWhereMask

public InstructionMask getWhereMask()
Returns

the vectorial mask of this instruction. When the instruction is a where test, the returned vectorial mask does not include this where control.

hasCommentStartingWith

public static String hasCommentStartingWith(Tree comment, String startString)

hasCommentWith

public boolean hasCommentWith(String text)

hasCommentWith

public static boolean hasCommentWith(Tree comment, String text)

hasDirective

public Directive hasDirective(int kind)

Looks for a directive of the given kind attached to this instruction.

Parameters
  • kind – The searched kind of directive

Returns

The directive of the given kind, or null if not found.

hasPostCommentStartingWith

public String hasPostCommentStartingWith(String startString)

hasPreCommentStartingWith

public String hasPreCommentStartingWith(String startString)

isADeclaration

public boolean isADeclaration()
Returns

true if this instruction is a declaration statement.

isALoop

public boolean isALoop()
Returns

true if this instruction is loop control.

isANoOp

public boolean isANoOp()
Returns

true if this instruction is a no_op, i.e. a op_none, created only e.g. to hold some comments.

isAProcedure

public boolean isAProcedure()

isAWhereControl

public boolean isAWhereControl()
Returns

true if this instruction is a where control instruction.

isInStdCInclude

public boolean isInStdCInclude()

isInStdInclude

public boolean isInStdInclude()

isMaskDefinition

public boolean isMaskDefinition()
Returns

true when this instruction is the one that sets the mask of a WHERE.

isUnitDefinitionStub

public Unit isUnitDefinitionStub()

replaceTree

public Tree replaceTree(Tree oldTree, Tree newTree)

Replaces the given oldTree by the given newTree in-place inside the tree of this Instruction. Does nothing when newTree is null or equals oldTree. When necessary, the tree of this Instruction is itself modified.

Returns

the newTree.

setFromInclude

public void setFromInclude(Instruction incl)

setFromIncludeCopy

public void setFromIncludeCopy(Instruction origInclude, boolean copy)

Declare that this Instruction belongs to the include file “origInclude”.

setIncludeOfDiffInstructions

public void setIncludeOfDiffInstructions(Instruction primalInstruction, boolean primalIsRewritten, TapList<Instruction>[] diffInstructionSR, String suffix)

Decorates the given primalInstruction and each of diffInstructionS, with the “fromInclude” info built by differentiation of this Instruction (“this” Instruction is the “fromInclude” of the original non-differentiated instruction). Keeps track of the correspondence between non-diff and diff include file names through TapEnv.get().differentiatedIncludeNames.

Parameters
  • primalInstruction – the primal copy of the original source instruction

  • primalIsRewritten – true when the primal copy is created specifically for the diff code (e.g. foo_nodiff), instead of being just a reference to the source (e.g. foo)

  • diffInstructionSR – the (array of (replicas)) list of new differentiated instructions.

  • suffix – The suffix used for differentiation. May be passed null when this is called not for differentiation but during fixImplicits preliminary phase.

setInterfaceUnits

public void setInterfaceUnits(TapList<Unit> units)

Sets the interface Units associated to this interface declaration Instruction.

setPosition

public void setPosition(Instruction refInstr)

Sets the “position” of this instruction to the same as of refInstr.

setTree

public void setTree(Tree newTree)

Places newTree into this Instruction, and accordingly set annotation from newTree to Instruction

setWhereMask

public void setWhereMask(InstructionMask whereMask)

Sets a vectorial mask on this instruction.

syntaxControls

public boolean syntaxControls(Instruction controlled)
Returns

true if this instruction syntactically controls “controlled”.

thisCallIsCheckpointed

public boolean thisCallIsCheckpointed(Unit calledUnit)
Returns

true if this instruction is a call that must be checkpointed (aka “joint mode”)

toString

public String toString()

updateUnitDefinitionStub

public void updateUnitDefinitionStub(Unit definedUnit)

Update the given Instruction (which is a unit definition stub) so that it becomes a stub for this definedUnit.

usedUnits

public static TapList<Unit> usedUnits(Tree tree, TapList<Unit> collected, SymbolTable symbolTable)

whereMask

public InstructionMask whereMask()
Returns

the vectorial mask of this instruction, if any.

whereMaskDepth

public int whereMaskDepth()
Returns

the nesting depth of this instruction’s vectorial masks.