Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 250bca7

Browse files
committed
Debugging and profiling support for LLVM JIT provider.
This currently requires patches to the LLVM codebase to be effective (submitted upstream), the GUCs are available without those patches however. Author: Andres Freund Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
1 parent b96d550 commit 250bca7

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

src/backend/jit/jit.c

+2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
/* GUCs */
3434
bool jit_enabled = true;
3535
char *jit_provider = "llvmjit";
36+
bool jit_debugging_support = false;
3637
bool jit_dump_bitcode = false;
38+
bool jit_profiling_support = false;
3739

3840
static JitProviderCallbacks provider;
3941
static bool provider_successfully_loaded = false;

src/backend/jit/llvm/llvmjit.c

+36
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,21 @@ llvm_session_initialize(void)
541541
llvm_opt0_orc = LLVMOrcCreateInstance(llvm_opt0_targetmachine);
542542
llvm_opt3_orc = LLVMOrcCreateInstance(llvm_opt3_targetmachine);
543543

544+
#if defined(HAVE_DECL_LLVMORCREGISTERGDB) && HAVE_DECL_LLVMORCREGISTERGDB
545+
if (jit_debugging_support)
546+
{
547+
LLVMOrcRegisterGDB(llvm_opt0_orc);
548+
LLVMOrcRegisterGDB(llvm_opt3_orc);
549+
}
550+
#endif
551+
#if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF
552+
if (jit_profiling_support)
553+
{
554+
LLVMOrcRegisterPerf(llvm_opt0_orc);
555+
LLVMOrcRegisterPerf(llvm_opt3_orc);
556+
}
557+
#endif
558+
544559
before_shmem_exit(llvm_shutdown, 0);
545560

546561
llvm_session_initialized = true;
@@ -551,6 +566,27 @@ llvm_session_initialize(void)
551566
static void
552567
llvm_shutdown(int code, Datum arg)
553568
{
569+
/* unregister profiling support, needs to be flushed to be useful */
570+
571+
if (llvm_opt3_orc)
572+
{
573+
#if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF
574+
if (jit_profiling_support)
575+
LLVMOrcUnregisterPerf(llvm_opt3_orc);
576+
#endif
577+
LLVMOrcDisposeInstance(llvm_opt3_orc);
578+
llvm_opt3_orc = NULL;
579+
}
580+
581+
if (llvm_opt0_orc)
582+
{
583+
#if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF
584+
if (jit_profiling_support)
585+
LLVMOrcUnregisterPerf(llvm_opt0_orc);
586+
#endif
587+
LLVMOrcDisposeInstance(llvm_opt0_orc);
588+
llvm_opt0_orc = NULL;
589+
}
554590
}
555591

556592
/* helper for llvm_create_types */

src/backend/utils/misc/guc.c

+32
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,22 @@ static struct config_bool ConfigureNamesBool[] =
17341734
NULL, NULL, NULL
17351735
},
17361736

1737+
{
1738+
{"jit_debugging_support", PGC_SU_BACKEND, DEVELOPER_OPTIONS,
1739+
gettext_noop("Register JIT compiled function with debugger."),
1740+
NULL,
1741+
GUC_NOT_IN_SAMPLE
1742+
},
1743+
&jit_debugging_support,
1744+
false,
1745+
/*
1746+
* This is not guaranteed to be available, but given it's a developer
1747+
* oriented option, it doesn't seem worth adding code checking
1748+
* availability.
1749+
*/
1750+
NULL, NULL, NULL
1751+
},
1752+
17371753
{
17381754
{"jit_dump_bitcode", PGC_SUSET, DEVELOPER_OPTIONS,
17391755
gettext_noop("Write out LLVM bitcode to facilitate JIT debugging."),
@@ -1745,6 +1761,22 @@ static struct config_bool ConfigureNamesBool[] =
17451761
NULL, NULL, NULL
17461762
},
17471763

1764+
{
1765+
{"jit_profiling_support", PGC_SU_BACKEND, DEVELOPER_OPTIONS,
1766+
gettext_noop("Register JIT compiled function with perf profiler."),
1767+
NULL,
1768+
GUC_NOT_IN_SAMPLE
1769+
},
1770+
&jit_profiling_support,
1771+
false,
1772+
/*
1773+
* This is not guaranteed to be available, but given it's a developer
1774+
* oriented option, it doesn't seem worth adding code checking
1775+
* availability.
1776+
*/
1777+
NULL, NULL, NULL
1778+
},
1779+
17481780
/* End-of-list marker */
17491781
{
17501782
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL

src/include/jit/jit.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ struct JitProviderCallbacks
5858
/* GUCs */
5959
extern bool jit_enabled;
6060
extern char *jit_provider;
61+
extern bool jit_debugging_support;
6162
extern bool jit_dump_bitcode;
63+
extern bool jit_profiling_support;
6264

6365

6466
extern void jit_reset_after_error(void);

0 commit comments

Comments
 (0)