csopt386.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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 hp: pai;
  432. tmpState: byte;
  433. begin
  434. tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
  435. PPaiProp(p^.optInfo)^.Regs[reg] := c;
  436. while getNextInstruction(p,p) and
  437. (PPaiProp(p^.optInfo)^.Regs[reg].wState = tmpState) do
  438. PPaiProp(p^.optInfo)^.Regs[reg] := c;
  439. {$ifdef replaceregdebug}
  440. if assigned(p) then
  441. begin
  442. hp := new(pai_asm_comment,init(strpnew(
  443. 'restored '+att_reg2str[reg]+' till here...')));
  444. hp^.next := p;
  445. hp^.previous := p^.previous;
  446. p^.previous := hp;
  447. if assigned(hp^.previous) then
  448. hp^.previous^.next := hp;
  449. end;
  450. {$endif replaceregdebug}
  451. end;
  452. Procedure ClearRegContentsFrom(reg: TRegister; p: pai);
  453. var hp: pai;
  454. tmpState: byte;
  455. begin
  456. tmpState := PPaiProp(p^.optInfo)^.Regs[reg].wState;
  457. PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
  458. while getNextInstruction(p,p) and
  459. (PPaiProp(p^.optInfo)^.Regs[reg].wState = tmpState) do
  460. PPaiProp(p^.optInfo)^.Regs[reg].typ := con_unknown;
  461. {$ifdef replaceregdebug}
  462. if assigned(p) then
  463. begin
  464. hp := new(pai_asm_comment,init(strpnew(
  465. 'cleared '+att_reg2str[reg]+' till here...')));
  466. hp^.next := p;
  467. hp^.previous := p^.previous;
  468. p^.previous := hp;
  469. if assigned(hp^.previous) then
  470. hp^.previous^.next := hp;
  471. end;
  472. {$endif replaceregdebug}
  473. end;
  474. function NoHardCodedRegs(p: paicpu): boolean;
  475. var chCount: byte;
  476. begin
  477. NoHardCodedRegs := true;
  478. with InsProp[p^.opcode] do
  479. for chCount := 1 to MaxCh do
  480. if Ch[chCount] in ([Ch_REAX..Ch_MEDI]-[Ch_RESP,Ch_WESP,Ch_RWESP]) then
  481. begin
  482. NoHardCodedRegs := false;
  483. break
  484. end;
  485. end;
  486. Procedure ChangeReg(var Reg: TRegister; orgReg, newReg: TRegister);
  487. begin
  488. if reg = newReg then
  489. reg := orgReg
  490. else if reg = regtoreg8(newReg) then
  491. reg := regtoreg8(orgReg)
  492. else if reg = regtoreg16(newReg) then
  493. reg := regtoreg16(orgReg);
  494. end;
  495. Procedure DoReplaceReg(orgReg,newReg: tregister; hp: paicpu);
  496. var opCount: byte;
  497. begin
  498. for opCount := 0 to 2 do
  499. with hp^.oper[opCount] Do
  500. case typ of
  501. top_reg: ChangeReg(reg,orgReg,newReg);
  502. top_ref:
  503. begin
  504. ChangeReg(ref^.base,orgReg,newReg);
  505. ChangeReg(ref^.index,orgReg,newReg);
  506. end;
  507. end;
  508. end;
  509. function RegSizesOK(oldReg,newReg: TRegister; p: paicpu): boolean;
  510. { oldreg and newreg must be 32bit components }
  511. var opCount: byte;
  512. begin
  513. RegSizesOK := true;
  514. if not(IsGP32reg(oldReg) and IsGP32Reg(newReg)) then
  515. begin
  516. for opCount := 0 to 2 do
  517. if (p^.oper[opCount].typ = top_reg) and
  518. (p^.oper[opCount].reg in [R_AL..R_DH]) then
  519. begin
  520. RegSizesOK := false;
  521. break
  522. end
  523. end;
  524. end;
  525. function RegReadByInstruction(reg: TRegister; hp: pai): boolean;
  526. { assumes p doesn't modify registers implicitely (like div) }
  527. var p: paicpu;
  528. opCount: byte;
  529. begin
  530. RegReadByInstruction := false;
  531. p := paicpu(hp);
  532. if hp^.typ <> ait_instruction then
  533. exit;
  534. for opCount := 0 to 2 do
  535. if (p^.oper[opCount].typ = top_ref) and
  536. RegInRef(reg,p^.oper[opCount].ref^) then
  537. begin
  538. RegReadByInstruction := true;
  539. exit
  540. end;
  541. for opCount := 1 to MaxCh do
  542. case InsProp[p^.opcode].Ch[opCount] of
  543. Ch_RWOp1,Ch_ROp1{$ifdef arithopt},Ch_MOp1{$endif}:
  544. if (p^.oper[0].typ = top_reg) and
  545. (p^.oper[0].reg = reg) then
  546. begin
  547. RegReadByInstruction := true;
  548. exit
  549. end;
  550. Ch_RWOp2,Ch_ROp2{$ifdef arithopt},Ch_MOp2{$endif}:
  551. if (p^.oper[1].typ = top_reg) and
  552. (p^.oper[1].reg = reg) then
  553. begin
  554. RegReadByInstruction := true;
  555. exit
  556. end;
  557. Ch_RWOp3,Ch_ROp3{$ifdef arithopt},Ch_MOp3{$endif}:
  558. if (p^.oper[2].typ = top_reg) and
  559. (p^.oper[2].reg = reg) then
  560. begin
  561. RegReadByInstruction := true;
  562. exit
  563. end;
  564. end;
  565. end;
  566. procedure DoReplaceReadReg(orgReg,newReg: tregister; p: paicpu);
  567. var opCount: byte;
  568. begin
  569. for opCount := 0 to 2 do
  570. if p^.oper[opCount].typ = top_ref then
  571. begin
  572. ChangeReg(p^.oper[opCount].ref^.base,orgReg,newReg);
  573. ChangeReg(p^.oper[opCount].ref^.index,orgReg,newReg);
  574. end;
  575. for opCount := 1 to MaxCh do
  576. case InsProp[p^.opcode].Ch[opCount] of
  577. Ch_RWOp1,Ch_ROp1{$ifdef arithopt},Ch_MOp1{$endif}:
  578. if p^.oper[0].typ = top_reg then
  579. ChangeReg(p^.oper[0].reg,orgReg,newReg);
  580. Ch_RWOp2,Ch_ROp2{$ifdef arithopt},Ch_MOp2{$endif}:
  581. if p^.oper[1].typ = top_reg then
  582. ChangeReg(p^.oper[1].reg,orgReg,newReg);
  583. Ch_RWOp3,Ch_ROp3{$ifdef arithopt},Ch_MOp3{$endif}:
  584. if p^.oper[2].typ = top_reg then
  585. ChangeReg(p^.oper[2].reg,orgReg,newReg);
  586. end;
  587. end;
  588. function ReplaceReg(orgReg, newReg: TRegister; p: pai;
  589. const c: TContent): Boolean;
  590. { Tries to replace orgreg with newreg in all instructions coming after p }
  591. { until orgreg gets loaded with a new value. Returns true if successful, }
  592. { false otherwise. If successful, the contents of newReg are set to c, }
  593. { which should hold the contents of newReg before the current sequence }
  594. { started }
  595. var endP, hp: Pai;
  596. sequenceEnd, tmpResult, newRegModified, orgRegRead, orgRegModified: Boolean;
  597. begin
  598. ReplaceReg := False;
  599. tmpResult := true;
  600. sequenceEnd := false;
  601. newRegModified := false;
  602. orgRegRead := false;
  603. endP := pai(p^.previous);
  604. while tmpResult and not sequenceEnd Do
  605. begin
  606. tmpResult :=
  607. getNextInstruction(endP,endP);
  608. If tmpResult then
  609. begin
  610. sequenceEnd :=
  611. RegLoadedWithNewValue(newReg,paicpu(endP)) or
  612. { FindRegDealloc(newReg,endP) or}
  613. (GetNextInstruction(endp,hp) and
  614. FindRegDealloc(newReg,hp));
  615. newRegModified :=
  616. newRegModified or
  617. (not(sequenceEnd) and
  618. RegModifiedByInstruction(newReg,endP));
  619. orgRegRead := newRegModified and RegReadByInstruction(orgReg,endP);
  620. sequenceEnd := SequenceEnd and not(newRegModified and orgRegRead);
  621. tmpResult :=
  622. not(newRegModified and orgRegRead) and
  623. (endP^.typ = ait_instruction) and
  624. not(paicpu(endP)^.is_jmp) and
  625. NoHardCodedRegs(paicpu(endP)) and
  626. RegSizesOk(orgReg,newReg,paicpu(endP)) and
  627. not RegModifiedByInstruction(orgReg,endP);
  628. end;
  629. end;
  630. if SequenceEnd then
  631. begin
  632. {$ifdef replaceregdebug}
  633. hp := new(pai_asm_comment,init(strpnew(
  634. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  635. ' from here...')));
  636. hp^.next := p;
  637. hp^.previous := p^.previous;
  638. p^.previous := hp;
  639. if assigned(hp^.previous) then
  640. hp^.previous^.next := hp;
  641. hp := new(pai_asm_comment,init(strpnew(
  642. 'replaced '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  643. ' till here')));
  644. hp^.next := endp^.next;
  645. hp^.previous := endp;
  646. endp^.next := hp;
  647. if assigned(hp^.next) then
  648. hp^.next^.previous := hp;
  649. {$endif replaceregdebug}
  650. ReplaceReg := true;
  651. hp := p;
  652. while hp <> endP do
  653. begin
  654. if hp^.typ = ait_instruction then
  655. DoReplaceReg(orgReg,newReg,paicpu(hp));
  656. GetNextInstruction(hp,hp)
  657. end;
  658. if assigned(endp) and (endp^.typ = ait_instruction) then
  659. DoReplaceReadReg(orgReg,newReg,paicpu(endP));
  660. if (p <> endp) then
  661. if not RegModifiedByInstruction(newReg,endP) then
  662. RestoreRegContentsTo(newReg, c ,p)
  663. else
  664. ClearRegContentsFrom(orgReg,p);
  665. end
  666. {$ifdef replaceregdebug}
  667. else
  668. begin
  669. hp := new(pai_asm_comment,init(strpnew(
  670. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  671. ' from here...')));
  672. hp^.previous := p^.previous;
  673. hp^.next := p;
  674. p^.previous := hp;
  675. if assigned(hp^.previous) then
  676. hp^.previous^.next := hp;
  677. hp := new(pai_asm_comment,init(strpnew(
  678. 'replacing '+att_reg2str[newreg]+' with '+att_reg2str[orgreg]+
  679. ' failed here')));
  680. hp^.next := endp^.next;
  681. hp^.previous := endp;
  682. endp^.next := hp;
  683. if assigned(hp^.next) then
  684. hp^.next^.previous := hp;
  685. end;
  686. {$endif replaceregdebug}
  687. End;
  688. {$endif replacereg}
  689. Procedure DoCSE(AsmL: PAasmOutput; First, Last: Pai);
  690. {marks the instructions that can be removed by RemoveInstructs. They're not
  691. removed immediately because sometimes an instruction needs to be checked in
  692. two different sequences}
  693. Var Cnt, Cnt2: Longint;
  694. p, hp1, hp2: Pai;
  695. hp3, hp4: Pai;
  696. {$ifdef csdebug}
  697. hp5: pai;
  698. {$endif csdebug}
  699. RegInfo: TRegInfo;
  700. RegCounter: TRegister;
  701. TmpState: Byte;
  702. Begin
  703. p := First;
  704. SkipHead(p);
  705. First := p;
  706. While (p <> Last) Do
  707. Begin
  708. Case p^.typ Of
  709. {$ifdef alignreg}
  710. ait_align:
  711. SetAlignReg(p);
  712. {$endif alignreg}
  713. ait_instruction:
  714. Begin
  715. Case Paicpu(p)^.opcode Of
  716. A_CLD: If GetLastInstruction(p, hp1) And
  717. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_NotSet) Then
  718. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  719. A_MOV, A_MOVZX, A_MOVSX:
  720. Begin
  721. Case Paicpu(p)^.oper[0].typ Of
  722. Top_Ref:
  723. Begin {destination is always a register in this case}
  724. With PPaiProp(p^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)] Do
  725. Begin
  726. If (p = StartMod) And
  727. GetLastInstruction (p, hp1) And
  728. (hp1^.typ <> ait_marker)
  729. Then
  730. {so we don't try to check a sequence when p is the first instruction of the block}
  731. If CheckSequence(p, Paicpu(p)^.oper[1].reg, Cnt, RegInfo) And
  732. (Cnt > 0) Then
  733. Begin
  734. hp1 := nil;
  735. { although it's perfectly ok to remove an instruction which doesn't contain }
  736. { the register that we've just checked (CheckSequence takes care of that), }
  737. { the sequence containing this other register should also be completely }
  738. { checked and removed, otherwise we may get situations like this: }
  739. { }
  740. { movl 12(%ebp), %edx movl 12(%ebp), %edx }
  741. { movl 16(%ebp), %eax movl 16(%ebp), %eax }
  742. { movl 8(%edx), %edx movl 8(%edx), %edx }
  743. { movl (%eax), eax movl (%eax), eax }
  744. { cmpl %eax, %edx cmpl %eax, %edx }
  745. { jnz l123 getting converted to jnz l123 }
  746. { movl 12(%ebp), %edx movl 4(%eax), eax }
  747. { movl 16(%ebp), %eax }
  748. { movl 8(%edx), %edx }
  749. { movl 4(%eax), eax }
  750. hp2 := p;
  751. Cnt2 := 1;
  752. While Cnt2 <= Cnt Do
  753. Begin
  754. If (hp1 = nil) And
  755. Not(RegInInstruction(Paicpu(hp2)^.oper[1].reg, p) Or
  756. RegInInstruction(Reg32(Paicpu(hp2)^.oper[1].reg), p)) And
  757. Not((p^.typ = ait_instruction) And
  758. (paicpu(p)^.OpCode = A_MOV) And
  759. (paicpu(p)^.Oper[0].typ = top_ref) And
  760. (PPaiProp(p^.OptInfo)^.Regs[Reg32(paicpu(p)^.Oper[1].reg)].NrOfMods
  761. <= (Cnt - Cnt2 + 1)))
  762. Then hp1 := p;
  763. {$ifndef noremove}
  764. PPaiProp(p^.OptInfo)^.CanBeRemoved := True;
  765. {$endif noremove}
  766. Inc(Cnt2);
  767. GetNextInstruction(p, p);
  768. End;
  769. hp3 := New(Pai_Marker,Init(NoPropInfoStart));
  770. InsertLLItem(AsmL, Pai(hp2^.Previous), hp2, hp3);
  771. {hp4 is used to get the contents of the registers before the sequence}
  772. GetLastInstruction(hp2, hp4);
  773. {$IfDef CSDebug}
  774. For RegCounter := R_EAX To R_EDI Do
  775. If (RegCounter in RegInfo.RegsLoadedForRef) Then
  776. Begin
  777. hp5 := new(pai_asm_comment,init(strpnew('New: '+att_reg2str[RegCounter]+', Old: '+
  778. att_reg2str[RegInfo.New2OldReg[RegCounter]])));
  779. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp5);
  780. End;
  781. {$EndIf CSDebug}
  782. { If some registers were different in the old and the new sequence, move }
  783. { the contents of those old registers to the new ones }
  784. For RegCounter := R_EAX To R_EDI Do
  785. If Not(RegCounter in [R_ESP,procinfo^.framepointer]) And
  786. (RegInfo.New2OldReg[RegCounter] <> R_NO) Then
  787. Begin
  788. AllocRegBetween(AsmL,RegInfo.New2OldReg[RegCounter],
  789. PPaiProp(hp4^.OptInfo)^.Regs[RegInfo.New2OldReg[RegCounter]].StartMod,hp2);
  790. If Not(RegCounter In RegInfo.RegsLoadedForRef) And
  791. {old reg new reg}
  792. (RegInfo.New2OldReg[RegCounter] <> RegCounter) Then
  793. Begin
  794. {$ifdef replacereg}
  795. If not ReplaceReg(RegInfo.New2OldReg[RegCounter],
  796. regCounter,p,
  797. PPaiProp(hp4^.optInfo)^.Regs[regCounter]) then
  798. begin
  799. {$endif replacereg}
  800. hp3 := New(Paicpu,Op_Reg_Reg(A_MOV, S_L,
  801. {old reg new reg}
  802. RegInfo.New2OldReg[RegCounter], RegCounter));
  803. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp3);
  804. {$ifdef replacereg}
  805. end
  806. {$ifdef replaceregdebug}
  807. else
  808. begin
  809. hp3 := new(pai_asm_comment,init(strpnew(
  810. 'restored '+att_reg2str[regCounter]+' with data from here...')));
  811. insertllitem(asml,hp4,hp4^.next,hp3);
  812. end;
  813. {$endif replaceregdebug}
  814. {$endif replacereg}
  815. End
  816. Else
  817. { imagine the following code: }
  818. { normal wrong optimized }
  819. { movl 8(%ebp), %eax movl 8(%ebp), %eax }
  820. { movl (%eax), %eax movl (%eax), %eax }
  821. { cmpl 8(%ebp), %eax cmpl 8(%ebp), %eax }
  822. { jne l1 jne l1 }
  823. { movl 8(%ebp), %eax }
  824. { movl (%eax), %edi movl %eax, %edi }
  825. { movl %edi, -4(%ebp) movl %edi, -4(%ebp) }
  826. { movl 8(%ebp), %eax }
  827. { pushl 70(%eax) pushl 70(%eax) }
  828. { }
  829. { The error is that at the moment that the last instruction is executed, }
  830. { %eax doesn't contain 8(%ebp) anymore. Solution: the contents of }
  831. { registers that are completely removed from a sequence (= registers in }
  832. { RegLoadedForRef, have to be changed to their contents from before the }
  833. { sequence. }
  834. If RegCounter in RegInfo.RegsLoadedForRef Then
  835. Begin
  836. {load Cnt2 with the total number of instructions of this sequence}
  837. Cnt2 := PPaiProp(hp4^.OptInfo)^.
  838. Regs[RegInfo.New2OldReg[RegCounter]].NrOfMods;
  839. hp3 := hp2;
  840. For Cnt := 1 to Pred(Cnt2) Do
  841. GetNextInstruction(hp3, hp3);
  842. TmpState := PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState;
  843. GetNextInstruction(hp3, hp3);
  844. {$ifdef csdebug}
  845. Writeln('Cnt2: ',Cnt2);
  846. hp5 := new(pai_asm_comment,init(strpnew('starting here...')));
  847. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp5);
  848. {$endif csdebug}
  849. hp3 := hp2;
  850. {first change the contents of the register inside the sequence}
  851. For Cnt := 1 to Cnt2 Do
  852. Begin
  853. {save the WState of the last pai object of the sequence for later use}
  854. TmpState := PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState;
  855. {$ifdef csdebug}
  856. hp5 := new(pai_asm_comment,init(strpnew('WState for '+att_reg2str[Regcounter]+': '
  857. +tostr(tmpstate))));
  858. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  859. {$endif csdebug}
  860. PPaiProp(hp3^.OptInfo)^.Regs[RegCounter] :=
  861. PPaiProp(hp4^.OptInfo)^.Regs[RegCounter];
  862. GetNextInstruction(hp3, hp3);
  863. End;
  864. {here, hp3 = p = Pai object right after the sequence, TmpState = WState of
  865. RegCounter at the last Pai object of the sequence}
  866. GetLastInstruction(hp3, hp3);
  867. While GetNextInstruction(hp3, hp3) And
  868. (PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState
  869. = TmpState) Do
  870. {$ifdef csdebug}
  871. begin
  872. hp5 := new(pai_asm_comment,init(strpnew('WState for '+att_reg2str[Regcounter]+': '+
  873. tostr(PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState))));
  874. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  875. {$endif csdebug}
  876. PPaiProp(hp3^.OptInfo)^.Regs[RegCounter] :=
  877. PPaiProp(hp4^.OptInfo)^.Regs[RegCounter];
  878. {$ifdef csdebug}
  879. end;
  880. {$endif csdebug}
  881. {$ifdef csdebug}
  882. hp5 := new(pai_asm_comment,init(strpnew('stopping here...')));
  883. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  884. {$endif csdebug}
  885. End;
  886. End;
  887. hp3 := New(Pai_Marker,Init(NoPropInfoEnd));
  888. InsertLLItem(AsmL, Pai(hp2^.Previous), hp2, hp3);
  889. If hp1 <> nil Then p := hp1;
  890. Continue;
  891. End
  892. Else
  893. If (Cnt > 0) And
  894. (PPaiProp(p^.OptInfo)^.
  895. Regs[Reg32(Paicpu(p)^.oper[1].reg)].Typ = Con_Ref) And
  896. (PPaiProp(p^.OptInfo)^.CanBeRemoved) Then
  897. Begin
  898. hp2 := p;
  899. Cnt2 := 1;
  900. While Cnt2 <= Cnt Do
  901. Begin
  902. If RegInInstruction(Paicpu(hp2)^.oper[1].reg, p) Or
  903. RegInInstruction(Reg32(Paicpu(hp2)^.oper[1].reg), p) Then
  904. PPaiProp(p^.OptInfo)^.CanBeRemoved := False;
  905. Inc(Cnt2);
  906. GetNextInstruction(p, p);
  907. End;
  908. Continue;
  909. End;
  910. End;
  911. End;
  912. Top_Const:
  913. Begin
  914. Case Paicpu(p)^.oper[1].typ Of
  915. Top_Reg:
  916. Begin
  917. If GetLastInstruction(p, hp1) Then
  918. With PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)] Do
  919. If (Typ = Con_Const) And
  920. (StartMod = p) Then
  921. PPaiProp(p^.OptInfo)^.CanBeRemoved := True;
  922. End;
  923. { Top_Ref:;}
  924. End;
  925. End;
  926. End;
  927. End;
  928. A_STD: If GetLastInstruction(p, hp1) And
  929. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_Set) Then
  930. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  931. A_XOR:
  932. Begin
  933. If (Paicpu(p)^.oper[0].typ = top_reg) And
  934. (Paicpu(p)^.oper[0].typ = top_reg) And
  935. (Paicpu(p)^.oper[1].reg = Paicpu(p)^.oper[1].reg) And
  936. GetLastInstruction(p, hp1) And
  937. (PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)].typ = con_const) And
  938. (PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Paicpu(p)^.oper[1].reg)].StartMod = nil)
  939. Then PPaiProp(p^.OptInfo)^.CanBeRemoved := True
  940. End
  941. End
  942. End;
  943. End;
  944. GetNextInstruction(p, p);
  945. End;
  946. End;
  947. Procedure RemoveInstructs(AsmL: PAasmOutput; First, Last: Pai);
  948. {Removes the marked instructions and disposes the PPaiProps of the other
  949. instructions, restoring their line number}
  950. Var p, hp1: Pai;
  951. {$IfDef TP}
  952. TmpLine: Longint;
  953. {$EndIf TP}
  954. InstrCnt: Longint;
  955. Begin
  956. p := First;
  957. SkipHead(P);
  958. InstrCnt := 1;
  959. While (p <> Last) Do
  960. Begin
  961. {$ifndef noinstremove}
  962. If PPaiProp(p^.OptInfo)^.CanBeRemoved
  963. Then
  964. Begin
  965. {$IfDef TP}
  966. Dispose(PPaiProp(p^.OptInfo));
  967. {$EndIf}
  968. GetNextInstruction(p, hp1);
  969. AsmL^.Remove(p);
  970. Dispose(p, Done);
  971. p := hp1;
  972. Inc(InstrCnt);
  973. End
  974. Else
  975. {$endif noinstremove}
  976. Begin
  977. {$IfDef TP}
  978. Dispose(PPaiProp(p^.OptInfo));
  979. {$EndIf TP}
  980. p^.OptInfo := nil;
  981. GetNextInstruction(p, p);
  982. Inc(InstrCnt);
  983. End;
  984. End;
  985. {$IfNDef TP}
  986. FreeMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4))
  987. {$EndIf TP}
  988. End;
  989. Procedure CSE(AsmL: PAasmOutput; First, Last: Pai);
  990. Begin
  991. DoCSE(AsmL, First, Last);
  992. RemoveInstructs(AsmL, First, Last);
  993. End;
  994. End.
  995. {
  996. $Log$
  997. Revision 1.32 1999-11-14 11:26:53 jonas
  998. + basic register renaming (not yet working completely, between
  999. -dreplacereg/-dreplaceregdebug)
  1000. Revision 1.31 1999/11/06 16:21:57 jonas
  1001. + search optimial register to use in alignment code (compile with
  1002. -dalignreg, -dalignregdebug to see chosen register in
  1003. assembler code). Still needs support in ag386bin.
  1004. Revision 1.30 1999/11/06 14:34:20 peter
  1005. * truncated log to 20 revs
  1006. Revision 1.29 1999/11/05 16:01:46 jonas
  1007. + first implementation of choosing least used register for alignment code
  1008. (not yet working, between ifdef alignreg)
  1009. Revision 1.28 1999/10/11 11:11:31 jonas
  1010. * fixed bug which sometimes caused a crash when optimizing blocks of code with
  1011. assembler blocks (didn't notice before because of lack of zero page protection
  1012. under Win9x :( )
  1013. Revision 1.27 1999/10/01 13:51:40 jonas
  1014. * CSE now updates the RegAlloc's
  1015. Revision 1.26 1999/09/30 14:43:13 jonas
  1016. * fixed small efficiency which caused some missed optimizations (saves 1
  1017. assembler instruction on the whole compiler/RTL source tree! :)
  1018. Revision 1.25 1999/09/27 23:44:50 peter
  1019. * procinfo is now a pointer
  1020. * support for result setting in sub procedure
  1021. Revision 1.24 1999/08/25 11:59:58 jonas
  1022. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  1023. Revision 1.23 1999/08/04 00:22:58 florian
  1024. * renamed i386asm and i386base to cpuasm and cpubase
  1025. Revision 1.22 1999/06/03 15:45:08 jonas
  1026. * sequences are now checked only once (previously, some long ones were
  1027. checked once completely and then several times partially)
  1028. Revision 1.21 1999/05/08 20:38:03 jonas
  1029. * seperate OPTimizer INFO pointer field in tai object
  1030. Revision 1.20 1999/05/01 13:24:19 peter
  1031. * merged nasm compiler
  1032. * old asm moved to oldasm/
  1033. Revision 1.2 1999/03/29 16:05:45 peter
  1034. * optimizer working for ag386bin
  1035. Revision 1.1 1999/03/26 00:01:09 peter
  1036. * first things for optimizer (compiles but cycle crashes)
  1037. Revision 1.19 1999/02/26 00:48:17 peter
  1038. * assembler writers fixed for ag386bin
  1039. Revision 1.18 1998/12/29 18:48:22 jonas
  1040. + optimize pascal code surrounding assembler blocks
  1041. Revision 1.17 1998/12/17 16:37:39 jonas
  1042. + extra checks in RegsEquivalent so some more optimizations can be done (which
  1043. where disabled by the second fix from revision 1.22)
  1044. Revision 1.16 1998/12/02 16:23:31 jonas
  1045. * changed "if longintvar in set" to case or "if () or () .." statements
  1046. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  1047. Revision 1.15 1998/11/24 19:47:24 jonas
  1048. * fixed problems posiible with 3 operand instructions
  1049. Revision 1.14 1998/11/09 19:40:48 jonas
  1050. * fixed comments from last commit (apparently there's still a 255 char limit :( )
  1051. Revision 1.13 1998/11/09 19:33:39 jonas
  1052. * changed specific bugfix (which was actually wrong implemented, but
  1053. did the right thing in most cases nevertheless) to general bugfix
  1054. * fixed bug that caused
  1055. mov (ebp), edx mov (ebp), edx
  1056. mov (edx), edx mov (edx), edx
  1057. ... being changed to ...
  1058. mov (ebp), edx mov edx, eax
  1059. mov (eax), eax
  1060. but this disabled another small correct optimization...
  1061. Revision 1.12 1998/10/20 09:32:54 peter
  1062. * removed some unused vars
  1063. }