diff options
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h')
-rw-r--r-- | llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h | 95 |
1 files changed, 52 insertions, 43 deletions
diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h index 598fb00e956e..6f055ca80ff2 100644 --- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h +++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h @@ -18,7 +18,6 @@ namespace llvm { class LoopVectorizationLegality; class LoopVectorizationCostModel; -class TargetTransformInfo; class TargetLibraryInfo; /// Helper class to create VPRecipies from IR instructions. @@ -35,6 +34,8 @@ class VPRecipeBuilder { /// The profitablity analysis. LoopVectorizationCostModel &CM; + PredicatedScalarEvolution &PSE; + VPBuilder &Builder; /// When we if-convert we need to create edge masks. We have to cache values @@ -49,11 +50,57 @@ class VPRecipeBuilder { // VPlan-VPlan transformations support: Hold a mapping from ingredients to // their recipe. To save on memory, only do so for selected ingredients, - // marked by having a nullptr entry in this map. If those ingredients get a - // VPWidenRecipe, also avoid compressing other ingredients into it to avoid - // having to split such recipes later. + // marked by having a nullptr entry in this map. DenseMap<Instruction *, VPRecipeBase *> Ingredient2Recipe; - VPWidenRecipe *LastExtensibleRecipe = nullptr; + + /// Check if \p I can be widened at the start of \p Range and possibly + /// decrease the range such that the returned value holds for the entire \p + /// Range. The function should not be called for memory instructions or calls. + bool shouldWiden(Instruction *I, VFRange &Range) const; + + /// Check if the load or store instruction \p I should widened for \p + /// Range.Start and potentially masked. Such instructions are handled by a + /// recipe that takes an additional VPInstruction for the mask. + VPWidenMemoryInstructionRecipe * + tryToWidenMemory(Instruction *I, VFRange &Range, VPlanPtr &Plan); + + /// Check if an induction recipe should be constructed for \I. If so build and + /// return it. If not, return null. + VPWidenIntOrFpInductionRecipe *tryToOptimizeInductionPHI(PHINode *Phi) const; + + /// Optimize the special case where the operand of \p I is a constant integer + /// induction variable. + VPWidenIntOrFpInductionRecipe * + tryToOptimizeInductionTruncate(TruncInst *I, VFRange &Range) const; + + /// Handle non-loop phi nodes. Currently all such phi nodes are turned into + /// a sequence of select instructions as the vectorizer currently performs + /// full if-conversion. + VPBlendRecipe *tryToBlend(PHINode *Phi, VPlanPtr &Plan); + + /// Handle call instructions. If \p CI can be widened for \p Range.Start, + /// return a new VPWidenCallRecipe. Range.End may be decreased to ensure same + /// decision from \p Range.Start to \p Range.End. + VPWidenCallRecipe *tryToWidenCall(CallInst *CI, VFRange &Range, + VPlan &Plan) const; + + /// Check if \p I has an opcode that can be widened and return a VPWidenRecipe + /// if it can. The function should only be called if the cost-model indicates + /// that widening should be performed. + VPWidenRecipe *tryToWiden(Instruction *I, VPlan &Plan) const; + +public: + VPRecipeBuilder(Loop *OrigLoop, const TargetLibraryInfo *TLI, + LoopVectorizationLegality *Legal, + LoopVectorizationCostModel &CM, + PredicatedScalarEvolution &PSE, VPBuilder &Builder) + : OrigLoop(OrigLoop), TLI(TLI), Legal(Legal), CM(CM), PSE(PSE), + Builder(Builder) {} + + /// Check if a recipe can be create for \p I withing the given VF \p Range. + /// If a recipe can be created, return it. Otherwise return nullptr. + VPRecipeBase *tryToCreateWidenRecipe(Instruction *Instr, VFRange &Range, + VPlanPtr &Plan); /// Set the recipe created for given ingredient. This operation is a no-op for /// ingredients that were not marked using a nullptr entry in the map. @@ -65,7 +112,6 @@ class VPRecipeBuilder { Ingredient2Recipe[I] = R; } -public: /// A helper function that computes the predicate of the block BB, assuming /// that the header block of the loop is set to True. It returns the *entry* /// mask for the block BB. @@ -92,48 +138,11 @@ public: return Ingredient2Recipe[I]; } - /// Check if \I is a memory instruction to be widened for \p Range.Start and - /// potentially masked. Such instructions are handled by a recipe that takes - /// an additional VPInstruction for the mask. - VPWidenMemoryInstructionRecipe * - tryToWidenMemory(Instruction *I, VFRange &Range, VPlanPtr &Plan); - - /// Check if an induction recipe should be constructed for \I within the given - /// VF \p Range. If so build and return it. If not, return null. \p Range.End - /// may be decreased to ensure same decision from \p Range.Start to - /// \p Range.End. - VPWidenIntOrFpInductionRecipe *tryToOptimizeInduction(Instruction *I, - VFRange &Range); - - /// Handle non-loop phi nodes. Currently all such phi nodes are turned into - /// a sequence of select instructions as the vectorizer currently performs - /// full if-conversion. - VPBlendRecipe *tryToBlend(Instruction *I, VPlanPtr &Plan); - - /// Check if \p I can be widened within the given VF \p Range. If \p I can be - /// widened for \p Range.Start, check if the last recipe of \p VPBB can be - /// extended to include \p I or else build a new VPWidenRecipe for it and - /// append it to \p VPBB. Return true if \p I can be widened for Range.Start, - /// false otherwise. Range.End may be decreased to ensure same decision from - /// \p Range.Start to \p Range.End. - bool tryToWiden(Instruction *I, VPBasicBlock *VPBB, VFRange &Range); - /// Create a replicating region for instruction \p I that requires /// predication. \p PredRecipe is a VPReplicateRecipe holding \p I. VPRegionBlock *createReplicateRegion(Instruction *I, VPRecipeBase *PredRecipe, VPlanPtr &Plan); -public: - VPRecipeBuilder(Loop *OrigLoop, const TargetLibraryInfo *TLI, - LoopVectorizationLegality *Legal, - LoopVectorizationCostModel &CM, VPBuilder &Builder) - : OrigLoop(OrigLoop), TLI(TLI), Legal(Legal), CM(CM), Builder(Builder) {} - - /// Check if a recipe can be create for \p I withing the given VF \p Range. - /// If a recipe can be created, it adds it to \p VPBB. - bool tryToCreateRecipe(Instruction *Instr, VFRange &Range, VPlanPtr &Plan, - VPBasicBlock *VPBB); - /// Build a VPReplicationRecipe for \p I and enclose it within a Region if it /// is predicated. \return \p VPBB augmented with this new recipe if \p I is /// not predicated, otherwise \return a new VPBasicBlock that succeeds the new |