14#ifndef CIRCT_DIALECT_HW_TYPES_H
15#define CIRCT_DIALECT_HW_TYPES_H
19#include "mlir/IR/DialectInterface.h"
20#include "mlir/Interfaces/MemorySlotInterfaces.h"
23#include "mlir/IR/AttrTypeSubElements.h"
24#include "mlir/IR/BuiltinTypes.h"
25#include "mlir/IR/Types.h"
45 llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
47 return mlir::success();
67 return llvm::hash_combine(port.
dir, port.
name, port.
type);
74 using KeyTy = ArrayRef<ModulePort>;
78 return std::equal(key.begin(), key.end(),
ports.begin(),
ports.end());
83 return llvm::hash_combine_range(key.begin(), key.end());
114ModuleType
fnToMod(Operation *op, ArrayRef<Attribute> inputNames,
115 ArrayRef<Attribute> outputNames);
116ModuleType
fnToMod(FunctionType fn, ArrayRef<Attribute> inputNames,
117 ArrayRef<Attribute> outputNames);
142struct AttrTypeSubElementHandler<
circt::hw::detail::FieldInfo> {
144 AttrTypeImmediateSubElementWalker &walker) {
145 walker.walk(param.
name);
146 walker.walk(param.
type);
150 AttrSubElementReplacements &attrRepls,
151 TypeSubElementReplacements &typeRepls) {
152 return {cast<StringAttr>(attrRepls.take_front(1)[0]),
153 typeRepls.take_front(1)[0]};
157struct AttrTypeSubElementHandler<
circt::hw::detail::OffsetFieldInfo> {
159 AttrTypeImmediateSubElementWalker &walker) {
160 walker.walk(param.
name);
161 walker.walk(param.
type);
165 AttrSubElementReplacements &attrRepls,
166 TypeSubElementReplacements &typeRepls) {
167 return {cast<StringAttr>(attrRepls.take_front(1)[0]),
168 typeRepls.take_front(1)[0], param.
offset};
173#define GET_TYPEDEF_CLASSES
174#include "circt/Dialect/HW/HWTypes.h.inc"
211 const APInt &intVal, ArrayAttr &result);
220template <
typename... BaseTy>
223 if (isa<BaseTy...>(type))
227 if (
auto alias = dyn_cast<TypeAliasType>(type))
228 return type_isa<BaseTy...>(alias.getInnerType());
234template <
typename... BaseTy>
241template <
typename BaseTy>
243 assert(type_isa<BaseTy>(type) &&
"type must convert to requested type");
246 if (isa<BaseTy>(type))
247 return cast<BaseTy>(type);
250 return type_cast<BaseTy>(cast<TypeAliasType>(type).getInnerType());
253template <
typename BaseTy>
255 if (!type_isa<BaseTy>(type))
258 return type_cast<BaseTy>(type);
264template <
typename... Types>
269 mlir::TypeStorage>::Base::Base;
276template <
typename BaseTy>
281 mlir::TypeStorage>::Base::Base;
285 static bool classof(Type other) {
return type_isa<BaseTy>(other); }
288 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)
bool isValidProbeElementType(mlir::Type type)
Return true if type is a valid probe payload.
LogicalResult aggregateAttrToAPInt(mlir::Type type, ArrayAttr attr, APInt &result)
Convert an ArrayAttr into an APInt value matching the given type.
int64_t getBitWidth(mlir::Type type)
Return the hardware bit width of a type.
LogicalResult apIntToAggregateAttr(mlir::Type aggregateType, const APInt &intVal, ArrayAttr &result)
Convert an APInt value into a nested aggregate attribute matching the given HWAggregateType.
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.
virtual mlir::LogicalResult verifyHWModulePortType(llvm::function_ref< mlir::InFlightDiagnostic()> emitError, ModulePort::Direction direction, mlir::Type type) const
Return failure if type is not valid for a module port with the given direction.
HWModulePortTypeInterface(mlir::Dialect *dialect)
Interface for dialects to classify their types as valid probe payloads.
virtual bool isValidProbeElementType(mlir::Type type) const =0
ProbeTypeDialectInterface(mlir::Dialect *dialect)
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)