* 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); ExcludeRegFromUsedRegs(tai_regalloc(p).Reg,Regs);
hp1 := p; hp1 := p;
hp2 := nil; 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 GetNextInstruction(hp1, hp1) And
RegInInstruction(tai_regalloc(p).Reg, hp1) Do RegInInstruction(tai_regalloc(p).Reg, hp1) Do
hp2 := hp1; hp2 := hp1;
@ -210,7 +210,7 @@ Unit aopt;
p := hp1; p := hp1;
End End
{ merge allocations/deallocations } { 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 and getnextinstruction(p,hp1) and
{ don't merge deallocations/allocation which mark a new use of register, this { don't merge deallocations/allocation which mark a new use of register, this
enables more possibilities for the peephole optimizer } 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 } { returns true if the operands o1 and o2 are completely equal }
Function OpsEqual(const o1,o2:toper): Boolean; 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" of Tai's starting with StartPai and ending with the next "real"
instruction } instruction. If none is found, it returns
Function FindRegAlloc(Reg: TRegister; StartPai: Tai): Boolean; 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? } { reg used after p? }
function RegUsedAfterInstruction(reg: Tregister; p: tai; var AllUsedRegs: TAllUsedRegs): Boolean; function RegUsedAfterInstruction(reg: Tregister; p: tai; var AllUsedRegs: TAllUsedRegs): Boolean;
@ -1000,9 +1008,10 @@ Unit AoptObj;
OpsEqual := False; OpsEqual := False;
End; End;
Function TAOptObj.FindRegAlloc(Reg: TRegister; StartPai: Tai): Boolean;
Function TAOptObj.FindRegAlloc(Reg: TRegister; StartPai: Tai): tai_regalloc;
Begin Begin
FindRegAlloc:=False; Result:=nil;
Repeat Repeat
While Assigned(StartPai) And While Assigned(StartPai) And
((StartPai.typ in (SkipInstr - [ait_regAlloc])) Or ((StartPai.typ in (SkipInstr - [ait_regAlloc])) Or
@ -1014,7 +1023,34 @@ Unit AoptObj;
Begin Begin
if (tai_regalloc(StartPai).ratype=ra_alloc) and (getsupreg(tai_regalloc(StartPai).Reg) = getsupreg(Reg)) then if (tai_regalloc(StartPai).ratype=ra_alloc) and (getsupreg(tai_regalloc(StartPai).Reg) = getsupreg(Reg)) then
begin begin
FindRegAlloc:=true; Result:=tai_regalloc(StartPai);
exit;
end;
StartPai := Tai(StartPai.Next);
End
else
exit;
Until false;
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; exit;
end; end;
StartPai := Tai(StartPai.Next); StartPai := Tai(StartPai.Next);
@ -1204,7 +1240,10 @@ Unit AoptObj;
InsertLLItem(tai(p.Previous),p,tai_comment.create(strpnew(GetAllocationString(UsedRegs)))); InsertLLItem(tai(p.Previous),p,tai_comment.create(strpnew(GetAllocationString(UsedRegs))));
{$endif DEBUG_OPTALLOC} {$endif DEBUG_OPTALLOC}
if PeepHoleOptPass1Cpu(p) then if PeepHoleOptPass1Cpu(p) then
begin
UpdateUsedRegs(p);
continue; continue;
end;
case p.Typ Of case p.Typ Of
ait_instruction: ait_instruction:
begin begin