ROSE 0.11.145.147
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
StaticSingleAssignment Class Reference

Description

Static single assignment analysis.

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 100 of file staticSingleAssignment.h.

#include <midend/programAnalysis/staticSingleAssignment/staticSingleAssignment.h>

Collaboration diagram for StaticSingleAssignment:
Collaboration graph
[legend]

Public Types

typedef std::vector< SgInitializedName * > VarName
 A compound variable name as used by the variable renaming.
 
typedef boost::unordered_map< SgNode *, std::set< VarName > > LocalDefUseTable
 Describes the defs or uses at each node.
 
typedef FilteredCFGNode< ssa_private::DataflowCfgFilterFilteredCfgNode
 A filtered CFGNode that is used for DefUse traversal.
 
typedef FilteredCFGEdge< ssa_private::DataflowCfgFilterFilteredCfgEdge
 A filtered CFGEdge that is used for DefUse traversal.
 
typedef boost::shared_ptr< ReachingDefReachingDefPtr
 
typedef std::map< VarName, ReachingDefPtr > NodeReachingDefTable
 A map from each variable to its reaching definitions at the current node.
 
typedef boost::unordered_map< SgNode *, std::pair< NodeReachingDefTable, NodeReachingDefTable > > GlobalReachingDefTable
 The first table is the IN table.
 
typedef boost::unordered_map< SgNode *, NodeReachingDefTableUseTable
 Map from each node to the variables used at that node and their reaching definitions.
 

Public Member Functions

 StaticSingleAssignment (SgProject *proj)
 
void run (bool interprocedural, bool treatPointersAsStructures)
 Run the analysis.
 
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 printOriginalDefs (SgNode *node)
 
void printOriginalDefTable ()
 
LocalDefUseTablegetOriginalDefTable ()
 Get the table of definitions for every node.
 
LocalDefUseTablegetLocalUsesTable ()
 
const NodeReachingDefTablegetOutgoingDefsAtNode (SgNode *node) const
 Returns the definitions of all the variables right after the given node has executed.
 
const NodeReachingDefTablegetReachingDefsAtNode_ (SgNode *node) const
 Returns the definitions of all the variables immediately before the given node has executed.
 
const NodeReachingDefTablegetUsesAtNode (SgNode *node) const
 Returns a list of all the variables used at this node.
 
const NodeReachingDefTablegetDefsAtNode (SgNode *node) const
 Returns a list of all the variables defined at the given node.
 
std::set< VarNamegetVarsUsedInSubtree (SgNode *root) const
 Returns a set of all the variables names that have uses in the subtree.
 
std::set< VarNamegetVarsDefinedInSubtree (SgNode *root) const
 Given a node, traverses all its children in the AST and collects all the variable names that have definitions in the subtree.
 
std::set< VarNamegetOriginalVarsDefinedInSubtree (SgNode *root) const
 Given a node, traverses all its children in the AST and collects all the variable names that have original definitions in the subtree.
 
NodeReachingDefTable getLastVersions (SgFunctionDeclaration *func) const
 Returns the last encountered definition of every variable.
 

Static Public Member Functions

static bool getDebug ()
 
static bool getDebugExtra ()
 
static bool isPrefixOfName (VarName name, VarName prefix)
 Find if the given prefix is a prefix of the given name.
 
static ssa_private::VarUniqueNamegetUniqueName (SgNode *node)
 Get the uniqueName attribute for the given node.
 
static const VarNamegetVarName (SgNode *node)
 Get the variable name of the given node.
 
static const VarNamegetVarForExpression (SgNode *node)
 If an expression evaluates to a reference of a variable, returns that variable.
 
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 bool isVarInScope (const VarName &var, SgNode *scope)
 Finds the scope of the given node, and returns true if the given variable is accessible there.
 
static std::string varnameToString (const VarName &vec)
 Get a string representation of a varName.
 
static void printLocalDefUseTable (const LocalDefUseTable &table)
 

Static Public Attributes

static VarName emptyName
 

Member Typedef Documentation

◆ VarName

A compound variable name as used by the variable renaming.


Definition at line 109 of file staticSingleAssignment.h.

◆ LocalDefUseTable

typedef boost::unordered_map<SgNode*, std::set<VarName> > StaticSingleAssignment::LocalDefUseTable

Describes the defs or uses at each node.

This is for local, rather than propagated, information.

Definition at line 112 of file staticSingleAssignment.h.

◆ FilteredCfgNode

A filtered CFGNode that is used for DefUse traversal.


Definition at line 115 of file staticSingleAssignment.h.

◆ FilteredCfgEdge

A filtered CFGEdge that is used for DefUse traversal.


Definition at line 118 of file staticSingleAssignment.h.

◆ ReachingDefPtr

typedef boost::shared_ptr<ReachingDef> StaticSingleAssignment::ReachingDefPtr

Definition at line 120 of file staticSingleAssignment.h.

◆ NodeReachingDefTable

typedef std::map<VarName, ReachingDefPtr> StaticSingleAssignment::NodeReachingDefTable

A map from each variable to its reaching definitions at the current node.

Definition at line 123 of file staticSingleAssignment.h.

◆ GlobalReachingDefTable

The first table is the IN table.

The second table is the OUT table.

