Coverage Report

Created: 2023-09-30 09:22

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