LLVM 24.0.0git
VPlanUtils.h
Go to the documentation of this file.
1//===- VPlanUtils.h - VPlan-related utilities -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H
10#define LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H
11
12#include "VPlan.h"
14
15namespace llvm {
16class DominatorTree;
17class MemoryLocation;
18class ScalarEvolution;
19class SCEV;
21class VPBuilder;
22} // namespace llvm
23
24namespace llvm {
25
26namespace vputils {
27/// Returns true if only the first lane of \p Def is used.
28bool onlyFirstLaneUsed(const VPValue *Def);
29
30/// Returns true if only the first part of \p Def is used.
31bool onlyFirstPartUsed(const VPValue *Def);
32
33/// Returns true if only scalar values of \p Def are used by all users.
34bool onlyScalarValuesUsed(const VPValue *Def);
35
36/// Get or create a VPValue that corresponds to the expansion of \p Expr. If \p
37/// Expr is a SCEVConstant or SCEVUnknown, return a VPValue wrapping the live-in
38/// value. Otherwise return a VPExpandSCEVRecipe to expand \p Expr. If \p Plan's
39/// pre-header already contains a recipe expanding \p Expr, return it. If not,
40/// create a new one.
42
43/// Return the SCEV expression for \p V. Returns SCEVCouldNotCompute if no
44/// SCEV expression could be constructed.
45const SCEV *getSCEVExprForVPValue(const VPValue *V,
47 const Loop *L = nullptr);
48
49/// Returns true if \p Addr is an address SCEV that can be passed to
50/// TTI::getAddressComputationCost, i.e. the address SCEV is loop invariant, an
51/// affine AddRec (i.e. induction ), or an add expression of such operands or a
52/// sign-extended AddRec.
53bool isAddressSCEVForCost(const SCEV *Addr, ScalarEvolution &SE, const Loop *L);
54
55/// Returns true if \p VPV is a single scalar, either because it produces the
56/// same value for all lanes or only has its first lane used.
57bool isSingleScalar(const VPValue *VPV);
58
59/// Checks if \p V is uniform across all VF lanes and UF parts. It is considered
60/// as such if it is either loop invariant (defined outside the vector region)
61/// or its operands are known to be uniform across all VFs and UFs (e.g.
62/// VPDerivedIV or the canonical IV).
64
65/// Return true if \p V is elementwise, i.e. none of the lanes are permuted.
66bool isElementwise(const VPValue *V);
67
68/// Returns true if \p R produces scalar values for all VF lanes.
70
71/// Returns the header block of the first, top-level loop, or null if none
72/// exist.
74
75/// Get the VF scaling factor applied to the recipe's output, if the recipe has
76/// one.
78
79/// Return true if we do not know how to (mechanically) hoist or sink \p R.
80/// When sinking, passing \p Sinking = true ensures that assumes aren't sunk.
81/// Returns true for recipes that access memory.
82bool cannotHoistOrSinkRecipe(const VPRecipeBase &R, bool Sinking = false);
83
84/// Return the intrinsic ID underlying a call.
85template <typename Ty> Intrinsic::ID getIntrinsicID(const Ty *R) {
86 if (const auto *Intr = dyn_cast<VPWidenIntrinsicRecipe>(R))
87 return Intr->getVectorIntrinsicID();
88 if (const auto *Call = dyn_cast<VPWidenCallRecipe>(R))
89 return Call->getCalledScalarFunction()->getIntrinsicID();
90
91 auto GetCalleeIntrinsic = [&](VPValue *CalleeOp) -> Intrinsic::ID {
92 if (!isa<VPIRValue>(CalleeOp))
94 auto *F = cast<Function>(CalleeOp->getLiveInIRValue());
95 return F->getIntrinsicID();
96 };
97 if (const auto *Rep = dyn_cast<VPReplicateRecipe>(R))
98 if (Rep->getOpcode() == Instruction::Call)
99 // The callee is the last operand, excluding the mask if predicated.
100 return GetCalleeIntrinsic(
101 Rep->getOperand(Rep->getNumOperandsWithoutMask() - 1));
102 if (const auto *VPI = dyn_cast<VPInstruction>(R)) {
103 if (VPI->getOpcode() == Instruction::Call)
104 return GetCalleeIntrinsic(VPI->getOperand(VPI->getNumOperands() - 1));
105 if (VPI->getOpcode() == VPInstruction::Intrinsic) {
106 return cast<VPConstantInt>(VPI->getOperand(VPI->getNumOperands() - 1))
107 ->getZExtValue();
108 }
109 }
111}
112
113/// Return the instruction opcode for the recipe defining \p V or 0 for
114/// unsupported recipes and VPValues not defined by a recipe.
115unsigned getOpcode(const VPValue *V);
116
117/// Get the instruction opcode or intrinsic ID for the recipe defining \p V.
118/// Returns an optional pair, where the first element indicates whether it is an
119/// intrinsic ID.
120std::optional<std::pair<bool, unsigned>>
122
123/// Return a MemoryLocation for \p R with noalias metadata populated from
124/// \p R, if the recipe is supported and std::nullopt otherwise. The pointer of
125/// the location is conservatively set to nullptr.
126std::optional<MemoryLocation> getMemoryLocation(const VPRecipeBase &R);
127
128/// Extracts and returns NoWrap and FastMath flags from the induction binop in
129/// \p ID.
132 return ID.getInductionBinOp()->getFastMathFlags();
133
135 ID.getInductionBinOp()))
136 return VPIRFlags::WrapFlagsTy(OBO->hasNoUnsignedWrap(),
137 OBO->hasNoSignedWrap());
138
140 "Expected int induction");
141 return VPIRFlags::WrapFlagsTy(false, false);
142}
143
144/// Search \p Start's users for a recipe satisfying \p Pred, looking through
145/// recipes with definitions.
146template <typename PredT>
147inline VPRecipeBase *findRecipe(VPValue *Start, PredT Pred) {
148 SetVector<VPValue *> Worklist;
149 Worklist.insert(Start);
150 for (unsigned I = 0; I != Worklist.size(); ++I) {
151 VPValue *Cur = Worklist[I];
152 auto *R = Cur->getDefiningRecipe();
153 if (!R)
154 continue;
155 if (Pred(R))
156 return R;
157 for (VPUser *U : Cur->users()) {
158 for (VPValue *V : cast<VPRecipeBase>(U)->definedValues())
159 Worklist.insert(V);
160 }
161 }
162 return nullptr;
163}
164
165/// Find the canonical IV increment of \p Plan's vector loop region. Returns
166/// nullptr if not found.
168
169/// Returns the GEP nowrap flags for \p Ptr, looking through pointer casts
170/// mirroring Value::stripPointerCasts.
172
173/// Returns true if \p V is used as part of the address of another load or
174/// store.
175bool isUsedByLoadStoreAddress(const VPValue *V);
176
177/// Find the ComputeReductionResult recipe for \p PhiR, looking through selects
178/// inserted for predicated reductions or tail folding.
180
181/// Finds the incoming alias-mask within the vector preheader.
183
184/// Create a scalar-iv-steps recipe over \p Plan's canonical IV for an
185/// induction of \p Kind with \p InductionOpcode / \p FPBinOp, start value \p
186/// StartV and step \p Step, truncated to \p TruncI's type if \p TruncI is
187/// non-null, inserting recipes via \p Builder.
190 Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp,
191 Instruction *TruncI, VPIRValue *StartV, VPValue *Step, DebugLoc DL,
192 VPBuilder &Builder, const VPIRFlags::WrapFlagsTy &Flags = {});
193
194/// Scalarize a VPWidenPointerInductionRecipe by replacing it with a PtrAdd
195/// (IndStart, ScalarIVSteps (0, Step)). This is used when the recipe only
196/// generates scalar values.
197VPValue *scalarizeVPWidenPointerInduction(VPWidenPointerInductionRecipe *PtrIV,
198 VPlan &Plan, VPBuilder &Builder);
199
200/// Returns true if \p R is dead, i.e. none of its defined values are used and
201/// it has no side effects (with the exception of conditional assumes, which are
202/// considered dead as their conditions may be flattened).
203bool isDeadRecipe(VPRecipeBase &R);
204
205/// Recursively delete \p V and any of its operands that become dead.
206void recursivelyDeleteDeadRecipes(VPValue *V);
207
208/// Collect all users of \p V, looking through recipes that define other values.
210
211/// Try to fold \p R using InstSimplifyFolder. Will succeed and return a
212/// non-nullptr VPValue for a handled opcode or intrinsic ID if corresponding \p
213/// Operands are foldable live-ins.
214VPIRValue *tryToFoldLiveIns(VPSingleDefRecipe &R, ArrayRef<VPValue *> Operands,
215 const DataLayout &DL);
216
217namespace detail {
218
219/// Template-independent implementation for pullOutPermutations.
221 VPlan &Plan, function_ref<VPValue *(VPValue *Op)> Perm,
223} // namespace detail
224
225/// Removes the permutation pattern \p Perm from any elementwise operations
226/// in the plan, by constructing a new permutation via \p Build.
227/// e.g. binop(perm(x), perm(y)) -> perm(binop(x,y)).
228template <typename Match_t, typename Builder>
229void pullOutPermutations(VPlan &Plan, Match_t Perm, Builder Build) {
230 // Convert matcher to function returing the matched VPValue.
231 auto MatchPerm = [&Perm](VPValue *Op) -> VPValue * {
232 VPValue *X;
233 return match(Op, Perm(X)) ? X : nullptr;
234 };
235 detail::pullOutPermutationsImpl(Plan, MatchPerm, Build);
236}
237
238} // namespace vputils
239
240/// Lightweight SCEV-to-VPlan expander. Converts SCEV expressions into
241/// VPInstructions where possible, and returning nullptr for unsupported
242/// expressions (like adds, casts, min/max).
244 VPBuilder &Builder;
245 ScalarEvolution &SE;
246 DebugLoc DL;
247
248 /// Try to find a loop-invariant IR value in the plan's entry block whose
249 /// SCEV matches \p S. Returns the corresponding live-in VPValue, or nullptr
250 /// if none is found.
251 VPValue *tryToReuseIRValue(const SCEV *S);
252
253public:
255 : Builder(Builder), SE(SE), DL(DL) {}
256
257 /// Try to expand \p S into recipes and live-ins using the builder. Returns
258 /// nullptr if \p S cannot be expanded yet.
259 VPValue *tryToExpand(const SCEV *S);
260};
261//===----------------------------------------------------------------------===//
262// Utilities for modifying predecessors and successors of VPlan blocks.
263//===----------------------------------------------------------------------===//
264
265/// Class that provides utilities for VPBlockBases in VPlan.
267public:
268 VPBlockUtils() = delete;
269
270 /// Insert disconnected VPBlockBase \p NewBlock after \p BlockPtr. Add \p
271 /// NewBlock as successor of \p BlockPtr and \p BlockPtr as predecessor of \p
272 /// NewBlock, and propagate \p BlockPtr parent to \p NewBlock. \p BlockPtr's
273 /// successors are moved from \p BlockPtr to \p NewBlock. \p NewBlock must
274 /// have neither successors nor predecessors.
275 static void insertBlockAfter(VPBlockBase *NewBlock, VPBlockBase *BlockPtr) {
276 assert(!NewBlock->hasSuccessors() && !NewBlock->hasPredecessors() &&
277 "Can't insert new block with predecessors or successors.");
278 NewBlock->setParent(BlockPtr->getParent());
279 transferSuccessors(BlockPtr, NewBlock);
280 connectBlocks(BlockPtr, NewBlock);
281 }
282
283 /// Insert disconnected block \p NewBlock before \p Blockptr. First
284 /// disconnects all predecessors of \p BlockPtr and connects them to \p
285 /// NewBlock. Add \p NewBlock as predecessor of \p BlockPtr and \p BlockPtr as
286 /// successor of \p NewBlock.
287 static void insertBlockBefore(VPBlockBase *NewBlock, VPBlockBase *BlockPtr) {
288 assert(!NewBlock->hasSuccessors() && !NewBlock->hasPredecessors() &&
289 "Can't insert new block with predecessors or successors.");
290 NewBlock->setParent(BlockPtr->getParent());
291 for (VPBlockBase *Pred : to_vector(BlockPtr->predecessors())) {
292 Pred->replaceSuccessor(BlockPtr, NewBlock);
293 NewBlock->appendPredecessor(Pred);
294 }
295 BlockPtr->clearPredecessors();
296 connectBlocks(NewBlock, BlockPtr);
297 }
298
299 /// Insert disconnected VPBlockBases \p IfTrue and \p IfFalse after \p
300 /// BlockPtr. Add \p IfTrue and \p IfFalse as succesors of \p BlockPtr and \p
301 /// BlockPtr as predecessor of \p IfTrue and \p IfFalse. Propagate \p BlockPtr
302 /// parent to \p IfTrue and \p IfFalse. \p BlockPtr must have no successors
303 /// and \p IfTrue and \p IfFalse must have neither successors nor
304 /// predecessors.
305 static void insertTwoBlocksAfter(VPBlockBase *IfTrue, VPBlockBase *IfFalse,
306 VPBlockBase *BlockPtr) {
307 assert(!IfTrue->hasSuccessors() && "Can't insert IfTrue with successors.");
308 assert(!IfFalse->hasSuccessors() &&
309 "Can't insert IfFalse with successors.");
310 BlockPtr->setTwoSuccessors(IfTrue, IfFalse);
311 IfTrue->setPredecessors({BlockPtr});
312 IfFalse->setPredecessors({BlockPtr});
313 IfTrue->setParent(BlockPtr->getParent());
314 IfFalse->setParent(BlockPtr->getParent());
315 }
316
317 /// Connect VPBlockBases \p From and \p To bi-directionally. If \p PredIdx is
318 /// -1, append \p From to the predecessors of \p To, otherwise set \p To's
319 /// predecessor at \p PredIdx to \p From. If \p SuccIdx is -1, append \p To to
320 /// the successors of \p From, otherwise set \p From's successor at \p SuccIdx
321 /// to \p To. Both VPBlockBases must have the same parent, which can be null.
322 /// Both VPBlockBases can be already connected to other VPBlockBases.
323 static void connectBlocks(VPBlockBase *From, VPBlockBase *To,
324 unsigned PredIdx = -1u, unsigned SuccIdx = -1u) {
325 assert((From->getParent() == To->getParent()) &&
326 "Can't connect two block with different parents");
327
328 if (SuccIdx == -1u)
329 From->appendSuccessor(To);
330 else
331 From->getSuccessors()[SuccIdx] = To;
332
333 if (PredIdx == -1u)
334 To->appendPredecessor(From);
335 else
336 To->getPredecessors()[PredIdx] = From;
337 }
338
339 /// Disconnect VPBlockBases \p From and \p To bi-directionally. Remove \p To
340 /// from the successors of \p From and \p From from the predecessors of \p To.
341 static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To) {
342 assert(To && "Successor to disconnect is null.");
343 From->removeSuccessor(To);
344 To->removePredecessor(From);
345 }
346
347 /// Reassociate all the blocks connected to \p Old so that they now point to
348 /// \p New.
349 static void reassociateBlocks(VPBlockBase *Old, VPBlockBase *New) {
350 for (auto *Pred : to_vector(Old->getPredecessors()))
351 Pred->replaceSuccessor(Old, New);
352 for (auto *Succ : to_vector(Old->getSuccessors()))
353 Succ->replacePredecessor(Old, New);
354 New->setPredecessors(Old->getPredecessors());
355 New->setSuccessors(Old->getSuccessors());
356 Old->clearPredecessors();
357 Old->clearSuccessors();
358 }
359
360 /// Transfer successors from \p Old to \p New. \p New must have no successors.
362 for (auto *Succ : Old->getSuccessors())
363 Succ->replacePredecessor(Old, New);
364 New->setSuccessors(Old->getSuccessors());
365 Old->clearSuccessors();
366 }
367
368 /// Clone the CFG for all nodes reachable from \p Entry, including cloning
369 /// the blocks and their recipes. Operands of cloned recipes will NOT be
370 /// updated. Remapping of operands must be done separately. Returns a pair
371 /// with the new entry and exiting blocks of the cloned region. If \p Entry
372 /// isn't part of a region, return nullptr for the exiting block.
373 static std::pair<VPBlockBase *, VPBlockBase *> cloneFrom(VPBlockBase *Entry);
374
375 /// Return an iterator range over \p Range which only includes \p BlockTy
376 /// blocks. The accesses are casted to \p BlockTy.
377 template <typename BlockTy, typename T> static auto blocksOnly(T &&Range) {
378 // Create BaseTy with correct const-ness based on BlockTy.
379 using BaseTy = std::conditional_t<std::is_const<BlockTy>::value,
380 const VPBlockBase, VPBlockBase>;
381
382 // We need to first create an iterator range over (const) BlocktTy & instead
383 // of (const) BlockTy * for filter_range to work properly.
384 auto Mapped =
385 map_range(Range, [](BaseTy *Block) -> BaseTy & { return *Block; });
387 Mapped, [](BaseTy &Block) { return isa<BlockTy>(&Block); });
388 return map_range(Filter, [](BaseTy &Block) -> BlockTy * {
389 return cast<BlockTy>(&Block);
390 });
391 }
392
393 /// Return an iterator range over \p Range with each block cast to \p
394 /// BlockTy. Unlike blocksOnly, all blocks in \p Range must be of type
395 /// \p BlockTy.
396 template <typename BlockTy, typename T> static auto blocksAs(T &&Range) {
397 // Create BaseTy with correct const-ness based on BlockTy.
398 using BaseTy = std::conditional_t<std::is_const<BlockTy>::value,
399 const VPBlockBase, VPBlockBase>;
400 return map_range(
401 Range, [](BaseTy *Block) -> BlockTy * { return cast<BlockTy>(Block); });
402 }
403
404 /// Returns the blocks between \p FirstBB and \p LastBB, where FirstBB
405 /// to LastBB forms a single-sucessor chain.
408 VPBasicBlock *LastBB);
409
410 /// Inserts \p BlockPtr on the edge between \p From and \p To. That is, update
411 /// \p From's successor to \p To to point to \p BlockPtr and \p To's
412 /// predecessor from \p From to \p BlockPtr. \p From and \p To are added to \p
413 /// BlockPtr's predecessors and successors respectively. There must be a
414 /// single edge between \p From and \p To.
415 static void insertOnEdge(VPBlockBase *From, VPBlockBase *To,
416 VPBlockBase *BlockPtr) {
417 unsigned SuccIdx = From->getIndexForSuccessor(To);
418 unsigned PredIx = To->getIndexForPredecessor(From);
419 VPBlockUtils::connectBlocks(From, BlockPtr, -1, SuccIdx);
420 VPBlockUtils::connectBlocks(BlockPtr, To, PredIx, -1);
421 }
422
423 /// Returns true if \p VPB is a loop header, based on regions or \p VPDT in
424 /// their absence.
425 static bool isHeader(const VPBlockBase *VPB, const VPDominatorTree &VPDT);
426
427 /// Returns true if \p VPB is a loop latch, using isHeader().
428 static bool isLatch(const VPBlockBase *VPB, const VPDominatorTree &VPDT);
429
430 /// Returns the header and latch of the outermost loop of \p Plan in plain
431 /// CFG form (before regions are formed).
432 static std::pair<VPBasicBlock *, VPBasicBlock *>
433 getPlainCFGHeaderAndLatch(const VPlan &Plan);
434
435 /// Returns the middle block of \p Plan in plain CFG form (before regions
436 /// are formed).
437 static VPBasicBlock *getPlainCFGMiddleBlock(const VPlan &Plan);
438};
439
440} // namespace llvm
441
442#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
std::pair< BasicBlock *, unsigned > BlockTy
A pair of (basic block, score).
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file contains the declarations of the Vectorization Plan base classes:
A debug info location.
Definition DebugLoc.h:126
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:151
Utility class for floating point operations which can have information about relaxed accuracy require...
Definition Operator.h:202
Represents flags for the getelementptr instruction/expression.
A struct for saving information about induction variables.
InductionKind
This enum represents the kinds of inductions that we support.
@ IK_FpInduction
Floating point induction variable.
@ IK_IntInduction
Integer induction variable. Step = C.
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
Representation for a specific memory location.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
This class represents an analyzed expression in the program.
The main scalar evolution driver.
A vector that has set insertion semantics.
Definition SetVector.h:57
size_type size() const
Determine the number of elements in the SetVector.
Definition SetVector.h:103
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:151
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4376
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:94
VPRegionBlock * getParent()
Definition VPlan.h:192
iterator_range< VPBlockBase ** > predecessors()
Definition VPlan.h:226
bool hasPredecessors() const
Returns true if this block has any predecessors.
Definition VPlan.h:223
unsigned getIndexForSuccessor(const VPBlockBase *Succ) const
Returns the index for Succ in the blocks successor list.
Definition VPlan.h:350
void setPredecessors(ArrayRef< VPBlockBase * > NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
Definition VPlan.h:306
unsigned getIndexForPredecessor(const VPBlockBase *Pred) const
Returns the index for Pred in the blocks predecessors list.
Definition VPlan.h:343
bool hasSuccessors() const
Returns true if this block has any successors.
Definition VPlan.h:221
const VPBlocksTy & getPredecessors() const
Definition VPlan.h:228
void clearSuccessors()
Remove all the successors of this block.
Definition VPlan.h:325
void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse)
Set two given VPBlockBases IfTrue and IfFalse to be the two successors of this VPBlockBase.
Definition VPlan.h:297
void clearPredecessors()
Remove all the predecessor of this block.
Definition VPlan.h:322
void setParent(VPRegionBlock *P)
Definition VPlan.h:203
const VPBlocksTy & getSuccessors() const
Definition VPlan.h:217
static auto blocksAs(T &&Range)
Return an iterator range over Range with each block cast to BlockTy.
Definition VPlanUtils.h:396
static void insertBlockAfter(VPBlockBase *NewBlock, VPBlockBase *BlockPtr)
Insert disconnected VPBlockBase NewBlock after BlockPtr.
Definition VPlanUtils.h:275
static void insertOnEdge(VPBlockBase *From, VPBlockBase *To, VPBlockBase *BlockPtr)
Inserts BlockPtr on the edge between From and To.
Definition VPlanUtils.h:415
static bool isLatch(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop latch, using isHeader().
static VPBasicBlock * getPlainCFGMiddleBlock(const VPlan &Plan)
Returns the middle block of Plan in plain CFG form (before regions are formed).
static bool isHeader(const VPBlockBase *VPB, const VPDominatorTree &VPDT)
Returns true if VPB is a loop header, based on regions or VPDT in their absence.
static void insertTwoBlocksAfter(VPBlockBase *IfTrue, VPBlockBase *IfFalse, VPBlockBase *BlockPtr)
Insert disconnected VPBlockBases IfTrue and IfFalse after BlockPtr.
Definition VPlanUtils.h:305
static void connectBlocks(VPBlockBase *From, VPBlockBase *To, unsigned PredIdx=-1u, unsigned SuccIdx=-1u)
Connect VPBlockBases From and To bi-directionally.
Definition VPlanUtils.h:323
static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To)
Disconnect VPBlockBases From and To bi-directionally.
Definition VPlanUtils.h:341
static void reassociateBlocks(VPBlockBase *Old, VPBlockBase *New)
Reassociate all the blocks connected to Old so that they now point to New.
Definition VPlanUtils.h:349
static void insertBlockBefore(VPBlockBase *NewBlock, VPBlockBase *BlockPtr)
Insert disconnected block NewBlock before Blockptr.
Definition VPlanUtils.h:287
static auto blocksOnly(T &&Range)
Return an iterator range over Range which only includes BlockTy blocks.
Definition VPlanUtils.h:377
static std::pair< VPBasicBlock *, VPBasicBlock * > getPlainCFGHeaderAndLatch(const VPlan &Plan)
Returns the header and latch of the outermost loop of Plan in plain CFG form (before regions are form...
static void transferSuccessors(VPBlockBase *Old, VPBlockBase *New)
Transfer successors from Old to New. New must have no successors.
Definition VPlanUtils.h:361
static SmallVector< VPBasicBlock * > blocksInSingleSuccessorChainBetween(VPBasicBlock *FirstBB, VPBasicBlock *LastBB)
Returns the blocks between FirstBB and LastBB, where FirstBB to LastBB forms a single-sucessor chain.
static std::pair< VPBlockBase *, VPBlockBase * > cloneFrom(VPBlockBase *Entry)
Clone the CFG for all nodes reachable from Entry, including cloning the blocks and their recipes.
Definition VPlan.cpp:712
VPlan-based builder utility analogous to IRBuilder.
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
Class to record and manage LLVM IR flags.
Definition VPlan.h:704
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1234
@ Intrinsic
Calls a scalar intrinsic. The intrinsic ID is the last operand.
Definition VPlan.h:1356
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:411
A recipe for handling reduction phis.
Definition VPlan.h:2852
VPValue * tryToExpand(const SCEV *S)
Try to expand S into recipes and live-ins using the builder.
VPSCEVExpander(VPBuilder &Builder, ScalarEvolution &SE, DebugLoc DL)
Definition VPlanUtils.h:254
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:4231
VPSingleDefRecipe is a base class for recipes that model a sequence of one or more output IR that def...
Definition VPlan.h:619
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:401
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:50
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition VPlan.cpp:130
user_range users()
Definition VPlanValue.h:157
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4788
An efficient, type-erasing, non-owning reference to a callable.
CallInst * Call
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
bool match(Val *V, const Pattern &P)
void pullOutPermutationsImpl(VPlan &Plan, function_ref< VPValue *(VPValue *Op)> Perm, function_ref< VPSingleDefRecipe *(VPSingleDefRecipe *X)> Build)
Template-independent implementation for pullOutPermutations.
bool isSingleScalar(const VPValue *VPV)
Returns true if VPV is a single scalar, either because it produces the same value for all lanes or on...
VPValue * getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr)
Get or create a VPValue that corresponds to the expansion of Expr.
bool cannotHoistOrSinkRecipe(const VPRecipeBase &R, bool Sinking=false)
Return true if we do not know how to (mechanically) hoist or sink R.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
VPBasicBlock * getFirstLoopHeader(VPlan &Plan, VPDominatorTree &VPDT)
Returns the header block of the first, top-level loop, or null if none exist.
bool isAddressSCEVForCost(const SCEV *Addr, ScalarEvolution &SE, const Loop *L)
Returns true if Addr is an address SCEV that can be passed to TTI::getAddressComputationCost,...
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used.
Intrinsic::ID getIntrinsicID(const Ty *R)
Return the intrinsic ID underlying a call.
Definition VPlanUtils.h:85
VPInstruction * findComputeReductionResult(VPReductionPHIRecipe *PhiR)
Find the ComputeReductionResult recipe for PhiR, looking through selects inserted for predicated redu...
VPInstruction * findCanonicalIVIncrement(VPlan &Plan)
Find the canonical IV increment of Plan's vector loop region.
std::optional< MemoryLocation > getMemoryLocation(const VPRecipeBase &R)
Return a MemoryLocation for R with noalias metadata populated from R, if the recipe is supported and ...
bool onlyFirstLaneUsed(const VPValue *Def)
Returns true if only the first lane of Def is used.
VPIRValue * tryToFoldLiveIns(VPSingleDefRecipe &R, ArrayRef< VPValue * > Operands, const DataLayout &DL)
Try to fold R using InstSimplifyFolder.
VPValue * findIncomingAliasMask(const VPlan &Plan)
Finds the incoming alias-mask within the vector preheader.
VPIRFlags getFlagsFromIndDesc(const InductionDescriptor &ID)
Extracts and returns NoWrap and FastMath flags from the induction binop in ID.
Definition VPlanUtils.h:130
void recursivelyDeleteDeadRecipes(VPValue *V)
Recursively delete V and any of its operands that become dead.
bool doesGeneratePerAllLanes(const VPRecipeBase *R)
Returns true if R produces scalar values for all VF lanes.
bool isDeadRecipe(VPRecipeBase &R)
Returns true if R is dead, i.e.
VPRecipeBase * findRecipe(VPValue *Start, PredT Pred)
Search Start's users for a recipe satisfying Pred, looking through recipes with definitions.
Definition VPlanUtils.h:147
bool isElementwise(const VPValue *V)
Return true if V is elementwise, i.e. none of the lanes are permuted.
bool onlyScalarValuesUsed(const VPValue *Def)
Returns true if only scalar values of Def are used by all users.
bool isUniformAcrossVFsAndUFs(const VPValue *V)
Checks if V is uniform across all VF lanes and UF parts.
bool isUsedByLoadStoreAddress(const VPValue *V)
Returns true if V is used as part of the address of another load or store.
std::optional< std::pair< bool, unsigned > > getOpcodeOrIntrinsicID(const VPValue *V)
Get the instruction opcode or intrinsic ID for the recipe defining V.
VPValue * scalarizeVPWidenPointerInduction(VPWidenPointerInductionRecipe *PtrIV, VPlan &Plan, VPBuilder &Builder)
Scalarize a VPWidenPointerInductionRecipe by replacing it with a PtrAdd (IndStart,...
GEPNoWrapFlags getGEPFlagsForPtr(VPValue *Ptr)
Returns the GEP nowrap flags for Ptr, looking through pointer casts mirroring Value::stripPointerCast...
const SCEV * getSCEVExprForVPValue(const VPValue *V, PredicatedScalarEvolution &PSE, const Loop *L=nullptr)
Return the SCEV expression for V.
void pullOutPermutations(VPlan &Plan, Match_t Perm, Builder Build)
Removes the permutation pattern Perm from any elementwise operations in the plan, by constructing a n...
Definition VPlanUtils.h:229
unsigned getVFScaleFactor(VPRecipeBase *R)
Get the VF scaling factor applied to the recipe's output, if the recipe has one.
SmallVector< VPUser * > collectUsersRecursively(VPValue *V)
Collect all users of V, looking through recipes that define other values.
VPScalarIVStepsRecipe * createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind, Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp, Instruction *TruncI, VPIRValue *StartV, VPValue *Step, DebugLoc DL, VPBuilder &Builder, const VPIRFlags::WrapFlagsTy &Flags={})
Create a scalar-iv-steps recipe over Plan's canonical IV for an induction of Kind with InductionOpcod...
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
Definition STLExtras.h:365
SmallVector< ValueTypeFromRangeType< R >, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:551
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
A VPValue representing a live-in from the input IR or a constant.
Definition VPlanValue.h:279