1 //===-- EmbedBitcodePass.h - Embeds bitcode into global ---------*- 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 pass which clones the current module and runs the 11 /// provided pass pipeline on the clone. The optimized module is stored into a 12 /// global variable in the `.llvm.lto` section. Primarily, this pass is used 13 /// to support the FatLTO pipeline, but could be used to generate a bitcode 14 /// section for any arbitrary pass pipeline without changing the current module. 15 /// 16 //===----------------------------------------------------------------------===// 17 // 18 #ifndef LLVM_TRANSFORMS_IPO_EMBEDBITCODEPASS_H 19 #define LLVM_TRANSFORMS_IPO_EMBEDBITCODEPASS_H 20 21 #include "llvm/IR/PassManager.h" 22 #include "llvm/Support/Compiler.h" 23 24 namespace llvm { 25 class Module; 26 class Pass; 27 28 struct EmbedBitcodeOptions { EmbedBitcodeOptionsEmbedBitcodeOptions29 EmbedBitcodeOptions() : EmbedBitcodeOptions(false, false) {} EmbedBitcodeOptionsEmbedBitcodeOptions30 EmbedBitcodeOptions(bool IsThinLTO, bool EmitLTOSummary) 31 : IsThinLTO(IsThinLTO), EmitLTOSummary(EmitLTOSummary) {} 32 bool IsThinLTO; 33 bool EmitLTOSummary; 34 }; 35 36 /// Pass embeds a copy of the module optimized with the provided pass pipeline 37 /// into a global variable. 38 class EmbedBitcodePass : public PassInfoMixin<EmbedBitcodePass> { 39 bool IsThinLTO; 40 bool EmitLTOSummary; 41 42 public: EmbedBitcodePass(EmbedBitcodeOptions Opts)43 EmbedBitcodePass(EmbedBitcodeOptions Opts) 44 : EmbedBitcodePass(Opts.IsThinLTO, Opts.EmitLTOSummary) {} EmbedBitcodePass(bool IsThinLTO,bool EmitLTOSummary)45 EmbedBitcodePass(bool IsThinLTO, bool EmitLTOSummary) 46 : IsThinLTO(IsThinLTO), EmitLTOSummary(EmitLTOSummary) {} 47 48 LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &); 49 isRequired()50 static bool isRequired() { return true; } 51 }; 52 53 } // end namespace llvm. 54 55 #endif 56