ROSE  0.9.9.109
nodeConstAnalysis.h
1 #ifndef NODE_CONST_ANALYSIS_H
2 #define NODE_CONST_ANALYSIS_H
3 
4 #include "genericDataflowCommon.h"
5 #include "genUID.h"
6 #include "VirtualCFGIterator.h"
7 #include "cfgUtils.h"
8 #include "CallGraphTraverse.h"
9 #include "analysisCommon.h"
10 #include "analysis.h"
11 #include "dataflow.h"
12 #include "latticeFull.h"
13 #include "printAnalysisStates.h"
14 
15 #include <string>
16 #include <vector>
17 
18 extern int nodeConstAnalysisDebugLevel;
19 
20 // For each live variable records whether this variable has not been assigned, has one value or multiple values.
21 // There is one nodeConstAnalysisDebugLevel object for every variable
23 {
24  private:
25  // the unique ID of the value of the variable (if known)
26  unsigned long valID;
27 
28  public:
29  // The different levels of this lattice
30  // this object is uninitialized
31  static const int uninitialized=0;
32 
33  private:
34  // no information is known about the value of the variable
35  // (we haven't seen an assignment)
36  static const int bottom=1;
37  // the value of the variable is known
38  // (we've seen exactly one assignment)
39  static const int valKnown=2;
40  // this variable may have more than one value at the given CFGNode
41  static const int top=3;
42 
43  public:
44  // public names for the different levels that correspond to the final outcome of the analysis
45  static const int noAssign=bottom;
46  static const int constVal=valKnown;
47  static const int multVal=top;
48 
49  private:
50  // this object's current level in the lattice: (uninitialized, bottom, valKnown, top)
51  short level;
52 
53  public:
54 
56  {
57  valID=0;
58  level=uninitialized;
59  }
60 
62  {
63  this->valID = that.valID;
64  this->level = that.level;
65  }
66 
67  // initializes this Lattice to its default state, if it is not already initialized
68  void initialize()
69  {
70  if(level == uninitialized)
71  {
72  valID=0;
73  level=bottom;
74  }
75  }
76 
77  // returns a copy of this lattice
78  Lattice* copy() const;
79 
80  // overwrites the state of this Lattice with that of that Lattice
81  void copy(Lattice* that);
82 
83  // computes the meet of this and that and saves the result in this
84  // returns true if this causes this to change and false otherwise
85  bool meetUpdate(Lattice* that);
86 
87  // Computes the maximum of this node and that, which is just like meet
88  // except that different values get max-ed, rather than push the result to top
89  // returns true if this causes this to change and false otherwise
90  bool maxUpdate(nodeConstLattice& that);
91 
92  // If this lattice is at level valKnown, increments the value by the given amount
93  // returns true if this causes this to change and false otherwise
94  bool increment(int val=1);
95 
96  // computes the meet of this and that and returns the result
97  //Lattice* meet(Lattice* that) const;
98 
99  bool operator==(Lattice* that);
100 
101  /*private:
102  // returns this object's level
103  short getLevel() const;
104 
105  public:*/
106  // returns whether the variable is constant at the current node
107  short getValConst() const;
108 
109  // Sets the state of this lattice to bottom
110  // returns true if this causes the lattice's state to change, false otherwise
111  bool setToBottom();
112 
113  // Sets the state of this lattice to the given value.
114  // returns true if this causes the lattice's state to change, false otherwise
115  bool set(unsigned long valID);
116 
117  // Sets the state of this lattice to top
118  // returns true if this causes the lattice's state to change, false otherwise
119  bool setToTop();
120 
121  std::string str(std::string indent="");
122 };
123 
125 {
126  protected:
127  genUID uids;
128 
129  public:
131  { }
132 
133  /*// generates the initial variable-specific lattice state for a dataflow node
134  Lattice* genInitVarState(const Function& func, const DataflowNode& n, const NodeState& state);
135 
136  // generates the initial non-variable-specific lattice state for a dataflow node
137  Lattice* genInitNonVarState(const Function& func, const DataflowNode& n, const NodeState& state);*/
138 
139  // generates the initial lattice state for the given dataflow node, in the given function, with the given NodeState
140  //std::vector<Lattice*> genInitState(const Function& func, const DataflowNode& n, const NodeState& state);
141  void genInitState(const Function& func, const DataflowNode& n, const NodeState& state,
142  std::vector<Lattice*>& initLattices, std::vector<NodeFact*>& initFacts);
143 
144  bool transfer(const Function& func, const DataflowNode& n, NodeState& state, const std::vector<Lattice*>& dfInfo);
145 };
146 
147 // runs the nodeConstAnalysis on the project and returns the resulting nodeConstAnalysis object
148 nodeConstAnalysis* runNodeConstAnalysis();
149 
150 // prints the Lattices set by the given nodeConstAnalysis
151 void printNodeConstAnalysisStates(nodeConstAnalysis* da, std::string indent="");
152 
153 #endif
Definition: lattice.h:9
Definition: genUID.h:9