Merge pull request #4680 from lioncash/ir

IR: Minor changes
This commit is contained in:
Matthew Parlane 2017-01-18 17:31:40 +13:00 committed by GitHub
commit 41f7995916
2 changed files with 30 additions and 40 deletions

View File

@ -121,6 +121,7 @@ TODO (in no particular order):
#endif
#include <algorithm>
#include <array>
#include <cinttypes>
#include <ctime>
#include <memory>
@ -149,6 +150,11 @@ void IRBuilder::Reset()
MarkUsed.clear();
MarkUsed.reserve(100000);
InvalidateCaches();
}
void IRBuilder::InvalidateCaches()
{
GRegCache = {};
GRegCacheStore = {};
@ -1208,25 +1214,7 @@ InstLoc IRBuilder::FoldICmpCRUnsigned(InstLoc Op1, InstLoc Op2)
InstLoc IRBuilder::FoldFallBackToInterpreter(InstLoc Op1, InstLoc Op2)
{
for (unsigned i = 0; i < 32; i++)
{
GRegCache[i] = nullptr;
GRegCacheStore[i] = nullptr;
FRegCache[i] = nullptr;
FRegCacheStore[i] = nullptr;
}
CarryCache = nullptr;
CarryCacheStore = nullptr;
for (unsigned i = 0; i < 8; i++)
{
CRCache[i] = nullptr;
CRCacheStore[i] = nullptr;
}
CTRCache = nullptr;
CTRCacheStore = nullptr;
InvalidateCaches();
return EmitBiOp(FallBackToInterpreter, Op1, Op2);
}
@ -1371,22 +1359,22 @@ unsigned IRBuilder::getComplexity(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;
if (!initialized)
{
initialized = true;
std::fill_n(numberOfOperands, sizeof(numberOfOperands) / sizeof(numberOfOperands[0]), -1U);
numberOfOperands[Nop] = 0;
numberOfOperands[CInt16] = 0;
numberOfOperands[CInt32] = 0;
number_of_operands.fill(0xFFFFFFFF);
number_of_operands[Nop] = 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,
LoadCarry, RFIExit, LoadFReg, LoadFRegDENToZero, LoadGQR, Int3,
};
static unsigned UOp[] = {
static constexpr std::array<u32, 39> unary_op = {
StoreLink,
BranchUncond,
StoreCR,
@ -1427,7 +1415,7 @@ unsigned IRBuilder::getNumberOfOperands(InstLoc I) const
FastCRGTSet,
FastCRLTSet,
};
static unsigned BiOp[] = {
static constexpr std::array<u32, 44> binary_op = {
BranchCond,
IdleBranch,
And,
@ -1473,17 +1461,17 @@ unsigned IRBuilder::getNumberOfOperands(InstLoc I) const
FPMerge11,
FDCmpCR,
};
for (auto& op : ZeroOp)
numberOfOperands[op] = 0;
for (auto op : zero_op)
number_of_operands[op] = 0;
for (auto& op : UOp)
numberOfOperands[op] = 1;
for (auto op : unary_op)
number_of_operands[op] = 1;
for (auto& op : BiOp)
numberOfOperands[op] = 2;
for (auto op : binary_op)
number_of_operands[op] = 2;
}
return numberOfOperands[getOpcode(*I)];
return number_of_operands[getOpcode(*I)];
}
// Performs a few simplifications for commutative operators

View File

@ -182,25 +182,25 @@ enum Opcode
Int3
};
typedef unsigned Inst;
typedef Inst* InstLoc;
using Inst = u32;
using InstLoc = Inst*;
unsigned inline getOpcode(Inst i)
constexpr u32 getOpcode(Inst i)
{
return i & 255;
}
unsigned inline isImm(Inst i)
constexpr bool isImm(Inst i)
{
return getOpcode(i) >= CInt16 && getOpcode(i) <= CInt32;
}
unsigned inline isICmp(Inst i)
constexpr bool isICmp(Inst i)
{
return getOpcode(i) >= ICmpEq && getOpcode(i) <= ICmpSle;
}
unsigned inline isFResult(Inst i)
constexpr bool isFResult(Inst i)
{
return getOpcode(i) > FResult_Start && getOpcode(i) < FResult_End;
}
@ -388,6 +388,8 @@ public:
void WriteToFile(u64 codeHash);
private:
void InvalidateCaches();
InstLoc EmitZeroOp(unsigned Opcode, unsigned extra);
InstLoc EmitUOp(unsigned OpCode, InstLoc Op1, unsigned extra = 0);
InstLoc EmitBiOp(unsigned OpCode, InstLoc Op1, InstLoc Op2, unsigned extra = 0);