rgcpu.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the powerpc 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,
  24. cpubase,
  25. rgobj;
  26. type
  27. trgcpu = class(trgobj)
  28. function getexplicitregisterint(list: taasmoutput; reg: Tnewregister): tregister; override;
  29. procedure ungetregisterint(list: taasmoutput; reg: tregister); override;
  30. function getexplicitregisterfpu(list : taasmoutput; r : Toldregister) : tregister;override;
  31. procedure ungetregisterfpu(list: taasmoutput; r : tregister);override;
  32. procedure saveusedintregisters(list:Taasmoutput;
  33. var saved:Tpushedsavedint;
  34. const s:Tsupregset);override;
  35. procedure saveusedotherregisters(list:Taasmoutput;
  36. var saved:Tpushedsavedother;
  37. const s:Tregisterset);override;
  38. procedure cleartempgen; override;
  39. private
  40. usedpararegs: Tsupregset;
  41. usedparafpuregs: tregisterset;
  42. end;
  43. implementation
  44. uses
  45. cgobj, verbose;
  46. function trgcpu.getexplicitregisterint(list: taasmoutput; reg: Tnewregister): tregister;
  47. begin
  48. if ((reg shr 8) in [RS_R0,RS_R2..RS_R12]) and
  49. not((reg shr 8) in is_reg_var_int) then
  50. begin
  51. if (reg shr 8) in usedpararegs then
  52. internalerror(2003060701);
  53. include(usedpararegs,reg shr 8);
  54. result.enum:=R_INTREGISTER;
  55. result.number:=reg;
  56. cg.a_reg_alloc(list,result);
  57. end
  58. else result := inherited getexplicitregisterint(list,reg);
  59. end;
  60. procedure trgcpu.ungetregisterint(list: taasmoutput; reg: tregister);
  61. begin
  62. if ((reg.number shr 8) in [RS_R0,RS_R2..RS_R12]) and
  63. not((reg.number shr 8) in is_reg_var_int) then
  64. begin
  65. if not((reg.number shr 8) in usedpararegs) then
  66. internalerror(2003060702);
  67. exclude(usedpararegs,reg.number shr 8);
  68. cg.a_reg_dealloc(list,reg);
  69. end
  70. else
  71. inherited ungetregisterint(list,reg);
  72. end;
  73. function trgcpu.getexplicitregisterfpu(list : taasmoutput; r : Toldregister) : tregister;
  74. begin
  75. if (r in [R_F1..R_F13]) and
  76. not is_reg_var_other[r] then
  77. begin
  78. if r in usedparafpuregs then
  79. internalerror(2003060902);
  80. include(usedparafpuregs,r);
  81. result.enum := r;
  82. cg.a_reg_alloc(list,result);
  83. end
  84. else
  85. result := inherited getexplicitregisterfpu(list,r);
  86. end;
  87. procedure trgcpu.ungetregisterfpu(list: taasmoutput; r : tregister);
  88. begin
  89. if (r.enum in [R_F1..R_F13]) and
  90. not is_reg_var_other[r.enum] then
  91. begin
  92. if not(r.enum in usedparafpuregs) then
  93. internalerror(2003060903);
  94. exclude(usedparafpuregs,r.enum);
  95. cg.a_reg_dealloc(list,r);
  96. end
  97. else
  98. inherited ungetregisterfpu(list,r);
  99. end;
  100. procedure trgcpu.saveusedintregisters(list:Taasmoutput;
  101. var saved:Tpushedsavedint;
  102. const s:Tsupregset);
  103. begin
  104. // saving/restoring is done by the callee (except for registers
  105. // which already contain parameters, but those aren't allocated
  106. // correctly yet)
  107. filldword(saved,sizeof(saved) div 4,reg_not_saved);
  108. end;
  109. procedure trgcpu.saveusedotherregisters(list:Taasmoutput;
  110. var saved:Tpushedsavedother;
  111. const s:Tregisterset);
  112. begin
  113. // saving/restoring is done by the callee (except for registers
  114. // which already contain parameters, but those aren't allocated
  115. // correctly yet)
  116. filldword(saved,sizeof(saved) div 4,reg_not_saved);
  117. end;
  118. procedure trgcpu.cleartempgen;
  119. begin
  120. inherited cleartempgen;
  121. usedpararegs := [];
  122. usedparafpuregs := [];
  123. end;
  124. initialization
  125. rg := trgcpu.create(32); {PPC has 32 registers.}
  126. end.
  127. {
  128. $Log$
  129. Revision 1.9 2003-06-09 14:54:26 jonas
  130. * (de)allocation of registers for parameters is now performed properly
  131. (and checked on the ppc)
  132. - removed obsolete allocation of all parameter registers at the start
  133. of a procedure (and deallocation at the end)
  134. Revision 1.8 2003/06/07 18:57:04 jonas
  135. + added freeintparaloc
  136. * ppc get/freeintparaloc now check whether the parameter regs are
  137. properly allocated/deallocated (and get an extra list para)
  138. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  139. * fixed lot of missing pi_do_call's
  140. Revision 1.7 2003/05/24 13:38:04 jonas
  141. * don't save callee-save registers in the caller as well (the ppc code
  142. that we generate is slow enough as it is without resorting to doing
  143. double work :)
  144. Revision 1.6 2003/04/22 10:09:35 daniel
  145. + Implemented the actual register allocator
  146. + Scratch registers unavailable when new register allocator used
  147. + maybe_save/maybe_restore unavailable when new register allocator used
  148. Revision 1.5 2003/02/19 22:00:16 daniel
  149. * Code generator converted to new register notation
  150. - Horribily outdated todo.txt removed
  151. Revision 1.4 2003/01/08 18:43:58 daniel
  152. * Tregister changed into a record
  153. Revision 1.3 2002/07/07 09:44:32 florian
  154. * powerpc target fixed, very simple units can be compiled
  155. Revision 1.2 2002/05/16 19:46:53 carl
  156. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  157. + try to fix temp allocation (still in ifdef)
  158. + generic constructor calls
  159. + start of tassembler / tmodulebase class cleanup
  160. Revision 1.1 2002/04/06 18:13:02 jonas
  161. * several powerpc-related additions and fixes
  162. }