-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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] RuntimeHelpers.CreateSpan<T> is now intrinsic. #81695
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
789a6f7
[mono] RuntimeHelpers.CreateSpan is now intrinsic.
jandupej b76e424
[mono][jit] RuntimeHelpers.CreateSpan intrinsic fixes.
jandupej 5c23aa3
[mono][jit] RuntimeHelpers.CreateSpan is intrinsic and seems to work.
jandupej ff717ca
[mono] Fixed a warning that broke build.
jandupej 14dba0f
[mono] Pointer arithmetic warnings hopefully solved.
jandupej 9882de0
[mono] Fix pointer conversion warning, take 2.
jandupej aad9e93
[mono] RuntimeHelpers.CreateSpan<T> is no longer intrinsic under AOT.
jandupej 1174cb5
[mono] RuntimeHelpers.CreateSpan<T> now constructs the result in a sa…
jandupej e831cdb
[mono][aot] RuntimeHelpers.CreateSpan<T> intrinsic fixed for AOT case.
jandupej fe79643
[mono] Cleaned up whitespace changes in decompose.c, YAGNI in ir-emit.h.
jandupej c55bbdf
[mono] OP_LDTOKEN_FIELD mini opcode introduced for RuntimeHelpers.Cre…
jandupej 619cba6
[mono][aot] RuntimeHelpers.CreateSpan<T> intrinsic now emits the corr…
jandupej 0e03cf0
[mono] RuntimeHelpers.CreateSpan intrinsic, removed superfluous sanit…
jandupej 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 |
---|---|---|
|
@@ -1008,6 +1008,49 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign | |
EMIT_NEW_UNALU (cfg, ins, OP_ICGT, dreg, -1); | ||
ins->type = STACK_I4; | ||
return ins; | ||
} else if (!strcmp (cmethod->name, "CreateSpan") && fsig->param_count == 1) { | ||
MonoGenericContext* ctx = mono_method_get_context (cmethod); | ||
g_assert (ctx); | ||
g_assert (ctx->method_inst); | ||
g_assert (ctx->method_inst->type_argc == 1); | ||
MonoType* arg_type = ctx->method_inst->type_argv [0]; | ||
MonoType* t = mini_get_underlying_type (arg_type); | ||
g_assert (!MONO_TYPE_IS_REFERENCE (t) && t->type != MONO_TYPE_VALUETYPE); | ||
|
||
// This OP_LDTOKEN_FIELD later changes into a OP_VMOVE. | ||
MonoClassField* field = (MonoClassField*) args [0]->inst_p1; | ||
if (args [0]->opcode != OP_LDTOKEN_FIELD) | ||
return NULL; | ||
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. The !field etc. checks should not be needed any more. |
||
|
||
int alignment = 0; | ||
const int element_size = mono_type_size (t, &alignment); | ||
const int num_elements = mono_type_size (field->type, &alignment) / element_size; | ||
const int obj_size = MONO_ABI_SIZEOF (MonoObject); | ||
|
||
MonoInst* span = mono_compile_create_var (cfg, fsig->ret, OP_LOCAL); | ||
MonoInst* span_addr; | ||
EMIT_NEW_TEMPLOADA (cfg, span_addr, span->inst_c0); | ||
|
||
MonoInst* ptr_inst; | ||
if (cfg->compile_aot) { | ||
NEW_RVACONST (cfg, ptr_inst, mono_class_get_image (mono_field_get_parent (field)), args [0]->inst_c0); | ||
MONO_ADD_INS (cfg->cbb, ptr_inst); | ||
} else { | ||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN | ||
const int swizzle = 1; | ||
#else | ||
const int swizzle = element_size; | ||
#endif | ||
gpointer data_ptr = (gpointer)mono_field_get_rva (field, swizzle); | ||
EMIT_NEW_PCONST (cfg, ptr_inst, data_ptr); | ||
} | ||
|
||
MonoClassField* field_ref = mono_class_get_field_from_name_full (span->klass, "_reference", NULL); | ||
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STOREP_MEMBASE_REG, span_addr->dreg, field_ref->offset - obj_size, ptr_inst->dreg); | ||
MonoClassField* field_len = mono_class_get_field_from_name_full (span->klass, "_length", NULL); | ||
MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI4_MEMBASE_IMM, span_addr->dreg, field_len->offset - obj_size, num_elements); | ||
EMIT_NEW_TEMPLOAD (cfg, ins, span->inst_c0); | ||
return ins; | ||
} else | ||
return NULL; | ||
} else if (cmethod->klass == mono_class_try_get_memory_marshal_class ()) { | ||
|
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 | ||
---|---|---|---|---|
|
@@ -10820,9 +10820,16 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b | |||
} else { | ||||
EMIT_NEW_PCONST (cfg, ins, handle); | ||||
} | ||||
|
||||
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.
Suggested change
|
||||
EMIT_NEW_TEMPLOADA (cfg, addr, vtvar->inst_c0); | ||||
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, addr->dreg, 0, ins->dreg); | ||||
EMIT_NEW_TEMPLOAD (cfg, ins, vtvar->inst_c0); | ||||
ins->opcode = OP_LDTOKEN_FIELD; | ||||
ins->inst_c0 = n; | ||||
ins->inst_p1 = handle; | ||||
|
||||
cfg->flags |= MONO_CFG_NEEDS_DECOMPOSE; | ||||
cfg->cbb->needs_decompose = TRUE; | ||||
} | ||||
} | ||||
|
||||
|
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
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.
This looks a little brittle, it depends on OP_VMOVE never having its inst_p1 set otherwise.
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.
I guess I could also use
backend
; the comments there do not indicate that the field is used with OP_VMOVE. Another way would be to do what you suggested earlier - emit a new opcode that would carry it ininst_p1
and then decompose it away. I had some issues getting that approach to work, so I tried this. It seems to work, although I cannot honestly verify that itsinst_p1
is always untouched. Wouldn't that also be the case for the new opcode?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.
Using a new opcode would mean that this code could be sure that the input comes from the CEE_LDTOKEN code. The downside is that new opcode needs to be decomposed/lowered if its not followed by CreateSpan etc.
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.
So now a
OP_LDTOKEN_FIELD
is emitted, which is equivalent in every way to aOP_VMOVE
, except its opcode. This should protect theMonoInst
contents until it is used byCreateSpan
intrinsic. The decomposition ofOP_LDTOKEN_FIELD
is then only rewriting the opcode toOP_VMOVE
.