FlowGraphDifferentiator

public final class FlowGraphDifferentiator

Differentiator for the flow of control given as a FlowGraph.

Fields

debugPointsCounter

protected int debugPointsCounter

Counter used by BlockDifferentiator to number the various debug points.

keepEmptyDiffBlocks

protected boolean keepEmptyDiffBlocks

True when we are in a (debug) mode such that empty diff Blocks must be kept.

returnedVariable

protected Tree returnedVariable

For ADJOINT diff of a function Unit, communicates the new temporary variable used to hold the returned value. Variable is created in BlockDifferentiator, and used here.

toBranchVariable

protected TapPair<NewSymbolHolder, WrapperTypeSpec> toBranchVariable

Container for the NewSymbolHolder of the integer variable used to store the POP’ped branch, plus its future type.

toChunklengthVariable

protected TapList<NewSymbolHolder> toChunklengthVariable

Container for the NewSymbolHolder of the integer variable used to store the allocated size.

toChunkoldVariable

protected TapList<NewSymbolHolder> toChunkoldVariable

Container for the NewSymbolHolder of the address variable used to store the address allocated during the forward sweep.

toDiffchunkoldVariable

protected TapList<NewSymbolHolder> toDiffchunkoldVariable

Container for the NewSymbolHolder of the address variable used to store the DIFF address allocated during the forward sweep.

toFwdChunklengthVariable

protected TapList<NewSymbolHolder> toFwdChunklengthVariable

For ADJOINT_SPLIT_MODE, container for the NewSymbolHolder of the integer variable used to store the allocated size in the split FWD sweep. For other modes, this container is equal to toChunklengthVariable.

Constructors

FlowGraphDifferentiator

protected FlowGraphDifferentiator(DifferentiationEnv adEnv)

Methods

declareDiffIsReturnVar

protected void declareDiffIsReturnVar(VariableDecl returnVarDecl, Unit unit, Unit diffUnit)

differentiateProcedure

protected void differentiateProcedure()

Differentiate the procedure “unit”, i.e. for each differentiation mode required, fill the empty diffUnit that has been created (empty) beforehand.

differentiateSaveList

protected void differentiateSaveList(SymbolTable diffSymbolTable)

Differentiate Fortran save attributes.

Parameters
  • diffSymbolTable – curDiffUnit symbolTable.

getIterationsBetweenPushAndPop

protected TapList<LoopBlock> getIterationsBetweenPushAndPop(Block block)
Returns

the list of enclosing loops of the given “block” that will “separate” block_FWD and block_BWD, i.e. block_FWD and block_BWD will be each in its own separate nest of these loops, instead of both inside the same loop nest (which may happen e.g. if we reach an enclosing level which is checkpointed). Returned list is ordered, outermost loop first. Special case: when we reach the topmost FlowGraphLevel without having seen any checkpoint, then the returned list starts with a null.

initializeMultiDirMode

protected void initializeMultiDirMode()

Initialization if -multi option.

initializeMultiDirNumberMax

protected void initializeMultiDirNumberMax()

Prepare the NewSymbolHolder that contains variable “NBDirsMax” for the differentiated Unit “curDiffUnit”. This initialization will be done only once for each curDiffUnit.

instructionsOnDeclaredZones

protected TapList<Tree> instructionsOnDeclaredZones(Tree instrumentedSourceTree, SymbolTable srcSymbolTable, SymbolTable diffSymbolTable, String traceFuncPrefix, Unit diffUnit, BoolVector placeActiveZones, int[] map, boolean adaptForDD, boolean modifiesPrimal, boolean modifiesDiff, int lastDeclaredZone, Instruction returnInstr)

Build the list of the Trees of trace, debug, or initialization calls to be placed around the given instrumentedSourceTree (generally a call) for each active declared zone in the given symbolTable “srcSymbolTable”, all these trace etc calls starting with the given trace function name prefix “traceFuncPrefix”.

Parameters
  • instrumentedSourceTree – the source Tree of the differentiated Tree that we are instrumenting.

  • srcSymbolTable – the source SymbolTable of the instrumentedSourceTree

  • diffSymbolTable – the SymbolTable of the future created trees

  • placeActiveZones – the vector of all the zones that we want to instrument. This vector follows the numbering of the declared “diffKind” zones of the context/calling function.

  • modifiesPrimal – Pass “true” when the created operation needs to modify the primal variable.

  • modifiesDiff – Pass “true” when the created operation needs to modify the diff variable.

  • returnInstr – the return instruction, needed to find the returned expression.

Returns

the list of the Trees of trace, debug, or initialization calls for each active declared zone in the given symbolTable “srcSymbolTable”, all these calls starting with the given trace function name prefix “traceFuncPrefix”.

placeDebugADTests

protected Tree placeDebugADTests(Unit diffUnit, Tree callTree, BoolVector placeActiveZones, int[] map, int nature, SymbolTable srcSymbolTable, int lastDeclaredZone, String placeName, Instruction returnInstr, Tree okHere, Tree forcedOkHere)
Parameters
  • diffUnit – the differentiated Unit that contains the instrumented place

  • callTree – when the instrumented place is a call, this call.

  • nature – indicates the nature of the corresponding point in the original source, i.e. -1:sourceEntry ; 1:sourceExit ; -2:upstreamSourceCall ; 2:downstreamSourceCall ; 0:elsewhere

  • returnInstr – the return instruction.

Returns

the instrumentation Instructions for this nature of location and for this debug AD mode.