[llvm] r202204 - Use DataLayout from the module when easily available.

Rafael Espindola rafael.espindola at gmail.com
Tue Feb 25 15:25:18 PST 2014


Author: rafael
Date: Tue Feb 25 17:25:17 2014
New Revision: 202204

URL: http://llvm.org/viewvc/llvm-project?rev=202204&view=rev
Log:
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.

Modified:
    llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp
    llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp
    llvm/trunk/include/llvm/Analysis/InlineCost.h
    llvm/trunk/include/llvm/IR/BasicBlock.h
    llvm/trunk/include/llvm/IR/DataLayout.h
    llvm/trunk/include/llvm/IR/GlobalValue.h
    llvm/trunk/include/llvm/IR/Instruction.h
    llvm/trunk/lib/Analysis/IPA/InlineCost.cpp
    llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
    llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp
    llvm/trunk/lib/IR/BasicBlock.cpp
    llvm/trunk/lib/IR/DataLayout.cpp
    llvm/trunk/lib/IR/Globals.cpp
    llvm/trunk/lib/IR/Instruction.cpp
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/lib/Target/Target.cpp
    llvm/trunk/lib/Target/TargetMachineC.cpp
    llvm/trunk/tools/llc/llc.cpp
    llvm/trunk/tools/opt/opt.cpp

Modified: llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp (original)
+++ llvm/trunk/examples/ExceptionDemo/ExceptionDemo.cpp Tue Feb 25 17:25:17 2014
@@ -1976,7 +1976,8 @@ int main(int argc, char *argv[]) {
     // Set up the optimizer pipeline.
     // Start with registering info about how the
     // target lays out data structures.
-    fpm.add(new llvm::DataLayoutPass(*executionEngine->getDataLayout()));
+    module->setDataLayout(executionEngine->getDataLayout());
+    fpm.add(new llvm::DataLayoutPass(module));
 
     // Optimizations turned on
 #ifdef ADD_OPT_PASSES

Modified: llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp Tue Feb 25 17:25:17 2014
@@ -586,7 +586,8 @@ int main() {
 
   // Set up the optimizer pipeline.  Start with registering info about how the
   // target lays out data structures.
-  OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+  TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+  OurFPM.add(new DataLayoutPass(TheModule));
   // Provide basic AliasAnalysis support for GVN.
   OurFPM.add(createBasicAliasAnalysisPass());
   // Do simple "peephole" optimizations and bit-twiddling optzns.

Modified: llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp Tue Feb 25 17:25:17 2014
@@ -831,7 +831,8 @@ int main() {
 
   // Set up the optimizer pipeline.  Start with registering info about how the
   // target lays out data structures.
-  OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+  TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+  OurFPM.add(new DataLayoutPass(TheModule));
   // Provide basic AliasAnalysis support for GVN.
   OurFPM.add(createBasicAliasAnalysisPass());
   // Do simple "peephole" optimizations and bit-twiddling optzns.

Modified: llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp Tue Feb 25 17:25:17 2014
@@ -949,7 +949,8 @@ int main() {
 
   // Set up the optimizer pipeline.  Start with registering info about how the
   // target lays out data structures.
-  OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+  TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+  OurFPM.add(new DataLayoutPass(TheModule));
   // Provide basic AliasAnalysis support for GVN.
   OurFPM.add(createBasicAliasAnalysisPass());
   // Do simple "peephole" optimizations and bit-twiddling optzns.

Modified: llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp (original)
+++ llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp Tue Feb 25 17:25:17 2014
@@ -1113,7 +1113,8 @@ int main() {
 
   // Set up the optimizer pipeline.  Start with registering info about how the
   // target lays out data structures.
-  OurFPM.add(new DataLayoutPass(*TheExecutionEngine->getDataLayout()));
+  TheModule->setDataLayout(TheExecutionEngine->getDataLayout());
+  OurFPM.add(new DataLayoutPass(TheModule));
   // Provide basic AliasAnalysis support for GVN.
   OurFPM.add(createBasicAliasAnalysisPass());
   // Promote allocas to registers.

Modified: llvm/trunk/include/llvm/Analysis/InlineCost.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InlineCost.h?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/InlineCost.h (original)
+++ llvm/trunk/include/llvm/Analysis/InlineCost.h Tue Feb 25 17:25:17 2014
@@ -99,7 +99,6 @@ public:
 
 /// \brief Cost analyzer used by inliner.
 class InlineCostAnalysis : public CallGraphSCCPass {
-  const DataLayout *DL;
   const TargetTransformInfo *TTI;
 
 public:

Modified: llvm/trunk/include/llvm/IR/BasicBlock.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/BasicBlock.h?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/BasicBlock.h (original)
+++ llvm/trunk/include/llvm/IR/BasicBlock.h Tue Feb 25 17:25:17 2014
@@ -116,6 +116,8 @@ public:
   const Function *getParent() const { return Parent; }
         Function *getParent()       { return Parent; }
 
+  const DataLayout *getDataLayout() const;
+
   /// \brief Returns the terminator instruction if the block is well formed or
   /// null if the block is not well formed.
   TerminatorInst *getTerminator();

Modified: llvm/trunk/include/llvm/IR/DataLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DataLayout.h?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DataLayout.h (original)
+++ llvm/trunk/include/llvm/IR/DataLayout.h Tue Feb 25 17:25:17 2014
@@ -460,10 +460,10 @@ public:
 
   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(StringRef LayoutDescription);
-
   explicit DataLayoutPass(const Module *M);
 
   static char ID; // Pass identification, replacement for typeid

Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Tue Feb 25 17:25:17 2014
@@ -300,6 +300,8 @@ public:
   inline Module *getParent() { return Parent; }
   inline const Module *getParent() const { return Parent; }
 
+  const DataLayout *getDataLayout() const;
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Value *V) {
     return V->getValueID() == Value::FunctionVal ||

Modified: llvm/trunk/include/llvm/IR/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instruction.h?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h (original)
+++ llvm/trunk/include/llvm/IR/Instruction.h Tue Feb 25 17:25:17 2014
@@ -53,6 +53,8 @@ public:
   inline const BasicBlock *getParent() const { return Parent; }
   inline       BasicBlock *getParent()       { return Parent; }
 
+  const DataLayout *getDataLayout() const;
+
   /// removeFromParent - This method unlinks 'this' from the containing basic
   /// block, but does not delete it.
   ///

Modified: llvm/trunk/lib/Analysis/IPA/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/InlineCost.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IPA/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/IPA/InlineCost.cpp Tue Feb 25 17:25:17 2014
@@ -399,6 +399,7 @@ bool CallAnalyzer::visitBitCast(BitCastI
 }
 
 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(PtrToIn
 }
 
 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,
 
 char InlineCostAnalysis::ID = 0;
 
-InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID), DL(0) {}
+InlineCostAnalysis::InlineCostAnalysis() : CallGraphSCCPass(ID) {}
 
 InlineCostAnalysis::~InlineCostAnalysis() {}
 
@@ -1214,8 +1216,6 @@ void InlineCostAnalysis::getAnalysisUsag
 }
 
 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::getInline
   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());

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Tue Feb 25 17:25:17 2014
@@ -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, T
   // 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.

Modified: llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/MCJIT/MCJIT.cpp Tue Feb 25 17:25:17 2014
@@ -142,7 +142,8 @@ ObjectBufferStream* MCJIT::emitObject(Mo
 
   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());

Modified: llvm/trunk/lib/IR/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)
+++ llvm/trunk/lib/IR/BasicBlock.cpp Tue Feb 25 17:25:17 2014
@@ -30,6 +30,10 @@ ValueSymbolTable *BasicBlock::getValueSy
   return 0;
 }
 
+const DataLayout *BasicBlock::getDataLayout() const {
+  return getParent()->getDataLayout();
+}
+
 LLVMContext &BasicBlock::getContext() const {
   return getType()->getContext();
 }

Modified: llvm/trunk/lib/IR/DataLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DataLayout.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DataLayout.cpp (original)
+++ llvm/trunk/lib/IR/DataLayout.cpp Tue Feb 25 17:25:17 2014
@@ -786,10 +786,6 @@ DataLayoutPass::DataLayoutPass(const Dat
   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());
 }

Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Tue Feb 25 17:25:17 2014
@@ -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() {

Modified: llvm/trunk/lib/IR/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instruction.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instruction.cpp (original)
+++ llvm/trunk/lib/IR/Instruction.cpp Tue Feb 25 17:25:17 2014
@@ -35,6 +35,10 @@ Instruction::Instruction(Type *ty, unsig
   }
 }
 
