aoptcpu.pas 3.6 KB

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