BitcodeWriterPass.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/ADT/StringRef.h"
  21. #include "llvm/IR/PassManager.h"
  22. namespace llvm {
  23. class Module;
  24. class ModulePass;
  25. class Pass;
  26. class raw_ostream;
  27. /// Create and return a pass that writes the module to the specified
  28. /// ostream. Note that this pass is designed for use with the legacy pass
  29. /// manager.
  30. ///
  31. /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
  32. /// reproduced when deserialized.
  33. ///
  34. /// If \c EmitSummaryIndex, emit the summary index (currently for use in ThinLTO
  35. /// optimization).
  36. ///
  37. /// If \c EmitModuleHash, compute and emit the module hash in the bitcode
  38. /// (currently for use in ThinLTO incremental build).
  39. ModulePass *createBitcodeWriterPass(raw_ostream &Str,
  40. bool ShouldPreserveUseListOrder = false,
  41. bool EmitSummaryIndex = false,
  42. bool EmitModuleHash = false);
  43. /// Check whether a pass is a BitcodeWriterPass.
  44. bool isBitcodeWriterPass(Pass *P);
  45. /// Pass for writing a module of IR out to a bitcode file.
  46. ///
  47. /// Note that this is intended for use with the new pass manager. To construct
  48. /// a pass for the legacy pass manager, use the function above.
  49. class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
  50. raw_ostream &OS;
  51. bool ShouldPreserveUseListOrder;
  52. bool EmitSummaryIndex;
  53. bool EmitModuleHash;
  54. public:
  55. /// Construct a bitcode writer pass around a particular output stream.
  56. ///
  57. /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
  58. /// reproduced when deserialized.
  59. ///
  60. /// If \c EmitSummaryIndex, emit the summary index (currently
  61. /// for use in ThinLTO optimization).
  62. explicit BitcodeWriterPass(raw_ostream &OS,
  63. bool ShouldPreserveUseListOrder = false,
  64. bool EmitSummaryIndex = false,
  65. bool EmitModuleHash = false)
  66. : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
  67. EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
  68. /// Run the bitcode writer pass, and output the module to the selected
  69. /// output stream.
  70. PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
  71. };
  72. }
  73. #endif
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif