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 #include "llvm/Support/Compiler.h" 19 20 namespace llvm { 21 class Module; 22 class ModulePass; 23 class Pass; 24 class raw_ostream; 25 26 /// 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 LLVM_ABI ModulePass * 33 createBitcodeWriterPass(raw_ostream &Str, 34 bool ShouldPreserveUseListOrder = false); 35 36 /// Check whether a pass is a BitcodeWriterPass. 37 LLVM_ABI bool isBitcodeWriterPass(Pass *P); 38 39 /// 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. 43 class BitcodeWriterPass : public PassInfoMixin<BitcodeWriterPass> { 44 raw_ostream &OS; 45 bool ShouldPreserveUseListOrder; 46 bool EmitSummaryIndex; 47 bool EmitModuleHash; 48 49 public: 50 /// Construct a bitcode writer pass around a particular output stream. 51 /// 52 /// If \c ShouldPreserveUseListOrder, encode use-list order so it can be 53 /// reproduced when deserialized. 54 /// 55 /// If \c EmitSummaryIndex, emit the summary index (currently 56 /// for use in ThinLTO optimization). 57 explicit BitcodeWriterPass(raw_ostream &OS, 58 bool ShouldPreserveUseListOrder = false, 59 bool EmitSummaryIndex = false, 60 bool EmitModuleHash = false) OS(OS)61 : OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), 62 EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {} 63 64 /// Run the bitcode writer pass, and output the module to the selected 65 /// output stream. 66 LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &); 67 isRequired()68 static bool isRequired() { return true; } 69 }; 70 71 } 72 73 #endif 74