Class VariableRenaming

Contents

Class VariableRenaming#

Nested Relationships#

Nested Types#

Class Documentation#

class VariableRenaming#

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 std::unordered_map<SgNode*, TableEntry> DefUseTable#

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

typedef std::unordered_map<VarName, SgNode*, VectorHash<SgInitializedName*>> FirstDefTable#

A table mapping a name to a single node.

typedef std::vector<SgInitializedName*> InitNameVec#

A vector of SgInitializedName*.

typedef FilteredCFGNode<IsDefUseFilter> cfgNode#

A filtered CFGNode that is used for DefUse traversal.

typedef FilteredCFGEdge<IsDefUseFilter> cfgEdge#

A filtered CFGEdge that is used for DefUse traversal.

typedef std::vector<cfgNode> cfgNodeVec#

A vector of cfgNodes.

typedef std::vector<cfgEdge> cfgEdgeVec#

A vector of cfgEdges.

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

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

typedef std::unordered_map<VarName, NodeNumRenameEntry, VectorHash<SgInitializedName*>> 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 std::unordered_map<VarName, NumNodeRenameEntry, VectorHash<SgInitializedName*>> NumNodeRenameTable#

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

Public Functions

inline VariableRenaming(SgProject *proj)#
inline ~VariableRenaming()#
void run()#
inline bool getDebug() const#
inline bool getDebugExtra() const#
void 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 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.

void printDefs(SgNode *node)#
void printOriginalDefs(SgNode *node)#
void printOriginalDefTable()#
void printUses(SgNode *node)#
void printRenameTable()#
void printRenameTable(const VarName &var)#
inline DefUseTable &getDefTable()#

Get the table of definitions for every node.

Returns:

Definition table.

inline const DefUseTable &getDefTable() const#

Get the table of definitions for every node.

Returns:

Definition table.

inline DefUseTable &getPropDefTable()#

Get the defTable containing the propogated definition information.

Returns:

Def table.

inline const DefUseTable &getPropDefTable() const#

Get the defTable containing the propogated definition information.

Returns:

Def table.

inline DefUseTable &getUseTable()#

Get the table of uses for every node.

Returns:

Use Table.

inline const DefUseTable &getUseTable() const#

Get the table of uses for every node.

Returns:

Use Table.

int 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 *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 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 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>
inline std::vector<T*> getAllUsesForDef(const VarName &var, int num)#

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

Public Static Functions

static std::string keyToString(const VarName &vec)#

Get a string representation of a varName.

Parameters:

vec – varName to get string for.

Returns:

String for given 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.

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 *getUniqueName(SgNode *node)#

Get the uniqueName attribute for the given node.

Parameters:

node – Node to get the attribute from.

Returns:

The attribute, or NULL.

static VarName getVarName(SgNode *node)#

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 isFromLibrary(SgFunctionDeclaration *node)#

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 *buildVariableReference(const VarName &var, SgScopeStatement *scope = NULL)#

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.

Public Static Attributes

static std::string varKeyTag#

Tag to use to retrieve unique naming key from node.

static SgInitializedName *thisDecl#

This represents the initializedName for the ‘this’ keyword.

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

static VarName emptyName#
static NumNodeRenameTable emptyRenameTable#
static NumNodeRenameEntry emptyRenameEntry#