LCOV - code coverage report
Current view: top level - lib/Bitcode/Writer - BitcodeWriterPass.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 23 27 85.2 %
Date: 2018-10-20 13:21:21 Functions: 7 9 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- BitcodeWriterPass.cpp - Bitcode writing pass -----------------------===//
       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             : //
      10             : // BitcodeWriterPass implementation.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/Bitcode/BitcodeWriterPass.h"
      15             : #include "llvm/Analysis/ModuleSummaryAnalysis.h"
      16             : #include "llvm/Bitcode/BitcodeWriter.h"
      17             : #include "llvm/IR/Module.h"
      18             : #include "llvm/IR/PassManager.h"
      19             : #include "llvm/Pass.h"
      20             : using namespace llvm;
      21             : 
      22          58 : PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
      23             :   const ModuleSummaryIndex *Index =
      24          58 :       EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
      25             :                        : nullptr;
      26          58 :   WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
      27          58 :   return PreservedAnalyses::all();
      28             : }
      29             : 
      30             : namespace {
      31             :   class WriteBitcodePass : public ModulePass {
      32             :     raw_ostream &OS; // raw_ostream to print on
      33             :     bool ShouldPreserveUseListOrder;
      34             :     bool EmitSummaryIndex;
      35             :     bool EmitModuleHash;
      36             : 
      37             :   public:
      38             :     static char ID; // Pass identification, replacement for typeid
      39           0 :     WriteBitcodePass() : ModulePass(ID), OS(dbgs()) {
      40           0 :       initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
      41           0 :     }
      42             : 
      43             :     explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder,
      44             :                               bool EmitSummaryIndex, bool EmitModuleHash)
      45        1093 :         : ModulePass(ID), OS(o),
      46             :           ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
      47        1093 :           EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {
      48        1093 :       initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
      49             :     }
      50             : 
      51           0 :     StringRef getPassName() const override { return "Bitcode Writer"; }
      52             : 
      53        1057 :     bool runOnModule(Module &M) override {
      54             :       const ModuleSummaryIndex *Index =
      55        1057 :           EmitSummaryIndex
      56        1057 :               ? &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex())
      57             :               : nullptr;
      58        1057 :       WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, Index,
      59        1057 :                          EmitModuleHash);
      60        1057 :       return false;
      61             :     }
      62        1093 :     void getAnalysisUsage(AnalysisUsage &AU) const override {
      63             :       AU.setPreservesAll();
      64        1093 :       if (EmitSummaryIndex)
      65             :         AU.addRequired<ModuleSummaryIndexWrapperPass>();
      66        1093 :     }
      67             :   };
      68             : }
      69             : 
      70             : char WriteBitcodePass::ID = 0;
      71       11056 : INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
      72             :                       true)
      73       11056 : INITIALIZE_PASS_DEPENDENCY(ModuleSummaryIndexWrapperPass)
      74       22888 : INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
      75             :                     true)
      76             : 
      77        1093 : ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
      78             :                                           bool ShouldPreserveUseListOrder,
      79             :                                           bool EmitSummaryIndex, bool EmitModuleHash) {
      80             :   return new WriteBitcodePass(Str, ShouldPreserveUseListOrder,
      81        1093 :                               EmitSummaryIndex, EmitModuleHash);
      82             : }
      83             : 
      84         441 : bool llvm::isBitcodeWriterPass(Pass *P) {
      85         441 :   return P->getPassID() == (llvm::AnalysisID)&WriteBitcodePass::ID;
      86             : }

Generated by: LCOV version 1.13