From 72c87d11e4d03e0d77a4edb9b86494d454e3ee3b Mon Sep 17 00:00:00 2001 From: Merry Date: Wed, 20 Jul 2022 16:53:48 +0100 Subject: [PATCH] a32_get_set_elimination_pass: Correct insertion point --- src/dynarmic/ir/ir_emitter.h | 14 ++++++++++++-- .../ir/opt/a32_get_set_elimination_pass.cpp | 4 ++-- src/dynarmic/ir/opt/a64_callback_config_pass.cpp | 2 +- src/dynarmic/ir/opt/polyfill_pass.cpp | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/dynarmic/ir/ir_emitter.h b/src/dynarmic/ir/ir_emitter.h index 82b8acc0..7c5bb0c7 100644 --- a/src/dynarmic/ir/ir_emitter.h +++ b/src/dynarmic/ir/ir_emitter.h @@ -393,14 +393,24 @@ public: void SetTerm(const Terminal& terminal); - void SetInsertionPoint(IR::Inst* new_insertion_point) { + void SetInsertionPointBefore(IR::Inst* new_insertion_point) { insertion_point = IR::Block::iterator{*new_insertion_point}; } - void SetInsertionPoint(IR::Block::iterator new_insertion_point) { + void SetInsertionPointBefore(IR::Block::iterator new_insertion_point) { insertion_point = new_insertion_point; } + void SetInsertionPointAfter(IR::Inst* new_insertion_point) { + insertion_point = IR::Block::iterator{*new_insertion_point}; + ++insertion_point; + } + + void SetInsertionPointAfter(IR::Block::iterator new_insertion_point) { + insertion_point = new_insertion_point; + ++insertion_point; + } + protected: IR::Block::iterator insertion_point; diff --git a/src/dynarmic/ir/opt/a32_get_set_elimination_pass.cpp b/src/dynarmic/ir/opt/a32_get_set_elimination_pass.cpp index becf118d..2abd52b1 100644 --- a/src/dynarmic/ir/opt/a32_get_set_elimination_pass.cpp +++ b/src/dynarmic/ir/opt/a32_get_set_elimination_pass.cpp @@ -209,7 +209,7 @@ void A32GetSetElimination(IR::Block& block, A32GetSetEliminationOptions opt) { } if (opt.convert_nz_to_nzc && !cpsr_info.c.register_value.IsEmpty()) { - ir.SetInsertionPoint(inst); + ir.SetInsertionPointAfter(inst); ir.SetCpsrNZC(IR::NZCV{inst->GetArg(0)}, ir.GetCFlag()); inst->Invalidate(); break; @@ -223,7 +223,7 @@ void A32GetSetElimination(IR::Block& block, A32GetSetEliminationOptions opt) { } case IR::Opcode::A32SetCpsrNZC: { if (opt.convert_nzc_to_nz && !inst->GetArg(1).IsImmediate() && inst->GetArg(1).GetInstRecursive()->GetOpcode() == IR::Opcode::A32GetCFlag) { - ir.SetInsertionPoint(inst); + ir.SetInsertionPointAfter(inst); ir.SetCpsrNZ(IR::NZCV{inst->GetArg(0)}); inst->Invalidate(); break; diff --git a/src/dynarmic/ir/opt/a64_callback_config_pass.cpp b/src/dynarmic/ir/opt/a64_callback_config_pass.cpp index 1e0195c4..79d97695 100644 --- a/src/dynarmic/ir/opt/a64_callback_config_pass.cpp +++ b/src/dynarmic/ir/opt/a64_callback_config_pass.cpp @@ -26,7 +26,7 @@ void A64CallbackConfigPass(IR::Block& block, const A64::UserConfig& conf) { if (op == A64::DataCacheOperation::ZeroByVA) { A64::IREmitter ir{block}; ir.current_location = A64::LocationDescriptor{IR::LocationDescriptor{inst.GetArg(0).GetU64()}}; - ir.SetInsertionPoint(&inst); + ir.SetInsertionPointBefore(&inst); size_t bytes = 4 << static_cast(conf.dczid_el0 & 0b1111); IR::U64 addr{inst.GetArg(2)}; diff --git a/src/dynarmic/ir/opt/polyfill_pass.cpp b/src/dynarmic/ir/opt/polyfill_pass.cpp index 77800ddc..8580f482 100644 --- a/src/dynarmic/ir/opt/polyfill_pass.cpp +++ b/src/dynarmic/ir/opt/polyfill_pass.cpp @@ -148,7 +148,7 @@ void PolyfillPass(IR::Block& block, const PolyfillOptions& polyfill) { IR::IREmitter ir{block}; for (auto& inst : block) { - ir.SetInsertionPoint(&inst); + ir.SetInsertionPointBefore(&inst); switch (inst.GetOpcode()) { case IR::Opcode::SHA256MessageSchedule0: