ROSE  0.11.145.0
defsAndUsesUnfilteredCfg.h
1 #pragma once
2 
3 // DQ (10/5/2014): This is more strict now that we include rose_config.h in the sage3basic.h.
4 // #include "rose.h"
5 // rose.h and sage3basic.h should not be included in librose header files. [Robb P. Matzke 2014-10-15]
6 // #include "sage3basic.h"
7 
8 #include <uniqueNameTraversal.h>
9 #include <map>
10 #include <virtualCFG.h>
11 
12 namespace ssa_unfiltered_cfg
13 {
14 
16  class ChildUses
17  {
18  private:
20  SgVarRefExp* currentVar;
21 
23  std::set<SgVarRefExp*> uses;
24 
25  public:
26 
28  ChildUses() : currentVar(NULL) { }
29 
30  ChildUses(SgVarRefExp* useNode, SgVarRefExp* var)
31  {
32  uses.insert(useNode);
33  currentVar = var;
34  }
35 
40  ChildUses(const std::set<SgVarRefExp*>& useTree, SgVarRefExp* var = NULL)
41  {
42  uses = useTree;
43  currentVar = var;
44  }
45 
50  std::set<SgVarRefExp*>& getUses()
51  {
52  return uses;
53  }
54 
59  void setUses(const std::set<SgVarRefExp*>& newUses)
60  {
61  uses = newUses;
62  }
63 
64  SgVarRefExp* getCurrentVar() const
65  {
66  return currentVar;
67  }
68  };
69 
73  class DefsAndUsesTraversal : private AstBottomUpProcessing<ChildUses>
74  {
75  public:
76 
77  typedef std::map<CFGNode, std::set<ssa_private::UniqueNameTraversal::VarName> > CFGNodeToVarsMap;
78 
81  static void CollectDefsAndUses(SgNode* traversalRoot, CFGNodeToVarsMap& defs,
82  std::map<SgNode*, std::set<SgVarRefExp*> >& uses);
83 
84  private:
86  CFGNodeToVarsMap cfgNodeToDefinedVars;
87 
89  std::map<SgNode*, std::set<SgVarRefExp*> > astNodeToUsedVars;
90 
91  public:
92 
102 
103  private:
104 
106  void addUsesToNode(SgNode* node, std::set<SgVarRefExp*> uses);
107 
109  void addDefForVarAtNode(SgVarRefExp* var, const CFGNode& node);
110 
111  };
112 
113 } //namespace ssa_unfiltered_cfg
114 
Attribute Evaluator for synthesized attributes.
This class collects all the defs and uses associated with each node in the traversed CFG...
Attribute that describes the variables used by a given expression.
ChildUses()
Create the attribute with no refs.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9846
void setUses(const std::set< SgVarRefExp * > &newUses)
Set the uses for this node and below.
virtual ChildUses evaluateSynthesizedAttribute(SgNode *node, SynthesizedAttributesList attrs)
Called to evaluate the synthesized attribute on every node.
This class represents the variable refernece in expressions.
std::set< SgVarRefExp * > & getUses()
Get the uses for this node and below.
static void CollectDefsAndUses(SgNode *traversalRoot, CFGNodeToVarsMap &defs, std::map< SgNode *, std::set< SgVarRefExp * > > &uses)
Call this method to collect defs and uses for a subtree.
ChildUses(const std::set< SgVarRefExp * > &useTree, SgVarRefExp *var=NULL)
Create the attribute with the def and list of uses.