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
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
--- /dev/null
+// 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"
// 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"
// 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"