ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VariableRenaming Class Reference

Class that defines an VariableRenaming of a program. More...

#include <VariableRenaming.h>

Collaboration diagram for VariableRenaming:

Classes

class  ChildUses
 Attribute that describes the variables used by a given expression. More...
 
class  DefsAndUsesTraversal
 This class collects all the defs and uses associated with each node in the traversed CFG. More...
 
class  UniqueNameTraversal
 Class to traverse the AST and assign unique names to every varRef. More...
 
class  VarRefSynthAttr
 Attribute that describes the variables modified by a given expression. More...
 

Public Types

typedef std::vector< SgNode * > NodeVec
 Vector of SgNode*. More...
 
typedef std::vector
< SgInitializedName * > 
VarName
 A compound variable name as used by the variable renaming. More...
 
typedef std::map< VarName,
NodeVec
TableEntry
 An entry in the rename table mapping a name to a nodeVec. More...
 
typedef boost::unordered_map
< SgNode *, TableEntry
DefUseTable
 A table storing the name->node mappings for every node in the program. More...
 
typedef boost::unordered_map
< VarName, SgNode * > 
FirstDefTable
 A table mapping a name to a single node. More...
 
typedef std::vector
< SgInitializedName * > 
InitNameVec
 A vector of SgInitializedName*. More...
 
typedef FilteredCFGNode
< IsDefUseFilter
cfgNode
 A filtered CFGNode that is used for DefUse traversal. More...
 
typedef FilteredCFGEdge
< IsDefUseFilter
cfgEdge
 A filtered CFGEdge that is used for DefUse traversal. More...
 
typedef std::vector< cfgNodecfgNodeVec
 A vector of cfgNodes. More...
 
typedef std::vector< cfgEdgecfgEdgeVec
 A vector of cfgEdges. More...
 
typedef std::map< SgNode *, int > NodeNumRenameEntry
 An entry in the rename table that maps a node to a number. More...
 
typedef boost::unordered_map
< VarName, NodeNumRenameEntry
NodeNumRenameTable
 A table that maps a name to it's node->number renamings. More...
 
typedef std::map< int, SgNode * > NumNodeRenameEntry
 An entry in the rename table that maps a number to a node. More...
 
typedef boost::unordered_map
< VarName, NumNodeRenameEntry
NumNodeRenameTable
 A table that maps a name to it's number->node renamings. More...
 

Public Member Functions

 VariableRenaming (SgProject *proj)
 
 ~VariableRenaming ()
 
void run ()
 
bool getDebug () const
 
bool getDebugExtra () const
 
void toDOT (const std::string fileName)
 Print the CFG with any UniqueNames and Def/Use information visible. More...
 
void toFilteredDOT (const std::string fileName)
 Print the CFG with any UniqueNames and Def/Use information visible. More...
 
void printDefs (SgNode *node)
 
void printOriginalDefs (SgNode *node)
 
void printOriginalDefTable ()
 
void printUses (SgNode *node)
 
void printRenameTable ()
 
void printRenameTable (const VarName &var)
 
DefUseTablegetDefTable ()
 Get the table of definitions for every node. More...
 
const DefUseTablegetDefTable () const
 Get the table of definitions for every node. More...
 
DefUseTablegetPropDefTable ()
 Get the defTable containing the propogated definition information. More...
 
const DefUseTablegetPropDefTable () const
 Get the defTable containing the propogated definition information. More...
 
DefUseTablegetUseTable ()
 Get the table of uses for every node. More...
 
const DefUseTablegetUseTable () const
 Get the table of uses for every node. More...
 
int getRenameNumberForNode (const VarName &var, SgNode *node) const
 Get the rename number for the given variable and the given node. More...
 
SgNodegetNodeForRenameNumber (const VarName &var, int num) const
 Get the node that defines the given number of the given variable. More...
 
int getMaxRenameNumberForName (const VarName &var) const
 Get the number of the last rename of the given variable. More...
 
NodeVec getAllUsesForDef (const VarName &var, int num)
 Retrieve a list of nodes that use the var:num specified. More...
 
template<typename T >
std::vector< T * > getAllUsesForDef (const VarName &var, int num)
 Retrieve a list of nodes of type T that use the var:num specified. More...
 
