summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-02-25 20:01:08 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-02-25 20:01:08 +0000
commitf863ee2949e1dec8f9444cc47983c6030034bb93 (patch)
treee41e034974eab9b211942bf8736ca45d5b2ef423 /llvm/lib
parent5689a217e303bc4fbba514cbe0491ac44b7081ef (diff)
downloadbcm5719-llvm-f863ee2949e1dec8f9444cc47983c6030034bb93.tar.gz
bcm5719-llvm-f863ee2949e1dec8f9444cc47983c6030034bb93.zip
Store a DataLayout in Module.
Now that DataLayout is not a pass, store one in Module. Since the C API expects to be able to get a char* to the datalayout description, we have to keep a std::string somewhere. This patch keeps it in Module and also uses it to represent modules without a DataLayout. Once DataLayout is mandatory, we should probably move the string to DataLayout itself since it won't be necessary anymore to represent the special case of a module without a DataLayout. llvm-svn: 202190
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp6
-rw-r--r--llvm/lib/IR/AsmWriter.cpp5
-rw-r--r--llvm/lib/IR/Core.cpp2
-rw-r--r--llvm/lib/IR/DataLayout.cpp8
-rw-r--r--llvm/lib/IR/Module.cpp28
-rw-r--r--llvm/lib/Linker/LinkModules.cpp4
6 files changed, 42 insertions, 11 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 1d763d66ddc..718cd123898 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/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/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index c48214cc2fa..d414f764d33 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/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/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 68bc5c5810e..b19fbe3fda0 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/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/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index 44410ceb684..d60c79f52e8 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/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/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index d911c7e2b5b..739f8888f96 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/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/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 1bfc8284b81..f1b8cb76106 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/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";
OpenPOWER on IntegriCloud