rgcpu.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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,aasmdata,
  25. cclasses,globtype,cgbase,rgobj,rgx86;
  26. type
  27. trgcpu = class(trgx86)
  28. procedure add_constraints(reg:Tregister);override;
  29. end;
  30. trgintcpu = class(trgcpu)
  31. procedure add_cpu_interferences(p : tai);override;
  32. end;
  33. implementation
  34. uses
  35. systems,
  36. verbose,
  37. aasmcpu,
  38. cgutils;
  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. procedure trgcpu.add_constraints(reg:Tregister);
  47. var
  48. supreg : tsuperregister;
  49. begin
  50. if getsubreg(reg) in [R_SUBL,R_SUBH] then
  51. begin
  52. { Some registers have no 8-bit subregister }
  53. supreg:=getsupreg(reg);
  54. add_edge(supreg,RS_SI);
  55. add_edge(supreg,RS_DI);
  56. add_edge(supreg,RS_BP);
  57. end;
  58. end;
  59. procedure trgintcpu.add_cpu_interferences(p : tai);
  60. var
  61. href : treference;
  62. i : integer;
  63. begin
  64. if p.typ=ait_instruction then
  65. begin
  66. for i:=0 to taicpu(p).ops-1 do
  67. begin
  68. if taicpu(p).oper[i]^.typ=top_ref then
  69. begin
  70. href:=taicpu(p).oper[i]^.ref^;
  71. { in case there's exactly one register used, we can treat it
  72. as either base or index and choose it from the larger set
  73. of registers [BX, BP, SI, DI] }
  74. if (href.base<>NR_NO) xor (href.index<>NR_NO) then
  75. begin
  76. if (href.base<>NR_NO) and (getsupreg(href.base)>=first_int_imreg) then
  77. begin
  78. add_edge(getsupreg(href.base),RS_AX);
  79. add_edge(getsupreg(href.base),RS_CX);
  80. add_edge(getsupreg(href.base),RS_DX);
  81. end;
  82. if (href.index<>NR_NO) and (getsupreg(href.index)>=first_int_imreg) then
  83. begin
  84. add_edge(getsupreg(href.index),RS_AX);
  85. add_edge(getsupreg(href.index),RS_CX);
  86. add_edge(getsupreg(href.index),RS_DX);
  87. end;
  88. end
  89. else
  90. begin
  91. { base is chosen from the set [BX, BP] }
  92. if (href.base<>NR_NO) and (getsupreg(href.base)>=first_int_imreg) then
  93. begin
  94. add_edge(getsupreg(href.base),RS_AX);
  95. add_edge(getsupreg(href.base),RS_CX);
  96. add_edge(getsupreg(href.base),RS_DX);
  97. add_edge(getsupreg(href.base),RS_SI);
  98. add_edge(getsupreg(href.base),RS_DI);
  99. end;
  100. { index is chosen from the set [SI, DI] }
  101. if (href.index<>NR_NO) and (getsupreg(href.index)>=first_int_imreg) then
  102. begin
  103. add_edge(getsupreg(href.index),RS_AX);
  104. add_edge(getsupreg(href.index),RS_BX);
  105. add_edge(getsupreg(href.index),RS_CX);
  106. add_edge(getsupreg(href.index),RS_DX);
  107. add_edge(getsupreg(href.index),RS_BP);
  108. end;
  109. end;
  110. end;
  111. end;
  112. end;
  113. end;
  114. end.