commit
7e52f867c1
|
@ -77,7 +77,7 @@ struct RegInfo final : private NonCopyable
|
||||||
u32 numFSpills = 0;
|
u32 numFSpills = 0;
|
||||||
u32 exitNumber = 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)
|
static BitSet32 regsInUse(RegInfo& R)
|
||||||
|
|
|
@ -137,6 +137,34 @@ using namespace Gen;
|
||||||
|
|
||||||
namespace IREmitter
|
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 IRBuilder::EmitZeroOp(unsigned Opcode, unsigned extra = 0)
|
||||||
{
|
{
|
||||||
InstLoc curIndex = InstList.data() + InstList.size();
|
InstLoc curIndex = InstList.data() + InstList.size();
|
||||||
|
@ -1741,15 +1769,15 @@ void IRBuilder::WriteToFile(u64 codeHash)
|
||||||
|
|
||||||
const InstLoc lastCurReadPtr = curReadPtr;
|
const InstLoc lastCurReadPtr = curReadPtr;
|
||||||
StartForwardPass();
|
StartForwardPass();
|
||||||
const unsigned numInsts = getNumInsts();
|
const size_t numInsts = getNumInsts();
|
||||||
for (unsigned int i = 0; i < numInsts; ++i)
|
for (size_t i = 0; i < numInsts; ++i)
|
||||||
{
|
{
|
||||||
const InstLoc I = ReadForward();
|
const InstLoc I = ReadForward();
|
||||||
const unsigned opcode = getOpcode(*I);
|
const unsigned opcode = getOpcode(*I);
|
||||||
const bool thisUsed = IsMarkUsed(I) || alwaysUseds.find(opcode) != alwaysUseds.end();
|
const bool thisUsed = IsMarkUsed(I) || alwaysUseds.find(opcode) != alwaysUseds.end();
|
||||||
|
|
||||||
// Line number
|
// Line number
|
||||||
fprintf(file, "%4u", i);
|
fprintf(file, "%4zu", i);
|
||||||
|
|
||||||
if (!thisUsed)
|
if (!thisUsed)
|
||||||
fprintf(file, "%*c", 32, ' ');
|
fprintf(file, "%*c", 32, ' ');
|
||||||
|
@ -1767,7 +1795,7 @@ void IRBuilder::WriteToFile(u64 codeHash)
|
||||||
if (isImm(*inst))
|
if (isImm(*inst))
|
||||||
fprintf(file, " 0x%08x", GetImmValue(inst));
|
fprintf(file, " 0x%08x", GetImmValue(inst));
|
||||||
else
|
else
|
||||||
fprintf(file, " %10u", i - (unsigned int)(I - inst));
|
fprintf(file, " %10zu", i - static_cast<size_t>(I - inst));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Op2
|
// Op2
|
||||||
|
@ -1778,7 +1806,7 @@ void IRBuilder::WriteToFile(u64 codeHash)
|
||||||
if (isImm(*inst))
|
if (isImm(*inst))
|
||||||
fprintf(file, " 0x%08x", GetImmValue(inst));
|
fprintf(file, " 0x%08x", GetImmValue(inst));
|
||||||
else
|
else
|
||||||
fprintf(file, " %10u", i - (unsigned int)(I - inst));
|
fprintf(file, " %10zu", i - static_cast<size_t>(I - inst));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extra8Regs.count(opcode))
|
if (extra8Regs.count(opcode))
|
||||||
|
|
|
@ -4,9 +4,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/NonCopyable.h"
|
||||||
|
|
||||||
namespace IREmitter
|
namespace IREmitter
|
||||||
{
|
{
|
||||||
|
@ -226,39 +229,13 @@ InstLoc inline getOp2(InstLoc i)
|
||||||
return 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:
|
public:
|
||||||
|
IRBuilder();
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
|
||||||
InstLoc EmitIntConst(unsigned value) { return EmitIntConst64(value); }
|
InstLoc EmitIntConst(unsigned value) { return EmitIntConst64(value); }
|
||||||
InstLoc EmitIntConst64(u64 value);
|
InstLoc EmitIntConst64(u64 value);
|
||||||
|
|
||||||
|
@ -403,45 +380,42 @@ public:
|
||||||
InstLoc ReadForward() { return curReadPtr++; }
|
InstLoc ReadForward() { return curReadPtr++; }
|
||||||
InstLoc ReadBackward() { return --curReadPtr; }
|
InstLoc ReadBackward() { return --curReadPtr; }
|
||||||
InstLoc getFirstInst() { return InstList.data(); }
|
InstLoc getFirstInst() { return InstList.data(); }
|
||||||
unsigned int getNumInsts() { return (unsigned int)InstList.size(); }
|
size_t getNumInsts() const { return InstList.size(); }
|
||||||
unsigned int ReadInst(InstLoc I) { return *I; }
|
|
||||||
unsigned int GetImmValue(InstLoc I) const { return (u32)GetImmValue64(I); }
|
unsigned int GetImmValue(InstLoc I) const { return (u32)GetImmValue64(I); }
|
||||||
u64 GetImmValue64(InstLoc I) const;
|
u64 GetImmValue64(InstLoc I) const;
|
||||||
void SetMarkUsed(InstLoc I);
|
void SetMarkUsed(InstLoc I);
|
||||||
bool IsMarkUsed(InstLoc I) const;
|
bool IsMarkUsed(InstLoc I) const;
|
||||||
void WriteToFile(u64 codeHash);
|
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:
|
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;
|
bool isSameValue(InstLoc Op1, InstLoc Op2) const;
|
||||||
unsigned getComplexity(InstLoc I) const;
|
unsigned getComplexity(InstLoc I) const;
|
||||||
unsigned getNumberOfOperands(InstLoc I) const;
|
unsigned getNumberOfOperands(InstLoc I) const;
|
||||||
|
@ -453,15 +427,15 @@ private:
|
||||||
std::vector<bool> MarkUsed; // Used for IRWriter
|
std::vector<bool> MarkUsed; // Used for IRWriter
|
||||||
std::vector<u64> ConstList;
|
std::vector<u64> ConstList;
|
||||||
InstLoc curReadPtr;
|
InstLoc curReadPtr;
|
||||||
InstLoc GRegCache[32];
|
std::array<InstLoc, 32> GRegCache;
|
||||||
InstLoc GRegCacheStore[32];
|
std::array<InstLoc, 32> GRegCacheStore;
|
||||||
InstLoc FRegCache[32];
|
std::array<InstLoc, 32> FRegCache;
|
||||||
InstLoc FRegCacheStore[32];
|
std::array<InstLoc, 32> FRegCacheStore;
|
||||||
InstLoc CarryCache;
|
InstLoc CarryCache;
|
||||||
InstLoc CarryCacheStore;
|
InstLoc CarryCacheStore;
|
||||||
InstLoc CTRCache;
|
InstLoc CTRCache;
|
||||||
InstLoc CTRCacheStore;
|
InstLoc CTRCacheStore;
|
||||||
InstLoc CRCache[8];
|
std::array<InstLoc, 8> CRCache;
|
||||||
InstLoc CRCacheStore[8];
|
std::array<InstLoc, 8> CRCacheStore;
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
} // namespace IREmitter
|
||||||
|
|
Loading…
Reference in New Issue