
This patch implements explicit unrolling by UF as VPlan transform. In follow up patches this will allow simplifying VPTransform state (no need to store unrolled parts) as well as recipe execution (no need to generate code for multiple parts in an each recipe). It also allows for more general optimziations (e.g. avoid generating code for recipes that are uniform-across parts). It also unifies the logic dealing with unrolled parts in a single place, rather than spreading it out across multiple places (e.g. VPlan post processing for header-phi recipes previously.) In the initial implementation, a number of recipes still take the unrolled part as additional, optional argument, if their execution depends on the unrolled part. The computation for start/step values for scalable inductions changed slightly. Previously the step would be computed as scalar and then splatted, now vscale gets splatted and multiplied by the step in a vector mul. This has been split off https://github.com/llvm/llvm-project/pull/94339 which also includes changes to simplify VPTransfomState and recipes' ::execute. The current version mostly leaves existing ::execute untouched and instead sets VPTransfomState::UF to 1. A follow-up patch will clean up all references to VPTransformState::UF. Another follow-up patch will simplify VPTransformState to only store a single vector value per VPValue. PR: https://github.com/llvm/llvm-project/pull/95842
67 lines
2.6 KiB
C++
67 lines
2.6 KiB
C++
//===- VPlanUtils.h - VPlan-related utilities -------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H
|
|
#define LLVM_TRANSFORMS_VECTORIZE_VPLANUTILS_H
|
|
|
|
#include "VPlan.h"
|
|
|
|
namespace llvm {
|
|
class ScalarEvolution;
|
|
class SCEV;
|
|
} // namespace llvm
|
|
|
|
namespace llvm::vputils {
|
|
/// Returns true if only the first lane of \p Def is used.
|
|
bool onlyFirstLaneUsed(const VPValue *Def);
|
|
|
|
/// Returns true if only the first part of \p Def is used.
|
|
bool onlyFirstPartUsed(const VPValue *Def);
|
|
|
|
/// Get or create a VPValue that corresponds to the expansion of \p Expr. If \p
|
|
/// Expr is a SCEVConstant or SCEVUnknown, return a VPValue wrapping the live-in
|
|
/// value. Otherwise return a VPExpandSCEVRecipe to expand \p Expr. If \p Plan's
|
|
/// pre-header already contains a recipe expanding \p Expr, return it. If not,
|
|
/// create a new one.
|
|
VPValue *getOrCreateVPValueForSCEVExpr(VPlan &Plan, const SCEV *Expr,
|
|
ScalarEvolution &SE);
|
|
|
|
/// Return the SCEV expression for \p V. Returns SCEVCouldNotCompute if no
|
|
/// SCEV expression could be constructed.
|
|
const SCEV *getSCEVExprForVPValue(VPValue *V, ScalarEvolution &SE);
|
|
|
|
/// Returns true if \p VPV is uniform after vectorization.
|
|
inline bool isUniformAfterVectorization(const VPValue *VPV) {
|
|
// A value defined outside the vector region must be uniform after
|
|
// vectorization inside a vector region.
|
|
if (VPV->isDefinedOutsideLoopRegions())
|
|
return true;
|
|
const VPRecipeBase *Def = VPV->getDefiningRecipe();
|
|
assert(Def && "Must have definition for value defined inside vector region");
|
|
if (auto *Rep = dyn_cast<VPReplicateRecipe>(Def))
|
|
return Rep->isUniform();
|
|
if (auto *GEP = dyn_cast<VPWidenGEPRecipe>(Def))
|
|
return all_of(GEP->operands(), isUniformAfterVectorization);
|
|
if (auto *VPI = dyn_cast<VPInstruction>(Def))
|
|
return VPI->isSingleScalar() || VPI->isVectorToScalar();
|
|
return false;
|
|
}
|
|
|
|
/// Return true if \p V is a header mask in \p Plan.
|
|
bool isHeaderMask(const VPValue *V, VPlan &Plan);
|
|
|
|
/// Checks if \p V is uniform across all VF lanes and UF parts. It is considered
|
|
/// as such if it is either loop invariant (defined outside the vector region)
|
|
/// or its operand is known to be uniform across all VFs and UFs (e.g.
|
|
/// VPDerivedIV or VPCanonicalIVPHI).
|
|
bool isUniformAcrossVFsAndUFs(VPValue *V);
|
|
|
|
} // end namespace llvm::vputils
|
|
|
|
#endif
|