@@ -65,7 +65,7 @@ class VISIBILITY_HIDDEN DSPtr {
65
65
inline bool operator !=(const DSPtr& X) const { return Raw != X.Raw ; }
66
66
inline bool operator <(const DSPtr& X) const {
67
67
VariantKind k = getKind (), Xk = X.getKind ();
68
- return k == Xk ? getPtr () < X.getPtr () : k < Xk ;
68
+ return k == Xk ? getPtr () < X.getPtr () : (( unsigned ) k) < (( unsigned ) Xk) ;
69
69
}
70
70
};
71
71
} // end anonymous namespace
@@ -76,7 +76,7 @@ namespace llvm {
76
76
return V.getKind () == DSPtr::IsValueDecl;
77
77
}
78
78
template <> inline bool isa<Stmt,DSPtr>(const DSPtr& V) {
79
- return ((unsigned ) V.getKind ()) > DSPtr::IsValueDecl;
79
+ return ((unsigned ) V.getKind ()) != DSPtr::IsValueDecl;
80
80
}
81
81
template <> struct VISIBILITY_HIDDEN cast_retty_impl<ValueDecl,DSPtr> {
82
82
typedef const ValueDecl* ret_type;
@@ -174,11 +174,12 @@ class VISIBILITY_HIDDEN GRConstants : public CFGStmtVisitor<GRConstants> {
174
174
NodeSetTy* Nodes;
175
175
NodeSetTy* OldNodes;
176
176
StateTy CurrentState;
177
+ NodeTy* InitialPred;
177
178
178
179
public:
179
180
GRConstants () : Liveness(NULL ), Builder(NULL ), cfg(NULL ),
180
181
Nodes (&NodeSetA), OldNodes(&NodeSetB),
181
- CurrentState(StateMgr.GetEmptyMap()) {}
182
+ CurrentState(StateMgr.GetEmptyMap()), InitialPred( NULL ) {}
182
183
183
184
~GRConstants () { delete Liveness; }
184
185
@@ -197,7 +198,9 @@ class VISIBILITY_HIDDEN GRConstants : public CFGStmtVisitor<GRConstants> {
197
198
void ProcessStmt (Stmt* S, NodeBuilder& builder);
198
199
void SwitchNodeSets ();
199
200
void DoStmt (Stmt* S);
200
- StateTy RemoveGrandchildrenMappings (Stmt* S, StateTy M);
201
+
202
+ StateTy RemoveDescendantMappings (Stmt* S, StateTy M, unsigned Levels=2 );
203
+ StateTy RemoveSubExprMappings (StateTy M);
201
204
202
205
void AddBinding (Expr* E, ExprVariantTy V, bool isBlkLvl = false );
203
206
void AddBinding (ValueDecl* D, ExprVariantTy V);
@@ -224,9 +227,10 @@ void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
224
227
Builder = &builder;
225
228
Nodes->clear ();
226
229
OldNodes->clear ();
227
- NodeTy* N = Builder->getLastNode ();
228
- assert (N);
229
- OldNodes->push_back (N);
230
+ InitialPred = Builder->getLastNode ();
231
+ assert (InitialPred);
232
+ OldNodes->push_back (InitialPred);
233
+ CurrentState = RemoveSubExprMappings (InitialPred->getState ());
230
234
BlockStmt_Visit (S);
231
235
Builder = NULL ;
232
236
}
@@ -276,22 +280,51 @@ void GRConstants::SwitchNodeSets() {
276
280
}
277
281
278
282
GRConstants::StateTy
279
- GRConstants::RemoveGrandchildrenMappings (Stmt* S, GRConstants::StateTy State) {
280
-
283
+ GRConstants::RemoveSubExprMappings (StateTy M) {
284
+ #if 0
285
+ return M;
286
+ #else
287
+ for (StateTy::iterator I = M.begin (), E = M.end ();
288
+ I!=E && I.getKey ().getKind () == DSPtr::IsSubExp; ++I) {
289
+ // Note: we can assign a new map to M since the iterators are
290
+ // iterating over the tree of the original map (aren't immutable maps
291
+ // nice?).
292
+ M = StateMgr.Remove (M, I.getKey ());
293
+ }
294
+
295
+ return M;
296
+ #endif
297
+ }
298
+
299
+
300
+ GRConstants::StateTy
301
+ GRConstants::RemoveDescendantMappings (Stmt* S, GRConstants::StateTy State,
302
+ unsigned Levels) {
303
+ #if 1
304
+ return State;
305
+ #else
281
306
typedef Stmt::child_iterator iterator;
282
307
283
308
for (iterator I=S->child_begin(), E=S->child_end(); I!=E; ++I)
284
- if (Stmt* C = *I)
285
- for (iterator CI=C-> child_begin (), CE=C-> child_end (); CI!=CE; ++CI ) {
309
+ if (Stmt* C = *I) {
310
+ if (Levels == 1 ) {
286
311
// Observe that this will only remove mappings to non-block level
287
312
// expressions. This is valid even if *CI is a block-level expression,
288
313
// since it simply won't be in the map in the first place.
289
314
// Note: This should also work if 'C' is a block-level expression,
290
315
// although ideally we would want to skip processing C's children.
291
- State = StateMgr.Remove (State, DSPtr (*CI,false ));
316
+ State = StateMgr.Remove(State, DSPtr(C,false));
317
+ }
318
+ else {
319
+ if (ParenExpr* P = dyn_cast<ParenExpr>(C))
320
+ State = RemoveDescendantMappings(P, State, Levels);
321
+ else
322
+ State = RemoveDescendantMappings(C, State, Levels-1);
292
323
}
324
+ }
293
325
294
326
return State;
327
+ #endif
295
328
}
296
329
297
330
void GRConstants::DoStmt (Stmt* S) {
@@ -300,10 +333,14 @@ void GRConstants::DoStmt(Stmt* S) {
300
333
301
334
for (NodeSetTy::iterator I=OldNodes->begin (), E=OldNodes->end (); I!=E; ++I) {
302
335
NodeTy* Pred = *I;
303
- CurrentState = Pred->getState ();
336
+
337
+ if (Pred != InitialPred)
338
+ CurrentState = Pred->getState ();
304
339
305
340
StateTy OldState = CurrentState;
306
- CurrentState = RemoveGrandchildrenMappings (S, CurrentState);
341
+
342
+ if (Pred != InitialPred)
343
+ CurrentState = RemoveDescendantMappings (S, CurrentState);
307
344
308
345
Visit (S);
309
346
0 commit comments