mirror of https://github.com/llvm/circt.git
[ParamBinaryAttr] add a nicer builder.
This commit is contained in:
parent
63e0be7a8a
commit
e8b21a3653
|
@ -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 {
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue