rgcpu.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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,hreg,0);
  65. if spilltemp.index<>NR_NO then
  66. internalerror(200401263);
  67. helpins:=spilling_create_load(tmpref,tempreg);
  68. helplist.concat(helpins);
  69. if pos=nil then
  70. list.insertlistafter(list.first,helplist)
  71. else
  72. list.insertlistafter(pos.next,helplist);
  73. helplist.free;
  74. end
  75. else
  76. inherited do_spill_read(list,pos,spilltemp,tempreg);
  77. end;
  78. procedure trgcpu.do_spill_written(list:TAsmList;pos:tai;const spilltemp:treference;tempreg:tregister);
  79. var
  80. helpins: tai;
  81. tmpref : treference;
  82. helplist : TAsmList;
  83. l : tasmlabel;
  84. hreg : tregister;
  85. begin
  86. if abs(spilltemp.offset)>4095 then
  87. begin
  88. helplist:=TAsmList.create;
  89. reference_reset(tmpref);
  90. { create consts entry }
  91. current_asmdata.getjumplabel(l);
  92. cg.a_label(current_procinfo.aktlocaldata,l);
  93. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  94. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  95. { load consts entry }
  96. if getregtype(tempreg)=R_INTREGISTER then
  97. hreg:=getregisterinline(helplist,R_SUBWHOLE)
  98. else
  99. hreg:=cg.getintregister(helplist,OS_ADDR);
  100. tmpref.symbol:=l;
  101. tmpref.base:=NR_R15;
  102. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  103. if spilltemp.index<>NR_NO then
  104. internalerror(200401263);
  105. reference_reset_base(tmpref,hreg,0);
  106. helplist.concat(spilling_create_store(tempreg,tmpref));
  107. if getregtype(tempreg)=R_INTREGISTER then
  108. ungetregisterinline(helplist,hreg);
  109. list.insertlistafter(pos,helplist)
  110. end
  111. else
  112. inherited do_spill_written(list,pos,spilltemp,tempreg);
  113. end;
  114. procedure trgintcpu.add_cpu_interferences(p : tai);
  115. begin
  116. if p.typ=ait_instruction then
  117. begin
  118. case taicpu(p).opcode of
  119. A_MUL:
  120. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  121. A_UMULL,
  122. A_UMLAL,
  123. A_SMULL,
  124. A_SMLAL:
  125. begin
  126. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[1]^.reg));
  127. add_edge(getsupreg(taicpu(p).oper[1]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  128. add_edge(getsupreg(taicpu(p).oper[0]^.reg),getsupreg(taicpu(p).oper[2]^.reg));
  129. end;
  130. end;
  131. end;
  132. end;
  133. end.