Skip to content

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
VariableRenaming
VariableRenaming(SgProject* proj); [constructor]
Construct from SgProject
~VariableRenaming
~VariableRenaming(); [destructor]
Destructor
getAllUsesForDef
NodeVec getAllUsesForDef( VarName const& var, int num);
getAllUsesForDef overloads
getDebug
bool getDebug() const;
getDebugExtra
bool getDebugExtra() const;
getDefTable
DefUseTable& getDefTable();
Get the table of definitions for every node.
getDefsAtNode
NumNodeRenameTable getDefsAtNode(SgNode* node);
Get name:num mapping for all defs at the given node.
getDefsAtNodeForName
NumNodeRenameEntry getDefsAtNodeForName( SgNode* node, VarName const& var);
Get name:num mapping for def of the specified variable at the given node.
getDefsForSubtree
NumNodeRenameTable 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.
getExpandedDefsAtNode
NumNodeRenameTable getExpandedDefsAtNode(SgNode* node);
Get name:num mapping for all expanded defs at the given node.
getExpandedDefsAtNodeForName
NumNodeRenameEntry getExpandedDefsAtNodeForName( SgNode* node, VarName const& var);
Get name:num mapping for def of the specified variable at the given node.
getMaxRenameNumberForName
int getMaxRenameNumberForName(VarName const& var) const;
Get the number of the last rename of the given variable.
getNodeForRenameNumber
SgNode* getNodeForRenameNumber( VarName const& var, int num) const;
Get the node that defines the given number of the given variable.
getOriginalDefsAtNode
NumNodeRenameTable getOriginalDefsAtNode(SgNode* node);
Get name:num mapping for all original defs at the given node.
getOriginalDefsAtNodeForName
NumNodeRenameEntry getOriginalDefsAtNodeForName( SgNode* node, VarName const& var);
Get name:num mapping for def of the specified variable at the given node.
getOriginalDefsForSubtree
NumNodeRenameTable 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.
getOriginalUsesAtNode
NumNodeRenameTable 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.
getPropDefTable
DefUseTable& getPropDefTable();
Get the defTable containing the propogated definition information.
getReachingDefsAtFunctionEnd
NumNodeRenameTable getReachingDefsAtFunctionEnd(SgFunctionDefinition* node);
Get the final versions if all variables at the end of the given function.
getReachingDefsAtFunctionEndForName
NumNodeRenameEntry getReachingDefsAtFunctionEndForName( SgFunctionDefinition* node, VarName const& var);
Get the versions of a variable at the end of the given function.
getReachingDefsAtFunctionStart
NumNodeRenameTable getReachingDefsAtFunctionStart(SgFunctionDefinition* node);
Get the versions of all variables at the start of the given function.
getReachingDefsAtFunctionStartForName
NumNodeRenameEntry getReachingDefsAtFunctionStartForName( SgFunctionDefinition* node, VarName const& var);
Get the versions of a variable at the start of the given function.
getReachingDefsAtNode
NumNodeRenameTable getReachingDefsAtNode(SgNode* node);
Get name:num mappings for all reaching definitions of all variables at the node.
getReachingDefsAtNodeForName
NumNodeRenameEntry getReachingDefsAtNodeForName( SgNode* node, VarName const& var);
Get name:num mapping for all reaching definitions of the given variable at the node.
getReachingDefsAtScopeEnd
NumNodeRenameTable getReachingDefsAtScopeEnd(SgScopeStatement* bb);
Get the final versions if all variables at the end of the given scope.
getReachingDefsAtStatementStart
NumNodeRenameTable 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.
getRenameNumberForNode
int getRenameNumberForNode( VarName const& var, SgNode* node) const;
Get the rename number for the given variable and the given node.
getUseTable
DefUseTable& getUseTable();
Get the table of uses for every node.
getUsesAtNode
NumNodeRenameTable 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
getUsesAtNodeForName
NumNodeRenameEntry getUsesAtNodeForName( SgNode* node, VarName const& var);
Get name:num mapping for use of the given variable at this node.
printDefs
void printDefs(SgNode* node);
printOriginalDefTable
void printOriginalDefTable();
printOriginalDefs
void printOriginalDefs(SgNode* node);
printRenameTable
void printRenameTable();
printUses
void printUses(SgNode* node);
run
void run();
toDOT
void toDOT(std::string const fileName);
Print the CFG with any UniqueNames and Def/Use information visible.
toFilteredDOT
void toFilteredDOT(std::string const fileName);
Print the CFG with any UniqueNames and Def/Use information visible.

Static Member Functions

Name Description
buildVariableReference
static 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.
getUniqueName
static VarUniqueName* getUniqueName(SgNode* node);
Get the uniqueName attribute for the given node.
getVarName
static VarName getVarName(SgNode* node);
Get the variable name of the given node.
isFromLibrary
static bool isFromLibrary(SgFunctionDeclaration* node);
Exclude generated declarations and declarations owned by system headers.
isPrefixOfName
static bool isPrefixOfName( VarName const& name, VarName const& prefix);
Check whether the given name begins with the given prefix.
keyToString
static std::string keyToString(VarName const& vec);
Get a string representation of a varName.
printRenameEntry
static void printRenameEntry(NodeNumRenameEntry const& entry);
printRenameTable
static 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
addRenameNumberForNode
int addRenameNumberForNode( VarName const& var, SgNode* node);
Add an entry to the renumbering table for the given var and node.
aggregatePreviousDefs
void aggregatePreviousDefs( cfgNode curNode, TableEntry& results);
Trace backwards in the cfg one step and return an aggregate of all previous defs.
defUse
bool defUse( cfgNode node, bool* memberRefInserted, NodeVec& changedNodes);
expandMemberDefinitions
bool expandMemberDefinitions(cfgNode curNode);
Expand all member definitions (chained names) to define every name in the chain.
expandMemberUses
bool expandMemberUses(cfgNode curNode);
Expand all member uses (chained names) to explicitly use every name in the chain.
getVarsUsedInSubtree
std::set<VarName> getVarsUsedInSubtree(SgNode* root);
Returns a set of all the variables names that have uses in the subtree.
insertDefsForExternalVariables
void insertDefsForExternalVariables(SgFunctionDeclaration* function);
Insert defs for functions that are declared outside the function scope.
insertExpandedDefsForUse
bool insertExpandedDefsForUse( cfgNode curNode, VarName name, NodeVec& changedNodes);
Insert defs for member uses (chained names) that do not have an explicit def.
isBuiltinVar
bool isBuiltinVar(VarName const& var);
mergeDefs
bool mergeDefs( cfgNode curNode, bool* memberRefInserted, NodeVec& changedNodes);
Called to merge the defs from previous nodes in the CFG to this one.
printDefs
void printDefs(TableEntry const& table);
printToDOT
void printToDOT( SgSourceFile* file, std::ofstream& outFile);
printToFilteredDOT
void printToFilteredDOT( SgSourceFile* file, std::ofstream& outFile);
printUses
void printUses(TableEntry const& table);
resolveUses
bool resolveUses( cfgNode curNode, bool* memberRefInserted, NodeVec& changedNodes);
Called to update the uses on the current node.
runDefUse
void 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