rgcpu.pas 7.1 KB

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