Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[VPlan] Speed up VPSlotTracker by using ModuleSlotTracker #139881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions 36 llvm/lib/Transforms/Vectorize/VPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,13 +1495,7 @@ void VPSlotTracker::assignName(const VPValue *V) {

// Use the name of the underlying Value, wrapped in "ir<>", and versioned by
// appending ".Number" to the name if there are multiple uses.
std::string Name;
if (UV) {
raw_string_ostream S(Name);
UV->printAsOperand(S, false);
} else
Name = VPI->getName();

std::string Name = getName(V);
assert(!Name.empty() && "Name cannot be empty.");
StringRef Prefix = UV ? "ir<" : "vp<%";
std::string BaseName = (Twine(Prefix) + Name + Twine(">")).str();
Expand Down Expand Up @@ -1546,6 +1540,34 @@ void VPSlotTracker::assignNames(const VPBasicBlock *VPBB) {
assignName(Def);
}

std::string VPSlotTracker::getName(const VPValue *V) {
auto *UV = V->getUnderlyingValue();
auto *VPI = dyn_cast_or_null<VPInstruction>(V->getDefiningRecipe());
if (!UV)
return VPI->getName().str();

std::string Name;
raw_string_ostream S(Name);
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());
MST->incorporateFunction(*IUV->getFunction());
} else {
MST = std::make_unique<ModuleSlotTracker>(nullptr);
}
UV->printAsOperand(S, false, *MST);
} else {
UV->printAsOperand(S, false);
}
return Name;
}

std::string VPSlotTracker::getOrCreateName(const VPValue *V) const {
std::string Name = VPValue2Name.lookup(V);
if (!Name.empty())
Expand Down
6 changes: 6 additions & 0 deletions 6 llvm/lib/Transforms/Vectorize/VPlanHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/Support/InstructionCost.h"

namespace llvm {
Expand Down Expand Up @@ -387,9 +388,14 @@ class VPSlotTracker {
/// Number to assign to the next VPValue without underlying value.
unsigned NextSlot = 0;

/// Lazily created ModuleSlotTracker, used only when unnamed IR instructions
/// require slot tracking.
std::unique_ptr<ModuleSlotTracker> MST;

void assignName(const VPValue *V);
void assignNames(const VPlan &Plan);
void assignNames(const VPBasicBlock *VPBB);
std::string getName(const VPValue *V);

public:
VPSlotTracker(const VPlan *Plan = nullptr) {
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.