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 | 339430f9935c4d3bb620f5e63be7ea3a7b3ea5ae (patch) | |
tree | 4c0929b332b0844dd8142e2eaf33885b332c6248 /llvm/tools | |
parent | 11918cff19ad106e16e851637e3dfef515c4861e (diff) | |
download | bcm5719-llvm-339430f9935c4d3bb620f5e63be7ea3a7b3ea5ae.tar.gz bcm5719-llvm-339430f9935c4d3bb620f5e63be7ea3a7b3ea5ae.zip |
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.
llvm-svn: 202204
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/llc/llc.cpp | 5 | ||||
-rw-r--r-- | llvm/tools/opt/opt.cpp | 10 |
2 files changed, 8 insertions, 7 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 5b311cb6173..bb72f252fe4 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -299,9 +299,8 @@ static int compileModule(char **argv, LLVMContext &Context) { // 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); diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 2b209d99c74..169e648e2eb 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/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); |