rgcpu.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {
  2. $Id$
  3. Copyright (c) 1998-2003 by Florian Klaempfl
  4. This unit implements the arm 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.1 2003-08-16 13:23:01 florian
  137. * several arm related stuff fixed
  138. }