VariableRenaming Class Reference

#include <VariableRenaming.h>

Collaboration diagram for VariableRenaming:

Collaboration graph
[legend]
List of all members.

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.


Public Types

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

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

Static Public Member Functions

static std::string keyToString (const VarName &vec)
 Get a string representation of a varName.
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.
static VarUniqueNamegetUniqueName (SgNode *node)
 Get the uniqueName attribute for the given node.
static VarName getVarName (SgNode *node)
 Get the variable name of the given node.
static bool isFromLibrary (SgFunctionDeclaration *node)
 Gets whether or not the function is from a library.
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.

Static Public Attributes

static std::string varKeyTag
 Tag to use to retrieve unique naming key from node.
static SgInitializedNamethisDecl
 This represents the initializedName for the 'this' keyword.
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.
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.
bool resolveUses (cfgNode curNode, bool *memberRefInserted, NodeVec &changedNodes)
 Called to update the uses on the current node.
void aggregatePreviousDefs (cfgNode curNode, TableEntry &results)
 Trace backwards in the cfg one step and return an aggregate of all previous defs.
bool expandMemberDefinitions (cfgNode curNode)
 Expand all member definitions (chained names) to define every name in the chain.
bool insertExpandedDefsForUse (cfgNode curNode, VarName name, NodeVec &changedNodes)
 Insert defs for member uses (chained names) that do not have an explicit def.
bool expandMemberUses (cfgNode curNode)
 Expand all member uses (chained names) to explicitly use every name in the chain.
void insertDefsForExternalVariables (SgFunctionDeclaration *function)
 Insert defs for functions that are declared outside the function scope.
std::set< VarNamegetVarsUsedInSubtree (SgNode *root)
 Returns a set of all the variables names that have uses in the subtree.
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.
bool DEBUG_MODE
bool DEBUG_MODE_EXTRA
DefUseTable originalDefTable
 This is the table of variable definition locations that is generated by the VarDefUseTraversal.
DefUseTable expandedDefTable
 This is the table of definitions that is expanded from the original table.
DefUseTable defTable
 This is the table that is populated with all the def information for all the variables at all the nodes.
DefUseTable useTable
 This is the table that is populated with all the use information for all the variables at all the nodes.
FirstDefTable firstDefList
 Holds a list of the locations that a particular name is first defined.
NodeNumRenameTable nodeRenameTable
 This holds the mapping between variables and the nodes where they are renumbered.
NumNodeRenameTable numRenameTable
 This holds the mapping between variables and the nodes where they are renumbered.

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...


Member Typedef Documentation

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

Vector of SgNode*.

typedef std::vector<SgInitializedName*> VariableRenaming::VarName

A compound variable name as used by the variable renaming.

typedef std::map<VarName, NodeVec> VariableRenaming::TableEntry

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

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

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

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

A table mapping a name to a single node.

typedef std::vector<SgInitializedName*> VariableRenaming::InitNameVec

A vector of SgInitializedName*.

typedef FilteredCFGNode<IsDefUseFilter> VariableRenaming::cfgNode

A filtered CFGNode that is used for DefUse traversal.

typedef FilteredCFGEdge<IsDefUseFilter> VariableRenaming::cfgEdge

A filtered CFGEdge that is used for DefUse traversal.

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

A vector of cfgNodes.

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

A vector of cfgEdges.

typedef std::map<SgNode*, int> VariableRenaming::NodeNumRenameEntry

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

typedef boost::unordered_map<VarName, NodeNumRenameEntry> VariableRenaming::NodeNumRenameTable

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

typedef std::map<int, SgNode*> VariableRenaming::NumNodeRenameEntry

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

typedef boost::unordered_map<VarName, NumNodeRenameEntry> VariableRenaming::NumNodeRenameTable

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


Constructor & Destructor Documentation

VariableRenaming::VariableRenaming ( SgProject proj  )  [inline]

VariableRenaming::~VariableRenaming (  )  [inline]


Member Function Documentation

void VariableRenaming::run (  ) 

bool VariableRenaming::getDebug (  )  const [inline]

bool VariableRenaming::getDebugExtra (  )  const [inline]

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:
var The variable to renumber.
node The 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:
curNode The node to merge defs onto.
memberRefInserted Reference 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:
curNode The node to resolve uses on.
memberRefInserted Reference 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:
curNode Node to traverse backwards from.
results TableEntry 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:
curNode The 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:
curNode The node to expand the uses on.
name The 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:
fileName The 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:
fileName The 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:
vec varName 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.

const DefUseTable& VariableRenaming::getDefTable (  )  const [inline]

Get the table of definitions for every node.

Returns:
Definition table.

DefUseTable& VariableRenaming::getPropDefTable (  )  [inline]

Get the defTable containing the propogated definition information.

Returns:
Def table.

const DefUseTable& VariableRenaming::getPropDefTable (  )  const [inline]

Get the defTable containing the propogated definition information.

Returns:
Def table.

DefUseTable& VariableRenaming::getUseTable (  )  [inline]

Get the table of uses for every node.

Returns:
Use Table.

const DefUseTable& VariableRenaming::getUseTable (  )  const [inline]

Get the table of uses for every node.

Returns:
Use Table.

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:
var The variable to get the renumbering for.
node The 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:
var The variable to get the defining node for.
num The 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:
var The 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:
var The variable name to find.
num The revision of the variable to find.
Returns:
A vector containing the usage nodes of the variable. Empty vector otherwise.

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:
var The variable name to find.
num The revision of the variable to find.
Returns:
A vector containing the usage nodes of the variable. Empty vector otherwise.

NumNodeRenameTable VariableRenaming::getReachingDefsAtNode ( SgNode node  ) 

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

Parameters:
node The 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:
node The node to retrieve reaching definitions for.
var The 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:
bb The 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:
node The 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:
node The function definition to get definitions for.
var The 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:
node The 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:
node The function definition to get definitions for.
var The 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:
node The 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:
node The 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:
node The node to get uses for.
var The 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:
node The 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:
node The node to get defs for.
var The 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:
node The 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:
node The node to get defs for.
var The 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:
node The 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:
node The node to get defs for.
var The 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:
node The 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:
node The 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:
name The name to search.
prefix The 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:
node Node 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:
node The 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:
node The 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:
var The variable to construct access for.
scope The 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.

bool VariableRenaming::DEBUG_MODE [private]

bool VariableRenaming::DEBUG_MODE_EXTRA [private]

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.

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.

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.

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.

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.

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.

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.

std::string VariableRenaming::varKeyTag [static]

Tag to use to retrieve unique naming key from node.

SgInitializedName* VariableRenaming::thisDecl [static]

This represents the initializedName for the 'this' keyword.

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

VarName VariableRenaming::emptyName [static]

NumNodeRenameTable VariableRenaming::emptyRenameTable [static]

NumNodeRenameEntry VariableRenaming::emptyRenameEntry [static]


The documentation for this class was generated from the following file:
Generated on Thu Dec 15 12:06:46 2011 for ROSE by  doxygen 1.4.7