Generate jitdump to support linux perf for LLVM JIT (#2788)

This commit is contained in:
liang.he
2023-11-27 15:42:00 +08:00
committed by GitHub
parent d7608690c0
commit 8aa813f44a
14 changed files with 165 additions and 14 deletions

View File

@ -653,6 +653,19 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
attr_no_jump_tables);
}
/* spread fp.all to every function */
if (comp_ctx->emit_frame_pointer) {
const char *key = "frame-pointer";
const char *val = "all";
LLVMAttributeRef no_omit_fp = LLVMCreateStringAttribute(
comp_ctx->context, key, strlen(key), val, strlen(val));
if (!no_omit_fp) {
aot_set_last_error("create LLVM attribute (frame-pointer) failed.");
goto fail;
}
LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, no_omit_fp);
}
if (need_precheck) {
if (!comp_ctx->is_jit_mode)
LLVMSetLinkage(func, LLVMInternalLinkage);
@ -2160,7 +2173,7 @@ jit_stack_size_callback(void *user_data, const char *name, size_t namelen,
}
static bool
orc_jit_create(AOTCompContext *comp_ctx)
orc_jit_create(AOTCompContext *comp_ctx, bool linux_perf_support)
{
LLVMErrorRef err;
LLVMOrcLLLazyJITRef orc_jit = NULL;
@ -2200,6 +2213,14 @@ orc_jit_create(AOTCompContext *comp_ctx)
/* Ownership transfer: LLVMOrcLLJITBuilderRef -> LLVMOrcLLJITRef */
builder = NULL;
if (linux_perf_support) {
LOG_DEBUG("Enable linux perf support");
LLVMOrcObjectLayerRef obj_linking_layer =
(LLVMOrcObjectLayerRef)LLVMOrcLLLazyJITGetObjLinkingLayer(orc_jit);
LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(
obj_linking_layer, LLVMCreatePerfJITEventListener());
}
/* Ownership transfer: local -> AOTCompContext */
comp_ctx->orc_jit = orc_jit;
orc_jit = NULL;
@ -2298,6 +2319,17 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
goto fail;
}
if (option->linux_perf_support) {
/* FramePointerKind.All */
LLVMMetadataRef val =
LLVMValueAsMetadata(LLVMConstInt(LLVMInt32Type(), 2, false));
const char *key = "frame-pointer";
LLVMAddModuleFlag(comp_ctx->module, LLVMModuleFlagBehaviorWarning, key,
strlen(key), val);
comp_ctx->emit_frame_pointer = true;
}
if (BH_LIST_ERROR == bh_list_init(&comp_ctx->native_symbols)) {
goto fail;
}
@ -2401,7 +2433,7 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
goto fail;
/* Create LLJIT Instance */
if (!orc_jit_create(comp_ctx))
if (!orc_jit_create(comp_ctx, option->linux_perf_support))
goto fail;
}
else {