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#include <memory>
16#include <sys/types.h>
17#include <system_error>
18
19namespace llvm {
20class AdvisoryLock;
21class MemoryBuffer;
22class MemoryBufferRef;
23} // namespace llvm
24
25namespace clang {
27
28/// The module cache used for compiling modules implicitly. This centralizes the
29/// operations the compiler might want to perform on the cache.
31public:
32 /// Returns lock for the given module file. The lock is initially unlocked.
33 virtual std::unique_ptr<llvm::AdvisoryLock>
34 getLock(StringRef ModuleFilename) = 0;
35
36 // TODO: Abstract away timestamps with isUpToDate() and markUpToDate().
37 // TODO: Consider exposing a "validation lock" API to prevent multiple clients
38 // concurrently noticing an out-of-date module file and validating its inputs.
39
40 /// Returns the timestamp denoting the last time inputs of the module file
41 /// were validated.
42 virtual std::time_t getModuleTimestamp(StringRef ModuleFilename) = 0;
43
44 /// Updates the timestamp denoting the last time inputs of the module file
45 /// were validated.
46 virtual void updateModuleTimestamp(StringRef ModuleFilename) = 0;
47
48 /// Prune module files that haven't been accessed in a long time.
49 virtual void maybePrune(StringRef Path, time_t PruneInterval,
50 time_t PruneAfter) = 0;
51
52 /// Returns this process's view of the module cache.
54 virtual const InMemoryModuleCache &getInMemoryModuleCache() const = 0;
55
56 /// Write the PCM contents to the given path in the module cache.
57 virtual std::error_code write(StringRef Path,
58 llvm::MemoryBufferRef Buffer) = 0;
59
61 read(StringRef FileName, off_t &Size, time_t &ModTime) = 0;
62
63 virtual ~ModuleCache() = default;
64};
65
66/// Creates new \c ModuleCache backed by a file system directory that may be
67/// operated on by multiple processes. This instance must be used across all
68/// \c CompilerInstance instances participating in building modules for single
69/// translation unit in order to share the same \c InMemoryModuleCache.
70std::shared_ptr<ModuleCache> createCrossProcessModuleCache();
71
72/// Shared implementation of `ModuleCache::maybePrune()`.
73void maybePruneImpl(StringRef Path, time_t PruneInterval, time_t PruneAfter);
74
75/// Shared implementation of `ModuleCache::write()`.
76std::error_code writeImpl(StringRef Path, llvm::MemoryBufferRef Buffer);
77
78/// Shared implementation of `ModuleCache::read()`.
80readImpl(StringRef FileName, off_t &Size, time_t &ModTime);
81} // namespace clang
82
83#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:30
virtual std::error_code write(StringRef Path, llvm::MemoryBufferRef Buffer)=0
Write the PCM contents to the given path in the module cache.
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 Expected< std::unique_ptr< llvm::MemoryBuffer > > read(StringRef FileName, off_t &Size, time_t &ModTime)=0
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.
Expected< std::unique_ptr< llvm::MemoryBuffer > > readImpl(StringRef FileName, off_t &Size, time_t &ModTime)
Shared implementation of ModuleCache::read().
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().
std::error_code writeImpl(StringRef Path, llvm::MemoryBufferRef Buffer)
Shared implementation of ModuleCache::write().
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30