uselistorder: Pull the assembly bit up out of the printer
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 15 Apr 2015 02:12:41 +0000 (02:12 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 15 Apr 2015 02:12:41 +0000 (02:12 +0000)
Pull the `-preserve-ll-uselistorder` bit up through all the callers of
`Module::print()`.  I converted callers of `operator<<` to
`Module::print()` where necessary to pull the bit through.

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

include/llvm/IR/Module.h
lib/IR/AsmWriter.cpp
lib/IR/IRPrintingPasses.cpp
tools/llvm-dis/llvm-dis.cpp
tools/llvm-link/llvm-link.cpp
tools/verify-uselistorder/verify-uselistorder.cpp

index ac60c8e885e28dbcd59df6b7963410bcb6a7bbc4..dbaf322263d43e00d3e2feadcad0ba2e27e40486 100644 (file)
@@ -642,8 +642,11 @@ public:
 /// @{
 
   /// Print the module to an output stream with an optional
-  /// AssemblyAnnotationWriter.
-  void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const;
+  /// AssemblyAnnotationWriter.  If \c ShouldPreserveUseListOrder, then include
+  /// uselistorder directives so that use-lists can be recreated when reading
+  /// the assembly.
+  void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW,
+             bool ShouldPreserveUseListOrder = false) const;
 
   /// Dump the module to stderr (for debugging).
   void dump() const;
index 6f4d99767d0d2c6c4c073b66de9eeeaf2f4c51b9..a2eb545f8b1952044cf8e75084e5cb1e375c54bf 100644 (file)
@@ -3071,11 +3071,11 @@ void Function::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
   W.printFunction(this);
 }
 
-void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const {
+void Module::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
+                   bool ShouldPreserveUseListOrder) const {
   SlotTracker SlotTable(this);
   formatted_raw_ostream OS(ROS);
-  AssemblyWriter W(OS, SlotTable, this, AAW,
-                   shouldPreserveAssemblyUseListOrder());
+  AssemblyWriter W(OS, SlotTable, this, AAW, ShouldPreserveUseListOrder);
   W.printModule(this);
 }
 
index 91ccfbb2f46ec0a5791e3e716ecf2805b76f30ac..e872387022ff0d7d821f2f6a04199f713a932628 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/IR/UseListOrder.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -25,7 +26,8 @@ PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner)
     : OS(OS), Banner(Banner) {}
 
 PreservedAnalyses PrintModulePass::run(Module &M) {
-  OS << Banner << M;
+  OS << Banner;
+  M.print(OS, nullptr, shouldPreserveAssemblyUseListOrder());
   return PreservedAnalyses::all();
 }
 
index f914df54cf3c121bdcb5990ac2f32787de865704..106fc18ebf58639d7b8bc6e0681fbc6fe0334456 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/IR/UseListOrder.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/DataStream.h"
 #include "llvm/Support/FileSystem.h"
@@ -189,7 +190,7 @@ int main(int argc, char **argv) {
 
   // All that llvm-dis does is write the assembly to a file.
   if (!DontPrint)
-    M->print(Out->os(), Annotator.get());
+    M->print(Out->os(), Annotator.get(), shouldPreserveAssemblyUseListOrder());
 
   // Declare success.
   Out->keep();
index daffec9371d72e20f54dbddf2c0047580b2ffed4..9d5369df66d81ab46683bb34e6c2dac199b99c04 100644 (file)
@@ -150,7 +150,7 @@ int main(int argc, char **argv) {
 
   if (Verbose) errs() << "Writing bitcode...\n";
   if (OutputAssembly) {
-    Out.os() << *Composite;
+    Composite->print(Out.os(), nullptr, shouldPreserveAssemblyUseListOrder());
   } else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
     WriteBitcodeToFile(Composite.get(), Out.os(),
                        shouldPreserveBitcodeUseListOrder());
index 9d297fa030c37aa3188619aa03e5a012d1484cc6..795d035d3df4f809bf64c2676091e426dbdd49a4 100644 (file)
@@ -144,7 +144,7 @@ bool TempFile::writeAssembly(const Module &M) const {
     return true;
   }
 
-  OS << M;
+  M.print(OS, nullptr, /* ShouldPreserveUseListOrder */ true);
   return false;
 }
 
@@ -540,14 +540,8 @@ int main(int argc, char **argv) {
     return 1;
   }
 
-  outs() << "*** verify-uselistorder ***\n";
-  // Can't verify if order isn't preserved.
-  if (!shouldPreserveAssemblyUseListOrder()) {
-    errs() << "warning: forcing -preserve-ll-uselistorder\n";
-    setPreserveAssemblyUseListOrder(true);
-  }
-
   // Verify the use lists now and after reversing them.
+  outs() << "*** verify-uselistorder ***\n";
   verifyUseListOrder(*M);
   outs() << "reverse\n";
   reverseUseLists(*M);