mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-05-03 13:23:41 +02:00
* fixed bug with -dreplacereg
This commit is contained in:
parent
33b6e19f1f
commit
ace77883c8
@ -450,7 +450,7 @@ begin
|
|||||||
(Reg32(p^.oper[0].reg) = reg)));
|
(Reg32(p^.oper[0].reg) = reg)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure RestoreRegContentsTo(reg: TRegister; const c: TContent; p: pai);
|
Procedure RestoreRegContentsTo(reg: TRegister; const c: TContent; p, endP: pai);
|
||||||
var
|
var
|
||||||
{$ifdef replaceregdebug}
|
{$ifdef replaceregdebug}
|
||||||
hp: pai;
|
hp: pai;
|
||||||
@ -466,11 +466,17 @@ begin
|
|||||||
if assigned(hp^.previous) then
|
if assigned(hp^.previous) then
|
||||||
hp^.previous^.next := hp;
|
hp^.previous^.next := hp;
|
||||||
{$endif replaceregdebug}
|
{$endif replaceregdebug}
|
||||||
|
PPaiProp(p^.optInfo)^.Regs[reg] := c;
|
||||||
|
While (p <> endP) Do
|
||||||
|
Begin
|
||||||
|
PPaiProp(p^.optInfo)^.Regs[reg] := c;
|
||||||
|
getNextInstruction(p,p);
|
||||||
|
end;
|
||||||
tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
|
tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
|
||||||
|
repeat
|
||||||
PPaiProp(p^.optInfo)^.Regs[reg] := c;
|
PPaiProp(p^.optInfo)^.Regs[reg] := c;
|
||||||
while getNextInstruction(p,p) and
|
until not getNextInstruction(p,p) or
|
||||||
(PPaiProp(p^.optInfo)^.Regs[reg].wState = tmpState) do
|
(PPaiProp(p^.optInfo)^.Regs[reg].wState <> tmpState);
|
||||||
PPaiProp(p^.optInfo)^.Regs[reg] := c;
|
|
||||||
{$ifdef replaceregdebug}
|
{$ifdef replaceregdebug}
|
||||||
if assigned(p) then
|
if assigned(p) then
|
||||||
begin
|
begin
|
||||||
@ -485,18 +491,26 @@ begin
|
|||||||
{$endif replaceregdebug}
|
{$endif replaceregdebug}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure ClearRegContentsFrom(reg: TRegister; p: pai);
|
Procedure ClearRegContentsFrom(reg: TRegister; p, endP: pai);
|
||||||
|
{ first clears the contents of reg from p till endP. Then the contents are }
|
||||||
|
{ cleared until the first instruction that changes reg }
|
||||||
var
|
var
|
||||||
{$ifdef replaceregdebug}
|
{$ifdef replaceregdebug}
|
||||||
hp: pai;
|
hp: pai;
|
||||||
{$endif replaceregdebug}
|
{$endif replaceregdebug}
|
||||||
tmpState: byte;
|
tmpState: byte;
|
||||||
begin
|
begin
|
||||||
|
PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
|
||||||
|
While (p <> endP) Do
|
||||||
|
Begin
|
||||||
|
PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
|
||||||
|
getNextInstruction(p,p);
|
||||||
|
end;
|
||||||
tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
|
tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
|
||||||
|
repeat
|
||||||
PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
|
PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
|
||||||
while getNextInstruction(p,p) and
|
until not getNextInstruction(p,p) or
|
||||||
(PPaiProp(p^.optInfo)^.Regs[reg].wState = tmpState) do
|
(PPaiProp(p^.optInfo)^.Regs[reg].wState <> tmpState);
|
||||||
PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
|
|
||||||
{$ifdef replaceregdebug}
|
{$ifdef replaceregdebug}
|
||||||
if assigned(p) then
|
if assigned(p) then
|
||||||
begin
|
begin
|
||||||
@ -647,19 +661,22 @@ begin
|
|||||||
sequenceEnd := false;
|
sequenceEnd := false;
|
||||||
newRegModified := false;
|
newRegModified := false;
|
||||||
orgRegRead := false;
|
orgRegRead := false;
|
||||||
|
endP := p;
|
||||||
|
(*
|
||||||
endP := pai(p^.previous);
|
endP := pai(p^.previous);
|
||||||
{ skip over the instructions that will be removed }
|
{ skip over the instructions that will be removed }
|
||||||
while getNextInstruction(endP,hp) and
|
while getNextInstruction(endP,hp) and
|
||||||
assigned(hp) and
|
assigned(hp) and
|
||||||
PPaiProp(hp^.optInfo)^.canBeRemoved do
|
PPaiProp(hp^.optInfo)^.canBeRemoved do
|
||||||
endP := hp;
|
endP := hp;
|
||||||
|
*)
|
||||||
while tmpResult and not sequenceEnd do
|
while tmpResult and not sequenceEnd do
|
||||||
begin
|
begin
|
||||||
tmpResult :=
|
tmpResult :=
|
||||||
getNextInstruction(endP,endP);
|
getNextInstruction(endP,endP);
|
||||||
If tmpResult and
|
If tmpResult and
|
||||||
{ don't take into account instructions that will be removed }
|
{ don't take into account instructions that will be removed }
|
||||||
Not (PPaiProp(hp^.optInfo)^.canBeRemoved) then
|
Not (PPaiProp(endP^.optInfo)^.canBeRemoved) then
|
||||||
begin
|
begin
|
||||||
sequenceEnd :=
|
sequenceEnd :=
|
||||||
RegLoadedWithNewValue(newReg,paicpu(endP)) or
|
RegLoadedWithNewValue(newReg,paicpu(endP)) or
|
||||||
@ -724,15 +741,18 @@ begin
|
|||||||
{ isn't used anymore }
|
{ isn't used anymore }
|
||||||
{ In case b, the newreg was completely replaced by oldreg, so it's contents }
|
{ In case b, the newreg was completely replaced by oldreg, so it's contents }
|
||||||
{ are unchanged compared the start of this sequence, so restore them }
|
{ are unchanged compared the start of this sequence, so restore them }
|
||||||
|
If RegLoadedWithNewValue(newReg,endP) then
|
||||||
|
GetLastInstruction(endP,hp)
|
||||||
|
else hp := endP;
|
||||||
if (p <> endp) or
|
if (p <> endp) or
|
||||||
not RegModifiedByInstruction(newReg,endP) then
|
not RegLoadedWithNewValue(newReg,endP) then
|
||||||
RestoreRegContentsTo(newReg, c ,p);
|
RestoreRegContentsTo(newReg, c ,p, hp);
|
||||||
{ In both case a and b, it is possible that the new register was modified }
|
{ In both case a and b, it is possible that the new register was modified }
|
||||||
{ (e.g. an add/sub), so if it was replaced by oldreg in that instruction, }
|
{ (e.g. an add/sub), so if it was replaced by oldreg in that instruction, }
|
||||||
{ oldreg's contents have been changed. To take this into account, we simply }
|
{ oldreg's contents have been changed. To take this into account, we simply }
|
||||||
{ set the contents of orgreg to "unknown" after this sequence }
|
{ set the contents of orgreg to "unknown" after this sequence }
|
||||||
if newRegModified then
|
if newRegModified then
|
||||||
ClearRegContentsFrom(orgReg,p);
|
ClearRegContentsFrom(orgReg,p,hp);
|
||||||
end
|
end
|
||||||
{$ifdef replaceregdebug}
|
{$ifdef replaceregdebug}
|
||||||
else
|
else
|
||||||
@ -898,8 +918,9 @@ Begin
|
|||||||
(RegInfo.New2OldReg[RegCounter] <> RegCounter) Then
|
(RegInfo.New2OldReg[RegCounter] <> RegCounter) Then
|
||||||
Begin
|
Begin
|
||||||
{$ifdef replacereg}
|
{$ifdef replacereg}
|
||||||
|
getLastInstruction(p,hp3);
|
||||||
If not ReplaceReg(RegInfo.New2OldReg[RegCounter],
|
If not ReplaceReg(RegInfo.New2OldReg[RegCounter],
|
||||||
regCounter,p,
|
regCounter,hp3,
|
||||||
PPaiProp(hp4^.optInfo)^.Regs[regCounter]) then
|
PPaiProp(hp4^.optInfo)^.Regs[regCounter]) then
|
||||||
begin
|
begin
|
||||||
{$endif replacereg}
|
{$endif replacereg}
|
||||||
@ -1093,7 +1114,10 @@ End.
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.36 1999-12-05 16:48:43 jonas
|
Revision 1.37 2000-01-03 17:11:17 jonas
|
||||||
|
* fixed bug with -dreplacereg
|
||||||
|
|
||||||
|
Revision 1.36 1999/12/05 16:48:43 jonas
|
||||||
* CSE of constant loading in regs works properly again
|
* CSE of constant loading in regs works properly again
|
||||||
+ if a constant is stored into memory using "mov const, ref" and
|
+ if a constant is stored into memory using "mov const, ref" and
|
||||||
there is a reg that contains this const, it is changed into
|
there is a reg that contains this const, it is changed into
|
||||||
|
Loading…
Reference in New Issue
Block a user