@@ -392,6 +392,15 @@ struct PromoteMem2Reg {
392
392
// / number.
393
393
SmallVector<unsigned > BBNumPreds;
394
394
395
+ // / The state of incoming values for the current DFS step.
396
+ RenamePassData::ValVector IncomingVals;
397
+
398
+ // / The state of incoming locations for the current DFS step.
399
+ RenamePassData::LocationVector IncomingLocs;
400
+
401
+ // DFS work stack.
402
+ SmallVector<RenamePassData, 8 > Worklist;
403
+
395
404
// / Whether the function has the no-signed-zeros-fp-math attribute set.
396
405
bool NoSignedZeros = false ;
397
406
@@ -423,10 +432,7 @@ struct PromoteMem2Reg {
423
432
void ComputeLiveInBlocks (AllocaInst *AI, AllocaInfo &Info,
424
433
const SmallPtrSetImpl<BasicBlock *> &DefBlocks,
425
434
SmallPtrSetImpl<BasicBlock *> &LiveInBlocks);
426
- void RenamePass (BasicBlock *BB, BasicBlock *Pred,
427
- RenamePassData::ValVector IncVals,
428
- RenamePassData::LocationVector IncLocs,
429
- std::vector<RenamePassData> &Worklist);
435
+ void RenamePass (BasicBlock *BB, BasicBlock *Pred);
430
436
bool QueuePhiNode (BasicBlock *BB, unsigned AllocaIdx, unsigned &Version);
431
437
432
438
// / Delete dbg.assigns that have been demoted to dbg.values.
@@ -438,6 +444,20 @@ struct PromoteMem2Reg {
438
444
DVR->eraseFromParent ();
439
445
DVRAssignsToDelete.clear ();
440
446
}
447
+
448
+ void pushToWorklist (BasicBlock *BB, BasicBlock *Pred,
449
+ RenamePassData::ValVector IncVals,
450
+ RenamePassData::LocationVector IncLocs) {
451
+ Worklist.emplace_back (BB, Pred, std::move (IncVals), std::move (IncLocs));
452
+ }
453
+
454
+ RenamePassData popFromWorklist () {
455
+ RenamePassData R = std::move (Worklist.back ());
456
+ Worklist.pop_back ();
457
+ IncomingVals = std::move (R.Values );
458
+ IncomingLocs = std::move (R.Locations );
459
+ return R;
460
+ }
441
461
};
442
462
443
463
} // end anonymous namespace
@@ -849,29 +869,26 @@ void PromoteMem2Reg::run() {
849
869
// Set the incoming values for the basic block to be null values for all of
850
870
// the alloca's. We do this in case there is a load of a value that has not
851
871
// been stored yet. In this case, it will get this null value.
852
- RenamePassData::ValVector Values (Allocas.size ());
872
+ IncomingVals. resize (Allocas.size ());
853
873
for (unsigned i = 0 , e = Allocas.size (); i != e; ++i)
854
- Values [i] = UndefValue::get (Allocas[i]->getAllocatedType ());
874
+ IncomingVals [i] = UndefValue::get (Allocas[i]->getAllocatedType ());
855
875
856
876
// When handling debug info, treat all incoming values as if they have unknown
857
877
// locations until proven otherwise.
858
- RenamePassData::LocationVector Locations (Allocas.size ());
878
+ IncomingLocs. resize (Allocas.size ());
859
879
860
880
// The renamer uses the Visited set to avoid infinite loops.
861
881
Visited.resize (F.getMaxBlockNumber ());
862
882
863
883
// Walks all basic blocks in the function performing the SSA rename algorithm
864
884
// and inserting the phi nodes we marked as necessary
865
- std::vector<RenamePassData> RenamePassWorkList;
866
- RenamePassWorkList.emplace_back (&F.front (), nullptr , std::move (Values),
867
- std::move (Locations));
885
+ pushToWorklist (&F.front (), nullptr , std::move (IncomingVals),
886
+ std::move (IncomingLocs));
868
887
do {
869
- RenamePassData RPD = std::move (RenamePassWorkList.back ());
870
- RenamePassWorkList.pop_back ();
888
+ RenamePassData RPD = popFromWorklist ();
871
889
// RenamePass may add new worklist entries.
872
- RenamePass (RPD.BB , RPD.Pred , std::move (RPD.Values ),
873
- std::move (RPD.Locations ), RenamePassWorkList);
874
- } while (!RenamePassWorkList.empty ());
890
+ RenamePass (RPD.BB , RPD.Pred );
891
+ } while (!Worklist.empty ());
875
892
876
893
// Remove the allocas themselves from the function.
877
894
for (Instruction *A : Allocas) {
@@ -1096,10 +1113,7 @@ static void updateForIncomingValueLocation(PHINode *PN, DebugLoc DL,
1096
1113
// /
1097
1114
// / IncomingVals indicates what value each Alloca contains on exit from the
1098
1115
// / predecessor block Pred.
1099
- void PromoteMem2Reg::RenamePass (BasicBlock *BB, BasicBlock *Pred,
1100
- RenamePassData::ValVector IncomingVals,
1101
- RenamePassData::LocationVector IncomingLocs,
1102
- std::vector<RenamePassData> &Worklist) {
1116
+ void PromoteMem2Reg::RenamePass (BasicBlock *BB, BasicBlock *Pred) {
1103
1117
// If we are inserting any phi nodes into this BB, they will already be in the
1104
1118
// block.
1105
1119
if (PHINode *APN = dyn_cast<PHINode>(BB->begin ())) {
@@ -1226,8 +1240,7 @@ void PromoteMem2Reg::RenamePass(BasicBlock *BB, BasicBlock *Pred,
1226
1240
IncomingVals = Worklist.back ().Values ;
1227
1241
IncomingLocs = Worklist.back ().Locations ;
1228
1242
}
1229
- Worklist.emplace_back (S, BB, std::move (IncomingVals),
1230
- std::move (IncomingLocs));
1243
+ pushToWorklist (S, BB, std::move (IncomingVals), std::move (IncomingLocs));
1231
1244
}
1232
1245
}
1233
1246
0 commit comments