19 #include "mlir/IR/DialectImplementation.h"
20 #include "llvm/ADT/APSInt.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/TypeSwitch.h"
24 using namespace circt;
25 using namespace firrtl;
31 void FIRRTLDialect::initialize() {
39 #include "circt/Dialect/FIRRTL/FIRRTL.cpp.inc"
42 addInterface<FIRRTLIntrinsicLoweringDialectInterface>();
52 Operation *FIRRTLDialect::materializeConstant(OpBuilder &builder,
53 Attribute value, Type type,
59 if (
auto attrValue = dyn_cast<BoolAttr>(value)) {
60 if (isa<BoolType>(type))
61 return builder.create<BoolConstantOp>(loc, type, attrValue);
62 assert((isa<ClockType, AsyncResetType, ResetType>(type) &&
63 "BoolAttrs can only be materialized for special constant types."));
64 return builder.create<SpecialConstantOp>(loc, type, attrValue);
68 if (
auto attrValue = dyn_cast<IntegerAttr>(value)) {
69 if (isa<FIntegerType>(type))
70 return builder.create<FIntegerConstantOp>(loc, type, attrValue);
72 if (attrValue.getValue().getBitWidth() == 1 &&
73 isa<ClockType, AsyncResetType, ResetType>(type))
74 return builder.create<SpecialConstantOp>(
75 loc, type, builder.getBoolAttr(attrValue.getValue().isAllOnes()));
77 assert((!type_cast<IntType>(type).hasWidth() ||
78 (
unsigned)type_cast<IntType>(type).getWidthOrSentinel() ==
79 attrValue.getValue().getBitWidth()) &&
80 "type/value width mismatch materializing constant");
81 return builder.create<ConstantOp>(loc, type, attrValue);
85 if (
auto arrayAttr = dyn_cast<ArrayAttr>(value)) {
86 if (isa<BundleType, FVectorType>(type))
87 return builder.create<AggregateConstantOp>(loc, type, arrayAttr);
91 if (
auto stringAttr = dyn_cast<StringAttr>(value)) {
92 if (type_isa<StringType>(type))
93 return builder.create<StringConstantOp>(loc, type, stringAttr);
100 #include "circt/Dialect/FIRRTL/FIRRTLEnums.cpp.inc"
102 #include "circt/Dialect/FIRRTL/FIRRTLDialect.cpp.inc"
assert(baseType &&"element must be base type")
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.