tgobj.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the base object for temp. generator
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {#@abstract(Temporary reference allocator unit)
  18. Temporary reference allocator unit. This unit contains
  19. all which is related to allocating temporary memory
  20. space on the stack, as required, by the code generator.
  21. }
  22. unit tgobj;
  23. {$i fpcdefs.inc}
  24. interface
  25. uses
  26. cclasses,
  27. globals,globtype,
  28. symtype,
  29. cpubase,cpuinfo,cgbase,cgutils,
  30. aasmbase,aasmtai,aasmdata;
  31. type
  32. ptemprecord = ^ttemprecord;
  33. ttemprecord = record
  34. temptype : ttemptype;
  35. pos : longint;
  36. size : longint;
  37. def : tdef;
  38. next : ptemprecord;
  39. nextfree : ptemprecord; { for faster freeblock checking }
  40. {$ifdef EXTDEBUG}
  41. posinfo,
  42. releaseposinfo : tfileposinfo;
  43. {$endif}
  44. end;
  45. {# Generates temporary variables }
  46. ttgobj = class
  47. protected
  48. { contains all free temps using nextfree links }
  49. tempfreelist : ptemprecord;
  50. function alloctemp(list: TAsmList; size,alignment : longint; temptype : ttemptype; def:tdef) : longint; virtual;
  51. procedure freetemp(list: TAsmList; pos:longint;temptypes:ttemptypeset);
  52. public
  53. { contains all temps }
  54. templist : ptemprecord;
  55. { Offsets of the first/last temp }
  56. firsttemp,
  57. lasttemp : longint;
  58. direction : shortint;
  59. constructor create;virtual;reintroduce;
  60. {# Clear and free the complete linked list of temporary memory
  61. locations. The list is set to nil.}
  62. procedure resettempgen;
  63. {# Sets the first offset from the frame pointer or stack pointer where
  64. the temporary references will be allocated. It is to note that this
  65. value should always be negative.
  66. @param(l start offset where temps will start in stack)
  67. }
  68. procedure setfirsttemp(l : longint); virtual;
  69. { version of gettemp that is compatible with hlcg-based targets;
  70. always use in common code, only use gettemp in cgobj and
  71. architecture-specific backends.
  72. the forcesize parameter is so that it can be used for defs that
  73. don't have an inherent size (e.g., array of const) }
  74. procedure gethltemp(list: TAsmList; def: tdef; forcesize: aint; temptype: ttemptype; out ref: treference); virtual;
  75. procedure gettemp(list: TAsmList; size, alignment : longint;temptype:ttemptype;out ref : treference);
  76. procedure gettemptyped(list: TAsmList; def:tdef;temptype:ttemptype;out ref : treference);
  77. procedure ungettemp(list: TAsmList; const ref : treference);
  78. function sizeoftemp(list: TAsmList; const ref: treference): longint;
  79. function changetemptype(list: TAsmList; const ref:treference;temptype:ttemptype):boolean;
  80. function gettypeoftemp(const ref:treference): ttemptype;
  81. {# Returns TRUE if the reference ref is allocated in temporary volatile memory space,
  82. otherwise returns FALSE.
  83. @param(ref reference to verify)
  84. }
  85. function istemp(const ref : treference) : boolean;
  86. {# Frees a reference @var(ref) which was allocated in the volatile temporary memory space.
  87. The freed space can later be reallocated and reused. If this reference
  88. is not in the temporary memory, it is simply not freed.
  89. }
  90. procedure ungetiftemp(list: TAsmList; const ref : treference);
  91. { Allocate space for a local }
  92. procedure getlocal(list: TAsmList; size : longint;def:tdef;var ref : treference);
  93. procedure getlocal(list: TAsmList; size : longint; alignment : shortint; def:tdef;var ref : treference); virtual;
  94. procedure UnGetLocal(list: TAsmList; const ref : treference);
  95. end;
  96. ttgobjclass = class of ttgobj;
  97. var
  98. tg: ttgobj;
  99. tgobjclass: ttgobjclass = ttgobj;
  100. procedure location_freetemp(list:TAsmList; const l : tlocation);
  101. implementation
  102. uses
  103. cutils,
  104. systems,verbose,
  105. procinfo,
  106. symconst
  107. ;
  108. const
  109. FreeTempTypes = [tt_free,tt_freenoreuse,tt_freeregallocator];
  110. {$ifdef EXTDEBUG}
  111. TempTypeStr : array[ttemptype] of string[18] = (
  112. '<none>',
  113. 'free','normal','persistant',
  114. 'noreuse','freenoreuse',
  115. 'regallocator','freeregallocator'
  116. );
  117. {$endif EXTDEBUG}
  118. Used2Free : array[ttemptype] of ttemptype = (
  119. tt_none,
  120. tt_none,tt_free,tt_free,
  121. tt_freenoreuse,tt_none,
  122. tt_freeregallocator,tt_none
  123. );
  124. {*****************************************************************************
  125. Helpers
  126. *****************************************************************************}
  127. procedure location_freetemp(list:TAsmList; const l : tlocation);
  128. begin
  129. if (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  130. tg.ungetiftemp(list,l.reference);
  131. end;
  132. {*****************************************************************************
  133. TTGOBJ
  134. *****************************************************************************}
  135. constructor ttgobj.create;
  136. begin
  137. tempfreelist:=nil;
  138. templist:=nil;
  139. { we could create a new child class for this but I don't if it is worth the effort (FK) }
  140. {$if defined(powerpc) or defined(powerpc64) or defined(avr) or defined(jvm)}
  141. direction:=1;
  142. {$else}
  143. direction:=-1;
  144. {$endif}
  145. end;
  146. procedure ttgobj.resettempgen;
  147. var
  148. hp : ptemprecord;
  149. begin
  150. { Clear the old templist }
  151. while assigned(templist) do
  152. begin
  153. {$ifdef EXTDEBUG}
  154. if not(templist^.temptype in FreeTempTypes) then
  155. begin
  156. Comment(V_Warning,'tgobj: (ResetTempgen) temp at pos '+tostr(templist^.pos)+
  157. ' with size '+tostr(templist^.size)+' and type '+TempTypeStr[templist^.temptype]+
  158. ' from pos '+tostr(templist^.posinfo.line)+':'+tostr(templist^.posinfo.column)+
  159. ' not freed at the end of the procedure');
  160. end;
  161. {$endif EXTDEBUG}
  162. hp:=templist;
  163. templist:=hp^.next;
  164. dispose(hp);
  165. end;
  166. templist:=nil;
  167. tempfreelist:=nil;
  168. firsttemp:=0;
  169. lasttemp:=0;
  170. end;
  171. procedure ttgobj.setfirsttemp(l : longint);
  172. begin
  173. { this is a negative value normally }
  174. if l*direction>=0 then
  175. begin
  176. if odd(l) then
  177. inc(l,direction);
  178. end
  179. else
  180. internalerror(200204221);
  181. firsttemp:=l;
  182. lasttemp:=l;
  183. end;
  184. function ttgobj.AllocTemp(list: TAsmList; size,alignment : longint; temptype : ttemptype;def : tdef) : longint;
  185. var
  186. tl,htl,
  187. bestslot,bestprev,
  188. hprev,hp : ptemprecord;
  189. freetype : ttemptype;
  190. bestatend,
  191. fitatbegin,
  192. fitatend : boolean;
  193. begin
  194. AllocTemp:=0;
  195. bestprev:=nil;
  196. bestslot:=nil;
  197. tl:=nil;
  198. bestatend:=false;
  199. if size=0 then
  200. begin
  201. {$ifdef EXTDEBUG}
  202. Comment(V_Warning,'tgobj: (AllocTemp) temp of size 0 requested, allocating 4 bytes');
  203. {$endif}
  204. size:=4;
  205. end;
  206. freetype:=Used2Free[temptype];
  207. if freetype=tt_none then
  208. internalerror(200208201);
  209. size:=align(size,alignment);
  210. { First check the tmpfreelist, but not when
  211. we don't want to reuse an already allocated block }
  212. if assigned(tempfreelist) and
  213. (temptype<>tt_noreuse) then
  214. begin
  215. hprev:=nil;
  216. hp:=tempfreelist;
  217. while assigned(hp) do
  218. begin
  219. {$ifdef EXTDEBUG}
  220. if not(hp^.temptype in FreeTempTypes) then
  221. Comment(V_Warning,'tgobj: (AllocTemp) temp at pos '+tostr(hp^.pos)+ ' in freelist is not set to tt_free !');
  222. {$endif}
  223. { Check only slots that are
  224. - free
  225. - share the same type
  226. - contain enough space
  227. - has a correct alignment }
  228. if (hp^.temptype=freetype) and
  229. (hp^.def=def) and
  230. (hp^.size>=size) and
  231. ((hp^.pos=align(hp^.pos,alignment)) or
  232. (hp^.pos+hp^.size-size = align(hp^.pos+hp^.size-size,alignment))) then
  233. begin
  234. { Slot is the same size then leave immediatly }
  235. if (hp^.size=size) then
  236. begin
  237. bestprev:=hprev;
  238. bestslot:=hp;
  239. break;
  240. end
  241. else
  242. begin
  243. { we can fit a smaller block either at the begin or at }
  244. { the end of a block. For direction=-1 we prefer the }
  245. { end, for direction=1 we prefer the begin (i.e., }
  246. { always closest to the source). We also try to use }
  247. { the block with the worst possible alignment that }
  248. { still suffices. And we pick the block which will }
  249. { have the best alignmenment after this new block is }
  250. { substracted from it. }
  251. fitatend:=(hp^.pos+hp^.size-size)=align(hp^.pos+hp^.size-size,alignment);
  252. fitatbegin:=hp^.pos=align(hp^.pos,alignment);
  253. if assigned(bestslot) then
  254. begin
  255. fitatend:=fitatend and
  256. ((not bestatend and
  257. (direction=-1)) or
  258. (bestatend and
  259. isbetteralignedthan(abs(bestslot^.pos+hp^.size-size),abs(hp^.pos+hp^.size-size),current_settings.alignment.localalignmax)));
  260. fitatbegin:=fitatbegin and
  261. (not bestatend or
  262. (direction=1)) and
  263. isbetteralignedthan(abs(hp^.pos+size),abs(bestslot^.pos+size),current_settings.alignment.localalignmax);
  264. end;
  265. if fitatend and
  266. fitatbegin then
  267. if isbetteralignedthan(abs(hp^.pos+hp^.size-size),abs(hp^.pos+size),current_settings.alignment.localalignmax) then
  268. fitatbegin:=false
  269. else if isbetteralignedthan(abs(hp^.pos+size),abs(hp^.pos+hp^.size-size),current_settings.alignment.localalignmax) then
  270. fitatend:=false
  271. else if (direction=1) then
  272. fitatend:=false
  273. else
  274. fitatbegin:=false;
  275. if fitatend or
  276. fitatbegin then
  277. begin
  278. bestprev:=hprev;
  279. bestslot:=hp;
  280. bestatend:=fitatend;
  281. end;
  282. end;
  283. end;
  284. hprev:=hp;
  285. hp:=hp^.nextfree;
  286. end;
  287. end;
  288. { Reuse an old temp ? }
  289. if assigned(bestslot) then
  290. begin
  291. if bestslot^.size=size then
  292. begin
  293. tl:=bestslot;
  294. { Remove from the tempfreelist }
  295. if assigned(bestprev) then
  296. bestprev^.nextfree:=tl^.nextfree
  297. else
  298. tempfreelist:=tl^.nextfree;
  299. end
  300. else
  301. begin
  302. { Duplicate bestlost and the block in the list }
  303. new(tl);
  304. move(bestslot^,tl^,sizeof(ttemprecord));
  305. tl^.next:=bestslot^.next;
  306. bestslot^.next:=tl;
  307. { Now we split the block in 2 parts. Depending on the direction
  308. we need to resize the newly inserted block or the old reused block.
  309. For direction=1 we can use tl for the new block. For direction=-1 we
  310. will be reusing bestslot and resize the new block, that means we need
  311. to swap the pointers }
  312. if (direction=-1) xor
  313. bestatend then
  314. begin
  315. htl:=tl;
  316. tl:=bestslot;
  317. bestslot:=htl;
  318. { Update the tempfreelist to point to the new block }
  319. if assigned(bestprev) then
  320. bestprev^.nextfree:=bestslot
  321. else
  322. tempfreelist:=bestslot;
  323. end;
  324. if not bestatend then
  325. inc(bestslot^.pos,size)
  326. else
  327. inc(tl^.pos,tl^.size-size);
  328. { Create new block and resize the old block }
  329. tl^.size:=size;
  330. tl^.nextfree:=nil;
  331. { Resize the old block }
  332. dec(bestslot^.size,size);
  333. end;
  334. tl^.temptype:=temptype;
  335. tl^.def:=def;
  336. tl^.nextfree:=nil;
  337. end
  338. else
  339. begin
  340. { now we can create the templist entry }
  341. new(tl);
  342. tl^.temptype:=temptype;
  343. tl^.def:=def;
  344. { Extend the temp }
  345. if direction=-1 then
  346. begin
  347. lasttemp:=(-align(-lasttemp,alignment))-size;
  348. tl^.pos:=lasttemp;
  349. end
  350. else
  351. begin
  352. tl^.pos:=align(lasttemp,alignment);
  353. lasttemp:=tl^.pos+size;
  354. end;
  355. tl^.size:=size;
  356. tl^.next:=templist;
  357. tl^.nextfree:=nil;
  358. templist:=tl;
  359. end;
  360. {$ifdef EXTDEBUG}
  361. tl^.posinfo:=current_filepos;
  362. if assigned(tl^.def) then
  363. list.concat(tai_tempalloc.allocinfo(tl^.pos,tl^.size,'allocated with type '+TempTypeStr[tl^.temptype]+' for def '+tl^.def.typename))
  364. else
  365. list.concat(tai_tempalloc.allocinfo(tl^.pos,tl^.size,'allocated with type '+TempTypeStr[tl^.temptype]));
  366. {$else}
  367. list.concat(tai_tempalloc.alloc(tl^.pos,tl^.size));
  368. {$endif}
  369. AllocTemp:=tl^.pos;
  370. end;
  371. procedure ttgobj.FreeTemp(list: TAsmList; pos:longint;temptypes:ttemptypeset);
  372. var
  373. hp,hnext,hprev,hprevfree : ptemprecord;
  374. begin
  375. hp:=templist;
  376. hprev:=nil;
  377. hprevfree:=nil;
  378. while assigned(hp) do
  379. begin
  380. if (hp^.pos=pos) then
  381. begin
  382. { check if already freed }
  383. if hp^.temptype in FreeTempTypes then
  384. begin
  385. {$ifdef EXTDEBUG}
  386. Comment(V_Warning,'tgobj: (FreeTemp) temp at pos '+tostr(pos)+ ' is already free !');
  387. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'temp is already freed'));
  388. {$endif}
  389. exit;
  390. end;
  391. { check type that are allowed to be released }
  392. if not(hp^.temptype in temptypes) then
  393. begin
  394. {$ifdef EXTDEBUG}
  395. Comment(V_Debug,'tgobj: (Freetemp) temp at pos '+tostr(pos)+ ' has different type ('+TempTypeStr[hp^.temptype]+'), not releasing');
  396. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'temp has wrong type ('+TempTypeStr[hp^.temptype]+') not releasing'));
  397. {$endif}
  398. exit;
  399. end;
  400. list.concat(tai_tempalloc.dealloc(hp^.pos,hp^.size));
  401. { set this block to free }
  402. hp^.temptype:=Used2Free[hp^.temptype];
  403. { Update tempfreelist }
  404. if assigned(hprevfree) then
  405. begin
  406. { Concat blocks when the previous block is free and
  407. there is no block assigned for a tdef }
  408. if assigned(hprev) and
  409. (hp^.temptype=tt_free) and
  410. not assigned(hp^.def) and
  411. (hprev^.temptype=tt_free) and
  412. not assigned(hprev^.def) then
  413. begin
  414. inc(hprev^.size,hp^.size);
  415. if direction=1 then
  416. hprev^.pos:=hp^.pos;
  417. hprev^.next:=hp^.next;
  418. dispose(hp);
  419. hp:=hprev;
  420. end
  421. else
  422. hprevfree^.nextfree:=hp;
  423. end
  424. else
  425. begin
  426. hp^.nextfree:=tempfreelist;
  427. tempfreelist:=hp;
  428. end;
  429. { Concat blocks when the next block is free and
  430. there is no block assigned for a tdef }
  431. hnext:=hp^.next;
  432. if assigned(hnext) and
  433. (hp^.temptype=tt_free) and
  434. not assigned(hp^.def) and
  435. (hnext^.temptype=tt_free) and
  436. not assigned(hnext^.def) then
  437. begin
  438. inc(hp^.size,hnext^.size);
  439. if direction=1 then
  440. hp^.pos:=hnext^.pos;
  441. hp^.nextfree:=hnext^.nextfree;
  442. hp^.next:=hnext^.next;
  443. dispose(hnext);
  444. end;
  445. { Stop }
  446. exit;
  447. end;
  448. if (hp^.temptype=tt_free) then
  449. hprevfree:=hp;
  450. hprev:=hp;
  451. hp:=hp^.next;
  452. end;
  453. end;
  454. procedure ttgobj.gethltemp(list: TAsmList; def: tdef; forcesize: aint; temptype: ttemptype; out ref: treference);
  455. begin
  456. gettemp(list,forcesize,def.alignment,temptype,ref);
  457. end;
  458. procedure ttgobj.gettemp(list: TAsmList; size, alignment : longint;temptype:ttemptype;out ref : treference);
  459. var
  460. varalign : shortint;
  461. begin
  462. varalign:=used_align(alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax);
  463. { can't use reference_reset_base, because that will let tgobj depend
  464. on cgobj (PFV) }
  465. fillchar(ref,sizeof(ref),0);
  466. ref.base:=current_procinfo.framepointer;
  467. ref.offset:=alloctemp(list,size,varalign,temptype,nil);
  468. ref.alignment:=varalign;
  469. end;
  470. procedure ttgobj.gettemptyped(list: TAsmList; def:tdef;temptype:ttemptype;out ref : treference);
  471. var
  472. varalign : shortint;
  473. begin
  474. varalign:=def.alignment;
  475. varalign:=used_align(varalign,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax);
  476. { can't use reference_reset_base, because that will let tgobj depend
  477. on cgobj (PFV) }
  478. fillchar(ref,sizeof(ref),0);
  479. ref.base:=current_procinfo.framepointer;
  480. ref.offset:=alloctemp(list,def.size,varalign,temptype,def);
  481. ref.alignment:=varalign;
  482. end;
  483. function ttgobj.istemp(const ref : treference) : boolean;
  484. begin
  485. { ref.index = R_NO was missing
  486. led to problems with local arrays
  487. with lower bound > 0 (PM) }
  488. if direction = 1 then
  489. begin
  490. istemp:=(ref.base=current_procinfo.framepointer) and
  491. (ref.index=NR_NO) and
  492. (ref.offset>=firsttemp);
  493. end
  494. else
  495. begin
  496. istemp:=(ref.base=current_procinfo.framepointer) and
  497. (ref.index=NR_NO) and
  498. (ref.offset<firsttemp);
  499. end;
  500. end;
  501. function ttgobj.sizeoftemp(list: TAsmList; const ref: treference): longint;
  502. var
  503. hp : ptemprecord;
  504. begin
  505. SizeOfTemp := -1;
  506. hp:=templist;
  507. while assigned(hp) do
  508. begin
  509. if (hp^.pos=ref.offset) then
  510. begin
  511. sizeoftemp := hp^.size;
  512. exit;
  513. end;
  514. hp := hp^.next;
  515. end;
  516. {$ifdef EXTDEBUG}
  517. comment(v_debug,'tgobj: (SizeOfTemp) temp at pos '+tostr(ref.offset)+' not found !');
  518. list.concat(tai_tempalloc.allocinfo(ref.offset,0,'temp not found'));
  519. {$endif}
  520. end;
  521. function ttgobj.changetemptype(list: tasmList; const ref:treference; temptype:ttemptype):boolean;
  522. var
  523. hp : ptemprecord;
  524. begin
  525. ChangeTempType:=false;
  526. hp:=templist;
  527. while assigned(hp) do
  528. begin
  529. if (hp^.pos=ref.offset) then
  530. begin
  531. if hp^.temptype<>tt_free then
  532. begin
  533. {$ifdef EXTDEBUG}
  534. if hp^.temptype=temptype then
  535. Comment(V_Warning,'tgobj: (ChangeTempType) temp'+
  536. ' at pos '+tostr(ref.offset)+ ' is already of the correct type !');
  537. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'type changed to '+TempTypeStr[temptype]));
  538. {$endif}
  539. ChangeTempType:=true;
  540. hp^.temptype:=temptype;
  541. end
  542. else
  543. begin
  544. {$ifdef EXTDEBUG}
  545. Comment(V_Warning,'tgobj: (ChangeTempType) temp'+
  546. ' at pos '+tostr(ref.offset)+ ' is already freed !');
  547. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'temp is already freed'));
  548. {$endif}
  549. end;
  550. exit;
  551. end;
  552. hp:=hp^.next;
  553. end;
  554. {$ifdef EXTDEBUG}
  555. Comment(V_Warning,'tgobj: (ChangeTempType) temp'+
  556. ' at pos '+tostr(ref.offset)+ ' not found !');
  557. list.concat(tai_tempalloc.allocinfo(ref.offset,0,'temp not found'));
  558. {$endif}
  559. end;
  560. function ttgobj.gettypeoftemp(const ref:treference): ttemptype;
  561. var
  562. hp : ptemprecord;
  563. begin
  564. hp:=templist;
  565. while assigned(hp) do
  566. begin
  567. if (hp^.pos=ref.offset) then
  568. begin
  569. if hp^.temptype<>tt_free then
  570. result:=hp^.temptype
  571. else
  572. internalerror(2007020810);
  573. exit;
  574. end;
  575. hp:=hp^.next;
  576. end;
  577. result:=tt_none;
  578. end;
  579. procedure ttgobj.UnGetTemp(list: TAsmList; const ref : treference);
  580. begin
  581. FreeTemp(list,ref.offset,[tt_normal,tt_noreuse,tt_persistent,tt_regallocator]);
  582. end;
  583. procedure ttgobj.UnGetIfTemp(list: TAsmList; const ref : treference);
  584. begin
  585. if istemp(ref) then
  586. FreeTemp(list,ref.offset,[tt_normal]);
  587. end;
  588. procedure ttgobj.getlocal(list: TAsmList; size : longint;def:tdef;var ref : treference);
  589. begin
  590. getlocal(list, size, def.alignment, def, ref);
  591. end;
  592. procedure ttgobj.getlocal(list: TAsmList; size : longint; alignment : shortint; def:tdef;var ref : treference);
  593. begin
  594. alignment:=used_align(alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax);
  595. { can't use reference_reset_base, because that will let tgobj depend
  596. on cgobj (PFV) }
  597. fillchar(ref,sizeof(ref),0);
  598. ref.base:=current_procinfo.framepointer;
  599. ref.offset:=alloctemp(list,size,alignment,tt_persistent,nil);
  600. ref.alignment:=alignment;
  601. end;
  602. procedure ttgobj.UnGetLocal(list: TAsmList; const ref : treference);
  603. begin
  604. FreeTemp(list,ref.offset,[tt_persistent]);
  605. end;
  606. end.