From 87e59e47e936f15e407dba1b963393dd96ff96fb Mon Sep 17 00:00:00 2001 From: River Riddle Date: Tue, 22 Jun 2021 19:13:57 +0000 Subject: [PATCH] [mlir] Remove the Identifier ThreadLocalCache from MLIRContext This used to be important for reducing lock contention when accessing identifiers, but the cost of the cache can be quite large if parsing in a multi-threaded context. After D104167, the win of keeping a cache is not worth the cost. Differential Revision: https://reviews.llvm.org/D104737 --- mlir/lib/IR/MLIRContext.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index 1041f1c..8aa4fe7 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -24,7 +24,6 @@ #include "mlir/IR/OpImplementation.h" #include "mlir/IR/Types.h" #include "mlir/Support/DebugAction.h" -#include "mlir/Support/ThreadLocalCache.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SetVector.h" @@ -275,10 +274,6 @@ public: llvm::StringMap, llvm::BumpPtrAllocator &> identifiers; - /// A thread local cache of identifiers to reduce lock contention. - ThreadLocalCache> *>> - localIdentifierCache; /// An allocator used for AbstractAttribute and AbstractType objects. llvm::BumpPtrAllocator abstractDialectSymbolAllocator; @@ -811,26 +806,18 @@ Identifier Identifier::get(const Twine &string, MLIRContext *context) { return Identifier(&*insertedIt.first); } - // Check for an existing instance in the local cache. - auto *&localEntry = (*impl.localIdentifierCache)[str]; - if (localEntry) - return Identifier(localEntry); - // Check for an existing identifier in read-only mode. { llvm::sys::SmartScopedReader contextLock(impl.identifierMutex); auto it = impl.identifiers.find(str); - if (it != impl.identifiers.end()) { - localEntry = &*it; - return Identifier(localEntry); - } + if (it != impl.identifiers.end()) + return Identifier(&*it); } // Acquire a writer-lock so that we can safely create the new instance. llvm::sys::SmartScopedWriter contextLock(impl.identifierMutex); auto it = impl.identifiers.insert({str, getDialectOrContext()}).first; - localEntry = &*it; - return Identifier(localEntry); + return Identifier(&*it); } Dialect *Identifier::getDialect() { -- 2.7.4