llvm.org GIT mirror llvm / 356deb5
Use DataLayout from the module when easily available. Eventually DataLayoutPass should go away, but for now that is the only easy way to get a DataLayout in some APIs. This patch only changes the ones that have easy access to a Module. One interesting issue with sometimes using DataLayoutPass and sometimes fetching it from the Module is that we have to make sure they are equivalent. We can get most of the way there by always constructing the pass with a Module. In fact, the pass could be changed to point to an external DataLayout instead of owning one to make this stricter. Unfortunately, the C api passes a DataLayout, so it has to be up to the caller to make sure the pass and the module are in sync. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202204 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
22 changed file(s) with 58 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
19751975 // Set up the optimizer pipeline.
19761976 // Start with registering info about how the
19771977 // target lays out data structures.
1978 fpm.add(new llvm::DataLayoutPass(*executionEngine->getDataLayout()));
1978 module->setDataLayout(executionEngine->getDataLayout());
1979 fpm.add(new llvm::DataLayoutPass(module));
19791980
19801981 // Optimizations turned on
19811982 #ifdef ADD_OPT_PASSES
585585
586586 // Set up the optimizer pipeline. Start with registering info about how the
587587 // target lays out data structures.
588 OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
588 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
589 OurFPM.add(new DataLayoutPass(TheModule));
589590 // Provide basic AliasAnalysis support for GVN.
590591 OurFPM.add(createBasicAliasAnalysisPass());
591592 // Do simple "peephole" optimizations and bit-twiddling optzns.
830830
831831 // Set up the optimizer pipeline. Start with registering info about how the
832832 // target lays out data structures.
833 OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
833 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
834 OurFPM.add(new DataLayoutPass(TheModule));
834835 // Provide basic AliasAnalysis support for GVN.
835836 OurFPM.add(createBasicAliasAnalysisPass());
836837 // Do simple "peephole" optimizations and bit-twiddling optzns.
948948
949949 // Set up the optimizer pipeline. Start with registering info about how the
950950 // target lays out data structures.
951 OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
951 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
952 OurFPM.add(new DataLayoutPass(TheModule));
952953 // Provide basic AliasAnalysis support for GVN.
953954 OurFPM.add(createBasicAliasAnalysisPass());
954955 // Do simple "peephole" optimizations and bit-twiddling optzns.
11121112
11131113 // Set up the optimizer pipeline. Start with registering info about how the
11141114 // target lays out data structures.
1115 OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
1115 TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
1116 OurFPM.add(new DataLayoutPass(TheModule));
11161117 // Provide basic AliasAnalysis support for GVN.
11171118 OurFPM.add(createBasicAliasAnalysisPass());
11181119 // Promote allocas to registers.
9898
9999 /// \brief Cost analyzer used by inliner.
100100 class InlineCostAnalysis : public CallGraphSCCPass {
101 const DataLayout *DL;
102101 const TargetTransformInfo *TTI;
103102
104103 public:
115115 const Function *getParent() const { return Parent; }
116116 Function *getParent() { return Parent; }
117117
118 const DataLayout *getDataLayout() const;
119
118120 /// \brief Returns the terminator instruction if the block is well formed or
119121 /// null if the block is not well formed.
120122 TerminatorInst *getTerminator();
459459
460460 const DataLayout &getDataLayout() const { return DL; }
461461
462 // For use with the C API. C++ code should always use the constructor that
463 // takes a module.
462464 explicit DataLayoutPass(const DataLayout &DL);
463
464 explicit DataLayoutPass(StringRef LayoutDescription);
465465
466466 explicit DataLayoutPass(const Module *M);
467467
299299 inline Module *getParent() { return Parent; }
300300 inline const Module *getParent() const { return Parent; }
301301
302 const DataLayout *getDataLayout() const;
303
302304 // Methods for support type inquiry through isa, cast, and dyn_cast:
303305 static inline bool classof(const Value *V) {
304306 return V->getValueID() == Value::FunctionVal ||
5252 inline const BasicBlock *getParent() const { return Parent; }
5353 inline BasicBlock *getParent() { return Parent; }
5454
55 const DataLayout *getDataLayout() const;
56
5557 /// removeFromParent - This method unlinks 'this' from the containing basic
5658 /// block, but does not delete it.
5759 ///
398398 }
399399
400400 bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) {
401 const DataLayout *DL = I.getDataLayout();
401402 // Propagate constants through ptrtoint.
402403 Constant *COp = dyn_cast(I.getOperand(0));
403404 if (!COp)
434435 }
435436
436437 bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) {
438 const DataLayout *DL = I.getDataLayout();
437439 // Propagate constants through ptrtoint.
438440 Constant *COp = dyn_cast(I.getOperand(0));
439441 if (!COp)
12021204
12031205 char InlineCostAnalysis::ID = 0;
12041206
1205 InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID), DL(0) {}
1207 InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID) {}
12061208
12071209 InlineCostAnalysis::~InlineCostAnalysis() {}
12081210
12131215 }
12141216
12151217 bool InlineCostAnalysis::runOnSCC(CallGraphSCC &SCC) {
1216 DataLayoutPass *DLP = getAnalysisIfAvailable();
1217 DL = DLP ? &DLP->getDataLayout() : 0;
12181218 TTI = &getAnalysis();
12191219 return false;
12201220 }
12721272 DEBUG(llvm::dbgs() << " Analyzing call of " << Callee->getName()
12731273 << "...\n");
12741274
1275 CallAnalyzer CA(DL, *TTI, *Callee, Threshold);
1275 CallAnalyzer CA(Callee->getDataLayout(), *TTI, *Callee, Threshold);
12761276 bool ShouldInline = CA.analyzeCall(CS);
12771277
12781278 DEBUG(CA.dump());
2525 #include "llvm/IR/Function.h"
2626 #include "llvm/IR/GlobalVariable.h"
2727 #include "llvm/IR/Instructions.h"
28 #include "llvm/IR/Module.h"
2829 #include "llvm/Support/Dwarf.h"
2930 #include "llvm/Support/DynamicLibrary.h"
3031 #include "llvm/Support/ErrorHandling.h"
150151 // Add target data
151152 MutexGuard locked(lock);
152153 FunctionPassManager &PM = jitstate->getPM(locked);
153 PM.add(new DataLayoutPass(*TM.getDataLayout()));
154 M->setDataLayout(TM.getDataLayout());
155 PM.add(new DataLayoutPass(M));
154156
155157 // Turn the machine code intermediate representation into bytes in memory that
156158 // may be executed.
182184 jitstate = new JITState(M);
183185
184186 FunctionPassManager &PM = jitstate->getPM(locked);
185 PM.add(new DataLayoutPass(*TM.getDataLayout()));
187 M->setDataLayout(TM.getDataLayout());
188 PM.add(new DataLayoutPass(M));
186189
187190 // Turn the machine code intermediate representation into bytes in memory
188191 // that may be executed.
213216 jitstate = new JITState(Modules[0]);
214217
215218 FunctionPassManager &PM = jitstate->getPM(locked);
216 PM.add(new DataLayoutPass(*TM.getDataLayout()));
219 M->setDataLayout(TM.getDataLayout());
220 PM.add(new DataLayoutPass(M));
217221
218222 // Turn the machine code intermediate representation into bytes in memory
219223 // that may be executed.
141141
142142 PassManager PM;
143143
144 PM.add(new DataLayoutPass(*TM->getDataLayout()));
144 M->setDataLayout(TM->getDataLayout());
145 PM.add(new DataLayoutPass(M));
145146
146147 // The RuntimeDyld will take ownership of this shortly
147148 OwningPtr CompiledObject(new ObjectBufferStream());
2727 if (Function *F = getParent())
2828 return &F->getValueSymbolTable();
2929 return 0;
30 }
31
32 const DataLayout *BasicBlock::getDataLayout() const {
33 return getParent()->getDataLayout();
3034 }
3135
3236 LLVMContext &BasicBlock::getContext() const {
785785 initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
786786 }
787787
788 DataLayoutPass::DataLayoutPass(StringRef Str) : ImmutablePass(ID), DL(Str) {
789 initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
790 }
791
792788 DataLayoutPass::DataLayoutPass(const Module *M) : ImmutablePass(ID), DL(M) {
793789 initializeDataLayoutPassPass(*PassRegistry::getPassRegistry());
794790 }
3737 }
3838 void GlobalValue::Dematerialize() {
3939 getParent()->Dematerialize(this);
40 }
41
42 const DataLayout *GlobalValue::getDataLayout() const {
43 return getParent()->getDataLayout();
4044 }
4145
4246 /// Override destroyConstant to make sure it doesn't get called on
3232 "Instruction to insert before is not in a basic block!");
3333 InsertBefore->getParent()->getInstList().insert(InsertBefore, this);
3434 }
35 }
36
37 const DataLayout *Instruction::getDataLayout() const {
38 return getParent()->getDataLayout();
3539 }
3640
3741 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
481481 passes.add(createVerifierPass());
482482
483483 // Add an appropriate DataLayout instance for this module...
484 passes.add(new DataLayoutPass(*TargetMach->getDataLayout()));
484 mergedModule->setDataLayout(TargetMach->getDataLayout());
485 passes.add(new DataLayoutPass(mergedModule));
485486
486487 // Add appropriate TargetLibraryInfo for this module.
487488 passes.add(new TargetLibraryInfo(Triple(TargetMach->getTargetTriple())));
502503
503504 PassManager codeGenPasses;
504505
505 codeGenPasses.add(new DataLayoutPass(*TargetMach->getDataLayout()));
506 codeGenPasses.add(new DataLayoutPass(mergedModule));
506507
507508 formatted_raw_ostream Out(out);
508509
5454 }
5555
5656 void LLVMAddTargetData(LLVMTargetDataRef TD, LLVMPassManagerRef PM) {
57 // The DataLayoutPass must now be in sync with the module. Unfortunatelly we
58 // cannot enforce that from the C api.
5759 unwrap(PM)->add(new DataLayoutPass(*unwrap(TD)));
5860 }
5961
211211 *ErrorMessage = strdup(error.c_str());
212212 return true;
213213 }
214 pass.add(new DataLayoutPass(*td));
214 Mod->setDataLayout(td);
215 pass.add(new DataLayoutPass(Mod));
215216
216217 TargetMachine::CodeGenFileType ft;
217218 switch (codegen) {
298298
299299 // Add the target data from the target machine, if it exists, or the module.
300300 if (const DataLayout *DL = Target.getDataLayout())
301 PM.add(new DataLayoutPass(*DL));
302 else
303 PM.add(new DataLayoutPass(mod));
301 mod->setDataLayout(DL);
302 PM.add(new DataLayoutPass(mod));
304303
305304 // Override default to generate verbose assembly.
306305 Target.setAsmVerbosityDefault(true);
429429
430430 // Add an appropriate DataLayout instance for this module.
431431 const DataLayout *DL = M.get()->getDataLayout();
432 if (!DL && !DefaultDataLayout.empty())
433 DL = new DataLayout(DefaultDataLayout);
432 if (!DL && !DefaultDataLayout.empty()) {
433 M->setDataLayout(DefaultDataLayout);
434 DL = M.get()->getDataLayout();
435 }
434436
435437 if (DL)
436 Passes.add(new DataLayoutPass(*DL));
438 Passes.add(new DataLayoutPass(M.get()));
437439
438440 Triple ModuleTriple(M->getTargetTriple());
439441 TargetMachine *Machine = 0;
449451 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
450452 FPasses.reset(new FunctionPassManager(M.get()));
451453 if (DL)
452 FPasses->add(new DataLayoutPass(*DL));
454 FPasses->add(new DataLayoutPass(M.get()));
453455 if (TM.get())
454456 TM->addAnalysisPasses(*FPasses);
455457