rgcpu.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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,
  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;instr : taicpu;pos: tai; regidx: word;
  31. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  32. procedure do_spill_written(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  33. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  34. procedure do_spill_readwritten(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  35. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  36. end;
  37. implementation
  38. uses
  39. verbose, cutils,
  40. cgutils,cgobj;
  41. procedure trgcpu.add_constraints(reg:tregister);
  42. var
  43. supreg,i : Tsuperregister;
  44. begin
  45. case getsubreg(reg) of
  46. { Let 64bit floats conflict with all odd float regs }
  47. R_SUBFD:
  48. begin
  49. supreg:=getsupreg(reg);
  50. i:=RS_F1;
  51. while (i<=RS_F31) do
  52. begin
  53. add_edge(supreg,i);
  54. inc(i,2);
  55. end;
  56. end;
  57. { Let 64bit ints conflict with all odd int regs }
  58. R_SUBQ:
  59. begin
  60. supreg:=getsupreg(reg);
  61. i:=RS_G1;
  62. while (i<=RS_I7) do
  63. begin
  64. add_edge(supreg,i);
  65. inc(i,2);
  66. end;
  67. end;
  68. end;
  69. end;
  70. function trgcpu.get_spill_subreg(r : tregister) : tsubregister;
  71. begin
  72. if getregtype(r)=R_FPUREGISTER then
  73. result:=getsubreg(r)
  74. else
  75. result:=defaultsub;
  76. end;
  77. procedure trgcpu.do_spill_read(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  78. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  79. var
  80. helpins: tai;
  81. tmpref,ref : treference;
  82. helplist : taasmoutput;
  83. tmpreg : tregister;
  84. begin
  85. ref:=spilltemplist[regs[regidx].orgreg];
  86. if abs(ref.offset)>4095 then
  87. begin
  88. helplist:=taasmoutput.create;
  89. reference_reset(tmpref);
  90. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  91. getregisterinline(helplist,nil,defaultsub,tmpreg)
  92. else
  93. tmpreg:=cg.getintregister(helplist,OS_ADDR);
  94. tmpref.offset:=ref.offset;
  95. tmpref.refaddr:=addr_hi;
  96. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,tmpreg));
  97. tmpref.refaddr:=addr_lo;
  98. helplist.concat(taicpu.op_reg_ref_reg(A_OR,tmpreg,tmpref,tmpreg));
  99. if ref.index<>NR_NO then
  100. internalerror(200401263);
  101. ref.index:=tmpreg;
  102. ref.offset:=0;
  103. helpins:=spilling_create_load(ref,regs[regidx].tempreg);
  104. helplist.concat(helpins);
  105. if pos=nil then
  106. list.insertlistafter(list.first,helplist)
  107. else
  108. list.insertlistafter(pos.next,helplist);
  109. helplist.free;
  110. ungetregisterinline(list,helpins,regs[regidx].tempreg);
  111. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  112. ungetregisterinline(list,helpins,tmpreg);
  113. forward_allocation(tai(helpins.next),instr);
  114. end
  115. else
  116. inherited do_spill_read(list,instr,pos,regidx,spilltemplist,regs);
  117. end;
  118. procedure trgcpu.do_spill_written(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  119. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  120. var
  121. helpins: tai;
  122. ref,tmpref : treference;
  123. helplist : taasmoutput;
  124. tmpreg : tregister;
  125. begin
  126. ref:=spilltemplist[regs[regidx].orgreg];
  127. if abs(ref.offset)>4095 then
  128. begin
  129. helplist:=taasmoutput.create;
  130. reference_reset(tmpref);
  131. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  132. getregisterinline(helplist,pos,defaultsub,tmpreg)
  133. else
  134. tmpreg:=cg.getintregister(helplist,OS_ADDR);
  135. tmpref.offset:=ref.offset;
  136. tmpref.refaddr:=addr_hi;
  137. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,tmpreg));
  138. tmpref.refaddr:=addr_lo;
  139. helplist.concat(taicpu.op_reg_ref_reg(A_OR,tmpreg,tmpref,tmpreg));
  140. if ref.index<>NR_NO then
  141. internalerror(200401263);
  142. ref.index:=tmpreg;
  143. ref.offset:=0;
  144. helpins:=spilling_create_store(regs[regidx].tempreg,ref);
  145. helplist.concat(helpins);
  146. list.insertlistafter(instr,helplist);
  147. helplist.free;
  148. ungetregisterinline(list,helpins,regs[regidx].tempreg);
  149. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  150. ungetregisterinline(list,helpins,tmpreg);
  151. end
  152. else
  153. inherited do_spill_written(list,instr,pos,regidx,spilltemplist,regs);
  154. end;
  155. procedure trgcpu.do_spill_readwritten(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  156. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  157. var
  158. helpins1, helpins2: tai;
  159. tmpref,ref : treference;
  160. helplist : taasmoutput;
  161. tmpreg : tregister;
  162. begin
  163. ref:=spilltemplist[regs[regidx].orgreg];
  164. if abs(ref.offset)>4095 then
  165. begin
  166. helplist:=taasmoutput.create;
  167. reference_reset(tmpref);
  168. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  169. getregisterinline(helplist,nil,defaultsub,tmpreg)
  170. else
  171. tmpreg:=cg.getintregister(helplist,OS_ADDR);
  172. tmpref.offset:=ref.offset;
  173. tmpref.refaddr:=addr_hi;
  174. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,tmpreg));
  175. tmpref.refaddr:=addr_lo;
  176. helplist.concat(taicpu.op_reg_ref_reg(A_OR,tmpreg,tmpref,tmpreg));
  177. if ref.index<>NR_NO then
  178. internalerror(200401263);
  179. ref.index:=tmpreg;
  180. ref.offset:=0;
  181. helpins1:=spilling_create_load(ref,regs[regidx].tempreg);
  182. helplist.concat(helpins1);
  183. if pos=nil then
  184. list.insertlistafter(list.first,helplist)
  185. else
  186. list.insertlistafter(pos.next,helplist);
  187. helplist.free;
  188. helpins2:=spilling_create_store(regs[regidx].tempreg,ref);
  189. list.insertafter(helpins2,instr);
  190. ungetregisterinline(list,helpins2,regs[regidx].tempreg);
  191. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  192. ungetregisterinline(list,helpins2,tmpreg);
  193. forward_allocation(tai(helpins1.next),instr);
  194. end
  195. else
  196. inherited do_spill_readwritten(list,instr,pos,regidx,spilltemplist,regs);
  197. end;
  198. end.
  199. {
  200. $Log$
  201. Revision 1.26 2004-09-28 20:19:36 peter
  202. * fixed crash
  203. Revision 1.25 2004/09/27 21:23:26 peter
  204. * fixed spilling code
  205. Revision 1.24 2004/08/24 21:02:33 florian
  206. * fixed longbool(<int64>) on sparc
  207. Revision 1.23 2004/06/20 08:55:32 florian
  208. * logs truncated
  209. Revision 1.22 2004/06/20 08:47:33 florian
  210. * spilling of doubles on sparc fixed
  211. Revision 1.21 2004/06/16 20:07:11 florian
  212. * dwarf branch merged
  213. Revision 1.20.2.4 2004/06/13 20:38:38 florian
  214. * fixed floating point register spilling on sparc
  215. Revision 1.20.2.3 2004/06/13 10:51:17 florian
  216. * fixed several register allocator problems (sparc/arm)
  217. Revision 1.20.2.2 2004/06/03 19:23:41 florian
  218. * fixed some spilling issues
  219. }