LLVM 23.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;
26class MachineFunction;
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.
47LLVM_ABI unsigned ComputeLinearIndex(Type *Ty, const unsigned *Indices,
48 const unsigned *IndicesEnd,
49 unsigned CurIndex = 0);
50
51inline unsigned ComputeLinearIndex(Type *Ty,
52 ArrayRef<unsigned> Indices,
53 unsigned CurIndex = 0) {
54 return ComputeLinearIndex(Ty, Indices.begin(), Indices.end(), CurIndex);
55}
56
57/// Given an LLVM IR type, compute non-aggregate subtypes. Optionally also
58/// compute their offsets.
59LLVM_ABI void ComputeValueTypes(const DataLayout &DL, Type *Ty,
60 SmallVectorImpl<Type *> &Types,
61 SmallVectorImpl<TypeSize> *Offsets = nullptr,
62 TypeSize StartingOffset = TypeSize::getZero());
63
64/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of
65/// EVTs that represent all the individual underlying
66/// non-aggregate types that comprise it.
67///
68/// If Offsets is non-null, it points to a vector to be filled in
69/// with the in-memory offsets of each of the individual values.
70///
71LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
72 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
73 SmallVectorImpl<EVT> *MemVTs = nullptr,
74 SmallVectorImpl<TypeSize> *Offsets = nullptr,
75 TypeSize StartingOffset = TypeSize::getZero());
76LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL,
77 Type *Ty, SmallVectorImpl<EVT> &ValueVTs,
78 SmallVectorImpl<EVT> *MemVTs,
79 SmallVectorImpl<uint64_t> *FixedOffsets,
80 uint64_t StartingOffset);
81
82/// computeValueLLTs - Given an LLVM IR type, compute a sequence of
83/// LLTs that represent all the individual underlying
84/// non-aggregate types that comprise it.
85///
86/// If Offsets is non-null, it points to a vector to be filled in
87/// with the in-memory offsets of each of the individual values.
88///
89LLVM_ABI void computeValueLLTs(const DataLayout &DL, Type &Ty,
90 SmallVectorImpl<LLT> &ValueLLTs,
91 SmallVectorImpl<TypeSize> *Offsets = nullptr,
92 TypeSize StartingOffset = TypeSize::getZero());
93LLVM_ABI void computeValueLLTs(const DataLayout &DL, Type &Ty,
94 SmallVectorImpl<LLT> &ValueLLTs,
95 SmallVectorImpl<uint64_t> *FixedOffsets,
96 uint64_t FixedStartingOffset = 0);
97
98/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
99LLVM_ABI GlobalValue *ExtractTypeInfo(Value *V);
100
101/// getFCmpCondCode - Return the ISD condition code corresponding to
102/// the given LLVM IR floating-point condition code. This includes
103/// consideration of global floating-point math flags.
104///
106
107/// getFCmpCodeWithoutNaN - Given an ISD condition code comparing floats,
108/// return the equivalent code if we're allowed to assume that NaNs won't occur.
110
111/// getICmpCondCode - Return the ISD condition code corresponding to
112/// the given LLVM IR integer condition code.
114
115/// getICmpCondCode - Return the LLVM IR integer condition code
116/// corresponding to the given ISD integer condition code.
118
119/// Test if the given instruction is in a position to be optimized
120/// with a tail-call. This roughly means that it's in a block with
121/// a return and there's nothing that needs to be scheduled
122/// between it and the return.
123///
124/// This function only tests target-independent requirements.
125LLVM_ABI bool isInTailCallPosition(const CallBase &Call,
126 const TargetMachine &TM,
127 bool ReturnsFirstArg = false);
128
129/// Test if given that the input instruction is in the tail call position, if
130/// there is an attribute mismatch between the caller and the callee that will
131/// inhibit tail call optimizations.
132/// \p AllowDifferingSizes is an output parameter which, if forming a tail call
133/// is permitted, determines whether it's permitted only if the size of the
134/// caller's and callee's return types match exactly.
135LLVM_ABI bool attributesPermitTailCall(const Function *F, const Instruction *I,
136 const ReturnInst *Ret,
137 const TargetLoweringBase &TLI,
138 bool *AllowDifferingSizes = nullptr);
139
140/// Test if given that the input instruction is in the tail call position if the
141/// return type or any attributes of the function will inhibit tail call
142/// optimization.
143LLVM_ABI bool returnTypeIsEligibleForTailCall(const Function *F,
144 const Instruction *I,
145 const ReturnInst *Ret,
146 const TargetLoweringBase &TLI,
147 bool ReturnsFirstArg = false);
148
149/// Returns true if the parent of \p CI returns CI's first argument after
150/// calling \p CI.
151LLVM_ABI bool funcReturnsFirstArgOfCall(const CallInst &CI);
152
153LLVM_ABI DenseMap<const MachineBasicBlock *, int>
154getEHScopeMembership(const MachineFunction &MF);
155
156} // End llvm namespace
157
158#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:213
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 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:349
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.
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:237
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:119
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:72
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:648
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:203
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:588
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:539
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:225
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:719
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:153
LLVM_ABI GlobalValue * ExtractTypeInfo(Value *V)
ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
Definition Analysis.cpp:181
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:33
LLVM_ABI DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)
Definition Analysis.cpp:757
Extended Value Type.
Definition ValueTypes.h:35