Skip to content

Commit 7891447

Browse files
sayeedkhannabillambdageeksteveisokakoeplinger
authoredApr 9, 2024
[mono] Make mono_inst_name less misleading (#91042)
Fixes #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>
1 parent d1747a7 commit 7891447

13 files changed

+52
-43
lines changed
 

‎src/mono/mono/mini/alias-analysis.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ lower_load (MonoCompile *cfg, MonoInst *load, MonoInst *ldaddr)
5353
}
5454

5555
if (replaced_op != load->opcode) {
56-
if (cfg->verbose_level > 2)
57-
printf ("Incompatible load type: expected %s but got %s\n",
56+
if (cfg->verbose_level > 2) {
57+
printf ("Incompatible load type: expected " M_PRI_INST " but got " M_PRI_INST "\n",
5858
mono_inst_name (replaced_op),
5959
mono_inst_name (load->opcode));
60+
}
6061
return FALSE;
6162
} else {
6263
if (cfg->verbose_level > 2) { printf ("mem2reg replacing: "); mono_print_ins (load); }
@@ -84,10 +85,11 @@ lower_store (MonoCompile *cfg, MonoInst *store, MonoInst *ldaddr)
8485

8586

8687
if (replaced_op != store->opcode) {
87-
if (cfg->verbose_level > 2)
88-
printf ("Incompatible store_reg type: expected %s but got %s\n",
88+
if (cfg->verbose_level > 2) {
89+
printf ("Incompatible store_reg type: expected " M_PRI_INST " but got " M_PRI_INST "\n",
8990
mono_inst_name (replaced_op),
9091
mono_inst_name (store->opcode));
92+
}
9193
return FALSE;
9294
} else {
9395
if (cfg->verbose_level > 2) { printf ("mem2reg replacing: "); mono_print_ins (store); }

‎src/mono/mono/mini/helpers.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,17 @@ static const gint16 opidx [] = {
7676
#endif
7777
//#define ARCH_PREFIX "powerpc64-linux-gnu-"
7878

79+
#ifndef DISABLE_LOGGING
7980
const char*
8081
mono_inst_name (int op) {
81-
#ifndef DISABLE_LOGGING
8282
if (op >= OP_LOAD && op <= OP_LAST)
8383
return (const char*)&opstr + opidx [op - OP_LOAD];
8484
if (op < OP_LOAD)
8585
return mono_opcode_name (op);
8686
g_error ("unknown opcode name for %d", op);
8787
return NULL;
88-
#else
89-
g_error ("unknown opcode name for %d", op);
90-
g_assert_not_reached ();
91-
#endif
9288
}
89+
#endif
9390

9491
void
9592
mono_blockset_print (MonoCompile *cfg, MonoBitSet *set, const char *name, guint idom)

‎src/mono/mono/mini/mini-amd64.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -7770,12 +7770,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
77707770
amd64_mov_membase_reg (code, ins->sreg1, MONO_STRUCT_OFFSET (MonoContext, gregs) + i * sizeof (target_mgreg_t), i, sizeof (target_mgreg_t));
77717771
break;
77727772
default:
7773-
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
7773+
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
77747774
g_assert_not_reached ();
77757775
}
77767776

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

‎src/mono/mono/mini/mini-arm.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -3439,7 +3439,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
34393439
temp->dreg = mono_alloc_ireg (cfg);
34403440
ins->sreg2 = temp->dreg;
34413441
if (opcode2 == -1)
3442-
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
3442+
g_error ("mono_op_imm_to_op failed for " M_PRI_INST "\n", mono_inst_name (ins->opcode));
34433443
ins->opcode = GUINT32_TO_OPCODE (opcode2);
34443444
}
34453445
if (ins->opcode == OP_SBB || ins->opcode == OP_ISBB || ins->opcode == OP_SUBCC)
@@ -3497,7 +3497,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
34973497
temp->dreg = mono_alloc_ireg (cfg);
34983498
ins->sreg2 = temp->dreg;
34993499
if (opcode2 == -1)
3500-
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (ins->opcode));
3500+
g_error ("mono_op_imm_to_op failed for " M_PRI_INST "\n", mono_inst_name (ins->opcode));
35013501
ins->opcode = GINT32_TO_UINT16 (opcode2);
35023502
break;
35033503
}
@@ -5957,12 +5957,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
59575957
ARM_STR_IMM (code, i, ins->sreg1, MONO_STRUCT_OFFSET (MonoContext, regs) + i * sizeof (target_mgreg_t));
59585958
break;
59595959
default:
5960-
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
5960+
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
59615961
g_assert_not_reached ();
59625962
}
59635963

