diff --git a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp index a9107b1e81..97bb83fa9e 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp @@ -77,7 +77,7 @@ struct RegInfo final : private NonCopyable u32 numFSpills = 0; u32 exitNumber = 0; - RegInfo(JitIL* j, InstLoc f, u32 insts) : Jit(j), FirstI(f), IInfo(insts), lastUsed(insts) {} + RegInfo(JitIL* j, InstLoc f, size_t insts) : Jit(j), FirstI(f), IInfo(insts), lastUsed(insts) {} }; static BitSet32 regsInUse(RegInfo& R) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp index 6fe5843c8c..f7348ba34e 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp @@ -137,6 +137,34 @@ using namespace Gen; namespace IREmitter { +IRBuilder::IRBuilder() +{ + Reset(); +} + +void IRBuilder::Reset() +{ + InstList.clear(); + InstList.reserve(100000); + MarkUsed.clear(); + MarkUsed.reserve(100000); + + GRegCache = {}; + GRegCacheStore = {}; + + FRegCache = {}; + FRegCacheStore = {}; + + CarryCache = nullptr; + CarryCacheStore = nullptr; + + CRCache = {}; + CRCacheStore = {}; + + CTRCache = nullptr; + CTRCacheStore = nullptr; +} + InstLoc IRBuilder::EmitZeroOp(unsigned Opcode, unsigned extra = 0) { InstLoc curIndex = InstList.data() + InstList.size(); @@ -1741,15 +1769,15 @@ void IRBuilder::WriteToFile(u64 codeHash) const InstLoc lastCurReadPtr = curReadPtr; StartForwardPass(); - const unsigned numInsts = getNumInsts(); - for (unsigned int i = 0; i < numInsts; ++i) + const size_t numInsts = getNumInsts(); + for (size_t i = 0; i < numInsts; ++i) { const InstLoc I = ReadForward(); const unsigned opcode = getOpcode(*I); const bool thisUsed = IsMarkUsed(I) || alwaysUseds.find(opcode) != alwaysUseds.end(); // Line number - fprintf(file, "%4u", i); + fprintf(file, "%4zu", i); if (!thisUsed) fprintf(file, "%*c", 32, ' '); @@ -1767,7 +1795,7 @@ void IRBuilder::WriteToFile(u64 codeHash) if (isImm(*inst)) fprintf(file, " 0x%08x", GetImmValue(inst)); else - fprintf(file, " %10u", i - (unsigned int)(I - inst)); + fprintf(file, " %10zu", i - static_cast(I - inst)); } // Op2 @@ -1778,7 +1806,7 @@ void IRBuilder::WriteToFile(u64 codeHash) if (isImm(*inst)) fprintf(file, " 0x%08x", GetImmValue(inst)); else - fprintf(file, " %10u", i - (unsigned int)(I - inst)); + fprintf(file, " %10zu", i - static_cast(I - inst)); } if (extra8Regs.count(opcode)) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 01a140a0b1..2321037ef8 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -4,9 +4,12 @@ #pragma once +#include +#include #include #include "Common/CommonTypes.h" +#include "Common/NonCopyable.h" namespace IREmitter { @@ -226,39 +229,13 @@ InstLoc inline getOp2(InstLoc i) return i; } -class IRBuilder +class IRBuilder final : private NonCopyable { -private: - 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); - - InstLoc FoldAdd(InstLoc Op1, InstLoc Op2); - InstLoc FoldSub(InstLoc Op1, InstLoc Op2); - InstLoc FoldMul(InstLoc Op1, InstLoc Op2); - InstLoc FoldMulHighUnsigned(InstLoc Op1, InstLoc Op2); - InstLoc FoldAnd(InstLoc Op1, InstLoc Op2); - InstLoc FoldOr(InstLoc Op1, InstLoc Op2); - InstLoc FoldRol(InstLoc Op1, InstLoc Op2); - InstLoc FoldShl(InstLoc Op1, InstLoc Op2); - InstLoc FoldShrl(InstLoc Op1, InstLoc Op2); - InstLoc FoldXor(InstLoc Op1, InstLoc Op2); - InstLoc FoldBranchCond(InstLoc Op1, InstLoc Op2); - InstLoc FoldIdleBranch(InstLoc Op1, InstLoc Op2); - InstLoc FoldICmp(unsigned Opcode, InstLoc Op1, InstLoc Op2); - InstLoc FoldICmpCRSigned(InstLoc Op1, InstLoc Op2); - InstLoc FoldICmpCRUnsigned(InstLoc Op1, InstLoc Op2); - InstLoc FoldDoubleBiOp(unsigned Opcode, InstLoc Op1, InstLoc Op2); - - InstLoc FoldFallBackToInterpreter(InstLoc Op1, InstLoc Op2); - - InstLoc FoldZeroOp(unsigned Opcode, unsigned extra); - InstLoc FoldUOp(unsigned OpCode, InstLoc Op1, unsigned extra = 0); - InstLoc FoldBiOp(unsigned OpCode, InstLoc Op1, InstLoc Op2, unsigned extra = 0); - - unsigned ComputeKnownZeroBits(InstLoc I) const; - public: + IRBuilder(); + + void Reset(); + InstLoc EmitIntConst(unsigned value) { return EmitIntConst64(value); } InstLoc EmitIntConst64(u64 value); @@ -403,45 +380,42 @@ public: InstLoc ReadForward() { return curReadPtr++; } InstLoc ReadBackward() { return --curReadPtr; } InstLoc getFirstInst() { return InstList.data(); } - unsigned int getNumInsts() { return (unsigned int)InstList.size(); } - unsigned int ReadInst(InstLoc I) { return *I; } + size_t getNumInsts() const { return InstList.size(); } unsigned int GetImmValue(InstLoc I) const { return (u32)GetImmValue64(I); } u64 GetImmValue64(InstLoc I) const; void SetMarkUsed(InstLoc I); bool IsMarkUsed(InstLoc I) const; void WriteToFile(u64 codeHash); - void Reset() - { - InstList.clear(); - InstList.reserve(100000); - MarkUsed.clear(); - MarkUsed.reserve(100000); - - 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; - } - - IRBuilder() { Reset(); } private: - IRBuilder(IRBuilder&); // DO NOT IMPLEMENT + 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); + + InstLoc FoldAdd(InstLoc Op1, InstLoc Op2); + InstLoc FoldSub(InstLoc Op1, InstLoc Op2); + InstLoc FoldMul(InstLoc Op1, InstLoc Op2); + InstLoc FoldMulHighUnsigned(InstLoc Op1, InstLoc Op2); + InstLoc FoldAnd(InstLoc Op1, InstLoc Op2); + InstLoc FoldOr(InstLoc Op1, InstLoc Op2); + InstLoc FoldRol(InstLoc Op1, InstLoc Op2); + InstLoc FoldShl(InstLoc Op1, InstLoc Op2); + InstLoc FoldShrl(InstLoc Op1, InstLoc Op2); + InstLoc FoldXor(InstLoc Op1, InstLoc Op2); + InstLoc FoldBranchCond(InstLoc Op1, InstLoc Op2); + InstLoc FoldICmp(unsigned Opcode, InstLoc Op1, InstLoc Op2); + InstLoc FoldICmpCRSigned(InstLoc Op1, InstLoc Op2); + InstLoc FoldICmpCRUnsigned(InstLoc Op1, InstLoc Op2); + InstLoc FoldDoubleBiOp(unsigned Opcode, InstLoc Op1, InstLoc Op2); + + InstLoc FoldFallBackToInterpreter(InstLoc Op1, InstLoc Op2); + + InstLoc FoldZeroOp(unsigned Opcode, unsigned extra); + InstLoc FoldUOp(unsigned OpCode, InstLoc Op1, unsigned extra = 0); + InstLoc FoldBiOp(unsigned OpCode, InstLoc Op1, InstLoc Op2, unsigned extra = 0); + + unsigned ComputeKnownZeroBits(InstLoc I) const; + bool isSameValue(InstLoc Op1, InstLoc Op2) const; unsigned getComplexity(InstLoc I) const; unsigned getNumberOfOperands(InstLoc I) const; @@ -453,15 +427,15 @@ private: std::vector MarkUsed; // Used for IRWriter std::vector ConstList; InstLoc curReadPtr; - InstLoc GRegCache[32]; - InstLoc GRegCacheStore[32]; - InstLoc FRegCache[32]; - InstLoc FRegCacheStore[32]; + std::array GRegCache; + std::array GRegCacheStore; + std::array FRegCache; + std::array FRegCacheStore; InstLoc CarryCache; InstLoc CarryCacheStore; InstLoc CTRCache; InstLoc CTRCacheStore; - InstLoc CRCache[8]; - InstLoc CRCacheStore[8]; -}; + std::array CRCache; + std::array CRCacheStore; }; +} // namespace IREmitter