LLVM 23.0.0git
VPlanAnalysis.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
10#define LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/DenseSet.h"
14#include "llvm/ADT/MapVector.h"
16#include "llvm/IR/DataLayout.h"
17#include "llvm/IR/Type.h"
18
19namespace llvm {
20
21class LLVMContext;
22class VPValue;
23class VPBlendRecipe;
24class VPInstruction;
25class VPWidenRecipe;
30class VPRecipeBase;
31class VPlan;
32class Value;
34class Type;
35class InstructionCost;
36
37struct VPCostContext;
38
39/// An analysis for type-inference for VPValues.
40/// It infers the scalar type for a given VPValue by bottom-up traversing
41/// through defining recipes until root nodes with known types are reached (e.g.
42/// live-ins or load recipes). The types are then propagated top down through
43/// operations.
44/// Note that the analysis caches the inferred types. A new analysis object must
45/// be constructed once a VPlan has been modified in a way that invalidates any
46/// of the previously inferred types.
49 /// Type of the canonical induction variable. Used for all VPValues without
50 /// any underlying IR value (like the vector trip count or the backedge-taken
51 /// count).
52 Type *CanonicalIVTy;
53 LLVMContext &Ctx;
54 const DataLayout &DL;
55
56 Type *inferScalarTypeForRecipe(const VPBlendRecipe *R);
57 Type *inferScalarTypeForRecipe(const VPInstruction *R);
58 Type *inferScalarTypeForRecipe(const VPWidenCallRecipe *R);
59 Type *inferScalarTypeForRecipe(const VPWidenRecipe *R);
60 Type *inferScalarTypeForRecipe(const VPWidenIntOrFpInductionRecipe *R);
61 Type *inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R);
62 Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R);
63
64public:
65 VPTypeAnalysis(const VPlan &Plan);
66
67 /// Infer the type of \p V. Returns the scalar type of \p V.
68 Type *inferScalarType(const VPValue *V);
69
70 /// Return the LLVMContext used by the analysis.
71 LLVMContext &getContext() { return Ctx; }
72};
73
74// Collect a VPlan's ephemeral recipes (those used only by an assume).
75void collectEphemeralRecipesForVPlan(VPlan &Plan,
76 DenseSet<VPRecipeBase *> &EphRecipes);
77
78/// A struct that represents some properties of the register usage
79/// of a loop.
81 /// Holds the number of loop invariant values that are used in the loop.
82 /// The key is ClassID of target-provided register class.
84 /// Holds the maximum number of concurrent live intervals in the loop.
85 /// The key is ClassID of target-provided register class.
87
88 /// Calculate the estimated cost of any spills due to using more registers
89 /// than the number available for the target. If non-zero, OverrideMaxNumRegs
90 /// is used in place of the target's number of registers.
93 unsigned OverrideMaxNumRegs = 0) const;
94};
95
96/// Estimate the register usage for \p Plan and vectorization factors in \p VFs
97/// by calculating the highest number of values that are live at a single
98/// location as a rough estimate. Returns the register usage for each VF in \p
99/// VFs.
102 const SmallPtrSetImpl<const Value *> &ValuesToIgnore);
103
104} // end namespace llvm
105
106#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
static cl::opt< OutputCostKind > CostKind("cost-kind", cl::desc("Target cost kind"), cl::init(OutputCostKind::RecipThroughput), cl::values(clEnumValN(OutputCostKind::RecipThroughput, "throughput", "Reciprocal throughput"), clEnumValN(OutputCostKind::Latency, "latency", "Instruction latency"), clEnumValN(OutputCostKind::CodeSize, "code-size", "Code size"), clEnumValN(OutputCostKind::SizeAndLatency, "size-latency", "Code size and latency"), clEnumValN(OutputCostKind::All, "all", "Print all cost kinds")))
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file implements a map that provides insertion order iteration.
This pass exposes codegen information to IR-level passes.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
TargetCostKind
The kind of cost model.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
A recipe for vectorizing a phi-node as a sequence of mask-based select instructions.
Definition VPlan.h:2775
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1222
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:405
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:3191
LLVMContext & getContext()
Return the LLVMContext used by the analysis.
Type * inferScalarType(const VPValue *V)
Infer the type of V. Returns the scalar type of V.
VPTypeAnalysis(const VPlan &Plan)
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:49
A recipe for widening Call instructions using library calls.
Definition VPlan.h:1984
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition VPlan.h:2443
A common base class for widening memory operations.
Definition VPlan.h:3502
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1776
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4513
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
SmallVector< VPRegisterUsage, 8 > calculateRegisterUsageForPlan(VPlan &Plan, ArrayRef< ElementCount > VFs, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value * > &ValuesToIgnore)
Estimate the register usage for Plan and vectorization factors in VFs by calculating the highest numb...
void collectEphemeralRecipesForVPlan(VPlan &Plan, DenseSet< VPRecipeBase * > &EphRecipes)
TargetTransformInfo TTI
A MapVector that performs no allocations if smaller than a certain size.
Definition MapVector.h:276
Struct to hold various analysis needed for cost computations.
A struct that represents some properties of the register usage of a loop.
SmallMapVector< unsigned, unsigned, 4 > MaxLocalUsers
Holds the maximum number of concurrent live intervals in the loop.
InstructionCost spillCost(const TargetTransformInfo &TTI, TargetTransformInfo::TargetCostKind CostKind, unsigned OverrideMaxNumRegs=0) const
Calculate the estimated cost of any spills due to using more registers than the number available for ...
SmallMapVector< unsigned, unsigned, 4 > LoopInvariantRegs
Holds the number of loop invariant values that are used in the loop.