IRCompileLayer.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
  9. namespace llvm {
  10. namespace orc {
  11. IRCompileLayer::IRCompiler::~IRCompiler() = default;
  12. IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
  13. std::unique_ptr<IRCompiler> Compile)
  14. : IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer),
  15. Compile(std::move(Compile)) {
  16. ManglingOpts = &this->Compile->getManglingOptions();
  17. }
  18. void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
  19. std::lock_guard<std::mutex> Lock(IRLayerMutex);
  20. this->NotifyCompiled = std::move(NotifyCompiled);
  21. }
  22. void IRCompileLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
  23. ThreadSafeModule TSM) {
  24. assert(TSM && "Module must not be null");
  25. if (auto Obj = TSM.withModuleDo(*Compile)) {
  26. {
  27. std::lock_guard<std::mutex> Lock(IRLayerMutex);
  28. if (NotifyCompiled)
  29. NotifyCompiled(*R, std::move(TSM));
  30. else
  31. TSM = ThreadSafeModule();
  32. }
  33. BaseLayer.emit(std::move(R), std::move(*Obj));
  34. } else {
  35. R->failMaterialization();
  36. getExecutionSession().reportError(Obj.takeError());
  37. }
  38. }
  39. } // End namespace orc.
  40. } // End namespace llvm.