ILUtils

public final class ILUtils

IL Trees basic utility methods.

Methods

acceptsMultiDirDimension

public static boolean acceptsMultiDirDimension(Tree typeTree)

Same as TypeSpec.acceptMultiDirDimension(), but on the Tree that designates the type.

addAddressOf

public static Tree addAddressOf(Tree tree)

Places an op_address around “tree”, which must be a reference expression. Simplifies op_address(op_pointerAccess(tree, null)).

addAddressOfAtBase

public static Tree addAddressOfAtBase(Tree tree)

Inserts an op_address around the base op_ident of “tree”, which must be a reference expression.

addExpressionsNumConstants

public static Tree addExpressionsNumConstants(Tree left, Tree right)
Returns

the constant Tree sum of the two given constant Trees.

addListTreeInList

public static TapList<Tree> addListTreeInList(TapList<Tree> listTree, TapList<Tree> list)

addNumericalStrings

protected static String addNumericalStrings(String str1, boolean isStr1Opposed, String str2, boolean isStr2Opposed)

addPointerAccess

public static Tree addPointerAccess(Tree tree)

Places an op_pointerAccess around “tree”, which must be a pointer expression. Simplifies op_pointerAccess(op_address(tree), null).

addPointerAccessAtBase

public static Tree addPointerAccessAtBase(Tree tree)

Inserts an op_pointerAccess around the base op_ident of “tree”, which must be a reference expression.

addProtectedExprs

public static Tree addProtectedExprs(Tree factor1, Tree factor2)

Adds two factors, taking care of the case where any of them is protected (i.e. an ifExpression). A few examples:

Exp1 + Exp2                     → Exp1+Exp2
Exp1 + (T2?():Exp2)             → (T2?Exp1:Exp1+Exp2)
Exp1 + (T2?SExp2:Exp2)          → (T2?Exp1+SExp2:Exp1+Exp2)

addSchedule

public static void addSchedule(Tree schedule, Tree ompPragma)

Adds the given “schedule” clause to the (head of the) clauses of the given “ompPragma”.

addTree

public static Tree addTree(Tree tree1, Tree tree2)

addTreeInList

public static TapList<Tree> addTreeInList(Tree tree, TapList<Tree> list)

addVarIntoFuturePrivates

public static void addVarIntoFuturePrivates(NewSymbolHolder privateNSH, Tree pragma, boolean inFwd, boolean diff)

Assumes pragma is an OpenMP pragma. Adds privateNSH into the list of variables that must be added as “private”.

Parameters
  • privateNSH – the symbol holder of the future variable to declare private.

  • pragma – the OpenMP pragma source tree.

  • inFwd – when true, the private clause goes to the fwd differentiated pragma

  • diff – when true, the private clause will be about the variable’s derivative

addVarIntoFutureShareds

public static void addVarIntoFutureShareds(NewSymbolHolder sharedNSH, Tree pragma, boolean inFwd, boolean diff)

Same as addVarIntoFuturePrivates, but will create “omp shared” clauses

addVarIntoFutureSumReductions

public static void addVarIntoFutureSumReductions(NewSymbolHolder sumReductionNSH, Tree pragma)

Same as addVarIntoFuturePrivates, but will cause a REDUCTION(+:…)

adoptOrAppendComments

public static void adoptOrAppendComments(Tree commentsTree, String commentsString, Tree commentedTree)

appendComments

public static Tree appendComments(Tree comments1, Tree comments2)

appendComments

public static Tree appendComments(Tree oldComments, TapList<Tree> newComments, int operatorCode)

appendCommentsBlock

public static void appendCommentsBlock(Tree comments1, Tree comments2)

arrayTripletsInside

public static TapList<Tree> arrayTripletsInside(Tree tree)

arrayTypeToArrayDeclarator

public static Tree arrayTypeToArrayDeclarator(Tree tree)

Transforms a varDeclaration with arrayType into a varDeclaration with declarators with arrayDeclarator (fortran77 style).

Returns

the modified varDeclaration.

assignedLabel

public static String assignedLabel(Tree tree)
Returns

the label value assigned to the label var if “tree” is a “assignLabelVar” Tree.

assignedLabelVar

public static String assignedLabelVar(Tree tree)
Returns

the String of the label variable that is being assigned if “tree” is a “assignLabelVar” Tree.

assignedName

public static String assignedName(Tree tree)
Returns

the name of the variable that is being written if “tree” is an ILLang.op_assign Tree.

baseName

public static String baseName(Tree tree)

If “tree” is an expression ultimately referencing a variable name.

Returns

this name.

baseTree

public static Tree baseTree(Tree tree)
Returns

the op_ident Tree which is the root of expression “tree”.

baseTypeTree

public static Tree baseTypeTree(Tree tree)

build

public static Tree build(int opRank, int value)

build

public static Tree build(int opRank, String value)

build

public static Tree build(int opRank)

build

public static Tree build(int opRank, Tree son1)

