summaryrefslogtreecommitdiff
path: root/compiler/aoptda.pas
blob: e818471d7cd22278b35e68b9f2e6b31ab0c033fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{
    Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
    Development Team

    This unit contains the data flow analyzer object of the assembler
    optimizer.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************
}
Unit aoptda;

{$i fpcdefs.inc}

  Interface

    uses
      cpubase,cgbase,
      aasmtai,aasmdata,aasmcpu,
      aoptcpub, aoptbase;

    Type
      TAOptDFA = class
        { uses the same constructor as TAoptCpu = constructor from TAoptObj }

        { How many instructions are between the current instruction and the }
        { last one that modified the register                               }
        InstrSinceLastMod: TInstrSinceLastMod;

        { gathers the information regarding the contents of every register }
        { at the end of every instruction                                  }
        Procedure DoDFA;

        { handles the processor dependent dataflow analizing               }
        Procedure CpuDFA(p: PInstr); Virtual; Abstract;

        { convert a TInsChange value into the corresponding register }
        //!!!!!!!!!! Function TCh2Reg(Ch: TInsChange): TRegister; Virtual;
        { returns whether the instruction P reads from register Reg }
        Function RegReadByInstr(Reg: TRegister; p: tai): Boolean; Virtual; Abstract;
      End;

  Implementation

    uses
      globals;

    Procedure TAOptDFA.DoDFA;
    { Analyzes the Data Flow of an assembler list. Analyses the reg contents     }
    { for the instructions between blockstart and blockend. Returns the last pai }
    { which has been processed                                                   }
    {
    Var
        CurProp: TPaiProp;
        UsedRegs: TUsedRegs;
        p, hp, NewBlockStart : tai;
        TmpReg: TRegister;
    }
    Begin
    (*!!!!!!!!!!
      p := BlockStart;
      UsedRegs.Create;
      UsedRegs.Update(p);
      NewBlockStart := SkipHead(p);
      { done implicitely by the constructor
      FillChar(InstrSinceLastMod, SizeOf(InstrSinceLastMod), 0); }
      While (P <> BlockEnd) Do
        Begin
          CurProp:=TPaiProp.Create;
          If (p <> NewBlockStart) Then
            Begin
              GetLastInstruction(p, hp);
              CurProp.Regs := TPaiProp(hp.OptInfo).Regs;
    { !!!!!!!!!!!! }
    {$ifdef x86}
              CurProp.CondRegs.Flags :=
                TPaiProp(hp.OptInfo).CondRegs.Flags;
    {$endif}
            End;
          CurProp.UsedRegs.InitWithValue(UsedRegs.GetUsedRegs);
          UsedRegs.Update(tai(p.Next));
          TPaiProp(p.OptInfo) := CurProp;
          For TmpReg := LoGPReg To HiGPReg Do
            Inc(InstrSinceLastMod[TmpReg]);
          Case p^.typ Of
            ait_label:
              If (Pai_label(p)^.l^.is_used) Then
                CurProp^.DestroyAllRegs(InstrSinceLastMod);
            ait_stab, ait_force_line, ait_function_name:;
            ait_instruction:
              if not(PInstr(p)^.is_jmp) then
                begin
                  If IsLoadMemReg(p) Then
                    Begin
                      CurProp^.ReadRef(PInstr(p)^.oper[LoadSrc].ref);
                      TmpReg := RegMaxSize(PInstr(p)^.oper[LoadDst].reg);
                      If RegInRef(TmpReg, PInstr(p)^.oper[LoadSrc].ref^) And
                         (CurProp^.GetRegContentType(TmpReg) = Con_Ref) Then
                        Begin
                          { a load based on the value this register already }
                          { contained                                       }
                          With CurProp^.Regs[TmpReg] Do
                            Begin
                              CurProp^.IncWState(TmpReg);
                               {also store how many instructions are part of the  }
                               { sequence in the first instruction's PPaiProp, so }
                               { it can be easily accessed from within            }
                               { CheckSequence                                    }
                              Inc(NrOfMods, InstrSinceLastMod[TmpReg]);
                              PPaiProp(Pai(StartMod)^.OptInfo)^.Regs[TmpReg].NrOfMods := NrOfMods;
                              InstrSinceLastMod[TmpReg] := 0
                            End
                        End
                      Else
                        Begin
                          { load of a register with a completely new value }
                          CurProp^.DestroyReg(TmpReg, InstrSinceLastMod);
                          If Not(RegInRef(TmpReg, PInstr(p)^.oper[LoadSrc].ref^)) Then
                            With CurProp^.Regs[TmpReg] Do
                              Begin
                                Typ := Con_Ref;
                                StartMod := p;
                                NrOfMods := 1;
                              End
                        End;
      {$ifdef StateDebug}
                        hp := new(pai_asm_comment,init(strpnew(std_reg2str[TmpReg]+': '+tostr(CurProp^.Regs[TmpReg].WState))));
                        InsertLLItem(AsmL, p, p^.next, hp);
      {$endif StateDebug}

                    End
                  Else if IsLoadConstReg(p) Then
                    Begin
                      TmpReg := RegMaxSize(PInstr(p)^.oper[LoadDst].reg);
                      With CurProp^.Regs[TmpReg] Do
                        Begin
                          CurProp^.DestroyReg(TmpReg, InstrSinceLastMod);
                          typ := Con_Const;
                          StartMod := Pointer(PInstr(p)^.oper[LoadSrc].val);
                        End
                    End
                  Else CpuDFA(Pinstr(p));
                End;
            Else CurProp^.DestroyAllRegs(InstrSinceLastMod);
          End;
    {      Inc(InstrCnt);}
          GetNextInstruction(p, p);
        End;
    *)
    End;

End.