Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:53

0001 //===- IRCompileLayer.h -- Eagerly compile IR for JIT -----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Contains the definition for a basic, eagerly compiling layer of the JIT.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
0014 #define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
0015 
0016 #include "llvm/ADT/STLExtras.h"
0017 #include "llvm/ExecutionEngine/JITSymbol.h"
0018 #include "llvm/ExecutionEngine/Orc/Layer.h"
0019 #include "llvm/Support/Error.h"
0020 #include "llvm/Support/MemoryBuffer.h"
0021 #include <functional>
0022 #include <memory>
0023 #include <mutex>
0024 
0025 namespace llvm {
0026 
0027 class Module;
0028 
0029 namespace orc {
0030 
0031 class IRCompileLayer : public IRLayer {
0032 public:
0033   class IRCompiler {
0034   public:
0035     IRCompiler(IRSymbolMapper::ManglingOptions MO) : MO(std::move(MO)) {}
0036     virtual ~IRCompiler();
0037     const IRSymbolMapper::ManglingOptions &getManglingOptions() const {
0038       return MO;
0039     }
0040     virtual Expected<std::unique_ptr<MemoryBuffer>> operator()(Module &M) = 0;
0041 
0042   protected:
0043     IRSymbolMapper::ManglingOptions &manglingOptions() { return MO; }
0044 
0045   private:
0046     IRSymbolMapper::ManglingOptions MO;
0047   };
0048 
0049   using NotifyCompiledFunction = std::function<void(
0050       MaterializationResponsibility &R, ThreadSafeModule TSM)>;
0051 
0052   IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
0053                  std::unique_ptr<IRCompiler> Compile);
0054 
0055   IRCompiler &getCompiler() { return *Compile; }
0056 
0057   void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
0058 
0059   void emit(std::unique_ptr<MaterializationResponsibility> R,
0060             ThreadSafeModule TSM) override;
0061 
0062 private:
0063   mutable std::mutex IRLayerMutex;
0064   ObjectLayer &BaseLayer;
0065   std::unique_ptr<IRCompiler> Compile;
0066   const IRSymbolMapper::ManglingOptions *ManglingOpts;
0067   NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();
0068 };
0069 
0070 } // end namespace orc
0071 } // end namespace llvm
0072 
0073 #endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H