build

public static Tree build(int opRank, Tree son1, Tree son2)

build

public static Tree build(int opRank, Tree son1, Tree son2, Tree son3)

build

public static Tree build(int opRank, Tree son1, Tree son2, Tree son3, Tree son4)

build

public static Tree build(int opRank, Tree son1, Tree son2, Tree son3, Tree son4, Tree son5)

build

public static Tree build(int opRank, Tree son1, Tree son2, Tree son3, Tree son4, Tree son5, Tree son6)

build

public static Tree build(int opRank, Tree son1, Tree son2, Tree son3, Tree son4, Tree son5, Tree son6, Tree son7)

build

public static Tree build(int opRank, Tree son1, Tree son2, Tree son3, Tree son4, Tree son5, Tree son6, Tree son7, Tree son8)

build

public static Tree build(int opRank, TapList<Tree> trees)

build

public static Tree build(int opRank, Tree[] trees)

buildArrayDeclarator

public static Tree buildArrayDeclarator(int language, Tree declTree, Tree typeTree)

buildArrayTripletAccess

public static Tree buildArrayTripletAccess(Tree array, Tree from, Tree to, int startIndex)
Returns

in general a new Tree array[from:to], except when array is itself an array section, in which case returns a copy of array, modified/combined with from:to at the right place.

buildCLoc

public static Tree buildCLoc(Tree expr, String cLoc)

buildCall

public static Tree buildCall(Tree object, Tree funcName, Tree arguments)

buildCall

public static Tree buildCall(Tree funcName, Tree arguments)

buildDimColon

public static Tree buildDimColon(int minIndex, Tree dimSize)
Returns

a dimColon given its size and index of first element.

buildExpressionOpposite

public static Tree buildExpressionOpposite(Tree tree)
Returns

the Tree opposite of a numerical expression.

buildInitAssign

public static Tree buildInitAssign(Tree doTree)

Given do header, build assignment.

Parameters
  • doTree – do header i=a,b,c"

Returns

assignment statement i:=a".

buildIterativeLength

public static int buildIterativeLength(Tree tree, SymbolTable symbolTable)
Returns

the number of successive individual atomic values in the list of expressions “tree”. If this length cannot be statically determined, return -1.

buildListIdents

public static TapList<Tree> buildListIdents(TapList<String> identNames)
Returns

a list of op_ident Tree’s, with the given identNames, and keeping the order.

buildNameInIdent

public static String buildNameInIdent(Tree tree)
Returns

a string that can be used in an identifier to represent the given reference Tree.

buildNameInText

public static String buildNameInText(Tree tree)
Returns

a printable string to represent the given reference Tree.

buildNumericalOpposite

public static Tree buildNumericalOpposite(Tree tree)
Returns

the Tree opposite of a numerical expression if it is easy, e.g. in particular when isNegativeExpression(tree) is true, null otherwise.

buildSingleStatement

public static Tree buildSingleStatement(TapList<Tree> statements)

When possible, turns the given ordered list of statements into a single statement. Reciprocal of getListOfStatements(). Should be refined if necessary.

buildSizeArgument1

public static Tree buildSizeArgument1(Tree tree, SymbolTable symbolTable)

used in size(…).

buildSizeTree

public static Tree buildSizeTree(Tree from, Tree to, Tree stride)
Returns

an expression Tree that evaluates to the size of this dimension (i.e. (to - from + stride)/stride or equivalently (to - from)/stride + 1 ).

buildSmartAddSub

public static Tree buildSmartAddSub(Tree leftTree, int factor, Tree rightTree)
Returns

a Tree that adds or substracts the two operands, with simplifications.

buildSmartMulDiv

public static Tree buildSmartMulDiv(Tree leftTree, int power, Tree rightTree)
Returns

a Tree that multiplies (power==1) or divides (power==-1) the two operands, with simplifications.

buildTypeName

public static String buildTypeName(Tree tree)

checkFunctionName

public static void checkFunctionName(FunctionDecl functionDecl, SymbolTable symbolTable)

cleanBoolCopy

public static Tree cleanBoolCopy(Tree boolTree, Unit diffUnit)

collectCommentStrings

public static TapList<Tree> collectCommentStrings(Tree commentsTree)

Because all the “appendComment*” methods are erratic on the tree nesting…, this method does a final flattening to make comments canonic.

collectCommentStrings

public static TapList<Tree> collectCommentStrings(TapList<Tree> commentsTrees)

collectIndexes

public static TapList<Tree> collectIndexes(Tree tree, TapList<Tree> indexes)

commentsToListReversed

public static TapList<Tree> commentsToListReversed(Tree commentsTree)

concatWithNull

public static Tree concatWithNull(Tree strTree)

contains

public static Tree contains(Tree tree, int operator, String value)

contains

public static boolean contains(Tree listTree, String value, boolean caseSensitive)
Parameters
  • listTree – is a list-arity Tree of atomic subtrees.

  • caseSensitive – when true, the string equality is case sensitive.

