rgobj.pas 87 KB

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