2016-07-21 22:48:45 +02:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
|
* Copyright (c) 2016 MerryMage
|
2020-04-23 16:25:11 +02:00
|
|
|
* SPDX-License-Identifier: 0BSD
|
2016-07-21 22:48:45 +02:00
|
|
|
*/
|
|
|
|
|
|
2017-02-19 12:04:31 +01:00
|
|
|
#include "common/iterator_util.h"
|
2016-08-17 16:53:36 +02:00
|
|
|
#include "frontend/ir/basic_block.h"
|
2016-07-21 22:48:45 +02:00
|
|
|
#include "ir_opt/passes.h"
|
|
|
|
|
|
2018-01-26 14:51:48 +01:00
|
|
|
namespace Dynarmic::Optimization {
|
2016-07-21 22:48:45 +02:00
|
|
|
|
|
|
|
|
void DeadCodeElimination(IR::Block& block) {
|
|
|
|
|
// We iterate over the instructions in reverse order.
|
|
|
|
|
// This is because removing an instruction reduces the number of uses for earlier instructions.
|
2017-02-19 12:04:31 +01:00
|
|
|
for (auto& inst : Common::Reverse(block)) {
|
|
|
|
|
if (!inst.HasUses() && !inst.MayHaveSideEffects()) {
|
|
|
|
|
inst.Invalidate();
|
2016-07-21 22:48:45 +02:00
|
|
|
}
|
2017-02-19 12:04:31 +01:00
|
|
|
}
|
2016-07-21 22:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Dynarmic
|