================ @@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, BasicBlock *LoopHeaderBB, assert(DT->verify(DominatorTree::VerificationLevel::Fast)); } +static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB, + DenseMap<VPValue *, VPValue *> &Old2NewVPValues, + bool Full = false) { + for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) { + for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) { + VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I)); + if (!Full) + continue; + NewR.setOperand(I, NewOp); + } + for (const auto &[OldV, NewV] : + zip(OldR.definedValues(), NewR.definedValues())) + Old2NewVPValues[OldV] = NewV; + } +} + +VPlan *VPlan::clone() { + DenseMap<VPBlockBase *, VPBlockBase *> Old2New; + DenseMap<VPValue *, VPValue *> Old2NewVPValues; + + auto *NewPlan = new VPlan(); + SmallVector<VPValue *, 16> NewLiveIns; + for (VPValue *LI : VPLiveInsToFree) { + VPValue *NewLI = new VPValue(LI->getLiveInIRValue()); + NewPlan->VPLiveInsToFree.push_back(NewLI); + Old2NewVPValues[LI] = NewLI; + } + + Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount; + Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF; + if (BackedgeTakenCount) { + Old2NewVPValues[BackedgeTakenCount] = new VPValue(); + NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount]; + } + + auto NewPH = cast<VPBasicBlock>(Preheader->clone()); + remapVPValues(cast<VPBasicBlock>(Preheader), cast<VPBasicBlock>(NewPH), + Old2NewVPValues, /*Full*/ true); + VPValue *NewTC = Old2NewVPValues.lookup(TripCount); + if (!NewTC) + Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue()); + NewPlan->TripCount = Old2NewVPValues[TripCount]; + + auto *NewEntry = cast<VPBasicBlock>(VPBlockUtils::cloneCFG( + getEntry(), Old2New, Old2NewVPValues, /*FullRemapping*/ true)); + + NewPlan->Entry = NewEntry; + NewPlan->Preheader = NewPH; + NewEntry->setPlan(NewPlan); + NewPH->setPlan(NewPlan); + NewPlan->VFs = VFs; + NewPlan->UFs = UFs; + NewPlan->Name = Name; + + for (const auto &[_, LO] : LiveOuts) + NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]); ---------------- fhahn wrote:
Documented stages and moved, thanks! https://github.com/llvm/llvm-project/pull/73158 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits