102 lines · c
1//===- VPlanAnalysis.h - Various Analyses working on VPlan ------*- 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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H10#define LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H11 12#include "llvm/ADT/DenseMap.h"13#include "llvm/ADT/DenseSet.h"14#include "llvm/ADT/MapVector.h"15#include "llvm/IR/Type.h"16 17namespace llvm {18 19class LLVMContext;20class VPValue;21class VPBlendRecipe;22class VPInstruction;23class VPWidenRecipe;24class VPWidenCallRecipe;25class VPWidenIntOrFpInductionRecipe;26class VPWidenMemoryRecipe;27struct VPWidenSelectRecipe;28class VPReplicateRecipe;29class VPRecipeBase;30class VPlan;31class Value;32class TargetTransformInfo;33class Type;34 35/// An analysis for type-inference for VPValues.36/// It infers the scalar type for a given VPValue by bottom-up traversing37/// through defining recipes until root nodes with known types are reached (e.g.38/// live-ins or load recipes). The types are then propagated top down through39/// operations.40/// Note that the analysis caches the inferred types. A new analysis object must41/// be constructed once a VPlan has been modified in a way that invalidates any42/// of the previously inferred types.43class VPTypeAnalysis {44 DenseMap<const VPValue *, Type *> CachedTypes;45 /// Type of the canonical induction variable. Used for all VPValues without46 /// any underlying IR value (like the vector trip count or the backedge-taken47 /// count).48 Type *CanonicalIVTy;49 LLVMContext &Ctx;50 51 Type *inferScalarTypeForRecipe(const VPBlendRecipe *R);52 Type *inferScalarTypeForRecipe(const VPInstruction *R);53 Type *inferScalarTypeForRecipe(const VPWidenCallRecipe *R);54 Type *inferScalarTypeForRecipe(const VPWidenRecipe *R);55 Type *inferScalarTypeForRecipe(const VPWidenIntOrFpInductionRecipe *R);56 Type *inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R);57 Type *inferScalarTypeForRecipe(const VPWidenSelectRecipe *R);58 Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R);59 60public:61 VPTypeAnalysis(const VPlan &Plan);62 63 /// Infer the type of \p V. Returns the scalar type of \p V.64 Type *inferScalarType(const VPValue *V);65 66 /// Return the LLVMContext used by the analysis.67 LLVMContext &getContext() { return Ctx; }68};69 70// Collect a VPlan's ephemeral recipes (those used only by an assume).71void collectEphemeralRecipesForVPlan(VPlan &Plan,72 DenseSet<VPRecipeBase *> &EphRecipes);73 74/// A struct that represents some properties of the register usage75/// of a loop.76struct VPRegisterUsage {77 /// Holds the number of loop invariant values that are used in the loop.78 /// The key is ClassID of target-provided register class.79 SmallMapVector<unsigned, unsigned, 4> LoopInvariantRegs;80 /// Holds the maximum number of concurrent live intervals in the loop.81 /// The key is ClassID of target-provided register class.82 SmallMapVector<unsigned, unsigned, 4> MaxLocalUsers;83 84 /// Check if any of the tracked live intervals exceeds the number of85 /// available registers for the target. If non-zero, OverrideMaxNumRegs86 /// is used in place of the target's number of registers.87 bool exceedsMaxNumRegs(const TargetTransformInfo &TTI,88 unsigned OverrideMaxNumRegs = 0) const;89};90 91/// Estimate the register usage for \p Plan and vectorization factors in \p VFs92/// by calculating the highest number of values that are live at a single93/// location as a rough estimate. Returns the register usage for each VF in \p94/// VFs.95SmallVector<VPRegisterUsage, 8> calculateRegisterUsageForPlan(96 VPlan &Plan, ArrayRef<ElementCount> VFs, const TargetTransformInfo &TTI,97 const SmallPtrSetImpl<const Value *> &ValuesToIgnore);98 99} // end namespace llvm100 101#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H102