clang 23.0.0git
ModuleCache.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_MODULECACHE_H
10#define LLVM_CLANG_SERIALIZATION_MODULECACHE_H
11
12#include "clang/Basic/LLVM.h"
13
14#include <ctime>
15
16namespace llvm {
17class AdvisoryLock;
18} // namespace llvm
19
20namespace clang {
22
23/// The module cache used for compiling modules implicitly. This centralizes the
24/// operations the compiler might want to perform on the cache.
26public:
27 /// May perform any work that only needs to be performed once for multiple
28 /// calls \c getLock() with the same module filename.
29 virtual void prepareForGetLock(StringRef ModuleFilename) = 0;
30
31 /// Returns lock for the given module file. The lock is initially unlocked.
32 virtual std::unique_ptr<llvm::AdvisoryLock>
33 getLock(StringRef ModuleFilename) = 0;
34
35 // TODO: Abstract away timestamps with isUpToDate() and markUpToDate().
36 // TODO: Consider exposing a "validation lock" API to prevent multiple clients
37 // concurrently noticing an out-of-date module file and validating its inputs.
38
39 /// Returns the timestamp denoting the last time inputs of the module file
40 /// were validated.
41 virtual std::time_t getModuleTimestamp(StringRef ModuleFilename) = 0;
42
43 /// Updates the timestamp denoting the last time inputs of the module file
44 /// were validated.
45 virtual void updateModuleTimestamp(StringRef ModuleFilename) = 0;
46
47 /// Prune module files that haven't been accessed in a long time.
48 virtual void maybePrune(StringRef Path, time_t PruneInterval,
49 time_t PruneAfter) = 0;
50
51 /// Returns this process's view of the module cache.
53 virtual const InMemoryModuleCache &getInMemoryModuleCache() const = 0;
54
55 // TODO: Virtualize writing/reading PCM files, etc.
56
57 virtual ~ModuleCache() = default;
58};
59
60/// Creates new \c ModuleCache backed by a file system directory that may be
61/// operated on by multiple processes. This instance must be used across all
62/// \c CompilerInstance instances participating in building modules for single
63/// translation unit in order to share the same \c InMemoryModuleCache.
64std::shared_ptr<ModuleCache> createCrossProcessModuleCache();
65
66/// Shared implementation of `ModuleCache::maybePrune()`.
67void maybePruneImpl(StringRef Path, time_t PruneInterval, time_t PruneAfter);
68} // namespace clang
69
70#endif
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
In-memory cache for modules.
The module cache used for compiling modules implicitly.
Definition ModuleCache.h:25
virtual void prepareForGetLock(StringRef ModuleFilename)=0
May perform any work that only needs to be performed once for multiple calls getLock() with the same ...
virtual ~ModuleCache()=default
virtual const InMemoryModuleCache & getInMemoryModuleCache() const =0
virtual std::time_t getModuleTimestamp(StringRef ModuleFilename)=0
Returns the timestamp denoting the last time inputs of the module file were validated.
virtual InMemoryModuleCache & getInMemoryModuleCache()=0
Returns this process's view of the module cache.
virtual void updateModuleTimestamp(StringRef ModuleFilename)=0
Updates the timestamp denoting the last time inputs of the module file were validated.
virtual void maybePrune(StringRef Path, time_t PruneInterval, time_t PruneAfter)=0
Prune module files that haven't been accessed in a long time.
virtual std::unique_ptr< llvm::AdvisoryLock > getLock(StringRef ModuleFilename)=0
Returns lock for the given module file. The lock is initially unlocked.
The JSON file list parser is used to communicate input to InstallAPI.
std::shared_ptr< ModuleCache > createCrossProcessModuleCache()
Creates new ModuleCache backed by a file system directory that may be operated on by multiple process...
void maybePruneImpl(StringRef Path, time_t PruneInterval, time_t PruneAfter)
Shared implementation of ModuleCache::maybePrune().
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30