LLVM 24.0.0git
Analysis.h
Go to the documentation of this file.
1//===- CodeGen/Analysis.h - CodeGen LLVM IR Analysis 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// This file declares several CodeGen-specific LLVM IR analysis utilities.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_ANALYSIS_H
14#define LLVM_CODEGEN_ANALYSIS_H
15
16#include "llvm/ADT/ArrayRef.h"
17#include "llvm/ADT/DenseMap.h"
20
21namespace llvm {
22template <typename T> class SmallVectorImpl;
23class Constant;
24class GlobalValue;
25class LLT;
27class MachineFunction;
29class TargetLowering;
30class TargetMachine;
31struct EVT;
32
33/// Compute the linearized index of a member in a nested
34/// aggregate/struct/array.
35///
36/// Given an LLVM IR aggregate type and a sequence of insertvalue or
37/// extractvalue indices that identify a member, return the linearized index of
38/// the start of the member, i.e the number of element in memory before the
39/// sought one. This is disconnected from the number of bytes.
40///
41/// \param Ty is the type indexed by \p Indices.
42/// \param Indices is an optional pointer in the indices list to the current
43/// index.
44/// \param IndicesEnd is the end of the indices list.
45/// \param CurIndex is the current index in the recursion.
46///
47/// \returns \p CurIndex plus the linear index in \p Ty the indices list.
48LLVM_ABI unsigned ComputeLinearIndex(Type *Ty, const unsigned *Indices,
49 const unsigned *IndicesEnd,
50 unsigned CurIndex = 0);
51
52inline unsigned ComputeLinearIndex(Type *Ty,
53 ArrayRef<unsigned> Indices,
54 unsigned CurIndex = 0) {
55 return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
56}
57
58/// Given an LLVM IR type, compute non-aggregate subtypes. Optionally also
59/// compute their offsets.
60LLVM_ABI void ComputeValueTypes(const DataLayout &DL, Type *Ty,
61 SmallVectorImpl<Type *> &Types,
62 SmallVectorImpl<TypeSize> *Offsets = nullptr,
63 TypeSize StartingOffset = TypeSize::getZero());
64
65/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
66/// EVTs that represent all the individual underlying
67/// non-aggregate types that comprise it.
68///
69/// If Offsets is non-null, it points to a vector to be filled in
70/// with the in-memory offsets of each of the individual values.
71///
72LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
73 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
74 SmallVectorImpl<EVT> *MemVTs = nullptr,
75 SmallVectorImpl<TypeSize> *Offsets = nullptr,
76 TypeSize StartingOffset = TypeSize::getZero());
77LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
78 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
79 SmallVectorImpl<EVT> *MemVTs,
80 SmallVectorImpl<uint64_t> *FixedOffsets,
81 uint64_t StartingOffset);
82
83/// computeValueLLTs - Given an LLVM IR type, compute a sequence of
84/// LLTs that represent all the individual underlying
85/// non-aggregate types that comprise it.
86///
87/// If Offsets is non-null, it points to a vector to be filled in
88/// with the in-memory offsets of each of the individual values.
89///
90LLVM_ABI void computeValueLLTs(const DataLayout &DL, Type &Ty,
91 SmallVectorImpl<LLT> &ValueLLTs,
92 SmallVectorImpl<TypeSize> *Offsets = nullptr,
93 TypeSize StartingOffset = TypeSize::getZero());
94LLVM_ABI void computeValueLLTs(const DataLayout &DL, Type &Ty,
95 SmallVectorImpl<LLT> &ValueLLTs,
96 SmallVectorImpl<uint64_t> *FixedOffsets,
97 uint64_t FixedStartingOffset = 0);
98
99/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
100LLVM_ABI GlobalValue *ExtractTypeInfo(Value *V);
101
102/// Return true if landingpad result type \p Ty is a struct of an exception
103/// pointer (pointer or integer) and an integer selector, the only lowerable
104/// form.
106
107/// getFCmpCondCode - Return the ISD condition code corresponding to
108/// the given LLVM IR floating-point condition code. This includes
109/// consideration of global floating-point math flags.
110///
112
113/// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
114/// return the equivalent code if we're allowed to assume that NaNs won't occur.
116
117/// getICmpCondCode - Return the ISD condition code corresponding to
118/// the given LLVM IR integer condition code.
120
121/// getICmpCondCode - Return the LLVM IR integer condition code
122/// corresponding to the given ISD integer condition code.
124
125/// Return the atomic node opcode for an atomicrmw operation.
127
128/// Test if the address of \p GV can be described in debug info as a plain
129/// reference to its symbol, so that a variable holding that address can be
130/// described for the whole of its scope rather than only from wherever the
131/// address happens to be materialized.
132///
133/// Whether the symbol alone denotes the runtime address depends on \p MF: the
134/// relocation model decides whether a base has to be added to it, and the
135/// debug format and DWARF version decide whether the result can be spelled as
136/// a value rather than as a place to load from.
137LLVM_ABI bool canDescribeGlobalAddressInDebugInfo(const GlobalValue *GV,
138 const MachineFunction &MF);
139
140/// If \p C is the address of a global, possibly displaced by a constant,
141/// return that global and set \p Offset to the displacement in bytes. Returns
142/// nullptr if \p C is not such an address, or if the global's address cannot be
143/// described per canDescribeGlobalAddressInDebugInfo(). \p Offset is set to
144/// zero in those cases, so it only carries a displacement alongside a global.
145LLVM_ABI const GlobalValue *
146getDescribableGlobalAddress(const Constant *C, int64_t &Offset,
147 const MachineFunction &MF);
148
149/// Test if the debug info for \p MF can name a describable global address in a
150/// location list too, rather than only in a variable's single location. Where
151/// it cannot, a register holding the address is the more robust description.
153
154/// Test if the given instruction is in a position to be optimized
155/// with a tail-call. This roughly means that it's in a block with
156/// a return and there's nothing that needs to be scheduled
157/// between it and the return.
158///
159/// This function only tests target-independent requirements.
160LLVM_ABI bool isInTailCallPosition(const CallBase &Call,
161 const TargetMachine &TM,
162 bool ReturnsFirstArg = false);
163
164/// Test if given that the input instruction is in the tail call position, if
165/// there is an attribute mismatch between the caller and the callee that will
166/// inhibit tail call optimizations.
167/// \p AllowDifferingSizes is an output parameter which, if forming a tail call
168/// is permitted, determines whether it's permitted only if the size of the
169/// caller's and callee's return types match exactly.
170LLVM_ABI bool attributesPermitTailCall(const Function *F, const Instruction *I,
171 const ReturnInst *Ret,
172 const TargetLoweringBase &TLI,
173 bool *AllowDifferingSizes = nullptr);
174
175/// Test if given that the input instruction is in the tail call position if the
176/// return type or any attributes of the function will inhibit tail call
177/// optimization.
179 const Instruction *I,
180 const ReturnInst *Ret,
181 const TargetLoweringBase &TLI,
182 bool ReturnsFirstArg = false);
183
184/// Returns true if the parent of \p CI returns CI's first argument after
185/// calling \p CI.
186LLVM_ABI bool funcReturnsFirstArgOfCall(const CallInst &CI);
187
188LLVM_ABI DenseMap<const MachineBasicBlock *, int>
190
191} // End llvm namespace
192
193#endif
const TargetLowering & TLI
SDValue Pred
uint64_t uint64_t
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
This file defines the DenseMap class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
RISCVCC::CondCode CC
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
iterator begin() const
Definition ArrayRef.h:129
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
This is an important base class in LLVM.
Definition Constant.h:44
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
static constexpr TypeSize getZero()
Definition TypeSize.h:358
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
CallInst * Call
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition ISDOpcodes.h:43
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI ISD::NodeType getAtomicRMWOpcode(AtomicRMWInst::BinOp Op)
Return the atomic node opcode for an atomicrmw operation.
Definition Analysis.cpp:292
@ Offset
Definition DWP.cpp:577
LLVM_ABI bool canDescribeGlobalAddressInLocationList(const MachineFunction &MF)
Test if the debug info for MF can name a describable global address in a location list too,...
Definition Analysis.cpp:695
LLVM_ABI ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred)
getICmpCondCode - Return the ISD condition code corresponding to the given LLVM IR integer condition ...
Definition Analysis.cpp:248
LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs=nullptr, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition Analysis.cpp:121
LLVM_ABI bool isExceptionPointerAndSelectorType(Type *Ty)
Return true if landingpad result type Ty is a struct of an exception pointer (pointer or integer) and...
Definition Analysis.cpp:201
LLVM_ABI void ComputeValueTypes(const DataLayout &DL, Type *Ty, SmallVectorImpl< Type * > &Types, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
Given an LLVM IR type, compute non-aggregate subtypes.
Definition Analysis.cpp:74
LLVM_ABI bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI, bool ReturnsFirstArg=false)
Test if given that the input instruction is in the tail call position if the return type or any attri...
Definition Analysis.cpp:817
LLVM_ABI ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred)
getFCmpCondCode - Return the ISD condition code corresponding to the given LLVM IR floating-point con...
Definition Analysis.cpp:214
LLVM_ABI bool attributesPermitTailCall(const Function *F, const Instruction *I, const ReturnInst *Ret, const TargetLoweringBase &TLI, bool *AllowDifferingSizes=nullptr)
Test if given that the input instruction is in the tail call position, if there is an attribute misma...
Definition Analysis.cpp:757
LLVM_ABI bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM, bool ReturnsFirstArg=false)
Test if the given instruction is in a position to be optimized with a tail-call.
Definition Analysis.cpp:709
DWARFExpression::Operation Op
LLVM_ABI ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC)
getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, return the equivalent code if w...
Definition Analysis.cpp:236
LLVM_ABI const GlobalValue * getDescribableGlobalAddress(const Constant *C, int64_t &Offset, const MachineFunction &MF)
If C is the address of a global, possibly displaced by a constant, return that global and set Offset ...
Definition Analysis.cpp:676
LLVM_ABI bool funcReturnsFirstArgOfCall(const CallInst &CI)
Returns true if the parent of CI returns CI's first argument after calling CI.
Definition Analysis.cpp:888
LLVM_ABI bool canDescribeGlobalAddressInDebugInfo(const GlobalValue *GV, const MachineFunction &MF)
Test if the address of GV can be described in debug info as a plain reference to its symbol,...
Definition Analysis.cpp:607
LLVM_ABI void computeValueLLTs(const DataLayout &DL, Type &Ty, SmallVectorImpl< LLT > &ValueLLTs, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
computeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individua...
Definition Analysis.cpp:155
LLVM_ABI GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
Definition Analysis.cpp:183
LLVM_ABI unsigned ComputeLinearIndex(Type *Ty, const unsigned *Indices, const unsigned *IndicesEnd, unsigned CurIndex=0)
Compute the linearized index of a member in a nested aggregate/struct/array.
Definition Analysis.cpp:35
LLVM_ABI DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)
Definition Analysis.cpp:926
Extended Value Type.
Definition ValueTypes.h:35