daopt386.pas 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Jonas Maebe
  4. This unit contains the data flow analyzer and several helper procedures
  5. and functions.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. {$ifDef TP}
  20. {$UnDef JumpAnal}
  21. {$Endif TP}
  22. Unit DAOpt386;
  23. {$ifdef newOptimizations}
  24. {$define foropt}
  25. {$define replacereg}
  26. {$define arithopt}
  27. {$define foldarithops}
  28. {$endif newOptimizations}
  29. Interface
  30. Uses
  31. GlobType,
  32. CObjects,Aasm,
  33. cpubase,cpuasm;
  34. Type
  35. TRegArray = Array[R_EAX..R_BL] of TRegister;
  36. TRegSet = Set of R_EAX..R_BL;
  37. TRegInfo = Record
  38. NewRegsEncountered, OldRegsEncountered: TRegSet;
  39. RegsLoadedForRef: TRegSet;
  40. New2OldReg: TRegArray;
  41. End;
  42. {possible actions on an operand: read, write or modify (= read & write)}
  43. TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
  44. {*********************** Procedures and Functions ************************}
  45. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  46. Function Reg32(Reg: TRegister): TRegister;
  47. Function RefsEquivalent(Const R1, R2: TReference; Var RegInfo: TRegInfo; OpAct: TOpAction): Boolean;
  48. Function RefsEqual(Const R1, R2: TReference): Boolean;
  49. Function IsGP32Reg(Reg: TRegister): Boolean;
  50. Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
  51. Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
  52. {$ifdef newOptimizations}
  53. Function RegInOp(Reg: TRegister; const o:toper): Boolean;
  54. {$endif newOptimizations}
  55. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  56. Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
  57. Function GetLastInstruction(Current: Pai; Var Last: Pai): Boolean;
  58. Procedure SkipHead(var P: Pai);
  59. Procedure UpdateUsedRegs(Var UsedRegs: TRegSet; p: Pai);
  60. Function RegsEquivalent(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo; OpAct: TopAction): Boolean;
  61. Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
  62. Function OpsEqual(const o1,o2:toper): Boolean;
  63. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  64. Function DFAPass2(
  65. {$ifdef statedebug}
  66. AsmL: PAasmOutPut;
  67. {$endif statedebug}
  68. BlockStart, BlockEnd: Pai): Boolean;
  69. Procedure ShutDownDFA;
  70. Function FindLabel(L: PasmLabel; Var hp: Pai): Boolean;
  71. {******************************* Constants *******************************}
  72. Const
  73. {ait_* types which don't result in executable code or which don't influence
  74. the way the program runs/behaves}
  75. SkipInstr = [ait_comment, ait_symbol
  76. {$ifdef GDB}
  77. ,ait_stabs, ait_stabn, ait_stab_function_name
  78. {$endif GDB}
  79. ,ait_regalloc, ait_tempalloc
  80. ];
  81. {Possible register content types}
  82. con_Unknown = 0;
  83. con_ref = 1;
  84. con_const = 2;
  85. {********************************* Types *********************************}
  86. type
  87. {the possible states of a flag}
  88. TFlagContents = (F_Unknown, F_NotSet, F_Set);
  89. TContent = Packed Record
  90. {start and end of block instructions that defines the
  91. content of this register.}
  92. StartMod: pai;
  93. {starts at 0, gets increased everytime the register is written to}
  94. WState: Byte;
  95. {starts at 0, gets increased everytime the register is read from}
  96. RState: Byte;
  97. {how many instructions starting with StarMod does the block consist of}
  98. NrOfMods: Byte;
  99. {the type of the content of the register: unknown, memory, constant}
  100. Typ: Byte;
  101. End;
  102. {Contents of the integer registers}
  103. TRegContent = Array[R_EAX..R_EDI] Of TContent;
  104. {contents of the FPU registers}
  105. TRegFPUContent = Array[R_ST..R_ST7] Of TContent;
  106. {$ifdef tempOpts}
  107. { linked list which allows searching/deleting based on value, no extra frills}
  108. PSearchLinkedListItem = ^TSearchLinkedListItem;
  109. TSearchLinkedListItem = object(TLinkedList_Item)
  110. constructor init;
  111. function equals(p: PSearchLinkedListItem): boolean; virtual;
  112. end;
  113. PSearchDoubleIntItem = ^TSearchDoubleInttem;
  114. TSearchDoubleIntItem = object(TLinkedList_Item)
  115. constructor init(_int1,_int2: longint);
  116. function equals(p: PSearchLinkedListItem): boolean; virtual;
  117. private
  118. int1, int2: longint;
  119. end;
  120. PSearchLinkedList = ^TSearchLinkedList;
  121. TSearchLinkedList = object(TLinkedList)
  122. function searchByValue(p: PSearchLinkedListItem): boolean;
  123. procedure removeByValue(p: PSearchLinkedListItem);
  124. end;
  125. {$endif tempOpts}
  126. {information record with the contents of every register. Every Pai object
  127. gets one of these assigned: a pointer to it is stored in the OptInfo field}
  128. TPaiProp = Record
  129. Regs: TRegContent;
  130. { FPURegs: TRegFPUContent;} {currently not yet used}
  131. { allocated Registers }
  132. UsedRegs: TRegSet;
  133. { status of the direction flag }
  134. DirFlag: TFlagContents;
  135. {$ifdef tempOpts}
  136. { currently used temps }
  137. tempAllocs: PSearchLinkedList;
  138. {$endif tempOpts}
  139. { can this instruction be removed? }
  140. CanBeRemoved: Boolean;
  141. End;
  142. PPaiProp = ^TPaiProp;
  143. {$IfNDef TP}
  144. TPaiPropBlock = Array[1..250000] Of TPaiProp;
  145. PPaiPropBlock = ^TPaiPropBlock;
  146. {$EndIf TP}
  147. TInstrSinceLastMod = Array[R_EAX..R_EDI] Of Byte;
  148. TLabelTableItem = Record
  149. PaiObj: Pai;
  150. {$IfDef JumpAnal}
  151. InstrNr: Longint;
  152. RefsFound: Word;
  153. JmpsProcessed: Word
  154. {$EndIf JumpAnal}
  155. End;
  156. {$IfDef tp}
  157. TLabelTable = Array[0..10000] Of TLabelTableItem;
  158. {$Else tp}
  159. TLabelTable = Array[0..2500000] Of TLabelTableItem;
  160. {$Endif tp}
  161. PLabelTable = ^TLabelTable;
  162. {******************************* Variables *******************************}
  163. Var
  164. {the amount of PaiObjects in the current assembler list}
  165. NrOfPaiObjs: Longint;
  166. {$IfNDef TP}
  167. {Array which holds all TPaiProps}
  168. PaiPropBlock: PPaiPropBlock;
  169. {$EndIf TP}
  170. LoLab, HiLab, LabDif: Longint;
  171. LTable: PLabelTable;
  172. {*********************** End of Interface section ************************}
  173. Implementation
  174. Uses
  175. globals, systems, strings, verbose, hcodegen;
  176. Type
  177. TRefCompare = function(const r1, r2: TReference): Boolean;
  178. Var
  179. {How many instructions are between the current instruction and the last one
  180. that modified the register}
  181. NrOfInstrSinceLastMod: TInstrSinceLastMod;
  182. {$ifdef tempOpts}
  183. constructor TSearchLinkedListItem.init;
  184. begin
  185. end;
  186. function TSearchLinkedListItem.equals(p: PSearchLinkedListItem): boolean;
  187. begin
  188. equals := false;
  189. end;
  190. constructor TSearchDoubleIntItem.init(_int1,_int2: longint);
  191. begin
  192. int1 := _int1;
  193. int2 := _int2;
  194. end;
  195. function TSearchDoubleIntItem.equals(p: PSearchLinkedListItem): boolean;
  196. begin
  197. equals := (TSearchDoubleIntItem(p).int1 = int1) and
  198. (TSearchDoubleIntItem(p).int2 = int2);
  199. end;
  200. function TSearchLinkedList.searchByValue(p: PSearchLinkedListItem): boolean;
  201. var temp: PSearchLinkedListItem;
  202. begin
  203. temp := first;
  204. while (temp <> last^.next) and
  205. not(temp^.equals(p)) do
  206. temp := temp^.next;
  207. searchByValue := temp <> last^.next;
  208. end;
  209. procedure TSearchLinkedList.removeByValue(p: PSearchLinkedListItem);
  210. begin
  211. temp := first;
  212. while (temp <> last^.next) and
  213. not(temp^.equals(p)) do
  214. temp := temp^.next;
  215. if temp <> last^.next then
  216. begin
  217. remove(temp);
  218. dispose(temp,done);
  219. end;
  220. end;
  221. Procedure updateTempAllocs(Var UsedRegs: TRegSet; p: Pai);
  222. {updates UsedRegs with the RegAlloc Information coming after P}
  223. Begin
  224. Repeat
  225. While Assigned(p) And
  226. ((p^.typ in (SkipInstr - [ait_RegAlloc])) or
  227. ((p^.typ = ait_label) And
  228. Not(Pai_Label(p)^.l^.is_used))) Do
  229. p := Pai(p^.next);
  230. While Assigned(p) And
  231. (p^.typ=ait_RegAlloc) Do
  232. Begin
  233. if pairegalloc(p)^.allocation then
  234. UsedRegs := UsedRegs + [PaiRegAlloc(p)^.Reg]
  235. else
  236. UsedRegs := UsedRegs - [PaiRegAlloc(p)^.Reg];
  237. p := pai(p^.next);
  238. End;
  239. Until Not(Assigned(p)) Or
  240. (Not(p^.typ in SkipInstr) And
  241. Not((p^.typ = ait_label) And
  242. Not(Pai_Label(p)^.l^.is_used)));
  243. End;
  244. {$endif tempOpts}
  245. {************************ Create the Label table ************************}
  246. Function FindLoHiLabels(Var LowLabel, HighLabel, LabelDif: Longint; BlockStart: Pai): Pai;
  247. {Walks through the paasmlist to find the lowest and highest label number}
  248. Var LabelFound: Boolean;
  249. P: Pai;
  250. Begin
  251. LabelFound := False;
  252. LowLabel := MaxLongint;
  253. HighLabel := 0;
  254. P := BlockStart;
  255. While Assigned(P) And
  256. ((P^.typ <> Ait_Marker) Or
  257. (Pai_Marker(P)^.Kind <> AsmBlockStart)) Do
  258. Begin
  259. If (Pai(p)^.typ = ait_label) Then
  260. If (Pai_Label(p)^.l^.is_used)
  261. Then
  262. Begin
  263. LabelFound := True;
  264. If (Pai_Label(p)^.l^.labelnr < LowLabel) Then
  265. LowLabel := Pai_Label(p)^.l^.labelnr;
  266. If (Pai_Label(p)^.l^.labelnr > HighLabel) Then
  267. HighLabel := Pai_Label(p)^.l^.labelnr;
  268. End;
  269. GetNextInstruction(p, p);
  270. End;
  271. FindLoHiLabels := p;
  272. If LabelFound
  273. Then LabelDif := HighLabel+1-LowLabel
  274. Else LabelDif := 0;
  275. End;
  276. Function FindRegAlloc(Reg: TRegister; StartPai: Pai): Boolean;
  277. {Returns true if a ait_alloc object for Reg is found in the block of Pai's
  278. starting with StartPai and ending with the next "real" instruction}
  279. Begin
  280. FindRegAlloc:=False;
  281. Repeat
  282. While Assigned(StartPai) And
  283. ((StartPai^.typ in (SkipInstr - [ait_regAlloc])) Or
  284. ((StartPai^.typ = ait_label) and
  285. Not(Pai_Label(StartPai)^.l^.Is_Used))) Do
  286. StartPai := Pai(StartPai^.Next);
  287. If Assigned(StartPai) And
  288. (StartPai^.typ = ait_regAlloc) and (PairegAlloc(StartPai)^.allocation) Then
  289. Begin
  290. if PairegAlloc(StartPai)^.Reg = Reg then
  291. begin
  292. FindRegAlloc:=true;
  293. exit;
  294. end;
  295. StartPai := Pai(StartPai^.Next);
  296. End
  297. else
  298. exit;
  299. Until false;
  300. End;
  301. Procedure AddRegDeallocFor(asmL: paasmOutput; reg: TRegister; p: pai);
  302. var hp1: pai;
  303. begin
  304. hp1 := p;
  305. While GetLastInstruction(p, p) And
  306. Not(RegInInstruction(reg, p)) Do
  307. hp1 := p;
  308. p := New(PaiRegAlloc, DeAlloc(reg));
  309. InsertLLItem(AsmL, hp1^.previous, hp1, p);
  310. end;
  311. Procedure BuildLabelTableAndFixRegAlloc(asmL: PAasmOutput; Var LabelTable: PLabelTable; LowLabel: Longint;
  312. Var LabelDif: Longint; BlockStart, BlockEnd: Pai);
  313. {Builds a table with the locations of the labels in the paasmoutput.
  314. Also fixes some RegDeallocs like "# %eax released; push (%eax)"}
  315. Var p, hp1, hp2, lastP: Pai;
  316. regCounter: TRegister;
  317. UsedRegs: TRegSet;
  318. Begin
  319. UsedRegs := [];
  320. If (LabelDif <> 0) Then
  321. Begin
  322. {$IfDef TP}
  323. If (MaxAvail >= LabelDif*SizeOf(Pai))
  324. Then
  325. Begin
  326. {$EndIf TP}
  327. GetMem(LabelTable, LabelDif*SizeOf(TLabelTableItem));
  328. FillChar(LabelTable^, LabelDif*SizeOf(TLabelTableItem), 0);
  329. {$IfDef TP}
  330. End
  331. Else LabelDif := 0;
  332. {$EndIf TP}
  333. End;
  334. p := BlockStart;
  335. lastP := p;
  336. While (P <> BlockEnd) Do
  337. Begin
  338. Case p^.typ Of
  339. ait_Label:
  340. If Pai_Label(p)^.l^.is_used Then
  341. LabelTable^[Pai_Label(p)^.l^.labelnr-LowLabel].PaiObj := p;
  342. ait_regAlloc:
  343. { ESI and EDI are (de)allocated manually, don't mess with them }
  344. if not(paiRegAlloc(p)^.Reg in [R_EDI,R_ESI]) then
  345. begin
  346. if PairegAlloc(p)^.Allocation then
  347. Begin
  348. If Not(paiRegAlloc(p)^.Reg in UsedRegs) Then
  349. UsedRegs := UsedRegs + [paiRegAlloc(p)^.Reg]
  350. Else
  351. addRegDeallocFor(asmL, paiRegAlloc(p)^.reg, p);
  352. End
  353. else
  354. Begin
  355. UsedRegs := UsedRegs - [paiRegAlloc(p)^.Reg];
  356. hp1 := p;
  357. hp2 := nil;
  358. While Not(FindRegAlloc(paiRegAlloc(p)^.Reg, Pai(hp1^.Next))) And
  359. GetNextInstruction(hp1, hp1) And
  360. RegInInstruction(paiRegAlloc(p)^.Reg, hp1) Do
  361. hp2 := hp1;
  362. If hp2 <> nil Then
  363. Begin
  364. hp1 := Pai(p^.previous);
  365. AsmL^.Remove(p);
  366. InsertLLItem(AsmL, hp2, Pai(hp2^.Next), p);
  367. p := hp1;
  368. End;
  369. End;
  370. end;
  371. End;
  372. repeat
  373. lastP := p;
  374. P := Pai(P^.Next);
  375. until not(Assigned(p) And
  376. (p^.typ in (SkipInstr - [ait_regalloc])));
  377. End;
  378. for regCounter := R_EAX to R_EDI do
  379. if regCounter in usedRegs then
  380. addRegDeallocFor(asmL,regCounter,lastP);
  381. End;
  382. {************************ Search the Label table ************************}
  383. Function FindLabel(L: PasmLabel; Var hp: Pai): Boolean;
  384. {searches for the specified label starting from hp as long as the
  385. encountered instructions are labels, to be able to optimize constructs like
  386. jne l2 jmp l2
  387. jmp l3 and l1:
  388. l1: l2:
  389. l2:}
  390. Var TempP: Pai;
  391. Begin
  392. TempP := hp;
  393. While Assigned(TempP) and
  394. (TempP^.typ In SkipInstr + [ait_label,ait_align]) Do
  395. If (TempP^.typ <> ait_Label) Or
  396. (pai_label(TempP)^.l <> L)
  397. Then GetNextInstruction(TempP, TempP)
  398. Else
  399. Begin
  400. hp := TempP;
  401. FindLabel := True;
  402. exit
  403. End;
  404. FindLabel := False;
  405. End;
  406. {************************ Some general functions ************************}
  407. Function TCh2Reg(Ch: TInsChange): TRegister;
  408. {converts a TChange variable to a TRegister}
  409. Begin
  410. If (Ch <= Ch_REDI) Then
  411. TCh2Reg := TRegister(Byte(Ch))
  412. Else
  413. If (Ch <= Ch_WEDI) Then
  414. TCh2Reg := TRegister(Byte(Ch) - Byte(Ch_REDI))
  415. Else
  416. If (Ch <= Ch_RWEDI) Then
  417. TCh2Reg := TRegister(Byte(Ch) - Byte(Ch_WEDI))
  418. Else
  419. If (Ch <= Ch_MEDI) Then
  420. TCh2Reg := TRegister(Byte(Ch) - Byte(Ch_RWEDI))
  421. Else InternalError($db)
  422. End;
  423. Function Reg32(Reg: TRegister): TRegister;
  424. {Returns the 32 bit component of Reg if it exists, otherwise Reg is returned}
  425. Begin
  426. Reg32 := Reg;
  427. If (Reg >= R_AX)
  428. Then
  429. If (Reg <= R_DI)
  430. Then Reg32 := Reg16ToReg32(Reg)
  431. Else
  432. If (Reg <= R_BL)
  433. Then Reg32 := Reg8toReg32(Reg);
  434. End;
  435. { inserts new_one between prev and foll }
  436. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  437. Begin
  438. If Assigned(prev) Then
  439. If Assigned(foll) Then
  440. Begin
  441. If Assigned(new_one) Then
  442. Begin
  443. new_one^.previous := prev;
  444. new_one^.next := foll;
  445. prev^.next := new_one;
  446. foll^.previous := new_one;
  447. Pai(new_one)^.fileinfo := Pai(foll)^.fileinfo;
  448. End;
  449. End
  450. Else AsmL^.Concat(new_one)
  451. Else If Assigned(Foll) Then AsmL^.Insert(new_one)
  452. End;
  453. {********************* Compare parts of Pai objects *********************}
  454. Function RegsSameSize(Reg1, Reg2: TRegister): Boolean;
  455. {returns true if Reg1 and Reg2 are of the same size (so if they're both
  456. 8bit, 16bit or 32bit)}
  457. Begin
  458. If (Reg1 <= R_EDI)
  459. Then RegsSameSize := (Reg2 <= R_EDI)
  460. Else
  461. If (Reg1 <= R_DI)
  462. Then RegsSameSize := (Reg2 in [R_AX..R_DI])
  463. Else
  464. If (Reg1 <= R_BL)
  465. Then RegsSameSize := (Reg2 in [R_AL..R_BL])
  466. Else RegsSameSize := False
  467. End;
  468. Procedure AddReg2RegInfo(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo);
  469. {updates the ???RegsEncountered and ???2???Reg fields of RegInfo. Assumes that
  470. OldReg and NewReg have the same size (has to be chcked in advance with
  471. RegsSameSize) and that neither equals R_NO}
  472. Begin
  473. With RegInfo Do
  474. Begin
  475. NewRegsEncountered := NewRegsEncountered + [NewReg];
  476. OldRegsEncountered := OldRegsEncountered + [OldReg];
  477. New2OldReg[NewReg] := OldReg;
  478. Case OldReg Of
  479. R_EAX..R_EDI:
  480. Begin
  481. NewRegsEncountered := NewRegsEncountered + [Reg32toReg16(NewReg)];
  482. OldRegsEncountered := OldRegsEncountered + [Reg32toReg16(OldReg)];
  483. New2OldReg[Reg32toReg16(NewReg)] := Reg32toReg16(OldReg);
  484. If (NewReg in [R_EAX..R_EBX]) And
  485. (OldReg in [R_EAX..R_EBX]) Then
  486. Begin
  487. NewRegsEncountered := NewRegsEncountered + [Reg32toReg8(NewReg)];
  488. OldRegsEncountered := OldRegsEncountered + [Reg32toReg8(OldReg)];
  489. New2OldReg[Reg32toReg8(NewReg)] := Reg32toReg8(OldReg);
  490. End;
  491. End;
  492. R_AX..R_DI:
  493. Begin
  494. NewRegsEncountered := NewRegsEncountered + [Reg16toReg32(NewReg)];
  495. OldRegsEncountered := OldRegsEncountered + [Reg16toReg32(OldReg)];
  496. New2OldReg[Reg16toReg32(NewReg)] := Reg16toReg32(OldReg);
  497. If (NewReg in [R_AX..R_BX]) And
  498. (OldReg in [R_AX..R_BX]) Then
  499. Begin
  500. NewRegsEncountered := NewRegsEncountered + [Reg16toReg8(NewReg)];
  501. OldRegsEncountered := OldRegsEncountered + [Reg16toReg8(OldReg)];
  502. New2OldReg[Reg16toReg8(NewReg)] := Reg16toReg8(OldReg);
  503. End;
  504. End;
  505. R_AL..R_BL:
  506. Begin
  507. NewRegsEncountered := NewRegsEncountered + [Reg8toReg32(NewReg)]
  508. + [Reg8toReg16(NewReg)];
  509. OldRegsEncountered := OldRegsEncountered + [Reg8toReg32(OldReg)]
  510. + [Reg8toReg16(OldReg)];
  511. New2OldReg[Reg8toReg32(NewReg)] := Reg8toReg32(OldReg);
  512. End;
  513. End;
  514. End;
  515. End;
  516. Procedure AddOp2RegInfo(const o:Toper; Var RegInfo: TRegInfo);
  517. Begin
  518. Case o.typ Of
  519. Top_Reg:
  520. If (o.reg <> R_NO) Then
  521. AddReg2RegInfo(o.reg, o.reg, RegInfo);
  522. Top_Ref:
  523. Begin
  524. If o.ref^.base <> R_NO Then
  525. AddReg2RegInfo(o.ref^.base, o.ref^.base, RegInfo);
  526. If o.ref^.index <> R_NO Then
  527. AddReg2RegInfo(o.ref^.index, o.ref^.index, RegInfo);
  528. End;
  529. End;
  530. End;
  531. Function RegsEquivalent(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo; OPAct: TOpAction): Boolean;
  532. Begin
  533. If Not((OldReg = R_NO) Or (NewReg = R_NO)) Then
  534. If RegsSameSize(OldReg, NewReg) Then
  535. With RegInfo Do
  536. {here we always check for the 32 bit component, because it is possible that
  537. the 8 bit component has not been set, event though NewReg already has been
  538. processed. This happens if it has been compared with a register that doesn't
  539. have an 8 bit component (such as EDI). In that case the 8 bit component is
  540. still set to R_NO and the comparison in the Else-part will fail}
  541. If (Reg32(OldReg) in OldRegsEncountered) Then
  542. If (Reg32(NewReg) in NewRegsEncountered) Then
  543. RegsEquivalent := (OldReg = New2OldReg[NewReg])
  544. { If we haven't encountered the new register yet, but we have encountered the
  545. old one already, the new one can only be correct if it's being written to
  546. (and consequently the old one is also being written to), otherwise
  547. movl -8(%ebp), %eax and movl -8(%ebp), %eax
  548. movl (%eax), %eax movl (%edx), %edx
  549. are considered equivalent}
  550. Else
  551. If (OpAct = OpAct_Write) Then
  552. Begin
  553. AddReg2RegInfo(OldReg, NewReg, RegInfo);
  554. RegsEquivalent := True
  555. End
  556. Else Regsequivalent := False
  557. Else
  558. If Not(Reg32(NewReg) in NewRegsEncountered) Then
  559. Begin
  560. AddReg2RegInfo(OldReg, NewReg, RegInfo);
  561. RegsEquivalent := True
  562. End
  563. Else RegsEquivalent := False
  564. Else RegsEquivalent := False
  565. Else RegsEquivalent := OldReg = NewReg
  566. End;
  567. Function RefsEquivalent(Const R1, R2: TReference; var RegInfo: TRegInfo; OpAct: TOpAction): Boolean;
  568. Begin
  569. If R1.is_immediate Then
  570. RefsEquivalent := R2.is_immediate and (R1.Offset = R2.Offset)
  571. Else
  572. RefsEquivalent := (R1.Offset+R1.OffsetFixup = R2.Offset+R2.OffsetFixup) And
  573. RegsEquivalent(R1.Base, R2.Base, RegInfo, OpAct) And
  574. RegsEquivalent(R1.Index, R2.Index, RegInfo, OpAct) And
  575. (R1.Segment = R2.Segment) And (R1.ScaleFactor = R2.ScaleFactor) And
  576. (R1.Symbol = R2.Symbol);
  577. End;
  578. Function RefsEqual(Const R1, R2: TReference): Boolean;
  579. Begin
  580. If R1.is_immediate Then
  581. RefsEqual := R2.is_immediate and (R1.Offset = R2.Offset)
  582. Else
  583. RefsEqual := (R1.Offset+R1.OffsetFixup = R2.Offset+R2.OffsetFixup) And
  584. (R1.Segment = R2.Segment) And (R1.Base = R2.Base) And
  585. (R1.Index = R2.Index) And (R1.ScaleFactor = R2.ScaleFactor) And
  586. (R1.Symbol=R2.Symbol);
  587. End;
  588. Function IsGP32Reg(Reg: TRegister): Boolean;
  589. {Checks if the register is a 32 bit general purpose register}
  590. Begin
  591. If (Reg >= R_EAX) and (Reg <= R_EBX)
  592. Then IsGP32Reg := True
  593. Else IsGP32reg := False
  594. End;
  595. Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
  596. Begin {checks whether Ref contains a reference to Reg}
  597. Reg := Reg32(Reg);
  598. RegInRef := (Ref.Base = Reg) Or (Ref.Index = Reg)
  599. End;
  600. Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
  601. {checks if Reg is used by the instruction p1}
  602. Var Counter: Longint;
  603. TmpResult: Boolean;
  604. Begin
  605. TmpResult := False;
  606. If (Pai(p1)^.typ = ait_instruction) Then
  607. Begin
  608. Reg := Reg32(Reg);
  609. Counter := 0;
  610. Repeat
  611. Case Paicpu(p1)^.oper[Counter].typ Of
  612. Top_Reg: TmpResult := Reg = Reg32(Paicpu(p1)^.oper[Counter].reg);
  613. Top_Ref: TmpResult := RegInRef(Reg, Paicpu(p1)^.oper[Counter].ref^);
  614. End;
  615. Inc(Counter)
  616. Until (Counter = 3) or TmpResult;
  617. End;
  618. RegInInstruction := TmpResult
  619. End;
  620. {$ifdef newOptimizations}
  621. Function RegInOp(Reg: TRegister; const o:toper): Boolean;
  622. Begin
  623. RegInOp := False;
  624. Case o.typ Of
  625. top_reg: RegInOp := Reg = o.reg;
  626. top_ref: RegInOp := (Reg = o.ref^.Base) Or
  627. (Reg = o.ref^.Index);
  628. End;
  629. End;
  630. {$endif newOptimizations}
  631. (*
  632. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  633. {returns true if Reg is modified by the instruction p1. P1 is assumed to be
  634. of the type ait_instruction}
  635. Var hp: Pai;
  636. Begin
  637. If GetLastInstruction(p1, hp)
  638. Then
  639. RegModifiedByInstruction :=
  640. PPAiProp(p1^.OptInfo)^.Regs[Reg].WState <>
  641. PPAiProp(hp^.OptInfo)^.Regs[Reg].WState
  642. Else RegModifiedByInstruction := True;
  643. End;
  644. *)
  645. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  646. Var InstrProp: TInsProp;
  647. TmpResult: Boolean;
  648. Cnt: Byte;
  649. Begin
  650. TmpResult := False;
  651. Reg := Reg32(Reg);
  652. If (p1^.typ = ait_instruction) Then
  653. Case paicpu(p1)^.opcode of
  654. A_IMUL:
  655. With paicpu(p1)^ Do
  656. TmpResult :=
  657. ((ops = 1) and (reg = R_EAX)) or
  658. ((ops = 2) and (Reg32(oper[1].reg) = reg)) or
  659. ((ops = 3) and (Reg32(oper[2].reg) = reg));
  660. A_DIV, A_IDIV, A_MUL:
  661. With paicpu(p1)^ Do
  662. TmpResult :=
  663. (Reg = R_EAX) or
  664. (Reg = R_EDX);
  665. Else
  666. Begin
  667. Cnt := 1;
  668. InstrProp := InsProp[paicpu(p1)^.OpCode];
  669. While (Cnt <= MaxCh) And
  670. (InstrProp.Ch[Cnt] <> Ch_None) And
  671. Not(TmpResult) Do
  672. Begin
  673. Case InstrProp.Ch[Cnt] Of
  674. Ch_WEAX..Ch_MEDI:
  675. TmpResult := Reg = TCh2Reg(InstrProp.Ch[Cnt]);
  676. Ch_RWOp1,Ch_WOp1{$ifdef arithopt},Ch_Mop1{$endif arithopt}:
  677. TmpResult := (paicpu(p1)^.oper[0].typ = top_reg) and
  678. (Reg32(paicpu(p1)^.oper[0].reg) = reg);
  679. Ch_RWOp2,Ch_WOp2{$ifdef arithopt},Ch_Mop2{$endif arithopt}:
  680. TmpResult := (paicpu(p1)^.oper[1].typ = top_reg) and
  681. (Reg32(paicpu(p1)^.oper[1].reg) = reg);
  682. Ch_RWOp3,Ch_WOp3{$ifdef arithopt},Ch_Mop3{$endif arithopt}:
  683. TmpResult := (paicpu(p1)^.oper[2].typ = top_reg) and
  684. (Reg32(paicpu(p1)^.oper[2].reg) = reg);
  685. Ch_FPU: TmpResult := Reg in [R_ST..R_ST7,R_MM0..R_MM7];
  686. Ch_ALL: TmpResult := true;
  687. End;
  688. Inc(Cnt)
  689. End
  690. End
  691. End;
  692. RegModifiedByInstruction := TmpResult
  693. End;
  694. {********************* GetNext and GetLastInstruction *********************}
  695. Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
  696. {skips ait_regalloc, ait_regdealloc and ait_stab* objects and puts the
  697. next pai object in Next. Returns false if there isn't any}
  698. Begin
  699. Repeat
  700. If (Current^.typ = ait_marker) And
  701. (Pai_Marker(Current)^.Kind = AsmBlockStart) Then
  702. Begin
  703. GetNextInstruction := False;
  704. Next := Nil;
  705. Exit
  706. End;
  707. Current := Pai(Current^.Next);
  708. While Assigned(Current) And
  709. ((Current^.typ In SkipInstr) or
  710. ((Current^.typ = ait_label) And
  711. Not(Pai_Label(Current)^.l^.is_used))) Do
  712. Current := Pai(Current^.Next);
  713. If Assigned(Current) And
  714. (Current^.typ = ait_Marker) And
  715. (Pai_Marker(Current)^.Kind = NoPropInfoStart) Then
  716. Begin
  717. While Assigned(Current) And
  718. ((Current^.typ <> ait_Marker) Or
  719. (Pai_Marker(Current)^.Kind <> NoPropInfoEnd)) Do
  720. Current := Pai(Current^.Next);
  721. End;
  722. Until Not(Assigned(Current)) Or
  723. (Current^.typ <> ait_Marker) Or
  724. (Pai_Marker(Current)^.Kind <> NoPropInfoEnd);
  725. Next := Current;
  726. If Assigned(Current) And
  727. Not((Current^.typ In SkipInstr) or
  728. ((Current^.typ = ait_label) And
  729. Not(Pai_Label(Current)^.l^.is_used)))
  730. Then GetNextInstruction := True
  731. Else
  732. Begin
  733. GetNextInstruction := False;
  734. Next := nil;
  735. End;
  736. End;
  737. Function GetLastInstruction(Current: Pai; Var Last: Pai): Boolean;
  738. {skips the ait-types in SkipInstr puts the previous pai object in
  739. Last. Returns false if there isn't any}
  740. Begin
  741. Repeat
  742. Current := Pai(Current^.previous);
  743. While Assigned(Current) And
  744. (((Current^.typ = ait_Marker) And
  745. Not(Pai_Marker(Current)^.Kind in [AsmBlockEnd,NoPropInfoEnd])) or
  746. (Current^.typ In SkipInstr) or
  747. ((Current^.typ = ait_label) And
  748. Not(Pai_Label(Current)^.l^.is_used))) Do
  749. Current := Pai(Current^.previous);
  750. If Assigned(Current) And
  751. (Current^.typ = ait_Marker) And
  752. (Pai_Marker(Current)^.Kind = NoPropInfoEnd) Then
  753. Begin
  754. While Assigned(Current) And
  755. ((Current^.typ <> ait_Marker) Or
  756. (Pai_Marker(Current)^.Kind <> NoPropInfoStart)) Do
  757. Current := Pai(Current^.previous);
  758. End;
  759. Until Not(Assigned(Current)) Or
  760. (Current^.typ <> ait_Marker) Or
  761. (Pai_Marker(Current)^.Kind <> NoPropInfoStart);
  762. If Not(Assigned(Current)) or
  763. (Current^.typ In SkipInstr) or
  764. ((Current^.typ = ait_label) And
  765. Not(Pai_Label(Current)^.l^.is_used)) or
  766. ((Current^.typ = ait_Marker) And
  767. (Pai_Marker(Current)^.Kind = AsmBlockEnd))
  768. Then
  769. Begin
  770. Last := nil;
  771. GetLastInstruction := False
  772. End
  773. Else
  774. Begin
  775. Last := Current;
  776. GetLastInstruction := True;
  777. End;
  778. End;
  779. Procedure SkipHead(var P: Pai);
  780. Var OldP: Pai;
  781. Begin
  782. Repeat
  783. OldP := P;
  784. If (P^.typ in SkipInstr) Or
  785. ((P^.typ = ait_marker) And
  786. (Pai_Marker(P)^.Kind = AsmBlockEnd)) Then
  787. GetNextInstruction(P, P)
  788. Else If ((P^.Typ = Ait_Marker) And
  789. (Pai_Marker(P)^.Kind = NoPropInfoStart)) Then
  790. {a marker of the NoPropInfoStart can't be the first instruction of a
  791. paasmoutput list}
  792. GetNextInstruction(Pai(P^.Previous),P);
  793. If (P^.Typ = Ait_Marker) And
  794. (Pai_Marker(P)^.Kind = AsmBlockStart) Then
  795. Begin
  796. P := Pai(P^.Next);
  797. While (P^.typ <> Ait_Marker) Or
  798. (Pai_Marker(P)^.Kind <> AsmBlockEnd) Do
  799. P := Pai(P^.Next)
  800. End;
  801. Until P = OldP
  802. End;
  803. {******************* The Data Flow Analyzer functions ********************}
  804. Procedure UpdateUsedRegs(Var UsedRegs: TRegSet; p: Pai);
  805. {updates UsedRegs with the RegAlloc Information coming after P}
  806. Begin
  807. Repeat
  808. While Assigned(p) And
  809. ((p^.typ in (SkipInstr - [ait_RegAlloc])) or
  810. ((p^.typ = ait_label) And
  811. Not(Pai_Label(p)^.l^.is_used))) Do
  812. p := Pai(p^.next);
  813. While Assigned(p) And
  814. (p^.typ=ait_RegAlloc) Do
  815. Begin
  816. if pairegalloc(p)^.allocation then
  817. UsedRegs := UsedRegs + [PaiRegAlloc(p)^.Reg]
  818. else
  819. UsedRegs := UsedRegs - [PaiRegAlloc(p)^.Reg];
  820. p := pai(p^.next);
  821. End;
  822. Until Not(Assigned(p)) Or
  823. (Not(p^.typ in SkipInstr) And
  824. Not((p^.typ = ait_label) And
  825. Not(Pai_Label(p)^.l^.is_used)));
  826. End;
  827. Procedure IncState(Var S: Byte);
  828. {Increases S by 1, wraps around at $ffff to 0 (so we won't get overflow
  829. errors}
  830. Begin
  831. If (s <> $ff)
  832. Then Inc(s)
  833. Else s := 0
  834. End;
  835. Function RegInSequence(Reg: TRegister; Const Content: TContent): Boolean;
  836. {checks the whole sequence of Content (so StartMod and and the next NrOfMods
  837. Pai objects) to see whether Reg is used somewhere, without it being loaded
  838. with something else first}
  839. Var p: Pai;
  840. Counter: Byte;
  841. TmpResult: Boolean;
  842. RegsChecked: TRegSet;
  843. Begin
  844. RegsChecked := [];
  845. p := Content.StartMod;
  846. TmpResult := False;
  847. Counter := 1;
  848. While Not(TmpResult) And
  849. (Counter <= Content.NrOfMods) Do
  850. Begin
  851. If (p^.typ = ait_instruction) and
  852. ((Paicpu(p)^.opcode = A_MOV) or
  853. (Paicpu(p)^.opcode = A_MOVZX) or
  854. (Paicpu(p)^.opcode = A_MOVSX))
  855. Then
  856. Begin
  857. If (Paicpu(p)^.oper[0].typ = top_ref) Then
  858. With Paicpu(p)^.oper[0].ref^ Do
  859. If (Base = procinfo^.FramePointer) And
  860. (Index = R_NO)
  861. Then
  862. Begin
  863. RegsChecked := RegsChecked + [Reg32(Paicpu(p)^.oper[1].reg)];
  864. If Reg = Reg32(Paicpu(p)^.oper[1].reg) Then
  865. Break;
  866. End
  867. Else
  868. Begin
  869. If (Base = Reg) And
  870. Not(Base In RegsChecked)
  871. Then TmpResult := True;
  872. If Not(TmpResult) And
  873. (Index = Reg) And
  874. Not(Index In RegsChecked)
  875. Then TmpResult := True;
  876. End
  877. End
  878. Else TmpResult := RegInInstruction(Reg, p);
  879. Inc(Counter);
  880. GetNextInstruction(p,p)
  881. End;
  882. RegInSequence := TmpResult
  883. End;
  884. Procedure DestroyReg(p1: PPaiProp; Reg: TRegister; doIncState:Boolean);
  885. {Destroys the contents of the register Reg in the PPaiProp p1, as well as the
  886. contents of registers are loaded with a memory location based on Reg.
  887. doIncState is false when this register has to be destroyed not because
  888. it's contents are directly modified/overwritten, but because of an indirect
  889. action (ie. this register holds the contents of a variable and the value
  890. of the variable in memory is changed }
  891. Var TmpWState, TmpRState: Byte;
  892. Counter: TRegister;
  893. Begin
  894. Reg := Reg32(Reg);
  895. NrOfInstrSinceLastMod[Reg] := 0;
  896. If (Reg >= R_EAX) And (Reg <= R_EDI)
  897. Then
  898. Begin
  899. With p1^.Regs[Reg] Do
  900. Begin
  901. if doIncState then
  902. IncState(WState);
  903. TmpWState := WState;
  904. TmpRState := RState;
  905. FillChar(p1^.Regs[Reg], SizeOf(TContent), 0);
  906. WState := TmpWState;
  907. RState := TmpRState;
  908. End;
  909. For Counter := R_EAX to R_EDI Do
  910. With p1^.Regs[Counter] Do
  911. If (Typ = Con_Ref) And
  912. RegInSequence(Reg, p1^.Regs[Counter])
  913. Then
  914. Begin
  915. if doIncState then
  916. IncState(WState);
  917. TmpWState := WState;
  918. TmpRState := RState;
  919. FillChar(p1^.Regs[Counter], SizeOf(TContent), 0);
  920. WState := TmpWState;
  921. RState := TmpRState;
  922. End;
  923. End;
  924. End;
  925. {Procedure AddRegsToSet(p: Pai; Var RegSet: TRegSet);
  926. Begin
  927. If (p^.typ = ait_instruction) Then
  928. Begin
  929. Case Paicpu(p)^.oper[0].typ Of
  930. top_reg:
  931. If Not(Paicpu(p)^.oper[0].reg in [R_NO,R_ESP,procinfo^.FramePointer]) Then
  932. RegSet := RegSet + [Paicpu(p)^.oper[0].reg];
  933. top_ref:
  934. With TReference(Paicpu(p)^.oper[0]^) Do
  935. Begin
  936. If Not(Base in [procinfo^.FramePointer,R_NO,R_ESP])
  937. Then RegSet := RegSet + [Base];
  938. If Not(Index in [procinfo^.FramePointer,R_NO,R_ESP])
  939. Then RegSet := RegSet + [Index];
  940. End;
  941. End;
  942. Case Paicpu(p)^.oper[1].typ Of
  943. top_reg:
  944. If Not(Paicpu(p)^.oper[1].reg in [R_NO,R_ESP,procinfo^.FramePointer]) Then
  945. If RegSet := RegSet + [TRegister(TwoWords(Paicpu(p)^.oper[1]).Word1];
  946. top_ref:
  947. With TReference(Paicpu(p)^.oper[1]^) Do
  948. Begin
  949. If Not(Base in [procinfo^.FramePointer,R_NO,R_ESP])
  950. Then RegSet := RegSet + [Base];
  951. If Not(Index in [procinfo^.FramePointer,R_NO,R_ESP])
  952. Then RegSet := RegSet + [Index];
  953. End;
  954. End;
  955. End;
  956. End;}
  957. Function OpsEquivalent(const o1, o2: toper; Var RegInfo: TRegInfo; OpAct: TopAction): Boolean;
  958. Begin {checks whether the two ops are equivalent}
  959. OpsEquivalent := False;
  960. if o1.typ=o2.typ then
  961. Case o1.typ Of
  962. Top_Reg:
  963. OpsEquivalent :=RegsEquivalent(o1.reg,o2.reg, RegInfo, OpAct);
  964. Top_Ref:
  965. OpsEquivalent := RefsEquivalent(o1.ref^, o2.ref^, RegInfo, OpAct);
  966. Top_Const:
  967. OpsEquivalent := o1.val = o2.val;
  968. Top_None:
  969. OpsEquivalent := True
  970. End;
  971. End;
  972. Function OpsEqual(const o1,o2:toper): Boolean;
  973. Begin {checks whether the two ops are equal}
  974. OpsEqual := False;
  975. if o1.typ=o2.typ then
  976. Case o1.typ Of
  977. Top_Reg :
  978. OpsEqual:=o1.reg=o2.reg;
  979. Top_Ref :
  980. OpsEqual := RefsEqual(o1.ref^, o2.ref^);
  981. Top_Const :
  982. OpsEqual:=o1.val=o2.val;
  983. Top_Symbol :
  984. OpsEqual:=(o1.sym=o2.sym) and (o1.symofs=o2.symofs);
  985. Top_None :
  986. OpsEqual := True
  987. End;
  988. End;
  989. Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
  990. {$ifdef csdebug}
  991. var hp: pai;
  992. {$endif csdebug}
  993. Begin {checks whether two Paicpu instructions are equal}
  994. If Assigned(p1) And Assigned(p2) And
  995. (Pai(p1)^.typ = ait_instruction) And
  996. (Pai(p1)^.typ = ait_instruction) And
  997. (Paicpu(p1)^.opcode = Paicpu(p2)^.opcode) And
  998. (Paicpu(p1)^.oper[0].typ = Paicpu(p2)^.oper[0].typ) And
  999. (Paicpu(p1)^.oper[1].typ = Paicpu(p2)^.oper[1].typ) And
  1000. (Paicpu(p1)^.oper[2].typ = Paicpu(p2)^.oper[2].typ)
  1001. Then
  1002. {both instructions have the same structure:
  1003. "<operator> <operand of type1>, <operand of type 2>"}
  1004. If ((Paicpu(p1)^.opcode = A_MOV) or
  1005. (Paicpu(p1)^.opcode = A_MOVZX) or
  1006. (Paicpu(p1)^.opcode = A_MOVSX)) And
  1007. (Paicpu(p1)^.oper[0].typ = top_ref) {then .oper[1]t = top_reg} Then
  1008. If Not(RegInRef(Paicpu(p1)^.oper[1].reg, Paicpu(p1)^.oper[0].ref^)) Then
  1009. {the "old" instruction is a load of a register with a new value, not with
  1010. a value based on the contents of this register (so no "mov (reg), reg")}
  1011. If Not(RegInRef(Paicpu(p2)^.oper[1].reg, Paicpu(p2)^.oper[0].ref^)) And
  1012. RefsEqual(Paicpu(p1)^.oper[0].ref^, Paicpu(p2)^.oper[0].ref^)
  1013. Then
  1014. {the "new" instruction is also a load of a register with a new value, and
  1015. this value is fetched from the same memory location}
  1016. Begin
  1017. With Paicpu(p2)^.oper[0].ref^ Do
  1018. Begin
  1019. If Not(Base in [procinfo^.FramePointer, R_NO, R_ESP])
  1020. {it won't do any harm if the register is already in RegsLoadedForRef}
  1021. Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
  1022. If Not(Index in [procinfo^.FramePointer, R_NO, R_ESP])
  1023. Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
  1024. End;
  1025. {add the registers from the reference (.oper[0]) to the RegInfo, all registers
  1026. from the reference are the same in the old and in the new instruction
  1027. sequence}
  1028. AddOp2RegInfo(Paicpu(p1)^.oper[0], RegInfo);
  1029. {the registers from .oper[1] have to be equivalent, but not necessarily equal}
  1030. InstructionsEquivalent :=
  1031. RegsEquivalent(Paicpu(p1)^.oper[1].reg, Paicpu(p2)^.oper[1].reg, RegInfo, OpAct_Write);
  1032. End
  1033. {the registers are loaded with values from different memory locations. If
  1034. this was allowed, the instructions "mov -4(esi),eax" and "mov -4(ebp),eax"
  1035. would be considered equivalent}
  1036. Else InstructionsEquivalent := False
  1037. Else
  1038. {load register with a value based on the current value of this register}
  1039. Begin
  1040. With Paicpu(p2)^.oper[0].ref^ Do
  1041. Begin
  1042. If Not(Base in [procinfo^.FramePointer,
  1043. Reg32(Paicpu(p2)^.oper[1].reg),R_NO,R_ESP])
  1044. {it won't do any harm if the register is already in RegsLoadedForRef}
  1045. Then
  1046. Begin
  1047. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
  1048. {$ifdef csdebug}
  1049. Writeln(att_reg2str[base], ' added');
  1050. {$endif csdebug}
  1051. end;
  1052. If Not(Index in [procinfo^.FramePointer,
  1053. Reg32(Paicpu(p2)^.oper[1].reg),R_NO,R_ESP])
  1054. Then
  1055. Begin
  1056. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
  1057. {$ifdef csdebug}
  1058. Writeln(att_reg2str[index], ' added');
  1059. {$endif csdebug}
  1060. end;
  1061. End;
  1062. If Not(Reg32(Paicpu(p2)^.oper[1].reg) In [procinfo^.FramePointer,R_NO,R_ESP])
  1063. Then
  1064. Begin
  1065. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef -
  1066. [Reg32(Paicpu(p2)^.oper[1].reg)];
  1067. {$ifdef csdebug}
  1068. Writeln(att_reg2str[Reg32(Paicpu(p2)^.oper[1].reg)], ' removed');
  1069. {$endif csdebug}
  1070. end;
  1071. InstructionsEquivalent :=
  1072. OpsEquivalent(Paicpu(p1)^.oper[0], Paicpu(p2)^.oper[0], RegInfo, OpAct_Read) And
  1073. OpsEquivalent(Paicpu(p1)^.oper[1], Paicpu(p2)^.oper[1], RegInfo, OpAct_Write)
  1074. End
  1075. Else
  1076. {an instruction <> mov, movzx, movsx}
  1077. begin
  1078. {$ifdef csdebug}
  1079. hp := new(pai_asm_comment,init(strpnew('checking if equivalent')));
  1080. hp^.previous := p2;
  1081. hp^.next := p2^.next;
  1082. p2^.next^.previous := hp;
  1083. p2^.next := hp;
  1084. {$endif csdebug}
  1085. InstructionsEquivalent :=
  1086. OpsEquivalent(Paicpu(p1)^.oper[0], Paicpu(p2)^.oper[0], RegInfo, OpAct_Unknown) And
  1087. OpsEquivalent(Paicpu(p1)^.oper[1], Paicpu(p2)^.oper[1], RegInfo, OpAct_Unknown) And
  1088. OpsEquivalent(Paicpu(p1)^.oper[2], Paicpu(p2)^.oper[2], RegInfo, OpAct_Unknown)
  1089. end
  1090. {the instructions haven't even got the same structure, so they're certainly
  1091. not equivalent}
  1092. Else
  1093. begin
  1094. {$ifdef csdebug}
  1095. hp := new(pai_asm_comment,init(strpnew('different opcodes/format')));
  1096. hp^.previous := p2;
  1097. hp^.next := p2^.next;
  1098. p2^.next^.previous := hp;
  1099. p2^.next := hp;
  1100. {$endif csdebug}
  1101. InstructionsEquivalent := False;
  1102. end;
  1103. {$ifdef csdebug}
  1104. hp := new(pai_asm_comment,init(strpnew('instreq: '+tostr(byte(instructionsequivalent)))));
  1105. hp^.previous := p2;
  1106. hp^.next := p2^.next;
  1107. p2^.next^.previous := hp;
  1108. p2^.next := hp;
  1109. {$endif csdebug}
  1110. End;
  1111. (*
  1112. Function InstructionsEqual(p1, p2: Pai): Boolean;
  1113. Begin {checks whether two Paicpu instructions are equal}
  1114. InstructionsEqual :=
  1115. Assigned(p1) And Assigned(p2) And
  1116. ((Pai(p1)^.typ = ait_instruction) And
  1117. (Pai(p1)^.typ = ait_instruction) And
  1118. (Paicpu(p1)^.opcode = Paicpu(p2)^.opcode) And
  1119. (Paicpu(p1)^.oper[0].typ = Paicpu(p2)^.oper[0].typ) And
  1120. (Paicpu(p1)^.oper[1].typ = Paicpu(p2)^.oper[1].typ) And
  1121. OpsEqual(Paicpu(p1)^.oper[0].typ, Paicpu(p1)^.oper[0], Paicpu(p2)^.oper[0]) And
  1122. OpsEqual(Paicpu(p1)^.oper[1].typ, Paicpu(p1)^.oper[1], Paicpu(p2)^.oper[1]))
  1123. End;
  1124. *)
  1125. Procedure ReadReg(p: PPaiProp; Reg: TRegister);
  1126. Begin
  1127. Reg := Reg32(Reg);
  1128. If Reg in [R_EAX..R_EDI] Then
  1129. IncState(p^.Regs[Reg].RState)
  1130. End;
  1131. Procedure ReadRef(p: PPaiProp; Ref: PReference);
  1132. Begin
  1133. If Ref^.Base <> R_NO Then
  1134. ReadReg(p, Ref^.Base);
  1135. If Ref^.Index <> R_NO Then
  1136. ReadReg(p, Ref^.Index);
  1137. End;
  1138. Procedure ReadOp(P: PPaiProp;const o:toper);
  1139. Begin
  1140. Case o.typ Of
  1141. top_reg: ReadReg(P, o.reg);
  1142. top_ref: ReadRef(P, o.ref);
  1143. top_symbol : ;
  1144. End;
  1145. End;
  1146. Function RefInInstruction(Const Ref: TReference; p: Pai;
  1147. RefsEq: TRefCompare): Boolean;
  1148. {checks whehter Ref is used in P}
  1149. Var TmpResult: Boolean;
  1150. Begin
  1151. TmpResult := False;
  1152. If (p^.typ = ait_instruction) Then
  1153. Begin
  1154. If (Paicpu(p)^.oper[0].typ = Top_Ref) Then
  1155. TmpResult := RefsEq(Ref, Paicpu(p)^.oper[0].ref^);
  1156. If Not(TmpResult) And (Paicpu(p)^.oper[1].typ = Top_Ref) Then
  1157. TmpResult := RefsEq(Ref, Paicpu(p)^.oper[1].ref^);
  1158. If Not(TmpResult) And (Paicpu(p)^.oper[2].typ = Top_Ref) Then
  1159. TmpResult := RefsEq(Ref, Paicpu(p)^.oper[2].ref^);
  1160. End;
  1161. RefInInstruction := TmpResult;
  1162. End;
  1163. Function RefInSequence(Const Ref: TReference; Content: TContent;
  1164. RefsEq: TRefCompare): Boolean;
  1165. {checks the whole sequence of Content (so StartMod and and the next NrOfMods
  1166. Pai objects) to see whether Ref is used somewhere}
  1167. Var p: Pai;
  1168. Counter: Byte;
  1169. TmpResult: Boolean;
  1170. Begin
  1171. p := Content.StartMod;
  1172. TmpResult := False;
  1173. Counter := 1;
  1174. While Not(TmpResult) And
  1175. (Counter <= Content.NrOfMods) Do
  1176. Begin
  1177. If (p^.typ = ait_instruction) And
  1178. RefInInstruction(Ref, p, RefsEq)
  1179. Then TmpResult := True;
  1180. Inc(Counter);
  1181. GetNextInstruction(p,p)
  1182. End;
  1183. RefInSequence := TmpResult
  1184. End;
  1185. Function ArrayRefsEq(const r1, r2: TReference): Boolean;{$ifdef tp}far;{$endif}
  1186. Begin
  1187. ArrayRefsEq := (R1.Offset+R1.OffsetFixup = R2.Offset+R2.OffsetFixup) And
  1188. (R1.Segment = R2.Segment) And
  1189. (R1.Symbol=R2.Symbol) And
  1190. ((Assigned(R1.Symbol)) Or
  1191. (R1.Base = R2.Base))
  1192. End;
  1193. Procedure DestroyRefs(p: pai; Const Ref: TReference; WhichReg: TRegister);
  1194. {destroys all registers which possibly contain a reference to Ref, WhichReg
  1195. is the register whose contents are being written to memory (if this proc
  1196. is called because of a "mov?? %reg, (mem)" instruction)}
  1197. Var RefsEq: TRefCompare;
  1198. Counter: TRegister;
  1199. Begin
  1200. WhichReg := Reg32(WhichReg);
  1201. If (Ref.base = procinfo^.FramePointer) or
  1202. Assigned(Ref.Symbol) Then
  1203. Begin
  1204. If (Ref.Index = R_NO) And
  1205. (Not(Assigned(Ref.Symbol)) or
  1206. (Ref.base = R_NO)) Then
  1207. { local variable which is not an array }
  1208. RefsEq := {$ifdef fpc}@{$endif}RefsEqual
  1209. Else
  1210. { local variable which is an array }
  1211. RefsEq := {$ifdef fpc}@{$endif}ArrayRefsEq;
  1212. {write something to a parameter, a local or global variable, so
  1213. * with uncertain optimizations on:
  1214. - destroy the contents of registers whose contents have somewhere a
  1215. "mov?? (Ref), %reg". WhichReg (this is the register whose contents
  1216. are being written to memory) is not destroyed if it's StartMod is
  1217. of that form and NrOfMods = 1 (so if it holds ref, but is not a
  1218. pointer based on Ref)
  1219. * with uncertain optimizations off:
  1220. - also destroy registers that contain any pointer}
  1221. For Counter := R_EAX to R_EDI Do
  1222. With PPaiProp(p^.OptInfo)^.Regs[Counter] Do
  1223. Begin
  1224. If (typ = Con_Ref) And
  1225. ((Not(cs_UncertainOpts in aktglobalswitches) And
  1226. (NrOfMods <> 1)
  1227. ) Or
  1228. (RefInSequence(Ref,PPaiProp(p^.OptInfo)^.Regs[Counter],RefsEq) And
  1229. ((Counter <> WhichReg) Or
  1230. ((NrOfMods <> 1) And
  1231. {StarMod is always of the type ait_instruction}
  1232. (Paicpu(StartMod)^.oper[0].typ = top_ref) And
  1233. RefsEq(Paicpu(StartMod)^.oper[0].ref^, Ref)
  1234. )
  1235. )
  1236. )
  1237. )
  1238. Then
  1239. DestroyReg(PPaiProp(p^.OptInfo), Counter, false)
  1240. End
  1241. End
  1242. Else
  1243. {write something to a pointer location, so
  1244. * with uncertain optimzations on:
  1245. - do not destroy registers which contain a local/global variable or a
  1246. parameter, except if DestroyRefs is called because of a "movsl"
  1247. * with uncertain optimzations off:
  1248. - destroy every register which contains a memory location
  1249. }
  1250. For Counter := R_EAX to R_EDI Do
  1251. With PPaiProp(p^.OptInfo)^.Regs[Counter] Do
  1252. If (typ = Con_Ref) And
  1253. (Not(cs_UncertainOpts in aktglobalswitches) Or
  1254. {for movsl}
  1255. (Ref.Base = R_EDI) Or
  1256. {don't destroy if reg contains a parameter, local or global variable}
  1257. Not((NrOfMods = 1) And
  1258. (Paicpu(StartMod)^.oper[0].typ = top_ref) And
  1259. ((Paicpu(StartMod)^.oper[0].ref^.base = procinfo^.FramePointer) Or
  1260. Assigned(Paicpu(StartMod)^.oper[0].ref^.Symbol)
  1261. )
  1262. )
  1263. )
  1264. Then DestroyReg(PPaiProp(p^.OptInfo), Counter, false)
  1265. End;
  1266. Procedure DestroyAllRegs(p: PPaiProp);
  1267. Var Counter: TRegister;
  1268. Begin {initializes/desrtoys all registers}
  1269. For Counter := R_EAX To R_EDI Do
  1270. Begin
  1271. ReadReg(p, Counter);
  1272. DestroyReg(p, Counter, true);
  1273. End;
  1274. p^.DirFlag := F_Unknown;
  1275. End;
  1276. Procedure DestroyOp(PaiObj: Pai; const o:Toper);
  1277. Begin
  1278. Case o.typ Of
  1279. top_reg: DestroyReg(PPaiProp(PaiObj^.OptInfo), o.reg, true);
  1280. top_ref:
  1281. Begin
  1282. ReadRef(PPaiProp(PaiObj^.OptInfo), o.ref);
  1283. DestroyRefs(PaiObj, o.ref^, R_NO);
  1284. End;
  1285. top_symbol:;
  1286. End;
  1287. End;
  1288. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  1289. {gathers the RegAlloc data... still need to think about where to store it to
  1290. avoid global vars}
  1291. Var BlockEnd: Pai;
  1292. Begin
  1293. BlockEnd := FindLoHiLabels(LoLab, HiLab, LabDif, BlockStart);
  1294. BuildLabelTableAndFixRegAlloc(AsmL, LTable, LoLab, LabDif, BlockStart, BlockEnd);
  1295. DFAPass1 := BlockEnd;
  1296. End;
  1297. {$ifdef arithopt}
  1298. Procedure AddInstr2RegContents({$ifdef statedebug} asml: paasmoutput; {$endif}
  1299. p: paicpu; reg: TRegister);
  1300. {$ifdef statedebug}
  1301. var hp: pai;
  1302. {$endif statedebug}
  1303. Begin
  1304. Reg := Reg32(Reg);
  1305. With PPaiProp(p^.optinfo)^.Regs[reg] Do
  1306. If (Typ = Con_Ref)
  1307. Then
  1308. Begin
  1309. IncState(WState);
  1310. {also store how many instructions are part of the sequence in the first
  1311. instructions PPaiProp, so it can be easily accessed from within
  1312. CheckSequence}
  1313. Inc(NrOfMods, NrOfInstrSinceLastMod[Reg]);
  1314. PPaiProp(Pai(StartMod)^.OptInfo)^.Regs[Reg].NrOfMods := NrOfMods;
  1315. NrOfInstrSinceLastMod[Reg] := 0;
  1316. {$ifdef StateDebug}
  1317. hp := new(pai_asm_comment,init(strpnew(att_reg2str[reg]+': '+tostr(PPaiProp(p^.optinfo)^.Regs[reg].WState)
  1318. + ' -- ' + tostr(PPaiProp(p^.optinfo)^.Regs[reg].nrofmods))));
  1319. InsertLLItem(AsmL, p, p^.next, hp);
  1320. {$endif StateDebug}
  1321. End
  1322. Else
  1323. Begin
  1324. DestroyReg(PPaiProp(p^.optinfo), Reg, true);
  1325. {$ifdef StateDebug}
  1326. hp := new(pai_asm_comment,init(strpnew(att_reg2str[reg]+': '+tostr(PPaiProp(p^.optinfo)^.Regs[reg].WState))));
  1327. InsertLLItem(AsmL, p, p^.next, hp);
  1328. {$endif StateDebug}
  1329. End
  1330. End;
  1331. Procedure AddInstr2OpContents({$ifdef statedebug} asml: paasmoutput; {$endif}
  1332. p: paicpu; const oper: TOper);
  1333. Begin
  1334. If oper.typ = top_reg Then
  1335. AddInstr2RegContents({$ifdef statedebug} asml, {$endif}p, oper.reg)
  1336. Else
  1337. Begin
  1338. ReadOp(PPaiProp(p^.optinfo), oper);
  1339. DestroyOp(p, oper);
  1340. End
  1341. End;
  1342. {$endif arithopt}
  1343. Procedure DoDFAPass2(
  1344. {$Ifdef StateDebug}
  1345. AsmL: PAasmOutput;
  1346. {$endif statedebug}
  1347. BlockStart, BlockEnd: Pai);
  1348. {Analyzes the Data Flow of an assembler list. Starts creating the reg
  1349. contents for the instructions starting with p. Returns the last pai which has
  1350. been processed}
  1351. Var
  1352. CurProp: PPaiProp;
  1353. {$ifdef AnalyzeLoops}
  1354. TmpState: Byte;
  1355. {$endif AnalyzeLoops}
  1356. Cnt, InstrCnt : Longint;
  1357. InstrProp: TInsProp;
  1358. UsedRegs: TRegSet;
  1359. p, hp : Pai;
  1360. TmpRef: TReference;
  1361. TmpReg: TRegister;
  1362. Begin
  1363. p := BlockStart;
  1364. UsedRegs := [];
  1365. UpdateUsedregs(UsedRegs, p);
  1366. SkipHead(P);
  1367. BlockStart := p;
  1368. InstrCnt := 1;
  1369. FillChar(NrOfInstrSinceLastMod, SizeOf(NrOfInstrSinceLastMod), 0);
  1370. While (P <> BlockEnd) Do
  1371. Begin
  1372. {$IfDef TP}
  1373. New(CurProp);
  1374. {$Else TP}
  1375. CurProp := @PaiPropBlock^[InstrCnt];
  1376. {$EndIf TP}
  1377. If (p <> BlockStart)
  1378. Then
  1379. Begin
  1380. {$ifdef JumpAnal}
  1381. If (p^.Typ <> ait_label) Then
  1382. {$endif JumpAnal}
  1383. Begin
  1384. GetLastInstruction(p, hp);
  1385. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1386. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1387. End
  1388. End
  1389. Else
  1390. Begin
  1391. FillChar(CurProp^, SizeOf(CurProp^), 0);
  1392. { For TmpReg := R_EAX to R_EDI Do
  1393. CurProp^.Regs[TmpReg].WState := 1;}
  1394. End;
  1395. CurProp^.UsedRegs := UsedRegs;
  1396. CurProp^.CanBeRemoved := False;
  1397. UpdateUsedRegs(UsedRegs, Pai(p^.Next));
  1398. {$ifdef TP}
  1399. PPaiProp(p^.OptInfo) := CurProp;
  1400. {$Endif TP}
  1401. For TmpReg := R_EAX To R_EDI Do
  1402. Inc(NrOfInstrSinceLastMod[TmpReg]);
  1403. Case p^.typ Of
  1404. ait_label:
  1405. {$Ifndef JumpAnal}
  1406. If (Pai_label(p)^.l^.is_used) Then
  1407. DestroyAllRegs(CurProp);
  1408. {$Else JumpAnal}
  1409. Begin
  1410. If (Pai_Label(p)^.is_used) Then
  1411. With LTable^[Pai_Label(p)^.l^.labelnr-LoLab] Do
  1412. {$IfDef AnalyzeLoops}
  1413. If (RefsFound = Pai_Label(p)^.l^.RefCount)
  1414. {$Else AnalyzeLoops}
  1415. If (JmpsProcessed = Pai_Label(p)^.l^.RefCount)
  1416. {$EndIf AnalyzeLoops}
  1417. Then
  1418. {all jumps to this label have been found}
  1419. {$IfDef AnalyzeLoops}
  1420. If (JmpsProcessed > 0)
  1421. Then
  1422. {$EndIf AnalyzeLoops}
  1423. {we've processed at least one jump to this label}
  1424. Begin
  1425. If (GetLastInstruction(p, hp) And
  1426. Not(((hp^.typ = ait_instruction)) And
  1427. (paicpu_labeled(hp)^.is_jmp))
  1428. Then
  1429. {previous instruction not a JMP -> the contents of the registers after the
  1430. previous intruction has been executed have to be taken into account as well}
  1431. For TmpReg := R_EAX to R_EDI Do
  1432. Begin
  1433. If (CurProp^.Regs[TmpReg].WState <>
  1434. PPaiProp(hp^.OptInfo)^.Regs[TmpReg].WState)
  1435. Then DestroyReg(CurProp, TmpReg, true)
  1436. End
  1437. End
  1438. {$IfDef AnalyzeLoops}
  1439. Else
  1440. {a label from a backward jump (e.g. a loop), no jump to this label has
  1441. already been processed}
  1442. If GetLastInstruction(p, hp) And
  1443. Not(hp^.typ = ait_instruction) And
  1444. (paicpu_labeled(hp)^.opcode = A_JMP))
  1445. Then
  1446. {previous instruction not a jmp, so keep all the registers' contents from the
  1447. previous instruction}
  1448. Begin
  1449. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1450. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1451. End
  1452. Else
  1453. {previous instruction a jmp and no jump to this label processed yet}
  1454. Begin
  1455. hp := p;
  1456. Cnt := InstrCnt;
  1457. {continue until we find a jump to the label or a label which has already
  1458. been processed}
  1459. While GetNextInstruction(hp, hp) And
  1460. Not((hp^.typ = ait_instruction) And
  1461. (paicpu(hp)^.is_jmp) and
  1462. (pasmlabel(paicpu(hp)^.oper[0].sym)^.labelnr = Pai_Label(p)^.l^.labelnr)) And
  1463. Not((hp^.typ = ait_label) And
  1464. (LTable^[Pai_Label(hp)^.l^.labelnr-LoLab].RefsFound
  1465. = Pai_Label(hp)^.l^.RefCount) And
  1466. (LTable^[Pai_Label(hp)^.l^.labelnr-LoLab].JmpsProcessed > 0)) Do
  1467. Inc(Cnt);
  1468. If (hp^.typ = ait_label)
  1469. Then
  1470. {there's a processed label after the current one}
  1471. Begin
  1472. CurProp^.Regs := PaiPropBlock^[Cnt].Regs;
  1473. CurProp^.DirFlag := PaiPropBlock^[Cnt].DirFlag;
  1474. End
  1475. Else
  1476. {there's no label anymore after the current one, or they haven't been
  1477. processed yet}
  1478. Begin
  1479. GetLastInstruction(p, hp);
  1480. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1481. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1482. DestroyAllRegs(PPaiProp(hp^.OptInfo))
  1483. End
  1484. End
  1485. {$EndIf AnalyzeLoops}
  1486. Else
  1487. {not all references to this label have been found, so destroy all registers}
  1488. Begin
  1489. GetLastInstruction(p, hp);
  1490. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1491. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1492. DestroyAllRegs(CurProp)
  1493. End;
  1494. End;
  1495. {$EndIf JumpAnal}
  1496. {$ifdef GDB}
  1497. ait_stabs, ait_stabn, ait_stab_function_name:;
  1498. {$endif GDB}
  1499. ait_align: ; { may destroy flags !!! }
  1500. ait_instruction:
  1501. Begin
  1502. if paicpu(p)^.is_jmp then
  1503. begin
  1504. {$IfNDef JumpAnal}
  1505. ;
  1506. {$Else JumpAnal}
  1507. With LTable^[pasmlabel(paicpu(p)^.oper[0].sym)^.labelnr-LoLab] Do
  1508. If (RefsFound = pasmlabel(paicpu(p)^.oper[0].sym)^.RefCount) Then
  1509. Begin
  1510. If (InstrCnt < InstrNr)
  1511. Then
  1512. {forward jump}
  1513. If (JmpsProcessed = 0) Then
  1514. {no jump to this label has been processed yet}
  1515. Begin
  1516. PaiPropBlock^[InstrNr].Regs := CurProp^.Regs;
  1517. PaiPropBlock^[InstrNr].DirFlag := CurProp^.DirFlag;
  1518. Inc(JmpsProcessed);
  1519. End
  1520. Else
  1521. Begin
  1522. For TmpReg := R_EAX to R_EDI Do
  1523. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1524. CurProp^.Regs[TmpReg].WState) Then
  1525. DestroyReg(@PaiPropBlock^[InstrNr], TmpReg, true);
  1526. Inc(JmpsProcessed);
  1527. End
  1528. {$ifdef AnalyzeLoops}
  1529. Else
  1530. { backward jump, a loop for example}
  1531. { If (JmpsProcessed > 0) Or
  1532. Not(GetLastInstruction(PaiObj, hp) And
  1533. (hp^.typ = ait_labeled_instruction) And
  1534. (paicpu_labeled(hp)^.opcode = A_JMP))
  1535. Then}
  1536. {instruction prior to label is not a jmp, or at least one jump to the label
  1537. has yet been processed}
  1538. Begin
  1539. Inc(JmpsProcessed);
  1540. For TmpReg := R_EAX to R_EDI Do
  1541. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1542. CurProp^.Regs[TmpReg].WState)
  1543. Then
  1544. Begin
  1545. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1546. Cnt := InstrNr;
  1547. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1548. Begin
  1549. DestroyReg(@PaiPropBlock^[Cnt], TmpReg, true);
  1550. Inc(Cnt);
  1551. End;
  1552. While (Cnt <= InstrCnt) Do
  1553. Begin
  1554. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1555. Inc(Cnt)
  1556. End
  1557. End;
  1558. End
  1559. { Else }
  1560. {instruction prior to label is a jmp and no jumps to the label have yet been
  1561. processed}
  1562. { Begin
  1563. Inc(JmpsProcessed);
  1564. For TmpReg := R_EAX to R_EDI Do
  1565. Begin
  1566. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1567. Cnt := InstrNr;
  1568. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1569. Begin
  1570. PaiPropBlock^[Cnt].Regs[TmpReg] := CurProp^.Regs[TmpReg];
  1571. Inc(Cnt);
  1572. End;
  1573. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1574. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1575. Begin
  1576. DestroyReg(@PaiPropBlock^[Cnt], TmpReg, true);
  1577. Inc(Cnt);
  1578. End;
  1579. While (Cnt <= InstrCnt) Do
  1580. Begin
  1581. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1582. Inc(Cnt)
  1583. End
  1584. End
  1585. End}
  1586. {$endif AnalyzeLoops}
  1587. End;
  1588. {$EndIf JumpAnal}
  1589. end
  1590. else
  1591. begin
  1592. InstrProp := InsProp[Paicpu(p)^.opcode];
  1593. Case Paicpu(p)^.opcode Of
  1594. A_MOV, A_MOVZX, A_MOVSX:
  1595. Begin
  1596. Case Paicpu(p)^.oper[0].typ Of
  1597. Top_Reg:
  1598. Case Paicpu(p)^.oper[1].typ Of
  1599. Top_Reg:
  1600. Begin
  1601. DestroyReg(CurProp, Paicpu(p)^.oper[1].reg, true);
  1602. ReadReg(CurProp, Paicpu(p)^.oper[0].reg);
  1603. { CurProp^.Regs[Paicpu(p)^.oper[1].reg] :=
  1604. CurProp^.Regs[Paicpu(p)^.oper[0].reg];
  1605. If (CurProp^.Regs[Paicpu(p)^.oper[1].reg].ModReg = R_NO) Then
  1606. CurProp^.Regs[Paicpu(p)^.oper[1].reg].ModReg :=
  1607. Paicpu(p)^.oper[0].reg;}
  1608. End;
  1609. Top_Ref:
  1610. Begin
  1611. ReadReg(CurProp, Paicpu(p)^.oper[0].reg);
  1612. ReadRef(CurProp, Paicpu(p)^.oper[1].ref);
  1613. DestroyRefs(p, Paicpu(p)^.oper[1].ref^, Paicpu(p)^.oper[0].reg);
  1614. End;
  1615. End;
  1616. Top_Ref:
  1617. Begin {destination is always a register in this case}
  1618. ReadRef(CurProp, Paicpu(p)^.oper[0].ref);
  1619. ReadReg(CurProp, Paicpu(p)^.oper[1].reg);
  1620. TmpReg := Reg32(Paicpu(p)^.oper[1].reg);
  1621. If RegInRef(TmpReg, Paicpu(p)^.oper[0].ref^) And
  1622. (CurProp^.Regs[TmpReg].Typ = Con_Ref)
  1623. Then
  1624. Begin
  1625. With CurProp^.Regs[TmpReg] Do
  1626. Begin
  1627. IncState(WState);
  1628. {also store how many instructions are part of the sequence in the first
  1629. instructions PPaiProp, so it can be easily accessed from within
  1630. CheckSequence}
  1631. Inc(NrOfMods, NrOfInstrSinceLastMod[TmpReg]);
  1632. PPaiProp(Pai(StartMod)^.OptInfo)^.Regs[TmpReg].NrOfMods := NrOfMods;
  1633. NrOfInstrSinceLastMod[TmpReg] := 0;
  1634. End;
  1635. End
  1636. Else
  1637. Begin
  1638. DestroyReg(CurProp, TmpReg, true);
  1639. If Not(RegInRef(TmpReg, Paicpu(p)^.oper[0].ref^)) Then
  1640. With CurProp^.Regs[TmpReg] Do
  1641. Begin
  1642. Typ := Con_Ref;
  1643. StartMod := p;
  1644. NrOfMods := 1;
  1645. End
  1646. End;
  1647. {$ifdef StateDebug}
  1648. hp := new(pai_asm_comment,init(strpnew(att_reg2str[TmpReg]+': '+tostr(CurProp^.Regs[TmpReg].WState))));
  1649. InsertLLItem(AsmL, p, p^.next, hp);
  1650. {$endif StateDebug}
  1651. End;
  1652. Top_Const:
  1653. Begin
  1654. Case Paicpu(p)^.oper[1].typ Of
  1655. Top_Reg:
  1656. Begin
  1657. TmpReg := Reg32(Paicpu(p)^.oper[1].reg);
  1658. With CurProp^.Regs[TmpReg] Do
  1659. Begin
  1660. DestroyReg(CurProp, TmpReg, true);
  1661. typ := Con_Const;
  1662. StartMod := p;
  1663. End
  1664. End;
  1665. Top_Ref:
  1666. Begin
  1667. ReadRef(CurProp, Paicpu(p)^.oper[1].ref);
  1668. DestroyRefs(P, Paicpu(p)^.oper[1].ref^, R_NO);
  1669. End;
  1670. End;
  1671. End;
  1672. End;
  1673. End;
  1674. A_DIV, A_IDIV, A_MUL:
  1675. Begin
  1676. ReadOp(Curprop, Paicpu(p)^.oper[0]);
  1677. ReadReg(CurProp,R_EAX);
  1678. If (Paicpu(p)^.OpCode = A_IDIV) or
  1679. (Paicpu(p)^.OpCode = A_DIV) Then
  1680. ReadReg(CurProp,R_EDX);
  1681. DestroyReg(CurProp, R_EAX, true);
  1682. DestroyReg(CurProp, R_EDX, true)
  1683. End;
  1684. A_IMUL:
  1685. Begin
  1686. ReadOp(CurProp,Paicpu(p)^.oper[0]);
  1687. ReadOp(CurProp,Paicpu(p)^.oper[1]);
  1688. If (Paicpu(p)^.oper[2].typ = top_none) Then
  1689. If (Paicpu(p)^.oper[1].typ = top_none) Then
  1690. Begin
  1691. ReadReg(CurProp,R_EAX);
  1692. DestroyReg(CurProp, R_EAX, true);
  1693. DestroyReg(CurProp, R_EDX, true)
  1694. End
  1695. Else
  1696. {$ifdef arithopt}
  1697. AddInstr2OpContents(Paicpu(p), Paicpu(p)^.oper[1])
  1698. {$else arithopt}
  1699. DestroyOp(p, Paicpu(p)^.oper[1])
  1700. {$endif arithopt}
  1701. Else
  1702. {$ifdef arithopt}
  1703. AddInstr2OpContents(Paicpu(p), Paicpu(p)^.oper[2]);
  1704. {$else arithopt}
  1705. DestroyOp(p, Paicpu(p)^.oper[2]);
  1706. {$endif arithopt}
  1707. End;
  1708. {$ifdef arithopt}
  1709. A_LEA:
  1710. begin
  1711. readop(curprop,paicpu(p)^.oper[0]);
  1712. if reginref(paicpu(p)^.oper[1].reg,paicpu(p)^.oper[0].ref^) then
  1713. AddInstr2RegContents(paicpu(p), paicpu(p)^.oper[1].reg)
  1714. else destroyreg(curprop,paicpu(p)^.oper[1].reg,true);
  1715. end;
  1716. {$endif arithopt}
  1717. Else
  1718. Begin
  1719. Cnt := 1;
  1720. While (Cnt <= MaxCh) And
  1721. (InstrProp.Ch[Cnt] <> Ch_None) Do
  1722. Begin
  1723. Case InstrProp.Ch[Cnt] Of
  1724. Ch_REAX..Ch_REDI: ReadReg(CurProp,TCh2Reg(InstrProp.Ch[Cnt]));
  1725. Ch_WEAX..Ch_RWEDI:
  1726. Begin
  1727. If (InstrProp.Ch[Cnt] >= Ch_RWEAX) Then
  1728. ReadReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]));
  1729. DestroyReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]), true);
  1730. End;
  1731. {$ifdef arithopt}
  1732. Ch_MEAX..Ch_MEDI:
  1733. AddInstr2RegContents({$ifdef statedebug} asml, {$endif}
  1734. Paicpu(p),
  1735. TCh2Reg(InstrProp.Ch[Cnt]));
  1736. {$endif arithopt}
  1737. Ch_CDirFlag: CurProp^.DirFlag := F_NotSet;
  1738. Ch_SDirFlag: CurProp^.DirFlag := F_Set;
  1739. Ch_Rop1: ReadOp(CurProp, Paicpu(p)^.oper[0]);
  1740. Ch_Rop2: ReadOp(CurProp, Paicpu(p)^.oper[1]);
  1741. Ch_ROp3: ReadOp(CurProp, Paicpu(p)^.oper[2]);
  1742. Ch_Wop1..Ch_RWop1:
  1743. Begin
  1744. If (InstrProp.Ch[Cnt] in [Ch_RWop1]) Then
  1745. ReadOp(CurProp, Paicpu(p)^.oper[0]);
  1746. DestroyOp(p, Paicpu(p)^.oper[0]);
  1747. End;
  1748. {$ifdef arithopt}
  1749. Ch_Mop1:
  1750. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1751. Paicpu(p), Paicpu(p)^.oper[0]);
  1752. {$endif arithopt}
  1753. Ch_Wop2..Ch_RWop2:
  1754. Begin
  1755. If (InstrProp.Ch[Cnt] = Ch_RWop2) Then
  1756. ReadOp(CurProp, Paicpu(p)^.oper[1]);
  1757. DestroyOp(p, Paicpu(p)^.oper[1]);
  1758. End;
  1759. {$ifdef arithopt}
  1760. Ch_Mop2:
  1761. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1762. Paicpu(p), Paicpu(p)^.oper[1]);
  1763. {$endif arithopt}
  1764. Ch_WOp3..Ch_RWOp3:
  1765. Begin
  1766. If (InstrProp.Ch[Cnt] = Ch_RWOp3) Then
  1767. ReadOp(CurProp, Paicpu(p)^.oper[2]);
  1768. DestroyOp(p, Paicpu(p)^.oper[2]);
  1769. End;
  1770. {$ifdef arithopt}
  1771. Ch_Mop3:
  1772. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1773. Paicpu(p), Paicpu(p)^.oper[2]);
  1774. {$endif arithopt}
  1775. Ch_WMemEDI:
  1776. Begin
  1777. ReadReg(CurProp, R_EDI);
  1778. FillChar(TmpRef, SizeOf(TmpRef), 0);
  1779. TmpRef.Base := R_EDI;
  1780. DestroyRefs(p, TmpRef, R_NO)
  1781. End;
  1782. Ch_RFlags, Ch_WFlags, Ch_RWFlags, Ch_FPU:
  1783. Else
  1784. Begin
  1785. DestroyAllRegs(CurProp);
  1786. End;
  1787. End;
  1788. Inc(Cnt);
  1789. End
  1790. End;
  1791. end;
  1792. End;
  1793. End
  1794. Else
  1795. Begin
  1796. DestroyAllRegs(CurProp);
  1797. End;
  1798. End;
  1799. Inc(InstrCnt);
  1800. GetNextInstruction(p, p);
  1801. End;
  1802. End;
  1803. Function InitDFAPass2(BlockStart, BlockEnd: Pai): Boolean;
  1804. {reserves memory for the PPaiProps in one big memory block when not using
  1805. TP, returns False if not enough memory is available for the optimizer in all
  1806. cases}
  1807. Var p: Pai;
  1808. Count: Longint;
  1809. { TmpStr: String; }
  1810. Begin
  1811. P := BlockStart;
  1812. SkipHead(P);
  1813. NrOfPaiObjs := 0;
  1814. While (P <> BlockEnd) Do
  1815. Begin
  1816. {$IfDef JumpAnal}
  1817. Case P^.Typ Of
  1818. ait_label:
  1819. Begin
  1820. If (Pai_Label(p)^.l^.is_used) Then
  1821. LTable^[Pai_Label(P)^.l^.labelnr-LoLab].InstrNr := NrOfPaiObjs
  1822. End;
  1823. ait_instruction:
  1824. begin
  1825. if paicpu(p)^.is_jmp then
  1826. begin
  1827. If (pasmlabel(paicpu(P)^.oper[0].sym)^.labelnr >= LoLab) And
  1828. (pasmlabel(paicpu(P)^.oper[0].sym)^.labelnr <= HiLab) Then
  1829. Inc(LTable^[pasmlabel(paicpu(P)^.oper[0].sym)^.labelnr-LoLab].RefsFound);
  1830. end;
  1831. end;
  1832. { ait_instruction:
  1833. Begin
  1834. If (Paicpu(p)^.opcode = A_PUSH) And
  1835. (Paicpu(p)^.oper[0].typ = top_symbol) And
  1836. (PCSymbol(Paicpu(p)^.oper[0])^.offset = 0) Then
  1837. Begin
  1838. TmpStr := StrPas(PCSymbol(Paicpu(p)^.oper[0])^.symbol);
  1839. If}
  1840. End;
  1841. {$EndIf JumpAnal}
  1842. Inc(NrOfPaiObjs);
  1843. GetNextInstruction(p, p);
  1844. End;
  1845. {$IfDef TP}
  1846. If (MemAvail < (SizeOf(TPaiProp)*NrOfPaiObjs))
  1847. Or (NrOfPaiObjs = 0)
  1848. {this doesn't have to be one contiguous block}
  1849. Then InitDFAPass2 := False
  1850. Else InitDFAPass2 := True;
  1851. {$Else}
  1852. {Uncomment the next line to see how much memory the reloading optimizer needs}
  1853. { Writeln((NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4)));}
  1854. {no need to check mem/maxavail, we've got as much virtual memory as we want}
  1855. If NrOfPaiObjs <> 0 Then
  1856. Begin
  1857. InitDFAPass2 := True;
  1858. GetMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4));
  1859. p := BlockStart;
  1860. SkipHead(p);
  1861. For Count := 1 To NrOfPaiObjs Do
  1862. Begin
  1863. PPaiProp(p^.OptInfo) := @PaiPropBlock^[Count];
  1864. GetNextInstruction(p, p);
  1865. End;
  1866. End
  1867. Else InitDFAPass2 := False;
  1868. {$EndIf TP}
  1869. End;
  1870. Function DFAPass2(
  1871. {$ifdef statedebug}
  1872. AsmL: PAasmOutPut;
  1873. {$endif statedebug}
  1874. BlockStart, BlockEnd: Pai): Boolean;
  1875. Begin
  1876. If InitDFAPass2(BlockStart, BlockEnd) Then
  1877. Begin
  1878. DoDFAPass2(
  1879. {$ifdef statedebug}
  1880. asml,
  1881. {$endif statedebug}
  1882. BlockStart, BlockEnd);
  1883. DFAPass2 := True
  1884. End
  1885. Else DFAPass2 := False;
  1886. End;
  1887. Procedure ShutDownDFA;
  1888. Begin
  1889. If LabDif <> 0 Then
  1890. FreeMem(LTable, LabDif*SizeOf(TLabelTableItem));
  1891. End;
  1892. End.
  1893. {
  1894. $Log$
  1895. Revision 1.78 2000-01-13 13:07:06 jonas
  1896. * released -dalignreg
  1897. * some small fixes to -dnewOptimizations helper procedures
  1898. Revision 1.77 2000/01/09 01:44:21 jonas
  1899. + (de)allocation info for EDI to fix reported bug on mailinglist.
  1900. Also some (de)allocation info for ESI added. Between -dallocEDI
  1901. because at this time of the night bugs could easily slip in ;)
  1902. Revision 1.76 2000/01/07 01:14:23 peter
  1903. * updated copyright to 2000
  1904. Revision 1.75 1999/12/05 16:48:43 jonas
  1905. * CSE of constant loading in regs works properly again
  1906. + if a constant is stored into memory using "mov const, ref" and
  1907. there is a reg that contains this const, it is changed into
  1908. "mov reg, ref"
  1909. Revision 1.74 1999/12/02 11:26:41 peter
  1910. * newoptimizations define added
  1911. Revision 1.73 1999/11/27 23:45:43 jonas
  1912. * even more missing register deallocations are added!
  1913. Revision 1.72 1999/11/21 13:06:30 jonas
  1914. * improved fixing of missing regallocs (they're almost all correct
  1915. now!)
  1916. Revision 1.71 1999/11/20 12:50:32 jonas
  1917. * fixed small typo (C_M* -> Ch_M*) so -darithopt compiles again
  1918. Revision 1.70 1999/11/14 11:25:38 jonas
  1919. * fixed stupid typo in previous commit :(
  1920. Revision 1.69 1999/11/13 19:01:51 jonas
  1921. * div, idiv and mul destroy edx!!
  1922. Revision 1.68 1999/11/07 14:57:09 jonas
  1923. * much more complete/waterproof RegModifiedByInstruction()
  1924. Revision 1.67 1999/11/06 14:34:20 peter
  1925. * truncated log to 20 revs
  1926. Revision 1.66 1999/11/05 16:01:46 jonas
  1927. + first implementation of choosing least used register for alignment code
  1928. (not yet working, between ifdef alignreg)
  1929. Revision 1.65 1999/10/27 16:11:28 peter
  1930. * insns.dat is used to generate all i386*.inc files
  1931. Revision 1.64 1999/10/23 14:44:24 jonas
  1932. * finally got around making GetNextInstruction return false when
  1933. the current pai object is a AsmBlockStart marker
  1934. * changed a loop in aopt386 which was incompatible with this change
  1935. Revision 1.63 1999/10/14 14:57:52 florian
  1936. - removed the hcodegen use in the new cg, use cgbase instead
  1937. Revision 1.62 1999/10/07 16:07:35 jonas
  1938. * small bugfix in ArrayRefsEq
  1939. Revision 1.61 1999/09/29 13:49:53 jonas
  1940. * writing to a position in an array now only destroys registers
  1941. containing a reference pointing somewhere in that array (since my last
  1942. fix, it behaved like a write to a pointer location)
  1943. Revision 1.60 1999/09/27 23:44:50 peter
  1944. * procinfo is now a pointer
  1945. * support for result setting in sub procedure
  1946. Revision 1.59 1999/09/21 15:46:58 jonas
  1947. * fixed bug in destroyrefs (indexes are now handled as pointers)
  1948. Revision 1.58 1999/09/05 12:37:50 jonas
  1949. * fixed typo's in -darithopt
  1950. Revision 1.57 1999/08/25 12:00:00 jonas
  1951. * changed pai386, paippc and paiapha (same for tai*) to paicpu (taicpu)
  1952. Revision 1.56 1999/08/18 13:25:54 jonas
  1953. * minor fixes regarding the reading of operands
  1954. Revision 1.55 1999/08/12 14:36:03 peter
  1955. + KNI instructions
  1956. Revision 1.54 1999/08/05 15:01:52 jonas
  1957. * fix in -darithopt code (sometimes crashed on 8/16bit regs)
  1958. Revision 1.53 1999/08/04 00:22:59 florian
  1959. * renamed i386asm and i386base to cpuasm and cpubase
  1960. Revision 1.52 1999/08/02 14:35:21 jonas
  1961. * bugfix in DestroyRefs
  1962. Revision 1.51 1999/08/02 12:12:53 jonas
  1963. * also add arithmetic operations to instruction sequences contained in registers
  1964. (compile with -darithopt, very nice!)
  1965. Revision 1.50 1999/07/30 18:18:51 jonas
  1966. * small bugfix in instructionsequal
  1967. * small bugfix in reginsequence
  1968. * made regininstruction a bit more logical
  1969. Revision 1.48 1999/07/01 18:21:21 jonas
  1970. * removed unused AsmL parameter from FindLoHiLabels
  1971. Revision 1.47 1999/05/27 19:44:24 peter
  1972. * removed oldasm
  1973. * plabel -> pasmlabel
  1974. * -a switches to source writing automaticly
  1975. * assembler readers OOPed
  1976. * asmsymbol automaticly external
  1977. * jumptables and other label fixes for asm readers
  1978. Revision 1.46 1999/05/08 20:40:02 jonas
  1979. * seperate OPTimizer INFO pointer field in tai object
  1980. * fix to GetLastInstruction that sometimes caused a crash
  1981. }