rgcpu.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. {
  2. Copyright (c) 1998-2008 by Florian Klaempfl
  3. This unit implements the avr 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,aasmsym,
  23. cgbase,cgutils,
  24. cpubase,
  25. rgobj;
  26. type
  27. trgcpu = class(trgobj)
  28. procedure add_constraints(reg:tregister);override;
  29. procedure do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  30. procedure do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister); override;
  31. function do_spill_replace(list : TAsmList;instr : tai_cpu_abstract_sym; orgreg : tsuperregister;const spilltemp : treference) : boolean; override;
  32. end;
  33. trgintcpu = class(trgcpu)
  34. procedure add_cpu_interferences(p : tai);override;
  35. end;
  36. implementation
  37. uses
  38. verbose, cutils,
  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 floats conflict with all odd float regs }
  47. R_SUBFD:
  48. begin
  49. {
  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. }
  58. end;
  59. { Let 64bit ints conflict with all odd int regs }
  60. R_SUBQ:
  61. begin
  62. supreg:=getsupreg(reg);
  63. {
  64. i:=RS_G1;
  65. while (i<=RS_I7) do
  66. begin
  67. add_edge(supreg,i);
  68. inc(i,2);
  69. end;
  70. }
  71. end;
  72. end;
  73. end;
  74. procedure trgcpu.do_spill_read(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  75. var
  76. helpins : tai;
  77. tmpref : treference;
  78. helplist : TAsmList;
  79. hreg : tregister;
  80. begin
  81. if abs(spilltemp.offset)>127 then
  82. begin
  83. Internalerror(2017032701);
  84. //
  85. // helplist:=TAsmList.create;
  86. //
  87. // helplist.concat(taicpu.op_reg_const(A_LDI,NR_R26,lo(word(spilltemp.offset))));
  88. // helplist.concat(taicpu.op_reg_const(A_LDI,NR_R27,hi(word(spilltemp.offset))));
  89. // helplist.concat(taicpu.op_reg_reg(A_ADD,NR_R26,spilltemp.base));
  90. // helplist.concat(taicpu.op_reg_reg(A_ADC,NR_R27,GetNextReg(spilltemp.base)));
  91. //
  92. // reference_reset_base(tmpref,NR_R26,0,1,[]);
  93. // helpins:=spilling_create_load(tmpref,tempreg);
  94. // helplist.concat(helpins);
  95. // list.insertlistafter(pos,helplist);
  96. // helplist.free;
  97. end
  98. else
  99. inherited;
  100. end;
  101. procedure trgcpu.do_spill_written(list: TAsmList; pos: tai; const spilltemp: treference; tempreg: tregister; orgsupreg: tsuperregister);
  102. var
  103. tmpref : treference;
  104. helplist : TAsmList;
  105. hreg : tregister;
  106. begin
  107. if abs(spilltemp.offset)>127 then
  108. begin
  109. Internalerror(2017032702);
  110. //
  111. // helplist:=TAsmList.create;
  112. //
  113. // helplist.concat(taicpu.op_reg_const(A_LDI,NR_R26,lo(word(spilltemp.offset))));
  114. // helplist.concat(taicpu.op_reg_const(A_LDI,NR_R27,hi(word(spilltemp.offset))));
  115. // helplist.concat(taicpu.op_reg_reg(A_ADD,NR_R26,spilltemp.base));
  116. // helplist.concat(taicpu.op_reg_reg(A_ADC,NR_R27,GetNextReg(spilltemp.base)));
  117. //
  118. // reference_reset_base(tmpref,NR_R26,0,1,[]);
  119. // helplist.concat(spilling_create_store(tempreg,tmpref));
  120. // list.insertlistafter(pos,helplist);
  121. // helplist.free;
  122. end
  123. else
  124. inherited;
  125. end;
  126. procedure trgintcpu.add_cpu_interferences(p : tai);
  127. var
  128. r : tsuperregister;
  129. begin
  130. //if p.typ=ait_instruction then
  131. // begin
  132. // case taicpu(p).opcode of
  133. // A_CPI,
  134. // A_ANDI,
  135. // A_ORI,
  136. // A_SUBI,
  137. // A_SBCI,
  138. // A_LDI:
  139. // for r:=RS_R0 to RS_R15 do
  140. // add_edge(r,GetSupReg(taicpu(p).oper[0]^.reg));
  141. // A_MULS:
  142. // begin
  143. // for r:=RS_R0 to RS_R15 do
  144. // add_edge(r,GetSupReg(taicpu(p).oper[0]^.reg));
  145. // for r:=RS_R0 to RS_R15 do
  146. // add_edge(r,GetSupReg(taicpu(p).oper[1]^.reg));
  147. // end;
  148. // end;
  149. // end;
  150. end;
  151. function trgcpu.do_spill_replace(list:TAsmList;instr:tai_cpu_abstract_sym;orgreg:tsuperregister;const spilltemp:treference):boolean;
  152. var
  153. b : byte;
  154. begin
  155. result:=false;
  156. if not(spilltemp.offset in [0..63]) then
  157. exit;
  158. { Replace 'mov dst,orgreg' with 'ld dst,spilltemp'
  159. and 'mov orgreg,src' with 'st dst,spilltemp' }
  160. with instr do
  161. begin
  162. if (opcode=A_LD) and (ops=2) and (oper[1]^.typ=top_reg) and (oper[0]^.typ=top_reg) then
  163. begin
  164. if (getregtype(oper[0]^.reg)=regtype) and
  165. (get_alias(getsupreg(oper[0]^.reg))=orgreg) and
  166. (get_alias(getsupreg(oper[1]^.reg))<>orgreg) then
  167. begin
  168. instr.loadreg(0,oper[1]^.reg);
  169. instr.loadref(1,spilltemp);
  170. opcode:=A_LD;
  171. result:=true;
  172. end
  173. else if (getregtype(oper[1]^.reg)=regtype) and
  174. (get_alias(getsupreg(oper[1]^.reg))=orgreg) and
  175. (get_alias(getsupreg(oper[0]^.reg))<>orgreg) then
  176. begin
  177. instr.loadref(0,spilltemp);
  178. opcode:=A_LD;
  179. result:=true;
  180. end;
  181. end;
  182. end;
  183. end;
  184. end.