Skip to content

Commit

Permalink
[VPlan] Implement computeCost for remaining VPSingleDefRecipes.
Browse files Browse the repository at this point in the history
Provide computeCost implementations for all remaining sub-classes of
VPSingleDefRecipe. This pushes one of the last uses of getLegacyCost
directly to its user: VPReplicateRecipe.
  • Loading branch information
fhahn committed Nov 2, 2024
1 parent 11df0ce commit af6ebb7
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 16 deletions.
78 changes: 74 additions & 4 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,10 +911,6 @@ class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
return cast<Instruction>(getUnderlyingValue());
}

/// Return the cost of this VPSingleDefRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print this VPSingleDefRecipe to dbgs() (for debugging).
LLVM_DUMP_METHOD void dump() const;
Expand Down Expand Up @@ -1323,6 +1319,13 @@ class VPInstruction : public VPRecipeWithIRFlags,
/// provided.
void execute(VPTransformState &State) override;

/// Return the cost of this VPInstruction.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the VPInstruction to \p O.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -1605,6 +1608,13 @@ class VPScalarCastRecipe : public VPSingleDefRecipe {

void execute(VPTransformState &State) override;

/// Return the cost of this VPScalarCastRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const override;
Expand Down Expand Up @@ -1872,6 +1882,13 @@ class VPWidenGEPRecipe : public VPRecipeWithIRFlags {
/// Generate the gep nodes.
void execute(VPTransformState &State) override;

/// Return the cost of this VPWidenGEPRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -1906,6 +1923,13 @@ class VPReverseVectorPointerRecipe : public VPRecipeWithIRFlags,
return true;
}

/// Return the cost of this VPVectorPointerRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

/// Returns true if the recipe only uses the first part of operand \p Op.
bool onlyFirstPartUsed(const VPValue *Op) const override {
assert(is_contained(operands(), Op) &&
Expand Down Expand Up @@ -1961,6 +1985,13 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
getDebugLoc());
}

/// Return the cost of this VPHeaderPHIRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -2655,6 +2686,10 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags {
/// the \p State.
void execute(VPTransformState &State) override;

/// Return the cost of this VPReplicateRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -2767,6 +2802,13 @@ class VPPredInstPHIRecipe : public VPSingleDefRecipe {
/// retain SSA form.
void execute(VPTransformState &State) override;

/// Return the cost of this VPPredInstPHIRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -3046,6 +3088,13 @@ class VPExpandSCEVRecipe : public VPSingleDefRecipe {
/// Generate a canonical vector induction variable of the vector loop, with
void execute(VPTransformState &State) override;

/// Return the cost of this VPExpandSCEVRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -3221,6 +3270,13 @@ class VPWidenCanonicalIVRecipe : public VPSingleDefRecipe,
/// step = <VF*UF, VF*UF, ..., VF*UF>.
void execute(VPTransformState &State) override;

/// Return the cost of this VPWidenCanonicalIVPHIRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -3265,6 +3321,13 @@ class VPDerivedIVRecipe : public VPSingleDefRecipe {
/// operand) + IV (2. operand) * StepValue (3, operand).
void execute(VPTransformState &State) override;

/// Return the cost of this VPDerivedIVRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down Expand Up @@ -3320,6 +3383,13 @@ class VPScalarIVStepsRecipe : public VPRecipeWithIRFlags,
/// Generate the scalarized versions of the phi node as needed by their users.
void execute(VPTransformState &State) override;

/// Return the cost of this VPScalarIVStepsRecipe.
InstructionCost computeCost(ElementCount VF,
VPCostContext &Ctx) const override {
// TODO: Compute accurate cost after retiring the legacy cost model.
return 0;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// Print the recipe.
void print(raw_ostream &O, const Twine &Indent,
Expand Down
21 changes: 9 additions & 12 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,6 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
llvm_unreachable("subclasses should implement computeCost");
}

InstructionCost VPSingleDefRecipe::computeCost(ElementCount VF,
VPCostContext &Ctx) const {
Instruction *UI = dyn_cast_or_null<Instruction>(getUnderlyingValue());
if (isa<VPReplicateRecipe>(this)) {
assert(UI && "VPReplicateRecipe must have an underlying instruction");
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
// transform, avoid computing their cost multiple times for now.
Ctx.SkipCostComputation.insert(UI);
}
return UI ? Ctx.getLegacyCost(UI, VF) : 0;
}

FastMathFlags VPRecipeWithIRFlags::getFastMathFlags() const {
assert(OpType == OperationType::FPMathOp &&
"recipe doesn't have fast math flags");
Expand Down Expand Up @@ -2283,6 +2271,15 @@ bool VPReplicateRecipe::shouldPack() const {
});
}

InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
VPCostContext &Ctx) const {
Instruction *UI = cast<Instruction>(getUnderlyingValue());
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
// transform, avoid computing their cost multiple times for now.
Ctx.SkipCostComputation.insert(UI);
return Ctx.getLegacyCost(UI, VF);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void VPReplicateRecipe::print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const {
Expand Down

0 comments on commit af6ebb7

Please sign in to comment.