Skip to content

Conversation

tommymcm
Copy link
Collaborator

cir::BreakOp::getBreakTarget gets the innermost cir::LoopOpInterface or cir::SwitchOp containing this break.

For example:

A: for (...) {
B:   for(...) {
       break; // target = B
C:     switch (...) {
         default: break; // target = C
       }
     break; // target = A
   }     

NOTE: This is a part of a broader effort I am working on to make querying CIR control flow facts more easily. If folks have any design notes or ideas, please share them.

Copy link
Collaborator

@xlauko xlauko left a comment

Choose a reason for hiding this comment

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

Eventually we should transfer to multiple-entry, multiple-exit regions, which gives this functionality directly. Though it is unclear when they will be upstreamed.

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.

LGTM after pending comment

@bcardosolopes bcardosolopes merged commit 7aa4f74 into llvm:main Sep 5, 2025
6 of 9 checks passed
tommymcm added a commit to tommymcm/clangir that referenced this pull request Sep 5, 2025
`cir::BreakOp::getBreakTarget` gets the innermost `cir::LoopOpInterface`
or `cir::SwitchOp` containing this `break`.

For example:
```
A: for (...) {
B:   for(...) {
       break; // target = B
C:     switch (...) {
         default: break; // target = C
       }
     break; // target = A
   }     
```

NOTE: This is a part of a broader effort I am working on to make
querying CIR control flow facts more easily. If folks have any design
notes or ideas, please share them.

---------

Co-authored-by: Tommy McMichen <tommymcmichen@fb.com>
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.

4 participants