rgcpu.pas 7.7 KB

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