llvm.org GIT mirror llvm / a794030
[ORC] Add an Error return to the JITCompileCallbackManager::grow method. Calling grow may result in an error if, for example, this is a callback manager for a remote target. We need to be able to return this error to the callee. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312429 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
7 changed file(s) with 52 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
134134 Error addFunctionAST(std::unique_ptr FnAST) {
135135 // Create a CompileCallback - this is the re-entry point into the compiler
136136 // for functions that haven't been compiled yet.
137 auto CCInfo = CompileCallbackMgr->getCompileCallback();
137 auto CCInfo = cantFail(CompileCallbackMgr->getCompileCallback());
138138
139139 // Create an indirect stub. This serves as the functions "canonical
140140 // definition" - an unchanging (constant address) entry point to the
163163 Error addFunctionAST(std::unique_ptr FnAST) {
164164 // Create a CompileCallback - this is the re-entry point into the compiler
165165 // for functions that haven't been compiled yet.
166 auto CCInfo = CompileCallbackMgr->getCompileCallback();
166 auto CCInfo = cantFail(CompileCallbackMgr->getCompileCallback());
167167
168168 // Create an indirect stub. This serves as the functions "canonical
169169 // definition" - an unchanging (constant address) entry point to the
348348 // Create a callback, associate it with the stub for the function,
349349 // and set the compile action to compile the partition containing the
350350 // function.
351 auto CCInfo = CompileCallbackMgr.getCompileCallback();
352 StubInits[MangledName] =
353 std::make_pair(CCInfo.getAddress(),
354 JITSymbolFlags::fromGlobalValue(F));
355 CCInfo.setCompileAction([this, &LD, LMId, &F]() -> JITTargetAddress {
356 if (auto FnImplAddrOrErr = this->extractAndCompile(LD, LMId, F))
357 return *FnImplAddrOrErr;
358 else {
359 // FIXME: Report error, return to 'abort' or something similar.
360 consumeError(FnImplAddrOrErr.takeError());
361 return 0;
362 }
363 });
351 if (auto CCInfoOrErr = CompileCallbackMgr.getCompileCallback()) {
352 auto &CCInfo = *CCInfoOrErr;
353 StubInits[MangledName] =
354 std::make_pair(CCInfo.getAddress(),
355 JITSymbolFlags::fromGlobalValue(F));
356 CCInfo.setCompileAction([this, &LD, LMId, &F]() -> JITTargetAddress {
357 if (auto FnImplAddrOrErr = this->extractAndCompile(LD, LMId, F))
358 return *FnImplAddrOrErr;
359 else {
360 // FIXME: Report error, return to 'abort' or something similar.
361 consumeError(FnImplAddrOrErr.takeError());
362 return 0;
363 }
364 });
365 } else
366 return CCInfoOrErr.takeError();
364367 }
365368
366369 if (auto Err = LD.StubsMgr->createStubs(StubInits))
104104 }
105105
106106 /// @brief Reserve a compile callback.
107 CompileCallbackInfo getCompileCallback() {
108 JITTargetAddress TrampolineAddr = getAvailableTrampolineAddr();
109 auto &Compile = this->ActiveTrampolines[TrampolineAddr];
110 return CompileCallbackInfo(TrampolineAddr, Compile);
107 Expected getCompileCallback() {
108 if (auto TrampolineAddrOrErr = getAvailableTrampolineAddr()) {
109 const auto &TrampolineAddr = *TrampolineAddrOrErr;
110 auto &Compile = this->ActiveTrampolines[TrampolineAddr];
111 return CompileCallbackInfo(TrampolineAddr, Compile);
112 } else
113 return TrampolineAddrOrErr.takeError();
111114 }
112115
113116 /// @brief Get a CompileCallbackInfo for an existing callback.
137140 std::vector AvailableTrampolines;
138141
139142 private:
140 JITTargetAddress getAvailableTrampolineAddr() {
143 Expected getAvailableTrampolineAddr() {
141144 if (this->AvailableTrampolines.empty())
142 grow();
145 if (auto Err = grow())
146 return std::move(Err);
143147 assert(!this->AvailableTrampolines.empty() &&
144148 "Failed to grow available trampolines.");
145149 JITTargetAddress TrampolineAddr = this->AvailableTrampolines.back();
148152 }
149153
150154 // Create new trampolines - to be implemented in subclasses.
151 virtual void grow() = 0;
155 virtual Error grow() = 0;
152156
153157 virtual void anchor();
154158 };
187191 reinterpret_cast(TrampolineId)));
188192 }
189193
190 void grow() override {
194 Error grow() override {
191195 assert(this->AvailableTrampolines.empty() && "Growing prematurely?");
192196
193197 std::error_code EC;
195199 sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
196200 sys::Process::getPageSize(), nullptr,
197201 sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
198 assert(!EC && "Failed to allocate trampoline block");
202 if (EC)
203 return errorCodeToError(EC);
199204
200205 unsigned NumTrampolines =
201206 (sys::Process::getPageSize() - TargetT::PointerSize) /
210215 static_cast(reinterpret_cast(
211216 TrampolineMem + (I * TargetT::TrampolineSize))));
212217
213 EC = sys::Memory::protectMappedMemory(TrampolineBlock.getMemoryBlock(),
214 sys::Memory::MF_READ |
215 sys::Memory::MF_EXEC);
216 assert(!EC && "Failed to mprotect trampoline block");
218 if (auto EC = sys::Memory::protectMappedMemory(
219 TrampolineBlock.getMemoryBlock(),
220 sys::Memory::MF_READ | sys::Memory::MF_EXEC))
221 return errorCodeToError(EC);
217222
218223 TrampolineBlocks.push_back(std::move(TrampolineBlock));
224 return Error::success();
219225 }
220226
221227 sys::OwningMemoryBlock ResolverBlock;
542542 : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {}
543543
544544 private:
545 void grow() override {
545 Error grow() override {
546546 JITTargetAddress BlockAddr = 0;
547547 uint32_t NumTrampolines = 0;
548548 if (auto TrampolineInfoOrErr = Remote.emitTrampolineBlock())
549549 std::tie(BlockAddr, NumTrampolines) = *TrampolineInfoOrErr;
550 else {
551 // FIXME: Return error.
552 llvm_unreachable("Failed to create trampolines");
553 }
550 else
551 return TrampolineInfoOrErr.takeError();
554552
555553 uint32_t TrampolineSize = Remote.getTrampolineSize();
556554 for (unsigned I = 0; I < NumTrampolines; ++I)
557555 this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
556
557 return Error::success();
558558 }
559559
560560 OrcRemoteTargetClient &Remote;
144144 createLazyCompileCallback(JITTargetAddress &RetAddr,
145145 LLVMOrcLazyCompileCallbackFn Callback,
146146 void *CallbackCtx) {
147 auto CCInfo = CCMgr->getCompileCallback();
148 CCInfo.setCompileAction([=]() -> JITTargetAddress {
149 return Callback(wrap(this), CallbackCtx);
150 });
151 RetAddr = CCInfo.getAddress();
152 return LLVMOrcErrSuccess;
147 if (auto CCInfoOrErr = CCMgr->getCompileCallback()) {
148 auto &CCInfo = *CCInfoOrErr;
149 CCInfo.setCompileAction([=]() -> JITTargetAddress {
150 return Callback(wrap(this), CallbackCtx);
151 });
152 RetAddr = CCInfo.getAddress();
153 return LLVMOrcErrSuccess;
154 } else
155 return mapError(CCInfoOrErr.takeError());
153156 }
154157
155158 LLVMOrcErrorCode createIndirectStub(StringRef StubName,
2020 DummyCallbackManager() : JITCompileCallbackManager(0) {}
2121
2222 public:
23 void grow() override { llvm_unreachable("not implemented"); }
23 Error grow() override { llvm_unreachable("not implemented"); }
2424 };
2525
2626 class DummyStubsManager : public orc::IndirectStubsManager {