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