20 #include "mlir/Support/IndentedOstream.h"
22 #include "mlir/Dialect/Func/IR/FuncOps.h"
23 #include "mlir/IR/Builders.h"
24 #include "mlir/IR/BuiltinAttributes.h"
25 #include "mlir/IR/BuiltinTypes.h"
26 #include "llvm/ADT/IntervalMap.h"
27 #include "llvm/ADT/TypeSwitch.h"
28 #include "llvm/Support/Format.h"
36 return llvm::TypeSwitch<::mlir::Type, bool>(type)
37 .Case([](IntegerType t) {
return t.getWidth() <= 64; })
38 .Case([](hw::ArrayType t) {
return isSupported(t.getElementType()); })
39 .Case([outer](hw::StructType t) {
44 for (
auto field : t.getElements()) {
50 .Default([](Type) {
return false; });
58 if (
auto chan = dyn_cast<ChannelType>(
type))
64 TypeSwitch<Type>(
type)
65 .Case([
this](IntegerType t) {
69 .Case([
this](hw::ArrayType t) {
73 .Case([
this](hw::StructType t) {
74 fieldTypes.append(t.getElements().begin(), t.getElements().end());
76 .Default([](Type) {});
85 static void emitName(Type type, uint64_t
id, llvm::raw_ostream &os) {
86 llvm::TypeSwitch<Type>(type)
87 .Case([&os](IntegerType intTy) {
89 llvm::raw_string_ostream(intName) << intTy;
91 intName[0] = toupper(intName[0]);
94 .Case([&os](hw::ArrayType arrTy) {
95 os <<
"ArrayOf" << arrTy.getNumElements() <<
'x';
96 emitName(arrTy.getElementType(), 0, os);
98 .Case([&os](NoneType) { os <<
"None"; })
99 .Case([&os,
id](hw::StructType t) { os <<
"Struct" << id; })
101 assert(
false &&
"Type not supported. Please check support first with "
124 std::string typeName;
125 llvm::raw_string_ostream osName(typeName);
127 size_t overhang = osName.tell() % 64;
129 osName.indent(64 - overhang);
131 const char *typeNameC = typeName.c_str();
134 for (
size_t i = 0, e = typeName.length() / 64; i < e; ++i)
136 llvm::hashing::detail::hash_33to64_bytes(&typeNameC[i * 64], 64, hash);
139 cachedID = hash | 0x8000000000000000;
assert(baseType &&"element must be base type")
StringRef name() const
For now, the name is just the type serialized.
hw::StructType::FieldInfo FieldInfo
bool operator==(const ESIAPIType &) const
llvm::SmallVector< FieldInfo > fieldTypes
Cosim requires that everything be contained in a struct.
std::optional< uint64_t > cachedID
virtual bool isSupported() const
Returns true if the type is currently supported.
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
constexpr uint64_t esiApiVersion
Every time we implement a breaking change in the schema generation, increment this number.
mlir::Type innerType(mlir::Type type)
static void emitName(Type type, uint64_t id, llvm::raw_ostream &os)
Write a valid Capnp name for 'type'.
static bool isSupported(Type type, bool outer=false)
Returns true if the type is currently supported.
int64_t getBitWidth(mlir::Type type)
Return the hardware bit width of a type.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...