#pragma once
#include "Common/RiscVEmitter.h"
#include "Core/MIPS/MIPS.h"
#include "Core/MIPS/IR/IRJit.h"
#include "Core/MIPS/IR/IRRegCache.h"
namespace RiscVJitConstants {
constexpr int XLEN = 64;
const RiscVGen::RiscVReg DOWNCOUNTREG = RiscVGen::X24;
const RiscVGen::RiscVReg JITBASEREG = RiscVGen::X25;
const RiscVGen::RiscVReg CTXREG = RiscVGen::X26;
const RiscVGen::RiscVReg MEMBASEREG = RiscVGen::X27;
const RiscVGen::RiscVReg SCRATCH1 = RiscVGen::X10;
const RiscVGen::RiscVReg SCRATCH2 = RiscVGen::X11;
}
class RiscVRegCache : public IRNativeRegCacheBase {
public:
RiscVRegCache(MIPSComp::JitOptions *jo);
void Init(RiscVGen::RiscVEmitter *emitter);
RiscVGen::RiscVReg TryMapTempImm(IRReg reg);
RiscVGen::RiscVReg MapGPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
RiscVGen::RiscVReg MapGPRAsPointer(IRReg reg);
RiscVGen::RiscVReg MapFPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
RiscVGen::RiscVReg MapWithFPRTemp(const IRInst &inst);
bool IsNormalized32(IRReg reg);
RiscVGen::RiscVReg Normalize32(IRReg reg, RiscVGen::RiscVReg destReg = RiscVGen::INVALID_REG);
void FlushBeforeCall();
RiscVGen::RiscVReg GetAndLockTempGPR();
RiscVGen::RiscVReg R(IRReg preg);
RiscVGen::RiscVReg RPtr(IRReg preg);
RiscVGen::RiscVReg F(IRReg preg);
void EmitLoadStaticRegisters();
void EmitSaveStaticRegisters();
protected:
void SetupInitialRegs() override;
const StaticAllocation *GetStaticAllocations(int &count) const override;
const int *GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const override;
void AdjustNativeRegAsPtr(IRNativeReg nreg, bool state) override;
bool IsNativeRegCompatible(IRNativeReg nreg, MIPSLoc type, MIPSMap flags, int lanes) override;
void LoadNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;
void StoreNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;
void SetNativeRegValue(IRNativeReg nreg, uint32_t imm) override;
void StoreRegValue(IRReg mreg, uint32_t imm) override;
private:
RiscVGen::RiscVEmitter *emit_ = nullptr;
enum {
NUM_RVGPR = 32,
NUM_RVFPR = 32,
NUM_RVVPR = 32,
};
};