NumNodeRenameTable getReachingDefsAtNode (SgNode *node)
 Get name:num mappings for all reaching definitions of all variables at the node. More...
 
NumNodeRenameEntry getReachingDefsAtNodeForName (SgNode *node, const VarName &var)
 Get name:num mapping for all reaching definitions of the given variable at the node. More...
 
NumNodeRenameTable getReachingDefsAtScopeEnd (SgScopeStatement *scope)
 Get the final versions if all variables at the end of the given scope. More...
 
NumNodeRenameTable getReachingDefsAtFunctionEnd (SgFunctionDefinition *node)
 Get the final versions if all variables at the end of the given function. More...
 
NumNodeRenameEntry getReachingDefsAtFunctionEndForName (SgFunctionDefinition *node, const VarName &var)
 Get the versions of a variable at the end of the given function. More...
 
NumNodeRenameTable getReachingDefsAtStatementStart (SgStatement *statement)
 Gets the versions of all variables reaching a statment before its execution. More...
 
NumNodeRenameTable getReachingDefsAtFunctionStart (SgFunctionDefinition *node)
 Get the versions of all variables at the start of the given function. More...
 
NumNodeRenameEntry getReachingDefsAtFunctionStartForName (SgFunctionDefinition *node, const VarName &var)
 Get the versions of a variable at the start of the given function. More...
 
NumNodeRenameTable getUsesAtNode (SgNode *node)
 Get name:num mappings for all uses at this node. More...
 
NumNodeRenameTable getOriginalUsesAtNode (SgNode *node)
 Get name:num mappings for the original uses at this node. More...
 
NumNodeRenameEntry getUsesAtNodeForName (SgNode *node, const VarName &var)
 Get name:num mapping for use of the given variable at this node. More...
 
NumNodeRenameTable getDefsAtNode (SgNode *node)
 Get name:num mapping for all defs at the given node. More...
 
NumNodeRenameEntry getDefsAtNodeForName (SgNode *node, const VarName &var)
 Get name:num mapping for def of the specified variable at the given node. More...
 
NumNodeRenameTable getOriginalDefsAtNode (SgNode *node)
 Get name:num mapping for all original defs at the given node. More...
 
NumNodeRenameEntry getOriginalDefsAtNodeForName (SgNode *node, const VarName &var)
 Get name:num mapping for def of the specified variable at the given node. More...
 
NumNodeRenameTable getExpandedDefsAtNode (SgNode *node)
 Get name:num mapping for all expanded defs at the given node. More...
 
NumNodeRenameEntry getExpandedDefsAtNodeForName (SgNode *node, const VarName &var)
 Get name:num mapping for def of the specified variable at the given node. More...
 
NumNodeRenameTable getDefsForSubtree (SgNode *node)
 Get all definitions for the subtree rooted at this node. More...
 
NumNodeRenameTable getOriginalDefsForSubtree (SgNode *node)
 Get all original definitions for the subtree rooted at this node. More...
 

Static Public Member Functions

static std::string keyToString (const VarName &vec)
 Get a string representation of a varName. More...
 
static void printRenameTable (const NodeNumRenameTable &table)
 
static void printRenameTable (const NumNodeRenameTable &table)
 
static void printRenameEntry (const NodeNumRenameEntry &entry)
 
static void printRenameEntry (const NumNodeRenameEntry &entry)
 
static bool isPrefixOfName (VarName name, VarName prefix)
 Find if the given prefix is a prefix of the given name. More...
 
static VarUniqueNamegetUniqueName (SgNode *node)
 Get the uniqueName attribute for the given node. More...
 
static VarName getVarName (SgNode *node)
 Get the variable name of the given node. More...
 
static bool isFromLibrary (SgFunctionDeclaration *node)
 Gets whether or not the function is from a library. More...
 
static SgExpressionbuildVariableReference (const VarName &var, SgScopeStatement *scope=NULL)
 Get an AST fragment containing the appropriate varRefs and Dot/Arrow ops to access the given variable. More...
 

Static Public Attributes

static std::string varKeyTag
 Tag to use to retrieve unique naming key from node. More...
 
static SgInitializedNamethisDecl
 This represents the initializedName for the 'this' keyword. More...
 
static VarName emptyName
 
static NumNodeRenameTable emptyRenameTable
 
