daopt386.pas 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427
  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. cpubase,cpuasm;
  28. Type
  29. TRegArray = Array[R_EAX..R_BL] of TRegister;
  30. TRegSet = Set of R_EAX..R_BL;
  31. TRegInfo = Record
  32. NewRegsEncountered, OldRegsEncountered: TRegSet;
  33. RegsLoadedForRef: TRegSet;
  34. New2OldReg: TRegArray;
  35. End;
  36. {possible actions on an operand: read, write or modify (= read & write)}
  37. TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
  38. {*********************** Procedures and Functions ************************}
  39. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  40. Function Reg32(Reg: TRegister): TRegister;
  41. Function RefsEquivalent(Const R1, R2: TReference; Var RegInfo: TRegInfo; OpAct: TOpAction): Boolean;
  42. Function RefsEqual(Const R1, R2: TReference): Boolean;
  43. Function IsGP32Reg(Reg: TRegister): Boolean;
  44. Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
  45. Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
  46. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  47. Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
  48. Function GetLastInstruction(Current: Pai; Var Last: Pai): Boolean;
  49. Procedure SkipHead(var P: Pai);
  50. Procedure UpdateUsedRegs(Var UsedRegs: TRegSet; p: Pai);
  51. Function RegsEquivalent(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo; OpAct: TopAction): Boolean;
  52. Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
  53. Function OpsEqual(const o1,o2:toper): Boolean;
  54. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  55. Function DFAPass2(
  56. {$ifdef statedebug}
  57. AsmL: PAasmOutPut;
  58. {$endif statedebug}
  59. BlockStart, BlockEnd: Pai): Boolean;
  60. Procedure ShutDownDFA;
  61. Function FindLabel(L: PasmLabel; Var hp: Pai): Boolean;
  62. {******************************* Constants *******************************}
  63. Const
  64. {ait_* types which don't result in executable code or which don't influence
  65. the way the program runs/behaves}
  66. SkipInstr = [ait_comment, ait_align, ait_symbol
  67. {$ifdef GDB}
  68. ,ait_stabs, ait_stabn, ait_stab_function_name
  69. {$endif GDB}
  70. ,ait_regalloc, ait_tempalloc
  71. ];
  72. {the maximum number of things (registers, memory, ...) a single instruction
  73. changes}
  74. MaxCh = 3;
  75. {Possible register content types}
  76. con_Unknown = 0;
  77. con_ref = 1;
  78. con_const = 2;
  79. {********************************* Types *********************************}
  80. Type
  81. {What an instruction can change}
  82. TChange = (C_None,
  83. {Read from a register}
  84. C_REAX, C_RECX, C_REDX, C_REBX, C_RESP, C_REBP, C_RESI, C_REDI,
  85. {write from a register}
  86. C_WEAX, C_WECX, C_WEDX, C_WEBX, C_WESP, C_WEBP, C_WESI, C_WEDI,
  87. {read and write from/to a register}
  88. C_RWEAX, C_RWECX, C_RWEDX, C_RWEBX, C_RWESP, C_RWEBP, C_RWESI, C_RWEDI,
  89. {modify the contents of a register with the purpose of using
  90. this changed content afterwards (add/sub/..., but e.g. not rep
  91. or movsd)}
  92. {$ifdef arithopt}
  93. C_MEAX, C_MECX, C_MEDX, C_MEBX, C_MESP, C_MEBP, C_MESI, C_MEDI,
  94. {$endif arithopt}
  95. C_CDirFlag {clear direction flag}, C_SDirFlag {set dir flag},
  96. C_RFlags, C_WFlags, C_RWFlags, C_FPU,
  97. C_Rop1, C_Wop1, C_RWop1,
  98. C_Rop2, C_Wop2, C_RWop2,
  99. C_Rop3, C_WOp3, C_RWOp3,
  100. {$ifdef arithopt}
  101. C_Mop1, C_Mop2, C_Mop3,
  102. {$endif arithopt}
  103. C_WMemEDI,
  104. C_All);
  105. {$ifndef arithopt}
  106. Const
  107. C_MEAX = C_RWEAX;
  108. C_MECX = C_RWECX;
  109. C_MEDX = C_RWEDX;
  110. C_MEBX = C_RWEBX;
  111. C_MESP = C_RWESP;
  112. C_MEBP = C_RWEBP;
  113. C_MESI = C_RWESI;
  114. C_MEDI = C_RWEDI;
  115. C_Mop1 = C_RWOp1;
  116. C_Mop2 = C_RWOp2;
  117. C_Mop3 = C_RWOp3;
  118. Type
  119. {$endif arithopt}
  120. {the possible states of a flag}
  121. TFlagContents = (F_Unknown, F_NotSet, F_Set);
  122. {the properties of a cpu instruction}
  123. TAsmInstrucProp = Record
  124. {how many things it changes}
  125. { NCh: Byte;}
  126. {and what it changes}
  127. Ch: Array[1..MaxCh] of TChange;
  128. End;
  129. TContent = Packed Record
  130. {start and end of block instructions that defines the
  131. content of this register. If Typ = con_const, then
  132. Longint(StartMod) = value of the constant)}
  133. StartMod: pai;
  134. {starts at 0, gets increased everytime the register is written to}
  135. WState: Byte;
  136. {starts at 0, gets increased everytime the register is read from}
  137. RState: Byte;
  138. {how many instructions starting with StarMod does the block consist of}
  139. NrOfMods: Byte;
  140. {the type of the content of the register: unknown, memory, constant}
  141. Typ: Byte;
  142. End;
  143. {Contents of the integer registers}
  144. TRegContent = Array[R_EAX..R_EDI] Of TContent;
  145. {contents of the FPU registers}
  146. TRegFPUContent = Array[R_ST..R_ST7] Of TContent;
  147. {information record with the contents of every register. Every Pai object
  148. gets one of these assigned: a pointer to it is stored in the OptInfo field}
  149. TPaiProp = Record
  150. Regs: TRegContent;
  151. { FPURegs: TRegFPUContent;} {currently not yet used}
  152. {allocated Registers}
  153. UsedRegs: TRegSet;
  154. {status of the direction flag}
  155. DirFlag: TFlagContents;
  156. {can this instruction be removed?}
  157. CanBeRemoved: Boolean;
  158. End;
  159. PPaiProp = ^TPaiProp;
  160. {$IfNDef TP}
  161. TPaiPropBlock = Array[1..250000] Of TPaiProp;
  162. PPaiPropBlock = ^TPaiPropBlock;
  163. {$EndIf TP}
  164. TInstrSinceLastMod = Array[R_EAX..R_EDI] Of Byte;
  165. TLabelTableItem = Record
  166. PaiObj: Pai;
  167. {$IfDef JumpAnal}
  168. InstrNr: Longint;
  169. RefsFound: Word;
  170. JmpsProcessed: Word
  171. {$EndIf JumpAnal}
  172. End;
  173. {$IfDef tp}
  174. TLabelTable = Array[0..10000] Of TLabelTableItem;
  175. {$Else tp}
  176. TLabelTable = Array[0..2500000] Of TLabelTableItem;
  177. {$Endif tp}
  178. PLabelTable = ^TLabelTable;
  179. {******************************* Variables *******************************}
  180. Var
  181. {the amount of PaiObjects in the current assembler list}
  182. NrOfPaiObjs: Longint;
  183. {$IfNDef TP}
  184. {Array which holds all TPaiProps}
  185. PaiPropBlock: PPaiPropBlock;
  186. {$EndIf TP}
  187. LoLab, HiLab, LabDif: Longint;
  188. LTable: PLabelTable;
  189. {*********************** End of Interface section ************************}
  190. Implementation
  191. Uses
  192. globals, systems, strings, verbose, hcodegen;
  193. Const AsmInstr: Array[tasmop] Of TAsmInstrucProp = (
  194. {A_<NONE>} (Ch: (C_All, C_None, C_None)), { new }
  195. {A_LOCK} (Ch: (C_None, C_None, C_None)),
  196. {A_REP} (Ch: (C_RWECX, C_RFlags, C_None)),
  197. {A_REPE} (Ch: (C_RWECX, C_RFlags, C_None)),
  198. {A_REPNE} (Ch: (C_RWECX, C_RFlags, C_None)),
  199. {A_REPNZ} (Ch: (C_WECX, C_RWFLAGS, C_None)), { new }
  200. {A_REPZ} (Ch: (C_WECX, C_RWFLAGS, C_None)), { new }
  201. {A_SEGCS} (Ch: (C_None, C_None, C_None)), { new }
  202. {A_SEGES} (Ch: (C_None, C_None, C_None)), { new }
  203. {A_SEGDS} (Ch: (C_None, C_None, C_None)), { new }
  204. {A_SEGFS} (Ch: (C_None, C_None, C_None)), { new }
  205. {A_SEGGS} (Ch: (C_None, C_None, C_None)), { new }
  206. {A_SEGSS} (Ch: (C_None, C_None, C_None)), { new }
  207. {A_AAA} (Ch: (C_MEAX, C_WFlags, C_None)),
  208. {A_AAD} (Ch: (C_MEAX, C_WFlags, C_None)),
  209. {A_AAM} (Ch: (C_MEAX, C_WFlags, C_None)),
  210. {A_AAS} (Ch: (C_MEAX, C_WFlags, C_None)),
  211. {A_ADC} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  212. {A_ADD} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  213. {A_AND} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  214. {A_ARPL} (Ch: (C_WFlags, C_None, C_None)),
  215. {A_BOUND} (Ch: (C_Rop1, C_None, C_None)),
  216. {A_BSF} (Ch: (C_Wop2, C_WFlags, C_Rop1)),
  217. {A_BSR} (Ch: (C_Wop2, C_WFlags, C_Rop1)),
  218. {A_BSWAP} (Ch: (C_MOp1, C_None, C_None)), { new }
  219. {A_BT} (Ch: (C_WFlags, C_Rop1, C_None)),
  220. {A_BTC} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  221. {A_BTR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  222. {A_BTS} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  223. {A_CALL} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  224. {A_CBW} (Ch: (C_MEAX, C_None, C_None)),
  225. {A_CDQ} (Ch: (C_MEAX, C_WEDX, C_None)),
  226. {A_CLC} (Ch: (C_WFlags, C_None, C_None)),
  227. {A_CLD} (Ch: (C_CDirFlag, C_None, C_None)),
  228. {A_CLI} (Ch: (C_WFlags, C_None, C_None)),
  229. {A_CLTS} (Ch: (C_None, C_None, C_None)),
  230. {A_CMC} (Ch: (C_WFlags, C_None, C_None)),
  231. {A_CMP} (Ch: (C_WFlags, C_None, C_None)),
  232. {A_CMPSB} (Ch: (C_All, C_None, C_None)), { new }
  233. {A_CMPSD} (Ch: (C_All, C_None, C_None)), { new }
  234. {A_CMPSW} (Ch: (C_All, C_None, C_None)), { new }
  235. {A_CMPXCHG} (Ch: (C_All, C_None, C_None)), { new }
  236. {A_CMPXCHG486} (Ch: (C_All, C_None, C_None)), { new }
  237. {A_CMPXCHG8B} (Ch: (C_All, C_None, C_None)), { new }
  238. {A_CPUID} (Ch: (C_All, C_None, C_none)),
  239. {A_CWD} (Ch: (C_MEAX, C_WEDX, C_None)),
  240. {A_CWDE} (Ch: (C_MEAX, C_None, C_None)),
  241. {A_DAA} (Ch: (C_MEAX, C_None, C_None)),
  242. {A_DAS} (Ch: (C_MEAX, C_None, C_None)),
  243. {A_DEC} (Ch: (C_Mop1, C_WFlags, C_None)),
  244. {A_DIV} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  245. {A_EMMS} (Ch: (C_FPU, C_None, C_None)), { new }
  246. {A_ENTER} (Ch: (C_RWESP, C_None, C_None)),
  247. {A_EQU} (Ch: (C_None, C_None, C_None)), { new }
  248. {A_F2XM1} (Ch: (C_FPU, C_None, C_None)),
  249. {A_FABS} (Ch: (C_FPU, C_None, C_None)),
  250. {A_FADD} (Ch: (C_FPU, C_None, C_None)),
  251. {A_FADDP} (Ch: (C_FPU, C_None, C_None)),
  252. {A_FBLD} (Ch: (C_Rop1, C_FPU, C_None)),
  253. {A_FBSTP} (Ch: (C_Wop1, C_FPU, C_None)),
  254. {A_FCHS} (Ch: (C_FPU, C_None, C_None)),
  255. {A_FCLEX} (Ch: (C_FPU, C_None, C_None)),
  256. {A_FCMOVB} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  257. {A_FCMOVBE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  258. {A_FCMOVE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  259. {A_FCMOVNB} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  260. {A_FCMOVNBE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  261. {A_FCMOVNE} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  262. {A_FCMOVNU} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  263. {A_FCMOVU} (Ch: (C_FPU, C_RFLAGS, C_None)), { new }
  264. {A_FCOM} (Ch: (C_FPU, C_None, C_None)),
  265. {A_FCOMI} (Ch: (C_WFLAGS, C_None, C_None)), { new }
  266. {A_FCOMIP} (Ch: (C_FPU, C_WFLAGS, C_None)), { new }
  267. {A_FCOMP} (Ch: (C_FPU, C_None, C_None)),
  268. {A_FCOMPP} (Ch: (C_FPU, C_None, C_None)),
  269. {A_FCOS} (Ch: (C_FPU, C_None, C_None)),
  270. {A_FDECSTP} (Ch: (C_FPU, C_None, C_None)),
  271. {A_FDISI} (Ch: (C_FPU, C_None, C_None)),
  272. {A_FDIV} (Ch: (C_FPU, C_None, C_None)),
  273. {A_FDIVP} (Ch: (C_FPU, C_None, C_None)),
  274. {A_FDIVR} (Ch: (C_FPU, C_None, C_None)),
  275. {A_FDIVRP} (Ch: (C_FPU, C_None, C_None)),
  276. {A_FEMMS} (Ch: (C_All, C_None, C_None)), { new }
  277. {A_FENI} (Ch: (C_FPU, C_None, C_None)),
  278. {A_FFREE} (Ch: (C_FPU, C_None, C_None)),
  279. {A_FIADD} (Ch: (C_FPU, C_None, C_None)),
  280. {A_FICOM} (Ch: (C_FPU, C_None, C_None)),
  281. {A_FICOMP} (Ch: (C_FPU, C_None, C_None)),
  282. {A_FIDIV} (Ch: (C_FPU, C_None, C_None)),
  283. {A_FIDIVR} (Ch: (C_FPU, C_None, C_None)),
  284. {A_FILD} (Ch: (C_FPU, C_None, C_None)),
  285. {A_FIMUL} (Ch: (C_FPU, C_None, C_None)),
  286. {A_FINCSTP} (Ch: (C_FPU, C_None, C_None)),
  287. {A_FINIT} (Ch: (C_FPU, C_None, C_None)),
  288. {A_FIST} (Ch: (C_Wop1, C_None, C_None)),
  289. {A_FISTP} (Ch: (C_Wop1, C_None, C_None)),
  290. {A_FISUB} (Ch: (C_FPU, C_None, C_None)),
  291. {A_FISUBR} (Ch: (C_FPU, C_None, C_None)), { new }
  292. {A_FLD} (Ch: (C_Rop1, C_FPU, C_None)),
  293. {A_FLD1} (Ch: (C_FPU, C_None, C_None)),
  294. {A_FLDCW} (Ch: (C_FPU, C_None, C_None)),
  295. {A_FLDENV} (Ch: (C_FPU, C_None, C_None)),
  296. {A_FLDL2E} (Ch: (C_FPU, C_None, C_None)),
  297. {A_FLDL2T} (Ch: (C_FPU, C_None, C_None)),
  298. {A_FLDLG2} (Ch: (C_FPU, C_None, C_None)),
  299. {A_FLDLN2} (Ch: (C_FPU, C_None, C_None)),
  300. {A_FLDPI} (Ch: (C_FPU, C_None, C_None)),
  301. {A_FLDZ} (Ch: (C_FPU, C_None, C_None)),
  302. {A_FMUL} (Ch: (C_FPU, C_None, C_None)),
  303. {A_FMULP} (Ch: (C_FPU, C_None, C_None)),
  304. {A_FNCLEX} (Ch: (C_FPU, C_None, C_None)),
  305. {A_FNDISI} (Ch: (C_FPU, C_None, C_None)),
  306. {A_FNENI} (Ch: (C_FPU, C_None, C_None)),
  307. {A_FNINIT} (Ch: (C_FPU, C_None, C_None)),
  308. {A_FNOP} (Ch: (C_FPU, C_None, C_None)),
  309. {A_FNSAVE} (Ch: (C_FPU, C_None, C_None)),
  310. {A_FNSTCW} (Ch: (C_Wop1, C_None, C_None)),
  311. {A_FNSTENV} (Ch: (C_Wop1, C_None, C_None)),
  312. {A_FNSTSW} (Ch: (C_Wop1, C_None, C_None)),
  313. {A_FPATAN} (Ch: (C_FPU, C_None, C_None)),
  314. {A_FPREM} (Ch: (C_FPU, C_None, C_None)),
  315. {A_FPREM1} (Ch: (C_FPU, C_None, C_None)),
  316. {A_FPTAN} (Ch: (C_FPU, C_None, C_None)),
  317. {A_FRNDINT} (Ch: (C_FPU, C_None, C_None)),
  318. {A_FRSTOR} (Ch: (C_FPU, C_None, C_None)),
  319. {A_FSAVE} (Ch: (C_Wop1, C_None, C_None)),
  320. {A_FSCALE} (Ch: (C_FPU, C_None, C_None)),
  321. {A_FSETPM} (Ch: (C_FPU, C_None, C_None)),
  322. {A_FSIN} (Ch: (C_FPU, C_None, C_None)),
  323. {A_FSINCOS} (Ch: (C_FPU, C_None, C_None)),
  324. {A_FSQRT} (Ch: (C_FPU, C_None, C_None)),
  325. {A_FST} (Ch: (C_Wop1, C_None, C_None)),
  326. {A_FSTCW} (Ch: (C_Wop1, C_None, C_None)),
  327. {A_FSTENV} (Ch: (C_Wop1, C_None, C_None)),
  328. {A_FSTP} (Ch: (C_Wop1, C_FPU, C_None)),
  329. {A_FSTSW} (Ch: (C_Wop1, C_None, C_None)),
  330. {A_FSUB} (Ch: (C_FPU, C_None, C_None)),
  331. {A_FSUBP} (Ch: (C_FPU, C_None, C_None)),
  332. {A_FSUBR} (Ch: (C_FPU, C_None, C_None)),
  333. {A_FSUBRP} (Ch: (C_FPU, C_None, C_None)),
  334. {A_FTST} (Ch: (C_FPU, C_None, C_None)),
  335. {A_FUCOM} (Ch: (C_None, C_None, C_None)), {changes fpu status word}
  336. {A_FUCOMI} (Ch: (C_WFLAGS, C_None, C_None)), { new }
  337. {A_FUCOMIP} (Ch: (C_FPU, C_WFLAGS, C_None)), { new }
  338. {A_FUCOMP} (Ch: (C_FPU, C_None, C_None)),
  339. {A_FUCOMPP} (Ch: (C_FPU, C_None, C_None)),
  340. {A_FWAIT} (Ch: (C_FPU, C_None, C_None)),
  341. {A_FXAM} (Ch: (C_FPU, C_None, C_None)),
  342. {A_FXCH} (Ch: (C_FPU, C_None, C_None)),
  343. {A_FXTRACT} (Ch: (C_FPU, C_None, C_None)),
  344. {A_FYL2X} (Ch: (C_FPU, C_None, C_None)),
  345. {A_FYL2XP1} (Ch: (C_FPU, C_None, C_None)),
  346. {A_HLT} (Ch: (C_None, C_None, C_None)),
  347. {A_IBTS} (Ch: (C_All, C_None, C_None)), { new }
  348. {A_ICEBP} (Ch: (C_All, C_None, C_None)), { new }
  349. {A_IDIV} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  350. {A_IMUL} (Ch: (C_RWEAX, C_WEDX, C_WFlags)), {handled separately, because several forms exist}
  351. {A_IN} (Ch: (C_Wop2, C_Rop1, C_None)),
  352. {A_INC} (Ch: (C_Mop1, C_WFlags, C_None)),
  353. {A_INSB} (Ch: (C_WMemEDI, C_RWEDI, C_None)), { new }
  354. {A_INSD} (Ch: (C_WMemEDI, C_RWEDI, C_None)), { new }
  355. {A_INSW} (Ch: (C_WMemEDI, C_RWEDI, C_None)), { new }
  356. {A_INT} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  357. {A_INT01} (Ch: (C_All, C_None, C_None)), { new }
  358. {A_INT1} (Ch: (C_All, C_None, C_None)), { new }
  359. {A_INT3} (Ch: (C_None, C_None, C_None)),
  360. {A_INTO} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  361. {A_INVD} (Ch: (C_All, C_None, C_None)), { new }
  362. {A_INVLPG} (Ch: (C_All, C_None, C_None)), { new }
  363. {A_IRET} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  364. {A_IRETD} (Ch: (C_All, C_None, C_None)), { new }
  365. {A_IRETW} (Ch: (C_All, C_None, C_None)), { new }
  366. {A_JCXZ} (Ch: (C_RECX, C_None, C_None)),
  367. {A_JECXZ} (Ch: (C_RECX, C_None, C_None)),
  368. {A_JMP} (Ch: (C_None, C_None, C_None)),
  369. {A_LAHF} (Ch: (C_WEAX, C_RFlags, C_None)),
  370. {A_LAR} (Ch: (C_Wop2, C_None, C_None)),
  371. {A_LDS} (Ch: (C_Wop2, C_None, C_None)),
  372. {A_LEA} (Ch: (C_Wop2, C_Rop1, C_None)),
  373. {A_LEAVE} (Ch: (C_RWESP, C_None, C_None)),
  374. {A_LES} (Ch: (C_Wop2, C_None, C_None)),
  375. {A_LFS} (Ch: (C_Wop2, C_None, C_None)),
  376. {A_LGDT} (Ch: (C_None, C_None, C_None)),
  377. {A_LGS} (Ch: (C_Wop2, C_None, C_None)),
  378. {A_LIDT} (Ch: (C_None, C_None, C_None)),
  379. {A_LLDT} (Ch: (C_None, C_None, C_None)),
  380. {A_LMSW} (Ch: (C_None, C_None, C_None)),
  381. {A_LOADALL} (Ch: (C_All, C_None, C_None)), { new }
  382. {A_LOADALL286} (Ch: (C_All, C_None, C_None)), { new }
  383. {A_LODSB} (Ch: (C_WEAX, C_RWESI, C_None)), { new }
  384. {A_LODSD} (Ch: (C_WEAX, C_RWESI, C_None)), { new }
  385. {A_LODSW} (Ch: (C_WEAX, C_RWESI, C_None)), { new }
  386. {A_LOOP} (Ch: (C_RWECX, C_None, C_None)),
  387. {A_LOOPE} (Ch: (C_RWECX, C_RFlags, C_None)),
  388. {A_LOOPNE} (Ch: (C_RWECX, C_RFlags, C_None)),
  389. {A_LOOPNZ} (Ch: (C_RWECX, C_RFlags, C_None)),
  390. {A_LOOPZ} (Ch: (C_RWECX, C_RFlags, C_None)),
  391. {A_LSL} (Ch: (C_Wop2, C_WFlags, C_None)),
  392. {A_LSS} (Ch: (C_Wop2, C_None, C_None)),
  393. {A_LTR} (Ch: (C_None, C_None, C_None)),
  394. {A_MOV} (Ch: (C_Wop2, C_Rop1, C_None)),
  395. {A_MOVD} (Ch: (C_All, C_None, C_None)), { new }
  396. {A_MOVQ} (Ch: (C_All, C_None, C_None)), { new }
  397. {A_MOVSB} (Ch: (C_All, C_Rop1, C_None)),
  398. {A_MOVSD} (Ch: (C_All, C_None, C_None)), { new }
  399. {A_MOVSW} (Ch: (C_All, C_None, C_None)), { new }
  400. {A_MOVSX} (Ch: (C_Wop2, C_Rop1, C_None)),
  401. {A_MOVZX} (Ch: (C_Wop2, C_Rop1, C_None)),
  402. {A_MUL} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  403. {A_NEG} (Ch: (C_Mop1, C_None, C_None)),
  404. {A_NOP} (Ch: (C_None, C_None, C_None)),
  405. {A_NOT} (Ch: (C_Mop1, C_WFlags, C_None)),
  406. {A_OR} (Ch: (C_Mop2, C_WFlags, C_None)),
  407. {A_OUT} (Ch: (C_Rop1, C_Rop2, C_None)),
  408. {A_OUTSB} (Ch: (C_All, C_None, C_None)), { new }
  409. {A_OUTSD} (Ch: (C_All, C_None, C_None)), { new }
  410. {A_OUTSW} (Ch: (C_All, C_None, C_None)), { new }
  411. {A_PACKSSDW} (Ch: (C_All, C_None, C_None)), { new }
  412. {A_PACKSSWB} (Ch: (C_All, C_None, C_None)), { new }
  413. {A_PACKUSWB} (Ch: (C_All, C_None, C_None)), { new }
  414. {A_PADDB} (Ch: (C_All, C_None, C_None)), { new }
  415. {A_PADDD} (Ch: (C_All, C_None, C_None)), { new }
  416. {A_PADDSB} (Ch: (C_All, C_None, C_None)), { new }
  417. {A_PADDSIW} (Ch: (C_All, C_None, C_None)), { new }
  418. {A_PADDSW} (Ch: (C_All, C_None, C_None)), { new }
  419. {A_PADDUSB} (Ch: (C_All, C_None, C_None)), { new }
  420. {A_PADDUSW} (Ch: (C_All, C_None, C_None)), { new }
  421. {A_PADDW} (Ch: (C_All, C_None, C_None)), { new }
  422. {A_PAND} (Ch: (C_All, C_None, C_None)), { new }
  423. {A_PANDN} (Ch: (C_All, C_None, C_None)), { new }
  424. {A_PAVEB} (Ch: (C_All, C_None, C_None)), { new }
  425. {A_PAVGUSB} (Ch: (C_All, C_None, C_None)), { new }
  426. {A_PCMPEQB} (Ch: (C_All, C_None, C_None)), { new }
  427. {A_PCMPEQD} (Ch: (C_All, C_None, C_None)), { new }
  428. {A_PCMPEQW} (Ch: (C_All, C_None, C_None)), { new }
  429. {A_PCMPGTB} (Ch: (C_All, C_None, C_None)), { new }
  430. {A_PCMPGTD} (Ch: (C_All, C_None, C_None)), { new }
  431. {A_PCMPGTW} (Ch: (C_All, C_None, C_None)), { new }
  432. {A_PDISTIB} (Ch: (C_All, C_None, C_None)), { new }
  433. {A_PF2ID} (Ch: (C_All, C_None, C_None)), { new }
  434. {A_PFACC} (Ch: (C_All, C_None, C_None)), { new }
  435. {A_PFADD} (Ch: (C_All, C_None, C_None)), { new }
  436. {A_PFCMPEQ} (Ch: (C_All, C_None, C_None)), { new }
  437. {A_PFCMPGE} (Ch: (C_All, C_None, C_None)), { new }
  438. {A_PFCMPGT} (Ch: (C_All, C_None, C_None)), { new }
  439. {A_PFMAX} (Ch: (C_All, C_None, C_None)), { new }
  440. {A_PFMIN} (Ch: (C_All, C_None, C_None)), { new }
  441. {A_PFMUL} (Ch: (C_All, C_None, C_None)), { new }
  442. {A_PFRCP} (Ch: (C_All, C_None, C_None)), { new }
  443. {A_PFRCPIT1} (Ch: (C_All, C_None, C_None)), { new }
  444. {A_PFRCPIT2} (Ch: (C_All, C_None, C_None)), { new }
  445. {A_PFRSQIT1} (Ch: (C_All, C_None, C_None)), { new }
  446. {A_PFRSQRT} (Ch: (C_All, C_None, C_None)), { new }
  447. {A_PFSUB} (Ch: (C_All, C_None, C_None)), { new }
  448. {A_PFSUBR} (Ch: (C_All, C_None, C_None)), { new }
  449. {A_PI2FD} (Ch: (C_All, C_None, C_None)), { new }
  450. {A_PMACHRIW} (Ch: (C_All, C_None, C_None)), { new }
  451. {A_PMADDWD} (Ch: (C_All, C_None, C_None)), { new }
  452. {A_PMAGW} (Ch: (C_All, C_None, C_None)), { new }
  453. {A_PMULHRIW} (Ch: (C_All, C_None, C_None)), { new }
  454. {A_PMULHRWA} (Ch: (C_All, C_None, C_None)), { new }
  455. {A_PMULHRWC} (Ch: (C_All, C_None, C_None)), { new }
  456. {A_PMULHW} (Ch: (C_All, C_None, C_None)), { new }
  457. {A_PMULLW} (Ch: (C_All, C_None, C_None)), { new }
  458. {A_PMVGEZB} (Ch: (C_All, C_None, C_None)), { new }
  459. {A_PMVLZB} (Ch: (C_All, C_None, C_None)), { new }
  460. {A_PMVNZB} (Ch: (C_All, C_None, C_None)), { new }
  461. {A_PMVZB} (Ch: (C_All, C_None, C_None)), { new }
  462. {A_POP} (Ch: (C_Wop1, C_RWESP, C_None)),
  463. {A_POPA} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  464. {A_POPAD} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  465. {A_POPAW} (Ch: (C_All, C_None, C_None)), { new }
  466. {A_POPF} (Ch: (C_RWESP, C_WFlags, C_None)),
  467. {A_POPFD} (Ch: (C_RWESP, C_WFlags, C_None)),
  468. {A_POPFW} (Ch: (C_RWESP, C_WFLAGS, C_None)), { new }
  469. {A_POR} (Ch: (C_All, C_None, C_None)), { new }
  470. {A_PREFETCH} (Ch: (C_All, C_None, C_None)), { new }
  471. {A_PREFETCHW} (Ch: (C_All, C_None, C_None)), { new }
  472. {A_PSLLD} (Ch: (C_All, C_None, C_None)), { new }
  473. {A_PSLLQ} (Ch: (C_All, C_None, C_None)), { new }
  474. {A_PSLLW} (Ch: (C_All, C_None, C_None)), { new }
  475. {A_PSRAD} (Ch: (C_All, C_None, C_None)), { new }
  476. {A_PSRAW} (Ch: (C_All, C_None, C_None)), { new }
  477. {A_PSRLD} (Ch: (C_All, C_None, C_None)), { new }
  478. {A_PSRLQ} (Ch: (C_All, C_None, C_None)), { new }
  479. {A_PSRLW} (Ch: (C_All, C_None, C_None)), { new }
  480. {A_PSUBB} (Ch: (C_All, C_None, C_None)), { new }
  481. {A_PSUBD} (Ch: (C_All, C_None, C_None)), { new }
  482. {A_PSUBSB} (Ch: (C_All, C_None, C_None)), { new }
  483. {A_PSUBSIW} (Ch: (C_All, C_None, C_None)), { new }
  484. {A_PSUBSW} (Ch: (C_All, C_None, C_None)), { new }
  485. {A_PSUBUSB} (Ch: (C_All, C_None, C_None)), { new }
  486. {A_PSUBUSW} (Ch: (C_All, C_None, C_None)), { new }
  487. {A_PSUBW} (Ch: (C_All, C_None, C_None)), { new }
  488. {A_PUNPCKHBW} (Ch: (C_All, C_None, C_None)), { new }
  489. {A_PUNPCKHDQ} (Ch: (C_All, C_None, C_None)), { new }
  490. {A_PUNPCKHWD} (Ch: (C_All, C_None, C_None)), { new }
  491. {A_PUNPCKLBW} (Ch: (C_All, C_None, C_None)), { new }
  492. {A_PUNPCKLDQ} (Ch: (C_All, C_None, C_None)), { new }
  493. {A_PUNPCKLWD} (Ch: (C_All, C_None, C_None)), { new }
  494. {A_PUSH} (Ch: (C_Rop1, C_RWESP, C_None)),
  495. {A_PUSHA} (Ch: (C_All, C_None, C_None)),
  496. {A_PUSHAD} (Ch: (C_All, C_None, C_None)),
  497. {A_PUSHAW} (Ch: (C_All, C_None, C_None)), { new }
  498. {A_PUSHF} (Ch: (C_RWESP, C_RFlags, C_None)),
  499. {A_PUSHFD} (Ch: (C_RWESP, C_RFlags, C_None)),
  500. {A_PUSHFW} (Ch: (C_RWESP, C_RFLAGS, C_None)), { new }
  501. {A_PXOR} (Ch: (C_All, C_None, C_None)), { new }
  502. {A_RCL} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  503. {A_RCR} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  504. {A_RDMSR} (Ch: (C_WEAX, C_WEDX, C_None)), { new }
  505. {A_RDPMC} (Ch: (C_WEAX, C_WEDX, C_None)), { new }
  506. {A_RDTSC} (Ch: (C_WEAX, C_WEDX, C_None)), { new }
  507. {A_RESB} (Ch: (C_All, C_None, C_None)), { new }
  508. {A_RET} (Ch: (C_All, C_None, C_None)),
  509. {A_RETF} (Ch: (C_All, C_None, C_None)), { new }
  510. {A_RETN} (Ch: (C_All, C_None, C_None)), { new }
  511. {A_ROL} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  512. {A_ROR} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  513. {A_RSM} (Ch: (C_All, C_None, C_None)), { new }
  514. {A_SAHF} (Ch: (C_WFlags, C_REAX, C_None)),
  515. {A_SAL} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  516. {A_SALC} (Ch: (C_WEAX, C_RFLAGS, C_None)), { new }
  517. {A_SAR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  518. {A_SBB} (Ch: (C_Mop2, C_Rop1, C_RWFlags)),
  519. {A_SCASB} (Ch: (C_All, C_None, C_None)), { new }
  520. {A_SCASD} (Ch: (C_All, C_None, C_None)), { new }
  521. {A_SCASW} (Ch: (C_All, C_None, C_None)), { new }
  522. {A_SGDT} (Ch: (C_Wop1, C_None, C_None)),
  523. {A_SHL} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  524. {A_SHLD} (Ch: (C_MOp3, C_RWFlags, C_Rop2)),
  525. {A_SHR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  526. {A_SHRD} (Ch: (C_MOp3, C_RWFlags, C_Rop2)),
  527. {A_SIDT} (Ch: (C_Wop1, C_None, C_None)),
  528. {A_SLDT} (Ch: (C_Wop1, C_None, C_None)),
  529. {A_SMI} (Ch: (C_All, C_None, C_None)), { new }
  530. {A_SMSW} (Ch: (C_Wop1, C_None, C_None)),
  531. {A_STC} (Ch: (C_WFlags, C_None, C_None)),
  532. {A_STD} (Ch: (C_SDirFlag, C_None, C_None)),
  533. {A_STI} (Ch: (C_WFlags, C_None, C_None)),
  534. {A_STOSB} (Ch: (C_REAX, C_WMemEDI, C_RWEDI)), { new }
  535. {A_STOSD} (Ch: (C_REAX, C_WMemEDI, C_RWEDI)), { new }
  536. {A_STOSW} (Ch: (C_REAX, C_WMemEDI, C_RWEDI)), { new }
  537. {A_STR} (Ch: (C_Wop1, C_None, C_None)),
  538. {A_SUB} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  539. {A_TEST} (Ch: (C_WFlags, C_Rop1, C_Rop2)),
  540. {A_UMOV} (Ch: (C_All, C_None, C_None)), { new }
  541. {A_VERR} (Ch: (C_WFlags, C_None, C_None)),
  542. {A_VERW} (Ch: (C_WFlags, C_None, C_None)),
  543. {A_WAIT} (Ch: (C_None, C_None, C_None)),
  544. {A_WBINVD} (Ch: (C_None, C_None, C_None)), { new }
  545. {A_WRMSR} (Ch: (C_All, C_None, C_None)), { new }
  546. {A_XADD} (Ch: (C_All, C_None, C_None)), { new }
  547. {A_XBTS} (Ch: (C_All, C_None, C_None)), { new }
  548. {A_XCHG} (Ch: (C_RWop1, C_RWop2, C_None)), {(might be) handled seperately}
  549. {A_XLAT} (Ch: (C_WEAX, C_REBX, C_None)),
  550. {A_XLATB} (Ch: (C_WEAX, C_REBX, C_None)),
  551. {A_XOR} (Ch: (C_Mop2, C_Rop1, C_WFlags)),
  552. {A_CMOV} (Ch: (C_ROp1, C_WOp2, C_RFLAGS)), { new }
  553. {A_J} (Ch: (C_None, C_None, C_None)), { new }
  554. {A_SET} (Ch: (C_WEAX, C_RFLAGS, C_None)) { new }
  555. );
  556. Var
  557. {How many instructions are between the current instruction and the last one
  558. that modified the register}
  559. NrOfInstrSinceLastMod: TInstrSinceLastMod;
  560. {************************ Create the Label table ************************}
  561. Function FindLoHiLabels(Var LowLabel, HighLabel, LabelDif: Longint; BlockStart: Pai): Pai;
  562. {Walks through the paasmlist to find the lowest and highest label number}
  563. Var LabelFound: Boolean;
  564. P: Pai;
  565. Begin
  566. LabelFound := False;
  567. LowLabel := MaxLongint;
  568. HighLabel := 0;
  569. P := BlockStart;
  570. While Assigned(P) And
  571. ((P^.typ <> Ait_Marker) Or
  572. (Pai_Marker(P)^.Kind <> AsmBlockStart)) Do
  573. Begin
  574. If (Pai(p)^.typ = ait_label) Then
  575. If (Pai_Label(p)^.l^.is_used)
  576. Then
  577. Begin
  578. LabelFound := True;
  579. If (Pai_Label(p)^.l^.labelnr < LowLabel) Then
  580. LowLabel := Pai_Label(p)^.l^.labelnr;
  581. If (Pai_Label(p)^.l^.labelnr > HighLabel) Then
  582. HighLabel := Pai_Label(p)^.l^.labelnr;
  583. End;
  584. GetNextInstruction(p, p);
  585. End;
  586. FindLoHiLabels := p;
  587. If LabelFound
  588. Then LabelDif := HighLabel+1-LowLabel
  589. Else LabelDif := 0;
  590. End;
  591. Function FindRegAlloc(Reg: TRegister; StartPai: Pai): Boolean;
  592. {Returns true if a ait_alloc object for Reg is found in the block of Pai's
  593. starting with StartPai and ending with the next "real" instruction}
  594. Begin
  595. FindRegAlloc:=False;
  596. Repeat
  597. While Assigned(StartPai) And
  598. ((StartPai^.typ in (SkipInstr - [ait_regAlloc])) Or
  599. ((StartPai^.typ = ait_label) and
  600. Not(Pai_Label(StartPai)^.l^.Is_Used))) Do
  601. StartPai := Pai(StartPai^.Next);
  602. If Assigned(StartPai) And
  603. (StartPai^.typ = ait_regAlloc) and (PairegAlloc(StartPai)^.allocation) Then
  604. Begin
  605. if PairegAlloc(StartPai)^.Reg = Reg then
  606. begin
  607. FindRegAlloc:=true;
  608. exit;
  609. end;
  610. StartPai := Pai(StartPai^.Next);
  611. End
  612. else
  613. exit;
  614. Until false;
  615. End;
  616. Procedure BuildLabelTableAndFixRegAlloc(AsmL: PAasmOutput; Var LabelTable: PLabelTable; LowLabel: Longint;
  617. Var LabelDif: Longint; BlockStart, BlockEnd: Pai);
  618. {Builds a table with the locations of the labels in the paasmoutput.
  619. Also fixes some RegDeallocs like "# %eax released; push (%eax)"}
  620. Var p, hp1, hp2: Pai;
  621. UsedRegs: TRegSet;
  622. Begin
  623. UsedRegs := [];
  624. If (LabelDif <> 0) Then
  625. Begin
  626. {$IfDef TP}
  627. If (MaxAvail >= LabelDif*SizeOf(Pai))
  628. Then
  629. Begin
  630. {$EndIf TP}
  631. GetMem(LabelTable, LabelDif*SizeOf(TLabelTableItem));
  632. FillChar(LabelTable^, LabelDif*SizeOf(TLabelTableItem), 0);
  633. p := BlockStart;
  634. While (P <> BlockEnd) Do
  635. Begin
  636. Case p^.typ Of
  637. ait_Label:
  638. If Pai_Label(p)^.l^.is_used Then
  639. LabelTable^[Pai_Label(p)^.l^.labelnr-LowLabel].PaiObj := p;
  640. ait_regAlloc:
  641. begin
  642. if PairegAlloc(p)^.Allocation then
  643. Begin
  644. If Not(PaiRegAlloc(p)^.Reg in UsedRegs) Then
  645. UsedRegs := UsedRegs + [PaiRegAlloc(p)^.Reg]
  646. Else
  647. Begin
  648. hp1 := p;
  649. hp2 := nil;
  650. While GetLastInstruction(hp1, hp1) And
  651. Not(RegInInstruction(PaiRegAlloc(p)^.Reg, hp1)) Do
  652. hp2 := hp1;
  653. If hp2 <> nil Then
  654. Begin
  655. hp1 := New(PaiRegAlloc, DeAlloc(PaiRegAlloc(p)^.Reg));
  656. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp1);
  657. End;
  658. End;
  659. End
  660. else
  661. Begin
  662. UsedRegs := UsedRegs - [PaiRegAlloc(p)^.Reg];
  663. hp1 := p;
  664. hp2 := nil;
  665. While Not(FindRegAlloc(PaiRegAlloc(p)^.Reg, Pai(hp1^.Next))) And
  666. GetNextInstruction(hp1, hp1) And
  667. RegInInstruction(PaiRegAlloc(p)^.Reg, hp1) Do
  668. hp2 := hp1;
  669. If hp2 <> nil Then
  670. Begin
  671. hp1 := Pai(p^.previous);
  672. AsmL^.Remove(p);
  673. InsertLLItem(AsmL, hp2, Pai(hp2^.Next), p);
  674. p := hp1;
  675. End;
  676. End;
  677. end;
  678. End;
  679. P := Pai(p^.Next);
  680. While Assigned(p) And
  681. (p^.typ in (SkipInstr - [ait_regalloc])) Do
  682. P := Pai(P^.Next);
  683. End;
  684. {$IfDef TP}
  685. End
  686. Else LabelDif := 0;
  687. {$EndIf TP}
  688. End;
  689. End;
  690. {************************ Search the Label table ************************}
  691. Function FindLabel(L: PasmLabel; Var hp: Pai): Boolean;
  692. {searches for the specified label starting from hp as long as the
  693. encountered instructions are labels, to be able to optimize constructs like
  694. jne l2 jmp l2
  695. jmp l3 and l1:
  696. l1: l2:
  697. l2:}
  698. Var TempP: Pai;
  699. Begin
  700. TempP := hp;
  701. While Assigned(TempP) and
  702. (TempP^.typ In SkipInstr + [ait_label]) Do
  703. If (TempP^.typ <> ait_Label) Or
  704. (pai_label(TempP)^.l <> L)
  705. Then GetNextInstruction(TempP, TempP)
  706. Else
  707. Begin
  708. hp := TempP;
  709. FindLabel := True;
  710. exit
  711. End;
  712. FindLabel := False;
  713. End;
  714. {************************ Some general functions ************************}
  715. Function Reg32(Reg: TRegister): TRegister;
  716. {Returns the 32 bit component of Reg if it exists, otherwise Reg is returned}
  717. Begin
  718. Reg32 := Reg;
  719. If (Reg >= R_AX)
  720. Then
  721. If (Reg <= R_DI)
  722. Then Reg32 := Reg16ToReg32(Reg)
  723. Else
  724. If (Reg <= R_BL)
  725. Then Reg32 := Reg8toReg32(Reg);
  726. End;
  727. { inserts new_one between prev and foll }
  728. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  729. Begin
  730. If Assigned(prev) Then
  731. If Assigned(foll) Then
  732. Begin
  733. If Assigned(new_one) Then
  734. Begin
  735. new_one^.previous := prev;
  736. new_one^.next := foll;
  737. prev^.next := new_one;
  738. foll^.previous := new_one;
  739. Pai(new_one)^.fileinfo := Pai(foll)^.fileinfo;
  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. )
  1454. Then
  1455. DestroyReg(PPaiProp(p^.OptInfo), Counter)
  1456. End
  1457. Else
  1458. {write something to a pointer location, so
  1459. * with uncertain optimzations on:
  1460. - do not destroy registers which contain a local/global variable or a
  1461. parameter, except if DestroyRefs is called because of a "movsl"
  1462. * with uncertain optimzations off:
  1463. - destroy every register which contains a memory location
  1464. }
  1465. For Counter := R_EAX to R_EDI Do
  1466. With PPaiProp(p^.OptInfo)^.Regs[Counter] Do
  1467. If (typ = Con_Ref) And
  1468. (Not(cs_UncertainOpts in aktglobalswitches) Or
  1469. {for movsl}
  1470. (Ref.Base = R_EDI) Or
  1471. {don't destroy if reg contains a parameter, local or global variable}
  1472. Not((NrOfMods = 1) And
  1473. (Pai386(StartMod)^.oper[0].typ = top_ref) And
  1474. ((Pai386(StartMod)^.oper[0].ref^.base = ProcInfo.FramePointer) Or
  1475. Assigned(Pai386(StartMod)^.oper[0].ref^.Symbol)
  1476. )
  1477. )
  1478. )
  1479. Then DestroyReg(PPaiProp(p^.OptInfo), Counter)
  1480. End;
  1481. Procedure DestroyAllRegs(p: PPaiProp);
  1482. Var Counter: TRegister;
  1483. Begin {initializes/desrtoys all registers}
  1484. For Counter := R_EAX To R_EDI Do
  1485. DestroyReg(p, Counter);
  1486. p^.DirFlag := F_Unknown;
  1487. End;
  1488. Procedure DestroyOp(PaiObj: Pai; const o:Toper);
  1489. Begin
  1490. Case o.typ Of
  1491. top_reg: DestroyReg(PPaiProp(PaiObj^.OptInfo), o.reg);
  1492. top_ref: DestroyRefs(PaiObj, o.ref^, R_NO);
  1493. top_symbol:;
  1494. End;
  1495. End;
  1496. Procedure ReadReg(p: PPaiProp; Reg: TRegister);
  1497. Begin
  1498. Reg := Reg32(Reg);
  1499. If Reg in [R_EAX..R_EDI] Then
  1500. IncState(p^.Regs[Reg32(Reg)].RState)
  1501. End;
  1502. Procedure ReadRef(p: PPaiProp; Ref: PReference);
  1503. Begin
  1504. If Ref^.Base <> R_NO Then
  1505. ReadReg(p, Ref^.Base);
  1506. If Ref^.Index <> R_NO Then
  1507. ReadReg(p, Ref^.Index);
  1508. End;
  1509. Procedure ReadOp(P: PPaiProp;const o:toper);
  1510. Begin
  1511. Case o.typ Of
  1512. top_reg: ReadReg(P, o.reg);
  1513. top_ref: ReadRef(P, o.ref);
  1514. top_symbol : ;
  1515. End;
  1516. End;
  1517. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  1518. {gathers the RegAlloc data... still need to think about where to store it to
  1519. avoid global vars}
  1520. Var BlockEnd: Pai;
  1521. Begin
  1522. BlockEnd := FindLoHiLabels(LoLab, HiLab, LabDif, BlockStart);
  1523. BuildLabelTableAndFixRegAlloc(AsmL, LTable, LoLab, LabDif, BlockStart, BlockEnd);
  1524. DFAPass1 := BlockEnd;
  1525. End;
  1526. {$ifdef arithopt}
  1527. Procedure AddInstr2RegContents({$ifdef statedebug} asml: paasmoutput; {$endif}
  1528. p: pai386; reg: TRegister);
  1529. {$ifdef statedebug}
  1530. var hp: pai;
  1531. {$endif statedebug}
  1532. Begin
  1533. Reg := Reg32(Reg);
  1534. With PPaiProp(p^.optinfo)^.Regs[reg] Do
  1535. If (Typ = Con_Ref)
  1536. Then
  1537. Begin
  1538. IncState(WState);
  1539. {also store how many instructions are part of the sequence in the first
  1540. instructions PPaiProp, so it can be easily accessed from within
  1541. CheckSequence}
  1542. Inc(NrOfMods, NrOfInstrSinceLastMod[Reg]);
  1543. PPaiProp(Pai(StartMod)^.OptInfo)^.Regs[Reg].NrOfMods := NrOfMods;
  1544. NrOfInstrSinceLastMod[Reg] := 0;
  1545. {$ifdef StateDebug}
  1546. hp := new(pai_asm_comment,init(strpnew(att_reg2str[reg]+': '+tostr(PPaiProp(p^.optinfo)^.Regs[reg].WState)
  1547. + ' -- ' + tostr(PPaiProp(p^.optinfo)^.Regs[reg].nrofmods))));
  1548. InsertLLItem(AsmL, p, p^.next, hp);
  1549. {$endif StateDebug}
  1550. End
  1551. Else
  1552. Begin
  1553. DestroyReg(PPaiProp(p^.optinfo), Reg);
  1554. {$ifdef StateDebug}
  1555. hp := new(pai_asm_comment,init(strpnew(att_reg2str[reg]+': '+tostr(PPaiProp(p^.optinfo)^.Regs[reg].WState))));
  1556. InsertLLItem(AsmL, p, p^.next, hp);
  1557. {$endif StateDebug}
  1558. End
  1559. End;
  1560. Procedure AddInstr2OpContents({$ifdef statedebug} asml: paasmoutput; {$endif}
  1561. p: pai386; const oper: TOper);
  1562. Begin
  1563. If oper.typ = top_reg Then
  1564. AddInstr2RegContents({$ifdef statedebug} asml, {$endif}p, oper.reg)
  1565. Else
  1566. Begin
  1567. ReadOp(PPaiProp(p^.optinfo), oper);
  1568. DestroyOp(p, oper);
  1569. End
  1570. End;
  1571. {$endif arithopt}
  1572. Procedure DoDFAPass2(
  1573. {$Ifdef StateDebug}
  1574. AsmL: PAasmOutput;
  1575. {$endif statedebug}
  1576. BlockStart, BlockEnd: Pai);
  1577. {Analyzes the Data Flow of an assembler list. Starts creating the reg
  1578. contents for the instructions starting with p. Returns the last pai which has
  1579. been processed}
  1580. Var
  1581. CurProp: PPaiProp;
  1582. {$ifdef AnalyzeLoops}
  1583. TmpState: Byte;
  1584. {$endif AnalyzeLoops}
  1585. Cnt, InstrCnt : Longint;
  1586. InstrProp: TAsmInstrucProp;
  1587. UsedRegs: TRegSet;
  1588. p, hp : Pai;
  1589. TmpRef: TReference;
  1590. TmpReg: TRegister;
  1591. Begin
  1592. p := BlockStart;
  1593. UsedRegs := [];
  1594. UpdateUsedregs(UsedRegs, p);
  1595. SkipHead(P);
  1596. BlockStart := p;
  1597. InstrCnt := 1;
  1598. FillChar(NrOfInstrSinceLastMod, SizeOf(NrOfInstrSinceLastMod), 0);
  1599. While (P <> BlockEnd) Do
  1600. Begin
  1601. {$IfDef TP}
  1602. New(CurProp);
  1603. {$Else TP}
  1604. CurProp := @PaiPropBlock^[InstrCnt];
  1605. {$EndIf TP}
  1606. If (p <> BlockStart)
  1607. Then
  1608. Begin
  1609. {$ifdef JumpAnal}
  1610. If (p^.Typ <> ait_label) Then
  1611. {$endif JumpAnal}
  1612. Begin
  1613. GetLastInstruction(p, hp);
  1614. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1615. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1616. End
  1617. End
  1618. Else
  1619. Begin
  1620. FillChar(CurProp^, SizeOf(CurProp^), 0);
  1621. { For TmpReg := R_EAX to R_EDI Do
  1622. CurProp^.Regs[TmpReg].WState := 1;}
  1623. End;
  1624. CurProp^.UsedRegs := UsedRegs;
  1625. CurProp^.CanBeRemoved := False;
  1626. UpdateUsedRegs(UsedRegs, Pai(p^.Next));
  1627. {$ifdef TP}
  1628. PPaiProp(p^.OptInfo) := CurProp;
  1629. {$Endif TP}
  1630. For TmpReg := R_EAX To R_EDI Do
  1631. Inc(NrOfInstrSinceLastMod[TmpReg]);
  1632. Case p^.typ Of
  1633. ait_label:
  1634. {$Ifndef JumpAnal}
  1635. If (Pai_label(p)^.l^.is_used) Then
  1636. DestroyAllRegs(CurProp);
  1637. {$Else JumpAnal}
  1638. Begin
  1639. If (Pai_Label(p)^.is_used) Then
  1640. With LTable^[Pai_Label(p)^.l^.labelnr-LoLab] Do
  1641. {$IfDef AnalyzeLoops}
  1642. If (RefsFound = Pai_Label(p)^.l^.RefCount)
  1643. {$Else AnalyzeLoops}
  1644. If (JmpsProcessed = Pai_Label(p)^.l^.RefCount)
  1645. {$EndIf AnalyzeLoops}
  1646. Then
  1647. {all jumps to this label have been found}
  1648. {$IfDef AnalyzeLoops}
  1649. If (JmpsProcessed > 0)
  1650. Then
  1651. {$EndIf AnalyzeLoops}
  1652. {we've processed at least one jump to this label}
  1653. Begin
  1654. If (GetLastInstruction(p, hp) And
  1655. Not(((hp^.typ = ait_instruction)) And
  1656. (pai386_labeled(hp)^.is_jmp))
  1657. Then
  1658. {previous instruction not a JMP -> the contents of the registers after the
  1659. previous intruction has been executed have to be taken into account as well}
  1660. For TmpReg := R_EAX to R_EDI Do
  1661. Begin
  1662. If (CurProp^.Regs[TmpReg].WState <>
  1663. PPaiProp(hp^.OptInfo)^.Regs[TmpReg].WState)
  1664. Then DestroyReg(CurProp, TmpReg)
  1665. End
  1666. End
  1667. {$IfDef AnalyzeLoops}
  1668. Else
  1669. {a label from a backward jump (e.g. a loop), no jump to this label has
  1670. already been processed}
  1671. If GetLastInstruction(p, hp) And
  1672. Not(hp^.typ = ait_instruction) And
  1673. (pai386_labeled(hp)^.opcode = A_JMP))
  1674. Then
  1675. {previous instruction not a jmp, so keep all the registers' contents from the
  1676. previous instruction}
  1677. Begin
  1678. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1679. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1680. End
  1681. Else
  1682. {previous instruction a jmp and no jump to this label processed yet}
  1683. Begin
  1684. hp := p;
  1685. Cnt := InstrCnt;
  1686. {continue until we find a jump to the label or a label which has already
  1687. been processed}
  1688. While GetNextInstruction(hp, hp) And
  1689. Not((hp^.typ = ait_instruction) And
  1690. (pai386(hp)^.is_jmp) and
  1691. (pasmlabel(pai386(hp)^.oper[0].sym)^.labelnr = Pai_Label(p)^.l^.labelnr)) And
  1692. Not((hp^.typ = ait_label) And
  1693. (LTable^[Pai_Label(hp)^.l^.labelnr-LoLab].RefsFound
  1694. = Pai_Label(hp)^.l^.RefCount) And
  1695. (LTable^[Pai_Label(hp)^.l^.labelnr-LoLab].JmpsProcessed > 0)) Do
  1696. Inc(Cnt);
  1697. If (hp^.typ = ait_label)
  1698. Then
  1699. {there's a processed label after the current one}
  1700. Begin
  1701. CurProp^.Regs := PaiPropBlock^[Cnt].Regs;
  1702. CurProp^.DirFlag := PaiPropBlock^[Cnt].DirFlag;
  1703. End
  1704. Else
  1705. {there's no label anymore after the current one, or they haven't been
  1706. processed yet}
  1707. Begin
  1708. GetLastInstruction(p, hp);
  1709. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1710. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1711. DestroyAllRegs(PPaiProp(hp^.OptInfo))
  1712. End
  1713. End
  1714. {$EndIf AnalyzeLoops}
  1715. Else
  1716. {not all references to this label have been found, so destroy all registers}
  1717. Begin
  1718. GetLastInstruction(p, hp);
  1719. CurProp^.Regs := PPaiProp(hp^.OptInfo)^.Regs;
  1720. CurProp^.DirFlag := PPaiProp(hp^.OptInfo)^.DirFlag;
  1721. DestroyAllRegs(CurProp)
  1722. End;
  1723. End;
  1724. {$EndIf JumpAnal}
  1725. {$ifdef GDB}
  1726. ait_stabs, ait_stabn, ait_stab_function_name:;
  1727. {$endif GDB}
  1728. ait_instruction:
  1729. Begin
  1730. if pai386(p)^.is_jmp then
  1731. begin
  1732. {$IfNDef JumpAnal}
  1733. ;
  1734. {$Else JumpAnal}
  1735. With LTable^[pasmlabel(pai386(p)^.oper[0].sym)^.labelnr-LoLab] Do
  1736. If (RefsFound = pasmlabel(pai386(p)^.oper[0].sym)^.RefCount) Then
  1737. Begin
  1738. If (InstrCnt < InstrNr)
  1739. Then
  1740. {forward jump}
  1741. If (JmpsProcessed = 0) Then
  1742. {no jump to this label has been processed yet}
  1743. Begin
  1744. PaiPropBlock^[InstrNr].Regs := CurProp^.Regs;
  1745. PaiPropBlock^[InstrNr].DirFlag := CurProp^.DirFlag;
  1746. Inc(JmpsProcessed);
  1747. End
  1748. Else
  1749. Begin
  1750. For TmpReg := R_EAX to R_EDI Do
  1751. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1752. CurProp^.Regs[TmpReg].WState) Then
  1753. DestroyReg(@PaiPropBlock^[InstrNr], TmpReg);
  1754. Inc(JmpsProcessed);
  1755. End
  1756. {$ifdef AnalyzeLoops}
  1757. Else
  1758. { backward jump, a loop for example}
  1759. { If (JmpsProcessed > 0) Or
  1760. Not(GetLastInstruction(PaiObj, hp) And
  1761. (hp^.typ = ait_labeled_instruction) And
  1762. (pai386_labeled(hp)^.opcode = A_JMP))
  1763. Then}
  1764. {instruction prior to label is not a jmp, or at least one jump to the label
  1765. has yet been processed}
  1766. Begin
  1767. Inc(JmpsProcessed);
  1768. For TmpReg := R_EAX to R_EDI Do
  1769. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1770. CurProp^.Regs[TmpReg].WState)
  1771. Then
  1772. Begin
  1773. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1774. Cnt := InstrNr;
  1775. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1776. Begin
  1777. DestroyReg(@PaiPropBlock^[Cnt], TmpReg);
  1778. Inc(Cnt);
  1779. End;
  1780. While (Cnt <= InstrCnt) Do
  1781. Begin
  1782. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1783. Inc(Cnt)
  1784. End
  1785. End;
  1786. End
  1787. { Else }
  1788. {instruction prior to label is a jmp and no jumps to the label have yet been
  1789. processed}
  1790. { Begin
  1791. Inc(JmpsProcessed);
  1792. For TmpReg := R_EAX to R_EDI Do
  1793. Begin
  1794. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1795. Cnt := InstrNr;
  1796. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1797. Begin
  1798. PaiPropBlock^[Cnt].Regs[TmpReg] := CurProp^.Regs[TmpReg];
  1799. Inc(Cnt);
  1800. End;
  1801. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1802. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1803. Begin
  1804. DestroyReg(@PaiPropBlock^[Cnt], TmpReg);
  1805. Inc(Cnt);
  1806. End;
  1807. While (Cnt <= InstrCnt) Do
  1808. Begin
  1809. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1810. Inc(Cnt)
  1811. End
  1812. End
  1813. End}
  1814. {$endif AnalyzeLoops}
  1815. End;
  1816. {$EndIf JumpAnal}
  1817. end
  1818. else
  1819. begin
  1820. InstrProp := AsmInstr[Pai386(p)^.opcode];
  1821. Case Pai386(p)^.opcode Of
  1822. A_MOV, A_MOVZX, A_MOVSX:
  1823. Begin
  1824. Case Pai386(p)^.oper[0].typ Of
  1825. Top_Reg:
  1826. Case Pai386(p)^.oper[1].typ Of
  1827. Top_Reg:
  1828. Begin
  1829. DestroyReg(CurProp, Pai386(p)^.oper[1].reg);
  1830. ReadReg(CurProp, Pai386(p)^.oper[0].reg);
  1831. { CurProp^.Regs[Pai386(p)^.oper[1].reg] :=
  1832. CurProp^.Regs[Pai386(p)^.oper[0].reg];
  1833. If (CurProp^.Regs[Pai386(p)^.oper[1].reg].ModReg = R_NO) Then
  1834. CurProp^.Regs[Pai386(p)^.oper[1].reg].ModReg :=
  1835. Pai386(p)^.oper[0].reg;}
  1836. End;
  1837. Top_Ref:
  1838. Begin
  1839. ReadReg(CurProp, Pai386(p)^.oper[0].reg);
  1840. ReadRef(CurProp, Pai386(p)^.oper[1].ref);
  1841. DestroyRefs(p, Pai386(p)^.oper[1].ref^, Pai386(p)^.oper[0].reg);
  1842. End;
  1843. End;
  1844. Top_Ref:
  1845. Begin {destination is always a register in this case}
  1846. ReadRef(CurProp, Pai386(p)^.oper[0].ref);
  1847. ReadReg(CurProp, Pai386(p)^.oper[1].reg);
  1848. TmpReg := Reg32(Pai386(p)^.oper[1].reg);
  1849. If RegInRef(TmpReg, Pai386(p)^.oper[0].ref^) And
  1850. (CurProp^.Regs[TmpReg].Typ = Con_Ref)
  1851. Then
  1852. Begin
  1853. With CurProp^.Regs[TmpReg] Do
  1854. Begin
  1855. IncState(WState);
  1856. {also store how many instructions are part of the sequence in the first
  1857. instructions PPaiProp, so it can be easily accessed from within
  1858. CheckSequence}
  1859. Inc(NrOfMods, NrOfInstrSinceLastMod[TmpReg]);
  1860. PPaiProp(Pai(StartMod)^.OptInfo)^.Regs[TmpReg].NrOfMods := NrOfMods;
  1861. NrOfInstrSinceLastMod[TmpReg] := 0;
  1862. End;
  1863. End
  1864. Else
  1865. Begin
  1866. DestroyReg(CurProp, TmpReg);
  1867. If Not(RegInRef(TmpReg, Pai386(p)^.oper[0].ref^)) Then
  1868. With CurProp^.Regs[TmpReg] Do
  1869. Begin
  1870. Typ := Con_Ref;
  1871. StartMod := p;
  1872. NrOfMods := 1;
  1873. End
  1874. End;
  1875. {$ifdef StateDebug}
  1876. hp := new(pai_asm_comment,init(strpnew(att_reg2str[TmpReg]+': '+tostr(CurProp^.Regs[TmpReg].WState))));
  1877. InsertLLItem(AsmL, p, p^.next, hp);
  1878. {$endif StateDebug}
  1879. End;
  1880. Top_Const:
  1881. Begin
  1882. Case Pai386(p)^.oper[1].typ Of
  1883. Top_Reg:
  1884. Begin
  1885. TmpReg := Reg32(Pai386(p)^.oper[1].reg);
  1886. With CurProp^.Regs[TmpReg] Do
  1887. Begin
  1888. DestroyReg(CurProp, TmpReg);
  1889. typ := Con_Const;
  1890. StartMod := p;
  1891. End
  1892. End;
  1893. Top_Ref:
  1894. Begin
  1895. ReadRef(CurProp, Pai386(p)^.oper[1].ref);
  1896. DestroyRefs(P, Pai386(p)^.oper[1].ref^, R_NO);
  1897. End;
  1898. End;
  1899. End;
  1900. End;
  1901. End;
  1902. A_IMUL:
  1903. Begin
  1904. ReadOp(CurProp, Pai386(p)^.oper[0]);
  1905. ReadOp(CurProp, Pai386(p)^.oper[1]);
  1906. If (Pai386(p)^.oper[2].typ = top_none) Then
  1907. If (Pai386(p)^.oper[1].typ = top_none) Then
  1908. Begin
  1909. DestroyReg(CurProp, R_EAX);
  1910. DestroyReg(CurProp, R_EDX)
  1911. End
  1912. Else
  1913. {$ifdef arithopt}
  1914. AddInstr2OpContents(Pai386(p), Pai386(p)^.oper[1])
  1915. {$else arithopt}
  1916. DestroyOp(p, Pai386(p)^.oper[1])
  1917. {$endif arithopt}
  1918. Else
  1919. {$ifdef arithopt}
  1920. AddInstr2OpContents(Pai386(p), Pai386(p)^.oper[2]);
  1921. {$else arithopt}
  1922. DestroyOp(p, Pai386(p)^.oper[2]);
  1923. {$endif arithopt}
  1924. End;
  1925. A_XOR:
  1926. Begin
  1927. ReadOp(CurProp, Pai386(p)^.oper[0]);
  1928. ReadOp(CurProp, Pai386(p)^.oper[1]);
  1929. If (Pai386(p)^.oper[0].typ = top_reg) And
  1930. (Pai386(p)^.oper[1].typ = top_reg) And
  1931. (Pai386(p)^.oper[0].reg = Pai386(p)^.oper[1].reg)
  1932. Then
  1933. Begin
  1934. DestroyReg(CurProp, Pai386(p)^.oper[0].reg);
  1935. CurProp^.Regs[Reg32(Pai386(p)^.oper[0].reg)].typ := Con_Const;
  1936. CurProp^.Regs[Reg32(Pai386(p)^.oper[0].reg)].StartMod := Pointer(0)
  1937. End
  1938. Else
  1939. DestroyOp(p, Pai386(p)^.oper[1]);
  1940. End
  1941. Else
  1942. Begin
  1943. Cnt := 1;
  1944. While (Cnt <= MaxCh) And
  1945. (InstrProp.Ch[Cnt] <> C_None) Do
  1946. Begin
  1947. Case InstrProp.Ch[Cnt] Of
  1948. C_REAX..C_REDI: ReadReg(CurProp,TCh2Reg(InstrProp.Ch[Cnt]));
  1949. C_WEAX..C_RWEDI:
  1950. Begin
  1951. If (InstrProp.Ch[Cnt] >= C_RWEAX) Then
  1952. ReadReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]));
  1953. DestroyReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]));
  1954. End;
  1955. {$ifdef arithopt}
  1956. C_MEAX..C_MEDI:
  1957. AddInstr2RegContents({$ifdef statedebug} asml, {$endif}
  1958. Pai386(p),
  1959. TCh2Reg(InstrProp.Ch[Cnt]));
  1960. {$endif arithopt}
  1961. C_CDirFlag: CurProp^.DirFlag := F_NotSet;
  1962. C_SDirFlag: CurProp^.DirFlag := F_Set;
  1963. C_Rop1: ReadOp(CurProp, Pai386(p)^.oper[0]);
  1964. C_Rop2: ReadOp(CurProp, Pai386(p)^.oper[1]);
  1965. C_ROp3: ReadOp(CurProp, Pai386(p)^.oper[2]);
  1966. C_Wop1..C_RWop1:
  1967. Begin
  1968. If (InstrProp.Ch[Cnt] in [C_RWop1]) Then
  1969. ReadOp(CurProp, Pai386(p)^.oper[0]);
  1970. DestroyOp(p, Pai386(p)^.oper[0]);
  1971. End;
  1972. {$ifdef arithopt}
  1973. C_Mop1:
  1974. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1975. Pai386(p), Pai386(p)^.oper[0]);
  1976. {$endif arithopt}
  1977. C_Wop2..C_RWop2:
  1978. Begin
  1979. If (InstrProp.Ch[Cnt] = C_RWop2) Then
  1980. ReadOp(CurProp, Pai386(p)^.oper[1]);
  1981. DestroyOp(p, Pai386(p)^.oper[1]);
  1982. End;
  1983. {$ifdef arithopt}
  1984. C_Mop2:
  1985. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1986. Pai386(p), Pai386(p)^.oper[1]);
  1987. {$endif arithopt}
  1988. C_WOp3..C_RWOp3:
  1989. Begin
  1990. If (InstrProp.Ch[Cnt] = C_RWOp3) Then
  1991. ReadOp(CurProp, Pai386(p)^.oper[2]);
  1992. DestroyOp(p, Pai386(p)^.oper[2]);
  1993. End;
  1994. {$ifdef arithopt}
  1995. C_Mop3:
  1996. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  1997. Pai386(p), Pai386(p)^.oper[2]);
  1998. {$endif arithopt}
  1999. C_WMemEDI:
  2000. Begin
  2001. ReadReg(CurProp, R_EDI);
  2002. FillChar(TmpRef, SizeOf(TmpRef), 0);
  2003. TmpRef.Base := R_EDI;
  2004. DestroyRefs(p, TmpRef, R_NO)
  2005. End;
  2006. C_RFlags, C_WFlags, C_RWFlags, C_FPU:
  2007. Else
  2008. Begin
  2009. DestroyAllRegs(CurProp);
  2010. End;
  2011. End;
  2012. Inc(Cnt);
  2013. End
  2014. End;
  2015. end;
  2016. End;
  2017. End
  2018. Else
  2019. Begin
  2020. DestroyAllRegs(CurProp);
  2021. End;
  2022. End;
  2023. Inc(InstrCnt);
  2024. GetNextInstruction(p, p);
  2025. End;
  2026. End;
  2027. Function InitDFAPass2(BlockStart, BlockEnd: Pai): Boolean;
  2028. {reserves memory for the PPaiProps in one big memory block when not using
  2029. TP, returns False if not enough memory is available for the optimizer in all
  2030. cases}
  2031. Var p: Pai;
  2032. Count: Longint;
  2033. { TmpStr: String; }
  2034. Begin
  2035. P := BlockStart;
  2036. SkipHead(P);
  2037. NrOfPaiObjs := 0;
  2038. While (P <> BlockEnd) Do
  2039. Begin
  2040. {$IfDef JumpAnal}
  2041. Case P^.Typ Of
  2042. ait_label:
  2043. Begin
  2044. If (Pai_Label(p)^.l^.is_used) Then
  2045. LTable^[Pai_Label(P)^.l^.labelnr-LoLab].InstrNr := NrOfPaiObjs
  2046. End;
  2047. ait_instruction:
  2048. begin
  2049. if pai386(p)^.is_jmp then
  2050. begin
  2051. If (pasmlabel(pai386(P)^.oper[0].sym)^.labelnr >= LoLab) And
  2052. (pasmlabel(pai386(P)^.oper[0].sym)^.labelnr <= HiLab) Then
  2053. Inc(LTable^[pasmlabel(pai386(P)^.oper[0].sym)^.labelnr-LoLab].RefsFound);
  2054. end;
  2055. end;
  2056. { ait_instruction:
  2057. Begin
  2058. If (Pai386(p)^.opcode = A_PUSH) And
  2059. (Pai386(p)^.oper[0].typ = top_symbol) And
  2060. (PCSymbol(Pai386(p)^.oper[0])^.offset = 0) Then
  2061. Begin
  2062. TmpStr := StrPas(PCSymbol(Pai386(p)^.oper[0])^.symbol);
  2063. If}
  2064. End;
  2065. {$EndIf JumpAnal}
  2066. Inc(NrOfPaiObjs);
  2067. GetNextInstruction(p, p);
  2068. End;
  2069. {$IfDef TP}
  2070. If (MemAvail < (SizeOf(TPaiProp)*NrOfPaiObjs))
  2071. Or (NrOfPaiObjs = 0)
  2072. {this doesn't have to be one contiguous block}
  2073. Then InitDFAPass2 := False
  2074. Else InitDFAPass2 := True;
  2075. {$Else}
  2076. {Uncomment the next line to see how much memory the reloading optimizer needs}
  2077. { Writeln((NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4)));}
  2078. {no need to check mem/maxavail, we've got as much virtual memory as we want}
  2079. If NrOfPaiObjs <> 0 Then
  2080. Begin
  2081. InitDFAPass2 := True;
  2082. GetMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4));
  2083. p := BlockStart;
  2084. SkipHead(p);
  2085. For Count := 1 To NrOfPaiObjs Do
  2086. Begin
  2087. PPaiProp(p^.OptInfo) := @PaiPropBlock^[Count];
  2088. GetNextInstruction(p, p);
  2089. End;
  2090. End
  2091. Else InitDFAPass2 := False;
  2092. {$EndIf TP}
  2093. End;
  2094. Function DFAPass2(
  2095. {$ifdef statedebug}
  2096. AsmL: PAasmOutPut;
  2097. {$endif statedebug}
  2098. BlockStart, BlockEnd: Pai): Boolean;
  2099. Begin
  2100. If InitDFAPass2(BlockStart, BlockEnd) Then
  2101. Begin
  2102. DoDFAPass2(
  2103. {$ifdef statedebug}
  2104. asml,
  2105. {$endif statedebug}
  2106. BlockStart, BlockEnd);
  2107. DFAPass2 := True
  2108. End
  2109. Else DFAPass2 := False;
  2110. End;
  2111. Procedure ShutDownDFA;
  2112. Begin
  2113. If LabDif <> 0 Then
  2114. FreeMem(LTable, LabDif*SizeOf(TLabelTableItem));
  2115. End;
  2116. End.
  2117. {
  2118. $Log$
  2119. Revision 1.54 1999-08-05 15:01:52 jonas
  2120. * fix in -darithopt code (sometimes crashed on 8/16bit regs)
  2121. Revision 1.53 1999/08/04 00:22:59 florian
  2122. * renamed i386asm and i386base to cpuasm and cpubase
  2123. Revision 1.52 1999/08/02 14:35:21 jonas
  2124. * bugfix in DestroyRefs
  2125. Revision 1.51 1999/08/02 12:12:53 jonas
  2126. * also add arithmetic operations to instruction sequences contained in registers
  2127. (compile with -darithopt, very nice!)
  2128. Revision 1.50 1999/07/30 18:18:51 jonas
  2129. * small bugfix in instructionsequal
  2130. * small bugfix in reginsequence
  2131. * made regininstruction a bit more logical
  2132. Revision 1.48 1999/07/01 18:21:21 jonas
  2133. * removed unused AsmL parameter from FindLoHiLabels
  2134. Revision 1.47 1999/05/27 19:44:24 peter
  2135. * removed oldasm
  2136. * plabel -> pasmlabel
  2137. * -a switches to source writing automaticly
  2138. * assembler readers OOPed
  2139. * asmsymbol automaticly external
  2140. * jumptables and other label fixes for asm readers
  2141. Revision 1.46 1999/05/08 20:40:02 jonas
  2142. * seperate OPTimizer INFO pointer field in tai object
  2143. * fix to GetLastInstruction that sometimes caused a crash
  2144. Revision 1.45 1999/05/01 13:48:37 peter
  2145. * merged nasm compiler
  2146. Revision 1.6 1999/04/18 17:57:21 jonas
  2147. * fix for crash when the first instruction of a sequence that gets
  2148. optimized is removed (this situation can't occur aymore now)
  2149. Revision 1.5 1999/04/16 11:49:50 peter
  2150. + tempalloc
  2151. + -at to show temp alloc info in .s file
  2152. Revision 1.4 1999/04/14 09:07:42 peter
  2153. * asm reader improvements
  2154. Revision 1.3 1999/03/31 13:55:29 peter
  2155. * assembler inlining working for ag386bin
  2156. Revision 1.2 1999/03/29 16:05:46 peter
  2157. * optimizer working for ag386bin
  2158. Revision 1.1 1999/03/26 00:01:10 peter
  2159. * first things for optimizer (compiles but cycle crashes)
  2160. Revision 1.39 1999/02/26 00:48:18 peter
  2161. * assembler writers fixed for ag386bin
  2162. Revision 1.38 1999/02/25 21:02:34 peter
  2163. * ag386bin updates
  2164. + coff writer
  2165. Revision 1.37 1999/02/22 02:15:20 peter
  2166. * updates for ag386bin
  2167. Revision 1.36 1999/01/20 17:41:26 jonas
  2168. * small bugfix (memory corruption could occur when certain fpu instructions
  2169. were encountered)
  2170. Revision 1.35 1999/01/08 12:39:22 florian
  2171. Changes of Alexander Stohr integrated:
  2172. + added KNI opcodes
  2173. + added KNI registers
  2174. + added 3DNow! opcodes
  2175. + added 64 bit and 128 bit register flags
  2176. * translated a few comments into english
  2177. Revision 1.34 1998/12/29 18:48:19 jonas
  2178. + optimize pascal code surrounding assembler blocks
  2179. Revision 1.33 1998/12/17 16:37:38 jonas
  2180. + extra checks in RegsEquivalent so some more optimizations can be done (which
  2181. where disabled by the second fix from revision 1.22)
  2182. Revision 1.32 1998/12/15 19:33:58 jonas
  2183. * uncommented OpsEqual & added to interface because popt386 uses it now
  2184. Revision 1.31 1998/12/11 00:03:13 peter
  2185. + globtype,tokens,version unit splitted from globals
  2186. Revision 1.30 1998/12/02 16:23:39 jonas
  2187. * changed "if longintvar in set" to case or "if () or () .." statements
  2188. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  2189. Revision 1.29 1998/11/26 21:45:31 jonas
  2190. - removed A_CLTD opcode (use A_CDQ instead)
  2191. * changed cbw, cwde and cwd to cbtw, cwtl and cwtd in att_.oper[1]str array
  2192. * in daopt386: adapted AsmInstr array to reflect changes + fixed line too long
  2193. Revision 1.27 1998/11/24 19:47:22 jonas
  2194. * fixed problems posible with 3 operand instructions
  2195. Revision 1.26 1998/11/24 12:50:09 peter
  2196. * fixed crash
  2197. Revision 1.25 1998/11/18 17:58:22 jonas
  2198. + gathering of register reading data, nowhere used yet (necessary for instruction scheduling)
  2199. Revision 1.24 1998/11/13 10:13:44 peter
  2200. + cpuid,emms support for asm readers
  2201. Revision 1.23 1998/11/09 19:40:46 jonas
  2202. * fixed comments from last commit (apparently there's still a 255 char limit :( )
  2203. Revision 1.22 1998/11/09 19:33:40 jonas
  2204. * changed specific bugfix (which was actually wrong implemented, but
  2205. did the right thing in most cases nevertheless) to general bugfix
  2206. * fixed bug that caused
  2207. mov (ebp), edx mov (ebp), edx
  2208. mov (edx), edx mov (edx), edx
  2209. ... being changed to ...
  2210. mov (ebp), edx mov edx, eax
  2211. mov (eax), eax
  2212. but this disabled another small correct optimization...
  2213. Revision 1.21 1998/11/02 23:17:49 jonas
  2214. * fixed bug shown in sortbug program from fpc-devel list
  2215. Revision 1.20 1998/10/22 13:24:51 jonas
  2216. * changed TRegSet to a small set
  2217. Revision 1.19 1998/10/20 09:29:24 peter
  2218. * bugfix so that code like
  2219. movl 48(%esi),%esi movl 48(%esi),%esi
  2220. pushl %esi doesn't get changed to pushl %esi
  2221. movl 48(%esi),%edi movl %esi,%edi
  2222. Revision 1.18 1998/10/07 16:27:02 jonas
  2223. * changed state to WState (WriteState), added RState for future use in
  2224. instruction scheduling
  2225. * RegAlloc data from the CG is now completely being patched and corrected (I
  2226. think)
  2227. Revision 1.17 1998/10/02 17:30:20 jonas
  2228. * small patches to regdealloc data
  2229. Revision 1.16 1998/10/01 20:21:47 jonas
  2230. * inter-register CSE, still requires some tweaks (peepholeoptpass2, better RegAlloc)
  2231. Revision 1.15 1998/09/20 18:00:20 florian
  2232. * small compiling problems fixed
  2233. Revision 1.14 1998/09/20 17:12:36 jonas
  2234. * small fix for uncertain optimizations & more cleaning up
  2235. Revision 1.12 1998/09/16 18:00:01 jonas
  2236. * optimizer now completely dependant on GetNext/GetLast instruction, works again with -dRegAlloc
  2237. Revision 1.11 1998/09/15 14:05:27 jonas
  2238. * fixed optimizer incompatibilities with freelabel code in psub
  2239. Revision 1.10 1998/09/09 15:33:58 peter
  2240. * removed warnings
  2241. Revision 1.9 1998/09/03 16:24:51 florian
  2242. * bug of type conversation from dword to real fixed
  2243. * bug fix of Jonas applied
  2244. Revision 1.8 1998/08/28 10:56:59 peter
  2245. * removed warnings
  2246. Revision 1.7 1998/08/19 16:07:44 jonas
  2247. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  2248. Revision 1.6 1998/08/10 14:49:57 peter
  2249. + localswitches, moduleswitches, globalswitches splitting
  2250. Revision 1.5 1998/08/09 13:56:24 jonas
  2251. * small bugfix for uncertain optimizations in DestroyRefs
  2252. Revision 1.4 1998/08/06 19:40:25 jonas
  2253. * removed $ before and after Log in comment
  2254. Revision 1.3 1998/08/05 16:00:14 florian
  2255. * some fixes for ansi strings
  2256. * log to Log changed
  2257. }