Files
TheRock/compiler/amd-llvm/mlir/lib/IR/DialectResourceBlobManager.cpp
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

74 lines
2.5 KiB
C++

//===- DialectResourceBlobManager.cpp - Dialect Blob Management -----------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "mlir/IR/DialectResourceBlobManager.h"
#include "llvm/ADT/SmallString.h"
#include <optional>
using namespace mlir;
//===----------------------------------------------------------------------===//
// DialectResourceBlobManager
//===---------------------------------------------------------------------===//
auto DialectResourceBlobManager::lookup(StringRef name) -> BlobEntry * {
llvm::sys::SmartScopedReader<true> reader(blobMapLock);
auto it = blobMap.find(name);
return it != blobMap.end() ? &it->second : nullptr;
}
void DialectResourceBlobManager::update(StringRef name,
AsmResourceBlob &&newBlob) {
BlobEntry *entry = lookup(name);
assert(entry && "`update` expects an existing entry for the provided name");
entry->setBlob(std::move(newBlob));
}
auto DialectResourceBlobManager::insert(StringRef name,
std::optional<AsmResourceBlob> blob)
-> BlobEntry & {
llvm::sys::SmartScopedWriter<true> writer(blobMapLock);
// Functor used to attempt insertion with a given name.
auto tryInsertion = [&](StringRef name) -> BlobEntry * {
auto it = blobMap.try_emplace(name, BlobEntry());
if (it.second) {
it.first->second.initialize(it.first->getKey(), std::move(blob));
return &it.first->second;
}
return nullptr;
};
// Try inserting with the name provided by the user.
if (BlobEntry *entry = tryInsertion(name))
return *entry;
// If an entry already exists for the user provided name, tweak the name and
// re-attempt insertion until we find one that is unique.
llvm::SmallString<32> nameStorage(name);
nameStorage.push_back('_');
size_t nameCounter = 1;
do {
Twine(nameCounter++).toVector(nameStorage);
// Try inserting with the new name.
if (BlobEntry *entry = tryInsertion(nameStorage))
return *entry;
nameStorage.resize(name.size() + 1);
} while (true);
}
void DialectResourceBlobManager::getBlobMap(
llvm::function_ref<void(const llvm::StringMap<BlobEntry> &)> accessor)
const {
llvm::sys::SmartScopedReader<true> reader(blobMapLock);
accessor(blobMap);
}