Skip to content

Commit 3f4ba52

Browse files
committed
accelerate symbol lookup in OrcJIT
CompileLayer.findSymbol is O(n) in the number of modules that have been emitted but we can pre-compute the result of findSymbolIn when notified that an object has been emitted and store it in one hash table for the JIT fix #15619
1 parent f2c699b commit 3f4ba52

File tree

4 files changed

+126
-137
lines changed

4 files changed

+126
-137
lines changed

src/codegen.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -1393,9 +1393,7 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc)
13931393
#endif
13941394
const object::ObjectFile *object = NULL;
13951395
assert(fptr != 0);
1396-
bool isJIT = true;
13971396
if (!jl_DI_for_fptr(fptr, &symsize, &slide, &section_slide, &object, &context)) {
1398-
isJIT = false;
13991397
if (!jl_dylib_DI_for_fptr(fptr, &object, &objcontext, &slide, &section_slide, false,
14001398
NULL, NULL, NULL, NULL)) {
14011399
jl_printf(JL_STDERR, "WARNING: Unable to find function pointer\n");
@@ -1410,9 +1408,6 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc)
14101408
}
14111409

14121410
if (raw_mc) {
1413-
#ifdef LLVM37
1414-
jl_cleanup_DI(context);
1415-
#endif
14161411
return (jl_value_t*)jl_pchar_to_array((char*)fptr, symsize);
14171412
}
14181413

@@ -1428,10 +1423,7 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc)
14281423
#endif
14291424
);
14301425

1431-
#ifdef LLVM37
1432-
if (isJIT)
1433-
jl_cleanup_DI(context);
1434-
#else
1426+
#ifndef LLVM37
14351427
fstream.flush();
14361428
#endif
14371429

src/codegen_internal.h

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ extern int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, int6
2727
extern bool jl_dylib_DI_for_fptr(size_t pointer, const object::ObjectFile **object, llvm::DIContext **context, int64_t *slide, int64_t *section_slide,
2828
bool onlySysImg, bool *isSysImg, void **saddr, char **name, char **filename);
2929

30-
#ifdef USE_MCJIT
31-
extern void jl_cleanup_DI(llvm::DIContext *context);
32-
#endif
33-
3430
#ifdef USE_ORCJIT
3531
extern JL_DLLEXPORT void ORCNotifyObjectEmitted(JITEventListener *Listener,
3632
const object::ObjectFile &obj,

src/debuginfo.cpp

+2-23
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ struct ObjectInfo {
9191
const object::ObjectFile *object;
9292
size_t SectionSize;
9393
ptrdiff_t slide;
94-
#ifdef LLVM39
94+
#ifdef LLVM37
9595
DIContext *context;
96-
#elif defined(LLVM37)
97-
const llvm::LoadedObjectInfo *L;
9896
#endif
9997
#if defined(_OS_DARWIN_) && !defined(LLVM37)
10098
const char *name;
@@ -444,11 +442,7 @@ class JuliaJITEventListener: public JITEventListener
444442
ObjectInfo tmp = {&debugObj,
445443
(size_t)SectionSize,
446444
(ptrdiff_t)(SectionAddr - SectionLoadAddr),
447-
#ifdef LLVM39
448445
new DWARFContextInMemory(debugObj, &L),
449-
#else
450-
L.clone().release(),
451-
#endif
452446
};
453447
objectmap[SectionLoadAddr] = tmp;
454448
first = false;
@@ -524,11 +518,6 @@ class JuliaJITEventListener: public JITEventListener
524518
#endif
525519
ObjectInfo tmp = {objfile, (size_t)Size,
526520
(ptrdiff_t)(SectionAddr - SectionLoadAddr),
527-
#ifdef LLVM39
528-
new DWARFContextInMemory(*objfile, &L),
529-
#elif defined(LLVM37)
530-
L.clone().release(),
531-
#endif
532521
#ifdef _OS_DARWIN_
533522
strndup(sName.data(), sName.size()),
534523
#endif
@@ -1066,10 +1055,8 @@ int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, int64_t *se
10661055
*section_slide = fit->second.slide;
10671056
*object = fit->second.object;
10681057
if (context) {
1069-
#if defined(LLVM39)
1058+
#if defined(LLVM37)
10701059
*context = fit->second.context;
1071-
#elif defined(LLVM37)
1072-
*context = new DWARFContextInMemory(*fit->second.object, fit->second.L);
10731060
#else
10741061
*context = DIContext::getDWARFContext(*fit->second.object);
10751062
#endif
@@ -1121,13 +1108,6 @@ JL_DLLEXPORT uint64_t jl_get_section_start(uint64_t fptr)
11211108

11221109
#endif
11231110

1124-
void jl_cleanup_DI(llvm::DIContext *context)
1125-
{
1126-
#ifndef LLVM39
1127-
delete context;
1128-
#endif
1129-
}
1130-
11311111
// Set *name and *filename to either NULL or malloc'd string
11321112
void jl_getFunctionInfo(char **name, char **filename, size_t *line,
11331113
char **inlinedat_file, size_t *inlinedat_line, jl_lambda_info_t **outer_linfo,
@@ -1151,7 +1131,6 @@ void jl_getFunctionInfo(char **name, char **filename, size_t *line,
11511131
if (jl_DI_for_fptr(pointer, &symsize, &slide, NULL, &object, &context)) {
11521132
*outer_linfo = jl_jit_events->lookupLinfo(pointer);
11531133
lookup_pointer(context, name, line, filename, inlinedat_line, inlinedat_file, pointer+slide, 1, fromC);
1154-
jl_cleanup_DI(context);
11551134
return;
11561135
}
11571136
#else // !USE_MCJIT

0 commit comments

Comments
 (0)