aoptcpu.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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_SAR,A_SHR:
  41. result:=PrePeepholeOptSxx(p);
  42. end;
  43. end;
  44. end;
  45. end;
  46. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  47. begin
  48. result:=False;
  49. case p.typ of
  50. ait_instruction:
  51. begin
  52. case taicpu(p).opcode of
  53. A_AND:
  54. Result:=OptPass1AND(p);
  55. A_MOV:
  56. Result:=OptPass1MOV(p);
  57. A_MOVSX,
  58. A_MOVZX:
  59. Result:=OptPass1Movx(p);
  60. A_VMOVAPS,
  61. A_VMOVAPD:
  62. result:=OptPass1VMOVAP(p);
  63. A_MOVAPD,
  64. A_MOVAPS:
  65. result:=OptPass1MOVAP(p);
  66. A_VDIVSD,
  67. A_VDIVSS,
  68. A_VSUBSD,
  69. A_VSUBSS,
  70. A_VMULSD,
  71. A_VMULSS,
  72. A_VADDSD,
  73. A_VADDSS:
  74. result:=OptPass1VOP(p);
  75. A_MULSD,
  76. A_MULSS,
  77. A_ADDSD,
  78. A_ADDSS:
  79. result:=OptPass1OP(p);
  80. A_VMOVSD,
  81. A_VMOVSS,
  82. A_MOVSD,
  83. A_MOVSS:
  84. result:=OptPass1MOVXX(p);
  85. end;
  86. end;
  87. end;
  88. end;
  89. function TCpuAsmOptimizer.PeepHoleOptPass2Cpu(var p : tai) : boolean;
  90. begin
  91. Result := False;
  92. case p.typ of
  93. ait_instruction:
  94. begin
  95. case taicpu(p).opcode of
  96. A_MOV:
  97. Result:=OptPass2MOV(p);
  98. A_IMUL:
  99. Result:=OptPass2Imul(p);
  100. A_JMP:
  101. Result:=OptPass2Jmp(p);
  102. A_Jcc:
  103. Result:=OptPass2Jcc(p);
  104. end;
  105. end;
  106. end;
  107. end;
  108. function TCpuAsmOptimizer.PostPeepHoleOptsCpu(var p: tai): boolean;
  109. begin
  110. result := false;
  111. case p.typ of
  112. ait_instruction:
  113. begin
  114. case taicpu(p).opcode of
  115. A_MOV:
  116. PostPeepholeOptMov(p);
  117. end;
  118. end;
  119. end;
  120. end;
  121. begin
  122. casmoptimizer := TCpuAsmOptimizer;
  123. end.