Author: Lang Hames Date: 2021-01-12T11:57:07+11:00 New Revision: ef50c07b1fad368f6a8d326b4f73dd531009dca4
URL: https://github.com/llvm/llvm-project/commit/ef50c07b1fad368f6a8d326b4f73dd531009dca4 DIFF: https://github.com/llvm/llvm-project/commit/ef50c07b1fad368f6a8d326b4f73dd531009dca4.diff LOG: [JITLink] Add a new PostAllocationPasses list. Passes in the new PostAllocationPasses list will run immediately after memory allocation and address assignment for defined symbols, and before JITLinkContext::notifyResolved is called. These passes can set up state associated with the addresses of defined symbols before any query for these addresses completes. Added: Modified: llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h index 72daf76b501a..e8c0e28b83aa 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -1223,11 +1223,27 @@ struct PassConfiguration { /// Notable use cases: Building GOT, stub, and TLV symbols. LinkGraphPassList PostPrunePasses; + /// Post-allocation passes. + /// + /// These passes are called on the graph after memory has been allocated and + /// defined nodes have been assigned their final addresses, but before the + /// context has been notified of these addresses. At this point externals + /// have not been resolved, and symbol content has not yet been copied into + /// working memory. + /// + /// Notable use cases: Setting up data structures associated with addresses + /// of defined symbols (e.g. a mapping of __dso_handle to JITDylib* for the + /// JIT runtime) -- using a PostAllocationPass for this ensures that the + /// data structures are in-place before any query for resolved symbols + /// can complete. + LinkGraphPassList PostAllocationPasses; + /// Pre-fixup passes. /// /// These passes are called on the graph after memory has been allocated, - /// content copied into working memory, and nodes have been assigned their - /// final addresses, but before any fixups have been applied. + /// content copied into working memory, and all nodes (including externals) + /// have been assigned their final addresses, but before any fixups have been + /// applied. /// /// Notable use cases: Late link-time optimizations like GOT and stub /// elimination. diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp index d6ad364add12..7a5e014f223d 100644 --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp @@ -55,6 +55,16 @@ void JITLinkerBase::linkPhase1(std::unique_ptr<JITLinkerBase> Self) { if (auto Err = allocateSegments(Layout)) return Ctx->notifyFailed(std::move(Err)); + LLVM_DEBUG({ + dbgs() << "Link graph \"" << G->getName() + << "\" before post-allocation passes:\n"; + dumpGraph(dbgs()); + }); + + // Run post-allocation passes. + if (auto Err = runPasses(Passes.PostAllocationPasses)) + return Ctx->notifyFailed(std::move(Err)); + // Notify client that the defined symbols have been assigned addresses. LLVM_DEBUG( { dbgs() << "Resolving symbols defined in " << G->getName() << "\n"; }); @@ -110,7 +120,7 @@ void JITLinkerBase::linkPhase2(std::unique_ptr<JITLinkerBase> Self, LLVM_DEBUG({ dbgs() << "Link graph \"" << G->getName() - << "\" before post-allocation passes:\n"; + << "\" before pre-fixup passes:\n"; dumpGraph(dbgs()); }); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits