Skip to content

[ThinLTO] Asynchronous caching #8236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/CAS/ObjectStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ class ObjectStore {
/// Asynchronous version of \c getProxyIfExists.
std::future<AsyncProxyValue> getProxyFuture(ObjectRef Ref);

/// Asynchronous version of \c getProxyIfExists using a callback.
void getProxyAsync(
const CASID &ID,
unique_function<void(Expected<std::optional<ObjectProxy>>)> Callback);
/// Asynchronous version of \c getProxyIfExists using a callback.
void getProxyAsync(
ObjectRef Ref,
Expand Down
41 changes: 41 additions & 0 deletions llvm/include/llvm/RemoteCachingService/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,37 @@ class KeyValueDBClient {
Expected<std::optional<ValueTy>> getValueSync(ArrayRef<uint8_t> Key) {
return getValueSync(toStringRef(Key).str());
}

using GetValueCb = std::function<void(Expected<std::optional<ValueTy>>)>;
void getValueAsync(std::string Key, GetValueCb Callback) {
return getValueAsyncImpl(std::move(Key), std::move(Callback));
}
void getValueAsync(ArrayRef<uint8_t> Key, GetValueCb Callback) {
return getValueAsync(toStringRef(Key).str(), std::move(Callback));
}

Error putValueSync(std::string Key, const ValueTy &Value) {
return putValueSyncImpl(std::move(Key), Value);
}
Error putValueSync(ArrayRef<uint8_t> Key, const ValueTy &Value) {
return putValueSync(toStringRef(Key).str(), Value);
}
void putValueAsync(std::string Key, const ValueTy &Value,
std::function<void(Error)> Callback) {
return putValueAsyncImpl(std::move(Key), Value, std::move(Callback));
}
void putValueAsync(ArrayRef<uint8_t> Key, const ValueTy &Value,
std::function<void(Error)> Callback) {
return putValueAsync(toStringRef(Key).str(), Value, std::move(Callback));
}

protected:
virtual Expected<std::optional<ValueTy>>
getValueSyncImpl(std::string Key) = 0;
virtual void getValueAsyncImpl(std::string Key, GetValueCb Callback) = 0;
virtual Error putValueSyncImpl(std::string Key, const ValueTy &Value) = 0;
virtual void putValueAsyncImpl(std::string Key, const ValueTy &Value,
std::function<void(Error)> Callback) = 0;

public:
class GetValueAsyncQueue : public AsyncQueueBase {
Expand Down Expand Up @@ -184,17 +204,32 @@ class CASDBClient {
std::optional<std::string> BlobData;
std::vector<std::string> Refs;
};

Expected<LoadResponse>
loadSync(std::string CASID,
std::optional<std::string> OutFilePath = std::nullopt) {
return loadSyncImpl(std::move(CASID), std::move(OutFilePath));
}

using LoadCb = std::function<void(Expected<LoadResponse>)>;
void loadAsync(std::string CASID, std::optional<std::string> OutFilePath,
LoadCb Callback) {
return loadAsyncImpl(std::move(CASID), std::move(OutFilePath),
std::move(Callback));
}

Expected<std::string> saveDataSync(std::string BlobData) {
return saveDataSyncImpl(std::move(BlobData));
}
Expected<std::string> saveFileSync(std::string FilePath) {
return saveFileSyncImpl(std::move(FilePath));
}

using SaveFileCb = std::function<void(Expected<std::string>)>;
void saveFileAsync(std::string FilePath, SaveFileCb Callback) {
return saveFileAsyncImpl(std::move(FilePath), std::move(Callback));
}

Expected<GetResponse>
getSync(std::string CASID,
std::optional<std::string> OutFilePath = std::nullopt) {
Expand All @@ -212,8 +247,14 @@ class CASDBClient {
protected:
virtual Expected<LoadResponse>
loadSyncImpl(std::string CASID, std::optional<std::string> OutFilePath) = 0;
virtual void loadAsyncImpl(std::string CASID,
std::optional<std::string> OutFilePath,
LoadCb Callback) = 0;

virtual Expected<std::string> saveDataSyncImpl(std::string BlobData) = 0;
virtual Expected<std::string> saveFileSyncImpl(std::string FilePath) = 0;
virtual void saveFileAsyncImpl(std::string FilePath, SaveFileCb Callback) = 0;

virtual Expected<GetResponse>
getSyncImpl(std::string CASID, std::optional<std::string> OutFilePath) = 0;
virtual Expected<std::string> putDataSyncImpl(std::string BlobData,
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/CAS/ObjectStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ std::future<AsyncProxyValue> ObjectStore::getProxyFuture(ObjectRef Ref) {
return Future;
}

void ObjectStore::getProxyAsync(
const CASID &ID,
unique_function<void(Expected<std::optional<ObjectProxy>>)> Callback) {
std::optional<ObjectRef> Ref = getReference(ID);
if (!Ref)
return Callback(createUnknownObjectError(ID));
return getProxyAsync(*Ref, std::move(Callback));
}

void ObjectStore::getProxyAsync(
ObjectRef Ref,
unique_function<void(Expected<std::optional<ObjectProxy>>)> Callback) {
Expand Down
Loading