clang  12.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 
32 namespace llvm {
33 class AttrBuilder;
34 class Constant;
35 class DataLayout;
36 class Module;
37 class Function;
38 class FunctionType;
39 class Type;
40 }
41 
42 namespace clang {
43 class ASTContext;
44 class CXXConstructorDecl;
45 class CXXDestructorDecl;
46 class CXXRecordDecl;
47 class CXXMethodDecl;
48 class CodeGenOptions;
49 class CoverageSourceInfo;
50 class DiagnosticsEngine;
51 class HeaderSearchOptions;
52 class ObjCMethodDecl;
53 class ObjCProtocolDecl;
54 class PreprocessorOptions;
55 
56 namespace CodeGen {
57 class CGFunctionInfo;
58 class CodeGenModule;
59 
60 /// Additional implicit arguments to add to a constructor argument list.
62  /// Implicit arguments to add before the explicit arguments, but after the
63  /// `*this` argument (which always comes first).
65 
66  /// Implicit arguments to add after the explicit arguments.
68 };
69 
71  const ObjCMethodDecl *MD,
72  QualType receiverType);
73 
76 
79 
81  const CXXRecordDecl *RD,
82  const FunctionProtoType *FTP,
83  const CXXMethodDecl *MD);
84 
86  CanQualType returnType,
87  ArrayRef<CanQualType> argTypes,
89  RequiredArgs args);
90 
91 /// Returns the implicit arguments to add to a complete, non-delegating C++
92 /// constructor call.
95 
97 getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock,
98  llvm::BasicBlock::iterator InsertPoint,
100  bool ForVirtualBase, bool Delegating);
101 
102 /// Returns null if the function type is incomplete and can't be lowered.
103 llvm::FunctionType *convertFreeFunctionType(CodeGenModule &CGM,
104  const FunctionDecl *FD);
105 
106 llvm::Type *convertTypeForMemory(CodeGenModule &CGM, QualType T);
107 
108 /// Given a non-bitfield struct field, return its index within the elements of
109 /// the struct's converted type. The returned index refers to a field number in
110 /// the complete object type which is returned by convertTypeForMemory. FD must
111 /// be a field in RD directly (i.e. not an inherited field).
112 unsigned getLLVMFieldNumber(CodeGenModule &CGM,
113  const RecordDecl *RD, const FieldDecl *FD);
114 
115 /// Given the language and code-generation options that Clang was configured
116 /// with, set the default LLVM IR attributes for a function definition.
117 /// The attributes set here are mostly global target-configuration and
118 /// pipeline-configuration options like the target CPU, variant stack
119 /// rules, whether to optimize for size, and so on. This is useful for
120 /// frontends (such as Swift) that generally intend to interoperate with
121 /// C code and rely on Clang's target configuration logic.
122 ///
123 /// As a general rule, this function assumes that meaningful attributes
124 /// haven't already been added to the builder. It won't intentionally
125 /// displace any existing attributes, but it also won't check to avoid
126 /// overwriting them. Callers should generally apply customizations after
127 /// making this call.
128 ///
129 /// This function assumes that the caller is not defining a function that
130 /// requires special no-builtin treatment.
132  llvm::AttrBuilder &attrs);
133 
134 /// Returns the default constructor for a C struct with non-trivially copyable
135 /// fields, generating it if necessary. The returned function uses the `cdecl`
136 /// calling convention, returns void, and takes a single argument that is a
137 /// pointer to the address of the struct.
139  CharUnits DstAlignment,
140  bool IsVolatile,
141  QualType QT);
142 
143 /// Returns the copy constructor for a C struct with non-trivially copyable
144 /// fields, generating it if necessary. The returned function uses the `cdecl`
145 /// calling convention, returns void, and takes two arguments: pointers to the
146 /// addresses of the destination and source structs, respectively.
148  CharUnits DstAlignment,
149  CharUnits SrcAlignment,
150  bool IsVolatile,
151  QualType QT);
152 
153 /// Returns the move constructor for a C struct with non-trivially copyable
154 /// fields, generating it if necessary. The returned function uses the `cdecl`
155 /// calling convention, returns void, and takes two arguments: pointers to the
156 /// addresses of the destination and source structs, respectively.
158  CharUnits DstAlignment,
159  CharUnits SrcAlignment,
160  bool IsVolatile,
161  QualType QT);
162 
163 /// Returns the copy assignment operator for a C struct with non-trivially
164 /// copyable fields, generating it if necessary. The returned function uses the
165 /// `cdecl` calling convention, returns void, and takes two arguments: pointers
166 /// to the addresses of the destination and source structs, respectively.
168  CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
169  bool IsVolatile, QualType QT);
170 
171 /// Return the move assignment operator for a C struct with non-trivially
172 /// copyable fields, generating it if necessary. The returned function uses the
173 /// `cdecl` calling convention, returns void, and takes two arguments: pointers
174 /// to the addresses of the destination and source structs, respectively.
176  CodeGenModule &CGM, CharUnits DstAlignment, CharUnits SrcAlignment,
177  bool IsVolatile, QualType QT);
178 
179 /// Returns the destructor for a C struct with non-trivially copyable fields,
180 /// generating it if necessary. The returned function uses the `cdecl` calling
181 /// convention, returns void, and takes a single argument that is a pointer to
182 /// the address of the struct.
183 llvm::Function *getNonTrivialCStructDestructor(CodeGenModule &CGM,
184  CharUnits DstAlignment,
185  bool IsVolatile, QualType QT);
186 
187 /// Get a pointer to a protocol object for the given declaration, emitting it if
188 /// it hasn't already been emitted in this translation unit. Note that the ABI
189 /// for emitting a protocol reference in code (e.g. for a protocol expression)
190 /// in most runtimes is not as simple as just materializing a pointer to this
191 /// object.
192 llvm::Constant *emitObjCProtocolObject(CodeGenModule &CGM,
193  const ObjCProtocolDecl *p);
194 } // end namespace CodeGen
195 } // end namespace clang
196 
197 #endif
Represents a function declaration or definition.
Definition: Decl.h:1783
A (possibly-)qualified type.
Definition: Type.h:655
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
C Language Family Type Representation.
The base class of the type hierarchy.
Definition: Type.h:1472
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2413
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
const CGFunctionInfo & arrangeCXXMethodType(CodeGenModule &CGM, const CXXRecordDecl *RD, const FunctionProtoType *FTP, const CXXMethodDecl *MD)
Represents a struct/union/class.
Definition: Decl.h:3770
SmallVector< llvm::Value *, 1 > Suffix
Implicit arguments to add after the explicit arguments.
MatchType Type
Represents a member of a struct/union/class.
Definition: Decl.h:2746
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
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...
Enums/classes describing ABI related information about constructors, destructors and thunks...
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2055
const CGFunctionInfo & arrangeObjCMessageSendSignature(CodeGenModule &CGM, const ObjCMethodDecl *MD, QualType receiverType)
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3886
CXXDtorType
C++ destructor types.
Definition: ABI.h:33
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2679
A class for recording the number of arguments that a function signature requires. ...
ImplicitCXXConstructorArgs getImplicitCXXConstructorArgs(CodeGenModule &CGM, const CXXConstructorDecl *D)
Returns the implicit arguments to add to a complete, non-delegating C++ constructor call...
llvm::FunctionType * convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD)
Returns null if the function type is incomplete and can&#39;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, generating it if necessary.
void addDefaultFunctionDefinitionAttributes(CodeGenModule &CGM, llvm::AttrBuilder &attrs)
Given the language and code-generation options that Clang was configured with, set the default LLVM I...
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1960
const CGFunctionInfo & arrangeFreeFunctionCall(CodeGenModule &CGM, CanQualType returnType, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, RequiredArgs args)
const CGFunctionInfo & arrangeFreeFunctionType(CodeGenModule &CGM, CanQual< FunctionNoProtoType > Ty)
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...
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
llvm::Constant * emitObjCProtocolObject(CodeGenModule &CGM, const ObjCProtocolDecl *p)
Get a pointer to a protocol object for the given declaration, emitting it if it hasn&#39;t already been e...
llvm::Function * getNonTrivialCStructDefaultConstructor(CodeGenModule &GCM, CharUnits DstAlignment, bool IsVolatile, QualType QT)
Returns the default constructor for a C struct with non-trivially copyable fields, generating it if necessary.
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, generating it if necessary.
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&#39;s converted typ...
SmallVector< llvm::Value *, 1 > Prefix
Implicit arguments to add before the explicit arguments, but after the *this argument (which always c...
llvm::Type * convertTypeForMemory(CodeGenModule &CGM, QualType T)
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
Additional implicit arguments to add to a constructor argument list.
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...
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3658