rgcpu.pas 8.1 KB

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