diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-02-25 20:01:08 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-02-25 20:01:08 +0000 |
commit | aab87fe0ec98072580586850ed00bac3d00df6c0 (patch) | |
tree | 7a7439c4180e01a3804eb528022a98f6d024cdfc /lib/IR | |
parent | dbaa6ab8b5527ca32969f4baa0931a674b9f4eef (diff) | |
download | llvm-aab87fe0ec98072580586850ed00bac3d00df6c0.tar.gz llvm-aab87fe0ec98072580586850ed00bac3d00df6c0.tar.bz2 llvm-aab87fe0ec98072580586850ed00bac3d00df6c0.tar.xz |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202190 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-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 |
4 files changed, 37 insertions, 6 deletions
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. // |