LLVM  8.0.1
VPRecipeBuilder.h
Go to the documentation of this file.
1 //===- VPRecipeBuilder.h - Helper class to build recipes --------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_TRANSFORMS_VECTORIZE_VPRECIPEBUILDER_H
11 #define LLVM_TRANSFORMS_VECTORIZE_VPRECIPEBUILDER_H
12 
14 #include "VPlan.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/IR/IRBuilder.h"
17 
18 namespace llvm {
19 
20 class LoopVectorizationLegality;
21 class LoopVectorizationCostModel;
22 class TargetTransformInfo;
23 class TargetLibraryInfo;
24 
25 /// Helper class to create VPRecipies from IR instructions.
27  /// The loop that we evaluate.
28  Loop *OrigLoop;
29 
30  /// Target Library Info.
31  const TargetLibraryInfo *TLI;
32 
33  /// Target Transform Info.
34  const TargetTransformInfo *TTI;
35 
36  /// The legality analysis.
38 
39  /// The profitablity analysis.
41 
42  VPBuilder &Builder;
43 
44  /// When we if-convert we need to create edge masks. We have to cache values
45  /// so that we don't end up with exponential recursion/IR. Note that
46  /// if-conversion currently takes place during VPlan-construction, so these
47  /// caches are only used at that stage.
48  using EdgeMaskCacheTy =
51  EdgeMaskCacheTy EdgeMaskCache;
52  BlockMaskCacheTy BlockMaskCache;
53 
54 public:
55  /// A helper function that computes the predicate of the block BB, assuming
56  /// that the header block of the loop is set to True. It returns the *entry*
57  /// mask for the block BB.
58  VPValue *createBlockInMask(BasicBlock *BB, VPlanPtr &Plan);
59 
60  /// A helper function that computes the predicate of the edge between SRC
61  /// and DST.
62  VPValue *createEdgeMask(BasicBlock *Src, BasicBlock *Dst, VPlanPtr &Plan);
63 
64  /// Check if \I belongs to an Interleave Group within the given VF \p Range,
65  /// \return true in the first returned value if so and false otherwise.
66  /// Build a new VPInterleaveGroup Recipe if \I is the primary member of an IG
67  /// for \p Range.Start, and provide it as the second returned value.
68  /// Note that if \I is an adjunct member of an IG for \p Range.Start, the
69  /// \return value is <true, nullptr>, as it is handled by another recipe.
70  /// \p Range.End may be decreased to ensure same decision from \p Range.Start
71  /// to \p Range.End.
73  VPlanPtr &Plan);
74 
75  /// Check if \I is a memory instruction to be widened for \p Range.Start and
76  /// potentially masked. Such instructions are handled by a recipe that takes
77  /// an additional VPInstruction for the mask.
79  tryToWidenMemory(Instruction *I, VFRange &Range, VPlanPtr &Plan);
80 
81  /// Check if an induction recipe should be constructed for \I within the given
82  /// VF \p Range. If so build and return it. If not, return null. \p Range.End
83  /// may be decreased to ensure same decision from \p Range.Start to
84  /// \p Range.End.
86  VFRange &Range);
87 
88  /// Handle non-loop phi nodes. Currently all such phi nodes are turned into
89  /// a sequence of select instructions as the vectorizer currently performs
90  /// full if-conversion.
92 
93  /// Check if \p I can be widened within the given VF \p Range. If \p I can be
94  /// widened for \p Range.Start, check if the last recipe of \p VPBB can be
95  /// extended to include \p I or else build a new VPWidenRecipe for it and
96  /// append it to \p VPBB. Return true if \p I can be widened for Range.Start,
97  /// false otherwise. Range.End may be decreased to ensure same decision from
98  /// \p Range.Start to \p Range.End.
99  bool tryToWiden(Instruction *I, VPBasicBlock *VPBB, VFRange &Range);
100 
101  /// Create a replicating region for instruction \p I that requires
102  /// predication. \p PredRecipe is a VPReplicateRecipe holding \p I.
104  VPlanPtr &Plan);
105 
106 public:
107  VPRecipeBuilder(Loop *OrigLoop, const TargetLibraryInfo *TLI,
108  const TargetTransformInfo *TTI,
111  : OrigLoop(OrigLoop), TLI(TLI), TTI(TTI), Legal(Legal), CM(CM),
112  Builder(Builder) {}
113 
114  /// Check if a recipe can be create for \p I withing the given VF \p Range.
115  /// If a recipe can be created, it adds it to \p VPBB.
116  bool tryToCreateRecipe(Instruction *Instr, VFRange &Range, VPlanPtr &Plan,
117  VPBasicBlock *VPBB);
118 
119  /// Build a VPReplicationRecipe for \p I and enclose it within a Region if it
120  /// is predicated. \return \p VPBB augmented with this new recipe if \p I is
121  /// not predicated, otherwise \return a new VPBasicBlock that succeeds the new
122  /// Region. Update the packing decision of predicated instructions if they
123  /// feed \p I. Range.End may be decreased to ensure same recipe behavior from
124  /// \p Range.Start to \p Range.End.
126  Instruction *I, VFRange &Range, VPBasicBlock *VPBB,
128  VPlanPtr &Plan);
129 };
130 } // end namespace llvm
131 
132 #endif // LLVM_TRANSFORMS_VECTORIZE_VPRECIPEBUILDER_H
VPInterleaveRecipe * tryToInterleaveMemory(Instruction *I, VFRange &Range, VPlanPtr &Plan)
Check if belongs to an Interleave Group within the given VF Range,.
This class represents lattice values for constants.
Definition: AllocatorList.h:24
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:1050
VPWidenMemoryInstructionRecipe * tryToWidenMemory(Instruction *I, VFRange &Range, VPlanPtr &Plan)
Check if is a memory instruction to be widened for Range.Start and potentially masked.
Helper class to create VPRecipies from IR instructions.
LoopVectorizationLegality checks if it is legal to vectorize a loop, and to what vectorization factor...
bool tryToCreateRecipe(Instruction *Instr, VFRange &Range, VPlanPtr &Plan, VPBasicBlock *VPBB)
Check if a recipe can be create for I withing the given VF Range.
A Recipe for widening load/store operations.
Definition: VPlan.h:938
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition: VPlan.h:551
VPValue * createBlockInMask(BasicBlock *BB, VPlanPtr &Plan)
A helper function that computes the predicate of the block BB, assuming that the header block of the ...
bool tryToWiden(Instruction *I, VPBasicBlock *VPBB, VFRange &Range)
Check if I can be widened within the given VF Range.
VPBlendRecipe * tryToBlend(Instruction *I, VPlanPtr &Plan)
Handle non-loop phi nodes.
VPRegionBlock * createReplicateRegion(Instruction *I, VPRecipeBase *PredRecipe, VPlanPtr &Plan)
Create a replicating region for instruction I that requires predication.
VPRecipeBuilder(Loop *OrigLoop, const TargetLibraryInfo *TLI, const TargetTransformInfo *TTI, LoopVectorizationLegality *Legal, LoopVectorizationCostModel &CM, VPBuilder &Builder)
This file provides a LoopVectorizationPlanner class.
VPlan-based builder utility analogous to IRBuilder.
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
This file contains the declarations of the Vectorization Plan base classes:
std::unique_ptr< VPlan > VPlanPtr
Definition: VPlan.h:76
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:965
A range of powers-of-2 vectorization factors with fixed start and adjustable end. ...
Definition: VPlan.h:68
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Provides information about what library functions are available for the current target.
VPValue * createEdgeMask(BasicBlock *Src, BasicBlock *Dst, VPlanPtr &Plan)
A helper function that computes the predicate of the edge between SRC and DST.
VPInterleaveRecipe is a recipe for transforming an interleave group of load or stores into one wide l...
Definition: VPlan.h:801
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:465
VPBasicBlock * handleReplication(Instruction *I, VFRange &Range, VPBasicBlock *VPBB, DenseMap< Instruction *, VPReplicateRecipe *> &PredInst2Recipe, VPlanPtr &Plan)
Build a VPReplicationRecipe for I and enclose it within a Region if it is predicated.
#define I(x, y, z)
Definition: MD5.cpp:58
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector and ...
Definition: VPlan.h:724
LoopVectorizationCostModel - estimates the expected speedups due to vectorization.
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition: VPlan.h:770
VPWidenIntOrFpInductionRecipe * tryToOptimizeInduction(Instruction *I, VFRange &Range)
Check if an induction recipe should be constructed for within the given VF Range.