static NumNodeRenameEntry emptyRenameEntry
 

Private Member Functions

void runDefUse (SgFunctionDefinition *func)
 
bool defUse (cfgNode node, bool *memberRefInserted, NodeVec &changedNodes)
 
int addRenameNumberForNode (const VarName &var, SgNode *node)
 Add an entry to the renumbering table for the given var and node. More...
 
bool isBuiltinVar (const VarName &var)
 
bool mergeDefs (cfgNode curNode, bool *memberRefInserted, NodeVec &changedNodes)
 Called to merge the defs from previous nodes in the CFG to this one. More...
 
bool resolveUses (cfgNode curNode, bool *memberRefInserted, NodeVec &changedNodes)
 Called to update the uses on the current node. More...
 
void aggregatePreviousDefs (cfgNode curNode, TableEntry &results)
 Trace backwards in the cfg one step and return an aggregate of all previous defs. More...
 
bool expandMemberDefinitions (cfgNode curNode)
 Expand all member definitions (chained names) to define every name in the chain. More...
 
bool insertExpandedDefsForUse (cfgNode curNode, VarName name, NodeVec &changedNodes)
 Insert defs for member uses (chained names) that do not have an explicit def. More...
 
bool expandMemberUses (cfgNode curNode)
 Expand all member uses (chained names) to explicitly use every name in the chain. More...
 
void insertDefsForExternalVariables (SgFunctionDeclaration *function)
 Insert defs for functions that are declared outside the function scope. More...
 
std::set< VarNamegetVarsUsedInSubtree (SgNode *root)
 Returns a set of all the variables names that have uses in the subtree. More...
 
void printToDOT (SgSourceFile *file, std::ofstream &outFile)
 
void printToFilteredDOT (SgSourceFile *file, std::ofstream &outFile)
 
void printUses (const TableEntry &table)
 
void printDefs (const TableEntry &table)
 

Private Attributes

SgProjectproject
 The project to perform SSA Analysis on. More...
 
bool DEBUG_MODE
 
bool DEBUG_MODE_EXTRA
 
DefUseTable originalDefTable
 This is the table of variable definition locations that is generated by the VarDefUseTraversal. More...
 
DefUseTable expandedDefTable
 This is the table of definitions that is expanded from the original table. More...
 
DefUseTable defTable
 This is the table that is populated with all the def information for all the variables at all the nodes. More...
 
DefUseTable useTable
 This is the table that is populated with all the use information for all the variables at all the nodes. More...
 
FirstDefTable firstDefList
 Holds a list of the locations that a particular name is first defined. More...
 
NodeNumRenameTable nodeRenameTable
 This holds the mapping between variables and the nodes where they are renumbered. More...
 
NumNodeRenameTable numRenameTable
 This holds the mapping between variables and the nodes where they are renumbered. More...
 

Detailed Description

Class that defines an VariableRenaming of a program.

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.

Definition at line 193 of file VariableRenaming.h.

Member Typedef Documentation

typedef std::vector<SgNode*> VariableRenaming::NodeVec

Vector of SgNode*.

Definition at line 205 of file VariableRenaming.h.

A compound variable name as used by the variable renaming.

Definition at line 208 of file VariableRenaming.h.

An entry in the rename table mapping a name to a nodeVec.

Definition at line 211 of file VariableRenaming.h.

typedef boost::unordered_map<SgNode*, TableEntry> VariableRenaming::DefUseTable

A table storing the name->node mappings for every node in the program.

Definition at line 214 of file VariableRenaming.h.

typedef boost::unordered_map<VarName, SgNode*> VariableRenaming::FirstDefTable

A table mapping a name to a single node.

Definition at line 217 of file VariableRenaming.h.

A vector of SgInitializedName*.

Definition at line 221 of file VariableRenaming.h.

typedef FilteredCFGNode<IsDefUseFilter> VariableRenaming::cfgNode

A filtered CFGNode that is used for DefUse traversal.

Definition at line 224 of file VariableRenaming.h.

typedef FilteredCFGEdge<IsDefUseFilter> VariableRenaming::cfgEdge

A filtered CFGEdge that is used for DefUse traversal.

Definition at line 227 of file VariableRenaming.h.

