ROSE  0.11.96.11
defsAndUsesTraversal.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 "staticSingleAssignment.h"
9 
10 namespace ssa_private
11 {
12 
14  class ChildUses
15  {
16  private:
18  SgVarRefExp* currentVar;
19 
21  std::vector<SgNode*> uses;
22 
23  public:
24 
26  ChildUses() : currentVar(NULL)
27  {
28  }
29 
30  ChildUses(SgNode* useNode, SgVarRefExp* var)
31  {
32  uses.push_back(useNode);
33  currentVar = var;
34  }
35 
40  ChildUses(const std::vector<SgNode*>& useTree, SgVarRefExp* var = NULL)
41  {
42  if (useTree.size() > 0)
43  uses.assign(useTree.begin(), useTree.end());
44  currentVar = var;
45  }
46 
51  std::vector<SgNode*>& getUses()
52  {
53  return uses;
54  }
55 
60  void setUses(const std::vector<SgNode*>& newUses)
61  {
62  uses.assign(newUses.begin(), newUses.end());
63  }
64 
65  SgVarRefExp* getCurrentVar() const
66  {
67  return currentVar;
68  }
69  };
70 
74  class DefsAndUsesTraversal : public AstBottomUpProcessing<ChildUses>
75  {
77 
80  const bool treatPointersAsStructs;
81 
82  public:
83 
86  DefsAndUsesTraversal(StaticSingleAssignment* ssa, bool treatPointersAsStructs = true) : ssa(ssa),
87  treatPointersAsStructs(treatPointersAsStructs)
88  {
89  }
90 
99  virtual ChildUses evaluateSynthesizedAttribute(SgNode* node, SynthesizedAttributesList attrs);
100 
101  private:
102 
104  void addUsesToNode(SgNode* node, std::vector<SgNode*> uses);
105 
107  void addDefForVarAtNode(SgVarRefExp* currentVar, SgNode* defNode);
108  };
109 
110 } //namespace ssa_private
111 
ssa_private::DefsAndUsesTraversal
This class collects all the defs and uses associated with each node in the traversed CFG.
Definition: defsAndUsesTraversal.h:74
ssa_private::ChildUses::getUses
std::vector< SgNode * > & getUses()
Get the uses for this node and below.
Definition: defsAndUsesTraversal.h:51
StaticSingleAssignment
Static single assignment analysis.
Definition: staticSingleAssignment.h:100
SgVarRefExp
This class represents the variable refernece in expressions.
Definition: Cxx_Grammar.h:272706
ssa_private::ChildUses::setUses
void setUses(const std::vector< SgNode * > &newUses)
Set the uses for this node and below.
Definition: defsAndUsesTraversal.h:60
AstBottomUpProcessing
Attribute Evaluator for synthesized attributes.
Definition: AstProcessing.h:289
ssa_private::ChildUses::ChildUses
ChildUses()
Create the attribute with no refs.
Definition: defsAndUsesTraversal.h:26
ssa_private::DefsAndUsesTraversal::evaluateSynthesizedAttribute
virtual ChildUses evaluateSynthesizedAttribute(SgNode *node, SynthesizedAttributesList attrs)
Called to evaluate the synthesized attribute on every node.
SgNode
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:6739
ssa_private::DefsAndUsesTraversal::DefsAndUsesTraversal
DefsAndUsesTraversal(StaticSingleAssignment *ssa, bool treatPointersAsStructs=true)
Definition: defsAndUsesTraversal.h:86
ssa_private::ChildUses
Attribute that describes the variables used by a given expression.
Definition: defsAndUsesTraversal.h:14
ssa_private::ChildUses::ChildUses
ChildUses(const std::vector< SgNode * > &useTree, SgVarRefExp *var=NULL)
Create the attribute with the def and list of uses.
Definition: defsAndUsesTraversal.h:40