summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-09-10 21:27:43 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-09-10 21:27:43 +0000
commitc435adcde045fc739ea18e798ceb32b552fd6827 (patch)
treec6566d0cfd3af5e1403be4682c25b036fd5a0ff4
parent4de669f5b3de09096b55cf1e70ea0b1ea9ad421b (diff)
downloadbcm5719-llvm-c435adcde045fc739ea18e798ceb32b552fd6827.tar.gz
bcm5719-llvm-c435adcde045fc739ea18e798ceb32b552fd6827.zip
Add doInitialization/doFinalization to DataLayoutPass.
With this a DataLayoutPass can be reused for multiple modules. Once we have doInitialization/doFinalization, it doesn't seem necessary to pass a Module to the constructor. Overall this change seems in line with the idea of making DataLayout a required part of Module. With it the only way of having a DataLayout used is to add it to the Module. llvm-svn: 217548
-rw-r--r--llvm/examples/ExceptionDemo/ExceptionDemo.cpp2
-rw-r--r--llvm/examples/Kaleidoscope/Chapter4/toy.cpp2
-rw-r--r--llvm/examples/Kaleidoscope/Chapter5/toy.cpp2
-rw-r--r--llvm/examples/Kaleidoscope/Chapter6/toy.cpp2
-rw-r--r--llvm/examples/Kaleidoscope/Chapter7/toy.cpp2
-rw-r--r--llvm/include/llvm/IR/DataLayout.h11
-rw-r--r--llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp2
-rw-r--r--llvm/lib/IR/DataLayout.cpp18
-rw-r--r--llvm/lib/LTO/LTOCodeGenerator.cpp2
-rw-r--r--llvm/lib/Target/Target.cpp2
-rw-r--r--llvm/lib/Target/TargetMachineC.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/PassManagerBuilder.cpp3
-rw-r--r--llvm/tools/gold/gold-plugin.cpp2
-rw-r--r--llvm/tools/llc/llc.cpp2
-rw-r--r--llvm/tools/llvm-extract/llvm-extract.cpp2
-rw-r--r--llvm/tools/opt/opt.cpp4
-rw-r--r--llvm/unittests/IR/LegacyPassManagerTest.cpp10
17 files changed, 36 insertions, 34 deletions
diff --git a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
index e5e2c923d73..17076facbca 100644
--- a/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/llvm/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -1977,7 +1977,7 @@ int main(int argc, char *argv[]) {
// Start with registering info about how the
// target lays out data structures.
module->setDataLayout(executionEngine->getDataLayout());
- fpm.add(new llvm::DataLayoutPass(module));
+ fpm.add(new llvm::DataLayoutPass());
// Optimizations turned on
#ifdef ADD_OPT_PASSES
diff --git a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
index 9daaaa7466f..3564d751e65 100644
--- a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -588,7 +588,7 @@ int main() {
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
- OurFPM.add(new DataLayoutPass(TheModule));
+ OurFPM.add(new DataLayoutPass());
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
diff --git a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
index 5454b21bece..4929a20cd7e 100644
--- a/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter5/toy.cpp
@@ -833,7 +833,7 @@ int main() {
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
- OurFPM.add(new DataLayoutPass(TheModule));
+ OurFPM.add(new DataLayoutPass());
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
diff --git a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
index 8977203a719..06da9ac682d 100644
--- a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp
@@ -951,7 +951,7 @@ int main() {
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
- OurFPM.add(new DataLayoutPass(TheModule));
+ OurFPM.add(new DataLayoutPass());
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
diff --git a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
index 3550a0d8a5b..56a6fa96e25 100644
--- a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp
@@ -1115,7 +1115,7 @@ int main() {
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
- OurFPM.add(new DataLayoutPass(TheModule));
+ OurFPM.add(new DataLayoutPass());
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Promote allocas to registers.
diff --git a/llvm/include/llvm/IR/DataLayout.h b/llvm/include/llvm/IR/DataLayout.h
index 877029f92f0..4ed10e0be9a 100644
--- a/llvm/include/llvm/IR/DataLayout.h
+++ b/llvm/include/llvm/IR/DataLayout.h
@@ -184,6 +184,8 @@ public:
/// Initialize target data from properties stored in the module.
explicit DataLayout(const Module *M);
+ void init(const Module *M);
+
DataLayout(const DataLayout &DL) : LayoutMap(nullptr) { *this = DL; }
DataLayout &operator=(const DataLayout &DL) {
@@ -466,13 +468,10 @@ public:
const DataLayout &getDataLayout() const { return DL; }
- // For use with the C API. C++ code should always use the constructor that
- // takes a module.
- explicit DataLayoutPass(const DataLayout &DL);
-
- explicit DataLayoutPass(const Module *M);
-
static char ID; // Pass identification, replacement for typeid
+
+ bool doFinalization(Module &M) override;
+ bool doInitialization(Module &M) override;
};
/// StructLayout - used to lazily calculate structure layout information for a
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 8ff41ffd7d6..e441ec8d1a3 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -133,7 +133,7 @@ std::unique_ptr<ObjectBufferStream> MCJIT::emitObject(Module *M) {
PassManager PM;
M->setDataLayout(TM->getSubtargetImpl()->getDataLayout());
- PM.add(new DataLayoutPass(M));
+ PM.add(new DataLayoutPass());
// The RuntimeDyld will take ownership of this shortly
std::unique_ptr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index dea05fbef4a..38873538670 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -345,6 +345,10 @@ void DataLayout::parseSpecifier(StringRef Desc) {
}
DataLayout::DataLayout(const Module *M) : LayoutMap(nullptr) {
+ init(M);
+}
+
+void DataLayout::init(const Module *M) {
const DataLayout *Other = M->getDataLayout();
if (Other)
*this = *Other;
@@ -796,17 +800,17 @@ unsigned DataLayout::getPreferredAlignmentLog(const GlobalVariable *GV) const {
}
DataLayoutPass::DataLayoutPass() : ImmutablePass(ID), DL("") {
- report_fatal_error("Bad DataLayoutPass ctor used. Tool did not specify a "
- "DataLayout to use?");
+ initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
}
DataLayoutPass::~DataLayoutPass() {}
-DataLayoutPass::DataLayoutPass(const DataLayout &DL)
- : ImmutablePass(ID), DL(DL) {
- initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
+bool DataLayoutPass::doInitialization(Module &M) {
+ DL.init(&M);
+ return false;
}
-DataLayoutPass::DataLayoutPass(const Module *M) : ImmutablePass(ID), DL(M) {
- initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
+bool DataLayoutPass::doFinalization(Module &M) {
+ DL.reset("");
+ return false;
}
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 491975e3db6..1b6f905f0ac 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -471,7 +471,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
PassManager codeGenPasses;
- codeGenPasses.add(new DataLayoutPass(mergedModule));
+ codeGenPasses.add(new DataLayoutPass());
formatted_raw_ostream Out(out);
diff --git a/llvm/lib/Target/Target.cpp b/llvm/lib/Target/Target.cpp
index d277f82eb86..4b51b3f7eea 100644
--- a/llvm/lib/Target/Target.cpp
+++ b/llvm/lib/Target/Target.cpp
@@ -49,7 +49,7 @@ LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
// The DataLayoutPass must now be in sync with the module. Unfortunatelly we
// cannot enforce that from the C api.
- unwrap(PM)->add(new DataLayoutPass(*unwrap(TD)));
+ unwrap(PM)->add(new DataLayoutPass());
}
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index 598783b1be1..b3e07df7b5b 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -198,7 +198,7 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
return true;
}
Mod->setDataLayout(td);
- pass.add(new DataLayoutPass(Mod));
+ pass.add(new DataLayoutPass());
TargetMachine::CodeGenFileType ft;
switch (codegen) {
diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
index 1b229123233..1b9d8c16060 100644
--- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -432,8 +432,7 @@ void PassManagerBuilder::addLTOOptimizationPasses(PassManagerBase &PM) {
void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
TargetMachine *TM) {
if (TM) {
- const DataLayout *DL = TM->getSubtargetImpl()->getDataLayout();
- PM.add(new DataLayoutPass(*DL));
+ PM.add(new DataLayoutPass());
TM->addAnalysisPasses(PM);
}
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index e7888bea9e6..abe6e4dd66b 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -693,7 +693,7 @@ static void codegen(Module &M) {
runLTOPasses(M, *TM);
PassManager CodeGenPasses;
- CodeGenPasses.add(new DataLayoutPass(&M));
+ CodeGenPasses.add(new DataLayoutPass());
SmallString<128> Filename;
int FD;
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 0dbe215cef7..fe4d9ac4f19 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -307,7 +307,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
// Add the target data from the target machine, if it exists, or the module.
if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
mod->setDataLayout(DL);
- PM.add(new DataLayoutPass(mod));
+ PM.add(new DataLayoutPass());
if (RelaxAll.getNumOccurrences() > 0 &&
FileType != TargetMachine::CGFT_ObjectFile)
diff --git a/llvm/tools/llvm-extract/llvm-extract.cpp b/llvm/tools/llvm-extract/llvm-extract.cpp
index 8da63fb1797..116b678e07e 100644
--- a/llvm/tools/llvm-extract/llvm-extract.cpp
+++ b/llvm/tools/llvm-extract/llvm-extract.cpp
@@ -250,7 +250,7 @@ int main(int argc, char **argv) {
// In addition to deleting all other functions, we also want to spiff it
// up a little bit. Do this now.
PassManager Passes;
- Passes.add(new DataLayoutPass(M.get())); // Use correct DataLayout
+ Passes.add(new DataLayoutPass()); // Use correct DataLayout
std::vector<GlobalValue*> Gvs(GVs.begin(), GVs.end());
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index f8172b51207..f1a945a6000 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -440,7 +440,7 @@ int main(int argc, char **argv) {
}
if (DL)
- Passes.add(new DataLayoutPass(M.get()));
+ Passes.add(new DataLayoutPass());
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = nullptr;
@@ -456,7 +456,7 @@ int main(int argc, char **argv) {
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
FPasses.reset(new FunctionPassManager(M.get()));
if (DL)
- FPasses->add(new DataLayoutPass(M.get()));
+ FPasses->add(new DataLayoutPass());
if (TM.get())
TM->addAnalysisPasses(*FPasses);
diff --git a/llvm/unittests/IR/LegacyPassManagerTest.cpp b/llvm/unittests/IR/LegacyPassManagerTest.cpp
index 7a2c47a59f9..4efc2f5b805 100644
--- a/llvm/unittests/IR/LegacyPassManagerTest.cpp
+++ b/llvm/unittests/IR/LegacyPassManagerTest.cpp
@@ -303,7 +303,7 @@ namespace llvm {
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
PassManager Passes;
- Passes.add(new DataLayoutPass(&M));
+ Passes.add(new DataLayoutPass());
Passes.add(mNDM2);
Passes.add(mNDM);
Passes.add(mNDNM);
@@ -327,7 +327,7 @@ namespace llvm {
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
PassManager Passes;
- Passes.add(new DataLayoutPass(&M));
+ Passes.add(new DataLayoutPass());
Passes.add(mNDM);
Passes.add(mNDNM);
Passes.add(mNDM2);// invalidates mNDM needed by mDNM
@@ -349,7 +349,7 @@ namespace llvm {
std::unique_ptr<Module> M(makeLLVMModule());
T *P = new T();
PassManager Passes;
- Passes.add(new DataLayoutPass(M.get()));
+ Passes.add(new DataLayoutPass());
Passes.add(P);
Passes.run(*M);
T::finishedOK(run);
@@ -360,7 +360,7 @@ namespace llvm {
Module *M = makeLLVMModule();
T *P = new T();
PassManager Passes;
- Passes.add(new DataLayoutPass(M));
+ Passes.add(new DataLayoutPass());
Passes.add(P);
Passes.run(*M);
T::finishedOK(run, N);
@@ -398,7 +398,7 @@ namespace llvm {
SCOPED_TRACE("Running OnTheFlyTest");
struct OnTheFlyTest *O = new OnTheFlyTest();
PassManager Passes;
- Passes.add(new DataLayoutPass(M));
+ Passes.add(new DataLayoutPass());
Passes.add(O);
Passes.run(*M);
OpenPOWER on IntegriCloud