containsArrayDeclarator

public static boolean containsArrayDeclarator(SymbolDecl varDecl, Tree tree)

containsFunctionDeclarator

public static boolean containsFunctionDeclarator(Tree trees, String value)
Parameters
  • trees – is a tree-list of functionDeclarator subtrees.

containsModifier

public static boolean containsModifier(String value, Tree tree, boolean stopOnPointer)

Look if a modifier named “value” appears in this declaration Tree.

Parameters
  • value – The searched modifier. Belongs to {in, out, inout, constant, const, optional}

Returns

true if the modifier is found.

containsUnknownDimension

public static boolean containsUnknownDimension(Tree expr)
Returns

true if expression “expr” refers to an array without specifying its dimension. This means we don’t have enough information to e.g. traverse it or initialize it etc…

copiedSonsList

public static TapList<Tree> copiedSonsList(Tree tree)

copy

public static Tree copy(Tree tree)
Returns

a copy of the given “tree”. The original Tree and the copied Tree share their set of annotations. Each subtree annotated with a “NewSymbolHolder”, (i.e. the subtree might change later) is copied into a new subtree with the same “NewSymbolHolder”, and registered by this “NewSymbolHolder”. This way, when the “NewSymbolHolder” eventually decides on the final form of the subtree, the copied subtree will receive the final form too.

copyWatchingEqualsSubtrees

public static Tree copyWatchingEqualsSubtrees(Tree origTree, TapList<TapPair<Tree, Tree>> subTreeCopies)

Same as copyWatchingSubtrees, but tree equality tests are made with “.equals”.

Returns

the copied tree.

copyWatchingSubtrees

public static TapPair<Tree, TapList<TapPair<Tree, Tree>>> copyWatchingSubtrees(Tree origTree, TapList<TapPair<Tree, Tree>> subTreeCopies)

Builds a recursive copy of origTree, observing separately copied sub-trees given by “subTreeCopies”. The TapList “subTreeCopies” is a key-list of TapPair’s (Tree . Tree). For each sub-tree of origTree that appears as a key in subTreeCopies, this sub-tree is not copied, and instead the corresponding “value” tree is inserted into the copied tree. In the special case where the “value” Tree is null, a copy of the key-tree is inserted into the copied tree. This function builds also a new key-list, where the keys are the copies of the original key Trees. These copies are those who appear in the copied Tree. The values in this new key-list are null.

Returns

the TapPair of the copied Tree and the new key-list.

declaresVariable

public static boolean declaresVariable(Tree tree, String varName)
Returns

true if given “tree” is a varDeclaration that declares variable “varName”

disjointPath

public static boolean disjointPath(Tree exp1, Tree exp2)

Suppose that expressions exp1 and exp2 start from the same root variable.

Returns

true if the access path of exp1 and the access path of exp2 certainly lead to different memory locations.

divProtectedExprs

public static Tree divProtectedExprs(Tree factor1, Tree factor2)

Same as mulProtectedExprs, but makes a division.

dump

public static void dump(Tree tree, int indent)

Prints in detail the contents of the given IL tree, onto TapEnv.curOutputStream(). This printing may go on several lines, with indentation. This printing calls toStringRec() for single-line pieces of the tree.

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

eqOrDisjointRef

public static int eqOrDisjointRef(Tree tree1, Tree tree2, Instruction instr1, Instruction instr2)
Returns

DIFFERENT = -1 if the two trees certainly always refer to different memory cells, SAME = 1 if the two trees certainly always refer to the same memory cell, DOUBT = 0 otherwise, i.e. in case of doubt.

equalValues

public static boolean equalValues(Tree tree1, Tree tree2, Instruction instr1, Instruction instr2)

equalsInclude

public static boolean equalsInclude(String include, Tree tree)

evalsToGEZero

public static boolean evalsToGEZero(Tree tree)
Returns

true if “tree” is an expression with no variables, that evaluates (statically) to a value strictly positive.

evalsToGTZero

public static boolean evalsToGTZero(Tree tree)
Returns

true if “tree” is an expression with no variables, that evaluates (statically) to a value strictly positive.

evalsToLTZero

public static boolean evalsToLTZero(Tree tree)
Returns

true if “tree” is an expression with no variables, that evaluates (statically) to a value strictly negative.

evalsToMinusOne

public static boolean evalsToMinusOne(Tree tree)
Returns

true if “tree” is an expression with no variables, that evaluates (statically) to -1.

evalsToOne

public static boolean evalsToOne(Tree tree)
Returns

true if “tree” is an expression with no variables, that evaluates (statically) to 1.

evalsToZero

public static boolean evalsToZero(Tree tree)
Returns

true if “tree” is an expression with no variables, that evaluates (statically) to 0. ATTENTION CONVENTION: null Tree evaluates to zero !.

extractPrivateTrees

