2016-07-21 21:48:45 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2017-02-19 11:04:31 +00:00
|
|
|
#include "common/iterator_util.h"
|
2016-08-17 15:53:36 +01:00
|
|
|
#include "frontend/ir/basic_block.h"
|
2016-07-21 21:48:45 +01:00
|
|
|
#include "ir_opt/passes.h"
|
|
|
|
|
|
|
|
namespace Dynarmic {
|
|
|
|
namespace Optimization {
|
|
|
|
|
|
|
|
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 11:04:31 +00:00
|
|
|
for (auto& inst : Common::Reverse(block)) {
|
|
|
|
if (!inst.HasUses() && !inst.MayHaveSideEffects()) {
|
|
|
|
inst.Invalidate();
|
2016-07-21 21:48:45 +01:00
|
|
|
}
|
2017-02-19 11:04:31 +00:00
|
|
|
}
|
2016-07-21 21:48:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Optimization
|
|
|
|
} // namespace Dynarmic
|