[llvm] r179497 - If we've specified a triple on the command line then go ahead

Eric Christopher echristo at gmail.com
Sun Apr 14 16:32:40 PDT 2013


Author: echristo
Date: Sun Apr 14 18:32:40 2013
New Revision: 179497

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

Modified:
    llvm/trunk/tools/opt/opt.cpp

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=179497&r1=179496&r2=179497&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Sun Apr 14 18:32:40 2013
@@ -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(T
   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;





More information about the llvm-commits mailing list