IRCompileLayer.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <memory>
  25. #include <string>
  26. namespace llvm {
  27. class Module;
  28. namespace orc {
  29. class IRCompileLayer : public IRLayer {
  30. public:
  31. class IRCompiler {
  32. public:
  33. IRCompiler(IRSymbolMapper::ManglingOptions MO) : MO(std::move(MO)) {}
  34. virtual ~IRCompiler();
  35. const IRSymbolMapper::ManglingOptions &getManglingOptions() const {
  36. return MO;
  37. }
  38. virtual Expected<std::unique_ptr<MemoryBuffer>> operator()(Module &M) = 0;
  39. protected:
  40. IRSymbolMapper::ManglingOptions &manglingOptions() { return MO; }
  41. private:
  42. IRSymbolMapper::ManglingOptions MO;
  43. };
  44. using NotifyCompiledFunction = std::function<void(
  45. MaterializationResponsibility &R, ThreadSafeModule TSM)>;
  46. IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
  47. std::unique_ptr<IRCompiler> Compile);
  48. IRCompiler &getCompiler() { return *Compile; }
  49. void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
  50. void emit(std::unique_ptr<MaterializationResponsibility> R,
  51. ThreadSafeModule TSM) override;
  52. private:
  53. mutable std::mutex IRLayerMutex;
  54. ObjectLayer &BaseLayer;
  55. std::unique_ptr<IRCompiler> Compile;
  56. const IRSymbolMapper::ManglingOptions *ManglingOpts;
  57. NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();
  58. };
  59. } // end namespace orc
  60. } // end namespace llvm
  61. #endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILINGLAYER_H
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif