Skip to content
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] Make mono_inst_name less misleading #91042

Merged
merged 11 commits into from
Apr 9, 2024
Merged
10 changes: 8 additions & 2 deletions src/mono/mono/mini/alias-analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ lower_load (MonoCompile *cfg, MonoInst *load, MonoInst *ldaddr)
}

if (replaced_op != load->opcode) {
if (cfg->verbose_level > 2)
if (cfg->verbose_level > 2) {
#ifndef DISABLE_LOGGING
printf ("Incompatible load type: expected %s but got %s\n",
steveisok marked this conversation as resolved.
Show resolved Hide resolved
mono_inst_name (replaced_op),
mono_inst_name (load->opcode));
#endif
}
return FALSE;
} else {
if (cfg->verbose_level > 2) { printf ("mem2reg replacing: "); mono_print_ins (load); }
Expand Down Expand Up @@ -84,10 +87,13 @@ lower_store (MonoCompile *cfg, MonoInst *store, MonoInst *ldaddr)


if (replaced_op != store->opcode) {
if (cfg->verbose_level > 2)
if (cfg->verbose_level > 2) {
#ifndef DISABLE_LOGGING
printf ("Incompatible store_reg type: expected %s but got %s\n",
mono_inst_name (replaced_op),
mono_inst_name (store->opcode));
#endif
}
return FALSE;
} else {
if (cfg->verbose_level > 2) { printf ("mem2reg replacing: "); mono_print_ins (store); }
Expand Down
7 changes: 2 additions & 5 deletions src/mono/mono/mini/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,17 @@ static const gint16 opidx [] = {
#endif
//#define ARCH_PREFIX "powerpc64-linux-gnu-"

#ifndef DISABLE_LOGGING
ivanpovazan marked this conversation as resolved.
Show resolved Hide resolved
const char*
mono_inst_name (int op) {
#ifndef DISABLE_LOGGING
if (op >= OP_LOAD && op <= OP_LAST)
return (const char*)&opstr + opidx [op - OP_LOAD];
if (op < OP_LOAD)
return mono_opcode_name (op);
g_error ("unknown opcode name for %d", op);
return NULL;
#else
g_error ("unknown opcode name for %d", op);
g_assert_not_reached ();
#endif
}
#endif

void
mono_blockset_print (MonoCompile *cfg, MonoBitSet *set, const char *name, guint idom)
Expand Down
6 changes: 5 additions & 1 deletion src/mono/mono/mini/mini-amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -7600,13 +7600,17 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
amd64_mov_membase_reg (code, ins->sreg1, MONO_STRUCT_OFFSET (MonoContext, gregs) + i * sizeof (target_mgreg_t), i, sizeof (target_mgreg_t));
break;
default:
#ifndef DISABLE_LOGGING
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
#endif
g_assert_not_reached ();
}


#ifndef DISABLE_LOGGING
g_assertf ((code - cfg->native_code - offset) <= max_len,
"wrong maximal instruction length of instruction %s (expected %d, got %d)",
mono_inst_name (ins->opcode), max_len, (int)(code - cfg->native_code - offset));
#endif
akoeplinger marked this conversation as resolved.
Show resolved Hide resolved
}

set_code_cursor (cfg, code);
Expand Down
6 changes: 6 additions & 0 deletions src/mono/mono/mini/mini-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -3493,7 +3493,9 @@ opcode_to_armcond (int opcode)
case OP_COND_EXC_INO:
return ARMCOND_VC;
default:
#ifndef DISABLE_LOGGING
printf ("%s\n", mono_inst_name (opcode));
#endif
g_assert_not_reached ();
return -1;
}
Expand Down Expand Up @@ -5533,14 +5535,18 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
break;

default:
#ifndef DISABLE_LOGGING
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
#endif
g_assert_not_reached ();
}

after_instruction_emit:
if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
#ifndef DISABLE_LOGGING
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
#endif
g_assert_not_reached ();

}
Expand Down
31 changes: 26 additions & 5 deletions src/mono/mono/mini/mini-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,16 @@ mono_print_ins_index_strbuf (int i, MonoInst *ins)
int sregs [MONO_MAX_SRC_REGS];
char spec_dest = (char)0, spec_src1 = (char)0, spec_src2 = (char)0, spec_src3 = (char)0;

