rgcpu.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the SPARC 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. unit rgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. aasmbase,aasmcpu,aasmtai,
  23. cgbase,
  24. cpubase,
  25. rgobj;
  26. type
  27. trgcpu=class(trgobj)
  28. procedure add_constraints(reg:tregister);override;
  29. function get_spill_subreg(r : tregister) : tsubregister;override;
  30. procedure do_spill_read(list:Taasmoutput;instr:taicpu;const spilltemp:treference;const tempreg:tregister);override;
  31. procedure do_spill_written(list:Taasmoutput;instr:taicpu;const spilltemp:treference;const tempreg:tregister);override;
  32. end;
  33. implementation
  34. uses
  35. verbose, cutils,
  36. cgutils,cgobj;
  37. procedure trgcpu.add_constraints(reg:tregister);
  38. var
  39. supreg,i : Tsuperregister;
  40. begin
  41. case getsubreg(reg) of
  42. { Let 64bit floats conflict with all odd float regs }
  43. R_SUBFD:
  44. begin
  45. supreg:=getsupreg(reg);
  46. i:=RS_F1;
  47. while (i<=RS_F31) do
  48. begin
  49. add_edge(supreg,i);
  50. inc(i,2);
  51. end;
  52. end;
  53. { Let 64bit ints conflict with all odd int regs }
  54. R_SUBQ:
  55. begin
  56. supreg:=getsupreg(reg);
  57. i:=RS_G1;
  58. while (i<=RS_I7) do
  59. begin
  60. add_edge(supreg,i);
  61. inc(i,2);
  62. end;
  63. end;
  64. end;
  65. end;
  66. function trgcpu.get_spill_subreg(r : tregister) : tsubregister;
  67. begin
  68. if getregtype(r)=R_FPUREGISTER then
  69. result:=getsubreg(r)
  70. else
  71. result:=defaultsub;
  72. end;
  73. procedure trgcpu.do_spill_read(list:Taasmoutput;instr:taicpu;const spilltemp:treference;const tempreg:tregister);
  74. var
  75. helpins : tai;
  76. tmpref : treference;
  77. helplist : taasmoutput;
  78. hreg : tregister;
  79. begin
  80. if abs(spilltemp.offset)>4095 then
  81. begin
  82. helplist:=taasmoutput.create;
  83. if getregtype(tempreg)=R_INTREGISTER then
  84. hreg:=tempreg
  85. else
  86. hreg:=cg.getintregister(helplist,OS_ADDR);
  87. reference_reset(tmpref);
  88. tmpref.offset:=spilltemp.offset;
  89. tmpref.refaddr:=addr_hi;
  90. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,hreg));
  91. tmpref.refaddr:=addr_lo;
  92. helplist.concat(taicpu.op_reg_ref_reg(A_OR,hreg,tmpref,hreg));
  93. reference_reset_base(tmpref,hreg,0);
  94. helpins:=spilling_create_load(spilltemp,tempreg);
  95. helplist.concat(helpins);
  96. list.insertlistbefore(instr,helplist)
  97. end
  98. else
  99. inherited do_spill_read(list,instr,spilltemp,tempreg);
  100. end;
  101. procedure trgcpu.do_spill_written(list:Taasmoutput;instr:taicpu;const spilltemp:treference;const tempreg:tregister);
  102. var
  103. helpins : tai;
  104. tmpref : treference;
  105. helplist : taasmoutput;
  106. hreg : tregister;
  107. begin
  108. if abs(spilltemp.offset)>4095 then
  109. begin
  110. helplist:=taasmoutput.create;
  111. if getregtype(tempreg)=R_INTREGISTER then
  112. getregisterinline(helplist,tai(helplist.first),R_SUBWHOLE,hreg)
  113. else
  114. hreg:=cg.getintregister(helplist,OS_ADDR);
  115. reference_reset(tmpref);
  116. tmpref.offset:=spilltemp.offset;
  117. tmpref.refaddr:=addr_hi;
  118. helplist.concat(taicpu.op_ref_reg(A_SETHI,tmpref,hreg));
  119. tmpref.refaddr:=addr_lo;
  120. helplist.concat(taicpu.op_reg_ref_reg(A_OR,hreg,tmpref,hreg));
  121. reference_reset_base(tmpref,hreg,0);
  122. helpins:=spilling_create_store(tempreg,spilltemp);
  123. helplist.concat(helpins);
  124. if getregtype(tempreg)=R_INTREGISTER then
  125. ungetregisterinline(helplist,tai(helplist.last),hreg);
  126. list.insertlistafter(instr,helplist)
  127. end
  128. else
  129. inherited do_spill_written(list,instr,spilltemp,tempreg);
  130. end;
  131. end.
  132. {
  133. $Log$
  134. Revision 1.28 2004-10-04 20:46:22 peter
  135. * spilling code rewritten for x86. It now used the generic
  136. spilling routines. Special x86 optimization still needs
  137. to be added.
  138. * Spilling fixed when both operands needed to be spilled
  139. * Cleanup of spilling routine, do_spill_readwritten removed
  140. Revision 1.27 2004/10/01 17:33:47 peter
  141. * indents
  142. Revision 1.26 2004/09/28 20:19:36 peter
  143. * fixed crash
  144. Revision 1.25 2004/09/27 21:23:26 peter
  145. * fixed spilling code
  146. Revision 1.24 2004/08/24 21:02:33 florian
  147. * fixed longbool(<int64>) on sparc
  148. Revision 1.23 2004/06/20 08:55:32 florian
  149. * logs truncated
  150. Revision 1.22 2004/06/20 08:47:33 florian
  151. * spilling of doubles on sparc fixed
  152. Revision 1.21 2004/06/16 20:07:11 florian
  153. * dwarf branch merged
  154. Revision 1.20.2.4 2004/06/13 20:38:38 florian
  155. * fixed floating point register spilling on sparc
  156. Revision 1.20.2.3 2004/06/13 10:51:17 florian
  157. * fixed several register allocator problems (sparc/arm)
  158. Revision 1.20.2.2 2004/06/03 19:23:41 florian
  159. * fixed some spilling issues
  160. }