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.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 18:39:49 +01:00
|
|
|
#include <map>
|
|
|
|
|
2016-07-21 21:48:45 +01:00
|
|
|
#include "common/assert.h"
|
2016-08-17 15:53:36 +01:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "frontend/ir/basic_block.h"
|
|
|
|
#include "frontend/ir/microinstruction.h"
|
2016-07-21 21:48:45 +01:00
|
|
|
#include "ir_opt/passes.h"
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
namespace Dynarmic::Optimization {
|
2016-07-21 21:48:45 +01:00
|
|
|
|
|
|
|
void VerificationPass(const IR::Block& block) {
|
basic_block: Add proxy member functions for the instruction list
Currently basic block kind of acts like a 'dumb struct' which makes things
a little more verbose to write (as opposed to keeping it all in one place,
I guess). It's also a little wonky conceptually, considering a block is
composed of instructions (i.e. 'contains' them).
So providing accessors that make it act more like a container can make working
with algorithms a little nicer. It also makes the API a little more
defined.
Ideally, the list would be only available through a function, but
currently, the pool allocator is exposed, which seems somewhat odd,
considering the block itself should manage its overall allocations
(with placement new, and regular new), rather than putting that
sanitizing directly on the IR emitter (it should just care about emission,
not block state). However, recontaining that can be followed up with,
as it's very trivial to do.
2016-08-21 17:35:30 +01:00
|
|
|
for (const auto& inst : block) {
|
2016-08-13 18:39:49 +01:00
|
|
|
for (size_t i = 0; i < inst.NumArgs(); i++) {
|
|
|
|
IR::Type t1 = inst.GetArg(i).GetType();
|
|
|
|
IR::Type t2 = IR::GetArgTypeOf(inst.GetOpcode(), i);
|
2016-08-19 01:34:14 +01:00
|
|
|
if (!IR::AreTypesCompatible(t1, t2)) {
|
2016-08-17 13:29:05 +01:00
|
|
|
puts(IR::DumpBlock(block).c_str());
|
|
|
|
ASSERT(false);
|
|
|
|
}
|
2016-08-13 18:39:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<IR::Inst*, size_t> actual_uses;
|
basic_block: Add proxy member functions for the instruction list
Currently basic block kind of acts like a 'dumb struct' which makes things
a little more verbose to write (as opposed to keeping it all in one place,
I guess). It's also a little wonky conceptually, considering a block is
composed of instructions (i.e. 'contains' them).
So providing accessors that make it act more like a container can make working
with algorithms a little nicer. It also makes the API a little more
defined.
Ideally, the list would be only available through a function, but
currently, the pool allocator is exposed, which seems somewhat odd,
considering the block itself should manage its overall allocations
(with placement new, and regular new), rather than putting that
sanitizing directly on the IR emitter (it should just care about emission,
not block state). However, recontaining that can be followed up with,
as it's very trivial to do.
2016-08-21 17:35:30 +01:00
|
|
|
for (const auto& inst : block) {
|
2016-08-13 18:39:49 +01:00
|
|
|
for (size_t i = 0; i < inst.NumArgs(); i++) {
|
|
|
|
if (!inst.GetArg(i).IsImmediate()) {
|
|
|
|
actual_uses[inst.GetArg(i).GetInst()]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& pair : actual_uses) {
|
2016-11-30 21:51:06 +00:00
|
|
|
ASSERT(pair.first->UseCount() == pair.second);
|
2016-07-21 21:48:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
} // namespace Dynarmic::Optimization
|