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