irjit: Allow flag-based allocation order.

Sometimes backends have needs, like XMM0/v0-only, or similar.
This commit is contained in:
Unknown W. Brackets committed 2023-08-21 20:46:05 -07:00
1 parent bea74ba162
commit db34b85107
6 files changed
+25 -24

No files matched your search

+14 -14
View File
@@ -330,18 +330,18 @@ void IRNativeRegCacheBase::MarkGPRAsPointerDirty(IRReg gpr) {
// Stays pointerified or REG_AS_PTR.
}
IRNativeReg IRNativeRegCacheBase::AllocateReg(MIPSLoc type) {
IRNativeReg IRNativeRegCacheBase::AllocateReg(MIPSLoc type, MIPSMap flags) {
_dbg_assert_(type == MIPSLoc::REG || type == MIPSLoc::FREG || type == MIPSLoc::VREG);
IRNativeReg nreg = FindFreeReg(type);
IRNativeReg nreg = FindFreeReg(type, flags);
if (nreg != -1)
return nreg;
// Still nothing. Let's spill a reg and goto 10.
bool clobbered;
IRNativeReg bestToSpill = FindBestToSpill(type, true, &clobbered);
IRNativeReg bestToSpill = FindBestToSpill(type, flags, true, &clobbered);
if (bestToSpill == -1) {
bestToSpill = FindBestToSpill(type, false, &clobbered);
bestToSpill = FindBestToSpill(type, flags, false, &clobbered);
}
if (bestToSpill != -1) {
@@ -351,7 +351,7 @@ IRNativeReg IRNativeRegCacheBase::AllocateReg(MIPSLoc type) {
FlushNativeReg(bestToSpill);
}
// Now one must be free.
return FindFreeReg(type);
return FindFreeReg(type, flags);
}
// Uh oh, we have all of them spilllocked....
@@ -360,9 +360,9 @@ IRNativeReg IRNativeRegCacheBase::AllocateReg(MIPSLoc type) {
return -1;
}
IRNativeReg IRNativeRegCacheBase::FindFreeReg(MIPSLoc type) const {
IRNativeReg IRNativeRegCacheBase::FindFreeReg(MIPSLoc type, MIPSMap flags) const {
int allocCount = 0, base = 0;
const int *allocOrder = GetAllocationOrder(type, allocCount, base);
const int *allocOrder = GetAllocationOrder(type, flags, allocCount, base);
for (int i = 0; i < allocCount; i++) {
IRNativeReg nreg = IRNativeReg(allocOrder[i] - base);
@@ -375,9 +375,9 @@ IRNativeReg IRNativeRegCacheBase::FindFreeReg(MIPSLoc type) const {
return -1;
}
IRNativeReg IRNativeRegCacheBase::FindBestToSpill(MIPSLoc type, bool unusedOnly, bool *clobbered) const {
IRNativeReg IRNativeRegCacheBase::FindBestToSpill(MIPSLoc type, MIPSMap flags, bool unusedOnly, bool *clobbered) const {
int allocCount = 0, base = 0;
const int *allocOrder = GetAllocationOrder(type, allocCount, base);
const int *allocOrder = GetAllocationOrder(type, flags, allocCount, base);
static const int UNUSED_LOOKAHEAD_OPS = 30;
@@ -670,7 +670,7 @@ IRNativeReg IRNativeRegCacheBase::MapWithTemp(const IRInst &inst, MIPSLoc type)
ApplyMapping(mapping, 3);
// Grab a temp while things are spill locked.
IRNativeReg temp = AllocateReg(type);
IRNativeReg temp = AllocateReg(type, MIPSMap::INIT);
CleanupMapping(mapping, 3);
return temp;
}
@@ -829,22 +829,22 @@ IRNativeReg IRNativeRegCacheBase::MapNativeReg(MIPSLoc type, IRReg first, int la
case MIPSLoc::REG_AS_PTR:
case MIPSLoc::REG:
if (type != MIPSLoc::REG)
nreg = AllocateReg(type);
nreg = AllocateReg(type, flags);
break;
case MIPSLoc::FREG:
if (type != MIPSLoc::FREG)
nreg = AllocateReg(type);
nreg = AllocateReg(type, flags);
break;
case MIPSLoc::VREG:
if (type != MIPSLoc::VREG)
nreg = AllocateReg(type);
nreg = AllocateReg(type, flags);
break;
case MIPSLoc::IMM:
case MIPSLoc::MEM:
nreg = AllocateReg(type);
nreg = AllocateReg(type, flags);
break;
}
}
+5 -4
View File
@@ -74,6 +74,7 @@ private:
};
// Initing is the default so the flag is reversed.
// 8 bits - upper 4 are reserved for backend purposes.
enum class MIPSMap : uint8_t {
INIT = 0,
DIRTY = 1,
@@ -191,15 +192,15 @@ public:
protected:
virtual void SetupInitialRegs();
virtual const int *GetAllocationOrder(MIPSLoc type, int &count, int &base) const = 0;
virtual const int *GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const = 0;
virtual const StaticAllocation *GetStaticAllocations(int &count) const {
count = 0;
return nullptr;
}
IRNativeReg AllocateReg(MIPSLoc type);
IRNativeReg FindFreeReg(MIPSLoc type) const;
IRNativeReg FindBestToSpill(MIPSLoc type, bool unusedOnly, bool *clobbered) const;
IRNativeReg AllocateReg(MIPSLoc type, MIPSMap flags);
IRNativeReg FindFreeReg(MIPSLoc type, MIPSMap flags) const;
IRNativeReg FindBestToSpill(MIPSLoc type, MIPSMap flags, bool unusedOnly, bool *clobbered) const;
virtual void DiscardNativeReg(IRNativeReg nreg);
virtual void FlushNativeReg(IRNativeReg nreg);
virtual void DiscardReg(IRReg mreg);
+2 -2
View File
@@ -55,7 +55,7 @@ void RiscVRegCache::SetupInitialRegs() {
mrInitial_[MIPS_REG_ZERO].isStatic = true;
}
const int *RiscVRegCache::GetAllocationOrder(MIPSLoc type, int &count, int &base) const {
const int *RiscVRegCache::GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const {
base = X0;
if (type == MIPSLoc::REG) {
@@ -236,7 +236,7 @@ RiscVReg RiscVRegCache::TryMapTempImm(IRReg r) {
}
RiscVReg RiscVRegCache::GetAndLockTempR() {
RiscVReg reg = (RiscVReg)AllocateReg(MIPSLoc::REG);
RiscVReg reg = (RiscVReg)AllocateReg(MIPSLoc::REG, MIPSMap::INIT);
if (reg != INVALID_REG) {
nr[reg].tempLockIRIndex = irIndex_;
}
+1 -1
View File
@@ -73,7 +73,7 @@ public:
protected:
void SetupInitialRegs() override;
const StaticAllocation *GetStaticAllocations(int &count) const override;
const int *GetAllocationOrder(MIPSLoc type, int &count, int &base) const override;
const int *GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const override;
void AdjustNativeRegAsPtr(IRNativeReg nreg, bool state) override;
void LoadNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;
+2 -2
View File
@@ -46,7 +46,7 @@ void X64IRRegCache::Init(XEmitter *emitter) {
emit_ = emitter;
}
const int *X64IRRegCache::GetAllocationOrder(MIPSLoc type, int &count, int &base) const {
const int *X64IRRegCache::GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const {
if (type == MIPSLoc::REG) {
base = RAX;
@@ -143,7 +143,7 @@ X64Reg X64IRRegCache::TryMapTempImm(IRReg r) {
}
X64Reg X64IRRegCache::GetAndLockTempR() {
X64Reg reg = FromNativeReg(AllocateReg(MIPSLoc::REG));
X64Reg reg = FromNativeReg(AllocateReg(MIPSLoc::REG, MIPSMap::INIT));
if (reg != INVALID_REG) {
nr[reg].tempLockIRIndex = irIndex_;
}
+1 -1
View File
@@ -71,7 +71,7 @@ public:
Gen::X64Reg FX(IRReg preg);
protected:
const int *GetAllocationOrder(MIPSLoc type, int &count, int &base) const override;
const int *GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const override;
void AdjustNativeRegAsPtr(IRNativeReg nreg, bool state) override;
void LoadNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;