llvm.org GIT mirror llvm / 3b67055
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217548 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
17 changed file(s) with 39 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
19761976 // Start with registering info about how the
19771977 // target lays out data structures.
19781978 module->setDataLayout(executionEngine->getDataLayout());
1979 fpm.add(new llvm::DataLayoutPass(module));
1979 fpm.add(new llvm::DataLayoutPass());
19801980
19811981 // Optimizations turned on
19821982 #ifdef ADD_OPT_PASSES
587587 // Set up the optimizer pipeline. Start with registering info about how the
588588 // target lays out data structures.
589589 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
590 OurFPM.add(new DataLayoutPass(TheModule));
590 OurFPM.add(new DataLayoutPass());
591591 // Provide basic AliasAnalysis support for GVN.
592592 OurFPM.add(createBasicAliasAnalysisPass());
593593 // Do simple "peephole" optimizations and bit-twiddling optzns.
832832 // Set up the optimizer pipeline. Start with registering info about how the
833833 // target lays out data structures.
834834 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
835 OurFPM.add(new DataLayoutPass(TheModule));
835 OurFPM.add(new DataLayoutPass());
836836 // Provide basic AliasAnalysis support for GVN.
837837 OurFPM.add(createBasicAliasAnalysisPass());
838838 // Do simple "peephole" optimizations and bit-twiddling optzns.
950950 // Set up the optimizer pipeline. Start with registering info about how the
951951 // target lays out data structures.
952952 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
953 OurFPM.add(new DataLayoutPass(TheModule));
953 OurFPM.add(new DataLayoutPass());
954954 // Provide basic AliasAnalysis support for GVN.
955955 OurFPM.add(createBasicAliasAnalysisPass());
956956 // Do simple "peephole" optimizations and bit-twiddling optzns.
11141114 // Set up the optimizer pipeline. Start with registering info about how the
11151115 // target lays out data structures.
11161116 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
1117 OurFPM.add(new DataLayoutPass(TheModule));
1117 OurFPM.add(new DataLayoutPass());
11181118 // Provide basic AliasAnalysis support for GVN.
11191119 OurFPM.add(createBasicAliasAnalysisPass());
11201120 // Promote allocas to registers.
183183 /// Initialize target data from properties stored in the module.
184184 explicit DataLayout(const Module *M);
185185
186 void init(const Module *M);
187
186188 DataLayout(const DataLayout &DL) : LayoutMap(nullptr) { *this = DL; }
187189
188190 DataLayout &operator=(const DataLayout &DL) {
465467
466468 const DataLayout &getDataLayout() const { return DL; }
467469
468 // For use with the C API. C++ code should always use the constructor that
469 // takes a module.
470 explicit DataLayoutPass(const DataLayout &DL);
471
472 explicit DataLayoutPass(const Module *M);
473
474470 static char ID; // Pass identification, replacement for typeid
471
472 bool doFinalization(Module &M) override;
473 bool doInitialization(Module &M) override;
475474 };
476475
477476 /// StructLayout - used to lazily calculate structure layout information for a
132132 PassManager PM;
133133
134134 M->setDataLayout(TM->getSubtargetImpl()->getDataLayout());
135 PM.add(new DataLayoutPass(M));
135 PM.add(new DataLayoutPass());
136136
137137 // The RuntimeDyld will take ownership of this shortly
138138 std::unique_ptr CompiledObject(new ObjectBufferStream());
344344 }
345345
346346 DataLayout::DataLayout(const Module *M) : LayoutMap(nullptr) {
347 init(M);
348 }
349
350 void DataLayout::init(const Module *M) {
347351 const DataLayout *Other = M->getDataLayout();
348352 if (Other)
349353 *this = *Other;
795799 }
796800
797801 DataLayoutPass::DataLayoutPass() : ImmutablePass(ID), DL("") {
798 report_fatal_error("Bad DataLayoutPass ctor used. Tool did not specify a "
799 "DataLayout to use?");
802 initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
800803 }
801804
802805 DataLayoutPass::~DataLayoutPass() {}
803806
804 DataLayoutPass::DataLayoutPass(const DataLayout &DL)
805 : ImmutablePass(ID), DL(DL) {
806 initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
807 }
808
809 DataLayoutPass::DataLayoutPass(const Module *M) : ImmutablePass(ID), DL(M) {
810 initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
811 }
807 bool DataLayoutPass::doInitialization(Module &M) {
808 DL.init(&M);
809 return false;
810 }
811
812 bool DataLayoutPass::doFinalization(Module &M) {
813 DL.reset("");
814 return false;
815 }
470470
471471 PassManager codeGenPasses;
472472
473 codeGenPasses.add(new DataLayoutPass(mergedModule));
473 codeGenPasses.add(new DataLayoutPass());
474474
475475 formatted_raw_ostream Out(out);
476476
4848 void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
4949 // The DataLayoutPass must now be in sync with the module. Unfortunatelly we
5050 // cannot enforce that from the C api.
51 unwrap(PM)->add(new DataLayoutPass(*unwrap(TD)));
51 unwrap(PM)->add(new DataLayoutPass());
5252 }
5353
5454 void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef TLI,
197197 return true;
198198 }
199199 Mod->setDataLayout(td);
200 pass.add(new DataLayoutPass(Mod));
200 pass.add(new DataLayoutPass());
201201
202202 TargetMachine::CodeGenFileType ft;
203203 switch (codegen) {
431431 void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM,
432432 TargetMachine *TM) {
433433 if (TM) {
434 const DataLayout *DL = TM->getSubtargetImpl()->getDataLayout();
435 PM.add(new DataLayoutPass(*DL));
434 PM.add(new DataLayoutPass());
436435 TM->addAnalysisPasses(PM);
437436 }
438437
692692 runLTOPasses(M, *TM);
693693
694694 PassManager CodeGenPasses;
695 CodeGenPasses.add(new DataLayoutPass(&M));
695 CodeGenPasses.add(new DataLayoutPass());
696696
697697 SmallString<128> Filename;
698698 int FD;
306306 // Add the target data from the target machine, if it exists, or the module.
307307 if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
308308 mod->setDataLayout(DL);
309 PM.add(new DataLayoutPass(mod));
309 PM.add(new DataLayoutPass());
310310
311311 if (RelaxAll.getNumOccurrences() > 0 &&
312312 FileType != TargetMachine::CGFT_ObjectFile)
249249 // In addition to deleting all other functions, we also want to spiff it
250250 // up a little bit. Do this now.
251251 PassManager Passes;
252 Passes.add(new DataLayoutPass(M.get())); // Use correct DataLayout
252 Passes.add(new DataLayoutPass()); // Use correct DataLayout
253253
254254 std::vector Gvs(GVs.begin(), GVs.end());
255255
439439 }
440440
441441 if (DL)
442 Passes.add(new DataLayoutPass(M.get()));
442 Passes.add(new DataLayoutPass());
443443
444444 Triple ModuleTriple(M->getTargetTriple());
445445 TargetMachine *Machine = nullptr;
455455 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
456456 FPasses.reset(new FunctionPassManager(M.get()));
457457 if (DL)
458 FPasses->add(new DataLayoutPass(M.get()));
458 FPasses->add(new DataLayoutPass());
459459 if (TM.get())
460460 TM->addAnalysisPasses(*FPasses);
461461
302302 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
303303
304304 PassManager Passes;
305 Passes.add(new DataLayoutPass(&M));
305 Passes.add(new DataLayoutPass());
306306 Passes.add(mNDM2);
307307 Passes.add(mNDM);
308308 Passes.add(mNDNM);
326326 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
327327
328328 PassManager Passes;
329 Passes.add(new DataLayoutPass(&M));
329 Passes.add(new DataLayoutPass());
330330 Passes.add(mNDM);
331331 Passes.add(mNDNM);
332332 Passes.add(mNDM2);// invalidates mNDM needed by mDNM
348348 std::unique_ptr M(makeLLVMModule());
349349 T *P = new T();
350350 PassManager Passes;
351 Passes.add(new DataLayoutPass(M.get()));
351 Passes.add(new DataLayoutPass());
352352 Passes.add(P);
353353 Passes.run(*M);
354354 T::finishedOK(run);
359359 Module *M = makeLLVMModule();
360360 T *P = new T();
361361 PassManager Passes;
362 Passes.add(new DataLayoutPass(M));
362 Passes.add(new DataLayoutPass());
363363 Passes.add(P);
364364 Passes.run(*M);
365365 T::finishedOK(run, N);
397397 SCOPED_TRACE("Running OnTheFlyTest");
398398 struct OnTheFlyTest *O = new OnTheFlyTest();
399399 PassManager Passes;
400 Passes.add(new DataLayoutPass(M));
400 Passes.add(new DataLayoutPass());
401401 Passes.add(O);
402402 Passes.run(*M);
403403