LCOV - code coverage report
Current view: top level - lib/Bitcode/Writer - BitcodeWriterPass.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 25 29 86.2 %
Date: 2017-09-14 15:23:50 Functions: 7 10 70.0 %
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          51 : PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
      23             :   const ModuleSummaryIndex *Index =
      24          53 :       EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
      25          51 :                        : nullptr;
      26          51 :   WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
      27          51 :   return PreservedAnalyses::all();
      28             : }
      29             : 
      30             : namespace {
      31         734 :   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         770 :         : ModulePass(ID), OS(o),
      46             :           ShouldPreserveUseListOrder(ShouldPreserveUseListOrder),
      47        1540 :           EmitSummaryIndex(EmitSummaryIndex), EmitModuleHash(EmitModuleHash) {
      48         770 :       initializeWriteBitcodePassPass(*PassRegistry::getPassRegistry());
      49             :     }
      50             : 
      51           0 :     StringRef getPassName() const override { return "Bitcode Writer"; }
      52             : 
      53         734 :     bool runOnModule(Module &M) override {
      54             :       const ModuleSummaryIndex *Index =
      55         734 :           EmitSummaryIndex
      56         954 :               ? &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex())
      57         734 :               : nullptr;
      58         734 :       WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index,
      59         734 :                          EmitModuleHash);
      60         734 :       return false;
      61             :     }
      62         770 :     void getAnalysisUsage(AnalysisUsage &AU) const override {
      63         770 :       AU.setPreservesAll();
      64         770 :       if (EmitSummaryIndex)
      65             :         AU.addRequired<ModuleSummaryIndexWrapperPass>();
      66         770 :     }
      67             :   };
      68             : }
      69             : 
      70             : char WriteBitcodePass::ID = 0;
      71         770 : INITIALIZE_PASS_BEGIN(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
      72             :                       true)
      73         770 : INITIALIZE_PASS_DEPENDENCY(ModuleSummaryIndexWrapperPass)
      74        3850 : INITIALIZE_PASS_END(WriteBitcodePass, "write-bitcode", "Write Bitcode", false,
      75             :                     true)
      76             : 
      77         770 : ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
      78             :                                           bool ShouldPreserveUseListOrder,
      79             :                                           bool EmitSummaryIndex, bool EmitModuleHash) {
      80             :   return new WriteBitcodePass(Str, ShouldPreserveUseListOrder,
      81        1540 :                               EmitSummaryIndex, EmitModuleHash);
      82             : }

Generated by: LCOV version 1.13