rgcpu.pas 5.7 KB

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