csopt386.pas 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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 defines.inc}
  21. Interface
  22. Uses aasm;
  23. {Procedure CSOpt386(First, Last: Pai);}
  24. Procedure CSE(AsmL: PAasmOutput; First, Last: Pai);
  25. Implementation
  26. Uses
  27. {$ifdef replaceregdebug}cutils,{$endif}
  28. verbose, hcodegen, globals,cpubase,cpuasm,DAOpt386, tgeni386;
  29. {
  30. Function PaiInSequence(P: Pai; Const Seq: TContent): Boolean;
  31. Var P1: Pai;
  32. Counter: Byte;
  33. TmpResult: Boolean;
  34. Begin
  35. TmpResult := False;
  36. P1 := Seq.StartMod;
  37. Counter := 1;
  38. While Not(TmpResult) And
  39. (Counter <= Seq.NrOfMods) Do
  40. Begin
  41. If (P = P1) Then TmpResult := True;
  42. Inc(Counter);
  43. p1 := Pai(p1^.Next);
  44. End;
  45. PaiInSequence := TmpResult;
  46. End;
  47. }
  48. function modifiesConflictingMemLocation(p1: pai; reg: tregister; c: tregContent;
  49. var regsStillValid: tregset): boolean;
  50. var
  51. p: paicpu;
  52. tmpRef: treference;
  53. regCounter: tregister;
  54. opCount: byte;
  55. begin
  56. modifiesConflictingMemLocation := false;
  57. if p1^.typ <> ait_instruction then
  58. exit;
  59. p := paicpu(p1);
  60. case p^.opcode of
  61. A_MOV,A_MOVSX,A_MOVZX:
  62. if p^.oper[1].typ = top_ref then
  63. for regCounter := R_EAX to R_EDI do
  64. begin
  65. if writeToMemDestroysContents(reg32(p^.oper[0].reg),p^.oper[1].ref^,
  66. regCounter,c[regCounter]) then
  67. begin
  68. exclude(regsStillValid,regCounter);
  69. modifiesConflictingMemLocation := not(reg in regsStillValid);
  70. end;
  71. end
  72. { else
  73. for regCounter := R_EAX to R_EDI do
  74. begin
  75. if writeDestroysContents(p^.oper[1],regCounter,c[regCounter]) then
  76. begin
  77. exclude(regsStillValid,regCounter);
  78. modifiesConflictingMemLocation := not(reg in regsStillValid);
  79. end
  80. end};
  81. A_IMUL,A_DIV, A_IDIV, A_MUL:; { they never write to memory }
  82. else
  83. for opCount := 1 to MaxCh do
  84. case InsProp[p^.opcode].Ch[opCount] of
  85. Ch_MOp1,CH_WOp1,CH_RWOp1:
  86. if paicpu(p)^.oper[0].typ = top_ref then
  87. for regCounter := R_EAX to R_EDI do
  88. if writeDestroysContents(p^.oper[0],regCounter,c[regCounter]) then
  89. begin
  90. exclude(regsStillValid,regCounter);
  91. modifiesConflictingMemLocation := not(reg in regsStillValid);
  92. end;
  93. Ch_MOp2,CH_WOp2,CH_RWOp2:
  94. if paicpu(p)^.oper[1].typ = top_ref then
  95. for regCounter := R_EAX to R_EDI do
  96. if writeDestroysContents(p^.oper[1],regCounter,c[regCounter]) then
  97. begin
  98. exclude(regsStillValid,regCounter);
  99. modifiesConflictingMemLocation := not(reg in regsStillValid);
  100. end;
  101. Ch_MOp3,CH_WOp3,CH_RWOp3:
  102. if paicpu(p)^.oper[2].typ = top_ref then
  103. for regCounter := R_EAX to R_EDI do
  104. if writeDestroysContents(p^.oper[2],regCounter,c[regCounter]) then
  105. begin
  106. exclude(regsStillValid,regCounter);
  107. modifiesConflictingMemLocation := not(reg in regsStillValid);
  108. end;
  109. Ch_WMemEDI:
  110. begin
  111. fillchar(tmpref,sizeof(tmpref),0);
  112. tmpRef.base := R_EDI;
  113. tmpRef.index := R_EDI;
  114. for regCounter := R_EAX to R_EDI do
  115. if writeToMemDestroysContents(R_NO,tmpRef,regCounter,c[regCounter]) then
  116. begin
  117. exclude(regsStillValid,regCounter);
  118. modifiesConflictingMemLocation := not(reg in regsStillValid);
  119. end;
  120. end;
  121. end;
  122. end;
  123. end;
  124. function getPrevSequence(p: pai; reg: tregister; currentPrev: pai; var newPrev: pai;
  125. var passedJump: boolean; var regsNotRead, regsStillValid: tregset): tregister;
  126. const
  127. current_reg: tregister = R_NO;
  128. function stillValid(p: pai): boolean;
  129. begin
  130. stillValid :=
  131. (p^.typ = ait_instruction) and
  132. (paicpu(p)^.opcode <> a_jmp) and
  133. (ppaiprop(p^.optinfo)^.regs[reg].wstate =
  134. ppaiprop(currentPrev^.optinfo)^.regs[reg].wstate) and
  135. { in case destroyreg is called with doIncState = false }
  136. (ppaiprop(p^.optinfo)^.regs[reg].typ =
  137. ppaiprop(currentPrev^.optinfo)^.regs[reg].typ) and
  138. (reg in (regsNotRead * regsStillValid));
  139. passedJump :=
  140. (p^.typ = ait_instruction) and
  141. (paicpu(p)^.is_jmp);
  142. end;
  143. function findChangedRegister(p: pai): tregister;
  144. var
  145. regCounter: tregister;
  146. begin
  147. for regCounter := succ(current_reg) to R_EDI do
  148. with ppaiprop(p^.optinfo)^.regs[regCounter] do
  149. if ((startmod <>
  150. ppaiprop(currentPrev^.optinfo)^.regs[regCounter].startmod) or
  151. (nrOfMods <>
  152. ppaiprop(currentPrev^.optinfo)^.regs[regCounter].nrOfMods)) and
  153. (ppaiprop(p^.optinfo)^.regs[regCounter].typ in
  154. [con_ref,con_noRemoveRef]) then
  155. begin
  156. findChangedRegister := regCounter;
  157. current_reg := regCounter;
  158. exit;
  159. end;
  160. current_reg := R_NO;
  161. findChangedRegister := R_NO;
  162. end;
  163. var
  164. hp, prevFound: pai;
  165. tmpResult, regCounter: tregister;
  166. begin
  167. if not(current_reg in [R_NO,R_EDI]) then
  168. begin
  169. tmpResult := findChangedRegister(currentPrev);
  170. if tmpResult <> R_NO then
  171. begin
  172. getPrevSequence := tmpResult;
  173. exit;
  174. end;
  175. end;
  176. getPrevSequence := R_NO;
  177. passedJump := passedJump or
  178. ((currentPrev^.typ = ait_instruction) and
  179. (paicpu(currentPrev)^.is_jmp));
  180. if (passedJump and not(reg in (usableregs+[R_EDI]))) or
  181. not getLastInstruction(currentPrev,hp) then
  182. exit;
  183. prevFound := currentPrev;
  184. tmpResult := R_NO;
  185. while (tmpResult = R_NO) and
  186. stillValid(hp) and
  187. not(modifiesConflictingMemLocation(prevFound,reg,
  188. ppaiprop(p^.optinfo)^.regs,regsStillValid)) do
  189. begin
  190. { only update the regsread for the instructions we already passed }
  191. if not(ppaiprop(prevFound^.optinfo)^.canBeRemoved) then
  192. for regCounter := R_EAX to R_EDI do
  193. if regReadByInstruction(regCounter,prevFound) then
  194. exclude(regsNotRead,regCounter);
  195. { in case getPreviousInstruction fails and sets hp to nil in the }
  196. { next iteration }
  197. prevFound := hp;
  198. if not(ppaiprop(hp^.optinfo)^.canBeRemoved) then
  199. tmpResult := findChangedRegister(hp);
  200. if { do not load the self pointer or a regvar before a (conditional) }
  201. { jump with a new value, since if the jump is taken, the old value }
  202. { is (probably) still necessary }
  203. (passedJump and not(reg in (usableregs+[R_EDI]))) or
  204. not getLastInstruction(hp,hp) then
  205. break;
  206. end;
  207. getPrevSequence := tmpResult;
  208. if tmpResult <> R_NO then
  209. newPrev := prevFound;
  210. end;
  211. function isSimpleMemLoc(const ref: treference): boolean;
  212. begin
  213. isSimpleMemLoc :=
  214. (ref.index = R_NO) and
  215. (not(ref.base in (usableregs+[R_EDI])) or
  216. (assigned(ref.symbol) and
  217. (ref.base = R_NO) and
  218. (ref.index = R_NO)));
  219. end;
  220. {checks whether the current instruction sequence (starting with p) and the
  221. one between StartMod and EndMod of Reg are the same. If so, the number of
  222. instructions that match is stored in Found and true is returned, otherwise
  223. Found holds the number of instructions between StartMod and EndMod and false
  224. is returned}
  225. Function CheckSequence(p: Pai; var prev: pai; Reg: TRegister; Var Found: Longint;
  226. Var RegInfo: TRegInfo): Boolean;
  227. const
  228. checkingPrevSequences: boolean = false;
  229. var
  230. regsNotRead, regsStillValid: tregset;
  231. function getNextRegToTest(var prev: pai; currentReg: tregister): tregister;
  232. const
  233. passedJump: boolean = false;
  234. begin
  235. if not checkingPrevSequences then
  236. begin
  237. Repeat
  238. Inc(currentReg);
  239. Until (currentReg > R_EDI) or
  240. (ppaiprop(prev^.optInfo)^.regs[currentReg].typ
  241. in [con_ref,con_noRemoveRef]);
  242. if currentReg > R_EDI then
  243. begin
  244. if isSimpleMemLoc(paicpu(p)^.oper[0].ref^) then
  245. begin
  246. checkingPrevSequences := true;
  247. passedJump := false;
  248. end
  249. else
  250. getNextRegToTest := R_NO;
  251. end
  252. else getNextRegToTest := currentReg;
  253. end;
  254. if checkingPrevSequences then
  255. getNextRegToTest :=
  256. getPrevSequence(p,reg,prev,prev,passedJump,regsNotRead,RegsStillValid);
  257. end;
  258. Var hp2, hp3{, EndMod},highPrev, orgPrev: Pai;
  259. {Cnt,} OldNrOfMods: Longint;
  260. startRegInfo, OrgRegInfo, HighRegInfo: TRegInfo;
  261. HighFound, OrgRegFound: Byte;
  262. RegCounter, regCounter2: TRegister;
  263. OrgRegResult: Boolean;
  264. TmpResult: Boolean;
  265. {TmpState: Byte;}
  266. Begin {CheckSequence}
  267. Reg := Reg32(Reg);
  268. TmpResult := False;
  269. FillChar(OrgRegInfo, SizeOf(OrgRegInfo), 0);
  270. FillChar(startRegInfo, sizeof(startRegInfo), 0);
  271. OrgRegFound := 0;
  272. HighFound := 0;
  273. OrgRegResult := False;
  274. with startRegInfo do
  275. begin
  276. newRegsEncountered := [procinfo^.FramePointer, stack_pointer];
  277. new2OldReg[procinfo^.FramePointer] := procinfo^.FramePointer;
  278. new2OldReg[stack_pointer] := stack_pointer;
  279. oldRegsEncountered := newRegsEncountered;
  280. end;
  281. checkingPrevSequences := false;
  282. regsNotRead := [R_EAX,R_EBX,R_ECX,R_EDX,R_ESP,R_EBP,R_EDI,R_ESI];
  283. regsStillValid := regsNotRead;
  284. GetLastInstruction(p, prev);
  285. regCounter := getNextRegToTest(prev,R_NO);
  286. While (RegCounter <> R_NO) Do
  287. Begin
  288. regInfo := startRegInfo;
  289. Found := 0;
  290. hp2 := PPaiProp(prev^.OptInfo)^.Regs[RegCounter].StartMod;
  291. If (prev <> PPaiProp(prev^.OptInfo)^.Regs[RegCounter].StartMod)
  292. Then OldNrOfMods := PPaiProp(prev^.OptInfo)^.Regs[RegCounter].NrOfMods
  293. Else OldNrOfMods := 1;
  294. hp3 := p;
  295. While (Found <> OldNrOfMods) And
  296. { old new }
  297. InstructionsEquivalent(hp2, hp3, RegInfo) Do
  298. Begin
  299. if (hp3^.typ = ait_instruction) and
  300. ((paicpu(hp3)^.opcode = A_MOV) or
  301. (paicpu(hp3)^.opcode = A_MOVZX) or
  302. (paicpu(hp3)^.opcode = A_MOVSX)) and
  303. (paicpu(hp3)^.oper[0].typ in
  304. [top_const,top_ref,top_symbol]) and
  305. (paicpu(hp3)^.oper[1].typ = top_reg) and
  306. not(regInRef(reg32(paicpu(hp3)^.oper[1].reg),
  307. paicpu(hp3)^.oper[0].ref^)) then
  308. regInfo.lastReload
  309. [reg32(paicpu(hp3)^.oper[1].reg)] := hp3;
  310. GetNextInstruction(hp2, hp2);
  311. GetNextInstruction(hp3, hp3);
  312. Inc(Found)
  313. End;
  314. for regCounter2 := R_EAX to R_EDI do
  315. if (regInfo.new2OldReg[regCounter2] <> R_NO) and
  316. (regCounter2 in PPaiProp(hp3^.optInfo)^.usedRegs) and
  317. not regLoadedWithNewValue(regCounter2,false,hp3) then
  318. include(regInfo.regsStillUsedAfterSeq,regCounter2);
  319. if checkingPrevSequences then
  320. for regCounter2 := R_EAX to R_EDI do
  321. if not(regInfo.new2OldReg[regCounter2] in [R_NO,regCounter2]) and
  322. (not(regCounter2 in (regsNotRead * regsStillValid)) or
  323. not(regInfo.new2OldReg[regCounter2] in regsStillValid)) then
  324. begin
  325. found := 0;
  326. break;
  327. end;
  328. If (Found <> OldNrOfMods) or
  329. { the following is to avoid problems with rangecheck code (see testcse2) }
  330. (assigned(hp3) and
  331. ((reg in regInfo.regsLoadedForRef) and
  332. (reg in PPaiProp(hp3^.optInfo)^.usedRegs) and
  333. not regLoadedWithNewValue(reg,false,hp3))) then
  334. Begin
  335. TmpResult := False;
  336. If (found > 0) then
  337. {this is correct because we only need to turn off the CanBeRemoved flag
  338. when an instruction has already been processed by CheckSequence
  339. (otherwise CanBeRemoved can't be true and thus can't have to be turned off).
  340. If it has already been processed by CheckSequence and flagged to be
  341. removed, it means that it has been checked against a previous sequence
  342. and that it was equal (otherwise CheckSequence would have returned false
  343. and the instruction wouldn't have been removed). If this "If found > 0"
  344. check is left out, incorrect optimizations are performed.}
  345. Found := PPaiProp(Pai(p)^.OptInfo)^.Regs[Reg].NrOfMods
  346. End
  347. Else TmpResult := True;
  348. If TmpResult And
  349. (Found > HighFound)
  350. Then
  351. Begin
  352. highPrev := prev;
  353. HighFound := Found;
  354. HighRegInfo := RegInfo;
  355. End;
  356. If (RegCounter = Reg) Then
  357. Begin
  358. orgPrev := prev;
  359. OrgRegFound := Found;
  360. OrgRegResult := TmpResult;
  361. OrgRegInfo := RegInfo
  362. End;
  363. regCounter := getNextRegToTest(prev,regCounter);
  364. End;
  365. If (HighFound > 0) And
  366. (Not(OrgRegResult) Or
  367. (HighFound > OrgRegFound))
  368. Then
  369. Begin
  370. {$ifndef fpc}
  371. TmpResult := True;
  372. {$else fpc}
  373. CheckSequence := True;
  374. {$endif fpc}
  375. prev := highPrev;
  376. RegInfo := HighRegInfo;
  377. Found := HighFound
  378. End
  379. Else
  380. Begin
  381. {$ifndef fpc}
  382. TmpResult := OrgRegResult;
  383. {$else fpc}
  384. CheckSequence := OrgRegResult;
  385. {$endif fpc}
  386. prev := orgPrev;
  387. Found := OrgRegFound;
  388. RegInfo := OrgRegInfo;
  389. End;
  390. {$ifndef fpc}
  391. CheckSequence := TmpResult;
  392. {$endif fpc}
  393. End; {CheckSequence}
  394. Procedure SetAlignReg(p: Pai);
  395. Const alignSearch = 12;
  396. var regsUsable: TRegSet;
  397. prevInstrCount, nextInstrCount: Longint;
  398. prevState, nextWState,nextRState: Array[R_EAX..R_EDI] of byte;
  399. regCounter, lastRemoved: TRegister;
  400. prev, next: Pai;
  401. {$ifdef alignregdebug}
  402. temp: Pai;
  403. {$endif alignregdebug}
  404. begin
  405. regsUsable := [R_EAX,R_ECX,R_EDX,R_EBX,{R_ESP,R_EBP,}R_ESI,R_EDI];
  406. for regCounter := R_EAX to R_EDI do
  407. begin
  408. prevState[regCounter] := PPaiProp(p^.optInfo)^.Regs[regCounter].wState;
  409. nextWState[regCounter] := PPaiProp(p^.optInfo)^.Regs[regCounter].wState;
  410. nextRState[regCounter] := PPaiProp(p^.optInfo)^.Regs[regCounter].rState;
  411. end;
  412. getLastInstruction(p,prev);
  413. getNextInstruction(p,next);
  414. lastRemoved := pai_align(p)^.reg;
  415. nextInstrCount := 0;
  416. prevInstrCount := 0;
  417. while ((assigned(prev) and
  418. assigned(prev^.optInfo) and
  419. (prevInstrCount < alignSearch)) or
  420. (assigned(next) and
  421. assigned(next^.optInfo) and
  422. (nextInstrCount < alignSearch))) And
  423. (regsUsable <> []) do
  424. begin
  425. {$ifdef alignregdebug}
  426. if assigned(prev) then
  427. begin
  428. temp := new(pai_asm_comment,init(strpnew('got here')));
  429. temp^.next := prev^.next;
  430. temp^.previous := prev;
  431. prev^.next := temp;
  432. if assigned(temp^.next) then
  433. temp^.next^.previous := temp;
  434. end;
  435. {$endif alignregdebug}
  436. if assigned(prev) and assigned(prev^.optinfo) and
  437. (prevInstrCount < alignSearch) then
  438. begin
  439. if (prev^.typ = ait_instruction) And
  440. (insProp[PaiCpu(prev)^.opcode].ch[1] <> Ch_ALL) and
  441. (PaiCpu(prev)^.opcode <> A_JMP) then
  442. begin
  443. inc(prevInstrCount);
  444. for regCounter := R_EAX to R_EDI do
  445. begin
  446. if (regCounter in regsUsable) And
  447. (PPaiProp(prev^.optInfo)^.Regs[regCounter].wState <>
  448. prevState[regCounter]) then
  449. begin
  450. lastRemoved := regCounter;
  451. exclude(regsUsable,regCounter);
  452. {$ifdef alignregdebug}
  453. temp := new(pai_asm_comment,init(strpnew(
  454. att_reg2str[regCounter]+' removed')));
  455. temp^.next := prev^.next;
  456. temp^.previous := prev;
  457. prev^.next := temp;
  458. if assigned(temp^.next) then
  459. temp^.next^.previous := temp;
  460. if regsUsable = [] then
  461. begin
  462. temp := new(pai_asm_comment,init(strpnew(
  463. 'regsUsable empty here')));
  464. temp^.next := prev^.next;
  465. temp^.previous := prev;
  466. prev^.next := temp;
  467. if assigned(temp^.next) then
  468. temp^.next^.previous := temp;
  469. end;
  470. {$endif alignregdebug}
  471. end;
  472. prevState[regCounter] :=
  473. PPaiProp(prev^.optInfo)^.Regs[regCounter].wState;
  474. end;
  475. getLastInstruction(prev,prev);
  476. end
  477. else
  478. If GetLastInstruction(prev,prev) and
  479. assigned(prev^.optinfo) then
  480. for regCounter := R_EAX to R_EDI do
  481. prevState[regCounter] :=
  482. PPaiProp(prev^.optInfo)^.Regs[regCounter].wState
  483. end;
  484. if assigned(next) and assigned(next^.optInfo) and
  485. (nextInstrCount < alignSearch) then
  486. begin
  487. if (next^.typ = ait_instruction) and
  488. (insProp[PaiCpu(next)^.opcode].ch[1] <> Ch_ALL) and
  489. (PaiCpu(next)^.opcode <> A_JMP) then
  490. begin
  491. inc(nextInstrCount);
  492. for regCounter := R_EAX to R_EDI do
  493. begin
  494. if (regCounter in regsUsable) And
  495. ((PPaiProp(next^.optInfo)^.Regs[regCounter].wState <>
  496. nextWState[regCounter]) or
  497. (PPaiProp(next^.optInfo)^.Regs[regCounter].rState <>
  498. nextRState[regCounter])) Then
  499. begin
  500. lastRemoved := regCounter;
  501. exclude(regsUsable,regCounter);
  502. {$ifdef alignregdebug}
  503. temp := new(pai_asm_comment,init(strpnew(
  504. att_reg2str[regCounter]+' removed')));
  505. temp^.next := next^.next;
  506. temp^.previous := next;
  507. next^.next := temp;
  508. if assigned(temp^.next) then
  509. temp^.next^.previous := temp;
  510. if regsUsable = [] then
  511. begin
  512. temp := new(pai_asm_comment,init(strpnew(
  513. 'regsUsable empty here')));
  514. temp^.next := next^.next;
  515. temp^.previous := next;
  516. next^.next := temp;
  517. if assigned(temp^.next) then
  518. temp^.next^.previous := temp;
  519. end;
  520. {$endif alignregdebug}
  521. end;
  522. nextWState[regCounter] :=
  523. PPaiProp(next^.optInfo)^.Regs[regCounter].wState;
  524. nextRState[regCounter] :=
  525. PPaiProp(next^.optInfo)^.Regs[regCounter].rState;
  526. end
  527. end
  528. else
  529. for regCounter := R_EAX to R_EDI do
  530. begin
  531. nextWState[regCounter] :=
  532. PPaiProp(next^.optInfo)^.Regs[regCounter].wState;
  533. nextRState[regCounter] :=
  534. PPaiProp(next^.optInfo)^.Regs[regCounter].rState;
  535. end;
  536. getNextInstruction(next,next);
  537. end;
  538. end;
  539. if regsUsable <> [] then
  540. for regCounter := R_EAX to R_EDI do
  541. if regCounter in regsUsable then
  542. begin
  543. lastRemoved := regCounter;
  544. break
  545. end;
  546. {$ifdef alignregdebug}
  547. next := new(pai_asm_comment,init(strpnew(att_reg2str[lastRemoved]+
  548. ' chosen as alignment register')));
  549. next^.next := p^.next;
  550. next^.previous := p;
  551. p^.next := next;
  552. if assigned(next^.next) then
  553. next^.next^.previous := next;
  554. {$endif alignregdebug}
  555. pai_align(p)^.reg := lastRemoved;
  556. End;
  557. Procedure RestoreRegContentsTo(reg: TRegister; const c: TContent; p, endP: pai);
  558. var
  559. {$ifdef replaceregdebug}
  560. hp: pai;
  561. l: longint;
  562. {$endif replaceregdebug}
  563. tmpState: byte;
  564. begin
  565. {$ifdef replaceregdebug}
  566. l := random(1000);
  567. hp := new(pai_asm_comment,init(strpnew(
  568. 'restored '+att_reg2str[reg]+' with data from here... '+tostr(l))));
  569. hp^.next := p;
  570. hp^.previous := p^.previous;
  571. p^.previous := hp;
  572. if assigned(hp^.previous) then
  573. hp^.previous^.next := hp;
  574. {$endif replaceregdebug}
  575. { PPaiProp(p^.optInfo)^.Regs[reg] := c;}
  576. While (p <> endP) Do
  577. Begin
  578. PPaiProp(p^.optInfo)^.Regs[reg] := c;
  579. getNextInstruction(p,p);
  580. end;
  581. tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
  582. repeat
  583. PPaiProp(p^.optInfo)^.Regs[reg] := c;
  584. until not getNextInstruction(p,p) or
  585. (PPaiProp(p^.optInfo)^.Regs[reg].wState <> tmpState);
  586. {$ifdef replaceregdebug}
  587. if assigned(p) then
  588. begin
  589. hp := new(pai_asm_comment,init(strpnew(
  590. 'restored '+att_reg2str[reg]+' till here... '+tostr(l))));
  591. hp^.next := p;
  592. hp^.previous := p^.previous;
  593. p^.previous := hp;
  594. if assigned(hp^.previous) then
  595. hp^.previous^.next := hp;
  596. end;
  597. {$endif replaceregdebug}
  598. end;
  599. function FindRegDealloc(reg: tregister; p: pai): boolean;
  600. { assumes reg is a 32bit register }
  601. var
  602. hp: pai;
  603. first: boolean;
  604. begin
  605. findregdealloc := false;
  606. first := true;
  607. while assigned(p^.previous) and
  608. ((Pai(p^.previous)^.typ in (skipinstr+[ait_align])) or
  609. ((Pai(p^.previous)^.typ = ait_label) and
  610. labelCanBeSkipped(pai_label(p^.previous)))) do
  611. begin
  612. p := pai(p^.previous);
  613. if (p^.typ = ait_regalloc) and
  614. (pairegalloc(p)^.reg = reg) then
  615. if not(pairegalloc(p)^.allocation) then
  616. if first then
  617. begin
  618. findregdealloc := true;
  619. break;
  620. end
  621. else
  622. begin
  623. findRegDealloc :=
  624. getNextInstruction(p,hp) and
  625. regLoadedWithNewValue(reg,false,hp);
  626. break
  627. end
  628. else
  629. first := false;
  630. end
  631. end;
  632. Procedure ClearRegContentsFrom(reg: TRegister; p, endP: pai);
  633. { first clears the contents of reg from p till endP. Then the contents are }
  634. { cleared until the first instruction that changes reg }
  635. var
  636. {$ifdef replaceregdebug}
  637. hp: pai;
  638. l: longint;
  639. {$endif replaceregdebug}
  640. oldStartmod: pai;
  641. begin
  642. {$ifdef replaceregdebug}
  643. l := random(1000);
  644. hp := new(pai_asm_comment,init(strpnew(
  645. 'cleared '+att_reg2str[reg]+' from here... '+tostr(l))));
  646. hp^.next := p;
  647. hp^.previous := p^.previous;
  648. p^.previous := hp;
  649. if assigned(hp^.previous) then
  650. hp^.previous^.next := hp;
  651. {$endif replaceregdebug}
  652. PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
  653. While (p <> endP) Do
  654. Begin
  655. PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
  656. getNextInstruction(p,p);
  657. end;
  658. oldStartmod := PPaiProp(p^.optInfo)^.Regs[reg].startmod;
  659. repeat
  660. PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
  661. until not getNextInstruction(p,p) or
  662. (PPaiProp(p^.optInfo)^.Regs[reg].startmod <> oldStartmod);
  663. {$ifdef replaceregdebug}
  664. if assigned(p) then
  665. begin
  666. hp := new(pai_asm_comment,init(strpnew(
  667. 'cleared '+att_reg2str[reg]+' till here... '+tostr(l))));
  668. hp^.next := p;
  669. hp^.previous := p^.previous;
  670. p^.previous := hp;
  671. if assigned(hp^.previous) then
  672. hp^.previous^.next := hp;
  673. end;
  674. {$endif replaceregdebug}
  675. end;
  676. function NoHardCodedRegs(p: paicpu; orgReg, newReg: tRegister): boolean;
  677. var chCount: byte;
  678. begin
  679. case p^.opcode of
  680. A_IMUL: noHardCodedRegs := p^.ops <> 1;
  681. A_SHL,A_SHR,A_SHLD,A_SHRD: noHardCodedRegs :=
  682. (p^.oper[0].typ <> top_reg) or
  683. ((orgReg <> R_ECX) and (newReg <> R_ECX));
  684. else
  685. begin
  686. NoHardCodedRegs := true;
  687. with InsProp[p^.opcode] do
  688. for chCount := 1 to MaxCh do
  689. if Ch[chCount] in ([Ch_REAX..Ch_MEDI,Ch_WMemEDI,Ch_All]-[Ch_RESP,Ch_WESP,Ch_RWESP]) then
  690. begin
  691. NoHardCodedRegs := false;
  692. break
  693. end;
  694. end;
  695. end;
  696. end;
  697. function ChangeReg(var Reg: TRegister; orgReg, newReg: TRegister): boolean;
  698. begin
  699. changeReg := true;
  700. if reg = newReg then
  701. reg := orgReg
  702. else if reg = regtoreg8(newReg) then
  703. reg := regtoreg8(orgReg)
  704. else if reg = regtoreg16(newReg) then
  705. reg := regtoreg16(orgReg)
  706. else changeReg := false;
  707. end;
  708. function changeOp(var o: toper; orgReg, newReg: tregister): boolean;
  709. begin
  710. case o.typ of
  711. top_reg: changeOp := changeReg(o.reg,orgReg,newReg);
  712. top_ref:
  713. begin
  714. changeOp :=
  715. changeReg(o.ref^.base,orgReg,newReg) or
  716. changeReg(o.ref^.index,orgReg,newReg);
  717. end;
  718. end;
  719. end;
  720. procedure updateStates(orgReg,newReg: tregister; hp: pai; writeStateToo: boolean);
  721. var
  722. prev: pai;
  723. newOrgRegRState, newOrgRegWState: byte;
  724. begin
  725. if getLastInstruction(hp,prev) then
  726. with ppaiprop(prev^.optinfo)^ do
  727. begin
  728. newOrgRegRState := regs[orgReg].rState +
  729. ppaiprop(hp^.optinfo)^.regs[newReg].rState - regs[newReg].rstate;
  730. if writeStateToo then
  731. newOrgRegWState := regs[orgReg].wState +
  732. ppaiprop(hp^.optinfo)^.regs[newReg].wState - regs[newReg].wstate;
  733. end
  734. else
  735. with ppaiprop(hp^.optinfo)^.regs[newReg] do
  736. begin
  737. newOrgRegRState := rState;
  738. if writeStateToo then
  739. newOrgRegWState := wState;
  740. end;
  741. with ppaiprop(hp^.optinfo)^.regs[orgReg] do
  742. begin
  743. rState := newOrgRegRState;
  744. if writeStateToo then
  745. wState := newOrgRegwState;
  746. end;
  747. end;
  748. function doReplaceReg(orgReg,newReg: tregister; hp: paicpu): boolean;
  749. var
  750. opCount: byte;
  751. tmpResult: boolean;
  752. begin
  753. for opCount := 0 to 2 do
  754. tmpResult :=
  755. changeOp(hp^.oper[opCount],orgReg,newReg) or tmpResult;
  756. doReplaceReg := tmpResult;
  757. end;
  758. function RegSizesOK(oldReg,newReg: TRegister; p: paicpu): boolean;
  759. { oldreg and newreg must be 32bit components }
  760. var opCount: byte;
  761. begin
  762. RegSizesOK := true;
  763. { if only one of them is a general purpose register ... }
  764. if (IsGP32reg(oldReg) xor IsGP32Reg(newReg)) then
  765. begin
  766. for opCount := 0 to 2 do
  767. if (p^.oper[opCount].typ = top_reg) and
  768. (p^.oper[opCount].reg in [R_AL..R_DH]) then
  769. begin
  770. RegSizesOK := false;
  771. break
  772. end
  773. end;
  774. end;
  775. function doReplaceReadReg(orgReg,newReg: tregister; p: paicpu): boolean;
  776. var opCount: byte;
  777. begin
  778. doReplaceReadReg := false;
  779. { handle special case }
  780. case p^.opcode of
  781. A_IMUL:
  782. begin
  783. case p^.ops of
  784. 1: internalerror(1301001);
  785. 2,3:
  786. begin
  787. if changeOp(p^.oper[0],orgReg,newReg) then
  788. begin
  789. { updateStates(orgReg,newReg,p,false);}
  790. doReplaceReadReg := true;
  791. end;
  792. if p^.ops = 3 then
  793. if changeOp(p^.oper[1],orgReg,newReg) then
  794. begin
  795. { updateStates(orgReg,newReg,p,false);}
  796. doReplaceReadReg := true;
  797. end;
  798. end;
  799. end;
  800. end;
  801. A_DIV,A_IDIV,A_MUL: internalerror(1301002);
  802. else
  803. begin
  804. for opCount := 0 to 2 do
  805. if p^.oper[opCount].typ = top_ref then
  806. if changeOp(p^.oper[opCount],orgReg,newReg) then
  807. begin
  808. { updateStates(orgReg,newReg,p,false);}
  809. doReplaceReadReg := true;
  810. end;
  811. for opCount := 1 to MaxCh do
  812. case InsProp[p^.opcode].Ch[opCount] of
  813. Ch_ROp1:
  814. if p^.oper[0].typ = top_reg then
  815. if changeReg(p^.oper[0].reg,orgReg,newReg) then
  816. begin
  817. { updateStates(orgReg,newReg,p,false);}
  818. doReplaceReadReg := true;
  819. end;
  820. Ch_ROp2:
  821. if p^.oper[1].typ = top_reg then
  822. if changeReg(p^.oper[1].reg,orgReg,newReg) then
  823. begin
  824. { updateStates(orgReg,newReg,p,false);}
  825. doReplaceReadReg := true;
  826. end;
  827. Ch_ROp3:
  828. if p^.oper[2].typ = top_reg then
  829. if changeReg(p^.oper[2].reg,orgReg,newReg) then
  830. begin
  831. { updateStates(orgReg,newReg,p,false);}
  832. doReplaceReadReg := true;
  833. end;
  834. end;
  835. end;
  836. end;
  837. end;
  838. procedure updateState(reg: tregister; p: pai);
  839. { this procedure updates the read and write states of the instructions }
  840. { coming after p. It's called when the read/write state of p has been }
  841. { changed and this change has to be propagated to the following }
  842. { instructions as well }
  843. var
  844. newRState, newWState: byte;
  845. prevRState, prevWState: byte;
  846. doRState, doWState: boolean;
  847. begin
  848. { get the new read/write states from p }
  849. with ppaiprop(p^.optinfo)^.regs[reg] do
  850. begin
  851. newRState := rState;
  852. newWState := wState;
  853. end;
  854. if not GetNextInstruction(p,p) then
  855. exit;
  856. { get the old read/write states from the next instruction, to know }
  857. { when we can stop updating }
  858. with ppaiprop(p^.optinfo)^.regs[reg] do
  859. begin
  860. prevRState := rState;
  861. prevWState := wState;
  862. end;
  863. { adjust the states if this next instruction reads/writes the register }
  864. if regReadByInstruction(reg,p) then
  865. incState(newRState,1);
  866. if regModifiedByInstruction(reg,p) then
  867. incState(newWState,1);
  868. { do we still have to update the read and/or write states? }
  869. doRState := true;
  870. doWState := true;
  871. repeat
  872. { update the states }
  873. with ppaiprop(p^.optinfo)^.regs[reg] do
  874. begin
  875. if doRState then
  876. rState := newRState;
  877. if doWState then
  878. wState := newWState;
  879. end;
  880. if not getNextInstruction(p,p) then
  881. break;
  882. with ppaiprop(p^.optinfo)^.regs[reg] do
  883. begin
  884. { stop updating the read state if it changes }
  885. doRState :=
  886. doRState and (rState = prevRState);
  887. { if, by accident, this changed state is the same as the one }
  888. { we've been using, change it to a value that's definitely }
  889. { different from the previous and next state }
  890. if not doRState and
  891. (rState = newRState) then
  892. begin
  893. incState(newRState,1);
  894. prevRState := rState;
  895. doRState := true;
  896. end;
  897. { ditto for the write state }
  898. doWState :=
  899. doWState and (WState = prevWState);
  900. if not doWState and
  901. (wState = newWState) then
  902. begin
  903. incState(newWState,1);
  904. prevWState := wState;
  905. doWState := true;
  906. end;
  907. end;
  908. { stop when we don't have to update either state anymore }
  909. until not(doRState or doWState);
  910. end;
  911. function ReplaceReg(asmL: PaasmOutput; orgReg, newReg: TRegister; p: pai;
  912. const c: TContent; orgRegCanBeModified: Boolean;
  913. var returnEndP: pai): Boolean;
  914. { Tries to replace orgreg with newreg in all instructions coming after p }
  915. { until orgreg gets loaded with a new value. Returns true if successful, }
  916. { false otherwise. If successful, the contents of newReg are set to c, }
  917. { which should hold the contents of newReg before the current sequence }
  918. { started }
  919. { if the function returns true, returnEndP holds the last instruction }
  920. { where newReg was replaced by orgReg }
  921. var endP, hp: Pai;
  922. removeLast, sequenceEnd, tmpResult, newRegModified, orgRegRead,
  923. stateChanged, readStateChanged: Boolean;
  924. function storeBack(p1: pai): boolean;
  925. { returns true if p1 contains an instruction that stores the contents }
  926. { of newReg back to orgReg }
  927. begin
  928. storeBack :=
  929. (p1^.typ = ait_instruction) and
  930. (paicpu(p1)^.opcode = A_MOV) and
  931. (paicpu(p1)^.oper[0].typ = top_reg) and
  932. (paicpu(p1)^.oper[0].reg = newReg) and
  933. (paicpu(p1)^.oper[1].typ = top_reg) and
  934. (paicpu(p1)^.oper[1].reg = orgReg);
  935. end;
  936. begin
  937. ReplaceReg := false;
  938. tmpResult := true;
  939. sequenceEnd := false;
  940. newRegModified := false;
  941. orgRegRead := false;
  942. removeLast := false;
  943. endP := p;
  944. while tmpResult and not sequenceEnd do
  945. begin
  946. tmpResult :=
  947. getNextInstruction(endP,endP) and
  948. (endP^.typ = ait_instruction);
  949. if tmpresult and not assigned(endP^.optInfo) then
  950. begin
  951. { hp := new(pai_asm_comment,init(strpnew('next no optinfo')));
  952. hp^.next := endp;
  953. hp^.previous := endp^.previous;
  954. endp^.previous := hp;
  955. if assigned(hp^.previous) then
  956. hp^.previous^.next := hp;}
  957. exit;
  958. end;
  959. If tmpResult and
  960. { don't take into account instructions that will be removed }
  961. Not (PPaiProp(endP^.optInfo)^.canBeRemoved) then
  962. begin
  963. { if the newReg gets stored back to the oldReg, we can change }
  964. { "mov %oldReg,%newReg; <operations on %newReg>; mov %newReg, }
  965. { %oldReg" to "<operations on %oldReg>" }
  966. removeLast := storeBack(endP);
  967. sequenceEnd :=
  968. { no support for (i)div, mul and imul with hardcoded operands }
  969. (noHardCodedRegs(paicpu(endP),orgReg,newReg) and
  970. { if newReg gets loaded with a new value, we can stop }
  971. { replacing newReg with oldReg here (possibly keeping }
  972. { the original contents of oldReg so we still know them }
  973. { afterwards) }
  974. RegLoadedWithNewValue(newReg,true,paicpu(endP)) or
  975. { we can also stop if we reached the end of the use of }
  976. { newReg's current contents }
  977. (GetNextInstruction(endp,hp) and
  978. FindRegDealloc(newReg,hp)));
  979. { to be able to remove the first and last instruction of }
  980. { movl %reg1, %reg2 }
  981. { <operations on %reg2> (replacing reg2 with reg1 here) }
  982. { movl %reg2, %reg1 }
  983. { %reg2 must not be use afterwards (it can be as the }
  984. { result of a peepholeoptimization) }
  985. removeLast := removeLast and sequenceEnd;
  986. newRegModified :=
  987. newRegModified or
  988. (not(regLoadedWithNewValue(newReg,true,paicpu(endP))) and
  989. RegModifiedByInstruction(newReg,endP));
  990. orgRegRead := newRegModified and RegReadByInstruction(orgReg,endP);
  991. sequenceEnd := SequenceEnd and
  992. (removeLast or
  993. { since newReg will be replaced by orgReg, we can't allow that newReg }
  994. { gets modified if orgReg is still read afterwards (since after }
  995. { replacing, this would mean that orgReg first gets modified and then }
  996. { gets read in the assumption it still contains the unmodified value) }
  997. not(newRegModified and orgRegRead)) (* and
  998. { since newReg will be replaced by orgReg, we can't allow that newReg }
  999. { gets modified if orgRegCanBeModified = false }
  1000. { this now gets checked after the loop (JM) }
  1001. (orgRegCanBeModified or not(newRegModified)) *);
  1002. tmpResult :=
  1003. not(removeLast) and
  1004. not(newRegModified and orgRegRead) and
  1005. (* (orgRegCanBeModified or not(newRegModified)) and *)
  1006. (endP^.typ = ait_instruction) and
  1007. not(paicpu(endP)^.is_jmp) and
  1008. NoHardCodedRegs(paicpu(endP),orgReg,newReg) and
  1009. RegSizesOk(orgReg,newReg,paicpu(endP)) and
  1010. not RegModifiedByInstruction(orgReg,endP);
  1011. end;
  1012. end;
  1013. sequenceEnd := sequenceEnd and
  1014. (removeLast or
  1015. (orgRegCanBeModified or not(newRegModified))) and
  1016. (not(assigned(endp)) or
  1017. not(endp^.typ = ait_instruction) or
  1018. (noHardCodedRegs(paicpu(endP),orgReg,newReg) and
  1019. RegSizesOk(orgReg,newReg,paicpu(endP)) and
  1020. not(newRegModified and
  1021. (orgReg in PPaiProp(endP^.optInfo)^.usedRegs) and
  1022. not(RegLoadedWithNewValue(orgReg,true,paicpu(endP))))));
  1023. if SequenceEnd then
  1024. begin
  1025. {$ifdef replaceregdebug}
  1026. hp := new(pai_asm_comment,init(strpnew(
  1027. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  1028. ' from here...')));
  1029. hp^.next := p;
  1030. hp^.previous := p^.previous;
  1031. p^.previous := hp;
  1032. if assigned(hp^.previous) then
  1033. hp^.previous^.next := hp;
  1034. hp := new(pai_asm_comment,init(strpnew(
  1035. 'replaced '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  1036. ' till here')));
  1037. hp^.next := endp^.next;
  1038. hp^.previous := endp;
  1039. endp^.next := hp;
  1040. if assigned(hp^.next) then
  1041. hp^.next^.previous := hp;
  1042. {$endif replaceregdebug}
  1043. replaceReg := true;
  1044. returnEndP := endP;
  1045. getNextInstruction(p,hp);
  1046. stateChanged := false;
  1047. while hp <> endP do
  1048. begin
  1049. if {not(PPaiProp(hp^.optInfo)^.canBeRemoved) and }
  1050. (hp^.typ = ait_instruction) then
  1051. stateChanged :=
  1052. doReplaceReg(orgReg,newReg,paicpu(hp)) or stateChanged;
  1053. if stateChanged then
  1054. updateStates(orgReg,newReg,hp,true);
  1055. getNextInstruction(hp,hp)
  1056. end;
  1057. if assigned(endp) and (endp^.typ = ait_instruction) then
  1058. readStateChanged :=
  1059. DoReplaceReadReg(orgReg,newReg,paicpu(endP));
  1060. if stateChanged or readStateChanged then
  1061. updateStates(orgReg,newReg,endP,stateChanged);
  1062. if stateChanged or readStateChanged then
  1063. updateState(orgReg,endP);
  1064. { the replacing stops either at the moment that }
  1065. { a) the newreg gets loaded with a new value (one not depending on the }
  1066. { current value of newreg) }
  1067. { b) newreg is completely replaced in this sequence and it's current value }
  1068. { isn't used anymore }
  1069. { In case b, the newreg was completely replaced by oldreg, so it's contents }
  1070. { are unchanged compared the start of this sequence, so restore them }
  1071. If removeLast or
  1072. RegLoadedWithNewValue(newReg,true,endP) then
  1073. GetLastInstruction(endP,hp)
  1074. else hp := endP;
  1075. if removeLast or
  1076. (p <> endp) or
  1077. not RegLoadedWithNewValue(newReg,true,endP) then
  1078. RestoreRegContentsTo(newReg,c,p,hp);
  1079. { In both case a and b, it is possible that the new register was modified }
  1080. { (e.g. an add/sub), so if it was replaced by oldreg in that instruction, }
  1081. { oldreg's contents have been changed. To take this into account, we simply }
  1082. { set the contents of orgreg to "unknown" after this sequence }
  1083. if newRegModified then
  1084. ClearRegContentsFrom(orgReg,p,hp);
  1085. if removeLast then
  1086. ppaiprop(endP^.optinfo)^.canBeRemoved := true;
  1087. allocRegBetween(asml,orgReg,p,endP);
  1088. end
  1089. {$ifdef replaceregdebug}
  1090. else
  1091. begin
  1092. hp := new(pai_asm_comment,init(strpnew(
  1093. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  1094. ' from here...')));
  1095. hp^.previous := p^.previous;
  1096. hp^.next := p;
  1097. p^.previous := hp;
  1098. if assigned(hp^.previous) then
  1099. hp^.previous^.next := hp;
  1100. hp := new(pai_asm_comment,init(strpnew(
  1101. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  1102. ' failed here')));
  1103. hp^.next := endp^.next;
  1104. hp^.previous := endp;
  1105. endp^.next := hp;
  1106. if assigned(hp^.next) then
  1107. hp^.next^.previous := hp;
  1108. end;
  1109. {$endif replaceregdebug}
  1110. End;
  1111. Function FindRegWithConst(p: Pai; size: topsize; l: longint; Var Res: TRegister): Boolean;
  1112. {Finds a register which contains the constant l}
  1113. Var Counter: TRegister;
  1114. {$ifdef testing}
  1115. hp: pai;
  1116. {$endif testing}
  1117. tmpresult: boolean;
  1118. Begin
  1119. Counter := R_NO;
  1120. repeat
  1121. inc(counter);
  1122. tmpresult := (ppaiprop(p^.optInfo)^.regs[counter].typ in
  1123. [con_const,con_noRemoveConst]) and
  1124. (paicpu(PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod)^.opsize = size) and
  1125. (paicpu(PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod)^.oper[0].typ = top_const) and
  1126. (paicpu(PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod)^.oper[0].val = l);
  1127. {$ifdef testing}
  1128. if (ppaiprop(p^.optInfo)^.regs[counter].typ in [con_const,con_noRemoveConst]) then
  1129. begin
  1130. hp := new(pai_asm_comment,init(strpnew(
  1131. 'checking const load of '+tostr(l)+' here...')));
  1132. hp^.next := PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod;
  1133. hp^.previous := PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod^.previous;
  1134. PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod^.previous := hp;
  1135. if assigned(hp^.previous) then
  1136. hp^.previous^.next := hp;
  1137. end;
  1138. {$endif testing}
  1139. until tmpresult or (Counter = R_EDI);
  1140. res := counter;
  1141. FindRegWithConst := tmpResult;
  1142. End;
  1143. procedure removePrevNotUsedLoad(p: pai; reg: tRegister; check: boolean);
  1144. { If check = true, it means the procedure has to check whether it isn't }
  1145. { possible that the contents are still used after p (used when removing }
  1146. { instructions because of a "call"), otherwise this is not necessary }
  1147. { (e.g. when you have a "mov 8(%ebp),%eax", you can be sure the previous }
  1148. { value of %eax isn't used anymore later on) }
  1149. var
  1150. hp1: pai;
  1151. begin
  1152. if getLastInstruction(p,hp1) then
  1153. with ppaiprop(hp1^.optInfo)^.regs[reg] do
  1154. if (typ in [con_ref,con_invalid]) and
  1155. (nrOfMods = 1) and
  1156. (rState = ppaiprop(startmod^.optInfo)^.regs[reg].rState) and
  1157. (not(check) or
  1158. (not(regInInstruction(reg,p)) and
  1159. (not(reg in usableregs) and
  1160. (startmod^.typ = ait_instruction) and
  1161. ((paicpu(startmod)^.opcode = A_MOV) or
  1162. (paicpu(startmod)^.opcode = A_MOVZX) or
  1163. (paicpu(startmod)^.opcode = A_MOVSX)) and
  1164. (paicpu(startmod)^.oper[0].typ = top_ref) and
  1165. (paicpu(startmod)^.oper[0].ref^.base = stack_pointer)) or
  1166. not(reg in ppaiprop(hp1^.optInfo)^.usedRegs) or
  1167. findRegDealloc(reg,p))) then
  1168. ppaiprop(startMod^.optInfo)^.canBeRemoved := true;
  1169. end;
  1170. Procedure DoCSE(AsmL: PAasmOutput; First, Last: Pai);
  1171. {marks the instructions that can be removed by RemoveInstructs. They're not
  1172. removed immediately because sometimes an instruction needs to be checked in
  1173. two different sequences}
  1174. var cnt, cnt2, cnt3: longint;
  1175. p, hp1, hp2, prevSeq, prevSeq_next: Pai;
  1176. hp3, hp4: pai;
  1177. hp5 : pai;
  1178. RegInfo: TRegInfo;
  1179. RegCounter: TRegister;
  1180. Begin
  1181. p := First;
  1182. SkipHead(p);
  1183. First := p;
  1184. While (p <> Last) Do
  1185. Begin
  1186. Case p^.typ Of
  1187. ait_align:
  1188. if not(pai_align(p)^.use_op) then
  1189. SetAlignReg(p);
  1190. ait_instruction:
  1191. Begin
  1192. Case Paicpu(p)^.opcode Of
  1193. A_CALL:
  1194. for regCounter := R_EAX to R_EBX do
  1195. removePrevNotUsedLoad(p,regCounter,true);
  1196. A_CLD: If GetLastInstruction(p, hp1) And
  1197. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_NotSet) Then
  1198. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  1199. A_MOV, A_MOVZX, A_MOVSX:
  1200. Begin
  1201. Case Paicpu(p)^.oper[0].typ Of
  1202. Top_Ref:
  1203. Begin {destination is always a register in this case}
  1204. With PPaiProp(p^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)] Do
  1205. Begin
  1206. If (p = StartMod) And
  1207. GetLastInstruction (p, hp1) And
  1208. (hp1^.typ <> ait_marker) Then
  1209. {so we don't try to check a sequence when p is the first instruction of the block}
  1210. begin
  1211. {$ifdef csdebug}
  1212. hp5 := new(pai_asm_comment,init(strpnew(
  1213. 'cse checking '+att_reg2str[Reg32(Paicpu(p)^.oper[1].reg)])));
  1214. insertLLItem(asml,p,p^.next,hp5);
  1215. {$endif csdebug}
  1216. If CheckSequence(p,prevSeq,Paicpu(p)^.oper[1].reg, Cnt, RegInfo) And
  1217. (Cnt > 0) Then
  1218. Begin
  1219. hp1 := nil;
  1220. { although it's perfectly ok to remove an instruction which doesn't contain }
  1221. { the register that we've just checked (CheckSequence takes care of that), }
  1222. { the sequence containing this other register should also be completely }
  1223. { checked and removed, otherwise we may get situations like this: }
  1224. { }
  1225. { movl 12(%ebp), %edx movl 12(%ebp), %edx }
  1226. { movl 16(%ebp), %eax movl 16(%ebp), %eax }
  1227. { movl 8(%edx), %edx movl 8(%edx), %edx }
  1228. { movl (%eax), eax movl (%eax), eax }
  1229. { cmpl %eax, %edx cmpl %eax, %edx }
  1230. { jnz l123 getting converted to jnz l123 }
  1231. { movl 12(%ebp), %edx movl 4(%eax), eax }
  1232. { movl 16(%ebp), %eax }
  1233. { movl 8(%edx), %edx }
  1234. { movl 4(%eax), eax }
  1235. hp2 := p;
  1236. Cnt2 := 1;
  1237. While Cnt2 <= Cnt Do
  1238. Begin
  1239. If Not(RegInInstruction(Paicpu(hp2)^.oper[1].reg, p)) then
  1240. begin
  1241. if ((p^.typ = ait_instruction) And
  1242. ((paicpu(p)^.OpCode = A_MOV) or
  1243. (paicpu(p)^.opcode = A_MOVZX) or
  1244. (paicpu(p)^.opcode = A_MOVSX)) And
  1245. (paicpu(p)^.Oper[0].typ in
  1246. [top_const,top_ref,top_symbol])) and
  1247. (paicpu(p)^.oper[1].typ = top_reg) then
  1248. begin
  1249. regCounter := reg32(paicpu(p)^.oper[1].reg);
  1250. if (regCounter in reginfo.regsStillUsedAfterSeq) then
  1251. begin
  1252. if (hp1 = nil) then
  1253. hp1 := reginfo.lastReload[regCounter];
  1254. end
  1255. {$ifndef noremove}
  1256. else
  1257. begin
  1258. hp5 := p;
  1259. for cnt3 := ppaiprop(p^.optinfo)^.regs[regCounter].nrofmods downto 1 do
  1260. begin
  1261. if regModifiedByInstruction(regCounter,hp5) then
  1262. PPaiProp(hp5^.OptInfo)^.CanBeRemoved := True;
  1263. getNextInstruction(hp5,hp5);
  1264. end;
  1265. end
  1266. {$endif noremove}
  1267. end
  1268. end
  1269. {$ifndef noremove}
  1270. else
  1271. PPaiProp(p^.OptInfo)^.CanBeRemoved := True
  1272. {$endif noremove}
  1273. ; Inc(Cnt2);
  1274. GetNextInstruction(p, p);
  1275. End;
  1276. {hp4 is used to get the contents of the registers before the sequence}
  1277. GetLastInstruction(hp2, hp4);
  1278. getNextInstruction(prevSeq,prevSeq_next);
  1279. {$IfDef CSDebug}
  1280. For RegCounter := R_EAX To R_EDI Do
  1281. If (RegCounter in RegInfo.RegsLoadedForRef) Then
  1282. Begin
  1283. hp5 := new(pai_asm_comment,init(strpnew('New: '+att_reg2str[RegCounter]+', Old: '+
  1284. att_reg2str[RegInfo.New2OldReg[RegCounter]])));
  1285. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp5);
  1286. End;
  1287. {$EndIf CSDebug}
  1288. { If some registers were different in the old and the new sequence, move }
  1289. { the contents of those old registers to the new ones }
  1290. For RegCounter := R_EAX To R_EDI Do
  1291. If Not(RegCounter in [R_ESP,procinfo^.framepointer]) And
  1292. (RegInfo.New2OldReg[RegCounter] <> R_NO) Then
  1293. Begin
  1294. AllocRegBetween(AsmL,RegInfo.New2OldReg[RegCounter],
  1295. PPaiProp(prevSeq^.OptInfo)^.Regs[RegInfo.New2OldReg[RegCounter]].StartMod,prevSeq_next);
  1296. if hp4 <> prevSeq then
  1297. begin
  1298. if assigned(reginfo.lastReload[regCounter]) then
  1299. getLastInstruction(reginfo.lastReload[regCounter],hp3)
  1300. else hp3 := hp4;
  1301. if prevSeq <> hp3 then
  1302. clearRegContentsFrom(regCounter,prevSeq_next,
  1303. hp3);
  1304. allocRegBetween(asmL,regCounter,prevSeq,hp3);
  1305. end;
  1306. If Not(RegCounter In RegInfo.RegsLoadedForRef) And
  1307. {old reg new reg}
  1308. (RegInfo.New2OldReg[RegCounter] <> RegCounter) Then
  1309. Begin
  1310. getLastInstruction(p,hp3);
  1311. If (hp4 <> prevSeq) or
  1312. not(regCounter in usableRegs + [R_EDI,R_ESI]) or
  1313. not ReplaceReg(asmL,RegInfo.New2OldReg[RegCounter],
  1314. regCounter,hp3,
  1315. PPaiProp(PrevSeq^.optInfo)^.Regs[regCounter],true,hp5) then
  1316. begin
  1317. hp3 := New(Pai_Marker,Init(NoPropInfoEnd));
  1318. InsertLLItem(AsmL, prevSeq, Pai(prevSeq^.next), hp3);
  1319. hp3 := New(Paicpu,Op_Reg_Reg(A_MOV, S_L,
  1320. {old reg new reg}
  1321. RegInfo.New2OldReg[RegCounter], RegCounter));
  1322. InsertLLItem(AsmL, prevSeq, Pai(prevSeq^.next), hp3);
  1323. hp3 := New(Pai_Marker,Init(NoPropInfoStart));
  1324. InsertLLItem(AsmL, prevSeq, Pai(prevSeq^.next), hp3);
  1325. { adjusts states in previous instruction so that it will }
  1326. { definitely be different from the previous or next state }
  1327. incstate(ppaiprop(prevSeq_next^.optinfo)^.
  1328. regs[RegInfo.New2OldReg[RegCounter]].rstate,20);
  1329. incstate(ppaiprop(prevSeq_next^.optinfo)^.
  1330. regs[regCounter].wstate,20);
  1331. updateState(RegInfo.New2OldReg[RegCounter],
  1332. prevSeq_next);
  1333. end
  1334. End
  1335. Else
  1336. { imagine the following code: }
  1337. { normal wrong optimized }
  1338. { movl 8(%ebp), %eax movl 8(%ebp), %eax }
  1339. { movl (%eax), %eax movl (%eax), %eax }
  1340. { cmpl 8(%ebp), %eax cmpl 8(%ebp), %eax }
  1341. { jne l1 jne l1 }
  1342. { movl 8(%ebp), %eax }
  1343. { movl (%eax), %edi movl %eax, %edi }
  1344. { movl %edi, -4(%ebp) movl %edi, -4(%ebp) }
  1345. { movl 8(%ebp), %eax }
  1346. { pushl 70(%eax) pushl 70(%eax) }
  1347. { }
  1348. { The error is that at the moment that the last instruction is executed, }
  1349. { %eax doesn't contain 8(%ebp) anymore. Solution: the contents of }
  1350. { registers that are completely removed from a sequence (= registers in }
  1351. { RegLoadedForRef, have to be changed to their contents from before the }
  1352. { sequence. }
  1353. If RegCounter in RegInfo.RegsLoadedForRef Then
  1354. Begin
  1355. hp3 := hp2;
  1356. { cnt still holds the number of instructions }
  1357. { of the sequence, so go to the end of it }
  1358. for cnt2 := 1 to pred(cnt) Do
  1359. getNextInstruction(hp3,hp3);
  1360. { hp4 = instruction prior to start of sequence }
  1361. restoreRegContentsTo(regCounter,
  1362. PPaiProp(hp4^.OptInfo)^.Regs[RegCounter],
  1363. hp2,hp3);
  1364. End;
  1365. End;
  1366. If hp1 <> nil Then
  1367. p := hp1;
  1368. Continue;
  1369. End
  1370. Else
  1371. If (PPaiProp(p^.OptInfo)^.
  1372. regs[reg32(paicpu(p)^.oper[1].reg)].typ
  1373. in [con_ref,con_noRemoveRef]) and
  1374. (PPaiProp(p^.OptInfo)^.CanBeRemoved) Then
  1375. if (cnt > 0) then
  1376. begin
  1377. hp2 := p;
  1378. Cnt2 := 1;
  1379. While Cnt2 <= Cnt Do
  1380. Begin
  1381. If RegInInstruction(Paicpu(hp2)^.oper[1].reg, p) Then
  1382. PPaiProp(p^.OptInfo)^.CanBeRemoved := False;
  1383. Inc(Cnt2);
  1384. GetNextInstruction(p, p);
  1385. End;
  1386. Continue;
  1387. End
  1388. else
  1389. begin
  1390. { Fix for web bug 972 }
  1391. regCounter := Reg32(Paicpu(p)^.oper[1].reg);
  1392. cnt := PPaiProp(p^.optInfo)^.Regs[regCounter].nrOfMods;
  1393. hp3 := p;
  1394. for cnt2 := 1 to cnt do
  1395. if not(regModifiedByInstruction(regCounter,hp3) and
  1396. not(PPaiProp(hp3^.optInfo)^.canBeRemoved)) then
  1397. getNextInstruction(hp3,hp3)
  1398. else
  1399. break;
  1400. getLastInstruction(p,hp4);
  1401. RestoreRegContentsTo(regCounter,
  1402. PPaiProp(hp4^.optInfo)^.Regs[regCounter],
  1403. p,hp3);
  1404. end;
  1405. End;
  1406. End;
  1407. if not ppaiprop(p^.optinfo)^.canBeRemoved and
  1408. not regInRef(reg32(paicpu(p)^.oper[1].reg),
  1409. paicpu(p)^.oper[0].ref^) then
  1410. removePrevNotUsedLoad(p,reg32(paicpu(p)^.oper[1].reg),false);
  1411. End;
  1412. top_Reg:
  1413. { try to replace the new reg with the old reg }
  1414. if not(PPaiProp(p^.optInfo)^.canBeRemoved) and
  1415. { only remove if we're not storing something in a regvar }
  1416. (paicpu(p)^.oper[1].reg in (usableregs+[R_EDI])) and
  1417. (paicpu(p)^.opcode = A_MOV) and
  1418. getLastInstruction(p,hp4) then
  1419. begin
  1420. case paicpu(p)^.oper[1].typ of
  1421. top_Reg:
  1422. { we only have to start replacing from the instruction after the mov, }
  1423. { but replacereg only starts with getnextinstruction(p,p) }
  1424. if ReplaceReg(asmL,paicpu(p)^.oper[0].reg,
  1425. paicpu(p)^.oper[1].reg,p,
  1426. PPaiProp(hp4^.optInfo)^.Regs[paicpu(p)^.oper[1].reg],false,hp1) then
  1427. begin
  1428. PPaiProp(p^.optInfo)^.canBeRemoved := true;
  1429. allocRegBetween(asmL,paicpu(p)^.oper[0].reg,
  1430. PPaiProp(p^.optInfo)^.regs[paicpu(p)^.oper[0].reg].startMod,
  1431. hp1);
  1432. end
  1433. else
  1434. if reg32(paicpu(p)^.oper[0].reg) <> reg32(paicpu(p)^.oper[1].reg) then
  1435. removePrevNotUsedLoad(p,reg32(paicpu(p)^.oper[1].reg),false);
  1436. end
  1437. end;
  1438. top_symbol,Top_Const:
  1439. Begin
  1440. Case Paicpu(p)^.oper[1].typ Of
  1441. Top_Reg:
  1442. Begin
  1443. regCounter := Reg32(Paicpu(p)^.oper[1].reg);
  1444. If GetLastInstruction(p, hp1) Then
  1445. With PPaiProp(hp1^.OptInfo)^.Regs[regCounter] Do
  1446. if (typ in [con_const,con_noRemoveConst]) and
  1447. (paicpu(startMod)^.opsize >= paicpu(p)^.opsize) and
  1448. opsequal(paicpu(StartMod)^.oper[0],paicpu(p)^.oper[0]) Then
  1449. begin
  1450. PPaiProp(p^.OptInfo)^.CanBeRemoved := True;
  1451. allocRegBetween(asmL,regCounter,startMod,p);
  1452. end
  1453. else
  1454. removePrevNotUsedLoad(p,reg32(paicpu(p)^.oper[1].reg),false);
  1455. End;
  1456. Top_Ref:
  1457. if (paicpu(p)^.oper[0].typ = top_const) and
  1458. getLastInstruction(p,hp1) and
  1459. findRegWithConst(hp1,paicpu(p)^.opsize,paicpu(p)^.oper[0].val,regCounter) then
  1460. begin
  1461. paicpu(p)^.loadreg(0,regCounter);
  1462. allocRegBetween(AsmL,reg32(regCounter),
  1463. PPaiProp(hp1^.optinfo)^.regs[regCounter].startMod,p);
  1464. end;
  1465. End;
  1466. End;
  1467. End;
  1468. End;
  1469. A_STD: If GetLastInstruction(p, hp1) And
  1470. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_Set) Then
  1471. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  1472. End
  1473. End;
  1474. End;
  1475. GetNextInstruction(p, p);
  1476. End;
  1477. End;
  1478. Procedure RemoveInstructs(AsmL: PAasmOutput; First, Last: Pai);
  1479. { Removes the marked instructions and disposes the PPaiProps of the other }
  1480. { instructions }
  1481. Var p, hp1: Pai;
  1482. begin
  1483. p := First;
  1484. While (p <> Last) Do
  1485. Begin
  1486. If (p^.typ = ait_marker) and
  1487. (pai_marker(p)^.kind in [noPropInfoStart,noPropInfoEnd]) then
  1488. begin
  1489. hp1 := pai(p^.next);
  1490. asmL^.remove(p);
  1491. dispose(p,done);
  1492. p := hp1
  1493. end
  1494. else
  1495. {$ifndef noinstremove}
  1496. if assigned(p^.optInfo) and
  1497. PPaiProp(p^.optInfo)^.canBeRemoved then
  1498. begin
  1499. hp1 := pai(p^.next);
  1500. AsmL^.Remove(p);
  1501. Dispose(p, Done);
  1502. p := hp1;
  1503. End
  1504. Else
  1505. {$endif noinstremove}
  1506. Begin
  1507. p^.OptInfo := nil;
  1508. p := pai(p^.next);;
  1509. End;
  1510. End;
  1511. FreeMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4))
  1512. End;
  1513. Procedure CSE(AsmL: PAasmOutput; First, Last: Pai);
  1514. Begin
  1515. DoCSE(AsmL, First, Last);
  1516. RemoveInstructs(AsmL, First, Last);
  1517. End;
  1518. End.
  1519. {
  1520. $Log$
  1521. Revision 1.13 2000-09-29 23:14:45 jonas
  1522. * search much further back for CSE sequences (non-conflicting stores are
  1523. now passed)
  1524. * remove more unnecessary loads of registers (especially the self pointer)
  1525. Revision 1.12 2000/09/26 11:49:41 jonas
  1526. * writes to register variables and to the self pointer now also count as
  1527. memore writes
  1528. Revision 1.11 2000/09/25 09:50:29 jonas
  1529. - removed TP conditional code
  1530. Revision 1.10 2000/09/24 15:06:14 peter
  1531. * use defines.inc
  1532. Revision 1.9 2000/09/22 15:01:59 jonas
  1533. * fixed some bugs in the previous improvements: in some cases, esi was
  1534. still being replaced before a conditional jump (the code that
  1535. detected conditional jumps sometimes skipped over them)
  1536. Revision 1.8 2000/09/20 15:00:58 jonas
  1537. + much improved CSE: the CSE now searches further back for sequences it
  1538. can reuse. After I've also implemented register renaming, the effect
  1539. should be even better (afaik web bug 1088 will then even be optimized
  1540. properly). I don't know about the slow down factor this adds. Maybe
  1541. a new optimization level should be introduced?
  1542. Revision 1.7 2000/08/25 19:40:45 jonas
  1543. * refined previous fix a bit, some instructions weren't being removed
  1544. while they could (merged from fixes branch)
  1545. * made checksequence a bit faster
  1546. Revision 1.6 2000/08/23 12:55:10 jonas
  1547. * fix for web bug 1112 and a bit of clean up in csopt386 (merged from
  1548. fixes branch)
  1549. Revision 1.5 2000/08/04 20:08:03 jonas
  1550. * improved detection of range of instructions which use a register
  1551. (merged from fixes branch)
  1552. Revision 1.4 2000/07/21 15:19:54 jonas
  1553. * daopt386: changes to getnextinstruction/getlastinstruction so they
  1554. ignore labels who have is_addr set
  1555. + daopt386/csopt386: remove loads of registers which are overwritten
  1556. before their contents are used (especially usefull for removing superfluous
  1557. maybe_loadesi outputs and push/pops transformed by below optimization
  1558. + popt386: transform pop/pop/pop/.../push/push/push to sequences of
  1559. 'movl x(%esp),%reg' (only active when compiling a go32v2 compiler
  1560. currently because I don't know whether it's safe to do this under Win32/
  1561. Linux (because of problems we had when using esp as frame pointer on
  1562. those os'es)
  1563. Revision 1.3 2000/07/14 05:11:48 michael
  1564. + Patch to 1.1
  1565. Revision 1.2 2000/07/13 11:32:39 michael
  1566. + removed logs
  1567. }