public static TapList<Tree> extractPrivateTrees(Tree pragma, SymbolTable usageST, boolean inFwd, boolean diff)

Assumes pragma is an OpenMP pragma.

Parameters
  • pragma – the OpenMP pragma source tree.

  • usageST – the scope of the place where the pragma is.

  • inFwd – when true, returns the trees for the fwd differentiated pragma

  • diff – when true, returns the trees that are meant to be differentiated

Returns

the list of Tree’s coming from the variables stored for private declaration. The stored list of variables stored to be private is then cleared. Since this list has been accumulated with the latest first, we can reverse it again upon rebuild.

extractSharedTrees

public static TapList<Tree> extractSharedTrees(Tree pragma, SymbolTable usageST, boolean inFwd, boolean diff)

Same as extractPrivateTrees, but extracts the future SHARED variables

extractSumReductionTrees

public static TapList<Tree> extractSumReductionTrees(Tree pragma, SymbolTable usageST)

Same as extractPrivateTrees, but extracts the future REDUCTION(+:…) diff variables

findArrayTriplet

public static Tree findArrayTriplet(Tree expr)

When the given expression “expr” is of array type and this type comes from that of an arrayTriplet inside “expr”, returns this arrayTriplet access (normalized?) Otherwise returns null

findDimColons

public static Tree findDimColons(Tree tree)
Parameters
  • tree – is a varDeclaration Tree.

findRankOfDeclarator

public static int findRankOfDeclarator(Tree tree, String symbol)
Parameters
  • tree – is a declarators Tree or a varDimDeclaration.

findSizeofCall

public static Tree findSizeofCall(Tree expression)

getAllocatedRef

public static Tree getAllocatedRef(Tree accessTree)

getArguments

public static Tree getArguments(Tree callTree)
Returns

the actual arguments of this method or function call.

getBindCValue

public static String getBindCValue(Tree tree, int rank)
Parameters
  • tree – is an accessDecl Tree

  • rank – of declared variable

Returns

FORTRAN_NAME if tree== accessDecl(accessDecl(ident:bind, expressions[ident:c]), expressions[ident:FORTRAN_NAME]) or return C_NAME if tree == accessDecl(accessDecl(ident:bind, expressions[ident:c, nameEq(ident:name, C_NAME)]), expressions[ident:FORTRAN_NAME]). [llh 12Dec2022] TODO: make this method cleaner and more general, or remove if not used any more.

getCall

public static Tree getCall(Tree tree)
Returns

tree if tree is a call, tree.down(2) if tree is a call to a function with a return value assignment, and null otherwise.

getCallFunctionNameString

public static String getCallFunctionNameString(Tree callTree)
Returns

the name of the called function when “callTree” is a procedure, function, method or constructor call.

getCalledName

public static Tree getCalledName(Tree callTree)
Returns

the name Tree of the called method or function.

getCalledNameString

public static String getCalledNameString(Tree callTree)
Returns

the name String of the called method or function.

getClassNameString

public static String getClassNameString(Tree constructorCallTree)

getFieldRank

public static int getFieldRank(Tree field)

Assuming that “field” is the ident tree that designates a record field,

Returns

the conventional rank of this field, that has been stored here during type-checking. This rank starts at 0 for the first field. In case this rank is not defined, returns -1.

getIdentString

public static String getIdentString(Tree tree)

if “tree” is an op_ident, returns its string.

Returns

the String, otherwise returns null.

getLineNumber

public static int getLineNumber(Tree tree)
Returns

the line number or 0 if there is no line number accessible.

getListOfStatements

public static TapList<Tree> getListOfStatements(Tree tree)

When possible, extracts a list of ordered atomic statements from tree. Reciprocal of buildSingleStatement(). Should be refined if necessary.

getModulesFromInterfaceDecl

public static TapList<String> getModulesFromInterfaceDecl(Tree tree)
Returns

a TapList of module names used by the op_interfaceDecl Tree.

getNamedElement

public static Tree getNamedElement(Tree listOfElements, String name)

If the given listOfElements contains a child of the form nameEq(“name”,”value”), returns this “value”. Otherwise returns null.

getObject

public static Tree getObject(Tree callTree)
Returns

the object on which this method is called.

getOptionalDim

public static Tree getOptionalDim(Tree[] srcParamExprs, SymbolTable symbolTable)
Returns

the optional “dim” argument of a F90 SUM. Returns null when no dim is present.

getOptionalMask

public static Tree getOptionalMask(Tree[] srcParamExprs, SymbolTable symbolTable)
Returns

the optional “mask” argument of a F90 SUM. Returns null when no mask is present.

getPosition

public static int getPosition(Tree tree)

getRemoveSchedule

public static Tree getRemoveSchedule(Tree ompPragma)

If “ompPragma” contains a “schedule” clause.

Returns

the “schedule” clause and removes it from “ompPragma”.

getUnitName

public static String getUnitName(Tree tree)

gotoLabelVar

public static String gotoLabelVar(Tree tree)
Returns

