17#include "mlir/IR/Builders.h"
18#include "mlir/IR/Diagnostics.h"
19#include "mlir/IR/DialectImplementation.h"
20#include "llvm/ADT/TypeSwitch.h"
31 return array.getElementType();
33 return array.getElementType();
44 if (isa<hw::IntType, IntegerType, hw::EnumType>(type))
47 if (
auto array = dyn_cast<hw::ArrayType>(type))
50 if (
auto t = dyn_cast<hw::StructType>(type))
51 return llvm::all_of(t.getElements(),
52 [](
auto f) { return isPackedType(f.type); });
54 if (
auto t = dyn_cast<hw::UnionType>(type))
55 return llvm::all_of(t.getElements(),
56 [](
auto m) { return isPackedType(m.type); });
68 if (
auto inout = dyn_cast_or_null<InOutType>(type))
69 return inout.getElementType();
81 if (
auto inout = dyn_cast_or_null<InOutType>(type))
82 return inout.getElementType();
83 if (
auto net = dyn_cast_or_null<NetType>(type))
84 return net.getElementType();
85 if (
auto var = dyn_cast_or_null<VarType>(type))
86 return var.getElementType();
96 if (isa_and_present<InOutType>(handleType))
98 if (isa_and_present<NetType>(handleType))
100 if (isa_and_present<VarType>(handleType))
112 if (
auto net = dyn_cast_or_null<NetType>(type))
113 return net.getElementType();
120 while (
auto uarray = dyn_cast<hw::UnpackedArrayType>(type))
121 type = uarray.getElementType();
130LogicalResult NetType::verify(function_ref<InFlightDiagnostic()> emitError,
132 if (isa_and_present<NetType, VarType>(
elementType))
133 return emitError() <<
"sv.net element type may not be itself an sv.net or "
139 <<
"sv.net element type must have a packed base type, but got "
140 << packedElementType;
152 if (
auto var = dyn_cast_or_null<VarType>(type))
153 return var.getElementType();
161 if (
auto uarray = dyn_cast<hw::UnpackedArrayType>(type))
173LogicalResult VarType::verify(function_ref<InFlightDiagnostic()> emitError,
175 if (isa_and_present<VarType, NetType>(
elementType))
176 return emitError() <<
"sv.var element type may not be itself an sv.var or "
179 return emitError() <<
"sv.var element type must be a valid value type, "
190#define GET_TYPEDEF_CLASSES
191#include "circt/Dialect/SV/SVTypes.cpp.inc"
193void SVDialect::registerTypes() {
195#define GET_TYPEDEF_LIST
196#include "circt/Dialect/SV/SVTypes.cpp.inc"
static bool isValidVarElementTypeImpl(Type type)
static bool isPackedType(Type type)
Return true if the specified type has a packed layout, i.e.
static Type stripUnpackedDimensions(Type type)
Return the innermost non-unpacked element type.
BaseTy type_dyn_cast(Type type)
mlir::Type getCanonicalType(mlir::Type type)
Recursively remove HW type aliases from a type and its subelements.
mlir::Type getVarElementType(mlir::Type type)
Return the element type of a VarType or null if the operand isn't a Var type.
bool isValidNetElementType(mlir::Type type)
Return true if a type is a valid element type of a NetType.
mlir::Type getAnyHWArrayElementType(mlir::Type type)
Return the element type of an ArrayType or UnpackedArrayType, or null if the operand isn't an array.
mlir::Type getHandleOfElementType(mlir::Type handleType, mlir::Type elementType)
Return a handle of the same kind (NetType or VarType) as handleType, wrapping elementType instead.
mlir::Type getNetElementType(mlir::Type type)
Return the element type of a NetType or null if the operand isn't a Net type.
mlir::Type getInOutElementType(mlir::Type type)
Return the element type of an InOutType or null if the operand isn't an InOut type.
mlir::Type getHandleElementType(mlir::Type type)
Return the element type of an SV handle type or null if the operand is not an SV lvalue (NetType or V...
bool isValidVarElementType(mlir::Type type)
Return true if a type is a valid element type of a VarType.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.