File indexing completed on 2026-05-10 08:43:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H
0014 #define LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H
0015
0016 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
0017 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
0018 #include "llvm/ExecutionEngine/Orc/Layer.h"
0019 #include <memory>
0020
0021 namespace llvm {
0022
0023 class MemoryBuffer;
0024 class Module;
0025 class ObjectCache;
0026 class TargetMachine;
0027
0028 namespace orc {
0029
0030 IRSymbolMapper::ManglingOptions
0031 irManglingOptionsFromTargetOptions(const TargetOptions &Opts);
0032
0033
0034
0035
0036 class SimpleCompiler : public IRCompileLayer::IRCompiler {
0037 public:
0038 using CompileResult = std::unique_ptr<MemoryBuffer>;
0039
0040
0041 SimpleCompiler(TargetMachine &TM, ObjectCache *ObjCache = nullptr)
0042 : IRCompiler(irManglingOptionsFromTargetOptions(TM.Options)), TM(TM),
0043 ObjCache(ObjCache) {}
0044
0045
0046 void setObjectCache(ObjectCache *NewCache) { ObjCache = NewCache; }
0047
0048
0049 Expected<CompileResult> operator()(Module &M) override;
0050
0051 private:
0052 IRSymbolMapper::ManglingOptions
0053 manglingOptionsForTargetMachine(const TargetMachine &TM);
0054
0055 CompileResult tryToLoadFromObjectCache(const Module &M);
0056 void notifyObjectCompiled(const Module &M, const MemoryBuffer &ObjBuffer);
0057
0058 TargetMachine &TM;
0059 ObjectCache *ObjCache = nullptr;
0060 };
0061
0062
0063
0064
0065
0066 class TMOwningSimpleCompiler : public SimpleCompiler {
0067 public:
0068 TMOwningSimpleCompiler(std::unique_ptr<TargetMachine> TM,
0069 ObjectCache *ObjCache = nullptr)
0070 : SimpleCompiler(*TM, ObjCache), TM(std::move(TM)) {}
0071
0072 private:
0073
0074
0075 std::shared_ptr<llvm::TargetMachine> TM;
0076 };
0077
0078
0079
0080
0081
0082 class ConcurrentIRCompiler : public IRCompileLayer::IRCompiler {
0083 public:
0084 ConcurrentIRCompiler(JITTargetMachineBuilder JTMB,
0085 ObjectCache *ObjCache = nullptr);
0086
0087 void setObjectCache(ObjectCache *ObjCache) { this->ObjCache = ObjCache; }
0088
0089 Expected<std::unique_ptr<MemoryBuffer>> operator()(Module &M) override;
0090
0091 private:
0092 JITTargetMachineBuilder JTMB;
0093 ObjectCache *ObjCache = nullptr;
0094 };
0095
0096 }
0097
0098 }
0099
0100 #endif