14#ifndef CIRCT_DIALECT_HW_INNERSYMBOLTABLE_H 
   15#define CIRCT_DIALECT_HW_INNERSYMBOLTABLE_H 
   19#include "mlir/IR/BuiltinAttributes.h" 
   20#include "mlir/IR/SymbolTable.h" 
   21#include "llvm/ADT/StringRef.h" 
   82  Operation *
op = 
nullptr;
 
  100  operator bool()
 const { 
return op; }
 
 
  125  Operation *
lookupOp(StringRef name) 
const;
 
  126  template <
typename T>
 
  128    return dyn_cast_or_null<T>(
lookupOp(name));
 
 
  133  Operation *
lookupOp(StringAttr name) 
const;
 
  134  template <
typename T>
 
  136    return dyn_cast_or_null<T>(
lookupOp(name));
 
 
  150  static FailureOr<InnerSymbolTable> 
get(Operation *op);
 
  153      llvm::function_ref<LogicalResult(StringAttr, 
const InnerSymTarget &)>;
 
  159  template <
typename FuncTy, 
typename RetTy = 
typename std::invoke_result_t<
 
  162    if constexpr (std::is_void_v<RetTy>)
 
  166                    std::invoke(std::forward<FuncTy>(callback), name, target);
 
  173            return std::invoke(std::forward<FuncTy>(callback), name, target);
 
 
  187      if (failed(callback(name, target)))
 
 
  193  using TableTy = DenseMap<StringAttr, InnerSymTarget>;
 
 
  223    assert(succeeded(result));
 
 
 
  246  Operation *
lookupOp(hw::InnerRefAttr inner) 
const;
 
  247  template <
typename T>
 
  249    return dyn_cast_or_null<T>(
lookupOp(inner));
 
 
 
  254template <
typename OS>
 
  257    return os << 
"<invalid target>";
 
  260    os << 
"field " << target.
getField() << 
" of ";
 
  263    os << 
"port " << target.
getPort() << 
" on @" 
  264       << SymbolTable::getSymbolName(target.
getOp()).getValue() << 
"";
 
  266    os << 
"op " << *target.
getOp() << 
"";
 
 
assert(baseType &&"element must be base type")
The target of an inner symbol, the entity the symbol is a handle for.
bool isOpOnly() const
Returns if this targets an operation only (not port or field).
InnerSymTarget(size_t portIdx, Operation *op, size_t fieldID=0)
Target a port, and optionally a field (=0 means the port itself).
auto getField() const
Return the target's fieldID.
bool isField() const
Return if this targets a field (nonzero fieldID).
static InnerSymTarget getTargetForSubfield(const InnerSymTarget &base, size_t fieldID)
Return a target to the specified field within the given base.
InnerSymTarget(InnerSymTarget &&)=default
InnerSymTarget(Operation *op)
Target an operation.
auto getPort() const
Return the target's port, if valid. Check "isPort()".
InnerSymTarget(Operation *op, size_t fieldID)
Target an operation and a field (=0 means the op itself).
InnerSymTarget()
Default constructor, invalid.
bool operator==(const InnerSymTarget &rhs) const
bool isPort() const
Return if this targets a port.
Operation * getOp() const
Return the target's base operation. For ports, this is the module.
InnerSymTarget(const InnerSymTarget &)=default
InnerSymTarget & operator=(InnerSymTarget &&)=default
static constexpr size_t invalidPort
InnerSymTarget & operator=(const InnerSymTarget &)=default
This class represents a collection of InnerSymbolTable's.
InnerSymbolTableCollection & operator=(const InnerSymbolTableCollection &)=delete
InnerSymbolTableCollection()=default
DenseMap< Operation *, std::unique_ptr< InnerSymbolTable > > symbolTables
This maps Operations to their InnnerSymbolTable's.
InnerSymbolTableCollection(Operation *innerRefNSOp)
LogicalResult populateAndVerifyTables(Operation *innerRefNSOp)
Populate tables in parallel for all InnerSymbolTable operations in the given InnerRefNamespace operat...
InnerSymbolTableCollection(const InnerSymbolTableCollection &)=delete
InnerSymbolTable & getInnerSymbolTable(Operation *op)
Get or create the InnerSymbolTable for the specified operation.
A table of inner symbols and their resolutions.
Operation * innerSymTblOp
This is the operation this table is constructed for, which must have the InnerSymbolTable trait.
T lookupOp(StringAttr name) const
InnerSymbolTable(const InnerSymbolTable &)=delete
Non-copyable.
LogicalResult walkSymbols(InnerSymCallbackFn callback) const
Invoke the callback for all symbols in this table.
T lookupOp(StringRef name) const
InnerSymTarget lookup(StringRef name) const
Look up a symbol with the specified name, returning empty InnerSymTarget if no such name exists.
DenseMap< StringAttr, InnerSymTarget > TableTy
InnerSymbolTable & operator=(InnerSymbolTable &&)=default
static StringAttr getInnerSymbol(Operation *op)
Get InnerSymbol for an operation.
llvm::function_ref< LogicalResult(StringAttr, const InnerSymTarget &)> InnerSymCallbackFn
InnerSymbolTable(InnerSymbolTable &&)=default
static RetTy walkSymbols(Operation *op, FuncTy &&callback)
Walk the given IST operation and invoke the callback for all encountered inner symbols.
InnerSymbolTable(Operation *op, TableTy &&table)
Construct an inner symbol table for the given operation, with pre-populated table contents.
Operation * lookupOp(StringRef name) const
Look up a symbol with the specified name, returning null if no such name exists or doesn't target jus...
InnerSymbolTable & operator=(const InnerSymbolTable &)=delete
static FailureOr< InnerSymbolTable > get(Operation *op)
Construct an InnerSymbolTable, checking for verification failure.
TableTy symbolTable
This maps inner symbol names to their targets.
static StringRef getInnerSymbolAttrName()
Return the name of the attribute used for inner symbol names.
OS & operator<<(OS &os, const InnerSymTarget &target)
Printing InnerSymTarget's.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
This class represents the namespace in which InnerRef's can be resolved.
T lookupOp(hw::InnerRefAttr inner) const
InnerSymTarget lookup(hw::InnerRefAttr inner) const
Resolve the InnerRef to its target within this namespace, returning empty target if no such name exis...
Operation * lookupOp(hw::InnerRefAttr inner) const
Resolve the InnerRef to its target within this namespace, returning empty target if no such name exis...
InnerSymbolTableCollection & innerSymTables