rgcpu.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the SPARC specific class for the register
  5. allocator
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************}
  18. unit rgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. aasmbase,aasmcpu,aasmtai,
  23. cgbase,cgutils,
  24. cpubase,
  25. rgobj;
  26. type
  27. trgcpu=class(trgobj)
  28. procedure add_constraints(reg:tregister);override;
  29. function get_spill_subreg(r : tregister) : tsubregister;override;
  30. procedure do_spill_read(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  31. procedure do_spill_written(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  32. end;
  33. implementation
  34. uses
  35. verbose,cutils,
  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:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  74. var
  75. helpins : tai;
  76. tmpref : treference;
  77. helplist : taasmoutput;
  78. hreg : tregister;
  79. begin
  80. if abs(spilltemp.offset)>4095 then
  81. begin
  82. helplist:=taasmoutput.create;
  83. if getregtype(tempreg)=R_INTREGISTER then
  84. hreg:=tempreg
  85. else
  86. hreg:=cg.getintregister(helplist,OS_ADDR);
  87. reference_reset(tmpref);
  88. tmpref.offset:=spilltemp.offset;
  89. tmpref.refaddr:=addr_hi;
  90. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,hreg));
  91. tmpref.refaddr:=addr_lo;
  92. helplist.concat(taicpu.op_reg_ref_reg(A_OR,hreg,tmpref,hreg));
  93. reference_reset_base(tmpref,hreg,0);
  94. tmpref.index:=spilltemp.base;
  95. helpins:=spilling_create_load(tmpref,tempreg);
  96. helplist.concat(helpins);
  97. list.insertlistafter(pos,helplist)
  98. end
  99. else
  100. inherited do_spill_read(list,pos,spilltemp,tempreg);
  101. end;
  102. procedure trgcpu.do_spill_written(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  103. var
  104. helpins : tai;
  105. tmpref : treference;
  106. helplist : taasmoutput;
  107. hreg : tregister;
  108. begin
  109. if abs(spilltemp.offset)>4095 then
  110. begin
  111. helplist:=taasmoutput.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);
  117. tmpref.offset:=spilltemp.offset;
  118. tmpref.refaddr:=addr_hi;
  119. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,hreg));
  120. tmpref.refaddr:=addr_lo;
  121. helplist.concat(taicpu.op_reg_ref_reg(A_OR,hreg,tmpref,hreg));
  122. reference_reset_base(tmpref,hreg,0);
  123. tmpref.index:=spilltemp.base;
  124. helpins:=spilling_create_store(tempreg,tmpref);
  125. helplist.concat(helpins);
  126. if getregtype(tempreg)=R_INTREGISTER then
  127. ungetregisterinline(helplist,hreg);
  128. list.insertlistafter(pos,helplist)
  129. end
  130. else
  131. inherited do_spill_written(list,pos,spilltemp,tempreg);
  132. end;
  133. end.
  134. {
  135. $Log$
  136. Revision 1.31 2004-10-31 21:45:04 peter
  137. * generic tlocation
  138. * move tlocation to cgutils
  139. Revision 1.30 2004/10/05 21:29:29 florian
  140. * fixed generation of refs wiht large offsets, code still broken though
  141. Revision 1.29 2004/10/05 20:41:02 peter
  142. * more spilling rewrites
  143. Revision 1.28 2004/10/04 20:46:22 peter
  144. * spilling code rewritten for x86. It now used the generic
  145. spilling routines. Special x86 optimization still needs
  146. to be added.
  147. * Spilling fixed when both operands needed to be spilled
  148. * Cleanup of spilling routine, do_spill_readwritten removed
  149. Revision 1.27 2004/10/01 17:33:47 peter
  150. * indents
  151. Revision 1.26 2004/09/28 20:19:36 peter
  152. * fixed crash
  153. Revision 1.25 2004/09/27 21:23:26 peter
  154. * fixed spilling code
  155. Revision 1.24 2004/08/24 21:02:33 florian
  156. * fixed longbool(<int64>) on sparc
  157. Revision 1.23 2004/06/20 08:55:32 florian
  158. * logs truncated
  159. Revision 1.22 2004/06/20 08:47:33 florian
  160. * spilling of doubles on sparc fixed
  161. Revision 1.21 2004/06/16 20:07:11 florian
  162. * dwarf branch merged
  163. Revision 1.20.2.4 2004/06/13 20:38:38 florian
  164. * fixed floating point register spilling on sparc
  165. Revision 1.20.2.3 2004/06/13 10:51:17 florian
  166. * fixed several register allocator problems (sparc/arm)
  167. Revision 1.20.2.2 2004/06/03 19:23:41 florian
  168. * fixed some spilling issues
  169. }