Reduce Inst::NumArgs calls / opcodes: Prefer std::vector to std::map (#425)
* Don't call Inst::NumArgs in a loop conditional * opcodes: Prefer a simple std::vector instead of a std::map
This commit is contained in:
parent
7957066968
commit
735e6c58be
@ -229,7 +229,8 @@ bool Argument::IsInMemory() const {
|
||||
|
||||
RegAlloc::ArgumentInfo RegAlloc::GetArgumentInfo(IR::Inst* inst) {
|
||||
ArgumentInfo ret = {Argument{*this}, Argument{*this}, Argument{*this}, Argument{*this}};
|
||||
for (size_t i = 0; i < inst->NumArgs(); i++) {
|
||||
const size_t num_args = inst->NumArgs();
|
||||
for (size_t i = 0; i < num_args; i++) {
|
||||
const IR::Value& arg = inst->GetArg(i);
|
||||
ret[i].value = arg;
|
||||
if (!arg.IsImmediate() && !IsValuelessType(arg.GetType())) {
|
||||
|
@ -45,34 +45,34 @@ constexpr Type NZCV = Type::NZCVFlags;
|
||||
constexpr Type Cond = Type::Cond;
|
||||
constexpr Type Table = Type::Table;
|
||||
|
||||
static const std::map<Opcode, Meta> opcode_info {{
|
||||
#define OPCODE(name, type, ...) { Opcode::name, { #name, type, { __VA_ARGS__ } } },
|
||||
#define A32OPC(name, type, ...) { Opcode::A32##name, { #name, type, { __VA_ARGS__ } } },
|
||||
#define A64OPC(name, type, ...) { Opcode::A64##name, { #name, type, { __VA_ARGS__ } } },
|
||||
static const std::vector<Meta> opcode_info {
|
||||
#define OPCODE(name, type, ...) { #name, type, { __VA_ARGS__ } },
|
||||
#define A32OPC(name, type, ...) { #name, type, { __VA_ARGS__ } },
|
||||
#define A64OPC(name, type, ...) { #name, type, { __VA_ARGS__ } },
|
||||
#include "opcodes.inc"
|
||||
#undef OPCODE
|
||||
#undef A32OPC
|
||||
#undef A64OPC
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace OpcodeInfo
|
||||
|
||||
Type GetTypeOf(Opcode op) {
|
||||
return OpcodeInfo::opcode_info.at(op).type;
|
||||
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).type;
|
||||
}
|
||||
|
||||
size_t GetNumArgsOf(Opcode op) {
|
||||
return OpcodeInfo::opcode_info.at(op).arg_types.size();
|
||||
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).arg_types.size();
|
||||
}
|
||||
|
||||
Type GetArgTypeOf(Opcode op, size_t arg_index) {
|
||||
return OpcodeInfo::opcode_info.at(op).arg_types.at(arg_index);
|
||||
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).arg_types.at(arg_index);
|
||||
}
|
||||
|
||||
std::string GetNameOf(Opcode op) {
|
||||
if (OpcodeInfo::opcode_info.count(op) == 0)
|
||||
if (OpcodeInfo::opcode_info.size() <= static_cast<size_t>(op))
|
||||
return fmt::format("Unknown Opcode {}", static_cast<Opcode>(op));
|
||||
return OpcodeInfo::opcode_info.at(op).name;
|
||||
return OpcodeInfo::opcode_info.at(static_cast<size_t>(op)).name;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, Opcode opcode) {
|
||||
|
@ -18,7 +18,8 @@ namespace Dynarmic::Optimization {
|
||||
|
||||
void VerificationPass(const IR::Block& block) {
|
||||
for (const auto& inst : block) {
|
||||
for (size_t i = 0; i < inst.NumArgs(); i++) {
|
||||
const size_t num_args = inst.NumArgs();
|
||||
for (size_t i = 0; i < num_args; i++) {
|
||||
IR::Type t1 = inst.GetArg(i).GetType();
|
||||
IR::Type t2 = IR::GetArgTypeOf(inst.GetOpcode(), i);
|
||||
if (!IR::AreTypesCompatible(t1, t2)) {
|
||||
@ -30,7 +31,8 @@ void VerificationPass(const IR::Block& block) {
|
||||
|
||||
std::map<IR::Inst*, size_t> actual_uses;
|
||||
for (const auto& inst : block) {
|
||||
for (size_t i = 0; i < inst.NumArgs(); i++) {
|
||||
const size_t num_args = inst.NumArgs();
|
||||
for (size_t i = 0; i < num_args; i++) {
|
||||
if (!inst.GetArg(i).IsImmediate()) {
|
||||
actual_uses[inst.GetArg(i).GetInst()]++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user