ROSE  0.9.9.139
sgnAnalysis.h
1 #ifndef SGN_ANALYSIS_H
2 #define SGN_ANALYSIS_H
3 
4 #include "genericDataflowCommon.h"
5 #include "VirtualCFGIterator.h"
6 #include "cfgUtils.h"
7 #include "CallGraphTraverse.h"
8 #include "analysisCommon.h"
9 #include "analysis.h"
10 #include "dataflow.h"
11 #include "latticeFull.h"
12 #include "liveDeadVarAnalysis.h"
13 #include "printAnalysisStates.h"
14 
15 extern int sgnAnalysisDebugLevel;
16 
17 // Maintains sign information about live variables. If a given variable may be either positive or negative, this object becomes top.
18 // There is one SgnLattice object for every variable
19 class SgnLattice : public FiniteLattice
20 {
21  public:
22 
23  // The different levels of this lattice
24  typedef enum{
25  // this object is uninitialized
26  uninitialized,
27  // no information is known about the value of the variable
28  bottom,
29  // this variable is = 0
30  eqZero,
31  // the sign of the variable is known
32  sgnKnown,
33  // this variable can be either positive or negative
34  top} sgnLevels;
35 
36  // The different states of this lattice (in level sgnKnown)
37  typedef enum{
38  // This variable's state is unknown
39  unknown,
40  // This variable is positive or =zero
41  posZero,
42  // This variable is negative or =zero
43  negZero} sgnStates;
44 
45  private:
46 
47  sgnStates sgnState;
48 
49  private:
50  // this object's current level in the lattice: (uninitialized, bottom, sgnKnown, top)
51  sgnLevels level;
52 
53  public:
54 
55  SgnLattice()
56  {
57  sgnState = unknown;
58  level=uninitialized;
59  }
60 
61  SgnLattice(const SgnLattice& that)
62  {
63  this->sgnState = that.sgnState;
64  this->level = that.level;
65  }
66 
67  SgnLattice(long val)
68  {
69  if(val == 0)
70  this->level = eqZero;
71  else {
72  this->level = sgnKnown;
73  if(val > 0) this->sgnState = posZero;
74  else this->sgnState = negZero;
75  }
76  }
77 
78  // Ensures that the state of this lattice is initialized
79  void initialize()
80  {
81  if(level == uninitialized)
82  {
83  sgnState=unknown;
84  level=bottom;
85  }
86  }
87 
88  // returns a copy of this lattice
89  Lattice* copy() const;
90 
91  // overwrites the state of this Lattice with that of that Lattice
92  void copy(Lattice* that);
93 
94  // overwrites the state of this Lattice with that of that Lattice
95  // returns true if this causes this lattice to change and false otherwise
96  bool copyMod(Lattice* that_arg);
97 
98  // computes the meet of this and that and saves the result in this
99  // returns true if this causes this to change and false otherwise
100  bool meetUpdate(Lattice* that);
101 
102  bool operator==(Lattice* that);
103 
104  // returns the current state of this object
105  sgnStates getSgnState() const;
106  sgnLevels getLevel() const;
107 
108  // Sets the state of this lattice to bottom
109  // returns true if this causes the lattice's state to change, false otherwise
110  bool setBot();
111 
112  // Sets the state of this lattice to eqZero.
113  // returns true if this causes the lattice's state to change, false otherwise
114  bool setEqZero();
115 
116  // Sets the state of this lattice to sgnKnown, with the given sign.
117  // returns true if this causes the lattice's state to change, false otherwise
118  bool setSgnKnown(sgnStates sgnState);
119 
120  // Sets the state of this lattice to sgnKnown, with the sign of the given value.
121  // returns true if this causes the lattice's state to change, false otherwise
122  bool set(int val);
123 
124  // Sets the state of this lattice to top
125  // returns true if this causes the lattice's state to change, false otherwise
126  bool setTop();
127 
128  // Increments the state of this object by increment
129  // returns true if this causes the lattice's state to change, false otherwise
130  bool plus(long increment);
131 
132  // Increments the state of this object by the contents of that
133  // returns true if this causes the lattice's state to change, false otherwise
134  bool plus(const SgnLattice& that);
135 
136  // Decrements the state of this object by increment
137  // returns true if this causes the lattice's state to change, false otherwise
138  bool minus(long increment);
139 
140  // Decrements the state of this object by the contents of that
141  // returns true if this causes the lattice's state to change, false otherwise
142  bool minus(const SgnLattice& that);
143 
144  // Negates the state of the object
145  // returns true if this causes the lattice's state to change, false otherwise
146  bool negate();
147 
148  // Multiplies and/or divides the state of this object by value
149  // returns true if this causes the lattice's state to change, false otherwise
150  bool multdiv(long multiplier);
151 
152  // Multiplies and/or divides the state of this object by the contents of that
153  // returns true if this causes the lattice's state to change, false otherwise
154  bool multdiv(const SgnLattice& that);
155 
156  // Applies a generic complex operation to this and that objects, storing the results in this object
157  // returns true if this causes the lattice's state to change, false otherwise
158  bool complexOp(const SgnLattice& that);
159 
160  string str(string indent="");
161 };
162 
164 {
165  protected:
166  static map<varID, Lattice*> constVars;
167  static bool constVars_init;
168 
169  // The LiveDeadVarsAnalysis that identifies the live/dead state of all application variables.
170  // Needed to create a FiniteVarsExprsProductLattice.
171  LiveDeadVarsAnalysis* ldva;
172 
173  public:
175  {
176  this->ldva = ldva;
177  }
178 
179  // generates the initial lattice state for the given dataflow node, in the given function, with the given NodeState
180  //vector<Lattice*> genInitState(const Function& func, const DataflowNode& n, const NodeState& state);
181  void genInitState(const Function& func, const DataflowNode& n, const NodeState& state,
182  vector<Lattice*>& initLattices, vector<NodeFact*>& initFacts);
183 
184  bool transfer(const Function& func, const DataflowNode& n, NodeState& state, const vector<Lattice*>& dfInfo);
185 };
186 
187 // prints the Lattices set by the given SgnAnalysis
188 void printSgnAnalysisStates(SgnAnalysis* sa, string indent="");
189 
190 
191 #endif
Definition: lattice.h:9