LLVM 20.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"
13
14namespace llvm {
15class ScalarEvolution;
16class SCEV;
17} // namespace llvm
18
19namespace llvm::vputils {
20/// Returns true if only the first lane of \p Def is used.
21bool onlyFirstLaneUsed(const VPValue *Def);
22
23/// Returns true if only the first part of \p Def is used.
24bool onlyFirstPartUsed(const VPValue *Def);
25
26/// Get or create a VPValue that corresponds to the expansion of \p Expr. If \p
27/// Expr is a SCEVConstant or SCEVUnknown, return a VPValue wrapping the live-in
28/// value. Otherwise return a VPExpandSCEVRecipe to expand \p Expr. If \p Plan's
29/// pre-header already contains a recipe expanding \p Expr, return it. If not,
30/// create a new one.
32 ScalarEvolution &SE);
33
34/// Return the SCEV expression for \p V. Returns SCEVCouldNotCompute if no
35/// SCEV expression could be constructed.
37
38/// Returns true if \p VPV is uniform after vectorization.
39inline bool isUniformAfterVectorization(const VPValue *VPV) {
40 // A value defined outside the vector region must be uniform after
41 // vectorization inside a vector region.
43 return true;
44 if (auto *Rep = dyn_cast<VPReplicateRecipe>(VPV))
45 return Rep->isUniform();
46 if (isa<VPWidenGEPRecipe, VPDerivedIVRecipe>(VPV))
47 return all_of(VPV->getDefiningRecipe()->operands(),
49 if (auto *VPI = dyn_cast<VPInstruction>(VPV))
50 return VPI->isSingleScalar() || VPI->isVectorToScalar() ||
51 ((Instruction::isBinaryOp(VPI->getOpcode()) ||
52 VPI->getOpcode() == VPInstruction::PtrAdd) &&
53 all_of(VPI->operands(), isUniformAfterVectorization));
54 if (auto *IV = dyn_cast<VPDerivedIVRecipe>(VPV))
55 return all_of(IV->operands(), isUniformAfterVectorization);
56
57 // VPExpandSCEVRecipes must be placed in the entry and are alway uniform.
58 return isa<VPExpandSCEVRecipe>(VPV);
59}
60
61/// Return true if \p V is a header mask in \p Plan.
62bool isHeaderMask(const VPValue *V, VPlan &Plan);
63
64/// Checks if \p V is uniform across all VF lanes and UF parts. It is considered
65/// as such if it is either loop invariant (defined outside the vector region)
66/// or its operand is known to be uniform across all VFs and UFs (e.g.
67/// VPDerivedIV or VPCanonicalIVPHI).
69
70} // end namespace llvm::vputils
71
72#endif
This file contains the declarations of the Vectorization Plan base classes:
static const uint32_t IV[8]
Definition: blake3_impl.h:78
bool isBinaryOp() const
Definition: Instruction.h:279
This class represents an analyzed expression in the program.
The main scalar evolution driver.
operand_range operands()
Definition: VPlanValue.h:263
bool isDefinedOutsideLoopRegions() const
Returns true if the VPValue is defined outside any loop region.
Definition: VPlan.cpp:1417
VPRecipeBase * getDefiningRecipe()
Returns the recipe defining this VPValue or nullptr if it is not defined by a recipe,...
Definition: VPlan.cpp:123
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:3812
bool isUniformAfterVectorization(const VPValue *VPV)
Returns true if VPV is uniform after vectorization.
Definition: VPlanUtils.h:39
VPValue * getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr, ScalarEvolution &SE)
Get or create a VPValue that corresponds to the expansion of Expr.
Definition: VPlanUtils.cpp:26
bool isUniformAcrossVFsAndUFs(VPValue *V)
Checks if V is uniform across all VF lanes and UF parts.
Definition: VPlanUtils.cpp:76
bool onlyFirstPartUsed(const VPValue *Def)
Returns true if only the first part of Def is used.
Definition: VPlanUtils.cpp:21
const SCEV * getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE)
Return the SCEV expression for V.
Definition: VPlanUtils.cpp:65
bool onlyFirstLaneUsed(const VPValue *Def)
Returns true if only the first lane of Def is used.
Definition: VPlanUtils.cpp:16
bool isHeaderMask(const VPValue *V, VPlan &Plan)
Return true if V is a header mask in Plan.
Definition: VPlanUtils.cpp:43
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1739