1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

[Analysis] Pass RecurrenceDescriptor as const reference. NFCI.

We were passing the RecurrenceDescriptor by value to most of the reduction analysis methods, despite it being rather bulky with TrackingVH members (that can be costly to copy). In all these cases we're only using the RecurrenceDescriptor for rather basic purposes (access to types/kinds etc.).

Differential Revision: https://reviews.llvm.org/D104029
This commit is contained in:
Simon Pilgrim 2021-06-11 10:19:37 +01:00
parent 2e422e4f72
commit cac15052d4
10 changed files with 25 additions and 23 deletions

View File

@ -1321,7 +1321,7 @@ public:
unsigned AddrSpace) const; unsigned AddrSpace) const;
/// \returns True if it is legal to vectorize the given reduction kind. /// \returns True if it is legal to vectorize the given reduction kind.
bool isLegalToVectorizeReduction(RecurrenceDescriptor RdxDesc, bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
ElementCount VF) const; ElementCount VF) const;
/// \returns The new vector factor value if the target doesn't support \p /// \returns The new vector factor value if the target doesn't support \p
@ -1705,7 +1705,7 @@ public:
virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes, virtual bool isLegalToVectorizeStoreChain(unsigned ChainSizeInBytes,
Align Alignment, Align Alignment,
unsigned AddrSpace) const = 0; unsigned AddrSpace) const = 0;
virtual bool isLegalToVectorizeReduction(RecurrenceDescriptor RdxDesc, virtual bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
ElementCount VF) const = 0; ElementCount VF) const = 0;
virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize, virtual unsigned getLoadVectorFactor(unsigned VF, unsigned LoadSize,
unsigned ChainSizeInBytes, unsigned ChainSizeInBytes,
@ -2254,7 +2254,7 @@ public:
return Impl.isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment, return Impl.isLegalToVectorizeStoreChain(ChainSizeInBytes, Alignment,
AddrSpace); AddrSpace);
} }
bool isLegalToVectorizeReduction(RecurrenceDescriptor RdxDesc, bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
ElementCount VF) const override { ElementCount VF) const override {
return Impl.isLegalToVectorizeReduction(RdxDesc, VF); return Impl.isLegalToVectorizeReduction(RdxDesc, VF);
} }

View File

@ -715,7 +715,7 @@ public:
return true; return true;
} }
bool isLegalToVectorizeReduction(RecurrenceDescriptor RdxDesc, bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
ElementCount VF) const { ElementCount VF) const {
return true; return true;
} }

View File

@ -370,12 +370,13 @@ Value *createSimpleTargetReduction(IRBuilderBase &B,
/// required to implement the reduction. /// required to implement the reduction.
/// Fast-math-flags are propagated using the RecurrenceDescriptor. /// Fast-math-flags are propagated using the RecurrenceDescriptor.
Value *createTargetReduction(IRBuilderBase &B, const TargetTransformInfo *TTI, Value *createTargetReduction(IRBuilderBase &B, const TargetTransformInfo *TTI,
RecurrenceDescriptor &Desc, Value *Src); const RecurrenceDescriptor &Desc, Value *Src);
/// Create an ordered reduction intrinsic using the given recurrence /// Create an ordered reduction intrinsic using the given recurrence
/// descriptor \p Desc. /// descriptor \p Desc.
Value *createOrderedReduction(IRBuilderBase &B, RecurrenceDescriptor &Desc, Value *createOrderedReduction(IRBuilderBase &B,
Value *Src, Value *Start); const RecurrenceDescriptor &Desc, Value *Src,
Value *Start);
/// Get the intersection (logical and) of all of the potential IR flags /// Get the intersection (logical and) of all of the potential IR flags
/// of each scalar operation (VL) that will be converted into a vector (I). /// of each scalar operation (VL) that will be converted into a vector (I).

View File

@ -999,7 +999,7 @@ bool TargetTransformInfo::isLegalToVectorizeStoreChain(
} }
bool TargetTransformInfo::isLegalToVectorizeReduction( bool TargetTransformInfo::isLegalToVectorizeReduction(
RecurrenceDescriptor RdxDesc, ElementCount VF) const { const RecurrenceDescriptor &RdxDesc, ElementCount VF) const {
return TTIImpl->isLegalToVectorizeReduction(RdxDesc, VF); return TTIImpl->isLegalToVectorizeReduction(RdxDesc, VF);
} }

View File

