rgcpu.pas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. {
  30. function getexplicitregisterint(list: taasmoutput; reg: Tnewregister): tregister; override;
  31. procedure ungetregisterint(list: taasmoutput; reg: tregister); override;
  32. function getexplicitregisterfpu(list : taasmoutput; r : Toldregister) : tregister;override;
  33. procedure ungetregisterfpu(list: taasmoutput; r : tregister; size:TCGsize);override;
  34. procedure cleartempgen; override;
  35. private
  36. usedpararegs: Tsupregset;
  37. usedparafpuregs: tregisterset;
  38. }
  39. end;
  40. implementation
  41. uses
  42. cgobj, verbose, cutils;
  43. (*
  44. function trgcpu.getexplicitregisterint(list: taasmoutput; reg: Tnewregister): tregister;
  45. begin
  46. if ((reg shr 8) in [RS_R0]) and
  47. not((reg shr 8) in is_reg_var_int) then
  48. begin
  49. if (reg shr 8) in usedpararegs then
  50. internalerror(2003060701);
  51. { comment(v_warning,'Double allocation of register '+tostr((reg shr 8)-1));}
  52. include(usedpararegs,reg shr 8);
  53. result.enum:=R_INTREGISTER;
  54. result.number:=reg;
  55. cg.a_reg_alloc(list,result);
  56. end
  57. else result := inherited getexplicitregisterint(list,reg);
  58. end;
  59. procedure trgcpu.ungetregisterint(list: taasmoutput; reg: tregister);
  60. begin
  61. if ((reg.number shr 8) in [RS_R0]) and
  62. not((reg.number shr 8) in is_reg_var_int) then
  63. begin
  64. if not((reg.number shr 8) in usedpararegs) then
  65. internalerror(2003060702);
  66. { comment(v_warning,'Double free of register '+tostr((reg.number shr 8)-1));}
  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; size:TCGsize);
  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,size);
  99. end;
  100. procedure trgcpu.cleartempgen;
  101. begin
  102. inherited cleartempgen;
  103. usedpararegs := [];
  104. usedparafpuregs := [];
  105. end;
  106. *)
  107. initialization
  108. rg := trgcpu.create(last_int_supreg-first_int_supreg+1);
  109. end.
  110. {
  111. $Log$
  112. Revision 1.14 2003-09-03 19:35:24 peter
  113. * powerpc compiles again
  114. Revision 1.13 2003/07/06 15:27:44 jonas
  115. * make sure all registers except r0 are handled by the register
  116. allocator for -dnewra
  117. Revision 1.12 2003/06/17 16:34:44 jonas
  118. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  119. * renamed all_intregisters to volatile_intregisters and made it
  120. processor dependent
  121. Revision 1.11 2003/06/14 22:32:43 jonas
  122. * ppc compiles with -dnewra, haven't tried to compile anything with it
  123. yet though
  124. Revision 1.10 2003/06/12 22:09:54 jonas
  125. * tcginnode.pass_2 doesn't call a helper anymore in any case
  126. * fixed ungetregisterfpu compilation problems
  127. Revision 1.9 2003/06/09 14:54:26 jonas
  128. * (de)allocation of registers for parameters is now performed properly
  129. (and checked on the ppc)
  130. - removed obsolete allocation of all parameter registers at the start
  131. of a procedure (and deallocation at the end)
  132. Revision 1.8 2003/06/07 18:57:04 jonas
  133. + added freeintparaloc
  134. * ppc get/freeintparaloc now check whether the parameter regs are
  135. properly allocated/deallocated (and get an extra list para)
  136. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  137. * fixed lot of missing pi_do_call's
  138. Revision 1.7 2003/05/24 13:38:04 jonas
  139. * don't save callee-save registers in the caller as well (the ppc code
  140. that we generate is slow enough as it is without resorting to doing
  141. double work :)
  142. Revision 1.6 2003/04/22 10:09:35 daniel
  143. + Implemented the actual register allocator
  144. + Scratch registers unavailable when new register allocator used
  145. + maybe_save/maybe_restore unavailable when new register allocator used
  146. Revision 1.5 2003/02/19 22:00:16 daniel
  147. * Code generator converted to new register notation
  148. - Horribily outdated todo.txt removed
  149. Revision 1.4 2003/01/08 18:43:58 daniel
  150. * Tregister changed into a record
  151. Revision 1.3 2002/07/07 09:44:32 florian
  152. * powerpc target fixed, very simple units can be compiled
  153. Revision 1.2 2002/05/16 19:46:53 carl
  154. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  155. + try to fix temp allocation (still in ifdef)
  156. + generic constructor calls
  157. + start of tassembler / tmodulebase class cleanup
  158. Revision 1.1 2002/04/06 18:13:02 jonas
  159. * several powerpc-related additions and fixes
  160. }