mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 18:16:06 +00:00
[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
This commit is contained in:
parent
e4e31e19bb
commit
87e59e47e9
@ -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<PointerUnion<Dialect *, MLIRContext *>,
|
||||
llvm::BumpPtrAllocator &>
|
||||
identifiers;
|
||||
/// A thread local cache of identifiers to reduce lock contention.
|
||||
ThreadLocalCache<llvm::StringMap<
|
||||
llvm::StringMapEntry<PointerUnion<Dialect *, MLIRContext *>> *>>
|
||||
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<true> 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<true> contextLock(impl.identifierMutex);
|
||||
auto it = impl.identifiers.insert({str, getDialectOrContext()}).first;
|
||||
localEntry = &*it;
|
||||
return Identifier(localEntry);
|
||||
return Identifier(&*it);
|
||||
}
|
||||
|
||||
Dialect *Identifier::getDialect() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user