Skip to content

Commit af6ebb7

Browse files
committed
[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.
1 parent 11df0ce commit af6ebb7

File tree

2 files changed

+83
-16
lines changed

2 files changed

+83
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,10 +911,6 @@ class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
911911
return cast<Instruction>(getUnderlyingValue());
912912
}
913913

914-
/// Return the cost of this VPSingleDefRecipe.
915-
InstructionCost computeCost(ElementCount VF,
916-
VPCostContext &Ctx) const override;
917-
918914
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
919915
/// Print this VPSingleDefRecipe to dbgs() (for debugging).
920916
LLVM_DUMP_METHOD void dump() const;
@@ -1323,6 +1319,13 @@ class VPInstruction : public VPRecipeWithIRFlags,
13231319
/// provided.
13241320
void execute(VPTransformState &State) override;
13251321

1322+
/// Return the cost of this VPInstruction.
1323+
InstructionCost computeCost(ElementCount VF,
1324+
VPCostContext &Ctx) const override {
1325+
// TODO: Compute accurate cost after retiring the legacy cost model.
1326+
return 0;
1327+
}
1328+
13261329
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
13271330
/// Print the VPInstruction to \p O.
13281331
void print(raw_ostream &O, const Twine &Indent,
@@ -1605,6 +1608,13 @@ class VPScalarCastRecipe : public VPSingleDefRecipe {
16051608

16061609
void execute(VPTransformState &State) override;
16071610

1611+
/// Return the cost of this VPScalarCastRecipe.
1612+
InstructionCost computeCost(ElementCount VF,
1613+
VPCostContext &Ctx) const override {
1614+
// TODO: Compute accurate cost after retiring the legacy cost model.
1615+
return 0;
1616+
}
1617+
16081618
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
16091619
void print(raw_ostream &O, const Twine &Indent,
16101620
VPSlotTracker &SlotTracker) const override;
@@ -1872,6 +1882,13 @@ class VPWidenGEPRecipe : public VPRecipeWithIRFlags {
18721882
/// Generate the gep nodes.
18731883
void execute(VPTransformState &State) override;
18741884

1885+
/// Return the cost of this VPWidenGEPRecipe.
1886+
InstructionCost computeCost(ElementCount VF,
1887+
VPCostContext &Ctx) const override {
1888+
// TODO: Compute accurate cost after retiring the legacy cost model.
1889+
return 0;
1890+
}
1891+
18751892
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
18761893
/// Print the recipe.
18771894
void print(raw_ostream &O, const Twine &Indent,
@@ -1906,6 +1923,13 @@ class VPReverseVectorPointerRecipe : public VPRecipeWithIRFlags,
19061923
return true;
19071924
}
19081925

1926+
/// Return the cost of this VPVectorPointerRecipe.
1927+
InstructionCost computeCost(ElementCount VF,
1928+
VPCostContext &Ctx) const override {
1929+
// TODO: Compute accurate cost after retiring the legacy cost model.
1930+
return 0;
1931+
}
1932+
19091933
/// Returns true if the recipe only uses the first part of operand \p Op.
19101934
bool onlyFirstPartUsed(const VPValue *Op) const override {
19111935
assert(is_contained(operands(), Op) &&
@@ -1961,6 +1985,13 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
19611985
getDebugLoc());
19621986
}
19631987

1988+
/// Return the cost of this VPHeaderPHIRecipe.
1989+
InstructionCost computeCost(ElementCount VF,
1990+
VPCostContext &Ctx) const override {
1991+
// TODO: Compute accurate cost after retiring the legacy cost model.
1992+
return 0;
1993+
}
1994+
19641995
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
19651996
/// Print the recipe.
19661997
void print(raw_ostream &O, const Twine &Indent,
@@ -2655,6 +2686,10 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags {
26552686
/// the \p State.
26562687
void execute(VPTransformState &State) override;
26572688

2689+
/// Return the cost of this VPReplicateRecipe.
2690+
InstructionCost computeCost(ElementCount VF,
2691+
VPCostContext &Ctx) const override;
2692+
26582693
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
26592694
/// Print the recipe.
26602695
void print(raw_ostream &O, const Twine &Indent,
@@ -2767,6 +2802,13 @@ class VPPredInstPHIRecipe : public VPSingleDefRecipe {
27672802
/// retain SSA form.
27682803
void execute(VPTransformState &State) override;
27692804

2805+
/// Return the cost of this VPPredInstPHIRecipe.
2806+
InstructionCost computeCost(ElementCount VF,
2807+
VPCostContext &Ctx) const override {
2808+
// TODO: Compute accurate cost after retiring the legacy cost model.
2809+
return 0;
2810+
}
2811+
27702812
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
27712813
/// Print the recipe.
27722814
void print(raw_ostream &O, const Twine &Indent,
@@ -3046,6 +3088,13 @@ class VPExpandSCEVRecipe : public VPSingleDefRecipe {
30463088
/// Generate a canonical vector induction variable of the vector loop, with
30473089
void execute(VPTransformState &State) override;
30483090

3091+
/// Return the cost of this VPExpandSCEVRecipe.
3092+
InstructionCost computeCost(ElementCount VF,
3093+
VPCostContext &Ctx) const override {
3094+
// TODO: Compute accurate cost after retiring the legacy cost model.
3095+
return 0;
3096+
}
3097+
30493098
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
30503099
/// Print the recipe.
30513100
void print(raw_ostream &O, const Twine &Indent,
@@ -3221,6 +3270,13 @@ class VPWidenCanonicalIVRecipe : public VPSingleDefRecipe,
32213270
/// step = <VF*UF, VF*UF, ..., VF*UF>.
32223271
void execute(VPTransformState &State) override;
32233272

3273+
/// Return the cost of this VPWidenCanonicalIVPHIRecipe.
3274+
InstructionCost computeCost(ElementCount VF,
3275+
VPCostContext &Ctx) const override {
3276+
// TODO: Compute accurate cost after retiring the legacy cost model.
3277+
return 0;
3278+
}
3279+
32243280
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
32253281
/// Print the recipe.
32263282
void print(raw_ostream &O, const Twine &Indent,
@@ -3265,6 +3321,13 @@ class VPDerivedIVRecipe : public VPSingleDefRecipe {
32653321
/// operand) + IV (2. operand) * StepValue (3, operand).
32663322
void execute(VPTransformState &State) override;
32673323

3324+
/// Return the cost of this VPDerivedIVRecipe.
3325+
InstructionCost computeCost(ElementCount VF,
3326+
VPCostContext &Ctx) const override {
3327+
// TODO: Compute accurate cost after retiring the legacy cost model.
3328+
return 0;
3329+
}
3330+
32683331
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
32693332
/// Print the recipe.
32703333
void print(raw_ostream &O, const Twine &Indent,
@@ -3320,6 +3383,13 @@ class VPScalarIVStepsRecipe : public VPRecipeWithIRFlags,
33203383
/// Generate the scalarized versions of the phi node as needed by their users.
33213384
void execute(VPTransformState &State) override;
33223385

3386+
/// Return the cost of this VPScalarIVStepsRecipe.
3387+
InstructionCost computeCost(ElementCount VF,
3388+
VPCostContext &Ctx) const override {
3389+
// TODO: Compute accurate cost after retiring the legacy cost model.
3390+
return 0;
3391+
}
3392+
33233393
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
33243394
/// Print the recipe.
33253395
void print(raw_ostream &O, const Twine &Indent,

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,6 @@ InstructionCost VPRecipeBase::computeCost(ElementCount VF,
292292
llvm_unreachable("subclasses should implement computeCost");
293293
}
294294

295-
InstructionCost VPSingleDefRecipe::computeCost(ElementCount VF,
296-
VPCostContext &Ctx) const {
297-
Instruction *UI = dyn_cast_or_null<Instruction>(getUnderlyingValue());
298-
if (isa<VPReplicateRecipe>(this)) {
299-
assert(UI && "VPReplicateRecipe must have an underlying instruction");
300-
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
301-
// transform, avoid computing their cost multiple times for now.
302-
Ctx.SkipCostComputation.insert(UI);
303-
}
304-
return UI ? Ctx.getLegacyCost(UI, VF) : 0;
305-
}
306-
307295
FastMathFlags VPRecipeWithIRFlags::getFastMathFlags() const {
308296
assert(OpType == OperationType::FPMathOp &&
309297
"recipe doesn't have fast math flags");
@@ -2283,6 +2271,15 @@ bool VPReplicateRecipe::shouldPack() const {
22832271
});
22842272
}
22852273

2274+
InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
2275+
VPCostContext &Ctx) const {
2276+
Instruction *UI = cast<Instruction>(getUnderlyingValue());
2277+
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
2278+
// transform, avoid computing their cost multiple times for now.
2279+
Ctx.SkipCostComputation.insert(UI);
2280+
return Ctx.getLegacyCost(UI, VF);
2281+
}
2282+
22862283
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
22872284
void VPReplicateRecipe::print(raw_ostream &O, const Twine &Indent,
22882285
VPSlotTracker &SlotTracker) const {

0 commit comments

Comments
 (0)