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 /// Whether the target has a 128-bit integer type. Default true.
88 virtual bool hasInt128Type() const { return true; }
89
90 /// Width of `long long` in bits. Default 64.
91 virtual unsigned getLongLongWidth() const { return 64; }
92
93 /// Alignment of the widest integer the target's data layout gives an
94 /// alignment to. An integer wider than that one is aligned to this. Default
95 /// 16, the alignment of i128 on AArch64 and x86-64.
96 virtual llvm::Align getMaxIntegerAlign() const { return llvm::Align(16); }
97
98protected:
100 LLVM_ABI RecordArgABI getRecordArgABI(const Type *Ty) const;
101 LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const;
102
103 /// Bit width above which a _BitInt cannot stay in registers.
104 unsigned getBitIntRegThreshold() const {
105 return hasInt128Type() ? 128 : getLongLongWidth();
106 }
107 LLVM_ABI ArgInfo getNaturalAlignIndirect(const Type *Ty, unsigned AddrSpace,
108 bool ByVal = true) const;
109
110 /// An array of \p NumBytes i8 elements, the padding element of a
111 /// coerce-and-expand type.
112 LLVM_ABI const Type *getI8Array(uint64_t NumBytes) const;
113
114 /// In-memory form of \p Ty. A record becomes one field list: non-empty
115 /// bases and fields in offset order. Padding is an array of i8. The result
116 /// is packed when a member offset or the record size is not a multiple of
117 /// the converted member alignment, and then every gap is an explicit array.
118 /// Any other record has an array only where that alignment does not already
119 /// produce the gap, and for the tail that alignment is capped at
120 /// getMaxIntegerAlign(). A record with a virtual base has no layout here. An
121 /// array is rebuilt when its element type changes. Any other type is
122 /// returned unchanged.
123 LLVM_ABI const Type *convertTypeForMem(const Type *Ty) const;
124
125 /// A record with one field per element of \p Elems, each at offset 0.
126 /// \p Packed selects a packed record, which has no alignment padding
127 /// between fields.
129 bool Packed) const;
130
131 LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const;
132
133 /// If Ty is a transparent union, return its first field type; otherwise
134 /// return Ty unchanged.
135 LLVM_ABI const Type *useFirstFieldIfTransparentUnion(const Type *Ty) const;
136
137 /// Returns the scalar a single-element struct reduces to, else null.
138 LLVM_ABI const Type *isSingleElementStruct(const Type *Ty) const;
139
140 /// Apply rules for classifying return types that are common to all targets.
142
143 /// Return true if \p Ty is a valid base type for a homogeneous aggregate.
144 virtual bool isHomogeneousAggregateBaseType(const Type *Ty) const {
145 return false;
146 }
147
148 /// Return true if a homogeneous aggregate with \p Members copies of \p Base
149 /// is small enough to be passed in registers for this ABI.
151 uint64_t Members) const {
152 return false;
153 }
154
155 /// Return true if zero-length bitfields should be ignored when deciding
156 /// whether an aggregate is homogeneous.
158 return false;
159 }
160
161 /// Return true if the C++ ABI permits \p RT to be a homogeneous aggregate.
162 virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const {
163 return true;
164 }
165
166 /// Return true if \p Ty is an ELFv2-style homogeneous aggregate. \p Base is
167 /// set to the base element type and \p Members to the number of base
168 /// elements.
169 LLVM_ABI bool isHomogeneousAggregate(const Type *Ty, const Type *&Base,
170 uint64_t &Members) const;
171};
172
173LLVM_ABI std::unique_ptr<TargetInfo> createBPFTargetInfo(TypeBuilder &TB);
174
175LLVM_ABI std::unique_ptr<TargetInfo>
176createAMDGPUTargetInfo(TypeBuilder &TB,
177 bool CoerceGenericPtrArgToGlobal = false);
178
179/// The AVX ABI level for X86 targets.
180enum class X86AVXABILevel {
184 Last = AVX512 // must be last
185};
186
187LLVM_ABI std::unique_ptr<TargetInfo>
188createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel,
189 bool Has64BitPointers, const X86ABICompatInfo &Compat);
190
197
198/// Target / language flags that affect AArch64 ABI classification.
199/// Callers (e.g. Clang) resolve Triple and LangOptions into these flags
200/// rather than passing a Triple into the ABI library.
214
215LLVM_ABI std::unique_ptr<TargetInfo>
216createAArch64TargetInfo(TypeBuilder &TB, const AArch64ABIOptions &Opts);
217
218} // namespace abi
219} // namespace llvm
220
221#endif // LLVM_ABI_TARGETINFO_H
unsigned 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:215
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:104
virtual unsigned getLongLongWidth() const
Width of long long in bits. Default 64.
Definition TargetInfo.h:91
virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const
Return true if the C++ ABI permits RT to be a homogeneous aggregate.
Definition TargetInfo.h:162
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:150
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:157
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:144
virtual bool hasInt128Type() const
Whether the target has a 128-bit integer type. Default true.
Definition TargetInfo.h:88
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:96
LLVM_ABI const Type * getI8Array(uint64_t NumBytes) const
An array of NumBytes i8 elements, the padding element of a coerce-and-expand type.
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Definition Types.h:462
Represents the ABI-specific view of a type in LLVM.
Definition Types.h:47
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:1383
X86AVXABILevel
The AVX ABI level for X86 targets.
Definition TargetInfo.h:180
LLVM_ABI std::unique_ptr< TargetInfo > createAMDGPUTargetInfo(TypeBuilder &TB, bool CoerceGenericPtrArgToGlobal=false)
Definition AMDGPU.cpp:255
@ 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:88
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:212
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