typedef std::vector<cfgNode> VariableRenaming::cfgNodeVec

A vector of cfgNodes.

Definition at line 230 of file VariableRenaming.h.

typedef std::vector<cfgEdge> VariableRenaming::cfgEdgeVec

A vector of cfgEdges.

Definition at line 233 of file VariableRenaming.h.

An entry in the rename table that maps a node to a number.

Definition at line 236 of file VariableRenaming.h.

A table that maps a name to it's node->number renamings.

Definition at line 239 of file VariableRenaming.h.

An entry in the rename table that maps a number to a node.

Definition at line 242 of file VariableRenaming.h.

A table that maps a name to it's number->node renamings.

Definition at line 245 of file VariableRenaming.h.

Constructor & Destructor Documentation

VariableRenaming::VariableRenaming ( SgProject proj)
inline

Definition at line 294 of file VariableRenaming.h.

VariableRenaming::~VariableRenaming ( )
inline

Definition at line 296 of file VariableRenaming.h.

Member Function Documentation

void VariableRenaming::run ( )
bool VariableRenaming::getDebug ( ) const
inline

Definition at line 300 of file VariableRenaming.h.

References DEBUG_MODE.

bool VariableRenaming::getDebugExtra ( ) const
inline

Definition at line 301 of file VariableRenaming.h.

References DEBUG_MODE_EXTRA.

void VariableRenaming::runDefUse ( SgFunctionDefinition func)
private
bool VariableRenaming::defUse ( cfgNode  node,
bool *  memberRefInserted,
NodeVec changedNodes 
)
private
int VariableRenaming::addRenameNumberForNode ( const VarName var,
SgNode node 
)
private

Add an entry to the renumbering table for the given var and node.

This will place a new entry into the renaming table that renumbers var at node. This new definition will have the next available numbering of var. If the var @ node combination already exists, the number will be returned.

Parameters
varThe variable to renumber.
nodeThe node that defines the new number.
Returns
The renumbering assigned to ver @ node.
bool VariableRenaming::isBuiltinVar ( const VarName var)
private
bool VariableRenaming::mergeDefs ( cfgNode  curNode,
bool *  memberRefInserted,
NodeVec changedNodes 
)
private

Called to merge the defs from previous nodes in the CFG to this one.

This will merge the def tables from all previous CFG nodes, merge in the defs at this node, and update this node's table if needed. If it locates a def that is not in the table, it will attempt to find the location where that member was first defined and insert a definition there. It will then set the outParameter to indicate that it back-inserted a def.

Parameters
curNodeThe node to merge defs onto.
memberRefInsertedReference that indicates whether the function back-inserted a definition.
Returns
Whether the defs were different from those already on the node.
bool VariableRenaming::resolveUses ( cfgNode  curNode,
bool *  memberRefInserted,
NodeVec changedNodes 
)
private

Called to update the uses on the current node.

This will update the uses at this node to point to the defs that were propogated from previous nodes. If it locates a use of a def that did not exist, it will attempt to locate the definition site of the base variable and insert a def there. It will then set the outParameter to indicate that it back-inserted a def.

Parameters
curNodeThe node to resolve uses on.
memberRefInsertedReference that indicates whether the function back-inserted a definition.
Returns
Whether the uses were different from those already on the node.
void VariableRenaming::aggregatePreviousDefs ( cfgNode  curNode,
TableEntry results 
)
private

Trace backwards in the cfg one step and return an aggregate of all previous defs.

Parameters
curNodeNode to traverse backwards from.
resultsTableEntry reference where results are stored.
bool VariableRenaming::expandMemberDefinitions ( cfgNode  curNode)
private

Expand all member definitions (chained names) to define every name in the chain.

When a member of a struct/class is referenced, this will insert definitions for every member referenced to access the currently referenced one.

ex. Obj o; //Declare o of type Obj o.a.b = 5; //Def for o.a.b

In the second line, this function will insert the following:

  o.a.b = 5;     //Def for o.a.b, o.a, o
Parameters
curNodeThe node to expand the definitions on.
Returns
Whether or not any new defs were inserted.
bool VariableRenaming::insertExpandedDefsForUse ( cfgNode  curNode,
VarName  name,
NodeVec changedNodes 
)
private

Insert defs for member uses (chained names) that do not have an explicit def.

