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"
16
17namespace llvm {
18class MemoryLocation;
19class ScalarEvolution;
20class SCEV;
21class SCEVNAryExpr;
23} // namespace llvm
24
25namespace llvm {
26
27namespace vputils {
28/// Returns true if checking whether \p U uses the first lane of \p Op requires
29/// recursively checking \p Op's users.
30bool propagatesFirstLaneUse(const VPUser *U, const VPValue *Op);
31
32/// Returns true if only the first lane of \p Def is used by all users.
33bool onlyFirstLaneUsed(const VPValue *Def);
34
35/// Returns true if only the first part of \p Def is used by all users.
36bool onlyFirstPartUsed(const VPValue *Def);
37
38/// Returns true if only scalar values of \p Def are used by all users.
39bool onlyScalarValuesUsed(const VPValue *Def);
40
41/// Returns true if only scalar values of \p Def are used by all users, either
42/// directly or by extracting a constant lane.
44
45/// Get or create a VPValue that corresponds to the expansion of \p Expr. If \p
46/// Expr is a SCEVConstant or SCEVUnknown, return a VPValue wrapping the live-in
47/// value. Otherwise return a VPExpandSCEVRecipe to expand \p Expr. If \p Plan's
48/// pre-header already contains a recipe expanding \p Expr, return it. If not,
49/// create a new one. \p ExpandInIR is forwarded to the VPExpandSCEVRecipe.
51 bool ExpandInIR = false);
52
53/// Return the SCEV expression for \p V. Returns SCEVCouldNotCompute if no
54/// SCEV expression could be constructed.
57 const Loop *L = nullptr);
58
59/// If the pointer operand \p Addr of a memory access is an affine AddRec
60/// w.r.t. \p L with a constant stride, return the stride in units of
61/// \p AccessTy. Otherwise, or if \p AccessTy is irregular, return
62/// std::nullopt.
63std::optional<int64_t> getConstantStride(VPValue *Addr, Type *AccessTy,
65 const Loop *L);
66
67/// Returns true if \p Addr is an address SCEV that can be passed to
68/// TTI::getAddressComputationCost, i.e. the address SCEV is loop invariant, an
69/// affine AddRec (i.e. induction ), or an add expression of such operands or a
70/// sign-extended AddRec.
71bool isAddressSCEVForCost(const SCEV *Addr, ScalarEvolution &SE, const Loop *L);
72
73/// Returns true if \p VPV is a single scalar, either because it produces the
74/// same value for all lanes or only has its first lane used.
75bool isSingleScalar(const VPValue *VPV);
76
77/// Checks if \p V is uniform across all VF lanes and UF parts. It is considered
78/// as such if it is either loop invariant (defined outside the vector region)
79/// or its operands are known to be uniform across all VFs and UFs (e.g.
80/// VPDerivedIV or the canonical IV).
82
83/// Return true if \p V is elementwise, i.e. none of the lanes are permuted.
84bool isElementwise(const VPValue *V);
85
86/// Returns true if \p R produces scalar values for all VF lanes.
88
89/// Returns the header block of the first, top-level loop, or null if none
90/// exist.
92
93/// Get the VF scaling factor applied to the recipe's output, if the recipe has
94/// one.
96
97/// Return true if we do not know how to (mechanically) hoist or sink \p R.
98/// When sinking, passing \p Sinking = true ensures that assumes aren't sunk.
99/// Returns true for recipes that access memory.
100bool cannotHoistOrSinkRecipe(const VPRecipeBase &R, bool Sinking = false);
101
102/// Return the intrinsic ID underlying a call.
103template <typename Ty> Intrinsic::ID getIntrinsicID(const Ty *R) {
104 if (const auto *Intr = dyn_cast<VPWidenIntrinsicRecipe>(R))
105 return Intr->getVectorIntrinsicID();
106 if (const auto *Call = dyn_cast<VPWidenCallRecipe>(R))
107 return Call->getCalledScalarFunction()->getIntrinsicID();
108
109 auto GetCalleeIntrinsic = [&](VPValue *CalleeOp) -> Intrinsic::ID {
110 if (!isa<VPIRValue>(CalleeOp))
112 auto *F = cast<Function>(CalleeOp->getLiveInIRValue());
113 return F->getIntrinsicID();
114 };
115 if (const auto *Rep = dyn_cast<VPReplicateRecipe>(R))
116 if (Rep->getOpcode() == Instruction::Call)
117 // The callee is the last operand, excluding the mask if predicated.
118 return GetCalleeIntrinsic(
119 Rep->getOperand(Rep->getNumOperandsWithoutMask() - 1));
120 if (const auto *VPI = dyn_cast<VPInstruction>(R)) {
121 if (VPI->getOpcode() == Instruction::Call)
122 // The callee is the last operand, excluding the mask if masked.
123 return GetCalleeIntrinsic(
124 VPI->getOperand(VPI->getNumOperandsWithoutMask() - 1));
125 if (VPI->getOpcode() == VPInstruction::Intrinsic) {
126 return cast<VPConstantInt>(VPI->getLastOperand())->getZExtValue();
127 }
128 }
130}
131
132/// Return the instruction opcode for the recipe defining \p V or 0 for
133/// unsupported recipes and VPValues not defined by a recipe.
134unsigned getOpcode(const VPValue *V);
135
136/// Get the instruction opcode or intrinsic ID for the recipe defining \p V.
137/// Returns an optional pair, where the first element indicates whether it is an
138/// intrinsic ID.
139std::optional<std::pair<bool, unsigned>>
141
142/// Return a MemoryLocation for \p R with noalias metadata populated from
143/// \p R, if the recipe is supported and std::nullopt otherwise. The pointer of
144/// the location is conservatively set to nullptr.
145std::optional<MemoryLocation> getMemoryLocation(const VPRecipeBase &R);
146
147/// Extracts and returns NoWrap flags from \p PhiR and fast-math flags from \p
148/// ID.
150 const VPPhi *PhiR);
151
152/// Search \p Start's users for a recipe satisfying \p Pred, looking through
153/// recipes with definitions.
154template <typename RecipeTy, typename PredT>
155inline RecipeTy *findUserRecursively(VPValue *Start, PredT Pred) {
156 SetVector<VPValue *> Worklist;
157 Worklist.insert(Start);
158 for (unsigned I = 0; I != Worklist.size(); ++I) {
159 VPValue *Cur = Worklist[I];
160 auto *R = Cur->getDefiningRecipe();
161 if (!R)
162 continue;
163 if (Pred(R))
164 return cast<RecipeTy>(R);
165 for (VPUser *U : Cur->users()) {
166 for (VPValue *V : cast<VPRecipeBase>(U)->definedValues())
167 Worklist.insert(V);
168 }
169 }
170 return nullptr;
171}
172
173/// Find the canonical IV increment of \p Plan's vector loop region. Returns
174/// nullptr if not found.
176
177/// Returns the GEP nowrap flags for \p Ptr, looking through pointer casts
178/// mirroring Value::stripPointerCasts.
180
181/// Returns true if \p V is used as part of the address of another load or
182/// store.
184
185/// Find the ComputeReductionResult recipe for \p PhiR, looking through selects
186/// inserted for predicated reductions or tail folding.
188
189/// Finds the incoming alias-mask within the vector preheader.
191
192/// Returns the (early exiting block, exit block) pairs of \p Plan, i.e. all
193/// edges to an exit block that do not come from \p MiddleVPBB.
195getEarlyExits(const VPlan &Plan, const VPBlockBase *MiddleVPBB);
196
197/// Create a scalar-iv-steps recipe over \p Plan's canonical IV for an
198/// induction of \p Kind with \p InductionOpcode / \p FPBinOp, start value \p
199/// StartV and step \p Step, truncated to \p ResultTy, inserting recipes via \p
200/// Builder.
203 Instruction::BinaryOps InductionOpcode,
204 FPMathOperator *FPBinOp, Type *ResultTy, VPValue *StartV,
205 VPValue *Step, DebugLoc DL, VPBuilder &Builder,
206 const VPIRFlags::WrapFlagsTy &Flags = {});
207
208/// Scalarize a VPWidenPointerInductionRecipe by replacing it with a PtrAdd
209/// (IndStart, ScalarIVSteps (0, Step)). This is used when the recipe only
210/// generates scalar values.
211VPValue *scalarizeVPWidenPointerInduction(VPWidenPointerInductionRecipe *PtrIV,
212 VPlan &Plan, VPBuilder &Builder);
213
214/// Returns true if \p R is dead, i.e. none of its defined values are used and
215/// it has no side effects (with the exception of conditional assumes, which are
216/// considered dead as their conditions may be flattened).
217bool isDeadRecipe(VPRecipeBase &R);
218
219/// Recursively delete \p V and any of its operands that become dead.
220void recursivelyDeleteDeadRecipes(VPValue *V);
221
222/// Collect all users of \p V, looking through recipes that define other values.
224
225/// Try to fold \p R using InstSimplifyFolder. Will succeed and return a
226/// non-nullptr VPValue for a handled opcode or intrinsic ID if corresponding \p
227/// Operands are foldable live-ins.
228VPIRValue *tryToFoldLiveIns(VPSingleDefRecipe &R, ArrayRef<VPValue *> Operands,
229 const DataLayout &DL);
230
231/// Insert phis to reconstruct SSA for a single value starting from \p VPBB. \p
232/// Defs is a map of definitions at specific blocks. Returns the
233/// reconstructed value at VPBB. Use if the CFG has been modified such that a
234/// def no longer dominates all its uses. Every block leading to VPBB must be
235/// reachable from the entry and the plan must be plain-CFG (not contain any
236/// regions).
237LLVM_ABI_FOR_TEST VPValue *
238reconstructSSA(VPBasicBlock *VPBB, DenseMap<VPBasicBlock *, VPValue *> &Defs);
239
240/// Returns \p Freq as a BranchProbability, relative to the full mass.
241BranchProbability getExecutionProbability(BlockFrequency Freq);
242
243/// Computes for each block in \p Blocks, which must be in reverse post-order,
244/// the frequency with which it executes relative to the first (header) block,
245/// and whether that frequency was composed using any estimated branch weights.
246/// The frequency of a block is the sum over its incoming edges, or std::nullopt
247/// if any edge on a path reaching it lacks branch weights. Edges to blocks
248/// outside \p Blocks are ignored.
249DenseMap<const VPBasicBlock *, std::optional<VPExecutionFrequency>>
251
252/// Get the value type of a VPInstruction or VPReplicateRecipe load or store.
254 bool IsLoad = vputils::getOpcode(R) == Instruction::Load;
255 return (IsLoad ? R : R->getOperand(0))->getScalarType();
256}
257
258namespace detail {
259
260/// Template-independent implementation for pullOutPermutations.
262 VPlan &Plan, function_ref<VPValue *(VPValue *Op)> Perm,
264} // namespace detail
265
266/// Removes the permutation pattern \p Perm from any elementwise operations
267/// in the plan, by constructing a new permutation via \p Build.
268/// e.g. binop(perm(x), perm(y)) -> perm(binop(x,y)).
269template <typename Match_t, typename Builder>
270void pullOutPermutations(VPlan &Plan, Match_t Perm, Builder Build) {
271 // Convert matcher to function returing the matched VPValue.
272 auto MatchPerm = [&Perm](VPValue *Op) -> VPValue * {
273 VPValue *X;
274 return match(Op, Perm(X)) ? X : nullptr;
275 };
276 detail::pullOutPermutationsImpl(Plan, MatchPerm, Build);
277}
278
279} // namespace vputils
280
281/// Lightweight SCEV-to-VPlan expander. Converts SCEV expressions into
282/// VPInstructions and live-ins. Canonical IVs and non-affine SCEVAddRecExprs
283/// are wrapped in a VPExpandSCEVRecipe to be expanded to IR later. Expansions
284/// are reused across calls to expand(), so the builder's insert point must
285/// only move to positions dominated by all earlier insert points.
287 VPBuilder &Builder;
288 ScalarEvolution &SE;
289 DebugLoc DL;
290
291 /// When true, nested SCEVUDivExprs are expanded so that they cannot divide by
292 /// zero, matching SCEVExpander's SafeUDivMode.
293 bool SafeUDivMode = false;
294
295 /// If set, expressions invariant in this loop are expanded in IR via
296 /// VPExpandSCEVRecipes, which hoists them out of it.
297 const Loop *HoistOutOf;
298
300 InsertedExpressions;
301
302 /// Try to find a loop-invariant IR value in the plan's entry block whose
303 /// SCEV matches \p S. Returns the corresponding live-in VPValue, an in-IR
304 /// VPExpandSCEVRecipe if reuse requires dropping flags, or nullptr if none
305 /// is found.
306 VPValue *tryToReuseIRValue(const SCEV *S);
307
308 /// Returns true if \p S can be expanded in IR, hoisted out of HoistOutOf.
309 bool canExpandInIR(const SCEV *S);
310
311 /// Expand the sum of \p Operands, with \p WrapFlags on the adds.
313 VPIRFlags::WrapFlagsTy WrapFlags);
314
315 /// Expand pointer-typed \p S as a ptradd of its pointer base and offset.
316 VPValue *expandAsPtrAdd(const SCEVNAryExpr *S);
317
318 VPValue *expandImpl(const SCEV *S);
319
320public:
322 const Loop *HoistOutOf = nullptr, bool SafeUDivMode = false)
323 : Builder(Builder), SE(SE), DL(DL), SafeUDivMode(SafeUDivMode),
324 HoistOutOf(HoistOutOf) {}
325
326 /// Expand \p S into recipes and live-ins using the builder.
327 VPValue *expand(const SCEV *S);
328
329 /// Expand the expression of \p R, or return \p R if it must be expanded in
330 /// IR.
332 return R.expandInIR() ? &R : expand(R.getSCEV());
333 }
334};
335//===----------------------------------------------------------------------===//
336// Utilities for modifying predecessors and successors of VPlan blocks.
337//===----------------------------------------------------------------------===//
338
339/// Class that provides utilities for VPBlockBases in VPlan.
341public:
342 VPBlockUtils() = delete;
343
344 /// Insert disconnected VPBlockBase \p NewBlock after \p BlockPtr. Add \p
345 /// NewBlock as successor of \p BlockPtr and \p BlockPtr as predecessor of \p
346 /// NewBlock, and propagate \p BlockPtr parent to \p NewBlock. \p BlockPtr's
347 /// successors are moved from \p BlockPtr to \p NewBlock. \p NewBlock must
348 /// have neither successors nor predecessors.
349 static void insertBlockAfter(VPBlockBase *NewBlock, VPBlockBase *BlockPtr) {
350 assert(!NewBlock->hasSuccessors() && !NewBlock->hasPredecessors() &&
351 "Can't insert new block with predecessors or successors.");
352 NewBlock->setParent(BlockPtr->getParent());
353 transferSuccessors(BlockPtr, NewBlock);
354 connectBlocks(BlockPtr, NewBlock);
355 }
356
357 /// Insert disconnected block \p NewBlock before \p Blockptr. First
358 /// disconnects all predecessors of \p BlockPtr and connects them to \p
359 /// NewBlock. Add \p NewBlock as predecessor of \p BlockPtr and \p BlockPtr as
360 /// successor of \p NewBlock.
361 static void insertBlockBefore(VPBlockBase *NewBlock, VPBlockBase *BlockPtr) {
362 assert(!NewBlock->hasSuccessors() && !NewBlock->hasPredecessors() &&
363 "Can't insert new block with predecessors or successors.");
364 NewBlock->setParent(BlockPtr->getParent());
365 for (VPBlockBase *Pred : to_vector(BlockPtr->predecessors()))
366 replaceSuccessor(Pred, BlockPtr, NewBlock);
367 connectBlocks(NewBlock, BlockPtr);
368 }
369
370 /// Insert disconnected VPBlockBases \p IfTrue and \p IfFalse after \p
371 /// BlockPtr. Add \p IfTrue and \p IfFalse as succesors of \p BlockPtr and \p
372 /// BlockPtr as predecessor of \p IfTrue and \p IfFalse. Propagate \p BlockPtr
373 /// parent to \p IfTrue and \p IfFalse. \p BlockPtr must have no successors
374 /// and \p IfTrue and \p IfFalse must have neither successors nor
375 /// predecessors.
376 static void insertTwoBlocksAfter(VPBlockBase *IfTrue, VPBlockBase *IfFalse,
377 VPBlockBase *BlockPtr) {
378 assert(!IfTrue->hasSuccessors() && "Can't insert IfTrue with successors.");
379 assert(!IfFalse->hasSuccessors() &&
380 "Can't insert IfFalse with successors.");
381 BlockPtr->setTwoSuccessors(IfTrue, IfFalse);
382 IfTrue->setPredecessors({BlockPtr});
383 IfFalse->setPredecessors({BlockPtr});
384 IfTrue->setParent(BlockPtr->getParent());
385 IfFalse->setParent(BlockPtr->getParent());
386 }
387
388 /// Connect VPBlockBases \p From and \p To bi-directionally. If \p PredIdx is
389 /// -1, append \p From to the predecessors of \p To, otherwise set \p To's
390 /// predecessor at \p PredIdx to \p From. If \p SuccIdx is -1, append \p To to
391 /// the successors of \p From, otherwise set \p From's successor at \p SuccIdx
392 /// to \p To. Both VPBlockBases must have the same parent, which can be null.
393 /// Both VPBlockBases can be already connected to other VPBlockBases.
394 static void connectBlocks(VPBlockBase *From, VPBlockBase *To,
395 unsigned PredIdx = -1u, unsigned SuccIdx = -1u) {
396 assert((From->getParent() == To->getParent()) &&
397 "Can't connect two block with different parents");
398
399 if (SuccIdx == -1u)
400 From->appendSuccessor(To);
401 else
402 From->getSuccessors()[SuccIdx] = To;
403
404 if (PredIdx == -1u)
405 To->appendPredecessor(From);
406 else
407 To->getPredecessors()[PredIdx] = From;
408 }
409
410 /// Disconnect VPBlockBases \p From and \p To bi-directionally. Remove \p To
411 /// from the successors of \p From and \p From from the predecessors of \p To.
412 static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To) {
413 assert(To && "Successor to disconnect is null.");
414 From->removeSuccessor(To);
415 To->removePredecessor(From);
416 }
417
418 /// Redirect the edge from \p From to \p OldSucc to \p NewSucc, keeping \p
419 /// From's successor order. \p From is removed from \p OldSucc's predecessors
420 /// and appended to \p NewSucc's.
421 static void replaceSuccessor(VPBlockBase *From, VPBlockBase *OldSucc,
422 VPBlockBase *NewSucc) {
423 From->replaceSuccessor(OldSucc, NewSucc);
424 OldSucc->removePredecessor(From);
425 NewSucc->appendPredecessor(From);
426 }
427
428 /// Reassociate all the blocks connected to \p Old so that they now point to
429 /// \p New.
430 static void reassociateBlocks(VPBlockBase *Old, VPBlockBase *New) {
431 auto Preds = to_vector(Old->getPredecessors());
432 auto Succs = to_vector(Old->getSuccessors());
433 for (auto *Pred : Preds)
434 Pred->replaceSuccessor(Old, New);
435 for (auto *Succ : Succs)
436 Succ->replacePredecessor(Old, New);
437 New->setPredecessors(Old->getPredecessors());
438 New->setSuccessors(Old->getSuccessors());
439 Old->clearPredecessors();
440 Old->clearSuccessors();
441 }
442
443 /// Transfer successors from \p Old to \p New. \p New must have no successors.
445 for (auto *Succ : Old->getSuccessors())
446 Succ->replacePredecessor(Old, New);
447 New->setSuccessors(Old->getSuccessors());
448 Old->clearSuccessors();
449 }
450
451 /// Clone the CFG for all nodes reachable from \p Entry, including cloning
452 /// the blocks and their recipes. Operands of cloned recipes will NOT be
453 /// updated. Remapping of operands must be done separately. Returns a pair
454 /// with the new entry and exiting blocks of the cloned region. If \p Entry
455 /// isn't part of a region, return nullptr for the exiting block.
456 static std::pair<VPBlockBase *, VPBlockBase *> cloneFrom(VPBlockBase *Entry);
457
458 /// Return an iterator range over \p Range which only includes \p BlockTy
459 /// blocks. The accesses are casted to \p BlockTy.
460 template <typename BlockTy, typename T> static auto blocksOnly(T &&Range) {
461 return make_isa_range<BlockTy>(std::forward<T>(Range));
462 }
463
464 /// Return an iterator range over \p Range with each block cast to \p
465 /// BlockTy. Unlike blocksOnly, all blocks in \p Range must be of type
466 /// \p BlockTy.
467 template <typename BlockTy, typename T> static auto blocksAs(T &&Range) {
469 }
470
471 /// Returns the blocks between \p FirstBB and \p LastBB, where FirstBB
472 /// to LastBB forms a single-sucessor chain.
475 VPBasicBlock *LastBB);
476
477 /// Inserts \p BlockPtr on the edge between \p From and \p To. That is, update
478 /// \p From's successor to \p To to point to \p BlockPtr and \p To's
479 /// predecessor from \p From to \p BlockPtr. \p From and \p To are added to \p
480 /// BlockPtr's predecessors and successors respectively. There must be a
481 /// single edge between \p From and \p To.
482 static void insertOnEdge(VPBlockBase *From, VPBlockBase *To,
483 VPBlockBase *BlockPtr) {
484 unsigned SuccIdx = From->getIndexForSuccessor(To);
485 unsigned PredIx = To->getIndexForPredecessor(From);
486 VPBlockUtils::connectBlocks(From, BlockPtr, -1, SuccIdx);
487 VPBlockUtils::connectBlocks(BlockPtr, To, PredIx, -1);
488 }
489
490 /// Returns true if \p VPB is a loop header, based on regions or \p VPDT in
491 /// their absence.
492 static bool isHeader(const VPBlockBase *VPB, const VPDominatorTree &VPDT);
493
494 /// Returns true if \p VPB is a loop latch, using isHeader().
495 static bool isLatch(const VPBlockBase *VPB, const VPDominatorTree &VPDT);
496
497 /// Returns the header and latch of the outermost loop of \p Plan in plain
498 /// CFG form (before regions are formed).
499 static std::pair<VPBasicBlock *, VPBasicBlock *>
500 getPlainCFGHeaderAndLatch(const VPlan &Plan);
501
502 /// Returns the middle block of \p Plan in plain CFG form (before regions
503 /// are formed).
504 static VPBasicBlock *getPlainCFGMiddleBlock(const VPlan &Plan);
505};
506
507} // namespace llvm
508
509#endif
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:216
#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))
SI Fold Operands
This file contains the declarations of the Vectorization Plan base classes:
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A debug info location.
Definition DebugLoc.h:126
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.
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 node is a base class providing common functionality for n'ary operators.
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:157
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition VPlan.h:4509
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition VPlan.h:79
VPRegionBlock * getParent()
Definition VPlan.h:177
iterator_range< VPBlockBase ** > predecessors()
Definition VPlan.h:210
bool hasPredecessors() const
Returns true if this block has any predecessors.
Definition VPlan.h:207
unsigned getIndexForSuccessor(const VPBlockBase *Succ) const
Returns the index for Succ in the blocks successor list.
Definition VPlan.h:324
void setPredecessors(ArrayRef< VPBlockBase * > NewPreds)
Set each VPBasicBlock in NewPreds as predecessor of this VPBlockBase.
Definition VPlan.h:280
unsigned getIndexForPredecessor(const VPBlockBase *Pred) const
Returns the index for Pred in the blocks predecessors list.
Definition VPlan.h:317
bool hasSuccessors() const
Returns true if this block has any successors.
Definition VPlan.h:205
const VPBlocksTy & getPredecessors() const
Definition VPlan.h:212
void clearSuccessors()
Remove all the successors of this block.
Definition VPlan.h:299
void setTwoSuccessors(VPBlockBase *IfTrue, VPBlockBase *IfFalse)
Set two given VPBlockBases IfTrue and IfFalse to be the two successors of this VPBlockBase.
Definition VPlan.h:271
void clearPredecessors()
Remove all the predecessor of this block.
Definition VPlan.h:296
void setParent(VPRegionBlock *P)
Definition VPlan.h:187
const VPBlocksTy & getSuccessors() const
Definition VPlan.h:201
static auto blocksAs(T &&Range)
Return an iterator range over Range with each block cast to BlockTy.
Definition VPlanUtils.h:467
static void insertBlockAfter(VPBlockBase *NewBlock, VPBlockBase *BlockPtr)
Insert disconnected VPBlockBase NewBlock after BlockPtr.
Definition VPlanUtils.h:349
static void insertOnEdge(VPBlockBase *From, VPBlockBase *To, VPBlockBase *BlockPtr)
Inserts BlockPtr on the edge between From and To.
Definition VPlanUtils.h:482
static void replaceSuccessor(VPBlockBase *From, VPBlockBase *OldSucc, VPBlockBase *NewSucc)
Redirect the edge from From to OldSucc to NewSucc, keeping From's successor order.
Definition VPlanUtils.h:421
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:376
static void connectBlocks(VPBlockBase *From, VPBlockBase *To, unsigned PredIdx=-1u, unsigned SuccIdx=-1u)
Connect VPBlockBases From and To bi-directionally.
Definition VPlanUtils.h:394
static void disconnectBlocks(VPBlockBase *From, VPBlockBase *To)
Disconnect VPBlockBases From and To bi-directionally.
Definition VPlanUtils.h:412
static void reassociateBlocks(VPBlockBase *Old, VPBlockBase *New)
Reassociate all the blocks connected to Old so that they now point to New.
Definition VPlanUtils.h:430
static void insertBlockBefore(VPBlockBase *NewBlock, VPBlockBase *BlockPtr)
Insert disconnected block NewBlock before Blockptr.
Definition VPlanUtils.h:361
static auto blocksOnly(T &&Range)
Return an iterator range over Range which only includes BlockTy blocks.
Definition VPlanUtils.h:460
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:444
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:652
Template specialization of the standard LLVM dominator tree utility for VPBlockBases.
Recipe to expand a SCEV expression.
Definition VPlan.h:4104
Class to record and manage LLVM IR flags.
Definition VPlan.h:667
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1310
@ Intrinsic
Calls a scalar intrinsic. The intrinsic ID is the last operand.
Definition VPlan.h:1436
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:386
A recipe for handling reduction phis.
Definition VPlan.h:2864
VPSCEVExpander(VPBuilder &Builder, ScalarEvolution &SE, DebugLoc DL, const Loop *HoistOutOf=nullptr, bool SafeUDivMode=false)
Definition VPlanUtils.h:321
VPValue * expand(VPExpandSCEVRecipe &R)
Expand the expression of R, or return R if it must be expanded in IR.
Definition VPlanUtils.h:331
VPValue * expand(const SCEV *S)
Expand S into recipes and live-ins using the builder.
A recipe for handling phi nodes of integer and floating-point inductions, producing their scalar valu...
Definition VPlan.h:4341
VPSingleDefRecipe is a base class for recipes that model a sequence of one or more output IR that def...
Definition VPlan.h:589
This class augments VPValue with operands which provide the inverse def-use edges from VPValue's user...
Definition VPlanValue.h:396
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:120
user_range users()
Definition VPlanValue.h:157
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4927
An efficient, type-erasing, non-owning reference to a callable.
CallInst * Call
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.
BranchProbability getExecutionProbability(BlockFrequency Freq)
Returns Freq as a BranchProbability, relative to the full mass.
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...
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...
std::optional< int64_t > getConstantStride(VPValue *Addr, Type *AccessTy, PredicatedScalarEvolution &PSE, const Loop *L)
If the pointer operand Addr of a memory access is an affine AddRec w.r.t.
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,...
LLVM_ABI_FOR_TEST VPValue * reconstructSSA(VPBasicBlock *VPBB, DenseMap< VPBasicBlock *, VPValue * > &Defs)
Insert phis to reconstruct SSA for a single value starting from VPBB.
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used by all users.
Intrinsic::ID getIntrinsicID(const Ty *R)
Return the intrinsic ID underlying a call.
Definition VPlanUtils.h:103
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 by all users.
VPIRValue * tryToFoldLiveIns(VPSingleDefRecipe &R, ArrayRef< VPValue * > Operands, const DataLayout &DL)
Try to fold R using InstSimplifyFolder.
SmallVector< std::pair< VPBasicBlock *, VPIRBasicBlock * > > getEarlyExits(const VPlan &Plan, const VPBlockBase *MiddleVPBB)
Returns the (early exiting block, exit block) pairs of Plan, i.e.
VPValue * findIncomingAliasMask(const VPlan &Plan)
Finds the incoming alias-mask within the vector preheader.
DenseMap< const VPBasicBlock *, std::optional< VPExecutionFrequency > > computeExecutionFrequencies(ArrayRef< VPBasicBlock * > Blocks)
Computes for each block in Blocks, which must be in reverse post-order, the frequency with which it e...
VPScalarIVStepsRecipe * createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind, Instruction::BinaryOps InductionOpcode, FPMathOperator *FPBinOp, Type *ResultTy, VPValue *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...
bool propagatesFirstLaneUse(const VPUser *U, const VPValue *Op)
Returns true if checking whether U uses the first lane of Op requires recursively checking Op's users...
RecipeTy * findUserRecursively(VPValue *Start, PredT Pred)
Search Start's users for a recipe satisfying Pred, looking through recipes with definitions.
Definition VPlanUtils.h:155
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.
VPIRFlags getFlagsForInduction(const InductionDescriptor &ID, const VPPhi *PhiR)
Extracts and returns NoWrap flags from PhiR and fast-math flags from ID.
Type * getLoadStoreValueType(const VPSingleDefRecipe *R)
Get the value type of a VPInstruction or VPReplicateRecipe load or store.
Definition VPlanUtils.h:253
bool isDeadRecipe(VPRecipeBase &R)
Returns true if R is dead, i.e.
bool isElementwise(const VPValue *V)
Return true if V is elementwise, i.e. none of the lanes are permuted.
bool onlyScalarValuesOrLanesUsed(const VPValue *Def)
Returns true if only scalar values of Def are used by all users, either directly or by extracting a c...
bool onlyScalarValuesUsed(const VPValue *Def)
Returns true if only scalar values of Def are used by all users.
LLVM_ABI_FOR_TEST bool isUniformAcrossVFsAndUFs(const VPValue *V)
Checks if V is uniform across all VF lanes and UF parts.
VPValue * getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr, bool ExpandInIR=false)
Get or create a VPValue that corresponds to the expansion of Expr.
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...
LLVM_ABI_FOR_TEST 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:270
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.
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
VPBuilderBase<> VPBuilder
Definition VPlan.h:65
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
Definition STLExtras.h:366
auto make_isa_range(RangeT &&Range)
Return a range over Range containing only elements for which isa<T> holds, casting each of them to T.
Definition STLExtras.h:567
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...
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
constexpr detail::CastFunc< To > CastTo
Definition Casting.h:884