rgobj.pas 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  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,node,
  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. i:Tsuperregister;
  449. begin
  450. { Insert regalloc info for imaginary registers }
  451. insert_regalloc_info_all(list);
  452. ibitmap:=tinterferencebitmap.create;
  453. generate_interference_graph(list,headertai);
  454. { Don't do the real allocation when -sr is passed }
  455. if (cs_no_regalloc in aktglobalswitches) then
  456. exit;
  457. {Do register allocation.}
  458. spillingcounter:=0;
  459. repeat
  460. prepare_colouring;
  461. colour_registers;
  462. epilogue_colouring;
  463. endspill:=true;
  464. if spillednodes.length<>0 then
  465. begin
  466. inc(spillingcounter);
  467. if spillingcounter>maxspillingcounter then
  468. exit;
  469. if spillingcounter>maxspillingcounter then
  470. internalerror(200309041);
  471. endspill:=not spill_registers(list,headertai);
  472. end;
  473. until endspill;
  474. ibitmap.free;
  475. translate_registers(list);
  476. dispose_reginfo;
  477. end;
  478. procedure trgobj.add_constraints(reg:Tregister);
  479. begin
  480. end;
  481. procedure trgobj.add_edge(u,v:Tsuperregister);
  482. {This procedure will add an edge to the virtual interference graph.}
  483. procedure addadj(u,v:Tsuperregister);
  484. begin
  485. with reginfo[u] do
  486. begin
  487. if adjlist=nil then
  488. new(adjlist,init);
  489. adjlist^.add(v);
  490. end;
  491. end;
  492. begin
  493. if (u<>v) and not(ibitmap[v,u]) then
  494. begin
  495. ibitmap[v,u]:=true;
  496. ibitmap[u,v]:=true;
  497. {Precoloured nodes are not stored in the interference graph.}
  498. if (u>=first_imaginary) then
  499. addadj(u,v);
  500. if (v>=first_imaginary) then
  501. addadj(v,u);
  502. end;
  503. end;
  504. procedure trgobj.add_edges_used(u:Tsuperregister);
  505. var i:word;
  506. begin
  507. with live_registers do
  508. if length>0 then
  509. for i:=0 to length-1 do
  510. add_edge(u,get_alias(buf^[i]));
  511. end;
  512. {$ifdef EXTDEBUG}
  513. procedure trgobj.writegraph(loopidx:longint);
  514. {This procedure writes out the current interference graph in the
  515. register allocator.}
  516. var f:text;
  517. i,j:Tsuperregister;
  518. begin
  519. assign(f,'igraph'+tostr(loopidx));
  520. rewrite(f);
  521. writeln(f,'Interference graph');
  522. writeln(f);
  523. write(f,' ');
  524. for i:=0 to 15 do
  525. for j:=0 to 15 do
  526. write(f,hexstr(i,1));
  527. writeln(f);
  528. write(f,' ');
  529. for i:=0 to 15 do
  530. write(f,'0123456789ABCDEF');
  531. writeln(f);
  532. for i:=0 to maxreg-1 do
  533. begin
  534. write(f,hexstr(i,2):4);
  535. for j:=0 to maxreg-1 do
  536. if ibitmap[i,j] then
  537. write(f,'*')
  538. else
  539. write(f,'-');
  540. writeln(f);
  541. end;
  542. close(f);
  543. end;
  544. {$endif EXTDEBUG}
  545. procedure trgobj.add_to_movelist(u:Tsuperregister;data:Tlinkedlistitem);
  546. begin
  547. with reginfo[u] do
  548. begin
  549. if movelist=nil then
  550. begin
  551. getmem(movelist,sizeof(tmovelistheader)+60*sizeof(pointer));
  552. movelist^.header.maxcount:=60;
  553. movelist^.header.count:=0;
  554. movelist^.header.sorted_until:=0;
  555. end
  556. else
  557. begin
  558. if movelist^.header.count>=movelist^.header.maxcount then
  559. begin
  560. movelist^.header.maxcount:=movelist^.header.maxcount*2;
  561. reallocmem(movelist,sizeof(tmovelistheader)+movelist^.header.maxcount*sizeof(pointer));
  562. end;
  563. end;
  564. movelist^.data[movelist^.header.count]:=data;
  565. inc(movelist^.header.count);
  566. end;
  567. end;
  568. procedure trgobj.add_reg_instruction(instr:Tai;r:tregister);
  569. var
  570. supreg : tsuperregister;
  571. begin
  572. supreg:=getsupreg(r);
  573. if supreg>=first_imaginary then
  574. with reginfo[supreg] do
  575. begin
  576. if not assigned(live_start) then
  577. live_start:=instr;
  578. live_end:=instr;
  579. end;
  580. end;
  581. procedure trgobj.add_move_instruction(instr:Taicpu);
  582. {This procedure notifies a certain as a move instruction so the
  583. register allocator can try to eliminate it.}
  584. var i:Tmoveins;
  585. ssupreg,dsupreg:Tsuperregister;
  586. begin
  587. {$ifdef extdebug}
  588. if (instr.oper[O_MOV_SOURCE]^.typ<>top_reg) or
  589. (instr.oper[O_MOV_DEST]^.typ<>top_reg) then
  590. internalerror(200311291);
  591. {$endif}
  592. i:=Tmoveins.create;
  593. i.moveset:=ms_worklist_moves;
  594. worklist_moves.insert(i);
  595. ssupreg:=getsupreg(instr.oper[O_MOV_SOURCE]^.reg);
  596. add_to_movelist(ssupreg,i);
  597. dsupreg:=getsupreg(instr.oper[O_MOV_DEST]^.reg);
  598. if ssupreg<>dsupreg then
  599. {Avoid adding the same move instruction twice to a single register.}
  600. add_to_movelist(dsupreg,i);
  601. i.x:=ssupreg;
  602. i.y:=dsupreg;
  603. end;
  604. function trgobj.move_related(n:Tsuperregister):boolean;
  605. var i:cardinal;
  606. begin
  607. move_related:=false;
  608. with reginfo[n] do
  609. if movelist<>nil then
  610. with movelist^ do
  611. for i:=0 to header.count-1 do
  612. if Tmoveins(data[i]).moveset in [ms_worklist_moves,ms_active_moves] then
  613. begin
  614. move_related:=true;
  615. break;
  616. end;
  617. end;
  618. procedure Trgobj.sort_simplify_worklist;
  619. {Sorts the simplifyworklist by the number of interferences the
  620. registers in it cause. This allows simplify to execute in
  621. constant time.}
  622. var p,h,i,leni,lent:word;
  623. t:Tsuperregister;
  624. adji,adjt:Psuperregisterworklist;
  625. begin
  626. with simplifyworklist do
  627. begin
  628. if length<2 then
  629. exit;
  630. p:=1;
  631. while 2*p<length do
  632. p:=2*p;
  633. while p<>0 do
  634. begin
  635. for h:=p to length-1 do
  636. begin
  637. i:=h;
  638. t:=buf^[i];
  639. adjt:=reginfo[buf^[i]].adjlist;
  640. lent:=0;
  641. if adjt<>nil then
  642. lent:=adjt^.length;
  643. repeat
  644. adji:=reginfo[buf^[i-p]].adjlist;
  645. leni:=0;
  646. if adji<>nil then
  647. leni:=adji^.length;
  648. if leni<=lent then
  649. break;
  650. buf^[i]:=buf^[i-p];
  651. dec(i,p)
  652. until i<p;
  653. buf^[i]:=t;
  654. end;
  655. p:=p shr 1;
  656. end;
  657. end;
  658. end;
  659. procedure trgobj.make_work_list;
  660. var n:Tsuperregister;
  661. begin
  662. {If we have 7 cpu registers, and the degree of a node is 7, we cannot
  663. assign it to any of the registers, thus it is significant.}
  664. for n:=first_imaginary to maxreg-1 do
  665. with reginfo[n] do
  666. begin
  667. if adjlist=nil then
  668. degree:=0
  669. else
  670. degree:=adjlist^.length;
  671. if degree>=usable_registers_cnt then
  672. spillworklist.add(n)
  673. else if move_related(n) then
  674. freezeworklist.add(n)
  675. else
  676. simplifyworklist.add(n);
  677. end;
  678. sort_simplify_worklist;
  679. end;
  680. procedure trgobj.prepare_colouring;
  681. var i:word;
  682. begin
  683. make_work_list;
  684. active_moves:=Tlinkedlist.create;
  685. frozen_moves:=Tlinkedlist.create;
  686. coalesced_moves:=Tlinkedlist.create;
  687. constrained_moves:=Tlinkedlist.create;
  688. selectstack.clear;
  689. end;
  690. procedure trgobj.enable_moves(n:Tsuperregister);
  691. var m:Tlinkedlistitem;
  692. i:cardinal;
  693. begin
  694. with reginfo[n] do
  695. if movelist<>nil then
  696. for i:=0 to movelist^.header.count-1 do
  697. begin
  698. m:=movelist^.data[i];
  699. if Tmoveins(m).moveset in [ms_worklist_moves,ms_active_moves] then
  700. if Tmoveins(m).moveset=ms_active_moves then
  701. begin
  702. {Move m from the set active_moves to the set worklist_moves.}
  703. active_moves.remove(m);
  704. Tmoveins(m).moveset:=ms_worklist_moves;
  705. worklist_moves.concat(m);
  706. end;
  707. end;
  708. end;
  709. procedure Trgobj.decrement_degree(m:Tsuperregister);
  710. var adj : Psuperregisterworklist;
  711. n : tsuperregister;
  712. d,i : word;
  713. begin
  714. with reginfo[m] do
  715. begin
  716. d:=degree;
  717. if d=0 then
  718. internalerror(200312151);
  719. dec(degree);
  720. if d=usable_registers_cnt then
  721. begin
  722. {Enable moves for m.}
  723. enable_moves(m);
  724. {Enable moves for adjacent.}
  725. adj:=adjlist;
  726. if adj<>nil then
  727. for i:=1 to adj^.length do
  728. begin
  729. n:=adj^.buf^[i-1];
  730. if reginfo[n].flags*[ri_selected,ri_coalesced]<>[] then
  731. enable_moves(n);
  732. end;
  733. {Remove the node from the spillworklist.}
  734. if not spillworklist.delete(m) then
  735. internalerror(200310145);
  736. if move_related(m) then
  737. freezeworklist.add(m)
  738. else
  739. simplifyworklist.add(m);
  740. end;
  741. end;
  742. end;
  743. procedure trgobj.simplify;
  744. var adj : Psuperregisterworklist;
  745. m,n : Tsuperregister;
  746. i : word;
  747. begin
  748. {We take the element with the least interferences out of the
  749. simplifyworklist. Since the simplifyworklist is now sorted, we
  750. no longer need to search, but we can simply take the first element.}
  751. m:=simplifyworklist.get;
  752. {Push it on the selectstack.}
  753. selectstack.add(m);
  754. with reginfo[m] do
  755. begin
  756. include(flags,ri_selected);
  757. adj:=adjlist;
  758. end;
  759. if adj<>nil then
  760. for i:=1 to adj^.length do
  761. begin
  762. n:=adj^.buf^[i-1];
  763. if (n>=first_imaginary) and
  764. (reginfo[n].flags*[ri_selected,ri_coalesced]=[]) then
  765. decrement_degree(n);
  766. end;
  767. end;
  768. function trgobj.get_alias(n:Tsuperregister):Tsuperregister;
  769. begin
  770. while ri_coalesced in reginfo[n].flags do
  771. n:=reginfo[n].alias;
  772. get_alias:=n;
  773. end;
  774. procedure trgobj.add_worklist(u:Tsuperregister);
  775. begin
  776. if (u>=first_imaginary) and
  777. (not move_related(u)) and
  778. (reginfo[u].degree<usable_registers_cnt) then
  779. begin
  780. if not freezeworklist.delete(u) then
  781. internalerror(200308161); {must be found}
  782. simplifyworklist.add(u);
  783. end;
  784. end;
  785. function trgobj.adjacent_ok(u,v:Tsuperregister):boolean;
  786. {Check wether u and v should be coalesced. u is precoloured.}
  787. function ok(t,r:Tsuperregister):boolean;
  788. begin
  789. ok:=(t<first_imaginary) or
  790. (reginfo[t].degree<usable_registers_cnt) or
  791. ibitmap[r,t];
  792. end;
  793. var adj : Psuperregisterworklist;
  794. i : word;
  795. n : tsuperregister;
  796. begin
  797. with reginfo[v] do
  798. begin
  799. adjacent_ok:=true;
  800. adj:=adjlist;
  801. if adj<>nil then
  802. for i:=1 to adj^.length do
  803. begin
  804. n:=adj^.buf^[i-1];
  805. if (flags*[ri_coalesced,ri_selected]=[]) and not ok(n,u) then
  806. begin
  807. adjacent_ok:=false;
  808. break;
  809. end;
  810. end;
  811. end;
  812. end;
  813. function trgobj.conservative(u,v:Tsuperregister):boolean;
  814. var adj : Psuperregisterworklist;
  815. done : Tsuperregisterset; {To prevent that we count nodes twice.}
  816. i,k:word;
  817. n : tsuperregister;
  818. begin
  819. k:=0;
  820. supregset_reset(done,false,maxreg);
  821. with reginfo[u] do
  822. begin
  823. adj:=adjlist;
  824. if adj<>nil then
  825. for i:=1 to adj^.length do
  826. begin
  827. n:=adj^.buf^[i-1];
  828. if flags*[ri_coalesced,ri_selected]=[] then
  829. begin
  830. supregset_include(done,n);
  831. if reginfo[n].degree>=usable_registers_cnt then
  832. inc(k);
  833. end;
  834. end;
  835. end;
  836. adj:=reginfo[v].adjlist;
  837. if adj<>nil then
  838. for i:=1 to adj^.length do
  839. begin
  840. n:=adj^.buf^[i-1];
  841. if not supregset_in(done,n) and
  842. (reginfo[n].degree>=usable_registers_cnt) and
  843. (reginfo[u].flags*[ri_coalesced,ri_selected]=[]) then
  844. inc(k);
  845. end;
  846. conservative:=(k<usable_registers_cnt);
  847. end;
  848. procedure trgobj.combine(u,v:Tsuperregister);
  849. var adj : Psuperregisterworklist;
  850. i,n,p,q:cardinal;
  851. t : tsuperregister;
  852. searched:Tlinkedlistitem;
  853. label l1;
  854. begin
  855. if not freezeworklist.delete(v) then
  856. spillworklist.delete(v);
  857. coalescednodes.add(v);
  858. include(reginfo[v].flags,ri_coalesced);
  859. reginfo[v].alias:=u;
  860. {Combine both movelists. Since the movelists are sets, only add
  861. elements that are not already present. The movelists cannot be
  862. empty by definition; nodes are only coalesced if there is a move
  863. between them. To prevent quadratic time blowup (movelists of
  864. especially machine registers can get very large because of moves
  865. generated during calls) we need to go into disgusting complexity.
  866. (See webtbs/tw2242 for an example that stresses this.)
  867. We want to sort the movelist to be able to search logarithmically.
  868. Unfortunately, sorting the movelist every time before searching
  869. is counter-productive, since the movelist usually grows with a few
  870. items at a time. Therefore, we split the movelist into a sorted
  871. and an unsorted part and search through both. If the unsorted part
  872. becomes too large, we sort.}
  873. if assigned(reginfo[u].movelist) then
  874. begin
  875. {We have to weigh the cost of sorting the list against searching
  876. the cost of the unsorted part. I use factor of 8 here; if the
  877. number of items is less than 8 times the numer of unsorted items,
  878. we'll sort the list.}
  879. with reginfo[u].movelist^ do
  880. if header.count<8*(header.count-header.sorted_until) then
  881. sort_movelist(reginfo[u].movelist);
  882. if assigned(reginfo[v].movelist) then
  883. begin
  884. for n:=0 to reginfo[v].movelist^.header.count-1 do
  885. begin
  886. {Binary search the sorted part of the list.}
  887. searched:=reginfo[v].movelist^.data[n];
  888. p:=0;
  889. q:=reginfo[u].movelist^.header.sorted_until;
  890. i:=0;
  891. if q<>0 then
  892. repeat
  893. i:=(p+q) shr 1;
  894. if ptrint(searched)>ptrint(reginfo[u].movelist^.data[i]) then
  895. p:=i+1
  896. else
  897. q:=i;
  898. until p=q;
  899. with reginfo[u].movelist^ do
  900. if searched<>data[i] then
  901. begin
  902. {Linear search the unsorted part of the list.}
  903. for i:=header.sorted_until+1 to header.count-1 do
  904. if searched=data[i] then
  905. goto l1;
  906. {Not found -> add}
  907. add_to_movelist(u,searched);
  908. l1:
  909. end;
  910. end;
  911. end;
  912. end;
  913. enable_moves(v);
  914. adj:=reginfo[v].adjlist;
  915. if adj<>nil then
  916. for i:=1 to adj^.length do
  917. begin
  918. t:=adj^.buf^[i-1];
  919. with reginfo[t] do
  920. if not(ri_coalesced in flags) then
  921. begin
  922. {t has a connection to v. Since we are adding v to u, we
  923. need to connect t to u. However, beware if t was already
  924. connected to u...}
  925. if (ibitmap[t,u]) and not (ri_selected in flags) then
  926. {... because in that case, we are actually removing an edge
  927. and the degree of t decreases.}
  928. decrement_degree(t)
  929. else
  930. begin
  931. add_edge(t,u);
  932. {We have added an edge to t and u. So their degree increases.
  933. However, v is added to u. That means its neighbours will
  934. no longer point to v, but to u instead. Therefore, only the
  935. degree of u increases.}
  936. if (u>=first_imaginary) and not (ri_selected in flags) then
  937. inc(reginfo[u].degree);
  938. end;
  939. end;
  940. end;
  941. if (reginfo[u].degree>=usable_registers_cnt) and freezeworklist.delete(u) then
  942. spillworklist.add(u);
  943. end;
  944. procedure trgobj.coalesce;
  945. var m:Tmoveins;
  946. x,y,u,v:Tsuperregister;
  947. begin
  948. m:=Tmoveins(worklist_moves.getfirst);
  949. x:=get_alias(m.x);
  950. y:=get_alias(m.y);
  951. if (y<first_imaginary) then
  952. begin
  953. u:=y;
  954. v:=x;
  955. end
  956. else
  957. begin
  958. u:=x;
  959. v:=y;
  960. end;
  961. if (u=v) then
  962. begin
  963. m.moveset:=ms_coalesced_moves; {Already coalesced.}
  964. coalesced_moves.insert(m);
  965. add_worklist(u);
  966. end
  967. {Do u and v interfere? In that case the move is constrained. Two
  968. precoloured nodes interfere allways. If v is precoloured, by the above
  969. code u is precoloured, thus interference...}
  970. else if (v<first_imaginary) or ibitmap[u,v] then
  971. begin
  972. m.moveset:=ms_constrained_moves; {Cannot coalesce yet...}
  973. constrained_moves.insert(m);
  974. add_worklist(u);
  975. add_worklist(v);
  976. end
  977. {Next test: is it possible and a good idea to coalesce??}
  978. else if ((u<first_imaginary) and adjacent_ok(u,v)) or
  979. ((u>=first_imaginary) and conservative(u,v)) then
  980. begin
  981. m.moveset:=ms_coalesced_moves; {Move coalesced!}
  982. coalesced_moves.insert(m);
  983. combine(u,v);
  984. add_worklist(u);
  985. end
  986. else
  987. begin
  988. m.moveset:=ms_active_moves;
  989. active_moves.insert(m);
  990. end;
  991. end;
  992. procedure trgobj.freeze_moves(u:Tsuperregister);
  993. var i:cardinal;
  994. m:Tlinkedlistitem;
  995. v,x,y:Tsuperregister;
  996. begin
  997. if reginfo[u].movelist<>nil then
  998. for i:=0 to reginfo[u].movelist^.header.count-1 do
  999. begin
  1000. m:=reginfo[u].movelist^.data[i];
  1001. if Tmoveins(m).moveset in [ms_worklist_moves,ms_active_moves] then
  1002. begin
  1003. x:=Tmoveins(m).x;
  1004. y:=Tmoveins(m).y;
  1005. if get_alias(y)=get_alias(u) then
  1006. v:=get_alias(x)
  1007. else
  1008. v:=get_alias(y);
  1009. {Move m from active_moves/worklist_moves to frozen_moves.}
  1010. if Tmoveins(m).moveset=ms_active_moves then
  1011. active_moves.remove(m)
  1012. else
  1013. worklist_moves.remove(m);
  1014. Tmoveins(m).moveset:=ms_frozen_moves;
  1015. frozen_moves.insert(m);
  1016. if (v>=first_imaginary) and not(move_related(v)) and
  1017. (reginfo[v].degree<usable_registers_cnt) then
  1018. begin
  1019. freezeworklist.delete(v);
  1020. simplifyworklist.add(v);
  1021. end;
  1022. end;
  1023. end;
  1024. end;
  1025. procedure trgobj.freeze;
  1026. var n:Tsuperregister;
  1027. begin
  1028. { We need to take a random element out of the freezeworklist. We take
  1029. the last element. Dirty code! }
  1030. n:=freezeworklist.get;
  1031. {Add it to the simplifyworklist.}
  1032. simplifyworklist.add(n);
  1033. freeze_moves(n);
  1034. end;
  1035. procedure trgobj.select_spill;
  1036. var
  1037. n : tsuperregister;
  1038. adj : psuperregisterworklist;
  1039. max,p,i:word;
  1040. begin
  1041. { We must look for the element with the most interferences in the
  1042. spillworklist. This is required because those registers are creating
  1043. the most conflicts and keeping them in a register will not reduce the
  1044. complexity and even can cause the help registers for the spilling code
  1045. to get too much conflicts with the result that the spilling code
  1046. will never converge (PFV) }
  1047. max:=0;
  1048. p:=0;
  1049. with spillworklist do
  1050. begin
  1051. {Safe: This procedure is only called if length<>0}
  1052. for i:=0 to length-1 do
  1053. begin
  1054. adj:=reginfo[buf^[i]].adjlist;
  1055. if assigned(adj) and (adj^.length>max) then
  1056. begin
  1057. p:=i;
  1058. max:=adj^.length;
  1059. end;
  1060. end;
  1061. n:=buf^[p];
  1062. deleteidx(p);
  1063. end;
  1064. simplifyworklist.add(n);
  1065. freeze_moves(n);
  1066. end;
  1067. procedure trgobj.assign_colours;
  1068. {Assign_colours assigns the actual colours to the registers.}
  1069. var adj : Psuperregisterworklist;
  1070. i,j,k : word;
  1071. n,a,c : Tsuperregister;
  1072. colourednodes : Tsuperregisterset;
  1073. adj_colours:set of 0..255;
  1074. found : boolean;
  1075. begin
  1076. spillednodes.clear;
  1077. {Reset colours}
  1078. for n:=0 to maxreg-1 do
  1079. reginfo[n].colour:=n;
  1080. {Colour the cpu registers...}
  1081. supregset_reset(colourednodes,false,maxreg);
  1082. for n:=0 to first_imaginary-1 do
  1083. supregset_include(colourednodes,n);
  1084. {Now colour the imaginary registers on the select-stack.}
  1085. for i:=selectstack.length downto 1 do
  1086. begin
  1087. n:=selectstack.buf^[i-1];
  1088. {Create a list of colours that we cannot assign to n.}
  1089. adj_colours:=[];
  1090. adj:=reginfo[n].adjlist;
  1091. if adj<>nil then
  1092. for j:=0 to adj^.length-1 do
  1093. begin
  1094. a:=get_alias(adj^.buf^[j]);
  1095. if supregset_in(colourednodes,a) and (reginfo[a].colour<=255) then
  1096. include(adj_colours,reginfo[a].colour);
  1097. end;
  1098. if regtype=R_INTREGISTER then
  1099. include(adj_colours,RS_STACK_POINTER_REG);
  1100. {Assume a spill by default...}
  1101. found:=false;
  1102. {Search for a colour not in this list.}
  1103. for k:=0 to usable_registers_cnt-1 do
  1104. begin
  1105. c:=usable_registers[k];
  1106. if not(c in adj_colours) then
  1107. begin
  1108. reginfo[n].colour:=c;
  1109. found:=true;
  1110. supregset_include(colourednodes,n);
  1111. include(used_in_proc,c);
  1112. break;
  1113. end;
  1114. end;
  1115. if not found then
  1116. spillednodes.add(n);
  1117. end;
  1118. {Finally colour the nodes that were coalesced.}
  1119. for i:=1 to coalescednodes.length do
  1120. begin
  1121. n:=coalescednodes.buf^[i-1];
  1122. k:=get_alias(n);
  1123. reginfo[n].colour:=reginfo[k].colour;
  1124. if reginfo[k].colour<maxcpuregister then
  1125. include(used_in_proc,reginfo[k].colour);
  1126. end;
  1127. end;
  1128. procedure trgobj.colour_registers;
  1129. begin
  1130. repeat
  1131. if simplifyworklist.length<>0 then
  1132. simplify
  1133. else if not(worklist_moves.empty) then
  1134. coalesce
  1135. else if freezeworklist.length<>0 then
  1136. freeze
  1137. else if spillworklist.length<>0 then
  1138. select_spill;
  1139. until (simplifyworklist.length=0) and
  1140. worklist_moves.empty and
  1141. (freezeworklist.length=0) and
  1142. (spillworklist.length=0);
  1143. assign_colours;
  1144. end;
  1145. procedure trgobj.epilogue_colouring;
  1146. var
  1147. i : Tsuperregister;
  1148. begin
  1149. worklist_moves.clear;
  1150. active_moves.destroy;
  1151. active_moves:=nil;
  1152. frozen_moves.destroy;
  1153. frozen_moves:=nil;
  1154. coalesced_moves.destroy;
  1155. coalesced_moves:=nil;
  1156. constrained_moves.destroy;
  1157. constrained_moves:=nil;
  1158. for i:=0 to maxreg-1 do
  1159. with reginfo[i] do
  1160. if movelist<>nil then
  1161. begin
  1162. dispose(movelist);
  1163. movelist:=nil;
  1164. end;
  1165. end;
  1166. procedure trgobj.clear_interferences(u:Tsuperregister);
  1167. {Remove node u from the interference graph and remove all collected
  1168. move instructions it is associated with.}
  1169. var i : word;
  1170. v : Tsuperregister;
  1171. adj,adj2 : Psuperregisterworklist;
  1172. begin
  1173. adj:=reginfo[u].adjlist;
  1174. if adj<>nil then
  1175. begin
  1176. for i:=1 to adj^.length do
  1177. begin
  1178. v:=adj^.buf^[i-1];
  1179. {Remove (u,v) and (v,u) from bitmap.}
  1180. ibitmap[u,v]:=false;
  1181. ibitmap[v,u]:=false;
  1182. {Remove (v,u) from adjacency list.}
  1183. adj2:=reginfo[v].adjlist;
  1184. if adj2<>nil then
  1185. begin
  1186. adj2^.delete(u);
  1187. if adj2^.length=0 then
  1188. begin
  1189. dispose(adj2,done);
  1190. reginfo[v].adjlist:=nil;
  1191. end;
  1192. end;
  1193. end;
  1194. {Remove ( u,* ) from adjacency list.}
  1195. dispose(adj,done);
  1196. reginfo[u].adjlist:=nil;
  1197. end;
  1198. end;
  1199. function trgobj.getregisterinline(list:Taasmoutput;subreg:Tsubregister):Tregister;
  1200. var
  1201. p : Tsuperregister;
  1202. r : Tregister;
  1203. begin
  1204. p:=getnewreg(subreg);
  1205. live_registers.add(p);
  1206. result:=newreg(regtype,p,subreg);
  1207. add_edges_used(p);
  1208. add_constraints(result);
  1209. end;
  1210. procedure trgobj.ungetregisterinline(list:Taasmoutput;r:Tregister);
  1211. var
  1212. supreg:Tsuperregister;
  1213. begin
  1214. supreg:=getsupreg(r);
  1215. live_registers.delete(supreg);
  1216. insert_regalloc_info(list,supreg);
  1217. end;
  1218. procedure trgobj.insert_regalloc_info(list:Taasmoutput;u:tsuperregister);
  1219. var
  1220. p : tai;
  1221. r : tregister;
  1222. begin
  1223. { Insert regallocs for all imaginary registers }
  1224. with reginfo[u] do
  1225. begin
  1226. r:=newreg(regtype,u,subreg);
  1227. if assigned(live_start) then
  1228. begin
  1229. list.insertbefore(Tai_regalloc.alloc(r,live_start),live_start);
  1230. { Insert live end deallocation before reg allocations
  1231. to reduce conflicts }
  1232. p:=live_end;
  1233. while assigned(p) and
  1234. assigned(p.previous) and
  1235. (tai(p.previous).typ=ait_regalloc) and
  1236. (tai_regalloc(p.previous).ratype=ra_alloc) and
  1237. (tai_regalloc(p.previous).reg<>r) do
  1238. p:=tai(p.previous);
  1239. { , but add release after sync }
  1240. if assigned(p) and
  1241. (p.typ=ait_regalloc) and
  1242. (tai_regalloc(p).ratype=ra_sync) then
  1243. p:=tai(p.next);
  1244. if assigned(p) then
  1245. list.insertbefore(Tai_regalloc.dealloc(r,live_end),p)
  1246. else
  1247. list.concat(Tai_regalloc.dealloc(r,live_end));
  1248. end
  1249. {$ifdef EXTDEBUG}
  1250. else
  1251. Comment(V_Warning,'Register '+std_regname(r)+' not used');
  1252. {$endif EXTDEBUG}
  1253. end;
  1254. end;
  1255. procedure trgobj.insert_regalloc_info_all(list:Taasmoutput);
  1256. var
  1257. supreg : tsuperregister;
  1258. begin
  1259. { Insert regallocs for all imaginary registers }
  1260. for supreg:=first_imaginary to maxreg-1 do
  1261. insert_regalloc_info(list,supreg);
  1262. end;
  1263. procedure trgobj.add_cpu_interferences(p : tai);
  1264. begin
  1265. end;
  1266. procedure trgobj.generate_interference_graph(list:Taasmoutput;headertai:tai);
  1267. var
  1268. p : tai;
  1269. i : integer;
  1270. supreg : tsuperregister;
  1271. begin
  1272. { All allocations are available. Now we can generate the
  1273. interference graph. Walk through all instructions, we can
  1274. start with the headertai, because before the header tai is
  1275. only symbols. }
  1276. live_registers.clear;
  1277. //live_registers.add(RS_STACK_POINTER_REG);
  1278. //live_registers.add(RS_FRAME_POINTER_REG);
  1279. p:=headertai;
  1280. while assigned(p) do
  1281. begin
  1282. if p.typ=ait_regalloc then
  1283. with Tai_regalloc(p) do
  1284. begin
  1285. if (getregtype(reg)=regtype) then
  1286. begin
  1287. supreg:=getsupreg(reg);
  1288. case ratype of
  1289. ra_alloc :
  1290. begin
  1291. live_registers.add(supreg);
  1292. add_edges_used(supreg);
  1293. end;
  1294. ra_dealloc :
  1295. begin
  1296. live_registers.delete(supreg);
  1297. add_edges_used(supreg);
  1298. end;
  1299. end;
  1300. { constraints needs always to be updated }
  1301. add_constraints(reg);
  1302. end;
  1303. end;
  1304. add_cpu_interferences(p);
  1305. p:=Tai(p.next);
  1306. end;
  1307. {$ifdef EXTDEBUG}
  1308. if live_registers.length>0 then
  1309. begin
  1310. for i:=0 to live_registers.length-1 do
  1311. begin
  1312. { Only report for imaginary registers }
  1313. if live_registers.buf^[i]>=first_imaginary then
  1314. Comment(V_Warning,'Register '+std_regname(newreg(R_INTREGISTER,live_registers.buf^[i],defaultsub))+' not released');
  1315. end;
  1316. end;
  1317. {$endif}
  1318. end;
  1319. procedure Trgobj.translate_registers(list:taasmoutput);
  1320. var
  1321. hp,p,q:Tai;
  1322. i:shortint;
  1323. {$ifdef arm}
  1324. so:pshifterop;
  1325. {$endif arm}
  1326. begin
  1327. { Leave when no imaginary registers are used }
  1328. if maxreg<=first_imaginary then
  1329. exit;
  1330. p:=Tai(list.first);
  1331. while assigned(p) do
  1332. begin
  1333. case p.typ of
  1334. ait_regalloc:
  1335. with Tai_regalloc(p) do
  1336. begin
  1337. if (getregtype(reg)=regtype) then
  1338. begin
  1339. { Only alloc/dealloc is needed for the optimizer, remove
  1340. other regalloc }
  1341. if not(ratype in [ra_alloc,ra_dealloc]) then
  1342. begin
  1343. q:=Tai(next);
  1344. list.remove(p);
  1345. p.free;
  1346. p:=q;
  1347. continue;
  1348. end
  1349. else
  1350. begin
  1351. setsupreg(reg,reginfo[getsupreg(reg)].colour);
  1352. {
  1353. Remove sequences of release and
  1354. allocation of the same register like. Other combinations
  1355. of release/allocate need to stay in the list.
  1356. # Register X released
  1357. # Register X allocated
  1358. }
  1359. if assigned(previous) and
  1360. (ratype=ra_alloc) and
  1361. (Tai(previous).typ=ait_regalloc) and
  1362. (Tai_regalloc(previous).reg=reg) and
  1363. (Tai_regalloc(previous).ratype=ra_dealloc) then
  1364. begin
  1365. q:=Tai(next);
  1366. hp:=tai(previous);
  1367. list.remove(hp);
  1368. hp.free;
  1369. list.remove(p);
  1370. p.free;
  1371. p:=q;
  1372. continue;
  1373. end;
  1374. end;
  1375. end;
  1376. end;
  1377. ait_instruction:
  1378. with Taicpu(p) do
  1379. begin
  1380. aktfilepos:=fileinfo;
  1381. for i:=0 to ops-1 do
  1382. with oper[i]^ do
  1383. case typ of
  1384. Top_reg:
  1385. if (getregtype(reg)=regtype) then
  1386. setsupreg(reg,reginfo[getsupreg(reg)].colour);
  1387. Top_ref:
  1388. begin
  1389. if regtype=R_INTREGISTER then
  1390. with ref^ do
  1391. begin
  1392. if base<>NR_NO then
  1393. setsupreg(base,reginfo[getsupreg(base)].colour);
  1394. if index<>NR_NO then
  1395. setsupreg(index,reginfo[getsupreg(index)].colour);
  1396. end;
  1397. end;
  1398. {$ifdef arm}
  1399. Top_shifterop:
  1400. begin
  1401. so:=shifterop;
  1402. if so^.rs<>NR_NO then
  1403. setsupreg(so^.rs,reginfo[getsupreg(so^.rs)].colour);
  1404. end;
  1405. {$endif arm}
  1406. end;
  1407. { Maybe the operation can be removed when
  1408. it is a move and both arguments are the same }
  1409. if is_same_reg_move(regtype) then
  1410. begin
  1411. q:=Tai(p.next);
  1412. list.remove(p);
  1413. p.free;
  1414. p:=q;
  1415. continue;
  1416. end;
  1417. end;
  1418. end;
  1419. p:=Tai(p.next);
  1420. end;
  1421. aktfilepos:=current_procinfo.exitpos;
  1422. end;
  1423. function trgobj.spill_registers(list:Taasmoutput;headertai:tai):boolean;
  1424. { Returns true if any help registers have been used }
  1425. var
  1426. i : word;
  1427. t : tsuperregister;
  1428. p,q : Tai;
  1429. regs_to_spill_set:Tsuperregisterset;
  1430. spill_temps : ^Tspill_temp_list;
  1431. supreg : tsuperregister;
  1432. templist : taasmoutput;
  1433. begin
  1434. spill_registers:=false;
  1435. live_registers.clear;
  1436. for i:=first_imaginary to maxreg-1 do
  1437. exclude(reginfo[i].flags,ri_selected);
  1438. spill_temps:=allocmem(sizeof(treference)*maxreg);
  1439. supregset_reset(regs_to_spill_set,false,$ffff);
  1440. { Allocate temps and insert in front of the list }
  1441. templist:=taasmoutput.create;
  1442. {Safe: this procedure is only called if there are spilled nodes.}
  1443. with spillednodes do
  1444. for i:=0 to length-1 do
  1445. begin
  1446. t:=buf^[i];
  1447. {Alternative representation.}
  1448. supregset_include(regs_to_spill_set,t);
  1449. {Clear all interferences of the spilled register.}
  1450. clear_interferences(t);
  1451. {Get a temp for the spilled register, the size must at least equal a complete register,
  1452. take also care of the fact that subreg can be larger than a single register like doubles
  1453. that occupy 2 registers }
  1454. tg.gettemp(templist,
  1455. max(tcgsize2size[reg_cgsize(newreg(regtype,t,R_SUBWHOLE))],
  1456. tcgsize2size[reg_cgsize(newreg(regtype,t,reginfo[t].subreg))]),
  1457. tt_noreuse,spill_temps^[t]);
  1458. end;
  1459. list.insertlistafter(headertai,templist);
  1460. templist.free;
  1461. { Walk through all instructions, we can start with the headertai,
  1462. because before the header tai is only symbols }
  1463. p:=headertai;
  1464. while assigned(p) do
  1465. begin
  1466. case p.typ of
  1467. ait_regalloc:
  1468. with Tai_regalloc(p) do
  1469. begin
  1470. if (getregtype(reg)=regtype) then
  1471. begin
  1472. {A register allocation of a spilled register can be removed.}
  1473. supreg:=getsupreg(reg);
  1474. if supregset_in(regs_to_spill_set,supreg) then
  1475. begin
  1476. q:=Tai(p.next);
  1477. list.remove(p);
  1478. p.free;
  1479. p:=q;
  1480. continue;
  1481. end
  1482. else
  1483. begin
  1484. case ratype of
  1485. ra_alloc :
  1486. live_registers.add(supreg);
  1487. ra_dealloc :
  1488. live_registers.delete(supreg);
  1489. end;
  1490. end;
  1491. end;
  1492. end;
  1493. ait_instruction:
  1494. with Taicpu(p) do
  1495. begin
  1496. aktfilepos:=fileinfo;
  1497. if instr_spill_register(list,taicpu(p),regs_to_spill_set,spill_temps^) then
  1498. spill_registers:=true;
  1499. end;
  1500. end;
  1501. p:=Tai(p.next);
  1502. end;
  1503. aktfilepos:=current_procinfo.exitpos;
  1504. {Safe: this procedure is only called if there are spilled nodes.}
  1505. with spillednodes do
  1506. for i:=0 to length-1 do
  1507. tg.ungettemp(list,spill_temps^[buf^[i]]);
  1508. freemem(spill_temps);
  1509. end;
  1510. function trgobj.do_spill_replace(list:Taasmoutput;instr:taicpu;orgreg:tsuperregister;const spilltemp:treference):boolean;
  1511. begin
  1512. result:=false;
  1513. end;
  1514. procedure Trgobj.do_spill_read(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  1515. begin
  1516. list.insertafter(spilling_create_load(spilltemp,tempreg),pos);
  1517. end;
  1518. procedure Trgobj.do_spill_written(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  1519. begin
  1520. list.insertafter(spilling_create_store(tempreg,spilltemp),pos);
  1521. end;
  1522. function trgobj.get_spill_subreg(r : tregister) : tsubregister;
  1523. begin
  1524. result:=defaultsub;
  1525. end;
  1526. function trgobj.instr_spill_register(list:Taasmoutput;
  1527. instr:taicpu;
  1528. const r:Tsuperregisterset;
  1529. const spilltemplist:Tspill_temp_list): boolean;
  1530. var
  1531. counter, regindex: longint;
  1532. regs: tspillregsinfo;
  1533. spilled: boolean;
  1534. procedure addreginfo(reg: tregister; operation: topertype);
  1535. var
  1536. i, tmpindex: longint;
  1537. supreg : tsuperregister;
  1538. begin
  1539. tmpindex := regindex;
  1540. supreg:=getsupreg(reg);
  1541. { did we already encounter this register? }
  1542. for i := 0 to pred(regindex) do
  1543. if (regs[i].orgreg = supreg) then
  1544. begin
  1545. tmpindex := i;
  1546. break;
  1547. end;
  1548. if tmpindex > high(regs) then
  1549. internalerror(2003120301);
  1550. regs[tmpindex].orgreg := supreg;
  1551. regs[tmpindex].spillreg:=reg;
  1552. if supregset_in(r,supreg) then
  1553. begin
  1554. { add/update info on this register }
  1555. regs[tmpindex].mustbespilled := true;
  1556. case operation of
  1557. operand_read:
  1558. regs[tmpindex].regread := true;
  1559. operand_write:
  1560. regs[tmpindex].regwritten := true;
  1561. operand_readwrite:
  1562. begin
  1563. regs[tmpindex].regread := true;
  1564. regs[tmpindex].regwritten := true;
  1565. end;
  1566. end;
  1567. spilled := true;
  1568. end;
  1569. inc(regindex,ord(regindex=tmpindex));
  1570. end;
  1571. procedure tryreplacereg(var reg: tregister);
  1572. var
  1573. i: longint;
  1574. supreg: tsuperregister;
  1575. begin
  1576. supreg:=getsupreg(reg);
  1577. for i:=0 to pred(regindex) do
  1578. if (regs[i].mustbespilled) and
  1579. (regs[i].orgreg=supreg) then
  1580. begin
  1581. { Only replace supreg }
  1582. setsupreg(reg,getsupreg(regs[i].tempreg));
  1583. break;
  1584. end;
  1585. end;
  1586. var
  1587. loadpos,
  1588. storepos : tai;
  1589. oldlive_registers : tsuperregisterworklist;
  1590. begin
  1591. result := false;
  1592. fillchar(regs,sizeof(regs),0);
  1593. for counter := low(regs) to high(regs) do
  1594. regs[counter].orgreg := RS_INVALID;
  1595. spilled := false;
  1596. regindex := 0;
  1597. { check whether and if so which and how (read/written) this instructions contains
  1598. registers that must be spilled }
  1599. for counter := 0 to instr.ops-1 do
  1600. with instr.oper[counter]^ do
  1601. begin
  1602. case typ of
  1603. top_reg:
  1604. begin
  1605. if (getregtype(reg) = regtype) then
  1606. addreginfo(reg,instr.spilling_get_operation_type(counter));
  1607. end;
  1608. top_ref:
  1609. begin
  1610. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1611. with ref^ do
  1612. begin
  1613. if (base <> NR_NO) then
  1614. addreginfo(base,operand_read);
  1615. if (index <> NR_NO) then
  1616. addreginfo(index,operand_read);
  1617. end;
  1618. end;
  1619. {$ifdef ARM}
  1620. top_shifterop:
  1621. begin
  1622. if shifterop^.rs<>NR_NO then
  1623. addreginfo(shifterop^.rs,operand_read);
  1624. end;
  1625. {$endif ARM}
  1626. end;
  1627. end;
  1628. { if no spilling for this instruction we can leave }
  1629. if not spilled then
  1630. exit;
  1631. {$ifdef x86}
  1632. { Try replacing the register with the spilltemp. This is usefull only
  1633. for the i386,x86_64 that support memory locations for several instructions }
  1634. for counter := 0 to pred(regindex) do
  1635. with regs[counter] do
  1636. begin
  1637. if mustbespilled then
  1638. begin
  1639. if do_spill_replace(list,instr,orgreg,spilltemplist[orgreg]) then
  1640. mustbespilled:=false;
  1641. end;
  1642. end;
  1643. {$endif x86}
  1644. {
  1645. There are registers that need are spilled. We generate the
  1646. following code for it. The used positions where code need
  1647. to be inserted are marked using #. Note that code is always inserted
  1648. before the positions using pos.previous. This way the position is always
  1649. the same since pos doesn't change, but pos.previous is modified everytime
  1650. new code is inserted.
  1651. [
  1652. - reg_allocs load spills
  1653. - load spills
  1654. ]
  1655. [#loadpos
  1656. - reg_deallocs
  1657. - reg_allocs
  1658. ]
  1659. [
  1660. - reg_deallocs for load-only spills
  1661. - reg_allocs for store-only spills
  1662. ]
  1663. [#instr
  1664. - original instruction
  1665. ]
  1666. [
  1667. - store spills
  1668. - reg_deallocs store spills
  1669. ]
  1670. [#storepos
  1671. ]
  1672. }
  1673. result := true;
  1674. oldlive_registers.copyfrom(live_registers);
  1675. { Process all tai_regallocs belonging to this instruction. All
  1676. released registers are also added to the live_registers because
  1677. they can't be used during the spilling }
  1678. loadpos:=tai(instr.previous);
  1679. while assigned(loadpos) and
  1680. (loadpos.typ=ait_regalloc) and
  1681. (tai_regalloc(loadpos).instr=instr) do
  1682. begin
  1683. if tai_regalloc(loadpos).ratype=ra_dealloc then
  1684. live_registers.add(getsupreg(tai_regalloc(loadpos).reg));
  1685. loadpos:=tai(loadpos.previous);
  1686. end;
  1687. loadpos:=tai(loadpos.next);
  1688. { Load the spilled registers }
  1689. for counter := 0 to pred(regindex) do
  1690. with regs[counter] do
  1691. begin
  1692. if mustbespilled and regread then
  1693. begin
  1694. tempreg:=getregisterinline(list,get_spill_subreg(regs[counter].spillreg));
  1695. do_spill_read(list,tai(loadpos.previous),spilltemplist[orgreg],tempreg);
  1696. end;
  1697. end;
  1698. { Release temp registers of read-only registers, and add reference of the instruction
  1699. to the reginfo }
  1700. for counter := 0 to pred(regindex) do
  1701. with regs[counter] do
  1702. begin
  1703. if mustbespilled and regread and (not regwritten) then
  1704. begin
  1705. { The original instruction will be the next that uses this register }
  1706. add_reg_instruction(instr,tempreg);
  1707. ungetregisterinline(list,tempreg);
  1708. end;
  1709. end;
  1710. { Allocate temp registers of write-only registers, and add reference of the instruction
  1711. to the reginfo }
  1712. for counter := 0 to pred(regindex) do
  1713. with regs[counter] do
  1714. begin
  1715. if mustbespilled and regwritten then
  1716. begin
  1717. { When the register is also loaded there is already a register assigned }
  1718. if (not regread) then
  1719. tempreg:=getregisterinline(list,get_spill_subreg(regs[counter].spillreg));
  1720. { The original instruction will be the next that uses this register, this
  1721. also needs to be done for read-write registers }
  1722. add_reg_instruction(instr,tempreg);
  1723. end;
  1724. end;
  1725. { store the spilled registers }
  1726. storepos:=tai(instr.next);
  1727. for counter := 0 to pred(regindex) do
  1728. with regs[counter] do
  1729. begin
  1730. if mustbespilled and regwritten then
  1731. begin
  1732. do_spill_written(list,tai(storepos.previous),spilltemplist[orgreg],tempreg);
  1733. ungetregisterinline(list,tempreg);
  1734. end;
  1735. end;
  1736. { now all spilling code is generated we can restore the live registers. This
  1737. must be done after the store because the store can need an extra register
  1738. that also needs to conflict with the registers of the instruction }
  1739. live_registers.done;
  1740. live_registers:=oldlive_registers;
  1741. { substitute registers }
  1742. for counter:=0 to instr.ops-1 do
  1743. with instr.oper[counter]^ do
  1744. begin
  1745. case typ of
  1746. top_reg:
  1747. begin
  1748. if (getregtype(reg) = regtype) then
  1749. tryreplacereg(reg);
  1750. end;
  1751. top_ref:
  1752. begin
  1753. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1754. begin
  1755. tryreplacereg(ref^.base);
  1756. tryreplacereg(ref^.index);
  1757. end;
  1758. end;
  1759. {$ifdef ARM}
  1760. top_shifterop:
  1761. begin
  1762. tryreplacereg(shifterop^.rs);
  1763. end;
  1764. {$endif ARM}
  1765. end;
  1766. end;
  1767. end;
  1768. end.
  1769. {
  1770. $Log$
  1771. Revision 1.144 2004-10-24 17:04:01 peter
  1772. * during translation only process regalloc for the current regtype
  1773. Revision 1.143 2004/10/15 09:14:17 mazen
  1774. - remove $IFDEF DELPHI and related code
  1775. - remove $IFDEF FPCPROCVAR and related code
  1776. Revision 1.142 2004/10/13 21:12:51 peter
  1777. * -Or fixes for open array
  1778. Revision 1.141 2004/10/11 15:47:03 peter
  1779. * removed warning about register used only once
  1780. Revision 1.140 2004/10/06 20:14:08 peter
  1781. * live_registers must be restored after the spilling store code
  1782. is generate to add correct conflicts for extra temporary registers
  1783. Revision 1.139 2004/10/05 20:41:01 peter
  1784. * more spilling rewrites
  1785. Revision 1.138 2004/10/04 20:46:22 peter
  1786. * spilling code rewritten for x86. It now used the generic
  1787. spilling routines. Special x86 optimization still needs
  1788. to be added.
  1789. * Spilling fixed when both operands needed to be spilled
  1790. * Cleanup of spilling routine, do_spill_readwritten removed
  1791. Revision 1.137 2004/09/26 17:45:30 peter
  1792. * simple regvar support, not yet finished
  1793. Revision 1.136 2004/09/25 14:23:54 peter
  1794. * ungetregister is now only used for cpuregisters, renamed to
  1795. ungetcpuregister
  1796. * renamed (get|unget)explicitregister(s) to ..cpuregister
  1797. * removed location-release/reference_release
  1798. Revision 1.135 2004/09/21 17:25:12 peter
  1799. * paraloc branch merged
  1800. Revision 1.134.4.2 2004/09/21 17:03:26 peter
  1801. * Include aliases of coalesce registers when adding conflicts
  1802. Revision 1.134.4.1 2004/09/12 13:36:40 peter
  1803. * fixed alignment issues
  1804. Revision 1.134 2004/08/24 21:02:32 florian
  1805. * fixed longbool(<int64>) on sparc
  1806. Revision 1.133 2004/07/09 21:38:30 daniel
  1807. * Add check <= 255 when adding to adj_colours
  1808. Revision 1.132 2004/07/08 09:57:55 daniel
  1809. * Use a normal pascal set in assign_colours, since it only will contain
  1810. real registers
  1811. Revision 1.131 2004/07/07 17:35:26 daniel
  1812. * supregset_reset clears 8kb of memory. However, it is being called in
  1813. inner loops, see for example colour_registers. According to profile data
  1814. this causes fillchar to be the most time consuming procedure.
  1815. Some modifications done to make it clear less than 8kb of memory each
  1816. call. Divides time spent in fillchar by two, but it still is the no.1
  1817. procedure.
  1818. Revision 1.130 2004/06/22 18:24:18 florian
  1819. * fixed arm compilation
  1820. Revision 1.129 2004/06/20 08:55:30 florian
  1821. * logs truncated
  1822. Revision 1.128 2004/06/20 08:47:33 florian
  1823. * spilling of doubles on sparc fixed
  1824. Revision 1.127 2004/06/16 20:07:09 florian
  1825. * dwarf branch merged
  1826. Revision 1.126 2004/05/22 23:34:28 peter
  1827. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1828. Revision 1.125 2004/04/26 19:57:50 jonas
  1829. * do not remove "allocation,deallocation" pairs, as those are important
  1830. for the optimizer
  1831. Revision 1.124.2.3 2004/06/13 10:51:16 florian
  1832. * fixed several register allocator problems (sparc/arm)
  1833. }