-
Notifications
You must be signed in to change notification settings - Fork 127
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] introduce cir.unreachable operation #447
Conversation
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.
This is awesome. Since you're adding support for this, let's make it complete while you're here, see other mentions in:
clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp:760
clang/lib/CIR/CodeGen/CIRGenFunction.cpp:589
- Add CIRGen for
__builtin_unreachable
, which should map into this operation.
Added. The codegen slightly diverges from upstream clang. The problem one needs to resolve when emitting calls to void test() {
__builtin_unreachable();
// How should we deal with the following code?
do_some_thing_that_may_never_happen();
} We cannot continue emitting code after In upstream Clang, the codegen of statements are allowed to erase the current insertion point. Thus, after emitting the full statement that contains a call to However, in CIRGen, there are already too many assumptions in the code that the insertion point is always present. So we can't erase the dangling block until the function CIRGen is fully complete. In this PR, the removal of the dangling block is not implemented. I believe we should invent a DCE pass in the future to remove these dangling blocks (I guess there is already one in MLIR).
Updated.
This place handles control flows that implicitly returns from a function with a non- |
That's right!
We take a different approach here. Upstream codegen relies too much on insertion point availability in order to take decisions, and although it works, it feels hacky because you are not really aware at any given point, why is it that an insertion point isn't available - is it because of a bug? is it because it's trying to signal something? if so, signal what? Overall I find it very hard to rely. It's also becomes a bit cumbersome when dealing with structured control flow in CIRGen. So I took the opposite direction: insert guard as much as possible so that we should assume at any point that we have BB to insert operations.
This is expected, we want dangling blocks to be around because in the future we want to emit "unreachable" warnings in Clang using CIR. This is an early optimization that upstream does, which we don't want in ClangIR. Some later cleanup pass should remove it before LLVM lowering, but CIRGen should emit them normally.
Yes, or alternatively apply it in MergeCleanups, whatever that pass is in the future, it should run after LoweringPrepare.
Very nice, thanks for updating the testcase too.
Fair, totally a "follow up PR" material. Let me track this in a new issue. As a last request for this PR, can you then change the comment in |
Updated. Also rebased onto the latest |
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.
Awesome, LGTM
In #426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](#426 (comment)). This PR adds it.
In llvm#426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](llvm#426 (comment)). This PR adds it.
In #426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](#426 (comment)). This PR adds it.
In #426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](#426 (comment)). This PR adds it.
In llvm#426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](llvm#426 (comment)). This PR adds it.
In #426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](#426 (comment)). This PR adds it.
In llvm#426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](llvm#426 (comment)). This PR adds it.
In llvm#426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](llvm#426 (comment)). This PR adds it.
In llvm#426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](llvm#426 (comment)). This PR adds it.
In #426 we confirmed that CIR needs a `cir.unreachable` operation to mark unreachable program points [(discussion)](#426 (comment)). This PR adds it.
In #426 we confirmed that CIR needs a
cir.unreachable
operation to mark unreachable program points (discussion). This PR adds it.