aoptcpu.pas 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. {
  2. Copyright (c) 1998-2014 by the Free Pascal development team
  3. This unit calls the optimization procedures to optimize the assembler
  4. code for m68k
  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, aasmtai;
  23. Type
  24. TCpuAsmOptimizer = class(TAsmOptimizer)
  25. function PeepHoleOptPass1Cpu(var p: tai): boolean; override;
  26. End;
  27. Implementation
  28. uses
  29. cutils, aasmcpu;
  30. function TCpuAsmOptimizer.PeepHoleOptPass1Cpu(var p: tai): boolean;
  31. var
  32. next: tai;
  33. begin
  34. result:=false;
  35. case p.typ of
  36. ait_instruction:
  37. begin
  38. //asml.insertbefore(tai_comment.Create(strpnew('pass1 called for instr')), p);
  39. { LEA (Ax),Ax is a NOP if src and dest reg is equal, so remove it. }
  40. if getnextinstruction(p,next) and (taicpu(p).opcode = A_LEA) and
  41. (not assigned(taicpu(p).oper[0]^.ref^.symbol)) and
  42. (((taicpu(p).oper[0]^.ref^.base = taicpu(p).oper[1]^.reg) and
  43. (taicpu(p).oper[0]^.ref^.index = NR_NO)) or
  44. ((taicpu(p).oper[0]^.ref^.index = taicpu(p).oper[1]^.reg) and
  45. (taicpu(p).oper[0]^.ref^.base = NR_NO))) and
  46. (taicpu(p).oper[0]^.ref^.offset = 0) then
  47. begin
  48. //asml.insertbefore(tai_comment.Create(strpnew('LEA (Ax),Ax removed')), p);
  49. asml.remove(p);
  50. p.free;
  51. p:=next;
  52. result:=true;
  53. end;
  54. end;
  55. end;
  56. end;
  57. begin
  58. casmoptimizer:=TCpuAsmOptimizer;
  59. end.