59645964
if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
5965-
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
5965+
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %d)",
59665966
mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
59675967
g_assert_not_reached ();
59685968
}

‎src/mono/mono/mini/mini-arm64.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -3704,7 +3704,7 @@ opcode_to_armcond (int opcode)
37043704
case OP_COND_EXC_INO:
37053705
return ARMCOND_VC;
37063706
default:
3707-
printf ("%s\n", mono_inst_name (opcode));
3707+
printf ("" M_PRI_INST "\n", mono_inst_name (opcode));
37083708
g_assert_not_reached ();
37093709
return -1;
37103710
}
@@ -5801,13 +5801,13 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
58015801
break;
58025802

58035803
default:
5804-
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
5804+
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
58055805
g_assert_not_reached ();
58065806
}
58075807

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

‎src/mono/mono/mini/mini-codegen.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ mono_print_ins_index_strbuf (int i, MonoInst *ins)
439439
char spec_dest = (char)0, spec_src1 = (char)0, spec_src2 = (char)0, spec_src3 = (char)0;
440440

441441
if (i != -1)
442-
g_string_append_printf (sbuf, "\t%-2d %s", i, mono_inst_name (ins->opcode));
442+
g_string_append_printf (sbuf, "\t%-2d " M_PRI_INST "", i, mono_inst_name (ins->opcode));
443443
else
444-
g_string_append_printf (sbuf, " %s", mono_inst_name (ins->opcode));
444+
g_string_append_printf (sbuf, " " M_PRI_INST "", mono_inst_name (ins->opcode));
445445
if (spec == (gpointer)MONO_ARCH_CPU_SPEC) {
446446
/* This is a lowered opcode */
447447
if (ins->dreg != -1) {
@@ -1160,11 +1160,11 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
11601160
ispec = INS_INFO (i);
11611161

11621162
if ((spec [MONO_INST_DEST] && (ispec [MONO_INST_DEST] == ' ')))
1163-
g_error ("Instruction metadata for %s inconsistent.\n", mono_inst_name (i));
1163+
g_error ("Instruction metadata for " M_PRI_INST " inconsistent.\n", mono_inst_name (i));
11641164
if ((spec [MONO_INST_SRC1] && (ispec [MONO_INST_SRC1] == ' ')))
1165-
g_error ("Instruction metadata for %s inconsistent.\n", mono_inst_name (i));
1165+
g_error ("Instruction metadata for " M_PRI_INST " inconsistent.\n", mono_inst_name (i));
11661166
if ((spec [MONO_INST_SRC2] && (ispec [MONO_INST_SRC2] == ' ')))
1167-
g_error ("Instruction metadata for %s inconsistent.\n", mono_inst_name (i));
1167+
g_error ("Instruction metadata for " M_PRI_INST " inconsistent.\n", mono_inst_name (i));
11681168
}
11691169
#endif
11701170
}
@@ -1249,7 +1249,7 @@ mono_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
12491249
spec_dest = spec [MONO_INST_DEST];
12501250

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

12551255
DEBUG (mono_print_ins_index (i, ins));
@@ -2303,7 +2303,7 @@ mono_opcode_to_cond (int opcode)
23032303
CompRelation rel = mono_opcode_to_cond_unchecked (opcode);
23042304

