daopt386.pas 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361
  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,i386;
  27. Type
  28. TRegArray = Array[R_EAX..R_BL] of TRegister;
  29. TRegSet = Set of R_EAX..R_BL;
  30. TRegInfo = Record
  31. NewRegsEncountered, OldRegsEncountered: TRegSet;
  32. RegsLoadedForRef: TRegSet;
  33. New2OldReg: TRegArray;
  34. End;
  35. {possible actions on an operand: read, write or modify (= read & write)}
  36. TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
  37. {*********************** Procedures and Functions ************************}
  38. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  39. Function Reg32(Reg: TRegister): TRegister;
  40. Function RefsEquivalent(Const R1, R2: TReference; Var RegInfo: TRegInfo; OpAct: TOpAction): Boolean;
  41. Function RefsEqual(Const R1, R2: TReference): Boolean;
  42. Function IsGP32Reg(Reg: TRegister): Boolean;
  43. Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
  44. Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
  45. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  46. Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
  47. Function GetLastInstruction(Current: Pai; Var Last: Pai): Boolean;
  48. Procedure SkipHead(var P: Pai);
  49. Procedure UpdateUsedRegs(Var UsedRegs: TRegSet; p: Pai);
  50. Function RegsEquivalent(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo; OpAct: TopAction): Boolean;
  51. Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
  52. Function OpsEqual(typ: Longint; op1, op2: Pointer): Boolean;
  53. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  54. Function DFAPass2(AsmL: PAasmOutput; BlockStart, BlockEnd: Pai): Boolean;
  55. Procedure ShutDownDFA;
  56. Function FindLabel(L: PLabel; Var hp: Pai): Boolean;
  57. {Procedure FindLoHiLabels(AsmL: PAasmOutput; Var LoLab, HiLab, LabDif: Longint);}
  58. {******************************* Constants *******************************}
  59. Const
  60. {ait_* types which don't result in executable code or which don't influence
  61. the way the program runs/behaves}
  62. SkipInstr = [ait_comment, ait_align, ait_symbol
  63. {$ifdef GDB}
  64. ,ait_stabs, ait_stabn, ait_stab_function_name
  65. {$endif GDB}
  66. ,ait_regalloc, ait_regdealloc
  67. ];
  68. {the maximum number of things (registers, memory, ...) a single instruction
  69. changes}
  70. MaxCh = 3;
  71. {Possible register content types}
  72. con_Unknown = 0;
  73. con_ref = 1;
  74. con_const = 2;
  75. {********************************* Types *********************************}
  76. Type
  77. {What an instruction can change}
  78. TChange = (C_None,
  79. {Read from a register}
  80. C_REAX, C_RECX, C_REDX, C_REBX, C_RESP, C_REBP, C_RESI, C_REDI,
  81. {write from a register}
  82. C_WEAX, C_WECX, C_WEDX, C_WEBX, C_WESP, C_WEBP, C_WESI, C_WEDI,
  83. {read and write from/to a register}
  84. C_RWEAX, C_RWECX, C_RWEDX, C_RWEBX, C_RWESP, C_RWEBP, C_RWESI, C_RWEDI,
  85. C_CDirFlag {clear direction flag}, C_SDirFlag {set dir flag},
  86. C_RFlags, C_WFlags, C_RWFlags, C_FPU,
  87. C_ROp1, C_WOp1, C_RWOp1,
  88. C_ROp2, C_WOp2, C_RWOp2,
  89. C_ROp3, C_WOp3, C_RWOp3,
  90. C_WMemEDI,
  91. C_All);
  92. {the possible states of a flag}
  93. TFlagContents = (F_Unknown, F_NotSet, F_Set);
  94. {the properties of a cpu instruction}
  95. TAsmInstrucProp = Record
  96. {how many things it changes}
  97. { NCh: Byte;}
  98. {and what it changes}
  99. Ch: Array[1..MaxCh] of TChange;
  100. End;
  101. TContent = Record
  102. {start and end of block instructions that defines the
  103. content of this register. If Typ = con_const, then
  104. Longint(StartMod) = value of the constant)}
  105. StartMod: Pointer;
  106. {starts at 0, gets increased everytime the register is written to}
  107. WState: Byte;
  108. {starts at 0, gets increased everytime the register is read from}
  109. RState: Byte;
  110. {how many instructions starting with StarMod does the block consist of}
  111. NrOfMods: Byte;
  112. {the type of the content of the register: unknown, memory, constant}
  113. Typ: Byte;
  114. End;
  115. {Contents of the integer registers}
  116. TRegContent = Array[R_EAX..R_EDI] Of TContent;
  117. {contents of the FPU registers}
  118. TRegFPUContent = Array[R_ST..R_ST7] Of TContent;
  119. {information record with the contents of every register. Every Pai object
  120. gets one of these assigned: a pointer to it is stored in the Line field and
  121. the original line number is stored in LineSave}
  122. TPaiProp = Record
  123. Regs: TRegContent;
  124. { FPURegs: TRegFPUContent;} {currently not yet used}
  125. LineSave: Longint;
  126. {allocated Registers}
  127. UsedRegs: TRegSet;
  128. {status of the direction flag}
  129. DirFlag: TFlagContents;
  130. {can this instruction be removed?}
  131. CanBeRemoved: Boolean;
  132. End;
  133. PPaiProp = ^TPaiProp;
  134. {$IfNDef TP}
  135. TPaiPropBlock = Array[1..250000] Of TPaiProp;
  136. PPaiPropBlock = ^TPaiPropBlock;
  137. {$EndIf TP}
  138. TInstrSinceLastMod = Array[R_EAX..R_EDI] Of Byte;
  139. TLabelTableItem = Record
  140. PaiObj: Pai;
  141. {$IfDef JumpAnal}
  142. InstrNr: Longint;
  143. RefsFound: Word;
  144. JmpsProcessed: Word
  145. {$EndIf JumpAnal}
  146. End;
  147. {$IfDef tp}
  148. TLabelTable = Array[0..10000] Of TLabelTableItem;
  149. {$Else tp}
  150. TLabelTable = Array[0..2500000] Of TLabelTableItem;
  151. {$Endif tp}
  152. PLabelTable = ^TLabelTable;
  153. TwoWords = Record
  154. Word1, Word2: Word;
  155. End;
  156. {******************************* Variables *******************************}
  157. Var
  158. {the amount of PaiObjects in the current assembler list}
  159. NrOfPaiObjs: Longint;
  160. {$IfNDef TP}
  161. {Array which holds all TPaiProps}
  162. PaiPropBlock: PPaiPropBlock;
  163. {$EndIf TP}
  164. LoLab, HiLab, LabDif: Longint;
  165. LTable: PLabelTable;
  166. {*********************** End of Interface section ************************}
  167. Implementation
  168. Uses globals, systems, strings, verbose, hcodegen,
  169. {$ifdef i386}
  170. pass_2;
  171. {$endif i386}
  172. Const AsmInstr: Array[tasmop] Of TAsmInstrucProp = (
  173. {MOV} (Ch: (C_WOp2, C_ROp1, C_None)),
  174. {MOVZX} (Ch: (C_WOp2, C_ROp1, C_None)),
  175. {MOVSX} (Ch: (C_WOp2, C_ROp1, C_None)),
  176. {LABEL} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  177. {ADD} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  178. {CALL} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  179. {IDIV} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  180. {IMUL} (Ch: (C_RWEAX, C_WEDX, C_WFlags)), {handled separately, because several forms exist}
  181. {JMP} (Ch: (C_None, C_None, C_None)),
  182. {LEA} (Ch: (C_WOp2, C_ROp1, C_None)),
  183. {MUL} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  184. {NEG} (Ch: (C_RWOp1, C_None, C_None)),
  185. {NOT} (Ch: (C_RWOp1, C_WFlags, C_None)),
  186. {POP} (Ch: (C_WOp1, C_RWESP, C_None)),
  187. {POPAD} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  188. {PUSH} (Ch: (C_RWESP, C_None, C_None)),
  189. {PUSHAD} (Ch: (C_RWESP, C_None, C_None)),
  190. {RET} (Ch: (C_ALL, C_None, C_None)),
  191. {SUB} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  192. {XCHG} (Ch: (C_RWOp1, C_RWOp2, C_None)), {(might be) handled seperately}
  193. {XOR} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  194. {FILD} (Ch: (C_FPU, C_None, C_None)),
  195. {CMP} (Ch: (C_WFlags, C_None, C_None)),
  196. {JZ} (Ch: (C_RFlags, C_None, C_None)),
  197. {INC} (Ch: (C_RWOp1, C_WFlags, C_None)),
  198. {DEC} (Ch: (C_RWOp1, C_WFlags, C_None)),
  199. {SETE} (Ch: (C_WOp1, C_RFlags, C_None)),
  200. {SETNE} (Ch: (C_WOp1, C_RFlags, C_None)),
  201. {SETL} (Ch: (C_WOp1, C_RFlags, C_None)),
  202. {SETG} (Ch: (C_WOp1, C_RFlags, C_None)),
  203. {SETLE} (Ch: (C_WOp1, C_RFlags, C_None)),
  204. {SETGE} (Ch: (C_WOp1, C_RFlags, C_None)),
  205. {JE} (Ch: (C_RFlags, C_None, C_None)),
  206. {JNE} (Ch: (C_RFlags, C_None, C_None)),
  207. {JL} (Ch: (C_RFlags, C_None, C_None)),
  208. {JG} (Ch: (C_RFlags, C_None, C_None)),
  209. {JLE} (Ch: (C_RFlags, C_None, C_None)),
  210. {JGE} (Ch: (C_RFlags, C_None, C_None)),
  211. {OR} (Ch: (C_RWOp2, C_WFlags, C_None)),
  212. {FLD} (Ch: (C_ROp1, C_FPU, C_None)),
  213. {FADD} (Ch: (C_FPU, C_None, C_None)),
  214. {FMUL} (Ch: (C_FPU, C_None, C_None)),
  215. {FSUB} (Ch: (C_FPU, C_None, C_None)),
  216. {FDIV} (Ch: (C_FPU, C_None, C_None)),
  217. {FCHS} (Ch: (C_FPU, C_None, C_None)),
  218. {FLD1} (Ch: (C_FPU, C_None, C_None)),
  219. {FIDIV} (Ch: (C_FPU, C_None, C_None)),
  220. {JNZ} (Ch: (C_RFlags, C_None, C_None)),
  221. {FSTP} (Ch: (C_WOp1, C_FPU, C_None)),
  222. {AND} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  223. {JNO} (Ch: (C_RFlags, C_None, C_None)),
  224. {NOTH} (Ch: (C_None, C_None, C_None)), {***???***}
  225. {NONE} (Ch: (C_None, C_None, C_None)),
  226. {ENTER} (Ch: (C_RWESP, C_None, C_None)),
  227. {LEAVE} (Ch: (C_RWESP, C_None, C_None)),
  228. {CLD} (Ch: (C_CDirFlag, C_None, C_None)),
  229. {MOVS} (Ch: (C_RWESI, C_RWEDI, C_WMemEDI)),
  230. {REP} (Ch: (C_RWECX, C_RFlags, C_None)),
  231. {SHL} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  232. {SHR} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  233. {BOUND} (Ch: (C_ROp1, C_None, C_None)),
  234. {JNS} (Ch: (C_RFlags, C_None, C_None)),
  235. {JS} (Ch: (C_RFlags, C_None, C_None)),
  236. {JO} (Ch: (C_RFlags, C_None, C_None)),
  237. {SAR} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  238. {TEST} (Ch: (C_WFlags, C_ROp1, C_ROp2)),
  239. {FCOM} (Ch: (C_FPU, C_None, C_None)),
  240. {FCOMP} (Ch: (C_FPU, C_None, C_None)),
  241. {FCOMPP} (Ch: (C_FPU, C_None, C_None)),
  242. {FXCH} (Ch: (C_FPU, C_None, C_None)),
  243. {FADDP} (Ch: (C_FPU, C_None, C_None)),
  244. {FMULP} (Ch: (C_FPU, C_None, C_None)),
  245. {FSUBP} (Ch: (C_FPU, C_None, C_None)),
  246. {FDIVP} (Ch: (C_FPU, C_None, C_None)),
  247. {FNSTS} (Ch: (C_WOp1, C_None, C_None)),
  248. {SAHF} (Ch: (C_WFlags, C_REAX, C_None)),
  249. {FDIVRP} (Ch: (C_FPU, C_None, C_None)),
  250. {FSUBRP} (Ch: (C_FPU, C_None, C_None)),
  251. {SETC} (Ch: (C_WOp1, C_RFlags, C_None)),
  252. {SETNC} (Ch: (C_WOp1, C_RFlags, C_None)),
  253. {JC} (Ch: (C_None, C_RFlags, C_None)),
  254. {JNC} (Ch: (C_RFlags, C_None, C_None)),
  255. {JA} (Ch: (C_RFlags, C_None, C_None)),
  256. {JAE} (Ch: (C_RFlags, C_None, C_None)),
  257. {JB} (Ch: (C_RFlags, C_None, C_None)),
  258. {JBE} (Ch: (C_RFlags, C_None, C_None)),
  259. {SETA} (Ch: (C_WOp1, C_RFlags, C_None)),
  260. {SETAE} (Ch: (C_WOp1, C_RFlags, C_None)),
  261. {SETB} (Ch: (C_WOp1, C_RFlags, C_None)),
  262. {SETBE} (Ch: (C_WOp1, C_RFlags, C_None)),
  263. {AAA} (Ch: (C_RWEAX, C_WFlags, C_None)),
  264. {AAD} (Ch: (C_RWEAX, C_WFlags, C_None)),
  265. {AAM} (Ch: (C_RWEAX, C_WFlags, C_None)),
  266. {AAS} (Ch: (C_RWEAX, C_WFlags, C_None)),
  267. {CBW} (Ch: (C_RWEAX, C_None, C_None)),
  268. {CDQ} (Ch: (C_RWEAX, C_WEDX, C_None)),
  269. {CLC} (Ch: (C_WFlags, C_None, C_None)),
  270. {CLI} (Ch: (C_WFlags, C_None, C_None)),
  271. {CLTS} (Ch: (C_None, C_None, C_None)),
  272. {CMC} (Ch: (C_WFlags, C_None, C_None)),
  273. {CWD} (Ch: (C_RWEAX, C_WEDX, C_None)),
  274. {CWDE} (Ch: (C_RWEAX, C_None, C_None)),
  275. {DAA} (Ch: (C_RWEAX, C_None, C_None)),
  276. {DAS} (Ch: (C_RWEAX, C_None, C_None)),
  277. {HLT} (Ch: (C_None, C_None, C_None)),
  278. {IRET} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  279. {LAHF} (Ch: (C_WEAX, C_RFlags, C_None)),
  280. {LODS} (Ch: (C_WEAX, C_RWESI, C_None)),
  281. {LOCK} (Ch: (C_None, C_None, C_None)),
  282. {NOP} (Ch: (C_None, C_None, C_None)),
  283. {PUSHA} (Ch: (C_ALL, C_None, C_None)), {not true, but a pushall is usually followed by an instruction that does, so
  284. it won hurt either}
  285. {PUSHF} (Ch: (C_RWESP, C_RFlags, C_None)),
  286. {PUSHFD} (Ch: (C_RWESP, C_RFlags, C_None)),
  287. {STC} (Ch: (C_WFlags, C_None, C_None)),
  288. {STD} (Ch: (C_SDirFlag, C_None, C_None)),
  289. {STI} (Ch: (C_WFlags, C_None, C_None)),
  290. {STOS} (Ch: (C_WMemEDI, C_RWEDI, C_REAX)),
  291. {WAIT} (Ch: (C_None, C_None, C_None)),
  292. {XLAT} (Ch: (C_WEAX, C_REBX, C_None)),
  293. {XLATB} (Ch: (C_WEAX, C_REBX, C_None)),
  294. {MOVSB} (Ch: (C_WOp2, C_ROp1, C_None)),
  295. {MOVSBL} (Ch: (C_WOp2, C_ROp1, C_None)),
  296. {MOVSBW} (Ch: (C_WOp2, C_ROp1, C_None)),
  297. {MOVSWL} (Ch: (C_WOp2, C_ROp1, C_None)),
  298. {MOVZB} (Ch: (C_WOp2, C_ROp1, C_None)),
  299. {MOVZWL} (Ch: (C_WOp2, C_ROp1, C_None)),
  300. {POPA} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  301. {IN} (Ch: (C_WOp2, C_ROp1, C_None)),
  302. {OUT} (Ch: (C_ROp1, C_ROp2, C_None)),
  303. {LDS} (Ch: (C_WOp2, C_None, C_None)),
  304. {LCS} (Ch: (C_WOp2, C_None, C_None)),
  305. {LES} (Ch: (C_WOp2, C_None, C_None)),
  306. {LFS} (Ch: (C_WOp2, C_None, C_None)),
  307. {LGS} (Ch: (C_WOp2, C_None, C_None)),
  308. {LSS} (Ch: (C_WOp2, C_None, C_None)),
  309. {POPF} (Ch: (C_RWESP, C_WFlags, C_None)),
  310. {SBB} (Ch: (C_RWOp2, C_ROp1, C_RWFlags)),
  311. {ADC} (Ch: (C_RWOp2, C_ROp1, C_RWFlags)),
  312. {DIV} (Ch: (C_RWEAX, C_WEDX, C_WFlags)),
  313. {ROR} (Ch: (C_RWOp2, C_ROp1, C_RWFlags)),
  314. {ROL} (Ch: (C_RWOp2, C_ROp1, C_RWFlags)),
  315. {RCL} (Ch: (C_RWOp2, C_ROp1, C_RWFlags)),
  316. {RCR} (Ch: (C_RWOp2, C_ROp1, C_RWFlags)),
  317. {SAL} (Ch: (C_RWOp2, C_ROp1, C_RWFlags)),
  318. {SHLD} (Ch: (C_RWOp3, C_RWFlags, C_ROp2)),
  319. {SHRD} (Ch: (C_RWOp3, C_RWFlags, C_ROp2)),
  320. {LCALL} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  321. {LJMP} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  322. {LRET} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  323. {JNAE} (Ch: (C_RFlags, C_None, C_None)),
  324. {JNB} (Ch: (C_RFlags, C_None, C_None)),
  325. {JNA} (Ch: (C_RFlags, C_None, C_None)),
  326. {JNBE} (Ch: (C_RFlags, C_None, C_None)),
  327. {JP} (Ch: (C_RFlags, C_None, C_None)),
  328. {JNP} (Ch: (C_RFlags, C_None, C_None)),
  329. {JPE} (Ch: (C_RFlags, C_None, C_None)),
  330. {JPO} (Ch: (C_RFlags, C_None, C_None)),
  331. {JNGE} (Ch: (C_RFlags, C_None, C_None)),
  332. {JNG} (Ch: (C_RFlags, C_None, C_None)),
  333. {JNL} (Ch: (C_RFlags, C_None, C_None)),
  334. {JNLE} (Ch: (C_RFlags, C_None, C_None)),
  335. {JCXZ} (Ch: (C_RECX, C_None, C_None)),
  336. {JECXZ} (Ch: (C_RECX, C_None, C_None)),
  337. {LOOP} (Ch: (C_RWECX, C_None, C_None)),
  338. {CMPS} (Ch: (C_RWESI, C_RWEDI, C_WFlags)),
  339. {INS} (Ch: (C_RWEDI, C_WMemEDI, C_None)),
  340. {OUTS} (Ch: (C_RWESI, C_None, C_None)),
  341. {SCAS} (Ch: (C_RWEDI, C_WFlags, C_None)),
  342. {BSF} (Ch: (C_WOp2, C_WFlags, C_ROp1)),
  343. {BSR} (Ch: (C_WOp2, C_WFlags, C_ROp1)),
  344. {BT} (Ch: (C_WFlags, C_ROp1, C_None)),
  345. {BTC} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  346. {BTR} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  347. {BTS} (Ch: (C_RWOp2, C_ROp1, C_WFlags)),
  348. {INT} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  349. {INT3} (Ch: (C_None, C_None, C_None)),
  350. {INTO} (Ch: (C_All, C_None, C_None)), {don't know value of any register}
  351. {BOUNDL} (Ch: (C_ROp1, C_None, C_None)),
  352. {BOUNDW} (Ch: (C_ROp1, C_None, C_None)),
  353. {LOOPZ} (Ch: (C_RWECX, C_RFlags, C_None)),
  354. {LOOPE} (Ch: (C_RWECX, C_RFlags, C_None)),
  355. {LOOPNZ} (Ch: (C_RWECX, C_RFlags, C_None)),
  356. {LOOPNE} (Ch: (C_RWECX, C_RFlags, C_None)),
  357. {SETO} (Ch: (C_WOp1, C_RFlags, C_None)),
  358. {SETNO} (Ch: (C_WOp1, C_RFlags, C_None)),
  359. {SETNAE} (Ch: (C_WOp1, C_RFlags, C_None)),
  360. {SETNB} (Ch: (C_WOp1, C_RFlags, C_None)),
  361. {SETZ} (Ch: (C_WOp1, C_RFlags, C_None)),
  362. {SETNZ} (Ch: (C_WOp1, C_RFlags, C_None)),
  363. {SETNA} (Ch: (C_WOp1, C_RFlags, C_None)),
  364. {SETNBE} (Ch: (C_WOp1, C_RFlags, C_None)),
  365. {SETS} (Ch: (C_WOp1, C_RFlags, C_None)),
  366. {SETNS} (Ch: (C_WOp1, C_RFlags, C_None)),
  367. {SETP} (Ch: (C_WOp1, C_RFlags, C_None)),
  368. {SETPE} (Ch: (C_WOp1, C_RFlags, C_None)),
  369. {SETNP} (Ch: (C_WOp1, C_RFlags, C_None)),
  370. {SETPO} (Ch: (C_WOp1, C_RFlags, C_None)),
  371. {SETNGE} (Ch: (C_WOp1, C_RFlags, C_None)),
  372. {SETNL} (Ch: (C_WOp1, C_RFlags, C_None)),
  373. {SETNG} (Ch: (C_WOp1, C_RFlags, C_None)),
  374. {SETNLE} (Ch: (C_WOp1, C_RFlags, C_None)),
  375. {ARPL} (Ch: (C_WFlags, C_None, C_None)),
  376. {LAR} (Ch: (C_WOp2, C_None, C_None)),
  377. {LGDT} (Ch: (C_None, C_None, C_None)),
  378. {LIDT} (Ch: (C_None, C_None, C_None)),
  379. {LLDT} (Ch: (C_None, C_None, C_None)),
  380. {LMSW} (Ch: (C_None, C_None, C_None)),
  381. {LSL} (Ch: (C_WOp2, C_WFlags, C_None)),
  382. {LTR} (Ch: (C_None, C_None, C_None)),
  383. {SGDT} (Ch: (C_WOp1, C_None, C_None)),
  384. {SIDT} (Ch: (C_WOp1, C_None, C_None)),
  385. {SLDT} (Ch: (C_WOp1, C_None, C_None)),
  386. {SMSW} (Ch: (C_WOp1, C_None, C_None)),
  387. {STR} (Ch: (C_WOp1, C_None, C_None)),
  388. {VERR} (Ch: (C_WFlags, C_None, C_None)),
  389. {VERW} (Ch: (C_WFlags, C_None, C_None)),
  390. {FABS} (Ch: (C_FPU, C_None, C_None)),
  391. {FBLD} (Ch: (C_ROp1, C_FPU, C_None)),
  392. {FBSTP} (Ch: (C_WOp1, C_FPU, C_None)),
  393. {FCLEX} (Ch: (C_FPU, C_None, C_None)),
  394. {FNCLEX} (Ch: (C_FPU, C_None, C_None)),
  395. {FCOS} (Ch: (C_FPU, C_None, C_None)),
  396. {FDECSTP}(Ch: (C_FPU, C_None, C_None)),
  397. {FDISI} (Ch: (C_FPU, C_None, C_None)),
  398. {FNDISI} (Ch: (C_FPU, C_None, C_None)),
  399. {FDIVR} (Ch: (C_FPU, C_None, C_None)),
  400. {FENI} (Ch: (C_FPU, C_None, C_None)),
  401. {FNENI} (Ch: (C_FPU, C_None, C_None)),
  402. {FFREE} (Ch: (C_FPU, C_None, C_None)),
  403. {FIADD} (Ch: (C_FPU, C_None, C_None)),
  404. {FICOM} (Ch: (C_FPU, C_None, C_None)),
  405. {FICOMP} (Ch: (C_FPU, C_None, C_None)),
  406. {FIDIVR} (Ch: (C_FPU, C_None, C_None)),
  407. {FIMUL} (Ch: (C_FPU, C_None, C_None)),
  408. {FINCSTP}(Ch: (C_FPU, C_None, C_None)),
  409. {FINIT} (Ch: (C_FPU, C_None, C_None)),
  410. {FNINIT} (Ch: (C_FPU, C_None, C_None)),
  411. {FIST} (Ch: (C_WOp1, C_None, C_None)),
  412. {FISTP} (Ch: (C_WOp1, C_None, C_None)),
  413. {FISUB} (Ch: (C_FPU, C_None, C_None)),
  414. {FSUBR} (Ch: (C_FPU, C_None, C_None)),
  415. {FLDCW} (Ch: (C_FPU, C_None, C_None)),
  416. {FLDENV} (Ch: (C_FPU, C_None, C_None)),
  417. {FLDLG2} (Ch: (C_FPU, C_None, C_None)),
  418. {FLDLN2} (Ch: (C_FPU, C_None, C_None)),
  419. {FLDL2E} (Ch: (C_FPU, C_None, C_None)),
  420. {FLDL2T} (Ch: (C_FPU, C_None, C_None)),
  421. {FLDPI} (Ch: (C_FPU, C_None, C_None)),
  422. {FLDS} (Ch: (C_FPU, C_None, C_None)),
  423. {FLDZ} (Ch: (C_FPU, C_None, C_None)),
  424. {FNOP} (Ch: (C_FPU, C_None, C_None)),
  425. {FPATAN} (Ch: (C_FPU, C_None, C_None)),
  426. {FPREM} (Ch: (C_FPU, C_None, C_None)),
  427. {FPREM1} (Ch: (C_FPU, C_None, C_None)),
  428. {FPTAN} (Ch: (C_FPU, C_None, C_None)),
  429. {FRNDINT}(Ch: (C_FPU, C_None, C_None)),
  430. {FRSTOR} (Ch: (C_FPU, C_None, C_None)),
  431. {FSAVE} (Ch: (C_WOp1, C_None, C_None)),
  432. {FNSAVE} (Ch: (C_FPU, C_None, C_None)),
  433. {FSCALE} (Ch: (C_FPU, C_None, C_None)),
  434. {FSETPM} (Ch: (C_FPU, C_None, C_None)),
  435. {FSIN} (Ch: (C_FPU, C_None, C_None)),
  436. {FSINCOS}(Ch: (C_FPU, C_None, C_None)),
  437. {FSQRT} (Ch: (C_FPU, C_None, C_None)),
  438. {FST} (Ch: (C_WOp1, C_None, C_None)),
  439. {FSTCW} (Ch: (C_WOp1, C_None, C_None)),
  440. {FNSTCW} (Ch: (C_WOp1, C_None, C_None)),
  441. {FSTENV} (Ch: (C_WOp1, C_None, C_None)),
  442. {FNSTENV}(Ch: (C_WOp1, C_None, C_None)),
  443. {FSTSW} (Ch: (C_WOp1, C_None, C_None)),
  444. {FNSTSW} (Ch: (C_WOp1, C_None, C_None)),
  445. {FTST} (Ch: (C_FPU, C_None, C_None)),
  446. {FUCOM} (Ch: (C_FPU, C_None, C_None)),
  447. {FUCOMP} (Ch: (C_FPU, C_None, C_None)),
  448. {FUCOMPP}(Ch: (C_FPU, C_None, C_None)),
  449. {FWAIT} (Ch: (C_FPU, C_None, C_None)),
  450. {FXAM} (Ch: (C_FPU, C_None, C_None)),
  451. {FXTRACT}(Ch: (C_FPU, C_None, C_None)),
  452. {FYL2X} (Ch: (C_FPU, C_None, C_None)),
  453. {FYL2XP1}(Ch: (C_FPU, C_None, C_None)),
  454. {F2XM1} (Ch: (C_FPU, C_None, C_None)),
  455. {FILDQ} (Ch: (C_FPU, C_None, C_None)),
  456. {FILDS} (Ch: (C_FPU, C_None, C_None)),
  457. {FILDL} (Ch: (C_FPU, C_None, C_None)),
  458. {FLDL} (Ch: (C_FPU, C_None, C_None)),
  459. {FLDT} (Ch: (C_FPU, C_None, C_None)),
  460. {FISTQ} (Ch: (C_WOp1, C_None, C_None)),
  461. {FISTS} (Ch: (C_WOp1, C_None, C_None)),
  462. {FISTL} (Ch: (C_WOp1, C_None, C_None)),
  463. {FSTL} (Ch: (C_WOp1, C_None, C_None)),
  464. {FSTS} (Ch: (C_WOp1, C_None, C_None)),
  465. {FSTPS} (Ch: (C_WOp1, C_FPU, C_None)),
  466. {FISTPL} (Ch: (C_WOp1, C_None, C_None)),
  467. {FSTPL} (Ch: (C_WOp1, C_FPU, C_None)),
  468. {FISTPS} (Ch: (C_WOp1, C_FPU, C_None)),
  469. {FISTPQ} (Ch: (C_WOp1, C_FPU, C_None)),
  470. {FSTPT} (Ch: (C_WOp1, C_FPU, C_None)),
  471. {FCOMPS} (Ch: (C_FPU, C_None, C_None)),
  472. {FICOMPL}(Ch: (C_FPU, C_None, C_None)),
  473. {FCOMPL} (Ch: (C_FPU, C_None, C_None)),
  474. {FICOMPS}(Ch: (C_FPU, C_None, C_None)),
  475. {FCOMS} (Ch: (C_FPU, C_None, C_None)),
  476. {FICOML} (Ch: (C_FPU, C_None, C_None)),
  477. {FCOML} (Ch: (C_FPU, C_None, C_None)),
  478. {FICOMS} (Ch: (C_FPU, C_None, C_None)),
  479. {FIADDL} (Ch: (C_FPU, C_None, C_None)),
  480. {FADDL} (Ch: (C_FPU, C_None, C_None)),
  481. {FIADDS} (Ch: (C_FPU, C_None, C_None)),
  482. {FISUBL} (Ch: (C_FPU, C_None, C_None)),
  483. {FSUBL} (Ch: (C_FPU, C_None, C_None)),
  484. {FISUBS} (Ch: (C_FPU, C_None, C_None)),
  485. {FSUBS} (Ch: (C_FPU, C_None, C_None)),
  486. {FSUBR} (Ch: (C_FPU, C_None, C_None)),
  487. {FSUBRS} (Ch: (C_FPU, C_None, C_None)),
  488. {FISUBRL}(Ch: (C_FPU, C_None, C_None)),
  489. {FSUBRL} (Ch: (C_FPU, C_None, C_None)),
  490. {FISUBRS}(Ch: (C_FPU, C_None, C_None)),
  491. {FMULS} (Ch: (C_FPU, C_None, C_None)),
  492. {FIMUL} (Ch: (C_FPU, C_None, C_None)),
  493. {FMULL} (Ch: (C_FPU, C_None, C_None)),
  494. {FIMULS} (Ch: (C_FPU, C_None, C_None)),
  495. {FIDIVS} (Ch: (C_FPU, C_None, C_None)),
  496. {FIDIVL} (Ch: (C_FPU, C_None, C_None)),
  497. {FDIVL} (Ch: (C_FPU, C_None, C_None)),
  498. {FIDIVS} (Ch: (C_FPU, C_None, C_None)),
  499. {FDIVRS} (Ch: (C_FPU, C_None, C_None)),
  500. {FIDIVRL}(Ch: (C_FPU, C_None, C_None)),
  501. {FDIVRL} (Ch: (C_FPU, C_None, C_None)),
  502. {FIDIVRS}(Ch: (C_FPU, C_None, C_None)),
  503. {REPE} (Ch: (C_RWECX, C_RFlags, C_None)),
  504. {REPNE} (Ch: (C_RWECX, C_RFlags, C_None)),
  505. {CPUID} (Ch: (C_All, C_None, C_none)),
  506. {FADDS} (Ch: (C_FPU, C_None, C_None)),
  507. {POPFD} (Ch: (C_RWESP, C_WFlags, C_None)),
  508. {below are the MMX instructions}
  509. {A_EMMS} (Ch: (C_FPU, C_None, C_None)),
  510. {A_MOVD} (Ch: (C_WOp2, C_None, C_None)),
  511. {A_MOVQ} (Ch: (C_WOp2, C_None, C_None)),
  512. {A_PACKSSDW} (Ch: (C_All, C_None, C_None)),
  513. {A_PACKSSWB} (Ch: (C_All, C_None, C_None)),
  514. {A_PACKUSWB} (Ch: (C_All, C_None, C_None)),
  515. {A_PADDB} (Ch: (C_RWOp2, C_None, C_None)),
  516. {A_PADDD} (Ch: (C_RWOp2, C_None, C_None)),
  517. {A_PADDSB} (Ch: (C_RWOp2, C_None, C_None)),
  518. {A_PADDSW} (Ch: (C_RWOp2, C_None, C_None)),
  519. {A_PADDUSB} (Ch: (C_RWOp2, C_None, C_None)),
  520. {A_PADDUSW} (Ch: (C_RWOp2, C_None, C_None)),
  521. {A_PADDW} (Ch: (C_RWOp2, C_None, C_None)),
  522. {A_PAND} (Ch: (C_RWOp2, C_None, C_None)),
  523. {A_PANDN} (Ch: (C_RWOp2, C_None, C_None)),
  524. {A_PCMPEQB} (Ch: (C_All, C_None, C_None)),
  525. {A_PCMPEQD} (Ch: (C_All, C_None, C_None)),
  526. {A_PCMPEQW} (Ch: (C_All, C_None, C_None)),
  527. {A_PCMPGTB} (Ch: (C_All, C_None, C_None)),
  528. {A_PCMPGTD} (Ch: (C_All, C_None, C_None)),
  529. {A_PCMPGTW} (Ch: (C_All, C_None, C_None)),
  530. {A_PMADDWD} (Ch: (C_RWOp2, C_None, C_None)),
  531. {A_PMULHW} (Ch: (C_All, C_None, C_None)),
  532. {A_PMULLW} (Ch: (C_All, C_None, C_None)),
  533. {A_POR} (Ch: (C_RWOp2, C_None, C_None)),
  534. {A_PSLLD} (Ch: (C_RWOp2, C_None, C_None)),
  535. {A_PSLLQ} (Ch: (C_RWOp2, C_None, C_None)),
  536. {A_PSLLW} (Ch: (C_RWOp2, C_None, C_None)),
  537. {A_PSRAD} (Ch: (C_RWOp2, C_None, C_None)),
  538. {A_PSRAW} (Ch: (C_RWOp2, C_None, C_None)),
  539. {A_PSRLD} (Ch: (C_RWOp2, C_None, C_None)),
  540. {A_PSRLQ} (Ch: (C_RWOp2, C_None, C_None)),
  541. {A_PSRLW} (Ch: (C_RWOp2, C_None, C_None)),
  542. {A_PSUBB} (Ch: (C_RWOp2, C_None, C_None)),
  543. {A_PSUBD} (Ch: (C_RWOp2, C_None, C_None)),
  544. {A_PSUBSB} (Ch: (C_RWOp2, C_None, C_None)),
  545. {A_PSUBSW} (Ch: (C_RWOp2, C_None, C_None)),
  546. {A_PSUBUSB} (Ch: (C_RWOp2, C_None, C_None)),
  547. {A_PSUBUSW} (Ch: (C_RWOp2, C_None, C_None)),
  548. {A_PSUBW} (Ch: (C_RWOp2, C_None, C_None)),
  549. {A_PUNPCKHBW} (Ch: (C_All, C_None, C_None)),
  550. {A_PUNPCKHDQ} (Ch: (C_All, C_None, C_None)),
  551. {A_PUNPCKHWD} (Ch: (C_All, C_None, C_None)),
  552. {A_PUNPCKLBW} (Ch: (C_All, C_None, C_None)),
  553. {A_PUNPCKLDQ} (Ch: (C_All, C_None, C_None)),
  554. {A_PUNPCKLWD} (Ch: (C_All, C_None, C_None)),
  555. {A_PXOR} (Ch: (C_RWOp2, C_None, C_None)),
  556. { Jonas, can you change this: }
  557. (Ch: (C_All, C_None, C_None)),
  558. (Ch: (C_All, C_None, C_None)),
  559. (Ch: (C_All, C_None, C_None)),
  560. (Ch: (C_All, C_None, C_None)),
  561. (Ch: (C_All, C_None, C_None)),
  562. (Ch: (C_All, C_None, C_None)),
  563. (Ch: (C_All, C_None, C_None)),
  564. (Ch: (C_All, C_None, C_None)),
  565. (Ch: (C_All, C_None, C_None)),
  566. (Ch: (C_All, C_None, C_None)),
  567. (Ch: (C_All, C_None, C_None)),
  568. (Ch: (C_All, C_None, C_None)),
  569. (Ch: (C_All, C_None, C_None)),
  570. (Ch: (C_All, C_None, C_None)),
  571. (Ch: (C_All, C_None, C_None)),
  572. (Ch: (C_All, C_None, C_None)),
  573. (Ch: (C_All, C_None, C_None)),
  574. (Ch: (C_All, C_None, C_None)),
  575. (Ch: (C_All, C_None, C_None)),
  576. (Ch: (C_All, C_None, C_None)),
  577. (Ch: (C_All, C_None, C_None)),
  578. (Ch: (C_All, C_None, C_None)),
  579. (Ch: (C_All, C_None, C_None)),
  580. (Ch: (C_All, C_None, C_None)),
  581. (Ch: (C_All, C_None, C_None)),
  582. (Ch: (C_All, C_None, C_None)),
  583. (Ch: (C_All, C_None, C_None)),
  584. (Ch: (C_All, C_None, C_None)),
  585. (Ch: (C_All, C_None, C_None)),
  586. (Ch: (C_All, C_None, C_None)),
  587. (Ch: (C_All, C_None, C_None)),
  588. (Ch: (C_All, C_None, C_None)),
  589. (Ch: (C_All, C_None, C_None)),
  590. (Ch: (C_All, C_None, C_None)),
  591. (Ch: (C_All, C_None, C_None)),
  592. (Ch: (C_All, C_None, C_None)),
  593. (Ch: (C_All, C_None, C_None)),
  594. (Ch: (C_All, C_None, C_None)),
  595. (Ch: (C_All, C_None, C_None)),
  596. (Ch: (C_All, C_None, C_None)),
  597. (Ch: (C_All, C_None, C_None)),
  598. (Ch: (C_All, C_None, C_None)),
  599. (Ch: (C_All, C_None, C_None)),
  600. (Ch: (C_All, C_None, C_None)),
  601. (Ch: (C_All, C_None, C_None)),
  602. (Ch: (C_All, C_None, C_None)),
  603. (Ch: (C_All, C_None, C_None)),
  604. (Ch: (C_All, C_None, C_None)),
  605. (Ch: (C_All, C_None, C_None)),
  606. (Ch: (C_All, C_None, C_None)),
  607. (Ch: (C_All, C_None, C_None)),
  608. (Ch: (C_All, C_None, C_None)),
  609. (Ch: (C_All, C_None, C_None)),
  610. (Ch: (C_All, C_None, C_None)),
  611. (Ch: (C_All, C_None, C_None)),
  612. (Ch: (C_All, C_None, C_None)),
  613. (Ch: (C_All, C_None, C_None)),
  614. (Ch: (C_All, C_None, C_None)),
  615. (Ch: (C_All, C_None, C_None)),
  616. (Ch: (C_All, C_None, C_None)),
  617. (Ch: (C_All, C_None, C_None)),
  618. (Ch: (C_All, C_None, C_None)),
  619. (Ch: (C_All, C_None, C_None)),
  620. (Ch: (C_All, C_None, C_None)),
  621. (Ch: (C_All, C_None, C_None)),
  622. (Ch: (C_All, C_None, C_None)),
  623. (Ch: (C_All, C_None, C_None)),
  624. (Ch: (C_All, C_None, C_None)),
  625. (Ch: (C_All, C_None, C_None)),
  626. (Ch: (C_All, C_None, C_None)),
  627. (Ch: (C_All, C_None, C_None)),
  628. (Ch: (C_All, C_None, C_None)),
  629. (Ch: (C_All, C_None, C_None)),
  630. (Ch: (C_All, C_None, C_None)),
  631. (Ch: (C_All, C_None, C_None)),
  632. (Ch: (C_All, C_None, C_None)),
  633. (Ch: (C_All, C_None, C_None)),
  634. (Ch: (C_All, C_None, C_None)),
  635. (Ch: (C_All, C_None, C_None)),
  636. (Ch: (C_All, C_None, C_None)),
  637. (Ch: (C_All, C_None, C_None)),
  638. (Ch: (C_All, C_None, C_None)),
  639. (Ch: (C_All, C_None, C_None)),
  640. (Ch: (C_All, C_None, C_None)),
  641. (Ch: (C_All, C_None, C_None)),
  642. (Ch: (C_All, C_None, C_None)),
  643. (Ch: (C_All, C_None, C_None)),
  644. (Ch: (C_All, C_None, C_None)),
  645. (Ch: (C_All, C_None, C_None)),
  646. (Ch: (C_All, C_None, C_None)),
  647. (Ch: (C_All, C_None, C_None)),
  648. (Ch: (C_All, C_None, C_None)),
  649. (Ch: (C_All, C_None, C_None)),
  650. (Ch: (C_All, C_None, C_None)),
  651. (Ch: (C_All, C_None, C_None)),
  652. (Ch: (C_All, C_None, C_None)),
  653. (Ch: (C_All, C_None, C_None)),
  654. (Ch: (C_All, C_None, C_None)),
  655. (Ch: (C_All, C_None, C_None)),
  656. (Ch: (C_All, C_None, C_None)),
  657. (Ch: (C_All, C_None, C_None)),
  658. (Ch: (C_All, C_None, C_None)));
  659. Var
  660. {How many instructions are between the current instruction and the last one
  661. that modified the register}
  662. NrOfInstrSinceLastMod: TInstrSinceLastMod;
  663. {************************ Create the Label table ************************}
  664. Function FindLoHiLabels(AsmL: PAasmOutput; Var LowLabel, HighLabel, LabelDif: Longint; BlockStart: Pai): Pai;
  665. {Walks through the paasmlist to find the lowest and highest label number;
  666. Since 0.9.3: also removes unused labels}
  667. Var LabelFound: Boolean;
  668. P: Pai;
  669. Begin
  670. LabelFound := False;
  671. LowLabel := MaxLongint;
  672. HighLabel := 0;
  673. P := BlockStart;
  674. While Assigned(P) And
  675. ((P^.typ <> Ait_Marker) Or
  676. (Pai_Marker(P)^.Kind <> AsmBlockStart)) Do
  677. Begin
  678. If (Pai(p)^.typ = ait_label) Then
  679. If (Pai_Label(p)^.l^.is_used)
  680. Then
  681. Begin
  682. LabelFound := True;
  683. If (Pai_Label(p)^.l^.nb < LowLabel) Then
  684. LowLabel := Pai_Label(p)^.l^.nb;
  685. If (Pai_Label(p)^.l^.nb > HighLabel) Then
  686. HighLabel := Pai_Label(p)^.l^.nb;
  687. End
  688. { Else
  689. Begin
  690. hp1 := pai(p^.next);
  691. AsmL^.Remove(p);
  692. Dispose(p, Done);
  693. p := hp1;
  694. continue;
  695. End};
  696. GetNextInstruction(p, p);
  697. End;
  698. FindLoHiLabels := p;
  699. If LabelFound
  700. Then LabelDif := HighLabel+1-LowLabel
  701. Else LabelDif := 0;
  702. End;
  703. Function FindRegAlloc(Reg: TRegister; StartPai: Pai): Boolean;
  704. {Returns true if a ait_regalloc object for Reg is found in the block of Pai's
  705. starting with StartPai and ending with the next "real" instruction}
  706. Var TmpResult: Boolean;
  707. Begin
  708. TmpResult := False;
  709. Repeat
  710. While Assigned(StartPai) And
  711. ((StartPai^.typ in (SkipInstr - [ait_RegAlloc])) Or
  712. ((StartPai^.typ = ait_label) and
  713. Not(Pai_Label(StartPai)^.l^.Is_Used))) Do
  714. StartPai := Pai(StartPai^.Next);
  715. If Assigned(StartPai) And
  716. (StartPai^.typ = ait_RegAlloc) Then
  717. Begin
  718. TmpResult := (PaiRegAlloc(StartPai)^.Reg = Reg);
  719. StartPai := Pai(StartPai^.Next);
  720. End;
  721. Until Not(Assigned(StartPai)) Or
  722. Not(StartPai^.typ in SkipInstr) or TmpResult;
  723. FindRegAlloc := TmpResult;
  724. End;
  725. Procedure BuildLabelTableAndFixRegAlloc(AsmL: PAasmOutput; Var LabelTable: PLabelTable; LowLabel: Longint;
  726. Var LabelDif: Longint; BlockStart, BlockEnd: Pai);
  727. {Builds a table with the locations of the labels in the paasmoutput.
  728. Also fixes some RegDeallocs like "# %eax released; push (%eax)"}
  729. Var p, hp1, hp2: Pai;
  730. UsedRegs: TRegSet;
  731. Begin
  732. UsedRegs := [];
  733. If (LabelDif <> 0) Then
  734. Begin
  735. {$IfDef TP}
  736. If (MaxAvail >= LabelDif*SizeOf(Pai))
  737. Then
  738. Begin
  739. {$EndIf TP}
  740. GetMem(LabelTable, LabelDif*SizeOf(TLabelTableItem));
  741. FillChar(LabelTable^, LabelDif*SizeOf(TLabelTableItem), 0);
  742. p := BlockStart;
  743. While (P <> BlockEnd) Do
  744. Begin
  745. Case p^.typ Of
  746. ait_Label:
  747. If Pai_Label(p)^.l^.is_used Then
  748. LabelTable^[Pai_Label(p)^.l^.nb-LowLabel].PaiObj := p;
  749. ait_RegAlloc:
  750. Begin
  751. If Not(PaiRegAlloc(p)^.Reg in UsedRegs) Then
  752. UsedRegs := UsedRegs + [PaiRegAlloc(p)^.Reg]
  753. Else
  754. Begin
  755. hp1 := p;
  756. hp2 := nil;
  757. While GetLastInstruction(hp1, hp1) And
  758. Not(RegInInstruction(PaiRegAlloc(p)^.Reg, hp1)) Do
  759. hp2 := hp1;
  760. If hp2 <> nil Then
  761. Begin
  762. hp1 := New(PaiRegDeAlloc, Init(PaiRegAlloc(p)^.Reg));
  763. InsertLLItem(AsmL, Pai(hp2^.previous), hp2, hp1);
  764. End;
  765. End;
  766. End;
  767. ait_RegDeAlloc:
  768. Begin
  769. UsedRegs := UsedRegs - [PaiRegDeAlloc(p)^.Reg];
  770. hp1 := p;
  771. hp2 := nil;
  772. While Not(FindRegAlloc(PaiRegDeAlloc(p)^.Reg, Pai(hp1^.Next))) And
  773. GetNextInstruction(hp1, hp1) And
  774. RegInInstruction(PaiRegDeAlloc(p)^.Reg, hp1) Do
  775. hp2 := hp1;
  776. If hp2 <> nil Then
  777. Begin
  778. hp1 := Pai(p^.previous);
  779. AsmL^.Remove(p);
  780. InsertLLItem(AsmL, hp2, Pai(hp2^.Next), p);
  781. p := hp1;
  782. End;
  783. End;
  784. End;
  785. P := Pai(p^.Next);
  786. While Assigned(p) And
  787. (p^.typ in (SkipInstr - [ait_regdealloc,ait_regalloc])) Do
  788. P := Pai(P^.Next);
  789. End;
  790. {$IfDef TP}
  791. End
  792. Else LabelDif := 0;
  793. {$EndIf TP}
  794. End;
  795. End;
  796. {************************ Search the Label table ************************}
  797. Function FindLabel(L: PLabel; Var hp: Pai): Boolean;
  798. {searches for the specified label starting from hp as long as the
  799. encountered instructions are labels, to be able to optimize constructs like
  800. jne l2 jmp l2
  801. jmp l3 and l1:
  802. l1: l2:
  803. l2:}
  804. Var TempP: Pai;
  805. Begin
  806. TempP := hp;
  807. While Assigned(TempP) and
  808. (TempP^.typ In SkipInstr + [ait_label]) Do
  809. If (TempP^.typ <> ait_Label) Or
  810. (pai_label(TempP)^.l <> L)
  811. Then GetNextInstruction(TempP, TempP)
  812. Else
  813. Begin
  814. hp := TempP;
  815. FindLabel := True;
  816. exit
  817. End;
  818. FindLabel := False;
  819. End;
  820. {************************ Some general functions ************************}
  821. Function Reg32(Reg: TRegister): TRegister;
  822. {Returns the 32 bit component of Reg if it exists, otherwise Reg is returned}
  823. Begin
  824. Reg32 := Reg;
  825. If (Reg >= R_AX)
  826. Then
  827. If (Reg <= R_DI)
  828. Then Reg32 := Reg16ToReg32(Reg)
  829. Else
  830. If (Reg <= R_BL)
  831. Then Reg32 := Reg8toReg32(Reg);
  832. End;
  833. { inserts new_one between prev and foll }
  834. Procedure InsertLLItem(AsmL: PAasmOutput; prev, foll, new_one: PLinkedList_Item);
  835. Begin
  836. If Assigned(prev) Then
  837. If Assigned(foll) Then
  838. Begin
  839. If Assigned(new_one) Then
  840. Begin
  841. new_one^.previous := prev;
  842. new_one^.next := foll;
  843. prev^.next := new_one;
  844. foll^.previous := new_one;
  845. End;
  846. End
  847. Else AsmL^.Concat(new_one)
  848. Else If Assigned(Foll) Then AsmL^.Insert(new_one)
  849. End;
  850. {********************* Compare parts of Pai objects *********************}
  851. Function RegsSameSize(Reg1, Reg2: TRegister): Boolean;
  852. {returns true if Reg1 and Reg2 are of the same size (so if they're both
  853. 8bit, 16bit or 32bit)}
  854. Begin
  855. If (Reg1 <= R_EDI)
  856. Then RegsSameSize := (Reg2 <= R_EDI)
  857. Else
  858. If (Reg1 <= R_DI)
  859. Then RegsSameSize := (Reg2 in [R_AX..R_DI])
  860. Else
  861. If (Reg1 <= R_BL)
  862. Then RegsSameSize := (Reg2 in [R_AL..R_BL])
  863. Else RegsSameSize := False
  864. End;
  865. Procedure AddReg2RegInfo(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo);
  866. {updates the ???RegsEncountered and ???2???Reg fields of RegInfo. Assumes that
  867. OldReg and NewReg have the same size (has to be chcked in advance with
  868. RegsSameSize) and that neither equals R_NO}
  869. Begin
  870. With RegInfo Do
  871. Begin
  872. NewRegsEncountered := NewRegsEncountered + [NewReg];
  873. OldRegsEncountered := OldRegsEncountered + [OldReg];
  874. New2OldReg[NewReg] := OldReg;
  875. Case OldReg Of
  876. R_EAX..R_EDI:
  877. Begin
  878. NewRegsEncountered := NewRegsEncountered + [Reg32toReg16(NewReg)];
  879. OldRegsEncountered := OldRegsEncountered + [Reg32toReg16(OldReg)];
  880. New2OldReg[Reg32toReg16(NewReg)] := Reg32toReg16(OldReg);
  881. If (NewReg in [R_EAX..R_EBX]) And
  882. (OldReg in [R_EAX..R_EBX]) Then
  883. Begin
  884. NewRegsEncountered := NewRegsEncountered + [Reg32toReg8(NewReg)];
  885. OldRegsEncountered := OldRegsEncountered + [Reg32toReg8(OldReg)];
  886. New2OldReg[Reg32toReg8(NewReg)] := Reg32toReg8(OldReg);
  887. End;
  888. End;
  889. R_AX..R_DI:
  890. Begin
  891. NewRegsEncountered := NewRegsEncountered + [Reg16toReg32(NewReg)];
  892. OldRegsEncountered := OldRegsEncountered + [Reg16toReg32(OldReg)];
  893. New2OldReg[Reg16toReg32(NewReg)] := Reg16toReg32(OldReg);
  894. If (NewReg in [R_AX..R_BX]) And
  895. (OldReg in [R_AX..R_BX]) Then
  896. Begin
  897. NewRegsEncountered := NewRegsEncountered + [Reg16toReg8(NewReg)];
  898. OldRegsEncountered := OldRegsEncountered + [Reg16toReg8(OldReg)];
  899. New2OldReg[Reg16toReg8(NewReg)] := Reg16toReg8(OldReg);
  900. End;
  901. End;
  902. R_AL..R_BL:
  903. Begin
  904. NewRegsEncountered := NewRegsEncountered + [Reg8toReg32(NewReg)]
  905. + [Reg8toReg16(NewReg)];
  906. OldRegsEncountered := OldRegsEncountered + [Reg8toReg32(OldReg)]
  907. + [Reg8toReg16(OldReg)];
  908. New2OldReg[Reg8toReg32(NewReg)] := Reg8toReg32(OldReg);
  909. End;
  910. End;
  911. End;
  912. End;
  913. Procedure AddOp2RegInfo(typ: Longint; Op: Pointer; Var RegInfo: TRegInfo);
  914. Begin
  915. Case typ Of
  916. Top_Reg:
  917. If (TRegister(op) <> R_NO) Then
  918. AddReg2RegInfo(TRegister(op), TRegister(op), RegInfo);
  919. Top_Ref:
  920. Begin
  921. If TReference(op^).base <> R_NO Then
  922. AddReg2RegInfo(TReference(op^).base, TReference(op^).base, RegInfo);
  923. If TReference(op^).index <> R_NO Then
  924. AddReg2RegInfo(TReference(op^).index, TReference(op^).index, RegInfo);
  925. End;
  926. End;
  927. End;
  928. Function RegsEquivalent(OldReg, NewReg: TRegister; Var RegInfo: TRegInfo; OPAct: TOpAction): Boolean;
  929. Begin
  930. If Not((OldReg = R_NO) Or (NewReg = R_NO)) Then
  931. If RegsSameSize(OldReg, NewReg) Then
  932. With RegInfo Do
  933. {here we always check for the 32 bit component, because it is possible that
  934. the 8 bit component has not been set, event though NewReg already has been
  935. processed. This happens if it has been compared with a register that doesn't
  936. have an 8 bit component (such as EDI). In that case the 8 bit component is
  937. still set to R_NO and the comparison in the Else-part will fail}
  938. If (Reg32(OldReg) in OldRegsEncountered) Then
  939. If (Reg32(NewReg) in NewRegsEncountered) Then
  940. RegsEquivalent := (OldReg = New2OldReg[NewReg])
  941. { If we haven't encountered the new register yet, but we have encountered the
  942. old one already, the new one can only be correct if it's being written to
  943. (and consequently the old one is also being written to), otherwise
  944. movl -8(%ebp), %eax and movl -8(%ebp), %eax
  945. movl (%eax), %eax movl (%edx), %edx
  946. are considered equivalent}
  947. Else
  948. If (OpAct = OpAct_Write) Then
  949. Begin
  950. AddReg2RegInfo(OldReg, NewReg, RegInfo);
  951. RegsEquivalent := True
  952. End
  953. Else Regsequivalent := False
  954. Else
  955. If Not(Reg32(NewReg) in NewRegsEncountered) Then
  956. Begin
  957. AddReg2RegInfo(OldReg, NewReg, RegInfo);
  958. RegsEquivalent := True
  959. End
  960. Else RegsEquivalent := False
  961. Else RegsEquivalent := False
  962. Else RegsEquivalent := OldReg = NewReg
  963. End;
  964. Function RefsEquivalent(Const R1, R2: TReference; var RegInfo: TRegInfo; OpAct: TOpAction): Boolean;
  965. Begin
  966. If R1.is_immediate
  967. Then RefsEquivalent := R2.is_immediate and (R1.Offset = R2.Offset)
  968. Else If (R1.Offset = R2.Offset) And
  969. RegsEquivalent(R1.Base, R2.Base, RegInfo, OpAct) And
  970. RegsEquivalent(R1.Index, R2.Index, RegInfo, OpAct) And
  971. (R1.Segment = R2.Segment) And (R1.ScaleFactor = R2.ScaleFactor)
  972. Then
  973. Begin
  974. If Assigned(R1.Symbol)
  975. Then RefsEquivalent := Assigned(R2.Symbol) And (R1.Symbol=R2.Symbol)
  976. Else RefsEquivalent := Not(Assigned(R2.Symbol));
  977. End
  978. Else RefsEquivalent := False;
  979. End;
  980. Function RefsEqual(Const R1, R2: TReference): Boolean;
  981. Begin
  982. If R1.is_immediate
  983. Then RefsEqual := R2.is_immediate and (R1.Offset = R2.Offset)
  984. Else If (R1.Offset = R2.Offset) And (R1.Base = R2.Base) And
  985. (R1.Index = R2.Index) And (R1.Segment = R2.Segment) And
  986. (R1.ScaleFactor = R2.ScaleFactor)
  987. Then
  988. Begin
  989. If Assigned(R1.Symbol)
  990. Then RefsEqual := Assigned(R2.Symbol) And (R1.Symbol=R2.Symbol)
  991. Else RefsEqual := Not(Assigned(R2.Symbol));
  992. End
  993. Else RefsEqual := False;
  994. End;
  995. Function IsGP32Reg(Reg: TRegister): Boolean;
  996. {Checks if the register is a 32 bit general purpose register}
  997. Begin
  998. If (Reg >= R_EAX) and (Reg <= R_EBX)
  999. Then IsGP32Reg := True
  1000. Else IsGP32reg := False
  1001. End;
  1002. Function RegInRef(Reg: TRegister; Const Ref: TReference): Boolean;
  1003. Begin {checks whether Ref contains a reference to Reg}
  1004. Reg := Reg32(Reg);
  1005. RegInRef := (Ref.Base = Reg) Or (Ref.Index = Reg)
  1006. End;
  1007. Function RegInInstruction(Reg: TRegister; p1: Pai): Boolean;
  1008. {checks if Reg is used by the instruction p1}
  1009. Var TmpResult: Boolean;
  1010. Begin
  1011. TmpResult := False;
  1012. If (Pai(p1)^.typ = ait_instruction) Then
  1013. Begin
  1014. Case Pai386(p1)^.op1t Of
  1015. Top_Reg: TmpResult := Reg = TRegister(Pai386(p1)^.op1);
  1016. Top_Ref: TmpResult := RegInRef(Reg, TReference(Pai386(p1)^.op1^))
  1017. End;
  1018. If Not(TmpResult) Then
  1019. Case Pai386(p1)^.op2t Of
  1020. Top_Reg:
  1021. if Pai386(p1)^.op3t<>Top_reg
  1022. then TmpResult := Reg = TRegister(Pai386(p1)^.op2)
  1023. else TmpResult := longint(Reg) = twowords(Pai386(p1)^.op2).word1;
  1024. Top_Ref: TmpResult := RegInRef(Reg, TReference(Pai386(p1)^.op2^))
  1025. End;
  1026. If Not(TmpResult) Then
  1027. Case Pai386(p1)^.op3t Of
  1028. Top_Reg: TmpResult := longint(Reg) =twowords(Pai386(p1)^.op2).word2;
  1029. Top_none:;
  1030. else
  1031. internalerror($Da);
  1032. End
  1033. End;
  1034. RegInInstruction := TmpResult
  1035. End;
  1036. {Function RegInOp(Reg: TRegister; opt: Longint; op: Pointer): Boolean;
  1037. Begin
  1038. RegInOp := False;
  1039. Case opt Of
  1040. top_reg: RegInOp := Reg = TRegister(Pointer);
  1041. top_ref: RegInOp := (Reg = TReference(op^).Base) Or
  1042. (Reg = TReference(op^).Index);
  1043. End;
  1044. End;}
  1045. Function RegModifiedByInstruction(Reg: TRegister; p1: Pai): Boolean;
  1046. {returns true if Reg is modified by the instruction p1. P1 is assumed to be
  1047. of the type ait_instruction}
  1048. Var hp: Pai;
  1049. Begin
  1050. If GetLastInstruction(p1, hp)
  1051. Then
  1052. RegModifiedByInstruction :=
  1053. PPAiProp(p1^.fileinfo.line)^.Regs[Reg].WState <>
  1054. PPAiProp(hp^.fileinfo.line)^.Regs[Reg].WState
  1055. Else RegModifiedByInstruction := True;
  1056. End;
  1057. {********************* GetNext and GetLastInstruction *********************}
  1058. Function GetNextInstruction(Current: Pai; Var Next: Pai): Boolean;
  1059. {skips ait_regalloc, ait_regdealloc and ait_stab* objects and puts the
  1060. next pai object in Next. Returns false if there isn't any}
  1061. Begin
  1062. Repeat
  1063. Current := Pai(Current^.Next);
  1064. While Assigned(Current) And
  1065. ((Current^.typ In SkipInstr) or
  1066. ((Current^.typ = ait_label) And
  1067. Not(Pai_Label(Current)^.l^.is_used))) Do
  1068. Current := Pai(Current^.Next);
  1069. If Assigned(Current) And
  1070. (Current^.typ = ait_Marker) And
  1071. (Pai_Marker(Current)^.Kind = NoPropInfoStart) Then
  1072. Begin
  1073. While Assigned(Current) And
  1074. ((Current^.typ <> ait_Marker) Or
  1075. (Pai_Marker(Current)^.Kind <> NoPropInfoEnd)) Do
  1076. Current := Pai(Current^.Next);
  1077. End;
  1078. Until Not(Assigned(Current)) Or
  1079. (Current^.typ <> ait_Marker) Or
  1080. (Pai_Marker(Current)^.Kind <> NoPropInfoEnd);
  1081. Next := Current;
  1082. If Assigned(Current) And
  1083. Not((Current^.typ In SkipInstr) or
  1084. ((Current^.typ = ait_label) And
  1085. Not(Pai_Label(Current)^.l^.is_used)))
  1086. Then GetNextInstruction := True
  1087. Else
  1088. Begin
  1089. Next := Nil;
  1090. GetNextInstruction := False;
  1091. End;
  1092. End;
  1093. Function GetLastInstruction(Current: Pai; Var Last: Pai): Boolean;
  1094. {skips the ait-types in SkipInstr puts the previous pai object in
  1095. Last. Returns false if there isn't any}
  1096. Begin
  1097. Repeat
  1098. Current := Pai(Current^.previous);
  1099. While Assigned(Current) And
  1100. ((Pai(Current)^.typ In SkipInstr) or
  1101. ((Pai(Current)^.typ = ait_label) And
  1102. Not(Pai_Label(Current)^.l^.is_used))) Do
  1103. Current := Pai(Current^.previous);
  1104. If Assigned(Current) And
  1105. (Current^.typ = ait_Marker) And
  1106. (Pai_Marker(Current)^.Kind = NoPropInfoEnd) Then
  1107. Begin
  1108. While Assigned(Current) And
  1109. ((Current^.typ <> ait_Marker) Or
  1110. (Pai_Marker(Current)^.Kind <> NoPropInfoStart)) Do
  1111. Current := Pai(Current^.previous);
  1112. End;
  1113. Until Not(Assigned(Current)) Or
  1114. (Current^.typ <> ait_Marker) Or
  1115. (Pai_Marker(Current)^.Kind <> NoPropInfoStart);
  1116. Last := Current;
  1117. If Assigned(Current) And
  1118. Not((Current^.typ In SkipInstr) or
  1119. ((Current^.typ = ait_label) And
  1120. Not(Pai_Label(Current)^.l^.is_used)))
  1121. Then GetLastInstruction := True
  1122. Else
  1123. Begin
  1124. Last := Nil;
  1125. GetLastInstruction := False
  1126. End;
  1127. End;
  1128. Procedure SkipHead(var P: Pai);
  1129. Var OldP: Pai;
  1130. Begin
  1131. Repeat
  1132. OldP := P;
  1133. If (P^.typ in SkipInstr) Then
  1134. GetNextInstruction(P, P)
  1135. Else If ((P^.Typ = Ait_Marker) And
  1136. (Pai_Marker(P)^.Kind = NoPropInfoStart)) Then
  1137. {a marker of the NoPropInfoStart can4t be the first instruction of a
  1138. paasmoutput list}
  1139. GetNextInstruction(Pai(P^.Previous),P);
  1140. If (P^.Typ = Ait_Marker) And
  1141. (Pai_Marker(P)^.Kind = AsmBlockStart) Then
  1142. Begin
  1143. P := Pai(P^.Next);
  1144. While (P^.typ <> Ait_Marker) Or
  1145. (Pai_Marker(P)^.Kind <> AsmBlockEnd) Do
  1146. P := Pai(P^.Next)
  1147. End;
  1148. Until P = OldP
  1149. End;
  1150. {******************* The Data Flow Analyzer functions ********************}
  1151. Procedure UpdateUsedRegs(Var UsedRegs: TRegSet; p: Pai);
  1152. {updates UsedRegs with the RegAlloc Information coming after P}
  1153. Begin
  1154. Repeat
  1155. While Assigned(p) And
  1156. ((p^.typ in (SkipInstr - [ait_RegAlloc, ait_RegDealloc])) or
  1157. ((p^.typ = ait_label) And
  1158. Not(Pai_Label(p)^.l^.is_used))) Do
  1159. p := Pai(p^.next);
  1160. While Assigned(p) And
  1161. (p^.typ in [ait_RegAlloc, ait_RegDealloc]) Do
  1162. Begin
  1163. Case p^.typ Of
  1164. ait_RegAlloc: UsedRegs := UsedRegs + [PaiRegAlloc(p)^.Reg];
  1165. ait_regdealloc: UsedRegs := UsedRegs - [PaiRegDeAlloc(p)^.Reg];
  1166. End;
  1167. p := pai(p^.next);
  1168. End;
  1169. Until Not(Assigned(p)) Or
  1170. (Not(p^.typ in SkipInstr) And
  1171. Not((p^.typ = ait_label) And
  1172. Not(Pai_Label(p)^.l^.is_used)));
  1173. End;
  1174. (*Function FindZeroreg(p: Pai; Var Result: TRegister): Boolean;
  1175. {Finds a register which contains the constant zero}
  1176. Var Counter: TRegister;
  1177. Begin
  1178. Counter := R_EAX;
  1179. FindZeroReg := True;
  1180. While (Counter <= R_EDI) And
  1181. ((PPaiProp(p^.fileinfo.line)^.Regs[Counter].Typ <> Con_Const) or
  1182. (PPaiProp(p^.fileinfo.line)^.Regs[Counter].StartMod <> Pointer(0))) Do
  1183. Inc(Byte(Counter));
  1184. If (PPaiProp(p^.fileinfo.line)^.Regs[Counter].Typ = Con_Const) And
  1185. (PPaiProp(p^.fileinfo.line)^.Regs[Counter].StartMod = Pointer(0))
  1186. Then Result := Counter
  1187. Else FindZeroReg := False;
  1188. End;*)
  1189. Function TCh2Reg(Ch: TChange): TRegister;
  1190. {converts a TChange variable to a TRegister}
  1191. Begin
  1192. If (Ch <= C_REDI) Then
  1193. TCh2Reg := TRegister(Byte(Ch))
  1194. Else
  1195. If (Ch <= C_WEDI) Then
  1196. TCh2Reg := TRegister(Byte(Ch) - Byte(C_REDI))
  1197. Else
  1198. If (Ch <= C_RWEDI) Then
  1199. TCh2Reg := TRegister(Byte(Ch) - Byte(C_WEDI))
  1200. Else InternalError($db)
  1201. End;
  1202. Procedure IncState(Var S: Byte);
  1203. {Increases S by 1, wraps around at $ffff to 0 (so we won't get overflow
  1204. errors}
  1205. Begin
  1206. If (s <> $ff)
  1207. Then Inc(s)
  1208. Else s := 0
  1209. End;
  1210. Function RegInSequence(Reg: TRegister; Const Content: TContent): Boolean;
  1211. {checks the whole sequence of Content (so StartMod and and the next NrOfMods
  1212. Pai objects) to see whether Reg is used somewhere, without it being loaded
  1213. with something else first}
  1214. Var p: Pai;
  1215. Counter: Byte;
  1216. TmpResult: Boolean;
  1217. RegsChecked: TRegSet;
  1218. Begin
  1219. RegsChecked := [];
  1220. p := Content.StartMod;
  1221. TmpResult := False;
  1222. Counter := 1;
  1223. While Not(TmpResult) And
  1224. (Counter <= Content.NrOfMods) Do
  1225. Begin
  1226. If (p^.typ = ait_instruction) and
  1227. ((Pai386(p)^.opcode = A_MOV) or
  1228. (Pai386(p)^.opcode = A_MOVZX) or
  1229. (Pai386(p)^.opcode = A_MOVSX))
  1230. Then
  1231. If (Pai386(p)^.op1t = top_ref)
  1232. Then
  1233. With TReference(Pai386(p)^.op1^) Do
  1234. If (Base = ProcInfo.FramePointer) And
  1235. (Index = R_NO)
  1236. Then RegsChecked := RegsChecked + [Reg32(TRegister(Pai386(p)^.op2))]
  1237. Else
  1238. Begin
  1239. If (Base = Reg) And
  1240. Not(Base In RegsChecked)
  1241. Then TmpResult := True;
  1242. If Not(TmpResult) And
  1243. (Index = Reg) And
  1244. Not(Index In RegsChecked)
  1245. Then TmpResult := True;
  1246. End;
  1247. Inc(Counter);
  1248. GetNextInstruction(p,p)
  1249. End;
  1250. RegInSequence := TmpResult
  1251. End;
  1252. Procedure DestroyReg(p1: PPaiProp; Reg: TRegister);
  1253. {Destroys the contents of the register Reg in the PPaiProp p1, as well as the
  1254. contents of registers are loaded with a memory location based on Reg}
  1255. Var TmpWState, TmpRState: Byte;
  1256. Counter: TRegister;
  1257. Begin
  1258. Reg := Reg32(Reg);
  1259. NrOfInstrSinceLastMod[Reg] := 0;
  1260. If (Reg >= R_EAX) And (Reg <= R_EDI)
  1261. Then
  1262. Begin
  1263. With p1^.Regs[Reg] Do
  1264. Begin
  1265. IncState(WState);
  1266. TmpWState := WState;
  1267. TmpRState := RState;
  1268. FillChar(p1^.Regs[Reg], SizeOf(TContent), 0);
  1269. WState := TmpWState;
  1270. RState := TmpRState;
  1271. End;
  1272. For Counter := R_EAX to R_EDI Do
  1273. With p1^.Regs[Counter] Do
  1274. If (Typ = Con_Ref) And
  1275. RegInSequence(Reg, p1^.Regs[Counter])
  1276. Then
  1277. Begin
  1278. IncState(WState);
  1279. TmpWState := WState;
  1280. TmpRState := RState;
  1281. FillChar(p1^.Regs[Counter], SizeOf(TContent), 0);
  1282. WState := TmpWState;
  1283. RState := TmpRState;
  1284. End;
  1285. End;
  1286. End;
  1287. {Procedure AddRegsToSet(p: Pai; Var RegSet: TRegSet);
  1288. Begin
  1289. If (p^.typ = ait_instruction) Then
  1290. Begin
  1291. Case Pai386(p)^.op1t Of
  1292. top_reg:
  1293. If Not(TRegister(Pai386(p)^.op1) in [R_NO,R_ESP,ProcInfo.FramePointer]) Then
  1294. RegSet := RegSet + [TRegister(Pai386(p)^.op1)];
  1295. top_ref:
  1296. With TReference(Pai386(p)^.op1^) Do
  1297. Begin
  1298. If Not(Base in [ProcInfo.FramePointer,R_NO,R_ESP])
  1299. Then RegSet := RegSet + [Base];
  1300. If Not(Index in [ProcInfo.FramePointer,R_NO,R_ESP])
  1301. Then RegSet := RegSet + [Index];
  1302. End;
  1303. End;
  1304. Case Pai386(p)^.op2t Of
  1305. top_reg:
  1306. If Not(TRegister(Pai386(p)^.op2) in [R_NO,R_ESP,ProcInfo.FramePointer]) Then
  1307. If RegSet := RegSet + [TRegister(TwoWords(Pai386(p)^.op2).Word1];
  1308. top_ref:
  1309. With TReference(Pai386(p)^.op2^) Do
  1310. Begin
  1311. If Not(Base in [ProcInfo.FramePointer,R_NO,R_ESP])
  1312. Then RegSet := RegSet + [Base];
  1313. If Not(Index in [ProcInfo.FramePointer,R_NO,R_ESP])
  1314. Then RegSet := RegSet + [Index];
  1315. End;
  1316. End;
  1317. End;
  1318. End;}
  1319. Function OpsEquivalent(typ: Longint; OldOp, NewOp: Pointer; Var RegInfo: TRegInfo; OpAct: TopAction): Boolean;
  1320. Begin {checks whether the two ops are equivalent}
  1321. Case typ Of
  1322. Top_Reg: OpsEquivalent :=RegsEquivalent(TRegister(OldOp), TRegister(NewOp), RegInfo, OpAct);
  1323. Top_Const: OpsEquivalent := OldOp = NewOp;
  1324. Top_Ref: OpsEquivalent := RefsEquivalent(TReference(OldOp^), TReference(NewOp^), RegInfo, OpAct);
  1325. Top_None: OpsEquivalent := True
  1326. Else OpsEquivalent := False
  1327. End;
  1328. End;
  1329. Function OpsEqual(typ: Longint; op1, op2: Pointer): Boolean;
  1330. Begin {checks whether the two ops are equal}
  1331. Case typ Of
  1332. Top_Reg, Top_Const: OpsEqual := op1 = op2;
  1333. Top_Ref: OpsEqual := RefsEqual(TReference(op1^), TReference(op2^));
  1334. Top_None: OpsEqual := True
  1335. Else OpsEqual := False
  1336. End;
  1337. End;
  1338. Function InstructionsEquivalent(p1, p2: Pai; Var RegInfo: TRegInfo): Boolean;
  1339. Begin {checks whether two Pai386 instructions are equal}
  1340. If Assigned(p1) And Assigned(p2) And
  1341. (Pai(p1)^.typ = ait_instruction) And
  1342. (Pai(p1)^.typ = ait_instruction) And
  1343. (Pai386(p1)^.opcode = Pai386(p2)^.opcode) And
  1344. (Pai386(p1)^.op1t = Pai386(p2)^.op1t) And
  1345. (Pai386(p1)^.op2t = Pai386(p2)^.op2t) And
  1346. (Pai386(p1)^.op3t = Pai386(p2)^.op3t)
  1347. Then
  1348. {both instructions have the same structure:
  1349. "<operator> <operand of type1>, <operand of type 2>"}
  1350. If ((Pai386(p1)^.opcode = A_MOV) or
  1351. (Pai386(p1)^.opcode = A_MOVZX) or
  1352. (Pai386(p1)^.opcode = A_MOVSX)) And
  1353. (Pai386(p1)^.op1t = top_ref) {then op2t = top_reg} Then
  1354. If Not(RegInRef(TRegister(Pai386(p1)^.op2), TReference(Pai386(p1)^.op1^))) Then
  1355. {the "old" instruction is a load of a register with a new value, not with
  1356. a value based on the contents of this register (so no "mov (reg), reg")}
  1357. If Not(RegInRef(TRegister(Pai386(p2)^.op2), TReference(Pai386(p2)^.op1^))) And
  1358. RefsEqual(TReference(Pai386(p1)^.op1^), TReference(Pai386(p2)^.op1^))
  1359. Then
  1360. {the "new" instruction is also a load of a register with a new value, and
  1361. this value is fetched from the same memory location}
  1362. Begin
  1363. With TReference(Pai386(p2)^.op1^) Do
  1364. Begin
  1365. If Not(Base in [ProcInfo.FramePointer, R_NO, R_ESP])
  1366. {it won't do any harm if the register is already in RegsLoadedForRef}
  1367. Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
  1368. If Not(Index in [ProcInfo.FramePointer, R_NO, R_ESP])
  1369. Then RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
  1370. End;
  1371. {add the registers from the reference (op1) to the RegInfo, all registers
  1372. from the reference are the same in the old and in the new instruction
  1373. sequence}
  1374. AddOp2RegInfo(Pai386(p1)^.op1t, Pai386(p1)^.op1, RegInfo);
  1375. {the registers from op2 have to be equivalent, but not necessarily equal}
  1376. InstructionsEquivalent :=
  1377. RegsEquivalent(TRegister(Pai386(p1)^.op2), TRegister(Pai386(p2)^.op2),
  1378. RegInfo, OpAct_Write);
  1379. End
  1380. {the registers are loaded with values from different memory locations. If
  1381. this was allowed, the instructions "mov -4(esi),eax" and "mov -4(ebp),eax"
  1382. would be considered equivalent}
  1383. Else InstructionsEquivalent := False
  1384. Else
  1385. {load register with a value based on the current value of this register}
  1386. Begin
  1387. With TReference(Pai386(p2)^.op1^) Do
  1388. Begin
  1389. If Not(Base in [ProcInfo.FramePointer,
  1390. Reg32(TRegister(Pai386(p2)^.op2)),R_NO,R_ESP])
  1391. {it won't do any harm if the register is already in RegsLoadedForRef}
  1392. Then
  1393. Begin
  1394. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Base];
  1395. {$ifdef csdebug}
  1396. Writeln(att_reg2str[base], ' added');
  1397. {$endif csdebug}
  1398. end;
  1399. If Not(Index in [ProcInfo.FramePointer,
  1400. Reg32(TRegister(Pai386(p2)^.op2)),R_NO,R_ESP])
  1401. Then
  1402. Begin
  1403. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef + [Index];
  1404. {$ifdef csdebug}
  1405. Writeln(att_reg2str[index], ' added');
  1406. {$endif csdebug}
  1407. end;
  1408. End;
  1409. If Not(Reg32(TRegister(Pai386(p2)^.op2)) In [ProcInfo.FramePointer,
  1410. R_NO,R_ESP])
  1411. Then
  1412. Begin
  1413. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef -
  1414. [Reg32(TRegister(Pai386(p2)^.op2))];
  1415. {$ifdef csdebug}
  1416. Writeln(att_reg2str[Reg32(TRegister(Pai386(p2)^.op2))], ' removed');
  1417. {$endif csdebug}
  1418. end;
  1419. InstructionsEquivalent :=
  1420. OpsEquivalent(Pai386(p1)^.op1t, Pai386(p1)^.op1, Pai386(p2)^.op1, RegInfo, OpAct_Read) And
  1421. OpsEquivalent(Pai386(p1)^.op2t, Pai386(p1)^.op2, Pai386(p2)^.op2, RegInfo, OpAct_Write)
  1422. End
  1423. Else
  1424. {an instruction <> mov, movzx, movsx}
  1425. If (Pai386(p1)^.op3t = top_none) Then
  1426. InstructionsEquivalent :=
  1427. OpsEquivalent(Pai386(p1)^.op1t, Pai386(p1)^.op1, Pai386(p2)^.op1, RegInfo, OpAct_Unknown) And
  1428. OpsEquivalent(Pai386(p1)^.op2t, Pai386(p1)^.op2, Pai386(p2)^.op2, RegInfo, OpAct_Unknown)
  1429. Else
  1430. InstructionsEquivalent :=
  1431. OpsEquivalent(Pai386(p1)^.op1t, Pai386(p1)^.op1, Pai386(p2)^.op1, RegInfo, OpAct_Unknown) And
  1432. OpsEquivalent(Pai386(p1)^.op2t, Pointer(Longint(TwoWords(Pai386(p1)^.op2).Word1)),
  1433. Pointer(Longint(TwoWords(Pai386(p2)^.op2).Word1)), RegInfo, OpAct_Unknown) And
  1434. OpsEquivalent(Pai386(p1)^.op3t, Pointer(Longint(TwoWords(Pai386(p1)^.op2).Word2)),
  1435. Pointer(Longint(TwoWords(Pai386(p2)^.op2).Word2)), RegInfo, OpAct_Unknown)
  1436. {the instructions haven't even got the same structure, so they're certainly
  1437. not equivalent}
  1438. Else InstructionsEquivalent := False;
  1439. End;
  1440. (*
  1441. Function InstructionsEqual(p1, p2: Pai): Boolean;
  1442. Begin {checks whether two Pai386 instructions are equal}
  1443. InstructionsEqual :=
  1444. Assigned(p1) And Assigned(p2) And
  1445. ((Pai(p1)^.typ = ait_instruction) And
  1446. (Pai(p1)^.typ = ait_instruction) And
  1447. (Pai386(p1)^.opcode = Pai386(p2)^.opcode) And
  1448. (Pai386(p1)^.op1t = Pai386(p2)^.op1t) And
  1449. (Pai386(p1)^.op2t = Pai386(p2)^.op2t) And
  1450. OpsEqual(Pai386(p1)^.op1t, Pai386(p1)^.op1, Pai386(p2)^.op1) And
  1451. OpsEqual(Pai386(p1)^.op2t, Pai386(p1)^.op2, Pai386(p2)^.op2))
  1452. End;
  1453. *)
  1454. Function RefInInstruction(Const Ref: TReference; p: Pai): Boolean;
  1455. {checks whehter Ref is used in P}
  1456. Var TmpResult: Boolean;
  1457. Begin
  1458. TmpResult := False;
  1459. If (p^.typ = ait_instruction) Then
  1460. Begin
  1461. If (Pai386(p)^.op1t = Top_Ref)
  1462. Then TmpResult := RefsEqual(Ref, TReference(Pai386(p)^.op1^));
  1463. If Not(TmpResult) And
  1464. (Pai386(p)^.op2t = Top_Ref)
  1465. Then TmpResult := RefsEqual(Ref, TReference(Pai386(p)^.op2^));
  1466. End;
  1467. RefInInstruction := TmpResult;
  1468. End;
  1469. Function RefInSequence(Const Ref: TReference; Content: TContent): Boolean;
  1470. {checks the whole sequence of Content (so StartMod and and the next NrOfMods
  1471. Pai objects) to see whether Ref is used somewhere}
  1472. Var p: Pai;
  1473. Counter: Byte;
  1474. TmpResult: Boolean;
  1475. Begin
  1476. p := Content.StartMod;
  1477. TmpResult := False;
  1478. Counter := 1;
  1479. While Not(TmpResult) And
  1480. (Counter <= Content.NrOfMods) Do
  1481. Begin
  1482. If (p^.typ = ait_instruction) And
  1483. RefInInstruction(Ref, p)
  1484. Then TmpResult := True;
  1485. Inc(Counter);
  1486. GetNextInstruction(p,p)
  1487. End;
  1488. RefInSequence := TmpResult
  1489. End;
  1490. Procedure DestroyRefs(p: pai; Const Ref: TReference; WhichReg: TRegister);
  1491. {destroys all registers which possibly contain a reference to Ref, WhichReg
  1492. is the register whose contents are being written to memory (if this proc
  1493. is called because of a "mov?? %reg, (mem)" instruction)}
  1494. Var Counter: TRegister;
  1495. Begin
  1496. WhichReg := Reg32(WhichReg);
  1497. If ((Ref.base = ProcInfo.FramePointer) And
  1498. (Ref.Index = R_NO)) Or
  1499. Assigned(Ref.Symbol)
  1500. Then
  1501. {write something to a parameter, a local or global variable, so
  1502. * with uncertzain optimizations on:
  1503. - destroy the contents of registers whose contents have somewhere a
  1504. "mov?? (Ref), %reg". WhichReg (this is the register whose contents
  1505. are being written to memory) is not destroyed if it's StartMod is
  1506. of that form and NrOfMods = 1 (so if it holds ref, but is not a
  1507. pointer based on Ref)
  1508. * with uncertain optimizations off:
  1509. - also destroy registers that contain any pointer}
  1510. For Counter := R_EAX to R_EDI Do
  1511. With PPaiProp(p^.fileinfo.line)^.Regs[Counter] Do
  1512. Begin
  1513. If (typ = Con_Ref) And
  1514. (Not(cs_UncertainOpts in aktglobalswitches) And
  1515. (NrOfMods <> 1)
  1516. ) Or
  1517. (RefInSequence(Ref,PPaiProp(p^.fileinfo.line)^.Regs[Counter]) And
  1518. ((Counter <> WhichReg) Or
  1519. ((NrOfMods = 1) And
  1520. {StarMod is always of the type ait_instruction}
  1521. (Pai386(StartMod)^.op1t = top_ref) And
  1522. RefsEqual(TReference(Pai386(StartMod)^.op1^), Ref)
  1523. )
  1524. )
  1525. )
  1526. Then DestroyReg(PPaiProp(p^.fileinfo.line), Counter)
  1527. End
  1528. Else
  1529. {write something to a pointer location, so
  1530. * with uncertain optimzations on:
  1531. - do not destroy registers which contain a local/global variable or a
  1532. parameter, except if DestroyRefs is called because of a "movsl"
  1533. * with uncertain optimzations off:
  1534. - destroy every register which contains a memory location
  1535. }
  1536. For Counter := R_EAX to R_EDI Do
  1537. With PPaiProp(p^.fileinfo.line)^.Regs[Counter] Do
  1538. If (typ = Con_Ref) And
  1539. (Not(cs_UncertainOpts in aktglobalswitches) Or
  1540. {for movsl}
  1541. (Ref.Base = R_EDI) Or
  1542. {don't destroy if reg contains a parameter, local or global variable}
  1543. Not((NrOfMods = 1) And
  1544. (Pai386(StartMod)^.op1t = top_ref) And
  1545. ((PReference(Pai386(StartMod)^.op1)^.base = ProcInfo.FramePointer) Or
  1546. Assigned(PReference(Pai386(StartMod)^.op1)^.Symbol)
  1547. )
  1548. )
  1549. )
  1550. Then DestroyReg(PPaiProp(p^.FileInfo.Line), Counter)
  1551. End;
  1552. Procedure DestroyAllRegs(p: PPaiProp);
  1553. Var Counter: TRegister;
  1554. Begin {initializes/desrtoys all registers}
  1555. For Counter := R_EAX To R_EDI Do
  1556. DestroyReg(p, Counter);
  1557. p^.DirFlag := F_Unknown;
  1558. End;
  1559. Procedure Destroy(PaiObj: Pai; Opt: Longint; Op: Pointer);
  1560. Begin
  1561. Case Opt Of
  1562. top_reg: DestroyReg(PPaiProp(PaiObj^.fileinfo.line), TRegister(Op));
  1563. top_ref: DestroyRefs(PaiObj, TReference(Op^), R_NO);
  1564. top_symbol:;
  1565. End;
  1566. End;
  1567. Procedure ReadReg(p: PPaiProp; Reg: TRegister);
  1568. Begin
  1569. Reg := Reg32(Reg);
  1570. If Reg in [R_EAX..R_EDI] Then
  1571. IncState(p^.Regs[Reg32(Reg)].RState)
  1572. End;
  1573. Procedure ReadRef(p: PPaiProp; Ref: PReference);
  1574. Begin
  1575. If Ref^.Base <> R_NO Then
  1576. ReadReg(p, Ref^.Base);
  1577. If Ref^.Index <> R_NO Then
  1578. ReadReg(p, Ref^.Index);
  1579. End;
  1580. Procedure ReadOp(P: PPaiProp; opt: Longint; Op: Pointer);
  1581. Begin
  1582. Case Opt Of
  1583. top_reg: ReadReg(P, TRegister(Op));
  1584. top_ref: ReadRef(P, PReference(Op));
  1585. top_symbol:
  1586. End;
  1587. End;
  1588. Function DFAPass1(AsmL: PAasmOutput; BlockStart: Pai): Pai;
  1589. {gathers the RegAlloc data... still need to think about where to store it to
  1590. avoid global vars}
  1591. Var BlockEnd: Pai;
  1592. Begin
  1593. BlockEnd := FindLoHiLabels(AsmL, LoLab, HiLab, LabDif, BlockStart);
  1594. BuildLabelTableAndFixRegAlloc(AsmL, LTable, LoLab, LabDif, BlockStart, BlockEnd);
  1595. DFAPass1 := BlockEnd;
  1596. End;
  1597. Procedure DoDFAPass2(
  1598. {$Ifdef StateDebug}
  1599. AsmL: PAasmOutput;
  1600. {$endif statedebug}
  1601. BlockStart, BlockEnd: Pai);
  1602. {Analyzes the Data Flow of an assembler list. Starts creating the reg
  1603. contents for the instructions starting with p. Returns the last pai which has
  1604. been processed}
  1605. Var
  1606. CurProp: PPaiProp;
  1607. {$ifdef AnalyzeLoops}
  1608. TmpState: Byte;
  1609. {$endif AnalyzeLoops}
  1610. Cnt, InstrCnt : Longint;
  1611. InstrProp: TAsmInstrucProp;
  1612. UsedRegs: TRegSet;
  1613. p, hp : Pai;
  1614. TmpRef: TReference;
  1615. TmpReg: TRegister;
  1616. Begin
  1617. p := BlockStart;
  1618. UsedRegs := [];
  1619. UpdateUsedregs(UsedRegs, p);
  1620. If (BlockStart^.typ in SkipInstr) Then
  1621. GetNextInstruction(p, p);
  1622. BlockStart := p;
  1623. InstrCnt := 1;
  1624. FillChar(NrOfInstrSinceLastMod, SizeOf(NrOfInstrSinceLastMod), 0);
  1625. While (P <> BlockEnd) Do
  1626. Begin
  1627. {$IfDef TP}
  1628. New(CurProp);
  1629. {$Else TP}
  1630. CurProp := @PaiPropBlock^[InstrCnt];
  1631. {$EndIf TP}
  1632. If (p <> BlockStart)
  1633. Then
  1634. Begin
  1635. {$ifdef JumpAnal}
  1636. If (p^.Typ <> ait_label) Then
  1637. {$endif JumpAnal}
  1638. Begin
  1639. GetLastInstruction(p, hp);
  1640. CurProp^.Regs := PPaiProp(hp^.fileinfo.line)^.Regs;
  1641. CurProp^.DirFlag := PPaiProp(hp^.fileinfo.line)^.DirFlag;
  1642. End
  1643. End
  1644. Else
  1645. Begin
  1646. FillChar(CurProp^, SizeOf(CurProp^), 0);
  1647. { For TmpReg := R_EAX to R_EDI Do
  1648. CurProp^.Regs[TmpReg].WState := 1;}
  1649. End;
  1650. CurProp^.UsedRegs := UsedRegs;
  1651. CurProp^.CanBeRemoved := False;
  1652. UpdateUsedRegs(UsedRegs, Pai(p^.Next));
  1653. {$ifdef TP}
  1654. CurProp^.linesave := p^.fileinfo.line;
  1655. PPaiProp(p^.fileinfo.line) := CurProp;
  1656. {$Endif TP}
  1657. For TmpReg := R_EAX To R_EDI Do
  1658. Inc(NrOfInstrSinceLastMod[TmpReg]);
  1659. Case p^.typ Of
  1660. ait_label:
  1661. {$Ifndef JumpAnal}
  1662. If (Pai_label(p)^.l^.is_used) Then
  1663. DestroyAllRegs(CurProp);
  1664. {$Else JumpAnal}
  1665. Begin
  1666. If (Pai_Label(p)^.is_used) Then
  1667. With LTable^[Pai_Label(p)^.l^.nb-LoLab] Do
  1668. {$IfDef AnalyzeLoops}
  1669. If (RefsFound = Pai_Label(p)^.l^.RefCount)
  1670. {$Else AnalyzeLoops}
  1671. If (JmpsProcessed = Pai_Label(p)^.l^.RefCount)
  1672. {$EndIf AnalyzeLoops}
  1673. Then
  1674. {all jumps to this label have been found}
  1675. {$IfDef AnalyzeLoops}
  1676. If (JmpsProcessed > 0)
  1677. Then
  1678. {$EndIf AnalyzeLoops}
  1679. {we've processed at least one jump to this label}
  1680. Begin
  1681. If (GetLastInstruction(p, hp) And
  1682. Not(((hp^.typ = ait_labeled_instruction) or
  1683. (hp^.typ = ait_instruction)) And
  1684. (pai386_labeled(hp)^.opcode = A_JMP))
  1685. Then
  1686. {previous instruction not a JMP -> the contents of the registers after the
  1687. previous intruction has been executed have to be taken into account as well}
  1688. For TmpReg := R_EAX to R_EDI Do
  1689. Begin
  1690. If (CurProp^.Regs[TmpReg].WState <>
  1691. PPaiProp(hp^.FileInfo.Line)^.Regs[TmpReg].WState)
  1692. Then DestroyReg(CurProp, TmpReg)
  1693. End
  1694. End
  1695. {$IfDef AnalyzeLoops}
  1696. Else
  1697. {a label from a backward jump (e.g. a loop), no jump to this label has
  1698. already been processed}
  1699. If GetLastInstruction(p, hp) And
  1700. Not(hp^.typ = ait_labeled_instruction) And
  1701. (pai386_labeled(hp)^.opcode = A_JMP))
  1702. Then
  1703. {previous instruction not a jmp, so keep all the registers' contents from the
  1704. previous instruction}
  1705. Begin
  1706. CurProp^.Regs := PPaiProp(hp^.FileInfo.Line)^.Regs;
  1707. CurProp^.DirFlag := PPaiProp(hp^.FileInfo.Line)^.DirFlag;
  1708. End
  1709. Else
  1710. {previous instruction a jmp and no jump to this label processed yet}
  1711. Begin
  1712. hp := p;
  1713. Cnt := InstrCnt;
  1714. {continue until we find a jump to the label or a label which has already
  1715. been processed}
  1716. While GetNextInstruction(hp, hp) And
  1717. Not((hp^.typ = ait_labeled_instruction) And
  1718. (pai386_labeled(hp)^.lab^.nb = Pai_Label(p)^.l^.nb)) And
  1719. Not((hp^.typ = ait_label) And
  1720. (LTable^[Pai_Label(hp)^.l^.nb-LoLab].RefsFound
  1721. = Pai_Label(hp)^.l^.RefCount) And
  1722. (LTable^[Pai_Label(hp)^.l^.nb-LoLab].JmpsProcessed > 0)) Do
  1723. Inc(Cnt);
  1724. If (hp^.typ = ait_label)
  1725. Then
  1726. {there's a processed label after the current one}
  1727. Begin
  1728. CurProp^.Regs := PaiPropBlock^[Cnt].Regs;
  1729. CurProp^.DirFlag := PaiPropBlock^[Cnt].DirFlag;
  1730. End
  1731. Else
  1732. {there's no label anymore after the current one, or they haven't been
  1733. processed yet}
  1734. Begin
  1735. GetLastInstruction(p, hp);
  1736. CurProp^.Regs := PPaiProp(hp^.FileInfo.Line)^.Regs;
  1737. CurProp^.DirFlag := PPaiProp(hp^.FileInfo.Line)^.DirFlag;
  1738. DestroyAllRegs(PPaiProp(hp^.FileInfo.Line))
  1739. End
  1740. End
  1741. {$EndIf AnalyzeLoops}
  1742. Else
  1743. {not all references to this label have been found, so destroy all registers}
  1744. Begin
  1745. GetLastInstruction(p, hp);
  1746. CurProp^.Regs := PPaiProp(hp^.FileInfo.Line)^.Regs;
  1747. CurProp^.DirFlag := PPaiProp(hp^.FileInfo.Line)^.DirFlag;
  1748. DestroyAllRegs(CurProp)
  1749. End;
  1750. End;
  1751. {$EndIf JumpAnal}
  1752. ait_labeled_instruction:
  1753. {$IfNDef JumpAnal}
  1754. ;
  1755. {$Else JumpAnal}
  1756. With LTable^[pai386_labeled(p)^.lab^.nb-LoLab] Do
  1757. If (RefsFound = pai386_labeled(p)^.lab^.RefCount) Then
  1758. Begin
  1759. If (InstrCnt < InstrNr)
  1760. Then
  1761. {forward jump}
  1762. If (JmpsProcessed = 0) Then
  1763. {no jump to this label has been processed yet}
  1764. Begin
  1765. PaiPropBlock^[InstrNr].Regs := CurProp^.Regs;
  1766. PaiPropBlock^[InstrNr].DirFlag := CurProp^.DirFlag;
  1767. Inc(JmpsProcessed);
  1768. End
  1769. Else
  1770. Begin
  1771. For TmpReg := R_EAX to R_EDI Do
  1772. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1773. CurProp^.Regs[TmpReg].WState) Then
  1774. DestroyReg(@PaiPropBlock^[InstrNr], TmpReg);
  1775. Inc(JmpsProcessed);
  1776. End
  1777. {$ifdef AnalyzeLoops}
  1778. Else
  1779. { backward jump, a loop for example}
  1780. { If (JmpsProcessed > 0) Or
  1781. Not(GetLastInstruction(PaiObj, hp) And
  1782. (hp^.typ = ait_labeled_instruction) And
  1783. (pai386_labeled(hp)^.opcode = A_JMP))
  1784. Then}
  1785. {instruction prior to label is not a jmp, or at least one jump to the label
  1786. has yet been processed}
  1787. Begin
  1788. Inc(JmpsProcessed);
  1789. For TmpReg := R_EAX to R_EDI Do
  1790. If (PaiPropBlock^[InstrNr].Regs[TmpReg].WState <>
  1791. CurProp^.Regs[TmpReg].WState)
  1792. Then
  1793. Begin
  1794. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1795. Cnt := InstrNr;
  1796. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1797. Begin
  1798. DestroyReg(@PaiPropBlock^[Cnt], TmpReg);
  1799. Inc(Cnt);
  1800. End;
  1801. While (Cnt <= InstrCnt) Do
  1802. Begin
  1803. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1804. Inc(Cnt)
  1805. End
  1806. End;
  1807. End
  1808. { Else }
  1809. {instruction prior to label is a jmp and no jumps to the label have yet been
  1810. processed}
  1811. { Begin
  1812. Inc(JmpsProcessed);
  1813. For TmpReg := R_EAX to R_EDI Do
  1814. Begin
  1815. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1816. Cnt := InstrNr;
  1817. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1818. Begin
  1819. PaiPropBlock^[Cnt].Regs[TmpReg] := CurProp^.Regs[TmpReg];
  1820. Inc(Cnt);
  1821. End;
  1822. TmpState := PaiPropBlock^[InstrNr].Regs[TmpReg].WState;
  1823. While (TmpState = PaiPropBlock^[Cnt].Regs[TmpReg].WState) Do
  1824. Begin
  1825. DestroyReg(@PaiPropBlock^[Cnt], TmpReg);
  1826. Inc(Cnt);
  1827. End;
  1828. While (Cnt <= InstrCnt) Do
  1829. Begin
  1830. Inc(PaiPropBlock^[Cnt].Regs[TmpReg].WState);
  1831. Inc(Cnt)
  1832. End
  1833. End
  1834. End}
  1835. {$endif AnalyzeLoops}
  1836. End;
  1837. {$EndIf JumpAnal}
  1838. {$ifdef GDB}
  1839. ait_stabs, ait_stabn, ait_stab_function_name:;
  1840. {$endif GDB}
  1841. ait_instruction:
  1842. Begin
  1843. InstrProp := AsmInstr[Pai386(p)^.opcode];
  1844. Case Pai386(p)^.opcode Of
  1845. A_MOV, A_MOVZX, A_MOVSX:
  1846. Begin
  1847. Case Pai386(p)^.op1t Of
  1848. Top_Reg:
  1849. Case Pai386(p)^.op2t Of
  1850. Top_Reg:
  1851. Begin
  1852. DestroyReg(CurProp, TRegister(Pai386(p)^.op2));
  1853. ReadReg(CurProp, TRegister(Pai386(p)^.op1));
  1854. { CurProp^.Regs[TRegister(Pai386(p)^.op2)] :=
  1855. CurProp^.Regs[TRegister(Pai386(p)^.op1)];
  1856. If (CurProp^.Regs[TRegister(Pai386(p)^.op2)].ModReg = R_NO) Then
  1857. CurProp^.Regs[TRegister(Pai386(p)^.op2)].ModReg :=
  1858. Tregister(Pai386(p)^.op1);}
  1859. End;
  1860. Top_Ref:
  1861. Begin
  1862. ReadReg(CurProp, TRegister(Pai386(p)^.op1));
  1863. ReadRef(CurProp, PReference(Pai386(p)^.op2));
  1864. DestroyRefs(p, TReference(Pai386(p)^.op2^), TRegister(Pai386(p)^.op1));
  1865. End;
  1866. End;
  1867. Top_Ref:
  1868. Begin {destination is always a register in this case}
  1869. ReadRef(CurProp, PReference(Pai386(p)^.op1));
  1870. ReadReg(CurProp, TRegister(Pai386(p)^.Op2));
  1871. TmpReg := Reg32(TRegister(Pai386(p)^.op2));
  1872. If RegInRef(TmpReg, TReference(Pai386(p)^.op1^)) And
  1873. (CurProp^.Regs[TmpReg].Typ = Con_Ref)
  1874. Then
  1875. Begin
  1876. With CurProp^.Regs[TmpReg] Do
  1877. Begin
  1878. IncState(WState);
  1879. {also store how many instructions are part of the sequence in the first
  1880. instructions PPaiProp, so it can be easily accessed from within
  1881. CheckSequence}
  1882. Inc(NrOfMods, NrOfInstrSinceLastMod[TmpReg]);
  1883. PPaiProp(Pai(StartMod)^.fileinfo.line)^.Regs[TmpReg].NrOfMods := NrOfMods;
  1884. NrOfInstrSinceLastMod[TmpReg] := 0;
  1885. End;
  1886. End
  1887. Else
  1888. Begin
  1889. DestroyReg(CurProp, TmpReg);
  1890. If Not(RegInRef(TmpReg, TReference(Pai386(p)^.op1^))) Then
  1891. With CurProp^.Regs[TmpReg] Do
  1892. Begin
  1893. Typ := Con_Ref;
  1894. StartMod := p;
  1895. NrOfMods := 1;
  1896. End
  1897. End;
  1898. {$ifdef StateDebug}
  1899. hp := new(pai_asm_comment,init(strpnew(att_reg2str[TmpReg]+': '+tostr(CurProp^.Regs[TmpReg].WState))));
  1900. InsertLLItem(AsmL, p, p^.next, hp);
  1901. {$endif StateDebug}
  1902. End;
  1903. Top_Const:
  1904. Begin
  1905. Case Pai386(p)^.op2t Of
  1906. Top_Reg:
  1907. Begin
  1908. TmpReg := Reg32(TRegister(Pai386(p)^.op2));
  1909. With CurProp^.Regs[TmpReg] Do
  1910. Begin
  1911. DestroyReg(CurProp, TmpReg);
  1912. typ := Con_Const;
  1913. StartMod := Pai386(p)^.op1;
  1914. End
  1915. End;
  1916. Top_Ref:
  1917. Begin
  1918. ReadRef(CurProp, PReference(Pai386(p)^.op2));
  1919. DestroyRefs(P, TReference(Pai386(p)^.op2^), R_NO);
  1920. End;
  1921. End;
  1922. End;
  1923. End;
  1924. End;
  1925. A_IMUL:
  1926. Begin
  1927. ReadOp(CurProp, Pai386(p)^.Op1t, Pai386(p)^.Op1);
  1928. If (Pai386(p)^.Op2t = Top_Ref) Then
  1929. ReadOp(CurProp, Pai386(p)^.Op2t, Pai386(p)^.Op2)
  1930. Else ReadOp(CurProp, Pai386(p)^.Op2t, Pointer(Longint(TwoWords(Pai386(p)^.Op2).Word1)));
  1931. ReadOp(CurProp, Pai386(p)^.Op3t, Pointer(LongInt(TwoWords(Pai386(p)^.Op2).Word2)));
  1932. If (Pai386(p)^.Op3t = top_none)
  1933. Then
  1934. If (Pai386(p)^.Op2t = top_none)
  1935. Then
  1936. Begin
  1937. DestroyReg(CurProp, R_EAX);
  1938. DestroyReg(CurProp, R_EDX)
  1939. End
  1940. Else Destroy(p, Pai386(p)^.Op2t, Pai386(p)^.Op2)
  1941. Else DestroyReg(CurProp, TRegister(longint(twowords(Pai386(p)^.Op2).word2)));
  1942. End;
  1943. A_XOR:
  1944. Begin
  1945. ReadOp(CurProp, Pai386(p)^.Op1t, Pai386(p)^.Op1);
  1946. ReadOp(CurProp, Pai386(p)^.Op2t, Pai386(p)^.Op2);
  1947. If (Pai386(p)^.op1t = top_reg) And
  1948. (Pai386(p)^.op2t = top_reg) And
  1949. (Pai386(p)^.op1 = Pai386(p)^.op2)
  1950. Then
  1951. Begin
  1952. DestroyReg(CurProp, Tregister(Pai386(p)^.op1));
  1953. CurProp^.Regs[Reg32(Tregister(Pai386(p)^.op1))].typ := Con_Const;
  1954. CurProp^.Regs[Reg32(Tregister(Pai386(p)^.op1))].StartMod := Pointer(0)
  1955. End
  1956. Else Destroy(p, Pai386(p)^.op2t, Pai386(p)^.op2);
  1957. End
  1958. Else
  1959. Begin
  1960. Cnt := 1;
  1961. While (Cnt <= MaxCh) And
  1962. (InstrProp.Ch[Cnt] <> C_None) Do
  1963. Begin
  1964. Case InstrProp.Ch[Cnt] Of
  1965. C_REAX..C_REDI: ReadReg(CurProp,TCh2Reg(InstrProp.Ch[Cnt]));
  1966. C_WEAX..C_RWEDI:
  1967. Begin
  1968. If (InstrProp.Ch[Cnt] >= C_RWEAX) Then
  1969. ReadReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]));
  1970. DestroyReg(CurProp, TCh2Reg(InstrProp.Ch[Cnt]));
  1971. End;
  1972. C_CDirFlag: CurProp^.DirFlag := F_NotSet;
  1973. C_SDirFlag: CurProp^.DirFlag := F_Set;
  1974. C_ROp1: ReadOp(CurProp, Pai386(p)^.op1t, Pai386(p)^.op1);
  1975. C_ROp2: If (Pai386(p)^.Op3t = top_none) Then
  1976. ReadOp(CurProp, Pai386(p)^.op2t, Pai386(p)^.op2)
  1977. Else ReadOp(CurProp, Pai386(p)^.op2t, Pointer(Longint(TwoWords(Pai386(p)^.op2).word1)));
  1978. C_ROp3: ReadOp(CurProp, Pai386(p)^.op3t, Pointer(Longint(TwoWords(Pai386(p)^.op2).word2)));
  1979. C_WOp1..C_RWOp1:
  1980. Begin
  1981. If (InstrProp.Ch[Cnt] = C_RWOp1) Then
  1982. ReadOp(CurProp, Pai386(p)^.op1t, Pai386(p)^.op1);
  1983. Destroy(p, Pai386(p)^.op1t, Pai386(p)^.op1);
  1984. End;
  1985. C_WOp2..C_RWOp2:
  1986. Begin
  1987. If (InstrProp.Ch[Cnt] = C_RWOp2) Then
  1988. If (Pai386(p)^.Op3t = top_none) Then
  1989. ReadOp(CurProp, Pai386(p)^.op2t, Pai386(p)^.op2)
  1990. Else ReadOp(CurProp, Pai386(p)^.op2t, Pointer(Longint(TwoWords(Pai386(p)^.op2).word1)));
  1991. If (Pai386(p)^.Op3t = top_none) Then
  1992. Destroy(p, Pai386(p)^.op2t, Pai386(p)^.op2)
  1993. Else Destroy(p, Pai386(p)^.op2t, Pointer(Longint(TwoWords(Pai386(p)^.op2).word1)));
  1994. End;
  1995. C_WOp3..C_RWOp3:
  1996. Begin
  1997. If (InstrProp.Ch[Cnt] = C_RWOp3) Then
  1998. ReadOp(CurProp, Pai386(p)^.op3t, Pointer(Longint(TwoWords(Pai386(p)^.op2).word2)));
  1999. Destroy(p, Pai386(p)^.op3t, Pointer(Longint(TwoWords(Pai386(p)^.op2).word2)));
  2000. End;
  2001. C_WMemEDI:
  2002. Begin
  2003. ReadReg(CurProp, R_EDI);
  2004. FillChar(TmpRef, SizeOf(TmpRef), 0);
  2005. TmpRef.Base := R_EDI;
  2006. DestroyRefs(p, TmpRef, R_NO)
  2007. End;
  2008. C_RFlags, C_WFlags, C_RWFlags, C_FPU:
  2009. Else
  2010. Begin
  2011. DestroyAllRegs(CurProp);
  2012. End;
  2013. End;
  2014. Inc(Cnt);
  2015. End
  2016. End;
  2017. End;
  2018. End
  2019. Else
  2020. Begin
  2021. DestroyAllRegs(CurProp);
  2022. End;
  2023. End;
  2024. Inc(InstrCnt);
  2025. GetNextInstruction(p, p);
  2026. End;
  2027. End;
  2028. Function InitDFAPass2(AsmL: PAasmOutput; BlockStart, BlockEnd: Pai): Boolean;
  2029. {reserves memory for the PPaiProps in one big memory block when not using
  2030. TP, returns False if not enough memory is available for the optimizer in all
  2031. cases}
  2032. Var p: Pai;
  2033. Count: Longint;
  2034. { TmpStr: String; }
  2035. Begin
  2036. P := BlockStart;
  2037. SkipHead(P);
  2038. NrOfPaiObjs := 0;
  2039. While (P <> BlockEnd) Do
  2040. Begin
  2041. {$IfDef JumpAnal}
  2042. Case P^.Typ Of
  2043. ait_labeled_instruction:
  2044. begin
  2045. If (pai386_labeled(P)^.lab^.nb >= LoLab) And
  2046. (pai386_labeled(P)^.lab^.nb <= HiLab) Then
  2047. Inc(LTable^[pai386_labeled(P)^.lab^.nb-LoLab].RefsFound);
  2048. end;
  2049. ait_label:
  2050. Begin
  2051. If (Pai_Label(p)^.l^.is_used) Then
  2052. LTable^[Pai_Label(P)^.l^.nb-LoLab].InstrNr := NrOfPaiObjs
  2053. End;
  2054. { ait_instruction:
  2055. Begin
  2056. If (Pai386(p)^.opcode = A_PUSH) And
  2057. (Pai386(p)^.op1t = top_symbol) And
  2058. (PCSymbol(Pai386(p)^.op1)^.offset = 0) Then
  2059. Begin
  2060. TmpStr := StrPas(PCSymbol(Pai386(p)^.op1)^.symbol);
  2061. If}
  2062. End;
  2063. {$EndIf JumpAnal}
  2064. Inc(NrOfPaiObjs);
  2065. GetNextInstruction(p, p);
  2066. End;
  2067. {$IfDef TP}
  2068. If (MemAvail < (SizeOf(TPaiProp)*NrOfPaiObjs))
  2069. Or (NrOfPaiObjs = 0)
  2070. {this doesn't have to be one contiguous block}
  2071. Then InitDFAPass2 := False
  2072. Else InitDFAPass2 := True;
  2073. {$Else}
  2074. {Uncomment the next line to see how much memory the reloading optimizer needs}
  2075. { Writeln((NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4)));}
  2076. {no need to check mem/maxavail, we've got as much virtual memory as we want}
  2077. If NrOfPaiObjs <> 0 Then
  2078. Begin
  2079. InitDFAPass2 := True;
  2080. GetMem(PaiPropBlock, NrOfPaiObjs*(((SizeOf(TPaiProp)+3)div 4)*4));
  2081. p := BlockStart;
  2082. SkipHead(p);
  2083. For Count := 1 To NrOfPaiObjs Do
  2084. Begin
  2085. PaiPropBlock^[Count].LineSave := p^.fileinfo.line;
  2086. PPaiProp(p^.fileinfo.line) := @PaiPropBlock^[Count];
  2087. GetNextInstruction(p, p);
  2088. End;
  2089. End
  2090. Else InitDFAPass2 := False;
  2091. {$EndIf TP}
  2092. End;
  2093. Function DFAPass2(AsmL: PAasmOutPut; BlockStart, BlockEnd: Pai): Boolean;
  2094. Begin
  2095. If InitDFAPass2(AsmL, BlockStart, BlockEnd) Then
  2096. Begin
  2097. DoDFAPass2(
  2098. {$ifdef statedebug}
  2099. asml,
  2100. {$endif statedebug}
  2101. BlockStart, BlockEnd);
  2102. DFAPass2 := True
  2103. End
  2104. Else DFAPass2 := False;
  2105. End;
  2106. Procedure ShutDownDFA;
  2107. Begin
  2108. If LabDif <> 0 Then
  2109. FreeMem(LTable, LabDif*SizeOf(TLabelTableItem));
  2110. End;
  2111. End.
  2112. {
  2113. $Log$
  2114. Revision 1.39 1999-02-26 00:48:18 peter
  2115. * assembler writers fixed for ag386bin
  2116. Revision 1.38 1999/02/25 21:02:34 peter
  2117. * ag386bin updates
  2118. + coff writer
  2119. Revision 1.37 1999/02/22 02:15:20 peter
  2120. * updates for ag386bin
  2121. Revision 1.36 1999/01/20 17:41:26 jonas
  2122. * small bugfix (memory corruption could occur when certain fpu instructions
  2123. were encountered)
  2124. Revision 1.35 1999/01/08 12:39:22 florian
  2125. Changes of Alexander Stohr integrated:
  2126. + added KNI opcodes
  2127. + added KNI registers
  2128. + added 3DNow! opcodes
  2129. + added 64 bit and 128 bit register flags
  2130. * translated a few comments into english
  2131. Revision 1.34 1998/12/29 18:48:19 jonas
  2132. + optimize pascal code surrounding assembler blocks
  2133. Revision 1.33 1998/12/17 16:37:38 jonas
  2134. + extra checks in RegsEquivalent so some more optimizations can be done (which
  2135. where disabled by the second fix from revision 1.22)
  2136. Revision 1.32 1998/12/15 19:33:58 jonas
  2137. * uncommented OpsEqual & added to interface because popt386 uses it now
  2138. Revision 1.31 1998/12/11 00:03:13 peter
  2139. + globtype,tokens,version unit splitted from globals
  2140. Revision 1.30 1998/12/02 16:23:39 jonas
  2141. * changed "if longintvar in set" to case or "if () or () .." statements
  2142. * tree.pas: changed inlinenumber (and associated constructor/vars) to a byte
  2143. Revision 1.29 1998/11/26 21:45:31 jonas
  2144. - removed A_CLTD opcode (use A_CDQ instead)
  2145. * changed cbw, cwde and cwd to cbtw, cwtl and cwtd in att_op2str array
  2146. * in daopt386: adapted AsmInstr array to reflect changes + fixed line too long
  2147. Revision 1.27 1998/11/24 19:47:22 jonas
  2148. * fixed problems posible with 3 operand instructions
  2149. Revision 1.26 1998/11/24 12:50:09 peter
  2150. * fixed crash
  2151. Revision 1.25 1998/11/18 17:58:22 jonas
  2152. + gathering of register reading data, nowhere used yet (necessary for instruction scheduling)
  2153. Revision 1.24 1998/11/13 10:13:44 peter
  2154. + cpuid,emms support for asm readers
  2155. Revision 1.23 1998/11/09 19:40:46 jonas
  2156. * fixed comments from last commit (apparently there's still a 255 char limit :( )
  2157. Revision 1.22 1998/11/09 19:33:40 jonas
  2158. * changed specific bugfix (which was actually wrong implemented, but
  2159. did the right thing in most cases nevertheless) to general bugfix
  2160. * fixed bug that caused
  2161. mov (ebp), edx mov (ebp), edx
  2162. mov (edx), edx mov (edx), edx
  2163. ... being changed to ...
  2164. mov (ebp), edx mov edx, eax
  2165. mov (eax), eax
  2166. but this disabled another small correct optimization...
  2167. Revision 1.21 1998/11/02 23:17:49 jonas
  2168. * fixed bug shown in sortbug program from fpc-devel list
  2169. Revision 1.20 1998/10/22 13:24:51 jonas
  2170. * changed TRegSet to a small set
  2171. Revision 1.19 1998/10/20 09:29:24 peter
  2172. * bugfix so that code like
  2173. movl 48(%esi),%esi movl 48(%esi),%esi
  2174. pushl %esi doesn't get changed to pushl %esi
  2175. movl 48(%esi),%edi movl %esi,%edi
  2176. Revision 1.18 1998/10/07 16:27:02 jonas
  2177. * changed state to WState (WriteState), added RState for future use in
  2178. instruction scheduling
  2179. * RegAlloc data from the CG is now completely being patched and corrected (I
  2180. think)
  2181. Revision 1.17 1998/10/02 17:30:20 jonas
  2182. * small patches to regdealloc data
  2183. Revision 1.16 1998/10/01 20:21:47 jonas
  2184. * inter-register CSE, still requires some tweaks (peepholeoptpass2, better RegAlloc)
  2185. Revision 1.15 1998/09/20 18:00:20 florian
  2186. * small compiling problems fixed
  2187. Revision 1.14 1998/09/20 17:12:36 jonas
  2188. * small fix for uncertain optimizations & more cleaning up
  2189. Revision 1.12 1998/09/16 18:00:01 jonas
  2190. * optimizer now completely dependant on GetNext/GetLast instruction, works again with -dRegAlloc
  2191. Revision 1.11 1998/09/15 14:05:27 jonas
  2192. * fixed optimizer incompatibilities with freelabel code in psub
  2193. Revision 1.10 1998/09/09 15:33:58 peter
  2194. * removed warnings
  2195. Revision 1.9 1998/09/03 16:24:51 florian
  2196. * bug of type conversation from dword to real fixed
  2197. * bug fix of Jonas applied
  2198. Revision 1.8 1998/08/28 10:56:59 peter
  2199. * removed warnings
  2200. Revision 1.7 1998/08/19 16:07:44 jonas
  2201. * changed optimizer switches + cleanup of DestroyRefs in daopt386.pas
  2202. Revision 1.6 1998/08/10 14:49:57 peter
  2203. + localswitches, moduleswitches, globalswitches splitting
  2204. Revision 1.5 1998/08/09 13:56:24 jonas
  2205. * small bugfix for uncertain optimizations in DestroyRefs
  2206. Revision 1.4 1998/08/06 19:40:25 jonas
  2207. * removed $ before and after Log in comment
  2208. Revision 1.3 1998/08/05 16:00:14 florian
  2209. * some fixes for ansi strings
  2210. * log to Log changed
  2211. }