14#ifndef CIRCT_DIALECT_HW_TYPES_H
15#define CIRCT_DIALECT_HW_TYPES_H
19#include "mlir/Interfaces/MemorySlotInterfaces.h"
22#include "mlir/IR/AttrTypeSubElements.h"
23#include "mlir/IR/BuiltinTypes.h"
24#include "mlir/IR/Types.h"
40 return llvm::hash_combine(port.
dir, port.
name, port.
type);
47 using KeyTy = ArrayRef<ModulePort>;
51 return std::equal(key.begin(), key.end(),
ports.begin(),
ports.end());
56 return llvm::hash_combine_range(key.begin(), key.end());
87ModuleType
fnToMod(Operation *op, ArrayRef<Attribute> inputNames,
88 ArrayRef<Attribute> outputNames);
89ModuleType
fnToMod(FunctionType fn, ArrayRef<Attribute> inputNames,
90 ArrayRef<Attribute> outputNames);
115struct AttrTypeSubElementHandler<
circt::hw::detail::FieldInfo> {
117 AttrTypeImmediateSubElementWalker &walker) {
118 walker.walk(param.
name);
119 walker.walk(param.
type);
123 AttrSubElementReplacements &attrRepls,
124 TypeSubElementReplacements &typeRepls) {
125 return {cast<StringAttr>(attrRepls.take_front(1)[0]),
126 typeRepls.take_front(1)[0]};
130struct AttrTypeSubElementHandler<
circt::hw::detail::OffsetFieldInfo> {
132 AttrTypeImmediateSubElementWalker &walker) {
133 walker.walk(param.
name);
134 walker.walk(param.
type);
138 AttrSubElementReplacements &attrRepls,
139 TypeSubElementReplacements &typeRepls) {
140 return {cast<StringAttr>(attrRepls.take_front(1)[0]),
141 typeRepls.take_front(1)[0], param.
offset};
146#define GET_TYPEDEF_CLASSES
147#include "circt/Dialect/HW/HWTypes.h.inc"
180template <
typename... BaseTy>
183 if (isa<BaseTy...>(type))
187 if (
auto alias = dyn_cast<TypeAliasType>(type))
188 return type_isa<BaseTy...>(alias.getInnerType());
194template <
typename... BaseTy>
201template <
typename BaseTy>
203 assert(type_isa<BaseTy>(type) &&
"type must convert to requested type");
206 if (isa<BaseTy>(type))
207 return cast<BaseTy>(type);
210 return type_cast<BaseTy>(cast<TypeAliasType>(type).getInnerType());
213template <
typename BaseTy>
215 if (!type_isa<BaseTy>(type))
218 return type_cast<BaseTy>(type);
224template <
typename... Types>
229 mlir::TypeStorage>::Base::Base;
236template <
typename BaseTy>
241 mlir::TypeStorage>::Base::Base;
245 static bool classof(Type other) {
return type_isa<BaseTy>(other); }
248 operator BaseTy()
const {
return type_cast<BaseTy>(*
this); }
assert(baseType &&"element must be base type")
This stores lookup tables to make manipulating and working with the IR more efficient.
static bool classof(Type other)
Utility type that wraps a type that may be one of several possible Types.
static bool classof(Type other)
ModuleType fnToMod(Operation *op, ArrayRef< Attribute > inputNames, ArrayRef< Attribute > outputNames)
BaseTy type_cast(Type type)
bool isHWIntegerType(mlir::Type type)
Return true if the specified type is a value HW Integer type.
bool type_isa_and_nonnull(Type type)
BaseTy type_dyn_cast(Type type)
bool isHWValueType(mlir::Type type)
Return true if the specified type can be used as an HW value type, that is the set of types that can ...
static bool operator==(const ModulePort &a, const ModulePort &b)
static llvm::hash_code hash_value(const ModulePort &port)
int64_t getBitWidth(mlir::Type type)
Return the hardware bit width of a type.
bool isHWEnumType(mlir::Type type)
Return true if the specified type is a HW Enum type.
mlir::Type getCanonicalType(mlir::Type type)
bool hasHWInOutType(mlir::Type type)
Return true if the specified type contains known marker types like InOutType.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Struct defining a field. Used in structs.
SmallVector< ModulePort > ports
The parametric data held by the storage class.
static llvm::hash_code hashKey(const KeyTy &key)
Define a hash function for the key type.
SmallVector< size_t > absToInput
bool operator==(const KeyTy &key) const
Define the comparison function for the key type.
SmallVector< size_t > outputToAbs
SmallVector< size_t > inputToAbs
ArrayRef< ModulePort > KeyTy
static ModuleTypeStorage * construct(mlir::TypeStorageAllocator &allocator, const KeyTy &key)
Define a construction method for creating a new instance of this storage.
ArrayRef< ModulePort > getPorts() const
KeyTy getAsKey() const
Construct an instance of the key from this storage class.
SmallVector< size_t > absToOutput
Struct defining a field with an offset. Used in unions.
static void walk(const circt::hw::detail::FieldInfo ¶m, AttrTypeImmediateSubElementWalker &walker)
static circt::hw::detail::FieldInfo replace(const circt::hw::detail::FieldInfo ¶m, AttrSubElementReplacements &attrRepls, TypeSubElementReplacements &typeRepls)
static void walk(const circt::hw::detail::OffsetFieldInfo ¶m, AttrTypeImmediateSubElementWalker &walker)
static circt::hw::detail::OffsetFieldInfo replace(const circt::hw::detail::OffsetFieldInfo ¶m, AttrSubElementReplacements &attrRepls, TypeSubElementReplacements &typeRepls)