Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _codeql_detected_source_root
19 changes: 11 additions & 8 deletions core/iwasm/compilation/aot_emit_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -2769,13 +2769,16 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
I32_CONST(1), /* 1 counter for this call site */
I32_CONST(0)); /* counter index 0 */

/* Now add value profiling to capture the call target */
/* Convert func_idx to i64 for value profiling */
LLVMValueRef func_idx_i64 = LLVMBuildZExt(comp_ctx->builder,
func_idx, I64_TYPE,
"func_idx_i64");
if (!func_idx_i64) {
aot_set_last_error("llvm build zext failed.");
/* Now add value profiling to capture the call target.
* LLVM's value profiling expects the actual function pointer address,
* not the WebAssembly function index. This allows LLVM to correlate
* the runtime target with the actual compiled function for PGO. */
/* Convert func_ptr to i64 for value profiling */
LLVMValueRef func_ptr_i64 = LLVMBuildPtrToInt(comp_ctx->builder,
func_ptr, I64_TYPE,
"func_ptr_i64");
if (!func_ptr_i64) {
aot_set_last_error("llvm build ptrtoint failed.");
goto fail;
}

Expand All @@ -2790,7 +2793,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
"llvm.instrprof.value.profile", VOID_TYPE,
value_prof_param_types, 5, glob,
I64_CONST(func_ctx->aot_func->func_idx),
func_idx_i64,
func_ptr_i64,
I32_CONST(0), /* IPVK_IndirectCallTarget */
I32_CONST(0)); /* call site index */
}
Expand Down