daopt386.pas 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Jonas Maebe, member of the Freepascal
  4. development team
  5. This unit contains the data flow analyzer and several helper procedures
  6. and functions.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ****************************************************************************
  19. }
  20. unit daopt386;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. globtype,
  25. cclasses,aasmbase,aasmtai,aasmcpu,cgbase,
  26. cpubase,optbase;
  27. {******************************* Constants *******************************}
  28. const
  29. { Possible register content types }
  30. con_Unknown = 0;
  31. con_ref = 1;
  32. con_const = 2;
  33. { The contents aren't usable anymore for CSE, but they may still be }
  34. { usefull for detecting whether the result of a load is actually used }
  35. con_invalid = 3;
  36. { the reverse of the above (in case a (conditional) jump is encountered): }
  37. { CSE is still possible, but the original instruction can't be removed }
  38. con_noRemoveRef = 4;
  39. { same, but for constants }
  40. con_noRemoveConst = 5;
  41. {********************************* Types *********************************}
  42. type
  43. TRegArray = Array[RS_EAX..RS_ESP] of tsuperregister;
  44. TRegSet = Set of RS_EAX..RS_ESP;
  45. toptreginfo = Record
  46. NewRegsEncountered, OldRegsEncountered: TRegSet;
  47. RegsLoadedForRef: TRegSet;
  48. regsStillUsedAfterSeq: TRegSet;
  49. lastReload: array[RS_EAX..RS_ESP] of tai;
  50. New2OldReg: TRegArray;
  51. end;
  52. {possible actions on an operand: read, write or modify (= read & write)}
  53. TOpAction = (OpAct_Read, OpAct_Write, OpAct_Modify, OpAct_Unknown);
  54. {the possible states of a flag}
  55. TFlagContents = (F_Unknown, F_notSet, F_Set);
  56. TContent = Packed Record
  57. {start and end of block instructions that defines the
  58. content of this register.}
  59. StartMod: tai;
  60. MemWrite: taicpu;
  61. {how many instructions starting with StarMod does the block consist of}
  62. NrOfMods: Byte;
  63. {the type of the content of the register: unknown, memory, constant}
  64. Typ: Byte;
  65. case byte of
  66. {starts at 0, gets increased everytime the register is written to}
  67. 1: (WState: Byte;
  68. {starts at 0, gets increased everytime the register is read from}
  69. RState: Byte);
  70. { to compare both states in one operation }
  71. 2: (state: word);
  72. end;
  73. {Contents of the integer registers}
  74. TRegContent = Array[RS_EAX..RS_ESP] Of TContent;
  75. {contents of the FPU registers}
  76. // TRegFPUContent = Array[RS_ST..RS_ST7] Of TContent;
  77. {$ifdef tempOpts}
  78. { linked list which allows searching/deleting based on value, no extra frills}
  79. PSearchLinkedListItem = ^TSearchLinkedListItem;
  80. TSearchLinkedListItem = object(TLinkedList_Item)
  81. constructor init;
  82. function equals(p: PSearchLinkedListItem): boolean; virtual;
  83. end;
  84. PSearchDoubleIntItem = ^TSearchDoubleInttem;
  85. TSearchDoubleIntItem = object(TLinkedList_Item)
  86. constructor init(_int1,_int2: longint);
  87. function equals(p: PSearchLinkedListItem): boolean; virtual;
  88. private
  89. int1, int2: longint;
  90. end;
  91. PSearchLinkedList = ^TSearchLinkedList;
  92. TSearchLinkedList = object(TLinkedList)
  93. function searchByValue(p: PSearchLinkedListItem): boolean;
  94. procedure removeByValue(p: PSearchLinkedListItem);
  95. end;
  96. {$endif tempOpts}
  97. {information record with the contents of every register. Every tai object
  98. gets one of these assigned: a pointer to it is stored in the OptInfo field}
  99. TtaiProp = Record
  100. Regs: TRegContent;
  101. { FPURegs: TRegFPUContent;} {currently not yet used}
  102. { allocated Registers }
  103. UsedRegs: TRegSet;
  104. { status of the direction flag }
  105. DirFlag: TFlagContents;
  106. {$ifdef tempOpts}
  107. { currently used temps }
  108. tempAllocs: PSearchLinkedList;
  109. {$endif tempOpts}
  110. { can this instruction be removed? }
  111. CanBeRemoved: Boolean;
  112. { are the resultflags set by this instruction used? }
  113. FlagsUsed: Boolean;
  114. end;
  115. ptaiprop = ^TtaiProp;
  116. TtaiPropBlock = Array[1..250000] Of TtaiProp;
  117. PtaiPropBlock = ^TtaiPropBlock;
  118. TInstrSinceLastMod = Array[RS_EAX..RS_ESP] Of Byte;
  119. TLabelTableItem = Record
  120. taiObj: tai;
  121. {$ifDef JumpAnal}
  122. InstrNr: Longint;
  123. RefsFound: Word;
  124. JmpsProcessed: Word
  125. {$endif JumpAnal}
  126. end;
  127. TLabelTable = Array[0..2500000] Of TLabelTableItem;
  128. PLabelTable = ^TLabelTable;
  129. {*********************** procedures and functions ************************}
  130. procedure InsertLLItem(AsmL: TAAsmOutput; prev, foll, new_one: TLinkedListItem);
  131. function RefsEquivalent(const R1, R2: TReference; var RegInfo: toptreginfo; OpAct: TOpAction): Boolean;
  132. function RefsEqual(const R1, R2: TReference): Boolean;
  133. function IsGP32Reg(reg: TRegister): Boolean;
  134. function reginref(supreg: tsuperregister; const ref: treference): boolean;
  135. function RegReadByInstruction(supreg: tsuperregister; hp: tai): boolean;
  136. function RegModifiedByInstruction(supreg: tsuperregister; p1: tai): boolean;
  137. function RegInInstruction(supreg: tsuperregister; p1: tai): boolean;
  138. function reginop(supreg: tsuperregister; const o:toper): boolean;
  139. function instrWritesFlags(p: tai): boolean;
  140. function instrReadsFlags(p: tai): boolean;
  141. function writeToMemDestroysContents(regWritten: tsuperregister; const ref: treference;
  142. supreg: tsuperregister; const c: tcontent; var invalsmemwrite: boolean): boolean;
  143. function writeToRegDestroysContents(destReg, supreg: tsuperregister;
  144. const c: tcontent): boolean;
  145. function writeDestroysContents(const op: toper; supreg: tsuperregister;
  146. const c: tcontent): boolean;
  147. function GetNextInstruction(Current: tai; var Next: tai): Boolean;
  148. function GetLastInstruction(Current: tai; var Last: tai): Boolean;
  149. procedure SkipHead(var p: tai);
  150. function labelCanBeSkipped(p: tai_label): boolean;
  151. procedure RemoveLastDeallocForFuncRes(asmL: TAAsmOutput; p: tai);
  152. function regLoadedWithNewValue(supreg: tsuperregister; canDependOnPrevValue: boolean;
  153. hp: tai): boolean;
  154. procedure UpdateUsedRegs(var UsedRegs: TRegSet; p: tai);
  155. procedure AllocRegBetween(asml: taasmoutput; reg: tregister; p1, p2: tai);
  156. function FindRegDealloc(supreg: tsuperregister; p: tai): boolean;
  157. //function RegsEquivalent(OldReg, NewReg: tregister; var RegInfo: toptreginfo; OpAct: TopAction): Boolean;
  158. function InstructionsEquivalent(p1, p2: tai; var RegInfo: toptreginfo): Boolean;
  159. function sizescompatible(loadsize,newsize: topsize): boolean;
  160. function OpsEqual(const o1,o2:toper): Boolean;
  161. type
  162. tdfaobj = class
  163. constructor create(_list: taasmoutput); virtual;
  164. function pass_1(_blockstart: tai): tai;
  165. function pass_2: boolean;
  166. procedure clear;
  167. function getlabelwithsym(sym: tasmlabel): tai;
  168. private
  169. { Walks through the list to find the lowest and highest label number, inits the }
  170. { labeltable and fixes/optimizes some regallocs }
  171. procedure initlabeltable;
  172. function initdfapass2: boolean;
  173. procedure dodfapass2;
  174. { asm list we're working on }
  175. list: taasmoutput;
  176. { current part of the asm list }
  177. blockstart, blockend: tai;
  178. { the amount of taiObjects in the current part of the assembler list }
  179. nroftaiobjs: longint;
  180. { Array which holds all TtaiProps }
  181. taipropblock: ptaipropblock;
  182. { all labels in the current block: their value mapped to their location }
  183. lolab, hilab, labdif: longint;
  184. labeltable: plabeltable;
  185. end;
  186. function FindLabel(L: tasmlabel; var hp: tai): Boolean;
  187. procedure incState(var S: Byte; amount: longint);
  188. {******************************* Variables *******************************}
  189. var
  190. dfa: tdfaobj;
  191. {*********************** end of Interface section ************************}
  192. Implementation
  193. Uses
  194. globals, systems, verbose, symconst, symsym, cgobj,
  195. rgobj, procinfo;
  196. Type
  197. TRefCompare = function(const r1, r2: TReference): Boolean;
  198. var
  199. {How many instructions are between the current instruction and the last one
  200. that modified the register}
  201. NrOfInstrSinceLastMod: TInstrSinceLastMod;
  202. {$ifdef tempOpts}
  203. constructor TSearchLinkedListItem.init;
  204. begin
  205. end;
  206. function TSearchLinkedListItem.equals(p: PSearchLinkedListItem): boolean;
  207. begin
  208. equals := false;
  209. end;
  210. constructor TSearchDoubleIntItem.init(_int1,_int2: longint);
  211. begin
  212. int1 := _int1;
  213. int2 := _int2;
  214. end;
  215. function TSearchDoubleIntItem.equals(p: PSearchLinkedListItem): boolean;
  216. begin
  217. equals := (TSearchDoubleIntItem(p).int1 = int1) and
  218. (TSearchDoubleIntItem(p).int2 = int2);
  219. end;
  220. function TSearchLinkedList.searchByValue(p: PSearchLinkedListItem): boolean;
  221. var temp: PSearchLinkedListItem;
  222. begin
  223. temp := first;
  224. while (temp <> last.next) and
  225. not(temp.equals(p)) do
  226. temp := temp.next;
  227. searchByValue := temp <> last.next;
  228. end;
  229. procedure TSearchLinkedList.removeByValue(p: PSearchLinkedListItem);
  230. begin
  231. temp := first;
  232. while (temp <> last.next) and
  233. not(temp.equals(p)) do
  234. temp := temp.next;
  235. if temp <> last.next then
  236. begin
  237. remove(temp);
  238. dispose(temp,done);
  239. end;
  240. end;
  241. procedure updateTempAllocs(var UsedRegs: TRegSet; p: tai);
  242. {updates UsedRegs with the RegAlloc Information coming after p}
  243. begin
  244. repeat
  245. while assigned(p) and
  246. ((p.typ in (SkipInstr - [ait_RegAlloc])) or
  247. ((p.typ = ait_label) and
  248. labelCanBeSkipped(tai_label(current)))) Do
  249. p := tai(p.next);
  250. while assigned(p) and
  251. (p.typ=ait_RegAlloc) Do
  252. begin
  253. if tai_regalloc(p).allocation then
  254. UsedRegs := UsedRegs + [tai_regalloc(p).reg]
  255. else
  256. UsedRegs := UsedRegs - [tai_regalloc(p).reg];
  257. p := tai(p.next);
  258. end;
  259. until not(assigned(p)) or
  260. (not(p.typ in SkipInstr) and
  261. not((p.typ = ait_label) and
  262. labelCanBeSkipped(tai_label(current))));
  263. end;
  264. {$endif tempOpts}
  265. {************************ Create the Label table ************************}
  266. function findregalloc(reg: tregister; starttai: tai; alloc: boolean): boolean;
  267. { Returns true if a ait_alloc object for reg is found in the block of tai's }
  268. { starting with Starttai and ending with the next "real" instruction }
  269. var
  270. supreg: tsuperregister;
  271. begin
  272. findregalloc := false;
  273. supreg := getsupreg(reg);
  274. repeat
  275. while assigned(starttai) and
  276. ((starttai.typ in (skipinstr - [ait_regalloc])) or
  277. ((starttai.typ = ait_label) and
  278. labelcanbeskipped(tai_label(starttai)))) do
  279. starttai := tai(starttai.next);
  280. if assigned(starttai) and
  281. (starttai.typ = ait_regalloc) then
  282. begin
  283. if (tai_regalloc(Starttai).allocation = alloc) and
  284. (getsupreg(tai_regalloc(Starttai).reg) = supreg) then
  285. begin
  286. findregalloc:=true;
  287. break;
  288. end;
  289. starttai := tai(starttai.next);
  290. end
  291. else
  292. break;
  293. until false;
  294. end;
  295. procedure RemoveLastDeallocForFuncRes(asml: taasmoutput; p: tai);
  296. procedure DoRemoveLastDeallocForFuncRes(asml: taasmoutput; supreg: tsuperregister);
  297. var
  298. hp2: tai;
  299. begin
  300. hp2 := p;
  301. repeat
  302. hp2 := tai(hp2.previous);
  303. if assigned(hp2) and
  304. (hp2.typ = ait_regalloc) and
  305. not(tai_regalloc(hp2).allocation) and
  306. (getregtype(tai_regalloc(hp2).reg) = R_INTREGISTER) and
  307. (getsupreg(tai_regalloc(hp2).reg) = supreg) then
  308. begin
  309. asml.remove(hp2);
  310. hp2.free;
  311. break;
  312. end;
  313. until not(assigned(hp2)) or regInInstruction(supreg,hp2);
  314. end;
  315. begin
  316. case current_procinfo.procdef.rettype.def.deftype of
  317. arraydef,recorddef,pointerdef,
  318. stringdef,enumdef,procdef,objectdef,errordef,
  319. filedef,setdef,procvardef,
  320. classrefdef,forwarddef:
  321. DoRemoveLastDeallocForFuncRes(asml,RS_EAX);
  322. orddef:
  323. if current_procinfo.procdef.rettype.def.size <> 0 then
  324. begin
  325. DoRemoveLastDeallocForFuncRes(asml,RS_EAX);
  326. { for int64/qword }
  327. if current_procinfo.procdef.rettype.def.size = 8 then
  328. DoRemoveLastDeallocForFuncRes(asml,RS_EDX);
  329. end;
  330. end;
  331. end;
  332. procedure getNoDeallocRegs(var regs: tregset);
  333. var
  334. regCounter: TSuperRegister;
  335. begin
  336. regs := [];
  337. case current_procinfo.procdef.rettype.def.deftype of
  338. arraydef,recorddef,pointerdef,
  339. stringdef,enumdef,procdef,objectdef,errordef,
  340. filedef,setdef,procvardef,
  341. classrefdef,forwarddef:
  342. regs := [RS_EAX];
  343. orddef:
  344. if current_procinfo.procdef.rettype.def.size <> 0 then
  345. begin
  346. regs := [RS_EAX];
  347. { for int64/qword }
  348. if current_procinfo.procdef.rettype.def.size = 8 then
  349. regs := regs + [RS_EDX];
  350. end;
  351. end;
  352. for regCounter := RS_EAX to RS_EBX do
  353. { if not(regCounter in rg.usableregsint) then}
  354. include(regs,regcounter);
  355. end;
  356. procedure AddRegDeallocFor(asml: taasmoutput; reg: tregister; p: tai);
  357. var
  358. hp1: tai;
  359. funcResRegs: tregset;
  360. funcResReg: boolean;
  361. begin
  362. { if not(supreg in rg.usableregsint) then
  363. exit;}
  364. { if not(supreg in [RS_EDI]) then
  365. exit;}
  366. getNoDeallocRegs(funcresregs);
  367. { funcResRegs := funcResRegs - rg.usableregsint;}
  368. { funcResRegs := funcResRegs - [RS_EDI];}
  369. { funcResRegs := funcResRegs - [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_ESI]; }
  370. funcResReg := getsupreg(reg) in funcresregs;
  371. hp1 := p;
  372. {
  373. while not(funcResReg and
  374. (p.typ = ait_instruction) and
  375. (taicpu(p).opcode = A_JMP) and
  376. (tasmlabel(taicpu(p).oper[0]^.sym) = aktexit2label)) and
  377. getLastInstruction(p, p) and
  378. not(regInInstruction(supreg, p)) do
  379. hp1 := p;
  380. }
  381. { don't insert a dealloc for registers which contain the function result }
  382. { if they are followed by a jump to the exit label (for exit(...)) }
  383. { if not(funcResReg) or
  384. not((hp1.typ = ait_instruction) and
  385. (taicpu(hp1).opcode = A_JMP) and
  386. (tasmlabel(taicpu(hp1).oper[0]^.sym) = aktexit2label)) then }
  387. begin
  388. p := tai_regalloc.deAlloc(reg);
  389. insertLLItem(AsmL, hp1.previous, hp1, p);
  390. end;
  391. end;
  392. {************************ Search the Label table ************************}
  393. function findlabel(l: tasmlabel; var hp: tai): boolean;
  394. {searches for the specified label starting from hp as long as the
  395. encountered instructions are labels, to be able to optimize constructs like
  396. jne l2 jmp l2
  397. jmp l3 and l1:
  398. l1: l2:
  399. l2:}
  400. var
  401. p: tai;
  402. begin
  403. p := hp;
  404. while assigned(p) and
  405. (p.typ in SkipInstr + [ait_label,ait_align]) Do
  406. if (p.typ <> ait_Label) or
  407. (tai_label(p).l <> l) then
  408. GetNextInstruction(p, p)
  409. else
  410. begin
  411. hp := p;
  412. findlabel := true;
  413. exit
  414. end;
  415. findlabel := false;
  416. end;
  417. {************************ Some general functions ************************}
  418. function tch2reg(ch: tinschange): tsuperregister;
  419. {converts a TChange variable to a TRegister}
  420. const
  421. ch2reg: array[CH_REAX..CH_REDI] of tsuperregister = (RS_EAX,RS_ECX,RS_EDX,RS_EBX,RS_ESP,RS_EBP,RS_ESI,RS_EDI);
  422. begin
  423. if (ch <= CH_REDI) then
  424. tch2reg := ch2reg[ch]
  425. else if (ch <= CH_WEDI) then
  426. tch2reg := ch2reg[tinschange(ord(ch) - ord(CH_REDI))]
  427. else if (ch <= CH_RWEDI) then
  428. tch2reg := ch2reg[tinschange(ord(ch) - ord(CH_WEDI))]
  429. else if (ch <= CH_MEDI) then
  430. tch2reg := ch2reg[tinschange(ord(ch) - ord(CH_RWEDI))]
  431. else
  432. InternalError($db)
  433. end;
  434. { inserts new_one between prev and foll }
  435. procedure InsertLLItem(AsmL: TAAsmOutput; prev, foll, new_one: TLinkedListItem);
  436. begin
  437. if assigned(prev) then
  438. if assigned(foll) then
  439. begin
  440. if assigned(new_one) then
  441. begin
  442. new_one.previous := prev;
  443. new_one.next := foll;
  444. prev.next := new_one;
  445. foll.previous := new_one;
  446. { shgould we update line information }
  447. if (not (tai(new_one).typ in SkipLineInfo)) and
  448. (not (tai(foll).typ in SkipLineInfo)) then
  449. tailineinfo(new_one).fileinfo := tailineinfo(foll).fileinfo;
  450. end;
  451. end
  452. else
  453. asml.Concat(new_one)
  454. else
  455. if assigned(foll) then
  456. asml.Insert(new_one)
  457. end;
  458. {********************* Compare parts of tai objects *********************}
  459. function regssamesize(reg1, reg2: tregister): boolean;
  460. {returns true if Reg1 and Reg2 are of the same size (so if they're both
  461. 8bit, 16bit or 32bit)}
  462. begin
  463. if (reg1 = NR_NO) or (reg2 = NR_NO) then
  464. internalerror(2003111602);
  465. regssamesize := getsubreg(reg1) = getsubreg(reg2);
  466. end;
  467. procedure AddReg2RegInfo(OldReg, NewReg: TRegister; var RegInfo: toptreginfo);
  468. {updates the ???RegsEncountered and ???2???reg fields of RegInfo. Assumes that
  469. OldReg and NewReg have the same size (has to be chcked in advance with
  470. RegsSameSize) and that neither equals RS_INVALID}
  471. var
  472. newsupreg, oldsupreg: tsuperregister;
  473. begin
  474. if (newreg = NR_NO) or (oldreg = NR_NO) then
  475. internalerror(2003111601);
  476. newsupreg := getsupreg(newreg);
  477. oldsupreg := getsupreg(oldreg);
  478. with RegInfo Do
  479. begin
  480. NewRegsEncountered := NewRegsEncountered + [newsupreg];
  481. OldRegsEncountered := OldRegsEncountered + [oldsupreg];
  482. New2OldReg[newsupreg] := oldsupreg;
  483. end;
  484. end;
  485. procedure AddOp2RegInfo(const o:toper; var reginfo: toptreginfo);
  486. begin
  487. case o.typ Of
  488. top_reg:
  489. if (o.reg <> NR_NO) then
  490. AddReg2RegInfo(o.reg, o.reg, RegInfo);
  491. top_ref:
  492. begin
  493. if o.ref^.base <> NR_NO then
  494. AddReg2RegInfo(o.ref^.base, o.ref^.base, RegInfo);
  495. if o.ref^.index <> NR_NO then
  496. AddReg2RegInfo(o.ref^.index, o.ref^.index, RegInfo);
  497. end;
  498. end;
  499. end;
  500. function RegsEquivalent(oldreg, newreg: tregister; var reginfo: toptreginfo; opact: topaction): Boolean;
  501. begin
  502. if not((oldreg = NR_NO) or (newreg = NR_NO)) then
  503. if RegsSameSize(oldreg, newreg) then
  504. with reginfo do
  505. {here we always check for the 32 bit component, because it is possible that
  506. the 8 bit component has not been set, event though NewReg already has been
  507. processed. This happens if it has been compared with a register that doesn't
  508. have an 8 bit component (such as EDI). in that case the 8 bit component is
  509. still set to RS_NO and the comparison in the else-part will fail}
  510. if (getsupreg(oldReg) in OldRegsEncountered) then
  511. if (getsupreg(NewReg) in NewRegsEncountered) then
  512. RegsEquivalent := (getsupreg(oldreg) = New2OldReg[getsupreg(newreg)])
  513. { if we haven't encountered the new register yet, but we have encountered the
  514. old one already, the new one can only be correct if it's being written to
  515. (and consequently the old one is also being written to), otherwise
  516. movl -8(%ebp), %eax and movl -8(%ebp), %eax
  517. movl (%eax), %eax movl (%edx), %edx
  518. are considered equivalent}
  519. else
  520. if (opact = opact_write) then
  521. begin
  522. AddReg2RegInfo(oldreg, newreg, reginfo);
  523. RegsEquivalent := true
  524. end
  525. else
  526. Regsequivalent := false
  527. else
  528. if not(getsupreg(newreg) in NewRegsEncountered) and
  529. ((opact = opact_write) or
  530. (newreg = oldreg)) then
  531. begin
  532. AddReg2RegInfo(oldreg, newreg, reginfo);
  533. RegsEquivalent := true
  534. end
  535. else
  536. RegsEquivalent := false
  537. else
  538. RegsEquivalent := false
  539. else
  540. RegsEquivalent := oldreg = newreg
  541. end;
  542. function RefsEquivalent(const r1, r2: treference; var regInfo: toptreginfo; opact: topaction): boolean;
  543. begin
  544. RefsEquivalent :=
  545. (r1.offset = r2.offset) and
  546. RegsEquivalent(r1.base, r2.base, reginfo, opact) and
  547. RegsEquivalent(r1.index, r2.index, reginfo, opact) and
  548. (r1.segment = r2.segment) and (r1.scalefactor = r2.scalefactor) and
  549. (r1.symbol = r2.symbol);
  550. end;
  551. function refsequal(const r1, r2: treference): boolean;
  552. begin
  553. refsequal :=
  554. (r1.offset = r2.offset) and
  555. (r1.segment = r2.segment) and (r1.base = r2.base) and
  556. (r1.index = r2.index) and (r1.scalefactor = r2.scalefactor) and
  557. (r1.symbol=r2.symbol);
  558. end;
  559. function isgp32reg(reg: tregister): boolean;
  560. {Checks if the register is a 32 bit general purpose register}
  561. var
  562. supreg: tsuperregister;
  563. begin
  564. isgp32reg := false;
  565. if (reg = NR_NO) or
  566. (getregtype(reg) <> R_INTREGISTER) then
  567. exit;
  568. supreg := getsupreg(reg);
  569. if (supreg >= RS_EAX) and (supreg <= RS_EBX) then
  570. isgp32reg := true
  571. end;
  572. function reginref(supreg: tsuperregister; const ref: treference): boolean;
  573. begin {checks whether ref contains a reference to reg}
  574. reginref :=
  575. ((ref.base <> NR_NO) and
  576. (getsupreg(ref.base) = supreg)) or
  577. ((ref.index <> NR_NO) and
  578. (getsupreg(ref.index) = supreg))
  579. end;
  580. function RegReadByInstruction(supreg: tsuperregister; hp: tai): boolean;
  581. var
  582. p: taicpu;
  583. opcount: longint;
  584. begin
  585. RegReadByInstruction := false;
  586. if hp.typ <> ait_instruction then
  587. exit;
  588. p := taicpu(hp);
  589. case p.opcode of
  590. A_IMUL:
  591. case p.ops of
  592. 1:
  593. regReadByInstruction :=
  594. (supreg = RS_EAX) or reginop(supreg,p.oper[0]^);
  595. 2,3:
  596. regReadByInstruction :=
  597. reginop(supreg,p.oper[0]^) or
  598. reginop(supreg,p.oper[1]^);
  599. end;
  600. A_IDIV,A_DIV,A_MUL:
  601. begin
  602. regReadByInstruction :=
  603. reginop(supreg,p.oper[0]^) or (supreg in [RS_EAX,RS_EDX]);
  604. end;
  605. else
  606. begin
  607. for opcount := 0 to p.ops-1 do
  608. if (p.oper[opCount]^.typ = top_ref) and
  609. reginref(supreg,p.oper[opcount]^.ref^) then
  610. begin
  611. RegReadByInstruction := true;
  612. exit
  613. end;
  614. for opcount := 1 to maxch do
  615. case insprop[p.opcode].ch[opcount] of
  616. CH_REAX..CH_REDI,CH_RWEAX..CH_MEDI:
  617. if supreg = tch2reg(insprop[p.opcode].ch[opcount]) then
  618. begin
  619. RegReadByInstruction := true;
  620. exit
  621. end;
  622. CH_RWOP1,CH_ROP1,CH_MOP1:
  623. if //(p.oper[0]^.typ = top_reg) and
  624. reginop(supreg,p.oper[0]^) then
  625. begin
  626. RegReadByInstruction := true;
  627. exit
  628. end;
  629. Ch_RWOP2,Ch_ROP2,Ch_MOP2:
  630. if //(p.oper[1]^.typ = top_reg) and
  631. reginop(supreg,p.oper[1]^) then
  632. begin
  633. RegReadByInstruction := true;
  634. exit
  635. end;
  636. Ch_RWOP3,Ch_ROP3,Ch_MOP3:
  637. if //(p.oper[2]^.typ = top_reg) and
  638. reginop(supreg,p.oper[2]^) then
  639. begin
  640. RegReadByInstruction := true;
  641. exit
  642. end;
  643. end;
  644. end;
  645. end;
  646. end;
  647. function regInInstruction(supreg: tsuperregister; p1: tai): boolean;
  648. { Checks if reg is used by the instruction p1 }
  649. { Difference with "regReadBysinstruction() or regModifiedByInstruction()": }
  650. { this one ignores CH_ALL opcodes, while regModifiedByInstruction doesn't }
  651. var
  652. p: taicpu;
  653. opcount: byte;
  654. begin
  655. regInInstruction := false;
  656. if p1.typ <> ait_instruction then
  657. exit;
  658. p := taicpu(p1);
  659. case p.opcode of
  660. A_IMUL:
  661. case p.ops of
  662. 1:
  663. regInInstruction :=
  664. (supreg = RS_EAX) or reginop(supreg,p.oper[0]^);
  665. 2,3:
  666. regInInstruction :=
  667. reginop(supreg,p.oper[0]^) or
  668. reginop(supreg,p.oper[1]^) or
  669. (assigned(p.oper[2]) and
  670. reginop(supreg,p.oper[2]^));
  671. end;
  672. A_IDIV,A_DIV,A_MUL:
  673. regInInstruction :=
  674. reginop(supreg,p.oper[0]^) or
  675. (supreg in [RS_EAX,RS_EDX])
  676. else
  677. begin
  678. for opcount := 1 to MaxCh do
  679. case insprop[p.opcode].Ch[opCount] of
  680. CH_REAX..CH_MEDI:
  681. if tch2reg(InsProp[p.opcode].Ch[opCount]) = supreg then
  682. begin
  683. regInInstruction := true;
  684. exit;
  685. end;
  686. CH_ROp1..CH_MOp1:
  687. if reginop(supreg,p.oper[0]^) then
  688. begin
  689. regInInstruction := true;
  690. exit
  691. end;
  692. Ch_ROp2..Ch_MOp2:
  693. if reginop(supreg,p.oper[1]^) then
  694. begin
  695. regInInstruction := true;
  696. exit
  697. end;
  698. Ch_ROp3..Ch_MOp3:
  699. if reginop(supreg,p.oper[2]^) then
  700. begin
  701. regInInstruction := true;
  702. exit
  703. end;
  704. end;
  705. end;
  706. end;
  707. end;
  708. function reginop(supreg: tsuperregister; const o:toper): boolean;
  709. begin
  710. reginop := false;
  711. case o.typ Of
  712. top_reg:
  713. reginop :=
  714. (getregtype(o.reg) = R_INTREGISTER) and
  715. (supreg = getsupreg(o.reg));
  716. top_ref:
  717. reginop :=
  718. ((o.ref^.base <> NR_NO) and
  719. (supreg = getsupreg(o.ref^.base))) or
  720. ((o.ref^.index <> NR_NO) and
  721. (supreg = getsupreg(o.ref^.index)));
  722. end;
  723. end;
  724. function RegModifiedByInstruction(supreg: tsuperregister; p1: tai): boolean;
  725. var
  726. InstrProp: TInsProp;
  727. TmpResult: Boolean;
  728. Cnt: Byte;
  729. begin
  730. TmpResult := False;
  731. if (p1.typ = ait_instruction) then
  732. case taicpu(p1).opcode of
  733. A_IMUL:
  734. With taicpu(p1) Do
  735. TmpResult :=
  736. ((ops = 1) and (supreg in [RS_EAX,RS_EDX])) or
  737. ((ops = 2) and (getsupreg(oper[1]^.reg) = supreg)) or
  738. ((ops = 3) and (getsupreg(oper[2]^.reg) = supreg));
  739. A_DIV, A_IDIV, A_MUL:
  740. With taicpu(p1) Do
  741. TmpResult :=
  742. (supreg in [RS_EAX,RS_EDX]);
  743. else
  744. begin
  745. Cnt := 1;
  746. InstrProp := InsProp[taicpu(p1).OpCode];
  747. while (Cnt <= MaxCh) and
  748. (InstrProp.Ch[Cnt] <> Ch_None) and
  749. not(TmpResult) Do
  750. begin
  751. case InstrProp.Ch[Cnt] Of
  752. Ch_WEAX..Ch_MEDI:
  753. TmpResult := supreg = tch2reg(InstrProp.Ch[Cnt]);
  754. Ch_RWOp1,Ch_WOp1,Ch_Mop1:
  755. TmpResult := (taicpu(p1).oper[0]^.typ = top_reg) and
  756. reginop(supreg,taicpu(p1).oper[0]^);
  757. Ch_RWOp2,Ch_WOp2,Ch_Mop2:
  758. TmpResult := (taicpu(p1).oper[1]^.typ = top_reg) and
  759. reginop(supreg,taicpu(p1).oper[1]^);
  760. Ch_RWOp3,Ch_WOp3,Ch_Mop3:
  761. TmpResult := (taicpu(p1).oper[2]^.typ = top_reg) and
  762. reginop(supreg,taicpu(p1).oper[2]^);
  763. Ch_FPU: TmpResult := false; // supreg is supposed to be an intreg!! supreg in [RS_ST..RS_ST7,RS_MM0..RS_MM7];
  764. Ch_ALL: TmpResult := true;
  765. end;
  766. inc(Cnt)
  767. end
  768. end
  769. end;
  770. RegModifiedByInstruction := TmpResult
  771. end;
  772. function instrWritesFlags(p: tai): boolean;
  773. var
  774. l: longint;
  775. begin
  776. instrWritesFlags := true;
  777. case p.typ of
  778. ait_instruction:
  779. begin
  780. for l := 1 to MaxCh do
  781. if InsProp[taicpu(p).opcode].Ch[l] in [Ch_WFlags,Ch_RWFlags,Ch_All] then
  782. exit;
  783. end;
  784. ait_label:
  785. exit;
  786. end;
  787. instrWritesFlags := false;
  788. end;
  789. function instrReadsFlags(p: tai): boolean;
  790. var
  791. l: longint;
  792. begin
  793. instrReadsFlags := true;
  794. case p.typ of
  795. ait_instruction:
  796. begin
  797. for l := 1 to MaxCh do
  798. if InsProp[taicpu(p).opcode].Ch[l] in [Ch_RFlags,Ch_RWFlags,Ch_All] then
  799. exit;
  800. end;
  801. ait_label:
  802. exit;
  803. end;
  804. instrReadsFlags := false;
  805. end;
  806. {********************* GetNext and GetLastInstruction *********************}
  807. function GetNextInstruction(Current: tai; var Next: tai): Boolean;
  808. { skips ait_regalloc, ait_regdealloc and ait_stab* objects and puts the }
  809. { next tai object in Next. Returns false if there isn't any }
  810. begin
  811. repeat
  812. if (Current.typ = ait_marker) and
  813. (tai_Marker(current).Kind = AsmBlockStart) then
  814. begin
  815. GetNextInstruction := False;
  816. Next := Nil;
  817. Exit
  818. end;
  819. Current := tai(current.Next);
  820. while assigned(Current) and
  821. ((current.typ in skipInstr) or
  822. ((current.typ = ait_label) and
  823. labelCanBeSkipped(tai_label(current)))) do
  824. Current := tai(current.Next);
  825. { if assigned(Current) and
  826. (current.typ = ait_Marker) and
  827. (tai_Marker(current).Kind = NoPropInfoStart) then
  828. begin
  829. while assigned(Current) and
  830. ((current.typ <> ait_Marker) or
  831. (tai_Marker(current).Kind <> NoPropInfoend)) Do
  832. Current := tai(current.Next);
  833. end;}
  834. until not(assigned(Current)) or
  835. (current.typ <> ait_Marker) or
  836. not(tai_Marker(current).Kind in [NoPropInfoStart,NoPropInfoend]);
  837. Next := Current;
  838. if assigned(Current) and
  839. not((current.typ in SkipInstr) or
  840. ((current.typ = ait_label) and
  841. labelCanBeSkipped(tai_label(current))))
  842. then
  843. GetNextInstruction :=
  844. not((current.typ = ait_marker) and
  845. (tai_marker(current).kind = asmBlockStart))
  846. else
  847. begin
  848. GetNextInstruction := False;
  849. Next := nil;
  850. end;
  851. end;
  852. function GetLastInstruction(Current: tai; var Last: tai): boolean;
  853. {skips the ait-types in SkipInstr puts the previous tai object in
  854. Last. Returns false if there isn't any}
  855. begin
  856. repeat
  857. Current := tai(current.previous);
  858. while assigned(Current) and
  859. (((current.typ = ait_Marker) and
  860. not(tai_Marker(current).Kind in [AsmBlockend{,NoPropInfoend}])) or
  861. (current.typ in SkipInstr) or
  862. ((current.typ = ait_label) and
  863. labelCanBeSkipped(tai_label(current)))) Do
  864. Current := tai(current.previous);
  865. { if assigned(Current) and
  866. (current.typ = ait_Marker) and
  867. (tai_Marker(current).Kind = NoPropInfoend) then
  868. begin
  869. while assigned(Current) and
  870. ((current.typ <> ait_Marker) or
  871. (tai_Marker(current).Kind <> NoPropInfoStart)) Do
  872. Current := tai(current.previous);
  873. end;}
  874. until not(assigned(Current)) or
  875. (current.typ <> ait_Marker) or
  876. not(tai_Marker(current).Kind in [NoPropInfoStart,NoPropInfoend]);
  877. if not(assigned(Current)) or
  878. (current.typ in SkipInstr) or
  879. ((current.typ = ait_label) and
  880. labelCanBeSkipped(tai_label(current))) or
  881. ((current.typ = ait_Marker) and
  882. (tai_Marker(current).Kind = AsmBlockend))
  883. then
  884. begin
  885. Last := nil;
  886. GetLastInstruction := False
  887. end
  888. else
  889. begin
  890. Last := Current;
  891. GetLastInstruction := True;
  892. end;
  893. end;
  894. procedure SkipHead(var p: tai);
  895. var
  896. oldp: tai;
  897. begin
  898. repeat
  899. oldp := p;
  900. if (p.typ in SkipInstr) or
  901. ((p.typ = ait_marker) and
  902. (tai_Marker(p).Kind in [AsmBlockend,inlinestart,inlineend])) then
  903. GetNextInstruction(p,p)
  904. else if ((p.Typ = Ait_Marker) and
  905. (tai_Marker(p).Kind = nopropinfostart)) then
  906. {a marker of the NoPropInfoStart can't be the first instruction of a
  907. TAAsmoutput list}
  908. GetNextInstruction(tai(p.previous),p);
  909. until p = oldp
  910. end;
  911. function labelCanBeSkipped(p: tai_label): boolean;
  912. begin
  913. labelCanBeSkipped := not(p.l.is_used) or p.l.is_addr;
  914. end;
  915. {******************* The Data Flow Analyzer functions ********************}
  916. function regLoadedWithNewValue(supreg: tsuperregister; canDependOnPrevValue: boolean;
  917. hp: tai): boolean;
  918. { assumes reg is a 32bit register }
  919. var
  920. p: taicpu;
  921. begin
  922. if not assigned(hp) or
  923. (hp.typ <> ait_instruction) then
  924. begin
  925. regLoadedWithNewValue := false;
  926. exit;
  927. end;
  928. p := taicpu(hp);
  929. regLoadedWithNewValue :=
  930. (((p.opcode = A_MOV) or
  931. (p.opcode = A_MOVZX) or
  932. (p.opcode = A_MOVSX) or
  933. (p.opcode = A_LEA)) and
  934. (p.oper[1]^.typ = top_reg) and
  935. (getsupreg(p.oper[1]^.reg) = supreg) and
  936. (canDependOnPrevValue or
  937. (p.oper[0]^.typ <> top_ref) or
  938. not regInRef(supreg,p.oper[0]^.ref^)) or
  939. ((p.opcode = A_POP) and
  940. (getsupreg(p.oper[0]^.reg) = supreg)));
  941. end;
  942. procedure UpdateUsedRegs(var UsedRegs: TRegSet; p: tai);
  943. {updates UsedRegs with the RegAlloc Information coming after p}
  944. begin
  945. repeat
  946. while assigned(p) and
  947. ((p.typ in (SkipInstr - [ait_RegAlloc])) or
  948. ((p.typ = ait_label) and
  949. labelCanBeSkipped(tai_label(p)))) Do
  950. p := tai(p.next);
  951. while assigned(p) and
  952. (p.typ=ait_RegAlloc) Do
  953. begin
  954. if (getregtype(tai_regalloc(p).reg) = R_INTREGISTER) then
  955. if tai_regalloc(p).allocation then
  956. UsedRegs := UsedRegs + [getsupreg(tai_regalloc(p).reg)]
  957. else
  958. UsedRegs := UsedRegs - [getsupreg(tai_regalloc(p).reg)];
  959. p := tai(p.next);
  960. end;
  961. until not(assigned(p)) or
  962. (not(p.typ in SkipInstr) and
  963. not((p.typ = ait_label) and
  964. labelCanBeSkipped(tai_label(p))));
  965. end;
  966. procedure AllocRegBetween(asml: taasmoutput; reg: tregister; p1, p2: tai);
  967. { allocates register reg between (and including) instructions p1 and p2 }
  968. { the type of p1 and p2 must not be in SkipInstr }
  969. var
  970. hp, start: tai;
  971. lastRemovedWasDealloc, firstRemovedWasAlloc, first: boolean;
  972. supreg: tsuperregister;
  973. begin
  974. supreg := getsupreg(reg);
  975. { if not(supreg in rg.usableregsint+[RS_EDI,RS_ESI]) or
  976. not(assigned(p1)) then}
  977. if not(supreg in [RS_EAX,RS_EBX,RS_ECX,RS_EDX,RS_EDI,RS_ESI]) or
  978. not(assigned(p1)) then
  979. { this happens with registers which are loaded implicitely, outside the }
  980. { current block (e.g. esi with self) }
  981. exit;
  982. { make sure we allocate it for this instruction }
  983. if p1 = p2 then
  984. getnextinstruction(p2,p2);
  985. lastRemovedWasDealloc := false;
  986. firstRemovedWasAlloc := false;
  987. first := true;
  988. {$ifdef allocregdebug}
  989. hp := tai_comment.Create(strpnew('allocating '+std_reg2str[supreg]+
  990. ' from here...')));
  991. insertllitem(asml,p1.previous,p1,hp);
  992. hp := tai_comment.Create(strpnew('allocated '+std_reg2str[supreg]+
  993. ' till here...')));
  994. insertllitem(asml,p2,p1.next,hp);
  995. {$endif allocregdebug}
  996. start := p1;
  997. repeat
  998. if assigned(p1.OptInfo) then
  999. include(ptaiprop(p1.OptInfo)^.UsedRegs,supreg);
  1000. p1 := tai(p1.next);
  1001. repeat
  1002. while assigned(p1) and
  1003. (p1.typ in (SkipInstr-[ait_regalloc])) Do
  1004. p1 := tai(p1.next);
  1005. { remove all allocation/deallocation info about the register in between }
  1006. if assigned(p1) and
  1007. (p1.typ = ait_regalloc) then
  1008. if (getsupreg(tai_regalloc(p1).reg) = supreg) then
  1009. begin
  1010. if first then
  1011. begin
  1012. firstRemovedWasAlloc := tai_regalloc(p1).allocation;
  1013. first := false;
  1014. end;
  1015. lastRemovedWasDealloc := not tai_regalloc(p1).allocation;
  1016. hp := tai(p1.Next);
  1017. asml.Remove(p1);
  1018. p1.free;
  1019. p1 := hp;
  1020. end
  1021. else p1 := tai(p1.next);
  1022. until not(assigned(p1)) or
  1023. not(p1.typ in SkipInstr);
  1024. until not(assigned(p1)) or
  1025. (p1 = p2);
  1026. if assigned(p1) then
  1027. begin
  1028. if assigned(p1.optinfo) then
  1029. include(ptaiprop(p1.OptInfo)^.UsedRegs,supreg);
  1030. if lastRemovedWasDealloc then
  1031. begin
  1032. hp := tai_regalloc.DeAlloc(reg);
  1033. insertLLItem(asmL,p1,p1.next,hp);
  1034. end;
  1035. end;
  1036. if firstRemovedWasAlloc then
  1037. begin
  1038. hp := tai_regalloc.Alloc(reg);
  1039. insertLLItem(asmL,start.previous,start,hp);
  1040. end;
  1041. end;
  1042. function FindRegDealloc(supreg: tsuperregister; p: tai): boolean;
  1043. var
  1044. hp: tai;
  1045. first: boolean;
  1046. begin
  1047. findregdealloc := false;
  1048. first := true;
  1049. while assigned(p.previous) and
  1050. ((tai(p.previous).typ in (skipinstr+[ait_align])) or
  1051. ((tai(p.previous).typ = ait_label) and
  1052. labelCanBeSkipped(tai_label(p.previous)))) do
  1053. begin
  1054. p := tai(p.previous);
  1055. if (p.typ = ait_regalloc) and
  1056. (getsupreg(tai_regalloc(p).reg) = supreg) then
  1057. if not(tai_regalloc(p).allocation) then
  1058. if first then
  1059. begin
  1060. findregdealloc := true;
  1061. break;
  1062. end
  1063. else
  1064. begin
  1065. findRegDealloc :=
  1066. getNextInstruction(p,hp) and
  1067. regLoadedWithNewValue(supreg,false,hp);
  1068. break
  1069. end
  1070. else
  1071. first := false;
  1072. end
  1073. end;
  1074. procedure incState(var S: Byte; amount: longint);
  1075. {increases S by 1, wraps around at $ffff to 0 (so we won't get overflow
  1076. errors}
  1077. begin
  1078. if (s <= $ff - amount) then
  1079. inc(s, amount)
  1080. else s := longint(s) + amount - $ff;
  1081. end;
  1082. function sequenceDependsonReg(const Content: TContent; seqreg: tsuperregister; supreg: tsuperregister): Boolean;
  1083. { Content is the sequence of instructions that describes the contents of }
  1084. { seqReg. reg is being overwritten by the current instruction. if the }
  1085. { content of seqReg depends on reg (ie. because of a }
  1086. { "movl (seqreg,reg), seqReg" instruction), this function returns true }
  1087. var
  1088. p: tai;
  1089. Counter: Byte;
  1090. TmpResult: Boolean;
  1091. RegsChecked: TRegSet;
  1092. begin
  1093. RegsChecked := [];
  1094. p := Content.StartMod;
  1095. TmpResult := False;
  1096. Counter := 1;
  1097. while not(TmpResult) and
  1098. (Counter <= Content.NrOfMods) Do
  1099. begin
  1100. if (p.typ = ait_instruction) and
  1101. ((taicpu(p).opcode = A_MOV) or
  1102. (taicpu(p).opcode = A_MOVZX) or
  1103. (taicpu(p).opcode = A_MOVSX) or
  1104. (taicpu(p).opcode = A_LEA)) and
  1105. (taicpu(p).oper[0]^.typ = top_ref) then
  1106. With taicpu(p).oper[0]^.ref^ Do
  1107. if ((base = current_procinfo.FramePointer) or
  1108. (assigned(symbol) and (base = NR_NO))) and
  1109. (index = NR_NO) then
  1110. begin
  1111. RegsChecked := RegsChecked + [getsupreg(taicpu(p).oper[1]^.reg)];
  1112. if supreg = getsupreg(taicpu(p).oper[1]^.reg) then
  1113. break;
  1114. end
  1115. else
  1116. tmpResult :=
  1117. regReadByInstruction(supreg,p) and
  1118. regModifiedByInstruction(seqReg,p)
  1119. else
  1120. tmpResult :=
  1121. regReadByInstruction(supreg,p) and
  1122. regModifiedByInstruction(seqReg,p);
  1123. inc(Counter);
  1124. GetNextInstruction(p,p)
  1125. end;
  1126. sequenceDependsonReg := TmpResult
  1127. end;
  1128. procedure invalidateDependingRegs(p1: ptaiprop; supreg: tsuperregister);
  1129. var
  1130. counter: tsuperregister;
  1131. begin
  1132. for counter := RS_EAX to RS_EDI do
  1133. if counter <> supreg then
  1134. with p1^.regs[counter] Do
  1135. begin
  1136. if (typ in [con_ref,con_noRemoveRef]) and
  1137. sequenceDependsOnReg(p1^.Regs[counter],counter,supreg) then
  1138. if typ in [con_ref, con_invalid] then
  1139. typ := con_invalid
  1140. { con_noRemoveRef = con_unknown }
  1141. else
  1142. typ := con_unknown;
  1143. if assigned(memwrite) and
  1144. regInRef(counter,memwrite.oper[1]^.ref^) then
  1145. memwrite := nil;
  1146. end;
  1147. end;
  1148. procedure DestroyReg(p1: ptaiprop; supreg: tsuperregister; doincState:Boolean);
  1149. {Destroys the contents of the register reg in the ptaiprop p1, as well as the
  1150. contents of registers are loaded with a memory location based on reg.
  1151. doincState is false when this register has to be destroyed not because
  1152. it's contents are directly modified/overwritten, but because of an indirect
  1153. action (e.g. this register holds the contents of a variable and the value
  1154. of the variable in memory is changed) }
  1155. begin
  1156. { the following happens for fpu registers }
  1157. if (supreg < low(NrOfInstrSinceLastMod)) or
  1158. (supreg > high(NrOfInstrSinceLastMod)) then
  1159. exit;
  1160. NrOfInstrSinceLastMod[supreg] := 0;
  1161. with p1^.regs[supreg] do
  1162. begin
  1163. if doincState then
  1164. begin
  1165. incState(wstate,1);
  1166. typ := con_unknown;
  1167. startmod := nil;
  1168. end
  1169. else
  1170. if typ in [con_ref,con_const,con_invalid] then
  1171. typ := con_invalid
  1172. { con_noRemoveRef = con_unknown }
  1173. else
  1174. typ := con_unknown;
  1175. memwrite := nil;
  1176. end;
  1177. invalidateDependingRegs(p1,supreg);
  1178. end;
  1179. {procedure AddRegsToSet(p: tai; var RegSet: TRegSet);
  1180. begin
  1181. if (p.typ = ait_instruction) then
  1182. begin
  1183. case taicpu(p).oper[0]^.typ Of
  1184. top_reg:
  1185. if not(taicpu(p).oper[0]^.reg in [RS_NO,RS_ESP,current_procinfo.FramePointer]) then
  1186. RegSet := RegSet + [taicpu(p).oper[0]^.reg];
  1187. top_ref:
  1188. With TReference(taicpu(p).oper[0]^) Do
  1189. begin
  1190. if not(base in [current_procinfo.FramePointer,RS_NO,RS_ESP])
  1191. then RegSet := RegSet + [base];
  1192. if not(index in [current_procinfo.FramePointer,RS_NO,RS_ESP])
  1193. then RegSet := RegSet + [index];
  1194. end;
  1195. end;
  1196. case taicpu(p).oper[1]^.typ Of
  1197. top_reg:
  1198. if not(taicpu(p).oper[1]^.reg in [RS_NO,RS_ESP,current_procinfo.FramePointer]) then
  1199. if RegSet := RegSet + [TRegister(TwoWords(taicpu(p).oper[1]^).Word1];
  1200. top_ref:
  1201. With TReference(taicpu(p).oper[1]^) Do
  1202. begin
  1203. if not(base in [current_procinfo.FramePointer,RS_NO,RS_ESP])
  1204. then RegSet := RegSet + [base];
  1205. if not(index in [current_procinfo.FramePointer,RS_NO,RS_ESP])
  1206. then RegSet := RegSet + [index];
  1207. end;
  1208. end;
  1209. end;
  1210. end;}
  1211. function OpsEquivalent(const o1, o2: toper; var RegInfo: toptreginfo; OpAct: TopAction): Boolean;
  1212. begin {checks whether the two ops are equivalent}
  1213. OpsEquivalent := False;
  1214. if o1.typ=o2.typ then
  1215. case o1.typ Of
  1216. top_reg:
  1217. OpsEquivalent :=RegsEquivalent(o1.reg,o2.reg, RegInfo, OpAct);
  1218. top_ref:
  1219. OpsEquivalent := RefsEquivalent(o1.ref^, o2.ref^, RegInfo, OpAct);
  1220. Top_Const:
  1221. OpsEquivalent := o1.val = o2.val;
  1222. Top_None:
  1223. OpsEquivalent := True
  1224. end;
  1225. end;
  1226. function OpsEqual(const o1,o2:toper): Boolean;
  1227. begin {checks whether the two ops are equal}
  1228. OpsEqual := False;
  1229. if o1.typ=o2.typ then
  1230. case o1.typ Of
  1231. top_reg :
  1232. OpsEqual:=o1.reg=o2.reg;
  1233. top_ref :
  1234. OpsEqual := RefsEqual(o1.ref^, o2.ref^);
  1235. Top_Const :
  1236. OpsEqual:=o1.val=o2.val;
  1237. Top_Symbol :
  1238. OpsEqual:=(o1.sym=o2.sym) and (o1.symofs=o2.symofs);
  1239. Top_None :
  1240. OpsEqual := True
  1241. end;
  1242. end;
  1243. function sizescompatible(loadsize,newsize: topsize): boolean;
  1244. begin
  1245. case loadsize of
  1246. S_B,S_BW,S_BL:
  1247. sizescompatible := (newsize = loadsize) or (newsize = S_B);
  1248. S_W,S_WL:
  1249. sizescompatible := (newsize = loadsize) or (newsize = S_W);
  1250. else
  1251. sizescompatible := newsize = S_L;
  1252. end;
  1253. end;
  1254. function opscompatible(p1,p2: taicpu): boolean;
  1255. begin
  1256. case p1.opcode of
  1257. A_MOVZX,A_MOVSX:
  1258. opscompatible :=
  1259. ((p2.opcode = p1.opcode) or (p2.opcode = A_MOV)) and
  1260. sizescompatible(p1.opsize,p2.opsize);
  1261. else
  1262. opscompatible :=
  1263. (p1.opcode = p2.opcode) and
  1264. (p1.ops = p2.ops) and
  1265. (p1.opsize = p2.opsize);
  1266. end;
  1267. end;
  1268. function InstructionsEquivalent(p1, p2: tai; var RegInfo: toptreginfo): Boolean;
  1269. {$ifdef csdebug}
  1270. var
  1271. hp: tai;
  1272. {$endif csdebug}
  1273. begin {checks whether two taicpu instructions are equal}
  1274. if assigned(p1) and assigned(p2) and
  1275. (tai(p1).typ = ait_instruction) and
  1276. (tai(p2).typ = ait_instruction) and
  1277. opscompatible(taicpu(p1),taicpu(p2)) and
  1278. (not(assigned(taicpu(p1).oper[0])) or
  1279. (taicpu(p1).oper[0]^.typ = taicpu(p2).oper[0]^.typ)) and
  1280. (not(assigned(taicpu(p1).oper[1])) or
  1281. (taicpu(p1).oper[1]^.typ = taicpu(p2).oper[1]^.typ)) and
  1282. (not(assigned(taicpu(p1).oper[2])) or
  1283. (taicpu(p1).oper[2]^.typ = taicpu(p2).oper[2]^.typ)) then
  1284. {both instructions have the same structure:
  1285. "<operator> <operand of type1>, <operand of type 2>"}
  1286. if ((taicpu(p1).opcode = A_MOV) or
  1287. (taicpu(p1).opcode = A_MOVZX) or
  1288. (taicpu(p1).opcode = A_MOVSX) or
  1289. (taicpu(p1).opcode = A_LEA)) and
  1290. (taicpu(p1).oper[0]^.typ = top_ref) {then .oper[1]^t = top_reg} then
  1291. if not(RegInRef(getsupreg(taicpu(p1).oper[1]^.reg), taicpu(p1).oper[0]^.ref^)) then
  1292. {the "old" instruction is a load of a register with a new value, not with
  1293. a value based on the contents of this register (so no "mov (reg), reg")}
  1294. if not(RegInRef(getsupreg(taicpu(p2).oper[1]^.reg), taicpu(p2).oper[0]^.ref^)) and
  1295. RefsEqual(taicpu(p1).oper[0]^.ref^, taicpu(p2).oper[0]^.ref^) then
  1296. {the "new" instruction is also a load of a register with a new value, and
  1297. this value is fetched from the same memory location}
  1298. begin
  1299. With taicpu(p2).oper[0]^.ref^ Do
  1300. begin
  1301. if (base <> NR_NO) and
  1302. (not(getsupreg(base) in [getsupreg(current_procinfo.FramePointer), RS_ESP])) then
  1303. include(RegInfo.RegsLoadedForRef, getsupreg(base));
  1304. if (index <> NR_NO) and
  1305. (not(getsupreg(index) in [getsupreg(current_procinfo.FramePointer), RS_ESP])) then
  1306. include(RegInfo.RegsLoadedForRef, getsupreg(index));
  1307. end;
  1308. {add the registers from the reference (.oper[0]^) to the RegInfo, all registers
  1309. from the reference are the same in the old and in the new instruction
  1310. sequence}
  1311. AddOp2RegInfo(taicpu(p1).oper[0]^, RegInfo);
  1312. {the registers from .oper[1]^ have to be equivalent, but not necessarily equal}
  1313. InstructionsEquivalent :=
  1314. RegsEquivalent(taicpu(p1).oper[1]^.reg,
  1315. taicpu(p2).oper[1]^.reg, RegInfo, OpAct_Write);
  1316. end
  1317. {the registers are loaded with values from different memory locations. if
  1318. this was allowed, the instructions "mov -4(esi),eax" and "mov -4(ebp),eax"
  1319. would be considered equivalent}
  1320. else
  1321. InstructionsEquivalent := False
  1322. else
  1323. {load register with a value based on the current value of this register}
  1324. begin
  1325. With taicpu(p2).oper[0]^.ref^ Do
  1326. begin
  1327. if (base <> NR_NO) and
  1328. (not(getsupreg(base) in [getsupreg(current_procinfo.FramePointer),
  1329. getsupreg(taicpu(p2).oper[1]^.reg),RS_ESP])) then
  1330. {it won't do any harm if the register is already in RegsLoadedForRef}
  1331. begin
  1332. include(RegInfo.RegsLoadedForRef, getsupreg(base));
  1333. {$ifdef csdebug}
  1334. Writeln(std_reg2str[base], ' added');
  1335. {$endif csdebug}
  1336. end;
  1337. if (index <> NR_NO) and
  1338. (not(getsupreg(index) in [getsupreg(current_procinfo.FramePointer),
  1339. getsupreg(taicpu(p2).oper[1]^.reg),RS_ESP])) then
  1340. begin
  1341. include(RegInfo.RegsLoadedForRef, getsupreg(index));
  1342. {$ifdef csdebug}
  1343. Writeln(std_reg2str[index], ' added');
  1344. {$endif csdebug}
  1345. end;
  1346. end;
  1347. if (taicpu(p2).oper[1]^.reg <> NR_NO) and
  1348. (not(getsupreg(taicpu(p2).oper[1]^.reg) in [getsupreg(current_procinfo.FramePointer),RS_ESP])) then
  1349. begin
  1350. RegInfo.RegsLoadedForRef := RegInfo.RegsLoadedForRef -
  1351. [getsupreg(taicpu(p2).oper[1]^.reg)];
  1352. {$ifdef csdebug}
  1353. Writeln(std_reg2str[getsupreg(taicpu(p2).oper[1]^.reg)], ' removed');
  1354. {$endif csdebug}
  1355. end;
  1356. InstructionsEquivalent :=
  1357. OpsEquivalent(taicpu(p1).oper[0]^, taicpu(p2).oper[0]^, RegInfo, OpAct_Read) and
  1358. OpsEquivalent(taicpu(p1).oper[1]^, taicpu(p2).oper[1]^, RegInfo, OpAct_Write)
  1359. end
  1360. else
  1361. {an instruction <> mov, movzx, movsx}
  1362. begin
  1363. {$ifdef csdebug}
  1364. hp := tai_comment.Create(strpnew('checking if equivalent'));
  1365. hp.previous := p2;
  1366. hp.next := p2^.next;
  1367. p2^.next^.previous := hp;
  1368. p2^.next := hp;
  1369. {$endif csdebug}
  1370. InstructionsEquivalent :=
  1371. (not(assigned(taicpu(p1).oper[0])) or
  1372. OpsEquivalent(taicpu(p1).oper[0]^, taicpu(p2).oper[0]^, RegInfo, OpAct_Unknown)) and
  1373. (not(assigned(taicpu(p1).oper[1])) or
  1374. OpsEquivalent(taicpu(p1).oper[1]^, taicpu(p2).oper[1]^, RegInfo, OpAct_Unknown)) and
  1375. (not(assigned(taicpu(p1).oper[2])) or
  1376. OpsEquivalent(taicpu(p1).oper[2]^, taicpu(p2).oper[2]^, RegInfo, OpAct_Unknown))
  1377. end
  1378. {the instructions haven't even got the same structure, so they're certainly
  1379. not equivalent}
  1380. else
  1381. begin
  1382. {$ifdef csdebug}
  1383. hp := tai_comment.Create(strpnew('different opcodes/format'));
  1384. hp.previous := p2;
  1385. hp.next := p2^.next;
  1386. p2^.next^.previous := hp;
  1387. p2^.next := hp;
  1388. {$endif csdebug}
  1389. InstructionsEquivalent := False;
  1390. end;
  1391. {$ifdef csdebug}
  1392. hp := tai_comment.Create(strpnew('instreq: '+tostr(byte(instructionsequivalent))));
  1393. hp.previous := p2;
  1394. hp.next := p2^.next;
  1395. p2^.next^.previous := hp;
  1396. p2^.next := hp;
  1397. {$endif csdebug}
  1398. end;
  1399. (*
  1400. function InstructionsEqual(p1, p2: tai): Boolean;
  1401. begin {checks whether two taicpu instructions are equal}
  1402. InstructionsEqual :=
  1403. assigned(p1) and assigned(p2) and
  1404. ((tai(p1).typ = ait_instruction) and
  1405. (tai(p1).typ = ait_instruction) and
  1406. (taicpu(p1).opcode = taicpu(p2).opcode) and
  1407. (taicpu(p1).oper[0]^.typ = taicpu(p2).oper[0]^.typ) and
  1408. (taicpu(p1).oper[1]^.typ = taicpu(p2).oper[1]^.typ) and
  1409. OpsEqual(taicpu(p1).oper[0]^.typ, taicpu(p1).oper[0]^, taicpu(p2).oper[0]^) and
  1410. OpsEqual(taicpu(p1).oper[1]^.typ, taicpu(p1).oper[1]^, taicpu(p2).oper[1]^))
  1411. end;
  1412. *)
  1413. procedure readreg(p: ptaiprop; supreg: tsuperregister);
  1414. begin
  1415. if supreg in [RS_EAX..RS_EDI] then
  1416. incState(p^.regs[supreg].rstate,1)
  1417. end;
  1418. procedure readref(p: ptaiprop; const ref: preference);
  1419. begin
  1420. if ref^.base <> NR_NO then
  1421. readreg(p, getsupreg(ref^.base));
  1422. if ref^.index <> NR_NO then
  1423. readreg(p, getsupreg(ref^.index));
  1424. end;
  1425. procedure ReadOp(p: ptaiprop;const o:toper);
  1426. begin
  1427. case o.typ Of
  1428. top_reg: readreg(p, getsupreg(o.reg));
  1429. top_ref: readref(p, o.ref);
  1430. top_symbol : ;
  1431. end;
  1432. end;
  1433. function RefInInstruction(const ref: TReference; p: tai;
  1434. RefsEq: TRefCompare): Boolean;
  1435. {checks whehter ref is used in p}
  1436. var TmpResult: Boolean;
  1437. begin
  1438. TmpResult := False;
  1439. if (p.typ = ait_instruction) then
  1440. begin
  1441. if (taicpu(p).ops >= 1) and
  1442. (taicpu(p).oper[0]^.typ = top_ref) then
  1443. TmpResult := RefsEq(ref, taicpu(p).oper[0]^.ref^);
  1444. if not(TmpResult) and
  1445. (taicpu(p).ops >= 2) and
  1446. (taicpu(p).oper[1]^.typ = top_ref) then
  1447. TmpResult := RefsEq(ref, taicpu(p).oper[1]^.ref^);
  1448. if not(TmpResult) and
  1449. (taicpu(p).ops >= 3) and
  1450. (taicpu(p).oper[2]^.typ = top_ref) then
  1451. TmpResult := RefsEq(ref, taicpu(p).oper[2]^.ref^);
  1452. end;
  1453. RefInInstruction := TmpResult;
  1454. end;
  1455. function RefInSequence(const ref: TReference; Content: TContent;
  1456. RefsEq: TRefCompare): Boolean;
  1457. {checks the whole sequence of Content (so StartMod and and the next NrOfMods
  1458. tai objects) to see whether ref is used somewhere}
  1459. var p: tai;
  1460. Counter: Byte;
  1461. TmpResult: Boolean;
  1462. begin
  1463. p := Content.StartMod;
  1464. TmpResult := False;
  1465. Counter := 1;
  1466. while not(TmpResult) and
  1467. (Counter <= Content.NrOfMods) Do
  1468. begin
  1469. if (p.typ = ait_instruction) and
  1470. RefInInstruction(ref, p, RefsEq)
  1471. then TmpResult := True;
  1472. inc(Counter);
  1473. GetNextInstruction(p,p)
  1474. end;
  1475. RefInSequence := TmpResult
  1476. end;
  1477. function ArrayRefsEq(const r1, r2: TReference): Boolean;
  1478. begin
  1479. ArrayRefsEq := (R1.Offset = R2.Offset) and
  1480. (R1.Segment = R2.Segment) and
  1481. (R1.Symbol=R2.Symbol) and
  1482. (R1.base = R2.base)
  1483. end;
  1484. function isSimpleRef(const ref: treference): boolean;
  1485. { returns true if ref is reference to a local or global variable, to a }
  1486. { parameter or to an object field (this includes arrays). Returns false }
  1487. { otherwise. }
  1488. begin
  1489. isSimpleRef :=
  1490. assigned(ref.symbol) or
  1491. (ref.base = current_procinfo.framepointer);
  1492. end;
  1493. function containsPointerRef(p: tai): boolean;
  1494. { checks if an instruction contains a reference which is a pointer location }
  1495. var
  1496. hp: taicpu;
  1497. count: longint;
  1498. begin
  1499. containsPointerRef := false;
  1500. if p.typ <> ait_instruction then
  1501. exit;
  1502. hp := taicpu(p);
  1503. for count := 0 to hp.ops-1 do
  1504. begin
  1505. case hp.oper[count]^.typ of
  1506. top_ref:
  1507. if not isSimpleRef(hp.oper[count]^.ref^) then
  1508. begin
  1509. containsPointerRef := true;
  1510. exit;
  1511. end;
  1512. top_none:
  1513. exit;
  1514. end;
  1515. end;
  1516. end;
  1517. function containsPointerLoad(c: tcontent): boolean;
  1518. { checks whether the contents of a register contain a pointer reference }
  1519. var
  1520. p: tai;
  1521. count: longint;
  1522. begin
  1523. containsPointerLoad := false;
  1524. p := c.startmod;
  1525. for count := c.nrOfMods downto 1 do
  1526. begin
  1527. if containsPointerRef(p) then
  1528. begin
  1529. containsPointerLoad := true;
  1530. exit;
  1531. end;
  1532. getnextinstruction(p,p);
  1533. end;
  1534. end;
  1535. function writeToMemDestroysContents(regWritten: tsuperregister; const ref: treference;
  1536. supreg: tsuperregister; const c: tcontent; var invalsmemwrite: boolean): boolean;
  1537. { returns whether the contents c of reg are invalid after regWritten is }
  1538. { is written to ref }
  1539. var
  1540. refsEq: trefCompare;
  1541. begin
  1542. if isSimpleRef(ref) then
  1543. begin
  1544. if (ref.index <> NR_NO) or
  1545. (assigned(ref.symbol) and
  1546. (ref.base <> NR_NO)) then
  1547. { local/global variable or parameter which is an array }
  1548. refsEq := {$ifdef fpc}@{$endif}arrayRefsEq
  1549. else
  1550. { local/global variable or parameter which is not an array }
  1551. refsEq := {$ifdef fpc}@{$endif}refsEqual;
  1552. invalsmemwrite :=
  1553. assigned(c.memwrite) and
  1554. ((not(cs_uncertainOpts in aktglobalswitches) and
  1555. containsPointerRef(c.memwrite)) or
  1556. refsEq(c.memwrite.oper[1]^.ref^,ref));
  1557. if not(c.typ in [con_ref,con_noRemoveRef,con_invalid]) then
  1558. begin
  1559. writeToMemDestroysContents := false;
  1560. exit;
  1561. end;
  1562. { write something to a parameter, a local or global variable, so }
  1563. { * with uncertain optimizations on: }
  1564. { - destroy the contents of registers whose contents have somewhere a }
  1565. { "mov?? (ref), %reg". WhichReg (this is the register whose contents }
  1566. { are being written to memory) is not destroyed if it's StartMod is }
  1567. { of that form and NrOfMods = 1 (so if it holds ref, but is not a }
  1568. { expression based on ref) }
  1569. { * with uncertain optimizations off: }
  1570. { - also destroy registers that contain any pointer }
  1571. with c do
  1572. writeToMemDestroysContents :=
  1573. (typ in [con_ref,con_noRemoveRef]) and
  1574. ((not(cs_uncertainOpts in aktglobalswitches) and
  1575. containsPointerLoad(c)
  1576. ) or
  1577. (refInSequence(ref,c,refsEq) and
  1578. ((supreg <> regWritten) or
  1579. not((nrOfMods = 1) and
  1580. {StarMod is always of the type ait_instruction}
  1581. (taicpu(StartMod).oper[0]^.typ = top_ref) and
  1582. refsEq(taicpu(StartMod).oper[0]^.ref^, ref)
  1583. )
  1584. )
  1585. )
  1586. );
  1587. end
  1588. else
  1589. { write something to a pointer location, so }
  1590. { * with uncertain optimzations on: }
  1591. { - do not destroy registers which contain a local/global variable or }
  1592. { a parameter, except if DestroyRefs is called because of a "movsl" }
  1593. { * with uncertain optimzations off: }
  1594. { - destroy every register which contains a memory location }
  1595. begin
  1596. invalsmemwrite :=
  1597. assigned(c.memwrite) and
  1598. (not(cs_UncertainOpts in aktglobalswitches) or
  1599. containsPointerRef(c.memwrite));
  1600. if not(c.typ in [con_ref,con_noRemoveRef,con_invalid]) then
  1601. begin
  1602. writeToMemDestroysContents := false;
  1603. exit;
  1604. end;
  1605. with c do
  1606. writeToMemDestroysContents :=
  1607. (typ in [con_ref,con_noRemoveRef]) and
  1608. (not(cs_UncertainOpts in aktglobalswitches) or
  1609. { for movsl }
  1610. ((ref.base = RS_EDI) and (ref.index = RS_EDI)) or
  1611. { don't destroy if reg contains a parameter, local or global variable }
  1612. containsPointerLoad(c)
  1613. );
  1614. end;
  1615. end;
  1616. function writeToRegDestroysContents(destReg, supreg: tsuperregister;
  1617. const c: tcontent): boolean;
  1618. { returns whether the contents c of reg are invalid after destReg is }
  1619. { modified }
  1620. begin
  1621. writeToRegDestroysContents :=
  1622. (c.typ in [con_ref,con_noRemoveRef,con_invalid]) and
  1623. sequenceDependsOnReg(c,supreg,destReg);
  1624. end;
  1625. function writeDestroysContents(const op: toper; supreg: tsuperregister;
  1626. const c: tcontent): boolean;
  1627. { returns whether the contents c of reg are invalid after regWritten is }
  1628. { is written to op }
  1629. var
  1630. dummy: boolean;
  1631. begin
  1632. case op.typ of
  1633. top_reg:
  1634. writeDestroysContents :=
  1635. writeToRegDestroysContents(getsupreg(op.reg),supreg,c);
  1636. top_ref:
  1637. writeDestroysContents :=
  1638. writeToMemDestroysContents(RS_INVALID,op.ref^,supreg,c,dummy);
  1639. else
  1640. writeDestroysContents := false;
  1641. end;
  1642. end;
  1643. procedure destroyRefs(p: tai; const ref: treference; regwritten: tsuperregister);
  1644. { destroys all registers which possibly contain a reference to ref, regWritten }
  1645. { is the register whose contents are being written to memory (if this proc }
  1646. { is called because of a "mov?? %reg, (mem)" instruction) }
  1647. var
  1648. counter: tsuperregister;
  1649. destroymemwrite: boolean;
  1650. begin
  1651. for counter := RS_EAX to RS_EDI Do
  1652. begin
  1653. if writeToMemDestroysContents(regwritten,ref,counter,
  1654. ptaiprop(p.optInfo)^.regs[counter],destroymemwrite) then
  1655. destroyReg(ptaiprop(p.optInfo), counter, false)
  1656. else if destroymemwrite then
  1657. ptaiprop(p.optinfo)^.regs[counter].MemWrite := nil;
  1658. end;
  1659. end;
  1660. procedure DestroyAllRegs(p: ptaiprop; read, written: boolean);
  1661. var Counter: tsuperregister;
  1662. begin {initializes/desrtoys all registers}
  1663. For Counter := RS_EAX To RS_EDI Do
  1664. begin
  1665. if read then
  1666. readreg(p, Counter);
  1667. DestroyReg(p, Counter, written);
  1668. p^.regs[counter].MemWrite := nil;
  1669. end;
  1670. p^.DirFlag := F_Unknown;
  1671. end;
  1672. procedure DestroyOp(taiObj: tai; const o:Toper);
  1673. {$ifdef statedebug}
  1674. var
  1675. hp: tai;
  1676. {$endif statedebug}
  1677. begin
  1678. case o.typ Of
  1679. top_reg:
  1680. begin
  1681. {$ifdef statedebug}
  1682. hp := tai_comment.Create(strpnew('destroying '+std_reg2str[o.reg]));
  1683. hp.next := taiobj^.next;
  1684. hp.previous := taiobj;
  1685. taiobj^.next := hp;
  1686. if assigned(hp.next) then
  1687. hp.next^.previous := hp;
  1688. {$endif statedebug}
  1689. DestroyReg(ptaiprop(taiObj.OptInfo), getsupreg(o.reg), true);
  1690. end;
  1691. top_ref:
  1692. begin
  1693. readref(ptaiprop(taiObj.OptInfo), o.ref);
  1694. DestroyRefs(taiObj, o.ref^, RS_INVALID);
  1695. end;
  1696. top_symbol:;
  1697. end;
  1698. end;
  1699. procedure AddInstr2RegContents({$ifdef statedebug} asml: taasmoutput; {$endif}
  1700. p: taicpu; supreg: tsuperregister);
  1701. {$ifdef statedebug}
  1702. var
  1703. hp: tai;
  1704. {$endif statedebug}
  1705. begin
  1706. With ptaiprop(p.optinfo)^.regs[supreg] Do
  1707. if (typ in [con_ref,con_noRemoveRef]) then
  1708. begin
  1709. incState(wstate,1);
  1710. { also store how many instructions are part of the sequence in the first }
  1711. { instructions ptaiprop, so it can be easily accessed from within }
  1712. { CheckSequence}
  1713. inc(NrOfMods, NrOfInstrSinceLastMod[supreg]);
  1714. ptaiprop(tai(StartMod).OptInfo)^.Regs[supreg].NrOfMods := NrOfMods;
  1715. NrOfInstrSinceLastMod[supreg] := 0;
  1716. invalidateDependingRegs(p.optinfo,supreg);
  1717. ptaiprop(p.optinfo)^.regs[supreg].memwrite := nil;
  1718. {$ifdef StateDebug}
  1719. hp := tai_comment.Create(strpnew(std_reg2str[reg]+': '+tostr(ptaiprop(p.optinfo)^.Regs[reg].WState)
  1720. + ' -- ' + tostr(ptaiprop(p.optinfo)^.Regs[reg].nrofmods))));
  1721. InsertLLItem(AsmL, p, p.next, hp);
  1722. {$endif StateDebug}
  1723. end
  1724. else
  1725. begin
  1726. {$ifdef statedebug}
  1727. hp := tai_comment.Create(strpnew('destroying '+std_reg2str[reg]));
  1728. insertllitem(asml,p,p.next,hp);
  1729. {$endif statedebug}
  1730. DestroyReg(ptaiprop(p.optinfo), supreg, true);
  1731. {$ifdef StateDebug}
  1732. hp := tai_comment.Create(strpnew(std_reg2str[reg]+': '+tostr(ptaiprop(p.optinfo)^.Regs[supreg].WState)));
  1733. InsertLLItem(AsmL, p, p.next, hp);
  1734. {$endif StateDebug}
  1735. end
  1736. end;
  1737. procedure AddInstr2OpContents({$ifdef statedebug} asml: TAAsmoutput; {$endif}
  1738. p: taicpu; const oper: TOper);
  1739. begin
  1740. if oper.typ = top_reg then
  1741. AddInstr2RegContents({$ifdef statedebug} asml, {$endif}p, getsupreg(oper.reg))
  1742. else
  1743. begin
  1744. ReadOp(ptaiprop(p.optinfo), oper);
  1745. DestroyOp(p, oper);
  1746. end
  1747. end;
  1748. {*************************************************************************************}
  1749. {************************************** TDFAOBJ **************************************}
  1750. {*************************************************************************************}
  1751. constructor tdfaobj.create(_list: taasmoutput);
  1752. begin
  1753. list := _list;
  1754. blockstart := nil;
  1755. blockend := nil;
  1756. nroftaiobjs := 0;
  1757. taipropblock := nil;
  1758. lolab := 0;
  1759. hilab := 0;
  1760. labdif := 0;
  1761. labeltable := nil;
  1762. end;
  1763. procedure tdfaobj.initlabeltable;
  1764. var
  1765. labelfound: boolean;
  1766. p, prev: tai;
  1767. hp1, hp2: tai;
  1768. {$ifdef i386}
  1769. regcounter: tregister;
  1770. {$endif i386}
  1771. usedregs, nodeallocregs: tregset;
  1772. begin
  1773. labelfound := false;
  1774. lolab := maxlongint;
  1775. hilab := 0;
  1776. p := blockstart;
  1777. prev := p;
  1778. while assigned(p) do
  1779. begin
  1780. if (tai(p).typ = ait_label) then
  1781. if not labelcanbeskipped(tai_label(p)) then
  1782. begin
  1783. labelfound := true;
  1784. if (tai_Label(p).l.labelnr < lolab) then
  1785. lolab := tai_label(p).l.labelnr;
  1786. if (tai_Label(p).l.labelnr > hilab) then
  1787. hilab := tai_label(p).l.labelnr;
  1788. end;
  1789. prev := p;
  1790. getnextinstruction(p, p);
  1791. end;
  1792. if (prev.typ = ait_marker) and
  1793. (tai_marker(prev).kind = asmblockstart) then
  1794. blockend := prev
  1795. else blockend := nil;
  1796. if labelfound then
  1797. labdif := hilab+1-lolab
  1798. else labdif := 0;
  1799. usedregs := [];
  1800. if (labdif <> 0) then
  1801. begin
  1802. getmem(labeltable, labdif*sizeof(tlabeltableitem));
  1803. fillchar(labeltable^, labdif*sizeof(tlabeltableitem), 0);
  1804. end;
  1805. p := blockstart;
  1806. prev := p;
  1807. while (p <> blockend) do
  1808. begin
  1809. case p.typ of
  1810. ait_label:
  1811. if not labelcanbeskipped(tai_label(p)) then
  1812. labeltable^[tai_label(p).l.labelnr-lolab].taiobj := p;
  1813. {$ifdef i386}
  1814. ait_regalloc:
  1815. if tai_regalloc(p).allocation then
  1816. begin
  1817. if not(getsupreg(tai_regalloc(p).reg) in usedregs) then
  1818. include(usedregs, getsupreg(tai_regalloc(p).reg))
  1819. else
  1820. addregdeallocfor(list, tai_regalloc(p).reg, p);
  1821. end
  1822. else
  1823. begin
  1824. exclude(usedregs, getsupreg(tai_regalloc(p).reg));
  1825. hp1 := p;
  1826. hp2 := nil;
  1827. while not(findregalloc(tai_regalloc(p).reg, tai(hp1.next),true)) and
  1828. getnextinstruction(hp1, hp1) and
  1829. regininstruction(getsupreg(tai_regalloc(p).reg), hp1) Do
  1830. hp2 := hp1;
  1831. if hp2 <> nil then
  1832. begin
  1833. hp1 := tai(p.previous);
  1834. list.remove(p);
  1835. insertllitem(list, hp2, tai(hp2.next), p);
  1836. p := hp1;
  1837. end;
  1838. end;
  1839. {$endif i386}
  1840. end;
  1841. repeat
  1842. prev := p;
  1843. p := tai(p.next);
  1844. until not(assigned(p)) or
  1845. not(p.typ in (skipinstr - [ait_regalloc]));
  1846. end;
  1847. {$ifdef i386}
  1848. { don't add deallocation for function result variable or for regvars}
  1849. getNoDeallocRegs(noDeallocRegs);
  1850. usedRegs := usedRegs - noDeallocRegs;
  1851. for regCounter := RS_EAX to RS_EDI do
  1852. if regCounter in usedRegs then
  1853. addRegDeallocFor(list,regCounter,prev);
  1854. {$endif i386}
  1855. end;
  1856. function tdfaobj.pass_1(_blockstart: tai): tai;
  1857. begin
  1858. blockstart := _blockstart;
  1859. initlabeltable;
  1860. pass_1 := blockend;
  1861. end;
  1862. function tdfaobj.initdfapass2: boolean;
  1863. {reserves memory for the PtaiProps in one big memory block when not using
  1864. TP, returns False if not enough memory is available for the optimizer in all
  1865. cases}
  1866. var
  1867. p: tai;
  1868. count: Longint;
  1869. { TmpStr: String; }
  1870. begin
  1871. p := blockstart;
  1872. skiphead(p);
  1873. nroftaiobjs := 0;
  1874. while (p <> blockend) do
  1875. begin
  1876. {$ifDef JumpAnal}
  1877. case p.typ of
  1878. ait_label:
  1879. begin
  1880. if not labelcanbeskipped(tai_label(p)) then
  1881. labeltable^[tai_label(p).l.labelnr-lolab].instrnr := nroftaiobjs
  1882. end;
  1883. ait_instruction:
  1884. begin
  1885. if taicpu(p).is_jmp then
  1886. begin
  1887. if (tasmlabel(taicpu(p).oper[0]^.sym).labelnr >= lolab) and
  1888. (tasmlabel(taicpu(p).oper[0]^.sym).labelnr <= hilab) then
  1889. inc(labeltable^[tasmlabel(taicpu(p).oper[0]^.sym).labelnr-lolab].refsfound);
  1890. end;
  1891. end;
  1892. { ait_instruction:
  1893. begin
  1894. if (taicpu(p).opcode = A_PUSH) and
  1895. (taicpu(p).oper[0]^.typ = top_symbol) and
  1896. (PCSymbol(taicpu(p).oper[0]^)^.offset = 0) then
  1897. begin
  1898. TmpStr := StrPas(PCSymbol(taicpu(p).oper[0]^)^.symbol);
  1899. if}
  1900. end;
  1901. {$endif JumpAnal}
  1902. inc(NrOftaiObjs);
  1903. getnextinstruction(p,p);
  1904. end;
  1905. if nroftaiobjs <> 0 then
  1906. begin
  1907. initdfapass2 := True;
  1908. getmem(taipropblock, nroftaiobjs*sizeof(ttaiprop));
  1909. fillchar(taiPropblock^,nroftaiobjs*sizeof(ttaiprop),0);
  1910. p := blockstart;
  1911. skiphead(p);
  1912. for count := 1 To nroftaiobjs do
  1913. begin
  1914. ptaiprop(p.optinfo) := @taipropblock^[count];
  1915. getnextinstruction(p, p);
  1916. end;
  1917. end
  1918. else
  1919. initdfapass2 := false;
  1920. end;
  1921. procedure tdfaobj.dodfapass2;
  1922. {Analyzes the Data Flow of an assembler list. Starts creating the reg
  1923. contents for the instructions starting with p. Returns the last tai which has
  1924. been processed}
  1925. var
  1926. curprop, LastFlagsChangeProp: ptaiprop;
  1927. Cnt, InstrCnt : Longint;
  1928. InstrProp: TInsProp;
  1929. UsedRegs: TRegSet;
  1930. prev,p : tai;
  1931. tmpref: TReference;
  1932. tmpsupreg: tsuperregister;
  1933. {$ifdef AnalyzeLoops}
  1934. hp : tai;
  1935. TmpState: Byte;
  1936. {$endif AnalyzeLoops}
  1937. begin
  1938. p := BlockStart;
  1939. LastFlagsChangeProp := nil;
  1940. prev := nil;
  1941. UsedRegs := [];
  1942. UpdateUsedregs(UsedRegs, p);
  1943. SkipHead(p);
  1944. BlockStart := p;
  1945. InstrCnt := 1;
  1946. fillchar(NrOfInstrSinceLastMod, SizeOf(NrOfInstrSinceLastMod), 0);
  1947. while (p <> Blockend) Do
  1948. begin
  1949. curprop := @taiPropBlock^[InstrCnt];
  1950. if assigned(prev)
  1951. then
  1952. begin
  1953. {$ifdef JumpAnal}
  1954. if (p.Typ <> ait_label) then
  1955. {$endif JumpAnal}
  1956. begin
  1957. curprop^.regs := ptaiprop(prev.OptInfo)^.Regs;
  1958. curprop^.DirFlag := ptaiprop(prev.OptInfo)^.DirFlag;
  1959. curprop^.FlagsUsed := false;
  1960. end
  1961. end
  1962. else
  1963. begin
  1964. fillchar(curprop^, SizeOf(curprop^), 0);
  1965. { For tmpreg := RS_EAX to RS_EDI Do
  1966. curprop^.regs[tmpreg].WState := 1;}
  1967. end;
  1968. curprop^.UsedRegs := UsedRegs;
  1969. curprop^.CanBeRemoved := False;
  1970. UpdateUsedRegs(UsedRegs, tai(p.Next));
  1971. For tmpsupreg := RS_EAX To RS_EDI Do
  1972. if NrOfInstrSinceLastMod[tmpsupreg] < 255 then
  1973. inc(NrOfInstrSinceLastMod[tmpsupreg])
  1974. else
  1975. begin
  1976. NrOfInstrSinceLastMod[tmpsupreg] := 0;
  1977. curprop^.regs[tmpsupreg].typ := con_unknown;
  1978. end;
  1979. case p.typ Of
  1980. ait_marker:;
  1981. ait_label:
  1982. {$ifndef JumpAnal}
  1983. if not labelCanBeSkipped(tai_label(p)) then
  1984. DestroyAllRegs(curprop,false,false);
  1985. {$else JumpAnal}
  1986. begin
  1987. if not labelCanBeSkipped(tai_label(p)) then
  1988. With LTable^[tai_Label(p).l^.labelnr-LoLab] Do
  1989. {$ifDef AnalyzeLoops}
  1990. if (RefsFound = tai_Label(p).l^.RefCount)
  1991. {$else AnalyzeLoops}
  1992. if (JmpsProcessed = tai_Label(p).l^.RefCount)
  1993. {$endif AnalyzeLoops}
  1994. then
  1995. {all jumps to this label have been found}
  1996. {$ifDef AnalyzeLoops}
  1997. if (JmpsProcessed > 0)
  1998. then
  1999. {$endif AnalyzeLoops}
  2000. {we've processed at least one jump to this label}
  2001. begin
  2002. if (GetLastInstruction(p, hp) and
  2003. not(((hp.typ = ait_instruction)) and
  2004. (taicpu_labeled(hp).is_jmp))
  2005. then
  2006. {previous instruction not a JMP -> the contents of the registers after the
  2007. previous intruction has been executed have to be taken into account as well}
  2008. For tmpsupreg := RS_EAX to RS_EDI Do
  2009. begin
  2010. if (curprop^.regs[tmpsupreg].WState <>
  2011. ptaiprop(hp.OptInfo)^.Regs[tmpsupreg].WState)
  2012. then DestroyReg(curprop, tmpsupreg, true)
  2013. end
  2014. end
  2015. {$ifDef AnalyzeLoops}
  2016. else
  2017. {a label from a backward jump (e.g. a loop), no jump to this label has
  2018. already been processed}
  2019. if GetLastInstruction(p, hp) and
  2020. not(hp.typ = ait_instruction) and
  2021. (taicpu_labeled(hp).opcode = A_JMP))
  2022. then
  2023. {previous instruction not a jmp, so keep all the registers' contents from the
  2024. previous instruction}
  2025. begin
  2026. curprop^.regs := ptaiprop(hp.OptInfo)^.Regs;
  2027. curprop.DirFlag := ptaiprop(hp.OptInfo)^.DirFlag;
  2028. end
  2029. else
  2030. {previous instruction a jmp and no jump to this label processed yet}
  2031. begin
  2032. hp := p;
  2033. Cnt := InstrCnt;
  2034. {continue until we find a jump to the label or a label which has already
  2035. been processed}
  2036. while GetNextInstruction(hp, hp) and
  2037. not((hp.typ = ait_instruction) and
  2038. (taicpu(hp).is_jmp) and
  2039. (tasmlabel(taicpu(hp).oper[0]^.sym).labelnr = tai_Label(p).l^.labelnr)) and
  2040. not((hp.typ = ait_label) and
  2041. (LTable^[tai_Label(hp).l^.labelnr-LoLab].RefsFound
  2042. = tai_Label(hp).l^.RefCount) and
  2043. (LTable^[tai_Label(hp).l^.labelnr-LoLab].JmpsProcessed > 0)) Do
  2044. inc(Cnt);
  2045. if (hp.typ = ait_label)
  2046. then
  2047. {there's a processed label after the current one}
  2048. begin
  2049. curprop^.regs := taiPropBlock^[Cnt].Regs;
  2050. curprop.DirFlag := taiPropBlock^[Cnt].DirFlag;
  2051. end
  2052. else
  2053. {there's no label anymore after the current one, or they haven't been
  2054. processed yet}
  2055. begin
  2056. GetLastInstruction(p, hp);
  2057. curprop^.regs := ptaiprop(hp.OptInfo)^.Regs;
  2058. curprop.DirFlag := ptaiprop(hp.OptInfo)^.DirFlag;
  2059. DestroyAllRegs(ptaiprop(hp.OptInfo),true,true)
  2060. end
  2061. end
  2062. {$endif AnalyzeLoops}
  2063. else
  2064. {not all references to this label have been found, so destroy all registers}
  2065. begin
  2066. GetLastInstruction(p, hp);
  2067. curprop^.regs := ptaiprop(hp.OptInfo)^.Regs;
  2068. curprop.DirFlag := ptaiprop(hp.OptInfo)^.DirFlag;
  2069. DestroyAllRegs(curprop,true,true)
  2070. end;
  2071. end;
  2072. {$endif JumpAnal}
  2073. {$ifdef GDB}
  2074. ait_stabs, ait_stabn, ait_stab_function_name:;
  2075. {$endif GDB}
  2076. ait_align: ; { may destroy flags !!! }
  2077. ait_instruction:
  2078. begin
  2079. if taicpu(p).is_jmp or
  2080. (taicpu(p).opcode = A_JMP) then
  2081. begin
  2082. {$ifNDef JumpAnal}
  2083. for tmpsupreg := RS_EAX to RS_EDI do
  2084. with curprop^.regs[tmpsupreg] do
  2085. case typ of
  2086. con_ref: typ := con_noRemoveRef;
  2087. con_const: typ := con_noRemoveConst;
  2088. con_invalid: typ := con_unknown;
  2089. end;
  2090. {$else JumpAnal}
  2091. With LTable^[tasmlabel(taicpu(p).oper[0]^.sym).labelnr-LoLab] Do
  2092. if (RefsFound = tasmlabel(taicpu(p).oper[0]^.sym).RefCount) then
  2093. begin
  2094. if (InstrCnt < InstrNr)
  2095. then
  2096. {forward jump}
  2097. if (JmpsProcessed = 0) then
  2098. {no jump to this label has been processed yet}
  2099. begin
  2100. taiPropBlock^[InstrNr].Regs := curprop^.regs;
  2101. taiPropBlock^[InstrNr].DirFlag := curprop.DirFlag;
  2102. inc(JmpsProcessed);
  2103. end
  2104. else
  2105. begin
  2106. For tmpreg := RS_EAX to RS_EDI Do
  2107. if (taiPropBlock^[InstrNr].Regs[tmpreg].WState <>
  2108. curprop^.regs[tmpreg].WState) then
  2109. DestroyReg(@taiPropBlock^[InstrNr], tmpreg, true);
  2110. inc(JmpsProcessed);
  2111. end
  2112. {$ifdef AnalyzeLoops}
  2113. else
  2114. { backward jump, a loop for example}
  2115. { if (JmpsProcessed > 0) or
  2116. not(GetLastInstruction(taiObj, hp) and
  2117. (hp.typ = ait_labeled_instruction) and
  2118. (taicpu_labeled(hp).opcode = A_JMP))
  2119. then}
  2120. {instruction prior to label is not a jmp, or at least one jump to the label
  2121. has yet been processed}
  2122. begin
  2123. inc(JmpsProcessed);
  2124. For tmpreg := RS_EAX to RS_EDI Do
  2125. if (taiPropBlock^[InstrNr].Regs[tmpreg].WState <>
  2126. curprop^.regs[tmpreg].WState)
  2127. then
  2128. begin
  2129. TmpState := taiPropBlock^[InstrNr].Regs[tmpreg].WState;
  2130. Cnt := InstrNr;
  2131. while (TmpState = taiPropBlock^[Cnt].Regs[tmpreg].WState) Do
  2132. begin
  2133. DestroyReg(@taiPropBlock^[Cnt], tmpreg, true);
  2134. inc(Cnt);
  2135. end;
  2136. while (Cnt <= InstrCnt) Do
  2137. begin
  2138. inc(taiPropBlock^[Cnt].Regs[tmpreg].WState);
  2139. inc(Cnt)
  2140. end
  2141. end;
  2142. end
  2143. { else }
  2144. {instruction prior to label is a jmp and no jumps to the label have yet been
  2145. processed}
  2146. { begin
  2147. inc(JmpsProcessed);
  2148. For tmpreg := RS_EAX to RS_EDI Do
  2149. begin
  2150. TmpState := taiPropBlock^[InstrNr].Regs[tmpreg].WState;
  2151. Cnt := InstrNr;
  2152. while (TmpState = taiPropBlock^[Cnt].Regs[tmpreg].WState) Do
  2153. begin
  2154. taiPropBlock^[Cnt].Regs[tmpreg] := curprop^.regs[tmpreg];
  2155. inc(Cnt);
  2156. end;
  2157. TmpState := taiPropBlock^[InstrNr].Regs[tmpreg].WState;
  2158. while (TmpState = taiPropBlock^[Cnt].Regs[tmpreg].WState) Do
  2159. begin
  2160. DestroyReg(@taiPropBlock^[Cnt], tmpreg, true);
  2161. inc(Cnt);
  2162. end;
  2163. while (Cnt <= InstrCnt) Do
  2164. begin
  2165. inc(taiPropBlock^[Cnt].Regs[tmpreg].WState);
  2166. inc(Cnt)
  2167. end
  2168. end
  2169. end}
  2170. {$endif AnalyzeLoops}
  2171. end;
  2172. {$endif JumpAnal}
  2173. end
  2174. else
  2175. begin
  2176. InstrProp := InsProp[taicpu(p).opcode];
  2177. case taicpu(p).opcode Of
  2178. A_MOV, A_MOVZX, A_MOVSX:
  2179. begin
  2180. case taicpu(p).oper[0]^.typ Of
  2181. top_ref, top_reg:
  2182. case taicpu(p).oper[1]^.typ Of
  2183. top_reg:
  2184. begin
  2185. {$ifdef statedebug}
  2186. hp := tai_comment.Create(strpnew('destroying '+
  2187. std_reg2str[taicpu(p).oper[1]^.reg])));
  2188. insertllitem(asml,p,p.next,hp);
  2189. {$endif statedebug}
  2190. readOp(curprop, taicpu(p).oper[0]^);
  2191. tmpsupreg := getsupreg(taicpu(p).oper[1]^.reg);
  2192. if reginop(tmpsupreg, taicpu(p).oper[0]^) and
  2193. (curprop^.regs[tmpsupreg].typ in [con_ref,con_noRemoveRef]) then
  2194. begin
  2195. with curprop^.regs[tmpsupreg] Do
  2196. begin
  2197. incState(wstate,1);
  2198. { also store how many instructions are part of the sequence in the first }
  2199. { instruction's ptaiprop, so it can be easily accessed from within }
  2200. { CheckSequence }
  2201. inc(nrOfMods, nrOfInstrSinceLastMod[tmpsupreg]);
  2202. ptaiprop(startmod.optinfo)^.regs[tmpsupreg].nrOfMods := nrOfMods;
  2203. nrOfInstrSinceLastMod[tmpsupreg] := 0;
  2204. { Destroy the contents of the registers }
  2205. { that depended on the previous value of }
  2206. { this register }
  2207. invalidateDependingRegs(curprop,tmpsupreg);
  2208. curprop^.regs[tmpsupreg].memwrite := nil;
  2209. end;
  2210. end
  2211. else
  2212. begin
  2213. {$ifdef statedebug}
  2214. hp := tai_comment.Create(strpnew('destroying & initing '+std_reg2str[tmpsupreg]));
  2215. insertllitem(asml,p,p.next,hp);
  2216. {$endif statedebug}
  2217. destroyReg(curprop, tmpsupreg, true);
  2218. if not(reginop(tmpsupreg, taicpu(p).oper[0]^)) then
  2219. with curprop^.regs[tmpsupreg] Do
  2220. begin
  2221. typ := con_ref;
  2222. startmod := p;
  2223. nrOfMods := 1;
  2224. end
  2225. end;
  2226. {$ifdef StateDebug}
  2227. hp := tai_comment.Create(strpnew(std_reg2str[tmpsupreg]+': '+tostr(curprop^.regs[tmpsupreg].WState)));
  2228. InsertLLItem(AsmL, p, p.next, hp);
  2229. {$endif StateDebug}
  2230. end;
  2231. top_ref:
  2232. begin
  2233. readref(curprop, taicpu(p).oper[1]^.ref);
  2234. if taicpu(p).oper[0]^.typ = top_reg then
  2235. begin
  2236. readreg(curprop, getsupreg(taicpu(p).oper[0]^.reg));
  2237. DestroyRefs(p, taicpu(p).oper[1]^.ref^, getsupreg(taicpu(p).oper[0]^.reg));
  2238. ptaiprop(p.optinfo)^.regs[getsupreg(taicpu(p).oper[0]^.reg)].memwrite :=
  2239. taicpu(p);
  2240. end
  2241. else
  2242. DestroyRefs(p, taicpu(p).oper[1]^.ref^, RS_INVALID);
  2243. end;
  2244. end;
  2245. top_symbol,Top_Const:
  2246. begin
  2247. case taicpu(p).oper[1]^.typ Of
  2248. top_reg:
  2249. begin
  2250. tmpsupreg := getsupreg(taicpu(p).oper[1]^.reg);
  2251. {$ifdef statedebug}
  2252. hp := tai_comment.Create(strpnew('destroying '+std_reg2str[tmpsupreg]));
  2253. insertllitem(asml,p,p.next,hp);
  2254. {$endif statedebug}
  2255. With curprop^.regs[tmpsupreg] Do
  2256. begin
  2257. DestroyReg(curprop, tmpsupreg, true);
  2258. typ := Con_Const;
  2259. StartMod := p;
  2260. end
  2261. end;
  2262. top_ref:
  2263. begin
  2264. readref(curprop, taicpu(p).oper[1]^.ref);
  2265. DestroyRefs(p, taicpu(p).oper[1]^.ref^, RS_INVALID);
  2266. end;
  2267. end;
  2268. end;
  2269. end;
  2270. end;
  2271. A_DIV, A_IDIV, A_MUL:
  2272. begin
  2273. ReadOp(curprop, taicpu(p).oper[0]^);
  2274. readreg(curprop,RS_EAX);
  2275. if (taicpu(p).OpCode = A_IDIV) or
  2276. (taicpu(p).OpCode = A_DIV) then
  2277. begin
  2278. readreg(curprop,RS_EDX);
  2279. end;
  2280. {$ifdef statedebug}
  2281. hp := tai_comment.Create(strpnew('destroying eax and edx'));
  2282. insertllitem(asml,p,p.next,hp);
  2283. {$endif statedebug}
  2284. { DestroyReg(curprop, RS_EAX, true);}
  2285. AddInstr2RegContents({$ifdef statedebug}asml,{$endif}
  2286. taicpu(p), RS_EAX);
  2287. DestroyReg(curprop, RS_EDX, true)
  2288. end;
  2289. A_IMUL:
  2290. begin
  2291. ReadOp(curprop,taicpu(p).oper[0]^);
  2292. if (taicpu(p).ops >= 2) then
  2293. ReadOp(curprop,taicpu(p).oper[1]^);
  2294. if (taicpu(p).ops <= 2) then
  2295. if (taicpu(p).oper[1]^.typ = top_none) then
  2296. begin
  2297. readreg(curprop,RS_EAX);
  2298. {$ifdef statedebug}
  2299. hp := tai_comment.Create(strpnew('destroying eax and edx'));
  2300. insertllitem(asml,p,p.next,hp);
  2301. {$endif statedebug}
  2302. { DestroyReg(curprop, RS_EAX, true); }
  2303. AddInstr2RegContents({$ifdef statedebug}asml,{$endif}
  2304. taicpu(p), RS_EAX);
  2305. DestroyReg(curprop,RS_EDX, true)
  2306. end
  2307. else
  2308. AddInstr2OpContents(
  2309. {$ifdef statedebug}asml,{$endif}
  2310. taicpu(p), taicpu(p).oper[1]^)
  2311. else
  2312. AddInstr2OpContents({$ifdef statedebug}asml,{$endif}
  2313. taicpu(p), taicpu(p).oper[2]^);
  2314. end;
  2315. A_LEA:
  2316. begin
  2317. readop(curprop,taicpu(p).oper[0]^);
  2318. if reginref(getsupreg(taicpu(p).oper[1]^.reg),taicpu(p).oper[0]^.ref^) then
  2319. AddInstr2RegContents({$ifdef statedebug}asml,{$endif}
  2320. taicpu(p), getsupreg(taicpu(p).oper[1]^.reg))
  2321. else
  2322. begin
  2323. {$ifdef statedebug}
  2324. hp := tai_comment.Create(strpnew('destroying & initing'+
  2325. std_reg2str[taicpu(p).oper[1]^.reg])));
  2326. insertllitem(asml,p,p.next,hp);
  2327. {$endif statedebug}
  2328. destroyreg(curprop,getsupreg(taicpu(p).oper[1]^.reg),true);
  2329. with curprop^.regs[getsupreg(taicpu(p).oper[1]^.reg)] Do
  2330. begin
  2331. typ := con_ref;
  2332. startmod := p;
  2333. nrOfMods := 1;
  2334. end
  2335. end;
  2336. end;
  2337. else
  2338. begin
  2339. Cnt := 1;
  2340. while (Cnt <= MaxCh) and
  2341. (InstrProp.Ch[Cnt] <> Ch_None) Do
  2342. begin
  2343. case InstrProp.Ch[Cnt] Of
  2344. Ch_REAX..Ch_REDI:
  2345. begin
  2346. tmpsupreg:=tch2reg(InstrProp.Ch[Cnt]);
  2347. readreg(curprop,tmpsupreg);
  2348. end;
  2349. Ch_WEAX..Ch_RWEDI:
  2350. begin
  2351. if (InstrProp.Ch[Cnt] >= Ch_RWEAX) then
  2352. begin
  2353. tmpsupreg:=tch2reg(InstrProp.Ch[Cnt]);
  2354. readreg(curprop,tmpsupreg);
  2355. end;
  2356. {$ifdef statedebug}
  2357. hp := tai_comment.Create(strpnew('destroying '+
  2358. std_reg2str[tch2reg(InstrProp.Ch[Cnt])])));
  2359. insertllitem(asml,p,p.next,hp);
  2360. {$endif statedebug}
  2361. tmpsupreg:=tch2reg(InstrProp.Ch[Cnt]);
  2362. DestroyReg(curprop,tmpsupreg, true);
  2363. end;
  2364. Ch_MEAX..Ch_MEDI:
  2365. begin
  2366. tmpsupreg:=tch2reg(InstrProp.Ch[Cnt]);
  2367. AddInstr2RegContents({$ifdef statedebug} asml,{$endif}
  2368. taicpu(p),tmpsupreg);
  2369. end;
  2370. Ch_CDirFlag: curprop^.DirFlag := F_notSet;
  2371. Ch_SDirFlag: curprop^.DirFlag := F_Set;
  2372. Ch_Rop1: ReadOp(curprop, taicpu(p).oper[0]^);
  2373. Ch_Rop2: ReadOp(curprop, taicpu(p).oper[1]^);
  2374. Ch_ROp3: ReadOp(curprop, taicpu(p).oper[2]^);
  2375. Ch_Wop1..Ch_RWop1:
  2376. begin
  2377. if (InstrProp.Ch[Cnt] in [Ch_RWop1]) then
  2378. ReadOp(curprop, taicpu(p).oper[0]^);
  2379. DestroyOp(p, taicpu(p).oper[0]^);
  2380. end;
  2381. Ch_Mop1:
  2382. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  2383. taicpu(p), taicpu(p).oper[0]^);
  2384. Ch_Wop2..Ch_RWop2:
  2385. begin
  2386. if (InstrProp.Ch[Cnt] = Ch_RWop2) then
  2387. ReadOp(curprop, taicpu(p).oper[1]^);
  2388. DestroyOp(p, taicpu(p).oper[1]^);
  2389. end;
  2390. Ch_Mop2:
  2391. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  2392. taicpu(p), taicpu(p).oper[1]^);
  2393. Ch_WOp3..Ch_RWOp3:
  2394. begin
  2395. if (InstrProp.Ch[Cnt] = Ch_RWOp3) then
  2396. ReadOp(curprop, taicpu(p).oper[2]^);
  2397. DestroyOp(p, taicpu(p).oper[2]^);
  2398. end;
  2399. Ch_Mop3:
  2400. AddInstr2OpContents({$ifdef statedebug} asml, {$endif}
  2401. taicpu(p), taicpu(p).oper[2]^);
  2402. Ch_WMemEDI:
  2403. begin
  2404. readreg(curprop, RS_EDI);
  2405. fillchar(tmpref, SizeOf(tmpref), 0);
  2406. tmpref.base := NR_EDI;
  2407. tmpref.index := NR_EDI;
  2408. DestroyRefs(p, tmpref,RS_INVALID)
  2409. end;
  2410. Ch_RFlags:
  2411. if assigned(LastFlagsChangeProp) then
  2412. LastFlagsChangeProp^.FlagsUsed := true;
  2413. Ch_WFlags:
  2414. LastFlagsChangeProp := curprop;
  2415. Ch_RWFlags:
  2416. begin
  2417. if assigned(LastFlagsChangeProp) then
  2418. LastFlagsChangeProp^.FlagsUsed := true;
  2419. LastFlagsChangeProp := curprop;
  2420. end;
  2421. Ch_FPU:;
  2422. else
  2423. begin
  2424. {$ifdef statedebug}
  2425. hp := tai_comment.Create(strpnew(
  2426. 'destroying all regs for prev instruction')));
  2427. insertllitem(asml,p, p.next,hp);
  2428. {$endif statedebug}
  2429. DestroyAllRegs(curprop,true,true);
  2430. LastFlagsChangeProp := curprop;
  2431. end;
  2432. end;
  2433. inc(Cnt);
  2434. end
  2435. end;
  2436. end;
  2437. end;
  2438. end
  2439. else
  2440. begin
  2441. {$ifdef statedebug}
  2442. hp := tai_comment.Create(strpnew(
  2443. 'destroying all regs: unknown tai: '+tostr(ord(p.typ)))));
  2444. insertllitem(asml,p, p.next,hp);
  2445. {$endif statedebug}
  2446. DestroyAllRegs(curprop,true,true);
  2447. end;
  2448. end;
  2449. inc(InstrCnt);
  2450. prev := p;
  2451. GetNextInstruction(p, p);
  2452. end;
  2453. end;
  2454. function tdfaobj.pass_2: boolean;
  2455. begin
  2456. if initdfapass2 then
  2457. begin
  2458. dodfapass2;
  2459. pass_2 := true
  2460. end
  2461. else
  2462. pass_2 := false;
  2463. end;
  2464. {$ifopt r+}
  2465. {$define rangewason}
  2466. {$r-}
  2467. {$endif}
  2468. function tdfaobj.getlabelwithsym(sym: tasmlabel): tai;
  2469. begin
  2470. if (sym.labelnr >= lolab) and
  2471. (sym.labelnr <= hilab) then { range check, a jump can go past an assembler block! }
  2472. getlabelwithsym := labeltable^[sym.labelnr-lolab].taiobj
  2473. else
  2474. getlabelwithsym := nil;
  2475. end;
  2476. {$ifdef rangewason}
  2477. {$r+}
  2478. {$undef rangewason}
  2479. {$endif}
  2480. procedure tdfaobj.clear;
  2481. begin
  2482. if labdif <> 0 then
  2483. begin
  2484. freemem(labeltable);
  2485. labeltable := nil;
  2486. end;
  2487. if assigned(taipropblock) then
  2488. begin
  2489. freemem(taipropblock, nroftaiobjs*sizeof(ttaiprop));
  2490. taipropblock := nil;
  2491. end;
  2492. end;
  2493. end.
  2494. {
  2495. $Log$
  2496. Revision 1.55 2003-11-22 13:10:32 jonas
  2497. * fixed double unit usage
  2498. Revision 1.54 2003/11/22 00:40:19 jonas
  2499. * fixed optimiser so it compiles again
  2500. * fixed several bugs which were in there already for a long time, but
  2501. which only popped up now :) -O2/-O3 will now optimise less than in
  2502. the past (and correctly so), but -O2u/-O3u will optimise a bit more
  2503. * some more small improvements for -O3 are still possible
  2504. Revision 1.53 2003/06/13 21:19:31 peter
  2505. * current_procdef removed, use current_procinfo.procdef instead
  2506. Revision 1.52 2003/06/08 18:48:03 jonas
  2507. * first small steps towards an oop optimizer
  2508. Revision 1.51 2003/06/03 21:09:05 peter
  2509. * internal changeregsize for optimizer
  2510. * fix with a hack to not remove the first instruction of a block
  2511. which will leave blockstart pointing to invalid memory
  2512. Revision 1.50 2003/05/26 21:17:18 peter
  2513. * procinlinenode removed
  2514. * aktexit2label removed, fast exit removed
  2515. + tcallnode.inlined_pass_2 added
  2516. Revision 1.49 2003/04/27 11:21:35 peter
  2517. * aktprocdef renamed to current_procinfo.procdef
  2518. * procinfo renamed to current_procinfo
  2519. * procinfo will now be stored in current_module so it can be
  2520. cleaned up properly
  2521. * gen_main_procsym changed to create_main_proc and release_main_proc
  2522. to also generate a tprocinfo structure
  2523. * fixed unit implicit initfinal
  2524. Revision 1.48 2003/03/28 19:16:57 peter
  2525. * generic constructor working for i386
  2526. * remove fixed self register
  2527. * esi added as address register for i386
  2528. Revision 1.47 2003/02/26 21:15:43 daniel
  2529. * Fixed the optimizer
  2530. Revision 1.46 2003/02/19 22:00:15 daniel
  2531. * Code generator converted to new register notation
  2532. - Horribily outdated todo.txt removed
  2533. Revision 1.45 2003/01/08 18:43:57 daniel
  2534. * Tregister changed into a record
  2535. Revision 1.44 2002/11/17 16:31:59 carl
  2536. * memory optimization (3-4%) : cleanup of tai fields,
  2537. cleanup of tdef and tsym fields.
  2538. * make it work for m68k
  2539. Revision 1.43 2002/08/18 20:06:29 peter
  2540. * inlining is now also allowed in interface
  2541. * renamed write/load to ppuwrite/ppuload
  2542. * tnode storing in ppu
  2543. * nld,ncon,nbas are already updated for storing in ppu
  2544. Revision 1.42 2002/08/17 09:23:44 florian
  2545. * first part of procinfo rewrite
  2546. Revision 1.41 2002/07/01 18:46:31 peter
  2547. * internal linker
  2548. * reorganized aasm layer
  2549. Revision 1.40 2002/06/24 12:43:00 jonas
  2550. * fixed errors found with new -CR code from Peter when cycling with -O2p3r
  2551. Revision 1.39 2002/06/09 12:56:04 jonas
  2552. * IDIV reads edx too (but now the div/mod optimization fails :/ )
  2553. Revision 1.38 2002/05/18 13:34:22 peter
  2554. * readded missing revisions
  2555. Revision 1.37 2002/05/16 19:46:51 carl
  2556. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2557. + try to fix temp allocation (still in ifdef)
  2558. + generic constructor calls
  2559. + start of tassembler / tmodulebase class cleanup
  2560. Revision 1.34 2002/05/12 16:53:16 peter
  2561. * moved entry and exitcode to ncgutil and cgobj
  2562. * foreach gets extra argument for passing local data to the
  2563. iterator function
  2564. * -CR checks also class typecasts at runtime by changing them
  2565. into as
  2566. * fixed compiler to cycle with the -CR option
  2567. * fixed stabs with elf writer, finally the global variables can
  2568. be watched
  2569. * removed a lot of routines from cga unit and replaced them by
  2570. calls to cgobj
  2571. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2572. u32bit then the other is typecasted also to u32bit without giving
  2573. a rangecheck warning/error.
  2574. * fixed pascal calling method with reversing also the high tree in
  2575. the parast, detected by tcalcst3 test
  2576. Revision 1.33 2002/04/21 15:32:59 carl
  2577. * changeregsize -> changeregsize
  2578. Revision 1.32 2002/04/20 21:37:07 carl
  2579. + generic FPC_CHECKPOINTER
  2580. + first parameter offset in stack now portable
  2581. * rename some constants
  2582. + move some cpu stuff to other units
  2583. - remove unused constents
  2584. * fix stacksize for some targets
  2585. * fix generic size problems which depend now on EXTEND_SIZE constant
  2586. * removing frame pointer in routines is only available for : i386,m68k and vis targets
  2587. Revision 1.31 2002/04/15 19:44:20 peter
  2588. * fixed stackcheck that would be called recursively when a stack
  2589. error was found
  2590. * generic changeregsize(reg,size) for i386 register resizing
  2591. * removed some more routines from cga unit
  2592. * fixed returnvalue handling
  2593. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  2594. Revision 1.30 2002/04/15 19:12:09 carl
  2595. + target_info.size_of_pointer -> pointeRS_size
  2596. + some cleanup of unused types/variables
  2597. * move several constants from cpubase to their specific units
  2598. (where they are used)
  2599. + att_Reg2str -> gas_reg2str
  2600. + int_reg2str -> std_reg2str
  2601. Revision 1.29 2002/04/14 17:00:49 carl
  2602. + att_reg2str -> std_reg2str
  2603. Revision 1.28 2002/04/02 17:11:34 peter
  2604. * tlocation,treference update
  2605. * LOC_CONSTANT added for better constant handling
  2606. * secondadd splitted in multiple routines
  2607. * location_force_reg added for loading a location to a register
  2608. of a specified size
  2609. * secondassignment parses now first the right and then the left node
  2610. (this is compatible with Kylix). This saves a lot of push/pop especially
  2611. with string operations
  2612. * adapted some routines to use the new cg methods
  2613. Revision 1.27 2002/03/31 20:26:38 jonas
  2614. + a_loadfpu_* and a_loadmm_* methods in tcg
  2615. * register allocation is now handled by a class and is mostly processor
  2616. independent (+rgobj.pas and i386/rgcpu.pas)
  2617. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  2618. * some small improvements and fixes to the optimizer
  2619. * some register allocation fixes
  2620. * some fpuvaroffset fixes in the unary minus node
  2621. * push/popusedregisters is now called rg.save/restoreusedregisters and
  2622. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  2623. also better optimizable)
  2624. * fixed and optimized register saving/restoring for new/dispose nodes
  2625. * LOC_FPU locations now also require their "register" field to be set to
  2626. RS_ST, not RS_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  2627. - list field removed of the tnode class because it's not used currently
  2628. and can cause hard-to-find bugs
  2629. Revision 1.26 2002/03/04 19:10:13 peter
  2630. * removed compiler warnings
  2631. }