VariableRenaming¶
Class that defines an VariableRenaming of a program
Synopsis¶
Declared in <src/midend/programAnalysis/variableRenaming/VariableRenaming.h>
class VariableRenaming; Description¶
Contains all the functionality to implement variable renaming on a given program. For this class, we do not actually transform the AST directly, rather we perform the analysis and add attributes to the AST nodes so that later optimizations can access the results of this analysis while still preserving the original AST.
Type Aliases¶
| Name | Description |
|---|---|
DefUseTable | A table storing the name->node mappings for every node in the program. |
FirstDefTable | A table mapping a name to a single node. |
InitNameVec | A vector of SgInitializedName* |
NodeNumRenameEntry | An entry in the rename table that maps a node to a number. |
NodeNumRenameTable | A table that maps a name to it's node->number renamings. |
NodeVec | Vector of SgNode* |
NumNodeRenameEntry | An entry in the rename table that maps a number to a node. |
NumNodeRenameTable | A table that maps a name to it's number->node renamings. |
TableEntry | An entry in the rename table mapping a name to a nodeVec. |
VarName | A compound variable name as used by the variable renaming. |
cfgEdge | A filtered CFGEdge that is used for DefUse traversal. |
cfgEdgeVec | A vector of cfgEdges. |
cfgNode | A filtered CFGNode that is used for DefUse traversal. |
cfgNodeVec | A vector of cfgNodes. |
Member Functions¶
| Name | Description |
|---|---|
VariableRenamingVariableRenaming(SgProject* proj); [constructor] | Construct from SgProject |
~VariableRenaming~VariableRenaming(); [destructor] | Destructor |
getAllUsesForDefNodeVec getAllUsesForDef( VarName const& var, int num); | getAllUsesForDef overloads |
getDebugbool getDebug() const; | |
getDebugExtrabool getDebugExtra() const; | |
getDefTableDefUseTable& getDefTable(); | Get the table of definitions for every node. |
getDefsAtNodeNumNodeRenameTable getDefsAtNode(SgNode* node); | Get name:num mapping for all defs at the given node. |
getDefsAtNodeForNameNumNodeRenameEntry getDefsAtNodeForName( SgNode* node, VarName const& var); | Get name:num mapping for def of the specified variable at the given node. |
getDefsForSubtreeNumNodeRenameTable getDefsForSubtree(SgNode* node); | Get all definitions for the subtree rooted at this node. If m.x is defined, the resulting table will also include a definition for m. |
getExpandedDefsAtNodeNumNodeRenameTable getExpandedDefsAtNode(SgNode* node); | Get name:num mapping for all expanded defs at the given node. |
getExpandedDefsAtNodeForNameNumNodeRenameEntry getExpandedDefsAtNodeForName( SgNode* node, VarName const& var); | Get name:num mapping for def of the specified variable at the given node. |
getMaxRenameNumberForNameint getMaxRenameNumberForName(VarName const& var) const; | Get the number of the last rename of the given variable. |
getNodeForRenameNumberSgNode* getNodeForRenameNumber( VarName const& var, int num) const; | Get the node that defines the given number of the given variable. |
getOriginalDefsAtNodeNumNodeRenameTable getOriginalDefsAtNode(SgNode* node); | Get name:num mapping for all original defs at the given node. |
getOriginalDefsAtNodeForNameNumNodeRenameEntry getOriginalDefsAtNodeForName( SgNode* node, VarName const& var); | Get name:num mapping for def of the specified variable at the given node. |
getOriginalDefsForSubtreeNumNodeRenameTable getOriginalDefsForSubtree(SgNode* node); | Get all original definitions for the subtree rooted at this node. No expanded definitions will be included - for example, if m.x is defined, there will be no definition for the structure m. |
getOriginalUsesAtNodeNumNodeRenameTable getOriginalUsesAtNode(SgNode* node); | Get name:num mappings for the original uses at this node. For example, if p.x appears, there will be a use for p.x, but not for p. |
getPropDefTableDefUseTable& getPropDefTable(); | Get the defTable containing the propogated definition information. |
getReachingDefsAtFunctionEndNumNodeRenameTable getReachingDefsAtFunctionEnd(SgFunctionDefinition* node); | Get the final versions if all variables at the end of the given function. |
getReachingDefsAtFunctionEndForNameNumNodeRenameEntry getReachingDefsAtFunctionEndForName( SgFunctionDefinition* node, VarName const& var); | Get the versions of a variable at the end of the given function. |
getReachingDefsAtFunctionStartNumNodeRenameTable getReachingDefsAtFunctionStart(SgFunctionDefinition* node); | Get the versions of all variables at the start of the given function. |
getReachingDefsAtFunctionStartForNameNumNodeRenameEntry getReachingDefsAtFunctionStartForName( SgFunctionDefinition* node, VarName const& var); | Get the versions of a variable at the start of the given function. |
getReachingDefsAtNodeNumNodeRenameTable getReachingDefsAtNode(SgNode* node); | Get name:num mappings for all reaching definitions of all variables at the node. |
getReachingDefsAtNodeForNameNumNodeRenameEntry getReachingDefsAtNodeForName( SgNode* node, VarName const& var); | Get name:num mapping for all reaching definitions of the given variable at the node. |
getReachingDefsAtScopeEndNumNodeRenameTable getReachingDefsAtScopeEnd(SgScopeStatement* bb); | Get the final versions if all variables at the end of the given scope. |
getReachingDefsAtStatementStartNumNodeRenameTable getReachingDefsAtStatementStart(SgStatement* statement); | Gets the versions of all variables reaching a statment before its execution. Notice that this method and getReachingDefsAtNode potentially return different values for loops. With loops, variable values from the body of the loop flow to the top; hence getReachingDefsAtNode returns definitions from the loop body. On the other hand, getReachingDefsAtStatementStart does not return definitions coming in from a loop body. |
getRenameNumberForNodeint getRenameNumberForNode( VarName const& var, SgNode* node) const; | Get the rename number for the given variable and the given node. |
getUseTableDefUseTable& getUseTable(); | Get the table of uses for every node. |
getUsesAtNodeNumNodeRenameTable getUsesAtNode(SgNode* node); | Get name:num mappings for all uses at this node. For example, if p.x appears, there will be a use for both p and p.x |
getUsesAtNodeForNameNumNodeRenameEntry getUsesAtNodeForName( SgNode* node, VarName const& var); | Get name:num mapping for use of the given variable at this node. |
printDefsvoid printDefs(SgNode* node); | |
printOriginalDefTablevoid printOriginalDefTable(); | |
printOriginalDefsvoid printOriginalDefs(SgNode* node); | |
printRenameTablevoid printRenameTable(); | |
printUsesvoid printUses(SgNode* node); | |
runvoid run(); | |
toDOTvoid toDOT(std::string const fileName); | Print the CFG with any UniqueNames and Def/Use information visible. |
toFilteredDOTvoid toFilteredDOT(std::string const fileName); | Print the CFG with any UniqueNames and Def/Use information visible. |
Static Member Functions¶
| Name | Description |
|---|---|
buildVariableReferencestatic SgExpression* buildVariableReference( VarName const& var, SgScopeStatement* scope = NULL); | Get an AST fragment containing the appropriate varRefs and Dot/Arrow ops to access the given variable. |
getUniqueNamestatic VarUniqueName* getUniqueName(SgNode* node); | Get the uniqueName attribute for the given node. |
getVarNamestatic VarName getVarName(SgNode* node); | Get the variable name of the given node. |
isFromLibrarystatic bool isFromLibrary(SgFunctionDeclaration* node); | Exclude generated declarations and declarations owned by system headers. |
isPrefixOfNamestatic bool isPrefixOfName( VarName const& name, VarName const& prefix); | Check whether the given name begins with the given prefix. |
keyToStringstatic std::string keyToString(VarName const& vec); | Get a string representation of a varName. |
printRenameEntrystatic void printRenameEntry(NodeNumRenameEntry const& entry); | |
printRenameTablestatic void printRenameTable(NodeNumRenameTable const& table); |
Static Data Members¶
| Name | Description |
|---|---|
emptyName | |
emptyRenameEntry | |
emptyRenameTable | |
thisDecl | This represents the initializedName for the 'this' keyword. |
varKeyTag | Tag to use to retrieve unique naming key from node. |
Private Types¶
| Name | Description |
|---|---|
ChildUses | Attribute that describes the variables used by a given expression. |
DefsAndUsesTraversal | This class collects all the defs and uses associated with each node in the traversed CFG. Note that this does not compute reachability information; it just records each instance of a variable used or defined. |
UniqueNameTraversal | Class to traverse the AST and assign unique names to every varRef. |
VarRefSynthAttr | Attribute that describes the variables modified by a given expression. |
Private Member Functions¶
| Name | Description |
|---|---|
addRenameNumberForNodeint addRenameNumberForNode( VarName const& var, SgNode* node); | Add an entry to the renumbering table for the given var and node. |
aggregatePreviousDefsvoid aggregatePreviousDefs( cfgNode curNode, TableEntry& results); | Trace backwards in the cfg one step and return an aggregate of all previous defs. |
defUsebool defUse( cfgNode node, bool* memberRefInserted, NodeVec& changedNodes); | |
expandMemberDefinitionsbool expandMemberDefinitions(cfgNode curNode); | Expand all member definitions (chained names) to define every name in the chain. |
expandMemberUsesbool expandMemberUses(cfgNode curNode); | Expand all member uses (chained names) to explicitly use every name in the chain. |
getVarsUsedInSubtreestd::set<VarName> getVarsUsedInSubtree(SgNode* root); | Returns a set of all the variables names that have uses in the subtree. |
insertDefsForExternalVariablesvoid insertDefsForExternalVariables(SgFunctionDeclaration* function); | Insert defs for functions that are declared outside the function scope. |
insertExpandedDefsForUsebool insertExpandedDefsForUse( cfgNode curNode, VarName name, NodeVec& changedNodes); | Insert defs for member uses (chained names) that do not have an explicit def. |
isBuiltinVarbool isBuiltinVar(VarName const& var); | |
mergeDefsbool mergeDefs( cfgNode curNode, bool* memberRefInserted, NodeVec& changedNodes); | Called to merge the defs from previous nodes in the CFG to this one. |
printDefsvoid printDefs(TableEntry const& table); | |
printToDOTvoid printToDOT( SgSourceFile* file, std::ofstream& outFile); | |
printToFilteredDOTvoid printToFilteredDOT( SgSourceFile* file, std::ofstream& outFile); | |
printUsesvoid printUses(TableEntry const& table); | |
resolveUsesbool resolveUses( cfgNode curNode, bool* memberRefInserted, NodeVec& changedNodes); | Called to update the uses on the current node. |
runDefUsevoid runDefUse(SgFunctionDefinition* func); |
Private Data Members¶
| Name | Description |
|---|---|
DEBUG_MODE | |
DEBUG_MODE_EXTRA | |
defTable | This is the table that is populated with all the def information for all the variables at all the nodes. It is populated during the runDefUse function, and is done with the steady-state dataflow algorithm. |
expandedDefTable | This is the table of definitions that is expanded from the original table. It is used to populate the actual def/use table. |
firstDefList | Holds a list of the locations that a particular name is first defined. |
nodeRenameTable | This holds the mapping between variables and the nodes where they are renumbered. Given a name and a node, we can get the number of the name that is defined at that node. Nodes which do not define a name are not in the table. |
numRenameTable | This holds the mapping between variables and the nodes where they are renumbered. Given a name and a number, we can get the node where that number is defined. Nodes which do not define a name are not in the table. |
originalDefTable | This is the table of variable definition locations that is generated by the VarDefUseTraversal. It is later used to populate the actual def/use table. |
project | The project to perform SSA Analysis on. |
useTable | This is the table that is populated with all the use information for all the variables at all the nodes. It is populated during the runDefUse function, and is done with the steady-state dataflow algorithm. |
Created with MrDocs