When a member of a struct/class is used and that member does not have a propogated def on the current node, this will find the closest definition of a member in the ref chain and insert a definition for this use at that member's def.

ex. Obj o; //Declare o of type o o.a = 5; //Def for o.a int i = o.b.x; //Def for i, use for o.b.x int j = o.a.x; //Def for j, use for o.a.x

This function will insert the following: Obj o; //Declare o of type o, Def for o.a, def for o.b, def for o.b.x o.a = 5; //Def for o.a, use for o, use for o.a, def for o.a.x int i = o.b.x; //Def for i, use for o.b.x int j = o.a.x; //Def for j, use for o.a.x

Parameters
curNodeThe node to expand the uses on.
nameThe variableName to expand the uses for.
Returns
Whether any new defs were inserted.
bool VariableRenaming::expandMemberUses ( cfgNode  curNode)
private

Expand all member uses (chained names) to explicitly use every name in the chain.

When a member of a struct/class is used, this will insert uses for every member referenced to access the currently used one.

ex. Obj o; //Declare o of type Obj int i; //Declare i of type int i = o.a.b; //Def for i, use for o.a.b

In the third line, this function will insert the following:

  i = o.a.b;     //Def for i, use for o.a.b, o.a, o
Parameters
curNode
Returns
Whether any new uses were inserted.
void VariableRenaming::insertDefsForExternalVariables ( SgFunctionDeclaration function)
private

Insert defs for functions that are declared outside the function scope.

std::set<VarName> VariableRenaming::getVarsUsedInSubtree ( SgNode root)
private

Returns a set of all the variables names that have uses in the subtree.

void VariableRenaming::printToDOT ( SgSourceFile file,
std::ofstream &  outFile 
)
private
void VariableRenaming::printToFilteredDOT ( SgSourceFile file,
std::ofstream &  outFile 
)
private
void VariableRenaming::printUses ( const TableEntry table)
private
void VariableRenaming::printDefs ( const TableEntry table)
private
void VariableRenaming::toDOT ( const std::string  fileName)

Print the CFG with any UniqueNames and Def/Use information visible.

Parameters
fileNameThe filename to save graph as. Filenames will be prepended.
void VariableRenaming::toFilteredDOT ( const std::string  fileName)

Print the CFG with any UniqueNames and Def/Use information visible.

This will only print the nodes that are of interest to the filter function used by the def/use traversal.

Parameters
fileNameThe filename to save graph as. Filenames will be prepended.
static std::string VariableRenaming::keyToString ( const VarName vec)
static

Get a string representation of a varName.

Parameters
vecvarName to get string for.
Returns
String for given varName.
void VariableRenaming::printDefs ( SgNode node)
void VariableRenaming::printOriginalDefs ( SgNode node)
void VariableRenaming::printOriginalDefTable ( )
void VariableRenaming::printUses ( SgNode node)
void VariableRenaming::printRenameTable ( )
void VariableRenaming::printRenameTable ( const VarName var)
static void VariableRenaming::printRenameTable ( const NodeNumRenameTable table)
static
static void VariableRenaming::printRenameTable ( const NumNodeRenameTable table)
static
static void VariableRenaming::printRenameEntry ( const NodeNumRenameEntry entry)
static
static void VariableRenaming::printRenameEntry ( const NumNodeRenameEntry entry)
static
DefUseTable& VariableRenaming::getDefTable ( )
inline

Get the table of definitions for every node.

Returns
Definition table.

Definition at line 501 of file VariableRenaming.h.

References originalDefTable.

const DefUseTable& VariableRenaming::getDefTable ( ) const
inline

Get the table of definitions for every node.

Returns
Definition table.

Definition at line 507 of file VariableRenaming.h.

References originalDefTable.

DefUseTable& VariableRenaming::getPropDefTable ( )
inline

Get the defTable containing the propogated definition information.

Returns
Def table.

Definition at line 513 of file VariableRenaming.h.

References defTable.

const DefUseTable& VariableRenaming::getPropDefTable ( ) const
inline

Get the defTable containing the propogated definition information.

Returns
Def table.

Definition at line 519 of file VariableRenaming.h.

References defTable.

DefUseTable& VariableRenaming::getUseTable ( )
inline

