clang 17.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"
26
27using namespace clang;
28using namespace CodeGen;
29
31 llvm::AttrBuilder &attrs) {
33}
34
35const CGFunctionInfo &
37 const ObjCMethodDecl *MD,
38 QualType receiverType) {
39 return CGM.getTypes().arrangeObjCMessageSendSignature(MD, receiverType);
40}
41
42const CGFunctionInfo &
45 return CGM.getTypes().arrangeFreeFunctionType(Ty);
46}
47
48const CGFunctionInfo &
51 return CGM.getTypes().arrangeFreeFunctionType(Ty);
52}
53
54const CGFunctionInfo &
56 const CXXRecordDecl *RD,
57 const FunctionProtoType *FTP,
58 const CXXMethodDecl *MD) {
59 return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD);
60}
61
62const CGFunctionInfo &
64 CanQualType returnType,
65 ArrayRef<CanQualType> argTypes,
67 RequiredArgs args) {
69 returnType, /*instanceMethod=*/false, /*chainCall=*/false, argTypes,
70 info, {}, args);
71}
72
75 const CXXConstructorDecl *D) {
76 // We have to create a dummy CodeGenFunction here to pass to
77 // getImplicitConstructorArgs(). In some cases (base and delegating
78 // constructor calls), getImplicitConstructorArgs() can reach into the
79 // CodeGenFunction to find parameters of the calling constructor to pass on to
80 // the called constructor, but that can't happen here because we're asking for
81 // the args for a complete, non-delegating constructor call.
82 CodeGenFunction CGF(CGM, /* suppressNewContext= */ true);
85 /* ForVirtualBase= */ false,
86 /* Delegating= */ false);
87 ImplicitCXXConstructorArgs implicitArgs;
88 for (const auto &arg : addedArgs.Prefix) {
89 implicitArgs.Prefix.push_back(arg.Value);
90 }
91 for (const auto &arg : addedArgs.Suffix) {
92 implicitArgs.Suffix.push_back(arg.Value);
93 }
94 return implicitArgs;
95}
96
97llvm::FunctionType *
99 assert(FD != nullptr && "Expected a non-null function declaration!");
100 llvm::Type *T = CGM.getTypes().ConvertType(FD->getType());
101
102 if (auto FT = dyn_cast<llvm::FunctionType>(T))
103 return FT;
104
105 return nullptr;
106}
107
108llvm::Type *
110 return CGM.getTypes().ConvertTypeForMem(T);
111}
112
114 const RecordDecl *RD,
115 const FieldDecl *FD) {
116 return CGM.getTypes().getCGRecordLayout(RD).getLLVMFieldNo(FD);
117}
118
120 CodeGenModule &CGM, llvm::BasicBlock *InsertBlock,
121 llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D,
122 CXXDtorType Type, bool ForVirtualBase, bool Delegating) {
123 CodeGenFunction CGF(CGM, /*suppressNewContext=*/true);
124 CGF.CurCodeDecl = D;
125 CGF.CurFuncDecl = D;
126 CGF.CurFn = InsertBlock->getParent();
127 CGF.Builder.SetInsertPoint(InsertBlock, InsertPoint);
129 CGF, D, Type, ForVirtualBase, Delegating);
130}
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2451
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2715
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1995
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
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::Function &F)
Adds attributes to F according to our CodeGenOptions and LangOptions, as though we had emitted it our...
Definition: CGCall.cpp:1986
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:264
const CGFunctionInfo & arrangeLLVMFunctionInfo(CanQualType returnType, bool instanceMethod, bool chainCall, 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:753
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty)
Arrange the argument and result information for a value of the given freestanding function type.
Definition: CGCall.cpp:200
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
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:485
A class for recording the number of arguments that a function signature requires.
Represents a member of a struct/union/class.
Definition: Decl.h:2943
Represents a function declaration or definition.
Definition: Decl.h:1919
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4027
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3791
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:138
A (possibly-)qualified type.
Definition: Type.h:736
Represents a struct/union/class.
Definition: Decl.h:3996
The base class of the type hierarchy.
Definition: Type.h:1566
QualType getType() const
Definition: Decl.h:714
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.
@ Ctor_Complete
Complete object ctor.
Definition: ABI.h:25
CXXDtorType
C++ destructor types.
Definition: ABI.h:33
Additional implicit arguments to add to the beginning (Prefix) and end (Suffix) of a constructor / de...
Definition: CGCXXABI.h:325
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.