Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Serialization/InMemoryModuleCache.cpp
Line
Count
Source
1
//===- InMemoryModuleCache.cpp - Cache for loaded memory buffers ----------===//
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
#include "clang/Serialization/InMemoryModuleCache.h"
10
#include "llvm/Support/MemoryBuffer.h"
11
12
using namespace clang;
13
14
InMemoryModuleCache::State
15
4.30k
InMemoryModuleCache::getPCMState(llvm::StringRef Filename) const {
16
4.30k
  auto I = PCMs.find(Filename);
17
4.30k
  if (I == PCMs.end())
18
4.26k
    return Unknown;
19
43
  if (I->second.IsFinal)
20
9
    return Final;
21
34
  return I->second.Buffer ? 
Tentative14
:
ToBuild20
;
22
34
}
23
24
llvm::MemoryBuffer &
25
InMemoryModuleCache::addPCM(llvm::StringRef Filename,
26
4.25k
                            std::unique_ptr<llvm::MemoryBuffer> Buffer) {
27
4.25k
  auto Insertion = PCMs.insert(std::make_pair(Filename, std::move(Buffer)));
28
4.25k
  assert(Insertion.second && "Already has a PCM");
29
4.25k
  return *Insertion.first->second.Buffer;
30
4.25k
}
31
32
llvm::MemoryBuffer &
33
InMemoryModuleCache::addBuiltPCM(llvm::StringRef Filename,
34
1.32k
                                 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
35
1.32k
  auto &PCM = PCMs[Filename];
36
1.32k
  assert(!PCM.IsFinal && "Trying to override finalized PCM?");
37
1.32k
  assert(!PCM.Buffer && "Trying to override tentative PCM?");
38
1.32k
  PCM.Buffer = std::move(Buffer);
39
1.32k
  PCM.IsFinal = true;
40
1.32k
  return *PCM.Buffer;
41
1.32k
}
42
43
llvm::MemoryBuffer *
44
6.19k
InMemoryModuleCache::lookupPCM(llvm::StringRef Filename) const {
45
6.19k
  auto I = PCMs.find(Filename);
46
6.19k
  if (I == PCMs.end())
47
4.25k
    return nullptr;
48
1.94k
  return I->second.Buffer.get();
49
1.94k
}
50
51
19
bool InMemoryModuleCache::isPCMFinal(llvm::StringRef Filename) const {
52
19
  return getPCMState(Filename) == Final;
53
19
}
54
55
4.27k
bool InMemoryModuleCache::shouldBuildPCM(llvm::StringRef Filename) const {
56
4.27k
  return getPCMState(Filename) == ToBuild;
57
4.27k
}
58
59
111
bool InMemoryModuleCache::tryToDropPCM(llvm::StringRef Filename) {
60
111
  auto I = PCMs.find(Filename);
61
111
  assert(I != PCMs.end() && "PCM to remove is unknown...");
62
111
63
111
  auto &PCM = I->second;
64
111
  assert(PCM.Buffer && "PCM to remove is scheduled to be built...");
65
111
66
111
  if (PCM.IsFinal)
67
3
    return true;
68
108
69
108
  PCM.Buffer.reset();
70
108
  return false;
71
108
}
72
73
6.14k
void InMemoryModuleCache::finalizePCM(llvm::StringRef Filename) {
74
6.14k
  auto I = PCMs.find(Filename);
75
6.14k
  assert(I != PCMs.end() && "PCM to finalize is unknown...");
76
6.14k
77
6.14k
  auto &PCM = I->second;
78
6.14k
  assert(PCM.Buffer && "Trying to finalize a dropped PCM...");
79
6.14k
  PCM.IsFinal = true;
80
6.14k
}