+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) {

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Tue Feb 25 17:25:17 2014
@@ -482,7 +482,8 @@ bool LTOCodeGenerator::generateObjectFil
   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::generateObjectFil
 
   PassManager codeGenPasses;
 
-  codeGenPasses.add(new DataLayoutPass(*TargetMach->getDataLayout()));
+  codeGenPasses.add(new DataLayoutPass(mergedModule));
 
   formatted_raw_ostream Out(out);
 

Modified: llvm/trunk/lib/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Target.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Target.cpp (original)
+++ llvm/trunk/lib/Target/Target.cpp Tue Feb 25 17:25:17 2014
@@ -55,6 +55,8 @@ LLVMTargetDataRef LLVMCreateTargetData(c
 }
 
 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)));
 }
 

Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Tue Feb 25 17:25:17 2014
@@ -212,7 +212,8 @@ static LLVMBool LLVMTargetMachineEmit(LL
     *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) {

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Tue Feb 25 17:25:17 2014
@@ -299,9 +299,8 @@ static int compileModule(char **argv, LL
 
   // Add the target data from the target machine, if it exists, or the module.
   if (const DataLayout *DL = Target.getDataLayout())
-    PM.add(new DataLayoutPass(*DL));
-  else
-    PM.add(new DataLayoutPass(mod));
+    mod->setDataLayout(DL);
+  PM.add(new DataLayoutPass(mod));
 
   // Override default to generate verbose assembly.
   Target.setAsmVerbosityDefault(true);

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=202204&r1=202203&r2=202204&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Tue Feb 25 17:25:17 2014
@@ -430,11 +430,13 @@ int main(int argc, char **argv) {
 
   // Add an appropriate DataLayout instance for this module.
   const DataLayout *DL = M.get()->getDataLayout();
-  if (!DL && !DefaultDataLayout.empty())
-    DL = new DataLayout(DefaultDataLayout);
+  if (!DL && !DefaultDataLayout.empty()) {
+    M->setDataLayout(DefaultDataLayout);
+    DL = M.get()->getDataLayout();
+  }
 
   if (DL)
-    Passes.add(new DataLayoutPass(*DL));
+    Passes.add(new DataLayoutPass(M.get()));
 
   Triple ModuleTriple(M->getTargetTriple());
   TargetMachine *Machine = 0;
@@ -450,7 +452,7 @@ int main(int argc, char **argv) {
   if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
     FPasses.reset(new FunctionPassManager(M.get()));
     if (DL)
-      FPasses->add(new DataLayoutPass(*DL));
+      FPasses->add(new DataLayoutPass(M.get()));
     if (TM.get())
       TM->addAnalysisPasses(*FPasses);
 





More information about the llvm-commits mailing list