if (i != -1)
if (i != -1) {
#ifndef DISABLE_LOGGING
g_string_append_printf (sbuf, "\t%-2d %s", i, mono_inst_name (ins->opcode));
else
#endif
}
else {
#ifndef DISABLE_LOGGING
g_string_append_printf (sbuf, " %s", mono_inst_name (ins->opcode));
#endif
}
if (spec == (gpointer)MONO_ARCH_CPU_SPEC) {
/* This is a lowered opcode */
if (ins->dreg != -1) {
Expand Down Expand Up @@ -1153,12 +1159,21 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
spec = ins_get_spec (i);
ispec = INS_INFO (i);

if ((spec [MONO_INST_DEST] && (ispec [MONO_INST_DEST] == ' ')))
if ((spec [MONO_INST_DEST] && (ispec [MONO_INST_DEST] == ' '))) {
#ifndef DISABLE_LOGGING
g_error ("Instruction metadata for %s inconsistent.\n", mono_inst_name (i));
if ((spec [MONO_INST_SRC1] && (ispec [MONO_INST_SRC1] == ' ')))
#endif
}
if ((spec [MONO_INST_SRC1] && (ispec [MONO_INST_SRC1] == ' '))) {
#ifndef DISABLE_LOGGING
g_error ("Instruction metadata for %s inconsistent.\n", mono_inst_name (i));
if ((spec [MONO_INST_SRC2] && (ispec [MONO_INST_SRC2] == ' ')))
#endif
}
if ((spec [MONO_INST_SRC2] && (ispec [MONO_INST_SRC2] == ' '))) {
#ifndef DISABLE_LOGGING
g_error ("Instruction metadata for %s inconsistent.\n", mono_inst_name (i));
#endif
}
}
#endif
}
Expand Down Expand Up @@ -1243,7 +1258,9 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
spec_dest = spec [MONO_INST_DEST];

if (G_UNLIKELY (spec == (gpointer)/*FIXME*/MONO_ARCH_CPU_SPEC)) {
#ifndef DISABLE_LOGGING
g_error ("Opcode '%s' missing from machine description file.", mono_inst_name (ins->opcode));
#endif
steveisok marked this conversation as resolved.
Show resolved Hide resolved
}

DEBUG (mono_print_ins_index (i, ins));
Expand Down Expand Up @@ -2286,7 +2303,9 @@ mono_opcode_to_cond (int opcode)
case OP_CMOV_LGT_UN:
return CMP_GT_UN;
default:
#ifndef DISABLE_LOGGING
printf ("%s\n", mono_inst_name (opcode));
#endif
g_assert_not_reached ();
return (CompRelation)0;
}
Expand Down Expand Up @@ -2349,7 +2368,9 @@ mono_opcode_to_type (int opcode, int cmp_opcode)
return CMP_TYPE_L;
}
} else {
#ifndef DISABLE_LOGGING
g_error ("Unknown opcode '%s' in opcode_to_type", mono_inst_name (opcode));
#endif
return (CompType)0;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ mono_decompose_op_imm (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins)
mono_bblock_insert_before_ins (bb, ins, temp);

if (opcode2 == -1)
#ifndef DISABLE_LOGGING
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
steveisok marked this conversation as resolved.
Show resolved Hide resolved
#endif
ins->opcode = GINT_TO_OPCODE (opcode2);

if (ins->opcode == OP_LOCALLOC)
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,9 @@ GString *mono_print_ins_index_strbuf (int i, MonoInst *ins);
void mono_print_ins (MonoInst *ins);
void mono_print_bb (MonoBasicBlock *bb, const char *msg);
void mono_print_code (MonoCompile *cfg, const char *msg);
#ifndef DISABLE_LOGGING
const char* mono_inst_name (int op);
#endif
int mono_op_to_op_imm (int opcode);
int mono_op_imm_to_op (int opcode);
int mono_load_membase_to_load_mem (int opcode);
Expand Down