-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[mono] Add SwiftError support for Swift reverse pinvokes #101122
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94ae2a4
initialized swift reverse pinvokes for mini jit arm64
jkurdek 8f8a71a
added comments
jkurdek 74c708a
Merge branch 'main' into swift-reverse-pinvokes
jkurdek 97003cd
fixed reverse pinvokes error passing on arm64
jkurdek 1ba2a83
implemented swift reverse pinvoke error passing on amd64
jkurdek 32455a4
disable SwiftErrorHandling tests on mono interpreter for now
jkurdek 6e7620d
add comments
jkurdek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2887,7 +2887,12 @@ mono_arch_allocate_vars (MonoCompile *cfg) | |
offset += size; | ||
|
||
cfg->arch.swift_error_var = ins; | ||
cfg->used_int_regs |= 1 << ARMREG_R21; | ||
|
||
/* In the n2m case, the error register functions as an extra return register | ||
* and is thus is not treated as callee-saved. | ||
*/ | ||
if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) | ||
cfg->used_int_regs |= 1 << ARMREG_R21; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be helpful to explain here that in the NATIVE_TO_MANAGED case, the error register is functioning as an extra return register, and thus isn't treated as callee-save. |
||
break; | ||
} | ||
default: | ||
|
@@ -3731,8 +3736,13 @@ emit_move_return_value (MonoCompile *cfg, guint8 * code, MonoInst *ins) | |
MonoCallInst *call; | ||
|
||
if (cfg->arch.swift_error_var) { | ||
code = emit_ldrx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
code = emit_strx (code, ARMREG_R21, ARMREG_IP0, 0); | ||
if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) { | ||
code = emit_ldrx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
code = emit_strx (code, ARMREG_R21, ARMREG_IP0, 0); | ||
} else if (cfg->method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) { | ||
/* Load the value of SwiftError into R21 */ | ||
code = emit_ldrx (code, ARMREG_R21, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
} | ||
} | ||
|
||
call = (MonoCallInst*)ins; | ||
|
@@ -5937,11 +5947,17 @@ emit_move_args (MonoCompile *cfg, guint8 *code) | |
code = emit_strfpq (code, ainfo->reg, ins->inst_basereg, GTMREG_TO_INT (ins->inst_offset)); | ||
break; | ||
case ArgSwiftError: | ||
if (ainfo->offset) { | ||
code = emit_ldrx (code, ARMREG_IP0, cfg->arch.args_reg, ainfo->offset); | ||
code = emit_strx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
} else { | ||
code = emit_strx (code, ainfo->reg, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
if (cfg->method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE) { | ||
if (ainfo->offset) { | ||
code = emit_ldrx (code, ARMREG_IP0, cfg->arch.args_reg, ainfo->offset); | ||
code = emit_strx (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
} else { | ||
code = emit_strx (code, ainfo->reg, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
} | ||
} else if (cfg->method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) { | ||
arm_addx_imm (code, ARMREG_IP0, cfg->arch.swift_error_var->inst_basereg, GTMREG_TO_INT (cfg->arch.swift_error_var->inst_offset)); | ||
/* Relies on arguments being passed on the stack */ | ||
code = emit_strx (code, ARMREG_IP0, ins->inst_basereg, GTMREG_TO_INT (ins->inst_offset)); | ||
} | ||
break; | ||
default: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why it doesn't include the
ARGS_OFFSET
offset between fp and the first argument in the callee?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.
ainfo->offset
was always 0 here. So it was always allocated at ARGS_OFFSET from the beginning. I think thatoffset
already includes information about the distance.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.
The Swift types are specified either at the beginning or the end of signature. We don't enforce strict signature rules, but it would be beneficial to make them more general if possible. Can it still function if
SwiftError
is specified as the last argument, usingainfo->offset
instead ofoffset
?@amanasifkhalid, what are the limitations from the CoreCLR side?
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.
We don't enforce any signature rules, either. The Swift special register types can appear anywhere in the signature's parameter list.
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.
@kotlarmilos i think for that to work with ainfo->offset without any modifications, the error would have to be the first argument. We could probably update ainfo->offset in get_call_info so that it works for every position. I'm not sure what are the benefits of using ainfo->offset though, as the current solution works for every position.
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.
Ok, sounds good. I forgot that the
ainfo->offset
is always 0 forswifterror
in theget_call_info
.