13 #ifndef CIRCT_SUPPORT_SYMCACHE_H
14 #define CIRCT_SUPPORT_SYMCACHE_H
16 #include "mlir/IR/SymbolTable.h"
17 #include "llvm/ADT/iterator.h"
18 #include "llvm/Support/Casting.h"
30 virtual void addDefinition(mlir::Attribute symbol, mlir::Operation *op) = 0;
42 virtual mlir::Operation *
getDefinition(mlir::Attribute symbol)
const = 0;
52 using CacheItem = std::pair<mlir::Attribute, mlir::Operation *>;
61 :
public llvm::iterator_facade_base<Iterator, std::forward_iterator_tag,
66 using llvm::iterator_facade_base<
Iterator, std::forward_iterator_tag,
74 std::unique_ptr<CacheIteratorImpl>
impl;
123 std::make_unique<SymbolCacheIteratorImpl>(
symbolCache.begin()));
127 std::make_unique<SymbolCacheIteratorImpl>(
symbolCache.end()));
Base symbol cache class to allow for cache lookup through a pointer to some abstract cache.
void addDefinitions(mlir::Operation *top)
Populate the symbol cache with all symbol-defining operations within the 'top' operation.
void addSymbol(mlir::SymbolOpInterface op)
Adds the symbol-defining 'op' to the cache.
virtual ~SymbolCacheBase()
Virtual method anchor.
virtual void addDefinition(mlir::Attribute symbol, mlir::Operation *op)=0
Defines 'op' as associated with the 'symbol' in the cache.
virtual mlir::Operation * getDefinition(mlir::Attribute symbol) const =0
Lookup a definition for 'symbol' in the cache.
virtual Iterator begin()=0
mlir::Operation * getDefinition(mlir::FlatSymbolRefAttr symbol) const
Lookup a definition for 'symbol' in the cache.
std::pair< mlir::Attribute, mlir::Operation * > CacheItem
Iterator support through a pointer to some abstract cache.
Default symbol cache implementation; stores associations between names (StringAttr's) to mlir::Operat...
void addDefinition(mlir::Attribute key, mlir::Operation *op) override
In the building phase, add symbols.
llvm::DenseMap< mlir::Attribute, mlir::Operation * > symbolCache
This stores a lookup table from symbol attribute to the operation that defines it.
decltype(symbolCache)::iterator Iterator
Iterator support: A simple mapping between decltype(symbolCache)::iterator to SymbolCacheBase::Iterat...
SymbolCacheBase::Iterator end() override
SymbolCacheBase::Iterator begin() override
mlir::Operation * getDefinition(mlir::Attribute attr) const override
Lookup a definition for 'symbol' in the cache.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
virtual CacheItem operator*()=0
virtual void operator++()=0
virtual ~CacheIteratorImpl()
virtual bool operator==(CacheIteratorImpl *other)=0
CacheItem operator*() const
std::unique_ptr< CacheIteratorImpl > impl
Iterator(std::unique_ptr< CacheIteratorImpl > &&impl)
bool operator==(const Iterator &other) const
SymbolCacheIteratorImpl(Iterator it)
void operator++() override
CacheItem operator*() override
bool operator==(CacheIteratorImpl *other) override