clang 20.0.0git
CodeGenABITypes.cpp
Go to the documentation of this file.
1//==--- CodeGenABITypes.cpp - 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//===----------------------------------------------------------------------===//
17
19#include "CGCXXABI.h"
20#include "CGRecordLayout.h"
21#include "CodeGenFunction.h"
22#include "CodeGenModule.h"
24
25using namespace clang;
26using namespace CodeGen;
27
29 llvm::AttrBuilder &attrs) {
31}
32
33const CGFunctionInfo &
35 const ObjCMethodDecl *MD,
36 QualType receiverType) {
37 return CGM.getTypes().arrangeObjCMessageSendSignature(MD, receiverType);
38}
39
40const CGFunctionInfo &
43 return CGM.getTypes().arrangeFreeFunctionType(Ty);
44}
45
46const CGFunctionInfo &
49 return CGM.getTypes().arrangeFreeFunctionType(Ty);
50}
51
52const CGFunctionInfo &
54 const CXXRecordDecl *RD,
55 const FunctionProtoType *FTP,
56 const CXXMethodDecl *MD) {
57 return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD);
58}
59
61 CodeGenModule &CGM, CanQualType returnType, ArrayRef<CanQualType> argTypes,
64 RequiredArgs args) {
66 returnType, FnInfoOpts::IsInstanceMethod, argTypes, info, paramInfos,
67 args);
68}
69
71 CodeGenModule &CGM, CanQualType returnType, ArrayRef<CanQualType> argTypes,
74 RequiredArgs args) {
76 returnType, FnInfoOpts::None, argTypes, info, paramInfos, args);
77}
78
81 const CXXConstructorDecl *D) {
82 // We have to create a dummy CodeGenFunction here to pass to
83 // getImplicitConstructorArgs(). In some cases (base and delegating
84 // constructor calls), getImplicitConstructorArgs() can reach into the
85 // CodeGenFunction to find parameters of the calling constructor to pass on to
86 // the called constructor, but that can't happen here because we're asking for
87 // the args for a complete, non-delegating constructor call.
88 CodeGenFunction CGF(CGM, /* suppressNewContext= */ true);
91 /* ForVirtualBase= */ false,
92 /* Delegating= */ false);
93 ImplicitCXXConstructorArgs implicitArgs;
94 for (const auto &arg : addedArgs.Prefix) {
95 implicitArgs.Prefix.push_back(arg.Value);
96 }
97 for (const auto &arg : addedArgs.Suffix) {
98 implicitArgs.Suffix.push_back(arg.Value);
99 }
100 return implicitArgs;
101}
102
103llvm::FunctionType *
105 assert(FD != nullptr && "Expected a non-null function declaration!");
106 llvm::Type *T = CGM.getTypes().ConvertType(FD->getType());
107
108 if (auto FT = dyn_cast<llvm::FunctionType>(T))
109 return FT;
110
111 return nullptr;
112}
113
114llvm::Type *
116 return CGM.getTypes().ConvertTypeForMem(T);
117}
118
120 const RecordDecl *RD,
121 const FieldDecl *FD) {
122 return CGM.getTypes().getCGRecordLayout(RD).getLLVMFieldNo(FD);
123}
124
126 CodeGenModule &CGM, llvm::BasicBlock *InsertBlock,
127 llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D,
128 CXXDtorType Type, bool ForVirtualBase, bool Delegating) {
129 CodeGenFunction CGF(CGM, /*suppressNewContext=*/true);
130 CGF.CurCodeDecl = D;
131 CGF.CurFuncDecl = D;
132 CGF.CurFn = InsertBlock->getParent();
133 CGF.Builder.SetInsertPoint(InsertBlock, InsertPoint);
135 CGF, D, Type, ForVirtualBase, Delegating);
136}
const Decl * D
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2553
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2817
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:66
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:2159
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:765
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:499
A class for recording the number of arguments that a function signature requires.
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Represents a function declaration or definition.
Definition: Decl.h:1935
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
A class which abstracts out some details necessary for making a call.
Definition: Type.h:4432
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
A (possibly-)qualified type.
Definition: Type.h:929
Represents a struct/union/class.
Definition: Decl.h:4148
The base class of the type hierarchy.
Definition: Type.h:1828
QualType getType() const
Definition: Decl.h:682
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)
const CGFunctionInfo & arrangeFreeFunctionCall(CodeGenModule &CGM, CanQualType returnType, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args)
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)
llvm::FunctionType * convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD)
Returns null if the function type is incomplete and can't be lowered.
const CGFunctionInfo & arrangeCXXMethodCall(CodeGenModule &CGM, CanQualType returnType, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, ArrayRef< FunctionProtoType::ExtParameterInfo > paramInfos, RequiredArgs args)
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
CXXDtorType
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.