[llvm] [VPlan] Speed up VPSlotTracker by using ModuleSlotTracker (PR #139881)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri May 16 08:10:25 PDT 2025


================
@@ -1441,7 +1441,23 @@ void VPSlotTracker::assignName(const VPValue *V) {
   std::string Name;
   if (UV) {
     raw_string_ostream S(Name);
-    UV->printAsOperand(S, false);
+    if (MST) {
+      UV->printAsOperand(S, false, *MST);
+    } else if (isa<Instruction>(UV) && !UV->hasName()) {
+      // Lazily create the ModuleSlotTracker when we first hit an unnamed
+      // instruction
+      auto *IUV = cast<Instruction>(UV);
+      // This check is required to support unit tests with incomplete IR.
+      if (IUV->getParent()) {
+        MST = std::make_unique<ModuleSlotTracker>(IUV->getModule());
----------------
david-arm wrote:

Sorry, I think I've misunderstood how the VPSlotTracker is most commonly used. I guess the performance we're most worried is on the path where we print the vplan, right?

```
LLVM_DUMP_METHOD
void VPlan::print(raw_ostream &O) const {
  VPSlotTracker SlotTracker(this);

  O << "VPlan '" << getName() << "' {";
```

in which case the slot tracker is only instantiated once and passed down the hierarchy. Please ignore my comment and sorry for the noise! I just happened to notice that some dump() function also create a slot tracker, but perhaps these are rarely called.

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


More information about the llvm-commits mailing list