Skip to content

Commit

Permalink
[VPlan] Update recipe ::clone definitions to use cloned tys (NFC).
Browse files Browse the repository at this point in the history
Update definitions on ::clone in recipe sub-types to use the sub-type as
return type. This avoids typecasts down to the cloned type in some
cases.
  • Loading branch information
fhahn committed Apr 11, 2024
1 parent 32b95a3 commit 478c420
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ class VPSingleDefRecipe : public VPRecipeBase, public VPValue {
return R && classof(R);
}

virtual VPSingleDefRecipe *clone() override = 0;

/// Returns the underlying instruction.
Instruction *getUnderlyingInstr() {
return cast<Instruction>(getUnderlyingValue());
Expand Down Expand Up @@ -1248,7 +1250,7 @@ class VPInstruction : public VPRecipeWithIRFlags {

VP_CLASSOF_IMPL(VPDef::VPInstructionSC)

VPRecipeBase *clone() override {
VPInstruction *clone() override {
SmallVector<VPValue *, 2> Operands(operands());
auto *New = new VPInstruction(Opcode, Operands, getDebugLoc(), Name);
New->transferFlags(*this);
Expand Down Expand Up @@ -1335,7 +1337,7 @@ class VPWidenRecipe : public VPRecipeWithIRFlags {

~VPWidenRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenRecipe *clone() override {
auto *R = new VPWidenRecipe(*getUnderlyingInstr(), operands());
R->transferFlags(*this);
return R;
Expand Down Expand Up @@ -1380,7 +1382,7 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {

~VPWidenCastRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenCastRecipe *clone() override {
if (auto *UV = getUnderlyingValue())
return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
*cast<CastInst>(UV));
Expand Down Expand Up @@ -1420,7 +1422,7 @@ class VPScalarCastRecipe : public VPSingleDefRecipe {

~VPScalarCastRecipe() override = default;

VPRecipeBase *clone() override {
VPScalarCastRecipe *clone() override {
return new VPScalarCastRecipe(Opcode, getOperand(0), ResultTy);
}

Expand Down Expand Up @@ -1465,7 +1467,7 @@ class VPWidenCallRecipe : public VPSingleDefRecipe {

~VPWidenCallRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenCallRecipe *clone() override {
return new VPWidenCallRecipe(*cast<CallInst>(getUnderlyingInstr()),
operands(), VectorIntrinsicID, getDebugLoc(),
Variant);
Expand All @@ -1492,7 +1494,7 @@ struct VPWidenSelectRecipe : public VPSingleDefRecipe {

~VPWidenSelectRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenSelectRecipe *clone() override {
return new VPWidenSelectRecipe(*cast<SelectInst>(getUnderlyingInstr()),
operands());
}
Expand Down Expand Up @@ -1540,7 +1542,7 @@ class VPWidenGEPRecipe : public VPRecipeWithIRFlags {

~VPWidenGEPRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenGEPRecipe *clone() override {
return new VPWidenGEPRecipe(cast<GetElementPtrInst>(getUnderlyingInstr()),
operands());
}
Expand Down Expand Up @@ -1581,7 +1583,7 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags {
return true;
}

VPRecipeBase *clone() override {
VPVectorPointerRecipe *clone() override {
return new VPVectorPointerRecipe(getOperand(0), IndexedTy, IsReverse,
isInBounds(), getDebugLoc());
}
Expand Down Expand Up @@ -1696,7 +1698,7 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {

~VPWidenIntOrFpInductionRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenIntOrFpInductionRecipe *clone() override {
return new VPWidenIntOrFpInductionRecipe(IV, getStartValue(),
getStepValue(), IndDesc, Trunc);
}
Expand Down Expand Up @@ -1771,7 +1773,7 @@ class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe {

~VPWidenPointerInductionRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenPointerInductionRecipe *clone() override {
return new VPWidenPointerInductionRecipe(
cast<PHINode>(getUnderlyingInstr()), getOperand(0), getOperand(1),
IndDesc, IsScalarAfterVectorization);
Expand Down Expand Up @@ -1810,7 +1812,7 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
addOperand(Start);
}

VPRecipeBase *clone() override {
VPWidenPHIRecipe *clone() override {
llvm_unreachable("cloning not implemented yet");
}

Expand Down Expand Up @@ -1853,7 +1855,7 @@ struct VPFirstOrderRecurrencePHIRecipe : public VPHeaderPHIRecipe {
return R->getVPDefID() == VPDef::VPFirstOrderRecurrencePHISC;
}

VPRecipeBase *clone() override {
VPFirstOrderRecurrencePHIRecipe *clone() override {
return new VPFirstOrderRecurrencePHIRecipe(
cast<PHINode>(getUnderlyingInstr()), *getOperand(0));
}
Expand Down Expand Up @@ -1893,7 +1895,7 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe {

~VPReductionPHIRecipe() override = default;

VPRecipeBase *clone() override {
VPReductionPHIRecipe *clone() override {
auto *R =
new VPReductionPHIRecipe(cast<PHINode>(getUnderlyingInstr()), RdxDesc,
*getOperand(0), IsInLoop, IsOrdered);
Expand Down Expand Up @@ -1940,7 +1942,7 @@ class VPBlendRecipe : public VPSingleDefRecipe {
"Expected an odd number of operands");
}

VPRecipeBase *clone() override {
VPBlendRecipe *clone() override {
SmallVector<VPValue *> Ops(operands());
return new VPBlendRecipe(cast<PHINode>(getUnderlyingValue()), Ops);
}
Expand Down Expand Up @@ -2019,7 +2021,7 @@ class VPInterleaveRecipe : public VPRecipeBase {
}
~VPInterleaveRecipe() override = default;

VPRecipeBase *clone() override {
VPInterleaveRecipe *clone() override {
return new VPInterleaveRecipe(IG, getAddr(), getStoredValues(), getMask(),
NeedsMaskForGaps);
}
Expand Down Expand Up @@ -2093,7 +2095,7 @@ class VPReductionRecipe : public VPSingleDefRecipe {

~VPReductionRecipe() override = default;

VPRecipeBase *clone() override {
VPReductionRecipe *clone() override {
return new VPReductionRecipe(RdxDesc, getUnderlyingInstr(), getChainOp(),
getVecOp(), getCondOp(), IsOrdered);
}
Expand Down Expand Up @@ -2142,7 +2144,7 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags {

~VPReplicateRecipe() override = default;

VPRecipeBase *clone() override {
VPReplicateRecipe *clone() override {
auto *Copy =
new VPReplicateRecipe(getUnderlyingInstr(), operands(), IsUniform,
isPredicated() ? getMask() : nullptr);
Expand Down Expand Up @@ -2204,7 +2206,7 @@ class VPBranchOnMaskRecipe : public VPRecipeBase {
addOperand(BlockInMask);
}

VPRecipeBase *clone() override {
VPBranchOnMaskRecipe *clone() override {
return new VPBranchOnMaskRecipe(getOperand(0));
}

Expand Down Expand Up @@ -2255,7 +2257,7 @@ class VPPredInstPHIRecipe : public VPSingleDefRecipe {
: VPSingleDefRecipe(VPDef::VPPredInstPHISC, PredV) {}
~VPPredInstPHIRecipe() override = default;

VPRecipeBase *clone() override {
VPPredInstPHIRecipe *clone() override {
return new VPPredInstPHIRecipe(getOperand(0));
}

Expand Down Expand Up @@ -2323,7 +2325,7 @@ class VPWidenMemoryInstructionRecipe : public VPRecipeBase {
setMask(Mask);
}

VPRecipeBase *clone() override {
VPWidenMemoryInstructionRecipe *clone() override {
if (isStore())
return new VPWidenMemoryInstructionRecipe(
cast<StoreInst>(Ingredient), getAddr(), getStoredValue(), getMask(),
Expand Down Expand Up @@ -2399,7 +2401,9 @@ class VPExpandSCEVRecipe : public VPSingleDefRecipe {

~VPExpandSCEVRecipe() override = default;

VPRecipeBase *clone() override { return new VPExpandSCEVRecipe(Expr, SE); }
VPExpandSCEVRecipe *clone() override {
return new VPExpandSCEVRecipe(Expr, SE);
}

VP_CLASSOF_IMPL(VPDef::VPExpandSCEVSC)

Expand All @@ -2426,7 +2430,7 @@ class VPCanonicalIVPHIRecipe : public VPHeaderPHIRecipe {

~VPCanonicalIVPHIRecipe() override = default;

VPRecipeBase *clone() override {
VPCanonicalIVPHIRecipe *clone() override {
auto *R = new VPCanonicalIVPHIRecipe(getOperand(0), getDebugLoc());
R->addOperand(getBackedgeValue());
return R;
Expand Down Expand Up @@ -2484,7 +2488,7 @@ class VPActiveLaneMaskPHIRecipe : public VPHeaderPHIRecipe {

~VPActiveLaneMaskPHIRecipe() override = default;

VPRecipeBase *clone() override {
VPActiveLaneMaskPHIRecipe *clone() override {
return new VPActiveLaneMaskPHIRecipe(getOperand(0), getDebugLoc());
}

Expand Down Expand Up @@ -2551,7 +2555,7 @@ class VPWidenCanonicalIVRecipe : public VPSingleDefRecipe {

~VPWidenCanonicalIVRecipe() override = default;

VPRecipeBase *clone() override {
VPWidenCanonicalIVRecipe *clone() override {
return new VPWidenCanonicalIVRecipe(
cast<VPCanonicalIVPHIRecipe>(getOperand(0)));
}
Expand Down Expand Up @@ -2602,7 +2606,7 @@ class VPDerivedIVRecipe : public VPSingleDefRecipe {

~VPDerivedIVRecipe() override = default;

VPRecipeBase *clone() override {
VPDerivedIVRecipe *clone() override {
return new VPDerivedIVRecipe(Kind, FPBinOp, getStartValue(), getOperand(1),
getStepValue());
}
Expand Down Expand Up @@ -2656,7 +2660,7 @@ class VPScalarIVStepsRecipe : public VPRecipeWithIRFlags {

~VPScalarIVStepsRecipe() override = default;

VPRecipeBase *clone() override {
VPScalarIVStepsRecipe *clone() override {
return new VPScalarIVStepsRecipe(
getOperand(0), getOperand(1), InductionOpcode,
hasFastMathFlags() ? getFastMathFlags() : FastMathFlags());
Expand Down

0 comments on commit 478c420

Please sign in to comment.