csopt386.pas 27 KB

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