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/// Flags controlling X86-specific ABI compatibility behaviour.
64
66protected:
68
69public:
70 explicit TargetInfo(TypeBuilder &Builder) : TB(Builder) {}
71
72 virtual ~TargetInfo() = default;
73
74 /// Populate FI with the target's ABI-lowering decisions for each argument
75 /// and return value.
76 virtual void computeInfo(FunctionInfo &FI) const = 0;
77 virtual bool isPassByRef(const Type *Ty) const { return false; }
78
79 /// Return this target's ABI compatibility flags. Targets with extra flags
80 /// store a derived object and return that as an ABICompatInfo reference.
81 virtual const ABICompatInfo &getABICompatInfo() const = 0;
82
83 /// Address space in which indirect arguments are allocated (the target's
84 /// alloca/stack space).
85 virtual unsigned getAllocaAddrSpace() const { return 0; }
86
87 /// Address space of the sret pointer of a record that cannot be passed in
88 /// registers (e.g. one with a non-trivial copy constructor or destructor).
89 virtual unsigned getSRetAddrSpace() const { return 0; }
90
91 /// Whether the target has a 128-bit integer type. Default true.
92 virtual bool hasInt128Type() const { return true; }
93
94 /// Width of `long long` in bits. Default 64.
95 virtual unsigned getLongLongWidth() const { return 64; }
96
97 /// Alignment of the widest integer the target's data layout gives an
98 /// alignment to. An integer wider than that one is aligned to this. Default
99 /// 16, the alignment of i128 on AArch64 and x86-64.
100 virtual llvm::Align getMaxIntegerAlign() const { return llvm::Align(16); }
101
102protected:
104 LLVM_ABI RecordArgABI getRecordArgABI(const Type *Ty) const;
105 LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const;
106
107 /// Bit width above which a _BitInt cannot stay in registers.
108 unsigned getBitIntRegThreshold() const {
109 return hasInt128Type() ? 128 : getLongLongWidth();
110 }
111 LLVM_ABI ArgInfo getNaturalAlignIndirect(const Type *Ty, unsigned AddrSpace,
112 bool ByVal = true) const;
113
114 /// An array of \p NumBytes i8 elements, the padding element of a
115 /// coerce-and-expand type.
116 LLVM_ABI const Type *getI8Array(uint64_t NumBytes) const;
117
118 /// In-memory form of \p Ty. A record becomes one field list: non-empty
119 /// bases and fields in offset order. Padding is an array of i8. The result
120 /// is packed when a member offset or the record size is not a multiple of
121 /// the converted member alignment, and then every gap is an explicit array.
122 /// Any other record has an array only where that alignment does not already
123 /// produce the gap, and for the tail that alignment is capped at
124 /// getMaxIntegerAlign(). A record with a virtual base has no layout here. An
125 /// array is rebuilt when its element type changes. Any other type is
126 /// returned unchanged.
127 LLVM_ABI const Type *convertTypeForMem(const Type *Ty) const;
128
129 /// A record with one field per element of \p Elems, each at offset 0.
130 /// \p Packed selects a packed record, which has no alignment padding
131 /// between fields.
133 bool Packed) const;
134
135 LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const;
136
137 /// If Ty is a transparent union, return its first field type; otherwise
138 /// return Ty unchanged.
139 LLVM_ABI const Type *useFirstFieldIfTransparentUnion(const Type *Ty) const;
140
141 /// Returns the scalar a single-element struct reduces to, else null.
142 LLVM_ABI const Type *isSingleElementStruct(const Type *Ty) const;
143
144 /// Apply rules for classifying return types that are common to all targets.
146
147 /// Return true if \p Ty is a valid base type for a homogeneous aggregate.
148 virtual bool isHomogeneousAggregateBaseType(const Type *Ty) const {
149 return false;
150 }
151
152 /// Return true if a homogeneous aggregate with \p Members copies of \p Base
153 /// is small enough to be passed in registers for this ABI.
155 uint64_t Members) const {
156 return false;
157 }
158
159 /// Return true if zero-length bitfields should be ignored when deciding
160 /// whether an aggregate is homogeneous.
162 return false;
163 }
164
165 /// Return true if the C++ ABI permits \p RT to be a homogeneous aggregate.
166 virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const {
167 return true;
168 }
169
170 /// Return true if \p Ty is an ELFv2-style homogeneous aggregate. \p Base is
171 /// set to the base element type and \p Members to the number of base
172 /// elements.
173 LLVM_ABI bool isHomogeneousAggregate(const Type *Ty, const Type *&Base,
174 uint64_t &Members) const;
175};
176
177LLVM_ABI std::unique_ptr<TargetInfo> createBPFTargetInfo(TypeBuilder &TB);
178
179LLVM_ABI std::unique_ptr<TargetInfo>
180createAMDGPUTargetInfo(TypeBuilder &TB,
181 bool CoerceGenericPtrArgToGlobal = false);
182
183LLVM_ABI std::unique_ptr<TargetInfo>
184createSPIRVTargetInfo(TypeBuilder &TB, unsigned DefaultAddrSpace,
185 bool KernelPassAggregatesIndirect = false);
186
187/// The AVX ABI level for X86 targets.
188enum class X86AVXABILevel {
192 Last = AVX512 // must be last
193};
194
195LLVM_ABI std::unique_ptr<TargetInfo>
196createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel,
197 bool Has64BitPointers, const X86ABICompatInfo &Compat);
198
205
206/// Target / language flags that affect AArch64 ABI classification.
207/// Callers (e.g. Clang) resolve Triple and LangOptions into these flags
208/// rather than passing a Triple into the ABI library.
223
224LLVM_ABI std::unique_ptr<TargetInfo>
225createAArch64TargetInfo(TypeBuilder &TB, const AArch64ABIOptions &Opts);
226
227} // namespace abi
228} // namespace llvm
229
230#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:108
virtual unsigned getLongLongWidth() const
Width of long long in bits. Default 64.
Definition TargetInfo.h:95
virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const
Return true if the C++ ABI permits RT to be a homogeneous aggregate.
Definition TargetInfo.h:166
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:154
virtual unsigned getAllocaAddrSpace() const
Address space in which indirect arguments are allocated (the target's alloca/stack space).
Definition TargetInfo.h:85
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:161
virtual bool isPassByRef(const Type *Ty) const
Definition TargetInfo.h:77
TargetInfo(TypeBuilder &Builder)
Definition TargetInfo.h:70
virtual bool isHomogeneousAggregateBaseType(const Type *Ty) const
Return true if Ty is a valid base type for a homogeneous aggregate.
Definition TargetInfo.h:148
virtual bool hasInt128Type() const
Whether the target has a 128-bit integer type. Default true.
Definition TargetInfo.h:92
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:67
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:100
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:89
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Definition Types.h:490
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:1398
X86AVXABILevel
The AVX ABI level for X86 targets.
Definition TargetInfo.h:188
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
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:221
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