rgobj.pas 85 KB

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