Skip to content

Commit

Permalink
[mono][jit] Reorganize the creation of the initlocals bblock. (dotnet…
Browse files Browse the repository at this point in the history
…#60804)

This is needed because the gsharedvt init code was emitted into it,
and that code might contain branches in llvmonly mode, so
emit_rgctx_fetch_inline () could not be enabled for it. This
caused gsharedvt methods to always emit a slow jit icall in
the gsharedvt init code.
  • Loading branch information
vargaz committed Oct 25, 2021
1 parent 9e795c0 commit 80f99fb
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2587,8 +2587,7 @@ emit_rgctx_fetch_inline (MonoCompile *cfg, MonoInst *rgctx, MonoJumpInfoRgctxEnt
EMIT_NEW_AOTCONST (cfg, slot_ins, MONO_PATCH_INFO_RGCTX_SLOT_INDEX, entry);

// Can't add basic blocks during decompose/interp entry mode etc.
// Can't add basic blocks to the gsharedvt init block either
if (cfg->after_method_to_ir || entry->info_type == MONO_RGCTX_INFO_METHOD_GSHAREDVT_INFO || cfg->interp_entry_only) {
if (cfg->after_method_to_ir || cfg->interp_entry_only) {
MonoInst *args [2] = { rgctx, slot_ins };
if (entry->in_mrgctx)
call = mono_emit_jit_icall (cfg, mono_fill_method_rgctx, args);
Expand Down Expand Up @@ -6401,14 +6400,6 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
mono_emit_method_call (cfg, wrapper, args, NULL);
}

/* FIRST CODE BLOCK */
NEW_BBLOCK (cfg, tblock);
tblock->cil_code = ip;
cfg->cbb = tblock;
cfg->ip = ip;

ADD_BBLOCK (cfg, tblock);

if (cfg->method == method) {
breakpoint_id = mono_debugger_method_has_breakpoint (method);
if (breakpoint_id) {
Expand All @@ -6417,15 +6408,24 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
}
}

if (cfg->llvm_only && cfg->interp && cfg->method == method) {
if (!cfg->method->wrapper_type && header->num_clauses) {
for (int i = 0; i < header->num_clauses; ++i) {
MonoExceptionClause *clause = &header->clauses [i];
/* Finally clauses are checked after the remove_finally pass */
if (clause->flags != MONO_EXCEPTION_CLAUSE_FINALLY)
cfg->interp_entry_only = TRUE;
}
}
}

/* we use a separate basic block for the initialization code */
NEW_BBLOCK (cfg, init_localsbb);
if (cfg->method == method)
cfg->bb_init = init_localsbb;
init_localsbb->real_offset = cfg->real_offset;
start_bblock->next_bb = init_localsbb;
init_localsbb->next_bb = cfg->cbb;
link_bblock (cfg, start_bblock, init_localsbb);
link_bblock (cfg, init_localsbb, cfg->cbb);
init_localsbb2 = init_localsbb;
cfg->cbb = init_localsbb;

Expand Down Expand Up @@ -6468,8 +6468,28 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
if (init_locals)
ins->flags |= MONO_INST_INIT;
*/
if (cfg->llvm_only) {
init_localsbb = cfg->cbb;
init_localsbb2 = cfg->cbb;
}
}

if (cfg->llvm_only && cfg->interp && cfg->method == method) {
if (cfg->interp_entry_only)
emit_llvmonly_interp_entry (cfg, header);
}

/* FIRST CODE BLOCK */
NEW_BBLOCK (cfg, tblock);
tblock->cil_code = ip;
cfg->cbb = tblock;
cfg->ip = ip;

init_localsbb->next_bb = cfg->cbb;
link_bblock (cfg, init_localsbb, cfg->cbb);

ADD_BBLOCK (cfg, tblock);

CHECK_CFG_EXCEPTION;

if (header->code_size == 0)
Expand Down Expand Up @@ -6521,19 +6541,6 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
}
}

if (cfg->llvm_only && cfg->interp && cfg->method == method) {
if (!cfg->method->wrapper_type && header->num_clauses) {
for (int i = 0; i < header->num_clauses; ++i) {
MonoExceptionClause *clause = &header->clauses [i];
/* Finally clauses are checked after the remove_finally pass */
if (clause->flags != MONO_EXCEPTION_CLAUSE_FINALLY)
cfg->interp_entry_only = TRUE;
}
}
if (cfg->interp_entry_only)
emit_llvmonly_interp_entry (cfg, header);
}

skip_dead_blocks = !dont_verify;
if (skip_dead_blocks) {
original_bb = bb = mono_basic_block_split (method, cfg->error, header);
Expand Down

0 comments on commit 80f99fb

Please sign in to comment.