uselistorder: Pull bit through BitcodeWriterPass
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 15 Apr 2015 00:34:24 +0000 (00:34 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 15 Apr 2015 00:34:24 +0000 (00:34 +0000)
Now the callers of `BitcodeWriterPass` decide whether or not to preserve
bitcode use-list order.

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

include/llvm/Bitcode/BitcodeWriterPass.h
lib/Bitcode/Writer/BitcodeWriterPass.cpp
tools/llvm-extract/llvm-extract.cpp
tools/opt/NewPMDriver.cpp
tools/opt/NewPMDriver.h
tools/opt/opt.cpp

index 8fe9b7e8434d4f52b0d07b22aa74ac4bb6d55f51..ae915c688ba0865832a4ced07ec1daee457f8a11 100644 (file)
@@ -26,7 +26,11 @@ class PreservedAnalyses;
 /// \brief Create and return a pass that writes the module to the specified
 /// ostream. Note that this pass is designed for use with the legacy pass
 /// manager.
 /// \brief Create and return a pass that writes the module to the specified
 /// ostream. Note that this pass is designed for use with the legacy pass
 /// manager.
-ModulePass *createBitcodeWriterPass(raw_ostream &Str);
+///
+/// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
+/// reproduced when deserialized.
+ModulePass *createBitcodeWriterPass(raw_ostream &Str,
+                                    bool ShouldPreserveUseListOrder = false);
 
 /// \brief Pass for writing a module of IR out to a bitcode file.
 ///
 
 /// \brief Pass for writing a module of IR out to a bitcode file.
 ///
@@ -34,10 +38,16 @@ ModulePass *createBitcodeWriterPass(raw_ostream &Str);
 /// a pass for the legacy pass manager, use the function above.
 class BitcodeWriterPass {
   raw_ostream &OS;
 /// a pass for the legacy pass manager, use the function above.
 class BitcodeWriterPass {
   raw_ostream &OS;
+  bool ShouldPreserveUseListOrder;
 
 public:
   /// \brief Construct a bitcode writer pass around a particular output stream.
 
 public:
   /// \brief Construct a bitcode writer pass around a particular output stream.
-  explicit BitcodeWriterPass(raw_ostream &OS) : OS(OS) {}
+  ///
+  /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
+  /// reproduced when deserialized.
+  explicit BitcodeWriterPass(raw_ostream &OS,
+                             bool ShouldPreserveUseListOrder = false)
+      : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
 
   /// \brief Run the bitcode writer pass, and output the module to the selected
   /// output stream.
 
   /// \brief Run the bitcode writer pass, and output the module to the selected
   /// output stream.
index fccc9e7a231b456cd7e89076b1126845c79564e0..ddb121a109a13c1a5e366f37f98084b242f88d10 100644 (file)
 using namespace llvm;
 
 PreservedAnalyses BitcodeWriterPass::run(Module &M) {
 using namespace llvm;
 
 PreservedAnalyses BitcodeWriterPass::run(Module &M) {
-  WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
+  WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
   return PreservedAnalyses::all();
 }
 
 namespace {
   class WriteBitcodePass : public ModulePass {
     raw_ostream &OS; // raw_ostream to print on
   return PreservedAnalyses::all();
 }
 
 namespace {
   class WriteBitcodePass : public ModulePass {
     raw_ostream &OS; // raw_ostream to print on
+    bool ShouldPreserveUseListOrder;
+
   public:
     static char ID; // Pass identification, replacement for typeid
   public:
     static char ID; // Pass identification, replacement for typeid
-    explicit WriteBitcodePass(raw_ostream &o)
-      : ModulePass(ID), OS(o) {}
+    explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
+        : ModulePass(ID), OS(o),
+          ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
 
     const char *getPassName() const override { return "Bitcode Writer"; }
 
     bool runOnModule(Module &M) override {
 
     const char *getPassName() const override { return "Bitcode Writer"; }
 
     bool runOnModule(Module &M) override {
-      WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
+      WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
       return false;
     }
   };
       return false;
     }
   };
@@ -43,6 +46,7 @@ namespace {
 
 char WriteBitcodePass::ID = 0;
 
 
 char WriteBitcodePass::ID = 0;
 
-ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
-  return new WriteBitcodePass(Str);
+ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
+                                          bool ShouldPreserveUseListOrder) {
+  return new WriteBitcodePass(Str, ShouldPreserveUseListOrder);
 }
 }
index 443ee653c8e72811404ef090fafaf2844a5c7685..d67b41bea21fb8f25e2cad19ed1c1b6280ac141d 100644 (file)
@@ -272,7 +272,8 @@ int main(int argc, char **argv) {
   if (OutputAssembly)
     Passes.add(createPrintModulePass(Out.os()));
   else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
   if (OutputAssembly)
     Passes.add(createPrintModulePass(Out.os()));
   else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
-    Passes.add(createBitcodeWriterPass(Out.os()));
+    Passes.add(
+        createBitcodeWriterPass(Out.os(), shouldPreserveBitcodeUseListOrder()));
 
   Passes.run(*M.get());
 
 
   Passes.run(*M.get());
 
index 9216d5c939ae3991f27b4fc01b70775dfaf0eca0..8d4b279c6f77c13b9f3724957835f54079caee0d 100644 (file)
@@ -39,7 +39,8 @@ static cl::opt<bool>
 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
                            TargetMachine *TM, tool_output_file *Out,
                            StringRef PassPipeline, OutputKind OK,
 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
                            TargetMachine *TM, tool_output_file *Out,
                            StringRef PassPipeline, OutputKind OK,
-                           VerifierKind VK) {
+                           VerifierKind VK,
+                           bool ShouldPreserveBitcodeUseListOrder) {
   PassBuilder PB(TM);
 
   FunctionAnalysisManager FAM(DebugPM);
   PassBuilder PB(TM);
 
   FunctionAnalysisManager FAM(DebugPM);
@@ -80,7 +81,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
     MPM.addPass(PrintModulePass(Out->os()));
     break;
   case OK_OutputBitcode:
     MPM.addPass(PrintModulePass(Out->os()));
     break;
   case OK_OutputBitcode:
-    MPM.addPass(BitcodeWriterPass(Out->os()));
+    MPM.addPass(
+        BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder));
     break;
   }
 
     break;
   }
 
index 5384fe295e132641656260ad1f735557c8b6a54f..e9a751da25027c7d4c9af69b0348c8cb87bd6d8a 100644 (file)
@@ -51,7 +51,8 @@ enum VerifierKind {
 bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
                      TargetMachine *TM, tool_output_file *Out,
                      StringRef PassPipeline, opt_tool::OutputKind OK,
 bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
                      TargetMachine *TM, tool_output_file *Out,
                      StringRef PassPipeline, opt_tool::OutputKind OK,
-                     opt_tool::VerifierKind VK);
+                     opt_tool::VerifierKind VK,
+                     bool ShouldPreserveBitcodeUseListOrder);
 }
 
 #endif
 }
 
 #endif
index b0951a4887e3b54994e54033675d3f94ae3c12ce..8946558d219219f74f5963cd278c09686ad83f05 100644 (file)
@@ -431,7 +431,8 @@ int main(int argc, char **argv) {
     // string. Hand off the rest of the functionality to the new code for that
     // layer.
     return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
     // string. Hand off the rest of the functionality to the new code for that
     // layer.
     return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
-                           PassPipeline, OK, VK)
+                           PassPipeline, OK, VK,
+                           shouldPreserveBitcodeUseListOrder())
                ? 0
                : 1;
   }
                ? 0
                : 1;
   }
@@ -594,7 +595,8 @@ int main(int argc, char **argv) {
     if (OutputAssembly)
       Passes.add(createPrintModulePass(Out->os()));
     else
     if (OutputAssembly)
       Passes.add(createPrintModulePass(Out->os()));
     else
-      Passes.add(createBitcodeWriterPass(Out->os()));
+      Passes.add(createBitcodeWriterPass(Out->os(),
+                                         shouldPreserveBitcodeUseListOrder()));
   }
 
   // Before executing passes, print the final values of the LLVM options.
   }
 
   // Before executing passes, print the final values of the LLVM options.