23052305
if (rel == (CompRelation)-1) {
2306-
printf ("%s\n", mono_inst_name (opcode));
2306+
printf ("" M_PRI_INST "\n", mono_inst_name (opcode));
23072307
g_assert_not_reached ();
23082308
return (CompRelation)0;
23092309
}
@@ -2367,7 +2367,7 @@ mono_opcode_to_type (int opcode, int cmp_opcode)
23672367
return CMP_TYPE_L;
23682368
}
23692369
} else {
2370-
g_error ("Unknown opcode '%s' in opcode_to_type", mono_inst_name (opcode));
2370+
g_error ("Unknown opcode '" M_PRI_INST "' in opcode_to_type", mono_inst_name (opcode));
23712371
return (CompType)0;
23722372
}
23732373
}

‎src/mono/mono/mini/mini-llvm.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ op_to_llvm_type (int opcode)
10281028
case OP_LMUL_OVF_UN:
10291029
return LLVMInt64Type ();
10301030
default:
1031-
printf ("%s\n", mono_inst_name (opcode));
1031+
printf ("" M_PRI_INST "\n", mono_inst_name (opcode));
10321032
g_assert_not_reached ();
10331033
return NULL;
10341034
}
@@ -12445,12 +12445,12 @@ MONO_RESTORE_WARNING
1244512445
case OP_LOAD_GOTADDR: {
1244612446
char reason [128];
1244712447

12448-
sprintf (reason, "opcode %s", mono_inst_name (ins->opcode));
12448+
sprintf (reason, "opcode " M_PRI_INST "", mono_inst_name (ins->opcode));
1244912449
set_failure (ctx, reason);
1245012450
break;
1245112451
}
1245212452
default:
12453-
g_error ("opcode %d %s", ins->opcode, mono_inst_name (ins->opcode));
12453+
g_error ("opcode %d " M_PRI_INST "", ins->opcode, mono_inst_name (ins->opcode));
1245412454
break;
1245512455
}
1245612456

‎src/mono/mono/mini/mini-ppc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,7 @@ map_to_reg_reg_op (int op)
24202420
return OP_STOREI8_MEMBASE_REG;
24212421
}
24222422
if (mono_op_imm_to_op (op) == -1)
2423-
g_error ("mono_op_imm_to_op failed for %s\n", mono_inst_name (op));
2423+
g_error ("mono_op_imm_to_op failed for " M_PRI_INST "\n", mono_inst_name (op));
24242424
return mono_op_imm_to_op (op);
24252425
}
24262426

@@ -4734,12 +4734,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
47344734
break;
47354735
}
47364736
default:
4737-
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
4737+
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
47384738
g_assert_not_reached ();
47394739
}
47404740

47414741
if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
4742-
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
4742+
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %ld)",
47434743
mono_inst_name (ins->opcode), max_len, (glong)(code - cfg->native_code - offset));
47444744
g_assert_not_reached ();
47454745
}

