regvars.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl and Jonas Maebe
  4. This unit handles register variable allocation
  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. unit regvars;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. aasmbase,aasmtai,aasmcpu,
  23. node,
  24. symsym,
  25. cpubase, cginfo, tgobj, rgobj;
  26. procedure assign_regvars(p: tnode);
  27. procedure load_regvars(asml: TAAsmoutput; p: tnode);
  28. procedure cleanup_regvars(asml: TAAsmoutput);
  29. procedure store_regvar(asml: TAAsmoutput; reg: tregister);
  30. procedure load_regvar(asml: TAAsmoutput; vsym: tvarsym);
  31. procedure load_regvar_reg(asml: TAAsmoutput; reg: tregister);
  32. procedure load_all_regvars(asml: TAAsmoutput);
  33. {$ifdef i386}
  34. procedure sync_regvars_other(list1, list2: taasmoutput; const regvarsloaded1,
  35. regvarsloaded2: regvarother_booleanarray);
  36. procedure sync_regvars_int(list1, list2: taasmoutput; const regvarsloaded1,
  37. regvarsloaded2: Tsupregset);
  38. {$endif i386}
  39. implementation
  40. uses
  41. globtype,systems,comphook,
  42. cutils,cclasses,verbose,globals,
  43. psub,
  44. symconst,symbase,symtype,symdef,paramgr,defutil,
  45. cpuinfo,cgbase,cgobj,rgcpu;
  46. procedure searchregvars(p : tnamedindexitem;arg:pointer);
  47. var
  48. i,j,k : longint;
  49. parasym : boolean;
  50. begin
  51. parasym:=pboolean(arg)^;
  52. if (tsym(p).typ=varsym) and (vo_regable in tvarsym(p).varoptions) then
  53. begin
  54. j:=tvarsym(p).refs;
  55. { parameter get a less value }
  56. if parasym then
  57. begin
  58. if cs_littlesize in aktglobalswitches then
  59. dec(j,1)
  60. else
  61. dec(j,100);
  62. end;
  63. { walk through all momentary register variables }
  64. for i:=1 to maxvarregs do
  65. begin
  66. with pregvarinfo(current_procdef.regvarinfo)^ do
  67. if ((regvars[i]=nil) or (j>regvars_refs[i])) and (j>0) then
  68. begin
  69. for k:=maxvarregs-1 downto i do
  70. begin
  71. regvars[k+1]:=regvars[k];
  72. regvars_para[k+1]:=regvars_para[k];
  73. regvars_refs[k+1]:=regvars_refs[k];
  74. end;
  75. { calc the new refs
  76. tvarsym(p).refs:=j; }
  77. regvars[i]:=tvarsym(p);
  78. regvars_para[i]:=parasym;
  79. regvars_refs[i]:=j;
  80. break;
  81. end;
  82. end;
  83. end;
  84. end;
  85. procedure searchfpuregvars(p : tnamedindexitem;arg:pointer);
  86. var
  87. i,j,k : longint;
  88. parasym : boolean;
  89. begin
  90. parasym:=pboolean(arg)^;
  91. if (tsym(p).typ=varsym) and (vo_fpuregable in tvarsym(p).varoptions) then
  92. begin
  93. j:=tvarsym(p).refs;
  94. { parameter get a less value }
  95. if parasym then
  96. begin
  97. if cs_littlesize in aktglobalswitches then
  98. dec(j,1)
  99. else
  100. dec(j,100);
  101. end;
  102. { walk through all momentary register variables }
  103. for i:=1 to maxfpuvarregs do
  104. begin
  105. with pregvarinfo(current_procdef.regvarinfo)^ do
  106. if ((fpuregvars[i]=nil) or (j>fpuregvars_refs[i])) and (j>0) then
  107. begin
  108. for k:=maxfpuvarregs-1 downto i do
  109. begin
  110. fpuregvars[k+1]:=fpuregvars[k];
  111. fpuregvars_para[k+1]:=fpuregvars_para[k];
  112. fpuregvars_refs[k+1]:=fpuregvars_refs[k];
  113. end;
  114. { calc the new refs
  115. tvarsym(p).refs:=j; }
  116. fpuregvars[i]:=tvarsym(p);
  117. fpuregvars_para[i]:=parasym;
  118. fpuregvars_refs[i]:=j;
  119. break;
  120. end;
  121. end;
  122. end;
  123. end;
  124. procedure assign_regvars(p: tnode);
  125. { register variables }
  126. var
  127. {$ifndef i386}
  128. hp: tparaitem;
  129. {$endif i386}
  130. regvarinfo: pregvarinfo;
  131. i: longint;
  132. parasym : boolean;
  133. r : Tregister;
  134. siz : tcgsize;
  135. begin
  136. {$ifndef newra}
  137. { max. optimizations }
  138. { only if no asm is used }
  139. { and no try statement }
  140. if (cs_regalloc in aktglobalswitches) and
  141. {$ifndef i386}
  142. { we have to store regvars back to memory in this case! }
  143. (tcgprocinfo(current_procinfo).nestedprocs.count = 0) and
  144. {$endif i386}
  145. not(pi_uses_asm in current_procinfo.flags) and
  146. not(pi_uses_exceptions in current_procinfo.flags) then
  147. begin
  148. new(regvarinfo);
  149. fillchar(regvarinfo^,sizeof(regvarinfo^),0);
  150. current_procdef.regvarinfo := regvarinfo;
  151. if (p.registers32<maxvarregs) then
  152. begin
  153. parasym:=false;
  154. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}searchregvars,@parasym);
  155. { copy parameter into a register ? }
  156. parasym:=true;
  157. {$ifndef i386}
  158. if (pi_do_call in current_procinfo.flags) then
  159. {$endif i386}
  160. begin
  161. symtablestack.next.foreach_static({$ifdef FPCPROCVAR}@{$endif}searchregvars,@parasym);
  162. end
  163. {$ifndef i386}
  164. else
  165. begin
  166. hp:=tparaitem(current_procdef.para.first);
  167. while assigned(hp) do
  168. begin
  169. if (hp.paraloc.loc in [LOC_REGISTER,LOC_FPUREGISTER,
  170. LOC_MMREGISTER,LOC_CREGISTER,LOC_CFPUREGISTER,
  171. LOC_CMMREGISTER]) and
  172. (TCGSize2Size[hp.paraloc.size] <= sizeof(aword)) then
  173. tvarsym(hp.parasym).reg := hp.paraloc.register
  174. else
  175. begin
  176. searchregvars(hp.parasym,@parasym);
  177. searchfpuregvars(hp.parasym,@parasym);
  178. end;
  179. hp := tparaitem(hp.next);
  180. end;
  181. end
  182. {$endif not i386}
  183. ;
  184. { hold needed registers free }
  185. for i:=maxvarregs downto maxvarregs-p.registers32+1 do
  186. begin
  187. regvarinfo^.regvars[i]:=nil;
  188. regvarinfo^.regvars_para[i] := false;
  189. end;
  190. { now assign register }
  191. for i:=1 to maxvarregs-p.registers32 do
  192. begin
  193. if assigned(regvarinfo^.regvars[i]) and
  194. (rg.reg_pushes_int[varregs[i]] < regvarinfo^.regvars[i].refs) then
  195. begin
  196. { register is no longer available for }
  197. { expressions }
  198. { search the register which is the most }
  199. { unused }
  200. rg.makeregvarint(varregs[i]);
  201. { call by reference/const ? }
  202. if (regvarinfo^.regvars[i].varspez in [vs_var,vs_out]) or
  203. ((regvarinfo^.regvars[i].varspez=vs_const) and
  204. paramanager.push_addr_param(regvarinfo^.regvars[i].vartype.def,current_procdef.proccalloption)) then
  205. siz:=OS_32
  206. else
  207. if (regvarinfo^.regvars[i].vartype.def.deftype in [orddef,enumdef]) and
  208. (regvarinfo^.regvars[i].vartype.def.size=1) then
  209. siz:=OS_8
  210. else
  211. if (regvarinfo^.regvars[i].vartype.def.deftype in [orddef,enumdef]) and
  212. (regvarinfo^.regvars[i].vartype.def.size=2) then
  213. siz:=OS_16
  214. else
  215. siz:=OS_32;
  216. regvarinfo^.regvars[i].reg.enum:=R_INTREGISTER;
  217. regvarinfo^.regvars[i].reg.number:=(varregs[i] shl 8) or cgsize2subreg(siz);
  218. {$ifdef i386}
  219. { procedure uses this register }
  220. include(rg.usedintinproc,varregs[i]);
  221. {$endif i386}
  222. end
  223. else
  224. begin
  225. regvarinfo^.regvars[i] := nil;
  226. regvarinfo^.regvars_para[i] := false;
  227. end;
  228. end;
  229. end;
  230. if ((p.registersfpu+1)<maxfpuvarregs) then
  231. begin
  232. parasym:=false;
  233. symtablestack.foreach_static({$ifdef FPCPROCVAR}@{$endif}searchfpuregvars,@parasym);
  234. {$ifdef dummy}
  235. { this code should be never enabled because }
  236. { 1. the caller loads parameters into registers }
  237. { 2. (later) the CSE loads a parameter into a }
  238. { register, if necessary }
  239. { (FK) }
  240. { copy parameter into a register ? }
  241. parasym:=true;
  242. symtablestack.next.foreach_static({$ifdef FPCPROCVAR}@{$endif}searchregvars);
  243. {$endif dummy}
  244. { hold needed registers free }
  245. { in non leaf procedures we must be very careful }
  246. { with assigning registers }
  247. if aktmaxfpuregisters=-1 then
  248. begin
  249. if (pi_do_call in current_procinfo.flags) then
  250. begin
  251. for i:=maxfpuvarregs downto 2 do
  252. regvarinfo^.fpuregvars[i]:=nil;
  253. end
  254. else
  255. begin
  256. for i:=maxfpuvarregs downto maxfpuvarregs-p.registersfpu do
  257. regvarinfo^.fpuregvars[i]:=nil;
  258. end;
  259. end
  260. else
  261. begin
  262. for i:=aktmaxfpuregisters+1 to maxfpuvarregs do
  263. regvarinfo^.fpuregvars[i]:=nil;
  264. end;
  265. { now assign register }
  266. for i:=1 to maxfpuvarregs do
  267. begin
  268. if assigned(regvarinfo^.fpuregvars[i]) then
  269. begin
  270. {$ifdef i386}
  271. { reserve place on the FPU stack }
  272. r.enum:=R_ST0;
  273. regvarinfo^.fpuregvars[i].reg:=trgcpu(rg).correct_fpuregister(r,i);
  274. {$else i386}
  275. regvarinfo^.fpuregvars[i].reg.enum:=fpuvarregs[i];
  276. rg.makeregvarother(regvarinfo^.fpuregvars[i].reg);
  277. {$endif i386}
  278. end;
  279. end;
  280. end;
  281. end;
  282. {$endif}
  283. end;
  284. procedure store_regvar(asml: TAAsmoutput; reg: tregister);
  285. var
  286. i: longint;
  287. r : tregister;
  288. hr: treference;
  289. regvarinfo: pregvarinfo;
  290. vsym: tvarsym;
  291. begin
  292. {$ifdef i386}
  293. regvarinfo := pregvarinfo(current_procdef.regvarinfo);
  294. if not assigned(regvarinfo) then
  295. exit;
  296. if reg.enum=R_INTREGISTER then
  297. begin
  298. for i := 1 to maxvarregs do
  299. if assigned(regvarinfo^.regvars[i]) and
  300. (regvarinfo^.regvars[i].reg.number shr 8 = reg.number shr 8) then
  301. begin
  302. if (reg.number shr 8) in rg.regvar_loaded_int then
  303. begin
  304. vsym := tvarsym(regvarinfo^.regvars[i]);
  305. { we only have to store the regvar back to memory if it's }
  306. { possible that it's been modified (JM) }
  307. if not(vsym.varspez in [vs_const,vs_var,vs_out]) then
  308. begin
  309. reference_reset_base(hr,current_procinfo.framepointer,vsym.adjusted_address);
  310. cg.a_load_reg_ref(asml,def_cgsize(vsym.vartype.def),vsym.reg,hr);
  311. end;
  312. asml.concat(tai_regalloc.dealloc(vsym.reg));
  313. exclude(rg.regvar_loaded_int,reg.number shr 8);
  314. end;
  315. break;
  316. end;
  317. end
  318. else
  319. begin
  320. for i := 1 to maxvarregs do
  321. if assigned(regvarinfo^.regvars[i]) then
  322. begin
  323. r:=rg.makeregsize(regvarinfo^.regvars[i].reg,OS_INT);
  324. if (r.enum = reg.enum) then
  325. begin
  326. if rg.regvar_loaded_other[r.enum] then
  327. begin
  328. vsym := tvarsym(regvarinfo^.regvars[i]);
  329. { we only have to store the regvar back to memory if it's }
  330. { possible that it's been modified (JM) }
  331. if not(vsym.varspez in [vs_const,vs_var,vs_out]) then
  332. begin
  333. reference_reset_base(hr,current_procinfo.framepointer,vsym.adjusted_address);
  334. cg.a_load_reg_ref(asml,def_cgsize(vsym.vartype.def),vsym.reg,hr);
  335. end;
  336. asml.concat(tai_regalloc.dealloc(vsym.reg));
  337. rg.regvar_loaded_other[r.enum] := false;
  338. end;
  339. break;
  340. end;
  341. end;
  342. end;
  343. {$endif i386}
  344. end;
  345. procedure load_regvar(asml: TAAsmoutput; vsym: tvarsym);
  346. var
  347. hr: treference;
  348. opsize: tcgsize;
  349. r,
  350. reg : tregister;
  351. begin
  352. {$ifndef i386}
  353. exit;
  354. {$endif i386}
  355. reg:=vsym.reg;
  356. if reg.enum=R_INTREGISTER then
  357. begin
  358. if not((reg.number shr 8) in rg.regvar_loaded_int) then
  359. begin
  360. asml.concat(tai_regalloc.alloc(reg));
  361. reference_reset_base(hr,current_procinfo.framepointer,vsym.adjusted_address);
  362. if (vsym.varspez in [vs_var,vs_out]) or
  363. ((vsym.varspez=vs_const) and
  364. paramanager.push_addr_param(vsym.vartype.def,current_procdef.proccalloption)) then
  365. opsize := OS_ADDR
  366. else
  367. opsize := def_cgsize(vsym.vartype.def);
  368. cg.a_load_ref_reg(asml,opsize,hr,reg);
  369. include(rg.regvar_loaded_int,reg.number shr 8);
  370. end;
  371. end
  372. else
  373. begin
  374. r:=rg.makeregsize(reg,OS_INT);
  375. if not rg.regvar_loaded_other[r.enum] then
  376. begin
  377. asml.concat(tai_regalloc.alloc(reg));
  378. reference_reset_base(hr,current_procinfo.framepointer,vsym.adjusted_address);
  379. if (vsym.varspez in [vs_var,vs_out]) or
  380. ((vsym.varspez=vs_const) and
  381. paramanager.push_addr_param(vsym.vartype.def,current_procdef.proccalloption)) then
  382. opsize := OS_ADDR
  383. else
  384. opsize := def_cgsize(vsym.vartype.def);
  385. cg.a_load_ref_reg(asml,opsize,hr,reg);
  386. rg.regvar_loaded_other[r.enum] := true;
  387. end;
  388. end;
  389. end;
  390. procedure load_regvar_reg(asml: TAAsmoutput; reg: tregister);
  391. var
  392. i: longint;
  393. regvarinfo: pregvarinfo;
  394. reg_spare : tregister;
  395. begin
  396. regvarinfo := pregvarinfo(current_procdef.regvarinfo);
  397. if not assigned(regvarinfo) then
  398. exit;
  399. if reg.enum=R_INTREGISTER then
  400. begin
  401. for i := 1 to maxvarregs do
  402. if assigned(regvarinfo^.regvars[i]) and
  403. (regvarinfo^.regvars[i].reg.number shr 8 = reg.number shr 8) then
  404. load_regvar(asml,tvarsym(regvarinfo^.regvars[i]))
  405. end
  406. else
  407. begin
  408. reg_spare := rg.makeregsize(reg,OS_INT);
  409. if reg_spare.enum>lastreg then
  410. internalerror(2003010801);
  411. for i := 1 to maxvarregs do
  412. if assigned(regvarinfo^.regvars[i]) and
  413. (rg.makeregsize(regvarinfo^.regvars[i].reg,OS_INT).enum = reg_spare.enum) then
  414. load_regvar(asml,tvarsym(regvarinfo^.regvars[i]))
  415. end;
  416. end;
  417. procedure load_all_regvars(asml: TAAsmoutput);
  418. var
  419. i: longint;
  420. regvarinfo: pregvarinfo;
  421. begin
  422. regvarinfo := pregvarinfo(current_procdef.regvarinfo);
  423. if not assigned(regvarinfo) then
  424. exit;
  425. for i := 1 to maxvarregs do
  426. if assigned(regvarinfo^.regvars[i]) then
  427. load_regvar(asml,tvarsym(regvarinfo^.regvars[i]))
  428. end;
  429. procedure load_regvars(asml: TAAsmoutput; p: tnode);
  430. var
  431. i: longint;
  432. regvarinfo: pregvarinfo;
  433. r:Tregister;
  434. begin
  435. if (cs_regalloc in aktglobalswitches) and
  436. not(pi_uses_asm in current_procinfo.flags) and
  437. not(pi_uses_exceptions in current_procinfo.flags) then
  438. begin
  439. regvarinfo := pregvarinfo(current_procdef.regvarinfo);
  440. { can happen when inlining assembler procedures (JM) }
  441. if not assigned(regvarinfo) then
  442. exit;
  443. for i:=1 to maxvarregs do
  444. begin
  445. if assigned(regvarinfo^.regvars[i]) then
  446. begin
  447. r:=regvarinfo^.regvars[i].reg;
  448. convert_register_to_enum(r);
  449. if cs_asm_source in aktglobalswitches then
  450. asml.insert(tai_comment.Create(strpnew(regvarinfo^.regvars[i].name+
  451. ' with weight '+tostr(regvarinfo^.regvars[i].refs)+' assigned to register '+
  452. std_reg2str[r.enum])));
  453. Message3(cg_d_register_weight,std_reg2str[r.enum],
  454. tostr(regvarinfo^.regvars[i].refs),regvarinfo^.regvars[i].name);
  455. end;
  456. end;
  457. for i:=1 to maxfpuvarregs do
  458. begin
  459. if assigned(regvarinfo^.fpuregvars[i]) then
  460. begin
  461. {$ifdef i386}
  462. r.enum:=R_ST0;
  463. { reserve place on the FPU stack }
  464. regvarinfo^.fpuregvars[i].reg:=trgcpu(rg).correct_fpuregister(r,i-1);
  465. asml.concat(Taicpu.op_none(A_FLDZ,S_NO));
  466. {$endif i386}
  467. end;
  468. end;
  469. {$ifdef i386}
  470. if assigned(p) then
  471. if cs_asm_source in aktglobalswitches then
  472. asml.insert(tai_comment.Create(strpnew(tostr(p.registersfpu)+
  473. ' registers on FPU stack used by temp. expressions')));
  474. {$endif i386}
  475. for i:=1 to maxfpuvarregs do
  476. begin
  477. if assigned(regvarinfo^.fpuregvars[i]) then
  478. begin
  479. if cs_asm_source in aktglobalswitches then
  480. asml.insert(tai_comment.Create(strpnew(regvarinfo^.fpuregvars[i].name+
  481. ' with weight '+tostr(regvarinfo^.fpuregvars[i].refs)+' assigned to register '+
  482. std_reg2str[regvarinfo^.fpuregvars[i].reg.enum])));
  483. if (status.verbosity and v_debug)=v_debug then
  484. Message3(cg_d_register_weight,std_reg2str[regvarinfo^.fpuregvars[i].reg.enum],
  485. tostr(regvarinfo^.fpuregvars[i].refs),regvarinfo^.fpuregvars[i].name);
  486. end;
  487. end;
  488. if cs_asm_source in aktglobalswitches then
  489. asml.insert(tai_comment.Create(strpnew('Register variable assignment:')));
  490. end;
  491. end;
  492. {$ifdef i386}
  493. procedure sync_regvars_other(list1, list2: taasmoutput; const regvarsloaded1,
  494. regvarsloaded2: regvarother_booleanarray);
  495. var
  496. counter: tregister;
  497. begin
  498. for counter.enum := low(rg.regvar_loaded_other) to high(rg.regvar_loaded_other) do
  499. begin
  500. rg.regvar_loaded_other[counter.enum] := regvarsloaded1[counter.enum] and
  501. regvarsloaded2[counter.enum];
  502. if regvarsloaded1[counter.enum] xor regvarsloaded2[counter.enum] then
  503. if regvarsloaded1[counter.enum] then
  504. load_regvar_reg(list2,counter)
  505. else
  506. load_regvar_reg(list1,counter);
  507. end;
  508. end;
  509. procedure sync_regvars_int(list1, list2: taasmoutput; const regvarsloaded1,
  510. regvarsloaded2: Tsupregset);
  511. var
  512. i : longint;
  513. r : tregister;
  514. begin
  515. for i:=1 to maxvarregs do
  516. begin
  517. r.enum:=R_INTREGISTER;
  518. r.number:=varregs[i] shl 8;
  519. if (varregs[i] in regvarsloaded1) and
  520. not(varregs[i] in regvarsloaded2) then
  521. load_regvar_reg(list2,r)
  522. else
  523. if (varregs[i] in regvarsloaded2) and
  524. not(varregs[i] in regvarsloaded1) then
  525. load_regvar_reg(list1,r);
  526. end;
  527. end;
  528. {$endif i386}
  529. procedure cleanup_regvars(asml: TAAsmoutput);
  530. var
  531. i: longint;
  532. r,reg : tregister;
  533. begin
  534. { can happen when inlining assembler procedures (JM) }
  535. if not assigned(current_procdef.regvarinfo) then
  536. exit;
  537. if (cs_regalloc in aktglobalswitches) and
  538. not(pi_uses_asm in current_procinfo.flags) and
  539. not(pi_uses_exceptions in current_procinfo.flags) then
  540. with pregvarinfo(current_procdef.regvarinfo)^ do
  541. begin
  542. {$ifdef i386}
  543. r.enum:=R_ST0;
  544. for i:=1 to maxfpuvarregs do
  545. if assigned(fpuregvars[i]) then
  546. { ... and clean it up }
  547. asml.concat(Taicpu.op_reg(A_FSTP,S_NO,r));
  548. {$endif i386}
  549. for i := 1 to maxvarregs do
  550. begin
  551. if assigned(regvars[i]) then
  552. begin
  553. reg:=regvars[i].reg;
  554. if reg.enum=R_INTREGISTER then
  555. begin
  556. if (reg.number shr 8 in rg.regvar_loaded_int) then
  557. asml.concat(tai_regalloc.dealloc(reg));
  558. end
  559. else
  560. begin
  561. reg.number:=(reg.number and not $ff) or cgsize2subreg(OS_INT);
  562. r:=reg;
  563. convert_register_to_enum(r);
  564. if r.enum>lastreg then
  565. internalerror(200201081);
  566. if (rg.regvar_loaded_other[r.enum]) then
  567. asml.concat(tai_regalloc.dealloc(reg));
  568. end;
  569. end;
  570. end;
  571. end;
  572. end;
  573. end.
  574. {
  575. $Log$
  576. Revision 1.54 2003-06-03 13:01:59 daniel
  577. * Register allocator finished
  578. Revision 1.53 2003/05/31 20:33:57 jonas
  579. * temp fix/hack for nested procedures (disable regvars in all procedures
  580. that have nested procedures)
  581. * leave register parameters in their own register (instead of storing
  582. them to memory or assigning them to another register) if the current
  583. procedure doesn't call any other procedures
  584. Revision 1.52 2003/05/30 18:55:21 jonas
  585. * fixed several regvar related bugs for non-i386. make cycle with -Or now
  586. works for ppc
  587. Revision 1.51 2003/05/23 14:27:35 peter
  588. * remove some unit dependencies
  589. * current_procinfo changes to store more info
  590. Revision 1.50 2003/05/16 14:33:31 peter
  591. * regvar fixes
  592. Revision 1.49 2003/05/15 18:58:53 peter
  593. * removed selfpointer_offset, vmtpointer_offset
  594. * tvarsym.adjusted_address
  595. * address in localsymtable is now in the real direction
  596. * removed some obsolete globals
  597. Revision 1.48 2003/05/12 17:22:00 jonas
  598. * fixed (last?) remaining -tvarsym(X).address to
  599. tg.direction*tvarsym(X).address...
  600. Revision 1.47 2003/04/27 11:21:34 peter
  601. * aktprocdef renamed to current_procdef
  602. * procinfo renamed to current_procinfo
  603. * procinfo will now be stored in current_module so it can be
  604. cleaned up properly
  605. * gen_main_procsym changed to create_main_proc and release_main_proc
  606. to also generate a tprocinfo structure
  607. * fixed unit implicit initfinal
  608. Revision 1.46 2003/03/28 19:16:57 peter
  609. * generic constructor working for i386
  610. * remove fixed self register
  611. * esi added as address register for i386
  612. Revision 1.45 2003/02/19 22:00:14 daniel
  613. * Code generator converted to new register notation
  614. - Horribily outdated todo.txt removed
  615. Revision 1.44 2003/01/08 18:43:57 daniel
  616. * Tregister changed into a record
  617. Revision 1.43 2002/11/25 17:43:24 peter
  618. * splitted defbase in defutil,symutil,defcmp
  619. * merged isconvertable and is_equal into compare_defs(_ext)
  620. * made operator search faster by walking the list only once
  621. Revision 1.42 2002/11/18 17:31:59 peter
  622. * pass proccalloption to ret_in_xxx and push_xxx functions
  623. Revision 1.41 2002/08/25 19:25:20 peter
  624. * sym.insert_in_data removed
  625. * symtable.insertvardata/insertconstdata added
  626. * removed insert_in_data call from symtable.insert, it needs to be
  627. called separatly. This allows to deref the address calculation
  628. * procedures now calculate the parast addresses after the procedure
  629. directives are parsed. This fixes the cdecl parast problem
  630. * push_addr_param has an extra argument that specifies if cdecl is used
  631. or not
  632. Revision 1.40 2002/08/18 20:06:25 peter
  633. * inlining is now also allowed in interface
  634. * renamed write/load to ppuwrite/ppuload
  635. * tnode storing in ppu
  636. * nld,ncon,nbas are already updated for storing in ppu
  637. Revision 1.39 2002/08/17 09:23:41 florian
  638. * first part of procinfo rewrite
  639. Revision 1.38 2002/08/06 20:55:22 florian
  640. * first part of ppc calling conventions fix
  641. Revision 1.37 2002/07/20 11:57:57 florian
  642. * types.pas renamed to defbase.pas because D6 contains a types
  643. unit so this would conflicts if D6 programms are compiled
  644. + Willamette/SSE2 instructions to assembler added
  645. Revision 1.36 2002/07/11 14:41:30 florian
  646. * start of the new generic parameter handling
  647. Revision 1.35 2002/07/01 18:46:25 peter
  648. * internal linker
  649. * reorganized aasm layer
  650. Revision 1.34 2002/06/24 12:43:00 jonas
  651. * fixed errors found with new -CR code from Peter when cycling with -O2p3r
  652. Revision 1.33 2002/05/18 13:34:17 peter
  653. * readded missing revisions
  654. Revision 1.32 2002/05/16 19:46:44 carl
  655. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  656. + try to fix temp allocation (still in ifdef)
  657. + generic constructor calls
  658. + start of tassembler / tmodulebase class cleanup
  659. Revision 1.30 2002/05/12 16:53:10 peter
  660. * moved entry and exitcode to ncgutil and cgobj
  661. * foreach gets extra argument for passing local data to the
  662. iterator function
  663. * -CR checks also class typecasts at runtime by changing them
  664. into as
  665. * fixed compiler to cycle with the -CR option
  666. * fixed stabs with elf writer, finally the global variables can
  667. be watched
  668. * removed a lot of routines from cga unit and replaced them by
  669. calls to cgobj
  670. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  671. u32bit then the other is typecasted also to u32bit without giving
  672. a rangecheck warning/error.
  673. * fixed pascal calling method with reversing also the high tree in
  674. the parast, detected by tcalcst3 test
  675. Revision 1.29 2002/04/21 15:23:34 carl
  676. + changeregsize -> makeregsize
  677. Revision 1.28 2002/04/19 15:46:03 peter
  678. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  679. in most cases and not written to the ppu
  680. * add mangeledname_prefix() routine to generate the prefix of
  681. manglednames depending on the current procedure, object and module
  682. * removed static procprefix since the mangledname is now build only
  683. on demand from tprocdef.mangledname
  684. Revision 1.27 2002/04/15 19:44:19 peter
  685. * fixed stackcheck that would be called recursively when a stack
  686. error was found
  687. * generic changeregsize(reg,size) for i386 register resizing
  688. * removed some more routines from cga unit
  689. * fixed returnvalue handling
  690. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  691. Revision 1.26 2002/04/15 19:04:04 carl
  692. + reg2str -> std_reg2str()
  693. Revision 1.25 2002/04/06 18:13:01 jonas
  694. * several powerpc-related additions and fixes
  695. Revision 1.24 2002/04/02 17:11:29 peter
  696. * tlocation,treference update
  697. * LOC_CONSTANT added for better constant handling
  698. * secondadd splitted in multiple routines
  699. * location_force_reg added for loading a location to a register
  700. of a specified size
  701. * secondassignment parses now first the right and then the left node
  702. (this is compatible with Kylix). This saves a lot of push/pop especially
  703. with string operations
  704. * adapted some routines to use the new cg methods
  705. Revision 1.23 2002/03/31 20:26:36 jonas
  706. + a_loadfpu_* and a_loadmm_* methods in tcg
  707. * register allocation is now handled by a class and is mostly processor
  708. independent (+rgobj.pas and i386/rgcpu.pas)
  709. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  710. * some small improvements and fixes to the optimizer
  711. * some register allocation fixes
  712. * some fpuvaroffset fixes in the unary minus node
  713. * push/popusedregisters is now called rg.save/restoreusedregisters and
  714. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  715. also better optimizable)
  716. * fixed and optimized register saving/restoring for new/dispose nodes
  717. * LOC_FPU locations now also require their "register" field to be set to
  718. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  719. - list field removed of the tnode class because it's not used currently
  720. and can cause hard-to-find bugs
  721. }