rgobj.pas 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092
  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. unit rgobj;
  22. interface
  23. uses
  24. cutils, cpubase,
  25. aasmbase,aasmtai,aasmcpu,
  26. cclasses,globtype,cgbase,cgutils,
  27. cpuinfo
  28. ;
  29. type
  30. {
  31. regvarother_longintarray = array[tregisterindex] of longint;
  32. regvarother_booleanarray = array[tregisterindex] of boolean;
  33. regvarint_longintarray = array[first_int_supreg..last_int_supreg] of longint;
  34. regvarint_ptreearray = array[first_int_supreg..last_int_supreg] of tnode;
  35. }
  36. {
  37. The interference bitmap contains of 2 layers:
  38. layer 1 - 256*256 blocks with pointers to layer 2 blocks
  39. layer 2 - blocks of 32*256 (32 bytes = 256 bits)
  40. }
  41. Tinterferencebitmap2 = array[byte] of set of byte;
  42. Pinterferencebitmap2 = ^Tinterferencebitmap2;
  43. Tinterferencebitmap1 = array[byte] of Pinterferencebitmap2;
  44. pinterferencebitmap1 = ^tinterferencebitmap1;
  45. Tinterferencebitmap=class
  46. private
  47. maxx1,
  48. maxy1 : byte;
  49. fbitmap : pinterferencebitmap1;
  50. function getbitmap(x,y:tsuperregister):boolean;
  51. procedure setbitmap(x,y:tsuperregister;b:boolean);
  52. public
  53. constructor create;
  54. destructor destroy;override;
  55. property bitmap[x,y:tsuperregister]:boolean read getbitmap write setbitmap;default;
  56. end;
  57. Tmovelistheader=record
  58. count,
  59. maxcount,
  60. sorted_until : cardinal;
  61. end;
  62. Tmovelist=record
  63. header : Tmovelistheader;
  64. data : array[tsuperregister] of Tlinkedlistitem;
  65. end;
  66. Pmovelist=^Tmovelist;
  67. {In the register allocator we keep track of move instructions.
  68. These instructions are moved between five linked lists. There
  69. is also a linked list per register to keep track about the moves
  70. it is associated with. Because we need to determine quickly in
  71. which of the five lists it is we add anu enumeradtion to each
  72. move instruction.}
  73. Tmoveset=(ms_coalesced_moves,ms_constrained_moves,ms_frozen_moves,
  74. ms_worklist_moves,ms_active_moves);
  75. Tmoveins=class(Tlinkedlistitem)
  76. moveset:Tmoveset;
  77. x,y:Tsuperregister;
  78. end;
  79. Treginfoflag=(ri_coalesced,ri_selected);
  80. Treginfoflagset=set of Treginfoflag;
  81. Treginfo=record
  82. live_start,
  83. live_end : Tai;
  84. subreg : tsubregister;
  85. alias : Tsuperregister;
  86. { The register allocator assigns each register a colour }
  87. colour : Tsuperregister;
  88. movelist : Pmovelist;
  89. adjlist : Psuperregisterworklist;
  90. degree : TSuperregister;
  91. flags : Treginfoflagset;
  92. end;
  93. Preginfo=^TReginfo;
  94. tspillreginfo = record
  95. spillreg : tregister;
  96. orgreg : tsuperregister;
  97. tempreg : tregister;
  98. regread,regwritten, mustbespilled: boolean;
  99. end;
  100. tspillregsinfo = array[0..2] of tspillreginfo;
  101. {#------------------------------------------------------------------
  102. This class implements the default register allocator. It is used by the
  103. code generator to allocate and free registers which might be valid
  104. across nodes. It also contains utility routines related to registers.
  105. Some of the methods in this class should be overriden
  106. by cpu-specific implementations.
  107. --------------------------------------------------------------------}
  108. trgobj=class
  109. preserved_by_proc : tcpuregisterset;
  110. used_in_proc : tcpuregisterset;
  111. constructor create(Aregtype:Tregistertype;
  112. Adefaultsub:Tsubregister;
  113. const Ausable:array of tsuperregister;
  114. Afirst_imaginary:Tsuperregister;
  115. Apreserved_by_proc:Tcpuregisterset);
  116. destructor destroy;override;
  117. {# Allocate a register. An internalerror will be generated if there is
  118. no more free registers which can be allocated.}
  119. function getregister(list:Taasmoutput;subreg:Tsubregister):Tregister;virtual;
  120. {# Get the register specified.}
  121. procedure getcpuregister(list:Taasmoutput;r:Tregister);virtual;
  122. procedure ungetcpuregister(list:Taasmoutput;r:Tregister);virtual;
  123. {# Get multiple registers specified.}
  124. procedure alloccpuregisters(list:Taasmoutput;r:Tcpuregisterset);virtual;
  125. {# Free multiple registers specified.}
  126. procedure dealloccpuregisters(list:Taasmoutput;r:Tcpuregisterset);virtual;
  127. function uses_registers:boolean;virtual;
  128. procedure add_reg_instruction(instr:Tai;r:tregister);
  129. procedure add_move_instruction(instr:Taicpu);
  130. {# Do the register allocation.}
  131. procedure do_register_allocation(list:Taasmoutput;headertai:tai);virtual;
  132. { Adds an interference edge.
  133. don't move this to the protected section, the arm cg requires to access this (FK) }
  134. procedure add_edge(u,v:Tsuperregister);
  135. protected
  136. regtype : Tregistertype;
  137. { default subregister used }
  138. defaultsub : tsubregister;
  139. live_registers:Tsuperregisterworklist;
  140. { can be overriden to add cpu specific interferences }
  141. procedure add_cpu_interferences(p : tai);virtual;
  142. procedure add_constraints(reg:Tregister);virtual;
  143. function getregisterinline(list:Taasmoutput;subreg:Tsubregister):Tregister;
  144. procedure ungetregisterinline(list:Taasmoutput;r:Tregister);
  145. function get_spill_subreg(r : tregister) : tsubregister;virtual;
  146. function do_spill_replace(list:Taasmoutput;instr:taicpu;orgreg:tsuperregister;const spilltemp:treference):boolean;virtual;
  147. procedure do_spill_read(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);virtual;
  148. procedure do_spill_written(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);virtual;
  149. function instr_spill_register(list:Taasmoutput;
  150. instr:taicpu;
  151. const r:Tsuperregisterset;
  152. const spilltemplist:Tspill_temp_list): boolean;virtual;
  153. private
  154. {# First imaginary register.}
  155. first_imaginary : Tsuperregister;
  156. {# Highest register allocated until now.}
  157. reginfo : PReginfo;
  158. maxreginfo,
  159. maxreginfoinc,
  160. maxreg : Tsuperregister;
  161. usable_registers_cnt : word;
  162. usable_registers : array[0..maxcpuregister-1] of tsuperregister;
  163. ibitmap : Tinterferencebitmap;
  164. spillednodes,
  165. simplifyworklist,
  166. freezeworklist,
  167. spillworklist,
  168. coalescednodes,
  169. selectstack : tsuperregisterworklist;
  170. worklist_moves,
  171. active_moves,
  172. frozen_moves,
  173. coalesced_moves,
  174. constrained_moves : Tlinkedlist;
  175. {$ifdef EXTDEBUG}
  176. procedure writegraph(loopidx:longint);
  177. {$endif EXTDEBUG}
  178. {# Disposes of the reginfo array.}
  179. procedure dispose_reginfo;
  180. {# Prepare the register colouring.}
  181. procedure prepare_colouring;
  182. {# Clean up after register colouring.}
  183. procedure epilogue_colouring;
  184. {# Colour the registers; that is do the register allocation.}
  185. procedure colour_registers;
  186. procedure insert_regalloc_info(list:Taasmoutput;u:tsuperregister);
  187. procedure insert_regalloc_info_all(list:Taasmoutput);
  188. procedure generate_interference_graph(list:Taasmoutput;headertai:tai);
  189. procedure translate_registers(list:Taasmoutput);
  190. function spill_registers(list:Taasmoutput;headertai:tai):boolean;virtual;
  191. function getnewreg(subreg:tsubregister):tsuperregister;
  192. procedure add_edges_used(u:Tsuperregister);
  193. procedure add_to_movelist(u:Tsuperregister;data:Tlinkedlistitem);
  194. function move_related(n:Tsuperregister):boolean;
  195. procedure make_work_list;
  196. procedure sort_simplify_worklist;
  197. procedure enable_moves(n:Tsuperregister);
  198. procedure decrement_degree(m:Tsuperregister);
  199. procedure simplify;
  200. function get_alias(n:Tsuperregister):Tsuperregister;
  201. procedure add_worklist(u:Tsuperregister);
  202. function adjacent_ok(u,v:Tsuperregister):boolean;
  203. function conservative(u,v:Tsuperregister):boolean;
  204. procedure combine(u,v:Tsuperregister);
  205. procedure coalesce;
  206. procedure freeze_moves(u:Tsuperregister);
  207. procedure freeze;
  208. procedure select_spill;
  209. procedure assign_colours;
  210. procedure clear_interferences(u:Tsuperregister);
  211. end;
  212. const
  213. first_reg = 0;
  214. last_reg = high(tsuperregister)-1;
  215. maxspillingcounter = 20;
  216. implementation
  217. uses
  218. systems,
  219. globals,verbose,tgobj,procinfo;
  220. procedure sort_movelist(ml:Pmovelist);
  221. {Ok, sorting pointers is silly, but it does the job to make Trgobj.combine
  222. faster.}
  223. var h,i,p:word;
  224. t:Tlinkedlistitem;
  225. begin
  226. with ml^ do
  227. begin
  228. if header.count<2 then
  229. exit;
  230. p:=1;
  231. while 2*p<header.count do
  232. p:=2*p;
  233. while p<>0 do
  234. begin
  235. for h:=p to header.count-1 do
  236. begin
  237. i:=h;
  238. t:=data[i];
  239. repeat
  240. if ptrint(data[i-p])<=ptrint(t) then
  241. break;
  242. data[i]:=data[i-p];
  243. dec(i,p);
  244. until i<p;
  245. data[i]:=t;
  246. end;
  247. p:=p shr 1;
  248. end;
  249. header.sorted_until:=header.count-1;
  250. end;
  251. end;
  252. {******************************************************************************
  253. tinterferencebitmap
  254. ******************************************************************************}
  255. constructor tinterferencebitmap.create;
  256. begin
  257. inherited create;
  258. maxx1:=1;
  259. getmem(fbitmap,sizeof(tinterferencebitmap1)*2);
  260. fillchar(fbitmap^,sizeof(tinterferencebitmap1)*2,0);
  261. end;
  262. destructor tinterferencebitmap.destroy;
  263. var i,j:byte;
  264. begin
  265. for i:=0 to maxx1 do
  266. for j:=0 to maxy1 do
  267. if assigned(fbitmap[i,j]) then
  268. dispose(fbitmap[i,j]);
  269. freemem(fbitmap);
  270. end;
  271. function tinterferencebitmap.getbitmap(x,y:tsuperregister):boolean;
  272. var
  273. page : pinterferencebitmap2;
  274. begin
  275. result:=false;
  276. if (x shr 8>maxx1) then
  277. exit;
  278. page:=fbitmap[x shr 8,y shr 8];
  279. result:=assigned(page) and
  280. ((x and $ff) in page^[y and $ff]);
  281. end;
  282. procedure tinterferencebitmap.setbitmap(x,y:tsuperregister;b:boolean);
  283. var
  284. x1,y1 : byte;
  285. begin
  286. x1:=x shr 8;
  287. y1:=y shr 8;
  288. if x1>maxx1 then
  289. begin
  290. reallocmem(fbitmap,sizeof(tinterferencebitmap1)*(x1+1));
  291. fillchar(fbitmap[maxx1+1],sizeof(tinterferencebitmap1)*(x1-maxx1),0);
  292. maxx1:=x1;
  293. end;
  294. if not assigned(fbitmap[x1,y1]) then
  295. begin
  296. if y1>maxy1 then
  297. maxy1:=y1;
  298. new(fbitmap[x1,y1]);
  299. fillchar(fbitmap[x1,y1]^,sizeof(tinterferencebitmap2),0);
  300. end;
  301. if b then
  302. include(fbitmap[x1,y1]^[y and $ff],(x and $ff))
  303. else
  304. exclude(fbitmap[x1,y1]^[y and $ff],(x and $ff));
  305. end;
  306. {******************************************************************************
  307. trgobj
  308. ******************************************************************************}
  309. constructor trgobj.create(Aregtype:Tregistertype;
  310. Adefaultsub:Tsubregister;
  311. const Ausable:array of tsuperregister;
  312. Afirst_imaginary:Tsuperregister;
  313. Apreserved_by_proc:Tcpuregisterset);
  314. var
  315. i : Tsuperregister;
  316. begin
  317. { empty super register sets can cause very strange problems }
  318. if high(Ausable)=0 then
  319. internalerror(200210181);
  320. first_imaginary:=Afirst_imaginary;
  321. maxreg:=Afirst_imaginary;
  322. regtype:=Aregtype;
  323. defaultsub:=Adefaultsub;
  324. preserved_by_proc:=Apreserved_by_proc;
  325. used_in_proc:=[];
  326. live_registers.init;
  327. { Get reginfo for CPU registers }
  328. maxreginfo:=first_imaginary;
  329. maxreginfoinc:=16;
  330. worklist_moves:=Tlinkedlist.create;
  331. reginfo:=allocmem(first_imaginary*sizeof(treginfo));
  332. for i:=0 to first_imaginary-1 do
  333. begin
  334. reginfo[i].degree:=high(tsuperregister);
  335. reginfo[i].alias:=RS_INVALID;
  336. end;
  337. { Usable registers }
  338. fillchar(usable_registers,sizeof(usable_registers),0);
  339. for i:=low(Ausable) to high(Ausable) do
  340. usable_registers[i]:=Ausable[i];
  341. usable_registers_cnt:=high(Ausable)+1;
  342. { Initialize Worklists }
  343. spillednodes.init;
  344. simplifyworklist.init;
  345. freezeworklist.init;
  346. spillworklist.init;
  347. coalescednodes.init;
  348. selectstack.init;
  349. end;
  350. destructor trgobj.destroy;
  351. begin
  352. spillednodes.done;
  353. simplifyworklist.done;
  354. freezeworklist.done;
  355. spillworklist.done;
  356. coalescednodes.done;
  357. selectstack.done;
  358. live_registers.done;
  359. worklist_moves.free;
  360. dispose_reginfo;
  361. end;
  362. procedure Trgobj.dispose_reginfo;
  363. var i:Tsuperregister;
  364. begin
  365. if reginfo<>nil then
  366. begin
  367. for i:=0 to maxreg-1 do
  368. with reginfo[i] do
  369. begin
  370. if adjlist<>nil then
  371. dispose(adjlist,done);
  372. if movelist<>nil then
  373. dispose(movelist);
  374. end;
  375. freemem(reginfo);
  376. reginfo:=nil;
  377. end;
  378. end;
  379. function trgobj.getnewreg(subreg:tsubregister):tsuperregister;
  380. var
  381. oldmaxreginfo : tsuperregister;
  382. begin
  383. result:=maxreg;
  384. inc(maxreg);
  385. if maxreg>=last_reg then
  386. internalerror(200310146);
  387. if maxreg>=maxreginfo then
  388. begin
  389. oldmaxreginfo:=maxreginfo;
  390. inc(maxreginfo,maxreginfoinc);
  391. if maxreginfoinc<256 then
  392. maxreginfoinc:=maxreginfoinc*2;
  393. reallocmem(reginfo,maxreginfo*sizeof(treginfo));
  394. { Do we really need it to clear it ? At least for 1.0.x (PFV) }
  395. fillchar(reginfo[oldmaxreginfo],(maxreginfo-oldmaxreginfo)*sizeof(treginfo),0);
  396. end;
  397. reginfo[result].subreg:=subreg;
  398. end;
  399. function trgobj.getregister(list:Taasmoutput;subreg:Tsubregister):Tregister;
  400. begin
  401. {$ifdef EXTDEBUG}
  402. if reginfo=nil then
  403. InternalError(2004020901);
  404. {$endif EXTDEBUG}
  405. if defaultsub=R_SUBNONE then
  406. result:=newreg(regtype,getnewreg(R_SUBNONE),R_SUBNONE)
  407. else
  408. result:=newreg(regtype,getnewreg(subreg),subreg);
  409. end;
  410. function trgobj.uses_registers:boolean;
  411. begin
  412. result:=(maxreg>first_imaginary);
  413. end;
  414. procedure trgobj.ungetcpuregister(list:Taasmoutput;r:Tregister);
  415. begin
  416. if (getsupreg(r)>=first_imaginary) then
  417. InternalError(2004020901);
  418. list.concat(Tai_regalloc.dealloc(r,nil));
  419. end;
  420. procedure trgobj.getcpuregister(list:Taasmoutput;r:Tregister);
  421. var
  422. supreg:Tsuperregister;
  423. begin
  424. supreg:=getsupreg(r);
  425. if supreg>=first_imaginary then
  426. internalerror(2003121503);
  427. include(used_in_proc,supreg);
  428. list.concat(Tai_regalloc.alloc(r,nil));
  429. end;
  430. procedure trgobj.alloccpuregisters(list:Taasmoutput;r:Tcpuregisterset);
  431. var i:Tsuperregister;
  432. begin
  433. for i:=0 to first_imaginary-1 do
  434. if i in r then
  435. getcpuregister(list,newreg(regtype,i,defaultsub));
  436. end;
  437. procedure trgobj.dealloccpuregisters(list:Taasmoutput;r:Tcpuregisterset);
  438. var i:Tsuperregister;
  439. begin
  440. for i:=0 to first_imaginary-1 do
  441. if i in r then
  442. ungetcpuregister(list,newreg(regtype,i,defaultsub));
  443. end;
  444. procedure trgobj.do_register_allocation(list:Taasmoutput;headertai:tai);
  445. var
  446. spillingcounter:byte;
  447. endspill:boolean;
  448. begin
  449. { Insert regalloc info for imaginary registers }
  450. insert_regalloc_info_all(list);
  451. ibitmap:=tinterferencebitmap.create;
  452. generate_interference_graph(list,headertai);
  453. { Don't do the real allocation when -sr is passed }
  454. if (cs_no_regalloc in aktglobalswitches) then
  455. exit;
  456. {Do register allocation.}
  457. spillingcounter:=0;
  458. repeat
  459. prepare_colouring;
  460. colour_registers;
  461. epilogue_colouring;
  462. endspill:=true;
  463. if spillednodes.length<>0 then
  464. begin
  465. inc(spillingcounter);
  466. if spillingcounter>maxspillingcounter then
  467. exit;
  468. if spillingcounter>maxspillingcounter then
  469. internalerror(200309041);
  470. endspill:=not spill_registers(list,headertai);
  471. end;
  472. until endspill;
  473. ibitmap.free;
  474. translate_registers(list);
  475. dispose_reginfo;
  476. end;
  477. procedure trgobj.add_constraints(reg:Tregister);
  478. begin
  479. end;
  480. procedure trgobj.add_edge(u,v:Tsuperregister);
  481. {This procedure will add an edge to the virtual interference graph.}
  482. procedure addadj(u,v:Tsuperregister);
  483. begin
  484. with reginfo[u] do
  485. begin
  486. if adjlist=nil then
  487. new(adjlist,init);
  488. adjlist^.add(v);
  489. end;
  490. end;
  491. begin
  492. if (u<>v) and not(ibitmap[v,u]) then
  493. begin
  494. ibitmap[v,u]:=true;
  495. ibitmap[u,v]:=true;
  496. {Precoloured nodes are not stored in the interference graph.}
  497. if (u>=first_imaginary) then
  498. addadj(u,v);
  499. if (v>=first_imaginary) then
  500. addadj(v,u);
  501. end;
  502. end;
  503. procedure trgobj.add_edges_used(u:Tsuperregister);
  504. var i:word;
  505. begin
  506. with live_registers do
  507. if length>0 then
  508. for i:=0 to length-1 do
  509. add_edge(u,get_alias(buf^[i]));
  510. end;
  511. {$ifdef EXTDEBUG}
  512. procedure trgobj.writegraph(loopidx:longint);
  513. {This procedure writes out the current interference graph in the
  514. register allocator.}
  515. var f:text;
  516. i,j:Tsuperregister;
  517. begin
  518. assign(f,'igraph'+tostr(loopidx));
  519. rewrite(f);
  520. writeln(f,'Interference graph');
  521. writeln(f);
  522. write(f,' ');
  523. for i:=0 to 15 do
  524. for j:=0 to 15 do
  525. write(f,hexstr(i,1));
  526. writeln(f);
  527. write(f,' ');
  528. for i:=0 to 15 do
  529. write(f,'0123456789ABCDEF');
  530. writeln(f);
  531. for i:=0 to maxreg-1 do
  532. begin
  533. write(f,hexstr(i,2):4);
  534. for j:=0 to maxreg-1 do
  535. if ibitmap[i,j] then
  536. write(f,'*')
  537. else
  538. write(f,'-');
  539. writeln(f);
  540. end;
  541. close(f);
  542. end;
  543. {$endif EXTDEBUG}
  544. procedure trgobj.add_to_movelist(u:Tsuperregister;data:Tlinkedlistitem);
  545. begin
  546. with reginfo[u] do
  547. begin
  548. if movelist=nil then
  549. begin
  550. getmem(movelist,sizeof(tmovelistheader)+60*sizeof(pointer));
  551. movelist^.header.maxcount:=60;
  552. movelist^.header.count:=0;
  553. movelist^.header.sorted_until:=0;
  554. end
  555. else
  556. begin
  557. if movelist^.header.count>=movelist^.header.maxcount then
  558. begin
  559. movelist^.header.maxcount:=movelist^.header.maxcount*2;
  560. reallocmem(movelist,sizeof(tmovelistheader)+movelist^.header.maxcount*sizeof(pointer));
  561. end;
  562. end;
  563. movelist^.data[movelist^.header.count]:=data;
  564. inc(movelist^.header.count);
  565. end;
  566. end;
  567. procedure trgobj.add_reg_instruction(instr:Tai;r:tregister);
  568. var
  569. supreg : tsuperregister;
  570. begin
  571. supreg:=getsupreg(r);
  572. if supreg>=first_imaginary then
  573. with reginfo[supreg] do
  574. begin
  575. if not assigned(live_start) then
  576. live_start:=instr;
  577. live_end:=instr;
  578. end;
  579. end;
  580. procedure trgobj.add_move_instruction(instr:Taicpu);
  581. {This procedure notifies a certain as a move instruction so the
  582. register allocator can try to eliminate it.}
  583. var i:Tmoveins;
  584. ssupreg,dsupreg:Tsuperregister;
  585. begin
  586. {$ifdef extdebug}
  587. if (instr.oper[O_MOV_SOURCE]^.typ<>top_reg) or
  588. (instr.oper[O_MOV_DEST]^.typ<>top_reg) then
  589. internalerror(200311291);
  590. {$endif}
  591. i:=Tmoveins.create;
  592. i.moveset:=ms_worklist_moves;
  593. worklist_moves.insert(i);
  594. ssupreg:=getsupreg(instr.oper[O_MOV_SOURCE]^.reg);
  595. add_to_movelist(ssupreg,i);
  596. dsupreg:=getsupreg(instr.oper[O_MOV_DEST]^.reg);
  597. if ssupreg<>dsupreg then
  598. {Avoid adding the same move instruction twice to a single register.}
  599. add_to_movelist(dsupreg,i);
  600. i.x:=ssupreg;
  601. i.y:=dsupreg;
  602. end;
  603. function trgobj.move_related(n:Tsuperregister):boolean;
  604. var i:cardinal;
  605. begin
  606. move_related:=false;
  607. with reginfo[n] do
  608. if movelist<>nil then
  609. with movelist^ do
  610. for i:=0 to header.count-1 do
  611. if Tmoveins(data[i]).moveset in [ms_worklist_moves,ms_active_moves] then
  612. begin
  613. move_related:=true;
  614. break;
  615. end;
  616. end;
  617. procedure Trgobj.sort_simplify_worklist;
  618. {Sorts the simplifyworklist by the number of interferences the
  619. registers in it cause. This allows simplify to execute in
  620. constant time.}
  621. var p,h,i,leni,lent:word;
  622. t:Tsuperregister;
  623. adji,adjt:Psuperregisterworklist;
  624. begin
  625. with simplifyworklist do
  626. begin
  627. if length<2 then
  628. exit;
  629. p:=1;
  630. while 2*p<length do
  631. p:=2*p;
  632. while p<>0 do
  633. begin
  634. for h:=p to length-1 do
  635. begin
  636. i:=h;
  637. t:=buf^[i];
  638. adjt:=reginfo[buf^[i]].adjlist;
  639. lent:=0;
  640. if adjt<>nil then
  641. lent:=adjt^.length;
  642. repeat
  643. adji:=reginfo[buf^[i-p]].adjlist;
  644. leni:=0;
  645. if adji<>nil then
  646. leni:=adji^.length;
  647. if leni<=lent then
  648. break;
  649. buf^[i]:=buf^[i-p];
  650. dec(i,p)
  651. until i<p;
  652. buf^[i]:=t;
  653. end;
  654. p:=p shr 1;
  655. end;
  656. end;
  657. end;
  658. procedure trgobj.make_work_list;
  659. var n:Tsuperregister;
  660. begin
  661. {If we have 7 cpu registers, and the degree of a node is 7, we cannot
  662. assign it to any of the registers, thus it is significant.}
  663. for n:=first_imaginary to maxreg-1 do
  664. with reginfo[n] do
  665. begin
  666. if adjlist=nil then
  667. degree:=0
  668. else
  669. degree:=adjlist^.length;
  670. if degree>=usable_registers_cnt then
  671. spillworklist.add(n)
  672. else if move_related(n) then
  673. freezeworklist.add(n)
  674. else
  675. simplifyworklist.add(n);
  676. end;
  677. sort_simplify_worklist;
  678. end;
  679. procedure trgobj.prepare_colouring;
  680. begin
  681. make_work_list;
  682. active_moves:=Tlinkedlist.create;
  683. frozen_moves:=Tlinkedlist.create;
  684. coalesced_moves:=Tlinkedlist.create;
  685. constrained_moves:=Tlinkedlist.create;
  686. selectstack.clear;
  687. end;
  688. procedure trgobj.enable_moves(n:Tsuperregister);
  689. var m:Tlinkedlistitem;
  690. i:cardinal;
  691. begin
  692. with reginfo[n] do
  693. if movelist<>nil then
  694. for i:=0 to movelist^.header.count-1 do
  695. begin
  696. m:=movelist^.data[i];
  697. if Tmoveins(m).moveset in [ms_worklist_moves,ms_active_moves] then
  698. if Tmoveins(m).moveset=ms_active_moves then
  699. begin
  700. {Move m from the set active_moves to the set worklist_moves.}
  701. active_moves.remove(m);
  702. Tmoveins(m).moveset:=ms_worklist_moves;
  703. worklist_moves.concat(m);
  704. end;
  705. end;
  706. end;
  707. procedure Trgobj.decrement_degree(m:Tsuperregister);
  708. var adj : Psuperregisterworklist;
  709. n : tsuperregister;
  710. d,i : word;
  711. begin
  712. with reginfo[m] do
  713. begin
  714. d:=degree;
  715. if d=0 then
  716. internalerror(200312151);
  717. dec(degree);
  718. if d=usable_registers_cnt then
  719. begin
  720. {Enable moves for m.}
  721. enable_moves(m);
  722. {Enable moves for adjacent.}
  723. adj:=adjlist;
  724. if adj<>nil then
  725. for i:=1 to adj^.length do
  726. begin
  727. n:=adj^.buf^[i-1];
  728. if reginfo[n].flags*[ri_selected,ri_coalesced]<>[] then
  729. enable_moves(n);
  730. end;
  731. {Remove the node from the spillworklist.}
  732. if not spillworklist.delete(m) then
  733. internalerror(200310145);
  734. if move_related(m) then
  735. freezeworklist.add(m)
  736. else
  737. simplifyworklist.add(m);
  738. end;
  739. end;
  740. end;
  741. procedure trgobj.simplify;
  742. var adj : Psuperregisterworklist;
  743. m,n : Tsuperregister;
  744. i : word;
  745. begin
  746. {We take the element with the least interferences out of the
  747. simplifyworklist. Since the simplifyworklist is now sorted, we
  748. no longer need to search, but we can simply take the first element.}
  749. m:=simplifyworklist.get;
  750. {Push it on the selectstack.}
  751. selectstack.add(m);
  752. with reginfo[m] do
  753. begin
  754. include(flags,ri_selected);
  755. adj:=adjlist;
  756. end;
  757. if adj<>nil then
  758. for i:=1 to adj^.length do
  759. begin
  760. n:=adj^.buf^[i-1];
  761. if (n>=first_imaginary) and
  762. (reginfo[n].flags*[ri_selected,ri_coalesced]=[]) then
  763. decrement_degree(n);
  764. end;
  765. end;
  766. function trgobj.get_alias(n:Tsuperregister):Tsuperregister;
  767. begin
  768. while ri_coalesced in reginfo[n].flags do
  769. n:=reginfo[n].alias;
  770. get_alias:=n;
  771. end;
  772. procedure trgobj.add_worklist(u:Tsuperregister);
  773. begin
  774. if (u>=first_imaginary) and
  775. (not move_related(u)) and
  776. (reginfo[u].degree<usable_registers_cnt) then
  777. begin
  778. if not freezeworklist.delete(u) then
  779. internalerror(200308161); {must be found}
  780. simplifyworklist.add(u);
  781. end;
  782. end;
  783. function trgobj.adjacent_ok(u,v:Tsuperregister):boolean;
  784. {Check wether u and v should be coalesced. u is precoloured.}
  785. function ok(t,r:Tsuperregister):boolean;
  786. begin
  787. ok:=(t<first_imaginary) or
  788. (reginfo[t].degree<usable_registers_cnt) or
  789. ibitmap[r,t];
  790. end;
  791. var adj : Psuperregisterworklist;
  792. i : word;
  793. n : tsuperregister;
  794. begin
  795. with reginfo[v] do
  796. begin
  797. adjacent_ok:=true;
  798. adj:=adjlist;
  799. if adj<>nil then
  800. for i:=1 to adj^.length do
  801. begin
  802. n:=adj^.buf^[i-1];
  803. if (flags*[ri_coalesced,ri_selected]=[]) and not ok(n,u) then
  804. begin
  805. adjacent_ok:=false;
  806. break;
  807. end;
  808. end;
  809. end;
  810. end;
  811. function trgobj.conservative(u,v:Tsuperregister):boolean;
  812. var adj : Psuperregisterworklist;
  813. done : Tsuperregisterset; {To prevent that we count nodes twice.}
  814. i,k:word;
  815. n : tsuperregister;
  816. begin
  817. k:=0;
  818. supregset_reset(done,false,maxreg);
  819. with reginfo[u] do
  820. begin
  821. adj:=adjlist;
  822. if adj<>nil then
  823. for i:=1 to adj^.length do
  824. begin
  825. n:=adj^.buf^[i-1];
  826. if flags*[ri_coalesced,ri_selected]=[] then
  827. begin
  828. supregset_include(done,n);
  829. if reginfo[n].degree>=usable_registers_cnt then
  830. inc(k);
  831. end;
  832. end;
  833. end;
  834. adj:=reginfo[v].adjlist;
  835. if adj<>nil then
  836. for i:=1 to adj^.length do
  837. begin
  838. n:=adj^.buf^[i-1];
  839. if not supregset_in(done,n) and
  840. (reginfo[n].degree>=usable_registers_cnt) and
  841. (reginfo[u].flags*[ri_coalesced,ri_selected]=[]) then
  842. inc(k);
  843. end;
  844. conservative:=(k<usable_registers_cnt);
  845. end;
  846. procedure trgobj.combine(u,v:Tsuperregister);
  847. var adj : Psuperregisterworklist;
  848. i,n,p,q:cardinal;
  849. t : tsuperregister;
  850. searched:Tlinkedlistitem;
  851. label l1;
  852. begin
  853. if not freezeworklist.delete(v) then
  854. spillworklist.delete(v);
  855. coalescednodes.add(v);
  856. include(reginfo[v].flags,ri_coalesced);
  857. reginfo[v].alias:=u;
  858. {Combine both movelists. Since the movelists are sets, only add
  859. elements that are not already present. The movelists cannot be
  860. empty by definition; nodes are only coalesced if there is a move
  861. between them. To prevent quadratic time blowup (movelists of
  862. especially machine registers can get very large because of moves
  863. generated during calls) we need to go into disgusting complexity.
  864. (See webtbs/tw2242 for an example that stresses this.)
  865. We want to sort the movelist to be able to search logarithmically.
  866. Unfortunately, sorting the movelist every time before searching
  867. is counter-productive, since the movelist usually grows with a few
  868. items at a time. Therefore, we split the movelist into a sorted
  869. and an unsorted part and search through both. If the unsorted part
  870. becomes too large, we sort.}
  871. if assigned(reginfo[u].movelist) then
  872. begin
  873. {We have to weigh the cost of sorting the list against searching
  874. the cost of the unsorted part. I use factor of 8 here; if the
  875. number of items is less than 8 times the numer of unsorted items,
  876. we'll sort the list.}
  877. with reginfo[u].movelist^ do
  878. if header.count<8*(header.count-header.sorted_until) then
  879. sort_movelist(reginfo[u].movelist);
  880. if assigned(reginfo[v].movelist) then
  881. begin
  882. for n:=0 to reginfo[v].movelist^.header.count-1 do
  883. begin
  884. {Binary search the sorted part of the list.}
  885. searched:=reginfo[v].movelist^.data[n];
  886. p:=0;
  887. q:=reginfo[u].movelist^.header.sorted_until;
  888. i:=0;
  889. if q<>0 then
  890. repeat
  891. i:=(p+q) shr 1;
  892. if ptrint(searched)>ptrint(reginfo[u].movelist^.data[i]) then
  893. p:=i+1
  894. else
  895. q:=i;
  896. until p=q;
  897. with reginfo[u].movelist^ do
  898. if searched<>data[i] then
  899. begin
  900. {Linear search the unsorted part of the list.}
  901. for i:=header.sorted_until+1 to header.count-1 do
  902. if searched=data[i] then
  903. goto l1;
  904. {Not found -> add}
  905. add_to_movelist(u,searched);
  906. l1:
  907. end;
  908. end;
  909. end;
  910. end;
  911. enable_moves(v);
  912. adj:=reginfo[v].adjlist;
  913. if adj<>nil then
  914. for i:=1 to adj^.length do
  915. begin
  916. t:=adj^.buf^[i-1];
  917. with reginfo[t] do
  918. if not(ri_coalesced in flags) then
  919. begin
  920. {t has a connection to v. Since we are adding v to u, we
  921. need to connect t to u. However, beware if t was already
  922. connected to u...}
  923. if (ibitmap[t,u]) and not (ri_selected in flags) then
  924. {... because in that case, we are actually removing an edge
  925. and the degree of t decreases.}
  926. decrement_degree(t)
  927. else
  928. begin
  929. add_edge(t,u);
  930. {We have added an edge to t and u. So their degree increases.
  931. However, v is added to u. That means its neighbours will
  932. no longer point to v, but to u instead. Therefore, only the
  933. degree of u increases.}
  934. if (u>=first_imaginary) and not (ri_selected in flags) then
  935. inc(reginfo[u].degree);
  936. end;
  937. end;
  938. end;
  939. if (reginfo[u].degree>=usable_registers_cnt) and freezeworklist.delete(u) then
  940. spillworklist.add(u);
  941. end;
  942. procedure trgobj.coalesce;
  943. var m:Tmoveins;
  944. x,y,u,v:Tsuperregister;
  945. begin
  946. m:=Tmoveins(worklist_moves.getfirst);
  947. x:=get_alias(m.x);
  948. y:=get_alias(m.y);
  949. if (y<first_imaginary) then
  950. begin
  951. u:=y;
  952. v:=x;
  953. end
  954. else
  955. begin
  956. u:=x;
  957. v:=y;
  958. end;
  959. if (u=v) then
  960. begin
  961. m.moveset:=ms_coalesced_moves; {Already coalesced.}
  962. coalesced_moves.insert(m);
  963. add_worklist(u);
  964. end
  965. {Do u and v interfere? In that case the move is constrained. Two
  966. precoloured nodes interfere allways. If v is precoloured, by the above
  967. code u is precoloured, thus interference...}
  968. else if (v<first_imaginary) or ibitmap[u,v] then
  969. begin
  970. m.moveset:=ms_constrained_moves; {Cannot coalesce yet...}
  971. constrained_moves.insert(m);
  972. add_worklist(u);
  973. add_worklist(v);
  974. end
  975. {Next test: is it possible and a good idea to coalesce??}
  976. else if ((u<first_imaginary) and adjacent_ok(u,v)) or
  977. ((u>=first_imaginary) and conservative(u,v)) then
  978. begin
  979. m.moveset:=ms_coalesced_moves; {Move coalesced!}
  980. coalesced_moves.insert(m);
  981. combine(u,v);
  982. add_worklist(u);
  983. end
  984. else
  985. begin
  986. m.moveset:=ms_active_moves;
  987. active_moves.insert(m);
  988. end;
  989. end;
  990. procedure trgobj.freeze_moves(u:Tsuperregister);
  991. var i:cardinal;
  992. m:Tlinkedlistitem;
  993. v,x,y:Tsuperregister;
  994. begin
  995. if reginfo[u].movelist<>nil then
  996. for i:=0 to reginfo[u].movelist^.header.count-1 do
  997. begin
  998. m:=reginfo[u].movelist^.data[i];
  999. if Tmoveins(m).moveset in [ms_worklist_moves,ms_active_moves] then
  1000. begin
  1001. x:=Tmoveins(m).x;
  1002. y:=Tmoveins(m).y;
  1003. if get_alias(y)=get_alias(u) then
  1004. v:=get_alias(x)
  1005. else
  1006. v:=get_alias(y);
  1007. {Move m from active_moves/worklist_moves to frozen_moves.}
  1008. if Tmoveins(m).moveset=ms_active_moves then
  1009. active_moves.remove(m)
  1010. else
  1011. worklist_moves.remove(m);
  1012. Tmoveins(m).moveset:=ms_frozen_moves;
  1013. frozen_moves.insert(m);
  1014. if (v>=first_imaginary) and not(move_related(v)) and
  1015. (reginfo[v].degree<usable_registers_cnt) then
  1016. begin
  1017. freezeworklist.delete(v);
  1018. simplifyworklist.add(v);
  1019. end;
  1020. end;
  1021. end;
  1022. end;
  1023. procedure trgobj.freeze;
  1024. var n:Tsuperregister;
  1025. begin
  1026. { We need to take a random element out of the freezeworklist. We take
  1027. the last element. Dirty code! }
  1028. n:=freezeworklist.get;
  1029. {Add it to the simplifyworklist.}
  1030. simplifyworklist.add(n);
  1031. freeze_moves(n);
  1032. end;
  1033. procedure trgobj.select_spill;
  1034. var
  1035. n : tsuperregister;
  1036. adj : psuperregisterworklist;
  1037. max,p,i:word;
  1038. begin
  1039. { We must look for the element with the most interferences in the
  1040. spillworklist. This is required because those registers are creating
  1041. the most conflicts and keeping them in a register will not reduce the
  1042. complexity and even can cause the help registers for the spilling code
  1043. to get too much conflicts with the result that the spilling code
  1044. will never converge (PFV) }
  1045. max:=0;
  1046. p:=0;
  1047. with spillworklist do
  1048. begin
  1049. {Safe: This procedure is only called if length<>0}
  1050. for i:=0 to length-1 do
  1051. begin
  1052. adj:=reginfo[buf^[i]].adjlist;
  1053. if assigned(adj) and (adj^.length>max) then
  1054. begin
  1055. p:=i;
  1056. max:=adj^.length;
  1057. end;
  1058. end;
  1059. n:=buf^[p];
  1060. deleteidx(p);
  1061. end;
  1062. simplifyworklist.add(n);
  1063. freeze_moves(n);
  1064. end;
  1065. procedure trgobj.assign_colours;
  1066. {Assign_colours assigns the actual colours to the registers.}
  1067. var adj : Psuperregisterworklist;
  1068. i,j,k : word;
  1069. n,a,c : Tsuperregister;
  1070. colourednodes : Tsuperregisterset;
  1071. adj_colours:set of 0..255;
  1072. found : boolean;
  1073. begin
  1074. spillednodes.clear;
  1075. {Reset colours}
  1076. for n:=0 to maxreg-1 do
  1077. reginfo[n].colour:=n;
  1078. {Colour the cpu registers...}
  1079. supregset_reset(colourednodes,false,maxreg);
  1080. for n:=0 to first_imaginary-1 do
  1081. supregset_include(colourednodes,n);
  1082. {Now colour the imaginary registers on the select-stack.}
  1083. for i:=selectstack.length downto 1 do
  1084. begin
  1085. n:=selectstack.buf^[i-1];
  1086. {Create a list of colours that we cannot assign to n.}
  1087. adj_colours:=[];
  1088. adj:=reginfo[n].adjlist;
  1089. if adj<>nil then
  1090. for j:=0 to adj^.length-1 do
  1091. begin
  1092. a:=get_alias(adj^.buf^[j]);
  1093. if supregset_in(colourednodes,a) and (reginfo[a].colour<=255) then
  1094. include(adj_colours,reginfo[a].colour);
  1095. end;
  1096. if regtype=R_INTREGISTER then
  1097. include(adj_colours,RS_STACK_POINTER_REG);
  1098. {Assume a spill by default...}
  1099. found:=false;
  1100. {Search for a colour not in this list.}
  1101. for k:=0 to usable_registers_cnt-1 do
  1102. begin
  1103. c:=usable_registers[k];
  1104. if not(c in adj_colours) then
  1105. begin
  1106. reginfo[n].colour:=c;
  1107. found:=true;
  1108. supregset_include(colourednodes,n);
  1109. include(used_in_proc,c);
  1110. break;
  1111. end;
  1112. end;
  1113. if not found then
  1114. spillednodes.add(n);
  1115. end;
  1116. {Finally colour the nodes that were coalesced.}
  1117. for i:=1 to coalescednodes.length do
  1118. begin
  1119. n:=coalescednodes.buf^[i-1];
  1120. k:=get_alias(n);
  1121. reginfo[n].colour:=reginfo[k].colour;
  1122. if reginfo[k].colour<maxcpuregister then
  1123. include(used_in_proc,reginfo[k].colour);
  1124. end;
  1125. end;
  1126. procedure trgobj.colour_registers;
  1127. begin
  1128. repeat
  1129. if simplifyworklist.length<>0 then
  1130. simplify
  1131. else if not(worklist_moves.empty) then
  1132. coalesce
  1133. else if freezeworklist.length<>0 then
  1134. freeze
  1135. else if spillworklist.length<>0 then
  1136. select_spill;
  1137. until (simplifyworklist.length=0) and
  1138. worklist_moves.empty and
  1139. (freezeworklist.length=0) and
  1140. (spillworklist.length=0);
  1141. assign_colours;
  1142. end;
  1143. procedure trgobj.epilogue_colouring;
  1144. var
  1145. i : Tsuperregister;
  1146. begin
  1147. worklist_moves.clear;
  1148. active_moves.destroy;
  1149. active_moves:=nil;
  1150. frozen_moves.destroy;
  1151. frozen_moves:=nil;
  1152. coalesced_moves.destroy;
  1153. coalesced_moves:=nil;
  1154. constrained_moves.destroy;
  1155. constrained_moves:=nil;
  1156. for i:=0 to maxreg-1 do
  1157. with reginfo[i] do
  1158. if movelist<>nil then
  1159. begin
  1160. dispose(movelist);
  1161. movelist:=nil;
  1162. end;
  1163. end;
  1164. procedure trgobj.clear_interferences(u:Tsuperregister);
  1165. {Remove node u from the interference graph and remove all collected
  1166. move instructions it is associated with.}
  1167. var i : word;
  1168. v : Tsuperregister;
  1169. adj,adj2 : Psuperregisterworklist;
  1170. begin
  1171. adj:=reginfo[u].adjlist;
  1172. if adj<>nil then
  1173. begin
  1174. for i:=1 to adj^.length do
  1175. begin
  1176. v:=adj^.buf^[i-1];
  1177. {Remove (u,v) and (v,u) from bitmap.}
  1178. ibitmap[u,v]:=false;
  1179. ibitmap[v,u]:=false;
  1180. {Remove (v,u) from adjacency list.}
  1181. adj2:=reginfo[v].adjlist;
  1182. if adj2<>nil then
  1183. begin
  1184. adj2^.delete(u);
  1185. if adj2^.length=0 then
  1186. begin
  1187. dispose(adj2,done);
  1188. reginfo[v].adjlist:=nil;
  1189. end;
  1190. end;
  1191. end;
  1192. {Remove ( u,* ) from adjacency list.}
  1193. dispose(adj,done);
  1194. reginfo[u].adjlist:=nil;
  1195. end;
  1196. end;
  1197. function trgobj.getregisterinline(list:Taasmoutput;subreg:Tsubregister):Tregister;
  1198. var
  1199. p : Tsuperregister;
  1200. r : Tregister;
  1201. begin
  1202. p:=getnewreg(subreg);
  1203. live_registers.add(p);
  1204. result:=newreg(regtype,p,subreg);
  1205. add_edges_used(p);
  1206. add_constraints(result);
  1207. end;
  1208. procedure trgobj.ungetregisterinline(list:Taasmoutput;r:Tregister);
  1209. var
  1210. supreg:Tsuperregister;
  1211. begin
  1212. supreg:=getsupreg(r);
  1213. live_registers.delete(supreg);
  1214. insert_regalloc_info(list,supreg);
  1215. end;
  1216. procedure trgobj.insert_regalloc_info(list:Taasmoutput;u:tsuperregister);
  1217. var
  1218. p : tai;
  1219. r : tregister;
  1220. begin
  1221. { Insert regallocs for all imaginary registers }
  1222. with reginfo[u] do
  1223. begin
  1224. r:=newreg(regtype,u,subreg);
  1225. if assigned(live_start) then
  1226. begin
  1227. list.insertbefore(Tai_regalloc.alloc(r,live_start),live_start);
  1228. { Insert live end deallocation before reg allocations
  1229. to reduce conflicts }
  1230. p:=live_end;
  1231. while assigned(p) and
  1232. assigned(p.previous) and
  1233. (tai(p.previous).typ=ait_regalloc) and
  1234. (tai_regalloc(p.previous).ratype=ra_alloc) and
  1235. (tai_regalloc(p.previous).reg<>r) do
  1236. p:=tai(p.previous);
  1237. { , but add release after sync }
  1238. if assigned(p) and
  1239. (p.typ=ait_regalloc) and
  1240. (tai_regalloc(p).ratype=ra_sync) then
  1241. p:=tai(p.next);
  1242. if assigned(p) then
  1243. list.insertbefore(Tai_regalloc.dealloc(r,live_end),p)
  1244. else
  1245. list.concat(Tai_regalloc.dealloc(r,live_end));
  1246. end
  1247. {$ifdef EXTDEBUG}
  1248. else
  1249. Comment(V_Warning,'Register '+std_regname(r)+' not used');
  1250. {$endif EXTDEBUG}
  1251. end;
  1252. end;
  1253. procedure trgobj.insert_regalloc_info_all(list:Taasmoutput);
  1254. var
  1255. supreg : tsuperregister;
  1256. begin
  1257. { Insert regallocs for all imaginary registers }
  1258. for supreg:=first_imaginary to maxreg-1 do
  1259. insert_regalloc_info(list,supreg);
  1260. end;
  1261. procedure trgobj.add_cpu_interferences(p : tai);
  1262. begin
  1263. end;
  1264. procedure trgobj.generate_interference_graph(list:Taasmoutput;headertai:tai);
  1265. var
  1266. p : tai;
  1267. i : integer;
  1268. supreg : tsuperregister;
  1269. begin
  1270. { All allocations are available. Now we can generate the
  1271. interference graph. Walk through all instructions, we can
  1272. start with the headertai, because before the header tai is
  1273. only symbols. }
  1274. live_registers.clear;
  1275. //live_registers.add(RS_STACK_POINTER_REG);
  1276. //live_registers.add(RS_FRAME_POINTER_REG);
  1277. p:=headertai;
  1278. while assigned(p) do
  1279. begin
  1280. if p.typ=ait_regalloc then
  1281. with Tai_regalloc(p) do
  1282. begin
  1283. if (getregtype(reg)=regtype) then
  1284. begin
  1285. supreg:=getsupreg(reg);
  1286. case ratype of
  1287. ra_alloc :
  1288. begin
  1289. live_registers.add(supreg);
  1290. add_edges_used(supreg);
  1291. end;
  1292. ra_dealloc :
  1293. begin
  1294. live_registers.delete(supreg);
  1295. add_edges_used(supreg);
  1296. end;
  1297. end;
  1298. { constraints needs always to be updated }
  1299. add_constraints(reg);
  1300. end;
  1301. end;
  1302. add_cpu_interferences(p);
  1303. p:=Tai(p.next);
  1304. end;
  1305. {$ifdef EXTDEBUG}
  1306. if live_registers.length>0 then
  1307. begin
  1308. for i:=0 to live_registers.length-1 do
  1309. begin
  1310. { Only report for imaginary registers }
  1311. if live_registers.buf^[i]>=first_imaginary then
  1312. Comment(V_Warning,'Register '+std_regname(newreg(R_INTREGISTER,live_registers.buf^[i],defaultsub))+' not released');
  1313. end;
  1314. end;
  1315. {$endif}
  1316. end;
  1317. procedure Trgobj.translate_registers(list:taasmoutput);
  1318. var
  1319. hp,p,q:Tai;
  1320. i:shortint;
  1321. {$ifdef arm}
  1322. so:pshifterop;
  1323. {$endif arm}
  1324. begin
  1325. { Leave when no imaginary registers are used }
  1326. if maxreg<=first_imaginary then
  1327. exit;
  1328. p:=Tai(list.first);
  1329. while assigned(p) do
  1330. begin
  1331. case p.typ of
  1332. ait_regalloc:
  1333. with Tai_regalloc(p) do
  1334. begin
  1335. if (getregtype(reg)=regtype) then
  1336. begin
  1337. { Only alloc/dealloc is needed for the optimizer, remove
  1338. other regalloc }
  1339. if not(ratype in [ra_alloc,ra_dealloc]) then
  1340. begin
  1341. q:=Tai(next);
  1342. list.remove(p);
  1343. p.free;
  1344. p:=q;
  1345. continue;
  1346. end
  1347. else
  1348. begin
  1349. setsupreg(reg,reginfo[getsupreg(reg)].colour);
  1350. {
  1351. Remove sequences of release and
  1352. allocation of the same register like. Other combinations
  1353. of release/allocate need to stay in the list.
  1354. # Register X released
  1355. # Register X allocated
  1356. }
  1357. if assigned(previous) and
  1358. (ratype=ra_alloc) and
  1359. (Tai(previous).typ=ait_regalloc) and
  1360. (Tai_regalloc(previous).reg=reg) and
  1361. (Tai_regalloc(previous).ratype=ra_dealloc) then
  1362. begin
  1363. q:=Tai(next);
  1364. hp:=tai(previous);
  1365. list.remove(hp);
  1366. hp.free;
  1367. list.remove(p);
  1368. p.free;
  1369. p:=q;
  1370. continue;
  1371. end;
  1372. end;
  1373. end;
  1374. end;
  1375. ait_instruction:
  1376. with Taicpu(p) do
  1377. begin
  1378. aktfilepos:=fileinfo;
  1379. for i:=0 to ops-1 do
  1380. with oper[i]^ do
  1381. case typ of
  1382. Top_reg:
  1383. if (getregtype(reg)=regtype) then
  1384. setsupreg(reg,reginfo[getsupreg(reg)].colour);
  1385. Top_ref:
  1386. begin
  1387. if regtype=R_INTREGISTER then
  1388. with ref^ do
  1389. begin
  1390. if base<>NR_NO then
  1391. setsupreg(base,reginfo[getsupreg(base)].colour);
  1392. if index<>NR_NO then
  1393. setsupreg(index,reginfo[getsupreg(index)].colour);
  1394. end;
  1395. end;
  1396. {$ifdef arm}
  1397. Top_shifterop:
  1398. begin
  1399. if regtype=R_INTREGISTER then
  1400. begin
  1401. so:=shifterop;
  1402. if so^.rs<>NR_NO then
  1403. setsupreg(so^.rs,reginfo[getsupreg(so^.rs)].colour);
  1404. end;
  1405. end;
  1406. {$endif arm}
  1407. end;
  1408. { Maybe the operation can be removed when
  1409. it is a move and both arguments are the same }
  1410. if is_same_reg_move(regtype) then
  1411. begin
  1412. q:=Tai(p.next);
  1413. list.remove(p);
  1414. p.free;
  1415. p:=q;
  1416. continue;
  1417. end;
  1418. end;
  1419. end;
  1420. p:=Tai(p.next);
  1421. end;
  1422. aktfilepos:=current_procinfo.exitpos;
  1423. end;
  1424. function trgobj.spill_registers(list:Taasmoutput;headertai:tai):boolean;
  1425. { Returns true if any help registers have been used }
  1426. var
  1427. i : word;
  1428. t : tsuperregister;
  1429. p,q : Tai;
  1430. regs_to_spill_set:Tsuperregisterset;
  1431. spill_temps : ^Tspill_temp_list;
  1432. supreg : tsuperregister;
  1433. templist : taasmoutput;
  1434. begin
  1435. spill_registers:=false;
  1436. live_registers.clear;
  1437. for i:=first_imaginary to maxreg-1 do
  1438. exclude(reginfo[i].flags,ri_selected);
  1439. spill_temps:=allocmem(sizeof(treference)*maxreg);
  1440. supregset_reset(regs_to_spill_set,false,$ffff);
  1441. { Allocate temps and insert in front of the list }
  1442. templist:=taasmoutput.create;
  1443. {Safe: this procedure is only called if there are spilled nodes.}
  1444. with spillednodes do
  1445. for i:=0 to length-1 do
  1446. begin
  1447. t:=buf^[i];
  1448. {Alternative representation.}
  1449. supregset_include(regs_to_spill_set,t);
  1450. {Clear all interferences of the spilled register.}
  1451. clear_interferences(t);
  1452. {Get a temp for the spilled register, the size must at least equal a complete register,
  1453. take also care of the fact that subreg can be larger than a single register like doubles
  1454. that occupy 2 registers }
  1455. tg.gettemp(templist,
  1456. max(tcgsize2size[reg_cgsize(newreg(regtype,t,R_SUBWHOLE))],
  1457. tcgsize2size[reg_cgsize(newreg(regtype,t,reginfo[t].subreg))]),
  1458. tt_noreuse,spill_temps^[t]);
  1459. end;
  1460. list.insertlistafter(headertai,templist);
  1461. templist.free;
  1462. { Walk through all instructions, we can start with the headertai,
  1463. because before the header tai is only symbols }
  1464. p:=headertai;
  1465. while assigned(p) do
  1466. begin
  1467. case p.typ of
  1468. ait_regalloc:
  1469. with Tai_regalloc(p) do
  1470. begin
  1471. if (getregtype(reg)=regtype) then
  1472. begin
  1473. {A register allocation of a spilled register can be removed.}
  1474. supreg:=getsupreg(reg);
  1475. if supregset_in(regs_to_spill_set,supreg) then
  1476. begin
  1477. q:=Tai(p.next);
  1478. list.remove(p);
  1479. p.free;
  1480. p:=q;
  1481. continue;
  1482. end
  1483. else
  1484. begin
  1485. case ratype of
  1486. ra_alloc :
  1487. live_registers.add(supreg);
  1488. ra_dealloc :
  1489. live_registers.delete(supreg);
  1490. end;
  1491. end;
  1492. end;
  1493. end;
  1494. ait_instruction:
  1495. with Taicpu(p) do
  1496. begin
  1497. aktfilepos:=fileinfo;
  1498. if instr_spill_register(list,taicpu(p),regs_to_spill_set,spill_temps^) then
  1499. spill_registers:=true;
  1500. end;
  1501. end;
  1502. p:=Tai(p.next);
  1503. end;
  1504. aktfilepos:=current_procinfo.exitpos;
  1505. {Safe: this procedure is only called if there are spilled nodes.}
  1506. with spillednodes do
  1507. for i:=0 to length-1 do
  1508. tg.ungettemp(list,spill_temps^[buf^[i]]);
  1509. freemem(spill_temps);
  1510. end;
  1511. function trgobj.do_spill_replace(list:Taasmoutput;instr:taicpu;orgreg:tsuperregister;const spilltemp:treference):boolean;
  1512. begin
  1513. result:=false;
  1514. end;
  1515. procedure Trgobj.do_spill_read(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  1516. begin
  1517. list.insertafter(spilling_create_load(spilltemp,tempreg),pos);
  1518. end;
  1519. procedure Trgobj.do_spill_written(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  1520. begin
  1521. list.insertafter(spilling_create_store(tempreg,spilltemp),pos);
  1522. end;
  1523. function trgobj.get_spill_subreg(r : tregister) : tsubregister;
  1524. begin
  1525. result:=defaultsub;
  1526. end;
  1527. function trgobj.instr_spill_register(list:Taasmoutput;
  1528. instr:taicpu;
  1529. const r:Tsuperregisterset;
  1530. const spilltemplist:Tspill_temp_list): boolean;
  1531. var
  1532. counter, regindex: longint;
  1533. regs: tspillregsinfo;
  1534. spilled: boolean;
  1535. procedure addreginfo(reg: tregister; operation: topertype);
  1536. var
  1537. i, tmpindex: longint;
  1538. supreg : tsuperregister;
  1539. begin
  1540. tmpindex := regindex;
  1541. supreg:=getsupreg(reg);
  1542. { did we already encounter this register? }
  1543. for i := 0 to pred(regindex) do
  1544. if (regs[i].orgreg = supreg) then
  1545. begin
  1546. tmpindex := i;
  1547. break;
  1548. end;
  1549. if tmpindex > high(regs) then
  1550. internalerror(2003120301);
  1551. regs[tmpindex].orgreg := supreg;
  1552. regs[tmpindex].spillreg:=reg;
  1553. if supregset_in(r,supreg) then
  1554. begin
  1555. { add/update info on this register }
  1556. regs[tmpindex].mustbespilled := true;
  1557. case operation of
  1558. operand_read:
  1559. regs[tmpindex].regread := true;
  1560. operand_write:
  1561. regs[tmpindex].regwritten := true;
  1562. operand_readwrite:
  1563. begin
  1564. regs[tmpindex].regread := true;
  1565. regs[tmpindex].regwritten := true;
  1566. end;
  1567. end;
  1568. spilled := true;
  1569. end;
  1570. inc(regindex,ord(regindex=tmpindex));
  1571. end;
  1572. procedure tryreplacereg(var reg: tregister);
  1573. var
  1574. i: longint;
  1575. supreg: tsuperregister;
  1576. begin
  1577. supreg:=getsupreg(reg);
  1578. for i:=0 to pred(regindex) do
  1579. if (regs[i].mustbespilled) and
  1580. (regs[i].orgreg=supreg) then
  1581. begin
  1582. { Only replace supreg }
  1583. setsupreg(reg,getsupreg(regs[i].tempreg));
  1584. break;
  1585. end;
  1586. end;
  1587. var
  1588. loadpos,
  1589. storepos : tai;
  1590. oldlive_registers : tsuperregisterworklist;
  1591. begin
  1592. result := false;
  1593. fillchar(regs,sizeof(regs),0);
  1594. for counter := low(regs) to high(regs) do
  1595. regs[counter].orgreg := RS_INVALID;
  1596. spilled := false;
  1597. regindex := 0;
  1598. { check whether and if so which and how (read/written) this instructions contains
  1599. registers that must be spilled }
  1600. for counter := 0 to instr.ops-1 do
  1601. with instr.oper[counter]^ do
  1602. begin
  1603. case typ of
  1604. top_reg:
  1605. begin
  1606. if (getregtype(reg) = regtype) then
  1607. addreginfo(reg,instr.spilling_get_operation_type(counter));
  1608. end;
  1609. top_ref:
  1610. begin
  1611. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1612. with ref^ do
  1613. begin
  1614. if (base <> NR_NO) then
  1615. addreginfo(base,operand_read);
  1616. if (index <> NR_NO) then
  1617. addreginfo(index,operand_read);
  1618. end;
  1619. end;
  1620. {$ifdef ARM}
  1621. top_shifterop:
  1622. begin
  1623. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1624. if shifterop^.rs<>NR_NO then
  1625. addreginfo(shifterop^.rs,operand_read);
  1626. end;
  1627. {$endif ARM}
  1628. end;
  1629. end;
  1630. { if no spilling for this instruction we can leave }
  1631. if not spilled then
  1632. exit;
  1633. {$ifdef x86}
  1634. { Try replacing the register with the spilltemp. This is usefull only
  1635. for the i386,x86_64 that support memory locations for several instructions }
  1636. for counter := 0 to pred(regindex) do
  1637. with regs[counter] do
  1638. begin
  1639. if mustbespilled then
  1640. begin
  1641. if do_spill_replace(list,instr,orgreg,spilltemplist[orgreg]) then
  1642. mustbespilled:=false;
  1643. end;
  1644. end;
  1645. {$endif x86}
  1646. {
  1647. There are registers that need are spilled. We generate the
  1648. following code for it. The used positions where code need
  1649. to be inserted are marked using #. Note that code is always inserted
  1650. before the positions using pos.previous. This way the position is always
  1651. the same since pos doesn't change, but pos.previous is modified everytime
  1652. new code is inserted.
  1653. [
  1654. - reg_allocs load spills
  1655. - load spills
  1656. ]
  1657. [#loadpos
  1658. - reg_deallocs
  1659. - reg_allocs
  1660. ]
  1661. [
  1662. - reg_deallocs for load-only spills
  1663. - reg_allocs for store-only spills
  1664. ]
  1665. [#instr
  1666. - original instruction
  1667. ]
  1668. [
  1669. - store spills
  1670. - reg_deallocs store spills
  1671. ]
  1672. [#storepos
  1673. ]
  1674. }
  1675. result := true;
  1676. oldlive_registers.copyfrom(live_registers);
  1677. { Process all tai_regallocs belonging to this instruction. All
  1678. released registers are also added to the live_registers because
  1679. they can't be used during the spilling }
  1680. loadpos:=tai(instr.previous);
  1681. while assigned(loadpos) and
  1682. (loadpos.typ=ait_regalloc) and
  1683. (tai_regalloc(loadpos).instr=instr) do
  1684. begin
  1685. if tai_regalloc(loadpos).ratype=ra_dealloc then
  1686. live_registers.add(getsupreg(tai_regalloc(loadpos).reg));
  1687. loadpos:=tai(loadpos.previous);
  1688. end;
  1689. loadpos:=tai(loadpos.next);
  1690. { Load the spilled registers }
  1691. for counter := 0 to pred(regindex) do
  1692. with regs[counter] do
  1693. begin
  1694. if mustbespilled and regread then
  1695. begin
  1696. tempreg:=getregisterinline(list,get_spill_subreg(regs[counter].spillreg));
  1697. do_spill_read(list,tai(loadpos.previous),spilltemplist[orgreg],tempreg);
  1698. end;
  1699. end;
  1700. { Release temp registers of read-only registers, and add reference of the instruction
  1701. to the reginfo }
  1702. for counter := 0 to pred(regindex) do
  1703. with regs[counter] do
  1704. begin
  1705. if mustbespilled and regread and (not regwritten) then
  1706. begin
  1707. { The original instruction will be the next that uses this register }
  1708. add_reg_instruction(instr,tempreg);
  1709. ungetregisterinline(list,tempreg);
  1710. end;
  1711. end;
  1712. { Allocate temp registers of write-only registers, and add reference of the instruction
  1713. to the reginfo }
  1714. for counter := 0 to pred(regindex) do
  1715. with regs[counter] do
  1716. begin
  1717. if mustbespilled and regwritten then
  1718. begin
  1719. { When the register is also loaded there is already a register assigned }
  1720. if (not regread) then
  1721. tempreg:=getregisterinline(list,get_spill_subreg(regs[counter].spillreg));
  1722. { The original instruction will be the next that uses this register, this
  1723. also needs to be done for read-write registers }
  1724. add_reg_instruction(instr,tempreg);
  1725. end;
  1726. end;
  1727. { store the spilled registers }
  1728. storepos:=tai(instr.next);
  1729. for counter := 0 to pred(regindex) do
  1730. with regs[counter] do
  1731. begin
  1732. if mustbespilled and regwritten then
  1733. begin
  1734. do_spill_written(list,tai(storepos.previous),spilltemplist[orgreg],tempreg);
  1735. ungetregisterinline(list,tempreg);
  1736. end;
  1737. end;
  1738. { now all spilling code is generated we can restore the live registers. This
  1739. must be done after the store because the store can need an extra register
  1740. that also needs to conflict with the registers of the instruction }
  1741. live_registers.done;
  1742. live_registers:=oldlive_registers;
  1743. { substitute registers }
  1744. for counter:=0 to instr.ops-1 do
  1745. with instr.oper[counter]^ do
  1746. begin
  1747. case typ of
  1748. top_reg:
  1749. begin
  1750. if (getregtype(reg) = regtype) then
  1751. tryreplacereg(reg);
  1752. end;
  1753. top_ref:
  1754. begin
  1755. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1756. begin
  1757. tryreplacereg(ref^.base);
  1758. tryreplacereg(ref^.index);
  1759. end;
  1760. end;
  1761. {$ifdef ARM}
  1762. top_shifterop:
  1763. begin
  1764. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1765. tryreplacereg(shifterop^.rs);
  1766. end;
  1767. {$endif ARM}
  1768. end;
  1769. end;
  1770. end;
  1771. end.
  1772. {
  1773. $Log$
  1774. Revision 1.147 2004-10-31 21:45:03 peter
  1775. * generic tlocation
  1776. * move tlocation to cgutils
  1777. Revision 1.146 2004/10/31 16:04:30 florian
  1778. * fixed compilation of system unit on arm
  1779. Revision 1.145 2004/10/30 15:21:37 florian
  1780. * fixed generic optimizer
  1781. * enabled generic optimizer for sparc
  1782. Revision 1.144 2004/10/24 17:04:01 peter
  1783. * during translation only process regalloc for the current regtype
  1784. Revision 1.143 2004/10/15 09:14:17 mazen
  1785. - remove $IFDEF DELPHI and related code
  1786. - remove $IFDEF FPCPROCVAR and related code
  1787. Revision 1.142 2004/10/13 21:12:51 peter
  1788. * -Or fixes for open array
  1789. Revision 1.141 2004/10/11 15:47:03 peter
  1790. * removed warning about register used only once
  1791. Revision 1.140 2004/10/06 20:14:08 peter
  1792. * live_registers must be restored after the spilling store code
  1793. is generate to add correct conflicts for extra temporary registers
  1794. Revision 1.139 2004/10/05 20:41:01 peter
  1795. * more spilling rewrites
  1796. Revision 1.138 2004/10/04 20:46:22 peter
  1797. * spilling code rewritten for x86. It now used the generic
  1798. spilling routines. Special x86 optimization still needs
  1799. to be added.
  1800. * Spilling fixed when both operands needed to be spilled
  1801. * Cleanup of spilling routine, do_spill_readwritten removed
  1802. Revision 1.137 2004/09/26 17:45:30 peter
  1803. * simple regvar support, not yet finished
  1804. Revision 1.136 2004/09/25 14:23:54 peter
  1805. * ungetregister is now only used for cpuregisters, renamed to
  1806. ungetcpuregister
  1807. * renamed (get|unget)explicitregister(s) to ..cpuregister
  1808. * removed location-release/reference_release
  1809. Revision 1.135 2004/09/21 17:25:12 peter
  1810. * paraloc branch merged
  1811. Revision 1.134.4.2 2004/09/21 17:03:26 peter
  1812. * Include aliases of coalesce registers when adding conflicts
  1813. Revision 1.134.4.1 2004/09/12 13:36:40 peter
  1814. * fixed alignment issues
  1815. Revision 1.134 2004/08/24 21:02:32 florian
  1816. * fixed longbool(<int64>) on sparc
  1817. Revision 1.133 2004/07/09 21:38:30 daniel
  1818. * Add check <= 255 when adding to adj_colours
  1819. Revision 1.132 2004/07/08 09:57:55 daniel
  1820. * Use a normal pascal set in assign_colours, since it only will contain
  1821. real registers
  1822. Revision 1.131 2004/07/07 17:35:26 daniel
  1823. * supregset_reset clears 8kb of memory. However, it is being called in
  1824. inner loops, see for example colour_registers. According to profile data
  1825. this causes fillchar to be the most time consuming procedure.
  1826. Some modifications done to make it clear less than 8kb of memory each
  1827. call. Divides time spent in fillchar by two, but it still is the no.1
  1828. procedure.
  1829. Revision 1.130 2004/06/22 18:24:18 florian
  1830. * fixed arm compilation
  1831. Revision 1.129 2004/06/20 08:55:30 florian
  1832. * logs truncated
  1833. Revision 1.128 2004/06/20 08:47:33 florian
  1834. * spilling of doubles on sparc fixed
  1835. Revision 1.127 2004/06/16 20:07:09 florian
  1836. * dwarf branch merged
  1837. Revision 1.126 2004/05/22 23:34:28 peter
  1838. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1839. Revision 1.125 2004/04/26 19:57:50 jonas
  1840. * do not remove "allocation,deallocation" pairs, as those are important
  1841. for the optimizer
  1842. Revision 1.124.2.3 2004/06/13 10:51:16 florian
  1843. * fixed several register allocator problems (sparc/arm)
  1844. }