[llvm] [VPlan] Speed up VPSlotTracker by using ModuleSlotTracker (PR #139881)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 08:37:39 PDT 2025
================
@@ -382,14 +383,25 @@ class VPSlotTracker {
/// Number to assign to the next VPValue without underlying value.
unsigned NextSlot = 0;
+ /// Cache slot indexes to avoid recomputing them on each printAsOperand call.
+ std::unique_ptr<ModuleSlotTracker> MST;
+
void assignName(const VPValue *V);
void assignNames(const VPlan &Plan);
void assignNames(const VPBasicBlock *VPBB);
public:
VPSlotTracker(const VPlan *Plan = nullptr) {
- if (Plan)
+ if (Plan) {
+ // This check is required to support unit tests with incomplete IR.
+ if (Function *F =
+ Plan->getScalarHeader()->getIRBasicBlock()->getParent()) {
+ Module *M = F->getParent();
+ MST = std::make_unique<ModuleSlotTracker>(M);
----------------
fhahn wrote:
IIUC this may slow down the case where numbering the function isn't neccessary, e.g. because all values are named or we only have VPValues w/o underlying IR. Could we delay `incorporateFunction` until it is definitely needed, i.e. printing an unnamed IR value?
Then we should get the best of both worlds, because otherwise printAsOperand would call `incorporateFunction` each time.
https://github.com/llvm/llvm-project/pull/139881
More information about the llvm-commits
mailing list