llvm.org GIT mirror llvm / 2c7f24d
uselistorder: Pull the bit through PrintModulePass Now the callers of `PrintModulePass()` (etc.) that care about use-list order in assembly pass in the flag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234969 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
6 changed file(s) with 27 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
3333 /// \brief Create and return a pass that writes the module to the specified
3434 /// \c raw_ostream.
3535 ModulePass *createPrintModulePass(raw_ostream &OS,
36 const std::string &Banner = "");
36 const std::string &Banner = "",
37 bool ShouldPreserveUseListOrder = false);
3738
3839 /// \brief Create and return a pass that prints functions to the specified
3940 /// \c raw_ostream as they are processed.
5253 class PrintModulePass {
5354 raw_ostream &OS;
5455 std::string Banner;
56 bool ShouldPreserveUseListOrder;
5557
5658 public:
5759 PrintModulePass();
58 PrintModulePass(raw_ostream &OS, const std::string &Banner = "");
60 PrintModulePass(raw_ostream &OS, const std::string &Banner = "",
61 bool ShouldPreserveUseListOrder = false);
5962
6063 PreservedAnalyses run(Module &M);
6164
1414 #include "llvm/IR/Function.h"
1515 #include "llvm/IR/Module.h"
1616 #include "llvm/IR/PassManager.h"
17 #include "llvm/IR/UseListOrder.h"
1817 #include "llvm/Pass.h"
1918 #include "llvm/Support/Debug.h"
2019 #include "llvm/Support/raw_ostream.h"
2120 using namespace llvm;
2221
2322 PrintModulePass::PrintModulePass() : OS(dbgs()) {}
24 PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner)
25 : OS(OS), Banner(Banner) {}
23 PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner,
24 bool ShouldPreserveUseListOrder)
25 : OS(OS), Banner(Banner),
26 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
2627
2728 PreservedAnalyses PrintModulePass::run(Module &M) {
2829 OS << Banner;
29 M.print(OS, nullptr, shouldPreserveAssemblyUseListOrder());
30 M.print(OS, nullptr, ShouldPreserveUseListOrder);
3031 return PreservedAnalyses::all();
3132 }
3233
4748 public:
4849 static char ID;
4950 PrintModulePassWrapper() : ModulePass(ID) {}
50 PrintModulePassWrapper(raw_ostream &OS, const std::string &Banner)
51 : ModulePass(ID), P(OS, Banner) {}
51 PrintModulePassWrapper(raw_ostream &OS, const std::string &Banner,
52 bool ShouldPreserveUseListOrder)
53 : ModulePass(ID), P(OS, Banner, ShouldPreserveUseListOrder) {}
5254
5355 bool runOnModule(Module &M) override {
5456 P.run(M);
113115 false)
114116
115117 ModulePass *llvm::createPrintModulePass(llvm::raw_ostream &OS,
116 const std::string &Banner) {
117 return new PrintModulePassWrapper(OS, Banner);
118 const std::string &Banner,
119 bool ShouldPreserveUseListOrder) {
120 return new PrintModulePassWrapper(OS, Banner, ShouldPreserveUseListOrder);
118121 }
119122
120123 FunctionPass *llvm::createPrintFunctionPass(llvm::raw_ostream &OS,
269269 }
270270
271271 if (OutputAssembly)
272 Passes.add(createPrintModulePass(Out.os()));
272 Passes.add(createPrintModulePass(Out.os(), "",
273 shouldPreserveAssemblyUseListOrder()));
273274 else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
274275 Passes.add(
275276 createBitcodeWriterPass(Out.os(), shouldPreserveBitcodeUseListOrder()));
3939 TargetMachine *TM, tool_output_file *Out,
4040 StringRef PassPipeline, OutputKind OK,
4141 VerifierKind VK,
42 bool ShouldPreserveAssemblyUseListOrder,
4243 bool ShouldPreserveBitcodeUseListOrder) {
4344 PassBuilder PB(TM);
4445
7778 case OK_NoOutput:
7879 break; // No output pass needed.
7980 case OK_OutputAssembly:
80 MPM.addPass(PrintModulePass(Out->os()));
81 MPM.addPass(
82 PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder));
8183 break;
8284 case OK_OutputBitcode:
8385 MPM.addPass(
5151 TargetMachine *TM, tool_output_file *Out,
5252 StringRef PassPipeline, opt_tool::OutputKind OK,
5353 opt_tool::VerifierKind VK,
54 bool ShouldPreserveAssemblyUseListOrder,
5455 bool ShouldPreserveBitcodeUseListOrder);
5556 }
5657
431431 // layer.
432432 return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
433433 PassPipeline, OK, VK,
434 shouldPreserveAssemblyUseListOrder(),
434435 shouldPreserveBitcodeUseListOrder())
435436 ? 0
436437 : 1;
555556 }
556557
557558 if (PrintEachXForm)
558 Passes.add(createPrintModulePass(errs()));
559 Passes.add(createPrintModulePass(errs(), "",
560 shouldPreserveAssemblyUseListOrder()));
559561 }
560562
561563 if (StandardLinkOpts) {
592594 // Write bitcode or assembly to the output as the last step...
593595 if (!NoOutput && !AnalyzeOnly) {
594596 if (OutputAssembly)
595 Passes.add(createPrintModulePass(Out->os()));
597 Passes.add(createPrintModulePass(Out->os(), "",
598 shouldPreserveAssemblyUseListOrder()));
596599 else
597600 Passes.add(createBitcodeWriterPass(Out->os(),
598601 shouldPreserveBitcodeUseListOrder()));