rgcpu.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 = class(trgobj)
  28. procedure do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  29. procedure do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  30. end;
  31. trgintcpu = class(trgcpu)
  32. procedure add_cpu_interferences(p : tai);override;
  33. end;
  34. implementation
  35. uses
  36. verbose, cutils,
  37. cgobj,
  38. procinfo;
  39. procedure trgcpu.do_spill_read(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  40. var
  41. tmpref : treference;
  42. helplist : TAsmList;
  43. l : tasmlabel;
  44. hreg : tregister;
  45. begin
  46. { don't load spilled register between
  47. mov lr,pc
  48. mov pc,r4
  49. but befure the mov lr,pc
  50. }
  51. if assigned(pos.previous) and
  52. (pos.typ=ait_instruction) and
  53. (taicpu(pos).opcode=A_MOV) and
  54. (taicpu(pos).oper[0]^.typ=top_reg) and
  55. (taicpu(pos).oper[0]^.reg=NR_R14) and
  56. (taicpu(pos).oper[1]^.typ=top_reg) and
  57. (taicpu(pos).oper[1]^.reg=NR_PC) then
  58. pos:=tai(pos.previous);
  59. if abs(spilltemp.offset)>4095 then
  60. begin
  61. helplist:=TAsmList.create;
  62. reference_reset(tmpref);
  63. { create consts entry }
  64. current_asmdata.getjumplabel(l);
  65. cg.a_label(current_procinfo.aktlocaldata,l);
  66. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  67. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  68. { load consts entry }
  69. if getregtype(tempreg)=R_INTREGISTER then
  70. hreg:=getregisterinline(helplist,R_SUBWHOLE)
  71. else
  72. hreg:=cg.getintregister(helplist,OS_ADDR);
  73. tmpref.symbol:=l;
  74. tmpref.base:=NR_R15;
  75. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  76. reference_reset_base(tmpref,current_procinfo.framepointer,0);
  77. tmpref.index:=hreg;
  78. if spilltemp.index<>NR_NO then
  79. internalerror(200401263);
  80. helplist.concat(spilling_create_load(tmpref,tempreg));
  81. if getregtype(tempreg)=R_INTREGISTER then
  82. ungetregisterinline(helplist,hreg);
  83. list.insertlistafter(pos,helplist);
  84. helplist.free;
  85. end
  86. else
  87. inherited do_spill_read(list,pos,spilltemp,tempreg);
  88. end;
  89. procedure trgcpu.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  90. var
  91. tmpref : treference;
  92. helplist : TAsmList;
  93. l : tasmlabel;
  94. hreg : tregister;
  95. begin
  96. if abs(spilltemp.offset)>4095 then
  97. begin
  98. helplist:=TAsmList.create;
  99. reference_reset(tmpref);
  100. { create consts entry }
  101. current_asmdata.getjumplabel(l);
  102. cg.a_label(current_procinfo.aktlocaldata,l);
  103. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  104. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  105. { load consts entry }
  106. if getregtype(tempreg)=R_INTREGISTER then
  107. hreg:=getregisterinline(helplist,R_SUBWHOLE)
  108. else
  109. hreg:=cg.getintregister(helplist,OS_ADDR);
  110. tmpref.symbol:=l;
  111. tmpref.base:=NR_R15;
  112. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  113. if spilltemp.index<>NR_NO then
  114. internalerror(200401263);
  115. reference_reset_base(tmpref,current_procinfo.framepointer,0);
  116. tmpref.index:=hreg;
  117. helplist.concat(spilling_create_store(tempreg,tmpref));
  118. if getregtype(tempreg)=R_INTREGISTER then
  119. ungetregisterinline(helplist,hreg);
  120. list.insertlistafter(pos,helplist);
  121. helplist.free;
  122. end
  123. else
  124. inherited do_spill_written(list,pos,spilltemp,tempreg);
  125. end;
  126. procedure trgintcpu.add_cpu_interferences(p : tai);
  127. var
  128. r : tregister;
  129. begin
  130. if p.typ=ait_instruction then
  131. begin
  132. case taicpu(p).opcode of
  133. A_MUL:
  134. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  135. A_UMULL,
  136. A_UMLAL,
  137. A_SMULL,
  138. A_SMLAL:
  139. begin
  140. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  141. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  142. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  143. end;
  144. A_LDRB,
  145. A_STRB,
  146. A_STR,
  147. A_LDR,
  148. A_LDRH,
  149. A_STRH:
  150. { don't mix up the framepointer and stackpointer with pre/post indexed operations }
  151. if (taicpu(p).oper[1]^.typ=top_ref) and
  152. (taicpu(p).oper[1]^.ref^.addressmode in [AM_PREINDEXED,AM_POSTINDEXED]) then
  153. begin
  154. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(current_procinfo.framepointer));
  155. { FIXME: temp variable r is needed here to avoid Internal error 20060521 }
  156. { while compiling the compiler. }
  157. r:=NR_STACK_POINTER_REG;
  158. if current_procinfo.framepointer<>r then
  159. add_edge(getsupreg(taicpu(p).oper[1]^.ref^.base),getsupreg(r));
  160. end;
  161. end;
  162. end;
  163. end;
  164. end.