Skip to content

Commit

Permalink
[VPlan] Move VF and UF string generation to getName() (NFC).
Browse files Browse the repository at this point in the history
The VFs and UFs may be more constrained as the plans are transformed
(e.g. see D135017 for an example).

To make sure the VFs/UFs included in the VPlan dump are accurate,
generate them when accessing a plan's name, rather than include them in
the name string set after initial construction.
  • Loading branch information
fhahn committed Dec 22, 2022
1 parent 6157a06 commit 9629692
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
14 changes: 3 additions & 11 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Expand Up @@ -9130,18 +9130,10 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
}
}

std::string PlanName;
raw_string_ostream RSO(PlanName);
ElementCount VF = Range.Start;
Plan->addVF(VF);
RSO << "Initial VPlan for VF={" << VF;
for (VF *= 2; ElementCount::isKnownLT(VF, Range.End); VF *= 2) {
for (ElementCount VF = Range.Start; ElementCount::isKnownLT(VF, Range.End);
VF *= 2)
Plan->addVF(VF);
RSO << "," << VF;
}
RSO << "},UF>=1";
RSO.flush();
Plan->setName(PlanName);
Plan->setName("Initial VPlan");

// From this point onwards, VPlan-to-VPlan transformations may change the plan
// in ways that accessing values using original IR values is incorrect.
Expand Down
16 changes: 15 additions & 1 deletion llvm/lib/Transforms/Vectorize/VPlan.cpp
Expand Up @@ -757,7 +757,7 @@ LLVM_DUMP_METHOD
void VPlan::print(raw_ostream &O) const {
VPSlotTracker SlotTracker(this);

O << "VPlan '" << Name << "' {";
O << "VPlan '" << getName() << "' {";

if (VectorTripCount.getNumUsers() > 0) {
O << "\nLive-in ";
Expand Down Expand Up @@ -789,6 +789,20 @@ void VPlan::print(raw_ostream &O) const {
O << "}\n";
}

std::string VPlan::getName() const {
std::string Out;
raw_string_ostream RSO(Out);
RSO << Name;
if (!VFs.empty()) {
RSO << " for VF={" << VFs[0];
for (ElementCount VF : drop_begin(VFs))
RSO << "," << VF;
RSO << "},UF>=1";
}

return Out;
}

LLVM_DUMP_METHOD
void VPlan::printDOT(raw_ostream &O) const {
VPlanPrinter Printer(O, *this);
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Transforms/Vectorize/VPlan.h
Expand Up @@ -2601,7 +2601,8 @@ class VPlan {

bool hasScalarVFOnly() const { return VFs.size() == 1 && VFs[0].isScalar(); }

const std::string &getName() const { return Name; }
/// Return a string with the name of the plan and the applicable VFs and UFs.
std::string getName() const;

void setName(const Twine &newName) { Name = newName.str(); }

Expand Down

0 comments on commit 9629692

Please sign in to comment.