jit-ir: Implement basic icache clear.

This commit is contained in:
Unknown W. Brackets 2016-07-01 17:27:24 -07:00
parent 6fb34d0bee
commit 1df08518ae
4 changed files with 24 additions and 6 deletions

View File

@ -221,7 +221,7 @@ MIPSOpcode IRFrontend::GetOffsetInstruction(int offset) {
return Memory::Read_Instruction(GetCompilerPC() + 4 * offset);
}
void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants) {
void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants, u32 &mipsBytes) {
js.cancel = false;
js.blockStart = em_address;
js.compilerPC = em_address;
@ -254,6 +254,8 @@ void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, std::v
}
}
mipsBytes = js.compilerPC - em_address;
IRWriter simplified;
IRWriter *code = &ir;
if (!js.hadBreakpoints) {

View File

@ -88,7 +88,7 @@ public:
void DoState(PointerWrap &p);
bool CheckRounding(); // returns true if we need a do-over
void DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants);
void DoJit(u32 em_address, std::vector<IRInst> &instructions, std::vector<u32> &constants, u32 &mipsBytes);
void EatPrefix() override {
js.EatPrefix();

View File

@ -85,8 +85,10 @@ void IRJit::Compile(u32 em_address) {
std::vector<IRInst> instructions;
std::vector<u32> constants;
frontend_.DoJit(em_address, instructions, constants);
u32 mipsBytes;
frontend_.DoJit(em_address, instructions, constants, mipsBytes);
b->SetInstructions(instructions, constants);
b->SetOriginalSize(mipsBytes);
b->Finalize(block_num); // Overwrites the first instruction
if (frontend_.CheckRounding()) {
@ -152,8 +154,13 @@ void IRBlockCache::Clear() {
blocks_.clear();
}
void IRBlockCache::InvalidateICache(u32 addess, u32 length) {
// TODO
void IRBlockCache::InvalidateICache(u32 address, u32 length) {
// TODO: Could be more efficient.
for (int i = 0; i < size_; ++i) {
if (blocks_[i].OverlapsRange(address, length)) {
blocks_[i].Destroy(i);
}
}
}
std::vector<u32> IRBlockCache::SaveAndClearEmuHackOps() {
@ -217,6 +224,10 @@ void IRBlock::Destroy(int number) {
}
}
bool IRBlock::OverlapsRange(u32 addr, u32 size) {
return addr + size > origAddr_ && addr < origAddr_ + origSize_;
}
MIPSOpcode IRJit::GetOriginalOp(MIPSOpcode op) {
IRBlock *b = blocks_.GetBlock(op.encoding & 0xFFFFFF);
return b->GetOriginalFirstOp();

View File

@ -100,6 +100,10 @@ public:
bool HasOriginalFirstOp();
bool RestoreOriginalFirstOp(int number);
bool IsValid() const { return origAddr_ != 0; }
void SetOriginalSize(u32 size) {
origSize_ = size;
}
bool OverlapsRange(u32 addr, u32 size);
void Finalize(int number);
void Destroy(int number);
@ -110,13 +114,14 @@ private:
u16 numInstructions_;
u16 numConstants_;
u32 origAddr_;
u32 origSize_;
MIPSOpcode origFirstOpcode_;
};
class IRBlockCache {
public:
void Clear();
void InvalidateICache(u32 addess, u32 length);
void InvalidateICache(u32 address, u32 length);
int GetNumBlocks() const { return (int)blocks_.size(); }
int AllocateBlock(int emAddr) {
blocks_.push_back(IRBlock(emAddr));