Get the table of uses for every node.

Returns
Use Table.

Definition at line 525 of file VariableRenaming.h.

References useTable.

const DefUseTable& VariableRenaming::getUseTable ( ) const
inline

Get the table of uses for every node.

Returns
Use Table.

Definition at line 531 of file VariableRenaming.h.

References useTable.

int VariableRenaming::getRenameNumberForNode ( const VarName var,
SgNode node 
) const

Get the rename number for the given variable and the given node.

This will return the number of the given variable as it is defined on the given node. If the provided node does not define the variable, the function will return -1.

Parameters
varThe variable to get the renumbering for.
nodeThe defining node to get the renumbering at.
Returns
The number of var @ node, or -1 if node does not define var.
SgNode* VariableRenaming::getNodeForRenameNumber ( const VarName var,
int  num 
) const

Get the node that defines the given number of the given variable.

This will return the node that defines the 'num' value of var. It will be the defining node for the variable renumbered with num of the variable var. If the provided number does not exist for var, it will return NULL.

Parameters
varThe variable to get the defining node for.
numThe renumbering of the defining node to get.
Returns
The defining node of var:num, or NULL if the renumbering does not exist.
int VariableRenaming::getMaxRenameNumberForName ( const VarName var) const

Get the number of the last rename of the given variable.

This will return the number of the last renaming of the given variable. If the given variable has no renamings, it will return -1.

Parameters
varThe variable to get the last renaming for.
Returns
The highest renaming number, or -1 if var is not renamed.
NodeVec VariableRenaming::getAllUsesForDef ( const VarName var,
int  num 
)

Retrieve a list of nodes that use the var:num specified.

This will retrieve a list of nodes that use the specified var:num combo. ex. int i = s2.y1; //Search for s:y1 will yield varRef for y1, as well as //the DotExpr and the AssignOp

Parameters
varThe variable name to find.
numThe revision of the variable to find.
Returns
A vector containing the usage nodes of the variable. Empty vector otherwise.

Referenced by getAllUsesForDef().

template<typename T >
std::vector<T*> VariableRenaming::getAllUsesForDef ( const VarName var,
int  num 
)
inline

Retrieve a list of nodes of type T that use the var:num specified.

This will retrieve a list of nodes of type T that use the specified var:num combo. ex. int i = s2.y1; //Search for s:y1,AssignOp will yield the AssignOp

Parameters
varThe variable name to find.
numThe revision of the variable to find.
Returns
A vector containing the usage nodes of the variable. Empty vector otherwise.

Definition at line 600 of file VariableRenaming.h.

References getAllUsesForDef().

NumNodeRenameTable VariableRenaming::getReachingDefsAtNode ( SgNode node)

Get name:num mappings for all reaching definitions of all variables at the node.

Parameters
nodeThe node to retrieve reaching definitions for.
Returns
A table mapping VarName->(num, defNode). Empty table otherwise.
NumNodeRenameEntry VariableRenaming::getReachingDefsAtNodeForName ( SgNode node,
const VarName var 
)

Get name:num mapping for all reaching definitions of the given variable at the node.

Parameters
nodeThe node to retrieve reaching definitions for.
varThe variable to retrieve definitions of.
Returns
A table of (num, defNode) for the given variable. Empty table otherwise.
NumNodeRenameTable VariableRenaming::getReachingDefsAtScopeEnd ( SgScopeStatement scope)

Get the final versions if all variables at the end of the given scope.

Parameters
bbThe scope to get variables for.
Returns
A table of VarName->(num, defNode) for all variables at the end of the scope. Empty table otherwise.
NumNodeRenameTable VariableRenaming::getReachingDefsAtFunctionEnd ( SgFunctionDefinition node)

Get the final versions if all variables at the end of the given function.

Parameters
nodeThe function to get variables for.
Returns
A table of VarName->(num, defNode) for all variables at the end of the function. Empty table otherwise.
NumNodeRenameEntry VariableRenaming::getReachingDefsAtFunctionEndForName ( SgFunctionDefinition node,
const VarName var 
)

Get the versions of a variable at the end of the given function.

Parameters
nodeThe function definition to get definitions for.
varThe varName to get definitions for.
Returns
A table of (num, defNode) for the given variable. Empty table otherwise.
NumNodeRenameTable VariableRenaming::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.

