mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
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
This commit is contained in:
parent
135a25bcb9
commit
4753b87f60
@ -1977,7 +1977,7 @@ int main(int argc, char *argv[]) {
|
|||||||
// Start with registering info about how the
|
// Start with registering info about how the
|
||||||
// target lays out data structures.
|
// target lays out data structures.
|
||||||
module->setDataLayout(executionEngine->getDataLayout());
|
module->setDataLayout(executionEngine->getDataLayout());
|
||||||
fpm.add(new llvm::DataLayoutPass(module));
|
fpm.add(new llvm::DataLayoutPass());
|
||||||
|
|
||||||
// Optimizations turned on
|
// Optimizations turned on
|
||||||
#ifdef ADD_OPT_PASSES
|
#ifdef ADD_OPT_PASSES
|
||||||
|
@ -588,7 +588,7 @@ int main() {
|
|||||||
// Set up the optimizer pipeline. Start with registering info about how the
|
// Set up the optimizer pipeline. Start with registering info about how the
|
||||||
// target lays out data structures.
|
// target lays out data structures.
|
||||||
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
||||||
OurFPM.add(new DataLayoutPass(TheModule));
|
OurFPM.add(new DataLayoutPass());
|
||||||
// Provide basic AliasAnalysis support for GVN.
|
// Provide basic AliasAnalysis support for GVN.
|
||||||
OurFPM.add(createBasicAliasAnalysisPass());
|
OurFPM.add(createBasicAliasAnalysisPass());
|
||||||
// Do simple "peephole" optimizations and bit-twiddling optzns.
|
// Do simple "peephole" optimizations and bit-twiddling optzns.
|
||||||
|
@ -833,7 +833,7 @@ int main() {
|
|||||||
// Set up the optimizer pipeline. Start with registering info about how the
|
// Set up the optimizer pipeline. Start with registering info about how the
|
||||||
// target lays out data structures.
|
// target lays out data structures.
|
||||||
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
||||||
OurFPM.add(new DataLayoutPass(TheModule));
|
OurFPM.add(new DataLayoutPass());
|
||||||
// Provide basic AliasAnalysis support for GVN.
|
// Provide basic AliasAnalysis support for GVN.
|
||||||
OurFPM.add(createBasicAliasAnalysisPass());
|
OurFPM.add(createBasicAliasAnalysisPass());
|
||||||
// Do simple "peephole" optimizations and bit-twiddling optzns.
|
// Do simple "peephole" optimizations and bit-twiddling optzns.
|
||||||
|
@ -951,7 +951,7 @@ int main() {
|
|||||||
// Set up the optimizer pipeline. Start with registering info about how the
|
// Set up the optimizer pipeline. Start with registering info about how the
|
||||||
// target lays out data structures.
|
// target lays out data structures.
|
||||||
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
||||||
OurFPM.add(new DataLayoutPass(TheModule));
|
OurFPM.add(new DataLayoutPass());
|
||||||
// Provide basic AliasAnalysis support for GVN.
|
// Provide basic AliasAnalysis support for GVN.
|
||||||
OurFPM.add(createBasicAliasAnalysisPass());
|
OurFPM.add(createBasicAliasAnalysisPass());
|
||||||
// Do simple "peephole" optimizations and bit-twiddling optzns.
|
// Do simple "peephole" optimizations and bit-twiddling optzns.
|
||||||
|
@ -1115,7 +1115,7 @@ int main() {
|
|||||||
// Set up the optimizer pipeline. Start with registering info about how the
|
// Set up the optimizer pipeline. Start with registering info about how the
|
||||||
// target lays out data structures.
|
// target lays out data structures.
|
||||||
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
|
||||||
OurFPM.add(new DataLayoutPass(TheModule));
|
OurFPM.add(new DataLayoutPass());
|
||||||
// Provide basic AliasAnalysis support for GVN.
|
// Provide basic AliasAnalysis support for GVN.
|
||||||
OurFPM.add(createBasicAliasAnalysisPass());
|
OurFPM.add(createBasicAliasAnalysisPass());
|
||||||
// Promote allocas to registers.
|
// Promote allocas to registers.
|
||||||
|
@ -184,6 +184,8 @@ public:
|
|||||||
/// Initialize target data from properties stored in the module.
|
/// Initialize target data from properties stored in the module.
|
||||||
explicit DataLayout(const Module *M);
|
explicit DataLayout(const Module *M);
|
||||||
|
|
||||||
|
void init(const Module *M);
|
||||||
|
|
||||||
DataLayout(const DataLayout &DL) : LayoutMap(nullptr) { *this = DL; }
|
DataLayout(const DataLayout &DL) : LayoutMap(nullptr) { *this = DL; }
|
||||||
|
|
||||||
DataLayout &operator=(const DataLayout &DL) {
|
DataLayout &operator=(const DataLayout &DL) {
|
||||||
@ -466,13 +468,10 @@ public:
|
|||||||
|
|
||||||
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
|
||||||
|
@ -133,7 +133,7 @@ std::unique_ptr<ObjectBufferStream> MCJIT::emitObject(Module *M) {
|
|||||||
PassManager PM;
|
PassManager PM;
|
||||||
|
|
||||||
M->setDataLayout(TM->getSubtargetImpl()->getDataLayout());
|
M->setDataLayout(TM->getSubtargetImpl()->getDataLayout());
|
||||||
PM.add(new DataLayoutPass(M));
|
PM.add(new DataLayoutPass());
|
||||||
|
|
||||||
// The RuntimeDyld will take ownership of this shortly
|
// The RuntimeDyld will take ownership of this shortly
|
||||||
std::unique_ptr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
|
std::unique_ptr<ObjectBufferStream> CompiledObject(new ObjectBufferStream());
|
||||||
|
@ -345,6 +345,10 @@ void DataLayout::parseSpecifier(StringRef Desc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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();
|
const DataLayout *Other = M->getDataLayout();
|
||||||
if (Other)
|
if (Other)
|
||||||
*this = *Other;
|
*this = *Other;
|
||||||
@ -796,17 +800,17 @@ unsigned DataLayout::getPreferredAlignmentLog(const GlobalVariable *GV) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DataLayoutPass::DataLayoutPass() : ImmutablePass(ID), DL("") {
|
DataLayoutPass::DataLayoutPass() : ImmutablePass(ID), DL("") {
|
||||||
report_fatal_error("Bad DataLayoutPass ctor used. Tool did not specify a "
|
initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
|
||||||
"DataLayout to use?");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataLayoutPass::~DataLayoutPass() {}
|
DataLayoutPass::~DataLayoutPass() {}
|
||||||
|
|
||||||
DataLayoutPass::DataLayoutPass(const DataLayout &DL)
|
bool DataLayoutPass::doInitialization(Module &M) {
|
||||||
: ImmutablePass(ID), DL(DL) {
|
DL.init(&M);
|
||||||
initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataLayoutPass::DataLayoutPass(const Module *M) : ImmutablePass(ID), DL(M) {
|
bool DataLayoutPass::doFinalization(Module &M) {
|
||||||
initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
|
DL.reset("");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -471,7 +471,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
|
|||||||
|
|
||||||
PassManager codeGenPasses;
|
PassManager codeGenPasses;
|
||||||
|
|
||||||
codeGenPasses.add(new DataLayoutPass(mergedModule));
|
codeGenPasses.add(new DataLayoutPass());
|
||||||
|
|
||||||
formatted_raw_ostream Out(out);
|
formatted_raw_ostream Out(out);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
|
|||||||
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
|
void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
|
||||||
// The DataLayoutPass must now be in sync with the module. Unfortunatelly we
|
// The DataLayoutPass must now be in sync with the module. Unfortunatelly we
|
||||||
// cannot enforce that from the C api.
|
// 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,
|
||||||
|
@ -198,7 +198,7 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Mod->setDataLayout(td);
|
Mod->setDataLayout(td);
|
||||||
pass.add(new DataLayoutPass(Mod));
|
pass.add(new DataLayoutPass());
|
||||||
|
|
||||||
TargetMachine::CodeGenFileType ft;
|
TargetMachine::CodeGenFileType ft;
|
||||||
switch (codegen) {
|
switch (codegen) {
|
||||||
|
@ -432,8 +432,7 @@ void PassManagerBuilder::addLTOOptimizationPasses(PassManagerBase &PM) {
|
|||||||
void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
|
void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
|
||||||
TargetMachine *TM) {
|
TargetMachine *TM) {
|
||||||
if (TM) {
|
if (TM) {
|
||||||
const DataLayout *DL = TM->getSubtargetImpl()->getDataLayout();
|
PM.add(new DataLayoutPass());
|
||||||
PM.add(new DataLayoutPass(*DL));
|
|
||||||
TM->addAnalysisPasses(PM);
|
TM->addAnalysisPasses(PM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,7 +693,7 @@ static void codegen(Module &M) {
|
|||||||
runLTOPasses(M, *TM);
|
runLTOPasses(M, *TM);
|
||||||
|
|
||||||
PassManager CodeGenPasses;
|
PassManager CodeGenPasses;
|
||||||
CodeGenPasses.add(new DataLayoutPass(&M));
|
CodeGenPasses.add(new DataLayoutPass());
|
||||||
|
|
||||||
SmallString<128> Filename;
|
SmallString<128> Filename;
|
||||||
int FD;
|
int FD;
|
||||||
|
@ -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.
|
// Add the target data from the target machine, if it exists, or the module.
|
||||||
if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
|
if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
|
||||||
mod->setDataLayout(DL);
|
mod->setDataLayout(DL);
|
||||||
PM.add(new DataLayoutPass(mod));
|
PM.add(new DataLayoutPass());
|
||||||
|
|
||||||
if (RelaxAll.getNumOccurrences() > 0 &&
|
if (RelaxAll.getNumOccurrences() > 0 &&
|
||||||
FileType != TargetMachine::CGFT_ObjectFile)
|
FileType != TargetMachine::CGFT_ObjectFile)
|
||||||
|
@ -250,7 +250,7 @@ int main(int argc, char **argv) {
|
|||||||
// In addition to deleting all other functions, we also want to spiff it
|
// In addition to deleting all other functions, we also want to spiff it
|
||||||
// up a little bit. Do this now.
|
// up a little bit. Do this now.
|
||||||
PassManager Passes;
|
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());
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (DL)
|
if (DL)
|
||||||
Passes.add(new DataLayoutPass(M.get()));
|
Passes.add(new DataLayoutPass());
|
||||||
|
|
||||||
Triple ModuleTriple(M->getTargetTriple());
|
Triple ModuleTriple(M->getTargetTriple());
|
||||||
TargetMachine *Machine = nullptr;
|
TargetMachine *Machine = nullptr;
|
||||||
@ -456,7 +456,7 @@ int main(int argc, char **argv) {
|
|||||||
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
|
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
|
||||||
FPasses.reset(new FunctionPassManager(M.get()));
|
FPasses.reset(new FunctionPassManager(M.get()));
|
||||||
if (DL)
|
if (DL)
|
||||||
FPasses->add(new DataLayoutPass(M.get()));
|
FPasses->add(new DataLayoutPass());
|
||||||
if (TM.get())
|
if (TM.get())
|
||||||
TM->addAnalysisPasses(*FPasses);
|
TM->addAnalysisPasses(*FPasses);
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ namespace llvm {
|
|||||||
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
|
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
|
||||||
|
|
||||||
PassManager Passes;
|
PassManager Passes;
|
||||||
Passes.add(new DataLayoutPass(&M));
|
Passes.add(new DataLayoutPass());
|
||||||
Passes.add(mNDM2);
|
Passes.add(mNDM2);
|
||||||
Passes.add(mNDM);
|
Passes.add(mNDM);
|
||||||
Passes.add(mNDNM);
|
Passes.add(mNDNM);
|
||||||
@ -327,7 +327,7 @@ namespace llvm {
|
|||||||
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
|
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
|
||||||
|
|
||||||
PassManager Passes;
|
PassManager Passes;
|
||||||
Passes.add(new DataLayoutPass(&M));
|
Passes.add(new DataLayoutPass());
|
||||||
Passes.add(mNDM);
|
Passes.add(mNDM);
|
||||||
Passes.add(mNDNM);
|
Passes.add(mNDNM);
|
||||||
Passes.add(mNDM2);// invalidates mNDM needed by mDNM
|
Passes.add(mNDM2);// invalidates mNDM needed by mDNM
|
||||||
@ -349,7 +349,7 @@ namespace llvm {
|
|||||||
std::unique_ptr<Module> M(makeLLVMModule());
|
std::unique_ptr<Module> M(makeLLVMModule());
|
||||||
T *P = new T();
|
T *P = new T();
|
||||||
PassManager Passes;
|
PassManager Passes;
|
||||||
Passes.add(new DataLayoutPass(M.get()));
|
Passes.add(new DataLayoutPass());
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
T::finishedOK(run);
|
T::finishedOK(run);
|
||||||
@ -360,7 +360,7 @@ namespace llvm {
|
|||||||
Module *M = makeLLVMModule();
|
Module *M = makeLLVMModule();
|
||||||
T *P = new T();
|
T *P = new T();
|
||||||
PassManager Passes;
|
PassManager Passes;
|
||||||
Passes.add(new DataLayoutPass(M));
|
Passes.add(new DataLayoutPass());
|
||||||
Passes.add(P);
|
Passes.add(P);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
T::finishedOK(run, N);
|
T::finishedOK(run, N);
|
||||||
@ -398,7 +398,7 @@ namespace llvm {
|
|||||||
SCOPED_TRACE("Running OnTheFlyTest");
|
SCOPED_TRACE("Running OnTheFlyTest");
|
||||||
struct OnTheFlyTest *O = new OnTheFlyTest();
|
struct OnTheFlyTest *O = new OnTheFlyTest();
|
||||||
PassManager Passes;
|
PassManager Passes;
|
||||||
Passes.add(new DataLayoutPass(M));
|
Passes.add(new DataLayoutPass());
|
||||||
Passes.add(O);
|
Passes.add(O);
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user