csopt386.pas 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Jonas Maebe, member of the Free Pascal
  4. development team
  5. This unit contains the common subexpression elimination procedure.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit CSOpt386;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses aasmbase,aasmtai,aasmcpu, cpuinfo, cpubase, optbase, cgbase;
  23. function CSE(asml: TAAsmoutput; first, last: tai; pass: longint): boolean;
  24. function doReplaceReg(hp: taicpu; newReg, orgReg: tsuperregister): boolean;
  25. function changeOp(var o: toper; newReg, orgReg: tsuperregister): boolean;
  26. function storeBack(start, current: tai; orgReg, newReg: tsuperregister): boolean;
  27. function NoHardCodedRegs(p: taicpu; orgReg, newReg: tsuperregister): boolean;
  28. function RegSizesOK(oldReg,newReg: tsuperregister; p: taicpu): boolean;
  29. implementation
  30. uses
  31. {$ifdef csdebug}
  32. cutils,
  33. {$else}
  34. {$ifdef replaceregdebug}cutils,{$endif}
  35. {$endif}
  36. globtype, verbose, procinfo, globals, daopt386, rgobj, rropt386;
  37. {
  38. function TaiInSequence(P: tai; Const Seq: TContent): Boolean;
  39. var P1: tai;
  40. Counter: Byte;
  41. TmpResult: Boolean;
  42. begin
  43. TmpResult := False;
  44. P1 := Seq.StartMod;
  45. Counter := 1;
  46. while not(TmpResult) and
  47. (Counter <= Seq.NrofMods) do
  48. begin
  49. if (P = P1) then TmpResult := True;
  50. inc(Counter);
  51. p1 := tai(p1.Next);
  52. end;
  53. TaiInSequence := TmpResult;
  54. end;
  55. }
  56. function modifiesConflictingMemLocation(p1: tai; supreg: tsuperregister; c: tregContent;
  57. var regsStillValid: tregset; onlymem: boolean; var invalsmemwrite: boolean): boolean;
  58. var
  59. p, hp: taicpu;
  60. tmpRef: treference;
  61. r,regCounter: tsuperregister;
  62. opCount: byte;
  63. dummy: boolean;
  64. begin
  65. modifiesConflictingMemLocation := false;
  66. invalsmemwrite := false;
  67. if p1.typ <> ait_instruction then
  68. exit;
  69. p := taicpu(p1);
  70. case p.opcode of
  71. A_MOV,A_MOVSX,A_MOVZX:
  72. if p.oper[1]^.typ = top_ref then
  73. for regCounter := RS_EAX to RS_EDI do
  74. begin
  75. if p.oper[0]^.typ<>top_reg then
  76. break;
  77. if writeToMemDestroysContents(getsupreg(p.oper[0]^.reg),p.oper[1]^.ref^,
  78. regCounter,c[regCounter],dummy) then
  79. begin
  80. exclude(regsStillValid,regCounter);
  81. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  82. end;
  83. if (regcounter = supreg) then
  84. invalsmemwrite := invalsmemwrite or dummy;
  85. end
  86. else
  87. { if is_reg_var[getsupreg(p.oper[1]^.reg)] then }
  88. if not onlymem then
  89. for regCounter := RS_EAX to RS_EDI do
  90. begin
  91. if writeDestroysContents(p.oper[1]^,regCounter,c[regCounter],dummy) then
  92. begin
  93. exclude(regsStillValid,regCounter);
  94. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  95. end
  96. end;
  97. A_DIV, A_IDIV, A_MUL, A_IMUL:
  98. begin
  99. if not onlymem then
  100. if (p.ops = 1) then
  101. begin
  102. for regCounter := RS_EAX to RS_EDI do
  103. begin
  104. if writeToRegDestroysContents(RS_EDX,regCounter,c[regCounter]) then
  105. begin
  106. exclude(regsStillValid,RS_EDX);
  107. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  108. end;
  109. if writeToRegDestroysContents(RS_EAX,regCounter,c[regCounter]) then
  110. begin
  111. exclude(regsStillValid,RS_EAX);
  112. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  113. end;
  114. end
  115. end
  116. else
  117. { only possible for imul }
  118. { last operand is always destination }
  119. for regCounter := RS_EAX to RS_EDI do
  120. begin
  121. if writeDestroysContents(p.oper[p.ops-1]^,regCounter,c[regCounter],dummy) then
  122. begin
  123. exclude(regsStillValid,regCounter);
  124. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  125. end
  126. end
  127. end;
  128. else
  129. for opCount := 1 to maxinschanges do
  130. case InsProp[p.opcode].Ch[opCount] of
  131. Ch_MOp1,CH_WOp1,CH_RWOp1:
  132. if not(onlymem) or
  133. (p.oper[0]^.typ = top_ref) then
  134. { or ((p.oper[0]^.typ = top_reg) and }
  135. { is_reg_var[getsupreg(p.oper[0]^.reg)]) then }
  136. for regCounter := RS_EAX to RS_EDI do
  137. begin
  138. if writeDestroysContents(p.oper[0]^,regCounter,c[regCounter],dummy) then
  139. begin
  140. exclude(regsStillValid,regCounter);
  141. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  142. end;
  143. if (regcounter = supreg) then
  144. invalsmemwrite := invalsmemwrite or dummy;
  145. end;
  146. Ch_MOp2,CH_WOp2,CH_RWOp2:
  147. if not(onlymem) or
  148. (p.oper[1]^.typ = top_ref) then
  149. { or ((p.oper[1]^.typ = top_reg) and }
  150. { is_reg_var[getsupreg(p.oper[1]^.reg)]) then }
  151. for regCounter := RS_EAX to RS_EDI do
  152. begin
  153. if writeDestroysContents(p.oper[1]^,regCounter,c[regCounter],dummy) then
  154. begin
  155. exclude(regsStillValid,regCounter);
  156. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  157. end;
  158. if (regcounter = supreg) then
  159. invalsmemwrite := invalsmemwrite or dummy;
  160. end;
  161. Ch_MOp3,CH_WOp3,CH_RWOp3:
  162. if not(onlymem) or
  163. (p.oper[2]^.typ = top_ref) then
  164. { or ((p.oper[2]^.typ = top_reg) and }
  165. { is_reg_var[getsupreg(p.oper[2]^.reg)]) then }
  166. for regCounter := RS_EAX to RS_EDI do
  167. begin
  168. if writeDestroysContents(p.oper[2]^,regCounter,c[regCounter],dummy) then
  169. begin
  170. exclude(regsStillValid,regCounter);
  171. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  172. end;
  173. if (regcounter = supreg) then
  174. invalsmemwrite := invalsmemwrite or dummy;
  175. end;
  176. Ch_WMemEDI:
  177. begin
  178. fillchar(tmpref,sizeof(tmpref),0);
  179. tmpRef.base := NR_EDI;
  180. tmpRef.index := NR_EDI;
  181. for regCounter := RS_EAX to RS_EDI do
  182. if writeToMemDestroysContents(RS_INVALID,tmpRef,regCounter,c[regCounter],dummy) then
  183. begin
  184. exclude(regsStillValid,regCounter);
  185. modifiesConflictingMemLocation := not(supreg in regsStillValid);
  186. end;
  187. if (regcounter = supreg) then
  188. invalsmemwrite := invalsmemwrite or dummy;
  189. end;
  190. end;
  191. end;
  192. end;
  193. function isSimpleMemLoc(const ref: treference): boolean;
  194. begin
  195. { isSimpleMemLoc :=
  196. (ref.index = RS_NO) and
  197. not(ref.base in (rg.usableregsint+[RS_EDI]));}
  198. isSimpleMemLoc :=
  199. (ref.index = NR_NO) and
  200. ((ref.base = NR_NO) or
  201. not(getsupreg(ref.base) in [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESI,RS_EDI]));
  202. end;
  203. {checks whether the current instruction sequence (starting with p) and the
  204. one between StartMod and EndMod of Reg are the same. if so, the number of
  205. instructions that match is stored in Found and true is returned, otherwise
  206. Found holds the number of instructions between StartMod and EndMod and false
  207. is returned}
  208. function CheckSequence(p: tai; var prev: tai; supreg: tsuperregister; var Found: Longint;
  209. var reginfo: toptreginfo; findPrevSeqs: boolean): Boolean;
  210. var
  211. regsNotRead, regsStillValid : tregset;
  212. checkingPrevSequences,
  213. passedFlagsModifyingInstr,
  214. invalsmemwrite : boolean;
  215. function getPrevSequence(p: tai; supreg: tsuperregister; currentPrev: tai; var newPrev: tai): tsuperregister;
  216. const
  217. current_reg: tsuperregister = RS_INVALID;
  218. function stillValid(p: tai): boolean;
  219. var
  220. hp: tai;
  221. begin
  222. stillValid :=
  223. (p.typ = ait_instruction) and
  224. (taicpu(p).opcode <> a_jmp) and
  225. (ptaiprop(p.optinfo)^.regs[supreg].wstate =
  226. ptaiprop(currentPrev.optinfo)^.regs[supreg].wstate) and
  227. { in case destroyreg is called with doIncState = false }
  228. (ptaiprop(p.optinfo)^.regs[supreg].typ =
  229. ptaiprop(currentPrev.optinfo)^.regs[supreg].typ) and
  230. (supreg in (regsNotRead * regsStillValid));
  231. { stop if the register was still used right before a (conditional) }
  232. { jump, since in that case its current contents could still be }
  233. { used in the other path of the jump) }
  234. if (p.typ = ait_instruction) and
  235. (taicpu(p).is_jmp) and
  236. getlastinstruction(p,hp) then
  237. stillValid := stillValid and
  238. not(supreg in ptaiprop(hp.optinfo)^.usedregs);
  239. passedFlagsModifyingInstr :=
  240. instrWritesFlags(currentPrev);
  241. end;
  242. function findChangedRegister(p: tai): tsuperregister;
  243. var
  244. regCounter, loopstart: tsuperregister;
  245. begin
  246. if (current_reg <> RS_INVALID) then
  247. loopstart := succ(current_reg)
  248. else
  249. loopstart := RS_EAX;
  250. for regCounter := loopstart to RS_EDI do
  251. with ptaiprop(p.optinfo)^.regs[regCounter] do
  252. if ((startmod <>
  253. ptaiprop(currentPrev.optinfo)^.regs[regCounter].startmod) or
  254. (nrofMods <>
  255. ptaiprop(currentPrev.optinfo)^.regs[regCounter].nrofMods)) and
  256. (ptaiprop(p.optinfo)^.regs[regCounter].typ in [con_ref,con_noRemoveRef]) then
  257. begin
  258. findChangedRegister := regCounter;
  259. current_reg := regCounter;
  260. exit;
  261. end;
  262. current_reg := RS_INVALID;
  263. findChangedRegister := RS_INVALID;
  264. end;
  265. var
  266. hp, prevFound: tai;
  267. tmpResult, regCounter: tsuperregister;
  268. invalsmemwrite: boolean;
  269. begin
  270. if (current_reg <> RS_EDI) and
  271. (current_reg <> RS_INVALID) then
  272. begin
  273. tmpResult := findChangedRegister(currentPrev);
  274. if tmpResult <> RS_INVALID then
  275. begin
  276. getPrevSequence := tmpResult;
  277. exit;
  278. end;
  279. end;
  280. getPrevSequence := RS_INVALID;
  281. passedFlagsModifyingInstr := instrWritesFlags(currentPrev);
  282. if not getLastInstruction(currentPrev,hp) then
  283. exit;
  284. prevFound := currentPrev;
  285. tmpResult := RS_INVALID;
  286. while (tmpResult = RS_INVALID) and
  287. stillValid(hp) and
  288. (ptaiprop(prevFound.optinfo)^.canBeRemoved or
  289. not(modifiesConflictingMemLocation(prevFound,supreg,
  290. ptaiprop(p.optinfo)^.regs,regsStillValid,false, invalsmemwrite))) do
  291. begin
  292. { only update the regsread for the instructions we already passed }
  293. if not(ptaiprop(prevFound.optinfo)^.canBeRemoved) then
  294. for regCounter := RS_EAX to RS_EDI do
  295. if regReadByInstruction(regCounter,prevFound) then
  296. exclude(regsNotRead,regCounter);
  297. { in case getPreviousInstruction fails and sets hp to nil in the }
  298. { next iteration }
  299. prevFound := hp;
  300. if not(ptaiprop(hp.optinfo)^.canBeRemoved) then
  301. tmpResult := findChangedRegister(hp);
  302. if not getLastInstruction(hp,hp) then
  303. break;
  304. end;
  305. getPrevSequence := tmpResult;
  306. if tmpResult <> RS_INVALID then
  307. newPrev := prevFound;
  308. end;
  309. function getNextRegToTest(var prev: tai; currentReg: tsuperregister): tsuperregister;
  310. begin
  311. if not checkingPrevSequences then
  312. begin
  313. if (currentreg = RS_INVALID) then
  314. currentreg := RS_EAX
  315. else
  316. inc(currentreg);
  317. while (currentReg <= RS_EDI) and
  318. not(ptaiprop(prev.optinfo)^.regs[currentReg].typ in [con_ref,con_noRemoveRef]) do
  319. inc(currentReg);
  320. if currentReg > RS_EDI then
  321. begin
  322. if (taicpu(p).oper[0]^.typ <> top_ref) or
  323. isSimpleMemLoc(taicpu(p).oper[0]^.ref^) then
  324. begin
  325. checkingPrevSequences := true;
  326. end
  327. else
  328. getNextRegToTest := RS_INVALID;
  329. end
  330. else
  331. getNextRegToTest := currentReg;
  332. end;
  333. if checkingPrevSequences then
  334. if findPrevSeqs then
  335. getNextRegToTest :=
  336. getPrevSequence(p,supreg,prev,prev)
  337. else
  338. getNextRegToTest := RS_INVALID;
  339. end;
  340. function changedreginvalidatedbetween(const oldreginfo: toptreginfo; var newreginfo: toptreginfo; startp,endp,current: tai): boolean;
  341. var
  342. orgdiffregs,diffregs: tregset;
  343. runner: tai;
  344. invalsmemwrite: boolean;
  345. begin
  346. diffregs := newreginfo.newregsencountered - oldreginfo.newregsencountered;
  347. orgdiffregs := diffregs;
  348. if diffregs <> [] then
  349. begin
  350. runner := startp;
  351. repeat
  352. modifiesConflictingMemLocation(runner,RS_EAX { dummy },ptaiprop(current.optinfo)^.regs,diffregs,true,invalsmemwrite);
  353. if orgdiffregs <> diffregs then
  354. begin
  355. changedreginvalidatedbetween := true;
  356. newreginfo := oldreginfo;
  357. exit;
  358. end;
  359. getnextinstruction(runner,runner);
  360. until (runner = endp);
  361. end;
  362. changedreginvalidatedbetween := false;
  363. end;
  364. var
  365. prevreginfo: toptreginfo;
  366. hp2, hp3{, EndMod},highPrev, orgPrev: tai;
  367. {Cnt,} OldNrofMods: Longint;
  368. startRegInfo, OrgRegInfo, HighRegInfo: toptreginfo;
  369. regModified: array[RS_EAX..RS_ESP] of boolean;
  370. HighFound, OrgRegFound: longint;
  371. regcounter, regCounter2, tmpreg, base, index: tsuperregister;
  372. OrgRegResult: Boolean;
  373. TmpResult, flagResultsNeeded, stopchecking: Boolean;
  374. begin {CheckSequence}
  375. TmpResult := False;
  376. FillChar(OrgRegInfo, Sizeof(OrgRegInfo), 0);
  377. FillChar(startRegInfo, sizeof(startRegInfo), 0);
  378. OrgRegFound := 0;
  379. HighFound := 0;
  380. OrgRegResult := False;
  381. with startRegInfo do
  382. begin
  383. newRegsEncountered := [RS_EBP, RS_ESP];
  384. fillword(new2oldreg,sizeof(new2oldreg),RS_INVALID);
  385. new2OldReg[RS_EBP] := RS_EBP;
  386. new2OldReg[RS_ESP] := RS_ESP;
  387. oldRegsEncountered := newRegsEncountered;
  388. end;
  389. checkingPrevSequences := false;
  390. passedFlagsModifyingInstr := false;
  391. flagResultsNeeded := false;
  392. regsNotRead := [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESP,RS_EBP,RS_EDI,RS_ESI];
  393. regsStillValid := regsNotRead;
  394. GetLastInstruction(p, prev);
  395. tmpreg:=RS_INVALID;
  396. regCounter := getNextRegToTest(prev,tmpreg);
  397. while (regcounter <> RS_INVALID) do
  398. begin
  399. fillchar(regModified,sizeof(regModified),0);
  400. reginfo := startRegInfo;
  401. Found := 0;
  402. hp2 := ptaiprop(prev.optinfo)^.Regs[regcounter].StartMod;
  403. if (prev <> ptaiprop(prev.optinfo)^.Regs[regcounter].StartMod) then
  404. OldNrofMods := ptaiprop(prev.optinfo)^.Regs[regcounter].NrofMods
  405. else
  406. OldNrofMods := 1;
  407. hp3 := p;
  408. if checkingprevsequences then
  409. prevreginfo := reginfo;
  410. stopchecking := false;
  411. while (Found <> OldNrofMods) and
  412. { old new }
  413. InstructionsEquivalent(hp2, hp3, reginfo) and
  414. (not(checkingprevsequences) or
  415. not(changedreginvalidatedbetween(prevreginfo,reginfo,prev,p,hp3))) do
  416. begin
  417. if checkingprevsequences then
  418. begin
  419. prevreginfo := reginfo;
  420. end
  421. else if (hp3.typ = ait_instruction) and
  422. ((taicpu(hp3).opcode = A_MOV) or
  423. (taicpu(hp3).opcode = A_MOVZX) or
  424. (taicpu(hp3).opcode = A_LEA) or
  425. (taicpu(hp3).opcode = A_MOVSX)) and
  426. (taicpu(hp3).oper[1]^.typ = top_reg) and
  427. not(regInOp(getsupreg(taicpu(hp3).oper[1]^.reg),taicpu(hp3).oper[0]^)) then
  428. begin
  429. tmpreg := getsupreg(taicpu(hp3).oper[1]^.reg);
  430. reginfo.lastReload[tmpreg] := hp3;
  431. case taicpu(hp3).oper[0]^.typ of
  432. top_ref:
  433. begin
  434. base := getsupreg(taicpu(hp3).oper[0]^.ref^.base);
  435. index := getsupreg(taicpu(hp3).oper[0]^.ref^.index);
  436. if (found <> 0) and
  437. ((taicpu(hp3).oper[0]^.ref^.base = NR_NO) or
  438. regModified[base] or
  439. (base = getsupreg(current_procinfo.framepointer))) and
  440. ((taicpu(hp3).oper[0]^.ref^.index = NR_NO) or
  441. regModified[index]) and
  442. not(regInRef(tmpReg,taicpu(hp3).oper[0]^.ref^)) then
  443. begin
  444. with ptaiprop(hp3.optinfo)^.regs[tmpreg] do
  445. if nrofMods > (oldNrofMods - found) then
  446. oldNrofMods := found + nrofMods;
  447. end;
  448. end;
  449. top_reg:
  450. if regModified[getsupreg(taicpu(hp3).oper[0]^.reg)] then
  451. with ptaiprop(hp3.optinfo)^.regs[tmpreg] do
  452. if nrofMods > (oldNrofMods - found) then
  453. oldNrofMods := found + nrofMods;
  454. end;
  455. end;
  456. for regCounter2 := RS_EAX to RS_EDI do
  457. regModified[regCounter2] := regModified[regCounter2] or
  458. regModifiedByInstruction(regCounter2,hp3);
  459. if flagResultsNeeded then
  460. flagResultsNeeded := not instrReadsFlags(hp3);
  461. if not flagResultsNeeded then
  462. flagResultsNeeded := ptaiprop(hp3.optinfo)^.FlagsUsed;
  463. GetNextInstruction(hp2, hp2);
  464. GetNextInstruction(hp3, hp3);
  465. inc(Found);
  466. end;
  467. for regCounter2 := RS_EAX to RS_EDI do
  468. if (reginfo.new2OldReg[regCounter2] <> RS_INVALID) and
  469. (regCounter2 in ptaiprop(hp3.optinfo)^.usedRegs) and
  470. not regLoadedWithNewValue(regCounter2,false,hp3) then
  471. include(reginfo.regsStillUsedAfterSeq,regCounter2);
  472. if checkingPrevSequences then
  473. begin
  474. for regCounter2 := RS_EAX to RS_EDI do
  475. if (reginfo.new2OldReg[regCounter2] <> RS_INVALID) and
  476. (reginfo.new2OldReg[regCounter2] <> regCounter2) and
  477. (not(regCounter2 in (regsNotRead * regsStillValid)) or
  478. not(reginfo.new2OldReg[regCounter2] in regsStillValid)) then
  479. begin
  480. found := 0;
  481. break;
  482. end;
  483. if passedFlagsModifyingInstr and flagResultsNeeded then
  484. found := 0;
  485. end;
  486. TmpResult := true;
  487. if (found <> OldNrofMods) then
  488. TmpResult := false
  489. else if assigned(hp3) then
  490. for regcounter2 := RS_EAX to RS_EDI do
  491. if (regcounter2 in reginfo.regsLoadedforRef) and
  492. (regcounter2 in ptaiprop(hp3.optinfo)^.usedRegs) and
  493. not regLoadedWithNewValue(regcounter2,false,hp3) then
  494. begin
  495. TmpResult := False;
  496. if (found > 0) then
  497. {this is correct because we only need to turn off the CanBeRemoved flag
  498. when an instruction has already been processed by CheckSequence
  499. (otherwise CanBeRemoved can't be true and thus can't have to be turned off).
  500. if it has already been processed by CheckSequence and flagged to be
  501. removed, it means that it has been checked against a previous sequence
  502. and that it was equal (otherwise CheckSequence would have returned false
  503. and the instruction wouldn't have been removed). if this "if found > 0"
  504. check is left out, incorrect optimizations are performed.}
  505. Found := ptaiprop(tai(p).optinfo)^.Regs[supreg].NrofMods;
  506. break;
  507. end;
  508. if TmpResult and
  509. (Found > HighFound) then
  510. begin
  511. highPrev := prev;
  512. HighFound := Found;
  513. HighRegInfo := reginfo;
  514. end;
  515. if (regcounter = supreg) then
  516. begin
  517. orgPrev := prev;
  518. OrgRegFound := Found;
  519. OrgRegResult := TmpResult;
  520. OrgRegInfo := reginfo
  521. end;
  522. regCounter := getNextRegToTest(prev,regCounter);
  523. end;
  524. if (HighFound > 0) and
  525. (not(OrgRegResult) Or
  526. (HighFound > OrgRegFound))
  527. then
  528. begin
  529. {$ifndef fpc}
  530. TmpResult := True;
  531. {$else fpc}
  532. CheckSequence := True;
  533. {$endif fpc}
  534. prev := highPrev;
  535. reginfo := HighRegInfo;
  536. Found := HighFound
  537. end
  538. else
  539. begin
  540. {$ifndef fpc}
  541. TmpResult := OrgRegResult;
  542. {$else fpc}
  543. CheckSequence := OrgRegResult;
  544. {$endif fpc}
  545. prev := orgPrev;
  546. Found := OrgRegFound;
  547. reginfo := OrgRegInfo;
  548. end;
  549. {$ifndef fpc}
  550. CheckSequence := TmpResult;
  551. {$endif fpc}
  552. end; {CheckSequence}
  553. procedure SetAlignReg(p: tai);
  554. Const alignSearch = 12;
  555. var regsUsable: TRegSet;
  556. prevInstrCount, nextInstrCount: Longint;
  557. prevState, nextWState,nextRState: Array[RS_EAX..RS_EDI] of byte;
  558. regCounter, lastRemoved: tsuperregister;
  559. prev, next: tai;
  560. {$ifdef alignregdebug}
  561. temp: tai;
  562. {$endif alignregdebug}
  563. begin
  564. regsUsable := [RS_EAX,RS_ECX,RS_EDX,RS_EBX,{R_ESP,RS_EBP,}RS_ESI,RS_EDI];
  565. for regCounter := RS_EAX to RS_EDI do
  566. begin
  567. prevState[regCounter] := ptaiprop(p.optinfo)^.Regs[regCounter].wState;
  568. nextWState[regCounter] := ptaiprop(p.optinfo)^.Regs[regCounter].wState;
  569. nextRState[regCounter] := ptaiprop(p.optinfo)^.Regs[regCounter].rState;
  570. end;
  571. getLastInstruction(p,prev);
  572. getNextInstruction(p,next);
  573. lastRemoved := getsupreg(tai_align(p).reg);
  574. nextInstrCount := 0;
  575. prevInstrCount := 0;
  576. while ((assigned(prev) and
  577. assigned(prev.optinfo) and
  578. (prevInstrCount < alignSearch)) or
  579. (assigned(next) and
  580. assigned(next.optinfo) and
  581. (nextInstrCount < alignSearch))) and
  582. (regsUsable <> []) do
  583. begin
  584. {$ifdef alignregdebug}
  585. if assigned(prev) then
  586. begin
  587. temp := tai_comment.Create(strpnew('got here'));
  588. temp.next := prev.next;
  589. temp.previous := prev;
  590. prev.next := temp;
  591. if assigned(temp.next) then
  592. temp.next.previous := temp;
  593. end;
  594. {$endif alignregdebug}
  595. if assigned(prev) and assigned(prev.optinfo) and
  596. (prevInstrCount < alignSearch) then
  597. begin
  598. if (prev.typ = ait_instruction) and
  599. (insProp[taicpu(prev).opcode].ch[1] <> Ch_ALL) and
  600. (taicpu(prev).opcode <> A_JMP) then
  601. begin
  602. inc(prevInstrCount);
  603. for regCounter := RS_EAX to RS_EDI do
  604. begin
  605. if (regCounter in regsUsable) and
  606. (ptaiprop(prev.optinfo)^.Regs[regCounter].wState <>
  607. prevState[regCounter]) then
  608. begin
  609. lastRemoved := regCounter;
  610. exclude(regsUsable,regCounter);
  611. {$ifdef alignregdebug}
  612. temp := tai_comment.Create(strpnew(
  613. std_regname(newreg(R_INTREGISTER,regCounter,R_SUBWHOLE))+' removed')));
  614. temp.next := prev.next;
  615. temp.previous := prev;
  616. prev.next := temp;
  617. if assigned(temp.next) then
  618. temp.next.previous := temp;
  619. if regsUsable = [] then
  620. begin
  621. temp := tai_comment.Create(strpnew(
  622. 'regsUsable empty here')));
  623. temp.next := prev.next;
  624. temp.previous := prev;
  625. prev.next := temp;
  626. if assigned(temp.next) then
  627. temp.next.previous := temp;
  628. end;
  629. {$endif alignregdebug}
  630. end;
  631. prevState[regCounter] :=
  632. ptaiprop(prev.optinfo)^.Regs[regCounter].wState;
  633. end;
  634. getLastInstruction(prev,prev);
  635. end
  636. else
  637. if GetLastInstruction(prev,prev) and
  638. assigned(prev.optinfo) then
  639. for regCounter := RS_EAX to RS_EDI do
  640. prevState[regCounter] :=
  641. ptaiprop(prev.optinfo)^.Regs[regCounter].wState
  642. end;
  643. if assigned(next) and assigned(next.optinfo) and
  644. (nextInstrCount < alignSearch) then
  645. begin
  646. if (next.typ = ait_instruction) and
  647. (insProp[taicpu(next).opcode].ch[1] <> Ch_ALL) and
  648. (taicpu(next).opcode <> A_JMP) then
  649. begin
  650. inc(nextInstrCount);
  651. for regCounter := RS_EAX to RS_EDI do
  652. begin
  653. if (regCounter in regsUsable) and
  654. ((ptaiprop(next.optinfo)^.Regs[regCounter].wState <>
  655. nextWState[regCounter]) or
  656. (ptaiprop(next.optinfo)^.Regs[regCounter].rState <>
  657. nextRState[regCounter])) then
  658. begin
  659. lastRemoved := regCounter;
  660. exclude(regsUsable,regCounter);
  661. {$ifdef alignregdebug}
  662. temp := tai_comment.Create(strpnew(
  663. std_regname(newreg(R_INTREGISTER,regCounter,R_SUBWHOLE))+' removed')));
  664. temp.next := next.next;
  665. temp.previous := next;
  666. next.next := temp;
  667. if assigned(temp.next) then
  668. temp.next.previous := temp;
  669. if regsUsable = [] then
  670. begin
  671. temp := tai_comment.Create(strpnew(
  672. 'regsUsable empty here')));
  673. temp.next := next.next;
  674. temp.previous := next;
  675. next.next := temp;
  676. if assigned(temp.next) then
  677. temp.next.previous := temp;
  678. end;
  679. {$endif alignregdebug}
  680. end;
  681. nextWState[regCounter] :=
  682. ptaiprop(next.optinfo)^.Regs[regCounter].wState;
  683. nextRState[regCounter] :=
  684. ptaiprop(next.optinfo)^.Regs[regCounter].rState;
  685. end
  686. end
  687. else
  688. for regCounter := RS_EAX to RS_EDI do
  689. begin
  690. nextWState[regCounter] :=
  691. ptaiprop(next.optinfo)^.Regs[regCounter].wState;
  692. nextRState[regCounter] :=
  693. ptaiprop(next.optinfo)^.Regs[regCounter].rState;
  694. end;
  695. getNextInstruction(next,next);
  696. end;
  697. end;
  698. if regsUsable <> [] then
  699. for regCounter := RS_EAX to RS_EDI do
  700. if regCounter in regsUsable then
  701. begin
  702. lastRemoved := regCounter;
  703. break
  704. end;
  705. {$ifdef alignregdebug}
  706. next := tai_comment.Create(strpnew(std_regname(newreg(R_INTREGISTER,lastremoved,R_SUBWHOLE))+
  707. ' chosen as alignment register')));
  708. next.next := p.next;
  709. next.previous := p;
  710. p.next := next;
  711. if assigned(next.next) then
  712. next.next.previous := next;
  713. {$endif alignregdebug}
  714. tai_align(p).reg := newreg(R_INTREGISTER,lastRemoved,R_SUBWHOLE);
  715. end;
  716. procedure clearmemwrites(p: tai; supreg: tsuperregister);
  717. var
  718. beginmemwrite: tai;
  719. begin
  720. beginmemwrite := ptaiprop(p.optinfo)^.regs[supreg].memwrite;
  721. repeat
  722. ptaiprop(p.optinfo)^.regs[supreg].memwrite := nil;
  723. until not getnextinstruction(p,p) or
  724. (ptaiprop(p.optinfo)^.regs[supreg].memwrite <> beginmemwrite);
  725. end;
  726. procedure ClearRegContentsFrom(supreg: tsuperregister; p, endP: tai);
  727. { first clears the contents of reg from p till endP. then the contents are }
  728. { cleared until the first instruction that changes reg }
  729. var
  730. {$ifdef replaceregdebug}
  731. hp: tai;
  732. l: longint;
  733. {$endif replaceregdebug}
  734. regcounter: tsuperregister;
  735. oldStartmod: tai;
  736. begin
  737. {$ifdef replaceregdebug}
  738. l := random(1000);
  739. hp := tai_comment.Create(strpnew(
  740. 'cleared '+std_regname(newreg(R_INTREGISTER,supreg,R_SUBWHOLE))+' from here... '+tostr(l)));
  741. hp.next := p;
  742. hp.previous := p.previous;
  743. p.previous := hp;
  744. if assigned(hp.previous) then
  745. hp.previous.next := hp;
  746. {$endif replaceregdebug}
  747. ptaiprop(p.optinfo)^.Regs[supreg].typ := con_unknown;
  748. while (p <> endP) do
  749. begin
  750. for regcounter := RS_EAX to RS_EDI do
  751. if (regcounter <> supreg) and
  752. assigned(ptaiprop(p.optinfo)^.regs[supreg].memwrite) and
  753. reginref(regcounter,ptaiprop(p.optinfo)^.regs[supreg].memwrite.oper[1]^.ref^) then
  754. clearmemwrites(p,regcounter);
  755. with ptaiprop(p.optinfo)^.Regs[supreg] do
  756. begin
  757. typ := con_unknown;
  758. memwrite := nil;
  759. end;
  760. getNextInstruction(p,p);
  761. end;
  762. oldStartmod := ptaiprop(p.optinfo)^.Regs[supreg].startmod;
  763. repeat
  764. with ptaiprop(p.optinfo)^.Regs[supreg] do
  765. begin
  766. typ := con_unknown;
  767. memwrite := nil;
  768. end;
  769. until not getNextInstruction(p,p) or
  770. (ptaiprop(p.optinfo)^.Regs[supreg].startmod <> oldStartmod);
  771. {$ifdef replaceregdebug}
  772. if assigned(p) then
  773. begin
  774. hp := tai_comment.Create(strpnew(
  775. 'cleared '+std_regname(newreg(R_INTREGISTER,supreg,R_SUBWHOLE))+' till here... '+tostr(l)));
  776. hp.next := p;
  777. hp.previous := p.previous;
  778. p.previous := hp;
  779. if assigned(hp.previous) then
  780. hp.previous.next := hp;
  781. end;
  782. {$endif replaceregdebug}
  783. end;
  784. procedure RestoreRegContentsTo(supreg: tsuperregister; const c: TContent; p, endP: tai);
  785. var
  786. {$ifdef replaceregdebug}
  787. hp: tai;
  788. l: longint;
  789. {$endif replaceregdebug}
  790. dummyregs: tregset;
  791. tmpState: byte;
  792. prevcontenttyp: byte;
  793. memconflict: boolean;
  794. invalsmemwrite: boolean;
  795. begin
  796. {$ifdef replaceregdebug}
  797. l := random(1000);
  798. hp := tai_comment.Create(strpnew(
  799. 'restored '+std_regname(newreg(R_INTREGISTER,supreg,R_SUBWHOLE))+' with data from here... '+tostr(l)));
  800. hp.next := p;
  801. hp.previous := p.previous;
  802. p.previous := hp;
  803. if assigned(hp.previous) then
  804. hp.previous.next := hp;
  805. {$endif replaceregdebug}
  806. { ptaiprop(p.optinfo)^.Regs[reg] := c;}
  807. while (p <> endP) do
  808. begin
  809. ptaiprop(p.optinfo)^.Regs[supreg] := c;
  810. getNextInstruction(p,p);
  811. end;
  812. tmpState := ptaiprop(p.optinfo)^.Regs[supreg].wState;
  813. dummyregs := [supreg];
  814. repeat
  815. prevcontenttyp := ptaiprop(p.optinfo)^.Regs[supreg].typ;
  816. // is this a write to memory that destroys the contents we are restoring?
  817. memconflict := modifiesConflictingMemLocation(p,supreg,ptaiprop(p.optinfo)^.regs,dummyregs,true,invalsmemwrite);
  818. if not memconflict and not invalsmemwrite then
  819. ptaiprop(p.optinfo)^.Regs[supreg] := c;
  820. until invalsmemwrite or
  821. memconflict or
  822. not getNextInstruction(p,p) or
  823. (ptaiprop(p.optinfo)^.Regs[supreg].wState <> tmpState) or
  824. (p.typ = ait_label) or
  825. ((prevcontenttyp <> con_invalid) and
  826. (ptaiprop(p.optinfo)^.Regs[supreg].typ = con_invalid));
  827. if assigned(p) and
  828. ((p.typ = ait_label) or
  829. memconflict or
  830. invalsmemwrite) then
  831. clearRegContentsFrom(supreg,p,p);
  832. {$ifdef replaceregdebug}
  833. if assigned(p) then
  834. begin
  835. hp := tai_comment.Create(strpnew(
  836. 'restored '+std_regname(newreg(R_INTREGISTER,supreg,R_SUBWHOLE))+' till here... '+tostr(l)));
  837. hp.next := p;
  838. hp.previous := p.previous;
  839. p.previous := hp;
  840. if assigned(hp.previous) then
  841. hp.previous.next := hp;
  842. end;
  843. {$endif replaceregdebug}
  844. end;
  845. function NoHardCodedRegs(p: taicpu; orgReg, newReg: tsuperregister): boolean;
  846. var
  847. chCount: byte;
  848. begin
  849. case p.opcode of
  850. A_IMUL: noHardCodedRegs := p.ops <> 1;
  851. A_SHL,A_SHR,A_SHLD,A_SHRD: noHardCodedRegs :=
  852. (p.oper[0]^.typ <> top_reg) or
  853. ((orgReg <> RS_ECX) and (newReg <> RS_ECX));
  854. else
  855. begin
  856. NoHardCodedRegs := true;
  857. with InsProp[p.opcode] do
  858. for chCount := 1 to maxinschanges do
  859. if Ch[chCount] in ([Ch_REAX..Ch_MEDI,Ch_WMemEDI,Ch_All]-[Ch_RESP,Ch_WESP,Ch_RWESP]) then
  860. begin
  861. NoHardCodedRegs := false;
  862. break
  863. end;
  864. end;
  865. end;
  866. end;
  867. function ChangeReg(var Reg: TRegister; newReg, orgReg: tsuperregister): boolean;
  868. begin
  869. changereg := false;
  870. if (reg <> NR_NO) and
  871. (getregtype(reg) = R_INTREGISTER) and
  872. (getsupreg(reg) = newreg) then
  873. begin
  874. changereg := true;
  875. setsupreg(reg,orgreg);
  876. end;
  877. end;
  878. function changeOp(var o: toper; newReg, orgReg: tsuperregister): boolean;
  879. var
  880. tmpresult: boolean;
  881. begin
  882. changeOp := false;
  883. case o.typ of
  884. top_reg: changeOp := changeReg(o.reg,newReg,orgReg);
  885. top_ref:
  886. begin
  887. tmpresult := changeReg(o.ref^.base,newReg,orgReg);
  888. changeop := changeReg(o.ref^.index,newReg,orgReg) or tmpresult;
  889. end;
  890. end;
  891. end;
  892. procedure updateStates(orgReg,newReg: tsuperregister; hp: tai; writeStateToo: boolean);
  893. var
  894. prev: tai;
  895. newOrgRegRState, newOrgRegWState: byte;
  896. begin
  897. if getLastInstruction(hp,prev) then
  898. with ptaiprop(prev.optinfo)^ do
  899. begin
  900. {$ifopt r+}
  901. {$define rangeon}
  902. {$r-}
  903. {$endif}
  904. newOrgRegRState := regs[orgReg].rState +
  905. ptaiprop(hp.optinfo)^.regs[newReg].rState - regs[newReg].rstate;
  906. if writeStateToo then
  907. newOrgRegWState := regs[orgReg].wState +
  908. ptaiprop(hp.optinfo)^.regs[newReg].wState - regs[newReg].wstate;
  909. {$ifdef rangeon}
  910. {$undef rangeon}
  911. {$r+}
  912. {$endif}
  913. end
  914. else
  915. with ptaiprop(hp.optinfo)^.regs[newReg] do
  916. begin
  917. newOrgRegRState := rState;
  918. if writeStateToo then
  919. newOrgRegWState := wState;
  920. end;
  921. with ptaiprop(hp.optinfo)^.regs[orgReg] do
  922. begin
  923. rState := newOrgRegRState;
  924. if writeStateToo then
  925. wState := newOrgRegwState;
  926. end;
  927. end;
  928. function doReplaceReg(hp: taicpu; newReg, orgReg: tsuperregister): boolean;
  929. var
  930. opCount: longint;
  931. tmpResult: boolean;
  932. begin
  933. tmpresult := false;
  934. for opCount := 0 to hp.ops-1 do
  935. tmpResult :=
  936. changeOp(hp.oper[opCount]^,newReg,orgReg) or tmpResult;
  937. doReplaceReg := tmpResult;
  938. end;
  939. function RegSizesOK(oldReg,newReg: tsuperregister; p: taicpu): boolean;
  940. { oldreg and newreg must be 32bit components }
  941. var
  942. opCount: longint;
  943. tmpreg: tsuperregister;
  944. begin
  945. RegSizesOK := true;
  946. { if only one of them is a general purpose register ... }
  947. if (IsGP32reg(oldReg) xor IsGP32Reg(newReg)) then
  948. begin
  949. for opCount := 0 to p.ops-1 do
  950. if (p.oper[opCount]^.typ = top_reg) and
  951. (getsubreg(p.oper[opCount]^.reg) in [R_SUBL,R_SUBH]) then
  952. begin
  953. tmpreg := getsupreg(p.oper[opCount]^.reg);
  954. if (tmpreg = oldreg) or
  955. (tmpreg = newreg) then
  956. begin
  957. RegSizesOK := false;
  958. break
  959. end
  960. end;
  961. end;
  962. end;
  963. function doReplaceReadReg(p: taicpu; newReg,orgReg: tsuperregister): boolean;
  964. var
  965. opCount: byte;
  966. begin
  967. doReplaceReadReg := false;
  968. { handle special case }
  969. case p.opcode of
  970. A_IMUL:
  971. begin
  972. case p.ops of
  973. 1: internalerror(1301001);
  974. 2,3:
  975. begin
  976. if changeOp(p.oper[0]^,newReg,orgReg) then
  977. begin
  978. { updateStates(orgReg,newReg,p,false);}
  979. doReplaceReadReg := true;
  980. end;
  981. if p.ops = 3 then
  982. if changeOp(p.oper[1]^,newReg,orgReg) then
  983. begin
  984. { updateStates(orgReg,newReg,p,false);}
  985. doReplaceReadReg := true;
  986. end;
  987. end;
  988. end;
  989. end;
  990. A_DIV,A_IDIV,A_MUL: internalerror(1301002);
  991. else
  992. begin
  993. for opCount := 0 to p.ops-1 do
  994. if p.oper[opCount]^.typ = top_ref then
  995. if changeOp(p.oper[opCount]^,newReg,orgReg) then
  996. begin
  997. { updateStates(orgReg,newReg,p,false);}
  998. doReplaceReadReg := true;
  999. end;
  1000. for opCount := 1 to maxinschanges do
  1001. case InsProp[p.opcode].Ch[opCount] of
  1002. Ch_ROp1:
  1003. if p.oper[0]^.typ = top_reg then
  1004. if changeReg(p.oper[0]^.reg,newReg,orgReg) then
  1005. begin
  1006. { updateStates(orgReg,newReg,p,false);}
  1007. doReplaceReadReg := true;
  1008. end;
  1009. Ch_ROp2:
  1010. if p.oper[1]^.typ = top_reg then
  1011. if changeReg(p.oper[1]^.reg,newReg,orgReg) then
  1012. begin
  1013. { updateStates(orgReg,newReg,p,false);}
  1014. doReplaceReadReg := true;
  1015. end;
  1016. Ch_ROp3:
  1017. if p.oper[2]^.typ = top_reg then
  1018. if changeReg(p.oper[2]^.reg,newReg,orgReg) then
  1019. begin
  1020. { updateStates(orgReg,newReg,p,false);}
  1021. doReplaceReadReg := true;
  1022. end;
  1023. end;
  1024. end;
  1025. end;
  1026. end;
  1027. procedure updateState(supreg: tsuperregister; p: tai);
  1028. { this procedure updates the read and write states of the instructions }
  1029. { coming after p. It's called when the read/write state of p has been }
  1030. { changed and this change has to be propagated to the following }
  1031. { instructions as well }
  1032. var
  1033. newRState, newWState: byte;
  1034. prevRState, prevWState: byte;
  1035. doRState, doWState: boolean;
  1036. begin
  1037. { get the new read/write states from p }
  1038. with ptaiprop(p.optinfo)^.regs[supreg] do
  1039. begin
  1040. newRState := rState;
  1041. newWState := wState;
  1042. end;
  1043. if not GetNextInstruction(p,p) then
  1044. exit;
  1045. { get the old read/write states from the next instruction, to know }
  1046. { when we can stop updating }
  1047. with ptaiprop(p.optinfo)^.regs[supreg] do
  1048. begin
  1049. prevRState := rState;
  1050. prevWState := wState;
  1051. end;
  1052. { adjust the states if this next instruction reads/writes the register }
  1053. if regReadByInstruction(supreg,p) then
  1054. incState(newRState,1);
  1055. if regModifiedByInstruction(supreg,p) then
  1056. incState(newWState,1);
  1057. { do we still have to update the read and/or write states? }
  1058. doRState := true;
  1059. doWState := true;
  1060. repeat
  1061. { update the states }
  1062. with ptaiprop(p.optinfo)^.regs[supreg] do
  1063. begin
  1064. if doRState then
  1065. rState := newRState;
  1066. if doWState then
  1067. wState := newWState;
  1068. end;
  1069. if not getNextInstruction(p,p) then
  1070. break;
  1071. with ptaiprop(p.optinfo)^.regs[supreg] do
  1072. begin
  1073. { stop updating the read state if it changes }
  1074. doRState :=
  1075. doRState and (rState = prevRState);
  1076. { if, by accident, this changed state is the same as the one }
  1077. { we've been using, change it to a value that's definitely }
  1078. { different from the previous and next state }
  1079. if not doRState and
  1080. (rState = newRState) then
  1081. begin
  1082. incState(newRState,1);
  1083. prevRState := rState;
  1084. doRState := true;
  1085. end;
  1086. { ditto for the write state }
  1087. doWState :=
  1088. doWState and (WState = prevWState);
  1089. if not doWState and
  1090. (wState = newWState) then
  1091. begin
  1092. incState(newWState,1);
  1093. prevWState := wState;
  1094. doWState := true;
  1095. end;
  1096. end;
  1097. { stop when we don't have to update either state anymore }
  1098. until not(doRState or doWState);
  1099. end;
  1100. function storeBack(start, current: tai; orgReg, newReg: tsuperregister): boolean;
  1101. { returns true if p1 contains an instruction that stores the contents }
  1102. { of newReg back to orgReg }
  1103. begin
  1104. storeback := false;
  1105. if (current.typ = ait_instruction) and
  1106. (taicpu(current).opcode = A_MOV) and
  1107. (taicpu(current).oper[0]^.typ = top_reg) and
  1108. (getsupreg(taicpu(current).oper[0]^.reg) = newReg) and
  1109. (taicpu(current).oper[1]^.typ = top_reg) and
  1110. (getsupreg(taicpu(current).oper[1]^.reg) = orgReg) then
  1111. case taicpu(current).opsize of
  1112. S_B:
  1113. storeback := true;
  1114. S_W:
  1115. storeback := taicpu(start).opsize <> S_B;
  1116. S_L:
  1117. storeback := taicpu(start).opsize = S_L;
  1118. else
  1119. internalerror(2003121501);
  1120. end;
  1121. end;
  1122. function ReplaceReg(asml: TAAsmOutput; orgsupreg, newsupreg: tsuperregister; p,
  1123. seqstart: tai; const c: TContent; orgRegCanBeModified: Boolean;
  1124. var returnEndP: tai): Boolean;
  1125. { Tries to replace orgsupreg with newsupreg in all instructions coming after p }
  1126. { until orgsupreg gets loaded with a new value. Returns true if successful, }
  1127. { false otherwise. if successful, the contents of newsupreg are set to c, }
  1128. { which should hold the contents of newsupreg before the current sequence }
  1129. { started }
  1130. { if the function returns true, returnEndP holds the last instruction }
  1131. { where newsupreg was replaced by orgsupreg }
  1132. var
  1133. endP, hp: tai;
  1134. removeLast, sequenceEnd, tmpResult, newRegModified, orgRegRead,
  1135. stateChanged, readStateChanged: Boolean;
  1136. begin
  1137. ReplaceReg := false;
  1138. tmpResult := true;
  1139. sequenceEnd := false;
  1140. newRegModified := false;
  1141. orgRegRead := false;
  1142. removeLast := false;
  1143. endP := p;
  1144. while tmpResult and not sequenceEnd do
  1145. begin
  1146. tmpResult :=
  1147. getNextInstruction(endP,endP) and
  1148. (endp.typ = ait_instruction) and
  1149. not(taicpu(endp).is_jmp);
  1150. if tmpresult and not assigned(endp.optinfo) then
  1151. begin
  1152. { hp := tai_comment.Create(strpnew('next no optinfo'));
  1153. hp.next := endp;
  1154. hp.previous := endp.previous;
  1155. endp.previous := hp;
  1156. if assigned(hp.previous) then
  1157. hp.previous.next := hp;}
  1158. exit;
  1159. end;
  1160. if tmpResult and
  1161. { don't take into account instructions that will be removed }
  1162. not (ptaiprop(endp.optinfo)^.canBeRemoved) then
  1163. begin
  1164. { if the newsupreg gets stored back to the oldReg, we can change }
  1165. { "mov %oldReg,%newReg; <operations on %newReg>; mov %newReg, }
  1166. { %oldReg" to "<operations on %oldReg>" }
  1167. removeLast := storeBack(p,endP, orgsupreg, newsupreg);
  1168. sequenceEnd :=
  1169. { no support for (i)div, mul and imul with hardcoded operands }
  1170. noHardCodedRegs(taicpu(endP),orgsupreg,newsupreg) and
  1171. { if newsupreg gets loaded with a new value, we can stop }
  1172. { replacing newsupreg with oldReg here (possibly keeping }
  1173. { the original contents of oldReg so we still know them }
  1174. { afterwards) }
  1175. (RegLoadedWithNewValue(newsupreg,true,taicpu(endP)) or
  1176. { we can also stop if we reached the end of the use of }
  1177. { newReg's current contents }
  1178. (GetNextInstruction(endp,hp) and
  1179. FindRegDealloc(newsupreg,hp)));
  1180. { to be able to remove the first and last instruction of }
  1181. { movl %reg1, %reg2 }
  1182. { <operations on %reg2> (replacing reg2 with reg1 here) }
  1183. { movl %reg2, %reg1 }
  1184. { %reg2 must not be use afterwards (it can be as the }
  1185. { result of a peepholeoptimization) }
  1186. removeLast := removeLast and sequenceEnd;
  1187. newRegModified :=
  1188. newRegModified or
  1189. (not(regLoadedWithNewValue(newsupreg,true,taicpu(endP))) and
  1190. RegModifiedByInstruction(newsupreg,endP));
  1191. orgRegRead := newRegModified and RegReadByInstruction(orgsupreg,endP);
  1192. sequenceEnd := SequenceEnd and
  1193. (removeLast or
  1194. { since newsupreg will be replaced by orgsupreg, we can't allow that newsupreg }
  1195. { gets modified if orgsupreg is still read afterwards (since after }
  1196. { replacing, this would mean that orgsupreg first gets modified and then }
  1197. { gets read in the assumption it still contains the unmodified value) }
  1198. not(newRegModified and orgRegRead)) (* and
  1199. { since newsupreg will be replaced by orgsupreg, we can't allow that newsupreg }
  1200. { gets modified if orgRegCanBeModified = false }
  1201. { this now gets checked after the loop (JM) }
  1202. (orgRegCanBeModified or not(newRegModified)) *);
  1203. tmpResult :=
  1204. not(removeLast) and
  1205. not(newRegModified and orgRegRead) and
  1206. (* (orgRegCanBeModified or not(newRegModified)) and *)
  1207. (* already checked at the top
  1208. (endp.typ = ait_instruction) and *)
  1209. NoHardCodedRegs(taicpu(endP),orgsupreg,newsupreg) and
  1210. RegSizesOk(orgsupreg,newsupreg,taicpu(endP)) and
  1211. not RegModifiedByInstruction(orgsupreg,endP);
  1212. end;
  1213. end;
  1214. sequenceEnd := sequenceEnd and
  1215. (removeLast or
  1216. (orgRegCanBeModified or not(newRegModified))) and
  1217. (not(assigned(endp)) or
  1218. not(endp.typ = ait_instruction) or
  1219. (noHardCodedRegs(taicpu(endP),orgsupreg,newsupreg) and
  1220. RegSizesOk(orgsupreg,newsupreg,taicpu(endP)) and
  1221. not(newRegModified and
  1222. (orgsupreg in ptaiprop(endp.optinfo)^.usedRegs) and
  1223. not(RegLoadedWithNewValue(orgsupreg,true,taicpu(endP))))));
  1224. if SequenceEnd then
  1225. begin
  1226. {$ifdef replaceregdebug}
  1227. hp := tai_comment.Create(strpnew(
  1228. 'replacing '+std_regname(newreg(R_INTREGISTER,newsupreg,R_SUBWHOLE))+' with '+std_regname(newreg(R_INTREGISTER,orgsupreg,R_SUBWHOLE))+
  1229. ' from here...'));
  1230. hp.next := p;
  1231. hp.previous := p.previous;
  1232. p.previous := hp;
  1233. if assigned(hp.previous) then
  1234. hp.previous.next := hp;
  1235. hp := tai_comment.Create(strpnew(
  1236. 'replaced '+std_regname(newreg(R_INTREGISTER,newsupreg,R_SUBWHOLE))+' with '+std_regname(newreg(R_INTREGISTER,orgsupreg,R_SUBWHOLE))+
  1237. ' till here'));
  1238. hp.next := endp.next;
  1239. hp.previous := endp;
  1240. endp.next := hp;
  1241. if assigned(hp.next) then
  1242. hp.next.previous := hp;
  1243. {$endif replaceregdebug}
  1244. replaceReg := true;
  1245. returnEndP := endP;
  1246. getNextInstruction(p,hp);
  1247. stateChanged := false;
  1248. while hp <> endP do
  1249. begin
  1250. if {not(ptaiprop(hp.optinfo)^.canBeRemoved) and }
  1251. (hp.typ = ait_instruction) then
  1252. stateChanged :=
  1253. doReplaceReg(taicpu(hp),newsupreg,orgsupreg) or stateChanged;
  1254. if stateChanged then
  1255. updateStates(orgsupreg,newsupreg,hp,true);
  1256. getNextInstruction(hp,hp)
  1257. end;
  1258. if assigned(endp) and (endp.typ = ait_instruction) then
  1259. readStateChanged :=
  1260. doReplaceReadReg(taicpu(endP),newsupreg,orgsupreg);
  1261. if stateChanged or readStateChanged then
  1262. updateStates(orgsupreg,newsupreg,endP,stateChanged);
  1263. if stateChanged or readStateChanged then
  1264. updateState(orgsupreg,endP);
  1265. { We replaced newreg with oldreg between p and endp, so restore the contents }
  1266. { of newreg there with its contents from before the sequence. }
  1267. if removeLast or
  1268. RegLoadedWithNewValue(newsupreg,true,endP) then
  1269. GetLastInstruction(endP,hp)
  1270. else hp := endP;
  1271. RestoreRegContentsTo(newsupreg,c,seqstart,hp);
  1272. { Ot is possible that the new register was modified (e.g. an add/sub), so if }
  1273. { it was replaced by oldreg in that instruction, oldreg's contents have been }
  1274. { changed. To take this into account, we simply set the contents of orgsupreg }
  1275. { to "unknown" after this sequence }
  1276. if newRegModified then
  1277. ClearRegContentsFrom(orgsupreg,p,hp);
  1278. if removeLast then
  1279. ptaiprop(endp.optinfo)^.canBeRemoved := true;
  1280. allocRegBetween(asml,newreg(R_INTREGISTER,orgsupreg,R_SUBWHOLE),p,endP);
  1281. end
  1282. {$ifdef replaceregdebug}
  1283. else
  1284. begin
  1285. hp := tai_comment.Create(strpnew(
  1286. 'replacing '+std_regname(newreg(R_INTREGISTER,newsupreg,R_SUBWHOLE))+' with '+std_regname(newreg(R_INTREGISTER,orgsupreg,R_SUBWHOLE))+
  1287. ' from here...'));
  1288. hp.previous := p.previous;
  1289. hp.next := p;
  1290. p.previous := hp;
  1291. if assigned(hp.previous) then
  1292. hp.previous.next := hp;
  1293. hp := tai_comment.Create(strpnew(
  1294. 'replacing '+std_regname(newreg(R_INTREGISTER,newsupreg,R_SUBWHOLE))+' with '+std_regname(newreg(R_INTREGISTER,orgsupreg,R_SUBWHOLE))+
  1295. ' failed here'));
  1296. hp.next := endp.next;
  1297. hp.previous := endp;
  1298. endp.next := hp;
  1299. if assigned(hp.next) then
  1300. hp.next.previous := hp;
  1301. end;
  1302. {$endif replaceregdebug}
  1303. end;
  1304. function FindRegWithConst(p: tai; size: topsize; l: aint; var Res: TRegister): Boolean;
  1305. {Finds a register which contains the constant l}
  1306. var
  1307. Counter: tsuperregister;
  1308. {$ifdef testing}
  1309. hp: tai;
  1310. {$endif testing}
  1311. begin
  1312. Result:=false;
  1313. Counter := RS_EAX;
  1314. repeat
  1315. {$ifdef testing}
  1316. if (ptaiprop(p.optinfo)^.regs[counter].typ in [con_const,con_noRemoveConst]) then
  1317. begin
  1318. hp := tai_comment.Create(strpnew(
  1319. 'checking const load of '+tostr(l)+' here...'));
  1320. hp.next := ptaiprop(p.optinfo)^.Regs[Counter].StartMod;
  1321. hp.previous := ptaiprop(p.optinfo)^.Regs[Counter].StartMod^.previous;
  1322. ptaiprop(p.optinfo)^.Regs[Counter].StartMod^.previous := hp;
  1323. if assigned(hp.previous) then
  1324. hp.previous.next := hp;
  1325. end;
  1326. {$endif testing}
  1327. if (ptaiprop(p.optinfo)^.regs[counter].typ in [con_const,con_noRemoveConst]) and
  1328. (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).opsize = size) and
  1329. (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[0]^.typ = top_const) and
  1330. (taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[0]^.val = l) then
  1331. begin
  1332. res:=taicpu(ptaiprop(p.optinfo)^.Regs[Counter].StartMod).oper[1]^.reg;
  1333. result:=true;
  1334. exit;
  1335. end;
  1336. inc(counter);
  1337. until (Counter > RS_EDI);
  1338. end;
  1339. procedure removePrevNotUsedLoad(p: tai; supreg: tsuperregister; check: boolean);
  1340. { if check = true, it means the procedure has to check whether it isn't }
  1341. { possible that the contents are still used after p (used when removing }
  1342. { instructions because of a "call"), otherwise this is not necessary }
  1343. { (e.g. when you have a "mov 8(%ebp),%eax", you can be sure the previous }
  1344. { value of %eax isn't used anymore later on) }
  1345. var
  1346. hp1: tai;
  1347. begin
  1348. if getLastInstruction(p,hp1) then
  1349. with ptaiprop(hp1.optinfo)^.regs[supreg] do
  1350. if (typ in [con_ref,con_invalid,con_const]) and
  1351. (nrofMods = 1) and
  1352. (rState = ptaiprop(startmod.optinfo)^.regs[supreg].rState) and
  1353. (not(check) or
  1354. (not(regInInstruction(supreg,p)) and
  1355. (not(supreg in ptaiprop(hp1.optinfo)^.usedRegs) or
  1356. findRegDealloc(supreg,p)))) then
  1357. ptaiprop(startMod.optinfo)^.canBeRemoved := true;
  1358. end;
  1359. {$ifdef notused}
  1360. function is_mov_for_div(p: taicpu): boolean;
  1361. begin
  1362. is_mov_for_div :=
  1363. (p.opcode = A_MOV) and
  1364. (p.oper[0]^.typ = top_const) and
  1365. (p.oper[1]^.typ = top_reg) and
  1366. (p.oper[1]^.reg = RS_EDX) and
  1367. getNextInstruction(p,p) and
  1368. (p.typ = ait_instruction) and
  1369. ((p.opcode = A_DIV) or
  1370. (p.opcode = A_IDIV));
  1371. end;
  1372. {$endif notused}
  1373. function memtoreg(t: taicpu; const ref: treference; var startp: tai): tregister;
  1374. var
  1375. hp: tai;
  1376. p: ptaiprop;
  1377. regcounter: tsuperregister;
  1378. optimizable: boolean;
  1379. begin
  1380. if not getlastinstruction(t,hp) or
  1381. not issimplememloc(ref) then
  1382. begin
  1383. memtoreg := NR_NO;
  1384. exit;
  1385. end;
  1386. p := ptaiprop(hp.optinfo);
  1387. optimizable := false;
  1388. for regcounter := RS_EAX to RS_EDI do
  1389. begin
  1390. if (assigned(p^.regs[regcounter].memwrite) and
  1391. refsequal(ref,p^.regs[regcounter].memwrite.oper[1]^.ref^)) then
  1392. begin
  1393. optimizable := true;
  1394. hp := p^.regs[regcounter].memwrite;
  1395. end
  1396. else if ((p^.regs[regcounter].typ in [CON_REF,CON_NOREMOVEREF]) and
  1397. (p^.regs[regcounter].nrofmods = 1) and
  1398. ((taicpu(p^.regs[regcounter].startmod).opcode = A_MOV) or
  1399. (taicpu(p^.regs[regcounter].startmod).opcode = A_MOVZX) or
  1400. (taicpu(p^.regs[regcounter].startmod).opcode = A_MOVSX)) and
  1401. (taicpu(p^.regs[regcounter].startmod).oper[0]^.typ = top_ref) and
  1402. refsequal(ref,taicpu(p^.regs[regcounter].startmod).oper[0]^.ref^)) then
  1403. begin
  1404. optimizable := true;
  1405. hp := p^.regs[regcounter].startmod;
  1406. end;
  1407. if optimizable then
  1408. if ((t.opsize <> S_B) or
  1409. not(regcounter in [RS_ESI,RS_EDI])) and
  1410. sizescompatible(taicpu(hp).opsize,t.opsize) then
  1411. begin
  1412. case t.opsize of
  1413. S_B:
  1414. begin
  1415. memtoreg := newreg(R_INTREGISTER,regcounter,R_SUBL)
  1416. end;
  1417. S_W,S_BW:
  1418. begin
  1419. memtoreg := newreg(R_INTREGISTER,regcounter,R_SUBW);
  1420. if (t.opsize = S_BW) then
  1421. begin
  1422. t.opcode := A_MOV;
  1423. t.opsize := S_W;
  1424. end;
  1425. end;
  1426. S_L,S_BL,S_WL:
  1427. begin
  1428. memtoreg := newreg(R_INTREGISTER,regcounter,R_SUBWHOLE);
  1429. if (t.opsize <> S_L) then
  1430. begin
  1431. t.opcode := A_MOV;
  1432. t.opsize := S_L;
  1433. end;
  1434. end;
  1435. end;
  1436. startp := hp;
  1437. exit;
  1438. end;
  1439. end;
  1440. memtoreg := NR_NO;
  1441. end;
  1442. procedure removeLocalStores(const t1: tai);
  1443. {var
  1444. p: tai;
  1445. regcount: tregister; }
  1446. begin
  1447. {
  1448. for regcount := LoGPReg to HiGPReg do
  1449. if assigned(pTaiProp(t1.optinfo)^.regs[regcount].memwrite) and
  1450. (taicpu(pTaiProp(t1.optinfo)^.regs[regcount].memwrite).oper[1]^.ref^.base
  1451. = current_procinfo.framepointer) then
  1452. begin
  1453. pTaiProp(pTaiProp(t1.optinfo)^.regs[regcount].memwrite.optinfo)^.canberemoved := true;
  1454. clearmemwrites(pTaiProp(t1.optinfo)^.regs[regcount].memwrite,regcount);
  1455. end;
  1456. }
  1457. end;
  1458. procedure loadcseregs(asml: taasmoutput; const reginfo: toptreginfo; curseqend, prevseqstart, curseqstart, curprev: tai; cnt: longint);
  1459. var
  1460. regsloaded: tregset;
  1461. regloads: array[RS_EAX..RS_EDI] of tai;
  1462. regcounter: tsuperregister;
  1463. hp, hp2: tai;
  1464. insertpos, prevseq_next: tai;
  1465. i: longint;
  1466. begin
  1467. regsloaded := [];
  1468. fillchar(regloads,sizeof(regloads),0);
  1469. getnextinstruction(prevseqstart,prevseq_next);
  1470. for regcounter := RS_EAX To RS_EDI do
  1471. if (reginfo.new2oldreg[regcounter] <> RS_INVALID) Then
  1472. begin
  1473. include(regsloaded,regcounter);
  1474. AllocRegBetween(asml,newreg(R_INTREGISTER,reginfo.new2oldreg[regcounter],R_SUBWHOLE),
  1475. ptaiprop(prevseqstart.optinfo)^.Regs[reginfo.new2oldreg[regcounter]].StartMod,curseqstart);
  1476. if curprev <> prevseqstart then
  1477. begin
  1478. if assigned(reginfo.lastReload[regCounter]) then
  1479. getLastInstruction(reginfo.lastReload[regCounter],hp)
  1480. else if assigned(reginfo.lastReload[reginfo.new2oldreg[regCounter]]) then
  1481. getLastInstruction(reginfo.lastReload[reginfo.new2OldReg[regCounter]],hp)
  1482. else
  1483. hp := curprev;
  1484. clearRegContentsFrom(regCounter,prevSeq_next,hp);
  1485. getnextInstruction(hp,hp);
  1486. allocRegBetween(asml,newreg(R_INTREGISTER,regCounter,R_SUBWHOLE),prevseqstart,hp);
  1487. end;
  1488. if not(regcounter in reginfo.RegsLoadedforRef) and
  1489. {old reg new reg}
  1490. (reginfo.new2oldreg[regcounter] <> regcounter) then
  1491. begin
  1492. getLastInstruction(curseqend,hp);
  1493. if (curprev <> prevseqstart) or
  1494. {not(regCounter in rg.usableregsint + [RS_EDI,RS_ESI]) or}
  1495. not(regCounter in [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_EDI,RS_ESI]) or
  1496. not ReplaceReg(asml,reginfo.new2oldreg[regcounter],
  1497. regCounter,hp,curseqstart,
  1498. ptaiprop(prevseqstart.optinfo)^.Regs[regCounter],true,hp2) then
  1499. begin
  1500. if not(reginfo.new2oldreg[regcounter] in regsloaded) or
  1501. { happens if the register has been replaced }
  1502. not(assigned(regloads[reginfo.new2oldreg[regcounter]])) then
  1503. insertpos := prevseq_next
  1504. else
  1505. begin
  1506. {$warning add cycle detection for register loads and use xchg if necessary}
  1507. insertpos := regloads[reginfo.new2oldreg[regcounter]];
  1508. end;
  1509. hp := Tai_Marker.Create(NoPropInfoStart);
  1510. InsertLLItem(asml, insertpos.previous,insertpos, hp);
  1511. hp2 := taicpu.Op_Reg_Reg(A_MOV, S_L,
  1512. {old reg new reg}
  1513. newreg(R_INTREGISTER,reginfo.new2oldreg[regcounter],R_SUBWHOLE), newreg(R_INTREGISTER,regcounter,R_SUBWHOLE));
  1514. regloads[regcounter] := hp2;
  1515. new(ptaiprop(hp2.optinfo));
  1516. ptaiprop(hp2.optinfo)^ := ptaiprop(insertpos.optinfo)^;
  1517. ptaiprop(hp2.optinfo)^.canBeRemoved := false;
  1518. InsertLLItem(asml, insertpos.previous, insertpos, hp2);
  1519. hp := Tai_Marker.Create(NoPropInfoEnd);
  1520. InsertLLItem(asml, insertpos.previous, insertpos, hp);
  1521. { adjusts states in previous instruction so that it will }
  1522. { definitely be different from the previous or next state }
  1523. incstate(ptaiprop(hp2.optinfo)^.
  1524. regs[reginfo.new2oldreg[regcounter]].rstate,20);
  1525. incstate(ptaiprop(hp2.optinfo)^.
  1526. regs[regCounter].wstate,20);
  1527. updateState(reginfo.new2oldreg[regcounter],hp2);
  1528. updateState(regcounter,hp2);
  1529. end
  1530. else
  1531. begin
  1532. // replace the new register with the old register in the
  1533. // sequence itself as well so later comparisons get the
  1534. // correct knowledge about which registers are used
  1535. hp2 := curseqstart;
  1536. // curseqend = instruction following last instruction of this
  1537. // sequence
  1538. while hp2 <> curseqend do
  1539. begin
  1540. doreplacereg(taicpu(hp2),regcounter,reginfo.new2oldreg[regcounter]);
  1541. getnextinstruction(hp2,hp2);
  1542. end;
  1543. end;
  1544. end
  1545. else
  1546. { imagine the following code: }
  1547. { normal wrong optimized }
  1548. { movl 8(%ebp), %eax movl 8(%ebp), %eax }
  1549. { movl (%eax), %eax movl (%eax), %eax }
  1550. { cmpl 8(%ebp), %eax cmpl 8(%ebp), %eax }
  1551. { jne l1 jne l1 }
  1552. { movl 8(%ebp), %eax }
  1553. { movl (%eax), %edi movl %eax, %edi }
  1554. { movl %edi, -4(%ebp) movl %edi, -4(%ebp) }
  1555. { movl 8(%ebp), %eax }
  1556. { pushl 70(%eax) pushl 70(%eax) }
  1557. { }
  1558. { The error is that at the moment that the last instruction is executed, }
  1559. { %eax doesn't contain 8(%ebp) anymore. Solution: the contents of }
  1560. { registers that are completely removed from a sequence (= registers in }
  1561. { RegLoadedforRef), have to be changed to their contents from before the }
  1562. { sequence. }
  1563. { if regcounter in reginfo.RegsLoadedforRef then }
  1564. begin
  1565. hp := curseqstart;
  1566. { cnt still holds the number of instructions }
  1567. { of the sequence, so go to the end of it }
  1568. for i := 1 to pred(cnt) do
  1569. getNextInstruction(hp,hp);
  1570. { curprev = instruction prior to start of sequence }
  1571. restoreRegContentsTo(regCounter,
  1572. ptaiprop(curprev.optinfo)^.Regs[regcounter],
  1573. curseqstart,hp);
  1574. end;
  1575. end;
  1576. end;
  1577. procedure replaceoperandwithreg(asml: taasmoutput; p: tai; opnr: byte; reg: tregister);
  1578. var
  1579. hp: tai;
  1580. begin
  1581. { new instruction -> it's info block is not in the big one allocated at the start }
  1582. hp := Tai_Marker.Create(NoPropInfoStart);
  1583. InsertLLItem(asml, p.previous,p, hp);
  1584. { duplicate the original instruction and replace it's designated operant with the register }
  1585. hp := tai(p.getcopy);
  1586. taicpu(hp).loadreg(opnr,reg);
  1587. { add optimizer state info }
  1588. new(ptaiprop(hp.optinfo));
  1589. ptaiprop(hp.optinfo)^ := ptaiprop(p.optinfo)^;
  1590. { new instruction can not be removed }
  1591. ptaiprop(hp.optinfo)^.canBeRemoved := false;
  1592. { but the old one can }
  1593. ptaiprop(p.optinfo)^.canBeRemoved := true;
  1594. { insert end marker }
  1595. InsertLLItem(asml, p.previous, p, hp);
  1596. hp := Tai_Marker.Create(NoPropInfoEnd);
  1597. InsertLLItem(asml, p.previous, p, hp);
  1598. end;
  1599. procedure doCSE(asml: TAAsmOutput; First, Last: tai; findPrevSeqs, doSubOpts: boolean);
  1600. {marks the instructions that can be removed by RemoveInstructs. They're not
  1601. removed immediately because sometimes an instruction needs to be checked in
  1602. two different sequences}
  1603. var cnt, cnt2, {cnt3,} orgNrofMods: longint;
  1604. p, hp1, hp2, prevSeq: tai;
  1605. hp3, hp4: tai;
  1606. hp5 : tai;
  1607. reginfo: toptreginfo;
  1608. memreg: tregister;
  1609. regcounter: tsuperregister;
  1610. begin
  1611. p := First;
  1612. SkipHead(p);
  1613. while (p <> Last) do
  1614. begin
  1615. case p.typ of
  1616. ait_align:
  1617. if not(tai_align(p).use_op) then
  1618. SetAlignReg(p);
  1619. ait_instruction:
  1620. begin
  1621. case taicpu(p).opcode of
  1622. {
  1623. Does not work anymore with register calling because the registers are
  1624. released before the call
  1625. A_CALL:
  1626. for regCounter := RS_EAX to RS_EBX do
  1627. removePrevNotUsedLoad(p,regCounter,true);
  1628. }
  1629. A_CLD: if GetLastInstruction(p, hp1) and
  1630. (ptaiprop(hp1.optinfo)^.DirFlag = F_NotSet) then
  1631. ptaiprop(tai(p).optinfo)^.CanBeRemoved := True;
  1632. A_LEA, A_MOV, A_MOVZX, A_MOVSX:
  1633. begin
  1634. hp2 := p;
  1635. case taicpu(p).oper[0]^.typ of
  1636. top_ref, top_reg:
  1637. if (taicpu(p).oper[1]^.typ = top_reg) then
  1638. begin
  1639. With ptaiprop(p.optinfo)^.Regs[getsupreg(taicpu(p).oper[1]^.reg)] do
  1640. begin
  1641. if (startmod = p) then
  1642. orgNrofMods := nrofMods
  1643. else
  1644. orgNrofMods := 0;
  1645. if (p = StartMod) and
  1646. GetLastInstruction (p, hp1) and
  1647. not(hp1.typ in [ait_marker,ait_label]) then
  1648. {so we don't try to check a sequence when p is the first instruction of the block}
  1649. begin
  1650. {$ifdef csdebug}
  1651. hp5 := tai_comment.Create(strpnew(
  1652. 'cse checking '+std_regname(taicpu(p).oper[1]^.reg)));
  1653. insertLLItem(asml,p,p.next,hp5);
  1654. {$endif csdebug}
  1655. if CheckSequence(p,prevSeq,getsupreg(taicpu(p).oper[1]^.reg), Cnt, reginfo, findPrevSeqs) and
  1656. (Cnt > 0) then
  1657. begin
  1658. (*
  1659. hp1 := nil;
  1660. { although it's perfectly ok to remove an instruction which doesn't contain }
  1661. { the register that we've just checked (CheckSequence takes care of that), }
  1662. { the sequence containing this other register should also be completely }
  1663. { checked and removed, otherwise we may get situations like this: }
  1664. { }
  1665. { movl 12(%ebp), %edx movl 12(%ebp), %edx }
  1666. { movl 16(%ebp), %eax movl 16(%ebp), %eax }
  1667. { movl 8(%edx), %edx movl 8(%edx), %edx }
  1668. { movl (%eax), eax movl (%eax), eax }
  1669. { cmpl %eax, %edx cmpl %eax, %edx }
  1670. { jnz l123 getting converted to jnz l123 }
  1671. { movl 12(%ebp), %edx movl 4(%eax), eax }
  1672. { movl 16(%ebp), %eax }
  1673. { movl 8(%edx), %edx }
  1674. { movl 4(%eax), eax }
  1675. *)
  1676. { not anymore: if the start of a new sequence is found while checking (e.g. }
  1677. { above that of eax while checking edx, this new sequence is automatically }
  1678. { also checked }
  1679. Cnt2 := 1;
  1680. while Cnt2 <= Cnt do
  1681. begin
  1682. {$ifndef noremove}
  1683. ptaiprop(p.optinfo)^.CanBeRemoved := True
  1684. {$endif noremove}
  1685. ; inc(Cnt2);
  1686. GetNextInstruction(p, p);
  1687. end;
  1688. {hp4 is used to get the contents of the registers before the sequence}
  1689. GetLastInstruction(hp2, hp4);
  1690. {$IfDef CSDebug}
  1691. for regcounter := RS_EAX To RS_EDI do
  1692. if (regcounter in reginfo.RegsLoadedforRef) then
  1693. begin
  1694. hp5 := tai_comment.Create(strpnew('New: '+std_regname(newreg(R_INTREGISTER,regcounter,R_SUBNONE))+', Old: '+
  1695. std_regname(newreg(R_INTREGISTER,reginfo.new2oldreg[regcounter],R_SUBNONE))));
  1696. InsertLLItem(asml, tai(hp2.previous), hp2, hp5);
  1697. end;
  1698. {$EndIf CSDebug}
  1699. { if some registers were different in the old and the new sequence, move }
  1700. { the contents of those old registers to the new ones }
  1701. loadcseregs(asml,reginfo,p,prevseq,hp2,hp4,cnt);
  1702. continue;
  1703. end
  1704. end;
  1705. end;
  1706. { try to replace the new reg with the old reg }
  1707. if not(ptaiprop(p.optinfo)^.canBeRemoved) then
  1708. if (taicpu(p).oper[0]^.typ = top_reg) and
  1709. (taicpu(p).oper[1]^.typ = top_reg) and
  1710. { only remove if we're not storing something in a regvar }
  1711. (getsupreg(taicpu(p).oper[1]^.reg) in [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESI,RS_EDI]) and
  1712. { (taicpu(p).oper[1]^.reg in (rg.usableregsint+[RS_EDI])) and}
  1713. (taicpu(p).opcode = A_MOV) and
  1714. getLastInstruction(p,hp4) and
  1715. { we only have to start replacing from the instruction after the mov, }
  1716. { but replacereg only starts with getnextinstruction(p,p) }
  1717. replaceReg(asml,getsupreg(taicpu(p).oper[0]^.reg),
  1718. getsupreg(taicpu(p).oper[1]^.reg),p,p,
  1719. ptaiprop(hp4.optinfo)^.regs[getsupreg(taicpu(p).oper[1]^.reg)],false,hp1) then
  1720. begin
  1721. ptaiprop(p.optinfo)^.canBeRemoved := true;
  1722. allocRegBetween(asml,taicpu(p).oper[0]^.reg,
  1723. pTaiProp(p.optinfo)^.regs[getsupreg(taicpu(p).oper[0]^.reg)].startMod,hp1);
  1724. end
  1725. else
  1726. begin
  1727. if (taicpu(p).oper[1]^.typ = top_reg) and
  1728. not regInOp(getsupreg(taicpu(p).oper[1]^.reg),taicpu(p).oper[0]^) then
  1729. removePrevNotUsedLoad(p,getsupreg(taicpu(p).oper[1]^.reg),false);
  1730. if doSubOpts and
  1731. (taicpu(p).opcode <> A_LEA) and
  1732. (taicpu(p).oper[0]^.typ = top_ref) then
  1733. begin
  1734. memreg :=
  1735. memtoreg(taicpu(p),
  1736. taicpu(p).oper[0]^.ref^,hp5);
  1737. if memreg <> NR_NO then
  1738. if (taicpu(p).opcode = A_MOV) and
  1739. (taicpu(p).oper[1]^.typ = top_reg) and
  1740. (taicpu(p).oper[1]^.reg = memreg) then
  1741. begin
  1742. pTaiProp(p.optinfo)^.canberemoved := true;
  1743. allocregbetween(asml,memreg,hp5,p);
  1744. end
  1745. else
  1746. begin
  1747. replaceoperandwithreg(asml,p,0,memreg);
  1748. allocregbetween(asml,memreg,hp5,p);
  1749. regcounter := getsupreg(memreg);
  1750. incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
  1751. updatestate(regcounter,p);
  1752. end;
  1753. end;
  1754. end;
  1755. { at first, only try optimizations of large blocks, because doing }
  1756. { doing smaller ones may prevent bigger ones from completing in }
  1757. { in the next pass }
  1758. if not doSubOpts and (orgNrofMods <> 0) then
  1759. begin
  1760. p := hp2;
  1761. for cnt := 1 to pred(orgNrofMods) do
  1762. getNextInstruction(p,p);
  1763. end;
  1764. end;
  1765. top_Const:
  1766. begin
  1767. case taicpu(p).oper[1]^.typ of
  1768. Top_Reg:
  1769. begin
  1770. regCounter := getsupreg(taicpu(p).oper[1]^.reg);
  1771. if GetLastInstruction(p, hp1) then
  1772. With ptaiprop(hp1.optinfo)^.Regs[regCounter] do
  1773. if (typ in [con_const,con_noRemoveConst]) and
  1774. (taicpu(startMod).opsize >= taicpu(p).opsize) and
  1775. opsequal(taicpu(StartMod).oper[0]^,taicpu(p).oper[0]^) then
  1776. begin
  1777. ptaiprop(p.optinfo)^.CanBeRemoved := True;
  1778. allocRegBetween(asml,taicpu(p).oper[1]^.reg,startMod,p);
  1779. end
  1780. else
  1781. removePrevNotUsedLoad(p,getsupreg(taicpu(p).oper[1]^.reg),false);
  1782. end;
  1783. Top_Ref:
  1784. if (taicpu(p).oper[0]^.typ = top_const) and
  1785. getLastInstruction(p,hp1) and
  1786. findRegWithConst(hp1,taicpu(p).opsize,taicpu(p).oper[0]^.val,memreg) then
  1787. begin
  1788. taicpu(p).loadreg(0,memreg);
  1789. allocRegBetween(asml,memreg,
  1790. ptaiprop(hp1.optinfo)^.regs[getsupreg(memreg)].startMod,p);
  1791. end;
  1792. end;
  1793. end;
  1794. end;
  1795. end;
  1796. A_LEAVE:
  1797. begin
  1798. if getlastinstruction(p,hp1) then
  1799. removeLocalStores(hp1);
  1800. end;
  1801. A_STD: if GetLastInstruction(p, hp1) and
  1802. (ptaiprop(hp1.optinfo)^.DirFlag = F_Set) then
  1803. ptaiprop(tai(p).optinfo)^.CanBeRemoved := True;
  1804. else
  1805. begin
  1806. for cnt := 1 to maxinschanges do
  1807. begin
  1808. case InsProp[taicpu(p).opcode].Ch[cnt] of
  1809. Ch_ROp1:
  1810. if (taicpu(p).oper[0]^.typ = top_ref) and
  1811. ((taicpu(p).opcode < A_F2XM1) or
  1812. ((taicpu(p).opcode > A_IN) and
  1813. (taicpu(p).opcode < A_OUT)) or
  1814. (taicpu(p).opcode = A_PUSH) or
  1815. ((taicpu(p).opcode >= A_RCL) and
  1816. (taicpu(p).opcode <= A_XOR))) then
  1817. begin
  1818. memreg :=
  1819. memtoreg(taicpu(p),
  1820. taicpu(p).oper[0]^.ref^,hp5);
  1821. if memreg <> NR_NO then
  1822. begin
  1823. replaceoperandwithreg(asml,p,0,memreg);
  1824. allocregbetween(asml,memreg,hp5,p);
  1825. regcounter := getsupreg(memreg);
  1826. incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
  1827. updatestate(regcounter,p);
  1828. end;
  1829. end;
  1830. Ch_MOp1:
  1831. if not(CS_LittleSize in aktglobalswitches) and
  1832. (taicpu(p).oper[0]^.typ = top_ref) then
  1833. begin
  1834. memreg :=
  1835. memtoreg(taicpu(p),
  1836. taicpu(p).oper[0]^.ref^,hp5);
  1837. if (memreg <> NR_NO) and
  1838. (not getNextInstruction(p,hp1) or
  1839. (RegLoadedWithNewValue(getsupreg(memreg),false,hp1) or
  1840. FindRegDealloc(getsupreg(memreg),hp1))) then
  1841. begin
  1842. hp1 := Tai_Marker.Create(NoPropInfoEnd);
  1843. insertllitem(asml,p,p.next,hp1);
  1844. hp1 := taicpu.op_reg_ref(A_MOV,reg2opsize(memreg),
  1845. memreg,taicpu(p).oper[0]^.ref^);
  1846. new(ptaiprop(hp1.optinfo));
  1847. pTaiProp(hp1.optinfo)^ := pTaiProp(p.optinfo)^;
  1848. insertllitem(asml,p,p.next,hp1);
  1849. regcounter := getsupreg(memreg);
  1850. incstate(pTaiProp(hp1.optinfo)^.regs[regcounter].rstate,1);
  1851. updatestate(regcounter,hp1);
  1852. hp1 := Tai_Marker.Create(NoPropInfoStart);
  1853. insertllitem(asml,p,p.next,hp1);
  1854. replaceoperandwithreg(asml,p,0,memreg);
  1855. allocregbetween(asml,memreg,hp5,
  1856. tai(p.next.next));
  1857. ClearRegContentsFrom(regcounter,hp5,p);
  1858. end;
  1859. end;
  1860. Ch_ROp2:
  1861. if ((taicpu(p).opcode = A_CMP) or
  1862. (taicpu(p).opcode = A_TEST)) and
  1863. (taicpu(p).oper[1]^.typ = top_ref) then
  1864. begin
  1865. memreg :=
  1866. memtoreg(taicpu(p),
  1867. taicpu(p).oper[1]^.ref^,hp5);
  1868. if memreg <> NR_NO then
  1869. begin
  1870. replaceoperandwithreg(asml,p,1,memreg);
  1871. allocregbetween(asml,memreg,hp5,p);
  1872. regcounter := getsupreg(memreg);
  1873. incstate(pTaiProp(p.optinfo)^.regs[regcounter].rstate,1);
  1874. updatestate(regcounter,p);
  1875. end;
  1876. end;
  1877. Ch_MOp2:
  1878. if not(cs_littlesize in aktglobalswitches) and
  1879. (taicpu(p).oper[1]^.typ = top_ref) and
  1880. ((taicpu(p).opcode < A_BT) or
  1881. ((taicpu(p).opcode > A_IN) and
  1882. (taicpu(p).opcode < A_OUT)) or
  1883. (taicpu(p).opcode = A_PUSH) or
  1884. ((taicpu(p).opcode >= A_RCL) and
  1885. (taicpu(p).opcode <= A_XOR))) then
  1886. begin
  1887. memreg :=
  1888. memtoreg(taicpu(p),
  1889. taicpu(p).oper[1]^.ref^,hp5);
  1890. if (memreg <> NR_NO) and
  1891. (not getNextInstruction(p,hp1) or
  1892. (RegLoadedWithNewValue(getsupreg(memreg),false,hp1) or
  1893. FindRegDealloc(getsupreg(memreg),hp1))) then
  1894. begin
  1895. hp1 := Tai_Marker.Create(NoPropInfoEnd);
  1896. insertllitem(asml,p,p.next,hp1);
  1897. hp1 := taicpu.op_reg_ref(A_MOV,reg2opsize(memreg),
  1898. memreg,taicpu(p).oper[1]^.ref^);
  1899. new(ptaiprop(hp1.optinfo));
  1900. pTaiProp(hp1.optinfo)^ := pTaiProp(p.optinfo)^;
  1901. insertllitem(asml,p,p.next,hp1);
  1902. regcounter := getsupreg(memreg);
  1903. incstate(pTaiProp(hp1.optinfo)^.regs[regcounter].rstate,1);
  1904. updatestate(regcounter,hp1);
  1905. hp1 := Tai_Marker.Create(NoPropInfoStart);
  1906. insertllitem(asml,p,p.next,hp1);
  1907. replaceoperandwithreg(asml,p,1,memreg);
  1908. allocregbetween(asml,memreg,hp5,
  1909. tai(p.next.next));
  1910. ClearRegContentsFrom(regcounter,hp5,p);
  1911. end;
  1912. end;
  1913. end;
  1914. end;
  1915. end;
  1916. end
  1917. end;
  1918. end;
  1919. GetNextInstruction(p, p);
  1920. end;
  1921. end;
  1922. function removeInstructs(asml: TAAsmoutput; first, last: tai): boolean;
  1923. { Removes the marked instructions and disposes the PTaiProps of the other }
  1924. { instructions }
  1925. var
  1926. p, hp1: tai;
  1927. nopropinfolevel: longint;
  1928. begin
  1929. removeInstructs := false;
  1930. p := First;
  1931. nopropinfolevel := 0;
  1932. while (p <> Last) do
  1933. begin
  1934. if (p.typ = ait_marker) and
  1935. (Tai_marker(p).kind = noPropInfoStart) then
  1936. begin
  1937. hp1 := tai(p.next);
  1938. asml.remove(p);
  1939. p.free;
  1940. nopropinfolevel := 1;
  1941. while (nopropinfolevel <> 0) do
  1942. begin
  1943. p := tai(hp1.next);
  1944. {$ifndef noinstremove}
  1945. { allocregbetween can insert new ait_regalloc objects }
  1946. { without optinfo }
  1947. if (hp1.typ = ait_marker) then
  1948. begin
  1949. case Tai_marker(hp1).kind of
  1950. { they can be nested! }
  1951. noPropInfoStart: inc(nopropinfolevel);
  1952. noPropInfoEnd: dec(nopropinfolevel);
  1953. else
  1954. begin
  1955. hp1 := p;
  1956. continue;
  1957. end;
  1958. end;
  1959. asml.remove(hp1);
  1960. hp1.free;
  1961. end
  1962. else if assigned(hp1.optinfo) then
  1963. if ptaiprop(hp1.optinfo)^.canBeRemoved then
  1964. begin
  1965. dispose(ptaiprop(hp1.optinfo));
  1966. hp1.optinfo := nil;
  1967. asml.remove(hp1);
  1968. hp1.free;
  1969. end
  1970. else
  1971. {$endif noinstremove}
  1972. begin
  1973. dispose(ptaiprop(hp1.optinfo));
  1974. hp1.optinfo := nil;
  1975. end;
  1976. hp1 := p;
  1977. end;
  1978. end
  1979. else
  1980. {$ifndef noinstremove}
  1981. if assigned(p.optinfo) and
  1982. ptaiprop(p.optinfo)^.canBeRemoved then
  1983. begin
  1984. hp1 := tai(p.next);
  1985. asml.Remove(p);
  1986. p.free;
  1987. p := hp1;
  1988. removeInstructs := true;
  1989. end
  1990. else
  1991. {$endif noinstremove}
  1992. begin
  1993. p.optinfo := nil;
  1994. p := tai(p.next);;
  1995. end;
  1996. end;
  1997. end;
  1998. function CSE(asml: TAAsmOutput; First, Last: tai; pass: longint): boolean;
  1999. begin
  2000. doCSE(asml, First, Last, not(cs_slowoptimize in aktglobalswitches) or (pass >= 2),
  2001. not(cs_slowoptimize in aktglobalswitches) or (pass >= 1));
  2002. { register renaming }
  2003. if not(cs_slowoptimize in aktglobalswitches) or (pass > 0) then
  2004. doRenaming(asml, first, last);
  2005. cse := removeInstructs(asml, first, last);
  2006. end;
  2007. end.
  2008. {
  2009. $Log$
  2010. Revision 1.66 2004-10-04 20:46:22 peter
  2011. * spilling code rewritten for x86. It now used the generic
  2012. spilling routines. Special x86 optimization still needs
  2013. to be added.
  2014. * Spilling fixed when both operands needed to be spilled
  2015. * Cleanup of spilling routine, do_spill_readwritten removed
  2016. Revision 1.65 2004/09/21 17:25:12 peter
  2017. * paraloc branch merged
  2018. Revision 1.64.4.1 2004/09/20 19:28:23 peter
  2019. * fixed valgrind warning
  2020. Revision 1.64 2004/07/23 13:30:19 jonas
  2021. * fixed some more potential regvar bugs
  2022. Revision 1.63 2004/06/20 08:55:31 florian
  2023. * logs truncated
  2024. Revision 1.62 2004/06/16 20:07:10 florian
  2025. * dwarf branch merged
  2026. Revision 1.61.2.2 2004/05/01 16:02:10 peter
  2027. * POINTER_SIZE replaced with sizeof(aint)
  2028. * aint,aword,tconst*int moved to globtype
  2029. Revision 1.61.2.1 2004/04/29 23:30:28 peter
  2030. * fix i386 compiler
  2031. Revision 1.61 2004/02/27 10:21:05 florian
  2032. * top_symbol killed
  2033. + refaddr to treference added
  2034. + refsymbol to treference added
  2035. * top_local stuff moved to an extra record to save memory
  2036. + aint introduced
  2037. * tppufile.get/putint64/aint implemented
  2038. Revision 1.60 2004/02/25 20:39:58 jonas
  2039. * fixed bugs that caused pasjpeg crashes
  2040. }