rgcpu.pas 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the register allocator for m68k
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit rgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. aasmbase,aasmtai,aasmdata,aasmcpu,
  22. cgbase,cgutils,cpubase,
  23. rgobj;
  24. type
  25. trgcpu = class(trgobj)
  26. function do_spill_replace(list:TAsmList;instr:taicpu;orgreg:tsuperregister;const spilltemp:treference):boolean;override;
  27. end;
  28. implementation
  29. { returns True if source operand of MOVE can be replaced with spilltemp when its destination is ref^. }
  30. function isvalidmovedest(ref: preference): boolean; inline;
  31. begin
  32. { The following is for Coldfire, for other CPUs it maybe can be relaxed. }
  33. result:=(ref^.symbol=nil) and (ref^.scalefactor<=1) and
  34. (ref^.index=NR_NO) and (ref^.base<>NR_NO) and (ref^.offset>=low(smallint)) and
  35. (ref^.offset<=high(smallint));
  36. end;
  37. function trgcpu.do_spill_replace(list:TAsmList;instr:taicpu;orgreg:tsuperregister;const spilltemp:treference):boolean;
  38. var
  39. opidx: longint;
  40. begin
  41. result:=false;
  42. opidx:=-1;
  43. { TODO: support more instructions (on m68k almost all are eligible) }
  44. if (not (regtype in [R_INTREGISTER,R_ADDRESSREGISTER])) or (instr.opcode<>A_MOVE) then
  45. exit;
  46. if (instr.ops<>2) then
  47. exit;
  48. if (instr.oper[0]^.typ=top_reg) and (get_alias(getsupreg(instr.oper[0]^.reg))=orgreg) then
  49. begin
  50. { source can be replaced if dest is register or a 'simple' reference }
  51. if (instr.oper[1]^.typ=top_reg) or
  52. ((instr.oper[1]^.typ=top_ref) and isvalidmovedest(instr.oper[1]^.ref)) then
  53. opidx:=0;
  54. end
  55. else if (instr.oper[1]^.typ=top_reg) and (get_alias(getsupreg(instr.oper[1]^.reg))=orgreg) and
  56. (instr.oper[0]^.typ=top_reg) then
  57. opidx:=1;
  58. if (opidx<0) then
  59. exit;
  60. instr.oper[opidx]^.typ:=top_ref;
  61. new(instr.oper[opidx]^.ref);
  62. instr.oper[opidx]^.ref^:=spilltemp;
  63. case instr.opsize of
  64. S_B: inc(instr.oper[opidx]^.ref^.offset,3);
  65. S_W: inc(instr.oper[opidx]^.ref^.offset,2);
  66. end;
  67. result:=true;
  68. end;
  69. end.