summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorYaxun Liu <Yaxun.Liu@amd.com>2018-01-30 22:32:39 +0000
committerYaxun Liu <Yaxun.Liu@amd.com>2018-01-30 22:32:39 +0000
commitc00d81e6977cc98e0eea33d58847ffb17223635a (patch)
treea138da7f22a4cf264b9234f094b68c27cf6415ab /llvm/lib
parent4ec0d9c1b7e221524a834d9ddfb5f47b36e2ecb8 (diff)
downloadbcm5719-llvm-c00d81e6977cc98e0eea33d58847ffb17223635a.tar.gz
bcm5719-llvm-c00d81e6977cc98e0eea33d58847ffb17223635a.zip
LLParser: add an argument for overriding data layout and do not check alloca addr space
Sometimes users do not specify data layout in LLVM assembly and let llc set the data layout by target triple after loading the LLVM assembly. Currently the parser checks alloca address space no matter whether the LLVM assembly contains data layout definition, which causes false alarm since the default data layout does not contain the correct alloca address space. The parser also calls verifier to check debug info and updating invalid debug info. Currently there is no way to let the verifier to check debug info only. If the verifier finds non-debug-info issues the parser will fail. For llc, the fix is to remove the check of alloca addr space in the parser and disable updating debug info, and defer the updating of debug info and verification to be after setting data layout of the IR by target. For other llvm tools, since they do not override data layout by target but instead can override data layout by a command line option, an argument for overriding data layout is added to the parser. In cases where data layout overriding is necessary for the parser, the data layout can be provided by command line. Differential Revision: https://reviews.llvm.org/D41832 llvm-svn: 323826
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp12
-rw-r--r--llvm/lib/AsmParser/LLParser.h11
-rw-r--r--llvm/lib/AsmParser/Parser.cpp35
-rw-r--r--llvm/lib/CodeGen/MIRParser/MIRParser.cpp2
-rw-r--r--llvm/lib/IRReader/IRReader.cpp13
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);
}
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud