aoptcpud.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {
  2. $Id $
  3. Copyright (c) 1999 by Jonas Maebe, member of the Free Pascal
  4. Development Team
  5. This unit contains the processor specific implementation of the
  6. assembler optimizer data flow analyzer.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ****************************************************************************
  19. }
  20. Unit aoptcpud;
  21. Interface
  22. uses Aasm, AoptCpub, AoptObj, AoptDA;
  23. Type TAsmDFACpu = Object(TAsmDFA)
  24. { uses the same constructor as TAoptDFA = constructor from TAoptObj }
  25. { handles the processor dependent dataflow analizing }
  26. Procedure CpuDFA(p: PInstr); Virtual;
  27. End;
  28. Implementation
  29. Procedure TAsmDFACpu(p: PInstr);
  30. { Analyzes the Data Flow of an assembler list. Analyses the reg contents }
  31. { for the instructions between blockstart and blockend. Returns the last pai }
  32. { which has been processed }
  33. Var CurProp: PPaiProp;
  34. InstrProp: TAsmInstrucProp;
  35. Cnt: Byte;
  36. Begin
  37. CurProp := PPaiProp(p^.OptInfo);
  38. Case p^.Opcode Of
  39. A_DIV, A_IDIV, A_MUL:
  40. Begin
  41. CurProp^.ReadOp(p^.oper[0]);
  42. CurProp^.ReadReg(R_EAX);
  43. If (p^.OpCode = A_IDIV) or
  44. (p^.OpCode = A_DIV) Then
  45. CurProp^.ReadReg(R_EDX);
  46. DestroyReg(R_EAX)
  47. End;
  48. A_IMUL:
  49. Begin
  50. CurProp^.ReadOp(p^.oper[0]);
  51. CurProp^.ReadOp(p^.oper[1]);
  52. If (p^.oper[2].typ = top_none) Then
  53. If (p^.oper[1].typ = top_none) Then
  54. Begin
  55. CurProp^.ReadReg(R_EAX);
  56. CurProp^.DestroyReg(R_EAX, InstrSinceLastMod);
  57. CurProp^.DestroyReg(R_EDX, InstrSinceLastMod)
  58. End
  59. Else
  60. {$ifdef arithopt}
  61. CurProp^.ModifyOp(p^.oper[1], InstrSinceLastMod)
  62. {$else arithopt}
  63. CurProp^.DestroyOp(p^.oper[1], InstrSinceLastMod)
  64. {$endif arithopt}
  65. Else
  66. {$ifdef arithopt}
  67. CurProp^.ModifyOp(p^.oper[2], InstrSinceLastMod);
  68. {$else arithopt}
  69. CurProp^.DestroyOp(p^.oper[2], InstrsinceLastMod);
  70. {$endif arithopt}
  71. End;
  72. A_XOR:
  73. Begin
  74. CurProp^.ReadOp(p^.oper[0]);
  75. CurProp^.ReadOp(p^.oper[1]);
  76. If (p^.oper[0].typ = top_reg) And
  77. (p^.oper[1].typ = top_reg) And
  78. (p^.oper[0].reg = p^.oper[1].reg) Then
  79. Begin
  80. CurProp^.DestroyReg(p^.oper[0].reg, InstrSinceLastMod);
  81. CurProp^.Regs[RegMaxSize(p^.oper[0].reg)].typ := Con_Const;
  82. CurProp^.Regs[RegMaxSize(p^.oper[0].reg)].StartMod := Pointer(0)
  83. End
  84. Else
  85. {$Ifdef ArithOpt}
  86. CurProp^.ModifyOp(p^.oper[1], InstrSinceLastMod);
  87. {$Else ArithOpt}
  88. CurProp^.DestroyOp(p^.oper[1], InstrSinceLastMod);
  89. {$EndIf ArithOpt}
  90. End
  91. Else
  92. Begin
  93. InstrProp := AsmInstr[p^.OpCode];
  94. Cnt := 1;
  95. While (Cnt <= MaxCh) And
  96. (InstrProp.Ch[Cnt] <> C_None) Do
  97. Begin
  98. Case InstrProp.Ch[Cnt] Of
  99. C_REAX..C_REDI:
  100. CurProp^.ReadReg(TCh2Reg(InstrProp.Ch[Cnt]));
  101. C_WEAX..C_RWEDI:
  102. Begin
  103. If (InstrProp.Ch[Cnt] >= C_RWEAX) Then
  104. CurProp^.ReadReg(TCh2Reg(InstrProp.Ch[Cnt]));
  105. CurProp^.DestroyReg(TCh2Reg(InstrProp.Ch[Cnt]),InstrSinceLastMod);
  106. End;
  107. {$ifdef arithopt}
  108. C_MEAX..C_MEDI:
  109. CurProp^.ModifyReg(TCh2Reg(InstrProp.Ch[Cnt]), InstrSinceLastMod);
  110. {$endif arithopt}
  111. C_CDirFlag: CurProp^.CondRegs.ClearFlag(DirFlag);
  112. C_SDirFlag: CurProp^.CondRegs.SetFlag(DirFlag);
  113. C_Rop1: ReadOp(CurProp, p^.oper[0]);
  114. C_Rop2: ReadOp(CurProp, p^.oper[1]);
  115. C_ROp3: ReadOp(CurProp, p^.oper[2]);
  116. C_Wop1..C_RWop1:
  117. Begin
  118. If (InstrProp.Ch[Cnt] = C_RWop1) Then
  119. ReadOp(CurProp, p^.oper[0]);
  120. DestroyOp(p, p^.oper[0], InstrSinceLastMod);
  121. End;
  122. {$ifdef arithopt}
  123. C_Mop1:
  124. CurProp^.ModifyOp(p^.oper[0], InstrSinceLastMod);
  125. {$endif arithopt}
  126. C_Wop2..C_RWop2:
  127. Begin
  128. If (InstrProp.Ch[Cnt] = C_RWop2) Then
  129. ReadOp(CurProp, p^.oper[1]);
  130. DestroyOp(p, p^.oper[1], InstrSinceLastMod);
  131. End;
  132. {$ifdef arithopt}
  133. C_Mop2:
  134. CurProp^.ModifyOp(p^.oper[1], InstrSinceLastMod);
  135. {$endif arithopt}
  136. C_Wop3..C_RWop3:
  137. Begin
  138. If (InstrProp.Ch[Cnt] = C_RWop3) Then
  139. ReadOp(CurProp, p^.oper[2]);
  140. DestroyOp(p, p^.oper[2], InstrSinceLastMod);
  141. End;
  142. {$ifdef arithopt}
  143. C_Mop3:
  144. CurProp^.ModifyOp(p^.oper[2], InstrSinceLastMod);
  145. {$endif arithopt}
  146. C_WMemEDI:
  147. Begin
  148. CurProp^.ReadReg(R_EDI);
  149. FillChar(TmpRef, SizeOf(TmpRef), 0);
  150. TmpRef.Base := R_EDI;
  151. DestroyRefs(p, TmpRef, R_NO, InstrSinceLastMod)
  152. End;
  153. C_RFlags, C_WFlags, C_RWFlags, C_FPU:;
  154. Else DestroyAllRegs(CurProp, InstrSinceLastMod)
  155. End;
  156. Inc(Cnt)
  157. End
  158. End
  159. End
  160. End;
  161. End.
  162. {
  163. $Log$
  164. Revision 1.1 1999-08-11 14:22:56 jonas
  165. + first version, added TAsmDFACpu object and CpuDFA method
  166. }