From 7d535eaba63ba019d5f5bf1cea3906e308d9a91f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 11 Apr 2019 18:18:26 -0400 Subject: [PATCH] ir_opt/a32_constant_memory_reads_pass: Apply const where applicable to locals Makes immutable state just slightly more explicit. --- src/ir_opt/a32_constant_memory_reads_pass.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/ir_opt/a32_constant_memory_reads_pass.cpp b/src/ir_opt/a32_constant_memory_reads_pass.cpp index 66aaa320..92426a47 100644 --- a/src/ir_opt/a32_constant_memory_reads_pass.cpp +++ b/src/ir_opt/a32_constant_memory_reads_pass.cpp @@ -16,52 +16,56 @@ void A32ConstantMemoryReads(IR::Block& block, A32::UserCallbacks* cb) { for (auto& inst : block) { switch (inst.GetOpcode()) { case IR::Opcode::A32SetCFlag: { - IR::Value arg = inst.GetArg(0); + const IR::Value arg = inst.GetArg(0); if (!arg.IsImmediate() && arg.GetInst()->GetOpcode() == IR::Opcode::A32GetCFlag) { inst.Invalidate(); } break; } case IR::Opcode::A32ReadMemory8: { - if (!inst.AreAllArgsImmediates()) + if (!inst.AreAllArgsImmediates()) { break; + } - u32 vaddr = inst.GetArg(0).GetU32(); + const u32 vaddr = inst.GetArg(0).GetU32(); if (cb->IsReadOnlyMemory(vaddr)) { - u8 value_from_memory = cb->MemoryRead8(vaddr); + const u8 value_from_memory = cb->MemoryRead8(vaddr); inst.ReplaceUsesWith(IR::Value{value_from_memory}); } break; } case IR::Opcode::A32ReadMemory16: { - if (!inst.AreAllArgsImmediates()) + if (!inst.AreAllArgsImmediates()) { break; + } - u32 vaddr = inst.GetArg(0).GetU32(); + const u32 vaddr = inst.GetArg(0).GetU32(); if (cb->IsReadOnlyMemory(vaddr)) { - u16 value_from_memory = cb->MemoryRead16(vaddr); + const u16 value_from_memory = cb->MemoryRead16(vaddr); inst.ReplaceUsesWith(IR::Value{value_from_memory}); } break; } case IR::Opcode::A32ReadMemory32: { - if (!inst.AreAllArgsImmediates()) + if (!inst.AreAllArgsImmediates()) { break; + } - u32 vaddr = inst.GetArg(0).GetU32(); + const u32 vaddr = inst.GetArg(0).GetU32(); if (cb->IsReadOnlyMemory(vaddr)) { - u32 value_from_memory = cb->MemoryRead32(vaddr); + const u32 value_from_memory = cb->MemoryRead32(vaddr); inst.ReplaceUsesWith(IR::Value{value_from_memory}); } break; } case IR::Opcode::A32ReadMemory64: { - if (!inst.AreAllArgsImmediates()) + if (!inst.AreAllArgsImmediates()) { break; + } - u32 vaddr = inst.GetArg(0).GetU32(); + const u32 vaddr = inst.GetArg(0).GetU32(); if (cb->IsReadOnlyMemory(vaddr)) { - u64 value_from_memory = cb->MemoryRead64(vaddr); + const u64 value_from_memory = cb->MemoryRead64(vaddr); inst.ReplaceUsesWith(IR::Value{value_from_memory}); } break;