2
0

rgcpu.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the Xtensa specific class for the register
  4. allocator
  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. unit rgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. aasmbase,aasmcpu,aasmtai,aasmdata,
  22. cgbase,cgutils,
  23. cpubase,
  24. globtype,
  25. rgobj;
  26. type
  27. trgcpu=class(trgobj)
  28. procedure do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  29. procedure do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  30. protected
  31. procedure do_spill_op(list: tasmlist; op: tasmop; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  32. end;
  33. trgintcpu=class(trgcpu)
  34. end;
  35. implementation
  36. uses
  37. verbose,cutils,
  38. cgobj;
  39. procedure trgcpu.do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  40. var
  41. op: TAsmOp;
  42. begin
  43. case getregtype(tempreg) of
  44. R_FPUREGISTER:
  45. op:=A_LSI;
  46. R_INTREGISTER:
  47. op:=A_L32I;
  48. else
  49. Internalerror(2020041001);
  50. end;
  51. do_spill_op(list,op,pos,spilltemp,tempreg,orgsupreg);
  52. end;
  53. procedure trgcpu.do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  54. var
  55. op: TAsmOp;
  56. begin
  57. case getregtype(tempreg) of
  58. R_FPUREGISTER:
  59. op:=A_SSI;
  60. R_INTREGISTER:
  61. op:=A_S32I;
  62. else
  63. Internalerror(2020041002);
  64. end;
  65. do_spill_op(list,op,pos,spilltemp,tempreg,orgsupreg);
  66. end;
  67. procedure trgcpu.do_spill_op(list: tasmlist; op: tasmop; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  68. var
  69. helpins : tai;
  70. tmpref : treference;
  71. helplist : TAsmList;
  72. hreg : tregister;
  73. isload : boolean;
  74. begin
  75. isload:=op in [A_L32I,A_LSI];
  76. if abs(spilltemp.offset)>1020 then
  77. begin
  78. helplist:=TAsmList.create;
  79. if getregtype(tempreg)=R_INTREGISTER then
  80. begin
  81. if isload then
  82. hreg:=tempreg
  83. else
  84. hreg:=getregisterinline(helplist,[R_SUBWHOLE]);
  85. end
  86. else
  87. hreg:=cg.getintregister(helplist,OS_ADDR);
  88. if spilltemp.index<>NR_NO then
  89. Internalerror(2020032401);
  90. helplist.concat(taicpu.op_reg_reg_const(A_ADDMI,hreg,spilltemp.base,(spilltemp.offset div 256)*256));
  91. reference_reset(tmpref,sizeof(pint),[]);
  92. tmpref.base:=hreg;
  93. tmpref.offset:=spilltemp.offset mod 256;
  94. helpins:=taicpu.op_reg_ref(op,tempreg,tmpref);
  95. helplist.concat(helpins);
  96. if (getregtype(tempreg)=R_INTREGISTER) and not(isload) then
  97. ungetregisterinline(helplist,hreg);
  98. list.insertlistafter(pos,helplist);
  99. helplist.free;
  100. end
  101. else if isload then
  102. inherited do_spill_read(list,pos,spilltemp,tempreg,orgsupreg)
  103. else
  104. inherited do_spill_written(list,pos,spilltemp,tempreg,orgsupreg);
  105. end;
  106. end.