rgobj.pas 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the base class for the register 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. {$i fpcdefs.inc}
  19. {# @abstract(Abstract register allocator unit)
  20. This unit contains services to allocate, free
  21. references and registers which are used by
  22. the code generator.
  23. }
  24. {*******************************************************************************
  25. (applies to new register allocator)
  26. Register allocator introduction.
  27. Free Pascal uses a Chaitin style register allocator. We use a variant similair
  28. to the one described in the book "Modern compiler implementation in C" by
  29. Andrew W. Appel., published by Cambridge University Press.
  30. The register allocator that is described by Appel uses a much improved way
  31. of register coalescing, called "iterated register coalescing". Instead
  32. of doing coalescing as a prepass to the register allocation, the coalescing
  33. is done inside the register allocator. This has the advantage that the
  34. register allocator can coalesce very aggresively without introducing spills.
  35. Reading this book is recommended for a complete understanding. Here is a small
  36. introduction.
  37. The code generator thinks it has an infinite amount of registers. Our processor
  38. has a limited amount of registers. Therefore we must reduce the amount of
  39. registers until there are less enough to fit into the processors registers.
  40. Registers can interfere or not interfere. If two imaginary registers interfere
  41. they cannot be placed into the same psysical register. Reduction of registers
  42. is done by:
  43. - "coalescing" Two registers that do not interfere are combined
  44. into one register.
  45. - "spilling" A register is changed into a memory location and the generated
  46. code is modified to use the memory location instead of the register.
  47. Register allocation is a graph colouring problem. Each register is a colour, and
  48. if two registers interfere there is a connection between them in the graph.
  49. In addition to the imaginary registers in the code generator, the psysical
  50. CPU registers are also present in this graph. This allows us to make
  51. interferences between imaginary registers and cpu registers. This is very
  52. usefull for describing archtectural constraints, like for example that
  53. the div instruction modifies edx, so variables that are in use at that time
  54. cannot be stored into edx. This can be modelled by making edx interfere
  55. with those variables.
  56. Graph colouring is an NP complete problem. Therefore we use an approximation
  57. that pushes registers to colour on to a stack. This is done in the "simplify"
  58. procedure.
  59. The register allocator first checks which registers are a candidate for
  60. coalescing.
  61. *******************************************************************************}
  62. unit rgobj;
  63. interface
  64. uses
  65. cutils, cpubase,
  66. cpuinfo,
  67. aasmbase,aasmtai,aasmcpu,
  68. cclasses,globtype,cginfo,cgbase,node
  69. {$ifdef delphi}
  70. ,dmisc
  71. {$endif}
  72. ;
  73. const
  74. ALL_OTHERREGISTERS=[low(tregisterindex)..high(tregisterindex)];
  75. type
  76. regvarother_longintarray = array[tregisterindex] of longint;
  77. regvarother_booleanarray = array[tregisterindex] of boolean;
  78. regvarint_longintarray = array[first_int_supreg..last_int_supreg] of longint;
  79. regvarint_ptreearray = array[first_int_supreg..last_int_supreg] of tnode;
  80. tpushedsavedloc = record
  81. case byte of
  82. 0: (pushed: boolean);
  83. 1: (ofs: longint);
  84. end;
  85. tpushedsavedother = array[tregisterindex] of tpushedsavedloc;
  86. Tinterferencebitmap=array[Tsuperregister] of set of Tsuperregister;
  87. Tinterferenceadjlist=array[Tsuperregister] of Pstring;
  88. Tinterferencegraph=record
  89. bitmap:Tinterferencebitmap;
  90. adjlist:Tinterferenceadjlist;
  91. end;
  92. Pinterferencegraph=^Tinterferencegraph;
  93. Tmovelist=record
  94. count:cardinal;
  95. data:array[0..$ffff] of Tlinkedlistitem;
  96. end;
  97. Pmovelist=^Tmovelist;
  98. {In the register allocator we keep track of move instructions.
  99. These instructions are moved between five linked lists. There
  100. is also a linked list per register to keep track about the moves
  101. it is associated with. Because we need to determine quickly in
  102. which of the five lists it is we add anu enumeradtion to each
  103. move instruction.}
  104. Tmoveset=(ms_coalesced_moves,ms_constrained_moves,ms_frozen_moves,
  105. ms_worklist_moves,ms_active_moves);
  106. Tmoveins=class(Tlinkedlistitem)
  107. moveset:Tmoveset;
  108. { $ifdef ra_debug}
  109. x,y:Tsuperregister;
  110. { $endif}
  111. instruction:Taicpu;
  112. end;
  113. {#
  114. This class implements the abstract register allocator
  115. It is used by the code generator to allocate and free
  116. registers which might be valid across nodes. It also
  117. contains utility routines related to registers.
  118. Some of the methods in this class should be overriden
  119. by cpu-specific implementations.
  120. }
  121. trgobj = class
  122. { The "usableregsxxx" contain all registers of type "xxx" that }
  123. { aren't currently allocated to a regvar. The "unusedregsxxx" }
  124. { contain all registers of type "xxx" that aren't currently }
  125. { allocated }
  126. lastintreg,maxintreg:Tsuperregister;
  127. unusedregsint,usableregsint:Tsuperregisterset;
  128. unusedregsaddr,usableregsaddr:Tsuperregisterset;
  129. unusedregsfpu,usableregsfpu : Tsuperregisterset;
  130. unusedregsmm,usableregsmm : Tsuperregisterset;
  131. { these counters contain the number of elements in the }
  132. { unusedregsxxx/usableregsxxx sets }
  133. countunusedregsfpu,
  134. countunusedregsmm : byte;
  135. countusableregsint,
  136. countusableregsaddr,
  137. countusableregsfpu,
  138. countusableregsmm : byte;
  139. { Contains the registers which are really used by the proc itself.
  140. It doesn't take care of registers used by called procedures
  141. }
  142. savedintbyproc,
  143. used_in_proc_int,
  144. usedaddrinproc : Tsuperregisterset;
  145. used_in_proc_other : totherregisterset;
  146. reg_pushes_other : regvarother_longintarray;
  147. is_reg_var_other : regvarother_booleanarray;
  148. is_reg_var_int : Tsuperregisterset;
  149. regvar_loaded_other : regvarother_booleanarray;
  150. regvar_loaded_int : Tsuperregisterset;
  151. colour : array[Tsuperregister] of Tsuperregister;
  152. spillednodes : string;
  153. { tries to hold the amount of times which the current tree is processed }
  154. t_times: longint;
  155. constructor create(Acpu_registers:byte);
  156. {# Allocate a general purpose register
  157. An internalerror will be generated if there
  158. is no more free registers which can be allocated
  159. }
  160. function getregisterint(list:Taasmoutput;size:Tcgsize):Tregister;
  161. procedure add_constraints(reg:Tregister);virtual;
  162. {# Allocate an ABT register
  163. An internalerror will be generated if there
  164. is no more free registers which can be allocated
  165. An explanantion of abt registers can be found near the implementation.
  166. }
  167. function getabtregisterint(list:Taasmoutput;size:Tcgsize):Tregister;
  168. {# Free a general purpose register
  169. @param(r register to free)
  170. }
  171. procedure ungetregisterint(list: taasmoutput; r : tregister); virtual;
  172. {# Allocate a floating point register
  173. An internalerror will be generated if there
  174. is no more free registers which can be allocated
  175. }
  176. function getregisterfpu(list: taasmoutput;size:Tcgsize) : tregister; virtual;
  177. {# Free a floating point register
  178. @param(r register to free)
  179. }
  180. procedure ungetregisterfpu(list: taasmoutput; r : tregister;size:TCGsize); virtual;
  181. function getregistermm(list: taasmoutput) : tregister; virtual;
  182. procedure ungetregistermm(list: taasmoutput; r : tregister); virtual;
  183. {# Allocate an address register.
  184. Address registers are the only registers which can
  185. be used as a base register in references (treference).
  186. On most cpu's this is the same as a general purpose
  187. register.
  188. An internalerror will be generated if there
  189. is no more free registers which can be allocated
  190. }
  191. function getaddressregister(list:Taasmoutput):Tregister;virtual;
  192. procedure ungetaddressregister(list: taasmoutput; r: tregister); virtual;
  193. {# Verify if the specified register is an address or
  194. general purpose register. Returns TRUE if @var(reg)
  195. is an adress register.
  196. This routine should only be used to check on
  197. general purpose or address register. It will
  198. not work on multimedia or floating point
  199. registers
  200. @param(reg register to verify)
  201. }
  202. function isaddressregister(reg: tregister): boolean; virtual;
  203. {# Tries to allocate the passed register, if possible
  204. @param(r specific register to allocate)
  205. }
  206. function getexplicitregisterint(list:Taasmoutput;r:Tregister):Tregister;virtual;
  207. {# Tries to allocate the passed fpu register, if possible
  208. @param(r specific register to allocate)
  209. }
  210. function getexplicitregisterfpu(list : taasmoutput; r : Tregister) : tregister;virtual;
  211. procedure allocexplicitregistersint(list:Taasmoutput;r:Tsuperregisterset);
  212. procedure deallocexplicitregistersint(list:Taasmoutput;r:Tsuperregisterset);
  213. {# Deallocate any kind of register }
  214. procedure ungetregister(list: taasmoutput; r : tregister); virtual;
  215. {# Deallocate all registers which are allocated
  216. in the specified reference. On most systems,
  217. this will free the base and index registers
  218. of the specified reference.
  219. @param(ref reference which must have its registers freed)
  220. }
  221. procedure ungetreference(list: taasmoutput; const ref : treference); virtual;
  222. {# Reset the register allocator information (usable registers etc).
  223. Please note that it is mortal sins to call cleartempgen during
  224. graph colouring (that is between prepare_colouring and
  225. epilogue_colouring).
  226. }
  227. procedure cleartempgen;virtual;
  228. {# Convert a register to a specified register size, and return that register size }
  229. function makeregsize(reg: tregister; size: tcgsize): tregister; virtual;
  230. {# saves register variables (restoring happens automatically) }
  231. procedure saveotherregvars(list:Taasmoutput;const s:Totherregisterset);
  232. {# Saves in temporary references (allocated via the temp. allocator)
  233. the registers defined in @var(s). The registers are only saved
  234. if they are currently in use, otherwise they are left as is.
  235. On processors which have instructions which manipulate the stack,
  236. this routine should be overriden for performance reasons.
  237. @param(list) List to add the instruction to
  238. @param(saved) Array of saved register information
  239. @param(s) Registers which might require saving
  240. }
  241. procedure saveusedotherregisters(list:Taasmoutput;
  242. var saved:Tpushedsavedother;
  243. const s:Totherregisterset);virtual;
  244. {# Restores the registers which were saved with a call
  245. to @var(saveusedregisters).
  246. On processors which have instructions which manipulate the stack,
  247. this routine should be overriden for performance reasons.
  248. }
  249. procedure restoreusedotherregisters(list:Taasmoutput;
  250. const saved:Tpushedsavedother);virtual;
  251. { used when deciding which registers to use for regvars }
  252. procedure incrementotherregisterpushed(const s: totherregisterset);
  253. procedure clearregistercount;
  254. procedure resetusableregisters;virtual;
  255. procedure makeregvarint(reg:Tsuperregister);
  256. procedure makeregvarother(reg:Tregister);
  257. procedure saveStateForInline(var state: pointer);virtual;
  258. procedure restoreStateAfterInline(var state: pointer);virtual;
  259. procedure saveUnusedState(var state: pointer);virtual;
  260. procedure restoreUnusedState(var state: pointer);virtual;
  261. {$ifdef ra_debug2}
  262. procedure writegraph;
  263. {$endif ra_debug2}
  264. procedure add_move_instruction(instr:Taicpu);
  265. procedure prepare_colouring;
  266. procedure epilogue_colouring;
  267. procedure colour_registers;
  268. function spill_registers(list:Taasmoutput;const regs_to_spill:string):boolean;
  269. protected
  270. cpu_registers:byte;
  271. igraph:Tinterferencegraph;
  272. degree:array[0..255] of byte;
  273. alias:array[Tsuperregister] of Tsuperregister;
  274. simplifyworklist,freezeworklist,spillworklist:string;
  275. coalescednodes:string;
  276. selectstack:string;
  277. abtlist:string;
  278. movelist:array[Tsuperregister] of Pmovelist;
  279. worklist_moves,active_moves,frozen_moves,
  280. coalesced_moves,constrained_moves:Tlinkedlist;
  281. { the following two contain the common (generic) code for all }
  282. { get- and ungetregisterxxx functions/procedures }
  283. function getregistergenother(list: taasmoutput; const lowreg, highreg: Tregisterindex;
  284. var unusedregs:Totherregisterset;var countunusedregs:byte): tregister;
  285. function getregistergenint(list:Taasmoutput;subreg:Tsubregister;
  286. const lowreg,highreg:Tsuperregister;
  287. var fusedinproc,unusedregs:Tsuperregisterset):Tregister;
  288. procedure ungetregistergen(list: taasmoutput; r: tregister;
  289. const usableregs:totherregisterset;var unusedregs: totherregisterset; var countunusedregs: byte);
  290. procedure ungetregistergenint(list:taasmoutput;r:Tregister;
  291. const usableregs:Tsuperregisterset;
  292. var unusedregs:Tsuperregisterset);
  293. procedure getregisterintinline(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister);
  294. procedure ungetregisterintinline(list:Taasmoutput;position:Tai;r:Tregister);
  295. procedure add_edge(u,v:Tsuperregister);
  296. procedure add_edges_used(u:Tsuperregister);
  297. procedure add_to_movelist(u:Tsuperregister;data:Tlinkedlistitem);
  298. function move_related(n:Tsuperregister):boolean;
  299. procedure make_work_list;
  300. procedure enable_moves(n:Tsuperregister);
  301. procedure decrement_degree(m:Tsuperregister);
  302. procedure simplify;
  303. function get_alias(n:Tsuperregister):Tsuperregister;
  304. procedure add_worklist(u:Tsuperregister);
  305. function adjacent_ok(u,v:Tsuperregister):boolean;
  306. function conservative(u,v:Tsuperregister):boolean;
  307. procedure combine(u,v:Tsuperregister);
  308. procedure coalesce;
  309. procedure freeze_moves(u:Tsuperregister);
  310. procedure freeze;
  311. procedure select_spill;
  312. procedure assign_colours;
  313. procedure clear_interferences(u:Tsuperregister);
  314. end;
  315. const
  316. {# This value is used in tsaved. If the array value is equal
  317. to this, then this means that this register is not used.
  318. }
  319. reg_not_saved = $7fffffff;
  320. var
  321. {# This is the class instance used to access the register allocator class }
  322. rg: trgobj;
  323. { trerefence handling }
  324. {# Clear to zero a treference }
  325. procedure reference_reset(var ref : treference);
  326. {# Clear to zero a treference, and set is base address
  327. to base register.
  328. }
  329. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  330. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  331. procedure reference_release(list: taasmoutput; const ref : treference);
  332. { This routine verifies if two references are the same, and
  333. if so, returns TRUE, otherwise returns false.
  334. }
  335. function references_equal(sref : treference;dref : treference) : boolean;
  336. { tlocation handling }
  337. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  338. procedure location_release(list: taasmoutput; const l : tlocation);
  339. procedure location_freetemp(list: taasmoutput; const l : tlocation);
  340. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  341. procedure location_swap(var destloc,sourceloc : tlocation);
  342. type
  343. psavedstate = ^tsavedstate;
  344. tsavedstate = record
  345. unusedregsint,usableregsint : Tsuperregisterset;
  346. unusedregsaddr,usableregsaddr : Tsuperregisterset;
  347. unusedregsfpu,usableregsfpu : totherregisterset;
  348. unusedregsmm,usableregsmm : totherregisterset;
  349. countunusedregsfpu,
  350. countunusedregsmm : byte;
  351. countusableregsint,
  352. countusableregsfpu,
  353. countusableregsmm : byte;
  354. { contains the registers which are really used by the proc itself }
  355. used_in_proc_int : Tsuperregisterset;
  356. used_in_proc_other : totherregisterset;
  357. reg_pushes_other : regvarother_longintarray;
  358. reg_pushes_int : regvarint_longintarray;
  359. is_reg_var_other : regvarother_booleanarray;
  360. is_reg_var_int : Tsuperregisterset;
  361. regvar_loaded_other: regvarother_booleanarray;
  362. regvar_loaded_int: Tsuperregisterset;
  363. end;
  364. punusedstate = ^tunusedstate;
  365. tunusedstate = record
  366. unusedregsaddr : Tsuperregisterset;
  367. unusedregsfpu : totherregisterset;
  368. unusedregsmm : totherregisterset;
  369. countunusedregsfpu,
  370. countunusedregsmm : byte;
  371. end;
  372. implementation
  373. uses
  374. systems,{$ifdef ra_debug2}fmodule,{$endif}
  375. globals,verbose,
  376. cgobj,tgobj,regvars;
  377. constructor Trgobj.create(Acpu_registers:byte);
  378. begin
  379. used_in_proc_int := [];
  380. used_in_proc_other:=[];
  381. t_times := 0;
  382. resetusableregisters;
  383. lastintreg:=0;
  384. maxintreg:=first_int_imreg;
  385. {What madman decided to change the code like this: (??)
  386. cpu_registers:=last_int_supreg-first_int_supreg+1;
  387. The amount of registers available for register allocation is
  388. allmost allways smaller than the amount of registers that exists!
  389. Therefore: }
  390. cpu_registers:=Acpu_registers;
  391. fillchar(igraph,sizeof(igraph),0);
  392. fillchar(degree,sizeof(degree),0);
  393. {Precoloured nodes should have an infinite degree, which we can approach
  394. by 255.}
  395. fillchar(movelist,sizeof(movelist),0);
  396. worklist_moves:=Tlinkedlist.create;
  397. abtlist:='';
  398. end;
  399. function trgobj.getregistergenother(list: taasmoutput; const lowreg, highreg: Tregisterindex;
  400. var unusedregs: totherregisterset; var countunusedregs: byte): tregister;
  401. var
  402. i: tregisterindex;
  403. r: Tregister;
  404. begin
  405. for i:=low(tregisterindex) to high(tregisterindex) do
  406. begin
  407. if i in unusedregs then
  408. begin
  409. exclude(unusedregs,i);
  410. include(used_in_proc_other,i);
  411. dec(countunusedregs);
  412. r:=regnumber_table[i];
  413. list.concat(tai_regalloc.alloc(r));
  414. result := r;
  415. exit;
  416. end;
  417. end;
  418. internalerror(10);
  419. end;
  420. function Trgobj.getregistergenint(list:Taasmoutput;
  421. subreg:Tsubregister;
  422. const lowreg,highreg:Tsuperregister;
  423. var fusedinproc,unusedregs:Tsuperregisterset):Tregister;
  424. var i:Tsuperregister;
  425. r:Tregister;
  426. begin
  427. if not (lastintreg in [lowreg..highreg]) then
  428. lastintreg:=lowreg;
  429. i:=lastintreg;
  430. repeat
  431. if i=highreg then
  432. i:=lowreg
  433. else
  434. inc(i);
  435. if (i in unusedregs) and (pos(char(i),abtlist)=0) then
  436. begin
  437. exclude(unusedregs,i);
  438. include(fusedinproc,i);
  439. r:=newreg(R_INTREGISTER,i,subreg);
  440. list.concat(Tai_regalloc.alloc(r));
  441. result:=r;
  442. lastintreg:=i;
  443. if i>maxintreg then
  444. maxintreg:=i;
  445. add_edges_used(i);
  446. exit;
  447. end;
  448. until i=lastintreg;
  449. internalerror(10);
  450. end;
  451. procedure trgobj.ungetregistergen(list: taasmoutput; r: tregister;
  452. const usableregs: totherregisterset; var unusedregs: totherregisterset; var countunusedregs: byte);
  453. var
  454. regidx : tregisterindex;
  455. begin
  456. regidx:=findreg_by_number(r);
  457. { takes much time }
  458. if not(regidx in usableregs) then
  459. exit;
  460. if (regidx in unusedregs) then
  461. exit
  462. else
  463. inc(countunusedregs);
  464. include(unusedregs,regidx);
  465. list.concat(tai_regalloc.dealloc(r));
  466. end;
  467. procedure trgobj.ungetregistergenint(list:taasmoutput;r:Tregister;
  468. const usableregs:Tsuperregisterset;
  469. var unusedregs:Tsuperregisterset);
  470. var
  471. supreg:Tsuperregister;
  472. begin
  473. supreg:=getsupreg(r);
  474. { takes much time }
  475. if supreg in is_reg_var_int then
  476. exit;
  477. if (supreg in unusedregs) then
  478. exit;
  479. include(unusedregs,supreg);
  480. list.concat(tai_regalloc.dealloc(r));
  481. add_edges_used(supreg);
  482. end;
  483. function trgobj.getregisterint(list:taasmoutput;size:Tcgsize):Tregister;
  484. var subreg:Tsubregister;
  485. begin
  486. subreg:=cgsize2subreg(size);
  487. result:=getregistergenint(list,
  488. subreg,
  489. first_int_imreg,
  490. last_int_imreg,
  491. used_in_proc_int,
  492. unusedregsint);
  493. add_constraints(getregisterint);
  494. end;
  495. procedure Trgobj.add_constraints(reg:Tregister);
  496. begin
  497. end;
  498. procedure trgobj.ungetregisterint(list : taasmoutput; r : tregister);
  499. begin
  500. ungetregistergenint(list,r,usableregsint,unusedregsint);
  501. end;
  502. { tries to allocate the passed register, if possible }
  503. function trgobj.getexplicitregisterint(list:Taasmoutput;r:Tregister):Tregister;
  504. var supreg : tsuperregister;
  505. begin
  506. supreg:=getsupreg(r);
  507. if supreg in unusedregsint then
  508. begin
  509. exclude(unusedregsint,supreg);
  510. include(used_in_proc_int,supreg);
  511. list.concat(tai_regalloc.alloc(r));
  512. add_edges_used(supreg);
  513. end
  514. else
  515. internalerror(200301103);
  516. getexplicitregisterint:=r;
  517. end;
  518. procedure Trgobj.allocexplicitregistersint(list:Taasmoutput;r:Tsuperregisterset);
  519. var reg:Tregister;
  520. i:Tsuperregister;
  521. begin
  522. if unusedregsint*r=r then
  523. begin
  524. unusedregsint:=unusedregsint-r;
  525. used_in_proc_int:=used_in_proc_int+r;
  526. for i:=first_int_supreg to last_int_supreg do
  527. if i in r then
  528. begin
  529. add_edges_used(i);
  530. reg:=newreg(R_INTREGISTER,i,R_SUBWHOLE);
  531. list.concat(Tai_regalloc.alloc(reg));
  532. end;
  533. end
  534. else
  535. internalerror(200305061);
  536. end;
  537. procedure Trgobj.deallocexplicitregistersint(list:Taasmoutput;r:Tsuperregisterset);
  538. var reg:Tregister;
  539. i:Tsuperregister;
  540. begin
  541. if unusedregsint*r=[] then
  542. begin
  543. unusedregsint:=unusedregsint+r;
  544. for i:=last_int_supreg downto first_int_supreg do
  545. if i in r then
  546. begin
  547. reg:=newreg(R_INTREGISTER,i,R_SUBWHOLE);
  548. list.concat(Tai_regalloc.dealloc(reg));
  549. end;
  550. end
  551. else
  552. internalerror(200305062);
  553. end;
  554. { tries to allocate the passed register, if possible }
  555. function trgobj.getexplicitregisterfpu(list : taasmoutput; r : Tregister) : tregister;
  556. var regidx : tregisterindex;
  557. begin
  558. regidx:=findreg_by_number(r);
  559. if regidx in unusedregsfpu then
  560. begin
  561. dec(countunusedregsfpu);
  562. exclude(unusedregsfpu,regidx);
  563. include(used_in_proc_other,regidx);
  564. list.concat(tai_regalloc.alloc(r));
  565. getexplicitregisterfpu:=r;
  566. end
  567. else
  568. {$warning Size for FPU reg is maybe not correct}
  569. getexplicitregisterfpu:=getregisterfpu(list,OS_F32);
  570. end;
  571. function trgobj.getregisterfpu(list: taasmoutput;size:Tcgsize) : tregister;
  572. begin
  573. if countunusedregsfpu=0 then
  574. internalerror(10);
  575. {$warning TODO firstsavefpureg}
  576. result := getregistergenother(list,{firstsavefpureg,lastsavefpureg,}0,0,
  577. unusedregsfpu,countunusedregsfpu);
  578. end;
  579. procedure trgobj.ungetregisterfpu(list : taasmoutput; r : tregister;size:TCGsize);
  580. begin
  581. ungetregistergen(list,r,usableregsfpu,unusedregsfpu,
  582. countunusedregsfpu);
  583. end;
  584. function trgobj.getregistermm(list: taasmoutput) : tregister;
  585. begin
  586. if countunusedregsmm=0 then
  587. internalerror(10);
  588. {$warning TODO firstsavemmreg}
  589. result := getregistergenother(list,{firstsavemmreg,lastsavemmreg,}0,0,
  590. unusedregsmm,countunusedregsmm);
  591. end;
  592. procedure trgobj.ungetregistermm(list: taasmoutput; r: tregister);
  593. begin
  594. ungetregistergen(list,r,usableregsmm,unusedregsmm,
  595. countunusedregsmm);
  596. end;
  597. function trgobj.getaddressregister(list:Taasmoutput): tregister;
  598. begin
  599. {An address register is OS_INT per definition.}
  600. result := getregisterint(list,OS_INT);
  601. end;
  602. procedure trgobj.ungetaddressregister(list: taasmoutput; r: tregister);
  603. begin
  604. ungetregisterint(list,r);
  605. end;
  606. function trgobj.isaddressregister(reg: tregister): boolean;
  607. begin
  608. result := true;
  609. end;
  610. procedure trgobj.ungetregister(list: taasmoutput; r : tregister);
  611. begin
  612. if r=NR_NO then
  613. exit;
  614. if getregtype(r)=R_FPUREGISTER then
  615. ungetregisterfpu(list,r,OS_NO)
  616. else if getregtype(r)=R_MMXREGISTER then
  617. ungetregistermm(list,r)
  618. else if getregtype(r)=R_ADDRESSREGISTER then
  619. ungetaddressregister(list,r)
  620. else internalerror(2002070602);
  621. end;
  622. procedure Trgobj.cleartempgen;
  623. var i:Tsuperregister;
  624. begin
  625. countunusedregsfpu:=countusableregsfpu;
  626. countunusedregsmm:=countusableregsmm;
  627. lastintreg:=0;
  628. maxintreg:=first_int_imreg;
  629. unusedregsint:=[0..255];
  630. unusedregsfpu:=usableregsfpu;
  631. unusedregsmm:=usableregsmm;
  632. {$ifdef powerpc}
  633. savedintbyproc:=[RS_R13..RS_R31];
  634. {$else powerpc}
  635. savedintbyproc:=[];
  636. {$endif powerpc}
  637. for i:=low(Tsuperregister) to high(Tsuperregister) do
  638. begin
  639. if igraph.adjlist[i]<>nil then
  640. dispose(igraph.adjlist[i]);
  641. if movelist[i]<>nil then
  642. dispose(movelist[i]);
  643. end;
  644. fillchar(movelist,sizeof(movelist),0);
  645. fillchar(igraph,sizeof(igraph),0);
  646. fillchar(degree,sizeof(degree),0);
  647. {Precoloured nodes should have an infinite degree, which we can approach
  648. by 255.}
  649. for i:=first_int_supreg to last_int_supreg do
  650. degree[i]:=255;
  651. worklist_moves.clear;
  652. abtlist:='';
  653. end;
  654. procedure trgobj.ungetreference(list : taasmoutput; const ref : treference);
  655. begin
  656. if (ref.base<>NR_NO) and (ref.base<>NR_FRAME_POINTER_REG) then
  657. ungetregisterint(list,ref.base);
  658. if (ref.index<>NR_NO) and (ref.index<>NR_FRAME_POINTER_REG) then
  659. ungetregisterint(list,ref.index);
  660. end;
  661. procedure trgobj.saveotherregvars(list: taasmoutput; const s: totherregisterset);
  662. var
  663. r: Tregister;
  664. begin
  665. if not(cs_regvars in aktglobalswitches) then
  666. exit;
  667. {$warning TODO firstsavefpureg}
  668. {
  669. if firstsavefpureg <> NR_NO then
  670. for r.enum := firstsavefpureg to lastsavefpureg do
  671. if is_reg_var_other[r.enum] and
  672. (r.enum in s) then
  673. store_regvar(list,r);
  674. if firstsavemmreg <> R_NO then
  675. for r.enum := firstsavemmreg to lastsavemmreg do
  676. if is_reg_var_other[r.enum] and
  677. (r.enum in s) then
  678. store_regvar(list,r);
  679. }
  680. end;
  681. procedure trgobj.saveusedotherregisters(list: taasmoutput;
  682. var saved : tpushedsavedother; const s: totherregisterset);
  683. var
  684. r : tregister;
  685. hr : treference;
  686. begin
  687. used_in_proc_other:=used_in_proc_other + s;
  688. {$warning TODO firstsavefpureg}
  689. (*
  690. { don't try to save the fpu registers if not desired (e.g. for }
  691. { the 80x86) }
  692. if firstsavefpureg <> R_NO then
  693. for r.enum:=firstsavefpureg to lastsavefpureg do
  694. begin
  695. saved[r.enum].ofs:=reg_not_saved;
  696. { if the register is used by the calling subroutine and if }
  697. { it's not a regvar (those are handled separately) }
  698. if not is_reg_var_other[r.enum] and
  699. (r.enum in s) and
  700. { and is present in use }
  701. not(r.enum in unusedregsfpu) then
  702. begin
  703. { then save it }
  704. tg.GetTemp(list,extended_size,tt_persistent,hr);
  705. saved[r.enum].ofs:=hr.offset;
  706. cg.a_loadfpu_reg_ref(list,OS_FLOAT,r,hr);
  707. cg.a_reg_dealloc(list,r);
  708. include(unusedregsfpu,r.enum);
  709. inc(countunusedregsfpu);
  710. end;
  711. end;
  712. { don't save the vector registers if there's no support for them }
  713. if firstsavemmreg <> R_NO then
  714. for r.enum:=firstsavemmreg to lastsavemmreg do
  715. begin
  716. saved[r.enum].ofs:=reg_not_saved;
  717. { if the register is in use and if it's not a regvar (those }
  718. { are handled separately), save it }
  719. if not is_reg_var_other[r.enum] and
  720. (r.enum in s) and
  721. { and is present in use }
  722. not(r.enum in unusedregsmm) then
  723. begin
  724. { then save it }
  725. tg.GetTemp(list,mmreg_size,tt_persistent,hr);
  726. saved[r.enum].ofs:=hr.offset;
  727. cg.a_loadmm_reg_ref(list,r,hr);
  728. cg.a_reg_dealloc(list,r);
  729. include(unusedregsmm,r.enum);
  730. inc(countunusedregsmm);
  731. end;
  732. end;
  733. *)
  734. end;
  735. procedure trgobj.restoreusedotherregisters(list : taasmoutput;
  736. const saved : tpushedsavedother);
  737. var
  738. r,r2 : tregister;
  739. hr : treference;
  740. begin
  741. {$warning TODO firstsavefpureg}
  742. (*
  743. if firstsavemmreg <> R_NO then
  744. for r.enum:=lastsavemmreg downto firstsavemmreg do
  745. begin
  746. if saved[r.enum].ofs <> reg_not_saved then
  747. begin
  748. r2.enum:=R_INTREGISTER;
  749. r2.number:=NR_FRAME_POINTER_REG;
  750. reference_reset_base(hr,r2,saved[r.enum].ofs);
  751. cg.a_reg_alloc(list,r);
  752. cg.a_loadmm_ref_reg(list,hr,r);
  753. if not (r.enum in unusedregsmm) then
  754. { internalerror(10)
  755. in n386cal we always save/restore the reg *state*
  756. using save/restoreunusedstate -> the current state
  757. may not be real (JM) }
  758. else
  759. begin
  760. dec(countunusedregsmm);
  761. exclude(unusedregsmm,r.enum);
  762. end;
  763. tg.UnGetTemp(list,hr);
  764. end;
  765. end;
  766. if firstsavefpureg <> R_NO then
  767. for r.enum:=lastsavefpureg downto firstsavefpureg do
  768. begin
  769. if saved[r.enum].ofs <> reg_not_saved then
  770. begin
  771. r2.enum:=R_INTREGISTER;
  772. r2.number:=NR_FRAME_POINTER_REG;
  773. reference_reset_base(hr,r2,saved[r.enum].ofs);
  774. cg.a_reg_alloc(list,r);
  775. cg.a_loadfpu_ref_reg(list,OS_FLOAT,hr,r);
  776. if not (r.enum in unusedregsfpu) then
  777. { internalerror(10)
  778. in n386cal we always save/restore the reg *state*
  779. using save/restoreunusedstate -> the current state
  780. may not be real (JM) }
  781. else
  782. begin
  783. dec(countunusedregsfpu);
  784. exclude(unusedregsfpu,r.enum);
  785. end;
  786. tg.UnGetTemp(list,hr);
  787. end;
  788. end;
  789. *)
  790. end;
  791. procedure trgobj.incrementotherregisterpushed(const s:Totherregisterset);
  792. {$ifdef i386}
  793. var
  794. regi : Tregister;
  795. {$endif i386}
  796. begin
  797. {$warning TODO firstsavefpureg}
  798. (*
  799. {$ifdef i386}
  800. if firstsavefpureg <> R_NO then
  801. for regi:=firstsavefpureg to lastsavefpureg do
  802. begin
  803. if (regi in s) then
  804. inc(reg_pushes_other[regi],t_times*2);
  805. end;
  806. if firstsavemmreg <> R_NO then
  807. for regi:=firstsavemmreg to lastsavemmreg do
  808. begin
  809. if (regi in s) then
  810. inc(reg_pushes_other[regi],t_times*2);
  811. end;
  812. {$endif i386}
  813. *)
  814. end;
  815. procedure trgobj.clearregistercount;
  816. begin
  817. fillchar(reg_pushes_other,sizeof(reg_pushes_other),0);
  818. {ifndef i386}
  819. { all used registers will have to be saved at the start and restored }
  820. { at the end, but otoh regpara's do not have to be saved to memory }
  821. { at the start (there is a move from regpara to regvar most of the }
  822. { time though) -> set cost to 100+20 }
  823. {$warning TODO firstsavefpureg}
  824. (*
  825. filldword(reg_pushes_other[firstsavefpureg],ord(lastsavefpureg)-ord(firstsavefpureg)+1,120);
  826. *)
  827. {endif not i386}
  828. fillchar(is_reg_var_other,sizeof(is_reg_var_other),false);
  829. is_reg_var_int:=[];
  830. fillchar(regvar_loaded_other,sizeof(regvar_loaded_other),false);
  831. regvar_loaded_int:=[];
  832. end;
  833. procedure trgobj.resetusableregisters;
  834. begin
  835. { initialize fields with constant values from cpubase }
  836. countusableregsint := cpubase.c_countusableregsint;
  837. countusableregsfpu := cpubase.c_countusableregsfpu;
  838. countusableregsmm := cpubase.c_countusableregsmm;
  839. usableregsint := cpubase.usableregsint;
  840. usableregsfpu := cpubase.usableregsfpu;
  841. usableregsmm := cpubase.usableregsmm;
  842. clearregistercount;
  843. end;
  844. procedure trgobj.makeregvarint(reg:Tsuperregister);
  845. begin
  846. dec(countusableregsint);
  847. include(is_reg_var_int,reg);
  848. end;
  849. procedure trgobj.makeregvarother(reg: tregister);
  850. begin
  851. (*
  852. if reg.enum>lastreg then
  853. internalerror(200301081);
  854. if reg.enum in intregs then
  855. internalerror(200301151)
  856. else if reg.enum in fpuregs then
  857. begin
  858. dec(countusableregsfpu);
  859. dec(countunusedregsfpu);
  860. exclude(usableregsfpu,reg.enum);
  861. exclude(unusedregsfpu,reg.enum);
  862. include(used_in_proc_other,reg.enum);
  863. end
  864. else if reg.enum in mmregs then
  865. begin
  866. dec(countusableregsmm);
  867. dec(countunusedregsmm);
  868. exclude(usableregsmm,reg.enum);
  869. exclude(unusedregsmm,reg.enum);
  870. include(used_in_proc_other,reg.enum);
  871. end;
  872. is_reg_var_other[reg.enum]:=true;
  873. *)
  874. end;
  875. procedure trgobj.saveStateForInline(var state: pointer);
  876. begin
  877. new(psavedstate(state));
  878. psavedstate(state)^.unusedregsint := unusedregsint;
  879. psavedstate(state)^.usableregsint := usableregsint;
  880. psavedstate(state)^.unusedregsfpu := unusedregsfpu;
  881. psavedstate(state)^.usableregsfpu := usableregsfpu;
  882. psavedstate(state)^.unusedregsmm := unusedregsmm;
  883. psavedstate(state)^.usableregsmm := usableregsmm;
  884. psavedstate(state)^.countunusedregsfpu := countunusedregsfpu;
  885. psavedstate(state)^.countunusedregsmm := countunusedregsmm;
  886. psavedstate(state)^.countusableregsint := countusableregsint;
  887. psavedstate(state)^.countusableregsfpu := countusableregsfpu;
  888. psavedstate(state)^.countusableregsmm := countusableregsmm;
  889. psavedstate(state)^.used_in_proc_int := used_in_proc_int;
  890. psavedstate(state)^.used_in_proc_other := used_in_proc_other;
  891. psavedstate(state)^.reg_pushes_other := reg_pushes_other;
  892. psavedstate(state)^.is_reg_var_int := is_reg_var_int;
  893. psavedstate(state)^.is_reg_var_other := is_reg_var_other;
  894. psavedstate(state)^.regvar_loaded_int := regvar_loaded_int;
  895. psavedstate(state)^.regvar_loaded_other := regvar_loaded_other;
  896. end;
  897. procedure trgobj.restoreStateAfterInline(var state: pointer);
  898. begin
  899. unusedregsint := psavedstate(state)^.unusedregsint;
  900. usableregsint := psavedstate(state)^.usableregsint;
  901. unusedregsfpu := psavedstate(state)^.unusedregsfpu;
  902. usableregsfpu := psavedstate(state)^.usableregsfpu;
  903. unusedregsmm := psavedstate(state)^.unusedregsmm;
  904. usableregsmm := psavedstate(state)^.usableregsmm;
  905. countunusedregsfpu := psavedstate(state)^.countunusedregsfpu;
  906. countunusedregsmm := psavedstate(state)^.countunusedregsmm;
  907. countusableregsint := psavedstate(state)^.countusableregsint;
  908. countusableregsfpu := psavedstate(state)^.countusableregsfpu;
  909. countusableregsmm := psavedstate(state)^.countusableregsmm;
  910. used_in_proc_int := psavedstate(state)^.used_in_proc_int;
  911. used_in_proc_other := psavedstate(state)^.used_in_proc_other;
  912. reg_pushes_other := psavedstate(state)^.reg_pushes_other;
  913. is_reg_var_int := psavedstate(state)^.is_reg_var_int;
  914. is_reg_var_other := psavedstate(state)^.is_reg_var_other;
  915. regvar_loaded_other := psavedstate(state)^.regvar_loaded_other;
  916. regvar_loaded_int := psavedstate(state)^.regvar_loaded_int;
  917. dispose(psavedstate(state));
  918. state := nil;
  919. end;
  920. procedure trgobj.saveUnusedState(var state: pointer);
  921. begin
  922. new(punusedstate(state));
  923. punusedstate(state)^.unusedregsfpu := unusedregsfpu;
  924. punusedstate(state)^.unusedregsmm := unusedregsmm;
  925. punusedstate(state)^.countunusedregsfpu := countunusedregsfpu;
  926. punusedstate(state)^.countunusedregsmm := countunusedregsmm;
  927. end;
  928. procedure trgobj.restoreUnusedState(var state: pointer);
  929. begin
  930. unusedregsfpu := punusedstate(state)^.unusedregsfpu;
  931. unusedregsmm := punusedstate(state)^.unusedregsmm;
  932. countunusedregsfpu := punusedstate(state)^.countunusedregsfpu;
  933. countunusedregsmm := punusedstate(state)^.countunusedregsmm;
  934. dispose(punusedstate(state));
  935. state := nil;
  936. end;
  937. procedure Trgobj.add_edge(u,v:Tsuperregister);
  938. {This procedure will add an edge to the virtual interference graph.}
  939. procedure addadj(u,v:Tsuperregister);
  940. begin
  941. if igraph.adjlist[u]=nil then
  942. begin
  943. getmem(igraph.adjlist[u],16);
  944. igraph.adjlist[u]^:='';
  945. end
  946. else if (length(igraph.adjlist[u]^) and 15)=15 then
  947. reallocmem(igraph.adjlist[u],length(igraph.adjlist[u]^)+16);
  948. igraph.adjlist[u]^:=igraph.adjlist[u]^+char(v);
  949. end;
  950. begin
  951. if (u<>v) and not(v in igraph.bitmap[u]) then
  952. begin
  953. include(igraph.bitmap[u],v);
  954. include(igraph.bitmap[v],u);
  955. {Precoloured nodes are not stored in the interference graph.}
  956. if not(u in [first_int_supreg..last_int_supreg]) then
  957. begin
  958. addadj(u,v);
  959. inc(degree[u]);
  960. end;
  961. if not(v in [first_int_supreg..last_int_supreg]) then
  962. begin
  963. addadj(v,u);
  964. inc(degree[v]);
  965. end;
  966. end;
  967. end;
  968. procedure Trgobj.add_edges_used(u:Tsuperregister);
  969. var i:Tsuperregister;
  970. begin
  971. for i:=0 to maxintreg do
  972. if not(i in unusedregsint) then
  973. add_edge(u,i);
  974. end;
  975. {$ifdef ra_debug2}
  976. procedure Trgobj.writegraph;
  977. {This procedure writes out the current interference graph in the
  978. register allocator.}
  979. var f:text;
  980. i,j:Tsuperregister;
  981. begin
  982. assign(f,'igraph.'+Lower(current_module.modulename^));
  983. rewrite(f);
  984. writeln(f,'Interference graph');
  985. writeln(f);
  986. write(f,' ');
  987. for i:=0 to 15 do
  988. for j:=0 to 15 do
  989. write(f,hexstr(i,1));
  990. writeln(f);
  991. write(f,' ');
  992. for i:=0 to 15 do
  993. write(f,'0123456789ABCDEF');
  994. writeln(f);
  995. for i:=0 to 255 do
  996. begin
  997. write(f,hexstr(i,2):4);
  998. for j:=0 to 255 do
  999. if j in igraph.bitmap[i] then
  1000. write(f,'*')
  1001. else
  1002. write(f,'-');
  1003. writeln(f);
  1004. end;
  1005. close(f);
  1006. end;
  1007. {$endif ra_debug2}
  1008. procedure Trgobj.add_to_movelist(u:Tsuperregister;data:Tlinkedlistitem);
  1009. begin
  1010. if movelist[u]=nil then
  1011. begin
  1012. getmem(movelist[u],64);
  1013. movelist[u]^.count:=0;
  1014. end
  1015. else if (movelist[u]^.count and 15)=15 then
  1016. reallocmem(movelist[u],(movelist[u]^.count+1)*4+64);
  1017. movelist[u]^.data[movelist[u]^.count]:=data;
  1018. inc(movelist[u]^.count);
  1019. end;
  1020. procedure Trgobj.add_move_instruction(instr:Taicpu);
  1021. {This procedure notifies a certain as a move instruction so the
  1022. register allocator can try to eliminate it.}
  1023. var i:Tmoveins;
  1024. ssupreg,dsupreg:Tsuperregister;
  1025. begin
  1026. i:=Tmoveins.create;
  1027. i.moveset:=ms_worklist_moves;
  1028. i.instruction:=instr;
  1029. worklist_moves.insert(i);
  1030. ssupreg:=getsupreg(instr.oper[O_MOV_SOURCE].reg);
  1031. add_to_movelist(ssupreg,i);
  1032. dsupreg:=getsupreg(instr.oper[O_MOV_DEST].reg);
  1033. if ssupreg<>dsupreg then
  1034. {Avoid adding the same move instruction twice to a single register.}
  1035. add_to_movelist(dsupreg,i);
  1036. i.x:=ssupreg;
  1037. i.y:=dsupreg;
  1038. end;
  1039. function Trgobj.move_related(n:Tsuperregister):boolean;
  1040. var i:cardinal;
  1041. begin
  1042. move_related:=false;
  1043. if movelist[n]<>nil then
  1044. begin
  1045. for i:=0 to movelist[n]^.count-1 do
  1046. if Tmoveins(movelist[n]^.data[i]).moveset in
  1047. [ms_worklist_moves,ms_active_moves] then
  1048. begin
  1049. move_related:=true;
  1050. break;
  1051. end;
  1052. end;
  1053. end;
  1054. procedure Trgobj.make_work_list;
  1055. var n:Tsuperregister;
  1056. begin
  1057. {If we have 7 cpu registers, and the degree of a node is 7, we cannot
  1058. assign it to any of the registers, thus it is significant.}
  1059. for n:=first_int_imreg to maxintreg do
  1060. if degree[n]>=cpu_registers then
  1061. spillworklist:=spillworklist+char(n)
  1062. else if move_related(n) then
  1063. freezeworklist:=freezeworklist+char(n)
  1064. else
  1065. simplifyworklist:=simplifyworklist+char(n);
  1066. end;
  1067. procedure Trgobj.prepare_colouring;
  1068. begin
  1069. make_work_list;
  1070. active_moves:=Tlinkedlist.create;
  1071. frozen_moves:=Tlinkedlist.create;
  1072. coalesced_moves:=Tlinkedlist.create;
  1073. constrained_moves:=Tlinkedlist.create;
  1074. fillchar(alias,sizeof(alias),0);
  1075. coalescednodes:='';
  1076. selectstack:='';
  1077. end;
  1078. procedure Trgobj.enable_moves(n:Tsuperregister);
  1079. var m:Tlinkedlistitem;
  1080. i:cardinal;
  1081. begin
  1082. if movelist[n]<>nil then
  1083. for i:=0 to movelist[n]^.count-1 do
  1084. begin
  1085. m:=movelist[n]^.data[i];
  1086. if Tmoveins(m).moveset in [ms_worklist_moves,ms_active_moves] then
  1087. begin
  1088. if Tmoveins(m).moveset=ms_active_moves then
  1089. begin
  1090. {Move m from the set active_moves to the set worklist_moves.}
  1091. active_moves.remove(m);
  1092. Tmoveins(m).moveset:=ms_worklist_moves;
  1093. worklist_moves.concat(m);
  1094. end;
  1095. end;
  1096. end;
  1097. end;
  1098. procedure Trgobj.decrement_degree(m:Tsuperregister);
  1099. var adj:Pstring;
  1100. d:byte;
  1101. i,p:byte;
  1102. n:char;
  1103. begin
  1104. d:=degree[m];
  1105. if degree[m]>0 then
  1106. dec(degree[m]);
  1107. if d=cpu_registers then
  1108. begin
  1109. {Enable moves for m.}
  1110. enable_moves(m);
  1111. {Enable moves for adjacent.}
  1112. adj:=igraph.adjlist[m];
  1113. if adj<>nil then
  1114. for i:=1 to length(adj^) do
  1115. begin
  1116. n:=adj^[i];
  1117. if (pos(n,selectstack) or pos(n,coalescednodes))=0 then
  1118. enable_moves(Tsuperregister(n));
  1119. end;
  1120. {Remove the node from the spillworklist.}
  1121. p:=pos(char(m),spillworklist);
  1122. if p=0 then
  1123. internalerror(200305301); {must be found}
  1124. if length(spillworklist)>1 then
  1125. spillworklist[p]:=spillworklist[length(spillworklist)];
  1126. dec(spillworklist[0]);
  1127. if move_related(m) then
  1128. freezeworklist:=freezeworklist+char(m)
  1129. else
  1130. simplifyworklist:=simplifyworklist+char(m);
  1131. end;
  1132. end;
  1133. procedure Trgobj.simplify;
  1134. var adj:Pstring;
  1135. i,min,p:byte;
  1136. m:char;
  1137. n:Tsuperregister;
  1138. begin
  1139. {We the element with the least interferences out of the
  1140. simplifyworklist.}
  1141. min:=$ff;
  1142. p:=1;
  1143. for i:=1 to length(simplifyworklist) do
  1144. begin
  1145. adj:=igraph.adjlist[Tsuperregister(simplifyworklist[i])];
  1146. if adj=nil then
  1147. begin
  1148. min:=0;
  1149. break; {We won't find smaller ones.}
  1150. end
  1151. else
  1152. if length(adj^)<min then
  1153. begin
  1154. min:=length(adj^);
  1155. if min=0 then
  1156. break; {We won't find smaller ones.}
  1157. p:=i;
  1158. end;
  1159. end;
  1160. n:=Tsuperregister(simplifyworklist[p]);
  1161. if length(simplifyworklist)>1 then
  1162. simplifyworklist[p]:=simplifyworklist[length(simplifyworklist)];
  1163. dec(simplifyworklist[0]);
  1164. {Push it on the selectstack.}
  1165. selectstack:=selectstack+char(n);
  1166. adj:=igraph.adjlist[n];
  1167. if adj<>nil then
  1168. for i:=1 to length(adj^) do
  1169. begin
  1170. m:=adj^[i];
  1171. if ((pos(m,selectstack) or pos(m,coalescednodes))=0) and
  1172. not (Tsuperregister(m) in [first_int_supreg..last_int_supreg]) then
  1173. decrement_degree(Tsuperregister(m));
  1174. end;
  1175. end;
  1176. function Trgobj.get_alias(n:Tsuperregister):Tsuperregister;
  1177. begin
  1178. while pos(char(n),coalescednodes)<>0 do
  1179. n:=alias[n];
  1180. get_alias:=n;
  1181. end;
  1182. procedure Trgobj.add_worklist(u:Tsuperregister);
  1183. var p:byte;
  1184. begin
  1185. if not(u in [first_int_supreg..last_int_supreg]) and not move_related(u) and
  1186. (degree[u]<cpu_registers) then
  1187. begin
  1188. p:=pos(char(u),freezeworklist);
  1189. if p=0 then
  1190. internalerror(200308161); {must be found}
  1191. if length(freezeworklist)>1 then
  1192. freezeworklist[p]:=freezeworklist[length(freezeworklist)];
  1193. dec(freezeworklist[0]);
  1194. { delete(freezeworklist,pos(char(u),freezeworklist),1);}
  1195. simplifyworklist:=simplifyworklist+char(u);
  1196. end;
  1197. end;
  1198. function Trgobj.adjacent_ok(u,v:Tsuperregister):boolean;
  1199. {Check wether u and v should be coalesced. u is precoloured.}
  1200. function ok(t,r:Tsuperregister):boolean;
  1201. begin
  1202. ok:=(degree[t]<cpu_registers) or
  1203. (t in [first_int_supreg..last_int_supreg]) or
  1204. (r in igraph.bitmap[t]);
  1205. end;
  1206. var adj:Pstring;
  1207. i:byte;
  1208. t:char;
  1209. begin
  1210. adjacent_ok:=true;
  1211. adj:=igraph.adjlist[v];
  1212. if adj<>nil then
  1213. for i:=1 to length(adj^) do
  1214. begin
  1215. t:=adj^[i];
  1216. if (pos(t,selectstack) or pos(t,coalescednodes))=0 then
  1217. if not ok(Tsuperregister(t),u) then
  1218. begin
  1219. adjacent_ok:=false;
  1220. break;
  1221. end;
  1222. end;
  1223. end;
  1224. function Trgobj.conservative(u,v:Tsuperregister):boolean;
  1225. var adj:Pstring;
  1226. done:set of char; {To prevent that we count nodes twice.}
  1227. i,k:byte;
  1228. n:char;
  1229. begin
  1230. k:=0;
  1231. done:=[];
  1232. adj:=igraph.adjlist[u];
  1233. if adj<>nil then
  1234. for i:=1 to length(adj^) do
  1235. begin
  1236. n:=adj^[i];
  1237. if (pos(n,selectstack) or pos(n,coalescednodes))=0 then
  1238. begin
  1239. include(done,n);
  1240. if degree[Tsuperregister(n)]>=cpu_registers then
  1241. inc(k);
  1242. end;
  1243. end;
  1244. adj:=igraph.adjlist[v];
  1245. if adj<>nil then
  1246. for i:=1 to length(adj^) do
  1247. begin
  1248. n:=adj^[i];
  1249. if ((pos(n,selectstack) or pos(n,coalescednodes))=0) and
  1250. not (n in done) and
  1251. (degree[Tsuperregister(n)]>=cpu_registers) then
  1252. inc(k);
  1253. end;
  1254. conservative:=(k<cpu_registers);
  1255. end;
  1256. procedure Trgobj.combine(u,v:Tsuperregister);
  1257. var add:boolean;
  1258. adj:Pstring;
  1259. i,p:byte;
  1260. n,o:cardinal;
  1261. t:char;
  1262. decrement:boolean;
  1263. begin
  1264. p:=pos(char(v),freezeworklist);
  1265. if p<>0 then
  1266. delete(freezeworklist,p,1)
  1267. else
  1268. delete(spillworklist,pos(char(v),spillworklist),1);
  1269. coalescednodes:=coalescednodes+char(v);
  1270. alias[v]:=u;
  1271. {Combine both movelists. Since the movelists are sets, only add
  1272. elements that are not already present.}
  1273. for n:=0 to movelist[v]^.count-1 do
  1274. begin
  1275. add:=true;
  1276. for o:=0 to movelist[u]^.count-1 do
  1277. if movelist[u]^.data[o]=movelist[v]^.data[n] then
  1278. begin
  1279. add:=false;
  1280. break;
  1281. end;
  1282. if add then
  1283. add_to_movelist(u,movelist[v]^.data[n]);
  1284. end;
  1285. enable_moves(v);
  1286. adj:=igraph.adjlist[v];
  1287. if adj<>nil then
  1288. for i:=1 to length(adj^) do
  1289. begin
  1290. t:=adj^[i];
  1291. if (pos(t,selectstack) or pos(t,coalescednodes))=0 then
  1292. begin
  1293. decrement:=(Tsuperregister(t)<>u) and not(u in igraph.bitmap[Tsuperregister(t)]);
  1294. add_edge(Tsuperregister(t),u);
  1295. {Do not call decrement_degree because it might move nodes between
  1296. lists while the degree does not change (add_edge will increase it).
  1297. Instead, we will decrement manually. (Only if the degree has been
  1298. increased.)}
  1299. if decrement and not (Tsuperregister(t) in [first_int_supreg..last_int_supreg])
  1300. and (degree[Tsuperregister(t)]>0) then
  1301. dec(degree[Tsuperregister(t)]);
  1302. end;
  1303. end;
  1304. p:=pos(char(u),freezeworklist);
  1305. if (degree[u]>=cpu_registers) and (p<>0) then
  1306. begin
  1307. delete(freezeworklist,p,1);
  1308. spillworklist:=spillworklist+char(u);
  1309. end;
  1310. end;
  1311. procedure Trgobj.coalesce;
  1312. var m:Tmoveins;
  1313. x,y,u,v:Tsuperregister;
  1314. begin
  1315. m:=Tmoveins(worklist_moves.getfirst);
  1316. x:=get_alias(getsupreg(m.instruction.oper[0].reg));
  1317. y:=get_alias(getsupreg(m.instruction.oper[1].reg));
  1318. if y in [first_int_supreg..last_int_supreg] then
  1319. begin
  1320. u:=y;
  1321. v:=x;
  1322. end
  1323. else
  1324. begin
  1325. u:=x;
  1326. v:=y;
  1327. end;
  1328. if (u=v) then
  1329. begin
  1330. m.moveset:=ms_coalesced_moves; {Already coalesced.}
  1331. coalesced_moves.insert(m);
  1332. add_worklist(u);
  1333. end
  1334. {Do u and v interfere? In that case the move is constrained. Two
  1335. precoloured nodes interfere allways. If v is precoloured, by the above
  1336. code u is precoloured, thus interference...}
  1337. else if (v in [first_int_supreg..last_int_supreg]) or (u in igraph.bitmap[v]) then
  1338. begin
  1339. m.moveset:=ms_constrained_moves; {Cannot coalesce yet...}
  1340. constrained_moves.insert(m);
  1341. add_worklist(u);
  1342. add_worklist(v);
  1343. end
  1344. {Next test: is it possible and a good idea to coalesce??}
  1345. else if ((u in [first_int_supreg..last_int_supreg]) and adjacent_ok(u,v)) or
  1346. (not(u in [first_int_supreg..last_int_supreg]) and conservative(u,v)) then
  1347. begin
  1348. m.moveset:=ms_coalesced_moves; {Move coalesced!}
  1349. coalesced_moves.insert(m);
  1350. combine(u,v);
  1351. add_worklist(u);
  1352. end
  1353. else
  1354. begin
  1355. m.moveset:=ms_active_moves;
  1356. active_moves.insert(m);
  1357. end;
  1358. end;
  1359. procedure Trgobj.freeze_moves(u:Tsuperregister);
  1360. var i:cardinal;
  1361. m:Tlinkedlistitem;
  1362. v,x,y:Tsuperregister;
  1363. begin
  1364. if movelist[u]<>nil then
  1365. for i:=0 to movelist[u]^.count-1 do
  1366. begin
  1367. m:=movelist[u]^.data[i];
  1368. if Tmoveins(m).moveset in [ms_worklist_moves,ms_active_moves] then
  1369. begin
  1370. x:=getsupreg(Tmoveins(m).instruction.oper[0].reg);
  1371. y:=getsupreg(Tmoveins(m).instruction.oper[1].reg);
  1372. if get_alias(y)=get_alias(u) then
  1373. v:=get_alias(x)
  1374. else
  1375. v:=get_alias(y);
  1376. {Move m from active_moves/worklist_moves to frozen_moves.}
  1377. if Tmoveins(m).moveset=ms_active_moves then
  1378. active_moves.remove(m)
  1379. else
  1380. worklist_moves.remove(m);
  1381. Tmoveins(m).moveset:=ms_frozen_moves;
  1382. frozen_moves.insert(m);
  1383. if not(move_related(v)) and (degree[v]<cpu_registers) then
  1384. begin
  1385. delete(freezeworklist,pos(char(v),freezeworklist),1);
  1386. simplifyworklist:=simplifyworklist+char(v);
  1387. end;
  1388. end;
  1389. end;
  1390. end;
  1391. procedure Trgobj.freeze;
  1392. var n:Tsuperregister;
  1393. begin
  1394. {We need to take a random element out of the freezeworklist. We take
  1395. the last element. Dirty code!}
  1396. n:=Tsuperregister(freezeworklist[byte(freezeworklist[0])]);
  1397. dec(freezeworklist[0]);
  1398. {Add it to the simplifyworklist.}
  1399. simplifyworklist:=simplifyworklist+char(n);
  1400. freeze_moves(n);
  1401. end;
  1402. procedure Trgobj.select_spill;
  1403. var n:char;
  1404. begin
  1405. {This code is WAY too naive. We need not to select just a register, but
  1406. the register that is used the least...}
  1407. n:=spillworklist[byte(spillworklist[0])];
  1408. dec(spillworklist[0]);
  1409. simplifyworklist:=simplifyworklist+n;
  1410. freeze_moves(Tsuperregister(n));
  1411. end;
  1412. procedure Trgobj.assign_colours;
  1413. {Assign_colours assigns the actual colours to the registers.}
  1414. var adj:Pstring;
  1415. i,j,k:byte;
  1416. n,a:Tsuperregister;
  1417. adj_colours,colourednodes:set of Tsuperregister;
  1418. w:char;
  1419. begin
  1420. spillednodes:='';
  1421. {Colour the cpu registers...}
  1422. colourednodes:=[first_int_supreg..last_int_supreg];
  1423. for i:=first_int_supreg to last_int_supreg do
  1424. colour[i]:=i;
  1425. {Now colour the imaginary registers on the select-stack.}
  1426. for i:=length(selectstack) downto 1 do
  1427. begin
  1428. n:=Tsuperregister(selectstack[i]);
  1429. {Create a list of colours that we cannot assign to n.}
  1430. adj_colours:=[];
  1431. adj:=igraph.adjlist[n];
  1432. if adj<>nil then
  1433. for j:=1 to length(adj^) do
  1434. begin
  1435. w:=adj^[j];
  1436. a:=get_alias(Tsuperregister(w));
  1437. if a in colourednodes then
  1438. include(adj_colours,colour[a]);
  1439. end;
  1440. include(adj_colours,RS_STACK_POINTER_REG);
  1441. {Assume a spill by default...}
  1442. spillednodes:=spillednodes+char(n);
  1443. {Search for a colour not in this list.}
  1444. for k:=first_int_supreg to last_int_supreg do
  1445. if not(k in adj_colours) then
  1446. begin
  1447. colour[n]:=k;
  1448. dec(spillednodes[0]); {Colour found: no spill.}
  1449. include(colourednodes,n);
  1450. if n in used_in_proc_int then
  1451. include(used_in_proc_int,k);
  1452. break;
  1453. end;
  1454. end;
  1455. {Finally colour the nodes that were coalesced.}
  1456. for i:=1 to length(coalescednodes) do
  1457. begin
  1458. n:=Tsuperregister(coalescednodes[i]);
  1459. k:=get_alias(n);
  1460. colour[n]:=colour[k];
  1461. if n in used_in_proc_int then
  1462. include(used_in_proc_int,colour[k]);
  1463. end;
  1464. { registers which aren't available to the register allocator must }
  1465. { retain their value }
  1466. { for i := 1 to first_int_supreg-1 do
  1467. colour[i] := i;}
  1468. {$ifdef ra_debug}
  1469. for i:=first_int_imreg to maxintreg do
  1470. writeln(i:4,' ',colour[i]:4)
  1471. {$endif ra_debug}
  1472. end;
  1473. procedure Trgobj.colour_registers;
  1474. begin
  1475. repeat
  1476. if length(simplifyworklist)<>0 then
  1477. simplify
  1478. else if not(worklist_moves.empty) then
  1479. coalesce
  1480. else if length(freezeworklist)<>0 then
  1481. freeze
  1482. else if length(spillworklist)<>0 then
  1483. select_spill;
  1484. until (length(simplifyworklist) or
  1485. byte(not(worklist_moves.empty)) or
  1486. length(freezeworklist) or
  1487. length(spillworklist)
  1488. )=0;
  1489. assign_colours;
  1490. end;
  1491. procedure Trgobj.epilogue_colouring;
  1492. {
  1493. procedure move_to_worklist_moves(list:Tlinkedlist);
  1494. var p:Tlinkedlistitem;
  1495. begin
  1496. p:=list.first;
  1497. while p<>nil do
  1498. begin
  1499. Tmoveins(p).moveset:=ms_worklist_moves;
  1500. p:=p.next;
  1501. end;
  1502. worklist_moves.concatlist(list);
  1503. end;
  1504. }
  1505. var i:Tsuperregister;
  1506. begin
  1507. worklist_moves.clear;
  1508. {$ifdef Principle_wrong_by_definition}
  1509. {Move everything back to worklist_moves.}
  1510. move_to_worklist_moves(active_moves);
  1511. move_to_worklist_moves(frozen_moves);
  1512. move_to_worklist_moves(coalesced_moves);
  1513. move_to_worklist_moves(constrained_moves);
  1514. {$endif Principle_wrong_by_definition}
  1515. active_moves.destroy;
  1516. active_moves:=nil;
  1517. frozen_moves.destroy;
  1518. frozen_moves:=nil;
  1519. coalesced_moves.destroy;
  1520. coalesced_moves:=nil;
  1521. constrained_moves.destroy;
  1522. constrained_moves:=nil;
  1523. for i:=0 to 255 do
  1524. if movelist[i]<>nil then
  1525. begin
  1526. dispose(movelist[i]);
  1527. movelist[i]:=0;
  1528. end;
  1529. end;
  1530. procedure Trgobj.clear_interferences(u:Tsuperregister);
  1531. {Remove node u from the interference graph and remove all collected
  1532. move instructions it is associated with.}
  1533. var i:byte;
  1534. j,k,count:cardinal;
  1535. v:Tsuperregister;
  1536. m,n:Tmoveins;
  1537. begin
  1538. if igraph.adjlist[u]<>nil then
  1539. begin
  1540. for i:=1 to length(igraph.adjlist[u]^) do
  1541. begin
  1542. v:=Tsuperregister(igraph.adjlist[u]^[i]);
  1543. {Remove (u,v) and (v,u) from bitmap.}
  1544. exclude(igraph.bitmap[u],v);
  1545. exclude(igraph.bitmap[v],u);
  1546. {Remove (v,u) from adjacency list.}
  1547. if igraph.adjlist[v]<>nil then
  1548. begin
  1549. delete(igraph.adjlist[v]^,pos(char(v),igraph.adjlist[v]^),1);
  1550. if length(igraph.adjlist[v]^)=0 then
  1551. begin
  1552. dispose(igraph.adjlist[v]);
  1553. igraph.adjlist[v]:=nil;
  1554. end;
  1555. end;
  1556. end;
  1557. {Remove ( u,* ) from adjacency list.}
  1558. dispose(igraph.adjlist[u]);
  1559. igraph.adjlist[u]:=nil;
  1560. end;
  1561. {$ifdef Principle_wrong_by_definition}
  1562. {Now remove the moves.}
  1563. if movelist[u]<>nil then
  1564. begin
  1565. for j:=0 to movelist[u]^.count-1 do
  1566. begin
  1567. m:=Tmoveins(movelist[u]^.data[j]);
  1568. {Get the other register of the move instruction.}
  1569. v:=m.instruction.oper[0].reg.number shr 8;
  1570. if v=u then
  1571. v:=m.instruction.oper[1].reg.number shr 8;
  1572. repeat
  1573. repeat
  1574. if (u<>v) and (movelist[v]<>nil) then
  1575. begin
  1576. {Remove the move from it's movelist.}
  1577. count:=movelist[v]^.count-1;
  1578. for k:=0 to count do
  1579. if m=movelist[v]^.data[k] then
  1580. begin
  1581. if k<>count then
  1582. movelist[v]^.data[k]:=movelist[v]^.data[count];
  1583. dec(movelist[v]^.count);
  1584. if count=0 then
  1585. begin
  1586. dispose(movelist[v]);
  1587. movelist[v]:=nil;
  1588. end;
  1589. break;
  1590. end;
  1591. end;
  1592. {The complexity is enourmous: the register might have been
  1593. coalesced. In that case it's movelists have been added to
  1594. it's coalescing alias. (DM)}
  1595. v:=alias[v];
  1596. until v=0;
  1597. {And also register u might have been coalesced.}
  1598. u:=alias[u];
  1599. until u=0;
  1600. case m.moveset of
  1601. ms_coalesced_moves:
  1602. coalesced_moves.remove(m);
  1603. ms_constrained_moves:
  1604. constrained_moves.remove(m);
  1605. ms_frozen_moves:
  1606. frozen_moves.remove(m);
  1607. ms_worklist_moves:
  1608. worklist_moves.remove(m);
  1609. ms_active_moves:
  1610. active_moves.remove(m);
  1611. end;
  1612. end;
  1613. dispose(movelist[u]);
  1614. movelist[u]:=nil;
  1615. end;
  1616. {$endif Principle_wrong_by_definition}
  1617. end;
  1618. procedure Trgobj.getregisterintinline(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister);
  1619. var i:Tsuperregister;
  1620. r:Tregister;
  1621. begin
  1622. if not (lastintreg in [first_int_imreg..last_int_imreg]) then
  1623. lastintreg:=first_int_imreg;
  1624. i:=lastintreg;
  1625. repeat
  1626. if i=last_int_imreg then
  1627. i:=first_int_imreg
  1628. else
  1629. inc(i);
  1630. if (i in unusedregsint) and (pos(char(i),abtlist)=0) then
  1631. begin
  1632. exclude(unusedregsint,i);
  1633. include(used_in_proc_int,i);
  1634. r:=newreg(R_INTREGISTER,i,subreg);
  1635. if position=nil then
  1636. list.insert(Tai_regalloc.alloc(r))
  1637. else
  1638. list.insertafter(Tai_regalloc.alloc(r),position);
  1639. result:=r;
  1640. lastintreg:=i;
  1641. if i>maxintreg then
  1642. maxintreg:=i;
  1643. add_edges_used(i);
  1644. add_constraints(result);
  1645. exit;
  1646. end;
  1647. until i=lastintreg;
  1648. internalerror(10);
  1649. end;
  1650. {In some cases we can get in big trouble. See this example:
  1651. ; register reg23d released
  1652. ; register eax allocated
  1653. ; register ebx allocated
  1654. ; register ecx allocated
  1655. ; register edx allocated
  1656. ; register esi allocated
  1657. ; register edi allocated
  1658. call [reg23d]
  1659. This code is ok, *except* when reg23d is spilled. In that case the
  1660. spilled would introduce a help register which can never get
  1661. allocated to a real register because it interferes with all of them.
  1662. To solve this we introduce the ABT ("avoid big trouble :)" ) registers.
  1663. If you allocate an ABT register you get a register that has less
  1664. than cpu_register interferences and will not be allocated ever again
  1665. by the normal register get procedures. In other words it is for sure it
  1666. will never get spilled.}
  1667. function Trgobj.getabtregisterint(list:Taasmoutput;size:Tcgsize):Tregister;
  1668. var i:Tsuperregister;
  1669. r:Tregister;
  1670. found:boolean;
  1671. begin
  1672. if not (lastintreg in [first_int_imreg..last_int_imreg]) then
  1673. lastintreg:=first_int_imreg;
  1674. found:=false;
  1675. for i:=1 to length(abtlist) do
  1676. if Tsuperregister(abtlist[i]) in unusedregsint then
  1677. begin
  1678. found:=true;
  1679. break;
  1680. end;
  1681. i:=lastintreg;
  1682. repeat
  1683. if i=last_int_imreg then
  1684. i:=first_int_imreg
  1685. else
  1686. inc(i);
  1687. if (i in unusedregsint) and ((igraph.adjlist[i]=nil) or (length(igraph.adjlist[i]^)<cpu_registers)) then
  1688. begin
  1689. found:=true;
  1690. break;
  1691. end;
  1692. until i=lastintreg;
  1693. if found then
  1694. begin
  1695. exclude(unusedregsint,i);
  1696. include(used_in_proc_int,i);
  1697. r:=newreg(R_INTREGISTER,i,cgsize2subreg(size));
  1698. list.concat(Tai_regalloc.alloc(r));
  1699. getabtregisterint:=r;
  1700. lastintreg:=i;
  1701. if i>maxintreg then
  1702. maxintreg:=i;
  1703. add_edges_used(i);
  1704. if pos(char(i),abtlist)=0 then
  1705. abtlist:=abtlist+char(i);
  1706. end
  1707. else
  1708. internalerror(10);
  1709. add_constraints(getabtregisterint);
  1710. end;
  1711. procedure Trgobj.ungetregisterintinline(list:Taasmoutput;position:Tai;r:Tregister);
  1712. var supreg:Tsuperregister;
  1713. begin
  1714. supreg:=getsupreg(r);
  1715. include(unusedregsint,supreg);
  1716. if position=nil then
  1717. list.insert(Tai_regalloc.dealloc(r))
  1718. else
  1719. list.insertafter(Tai_regalloc.dealloc(r),position);
  1720. add_edges_used(supreg);
  1721. end;
  1722. function Trgobj.spill_registers(list:Taasmoutput;const regs_to_spill:string):boolean;
  1723. {Returns true if any help registers have been used.}
  1724. var i:byte;
  1725. r:Tsuperregister;
  1726. p,q:Tai;
  1727. regs_to_spill_set:Tsuperregisterset;
  1728. spill_temps:^Tspill_temp_list;
  1729. supreg : tsuperregister;
  1730. begin
  1731. spill_registers:=false;
  1732. unusedregsint:=[0..255];
  1733. fillchar(degree,sizeof(degree),0);
  1734. {Precoloured nodes should have an infinite degree, which we can approach
  1735. by 255.}
  1736. for i:=first_int_supreg to last_int_supreg do
  1737. degree[i]:=255;
  1738. { exclude(unusedregsint,RS_STACK_POINTER_REG);}
  1739. if current_procinfo.framepointer=NR_FRAME_POINTER_REG then
  1740. {Make sure the register allocator won't allocate registers into ebp.}
  1741. exclude(unusedregsint,RS_FRAME_POINTER_REG);
  1742. new(spill_temps);
  1743. fillchar(spill_temps^,sizeof(spill_temps^),0);
  1744. regs_to_spill_set:=[];
  1745. for i:=1 to length(regs_to_spill) do
  1746. begin
  1747. {Alternative representation.}
  1748. include(regs_to_spill_set,Tsuperregister(regs_to_spill[i]));
  1749. {Clear all interferences of the spilled register.}
  1750. clear_interferences(Tsuperregister(regs_to_spill[i]));
  1751. {Get a temp for the spilled register.}
  1752. tg.gettemp(list,4,tt_noreuse,spill_temps^[Tsuperregister(regs_to_spill[i])]);
  1753. end;
  1754. p:=Tai(list.first);
  1755. while assigned(p) do
  1756. begin
  1757. case p.typ of
  1758. ait_regalloc:
  1759. begin
  1760. {A register allocation of a spilled register can be removed.}
  1761. supreg:=getsupreg(Tai_regalloc(p).reg);
  1762. if supreg in regs_to_spill_set then
  1763. begin
  1764. q:=p;
  1765. p:=Tai(p.next);
  1766. list.remove(q);
  1767. continue;
  1768. end
  1769. else
  1770. if Tai_regalloc(p).allocation then
  1771. exclude(unusedregsint,supreg)
  1772. else
  1773. include(unusedregsint,supreg);
  1774. end;
  1775. ait_instruction:
  1776. begin
  1777. if Taicpu_abstract(p).spill_registers(list,@getregisterintinline,
  1778. @ungetregisterintinline,
  1779. regs_to_spill_set,
  1780. unusedregsint,
  1781. spill_temps^) then
  1782. spill_registers:=true;
  1783. if Taicpu_abstract(p).is_move then
  1784. add_move_instruction(Taicpu(p));
  1785. end;
  1786. end;
  1787. p:=Tai(p.next);
  1788. end;
  1789. for i:=1 to length(regs_to_spill) do
  1790. begin
  1791. tg.ungettemp(list,spill_temps^[Tsuperregister(regs_to_spill[i])]);
  1792. end;
  1793. dispose(spill_temps);
  1794. end;
  1795. {****************************************************************************
  1796. TReference
  1797. ****************************************************************************}
  1798. procedure reference_reset(var ref : treference);
  1799. begin
  1800. FillChar(ref,sizeof(treference),0);
  1801. {$ifdef arm}
  1802. ref.signindex:=1;
  1803. {$endif arm}
  1804. end;
  1805. procedure reference_reset_old(var ref : treference);
  1806. begin
  1807. FillChar(ref,sizeof(treference),0);
  1808. end;
  1809. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  1810. begin
  1811. reference_reset(ref);
  1812. ref.base:=base;
  1813. ref.offset:=offset;
  1814. end;
  1815. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  1816. begin
  1817. reference_reset(ref);
  1818. ref.symbol:=sym;
  1819. ref.offset:=offset;
  1820. end;
  1821. procedure reference_release(list: taasmoutput; const ref : treference);
  1822. begin
  1823. rg.ungetreference(list,ref);
  1824. end;
  1825. function references_equal(sref : treference;dref : treference):boolean;
  1826. begin
  1827. references_equal:=CompareByte(sref,dref,sizeof(treference))=0;
  1828. end;
  1829. { on most processors , this routine does nothing, overriden currently }
  1830. { only by 80x86 processor. }
  1831. function trgobj.makeregsize(reg: tregister; size: tcgsize): tregister;
  1832. begin
  1833. makeregsize := reg;
  1834. end;
  1835. {****************************************************************************
  1836. TLocation
  1837. ****************************************************************************}
  1838. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  1839. begin
  1840. FillChar(l,sizeof(tlocation),0);
  1841. l.loc:=lt;
  1842. l.size:=lsize;
  1843. {$ifdef arm}
  1844. if l.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  1845. l.reference.signindex:=1;
  1846. {$endif arm}
  1847. end;
  1848. procedure location_release(list: taasmoutput; const l : tlocation);
  1849. begin
  1850. case l.loc of
  1851. LOC_REGISTER,LOC_CREGISTER :
  1852. begin
  1853. rg.ungetregisterint(list,l.register);
  1854. if l.size in [OS_64,OS_S64] then
  1855. rg.ungetregisterint(list,l.registerhigh);
  1856. end;
  1857. LOC_FPUREGISTER,LOC_CFPUREGISTER :
  1858. rg.ungetregisterfpu(list,l.register,l.size);
  1859. LOC_CREFERENCE,LOC_REFERENCE :
  1860. rg.ungetreference(list, l.reference);
  1861. end;
  1862. end;
  1863. procedure location_freetemp(list:taasmoutput; const l : tlocation);
  1864. begin
  1865. if (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1866. tg.ungetiftemp(list,l.reference);
  1867. end;
  1868. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  1869. begin
  1870. destloc:=sourceloc;
  1871. end;
  1872. procedure location_swap(var destloc,sourceloc : tlocation);
  1873. var
  1874. swapl : tlocation;
  1875. begin
  1876. swapl := destloc;
  1877. destloc := sourceloc;
  1878. sourceloc := swapl;
  1879. end;
  1880. initialization
  1881. ;
  1882. finalization
  1883. rg.free;
  1884. end.
  1885. {
  1886. $Log$
  1887. Revision 1.69 2003-09-03 15:55:01 peter
  1888. * NEWRA branch merged
  1889. Revision 1.68 2003/09/03 11:18:37 florian
  1890. * fixed arm concatcopy
  1891. + arm support in the common compiler sources added
  1892. * moved some generic cg code around
  1893. + tfputype added
  1894. * ...
  1895. Revision 1.67.2.5 2003/08/31 20:44:07 peter
  1896. * fixed getexplicitregisterint tregister value
  1897. Revision 1.67.2.4 2003/08/31 20:40:50 daniel
  1898. * Fixed add_edges_used
  1899. Revision 1.67.2.3 2003/08/29 17:28:59 peter
  1900. * next batch of updates
  1901. Revision 1.67.2.2 2003/08/28 18:35:08 peter
  1902. * tregister changed to cardinal
  1903. Revision 1.67.2.1 2003/08/27 19:55:54 peter
  1904. * first tregister patch
  1905. Revision 1.67 2003/08/23 10:46:21 daniel
  1906. * Register allocator bugfix for h2pas
  1907. Revision 1.66 2003/08/17 16:59:20 jonas
  1908. * fixed regvars so they work with newra (at least for ppc)
  1909. * fixed some volatile register bugs
  1910. + -dnotranslation option for -dnewra, which causes the registers not to
  1911. be translated from virtual to normal registers. Requires support in
  1912. the assembler writer as well, which is only implemented in aggas/
  1913. agppcgas currently
  1914. Revision 1.65 2003/08/17 14:32:48 daniel
  1915. * Precoloured nodes now have an infinite degree approached with 255,
  1916. like they should.
  1917. Revision 1.64 2003/08/17 08:48:02 daniel
  1918. * Another register allocator bug fixed.
  1919. * cpu_registers set to 6 for i386
  1920. Revision 1.63 2003/08/09 18:56:54 daniel
  1921. * cs_regalloc renamed to cs_regvars to avoid confusion with register
  1922. allocator
  1923. * Some preventive changes to i386 spillinh code
  1924. Revision 1.62 2003/08/03 14:09:50 daniel
  1925. * Fixed a register allocator bug
  1926. * Figured out why -dnewra generates superfluous "mov reg1,reg2"
  1927. statements: changes in location_force. These moves are now no longer
  1928. constrained so they are optimized away.
  1929. Revision 1.61 2003/07/21 13:32:39 jonas
  1930. * add_edges_used() is now also called for registers allocated with
  1931. getexplicitregisterint()
  1932. * writing the intereference graph is now only done with -dradebug2 and
  1933. the created files are now called "igraph.<module_name>"
  1934. Revision 1.60 2003/07/06 15:31:21 daniel
  1935. * Fixed register allocator. *Lots* of fixes.
  1936. Revision 1.59 2003/07/06 15:00:47 jonas
  1937. * fixed my previous completely broken commit. It's not perfect though,
  1938. registers > last_int_supreg and < max_intreg may still be "translated"
  1939. Revision 1.58 2003/07/06 14:45:05 jonas
  1940. * support integer registers that are not managed by newra (ie. don't
  1941. translate register numbers that fall outside the range
  1942. first_int_supreg..last_int_supreg)
  1943. Revision 1.57 2003/07/02 22:18:04 peter
  1944. * paraloc splitted in callerparaloc,calleeparaloc
  1945. * sparc calling convention updates
  1946. Revision 1.56 2003/06/17 16:34:44 jonas
  1947. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  1948. * renamed all_intregisters to volatile_intregisters and made it
  1949. processor dependent
  1950. Revision 1.55 2003/06/14 14:53:50 jonas
  1951. * fixed newra cycle for x86
  1952. * added constants for indicating source and destination operands of the
  1953. "move reg,reg" instruction to aasmcpu (and use those in rgobj)
  1954. Revision 1.54 2003/06/13 21:19:31 peter
  1955. * current_procdef removed, use current_procinfo.procdef instead
  1956. Revision 1.53 2003/06/12 21:11:10 peter
  1957. * ungetregisterfpu gets size parameter
  1958. Revision 1.52 2003/06/12 16:43:07 peter
  1959. * newra compiles for sparc
  1960. Revision 1.51 2003/06/09 14:54:26 jonas
  1961. * (de)allocation of registers for parameters is now performed properly
  1962. (and checked on the ppc)
  1963. - removed obsolete allocation of all parameter registers at the start
  1964. of a procedure (and deallocation at the end)
  1965. Revision 1.50 2003/06/03 21:11:09 peter
  1966. * cg.a_load_* get a from and to size specifier
  1967. * makeregsize only accepts newregister
  1968. * i386 uses generic tcgnotnode,tcgunaryminus
  1969. Revision 1.49 2003/06/03 13:01:59 daniel
  1970. * Register allocator finished
  1971. Revision 1.48 2003/06/01 21:38:06 peter
  1972. * getregisterfpu size parameter added
  1973. * op_const_reg size parameter added
  1974. * sparc updates
  1975. Revision 1.47 2003/05/31 20:31:11 jonas
  1976. * set inital costs of assigning a variable to a register to 120 for
  1977. non-i386, because the used register must be store to memory at the
  1978. start and loaded again at the end
  1979. Revision 1.46 2003/05/30 18:55:21 jonas
  1980. * fixed several regvar related bugs for non-i386. make cycle with -Or now
  1981. works for ppc
  1982. Revision 1.45 2003/05/30 12:36:13 jonas
  1983. * use as little different registers on the ppc until newra is released,
  1984. since every used register must be saved
  1985. Revision 1.44 2003/05/17 13:30:08 jonas
  1986. * changed tt_persistant to tt_persistent :)
  1987. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1988. temps, but a ttemptype, so you can also create ansistring temps etc
  1989. Revision 1.43 2003/05/16 14:33:31 peter
  1990. * regvar fixes
  1991. Revision 1.42 2003/04/26 20:03:49 daniel
  1992. * Bug fix in simplify
  1993. Revision 1.41 2003/04/25 20:59:35 peter
  1994. * removed funcretn,funcretsym, function result is now in varsym
  1995. and aliases for result and function name are added using absolutesym
  1996. * vs_hidden parameter for funcret passed in parameter
  1997. * vs_hidden fixes
  1998. * writenode changed to printnode and released from extdebug
  1999. * -vp option added to generate a tree.log with the nodetree
  2000. * nicer printnode for statements, callnode
  2001. Revision 1.40 2003/04/25 08:25:26 daniel
  2002. * Ifdefs around a lot of calls to cleartempgen
  2003. * Fixed registers that are allocated but not freed in several nodes
  2004. * Tweak to register allocator to cause less spills
  2005. * 8-bit registers now interfere with esi,edi and ebp
  2006. Compiler can now compile rtl successfully when using new register
  2007. allocator
  2008. Revision 1.39 2003/04/23 20:23:06 peter
  2009. * compile fix for no-newra
  2010. Revision 1.38 2003/04/23 14:42:07 daniel
  2011. * Further register allocator work. Compiler now smaller with new
  2012. allocator than without.
  2013. * Somebody forgot to adjust ppu version number
  2014. Revision 1.37 2003/04/22 23:50:23 peter
  2015. * firstpass uses expectloc
  2016. * checks if there are differences between the expectloc and
  2017. location.loc from secondpass in EXTDEBUG
  2018. Revision 1.36 2003/04/22 10:09:35 daniel
  2019. + Implemented the actual register allocator
  2020. + Scratch registers unavailable when new register allocator used
  2021. + maybe_save/maybe_restore unavailable when new register allocator used
  2022. Revision 1.35 2003/04/21 19:16:49 peter
  2023. * count address regs separate
  2024. Revision 1.34 2003/04/17 16:48:21 daniel
  2025. * Added some code to keep track of move instructions in register
  2026. allocator
  2027. Revision 1.33 2003/04/17 07:50:24 daniel
  2028. * Some work on interference graph construction
  2029. Revision 1.32 2003/03/28 19:16:57 peter
  2030. * generic constructor working for i386
  2031. * remove fixed self register
  2032. * esi added as address register for i386
  2033. Revision 1.31 2003/03/11 21:46:24 jonas
  2034. * lots of new regallocator fixes, both in generic and ppc-specific code
  2035. (ppc compiler still can't compile the linux system unit though)
  2036. Revision 1.30 2003/03/09 21:18:59 olle
  2037. + added cutils to the uses clause
  2038. Revision 1.29 2003/03/08 20:36:41 daniel
  2039. + Added newra version of Ti386shlshrnode
  2040. + Added interference graph construction code
  2041. Revision 1.28 2003/03/08 13:59:16 daniel
  2042. * Work to handle new register notation in ag386nsm
  2043. + Added newra version of Ti386moddivnode
  2044. Revision 1.27 2003/03/08 10:53:48 daniel
  2045. * Created newra version of secondmul in n386add.pas
  2046. Revision 1.26 2003/03/08 08:59:07 daniel
  2047. + $define newra will enable new register allocator
  2048. + getregisterint will return imaginary registers with $newra
  2049. + -sr switch added, will skip register allocation so you can see
  2050. the direct output of the code generator before register allocation
  2051. Revision 1.25 2003/02/26 20:50:45 daniel
  2052. * Fixed ungetreference
  2053. Revision 1.24 2003/02/19 22:39:56 daniel
  2054. * Fixed a few issues
  2055. Revision 1.23 2003/02/19 22:00:14 daniel
  2056. * Code generator converted to new register notation
  2057. - Horribily outdated todo.txt removed
  2058. Revision 1.22 2003/02/02 19:25:54 carl
  2059. * Several bugfixes for m68k target (register alloc., opcode emission)
  2060. + VIS target
  2061. + Generic add more complete (still not verified)
  2062. Revision 1.21 2003/01/08 18:43:57 daniel
  2063. * Tregister changed into a record
  2064. Revision 1.20 2002/10/05 12:43:28 carl
  2065. * fixes for Delphi 6 compilation
  2066. (warning : Some features do not work under Delphi)
  2067. Revision 1.19 2002/08/23 16:14:49 peter
  2068. * tempgen cleanup
  2069. * tt_noreuse temp type added that will be used in genentrycode
  2070. Revision 1.18 2002/08/17 22:09:47 florian
  2071. * result type handling in tcgcal.pass_2 overhauled
  2072. * better tnode.dowrite
  2073. * some ppc stuff fixed
  2074. Revision 1.17 2002/08/17 09:23:42 florian
  2075. * first part of procinfo rewrite
  2076. Revision 1.16 2002/08/06 20:55:23 florian
  2077. * first part of ppc calling conventions fix
  2078. Revision 1.15 2002/08/05 18:27:48 carl
  2079. + more more more documentation
  2080. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  2081. Revision 1.14 2002/08/04 19:06:41 carl
  2082. + added generic exception support (still does not work!)
  2083. + more documentation
  2084. Revision 1.13 2002/07/07 09:52:32 florian
  2085. * powerpc target fixed, very simple units can be compiled
  2086. * some basic stuff for better callparanode handling, far from being finished
  2087. Revision 1.12 2002/07/01 18:46:26 peter
  2088. * internal linker
  2089. * reorganized aasm layer
  2090. Revision 1.11 2002/05/18 13:34:17 peter
  2091. * readded missing revisions
  2092. Revision 1.10 2002/05/16 19:46:44 carl
  2093. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2094. + try to fix temp allocation (still in ifdef)
  2095. + generic constructor calls
  2096. + start of tassembler / tmodulebase class cleanup
  2097. Revision 1.8 2002/04/21 15:23:03 carl
  2098. + makeregsize
  2099. + changeregsize is now a local routine
  2100. Revision 1.7 2002/04/20 21:32:25 carl
  2101. + generic FPC_CHECKPOINTER
  2102. + first parameter offset in stack now portable
  2103. * rename some constants
  2104. + move some cpu stuff to other units
  2105. - remove unused constents
  2106. * fix stacksize for some targets
  2107. * fix generic size problems which depend now on EXTEND_SIZE constant
  2108. Revision 1.6 2002/04/15 19:03:31 carl
  2109. + reg2str -> std_reg2str()
  2110. Revision 1.5 2002/04/06 18:13:01 jonas
  2111. * several powerpc-related additions and fixes
  2112. Revision 1.4 2002/04/04 19:06:04 peter
  2113. * removed unused units
  2114. * use tlocation.size in cg.a_*loc*() routines
  2115. Revision 1.3 2002/04/02 17:11:29 peter
  2116. * tlocation,treference update
  2117. * LOC_CONSTANT added for better constant handling
  2118. * secondadd splitted in multiple routines
  2119. * location_force_reg added for loading a location to a register
  2120. of a specified size
  2121. * secondassignment parses now first the right and then the left node
  2122. (this is compatible with Kylix). This saves a lot of push/pop especially
  2123. with string operations
  2124. * adapted some routines to use the new cg methods
  2125. Revision 1.2 2002/04/01 19:24:25 jonas
  2126. * fixed different parameter name in interface and implementation
  2127. declaration of a method (only 1.0.x detected this)
  2128. Revision 1.1 2002/03/31 20:26:36 jonas
  2129. + a_loadfpu_* and a_loadmm_* methods in tcg
  2130. * register allocation is now handled by a class and is mostly processor
  2131. independent (+rgobj.pas and i386/rgcpu.pas)
  2132. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  2133. * some small improvements and fixes to the optimizer
  2134. * some register allocation fixes
  2135. * some fpuvaroffset fixes in the unary minus node
  2136. * push/popusedregisters is now called rg.save/restoreusedregisters and
  2137. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  2138. also better optimizable)
  2139. * fixed and optimized register saving/restoring for new/dispose nodes
  2140. * LOC_FPU locations now also require their "register" field to be set to
  2141. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  2142. - list field removed of the tnode class because it's not used currently
  2143. and can cause hard-to-find bugs
  2144. }