llvm.org GIT mirror llvm / e005d71
uselistorder: Pull bit through BitcodeWriterPass 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 Duncan P. N. Exon Smith 4 years ago
6 changed file(s) with 34 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
2525 /// \brief Create and return a pass that writes the module to the specified
2626 /// ostream. Note that this pass is designed for use with the legacy pass
2727 /// manager.
28 ModulePass *createBitcodeWriterPass(raw_ostream &Str);
28 ///
29 /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
30 /// reproduced when deserialized.
31 ModulePass *createBitcodeWriterPass(raw_ostream &Str,
32 bool ShouldPreserveUseListOrder = false);
2933
3034 /// \brief Pass for writing a module of IR out to a bitcode file.
3135 ///
3337 /// a pass for the legacy pass manager, use the function above.
3438 class BitcodeWriterPass {
3539 raw_ostream &OS;
40 bool ShouldPreserveUseListOrder;
3641
3742 public:
3843 /// \brief Construct a bitcode writer pass around a particular output stream.
39 explicit BitcodeWriterPass(raw_ostream &OS) : OS(OS) {}
44 ///
45 /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
46 /// reproduced when deserialized.
47 explicit BitcodeWriterPass(raw_ostream &OS,
48 bool ShouldPreserveUseListOrder = false)
49 : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
4050
4151 /// \brief Run the bitcode writer pass, and output the module to the selected
4252 /// output stream.
1919 using namespace llvm;
2020
2121 PreservedAnalyses BitcodeWriterPass::run(Module &M) {
22 WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
22 WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
2323 return PreservedAnalyses::all();
2424 }
2525
2626 namespace {
2727 class WriteBitcodePass : public ModulePass {
2828 raw_ostream &OS; // raw_ostream to print on
29 bool ShouldPreserveUseListOrder;
30
2931 public:
3032 static char ID; // Pass identification, replacement for typeid
31 explicit WriteBitcodePass(raw_ostream &o)
32 : ModulePass(ID), OS(o) {}
33 explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
34 : ModulePass(ID), OS(o),
35 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
3336
3437 const char *getPassName() const override { return "Bitcode Writer"; }
3538
3639 bool runOnModule(Module &M) override {
37 WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
40 WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
3841 return false;
3942 }
4043 };
4245
4346 char WriteBitcodePass::ID = 0;
4447
45 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
46 return new WriteBitcodePass(Str);
48 ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
49 bool ShouldPreserveUseListOrder) {
50 return new WriteBitcodePass(Str, ShouldPreserveUseListOrder);
4751 }
271271 if (OutputAssembly)
272272 Passes.add(createPrintModulePass(Out.os()));
273273 else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
274 Passes.add(createBitcodeWriterPass(Out.os()));
274 Passes.add(
275 createBitcodeWriterPass(Out.os(), shouldPreserveBitcodeUseListOrder()));
275276
276277 Passes.run(*M.get());
277278
3838 bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
3939 TargetMachine *TM, tool_output_file *Out,
4040 StringRef PassPipeline, OutputKind OK,
41 VerifierKind VK) {
41 VerifierKind VK,
42 bool ShouldPreserveBitcodeUseListOrder) {
4243 PassBuilder PB(TM);
4344
4445 FunctionAnalysisManager FAM(DebugPM);
7980 MPM.addPass(PrintModulePass(Out->os()));
8081 break;
8182 case OK_OutputBitcode:
82 MPM.addPass(BitcodeWriterPass(Out->os()));
83 MPM.addPass(
84 BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder));
8385 break;
8486 }
8587
5050 bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
5151 TargetMachine *TM, tool_output_file *Out,
5252 StringRef PassPipeline, opt_tool::OutputKind OK,
53 opt_tool::VerifierKind VK);
53 opt_tool::VerifierKind VK,
54 bool ShouldPreserveBitcodeUseListOrder);
5455 }
5556
5657 #endif
430430 // string. Hand off the rest of the functionality to the new code for that
431431 // layer.
432432 return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
433 PassPipeline, OK, VK)
433 PassPipeline, OK, VK,
434 shouldPreserveBitcodeUseListOrder())
434435 ? 0
435436 : 1;
436437 }
593594 if (OutputAssembly)
594595 Passes.add(createPrintModulePass(Out->os()));
595596 else
596 Passes.add(createBitcodeWriterPass(Out->os()));
597 Passes.add(createBitcodeWriterPass(Out->os(),
598 shouldPreserveBitcodeUseListOrder()));
597599 }
598600
599601 // Before executing passes, print the final values of the LLVM options.