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,
  24. cgbase,
  25. cpubase,
  26. rgobj;
  27. type
  28. trgcpu = class(trgobj)
  29. procedure add_cpu_interferences(p : tai);override;
  30. procedure DoSpillRead(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: longint;
  31. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  32. procedure DoSpillWritten(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: longint;
  33. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  34. procedure DoSpillReadWritten(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: longint;
  35. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);override;
  36. end;
  37. implementation
  38. uses
  39. cgobj, verbose, cutils,
  40. procinfo,
  41. aasmcpu;
  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.DoSpillRead(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: longint;
  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. getregisterinline(helplist,nil,defaultsub,tmpreg);
  71. tmpref.symbol:=l;
  72. tmpref.base:=NR_R15;
  73. helplist.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  74. if ref.index<>NR_NO then
  75. internalerror(200401263);
  76. ref.index:=tmpreg;
  77. ref.offset:=0;
  78. helpins:=taicpu.op_reg_ref(A_LDR,regs[regidx].tempreg,ref);
  79. helplist.concat(helpins);
  80. if pos=nil then
  81. list.insertlistafter(list.first,helplist)
  82. else
  83. list.insertlistafter(pos.next,helplist);
  84. ungetregisterinline(helplist,tai(helplist.last),regs[regidx].tempreg);
  85. ungetregisterinline(list,instr,regs[regidx].tempreg);
  86. forward_allocation(tai(helpins.next),instr);
  87. helplist.free;
  88. end
  89. else
  90. begin
  91. helpins:=taicpu.op_reg_ref(A_LDR,regs[regidx].tempreg,ref);
  92. if pos=nil then
  93. list.insertafter(helpins,list.first)
  94. else
  95. list.insertafter(helpins,pos.next);
  96. ungetregisterinline(list,instr,regs[regidx].tempreg);
  97. forward_allocation(tai(helpins.next),instr);
  98. end;
  99. end;
  100. procedure trgcpu.DoSpillWritten(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: longint;
  101. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  102. var
  103. helpins: tai;
  104. ref,tmpref : treference;
  105. helplist : taasmoutput;
  106. l : tasmlabel;
  107. tmpreg : tregister;
  108. begin
  109. ref:=spilltemplist[regs[regidx].orgreg];
  110. if abs(ref.offset)>4095 then
  111. begin
  112. helplist:=taasmoutput.create;
  113. reference_reset(tmpref);
  114. { create consts entry }
  115. objectlibrary.getlabel(l);
  116. cg.a_label(current_procinfo.aktlocaldata,l);
  117. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  118. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  119. { load consts entry }
  120. getregisterinline(helplist,nil,defaultsub,tmpreg);
  121. tmpref.symbol:=l;
  122. tmpref.base:=NR_R15;
  123. helplist.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  124. if ref.index<>NR_NO then
  125. internalerror(200401263);
  126. ref.index:=tmpreg;
  127. ref.offset:=0;
  128. helplist.concat(taicpu.op_reg_ref(A_STR,regs[regidx].tempreg,ref));
  129. ungetregisterinline(helplist,tai(helplist.last),regs[regidx].tempreg);
  130. ungetregisterinline(helplist,tai(helplist.last),tmpreg);
  131. list.insertlistafter(instr,helplist);
  132. helplist.free;
  133. end
  134. else
  135. begin
  136. helpins:=taicpu.op_reg_ref(A_STR,regs[regidx].tempreg,ref);
  137. list.insertafter(helpins,instr);
  138. ungetregisterinline(list,helpins,regs[regidx].tempreg);
  139. end;
  140. end;
  141. procedure trgcpu.DoSpillReadWritten(list : taasmoutput;instr : taicpu_abstract;pos: tai; regidx: longint;
  142. const spilltemplist:Tspill_temp_list;const regs : tspillregsinfo);
  143. var
  144. helpins1, helpins2: tai;
  145. tmpref,ref : treference;
  146. tmpreg : tregister;
  147. begin
  148. ref:=spilltemplist[regs[regidx].orgreg];
  149. {
  150. if abs(ref.offset)>4095 then
  151. begin
  152. reference_reset(tmpref);
  153. { create consts entry }
  154. objectlibrary.getlabel(l);
  155. cg.a_label(current_procinfo.aktlocaldata,l);
  156. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  157. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(ref.offset));
  158. { load consts entry }
  159. getregisterinline(list,pos,defaultsub,tmpreg);
  160. tmpref.symbol:=l;
  161. tmpref.base:=NR_R15;
  162. list.concat(taicpu.op_reg_ref(A_LDR,tmpreg,tmpref));
  163. if ref.index<>NR_NO then
  164. internalerror(200401263);
  165. ref.index:=tmpreg;
  166. ref.offset:=0;
  167. end;
  168. }
  169. helpins1:=taicpu.op_reg_ref(A_LDR,regs[regidx].tempreg,ref);
  170. if pos=nil then
  171. list.insertafter(helpins1,list.first)
  172. else
  173. list.insertafter(helpins1,pos.next);
  174. ref:=spilltemplist[regs[regidx].orgreg];
  175. ref.symboldata:=nil;
  176. helpins2:=taicpu.op_reg_ref(A_STR,regs[regidx].tempreg,ref);
  177. list.insertafter(helpins2,instr);
  178. ungetregisterinline(list,helpins2,regs[regidx].tempreg);
  179. forward_allocation(tai(helpins1.next),instr);
  180. end;
  181. end.
  182. {
  183. $Log$
  184. Revision 1.7 2004-01-28 15:36:47 florian
  185. * fixed another couple of arm bugs
  186. Revision 1.6 2004/01/26 19:05:56 florian
  187. * fixed several arm issues
  188. Revision 1.5 2003/11/02 14:30:03 florian
  189. * fixed ARM for new reg. allocation scheme
  190. Revision 1.4 2003/09/11 11:55:00 florian
  191. * improved arm code generation
  192. * move some protected and private field around
  193. * the temp. register for register parameters/arguments are now released
  194. before the move to the parameter register is done. This improves
  195. the code in a lot of cases.
  196. Revision 1.3 2003/09/04 00:15:29 florian
  197. * first bunch of adaptions of arm compiler for new register type
  198. Revision 1.2 2003/08/25 23:20:38 florian
  199. + started to implement FPU support for the ARM
  200. * fixed a lot of other things
  201. Revision 1.1 2003/08/16 13:23:01 florian
  202. * several arm related stuff fixed
  203. }