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
83protected:
86 LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const;
88 bool ByVal = true) const;
89 LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const;
90
91 /// If Ty is a transparent union, return its first field type; otherwise
92 /// return Ty unchanged.
93 LLVM_ABI const Type *useFirstFieldIfTransparentUnion(const Type *Ty) const;
94
95 /// Apply rules for classifying return types that are common to all targets.
97
98 /// Return true if \p Ty is a valid base type for a homogeneous aggregate.
99 virtual bool isHomogeneousAggregateBaseType(const Type *Ty) const {
100 return false;
101 }
102
103 /// Return true if a homogeneous aggregate with \p Members copies of \p Base
104 /// is small enough to be passed in registers for this ABI.
106 uint64_t Members) const {
107 return false;
108 }
109
110 /// Return true if zero-length bitfields should be ignored when deciding
111 /// whether an aggregate is homogeneous.
113 return false;
114 }
115
116 /// Return true if the C++ ABI permits \p RT to be a homogeneous aggregate.
117 virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const {
118 return true;
119 }
120
121 /// Return true if \p Ty is an ELFv2-style homogeneous aggregate. \p Base is
122 /// set to the base element type and \p Members to the number of base
123 /// elements.
124 LLVM_ABI bool isHomogeneousAggregate(const Type *Ty, const Type *&Base,
125 uint64_t &Members) const;
126};
127
128LLVM_ABI std::unique_ptr<TargetInfo> createBPFTargetInfo(TypeBuilder &TB);
129
130/// The AVX ABI level for X86 targets.
131enum class X86AVXABILevel {
135 Last = AVX512 // must be last
136};
137
138LLVM_ABI std::unique_ptr<TargetInfo>
139createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel,
140 bool Has64BitPointers, const X86ABICompatInfo &Compat);
141
148
149/// Target / language flags that affect AArch64 ABI classification.
150/// Callers (e.g. Clang) resolve Triple and LangOptions into these flags
151/// rather than passing a Triple into the ABI library.
161
162LLVM_ABI std::unique_ptr<TargetInfo>
163createAArch64TargetInfo(TypeBuilder &TB, const AArch64ABIOptions &Opts);
164
165} // namespace abi
166} // namespace llvm
167
168#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 ArgInfo getNaturalAlignIndirect(const Type *Ty, bool ByVal=true) const
virtual bool isPermittedToBeHomogeneousAggregate(const RecordType *RT) const
Return true if the C++ ABI permits RT to be a homogeneous aggregate.
Definition TargetInfo.h:117
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:105
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:112
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:99
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 RecordArgABI getRecordArgABI(const RecordType *RT) const
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Definition Types.h:434
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:86
LLVM_ABI std::unique_ptr< TargetInfo > createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel, bool Has64BitPointers, const X86ABICompatInfo &Compat)
Definition X86.cpp:1472
X86AVXABILevel
The AVX ABI level for X86 targets.
Definition TargetInfo.h:131
@ 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:159
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