Skip to content

Commit 2d700ed

Browse files
committed
More cleanups in DoStmt. The NodeSets are now vectors instead of sets, since
node caching in GREngine will guarantee that we do not insert a node twice into a nodeset. llvm-svn: 46071
1 parent 17832a4 commit 2d700ed

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

clang/Analysis/GRConstants.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/APSInt.h"
2626
#include "llvm/ADT/FoldingSet.h"
2727
#include "llvm/ADT/ImmutableMap.h"
28+
#include "llvm/ADT/SmallVector.h"
2829
#include "llvm/Support/Compiler.h"
2930

3031
using namespace clang;
@@ -159,19 +160,17 @@ class VISIBILITY_HIDDEN GRConstants : public CFGStmtVisitor<GRConstants> {
159160
// cfg - the current CFG.
160161
CFG* cfg;
161162

162-
typedef llvm::SmallPtrSet<NodeTy*,16> NodeSetTy;
163+
typedef llvm::SmallVector<NodeTy*,8> NodeSetTy;
163164
NodeSetTy NodeSetA;
164165
NodeSetTy NodeSetB;
165166
NodeSetTy* Nodes;
166167
NodeSetTy* OldNodes;
167168
StateTy CurrentState;
168169

169-
bool DoNotSwitch;
170-
171170
public:
172171
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()) {}
175174

176175
~GRConstants() { delete Liveness; }
177176

@@ -196,7 +195,6 @@ class VISIBILITY_HIDDEN GRConstants : public CFGStmtVisitor<GRConstants> {
196195
ExprVariantTy GetBinding(Expr* E);
197196

198197
void BlockStmt_VisitStmt(Stmt* S) { DoStmt(S); }
199-
void VisitStmt(Stmt* S) { DoNotSwitch = true; }
200198

201199
void VisitAssign(BinaryOperator* O);
202200
void VisitIntegerLiteral(IntegerLiteral* L);
@@ -211,8 +209,7 @@ void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
211209
OldNodes->clear();
212210
NodeTy* N = Builder->getLastNode();
213211
assert (N);
214-
OldNodes->insert(N);
215-
DoNotSwitch = true;
212+
OldNodes->push_back(N);
216213
BlockStmt_Visit(S);
217214
Builder = NULL;
218215
}
@@ -249,6 +246,8 @@ GRConstants::RemoveGrandchildrenMappings(Stmt* S, GRConstants::StateTy State) {
249246
// Observe that this will only remove mappings to non-block level
250247
// expressions. This is valid even if *CI is a block-level expression,
251248
// 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.
252251
State = StateMgr.Remove(State, DSPtr(*CI,false));
253252
}
254253

@@ -259,29 +258,23 @@ void GRConstants::DoStmt(Stmt* S) {
259258
for (Stmt::child_iterator I=S->child_begin(), E=S->child_end(); I!=E; ++I)
260259
if (*I) DoStmt(*I);
261260

262-
if (!DoNotSwitch) SwitchNodeSets();
263-
DoNotSwitch = false;
264-
265261
for (NodeSetTy::iterator I=OldNodes->begin(), E=OldNodes->end(); I!=E; ++I) {
266262
NodeTy* Pred = *I;
267263
CurrentState = Pred->getState();
268264

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);
276267

277268
Visit(S);
278269

279-
if (AlwaysGenerateNode || CurrentState != CleanedState) {
270+
if (CurrentState != OldState) {
280271
NodeTy* N = Builder->generateNode(S, CurrentState, Pred);
281-
if (N) Nodes->insert(N);
272+
if (N) Nodes->push_back(N);
282273
}
283-
else Nodes->insert(Pred);
274+
else Nodes->push_back(Pred);
284275
}
276+
277+
SwitchNodeSets();
285278
}
286279

287280
void GRConstants::VisitIntegerLiteral(IntegerLiteral* L) {

0 commit comments

Comments
 (0)