-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reuse incremental JIT compilation for --image-codegen #50649
Conversation
src/jitlayers.cpp
Outdated
// need to emit a separate module for the globals before any functions are compiled, | ||
// to ensure that the globals are defined when they are compiled. | ||
if (params.imaging) { | ||
jl_ExecutionEngine->addModule(jl_get_globals_module(params.tsctx, params.imaging, params.DL, params.TargetTriple, params.globals)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jl_ExecutionEngine->addModule(jl_get_globals_module(params.tsctx, params.imaging, params.DL, params.TargetTriple, params.globals)); | |
auto lock = params.tsctx.getLock(); | |
for (auto &global : params.globals) { | |
auto GV = global.second; | |
GV->setName(GV->getName() + "." + unique_counter++); | |
addGlobalMapping(GV->getName(), global.first); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, other than jl_get_globals_module
which needs to mangle names to something unique in the current jl_ExecutionEngine
.
That's actually handled elsewhere in |
1e898f3
to
4b440a0
Compare
Ah right, so you can remove that extra setName call then for now, but still simplify that loop substantially by using for (auto &global : params.globals)
addGlobalMapping(global.second->getName(), global.first); The That should be some of the last steps needed to make codegen itself pure, and make native code caching feasible based on the IR or bitcode hash. |
I don't think addGlobalMapping is helpful here, we want the pointer to be the value stored in the global rather than the address of the global. We still need to allocate memory to load from in the IR. |
Ah, right. That probably gets us even closer to the version where we actually do the same representation as image_codegen though, since we would already make the equivalent array for it: void **globals = (void**)malloc(sizeof(void*) * params.globals.size());
size_t i = 0;
for (auto &global : params.globals) {
globals[i] = global.first;
addGlobalMapping(global.second->getName(), &globals[i]);
i++;
} Then all the remains is converting all of the |
I think the better route to go about this is to convert imaging mode to use direct pointers instead of offsets, and make the linker patch in those references at load time. |
I don't see how that would work well with caching, since we don't have names for those things to give the linker. The names have to be globally meaningful for it to work, but everything really should be self-contained in the module. We also want it to be efficient, and giant string pools to compute offsets at runtime is a lot less compact than simply having the ordered array in the first place. |
We don't need to merge all of the workqueue modules when performing compilation with `--image-codegen` set, we just need the global variable initializers to be defined before they're used in one of the modules. Therefore we can do this by compiling all of the global variable initializers upfront, so that later references will link them properly. (cherry picked from commit ff14eaf)
We don't need to merge all of the workqueue modules when performing compilation with
--image-codegen
set, we just need the global variable initializers to be defined before they're used in one of the modules. Therefore we can do this by compiling all of the global variable initializers upfront, so that later references will link them properly.