rgcpu.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. procedure saveusedintregisters(list:Taasmoutput;
  31. var saved:Tpushedsavedint;
  32. const s:Tsupregset);override;
  33. procedure saveusedotherregisters(list:Taasmoutput;
  34. var saved:Tpushedsavedother;
  35. const s:Tregisterset);override;
  36. procedure cleartempgen; override;
  37. private
  38. usedpararegs: Tsupregset;
  39. end;
  40. implementation
  41. uses
  42. cgobj, verbose;
  43. function trgcpu.getexplicitregisterint(list: taasmoutput; reg: Tnewregister): tregister;
  44. var r:Tregister;
  45. begin
  46. if ((reg shr 8) in [RS_R0,RS_R2..RS_R12]) 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. include(usedpararegs,reg shr 8);
  52. r.enum:=R_INTREGISTER;
  53. r.number:=reg;
  54. cg.a_reg_alloc(list,r);
  55. result := r;
  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,RS_R2..RS_R12]) 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. exclude(usedpararegs,reg.number shr 8);
  67. cg.a_reg_dealloc(list,reg);
  68. end
  69. else
  70. inherited ungetregisterint(list,reg);
  71. end;
  72. procedure trgcpu.saveusedintregisters(list:Taasmoutput;
  73. var saved:Tpushedsavedint;
  74. const s:Tsupregset);
  75. begin
  76. // saving/restoring is done by the callee (except for registers
  77. // which already contain parameters, but those aren't allocated
  78. // correctly yet)
  79. filldword(saved,sizeof(saved) div 4,reg_not_saved);
  80. end;
  81. procedure trgcpu.saveusedotherregisters(list:Taasmoutput;
  82. var saved:Tpushedsavedother;
  83. const s:Tregisterset);
  84. begin
  85. // saving/restoring is done by the callee (except for registers
  86. // which already contain parameters, but those aren't allocated
  87. // correctly yet)
  88. filldword(saved,sizeof(saved) div 4,reg_not_saved);
  89. end;
  90. procedure trgcpu.cleartempgen;
  91. begin
  92. inherited cleartempgen;
  93. usedpararegs := [];
  94. end;
  95. initialization
  96. rg := trgcpu.create(32); {PPC has 32 registers.}
  97. end.
  98. {
  99. $Log$
  100. Revision 1.8 2003-06-07 18:57:04 jonas
  101. + added freeintparaloc
  102. * ppc get/freeintparaloc now check whether the parameter regs are
  103. properly allocated/deallocated (and get an extra list para)
  104. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  105. * fixed lot of missing pi_do_call's
  106. Revision 1.7 2003/05/24 13:38:04 jonas
  107. * don't save callee-save registers in the caller as well (the ppc code
  108. that we generate is slow enough as it is without resorting to doing
  109. double work :)
  110. Revision 1.6 2003/04/22 10:09:35 daniel
  111. + Implemented the actual register allocator
  112. + Scratch registers unavailable when new register allocator used
  113. + maybe_save/maybe_restore unavailable when new register allocator used
  114. Revision 1.5 2003/02/19 22:00:16 daniel
  115. * Code generator converted to new register notation
  116. - Horribily outdated todo.txt removed
  117. Revision 1.4 2003/01/08 18:43:58 daniel
  118. * Tregister changed into a record
  119. Revision 1.3 2002/07/07 09:44:32 florian
  120. * powerpc target fixed, very simple units can be compiled
  121. Revision 1.2 2002/05/16 19:46:53 carl
  122. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  123. + try to fix temp allocation (still in ifdef)
  124. + generic constructor calls
  125. + start of tassembler / tmodulebase class cleanup
  126. Revision 1.1 2002/04/06 18:13:02 jonas
  127. * several powerpc-related additions and fixes
  128. }