From 4f75590fdbe14a6a765724ba7bae10bae6884f0e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 18:08:11 -0500 Subject: [PATCH 1/8] IR: Move private details below public details --- Source/Core/Core/PowerPC/JitILCommon/IR.h | 62 +++++++++++------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 01a140a0b1..857f38107e 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -228,37 +228,8 @@ InstLoc inline getOp2(InstLoc i) class IRBuilder { -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() { Reset(); } InstLoc EmitIntConst(unsigned value) { return EmitIntConst64(value); } InstLoc EmitIntConst64(u64 value); @@ -439,9 +410,38 @@ public: 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 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; + bool isSameValue(InstLoc Op1, InstLoc Op2) const; unsigned getComplexity(InstLoc I) const; unsigned getNumberOfOperands(InstLoc I) const; From 47fc72f0a86ebce869b77c7083e911ea97ad569a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 18:11:54 -0500 Subject: [PATCH 2/8] IR: Get rid of an unimplemented member function prototype --- Source/Core/Core/PowerPC/JitILCommon/IR.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 857f38107e..7e5bbcd11c 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -428,7 +428,6 @@ private: 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); From ef3e6de875155f09561e07edb27ad2fd4374b582 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 18:21:09 -0500 Subject: [PATCH 3/8] IR: Move implementation of the constructor and Reset into the cpp file Neither of these are intended to be called extremely frequently to warrant this. --- Source/Core/Core/PowerPC/JitILCommon/IR.cpp | 33 +++++++++++++++++++++ Source/Core/Core/PowerPC/JitILCommon/IR.h | 33 +++------------------ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp index 6fe5843c8c..9e58e3fc3b 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp @@ -137,6 +137,39 @@ using namespace Gen; namespace IREmitter { +IRBuilder::IRBuilder() +{ + Reset(); +} + +void IRBuilder::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; +} + InstLoc IRBuilder::EmitZeroOp(unsigned Opcode, unsigned extra = 0) { InstLoc curIndex = InstList.data() + InstList.size(); diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 7e5bbcd11c..7125fdc954 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -229,7 +229,10 @@ InstLoc inline getOp2(InstLoc i) class IRBuilder { public: - IRBuilder() { Reset(); } + IRBuilder(); + + void Reset(); + InstLoc EmitIntConst(unsigned value) { return EmitIntConst64(value); } InstLoc EmitIntConst64(u64 value); @@ -382,34 +385,6 @@ public: 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; - } - private: IRBuilder(IRBuilder&); // DO NOT IMPLEMENT From a8b2dd7fc3b2c5a422633a0ac81f3a427b6d3791 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 18:45:26 -0500 Subject: [PATCH 4/8] IR: Use std::array instead of raw C arrays --- Source/Core/Core/PowerPC/JitILCommon/IR.cpp | 19 +++++++------------ Source/Core/Core/PowerPC/JitILCommon/IR.h | 13 +++++++------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp index 9e58e3fc3b..8eb732ea98 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp @@ -149,22 +149,17 @@ void IRBuilder::Reset() MarkUsed.clear(); MarkUsed.reserve(100000); - for (unsigned i = 0; i < 32; i++) - { - GRegCache[i] = nullptr; - GRegCacheStore[i] = nullptr; - FRegCache[i] = nullptr; - FRegCacheStore[i] = nullptr; - } + GRegCache = {}; + GRegCacheStore = {}; + + FRegCache = {}; + FRegCacheStore = {}; CarryCache = nullptr; CarryCacheStore = nullptr; - for (unsigned i = 0; i < 8; i++) - { - CRCache[i] = nullptr; - CRCacheStore[i] = nullptr; - } + CRCache = {}; + CRCacheStore = {}; CTRCache = nullptr; CTRCacheStore = nullptr; diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 7125fdc954..fe5e6c46b6 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "Common/CommonTypes.h" @@ -427,15 +428,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; }; }; From cd12b2c55f8c4731fb828edde8473de56cb40cc4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 18:58:38 -0500 Subject: [PATCH 5/8] IR: Make IRBuilder uncopyable Hiding and not implementing the copy constructor is a pre-C++11 thing. It should also be noted that a copy constructor, as defined by the language, contains a const qualifier on its parameter, so this wouldn't have prevented copies from being performed. --- Source/Core/Core/PowerPC/JitILCommon/IR.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index fe5e6c46b6..bfe724df59 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -8,6 +8,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/NonCopyable.h" namespace IREmitter { @@ -227,7 +228,7 @@ InstLoc inline getOp2(InstLoc i) return i; } -class IRBuilder +class IRBuilder final : private NonCopyable { public: IRBuilder(); @@ -387,8 +388,6 @@ public: void WriteToFile(u64 codeHash); 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); From 459a6e73c38d17fb2ea58ff834b110d5a631f2f4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 19:32:13 -0500 Subject: [PATCH 6/8] IR: Remove unused function --- Source/Core/Core/PowerPC/JitILCommon/IR.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index bfe724df59..d1e64d550c 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -380,7 +380,6 @@ public: InstLoc ReadBackward() { return --curReadPtr; } InstLoc getFirstInst() { return InstList.data(); } unsigned int getNumInsts() { return (unsigned int)InstList.size(); } - unsigned int ReadInst(InstLoc I) { return *I; } unsigned int GetImmValue(InstLoc I) const { return (u32)GetImmValue64(I); } u64 GetImmValue64(InstLoc I) const; void SetMarkUsed(InstLoc I); From 67fc73e82c20cc55ed65b12f292bf61dcd971429 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 19:38:13 -0500 Subject: [PATCH 7/8] IR: Make getNumInsts return type size_t There's no need to cast here. --- Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp | 2 +- Source/Core/Core/PowerPC/JitILCommon/IR.cpp | 10 +++++----- Source/Core/Core/PowerPC/JitILCommon/IR.h | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) 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 8eb732ea98..f7348ba34e 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.cpp +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.cpp @@ -1769,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, ' '); @@ -1795,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 @@ -1806,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 d1e64d550c..1ad69cfcef 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "Common/CommonTypes.h" @@ -379,7 +380,7 @@ public: InstLoc ReadForward() { return curReadPtr++; } InstLoc ReadBackward() { return --curReadPtr; } InstLoc getFirstInst() { return InstList.data(); } - unsigned int getNumInsts() { return (unsigned int)InstList.size(); } + 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); From 8346f86ee43b480c8ccd977b2c81755a00517421 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 19:54:42 -0500 Subject: [PATCH 8/8] IR: Remove unnecessary semicolon on namespace brace --- Source/Core/Core/PowerPC/JitILCommon/IR.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/PowerPC/JitILCommon/IR.h b/Source/Core/Core/PowerPC/JitILCommon/IR.h index 1ad69cfcef..2321037ef8 100644 --- a/Source/Core/Core/PowerPC/JitILCommon/IR.h +++ b/Source/Core/Core/PowerPC/JitILCommon/IR.h @@ -438,4 +438,4 @@ private: std::array CRCache; std::array CRCacheStore; }; -}; +} // namespace IREmitter