* more consistent updates of used registers

+ FindRegDeAlloc searching for a register deallocation
* FindRegAlloc now returns the allocation object which was found

git-svn-id: trunk@22191 -
This commit is contained in:
florian 2012-08-22 19:52:15 +00:00
parent e1a2b1859a
commit 6e62fbc3d2
2 changed files with 48 additions and 9 deletions

View File

@ -185,7 +185,7 @@ Unit aopt;
ExcludeRegFromUsedRegs(tai_regalloc(p).Reg,Regs);
hp1 := p;
hp2 := nil;
While Not(FindRegAlloc(tai_regalloc(p).Reg, tai(hp1.Next))) And
While Not(assigned(FindRegAlloc(tai_regalloc(p).Reg, tai(hp1.Next)))) And
GetNextInstruction(hp1, hp1) And
RegInInstruction(tai_regalloc(p).Reg, hp1) Do
hp2 := hp1;
@ -210,7 +210,7 @@ Unit aopt;
p := hp1;
End
{ merge allocations/deallocations }
else if findregalloc(tai_regalloc(p).reg, tai(p.next))
else if assigned(findregalloc(tai_regalloc(p).reg, tai(p.next)))
and getnextinstruction(p,hp1) and
{ don't merge deallocations/allocation which mark a new use of register, this
enables more possibilities for the peephole optimizer }

View File

@ -289,10 +289,18 @@ Unit AoptObj;
{ returns true if the operands o1 and o2 are completely equal }
Function OpsEqual(const o1,o2:toper): Boolean;
{ Returns true if a ait_alloc object for Reg is found in the block
{ Returns the next ait_alloc object with ratype ra_dealloc for
Reg is found in the block
of Tai's starting with StartPai and ending with the next "real"
instruction }
Function FindRegAlloc(Reg: TRegister; StartPai: Tai): Boolean;
instruction. If none is found, it returns
nil }
Function FindRegAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
{ Returns the next ait_alloc object with ratype ra_dealloc
for Reg which is found in the block of Tai's starting with StartPai
and ending with the next "real" instruction. If none is found, it returns
nil }
Function FindRegDeAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
{ reg used after p? }
function RegUsedAfterInstruction(reg: Tregister; p: tai; var AllUsedRegs: TAllUsedRegs): Boolean;
@ -1000,9 +1008,10 @@ Unit AoptObj;
OpsEqual := False;
End;
Function TAOptObj.FindRegAlloc(Reg: TRegister; StartPai: Tai): Boolean;
Function TAOptObj.FindRegAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
Begin
FindRegAlloc:=False;
Result:=nil;
Repeat
While Assigned(StartPai) And
((StartPai.typ in (SkipInstr - [ait_regAlloc])) Or
@ -1014,7 +1023,7 @@ Unit AoptObj;
Begin
if (tai_regalloc(StartPai).ratype=ra_alloc) and (getsupreg(tai_regalloc(StartPai).Reg) = getsupreg(Reg)) then
begin
FindRegAlloc:=true;
Result:=tai_regalloc(StartPai);
exit;
end;
StartPai := Tai(StartPai.Next);
@ -1025,6 +1034,33 @@ Unit AoptObj;
End;
function TAOptObj.FindRegDeAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
Begin
Result:=nil;
Repeat
While Assigned(StartPai) And
((StartPai.typ in (SkipInstr - [ait_regAlloc])) Or
((StartPai.typ = ait_label) and
Not(Tai_Label(StartPai).labsym.Is_Used))) Do
StartPai := Tai(StartPai.Next);
If Assigned(StartPai) And
(StartPai.typ = ait_regAlloc) Then
Begin
if (tai_regalloc(StartPai).ratype=ra_dealloc) and
(getregtype(tai_regalloc(StartPai).Reg) = getregtype(Reg)) and
(getsupreg(tai_regalloc(StartPai).Reg) = getsupreg(Reg)) then
begin
Result:=tai_regalloc(StartPai);
exit;
end;
StartPai := Tai(StartPai.Next);
End
else
exit;
Until false;
End;
function TAOptObj.RegUsedAfterInstruction(reg: Tregister; p: tai;
var AllUsedRegs: TAllUsedRegs): Boolean;
begin
@ -1204,7 +1240,10 @@ Unit AoptObj;
InsertLLItem(tai(p.Previous),p,tai_comment.create(strpnew(GetAllocationString(UsedRegs))));
{$endif DEBUG_OPTALLOC}
if PeepHoleOptPass1Cpu(p) then
continue;
begin
UpdateUsedRegs(p);
continue;
end;
case p.Typ Of
ait_instruction:
begin