rgcpu.pas 6.1 KB

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