rgcpu.pas 10 KB

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