forked from OSchip/llvm-project
[VPlan] Add recipe to handle SCEV expansion (NFC).
This can be used to explicitly model VPValues that depend on SCEV expansion, like the step for inductions. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D116288
This commit is contained in:
parent
850bc76a35
commit
9bc866cc6f
|
@ -41,6 +41,7 @@
|
|||
#include "llvm/Support/GraphWriter.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
@ -1399,6 +1400,27 @@ void VPCanonicalIVPHIRecipe::print(raw_ostream &O, const Twine &Indent,
|
|||
}
|
||||
#endif
|
||||
|
||||
void VPExpandSCEVRecipe::execute(VPTransformState &State) {
|
||||
assert(!State.Instance && "cannot be used in per-lane");
|
||||
const DataLayout &DL =
|
||||
State.CFG.VectorPreHeader->getModule()->getDataLayout();
|
||||
SCEVExpander Exp(SE, DL, "induction");
|
||||
Value *Res = Exp.expandCodeFor(Expr, Expr->getType(),
|
||||
State.CFG.VectorPreHeader->getTerminator());
|
||||
|
||||
for (unsigned Part = 0, UF = State.UF; Part < UF; ++Part)
|
||||
State.set(this, Res, Part);
|
||||
}
|
||||
|
||||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
||||
void VPExpandSCEVRecipe::print(raw_ostream &O, const Twine &Indent,
|
||||
VPSlotTracker &SlotTracker) const {
|
||||
O << Indent << "EMIT ";
|
||||
getVPSingleValue()->printAsOperand(O, SlotTracker);
|
||||
O << " = EXPAND SCEV " << *Expr;
|
||||
}
|
||||
#endif
|
||||
|
||||
void VPWidenCanonicalIVRecipe::execute(VPTransformState &State) {
|
||||
Value *CanonicalIV = State.get(getOperand(0), 0);
|
||||
Type *STy = CanonicalIV->getType();
|
||||
|
|
|
@ -1720,6 +1720,36 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/// Recipe to expand a SCEV expression.
|
||||
/// TODO: Currently the recipe always expands the expression in the loop
|
||||
/// pre-header, but the recipe is currently placed in the header; place it in
|
||||
/// the pre-header once the latter is modeled in VPlan as a VPBasicBlock.
|
||||
class VPExpandSCEVRecipe : public VPRecipeBase, public VPValue {
|
||||
const SCEV *Expr;
|
||||
ScalarEvolution &SE;
|
||||
|
||||
public:
|
||||
VPExpandSCEVRecipe(const SCEV *Expr, ScalarEvolution &SE)
|
||||
: VPRecipeBase(VPExpandSCEVSC, {}), VPValue(nullptr, this), Expr(Expr),
|
||||
SE(SE) {}
|
||||
|
||||
~VPExpandSCEVRecipe() override = default;
|
||||
|
||||
/// Method to support type inquiry through isa, cast, and dyn_cast.
|
||||
static inline bool classof(const VPDef *D) {
|
||||
return D->getVPDefID() == VPExpandSCEVSC;
|
||||
}
|
||||
|
||||
/// Generate a canonical vector induction variable of the vector loop, with
|
||||
void execute(VPTransformState &State) override;
|
||||
|
||||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
||||
/// Print the recipe.
|
||||
void print(raw_ostream &O, const Twine &Indent,
|
||||
VPSlotTracker &SlotTracker) const override;
|
||||
#endif
|
||||
};
|
||||
|
||||
/// Canonical scalar induction phi of the vector loop. Starting at the specified
|
||||
/// start value (either 0 or the resume value when vectorizing the epilogue
|
||||
/// loop). VPWidenCanonicalIVRecipe represents the vector version of the
|
||||
|
|
|
@ -327,6 +327,7 @@ public:
|
|||
/// type identification.
|
||||
using VPRecipeTy = enum {
|
||||
VPBranchOnMaskSC,
|
||||
VPExpandSCEVSC,
|
||||
VPInstructionSC,
|
||||
VPInterleaveSC,
|
||||
VPReductionSC,
|
||||
|
|
Loading…
Reference in New Issue