Skip to content
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][Lowering] Fixed break/continue lowering for loops #211

Merged
merged 6 commits into from
Aug 9, 2023

Conversation

gitoleg
Copy link
Collaborator

@gitoleg gitoleg commented Aug 4, 2023

This PR fixes lowering for break/continue in loops.
The idea is to replace cir.yield break and cir.yield continue with the branch operations to the corresponding blocks. Note, that we need to ignore nesting loops and don't touch break in switch operations. Also, yield from if need to be considered only when it's not the loop yield and continue in switch is ignored since it's processed in the loops lowering.

Fixes #160

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty cool, thanks for fixing this issue! Added a few comments inline.

@sitio-couto can you also take a look?

Copy link
Collaborator

@sitio-couto sitio-couto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gitoleg great implementation! Thanks.

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp Outdated Show resolved Hide resolved
clang/test/CIR/Lowering/loops-with-break.cir Outdated Show resolved Hide resolved
Copy link
Collaborator

@sitio-couto sitio-couto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gitoleg great! Thanks.

@sitio-couto
Copy link
Collaborator

@gitoleg could you squash the commits in this PR and rebase it on main so that we can land it?

@bcardosolopes
Copy link
Member

@sitio-couto can you try "Squash and merge"? Should do the job!

@sitio-couto sitio-couto merged commit 1ebed61 into llvm:main Aug 9, 2023
lanza pushed a commit that referenced this pull request Oct 27, 2023
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes #160
bcardosolopes pushed a commit that referenced this pull request Dec 8, 2023
This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in #211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes #324
lanza pushed a commit that referenced this pull request Dec 20, 2023
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes #160
lanza pushed a commit that referenced this pull request Dec 20, 2023
This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in #211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes #324
lanza pushed a commit that referenced this pull request Jan 29, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes #160
lanza pushed a commit that referenced this pull request Jan 29, 2024
This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in #211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes #324
lanza pushed a commit that referenced this pull request Mar 23, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes #160
lanza pushed a commit that referenced this pull request Mar 23, 2024
This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in #211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes #324
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes llvm#160
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
)

This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in llvm#211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes llvm#324
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes llvm#160
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
)

This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in llvm#211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes llvm#324
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes #160
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in #211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes #324
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes #160
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in #211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes #324
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes llvm#160
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
)

This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in llvm#211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`. 

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes llvm#324
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes lowering for `break/continue`  in loops.
The idea is to replace `cir.yield break` and `cir.yield continue` with
the branch operations to the corresponding blocks. Note, that we need to
ignore nesting loops and don't touch `break` in switch operations. Also,
`yield` from `if` need to be considered only when it's not the loop
`yield` and `continue` in switch is ignored since it's processed in the
loops lowering.

Fixes #160
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes a couple of corner cases connected with the `YieldOp`
lowering in loops.
Previously, in #211 we introduced `lowerNestedBreakContinue` but we
didn't check that `YieldOp` may belong to the same region, i.e. it is
not nested, e.g.
```
while(1) {
   break;
}
```
Hence the error `op already replaced`.

Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
`scopeOp`, and the same error occurred. This PR fixes this as well.

I added two tests - with no checks actually, just to make sure no more
crashes happen.

fixes #324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lowering of nested break/continue in loops
3 participants