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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217548
91177308-0d34-0410-b5e6-
96231b3b80d8
17 files changed:
// Start with registering info about how the
// target lays out data structures.
module->setDataLayout(executionEngine->getDataLayout());
// 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
// Optimizations turned on
#ifdef ADD_OPT_PASSES
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
// 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.
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
// 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.
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
// 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.
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Do simple "peephole" optimizations and bit-twiddling optzns.
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
// 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.
// Provide basic AliasAnalysis support for GVN.
OurFPM.add(createBasicAliasAnalysisPass());
// Promote allocas to registers.
/// Initialize target data from properties stored in the module.
explicit DataLayout(const Module *M);
/// 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) {
DataLayout(const DataLayout &DL) : LayoutMap(nullptr) { *this = DL; }
DataLayout &operator=(const DataLayout &DL) {
const DataLayout &getDataLayout() const { return DL; }
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
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
};
/// StructLayout - used to lazily calculate structure layout information for a
PassManager PM;
M->setDataLayout(TM->getSubtargetImpl()->getDataLayout());
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());
// The RuntimeDyld will take ownership of this shortly
std::unique_ptr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
}
DataLayout::DataLayout(const Module *M) : LayoutMap(nullptr) {
}
DataLayout::DataLayout(const Module *M) : LayoutMap(nullptr) {
+ init(M);
+}
+
+void DataLayout::init(const Module *M) {
const DataLayout *Other = M->getDataLayout();
if (Other)
*this = *Other;
const DataLayout *Other = M->getDataLayout();
if (Other)
*this = *Other;
}
DataLayoutPass::DataLayoutPass() : ImmutablePass(ID), DL("") {
}
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() {}
-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;
PassManager codeGenPasses;
PassManager codeGenPasses;
- codeGenPasses.add(new DataLayoutPass(mergedModule));
+ codeGenPasses.add(new DataLayoutPass());
formatted_raw_ostream Out(out);
formatted_raw_ostream Out(out);
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.
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,
}
void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
return true;
}
Mod->setDataLayout(td);
return true;
}
Mod->setDataLayout(td);
- pass.add(new DataLayoutPass(Mod));
+ pass.add(new DataLayoutPass());
TargetMachine::CodeGenFileType ft;
switch (codegen) {
TargetMachine::CodeGenFileType ft;
switch (codegen) {
void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
TargetMachine *TM) {
if (TM) {
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);
}
TM->addAnalysisPasses(PM);
}
runLTOPasses(M, *TM);
PassManager CodeGenPasses;
runLTOPasses(M, *TM);
PassManager CodeGenPasses;
- CodeGenPasses.add(new DataLayoutPass(&M));
+ CodeGenPasses.add(new DataLayoutPass());
SmallString<128> Filename;
int FD;
SmallString<128> Filename;
int FD;
// Add the target data from the target machine, if it exists, or the module.
if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
mod->setDataLayout(DL);
// 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)
if (RelaxAll.getNumOccurrences() > 0 &&
FileType != TargetMachine::CGFT_ObjectFile)
// In addition to deleting all other functions, we also want to spiff it
// up a little bit. Do this now.
PassManager Passes;
// 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());
std::vector<GlobalValue*> Gvs(GVs.begin(), GVs.end());
- Passes.add(new DataLayoutPass(M.get()));
+ Passes.add(new DataLayoutPass());
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = nullptr;
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = nullptr;
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
FPasses.reset(new FunctionPassManager(M.get()));
if (DL)
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);
if (TM.get())
TM->addAnalysisPasses(*FPasses);
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
PassManager Passes;
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);
Passes.add(mNDM2);
Passes.add(mNDM);
Passes.add(mNDNM);
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
PassManager Passes;
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
Passes.add(mNDM);
Passes.add(mNDNM);
Passes.add(mNDM2);// invalidates mNDM needed by mDNM
std::unique_ptr<Module> M(makeLLVMModule());
T *P = new T();
PassManager Passes;
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);
Passes.add(P);
Passes.run(*M);
T::finishedOK(run);
Module *M = makeLLVMModule();
T *P = new T();
PassManager Passes;
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);
Passes.add(P);
Passes.run(*M);
T::finishedOK(run, N);
SCOPED_TRACE("Running OnTheFlyTest");
struct OnTheFlyTest *O = new OnTheFlyTest();
PassManager Passes;
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);
Passes.add(O);
Passes.run(*M);