[llvm] af6ebb7 - [VPlan] Implement computeCost for remaining VPSingleDefRecipes.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 2 12:39:06 PDT 2024
Author: Florian Hahn
Date: 2024-11-02T19:38:31Z
New Revision: af6ebb70d22ed75d4472a6069ba3a0890e0d3a00
URL: https://github.com/llvm/llvm-project/commit/af6ebb70d22ed75d4472a6069ba3a0890e0d3a00
DIFF: https://github.com/llvm/llvm-project/commit/af6ebb70d22ed75d4472a6069ba3a0890e0d3a00.diff
LOG: [VPlan] Implement computeCost for remaining VPSingleDefRecipes.
Provide computeCost implementations for all remaining sub-classes of
VPSingleDefRecipe. This pushes one of the last uses of getLegacyCost
directly to its user: VPReplicateRecipe.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index cf4b38b340dc12..ddf1fac1c54549 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -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;
@@ -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,
@@ -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;
@@ -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,
@@ -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) &&
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
@@ -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,
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 2ecd546633825e..e63930551b222a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -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");
@@ -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 {
More information about the llvm-commits
mailing list