clangir
clangir copied to clipboard
[CIR] Cleanup cir.scopes with a single cir.yield operation
This PR adds an extra condition to the match pattern in the RemoveEmptyScope cleanup pass to consider the case where there is a single operation in the block and that it is YieldOp.
Issue #455
Related to #436
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
You can test this locally with the following command:
git-clang-format --diff b9cd201198ee61b57cfbdfced69c9fe2f3710cf5 a984329e4fcbc220ec681e6ed1b9ee2aad20c487 -- clang/lib/CIR/Dialect/Transforms/MergeCleanups.cpp
View the diff from clang-format here.
diff --git a/clang/lib/CIR/Dialect/Transforms/MergeCleanups.cpp b/clang/lib/CIR/Dialect/Transforms/MergeCleanups.cpp
index b12f4c9f08..42dcb6e965 100644
--- a/clang/lib/CIR/Dialect/Transforms/MergeCleanups.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/MergeCleanups.cpp
@@ -59,10 +59,10 @@ struct RemoveEmptyScope : public OpRewritePattern<ScopeOp> {
LogicalResult match(ScopeOp op) const final {
return success(op.getRegion().empty() ||
- (op.getRegion().getBlocks().size() == 1 &&
- op.getRegion().front().empty()) ||
- (op.getRegion().front().getOperations().size() == 1 &&
- isa<YieldOp>(&op.getRegion().front().front())));
+ (op.getRegion().getBlocks().size() == 1 &&
+ op.getRegion().front().empty()) ||
+ (op.getRegion().front().getOperations().size() == 1 &&
+ isa<YieldOp>(&op.getRegion().front().front())));
}
void rewrite(ScopeOp op, PatternRewriter &rewriter) const final {
Thanks, this also needs a testcase!
Thanks for this comment. Just to clarify, I should add the test case to clangir/tree/main/clang/test/CIR/Transforms/merge-cleanups.cir, right?
Thanks for this comment. Just to clarify, I should add the test case to clangir/tree/main/clang/test/CIR/Transforms/merge-cleanups.cir, right?
That'd be a good place for it
Any plans to continue the work here?
Gonna close this for now in order to keep tracking of only active PRs, feel free to re-open if there are updated.