Generate jitdump to support linux perf for LLVM JIT (#2788)
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "llvm-c/Target.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/Object.h"
|
||||
#include "llvm-c/OrcEE.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include "llvm-c/Analysis.h"
|
||||
#include "llvm-c/BitWriter.h"
|
||||
@ -422,6 +423,8 @@ typedef struct AOTCompContext {
|
||||
char stack_usage_temp_file[64];
|
||||
const char *llvm_passes;
|
||||
const char *builtin_intrinsics;
|
||||
|
||||
bool emit_frame_pointer;
|
||||
} AOTCompContext;
|
||||
|
||||
enum {
|
||||
@ -431,6 +434,7 @@ enum {
|
||||
AOT_LLVMIR_OPT_FILE,
|
||||
};
|
||||
|
||||
/* always sync it with AOTCompOption in aot_export.h */
|
||||
typedef struct AOTCompOption {
|
||||
bool is_jit_mode;
|
||||
bool is_indirect_mode;
|
||||
@ -457,6 +461,7 @@ typedef struct AOTCompOption {
|
||||
uint32 bounds_checks;
|
||||
uint32 stack_bounds_checks;
|
||||
uint32 segue_flags;
|
||||
bool linux_perf_support;
|
||||
char **custom_sections;
|
||||
uint32 custom_sections_count;
|
||||
const char *stack_usage_file;
|
||||
|
||||
@ -12,11 +12,13 @@
|
||||
#include "llvm/ADT/None.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#endif
|
||||
#include "llvm/ExecutionEngine/JITEventListener.h"
|
||||
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
||||
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
|
||||
@ -108,6 +110,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectTransformLayer,
|
||||
LLVMOrcObjectTransformLayerRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcV2CAPIHelper::PoolEntry,
|
||||
LLVMOrcSymbolStringPoolEntryRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectLayer, LLVMOrcObjectLayerRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SymbolStringPool, LLVMOrcSymbolStringPoolRef)
|
||||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef)
|
||||
|
||||
@ -322,3 +325,9 @@ LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J)
|
||||
{
|
||||
return wrap(&unwrap(J)->getObjTransformLayer());
|
||||
}
|
||||
|
||||
LLVMOrcObjectLayerRef
|
||||
LLVMOrcLLLazyJITGetObjLinkingLayer(LLVMOrcLLLazyJITRef J)
|
||||
{
|
||||
return wrap(&unwrap(J)->getObjLinkingLayer());
|
||||
}
|
||||
|
||||
@ -76,5 +76,8 @@ LLVMOrcLLJITBuilderSetCompileFuncitonCreatorWithStackSizesCallback(
|
||||
LLVMOrcLLLazyJITBuilderRef Builder,
|
||||
void (*cb)(void *, const char *, size_t, size_t), void *cb_data);
|
||||
|
||||
LLVMOrcObjectLayerRef
|
||||
LLVMOrcLLLazyJITGetObjLinkingLayer(LLVMOrcLLLazyJITRef J);
|
||||
|
||||
LLVM_C_EXTERN_C_END
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user