Skip to content

Commit

Permalink
[FIRRTL] enable properties for inherent attributes
Browse files Browse the repository at this point in the history
This enables properties in the FIRRTL dialect. Some op parsers which
called `inferReturnTypes` had to be updated to store inherent attributes
as properties on the OperationState, as the call to `inferReturnTypes`
expects properties to have already been populated.  This is a change
that we should make for all operation parsers and builders, to make
things faster, but is not strictly necessary at this time.
  • Loading branch information
youngar committed Oct 30, 2024
1 parent fd56341 commit f22f11a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
3 changes: 0 additions & 3 deletions include/circt/Dialect/FIRRTL/FIRRTLDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def FIRRTLDialect : Dialect {
let useDefaultTypePrinterParser = 0;
let useDefaultAttributePrinterParser = 1;

// Opt-out of properties for now, must migrate by LLVM 19. #5273.
let usePropertiesForAttributes = 0;

let dependentDialects = [
"circt::hw::HWDialect",
"circt::om::OMDialect",
Expand Down
10 changes: 4 additions & 6 deletions lib/Dialect/FIRRTL/FIRRTLOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4499,8 +4499,7 @@ ParseResult parseSubfieldLikeOp(OpAsmParser &parser, OperationState &result) {
"unknown field " + fieldName + " in bundle type ")
<< bundleType;

result.addAttribute(
"fieldIndex",
result.getOrAddProperties<typename OpTy::Properties>().setFieldIndex(
IntegerAttr::get(IntegerType::get(context, 32), *fieldIndex));

SmallVector<Type> inferredReturnTypes;
Expand Down Expand Up @@ -4540,8 +4539,7 @@ ParseResult SubtagOp::parse(OpAsmParser &parser, OperationState &result) {
"unknown field " + fieldName + " in enum type ")
<< enumType;

result.addAttribute(
"fieldIndex",
result.getOrAddProperties<Properties>().setFieldIndex(
IntegerAttr::get(IntegerType::get(context, 32), *fieldIndex));

SmallVector<Type> inferredReturnTypes;
Expand Down Expand Up @@ -4869,8 +4867,8 @@ ParseResult ObjectSubfieldOp::parse(OpAsmParser &parser,
return parser.emitError(parser.getNameLoc(),
"unknown field " + fieldName + " in class type ")
<< inputType;
result.addAttribute("index",
IntegerAttr::get(IntegerType::get(context, 32), *index));
result.getOrAddProperties<Properties>().setIndex(
IntegerAttr::get(IntegerType::get(context, 32), *index));

SmallVector<Type> inferredReturnTypes;
if (failed(inferReturnTypes(context, result.location, result.operands,
Expand Down
10 changes: 6 additions & 4 deletions test/Dialect/FIRRTL/annotations-generic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ firrtl.circuit "Foo" attributes {rawAnnotations = [
}
}

// CHECK-LABEL: "firrtl.extmodule"() ({
// CHECK: }) {
// CHECK-LABEL: "firrtl.extmodule"() <
// CHECK-SAME: portAnnotations = {{['[']['[']}}{class = "circt.test", data = "a"}]]
// CHECK-SAME: > ({
// CHECK: }) {
// CHECK-SAME: sym_name = "Bar"

// CHECK-LABEL: "firrtl.module"() ({
// CHECK: }) {
// CHECK-LABEL: "firrtl.module"() <
// CHECK-SAME: portAnnotations = {{['[']['[']}}{class = "circt.test", data = "b"}]]
// CHECK-SAME: > ({
// CHECK: }) {
// CHECK-SAME: sym_name = "Foo"

0 comments on commit f22f11a

Please sign in to comment.