diff options
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h')
| -rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h index 13357cb06c55..577ce8000de2 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h @@ -31,6 +31,7 @@ namespace llvm { class LoopInfo; +class DominatorTree; class LoopVectorizationLegality; class LoopVectorizationCostModel; class PredicatedScalarEvolution; @@ -45,13 +46,17 @@ class VPBuilder { VPBasicBlock *BB = nullptr; VPBasicBlock::iterator InsertPt = VPBasicBlock::iterator(); + /// Insert \p VPI in BB at InsertPt if BB is set. + VPInstruction *tryInsertInstruction(VPInstruction *VPI) { + if (BB) + BB->insert(VPI, InsertPt); + return VPI; + } + VPInstruction *createInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands, DebugLoc DL, const Twine &Name = "") { - VPInstruction *Instr = new VPInstruction(Opcode, Operands, DL, Name); - if (BB) - BB->insert(Instr, InsertPt); - return Instr; + return tryInsertInstruction(new VPInstruction(Opcode, Operands, DL, Name)); } VPInstruction *createInstruction(unsigned Opcode, @@ -62,6 +67,7 @@ class VPBuilder { public: VPBuilder() = default; + VPBuilder(VPBasicBlock *InsertBB) { setInsertPoint(InsertBB); } /// Clear the insertion point: created instructions will not be inserted into /// a block. @@ -116,10 +122,11 @@ public: InsertPt = IP; } - /// Insert and return the specified instruction. - VPInstruction *insert(VPInstruction *I) const { - BB->insert(I, InsertPt); - return I; + /// This specifies that created instructions should be inserted at the + /// specified point. + void setInsertPoint(VPRecipeBase *IP) { + BB = IP->getParent(); + InsertPt = IP->getIterator(); } /// Create an N-ary operation with \p Opcode, \p Operands and set \p Inst as @@ -138,6 +145,13 @@ public: return createInstruction(Opcode, Operands, DL, Name); } + VPInstruction *createOverflowingOp(unsigned Opcode, + std::initializer_list<VPValue *> Operands, + VPRecipeWithIRFlags::WrapFlagsTy WrapFlags, + DebugLoc DL, const Twine &Name = "") { + return tryInsertInstruction( + new VPInstruction(Opcode, Operands, WrapFlags, DL, Name)); + } VPValue *createNot(VPValue *Operand, DebugLoc DL, const Twine &Name = "") { return createInstruction(VPInstruction::Not, {Operand}, DL, Name); } @@ -158,6 +172,12 @@ public: Name); } + /// Create a new ICmp VPInstruction with predicate \p Pred and operands \p A + /// and \p B. + /// TODO: add createFCmp when needed. + VPValue *createICmp(CmpInst::Predicate Pred, VPValue *A, VPValue *B, + DebugLoc DL = {}, const Twine &Name = ""); + //===--------------------------------------------------------------------===// // RAII helpers. //===--------------------------------------------------------------------===// @@ -268,6 +288,9 @@ class LoopVectorizationPlanner { /// Loop Info analysis. LoopInfo *LI; + /// The dominator tree. + DominatorTree *DT; + /// Target Library Info. const TargetLibraryInfo *TLI; @@ -298,16 +321,14 @@ class LoopVectorizationPlanner { VPBuilder Builder; public: - LoopVectorizationPlanner(Loop *L, LoopInfo *LI, const TargetLibraryInfo *TLI, - const TargetTransformInfo &TTI, - LoopVectorizationLegality *Legal, - LoopVectorizationCostModel &CM, - InterleavedAccessInfo &IAI, - PredicatedScalarEvolution &PSE, - const LoopVectorizeHints &Hints, - OptimizationRemarkEmitter *ORE) - : OrigLoop(L), LI(LI), TLI(TLI), TTI(TTI), Legal(Legal), CM(CM), IAI(IAI), - PSE(PSE), Hints(Hints), ORE(ORE) {} + LoopVectorizationPlanner( + Loop *L, LoopInfo *LI, DominatorTree *DT, const TargetLibraryInfo *TLI, + const TargetTransformInfo &TTI, LoopVectorizationLegality *Legal, + LoopVectorizationCostModel &CM, InterleavedAccessInfo &IAI, + PredicatedScalarEvolution &PSE, const LoopVectorizeHints &Hints, + OptimizationRemarkEmitter *ORE) + : OrigLoop(L), LI(LI), DT(DT), TLI(TLI), TTI(TTI), Legal(Legal), CM(CM), + IAI(IAI), PSE(PSE), Hints(Hints), ORE(ORE) {} /// Plan how to best vectorize, return the best VF and its cost, or /// std::nullopt if vectorization and interleaving should be avoided up front. @@ -333,7 +354,7 @@ public: executePlan(ElementCount VF, unsigned UF, VPlan &BestPlan, InnerLoopVectorizer &LB, DominatorTree *DT, bool IsEpilogueVectorization, - DenseMap<const SCEV *, Value *> *ExpandedSCEVs = nullptr); + const DenseMap<const SCEV *, Value *> *ExpandedSCEVs = nullptr); #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void printPlans(raw_ostream &O); @@ -377,8 +398,7 @@ private: /// returned VPlan is valid for. If no VPlan can be built for the input range, /// set the largest included VF to the maximum VF for which no plan could be /// built. - std::optional<VPlanPtr> tryToBuildVPlanWithVPRecipes( - VFRange &Range, SmallPtrSetImpl<Instruction *> &DeadInstructions); + VPlanPtr tryToBuildVPlanWithVPRecipes(VFRange &Range); /// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive, /// according to the information gathered by Legal when it checked if it is |
