aoptcpu.pas 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. {
  2. Copyright (c) 1998-2004 by Jonas Maebe
  3. This unit calls the optimization procedures to optimize the assembler
  4. code for sparc
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit aoptcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses cpubase, aasmtai, aopt, aoptx86;
  22. type
  23. TCpuAsmOptimizer = class(TX86AsmOptimizer)
  24. function PrePeepHoleOptsCpu(var p: tai): boolean; override;
  25. function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
  26. function PeepHoleOptPass2Cpu(var p: tai): boolean; override;
  27. function PostPeepHoleOptsCpu(var p : tai) : boolean; override;
  28. end;
  29. implementation
  30. uses
  31. globals,
  32. aasmcpu;
  33. function TCpuAsmOptimizer.PrePeepHoleOptsCpu(var p : tai) : boolean;
  34. begin
  35. result := false;
  36. case p.typ of
  37. ait_instruction:
  38. begin
  39. case taicpu(p).opcode of
  40. A_IMUL:
  41. result:=PrePeepholeOptIMUL(p);
  42. A_SAR,A_SHR:
  43. result:=PrePeepholeOptSxx(p);
  44. A_AND:
  45. Result:=PrePeepholeOptAND(p);
  46. else
  47. ;
  48. end;
  49. end;
  50. else
  51. ;
  52. end;
  53. end;
  54. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  55. begin
  56. result:=False;
  57. case p.typ of
  58. ait_instruction:
  59. begin
  60. case taicpu(p).opcode of
  61. A_ADD:
  62. Result:=OptPass1ADD(p);
  63. A_AND:
  64. Result:=OptPass1AND(p);
  65. A_IMUL:
  66. Result:=OptPass1Imul(p);
  67. A_MOV:
  68. Result:=OptPass1MOV(p);
  69. A_MOVSX,
  70. A_MOVSXD,
  71. A_MOVZX:
  72. Result:=OptPass1Movx(p);
  73. A_MOVAPD,
  74. A_MOVAPS,
  75. A_MOVUPD,
  76. A_MOVUPS,
  77. A_VMOVAPS,
  78. A_VMOVAPD,
  79. A_VMOVUPS,
  80. A_VMOVUPD:
  81. result:=OptPass1_V_MOVAP(p);
  82. A_VMINSS,
  83. A_VMINSD,
  84. A_VMAXSS,
  85. A_VMAXSD,
  86. A_VSQRTSD,
  87. A_VSQRTSS,
  88. A_VDIVSD,
  89. A_VDIVSS,
  90. A_VSUBSD,
  91. A_VSUBSS,
  92. A_VMULSD,
  93. A_VMULSS,
  94. A_VADDSD,
  95. A_VADDSS,
  96. A_VANDPD,
  97. A_VANDPS,
  98. A_VORPD,
  99. A_VORPS:
  100. result:=OptPass1VOP(p);
  101. A_MULSD,
  102. A_MULSS,
  103. A_ADDSD,
  104. A_ADDSS:
  105. result:=OptPass1OP(p);
  106. A_VMOVSD,
  107. A_VMOVSS,
  108. A_MOVSD,
  109. A_MOVSS:
  110. result:=OptPass1MOVXX(p);
  111. A_LEA:
  112. result:=OptPass1LEA(p);
  113. A_SUB:
  114. result:=OptPass1Sub(p);
  115. A_SHL,A_SAL:
  116. result:=OptPass1SHLSAL(p);
  117. A_FSTP,A_FISTP:
  118. result:=OptPass1FSTP(p);
  119. A_FLD:
  120. result:=OptPass1FLD(p);
  121. A_CMP:
  122. result:=OptPass1Cmp(p);
  123. A_VPXORD,
  124. A_VPXORQ,
  125. A_VXORPS,
  126. A_VXORPD,
  127. A_VPXOR:
  128. Result:=OptPass1VPXor(p);
  129. A_XORPS,
  130. A_XORPD,
  131. A_PXOR:
  132. Result:=OptPass1PXor(p);
  133. A_TEST:
  134. Result:=OptPass1Test(p);
  135. A_Jcc:
  136. Result:=OptPass1Jcc(p);
  137. A_SHRX,
  138. A_SHLX:
  139. Result:=OptPass1SHXX(p);
  140. else
  141. ;
  142. end;
  143. end;
  144. else
  145. ;
  146. end;
  147. end;
  148. function TCpuAsmOptimizer.PeepHoleOptPass2Cpu(var p : tai) : boolean;
  149. begin
  150. Result := False;
  151. case p.typ of
  152. ait_instruction:
  153. begin
  154. case taicpu(p).opcode of
  155. A_MOV:
  156. Result:=OptPass2MOV(p);
  157. A_MOVZX:
  158. Result:=OptPass2Movx(p);
  159. A_IMUL:
  160. Result:=OptPass2Imul(p);
  161. A_JMP:
  162. Result:=OptPass2Jmp(p);
  163. A_Jcc:
  164. Result:=OptPass2Jcc(p);
  165. A_Lea:
  166. Result:=OptPass2Lea(p);
  167. A_SUB:
  168. Result:=OptPass2SUB(p);
  169. A_ADD:
  170. Result:=OptPass2ADD(p);
  171. A_SETcc:
  172. result:=OptPass2SETcc(p);
  173. else
  174. ;
  175. end;
  176. end;
  177. else
  178. ;
  179. end;
  180. end;
  181. function TCpuAsmOptimizer.PostPeepHoleOptsCpu(var p: tai): boolean;
  182. begin
  183. result := false;
  184. case p.typ of
  185. ait_instruction:
  186. begin
  187. case taicpu(p).opcode of
  188. A_MOV:
  189. Result:=PostPeepholeOptMov(p);
  190. A_AND:
  191. Result:=PostPeepholeOptAnd(p);
  192. A_MOVSX:
  193. Result:=PostPeepholeOptMOVSX(p);
  194. A_MOVZX:
  195. Result:=PostPeepholeOptMovzx(p);
  196. A_CMP:
  197. Result:=PostPeepholeOptCmp(p);
  198. A_OR,
  199. A_TEST:
  200. Result:=PostPeepholeOptTestOr(p);
  201. A_XOR:
  202. Result:=PostPeepholeOptXor(p);
  203. A_CALL:
  204. Result:=PostPeepholeOptCall(p);
  205. A_LEA:
  206. Result:=PostPeepholeOptLea(p);
  207. A_PUSH:
  208. Result:=PostPeepholeOptPush(p);
  209. A_SHR:
  210. Result:=PostPeepholeOptShr(p);
  211. else
  212. ;
  213. end;
  214. { Optimise any reference-type operands (if Result is True, the
  215. instruction will be checked on the next iteration) }
  216. if not Result then
  217. OptimizeRefs(taicpu(p));
  218. end;
  219. else
  220. ;
  221. end;
  222. end;
  223. begin
  224. casmoptimizer := TCpuAsmOptimizer;
  225. end.