|
19 | 19 | #include "mlir/IR/BuiltinTypes.h"
|
20 | 20 | #include "mlir/IR/IntegerSet.h"
|
21 | 21 | #include "mlir/IR/MLIRContext.h"
|
22 |
| -#include "mlir/Support/StorageUniquer.h" |
23 |
| -#include "mlir/Support/ThreadLocalCache.h" |
24 | 22 | #include "llvm/ADT/APFloat.h"
|
25 |
| -#include "llvm/ADT/PointerIntPair.h" |
26 |
| -#include "llvm/Support/TrailingObjects.h" |
| 23 | +#include "llvm/Support/Allocator.h" |
| 24 | +#include <mutex> |
27 | 25 |
|
28 | 26 | namespace mlir {
|
29 | 27 | namespace detail {
|
@@ -396,27 +394,30 @@ class DistinctAttributeUniquer {
|
396 | 394 | Attribute referencedAttr);
|
397 | 395 | };
|
398 | 396 |
|
399 |
| -/// An allocator for distinct attribute storage instances. It uses thread local |
400 |
| -/// bump pointer allocators stored in a thread local cache to ensure the storage |
401 |
| -/// is freed after the destruction of the distinct attribute allocator. |
402 |
| -class DistinctAttributeAllocator { |
| 397 | +/// An allocator for distinct attribute storage instances. Uses a synchronized |
| 398 | +/// BumpPtrAllocator to ensure thread-safety. The allocated storage is deleted |
| 399 | +/// when the DistinctAttributeAllocator is destroyed. |
| 400 | +class DistinctAttributeAllocator final { |
403 | 401 | public:
|
404 | 402 | DistinctAttributeAllocator() = default;
|
405 |
| - |
406 | 403 | DistinctAttributeAllocator(DistinctAttributeAllocator &&) = delete;
|
407 | 404 | DistinctAttributeAllocator(const DistinctAttributeAllocator &) = delete;
|
408 | 405 | DistinctAttributeAllocator &
|
409 | 406 | operator=(const DistinctAttributeAllocator &) = delete;
|
410 | 407 |
|
411 |
| - /// Allocates a distinct attribute storage using a thread local bump pointer |
412 |
| - /// allocator to enable synchronization free parallel allocations. |
413 | 408 | DistinctAttrStorage *allocate(Attribute referencedAttr) {
|
414 |
| - return new (allocatorCache.get().Allocate<DistinctAttrStorage>()) |
| 409 | + std::scoped_lock<std::mutex> guard(allocatorMutex); |
| 410 | + return new (allocator.Allocate<DistinctAttrStorage>()) |
415 | 411 | DistinctAttrStorage(referencedAttr);
|
416 |
| - } |
| 412 | + }; |
417 | 413 |
|
418 | 414 | private:
|
419 |
| - ThreadLocalCache<llvm::BumpPtrAllocator> allocatorCache; |
| 415 | + /// Used to allocate distict attribute storages. The managed memory is freed |
| 416 | + /// automatically when the allocator instance is destroyed. |
| 417 | + llvm::BumpPtrAllocator allocator; |
| 418 | + |
| 419 | + /// Used to lock access to the allocator. |
| 420 | + std::mutex allocatorMutex; |
420 | 421 | };
|
421 | 422 | } // namespace detail
|
422 | 423 | } // namespace mlir
|
|
0 commit comments