[JITLink] Add a shouldAddDefaultPasses predicate to JITLinkerBase.

This allows JITLinkerBase implementations to check whether default passes
should be added. The ELF_x86_64 backend is updated to check this predicate
before installing the getOrCreateGOTSymbol pass.

This is an alternative solution to https://reviews.llvm.org/D158909.
This commit is contained in:
Lang Hames
2023-08-25 22:03:14 -07:00
parent c95f23b884
commit 265d6bda95
2 changed files with 11 additions and 2 deletions

View File

@@ -242,8 +242,10 @@ public:
std::unique_ptr<LinkGraph> G,
PassConfiguration PassConfig)
: JITLinker(std::move(Ctx), std::move(G), std::move(PassConfig)) {
getPassConfig().PostAllocationPasses.push_back(
[this](LinkGraph &G) { return getOrCreateGOTSymbol(G); });
if (shouldAddDefaultTargetPasses(G->getTargetTriple()))
getPassConfig().PostAllocationPasses.push_back(
[this](LinkGraph &G) { return getOrCreateGOTSymbol(G); });
}
private:

View File

@@ -43,6 +43,13 @@ protected:
using AllocResult = Expected<std::unique_ptr<InFlightAlloc>>;
using FinalizeResult = Expected<JITLinkMemoryManager::FinalizedAlloc>;
// Returns true if the context says that the linker should add default
// passes. This can be used by JITLinkerBase implementations when deciding
// whether they should add default passes.
bool shouldAddDefaultTargetPasses(const Triple &TT) {
return Ctx->shouldAddDefaultTargetPasses(TT);
}
// Returns the PassConfiguration for this instance. This can be used by
// JITLinkerBase implementations to add late passes that reference their
// own data structures (e.g. for ELF implementations to locate / construct