Skip to content

Commit

Permalink
[mono] Make mono_inst_name less misleading (dotnet#91042)
Browse files Browse the repository at this point in the history
Fixes dotnet#83545

Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
Co-authored-by: Steve Pfister <stpfiste@microsoft.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
  • Loading branch information
4 people authored and matouskozak committed Apr 30, 2024
1 parent 2c3e38b commit bc0b090
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 43 deletions.
10 changes: 6 additions & 4 deletions src/mono/mono/mini/alias-analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ lower_load (MonoCompile *cfg, MonoInst *load, MonoInst *ldaddr)
}

if (replaced_op != load->opcode) {
if (cfg->verbose_level > 2)
printf ("Incompatible load type: expected %s but got %s\n",
if (cfg->verbose_level > 2) {
printf ("Incompatible load type: expected " M_PRI_INST " but got " M_PRI_INST "\n",
mono_inst_name (replaced_op),
mono_inst_name (load->opcode));
}
return FALSE;
} else {
if (cfg->verbose_level > 2) { printf ("mem2reg replacing: "); mono_print_ins (load); }
Expand Down Expand Up @@ -84,10 +85,11 @@ lower_store (MonoCompile *cfg, MonoInst *store, MonoInst *ldaddr)


if (replaced_op != store->opcode) {
if (cfg->verbose_level > 2)
printf ("Incompatible store_reg type: expected %s but got %s\n",
if (cfg->verbose_level > 2) {
printf ("Incompatible store_reg type: expected " M_PRI_INST " but got " M_PRI_INST "\n",
mono_inst_name (replaced_op),
mono_inst_name (store->opcode));
}
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
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
4 changes: 2 additions & 2 deletions src/mono/mono/mini/mini-amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -7770,12 +7770,12 @@ 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:
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_assert_not_reached ();
}

g_assertf ((code - cfg->native_code - offset) <= max_len,
"wrong maximal instruction length of instruction %s (expected %d, got %d)",
"wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %d)",
mono_inst_name (ins->opcode), max_len, (int)(code - cfg->native_code - offset));
}

Expand Down
8 changes: 4 additions & 4 deletions src/mono/mono/mini/mini-arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3439,7 +3439,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
temp->dreg = mono_alloc_ireg (cfg);
ins->sreg2 = temp->dreg;
if (opcode2 == -1)
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
g_error ("mono_op_imm_to_op failed for " M_PRI_INST "\n", mono_inst_name (ins->opcode));
ins->opcode = GUINT32_TO_OPCODE (opcode2);
}
if (ins->opcode == OP_SBB || ins->opcode == OP_ISBB || ins->opcode == OP_SUBCC)
Expand Down Expand Up @@ -3497,7 +3497,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
temp->dreg = mono_alloc_ireg (cfg);
ins->sreg2 = temp->dreg;
if (opcode2 == -1)
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
g_error ("mono_op_imm_to_op failed for " M_PRI_INST "\n", mono_inst_name (ins->opcode));
ins->opcode = GINT32_TO_UINT16 (opcode2);
break;
}
Expand Down Expand Up @@ -5957,12 +5957,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
ARM_STR_IMM (code, i, ins->sreg1, MONO_STRUCT_OFFSET (MonoContext, regs) + i * sizeof (target_mgreg_t));
break;
default:
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_assert_not_reached ();
}

if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %d)",
mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
g_assert_not_reached ();
}
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/mini/mini-arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,7 @@ opcode_to_armcond (int opcode)
case OP_COND_EXC_INO:
return ARMCOND_VC;
default:
printf ("%s\n", mono_inst_name (opcode));
printf ("" M_PRI_INST "\n", mono_inst_name (opcode));
g_assert_not_reached ();
return -1;
}
Expand Down Expand Up @@ -5801,13 +5801,13 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
break;

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

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

Expand Down
16 changes: 8 additions & 8 deletions src/mono/mono/mini/mini-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ mono_print_ins_index_strbuf (int i, MonoInst *ins)
char spec_dest = (char)0, spec_src1 = (char)0, spec_src2 = (char)0, spec_src3 = (char)0;

