tgobj.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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. 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;
  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. function ttgobj.AllocTemp(list: TAsmList; size,alignment : longint; temptype : ttemptype;def : tdef) : longint;
  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. AllocTemp:=0;
  208. bestprev:=nil;
  209. bestslot:=nil;
  210. tl:=nil;
  211. bestatend:=false;
  212. current_procinfo.updatestackalignment(alignment);
  213. if size=0 then
  214. begin
  215. {$ifdef EXTDEBUG}
  216. Comment(V_Warning,'tgobj: (AllocTemp) temp of size 0 requested, allocating 4 bytes');
  217. {$endif}
  218. size:=4;
  219. end;
  220. freetype:=Used2Free[temptype];
  221. if freetype=tt_none then
  222. internalerror(200208201);
  223. size:=align(size,alignment);
  224. { First check the tmpfreelist, but not when
  225. we don't want to reuse an already allocated block }
  226. if assigned(tempfreelist) and
  227. (temptype<>tt_noreuse) then
  228. begin
  229. hprev:=nil;
  230. hp:=tempfreelist;
  231. while assigned(hp) do
  232. begin
  233. {$ifdef EXTDEBUG}
  234. if not(hp^.temptype in FreeTempTypes) then
  235. Comment(V_Warning,'tgobj: (AllocTemp) temp at pos '+tostr(hp^.pos)+ ' in freelist is not set to tt_free !');
  236. {$endif}
  237. { Check only slots that are
  238. - free
  239. - share the same type
  240. - contain enough space
  241. - has a correct alignment }
  242. adjustedpos:=hp^.pos+alignmismatch;
  243. if (hp^.temptype=freetype) and
  244. (hp^.def=def) and
  245. (hp^.size>=size) and
  246. ((adjustedpos=align(adjustedpos,alignment)) or
  247. (adjustedpos+hp^.size-size = align(adjustedpos+hp^.size-size,alignment))) then
  248. begin
  249. { Slot is the same size then leave immediatly }
  250. if (hp^.size=size) then
  251. begin
  252. bestprev:=hprev;
  253. bestslot:=hp;
  254. break;
  255. end
  256. else
  257. begin
  258. { we can fit a smaller block either at the begin or at }
  259. { the end of a block. For direction=-1 we prefer the }
  260. { end, for direction=1 we prefer the begin (i.e., }
  261. { always closest to the source). We also try to use }
  262. { the block with the worst possible alignment that }
  263. { still suffices. And we pick the block which will }
  264. { have the best alignmenment after this new block is }
  265. { substracted from it. }
  266. fitatend:=(adjustedpos+hp^.size-size)=align(adjustedpos+hp^.size-size,alignment);
  267. fitatbegin:=adjustedpos=align(adjustedpos,alignment);
  268. if assigned(bestslot) then
  269. begin
  270. fitatend:=fitatend and
  271. ((not bestatend and
  272. (direction=-1)) or
  273. (bestatend and
  274. isbetteralignedthan(abs(bestslot^.pos+hp^.size-size),abs(adjustedpos+hp^.size-size),current_settings.alignment.localalignmax)));
  275. fitatbegin:=fitatbegin and
  276. (not bestatend or
  277. (direction=1)) and
  278. isbetteralignedthan(abs(adjustedpos+size),abs(bestslot^.pos+size),current_settings.alignment.localalignmax);
  279. end;
  280. if fitatend and
  281. fitatbegin then
  282. if isbetteralignedthan(abs(adjustedpos+hp^.size-size),abs(adjustedpos+size),current_settings.alignment.localalignmax) then
  283. fitatbegin:=false
  284. else if isbetteralignedthan(abs(adjustedpos+size),abs(adjustedpos+hp^.size-size),current_settings.alignment.localalignmax) then
  285. fitatend:=false
  286. else if (direction=1) then
  287. fitatend:=false
  288. else
  289. fitatbegin:=false;
  290. if fitatend or
  291. fitatbegin then
  292. begin
  293. bestprev:=hprev;
  294. bestslot:=hp;
  295. bestatend:=fitatend;
  296. end;
  297. end;
  298. end;
  299. hprev:=hp;
  300. hp:=hp^.nextfree;
  301. end;
  302. end;
  303. { Reuse an old temp ? }
  304. if assigned(bestslot) then
  305. begin
  306. if bestslot^.size=size then
  307. begin
  308. tl:=bestslot;
  309. { Remove from the tempfreelist }
  310. if assigned(bestprev) then
  311. bestprev^.nextfree:=tl^.nextfree
  312. else
  313. tempfreelist:=tl^.nextfree;
  314. end
  315. else
  316. begin
  317. { Duplicate bestlost and the block in the list }
  318. new(tl);
  319. move(bestslot^,tl^,sizeof(ttemprecord));
  320. tl^.next:=bestslot^.next;
  321. bestslot^.next:=tl;
  322. { Now we split the block in 2 parts. Depending on the direction
  323. we need to resize the newly inserted block or the old reused block.
  324. For direction=1 we can use tl for the new block. For direction=-1 we
  325. will be reusing bestslot and resize the new block, that means we need
  326. to swap the pointers }
  327. if (direction=-1) xor
  328. bestatend then
  329. begin
  330. htl:=tl;
  331. tl:=bestslot;
  332. bestslot:=htl;
  333. { Update the tempfreelist to point to the new block }
  334. if assigned(bestprev) then
  335. bestprev^.nextfree:=bestslot
  336. else
  337. tempfreelist:=bestslot;
  338. end;
  339. if not bestatend then
  340. inc(bestslot^.pos,size)
  341. else
  342. inc(tl^.pos,tl^.size-size);
  343. { Create new block and resize the old block }
  344. tl^.size:=size;
  345. tl^.nextfree:=nil;
  346. { Resize the old block }
  347. dec(bestslot^.size,size);
  348. end;
  349. tl^.temptype:=temptype;
  350. tl^.def:=def;
  351. tl^.nextfree:=nil;
  352. end
  353. else
  354. begin
  355. { now we can create the templist entry }
  356. new(tl);
  357. tl^.temptype:=temptype;
  358. tl^.def:=def;
  359. { Extend the temp }
  360. if direction=-1 then
  361. begin
  362. lasttemp:=(-align(-lasttemp-alignmismatch,alignment))-size-alignmismatch;
  363. tl^.pos:=lasttemp;
  364. end
  365. else
  366. begin
  367. tl^.pos:=align(lasttemp+alignmismatch,alignment)-alignmismatch;
  368. lasttemp:=tl^.pos+size;
  369. end;
  370. tl^.size:=size;
  371. tl^.next:=templist;
  372. tl^.nextfree:=nil;
  373. templist:=tl;
  374. end;
  375. {$ifdef EXTDEBUG}
  376. tl^.posinfo:=current_filepos;
  377. if assigned(tl^.def) then
  378. list.concat(tai_tempalloc.allocinfo(tl^.pos,tl^.size,'allocated with type '+TempTypeStr[tl^.temptype]+' for def '+tl^.def.typename))
  379. else
  380. list.concat(tai_tempalloc.allocinfo(tl^.pos,tl^.size,'allocated with type '+TempTypeStr[tl^.temptype]));
  381. {$else}
  382. list.concat(tai_tempalloc.alloc(tl^.pos,tl^.size));
  383. {$endif}
  384. AllocTemp:=tl^.pos;
  385. end;
  386. procedure ttgobj.FreeTemp(list: TAsmList; pos:longint;temptypes:ttemptypeset);
  387. var
  388. hp,hnext,hprev,hprevfree : ptemprecord;
  389. begin
  390. hp:=templist;
  391. hprev:=nil;
  392. hprevfree:=nil;
  393. while assigned(hp) do
  394. begin
  395. if (hp^.pos=pos) then
  396. begin
  397. { check if already freed }
  398. if hp^.temptype in FreeTempTypes then
  399. begin
  400. {$ifdef EXTDEBUG}
  401. Comment(V_Warning,'tgobj: (FreeTemp) temp at pos '+tostr(pos)+ ' is already free !');
  402. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'temp is already freed'));
  403. {$endif}
  404. exit;
  405. end;
  406. { check type that are allowed to be released }
  407. if not(hp^.temptype in temptypes) then
  408. begin
  409. {$ifdef EXTDEBUG}
  410. Comment(V_Debug,'tgobj: (Freetemp) temp at pos '+tostr(pos)+ ' has different type ('+TempTypeStr[hp^.temptype]+'), not releasing');
  411. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'temp has wrong type ('+TempTypeStr[hp^.temptype]+') not releasing'));
  412. {$endif}
  413. exit;
  414. end;
  415. list.concat(tai_tempalloc.dealloc(hp^.pos,hp^.size));
  416. { set this block to free }
  417. hp^.temptype:=Used2Free[hp^.temptype];
  418. { Update tempfreelist }
  419. if assigned(hprevfree) then
  420. begin
  421. { Concat blocks when the previous block is free and
  422. there is no block assigned for a tdef }
  423. if assigned(hprev) and
  424. (hp^.temptype=tt_free) and
  425. not assigned(hp^.def) and
  426. (hprev^.temptype=tt_free) and
  427. not assigned(hprev^.def) then
  428. begin
  429. inc(hprev^.size,hp^.size);
  430. if direction=1 then
  431. hprev^.pos:=hp^.pos;
  432. hprev^.next:=hp^.next;
  433. dispose(hp);
  434. hp:=hprev;
  435. end
  436. else
  437. hprevfree^.nextfree:=hp;
  438. end
  439. else
  440. begin
  441. hp^.nextfree:=tempfreelist;
  442. tempfreelist:=hp;
  443. end;
  444. { Concat blocks when the next block is free and
  445. there is no block assigned for a tdef }
  446. hnext:=hp^.next;
  447. if assigned(hnext) and
  448. (hp^.temptype=tt_free) and
  449. not assigned(hp^.def) and
  450. (hnext^.temptype=tt_free) and
  451. not assigned(hnext^.def) then
  452. begin
  453. inc(hp^.size,hnext^.size);
  454. if direction=1 then
  455. hp^.pos:=hnext^.pos;
  456. hp^.nextfree:=hnext^.nextfree;
  457. hp^.next:=hnext^.next;
  458. dispose(hnext);
  459. end;
  460. { Stop }
  461. exit;
  462. end;
  463. if (hp^.temptype=tt_free) then
  464. hprevfree:=hp;
  465. hprev:=hp;
  466. hp:=hp^.next;
  467. end;
  468. end;
  469. procedure ttgobj.gethltemp(list: TAsmList; def: tdef; forcesize: aint; temptype: ttemptype; out ref: treference);
  470. begin
  471. gettemp(list,forcesize,def.alignment,temptype,ref);
  472. end;
  473. procedure ttgobj.gethltemptyped(list: TAsmList; def: tdef; temptype: ttemptype; out ref: treference);
  474. begin
  475. gettemptyped(list,def,temptype,ref);
  476. end;
  477. procedure ttgobj.gettemp(list: TAsmList; size, alignment : longint;temptype:ttemptype;out ref : treference);
  478. begin
  479. gettempinternal(list,size,alignment,temptype,nil,ref);
  480. end;
  481. procedure ttgobj.gettempinternal(list: TAsmList; size, alignment : longint;temptype:ttemptype;def: tdef;out ref : treference);
  482. var
  483. varalign : shortint;
  484. begin
  485. varalign:=used_align(alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax);
  486. { can't use reference_reset_base, because that will let tgobj depend
  487. on cgobj (PFV) }
  488. fillchar(ref,sizeof(ref),0);
  489. ref.base:=current_procinfo.framepointer;
  490. ref.offset:=alloctemp(list,size,varalign,temptype,def);
  491. ref.alignment:=varalign;
  492. end;
  493. procedure ttgobj.gettemptyped(list: TAsmList; def:tdef;temptype:ttemptype;out ref : treference);
  494. begin
  495. gettempinternal(list,def.size,def.alignment,temptype,def,ref);
  496. end;
  497. function ttgobj.istemp(const ref : treference) : boolean;
  498. begin
  499. { ref.index = R_NO was missing
  500. led to problems with local arrays
  501. with lower bound > 0 (PM) }
  502. if direction = 1 then
  503. begin
  504. istemp:=(ref.base=current_procinfo.framepointer) and
  505. (ref.index=NR_NO) and
  506. (ref.offset>=firsttemp);
  507. end
  508. else
  509. begin
  510. istemp:=(ref.base=current_procinfo.framepointer) and
  511. (ref.index=NR_NO) and
  512. (ref.offset<firsttemp);
  513. end;
  514. end;
  515. function ttgobj.sizeoftemp(list: TAsmList; const ref: treference): longint;
  516. var
  517. hp : ptemprecord;
  518. begin
  519. SizeOfTemp := -1;
  520. hp:=templist;
  521. while assigned(hp) do
  522. begin
  523. if (hp^.pos=ref.offset) then
  524. begin
  525. sizeoftemp := hp^.size;
  526. exit;
  527. end;
  528. hp := hp^.next;
  529. end;
  530. {$ifdef EXTDEBUG}
  531. comment(v_debug,'tgobj: (SizeOfTemp) temp at pos '+tostr(ref.offset)+' not found !');
  532. list.concat(tai_tempalloc.allocinfo(ref.offset,0,'temp not found'));
  533. {$endif}
  534. end;
  535. function ttgobj.changetemptype(list: tasmList; const ref:treference; temptype:ttemptype):boolean;
  536. var
  537. hp : ptemprecord;
  538. begin
  539. ChangeTempType:=false;
  540. hp:=templist;
  541. while assigned(hp) do
  542. begin
  543. if (hp^.pos=ref.offset) then
  544. begin
  545. if hp^.temptype<>tt_free then
  546. begin
  547. {$ifdef EXTDEBUG}
  548. if hp^.temptype=temptype then
  549. Comment(V_Warning,'tgobj: (ChangeTempType) temp'+
  550. ' at pos '+tostr(ref.offset)+ ' is already of the correct type !');
  551. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'type changed to '+TempTypeStr[temptype]));
  552. {$endif}
  553. ChangeTempType:=true;
  554. hp^.temptype:=temptype;
  555. end
  556. else
  557. begin
  558. {$ifdef EXTDEBUG}
  559. Comment(V_Warning,'tgobj: (ChangeTempType) temp'+
  560. ' at pos '+tostr(ref.offset)+ ' is already freed !');
  561. list.concat(tai_tempalloc.allocinfo(hp^.pos,hp^.size,'temp is already freed'));
  562. {$endif}
  563. end;
  564. exit;
  565. end;
  566. hp:=hp^.next;
  567. end;
  568. {$ifdef EXTDEBUG}
  569. Comment(V_Warning,'tgobj: (ChangeTempType) temp'+
  570. ' at pos '+tostr(ref.offset)+ ' not found !');
  571. list.concat(tai_tempalloc.allocinfo(ref.offset,0,'temp not found'));
  572. {$endif}
  573. end;
  574. function ttgobj.gettypeoftemp(const ref:treference): ttemptype;
  575. var
  576. hp : ptemprecord;
  577. begin
  578. hp:=templist;
  579. while assigned(hp) do
  580. begin
  581. if (hp^.pos=ref.offset) then
  582. begin
  583. if hp^.temptype<>tt_free then
  584. result:=hp^.temptype
  585. else
  586. internalerror(2007020810);
  587. exit;
  588. end;
  589. hp:=hp^.next;
  590. end;
  591. result:=tt_none;
  592. end;
  593. procedure ttgobj.UnGetTemp(list: TAsmList; const ref : treference);
  594. begin
  595. FreeTemp(list,ref.offset,[tt_normal,tt_noreuse,tt_persistent,tt_regallocator]);
  596. end;
  597. procedure ttgobj.UnGetIfTemp(list: TAsmList; const ref : treference);
  598. begin
  599. if istemp(ref) then
  600. FreeTemp(list,ref.offset,[tt_normal]);
  601. end;
  602. procedure ttgobj.getlocal(list: TAsmList; size : longint;def:tdef;var ref : treference);
  603. begin
  604. getlocal(list, size, def.alignment, def, ref);
  605. end;
  606. procedure ttgobj.getlocal(list: TAsmList; size : longint; alignment : shortint; def:tdef;var ref : treference);
  607. begin
  608. alignment:=used_align(alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax);
  609. { can't use reference_reset_base, because that will let tgobj depend
  610. on cgobj (PFV) }
  611. fillchar(ref,sizeof(ref),0);
  612. ref.base:=current_procinfo.framepointer;
  613. ref.offset:=alloctemp(list,size,alignment,tt_persistent,nil);
  614. ref.alignment:=alignment;
  615. end;
  616. procedure ttgobj.UnGetLocal(list: TAsmList; const ref : treference);
  617. begin
  618. FreeTemp(list,ref.offset,[tt_persistent]);
  619. end;
  620. end.