Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Serialization/InMemoryModuleCache.h
Line
Count
Source
1
//===- InMemoryModuleCache.h - In-memory cache for modules ------*- C++ -*-===//
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
#ifndef LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H
10
#define LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H
11
12
#include "llvm/ADT/IntrusiveRefCntPtr.h"
13
#include "llvm/ADT/Optional.h"
14
#include "llvm/ADT/StringMap.h"
15
#include "llvm/Support/MemoryBuffer.h"
16
#include <memory>
17
18
namespace clang {
19
20
/// In-memory cache for modules.
21
///
22
/// This is a cache for modules for use across a compilation, sharing state
23
/// between the CompilerInstances in an implicit modules build.  It must be
24
/// shared by each CompilerInstance, ASTReader, ASTWriter, and ModuleManager
25
/// that are coordinating.
26
///
27
/// Critically, it ensures that a single process has a consistent view of each
28
/// PCM.  This is used by \a CompilerInstance when building PCMs to ensure that
29
/// each \a ModuleManager sees the same files.
30
class InMemoryModuleCache : public llvm::RefCountedBase<InMemoryModuleCache> {
31
  struct PCM {
32
    std::unique_ptr<llvm::MemoryBuffer> Buffer;
33
34
    /// Track whether this PCM is known to be good (either built or
35
    /// successfully imported by a CompilerInstance/ASTReader using this
36
    /// cache).
37
    bool IsFinal = false;
38
39
1.69k
    PCM() = default;
40
    PCM(std::unique_ptr<llvm::MemoryBuffer> Buffer)
41
16.1k
        : Buffer(std::move(Buffer)) {}
42
  };
43
44
  /// Cache of buffers.
45
  llvm::StringMap<PCM> PCMs;
46
47
public:
48
  /// Store the PCM under the Filename.
49
  ///
50
  /// \pre PCM for the same Filename shouldn't be in cache already.
51
  /// \return a reference to the buffer as a convenience.
52
  llvm::MemoryBuffer &addPCM(llvm::StringRef Filename,
53
                             std::unique_ptr<llvm::MemoryBuffer> Buffer);
54
55
  /// Store a final PCM under the Filename.
56
  ///
57
  /// \pre PCM for the same Filename shouldn't be in cache already.
58
  /// \return a reference to the buffer as a convenience.
59
  llvm::MemoryBuffer &addFinalPCM(llvm::StringRef Filename,
60
                                  std::unique_ptr<llvm::MemoryBuffer> Buffer);
61
62
  /// Try to remove a PCM from the cache.  No effect if it is Final.
63
  ///
64
  /// \return false on success.
65
  bool tryToRemovePCM(llvm::StringRef Filename);
66
67
  /// Mark a PCM as final.
68
  void finalizePCM(llvm::StringRef Filename);
69
70
  /// Get a pointer to the PCM if it exists; else nullptr.
71
  llvm::MemoryBuffer *lookupPCM(llvm::StringRef Filename) const;
72
73
  /// Check whether the PCM is final and has been shown to work.
74
  ///
75
  /// \return true iff state is Final.
76
  bool isPCMFinal(llvm::StringRef Filename) const;
77
};
78
79
} // end namespace clang
80
81
#endif // LLVM_CLANG_SERIALIZATION_INMEMORYMODULECACHE_H