[llvm] [VPlan] Track VPValue names in VPlan. (PR #81411)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 11 00:26:46 PDT 2024


================
@@ -1373,32 +1362,73 @@ VPInterleavedAccessInfo::VPInterleavedAccessInfo(VPlan &Plan,
   visitRegion(Plan.getVectorLoopRegion(), Old2New, IAI);
 }
 
-void VPSlotTracker::assignSlot(const VPValue *V) {
-  if (V->getUnderlyingValue())
+void VPSlotTracker::assignSlotOrName(const VPValue *V) {
+  if (auto *UV = V->getUnderlyingValue()) {
+    std::string Name;
+    raw_string_ostream S(Name);
+    UV->printAsOperand(S, false);
+    deduplicateName(V, Name);
     return;
+  }
   assert(!Slots.contains(V) && "VPValue already has a slot!");
   Slots[V] = NextSlot++;
 }
 
-void VPSlotTracker::assignSlots(const VPlan &Plan) {
+void VPSlotTracker::assignSlotsOrNames(const VPlan &Plan) {
   if (Plan.VFxUF.getNumUsers() > 0)
-    assignSlot(&Plan.VFxUF);
-  assignSlot(&Plan.VectorTripCount);
+    assignSlotOrName(&Plan.VFxUF);
+  assignSlotOrName(&Plan.VectorTripCount);
   if (Plan.BackedgeTakenCount)
-    assignSlot(Plan.BackedgeTakenCount);
-  assignSlots(Plan.getPreheader());
+    assignSlotOrName(Plan.BackedgeTakenCount);
+  for (VPValue *LI : Plan.VPLiveInsToFree)
+    assignSlotOrName(LI);
+  assignSlotsOrNames(Plan.getPreheader());
 
   ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<const VPBlockBase *>>
       RPOT(VPBlockDeepTraversalWrapper<const VPBlockBase *>(Plan.getEntry()));
   for (const VPBasicBlock *VPBB :
        VPBlockUtils::blocksOnly<const VPBasicBlock>(RPOT))
-    assignSlots(VPBB);
+    assignSlotsOrNames(VPBB);
 }
 
-void VPSlotTracker::assignSlots(const VPBasicBlock *VPBB) {
+void VPSlotTracker::assignSlotsOrNames(const VPBasicBlock *VPBB) {
   for (const VPRecipeBase &Recipe : *VPBB)
     for (VPValue *Def : Recipe.definedValues())
-      assignSlot(Def);
+      assignSlotOrName(Def);
+}
+
+void VPSlotTracker::deduplicateName(const VPValue *V, StringRef Name) {
+  assert(!Name.empty() && "Name cannot be be empty.");
+  std::string NewName = Name.str();
+  const auto &[A, AssignedInserted] = AssignedNames.insert({V, NewName});
+  if (!AssignedInserted || V->isLiveIn())
----------------
ayalz wrote:

Would be good to explain the logic here: first assign to V the BaseName provided, then if this BaseName is already used by C>0 other V's, augment the name assigned to V by ".{C++ - 1}".

Can `V` already have a name assigned in AssignedNames when calling deduplicateName()? I.e., assert !AssignedNames.contains(V) rather than check if insert fails (it should not)? OTOH, if insert may fail, to support renaming, assert that NewName is the same as the old one, or replace the latter with the former? If V is live-in - w/ or w/o underlying? - it should not be versioned?

https://github.com/llvm/llvm-project/pull/81411


More information about the llvm-commits mailing list