tgobj.pas 25 KB

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