From 45f7883ed87ebd5cc4752b91e8f15267513edb22 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 15:43:22 -0500 Subject: [PATCH 1/3] IR_X86: Make RegInfo 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. It also follows that if the copy constructor is deleted, then copy assignment should also be forbidden. --- Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp index 83eb202eb2..0f95449d9d 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp @@ -33,6 +33,7 @@ The register allocation is linear scan allocation. #include "Common/CommonTypes.h" #include "Common/MathUtil.h" #include "Common/MsgHandler.h" +#include "Common/NonCopyable.h" #include "Common/x64ABI.h" #include "Common/x64Emitter.h" #include "Core/CoreTiming.h" @@ -48,7 +49,7 @@ using namespace Gen; static const unsigned int MAX_NUMBER_OF_REGS = 16; -struct RegInfo +struct RegInfo final : private NonCopyable { JitIL* Jit; IRBuilder* Build; @@ -79,9 +80,6 @@ struct RegInfo numSpills(0), numFSpills(0), exitNumber(0) { } - -private: - RegInfo(RegInfo&); // DO NOT IMPLEMENT }; static BitSet32 regsInUse(RegInfo& R) From bc7374a5e175caaefef0266b5642670594c6b82e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 15:55:14 -0500 Subject: [PATCH 2/3] IR_X86: Use std::array instead of raw C arrays in RegInfo --- Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp index 0f95449d9d..9427ebf78e 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp @@ -26,6 +26,8 @@ The register allocation is linear scan allocation. #endif #include +#include +#include #include #include "Common/BitSet.h" @@ -47,10 +49,10 @@ The register allocation is linear scan allocation. using namespace IREmitter; using namespace Gen; -static const unsigned int MAX_NUMBER_OF_REGS = 16; - struct RegInfo final : private NonCopyable { + static constexpr size_t MAX_NUMBER_OF_REGS = 16; + JitIL* Jit; IRBuilder* Build; InstLoc FirstI; @@ -69,8 +71,8 @@ struct RegInfo final : private NonCopyable // The last instruction which uses the result of this instruction. Used by the register allocator. std::vector lastUsed; - InstLoc regs[MAX_NUMBER_OF_REGS]; - InstLoc fregs[MAX_NUMBER_OF_REGS]; + std::array regs; + std::array fregs; unsigned numSpills; unsigned numFSpills; unsigned exitNumber; @@ -85,7 +87,7 @@ struct RegInfo final : private NonCopyable static BitSet32 regsInUse(RegInfo& R) { BitSet32 result; - for (unsigned i = 0; i < MAX_NUMBER_OF_REGS; i++) + for (size_t i = 0; i < RegInfo::MAX_NUMBER_OF_REGS; i++) { if (R.regs[i] != nullptr) result[i] = true; @@ -2328,7 +2330,7 @@ static void DoWriteCode(IRBuilder* ibuild, JitIL* Jit, u32 exitAddress) } } - for (unsigned i = 0; i < MAX_NUMBER_OF_REGS; i++) + for (size_t i = 0; i < RegInfo::MAX_NUMBER_OF_REGS; i++) { if (RI.regs[i]) { From 43910e474b14c2b93ea37434a47e17fd4370960f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jan 2017 16:21:01 -0500 Subject: [PATCH 3/3] IR_X86: Use member initializers where applicable for RegInfo --- Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp index 9427ebf78e..a9107b1e81 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/IR_X86.cpp @@ -54,7 +54,7 @@ struct RegInfo final : private NonCopyable static constexpr size_t MAX_NUMBER_OF_REGS = 16; JitIL* Jit; - IRBuilder* Build; + IRBuilder* Build = nullptr; InstLoc FirstI; // IInfo contains (per instruction) @@ -66,22 +66,18 @@ struct RegInfo final : private NonCopyable // and if we can clobber the operands registers. // Warning, Memory instruction use these bits slightly differently. // Bits 15-31: Spill location - std::vector IInfo; + std::vector IInfo; // The last instruction which uses the result of this instruction. Used by the register allocator. std::vector lastUsed; - std::array regs; - std::array fregs; - unsigned numSpills; - unsigned numFSpills; - unsigned exitNumber; + std::array regs{}; + std::array fregs{}; + u32 numSpills = 0; + u32 numFSpills = 0; + u32 exitNumber = 0; - RegInfo(JitIL* j, InstLoc f, unsigned insts) - : Jit(j), Build(nullptr), FirstI(f), IInfo(insts), lastUsed(insts), regs(), fregs(), - numSpills(0), numFSpills(0), exitNumber(0) - { - } + RegInfo(JitIL* j, InstLoc f, u32 insts) : Jit(j), FirstI(f), IInfo(insts), lastUsed(insts) {} }; static BitSet32 regsInUse(RegInfo& R)