[ParamBinaryAttr] add a nicer builder.

This commit is contained in:
Chris Lattner 2021-09-26 21:49:22 -07:00
parent 63e0be7a8a
commit e8b21a3653
4 changed files with 12 additions and 5 deletions

View File

@ -160,6 +160,15 @@ def ParamBinaryAttr : AttrDef<HWDialect, "ParamBinary"> {
"::mlir::Attribute":$lhs, "::mlir::Attribute":$rhs,
AttributeSelfTypeParameter<"">:$type);
let mnemonic = "param.binary";
let builders = [
AttrBuilderWithInferredContext<(ins
"PBO":$opcode,
"::mlir::Attribute":$lhs,
"::mlir::Attribute":$rhs), [{
return get(lhs.getContext(), opcode, lhs, rhs, lhs.getType());
}]>,
];
}
let cppNamespace = "circt::hw" in {

View File

@ -1217,8 +1217,7 @@ OpFoldResult AddOp::fold(ArrayRef<Attribute> constants) {
// If this is a binary add of parameter compatible values, fold it.
// TODO: Generalize this after cleaning up ParamBinaryAttr.
if (constants.size() == 2 && constants[1] && constants[0])
return hw::ParamBinaryAttr::get(getContext(), hw::PBO::Add, constants[0],
constants[1], constants[0].getType());
return hw::ParamBinaryAttr::get(hw::PBO::Add, constants[0], constants[1]);
return {};
}

View File

@ -214,7 +214,7 @@ Attribute ParamBinaryAttr::parse(MLIRContext *context, DialectAsmParser &p,
return {};
}
return ParamBinaryAttr::get(context, *opcode, lhs, rhs, type);
return ParamBinaryAttr::get(*opcode, lhs, rhs);
}
void ParamBinaryAttr::print(DialectAsmPrinter &p) const {

View File

@ -229,8 +229,7 @@ remapRenamedParameters(Attribute value, HWModuleOp module,
// Don't rebuild an attribute if nothing changed.
if (newLHS == binOp.getLhs() && newRHS == binOp.getRhs())
return value;
return ParamBinaryAttr::get(value.getContext(), binOp.getOpcode(), newLHS,
newRHS, value.getType());
return ParamBinaryAttr::get(binOp.getOpcode(), newLHS, newRHS);
}
// Otherwise this must be a parameter reference.