//===- StorageUniquer.cpp - Common Storage Class Uniquer ------------------===// // // 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/Support/StorageUniquer.h" #include "mlir/Support/LLVM.h" #include "mlir/Support/ThreadLocalCache.h" #include "mlir/Support/TypeID.h" #include "llvm/Support/RWMutex.h" usingnamespacemlir; usingnamespacemlir::detail; namespace { /// This class represents a uniquer for storage instances of a specific type /// that has parametric storage. It contains all of the necessary data to unique /// storage instances in a thread safe way. This allows for the main uniquer to /// bucket each of the individual sub-types removing the need to lock the main /// uniquer itself. class ParametricStorageUniquer { … }; } // namespace namespace mlir { namespace detail { /// This is the implementation of the StorageUniquer class. struct StorageUniquerImpl { … }; } // namespace detail } // namespace mlir StorageUniquer::StorageUniquer() : … { … } StorageUniquer::~StorageUniquer() = default; /// Set the flag specifying if multi-threading is disabled within the uniquer. void StorageUniquer::disableMultithreading(bool disable) { … } /// Implementation for getting/creating an instance of a derived type with /// parametric storage. auto StorageUniquer::getParametricStorageTypeImpl( TypeID id, unsigned hashValue, function_ref<bool(const BaseStorage *)> isEqual, function_ref<BaseStorage *(StorageAllocator &)> ctorFn) -> BaseStorage * { … } /// Implementation for registering an instance of a derived type with /// parametric storage. void StorageUniquer::registerParametricStorageTypeImpl( TypeID id, function_ref<void(BaseStorage *)> destructorFn) { … } /// Implementation for getting an instance of a derived type with default /// storage. auto StorageUniquer::getSingletonImpl(TypeID id) -> BaseStorage * { … } /// Test is the storage singleton is initialized. bool StorageUniquer::isSingletonStorageInitialized(TypeID id) { … } /// Test is the parametric storage is initialized. bool StorageUniquer::isParametricStorageInitialized(TypeID id) { … } /// Implementation for registering an instance of a derived type with default /// storage. void StorageUniquer::registerSingletonImpl( TypeID id, function_ref<BaseStorage *(StorageAllocator &)> ctorFn) { … } /// Implementation for mutating an instance of a derived storage. LogicalResult StorageUniquer::mutateImpl( TypeID id, BaseStorage *storage, function_ref<LogicalResult(StorageAllocator &)> mutationFn) { … }