Parameters
statement
Returns
A table of VarName->(num, defNode) for all variables at the beginning of the statement
NumNodeRenameTable VariableRenaming::getReachingDefsAtFunctionStart ( SgFunctionDefinition node)

Get the versions of all variables at the start of the given function.

Parameters
nodeThe function to get variables for.
Returns
A table of VarName->(num, defNode) for all variables at the start of the function. Empty table otherwise.
NumNodeRenameEntry VariableRenaming::getReachingDefsAtFunctionStartForName ( SgFunctionDefinition node,
const VarName var 
)

Get the versions of a variable at the start of the given function.

Parameters
nodeThe function definition to get definitions for.
varThe varName to get definitions for.
Returns
A table of (num, defNode) for the given variable. Empty table otherwise.
NumNodeRenameTable VariableRenaming::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

Parameters
nodeThe node to get uses for.
Returns
A table mapping VarName->(num, defNode) for every varName used at node. Empty table otherwise.
NumNodeRenameTable VariableRenaming::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.

Parameters
nodeThe node to get uses for.
Returns
A table mapping VarName->(num, defNode) for every varName used at node. Empty table otherwise.
NumNodeRenameEntry VariableRenaming::getUsesAtNodeForName ( SgNode node,
const VarName var 
)

Get name:num mapping for use of the given variable at this node.

Parameters
nodeThe node to get uses for.
varThe varName to get the uses for.
Returns
A table of (num, defNode) for the given varName used at node. Empty table otherwise.
NumNodeRenameTable VariableRenaming::getDefsAtNode ( SgNode node)

Get name:num mapping for all defs at the given node.

This will return the combination of original and expanded defs on this node.

ex. s.x = 5; //This will return s.x and s (s.x is original & s is expanded)

Parameters
nodeThe node to get defs for.
Returns
A table mapping VarName->(num, defNode) for every varName defined at node. Empty table otherwise.
NumNodeRenameEntry VariableRenaming::getDefsAtNodeForName ( SgNode node,
const VarName var 
)

Get name:num mapping for def of the specified variable at the given node.

This will return the combination of original and expanded defs of the given variable on this node.

ex. s.x = 5; //(s is expanded & s.x is original) Looking for s will return this node, even though s is an expanded definition.

Parameters
nodeThe node to get defs for.
varThe variable to get defs for.
Returns
A table mapping VarName->(num, defNode) for every varName defined at node. Empty table otherwise.
NumNodeRenameTable VariableRenaming::getOriginalDefsAtNode ( SgNode node)

Get name:num mapping for all original defs at the given node.

This will return the original defs on this node.

ex. s.x = 5; //This will return s.x (s.x is original & s is expanded)

Parameters
nodeThe node to get defs for.
Returns
A table mapping VarName->(num, defNode) for every varName originally defined at node. Empty table otherwise.
NumNodeRenameEntry VariableRenaming::getOriginalDefsAtNodeForName ( SgNode node,
const VarName var 
)

Get name:num mapping for def of the specified variable at the given node.

This will return the combination of original defs of the given variable on this node.

ex. s.x = 5; //(s is expanded & s.x is original) Looking for s.x will return this node, s will return empty

Parameters
nodeThe node to get defs for.
varThe variable to get defs for.
Returns
A table mapping VarName->(num, defNode) for every varName defined at node. Empty table otherwise.
NumNodeRenameTable VariableRenaming::getExpandedDefsAtNode ( SgNode node)

Get name:num mapping for all expanded defs at the given node.

This will return the expanded defs on this node.

ex. s.x = 5; //This will return s (s.x is original & s is expanded)

Parameters
nodeThe node to get defs for.
Returns
A table mapping VarName->(num, defNode) for every varName defined via expansion at node. Empty table otherwise.
NumNodeRenameEntry VariableRenaming::getExpandedDefsAtNodeForName ( SgNode node,
const VarName var 
)

Get name:num mapping for def of the specified variable at the given node.

This will return the combination of expanded defs of the given variable on this node.

ex. s.x = 5; //(s is expanded & s.x is original) Looking for s will return this node, s.x will return empty

