From 356deb5ecde78fdef706e325325c23c828666b9f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 25 Feb 2014 23:25:17 +0000 Subject: 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 --- tools/opt/opt.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tools/opt') diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 2b209d99c7..169e648e2e 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -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); -- cgit v1.2.3