[FIRRTL][OM] Use signed integer attributes#9548
Conversation
eb71ab9 to
99b77ff
Compare
| if (apInt.isNegative()) { | ||
| ++width; | ||
| apInt = apInt.zext(width); | ||
| } |
There was a problem hiding this comment.
Consider:
| if (apInt.isNegative()) { | |
| ++width; | |
| apInt = apInt.zext(width); | |
| } | |
| if (apInt.isNegative()) | |
| apInt = apInt.zext(++width); |
| } | ||
| type = IntegerType::get(context, width, IntegerType::Signed); | ||
| intConstant = IntegerAttr::get(type, apInt); | ||
| } |
There was a problem hiding this comment.
This looks great. Thanks for taking the time to do this correctly and get the width correct.
| let results = (outs FIntegerType:$result); | ||
| let hasFolder = 1; | ||
| let hasCustomAssemblyFormat = true; | ||
| let hasVerifier = true; |
There was a problem hiding this comment.
Doing this with the verifier is fine. Did you explore changing this from APSIntAttr to some other, stricter constraint? E.g., like how OMIntegerAttr does it? WDYT?
There was a problem hiding this comment.
I didn't for this PR, but something along those lines would be great. Honestly I think we should build out a whole new bigint attribute, rather than using APInts and IntegerAttrs directly.
|
circt/lib/Bindings/Python/OMModule.cpp Line 298 in f5a6e91 Not actually tested but I feel this line is problematic. I think it's ok to consider python integer to si64 (historically we are using i64 for python integer, not ideal thouigh... |
0a40434 to
6566dc1
Compare
1138577 to
d53751e
Compare
| return IntegerAttr::get(IntegerType::get(getContext(), | ||
| lhsCst->getBitWidth(), | ||
| IntegerType::Signed), | ||
| lhsCst->shl(*rhsCst)); |
There was a problem hiding this comment.
I believe there is a bug here, which I am not fixing in this PR. This folder should be extending the width before shifting. Probably, the evaluator has the same issue.
Demo
firrtl.circuit "Casts" {
firrtl.module @Casts() {}
firrtl.class @PropertyArithmetic(out %o1: !firrtl.integer) {
%0 = firrtl.integer 4
%1 = firrtl.integer.shl %0, %0 : (!firrtl.integer, !firrtl.integer) -> !firrtl.integer
firrtl.propassign %o1, %1 : !firrtl.integer
}
}
// ./bin/circt-opt -canonicalize='top-down=true region-simplify=aggressive' ../scratch/scratch.mlir --mlir-print-ir-before-all
module {
firrtl.circuit "Casts" {
firrtl.module @Casts() {
}
firrtl.class @PropertyArithmetic(out %o1: !firrtl.integer) {
%0 = firrtl.integer 0
firrtl.propassign %o1, %0 : !firrtl.integer
}
}
}
seldridge
left a comment
There was a problem hiding this comment.
LGTM
Are there error tests that can be added?
| type = IntegerType::get(context, width, IntegerType::Signed); | ||
| intConstant = IntegerAttr::get(type, apInt); | ||
| } | ||
| return FIntegerConstantOp::create(builderOM, intConstant); |
There was a problem hiding this comment.
Nit: this could invert the check and do an early return for less indentation.
| return IntegerAttr::get(IntegerType::get(getContext(), | ||
| lhsCst->getBitWidth(), | ||
| IntegerType::Signed), | ||
| lhsCst->shl(*rhsCst)); |
Uh oh!
There was an error while loading. Please reload this page.