diff options
author | Eric Christopher <echristo@gmail.com> | 2013-04-14 23:32:40 +0000 |
---|---|---|
committer | Eric Christopher <echristo@gmail.com> | 2013-04-14 23:32:40 +0000 |
commit | 10f8d2bb5bec3630ab4c56429e942fc422d94ddb (patch) | |
tree | ef306ba5faf26fdc39178e11395cc6bb5d1da980 /tools | |
parent | ef1762b6a1d3353790bdb415788e7d8963e70372 (diff) | |
download | external_llvm-10f8d2bb5bec3630ab4c56429e942fc422d94ddb.zip external_llvm-10f8d2bb5bec3630ab4c56429e942fc422d94ddb.tar.gz external_llvm-10f8d2bb5bec3630ab4c56429e942fc422d94ddb.tar.bz2 |
If we've specified a triple on the command line then go ahead
and use that as the default triple for the module and target
data layout.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179497 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/opt/opt.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index e385d7f..e3aa77d 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -36,6 +36,7 @@ #include "llvm/Support/PassNameParser.h" #include "llvm/Support/PluginLoader.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/Signals.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/SystemUtils.h" @@ -529,9 +530,8 @@ static TargetMachine* GetTargetMachine(Triple TheTriple) { const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple, Error); // Some modules don't specify a triple, and this is okay. - if (!TheTarget) { + if (!TheTarget) return 0; - } // Package up features to be passed to target/subtarget std::string FeaturesStr; @@ -598,9 +598,12 @@ int main(int argc, char **argv) { } // If we are supposed to override the target triple, do so now. - if (!TargetTriple.empty()) + const DataLayout *TD; + if (!TargetTriple.empty()) { M->setTargetTriple(Triple::normalize(TargetTriple)); - + TD = GetTargetMachine(Triple(TargetTriple))->getDataLayout(); + } + // Figure out what stream we are supposed to write to... OwningPtr<tool_output_file> Out; if (NoOutput) { @@ -641,16 +644,16 @@ int main(int argc, char **argv) { TLI->disableAllFunctions(); Passes.add(TLI); - // Add an appropriate DataLayout instance for this module. - DataLayout *TD = 0; - const std::string &ModuleDataLayout = M.get()->getDataLayout(); - if (!ModuleDataLayout.empty()) - TD = new DataLayout(ModuleDataLayout); - else if (!DefaultDataLayout.empty()) - TD = new DataLayout(DefaultDataLayout); - + // If we don't have a data layout by now go ahead and set it if we can. + if (!TD) { + const std::string &ModuleDataLayout = M.get()->getDataLayout(); + if (!ModuleDataLayout.empty()) + TD = new DataLayout(ModuleDataLayout); + else if (!DefaultDataLayout.empty()) + TD = new DataLayout(DefaultDataLayout); + } if (TD) - Passes.add(TD); + Passes.add(new DataLayout(*TD)); Triple ModuleTriple(M->getTargetTriple()); TargetMachine *Machine = 0; |