19#include "mlir/IR/DialectImplementation.h"
20#include "llvm/ADT/APSInt.h"
21#include "llvm/ADT/SmallString.h"
22#include "llvm/ADT/TypeSwitch.h"
31void FIRRTLDialect::initialize() {
36 addInterface<FIRRTLIntrinsicLoweringDialectInterface>();
46Operation *FIRRTLDialect::materializeConstant(OpBuilder &builder,
47 Attribute value, Type type,
53 if (
auto attrValue = dyn_cast<BoolAttr>(value)) {
54 if (isa<BoolType>(type))
55 return BoolConstantOp::create(builder, loc, type, attrValue);
56 assert((isa<ClockType, AsyncResetType, ResetType>(type) &&
57 "BoolAttrs can only be materialized for special constant types."));
58 return SpecialConstantOp::create(builder, loc, type, attrValue);
62 if (
auto attrValue = dyn_cast<IntegerAttr>(value)) {
63 if (isa<FIntegerType>(type))
64 return FIntegerConstantOp::create(builder, loc, type, attrValue);
66 if (attrValue.getValue().getBitWidth() == 1 &&
67 isa<ClockType, AsyncResetType, ResetType>(type))
68 return SpecialConstantOp::create(
70 builder.getBoolAttr(attrValue.getValue().isAllOnes()));
74 attrValue.getValue().getBitWidth()) &&
75 "type/value width mismatch materializing constant");
76 return ConstantOp::create(builder, loc, type, attrValue);
80 if (
auto arrayAttr = dyn_cast<ArrayAttr>(value)) {
81 if (isa<BundleType, FVectorType>(type))
82 return AggregateConstantOp::create(builder, loc, type, arrayAttr);
86 if (
auto stringAttr = dyn_cast<StringAttr>(value)) {
88 return StringConstantOp::create(builder, loc, type, stringAttr);
95#include "circt/Dialect/FIRRTL/FIRRTLEnums.cpp.inc"
97#include "circt/Dialect/FIRRTL/FIRRTLDialect.cpp.inc"
assert(baseType &&"element must be base type")
BaseTy type_cast(Type type)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.