rgcpu.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. {
  2. Copyright (c) 1998-2009 by Florian Klaempfl and David Zhang
  3. This unit implements the register allocator for MIPLEL
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit rgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. aasmbase,aasmcpu,aasmtai,aasmdata,
  22. cgbase,cgutils,
  23. cpubase,
  24. rgobj;
  25. type
  26. trgcpu=class(trgobj)
  27. procedure add_constraints(reg:tregister);override;
  28. function get_spill_subreg(r : tregister) : tsubregister;override;
  29. procedure do_spill_read(list:tasmlist;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  30. procedure do_spill_written(list:tasmlist;pos:tai;const spilltemp:treference;tempreg:tregister);override;
  31. end;
  32. implementation
  33. uses
  34. globtype,
  35. verbose,cutils,
  36. 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_R1;
  58. while (i<=RS_R31) 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:tasmlist;pos:tai;const spilltemp:treference;tempreg:tregister);
  74. var
  75. helpins : tai;
  76. tmpref : treference;
  77. helplist : tasmlist;
  78. hreg : tregister;
  79. begin
  80. if abs(spilltemp.offset)>4095 then
  81. begin
  82. helplist:=tasmlist.create;
  83. if getregtype(tempreg)=R_INTREGISTER then
  84. hreg:=tempreg
  85. else
  86. hreg:=cg.getintregister(helplist,OS_ADDR);
  87. reference_reset(tmpref,sizeof(aint));
  88. tmpref.offset:=spilltemp.offset;
  89. tmpref.refaddr:=addr_high;
  90. helplist.concat(taicpu.op_reg_ref(A_LUI,hreg,tmpref));
  91. tmpref.refaddr:=addr_low;
  92. helplist.concat(taicpu.op_reg_reg_ref(A_ADDIU,hreg,hreg,tmpref));
  93. helplist.concat(taicpu.op_reg_reg_reg(A_ADDU,hreg,hreg,spilltemp.base));
  94. reference_reset_base(tmpref,hreg,0,sizeof(aint));
  95. helpins:=spilling_create_load(tmpref,tempreg);
  96. helplist.concat(helpins);
  97. list.insertlistafter(pos,helplist)
  98. end
  99. else
  100. inherited do_spill_read(list,pos,spilltemp,tempreg);
  101. end;
  102. procedure trgcpu.do_spill_written(list:tasmlist;pos:tai;const spilltemp:treference;tempreg:tregister);
  103. var
  104. helpins : tai;
  105. tmpref : treference;
  106. helplist : tasmlist;
  107. hreg : tregister;
  108. begin
  109. if abs(spilltemp.offset)>4095 then
  110. begin
  111. helplist:=tasmlist.create;
  112. if getregtype(tempreg)=R_INTREGISTER then
  113. hreg:=getregisterinline(helplist,[R_SUBWHOLE])
  114. else
  115. hreg:=cg.getintregister(helplist,OS_ADDR);
  116. reference_reset(tmpref,sizeof(aint));
  117. tmpref.offset:=spilltemp.offset;
  118. tmpref.refaddr:=addr_high;
  119. helplist.concat(taicpu.op_reg_ref(A_LUI,hreg,tmpref));
  120. tmpref.refaddr:=addr_low;
  121. helplist.concat(taicpu.op_reg_reg_ref(A_ADDIU,hreg,hreg,tmpref));
  122. helplist.concat(taicpu.op_reg_reg_reg(A_ADDU,hreg,hreg,spilltemp.base));
  123. reference_reset_base(tmpref,hreg,0,sizeof(aint));
  124. helpins:=spilling_create_store(tempreg,tmpref);
  125. helplist.concat(helpins);
  126. if getregtype(tempreg)=R_INTREGISTER then
  127. ungetregisterinline(helplist,hreg);
  128. list.insertlistafter(pos,helplist)
  129. end
  130. else
  131. inherited do_spill_written(list,pos,spilltemp,tempreg);
  132. end;
  133. end.