25
25
#include " llvm/ADT/APSInt.h"
26
26
#include " llvm/ADT/FoldingSet.h"
27
27
#include " llvm/ADT/ImmutableMap.h"
28
+ #include " llvm/ADT/SmallVector.h"
28
29
#include " llvm/Support/Compiler.h"
29
30
30
31
using namespace clang ;
@@ -159,19 +160,17 @@ class VISIBILITY_HIDDEN GRConstants : public CFGStmtVisitor<GRConstants> {
159
160
// cfg - the current CFG.
160
161
CFG* cfg;
161
162
162
- typedef llvm::SmallPtrSet <NodeTy*,16 > NodeSetTy;
163
+ typedef llvm::SmallVector <NodeTy*,8 > NodeSetTy;
163
164
NodeSetTy NodeSetA;
164
165
NodeSetTy NodeSetB;
165
166
NodeSetTy* Nodes;
166
167
NodeSetTy* OldNodes;
167
168
StateTy CurrentState;
168
169
169
- bool DoNotSwitch;
170
-
171
170
public:
172
171
GRConstants () : Liveness(NULL ), Builder(NULL ), cfg(NULL ),
173
- Nodes (&NodeSetA), OldNodes(&NodeSetB),
174
- CurrentState(StateMgr.GetEmptyMap()), DoNotSwitch( false ) {}
172
+ Nodes (&NodeSetA), OldNodes(&NodeSetB),
173
+ CurrentState(StateMgr.GetEmptyMap()) {}
175
174
176
175
~GRConstants () { delete Liveness; }
177
176
@@ -196,7 +195,6 @@ class VISIBILITY_HIDDEN GRConstants : public CFGStmtVisitor<GRConstants> {
196
195
ExprVariantTy GetBinding (Expr* E);
197
196
198
197
void BlockStmt_VisitStmt (Stmt* S) { DoStmt (S); }
199
- void VisitStmt (Stmt* S) { DoNotSwitch = true ; }
200
198
201
199
void VisitAssign (BinaryOperator* O);
202
200
void VisitIntegerLiteral (IntegerLiteral* L);
@@ -211,8 +209,7 @@ void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
211
209
OldNodes->clear ();
212
210
NodeTy* N = Builder->getLastNode ();
213
211
assert (N);
214
- OldNodes->insert (N);
215
- DoNotSwitch = true ;
212
+ OldNodes->push_back (N);
216
213
BlockStmt_Visit (S);
217
214
Builder = NULL ;
218
215
}
@@ -249,6 +246,8 @@ GRConstants::RemoveGrandchildrenMappings(Stmt* S, GRConstants::StateTy State) {
249
246
// Observe that this will only remove mappings to non-block level
250
247
// expressions. This is valid even if *CI is a block-level expression,
251
248
// since it simply won't be in the map in the first place.
249
+ // Note: This should also work if 'C' is a block-level expression,
250
+ // although ideally we would want to skip processing C's children.
252
251
State = StateMgr.Remove (State, DSPtr (*CI,false ));
253
252
}
254
253
@@ -259,29 +258,23 @@ void GRConstants::DoStmt(Stmt* S) {
259
258
for (Stmt::child_iterator I=S->child_begin (), E=S->child_end (); I!=E; ++I)
260
259
if (*I) DoStmt (*I);
261
260
262
- if (!DoNotSwitch) SwitchNodeSets ();
263
- DoNotSwitch = false ;
264
-
265
261
for (NodeSetTy::iterator I=OldNodes->begin (), E=OldNodes->end (); I!=E; ++I) {
266
262
NodeTy* Pred = *I;
267
263
CurrentState = Pred->getState ();
268
264
269
- StateTy CleanedState = RemoveGrandchildrenMappings (S, CurrentState);
270
- bool AlwaysGenerateNode = false ;
271
-
272
- if (CleanedState != CurrentState) {
273
- CurrentState = CleanedState;
274
- AlwaysGenerateNode = true ;
275
- }
265
+ StateTy OldState = CurrentState;
266
+ CurrentState = RemoveGrandchildrenMappings (S, CurrentState);
276
267
277
268
Visit (S);
278
269
279
- if (AlwaysGenerateNode || CurrentState != CleanedState ) {
270
+ if (CurrentState != OldState ) {
280
271
NodeTy* N = Builder->generateNode (S, CurrentState, Pred);
281
- if (N) Nodes->insert (N);
272
+ if (N) Nodes->push_back (N);
282
273
}
283
- else Nodes->insert (Pred);
274
+ else Nodes->push_back (Pred);
284
275
}
276
+
277
+ SwitchNodeSets ();
285
278
}
286
279
287
280
void GRConstants::VisitIntegerLiteral (IntegerLiteral* L) {
0 commit comments