1 //==--- CodeGenABITypes.cpp - Convert Clang types to LLVM types for ABI ----==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // CodeGenABITypes is a simple interface for getting LLVM types for 11 // the parameters and the return value of a function given the Clang 12 // types. 13 // 14 // The class is implemented as a public wrapper around the private 15 // CodeGenTypes class in lib/CodeGen. 16 // 17 //===----------------------------------------------------------------------===// 18 19 #include "clang/CodeGen/CodeGenABITypes.h" 20 #include "CGRecordLayout.h" 21 #include "CodeGenModule.h" 22 #include "clang/CodeGen/CGFunctionInfo.h" 23 #include "clang/Frontend/CodeGenOptions.h" 24 #include "clang/Lex/HeaderSearchOptions.h" 25 #include "clang/Lex/PreprocessorOptions.h" 26 27 using namespace clang; 28 using namespace CodeGen; 29 30 const CGFunctionInfo & 31 CodeGen::arrangeObjCMessageSendSignature(CodeGenModule &CGM, 32 const ObjCMethodDecl *MD, 33 QualType receiverType) { 34 return CGM.getTypes().arrangeObjCMessageSendSignature(MD, receiverType); 35 } 36 37 const CGFunctionInfo & 38 CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM, 39 CanQual<FunctionProtoType> Ty, 40 const FunctionDecl *FD) { 41 return CGM.getTypes().arrangeFreeFunctionType(Ty, FD); 42 } 43 44 const CGFunctionInfo & 45 CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM, 46 CanQual<FunctionNoProtoType> Ty) { 47 return CGM.getTypes().arrangeFreeFunctionType(Ty); 48 } 49 50 const CGFunctionInfo & 51 CodeGen::arrangeCXXMethodType(CodeGenModule &CGM, 52 const CXXRecordDecl *RD, 53 const FunctionProtoType *FTP, 54 const CXXMethodDecl *MD) { 55 return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD); 56 } 57 58 const CGFunctionInfo & 59 CodeGen::arrangeFreeFunctionCall(CodeGenModule &CGM, 60 CanQualType returnType, 61 ArrayRef<CanQualType> argTypes, 62 FunctionType::ExtInfo info, 63 RequiredArgs args) { 64 return CGM.getTypes().arrangeLLVMFunctionInfo( 65 returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes, 66 info, {}, args); 67 } 68 69 llvm::FunctionType * 70 CodeGen::convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD) { 71 assert(FD != nullptr && "Expected a non-null function declaration!"); 72 llvm::Type *T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD); 73 74 if (auto FT = dyn_cast<llvm::FunctionType>(T)) 75 return FT; 76 77 return nullptr; 78 } 79 80 llvm::Type * 81 CodeGen::convertTypeForMemory(CodeGenModule &CGM, QualType T) { 82 return CGM.getTypes().ConvertTypeForMem(T); 83 } 84 85 unsigned CodeGen::getLLVMFieldNumber(CodeGenModule &CGM, 86 const RecordDecl *RD, 87 const FieldDecl *FD) { 88 return CGM.getTypes().getCGRecordLayout(RD).getLLVMFieldNo(FD); 89 } 90