blob: 1773d1b9f11b23b6a193e39da037bb2f954b9e22 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- BitcodeWriterPass.h - Bitcode writing pass --------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file provides a bitcode writing pass.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_BITCODE_BITCODEWRITERPASS_H
15#define LLVM_BITCODE_BITCODEWRITERPASS_H
16
17#include "llvm/ADT/StringRef.h"
18#include "llvm/IR/PassManager.h"
19
20namespace llvm {
21class Module;
22class ModulePass;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010023class Pass;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010024class raw_ostream;
25
Andrew Scullcdfcccc2018-10-05 20:58:37 +010026/// Create and return a pass that writes the module to the specified
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010027/// 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).
38ModulePass *createBitcodeWriterPass(raw_ostream &Str,
39 bool ShouldPreserveUseListOrder = false,
40 bool EmitSummaryIndex = false,
41 bool EmitModuleHash = false);
42
Andrew Scullcdfcccc2018-10-05 20:58:37 +010043/// Check whether a pass is a BitcodeWriterPass.
44bool isBitcodeWriterPass(Pass *P);
45
46/// Pass for writing a module of IR out to a bitcode file.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010047///
48/// Note that this is intended for use with the new pass manager. To construct
49/// a pass for the legacy pass manager, use the function above.
50class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> {
51 raw_ostream &OS;
52 bool ShouldPreserveUseListOrder;
53 bool EmitSummaryIndex;
54 bool EmitModuleHash;
55
56public:
Andrew Scullcdfcccc2018-10-05 20:58:37 +010057 /// Construct a bitcode writer pass around a particular output stream.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010058 ///
59 /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
60 /// reproduced when deserialized.
61 ///
62 /// If \c EmitSummaryIndex, emit the summary index (currently
63 /// for use in ThinLTO optimization).
64 explicit BitcodeWriterPass(raw_ostream &OS,
65 bool ShouldPreserveUseListOrder = false,
66 bool EmitSummaryIndex = false,
67 bool EmitModuleHash = false)
68 : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
69 EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {}
70
Andrew Scullcdfcccc2018-10-05 20:58:37 +010071 /// Run the bitcode writer pass, and output the module to the selected
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010072 /// output stream.
73 PreservedAnalyses run(Module &M, ModuleAnalysisManager &);
74};
75
76}
77
78#endif