diff --git a/include/llvm/IR/IRPrintingPasses.h b/include/llvm/IR/IRPrintingPasses.h index 7f2027b6e29..5f1d56f7e83 100644 --- a/include/llvm/IR/IRPrintingPasses.h +++ b/include/llvm/IR/IRPrintingPasses.h @@ -34,7 +34,8 @@ class raw_ostream; /// \brief Create and return a pass that writes the module to the specified /// \c raw_ostream. ModulePass *createPrintModulePass(raw_ostream &OS, - const std::string &Banner = ""); + const std::string &Banner = "", + bool ShouldPreserveUseListOrder = false); /// \brief Create and return a pass that prints functions to the specified /// \c raw_ostream as they are processed. @@ -53,10 +54,12 @@ BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS, class PrintModulePass { raw_ostream &OS; std::string Banner; + bool ShouldPreserveUseListOrder; public: PrintModulePass(); - PrintModulePass(raw_ostream &OS, const std::string &Banner = ""); + PrintModulePass(raw_ostream &OS, const std::string &Banner = "", + bool ShouldPreserveUseListOrder = false); PreservedAnalyses run(Module &M); diff --git a/lib/IR/IRPrintingPasses.cpp b/lib/IR/IRPrintingPasses.cpp index e872387022f..c1ac336c1fb 100644 --- a/lib/IR/IRPrintingPasses.cpp +++ b/lib/IR/IRPrintingPasses.cpp @@ -15,19 +15,20 @@ #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" using namespace llvm; PrintModulePass::PrintModulePass() : OS(dbgs()) {} -PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner) - : OS(OS), Banner(Banner) {} +PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner, + bool ShouldPreserveUseListOrder) + : OS(OS), Banner(Banner), + ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {} PreservedAnalyses PrintModulePass::run(Module &M) { OS << Banner; - M.print(OS, nullptr, shouldPreserveAssemblyUseListOrder()); + M.print(OS, nullptr, ShouldPreserveUseListOrder); return PreservedAnalyses::all(); } @@ -48,8 +49,9 @@ class PrintModulePassWrapper : public ModulePass { public: static char ID; PrintModulePassWrapper() : ModulePass(ID) {} - PrintModulePassWrapper(raw_ostream &OS, const std::string &Banner) - : ModulePass(ID), P(OS, Banner) {} + PrintModulePassWrapper(raw_ostream &OS, const std::string &Banner, + bool ShouldPreserveUseListOrder) + : ModulePass(ID), P(OS, Banner, ShouldPreserveUseListOrder) {} bool runOnModule(Module &M) override { P.run(M); @@ -114,8 +116,9 @@ INITIALIZE_PASS(PrintBasicBlockPass, "print-bb", "Print BB to stderr", false, false) ModulePass *llvm::createPrintModulePass(llvm::raw_ostream &OS, - const std::string &Banner) { - return new PrintModulePassWrapper(OS, Banner); + const std::string &Banner, + bool ShouldPreserveUseListOrder) { + return new PrintModulePassWrapper(OS, Banner, ShouldPreserveUseListOrder); } FunctionPass *llvm::createPrintFunctionPass(llvm::raw_ostream &OS, diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index d67b41bea21..1a477934357 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -270,7 +270,8 @@ int main(int argc, char **argv) { } if (OutputAssembly) - Passes.add(createPrintModulePass(Out.os())); + Passes.add(createPrintModulePass(Out.os(), "", + shouldPreserveAssemblyUseListOrder())); else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true)) Passes.add( createBitcodeWriterPass(Out.os(), shouldPreserveBitcodeUseListOrder())); diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index 8d4b279c6f7..3030d65743a 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/tools/opt/NewPMDriver.cpp @@ -40,6 +40,7 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, TargetMachine *TM, tool_output_file *Out, StringRef PassPipeline, OutputKind OK, VerifierKind VK, + bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder) { PassBuilder PB(TM); @@ -78,7 +79,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, case OK_NoOutput: break; // No output pass needed. case OK_OutputAssembly: - MPM.addPass(PrintModulePass(Out->os())); + MPM.addPass( + PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder)); break; case OK_OutputBitcode: MPM.addPass( diff --git a/tools/opt/NewPMDriver.h b/tools/opt/NewPMDriver.h index e9a751da250..349a7b1267f 100644 --- a/tools/opt/NewPMDriver.h +++ b/tools/opt/NewPMDriver.h @@ -52,6 +52,7 @@ bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, TargetMachine *TM, tool_output_file *Out, StringRef PassPipeline, opt_tool::OutputKind OK, opt_tool::VerifierKind VK, + bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder); } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 8946558d219..28cbe4f1a94 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -432,6 +432,7 @@ int main(int argc, char **argv) { // layer. return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(), PassPipeline, OK, VK, + shouldPreserveAssemblyUseListOrder(), shouldPreserveBitcodeUseListOrder()) ? 0 : 1; @@ -556,7 +557,8 @@ int main(int argc, char **argv) { } if (PrintEachXForm) - Passes.add(createPrintModulePass(errs())); + Passes.add(createPrintModulePass(errs(), "", + shouldPreserveAssemblyUseListOrder())); } if (StandardLinkOpts) { @@ -593,7 +595,8 @@ int main(int argc, char **argv) { // Write bitcode or assembly to the output as the last step... if (!NoOutput && !AnalyzeOnly) { if (OutputAssembly) - Passes.add(createPrintModulePass(Out->os())); + Passes.add(createPrintModulePass(Out->os(), "", + shouldPreserveAssemblyUseListOrder())); else Passes.add(createBitcodeWriterPass(Out->os(), shouldPreserveBitcodeUseListOrder()));