From: Egor Bogatov Date: Thu, 26 Sep 2019 07:51:36 +0000 (+0300) Subject: LLVM: Add comments (string metadata) for calls (mono/mono#16956) X-Git-Tag: submit/tizen/20210909.063632~10331^2~5^2~448 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b9d1c59d425d1eb3349bb29d2192cc0a0b85d0b;p=platform%2Fupstream%2Fdotnet%2Fruntime.git LLVM: Add comments (string metadata) for calls (mono/mono#16956) * Add string metadata to all calls (comments) * Update mini-llvm.c * rename tramp_%d to full name too Commit migrated from https://github.com/mono/mono/commit/4a72dadb34f313d242908b086f204cd5346d0bbc --- diff --git a/src/mono/mono/mini/mini-llvm-cpp.cpp b/src/mono/mono/mini/mini-llvm-cpp.cpp index 33c0ad5..8e9a0b5 100644 --- a/src/mono/mono/mini/mini-llvm-cpp.cpp +++ b/src/mono/mono/mini/mini-llvm-cpp.cpp @@ -222,6 +222,14 @@ mono_llvm_build_weighted_branch (LLVMBuilderRef builder, LLVMValueRef cond, LLVM } void +mono_llvm_add_string_metadata (LLVMValueRef insref, const char* label, const char* text) +{ + auto ins = unwrap (insref); + auto &ctx = ins->getContext (); + ins->setMetadata (label, MDNode::get (ctx, MDString::get (ctx, text))); +} + +void mono_llvm_set_implicit_branch (LLVMBuilderRef builder, LLVMValueRef branch) { auto b = unwrap (builder); diff --git a/src/mono/mono/mini/mini-llvm-cpp.h b/src/mono/mono/mini/mini-llvm-cpp.h index f8f807f..1ebeddc 100644 --- a/src/mono/mono/mini/mini-llvm-cpp.h +++ b/src/mono/mono/mini/mini-llvm-cpp.h @@ -95,6 +95,9 @@ LLVMValueRef mono_llvm_build_weighted_branch (LLVMBuilderRef builder, LLVMValueRef cond, LLVMBasicBlockRef t, LLVMBasicBlockRef f, uint32_t t_weight, uint32_t f_weight); void +mono_llvm_add_string_metadata (LLVMValueRef insref, const char* label, const char* text); + +void mono_llvm_set_implicit_branch (LLVMBuilderRef builder, LLVMValueRef branch); void diff --git a/src/mono/mono/mini/mini-llvm.c b/src/mono/mono/mini/mini-llvm.c index 2661c85..bb9172e 100644 --- a/src/mono/mono/mini/mini-llvm.c +++ b/src/mono/mono/mini/mini-llvm.c @@ -3837,7 +3837,7 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref, static int tramp_index; char *name; - name = g_strdup_printf ("tramp_%d", tramp_index); + name = g_strdup_printf ("[tramp_%d] %s", tramp_index, mono_method_full_name (call->method, TRUE)); tramp_index ++; /* @@ -4101,6 +4101,10 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref, if (ins->opcode != OP_TAILCALL && ins->opcode != OP_TAILCALL_MEMBASE && LLVMGetInstructionOpcode (lcall) == LLVMCall) mono_llvm_set_call_notailcall (lcall); + // Add original method name we are currently emitting as a custom string metadata (the only way to leave comments in LLVM IR) + if (mono_debug_enabled () && call && call->method) + mono_llvm_add_string_metadata (lcall, "managed_name", mono_method_full_name (call->method, TRUE)); + // As per the LLVM docs, a function has a noalias return value if and only if // it is an allocation function. This is an allocation function. if (call->method && call->method->wrapper_type == MONO_WRAPPER_ALLOC)