rgobj.pas 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109
  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. { these can be removed by the register allocator and thus }
  1228. { live_start/end can become invalid in this case! (JM) }
  1229. while live_start.typ = ait_regalloc do
  1230. begin
  1231. if (live_end = live_start) then
  1232. live_end := tai(live_end.next);
  1233. live_start := tai(live_start.next);
  1234. end;
  1235. if not assigned(live_start) then
  1236. internalerror(2004103110);
  1237. list.insertbefore(Tai_regalloc.alloc(r,live_start),live_start);
  1238. { Insert live end deallocation before reg allocations
  1239. to reduce conflicts }
  1240. p:=live_end;
  1241. while assigned(p) and
  1242. assigned(p.previous) and
  1243. (tai(p.previous).typ=ait_regalloc) and
  1244. (tai_regalloc(p.previous).ratype=ra_alloc) and
  1245. (tai_regalloc(p.previous).reg<>r) do
  1246. p:=tai(p.previous);
  1247. { , but add release after sync }
  1248. if assigned(p) and
  1249. (p.typ=ait_regalloc) and
  1250. (tai_regalloc(p).ratype=ra_sync) then
  1251. p:=tai(p.next);
  1252. if assigned(p) then
  1253. list.insertbefore(Tai_regalloc.dealloc(r,live_end),p)
  1254. else
  1255. list.concat(Tai_regalloc.dealloc(r,live_end));
  1256. end
  1257. {$ifdef EXTDEBUG}
  1258. else
  1259. Comment(V_Warning,'Register '+std_regname(r)+' not used');
  1260. {$endif EXTDEBUG}
  1261. end;
  1262. end;
  1263. procedure trgobj.insert_regalloc_info_all(list:Taasmoutput);
  1264. var
  1265. supreg : tsuperregister;
  1266. begin
  1267. { Insert regallocs for all imaginary registers }
  1268. for supreg:=first_imaginary to maxreg-1 do
  1269. insert_regalloc_info(list,supreg);
  1270. end;
  1271. procedure trgobj.add_cpu_interferences(p : tai);
  1272. begin
  1273. end;
  1274. procedure trgobj.generate_interference_graph(list:Taasmoutput;headertai:tai);
  1275. var
  1276. p : tai;
  1277. i : integer;
  1278. supreg : tsuperregister;
  1279. begin
  1280. { All allocations are available. Now we can generate the
  1281. interference graph. Walk through all instructions, we can
  1282. start with the headertai, because before the header tai is
  1283. only symbols. }
  1284. live_registers.clear;
  1285. //live_registers.add(RS_STACK_POINTER_REG);
  1286. //live_registers.add(RS_FRAME_POINTER_REG);
  1287. p:=headertai;
  1288. while assigned(p) do
  1289. begin
  1290. if p.typ=ait_regalloc then
  1291. with Tai_regalloc(p) do
  1292. begin
  1293. if (getregtype(reg)=regtype) then
  1294. begin
  1295. supreg:=getsupreg(reg);
  1296. case ratype of
  1297. ra_alloc :
  1298. begin
  1299. live_registers.add(supreg);
  1300. add_edges_used(supreg);
  1301. end;
  1302. ra_dealloc :
  1303. begin
  1304. live_registers.delete(supreg);
  1305. add_edges_used(supreg);
  1306. end;
  1307. end;
  1308. { constraints needs always to be updated }
  1309. add_constraints(reg);
  1310. end;
  1311. end;
  1312. add_cpu_interferences(p);
  1313. p:=Tai(p.next);
  1314. end;
  1315. {$ifdef EXTDEBUG}
  1316. if live_registers.length>0 then
  1317. begin
  1318. for i:=0 to live_registers.length-1 do
  1319. begin
  1320. { Only report for imaginary registers }
  1321. if live_registers.buf^[i]>=first_imaginary then
  1322. Comment(V_Warning,'Register '+std_regname(newreg(R_INTREGISTER,live_registers.buf^[i],defaultsub))+' not released');
  1323. end;
  1324. end;
  1325. {$endif}
  1326. end;
  1327. procedure Trgobj.translate_registers(list:taasmoutput);
  1328. var
  1329. hp,p,q:Tai;
  1330. i:shortint;
  1331. {$ifdef arm}
  1332. so:pshifterop;
  1333. {$endif arm}
  1334. begin
  1335. { Leave when no imaginary registers are used }
  1336. if maxreg<=first_imaginary then
  1337. exit;
  1338. p:=Tai(list.first);
  1339. while assigned(p) do
  1340. begin
  1341. case p.typ of
  1342. ait_regalloc:
  1343. with Tai_regalloc(p) do
  1344. begin
  1345. if (getregtype(reg)=regtype) then
  1346. begin
  1347. { Only alloc/dealloc is needed for the optimizer, remove
  1348. other regalloc }
  1349. if not(ratype in [ra_alloc,ra_dealloc]) then
  1350. begin
  1351. q:=Tai(next);
  1352. list.remove(p);
  1353. p.free;
  1354. p:=q;
  1355. continue;
  1356. end
  1357. else
  1358. begin
  1359. setsupreg(reg,reginfo[getsupreg(reg)].colour);
  1360. {
  1361. Remove sequences of release and
  1362. allocation of the same register like. Other combinations
  1363. of release/allocate need to stay in the list.
  1364. # Register X released
  1365. # Register X allocated
  1366. }
  1367. if assigned(previous) and
  1368. (ratype=ra_alloc) and
  1369. (Tai(previous).typ=ait_regalloc) and
  1370. (Tai_regalloc(previous).reg=reg) and
  1371. (Tai_regalloc(previous).ratype=ra_dealloc) then
  1372. begin
  1373. q:=Tai(next);
  1374. hp:=tai(previous);
  1375. list.remove(hp);
  1376. hp.free;
  1377. list.remove(p);
  1378. p.free;
  1379. p:=q;
  1380. continue;
  1381. end;
  1382. end;
  1383. end;
  1384. end;
  1385. ait_instruction:
  1386. with Taicpu(p) do
  1387. begin
  1388. aktfilepos:=fileinfo;
  1389. for i:=0 to ops-1 do
  1390. with oper[i]^ do
  1391. case typ of
  1392. Top_reg:
  1393. if (getregtype(reg)=regtype) then
  1394. setsupreg(reg,reginfo[getsupreg(reg)].colour);
  1395. Top_ref:
  1396. begin
  1397. if regtype=R_INTREGISTER then
  1398. with ref^ do
  1399. begin
  1400. if base<>NR_NO then
  1401. setsupreg(base,reginfo[getsupreg(base)].colour);
  1402. if index<>NR_NO then
  1403. setsupreg(index,reginfo[getsupreg(index)].colour);
  1404. end;
  1405. end;
  1406. {$ifdef arm}
  1407. Top_shifterop:
  1408. begin
  1409. if regtype=R_INTREGISTER then
  1410. begin
  1411. so:=shifterop;
  1412. if so^.rs<>NR_NO then
  1413. setsupreg(so^.rs,reginfo[getsupreg(so^.rs)].colour);
  1414. end;
  1415. end;
  1416. {$endif arm}
  1417. end;
  1418. { Maybe the operation can be removed when
  1419. it is a move and both arguments are the same }
  1420. if is_same_reg_move(regtype) then
  1421. begin
  1422. q:=Tai(p.next);
  1423. list.remove(p);
  1424. p.free;
  1425. p:=q;
  1426. continue;
  1427. end;
  1428. end;
  1429. end;
  1430. p:=Tai(p.next);
  1431. end;
  1432. aktfilepos:=current_procinfo.exitpos;
  1433. end;
  1434. function trgobj.spill_registers(list:Taasmoutput;headertai:tai):boolean;
  1435. { Returns true if any help registers have been used }
  1436. var
  1437. i : word;
  1438. t : tsuperregister;
  1439. p,q : Tai;
  1440. regs_to_spill_set:Tsuperregisterset;
  1441. spill_temps : ^Tspill_temp_list;
  1442. supreg : tsuperregister;
  1443. templist : taasmoutput;
  1444. begin
  1445. spill_registers:=false;
  1446. live_registers.clear;
  1447. for i:=first_imaginary to maxreg-1 do
  1448. exclude(reginfo[i].flags,ri_selected);
  1449. spill_temps:=allocmem(sizeof(treference)*maxreg);
  1450. supregset_reset(regs_to_spill_set,false,$ffff);
  1451. { Allocate temps and insert in front of the list }
  1452. templist:=taasmoutput.create;
  1453. {Safe: this procedure is only called if there are spilled nodes.}
  1454. with spillednodes do
  1455. for i:=0 to length-1 do
  1456. begin
  1457. t:=buf^[i];
  1458. {Alternative representation.}
  1459. supregset_include(regs_to_spill_set,t);
  1460. {Clear all interferences of the spilled register.}
  1461. clear_interferences(t);
  1462. {Get a temp for the spilled register, the size must at least equal a complete register,
  1463. take also care of the fact that subreg can be larger than a single register like doubles
  1464. that occupy 2 registers }
  1465. tg.gettemp(templist,
  1466. max(tcgsize2size[reg_cgsize(newreg(regtype,t,R_SUBWHOLE))],
  1467. tcgsize2size[reg_cgsize(newreg(regtype,t,reginfo[t].subreg))]),
  1468. tt_noreuse,spill_temps^[t]);
  1469. end;
  1470. list.insertlistafter(headertai,templist);
  1471. templist.free;
  1472. { Walk through all instructions, we can start with the headertai,
  1473. because before the header tai is only symbols }
  1474. p:=headertai;
  1475. while assigned(p) do
  1476. begin
  1477. case p.typ of
  1478. ait_regalloc:
  1479. with Tai_regalloc(p) do
  1480. begin
  1481. if (getregtype(reg)=regtype) then
  1482. begin
  1483. {A register allocation of a spilled register can be removed.}
  1484. supreg:=getsupreg(reg);
  1485. if supregset_in(regs_to_spill_set,supreg) then
  1486. begin
  1487. q:=Tai(p.next);
  1488. list.remove(p);
  1489. p.free;
  1490. p:=q;
  1491. continue;
  1492. end
  1493. else
  1494. begin
  1495. case ratype of
  1496. ra_alloc :
  1497. live_registers.add(supreg);
  1498. ra_dealloc :
  1499. live_registers.delete(supreg);
  1500. end;
  1501. end;
  1502. end;
  1503. end;
  1504. ait_instruction:
  1505. with Taicpu(p) do
  1506. begin
  1507. aktfilepos:=fileinfo;
  1508. if instr_spill_register(list,taicpu(p),regs_to_spill_set,spill_temps^) then
  1509. spill_registers:=true;
  1510. end;
  1511. end;
  1512. p:=Tai(p.next);
  1513. end;
  1514. aktfilepos:=current_procinfo.exitpos;
  1515. {Safe: this procedure is only called if there are spilled nodes.}
  1516. with spillednodes do
  1517. for i:=0 to length-1 do
  1518. tg.ungettemp(list,spill_temps^[buf^[i]]);
  1519. freemem(spill_temps);
  1520. end;
  1521. function trgobj.do_spill_replace(list:Taasmoutput;instr:taicpu;orgreg:tsuperregister;const spilltemp:treference):boolean;
  1522. begin
  1523. result:=false;
  1524. end;
  1525. procedure Trgobj.do_spill_read(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  1526. begin
  1527. list.insertafter(spilling_create_load(spilltemp,tempreg),pos);
  1528. end;
  1529. procedure Trgobj.do_spill_written(list:Taasmoutput;pos:tai;const spilltemp:treference;tempreg:tregister);
  1530. begin
  1531. list.insertafter(spilling_create_store(tempreg,spilltemp),pos);
  1532. end;
  1533. function trgobj.get_spill_subreg(r : tregister) : tsubregister;
  1534. begin
  1535. result:=defaultsub;
  1536. end;
  1537. function trgobj.instr_spill_register(list:Taasmoutput;
  1538. instr:taicpu;
  1539. const r:Tsuperregisterset;
  1540. const spilltemplist:Tspill_temp_list): boolean;
  1541. var
  1542. counter, regindex: longint;
  1543. regs: tspillregsinfo;
  1544. spilled: boolean;
  1545. procedure addreginfo(reg: tregister; operation: topertype);
  1546. var
  1547. i, tmpindex: longint;
  1548. supreg : tsuperregister;
  1549. begin
  1550. tmpindex := regindex;
  1551. supreg:=getsupreg(reg);
  1552. { did we already encounter this register? }
  1553. for i := 0 to pred(regindex) do
  1554. if (regs[i].orgreg = supreg) then
  1555. begin
  1556. tmpindex := i;
  1557. break;
  1558. end;
  1559. if tmpindex > high(regs) then
  1560. internalerror(2003120301);
  1561. regs[tmpindex].orgreg := supreg;
  1562. regs[tmpindex].spillreg:=reg;
  1563. if supregset_in(r,supreg) then
  1564. begin
  1565. { add/update info on this register }
  1566. regs[tmpindex].mustbespilled := true;
  1567. case operation of
  1568. operand_read:
  1569. regs[tmpindex].regread := true;
  1570. operand_write:
  1571. regs[tmpindex].regwritten := true;
  1572. operand_readwrite:
  1573. begin
  1574. regs[tmpindex].regread := true;
  1575. regs[tmpindex].regwritten := true;
  1576. end;
  1577. end;
  1578. spilled := true;
  1579. end;
  1580. inc(regindex,ord(regindex=tmpindex));
  1581. end;
  1582. procedure tryreplacereg(var reg: tregister);
  1583. var
  1584. i: longint;
  1585. supreg: tsuperregister;
  1586. begin
  1587. supreg:=getsupreg(reg);
  1588. for i:=0 to pred(regindex) do
  1589. if (regs[i].mustbespilled) and
  1590. (regs[i].orgreg=supreg) then
  1591. begin
  1592. { Only replace supreg }
  1593. setsupreg(reg,getsupreg(regs[i].tempreg));
  1594. break;
  1595. end;
  1596. end;
  1597. var
  1598. loadpos,
  1599. storepos : tai;
  1600. oldlive_registers : tsuperregisterworklist;
  1601. begin
  1602. result := false;
  1603. fillchar(regs,sizeof(regs),0);
  1604. for counter := low(regs) to high(regs) do
  1605. regs[counter].orgreg := RS_INVALID;
  1606. spilled := false;
  1607. regindex := 0;
  1608. { check whether and if so which and how (read/written) this instructions contains
  1609. registers that must be spilled }
  1610. for counter := 0 to instr.ops-1 do
  1611. with instr.oper[counter]^ do
  1612. begin
  1613. case typ of
  1614. top_reg:
  1615. begin
  1616. if (getregtype(reg) = regtype) then
  1617. addreginfo(reg,instr.spilling_get_operation_type(counter));
  1618. end;
  1619. top_ref:
  1620. begin
  1621. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1622. with ref^ do
  1623. begin
  1624. if (base <> NR_NO) then
  1625. addreginfo(base,operand_read);
  1626. if (index <> NR_NO) then
  1627. addreginfo(index,operand_read);
  1628. end;
  1629. end;
  1630. {$ifdef ARM}
  1631. top_shifterop:
  1632. begin
  1633. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1634. if shifterop^.rs<>NR_NO then
  1635. addreginfo(shifterop^.rs,operand_read);
  1636. end;
  1637. {$endif ARM}
  1638. end;
  1639. end;
  1640. { if no spilling for this instruction we can leave }
  1641. if not spilled then
  1642. exit;
  1643. {$ifdef x86}
  1644. { Try replacing the register with the spilltemp. This is usefull only
  1645. for the i386,x86_64 that support memory locations for several instructions }
  1646. for counter := 0 to pred(regindex) do
  1647. with regs[counter] do
  1648. begin
  1649. if mustbespilled then
  1650. begin
  1651. if do_spill_replace(list,instr,orgreg,spilltemplist[orgreg]) then
  1652. mustbespilled:=false;
  1653. end;
  1654. end;
  1655. {$endif x86}
  1656. {
  1657. There are registers that need are spilled. We generate the
  1658. following code for it. The used positions where code need
  1659. to be inserted are marked using #. Note that code is always inserted
  1660. before the positions using pos.previous. This way the position is always
  1661. the same since pos doesn't change, but pos.previous is modified everytime
  1662. new code is inserted.
  1663. [
  1664. - reg_allocs load spills
  1665. - load spills
  1666. ]
  1667. [#loadpos
  1668. - reg_deallocs
  1669. - reg_allocs
  1670. ]
  1671. [
  1672. - reg_deallocs for load-only spills
  1673. - reg_allocs for store-only spills
  1674. ]
  1675. [#instr
  1676. - original instruction
  1677. ]
  1678. [
  1679. - store spills
  1680. - reg_deallocs store spills
  1681. ]
  1682. [#storepos
  1683. ]
  1684. }
  1685. result := true;
  1686. oldlive_registers.copyfrom(live_registers);
  1687. { Process all tai_regallocs belonging to this instruction. All
  1688. released registers are also added to the live_registers because
  1689. they can't be used during the spilling }
  1690. loadpos:=tai(instr.previous);
  1691. while assigned(loadpos) and
  1692. (loadpos.typ=ait_regalloc) and
  1693. (tai_regalloc(loadpos).instr=instr) do
  1694. begin
  1695. if tai_regalloc(loadpos).ratype=ra_dealloc then
  1696. live_registers.add(getsupreg(tai_regalloc(loadpos).reg));
  1697. loadpos:=tai(loadpos.previous);
  1698. end;
  1699. loadpos:=tai(loadpos.next);
  1700. { Load the spilled registers }
  1701. for counter := 0 to pred(regindex) do
  1702. with regs[counter] do
  1703. begin
  1704. if mustbespilled and regread then
  1705. begin
  1706. tempreg:=getregisterinline(list,get_spill_subreg(regs[counter].spillreg));
  1707. do_spill_read(list,tai(loadpos.previous),spilltemplist[orgreg],tempreg);
  1708. end;
  1709. end;
  1710. { Release temp registers of read-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 regread and (not regwritten) then
  1716. begin
  1717. { The original instruction will be the next that uses this register }
  1718. add_reg_instruction(instr,tempreg);
  1719. ungetregisterinline(list,tempreg);
  1720. end;
  1721. end;
  1722. { Allocate temp registers of write-only registers, and add reference of the instruction
  1723. to the reginfo }
  1724. for counter := 0 to pred(regindex) do
  1725. with regs[counter] do
  1726. begin
  1727. if mustbespilled and regwritten then
  1728. begin
  1729. { When the register is also loaded there is already a register assigned }
  1730. if (not regread) then
  1731. tempreg:=getregisterinline(list,get_spill_subreg(regs[counter].spillreg));
  1732. { The original instruction will be the next that uses this register, this
  1733. also needs to be done for read-write registers }
  1734. add_reg_instruction(instr,tempreg);
  1735. end;
  1736. end;
  1737. { store the spilled registers }
  1738. storepos:=tai(instr.next);
  1739. for counter := 0 to pred(regindex) do
  1740. with regs[counter] do
  1741. begin
  1742. if mustbespilled and regwritten then
  1743. begin
  1744. do_spill_written(list,tai(storepos.previous),spilltemplist[orgreg],tempreg);
  1745. ungetregisterinline(list,tempreg);
  1746. end;
  1747. end;
  1748. { now all spilling code is generated we can restore the live registers. This
  1749. must be done after the store because the store can need an extra register
  1750. that also needs to conflict with the registers of the instruction }
  1751. live_registers.done;
  1752. live_registers:=oldlive_registers;
  1753. { substitute registers }
  1754. for counter:=0 to instr.ops-1 do
  1755. with instr.oper[counter]^ do
  1756. begin
  1757. case typ of
  1758. top_reg:
  1759. begin
  1760. if (getregtype(reg) = regtype) then
  1761. tryreplacereg(reg);
  1762. end;
  1763. top_ref:
  1764. begin
  1765. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1766. begin
  1767. tryreplacereg(ref^.base);
  1768. tryreplacereg(ref^.index);
  1769. end;
  1770. end;
  1771. {$ifdef ARM}
  1772. top_shifterop:
  1773. begin
  1774. if regtype in [R_INTREGISTER,R_ADDRESSREGISTER] then
  1775. tryreplacereg(shifterop^.rs);
  1776. end;
  1777. {$endif ARM}
  1778. end;
  1779. end;
  1780. end;
  1781. end.
  1782. {
  1783. $Log$
  1784. Revision 1.148 2004-10-31 23:18:29 jonas
  1785. * make sure live_start/end is never a tai_regalloc, as those can be
  1786. removed by the register allocator and thus become invalid. This fixed
  1787. make cycle with -Or for ppc, but I'm not sure what the warning on
  1788. symsym.pas:1663 means. Since the tlocation change, even regular make
  1789. cycle doesn't work anymore though...
  1790. Revision 1.147 2004/10/31 21:45:03 peter
  1791. * generic tlocation
  1792. * move tlocation to cgutils
  1793. Revision 1.146 2004/10/31 16:04:30 florian
  1794. * fixed compilation of system unit on arm
  1795. Revision 1.145 2004/10/30 15:21:37 florian
  1796. * fixed generic optimizer
  1797. * enabled generic optimizer for sparc
  1798. Revision 1.144 2004/10/24 17:04:01 peter
  1799. * during translation only process regalloc for the current regtype
  1800. Revision 1.143 2004/10/15 09:14:17 mazen
  1801. - remove $IFDEF DELPHI and related code
  1802. - remove $IFDEF FPCPROCVAR and related code
  1803. Revision 1.142 2004/10/13 21:12:51 peter
  1804. * -Or fixes for open array
  1805. Revision 1.141 2004/10/11 15:47:03 peter
  1806. * removed warning about register used only once
  1807. Revision 1.140 2004/10/06 20:14:08 peter
  1808. * live_registers must be restored after the spilling store code
  1809. is generate to add correct conflicts for extra temporary registers
  1810. Revision 1.139 2004/10/05 20:41:01 peter
  1811. * more spilling rewrites
  1812. Revision 1.138 2004/10/04 20:46:22 peter
  1813. * spilling code rewritten for x86. It now used the generic
  1814. spilling routines. Special x86 optimization still needs
  1815. to be added.
  1816. * Spilling fixed when both operands needed to be spilled
  1817. * Cleanup of spilling routine, do_spill_readwritten removed
  1818. Revision 1.137 2004/09/26 17:45:30 peter
  1819. * simple regvar support, not yet finished
  1820. Revision 1.136 2004/09/25 14:23:54 peter
  1821. * ungetregister is now only used for cpuregisters, renamed to
  1822. ungetcpuregister
  1823. * renamed (get|unget)explicitregister(s) to ..cpuregister
  1824. * removed location-release/reference_release
  1825. Revision 1.135 2004/09/21 17:25:12 peter
  1826. * paraloc branch merged
  1827. Revision 1.134.4.2 2004/09/21 17:03:26 peter
  1828. * Include aliases of coalesce registers when adding conflicts
  1829. Revision 1.134.4.1 2004/09/12 13:36:40 peter
  1830. * fixed alignment issues
  1831. Revision 1.134 2004/08/24 21:02:32 florian
  1832. * fixed longbool(<int64>) on sparc
  1833. Revision 1.133 2004/07/09 21:38:30 daniel
  1834. * Add check <= 255 when adding to adj_colours
  1835. Revision 1.132 2004/07/08 09:57:55 daniel
  1836. * Use a normal pascal set in assign_colours, since it only will contain
  1837. real registers
  1838. Revision 1.131 2004/07/07 17:35:26 daniel
  1839. * supregset_reset clears 8kb of memory. However, it is being called in
  1840. inner loops, see for example colour_registers. According to profile data
  1841. this causes fillchar to be the most time consuming procedure.
  1842. Some modifications done to make it clear less than 8kb of memory each
  1843. call. Divides time spent in fillchar by two, but it still is the no.1
  1844. procedure.
  1845. Revision 1.130 2004/06/22 18:24:18 florian
  1846. * fixed arm compilation
  1847. Revision 1.129 2004/06/20 08:55:30 florian
  1848. * logs truncated
  1849. Revision 1.128 2004/06/20 08:47:33 florian
  1850. * spilling of doubles on sparc fixed
  1851. Revision 1.127 2004/06/16 20:07:09 florian
  1852. * dwarf branch merged
  1853. Revision 1.126 2004/05/22 23:34:28 peter
  1854. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1855. Revision 1.125 2004/04/26 19:57:50 jonas
  1856. * do not remove "allocation,deallocation" pairs, as those are important
  1857. for the optimizer
  1858. Revision 1.124.2.3 2004/06/13 10:51:16 florian
  1859. * fixed several register allocator problems (sparc/arm)
  1860. }