Make opt grab the triple from the module and use it to initialize the target machine.
authorNadav Rotem <nrotem@apple.com>
Tue, 1 Jan 2013 08:00:32 +0000 (08:00 +0000)
committerNadav Rotem <nrotem@apple.com>
Tue, 1 Jan 2013 08:00:32 +0000 (08:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171341 91177308-0d34-0410-b5e6-96231b3b80d8

test/Analysis/CostModel/no_info.ll
test/Transforms/BBVectorize/loop1.ll
tools/opt/opt.cpp

index d20d56b79a7f01159962e142924a2d8464bc78ed..f3f165b1b52aed9a4d8f4c6428aae60f8132a843 100644 (file)
@@ -1,11 +1,8 @@
 ; RUN: opt < %s -cost-model -analyze | FileCheck %s
 
 ; The cost model does not have any target information so it can't make a decision.
-; Notice that OPT does not read the triple information from the module itself, only through the command line.
 
-; This info ignored:
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
-target triple = "x86_64-apple-macosx10.8.0"
+; -- No triple in this module --
 
 ;CHECK: Unknown cost {{.*}} add
 ;CHECK: Unknown cost {{.*}} ret
index c22ea5852a1bd6458a2bd4f5246f989d07f8cecd..766eefaf5eae3275c9b33099c04fca8efeeadd03 100644 (file)
@@ -1,6 +1,6 @@
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
-; RUN: opt < %s -bb-vectorize -bb-vectorize-req-chain-depth=3 -instcombine -gvn -S | FileCheck %s
+; RUN: opt < %s -bb-vectorize -bb-vectorize-req-chain-depth=3 -instcombine -gvn -S -mtriple=unknown | FileCheck %s
 ; RUN: opt < %s -basicaa -loop-unroll -unroll-threshold=45 -unroll-allow-partial -bb-vectorize -bb-vectorize-req-chain-depth=3 -instcombine -gvn -S | FileCheck %s -check-prefix=CHECK-UNRL
 ; The second check covers the use of alias analysis (with loop unrolling).
 
index 1bbe4e3623aaebf3c39447d3aa88ca86356903d7..af37e5e8c21b77b47db70937d00398f63fecf266 100644 (file)
@@ -524,16 +524,11 @@ CodeGenOpt::Level GetCodeGenOptLevel() {
 }
 
 // Returns the TargetMachine instance or zero if no triple is provided.
-static TargetMachine* GetTargetMachine(std::string TripleStr) {
-  if (TripleStr.empty())
-    return 0;
-
-  // Get the target specific parser.
+static TargetMachine* GetTargetMachine(Triple TheTriple) {
   std::string Error;
-  Triple TheTriple(Triple::normalize(TargetTriple));
-
   const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
                                                          Error);
+  // Some modules don't specify a triple, and this is okay.
   if (!TheTarget) {
     return 0;
   }
@@ -656,7 +651,12 @@ int main(int argc, char **argv) {
   if (TD)
     Passes.add(TD);
 
-  std::auto_ptr<TargetMachine> TM(GetTargetMachine(TargetTriple));
+  Triple ModuleTriple(M->getTargetTriple());
+  TargetMachine *Machine = 0;
+  if (ModuleTriple.getArch())
+    Machine = GetTargetMachine(Triple(ModuleTriple));
+  std::auto_ptr<TargetMachine> TM(Machine);
+
   if (TM.get()) {
     Passes.add(new TargetTransformInfo(TM->getScalarTargetTransformInfo(),
                                        TM->getVectorTargetTransformInfo()));