2
$Id: aoptcpud.pas,v 1.3 2002/09/07 15:25:14 peter Exp $
3
Copyright (c) 1998-2000 by Jonas Maebe, member of the Free Pascal
6
This unit contains the processor specific implementation of the
7
assembler optimizer data flow analyzer.
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
****************************************************************************
29
uses Aasm, cpubase, AoptCpub, AoptObj, AoptDA;
32
PAOptDFACpu = ^TAOptDFACpu;
33
TAOptDFACpu = Object(TAOptDFA)
34
{ uses the same constructor as TAoptDFA = constructor from TAoptObj }
36
{ handles the processor dependent dataflow analizing }
37
Procedure CpuDFA(p: PInstr); Virtual;
38
Function TCh2Reg(Ch: TInsChange): TRegister; Virtual;
39
Function RegReadByInstr(Reg: TRegister; p: Pai): Boolean; Virtual;
46
Procedure TAOptDFACpu.CpuDFA(p: PInstr);
47
{ Analyzes the Data Flow of an assembler list. Analyses the reg contents }
48
{ for the instructions between blockstart and blockend. Returns the last pai }
49
{ which has been processed }
50
Var CurProp: PPaiProp;
55
CurProp := PPaiProp(p^.OptInfo);
59
CurProp^.ReadOp(p^.oper[0]);
60
CurProp^.ReadReg(R_EAX);
61
If (p^.OpCode = A_IDIV) or
62
(p^.OpCode = A_DIV) Then
63
CurProp^.ReadReg(R_EDX);
64
CurProp^.DestroyReg(R_EAX, InstrSinceLastMod)
68
CurProp^.ReadOp(p^.oper[0]);
69
CurProp^.ReadOp(p^.oper[1]);
70
If (p^.oper[2].typ = top_none) Then
71
If (p^.oper[1].typ = top_none) Then
73
CurProp^.ReadReg(R_EAX);
74
CurProp^.DestroyReg(R_EAX, InstrSinceLastMod);
75
CurProp^.DestroyReg(R_EDX, InstrSinceLastMod)
78
CurProp^.ModifyOp(p^.oper[1], InstrSinceLastMod)
80
CurProp^.ModifyOp(p^.oper[2], InstrSinceLastMod);
84
CurProp^.ReadOp(p^.oper[0]);
85
CurProp^.ReadOp(p^.oper[1]);
86
If (p^.oper[0].typ = top_reg) And
87
(p^.oper[1].typ = top_reg) And
88
(p^.oper[0].reg = p^.oper[1].reg) Then
90
CurProp^.DestroyReg(p^.oper[0].reg, InstrSinceLastMod);
91
CurProp^.Regs[RegMaxSize(p^.oper[0].reg)].typ := Con_Const;
92
CurProp^.Regs[RegMaxSize(p^.oper[0].reg)].StartMod := Pointer(0)
95
CurProp^.ModifyOp(p^.oper[1], InstrSinceLastMod);
99
InstrProp := InsProp[p^.OpCode];
101
While (Cnt <= MaxCh) And
102
(InstrProp.Ch[Cnt] <> Ch_None) Do
104
Case InstrProp.Ch[Cnt] Of
106
CurProp^.ReadReg(TCh2Reg(InstrProp.Ch[Cnt]));
109
If (InstrProp.Ch[Cnt] >= Ch_RWEAX) Then
110
CurProp^.ReadReg(TCh2Reg(InstrProp.Ch[Cnt]));
111
CurProp^.DestroyReg(TCh2Reg(InstrProp.Ch[Cnt]),InstrSinceLastMod);
114
CurProp^.ModifyReg(TCh2Reg(InstrProp.Ch[Cnt]), InstrSinceLastMod);
115
Ch_CDirFlag: CurProp^.CondRegs.ClearFlag(DirFlag);
116
Ch_SDirFlag: CurProp^.CondRegs.SetFlag(DirFlag);
117
Ch_Rop1: CurProp^.ReadOp(p^.oper[0]);
118
Ch_Rop2: CurProp^.ReadOp(p^.oper[1]);
119
Ch_Rop3: CurProp^.ReadOp(p^.oper[2]);
122
If (InstrProp.Ch[Cnt] = Ch_RWop1) Then
123
CurProp^.ReadOp(p^.oper[0]);
124
CurProp^.DestroyOp(p^.oper[0], InstrSinceLastMod);
127
CurProp^.ModifyOp(p^.oper[0], InstrSinceLastMod);
130
If (InstrProp.Ch[Cnt] = Ch_RWop2) Then
131
CurProp^.ReadOp(p^.oper[1]);
132
CurProp^.DestroyOp(p^.oper[1], InstrSinceLastMod);
135
CurProp^.ModifyOp(p^.oper[1], InstrSinceLastMod);
138
If (InstrProp.Ch[Cnt] = Ch_RWop3) Then
139
CurProp^.ReadOp(p^.oper[2]);
140
CurProp^.DestroyOp(p^.oper[2], InstrSinceLastMod);
143
CurProp^.ModifyOp(p^.oper[2], InstrSinceLastMod);
146
CurProp^.ReadReg(R_EDI);
147
FillChar(TmpRef, SizeOf(TmpRef), 0);
148
TmpRef.Base := R_EDI;
149
CurProp^.DestroyRefs(TmpRef, R_NO, InstrSinceLastMod)
151
Ch_RFlags, Ch_WFlags, Ch_RWFlags, Ch_FPU:;
152
Else CurProp^.DestroyAllRegs(InstrSinceLastMod)
160
Function TAOptDFACpu.RegReadByInstr(Reg: TRegister; p: Pai): Boolean;
166
If (p^.typ = ait_instruction) Then
167
Case PInstr(p)^.opcode of
171
RegInOp(Reg,oper[0]) or
172
RegInOp(Reg,oper[1]) or
175
A_DIV, A_IDIV, A_MUL:
178
RegInOp(Reg,oper[0]) or
182
(opcode = A_IDIV)) and
187
InstrProp := InsProp[PInstr(p)^.OpCode];
188
While (Cnt <= MaxCh) And
189
(InstrProp.Ch[Cnt] <> Ch_None) And
192
Case InstrProp.Ch[Cnt] Of
193
Ch_REAX..Ch_REDI,Ch_RWEAX..Ch_RWEDI
195
TmpResult := Reg = TCh2Reg(InstrProp.Ch[Cnt]);
196
Ch_ROp1,Ch_RWOp1,Ch_Mop1:
197
TmpResult := RegInOp(Reg,PInstr(p)^.oper[0]);
198
Ch_ROp2,Ch_RWOp2,Ch_Mop2:
199
TmpResult := RegInOp(Reg,PInstr(p)^.oper[1]);
200
Ch_ROp3,Ch_RWOp3,Ch_Mop3:
201
TmpResult := RegInOp(Reg,PInstr(p)^.oper[2]);
202
Ch_WOp1: TmpResult := (PInstr(p)^.oper[0].typ = top_ref) And
203
RegInRef(Reg,PInstr(p)^.oper[0].ref^);
204
Ch_WOp2: TmpResult := (PInstr(p)^.oper[1].typ = top_ref) And
205
RegInRef(Reg,PInstr(p)^.oper[1].ref^);
206
Ch_WOp3: TmpResult := (PInstr(p)^.oper[2].typ = top_ref) And
207
RegInRef(Reg,PInstr(p)^.oper[2].ref^);
208
Ch_WMemEDI: TmpResult := (Reg = R_EDI);
209
Ch_FPU: TmpResult := Reg in [R_ST..R_ST7,R_MM0..R_MM7]
215
RegReadByInstr := TmpResult
218
Function TAOptDFACpu.TCh2Reg(Ch: TInsChange): TRegister;
220
If (Ch <= Ch_REDI) Then
221
TCh2Reg := TRegister(Byte(Ch))
223
If (Ch <= Ch_WEDI) Then
224
TCh2Reg := TRegister(Byte(Ch) - Byte(Ch_REDI))
226
If (Ch <= Ch_RWEDI) Then
227
TCh2Reg := TRegister(Byte(Ch) - Byte(Ch_WEDI))
229
If (Ch <= Ch_MEDI) Then
230
TCh2Reg := TRegister(Byte(Ch) - Byte(Ch_RWEDI))
237
$Log: aoptcpud.pas,v $
238
Revision 1.3 2002/09/07 15:25:14 peter
239
* old logs removed and tabs fixed