diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 6 | ||||
-rw-r--r-- | lib/IR/AsmWriter.cpp | 5 | ||||
-rw-r--r-- | lib/IR/Core.cpp | 2 | ||||
-rw-r--r-- | lib/IR/DataLayout.cpp | 8 | ||||
-rw-r--r-- | lib/IR/Module.cpp | 28 | ||||
-rw-r--r-- | lib/Linker/LinkModules.cpp | 4 |
6 files changed, 42 insertions, 11 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 1d763d66dd..718cd12389 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -530,9 +530,9 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, if (!M->getTargetTriple().empty()) WriteStringRecord(bitc::MODULE_CODE_TRIPLE, M->getTargetTriple(), 0/*TODO*/, Stream); - if (!M->getDataLayout().empty()) - WriteStringRecord(bitc::MODULE_CODE_DATALAYOUT, M->getDataLayout(), - 0/*TODO*/, Stream); + const std::string &DL = M->getDataLayoutStr(); + if (!DL.empty()) + WriteStringRecord(bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/, Stream); if (!M->getModuleInlineAsm().empty()) WriteStringRecord(bitc::MODULE_CODE_ASM, M->getModuleInlineAsm(), 0/*TODO*/, Stream); diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index c48214cc2f..d414f764d3 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1252,8 +1252,9 @@ void AssemblyWriter::printModule(const Module *M) { M->getModuleIdentifier().find('\n') == std::string::npos) Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; - if (!M->getDataLayout().empty()) - Out << "target datalayout = \"" << M->getDataLayout() << "\"\n"; + const std::string &DL = M->getDataLayoutStr(); + if (!DL.empty()) + Out << "target datalayout = \"" << DL << "\"\n"; if (!M->getTargetTriple().empty()) Out << "target triple = \"" << M->getTargetTriple() << "\"\n"; diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp index 68bc5c5810..b19fbe3fda 100644 --- a/lib/IR/Core.cpp +++ b/lib/IR/Core.cpp @@ -107,7 +107,7 @@ void LLVMDisposeModule(LLVMModuleRef M) { /*--.. Data layout .........................................................--*/ const char * LLVMGetDataLayout(LLVMModuleRef M) { - return unwrap(M)->getDataLayout().c_str(); + return unwrap(M)->getDataLayoutStr().c_str(); } void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) { diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index 44410ceb68..d60c79f52e 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -344,7 +344,13 @@ void DataLayout::parseSpecifier(StringRef Desc) { } } -DataLayout::DataLayout(const Module *M) { init(M->getDataLayout()); } +DataLayout::DataLayout(const Module *M) { + const DataLayout *Other = M->getDataLayout(); + if (Other) + *this = *Other; + else + init(""); +} void DataLayout::setAlignment(AlignTypeEnum align_type, unsigned abi_align, diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index d911c7e2b5..739f8888f9 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -42,8 +42,8 @@ template class llvm::SymbolTableListTraits<GlobalAlias, Module>; // Primitive Module methods. // -Module::Module(StringRef MID, LLVMContext& C) - : Context(C), Materializer(NULL), ModuleID(MID) { +Module::Module(StringRef MID, LLVMContext &C) + : Context(C), Materializer(NULL), ModuleID(MID), DL("") { ValSymTab = new ValueSymbolTable(); NamedMDSymTab = new StringMap<NamedMDNode *>(); Context.addModule(this); @@ -338,6 +338,30 @@ void Module::addModuleFlag(MDNode *Node) { getOrInsertModuleFlagsMetadata()->addOperand(Node); } +void Module::setDataLayout(StringRef Desc) { + if (Desc.empty()) { + DataLayoutStr = ""; + } else { + DL.init(Desc); + DataLayoutStr = DL.getStringRepresentation(); + } +} + +void Module::setDataLayout(const DataLayout *Other) { + if (!Other) { + DataLayoutStr = ""; + } else { + DL = *Other; + DataLayoutStr = DL.getStringRepresentation(); + } +} + +const DataLayout *Module::getDataLayout() const { + if (DataLayoutStr.empty()) + return 0; + return &DL; +} + //===----------------------------------------------------------------------===// // Methods to control the materialization of GlobalValues in the Module. // diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 1bfc8284b8..f1b8cb7610 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1200,14 +1200,14 @@ bool ModuleLinker::run() { // Inherit the target data from the source module if the destination module // doesn't have one already. - if (DstM->getDataLayout().empty() && !SrcM->getDataLayout().empty()) + if (!DstM->getDataLayout() && SrcM->getDataLayout()) DstM->setDataLayout(SrcM->getDataLayout()); // Copy the target triple from the source to dest if the dest's is empty. if (DstM->getTargetTriple().empty() && !SrcM->getTargetTriple().empty()) DstM->setTargetTriple(SrcM->getTargetTriple()); - if (!SrcM->getDataLayout().empty() && !DstM->getDataLayout().empty() && + if (SrcM->getDataLayout() && DstM->getDataLayout() && SrcM->getDataLayout() != DstM->getDataLayout()) { if (!SuppressWarnings) { errs() << "WARNING: Linking two modules of different data layouts!\n"; |