rgcpu.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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.22 2004-06-20 08:47:33 florian
  191. * spilling of doubles on sparc fixed
  192. Revision 1.21 2004/06/16 20:07:11 florian
  193. * dwarf branch merged
  194. Revision 1.20.2.4 2004/06/13 20:38:38 florian
  195. * fixed floating point register spilling on sparc
  196. Revision 1.20.2.3 2004/06/13 10:51:17 florian
  197. * fixed several register allocator problems (sparc/arm)
  198. Revision 1.20.2.2 2004/06/03 19:23:41 florian
  199. * fixed some spilling issues
  200. Revision 1.20.2.1 2004/05/30 17:54:14 florian
  201. + implemented cmp64bit
  202. * started to fix spilling
  203. * fixed int64 sub partially
  204. Revision 1.20 2003/10/24 15:20:37 peter
  205. * added more register functions
  206. Revision 1.19 2003/10/01 20:34:50 peter
  207. * procinfo unit contains tprocinfo
  208. * cginfo renamed to cgbase
  209. * moved cgmessage to verbose
  210. * fixed ppc and sparc compiles
  211. Revision 1.18 2003/09/14 19:19:05 peter
  212. * updates for new ra
  213. Revision 1.17 2003/09/03 15:55:01 peter
  214. * NEWRA branch merged
  215. Revision 1.16.2.2 2003/09/02 17:49:17 peter
  216. * newra updates
  217. Revision 1.16.2.1 2003/09/01 21:02:55 peter
  218. * sparc updates for new tregister
  219. Revision 1.16 2003/08/11 21:18:20 peter
  220. * start of sparc support for newra
  221. Revision 1.15 2003/07/02 22:18:04 peter
  222. * paraloc splitted in callerparaloc,calleeparaloc
  223. * sparc calling convention updates
  224. Revision 1.14 2003/06/17 16:36:11 peter
  225. * freeintparaloc added
  226. Revision 1.13 2003/06/12 22:47:52 mazen
  227. - unused temp var r removed in GetExplicitRegisterInt function
  228. * some case added for var and fauncions naming
  229. Revision 1.12 2003/06/12 21:11:44 peter
  230. * updates like the powerpc
  231. Revision 1.11 2003/06/01 21:38:07 peter
  232. * getregisterfpu size parameter added
  233. * op_const_reg size parameter added
  234. * sparc updates
  235. Revision 1.10 2003/05/31 01:00:51 peter
  236. * register fixes
  237. Revision 1.9 2003/04/22 10:09:35 daniel
  238. + Implemented the actual register allocator
  239. + Scratch registers unavailable when new register allocator used
  240. + maybe_save/maybe_restore unavailable when new register allocator used
  241. Revision 1.8 2003/03/15 22:51:58 mazen
  242. * remaking sparc rtl compile
  243. Revision 1.7 2003/03/10 21:59:54 mazen
  244. * fixing index overflow in handling new registers arrays.
  245. Revision 1.6 2003/02/19 22:00:17 daniel
  246. * Code generator converted to new register notation
  247. - Horribily outdated todo.txt removed
  248. Revision 1.5 2003/01/08 18:43:58 daniel
  249. * Tregister changed into a record
  250. Revision 1.4 2002/10/13 21:46:07 mazen
  251. * assembler output format fixed
  252. Revision 1.3 2002/10/12 19:03:23 mazen
  253. * Get/Unget expilit registers to be re-examined
  254. }