Definition at line 126 of file staticSingleAssignment.h.

◆ UseTable

Map from each node to the variables used at that node and their reaching definitions.

Definition at line 129 of file staticSingleAssignment.h.

Constructor & Destructor Documentation

◆ StaticSingleAssignment()

StaticSingleAssignment::StaticSingleAssignment ( SgProject proj)
inline

Definition at line 169 of file staticSingleAssignment.h.

◆ ~StaticSingleAssignment()

StaticSingleAssignment::~StaticSingleAssignment ( )
inline

Definition at line 173 of file staticSingleAssignment.h.

Member Function Documentation

◆ run()

void StaticSingleAssignment::run ( bool  interprocedural,
bool  treatPointersAsStructures 
)

Run the analysis.

If interprocedural analysis is not enabled, functionc all expressions (SgFunctionCallExp) will not count as definitions of any variables.

Parameters
interproceduraltrue to enable interprocedural analysis, false to perform no interprocedural analysis.
treatPointersAsStructuresif true, p->x is versioned as if it were the variable p.x.

◆ getDebug()

static bool StaticSingleAssignment::getDebug ( )
inlinestatic

Definition at line 183 of file staticSingleAssignment.h.

◆ getDebugExtra()

static bool StaticSingleAssignment::getDebugExtra ( )
inlinestatic

Definition at line 188 of file staticSingleAssignment.h.

◆ toDOT()

void StaticSingleAssignment::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.

◆ toFilteredDOT()

void StaticSingleAssignment::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.

◆ getOriginalDefTable()

LocalDefUseTable & StaticSingleAssignment::getOriginalDefTable ( )
inline

Get the table of definitions for every node.

These definitions are NOT propagated.

Returns
Definition table.

Definition at line 380 of file staticSingleAssignment.h.

◆ getLocalUsesTable()

LocalDefUseTable & StaticSingleAssignment::getLocalUsesTable ( )
inline

Definition at line 385 of file staticSingleAssignment.h.

◆ getOutgoingDefsAtNode()

const NodeReachingDefTable & StaticSingleAssignment::getOutgoingDefsAtNode ( SgNode node) const

Returns the definitions of all the variables right after the given node has executed.

This function does not work correctly for "container" nodes such as SgBasicBlock, SgCommaOp, SgExprStmt. If there is a definition at the node itself, e.g. SgAssignOp, it is included in the outgoing defs.

◆ getReachingDefsAtNode_()

const NodeReachingDefTable & StaticSingleAssignment::getReachingDefsAtNode_ ( SgNode node) const

Returns the definitions of all the variables immediately before the given node has executed.

If there is a definition at the node itself, e.g. SgAssignOp, it is not included in the reaching defs.

◆ getUsesAtNode()

const NodeReachingDefTable & StaticSingleAssignment::getUsesAtNode ( SgNode node) const

Returns a list of all the variables used at this node.

Note that uses don't propagate past an SgStatement. Each use is mapped to the reaching definition to which the use corresponds.

◆ getDefsAtNode()

const NodeReachingDefTable & StaticSingleAssignment::getDefsAtNode ( SgNode node) const

Returns a list of all the variables defined at the given node.

Note that this will return an empty collections for nodes that do not modify any variables. Compare this function to getReachingDefsAtNode.

◆ getOriginalVarsDefinedInSubtree()

std::set< VarName > StaticSingleAssignment::getOriginalVarsDefinedInSubtree ( SgNode root) const

Given a node, traverses all its children in the AST and collects all the variable names that have original definitions in the subtree.

Expanded definitions are not included - for example if p.x is defined, p is not included.

◆ getLastVersions()

NodeReachingDefTable StaticSingleAssignment::getLastVersions ( SgFunctionDeclaration func) const

Returns the last encountered definition of every variable.

Variables go out of scope, so quering for reaching definitions at the end of a function doesn't return the last versions of all variables.

◆ isPrefixOfName()

static bool StaticSingleAssignment::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.

◆ getUniqueName()

static ssa_private::VarUniqueName * StaticSingleAssignment::getUniqueName ( SgNode node)
static

Get the uniqueName attribute for the given node.

Parameters
nodeNode to get the attribute from.
Returns
The attribute, or NULL.

◆ getVarName()

static const VarName & StaticSingleAssignment::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.

◆ getVarForExpression()

static const VarName & StaticSingleAssignment::getVarForExpression ( SgNode node)
static

If an expression evaluates to a reference of a variable, returns that variable.

Handles casts, comma ops, address of ops, etc. For example, Given the expression (...., &a), this method would return the VarName for a.

◆ buildVariableReference()

static SgExpression * StaticSingleAssignment::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.

◆ isVarInScope()

static bool StaticSingleAssignment::isVarInScope ( const VarName var,
SgNode scope 
)
static

Finds the scope of the given node, and returns true if the given variable is accessible there.

False if the variable is not accessible.

◆ varnameToString()

static std::string StaticSingleAssignment::varnameToString ( const VarName vec)
static

Get a string representation of a varName.

Parameters
vecvarName to get string for.
Returns
String for given varName.

Member Data Documentation

◆ emptyName

VarName StaticSingleAssignment::emptyName
static

Definition at line 348 of file staticSingleAssignment.h.


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