From 932e7cd966cc60a7aee91bd6d4c2015f55d28dc8 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 16 Jun 2024 11:49:23 -0400 Subject: [PATCH] xo-jit: refactor: Jit -> MachPipeline --- example/ex1/ex1.cpp | 6 +- include/xo/jit/{Jit.hpp => MachPipeline.hpp} | 18 ++--- src/jit/CMakeLists.txt | 2 +- src/jit/{Jit.cpp => MachPipeline.cpp} | 76 ++++++++++---------- 4 files changed, 51 insertions(+), 51 deletions(-) rename include/xo/jit/{Jit.hpp => MachPipeline.hpp} (92%) rename src/jit/{Jit.cpp => MachPipeline.cpp} (84%) diff --git a/example/ex1/ex1.cpp b/example/ex1/ex1.cpp index 77ee265c..238ba4a3 100644 --- a/example/ex1/ex1.cpp +++ b/example/ex1/ex1.cpp @@ -1,6 +1,6 @@ /** @file ex1.cpp **/ -#include "xo/jit/Jit.hpp" +#include "xo/jit/MachPipeline.hpp" #include "xo/expression/Constant.hpp" #include "xo/expression/Primitive.hpp" #include "xo/expression/Apply.hpp" @@ -35,7 +35,7 @@ int main() { using xo::scope; - using xo::jit::Jit; + using xo::jit::MachPipeline; using xo::ast::make_constant; using xo::ast::make_primitive; using xo::ast::make_apply; @@ -54,7 +54,7 @@ main() { llvm::InitializeNativeTargetAsmParser(); //auto jit = llvm_exit_on_err(Jit::make_aux()); - auto jit = Jit::make(); + auto jit = MachPipeline::make(); //static_assert(std::is_function_v); diff --git a/include/xo/jit/Jit.hpp b/include/xo/jit/MachPipeline.hpp similarity index 92% rename from include/xo/jit/Jit.hpp rename to include/xo/jit/MachPipeline.hpp index 9ef11939..71df826f 100644 --- a/include/xo/jit/Jit.hpp +++ b/include/xo/jit/MachPipeline.hpp @@ -1,4 +1,4 @@ -/** @file Jit.hpp +/** @file MachPipeline.hpp * * Author: Roland Conybeare **/ @@ -45,20 +45,20 @@ namespace xo { namespace jit { - /** @class Jit + /** @class MachPipeline * @brief just-in-time compiler for EGAD * * TODO: make module name a parameter? **/ - class Jit : public ref::Refcount { + class MachPipeline : public ref::Refcount { public: using Expression = xo::ast::Expression; //using ConstantInterface = xo::ast::ConstantInterface; public: /* tracking KaleidoscopeJIT::Create() here.. */ - static llvm::Expected> make_aux(); - static xo::ref::rp make(); + static llvm::Expected> make_aux(); + static xo::ref::rp make(); // ----- module access ----- @@ -96,7 +96,7 @@ namespace xo { virtual std::string display_string() const; private: - Jit(std::unique_ptr kal_jit); + MachPipeline(std::unique_ptr kal_jit); /* iniitialize native builder (i.e. for platform we're running on) */ static void init_once(); @@ -146,10 +146,10 @@ namespace xo { **/ std::map nested_env_; - }; /*Jit*/ + }; /*MachPipeline*/ inline std::ostream & - operator<<(std::ostream & os, const Jit & x) { + operator<<(std::ostream & os, const MachPipeline & x) { x.display(os); return os; } @@ -157,4 +157,4 @@ namespace xo { } /*namespace xo*/ -/** end Jit.hpp **/ +/** end MachPipeline.hpp **/ diff --git a/src/jit/CMakeLists.txt b/src/jit/CMakeLists.txt index 018ecb0e..88b9d2da 100644 --- a/src/jit/CMakeLists.txt +++ b/src/jit/CMakeLists.txt @@ -4,7 +4,7 @@ set(SELF_LIB xo_jit) set(SELF_SRCS LlvmContext.cpp IrPipeline.cpp - Jit.cpp + MachPipeline.cpp ) xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) diff --git a/src/jit/Jit.cpp b/src/jit/MachPipeline.cpp similarity index 84% rename from src/jit/Jit.cpp rename to src/jit/MachPipeline.cpp index f1e00828..4acbbf3c 100644 --- a/src/jit/Jit.cpp +++ b/src/jit/MachPipeline.cpp @@ -1,6 +1,6 @@ -/* @file Jit.cpp */ +/* @file MachPipeline.cpp */ -#include "Jit.hpp" +#include "MachPipeline.hpp" namespace xo { using xo::ast::exprtype; @@ -16,7 +16,7 @@ namespace xo { namespace jit { void - Jit::init_once() { + MachPipeline::init_once() { static bool s_init_once = false; if (!s_init_once) { @@ -38,36 +38,36 @@ namespace xo { * + 'jit_copmile_layer' * + 'jit_our_dynamic_lib' */ - llvm::Expected> - Jit::make_aux() + llvm::Expected> + MachPipeline::make_aux() { - Jit::init_once(); + MachPipeline::init_once(); static llvm::ExitOnError llvm_exit_on_err; std::unique_ptr kal_jit = llvm_exit_on_err(KaleidoscopeJIT::Create()); - return std::unique_ptr(new Jit(std::move(kal_jit) + return std::unique_ptr(new MachPipeline(std::move(kal_jit) )); } /*make*/ - xo::ref::rp - Jit::make() { + xo::ref::rp + MachPipeline::make() { static llvm::ExitOnError llvm_exit_on_err; - std::unique_ptr jit = llvm_exit_on_err(make_aux()); + std::unique_ptr jit = llvm_exit_on_err(make_aux()); return jit.release(); } /*make*/ - Jit::Jit(std::unique_ptr kal_jit) + MachPipeline::MachPipeline(std::unique_ptr kal_jit) : kal_jit_{std::move(kal_jit)} { this->recreate_llvm_ir_pipeline(); } void - Jit::recreate_llvm_ir_pipeline() + MachPipeline::recreate_llvm_ir_pipeline() { //llvm_cx_ = std::make_unique(); llvm_cx_ = LlvmContext::make(); @@ -77,13 +77,13 @@ namespace xo { llvm_module_->setDataLayout(kal_jit_->data_layout()); if (!llvm_cx_.get()) { - throw std::runtime_error("Jit::ctor: expected non-empty llvm context"); + throw std::runtime_error("MachPipeline::ctor: expected non-empty llvm context"); } if (!llvm_ir_builder_.get()) { - throw std::runtime_error("Jit::ctor: expected non-empty llvm IR builder"); + throw std::runtime_error("MachPipeline::ctor: expected non-empty llvm IR builder"); } if (!llvm_module_.get()) { - throw std::runtime_error("Jit::ctor: expected non-empty llvm module"); + throw std::runtime_error("MachPipeline::ctor: expected non-empty llvm module"); } ir_pipeline_ = new IrPipeline(llvm_cx_); @@ -93,7 +93,7 @@ namespace xo { * e.g. "x86_64-unknown-linux-gnu" **/ const std::string & - Jit::target_triple() const { + MachPipeline::target_triple() const { // although this getter is defined, seems to be empty in practice //return llvm_module_->getTargetTriple(); @@ -101,7 +101,7 @@ namespace xo { } std::vector - Jit::get_function_name_v() { + MachPipeline::get_function_name_v() { std::vector retval; for (const auto & fn_name : *llvm_module_) retval.push_back(fn_name.getName().str()); @@ -110,12 +110,12 @@ namespace xo { } /*get_function_names*/ void - Jit::dump_execution_session() { + MachPipeline::dump_execution_session() { kal_jit_->dump_execution_session(); } llvm::Value * - Jit::codegen_constant(ref::brw expr) + MachPipeline::codegen_constant(ref::brw expr) { TypeDescr td = expr->value_td(); @@ -131,7 +131,7 @@ namespace xo { } llvm::Function * - Jit::codegen_primitive(ref::brw expr) + MachPipeline::codegen_primitive(ref::brw expr) { constexpr bool c_debug_flag = true; using xo::scope; @@ -178,7 +178,7 @@ namespace xo { // TODO: extend with other native types here... } else { - cerr << "Jit::codegen_primitive: error: primitive f with arg i of type T where double expected" + cerr << "MachPipeline::codegen_primitive: error: primitive f with arg i of type T where double expected" << xtag("f", expr->name()) << xtag("i", i) << xtag("T", arg_td->short_name()) @@ -198,7 +198,7 @@ namespace xo { if (retval_td->is_native()) { llvm_retval = llvm::Type::getDoubleTy(llvm_cx_->llvm_cx_ref()); } else { - cerr << "Jit::codegen_primitive: error: primitive f returning T where double expected" + cerr << "MachPipeline::codegen_primitive: error: primitive f returning T where double expected" << xtag("f", expr->name()) << xtag("T", retval_td->short_name()) << endl; @@ -234,7 +234,7 @@ namespace xo { } /*codegen_primitive*/ llvm::Value * - Jit::codegen_apply(ref::brw apply) + MachPipeline::codegen_apply(ref::brw apply) { using std::cerr; using std::endl; @@ -251,13 +251,13 @@ namespace xo { auto * fn = this->codegen_primitive(pm); #ifdef NOT_USING_DEBUG - cerr << "Jit::codegen_apply: fn:" << endl; + cerr << "MachPipeline::codegen_apply: fn:" << endl; fn->print(llvm::errs()); cerr << endl; #endif if (fn->arg_size() != apply->argv().size()) { - cerr << "Jit::codegen_apply: error: callee f expecting n1 args where n2 supplied" + cerr << "MachPipeline::codegen_apply: error: callee f expecting n1 args where n2 supplied" << xtag("f", pm->name()) << xtag("n1", pm->n_arg()) << xtag("n2", apply->argv().size()) @@ -272,7 +272,7 @@ namespace xo { auto * arg = this->codegen(arg_expr); #ifdef NOT_USING_DEBUG - cerr << "Jit::codegen_apply: arg:" << endl; + cerr << "MachPipeline::codegen_apply: arg:" << endl; arg->print(llvm::errs()); cerr << endl; #endif @@ -282,13 +282,13 @@ namespace xo { return llvm_ir_builder_->CreateCall(fn, args, "calltmp"); } else { - cerr << "Jit::codegen_apply: error: only allowing call to known primitives at present" << endl; + cerr << "MachPipeline::codegen_apply: error: only allowing call to known primitives at present" << endl; return nullptr; } } /*codegen_apply*/ llvm::Function * - Jit::codegen_lambda(ref::brw lambda) + MachPipeline::codegen_lambda(ref::brw lambda) { /* reminder! this is the *expression*, not the *closure* */ @@ -356,12 +356,12 @@ namespace xo { } /*codegen_lambda*/ llvm::Value * - Jit::codegen_variable(ref::brw var) + MachPipeline::codegen_variable(ref::brw var) { auto ix = nested_env_.find(var->name()); if (ix == nested_env_.end()) { - cerr << "Jit::codegen_variable: no binding for variable x" + cerr << "MachPipeline::codegen_variable: no binding for variable x" << xtag("x", var->name()) << endl; } @@ -370,7 +370,7 @@ namespace xo { } /*codegen_variable*/ llvm::Value * - Jit::codegen(ref::brw expr) + MachPipeline::codegen(ref::brw expr) { switch(expr->extype()) { case exprtype::constant: @@ -389,7 +389,7 @@ namespace xo { break; } - cerr << "Jit::codegen: error: no handler for expression of type T" + cerr << "MachPipeline::codegen: error: no handler for expression of type T" << xtag("T", expr->extype()) << endl; @@ -397,7 +397,7 @@ namespace xo { } /*codegen*/ void - Jit::machgen_current_module() + MachPipeline::machgen_current_module() { static llvm::ExitOnError llvm_exit_on_err; @@ -419,7 +419,7 @@ namespace xo { } llvm::orc::ExecutorAddr - Jit::lookup_symbol(const std::string & sym) + MachPipeline::lookup_symbol(const std::string & sym) { static llvm::ExitOnError llvm_exit_on_err; @@ -433,15 +433,15 @@ namespace xo { } /*lookup_symbol*/ void - Jit::display(std::ostream & os) const { - os << ""; + MachPipeline::display(std::ostream & os) const { + os << ""; } std::string - Jit::display_string() const { + MachPipeline::display_string() const { return tostr(*this); } } /*namespace jit*/ } /*namespace xo*/ -/* end Jit.cpp */ +/* end MachPipeline.cpp */