Coverage Report

Created: 2019-07-24 05:18

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