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

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri May 16 07:15:27 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:

I'm not sure how useful this level of caching really is, because we're still throwing away the cached object for every dump of VPValue. Although in fairness I think that also seems to be true for `VPValue2Name`, since that member variable is not static.

Can you not just make `MST` a static member that's initialised to nullptr and lazily updated to `std::make_unique<ModuleSlotTracker>(nullptr)`?

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


More information about the llvm-commits mailing list