blob: 05044c9ae11c2e48698a118661a841a48ad2d90d [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- 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#include "llvm/IR/PassManager.h"
20
21namespace llvm {
22class Module;
23class ModulePass;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010024class Pass;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010025class raw_ostream;
26
Andrew Scullcdfcccc2018-10-05 20:58:37 +010027/// Create and return a pass that writes the module to the specified
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010028/// 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).
39ModulePass *createBitcodeWriterPass(raw_ostream &Str,
40 bool ShouldPreserveUseListOrder = false,
41 bool EmitSummaryIndex = false,
42 bool EmitModuleHash = false);
43
Andrew Scullcdfcccc2018-10-05 20:58:37 +010044/// Check whether a pass is a BitcodeWriterPass.
45bool isBitcodeWriterPass(Pass *P);
46
47/// Pass for writing a module of IR out to a bitcode file.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010048///
49/// Note that this is intended for use with the new pass manager. To construct
50/// a pass for the legacy pass manager, use the function above.
51class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
52 raw_ostream &OS;
53 bool ShouldPreserveUseListOrder;
54 bool EmitSummaryIndex;
55 bool EmitModuleHash;
56
57public:
Andrew Scullcdfcccc2018-10-05 20:58:37 +010058 /// Construct a bitcode writer pass around a particular output stream.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010059 ///
60 /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
61 /// reproduced when deserialized.
62 ///
63 /// If \c EmitSummaryIndex, emit the summary index (currently
64 /// for use in ThinLTO optimization).
65 explicit BitcodeWriterPass(raw_ostream &OS,
66 bool ShouldPreserveUseListOrder = false,
67 bool EmitSummaryIndex = false,
68 bool EmitModuleHash = false)
69 : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
70 EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
71
Andrew Scullcdfcccc2018-10-05 20:58:37 +010072 /// Run the bitcode writer pass, and output the module to the selected
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010073 /// output stream.
74 PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
75};
76
77}
78
79#endif