19#include <boost/foreach.hpp>
20#include <filteredCFG.h>
21#include <boost/unordered_map.hpp>
22#include "reachingDef.h"
23#include "dataflowCfgFilter.h"
25#include "uniqueNameTraversal.h"
34#define DEBUG_SSA_FILTER 0
38 ROSE_ASSERT(funcDecl != NULL);
41 bool returnValue =
true;
46 printf (
"In FunctionFilter::operator():funcDecl = %p = %s name = %s: filename = %s \n",funcDecl,funcDecl->
class_name().c_str(),funcDecl->get_name().str(),filename.c_str());
48 if (filename.find(
"include") != std::string::npos)
58 bool functionDefinitionIsCompilerGenerated = definingFunction != NULL ? definingFunction->
isCompilerGenerated() :
false;
61 printf (
"definingFunction = %p functionDefinitionIsCompilerGenerated = %s \n",definingFunction,functionDefinitionIsCompilerGenerated ?
"true" :
"false");
64 if (returnValue ==
true && functionDefinitionIsCompilerGenerated && !isSgTemplateInstantiationFunctionDecl(funcDecl)
65 && !isSgTemplateInstantiationMemberFunctionDecl(funcDecl))
68 printf (
"In FunctionFilter::operator(): compiler generated and is NOT a template instantiation function or member function: setting returnValue == false \n");
77 printf (
"In FunctionFilter::operator(): funcDecl->get_definingDeclaration() == NULL: setting returnValue == false \n");
83 printf (
"Leaving FunctionFilter::operator(): funcDecl = %p = %s name = %s returnValue = %s \n",funcDecl,funcDecl->
class_name().c_str(),funcDecl->get_name().str(),returnValue ?
"true" :
"false");
109 typedef std::vector<SgInitializedName*>
VarName;
120 typedef boost::shared_ptr<ReachingDef> ReachingDefPtr;
129 typedef boost::unordered_map<SgNode*, NodeReachingDefTable>
UseTable;
165 boost::unordered_map<SgNode*, NodeReachingDefTable> ssaLocalDefTable;
181 void run(
bool interprocedural,
bool treatPointersAsStructures);
183 static bool getDebug()
188 static bool getDebugExtra()
199 static bool isBuiltinVar(
const VarName& var);
248 std::multimap< FilteredCfgNode, std::pair<FilteredCfgNode, FilteredCfgEdge> > insertPhiFunctions(
SgFunctionDefinition* function,
249 const std::vector<FilteredCfgNode>& cfgNodesInPostOrder);
258 void renumberAllDefinitions(
SgFunctionDefinition* func,
const std::vector<FilteredCfgNode>& cfgNodesInPostOrder);
262 void updateIncomingPropagatedDefs(FilteredCfgNode cfgNode);
266 bool propagateDefs(FilteredCfgNode cfgNode);
271 void buildUseTable(
const std::vector<FilteredCfgNode>& cfgNodes);
282 void interproceduralDefPropagation(
const boost::unordered_set<SgFunctionDefinition*>& interestingFunctions);
287 std::vector<SgFunctionDefinition*> calculateInterproceduralProcessingOrder(
288 const boost::unordered_set<SgFunctionDefinition*>& interestingFunctions);
293 const boost::unordered_map<SgFunctionDefinition*, SgGraphNode*>& graphNodeToFunction,
294 std::vector<SgFunctionDefinition*> &processingOrder, std::set<SgFunctionDefinition*> visited);
302 bool insertInterproceduralDefs(
SgFunctionDefinition* funcDef,
const boost::unordered_set<SgFunctionDefinition*>& processed,
310 const boost::unordered_set<SgFunctionDefinition*>& processed,
ClassHierarchyWrapper* classHierarchy);
318 static bool varRequiresThisPointer(
const VarName& var);
330 static bool isDeepConstPointer(
SgType* type);
334 static bool isPointerToDeepConst(
SgType* type);
338 static bool isArgumentNonConstReferenceOrPointer(
SgInitializedName* formalArgument);
342 void printToDOT(
SgSourceFile* file, std::ofstream &outFile);
343 void printToFilteredDOT(
SgSourceFile* file, std::ofstream &outFile);
348 static VarName emptyName;
358 void toDOT(
const std::string fileName);
369 void printOriginalDefs(
SgNode* node);
370 void printOriginalDefTable();
382 return originalDefTable;
385 LocalDefUseTable& getLocalUsesTable()
387 return localUsesTable;
SgDeclarationStatement * get_definingDeclaration() const
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
This class represents the concept of a C++ function call (which is an expression).
This class represents the concept of a function declaration statement.
virtual std::string class_name() const override
returns a string representing the class name
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents the notion of a declared variable.
bool isCompilerGenerated() const
Simple test for if this is a compiler generated node.
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
This class represents the concept of a member function declaration statement.
This class represents the base class for all IR nodes within Sage III.
This class represents a source project, with a list of SgFile objects and global information about th...
static int get_verbose(void)
DQ: Modified to accept a value on the command line (no longer a boolean variable) value of 0 means qu...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents the base class for all types.
const char * get_filename() const
Returns filename of source code associated with IR node.
Static single assignment analysis.
static std::string varnameToString(const VarName &vec)
Get a string representation of a varName.
static const VarName & getVarName(SgNode *node)
Get the variable name of the given node.
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...
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.
std::set< VarName > getVarsDefinedInSubtree(SgNode *root) const
Given a node, traverses all its children in the AST and collects all the variable names that have def...
static ssa_private::VarUniqueName * getUniqueName(SgNode *node)
Get the uniqueName attribute for the given node.
static const VarName & getVarForExpression(SgNode *node)
If an expression evaluates to a reference of a variable, returns that variable.
void run(bool interprocedural, bool treatPointersAsStructures)
Run the analysis.
const NodeReachingDefTable & getReachingDefsAtNode_(SgNode *node) const
Returns the definitions of all the variables immediately before the given node has executed.
void toFilteredDOT(const std::string fileName)
Print the CFG with any UniqueNames and Def/Use information visible.
std::map< VarName, ReachingDefPtr > NodeReachingDefTable
A map from each variable to its reaching definitions at the current node.
boost::unordered_map< SgNode *, std::pair< NodeReachingDefTable, NodeReachingDefTable > > GlobalReachingDefTable
The first table is the IN table.
FilteredCFGEdge< ssa_private::DataflowCfgFilter > FilteredCfgEdge
A filtered CFGEdge that is used for DefUse traversal.
boost::unordered_map< SgNode *, NodeReachingDefTable > UseTable
Map from each node to the variables used at that node and their reaching definitions.
const NodeReachingDefTable & getOutgoingDefsAtNode(SgNode *node) const
Returns the definitions of all the variables right after the given node has executed.
FilteredCFGNode< ssa_private::DataflowCfgFilter > FilteredCfgNode
A filtered CFGNode that is used for DefUse traversal.
std::vector< SgInitializedName * > VarName
A compound variable name as used by the variable renaming.
LocalDefUseTable & getOriginalDefTable()
Get the table of definitions for every node.
static bool isPrefixOfName(VarName name, VarName prefix)
Find if the given prefix is a prefix of the given name.
const NodeReachingDefTable & getDefsAtNode(SgNode *node) const
Returns a list of all the variables defined at the given node.
boost::unordered_map< SgNode *, std::set< VarName > > LocalDefUseTable
Describes the defs or uses at each node.
NodeReachingDefTable getLastVersions(SgFunctionDeclaration *func) const
Returns the last encountered definition of every variable.
std::set< VarName > getOriginalVarsDefinedInSubtree(SgNode *root) const
Given a node, traverses all its children in the AST and collects all the variable names that have ori...
void toDOT(const std::string fileName)
Print the CFG with any UniqueNames and Def/Use information visible.
std::set< VarName > getVarsUsedInSubtree(SgNode *root) const
Returns a set of all the variables names that have uses in the subtree.
const NodeReachingDefTable & getUsesAtNode(SgNode *node) const
Returns a list of all the variables used at this node.
Class holding a unique name for a variable.
This filter determines which function declarations get processed in the analysis.