From 8b376eb892a4667beb08a0cc0f68d370b99e10a5 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 15 Apr 2015 02:12:41 +0000 Subject: [PATCH] uselistorder: Pull the assembly bit up out of the printer 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 | 7 +++++-- lib/IR/AsmWriter.cpp | 6 +++--- lib/IR/IRPrintingPasses.cpp | 4 +++- tools/llvm-dis/llvm-dis.cpp | 3 ++- tools/llvm-link/llvm-link.cpp | 2 +- tools/verify-uselistorder/verify-uselistorder.cpp | 10 ++-------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/llvm/IR/Module.h b/include/llvm/IR/Module.h index ac60c8e885e..dbaf322263d 100644 --- a/include/llvm/IR/Module.h +++ b/include/llvm/IR/Module.h @@ -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; diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 6f4d99767d0..a2eb545f8b1 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -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); } diff --git a/lib/IR/IRPrintingPasses.cpp b/lib/IR/IRPrintingPasses.cpp index 91ccfbb2f46..e872387022f 100644 --- a/lib/IR/IRPrintingPasses.cpp +++ b/lib/IR/IRPrintingPasses.cpp @@ -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(); } diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index f914df54cf3..106fc18ebf5 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -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(); diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index daffec9371d..9d5369df66d 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -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()); diff --git a/tools/verify-uselistorder/verify-uselistorder.cpp b/tools/verify-uselistorder/verify-uselistorder.cpp index 9d297fa030c..795d035d3df 100644 --- a/tools/verify-uselistorder/verify-uselistorder.cpp +++ b/tools/verify-uselistorder/verify-uselistorder.cpp @@ -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); -- 2.34.1