the String of the label variable that is used if “tree” is a “gotoLabelVar” Tree.

hasATypeOperator

public static boolean hasATypeOperator(Tree tree)

hasDuplicableLastIndex

public static Tree hasDuplicableLastIndex(Tree doLoopControl, boolean exit)
Returns

the expression tree that computes the last (if “exit” is false) or the exit value (if “exit” is true) of the index of a do-loop. @return null when this expression contains side-effets and therefore cannot be executed twice without risk.

hasFortran90Modifiers

public static boolean hasFortran90Modifiers(Tree tree)

hasInitializations

public static boolean hasInitializations(Tree tree)

hasTwoLevelIndex

public static boolean hasTwoLevelIndex(Tree indices, SymbolTable symbolTable)

Detects that some index in indices is itself an array of arbitrary indices

inInclude

public static boolean inInclude(Tree tree, String beginOrEnd)

incorporateAnnotations

public static void incorporateAnnotations(Tree destTree, Tree origTree)

Reads the annotations at the root of origTree and tries to merge them with the annotations at the root of destTree. This depends on the “meaning” of the annotations created by Tapenade. You may develop this method further if other annotations get lost…

incrementByProtectedExpr

public static Tree incrementByProtectedExpr(int language, Tree lhs, Tree factor, boolean needAtomic)

instrHasSideEffect

public static boolean instrHasSideEffect(Tree expr)

intConstantValue

public static int intConstantValue(Tree tree)
Returns

value when it is an integer constant.

isACIOSymbol

public static boolean isACIOSymbol(Tree tree)

isAConstModified

public static boolean isAConstModified(Tree decl)
Returns

True when given “decl” is modifiedDeclarator(modifiers[ident:const], “subDecl”).

isADeclMayAppearFirst

public static boolean isADeclMayAppearFirst(Tree tree)

isADeclaration

public static boolean isADeclaration(Tree tree)

isAFortranOverloadedOperator

public static boolean isAFortranOverloadedOperator(Tree tree)

isAStringManipulation

public static boolean isAStringManipulation(Tree tree)

isAUnitPlaceHolder

public static boolean isAUnitPlaceHolder(Tree tree)

isAVarRef

public static boolean isAVarRef(Tree tree, SymbolTable symbolTable)
Returns

true when “tree” is a reference to a variable writable at the present location. This means that “tree” can be overwritten, modified, passed as a “write” argument of a function or put on the left side of an assignment. WARNING: differs from isAWritableVarRef(): if this variable was declared as a “const” argument of a C procedure, this method considers this tree is not writeable.

isAVarRefOrConstant

public static boolean isAVarRefOrConstant(Tree tree)
Returns

true when “tree” either is a reference to a variable or is a constant immediate value, i.e. in other words when “tree” does not need a computation to obtain its value.

isAVariableOnlyDeclaration

public static boolean isAVariableOnlyDeclaration(Tree tree)

isAWritableIdentVarRef

public static boolean isAWritableIdentVarRef(Tree tree, SymbolTable symbolTable)

Same as isAWritableVarRef() but rejects op_fieldAccess and op_substringAccess.

isAWritableVarRef

public static boolean isAWritableVarRef(Tree tree, SymbolTable symbolTable)
Returns

true when “tree” is a reference to a variable intrinsically writable. This means that “tree” can be overwritten, modified, passed as a “write” argument of a function or put on the left side of an assignment. WARNING: this is not exactly the same as isAVarRef(): a FORTRAN CONSTANT is considered not writable whereas a C “const” argument is considered writable because “const” only means that this procedure promises it will not write in the variable (but it would be possible). This is important because the diff of tree will be writeable because we will not make it “const”.

isAccessDeclValue

public static boolean isAccessDeclValue(Tree tree, String value)

isAccessedThroughPointer

public static boolean isAccessedThroughPointer(Tree expr)
Returns

true if expression “expr” dereferences at least one pointer.

isAccessibleDirectlyFromVariable

public static boolean isAccessibleDirectlyFromVariable(Tree tree)
Returns

True if this tree is a direct access to a visible variable name, followed by array or field references, without going through a pointer.

isAllocate

public static boolean isAllocate(Tree tree)

isCall

public static boolean isCall(Tree tree)

isCallingString

public static boolean isCallingString(Tree callTree, String calledName, boolean caseSensitive)
Parameters
  • caseSensitive – when true, the String equality is case sensitive.

Returns

true when “callTree” is a call of a function called “calledName”.

isCudaController

public static boolean isCudaController(Tree tree)
Returns

true if “tree” is the controller of a CUDA call.

isExpressionConstant

public static boolean isExpressionConstant(Tree tree)
Returns

true when expression is constant or made with constants.

isExpressionIntConstant

public static boolean isExpressionIntConstant(Tree tree)
Returns

true when it is an integer constant.

isExpressionNumConstant

public static boolean isExpressionNumConstant(Tree tree)
Returns

