rgcpu.pas 6.9 KB

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