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

Generated by: LCOV version 1.13