]> granicus.if.org Git - clang/commitdiff
IR: Change clang to set -preserve-bc-uselistorder
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 14 Apr 2015 18:30:13 +0000 (18:30 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 14 Apr 2015 18:30:13 +0000 (18:30 +0000)
Change `clang` to set `-preserve-bc-uselistorder` for the driver options
`-emit-llvm` and `-save-temps`.  The former is useful for reproducing
results from `clang` in `opt` or `llc`, while the latter prevents
`-save-temps` from affecting the output.  This is part of PR5680.

`-preserve-bc-uselistorder=true` is currently on by default, but a
follow-up commit in LLVM will reverse it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234920 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/preserve-uselistorder.c [new file with mode: 0644]
test/Driver/save-temps.c

index 1e34d7f403a229ee4f21e20320053c4145f0d16f..2d2526c4bdf981f0d099410bf9008e5c50c6f9ed 100644 (file)
@@ -2678,6 +2678,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
       assert(JA.getType() == types::TY_PP_Asm &&
              "Unexpected output type!");
     }
+
+    // Preserve use-list order by default when emitting bitcode, so that
+    // loading the bitcode up in 'opt' or 'llc' and running passes gives the
+    // same result as running passes here.  For LTO, we don't need to preserve
+    // the use-list order, since serialization to bitcode is part of the flow.
+    if (JA.getType() == types::TY_LLVM_BC) {
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-preserve-bc-uselistorder");
+    }
   }
 
   // We normally speed up the clang process a bit by skipping destructors at
diff --git a/test/Driver/preserve-uselistorder.c b/test/Driver/preserve-uselistorder.c
new file mode 100644 (file)
index 0000000..ac02230
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang -target x86_64-apple-darwin -emit-llvm -arch x86_64 %s -### 2>&1 \
+// RUN:   | FileCheck %s
+// CHECK: "-emit-llvm-bc"
+// CHECK: "-preserve-bc-uselistorder"
+
+// RUN: %clang -target x86_64-apple-darwin -flto -arch x86_64 %s -### 2>&1 \
+// RUN:   | FileCheck -check-prefix=LTO %s
+// LTO:      "-emit-llvm-bc"
+// LTO-NOT:  "-preserve-bc-uselistorder"
index 438d748932b8f958314097ef3a3d6fa15b69f719..0b1a17f34f5fdf6f7cc9b53f27f2825efbb0884b 100644 (file)
@@ -1,6 +1,7 @@
 // RUN: %clang -target x86_64-apple-darwin -save-temps -arch x86_64 %s -### 2>&1 \
 // RUN:   | FileCheck %s
 // CHECK: "-o" "save-temps.i"
+// CHECK: "-preserve-bc-uselistorder"
 // CHECK: "-disable-llvm-optzns"
 // CHECK: "-o" "save-temps.bc"
 // CHECK: "-o" "save-temps.s"
@@ -12,6 +13,7 @@
 // RUN: %clang -target x86_64-apple-darwin -save-temps=cwd -arch x86_64 %s -### 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=CWD
 // CWD: "-o" "save-temps.i"
+// CWD: "-preserve-bc-uselistorder"
 // CWD: "-disable-llvm-optzns"
 // CWD: "-o" "save-temps.bc"
 // CWD: "-o" "save-temps.s"