true when it is a numerical constant.

isIORead

public static boolean isIORead(Tree tree)
Returns

true if the “tree” is a call to an IO that reads data into its arguments.

isIOWrite

public static boolean isIOWrite(Tree tree)
Returns

true if the “tree” is a call to an IO that writes data from its arguments.

isIdent

public static boolean isIdent(Tree tree, String name, boolean caseSensitive)
Parameters
  • caseSensitive – when true, the string equality is case sensitive.

Returns

True iff “tree” is op_ident:”name”.

isIdentOf

public static boolean isIdentOf(Tree tree, String[] names, boolean caseSensitive)
Parameters
  • caseSensitive – when true, the string equality is case sensitive.

Returns

True iff “tree” is op_ident:”name” with “name” belonging to the given array “names”.

isIfExpression

public static boolean isIfExpression(Tree expr)

isImplicitCompleteDimension

public static boolean isImplicitCompleteDimension(Tree indexTree)

isIntCst

public static boolean isIntCst(Tree tree, int value)
Returns

True iff “tree” is op_intCst:”value”.

isNegativeExpression

public static boolean isNegativeExpression(Tree tree)
Returns

true if “tree” is an expression that starts by a “-“.

isNotNone

public static boolean isNotNone(Tree tree)

isNotNoneNorEmpty

public static boolean isNotNoneNorEmpty(Tree tree)

isNotNoneNorVoid

public static boolean isNotNoneNorVoid(Tree tree)

isNotVoid

public static boolean isNotVoid(Tree tree)

isNullOrEmptyAtom

public static boolean isNullOrEmptyAtom(Tree tree)

isNullOrEmptyList

public static boolean isNullOrEmptyList(Tree tree)

isNullOrNone

public static boolean isNullOrNone(Tree tree)

isNullOrNoneOrEmptyList

public static boolean isNullOrNoneOrEmptyList(Tree tree)

isNullOrNoneOrStar

public static boolean isNullOrNoneOrStar(Tree tree)

isNullOrNoneOrVoid

public static boolean isNullOrNoneOrVoid(Tree tree)

isOptPointersIdent

public static boolean isOptPointersIdent(Tree tree)
Returns

True iff this tree is op_ident nested in 0 or more op_pointerDeclarator.

isOverloadedAssign

public static boolean isOverloadedAssign(Tree callAssign)
Returns

true when the given Tree is an overloaded assignment, i.e. a call to “assign” with a sourcetree annotation which is an op_binary “assign”

isParallelController

public static boolean isParallelController(Tree tree)
Returns

true if “tree” is the controller of an OpenMP parallel region or loop.

isStar

public static boolean isStar(Tree tree)

isStaticSchedule

public static boolean isStaticSchedule(Tree schedule)
Returns

True if the given “schedule” clause actually specifies “static”.

isStringOf

public static boolean isStringOf(String name, String[] names)
Returns

True iff String “name” belongs to the given array “names”.

isZero

public static boolean isZero(Tree tree)

keepArrayTriplet

public static Tree keepArrayTriplet(Tree tree)

listReversedToComments

public static Tree listReversedToComments(TapList<Tree> commentsListReversed)

matches

public static boolean matches(Tree tree, Tree patternTree, TapList<TapPair<Tree, Tree>> keyTreeList)
Returns

true iff “tree” matches “patternTree”. As a side-effect, places inside “keyTreeList”, in front of each metavariable Tree from “patternTree”, the matched Tree from “tree”. However, even if finally there is no matching, tree traversal goes on and keeps associating trees when reasonably possible.

mayBeTransformed2Do

public static boolean mayBeTransformed2Do(Tree tree)
Returns

true if this for loop may be transformed into a do loop

mergeUseDeclTrees

public static Tree mergeUseDeclTrees(Tree newRestrict, Tree oldRestrict)

Combines two successive use-restriction trees, that are of form either “onlyVisibles” or “renamesVisibles”. These restriction trees apply in order, i.e. this method returns the use-restriction tree that results from applying “newRestrict” over “oldRestrict”.

[any] + renamedVisibles[] → [any]
onlyVisibles[ident1] + onlyVisibles[ident2] → onlyVisibles[ident1]
renamedVisibles[r1] + renamedVisibles[r2] → renamedVisibles[r1 + r2] (TODO)
onlyVisibles[ident1] + renamedVisibles[r2] → onlyVisibles[ident1, renamedVisibles[r2]] (TODO)

minusProtectedExpr

public static Tree minusProtectedExpr(Tree factor)

Same as mulProtectedExprs, but just takes the opposite.

minusTree

public static Tree minusTree(Tree tree)

modifyRootName

public static Tree modifyRootName(Tree model, String oldName, String newName)

mulProtectedExprs

public static Tree mulProtectedExprs(Tree factor1, TypeSpec type1, Tree factor2, TypeSpec type2)

