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
93protected:
96 LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const;
97
98 /// Bit width above which a _BitInt cannot stay in registers.
99 unsigned getBitIntRegThreshold() const {
100 return hasInt128Type() ? 128 : getLongLongWidth();
101 }
102 LLVM_ABI ArgInfo getNaturalAlignIndirect(const Type *Ty, unsigned AddrSpace,
103 bool ByVal = true) const;
104 LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const;
105
106 /// If Ty is a transparent union, return its first field type; otherwise
107 /// return Ty unchanged.
108 LLVM_ABI const Type *useFirstFieldIfTransparentUnion(const Type *Ty) const;
109
110 /// Returns the scalar a single-element struct reduces to, else null.
111 LLVM_ABI const Type *isSingleElementStruct(const Type *Ty) const;
112
113 /// Apply rules for classifying return types that are common to all targets.
115
116 /// Return true if \p Ty is a valid base type for a homogeneous aggregate.
117 virtual bool isHomogeneousAggregateBaseType(const Type *Ty) const {
118 return false;
119 }
120
121 /// Return true if a homogeneous aggregate with \p Members copies of \p Base
122 /// is small enough to be passed in registers for this ABI.
124 uint64_t Members) const {
125 return false;
126 }
127
128 /// Return true if zero-length bitfields should be ignored when deciding
129 /// whether an aggregate is homogeneous.
131 return false;
132 }
133
134 /// Return true if the C++ ABI permits \p RT to be a homogeneous aggregate.
135 virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const {
136 return true;
137 }
138
139 /// Return true if \p Ty is an ELFv2-style homogeneous aggregate. \p Base is
140 /// set to the base element type and \p Members to the number of base
141 /// elements.
142 LLVM_ABI bool isHomogeneousAggregate(const Type *Ty, const Type *&Base,
143 uint64_t &Members) const;
144};
145
146LLVM_ABI std::unique_ptr<TargetInfo> createBPFTargetInfo(TypeBuilder &TB);
147
148/// The AVX ABI level for X86 targets.
149enum class X86AVXABILevel {
153 Last = AVX512 // must be last
154};
155
156LLVM_ABI std::unique_ptr<TargetInfo>
157createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel,
158 bool Has64BitPointers, const X86ABICompatInfo &Compat);
159
166
167/// Target / language flags that affect AArch64 ABI classification.
168/// Callers (e.g. Clang) resolve Triple and LangOptions into these flags
169/// rather than passing a Triple into the ABI library.
180
181LLVM_ABI std::unique_ptr<TargetInfo>
182createAArch64TargetInfo(TypeBuilder &TB, const AArch64ABIOptions &Opts);
183
184} // namespace abi
185} // namespace llvm
186
187#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
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:99
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:135
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:123
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:130
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:117
virtual bool hasInt128Type() const
Whether the target has a 128-bit integer type. Default true.
Definition TargetInfo.h:88
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
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Definition Types.h:443
Represents the ABI-specific view of a type in LLVM.
Definition Types.h:46
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:1420
X86AVXABILevel
The AVX ABI level for X86 targets.
Definition TargetInfo.h:149
@ 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:67
This is an optimization pass for GlobalISel generic memory operations.
AArch64ABIOptions(AArch64ABIKind Kind)
Definition TargetInfo.h:178
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