-
Notifications
You must be signed in to change notification settings - Fork 110
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
[CIR][ThroughMLIR] lowering cir.bit.clz and cir.bit.ctz to MLIR #645
Conversation
matchAndRewrite(mlir::cir::BitCtzOp op, OpAdaptor adaptor, | ||
mlir::ConversionPatternRewriter &rewriter) const override { | ||
auto resultIntTy = | ||
getTypeConverter()->convertType(op.getType()).cast<mlir::IntegerType>(); | ||
auto ctz = rewriter.create<mlir::math::CountTrailingZerosOp>( | ||
op->getLoc(), adaptor.getInput()); | ||
auto newOp = createIntCast(rewriter, ctz->getResult(0), resultIntTy, | ||
/*isSigned=*/false); | ||
rewriter.replaceOp(op, newOp); | ||
return mlir::LogicalResult::success(); | ||
} |
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.
These two matchAndRewrite
functions looks similar. Could you refactor out a common matchAndRewriteBitOp
function to do the common job? You can reuse this function in later PRs when you try to lower other bit operations.
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.
Sounds good, I will do that right away.
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.
LGTM.
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.
Thanks for the review @Lancern
Added one minor nit
@@ -0,0 +1,94 @@ | |||
// RUN: cir-opt %s -cir-to-mlir -o %t.mlir | |||
// RUN: FileCheck %s --input-file %t.mlir |
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.
In your next PRs can you please start writing these from source? You can use -fno-clangir-direct-lowering
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.
Ok, I'll rewrite bit.cir to bit.c
…#645) This pr adds cir.bit.clz and cir.bit.ctz lowering to MLIR passes and test files. I will complete the lowering of other `cir.bit` operations in subsequent PRs.
…#645) This pr adds cir.bit.clz and cir.bit.ctz lowering to MLIR passes and test files. I will complete the lowering of other `cir.bit` operations in subsequent PRs.
…#645) This pr adds cir.bit.clz and cir.bit.ctz lowering to MLIR passes and test files. I will complete the lowering of other `cir.bit` operations in subsequent PRs.
…#645) This pr adds cir.bit.clz and cir.bit.ctz lowering to MLIR passes and test files. I will complete the lowering of other `cir.bit` operations in subsequent PRs.
This pr adds cir.bit.clz and cir.bit.ctz lowering to MLIR passes and test files. I will complete the lowering of other `cir.bit` operations in subsequent PRs.
This pr adds cir.bit.clz and cir.bit.ctz lowering to MLIR passes and test files.
I will complete the lowering of other
cir.bit
operations in subsequent PRs.