BitcodeWriterPass.h 2.9 KB

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