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