1 //===- VPlanUtils.h - VPlan-related utilities -------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H
10 #define LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H
15 class ScalarEvolution
;
19 namespace llvm::vputils
{
20 /// Returns true if only the first lane of \p Def is used.
21 bool onlyFirstLaneUsed(const VPValue
*Def
);
23 /// Returns true if only the first part of \p Def is used.
24 bool onlyFirstPartUsed(const VPValue
*Def
);
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,
31 VPValue
*getOrCreateVPValueForSCEVExpr(VPlan
&Plan
, const SCEV
*Expr
,
34 /// Return the SCEV expression for \p V. Returns SCEVCouldNotCompute if no
35 /// SCEV expression could be constructed.
36 const SCEV
*getSCEVExprForVPValue(VPValue
*V
, ScalarEvolution
&SE
);
38 /// Returns true if \p VPV is uniform after vectorization.
39 inline bool isUniformAfterVectorization(const VPValue
*VPV
) {
40 // A value defined outside the vector region must be uniform after
41 // vectorization inside a vector region.
42 if (VPV
->isDefinedOutsideLoopRegions())
44 const VPRecipeBase
*Def
= VPV
->getDefiningRecipe();
45 assert(Def
&& "Must have definition for value defined inside vector region");
46 if (auto *Rep
= dyn_cast
<VPReplicateRecipe
>(Def
))
47 return Rep
->isUniform();
48 if (auto *GEP
= dyn_cast
<VPWidenGEPRecipe
>(Def
))
49 return all_of(GEP
->operands(), isUniformAfterVectorization
);
50 if (auto *VPI
= dyn_cast
<VPInstruction
>(Def
))
51 return VPI
->isSingleScalar() || VPI
->isVectorToScalar();
55 /// Return true if \p V is a header mask in \p Plan.
56 bool isHeaderMask(const VPValue
*V
, VPlan
&Plan
);
58 /// Checks if \p V is uniform across all VF lanes and UF parts. It is considered
59 /// as such if it is either loop invariant (defined outside the vector region)
60 /// or its operand is known to be uniform across all VFs and UFs (e.g.
61 /// VPDerivedIV or VPCanonicalIVPHI).
62 bool isUniformAcrossVFsAndUFs(VPValue
*V
);
64 } // end namespace llvm::vputils