ROSE 0.11.145.237
ssaUnfilteredCfg.h
1//Author: George Vulov <georgevulov@hotmail.com>
2#pragma once
3
4// DQ (10/5/2014): This is more strict now that we include rose_config.h in the sage3basic.h.
5// #include "rose.h"
6// rose.h and sage3basic.h should not be included in librose header files. [Robb P. Matzke 2014-10-15]
7// #include "sage3basic.h"
8
9#include <string>
10#include <iostream>
11#include <map>
12#include <set>
13#include <vector>
14#include <algorithm>
15#include <ostream>
16#include <fstream>
17#include <sstream>
18#include <boost/foreach.hpp>
19#include "filteredCFG.h"
20#include <boost/unordered_map.hpp>
21#include "reachingDefUnfilteredCfg.h"
22#include "CallGraph.h"
23#include <uniqueNameTraversal.h>
24
25namespace ssa_unfiltered_cfg
26{
27
30 {
31
32 bool operator()(SgFunctionDeclaration * funcDecl)
33 {
34 ROSE_ASSERT(funcDecl != NULL);
35 bool returnValue = true;
36
37 //Exclude compiler generated functions, but keep template instantiations
38 if (funcDecl->get_file_info()->isCompilerGenerated() && !isSgTemplateInstantiationFunctionDecl(funcDecl)
39 && !isSgTemplateInstantiationMemberFunctionDecl(funcDecl))
40 returnValue = false;
41
42 //We don't process functions that don't have definitions
43 if (funcDecl->get_definingDeclaration() == NULL)
44 returnValue = false;
45
46 return returnValue;
47 }
48 };
49
65 {
66 private:
68 SgProject* project;
69
70 public:
71
73 typedef std::vector<SgInitializedName*> VarName;
74
75 typedef boost::shared_ptr<ReachingDef> ReachingDefPtr;
76
78 typedef std::map<VarName, ReachingDefPtr> NodeReachingDefTable;
79
80 typedef std::map<CFGNode, std::set<VarName> > CFGNodeToVarNamesMap;
81
82 typedef std::map<SgNode*, std::set<SgVarRefExp*> > ASTNodeToVarRefsMap;
83
84 typedef std::map<CFGNode, NodeReachingDefTable> CFGNodeToDefTableMap;
85
86 private:
87
88 ASTNodeToVarRefsMap astNodeToUses;
89
92 CFGNodeToDefTableMap localDefTable;
93
96 CFGNodeToDefTableMap reachingDefTable;
97
100 CFGNodeToDefTableMap outgoingDefTable;
101
102 public:
103
104 SSA_UnfilteredCfg(SgProject* proj) : project(proj) { }
105
107
109 void run();
110
111 static bool getDebug()
112 {
113 return SgProject::get_verbose() > 0;
114 }
115
116 static bool getDebugExtra()
117 {
118 return SgProject::get_verbose() > 1;
119 }
120
121 private:
124 void runDefUseDataFlow(SgFunctionDefinition* func);
125
127 static bool isBuiltinVar(const VarName& var);
128
142 void expandParentMemberDefinitions(const CFGNodeToVarNamesMap& defs);
143
148 void insertDefsForChildMemberUses(const CFGNodeToVarNamesMap& defs, const std::set<VarName>& usedNames);
149
151 void insertDefsForExternalVariables(SgFunctionDefinition* function, const std::set<VarName>& usedNames);
152
157 void insertPhiFunctions(SgFunctionDefinition* function, const std::vector<CFGNode>& cfgNodesInPostOrder);
158
163 void renumberAllDefinitions(SgFunctionDefinition* func, const std::vector<CFGNode>& cfgNodesInPostOrder);
164
167 void updateIncomingPropagatedDefs(const CFGNode& cfgNode);
168
171 bool propagateDefs(const CFGNode& cfgNode);
172
175 static std::vector<CFGNode> getCfgNodesInPostorder(SgFunctionDefinition* func);
176
177
178 //------------ GRAPH OUTPUT FUNCTIONS ------------ //
179
180 void printToDOT(SgNode* root, std::ostream &outFile);
181 void printToFilteredDOT(SgSourceFile* file, std::ofstream &outFile);
182
183 public:
184 //External static helper functions/variables
185
186 static VarName emptyName;
187
188 /*
189 * Printing functions.
190 */
191
196 void toDOT(const std::string fileName);
197
205 void toFilteredDOT(const std::string fileName);
206
207
208 //------------ DEF/USE TABLE ACCESS FUNCTIONS ------------ //
209
211 const NodeReachingDefTable& getReachingDefsBefore(const CFGNode& node) const;
212
216 const NodeReachingDefTable& getReachingDefsAfter(const CFGNode& node) const;
217
220 const NodeReachingDefTable& getDefsAtNode(const CFGNode& node) const;
221
225
229
232
235 const std::set<SgVarRefExp*>& getUsesAtNode(SgNode* astNode) const;
236
239 const ReachingDefPtr getDefinitionForUse(SgVarRefExp* astNode) const;
240
243 const ASTNodeToVarRefsMap& getUseTable() const;
244
245 //------------ STATIC UTILITY FUNCTIONS FUNCTIONS ------------ //
246
257 static bool isPrefixOfName(VarName name, VarName prefix);
258
265
271 static const VarName& getVarName(SgNode* node);
272
276 static const VarName& getVarForExpression(SgNode* node);
277
285
291 static std::string varnameToString(const VarName& vec);
292
293 static void printNodeDefTable(const NodeReachingDefTable& table);
294 static void printFullDefTable(const CFGNodeToDefTableMap& defTable);
295 };
296
297} //namespace ssa_unfiltered_cfg
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 function declaration statement.
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
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 variable refernece in expressions.
bool isCompilerGenerated() const
Returns true only if compiler generated (either by the front-end or by ROSE).
Class holding a unique name for a variable.
void toFilteredDOT(const std::string fileName)
Print the CFG with any UniqueNames and Def/Use information visible.
const NodeReachingDefTable & getDefsAtNode(const CFGNode &node) const
Returns the definitions that occur at the given node.
void toDOT(const std::string fileName)
Print the CFG with any UniqueNames and Def/Use information visible.
static const VarName & getVarForExpression(SgNode *node)
If an expression evaluates to a reference of a variable, returns that variable.
const ReachingDefPtr getDefinitionForUse(SgVarRefExp *astNode) const
Given a use obtained through getUsesAtNode, resolve its corresponding def.
const NodeReachingDefTable & getReachingDefsBefore(SgNode *astNode) const
Get the reaching definitions before the given AST node is executed.
const NodeReachingDefTable & getLastVersions(SgFunctionDefinition *astNode) const
Get the final versions of all the variables at the end of the given function.
std::map< VarName, ReachingDefPtr > NodeReachingDefTable
A map from each variable to its reaching definitions at the current 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 std::string varnameToString(const VarName &vec)
Get a string representation of a varName.
const NodeReachingDefTable & getReachingDefsAfter(const CFGNode &node) const
Returns the reaching definitions after the given node was executed.
static ssa_private::VarUniqueName * getUniqueName(SgNode *node)
Get the uniqueName attribute for the given node.
const std::set< SgVarRefExp * > & getUsesAtNode(SgNode *astNode) const
Returns all the SgVarRef objects that are used in the execution of the given AST node.
const ASTNodeToVarRefsMap & getUseTable() const
Returns the entire use table, mapping each non-statement AST node to the variables used in its execut...
static const VarName & getVarName(SgNode *node)
Get the variable name of the given node.
static bool isPrefixOfName(VarName name, VarName prefix)
Find if the given prefix is a prefix of the given name.
const NodeReachingDefTable & getReachingDefsBefore(const CFGNode &node) const
Returns the reaching definitions before the given node was executed.
const NodeReachingDefTable & getReachingDefsAfter(SgNode *astNode) const
Get the reaching definitions after the given AST node is executed.
std::vector< SgInitializedName * > VarName
A compound variable name as used by the variable renaming.
This filter determines which function declarations get processed in the analysis.