rgcpu.pas 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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,
  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_abstract;pos: tai; regidx: word;
  31. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  32. procedure do_spill_written(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: word;
  33. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  34. procedure do_spill_readwritten(list : taasmoutput;instr : taicpu_abstract;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. aasmcpu;
  43. procedure trgcpu.add_cpu_interferences(p : tai);
  44. begin
  45. if p.typ=ait_instruction then
  46. begin
  47. if (taicpu(p).opcode=A_MUL) then
  48. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  49. end;
  50. end;
  51. procedure trgcpu.do_spill_read(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: word;
  52. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  53. var
  54. helpins: tai;
  55. tmpref,ref : treference;
  56. helplist : taasmoutput;
  57. l : tasmlabel;
  58. tmpreg : tregister;
  59. begin
  60. ref:=spilltemplist[regs[regidx].orgreg];
  61. if abs(ref.offset)>4095 then
  62. begin
  63. helplist:=taasmoutput.create;
  64. reference_reset(tmpref);
  65. { create consts entry }
  66. objectlibrary.getlabel(l);
  67. cg.a_label(current_procinfo.aktlocaldata,l);
  68. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  69. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  70. { load consts entry }
  71. getregisterinline(helplist,nil,defaultsub,tmpreg);
  72. tmpref.symbol:=l;
  73. tmpref.base:=NR_R15;
  74. helplist.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  75. if ref.index<>NR_NO then
  76. internalerror(200401263);
  77. ref.index:=tmpreg;
  78. ref.offset:=0;
  79. helpins:=taicpu.op_reg_ref(A_LDR,regs[regidx].tempreg,ref);
  80. helplist.concat(helpins);
  81. if pos=nil then
  82. list.insertlistafter(list.first,helplist)
  83. else
  84. list.insertlistafter(pos.next,helplist);
  85. ungetregisterinline(helplist,tai(helplist.last),regs[regidx].tempreg);
  86. ungetregisterinline(list,instr,regs[regidx].tempreg);
  87. forward_allocation(tai(helpins.next),instr);
  88. helplist.free;
  89. end
  90. else
  91. begin
  92. helpins:=taicpu.op_reg_ref(A_LDR,regs[regidx].tempreg,ref);
  93. if pos=nil then
  94. list.insertafter(helpins,list.first)
  95. else
  96. list.insertafter(helpins,pos.next);
  97. ungetregisterinline(list,instr,regs[regidx].tempreg);
  98. forward_allocation(tai(helpins.next),instr);
  99. end;
  100. end;
  101. procedure trgcpu.do_spill_written(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: word;
  102. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  103. var
  104. helpins: tai;
  105. ref,tmpref : treference;
  106. helplist : taasmoutput;
  107. l : tasmlabel;
  108. tmpreg : tregister;
  109. begin
  110. ref:=spilltemplist[regs[regidx].orgreg];
  111. if abs(ref.offset)>4095 then
  112. begin
  113. helplist:=taasmoutput.create;
  114. reference_reset(tmpref);
  115. { create consts entry }
  116. objectlibrary.getlabel(l);
  117. cg.a_label(current_procinfo.aktlocaldata,l);
  118. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  119. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  120. { load consts entry }
  121. getregisterinline(helplist,nil,defaultsub,tmpreg);
  122. tmpref.symbol:=l;
  123. tmpref.base:=NR_R15;
  124. helplist.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  125. if ref.index<>NR_NO then
  126. internalerror(200401263);
  127. ref.index:=tmpreg;
  128. ref.offset:=0;
  129. helplist.concat(taicpu.op_reg_ref(A_STR,regs[regidx].tempreg,ref));
  130. ungetregisterinline(helplist,tai(helplist.last),regs[regidx].tempreg);
  131. ungetregisterinline(helplist,tai(helplist.last),tmpreg);
  132. list.insertlistafter(instr,helplist);
  133. helplist.free;
  134. end
  135. else
  136. begin
  137. helpins:=taicpu.op_reg_ref(A_STR,regs[regidx].tempreg,ref);
  138. list.insertafter(helpins,instr);
  139. ungetregisterinline(list,helpins,regs[regidx].tempreg);
  140. end;
  141. end;
  142. procedure trgcpu.do_spill_readwritten(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: word;
  143. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  144. var
  145. helpins1, helpins2: tai;
  146. tmpref,ref : treference;
  147. tmpreg : tregister;
  148. begin
  149. ref:=spilltemplist[regs[regidx].orgreg];
  150. internalerror(200403141);
  151. {
  152. if abs(ref.offset)>4095 then
  153. begin
  154. reference_reset(tmpref);
  155. { create consts entry }
  156. objectlibrary.getlabel(l);
  157. cg.a_label(current_procinfo.aktlocaldata,l);
  158. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  159. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  160. { load consts entry }
  161. getregisterinline(list,pos,defaultsub,tmpreg);
  162. tmpref.symbol:=l;
  163. tmpref.base:=NR_R15;
  164. list.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  165. if ref.index<>NR_NO then
  166. internalerror(200401263);
  167. ref.index:=tmpreg;
  168. ref.offset:=0;
  169. end;
  170. }
  171. helpins1:=taicpu.op_reg_ref(A_LDR,regs[regidx].tempreg,ref);
  172. if pos=nil then
  173. list.insertafter(helpins1,list.first)
  174. else
  175. list.insertafter(helpins1,pos.next);
  176. ref:=spilltemplist[regs[regidx].orgreg];
  177. ref.symboldata:=nil;
  178. helpins2:=taicpu.op_reg_ref(A_STR,regs[regidx].tempreg,ref);
  179. list.insertafter(helpins2,instr);
  180. ungetregisterinline(list,helpins2,regs[regidx].tempreg);
  181. forward_allocation(tai(helpins1.next),instr);
  182. end;
  183. end.
  184. {
  185. $Log$
  186. Revision 1.10 2004-03-14 16:15:40 florian
  187. * spilling problem fixed
  188. * handling of floating point memory references fixed
  189. Revision 1.9 2004/03/06 20:35:20 florian
  190. * fixed arm compilation
  191. * cleaned up code generation for exported linux procedures
  192. Revision 1.8 2004/02/08 23:06:59 florian
  193. * fixed compilation problem
  194. Revision 1.7 2004/01/28 15:36:47 florian
  195. * fixed another couple of arm bugs
  196. Revision 1.6 2004/01/26 19:05:56 florian
  197. * fixed several arm issues
  198. Revision 1.5 2003/11/02 14:30:03 florian
  199. * fixed ARM for new reg. allocation scheme
  200. Revision 1.4 2003/09/11 11:55:00 florian
  201. * improved arm code generation
  202. * move some protected and private field around
  203. * the temp. register for register parameters/arguments are now released
  204. before the move to the parameter register is done. This improves
  205. the code in a lot of cases.
  206. Revision 1.3 2003/09/04 00:15:29 florian
  207. * first bunch of adaptions of arm compiler for new register type
  208. Revision 1.2 2003/08/25 23:20:38 florian
  209. + started to implement FPU support for the ARM
  210. * fixed a lot of other things
  211. Revision 1.1 2003/08/16 13:23:01 florian
  212. * several arm related stuff fixed
  213. }