@ -1664,8 +1664,8 @@ bool AArch64TTIImpl::shouldConsiderAddressTypePromotion(
return Considerable; return Considerable;
} }
bool AArch64TTIImpl::isLegalToVectorizeReduction(RecurrenceDescriptor RdxDesc, bool AArch64TTIImpl::isLegalToVectorizeReduction(
ElementCount VF) const { const RecurrenceDescriptor &RdxDesc, ElementCount VF) const {
if (!VF.isScalable()) if (!VF.isScalable())
return true; return true;

View File

@ -292,7 +292,7 @@ public:
bool supportsScalableVectors() const { return ST->hasSVE(); } bool supportsScalableVectors() const { return ST->hasSVE(); }
bool isLegalToVectorizeReduction(RecurrenceDescriptor RdxDesc, bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
ElementCount VF) const; ElementCount VF) const;
InstructionCost getArithmeticReductionCost( InstructionCost getArithmeticReductionCost(

View File

@ -148,7 +148,7 @@ public:
return VPLegalization(VPLegalization::Legal, VPLegalization::Legal); return VPLegalization(VPLegalization::Legal, VPLegalization::Legal);
} }
bool isLegalToVectorizeReduction(RecurrenceDescriptor RdxDesc, bool isLegalToVectorizeReduction(const RecurrenceDescriptor &RdxDesc,
ElementCount VF) const { ElementCount VF) const {
if (!ST->hasStdExtV()) if (!ST->hasStdExtV())
return false; return false;

View File

@ -1000,7 +1000,8 @@ Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder,
Value *llvm::createTargetReduction(IRBuilderBase &B, Value *llvm::createTargetReduction(IRBuilderBase &B,
const TargetTransformInfo *TTI, const TargetTransformInfo *TTI,
RecurrenceDescriptor &Desc, Value *Src) { const RecurrenceDescriptor &Desc,
Value *Src) {
// TODO: Support in-order reductions based on the recurrence descriptor. // TODO: Support in-order reductions based on the recurrence descriptor.
// All ops in the reduction inherit fast-math-flags from the recurrence // All ops in the reduction inherit fast-math-flags from the recurrence
// descriptor. // descriptor.
@ -1010,8 +1011,8 @@ Value *llvm::createTargetReduction(IRBuilderBase &B,
} }
Value *llvm::createOrderedReduction(IRBuilderBase &B, Value *llvm::createOrderedReduction(IRBuilderBase &B,
RecurrenceDescriptor &Desc, Value *Src, const RecurrenceDescriptor &Desc,
Value *Start) { Value *Src, Value *Start) {
assert(Desc.getRecurrenceKind() == RecurKind::FAdd && assert(Desc.getRecurrenceKind() == RecurKind::FAdd &&
"Unexpected reduction kind"); "Unexpected reduction kind");
assert(Src->getType()->isVectorTy() && "Expected a vector type"); assert(Src->getType()->isVectorTy() && "Expected a vector type");

View File

@ -921,7 +921,7 @@ bool LoopVectorizationLegality::canVectorizeFPMath(
// have the isOrdered flag set, which indicates that we can move the // have the isOrdered flag set, which indicates that we can move the
// reduction operations in-loop. // reduction operations in-loop.
return (all_of(getReductionVars(), [&](auto &Reduction) -> bool { return (all_of(getReductionVars(), [&](auto &Reduction) -> bool {
RecurrenceDescriptor RdxDesc = Reduction.second; const RecurrenceDescriptor &RdxDesc = Reduction.second;
return !RdxDesc.hasExactFPMath() || RdxDesc.isOrdered(); return !RdxDesc.hasExactFPMath() || RdxDesc.isOrdered();
})); }));
} }

View File

@ -598,7 +598,7 @@ protected:
void fixReduction(VPWidenPHIRecipe *Phi, VPTransformState &State); void fixReduction(VPWidenPHIRecipe *Phi, VPTransformState &State);
/// Clear NSW/NUW flags from reduction instructions if necessary. /// Clear NSW/NUW flags from reduction instructions if necessary.
void clearReductionWrapFlags(RecurrenceDescriptor &RdxDesc, void clearReductionWrapFlags(const RecurrenceDescriptor &RdxDesc,
VPTransformState &State); VPTransformState &State);
/// Fixup the LCSSA phi nodes in the unique exit block. This simply /// Fixup the LCSSA phi nodes in the unique exit block. This simply
@ -1310,7 +1310,7 @@ public:
/// RdxDesc. This is true if the -enable-strict-reductions flag is passed, /// RdxDesc. This is true if the -enable-strict-reductions flag is passed,
/// the IsOrdered flag of RdxDesc is set and we do not allow reordering /// the IsOrdered flag of RdxDesc is set and we do not allow reordering
/// of FP operations. /// of FP operations.
bool useOrderedReductions(RecurrenceDescriptor &RdxDesc) { bool useOrderedReductions(const RecurrenceDescriptor &RdxDesc) {
return EnableStrictReductions && !Hints->allowReordering() && return EnableStrictReductions && !Hints->allowReordering() &&
RdxDesc.isOrdered(); RdxDesc.isOrdered();
} }
@ -1515,7 +1515,7 @@ public:
/// variables found for the given VF. /// variables found for the given VF.
bool canVectorizeReductions(ElementCount VF) { bool canVectorizeReductions(ElementCount VF) {
return (all_of(Legal->getReductionVars(), [&](auto &Reduction) -> bool { return (all_of(Legal->getReductionVars(), [&](auto &Reduction) -> bool {
RecurrenceDescriptor RdxDesc = Reduction.second; const RecurrenceDescriptor &RdxDesc = Reduction.second;
return TTI.isLegalToVectorizeReduction(RdxDesc, VF); return TTI.isLegalToVectorizeReduction(RdxDesc, VF);
})); }));
} }
@ -4331,7 +4331,7 @@ void InnerLoopVectorizer::fixReduction(VPWidenPHIRecipe *PhiR,
// Get it's reduction variable descriptor. // Get it's reduction variable descriptor.
assert(Legal->isReductionVariable(OrigPhi) && assert(Legal->isReductionVariable(OrigPhi) &&
"Unable to find the reduction variable"); "Unable to find the reduction variable");
RecurrenceDescriptor RdxDesc = *PhiR->getRecurrenceDescriptor(); const RecurrenceDescriptor &RdxDesc = *PhiR->getRecurrenceDescriptor();
RecurKind RK = RdxDesc.getRecurrenceKind(); RecurKind RK = RdxDesc.getRecurrenceKind();
TrackingVH<Value> ReductionStartValue = RdxDesc.getRecurrenceStartValue(); TrackingVH<Value> ReductionStartValue = RdxDesc.getRecurrenceStartValue();
@ -4512,7 +4512,7 @@ void InnerLoopVectorizer::fixReduction(VPWidenPHIRecipe *PhiR,
OrigPhi->setIncomingValue(IncomingEdgeBlockIdx, LoopExitInst); OrigPhi->setIncomingValue(IncomingEdgeBlockIdx, LoopExitInst);
} }
void InnerLoopVectorizer::clearReductionWrapFlags(RecurrenceDescriptor &RdxDesc, void InnerLoopVectorizer::clearReductionWrapFlags(const RecurrenceDescriptor &RdxDesc,
VPTransformState &State) { VPTransformState &State) {
RecurKind RK = RdxDesc.getRecurrenceKind(); RecurKind RK = RdxDesc.getRecurrenceKind();
if (RK != RecurKind::Add && RK != RecurKind::Mul) if (RK != RecurKind::Add && RK != RecurKind::Mul)
@ -6273,7 +6273,7 @@ LoopVectorizationCostModel::getSmallestAndWidestTypes() {
if (auto *PN = dyn_cast<PHINode>(&I)) { if (auto *PN = dyn_cast<PHINode>(&I)) {
if (!Legal->isReductionVariable(PN)) if (!Legal->isReductionVariable(PN))
continue; continue;
RecurrenceDescriptor RdxDesc = Legal->getReductionVars()[PN]; const RecurrenceDescriptor &RdxDesc = Legal->getReductionVars()[PN];
if (PreferInLoopReductions || useOrderedReductions(RdxDesc) || if (PreferInLoopReductions || useOrderedReductions(RdxDesc) ||
TTI.preferInLoopReduction(RdxDesc.getOpcode(), TTI.preferInLoopReduction(RdxDesc.getOpcode(),
RdxDesc.getRecurrenceType(), RdxDesc.getRecurrenceType(),
@ -7173,7 +7173,7 @@ InstructionCost LoopVectorizationCostModel::getReductionPatternCost(
while (!isa<PHINode>(ReductionPhi)) while (!isa<PHINode>(ReductionPhi))
ReductionPhi = InLoopReductionImmediateChains[ReductionPhi]; ReductionPhi = InLoopReductionImmediateChains[ReductionPhi];
RecurrenceDescriptor RdxDesc = const RecurrenceDescriptor &RdxDesc =
Legal->getReductionVars()[cast<PHINode>(ReductionPhi)]; Legal->getReductionVars()[cast<PHINode>(ReductionPhi)];
InstructionCost BaseCost = TTI.getArithmeticReductionCost( InstructionCost BaseCost = TTI.getArithmeticReductionCost(
RdxDesc.getOpcode(), VectorTy, false, CostKind); RdxDesc.getOpcode(), VectorTy, false, CostKind);