Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Serialization/InMemoryModuleCache.cpp
Line
Count
Source (jump to first uncovered line)
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
15.8k
InMemoryModuleCache::getPCMState(llvm::StringRef Filename) const {
16
15.8k
  auto I = PCMs.find(Filename);
17
15.8k
  if (I == PCMs.end())
18
15.6k
    return Unknown;
19
199
  if (I->second.IsFinal)
20
21
    return Final;
21
178
  return I->second.Buffer ? 
Tentative63
:
ToBuild115
;
22
199
}
23
24
llvm::MemoryBuffer &
25
InMemoryModuleCache::addPCM(llvm::StringRef Filename,
26
14.0k
                            std::unique_ptr<llvm::MemoryBuffer> Buffer) {
27
14.0k
  auto Insertion = PCMs.insert(std::make_pair(Filename, std::move(Buffer)));
28
14.0k
  assert(Insertion.second && "Already has a PCM");
29
0
  return *Insertion.first->second.Buffer;
30
14.0k
}
31
32
llvm::MemoryBuffer &
33
InMemoryModuleCache::addBuiltPCM(llvm::StringRef Filename,
34
1.76k
                                 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
35
1.76k
  auto &PCM = PCMs[Filename];
36
1.76k
  assert(!PCM.IsFinal && "Trying to override finalized PCM?");
37
0
  assert(!PCM.Buffer && "Trying to override tentative PCM?");
38
0
  PCM.Buffer = std::move(Buffer);
39
1.76k
  PCM.IsFinal = true;
40
1.76k
  return *PCM.Buffer;
41
1.76k
}
42
43
llvm::MemoryBuffer *
44
18.0k
InMemoryModuleCache::lookupPCM(llvm::StringRef Filename) const {
45
18.0k
  auto I = PCMs.find(Filename);
46
18.0k
  if (I == PCMs.end())
47
14.0k
    return nullptr;
48
4.02k
  return I->second.Buffer.get();
49
18.0k
}
50
51
1.81k
bool InMemoryModuleCache::isPCMFinal(llvm::StringRef Filename) const {
52
1.81k
  return getPCMState(Filename) == Final;
53
1.81k
}
54
55
14.0k
bool InMemoryModuleCache::shouldBuildPCM(llvm::StringRef Filename) const {
56
14.0k
  return getPCMState(Filename) == ToBuild;
57
14.0k
}
58
59
161
bool InMemoryModuleCache::tryToDropPCM(llvm::StringRef Filename) {
60
161
  auto I = PCMs.find(Filename);
61
161
  assert(I != PCMs.end() && "PCM to remove is unknown...");
62
63
0
  auto &PCM = I->second;
64
161
  assert(PCM.Buffer && "PCM to remove is scheduled to be built...");
65
66
161
  if (PCM.IsFinal)
67
7
    return true;
68
69
154
  PCM.Buffer.reset();
70
154
  return false;
71
161
}
72
73
17.9k
void InMemoryModuleCache::finalizePCM(llvm::StringRef Filename) {
74
17.9k
  auto I = PCMs.find(Filename);
75
17.9k
  assert(I != PCMs.end() && "PCM to finalize is unknown...");
76
77
0
  auto &PCM = I->second;
78
17.9k
  assert(PCM.Buffer && "Trying to finalize a dropped PCM...");
79
0
  PCM.IsFinal = true;
80
17.9k
}