mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
a397416183
This is a first step towards consistently using the term 'executor' for the process that executes JIT'd code. I've opted for 'executor' as the preferred term over 'target' as target is already heavily overloaded ("the target machine for the executor" is much clearer than "the target machine for the target").
104 lines
3.4 KiB
C++
104 lines
3.4 KiB
C++
//===- KaleidoscopeJIT.h - A simple JIT for Kaleidoscope --------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Contains a simple JIT definition for use in the kaleidoscope tutorials.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
|
|
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/ExecutionEngine/JITSymbol.h"
|
|
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
|
|
#include "llvm/ExecutionEngine/Orc/Core.h"
|
|
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
|
|
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
|
|
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
|
|
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
|
|
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
|
|
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
|
#include "llvm/IR/DataLayout.h"
|
|
#include "llvm/IR/LLVMContext.h"
|
|
#include <memory>
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
|
|
class KaleidoscopeJIT {
|
|
private:
|
|
std::unique_ptr<ExecutorProcessControl> EPC;
|
|
std::unique_ptr<ExecutionSession> ES;
|
|
|
|
DataLayout DL;
|
|
MangleAndInterner Mangle;
|
|
|
|
RTDyldObjectLinkingLayer ObjectLayer;
|
|
IRCompileLayer CompileLayer;
|
|
|
|
JITDylib &MainJD;
|
|
|
|
public:
|
|
KaleidoscopeJIT(std::unique_ptr<ExecutorProcessControl> EPC,
|
|
std::unique_ptr<ExecutionSession> ES,
|
|
JITTargetMachineBuilder JTMB, DataLayout DL)
|
|
: EPC(std::move(EPC)), ES(std::move(ES)), DL(std::move(DL)),
|
|
Mangle(*this->ES, this->DL),
|
|
ObjectLayer(*this->ES,
|
|
[]() { return std::make_unique<SectionMemoryManager>(); }),
|
|
CompileLayer(*this->ES, ObjectLayer,
|
|
std::make_unique<ConcurrentIRCompiler>(std::move(JTMB))),
|
|
MainJD(this->ES->createBareJITDylib("<main>")) {
|
|
MainJD.addGenerator(
|
|
cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess(
|
|
DL.getGlobalPrefix())));
|
|
}
|
|
|
|
~KaleidoscopeJIT() {
|
|
if (auto Err = ES->endSession())
|
|
ES->reportError(std::move(Err));
|
|
}
|
|
|
|
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
|
|
auto SSP = std::make_shared<SymbolStringPool>();
|
|
auto EPC = SelfExecutorProcessControl::Create(SSP);
|
|
if (!EPC)
|
|
return EPC.takeError();
|
|
|
|
auto ES = std::make_unique<ExecutionSession>(std::move(SSP));
|
|
|
|
JITTargetMachineBuilder JTMB((*EPC)->getTargetTriple());
|
|
|
|
auto DL = JTMB.getDefaultDataLayoutForTarget();
|
|
if (!DL)
|
|
return DL.takeError();
|
|
|
|
return std::make_unique<KaleidoscopeJIT>(std::move(*EPC), std::move(ES),
|
|
std::move(JTMB), std::move(*DL));
|
|
}
|
|
|
|
const DataLayout &getDataLayout() const { return DL; }
|
|
|
|
JITDylib &getMainJITDylib() { return MainJD; }
|
|
|
|
Error addModule(ThreadSafeModule TSM, ResourceTrackerSP RT = nullptr) {
|
|
if (!RT)
|
|
RT = MainJD.getDefaultResourceTracker();
|
|
return CompileLayer.add(RT, std::move(TSM));
|
|
}
|
|
|
|
Expected<JITEvaluatedSymbol> lookup(StringRef Name) {
|
|
return ES->lookup({&MainJD}, Mangle(Name.str()));
|
|
}
|
|
};
|
|
|
|
} // end namespace orc
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
|