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/// Test if the address of \p GV can be described in debug info as a plain
126/// reference to its symbol, so that a variable holding that address can be
127/// described for the whole of its scope rather than only from wherever the
128/// address happens to be materialized.
129///
130/// Whether the symbol alone denotes the runtime address depends on \p MF: the
131/// relocation model decides whether a base has to be added to it, and the
132/// debug format and DWARF version decide whether the result can be spelled as
133/// a value rather than as a place to load from.
134LLVM_ABI bool canDescribeGlobalAddressInDebugInfo(const GlobalValue *GV,
135 const MachineFunction &MF);
136
137/// If \p C is the address of a global, possibly displaced by a constant,
138/// return that global and set \p Offset to the displacement in bytes. Returns
139/// nullptr if \p C is not such an address, or if the global's address cannot be
140/// described per canDescribeGlobalAddressInDebugInfo(). \p Offset is set to
141/// zero in those cases, so it only carries a displacement alongside a global.
142LLVM_ABI const GlobalValue *
143getDescribableGlobalAddress(const Constant *C, int64_t &Offset,
144 const MachineFunction &MF);
145
146/// Test if the debug info for \p MF can name a describable global address in a
147/// location list too, rather than only in a variable's single location. Where
148/// it cannot, a register holding the address is the more robust description.
150
151/// Test if the given instruction is in a position to be optimized
152/// with a tail-call. This roughly means that it's in a block with
153/// a return and there's nothing that needs to be scheduled
154/// between it and the return.
155///
156/// This function only tests target-independent requirements.
157LLVM_ABI bool isInTailCallPosition(const CallBase &Call,
158 const TargetMachine &TM,
159 bool ReturnsFirstArg = false);
160
161/// Test if given that the input instruction is in the tail call position, if
162/// there is an attribute mismatch between the caller and the callee that will
163/// inhibit tail call optimizations.
164/// \p AllowDifferingSizes is an output parameter which, if forming a tail call
165/// is permitted, determines whether it's permitted only if the size of the
166/// caller's and callee's return types match exactly.
167LLVM_ABI bool attributesPermitTailCall(const Function *F, const Instruction *I,
168 const ReturnInst *Ret,
169 const TargetLoweringBase &TLI,
170 bool *AllowDifferingSizes = nullptr);
171
172/// Test if given that the input instruction is in the tail call position if the
173/// return type or any attributes of the function will inhibit tail call
174/// optimization.
176 const Instruction *I,
177 const ReturnInst *Ret,
178 const TargetLoweringBase &TLI,
179 bool ReturnsFirstArg = false);
180
181/// Returns true if the parent of \p CI returns CI's first argument after
182/// calling \p CI.
183LLVM_ABI bool funcReturnsFirstArgOfCall(const CallInst &CI);
184
185LLVM_ABI DenseMap<const MachineBasicBlock *, int>
187
188} // End llvm namespace
189
190#endif
unsigned 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:215
This file defines the DenseMap class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
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
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:43
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:345
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
CallInst * Call
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.
@ 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:642
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:765
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:705
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:656
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:623
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:836
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:554
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:874
Extended Value Type.
Definition ValueTypes.h:35