mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2025-12-27 09:45:19 +01:00
Implement some simple IR optimizations (get/set eliminiation and DCE)
This commit is contained in:
parent
90d317b868
commit
5fbfc6c155
16 changed files with 544 additions and 300 deletions
37
src/ir_opt/dead_code_elimination_pass.cpp
Normal file
37
src/ir_opt/dead_code_elimination_pass.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* This file is part of the dynarmic project.
|
||||
* Copyright (c) 2016 MerryMage
|
||||
* This software may be used and distributed according to the terms of the GNU
|
||||
* General Public License version 2 or any later version.
|
||||
*/
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "frontend/ir/ir.h"
|
||||
#include "ir_opt/passes.h"
|
||||
|
||||
namespace Dynarmic {
|
||||
namespace Optimization {
|
||||
|
||||
void DeadCodeElimination(IR::Block& block) {
|
||||
const auto is_side_effect_free = [](IR::Opcode op) -> bool {
|
||||
return IR::GetTypeOf(op) != IR::Type::Void;
|
||||
};
|
||||
|
||||
// We iterate over the instructions in reverse order.
|
||||
// This is because removing an instruction reduces the number of uses for earlier instructions.
|
||||
|
||||
if (block.instructions.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto iter = block.instructions.end();
|
||||
do {
|
||||
--iter;
|
||||
if (!(*iter)->HasUses() && is_side_effect_free((*iter)->GetOpcode())) {
|
||||
(*iter)->Invalidate();
|
||||
iter = block.instructions.erase(iter);
|
||||
}
|
||||
} while (iter != block.instructions.begin());
|
||||
}
|
||||
|
||||
} // namespace Optimization
|
||||
} // namespace Dynarmic
|
||||
Loading…
Add table
Add a link
Reference in a new issue