Added tracking of end block to detect if block should be split

This commit is contained in:
zilmar 2012-10-17 20:04:11 +11:00
parent b5bee95acb
commit 923576c93c
4 changed files with 44 additions and 18 deletions

View File

@ -43,7 +43,7 @@ bool CCodeBlock::SetSection ( CCodeSection * & Section, CCodeSection * CurrentSe
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
} }
if (TargetPC > ((CurrentPC + 0x1000) & 0xFFFFF000)) if (TargetPC >= ((CurrentPC + 0x1000) & 0xFFFFF000))
{ {
return false; return false;
} }
@ -92,19 +92,28 @@ bool CCodeBlock::SetSection ( CCodeSection * & Section, CCodeSection * CurrentSe
} }
SplitSection = itr->second; SplitSection = itr->second;
} }
CCodeSection * BaseSection = Section; if (SplitSection->m_EndPC == (DWORD)-1)
BaseSection->SetJumpAddress(SplitSection->m_Jump.JumpPC, SplitSection->m_Jump.TargetPC,SplitSection->m_Jump.PermLoop); {
BaseSection->m_JumpSection = SplitSection->m_JumpSection; _Notify->BreakPoint(__FILE__,__LINE__);
BaseSection->SetContinueAddress(SplitSection->m_Cont.JumpPC,SplitSection->m_Cont.TargetPC); }
BaseSection->m_ContinueSection = SplitSection->m_ContinueSection; if (SplitSection->m_EndPC >= TargetPC)
BaseSection->m_JumpSection->SwitchParent(SplitSection,BaseSection); {
BaseSection->m_ContinueSection->SwitchParent(SplitSection,BaseSection); CCodeSection * BaseSection = Section;
BaseSection->AddParent(SplitSection); BaseSection->m_EndPC = SplitSection->m_EndPC;
BaseSection->SetJumpAddress(SplitSection->m_Jump.JumpPC, SplitSection->m_Jump.TargetPC,SplitSection->m_Jump.PermLoop);
BaseSection->m_JumpSection = SplitSection->m_JumpSection;
BaseSection->SetContinueAddress(SplitSection->m_Cont.JumpPC,SplitSection->m_Cont.TargetPC);
BaseSection->m_ContinueSection = SplitSection->m_ContinueSection;
BaseSection->m_JumpSection->SwitchParent(SplitSection,BaseSection);
BaseSection->m_ContinueSection->SwitchParent(SplitSection,BaseSection);
BaseSection->AddParent(SplitSection);
SplitSection->m_JumpSection = NULL; SplitSection->m_EndPC = TargetPC - 4;
SplitSection->m_ContinueSection = BaseSection; SplitSection->m_JumpSection = NULL;
SplitSection->SetContinueAddress(TargetPC - 4, TargetPC); SplitSection->m_ContinueSection = BaseSection;
SplitSection->SetJumpAddress((DWORD)-1,(DWORD)-1,false); SplitSection->SetContinueAddress(TargetPC - 4, TargetPC);
SplitSection->SetJumpAddress((DWORD)-1,(DWORD)-1,false);
}
} }
} }
return true; return true;
@ -132,6 +141,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
SetSection(CurrentSection->m_ContinueSection, CurrentSection, TestPC,true,TestPC); SetSection(CurrentSection->m_ContinueSection, CurrentSection, TestPC,true,TestPC);
CurrentSection->SetContinueAddress(TestPC - 4, TestPC); CurrentSection->SetContinueAddress(TestPC - 4, TestPC);
} }
CurrentSection->m_EndPC = TestPC - 4;
CurrentSection = itr->second; CurrentSection = itr->second;
CPU_Message("Section %d",CurrentSection->m_SectionID); CPU_Message("Section %d",CurrentSection->m_SectionID);
if (EnterSection != m_EnterSection) if (EnterSection != m_EnterSection)
@ -152,6 +162,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
bool LikelyBranch, EndBlock, IncludeDelaySlot, PermLoop; bool LikelyBranch, EndBlock, IncludeDelaySlot, PermLoop;
DWORD TargetPC, ContinuePC, SectionCount = m_Sections.size(); DWORD TargetPC, ContinuePC, SectionCount = m_Sections.size();
CurrentSection->m_EndPC = TestPC;
if (!AnalyzeInstruction(TestPC, TargetPC, ContinuePC, LikelyBranch, IncludeDelaySlot, EndBlock, PermLoop)) if (!AnalyzeInstruction(TestPC, TargetPC, ContinuePC, LikelyBranch, IncludeDelaySlot, EndBlock, PermLoop))
{ {
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
@ -160,6 +171,10 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
if (TargetPC == (DWORD)-1 && !EndBlock) if (TargetPC == (DWORD)-1 && !EndBlock)
{ {
if (ContinuePC != (DWORD)-1)
{
_Notify->BreakPoint(__FILE__,__LINE__);
}
continue; continue;
} }
@ -180,10 +195,12 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
if (LikelyBranch) if (LikelyBranch)
{ {
CPU_Message(__FUNCTION__ ": SetJumpAddress TestPC = %X Target = %X",TestPC,TestPC + 4);
CurrentSection->SetJumpAddress(TestPC, TestPC + 4,false); CurrentSection->SetJumpAddress(TestPC, TestPC + 4,false);
if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4,false,TestPC)) if (SetSection(CurrentSection->m_JumpSection, CurrentSection, TestPC + 4,false,TestPC))
{ {
CCodeSection * JumpSection = CurrentSection->m_JumpSection; CCodeSection * JumpSection = CurrentSection->m_JumpSection;
JumpSection->m_EndPC = TestPC + 4;
JumpSection->SetJumpAddress(TestPC, TargetPC,false); JumpSection->SetJumpAddress(TestPC, TargetPC,false);
JumpSection->SetDelaySlot(); JumpSection->SetDelaySlot();
SetSection(JumpSection->m_JumpSection,CurrentSection->m_JumpSection,TargetPC,true,TestPC); SetSection(JumpSection->m_JumpSection,CurrentSection->m_JumpSection,TargetPC,true,TestPC);
@ -193,6 +210,7 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
} }
else if (TargetPC != ((DWORD)-1)) else if (TargetPC != ((DWORD)-1))
{ {
CPU_Message(__FUNCTION__ ": SetJumpAddress TestPC = %X Target = %X",TestPC,TargetPC);
CurrentSection->SetJumpAddress(TestPC, TargetPC,PermLoop); CurrentSection->SetJumpAddress(TestPC, TargetPC,PermLoop);
if (PermLoop || !SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC,true,TestPC)) if (PermLoop || !SetSection(CurrentSection->m_JumpSection, CurrentSection, TargetPC,true,TestPC))
{ {
@ -279,6 +297,10 @@ bool CCodeBlock::CreateBlockLinkage ( CCodeSection * EnterSection )
if (!CreateBlockLinkage(Section)) { return false; } if (!CreateBlockLinkage(Section)) { return false; }
break; break;
} }
if (CurrentSection->m_EndPC == (DWORD)-1)
{
_Notify->BreakPoint(__FILE__,__LINE__);
}
return true; return true;
} }

View File

@ -77,6 +77,7 @@ int DelaySlotEffectsJump (DWORD JumpPC) {
CCodeSection::CCodeSection( CCodeBlock * CodeBlock, DWORD EnterPC, DWORD ID, bool LinkAllowed) : CCodeSection::CCodeSection( CCodeBlock * CodeBlock, DWORD EnterPC, DWORD ID, bool LinkAllowed) :
m_BlockInfo(CodeBlock), m_BlockInfo(CodeBlock),
m_EnterPC(EnterPC), m_EnterPC(EnterPC),
m_EndPC((DWORD)-1),
m_SectionID(ID), m_SectionID(ID),
m_ContinueSection(NULL), m_ContinueSection(NULL),
m_JumpSection(NULL), m_JumpSection(NULL),
@ -1926,6 +1927,7 @@ void CCodeSection::DisplaySectionInformation (void)
{ {
CPU_Message("====== Section %d ======",m_SectionID); CPU_Message("====== Section %d ======",m_SectionID);
CPU_Message("Start PC: %X",m_EnterPC); CPU_Message("Start PC: %X",m_EnterPC);
CPU_Message("End PC: %X",m_EndPC);
CPU_Message("CompiledLocation: %X",m_CompiledLocation); CPU_Message("CompiledLocation: %X",m_CompiledLocation);
if (!m_ParentSection.empty()) if (!m_ParentSection.empty())
{ {

View File

@ -31,8 +31,9 @@ public:
/* Block Connection info */ /* Block Connection info */
SECTION_LIST m_ParentSection; SECTION_LIST m_ParentSection;
CCodeBlock * const m_BlockInfo; CCodeBlock * const m_BlockInfo;
const DWORD m_EnterPC;
const DWORD m_SectionID; const DWORD m_SectionID;
const DWORD m_EnterPC;
DWORD m_EndPC;
CCodeSection * m_ContinueSection; CCodeSection * m_ContinueSection;
CCodeSection * m_JumpSection; CCodeSection * m_JumpSection;
bool m_EndSection; // if this section does not link bool m_EndSection; // if this section does not link

View File

@ -2,6 +2,8 @@
#define CHECKED_BUILD 1 #define CHECKED_BUILD 1
int DelaySlotEffectsCompare ( DWORD PC, DWORD Reg1, DWORD Reg2 );
LoopAnalysis::LoopAnalysis(CCodeBlock * CodeBlock, CCodeSection * Section) : LoopAnalysis::LoopAnalysis(CCodeBlock * CodeBlock, CCodeSection * Section) :
m_EnterSection(Section), m_EnterSection(Section),
m_BlockInfo(CodeBlock), m_BlockInfo(CodeBlock),
@ -400,7 +402,9 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section)
case R4300i_BGTZ: case R4300i_BGTZ:
m_NextInstruction = DELAY_SLOT; m_NextInstruction = DELAY_SLOT;
#ifdef CHECKED_BUILD #ifdef CHECKED_BUILD
if (Section->m_Cont.TargetPC != m_PC + 8) if (Section->m_Cont.TargetPC != m_PC + 8 &&
Section->m_ContinueSection != NULL &&
Section->m_Cont.TargetPC != (DWORD)-1)
{ {
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
} }
@ -410,13 +414,10 @@ bool LoopAnalysis::CheckLoopRegisterUsage( CCodeSection * Section)
} }
if (m_PC == Section->m_Jump.TargetPC) if (m_PC == Section->m_Jump.TargetPC)
{ {
_Notify->BreakPoint(__FILE__,__LINE__);
#ifdef tofix
if (!DelaySlotEffectsCompare(m_PC,m_Command.rs,m_Command.rt) && !Section->m_Jump.PermLoop) if (!DelaySlotEffectsCompare(m_PC,m_Command.rs,m_Command.rt) && !Section->m_Jump.PermLoop)
{ {
_Notify->BreakPoint(__FILE__,__LINE__); _Notify->BreakPoint(__FILE__,__LINE__);
} }
#endif
} }
#endif #endif
break; break;