Skip to content

Commit

Permalink
[mono][interp] Don't compute native offset estimate during super ins …
Browse files Browse the repository at this point in the history
…pass

We generate superins without caring if the branch is long or short since the superinstructions use a long offset now.
  • Loading branch information
BrzVlad committed Jul 23, 2024
1 parent 95b3ab7 commit 189a250
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
8 changes: 2 additions & 6 deletions src/mono/mono/mini/interp/transform-opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3387,15 +3387,12 @@ can_propagate_var_def (TransformData *td, int var, InterpLivenessPosition cur_li
static void
interp_super_instructions (TransformData *td)
{
interp_compute_native_offset_estimates (td, FALSE);

// Add some actual super instructions
for (int bb_dfs_index = 0; bb_dfs_index < td->bblocks_count_eh; bb_dfs_index++) {
InterpBasicBlock *bb = td->bblocks [bb_dfs_index];

// Set cbb since we do some instruction inserting below
td->cbb = bb;
int noe = bb->native_offset_estimate;
InterpLivenessPosition current_liveness;
current_liveness.bb_dfs_index = bb->dfs_index;
current_liveness.ins_index = 0;
Expand Down Expand Up @@ -3720,7 +3717,7 @@ interp_super_instructions (TransformData *td)
interp_clear_ins (def);
td->var_values [obj_sreg].ref_count--;
}
} else if (MINT_IS_BINOP_CONDITIONAL_BRANCH (opcode) && interp_is_short_offset (noe, ins->info.target_bb->native_offset_estimate)) {
} else if (MINT_IS_BINOP_CONDITIONAL_BRANCH (opcode)) {
gint32 imm;
int imm_mt;
int sreg_imm = ins->sregs [1];
Expand Down Expand Up @@ -3757,7 +3754,7 @@ interp_super_instructions (TransformData *td)
}
}
}
} else if (MINT_IS_UNOP_CONDITIONAL_BRANCH (opcode) && interp_is_short_offset (noe, ins->info.target_bb->native_offset_estimate)) {
} else if (MINT_IS_UNOP_CONDITIONAL_BRANCH (opcode)) {
if (opcode == MINT_BRFALSE_I4 || opcode == MINT_BRTRUE_I4) {
gboolean negate = opcode == MINT_BRFALSE_I4;
int cond_sreg = ins->sregs [0];
Expand Down Expand Up @@ -3867,7 +3864,6 @@ interp_super_instructions (TransformData *td)
}
}
}
noe += interp_get_ins_length (ins);
}
}
}
Expand Down
25 changes: 3 additions & 22 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -8751,18 +8751,14 @@ interp_foreach_ins_var (TransformData *td, InterpInst *ins, gpointer data, void
}

int
interp_compute_native_offset_estimates (TransformData *td, gboolean final_code)
interp_compute_native_offset_estimates (TransformData *td)
{
InterpBasicBlock *bb;
int noe = 0;

for (bb = td->entry_bb; bb != NULL; bb = bb->next_bb) {
InterpInst *ins;
// FIXME This doesn't currently hold because of bblock reordering potentially
// inserting additional instructions after the estimate is computed.
//
// if (bb->native_offset_estimate)
// g_assert (bb->native_offset_estimate >= noe);

bb->native_offset_estimate = noe;
if (!td->optimized && bb->patchpoint_bb)
noe += 2;
Expand All @@ -8782,19 +8778,6 @@ interp_compute_native_offset_estimates (TransformData *td, gboolean final_code)
continue;
noe += interp_get_ins_length (ins);

if (!final_code && td->optimized &&
(ins->flags & INTERP_INST_FLAG_CALL) &&
ins->info.call_info &&
ins->info.call_info->call_args) {
// When code is optimized, for a call, the offset allocator
// might end up inserting additional moves for the arguments
int *call_args = ins->info.call_info->call_args;
while (*call_args != -1) {
noe += 4; // mono_interp_oplen [MINT_MOV_VT];
call_args++;
}
}

if (!td->optimized)
interp_foreach_ins_var (td, ins, NULL, alloc_unopt_global_local);
}
Expand Down Expand Up @@ -9228,9 +9211,7 @@ generate_compacted_code (InterpMethod *rtm, TransformData *td)
td->relocs = g_ptr_array_new ();
InterpBasicBlock *bb;

// This iteration could be avoided at the cost of less precise size result, following
// super instruction pass
size = interp_compute_native_offset_estimates (td, TRUE);
size = interp_compute_native_offset_estimates (td);

// Generate the compacted stream of instructions
td->new_code = ip = (guint16*)imethod_alloc0 (td, size * sizeof (guint16));
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/interp/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void
interp_link_bblocks (TransformData *td, InterpBasicBlock *from, InterpBasicBlock *to);

int
interp_compute_native_offset_estimates (TransformData *td, gboolean final_code);
interp_compute_native_offset_estimates (TransformData *td);

void
interp_optimize_code (TransformData *td);
Expand Down

0 comments on commit 189a250

Please sign in to comment.