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"
24#include "mlir/IR/AttrTypeSubElements.h"
25#include "mlir/IR/BuiltinTypes.h"
26#include "mlir/IR/Types.h"
46 llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
48 return mlir::success();
68 return llvm::hash_combine(port.
dir, port.
name, port.
type);
75 using KeyTy = ArrayRef<ModulePort>;
79 return std::equal(key.begin(), key.end(),
ports.begin(),
ports.end());
84 return llvm::hash_combine_range(key.begin(), key.end());
115ModuleType
fnToMod(Operation *op, ArrayRef<Attribute> inputNames,
116 ArrayRef<Attribute> outputNames);
117ModuleType
fnToMod(FunctionType fn, ArrayRef<Attribute> inputNames,
118 ArrayRef<Attribute> outputNames);
139struct AttrTypeSubElementHandler<
circt::hw::detail::OffsetFieldInfo> {
141 AttrTypeImmediateSubElementWalker &walker) {
142 walker.walk(param.
name);
143 walker.walk(param.
type);
147 AttrSubElementReplacements &attrRepls,
148 TypeSubElementReplacements &typeRepls) {
149 return {cast<StringAttr>(attrRepls.take_front(1)[0]),
150 typeRepls.take_front(1)[0], param.
offset};
155#define GET_TYPEDEF_CLASSES
156#include "circt/Dialect/HW/HWTypes.h.inc"
193 const APInt &intVal, ArrayAttr &result);
202template <
typename... BaseTy>
205 if (isa<BaseTy...>(type))
209 if (
auto alias = dyn_cast<TypeAliasType>(type))
210 return type_isa<BaseTy...>(alias.getInnerType());
216template <
typename... BaseTy>
223template <
typename BaseTy>
225 assert(type_isa<BaseTy>(type) &&
"type must convert to requested type");
228 if (isa<BaseTy>(type))
229 return cast<BaseTy>(type);
232 return type_cast<BaseTy>(cast<TypeAliasType>(type).getInnerType());
235template <
typename BaseTy>
237 if (!type_isa<BaseTy>(type))
240 return type_cast<BaseTy>(type);
246template <
typename... Types>
251 mlir::TypeStorage>::Base::Base;
258template <
typename BaseTy>
263 mlir::TypeStorage>::Base::Base;
267 static bool classof(Type other) {
return type_isa<BaseTy>(other); }
270 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)
Recursively remove HW type aliases from a type and its subelements.
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.
A named and typed field of an aggregate type.
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)
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::OffsetFieldInfo ¶m, AttrTypeImmediateSubElementWalker &walker)
static circt::hw::detail::OffsetFieldInfo replace(const circt::hw::detail::OffsetFieldInfo ¶m, AttrSubElementReplacements &attrRepls, TypeSubElementReplacements &typeRepls)