if (i != -1)
g_string_append_printf (sbuf, "\t%-2d %s", i, mono_inst_name (ins->opcode));
g_string_append_printf (sbuf, "\t%-2d " M_PRI_INST "", i, mono_inst_name (ins->opcode));
else
g_string_append_printf (sbuf, " %s", mono_inst_name (ins->opcode));
g_string_append_printf (sbuf, " " M_PRI_INST "", mono_inst_name (ins->opcode));
if (spec == (gpointer)MONO_ARCH_CPU_SPEC) {
/* This is a lowered opcode */
if (ins->dreg != -1) {
Expand Down Expand Up @@ -1160,11 +1160,11 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
ispec = INS_INFO (i);

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

if (G_UNLIKELY (spec == (gpointer)/*FIXME*/MONO_ARCH_CPU_SPEC)) {
g_error ("Opcode '%s' missing from machine description file.", mono_inst_name (ins->opcode));
g_error ("Opcode '" M_PRI_INST "' missing from machine description file.", mono_inst_name (ins->opcode));
}

DEBUG (mono_print_ins_index (i, ins));
Expand Down Expand Up @@ -2303,7 +2303,7 @@ mono_opcode_to_cond (int opcode)
CompRelation rel = mono_opcode_to_cond_unchecked (opcode);

if (rel == (CompRelation)-1) {
printf ("%s\n", mono_inst_name (opcode));
printf ("" M_PRI_INST "\n", mono_inst_name (opcode));
g_assert_not_reached ();
return (CompRelation)0;
}
Expand Down Expand Up @@ -2367,7 +2367,7 @@ mono_opcode_to_type (int opcode, int cmp_opcode)
return CMP_TYPE_L;
}
} else {
g_error ("Unknown opcode '%s' in opcode_to_type", mono_inst_name (opcode));
g_error ("Unknown opcode '" M_PRI_INST "' in opcode_to_type", mono_inst_name (opcode));
return (CompType)0;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/mini/mini-llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ op_to_llvm_type (int opcode)
case OP_LMUL_OVF_UN:
return LLVMInt64Type ();
default:
printf ("%s\n", mono_inst_name (opcode));
printf ("" M_PRI_INST "\n", mono_inst_name (opcode));
g_assert_not_reached ();
return NULL;
}
Expand Down Expand Up @@ -12445,12 +12445,12 @@ MONO_RESTORE_WARNING
case OP_LOAD_GOTADDR: {
char reason [128];

sprintf (reason, "opcode %s", mono_inst_name (ins->opcode));
sprintf (reason, "opcode " M_PRI_INST "", mono_inst_name (ins->opcode));
set_failure (ctx, reason);
break;
}
default:
g_error ("opcode %d %s", ins->opcode, mono_inst_name (ins->opcode));
g_error ("opcode %d " M_PRI_INST "", ins->opcode, mono_inst_name (ins->opcode));
break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/mono/mono/mini/mini-ppc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,7 @@ map_to_reg_reg_op (int op)
return OP_STOREI8_MEMBASE_REG;
}
if (mono_op_imm_to_op (op) == -1)
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (op));
g_error ("mono_op_imm_to_op failed for " M_PRI_INST "\n", mono_inst_name (op));
return mono_op_imm_to_op (op);
}

Expand Down Expand Up @@ -4734,12 +4734,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
break;
}
default:
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_assert_not_reached ();
}

if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %ld)",
mono_inst_name (ins->opcode), max_len, (glong)(code - cfg->native_code - offset));
g_assert_not_reached ();
}
Expand Down
10 changes: 5 additions & 5 deletions src/mono/mono/mini/mini-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
NULLIFY_INS (ins);
break;
default:
g_print ("Can't decompose the OP %s\n", mono_inst_name (ins->opcode));
g_print ("Can't decompose the OP " M_PRI_INST "\n", mono_inst_name (ins->opcode));
NOT_IMPLEMENTED;
}
}
Expand Down Expand Up @@ -2801,7 +2801,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
next_ins->sreg2 = RISCV_ZERO;
} else {
if (cfg->verbose_level > 1) {
g_print ("Unhandaled op %s following after OP_RCOMPARE\n", mono_inst_name (next_ins->opcode));
g_print ("Unhandaled op " M_PRI_INST " following after OP_RCOMPARE\n", mono_inst_name (next_ins->opcode));
}
NULLIFY_INS (ins);
}
Expand Down Expand Up @@ -2885,7 +2885,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
next_ins->sreg2 = RISCV_ZERO;
} else {
if (cfg->verbose_level > 1) {
g_print ("Unhandaled op %s following after OP_FCOMPARE\n", mono_inst_name (next_ins->opcode));
g_print ("Unhandaled op " M_PRI_INST " following after OP_FCOMPARE\n", mono_inst_name (next_ins->opcode));
}
NULLIFY_INS (ins);
}
Expand Down Expand Up @@ -3302,7 +3302,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
* what should I do?
*/
if (cfg->verbose_level > 1) {
g_print ("Unhandaled op %s following after OP_{I|L}COMPARE{|_IMM}\n",
g_print ("Unhandaled op " M_PRI_INST " following after OP_{I|L}COMPARE{|_IMM}\n",
mono_inst_name (next_ins->opcode));
}
NULLIFY_INS (ins);
Expand Down Expand Up @@ -5632,7 +5632,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
}

g_assertf ((code - cfg->native_code - offset) <= max_len,
"wrong maximal instruction length of instruction %s (expected %d, got %d)",
"wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %d)",
mono_inst_name (ins->opcode), max_len, (int)(code - cfg->native_code - offset));
}
set_code_cursor (cfg, code);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/mini-s390x.c
Original file line number Diff line number Diff line change
Expand Up @@ -5436,12 +5436,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
break;
#endif
default:
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
g_assert_not_reached ();
}

if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %ld)",
mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
g_assert_not_reached ();
}
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/mini-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -4912,12 +4912,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
code = emit_get_last_error (code, ins->dreg);
break;
default:
g_warning ("unknown opcode %s\n", mono_inst_name (ins->opcode));
g_warning ("unknown opcode " M_PRI_INST "\n", mono_inst_name (ins->opcode));
g_assert_not_reached ();
}

if (G_UNLIKELY ((code - cfg->native_code - offset) > GINT_TO_UINT(max_len))) {
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %d)",
mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
g_assert_not_reached ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ mono_decompose_op_imm (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins)
mono_bblock_insert_before_ins (bb, ins, temp);

if (opcode2 == -1)
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
g_error ("mono_op_imm_to_op failed for " M_PRI_INST "\n", mono_inst_name (ins->opcode));
ins->opcode = GINT_TO_OPCODE (opcode2);

if (ins->opcode == OP_LOCALLOC)
Expand Down
12 changes: 11 additions & 1 deletion src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,17 @@ 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);
const char* mono_inst_name (int op);
#ifndef DISABLE_LOGGING
#define M_PRI_INST "%s"
const char * mono_inst_name(int opcode);
#else
#define M_PRI_INST "%d"
static inline int
mono_inst_name(int opcode)
{
return opcode;
}
#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

0 comments on commit bc0b090

Please sign in to comment.