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;
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);