Multiplies two factors, taking care of the case where any of them is protected. In this case, builds a new protected factor, where the test is the OR of both tests and the factor is the mulTree of the two factors. In either branch “then” and “else”, a null or a none “()” means zero. Works only in the following cases (symmetric cases work just as well):

()           * ()               → ()
Exp1         * Exp2             → Exp1*Exp2
Exp1         * (T2?SExp2:Exp2)  → (T2?Exp1*SExp2:Exp1*Exp2)
(T1?():Exp1) * (T2?():Exp2)     → (T1orT2?():Exp1*Exp2)

mulTree

public static Tree mulTree(Tree tree1, Tree tree2)

normalizePath

public static String normalizePath(String path)

When stringAtomTree is an atomic Tree with a String value, assuming this string is a file path, normalizes this path by removing “dirname/..” sequences.

oneIsArrayTriplet

public static boolean oneIsArrayTriplet(Tree indices)

operator

public static Operator operator(String name)

Gets an IL operator from its name.

Parameters
  • name – The name of the operator.

Returns

The operator if it exists otherwise null.

pathFromPointerAccess

public static Tree pathFromPointerAccess(Tree expr)

*(*(*p.f1).f2).f3.f4  ==>  *_.f3.f4

peelConstModifier

public static Tree peelConstModifier(Tree type)

peelInOutConstValueModifier

public static Tree peelInOutConstValueModifier(Tree type)

peelModifier

public static void peelModifier(Tree tree, String modifier)

position

public static int position(Tree tree)
Returns

the “position” of “tree”. To do that, go up until a tree annotated with its “position” is found, then depth-first sweep this above tree, incrementing the position, until “tree” is found again.

powerTree

public static Tree powerTree(Tree tree1, Tree tree2)

pullProtectedArg

public static Tree pullProtectedArg(Tree callTree, int argRank)

Looks at argument argRank of the given callTree. If this argument is “protected”, i.e. it is an ifExpression, and we are targetting Fortran, then returns a new tree which has the protection outside and the call inside. Otherwise returns the unmodified callTree.

putBackNamedArguments

public static void putBackNamedArguments(Tree tree)

If the given tree contains call arguments, and those have been “normalized” by inserting none() arguments and removing the nameEq’s, puts the argument list back in the fortran-style form with no none() and named arguments when needed.

reBuildNameEqArgs

public static void reBuildNameEqArgs(Tree callTree, Tree resultTree)

realIsInt

protected static boolean realIsInt(String str, TapIntList toIntVal)

Tests that the current String (found in a op_realCst) actually represents an integer. If so, returns true, and if “toIntVal” is non-null, also sets its head to the corresponding integer value if in [-maxint;+maxint].

reducSumProtectedExpr

public static Tree reducSumProtectedExpr(Tree factor, Tree maskTree)

removeSizeModifiers

public static Tree[] removeSizeModifiers(Tree[] modifiers)

removeSourceCodeAnnot

public static Tree removeSourceCodeAnnot(Tree tree)

removeTreeDeclOf

public static void removeTreeDeclOf(String symbol, Tree varDeclTree)

removeUsedModuleFromInterfaceDecl

public static void removeUsedModuleFromInterfaceDecl(Tree tree, String moduleName)

replaceAllCallName

public static void replaceAllCallName(Tree tree, String oldUnitName, String newUnitName, Tree newUnitNameTree, SymbolTable symbolTable)

replaceAllIdentsNamed

public static void replaceAllIdentsNamed(Tree tree, String oldName, String newName)

replaceIdentStringOccurences

public static Tree replaceIdentStringOccurences(Tree tree, String identString, Tree newTree)

Replaces all occurrences of op_ident(identString) with “newTree” in the given “tree”. Modifies “tree” in place.

Returns

the modified tree.

replaceRootWithNewRoot

public static Tree replaceRootWithNewRoot(Tree ref, Tree oldRoot, Tree newRoot)

Builds a new Tree, copy of given ref-expression “ref”, but in which root ref-expression “oldRoot” is replaced with “newRoot”

replaceUsedModule

public static void replaceUsedModule(Tree tree, String oldUnitName, Tree newUnitNameTree)

resetAssignFromInitDecl

public static void resetAssignFromInitDecl(Tree assignmentTree)

Restoration. cf turnAssignFromInitDecl().

resetReturnFromAssign

public static void resetReturnFromAssign(Tree returnTree, Tree assignTree)

Restoration. cf turnReturnIntoAssign().

reverseArrayComponentOrder

public static Tree reverseArrayComponentOrder(Tree tree)
Parameters
  • tree – is a list Tree

Returns

the reversed list Tree

reversedExprAccess

public static TapList<Tree> reversedExprAccess(Tree expr)
Returns

the reversed list of all nested levels in “expr”. For example A[2,1:n]%x[:] produces {A, A[2,1:n], A[2,1:n]%x, A[2,1:n]%x[:]}.

reversedExprAccessFromPointerAccess

