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