-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add arithmetic shift operation #68
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
8d6ea7c
to
b4c67f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
lib/Dialect/P4HIR/P4HIR_Ops.cpp
Outdated
"equal the width of the left-hand side operand"; | ||
} | ||
|
||
if (::mlir::isa<P4HIR::BitsType>(rhsType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified to:
if (auto rhsBits = mlir::dyn_cast<P4HIR::BitsType>(rhsType)) {
if (rhsBits.isSigned())
return op->emitOpError()
<< "the right-hand side operand of an arithmetic shift must be unsigned";
}
Same in other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
tools/p4mlir-translate/translate.cpp
Outdated
@@ -598,6 +604,16 @@ mlir::Value P4HIRConverter::emitConcatOp(const P4::IR::Concat *concatop) { | |||
getValue(concatop->right)); | |||
} | |||
|
|||
mlir::Value P4HIRConverter::emitShlOp(const P4::IR::Shl *op) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think we need separate methods for this (at least here, in translator), just emit shift ops in postorder
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
lib/Dialect/P4HIR/P4HIR_Ops.cpp
Outdated
"constant; width of left operand of shift needs to be specified or both " | ||
"operands need to be constant"; | ||
|
||
if (!::mlir::isa<P4HIR::InfIntType>(resultType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can start with the check that resultType
equals to lhsType
. This is a common invariant, so it could be hoisted out of conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. I think TypesMatchWith
trait will make this check obsolete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
let results = (outs AnyIntP4Type:$result); | ||
let arguments = (ins AnyIntP4Type:$lhs, AnyIntP4Type:$rhs); | ||
|
||
// Custom builder to infer the result type with the proper width |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the comment was just copied from concat
and does not make sense here. Also, I think you can use TypesMatchWith
to match result type with lhs type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
… result type. Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
… pull request. Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
… pull request. Get rid of separate emitSh(l/r)Op functions. Signed-off-by: Vladimir Shiryaev <w@tagolog.com>
Signed-off-by: Vladimir Shiryaev w@tagolog.com