clangir icon indicating copy to clipboard operation
clangir copied to clipboard

[CIR] Cleanup cir.scopes with a single cir.yield operation

Open hardshah opened this issue 1 year ago • 5 comments

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

hardshah avatar Feb 24 '24 00:02 hardshah

: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 {

github-actions[bot] avatar Feb 24 '24 00:02 github-actions[bot]

Thanks, this also needs a testcase!

bcardosolopes avatar Feb 24 '24 01:02 bcardosolopes

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?

hardshah avatar Feb 24 '24 01:02 hardshah

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

bcardosolopes avatar Feb 24 '24 02:02 bcardosolopes

Any plans to continue the work here?

bcardosolopes avatar Apr 17 '24 20:04 bcardosolopes

Gonna close this for now in order to keep tracking of only active PRs, feel free to re-open if there are updated.

bcardosolopes avatar Jun 20 '24 21:06 bcardosolopes