-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[ORC] Implement basic reoptimization. #67050
Conversation
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.
Just reviewing the RedirectionManager
interface and implementation patch for now. I have some minor comments, but otherwise this is looking amazing -- thank you very much @sunho!
for (auto [K, V] : InitialDests) { | ||
Flags[K] = V.getFlags(); | ||
} |
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.
No braces needed for single-line loops. :)
if (auto Err = JD.define(std::make_unique<RedirectableMaterializationUnit>( | ||
*this, InitialDests), | ||
RT)) | ||
return Err; | ||
|
||
return Error::success(); |
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.
This could just be:
return JD.define(std::make_unique<RedirectableMaterializationUnit>(*this, InitialDests), RT);
R->failMaterialization(); | ||
return; | ||
} | ||
dbgs() << *K << "\n"; |
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.
Stray debugging output?
if (auto Err = R->replace(absoluteSymbols(NewSymbolDefs))) { | ||
ES.reportError(std::move(Err)); | ||
R->failMaterialization(); | ||
return; | ||
} | ||
|
||
if (auto Err = redirectInner(TargetJD, InitialDests)) { | ||
ES.reportError(std::move(Err)); | ||
R->failMaterialization(); | ||
return; | ||
} |
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.
I think the call to redirectInner
should precede the call to replace: As soon as replace runs anyone waiting on NewSymbolDefs
will be notified that those symbols are available, but they're not actually usable until the call to redirectInner
, right?
You should also return the stubs to the pool on all three of the failure paths (or add a FIXME that we should do that in the future).
if (auto Err = ES.getExecutorProcessControl().getMemoryAccess().writePointers( | ||
PtrWrites)) | ||
return Err; | ||
return Error::success(); |
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.
This could just be:
return ES.getExecutorProcessControl().getMemoryAccess().writePointers(PtrWrites);
SymbolLookupSet LookupSymbols; | ||
DenseMap<SymbolStringPtr, ExecutorSymbolDef *> NewDefsMap; | ||
|
||
Triple TT = ES.getTargetTriple(); | ||
auto G = std::make_unique<jitlink::LinkGraph>( | ||
"<INDIRECT STUBS>", TT, TT.isArch64Bit() ? 8 : 4, | ||
TT.isLittleEndian() ? support::little : support::big, | ||
jitlink::getGenericEdgeKindName); | ||
auto &PointerSection = | ||
G->createSection(StubPtrTableName, MemProt::Write | MemProt::Read); | ||
auto &StubsSection = | ||
G->createSection(JumpStubTableName, MemProt::Exec | MemProt::Read); | ||
|
||
for (size_t I = OldSize; I < NewSize; I++) { | ||
auto Pointer = AnonymousPtrCreator(*G, PointerSection, nullptr, 0); | ||
if (auto Err = Pointer.takeError()) | ||
return Err; | ||
|
||
StringRef PtrSymName = StubPtrSymbolName(I); | ||
Pointer->setName(PtrSymName); | ||
Pointer->setScope(jitlink::Scope::Default); | ||
LookupSymbols.add(ES.intern(PtrSymName)); | ||
NewDefsMap[ES.intern(PtrSymName)] = &StubPointers[I]; | ||
|
||
auto Stub = PtrJumpStubCreator(*G, StubsSection, *Pointer); | ||
if (auto Err = Stub.takeError()) | ||
return Err; | ||
|
||
StringRef JumpStubSymName = JumpStubSymbolName(I); | ||
Stub->setName(JumpStubSymName); | ||
Stub->setScope(jitlink::Scope::Default); | ||
LookupSymbols.add(ES.intern(JumpStubSymName)); | ||
NewDefsMap[ES.intern(JumpStubSymName)] = &JumpStubs[I]; | ||
} |
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.
We only need one anchor symbol to trigger emission of the graph. Eventually I think this could be sped up by emitting:
.section <JumpStubTableName>
__<JumpStubTableName>.<++Idx>:
... stubs ...
.section <StubPtrTableName>
__<StubPtrTableName>.<Idx>:
... ptrs ...
Then looking up __JumpStubTableName.<Idx>
and __StubPtrTableName.<Idx>
and using the stub and pointer sizes to stride through the resulting addresses.
I don't think this change needs to happen before the commit though -- you could add a FIXME and this can be handled in the future.
namespace llvm { | ||
namespace orc { | ||
|
||
class IRPartitionLayer : public IRLayer { |
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.
It'd be good to add a class comment explaining the layer's behavior. (I know the file comment covers this, but people looking up the type docs may not see that).
llvm/include/llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h
Outdated
Show resolved
Hide resolved
#ifndef LLVM_EXECUTIONENGINE_ORC_JITLINKREDIRECABLEMANAGER_H | ||
#define LLVM_EXECUTIONENGINE_ORC_JITLINKREDIRECABLEMANAGER_H |
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.
Include guard should be LLVM_EXECUTIONENGINE_ORC_JITLINKREDIRECABLESYMBOLMANAGER_H
.
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.
Minor comments aside: LGTM!
#ifndef LLVM_EXECUTIONENGINE_ORC_REOPTLAYER_H | ||
#define LLVM_EXECUTIONENGINE_ORC_REOPTLAYER_H |
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.
Include guard should be LLVM_EXECUTIONENGINE_ORC_REOPTIMIZELAYER_H
to match the file name.
namespace llvm { | ||
namespace orc { | ||
|
||
using ReOptMaterializationUnitID = uint64_t; |
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.
Use of this type seems to be contained within the ReOptimizeLayer
-- could it be a member of that class?
This reverts commit 0d288e5. Breaks the build.
I've reverted this to fix build failures -- it looks like this has been implemented against a very old LLVM version. |
Thanks for reverting the commit. Let me fix build error shortly. |
/// Registers reoptimize runtime dispatch handlers to given PlatformJD. The | ||
/// reoptimization request will not be handled if dispatch handler is not | ||
/// registered by using this function. | ||
Error reigsterRuntimeFunctions(JITDylib &PlatformJD); |
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.
Typo: reigsterRuntimeFunctions
-> registerRuntimeFunctions
Hi @sunho, |
@Thrrreeee Oh this has been forgotten. It should be a trivial fix. Let me try to reland it tmr. |
Hi @sunho, |
Hi @sunho, Have you finished this? |
Some build bots are breaking because we are running runtime JIT execution unit tests on unsupported targets. Investigating this issue right now. |
Relanded on 188ede2 |
Failing at https://lab.llvm.org/buildbot/#/builders/161/builds/2692. Probably wise to disable to test on the COFF-ARM64. |
No description provided.