aoptcpu.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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
  22. cpubase, aoptobj, aoptcpub, aopt, aoptx86,
  23. aasmtai;
  24. Type
  25. TCpuAsmOptimizer = class(TX86AsmOptimizer)
  26. function PeepHoleOptPass1Cpu(var p : tai) : boolean; override;
  27. End;
  28. Implementation
  29. uses
  30. globals,
  31. verbose,
  32. cpuinfo,
  33. aasmcpu,
  34. aoptutils;
  35. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p : tai) : boolean;
  36. var
  37. hp1 : tai;
  38. hp2 : tai;
  39. begin
  40. result:=false;
  41. case p.typ of
  42. ait_instruction:
  43. begin
  44. case taicpu(p).opcode of
  45. A_MOV:
  46. begin
  47. if MatchInstruction(p,A_MOV,[S_W]) and
  48. MatchOpType(taicpu(p),top_ref,top_reg) and
  49. GetNextInstruction(p, hp1) and
  50. MatchInstruction(hp1,A_MOV,[S_W]) and
  51. MatchOpType(taicpu(hp1),top_ref,top_reg) and
  52. GetNextInstruction(hp1, hp2) and
  53. MatchInstruction(hp2,A_MOV,[S_W]) and
  54. MatchOpType(taicpu(hp2),top_reg,top_reg) and
  55. not(OpsEqual(taicpu(p).oper[1]^,taicpu(hp1).oper[1]^)) and
  56. OpsEqual(taicpu(hp1).oper[1]^,taicpu(hp2).oper[0]^) and
  57. (MatchOperand(taicpu(hp2).oper[1]^,NR_ES) or MatchOperand(taicpu(hp2).oper[1]^,NR_DS) or
  58. ((current_settings.cputype>=cpu_386) and
  59. (MatchOperand(taicpu(hp2).oper[1]^,NR_SS) or
  60. MatchOperand(taicpu(hp2).oper[1]^,NR_FS) or
  61. MatchOperand(taicpu(hp2).oper[1]^,NR_GS)))) and
  62. (taicpu(p).oper[0]^.ref^.base=taicpu(hp1).oper[0]^.ref^.base) and
  63. (taicpu(p).oper[0]^.ref^.index=taicpu(hp1).oper[0]^.ref^.index) and
  64. (taicpu(p).oper[0]^.ref^.segment=taicpu(hp1).oper[0]^.ref^.segment) and
  65. (taicpu(p).oper[0]^.ref^.symbol=taicpu(hp1).oper[0]^.ref^.symbol) and
  66. (taicpu(p).oper[0]^.ref^.relsymbol=taicpu(hp1).oper[0]^.ref^.relsymbol) and
  67. (taicpu(p).oper[0]^.ref^.offset+2=taicpu(hp1).oper[0]^.ref^.offset) and
  68. assigned(FindRegDealloc(taicpu(hp2).oper[0]^.reg,tai(hp2.Next))) then
  69. begin
  70. case taicpu(hp2).oper[1]^.reg of
  71. NR_DS:
  72. taicpu(p).opcode:=A_LDS;
  73. NR_ES:
  74. taicpu(p).opcode:=A_LES;
  75. NR_SS:
  76. taicpu(p).opcode:=A_LSS;
  77. NR_FS:
  78. taicpu(p).opcode:=A_LFS;
  79. NR_GS:
  80. taicpu(p).opcode:=A_LGS;
  81. else
  82. internalerror(2015092601);
  83. end;
  84. asml.remove(hp1);
  85. hp1.free;
  86. asml.remove(hp2);
  87. hp2.free;
  88. result:=true;
  89. end;
  90. end;
  91. end
  92. end
  93. end;
  94. end;
  95. begin
  96. casmoptimizer:=TCpuAsmOptimizer;
  97. end.