rgcpu.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. $Id$
  3. Copyright (c) 1998-2003 by Florian Klaempfl
  4. This unit implements the arm specific class for the register
  5. allocator
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit rgcpu;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. aasmbase,aasmtai,aasmcpu,
  24. cgbase,cgutils,
  25. cpubase,
  26. rgobj;
  27. type
  28. trgcpu = class(trgobj)
  29. procedure do_spill_read(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  30. procedure do_spill_written(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  31. end;
  32. trgintcpu = class(trgcpu)
  33. procedure add_cpu_interferences(p : tai);override;
  34. end;
  35. implementation
  36. uses
  37. verbose, cutils,
  38. cgobj,
  39. procinfo;
  40. procedure trgcpu.do_spill_read(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  41. var
  42. helpins: tai;
  43. tmpref : treference;
  44. helplist : taasmoutput;
  45. l : tasmlabel;
  46. hreg : tregister;
  47. begin
  48. if abs(spilltemp.offset)>4095 then
  49. begin
  50. helplist:=taasmoutput.create;
  51. reference_reset(tmpref);
  52. { create consts entry }
  53. objectlibrary.getlabel(l);
  54. cg.a_label(current_procinfo.aktlocaldata,l);
  55. tmpref.symboldata:=current_procinfo.aktlocaldata.last;
  56. current_procinfo.aktlocaldata.concat(tai_const.Create_32bit(spilltemp.offset));
  57. { load consts entry }
  58. if getregtype(tempreg)=R_INTREGISTER then
  59. hreg:=getregisterinline(helplist,R_SUBWHOLE)
  60. else
  61. hreg:=cg.getintregister(helplist,OS_ADDR);
  62. tmpref.symbol:=l;
  63. tmpref.base:=NR_R15;
  64. helplist.concat(taicpu.op_reg_ref(A_LDR,hreg,tmpref));
  65. reference_reset_base(tmpref,hreg,0);
  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:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  80. var
  81. helpins: tai;
  82. tmpref : treference;
  83. helplist : taasmoutput;
  84. l : tasmlabel;
  85. hreg : tregister;
  86. begin
  87. if abs(spilltemp.offset)>4095 then
  88. begin
  89. helplist:=taasmoutput.create;
  90. reference_reset(tmpref);
  91. { create consts entry }
  92. objectlibrary.getlabel(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,hreg,0);
  107. helplist.concat(spilling_create_store(tempreg,tmpref));
  108. if getregtype(tempreg)=R_INTREGISTER then
  109. ungetregisterinline(helplist,hreg);
  110. list.insertlistafter(pos,helplist)
  111. end
  112. else
  113. inherited do_spill_written(list,pos,spilltemp,tempreg);
  114. end;
  115. procedure trgintcpu.add_cpu_interferences(p : tai);
  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. end;
  132. end;
  133. end;
  134. end.
  135. {
  136. $Log$
  137. Revision 1.17 2005-02-14 17:13:09 peter
  138. * truncate log
  139. Revision 1.16 2005/02/13 18:55:19 florian
  140. + overflow checking for the arm
  141. }