diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-02-25 23:25:17 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-02-25 23:25:17 +0000 |
commit | 356deb5ecde78fdef706e325325c23c828666b9f (patch) | |
tree | 21aa8a0fb4fed7044dc5449561035d3d8e26a825 /lib | |
parent | 7e2bf3c6f908cc79dd48c69f86920a3826141e72 (diff) | |
download | llvm-356deb5ecde78fdef706e325325c23c828666b9f.tar.gz llvm-356deb5ecde78fdef706e325325c23c828666b9f.tar.bz2 llvm-356deb5ecde78fdef706e325325c23c828666b9f.tar.xz |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/IPA/InlineCost.cpp | 8 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JIT.cpp | 10 | ||||
-rw-r--r-- | lib/ExecutionEngine/MCJIT/MCJIT.cpp | 3 | ||||
-rw-r--r-- | lib/IR/BasicBlock.cpp | 4 | ||||
-rw-r--r-- | lib/IR/DataLayout.cpp | 4 | ||||
-rw-r--r-- | lib/IR/Globals.cpp | 4 | ||||
-rw-r--r-- | lib/IR/Instruction.cpp | 4 | ||||
-rw-r--r-- | lib/LTO/LTOCodeGenerator.cpp | 5 | ||||
-rw-r--r-- | lib/Target/Target.cpp | 2 | ||||
-rw-r--r-- | lib/Target/TargetMachineC.cpp | 3 |
10 files changed, 32 insertions, 15 deletions
diff --git a/lib/Analysis/IPA/InlineCost.cpp b/lib/Analysis/IPA/InlineCost.cpp index 53faae5c67..6d700b9db8 100644 --- a/lib/Analysis/IPA/InlineCost.cpp +++ b/lib/Analysis/IPA/InlineCost.cpp @@ -399,6 +399,7 @@ bool CallAnalyzer::visitBitCast(BitCastInst &I) { } bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) { + const DataLayout *DL = I.getDataLayout(); // Propagate constants through ptrtoint. Constant *COp = dyn_cast<Constant>(I.getOperand(0)); if (!COp) @@ -435,6 +436,7 @@ bool CallAnalyzer::visitPtrToInt(PtrToIntInst &I) { } bool CallAnalyzer::visitIntToPtr(IntToPtrInst &I) { + const DataLayout *DL = I.getDataLayout(); // Propagate constants through ptrtoint. Constant *COp = dyn_cast<Constant>(I.getOperand(0)); if (!COp) @@ -1203,7 +1205,7 @@ INITIALIZE_PASS_END(InlineCostAnalysis, "inline-cost", "Inline Cost Analysis", char InlineCostAnalysis::ID = 0; -InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID), DL(0) {} +InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID) {} InlineCostAnalysis::~InlineCostAnalysis() {} @@ -1214,8 +1216,6 @@ void InlineCostAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { } bool InlineCostAnalysis::runOnSCC(CallGraphSCC &SCC) { - DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); - DL = DLP ? &DLP->getDataLayout() : 0; TTI = &getAnalysis<TargetTransformInfo>(); return false; } @@ -1273,7 +1273,7 @@ InlineCost InlineCostAnalysis::getInlineCost(CallSite CS, Function *Callee, DEBUG(llvm::dbgs() << " Analyzing call of " << Callee->getName() << "...\n"); - CallAnalyzer CA(DL, *TTI, *Callee, Threshold); + CallAnalyzer CA(Callee->getDataLayout(), *TTI, *Callee, Threshold); bool ShouldInline = CA.analyzeCall(CS); DEBUG(CA.dump()); diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 2836218d4a..b271618a5f 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -26,6 +26,7 @@ #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Instructions.h" +#include "llvm/IR/Module.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/ErrorHandling.h" @@ -151,7 +152,8 @@ JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji, // Add target data MutexGuard locked(lock); FunctionPassManager &PM = jitstate->getPM(locked); - PM.add(new DataLayoutPass(*TM.getDataLayout())); + M->setDataLayout(TM.getDataLayout()); + PM.add(new DataLayoutPass(M)); // Turn the machine code intermediate representation into bytes in memory that // may be executed. @@ -183,7 +185,8 @@ void JIT::addModule(Module *M) { jitstate = new JITState(M); FunctionPassManager &PM = jitstate->getPM(locked); - PM.add(new DataLayoutPass(*TM.getDataLayout())); + M->setDataLayout(TM.getDataLayout()); + PM.add(new DataLayoutPass(M)); // Turn the machine code intermediate representation into bytes in memory // that may be executed. @@ -214,7 +217,8 @@ bool JIT::removeModule(Module *M) { jitstate = new JITState(Modules[0]); FunctionPassManager &PM = jitstate->getPM(locked); - PM.add(new DataLayoutPass(*TM.getDataLayout())); + M->setDataLayout(TM.getDataLayout()); + PM.add(new DataLayoutPass(M)); // Turn the machine code intermediate representation into bytes in memory // that may be executed. diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp index ad11a839f0..a0dfbef51f 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -142,7 +142,8 @@ ObjectBufferStream* MCJIT::emitObject(Module *M) { PassManager PM; - PM.add(new DataLayoutPass(*TM->getDataLayout())); + M->setDataLayout(TM->getDataLayout()); + PM.add(new DataLayoutPass(M)); // The RuntimeDyld will take ownership of this shortly OwningPtr<ObjectBufferStream> CompiledObject(new ObjectBufferStream()); diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp index 41e58ec5da..1d7db91791 100644 --- a/lib/IR/BasicBlock.cpp +++ b/lib/IR/BasicBlock.cpp @@ -30,6 +30,10 @@ ValueSymbolTable *BasicBlock::getValueSymbolTable() { return 0; } +const DataLayout *BasicBlock::getDataLayout() const { + return getParent()->getDataLayout(); +} + LLVMContext &BasicBlock::getContext() const { return getType()->getContext(); } diff --git a/lib/IR/DataLayout.cpp b/lib/IR/DataLayout.cpp index ccdaec5e55..bddb680751 100644 --- a/lib/IR/DataLayout.cpp +++ b/lib/IR/DataLayout.cpp @@ -786,10 +786,6 @@ DataLayoutPass::DataLayoutPass(const DataLayout &DL) initializeDataLayoutPassPass(*PassRegistry::getPassRegistry()); } -DataLayoutPass::DataLayoutPass(StringRef Str) : ImmutablePass(ID), DL(Str) { - initializeDataLayoutPassPass(*PassRegistry::getPassRegistry()); -} - DataLayoutPass::DataLayoutPass(const Module *M) : ImmutablePass(ID), DL(M) { initializeDataLayoutPassPass(*PassRegistry::getPassRegistry()); } diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index 5ad96b2ce3..ee882c3eac 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -40,6 +40,10 @@ void GlobalValue::Dematerialize() { getParent()->Dematerialize(this); } +const DataLayout *GlobalValue::getDataLayout() const { + return getParent()->getDataLayout(); +} + /// Override destroyConstant to make sure it doesn't get called on /// GlobalValue's because they shouldn't be treated like other constants. void GlobalValue::destroyConstant() { diff --git a/lib/IR/Instruction.cpp b/lib/IR/Instruction.cpp index a7773c4716..fd5bcc904f 100644 --- a/lib/IR/Instruction.cpp +++ b/lib/IR/Instruction.cpp @@ -35,6 +35,10 @@ Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps, } } +const DataLayout *Instruction::getDataLayout() const { + return getParent()->getDataLayout(); +} + Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps, BasicBlock *InsertAtEnd) : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) { diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index b18726b98d..c5f98736c0 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -482,7 +482,8 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, passes.add(createVerifierPass()); // Add an appropriate DataLayout instance for this module... - passes.add(new DataLayoutPass(*TargetMach->getDataLayout())); + mergedModule->setDataLayout(TargetMach->getDataLayout()); + passes.add(new DataLayoutPass(mergedModule)); // Add appropriate TargetLibraryInfo for this module. passes.add(new TargetLibraryInfo(Triple(TargetMach->getTargetTriple()))); @@ -503,7 +504,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, PassManager codeGenPasses; - codeGenPasses.add(new DataLayoutPass(*TargetMach->getDataLayout())); + codeGenPasses.add(new DataLayoutPass(mergedModule)); formatted_raw_ostream Out(out); diff --git a/lib/Target/Target.cpp b/lib/Target/Target.cpp index ee5178184f..627786dfb4 100644 --- a/lib/Target/Target.cpp +++ b/lib/Target/Target.cpp @@ -55,6 +55,8 @@ 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))); } diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index e939b88e0a..a2829d4c02 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -212,7 +212,8 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, *ErrorMessage = strdup(error.c_str()); return true; } - pass.add(new DataLayoutPass(*td)); + Mod->setDataLayout(td); + pass.add(new DataLayoutPass(Mod)); TargetMachine::CodeGenFileType ft; switch (codegen) { |