From ca39a6cdf95fda8e51cd89489c7e195036f544f8 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Wed, 17 Apr 2019 00:41:54 -0700 Subject: [PATCH] Factor the function mono_call_add_patch_info out of a few lines of repeated code in many backends. (mono/mono#13970) This notably does not apply to amd64, x86. They have more logic intertwined around the patch when they emit the call. Commit migrated from https://github.com/mono/mono/commit/cd5e14a3ccaa76e6ba6c58b26823863a2d0a0854 --- src/mono/mono/mini/calls.c | 9 +++++++++ src/mono/mono/mini/mini-arm.c | 6 ++---- src/mono/mono/mini/mini-arm64.c | 4 ++-- src/mono/mono/mini/mini-mips.c | 3 +-- src/mono/mono/mini/mini-ppc.c | 5 +---- src/mono/mono/mini/mini-s390x.c | 9 +-------- src/mono/mono/mini/mini.c | 6 ++++++ src/mono/mono/mini/mini.h | 1 + 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/mono/mono/mini/calls.c b/src/mono/mono/mini/calls.c index 801d03f..0b56d38 100644 --- a/src/mono/mono/mini/calls.c +++ b/src/mono/mono/mini/calls.c @@ -22,6 +22,15 @@ static const gboolean debug_tailcall_break_compile = FALSE; // break in method_t static const gboolean debug_tailcall_break_run = FALSE; // insert breakpoint in generated code void +mono_call_add_patch_info (MonoCompile *cfg, MonoCallInst *call, int ip) +{ + if (call->inst.flags & MONO_INST_HAS_METHOD) + mono_add_patch_info (cfg, ip, MONO_PATCH_INFO_METHOD, call->method); + else + mono_add_patch_info (cfg, ip, MONO_PATCH_INFO_ABS, call->fptr); +} + +void mini_test_tailcall (MonoCompile *cfg, gboolean tailcall) { // A lot of tests say "tailcall" throughout their verbose output. diff --git a/src/mono/mono/mini/mini-arm.c b/src/mono/mono/mini/mini-arm.c index 9333948..5b1459b 100644 --- a/src/mono/mono/mini/mini-arm.c +++ b/src/mono/mono/mini/mini-arm.c @@ -5131,10 +5131,8 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) if (IS_HARD_FLOAT) code = emit_float_args (cfg, call, code, &max_len, &offset); - if (ins->flags & MONO_INST_HAS_METHOD) - mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_METHOD, call->method); - else - mono_add_patch_info (cfg, code - cfg->native_code, MONO_PATCH_INFO_ABS, call->fptr); + mono_call_add_patch_info (cfg, call, code - cfg->native_code); + code = emit_call_seq (cfg, code); ins->flags |= MONO_INST_GC_CALLSITE; ins->backend.pc_offset = code - cfg->native_code; diff --git a/src/mono/mono/mini/mini-arm64.c b/src/mono/mono/mini/mini-arm64.c index 73fd160..19c9191 100644 --- a/src/mono/mono/mini/mini-arm64.c +++ b/src/mono/mono/mini/mini-arm64.c @@ -706,14 +706,14 @@ mono_arm_emit_ldrx (guint8 *code, int rt, int rn, int imm) } static guint8* -emit_call (MonoCompile *cfg, guint8* code, guint32 patch_type, gconstpointer data) +emit_call (MonoCompile *cfg, guint8* code, MonoJumpInfoType patch_type, gconstpointer data) { /* mono_add_patch_info_rel (cfg, code - cfg->native_code, patch_type, data, MONO_R_ARM64_IMM); code = emit_imm64_template (code, ARMREG_LR); arm_blrx (code, ARMREG_LR); */ - mono_add_patch_info_rel (cfg, code - cfg->native_code, (MonoJumpInfoType)patch_type, data, MONO_R_ARM64_BL); + mono_add_patch_info_rel (cfg, code - cfg->native_code, patch_type, data, MONO_R_ARM64_BL); arm_bl (code, code); cfg->thunk_area += THUNK_SIZE; return code; diff --git a/src/mono/mono/mini/mini-mips.c b/src/mono/mono/mini/mini-mips.c index bfe3aea..f27cfda 100644 --- a/src/mono/mono/mini/mini-mips.c +++ b/src/mono/mono/mini/mini-mips.c @@ -3802,12 +3802,11 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_VCALL2: case OP_VOIDCALL: case OP_CALL: + mono_call_add_patch_info (cfg, call, offset); if (ins->flags & MONO_INST_HAS_METHOD) { - mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD, call->method); mips_load (code, mips_t9, call->method); } else { - mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS, call->fptr); mips_load (code, mips_t9, call->fptr); } mips_jalr (code, mips_t9, mips_ra); diff --git a/src/mono/mono/mini/mini-ppc.c b/src/mono/mono/mini/mini-ppc.c index 641acd4..1761a95 100644 --- a/src/mono/mono/mini/mini-ppc.c +++ b/src/mono/mono/mini/mini-ppc.c @@ -3810,10 +3810,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_VOIDCALL: case OP_CALL: call = (MonoCallInst*)ins; - if (ins->flags & MONO_INST_HAS_METHOD) - mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_METHOD, call->method); - else - mono_add_patch_info (cfg, offset, MONO_PATCH_INFO_ABS, call->fptr); + mono_call_add_patch_info (cfg, call, offset); if ((FORCE_INDIR_CALL || cfg->method->dynamic) && !cfg->compile_aot) { ppc_load_func (code, PPC_CALL_REG, 0); ppc_mtlr (code, PPC_CALL_REG); diff --git a/src/mono/mono/mini/mini-s390x.c b/src/mono/mono/mini/mini-s390x.c index 07bb6ba..f4073a9 100644 --- a/src/mono/mono/mini/mini-s390x.c +++ b/src/mono/mono/mini/mini-s390x.c @@ -3633,14 +3633,7 @@ mono_arch_output_basic_block (MonoCompile *cfg, MonoBasicBlock *bb) case OP_RCALL: case OP_CALL: { call = (MonoCallInst*)ins; - if (ins->flags & MONO_INST_HAS_METHOD) - mono_add_patch_info (cfg, code-cfg->native_code, - MONO_PATCH_INFO_METHOD, - call->method); - else - mono_add_patch_info (cfg, code-cfg->native_code, - MONO_PATCH_INFO_ABS, - call->fptr); + mono_call_add_patch_info (cfg, call, code - cfg->native_code); S390_CALL_TEMPLATE (code, s390_r14); } break; diff --git a/src/mono/mono/mini/mini.c b/src/mono/mono/mini/mini.c index 40f5e6a..039b076 100644 --- a/src/mono/mono/mini/mini.c +++ b/src/mono/mono/mini/mini.c @@ -1908,6 +1908,9 @@ mono_destroy_compile (MonoCompile *cfg) void mono_add_patch_info (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target) { + if (type == MONO_PATCH_INFO_NONE) + return; + MonoJumpInfo *ji = (MonoJumpInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoJumpInfo)); ji->ip.i = ip; @@ -1921,6 +1924,9 @@ mono_add_patch_info (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpoin void mono_add_patch_info_rel (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target, int relocation) { + if (type == MONO_PATCH_INFO_NONE) + return; + MonoJumpInfo *ji = (MonoJumpInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (MonoJumpInfo)); ji->ip.i = ip; diff --git a/src/mono/mono/mini/mini.h b/src/mono/mono/mini/mini.h index 2493fef..bf5945b 100644 --- a/src/mono/mono/mini/mini.h +++ b/src/mono/mono/mini/mini.h @@ -2039,6 +2039,7 @@ guint mini_type_to_stind (MonoCompile* cfg, MonoType *type); MonoJitInfo* mini_lookup_method (MonoDomain *domain, MonoMethod *method, MonoMethod *shared); guint32 mono_reverse_branch_op (guint32 opcode); void mono_disassemble_code (MonoCompile *cfg, guint8 *code, int size, char *id); +void mono_call_add_patch_info (MonoCompile *cfg, MonoCallInst *call, int ip); void mono_add_patch_info (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target) MONO_LLVM_INTERNAL; void mono_add_patch_info_rel (MonoCompile *cfg, int ip, MonoJumpInfoType type, gconstpointer target, int relocation) MONO_LLVM_INTERNAL; void mono_remove_patch_info (MonoCompile *cfg, int ip); -- 2.7.4