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 #include "llvm/ADT/IntrusiveRefCntPtr.h" 14 15 #include <ctime> 16 17 namespace llvm { 18 class AdvisoryLock; 19 } // namespace llvm 20 21 namespace clang { 22 class InMemoryModuleCache; 23 24 /// The module cache used for compiling modules implicitly. This centralizes the 25 /// operations the compiler might want to perform on the cache. 26 class ModuleCache : public RefCountedBase<ModuleCache> { 27 public: 28 /// May perform any work that only needs to be performed once for multiple 29 /// calls \c getLock() with the same module filename. 30 virtual void prepareForGetLock(StringRef ModuleFilename) = 0; 31 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 /// Returns this process's view of the module cache. 49 virtual InMemoryModuleCache &getInMemoryModuleCache() = 0; 50 virtual const InMemoryModuleCache &getInMemoryModuleCache() const = 0; 51 52 // TODO: Virtualize writing/reading PCM files, pruning, etc. 53 54 virtual ~ModuleCache() = default; 55 }; 56 57 /// Creates new \c ModuleCache backed by a file system directory that may be 58 /// operated on by multiple processes. This instance must be used across all 59 /// \c CompilerInstance instances participating in building modules for single 60 /// translation unit in order to share the same \c InMemoryModuleCache. 61 IntrusiveRefCntPtr<ModuleCache> createCrossProcessModuleCache(); 62 } // namespace clang 63 64 #endif 65