rgcpu.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. {
  2. Copyright (c) 1998-2003 by Florian Klaempfl
  3. This unit implements the arm specific class for the register
  4. allocator
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit rgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. aasmbase,aasmtai,aasmdata,aasmcpu,
  23. cgbase,cgutils,
  24. cpubase,
  25. rgobj;
  26. type
  27. { trgcpu }
  28. trgcpu = class(trgobj)
  29. procedure add_constraints(reg: Tregister); override;
  30. procedure add_cpu_interferences(p: tai); override;
  31. procedure do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  32. procedure do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  33. end;
  34. trgintcpu = class(trgcpu)
  35. end;
  36. implementation
  37. uses
  38. verbose, cutils,globtype,
  39. cgobj,
  40. procinfo;
  41. procedure trgcpu.add_constraints(reg: Tregister);
  42. var
  43. supreg,i : Tsuperregister;
  44. begin
  45. case getsubreg(reg) of
  46. { Let 64bit ints conflict with all odd int regs }
  47. R_SUBQ:
  48. begin
  49. supreg:=getsupreg(reg);
  50. i:=RS_R1;
  51. while (i<=RS_R15) do
  52. begin
  53. add_edge(supreg,i);
  54. inc(i,2);
  55. end;
  56. end;
  57. end;
  58. end;
  59. procedure trgcpu.add_cpu_interferences(p: tai);
  60. var
  61. r : Tsuperregister;
  62. begin
  63. if p.typ=ait_instruction then
  64. begin
  65. case taicpu(p).opcode of
  66. A_DIVS,
  67. A_DIVU:
  68. begin
  69. r:=RS_R1;
  70. while r <= RS_R15 do
  71. begin
  72. add_edge(getsupreg(taicpu(p).oper[0]^.reg), r);
  73. inc(r,2);
  74. end;
  75. end;
  76. A_MACHH,
  77. A_MACS,
  78. A_MACU,
  79. A_MACWH,
  80. A_MULNWH,
  81. A_MULS,
  82. A_MULU,
  83. A_MULWH:
  84. begin
  85. if taicpu(p).oppostfix=PF_D then
  86. begin
  87. r:=RS_R1;
  88. while r <= RS_R15 do
  89. begin
  90. add_edge(getsupreg(taicpu(p).oper[0]^.reg), r);
  91. inc(r,2);
  92. end;
  93. end;
  94. end;
  95. end;
  96. end;
  97. end;
  98. procedure trgcpu.do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  99. var
  100. tmpref : treference;
  101. helplist : TAsmList;
  102. l : tasmlabel;
  103. hreg : tregister;
  104. begin
  105. if in_signed_bits(spilltemp.offset,16) then
  106. begin
  107. {helplist:=TAsmList.create;
  108. reference_reset(tmpref,sizeof(aint));
  109. { create consts entry }
  110. current_asmdata.getjumplabel(l);
  111. cg.a_label(current_procinfo.aktlocaldata,l);
  112. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  113. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  114. { load consts entry }
  115. if getregtype(tempreg)=R_INTREGISTER then
  116. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  117. else
  118. hreg:=cg.getintregister(helplist,OS_ADDR);
  119. tmpref.symbol:=l;
  120. tmpref.base:=NR_R15;
  121. helplist.concat(setoppostfix(taicpu.op_reg_ref(A_LD,hreg,tmpref),PF_W));
  122. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(aint));
  123. tmpref.index:=hreg;
  124. if spilltemp.index<>NR_NO then
  125. internalerror(200401263);
  126. helplist.concat(spilling_create_load(tmpref,tempreg));
  127. if getregtype(tempreg)=R_INTREGISTER then
  128. ungetregisterinline(helplist,hreg);
  129. list.insertlistafter(pos,helplist);
  130. helplist.free; }
  131. end
  132. else
  133. inherited do_spill_read(list,pos,spilltemp,tempreg);
  134. end;
  135. procedure trgcpu.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  136. var
  137. tmpref : treference;
  138. helplist : TAsmList;
  139. l : tasmlabel;
  140. hreg : tregister;
  141. begin
  142. if in_signed_bits(spilltemp.offset,16) then
  143. begin
  144. {helplist:=TAsmList.create;
  145. reference_reset(tmpref,sizeof(aint));
  146. { create consts entry }
  147. current_asmdata.getjumplabel(l);
  148. cg.a_label(current_procinfo.aktlocaldata,l);
  149. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  150. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  151. { load consts entry }
  152. if getregtype(tempreg)=R_INTREGISTER then
  153. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  154. else
  155. hreg:=cg.getintregister(helplist,OS_ADDR);
  156. tmpref.symbol:=l;
  157. tmpref.base:=NR_R15;
  158. helplist.concat(setoppostfix(taicpu.op_reg_ref(A_LD,hreg,tmpref),PF_W));
  159. if spilltemp.index<>NR_NO then
  160. internalerror(200401263);
  161. reference_reset_base(tmpref,current_procinfo.framepointer,0,sizeof(pint));
  162. tmpref.index:=hreg;
  163. helplist.concat(spilling_create_store(tempreg,tmpref));
  164. if getregtype(tempreg)=R_INTREGISTER then
  165. ungetregisterinline(helplist,hreg);
  166. list.insertlistafter(pos,helplist);
  167. helplist.free;}
  168. end
  169. else
  170. inherited do_spill_written(list,pos,spilltemp,tempreg);
  171. end;
  172. end.