rgcpu.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the i386 specific class for the register
  4. allocator
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit rgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cpubase,
  23. cpuinfo,
  24. aasmbase,aasmtai,aasmsym,aasmdata,aasmcpu,
  25. cclasses,globtype,cgbase,cgutils,rgobj,rgx86;
  26. type
  27. { trgcpu }
  28. trgcpu = class(trgx86)
  29. function do_spill_replace(list:TAsmList;instr:tai_cpu_abstract_sym;orgreg:tsuperregister;const spilltemp:treference):boolean;override;
  30. procedure add_constraints(reg:Tregister);override;
  31. end;
  32. trgintcpu = class(trgcpu)
  33. procedure add_cpu_interferences(p : tai);override;
  34. end;
  35. implementation
  36. uses
  37. systems,
  38. verbose;
  39. const
  40. { This value is used in tsaved. If the array value is equal
  41. to this, then this means that this register is not used.}
  42. reg_not_saved = $7fffffff;
  43. {************************************************************************
  44. trgcpu
  45. *************************************************************************}
  46. function trgcpu.do_spill_replace(list:TAsmList;instr:tai_cpu_abstract_sym;orgreg:tsuperregister;const spilltemp:treference): boolean;
  47. var
  48. spilltemp2: treference;
  49. begin
  50. spilltemp2:=spilltemp;
  51. if spilltemp2.segment=NR_SS then
  52. spilltemp2.segment:=NR_NO;
  53. Result:=inherited do_spill_replace(list, instr, orgreg, spilltemp2);
  54. end;
  55. procedure trgcpu.add_constraints(reg:Tregister);
  56. var
  57. supreg : tsuperregister;
  58. begin
  59. if getsubreg(reg) in [R_SUBL,R_SUBH] then
  60. begin
  61. { Some registers have no 8-bit subregister }
  62. supreg:=getsupreg(reg);
  63. add_edge(supreg,RS_SI);
  64. add_edge(supreg,RS_DI);
  65. add_edge(supreg,RS_BP);
  66. end;
  67. end;
  68. procedure trgintcpu.add_cpu_interferences(p : tai);
  69. var
  70. href : treference;
  71. i : integer;
  72. begin
  73. if p.typ=ait_instruction then
  74. begin
  75. for i:=0 to taicpu(p).ops-1 do
  76. begin
  77. if taicpu(p).oper[i]^.typ=top_ref then
  78. begin
  79. href:=taicpu(p).oper[i]^.ref^;
  80. { in case there's exactly one register used, we can treat it
  81. as either base or index and choose it from the larger set
  82. of registers [BX, BP, SI, DI] }
  83. if (href.base<>NR_NO) xor (href.index<>NR_NO) then
  84. begin
  85. if (href.base<>NR_NO) and (getsupreg(href.base)>=first_int_imreg) then
  86. begin
  87. add_edge(getsupreg(href.base),RS_AX);
  88. add_edge(getsupreg(href.base),RS_CX);
  89. add_edge(getsupreg(href.base),RS_DX);
  90. end;
  91. if (href.index<>NR_NO) and (getsupreg(href.index)>=first_int_imreg) then
  92. begin
  93. add_edge(getsupreg(href.index),RS_AX);
  94. add_edge(getsupreg(href.index),RS_CX);
  95. add_edge(getsupreg(href.index),RS_DX);
  96. end;
  97. end
  98. else
  99. begin
  100. { base is chosen from the set [BX, BP] }
  101. if (href.base<>NR_NO) and (getsupreg(href.base)>=first_int_imreg) then
  102. begin
  103. add_edge(getsupreg(href.base),RS_AX);
  104. add_edge(getsupreg(href.base),RS_CX);
  105. add_edge(getsupreg(href.base),RS_DX);
  106. add_edge(getsupreg(href.base),RS_SI);
  107. add_edge(getsupreg(href.base),RS_DI);
  108. end;
  109. { index is chosen from the set [SI, DI] }
  110. if (href.index<>NR_NO) and (getsupreg(href.index)>=first_int_imreg) then
  111. begin
  112. add_edge(getsupreg(href.index),RS_AX);
  113. add_edge(getsupreg(href.index),RS_BX);
  114. add_edge(getsupreg(href.index),RS_CX);
  115. add_edge(getsupreg(href.index),RS_DX);
  116. add_edge(getsupreg(href.index),RS_BP);
  117. end;
  118. end;
  119. end;
  120. end;
  121. end;
  122. end;
  123. end.