This is an archive of the discontinued LLVM Phabricator instance.

[mlir][llvm] Allow llvm.resume with non-landingpad input
AbandonedPublic

Authored by victor-eds on Mar 10 2023, 8:52 AM.

Details

Summary

This changes verification of llvm.resume to just fail if there is no
llvm.landingpad instruction in the same function with the same type as
this instruction's input, more in line with LLVM's specification. From
LLVM documentation (https://llvm.org/docs/LangRef.html#i-resume):

The ‘resume’ instruction requires one argument, which must have the same
type as the result of any ‘landingpad’ instruction in the same function.

Signed-off-by: Victor Perez <victor.perez@codeplay.com>

Diff Detail

Event Timeline

victor-eds created this revision.Mar 10 2023, 8:52 AM
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
victor-eds requested review of this revision.Mar 10 2023, 8:52 AM

Looks good to me with some notes:

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
1528

nit: Use Type here instead of const auto

Use Type instead of const auto and use opaque pointers in tests.

victor-eds added a comment.EditedMar 27 2023, 5:00 AM

Yes, I saw that the code differs from the spec. According to the specification of the landingpad instruction:

The ‘landingpad’ instruction defines the values which are set by the personality function upon re-entry to the function, and therefore the “result type” of the landingpad instruction. As with calling conventions, how the personality function results are represented in LLVM IR is target specific.

I'd argue it would make sense to check every llvm.landingpad operation in a function has the same type (not sure if we should check it in llvm.resume's verifier). If you don't mind, I can address that in a different patch to keep this one small and simple and separate concerns.

zero9178 accepted this revision.Mar 27 2023, 5:11 AM
zero9178 added reviewers: gysit, Dinistro.

Yes, I saw that the code differs from the spec. According to the specification of the landingpad instruction:

The ‘landingpad’ instruction defines the values which are set by the personality function upon re-entry to the function, and therefore the “result type” of the landingpad instruction. As with calling conventions, how the personality function results are represented in LLVM IR is target specific.

I'd argue it would make sense to check every llvm.landingpad operation in a function has the same type (not sure if we should check it in llvm.resume's verifier). If you don't mind, I can address that in a different patch to keep this one small and simple and separate concerns.

I think it is fine as is. Making the verifier not have false positives is much more important than catching false negatives.

LGTM, but please wait a day or two for others to check as well. Ading some extra reviewers for visibility as well.

This revision is now accepted and ready to land.Mar 27 2023, 5:11 AM
victor-eds edited the summary of this revision. (Show Details)

Assume all llvm.landingpad operations have the same type.

Yes, I saw that the code differs from the spec. According to the specification of the landingpad instruction:

The ‘landingpad’ instruction defines the values which are set by the personality function upon re-entry to the function, and therefore the “result type” of the landingpad instruction. As with calling conventions, how the personality function results are represented in LLVM IR is target specific.

I'd argue it would make sense to check every llvm.landingpad operation in a function has the same type (not sure if we should check it in llvm.resume's verifier). If you don't mind, I can address that in a different patch to keep this one small and simple and separate concerns.

I think it is fine as is. Making the verifier not have false positives is much more important than catching false negatives.

LGTM, but please wait a day or two for others to check as well. Ading some extra reviewers for visibility as well.

Yes, I'll wait till Wednesday morning (European time) to land. I've modified the code so that we assume all landingpad operations have the same type, as they should.

Allow nested ops

Drop include

victor-eds edited the summary of this revision. (Show Details)

Run tests

gysit added inline comments.Mar 27 2023, 6:08 AM
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
1527

I would probably return failure in this case since this can theoretically happen if the operation is used in some custom function type that does not implement FunctionOpInterface?

1529

If I understand the discussion correctly then we want to test that the type of all landing pad instructions in the function match the type of the resume operand type. Wouldn't that require adding all types to a vector and then checking all of them match? The current code seems to stop after matching the first landingpad op?

Address review comments

gysit accepted this revision.Mar 27 2023, 7:05 AM

Thanks, LGTM!

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
1529

Got it, the assumption is there is another verifier that checks all the types are the same...

1530

nit: let's drop the braces here and in for the if below since the body contains a single statement.

victor-eds edited the summary of this revision. (Show Details)

Add test

victor-eds marked 3 inline comments as done.
victor-eds edited the summary of this revision. (Show Details)

Drop braces

I addressed your comments already

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
1527

I did that and added a test.

1529

If we follow the spec closely, it'd make sense to simply check there is an llvm.landingpad operation in the function with the same type as the input type of the current operation.

As all llvm.landingpad operations should have the same type (according to the LLVM spec and its verifier), it'd be enough to check a single operation here.

I'm working on a patch checking all llvm.landingpad operations have the same type (we could land that one before this one)

gysit added inline comments.Mar 27 2023, 7:20 AM
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
1529

Yes perfect! That's why I accepted the revision :). The "got it" comment was meant as an explanation for my earlier comment. Sorry for the confusion.