IR: Change clang to set -preserve-bc-uselistorder

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.

llvm-svn: 234920
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 1e34d7f..2d2526c 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -2678,6 +2678,15 @@
       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