csopt386.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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
  26. ,i386base,i386asm
  27. ,DAOpt386;
  28. {
  29. Function PaiInSequence(P: Pai; Const Seq: TContent): Boolean;
  30. Var P1: Pai;
  31. Counter: Byte;
  32. TmpResult: Boolean;
  33. Begin
  34. TmpResult := False;
  35. P1 := Seq.StartMod;
  36. Counter := 1;
  37. While Not(TmpResult) And
  38. (Counter <= Seq.NrOfMods) Do
  39. Begin
  40. If (P = P1) Then TmpResult := True;
  41. Inc(Counter);
  42. p1 := Pai(p1^.Next);
  43. End;
  44. PaiInSequence := TmpResult;
  45. End;
  46. }
  47. Function CheckSequence(p: Pai; Reg: TRegister; Var Found: Longint; Var RegInfo: TRegInfo): Boolean;
  48. {checks whether the current instruction sequence (starting with p) and the
  49. one between StartMod and EndMod of Reg are the same. If so, the number of
  50. instructions that match is stored in Found and true is returned, otherwise
  51. Found holds the number of instructions between StartMod and EndMod and false
  52. is returned}
  53. Var hp2, hp3{, EndMod}: Pai;
  54. PrevNonRemovablePai: Pai;
  55. OrgRegInfo, HighRegInfo: TRegInfo;
  56. HighFound, OrgRegFound: Byte;
  57. RegCounter: TRegister;
  58. OrgRegResult: Boolean;
  59. TmpResult: Boolean;
  60. OldNrOfMods: Byte;
  61. Begin {CheckSequence}
  62. Reg := Reg32(Reg);
  63. TmpResult := False;
  64. FillChar(OrgRegInfo, SizeOf(OrgRegInfo), 0);
  65. OrgRegFound := 0;
  66. HighFound := 0;
  67. OrgRegResult := False;
  68. RegCounter := R_EAX;
  69. GetLastInstruction(p, PrevNonRemovablePai);
  70. While (RegCounter <= R_EDI) And
  71. (PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].Typ <> Con_Ref) Do
  72. Inc(RegCounter);
  73. While (RegCounter <= R_EDI) Do
  74. Begin
  75. FillChar(RegInfo, SizeOf(RegInfo), 0);
  76. RegInfo.NewRegsEncountered := [ProcInfo.FramePointer, R_ESP];
  77. RegInfo.OldRegsEncountered := RegInfo.NewRegsEncountered;
  78. RegInfo.New2OldReg[ProcInfo.FramePointer] := ProcInfo.FramePointer;
  79. RegInfo.New2OldReg[R_ESP] := R_ESP;
  80. Found := 0;
  81. hp2 := PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].StartMod;
  82. If (PrevNonRemovablePai <> PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].StartMod)
  83. Then OldNrOfMods := PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].NrOfMods
  84. Else OldNrOfMods := 1;
  85. hp3 := p;
  86. While (Found <> OldNrOfMods) And
  87. { old new }
  88. InstructionsEquivalent(hp2, hp3, RegInfo) Do
  89. Begin
  90. GetNextInstruction(hp2, hp2);
  91. GetNextInstruction(hp3, hp3);
  92. Inc(Found)
  93. End;
  94. If (Found <> OldNrOfMods)
  95. Then
  96. Begin
  97. (* If ((Found+1) = OldNrOfMods) And
  98. Assigned(hp2) And
  99. (Pai(hp2)^.typ = ait_instruction) And
  100. ((Pai386(hp2)^.opcode = A_MOV) or
  101. (Pai386(p1)^.opcode = A_MOVZX)) And
  102. (Pai386(hp2)^.oper[0].typ = top_ref) And
  103. (Pai386(hp2)^.optype[1] = top_reg) And
  104. Assigned(hp3) And
  105. (Pai(hp3)^.typ = ait_instruction) And
  106. ((Pai386(hp3)^.opcode = A_MOV) or
  107. (Pai386(hp3)^.opcode = A_MOVZX)) And
  108. (Pai386(hp3)^.oper[0].typ = top_ref) And
  109. (Pai386(hp3)^.optype[1] = top_reg) And
  110. (Pai386(hp2)^.opcode <> Pai386(hp3)^.opcode) And
  111. RefsEquivalent(TReference(Pai386(hp2)^.oper[1]^),TReference(Pai386(hp3)^.oper[1]^), RegInfo)
  112. Then
  113. {hack to be able to optimize
  114. mov (mem), reg
  115. mov (reg), reg
  116. mov (reg), reg [*]
  117. test reg, reg and the oposite (where the marked instructions are
  118. jne l1 switched)
  119. mov (mem), reg
  120. mov (reg), reg
  121. movzx (reg), reg [*]}
  122. If (Pai386(hp2)^.opcode = A_MOV)
  123. Then
  124. Begin
  125. If (Pai386(hp2)^.opsize = S_B) And
  126. RegsEquivalent(Reg8toReg32(TRegister(Pai386(hp2)^.oper[1])),
  127. TRegister(Pai386(hp3)^.oper[1]), RegInfo)
  128. Then
  129. Begin
  130. Pai386(hp2)^.opcode := A_MOVZX;
  131. Pai386(hp2)^.opsize := S_BL;
  132. Pai386(hp2)^.loadoper(1,Pai386(hp3)^.oper[1]);
  133. Inc(Found);
  134. TmpResult := True;
  135. End
  136. Else
  137. Begin
  138. TmpResult := False;
  139. If (Found > 0) Then
  140. Found := PPaiProp(Pai(p)^.OptInfo)^.Regs[Reg].NrOfMods
  141. End
  142. End
  143. Else
  144. Begin
  145. If (Pai386(hp3)^.opsize = S_B) And
  146. RegsEquivalent(TRegister(Pai386(hp2)^.oper[1]),
  147. Reg8toReg32(TRegister(Pai386(hp3)^.oper[1])),
  148. RegInfo)
  149. Then
  150. Begin
  151. TmpResult := True;
  152. Inc(Found)
  153. End
  154. Else
  155. Begin
  156. TmpResult := False;
  157. If (Found > 0) Then
  158. Found := PPaiProp(Pai(p)^.OptInfo)^.Regs[Reg].NrOfMods
  159. End
  160. End
  161. Else *)
  162. Begin
  163. TmpResult := False;
  164. If (found > 0) then
  165. {this is correct because we only need to turn off the CanBeRemoved flag
  166. when an instruction has already been processed by CheckSequence
  167. (otherwise CanBeRemoved can't be true and thus can't have to be turned off).
  168. If it has already been processed by CheckSequence and flagged to be
  169. removed, it means that it has been checked against a previous sequence
  170. and that it was equal (otherwise CheckSequence would have returned false
  171. and the instruction wouldn't have been removed). If this "If found > 0"
  172. check is left out, incorrect optimizations are performed.}
  173. Found := PPaiProp(Pai(p)^.OptInfo)^.Regs[Reg].NrOfMods
  174. End
  175. End
  176. Else TmpResult := True;
  177. If TmpResult And
  178. (Found > HighFound)
  179. Then
  180. Begin
  181. HighFound := Found;
  182. HighRegInfo := RegInfo;
  183. End;
  184. If (RegCounter = Reg) Then
  185. Begin
  186. OrgRegFound := Found;
  187. OrgRegResult := TmpResult;
  188. OrgRegInfo := RegInfo
  189. End;
  190. Repeat
  191. Inc(RegCounter);
  192. Until (RegCounter > R_EDI) or
  193. ((PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter].Typ = Con_Ref) {And
  194. ((Regcounter = Reg) Or
  195. Not(PaiInSequence(p, PPaiProp(PrevNonRemovablePai^.OptInfo)^.Regs[RegCounter]))) }
  196. );
  197. End;
  198. If (HighFound > 0) And
  199. (Not(OrgRegResult) Or
  200. (HighFound > OrgRegFound))
  201. Then
  202. Begin
  203. CheckSequence := True;
  204. RegInfo := HighRegInfo;
  205. Found := HighFound
  206. End
  207. Else
  208. Begin
  209. CheckSequence := OrgRegResult;
  210. Found := OrgRegFound;
  211. RegInfo := OrgRegInfo;
  212. End;
  213. End; {CheckSequence}
  214. Procedure DoCSE(AsmL: PAasmOutput; First, Last: Pai);
  215. {marks the instructions that can be removed by RemoveInstructs. They're not
  216. removed immediately because sometimes an instruction needs to be checked in
  217. two different sequences}
  218. Var Cnt, Cnt2: Longint;
  219. p, hp1, hp2: Pai;
  220. hp3, hp4: Pai;
  221. {$ifdef csdebug}
  222. hp5: pai;
  223. {$endif csdebug}
  224. RegInfo: TRegInfo;
  225. RegCounter: TRegister;
  226. TmpState: Byte;
  227. Begin
  228. p := First;
  229. SkipHead(p);
  230. First := p;
  231. While (p <> Last) Do
  232. Begin
  233. Case p^.typ Of
  234. ait_instruction:
  235. Begin
  236. Case Pai386(p)^.opcode Of
  237. A_CLD: If GetLastInstruction(p, hp1) And
  238. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_NotSet) Then
  239. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  240. A_MOV, A_MOVZX, A_MOVSX:
  241. Begin
  242. Case Pai386(p)^.oper[0].typ Of
  243. { Top_Reg:
  244. Case Pai386(p)^.optype[1] Of
  245. Top_Reg:;
  246. Top_Ref:;
  247. End;}
  248. Top_Ref:
  249. Begin {destination is always a register in this case}
  250. With PPaiProp(p^.OptInfo)^.Regs[Reg32(Pai386(p)^.oper[1].reg)] Do
  251. Begin
  252. If GetLastInstruction (p, hp1) And
  253. (hp1^.typ <> ait_marker) Then
  254. {so we don't try to check a sequence when p is the first instruction of the block}
  255. If CheckSequence(p, Pai386(p)^.oper[1].reg, Cnt, RegInfo) And
  256. (Cnt > 0)
  257. Then
  258. Begin
  259. hp1 := nil;
  260. {although it's perfectly ok to remove an instruction which doesn't contain
  261. the register that we've just checked (CheckSequence takes care of that),
  262. the sequence containing this other register should also be completely
  263. checked and removed, otherwise we may get situations like this:
  264. movl 12(%ebp), %edx movl 12(%ebp), %edx
  265. movl 16(%ebp), %eax movl 16(%ebp), %eax
  266. movl 8(%edx), %edx movl 8(%edx), %edx
  267. movl (%eax), eax movl (%eax), eax
  268. cmpl %eax, %edx cmpl %eax, %edx
  269. jnz l123 getting converted to jnz l123
  270. movl 12(%ebp), %edx movl 4(%eax), eax
  271. movl 16(%ebp), %eax
  272. movl 8(%edx), %edx
  273. movl 4(%eax), eax}
  274. hp2 := p;
  275. Cnt2 := 1;
  276. While Cnt2 <= Cnt Do
  277. Begin
  278. If (hp1 = nil) And
  279. Not(RegInInstruction(Pai386(hp2)^.oper[1].reg, p) Or
  280. RegInInstruction(Reg32(Pai386(hp2)^.oper[1].reg), p))
  281. Then hp1 := p;
  282. {$ifndef noremove}
  283. PPaiProp(p^.OptInfo)^.CanBeRemoved := True;
  284. {$endif noremove}
  285. Inc(Cnt2);
  286. GetNextInstruction(p, p);
  287. End;
  288. hp3 := New(Pai_Marker,Init(NoPropInfoStart));
  289. InsertLLItem(AsmL, Pai(hp2^.Previous), hp2, hp3);
  290. {imagine the following code:
  291. normal wrong optimized
  292. movl 8(%ebp), %eax movl 8(%ebp), %eax
  293. movl (%eax), %eax movl (%eax), %eax
  294. cmpl 8(%ebp), %eax cmpl 8(%ebp), %eax
  295. jne l1 jne l1
  296. movl 8(%ebp), %eax
  297. movl (%eax), %edi movl %eax, %edi
  298. movl %edi, -4(%ebp) movl %edi, -4(%ebp)
  299. movl 8(%ebp), %eax
  300. pushl 70(%eax) pushl 70(%eax)
  301. The error is that at the moment that the last instruction is executed,
  302. %eax doesn't contain 8(%ebp) anymore. Solution: the contents of registers
  303. that are completely removed from a sequence, have to be changed to their
  304. contents from before the sequence.}
  305. {hp4 is used to get the contents of the registers before the sequence}
  306. GetLastInstruction(hp2, hp4);
  307. {If some registers were different in the old and the new sequence, move
  308. the contents of those old registers to the new ones}
  309. {$IfDef CSDebug}
  310. For RegCounter := R_EAX To R_EDI Do
  311. If (RegCounter in RegInfo.RegsLoadedForRef) Then
  312. Begin
  313. hp5 := new(pai_asm_comment,init(strpnew('New: '+att_reg2str[RegCounter]+', Old: '+
  314. att_reg2str[RegInfo.New2OldReg[RegCounter]])));
  315. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp5);
  316. End;
  317. {$EndIf CSDebug}
  318. For RegCounter := R_EAX To R_EDI Do
  319. Begin
  320. If (RegInfo.New2OldReg[RegCounter] <> R_NO) Then
  321. If Not(RegCounter In RegInfo.RegsLoadedForRef) And
  322. {old reg new reg}
  323. (RegInfo.New2OldReg[RegCounter] <> RegCounter) Then
  324. Begin
  325. hp3 := New(Pai386,Op_Reg_Reg(A_MOV, S_L,
  326. {old reg new reg}
  327. RegInfo.New2OldReg[RegCounter], RegCounter));
  328. hp3^.fileinfo := hp2^.fileinfo;
  329. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp3);
  330. End
  331. Else
  332. If (RegCounter In RegInfo.RegsLoadedForRef) Then
  333. {change the contents of this register to the its contents before the
  334. sequence (for all instructions in and after the sequence, until the register
  335. is reloaded)}
  336. Begin
  337. {load Cnt2 with the total number of instructions of this sequence}
  338. Cnt2 := PPaiProp(hp4^.OptInfo)^.
  339. Regs[RegInfo.New2OldReg[RegCounter]].NrOfMods;
  340. {sometimes, a register can not be removed from a sequence, because it's
  341. still used afterwards:
  342. movl -8(%ebp), %eax movl -8(%ebp), %eax
  343. movl 70(%eax), %eax movl 70(%eax), %eax
  344. cmpl 74(%eax), %eax cmpl 74(%eax), %eax
  345. jne l1 can't be changed to jne l1
  346. movl -8(%ebp), %eax
  347. movl 70(%eax), %edi movl %eax, %edi
  348. boundl R_282, %edi boundl R_282, %edi
  349. pushl 70(%eax) pushl 70(%eax)
  350. because eax now contains the wrong value when 70(%eax) is pushed}
  351. hp3 := hp2;
  352. For Cnt := 1 to Pred(Cnt2) Do
  353. GetNextInstruction(hp3, hp3);
  354. TmpState := PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState;
  355. GetNextInstruction(hp3, hp3);
  356. If (TmpState <> PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState) Or
  357. Not(RegCounter in PPaiProp(hp3^.OptInfo)^.UsedRegs) Then
  358. Begin
  359. {$ifdef csdebug}
  360. Writeln('Cnt2: ',Cnt2);
  361. hp5 := new(pai_asm_comment,init(strpnew('starting here...')));
  362. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp5);
  363. {$endif csdebug}
  364. hp3 := hp2;
  365. {first change the contents of the register inside the sequence}
  366. For Cnt := 1 to Cnt2 Do
  367. Begin
  368. {save the WState of the last pai object of the sequence for later use}
  369. TmpState := PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState;
  370. {$ifdef csdebug}
  371. hp5 := new(pai_asm_comment,init(strpnew('WState for '+att_reg2str[Regcounter]+': '
  372. +tostr(tmpstate))));
  373. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  374. {$endif csdebug}
  375. PPaiProp(hp3^.OptInfo)^.Regs[RegCounter] :=
  376. PPaiProp(hp4^.OptInfo)^.Regs[RegCounter];
  377. GetNextInstruction(hp3, hp3);
  378. End;
  379. {here, hp3 = p = Pai object right after the sequence, TmpState = WState of
  380. RegCounter at the last Pai object of the sequence}
  381. GetLastInstruction(hp3, hp3);
  382. While GetNextInstruction(hp3, hp3) And
  383. (PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState
  384. = TmpState) Do
  385. {$ifdef csdebug}
  386. begin
  387. hp5 := new(pai_asm_comment,init(strpnew('WState for '+att_reg2str[Regcounter]+': '+
  388. tostr(PPaiProp(hp3^.OptInfo)^.Regs[RegCounter].WState))));
  389. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  390. {$endif csdebug}
  391. PPaiProp(hp3^.OptInfo)^.Regs[RegCounter] :=
  392. PPaiProp(hp4^.OptInfo)^.Regs[RegCounter];
  393. {$ifdef csdebug}
  394. end;
  395. {$endif csdebug}
  396. End
  397. Else
  398. Begin
  399. {$ifdef csdebug}
  400. Writeln('Got there for ',att_Reg2Str[RegCounter]);
  401. {$endif csdebug}
  402. hp3 := hp2;
  403. For Cnt := 1 to Cnt2 Do
  404. Begin
  405. If RegModifiedByInstruction(RegCounter, hp3)
  406. Then PPaiProp(hp3^.OptInfo)^.CanBeRemoved := False;
  407. GetNextInstruction(hp3, hp3);
  408. End;
  409. End;
  410. {$ifdef csdebug}
  411. hp5 := new(pai_asm_comment,init(strpnew('stopping here...')));
  412. InsertLLItem(AsmL, hp3, pai(hp3^.next), hp5);
  413. {$endif csdebug}
  414. End;
  415. End;
  416. hp3 := New(Pai_Marker,Init(NoPropInfoEnd));
  417. InsertLLItem(AsmL, Pai(hp2^.Previous), hp2, hp3);
  418. If hp1 <> nil Then p := hp1;
  419. Continue;
  420. End
  421. Else
  422. If (Cnt > 0) And
  423. (PPaiProp(p^.OptInfo)^.
  424. Regs[Reg32(Pai386(p)^.oper[1].reg)].Typ = Con_Ref) And
  425. (PPaiProp(p^.OptInfo)^.CanBeRemoved) Then
  426. Begin
  427. hp2 := p;
  428. Cnt2 := 1;
  429. While Cnt2 <= Cnt Do
  430. Begin
  431. If RegInInstruction(Pai386(hp2)^.oper[1].reg, p) Or
  432. RegInInstruction(Reg32(Pai386(hp2)^.oper[1].reg), p) Then
  433. PPaiProp(p^.OptInfo)^.CanBeRemoved := False;
  434. Inc(Cnt2);
  435. GetNextInstruction(p, p);
  436. End;
  437. Continue;
  438. End;
  439. End;
  440. End;
  441. Top_Const:
  442. Begin
  443. Case Pai386(p)^.oper[1].typ Of
  444. Top_Reg:
  445. Begin
  446. If GetLastInstruction(p, hp1) Then
  447. With PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Pai386(p)^.oper[1].reg)] Do
  448. If (Typ = Con_Const) And
  449. (StartMod = p) Then
  450. PPaiProp(p^.OptInfo)^.CanBeRemoved := True;
  451. End;
  452. { Top_Ref:;}
  453. End;
  454. End;
  455. End;
  456. End;
  457. A_STD: If GetLastInstruction(p, hp1) And
  458. (PPaiProp(hp1^.OptInfo)^.DirFlag = F_Set) Then
  459. PPaiProp(Pai(p)^.OptInfo)^.CanBeRemoved := True;
  460. A_XOR:
  461. Begin
  462. If (Pai386(p)^.oper[0].typ = top_reg) And
  463. (Pai386(p)^.oper[0].typ = top_reg) And
  464. (Pai386(p)^.oper[1].reg = Pai386(p)^.oper[1].reg) And
  465. GetLastInstruction(p, hp1) And
  466. (PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Pai386(p)^.oper[1].reg)].typ = con_const) And
  467. (PPaiProp(hp1^.OptInfo)^.Regs[Reg32(Pai386(p)^.oper[1].reg)].StartMod = nil)
  468. Then PPaiProp(p^.OptInfo)^.CanBeRemoved := True
  469. End
  470. End
  471. End;
  472. End;
  473. GetNextInstruction(p, p);
  474. End;
  475. End;
  476. Procedure RemoveInstructs(AsmL: PAasmOutput; First, Last: Pai);
  477. {Removes the marked instructions and disposes the PPaiProps of the other
  478. instructions, restoring their line number}
  479. Var p, hp1: Pai;
  480. {$IfDef TP}
  481. TmpLine: Longint;
  482. {$EndIf TP}
  483. InstrCnt: Longint;
  484. Begin
  485. p := First;
  486. SkipHead(P);
  487. InstrCnt := 1;
  488. While (p <> Last) Do
  489. Begin
  490. {$ifndef noinstremove}
  491. If PPaiProp(p^.OptInfo)^.CanBeRemoved
  492. Then
  493. Begin
  494. {$IfDef TP}
  495. Dispose(PPaiProp(p^.OptInfo));
  496. {$EndIf}
  497. GetNextInstruction(p, hp1);
  498. AsmL^.Remove(p);
  499. Dispose(p, Done);
  500. p := hp1;
  501. Inc(InstrCnt);
  502. End
  503. Else
  504. {$endif noinstremove}
  505. Begin
  506. {$IfDef TP}
  507. Dispose(PPaiProp(p^.OptInfo));
  508. {$EndIf TP}
  509. p^.OptInfo := nil;
  510. GetNextInstruction(p, p);
  511. Inc(InstrCnt);
  512. End;
  513. End;
  514. {$IfNDef TP}
  515. FreeMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4))
  516. {$EndIf TP}
  517. End;
  518. Procedure CSE(AsmL: PAasmOutput; First, Last: Pai);
  519. Begin
  520. DoCSE(AsmL, First, Last);
  521. RemoveInstructs(AsmL, First, Last);
  522. End;
  523. End.
  524. {
  525. $Log$
  526. Revision 1.21 1999-05-08 20:38:03 jonas
  527. * seperate OPTimizer INFO pointer field in tai object
  528. Revision 1.20 1999/05/01 13:24:19 peter
  529. * merged nasm compiler
  530. * old asm moved to oldasm/
  531. Revision 1.2 1999/03/29 16:05:45 peter
  532. * optimizer working for ag386bin
  533. Revision 1.1 1999/03/26 00:01:09 peter
  534. * first things for optimizer (compiles but cycle crashes)
  535. Revision 1.19 1999/02/26 00:48:17 peter
  536. * assembler writers fixed for ag386bin
  537. Revision 1.18 1998/12/29 18:48:22 jonas
  538. + optimize pascal code surrounding assembler blocks
  539. Revision 1.17 1998/12/17 16:37:39 jonas
  540. + extra checks in RegsEquivalent so some more optimizations can be done (which
  541. where disabled by the second fix from revision 1.22)
  542. Revision 1.16 1998/12/02 16:23:31 jonas
  543. * changed "if longintvar in set" to case or "if () or () .." statements
  544. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  545. Revision 1.15 1998/11/24 19:47:24 jonas
  546. * fixed problems posiible with 3 operand instructions
  547. Revision 1.14 1998/11/09 19:40:48 jonas
  548. * fixed comments from last commit (apparently there's still a 255 char limit :( )
  549. Revision 1.13 1998/11/09 19:33:39 jonas
  550. * changed specific bugfix (which was actually wrong implemented, but
  551. did the right thing in most cases nevertheless) to general bugfix
  552. * fixed bug that caused
  553. mov (ebp), edx mov (ebp), edx
  554. mov (edx), edx mov (edx), edx
  555. ... being changed to ...
  556. mov (ebp), edx mov edx, eax
  557. mov (eax), eax
  558. but this disabled another small correct optimization...
  559. Revision 1.12 1998/10/20 09:32:54 peter
  560. * removed some unused vars
  561. Revision 1.11 1998/10/07 16:24:52 jonas
  562. * changed state to WState (WriteState), added RState for future use in
  563. instruction scheduling
  564. Revision 1.10 1998/10/02 17:29:23 jonas
  565. * much better interregister CSE
  566. Revision 1.9 1998/10/01 20:21:49 jonas
  567. * inter-register CSE, still requires some tweaks (peepholeoptpass2, better RegAlloc)
  568. Revision 1.8 1998/09/21 08:45:09 pierre
  569. + added vmt_offset in tobjectdef.write for fututre use
  570. (first steps to have objects without vmt if no virtual !!)
  571. + added fpu_used field for tabstractprocdef :
  572. sets this level to 2 if the functions return with value in FPU
  573. (is then set to correct value at parsing of implementation)
  574. THIS MIGHT refuse some code with FPU expression too complex
  575. that were accepted before and even in some cases
  576. that don't overflow in fact
  577. ( like if f : float; is a forward that finally in implementation
  578. only uses one fpu register !!)
  579. Nevertheless I think that it will improve security on
  580. FPU operations !!
  581. * most other changes only for UseBrowser code
  582. (added symtable references for record and objects)
  583. local switch for refs to args and local of each function
  584. (static symtable still missing)
  585. UseBrowser still not stable and probably broken by
  586. the definition hash array !!
  587. Revision 1.7 1998/09/20 17:12:35 jonas
  588. * small fix for uncertain optimizations & more cleaning up
  589. Revision 1.5 1998/09/16 17:59:59 jonas
  590. * optimizer now completely dependant on GetNext/GetLast instruction, works again with -dRegAlloc
  591. Revision 1.4 1998/08/06 19:40:27 jonas
  592. * removed $ before and after Log in comment
  593. Revision 1.3 1998/08/05 16:00:12 florian
  594. * some fixes for ansi strings
  595. * log to Log changed
  596. }