Parameters
nodeThe node to get defs for.
varThe variable to get defs for.
Returns
A table mapping VarName->(num, defNode) for every varName defined at node. Empty table otherwise.
NumNodeRenameTable VariableRenaming::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.

Parameters
nodeThe root of the subtree to get definitions for.
Returns
The table mapping VarName->(num, node) for every definition.
NumNodeRenameTable VariableRenaming::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.

Parameters
nodeThe root of the subtree to get definitions for.
Returns
The table mapping VarName->(num, node) for every definition.
static bool VariableRenaming::isPrefixOfName ( VarName  name,
VarName  prefix 
)
static

Find if the given prefix is a prefix of the given name.

This will return whether the given name has the given prefix inside it.

ex. a.b.c has prefix a.b, but not a.c

Parameters
nameThe name to search.
prefixThe prefix to search for.
Returns
Whether or not the prefix is in this name.
static VarUniqueName* VariableRenaming::getUniqueName ( SgNode node)
static

Get the uniqueName attribute for the given node.

Parameters
nodeNode to get the attribute from.
Returns
The attribute, or NULL.
static VarName VariableRenaming::getVarName ( SgNode node)
static

Get the variable name of the given node.

Parameters
nodeThe node to get the name for.
Returns
The name, or empty name.
static bool VariableRenaming::isFromLibrary ( SgFunctionDeclaration node)
static

Gets whether or not the function is from a library.

This method checks if the variable is compiler generated, and if its filename has "/include/" in it. If so, it will return true. Otherwise, it returns false.

Parameters
nodeThe function to check.
Returns
true if initName is from a library, false if otherwise.
static SgExpression* VariableRenaming::buildVariableReference ( const VarName var,
SgScopeStatement scope = NULL 
)
static

Get an AST fragment containing the appropriate varRefs and Dot/Arrow ops to access the given variable.

Parameters
varThe variable to construct access for.
scopeThe scope within which to construct the access.
Returns
An expression that access the given variable in the given scope.

Member Data Documentation

SgProject* VariableRenaming::project
private

The project to perform SSA Analysis on.

Definition at line 198 of file VariableRenaming.h.

bool VariableRenaming::DEBUG_MODE
private

Definition at line 199 of file VariableRenaming.h.

Referenced by getDebug().

bool VariableRenaming::DEBUG_MODE_EXTRA
private

Definition at line 200 of file VariableRenaming.h.

Referenced by getDebugExtra().

DefUseTable VariableRenaming::originalDefTable
private

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.

Definition at line 254 of file VariableRenaming.h.

Referenced by getDefTable().

DefUseTable VariableRenaming::expandedDefTable
private

This is the table of definitions that is expanded from the original table.

It is used to populate the actual def/use table.

Definition at line 259 of file VariableRenaming.h.

DefUseTable VariableRenaming::defTable
private

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.

Definition at line 265 of file VariableRenaming.h.

Referenced by getPropDefTable().

DefUseTable VariableRenaming::useTable
private

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.

Definition at line 271 of file VariableRenaming.h.

Referenced by getUseTable().

FirstDefTable VariableRenaming::firstDefList
private

Holds a list of the locations that a particular name is first defined.

This helps when backwards-inserting definitions of member variables, so that we can simply insert the definition at the first definition.

Definition at line 279 of file VariableRenaming.h.

NodeNumRenameTable VariableRenaming::nodeRenameTable
private

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.

Definition at line 285 of file VariableRenaming.h.

NumNodeRenameTable VariableRenaming::numRenameTable
private

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.

Definition at line 291 of file VariableRenaming.h.

std::string VariableRenaming::varKeyTag
static

Tag to use to retrieve unique naming key from node.

Definition at line 430 of file VariableRenaming.h.

SgInitializedName* VariableRenaming::thisDecl
static

This represents the initializedName for the 'this' keyword.

This will allow the this pointer to be versioned inside member functions.

Definition at line 436 of file VariableRenaming.h.

VarName VariableRenaming::emptyName
static

Definition at line 438 of file VariableRenaming.h.

NumNodeRenameTable VariableRenaming::emptyRenameTable
static

Definition at line 440 of file VariableRenaming.h.

NumNodeRenameEntry VariableRenaming::emptyRenameEntry
static

Definition at line 442 of file VariableRenaming.h.


The documentation for this class was generated from the following file: