aoptcpu.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. {
  2. Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
  3. Development Team
  4. This unit implements the ARM optimizer object
  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, aoptcpub;
  22. Type
  23. TCpuAsmOptimizer = class(TAsmOptimizer)
  24. { uses the same constructor as TAopObj }
  25. function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
  26. procedure PeepHoleOptPass2;override;
  27. End;
  28. Implementation
  29. uses
  30. aasmbase,aasmcpu,cgbase;
  31. function CanBeCond(p : tai) : boolean;
  32. begin
  33. result:=(p.typ=ait_instruction) and (taicpu(p).condition=C_None);
  34. end;
  35. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  36. var
  37. next1: tai;
  38. begin
  39. result := false;
  40. case p.typ of
  41. ait_instruction:
  42. begin
  43. case taicpu(p).opcode of
  44. A_MOV:
  45. begin
  46. { fold
  47. mov reg2,reg0
  48. mov reg3,reg1
  49. to
  50. movw reg2,reg0
  51. }
  52. if (taicpu(p).ops=2) and
  53. (taicpu(p).oper[0]^.typ = top_reg) and
  54. (taicpu(p).oper[1]^.typ = top_reg) and
  55. getnextinstruction(p,next1) and
  56. (next1.typ = ait_instruction) and
  57. (taicpu(next1).opcode = A_MOV) and
  58. (taicpu(next1).ops=2) and
  59. (taicpu(next1).oper[0]^.typ = top_reg) and
  60. (taicpu(next1).oper[1]^.typ = top_reg) and
  61. (getsupreg(taicpu(next1).oper[0]^.reg)=getsupreg(taicpu(p).oper[0]^.reg)+1) and
  62. ((getsupreg(taicpu(p).oper[0]^.reg) mod 2)=0) and
  63. ((getsupreg(taicpu(p).oper[1]^.reg) mod 2)=0) and
  64. (getsupreg(taicpu(next1).oper[1]^.reg)=getsupreg(taicpu(p).oper[1]^.reg)+1) then
  65. begin
  66. taicpu(p).opcode:=A_MOVW;
  67. asml.remove(next1);
  68. next1.free;
  69. result := true;
  70. end;
  71. end;
  72. end;
  73. end;
  74. end;
  75. end;
  76. procedure TCpuAsmOptimizer.PeepHoleOptPass2;
  77. begin
  78. end;
  79. begin
  80. casmoptimizer:=TCpuAsmOptimizer;
  81. End.