aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2013-06-25 14:10:05 -0700
committerMark Seaborn <mseaborn@chromium.org>2013-06-25 14:10:05 -0700
commit35d0901ac239469021a36f21e488cf20484f2095 (patch)
treee071c53b6a03c913cc7a37ad4df84c49ac733a9e
parente93df18eccc8d9cad27853b805a5a22b124b416d (diff)
PNaCl wire format: Remove the top-level DATALAYOUT record
PNaCl only supports a fixed data layout, so treat this as implicit in the pexe file. Add the data layout field back at read time, to prevent accidentally using any architecture-specific backend data layout when translating, and to ensure that any IR passes that use the data layout work correctly. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3505 TEST=*.ll tests + PNaCl toolchain trybots Review URL: https://codereview.chromium.org/17591014
-rw-r--r--include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h2
-rw-r--r--lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp17
-rw-r--r--lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp3
-rw-r--r--test/NaCl/Bitcode/implicit-datalayout.ll9
4 files changed, 20 insertions, 11 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
index 1c4d80efba..0f3755abba 100644
--- a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
+++ b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h
@@ -51,7 +51,7 @@ namespace naclbitc {
enum NaClModuleCodes {
MODULE_CODE_VERSION = 1, // VERSION: [version#]
MODULE_CODE_TRIPLE = 2, // Not used in PNaCl
- MODULE_CODE_DATALAYOUT = 3, // DATALAYOUT: [strchr x N]
+ MODULE_CODE_DATALAYOUT = 3, // Not used in PNaCl
MODULE_CODE_ASM = 4, // ASM: [strchr x N]
MODULE_CODE_SECTIONNAME = 5, // SECTIONNAME: [strchr x N]
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
index 8fe6274a15..bd6ddcb020 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp
@@ -1477,13 +1477,6 @@ bool NaClBitcodeReader::ParseModule(bool Resume) {
}
break;
}
- case naclbitc::MODULE_CODE_DATALAYOUT: { // DATALAYOUT: [strchr x N]
- std::string S;
- if (ConvertToString(Record, 0, S))
- return Error("Invalid MODULE_CODE_DATALAYOUT record");
- TheModule->setDataLayout(S);
- break;
- }
case naclbitc::MODULE_CODE_ASM: { // ASM: [strchr x N]
std::string S;
if (ConvertToString(Record, 0, S))
@@ -1630,6 +1623,16 @@ bool NaClBitcodeReader::ParseModule(bool Resume) {
bool NaClBitcodeReader::ParseBitcodeInto(Module *M) {
TheModule = 0;
+ // PNaCl does not support different DataLayouts in pexes, so we
+ // implicitly set the DataLayout to the following default.
+ //
+ // This is not usually needed by the backend, but it might be used
+ // by IR passes that the PNaCl translator runs. We set this in the
+ // reader rather than in pnacl-llc so that 'opt' will also use the
+ // correct DataLayout if it is run on a pexe.
+ M->setDataLayout("e-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"
+ "f32:32:32-f64:64:64-p:32:32:32-v128:32:32");
+
if (InitStream()) return true;
// We expect a number of well-defined blocks, though we don't necessarily
diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
index bf1faa463d..7afcf666dc 100644
--- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
+++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp
@@ -431,9 +431,6 @@ static void WriteModuleInfo(const Module *M, const NaClValueEnumerator &VE,
NaClBitstreamWriter &Stream) {
DEBUG(dbgs() << "-> WriteModuleInfo\n");
// Emit various pieces of data attached to a module.
- if (!M->getDataLayout().empty())
- WriteStringRecord(naclbitc::MODULE_CODE_DATALAYOUT, M->getDataLayout(),
- 0/*TODO*/, Stream);
if (!M->getModuleInlineAsm().empty())
WriteStringRecord(naclbitc::MODULE_CODE_ASM, M->getModuleInlineAsm(),
0/*TODO*/, Stream);
diff --git a/test/NaCl/Bitcode/implicit-datalayout.ll b/test/NaCl/Bitcode/implicit-datalayout.ll
new file mode 100644
index 0000000000..5a957dffec
--- /dev/null
+++ b/test/NaCl/Bitcode/implicit-datalayout.ll
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | pnacl-freeze | pnacl-thaw - | llvm-dis - | FileCheck %s
+
+; The "datalayout" field is considered to be implicit in the pexe. It
+; is not stored in the pexe; the reader adds it implicitly.
+;
+; The most important parts of the datalayout for PNaCl are the pointer
+; size and the endianness ("e" for little endian).
+
+; CHECK: target datalayout = "e{{.*}}p:32:32:32{{.*}}"