csopt386.pas 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. {
  2. $Id$
  3. Copyright (c) 1997-98 by Jonas Maebe
  4. This unit contains the common subexpression elimination procedure.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. Unit CSOpt386;
  19. Interface
  20. Uses aasm;
  21. {Procedure CSOpt386(First, Last: Pai);}
  22. Procedure CSE(AsmL: PAasmOutput; First, Last: Pai);
  23. Implementation
  24. Uses
  25. CObjects, verbose, hcodegen, globals,cpubase,cpuasm,DAOpt386;
  26. {
  27. Function PaiInSequence(P: Pai; Const Seq: TContent): Boolean;
  28. Var P1: Pai;
  29. Counter: Byte;
  30. TmpResult: Boolean;
  31. Begin
  32. TmpResult := False;
  33. P1 := Seq.StartMod;
  34. Counter := 1;
  35. While Not(TmpResult) And
  36. (Counter <= Seq.NrOfMods) Do
  37. Begin
  38. If (P = P1) Then TmpResult := True;
  39. Inc(Counter);
  40. p1 := Pai(p1^.Next);
  41. End;
  42. PaiInSequence := TmpResult;
  43. End;
  44. }
  45. Function CheckSequence(p: Pai; Reg: TRegister; Var Found: Longint; Var RegInfo: TRegInfo): Boolean;
  46. {checks whether the current instruction sequence (starting with p) and the
  47. one between StartMod and EndMod of Reg are the same. If so, the number of
  48. instructions that match is stored in Found and true is returned, otherwise
  49. Found holds the number of instructions between StartMod and EndMod and false
  50. is returned}
  51. Var hp2, hp3{, EndMod}: Pai;
  52. PrevNonRemovablePai: Pai;
  53. Cnt, OldNrOfMods: Longint;
  54. OrgRegInfo, HighRegInfo: TRegInfo;
  55. HighFound, OrgRegFound: Byte;
  56. RegCounter: TRegister;
  57. OrgRegResult: Boolean;
  58. TmpResult: Boolean;
  59. TmpState: Byte;
  60. Begin {CheckSequence}
  61. Reg := Reg32(Reg);
  62. TmpResult := False;
  63. FillChar(OrgRegInfo, SizeOf(OrgRegInfo), 0);
  64. OrgRegFound := 0;
  65. HighFound := 0;
  66. OrgRegResult := False;
  67. RegCounter := R_EAX;
  68. GetLastInstruction(p, PrevNonRemovablePai);
  69. While (RegCounter <= R_EDI) And
  70. (PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].Typ <> Con_Ref) Do
  71. Inc(RegCounter);
  72. While (RegCounter <= R_EDI) Do
  73. Begin
  74. FillChar(RegInfo, SizeOf(RegInfo), 0);
  75. RegInfo.NewRegsEncountered := [procinfo^.FramePointer, R_ESP];
  76. RegInfo.OldRegsEncountered := RegInfo.NewRegsEncountered;
  77. RegInfo.New2OldReg[procinfo^.FramePointer] := procinfo^.FramePointer;
  78. RegInfo.New2OldReg[R_ESP] := R_ESP;
  79. Found := 0;
  80. hp2 := PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].StartMod;
  81. If (PrevNonRemovablePai <> PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].StartMod)
  82. Then OldNrOfMods := PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].NrOfMods
  83. Else OldNrOfMods := 1;
  84. hp3 := p;
  85. While (Found <> OldNrOfMods) And
  86. { old new }
  87. InstructionsEquivalent(hp2, hp3, RegInfo) Do
  88. Begin
  89. GetNextInstruction(hp2, hp2);
  90. GetNextInstruction(hp3, hp3);
  91. Inc(Found)
  92. End;
  93. If (Found <> OldNrOfMods) Then
  94. Begin
  95. TmpResult := False;
  96. If (found > 0) then
  97. {this is correct because we only need to turn off the CanBeRemoved flag
  98. when an instruction has already been processed by CheckSequence
  99. (otherwise CanBeRemoved can't be true and thus can't have to be turned off).
  100. If it has already been processed by CheckSequence and flagged to be
  101. removed, it means that it has been checked against a previous sequence
  102. and that it was equal (otherwise CheckSequence would have returned false
  103. and the instruction wouldn't have been removed). If this "If found > 0"
  104. check is left out, incorrect optimizations are performed.}
  105. Found := PPaiProp(Pai(p)^.OptInfo)^.Regs[Reg].NrOfMods
  106. End
  107. Else TmpResult := True;
  108. If TmpResult And
  109. (Found > HighFound)
  110. Then
  111. Begin
  112. HighFound := Found;
  113. HighRegInfo := RegInfo;
  114. End;
  115. If (RegCounter = Reg) Then
  116. Begin
  117. OrgRegFound := Found;
  118. OrgRegResult := TmpResult;
  119. OrgRegInfo := RegInfo
  120. End;
  121. Repeat
  122. Inc(RegCounter);
  123. Until (RegCounter > R_EDI) or
  124. ((PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].Typ = Con_Ref) {And
  125. ((Regcounter = Reg) Or
  126. Not(PaiInSequence(p, PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter]))) }
  127. );
  128. End;
  129. If (HighFound > 0) And
  130. (Not(OrgRegResult) Or
  131. (HighFound > OrgRegFound))
  132. Then
  133. Begin
  134. {$ifndef fpc}
  135. TmpResult := True;
  136. {$else fpc}
  137. CheckSequence := True;
  138. {$endif fpc}
  139. RegInfo := HighRegInfo;
  140. Found := HighFound
  141. End
  142. Else
  143. Begin
  144. {$ifndef fpc}
  145. TmpResult := OrgRegResult;
  146. {$else fpc}
  147. CheckSequence := OrgRegResult;
  148. {$endif fpc}
  149. Found := OrgRegFound;
  150. RegInfo := OrgRegInfo;
  151. End;
  152. { sometimes, registers in RegsLoadedForRef (which normally aren't/shouldn't }
  153. { be used anymore after the sequence, are still used nevertheless (when }
  154. { range checking is on for instance, because this is not "normal" generated }
  155. { code, but more or less manually inserted) }
  156. {$ifndef fpc}
  157. If TmpResult Then
  158. {$else fpc}
  159. If CheckSequence And (Found > 0) Then
  160. {$endif fpc}
  161. For RegCounter := R_EAX to R_EDI Do
  162. If (RegCounter in RegInfo.RegsLoadedForRef) And
  163. (RegInfo.New2OldReg[RegCounter] <> RegCounter) Then
  164. Begin
  165. OldNrOfMods := PPaiProp(PrevNonRemovablePai^.OptInfo)^.
  166. Regs[RegInfo.New2OldReg[RegCounter]].NrOfMods;
  167. hp2 := p;
  168. For Cnt := 1 to Pred(OldNrOfMods) Do
  169. GetNextInstruction(hp2, hp2);
  170. { hp2 now containts the last instruction of the sequence }
  171. { get the writestate at this point of the register in TmpState }
  172. TmpState := PPaiProp(hp2^.OptInfo)^.Regs[RegCounter].WState;
  173. { hp3 := first instruction after the sequence }
  174. GetNextInstruction(hp2, hp2);
  175. { now, even though reg is in RegsLoadedForRef, sometimes it's still used }
  176. { afterwards. It is not if either it is not in usedregs anymore after the }
  177. { sequence, or if it is loaded with a new value right after the sequence }
  178. If (TmpState = PPaiProp(hp2^.OptInfo)^.Regs[RegCounter].WState) And
  179. (RegCounter in PPaiProp(hp2^.OptInfo)^.UsedRegs) Then
  180. { it is still used, so remove it from RegsLoadedForRef }
  181. Begin
  182. {$ifdef regrefdebug}
  183. hp3 := new(pai_asm_comment,init(strpnew(att_reg2str[regcounter]+
  184. ' removed from regsloadedforref')));
  185. hp3^.fileinfo := hp2^.fileinfo;
  186. hp3^.next := hp2^.next;
  187. hp3^.previous := hp2;
  188. hp2^.next := hp3;
  189. If assigned(hp3^.next) then
  190. Pai(hp3^.next)^.previous := hp3;
  191. {$endif regrefdebug}
  192. Exclude(RegInfo.RegsLoadedForRef,RegCounter);
  193. End;
  194. End;
  195. {$ifndef fpc}
  196. CheckSequence := TmpResult;
  197. {$endif fpc}
  198. End; {CheckSequence}
  199. Procedure AllocRegBetween(AsmL: PAasmOutput; Reg: TRegister; p1, p2: Pai);
  200. { allocates register Reg between (and including) instructions p1 and p2 }
  201. { the type of p1 and p2 must not be in SkipInstr }
  202. var hp: pai;
  203. Begin
  204. If not(assigned(p1)) Then
  205. { this happens with registers which are loaded implicitely, outside the }
  206. { current block (e.g. esi with self) }
  207. exit;
  208. Repeat
  209. If Assigned(p1^.OptInfo) Then
  210. Include(PPaiProp(p1^.OptInfo)^.UsedRegs,Reg);
  211. p1 := Pai(p1^.next);
  212. Repeat
  213. While (p1^.typ in (SkipInstr-[ait_regalloc])) Do
  214. p1 := Pai(p1^.next);
  215. { remove all allocation/deallocation info about the register in between }
  216. If (p1^.typ = ait_regalloc) Then
  217. If (PaiRegAlloc(p1)^.Reg = Reg) Then
  218. Begin
  219. hp := Pai(p1^.Next);
  220. AsmL^.Remove(p1);
  221. Dispose(p1, Done);
  222. p1 := hp;
  223. End
  224. Else p1 := Pai(p1^.next);
  225. Until Not(p1^.typ in SkipInstr);
  226. Until p1 = p2;
  227. End;
  228. {$ifdef alignreg}
  229. Procedure SetAlignReg(p: Pai);
  230. Const alignSearch = 12;
  231. var regsUsable: TRegSet;
  232. prevInstrCount, nextInstrCount: Longint;
  233. prevState, nextWState,nextRState: Array[R_EAX..R_EDI] of byte;
  234. regCounter, lastRemoved: TRegister;
  235. prev, next: Pai;
  236. {$ifdef alignregdebug}
  237. temp: Pai;
  238. {$endif alignregdebug}
  239. begin
  240. regsUsable := [R_EAX,R_ECX,R_EDX,R_EBX,{R_ESP,R_EBP,}R_ESI,R_EDI];
  241. for regCounter := R_EAX to R_EDI do
  242. begin
  243. prevState[regCounter] := PPaiProp(p^.optInfo)^.Regs[regCounter].wState;
  244. nextWState[regCounter] := PPaiProp(p^.optInfo)^.Regs[regCounter].wState;
  245. nextRState[regCounter] := PPaiProp(p^.optInfo)^.Regs[regCounter].rState;
  246. end;
  247. getLastInstruction(p,prev);
  248. getNextInstruction(p,next);
  249. lastRemoved := pai_align(p)^.reg;
  250. nextInstrCount := 0;
  251. prevInstrCount := 0;
  252. while ((assigned(prev) and
  253. assigned(prev^.optInfo) and
  254. (prevInstrCount < alignSearch)) or
  255. (assigned(next) and
  256. assigned(next^.optInfo) and
  257. (nextInstrCount < alignSearch))) And
  258. (regsUsable <> []) do
  259. begin
  260. {$ifdef alignregdebug}
  261. if assigned(prev) then
  262. begin
  263. temp := new(pai_asm_comment,init(strpnew('got here')));
  264. temp^.next := prev^.next;
  265. temp^.previous := prev;
  266. prev^.next := temp;
  267. if assigned(temp^.next) then
  268. temp^.next^.previous := temp;
  269. end;
  270. {$endif alignregdebug}
  271. if assigned(prev) and assigned(prev^.optinfo) and
  272. (prevInstrCount < alignSearch) then
  273. begin
  274. if (prev^.typ = ait_instruction) And
  275. (insProp[PaiCpu(prev)^.opcode].ch[1] <> Ch_ALL) and
  276. (PaiCpu(prev)^.opcode <> A_JMP) then
  277. begin
  278. inc(prevInstrCount);
  279. for regCounter := R_EAX to R_EDI do
  280. begin
  281. if (regCounter in regsUsable) And
  282. (PPaiProp(prev^.optInfo)^.Regs[regCounter].wState <>
  283. prevState[regCounter]) then
  284. begin
  285. lastRemoved := regCounter;
  286. exclude(regsUsable,regCounter);
  287. {$ifdef alignregdebug}
  288. temp := new(pai_asm_comment,init(strpnew(
  289. att_reg2str[regCounter]+' removed')));
  290. temp^.next := prev^.next;
  291. temp^.previous := prev;
  292. prev^.next := temp;
  293. if assigned(temp^.next) then
  294. temp^.next^.previous := temp;
  295. if regsUsable = [] then
  296. begin
  297. temp := new(pai_asm_comment,init(strpnew(
  298. 'regsUsable empty here')));
  299. temp^.next := prev^.next;
  300. temp^.previous := prev;
  301. prev^.next := temp;
  302. if assigned(temp^.next) then
  303. temp^.next^.previous := temp;
  304. end;
  305. {$endif alignregdebug}
  306. end;
  307. prevState[regCounter] :=
  308. PPaiProp(prev^.optInfo)^.Regs[regCounter].wState;
  309. end;
  310. getLastInstruction(prev,prev);
  311. end
  312. else
  313. If GetLastInstruction(prev,prev) and
  314. assigned(prev^.optinfo) then
  315. for regCounter := R_EAX to R_EDI do
  316. prevState[regCounter] :=
  317. PPaiProp(prev^.optInfo)^.Regs[regCounter].wState
  318. end;
  319. if assigned(next) and assigned(next^.optInfo) and
  320. (nextInstrCount < alignSearch) then
  321. begin
  322. if (next^.typ = ait_instruction) and
  323. (insProp[PaiCpu(next)^.opcode].ch[1] <> Ch_ALL) and
  324. (PaiCpu(next)^.opcode <> A_JMP) then
  325. begin
  326. inc(nextInstrCount);
  327. for regCounter := R_EAX to R_EDI do
  328. begin
  329. if (regCounter in regsUsable) And
  330. ((PPaiProp(next^.optInfo)^.Regs[regCounter].wState <>
  331. nextWState[regCounter]) or
  332. (PPaiProp(next^.optInfo)^.Regs[regCounter].rState <>
  333. nextRState[regCounter])) Then
  334. begin
  335. lastRemoved := regCounter;
  336. exclude(regsUsable,regCounter);
  337. {$ifdef alignregdebug}
  338. temp := new(pai_asm_comment,init(strpnew(
  339. att_reg2str[regCounter]+' removed')));
  340. temp^.next := next^.next;
  341. temp^.previous := next;
  342. next^.next := temp;
  343. if assigned(temp^.next) then
  344. temp^.next^.previous := temp;
  345. if regsUsable = [] then
  346. begin
  347. temp := new(pai_asm_comment,init(strpnew(
  348. 'regsUsable empty here')));
  349. temp^.next := next^.next;
  350. temp^.previous := next;
  351. next^.next := temp;
  352. if assigned(temp^.next) then
  353. temp^.next^.previous := temp;
  354. end;
  355. {$endif alignregdebug}
  356. end;
  357. nextWState[regCounter] :=
  358. PPaiProp(next^.optInfo)^.Regs[regCounter].wState;
  359. nextRState[regCounter] :=
  360. PPaiProp(next^.optInfo)^.Regs[regCounter].rState;
  361. end
  362. end
  363. else
  364. for regCounter := R_EAX to R_EDI do
  365. begin
  366. nextWState[regCounter] :=
  367. PPaiProp(next^.optInfo)^.Regs[regCounter].wState;
  368. nextRState[regCounter] :=
  369. PPaiProp(next^.optInfo)^.Regs[regCounter].rState;
  370. end;
  371. getNextInstruction(next,next);
  372. end;
  373. end;
  374. if regsUsable <> [] then
  375. for regCounter := R_EAX to R_EDI do
  376. if regCounter in regsUsable then
  377. begin
  378. lastRemoved := regCounter;
  379. break
  380. end;
  381. {$ifdef alignregdebug}
  382. next := new(pai_asm_comment,init(strpnew(att_reg2str[lastRemoved]+
  383. ' chosen as alignment register')));
  384. next^.next := p^.next;
  385. next^.previous := p;
  386. p^.next := next;
  387. if assigned(next^.next) then
  388. next^.next^.previous := next;
  389. {$endif alignregdebug}
  390. pai_align(p)^.reg := lastRemoved;
  391. End;
  392. {$endif alignreg}
  393. {$ifdef replacereg}
  394. function FindRegDealloc(reg: tregister; p: pai): boolean;
  395. begin
  396. findregdealloc := false;
  397. while assigned(p^.previous) and
  398. ((Pai(p^.previous)^.typ in (skipinstr+[ait_align])) or
  399. ((Pai(p^.previous)^.typ = ait_label) and
  400. not(Pai_Label(p^.previous)^.l^.is_used))) do
  401. begin
  402. p := pai(p^.previous);
  403. if (p^.typ = ait_regalloc) and
  404. (pairegalloc(p)^.reg = reg) then
  405. begin
  406. findregdealloc := not(pairegalloc(p)^.allocation);
  407. break;
  408. end;
  409. end
  410. end;
  411. function regLoadedWithNewValue(reg: tregister; hp: pai): boolean;
  412. var p: paicpu;
  413. begin
  414. p := paicpu(hp);
  415. regLoadedWithNewValue :=
  416. assigned(hp) and
  417. ((hp^.typ = ait_instruction) and
  418. (((p^.opcode = A_MOV) or
  419. (p^.opcode = A_MOVZX) or
  420. (p^.opcode = A_MOVSX) or
  421. (p^.opcode = A_LEA)) and
  422. (p^.oper[1].typ = top_reg) and
  423. (p^.oper[1].reg = reg) {and
  424. (not(p^.oper[0].typ = top_ref) or
  425. not RegInRef(p^.oper[1].reg,p^.oper[0].ref^))}) or
  426. ((p^.opcode = A_POP) and
  427. (p^.oper[0].reg = reg))) {or
  428. findRegDealloc(reg,hp)};
  429. end;
  430. Procedure RestoreRegContentsTo(reg: TRegister; const c: TContent; p: pai);
  431. var
  432. {$ifdef replaceregdebug}
  433. hp: pai;
  434. {$endif replaceregdebug}
  435. tmpState: byte;
  436. begin
  437. {$ifdef replaceregdebug}
  438. hp := new(pai_asm_comment,init(strpnew(
  439. 'restored '+att_reg2str[reg]+' with data from here...')));
  440. hp^.next := p;
  441. hp^.previous := p^.previous;
  442. p^.previous := hp;
  443. if assigned(hp^.previous) then
  444. hp^.previous^.next := hp;
  445. {$endif replaceregdebug}
  446. tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
  447. PPaiProp(p^.optInfo)^.Regs[reg] := c;
  448. while getNextInstruction(p,p) and
  449. (PPaiProp(p^.optInfo)^.Regs[reg].wState = tmpState) do
  450. PPaiProp(p^.optInfo)^.Regs[reg] := c;
  451. {$ifdef replaceregdebug}
  452. if assigned(p) then
  453. begin
  454. hp := new(pai_asm_comment,init(strpnew(
  455. 'restored '+att_reg2str[reg]+' till here...')));
  456. hp^.next := p;
  457. hp^.previous := p^.previous;
  458. p^.previous := hp;
  459. if assigned(hp^.previous) then
  460. hp^.previous^.next := hp;
  461. end;
  462. {$endif replaceregdebug}
  463. end;
  464. Procedure ClearRegContentsFrom(reg: TRegister; p: pai);
  465. var hp: pai;
  466. tmpState: byte;
  467. begin
  468. tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
  469. PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
  470. while getNextInstruction(p,p) and
  471. (PPaiProp(p^.optInfo)^.Regs[reg].wState = tmpState) do
  472. PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
  473. {$ifdef replaceregdebug}
  474. if assigned(p) then
  475. begin
  476. hp := new(pai_asm_comment,init(strpnew(
  477. 'cleared '+att_reg2str[reg]+' till here...')));
  478. hp^.next := p;
  479. hp^.previous := p^.previous;
  480. p^.previous := hp;
  481. if assigned(hp^.previous) then
  482. hp^.previous^.next := hp;
  483. end;
  484. {$endif replaceregdebug}
  485. end;
  486. function NoHardCodedRegs(p: paicpu): boolean;
  487. var chCount: byte;
  488. begin
  489. NoHardCodedRegs := true;
  490. with InsProp[p^.opcode] do
  491. for chCount := 1 to MaxCh do
  492. if Ch[chCount] in ([Ch_REAX..Ch_MEDI]-[Ch_RESP,Ch_WESP,Ch_RWESP]) then
  493. begin
  494. NoHardCodedRegs := false;
  495. break
  496. end;
  497. end;
  498. Procedure ChangeReg(var Reg: TRegister; orgReg, newReg: TRegister);
  499. begin
  500. if reg = newReg then
  501. reg := orgReg
  502. else if reg = regtoreg8(newReg) then
  503. reg := regtoreg8(orgReg)
  504. else if reg = regtoreg16(newReg) then
  505. reg := regtoreg16(orgReg);
  506. end;
  507. Procedure DoReplaceReg(orgReg,newReg: tregister; hp: paicpu);
  508. var opCount: byte;
  509. begin
  510. for opCount := 0 to 2 do
  511. with hp^.oper[opCount] Do
  512. case typ of
  513. top_reg: ChangeReg(reg,orgReg,newReg);
  514. top_ref:
  515. begin
  516. ChangeReg(ref^.base,orgReg,newReg);
  517. ChangeReg(ref^.index,orgReg,newReg);
  518. end;
  519. end;
  520. end;
  521. function RegSizesOK(oldReg,newReg: TRegister; p: paicpu): boolean;
  522. { oldreg and newreg must be 32bit components }
  523. var opCount: byte;
  524. begin
  525. RegSizesOK := true;
  526. if not(IsGP32reg(oldReg) and IsGP32Reg(newReg)) then
  527. begin
  528. for opCount := 0 to 2 do
  529. if (p^.oper[opCount].typ = top_reg) and
  530. (p^.oper[opCount].reg in [R_AL..R_DH]) then
  531. begin
  532. RegSizesOK := false;
  533. break
  534. end
  535. end;
  536. end;
  537. function RegReadByInstruction(reg: TRegister; hp: pai): boolean;
  538. { assumes p doesn't modify registers implicitely (like div) }
  539. var p: paicpu;
  540. opCount: byte;
  541. begin
  542. RegReadByInstruction := false;
  543. p := paicpu(hp);
  544. if hp^.typ <> ait_instruction then
  545. exit;
  546. for opCount := 0 to 2 do
  547. if (p^.oper[opCount].typ = top_ref) and
  548. RegInRef(reg,p^.oper[opCount].ref^) then
  549. begin
  550. RegReadByInstruction := true;
  551. exit
  552. end;
  553. for opCount := 1 to MaxCh do
  554. case InsProp[p^.opcode].Ch[opCount] of
  555. Ch_RWOp1,Ch_ROp1{$ifdef arithopt},Ch_MOp1{$endif}:
  556. if (p^.oper[0].typ = top_reg) and
  557. (p^.oper[0].reg = reg) then
  558. begin
  559. RegReadByInstruction := true;
  560. exit
  561. end;
  562. Ch_RWOp2,Ch_ROp2{$ifdef arithopt},Ch_MOp2{$endif}:
  563. if (p^.oper[1].typ = top_reg) and
  564. (p^.oper[1].reg = reg) then
  565. begin
  566. RegReadByInstruction := true;
  567. exit
  568. end;
  569. Ch_RWOp3,Ch_ROp3{$ifdef arithopt},Ch_MOp3{$endif}:
  570. if (p^.oper[2].typ = top_reg) and
  571. (p^.oper[2].reg = reg) then
  572. begin
  573. RegReadByInstruction := true;
  574. exit
  575. end;
  576. end;
  577. end;
  578. procedure DoReplaceReadReg(orgReg,newReg: tregister; p: paicpu);
  579. var opCount: byte;
  580. begin
  581. for opCount := 0 to 2 do
  582. if p^.oper[opCount].typ = top_ref then
  583. begin
  584. ChangeReg(p^.oper[opCount].ref^.base,orgReg,newReg);
  585. ChangeReg(p^.oper[opCount].ref^.index,orgReg,newReg);
  586. end;
  587. for opCount := 1 to MaxCh do
  588. case InsProp[p^.opcode].Ch[opCount] of
  589. Ch_RWOp1,Ch_ROp1{$ifdef arithopt},Ch_MOp1{$endif}:
  590. if p^.oper[0].typ = top_reg then
  591. ChangeReg(p^.oper[0].reg,orgReg,newReg);
  592. Ch_RWOp2,Ch_ROp2{$ifdef arithopt},Ch_MOp2{$endif}:
  593. if p^.oper[1].typ = top_reg then
  594. ChangeReg(p^.oper[1].reg,orgReg,newReg);
  595. Ch_RWOp3,Ch_ROp3{$ifdef arithopt},Ch_MOp3{$endif}:
  596. if p^.oper[2].typ = top_reg then
  597. ChangeReg(p^.oper[2].reg,orgReg,newReg);
  598. end;
  599. end;
  600. function ReplaceReg(orgReg, newReg: TRegister; p: pai;
  601. const c: TContent): Boolean;
  602. { Tries to replace orgreg with newreg in all instructions coming after p }
  603. { until orgreg gets loaded with a new value. Returns true if successful, }
  604. { false otherwise. If successful, the contents of newReg are set to c, }
  605. { which should hold the contents of newReg before the current sequence }
  606. { started }
  607. var endP, hp: Pai;
  608. sequenceEnd, tmpResult, newRegModified, orgRegRead: Boolean;
  609. begin
  610. ReplaceReg := false;
  611. tmpResult := true;
  612. sequenceEnd := false;
  613. newRegModified := false;
  614. orgRegRead := false;
  615. endP := pai(p^.previous);
  616. { skip over the instructions that will be removed }
  617. while getNextInstruction(endP,hp) and
  618. assigned(hp) and
  619. PPaiProp(hp^.optInfo)^.canBeRemoved do
  620. endP := hp;
  621. while tmpResult and not sequenceEnd do
  622. begin
  623. tmpResult :=
  624. getNextInstruction(endP,endP);
  625. If tmpResult and
  626. { don't take into account instructions that will be removed }
  627. Not (PPaiProp(hp^.optInfo)^.canBeRemoved) then
  628. begin
  629. sequenceEnd :=
  630. RegLoadedWithNewValue(newReg,paicpu(endP)) or
  631. (GetNextInstruction(endp,hp) and
  632. FindRegDealloc(newReg,hp));
  633. newRegModified :=
  634. newRegModified or
  635. (not(sequenceEnd) and
  636. RegModifiedByInstruction(newReg,endP));
  637. orgRegRead := newRegModified and RegReadByInstruction(orgReg,endP);
  638. sequenceEnd := SequenceEnd and not(newRegModified and orgRegRead);
  639. tmpResult :=
  640. not(newRegModified and orgRegRead) and
  641. (endP^.typ = ait_instruction) and
  642. not(paicpu(endP)^.is_jmp) and
  643. NoHardCodedRegs(paicpu(endP)) and
  644. RegSizesOk(orgReg,newReg,paicpu(endP)) and
  645. not RegModifiedByInstruction(orgReg,endP);
  646. end;
  647. end;
  648. sequenceEnd := sequenceEnd and
  649. not(newRegModified and
  650. (orgReg in PPaiProp(endP^.optInfo)^.usedRegs) and
  651. not(RegLoadedWithNewValue(orgReg,paicpu(endP))));
  652. if SequenceEnd then
  653. begin
  654. {$ifdef replaceregdebug}
  655. hp := new(pai_asm_comment,init(strpnew(
  656. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  657. ' from here...')));
  658. hp^.next := p;
  659. hp^.previous := p^.previous;
  660. p^.previous := hp;
  661. if assigned(hp^.previous) then
  662. hp^.previous^.next := hp;
  663. hp := new(pai_asm_comment,init(strpnew(
  664. 'replaced '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  665. ' till here')));
  666. hp^.next := endp^.next;
  667. hp^.previous := endp;
  668. endp^.next := hp;
  669. if assigned(hp^.next) then
  670. hp^.next^.previous := hp;
  671. {$endif replaceregdebug}
  672. ReplaceReg := true;
  673. hp := p;
  674. while hp <> endP do
  675. begin
  676. if not(PPaiProp(hp^.optInfo)^.canBeRemoved) and
  677. (hp^.typ = ait_instruction) then
  678. DoReplaceReg(orgReg,newReg,paicpu(hp));
  679. GetNextInstruction(hp,hp)
  680. end;
  681. if assigned(endp) and (endp^.typ = ait_instruction) then
  682. DoReplaceReadReg(orgReg,newReg,paicpu(endP));
  683. { the replacing stops either at the moment that }
  684. { a) the newreg gets loaded with a new value (one not depending on the }
  685. { current value of newreg) }
  686. { b) newreg is completely replaced in this sequence and it's current value }
  687. { isn't used anymore }
  688. { In case b, the newreg was completely replaced by oldreg, so it's contents }
  689. { are unchanged compared the start of this sequence, so restore them }
  690. if (p <> endp) or
  691. not RegModifiedByInstruction(newReg,endP) then
  692. RestoreRegContentsTo(newReg, c ,p);
  693. { In both case a and b, it is possible that the new register was modified }
  694. { (e.g. an add/sub), so if it was replaced by oldreg in that instruction, }
  695. { oldreg's contents have been changed. To take this into account, we simply }
  696. { set the contents of orgreg to "unknown" after this sequence }
  697. if newRegModified then
  698. ClearRegContentsFrom(orgReg,p);
  699. end
  700. {$ifdef replaceregdebug}
  701. else
  702. begin
  703. hp := new(pai_asm_comment,init(strpnew(
  704. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  705. ' from here...')));
  706. hp^.previous := p^.previous;
  707. hp^.next := p;
  708. p^.previous := hp;
  709. if assigned(hp^.previous) then
  710. hp^.previous^.next := hp;
  711. hp := new(pai_asm_comment,init(strpnew(
  712. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  713. ' failed here')));
  714. hp^.next := endp^.next;
  715. hp^.previous := endp;
  716. endp^.next := hp;
  717. if assigned(hp^.next) then
  718. hp^.next^.previous := hp;
  719. end;
  720. {$endif replaceregdebug}
  721. End;
  722. {$endif replacereg}
  723. Procedure DoCSE(AsmL: PAasmOutput; First, Last: Pai);
  724. {marks the instructions that can be removed by RemoveInstructs. They're not
  725. removed immediately because sometimes an instruction needs to be checked in
  726. two different sequences}
  727. Var Cnt, Cnt2: Longint;
  728. p, hp1, hp2: Pai;
  729. hp3, hp4: Pai;
  730. {$ifdef csdebug}
  731. hp5: pai;
  732. {$endif csdebug}
  733. RegInfo: TRegInfo;
  734. RegCounter: TRegister;
  735. TmpState: Byte;
  736. Begin
  737. p := First;
  738. SkipHead(p);
  739. First := p;
  740. While (p <> Last) Do
  741. Begin
  742. Case p^.typ Of
  743. {$ifdef alignreg}
  744. ait_align:
  745. SetAlignReg(p);
  746. {$endif alignreg}
  747. ait_instruction:
  748. Begin
  749. Case Paicpu(p)^.opcode Of
  750. A_CLD: If GetLastInstruction(p, hp1) And
  751. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_NotSet) Then
  752. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  753. A_MOV, A_MOVZX, A_MOVSX:
  754. Begin
  755. Case Paicpu(p)^.oper[0].typ Of
  756. Top_Ref:
  757. Begin {destination is always a register in this case}
  758. With PPaiProp(p^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)] Do
  759. Begin
  760. If (p = StartMod) And
  761. GetLastInstruction (p, hp1) And
  762. (hp1^.typ <> ait_marker)
  763. Then
  764. {so we don't try to check a sequence when p is the first instruction of the block}
  765. If CheckSequence(p, Paicpu(p)^.oper[1].reg, Cnt, RegInfo) And
  766. (Cnt > 0) Then
  767. Begin
  768. hp1 := nil;
  769. { although it's perfectly ok to remove an instruction which doesn't contain }
  770. { the register that we've just checked (CheckSequence takes care of that), }
  771. { the sequence containing this other register should also be completely }
  772. { checked and removed, otherwise we may get situations like this: }
  773. { }
  774. { movl 12(%ebp), %edx movl 12(%ebp), %edx }
  775. { movl 16(%ebp), %eax movl 16(%ebp), %eax }
  776. { movl 8(%edx), %edx movl 8(%edx), %edx }
  777. { movl (%eax), eax movl (%eax), eax }
  778. { cmpl %eax, %edx cmpl %eax, %edx }
  779. { jnz l123 getting converted to jnz l123 }
  780. { movl 12(%ebp), %edx movl 4(%eax), eax }
  781. { movl 16(%ebp), %eax }
  782. { movl 8(%edx), %edx }
  783. { movl 4(%eax), eax }
  784. hp2 := p;
  785. Cnt2 := 1;
  786. While Cnt2 <= Cnt Do
  787. Begin
  788. If (hp1 = nil) And
  789. Not(RegInInstruction(Paicpu(hp2)^.oper[1].reg, p) Or
  790. RegInInstruction(Reg32(Paicpu(hp2)^.oper[1].reg), p)) And
  791. Not((p^.typ = ait_instruction) And
  792. (paicpu(p)^.OpCode = A_MOV) And
  793. (paicpu(p)^.Oper[0].typ = top_ref) And
  794. (PPaiProp(p^.OptInfo)^.Regs[Reg32(paicpu(p)^.Oper[1].reg)].NrOfMods
  795. <= (Cnt - Cnt2 + 1)))
  796. Then hp1 := p;
  797. {$ifndef noremove}
  798. PPaiProp(p^.OptInfo)^.CanBeRemoved := True;
  799. {$endif noremove}
  800. Inc(Cnt2);
  801. GetNextInstruction(p, p);
  802. End;
  803. hp3 := New(Pai_Marker,Init(NoPropInfoStart));
  804. InsertLLItem(AsmL, Pai(hp2^.Previous), hp2, hp3);
  805. {hp4 is used to get the contents of the registers before the sequence}
  806. GetLastInstruction(hp2, hp4);
  807. {$IfDef CSDebug}
  808. For RegCounter := R_EAX To R_EDI Do
  809. If (RegCounter in RegInfo.RegsLoadedForRef) Then
  810. Begin
  811. hp5 := new(pai_asm_comment,init(strpnew('New: '+att_reg2str[RegCounter]+', Old: '+
  812. att_reg2str[RegInfo.New2OldReg[RegCounter]])));
  813. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp5);
  814. End;
  815. {$EndIf CSDebug}
  816. { If some registers were different in the old and the new sequence, move }
  817. { the contents of those old registers to the new ones }
  818. For RegCounter := R_EAX To R_EDI Do
  819. If Not(RegCounter in [R_ESP,procinfo^.framepointer]) And
  820. (RegInfo.New2OldReg[RegCounter] <> R_NO) Then
  821. Begin
  822. AllocRegBetween(AsmL,RegInfo.New2OldReg[RegCounter],
  823. PPaiProp(hp4^.OptInfo)^.Regs[RegInfo.New2OldReg[RegCounter]].StartMod,hp2);
  824. If Not(RegCounter In RegInfo.RegsLoadedForRef) And
  825. {old reg new reg}
  826. (RegInfo.New2OldReg[RegCounter] <> RegCounter) Then
  827. Begin
  828. {$ifdef replacereg}
  829. If not ReplaceReg(RegInfo.New2OldReg[RegCounter],
  830. regCounter,p,
  831. PPaiProp(hp4^.optInfo)^.Regs[regCounter]) then
  832. begin
  833. {$endif replacereg}
  834. hp3 := New(Paicpu,Op_Reg_Reg(A_MOV, S_L,
  835. {old reg new reg}
  836. RegInfo.New2OldReg[RegCounter], RegCounter));
  837. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp3);
  838. {$ifdef replacereg}
  839. end
  840. {$endif replacereg}
  841. End
  842. Else
  843. { imagine the following code: }
  844. { normal wrong optimized }
  845. { movl 8(%ebp), %eax movl 8(%ebp), %eax }
  846. { movl (%eax), %eax movl (%eax), %eax }
  847. { cmpl 8(%ebp), %eax cmpl 8(%ebp), %eax }
  848. { jne l1 jne l1 }
  849. { movl 8(%ebp), %eax }
  850. { movl (%eax), %edi movl %eax, %edi }
  851. { movl %edi, -4(%ebp) movl %edi, -4(%ebp) }
  852. { movl 8(%ebp), %eax }
  853. { pushl 70(%eax) pushl 70(%eax) }
  854. { }
  855. { The error is that at the moment that the last instruction is executed, }
  856. { %eax doesn't contain 8(%ebp) anymore. Solution: the contents of }
  857. { registers that are completely removed from a sequence (= registers in }
  858. { RegLoadedForRef, have to be changed to their contents from before the }
  859. { sequence. }
  860. If RegCounter in RegInfo.RegsLoadedForRef Then
  861. Begin
  862. {load Cnt2 with the total number of instructions of this sequence}
  863. Cnt2 := PPaiProp(hp4^.OptInfo)^.
  864. Regs[RegInfo.New2OldReg[RegCounter]].NrOfMods;
  865. hp3 := hp2;
  866. For Cnt := 1 to Pred(Cnt2) Do
  867. GetNextInstruction(hp3, hp3);
  868. TmpState := PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState;
  869. GetNextInstruction(hp3, hp3);
  870. {$ifdef csdebug}
  871. Writeln('Cnt2: ',Cnt2);
  872. hp5 := new(pai_asm_comment,init(strpnew('starting here...')));
  873. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp5);
  874. {$endif csdebug}
  875. hp3 := hp2;
  876. {first change the contents of the register inside the sequence}
  877. For Cnt := 1 to Cnt2 Do
  878. Begin
  879. {save the WState of the last pai object of the sequence for later use}
  880. TmpState := PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState;
  881. {$ifdef csdebug}
  882. hp5 := new(pai_asm_comment,init(strpnew('WState for '+att_reg2str[Regcounter]+': '
  883. +tostr(tmpstate))));
  884. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  885. {$endif csdebug}
  886. PPaiProp(hp3^.OptInfo)^.Regs[RegCounter] :=
  887. PPaiProp(hp4^.OptInfo)^.Regs[RegCounter];
  888. GetNextInstruction(hp3, hp3);
  889. End;
  890. {here, hp3 = p = Pai object right after the sequence, TmpState = WState of
  891. RegCounter at the last Pai object of the sequence}
  892. GetLastInstruction(hp3, hp3);
  893. While GetNextInstruction(hp3, hp3) And
  894. (PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState
  895. = TmpState) Do
  896. {$ifdef csdebug}
  897. begin
  898. hp5 := new(pai_asm_comment,init(strpnew('WState for '+att_reg2str[Regcounter]+': '+
  899. tostr(PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState))));
  900. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  901. {$endif csdebug}
  902. PPaiProp(hp3^.OptInfo)^.Regs[RegCounter] :=
  903. PPaiProp(hp4^.OptInfo)^.Regs[RegCounter];
  904. {$ifdef csdebug}
  905. end;
  906. {$endif csdebug}
  907. {$ifdef csdebug}
  908. hp5 := new(pai_asm_comment,init(strpnew('stopping here...')));
  909. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  910. {$endif csdebug}
  911. End;
  912. End;
  913. hp3 := New(Pai_Marker,Init(NoPropInfoEnd));
  914. InsertLLItem(AsmL, Pai(hp2^.Previous), hp2, hp3);
  915. If hp1 <> nil Then p := hp1;
  916. Continue;
  917. End
  918. Else
  919. If (Cnt > 0) And
  920. (PPaiProp(p^.OptInfo)^.
  921. Regs[Reg32(Paicpu(p)^.oper[1].reg)].Typ = Con_Ref) And
  922. (PPaiProp(p^.OptInfo)^.CanBeRemoved) Then
  923. Begin
  924. hp2 := p;
  925. Cnt2 := 1;
  926. While Cnt2 <= Cnt Do
  927. Begin
  928. If RegInInstruction(Paicpu(hp2)^.oper[1].reg, p) Or
  929. RegInInstruction(Reg32(Paicpu(hp2)^.oper[1].reg), p) Then
  930. PPaiProp(p^.OptInfo)^.CanBeRemoved := False;
  931. Inc(Cnt2);
  932. GetNextInstruction(p, p);
  933. End;
  934. Continue;
  935. End;
  936. End;
  937. End;
  938. Top_Const:
  939. Begin
  940. Case Paicpu(p)^.oper[1].typ Of
  941. Top_Reg:
  942. Begin
  943. If GetLastInstruction(p, hp1) Then
  944. With PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)] Do
  945. If (Typ = Con_Const) And
  946. (StartMod = p) Then
  947. PPaiProp(p^.OptInfo)^.CanBeRemoved := True;
  948. End;
  949. { Top_Ref:;}
  950. End;
  951. End;
  952. End;
  953. End;
  954. A_STD: If GetLastInstruction(p, hp1) And
  955. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_Set) Then
  956. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  957. A_XOR:
  958. Begin
  959. If (Paicpu(p)^.oper[0].typ = top_reg) And
  960. (Paicpu(p)^.oper[0].typ = top_reg) And
  961. (Paicpu(p)^.oper[1].reg = Paicpu(p)^.oper[1].reg) And
  962. GetLastInstruction(p, hp1) And
  963. (PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)].typ = con_const) And
  964. (PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)].StartMod = nil)
  965. Then PPaiProp(p^.OptInfo)^.CanBeRemoved := True
  966. End
  967. End
  968. End;
  969. End;
  970. GetNextInstruction(p, p);
  971. End;
  972. End;
  973. Procedure RemoveInstructs(AsmL: PAasmOutput; First, Last: Pai);
  974. {Removes the marked instructions and disposes the PPaiProps of the other
  975. instructions, restoring their line number}
  976. Var p, hp1: Pai;
  977. {$IfDef TP}
  978. TmpLine: Longint;
  979. {$EndIf TP}
  980. InstrCnt: Longint;
  981. Begin
  982. p := First;
  983. SkipHead(P);
  984. InstrCnt := 1;
  985. While (p <> Last) Do
  986. Begin
  987. {$ifndef noinstremove}
  988. If PPaiProp(p^.OptInfo)^.CanBeRemoved
  989. Then
  990. Begin
  991. {$IfDef TP}
  992. Dispose(PPaiProp(p^.OptInfo));
  993. {$EndIf}
  994. GetNextInstruction(p, hp1);
  995. AsmL^.Remove(p);
  996. Dispose(p, Done);
  997. p := hp1;
  998. Inc(InstrCnt);
  999. End
  1000. Else
  1001. {$endif noinstremove}
  1002. Begin
  1003. {$IfDef TP}
  1004. Dispose(PPaiProp(p^.OptInfo));
  1005. {$EndIf TP}
  1006. p^.OptInfo := nil;
  1007. GetNextInstruction(p, p);
  1008. Inc(InstrCnt);
  1009. End;
  1010. End;
  1011. {$IfNDef TP}
  1012. FreeMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4))
  1013. {$EndIf TP}
  1014. End;
  1015. Procedure CSE(AsmL: PAasmOutput; First, Last: Pai);
  1016. Begin
  1017. DoCSE(AsmL, First, Last);
  1018. RemoveInstructs(AsmL, First, Last);
  1019. End;
  1020. End.
  1021. {
  1022. $Log$
  1023. Revision 1.33 1999-11-20 11:37:03 jonas
  1024. * make cycle works with -dreplacereg (register renaming)! I have not
  1025. tested it yet together with -darithopt, but I don't expect problems
  1026. Revision 1.32 1999/11/14 11:26:53 jonas
  1027. + basic register renaming (not yet working completely, between
  1028. -dreplacereg/-dreplaceregdebug)
  1029. Revision 1.31 1999/11/06 16:21:57 jonas
  1030. + search optimial register to use in alignment code (compile with
  1031. -dalignreg, -dalignregdebug to see chosen register in
  1032. assembler code). Still needs support in ag386bin.
  1033. Revision 1.30 1999/11/06 14:34:20 peter
  1034. * truncated log to 20 revs
  1035. Revision 1.29 1999/11/05 16:01:46 jonas
  1036. + first implementation of choosing least used register for alignment code
  1037. (not yet working, between ifdef alignreg)
  1038. Revision 1.28 1999/10/11 11:11:31 jonas
  1039. * fixed bug which sometimes caused a crash when optimizing blocks of code with
  1040. assembler blocks (didn't notice before because of lack of zero page protection
  1041. under Win9x :( )
  1042. Revision 1.27 1999/10/01 13:51:40 jonas
  1043. * CSE now updates the RegAlloc's
  1044. Revision 1.26 1999/09/30 14:43:13 jonas
  1045. * fixed small efficiency which caused some missed optimizations (saves 1
  1046. assembler instruction on the whole compiler/RTL source tree! :)
  1047. Revision 1.25 1999/09/27 23:44:50 peter
  1048. * procinfo is now a pointer
  1049. * support for result setting in sub procedure
  1050. Revision 1.24 1999/08/25 11:59:58 jonas
  1051. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  1052. Revision 1.23 1999/08/04 00:22:58 florian
  1053. * renamed i386asm and i386base to cpuasm and cpubase
  1054. Revision 1.22 1999/06/03 15:45:08 jonas
  1055. * sequences are now checked only once (previously, some long ones were
  1056. checked once completely and then several times partially)
  1057. Revision 1.21 1999/05/08 20:38:03 jonas
  1058. * seperate OPTimizer INFO pointer field in tai object
  1059. Revision 1.20 1999/05/01 13:24:19 peter
  1060. * merged nasm compiler
  1061. * old asm moved to oldasm/
  1062. Revision 1.2 1999/03/29 16:05:45 peter
  1063. * optimizer working for ag386bin
  1064. Revision 1.1 1999/03/26 00:01:09 peter
  1065. * first things for optimizer (compiles but cycle crashes)
  1066. Revision 1.19 1999/02/26 00:48:17 peter
  1067. * assembler writers fixed for ag386bin
  1068. Revision 1.18 1998/12/29 18:48:22 jonas
  1069. + optimize pascal code surrounding assembler blocks
  1070. Revision 1.17 1998/12/17 16:37:39 jonas
  1071. + extra checks in RegsEquivalent so some more optimizations can be done (which
  1072. where disabled by the second fix from revision 1.22)
  1073. Revision 1.16 1998/12/02 16:23:31 jonas
  1074. * changed "if longintvar in set" to case or "if () or () .." statements
  1075. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  1076. Revision 1.15 1998/11/24 19:47:24 jonas
  1077. * fixed problems posiible with 3 operand instructions
  1078. Revision 1.14 1998/11/09 19:40:48 jonas
  1079. * fixed comments from last commit (apparently there's still a 255 char limit :( )
  1080. Revision 1.13 1998/11/09 19:33:39 jonas
  1081. * changed specific bugfix (which was actually wrong implemented, but
  1082. did the right thing in most cases nevertheless) to general bugfix
  1083. * fixed bug that caused
  1084. mov (ebp), edx mov (ebp), edx
  1085. mov (edx), edx mov (edx), edx
  1086. ... being changed to ...
  1087. mov (ebp), edx mov edx, eax
  1088. mov (eax), eax
  1089. but this disabled another small correct optimization...
  1090. Revision 1.12 1998/10/20 09:32:54 peter
  1091. * removed some unused vars
  1092. }