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