19 #include <boost/foreach.hpp>
20 #include <filteredCFG.h>
21 #include <boost/unordered_map.hpp>
22 #include "reachingDef.h"
23 #include "dataflowCfgFilter.h"
24 #include "CallGraph.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;
138 LocalDefUseTable originalDefTable;
144 LocalDefUseTable expandedDefTable;
149 GlobalReachingDefTable reachingDefsTable;
157 LocalDefUseTable localUsesTable;
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);
367 void toFilteredDOT(
const std::string fileName);
369 void printOriginalDefs(
SgNode* node);
370 void printOriginalDefTable();
382 return originalDefTable;
385 LocalDefUseTable& getLocalUsesTable()
387 return localUsesTable;
393 const NodeReachingDefTable& getOutgoingDefsAtNode(
SgNode* node)
const;
397 const NodeReachingDefTable& getReachingDefsAtNode_(
SgNode* node)
const;
401 const NodeReachingDefTable& getUsesAtNode(
SgNode* node)
const;
405 const NodeReachingDefTable& getDefsAtNode(
SgNode* node)
const;
408 std::set<VarName> getVarsUsedInSubtree(
SgNode* root)
const;
412 std::set<VarName> getVarsDefinedInSubtree(
SgNode* root)
const;
416 std::set<VarName> getOriginalVarsDefinedInSubtree(
SgNode* root)
const;
435 static bool isPrefixOfName(VarName name, VarName prefix);
449 static const VarName& getVarName(
SgNode* node);
454 static const VarName& getVarForExpression(
SgNode* node);
466 static bool isVarInScope(
const VarName& var,
SgNode* scope);
473 static std::string varnameToString(
const VarName& vec);
475 static void printLocalDefUseTable(
const LocalDefUseTable& table);
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
virtual std::string class_name() const override
returns a string representing the class name
const char * get_filename() const ROSE_DEPRECATED_FUNCTION
Returns filename of source code associated with IR node.
boost::unordered_map< SgNode *, std::pair< NodeReachingDefTable, NodeReachingDefTable > > GlobalReachingDefTable
The first table is the IN table.
This class represents the base class for all types.
This class represents the notion of a declared variable.
This class represents the concept of a member function declaration statement.
This class represents the concept of a function declaration statement.
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope, etc.).
boost::unordered_map< SgNode *, std::set< VarName > > LocalDefUseTable
Describes the defs or uses at each node.
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.
This filter determines which function declarations get processed in the analysis. ...
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
std::map< VarName, ReachingDefPtr > NodeReachingDefTable
A map from each variable to its reaching definitions at the current node.
Static single assignment analysis.
This class represents the base class for all IR nodes within Sage III.
std::vector< SgInitializedName * > VarName
A compound variable name as used by the variable renaming.
SgDeclarationStatement * get_definingDeclaration() const
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see tha...
FilteredCFGNode< ssa_private::DataflowCfgFilter > FilteredCfgNode
A filtered CFGNode that is used for DefUse traversal.
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 a source project, with a list of SgFile objects and global information about th...
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
Class holding a unique name for a variable.
LocalDefUseTable & getOriginalDefTable()
Get the table of definitions for every node.
bool isCompilerGenerated() const
Simple test for if this is a compiler generated node.
This class represents the concept of a C++ function call (which is an expression).