public static TapList<Tree> reversedExprAccessFromPointerAccess(Tree expr, boolean peelAllocate)

seemsInteger

public static boolean seemsInteger(Tree exp)
Returns

true when the given Tree seems to be an expression with a numerical INTEGER value, that can be computed.

setArguments

public static void setArguments(Tree callTree, Tree arguments)

setFieldRank

public static void setFieldRank(Tree field, int fieldRank)

setOrigTree

public static void setOrigTree(Tree tree, Tree origTree)

setPosition

public static void setPosition(Tree tree, int position)

setToProtectedExpr

public static Tree setToProtectedExpr(int language, Tree lhs, Tree rhs, TypeSpec assignedType)

skipAllocate

public static Tree skipAllocate(Tree tree)

Copy “tree” skipping its op_allocate level

splitDeclInit

public static TapPair<Tree, Tree> splitDeclInit(Tree tree, boolean addSaveModifier, Unit curUnit)

splitLongDeclaration

public static TapList<Tree> splitLongDeclaration(Tree tree)

If tree is a varDeclaration with too many declared variables, splits it into a list of varDeclaration, each of acceptable length. Otherwise returns null

stopInclude

public static boolean stopInclude(Tree tree, String stopValue)

stripArrayAccesses

public static Tree stripArrayAccesses(Tree expr)

Returns a copy of ref-expression “expr” in which array accesses are removed. Example: *(A(2,:).field(j+1)).field2 gives *(A.field).field2

stripSpecialization

public static String stripSpecialization(String name)

Removes the specialization suffix added to C++ specialized templated objects.

subTree

public static Tree subTree(Tree tree1, Tree tree2)

tapenadeUtilityFunctionName

public static Tree tapenadeUtilityFunctionName(Unit diffUnit, String funcName)

toString

public static String toString(Tree tree)

toString

public static String toString(Tree tree, int language)

toString

public static String toString(Tree tree, int language, boolean withIndices)

toString

public static String toString(Tree tree, int language, ActivityPattern pattern)

toString

public static String toString(Tree tree, ActivityPattern pattern)

transformFor2Do

public static Tree transformFor2Do(Tree tree)

Transforms a for-loop into a do-loop.

Returns

a do-loop.

turnAssignFromInitDecl

public static void turnAssignFromInitDecl(Tree assignmentTree)

Modifies assigmentTree to represent the corresponding “true” assignment. For instance, given (*x) = y+1 which is the 2nd child of float *x = y+1, turns it temporarily into x = y+1. This damages the original assignment. WARNING: IMMEDIATELY after usage of the modified assignment tree, it MUST be repaired into its original form with resetAssignFromInitDecl(returnedTree).

Parameters
  • assignmentTree – Tree present in a declaration with initialization.

turnReturnIntoAssign

public static Tree turnReturnIntoAssign(Tree returnTree, String returnVarName)

Given “returnTree” (a C-style “return <expression>” tree), creates “assignTree” (a tree of shape “returnVarName := <expression>”) that shares the <expression> tree instead of copying it. This damages the original returnTree. WARNING: IMMEDIATELY after usage of the created assignTree, the returnTree MUST be repaired into its original form with resetReturnFromAssign(returnTree, assignTree).

typeName

public static String typeName(Tree tree)

usedVarsInDiffExp

public static TapList<Tree> usedVarsInDiffExp(Tree expression, TapList<Tree> refsR, TapList<Tree> toDiffRefsR, boolean keepTop)

Augment the list of Trees “refsR” with all the expressions whose primal is recursively needed to evaluate the diff of “expression”. Augment the (hatted) list of Trees “toDiffRefsR” with all the expressions whose diff is recursively needed to evaluate the diff of “expression”. New expressions are added only if they are not already present. Example: for *(p[i+j]), i , j go to refsR, and p, p[i], (and if keepTop *(p[i])) go to toDiffRefsR

Parameters
  • toDiffRefsR – the hatted list that accumulates the expressions whose diff is used.

  • keepTop – if false, the top “expression” itself is not added.

Returns

the augmented “refsR” list.

usedVarsInExp

public static TapList<Tree> usedVarsInExp(Tree expression, TapList<Tree> refsR, boolean keepTop)

Augment the list of Trees “refsR” with all the expressions recursively needed to evaluate “expression”. New expressions are added only if they are not already present.

Parameters
  • keepTop – if false, the top “expression” itself is not added.

Returns

the augmented “refsR” list.

usedVarsInTreeOfExps

public static TapList<Tree> usedVarsInTreeOfExps(TapList<Tree> treeOfExps, TapList<Tree> refsR, boolean keepTop)
Returns

the list of Trees “refsR”, augmented with all the expressions recursively needed to evaluate expressions in “treeOfExps”. New expressions are added only if they are not already present. If “keepTop” is false, top-level expressions in “treeOfExps” are not returned.

variableDeclaratorToVariableRef

public static Tree variableDeclaratorToVariableRef(Tree varDecl)