diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/AsmParser/LLParser.h | 11 | ||||
-rw-r--r-- | llvm/lib/AsmParser/Parser.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/IRReader/IRReader.cpp | 13 |
5 files changed, 41 insertions, 32 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 9bc34f927e8..226e4827968 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -327,7 +327,8 @@ bool LLParser::ParseTargetDefinition() { if (ParseToken(lltok::equal, "expected '=' after target datalayout") || ParseStringConstant(Str)) return true; - M->setDataLayout(Str); + if (DataLayoutStr.empty()) + M->setDataLayout(Str); return false; } } @@ -6261,14 +6262,7 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) { if (Size && !Size->getType()->isIntegerTy()) return Error(SizeLoc, "element count must have integer type"); - const DataLayout &DL = M->getDataLayout(); - unsigned AS = DL.getAllocaAddrSpace(); - if (AS != AddrSpace) { - // TODO: In the future it should be possible to specify addrspace per-alloca. - return Error(ASLoc, "address space must match datalayout"); - } - - AllocaInst *AI = new AllocaInst(Ty, AS, Size, Alignment); + AllocaInst *AI = new AllocaInst(Ty, AddrSpace, Size, Alignment); AI->setUsedWithInAlloca(IsInAlloca); AI->setSwiftError(IsSwiftError); Inst = AI; diff --git a/llvm/lib/AsmParser/LLParser.h b/llvm/lib/AsmParser/LLParser.h index 94e4c1ae96d..a3252ff5f19 100644 --- a/llvm/lib/AsmParser/LLParser.h +++ b/llvm/lib/AsmParser/LLParser.h @@ -143,12 +143,19 @@ namespace llvm { /// UpgradeDebuginfo so it can generate broken bitcode. bool UpgradeDebugInfo; + /// DataLayout string to override that in LLVM assembly. + StringRef DataLayoutStr; + public: LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, - SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true) + SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true, + StringRef DataLayoutString = "") : Context(M->getContext()), Lex(F, SM, Err, M->getContext()), M(M), Slots(Slots), BlockAddressPFS(nullptr), - UpgradeDebugInfo(UpgradeDebugInfo) {} + UpgradeDebugInfo(UpgradeDebugInfo), DataLayoutStr(DataLayoutString) { + if (!DataLayoutStr.empty()) + M->setDataLayout(DataLayoutStr); + } bool Run(); bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots); diff --git a/llvm/lib/AsmParser/Parser.cpp b/llvm/lib/AsmParser/Parser.cpp index a43ae2b5577..37b97a17a53 100644 --- a/llvm/lib/AsmParser/Parser.cpp +++ b/llvm/lib/AsmParser/Parser.cpp @@ -23,31 +23,34 @@ using namespace llvm; bool llvm::parseAssemblyInto(MemoryBufferRef F, Module &M, SMDiagnostic &Err, - SlotMapping *Slots, bool UpgradeDebugInfo) { + SlotMapping *Slots, bool UpgradeDebugInfo, + StringRef DataLayoutString) { SourceMgr SM; std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F); SM.AddNewSourceBuffer(std::move(Buf), SMLoc()); - return LLParser(F.getBuffer(), SM, Err, &M, Slots, UpgradeDebugInfo).Run(); + return LLParser(F.getBuffer(), SM, Err, &M, Slots, UpgradeDebugInfo, + DataLayoutString) + .Run(); } std::unique_ptr<Module> llvm::parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, - SlotMapping *Slots, bool UpgradeDebugInfo) { + SlotMapping *Slots, bool UpgradeDebugInfo, + StringRef DataLayoutString) { std::unique_ptr<Module> M = make_unique<Module>(F.getBufferIdentifier(), Context); - if (parseAssemblyInto(F, *M, Err, Slots, UpgradeDebugInfo)) + if (parseAssemblyInto(F, *M, Err, Slots, UpgradeDebugInfo, DataLayoutString)) return nullptr; return M; } -std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename, - SMDiagnostic &Err, - LLVMContext &Context, - SlotMapping *Slots, - bool UpgradeDebugInfo) { +std::unique_ptr<Module> +llvm::parseAssemblyFile(StringRef Filename, SMDiagnostic &Err, + LLVMContext &Context, SlotMapping *Slots, + bool UpgradeDebugInfo, StringRef DataLayoutString) { ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename); if (std::error_code EC = FileOrErr.getError()) { @@ -57,16 +60,16 @@ std::unique_ptr<Module> llvm::parseAssemblyFile(StringRef Filename, } return parseAssembly(FileOrErr.get()->getMemBufferRef(), Err, Context, Slots, - UpgradeDebugInfo); + UpgradeDebugInfo, DataLayoutString); } -std::unique_ptr<Module> llvm::parseAssemblyString(StringRef AsmString, - SMDiagnostic &Err, - LLVMContext &Context, - SlotMapping *Slots, - bool UpgradeDebugInfo) { +std::unique_ptr<Module> +llvm::parseAssemblyString(StringRef AsmString, SMDiagnostic &Err, + LLVMContext &Context, SlotMapping *Slots, + bool UpgradeDebugInfo, StringRef DataLayoutString) { MemoryBufferRef F(AsmString, "<string>"); - return parseAssembly(F, Err, Context, Slots, UpgradeDebugInfo); + return parseAssembly(F, Err, Context, Slots, UpgradeDebugInfo, + DataLayoutString); } Constant *llvm::parseConstantValue(StringRef Asm, SMDiagnostic &Err, diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp index e4e3fbbd75d..52ac08cd2d3 100644 --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -237,7 +237,7 @@ std::unique_ptr<Module> MIRParserImpl::parseIRModule() { dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) { SMDiagnostic Error; M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error, - Context, &IRSlots); + Context, &IRSlots, /*UpgradeDebugInfo=*/false); if (!M) { reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange())); return nullptr; diff --git a/llvm/lib/IRReader/IRReader.cpp b/llvm/lib/IRReader/IRReader.cpp index 999f11deb15..36bbf719bb6 100644 --- a/llvm/lib/IRReader/IRReader.cpp +++ b/llvm/lib/IRReader/IRReader.cpp @@ -68,7 +68,8 @@ std::unique_ptr<Module> llvm::getLazyIRFileModule(StringRef Filename, std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, LLVMContext &Context, - bool UpgradeDebugInfo) { + bool UpgradeDebugInfo, + StringRef DataLayoutString) { NamedRegionTimer T(TimeIRParsingName, TimeIRParsingDescription, TimeIRParsingGroupName, TimeIRParsingGroupDescription, TimePassesIsEnabled); @@ -83,15 +84,19 @@ std::unique_ptr<Module> llvm::parseIR(MemoryBufferRef Buffer, SMDiagnostic &Err, }); return nullptr; } + if (!DataLayoutString.empty()) + ModuleOrErr.get()->setDataLayout(DataLayoutString); return std::move(ModuleOrErr.get()); } - return parseAssembly(Buffer, Err, Context, nullptr, UpgradeDebugInfo); + return parseAssembly(Buffer, Err, Context, nullptr, UpgradeDebugInfo, + DataLayoutString); } std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, LLVMContext &Context, - bool UpgradeDebugInfo) { + bool UpgradeDebugInfo, + StringRef DataLayoutString) { ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename); if (std::error_code EC = FileOrErr.getError()) { @@ -101,7 +106,7 @@ std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err, } return parseIR(FileOrErr.get()->getMemBufferRef(), Err, Context, - UpgradeDebugInfo); + UpgradeDebugInfo, DataLayoutString); } //===----------------------------------------------------------------------===// |