aoptobj.pas 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. {
  2. Copyright (c) 1998-2004 by Jonas Maebe, member of the Free Pascal
  3. Development Team
  4. This unit contains the processor independent assembler optimizer
  5. object, base for the dataflow analyzer, peepholeoptimizer and
  6. common subexpression elimination objects.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ****************************************************************************
  19. }
  20. Unit AoptObj;
  21. {$i fpcdefs.inc}
  22. { general, processor independent objects for use by the assembler optimizer }
  23. Interface
  24. uses
  25. globtype,
  26. aasmbase,aasmcpu,aasmtai,aasmdata,
  27. cclasses,
  28. cgbase,cgutils,
  29. cpubase,
  30. aoptbase,aoptcpub,aoptda;
  31. { ************************************************************************* }
  32. { ********************************* Constants ***************************** }
  33. { ************************************************************************* }
  34. Const
  35. {Possible register content types}
  36. con_Unknown = 0;
  37. con_ref = 1;
  38. con_const = 2;
  39. {***************** Types ****************}
  40. Type
  41. { ************************************************************************* }
  42. { ************************* Some general type definitions ***************** }
  43. { ************************************************************************* }
  44. TRefCompare = Function(const r1, r2: TReference): Boolean;
  45. //!!! FIXME
  46. TRegArray = Array[byte] of tsuperregister;
  47. TRegSet = Set of byte;
  48. { possible actions on an operand: read, write or modify (= read & write) }
  49. TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
  50. { ************************************************************************* }
  51. { * Object to hold information on which regiters are in use and which not * }
  52. { ************************************************************************* }
  53. { TUsedRegs }
  54. TUsedRegs = class
  55. Constructor create(aTyp : TRegisterType);
  56. Constructor create_regset(aTyp : TRegisterType;Const _RegSet: TRegSet);
  57. Destructor Destroy;override;
  58. Procedure Clear;
  59. { update the info with the pairegalloc objects coming after
  60. p }
  61. Procedure Update(p: Tai);
  62. { is Reg currently in use }
  63. Function IsUsed(Reg: TRegister): Boolean;
  64. { get all the currently used registers }
  65. Function GetUsedRegs: TRegSet;
  66. Private
  67. Typ : TRegisterType;
  68. UsedRegs: TRegSet;
  69. End;
  70. { ************************************************************************* }
  71. { ******************* Contents of the integer registers ******************* }
  72. { ************************************************************************* }
  73. { size of the integer that holds the state number of a register. Can be any }
  74. { integer type, so it can be changed to reduce the size of the TContent }
  75. { structure or to improve alignment }
  76. TStateInt = Byte;
  77. TContent = Record
  78. { start and end of block instructions that defines the }
  79. { content of this register. If Typ = con_const, then }
  80. { Longint(StartMod) = value of the constant) }
  81. StartMod: Tai;
  82. { starts at 0, gets increased everytime the register is }
  83. { written to }
  84. WState: TStateInt;
  85. { starts at 0, gets increased everytime the register is read }
  86. { from }
  87. RState: TStateInt;
  88. { how many instructions starting with StarMod does the block }
  89. { consist of }
  90. NrOfMods: Byte;
  91. { the type of the content of the register: unknown, memory }
  92. { (variable) or constant }
  93. Typ: Byte;
  94. End;
  95. //!!! FIXME
  96. TRegContent = Array[byte] Of TContent;
  97. { ************************************************************************** }
  98. { information object with the contents of every register. Every Tai object }
  99. { gets one of these assigned: a pointer to it is stored in the OptInfo field }
  100. { ************************************************************************** }
  101. { TPaiProp }
  102. TPaiProp = class(TAoptBaseCpu)
  103. Regs: TRegContent;
  104. { can this instruction be removed? }
  105. CanBeRemoved: Boolean;
  106. Constructor create; reintroduce;
  107. { checks the whole sequence of which (so regs[which].StartMod and and }
  108. { the next NrOfMods Tai objects) to see whether Reg is used somewhere, }
  109. { without it being loaded with something else first }
  110. Function RegInSequence(Reg, which: TRegister): Boolean;
  111. { destroy the contents of a register, as well as those whose contents }
  112. { are based on those of that register }
  113. Procedure DestroyReg(Reg: TRegister; var InstrSinceLastMod:
  114. TInstrSinceLastMod);
  115. { if the contents of WhichReg (can be R_NO in case of a constant) are }
  116. { written to memory at the location Ref, the contents of the registers }
  117. { that depend on Ref have to be destroyed }
  118. Procedure DestroyRefs(Const Ref: TReference; WhichReg: TRegister; var
  119. InstrSinceLastMod: TInstrSinceLastMod);
  120. { an instruction reads from operand o }
  121. Procedure ReadOp(const o:toper);
  122. { an instruction reads from reference Ref }
  123. Procedure ReadRef(Ref: PReference);
  124. { an instruction reads from register Reg }
  125. Procedure ReadReg(Reg: TRegister);
  126. { an instruction writes/modifies operand o and this has special }
  127. { side-effects or modifies the contents in such a way that we can't }
  128. { simply add this instruction to the sequence of instructions that }
  129. { describe the contents of the operand, so destroy it }
  130. Procedure DestroyOp(const o:Toper; var InstrSinceLastMod:
  131. TInstrSinceLastMod);
  132. { destroy the contents of all registers }
  133. Procedure DestroyAllRegs(var InstrSinceLastMod: TInstrSinceLastMod);
  134. { a register's contents are modified, but not destroyed (the new value }
  135. { depends on the old one) }
  136. Procedure ModifyReg(reg: TRegister; var InstrSinceLastMod:
  137. TInstrSinceLastMod);
  138. { an operand's contents are modified, but not destroyed (the new value }
  139. { depends on the old one) }
  140. Procedure ModifyOp(const oper: TOper; var InstrSinceLastMod:
  141. TInstrSinceLastMod);
  142. { increase the write state of a register (call every time a register is }
  143. { written to) }
  144. Procedure IncWState(Reg: TRegister);
  145. { increase the read state of a register (call every time a register is }
  146. { read from) }
  147. Procedure IncRState(Reg: TRegister);
  148. { get the write state of a register }
  149. Function GetWState(Reg: TRegister): TStateInt;
  150. { get the read state of a register }
  151. Function GetRState(Reg: TRegister): TStateInt;
  152. { get the type of contents of a register }
  153. Function GetRegContentType(Reg: TRegister): Byte;
  154. Destructor Done;
  155. Private
  156. Procedure IncState(var s: TStateInt);
  157. { returns whether the reference Ref is used somewhere in the loading }
  158. { sequence Content }
  159. Function RefInSequence(Const Ref: TReference; Content: TContent;
  160. RefsEq: TRefCompare): Boolean;
  161. { returns whether the instruction P reads from and/or writes }
  162. { to Reg }
  163. Function RefInInstruction(Const Ref: TReference; p: Tai;
  164. RefsEq: TRefCompare): Boolean;
  165. { returns whether two references with at least one pointing to an array }
  166. { may point to the same memory location }
  167. End;
  168. { ************************************************************************* }
  169. { ************************ Label information ****************************** }
  170. { ************************************************************************* }
  171. TLabelTableItem = Record
  172. PaiObj: Tai;
  173. End;
  174. TLabelTable = Array[0..2500000] Of TLabelTableItem;
  175. PLabelTable = ^TLabelTable;
  176. PLabelInfo = ^TLabelInfo;
  177. TLabelInfo = Record
  178. { the highest and lowest label number occurring in the current code }
  179. { fragment }
  180. LowLabel, HighLabel: longint;
  181. LabelDif: cardinal;
  182. { table that contains the addresses of the Pai_Label objects associated
  183. with each label number }
  184. LabelTable: PLabelTable;
  185. End;
  186. { ************************************************************************* }
  187. { ********** General optimizer object, used to derive others from ********* }
  188. { ************************************************************************* }
  189. TAllUsedRegs = array[TRegisterType] of TUsedRegs;
  190. { TAOptObj }
  191. TAOptObj = class(TAoptBaseCpu)
  192. { the PAasmOutput list this optimizer instance works on }
  193. AsmL: TAsmList;
  194. { The labelinfo record contains the addresses of the Tai objects }
  195. { that are labels, how many labels there are and the min and max }
  196. { label numbers }
  197. LabelInfo: PLabelInfo;
  198. { Start and end of the block that is currently being optimized }
  199. BlockStart, BlockEnd: Tai;
  200. DFA: TAOptDFA;
  201. UsedRegs: TAllUsedRegs;
  202. { _AsmL is the PAasmOutpout list that has to be optimized, }
  203. { _BlockStart and _BlockEnd the start and the end of the block }
  204. { that has to be optimized and _LabelInfo a pointer to a }
  205. { TLabelInfo record }
  206. Constructor create(_AsmL: TAsmList; _BlockStart, _BlockEnd: Tai;
  207. _LabelInfo: PLabelInfo); virtual; reintroduce;
  208. Destructor Destroy;override;
  209. { processor independent methods }
  210. Procedure ClearUsedRegs;
  211. Procedure UpdateUsedRegs(p : Tai);
  212. procedure UpdateUsedRegs(var Regs: TAllUsedRegs; p: Tai);
  213. Function CopyUsedRegs(var dest : TAllUsedRegs) : boolean;
  214. Procedure ReleaseUsedRegs(const regs : TAllUsedRegs);
  215. { returns true if the label L is found between hp and the next }
  216. { instruction }
  217. Function FindLabel(L: TasmLabel; Var hp: Tai): Boolean;
  218. { inserts new_one between prev and foll in AsmL }
  219. Procedure InsertLLItem(prev, foll, new_one: TLinkedListItem);
  220. { If P is a Tai object releveant to the optimizer, P is returned
  221. If it is not relevant tot he optimizer, the first object after P
  222. that is relevant is returned }
  223. Function SkipHead(P: Tai): Tai;
  224. { returns true if the operands o1 and o2 are completely equal }
  225. Function OpsEqual(const o1,o2:toper): Boolean;
  226. { Returns true if a ait_alloc object for Reg is found in the block
  227. of Tai's starting with StartPai and ending with the next "real"
  228. instruction }
  229. Function FindRegAlloc(Reg: TRegister; StartPai: Tai): Boolean;
  230. { reg used after p? }
  231. function RegUsedAfterInstruction(reg: Tregister; p: tai; var AllUsedRegs: TAllUsedRegs): Boolean;
  232. { traces sucessive jumps to their final destination and sets it, e.g.
  233. je l1 je l3
  234. <code> <code>
  235. l1: becomes l1:
  236. je l2 je l3
  237. <code> <code>
  238. l2: l2:
  239. jmp l3 jmp l3
  240. the level parameter denotes how deeep we have already followed the jump,
  241. to avoid endless loops with constructs such as "l5: ; jmp l5" }
  242. function GetFinalDestination(hp: taicpu; level: longint): boolean;
  243. function getlabelwithsym(sym: tasmlabel): tai;
  244. { peephole optimizer }
  245. procedure PrePeepHoleOpts;
  246. procedure PeepHoleOptPass1;
  247. procedure PeepHoleOptPass2; virtual;
  248. procedure PostPeepHoleOpts;
  249. { processor dependent methods }
  250. // if it returns true, perform a "continue"
  251. function PeepHoleOptPass1Cpu(var p: tai): boolean; virtual;
  252. function PostPeepHoleOptsCpu(var p: tai): boolean; virtual;
  253. End;
  254. Function ArrayRefsEq(const r1, r2: TReference): Boolean;
  255. { ***************************** Implementation **************************** }
  256. Implementation
  257. uses
  258. globals,
  259. verbose,
  260. procinfo;
  261. { ************************************************************************* }
  262. { ******************************** TUsedRegs ****************************** }
  263. { ************************************************************************* }
  264. Constructor TUsedRegs.create(aTyp : TRegisterType);
  265. Begin
  266. Typ:=aTyp;
  267. UsedRegs := [];
  268. End;
  269. Constructor TUsedRegs.create_regset(aTyp : TRegisterType;Const _RegSet: TRegSet);
  270. Begin
  271. Typ:=aTyp;
  272. UsedRegs := _RegSet;
  273. End;
  274. {
  275. updates UsedRegs with the RegAlloc Information coming after P
  276. }
  277. Procedure TUsedRegs.Update(p: Tai);
  278. Begin
  279. repeat
  280. while assigned(p) and
  281. ((p.typ in (SkipInstr - [ait_RegAlloc])) or
  282. ((p.typ = ait_label) and
  283. labelCanBeSkipped(tai_label(p))) or
  284. ((p.typ = ait_marker) and
  285. (tai_Marker(p).Kind in [mark_AsmBlockEnd,mark_NoLineInfoStart,mark_NoLineInfoEnd]))) do
  286. p := tai(p.next);
  287. while assigned(p) and
  288. (p.typ=ait_RegAlloc) Do
  289. begin
  290. if (getregtype(tai_regalloc(p).reg) = typ) then
  291. begin
  292. case tai_regalloc(p).ratype of
  293. ra_alloc :
  294. Include(UsedRegs, getsupreg(tai_regalloc(p).reg));
  295. ra_dealloc :
  296. Exclude(UsedRegs, getsupreg(tai_regalloc(p).reg));
  297. end;
  298. end;
  299. p := tai(p.next);
  300. end;
  301. until not(assigned(p)) or
  302. (not(p.typ in SkipInstr) and
  303. not((p.typ = ait_label) and
  304. labelCanBeSkipped(tai_label(p))));
  305. End;
  306. Function TUsedRegs.IsUsed(Reg: TRegister): Boolean;
  307. Begin
  308. IsUsed := (getregtype(Reg)=Typ) and (getsupreg(Reg) in UsedRegs);
  309. End;
  310. Function TUsedRegs.GetUsedRegs: TRegSet;
  311. Begin
  312. GetUsedRegs := UsedRegs;
  313. End;
  314. Destructor TUsedRegs.Destroy;
  315. Begin
  316. inherited destroy;
  317. end;
  318. procedure TUsedRegs.Clear;
  319. begin
  320. UsedRegs := [];
  321. end;
  322. { ************************************************************************* }
  323. { **************************** TPaiProp *********************************** }
  324. { ************************************************************************* }
  325. Constructor TPaiProp.Create;
  326. Begin
  327. {!!!!!!
  328. UsedRegs.Init;
  329. CondRegs.init;
  330. }
  331. { DirFlag: TFlagContents; I386 specific}
  332. End;
  333. Function TPaiProp.RegInSequence(Reg, which: TRegister): Boolean;
  334. {
  335. Var p: Tai;
  336. RegsChecked: TRegSet;
  337. content: TContent;
  338. Counter: Byte;
  339. TmpResult: Boolean;
  340. }
  341. begin
  342. Result:=False; { unimplemented }
  343. (*!!!!!!!!!!1
  344. RegsChecked := [];
  345. content := regs[which];
  346. p := content.StartMod;
  347. TmpResult := False;
  348. Counter := 1;
  349. While Not(TmpResult) And
  350. (Counter <= Content.NrOfMods) Do
  351. Begin
  352. If IsLoadMemReg(p) Then
  353. With PInstr(p)^.oper[LoadSrc]^.ref^ Do
  354. If (Base = ProcInfo.FramePointer)
  355. {$ifdef cpurefshaveindexreg}
  356. And (Index = R_NO)
  357. {$endif cpurefshaveindexreg} Then
  358. Begin
  359. RegsChecked := RegsChecked +
  360. [RegMaxSize(PInstr(p)^.oper[LoadDst]^.reg)];
  361. If Reg = RegMaxSize(PInstr(p)^.oper[LoadDst]^.reg) Then
  362. Break;
  363. End
  364. Else
  365. Begin
  366. If (Base = Reg) And
  367. Not(Base In RegsChecked)
  368. Then TmpResult := True;
  369. {$ifdef cpurefshaveindexreg}
  370. If Not(TmpResult) And
  371. (Index = Reg) And
  372. Not(Index In RegsChecked)
  373. Then TmpResult := True;
  374. {$Endif cpurefshaveindexreg}
  375. End
  376. Else TmpResult := RegInInstruction(Reg, p);
  377. Inc(Counter);
  378. GetNextInstruction(p,p)
  379. End;
  380. RegInSequence := TmpResult
  381. *)
  382. End;
  383. Procedure TPaiProp.DestroyReg(Reg: TRegister; var InstrSinceLastMod:
  384. TInstrSinceLastMod);
  385. { Destroys the contents of the register Reg in the PPaiProp p1, as well as }
  386. { the contents of registers are loaded with a memory location based on Reg }
  387. {
  388. Var TmpWState, TmpRState: Byte;
  389. Counter: TRegister;
  390. }
  391. Begin
  392. {!!!!!!!
  393. Reg := RegMaxSize(Reg);
  394. If (Reg in [LoGPReg..HiGPReg]) Then
  395. For Counter := LoGPReg to HiGPReg Do
  396. With Regs[Counter] Do
  397. If (Counter = reg) Or
  398. ((Typ = Con_Ref) And
  399. RegInSequence(Reg, Counter)) Then
  400. Begin
  401. InstrSinceLastMod[Counter] := 0;
  402. IncWState(Counter);
  403. TmpWState := GetWState(Counter);
  404. TmpRState := GetRState(Counter);
  405. FillChar(Regs[Counter], SizeOf(TContent), 0);
  406. WState := TmpWState;
  407. RState := TmpRState
  408. End
  409. }
  410. End;
  411. Function ArrayRefsEq(const r1, r2: TReference): Boolean;
  412. Begin
  413. Result:=False; { unimplemented }
  414. (*!!!!!!!!!!
  415. ArrayRefsEq := (R1.Offset+R1.OffsetFixup = R2.Offset+R2.OffsetFixup) And
  416. {$ifdef refsHaveSegmentReg}
  417. (R1.Segment = R2.Segment) And
  418. {$endif}
  419. (R1.Base = R2.Base) And
  420. (R1.Symbol=R2.Symbol);
  421. *)
  422. End;
  423. Procedure TPaiProp.DestroyRefs(Const Ref: TReference; WhichReg: TRegister;
  424. var InstrSinceLastMod: TInstrSinceLastMod);
  425. { destroys all registers which possibly contain a reference to Ref, WhichReg }
  426. { is the register whose contents are being written to memory (if this proc }
  427. { is called because of a "mov?? %reg, (mem)" instruction) }
  428. {
  429. Var RefsEq: TRefCompare;
  430. Counter: TRegister;
  431. }
  432. Begin
  433. (*!!!!!!!!!!!
  434. WhichReg := RegMaxSize(WhichReg);
  435. If (Ref.base = procinfo.FramePointer) or
  436. Assigned(Ref.Symbol) Then
  437. Begin
  438. If
  439. {$ifdef cpurefshaveindexreg}
  440. (Ref.Index = R_NO) And
  441. {$endif cpurefshaveindexreg}
  442. (Not(Assigned(Ref.Symbol)) or
  443. (Ref.base = R_NO)) Then
  444. { local variable which is not an array }
  445. RefsEq := @RefsEqual
  446. Else
  447. { local variable which is an array }
  448. RefsEq := @ArrayRefsEq;
  449. {write something to a parameter, a local or global variable, so
  450. * with uncertain optimizations on:
  451. - destroy the contents of registers whose contents have somewhere a
  452. "mov?? (Ref), %reg". WhichReg (this is the register whose contents
  453. are being written to memory) is not destroyed if it's StartMod is
  454. of that form and NrOfMods = 1 (so if it holds ref, but is not a
  455. pointer or value based on Ref)
  456. * with uncertain optimizations off:
  457. - also destroy registers that contain any pointer}
  458. For Counter := LoGPReg to HiGPReg Do
  459. With Regs[Counter] Do
  460. Begin
  461. If (typ = Con_Ref) And
  462. ((Not(cs_opt_size in current_settings.optimizerswitches) And
  463. (NrOfMods <> 1)
  464. ) Or
  465. (RefInSequence(Ref,Regs[Counter], RefsEq) And
  466. ((Counter <> WhichReg) Or
  467. ((NrOfMods <> 1) And
  468. {StarMod is always of the type ait_instruction}
  469. (PInstr(StartMod)^.oper[0].typ = top_ref) And
  470. RefsEq(PInstr(StartMod)^.oper[0].ref^, Ref)
  471. )
  472. )
  473. )
  474. )
  475. Then
  476. DestroyReg(Counter, InstrSinceLastMod)
  477. End
  478. End
  479. Else
  480. {write something to a pointer location, so
  481. * with uncertain optimzations on:
  482. - do not destroy registers which contain a local/global variable or a
  483. parameter, except if DestroyRefs is called because of a "movsl"
  484. * with uncertain optimzations off:
  485. - destroy every register which contains a memory location
  486. }
  487. For Counter := LoGPReg to HiGPReg Do
  488. With Regs[Counter] Do
  489. If (typ = Con_Ref) And
  490. (Not(cs_opt_size in current_settings.optimizerswitches) Or
  491. {$ifdef x86}
  492. {for movsl}
  493. (Ref.Base = R_EDI) Or
  494. {$endif}
  495. {don't destroy if reg contains a parameter, local or global variable}
  496. Not((NrOfMods = 1) And
  497. (PInstr(StartMod)^.oper[0].typ = top_ref) And
  498. ((PInstr(StartMod)^.oper[0].ref^.base = ProcInfo.FramePointer) Or
  499. Assigned(PInstr(StartMod)^.oper[0].ref^.Symbol)
  500. )
  501. )
  502. )
  503. Then DestroyReg(Counter, InstrSinceLastMod)
  504. *)
  505. End;
  506. Procedure TPaiProp.DestroyAllRegs(var InstrSinceLastMod: TInstrSinceLastMod);
  507. {Var Counter: TRegister;}
  508. Begin {initializes/desrtoys all registers}
  509. (*!!!!!!!!!
  510. For Counter := LoGPReg To HiGPReg Do
  511. Begin
  512. ReadReg(Counter);
  513. DestroyReg(Counter, InstrSinceLastMod);
  514. End;
  515. CondRegs.Init;
  516. { FPURegs.Init; }
  517. *)
  518. End;
  519. Procedure TPaiProp.DestroyOp(const o:Toper; var InstrSinceLastMod:
  520. TInstrSinceLastMod);
  521. Begin
  522. {!!!!!!!
  523. Case o.typ Of
  524. top_reg: DestroyReg(o.reg, InstrSinceLastMod);
  525. top_ref:
  526. Begin
  527. ReadRef(o.ref);
  528. DestroyRefs(o.ref^, R_NO, InstrSinceLastMod);
  529. End;
  530. top_symbol:;
  531. End;
  532. }
  533. End;
  534. Procedure TPaiProp.ReadReg(Reg: TRegister);
  535. Begin
  536. {!!!!!!!
  537. Reg := RegMaxSize(Reg);
  538. If Reg in General_Registers Then
  539. IncRState(RegMaxSize(Reg))
  540. }
  541. End;
  542. Procedure TPaiProp.ReadRef(Ref: PReference);
  543. Begin
  544. (*!!!!!!
  545. If Ref^.Base <> R_NO Then
  546. ReadReg(Ref^.Base);
  547. {$ifdef cpurefshaveindexreg}
  548. If Ref^.Index <> R_NO Then
  549. ReadReg(Ref^.Index);
  550. {$endif cpurefshaveindexreg}
  551. *)
  552. End;
  553. Procedure TPaiProp.ReadOp(const o:toper);
  554. Begin
  555. Case o.typ Of
  556. top_reg: ReadReg(o.reg);
  557. top_ref: ReadRef(o.ref);
  558. else
  559. internalerror(200410241);
  560. End;
  561. End;
  562. Procedure TPaiProp.ModifyReg(reg: TRegister; Var InstrSinceLastMod:
  563. TInstrSinceLastMod);
  564. Begin
  565. (*!!!!!!!
  566. With Regs[reg] Do
  567. If (Typ = Con_Ref)
  568. Then
  569. Begin
  570. IncState(WState);
  571. {also store how many instructions are part of the sequence in the first
  572. instructions PPaiProp, so it can be easily accessed from within
  573. CheckSequence}
  574. Inc(NrOfMods, InstrSinceLastMod[Reg]);
  575. PPaiProp(StartMod.OptInfo)^.Regs[Reg].NrOfMods := NrOfMods;
  576. InstrSinceLastMod[Reg] := 0;
  577. End
  578. Else
  579. DestroyReg(Reg, InstrSinceLastMod);
  580. *)
  581. End;
  582. Procedure TPaiProp.ModifyOp(const oper: TOper; var InstrSinceLastMod:
  583. TInstrSinceLastMod);
  584. Begin
  585. If oper.typ = top_reg Then
  586. ModifyReg(RegMaxSize(oper.reg),InstrSinceLastMod)
  587. Else
  588. Begin
  589. ReadOp(oper);
  590. DestroyOp(oper, InstrSinceLastMod);
  591. End
  592. End;
  593. Procedure TPaiProp.IncWState(Reg: TRegister);{$ifdef inl} inline;{$endif inl}
  594. Begin
  595. //!!!! IncState(Regs[Reg].WState);
  596. End;
  597. Procedure TPaiProp.IncRState(Reg: TRegister);{$ifdef inl} inline;{$endif inl}
  598. Begin
  599. //!!!! IncState(Regs[Reg].RState);
  600. End;
  601. Function TPaiProp.GetWState(Reg: TRegister): TStateInt; {$ifdef inl} inline;{$endif inl}
  602. Begin
  603. Result:=0; { unimplemented }
  604. //!!!! GetWState := Regs[Reg].WState
  605. End;
  606. Function TPaiProp.GetRState(Reg: TRegister): TStateInt; {$ifdef inl} inline;{$endif inl}
  607. Begin
  608. Result:=0; { unimplemented }
  609. //!!!! GetRState := Regs[Reg].RState
  610. End;
  611. Function TPaiProp.GetRegContentType(Reg: TRegister): Byte; {$ifdef inl} inline;{$endif inl}
  612. Begin
  613. Result:=0; { unimplemented }
  614. //!!!! GetRegContentType := Regs[Reg].typ
  615. End;
  616. Destructor TPaiProp.Done;
  617. Begin
  618. //!!!! UsedRegs.Done;
  619. //!!!! CondRegs.Done;
  620. { DirFlag: TFlagContents; I386 specific}
  621. End;
  622. { ************************ private TPaiProp stuff ************************* }
  623. Procedure TPaiProp.IncState(Var s: TStateInt); {$ifdef inl} inline;{$endif inl}
  624. Begin
  625. If s <> High(TStateInt) Then Inc(s)
  626. Else s := 0
  627. End;
  628. Function TPaiProp.RefInInstruction(Const Ref: TReference; p: Tai;
  629. RefsEq: TRefCompare): Boolean;
  630. Var Count: AWord;
  631. TmpResult: Boolean;
  632. Begin
  633. TmpResult := False;
  634. If (p.typ = ait_instruction) Then
  635. Begin
  636. Count := 0;
  637. Repeat
  638. If (TInstr(p).oper[Count]^.typ = Top_Ref) Then
  639. TmpResult := RefsEq(Ref, PInstr(p)^.oper[Count]^.ref^);
  640. Inc(Count);
  641. Until (Count = MaxOps) or TmpResult;
  642. End;
  643. RefInInstruction := TmpResult;
  644. End;
  645. Function TPaiProp.RefInSequence(Const Ref: TReference; Content: TContent;
  646. RefsEq: TRefCompare): Boolean;
  647. Var p: Tai;
  648. Counter: Byte;
  649. TmpResult: Boolean;
  650. Begin
  651. p := Content.StartMod;
  652. TmpResult := False;
  653. Counter := 1;
  654. While Not(TmpResult) And
  655. (Counter <= Content.NrOfMods) Do
  656. Begin
  657. If (p.typ = ait_instruction) And
  658. RefInInstruction(Ref, p, @references_equal)
  659. Then TmpResult := True;
  660. Inc(Counter);
  661. GetNextInstruction(p,p)
  662. End;
  663. RefInSequence := TmpResult
  664. End;
  665. { ************************************************************************* }
  666. { ***************************** TAoptObj ********************************** }
  667. { ************************************************************************* }
  668. Constructor TAoptObj.create(_AsmL: TAsmList; _BlockStart, _BlockEnd: Tai;
  669. _LabelInfo: PLabelInfo);
  670. var
  671. i : TRegisterType;
  672. Begin
  673. AsmL := _AsmL;
  674. BlockStart := _BlockStart;
  675. BlockEnd := _BlockEnd;
  676. LabelInfo := _LabelInfo;
  677. for i:=low(TRegisterType) to high(TRegisterType) do
  678. UsedRegs[i]:=TUsedRegs.Create(i);
  679. End;
  680. destructor TAOptObj.Destroy;
  681. var
  682. i : TRegisterType;
  683. begin
  684. for i:=low(TRegisterType) to high(TRegisterType) do
  685. UsedRegs[i].Destroy;
  686. inherited Destroy;
  687. end;
  688. procedure TAOptObj.ClearUsedRegs;
  689. var
  690. i : TRegisterType;
  691. begin
  692. for i:=low(TRegisterType) to high(TRegisterType) do
  693. UsedRegs[i].Clear;
  694. end;
  695. procedure TAOptObj.UpdateUsedRegs(p : Tai);
  696. var
  697. i : TRegisterType;
  698. begin
  699. for i:=low(TRegisterType) to high(TRegisterType) do
  700. UsedRegs[i].Update(p);
  701. end;
  702. procedure TAOptObj.UpdateUsedRegs(var Regs : TAllUsedRegs;p : Tai);
  703. var
  704. i : TRegisterType;
  705. begin
  706. for i:=low(TRegisterType) to high(TRegisterType) do
  707. Regs[i].Update(p);
  708. end;
  709. function TAOptObj.CopyUsedRegs(var dest: TAllUsedRegs): boolean;
  710. var
  711. i : TRegisterType;
  712. begin
  713. Result:=true;
  714. for i:=low(TRegisterType) to high(TRegisterType) do
  715. dest[i]:=TUsedRegs.Create_Regset(i,UsedRegs[i].GetUsedRegs);
  716. end;
  717. procedure TAOptObj.ReleaseUsedRegs(const regs: TAllUsedRegs);
  718. var
  719. i : TRegisterType;
  720. begin
  721. for i:=low(TRegisterType) to high(TRegisterType) do
  722. regs[i].Free;
  723. end;
  724. Function TAOptObj.FindLabel(L: TasmLabel; Var hp: Tai): Boolean;
  725. Var TempP: Tai;
  726. Begin
  727. TempP := hp;
  728. While Assigned(TempP) and
  729. (TempP.typ In SkipInstr + [ait_label]) Do
  730. If (TempP.typ <> ait_Label) Or
  731. (Tai_label(TempP).labsym <> L)
  732. Then GetNextInstruction(TempP, TempP)
  733. Else
  734. Begin
  735. hp := TempP;
  736. FindLabel := True;
  737. exit
  738. End;
  739. FindLabel := False;
  740. End;
  741. Procedure TAOptObj.InsertLLItem(prev, foll, new_one : TLinkedListItem);
  742. Begin
  743. If Assigned(prev) Then
  744. If Assigned(foll) Then
  745. Begin
  746. If Assigned(new_one) Then
  747. Begin
  748. new_one.previous := prev;
  749. new_one.next := foll;
  750. prev.next := new_one;
  751. foll.previous := new_one;
  752. { should we update line information? }
  753. if (not (tai(new_one).typ in SkipLineInfo)) and
  754. (not (tai(foll).typ in SkipLineInfo)) then
  755. Tailineinfo(new_one).fileinfo := Tailineinfo(foll).fileinfo
  756. End
  757. End
  758. Else AsmL.Concat(new_one)
  759. Else If Assigned(Foll) Then AsmL.Insert(new_one)
  760. End;
  761. Function TAOptObj.SkipHead(P: Tai): Tai;
  762. Var OldP: Tai;
  763. Begin
  764. Repeat
  765. OldP := P;
  766. If (P.typ in SkipInstr) Or
  767. ((P.typ = ait_marker) And
  768. (Tai_Marker(P).Kind = mark_AsmBlockEnd)) Then
  769. GetNextInstruction(P, P)
  770. Else If ((P.Typ = Ait_Marker) And
  771. (Tai_Marker(P).Kind = mark_NoPropInfoStart)) Then
  772. { a marker of the type mark_NoPropInfoStart can't be the first instruction of a }
  773. { paasmoutput list }
  774. GetNextInstruction(Tai(P.Previous),P);
  775. If (P.Typ = Ait_Marker) And
  776. (Tai_Marker(P).Kind = mark_AsmBlockStart) Then
  777. Begin
  778. P := Tai(P.Next);
  779. While (P.typ <> Ait_Marker) Or
  780. (Tai_Marker(P).Kind <> mark_AsmBlockEnd) Do
  781. P := Tai(P.Next)
  782. End;
  783. Until P = OldP;
  784. SkipHead := P;
  785. End;
  786. Function TAOptObj.OpsEqual(const o1,o2:toper): Boolean;
  787. Begin
  788. if o1.typ=o2.typ then
  789. Case o1.typ Of
  790. Top_Reg :
  791. OpsEqual:=o1.reg=o2.reg;
  792. Top_Ref :
  793. OpsEqual := references_equal(o1.ref^, o2.ref^);
  794. Top_Const :
  795. OpsEqual:=o1.val=o2.val;
  796. Top_None :
  797. OpsEqual := True
  798. else OpsEqual := False
  799. End
  800. else
  801. OpsEqual := False;
  802. End;
  803. Function TAOptObj.FindRegAlloc(Reg: TRegister; StartPai: Tai): Boolean;
  804. Begin
  805. FindRegAlloc:=False;
  806. Repeat
  807. While Assigned(StartPai) And
  808. ((StartPai.typ in (SkipInstr - [ait_regAlloc])) Or
  809. ((StartPai.typ = ait_label) and
  810. Not(Tai_Label(StartPai).labsym.Is_Used))) Do
  811. StartPai := Tai(StartPai.Next);
  812. If Assigned(StartPai) And
  813. (StartPai.typ = ait_regAlloc) and (tai_regalloc(StartPai).ratype=ra_alloc) Then
  814. Begin
  815. if tai_regalloc(StartPai).Reg = Reg then
  816. begin
  817. FindRegAlloc:=true;
  818. exit;
  819. end;
  820. StartPai := Tai(StartPai.Next);
  821. End
  822. else
  823. exit;
  824. Until false;
  825. End;
  826. function TAOptObj.RegUsedAfterInstruction(reg: Tregister; p: tai;
  827. var AllUsedRegs: TAllUsedRegs): Boolean;
  828. begin
  829. AllUsedRegs[getregtype(reg)].Update(tai(p.Next));
  830. RegUsedAfterInstruction :=
  831. (AllUsedRegs[getregtype(reg)].IsUsed(reg)); { optimization and
  832. (not(getNextInstruction(p,p)) or
  833. not(regLoadedWithNewValue(supreg,false,p))); }
  834. end;
  835. function SkipLabels(hp: tai; var hp2: tai): boolean;
  836. {skips all labels and returns the next "real" instruction}
  837. begin
  838. while assigned(hp.next) and
  839. (tai(hp.next).typ in SkipInstr + [ait_label,ait_align]) Do
  840. hp := tai(hp.next);
  841. if assigned(hp.next) then
  842. begin
  843. SkipLabels := True;
  844. hp2 := tai(hp.next)
  845. end
  846. else
  847. begin
  848. hp2 := hp;
  849. SkipLabels := False
  850. end;
  851. end;
  852. function FindAnyLabel(hp: tai; var l: tasmlabel): Boolean;
  853. begin
  854. FindAnyLabel := false;
  855. while assigned(hp.next) and
  856. (tai(hp.next).typ in (SkipInstr+[ait_align])) Do
  857. hp := tai(hp.next);
  858. if assigned(hp.next) and
  859. (tai(hp.next).typ = ait_label) then
  860. begin
  861. FindAnyLabel := true;
  862. l := tai_label(hp.next).labsym;
  863. end
  864. end;
  865. {$push}
  866. {$r-}
  867. function tAOptObj.getlabelwithsym(sym: tasmlabel): tai;
  868. begin
  869. if (int64(sym.labelnr) >= int64(labelinfo^.lowlabel)) and
  870. (int64(sym.labelnr) <= int64(labelinfo^.highlabel)) then { range check, a jump can go past an assembler block! }
  871. getlabelwithsym := labelinfo^.labeltable^[sym.labelnr-labelinfo^.lowlabel].paiobj
  872. else
  873. getlabelwithsym := nil;
  874. end;
  875. {$pop}
  876. function TAOptObj.GetFinalDestination(hp: taicpu; level: longint): boolean;
  877. {traces sucessive jumps to their final destination and sets it, e.g.
  878. je l1 je l3
  879. <code> <code>
  880. l1: becomes l1:
  881. je l2 je l3
  882. <code> <code>
  883. l2: l2:
  884. jmp l3 jmp l3
  885. the level parameter denotes how deeep we have already followed the jump,
  886. to avoid endless loops with constructs such as "l5: ; jmp l5" }
  887. var p1, p2: tai;
  888. l: tasmlabel;
  889. begin
  890. GetfinalDestination := false;
  891. if level > 20 then
  892. exit;
  893. p1 := getlabelwithsym(tasmlabel(hp.oper[0]^.ref^.symbol));
  894. if assigned(p1) then
  895. begin
  896. SkipLabels(p1,p1);
  897. if (tai(p1).typ = ait_instruction) and
  898. (taicpu(p1).is_jmp) then
  899. if { the next instruction after the label where the jump hp arrives}
  900. { is unconditional or of the same type as hp, so continue }
  901. (((taicpu(p1).opcode = aopt_uncondjmp) and
  902. {$ifdef arm}
  903. (taicpu(p1).condition = C_None) and
  904. {$endif arm}
  905. (taicpu(p1).oper[0]^.typ = top_ref) and
  906. (assigned(taicpu(p1).oper[0]^.ref^.symbol)) and
  907. (taicpu(p1).oper[0]^.ref^.symbol is TAsmLabel)) or
  908. conditions_equal(taicpu(p1).condition,hp.condition)) or
  909. { the next instruction after the label where the jump hp arrives}
  910. { is the opposite of hp (so this one is never taken), but after }
  911. { that one there is a branch that will be taken, so perform a }
  912. { little hack: set p1 equal to this instruction (that's what the}
  913. { last SkipLabels is for, only works with short bool evaluation)}
  914. (conditions_equal(taicpu(p1).condition,inverse_cond(hp.condition)) and
  915. SkipLabels(p1,p2) and
  916. (p2.typ = ait_instruction) and
  917. (taicpu(p2).is_jmp) and
  918. (((taicpu(p2).opcode = aopt_uncondjmp) and
  919. {$ifdef arm}
  920. (taicpu(p1).condition = C_None) and
  921. {$endif arm}
  922. (taicpu(p2).oper[0]^.typ = top_ref) and
  923. (assigned(taicpu(p2).oper[0]^.ref^.symbol)) and
  924. (taicpu(p2).oper[0]^.ref^.symbol is TAsmLabel)) or
  925. (conditions_equal(taicpu(p2).condition,hp.condition))) and
  926. SkipLabels(p1,p1)) then
  927. begin
  928. { quick check for loops of the form "l5: ; jmp l5 }
  929. if (tasmlabel(taicpu(p1).oper[0]^.ref^.symbol).labelnr =
  930. tasmlabel(hp.oper[0]^.ref^.symbol).labelnr) then
  931. exit;
  932. if not GetFinalDestination(taicpu(p1),succ(level)) then
  933. exit;
  934. tasmlabel(hp.oper[0]^.ref^.symbol).decrefs;
  935. hp.oper[0]^.ref^.symbol:=taicpu(p1).oper[0]^.ref^.symbol;
  936. tasmlabel(hp.oper[0]^.ref^.symbol).increfs;
  937. end
  938. else
  939. if conditions_equal(taicpu(p1).condition,inverse_cond(hp.condition)) then
  940. if not FindAnyLabel(p1,l) then
  941. begin
  942. {$ifdef finaldestdebug}
  943. insertllitem(asml,p1,p1.next,tai_comment.Create(
  944. strpnew('previous label inserted'))));
  945. {$endif finaldestdebug}
  946. current_asmdata.getjumplabel(l);
  947. insertllitem(p1,p1.next,tai_label.Create(l));
  948. tasmlabel(taicpu(hp).oper[0]^.ref^.symbol).decrefs;
  949. hp.oper[0]^.ref^.symbol := l;
  950. l.increfs;
  951. { this won't work, since the new label isn't in the labeltable }
  952. { so it will fail the rangecheck. Labeltable should become a }
  953. { hashtable to support this: }
  954. { GetFinalDestination(asml, hp); }
  955. end
  956. else
  957. begin
  958. {$ifdef finaldestdebug}
  959. insertllitem(asml,p1,p1.next,tai_comment.Create(
  960. strpnew('next label reused'))));
  961. {$endif finaldestdebug}
  962. l.increfs;
  963. tasmlabel(hp.oper[0]^.ref^.symbol).decrefs;
  964. hp.oper[0]^.ref^.symbol := l;
  965. if not GetFinalDestination(hp,succ(level)) then
  966. exit;
  967. end;
  968. end;
  969. GetFinalDestination := true;
  970. end;
  971. procedure TAOptObj.PrePeepHoleOpts;
  972. begin
  973. end;
  974. procedure TAOptObj.PeepHoleOptPass1;
  975. var
  976. p,hp1,hp2 : tai;
  977. begin
  978. p := BlockStart;
  979. ClearUsedRegs;
  980. while (p <> BlockEnd) Do
  981. begin
  982. UpdateUsedRegs(tai(p.next));
  983. if PeepHoleOptPass1Cpu(p) then
  984. continue;
  985. case p.Typ Of
  986. ait_instruction:
  987. begin
  988. { Handle Jmp Optimizations }
  989. if taicpu(p).is_jmp then
  990. begin
  991. { the following if-block removes all code between a jmp and the next label,
  992. because it can never be executed
  993. }
  994. if (taicpu(p).opcode = aopt_uncondjmp) and
  995. {$ifdef arm}
  996. (taicpu(p).condition = C_None) and
  997. {$endif arm}
  998. (taicpu(p).oper[0]^.typ = top_ref) and
  999. (assigned(taicpu(p).oper[0]^.ref^.symbol)) and
  1000. (taicpu(p).oper[0]^.ref^.symbol is TAsmLabel) then
  1001. begin
  1002. while GetNextInstruction(p, hp1) and
  1003. (hp1.typ <> ait_label) do
  1004. if not(hp1.typ in ([ait_label,ait_align]+skipinstr)) then
  1005. begin
  1006. if (hp1.typ = ait_instruction) and
  1007. taicpu(hp1).is_jmp and
  1008. (taicpu(hp1).oper[0]^.typ = top_ref) and
  1009. assigned(taicpu(hp1).oper[0]^.ref^.symbol) and
  1010. (taicpu(hp1).oper[0]^.ref^.symbol is TAsmLabel) then
  1011. TAsmLabel(taicpu(hp1).oper[0]^.ref^.symbol).decrefs;
  1012. asml.remove(hp1);
  1013. hp1.free;
  1014. end
  1015. else break;
  1016. end;
  1017. { remove jumps to a label coming right after them }
  1018. if GetNextInstruction(p, hp1) then
  1019. begin
  1020. if FindLabel(tasmlabel(taicpu(p).oper[0]^.ref^.symbol), hp1) and
  1021. { TODO: FIXME removing the first instruction fails}
  1022. (p<>blockstart) then
  1023. begin
  1024. hp2:=tai(hp1.next);
  1025. asml.remove(p);
  1026. tasmlabel(taicpu(p).oper[0]^.ref^.symbol).decrefs;
  1027. p.free;
  1028. p:=hp2;
  1029. continue;
  1030. end
  1031. else
  1032. begin
  1033. if hp1.typ = ait_label then
  1034. SkipLabels(hp1,hp1);
  1035. if (tai(hp1).typ=ait_instruction) and
  1036. (taicpu(hp1).opcode=aopt_uncondjmp) and
  1037. {$ifdef arm}
  1038. (taicpu(hp1).condition=C_None) and
  1039. {$endif arm}
  1040. (taicpu(hp1).oper[0]^.typ = top_ref) and
  1041. (assigned(taicpu(hp1).oper[0]^.ref^.symbol)) and
  1042. (taicpu(hp1).oper[0]^.ref^.symbol is TAsmLabel) and
  1043. GetNextInstruction(hp1, hp2) and
  1044. FindLabel(tasmlabel(taicpu(p).oper[0]^.ref^.symbol), hp2) then
  1045. begin
  1046. if (taicpu(p).opcode=aopt_condjmp)
  1047. {$ifdef arm}
  1048. and (taicpu(p).condition<>C_None)
  1049. {$endif arm}
  1050. then
  1051. begin
  1052. taicpu(p).condition:=inverse_cond(taicpu(p).condition);
  1053. tai_label(hp2).labsym.decrefs;
  1054. taicpu(p).oper[0]^.ref^.symbol:=taicpu(hp1).oper[0]^.ref^.symbol;
  1055. { when freeing hp1, the reference count
  1056. isn't decreased, so don't increase
  1057. taicpu(p).oper[0]^.ref^.symbol.increfs;
  1058. }
  1059. {$ifdef SPARC}
  1060. hp2:=tai(hp1.next);
  1061. asml.remove(hp2);
  1062. hp2.free;
  1063. {$endif SPARC}
  1064. asml.remove(hp1);
  1065. hp1.free;
  1066. GetFinalDestination(taicpu(p),0);
  1067. end
  1068. else
  1069. begin
  1070. GetFinalDestination(taicpu(p),0);
  1071. p:=tai(p.next);
  1072. continue;
  1073. end;
  1074. end
  1075. else
  1076. GetFinalDestination(taicpu(p),0);
  1077. end;
  1078. end;
  1079. end
  1080. else
  1081. { All other optimizes }
  1082. begin
  1083. end; { if is_jmp }
  1084. end;
  1085. end;
  1086. UpdateUsedRegs(p);
  1087. p:=tai(p.next);
  1088. end;
  1089. end;
  1090. procedure TAOptObj.PeepHoleOptPass2;
  1091. begin
  1092. end;
  1093. procedure TAOptObj.PostPeepHoleOpts;
  1094. var
  1095. p: tai;
  1096. begin
  1097. p := BlockStart;
  1098. ClearUsedRegs;
  1099. while (p <> BlockEnd) Do
  1100. begin
  1101. UpdateUsedRegs(tai(p.next));
  1102. if PostPeepHoleOptsCpu(p) then
  1103. continue;
  1104. UpdateUsedRegs(p);
  1105. p:=tai(p.next);
  1106. end;
  1107. end;
  1108. function TAOptObj.PeepHoleOptPass1Cpu(var p: tai): boolean;
  1109. begin
  1110. result := false;
  1111. end;
  1112. function TAOptObj.PostPeepHoleOptsCpu(var p: tai): boolean;
  1113. begin
  1114. result := false;
  1115. end;
  1116. End.