IR: Clean up getNumberOfOperands

- Use std::array
- Make arrays constexpr where their contents aren't modified.
This commit is contained in:
Lioncash 2017-01-17 20:03:42 -05:00
parent d3aed03563
commit 89473d5996
1 changed files with 16 additions and 15 deletions

View File

@ -121,6 +121,7 @@ TODO (in no particular order):
#endif #endif
#include <algorithm> #include <algorithm>
#include <array>
#include <cinttypes> #include <cinttypes>
#include <ctime> #include <ctime>
#include <memory> #include <memory>
@ -1371,22 +1372,22 @@ unsigned IRBuilder::getComplexity(InstLoc I) const
unsigned IRBuilder::getNumberOfOperands(InstLoc I) const unsigned IRBuilder::getNumberOfOperands(InstLoc I) const
{ {
static unsigned numberOfOperands[256]; static std::array<u32, 256> number_of_operands;
static bool initialized = false; static bool initialized = false;
if (!initialized) if (!initialized)
{ {
initialized = true; initialized = true;
std::fill_n(numberOfOperands, sizeof(numberOfOperands) / sizeof(numberOfOperands[0]), -1U);
numberOfOperands[Nop] = 0; number_of_operands.fill(0xFFFFFFFF);
numberOfOperands[CInt16] = 0; number_of_operands[Nop] = 0;
numberOfOperands[CInt32] = 0; number_of_operands[CInt16] = 0;
number_of_operands[CInt32] = 0;
static unsigned ZeroOp[] = { static constexpr std::array<u32, 12> zero_op = {
LoadCR, LoadLink, LoadMSR, LoadGReg, LoadCTR, InterpreterBranch, LoadCR, LoadLink, LoadMSR, LoadGReg, LoadCTR, InterpreterBranch,
LoadCarry, RFIExit, LoadFReg, LoadFRegDENToZero, LoadGQR, Int3, LoadCarry, RFIExit, LoadFReg, LoadFRegDENToZero, LoadGQR, Int3,
}; };
static unsigned UOp[] = { static constexpr std::array<u32, 39> unary_op = {
StoreLink, StoreLink,
BranchUncond, BranchUncond,
StoreCR, StoreCR,
@ -1427,7 +1428,7 @@ unsigned IRBuilder::getNumberOfOperands(InstLoc I) const
FastCRGTSet, FastCRGTSet,
FastCRLTSet, FastCRLTSet,
}; };
static unsigned BiOp[] = { static constexpr std::array<u32, 44> binary_op = {
BranchCond, BranchCond,
IdleBranch, IdleBranch,
And, And,
@ -1473,17 +1474,17 @@ unsigned IRBuilder::getNumberOfOperands(InstLoc I) const
FPMerge11, FPMerge11,
FDCmpCR, FDCmpCR,
}; };
for (auto& op : ZeroOp) for (auto op : zero_op)
numberOfOperands[op] = 0; number_of_operands[op] = 0;
for (auto& op : UOp) for (auto op : unary_op)
numberOfOperands[op] = 1; number_of_operands[op] = 1;
for (auto& op : BiOp) for (auto op : binary_op)
numberOfOperands[op] = 2; number_of_operands[op] = 2;
} }
return numberOfOperands[getOpcode(*I)]; return number_of_operands[getOpcode(*I)];
} }
// Performs a few simplifications for commutative operators // Performs a few simplifications for commutative operators