diff --git a/include/xo/jit/KaleidoscopeJit.hpp b/include/xo/jit/Jit.hpp similarity index 76% rename from include/xo/jit/KaleidoscopeJit.hpp rename to include/xo/jit/Jit.hpp index f3d2ebcd..fa188245 100644 --- a/include/xo/jit/KaleidoscopeJit.hpp +++ b/include/xo/jit/Jit.hpp @@ -1,14 +1,6 @@ -//===- 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. -// -//===----------------------------------------------------------------------===// +/** @file Jit.hpp **/ + +/** Adapted from LLVM KaleidoscopeJIT.h **/ #pragma once @@ -30,7 +22,7 @@ namespace xo { namespace jit { - class KaleidoscopeJIT { + class Jit { private: using StringRef = llvm::StringRef; using SectionMemoryManager = llvm::SectionMemoryManager; @@ -61,14 +53,16 @@ namespace xo { * (? specialized for jit in running process ?) **/ RTDyldObjectLinkingLayer object_layer_; + /** compilation layer (sits above linking layer) **/ IRCompileLayer compile_layer_; - JITDylib &MainJD; + /** destination library **/ + JITDylib & dest_dynamic_lib_; //MainJD; public: - KaleidoscopeJIT(std::unique_ptr xsession, - JITTargetMachineBuilder jtmb, - DataLayout data_layout_) + Jit(std::unique_ptr xsession, + JITTargetMachineBuilder jtmb, + DataLayout data_layout_) : xsession_{std::move(xsession)}, data_layout_(std::move(data_layout_)), mangler_(*this->xsession_, this->data_layout_), @@ -76,9 +70,9 @@ namespace xo { []() { return std::make_unique(); }), compile_layer_(*this->xsession_, object_layer_, std::make_unique(std::move(jtmb))), - MainJD(this->xsession_->createBareJITDylib("
")) + dest_dynamic_lib_(this->xsession_->createBareJITDylib("
")) { - MainJD.addGenerator( + dest_dynamic_lib_.addGenerator( cantFail(DynamicLibrarySearchGenerator::GetForCurrentProcess( data_layout_.getGlobalPrefix()))); if (jtmb.getTargetTriple().isOSBinFormatCOFF()) { @@ -87,12 +81,12 @@ namespace xo { } } - ~KaleidoscopeJIT() { + ~Jit() { if (auto Err = this->xsession_->endSession()) this->xsession_->reportError(std::move(Err)); } - static llvm::Expected> Create() { + static llvm::Expected> Create() { auto EPC = SelfExecutorProcessControl::Create(); if (!EPC) return EPC.takeError(); @@ -106,9 +100,9 @@ namespace xo { if (!data_layout) return data_layout.takeError(); - return std::make_unique(std::move(xsession), - std::move(jtmb), - std::move(*data_layout)); + return std::make_unique(std::move(xsession), + std::move(jtmb), + std::move(*data_layout)); } const std::string & target_triple() const { @@ -117,19 +111,19 @@ namespace xo { const DataLayout & data_layout() const { return data_layout_; } - JITDylib &getMainJITDylib() { return MainJD; } + JITDylib &getMainJITDylib() { return dest_dynamic_lib_; } llvm::Error addModule(ThreadSafeModule ts_module, ResourceTrackerSP RT = nullptr) { if (!RT) - RT = MainJD.getDefaultResourceTracker(); + RT = dest_dynamic_lib_.getDefaultResourceTracker(); return compile_layer_.add(RT, std::move(ts_module)); } llvm::Expected lookup(StringRef name) { - return this->xsession_->lookup({&MainJD}, + return this->xsession_->lookup({&dest_dynamic_lib_}, this->mangler_(name.str())); } @@ -137,7 +131,9 @@ namespace xo { void dump_execution_session() { this->xsession_->dump(llvm::errs()); } - }; + }; /*Jit*/ - } // end namespace jit -} // end namespace xo + } /*namespace jit&*/ +} /*namespace xo*/ + +/** end Jit.hpp **/ diff --git a/include/xo/jit/MachPipeline.hpp b/include/xo/jit/MachPipeline.hpp index 71df826f..834390c3 100644 --- a/include/xo/jit/MachPipeline.hpp +++ b/include/xo/jit/MachPipeline.hpp @@ -10,6 +10,8 @@ #include "xo/refcnt/Refcounted.hpp" #include "IrPipeline.hpp" #include "LlvmContext.hpp" +#include "Jit.hpp" + #include "xo/expression/Expression.hpp" #include "xo/expression/ConstantInterface.hpp" #include "xo/expression/PrimitiveInterface.hpp" @@ -17,7 +19,6 @@ #include "xo/expression/Lambda.hpp" #include "xo/expression/Variable.hpp" -#include "KaleidoscopeJit.hpp" /* stuff from kaleidoscope.cpp */ #include "llvm/ADT/APFloat.h" @@ -96,7 +97,7 @@ namespace xo { virtual std::string display_string() const; private: - MachPipeline(std::unique_ptr kal_jit); + MachPipeline(std::unique_ptr jit); /* iniitialize native builder (i.e. for platform we're running on) */ static void init_once(); @@ -107,7 +108,7 @@ namespace xo { private: // ----- this part adapted from LLVM 19.0 KaleidoscopeJIT.hpp [wip] ----- - std::unique_ptr kal_jit_; + std::unique_ptr kal_jit_; // ----- this part adapted from kaleidoscope.cpp ----- diff --git a/src/jit/MachPipeline.cpp b/src/jit/MachPipeline.cpp index 4acbbf3c..54ab95f8 100644 --- a/src/jit/MachPipeline.cpp +++ b/src/jit/MachPipeline.cpp @@ -45,7 +45,7 @@ namespace xo { static llvm::ExitOnError llvm_exit_on_err; - std::unique_ptr kal_jit = llvm_exit_on_err(KaleidoscopeJIT::Create()); + std::unique_ptr kal_jit = llvm_exit_on_err(Jit::Create()); return std::unique_ptr(new MachPipeline(std::move(kal_jit) )); @@ -60,7 +60,7 @@ namespace xo { return jit.release(); } /*make*/ - MachPipeline::MachPipeline(std::unique_ptr kal_jit) + MachPipeline::MachPipeline(std::unique_ptr kal_jit) : kal_jit_{std::move(kal_jit)} { this->recreate_llvm_ir_pipeline();