LLVM 24.0.0git
TargetInfo.h
Go to the documentation of this file.
1//===----- TargetInfo.h - Target ABI information ------------------- 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/// \file
10/// Target-specific ABI information and factory functions.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ABI_TARGETINFO_H
15#define LLVM_ABI_TARGETINFO_H
16
18#include "llvm/ABI/Types.h"
20#include <cassert>
21#include <memory>
22
23namespace llvm {
24namespace abi {
25
27 /// Pass it using the normal C aggregate rules for the ABI, potentially
28 /// introducing extra copies and passing some or all of it in registers.
30
31 /// Pass it on the stack using its defined layout. The argument must be
32 /// evaluated directly into the correct stack position in the arguments area,
33 /// and the call machinery must not move it or introduce extra copies.
35
36 /// Pass it as a pointer to temporary memory.
38};
39
40/// Flags controlling ABI compatibility behaviour that applies to every target.
41/// Targets with compatibility flags of their own extend this with a derived
42/// structure.
44 /// Whether a matrix type may be the base type of a homogeneous aggregate.
45 bool IsMatrixHA : 1;
46
48};
49
50/// How promotable integer arguments are passed on X86
51/// (-mextend-small-integers).
53 /// Compat with platform ABI (high bits unspecified).
55 /// Compat with old Clang ABI (high bits zero/sign-extended).
57 /// Compat with both. Extend in caller, don't assume in callee.
59};
60
61/// Flags controlling X86-specific ABI compatibility behaviour.
77
79protected:
81
82public:
83 explicit TargetInfo(TypeBuilder &Builder) : TB(Builder) {}
84
85 virtual ~TargetInfo() = default;
86
87 /// Populate FI with the target's ABI-lowering decisions for each argument
88 /// and return value.
89 virtual void computeInfo(FunctionInfo &FI) const = 0;
90 virtual bool isPassByRef(const Type *Ty) const { return false; }
91
92 /// Return this target's ABI compatibility flags. Targets with extra flags
93 /// store a derived object and return that as an ABICompatInfo reference.
94 virtual const ABICompatInfo &getABICompatInfo() const = 0;
95
96 /// Address space in which indirect arguments are allocated (the target's
97 /// alloca/stack space).
98 virtual unsigned getAllocaAddrSpace() const { return 0; }
99
100 /// Address space of the sret pointer of a record that cannot be passed in
101 /// registers (e.g. one with a non-trivial copy constructor or destructor).
102 virtual unsigned getSRetAddrSpace() const { return 0; }
103
104 /// Whether the target has a 128-bit integer type. Default true.
105 virtual bool hasInt128Type() const { return true; }
106
107 /// Width of `long long` in bits. Default 64.
108 virtual unsigned getLongLongWidth() const { return 64; }
109
110 /// Alignment of the widest integer the target's data layout gives an
111 /// alignment to. An integer wider than that one is aligned to this. Default
112 /// 16, the alignment of i128 on AArch64 and x86-64.
113 virtual llvm::Align getMaxIntegerAlign() const { return llvm::Align(16); }
114
115protected:
117 LLVM_ABI RecordArgABI getRecordArgABI(const Type *Ty) const;
118 LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const;
119
120 /// Bit width above which a _BitInt cannot stay in registers.
121 unsigned getBitIntRegThreshold() const {
122 return hasInt128Type() ? 128 : getLongLongWidth();
123 }
124 LLVM_ABI ArgInfo getNaturalAlignIndirect(const Type *Ty, unsigned AddrSpace,
125 bool ByVal = true) const;
126
127 /// An array of \p NumBytes i8 elements, the padding element of a
128 /// coerce-and-expand type.
129 LLVM_ABI const Type *getI8Array(uint64_t NumBytes) const;
130
131 /// In-memory form of \p Ty. A record becomes one field list: non-empty
132 /// bases and fields in offset order. Padding is an array of i8. The result
133 /// is packed when a member offset or the record size is not a multiple of
134 /// the converted member alignment, and then every gap is an explicit array.
135 /// Any other record has an array only where that alignment does not already
136 /// produce the gap, and for the tail that alignment is capped at
137 /// getMaxIntegerAlign(). A record with a virtual base has no layout here. An
138 /// array is rebuilt when its element type changes. Any other type is
139 /// returned unchanged.
140 LLVM_ABI const Type *convertTypeForMem(const Type *Ty) const;
141
142 /// A record with one field per element of \p Elems, each at offset 0.
143 /// \p Packed selects a packed record, which has no alignment padding
144 /// between fields.
146 bool Packed) const;
147
148 LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const;
149
150 /// If Ty is a transparent union, return its first field type; otherwise
151 /// return Ty unchanged.
152 LLVM_ABI const Type *useFirstFieldIfTransparentUnion(const Type *Ty) const;
153
154 /// Returns the scalar a single-element struct reduces to, else null.
155 LLVM_ABI const Type *isSingleElementStruct(const Type *Ty) const;
156
157 /// Apply rules for classifying return types that are common to all targets.
159
160 /// Return true if \p Ty is a valid base type for a homogeneous aggregate.
161 virtual bool isHomogeneousAggregateBaseType(const Type *Ty) const {
162 return false;
163 }
164
165 /// Return true if a homogeneous aggregate with \p Members copies of \p Base
166 /// is small enough to be passed in registers for this ABI.
168 uint64_t Members) const {
169 return false;
170 }
171
172 /// Return true if zero-length bitfields should be ignored when deciding
173 /// whether an aggregate is homogeneous.
175 return false;
176 }
177
178 /// Return true if the C++ ABI permits \p RT to be a homogeneous aggregate.
179 virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const {
180 return true;
181 }
182
183 /// Return true if \p Ty is an ELFv2-style homogeneous aggregate. \p Base is
184 /// set to the base element type and \p Members to the number of base
185 /// elements.
186 LLVM_ABI bool isHomogeneousAggregate(const Type *Ty, const Type *&Base,
187 uint64_t &Members) const;
188};
189
190LLVM_ABI std::unique_ptr<TargetInfo> createBPFTargetInfo(TypeBuilder &TB);
191
192LLVM_ABI std::unique_ptr<TargetInfo>
193createAMDGPUTargetInfo(TypeBuilder &TB,
194 bool CoerceGenericPtrArgToGlobal = false);
195
196LLVM_ABI std::unique_ptr<TargetInfo>
197createSPIRVTargetInfo(TypeBuilder &TB, unsigned DefaultAddrSpace,
198 bool KernelPassAggregatesIndirect = false);
199
200/// The AVX ABI level for X86 targets.
201enum class X86AVXABILevel {
205 Last = AVX512 // must be last
206};
207
208LLVM_ABI std::unique_ptr<TargetInfo>
209createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel,
210 bool Has64BitPointers, const X86ABICompatInfo &Compat);
211
218
219/// Target / language flags that affect AArch64 ABI classification.
220/// Callers (e.g. Clang) resolve Triple and LangOptions into these flags
221/// rather than passing a Triple into the ABI library.
236
237LLVM_ABI std::unique_ptr<TargetInfo>
238createAArch64TargetInfo(TypeBuilder &TB, const AArch64ABIOptions &Opts);
239
240} // namespace abi
241} // namespace llvm
242
243#endif // LLVM_ABI_TARGETINFO_H
uint64_t uint64_t
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
#define LLVM_ABI
Definition Compiler.h:211
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Helper class to encapsulate information about how a specific type should be passed to or returned fro...
LLVM_ABI const Type * isSingleElementStruct(const Type *Ty) const
Returns the scalar a single-element struct reduces to, else null.
unsigned getBitIntRegThreshold() const
Bit width above which a _BitInt cannot stay in registers.
Definition TargetInfo.h:121
virtual unsigned getLongLongWidth() const
Width of long long in bits. Default 64.
Definition TargetInfo.h:108
virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const
Return true if the C++ ABI permits RT to be a homogeneous aggregate.
Definition TargetInfo.h:179
virtual const ABICompatInfo & getABICompatInfo() const =0
Return this target's ABI compatibility flags.
virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, uint64_t Members) const
Return true if a homogeneous aggregate with Members copies of Base is small enough to be passed in re...
Definition TargetInfo.h:167
virtual unsigned getAllocaAddrSpace() const
Address space in which indirect arguments are allocated (the target's alloca/stack space).
Definition TargetInfo.h:98
virtual void computeInfo(FunctionInfo &FI) const =0
Populate FI with the target's ABI-lowering decisions for each argument and return value.
LLVM_ABI bool isHomogeneousAggregate(const Type *Ty, const Type *&Base, uint64_t &Members) const
Return true if Ty is an ELFv2-style homogeneous aggregate.
LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const
virtual ~TargetInfo()=default
virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const
Return true if zero-length bitfields should be ignored when deciding whether an aggregate is homogene...
Definition TargetInfo.h:174
virtual bool isPassByRef(const Type *Ty) const
Definition TargetInfo.h:90
TargetInfo(TypeBuilder &Builder)
Definition TargetInfo.h:83
virtual bool isHomogeneousAggregateBaseType(const Type *Ty) const
Return true if Ty is a valid base type for a homogeneous aggregate.
Definition TargetInfo.h:161
virtual bool hasInt128Type() const
Whether the target has a 128-bit integer type. Default true.
Definition TargetInfo.h:105
LLVM_ABI const Type * getStructOfTypes(ArrayRef< const Type * > Elems, bool Packed) const
A record with one field per element of Elems, each at offset 0.
LLVM_ABI bool maybeCommonClassifyReturnType(FunctionInfo &FI) const
Apply rules for classifying return types that are common to all targets.
LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const
TypeBuilder & TB
Definition TargetInfo.h:80
LLVM_ABI const Type * useFirstFieldIfTransparentUnion(const Type *Ty) const
If Ty is a transparent union, return its first field type; otherwise return Ty unchanged.
LLVM_ABI ArgInfo getNaturalAlignIndirect(const Type *Ty, unsigned AddrSpace, bool ByVal=true) const
LLVM_ABI RecordArgABI getRecordArgABI(const RecordType *RT) const
LLVM_ABI const Type * convertTypeForMem(const Type *Ty) const
In-memory form of Ty.
virtual llvm::Align getMaxIntegerAlign() const
Alignment of the widest integer the target's data layout gives an alignment to.
Definition TargetInfo.h:113
LLVM_ABI const Type * getI8Array(uint64_t NumBytes) const
An array of NumBytes i8 elements, the padding element of a coerce-and-expand type.
virtual unsigned getSRetAddrSpace() const
Address space of the sret pointer of a record that cannot be passed in registers (e....
Definition TargetInfo.h:102
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Definition Types.h:513
Represents the ABI-specific view of a type in LLVM.
Definition Types.h:48
This file defines the type system for the LLVMABI library, which mirrors ABI-relevant aspects of fron...
LLVM_ABI std::unique_ptr< TargetInfo > createBPFTargetInfo(TypeBuilder &TB)
Definition BPF.cpp:88
LLVM_ABI std::unique_ptr< TargetInfo > createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel, bool Has64BitPointers, const X86ABICompatInfo &Compat)
Definition X86.cpp:1411
X86AVXABILevel
The AVX ABI level for X86 targets.
Definition TargetInfo.h:201
LLVM_ABI std::unique_ptr< TargetInfo > createAMDGPUTargetInfo(TypeBuilder &TB, bool CoerceGenericPtrArgToGlobal=false)
Definition AMDGPU.cpp:256
LLVM_ABI std::unique_ptr< TargetInfo > createSPIRVTargetInfo(TypeBuilder &TB, unsigned DefaultAddrSpace, bool KernelPassAggregatesIndirect=false)
Definition SPIRV.cpp:88
@ RAA_Indirect
Pass it as a pointer to temporary memory.
Definition TargetInfo.h:37
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
Definition TargetInfo.h:34
@ RAA_Default
Pass it using the normal C aggregate rules for the ABI, potentially introducing extra copies and pass...
Definition TargetInfo.h:29
LLVM_ABI std::unique_ptr< TargetInfo > createAArch64TargetInfo(TypeBuilder &TB, const AArch64ABIOptions &Opts)
Definition AArch64.cpp:89
SmallIntABICompatKind
How promotable integer arguments are passed on X86 (-mextend-small-integers).
Definition TargetInfo.h:52
@ Both
Compat with both. Extend in caller, don't assume in callee.
Definition TargetInfo.h:58
@ Platform
Compat with platform ABI (high bits unspecified).
Definition TargetInfo.h:54
@ Clang23
Compat with old Clang ABI (high bits zero/sign-extended).
Definition TargetInfo.h:56
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
AArch64ABIOptions(AArch64ABIKind Kind)
Definition TargetInfo.h:234
Flags controlling ABI compatibility behaviour that applies to every target.
Definition TargetInfo.h:43
bool IsMatrixHA
Whether a matrix type may be the base type of a homogeneous aggregate.
Definition TargetInfo.h:45
SmallIntABICompatKind SmallIntABICompat
Definition TargetInfo.h:69