Skip to content

Commit d8fe7f8

Browse files
committed
Initialize MST lazily
1 parent e0825e4 commit d8fe7f8

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,10 +1441,23 @@ void VPSlotTracker::assignName(const VPValue *V) {
14411441
std::string Name;
14421442
if (UV) {
14431443
raw_string_ostream S(Name);
1444-
if (MST)
1444+
if (MST) {
14451445
UV->printAsOperand(S, false, *MST);
1446-
else
1446+
} else if (isa<Instruction>(UV) && !UV->hasName()) {
1447+
// Lazily create the ModuleSlotTracker when we first hit an unnamed
1448+
// instruction
1449+
auto *IUV = cast<Instruction>(UV);
1450+
// This check is required to support unit tests with incomplete IR.
1451+
if (IUV->getParent()) {
1452+
MST = std::make_unique<ModuleSlotTracker>(IUV->getModule());
1453+
MST->incorporateFunction(*IUV->getFunction());
1454+
} else {
1455+
MST = std::make_unique<ModuleSlotTracker>(nullptr);
1456+
}
1457+
UV->printAsOperand(S, false, *MST);
1458+
} else {
14471459
UV->printAsOperand(S, false);
1460+
}
14481461
} else
14491462
Name = VPI->getName();
14501463

llvm/lib/Transforms/Vectorize/VPlanHelpers.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ class VPSlotTracker {
383383
/// Number to assign to the next VPValue without underlying value.
384384
unsigned NextSlot = 0;
385385

386-
/// Cache slot indexes to avoid recomputing them on each printAsOperand call.
386+
/// Lazily created ModuleSlotTracker, used only when unnamed IR instructions
387+
/// require slot tracking.
387388
std::unique_ptr<ModuleSlotTracker> MST;
388389

389390
void assignName(const VPValue *V);
@@ -392,16 +393,8 @@ class VPSlotTracker {
392393

393394
public:
394395
VPSlotTracker(const VPlan *Plan = nullptr) {
395-
if (Plan) {
396-
// This check is required to support unit tests with incomplete IR.
397-
if (Function *F =
398-
Plan->getScalarHeader()->getIRBasicBlock()->getParent()) {
399-
Module *M = F->getParent();
400-
MST = std::make_unique<ModuleSlotTracker>(M);
401-
MST->incorporateFunction(*F);
402-
}
396+
if (Plan)
403397
assignNames(*Plan);
404-
}
405398
}
406399

407400
/// Returns the name assigned to \p V, if there is one, otherwise try to

0 commit comments

Comments
 (0)