clang  14.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 
27 using namespace clang;
28 using namespace CodeGen;
29 
31  llvm::AttrBuilder &attrs) {
33 }
34 
35 const CGFunctionInfo &
37  const ObjCMethodDecl *MD,
38  QualType receiverType) {
39  return CGM.getTypes().arrangeObjCMessageSendSignature(MD, receiverType);
40 }
41 
42 const CGFunctionInfo &
45  return CGM.getTypes().arrangeFreeFunctionType(Ty);
46 }
47 
48 const CGFunctionInfo &
51  return CGM.getTypes().arrangeFreeFunctionType(Ty);
52 }
53 
54 const CGFunctionInfo &
56  const CXXRecordDecl *RD,
57  const FunctionProtoType *FTP,
58  const CXXMethodDecl *MD) {
59  return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD);
60 }
61 
62 const CGFunctionInfo &
64  CanQualType returnType,
65  ArrayRef<CanQualType> argTypes,
67  RequiredArgs args) {
68  return CGM.getTypes().arrangeLLVMFunctionInfo(
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);
83  CGCXXABI::AddedStructorArgs addedArgs =
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 
97 llvm::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 
108 llvm::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 }
clang::CXXConstructorDecl
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2401
CodeGenFunction.h
clang::CodeGen::convertFreeFunctionType
llvm::FunctionType * convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD)
Returns null if the function type is incomplete and can't be lowered.
Definition: CodeGenABITypes.cpp:98
clang::CodeGen::CodeGenFunction::CurCodeDecl
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
Definition: CodeGenFunction.h:327
clang::CodeGen::CGCXXABI::AddedStructorArgs
Additional implicit arguments to add to the beginning (Prefix) and end (Suffix) of a constructor / de...
Definition: CGCXXABI.h:299
CGRecordLayout.h
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::FieldDecl
Represents a member of a struct/union/class.
Definition: Decl.h:2835
clang::CodeGen::arrangeFreeFunctionCall
const CGFunctionInfo & arrangeFreeFunctionCall(CodeGenModule &CGM, CanQualType returnType, ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, RequiredArgs args)
Definition: CodeGenABITypes.cpp:63
clang::Ctor_Complete
@ Ctor_Complete
Complete object ctor.
Definition: ABI.h:25
clang::CodeGen::CodeGenTypes::arrangeObjCMessageSendSignature
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:475
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:274
CodeGenABITypes.h
clang::CodeGen::CodeGenTypes::ConvertType
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:395
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
clang::CodeGen::CodeGenTypes::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T, bool ForBitField=false)
ConvertTypeForMem - Convert type T into a llvm::Type.
Definition: CodeGenTypes.cpp:90
clang::CodeGen::CGCXXABI::getImplicitConstructorArgs
virtual AddedStructorArgs getImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating)=0
HeaderSearchOptions.h
clang::CodeGen::CodeGenTypes::arrangeLLVMFunctionInfo
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:741
clang::CodeGen::ImplicitCXXConstructorArgs::Suffix
SmallVector< llvm::Value *, 1 > Suffix
Implicit arguments to add after the explicit arguments.
Definition: CodeGenABITypes.h:67
CGFunctionInfo.h
clang::CXXDtorType
CXXDtorType
C++ destructor types.
Definition: ABI.h:33
clang::CodeGen::getLLVMFieldNumber
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...
Definition: CodeGenABITypes.cpp:113
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2668
clang::CodeGen::CGRecordLayout::getLLVMFieldNo
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
Definition: CGRecordLayout.h:197
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:726
clang::CodeGen::convertTypeForMemory
llvm::Type * convertTypeForMemory(CodeGenModule &CGM, QualType T)
Definition: CodeGenABITypes.cpp:109
clang::CanQual< FunctionProtoType >
CodeGenModule.h
clang::CodeGen::CodeGenTypes::getCGRecordLayout
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
Definition: CodeGenTypes.cpp:875
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
clang::CodeGen::CodeGenTypes::arrangeCXXMethodType
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:255
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:235
clang::CodeGen::RequiredArgs
A class for recording the number of arguments that a function signature requires.
Definition: CGFunctionInfo.h:480
clang::CodeGen::CodeGenModule::getCXXABI
CGCXXABI & getCXXABI() const
Definition: CodeGenModule.h:719
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3885
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:284
llvm::ArrayRef
Definition: LLVM.h:34
Value
Value
Definition: UninitializedValues.cpp:102
clang::CodeGen::CGCXXABI::AddedStructorArgs::Suffix
SmallVector< Arg, 1 > Suffix
Definition: CGCXXABI.h:305
clang::CodeGen::CodeGenModule::addDefaultFunctionDefinitionAttributes
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:1905
clang::FunctionType::ExtInfo
A class which abstracts out some details necessary for making a call.
Definition: Type.h:3657
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
CGCXXABI.h
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::CodeGen::arrangeCXXMethodType
const CGFunctionInfo & arrangeCXXMethodType(CodeGenModule &CGM, const CXXRecordDecl *RD, const FunctionProtoType *FTP, const CXXMethodDecl *MD)
Definition: CodeGenABITypes.cpp:55
clang::CodeGen::CGCXXABI::getCXXDestructorImplicitParam
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...
clang::CodeGen::arrangeFreeFunctionType
const CGFunctionInfo & arrangeFreeFunctionType(CodeGenModule &CGM, CanQual< FunctionProtoType > Ty)
Definition: CodeGenABITypes.cpp:43
clang::CodeGen::CodeGenFunction::CurFn
llvm::Function * CurFn
Definition: CodeGenFunction.h:330
clang
Definition: CalledOnceCheck.h:17
std::arg
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
Definition: complex_cmath.h:40
clang::CodeGen::ImplicitCXXConstructorArgs::Prefix
SmallVector< llvm::Value *, 1 > Prefix
Implicit arguments to add before the explicit arguments, but after the *this argument (which always c...
Definition: CodeGenABITypes.h:64
clang::CodeGen::arrangeObjCMessageSendSignature
const CGFunctionInfo & arrangeObjCMessageSendSignature(CodeGenModule &CGM, const ObjCMethodDecl *MD, QualType receiverType)
Definition: CodeGenABITypes.cpp:36
clang::CodeGen::CodeGenTypes::arrangeFreeFunctionType
const CGFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > Ty)
Arrange the argument and result information for a value of the given freestanding function type.
Definition: CGCall.cpp:197
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:687
PreprocessorOptions.h
clang::CodeGen::getCXXDestructorImplicitParam
llvm::Value * getCXXDestructorImplicitParam(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, llvm::BasicBlock::iterator InsertPoint, const CXXDestructorDecl *D, CXXDtorType Type, bool ForVirtualBase, bool Delegating)
Definition: CodeGenABITypes.cpp:119
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1856
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3859
clang::CodeGen::ImplicitCXXConstructorArgs
Additional implicit arguments to add to a constructor argument list.
Definition: CodeGenABITypes.h:61
clang::CodeGen::getImplicitCXXConstructorArgs
ImplicitCXXConstructorArgs getImplicitCXXConstructorArgs(CodeGenModule &CGM, const CXXConstructorDecl *D)
Returns the implicit arguments to add to a complete, non-delegating C++ constructor call.
Definition: CodeGenABITypes.cpp:74
clang::CodeGen::addDefaultFunctionDefinitionAttributes
void addDefaultFunctionDefinitionAttributes(CodeGenModule &CGM, llvm::AttrBuilder &attrs)
Given the language and code-generation options that Clang was configured with, set the default LLVM I...
Definition: CodeGenABITypes.cpp:30
clang::CodeGen::CGCXXABI::AddedStructorArgs::Prefix
SmallVector< Arg, 1 > Prefix
Definition: CGCXXABI.h:304
clang::CodeGen::CodeGenFunction::CurFuncDecl
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
Definition: CodeGenFunction.h:325
clang::CXXMethodDecl
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1948