[libcxx] [flang] [llvm] [libc] [lld] [clang-tools-extra] [compiler-rt] [lldb] [clang] [VPlan] Implement cloning of VPlans. (PR #73158)
Florian Hahn via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 21 04:44:47 PST 2024
================
@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const {
}
#endif
+VPBlockBase *VPBlockUtils::cloneCFG(
+ VPBlockBase *Entry, DenseMap<VPBlockBase *, VPBlockBase *> &Old2New,
+ DenseMap<VPValue *, VPValue *> &Old2NewVPValues, bool FullRemapping) {
+ ReversePostOrderTraversal<VPBlockShallowTraversalWrapper<VPBlockBase *>> RPOT(
+ Entry);
+ VPBlockBase *NewEntry = nullptr;
+ for (VPBlockBase *BB : RPOT) {
+ VPBlockBase *NewBB = BB->clone();
+ if (!NewEntry)
+ NewEntry = NewBB;
+
+ for (VPBlockBase *Pred : BB->getPredecessors())
+ connectBlocks(Old2New[Pred], NewBB);
+
+ Old2New[BB] = NewBB;
+
+ if (!isa<VPBasicBlock>(BB))
+ continue;
+ }
+
+ // Update the operands of all cloned recipes starting at NewEntry. This
+ // traverses all reachable blocks. This is done in two steps, to handle cycles
+ // in PHI recipes.
+ ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>>
+ OldDeepRPOT(Entry);
+ ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>>
+ NewDeepRPOT(NewEntry);
+ // First, collect all mappings from old to new VPValues defined by cloned
+ // recipes.
+ for (const auto &[OldBB, NewBB] :
+ zip(VPBlockUtils::blocksOnly<VPBasicBlock>(OldDeepRPOT),
+ VPBlockUtils::blocksOnly<VPBasicBlock>(NewDeepRPOT))) {
+ for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB))
+ for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+ Old2NewVPValues[OldV] = NewV;
+ }
+
+ // Update all operands to use cloned VPValues.
+ for (VPBasicBlock *NewBB :
+ VPBlockUtils::blocksOnly<VPBasicBlock>(NewDeepRPOT)) {
+ for (VPRecipeBase &NewR : *NewBB)
+ for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+ VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+ if (!FullRemapping)
----------------
fhahn wrote:
FullRemapping is gone
https://github.com/llvm/llvm-project/pull/73158
More information about the cfe-commits
mailing list