From 0ed71ab5569e45460ff4b3c035e3a847329d72f6 Mon Sep 17 00:00:00 2001 From: Hugo Devillers Date: Wed, 22 Oct 2025 16:59:02 +0200 Subject: [PATCH] delete shady backend, SPIR-V will replace it --- CMakeLists.txt | 11 - cmake/thorin-config.cmake.in | 1 - src/thorin/CMakeLists.txt | 14 - src/thorin/be/codegen.cpp | 21 -- src/thorin/be/llvm/llvm.cpp | 1 - src/thorin/be/runtime.h | 1 - src/thorin/be/shady/shady.cpp | 508 ---------------------------------- src/thorin/be/shady/shady.h | 67 ----- src/thorin/config.h.in | 1 - src/thorin/continuation.cpp | 1 - src/thorin/continuation.h | 1 - 11 files changed, 627 deletions(-) delete mode 100644 src/thorin/be/shady/shady.cpp delete mode 100644 src/thorin/be/shady/shady.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d2b54c872..84813b0fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,17 +61,6 @@ endif() include(CheckIncludeFile) check_include_file(sys/resource.h THORIN_ENABLE_RLIMITS) -if (NOT TARGET shady) - find_package(shady CONFIG) - if (shady_FOUND) - message(STATUS "Found shady at ${shady_DIR}") - set(THORIN_ENABLE_SHADY TRUE) - endif() -else() - export(TARGETS shady api FILE ${CMAKE_BINARY_DIR}/share/anydsl/cmake/shady-exports.cmake) - set(THORIN_ENABLE_SHADY TRUE) -endif() - find_package(SPIRV-Headers) if (SPIRV-Headers_FOUND) message(STATUS "Found SPIRV-Headers at ${SPIRV-Headers_DIR}") diff --git a/cmake/thorin-config.cmake.in b/cmake/thorin-config.cmake.in index 641f33e0c..8bd23d5de 100644 --- a/cmake/thorin-config.cmake.in +++ b/cmake/thorin-config.cmake.in @@ -31,7 +31,6 @@ find_package(Half REQUIRED) set(Thorin_HAS_JSON_SUPPORT @THORIN_ENABLE_JSON@) set(Thorin_HAS_LLVM_SUPPORT @LLVM_FOUND@) set(Thorin_HAS_RV_SUPPORT @RV_FOUND@) -set(Thorin_HAS_SHADY_SUPPORT @THORIN_ENABLE_SHADY@) set(Thorin_HAS_SPIRV_SUPPORT @THORIN_ENABLE_SPIRV@) set(AnyDSL_LLVM_LINK_SHARED @AnyDSL_LLVM_LINK_SHARED@) diff --git a/src/thorin/CMakeLists.txt b/src/thorin/CMakeLists.txt index 7910f0dfa..5f9f6f265 100644 --- a/src/thorin/CMakeLists.txt +++ b/src/thorin/CMakeLists.txt @@ -112,12 +112,6 @@ if(LLVM_FOUND) ) endif() -if (THORIN_ENABLE_SHADY) - list(APPEND THORIN_SOURCES - be/shady/shady.cpp - ) -endif() - if(THORIN_ENABLE_JSON) list(APPEND THORIN_SOURCES be/json/json.cpp @@ -149,14 +143,6 @@ if(LLVM_FOUND) llvm_config(thorin ${AnyDSL_LLVM_LINK_SHARED} ${Thorin_LLVM_COMPONENTS}) endif() -if (THORIN_ENABLE_SHADY) - if (shady_FOUND) - target_link_libraries(thorin PRIVATE shady::shady) - else() - target_link_libraries(thorin PRIVATE shady) - endif() -endif() - if(THORIN_ENABLE_JSON) target_link_libraries(thorin PRIVATE nlohmann_json::nlohmann_json) endif() diff --git a/src/thorin/be/codegen.cpp b/src/thorin/be/codegen.cpp index 36aa34849..393f1f351 100644 --- a/src/thorin/be/codegen.cpp +++ b/src/thorin/be/codegen.cpp @@ -9,12 +9,6 @@ #include "thorin/be/llvm/amdgpu_pal.h" #endif -#if THORIN_ENABLE_SHADY -#include "thorin/be/shady/shady.h" -#undef empty -#undef nodes -#endif - #if THORIN_ENABLE_SPIRV #include "thorin/be/spirv/spirv.h" #endif @@ -197,18 +191,6 @@ struct NVVMBackend : public Backend { }; #endif -#if THORIN_ENABLE_SHADY -struct ShadyBackend : public Backend { - explicit ShadyBackend(DeviceBackends2& b, World& src) : Backend(b, src) { - b.register_intrinsic(Intrinsic::ShadyCompute, get_gpu_kernel_config); - } - - std::unique_ptr create_cg(const Cont2Config& config) override { - return std::make_unique(device_code_, config, backends_.debug()); - } -}; -#endif - struct HLSBackend : public Backend { explicit HLSBackend(DeviceBackends& b, World& src, std::string& hls_flags) : Backend(b, src), hls_flags_(hls_flags) { b.register_intrinsic(Intrinsic::HLS, *this, [&](const App* app, Continuation* imported) { @@ -265,9 +247,6 @@ DeviceBackends::DeviceBackends(thorin::World& world, int opt, bool debug, std::s register_backend(std::make_unique(*this, world)); register_backend(std::make_unique(*this, world)); #endif -#if THORIN_ENABLE_SHADY - register_backend(std::make_unique(*this, world)) -#endif #if THORIN_ENABLE_SPIRV register_backend(std::make_unique(*this, world)); register_backend(std::make_unique(*this, world)); diff --git a/src/thorin/be/llvm/llvm.cpp b/src/thorin/be/llvm/llvm.cpp index 4f7d80451..ab1fd50f5 100644 --- a/src/thorin/be/llvm/llvm.cpp +++ b/src/thorin/be/llvm/llvm.cpp @@ -1310,7 +1310,6 @@ std::vector CodeGen::emit_intrinsic(llvm::IRBuilder<>& irbuilder, case Intrinsic::LevelZero_SPIRV: runtime_->emit_host_code(*this, irbuilder, Platform::LEVEL_ZERO_PLATFORM, ".spv", continuation); break; case Intrinsic::AMDGPUHSA: runtime_->emit_host_code(*this, irbuilder, Platform::HSA_PLATFORM, ".amdgpu", continuation); break; case Intrinsic::AMDGPUPAL: runtime_->emit_host_code(*this, irbuilder, Platform::PAL_PLATFORM, ".amdgpu", continuation); break; - case Intrinsic::ShadyCompute: runtime_->emit_host_code(*this, irbuilder, Platform::SHADY_PLATFORM, ".shady", continuation); break; case Intrinsic::HLS: emit_hls(irbuilder, continuation); break; case Intrinsic::Parallel: emit_parallel(irbuilder, continuation); break; case Intrinsic::Fibers: emit_fibers(irbuilder, continuation); break; diff --git a/src/thorin/be/runtime.h b/src/thorin/be/runtime.h index 68cdd9b97..4b66b6e7a 100644 --- a/src/thorin/be/runtime.h +++ b/src/thorin/be/runtime.h @@ -11,7 +11,6 @@ enum Platform { HSA_PLATFORM, PAL_PLATFORM, LEVEL_ZERO_PLATFORM, - SHADY_PLATFORM, }; enum KernelLaunchArgs { diff --git a/src/thorin/be/shady/shady.cpp b/src/thorin/be/shady/shady.cpp deleted file mode 100644 index 3e4a91e7a..000000000 --- a/src/thorin/be/shady/shady.cpp +++ /dev/null @@ -1,508 +0,0 @@ -#include "shady.h" -#undef empty - -#include "thorin/analyses/scope.h" - -namespace thorin::shady_be { - -CodeGen::CodeGen(thorin::Thorin& thorin, Cont2Config& kernel_config, bool debug) - : thorin::CodeGen(thorin, debug), kernel_config_(kernel_config) -{} - -void CodeGen::emit_stream(std::ostream& out) { - assert(!module); - - shady::ArenaConfig config = shady::default_arena_config(); - config.name_bound = true; - config.check_types = true; - arena = shady::new_ir_arena(config); - module = shady::new_module(arena, world().name().c_str()); - - ScopesForest forest(world()); - forest.for_each([&](const Scope& scope) { - if(scope.entry()->cc() == CC::Thorin) { - return; - } - emit_scope(scope, forest); - }); - - char* bufptr; - size_t size; - shady::print_module_into_str(module, &bufptr, &size); - out.write(bufptr, static_cast(size)); - free(bufptr); - - shady::destroy_ir_arena(arena); - arena = nullptr; -} - -shady::AddressSpace CodeGen::convert_address_space(AddrSpace as) { - switch(as) { - case AddrSpace::Generic: assert(false); break; - case AddrSpace::Global: return shady::AsGlobalPhysical; - case AddrSpace::Texture: assert(false); break; - case AddrSpace::Shared: return shady::AsSharedPhysical; - case AddrSpace::Constant: assert(false); break; - case AddrSpace::Private: return shady::AsPrivatePhysical; - } - assert(false); -} - -static inline int find_return_parameter(const FnType* type) { - for (size_t i = 0; i < type->num_ops(); i++) { - auto t = type->op(i); - if (t->order() % 2 == 1) - return static_cast(i); - } - return -1; -} - -const shady::Type* CodeGen::convert(const Type* type) { - if (auto res = types_.lookup(type)) return *res; - const shady::Type* t; - if (type == world().mem_type()) { - t = nullptr; - goto skip_check; - } else if (auto prim = type->isa()) { - switch (prim->primtype_tag()) { - case PrimType_bool: t = shady::bool_type(arena); break; - case PrimType_ps8: case PrimType_qs8: - case PrimType_pu8: case PrimType_qu8: t = shady::int8_type(arena); break; - case PrimType_ps16: case PrimType_qs16: - case PrimType_pu16: case PrimType_qu16: t = shady::int16_type(arena); break; - case PrimType_ps32: case PrimType_qs32: - case PrimType_pu32: case PrimType_qu32: t = shady::int32_type(arena); break; - case PrimType_ps64: case PrimType_qs64: - case PrimType_pu64: case PrimType_qu64: t = shady::int64_type(arena); break; - case PrimType_pf16: case PrimType_qf16: t = shady::fp16_type(arena); break; - case PrimType_pf32: case PrimType_qf32: t = shady::fp32_type(arena); break; - case PrimType_pf64: case PrimType_qf64: t = shady::fp64_type(arena); break; - default: THORIN_UNREACHABLE; - } - } else if (auto ptr = type->isa()) { - shady::PtrType payload = { - convert_address_space(ptr->addr_space()), - convert(ptr->pointee()) - }; - t = shady::ptr_type(arena, payload); - } else if (auto arr = type->isa()) { - shady::ArrType payload = {}; - payload.element_type = convert(arr->elem_type()); - payload.size = nullptr; - if (auto definite = arr->isa()) { - payload.size = shady::int32_literal(arena, static_cast(definite->dim())); - } - t = shady::arr_type(arena, payload); - } else if (auto strct = type->isa()) { - auto members = std::vector(strct->num_ops()); - for (size_t i = 0; i < strct->num_ops(); i++) { - members[i] = convert(strct->types()[i]); - } - shady::RecordType payload = {}; - payload.members = shady::nodes(arena, strct->num_ops(), members.data()); - payload.names = shady::strings(arena, 0, nullptr); - payload.special = shady::NotSpecial; - t = shady::record_type(arena, payload); - } else if (auto variant = type->isa()) { - assert(false && "TODO"); - } else if (auto fn_type = type->isa()) { - shady::FnType payload = {}; - NodeVec dom, codom; - - int return_param_i = find_return_parameter(fn_type); - for (size_t i = 0; i < fn_type->num_ops(); i++) { - // Skip the return param - if (return_param_i != -1 && i == static_cast(return_param_i)) continue; - auto converted = convert(fn_type->types()[i]); - if (!converted) - continue; // Eliminate mem params - shady::QualifiedType qtype; - qtype.type = converted; - qtype.is_uniform = false; - converted = shady::qualified_type(arena, qtype); - dom.push_back(converted); - } - - if (return_param_i != -1) { - auto ret_fn_type = fn_type->types()[return_param_i]->as(); - for (size_t i = 0; i < ret_fn_type->num_ops(); i++) { - auto converted = convert(ret_fn_type->types()[i]); - if (!converted) - continue; // Eliminate mem params - codom.push_back(converted); - } - } - - if (fn_type->is_basicblock()) - assert(codom.empty()); - payload.param_types = vec2nodes(dom); - payload.return_types = vec2nodes(codom); - t = shady::fn_type(arena, payload); - } else { - assert(false); - } - - assert(t); - skip_check: - types_[type] = t; - return t; -} - -shady::Node* CodeGen::emit_decl_head(Def* def) { - NodeVec annotations; - if (auto cont = def->isa_nom()) { - assert(!cont->is_basicblock()); - NodeVec params; - NodeVec returns; - - int ret_param_i = find_return_parameter(cont->type()); - - for (size_t i = 0; i < cont->num_params(); i++) { - if (ret_param_i != -1 && i == static_cast(ret_param_i)) - continue; // Skip the return parameter - auto type = convert(cont->param(i)->type()); - if (!type) continue; // Eliminate mem tokens - shady::QualifiedType qtype; - qtype.type = type; - qtype.is_uniform = false; - type = shady::qualified_type(arena, qtype); - auto param = shady::var(arena, type, cont->param(i)->name().c_str()); - defs_[cont->param(i)] = param; // Register the param as emitted already - params.push_back(param); - } - - auto ret_fn_type = cont->type()->types()[ret_param_i]->as(); - - for (auto t : ret_fn_type->types()) { - auto ret_type = convert(t); - if (!ret_type) - continue; // Eliminate mem types - - shady::QualifiedType qtype; - qtype.type = ret_type; - qtype.is_uniform = false; - ret_type = shady::qualified_type(arena, qtype); - returns.push_back(ret_type); - } - - std::string name = def->unique_name(); - - auto config = kernel_config_.find(cont); - if (config != kernel_config_.end()) { - if (auto gpu_config = config->second->isa()) { - annotations.push_back(shady::annotation_value(arena, { .name = "EntryPoint", .value = shady::string_lit(arena, { .string = "compute" })})); - std::vector block_size; - block_size.emplace_back(shady::int32_literal(arena, get<0>(gpu_config->block_size()))); - block_size.emplace_back(shady::int32_literal(arena, get<1>(gpu_config->block_size()))); - block_size.emplace_back(shady::int32_literal(arena, get<2>(gpu_config->block_size()))); - annotations.push_back(shady::annotation_values(arena, { .name = "WorkgroupSize", .values = vec2nodes(block_size) })); - name = "main"; - } else { - assert(false && "Only GPU kernel configs are currently supported"); - } - } - - return shady::function(module, vec2nodes(params), name.c_str(), vec2nodes(annotations), vec2nodes(returns)); - } else if (auto global = def->isa()) { - if (global->is_mutable()) { - return shady::global_var(module, vec2nodes(annotations), convert(global->alloced_type()), global->unique_name().c_str(), convert_address_space(AddrSpace::Private)); - } else { - // Tentatively make those things constants... - return shady::constant(module, vec2nodes(annotations), convert(global->alloced_type()), global->unique_name().c_str()); - } - } else { - assert(false && "This doesn't map to a decl !"); - } -} - -shady::Node* CodeGen::get_decl(Def* def) { - shady::Nodes already_done = shady::get_module_declarations(module); - for (size_t i = 0; i < already_done.count; i++) { - auto& e = already_done.nodes[i]; - if (shady::get_decl_name(e) == def->unique_name()) - return (shady::Node*) e; - } - - return emit_decl_head(def); -} - -shady::Node* CodeGen::prepare(const Scope& scope) { - return cont2bb_[scope.entry()].head = curr_fn = get_decl(scope.entry()); -} - -void CodeGen::prepare(Continuation* cont, shady::Node*) { - BB& bb = cont2bb_[cont]; - if (cont->is_basicblock()) { - NodeVec params; - - for (size_t i = 0; i < cont->num_params(); i++) { - auto type = convert(cont->param(i)->type()); - if (!type) continue; // Eliminate mem tokens - shady::QualifiedType qtype; - qtype.type = type; - qtype.is_uniform = false; - type = shady::qualified_type(arena, qtype); - auto param = shady::var(arena, type, cont->param(i)->name().c_str()); - defs_[cont->param(i)] = param; // Register the param as emitted already - params.push_back(param); - } - - bb.head = shady::basic_block(arena, curr_fn, vec2nodes(params), cont->unique_name().c_str()); - } else - assert(bb.head); - - bb.builder = shady::begin_body(arena); -} - -static std::optional is_shady_prim_op(const Continuation* cont) { - for (int i = 0; i < shady::PRIMOPS_COUNT; i++) { - if (cont->name() == shady::get_primop_name(static_cast(i))) - return std::make_optional((shady::Op) i); - } - return std::nullopt; -} - -static std::vector emit_instruction(shady::BodyBuilder* builder, const shady::Node* instruction); - -void CodeGen::emit_epilogue(Continuation* cont) { - BB& bb = cont2bb_[cont]; - assert(cont->has_body()); - auto body = cont->body(); - NodeVec args; - for (auto& arg : body->args()) { - if (convert(arg->type()) == nullptr) { - if (is_mem(arg)) - emit_unsafe(arg); - args.push_back(nullptr); - } else if (auto target = arg->isa_nom(); target && target->is_basicblock()) { - // Emitting basic blocks as values isn't legal - but for convenience we'll put them in our list. - assert(cont2bb_.contains(target)); - BB& callee_bb = cont2bb_[target]; - assert(callee_bb.head && shady::is_basic_block(callee_bb.head)); - args.push_back(callee_bb.head); - } else { - args.push_back(emit(arg)); - } - } - - if (body->callee() == entry_->ret_param()) { - shady::Return payload = {}; - payload.fn = curr_fn; - args.erase(std::remove_if(args.begin(), args.end(), [&](const auto& item){ return item == nullptr || !shady::is_value(item); }), args.end()); - payload.args = vec2nodes(args); - bb.terminator = shady::fn_ret(arena, payload); - } else if (body->callee() == world().branch()) { - shady::Branch payload = {}; - payload.branch_condition = args[0]; - payload.true_jump = shady::jump_helper(arena, args[1], shady::empty(arena)); - payload.false_jump = shady::jump_helper(arena, args[2], shady::empty(arena)); - bb.terminator = shady::branch(arena, payload); - } else if (auto match = body->callee()->as_nom(); match && match->intrinsic() == Intrinsic::Match) { - assert(false); - } else if (auto destination = body->callee()->isa_nom(); destination && destination->is_basicblock()) { - shady::Jump payload = {}; - args.erase(std::remove_if(args.begin(), args.end(), [&](const auto& item){ return item == nullptr || !shady::is_value(item); }), args.end()); - payload.args = vec2nodes(args); - payload.target = args[0]; - bb.terminator = shady::jump(arena, payload); - } else if (auto intrinsic = body->callee()->isa_nom(); intrinsic && intrinsic->is_intrinsic()) { - assert(false); - } else { - int ret_param = find_return_parameter(body->callee()->type()->as()); - // TODO handle tail calls ? - assert(ret_param >= 0); - - args.erase(args.begin() + ret_param); - args.erase(std::remove_if(args.begin(), args.end(), [&](const auto& item){ return item == nullptr || !shady::is_value(item); }), args.end()); - - if (auto callee = body->callee()->isa_nom()) { - // shady primop called as imported continuations look like continuation calls to thorin, but not to shady - // we just need to carefully emit the primop as an instruction, then jump to the target BB, passing the stuff as we do - if (auto op = is_shady_prim_op(callee); op.has_value()) { - shady::Jump jump; - jump.target = args[ret_param]; - jump.args = shady::bind_instruction(bb.builder, shady::prim_op(arena, (shady::PrimOp) { - .op = op.value(), - .type_arguments = shady::nodes(arena, 0, nullptr), - .operands = vec2nodes(args), - })); - bb.terminator = shady::jump(arena, jump); - return; - } - } - - shady::BodyBuilder* builder = shady::begin_body(arena); - - shady::Call icall_payload; - icall_payload.args = vec2nodes(args); - icall_payload.callee = emit(body->callee()); - shady::Nodes results = shady::bind_instruction(builder, shady::call(arena, icall_payload)); - - assert(args[ret_param]->tag == shady::BasicBlock_TAG); - shady::Jump jump_payload; - jump_payload.target = args[ret_param]; - jump_payload.args = results; - bb.terminator = shady::finish_body(builder, shady::jump(arena, jump_payload)); - } -} - -void CodeGen::finalize(Continuation* cont) { - BB& bb = cont2bb_[cont]; - assert(bb.head && bb.builder && bb.terminator); - if (shady::is_basic_block(bb.head)) - bb.head->payload.basic_block.body = shady::finish_body(bb.builder, bb.terminator); - else if (shady::is_function(bb.head)) - bb.head->payload.fun.body = shady::finish_body(bb.builder, bb.terminator); - else - assert(false); -} - -void CodeGen::finalize(const Scope& scope) { - BB& bb = cont2bb_[scope.entry()]; - assert(bb.head->payload.fun.body != nullptr); - curr_fn = nullptr; -} - -const shady::Node* CodeGen::emit_fun_decl(Continuation* cont) { - assert(!cont->is_basicblock()); - shady::FnAddr payload; - payload.fn = get_decl(cont); - return shady::fn_addr(arena, payload); -} - -void CodeGen::unimplemented(const Def* def) { - world().error(def->loc(), "We don't know how to emit {} !", def); - abort(); -} - -const shady::Node* CodeGen::emit_bb(BB& bb, const Def* def) { - const shady::Node* v = nullptr; - - auto mk_primop = [&](shady::Op op, ArrayRef args, ArrayRef types = {}) -> const shady::Node* { - shady::PrimOp payload = {}; - payload.op = op; - std::vector operands; - for (auto arg : args) - operands.push_back(emit(arg)); - std::vector type_arguments; - for (auto type_arg : types) - type_arguments.push_back(convert(type_arg)); - payload.operands = vec2nodes(operands); - payload.type_arguments = vec2nodes(type_arguments); - auto ret = shady::bind_instruction(bb.builder, shady::prim_op(arena, payload)); - return ret.count ? shady::first(ret) : nullptr; - }; - - if (auto prim_lit = def->isa()) { - const auto& box = prim_lit->value(); - shady::FloatLiteral fl {}; - switch (prim_lit->primtype_tag()) { - case PrimType_bool: v = box.get_bool() ? shady::true_lit(arena) : shady::false_lit(arena); break; - case PrimType_ps8: case PrimType_qs8: v = shady::int8_literal (arena, box.get_s8()); break; - case PrimType_pu8: case PrimType_qu8: v = shady::uint8_literal (arena, box.get_u8()); break; - case PrimType_ps16: case PrimType_qs16: v = shady::int16_literal(arena, box.get_s16()); break; - case PrimType_pu16: case PrimType_qu16: v = shady::uint16_literal(arena, box.get_u16()); break; - case PrimType_ps32: case PrimType_qs32: v = shady::int32_literal(arena, box.get_s32()); break; - case PrimType_pu32: case PrimType_qu32: v = shady::uint32_literal(arena, box.get_u32()); break; - case PrimType_ps64: case PrimType_qs64: v = shady::int64_literal(arena, box.get_s64()); break; - case PrimType_pu64: case PrimType_qu64: v = shady::uint64_literal(arena, box.get_u64()); break; - case PrimType_pf16: case PrimType_qf16: { - fl.width = shady::FloatTy16; - auto f = box.get_f16(); - memcpy(&fl.value, &f, sizeof(f)); - v = shady::float_literal(arena, fl); - break; - } - case PrimType_pf32: case PrimType_qf32: { - fl.width = shady::FloatTy32; - auto f = box.get_f32(); - memcpy(&fl.value, &f, sizeof(f)); - v = shady::float_literal(arena, fl); - break; - } - case PrimType_pf64: case PrimType_qf64:{ - fl.width = shady::FloatTy64; - auto f = box.get_f64(); - memcpy(&fl.value, &f, sizeof(f)); - v = shady::float_literal(arena, fl); - break; - } - default: THORIN_UNREACHABLE; - } - } else if (auto arr = def->isa()) { - NodeVec contents; - for (auto& e : arr->ops()) { - assert(emit(e)); - contents.push_back(emit(e)); - } - shady::ArrType payload; - payload.element_type = convert(arr->elem_type()); - payload.size = shady::int32_literal(arena, contents.size()); - const shady::Type* arr_type = shady::arr_type(arena, payload); - v = shady::composite_helper(arena, arr_type, vec2nodes(contents)); - } else if (auto cmp = def->isa()) { - switch (cmp->cmp_tag()) { - case Cmp_eq: v = mk_primop(shady::Op::eq_op, { cmp->lhs(), cmp->rhs() }); break; - case Cmp_ne: v = mk_primop(shady::Op::neq_op, { cmp->lhs(), cmp->rhs() }); break; - case Cmp_gt: v = mk_primop(shady::Op::gt_op, { cmp->lhs(), cmp->rhs() }); break; - case Cmp_ge: v = mk_primop(shady::Op::gte_op, { cmp->lhs(), cmp->rhs() }); break; - case Cmp_lt: v = mk_primop(shady::Op::lt_op, { cmp->lhs(), cmp->rhs() }); break; - case Cmp_le: v = mk_primop(shady::Op::lte_op, { cmp->lhs(), cmp->rhs() }); break; - } - } else if (auto arith = def->isa()) { - switch (arith->arithop_tag()) { - case ArithOp_add: v = mk_primop(shady::Op::add_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_sub: v = mk_primop(shady::Op::sub_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_mul: v = mk_primop(shady::Op::mul_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_div: v = mk_primop(shady::Op::div_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_rem: v = mk_primop(shady::Op::mod_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_and: v = mk_primop(shady::Op::and_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_or: v = mk_primop(shady::Op::or_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_xor: v = mk_primop(shady::Op::xor_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_shl: v = mk_primop(shady::Op::lshift_op, { arith->lhs(), arith->rhs() }); break; - case ArithOp_shr: v = mk_primop(shady::Op::rshift_logical_op, { arith->lhs(), arith->rhs() }); break; - } - } else if (auto math = def->isa()) { - switch (math->mathop_tag()) { - case MathOp_fmin: v = mk_primop(shady::Op::min_op, math->ops()); break; - case MathOp_fmax: v = mk_primop(shady::Op::max_op, math->ops()); break; - case MathOp_cos: v = mk_primop(shady::Op::cos_op, math->ops()); break; - case MathOp_sin: v = mk_primop(shady::Op::sin_op, math->ops()); break; - case MathOp_fabs: v = mk_primop(shady::Op::abs_op, math->ops()); break; - case MathOp_floor: v = mk_primop(shady::Op::floor_op, math->ops()); break; - case MathOp_round: v = mk_primop(shady::Op::round_op, math->ops()); break; - case MathOp_pow: v = mk_primop(shady::Op::pow_op, math->ops()); break; - case MathOp_exp: v = mk_primop(shady::Op::exp_op, math->ops()); break; - case MathOp_sqrt: v = mk_primop(shady::Op::sqrt_op, math->ops()); break; - default: { - unimplemented(def); - THORIN_UNREACHABLE; - } - } - } else if (auto store = def->isa()) { - mk_primop(shady::Op::store_op, { store->ptr(), store->val() }); - defs_[def] = nullptr; - return nullptr; - } else if (auto lea = def->isa()) { - v = mk_primop(shady::Op::lea_op, { lea->ptr(), world().zero(lea->index()->type()), lea->index() }); - } else if (auto param = def->isa()) { - assert(param->type() == world().mem_type()); - defs_[def] = nullptr; - return nullptr; - } else if (auto bitcast = def->isa()) { - v = mk_primop(shady::Op::reinterpret_op, { bitcast->from() }, { bitcast->type() }); - } else if (auto conversion = def->isa()) { - v = mk_primop(shady::Op::convert_op, {conversion->from() }, {conversion->type() }); - } else { - unimplemented(def); - } - assert(v && shady::is_value(v)); - defs_[def] = v; - return v; -} - -const shady::Node* CodeGen::emit_constant(const Def* def) { - THORIN_UNREACHABLE; -} - -} diff --git a/src/thorin/be/shady/shady.h b/src/thorin/be/shady/shady.h deleted file mode 100644 index 648cdf0c4..000000000 --- a/src/thorin/be/shady/shady.h +++ /dev/null @@ -1,67 +0,0 @@ -#include "thorin/be/codegen.h" -#include "thorin/analyses/schedule.h" -#include "thorin/be/emitter.h" - -namespace shady { -extern "C" { -#include -} -} - -namespace thorin::shady_be { - -// using BB = std::pair; - -struct BB { - /// For an entry BB, this will also be the head of the entire function - shady::Node* head; - shady::BodyBuilder* builder; - const shady::Node* terminator; -}; - -class CodeGen : public thorin::CodeGen, public thorin::Emitter { -public: - CodeGen(Thorin&, Cont2Config&, bool debug); - - void emit_stream(std::ostream& stream) override; - const char* file_ext() const override { return ".shady"; } - - shady::Node* prepare(const Scope&); - void prepare(Continuation*, shady::Node*); - void emit_epilogue(Continuation*); - // const shady::Node* emit_(const Def* def); - void finalize(const Scope&); - void finalize(Continuation*); - - const shady::Type* convert(const Type*); - const shady::Node* emit_bb(BB&, const Def*); - const shady::Node* emit_constant(const Def*); - - bool is_valid(const shady::Node* n) { - return n; - } - - const shady::Node* emit_fun_decl(Continuation*); -protected: - shady::AddressSpace convert_address_space(AddrSpace); - shady::Node* emit_decl_head(Def*); - shady::Node* get_decl(Def*); - - using NodeVec = std::vector; - - inline shady::Nodes vec2nodes(NodeVec& vec) { - return shady::nodes(arena, vec.size(), vec.data()); - } - - shady::IrArena* arena = nullptr; - shady::Module* module = nullptr; - - void unimplemented(const Def* def); - - shady::Node* curr_fn; - - const Cont2Config& kernel_config_; - -}; - -} diff --git a/src/thorin/config.h.in b/src/thorin/config.h.in index 3a6b28644..21a762860 100644 --- a/src/thorin/config.h.in +++ b/src/thorin/config.h.in @@ -7,7 +7,6 @@ #cmakedefine01 THORIN_ENABLE_LLVM #cmakedefine01 THORIN_ENABLE_JSON #cmakedefine01 THORIN_ENABLE_RV -#cmakedefine01 THORIN_ENABLE_SHADY #cmakedefine01 THORIN_ENABLE_SPIRV #cmakedefine01 THORIN_ENABLE_RLIMITS diff --git a/src/thorin/continuation.cpp b/src/thorin/continuation.cpp index 1632708b1..41692d974 100644 --- a/src/thorin/continuation.cpp +++ b/src/thorin/continuation.cpp @@ -261,7 +261,6 @@ void Continuation::set_intrinsic() { else if (name() == "levelzero") attributes().intrinsic = Intrinsic::LevelZero_SPIRV; else if (name() == "amdgpu_hsa") attributes().intrinsic = Intrinsic::AMDGPUHSA; else if (name() == "amdgpu_pal") attributes().intrinsic = Intrinsic::AMDGPUPAL; - else if (name() == "shady_compute") attributes().intrinsic = Intrinsic::ShadyCompute; else if (name() == "hls") attributes().intrinsic = Intrinsic::HLS; else if (name() == "parallel") attributes().intrinsic = Intrinsic::Parallel; else if (name() == "fibers") attributes().intrinsic = Intrinsic::Fibers; diff --git a/src/thorin/continuation.h b/src/thorin/continuation.h index a99bf8636..10d331eb9 100644 --- a/src/thorin/continuation.h +++ b/src/thorin/continuation.h @@ -105,7 +105,6 @@ enum class Intrinsic : uint8_t { LevelZero_SPIRV, ///< Internal SPIRV for Level0-Backend. AMDGPUHSA, ///< Internal AMDGPU-HSA-Backend. AMDGPUPAL, ///< Internal AMDGPU-PAL-Backend. - ShadyCompute, ///< Internal Shady Compute Backend. HLS, ///< Internal HLS-Backend. OffloadEnd = HLS, Parallel, ///< Internal Parallel-CPU-Backend.