rgcpu.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the SPARC 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. rgobj;
  25. type
  26. trgcpu=class(trgobj)
  27. procedure add_constraints(reg:tregister);override;
  28. function get_spill_subreg(r : tregister) : tsubregister;override;
  29. procedure do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  30. procedure do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  31. end;
  32. implementation
  33. uses
  34. verbose,cutils,
  35. globtype,
  36. cgobj;
  37. procedure trgcpu.add_constraints(reg:tregister);
  38. var
  39. supreg,i : Tsuperregister;
  40. begin
  41. case getsubreg(reg) of
  42. { Let 64bit floats conflict with all odd float regs }
  43. R_SUBFD:
  44. begin
  45. supreg:=getsupreg(reg);
  46. i:=RS_F1;
  47. while (i<=RS_F31) do
  48. begin
  49. add_edge(supreg,i);
  50. inc(i,2);
  51. end;
  52. end;
  53. { Let 64bit ints conflict with all odd int regs }
  54. R_SUBQ:
  55. begin
  56. supreg:=getsupreg(reg);
  57. i:=RS_G1;
  58. while (i<=RS_I7) do
  59. begin
  60. add_edge(supreg,i);
  61. inc(i,2);
  62. end;
  63. end;
  64. end;
  65. end;
  66. function trgcpu.get_spill_subreg(r : tregister) : tsubregister;
  67. begin
  68. if getregtype(r)=R_FPUREGISTER then
  69. result:=getsubreg(r)
  70. else
  71. result:=defaultsub;
  72. end;
  73. procedure trgcpu.do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  74. var
  75. helpins : tai;
  76. tmpref : treference;
  77. helplist : TAsmList;
  78. hreg : tregister;
  79. begin
  80. if abs(spilltemp.offset)>4095 then
  81. begin
  82. helplist:=TAsmList.create;
  83. if getregtype(tempreg)=R_INTREGISTER then
  84. hreg:=tempreg
  85. else
  86. hreg:=cg.getintregister(helplist,OS_ADDR);
  87. reference_reset(tmpref,sizeof(pint));
  88. tmpref.offset:=spilltemp.offset;
  89. tmpref.refaddr:=addr_high;
  90. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,hreg));
  91. tmpref.refaddr:=addr_low;
  92. helplist.concat(taicpu.op_reg_ref_reg(A_OR,hreg,tmpref,hreg));
  93. reference_reset_base(tmpref,hreg,0,sizeof(aint));
  94. tmpref.index:=spilltemp.base;
  95. helpins:=spilling_create_load(tmpref,tempreg);
  96. helplist.concat(helpins);
  97. list.insertlistafter(pos,helplist);
  98. helplist.free;
  99. end
  100. else
  101. inherited do_spill_read(list,pos,spilltemp,tempreg);
  102. end;
  103. procedure trgcpu.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  104. var
  105. tmpref : treference;
  106. helplist : TAsmList;
  107. hreg : tregister;
  108. begin
  109. if abs(spilltemp.offset)>4095 then
  110. begin
  111. helplist:=TAsmList.create;
  112. if getregtype(tempreg)=R_INTREGISTER then
  113. hreg:=getregisterinline(helplist,R_SUBWHOLE)
  114. else
  115. hreg:=cg.getintregister(helplist,OS_ADDR);
  116. reference_reset(tmpref,sizeof(aint));
  117. tmpref.offset:=spilltemp.offset;
  118. tmpref.refaddr:=addr_high;
  119. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,hreg));
  120. tmpref.refaddr:=addr_low;
  121. helplist.concat(taicpu.op_reg_ref_reg(A_OR,hreg,tmpref,hreg));
  122. reference_reset_base(tmpref,hreg,0,sizeof(aint));
  123. tmpref.index:=spilltemp.base;
  124. helplist.concat(spilling_create_store(tempreg,tmpref));
  125. if getregtype(tempreg)=R_INTREGISTER then
  126. ungetregisterinline(helplist,hreg);
  127. list.insertlistafter(pos,helplist);
  128. helplist.free;
  129. end
  130. else
  131. inherited do_spill_written(list,pos,spilltemp,tempreg);
  132. end;
  133. end.