[PATCH] libLTO: Allow linker to choose context of modules and codegen
Duncan P. N. Exon Smith
dexonsmith at apple.com
Tue Nov 11 11:16:55 PST 2014
The attached patches add API for specifying which `LLVMContext` each
`lto_module_t` and `lto_code_gen_t` is in. combined.patch has the
combine diff.
This enables the following flow:
for (auto &File : Files) {
lto_module_t M = lto_module_create_in_local_context(File...);
querySymbols(M);
lto_module_dispose(M);
}
lto_code_gen_t CG = lto_codegen_create_in_local_context();
for (auto &File : FilesToLink) {
lto_module_t M = lto_module_create_in_codegen_context(File..., CG);
lto_codegen_add_module(CG, M);
lto_module_dispose(M);
}
lto_codegen_compile(CG);
lto_codegen_write_merged_modules(CG, ...);
lto_codegen_dispose(CG);
This flow has a few benefits.
- Only one module (two if you count the combined module in the code
generator) is in memory at a time.
- Metadata (and constants) from files that are parsed to query symbols
but not linked into the code generator don't pollute the global
context.
- The first for loop can be parallelized, since each module is in its
own context.
- When the code generator is disposed, the memory from LTO gets freed.
I'm not really sure how best to test this. Let me know if you have
any ideas.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: combined.patch
Type: application/octet-stream
Size: 14269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141111/71680a7d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-libLTO-Allow-LTOCodeGenerator-to-own-a-context.patch
Type: application/octet-stream
Size: 1798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141111/71680a7d/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-libLTO-Allow-LTOModule-to-own-a-context.patch
Type: application/octet-stream
Size: 7435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141111/71680a7d/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-libLTO-Error-if-LTOCodeGenerator-and-LTOModule-are-f.patch
Type: application/octet-stream
Size: 2866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141111/71680a7d/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-libLTO-Allow-linker-to-choose-context-of-modules-and.patch
Type: application/octet-stream
Size: 5970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141111/71680a7d/attachment-0004.obj>
More information about the llvm-commits
mailing list