LLVM 20.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 GlobalValue;
24class LLT;
25class MachineBasicBlock;
26class MachineFunction;
27class TargetLoweringBase;
28class TargetLowering;
29class TargetMachine;
30struct EVT;
31
32/// Compute the linearized index of a member in a nested
33/// aggregate/struct/array.
34///
35/// Given an LLVM IR aggregate type and a sequence of insertvalue or
36/// extractvalue indices that identify a member, return the linearized index of
37/// the start of the member, i.e the number of element in memory before the
38/// sought one. This is disconnected from the number of bytes.
39///
40/// \param Ty is the type indexed by \p Indices.
41/// \param Indices is an optional pointer in the indices list to the current
42/// index.
43/// \param IndicesEnd is the end of the indices list.
44/// \param CurIndex is the current index in the recursion.
45///
46/// \returns \p CurIndex plus the linear index in \p Ty the indices list.
47unsigned ComputeLinearIndex(Type *Ty,
48 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/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
59/// EVTs that represent all the individual underlying
60/// non-aggregate types that comprise it.
61///
62/// If Offsets is non-null, it points to a vector to be filled in
63/// with the in-memory offsets of each of the individual values.
64///
65void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
66 SmallVectorImpl<EVT> &ValueVTs,
67 SmallVectorImpl<EVT> *MemVTs,
68 SmallVectorImpl<TypeSize> *Offsets = nullptr,
69 TypeSize StartingOffset = TypeSize::getZero());
70void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty,
71 SmallVectorImpl<EVT> &ValueVTs,
72 SmallVectorImpl<EVT> *MemVTs,
73 SmallVectorImpl<uint64_t> *FixedOffsets,
74 uint64_t StartingOffset);
75
76/// Variant of ComputeValueVTs that don't produce memory VTs.
77inline void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
78 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
79 SmallVectorImpl<TypeSize> *Offsets = nullptr,
80 TypeSize StartingOffset = TypeSize::getZero()) {
81 ComputeValueVTs(TLI, DL, Ty, ValueVTs, nullptr, Offsets, StartingOffset);
82}
83inline void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
84 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
85 SmallVectorImpl<uint64_t> *FixedOffsets,
86 uint64_t StartingOffset) {
87 ComputeValueVTs(TLI, DL, Ty, ValueVTs, nullptr, FixedOffsets, StartingOffset);
88}
89
90/// computeValueLLTs - Given an LLVM IR type, compute a sequence of
91/// LLTs that represent all the individual underlying
92/// non-aggregate types that comprise it.
93///
94/// If Offsets is non-null, it points to a vector to be filled in
95/// with the in-memory offsets of each of the individual values.
96///
97void computeValueLLTs(const DataLayout &DL, Type &Ty,
98 SmallVectorImpl<LLT> &ValueTys,
99 SmallVectorImpl<uint64_t> *Offsets = nullptr,
100 uint64_t StartingOffset = 0);
101
102/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
103GlobalValue *ExtractTypeInfo(Value *V);
104
105/// getFCmpCondCode - Return the ISD condition code corresponding to
106/// the given LLVM IR floating-point condition code. This includes
107/// consideration of global floating-point math flags.
108///
110
111/// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
112/// return the equivalent code if we're allowed to assume that NaNs won't occur.
114
115/// getICmpCondCode - Return the ISD condition code corresponding to
116/// the given LLVM IR integer condition code.
118
119/// getICmpCondCode - Return the LLVM IR integer condition code
120/// corresponding to the given ISD integer condition code.
122
123/// Test if the given instruction is in a position to be optimized
124/// with a tail-call. This roughly means that it's in a block with
125/// a return and there's nothing that needs to be scheduled
126/// between it and the return.
127///
128/// This function only tests target-independent requirements.
129bool isInTailCallPosition(const CallBase &Call, const TargetMachine &TM,
130 bool ReturnsFirstArg = false);
131
132/// Test if given that the input instruction is in the tail call position, if
133/// there is an attribute mismatch between the caller and the callee that will
134/// inhibit tail call optimizations.
135/// \p AllowDifferingSizes is an output parameter which, if forming a tail call
136/// is permitted, determines whether it's permitted only if the size of the
137/// caller's and callee's return types match exactly.
138bool attributesPermitTailCall(const Function *F, const Instruction *I,
139 const ReturnInst *Ret,
140 const TargetLoweringBase &TLI,
141 bool *AllowDifferingSizes = nullptr);
142
143/// Test if given that the input instruction is in the tail call position if the
144/// return type or any attributes of the function will inhibit tail call
145/// optimization.
146bool returnTypeIsEligibleForTailCall(const Function *F, const Instruction *I,
147 const ReturnInst *Ret,
148 const TargetLoweringBase &TLI,
149 bool ReturnsFirstArg = false);
150
151/// Returns true if the parent of \p CI returns CI's first argument after
152/// calling \p CI.
153bool funcReturnsFirstArgOfCall(const CallInst &CI);
154
155DenseMap<const MachineBasicBlock *, int>
156getEHScopeMembership(const MachineFunction &MF);
157
158} // End llvm namespace
159
160#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
RelocType Type
Definition: COFFYAML.cpp:391
This file defines the DenseMap class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:154
iterator begin() const
Definition: ArrayRef.h:153
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:757
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
static constexpr TypeSize getZero()
Definition: TypeSize.h:351
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Definition: ISDOpcodes.h:1603
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ISD::CondCode getICmpCondCode(ICmpInst::Predicate Pred)
getICmpCondCode - Return the ISD condition code corresponding to the given LLVM IR integer condition ...
Definition: Analysis.cpp:233
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:643
void computeValueLLTs(const DataLayout &DL, Type &Ty, SmallVectorImpl< LLT > &ValueTys, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
computeValueLLTs - Given an LLVM IR type, compute a sequence of LLTs that represent all the individua...
Definition: Analysis.cpp:141
ISD::CondCode getFCmpCondCode(FCmpInst::Predicate Pred)
getFCmpCondCode - Return the ISD condition code corresponding to the given LLVM IR floating-point con...
Definition: Analysis.cpp:199
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:583
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:535
ISD::CondCode getFCmpCodeWithoutNaN(ISD::CondCode CC)
getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats, return the equivalent code if w...
Definition: Analysis.cpp:221
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs, 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:79
bool funcReturnsFirstArgOfCall(const CallInst &CI)
Returns true if the parent of CI returns CI's first argument after calling CI.
Definition: Analysis.cpp:714
GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
Definition: Analysis.cpp:177
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:33
DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)
Definition: Analysis.cpp:752