IRCompileLayer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IRCompileLayer.h -- Eagerly compile IR for JIT -----------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Contains the definition for a basic, eagerly compiling layer of the JIT.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
  18. #define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
  19. #include "llvm/ADT/STLExtras.h"
  20. #include "llvm/ExecutionEngine/JITSymbol.h"
  21. #include "llvm/ExecutionEngine/Orc/Layer.h"
  22. #include "llvm/Support/Error.h"
  23. #include "llvm/Support/MemoryBuffer.h"
  24. #include <functional>
  25. #include <memory>
  26. #include <mutex>
  27. namespace llvm {
  28. class Module;
  29. namespace orc {
  30. class IRCompileLayer : public IRLayer {
  31. public:
  32. class IRCompiler {
  33. public:
  34. IRCompiler(IRSymbolMapper::ManglingOptions MO) : MO(std::move(MO)) {}
  35. virtual ~IRCompiler();
  36. const IRSymbolMapper::ManglingOptions &getManglingOptions() const {
  37. return MO;
  38. }
  39. virtual Expected<std::unique_ptr<MemoryBuffer>> operator()(Module &M) = 0;
  40. protected:
  41. IRSymbolMapper::ManglingOptions &manglingOptions() { return MO; }
  42. private:
  43. IRSymbolMapper::ManglingOptions MO;
  44. };
  45. using NotifyCompiledFunction = std::function<void(
  46. MaterializationResponsibility &R, ThreadSafeModule TSM)>;
  47. IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
  48. std::unique_ptr<IRCompiler> Compile);
  49. IRCompiler &getCompiler() { return *Compile; }
  50. void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
  51. void emit(std::unique_ptr<MaterializationResponsibility> R,
  52. ThreadSafeModule TSM) override;
  53. private:
  54. mutable std::mutex IRLayerMutex;
  55. ObjectLayer &BaseLayer;
  56. std::unique_ptr<IRCompiler> Compile;
  57. const IRSymbolMapper::ManglingOptions *ManglingOpts;
  58. NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();
  59. };
  60. } // end namespace orc
  61. } // end namespace llvm
  62. #endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
  63. #ifdef __GNUC__
  64. #pragma GCC diagnostic pop
  65. #endif