clang 19.0.0git
Go to the documentation of this file.
1//==--- CodeGenABITypes.cpp - Convert Clang types to LLVM types for ABI ----==//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
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.
13// The class is implemented as a public wrapper around the private
14// CodeGenTypes class in lib/CodeGen.
19#include "CGCXXABI.h"
20#include "CGRecordLayout.h"
21#include "CodeGenFunction.h"
22#include "CodeGenModule.h"
27using namespace clang;
28using namespace CodeGen;
31 llvm::AttrBuilder &attrs) {
35const CGFunctionInfo &
37 const ObjCMethodDecl *MD,
38 QualType receiverType) {
39 return CGM.getTypes().arrangeObjCMessageSendSignature(MD, receiverType);
42const CGFunctionInfo &
45 return CGM.getTypes().arrangeFreeFunctionType(Ty);
48const CGFunctionInfo &
51 return CGM.getTypes().arrangeFreeFunctionType(Ty);
54const CGFunctionInfo &
56 const CXXRecordDecl *RD,
57 const FunctionProtoType *FTP,
58 const CXXMethodDecl *MD) {
59 return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD);
62const CGFunctionInfo &
64 CanQualType returnType,
65 ArrayRef<CanQualType> argTypes,
67 RequiredArgs args) {
68 return CGM.getTypes().arrangeLLVMFunctionInfo(returnType, FnInfoOpts::None,
69 argTypes, info, {}, args);
74 const CXXConstructorDecl *D) {
75 // We have to create a dummy CodeGenFunction here to pass to
76 // getImplicitConstructorArgs(). In some cases (base and delegating
77 // constructor calls), getImplicitConstructorArgs() can reach into the
78 // CodeGenFunction to find parameters of the calling constructor to pass on to
79 // the called constructor, but that can't happen here because we're asking for
80 // the args for a complete, non-delegating constructor call.
81 CodeGenFunction CGF(CGM, /* suppressNewContext= */ true);
84 /* ForVirtualBase= */ false,
85 /* Delegating= */ false);
86 ImplicitCXXConstructorArgs implicitArgs;
87 for (const auto &arg : addedArgs.Prefix) {
88 implicitArgs.Prefix.push_back(arg.Value);
89 }
90 for (const auto &arg : addedArgs.Suffix) {
91 implicitArgs.Suffix.push_back(arg.Value);
92 }
93 return implicitArgs;
96llvm::FunctionType *
98 assert(FD != nullptr && "Expected a non-null function declaration!");
99 llvm::Type *T = CGM.getTypes().ConvertType(FD->getType());
101 if (auto FT = dyn_cast<llvm::FunctionType>(T))
102 return FT;
104 return nullptr;
107llvm::Type *
109 return CGM.getTypes().ConvertTypeForMem(T);
113 const RecordDecl *RD,
114 const FieldDecl *FD) {
115 return CGM.getTypes().getCGRecordLayout(RD).getLLVMFieldNo(FD);
119 CodeGenModule &CGM, llvm::BasicBlock *InsertBlock,
120 llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D,
121 CXXDtorType Type, bool ForVirtualBase, bool Delegating) {
122 CodeGenFunction CGF(CGM, /*suppressNewContext=*/true);
123 CGF.CurCodeDecl = D;
124 CGF.CurFuncDecl = D;
125 CGF.CurFn = InsertBlock->getParent();
126 CGF.Builder.SetInsertPoint(InsertBlock, InsertPoint);
128 CGF, D, Type, ForVirtualBase, Delegating);
const Decl * D
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:65
virtual llvm::Value * getCXXDestructorImplicitParam(CodeGenFunction &CGF, const CXXDestructorDecl *DD, CXXDtorType Type, bool ForVirtualBase, bool Delegating)=0
Get the implicit (second) parameter that comes after the "this" pointer, or nullptr if there is isn't...
virtual AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating)=0
CGFunctionInfo - Class to encapsulate the information about a function definition.
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
This class organizes the cross-function state that is used while generating LLVM code.
CGCXXABI & getCXXABI() const
void addDefaultFunctionDefinitionAttributes(llvm::AttrBuilder &attrs)
Like the overload taking a Function &, but intended specifically for frontends that want to build on ...
Definition: CGCall.cpp:2158
const CGFunctionInfo & arrangeCXXMethodType(const CXXRecordDecl *RD, const FunctionProtoType *FTP, const CXXMethodDecl *MD)
Arrange the argument and result information for a call to an unknown C++ non-static member function o...
Definition: CGCall.cpp:279
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
const CGFunctionInfo & arrangeLLVMFunctionInfo(CanQualType returnType, FnInfoOpts opts, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args)
"Arrange" the LLVM information for a call or type with the given signature.
Definition: CGCall.cpp:766
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty)
Arrange the argument and result information for a value of the given freestanding function type.
Definition: CGCall.cpp:206
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
const CGFunctionInfo & arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD, QualType receiverType)
Arrange the argument and result information for the function type through which to perform a send to ...
Definition: CGCall.cpp:500
A class for recording the number of arguments that a function signature requires.
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Represents a function declaration or definition.
Definition: Decl.h:1932
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4971
A class which abstracts out some details necessary for making a call.
Definition: Type.h:4386
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
A (possibly-)qualified type.
Definition: Type.h:942
Represents a struct/union/class.
Definition: Decl.h:4141
The base class of the type hierarchy.
Definition: Type.h:1826
QualType getType() const
Definition: Decl.h:678
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)
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...
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)
const CGFunctionInfo & arrangeFreeFunctionCall(CodeGenModule &CGM, CanQualType returnType, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, RequiredArgs args)
llvm::FunctionType * convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD)
Returns null if the function type is incomplete and can't be lowered.
ImplicitCXXConstructorArgs getImplicitCXXConstructorArgs(CodeGenModule &CGM, const CXXConstructorDecl *D)
Returns the implicit arguments to add to a complete, non-delegating C++ constructor call.
The JSON file list parser is used to communicate input to InstallAPI.
@ Ctor_Complete
Complete object ctor.
Definition: ABI.h:25
C++ destructor types.
Definition: ABI.h:33
const FunctionProtoType * T
Additional implicit arguments to add to the beginning (Prefix) and end (Suffix) of a constructor / de...
Definition: CGCXXABI.h:330
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.