* fixes from daopt386.pas integrated

This commit is contained in:
Jonas Maebe 1999-09-29 13:50:34 +00:00
parent e62d58ea51
commit 167f8d654f

View File

@ -49,6 +49,7 @@ Type
{ ************************************************************************* } { ************************************************************************* }
{ ************************* Some general type definitions ***************** } { ************************* Some general type definitions ***************** }
{ ************************************************************************* } { ************************************************************************* }
TRefCompare = Function(const r1, r2: TReference): Boolean;
TRegArray = Array[LoReg..HiReg] of TRegister; TRegArray = Array[LoReg..HiReg] of TRegister;
TRegSet = Set of LoReg..HiReg; TRegSet = Set of LoReg..HiReg;
{ possible actions on an operand: read, write or modify (= read & write) } { possible actions on an operand: read, write or modify (= read & write) }
@ -184,11 +185,18 @@ Type
{ returns whether the reference Ref is used somewhere in the loading } { returns whether the reference Ref is used somewhere in the loading }
{ sequence Content } { sequence Content }
Function RefInSequence(Const Ref: TReference; Content: TContent): Boolean; Function RefInSequence(Const Ref: TReference; Content: TContent;
RefsEq: TRefCompare): Boolean;
{ returns whether the instruction P reads from and/or writes } { returns whether the instruction P reads from and/or writes }
{ to Reg } { to Reg }
Function RefInInstruction(Const Ref: TReference; p: Pai): Boolean; Function RefInInstruction(Const Ref: TReference; p: Pai;
RefsEq: TRefCompare): Boolean;
{ returns whether two references with at least one pointing to an array }
{ may point to the same memory location }
Function ArrayRefsEq(const r1, r2: TReference): Boolean;
End; End;
{ ************************************************************************* } { ************************************************************************* }
@ -407,21 +415,36 @@ Begin
End End
End; End;
Function TPaiProp.ArrayRefsEq(const r1, r2: TReference): Boolean;
Begin
ArrayRefsEq := (R1.Offset+R1.OffsetFixup = R2.Offset+R2.OffsetFixup) And
(R1.Segment = R2.Segment) And (R1.Base = R2.Base) And
(R1.Symbol=R2.Symbol);
End;
Procedure TPaiProp.DestroyRefs(Const Ref: TReference; WhichReg: TRegister; Procedure TPaiProp.DestroyRefs(Const Ref: TReference; WhichReg: TRegister;
var InstrSinceLastMod: TInstrSinceLastMod); var InstrSinceLastMod: TInstrSinceLastMod);
{ destroys all registers which possibly contain a reference to Ref, WhichReg } { destroys all registers which possibly contain a reference to Ref, WhichReg }
{ is the register whose contents are being written to memory (if this proc } { is the register whose contents are being written to memory (if this proc }
{ is called because of a "mov?? %reg, (mem)" instruction) } { is called because of a "mov?? %reg, (mem)" instruction) }
Var Counter: TRegister; Var RefsEq: TRefCompare;
Counter: TRegister;
Begin Begin
WhichReg := RegMaxSize(WhichReg); WhichReg := RegMaxSize(WhichReg);
If ((Ref.base = ProcInfo.FramePointer) If (Ref.base = procinfo^.FramePointer) or
Assigned(Ref.Symbol) Then
Begin
If
{$ifdef refsHaveIndexReg} {$ifdef refsHaveIndexReg}
And (Ref.Index = R_NO (Ref.Index = R_NO) And
{$endif refsHaveIndexReg} {$endif refsHaveIndexReg}
) Or (Not(Assigned(Ref.Symbol)) or
Assigned(Ref.Symbol) (Ref.base = R_NO)) Then
Then { local variable which is not an array }
RefsEq := {$ifdef fpc}@{$endif}RefsEqual
Else
{ local variable which is an array }
RefsEq := {$ifdef fpc}@{$endif}ArrayRefsEq;
{write something to a parameter, a local or global variable, so {write something to a parameter, a local or global variable, so
* with uncertain optimizations on: * with uncertain optimizations on:
- destroy the contents of registers whose contents have somewhere a - destroy the contents of registers whose contents have somewhere a
@ -438,12 +461,12 @@ Begin
((Not(cs_UncertainOpts in aktglobalswitches) And ((Not(cs_UncertainOpts in aktglobalswitches) And
(NrOfMods <> 1) (NrOfMods <> 1)
) Or ) Or
(RefInSequence(Ref,Regs[Counter]) And (RefInSequence(Ref,Regs[Counter], RefsEq) And
((Counter <> WhichReg) Or ((Counter <> WhichReg) Or
((NrOfMods <> 1) And ((NrOfMods <> 1) And
{StarMod is always of the type ait_instruction} {StarMod is always of the type ait_instruction}
(PInstr(StartMod)^.oper[0].typ = top_ref) And (PInstr(StartMod)^.oper[0].typ = top_ref) And
RefsEqual(PInstr(StartMod)^.oper[0].ref^, Ref) RefsEq(PInstr(StartMod)^.oper[0].ref^, Ref)
) )
) )
) )
@ -482,7 +505,10 @@ Procedure TPaiProp.DestroyAllRegs(var InstrSinceLastMod: TInstrSinceLastMod);
Var Counter: TRegister; Var Counter: TRegister;
Begin {initializes/desrtoys all registers} Begin {initializes/desrtoys all registers}
For Counter := R_EAX To R_EDI Do For Counter := R_EAX To R_EDI Do
Begin
ReadReg(Counter);
DestroyReg(Counter, InstrSinceLastMod); DestroyReg(Counter, InstrSinceLastMod);
End;
CondRegs.Init; CondRegs.Init;
{ FPURegs.Init; } { FPURegs.Init; }
End; End;
@ -492,7 +518,11 @@ Procedure TPaiProp.DestroyOp(const o:Toper; var InstrSinceLastMod:
Begin Begin
Case o.typ Of Case o.typ Of
top_reg: DestroyReg(o.reg, InstrSinceLastMod); top_reg: DestroyReg(o.reg, InstrSinceLastMod);
top_ref: DestroyRefs(o.ref^, R_NO, InstrSinceLastMod); top_ref:
Begin
ReadRef(o.ref^);
DestroyRefs(o.ref^, R_NO, InstrSinceLastMod);
End;
top_symbol:; top_symbol:;
End; End;
End; End;
@ -593,7 +623,8 @@ Begin
Else s := 0 Else s := 0
End; End;
Function TPaiProp.RefInInstruction(Const Ref: TReference; p: Pai): Boolean; Function TPaiProp.RefInInstruction(Const Ref: TReference; p: Pai;
RefsEq: TRefCompare): Boolean;
Var Count: AWord; Var Count: AWord;
TmpResult: Boolean; TmpResult: Boolean;
Begin Begin
@ -603,15 +634,15 @@ Begin
Count := 0; Count := 0;
Repeat Repeat
If (PInstr(p)^.oper[Count].typ = Top_Ref) Then If (PInstr(p)^.oper[Count].typ = Top_Ref) Then
TmpResult := RefsEqual(Ref, PInstr(p)^.oper[Count].ref^); TmpResult := RefsEq(Ref, PInstr(p)^.oper[Count].ref^);
Inc(Count); Inc(Count);
Until (Count = MaxOps) or TmpResult; Until (Count = MaxOps) or TmpResult;
End; End;
RefInInstruction := TmpResult; RefInInstruction := TmpResult;
End; End;
Function TPaiProp.RefInSequence(Const Ref: TReference; Content: TContent): Function TPaiProp.RefInSequence(Const Ref: TReference; Content: TContent;
Boolean; RefsEq: TRefCompare): Boolean;
Var p: Pai; Var p: Pai;
Counter: Byte; Counter: Byte;
TmpResult: Boolean; TmpResult: Boolean;
@ -753,7 +784,10 @@ End.
{ {
$Log$ $Log$
Revision 1.5 1999-08-26 14:50:52 jonas Revision 1.6 1999-09-29 13:50:34 jonas
* fixes from daopt386.pas integrated
Revision 1.5 1999/08/26 14:50:52 jonas
* fixed small type in TP conditional * fixed small type in TP conditional
Revision 1.4 1999/08/18 14:32:22 jonas Revision 1.4 1999/08/18 14:32:22 jonas