clang 24.0.0git
CodeGenABITypes.h
Go to the documentation of this file.
1//==---- CodeGenABITypes.h - Convert Clang types to LLVM types for ABI -----==//
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// CodeGenABITypes is a simple interface for getting LLVM types for
10// the parameters and the return value of a function given the Clang
11// types.
12//
13// The class is implemented as a public wrapper around the private
14// CodeGenTypes class in lib/CodeGen.
15//
16// It allows other clients, like LLDB, to determine the LLVM types that are
17// actually used in function calls, which makes it possible to then determine
18// the actual ABI locations (e.g. registers, stack locations, etc.) that
19// these parameters are stored in.
20//
21//===----------------------------------------------------------------------===//
22
23#ifndef LLVM_CLANG_CODEGEN_CODEGENABITYPES_H
24#define LLVM_CLANG_CODEGEN_CODEGENABITYPES_H
25
27#include "clang/AST/Type.h"
28#include "clang/Basic/ABI.h"
30#include "llvm/IR/BasicBlock.h"
31
32namespace llvm {
33class AttrBuilder;
34class Constant;
35class ConstantInt;
36class Function;
37class FunctionType;
38class Type;
39}
40
41namespace clang {
44class CXXRecordDecl;
45class CXXMethodDecl;
46class GlobalDecl;
48class ObjCMethodDecl;
50
51namespace CodeGen {
52class CGFunctionInfo;
53class CodeGenModule;
54
55/// Additional implicit arguments to add to a constructor argument list.
57 /// Implicit arguments to add before the explicit arguments, but after the
58 /// `*this` argument (which always comes first).
60
61 /// Implicit arguments to add after the explicit arguments.
63};
64
66 const ObjCMethodDecl *MD,
67 QualType receiverType);
68
71
74
76 const CXXRecordDecl *RD,
77 const FunctionProtoType *FTP,
78 const CXXMethodDecl *MD);
79
80const CGFunctionInfo &
84 RequiredArgs args, const FunctionDecl *CallerFD);
85
87 CodeGenModule &CGM, CanQualType returnType, ArrayRef<CanQualType> argTypes,
90 const FunctionDecl *CallerFD);
91
92// An overload with an empty `paramInfos`
93inline const CGFunctionInfo &
95 ArrayRef<CanQualType> argTypes,
97 const FunctionDecl *CallerFD) {
98 return arrangeFreeFunctionCall(CGM, returnType, argTypes, info, {}, args,
99 CallerFD);
100}
101
102/// Returns the implicit arguments to add to a complete, non-delegating C++
103/// constructor call.
104ImplicitCXXConstructorArgs
105getImplicitCXXConstructorArgs(CodeGenModule &CGM, const CXXConstructorDecl *D);
106
107llvm::Value *
108getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock,
109 llvm::BasicBlock::iterator InsertPoint,
111 bool ForVirtualBase, bool Delegating);
112
113/// Returns null if the function type is incomplete and can't be lowered.
114llvm::FunctionType *convertFreeFunctionType(CodeGenModule &CGM,
115 const FunctionDecl *FD);
116
117llvm::Type *convertTypeForMemory(CodeGenModule &CGM, QualType T);
118
119/// Given a non-bitfield struct field, return its index within the elements of
120/// the struct's converted type. The returned index refers to a field number in
121/// the complete object type which is returned by convertTypeForMemory. FD must
122/// be a field in RD directly (i.e. not an inherited field).
123unsigned getLLVMFieldNumber(CodeGenModule &CGM,
124 const RecordDecl *RD, const FieldDecl *FD);
125
126/// Return a declaration discriminator for the given global decl.
128
129/// Return a type discriminator for the given function type.
132
133/// Return a signed constant pointer.
134llvm::Constant *getConstantSignedPointer(CodeGenModule &CGM,
135 llvm::Constant *Pointer, unsigned Key,
136 llvm::Constant *StorageAddress,
137 llvm::ConstantInt *OtherDiscriminator);
138
139/// Given the language and code-generation options that Clang was configured
140/// with, set the default LLVM IR attributes for a function definition.
141/// The attributes set here are mostly global target-configuration and
142/// pipeline-configuration options like the target CPU, variant stack
143/// rules, whether to optimize for size, and so on. This is useful for
144/// frontends (such as Swift) that generally intend to interoperate with
145/// C code and rely on Clang's target configuration logic.
146///
147/// As a general rule, this function assumes that meaningful attributes
148/// haven't already been added to the builder. It won't intentionally
149/// displace any existing attributes, but it also won't check to avoid
150/// overwriting them. Callers should generally apply customizations after
151/// making this call.
152///
153/// This function assumes that the caller is not defining a function that
154/// requires special no-builtin treatment.
155void addDefaultFunctionDefinitionAttributes(CodeGenModule &CGM,
156 llvm::AttrBuilder &attrs);
157
158/// Returns the default constructor for a C struct with non-trivially copyable
159/// fields, generating it if necessary. The returned function uses the `cdecl`
160/// calling convention, returns void, and takes a single argument that is a
161/// pointer to the address of the struct.
162llvm::Function *getNonTrivialCStructDefaultConstructor(CodeGenModule &GCM,
163 CharUnits DstAlignment,
164 bool IsVolatile,
165 QualType QT);
166
167/// Returns the copy constructor for a C struct with non-trivially copyable
168/// fields, generating it if necessary. The returned function uses the `cdecl`
169/// calling convention, returns void, and takes two arguments: pointers to the
170/// addresses of the destination and source structs, respectively.
171llvm::Function *getNonTrivialCStructCopyConstructor(CodeGenModule &CGM,
172 CharUnits DstAlignment,
173 CharUnits SrcAlignment,
174 bool IsVolatile,
175 QualType QT);
176
177/// Returns the move constructor for a C struct with non-trivially copyable
178/// fields, generating it if necessary. The returned function uses the `cdecl`
179/// calling convention, returns void, and takes two arguments: pointers to the
180/// addresses of the destination and source structs, respectively.
181llvm::Function *getNonTrivialCStructMoveConstructor(CodeGenModule &CGM,
182 CharUnits DstAlignment,
183 CharUnits SrcAlignment,
184 bool IsVolatile,
185 QualType QT);
186
187/// Returns the copy assignment operator for a C struct with non-trivially
188/// copyable fields, generating it if necessary. The returned function uses the
189/// `cdecl` calling convention, returns void, and takes two arguments: pointers
190/// to the addresses of the destination and source structs, respectively.
192 CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
193 bool IsVolatile, QualType QT);
194
195/// Return the move assignment operator for a C struct with non-trivially
196/// copyable fields, generating it if necessary. The returned function uses the
197/// `cdecl` calling convention, returns void, and takes two arguments: pointers
198/// to the addresses of the destination and source structs, respectively.
200 CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
201 bool IsVolatile, QualType QT);
202
203/// Returns the destructor for a C struct with non-trivially copyable fields,
204/// generating it if necessary. The returned function uses the `cdecl` calling
205/// convention, returns void, and takes a single argument that is a pointer to
206/// the address of the struct.
207llvm::Function *getNonTrivialCStructDestructor(CodeGenModule &CGM,
208 CharUnits DstAlignment,
209 bool IsVolatile, QualType QT);
210
211/// Get a pointer to a protocol object for the given declaration, emitting it if
212/// it hasn't already been emitted in this translation unit. Note that the ABI
213/// for emitting a protocol reference in code (e.g. for a protocol expression)
214/// in most runtimes is not as simple as just materializing a pointer to this
215/// object.
216llvm::Constant *emitObjCProtocolObject(CodeGenModule &CGM,
217 const ObjCProtocolDecl *p);
218
219/// Get the appropriate callee for an ObjC direct method. Returns the thunk
220/// if the receiver may be null (or class may be unrealized) and precondition
221/// thunks are enabled, otherwise returns the true implementation.
222///
223/// This allows external compilers (e.g., Swift) to reuse Clang's thunk
224/// generation logic when calling ObjC direct methods, ensuring consistent
225/// nil-check behavior.
227 const ObjCMethodDecl *OMD,
228 const ObjCContainerDecl *CD,
229 bool ReceiverCanBeNull,
230 bool ClassObjectCanBeUnrealized);
231
232} // end namespace CodeGen
233} // end namespace clang
234
235#endif
Enums/classes describing ABI related information about constructors, destructors and thunks.
C Language Family Type Representation.
Represents a C++ constructor within a class.
Definition DeclCXX.h:2633
Represents a C++ destructor within a class.
Definition DeclCXX.h:2898
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a canonical, potentially-qualified type.
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
A class for recording the number of arguments that a function signature requires.
Represents a member of a struct/union/class.
Definition Decl.h:3204
Represents a function declaration or definition.
Definition Decl.h:2029
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5371
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4678
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4567
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
ObjCContainerDecl - Represents a container for method declarations.
Definition DeclObjC.h:948
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2084
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4369
The base class of the type hierarchy.
Definition TypeBase.h:1875
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
const CGFunctionInfo & arrangeFreeFunctionType(CodeGenModule &CGM, CanQual< FunctionProtoType > Ty)
llvm::Type * convertTypeForMemory(CodeGenModule &CGM, QualType T)
const CGFunctionInfo & arrangeObjCMessageSendSignature(CodeGenModule &CGM, const ObjCMethodDecl *MD, QualType receiverType)
llvm::Function * getNonTrivialCStructCopyConstructor(CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment, bool IsVolatile, QualType QT)
Returns the copy constructor for a C struct with non-trivially copyable fields, generating it if nece...
const CGFunctionInfo & arrangeCXXMethodCall(CodeGenModule &CGM, CanQualType returnType, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args, const FunctionDecl *CallerFD)
unsigned getLLVMFieldNumber(CodeGenModule &CGM, const RecordDecl *RD, const FieldDecl *FD)
Given a non-bitfield struct field, return its index within the elements of the struct's converted typ...
llvm::Function * getNonTrivialCStructMoveConstructor(CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment, bool IsVolatile, QualType QT)
Returns the move constructor for a C struct with non-trivially copyable fields, generating it if nece...
void addDefaultFunctionDefinitionAttributes(CodeGenModule &CGM, llvm::AttrBuilder &attrs)
Given the language and code-generation options that Clang was configured with, set the default LLVM I...
const CGFunctionInfo & arrangeCXXMethodType(CodeGenModule &CGM, const CXXRecordDecl *RD, const FunctionProtoType *FTP, const CXXMethodDecl *MD)
llvm::Function * getNonTrivialCStructCopyAssignmentOperator(CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment, bool IsVolatile, QualType QT)
Returns the copy assignment operator for a C struct with non-trivially copyable fields,...
llvm::Function * getObjCDirectMethodCallee(CodeGenModule &CGM, const ObjCMethodDecl *OMD, const ObjCContainerDecl *CD, bool ReceiverCanBeNull, bool ClassObjectCanBeUnrealized)
Get the appropriate callee for an ObjC direct method.
llvm::FunctionType * convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD)
Returns null if the function type is incomplete and can't be lowered.
llvm::Function * getNonTrivialCStructMoveAssignmentOperator(CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment, bool IsVolatile, QualType QT)
Return the move assignment operator for a C struct with non-trivially copyable fields,...
llvm::Constant * emitObjCProtocolObject(CodeGenModule &CGM, const ObjCProtocolDecl *p)
Get a pointer to a protocol object for the given declaration, emitting it if it hasn't already been e...
uint16_t getPointerAuthDeclDiscriminator(CodeGenModule &CGM, GlobalDecl GD)
Return a declaration discriminator for the given global decl.
llvm::Function * getNonTrivialCStructDestructor(CodeGenModule &CGM, CharUnits DstAlignment, bool IsVolatile, QualType QT)
Returns the destructor for a C struct with non-trivially copyable fields, generating it if necessary.
const CGFunctionInfo & arrangeFreeFunctionCall(CodeGenModule &CGM, CanQualType returnType, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args, const FunctionDecl *CallerFD)
ImplicitCXXConstructorArgs getImplicitCXXConstructorArgs(CodeGenModule &CGM, const CXXConstructorDecl *D)
Returns the implicit arguments to add to a complete, non-delegating C++ constructor call.
llvm::Constant * getConstantSignedPointer(CodeGenModule &CGM, llvm::Constant *Pointer, unsigned Key, llvm::Constant *StorageAddress, llvm::ConstantInt *OtherDiscriminator)
Return a signed constant pointer.
llvm::Function * getNonTrivialCStructDefaultConstructor(CodeGenModule &GCM, CharUnits DstAlignment, bool IsVolatile, QualType QT)
Returns the default constructor for a C struct with non-trivially copyable fields,...
uint16_t getPointerAuthTypeDiscriminator(CodeGenModule &CGM, QualType FunctionType)
Return a type discriminator for the given function type.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CXXDtorType
C++ destructor types.
Definition ABI.h:34
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
Additional implicit arguments to add to a constructor argument list.
SmallVector< llvm::Value *, 1 > Prefix
Implicit arguments to add before the explicit arguments, but after the *this argument (which always c...
SmallVector< llvm::Value *, 1 > Suffix
Implicit arguments to add after the explicit arguments.