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