17 #include "mlir/IR/Builders.h"
18 #include "mlir/IR/BuiltinAttributes.h"
19 #include "mlir/IR/BuiltinTypes.h"
20 #include "mlir/IR/DialectImplementation.h"
21 #include "mlir/Transforms/InliningUtils.h"
23 using namespace circt;
31 #include "circt/Dialect/HW/HWDialect.cpp.inc"
37 struct HWOpAsmDialectInterface :
public OpAsmDialectInterface {
38 using OpAsmDialectInterface::OpAsmDialectInterface;
48 struct HWInlinerInterface :
public mlir::DialectInlinerInterface {
49 using mlir::DialectInlinerInterface::DialectInlinerInterface;
51 bool isLegalToInline(Operation *op, Region *,
bool,
52 mlir::IRMapping &)
const final {
53 return isa<ConstantOp>(op) || isa<AggregateConstantOp>(op) ||
54 isa<EnumConstantOp>(op) || isa<BitcastOp>(op) ||
55 isa<ArrayCreateOp>(op) || isa<ArrayConcatOp>(op) ||
56 isa<ArraySliceOp>(op) || isa<ArrayGetOp>(op) ||
57 isa<StructCreateOp>(op) || isa<StructExplodeOp>(op) ||
58 isa<StructExtractOp>(op) || isa<StructInjectOp>(op) ||
59 isa<UnionCreateOp>(op) || isa<UnionExtractOp>(op);
62 bool isLegalToInline(Region *, Region *,
bool,
63 mlir::IRMapping &)
const final {
69 void HWDialect::initialize() {
77 #include "circt/Dialect/HW/HW.cpp.inc"
81 addInterfaces<HWOpAsmDialectInterface, HWInlinerInterface>();
91 Operation *HWDialect::materializeConstant(OpBuilder &builder, Attribute value,
92 Type type, Location loc) {
94 if (
auto intType = dyn_cast<IntegerType>(type))
95 if (
auto attrValue = dyn_cast<IntegerAttr>(value))
96 return builder.create<
ConstantOp>(loc, type, attrValue);
99 if (
auto arrayAttr = dyn_cast<ArrayAttr>(value)) {
100 if (isa<StructType, ArrayType, UnpackedArrayType>(type))
101 return builder.
create<AggregateConstantOp>(loc, type, arrayAttr);
105 auto parentOp = builder.getBlock()->getParentOp();
106 auto curModule = dyn_cast<HWModuleOp>(parentOp);
108 curModule = parentOp->getParentOfType<
HWModuleOp>();
110 return builder.create<ParamValueOp>(loc, type, value);
def create(data_type, value)
void getAsmResultNames(OpAsmSetValueNameFn setNameFn, StringRef instanceName, ArrayAttr resultNames, ValueRange results)
Suggest a name for each result value based on the saved result names attribute.
bool isValidParameterExpression(Attribute attr, Operation *module)
Return true if the specified attribute tree is made up of nodes that are valid in a parameter express...
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
function_ref< void(Value, StringRef)> OpAsmSetValueNameFn