13 #ifndef MLIR_SUPPORT_SYMCACHE_H
14 #define MLIR_SUPPORT_SYMCACHE_H
17 #include "llvm/ADT/iterator.h"
18 #include "llvm/Support/Casting.h"
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,
69 return *
impl == other.impl.get();
74 std::unique_ptr<CacheIteratorImpl>
impl;
111 SymbolCacheIteratorImpl(Iterator it) : it(it) {}
115 return it ==
static_cast<SymbolCacheIteratorImpl *
>(other)->it;
123 std::make_unique<SymbolCacheIteratorImpl>(
symbolCache.begin()));
127 std::make_unique<SymbolCacheIteratorImpl>(
symbolCache.end()));
Attributes are known-constant values of operations.
A symbol reference with a reference path containing a single element.
StringAttr getAttr() const
Returns the name of the held symbol reference as a StringAttr.
Operation is the basic unit of execution within MLIR.
Base symbol cache class to allow for cache lookup through a pointer to some abstract cache.
std::pair< mlir::Attribute, mlir::Operation * > CacheItem
Iterator support through a pointer to some abstract cache.
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.
mlir::Operation * getDefinition(mlir::FlatSymbolRefAttr symbol) const
Lookup a definition for 'symbol' in the 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 Iterator begin()=0
Default symbol cache implementation; stores associations between names (StringAttr's) to mlir::Operat...
SymbolCacheBase::Iterator end() override
mlir::Operation * getDefinition(mlir::Attribute attr) const override
Lookup a definition for 'symbol' in the cache.
SymbolCacheBase::Iterator begin() override
llvm::DenseMap< mlir::Attribute, mlir::Operation * > symbolCache
This stores a lookup table from symbol attribute to the operation that defines it.
void addDefinition(mlir::Attribute key, mlir::Operation *op) override
In the building phase, add symbols.
static MappingLevel & operator++(MappingLevel &mappingLevel)
Bounded increment on MappingLevel.
Include the generated interface declarations.
bool operator==(StringAttr lhs, std::nullptr_t)
Define comparisons for StringAttr against nullptr and itself to avoid the StringRef overloads from be...
AffineExpr operator*(int64_t val, AffineExpr expr)
virtual void operator++()=0
virtual ~CacheIteratorImpl()
virtual bool operator==(CacheIteratorImpl *other)=0
virtual CacheItem operator*()=0
bool operator==(const Iterator &other) const
Iterator(std::unique_ptr< CacheIteratorImpl > &&impl)
CacheItem operator*() const