rgcpu.pas 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. {
  2. $Id$
  3. Copyright (c) 1998-2003 by Florian Klaempfl
  4. This unit implements the arm 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. }
  19. unit rgcpu;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. aasmbase,aasmtai,aasmcpu,
  24. cgbase,
  25. cpubase,
  26. rgobj;
  27. type
  28. trgcpu = class(trgobj)
  29. procedure add_cpu_interferences(p : tai);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_cpu_interferences(p : tai);
  43. begin
  44. if p.typ=ait_instruction then
  45. begin
  46. if (taicpu(p).opcode=A_MUL) then
  47. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  48. end;
  49. end;
  50. procedure trgcpu.do_spill_read(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  51. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  52. var
  53. helpins: tai;
  54. tmpref,ref : treference;
  55. helplist : taasmoutput;
  56. l : tasmlabel;
  57. tmpreg : tregister;
  58. begin
  59. ref:=spilltemplist[regs[regidx].orgreg];
  60. if abs(ref.offset)>4095 then
  61. begin
  62. helplist:=taasmoutput.create;
  63. reference_reset(tmpref);
  64. { create consts entry }
  65. objectlibrary.getlabel(l);
  66. cg.a_label(current_procinfo.aktlocaldata,l);
  67. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  68. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  69. { load consts entry }
  70. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  71. getregisterinline(helplist,pos,defaultsub,tmpreg)
  72. else
  73. tmpreg:=cg.getintregister(helplist,OS_ADDR);
  74. tmpref.symbol:=l;
  75. tmpref.base:=NR_R15;
  76. helplist.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  77. if ref.index<>NR_NO then
  78. internalerror(200401263);
  79. ref.index:=tmpreg;
  80. ref.offset:=0;
  81. helpins:=spilling_create_load(ref,regs[regidx].tempreg);
  82. helplist.concat(helpins);
  83. if pos=nil then
  84. list.insertlistafter(list.first,helplist)
  85. else
  86. list.insertlistafter(pos.next,helplist);
  87. ungetregisterinline(list,helpins,regs[regidx].tempreg);
  88. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  89. ungetregisterinline(list,helpins,tmpreg);
  90. forward_allocation(tai(helpins.next),instr);
  91. helplist.free;
  92. end
  93. else
  94. inherited do_spill_read(list,instr,pos,regidx,spilltemplist,regs);
  95. end;
  96. procedure trgcpu.do_spill_written(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  97. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  98. var
  99. helpins: tai;
  100. ref,tmpref : treference;
  101. helplist : taasmoutput;
  102. l : tasmlabel;
  103. tmpreg : tregister;
  104. begin
  105. ref:=spilltemplist[regs[regidx].orgreg];
  106. if abs(ref.offset)>4095 then
  107. begin
  108. helplist:=taasmoutput.create;
  109. reference_reset(tmpref);
  110. { create consts entry }
  111. objectlibrary.getlabel(l);
  112. cg.a_label(current_procinfo.aktlocaldata,l);
  113. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  114. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  115. { load consts entry }
  116. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  117. getregisterinline(helplist,pos,defaultsub,tmpreg)
  118. else
  119. tmpreg:=cg.getintregister(helplist,OS_ADDR);
  120. tmpref.symbol:=l;
  121. tmpref.base:=NR_R15;
  122. helplist.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  123. if ref.index<>NR_NO then
  124. internalerror(200401263);
  125. ref.index:=tmpreg;
  126. ref.offset:=0;
  127. helplist.concat(spilling_create_store(regs[regidx].tempreg,ref));
  128. ungetregisterinline(helplist,tai(helplist.last),regs[regidx].tempreg);
  129. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  130. ungetregisterinline(helplist,tai(helplist.last),tmpreg);
  131. list.insertlistafter(instr,helplist);
  132. helplist.free;
  133. end
  134. else
  135. inherited do_spill_written(list,instr,pos,regidx,spilltemplist,regs);
  136. end;
  137. procedure trgcpu.do_spill_readwritten(list : taasmoutput;instr : taicpu;pos: tai; regidx: word;
  138. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  139. var
  140. helpins1, helpins2: tai;
  141. tmpref,ref : treference;
  142. helplist : taasmoutput;
  143. l : tasmlabel;
  144. tmpreg : tregister;
  145. begin
  146. ref:=spilltemplist[regs[regidx].orgreg];
  147. if abs(ref.offset)>4095 then
  148. begin
  149. helplist:=taasmoutput.create;
  150. reference_reset(tmpref);
  151. { create consts entry }
  152. objectlibrary.getlabel(l);
  153. cg.a_label(current_procinfo.aktlocaldata,l);
  154. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  155. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  156. { load consts entry }
  157. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  158. getregisterinline(helplist,pos,defaultsub,tmpreg)
  159. else
  160. tmpreg:=cg.getintregister(helplist,OS_ADDR);
  161. tmpref.symbol:=l;
  162. tmpref.base:=NR_R15;
  163. helplist.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  164. if ref.index<>NR_NO then
  165. internalerror(200401263);
  166. ref.index:=tmpreg;
  167. ref.offset:=0;
  168. helpins1:=spilling_create_load(ref,regs[regidx].tempreg);
  169. helplist.concat(helpins1);
  170. if pos=nil then
  171. list.insertlistafter(list.first,helplist)
  172. else
  173. list.insertlistafter(pos.next,helplist);
  174. helpins2:=spilling_create_store(regs[regidx].tempreg,ref);
  175. list.insertafter(helpins2,instr);
  176. ungetregisterinline(list,helpins2,regs[regidx].tempreg);
  177. if getregtype(regs[regidx].tempreg)=R_INTREGISTER then
  178. ungetregisterinline(list,helpins2,tmpreg);
  179. forward_allocation(tai(helpins1.next),instr);
  180. end
  181. else
  182. inherited do_spill_readwritten(list,instr,pos,regidx,spilltemplist,regs);
  183. end;
  184. end.
  185. {
  186. $Log$
  187. Revision 1.12 2004-06-20 08:55:31 florian
  188. * logs truncated
  189. Revision 1.11 2004/06/16 20:07:10 florian
  190. * dwarf branch merged
  191. Revision 1.10.2.4 2004/06/13 20:38:38 florian
  192. * fixed floating point register spilling on sparc
  193. Revision 1.10.2.3 2004/06/13 16:02:39 florian
  194. * fixed floating point register spilling problems with offsets > 4095
  195. Revision 1.10.2.2 2004/06/13 10:51:17 florian
  196. * fixed several register allocator problems (sparc/arm)
  197. Revision 1.10.2.1 2004/06/12 17:01:01 florian
  198. * fixed compilation of arm compiler
  199. }