1//===-- BitcodeWriterPass.h - Bitcode writing pass --------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10///
11/// This file provides a bitcode writing pass.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_BITCODE_BITCODEWRITERPASS_H
16#define LLVM_BITCODE_BITCODEWRITERPASS_H
17
18#include "llvm/ADT/StringRef.h"
19
20namespace llvm {
21class Module;
22class ModulePass;
23class raw_ostream;
24class PreservedAnalyses;
25
26/// \brief 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 EmitFunctionSummary, emit the function summary index (currently
34/// for use in ThinLTO optimization).
35ModulePass *createBitcodeWriterPass(raw_ostream &Str,
36                                    bool ShouldPreserveUseListOrder = false,
37                                    bool EmitFunctionSummary = false);
38
39/// \brief Pass for writing a module of IR out to a bitcode file.
40///
41/// Note that this is intended for use with the new pass manager. To construct
42/// a pass for the legacy pass manager, use the function above.
43class BitcodeWriterPass {
44  raw_ostream &OS;
45  bool ShouldPreserveUseListOrder;
46  bool EmitFunctionSummary;
47
48public:
49  /// \brief Construct a bitcode writer pass around a particular output stream.
50  ///
51  /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
52  /// reproduced when deserialized.
53  ///
54  /// If \c EmitFunctionSummary, emit the function summary index (currently
55  /// for use in ThinLTO optimization).
56  explicit BitcodeWriterPass(raw_ostream &OS,
57                             bool ShouldPreserveUseListOrder = false,
58                             bool EmitFunctionSummary = false)
59      : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
60        EmitFunctionSummary(EmitFunctionSummary) {}
61
62  /// \brief Run the bitcode writer pass, and output the module to the selected
63  /// output stream.
64  PreservedAnalyses run(Module &M);
65
66  static StringRef name() { return "BitcodeWriterPass"; }
67};
68
69}
70
71#endif
72