daopt386.pas 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417
  1. {
  2. $Id$
  3. Copyright (c) 1997-98 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. Interface
  24. Uses
  25. GlobType,
  26. CObjects,Aasm,
  27. i386base,i386asm
  28. ;
  29. Type
  30. TRegArray = Array[R_EAX..R_BL] of TRegister;
  31. TRegSet = Set of R_EAX..R_BL;
  32. TRegInfo = Record
  33. NewRegsEncountered, OldRegsEncountered: TRegSet;
  34. RegsLoadedForRef: TRegSet;
  35. New2OldReg: TRegArray;
  36. End;
  37. {possible actions on an operand: read, write or modify (= read & write)}
  38. TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
  39. {*********************** Procedures and Functions ************************}
  40. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  41. Function Reg32(Reg: TRegister): TRegister;
  42. Function RefsEquivalent(Const R1, R2: TReference; Var RegInfo: TRegInfo; OpAct: TOpAction): Boolean;
  43. Function RefsEqual(Const R1, R2: TReference): Boolean;
  44. Function IsGP32Reg(Reg: TRegister): Boolean;
  45. Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
  46. Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
  47. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  48. Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
  49. Function GetLastInstruction(Current: Pai; Var Last: Pai): Boolean;
  50. Procedure SkipHead(var P: Pai);
  51. Procedure UpdateUsedRegs(Var UsedRegs: TRegSet; p: Pai);
  52. Function RegsEquivalent(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo; OpAct: TopAction): Boolean;
  53. Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
  54. Function OpsEqual(const o1,o2:toper): Boolean;
  55. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  56. Function DFAPass2(
  57. {$ifdef statedebug}
  58. AsmL: PAasmOutPut;
  59. {$endif statedebug}
  60. BlockStart, BlockEnd: Pai): Boolean;
  61. Procedure ShutDownDFA;
  62. Function FindLabel(L: PasmLabel; Var hp: Pai): Boolean;
  63. {******************************* Constants *******************************}
  64. Const
  65. {ait_* types which don't result in executable code or which don't influence
  66. the way the program runs/behaves}
  67. SkipInstr = [ait_comment, ait_align, ait_symbol
  68. {$ifdef GDB}
  69. ,ait_stabs, ait_stabn, ait_stab_function_name
  70. {$endif GDB}
  71. ,ait_regalloc, ait_tempalloc
  72. ];
  73. {the maximum number of things (registers, memory, ...) a single instruction
  74. changes}
  75. MaxCh = 3;
  76. {Possible register content types}
  77. con_Unknown = 0;
  78. con_ref = 1;
  79. con_const = 2;
  80. {********************************* Types *********************************}
  81. Type
  82. {What an instruction can change}
  83. TChange = (C_None,
  84. {Read from a register}
  85. C_REAX, C_RECX, C_REDX, C_REBX, C_RESP, C_REBP, C_RESI, C_REDI,
  86. {write from a register}
  87. C_WEAX, C_WECX, C_WEDX, C_WEBX, C_WESP, C_WEBP, C_WESI, C_WEDI,
  88. {read and write from/to a register}
  89. C_RWEAX, C_RWECX, C_RWEDX, C_RWEBX, C_RWESP, C_RWEBP, C_RWESI, C_RWEDI,
  90. {modify the contents of a register with the purpose of using
  91. this changed content afterwards (add/sub/..., but e.g. not rep
  92. or movsd)}
  93. {$ifdef arithopt}
  94. C_MEAX, C_MECX, C_MEDX, C_MEBX, C_MESP, C_MEBP, C_MESI, C_MEDI,
  95. {$endif arithopt}
  96. C_CDirFlag {clear direction flag}, C_SDirFlag {set dir flag},
  97. C_RFlags, C_WFlags, C_RWFlags, C_FPU,
  98. C_Rop1, C_Wop1, C_RWop1,
  99. C_Rop2, C_Wop2, C_RWop2,
  100. C_Rop3, C_WOp3, C_RWOp3,
  101. {$ifdef arithopt}
  102. C_Mop1, C_Mop2, C_Mop3,
  103. {$endif arithopt}
  104. C_WMemEDI,
  105. C_All);
  106. {$ifndef arithopt}
  107. Const
  108. C_MEAX = C_RWEAX;
  109. C_MECX = C_RWECX;
  110. C_MEDX = C_RWEDX;
  111. C_MEBX = C_RWEBX;
  112. C_MESP = C_RWESP;
  113. C_MEBP = C_RWEBP;
  114. C_MESI = C_RWESI;
  115. C_MEDI = C_RWEDI;
  116. C_Mop1 = C_RWOp1;
  117. C_Mop2 = C_RWOp2;
  118. C_Mop3 = C_RWOp3;
  119. Type
  120. {$endif arithopt}
  121. {the possible states of a flag}
  122. TFlagContents = (F_Unknown, F_NotSet, F_Set);
  123. {the properties of a cpu instruction}
  124. TAsmInstrucProp = Record
  125. {how many things it changes}
  126. { NCh: Byte;}
  127. {and what it changes}
  128. Ch: Array[1..MaxCh] of TChange;
  129. End;
  130. TContent = Packed Record
  131. {start and end of block instructions that defines the
  132. content of this register. If Typ = con_const, then
  133. Longint(StartMod) = value of the constant)}
  134. StartMod: pai;
  135. {starts at 0, gets increased everytime the register is written to}
  136. WState: Byte;
  137. {starts at 0, gets increased everytime the register is read from}
  138. RState: Byte;
  139. {how many instructions starting with StarMod does the block consist of}
  140. NrOfMods: Byte;
  141. {the type of the content of the register: unknown, memory, constant}
  142. Typ: Byte;
  143. End;
  144. {Contents of the integer registers}
  145. TRegContent = Array[R_EAX..R_EDI] Of TContent;
  146. {contents of the FPU registers}
  147. TRegFPUContent = Array[R_ST..R_ST7] Of TContent;
  148. {information record with the contents of every register. Every Pai object
  149. gets one of these assigned: a pointer to it is stored in the OptInfo field}
  150. TPaiProp = Record
  151. Regs: TRegContent;
  152. { FPURegs: TRegFPUContent;} {currently not yet used}
  153. {allocated Registers}
  154. UsedRegs: TRegSet;
  155. {status of the direction flag}
  156. DirFlag: TFlagContents;
  157. {can this instruction be removed?}
  158. CanBeRemoved: Boolean;
  159. End;
  160. PPaiProp = ^TPaiProp;
  161. {$IfNDef TP}
  162. TPaiPropBlock = Array[1..250000] Of TPaiProp;
  163. PPaiPropBlock = ^TPaiPropBlock;
  164. {$EndIf TP}
  165. TInstrSinceLastMod = Array[R_EAX..R_EDI] Of Byte;
  166. TLabelTableItem = Record
  167. PaiObj: Pai;
  168. {$IfDef JumpAnal}
  169. InstrNr: Longint;
  170. RefsFound: Word;
  171. JmpsProcessed: Word
  172. {$EndIf JumpAnal}
  173. End;
  174. {$IfDef tp}
  175. TLabelTable = Array[0..10000] Of TLabelTableItem;
  176. {$Else tp}
  177. TLabelTable = Array[0..2500000] Of TLabelTableItem;
  178. {$Endif tp}
  179. PLabelTable = ^TLabelTable;
  180. {******************************* Variables *******************************}
  181. Var
  182. {the amount of PaiObjects in the current assembler list}
  183. NrOfPaiObjs: Longint;
  184. {$IfNDef TP}
  185. {Array which holds all TPaiProps}
  186. PaiPropBlock: PPaiPropBlock;
  187. {$EndIf TP}
  188. LoLab, HiLab, LabDif: Longint;
  189. LTable: PLabelTable;
  190. {*********************** End of Interface section ************************}
  191. Implementation
  192. Uses
  193. globals, systems, strings, verbose, hcodegen;
  194. Const AsmInstr: Array[tasmop] Of TAsmInstrucProp = (
  195. {A_<NONE>} (Ch: (C_All, C_None, C_None)), { new }
  196. {A_LOCK} (Ch: (C_None, C_None, C_None)),
  197. {A_REP} (Ch: (C_RWECX, C_RFlags, C_None)),
  198. {A_REPE} (Ch: (C_RWECX, C_RFlags, C_None)),
  199. {A_REPNE} (Ch: (C_RWECX, C_RFlags, C_None)),
  200. {A_REPNZ} (Ch: (C_WECX, C_RWFLAGS, C_None)), { new }
  201. {A_REPZ} (Ch: (C_WECX, C_RWFLAGS, C_None)), { new }
  202. {A_SEGCS} (Ch: (C_None, C_None, C_None)), { new }
  203. {A_SEGES} (Ch: (C_None, C_None, C_None)), { new }
  204. {A_SEGDS} (Ch: (C_None, C_None, C_None)), { new }
  205. {A_SEGFS} (Ch: (C_None, C_None, C_None)), { new }
  206. {A_SEGGS} (Ch: (C_None, C_None, C_None)), { new }
  207. {A_SEGSS} (Ch: (C_None, C_None, C_None)), { new }
  208. {A_AAA} (Ch: (C_MEAX, C_WFlags, C_None)),
  209. {A_AAD} (Ch: (C_MEAX, C_WFlags, C_None)),
  210. {A_AAM} (Ch: (C_MEAX, C_WFlags, C_None)),
  211. {A_AAS} (Ch: (C_MEAX, C_WFlags, C_None)),
  212. {A_ADC} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  213. {A_ADD} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  214. {A_AND} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  215. {A_ARPL} (Ch: (C_WFlags, C_None, C_None)),
  216. {A_BOUND} (Ch: (C_Rop1, C_None, C_None)),
  217. {A_BSF} (Ch: (C_Wop2, C_WFlags, C_Rop1)),
  218. {A_BSR} (Ch: (C_Wop2, C_WFlags, C_Rop1)),
  219. {A_BSWAP} (Ch: (C_MOp1, C_None, C_None)), { new }
  220. {A_BT} (Ch: (C_WFlags, C_Rop1, C_None)),
  221. {A_BTC} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  222. {A_BTR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  223. {A_BTS} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  224. {A_CALL} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  225. {A_CBW} (Ch: (C_MEAX, C_None, C_None)),
  226. {A_CDQ} (Ch: (C_MEAX, C_WEDX, C_None)),
  227. {A_CLC} (Ch: (C_WFlags, C_None, C_None)),
  228. {A_CLD} (Ch: (C_CDirFlag, C_None, C_None)),
  229. {A_CLI} (Ch: (C_WFlags, C_None, C_None)),
  230. {A_CLTS} (Ch: (C_None, C_None, C_None)),
  231. {A_CMC} (Ch: (C_WFlags, C_None, C_None)),
  232. {A_CMP} (Ch: (C_WFlags, C_None, C_None)),
  233. {A_CMPSB} (Ch: (C_All, C_None, C_None)), { new }
  234. {A_CMPSD} (Ch: (C_All, C_None, C_None)), { new }
  235. {A_CMPSW} (Ch: (C_All, C_None, C_None)), { new }
  236. {A_CMPXCHG} (Ch: (C_All, C_None, C_None)), { new }
  237. {A_CMPXCHG486} (Ch: (C_All, C_None, C_None)), { new }
  238. {A_CMPXCHG8B} (Ch: (C_All, C_None, C_None)), { new }
  239. {A_CPUID} (Ch: (C_All, C_None, C_none)),
  240. {A_CWD} (Ch: (C_MEAX, C_WEDX, C_None)),
  241. {A_CWDE} (Ch: (C_MEAX, C_None, C_None)),
  242. {A_DAA} (Ch: (C_MEAX, C_None, C_None)),
  243. {A_DAS} (Ch: (C_MEAX, C_None, C_None)),
  244. {A_DEC} (Ch: (C_Mop1, C_WFlags, C_None)),
  245. {A_DIV} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  246. {A_EMMS} (Ch: (C_FPU, C_None, C_None)), { new }
  247. {A_ENTER} (Ch: (C_RWESP, C_None, C_None)),
  248. {A_EQU} (Ch: (C_None, C_None, C_None)), { new }
  249. {A_F2XM1} (Ch: (C_FPU, C_None, C_None)),
  250. {A_FABS} (Ch: (C_FPU, C_None, C_None)),
  251. {A_FADD} (Ch: (C_FPU, C_None, C_None)),
  252. {A_FADDP} (Ch: (C_FPU, C_None, C_None)),
  253. {A_FBLD} (Ch: (C_Rop1, C_FPU, C_None)),
  254. {A_FBSTP} (Ch: (C_Wop1, C_FPU, C_None)),
  255. {A_FCHS} (Ch: (C_FPU, C_None, C_None)),
  256. {A_FCLEX} (Ch: (C_FPU, C_None, C_None)),
  257. {A_FCMOVB} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  258. {A_FCMOVBE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  259. {A_FCMOVE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  260. {A_FCMOVNB} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  261. {A_FCMOVNBE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  262. {A_FCMOVNE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  263. {A_FCMOVNU} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  264. {A_FCMOVU} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  265. {A_FCOM} (Ch: (C_FPU, C_None, C_None)),
  266. {A_FCOMI} (Ch: (C_WFLAGS, C_None, C_None)), { new }
  267. {A_FCOMIP} (Ch: (C_FPU, C_WFLAGS, C_None)), { new }
  268. {A_FCOMP} (Ch: (C_FPU, C_None, C_None)),
  269. {A_FCOMPP} (Ch: (C_FPU, C_None, C_None)),
  270. {A_FCOS} (Ch: (C_FPU, C_None, C_None)),
  271. {A_FDECSTP} (Ch: (C_FPU, C_None, C_None)),
  272. {A_FDISI} (Ch: (C_FPU, C_None, C_None)),
  273. {A_FDIV} (Ch: (C_FPU, C_None, C_None)),
  274. {A_FDIVP} (Ch: (C_FPU, C_None, C_None)),
  275. {A_FDIVR} (Ch: (C_FPU, C_None, C_None)),
  276. {A_FDIVRP} (Ch: (C_FPU, C_None, C_None)),
  277. {A_FEMMS} (Ch: (C_All, C_None, C_None)), { new }
  278. {A_FENI} (Ch: (C_FPU, C_None, C_None)),
  279. {A_FFREE} (Ch: (C_FPU, C_None, C_None)),
  280. {A_FIADD} (Ch: (C_FPU, C_None, C_None)),
  281. {A_FICOM} (Ch: (C_FPU, C_None, C_None)),
  282. {A_FICOMP} (Ch: (C_FPU, C_None, C_None)),
  283. {A_FIDIV} (Ch: (C_FPU, C_None, C_None)),
  284. {A_FIDIVR} (Ch: (C_FPU, C_None, C_None)),
  285. {A_FILD} (Ch: (C_FPU, C_None, C_None)),
  286. {A_FIMUL} (Ch: (C_FPU, C_None, C_None)),
  287. {A_FINCSTP} (Ch: (C_FPU, C_None, C_None)),
  288. {A_FINIT} (Ch: (C_FPU, C_None, C_None)),
  289. {A_FIST} (Ch: (C_Wop1, C_None, C_None)),
  290. {A_FISTP} (Ch: (C_Wop1, C_None, C_None)),
  291. {A_FISUB} (Ch: (C_FPU, C_None, C_None)),
  292. {A_FISUBR} (Ch: (C_FPU, C_None, C_None)), { new }
  293. {A_FLD} (Ch: (C_Rop1, C_FPU, C_None)),
  294. {A_FLD1} (Ch: (C_FPU, C_None, C_None)),
  295. {A_FLDCW} (Ch: (C_FPU, C_None, C_None)),
  296. {A_FLDENV} (Ch: (C_FPU, C_None, C_None)),
  297. {A_FLDL2E} (Ch: (C_FPU, C_None, C_None)),
  298. {A_FLDL2T} (Ch: (C_FPU, C_None, C_None)),
  299. {A_FLDLG2} (Ch: (C_FPU, C_None, C_None)),
  300. {A_FLDLN2} (Ch: (C_FPU, C_None, C_None)),
  301. {A_FLDPI} (Ch: (C_FPU, C_None, C_None)),
  302. {A_FLDZ} (Ch: (C_FPU, C_None, C_None)),
  303. {A_FMUL} (Ch: (C_FPU, C_None, C_None)),
  304. {A_FMULP} (Ch: (C_FPU, C_None, C_None)),
  305. {A_FNCLEX} (Ch: (C_FPU, C_None, C_None)),
  306. {A_FNDISI} (Ch: (C_FPU, C_None, C_None)),
  307. {A_FNENI} (Ch: (C_FPU, C_None, C_None)),
  308. {A_FNINIT} (Ch: (C_FPU, C_None, C_None)),
  309. {A_FNOP} (Ch: (C_FPU, C_None, C_None)),
  310. {A_FNSAVE} (Ch: (C_FPU, C_None, C_None)),
  311. {A_FNSTCW} (Ch: (C_Wop1, C_None, C_None)),
  312. {A_FNSTENV} (Ch: (C_Wop1, C_None, C_None)),
  313. {A_FNSTSW} (Ch: (C_Wop1, C_None, C_None)),
  314. {A_FPATAN} (Ch: (C_FPU, C_None, C_None)),
  315. {A_FPREM} (Ch: (C_FPU, C_None, C_None)),
  316. {A_FPREM1} (Ch: (C_FPU, C_None, C_None)),
  317. {A_FPTAN} (Ch: (C_FPU, C_None, C_None)),
  318. {A_FRNDINT} (Ch: (C_FPU, C_None, C_None)),
  319. {A_FRSTOR} (Ch: (C_FPU, C_None, C_None)),
  320. {A_FSAVE} (Ch: (C_Wop1, C_None, C_None)),
  321. {A_FSCALE} (Ch: (C_FPU, C_None, C_None)),
  322. {A_FSETPM} (Ch: (C_FPU, C_None, C_None)),
  323. {A_FSIN} (Ch: (C_FPU, C_None, C_None)),
  324. {A_FSINCOS} (Ch: (C_FPU, C_None, C_None)),
  325. {A_FSQRT} (Ch: (C_FPU, C_None, C_None)),
  326. {A_FST} (Ch: (C_Wop1, C_None, C_None)),
  327. {A_FSTCW} (Ch: (C_Wop1, C_None, C_None)),
  328. {A_FSTENV} (Ch: (C_Wop1, C_None, C_None)),
  329. {A_FSTP} (Ch: (C_Wop1, C_FPU, C_None)),
  330. {A_FSTSW} (Ch: (C_Wop1, C_None, C_None)),
  331. {A_FSUB} (Ch: (C_FPU, C_None, C_None)),
  332. {A_FSUBP} (Ch: (C_FPU, C_None, C_None)),
  333. {A_FSUBR} (Ch: (C_FPU, C_None, C_None)),
  334. {A_FSUBRP} (Ch: (C_FPU, C_None, C_None)),
  335. {A_FTST} (Ch: (C_FPU, C_None, C_None)),
  336. {A_FUCOM} (Ch: (C_None, C_None, C_None)), {changes fpu status word}
  337. {A_FUCOMI} (Ch: (C_WFLAGS, C_None, C_None)), { new }
  338. {A_FUCOMIP} (Ch: (C_FPU, C_WFLAGS, C_None)), { new }
  339. {A_FUCOMP} (Ch: (C_FPU, C_None, C_None)),
  340. {A_FUCOMPP} (Ch: (C_FPU, C_None, C_None)),
  341. {A_FWAIT} (Ch: (C_FPU, C_None, C_None)),
  342. {A_FXAM} (Ch: (C_FPU, C_None, C_None)),
  343. {A_FXCH} (Ch: (C_FPU, C_None, C_None)),
  344. {A_FXTRACT} (Ch: (C_FPU, C_None, C_None)),
  345. {A_FYL2X} (Ch: (C_FPU, C_None, C_None)),
  346. {A_FYL2XP1} (Ch: (C_FPU, C_None, C_None)),
  347. {A_HLT} (Ch: (C_None, C_None, C_None)),
  348. {A_IBTS} (Ch: (C_All, C_None, C_None)), { new }
  349. {A_ICEBP} (Ch: (C_All, C_None, C_None)), { new }
  350. {A_IDIV} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  351. {A_IMUL} (Ch: (C_RWEAX, C_WEDX, C_WFlags)), {handled separately, because several forms exist}
  352. {A_IN} (Ch: (C_Wop2, C_Rop1, C_None)),
  353. {A_INC} (Ch: (C_Mop1, C_WFlags, C_None)),
  354. {A_INSB} (Ch: (C_WMemEDI, C_RWEDI, C_None)), { new }
  355. {A_INSD} (Ch: (C_WMemEDI, C_RWEDI, C_None)), { new }
  356. {A_INSW} (Ch: (C_WMemEDI, C_RWEDI, C_None)), { new }
  357. {A_INT} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  358. {A_INT01} (Ch: (C_All, C_None, C_None)), { new }
  359. {A_INT1} (Ch: (C_All, C_None, C_None)), { new }
  360. {A_INT3} (Ch: (C_None, C_None, C_None)),
  361. {A_INTO} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  362. {A_INVD} (Ch: (C_All, C_None, C_None)), { new }
  363. {A_INVLPG} (Ch: (C_All, C_None, C_None)), { new }
  364. {A_IRET} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  365. {A_IRETD} (Ch: (C_All, C_None, C_None)), { new }
  366. {A_IRETW} (Ch: (C_All, C_None, C_None)), { new }
  367. {A_JCXZ} (Ch: (C_RECX, C_None, C_None)),
  368. {A_JECXZ} (Ch: (C_RECX, C_None, C_None)),
  369. {A_JMP} (Ch: (C_None, C_None, C_None)),
  370. {A_LAHF} (Ch: (C_WEAX, C_RFlags, C_None)),
  371. {A_LAR} (Ch: (C_Wop2, C_None, C_None)),
  372. {A_LDS} (Ch: (C_Wop2, C_None, C_None)),
  373. {A_LEA} (Ch: (C_Wop2, C_Rop1, C_None)),
  374. {A_LEAVE} (Ch: (C_RWESP, C_None, C_None)),
  375. {A_LES} (Ch: (C_Wop2, C_None, C_None)),
  376. {A_LFS} (Ch: (C_Wop2, C_None, C_None)),
  377. {A_LGDT} (Ch: (C_None, C_None, C_None)),
  378. {A_LGS} (Ch: (C_Wop2, C_None, C_None)),
  379. {A_LIDT} (Ch: (C_None, C_None, C_None)),
  380. {A_LLDT} (Ch: (C_None, C_None, C_None)),
  381. {A_LMSW} (Ch: (C_None, C_None, C_None)),
  382. {A_LOADALL} (Ch: (C_All, C_None, C_None)), { new }
  383. {A_LOADALL286} (Ch: (C_All, C_None, C_None)), { new }
  384. {A_LODSB} (Ch: (C_WEAX, C_RWESI, C_None)), { new }
  385. {A_LODSD} (Ch: (C_WEAX, C_RWESI, C_None)), { new }
  386. {A_LODSW} (Ch: (C_WEAX, C_RWESI, C_None)), { new }
  387. {A_LOOP} (Ch: (C_RWECX, C_None, C_None)),
  388. {A_LOOPE} (Ch: (C_RWECX, C_RFlags, C_None)),
  389. {A_LOOPNE} (Ch: (C_RWECX, C_RFlags, C_None)),
  390. {A_LOOPNZ} (Ch: (C_RWECX, C_RFlags, C_None)),
  391. {A_LOOPZ} (Ch: (C_RWECX, C_RFlags, C_None)),
  392. {A_LSL} (Ch: (C_Wop2, C_WFlags, C_None)),
  393. {A_LSS} (Ch: (C_Wop2, C_None, C_None)),
  394. {A_LTR} (Ch: (C_None, C_None, C_None)),
  395. {A_MOV} (Ch: (C_Wop2, C_Rop1, C_None)),
  396. {A_MOVD} (Ch: (C_All, C_None, C_None)), { new }
  397. {A_MOVQ} (Ch: (C_All, C_None, C_None)), { new }
  398. {A_MOVSB} (Ch: (C_All, C_Rop1, C_None)),
  399. {A_MOVSD} (Ch: (C_All, C_None, C_None)), { new }
  400. {A_MOVSW} (Ch: (C_All, C_None, C_None)), { new }
  401. {A_MOVSX} (Ch: (C_Wop2, C_Rop1, C_None)),
  402. {A_MOVZX} (Ch: (C_Wop2, C_Rop1, C_None)),
  403. {A_MUL} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  404. {A_NEG} (Ch: (C_Mop1, C_None, C_None)),
  405. {A_NOP} (Ch: (C_None, C_None, C_None)),
  406. {A_NOT} (Ch: (C_Mop1, C_WFlags, C_None)),
  407. {A_OR} (Ch: (C_Mop2, C_WFlags, C_None)),
  408. {A_OUT} (Ch: (C_Rop1, C_Rop2, C_None)),
  409. {A_OUTSB} (Ch: (C_All, C_None, C_None)), { new }
  410. {A_OUTSD} (Ch: (C_All, C_None, C_None)), { new }
  411. {A_OUTSW} (Ch: (C_All, C_None, C_None)), { new }
  412. {A_PACKSSDW} (Ch: (C_All, C_None, C_None)), { new }
  413. {A_PACKSSWB} (Ch: (C_All, C_None, C_None)), { new }
  414. {A_PACKUSWB} (Ch: (C_All, C_None, C_None)), { new }
  415. {A_PADDB} (Ch: (C_All, C_None, C_None)), { new }
  416. {A_PADDD} (Ch: (C_All, C_None, C_None)), { new }
  417. {A_PADDSB} (Ch: (C_All, C_None, C_None)), { new }
  418. {A_PADDSIW} (Ch: (C_All, C_None, C_None)), { new }
  419. {A_PADDSW} (Ch: (C_All, C_None, C_None)), { new }
  420. {A_PADDUSB} (Ch: (C_All, C_None, C_None)), { new }
  421. {A_PADDUSW} (Ch: (C_All, C_None, C_None)), { new }
  422. {A_PADDW} (Ch: (C_All, C_None, C_None)), { new }
  423. {A_PAND} (Ch: (C_All, C_None, C_None)), { new }
  424. {A_PANDN} (Ch: (C_All, C_None, C_None)), { new }
  425. {A_PAVEB} (Ch: (C_All, C_None, C_None)), { new }
  426. {A_PAVGUSB} (Ch: (C_All, C_None, C_None)), { new }
  427. {A_PCMPEQB} (Ch: (C_All, C_None, C_None)), { new }
  428. {A_PCMPEQD} (Ch: (C_All, C_None, C_None)), { new }
  429. {A_PCMPEQW} (Ch: (C_All, C_None, C_None)), { new }
  430. {A_PCMPGTB} (Ch: (C_All, C_None, C_None)), { new }
  431. {A_PCMPGTD} (Ch: (C_All, C_None, C_None)), { new }
  432. {A_PCMPGTW} (Ch: (C_All, C_None, C_None)), { new }
  433. {A_PDISTIB} (Ch: (C_All, C_None, C_None)), { new }
  434. {A_PF2ID} (Ch: (C_All, C_None, C_None)), { new }
  435. {A_PFACC} (Ch: (C_All, C_None, C_None)), { new }
  436. {A_PFADD} (Ch: (C_All, C_None, C_None)), { new }
  437. {A_PFCMPEQ} (Ch: (C_All, C_None, C_None)), { new }
  438. {A_PFCMPGE} (Ch: (C_All, C_None, C_None)), { new }
  439. {A_PFCMPGT} (Ch: (C_All, C_None, C_None)), { new }
  440. {A_PFMAX} (Ch: (C_All, C_None, C_None)), { new }
  441. {A_PFMIN} (Ch: (C_All, C_None, C_None)), { new }
  442. {A_PFMUL} (Ch: (C_All, C_None, C_None)), { new }
  443. {A_PFRCP} (Ch: (C_All, C_None, C_None)), { new }
  444. {A_PFRCPIT1} (Ch: (C_All, C_None, C_None)), { new }
  445. {A_PFRCPIT2} (Ch: (C_All, C_None, C_None)), { new }
  446. {A_PFRSQIT1} (Ch: (C_All, C_None, C_None)), { new }
  447. {A_PFRSQRT} (Ch: (C_All, C_None, C_None)), { new }
  448. {A_PFSUB} (Ch: (C_All, C_None, C_None)), { new }
  449. {A_PFSUBR} (Ch: (C_All, C_None, C_None)), { new }
  450. {A_PI2FD} (Ch: (C_All, C_None, C_None)), { new }
  451. {A_PMACHRIW} (Ch: (C_All, C_None, C_None)), { new }
  452. {A_PMADDWD} (Ch: (C_All, C_None, C_None)), { new }
  453. {A_PMAGW} (Ch: (C_All, C_None, C_None)), { new }
  454. {A_PMULHRIW} (Ch: (C_All, C_None, C_None)), { new }
  455. {A_PMULHRWA} (Ch: (C_All, C_None, C_None)), { new }
  456. {A_PMULHRWC} (Ch: (C_All, C_None, C_None)), { new }
  457. {A_PMULHW} (Ch: (C_All, C_None, C_None)), { new }
  458. {A_PMULLW} (Ch: (C_All, C_None, C_None)), { new }
  459. {A_PMVGEZB} (Ch: (C_All, C_None, C_None)), { new }
  460. {A_PMVLZB} (Ch: (C_All, C_None, C_None)), { new }
  461. {A_PMVNZB} (Ch: (C_All, C_None, C_None)), { new }
  462. {A_PMVZB} (Ch: (C_All, C_None, C_None)), { new }
  463. {A_POP} (Ch: (C_Wop1, C_RWESP, C_None)),
  464. {A_POPA} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  465. {A_POPAD} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  466. {A_POPAW} (Ch: (C_All, C_None, C_None)), { new }
  467. {A_POPF} (Ch: (C_RWESP, C_WFlags, C_None)),
  468. {A_POPFD} (Ch: (C_RWESP, C_WFlags, C_None)),
  469. {A_POPFW} (Ch: (C_RWESP, C_WFLAGS, C_None)), { new }
  470. {A_POR} (Ch: (C_All, C_None, C_None)), { new }
  471. {A_PREFETCH} (Ch: (C_All, C_None, C_None)), { new }
  472. {A_PREFETCHW} (Ch: (C_All, C_None, C_None)), { new }
  473. {A_PSLLD} (Ch: (C_All, C_None, C_None)), { new }
  474. {A_PSLLQ} (Ch: (C_All, C_None, C_None)), { new }
  475. {A_PSLLW} (Ch: (C_All, C_None, C_None)), { new }
  476. {A_PSRAD} (Ch: (C_All, C_None, C_None)), { new }
  477. {A_PSRAW} (Ch: (C_All, C_None, C_None)), { new }
  478. {A_PSRLD} (Ch: (C_All, C_None, C_None)), { new }
  479. {A_PSRLQ} (Ch: (C_All, C_None, C_None)), { new }
  480. {A_PSRLW} (Ch: (C_All, C_None, C_None)), { new }
  481. {A_PSUBB} (Ch: (C_All, C_None, C_None)), { new }
  482. {A_PSUBD} (Ch: (C_All, C_None, C_None)), { new }
  483. {A_PSUBSB} (Ch: (C_All, C_None, C_None)), { new }
  484. {A_PSUBSIW} (Ch: (C_All, C_None, C_None)), { new }
  485. {A_PSUBSW} (Ch: (C_All, C_None, C_None)), { new }
  486. {A_PSUBUSB} (Ch: (C_All, C_None, C_None)), { new }
  487. {A_PSUBUSW} (Ch: (C_All, C_None, C_None)), { new }
  488. {A_PSUBW} (Ch: (C_All, C_None, C_None)), { new }
  489. {A_PUNPCKHBW} (Ch: (C_All, C_None, C_None)), { new }
  490. {A_PUNPCKHDQ} (Ch: (C_All, C_None, C_None)), { new }
  491. {A_PUNPCKHWD} (Ch: (C_All, C_None, C_None)), { new }
  492. {A_PUNPCKLBW} (Ch: (C_All, C_None, C_None)), { new }
  493. {A_PUNPCKLDQ} (Ch: (C_All, C_None, C_None)), { new }
  494. {A_PUNPCKLWD} (Ch: (C_All, C_None, C_None)), { new }
  495. {A_PUSH} (Ch: (C_Rop1, C_RWESP, C_None)),
  496. {A_PUSHA} (Ch: (C_All, C_None, C_None)),
  497. {A_PUSHAD} (Ch: (C_All, C_None, C_None)),
  498. {A_PUSHAW} (Ch: (C_All, C_None, C_None)), { new }
  499. {A_PUSHF} (Ch: (C_RWESP, C_RFlags, C_None)),
  500. {A_PUSHFD} (Ch: (C_RWESP, C_RFlags, C_None)),
  501. {A_PUSHFW} (Ch: (C_RWESP, C_RFLAGS, C_None)), { new }
  502. {A_PXOR} (Ch: (C_All, C_None, C_None)), { new }
  503. {A_RCL} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  504. {A_RCR} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  505. {A_RDMSR} (Ch: (C_WEAX, C_WEDX, C_None)), { new }
  506. {A_RDPMC} (Ch: (C_WEAX, C_WEDX, C_None)), { new }
  507. {A_RDTSC} (Ch: (C_WEAX, C_WEDX, C_None)), { new }
  508. {A_RESB} (Ch: (C_All, C_None, C_None)), { new }
  509. {A_RET} (Ch: (C_All, C_None, C_None)),
  510. {A_RETF} (Ch: (C_All, C_None, C_None)), { new }
  511. {A_RETN} (Ch: (C_All, C_None, C_None)), { new }
  512. {A_ROL} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  513. {A_ROR} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  514. {A_RSM} (Ch: (C_All, C_None, C_None)), { new }
  515. {A_SAHF} (Ch: (C_WFlags, C_REAX, C_None)),
  516. {A_SAL} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  517. {A_SALC} (Ch: (C_WEAX, C_RFLAGS, C_None)), { new }
  518. {A_SAR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  519. {A_SBB} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  520. {A_SCASB} (Ch: (C_All, C_None, C_None)), { new }
  521. {A_SCASD} (Ch: (C_All, C_None, C_None)), { new }
  522. {A_SCASW} (Ch: (C_All, C_None, C_None)), { new }
  523. {A_SGDT} (Ch: (C_Wop1, C_None, C_None)),
  524. {A_SHL} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  525. {A_SHLD} (Ch: (C_MOp3, C_RWFlags, C_Rop2)),
  526. {A_SHR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  527. {A_SHRD} (Ch: (C_MOp3, C_RWFlags, C_Rop2)),
  528. {A_SIDT} (Ch: (C_Wop1, C_None, C_None)),
  529. {A_SLDT} (Ch: (C_Wop1, C_None, C_None)),
  530. {A_SMI} (Ch: (C_All, C_None, C_None)), { new }
  531. {A_SMSW} (Ch: (C_Wop1, C_None, C_None)),
  532. {A_STC} (Ch: (C_WFlags, C_None, C_None)),
  533. {A_STD} (Ch: (C_SDirFlag, C_None, C_None)),
  534. {A_STI} (Ch: (C_WFlags, C_None, C_None)),
  535. {A_STOSB} (Ch: (C_REAX, C_WMemEDI, C_RWEDI)), { new }
  536. {A_STOSD} (Ch: (C_REAX, C_WMemEDI, C_RWEDI)), { new }
  537. {A_STOSW} (Ch: (C_REAX, C_WMemEDI, C_RWEDI)), { new }
  538. {A_STR} (Ch: (C_Wop1, C_None, C_None)),
  539. {A_SUB} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  540. {A_TEST} (Ch: (C_WFlags, C_Rop1, C_Rop2)),
  541. {A_UMOV} (Ch: (C_All, C_None, C_None)), { new }
  542. {A_VERR} (Ch: (C_WFlags, C_None, C_None)),
  543. {A_VERW} (Ch: (C_WFlags, C_None, C_None)),
  544. {A_WAIT} (Ch: (C_None, C_None, C_None)),
  545. {A_WBINVD} (Ch: (C_None, C_None, C_None)), { new }
  546. {A_WRMSR} (Ch: (C_All, C_None, C_None)), { new }
  547. {A_XADD} (Ch: (C_All, C_None, C_None)), { new }
  548. {A_XBTS} (Ch: (C_All, C_None, C_None)), { new }
  549. {A_XCHG} (Ch: (C_RWop1, C_RWop2, C_None)), {(might be) handled seperately}
  550. {A_XLAT} (Ch: (C_WEAX, C_REBX, C_None)),
  551. {A_XLATB} (Ch: (C_WEAX, C_REBX, C_None)),
  552. {A_XOR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  553. {A_CMOV} (Ch: (C_ROp1, C_WOp2, C_RFLAGS)), { new }
  554. {A_J} (Ch: (C_None, C_None, C_None)), { new }
  555. {A_SET} (Ch: (C_WEAX, C_RFLAGS, C_None)) { new }
  556. );
  557. Var
  558. {How many instructions are between the current instruction and the last one
  559. that modified the register}
  560. NrOfInstrSinceLastMod: TInstrSinceLastMod;
  561. {************************ Create the Label table ************************}
  562. Function FindLoHiLabels(Var LowLabel, HighLabel, LabelDif: Longint; BlockStart: Pai): Pai;
  563. {Walks through the paasmlist to find the lowest and highest label number}
  564. Var LabelFound: Boolean;
  565. P: Pai;
  566. Begin
  567. LabelFound := False;
  568. LowLabel := MaxLongint;
  569. HighLabel := 0;
  570. P := BlockStart;
  571. While Assigned(P) And
  572. ((P^.typ <> Ait_Marker) Or
  573. (Pai_Marker(P)^.Kind <> AsmBlockStart)) Do
  574. Begin
  575. If (Pai(p)^.typ = ait_label) Then
  576. If (Pai_Label(p)^.l^.is_used)
  577. Then
  578. Begin
  579. LabelFound := True;
  580. If (Pai_Label(p)^.l^.labelnr < LowLabel) Then
  581. LowLabel := Pai_Label(p)^.l^.labelnr;
  582. If (Pai_Label(p)^.l^.labelnr > HighLabel) Then
  583. HighLabel := Pai_Label(p)^.l^.labelnr;
  584. End;
  585. GetNextInstruction(p, p);
  586. End;
  587. FindLoHiLabels := p;
  588. If LabelFound
  589. Then LabelDif := HighLabel+1-LowLabel
  590. Else LabelDif := 0;
  591. End;
  592. Function FindRegAlloc(Reg: TRegister; StartPai: Pai): Boolean;
  593. {Returns true if a ait_alloc object for Reg is found in the block of Pai's
  594. starting with StartPai and ending with the next "real" instruction}
  595. Begin
  596. FindRegAlloc:=False;
  597. Repeat
  598. While Assigned(StartPai) And
  599. ((StartPai^.typ in (SkipInstr - [ait_regAlloc])) Or
  600. ((StartPai^.typ = ait_label) and
  601. Not(Pai_Label(StartPai)^.l^.Is_Used))) Do
  602. StartPai := Pai(StartPai^.Next);
  603. If Assigned(StartPai) And
  604. (StartPai^.typ = ait_regAlloc) and (PairegAlloc(StartPai)^.allocation) Then
  605. Begin
  606. if PairegAlloc(StartPai)^.Reg = Reg then
  607. begin
  608. FindRegAlloc:=true;
  609. exit;
  610. end;
  611. StartPai := Pai(StartPai^.Next);
  612. End
  613. else
  614. exit;
  615. Until false;
  616. End;
  617. Procedure BuildLabelTableAndFixRegAlloc(AsmL: PAasmOutput; Var LabelTable: PLabelTable; LowLabel: Longint;
  618. Var LabelDif: Longint; BlockStart, BlockEnd: Pai);
  619. {Builds a table with the locations of the labels in the paasmoutput.
  620. Also fixes some RegDeallocs like "# %eax released; push (%eax)"}
  621. Var p, hp1, hp2: Pai;
  622. UsedRegs: TRegSet;
  623. Begin
  624. UsedRegs := [];
  625. If (LabelDif <> 0) Then
  626. Begin
  627. {$IfDef TP}
  628. If (MaxAvail >= LabelDif*SizeOf(Pai))
  629. Then
  630. Begin
  631. {$EndIf TP}
  632. GetMem(LabelTable, LabelDif*SizeOf(TLabelTableItem));
  633. FillChar(LabelTable^, LabelDif*SizeOf(TLabelTableItem), 0);
  634. p := BlockStart;
  635. While (P <> BlockEnd) Do
  636. Begin
  637. Case p^.typ Of
  638. ait_Label:
  639. If Pai_Label(p)^.l^.is_used Then
  640. LabelTable^[Pai_Label(p)^.l^.labelnr-LowLabel].PaiObj := p;
  641. ait_regAlloc:
  642. begin
  643. if PairegAlloc(p)^.Allocation then
  644. Begin
  645. If Not(PaiRegAlloc(p)^.Reg in UsedRegs) Then
  646. UsedRegs := UsedRegs + [PaiRegAlloc(p)^.Reg]
  647. Else
  648. Begin
  649. hp1 := p;
  650. hp2 := nil;
  651. While GetLastInstruction(hp1, hp1) And
  652. Not(RegInInstruction(PaiRegAlloc(p)^.Reg, hp1)) Do
  653. hp2 := hp1;
  654. If hp2 <> nil Then
  655. Begin
  656. hp1 := New(PaiRegAlloc, DeAlloc(PaiRegAlloc(p)^.Reg));
  657. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp1);
  658. End;
  659. End;
  660. End
  661. else
  662. Begin
  663. UsedRegs := UsedRegs - [PaiRegAlloc(p)^.Reg];
  664. hp1 := p;
  665. hp2 := nil;
  666. While Not(FindRegAlloc(PaiRegAlloc(p)^.Reg, Pai(hp1^.Next))) And
  667. GetNextInstruction(hp1, hp1) And
  668. RegInInstruction(PaiRegAlloc(p)^.Reg, hp1) Do
  669. hp2 := hp1;
  670. If hp2 <> nil Then
  671. Begin
  672. hp1 := Pai(p^.previous);
  673. AsmL^.Remove(p);
  674. InsertLLItem(AsmL, hp2, Pai(hp2^.Next), p);
  675. p := hp1;
  676. End;
  677. End;
  678. end;
  679. End;
  680. P := Pai(p^.Next);
  681. While Assigned(p) And
  682. (p^.typ in (SkipInstr - [ait_regalloc])) Do
  683. P := Pai(P^.Next);
  684. End;
  685. {$IfDef TP}
  686. End
  687. Else LabelDif := 0;
  688. {$EndIf TP}
  689. End;
  690. End;
  691. {************************ Search the Label table ************************}
  692. Function FindLabel(L: PasmLabel; Var hp: Pai): Boolean;
  693. {searches for the specified label starting from hp as long as the
  694. encountered instructions are labels, to be able to optimize constructs like
  695. jne l2 jmp l2
  696. jmp l3 and l1:
  697. l1: l2:
  698. l2:}
  699. Var TempP: Pai;
  700. Begin
  701. TempP := hp;
  702. While Assigned(TempP) and
  703. (TempP^.typ In SkipInstr + [ait_label]) Do
  704. If (TempP^.typ <> ait_Label) Or
  705. (pai_label(TempP)^.l <> L)
  706. Then GetNextInstruction(TempP, TempP)
  707. Else
  708. Begin
  709. hp := TempP;
  710. FindLabel := True;
  711. exit
  712. End;
  713. FindLabel := False;
  714. End;
  715. {************************ Some general functions ************************}
  716. Function Reg32(Reg: TRegister): TRegister;
  717. {Returns the 32 bit component of Reg if it exists, otherwise Reg is returned}
  718. Begin
  719. Reg32 := Reg;
  720. If (Reg >= R_AX)
  721. Then
  722. If (Reg <= R_DI)
  723. Then Reg32 := Reg16ToReg32(Reg)
  724. Else
  725. If (Reg <= R_BL)
  726. Then Reg32 := Reg8toReg32(Reg);
  727. End;
  728. { inserts new_one between prev and foll }
  729. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  730. Begin
  731. If Assigned(prev) Then
  732. If Assigned(foll) Then
  733. Begin
  734. If Assigned(new_one) Then
  735. Begin
  736. new_one^.previous := prev;
  737. new_one^.next := foll;
  738. prev^.next := new_one;
  739. foll^.previous := new_one;
  740. End;
  741. End
  742. Else AsmL^.Concat(new_one)
  743. Else If Assigned(Foll) Then AsmL^.Insert(new_one)
  744. End;
  745. {********************* Compare parts of Pai objects *********************}
  746. Function RegsSameSize(Reg1, Reg2: TRegister): Boolean;
  747. {returns true if Reg1 and Reg2 are of the same size (so if they're both
  748. 8bit, 16bit or 32bit)}
  749. Begin
  750. If (Reg1 <= R_EDI)
  751. Then RegsSameSize := (Reg2 <= R_EDI)
  752. Else
  753. If (Reg1 <= R_DI)
  754. Then RegsSameSize := (Reg2 in [R_AX..R_DI])
  755. Else
  756. If (Reg1 <= R_BL)
  757. Then RegsSameSize := (Reg2 in [R_AL..R_BL])
  758. Else RegsSameSize := False
  759. End;
  760. Procedure AddReg2RegInfo(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo);
  761. {updates the ???RegsEncountered and ???2???Reg fields of RegInfo. Assumes that
  762. OldReg and NewReg have the same size (has to be chcked in advance with
  763. RegsSameSize) and that neither equals R_NO}
  764. Begin
  765. With RegInfo Do
  766. Begin
  767. NewRegsEncountered := NewRegsEncountered + [NewReg];
  768. OldRegsEncountered := OldRegsEncountered + [OldReg];
  769. New2OldReg[NewReg] := OldReg;
  770. Case OldReg Of
  771. R_EAX..R_EDI:
  772. Begin
  773. NewRegsEncountered := NewRegsEncountered + [Reg32toReg16(NewReg)];
  774. OldRegsEncountered := OldRegsEncountered + [Reg32toReg16(OldReg)];
  775. New2OldReg[Reg32toReg16(NewReg)] := Reg32toReg16(OldReg);
  776. If (NewReg in [R_EAX..R_EBX]) And
  777. (OldReg in [R_EAX..R_EBX]) Then
  778. Begin
  779. NewRegsEncountered := NewRegsEncountered + [Reg32toReg8(NewReg)];
  780. OldRegsEncountered := OldRegsEncountered + [Reg32toReg8(OldReg)];
  781. New2OldReg[Reg32toReg8(NewReg)] := Reg32toReg8(OldReg);
  782. End;
  783. End;
  784. R_AX..R_DI:
  785. Begin
  786. NewRegsEncountered := NewRegsEncountered + [Reg16toReg32(NewReg)];
  787. OldRegsEncountered := OldRegsEncountered + [Reg16toReg32(OldReg)];
  788. New2OldReg[Reg16toReg32(NewReg)] := Reg16toReg32(OldReg);
  789. If (NewReg in [R_AX..R_BX]) And
  790. (OldReg in [R_AX..R_BX]) Then
  791. Begin
  792. NewRegsEncountered := NewRegsEncountered + [Reg16toReg8(NewReg)];
  793. OldRegsEncountered := OldRegsEncountered + [Reg16toReg8(OldReg)];
  794. New2OldReg[Reg16toReg8(NewReg)] := Reg16toReg8(OldReg);
  795. End;
  796. End;
  797. R_AL..R_BL:
  798. Begin
  799. NewRegsEncountered := NewRegsEncountered + [Reg8toReg32(NewReg)]
  800. + [Reg8toReg16(NewReg)];
  801. OldRegsEncountered := OldRegsEncountered + [Reg8toReg32(OldReg)]
  802. + [Reg8toReg16(OldReg)];
  803. New2OldReg[Reg8toReg32(NewReg)] := Reg8toReg32(OldReg);
  804. End;
  805. End;
  806. End;
  807. End;
  808. Procedure AddOp2RegInfo(const o:Toper; Var RegInfo: TRegInfo);
  809. Begin
  810. Case o.typ Of
  811. Top_Reg:
  812. If (o.reg <> R_NO) Then
  813. AddReg2RegInfo(o.reg, o.reg, RegInfo);
  814. Top_Ref:
  815. Begin
  816. If o.ref^.base <> R_NO Then
  817. AddReg2RegInfo(o.ref^.base, o.ref^.base, RegInfo);
  818. If o.ref^.index <> R_NO Then
  819. AddReg2RegInfo(o.ref^.index, o.ref^.index, RegInfo);
  820. End;
  821. End;
  822. End;
  823. Function RegsEquivalent(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo; OPAct: TOpAction): Boolean;
  824. Begin
  825. If Not((OldReg = R_NO) Or (NewReg = R_NO)) Then
  826. If RegsSameSize(OldReg, NewReg) Then
  827. With RegInfo Do
  828. {here we always check for the 32 bit component, because it is possible that
  829. the 8 bit component has not been set, event though NewReg already has been
  830. processed. This happens if it has been compared with a register that doesn't
  831. have an 8 bit component (such as EDI). In that case the 8 bit component is
  832. still set to R_NO and the comparison in the Else-part will fail}
  833. If (Reg32(OldReg) in OldRegsEncountered) Then
  834. If (Reg32(NewReg) in NewRegsEncountered) Then
  835. RegsEquivalent := (OldReg = New2OldReg[NewReg])
  836. { If we haven't encountered the new register yet, but we have encountered the
  837. old one already, the new one can only be correct if it's being written to
  838. (and consequently the old one is also being written to), otherwise
  839. movl -8(%ebp), %eax and movl -8(%ebp), %eax
  840. movl (%eax), %eax movl (%edx), %edx
  841. are considered equivalent}
  842. Else
  843. If (OpAct = OpAct_Write) Then
  844. Begin
  845. AddReg2RegInfo(OldReg, NewReg, RegInfo);
  846. RegsEquivalent := True
  847. End
  848. Else Regsequivalent := False
  849. Else
  850. If Not(Reg32(NewReg) in NewRegsEncountered) Then
  851. Begin
  852. AddReg2RegInfo(OldReg, NewReg, RegInfo);
  853. RegsEquivalent := True
  854. End
  855. Else RegsEquivalent := False
  856. Else RegsEquivalent := False
  857. Else RegsEquivalent := OldReg = NewReg
  858. End;
  859. Function RefsEquivalent(Const R1, R2: TReference; var RegInfo: TRegInfo; OpAct: TOpAction): Boolean;
  860. Begin
  861. If R1.is_immediate Then
  862. RefsEquivalent := R2.is_immediate and (R1.Offset = R2.Offset)
  863. Else
  864. RefsEquivalent := (R1.Offset+R1.OffsetFixup = R2.Offset+R2.OffsetFixup) And
  865. RegsEquivalent(R1.Base, R2.Base, RegInfo, OpAct) And
  866. RegsEquivalent(R1.Index, R2.Index, RegInfo, OpAct) And
  867. (R1.Segment = R2.Segment) And (R1.ScaleFactor = R2.ScaleFactor) And
  868. (R1.Symbol = R2.Symbol);
  869. End;
  870. Function RefsEqual(Const R1, R2: TReference): Boolean;
  871. Begin
  872. If R1.is_immediate Then
  873. RefsEqual := R2.is_immediate and (R1.Offset = R2.Offset)
  874. Else
  875. RefsEqual := (R1.Offset+R1.OffsetFixup = R2.Offset+R2.OffsetFixup) And
  876. (R1.Segment = R2.Segment) And (R1.Base = R2.Base) And
  877. (R1.Index = R2.Index) And (R1.ScaleFactor = R2.ScaleFactor) And
  878. (R1.Symbol=R2.Symbol);
  879. End;
  880. Function IsGP32Reg(Reg: TRegister): Boolean;
  881. {Checks if the register is a 32 bit general purpose register}
  882. Begin
  883. If (Reg >= R_EAX) and (Reg <= R_EBX)
  884. Then IsGP32Reg := True
  885. Else IsGP32reg := False
  886. End;
  887. Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
  888. Begin {checks whether Ref contains a reference to Reg}
  889. Reg := Reg32(Reg);
  890. RegInRef := (Ref.Base = Reg) Or (Ref.Index = Reg)
  891. End;
  892. Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
  893. {checks if Reg is used by the instruction p1}
  894. Var Counter: Longint;
  895. TmpResult: Boolean;
  896. Begin
  897. TmpResult := False;
  898. If (Pai(p1)^.typ = ait_instruction) Then
  899. Begin
  900. Reg := Reg32(Reg);
  901. Counter := 0;
  902. Repeat
  903. Case Pai386(p1)^.oper[Counter].typ Of
  904. Top_Reg: TmpResult := Reg = Reg32(Pai386(p1)^.oper[Counter].reg);
  905. Top_Ref: TmpResult := RegInRef(Reg, Pai386(p1)^.oper[Counter].ref^);
  906. End;
  907. Inc(Counter)
  908. Until (Counter = 3) or TmpResult;
  909. End;
  910. RegInInstruction := TmpResult
  911. End;
  912. {Function RegInOp(Reg: TRegister; const o:toper): Boolean;
  913. Begin
  914. RegInOp := False;
  915. Case opt Of
  916. top_reg: RegInOp := Reg = o.reg;
  917. top_ref: RegInOp := (Reg = o.ref^.Base) Or
  918. (Reg = o.ref^.Index);
  919. End;
  920. End;}
  921. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  922. {returns true if Reg is modified by the instruction p1. P1 is assumed to be
  923. of the type ait_instruction}
  924. Var hp: Pai;
  925. Begin
  926. If GetLastInstruction(p1, hp)
  927. Then
  928. RegModifiedByInstruction :=
  929. PPAiProp(p1^.OptInfo)^.Regs[Reg].WState <>
  930. PPAiProp(hp^.OptInfo)^.Regs[Reg].WState
  931. Else RegModifiedByInstruction := True;
  932. End;
  933. {********************* GetNext and GetLastInstruction *********************}
  934. Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
  935. {skips ait_regalloc, ait_regdealloc and ait_stab* objects and puts the
  936. next pai object in Next. Returns false if there isn't any}
  937. Begin
  938. Repeat
  939. Current := Pai(Current^.Next);
  940. While Assigned(Current) And
  941. ((Current^.typ In SkipInstr) or
  942. ((Current^.typ = ait_label) And
  943. Not(Pai_Label(Current)^.l^.is_used))) Do
  944. Current := Pai(Current^.Next);
  945. If Assigned(Current) And
  946. (Current^.typ = ait_Marker) And
  947. (Pai_Marker(Current)^.Kind = NoPropInfoStart) Then
  948. Begin
  949. While Assigned(Current) And
  950. ((Current^.typ <> ait_Marker) Or
  951. (Pai_Marker(Current)^.Kind <> NoPropInfoEnd)) Do
  952. Current := Pai(Current^.Next);
  953. End;
  954. Until Not(Assigned(Current)) Or
  955. (Current^.typ <> ait_Marker) Or
  956. (Pai_Marker(Current)^.Kind <> NoPropInfoEnd);
  957. Next := Current;
  958. If Assigned(Current) And
  959. Not((Current^.typ In SkipInstr) or
  960. ((Current^.typ = ait_label) And
  961. Not(Pai_Label(Current)^.l^.is_used)))
  962. Then GetNextInstruction := True
  963. Else
  964. Begin
  965. Next := Nil;
  966. GetNextInstruction := False;
  967. End;
  968. End;
  969. Function GetLastInstruction(Current: Pai; Var Last: Pai): Boolean;
  970. {skips the ait-types in SkipInstr puts the previous pai object in
  971. Last. Returns false if there isn't any}
  972. Begin
  973. Repeat
  974. Current := Pai(Current^.previous);
  975. While Assigned(Current) And
  976. (((Current^.typ = ait_Marker) And
  977. Not(Pai_Marker(Current)^.Kind in [AsmBlockEnd,NoPropInfoEnd])) or
  978. (Current^.typ In SkipInstr) or
  979. ((Current^.typ = ait_label) And
  980. Not(Pai_Label(Current)^.l^.is_used))) Do
  981. Current := Pai(Current^.previous);
  982. If Assigned(Current) And
  983. (Current^.typ = ait_Marker) And
  984. (Pai_Marker(Current)^.Kind = NoPropInfoEnd) Then
  985. Begin
  986. While Assigned(Current) And
  987. ((Current^.typ <> ait_Marker) Or
  988. (Pai_Marker(Current)^.Kind <> NoPropInfoStart)) Do
  989. Current := Pai(Current^.previous);
  990. End;
  991. Until Not(Assigned(Current)) Or
  992. (Current^.typ <> ait_Marker) Or
  993. (Pai_Marker(Current)^.Kind <> NoPropInfoStart);
  994. If Not(Assigned(Current)) or
  995. (Current^.typ In SkipInstr) or
  996. ((Current^.typ = ait_label) And
  997. Not(Pai_Label(Current)^.l^.is_used)) or
  998. ((Current^.typ = ait_Marker) And
  999. (Pai_Marker(Current)^.Kind = AsmBlockEnd))
  1000. Then
  1001. Begin
  1002. Last := Nil;
  1003. GetLastInstruction := False
  1004. End
  1005. Else
  1006. Begin
  1007. Last := Current;
  1008. GetLastInstruction := True;
  1009. End;
  1010. End;
  1011. Procedure SkipHead(var P: Pai);
  1012. Var OldP: Pai;
  1013. Begin
  1014. Repeat
  1015. OldP := P;
  1016. If (P^.typ in SkipInstr) Or
  1017. ((P^.typ = ait_marker) And
  1018. (Pai_Marker(P)^.Kind = AsmBlockEnd)) Then
  1019. GetNextInstruction(P, P)
  1020. Else If ((P^.Typ = Ait_Marker) And
  1021. (Pai_Marker(P)^.Kind = NoPropInfoStart)) Then
  1022. {a marker of the NoPropInfoStart can't be the first instruction of a
  1023. paasmoutput list}
  1024. GetNextInstruction(Pai(P^.Previous),P);
  1025. If (P^.Typ = Ait_Marker) And
  1026. (Pai_Marker(P)^.Kind = AsmBlockStart) Then
  1027. Begin
  1028. P := Pai(P^.Next);
  1029. While (P^.typ <> Ait_Marker) Or
  1030. (Pai_Marker(P)^.Kind <> AsmBlockEnd) Do
  1031. P := Pai(P^.Next)
  1032. End;
  1033. Until P = OldP
  1034. End;
  1035. {******************* The Data Flow Analyzer functions ********************}
  1036. Procedure UpdateUsedRegs(Var UsedRegs: TRegSet; p: Pai);
  1037. {updates UsedRegs with the RegAlloc Information coming after P}
  1038. Begin
  1039. Repeat
  1040. While Assigned(p) And
  1041. ((p^.typ in (SkipInstr - [ait_RegAlloc])) or
  1042. ((p^.typ = ait_label) And
  1043. Not(Pai_Label(p)^.l^.is_used))) Do
  1044. p := Pai(p^.next);
  1045. While Assigned(p) And
  1046. (p^.typ=ait_RegAlloc) Do
  1047. Begin
  1048. if pairegalloc(p)^.allocation then
  1049. UsedRegs := UsedRegs + [PaiRegAlloc(p)^.Reg]
  1050. else
  1051. UsedRegs := UsedRegs - [PaiRegAlloc(p)^.Reg];
  1052. p := pai(p^.next);
  1053. End;
  1054. Until Not(Assigned(p)) Or
  1055. (Not(p^.typ in SkipInstr) And
  1056. Not((p^.typ = ait_label) And
  1057. Not(Pai_Label(p)^.l^.is_used)));
  1058. End;
  1059. (*Function FindZeroreg(p: Pai; Var Result: TRegister): Boolean;
  1060. {Finds a register which contains the constant zero}
  1061. Var Counter: TRegister;
  1062. Begin
  1063. Counter := R_EAX;
  1064. FindZeroReg := True;
  1065. While (Counter <= R_EDI) And
  1066. ((PPaiProp(p^.OptInfo)^.Regs[Counter].Typ <> Con_Const) or
  1067. (PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod <> Pointer(0))) Do
  1068. Inc(Byte(Counter));
  1069. If (PPaiProp(p^.OptInfo)^.Regs[Counter].Typ = Con_Const) And
  1070. (PPaiProp(p^.OptInfo)^.Regs[Counter].StartMod = Pointer(0))
  1071. Then Result := Counter
  1072. Else FindZeroReg := False;
  1073. End;*)
  1074. Function TCh2Reg(Ch: TChange): TRegister;
  1075. {converts a TChange variable to a TRegister}
  1076. Begin
  1077. If (Ch <= C_REDI) Then
  1078. TCh2Reg := TRegister(Byte(Ch))
  1079. Else
  1080. If (Ch <= C_WEDI) Then
  1081. TCh2Reg := TRegister(Byte(Ch) - Byte(C_REDI))
  1082. Else
  1083. If (Ch <= C_RWEDI) Then
  1084. TCh2Reg := TRegister(Byte(Ch) - Byte(C_WEDI))
  1085. Else
  1086. If (Ch <= C_MEDI) Then
  1087. TCh2Reg := TRegister(Byte(Ch) - Byte(C_RWEDI))
  1088. Else InternalError($db)
  1089. End;
  1090. Procedure IncState(Var S: Byte);
  1091. {Increases S by 1, wraps around at $ffff to 0 (so we won't get overflow
  1092. errors}
  1093. Begin
  1094. If (s <> $ff)
  1095. Then Inc(s)
  1096. Else s := 0
  1097. End;
  1098. Function RegInSequence(Reg: TRegister; Const Content: TContent): Boolean;
  1099. {checks the whole sequence of Content (so StartMod and and the next NrOfMods
  1100. Pai objects) to see whether Reg is used somewhere, without it being loaded
  1101. with something else first}
  1102. Var p: Pai;
  1103. Counter: Byte;
  1104. TmpResult: Boolean;
  1105. RegsChecked: TRegSet;
  1106. Begin
  1107. RegsChecked := [];
  1108. p := Content.StartMod;
  1109. TmpResult := False;
  1110. Counter := 1;
  1111. While Not(TmpResult) And
  1112. (Counter <= Content.NrOfMods) Do
  1113. Begin
  1114. If (p^.typ = ait_instruction) and
  1115. ((Pai386(p)^.opcode = A_MOV) or
  1116. (Pai386(p)^.opcode = A_MOVZX) or
  1117. (Pai386(p)^.opcode = A_MOVSX))
  1118. Then
  1119. Begin
  1120. If (Pai386(p)^.oper[0].typ = top_ref) Then
  1121. With Pai386(p)^.oper[0].ref^ Do
  1122. If (Base = ProcInfo.FramePointer) And
  1123. (Index = R_NO)
  1124. Then
  1125. Begin
  1126. RegsChecked := RegsChecked + [Reg32(Pai386(p)^.oper[1].reg)];
  1127. If Reg = Reg32(Pai386(p)^.oper[1].reg) Then
  1128. Break;
  1129. End
  1130. Else
  1131. Begin
  1132. If (Base = Reg) And
  1133. Not(Base In RegsChecked)
  1134. Then TmpResult := True;
  1135. If Not(TmpResult) And
  1136. (Index = Reg) And
  1137. Not(Index In RegsChecked)
  1138. Then TmpResult := True;
  1139. End
  1140. End
  1141. Else TmpResult := RegInInstruction(Reg, p);
  1142. Inc(Counter);
  1143. GetNextInstruction(p,p)
  1144. End;
  1145. RegInSequence := TmpResult
  1146. End;
  1147. Procedure DestroyReg(p1: PPaiProp; Reg: TRegister);
  1148. {Destroys the contents of the register Reg in the PPaiProp p1, as well as the
  1149. contents of registers are loaded with a memory location based on Reg}
  1150. Var TmpWState, TmpRState: Byte;
  1151. Counter: TRegister;
  1152. Begin
  1153. Reg := Reg32(Reg);
  1154. NrOfInstrSinceLastMod[Reg] := 0;
  1155. If (Reg >= R_EAX) And (Reg <= R_EDI)
  1156. Then
  1157. Begin
  1158. With p1^.Regs[Reg] Do
  1159. Begin
  1160. IncState(WState);
  1161. TmpWState := WState;
  1162. TmpRState := RState;
  1163. FillChar(p1^.Regs[Reg], SizeOf(TContent), 0);
  1164. WState := TmpWState;
  1165. RState := TmpRState;
  1166. End;
  1167. For Counter := R_EAX to R_EDI Do
  1168. With p1^.Regs[Counter] Do
  1169. If (Typ = Con_Ref) And
  1170. RegInSequence(Reg, p1^.Regs[Counter])
  1171. Then
  1172. Begin
  1173. IncState(WState);
  1174. TmpWState := WState;
  1175. TmpRState := RState;
  1176. FillChar(p1^.Regs[Counter], SizeOf(TContent), 0);
  1177. WState := TmpWState;
  1178. RState := TmpRState;
  1179. End;
  1180. End;
  1181. End;
  1182. {Procedure AddRegsToSet(p: Pai; Var RegSet: TRegSet);
  1183. Begin
  1184. If (p^.typ = ait_instruction) Then
  1185. Begin
  1186. Case Pai386(p)^.oper[0].typ Of
  1187. top_reg:
  1188. If Not(Pai386(p)^.oper[0].reg in [R_NO,R_ESP,ProcInfo.FramePointer]) Then
  1189. RegSet := RegSet + [Pai386(p)^.oper[0].reg];
  1190. top_ref:
  1191. With TReference(Pai386(p)^.oper[0]^) Do
  1192. Begin
  1193. If Not(Base in [ProcInfo.FramePointer,R_NO,R_ESP])
  1194. Then RegSet := RegSet + [Base];
  1195. If Not(Index in [ProcInfo.FramePointer,R_NO,R_ESP])
  1196. Then RegSet := RegSet + [Index];
  1197. End;
  1198. End;
  1199. Case Pai386(p)^.oper[1].typ Of
  1200. top_reg:
  1201. If Not(Pai386(p)^.oper[1].reg in [R_NO,R_ESP,ProcInfo.FramePointer]) Then
  1202. If RegSet := RegSet + [TRegister(TwoWords(Pai386(p)^.oper[1]).Word1];
  1203. top_ref:
  1204. With TReference(Pai386(p)^.oper[1]^) Do
  1205. Begin
  1206. If Not(Base in [ProcInfo.FramePointer,R_NO,R_ESP])
  1207. Then RegSet := RegSet + [Base];
  1208. If Not(Index in [ProcInfo.FramePointer,R_NO,R_ESP])
  1209. Then RegSet := RegSet + [Index];
  1210. End;
  1211. End;
  1212. End;
  1213. End;}
  1214. Function OpsEquivalent(const o1, o2: toper; Var RegInfo: TRegInfo; OpAct: TopAction): Boolean;
  1215. Begin {checks whether the two ops are equivalent}
  1216. OpsEquivalent := False;
  1217. if o1.typ=o2.typ then
  1218. Case o1.typ Of
  1219. Top_Reg:
  1220. OpsEquivalent :=RegsEquivalent(o1.reg,o2.reg, RegInfo, OpAct);
  1221. Top_Ref:
  1222. OpsEquivalent := RefsEquivalent(o1.ref^, o2.ref^, RegInfo, OpAct);
  1223. Top_Const:
  1224. OpsEquivalent := o1.val = o2.val;
  1225. Top_None:
  1226. OpsEquivalent := True
  1227. End;
  1228. End;
  1229. Function OpsEqual(const o1,o2:toper): Boolean;
  1230. Begin {checks whether the two ops are equal}
  1231. OpsEqual := False;
  1232. if o1.typ=o2.typ then
  1233. Case o1.typ Of
  1234. Top_Reg :
  1235. OpsEqual:=o1.reg=o2.reg;
  1236. Top_Ref :
  1237. OpsEqual := RefsEqual(o1.ref^, o2.ref^);
  1238. Top_Const :
  1239. OpsEqual:=o1.val=o2.val;
  1240. Top_Symbol :
  1241. OpsEqual:=(o1.sym=o2.sym) and (o1.symofs=o2.symofs);
  1242. Top_None :
  1243. OpsEqual := True
  1244. End;
  1245. End;
  1246. Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
  1247. {$ifdef csdebug}
  1248. var hp: pai;
  1249. {$endif csdebug}
  1250. Begin {checks whether two Pai386 instructions are equal}
  1251. If Assigned(p1) And Assigned(p2) And
  1252. (Pai(p1)^.typ = ait_instruction) And
  1253. (Pai(p1)^.typ = ait_instruction) And
  1254. (Pai386(p1)^.opcode = Pai386(p2)^.opcode) And
  1255. (Pai386(p1)^.oper[0].typ = Pai386(p2)^.oper[0].typ) And
  1256. (Pai386(p1)^.oper[1].typ = Pai386(p2)^.oper[1].typ) And
  1257. (Pai386(p1)^.oper[2].typ = Pai386(p2)^.oper[2].typ)
  1258. Then
  1259. {both instructions have the same structure:
  1260. "<operator> <operand of type1>, <operand of type 2>"}
  1261. If ((Pai386(p1)^.opcode = A_MOV) or
  1262. (Pai386(p1)^.opcode = A_MOVZX) or
  1263. (Pai386(p1)^.opcode = A_MOVSX)) And
  1264. (Pai386(p1)^.oper[0].typ = top_ref) {then .oper[1]t = top_reg} Then
  1265. If Not(RegInRef(Pai386(p1)^.oper[1].reg, Pai386(p1)^.oper[0].ref^)) Then
  1266. {the "old" instruction is a load of a register with a new value, not with
  1267. a value based on the contents of this register (so no "mov (reg), reg")}
  1268. If Not(RegInRef(Pai386(p2)^.oper[1].reg, Pai386(p2)^.oper[0].ref^)) And
  1269. RefsEqual(Pai386(p1)^.oper[0].ref^, Pai386(p2)^.oper[0].ref^)
  1270. Then
  1271. {the "new" instruction is also a load of a register with a new value, and
  1272. this value is fetched from the same memory location}
  1273. Begin
  1274. With Pai386(p2)^.oper[0].ref^ Do
  1275. Begin
  1276. If Not(Base in [ProcInfo.FramePointer, R_NO, R_ESP])
  1277. {it won't do any harm if the register is already in RegsLoadedForRef}
  1278. Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
  1279. If Not(Index in [ProcInfo.FramePointer, R_NO, R_ESP])
  1280. Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
  1281. End;
  1282. {add the registers from the reference (.oper[0]) to the RegInfo, all registers
  1283. from the reference are the same in the old and in the new instruction
  1284. sequence}
  1285. AddOp2RegInfo(Pai386(p1)^.oper[0], RegInfo);
  1286. {the registers from .oper[1] have to be equivalent, but not necessarily equal}
  1287. InstructionsEquivalent :=
  1288. RegsEquivalent(Pai386(p1)^.oper[1].reg, Pai386(p2)^.oper[1].reg, RegInfo, OpAct_Write);
  1289. End
  1290. {the registers are loaded with values from different memory locations. If
  1291. this was allowed, the instructions "mov -4(esi),eax" and "mov -4(ebp),eax"
  1292. would be considered equivalent}
  1293. Else InstructionsEquivalent := False
  1294. Else
  1295. {load register with a value based on the current value of this register}
  1296. Begin
  1297. With Pai386(p2)^.oper[0].ref^ Do
  1298. Begin
  1299. If Not(Base in [ProcInfo.FramePointer,
  1300. Reg32(Pai386(p2)^.oper[1].reg),R_NO,R_ESP])
  1301. {it won't do any harm if the register is already in RegsLoadedForRef}
  1302. Then
  1303. Begin
  1304. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
  1305. {$ifdef csdebug}
  1306. Writeln(att_reg2str[base], ' added');
  1307. {$endif csdebug}
  1308. end;
  1309. If Not(Index in [ProcInfo.FramePointer,
  1310. Reg32(Pai386(p2)^.oper[1].reg),R_NO,R_ESP])
  1311. Then
  1312. Begin
  1313. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
  1314. {$ifdef csdebug}
  1315. Writeln(att_reg2str[index], ' added');
  1316. {$endif csdebug}
  1317. end;
  1318. End;
  1319. If Not(Reg32(Pai386(p2)^.oper[1].reg) In [ProcInfo.FramePointer,R_NO,R_ESP])
  1320. Then
  1321. Begin
  1322. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef -
  1323. [Reg32(Pai386(p2)^.oper[1].reg)];
  1324. {$ifdef csdebug}
  1325. Writeln(att_reg2str[Reg32(Pai386(p2)^.oper[1].reg)], ' removed');
  1326. {$endif csdebug}
  1327. end;
  1328. InstructionsEquivalent :=
  1329. OpsEquivalent(Pai386(p1)^.oper[0], Pai386(p2)^.oper[0], RegInfo, OpAct_Read) And
  1330. OpsEquivalent(Pai386(p1)^.oper[1], Pai386(p2)^.oper[1], RegInfo, OpAct_Write)
  1331. End
  1332. Else
  1333. {an instruction <> mov, movzx, movsx}
  1334. begin
  1335. {$ifdef csdebug}
  1336. hp := new(pai_asm_comment,init(strpnew('checking if equivalent')));
  1337. hp^.previous := p2;
  1338. hp^.next := p2^.next;
  1339. p2^.next^.previous := hp;
  1340. p2^.next := hp;
  1341. {$endif csdebug}
  1342. InstructionsEquivalent :=
  1343. OpsEquivalent(Pai386(p1)^.oper[0], Pai386(p2)^.oper[0], RegInfo, OpAct_Unknown) And
  1344. OpsEquivalent(Pai386(p1)^.oper[1], Pai386(p2)^.oper[1], RegInfo, OpAct_Unknown) And
  1345. OpsEquivalent(Pai386(p1)^.oper[2], Pai386(p2)^.oper[2], RegInfo, OpAct_Unknown)
  1346. end
  1347. {the instructions haven't even got the same structure, so they're certainly
  1348. not equivalent}
  1349. Else
  1350. begin
  1351. {$ifdef csdebug}
  1352. hp := new(pai_asm_comment,init(strpnew('different opcodes/format')));
  1353. hp^.previous := p2;
  1354. hp^.next := p2^.next;
  1355. p2^.next^.previous := hp;
  1356. p2^.next := hp;
  1357. {$endif csdebug}
  1358. InstructionsEquivalent := False;
  1359. end;
  1360. {$ifdef csdebug}
  1361. hp := new(pai_asm_comment,init(strpnew('instreq: '+tostr(byte(instructionsequivalent)))));
  1362. hp^.previous := p2;
  1363. hp^.next := p2^.next;
  1364. p2^.next^.previous := hp;
  1365. p2^.next := hp;
  1366. {$endif csdebug}
  1367. End;
  1368. (*
  1369. Function InstructionsEqual(p1, p2: Pai): Boolean;
  1370. Begin {checks whether two Pai386 instructions are equal}
  1371. InstructionsEqual :=
  1372. Assigned(p1) And Assigned(p2) And
  1373. ((Pai(p1)^.typ = ait_instruction) And
  1374. (Pai(p1)^.typ = ait_instruction) And
  1375. (Pai386(p1)^.opcode = Pai386(p2)^.opcode) And
  1376. (Pai386(p1)^.oper[0].typ = Pai386(p2)^.oper[0].typ) And
  1377. (Pai386(p1)^.oper[1].typ = Pai386(p2)^.oper[1].typ) And
  1378. OpsEqual(Pai386(p1)^.oper[0].typ, Pai386(p1)^.oper[0], Pai386(p2)^.oper[0]) And
  1379. OpsEqual(Pai386(p1)^.oper[1].typ, Pai386(p1)^.oper[1], Pai386(p2)^.oper[1]))
  1380. End;
  1381. *)
  1382. Function RefInInstruction(Const Ref: TReference; p: Pai): Boolean;
  1383. {checks whehter Ref is used in P}
  1384. Var TmpResult: Boolean;
  1385. Begin
  1386. TmpResult := False;
  1387. If (p^.typ = ait_instruction) Then
  1388. Begin
  1389. If (Pai386(p)^.oper[0].typ = Top_Ref) Then
  1390. TmpResult := RefsEqual(Ref, Pai386(p)^.oper[0].ref^);
  1391. If Not(TmpResult) And (Pai386(p)^.oper[1].typ = Top_Ref) Then
  1392. TmpResult := RefsEqual(Ref, Pai386(p)^.oper[1].ref^);
  1393. End;
  1394. RefInInstruction := TmpResult;
  1395. End;
  1396. Function RefInSequence(Const Ref: TReference; Content: TContent): Boolean;
  1397. {checks the whole sequence of Content (so StartMod and and the next NrOfMods
  1398. Pai objects) to see whether Ref is used somewhere}
  1399. Var p: Pai;
  1400. Counter: Byte;
  1401. TmpResult: Boolean;
  1402. Begin
  1403. p := Content.StartMod;
  1404. TmpResult := False;
  1405. Counter := 1;
  1406. While Not(TmpResult) And
  1407. (Counter <= Content.NrOfMods) Do
  1408. Begin
  1409. If (p^.typ = ait_instruction) And
  1410. RefInInstruction(Ref, p)
  1411. Then TmpResult := True;
  1412. Inc(Counter);
  1413. GetNextInstruction(p,p)
  1414. End;
  1415. RefInSequence := TmpResult
  1416. End;
  1417. Procedure DestroyRefs(p: pai; Const Ref: TReference; WhichReg: TRegister);
  1418. {destroys all registers which possibly contain a reference to Ref, WhichReg
  1419. is the register whose contents are being written to memory (if this proc
  1420. is called because of a "mov?? %reg, (mem)" instruction)}
  1421. Var Counter: TRegister;
  1422. Begin
  1423. WhichReg := Reg32(WhichReg);
  1424. If ((Ref.base = ProcInfo.FramePointer) And
  1425. (Ref.Index = R_NO)) Or
  1426. Assigned(Ref.Symbol)
  1427. Then
  1428. {write something to a parameter, a local or global variable, so
  1429. * with uncertzain optimizations on:
  1430. - destroy the contents of registers whose contents have somewhere a
  1431. "mov?? (Ref), %reg". WhichReg (this is the register whose contents
  1432. are being written to memory) is not destroyed if it's StartMod is
  1433. of that form and NrOfMods = 1 (so if it holds ref, but is not a
  1434. pointer based on Ref)
  1435. * with uncertain optimizations off:
  1436. - also destroy registers that contain any pointer}
  1437. For Counter := R_EAX to R_EDI Do
  1438. With PPaiProp(p^.OptInfo)^.Regs[Counter] Do
  1439. Begin
  1440. If (typ = Con_Ref) And
  1441. (Not(cs_UncertainOpts in aktglobalswitches) And
  1442. (NrOfMods <> 1)
  1443. ) Or
  1444. (RefInSequence(Ref,PPaiProp(p^.OptInfo)^.Regs[Counter]) And
  1445. ((Counter <> WhichReg) Or
  1446. ((NrOfMods = 1) And
  1447. {StarMod is always of the type ait_instruction}
  1448. (Pai386(StartMod)^.oper[0].typ = top_ref) And
  1449. RefsEqual(Pai386(StartMod)^.oper[0].ref^, Ref)
  1450. )
  1451. )
  1452. )
  1453. Then DestroyReg(PPaiProp(p^.OptInfo), Counter)
  1454. End
  1455. Else
  1456. {write something to a pointer location, so
  1457. * with uncertain optimzations on:
  1458. - do not destroy registers which contain a local/global variable or a
  1459. parameter, except if DestroyRefs is called because of a "movsl"
  1460. * with uncertain optimzations off:
  1461. - destroy every register which contains a memory location
  1462. }
  1463. For Counter := R_EAX to R_EDI Do
  1464. With PPaiProp(p^.OptInfo)^.Regs[Counter] Do
  1465. If (typ = Con_Ref) And
  1466. (Not(cs_UncertainOpts in aktglobalswitches) Or
  1467. {for movsl}
  1468. (Ref.Base = R_EDI) Or
  1469. {don't destroy if reg contains a parameter, local or global variable}
  1470. Not((NrOfMods = 1) And
  1471. (Pai386(StartMod)^.oper[0].typ = top_ref) And
  1472. ((Pai386(StartMod)^.oper[0].ref^.base = ProcInfo.FramePointer) Or
  1473. Assigned(Pai386(StartMod)^.oper[0].ref^.Symbol)
  1474. )
  1475. )
  1476. )
  1477. Then DestroyReg(PPaiProp(p^.OptInfo), Counter)
  1478. End;
  1479. Procedure DestroyAllRegs(p: PPaiProp);
  1480. Var Counter: TRegister;
  1481. Begin {initializes/desrtoys all registers}
  1482. For Counter := R_EAX To R_EDI Do
  1483. DestroyReg(p, Counter);
  1484. p^.DirFlag := F_Unknown;
  1485. End;
  1486. Procedure DestroyOp(PaiObj: Pai; const o:Toper);
  1487. Begin
  1488. Case o.typ Of
  1489. top_reg: DestroyReg(PPaiProp(PaiObj^.OptInfo), o.reg);
  1490. top_ref: DestroyRefs(PaiObj, o.ref^, R_NO);
  1491. top_symbol:;
  1492. End;
  1493. End;
  1494. Procedure ReadReg(p: PPaiProp; Reg: TRegister);
  1495. Begin
  1496. Reg := Reg32(Reg);
  1497. If Reg in [R_EAX..R_EDI] Then
  1498. IncState(p^.Regs[Reg32(Reg)].RState)
  1499. End;
  1500. Procedure ReadRef(p: PPaiProp; Ref: PReference);
  1501. Begin
  1502. If Ref^.Base <> R_NO Then
  1503. ReadReg(p, Ref^.Base);
  1504. If Ref^.Index <> R_NO Then
  1505. ReadReg(p, Ref^.Index);
  1506. End;
  1507. Procedure ReadOp(P: PPaiProp;const o:toper);
  1508. Begin
  1509. Case o.typ Of
  1510. top_reg: ReadReg(P, o.reg);
  1511. top_ref: ReadRef(P, o.ref);
  1512. top_symbol : ;
  1513. End;
  1514. End;
  1515. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  1516. {gathers the RegAlloc data... still need to think about where to store it to
  1517. avoid global vars}
  1518. Var BlockEnd: Pai;
  1519. Begin
  1520. BlockEnd := FindLoHiLabels(LoLab, HiLab, LabDif, BlockStart);
  1521. BuildLabelTableAndFixRegAlloc(AsmL, LTable, LoLab, LabDif, BlockStart, BlockEnd);
  1522. DFAPass1 := BlockEnd;
  1523. End;
  1524. {$ifdef arithopt}
  1525. Procedure AddInstr2RegContents({$ifdef statedebug} asml: paasmoutput; {$endif}
  1526. p: pai386; reg: TRegister);
  1527. {$ifdef statedebug}
  1528. var hp: pai;
  1529. {$endif statedebug}
  1530. Begin
  1531. With PPaiProp(p^.optinfo)^.Regs[reg] Do
  1532. If (Typ = Con_Ref)
  1533. Then
  1534. Begin
  1535. IncState(WState);
  1536. {also store how many instructions are part of the sequence in the first
  1537. instructions PPaiProp, so it can be easily accessed from within
  1538. CheckSequence}
  1539. Inc(NrOfMods, NrOfInstrSinceLastMod[Reg]);
  1540. PPaiProp(Pai(StartMod)^.OptInfo)^.Regs[Reg].NrOfMods := NrOfMods;
  1541. NrOfInstrSinceLastMod[Reg] := 0;
  1542. {$ifdef StateDebug}
  1543. hp := new(pai_asm_comment,init(strpnew(att_reg2str[reg]+': '+tostr(PPaiProp(p^.optinfo)^.Regs[reg].WState)
  1544. + ' -- ' + tostr(PPaiProp(p^.optinfo)^.Regs[reg].nrofmods))));
  1545. InsertLLItem(AsmL, p, p^.next, hp);
  1546. {$endif StateDebug}
  1547. End
  1548. Else
  1549. Begin
  1550. DestroyReg(PPaiProp(p^.optinfo), Reg);
  1551. {$ifdef StateDebug}
  1552. hp := new(pai_asm_comment,init(strpnew(att_reg2str[reg]+': '+tostr(PPaiProp(p^.optinfo)^.Regs[reg].WState))));
  1553. InsertLLItem(AsmL, p, p^.next, hp);
  1554. {$endif StateDebug}
  1555. End
  1556. End;
  1557. Procedure AddInstr2OpContents({$ifdef statedebug} asml: paasmoutput; {$endif}
  1558. p: pai386; const oper: TOper);
  1559. Begin
  1560. If oper.typ = top_reg Then
  1561. AddInstr2RegContents({$ifdef statedebug} asml, {$endif}p, oper.reg)
  1562. Else
  1563. Begin
  1564. ReadOp(PPaiProp(p^.optinfo), oper);
  1565. DestroyOp(p, oper);
  1566. End
  1567. End;
  1568. {$endif arithopt}
  1569. Procedure DoDFAPass2(
  1570. {$Ifdef StateDebug}
  1571. AsmL: PAasmOutput;
  1572. {$endif statedebug}
  1573. BlockStart, BlockEnd: Pai);
  1574. {Analyzes the Data Flow of an assembler list. Starts creating the reg
  1575. contents for the instructions starting with p. Returns the last pai which has
  1576. been processed}
  1577. Var
  1578. CurProp: PPaiProp;
  1579. {$ifdef AnalyzeLoops}
  1580. TmpState: Byte;
  1581. {$endif AnalyzeLoops}
  1582. Cnt, InstrCnt : Longint;
  1583. InstrProp: TAsmInstrucProp;
  1584. UsedRegs: TRegSet;
  1585. p, hp : Pai;
  1586. TmpRef: TReference;
  1587. TmpReg: TRegister;
  1588. Begin
  1589. p := BlockStart;
  1590. UsedRegs := [];
  1591. UpdateUsedregs(UsedRegs, p);
  1592. SkipHead(P);
  1593. BlockStart := p;
  1594. InstrCnt := 1;
  1595. FillChar(NrOfInstrSinceLastMod, SizeOf(NrOfInstrSinceLastMod), 0);
  1596. While (P <> BlockEnd) Do
  1597. Begin
  1598. {$IfDef TP}
  1599. New(CurProp);
  1600. {$Else TP}
  1601. CurProp := @PaiPropBlock^[InstrCnt];
  1602. {$EndIf TP}
  1603. If (p <> BlockStart)
  1604. Then
  1605. Begin
  1606. {$ifdef JumpAnal}
  1607. If (p^.Typ <> ait_label) Then
  1608. {$endif JumpAnal}
  1609. Begin
  1610. GetLastInstruction(p, hp);
  1611. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1612. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1613. End
  1614. End
  1615. Else
  1616. Begin
  1617. FillChar(CurProp^, SizeOf(CurProp^), 0);
  1618. { For TmpReg := R_EAX to R_EDI Do
  1619. CurProp^.Regs[TmpReg].WState := 1;}
  1620. End;
  1621. CurProp^.UsedRegs := UsedRegs;
  1622. CurProp^.CanBeRemoved := False;
  1623. UpdateUsedRegs(UsedRegs, Pai(p^.Next));
  1624. {$ifdef TP}
  1625. PPaiProp(p^.OptInfo) := CurProp;
  1626. {$Endif TP}
  1627. For TmpReg := R_EAX To R_EDI Do
  1628. Inc(NrOfInstrSinceLastMod[TmpReg]);
  1629. Case p^.typ Of
  1630. ait_label:
  1631. {$Ifndef JumpAnal}
  1632. If (Pai_label(p)^.l^.is_used) Then
  1633. DestroyAllRegs(CurProp);
  1634. {$Else JumpAnal}
  1635. Begin
  1636. If (Pai_Label(p)^.is_used) Then
  1637. With LTable^[Pai_Label(p)^.l^.labelnr-LoLab] Do
  1638. {$IfDef AnalyzeLoops}
  1639. If (RefsFound = Pai_Label(p)^.l^.RefCount)
  1640. {$Else AnalyzeLoops}
  1641. If (JmpsProcessed = Pai_Label(p)^.l^.RefCount)
  1642. {$EndIf AnalyzeLoops}
  1643. Then
  1644. {all jumps to this label have been found}
  1645. {$IfDef AnalyzeLoops}
  1646. If (JmpsProcessed > 0)
  1647. Then
  1648. {$EndIf AnalyzeLoops}
  1649. {we've processed at least one jump to this label}
  1650. Begin
  1651. If (GetLastInstruction(p, hp) And
  1652. Not(((hp^.typ = ait_instruction)) And
  1653. (pai386_labeled(hp)^.is_jmp))
  1654. Then
  1655. {previous instruction not a JMP -> the contents of the registers after the
  1656. previous intruction has been executed have to be taken into account as well}
  1657. For TmpReg := R_EAX to R_EDI Do
  1658. Begin
  1659. If (CurProp^.Regs[TmpReg].WState <>
  1660. PPaiProp(hp^.OptInfo)^.Regs[TmpReg].WState)
  1661. Then DestroyReg(CurProp, TmpReg)
  1662. End
  1663. End
  1664. {$IfDef AnalyzeLoops}
  1665. Else
  1666. {a label from a backward jump (e.g. a loop), no jump to this label has
  1667. already been processed}
  1668. If GetLastInstruction(p, hp) And
  1669. Not(hp^.typ = ait_instruction) And
  1670. (pai386_labeled(hp)^.opcode = A_JMP))
  1671. Then
  1672. {previous instruction not a jmp, so keep all the registers' contents from the
  1673. previous instruction}
  1674. Begin
  1675. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1676. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1677. End
  1678. Else
  1679. {previous instruction a jmp and no jump to this label processed yet}
  1680. Begin
  1681. hp := p;
  1682. Cnt := InstrCnt;
  1683. {continue until we find a jump to the label or a label which has already
  1684. been processed}
  1685. While GetNextInstruction(hp, hp) And
  1686. Not((hp^.typ = ait_instruction) And
  1687. (pai386(hp)^.is_jmp) and
  1688. (pasmlabel(pai386(hp)^.oper[0].sym)^.labelnr = Pai_Label(p)^.l^.labelnr)) And
  1689. Not((hp^.typ = ait_label) And
  1690. (LTable^[Pai_Label(hp)^.l^.labelnr-LoLab].RefsFound
  1691. = Pai_Label(hp)^.l^.RefCount) And
  1692. (LTable^[Pai_Label(hp)^.l^.labelnr-LoLab].JmpsProcessed > 0)) Do
  1693. Inc(Cnt);
  1694. If (hp^.typ = ait_label)
  1695. Then
  1696. {there's a processed label after the current one}
  1697. Begin
  1698. CurProp^.Regs := PaiPropBlock^[Cnt].Regs;
  1699. CurProp^.DirFlag := PaiPropBlock^[Cnt].DirFlag;
  1700. End
  1701. Else
  1702. {there's no label anymore after the current one, or they haven't been
  1703. processed yet}
  1704. Begin
  1705. GetLastInstruction(p, hp);
  1706. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1707. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1708. DestroyAllRegs(PPaiProp(hp^.OptInfo))
  1709. End
  1710. End
  1711. {$EndIf AnalyzeLoops}
  1712. Else
  1713. {not all references to this label have been found, so destroy all registers}
  1714. Begin
  1715. GetLastInstruction(p, hp);
  1716. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1717. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1718. DestroyAllRegs(CurProp)
  1719. End;
  1720. End;
  1721. {$EndIf JumpAnal}
  1722. {$ifdef GDB}
  1723. ait_stabs, ait_stabn, ait_stab_function_name:;
  1724. {$endif GDB}
  1725. ait_instruction:
  1726. Begin
  1727. if pai386(p)^.is_jmp then
  1728. begin
  1729. {$IfNDef JumpAnal}
  1730. ;
  1731. {$Else JumpAnal}
  1732. With LTable^[pasmlabel(pai386(p)^.oper[0].sym)^.labelnr-LoLab] Do
  1733. If (RefsFound = pasmlabel(pai386(p)^.oper[0].sym)^.RefCount) Then
  1734. Begin
  1735. If (InstrCnt < InstrNr)
  1736. Then
  1737. {forward jump}
  1738. If (JmpsProcessed = 0) Then
  1739. {no jump to this label has been processed yet}
  1740. Begin
  1741. PaiPropBlock^[InstrNr].Regs := CurProp^.Regs;
  1742. PaiPropBlock^[InstrNr].DirFlag := CurProp^.DirFlag;
  1743. Inc(JmpsProcessed);
  1744. End
  1745. Else
  1746. Begin
  1747. For TmpReg := R_EAX to R_EDI Do
  1748. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1749. CurProp^.Regs[TmpReg].WState) Then
  1750. DestroyReg(@PaiPropBlock^[InstrNr], TmpReg);
  1751. Inc(JmpsProcessed);
  1752. End
  1753. {$ifdef AnalyzeLoops}
  1754. Else
  1755. { backward jump, a loop for example}
  1756. { If (JmpsProcessed > 0) Or
  1757. Not(GetLastInstruction(PaiObj, hp) And
  1758. (hp^.typ = ait_labeled_instruction) And
  1759. (pai386_labeled(hp)^.opcode = A_JMP))
  1760. Then}
  1761. {instruction prior to label is not a jmp, or at least one jump to the label
  1762. has yet been processed}
  1763. Begin
  1764. Inc(JmpsProcessed);
  1765. For TmpReg := R_EAX to R_EDI Do
  1766. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1767. CurProp^.Regs[TmpReg].WState)
  1768. Then
  1769. Begin
  1770. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1771. Cnt := InstrNr;
  1772. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1773. Begin
  1774. DestroyReg(@PaiPropBlock^[Cnt], TmpReg);
  1775. Inc(Cnt);
  1776. End;
  1777. While (Cnt <= InstrCnt) Do
  1778. Begin
  1779. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1780. Inc(Cnt)
  1781. End
  1782. End;
  1783. End
  1784. { Else }
  1785. {instruction prior to label is a jmp and no jumps to the label have yet been
  1786. processed}
  1787. { Begin
  1788. Inc(JmpsProcessed);
  1789. For TmpReg := R_EAX to R_EDI Do
  1790. Begin
  1791. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1792. Cnt := InstrNr;
  1793. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1794. Begin
  1795. PaiPropBlock^[Cnt].Regs[TmpReg] := CurProp^.Regs[TmpReg];
  1796. Inc(Cnt);
  1797. End;
  1798. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1799. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1800. Begin
  1801. DestroyReg(@PaiPropBlock^[Cnt], TmpReg);
  1802. Inc(Cnt);
  1803. End;
  1804. While (Cnt <= InstrCnt) Do
  1805. Begin
  1806. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1807. Inc(Cnt)
  1808. End
  1809. End
  1810. End}
  1811. {$endif AnalyzeLoops}
  1812. End;
  1813. {$EndIf JumpAnal}
  1814. end
  1815. else
  1816. begin
  1817. InstrProp := AsmInstr[Pai386(p)^.opcode];
  1818. Case Pai386(p)^.opcode Of
  1819. A_MOV, A_MOVZX, A_MOVSX:
  1820. Begin
  1821. Case Pai386(p)^.oper[0].typ Of
  1822. Top_Reg:
  1823. Case Pai386(p)^.oper[1].typ Of
  1824. Top_Reg:
  1825. Begin
  1826. DestroyReg(CurProp, Pai386(p)^.oper[1].reg);
  1827. ReadReg(CurProp, Pai386(p)^.oper[0].reg);
  1828. { CurProp^.Regs[Pai386(p)^.oper[1].reg] :=
  1829. CurProp^.Regs[Pai386(p)^.oper[0].reg];
  1830. If (CurProp^.Regs[Pai386(p)^.oper[1].reg].ModReg = R_NO) Then
  1831. CurProp^.Regs[Pai386(p)^.oper[1].reg].ModReg :=
  1832. Pai386(p)^.oper[0].reg;}
  1833. End;
  1834. Top_Ref:
  1835. Begin
  1836. ReadReg(CurProp, Pai386(p)^.oper[0].reg);
  1837. ReadRef(CurProp, Pai386(p)^.oper[1].ref);
  1838. DestroyRefs(p, Pai386(p)^.oper[1].ref^, Pai386(p)^.oper[0].reg);
  1839. End;
  1840. End;
  1841. Top_Ref:
  1842. Begin {destination is always a register in this case}
  1843. ReadRef(CurProp, Pai386(p)^.oper[0].ref);
  1844. ReadReg(CurProp, Pai386(p)^.oper[1].reg);
  1845. TmpReg := Reg32(Pai386(p)^.oper[1].reg);
  1846. If RegInRef(TmpReg, Pai386(p)^.oper[0].ref^) And
  1847. (CurProp^.Regs[TmpReg].Typ = Con_Ref)
  1848. Then
  1849. Begin
  1850. With CurProp^.Regs[TmpReg] Do
  1851. Begin
  1852. IncState(WState);
  1853. {also store how many instructions are part of the sequence in the first
  1854. instructions PPaiProp, so it can be easily accessed from within
  1855. CheckSequence}
  1856. Inc(NrOfMods, NrOfInstrSinceLastMod[TmpReg]);
  1857. PPaiProp(Pai(StartMod)^.OptInfo)^.Regs[TmpReg].NrOfMods := NrOfMods;
  1858. NrOfInstrSinceLastMod[TmpReg] := 0;
  1859. End;
  1860. End
  1861. Else
  1862. Begin
  1863. DestroyReg(CurProp, TmpReg);
  1864. If Not(RegInRef(TmpReg, Pai386(p)^.oper[0].ref^)) Then
  1865. With CurProp^.Regs[TmpReg] Do
  1866. Begin
  1867. Typ := Con_Ref;
  1868. StartMod := p;
  1869. NrOfMods := 1;
  1870. End
  1871. End;
  1872. {$ifdef StateDebug}
  1873. hp := new(pai_asm_comment,init(strpnew(att_reg2str[TmpReg]+': '+tostr(CurProp^.Regs[TmpReg].WState))));
  1874. InsertLLItem(AsmL, p, p^.next, hp);
  1875. {$endif StateDebug}
  1876. End;
  1877. Top_Const:
  1878. Begin
  1879. Case Pai386(p)^.oper[1].typ Of
  1880. Top_Reg:
  1881. Begin
  1882. TmpReg := Reg32(Pai386(p)^.oper[1].reg);
  1883. With CurProp^.Regs[TmpReg] Do
  1884. Begin
  1885. DestroyReg(CurProp, TmpReg);
  1886. typ := Con_Const;
  1887. StartMod := p;
  1888. End
  1889. End;
  1890. Top_Ref:
  1891. Begin
  1892. ReadRef(CurProp, Pai386(p)^.oper[1].ref);
  1893. DestroyRefs(P, Pai386(p)^.oper[1].ref^, R_NO);
  1894. End;
  1895. End;
  1896. End;
  1897. End;
  1898. End;
  1899. A_IMUL:
  1900. Begin
  1901. ReadOp(CurProp, Pai386(p)^.oper[0]);
  1902. ReadOp(CurProp, Pai386(p)^.oper[1]);
  1903. If (Pai386(p)^.oper[2].typ = top_none) Then
  1904. If (Pai386(p)^.oper[1].typ = top_none) Then
  1905. Begin
  1906. DestroyReg(CurProp, R_EAX);
  1907. DestroyReg(CurProp, R_EDX)
  1908. End
  1909. Else
  1910. {$ifdef arithopt}
  1911. AddInstr2OpContents(Pai386(p), Pai386(p)^.oper[1])
  1912. {$else arithopt}
  1913. DestroyOp(p, Pai386(p)^.oper[1])
  1914. {$endif arithopt}
  1915. Else
  1916. {$ifdef arithopt}
  1917. AddInstr2OpContents(Pai386(p), Pai386(p)^.oper[2]);
  1918. {$else arithopt}
  1919. DestroyOp(p, Pai386(p)^.oper[2]);
  1920. {$endif arithopt}
  1921. End;
  1922. A_XOR:
  1923. Begin
  1924. ReadOp(CurProp, Pai386(p)^.oper[0]);
  1925. ReadOp(CurProp, Pai386(p)^.oper[1]);
  1926. If (Pai386(p)^.oper[0].typ = top_reg) And
  1927. (Pai386(p)^.oper[1].typ = top_reg) And
  1928. (Pai386(p)^.oper[0].reg = Pai386(p)^.oper[1].reg)
  1929. Then
  1930. Begin
  1931. DestroyReg(CurProp, Pai386(p)^.oper[0].reg);
  1932. CurProp^.Regs[Reg32(Pai386(p)^.oper[0].reg)].typ := Con_Const;
  1933. CurProp^.Regs[Reg32(Pai386(p)^.oper[0].reg)].StartMod := Pointer(0)
  1934. End
  1935. Else
  1936. DestroyOp(p, Pai386(p)^.oper[1]);
  1937. End
  1938. Else
  1939. Begin
  1940. Cnt := 1;
  1941. While (Cnt <= MaxCh) And
  1942. (InstrProp.Ch[Cnt] <> C_None) Do
  1943. Begin
  1944. Case InstrProp.Ch[Cnt] Of
  1945. C_REAX..C_REDI: ReadReg(CurProp,TCh2Reg(InstrProp.Ch[Cnt]));
  1946. C_WEAX..C_RWEDI:
  1947. Begin
  1948. If (InstrProp.Ch[Cnt] >= C_RWEAX) Then
  1949. ReadReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]));
  1950. DestroyReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]));
  1951. End;
  1952. {$ifdef arithopt}
  1953. C_MEAX..C_MEDI:
  1954. AddInstr2RegContents({$ifdef statedebug} asml, {$endif}
  1955. Pai386(p),
  1956. TCh2Reg(InstrProp.Ch[Cnt]));
  1957. {$endif arithopt}
  1958. C_CDirFlag: CurProp^.DirFlag := F_NotSet;
  1959. C_SDirFlag: CurProp^.DirFlag := F_Set;
  1960. C_Rop1: ReadOp(CurProp, Pai386(p)^.oper[0]);
  1961. C_Rop2: ReadOp(CurProp, Pai386(p)^.oper[1]);
  1962. C_ROp3: ReadOp(CurProp, Pai386(p)^.oper[2]);
  1963. C_Wop1..C_RWop1:
  1964. Begin
  1965. If (InstrProp.Ch[Cnt] in [C_RWop1]) Then
  1966. ReadOp(CurProp, Pai386(p)^.oper[0]);
  1967. DestroyOp(p, Pai386(p)^.oper[0]);
  1968. End;
  1969. {$ifdef arithopt}
  1970. C_Mop1:
  1971. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1972. Pai386(p), Pai386(p)^.oper[0]);
  1973. {$endif arithopt}
  1974. C_Wop2..C_RWop2:
  1975. Begin
  1976. If (InstrProp.Ch[Cnt] = C_RWop2) Then
  1977. ReadOp(CurProp, Pai386(p)^.oper[1]);
  1978. DestroyOp(p, Pai386(p)^.oper[1]);
  1979. End;
  1980. {$ifdef arithopt}
  1981. C_Mop2:
  1982. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1983. Pai386(p), Pai386(p)^.oper[1]);
  1984. {$endif arithopt}
  1985. C_WOp3..C_RWOp3:
  1986. Begin
  1987. If (InstrProp.Ch[Cnt] = C_RWOp3) Then
  1988. ReadOp(CurProp, Pai386(p)^.oper[2]);
  1989. DestroyOp(p, Pai386(p)^.oper[2]);
  1990. End;
  1991. {$ifdef arithopt}
  1992. C_Mop3:
  1993. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1994. Pai386(p), Pai386(p)^.oper[2]);
  1995. {$endif arithopt}
  1996. C_WMemEDI:
  1997. Begin
  1998. ReadReg(CurProp, R_EDI);
  1999. FillChar(TmpRef, SizeOf(TmpRef), 0);
  2000. TmpRef.Base := R_EDI;
  2001. DestroyRefs(p, TmpRef, R_NO)
  2002. End;
  2003. C_RFlags, C_WFlags, C_RWFlags, C_FPU:
  2004. Else
  2005. Begin
  2006. DestroyAllRegs(CurProp);
  2007. End;
  2008. End;
  2009. Inc(Cnt);
  2010. End
  2011. End;
  2012. end;
  2013. End;
  2014. End
  2015. Else
  2016. Begin
  2017. DestroyAllRegs(CurProp);
  2018. End;
  2019. End;
  2020. Inc(InstrCnt);
  2021. GetNextInstruction(p, p);
  2022. End;
  2023. End;
  2024. Function InitDFAPass2(BlockStart, BlockEnd: Pai): Boolean;
  2025. {reserves memory for the PPaiProps in one big memory block when not using
  2026. TP, returns False if not enough memory is available for the optimizer in all
  2027. cases}
  2028. Var p: Pai;
  2029. Count: Longint;
  2030. { TmpStr: String; }
  2031. Begin
  2032. P := BlockStart;
  2033. SkipHead(P);
  2034. NrOfPaiObjs := 0;
  2035. While (P <> BlockEnd) Do
  2036. Begin
  2037. {$IfDef JumpAnal}
  2038. Case P^.Typ Of
  2039. ait_label:
  2040. Begin
  2041. If (Pai_Label(p)^.l^.is_used) Then
  2042. LTable^[Pai_Label(P)^.l^.labelnr-LoLab].InstrNr := NrOfPaiObjs
  2043. End;
  2044. ait_instruction:
  2045. begin
  2046. if pai386(p)^.is_jmp then
  2047. begin
  2048. If (pasmlabel(pai386(P)^.oper[0].sym)^.labelnr >= LoLab) And
  2049. (pasmlabel(pai386(P)^.oper[0].sym)^.labelnr <= HiLab) Then
  2050. Inc(LTable^[pasmlabel(pai386(P)^.oper[0].sym)^.labelnr-LoLab].RefsFound);
  2051. end;
  2052. end;
  2053. { ait_instruction:
  2054. Begin
  2055. If (Pai386(p)^.opcode = A_PUSH) And
  2056. (Pai386(p)^.oper[0].typ = top_symbol) And
  2057. (PCSymbol(Pai386(p)^.oper[0])^.offset = 0) Then
  2058. Begin
  2059. TmpStr := StrPas(PCSymbol(Pai386(p)^.oper[0])^.symbol);
  2060. If}
  2061. End;
  2062. {$EndIf JumpAnal}
  2063. Inc(NrOfPaiObjs);
  2064. GetNextInstruction(p, p);
  2065. End;
  2066. {$IfDef TP}
  2067. If (MemAvail < (SizeOf(TPaiProp)*NrOfPaiObjs))
  2068. Or (NrOfPaiObjs = 0)
  2069. {this doesn't have to be one contiguous block}
  2070. Then InitDFAPass2 := False
  2071. Else InitDFAPass2 := True;
  2072. {$Else}
  2073. {Uncomment the next line to see how much memory the reloading optimizer needs}
  2074. { Writeln((NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4)));}
  2075. {no need to check mem/maxavail, we've got as much virtual memory as we want}
  2076. If NrOfPaiObjs <> 0 Then
  2077. Begin
  2078. InitDFAPass2 := True;
  2079. GetMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4));
  2080. p := BlockStart;
  2081. SkipHead(p);
  2082. For Count := 1 To NrOfPaiObjs Do
  2083. Begin
  2084. PPaiProp(p^.OptInfo) := @PaiPropBlock^[Count];
  2085. GetNextInstruction(p, p);
  2086. End;
  2087. End
  2088. Else InitDFAPass2 := False;
  2089. {$EndIf TP}
  2090. End;
  2091. Function DFAPass2(
  2092. {$ifdef statedebug}
  2093. AsmL: PAasmOutPut;
  2094. {$endif statedebug}
  2095. BlockStart, BlockEnd: Pai): Boolean;
  2096. Begin
  2097. If InitDFAPass2(BlockStart, BlockEnd) Then
  2098. Begin
  2099. DoDFAPass2(
  2100. {$ifdef statedebug}
  2101. asml,
  2102. {$endif statedebug}
  2103. BlockStart, BlockEnd);
  2104. DFAPass2 := True
  2105. End
  2106. Else DFAPass2 := False;
  2107. End;
  2108. Procedure ShutDownDFA;
  2109. Begin
  2110. If LabDif <> 0 Then
  2111. FreeMem(LTable, LabDif*SizeOf(TLabelTableItem));
  2112. End;
  2113. End.
  2114. {
  2115. $Log$
  2116. Revision 1.51 1999-08-02 12:12:53 jonas
  2117. * also add arithmetic operations to instruction sequences contained in registers
  2118. (compile with -darithopt, very nice!)
  2119. Revision 1.50 1999/07/30 18:18:51 jonas
  2120. * small bugfix in instructionsequal
  2121. * small bugfix in reginsequence
  2122. * made regininstruction a bit more logical
  2123. Revision 1.48 1999/07/01 18:21:21 jonas
  2124. * removed unused AsmL parameter from FindLoHiLabels
  2125. Revision 1.47 1999/05/27 19:44:24 peter
  2126. * removed oldasm
  2127. * plabel -> pasmlabel
  2128. * -a switches to source writing automaticly
  2129. * assembler readers OOPed
  2130. * asmsymbol automaticly external
  2131. * jumptables and other label fixes for asm readers
  2132. Revision 1.46 1999/05/08 20:40:02 jonas
  2133. * seperate OPTimizer INFO pointer field in tai object
  2134. * fix to GetLastInstruction that sometimes caused a crash
  2135. Revision 1.45 1999/05/01 13:48:37 peter
  2136. * merged nasm compiler
  2137. Revision 1.6 1999/04/18 17:57:21 jonas
  2138. * fix for crash when the first instruction of a sequence that gets
  2139. optimized is removed (this situation can't occur aymore now)
  2140. Revision 1.5 1999/04/16 11:49:50 peter
  2141. + tempalloc
  2142. + -at to show temp alloc info in .s file
  2143. Revision 1.4 1999/04/14 09:07:42 peter
  2144. * asm reader improvements
  2145. Revision 1.3 1999/03/31 13:55:29 peter
  2146. * assembler inlining working for ag386bin
  2147. Revision 1.2 1999/03/29 16:05:46 peter
  2148. * optimizer working for ag386bin
  2149. Revision 1.1 1999/03/26 00:01:10 peter
  2150. * first things for optimizer (compiles but cycle crashes)
  2151. Revision 1.39 1999/02/26 00:48:18 peter
  2152. * assembler writers fixed for ag386bin
  2153. Revision 1.38 1999/02/25 21:02:34 peter
  2154. * ag386bin updates
  2155. + coff writer
  2156. Revision 1.37 1999/02/22 02:15:20 peter
  2157. * updates for ag386bin
  2158. Revision 1.36 1999/01/20 17:41:26 jonas
  2159. * small bugfix (memory corruption could occur when certain fpu instructions
  2160. were encountered)
  2161. Revision 1.35 1999/01/08 12:39:22 florian
  2162. Changes of Alexander Stohr integrated:
  2163. + added KNI opcodes
  2164. + added KNI registers
  2165. + added 3DNow! opcodes
  2166. + added 64 bit and 128 bit register flags
  2167. * translated a few comments into english
  2168. Revision 1.34 1998/12/29 18:48:19 jonas
  2169. + optimize pascal code surrounding assembler blocks
  2170. Revision 1.33 1998/12/17 16:37:38 jonas
  2171. + extra checks in RegsEquivalent so some more optimizations can be done (which
  2172. where disabled by the second fix from revision 1.22)
  2173. Revision 1.32 1998/12/15 19:33:58 jonas
  2174. * uncommented OpsEqual & added to interface because popt386 uses it now
  2175. Revision 1.31 1998/12/11 00:03:13 peter
  2176. + globtype,tokens,version unit splitted from globals
  2177. Revision 1.30 1998/12/02 16:23:39 jonas
  2178. * changed "if longintvar in set" to case or "if () or () .." statements
  2179. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  2180. Revision 1.29 1998/11/26 21:45:31 jonas
  2181. - removed A_CLTD opcode (use A_CDQ instead)
  2182. * changed cbw, cwde and cwd to cbtw, cwtl and cwtd in att_.oper[1]str array
  2183. * in daopt386: adapted AsmInstr array to reflect changes + fixed line too long
  2184. Revision 1.27 1998/11/24 19:47:22 jonas
  2185. * fixed problems posible with 3 operand instructions
  2186. Revision 1.26 1998/11/24 12:50:09 peter
  2187. * fixed crash
  2188. Revision 1.25 1998/11/18 17:58:22 jonas
  2189. + gathering of register reading data, nowhere used yet (necessary for instruction scheduling)
  2190. Revision 1.24 1998/11/13 10:13:44 peter
  2191. + cpuid,emms support for asm readers
  2192. Revision 1.23 1998/11/09 19:40:46 jonas
  2193. * fixed comments from last commit (apparently there's still a 255 char limit :( )
  2194. Revision 1.22 1998/11/09 19:33:40 jonas
  2195. * changed specific bugfix (which was actually wrong implemented, but
  2196. did the right thing in most cases nevertheless) to general bugfix
  2197. * fixed bug that caused
  2198. mov (ebp), edx mov (ebp), edx
  2199. mov (edx), edx mov (edx), edx
  2200. ... being changed to ...
  2201. mov (ebp), edx mov edx, eax
  2202. mov (eax), eax
  2203. but this disabled another small correct optimization...
  2204. Revision 1.21 1998/11/02 23:17:49 jonas
  2205. * fixed bug shown in sortbug program from fpc-devel list
  2206. Revision 1.20 1998/10/22 13:24:51 jonas
  2207. * changed TRegSet to a small set
  2208. Revision 1.19 1998/10/20 09:29:24 peter
  2209. * bugfix so that code like
  2210. movl 48(%esi),%esi movl 48(%esi),%esi
  2211. pushl %esi doesn't get changed to pushl %esi
  2212. movl 48(%esi),%edi movl %esi,%edi
  2213. Revision 1.18 1998/10/07 16:27:02 jonas
  2214. * changed state to WState (WriteState), added RState for future use in
  2215. instruction scheduling
  2216. * RegAlloc data from the CG is now completely being patched and corrected (I
  2217. think)
  2218. Revision 1.17 1998/10/02 17:30:20 jonas
  2219. * small patches to regdealloc data
  2220. Revision 1.16 1998/10/01 20:21:47 jonas
  2221. * inter-register CSE, still requires some tweaks (peepholeoptpass2, better RegAlloc)
  2222. Revision 1.15 1998/09/20 18:00:20 florian
  2223. * small compiling problems fixed
  2224. Revision 1.14 1998/09/20 17:12:36 jonas
  2225. * small fix for uncertain optimizations & more cleaning up
  2226. Revision 1.12 1998/09/16 18:00:01 jonas
  2227. * optimizer now completely dependant on GetNext/GetLast instruction, works again with -dRegAlloc
  2228. Revision 1.11 1998/09/15 14:05:27 jonas
  2229. * fixed optimizer incompatibilities with freelabel code in psub
  2230. Revision 1.10 1998/09/09 15:33:58 peter
  2231. * removed warnings
  2232. Revision 1.9 1998/09/03 16:24:51 florian
  2233. * bug of type conversation from dword to real fixed
  2234. * bug fix of Jonas applied
  2235. Revision 1.8 1998/08/28 10:56:59 peter
  2236. * removed warnings
  2237. Revision 1.7 1998/08/19 16:07:44 jonas
  2238. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  2239. Revision 1.6 1998/08/10 14:49:57 peter
  2240. + localswitches, moduleswitches, globalswitches splitting
  2241. Revision 1.5 1998/08/09 13:56:24 jonas
  2242. * small bugfix for uncertain optimizations in DestroyRefs
  2243. Revision 1.4 1998/08/06 19:40:25 jonas
  2244. * removed $ before and after Log in comment
  2245. Revision 1.3 1998/08/05 16:00:14 florian
  2246. * some fixes for ansi strings
  2247. * log to Log changed
  2248. }