BitcodeWriterPass.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===-- BitcodeWriterPass.h - Bitcode writing pass --------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. /// \file
  9. ///
  10. /// This file provides a bitcode writing pass.
  11. ///
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_BITCODE_BITCODEWRITERPASS_H
  14. #define LLVM_BITCODE_BITCODEWRITERPASS_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/IR/PassManager.h"
  17. namespace llvm {
  18. class Module;
  19. class ModulePass;
  20. class Pass;
  21. class raw_ostream;
  22. /// Create and return a pass that writes the module to the specified
  23. /// ostream. Note that this pass is designed for use with the legacy pass
  24. /// manager.
  25. ///
  26. /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
  27. /// reproduced when deserialized.
  28. ///
  29. /// If \c EmitSummaryIndex, emit the summary index (currently for use in ThinLTO
  30. /// optimization).
  31. ///
  32. /// If \c EmitModuleHash, compute and emit the module hash in the bitcode
  33. /// (currently for use in ThinLTO incremental build).
  34. ModulePass *createBitcodeWriterPass(raw_ostream &Str,
  35. bool ShouldPreserveUseListOrder = false,
  36. bool EmitSummaryIndex = false,
  37. bool EmitModuleHash = false);
  38. /// Check whether a pass is a BitcodeWriterPass.
  39. bool isBitcodeWriterPass(Pass *P);
  40. /// Pass for writing a module of IR out to a bitcode file.
  41. ///
  42. /// Note that this is intended for use with the new pass manager. To construct
  43. /// a pass for the legacy pass manager, use the function above.
  44. class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
  45. raw_ostream &OS;
  46. bool ShouldPreserveUseListOrder;
  47. bool EmitSummaryIndex;
  48. bool EmitModuleHash;
  49. public:
  50. /// Construct a bitcode writer pass around a particular output stream.
  51. ///
  52. /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
  53. /// reproduced when deserialized.
  54. ///
  55. /// If \c EmitSummaryIndex, emit the summary index (currently
  56. /// for use in ThinLTO optimization).
  57. explicit BitcodeWriterPass(raw_ostream &OS,
  58. bool ShouldPreserveUseListOrder = false,
  59. bool EmitSummaryIndex = false,
  60. bool EmitModuleHash = false)
  61. : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
  62. EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
  63. /// Run the bitcode writer pass, and output the module to the selected
  64. /// output stream.
  65. PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
  66. static bool isRequired() { return true; }
  67. };
  68. }
  69. #endif