clang 20.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;
23} // namespace llvm
24
25namespace clang {
26class ASTContext;
27class CodeGenOptions;
28class TargetInfo;
29
30namespace CodeGen {
31class ABIArgInfo;
32class Address;
33class CGCXXABI;
34class CGFunctionInfo;
35class CodeGenFunction;
36class CodeGenTypes;
37class RValue;
38class AggValueSlot;
39
40// FIXME: All of this stuff should be part of the target interface
41// somehow. It is currently here because it is not clear how to factor
42// the targets to support this, since the Targets currently live in a
43// layer below types n'stuff.
44
45/// ABIInfo - Target specific hooks for defining how a type should be
46/// passed or returned from functions.
47class ABIInfo {
48protected:
50 llvm::CallingConv::ID RuntimeCC;
51
52public:
54 : CGT(cgt), RuntimeCC(llvm::CallingConv::C) {}
55
56 virtual ~ABIInfo();
57
58 virtual bool allowBFloatArgsAndRet() const { return false; }
59
61 ASTContext &getContext() const;
62 llvm::LLVMContext &getVMContext() const;
63 const llvm::DataLayout &getDataLayout() const;
64 const TargetInfo &getTarget() const;
65 const CodeGenOptions &getCodeGenOpts() const;
66
67 /// Return the calling convention to use for system runtime
68 /// functions.
69 llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
70
71 virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const = 0;
72
73 /// EmitVAArg - Emit the target dependent code to load a value of
74 /// \arg Ty from the va_list pointed to by \arg VAListAddr.
75
76 // FIXME: This is a gaping layering violation if we wanted to drop
77 // the ABI information any lower than CodeGen. Of course, for
78 // VAArg handling it has to be at this level; there is no way to
79 // abstract this out.
81 CodeGen::Address VAListAddr, QualType Ty,
82 AggValueSlot Slot) const = 0;
83
84 bool isAndroid() const;
85 bool isOHOSFamily() const;
86
87 /// Emit the target dependent code to load a value of
88 /// \arg Ty from the \c __builtin_ms_va_list pointed to by \arg VAListAddr.
90 CodeGen::Address VAListAddr, QualType Ty,
91 AggValueSlot Slot) const;
92
93 virtual bool isHomogeneousAggregateBaseType(QualType Ty) const;
94
96 uint64_t Members) const;
98
99 /// isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous
100 /// aggregate. Base is set to the base element type, and Members is set
101 /// to the number of base elements.
102 bool isHomogeneousAggregate(QualType Ty, const Type *&Base,
103 uint64_t &Members) const;
104
105 // Implement the Type::IsPromotableIntegerType for ABI specific needs. The
106 // only difference is that this considers bit-precise integer types as well.
108
109 /// A convenience method to return an indirect ABIArgInfo with an
110 /// expected alignment equal to the ABI alignment of the given type.
112 getNaturalAlignIndirect(QualType Ty, bool ByVal = true, bool Realign = false,
113 llvm::Type *Padding = nullptr) const;
114
116 bool Realign = false) const;
117
118 virtual void appendAttributeMangling(TargetAttr *Attr,
119 raw_ostream &Out) const;
120 virtual void appendAttributeMangling(TargetVersionAttr *Attr,
121 raw_ostream &Out) const;
122 virtual void appendAttributeMangling(TargetClonesAttr *Attr, unsigned Index,
123 raw_ostream &Out) const;
124 virtual void appendAttributeMangling(StringRef AttrStr,
125 raw_ostream &Out) const;
126};
127
128/// Target specific hooks for defining how a type should be passed or returned
129/// from functions with one of the Swift calling conventions.
131protected:
134
136 unsigned maxAllRegisters) const;
137
138public:
141
142 virtual ~SwiftABIInfo();
143
144 /// Returns true if an aggregate which expands to the given type sequence
145 /// should be passed / returned indirectly.
146 virtual bool shouldPassIndirectly(ArrayRef<llvm::Type *> ComponentTys,
147 bool AsReturnValue) const;
148
149 /// Returns true if the given vector type is legal from Swift's calling
150 /// convention perspective.
151 virtual bool isLegalVectorType(CharUnits VectorSize, llvm::Type *EltTy,
152 unsigned NumElts) const;
153
154 /// Returns true if swifterror is lowered to a register by the target ABI.
156};
157} // end namespace CodeGen
158} // end namespace clang
159
160#endif
MatchType Type
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:187
Attr - This represents one attribute.
Definition: Attr.h:42
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 ...
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
Definition: ABIInfo.h:47
const llvm::DataLayout & getDataLayout() const
Definition: ABIInfo.cpp:26
virtual bool allowBFloatArgsAndRet() const
Definition: ABIInfo.h:58
const CodeGenOptions & getCodeGenOpts() const
Definition: ABIInfo.cpp:32
ABIInfo(CodeGen::CodeGenTypes &cgt)
Definition: ABIInfo.h:53
CodeGen::CodeGenTypes & CGT
Definition: ABIInfo.h:49
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:61
CodeGen::CGCXXABI & getCXXABI() const
Definition: ABIInfo.cpp:18
ASTContext & getContext() const
Definition: ABIInfo.cpp:20
virtual bool isHomogeneousAggregateBaseType(QualType Ty) const
Definition: ABIInfo.cpp:47
bool isPromotableIntegerTypeForABI(QualType Ty) const
Definition: ABIInfo.cpp:163
virtual void appendAttributeMangling(TargetAttr *Attr, raw_ostream &Out) const
Definition: ABIInfo.cpp:187
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
CodeGen::ABIArgInfo getNaturalAlignIndirect(QualType Ty, 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:174
virtual bool isHomogeneousAggregateSmallEnough(const Type *Base, uint64_t Members) const
Definition: ABIInfo.cpp:51
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:56
llvm::CallingConv::ID getRuntimeCC() const
Return the calling convention to use for system runtime functions.
Definition: ABIInfo.h:69
CodeGen::ABIArgInfo getNaturalAlignIndirectInReg(QualType Ty, bool Realign=false) const
Definition: ABIInfo.cpp:181
virtual void computeInfo(CodeGen::CGFunctionInfo &FI) const =0
llvm::CallingConv::ID RuntimeCC
Definition: ABIInfo.h:50
bool isAndroid() const
Definition: ABIInfo.cpp:36
llvm::LLVMContext & getVMContext() const
Definition: ABIInfo.cpp:22
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:504
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.
Definition: CodeGenTypes.h:54
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:42
Target specific hooks for defining how a type should be passed or returned from functions with one of...
Definition: ABIInfo.h:130
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:278
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:255
bool isSwiftErrorInRegister() const
Returns true if swifterror is lowered to a register by the target ABI.
Definition: ABIInfo.h:155
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:273
SwiftABIInfo(CodeGen::CodeGenTypes &CGT, bool SwiftErrorInRegister)
Definition: ABIInfo.h:139
A (possibly-)qualified type.
Definition: Type.h:941
Exposes information about the current target.
Definition: TargetInfo.h:218
The base class of the type hierarchy.
Definition: Type.h:1829
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:278
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30