‎src/mono/mono/mini/mini-riscv.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ mono_arch_decompose_opts (MonoCompile *cfg, MonoInst *ins)
21552155
NULLIFY_INS (ins);
21562156
break;
21572157
default:
2158-
g_print ("Can't decompose the OP %s\n", mono_inst_name (ins->opcode));
2158+
g_print ("Can't decompose the OP " M_PRI_INST "\n", mono_inst_name (ins->opcode));
21592159
NOT_IMPLEMENTED;
21602160
}
21612161
}
@@ -2801,7 +2801,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
28012801
next_ins->sreg2 = RISCV_ZERO;
28022802
} else {
28032803
if (cfg->verbose_level > 1) {
2804-
g_print ("Unhandaled op %s following after OP_RCOMPARE\n", mono_inst_name (next_ins->opcode));
2804+
g_print ("Unhandaled op " M_PRI_INST " following after OP_RCOMPARE\n", mono_inst_name (next_ins->opcode));
28052805
}
28062806
NULLIFY_INS (ins);
28072807
}
@@ -2885,7 +2885,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
28852885
next_ins->sreg2 = RISCV_ZERO;
28862886
} else {
28872887
if (cfg->verbose_level > 1) {
2888-
g_print ("Unhandaled op %s following after OP_FCOMPARE\n", mono_inst_name (next_ins->opcode));
2888+
g_print ("Unhandaled op " M_PRI_INST " following after OP_FCOMPARE\n", mono_inst_name (next_ins->opcode));
28892889
}
28902890
NULLIFY_INS (ins);
28912891
}
@@ -3302,7 +3302,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb)
33023302
* what should I do?
33033303
*/
33043304
if (cfg->verbose_level > 1) {
3305-
g_print ("Unhandaled op %s following after OP_{I|L}COMPARE{|_IMM}\n",
3305+
g_print ("Unhandaled op " M_PRI_INST " following after OP_{I|L}COMPARE{|_IMM}\n",
33063306
mono_inst_name (next_ins->opcode));
33073307
}
33083308
NULLIFY_INS (ins);
@@ -5632,7 +5632,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
56325632
}
56335633

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

‎src/mono/mono/mini/mini-s390x.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5436,12 +5436,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
54365436
break;
54375437
#endif
54385438
default:
5439-
g_warning ("unknown opcode %s in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
5439+
g_warning ("unknown opcode " M_PRI_INST " in %s()\n", mono_inst_name (ins->opcode), __FUNCTION__);
54405440
g_assert_not_reached ();
54415441
}
54425442

54435443
if ((cfg->opt & MONO_OPT_BRANCH) && ((code - cfg->native_code - offset) > max_len)) {
5444-
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %ld)",
5444+
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %ld)",
54455445
mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
54465446
g_assert_not_reached ();
54475447
}

‎src/mono/mono/mini/mini-x86.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4912,12 +4912,12 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb)
49124912
code = emit_get_last_error (code, ins->dreg);
49134913
break;
49144914
default:
4915-
g_warning ("unknown opcode %s\n", mono_inst_name (ins->opcode));
4915+
g_warning ("unknown opcode " M_PRI_INST "\n", mono_inst_name (ins->opcode));
49164916
g_assert_not_reached ();
49174917
}
49184918

49194919
if (G_UNLIKELY ((code - cfg->native_code - offset) > GINT_TO_UINT(max_len))) {
4920-
g_warning ("wrong maximal instruction length of instruction %s (expected %d, got %d)",
4920+
g_warning ("wrong maximal instruction length of instruction " M_PRI_INST " (expected %d, got %d)",
49214921
mono_inst_name (ins->opcode), max_len, code - cfg->native_code - offset);
49224922
g_assert_not_reached ();
49234923
}

‎src/mono/mono/mini/mini.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ mono_decompose_op_imm (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins)
602602
mono_bblock_insert_before_ins (bb, ins, temp);
603603

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

608608
if (ins->opcode == OP_LOCALLOC)

‎src/mono/mono/mini/mini.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,17 @@ GString *mono_print_ins_index_strbuf (int i, MonoInst *ins);
21832183
void mono_print_ins (MonoInst *ins);
21842184
void mono_print_bb (MonoBasicBlock *bb, const char *msg);
21852185
void mono_print_code (MonoCompile *cfg, const char *msg);
2186-
const char* mono_inst_name (int op);
2186+
#ifndef DISABLE_LOGGING
2187+
#define M_PRI_INST "%s"
2188+
const char * mono_inst_name(int opcode);
2189+
#else
2190+
#define M_PRI_INST "%d"
2191+
static inline int
2192+
mono_inst_name(int opcode)
2193+
{
2194+
return opcode;
2195+
}
2196+
#endif
21872197
int mono_op_to_op_imm (int opcode);
21882198
int mono_op_imm_to_op (int opcode);
21892199
int mono_load_membase_to_load_mem (int opcode);

0 commit comments

Comments
 (0)