[dpgo] Add profiling counters for opcode if (#2301)

This commit is contained in:
liang.he 2023-06-21 11:40:29 +08:00 committed by GitHub
parent 558a5f6d44
commit cf40531b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 5 deletions

View File

@ -505,7 +505,7 @@ wasm_dpgo_get_cnts_for_instr(WASMModule *wasm_module, uint32 func_idx,
// FIXME: remove if when we have switch
if (!LLVMIsASwitchInst(instruction)) {
wasm_dpgo_dump_func_prof_cnts_info(wasm_module, func_idx);
bh_assert(*cnt_amount == 0 && "No counter for condBr or select");
bh_assert(*cnt_amount != 0 && "No counter for condBr or select");
return false;
}

View File

@ -806,6 +806,10 @@ jit_compile_op_block(JitCompContext *cc, uint8 **p_frame_ip,
goto fail;
}
else if (label_type == LABEL_TYPE_IF) {
#if WASM_ENABLE_DYNAMIC_PGO != 0
gen_increase_cnt_insn(cc->jit_frame);
#endif
POP_I32(value);
if (!jit_reg_is_const_val(value)) {
@ -820,6 +824,10 @@ jit_compile_op_block(JitCompContext *cc, uint8 **p_frame_ip,
cc, block, block->basic_block_entry, value,
merge_cmp_and_if))
goto fail;
#if WASM_ENABLE_DYNAMIC_PGO != 0
gen_increase_cnt_insn(cc->jit_frame);
#endif
}
else {
if (jit_cc_get_const_I32(cc, value) != 0) {
@ -829,8 +837,16 @@ jit_compile_op_block(JitCompContext *cc, uint8 **p_frame_ip,
if (!push_jit_block_to_stack_and_pass_params(
cc, block, cc->cur_basic_block, 0, false))
goto fail;
#if WASM_ENABLE_DYNAMIC_PGO != 0
gen_increase_cnt_insn(cc->jit_frame);
#endif
}
else {
#if WASM_ENABLE_DYNAMIC_PGO != 0
/* Clarify me */
gen_dummy_increase_cnt_insn(cc->jit_frame);
#endif
if (else_addr) {
/* Compare value is not 0, condition is false, if branch of
BASIC_BLOCK if cannot be reached, we treat it same as

View File

@ -554,6 +554,12 @@ gen_increase_cnt_insn(JitFrame *frame)
gen_increase_cnt_insn_internal(frame, frame->cc->ent_and_br_cnts_idx++);
}
void
gen_dummy_increase_cnt_insn(JitFrame *frame)
{
frame->cc->ent_and_br_cnts_idx++;
}
void
gen_increase_cnt_w_val_insn(JitFrame *frame, JitReg val_reg)
{

View File

@ -226,6 +226,9 @@ get_ent_and_br_cnts_reg(JitFrame *frame);
void
gen_increase_cnt_insn(JitFrame *frame);
void
gen_dummy_increase_cnt_insn(JitFrame *frame);
void
gen_increase_cnt_w_val_insn(JitFrame *frame, JitReg val_reg);
#endif

View File

@ -7579,11 +7579,19 @@ re_scan:
#if WASM_ENABLE_FAST_INTERP != 0
PRESERVE_LOCAL_FOR_BLOCK();
#endif
#if WASM_ENABLE_DYNAMIC_PGO != 0
if (!create_and_append_WasmProfCntInfo(
func_prof_cnts_info,
module->import_function_count + cur_func_idx,
p - func->code, opcode, 2, ent_and_br_cnts_cap,
error_buf, error_buf_size))
goto fail;
ent_and_br_cnts_cap += 2;
#endif
POP_I32();
/*FIXME: enable it later */
// #if WASM_ENABLE_DYNAMIC_PGO != 0
// ent_and_br_cnts_cap += 2;
// #endif
goto handle_op_block_and_loop;
case WASM_OP_BLOCK:
case WASM_OP_LOOP: