uselistorder: Pull the bit through WriteToBitcodFile()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 15 Apr 2015 00:10:50 +0000 (00:10 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 15 Apr 2015 00:10:50 +0000 (00:10 +0000)
Change the callers of `WriteToBitcodeFile()` to pass `true` or
`shouldPreserveBitcodeUseListOrder()` explicitly.  I left the callers
that want to send `false` alone.

I'll keep pushing the bit higher until hopefully I can delete the global
`cl::opt` entirely.

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

include/llvm/Bitcode/ReaderWriter.h
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Bitcode/Writer/BitcodeWriterPass.cpp
lib/LTO/LTOCodeGenerator.cpp
tools/bugpoint/OptimizerDriver.cpp
tools/gold/gold-plugin.cpp
tools/llvm-as/llvm-as.cpp
tools/llvm-link/llvm-link.cpp
tools/verify-uselistorder/verify-uselistorder.cpp

index 254949d1a33a4b5bf1bccd37d5ba16a270c11270..9d30098fddee408ab5c9accc88acef100e93d2c2 100644 (file)
@@ -56,11 +56,16 @@ namespace llvm {
   parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
                    DiagnosticHandlerFunction DiagnosticHandler = nullptr);
 
-  /// WriteBitcodeToFile - Write the specified module to the specified
-  /// raw output stream.  For streams where it matters, the given stream
-  /// should be in "binary" mode.
-  void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
-
+  /// \brief Write the specified module to the specified raw output stream.
+  ///
+  /// For streams where it matters, the given stream should be in "binary"
+  /// mode.
+  ///
+  /// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
+  /// Value in \c M.  These will be reconstructed exactly when \a M is
+  /// deserialized.
+  void WriteBitcodeToFile(const Module *M, raw_ostream &Out,
+                          bool ShouldPreserveUseListOrder = false);
 
   /// isBitcodeWrapper - Return true if the given bytes are the magic bytes
   /// for an LLVM IR bitcode wrapper.
index ff02b7d269ba8a0676ba90307b70f914e5c69927..e209b03b97a802a8572d4edf6a4e381e02fbfe57 100644 (file)
@@ -2312,7 +2312,8 @@ static void WriteBlockInfo(const ValueEnumerator &VE, BitstreamWriter &Stream) {
 }
 
 /// WriteModule - Emit the specified module to the bitstream.
-static void WriteModule(const Module *M, BitstreamWriter &Stream) {
+static void WriteModule(const Module *M, BitstreamWriter &Stream,
+                        bool ShouldPreserveUseListOrder) {
   Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
 
   SmallVector<unsigned, 1> Vals;
@@ -2321,7 +2322,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
   Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);
 
   // Analyze the module, enumerating globals, functions, etc.
-  ValueEnumerator VE(*M, shouldPreserveBitcodeUseListOrder());
+  ValueEnumerator VE(*M, ShouldPreserveUseListOrder);
 
   // Emit blockinfo, which defines the standard abbreviations etc.
   WriteBlockInfo(VE, Stream);
@@ -2440,7 +2441,8 @@ static void EmitDarwinBCHeaderAndTrailer(SmallVectorImpl<char> &Buffer,
 
 /// WriteBitcodeToFile - Write the specified module to the specified output
 /// stream.
-void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
+void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out,
+                              bool ShouldPreserveUseListOrder) {
   SmallVector<char, 0> Buffer;
   Buffer.reserve(256*1024);
 
@@ -2463,7 +2465,7 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
     Stream.Emit(0xD, 4);
 
     // Emit the module.
-    WriteModule(M, Stream);
+    WriteModule(M, Stream, ShouldPreserveUseListOrder);
   }
 
   if (TT.isOSDarwin())
index 25456a4562171cf876cb511afbd816588fe6decd..fccc9e7a231b456cd7e89076b1126845c79564e0 100644 (file)
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/IR/UseListOrder.h"
 #include "llvm/Pass.h"
 using namespace llvm;
 
 PreservedAnalyses BitcodeWriterPass::run(Module &M) {
-  WriteBitcodeToFile(&M, OS);
+  WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
   return PreservedAnalyses::all();
 }
 
@@ -34,7 +35,7 @@ namespace {
     const char *getPassName() const override { return "Bitcode Writer"; }
 
     bool runOnModule(Module &M) override {
-      WriteBitcodeToFile(&M, OS);
+      WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
       return false;
     }
   };
index 6745c5707545d4db5a43037ee89fd08c8942ce4f..c9ff5b2d019cffe9a92791cd6c8887873b9c15e1 100644 (file)
@@ -215,7 +215,8 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
   }
 
   // write bitcode to it
-  WriteBitcodeToFile(IRLinker.getModule(), Out.os());
+  WriteBitcodeToFile(IRLinker.getModule(), Out.os(),
+                     shouldPreserveBitcodeUseListOrder());
   Out.os().close();
 
   if (Out.os().has_error()) {
index 481f343c98878b42bc7dda358a777020b0d72c55..3ac263c6de9e2a711031d5efeff5a5f74f85f5f5 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/UseListOrder.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -55,7 +56,7 @@ namespace {
 /// file.  If an error occurs, true is returned.
 ///
 static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) {
-  WriteBitcodeToFile(M, Out.os());
+  WriteBitcodeToFile(M, Out.os(), shouldPreserveBitcodeUseListOrder());
   Out.os().close();
   if (!Out.os().has_error()) {
     Out.keep();
@@ -151,7 +152,7 @@ bool BugDriver::runPasses(Module *Program,
 
   tool_output_file InFile(InputFilename, InputFD);
 
-  WriteBitcodeToFile(Program, InFile.os());
+  WriteBitcodeToFile(Program, InFile.os(), shouldPreserveBitcodeUseListOrder());
   InFile.os().close();
   if (InFile.os().has_error()) {
     errs() << "Error writing bitcode file: " << InputFilename << "\n";
index 2c7bf5a64eef3b5e5f7b8185fce2d31373911309..31a9b950ce99c98c8242d1e03ecfcb7e68912543 100644 (file)
@@ -734,12 +734,13 @@ static void runLTOPasses(Module &M, TargetMachine &TM) {
   passes.run(M);
 }
 
-static void saveBCFile(StringRef Path, Module &M) {
+static void saveBCFile(StringRef Path, Module &M,
+                       bool ShouldPreserveUseListOrder) {
   std::error_code EC;
   raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::F_None);
   if (EC)
     message(LDPL_FATAL, "Failed to write the output file.");
-  WriteBitcodeToFile(&M, OS);
+  WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true);
 }
 
 static void codegen(Module &M) {
index ae8ca569fd4964fb4825c61e45daccb956b7acd4..1d48596a24f37d2cc547853b47e1e4bdf61ffe5d 100644 (file)
@@ -79,7 +79,7 @@ static void WriteOutputFile(const Module *M) {
   }
 
   if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
-    WriteBitcodeToFile(M, Out->os());
+    WriteBitcodeToFile(M, Out->os(), shouldPreserveBitcodeUseListOrder());
 
   // Declare success.
   Out->keep();
index 5f1dccb378ad6f537af6bf1b07cf3d9976335b21..daffec9371d72e20f54dbddf2c0047580b2ffed4 100644 (file)
@@ -152,7 +152,8 @@ int main(int argc, char **argv) {
   if (OutputAssembly) {
     Out.os() << *Composite;
   } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
-    WriteBitcodeToFile(Composite.get(), Out.os());
+    WriteBitcodeToFile(Composite.get(), Out.os(),
+                       shouldPreserveBitcodeUseListOrder());
 
   // Declare success.
   Out.keep();
index c88df1c6669a4f2ed5b8db99e5d4d4988a255233..9d297fa030c37aa3188619aa03e5a012d1484cc6 100644 (file)
@@ -131,7 +131,7 @@ bool TempFile::writeBitcode(const Module &M) const {
     return true;
   }
 
-  WriteBitcodeToFile(&M, OS);
+  WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true);
   return false;
 }
 
@@ -542,10 +542,6 @@ int main(int argc, char **argv) {
 
   outs() << "*** verify-uselistorder ***\n";
   // Can't verify if order isn't preserved.
-  if (!shouldPreserveBitcodeUseListOrder()) {
-    errs() << "warning: forcing -preserve-bc-uselistorder\n";
-    setPreserveBitcodeUseListOrder(true);
-  }
   if (!shouldPreserveAssemblyUseListOrder()) {
     errs() << "warning: forcing -preserve-ll-uselistorder\n";
     setPreserveAssemblyUseListOrder(true);