[llvm] [CAS] Add ActionCache to LLVMCAS Library (PR #114097)
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 14 18:02:38 PDT 2025
================
@@ -0,0 +1,94 @@
+//===- llvm/CAS/ActionCache.h -----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CAS_CASACTIONCACHE_H
+#define LLVM_CAS_CASACTIONCACHE_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/CAS/CASID.h"
+#include "llvm/CAS/CASReference.h"
+#include "llvm/Support/Error.h"
+
+namespace llvm::cas {
+
+class ObjectStore;
+class CASID;
+class ObjectProxy;
+
+/// A key for caching an operation.
+/// It is implemented as a bag of bytes and provides a convenient constructor
+/// for CAS types.
+class CacheKey {
+public:
+ StringRef getKey() const { return Key; }
+
+ // TODO: Support CacheKey other than a CASID but rather any array of bytes.
+ // To do that, ActionCache need to be able to rehash the key into the index,
+ // which then `getOrCompute` method can be used to avoid multiple calls to
+ // has function.
+ CacheKey(const CASID &ID);
+ CacheKey(const ObjectProxy &Proxy);
+ CacheKey(const ObjectStore &CAS, const ObjectRef &Ref);
+
+private:
+ std::string Key;
+};
+
+/// A cache from a key describing an action to the result of doing it.
+///
+/// Actions are expected to be pure (collision is an error).
+class ActionCache {
+ virtual void anchor();
+
+public:
+ /// Get a previously computed result for \p ActionKey.
+ ///
+ /// \param Globally if true it is a hint to the underlying implementation that
+ /// the lookup is profitable to be done on a distributed caching level, not
+ /// just locally. The implementation is free to ignore this flag.
+ Expected<std::optional<CASID>> get(const CacheKey &ActionKey,
+ bool Globally = false) const {
----------------
ilovepi wrote:
SGTM
https://github.com/llvm/llvm-project/pull/114097
More information about the llvm-commits
mailing list