Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- CompileOnDemandLayer.h - Compile each function on demand -*- 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 // JIT layer for breaking up modules and inserting callbacks to allow
0010 // individual functions to be compiled on demand.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_EXECUTIONENGINE_ORC_COMPILEONDEMANDLAYER_H
0015 #define LLVM_EXECUTIONENGINE_ORC_COMPILEONDEMANDLAYER_H
0016 
0017 #include "llvm/ADT/APInt.h"
0018 #include "llvm/ADT/STLExtras.h"
0019 #include "llvm/ADT/StringRef.h"
0020 #include "llvm/ExecutionEngine/JITSymbol.h"
0021 #include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
0022 #include "llvm/ExecutionEngine/Orc/Layer.h"
0023 #include "llvm/ExecutionEngine/Orc/LazyReexports.h"
0024 #include "llvm/ExecutionEngine/Orc/Shared/OrcError.h"
0025 #include "llvm/ExecutionEngine/Orc/Speculation.h"
0026 #include "llvm/ExecutionEngine/RuntimeDyld.h"
0027 #include "llvm/IR/Attributes.h"
0028 #include "llvm/IR/Constant.h"
0029 #include "llvm/IR/Constants.h"
0030 #include "llvm/IR/DataLayout.h"
0031 #include "llvm/IR/Function.h"
0032 #include "llvm/IR/GlobalAlias.h"
0033 #include "llvm/IR/GlobalValue.h"
0034 #include "llvm/IR/GlobalVariable.h"
0035 #include "llvm/IR/Instruction.h"
0036 #include "llvm/IR/Mangler.h"
0037 #include "llvm/IR/Module.h"
0038 #include "llvm/IR/Type.h"
0039 #include "llvm/Support/Casting.h"
0040 #include "llvm/Support/raw_ostream.h"
0041 #include "llvm/Transforms/Utils/ValueMapper.h"
0042 #include <algorithm>
0043 #include <cassert>
0044 #include <functional>
0045 #include <iterator>
0046 #include <list>
0047 #include <memory>
0048 #include <optional>
0049 #include <set>
0050 #include <utility>
0051 
0052 namespace llvm {
0053 namespace orc {
0054 
0055 class CompileOnDemandLayer : public IRLayer {
0056 public:
0057   /// Builder for IndirectStubsManagers.
0058   using IndirectStubsManagerBuilder =
0059       std::function<std::unique_ptr<IndirectStubsManager>()>;
0060 
0061   /// Construct a CompileOnDemandLayer.
0062   CompileOnDemandLayer(ExecutionSession &ES, IRLayer &BaseLayer,
0063                        LazyCallThroughManager &LCTMgr,
0064                        IndirectStubsManagerBuilder BuildIndirectStubsManager);
0065   /// Sets the ImplSymbolMap
0066   void setImplMap(ImplSymbolMap *Imp);
0067 
0068   /// Emits the given module. This should not be called by clients: it will be
0069   /// called by the JIT when a definition added via the add method is requested.
0070   void emit(std::unique_ptr<MaterializationResponsibility> R,
0071             ThreadSafeModule TSM) override;
0072 
0073 private:
0074   struct PerDylibResources {
0075   public:
0076     PerDylibResources(JITDylib &ImplD,
0077                       std::unique_ptr<IndirectStubsManager> ISMgr)
0078         : ImplD(ImplD), ISMgr(std::move(ISMgr)) {}
0079     JITDylib &getImplDylib() { return ImplD; }
0080     IndirectStubsManager &getISManager() { return *ISMgr; }
0081 
0082   private:
0083     JITDylib &ImplD;
0084     std::unique_ptr<IndirectStubsManager> ISMgr;
0085   };
0086 
0087   using PerDylibResourcesMap = std::map<const JITDylib *, PerDylibResources>;
0088 
0089   PerDylibResources &getPerDylibResources(JITDylib &TargetD);
0090 
0091   mutable std::mutex CODLayerMutex;
0092 
0093   IRLayer &BaseLayer;
0094   LazyCallThroughManager &LCTMgr;
0095   IndirectStubsManagerBuilder BuildIndirectStubsManager;
0096   PerDylibResourcesMap DylibResources;
0097   ImplSymbolMap *AliaseeImpls = nullptr;
0098 };
0099 
0100 } // end namespace orc
0101 } // end namespace llvm
0102 
0103 #endif // LLVM_EXECUTIONENGINE_ORC_COMPILEONDEMANDLAYER_H