From 6bcf2ba2f0fff179602fd60b5e0127cd20fc907e Mon Sep 17 00:00:00 2001 From: Alexander Richardson Date: Thu, 23 Aug 2018 09:25:17 +0000 Subject: Allow creating llvm::Function in non-zero address spaces Most users won't have to worry about this as all of the 'getOrInsertFunction' functions on Module will default to the program address space. An overload has been added to Function::Create to abstract away the details for most callers. This is based on https://reviews.llvm.org/D37054 but without the changes to make passing a Module to Function::Create() mandatory. I have also added some more tests and fixed the LLParser to accept call instructions for types in the program address space. Reviewed By: bjope Differential Revision: https://reviews.llvm.org/D47541 llvm-svn: 340519 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index c45b441..48a9597 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2938,7 +2938,7 @@ Error BitcodeReader::parseGlobalVarRecord(ArrayRef Record) { Error BitcodeReader::parseFunctionRecord(ArrayRef Record) { // v1: [type, callingconv, isproto, linkage, paramattr, alignment, section, // visibility, gc, unnamed_addr, prologuedata, dllstorageclass, comdat, - // prefixdata, personalityfn, preemption specifier] (name in VST) + // prefixdata, personalityfn, preemption specifier, addrspace] (name in VST) // v2: [strtab_offset, strtab_size, v1] StringRef Name; std::tie(Name, Record) = readNameFromStrtab(Record); @@ -2957,8 +2957,12 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef Record) { if (CC & ~CallingConv::MaxID) return error("Invalid calling convention ID"); - Function *Func = - Function::Create(FTy, GlobalValue::ExternalLinkage, Name, TheModule); + unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace(); + if (Record.size() > 16) + AddrSpace = Record[16]; + + Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage, + AddrSpace, Name, TheModule); Func->setCallingConv(CC); bool isProto = Record[2]; -- cgit v1.1