From b485553ed855ae4fc5b96f4753e8e66f89d21abd Mon Sep 17 00:00:00 2001 From: Yang Liu Date: Sat, 17 Feb 2024 14:38:31 +0800 Subject: backend/rv64: Implement Identity --- src/dynarmic/backend/riscv64/emit_riscv64.cpp | 8 +++++++- src/dynarmic/backend/riscv64/reg_alloc.cpp | 13 +++++++++++++ src/dynarmic/backend/riscv64/reg_alloc.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/dynarmic/backend/riscv64/emit_riscv64.cpp b/src/dynarmic/backend/riscv64/emit_riscv64.cpp index 1ac24b3e..54eb73c1 100644 --- a/src/dynarmic/backend/riscv64/emit_riscv64.cpp +++ b/src/dynarmic/backend/riscv64/emit_riscv64.cpp @@ -23,12 +23,18 @@ namespace Dynarmic::Backend::RV64 { template void EmitIR(biscuit::Assembler&, EmitContext&, IR::Inst*) { - ASSERT_FALSE("Unimplemented opcode {}", op); + ASSERT_FALSE("Unimplemented opcode {} ", op); } template<> void EmitIR(biscuit::Assembler&, EmitContext&, IR::Inst*) {} +template<> +void EmitIR(biscuit::Assembler&, EmitContext& ctx, IR::Inst* inst) { + auto args = ctx.reg_alloc.GetArgumentInfo(inst); + ctx.reg_alloc.DefineAsExisting(inst, args[0]); +} + template<> void EmitIR(biscuit::Assembler& as, EmitContext& ctx, IR::Inst* inst); template<> diff --git a/src/dynarmic/backend/riscv64/reg_alloc.cpp b/src/dynarmic/backend/riscv64/reg_alloc.cpp index 245c961f..1451b430 100644 --- a/src/dynarmic/backend/riscv64/reg_alloc.cpp +++ b/src/dynarmic/backend/riscv64/reg_alloc.cpp @@ -125,6 +125,19 @@ void RegAlloc::UpdateAllUses() { } } +void RegAlloc::DefineAsExisting(IR::Inst* inst, Argument& arg) { + ASSERT(!ValueLocation(inst)); + + if (arg.value.IsImmediate()) { + inst->ReplaceUsesWith(arg.value); + return; + } + + auto& info = ValueInfo(arg.value.GetInst()); + info.values.emplace_back(inst); + info.expected_uses += inst->UseCount(); +} + void RegAlloc::AssertNoMoreUses() const { const auto is_empty = [](const auto& i) { return i.IsCompletelyEmpty(); }; ASSERT(std::all_of(gprs.begin(), gprs.end(), is_empty)); diff --git a/src/dynarmic/backend/riscv64/reg_alloc.h b/src/dynarmic/backend/riscv64/reg_alloc.h index e457bc84..d80f588b 100644 --- a/src/dynarmic/backend/riscv64/reg_alloc.h +++ b/src/dynarmic/backend/riscv64/reg_alloc.h @@ -118,6 +118,8 @@ public: auto WriteX(IR::Inst* inst) { return RAReg{*this, true, IR::Value{inst}}; } auto WriteD(IR::Inst* inst) { return RAReg{*this, true, IR::Value{inst}}; } + void DefineAsExisting(IR::Inst* inst, Argument& arg); + void SpillAll(); template -- cgit v1.2.3