clang 23.0.0git
ABIInfo.h
Go to the documentation of this file.
1//===----- ABIInfo.h - ABI information access & encapsulation ---*- 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#ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
10#define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
11
12#include "clang/AST/Attr.h"
13#include "clang/AST/CharUnits.h"
14#include "clang/AST/Type.h"
15#include "llvm/IR/CallingConv.h"
16#include "llvm/IR/Type.h"
17
18namespace llvm {
19class Value;
20class LLVMContext;
21class DataLayout;
22class Type;
23class FixedVectorType;
24} // namespace llvm
25
26namespace clang {
27class ASTContext;
28class CodeGenOptions;
29class TargetInfo;
30
31namespace CodeGen {
32class ABIArgInfo;
33class Address;
34class CGCXXABI;
35class CGFunctionInfo;
36class CodeGenFunction;
37class CodeGenTypes;
38class RValue;
39class AggValueSlot;
40
41// FIXME: All of this stuff should be part of the target interface
42// somehow. It is currently here because it is not clear how to factor
43// the targets to support this, since the Targets currently live in a
44// layer below types n'stuff.
45
46/// ABIInfo - Target specific hooks for defining how a type should be
47/// passed or returned from functions.
48class ABIInfo {
49protected:
51 llvm::CallingConv::ID RuntimeCC;
52
53public:
56
57 virtual ~ABIInfo();
58
59 virtual bool allowBFloatArgsAndRet() const { return false; }
60
62 ASTContext &getContext() const;
63 llvm::LLVMContext &getVMContext() const;
64 const llvm::DataLayout &getDataLayout() const;
65 const TargetInfo &getTarget() const;
66 const CodeGenOptions &getCodeGenOpts() const;
67
68 /// Return the calling convention to use for system runtime
69 /// functions.
70 llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
71
72 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
73
74 /// EmitVAArg - Emit the target dependent code to load a value of
75 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
76
77 // FIXME: This is a gaping layering violation if we wanted to drop
78 // the ABI information any lower than CodeGen. Of course, for
79 // VAArg handling it has to be at this level; there is no way to
80 // abstract this out.
82 CodeGen::Address VAListAddr, QualType Ty,
83 AggValueSlot Slot) const = 0;
84
85 bool isAndroid() const;
86 bool isOHOSFamily() const;
87
88 /// Emit the target dependent code to load a value of
89 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
91 CodeGen::Address VAListAddr, QualType Ty,
92 AggValueSlot Slot) const;
93
94 /// Emit the target dependent code to load a value of
95 /// \arg Ty from the \c __builtin_zos_va_list pointed to by \arg VAListAddr.
97 CodeGen::Address VAListAddr, QualType Ty,
98 AggValueSlot Slot) const;
99
100 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
101
102 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
103 uint64_t Members) const;
105
106 /// isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous
107 /// aggregate. Base is set to the base element type, and Members is set
108 /// to the number of base elements.
109 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
110 uint64_t &Members) const;
111
112 // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
113 // only difference is that this considers bit-precise integer types as well.
115
116 /// A convenience method to return an indirect ABIArgInfo with an
117 /// expected alignment equal to the ABI alignment of the given type.
119 getNaturalAlignIndirect(QualType Ty, unsigned AddrSpace, bool ByVal = true,
120 bool Realign = false,
121 llvm::Type *Padding = nullptr) const;
122
124 bool Realign = false) const;
125
126 virtual void appendAttributeMangling(TargetAttr *Attr,
127 raw_ostream &Out) const;
128 virtual void appendAttributeMangling(TargetVersionAttr *Attr,
129 raw_ostream &Out) const;
130 virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
131 raw_ostream &Out) const;
132 virtual void appendAttributeMangling(StringRef AttrStr,
133 raw_ostream &Out) const;
134
135 /// Returns the optimal vector memory type based on the given vector type. For
136 /// example, on certain targets, a vector with 3 elements might be promoted to
137 /// one with 4 elements to improve performance.
138 virtual llvm::FixedVectorType *
139 getOptimalVectorMemoryType(llvm::FixedVectorType *T,
140 const LangOptions &Opt) const;
141
142 virtual llvm::Value *createCoercedLoad(Address SrcAddr, const ABIArgInfo &AI,
143 CodeGenFunction &CGF) const;
144 virtual void createCoercedStore(llvm::Value *Val, Address DstAddr,
145 const ABIArgInfo &AI, bool DestIsVolatile,
146 CodeGenFunction &CGF) const;
147
148 /// Used by Arm64EC calling convention code to call into x86 calling
149 /// convention code for varargs function.
151};
152
153/// Target specific hooks for defining how a type should be passed or returned
154/// from functions with one of the Swift calling conventions.
156protected:
159
161 unsigned maxAllRegisters) const;
162
163public:
166
167 virtual ~SwiftABIInfo();
168
169 /// Returns true if an aggregate which expands to the given type sequence
170 /// should be passed / returned indirectly.
171 virtual bool shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
172 bool AsReturnValue) const;
173
174 /// Returns true if the given vector type is legal from Swift's calling
175 /// convention perspective.
176 virtual bool isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
177 unsigned NumElts) const;
178
179 /// Returns true if swifterror is lowered to a register by the target ABI.
181};
182} // end namespace CodeGen
183} // end namespace clang
184
185#endif
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
Attr - This represents one attribute.
Definition Attr.h:46
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
const llvm::DataLayout & getDataLayout() const
Definition ABIInfo.cpp:26
CodeGen::ABIArgInfo getNaturalAlignIndirect(QualType Ty, unsigned AddrSpace, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr) const
A convenience method to return an indirect ABIArgInfo with an expected alignment equal to the ABI ali...
Definition ABIInfo.cpp:178
virtual bool allowBFloatArgsAndRet() const
Definition ABIInfo.h:59
const CodeGenOptions & getCodeGenOpts() const
Definition ABIInfo.cpp:32
ABIInfo(CodeGen::CodeGenTypes &cgt)
Definition ABIInfo.h:54
CodeGen::CodeGenTypes & CGT
Definition ABIInfo.h:50
bool isHomogeneousAggregate(QualType Ty, const Type *&Base, uint64_t &Members) const
isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous aggregate.
Definition ABIInfo.cpp:66
CodeGen::CGCXXABI & getCXXABI() const
Definition ABIInfo.cpp:18
ASTContext & getContext() const
Definition ABIInfo.cpp:20
virtual bool isHomogeneousAggregateBaseType(QualType Ty) const
Definition ABIInfo.cpp:52
bool isPromotableIntegerTypeForABI(QualType Ty) const
Definition ABIInfo.cpp:167
virtual void createCoercedStore(llvm::Value *Val, Address DstAddr, const ABIArgInfo &AI, bool DestIsVolatile, CodeGenFunction &CGF) const
Definition ABIInfo.cpp:256
virtual void appendAttributeMangling(TargetAttr *Attr, raw_ostream &Out) const
Definition ABIInfo.cpp:191
bool isOHOSFamily() const
Definition ABIInfo.cpp:38
virtual RValue EmitMSVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty, AggValueSlot Slot) const
Emit the target dependent code to load a value of.
Definition ABIInfo.cpp:42
virtual ABIArgInfo classifyArgForArm64ECVarArg(QualType Ty) const
Used by Arm64EC calling convention code to call into x86 calling convention code for varargs function...
Definition ABIInfo.cpp:260
virtual RValue EmitZOSVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty, AggValueSlot Slot) const
Emit the target dependent code to load a value of.
Definition ABIInfo.cpp:47
virtual llvm::Value * createCoercedLoad(Address SrcAddr, const ABIArgInfo &AI, CodeGenFunction &CGF) const
Definition ABIInfo.cpp:251
virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, uint64_t Members) const
Definition ABIInfo.cpp:56
const TargetInfo & getTarget() const
Definition ABIInfo.cpp:30
virtual RValue EmitVAArg(CodeGen::CodeGenFunction &CGF, CodeGen::Address VAListAddr, QualType Ty, AggValueSlot Slot) const =0
EmitVAArg - Emit the target dependent code to load a value of.
virtual bool isZeroLengthBitfieldPermittedInHomogeneousAggregate() const
Definition ABIInfo.cpp:61
llvm::CallingConv::ID getRuntimeCC() const
Return the calling convention to use for system runtime functions.
Definition ABIInfo.h:70
CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty, bool Realign=false) const
Definition ABIInfo.cpp:185
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
llvm::CallingConv::ID RuntimeCC
Definition ABIInfo.h:51
bool isAndroid() const
Definition ABIInfo.cpp:36
llvm::LLVMContext & getVMContext() const
Definition ABIInfo.cpp:22
virtual llvm::FixedVectorType * getOptimalVectorMemoryType(llvm::FixedVectorType *T, const LangOptions &Opt) const
Returns the optimal vector memory type based on the given vector type.
Definition ABIInfo.cpp:244
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition Address.h:128
An aggregate value slot.
Definition CGValue.h:551
Implements C++ ABI-specific code generation functions.
Definition CGCXXABI.h:43
CGFunctionInfo - Class to encapsulate the information about a function definition.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition CGValue.h:42
virtual bool isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy, unsigned NumElts) const
Returns true if the given vector type is legal from Swift's calling convention perspective.
Definition ABIInfo.cpp:303
bool occupiesMoreThan(ArrayRef< llvm::Type * > scalarTypes, unsigned maxAllRegisters) const
Does the given lowering require more than the given number of registers when expanded?
Definition ABIInfo.cpp:280
bool isSwiftErrorInRegister() const
Returns true if swifterror is lowered to a register by the target ABI.
Definition ABIInfo.h:180
virtual bool shouldPassIndirectly(ArrayRef< llvm::Type * > ComponentTys, bool AsReturnValue) const
Returns true if an aggregate which expands to the given type sequence should be passed / returned ind...
Definition ABIInfo.cpp:298
SwiftABIInfo(CodeGen::CodeGenTypes &CGT, bool SwiftErrorInRegister)
Definition ABIInfo.h:164
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A (possibly-)qualified type.
Definition TypeBase.h:937
Exposes information about the current target.
Definition TargetInfo.h:227
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
Definition CGValue.h:155
The JSON file list parser is used to communicate input to InstallAPI.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:279
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30