rgcpu.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the i386 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. cpubase,
  24. cpuinfo,
  25. aasmbase,aasmtai,
  26. cclasses,globtype,cgbase,rgobj,rgx86;
  27. type
  28. trgcpu = class(trgobj)
  29. procedure add_constraints(reg:Tregister);override;
  30. end;
  31. implementation
  32. uses
  33. systems,
  34. verbose;
  35. const
  36. { This value is used in tsaved. If the array value is equal
  37. to this, then this means that this register is not used.}
  38. reg_not_saved = $7fffffff;
  39. {************************************************************************
  40. trgcpu
  41. *************************************************************************}
  42. procedure trgcpu.add_constraints(reg:Tregister);
  43. var
  44. supreg : tsuperregister;
  45. begin
  46. if getsubreg(reg) in [R_SUBL,R_SUBH] then
  47. begin
  48. supreg:=getsupreg(reg);
  49. {These registers have no 8-bit subregister, so add interferences.}
  50. add_edge(supreg,RS_ESI);
  51. add_edge(supreg,RS_EDI);
  52. add_edge(supreg,RS_EBP);
  53. end;
  54. end;
  55. end.
  56. {
  57. $Log$
  58. Revision 1.41 2003-12-24 00:10:02 florian
  59. - delete parameter in cg64 methods removed
  60. Revision 1.40 2003/10/17 15:08:34 peter
  61. * commented out more obsolete constants
  62. Revision 1.39 2003/10/17 14:38:32 peter
  63. * 64k registers supported
  64. * fixed some memory leaks
  65. Revision 1.38 2003/10/10 17:48:14 peter
  66. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  67. * tregisteralloctor renamed to trgobj
  68. * removed rgobj from a lot of units
  69. * moved location_* and reference_* to cgobj
  70. * first things for mmx register allocation
  71. Revision 1.37 2003/10/09 21:31:37 daniel
  72. * Register allocator splitted, ans abstract now
  73. Revision 1.36 2003/10/01 20:34:49 peter
  74. * procinfo unit contains tprocinfo
  75. * cginfo renamed to cgbase
  76. * moved cgmessage to verbose
  77. * fixed ppc and sparc compiles
  78. Revision 1.35 2003/09/11 11:55:00 florian
  79. * improved arm code generation
  80. * move some protected and private field around
  81. * the temp. register for register parameters/arguments are now released
  82. before the move to the parameter register is done. This improves
  83. the code in a lot of cases.
  84. Revision 1.34 2003/09/09 20:59:27 daniel
  85. * Adding register allocation order
  86. Revision 1.33 2003/09/07 22:09:35 peter
  87. * preparations for different default calling conventions
  88. * various RA fixes
  89. Revision 1.32 2003/09/03 15:55:01 peter
  90. * NEWRA branch merged
  91. Revision 1.31.2.3 2003/08/31 13:50:16 daniel
  92. * Remove sorting and use pregenerated indexes
  93. * Some work on making things compile
  94. Revision 1.31.2.2 2003/08/28 18:35:08 peter
  95. * tregister changed to cardinal
  96. Revision 1.31.2.1 2003/08/27 19:55:54 peter
  97. * first tregister patch
  98. Revision 1.31 2003/08/20 09:07:00 daniel
  99. * New register coding now mandatory, some more convert_registers calls
  100. removed.
  101. Revision 1.30 2003/08/17 08:48:02 daniel
  102. * Another register allocator bug fixed.
  103. * cpu_registers set to 6 for i386
  104. Revision 1.29 2003/06/17 16:51:30 peter
  105. * cycle fixes
  106. Revision 1.28 2003/06/17 16:34:44 jonas
  107. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  108. * renamed all_intregisters to volatile_intregisters and made it
  109. processor dependent
  110. Revision 1.27 2003/06/13 21:19:31 peter
  111. * current_procdef removed, use current_procinfo.procdef instead
  112. Revision 1.26 2003/06/12 21:12:20 peter
  113. * size para for ungetregisterfpu
  114. Revision 1.25 2003/06/03 21:11:09 peter
  115. * cg.a_load_* get a from and to size specifier
  116. * makeregsize only accepts newregister
  117. * i386 uses generic tcgnotnode,tcgunaryminus
  118. Revision 1.24 2003/06/03 13:01:59 daniel
  119. * Register allocator finished
  120. Revision 1.23 2003/06/01 21:38:06 peter
  121. * getregisterfpu size parameter added
  122. * op_const_reg size parameter added
  123. * sparc updates
  124. Revision 1.22 2003/05/16 14:33:31 peter
  125. * regvar fixes
  126. Revision 1.21 2003/04/25 08:25:26 daniel
  127. * Ifdefs around a lot of calls to cleartempgen
  128. * Fixed registers that are allocated but not freed in several nodes
  129. * Tweak to register allocator to cause less spills
  130. * 8-bit registers now interfere with esi,edi and ebp
  131. Compiler can now compile rtl successfully when using new register
  132. allocator
  133. Revision 1.20 2003/04/23 14:42:08 daniel
  134. * Further register allocator work. Compiler now smaller with new
  135. allocator than without.
  136. * Somebody forgot to adjust ppu version number
  137. Revision 1.19 2003/04/22 10:09:35 daniel
  138. + Implemented the actual register allocator
  139. + Scratch registers unavailable when new register allocator used
  140. + maybe_save/maybe_restore unavailable when new register allocator used
  141. Revision 1.18 2003/04/21 19:16:50 peter
  142. * count address regs separate
  143. Revision 1.17 2003/03/28 19:16:57 peter
  144. * generic constructor working for i386
  145. * remove fixed self register
  146. * esi added as address register for i386
  147. Revision 1.16 2003/03/17 15:52:57 peter
  148. * SUPPORT_MMX define compile fix
  149. Revision 1.15 2003/03/08 13:59:17 daniel
  150. * Work to handle new register notation in ag386nsm
  151. + Added newra version of Ti386moddivnode
  152. Revision 1.14 2003/03/08 08:59:07 daniel
  153. + $define newra will enable new register allocator
  154. + getregisterint will return imaginary registers with $newra
  155. + -sr switch added, will skip register allocation so you can see
  156. the direct output of the code generator before register allocation
  157. Revision 1.13 2003/03/07 21:57:53 daniel
  158. * Improved getregisterint
  159. Revision 1.12 2003/02/19 22:00:16 daniel
  160. * Code generator converted to new register notation
  161. - Horribily outdated todo.txt removed
  162. Revision 1.11 2003/01/08 18:43:57 daniel
  163. * Tregister changed into a record
  164. Revision 1.10 2002/10/05 12:43:29 carl
  165. * fixes for Delphi 6 compilation
  166. (warning : Some features do not work under Delphi)
  167. Revision 1.9 2002/08/17 09:23:48 florian
  168. * first part of procinfo rewrite
  169. Revision 1.8 2002/07/01 18:46:34 peter
  170. * internal linker
  171. * reorganized aasm layer
  172. Revision 1.7 2002/05/16 19:46:52 carl
  173. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  174. + try to fix temp allocation (still in ifdef)
  175. + generic constructor calls
  176. + start of tassembler / tmodulebase class cleanup
  177. Revision 1.6 2002/05/12 16:53:18 peter
  178. * moved entry and exitcode to ncgutil and cgobj
  179. * foreach gets extra argument for passing local data to the
  180. iterator function
  181. * -CR checks also class typecasts at runtime by changing them
  182. into as
  183. * fixed compiler to cycle with the -CR option
  184. * fixed stabs with elf writer, finally the global variables can
  185. be watched
  186. * removed a lot of routines from cga unit and replaced them by
  187. calls to cgobj
  188. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  189. u32bit then the other is typecasted also to u32bit without giving
  190. a rangecheck warning/error.
  191. * fixed pascal calling method with reversing also the high tree in
  192. the parast, detected by tcalcst3 test
  193. Revision 1.5 2002/04/21 15:43:32 carl
  194. * changeregsize -> rg.makeregsize
  195. * changeregsize moved from cpubase to here
  196. Revision 1.4 2002/04/15 19:44:22 peter
  197. * fixed stackcheck that would be called recursively when a stack
  198. error was found
  199. * generic changeregsize(reg,size) for i386 register resizing
  200. * removed some more routines from cga unit
  201. * fixed returnvalue handling
  202. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  203. Revision 1.3 2002/04/04 19:06:13 peter
  204. * removed unused units
  205. * use tlocation.size in cg.a_*loc*() routines
  206. Revision 1.2 2002/04/02 17:11:39 peter
  207. * tlocation,treference update
  208. * LOC_CONSTANT added for better constant handling
  209. * secondadd splitted in multiple routines
  210. * location_force_reg added for loading a location to a register
  211. of a specified size
  212. * secondassignment parses now first the right and then the left node
  213. (this is compatible with Kylix). This saves a lot of push/pop especially
  214. with string operations
  215. * adapted some routines to use the new cg methods
  216. Revision 1.1 2002/03/31 20:26:40 jonas
  217. + a_loadfpu_* and a_loadmm_* methods in tcg
  218. * register allocation is now handled by a class and is mostly processor
  219. independent (+rgobj.pas and i386/rgcpu.pas)
  220. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  221. * some small improvements and fixes to the optimizer
  222. * some register allocation fixes
  223. * some fpuvaroffset fixes in the unary minus node
  224. * push/popusedregisters is now called rg.save/restoreusedregisters and
  225. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  226. also better optimizable)
  227. * fixed and optimized register saving/restoring for new/dispose nodes
  228. * LOC_FPU locations now also require their "register" field to be set to
  229. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  230. - list field removed of the tnode class because it's not used currently
  231. and can cause hard-to-find bugs
  232. }