[llvm] 503e108 - [VPlan] Create VPSlotTracker's ModuleSlotTracker for the plan (NFC). (#223952)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 08:02:29 PDT 2026
Author: Florian Hahn
Date: 2026-09-16T16:02:22+01:00
New Revision: 503e108f373e1fbd64bbf025cd74d98426d4f566
URL: https://github.com/llvm/llvm-project/commit/503e108f373e1fbd64bbf025cd74d98426d4f566
DIFF: https://github.com/llvm/llvm-project/commit/503e108f373e1fbd64bbf025cd74d98426d4f566.diff
LOG: [VPlan] Create VPSlotTracker's ModuleSlotTracker for the plan (NFC). (#223952)
Move the lazy creation of VPSlotTracker's ModuleSlotTracker into a new
getOrCreateMST helper, so it can be shared with other users in the
future (https://github.com/llvm/llvm-project/pull/203982).
Also get the function and module directly from the plan Create it for
the cached module and get the function to incorporate from the plan,
instead of using the module and function of the first unnamed
instruction printed.
PR: https://github.com/llvm/llvm-project/pull/223952
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlanHelpers.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index f3bdf910a6e7b..05cb353616ee5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1588,27 +1588,28 @@ void VPSlotTracker::assignNames(const VPBasicBlock *VPBB) {
assignName(Def);
}
+ModuleSlotTracker &VPSlotTracker::getOrCreateMST() {
+ // F is null for unit tests with incomplete IR.
+ if (!MST) {
+ MST = std::make_unique<ModuleSlotTracker>(getModule());
+ if (F)
+ MST->incorporateFunction(*F);
+ }
+ return *MST;
+}
+
std::string VPSlotTracker::getName(const Value *V) {
std::string Name;
raw_string_ostream S(Name);
- if (V->hasName() || !isa<Instruction>(V)) {
+ // If V isn't an instruction in a basic block or named, it can be printed
+ // directly without ModuleSlotTracker.
+ auto *I = dyn_cast<Instruction>(V);
+ if (!I || I->hasName() || !I->getParent()) {
V->printAsOperand(S, false);
return Name;
}
- if (!MST) {
- // Lazily create the ModuleSlotTracker when we first hit an unnamed
- // instruction.
- auto *I = cast<Instruction>(V);
- // This check is required to support unit tests with incomplete IR.
- if (I->getParent()) {
- MST = std::make_unique<ModuleSlotTracker>(I->getModule());
- MST->incorporateFunction(*I->getFunction());
- } else {
- MST = std::make_unique<ModuleSlotTracker>(nullptr);
- }
- }
- V->printAsOperand(S, false, *MST);
+ V->printAsOperand(S, false, getOrCreateMST());
return Name;
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
index d31c5acdf69a9..4f4a435db00e0 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h
@@ -32,6 +32,7 @@ class AssumptionCache;
class BasicBlock;
class CallInst;
class DominatorTree;
+class Function;
class InnerLoopVectorizer;
class IRBuilderBase;
class LoopInfo;
@@ -432,20 +433,25 @@ class VPSlotTracker {
/// Cached metadata kind names from the Module's LLVMContext.
SmallVector<StringRef> MDNames;
- /// Cached Module pointer for printing metadata.
- const Module *M = nullptr;
+ /// Cached Function pointer for printing names and metadata.
+ const Function *F = nullptr;
void assignName(const VPValue *V);
LLVM_ABI_FOR_TEST void assignNames(const VPlan &Plan);
void assignNames(const VPBasicBlock *VPBB);
std::string getName(const Value *V);
+ /// Lazily create the ModuleSlotTracker.
+ ModuleSlotTracker &getOrCreateMST();
+
public:
VPSlotTracker(const VPlan *Plan = nullptr) {
if (Plan) {
+ if (auto *ScalarHeader = Plan->getScalarHeader()) {
+ const BasicBlock *ScalarHeaderIRBB = ScalarHeader->getIRBasicBlock();
+ F = ScalarHeaderIRBB->getParent();
+ }
assignNames(*Plan);
- if (auto *ScalarHeader = Plan->getScalarHeader())
- M = ScalarHeader->getIRBasicBlock()->getModule();
}
}
@@ -456,13 +462,14 @@ class VPSlotTracker {
/// Returns the cached metadata kind names.
ArrayRef<StringRef> getMDNames() {
+ const Module *M = getModule();
if (MDNames.empty() && M)
M->getContext().getMDKindNames(MDNames);
return MDNames;
}
- /// Returns the cached Module pointer.
- const Module *getModule() const { return M; }
+ /// Returns the module the plan operates on, if any.
+ const Module *getModule() const { return F ? F->getParent() : nullptr; }
};
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
More information about the llvm-commits
mailing list