@@ -38,18 +38,19 @@ static BasicBlock *getUserBB(Use *U) {
38
38
39
39
// / Add a new variable to the SSA rewriter. This needs to be called before
40
40
// / AddAvailableValue or AddUse calls.
41
- void SSAUpdaterBulk::AddVariable (unsigned Var, StringRef Name, Type *Ty) {
42
- assert (Rewrites. find ( Var) == Rewrites.end () && " Variable added twice! " );
41
+ unsigned SSAUpdaterBulk::AddVariable (StringRef Name, Type *Ty) {
42
+ unsigned Var = Rewrites.size ( );
43
43
DEBUG (dbgs () << " SSAUpdater: Var=" << Var << " : initialized with Ty = " << *Ty
44
44
<< " , Name = " << Name << " \n " );
45
45
RewriteInfo RI (Name, Ty);
46
- Rewrites[Var] = RI;
46
+ Rewrites.push_back (RI);
47
+ return Var;
47
48
}
48
49
49
50
// / Indicate that a rewritten value is available in the specified block with the
50
51
// / specified value.
51
52
void SSAUpdaterBulk::AddAvailableValue (unsigned Var, BasicBlock *BB, Value *V) {
52
- assert (Rewrites. find ( Var) != Rewrites.end () && " Should add variable first !" );
53
+ assert (Var < Rewrites.size () && " Variable not found !" );
53
54
DEBUG (dbgs () << " SSAUpdater: Var=" << Var << " : added new available value"
54
55
<< *V << " in " << BB->getName () << " \n " );
55
56
Rewrites[Var].Defines [BB] = V;
@@ -58,7 +59,7 @@ void SSAUpdaterBulk::AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V) {
58
59
// / Record a use of the symbolic value. This use will be updated with a
59
60
// / rewritten value when RewriteAllUses is called.
60
61
void SSAUpdaterBulk::AddUse (unsigned Var, Use *U) {
61
- assert (Rewrites. find ( Var) != Rewrites.end () && " Should add variable first !" );
62
+ assert (Var < Rewrites.size () && " Variable not found !" );
62
63
DEBUG (dbgs () << " SSAUpdater: Var=" << Var << " : added a use" << *U->get ()
63
64
<< " in " << getUserBB (U)->getName () << " \n " );
64
65
Rewrites[Var].Uses .push_back (U);
@@ -67,7 +68,7 @@ void SSAUpdaterBulk::AddUse(unsigned Var, Use *U) {
67
68
// / Return true if the SSAUpdater already has a value for the specified variable
68
69
// / in the specified block.
69
70
bool SSAUpdaterBulk::HasValueForBlock (unsigned Var, BasicBlock *BB) {
70
- return Rewrites.count (Var ) ? Rewrites[Var].Defines .count (BB) : false ;
71
+ return (Var < Rewrites.size () ) ? Rewrites[Var].Defines .count (BB) : false ;
71
72
}
72
73
73
74
// Compute value at the given block BB. We either should already know it, or we
@@ -126,16 +127,14 @@ ComputeLiveInBlocks(const SmallPtrSetImpl<BasicBlock *> &UsingBlocks,
126
127
// / requested uses update.
127
128
void SSAUpdaterBulk::RewriteAllUses (DominatorTree *DT,
128
129
SmallVectorImpl<PHINode *> *InsertedPHIs) {
129
- for (auto &P : Rewrites) {
130
+ for (auto &R : Rewrites) {
130
131
// Compute locations for new phi-nodes.
131
132
// For that we need to initialize DefBlocks from definitions in R.Defines,
132
133
// UsingBlocks from uses in R.Uses, then compute LiveInBlocks, and then use
133
134
// this set for computing iterated dominance frontier (IDF).
134
135
// The IDF blocks are the blocks where we need to insert new phi-nodes.
135
136
ForwardIDFCalculator IDF (*DT);
136
- RewriteInfo &R = P.second ;
137
- DEBUG (dbgs () << " SSAUpdater: Var=" << P.first << " : rewriting "
138
- << R.Uses .size () << " use(s)\n " );
137
+ DEBUG (dbgs () << " SSAUpdater: rewriting " << R.Uses .size () << " use(s)\n " );
139
138
140
139
SmallPtrSet<BasicBlock *, 2 > DefBlocks;
141
140
for (auto &Def : R.Defines )
@@ -165,7 +164,7 @@ void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT,
165
164
}
166
165
167
166
// Fill in arguments of the inserted PHIs.
168
- for (auto PN : InsertedPHIsForVar) {
167
+ for (auto * PN : InsertedPHIsForVar) {
169
168
BasicBlock *PBB = PN->getParent ();
170
169
for (BasicBlock *Pred : PredCache.get (PBB))
171
170
PN->addIncoming (computeValueAt (Pred, R, DT), Pred);
@@ -182,8 +181,8 @@ void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT,
182
181
// Notify that users of the existing value that it is being replaced.
183
182
if (OldVal != V && OldVal->hasValueHandle ())
184
183
ValueHandleBase::ValueIsRAUWd (OldVal, V);
185
- DEBUG (dbgs () << " SSAUpdater: Var= " << P. first << " : replacing " << *OldVal
186
- << " with " << *V << " \n " );
184
+ DEBUG (dbgs () << " SSAUpdater: replacing " << *OldVal << " with " << *V
185
+ << " \n " );
187
186
U->set (V);
188
187
}
189
188
}
0 commit comments