df-scan.c 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338
  1. /* Scanning of rtl for dataflow analysis.
  2. Copyright (C) 1999-2015 Free Software Foundation, Inc.
  3. Originally contributed by Michael P. Hayes
  4. (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
  5. Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
  6. and Kenneth Zadeck (zadeck@naturalbridge.com).
  7. This file is part of GCC.
  8. GCC is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 3, or (at your option) any later
  11. version.
  12. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with GCC; see the file COPYING3. If not see
  18. <http://www.gnu.org/licenses/>. */
  19. #include "config.h"
  20. #include "system.h"
  21. #include "coretypes.h"
  22. #include "tm.h"
  23. #include "rtl.h"
  24. #include "tm_p.h"
  25. #include "insn-config.h"
  26. #include "recog.h"
  27. #include "hashtab.h"
  28. #include "hash-set.h"
  29. #include "machmode.h"
  30. #include "vec.h"
  31. #include "double-int.h"
  32. #include "input.h"
  33. #include "alias.h"
  34. #include "symtab.h"
  35. #include "wide-int.h"
  36. #include "inchash.h"
  37. #include "hard-reg-set.h"
  38. #include "input.h"
  39. #include "function.h"
  40. #include "regs.h"
  41. #include "alloc-pool.h"
  42. #include "flags.h"
  43. #include "predict.h"
  44. #include "dominance.h"
  45. #include "cfg.h"
  46. #include "basic-block.h"
  47. #include "sbitmap.h"
  48. #include "bitmap.h"
  49. #include "dumpfile.h"
  50. #include "tree.h"
  51. #include "target.h"
  52. #include "target-def.h"
  53. #include "df.h"
  54. #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
  55. typedef struct df_mw_hardreg *df_mw_hardreg_ptr;
  56. #ifndef HAVE_epilogue
  57. #define HAVE_epilogue 0
  58. #endif
  59. #ifndef HAVE_prologue
  60. #define HAVE_prologue 0
  61. #endif
  62. #ifndef HAVE_sibcall_epilogue
  63. #define HAVE_sibcall_epilogue 0
  64. #endif
  65. #ifndef EPILOGUE_USES
  66. #define EPILOGUE_USES(REGNO) 0
  67. #endif
  68. /* The set of hard registers in eliminables[i].from. */
  69. static HARD_REG_SET elim_reg_set;
  70. /* Initialize ur_in and ur_out as if all hard registers were partially
  71. available. */
  72. struct df_collection_rec
  73. {
  74. auto_vec<df_ref, 128> def_vec;
  75. auto_vec<df_ref, 32> use_vec;
  76. auto_vec<df_ref, 32> eq_use_vec;
  77. auto_vec<df_mw_hardreg_ptr, 32> mw_vec;
  78. };
  79. static void df_ref_record (enum df_ref_class, struct df_collection_rec *,
  80. rtx, rtx *,
  81. basic_block, struct df_insn_info *,
  82. enum df_ref_type, int ref_flags);
  83. static void df_def_record_1 (struct df_collection_rec *, rtx *,
  84. basic_block, struct df_insn_info *,
  85. int ref_flags);
  86. static void df_defs_record (struct df_collection_rec *, rtx,
  87. basic_block, struct df_insn_info *,
  88. int ref_flags);
  89. static void df_uses_record (struct df_collection_rec *,
  90. rtx *, enum df_ref_type,
  91. basic_block, struct df_insn_info *,
  92. int ref_flags);
  93. static void df_install_ref_incremental (df_ref);
  94. static void df_insn_refs_collect (struct df_collection_rec*,
  95. basic_block, struct df_insn_info *);
  96. static void df_canonize_collection_rec (struct df_collection_rec *);
  97. static void df_get_regular_block_artificial_uses (bitmap);
  98. static void df_get_eh_block_artificial_uses (bitmap);
  99. static void df_record_entry_block_defs (bitmap);
  100. static void df_record_exit_block_uses (bitmap);
  101. static void df_get_exit_block_use_set (bitmap);
  102. static void df_get_entry_block_def_set (bitmap);
  103. static void df_grow_ref_info (struct df_ref_info *, unsigned int);
  104. static void df_ref_chain_delete_du_chain (df_ref);
  105. static void df_ref_chain_delete (df_ref);
  106. static void df_refs_add_to_chains (struct df_collection_rec *,
  107. basic_block, rtx_insn *, unsigned int);
  108. static bool df_insn_refs_verify (struct df_collection_rec *, basic_block,
  109. rtx_insn *, bool);
  110. static void df_entry_block_defs_collect (struct df_collection_rec *, bitmap);
  111. static void df_exit_block_uses_collect (struct df_collection_rec *, bitmap);
  112. static void df_install_ref (df_ref, struct df_reg_info *,
  113. struct df_ref_info *, bool);
  114. static int df_ref_compare (df_ref, df_ref);
  115. static int df_ref_ptr_compare (const void *, const void *);
  116. static int df_mw_compare (const df_mw_hardreg *, const df_mw_hardreg *);
  117. static int df_mw_ptr_compare (const void *, const void *);
  118. static void df_insn_info_delete (unsigned int);
  119. /* Indexed by hardware reg number, is true if that register is ever
  120. used in the current function.
  121. In df-scan.c, this is set up to record the hard regs used
  122. explicitly. Reload adds in the hard regs used for holding pseudo
  123. regs. Final uses it to generate the code in the function prologue
  124. and epilogue to save and restore registers as needed. */
  125. static bool regs_ever_live[FIRST_PSEUDO_REGISTER];
  126. /* Flags used to tell df_refs_add_to_chains() which vectors it should copy. */
  127. static const unsigned int copy_defs = 0x1;
  128. static const unsigned int copy_uses = 0x2;
  129. static const unsigned int copy_eq_uses = 0x4;
  130. static const unsigned int copy_mw = 0x8;
  131. static const unsigned int copy_all = copy_defs | copy_uses | copy_eq_uses
  132. | copy_mw;
  133. /*----------------------------------------------------------------------------
  134. SCANNING DATAFLOW PROBLEM
  135. There are several ways in which scanning looks just like the other
  136. dataflow problems. It shares the all the mechanisms for local info
  137. as well as basic block info. Where it differs is when and how often
  138. it gets run. It also has no need for the iterative solver.
  139. ----------------------------------------------------------------------------*/
  140. /* Problem data for the scanning dataflow function. */
  141. struct df_scan_problem_data
  142. {
  143. alloc_pool ref_base_pool;
  144. alloc_pool ref_artificial_pool;
  145. alloc_pool ref_regular_pool;
  146. alloc_pool insn_pool;
  147. alloc_pool reg_pool;
  148. alloc_pool mw_reg_pool;
  149. bitmap_obstack reg_bitmaps;
  150. bitmap_obstack insn_bitmaps;
  151. };
  152. typedef struct df_scan_bb_info *df_scan_bb_info_t;
  153. /* Internal function to shut down the scanning problem. */
  154. static void
  155. df_scan_free_internal (void)
  156. {
  157. struct df_scan_problem_data *problem_data
  158. = (struct df_scan_problem_data *) df_scan->problem_data;
  159. free (df->def_info.refs);
  160. free (df->def_info.begin);
  161. free (df->def_info.count);
  162. memset (&df->def_info, 0, (sizeof (struct df_ref_info)));
  163. free (df->use_info.refs);
  164. free (df->use_info.begin);
  165. free (df->use_info.count);
  166. memset (&df->use_info, 0, (sizeof (struct df_ref_info)));
  167. free (df->def_regs);
  168. df->def_regs = NULL;
  169. free (df->use_regs);
  170. df->use_regs = NULL;
  171. free (df->eq_use_regs);
  172. df->eq_use_regs = NULL;
  173. df->regs_size = 0;
  174. DF_REG_SIZE (df) = 0;
  175. free (df->insns);
  176. df->insns = NULL;
  177. DF_INSN_SIZE () = 0;
  178. free (df_scan->block_info);
  179. df_scan->block_info = NULL;
  180. df_scan->block_info_size = 0;
  181. bitmap_clear (&df->hardware_regs_used);
  182. bitmap_clear (&df->regular_block_artificial_uses);
  183. bitmap_clear (&df->eh_block_artificial_uses);
  184. BITMAP_FREE (df->entry_block_defs);
  185. BITMAP_FREE (df->exit_block_uses);
  186. bitmap_clear (&df->insns_to_delete);
  187. bitmap_clear (&df->insns_to_rescan);
  188. bitmap_clear (&df->insns_to_notes_rescan);
  189. free_alloc_pool (problem_data->ref_base_pool);
  190. free_alloc_pool (problem_data->ref_artificial_pool);
  191. free_alloc_pool (problem_data->ref_regular_pool);
  192. free_alloc_pool (problem_data->insn_pool);
  193. free_alloc_pool (problem_data->reg_pool);
  194. free_alloc_pool (problem_data->mw_reg_pool);
  195. bitmap_obstack_release (&problem_data->reg_bitmaps);
  196. bitmap_obstack_release (&problem_data->insn_bitmaps);
  197. free (df_scan->problem_data);
  198. }
  199. /* Free basic block info. */
  200. static void
  201. df_scan_free_bb_info (basic_block bb, void *vbb_info)
  202. {
  203. struct df_scan_bb_info *bb_info = (struct df_scan_bb_info *) vbb_info;
  204. unsigned int bb_index = bb->index;
  205. rtx_insn *insn;
  206. FOR_BB_INSNS (bb, insn)
  207. if (INSN_P (insn))
  208. df_insn_info_delete (INSN_UID (insn));
  209. if (bb_index < df_scan->block_info_size)
  210. bb_info = df_scan_get_bb_info (bb_index);
  211. /* Get rid of any artificial uses or defs. */
  212. df_ref_chain_delete_du_chain (bb_info->artificial_defs);
  213. df_ref_chain_delete_du_chain (bb_info->artificial_uses);
  214. df_ref_chain_delete (bb_info->artificial_defs);
  215. df_ref_chain_delete (bb_info->artificial_uses);
  216. bb_info->artificial_defs = NULL;
  217. bb_info->artificial_uses = NULL;
  218. }
  219. /* Allocate the problem data for the scanning problem. This should be
  220. called when the problem is created or when the entire function is to
  221. be rescanned. */
  222. void
  223. df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
  224. {
  225. struct df_scan_problem_data *problem_data;
  226. unsigned int insn_num = get_max_uid () + 1;
  227. unsigned int block_size = 512;
  228. basic_block bb;
  229. /* Given the number of pools, this is really faster than tearing
  230. everything apart. */
  231. if (df_scan->problem_data)
  232. df_scan_free_internal ();
  233. problem_data = XNEW (struct df_scan_problem_data);
  234. df_scan->problem_data = problem_data;
  235. df_scan->computed = true;
  236. problem_data->ref_base_pool
  237. = create_alloc_pool ("df_scan ref base",
  238. sizeof (struct df_base_ref), block_size);
  239. problem_data->ref_artificial_pool
  240. = create_alloc_pool ("df_scan ref artificial",
  241. sizeof (struct df_artificial_ref), block_size);
  242. problem_data->ref_regular_pool
  243. = create_alloc_pool ("df_scan ref regular",
  244. sizeof (struct df_regular_ref), block_size);
  245. problem_data->insn_pool
  246. = create_alloc_pool ("df_scan insn",
  247. sizeof (struct df_insn_info), block_size);
  248. problem_data->reg_pool
  249. = create_alloc_pool ("df_scan reg",
  250. sizeof (struct df_reg_info), block_size);
  251. problem_data->mw_reg_pool
  252. = create_alloc_pool ("df_scan mw_reg",
  253. sizeof (struct df_mw_hardreg), block_size / 16);
  254. bitmap_obstack_initialize (&problem_data->reg_bitmaps);
  255. bitmap_obstack_initialize (&problem_data->insn_bitmaps);
  256. insn_num += insn_num / 4;
  257. df_grow_reg_info ();
  258. df_grow_insn_info ();
  259. df_grow_bb_info (df_scan);
  260. FOR_ALL_BB_FN (bb, cfun)
  261. {
  262. unsigned int bb_index = bb->index;
  263. struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb_index);
  264. bb_info->artificial_defs = NULL;
  265. bb_info->artificial_uses = NULL;
  266. }
  267. bitmap_initialize (&df->hardware_regs_used, &problem_data->reg_bitmaps);
  268. bitmap_initialize (&df->regular_block_artificial_uses, &problem_data->reg_bitmaps);
  269. bitmap_initialize (&df->eh_block_artificial_uses, &problem_data->reg_bitmaps);
  270. df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
  271. df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
  272. bitmap_initialize (&df->insns_to_delete, &problem_data->insn_bitmaps);
  273. bitmap_initialize (&df->insns_to_rescan, &problem_data->insn_bitmaps);
  274. bitmap_initialize (&df->insns_to_notes_rescan, &problem_data->insn_bitmaps);
  275. df_scan->optional_p = false;
  276. }
  277. /* Free all of the data associated with the scan problem. */
  278. static void
  279. df_scan_free (void)
  280. {
  281. if (df_scan->problem_data)
  282. df_scan_free_internal ();
  283. if (df->blocks_to_analyze)
  284. {
  285. BITMAP_FREE (df->blocks_to_analyze);
  286. df->blocks_to_analyze = NULL;
  287. }
  288. free (df_scan);
  289. }
  290. /* Dump the preamble for DF_SCAN dump. */
  291. static void
  292. df_scan_start_dump (FILE *file ATTRIBUTE_UNUSED)
  293. {
  294. int i;
  295. int dcount = 0;
  296. int ucount = 0;
  297. int ecount = 0;
  298. int icount = 0;
  299. int ccount = 0;
  300. basic_block bb;
  301. rtx_insn *insn;
  302. fprintf (file, ";; invalidated by call \t");
  303. df_print_regset (file, regs_invalidated_by_call_regset);
  304. fprintf (file, ";; hardware regs used \t");
  305. df_print_regset (file, &df->hardware_regs_used);
  306. fprintf (file, ";; regular block artificial uses \t");
  307. df_print_regset (file, &df->regular_block_artificial_uses);
  308. fprintf (file, ";; eh block artificial uses \t");
  309. df_print_regset (file, &df->eh_block_artificial_uses);
  310. fprintf (file, ";; entry block defs \t");
  311. df_print_regset (file, df->entry_block_defs);
  312. fprintf (file, ";; exit block uses \t");
  313. df_print_regset (file, df->exit_block_uses);
  314. fprintf (file, ";; regs ever live \t");
  315. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  316. if (df_regs_ever_live_p (i))
  317. fprintf (file, " %d[%s]", i, reg_names[i]);
  318. fprintf (file, "\n;; ref usage \t");
  319. for (i = 0; i < (int)df->regs_inited; i++)
  320. if (DF_REG_DEF_COUNT (i) || DF_REG_USE_COUNT (i) || DF_REG_EQ_USE_COUNT (i))
  321. {
  322. const char * sep = "";
  323. fprintf (file, "r%d={", i);
  324. if (DF_REG_DEF_COUNT (i))
  325. {
  326. fprintf (file, "%dd", DF_REG_DEF_COUNT (i));
  327. sep = ",";
  328. dcount += DF_REG_DEF_COUNT (i);
  329. }
  330. if (DF_REG_USE_COUNT (i))
  331. {
  332. fprintf (file, "%s%du", sep, DF_REG_USE_COUNT (i));
  333. sep = ",";
  334. ucount += DF_REG_USE_COUNT (i);
  335. }
  336. if (DF_REG_EQ_USE_COUNT (i))
  337. {
  338. fprintf (file, "%s%de", sep, DF_REG_EQ_USE_COUNT (i));
  339. ecount += DF_REG_EQ_USE_COUNT (i);
  340. }
  341. fprintf (file, "} ");
  342. }
  343. FOR_EACH_BB_FN (bb, cfun)
  344. FOR_BB_INSNS (bb, insn)
  345. if (INSN_P (insn))
  346. {
  347. if (CALL_P (insn))
  348. ccount++;
  349. else
  350. icount++;
  351. }
  352. fprintf (file, "\n;; total ref usage %d{%dd,%du,%de}"
  353. " in %d{%d regular + %d call} insns.\n",
  354. dcount + ucount + ecount, dcount, ucount, ecount,
  355. icount + ccount, icount, ccount);
  356. }
  357. /* Dump the bb_info for a given basic block. */
  358. static void
  359. df_scan_start_block (basic_block bb, FILE *file)
  360. {
  361. struct df_scan_bb_info *bb_info
  362. = df_scan_get_bb_info (bb->index);
  363. if (bb_info)
  364. {
  365. fprintf (file, ";; bb %d artificial_defs: ", bb->index);
  366. df_refs_chain_dump (bb_info->artificial_defs, true, file);
  367. fprintf (file, "\n;; bb %d artificial_uses: ", bb->index);
  368. df_refs_chain_dump (bb_info->artificial_uses, true, file);
  369. fprintf (file, "\n");
  370. }
  371. #if 0
  372. {
  373. rtx_insn *insn;
  374. FOR_BB_INSNS (bb, insn)
  375. if (INSN_P (insn))
  376. df_insn_debug (insn, false, file);
  377. }
  378. #endif
  379. }
  380. static struct df_problem problem_SCAN =
  381. {
  382. DF_SCAN, /* Problem id. */
  383. DF_NONE, /* Direction. */
  384. df_scan_alloc, /* Allocate the problem specific data. */
  385. NULL, /* Reset global information. */
  386. df_scan_free_bb_info, /* Free basic block info. */
  387. NULL, /* Local compute function. */
  388. NULL, /* Init the solution specific data. */
  389. NULL, /* Iterative solver. */
  390. NULL, /* Confluence operator 0. */
  391. NULL, /* Confluence operator n. */
  392. NULL, /* Transfer function. */
  393. NULL, /* Finalize function. */
  394. df_scan_free, /* Free all of the problem information. */
  395. NULL, /* Remove this problem from the stack of dataflow problems. */
  396. df_scan_start_dump, /* Debugging. */
  397. df_scan_start_block, /* Debugging start block. */
  398. NULL, /* Debugging end block. */
  399. NULL, /* Debugging start insn. */
  400. NULL, /* Debugging end insn. */
  401. NULL, /* Incremental solution verify start. */
  402. NULL, /* Incremental solution verify end. */
  403. NULL, /* Dependent problem. */
  404. sizeof (struct df_scan_bb_info),/* Size of entry of block_info array. */
  405. TV_DF_SCAN, /* Timing variable. */
  406. false /* Reset blocks on dropping out of blocks_to_analyze. */
  407. };
  408. /* Create a new DATAFLOW instance and add it to an existing instance
  409. of DF. The returned structure is what is used to get at the
  410. solution. */
  411. void
  412. df_scan_add_problem (void)
  413. {
  414. df_add_problem (&problem_SCAN);
  415. }
  416. /*----------------------------------------------------------------------------
  417. Storage Allocation Utilities
  418. ----------------------------------------------------------------------------*/
  419. /* First, grow the reg_info information. If the current size is less than
  420. the number of pseudos, grow to 25% more than the number of
  421. pseudos.
  422. Second, assure that all of the slots up to max_reg_num have been
  423. filled with reg_info structures. */
  424. void
  425. df_grow_reg_info (void)
  426. {
  427. unsigned int max_reg = max_reg_num ();
  428. unsigned int new_size = max_reg;
  429. struct df_scan_problem_data *problem_data
  430. = (struct df_scan_problem_data *) df_scan->problem_data;
  431. unsigned int i;
  432. if (df->regs_size < new_size)
  433. {
  434. new_size += new_size / 4;
  435. df->def_regs = XRESIZEVEC (struct df_reg_info *, df->def_regs, new_size);
  436. df->use_regs = XRESIZEVEC (struct df_reg_info *, df->use_regs, new_size);
  437. df->eq_use_regs = XRESIZEVEC (struct df_reg_info *, df->eq_use_regs,
  438. new_size);
  439. df->def_info.begin = XRESIZEVEC (unsigned, df->def_info.begin, new_size);
  440. df->def_info.count = XRESIZEVEC (unsigned, df->def_info.count, new_size);
  441. df->use_info.begin = XRESIZEVEC (unsigned, df->use_info.begin, new_size);
  442. df->use_info.count = XRESIZEVEC (unsigned, df->use_info.count, new_size);
  443. df->regs_size = new_size;
  444. }
  445. for (i = df->regs_inited; i < max_reg; i++)
  446. {
  447. struct df_reg_info *reg_info;
  448. reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
  449. memset (reg_info, 0, sizeof (struct df_reg_info));
  450. df->def_regs[i] = reg_info;
  451. reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
  452. memset (reg_info, 0, sizeof (struct df_reg_info));
  453. df->use_regs[i] = reg_info;
  454. reg_info = (struct df_reg_info *) pool_alloc (problem_data->reg_pool);
  455. memset (reg_info, 0, sizeof (struct df_reg_info));
  456. df->eq_use_regs[i] = reg_info;
  457. df->def_info.begin[i] = 0;
  458. df->def_info.count[i] = 0;
  459. df->use_info.begin[i] = 0;
  460. df->use_info.count[i] = 0;
  461. }
  462. df->regs_inited = max_reg;
  463. }
  464. /* Grow the ref information. */
  465. static void
  466. df_grow_ref_info (struct df_ref_info *ref_info, unsigned int new_size)
  467. {
  468. if (ref_info->refs_size < new_size)
  469. {
  470. ref_info->refs = XRESIZEVEC (df_ref, ref_info->refs, new_size);
  471. memset (ref_info->refs + ref_info->refs_size, 0,
  472. (new_size - ref_info->refs_size) *sizeof (df_ref));
  473. ref_info->refs_size = new_size;
  474. }
  475. }
  476. /* Check and grow the ref information if necessary. This routine
  477. guarantees total_size + BITMAP_ADDEND amount of entries in refs
  478. array. It updates ref_info->refs_size only and does not change
  479. ref_info->total_size. */
  480. static void
  481. df_check_and_grow_ref_info (struct df_ref_info *ref_info,
  482. unsigned bitmap_addend)
  483. {
  484. if (ref_info->refs_size < ref_info->total_size + bitmap_addend)
  485. {
  486. int new_size = ref_info->total_size + bitmap_addend;
  487. new_size += ref_info->total_size / 4;
  488. df_grow_ref_info (ref_info, new_size);
  489. }
  490. }
  491. /* Grow the ref information. If the current size is less than the
  492. number of instructions, grow to 25% more than the number of
  493. instructions. */
  494. void
  495. df_grow_insn_info (void)
  496. {
  497. unsigned int new_size = get_max_uid () + 1;
  498. if (DF_INSN_SIZE () < new_size)
  499. {
  500. new_size += new_size / 4;
  501. df->insns = XRESIZEVEC (struct df_insn_info *, df->insns, new_size);
  502. memset (df->insns + df->insns_size, 0,
  503. (new_size - DF_INSN_SIZE ()) *sizeof (struct df_insn_info *));
  504. DF_INSN_SIZE () = new_size;
  505. }
  506. }
  507. /*----------------------------------------------------------------------------
  508. PUBLIC INTERFACES FOR SMALL GRAIN CHANGES TO SCANNING.
  509. ----------------------------------------------------------------------------*/
  510. /* Rescan all of the block_to_analyze or all of the blocks in the
  511. function if df_set_blocks if blocks_to_analyze is NULL; */
  512. void
  513. df_scan_blocks (void)
  514. {
  515. basic_block bb;
  516. df->def_info.ref_order = DF_REF_ORDER_NO_TABLE;
  517. df->use_info.ref_order = DF_REF_ORDER_NO_TABLE;
  518. df_get_regular_block_artificial_uses (&df->regular_block_artificial_uses);
  519. df_get_eh_block_artificial_uses (&df->eh_block_artificial_uses);
  520. bitmap_ior_into (&df->eh_block_artificial_uses,
  521. &df->regular_block_artificial_uses);
  522. /* ENTRY and EXIT blocks have special defs/uses. */
  523. df_get_entry_block_def_set (df->entry_block_defs);
  524. df_record_entry_block_defs (df->entry_block_defs);
  525. df_get_exit_block_use_set (df->exit_block_uses);
  526. df_record_exit_block_uses (df->exit_block_uses);
  527. df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK));
  528. df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
  529. /* Regular blocks */
  530. FOR_EACH_BB_FN (bb, cfun)
  531. {
  532. unsigned int bb_index = bb->index;
  533. df_bb_refs_record (bb_index, true);
  534. }
  535. }
  536. /* Create new refs under address LOC within INSN. This function is
  537. only used externally. REF_FLAGS must be either 0 or DF_REF_IN_NOTE,
  538. depending on whether LOC is inside PATTERN (INSN) or a note. */
  539. void
  540. df_uses_create (rtx *loc, rtx_insn *insn, int ref_flags)
  541. {
  542. gcc_assert (!(ref_flags & ~DF_REF_IN_NOTE));
  543. df_uses_record (NULL, loc, DF_REF_REG_USE,
  544. BLOCK_FOR_INSN (insn),
  545. DF_INSN_INFO_GET (insn),
  546. ref_flags);
  547. }
  548. static void
  549. df_install_ref_incremental (df_ref ref)
  550. {
  551. struct df_reg_info **reg_info;
  552. struct df_ref_info *ref_info;
  553. df_ref *ref_ptr;
  554. bool add_to_table;
  555. rtx_insn *insn = DF_REF_INSN (ref);
  556. basic_block bb = BLOCK_FOR_INSN (insn);
  557. if (DF_REF_REG_DEF_P (ref))
  558. {
  559. reg_info = df->def_regs;
  560. ref_info = &df->def_info;
  561. ref_ptr = &DF_INSN_DEFS (insn);
  562. add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
  563. }
  564. else if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
  565. {
  566. reg_info = df->eq_use_regs;
  567. ref_info = &df->use_info;
  568. ref_ptr = &DF_INSN_EQ_USES (insn);
  569. switch (ref_info->ref_order)
  570. {
  571. case DF_REF_ORDER_UNORDERED_WITH_NOTES:
  572. case DF_REF_ORDER_BY_REG_WITH_NOTES:
  573. case DF_REF_ORDER_BY_INSN_WITH_NOTES:
  574. add_to_table = true;
  575. break;
  576. default:
  577. add_to_table = false;
  578. break;
  579. }
  580. }
  581. else
  582. {
  583. reg_info = df->use_regs;
  584. ref_info = &df->use_info;
  585. ref_ptr = &DF_INSN_USES (insn);
  586. add_to_table = ref_info->ref_order != DF_REF_ORDER_NO_TABLE;
  587. }
  588. /* Do not add if ref is not in the right blocks. */
  589. if (add_to_table && df->analyze_subset)
  590. add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
  591. df_install_ref (ref, reg_info[DF_REF_REGNO (ref)], ref_info, add_to_table);
  592. if (add_to_table)
  593. switch (ref_info->ref_order)
  594. {
  595. case DF_REF_ORDER_UNORDERED_WITH_NOTES:
  596. case DF_REF_ORDER_BY_REG_WITH_NOTES:
  597. case DF_REF_ORDER_BY_INSN_WITH_NOTES:
  598. ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
  599. break;
  600. default:
  601. ref_info->ref_order = DF_REF_ORDER_UNORDERED;
  602. break;
  603. }
  604. while (*ref_ptr && df_ref_compare (*ref_ptr, ref) < 0)
  605. ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
  606. DF_REF_NEXT_LOC (ref) = *ref_ptr;
  607. *ref_ptr = ref;
  608. #if 0
  609. if (dump_file)
  610. {
  611. fprintf (dump_file, "adding ref ");
  612. df_ref_debug (ref, dump_file);
  613. }
  614. #endif
  615. /* By adding the ref directly, df_insn_rescan my not find any
  616. differences even though the block will have changed. So we need
  617. to mark the block dirty ourselves. */
  618. if (!DEBUG_INSN_P (DF_REF_INSN (ref)))
  619. df_set_bb_dirty (bb);
  620. }
  621. /*----------------------------------------------------------------------------
  622. UTILITIES TO CREATE AND DESTROY REFS AND CHAINS.
  623. ----------------------------------------------------------------------------*/
  624. static void
  625. df_free_ref (df_ref ref)
  626. {
  627. struct df_scan_problem_data *problem_data
  628. = (struct df_scan_problem_data *) df_scan->problem_data;
  629. switch (DF_REF_CLASS (ref))
  630. {
  631. case DF_REF_BASE:
  632. pool_free (problem_data->ref_base_pool, ref);
  633. break;
  634. case DF_REF_ARTIFICIAL:
  635. pool_free (problem_data->ref_artificial_pool, ref);
  636. break;
  637. case DF_REF_REGULAR:
  638. pool_free (problem_data->ref_regular_pool, ref);
  639. break;
  640. }
  641. }
  642. /* Unlink and delete REF at the reg_use, reg_eq_use or reg_def chain.
  643. Also delete the def-use or use-def chain if it exists. */
  644. static void
  645. df_reg_chain_unlink (df_ref ref)
  646. {
  647. df_ref next = DF_REF_NEXT_REG (ref);
  648. df_ref prev = DF_REF_PREV_REG (ref);
  649. int id = DF_REF_ID (ref);
  650. struct df_reg_info *reg_info;
  651. df_ref *refs = NULL;
  652. if (DF_REF_REG_DEF_P (ref))
  653. {
  654. int regno = DF_REF_REGNO (ref);
  655. reg_info = DF_REG_DEF_GET (regno);
  656. refs = df->def_info.refs;
  657. }
  658. else
  659. {
  660. if (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE)
  661. {
  662. reg_info = DF_REG_EQ_USE_GET (DF_REF_REGNO (ref));
  663. switch (df->use_info.ref_order)
  664. {
  665. case DF_REF_ORDER_UNORDERED_WITH_NOTES:
  666. case DF_REF_ORDER_BY_REG_WITH_NOTES:
  667. case DF_REF_ORDER_BY_INSN_WITH_NOTES:
  668. refs = df->use_info.refs;
  669. break;
  670. default:
  671. break;
  672. }
  673. }
  674. else
  675. {
  676. reg_info = DF_REG_USE_GET (DF_REF_REGNO (ref));
  677. refs = df->use_info.refs;
  678. }
  679. }
  680. if (refs)
  681. {
  682. if (df->analyze_subset)
  683. {
  684. if (bitmap_bit_p (df->blocks_to_analyze, DF_REF_BBNO (ref)))
  685. refs[id] = NULL;
  686. }
  687. else
  688. refs[id] = NULL;
  689. }
  690. /* Delete any def-use or use-def chains that start here. It is
  691. possible that there is trash in this field. This happens for
  692. insns that have been deleted when rescanning has been deferred
  693. and the chain problem has also been deleted. The chain tear down
  694. code skips deleted insns. */
  695. if (df_chain && DF_REF_CHAIN (ref))
  696. df_chain_unlink (ref);
  697. reg_info->n_refs--;
  698. if (DF_REF_FLAGS_IS_SET (ref, DF_HARD_REG_LIVE))
  699. {
  700. gcc_assert (DF_REF_REGNO (ref) < FIRST_PSEUDO_REGISTER);
  701. df->hard_regs_live_count[DF_REF_REGNO (ref)]--;
  702. }
  703. /* Unlink from the reg chain. If there is no prev, this is the
  704. first of the list. If not, just join the next and prev. */
  705. if (prev)
  706. DF_REF_NEXT_REG (prev) = next;
  707. else
  708. {
  709. gcc_assert (reg_info->reg_chain == ref);
  710. reg_info->reg_chain = next;
  711. }
  712. if (next)
  713. DF_REF_PREV_REG (next) = prev;
  714. df_free_ref (ref);
  715. }
  716. /* Create the insn record for INSN. If there was one there, zero it
  717. out. */
  718. struct df_insn_info *
  719. df_insn_create_insn_record (rtx_insn *insn)
  720. {
  721. struct df_scan_problem_data *problem_data
  722. = (struct df_scan_problem_data *) df_scan->problem_data;
  723. struct df_insn_info *insn_rec;
  724. df_grow_insn_info ();
  725. insn_rec = DF_INSN_INFO_GET (insn);
  726. if (!insn_rec)
  727. {
  728. insn_rec = (struct df_insn_info *) pool_alloc (problem_data->insn_pool);
  729. DF_INSN_INFO_SET (insn, insn_rec);
  730. }
  731. memset (insn_rec, 0, sizeof (struct df_insn_info));
  732. insn_rec->insn = insn;
  733. return insn_rec;
  734. }
  735. /* Delete all du chain (DF_REF_CHAIN()) of all refs in the ref chain. */
  736. static void
  737. df_ref_chain_delete_du_chain (df_ref ref)
  738. {
  739. for (; ref; ref = DF_REF_NEXT_LOC (ref))
  740. /* CHAIN is allocated by DF_CHAIN. So make sure to
  741. pass df_scan instance for the problem. */
  742. if (DF_REF_CHAIN (ref))
  743. df_chain_unlink (ref);
  744. }
  745. /* Delete all refs in the ref chain. */
  746. static void
  747. df_ref_chain_delete (df_ref ref)
  748. {
  749. df_ref next;
  750. for (; ref; ref = next)
  751. {
  752. next = DF_REF_NEXT_LOC (ref);
  753. df_reg_chain_unlink (ref);
  754. }
  755. }
  756. /* Delete the hardreg chain. */
  757. static void
  758. df_mw_hardreg_chain_delete (struct df_mw_hardreg *hardregs)
  759. {
  760. struct df_scan_problem_data *problem_data
  761. = (struct df_scan_problem_data *) df_scan->problem_data;
  762. df_mw_hardreg *next;
  763. for (; hardregs; hardregs = next)
  764. {
  765. next = DF_MWS_NEXT (hardregs);
  766. pool_free (problem_data->mw_reg_pool, hardregs);
  767. }
  768. }
  769. /* Delete all of the refs information from the insn with UID.
  770. Internal helper for df_insn_delete, df_insn_rescan, and other
  771. df-scan routines that don't have to work in deferred mode
  772. and do not have to mark basic blocks for re-processing. */
  773. static void
  774. df_insn_info_delete (unsigned int uid)
  775. {
  776. struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
  777. bitmap_clear_bit (&df->insns_to_delete, uid);
  778. bitmap_clear_bit (&df->insns_to_rescan, uid);
  779. bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
  780. if (insn_info)
  781. {
  782. struct df_scan_problem_data *problem_data
  783. = (struct df_scan_problem_data *) df_scan->problem_data;
  784. /* In general, notes do not have the insn_info fields
  785. initialized. However, combine deletes insns by changing them
  786. to notes. How clever. So we cannot just check if it is a
  787. valid insn before short circuiting this code, we need to see
  788. if we actually initialized it. */
  789. df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
  790. if (df_chain)
  791. {
  792. df_ref_chain_delete_du_chain (insn_info->defs);
  793. df_ref_chain_delete_du_chain (insn_info->uses);
  794. df_ref_chain_delete_du_chain (insn_info->eq_uses);
  795. }
  796. df_ref_chain_delete (insn_info->defs);
  797. df_ref_chain_delete (insn_info->uses);
  798. df_ref_chain_delete (insn_info->eq_uses);
  799. pool_free (problem_data->insn_pool, insn_info);
  800. DF_INSN_UID_SET (uid, NULL);
  801. }
  802. }
  803. /* Delete all of the refs information from INSN, either right now
  804. or marked for later in deferred mode. */
  805. void
  806. df_insn_delete (rtx_insn *insn)
  807. {
  808. unsigned int uid;
  809. basic_block bb;
  810. gcc_checking_assert (INSN_P (insn));
  811. if (!df)
  812. return;
  813. uid = INSN_UID (insn);
  814. bb = BLOCK_FOR_INSN (insn);
  815. /* ??? bb can be NULL after pass_free_cfg. At that point, DF should
  816. not exist anymore (as mentioned in df-core.c: "The only requirement
  817. [for DF] is that there be a correct control flow graph." Clearly
  818. that isn't the case after pass_free_cfg. But DF is freed much later
  819. because some back-ends want to use DF info even though the CFG is
  820. already gone. It's not clear to me whether that is safe, actually.
  821. In any case, we expect BB to be non-NULL at least up to register
  822. allocation, so disallow a non-NULL BB up to there. Not perfect
  823. but better than nothing... */
  824. gcc_checking_assert (bb != NULL || reload_completed);
  825. df_grow_bb_info (df_scan);
  826. df_grow_reg_info ();
  827. /* The block must be marked as dirty now, rather than later as in
  828. df_insn_rescan and df_notes_rescan because it may not be there at
  829. rescanning time and the mark would blow up.
  830. DEBUG_INSNs do not make a block's data flow solution dirty (at
  831. worst the LUIDs are no longer contiguous). */
  832. if (bb != NULL && NONDEBUG_INSN_P (insn))
  833. df_set_bb_dirty (bb);
  834. /* The client has deferred rescanning. */
  835. if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
  836. {
  837. struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
  838. if (insn_info)
  839. {
  840. bitmap_clear_bit (&df->insns_to_rescan, uid);
  841. bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
  842. bitmap_set_bit (&df->insns_to_delete, uid);
  843. }
  844. if (dump_file)
  845. fprintf (dump_file, "deferring deletion of insn with uid = %d.\n", uid);
  846. return;
  847. }
  848. if (dump_file)
  849. fprintf (dump_file, "deleting insn with uid = %d.\n", uid);
  850. df_insn_info_delete (uid);
  851. }
  852. /* Free all of the refs and the mw_hardregs in COLLECTION_REC. */
  853. static void
  854. df_free_collection_rec (struct df_collection_rec *collection_rec)
  855. {
  856. unsigned int ix;
  857. struct df_scan_problem_data *problem_data
  858. = (struct df_scan_problem_data *) df_scan->problem_data;
  859. df_ref ref;
  860. struct df_mw_hardreg *mw;
  861. FOR_EACH_VEC_ELT (collection_rec->def_vec, ix, ref)
  862. df_free_ref (ref);
  863. FOR_EACH_VEC_ELT (collection_rec->use_vec, ix, ref)
  864. df_free_ref (ref);
  865. FOR_EACH_VEC_ELT (collection_rec->eq_use_vec, ix, ref)
  866. df_free_ref (ref);
  867. FOR_EACH_VEC_ELT (collection_rec->mw_vec, ix, mw)
  868. pool_free (problem_data->mw_reg_pool, mw);
  869. collection_rec->def_vec.release ();
  870. collection_rec->use_vec.release ();
  871. collection_rec->eq_use_vec.release ();
  872. collection_rec->mw_vec.release ();
  873. }
  874. /* Rescan INSN. Return TRUE if the rescanning produced any changes. */
  875. bool
  876. df_insn_rescan (rtx_insn *insn)
  877. {
  878. unsigned int uid = INSN_UID (insn);
  879. struct df_insn_info *insn_info = NULL;
  880. basic_block bb = BLOCK_FOR_INSN (insn);
  881. struct df_collection_rec collection_rec;
  882. if ((!df) || (!INSN_P (insn)))
  883. return false;
  884. if (!bb)
  885. {
  886. if (dump_file)
  887. fprintf (dump_file, "no bb for insn with uid = %d.\n", uid);
  888. return false;
  889. }
  890. /* The client has disabled rescanning and plans to do it itself. */
  891. if (df->changeable_flags & DF_NO_INSN_RESCAN)
  892. return false;
  893. df_grow_bb_info (df_scan);
  894. df_grow_reg_info ();
  895. insn_info = DF_INSN_UID_SAFE_GET (uid);
  896. /* The client has deferred rescanning. */
  897. if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
  898. {
  899. if (!insn_info)
  900. {
  901. insn_info = df_insn_create_insn_record (insn);
  902. insn_info->defs = 0;
  903. insn_info->uses = 0;
  904. insn_info->eq_uses = 0;
  905. insn_info->mw_hardregs = 0;
  906. }
  907. if (dump_file)
  908. fprintf (dump_file, "deferring rescan insn with uid = %d.\n", uid);
  909. bitmap_clear_bit (&df->insns_to_delete, uid);
  910. bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
  911. bitmap_set_bit (&df->insns_to_rescan, INSN_UID (insn));
  912. return false;
  913. }
  914. bitmap_clear_bit (&df->insns_to_delete, uid);
  915. bitmap_clear_bit (&df->insns_to_rescan, uid);
  916. bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
  917. if (insn_info)
  918. {
  919. int luid;
  920. bool the_same = df_insn_refs_verify (&collection_rec, bb, insn, false);
  921. /* If there's no change, return false. */
  922. if (the_same)
  923. {
  924. df_free_collection_rec (&collection_rec);
  925. if (dump_file)
  926. fprintf (dump_file, "verify found no changes in insn with uid = %d.\n", uid);
  927. return false;
  928. }
  929. if (dump_file)
  930. fprintf (dump_file, "rescanning insn with uid = %d.\n", uid);
  931. /* There's change - we need to delete the existing info.
  932. Since the insn isn't moved, we can salvage its LUID. */
  933. luid = DF_INSN_LUID (insn);
  934. df_insn_info_delete (uid);
  935. df_insn_create_insn_record (insn);
  936. DF_INSN_LUID (insn) = luid;
  937. }
  938. else
  939. {
  940. struct df_insn_info *insn_info = df_insn_create_insn_record (insn);
  941. df_insn_refs_collect (&collection_rec, bb, insn_info);
  942. if (dump_file)
  943. fprintf (dump_file, "scanning new insn with uid = %d.\n", uid);
  944. }
  945. df_refs_add_to_chains (&collection_rec, bb, insn, copy_all);
  946. if (!DEBUG_INSN_P (insn))
  947. df_set_bb_dirty (bb);
  948. return true;
  949. }
  950. /* Same as df_insn_rescan, but don't mark the basic block as
  951. dirty. */
  952. bool
  953. df_insn_rescan_debug_internal (rtx_insn *insn)
  954. {
  955. unsigned int uid = INSN_UID (insn);
  956. struct df_insn_info *insn_info;
  957. gcc_assert (DEBUG_INSN_P (insn)
  958. && VAR_LOC_UNKNOWN_P (INSN_VAR_LOCATION_LOC (insn)));
  959. if (!df)
  960. return false;
  961. insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
  962. if (!insn_info)
  963. return false;
  964. if (dump_file)
  965. fprintf (dump_file, "deleting debug_insn with uid = %d.\n", uid);
  966. bitmap_clear_bit (&df->insns_to_delete, uid);
  967. bitmap_clear_bit (&df->insns_to_rescan, uid);
  968. bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
  969. if (insn_info->defs == 0
  970. && insn_info->uses == 0
  971. && insn_info->eq_uses == 0
  972. && insn_info->mw_hardregs == 0)
  973. return false;
  974. df_mw_hardreg_chain_delete (insn_info->mw_hardregs);
  975. if (df_chain)
  976. {
  977. df_ref_chain_delete_du_chain (insn_info->defs);
  978. df_ref_chain_delete_du_chain (insn_info->uses);
  979. df_ref_chain_delete_du_chain (insn_info->eq_uses);
  980. }
  981. df_ref_chain_delete (insn_info->defs);
  982. df_ref_chain_delete (insn_info->uses);
  983. df_ref_chain_delete (insn_info->eq_uses);
  984. insn_info->defs = 0;
  985. insn_info->uses = 0;
  986. insn_info->eq_uses = 0;
  987. insn_info->mw_hardregs = 0;
  988. return true;
  989. }
  990. /* Rescan all of the insns in the function. Note that the artificial
  991. uses and defs are not touched. This function will destroy def-use
  992. or use-def chains. */
  993. void
  994. df_insn_rescan_all (void)
  995. {
  996. bool no_insn_rescan = false;
  997. bool defer_insn_rescan = false;
  998. basic_block bb;
  999. bitmap_iterator bi;
  1000. unsigned int uid;
  1001. bitmap_head tmp;
  1002. bitmap_initialize (&tmp, &df_bitmap_obstack);
  1003. if (df->changeable_flags & DF_NO_INSN_RESCAN)
  1004. {
  1005. df_clear_flags (DF_NO_INSN_RESCAN);
  1006. no_insn_rescan = true;
  1007. }
  1008. if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
  1009. {
  1010. df_clear_flags (DF_DEFER_INSN_RESCAN);
  1011. defer_insn_rescan = true;
  1012. }
  1013. bitmap_copy (&tmp, &df->insns_to_delete);
  1014. EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
  1015. {
  1016. struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
  1017. if (insn_info)
  1018. df_insn_info_delete (uid);
  1019. }
  1020. bitmap_clear (&tmp);
  1021. bitmap_clear (&df->insns_to_delete);
  1022. bitmap_clear (&df->insns_to_rescan);
  1023. bitmap_clear (&df->insns_to_notes_rescan);
  1024. FOR_EACH_BB_FN (bb, cfun)
  1025. {
  1026. rtx_insn *insn;
  1027. FOR_BB_INSNS (bb, insn)
  1028. {
  1029. df_insn_rescan (insn);
  1030. }
  1031. }
  1032. if (no_insn_rescan)
  1033. df_set_flags (DF_NO_INSN_RESCAN);
  1034. if (defer_insn_rescan)
  1035. df_set_flags (DF_DEFER_INSN_RESCAN);
  1036. }
  1037. /* Process all of the deferred rescans or deletions. */
  1038. void
  1039. df_process_deferred_rescans (void)
  1040. {
  1041. bool no_insn_rescan = false;
  1042. bool defer_insn_rescan = false;
  1043. bitmap_iterator bi;
  1044. unsigned int uid;
  1045. bitmap_head tmp;
  1046. bitmap_initialize (&tmp, &df_bitmap_obstack);
  1047. if (df->changeable_flags & DF_NO_INSN_RESCAN)
  1048. {
  1049. df_clear_flags (DF_NO_INSN_RESCAN);
  1050. no_insn_rescan = true;
  1051. }
  1052. if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
  1053. {
  1054. df_clear_flags (DF_DEFER_INSN_RESCAN);
  1055. defer_insn_rescan = true;
  1056. }
  1057. if (dump_file)
  1058. fprintf (dump_file, "starting the processing of deferred insns\n");
  1059. bitmap_copy (&tmp, &df->insns_to_delete);
  1060. EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
  1061. {
  1062. struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
  1063. if (insn_info)
  1064. df_insn_info_delete (uid);
  1065. }
  1066. bitmap_copy (&tmp, &df->insns_to_rescan);
  1067. EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
  1068. {
  1069. struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
  1070. if (insn_info)
  1071. df_insn_rescan (insn_info->insn);
  1072. }
  1073. bitmap_copy (&tmp, &df->insns_to_notes_rescan);
  1074. EXECUTE_IF_SET_IN_BITMAP (&tmp, 0, uid, bi)
  1075. {
  1076. struct df_insn_info *insn_info = DF_INSN_UID_SAFE_GET (uid);
  1077. if (insn_info)
  1078. df_notes_rescan (insn_info->insn);
  1079. }
  1080. if (dump_file)
  1081. fprintf (dump_file, "ending the processing of deferred insns\n");
  1082. bitmap_clear (&tmp);
  1083. bitmap_clear (&df->insns_to_delete);
  1084. bitmap_clear (&df->insns_to_rescan);
  1085. bitmap_clear (&df->insns_to_notes_rescan);
  1086. if (no_insn_rescan)
  1087. df_set_flags (DF_NO_INSN_RESCAN);
  1088. if (defer_insn_rescan)
  1089. df_set_flags (DF_DEFER_INSN_RESCAN);
  1090. /* If someone changed regs_ever_live during this pass, fix up the
  1091. entry and exit blocks. */
  1092. if (df->redo_entry_and_exit)
  1093. {
  1094. df_update_entry_exit_and_calls ();
  1095. df->redo_entry_and_exit = false;
  1096. }
  1097. }
  1098. /* Count the number of refs. Include the defs if INCLUDE_DEFS. Include
  1099. the uses if INCLUDE_USES. Include the eq_uses if
  1100. INCLUDE_EQ_USES. */
  1101. static unsigned int
  1102. df_count_refs (bool include_defs, bool include_uses,
  1103. bool include_eq_uses)
  1104. {
  1105. unsigned int regno;
  1106. int size = 0;
  1107. unsigned int m = df->regs_inited;
  1108. for (regno = 0; regno < m; regno++)
  1109. {
  1110. if (include_defs)
  1111. size += DF_REG_DEF_COUNT (regno);
  1112. if (include_uses)
  1113. size += DF_REG_USE_COUNT (regno);
  1114. if (include_eq_uses)
  1115. size += DF_REG_EQ_USE_COUNT (regno);
  1116. }
  1117. return size;
  1118. }
  1119. /* Take build ref table for either the uses or defs from the reg-use
  1120. or reg-def chains. This version processes the refs in reg order
  1121. which is likely to be best if processing the whole function. */
  1122. static void
  1123. df_reorganize_refs_by_reg_by_reg (struct df_ref_info *ref_info,
  1124. bool include_defs,
  1125. bool include_uses,
  1126. bool include_eq_uses)
  1127. {
  1128. unsigned int m = df->regs_inited;
  1129. unsigned int regno;
  1130. unsigned int offset = 0;
  1131. unsigned int start;
  1132. if (df->changeable_flags & DF_NO_HARD_REGS)
  1133. {
  1134. start = FIRST_PSEUDO_REGISTER;
  1135. memset (ref_info->begin, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
  1136. memset (ref_info->count, 0, sizeof (int) * FIRST_PSEUDO_REGISTER);
  1137. }
  1138. else
  1139. start = 0;
  1140. ref_info->total_size
  1141. = df_count_refs (include_defs, include_uses, include_eq_uses);
  1142. df_check_and_grow_ref_info (ref_info, 1);
  1143. for (regno = start; regno < m; regno++)
  1144. {
  1145. int count = 0;
  1146. ref_info->begin[regno] = offset;
  1147. if (include_defs)
  1148. {
  1149. df_ref ref = DF_REG_DEF_CHAIN (regno);
  1150. while (ref)
  1151. {
  1152. ref_info->refs[offset] = ref;
  1153. DF_REF_ID (ref) = offset++;
  1154. count++;
  1155. ref = DF_REF_NEXT_REG (ref);
  1156. gcc_checking_assert (offset < ref_info->refs_size);
  1157. }
  1158. }
  1159. if (include_uses)
  1160. {
  1161. df_ref ref = DF_REG_USE_CHAIN (regno);
  1162. while (ref)
  1163. {
  1164. ref_info->refs[offset] = ref;
  1165. DF_REF_ID (ref) = offset++;
  1166. count++;
  1167. ref = DF_REF_NEXT_REG (ref);
  1168. gcc_checking_assert (offset < ref_info->refs_size);
  1169. }
  1170. }
  1171. if (include_eq_uses)
  1172. {
  1173. df_ref ref = DF_REG_EQ_USE_CHAIN (regno);
  1174. while (ref)
  1175. {
  1176. ref_info->refs[offset] = ref;
  1177. DF_REF_ID (ref) = offset++;
  1178. count++;
  1179. ref = DF_REF_NEXT_REG (ref);
  1180. gcc_checking_assert (offset < ref_info->refs_size);
  1181. }
  1182. }
  1183. ref_info->count[regno] = count;
  1184. }
  1185. /* The bitmap size is not decremented when refs are deleted. So
  1186. reset it now that we have squished out all of the empty
  1187. slots. */
  1188. ref_info->table_size = offset;
  1189. }
  1190. /* Take build ref table for either the uses or defs from the reg-use
  1191. or reg-def chains. This version processes the refs in insn order
  1192. which is likely to be best if processing some segment of the
  1193. function. */
  1194. static void
  1195. df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
  1196. bool include_defs,
  1197. bool include_uses,
  1198. bool include_eq_uses)
  1199. {
  1200. bitmap_iterator bi;
  1201. unsigned int bb_index;
  1202. unsigned int m = df->regs_inited;
  1203. unsigned int offset = 0;
  1204. unsigned int r;
  1205. unsigned int start
  1206. = (df->changeable_flags & DF_NO_HARD_REGS) ? FIRST_PSEUDO_REGISTER : 0;
  1207. memset (ref_info->begin, 0, sizeof (int) * df->regs_inited);
  1208. memset (ref_info->count, 0, sizeof (int) * df->regs_inited);
  1209. ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
  1210. df_check_and_grow_ref_info (ref_info, 1);
  1211. EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
  1212. {
  1213. basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
  1214. rtx_insn *insn;
  1215. df_ref def, use;
  1216. if (include_defs)
  1217. FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
  1218. {
  1219. unsigned int regno = DF_REF_REGNO (def);
  1220. ref_info->count[regno]++;
  1221. }
  1222. if (include_uses)
  1223. FOR_EACH_ARTIFICIAL_USE (use, bb_index)
  1224. {
  1225. unsigned int regno = DF_REF_REGNO (use);
  1226. ref_info->count[regno]++;
  1227. }
  1228. FOR_BB_INSNS (bb, insn)
  1229. {
  1230. if (INSN_P (insn))
  1231. {
  1232. struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
  1233. if (include_defs)
  1234. FOR_EACH_INSN_INFO_DEF (def, insn_info)
  1235. {
  1236. unsigned int regno = DF_REF_REGNO (def);
  1237. ref_info->count[regno]++;
  1238. }
  1239. if (include_uses)
  1240. FOR_EACH_INSN_INFO_USE (use, insn_info)
  1241. {
  1242. unsigned int regno = DF_REF_REGNO (use);
  1243. ref_info->count[regno]++;
  1244. }
  1245. if (include_eq_uses)
  1246. FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
  1247. {
  1248. unsigned int regno = DF_REF_REGNO (use);
  1249. ref_info->count[regno]++;
  1250. }
  1251. }
  1252. }
  1253. }
  1254. for (r = start; r < m; r++)
  1255. {
  1256. ref_info->begin[r] = offset;
  1257. offset += ref_info->count[r];
  1258. ref_info->count[r] = 0;
  1259. }
  1260. EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
  1261. {
  1262. basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
  1263. rtx_insn *insn;
  1264. df_ref def, use;
  1265. if (include_defs)
  1266. FOR_EACH_ARTIFICIAL_DEF (def, bb_index)
  1267. {
  1268. unsigned int regno = DF_REF_REGNO (def);
  1269. if (regno >= start)
  1270. {
  1271. unsigned int id
  1272. = ref_info->begin[regno] + ref_info->count[regno]++;
  1273. DF_REF_ID (def) = id;
  1274. ref_info->refs[id] = def;
  1275. }
  1276. }
  1277. if (include_uses)
  1278. FOR_EACH_ARTIFICIAL_USE (use, bb_index)
  1279. {
  1280. unsigned int regno = DF_REF_REGNO (def);
  1281. if (regno >= start)
  1282. {
  1283. unsigned int id
  1284. = ref_info->begin[regno] + ref_info->count[regno]++;
  1285. DF_REF_ID (use) = id;
  1286. ref_info->refs[id] = use;
  1287. }
  1288. }
  1289. FOR_BB_INSNS (bb, insn)
  1290. {
  1291. if (INSN_P (insn))
  1292. {
  1293. struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
  1294. if (include_defs)
  1295. FOR_EACH_INSN_INFO_DEF (def, insn_info)
  1296. {
  1297. unsigned int regno = DF_REF_REGNO (def);
  1298. if (regno >= start)
  1299. {
  1300. unsigned int id
  1301. = ref_info->begin[regno] + ref_info->count[regno]++;
  1302. DF_REF_ID (def) = id;
  1303. ref_info->refs[id] = def;
  1304. }
  1305. }
  1306. if (include_uses)
  1307. FOR_EACH_INSN_INFO_USE (use, insn_info)
  1308. {
  1309. unsigned int regno = DF_REF_REGNO (use);
  1310. if (regno >= start)
  1311. {
  1312. unsigned int id
  1313. = ref_info->begin[regno] + ref_info->count[regno]++;
  1314. DF_REF_ID (use) = id;
  1315. ref_info->refs[id] = use;
  1316. }
  1317. }
  1318. if (include_eq_uses)
  1319. FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
  1320. {
  1321. unsigned int regno = DF_REF_REGNO (use);
  1322. if (regno >= start)
  1323. {
  1324. unsigned int id
  1325. = ref_info->begin[regno] + ref_info->count[regno]++;
  1326. DF_REF_ID (use) = id;
  1327. ref_info->refs[id] = use;
  1328. }
  1329. }
  1330. }
  1331. }
  1332. }
  1333. /* The bitmap size is not decremented when refs are deleted. So
  1334. reset it now that we have squished out all of the empty
  1335. slots. */
  1336. ref_info->table_size = offset;
  1337. }
  1338. /* Take build ref table for either the uses or defs from the reg-use
  1339. or reg-def chains. */
  1340. static void
  1341. df_reorganize_refs_by_reg (struct df_ref_info *ref_info,
  1342. bool include_defs,
  1343. bool include_uses,
  1344. bool include_eq_uses)
  1345. {
  1346. if (df->analyze_subset)
  1347. df_reorganize_refs_by_reg_by_insn (ref_info, include_defs,
  1348. include_uses, include_eq_uses);
  1349. else
  1350. df_reorganize_refs_by_reg_by_reg (ref_info, include_defs,
  1351. include_uses, include_eq_uses);
  1352. }
  1353. /* Add the refs in REF_VEC to the table in REF_INFO starting at OFFSET. */
  1354. static unsigned int
  1355. df_add_refs_to_table (unsigned int offset,
  1356. struct df_ref_info *ref_info,
  1357. df_ref ref)
  1358. {
  1359. for (; ref; ref = DF_REF_NEXT_LOC (ref))
  1360. if (!(df->changeable_flags & DF_NO_HARD_REGS)
  1361. || (DF_REF_REGNO (ref) >= FIRST_PSEUDO_REGISTER))
  1362. {
  1363. ref_info->refs[offset] = ref;
  1364. DF_REF_ID (ref) = offset++;
  1365. }
  1366. return offset;
  1367. }
  1368. /* Count the number of refs in all of the insns of BB. Include the
  1369. defs if INCLUDE_DEFS. Include the uses if INCLUDE_USES. Include the
  1370. eq_uses if INCLUDE_EQ_USES. */
  1371. static unsigned int
  1372. df_reorganize_refs_by_insn_bb (basic_block bb, unsigned int offset,
  1373. struct df_ref_info *ref_info,
  1374. bool include_defs, bool include_uses,
  1375. bool include_eq_uses)
  1376. {
  1377. rtx_insn *insn;
  1378. if (include_defs)
  1379. offset = df_add_refs_to_table (offset, ref_info,
  1380. df_get_artificial_defs (bb->index));
  1381. if (include_uses)
  1382. offset = df_add_refs_to_table (offset, ref_info,
  1383. df_get_artificial_uses (bb->index));
  1384. FOR_BB_INSNS (bb, insn)
  1385. if (INSN_P (insn))
  1386. {
  1387. unsigned int uid = INSN_UID (insn);
  1388. if (include_defs)
  1389. offset = df_add_refs_to_table (offset, ref_info,
  1390. DF_INSN_UID_DEFS (uid));
  1391. if (include_uses)
  1392. offset = df_add_refs_to_table (offset, ref_info,
  1393. DF_INSN_UID_USES (uid));
  1394. if (include_eq_uses)
  1395. offset = df_add_refs_to_table (offset, ref_info,
  1396. DF_INSN_UID_EQ_USES (uid));
  1397. }
  1398. return offset;
  1399. }
  1400. /* Organize the refs by insn into the table in REF_INFO. If
  1401. blocks_to_analyze is defined, use that set, otherwise the entire
  1402. program. Include the defs if INCLUDE_DEFS. Include the uses if
  1403. INCLUDE_USES. Include the eq_uses if INCLUDE_EQ_USES. */
  1404. static void
  1405. df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
  1406. bool include_defs, bool include_uses,
  1407. bool include_eq_uses)
  1408. {
  1409. basic_block bb;
  1410. unsigned int offset = 0;
  1411. ref_info->total_size = df_count_refs (include_defs, include_uses, include_eq_uses);
  1412. df_check_and_grow_ref_info (ref_info, 1);
  1413. if (df->blocks_to_analyze)
  1414. {
  1415. bitmap_iterator bi;
  1416. unsigned int index;
  1417. EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
  1418. {
  1419. offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun,
  1420. index),
  1421. offset, ref_info,
  1422. include_defs, include_uses,
  1423. include_eq_uses);
  1424. }
  1425. ref_info->table_size = offset;
  1426. }
  1427. else
  1428. {
  1429. FOR_ALL_BB_FN (bb, cfun)
  1430. offset = df_reorganize_refs_by_insn_bb (bb, offset, ref_info,
  1431. include_defs, include_uses,
  1432. include_eq_uses);
  1433. ref_info->table_size = offset;
  1434. }
  1435. }
  1436. /* If the use refs in DF are not organized, reorganize them. */
  1437. void
  1438. df_maybe_reorganize_use_refs (enum df_ref_order order)
  1439. {
  1440. if (order == df->use_info.ref_order)
  1441. return;
  1442. switch (order)
  1443. {
  1444. case DF_REF_ORDER_BY_REG:
  1445. df_reorganize_refs_by_reg (&df->use_info, false, true, false);
  1446. break;
  1447. case DF_REF_ORDER_BY_REG_WITH_NOTES:
  1448. df_reorganize_refs_by_reg (&df->use_info, false, true, true);
  1449. break;
  1450. case DF_REF_ORDER_BY_INSN:
  1451. df_reorganize_refs_by_insn (&df->use_info, false, true, false);
  1452. break;
  1453. case DF_REF_ORDER_BY_INSN_WITH_NOTES:
  1454. df_reorganize_refs_by_insn (&df->use_info, false, true, true);
  1455. break;
  1456. case DF_REF_ORDER_NO_TABLE:
  1457. free (df->use_info.refs);
  1458. df->use_info.refs = NULL;
  1459. df->use_info.refs_size = 0;
  1460. break;
  1461. case DF_REF_ORDER_UNORDERED:
  1462. case DF_REF_ORDER_UNORDERED_WITH_NOTES:
  1463. gcc_unreachable ();
  1464. break;
  1465. }
  1466. df->use_info.ref_order = order;
  1467. }
  1468. /* If the def refs in DF are not organized, reorganize them. */
  1469. void
  1470. df_maybe_reorganize_def_refs (enum df_ref_order order)
  1471. {
  1472. if (order == df->def_info.ref_order)
  1473. return;
  1474. switch (order)
  1475. {
  1476. case DF_REF_ORDER_BY_REG:
  1477. df_reorganize_refs_by_reg (&df->def_info, true, false, false);
  1478. break;
  1479. case DF_REF_ORDER_BY_INSN:
  1480. df_reorganize_refs_by_insn (&df->def_info, true, false, false);
  1481. break;
  1482. case DF_REF_ORDER_NO_TABLE:
  1483. free (df->def_info.refs);
  1484. df->def_info.refs = NULL;
  1485. df->def_info.refs_size = 0;
  1486. break;
  1487. case DF_REF_ORDER_BY_INSN_WITH_NOTES:
  1488. case DF_REF_ORDER_BY_REG_WITH_NOTES:
  1489. case DF_REF_ORDER_UNORDERED:
  1490. case DF_REF_ORDER_UNORDERED_WITH_NOTES:
  1491. gcc_unreachable ();
  1492. break;
  1493. }
  1494. df->def_info.ref_order = order;
  1495. }
  1496. /* Change all of the basic block references in INSN to use the insn's
  1497. current basic block. This function is called from routines that move
  1498. instructions from one block to another. */
  1499. void
  1500. df_insn_change_bb (rtx_insn *insn, basic_block new_bb)
  1501. {
  1502. basic_block old_bb = BLOCK_FOR_INSN (insn);
  1503. struct df_insn_info *insn_info;
  1504. unsigned int uid = INSN_UID (insn);
  1505. if (old_bb == new_bb)
  1506. return;
  1507. set_block_for_insn (insn, new_bb);
  1508. if (!df)
  1509. return;
  1510. if (dump_file)
  1511. fprintf (dump_file, "changing bb of uid %d\n", uid);
  1512. insn_info = DF_INSN_UID_SAFE_GET (uid);
  1513. if (insn_info == NULL)
  1514. {
  1515. if (dump_file)
  1516. fprintf (dump_file, " unscanned insn\n");
  1517. df_insn_rescan (insn);
  1518. return;
  1519. }
  1520. if (!INSN_P (insn))
  1521. return;
  1522. df_set_bb_dirty (new_bb);
  1523. if (old_bb)
  1524. {
  1525. if (dump_file)
  1526. fprintf (dump_file, " from %d to %d\n",
  1527. old_bb->index, new_bb->index);
  1528. df_set_bb_dirty (old_bb);
  1529. }
  1530. else
  1531. if (dump_file)
  1532. fprintf (dump_file, " to %d\n", new_bb->index);
  1533. }
  1534. /* Helper function for df_ref_change_reg_with_loc. */
  1535. static void
  1536. df_ref_change_reg_with_loc_1 (struct df_reg_info *old_df,
  1537. struct df_reg_info *new_df,
  1538. int new_regno, rtx loc)
  1539. {
  1540. df_ref the_ref = old_df->reg_chain;
  1541. while (the_ref)
  1542. {
  1543. if ((!DF_REF_IS_ARTIFICIAL (the_ref))
  1544. && DF_REF_LOC (the_ref)
  1545. && (*DF_REF_LOC (the_ref) == loc))
  1546. {
  1547. df_ref next_ref = DF_REF_NEXT_REG (the_ref);
  1548. df_ref prev_ref = DF_REF_PREV_REG (the_ref);
  1549. df_ref *ref_ptr;
  1550. struct df_insn_info *insn_info = DF_REF_INSN_INFO (the_ref);
  1551. DF_REF_REGNO (the_ref) = new_regno;
  1552. DF_REF_REG (the_ref) = regno_reg_rtx[new_regno];
  1553. /* Pull the_ref out of the old regno chain. */
  1554. if (prev_ref)
  1555. DF_REF_NEXT_REG (prev_ref) = next_ref;
  1556. else
  1557. old_df->reg_chain = next_ref;
  1558. if (next_ref)
  1559. DF_REF_PREV_REG (next_ref) = prev_ref;
  1560. old_df->n_refs--;
  1561. /* Put the ref into the new regno chain. */
  1562. DF_REF_PREV_REG (the_ref) = NULL;
  1563. DF_REF_NEXT_REG (the_ref) = new_df->reg_chain;
  1564. if (new_df->reg_chain)
  1565. DF_REF_PREV_REG (new_df->reg_chain) = the_ref;
  1566. new_df->reg_chain = the_ref;
  1567. new_df->n_refs++;
  1568. if (DF_REF_BB (the_ref))
  1569. df_set_bb_dirty (DF_REF_BB (the_ref));
  1570. /* Need to sort the record again that the ref was in because
  1571. the regno is a sorting key. First, find the right
  1572. record. */
  1573. if (DF_REF_REG_DEF_P (the_ref))
  1574. ref_ptr = &insn_info->defs;
  1575. else if (DF_REF_FLAGS (the_ref) & DF_REF_IN_NOTE)
  1576. ref_ptr = &insn_info->eq_uses;
  1577. else
  1578. ref_ptr = &insn_info->uses;
  1579. if (dump_file)
  1580. fprintf (dump_file, "changing reg in insn %d\n",
  1581. DF_REF_INSN_UID (the_ref));
  1582. /* Stop if we find the current reference or where the reference
  1583. needs to be. */
  1584. while (*ref_ptr != the_ref && df_ref_compare (*ref_ptr, the_ref) < 0)
  1585. ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
  1586. if (*ref_ptr != the_ref)
  1587. {
  1588. /* The reference needs to be promoted up the list. */
  1589. df_ref next = DF_REF_NEXT_LOC (the_ref);
  1590. DF_REF_NEXT_LOC (the_ref) = *ref_ptr;
  1591. *ref_ptr = the_ref;
  1592. do
  1593. ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
  1594. while (*ref_ptr != the_ref);
  1595. *ref_ptr = next;
  1596. }
  1597. else if (DF_REF_NEXT_LOC (the_ref)
  1598. && df_ref_compare (the_ref, DF_REF_NEXT_LOC (the_ref)) > 0)
  1599. {
  1600. /* The reference needs to be demoted down the list. */
  1601. *ref_ptr = DF_REF_NEXT_LOC (the_ref);
  1602. do
  1603. ref_ptr = &DF_REF_NEXT_LOC (*ref_ptr);
  1604. while (*ref_ptr && df_ref_compare (the_ref, *ref_ptr) > 0);
  1605. DF_REF_NEXT_LOC (the_ref) = *ref_ptr;
  1606. *ref_ptr = the_ref;
  1607. }
  1608. the_ref = next_ref;
  1609. }
  1610. else
  1611. the_ref = DF_REF_NEXT_REG (the_ref);
  1612. }
  1613. }
  1614. /* Change the regno of all refs that contained LOC from OLD_REGNO to
  1615. NEW_REGNO. Refs that do not match LOC are not changed which means
  1616. that artificial refs are not changed since they have no loc. This
  1617. call is to support the SET_REGNO macro. */
  1618. void
  1619. df_ref_change_reg_with_loc (int old_regno, int new_regno, rtx loc)
  1620. {
  1621. if ((!df) || (old_regno == -1) || (old_regno == new_regno))
  1622. return;
  1623. df_grow_reg_info ();
  1624. df_ref_change_reg_with_loc_1 (DF_REG_DEF_GET (old_regno),
  1625. DF_REG_DEF_GET (new_regno), new_regno, loc);
  1626. df_ref_change_reg_with_loc_1 (DF_REG_USE_GET (old_regno),
  1627. DF_REG_USE_GET (new_regno), new_regno, loc);
  1628. df_ref_change_reg_with_loc_1 (DF_REG_EQ_USE_GET (old_regno),
  1629. DF_REG_EQ_USE_GET (new_regno), new_regno, loc);
  1630. }
  1631. /* Delete the mw_hardregs that point into the eq_notes. */
  1632. static void
  1633. df_mw_hardreg_chain_delete_eq_uses (struct df_insn_info *insn_info)
  1634. {
  1635. struct df_mw_hardreg **mw_ptr = &insn_info->mw_hardregs;
  1636. struct df_scan_problem_data *problem_data
  1637. = (struct df_scan_problem_data *) df_scan->problem_data;
  1638. while (*mw_ptr)
  1639. {
  1640. df_mw_hardreg *mw = *mw_ptr;
  1641. if (mw->flags & DF_REF_IN_NOTE)
  1642. {
  1643. *mw_ptr = DF_MWS_NEXT (mw);
  1644. pool_free (problem_data->mw_reg_pool, mw);
  1645. }
  1646. else
  1647. mw_ptr = &DF_MWS_NEXT (mw);
  1648. }
  1649. }
  1650. /* Rescan only the REG_EQUIV/REG_EQUAL notes part of INSN. */
  1651. void
  1652. df_notes_rescan (rtx_insn *insn)
  1653. {
  1654. struct df_insn_info *insn_info;
  1655. unsigned int uid = INSN_UID (insn);
  1656. if (!df)
  1657. return;
  1658. /* The client has disabled rescanning and plans to do it itself. */
  1659. if (df->changeable_flags & DF_NO_INSN_RESCAN)
  1660. return;
  1661. /* Do nothing if the insn hasn't been emitted yet. */
  1662. if (!BLOCK_FOR_INSN (insn))
  1663. return;
  1664. df_grow_bb_info (df_scan);
  1665. df_grow_reg_info ();
  1666. insn_info = DF_INSN_UID_SAFE_GET (INSN_UID (insn));
  1667. /* The client has deferred rescanning. */
  1668. if (df->changeable_flags & DF_DEFER_INSN_RESCAN)
  1669. {
  1670. if (!insn_info)
  1671. {
  1672. insn_info = df_insn_create_insn_record (insn);
  1673. insn_info->defs = 0;
  1674. insn_info->uses = 0;
  1675. insn_info->eq_uses = 0;
  1676. insn_info->mw_hardregs = 0;
  1677. }
  1678. bitmap_clear_bit (&df->insns_to_delete, uid);
  1679. /* If the insn is set to be rescanned, it does not need to also
  1680. be notes rescanned. */
  1681. if (!bitmap_bit_p (&df->insns_to_rescan, uid))
  1682. bitmap_set_bit (&df->insns_to_notes_rescan, INSN_UID (insn));
  1683. return;
  1684. }
  1685. bitmap_clear_bit (&df->insns_to_delete, uid);
  1686. bitmap_clear_bit (&df->insns_to_notes_rescan, uid);
  1687. if (insn_info)
  1688. {
  1689. basic_block bb = BLOCK_FOR_INSN (insn);
  1690. rtx note;
  1691. struct df_collection_rec collection_rec;
  1692. unsigned int i;
  1693. df_mw_hardreg_chain_delete_eq_uses (insn_info);
  1694. df_ref_chain_delete (insn_info->eq_uses);
  1695. insn_info->eq_uses = NULL;
  1696. /* Process REG_EQUIV/REG_EQUAL notes */
  1697. for (note = REG_NOTES (insn); note;
  1698. note = XEXP (note, 1))
  1699. {
  1700. switch (REG_NOTE_KIND (note))
  1701. {
  1702. case REG_EQUIV:
  1703. case REG_EQUAL:
  1704. df_uses_record (&collection_rec,
  1705. &XEXP (note, 0), DF_REF_REG_USE,
  1706. bb, insn_info, DF_REF_IN_NOTE);
  1707. default:
  1708. break;
  1709. }
  1710. }
  1711. /* Find some place to put any new mw_hardregs. */
  1712. df_canonize_collection_rec (&collection_rec);
  1713. struct df_mw_hardreg **mw_ptr = &insn_info->mw_hardregs, *mw;
  1714. FOR_EACH_VEC_ELT (collection_rec.mw_vec, i, mw)
  1715. {
  1716. while (*mw_ptr && df_mw_compare (*mw_ptr, mw) < 0)
  1717. mw_ptr = &DF_MWS_NEXT (*mw_ptr);
  1718. DF_MWS_NEXT (mw) = *mw_ptr;
  1719. *mw_ptr = mw;
  1720. mw_ptr = &DF_MWS_NEXT (mw);
  1721. }
  1722. df_refs_add_to_chains (&collection_rec, bb, insn, copy_eq_uses);
  1723. }
  1724. else
  1725. df_insn_rescan (insn);
  1726. }
  1727. /*----------------------------------------------------------------------------
  1728. Hard core instruction scanning code. No external interfaces here,
  1729. just a lot of routines that look inside insns.
  1730. ----------------------------------------------------------------------------*/
  1731. /* Return true if the contents of two df_ref's are identical.
  1732. It ignores DF_REF_MARKER. */
  1733. static bool
  1734. df_ref_equal_p (df_ref ref1, df_ref ref2)
  1735. {
  1736. if (!ref2)
  1737. return false;
  1738. if (ref1 == ref2)
  1739. return true;
  1740. if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2)
  1741. || DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2)
  1742. || DF_REF_REG (ref1) != DF_REF_REG (ref2)
  1743. || DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2)
  1744. || ((DF_REF_FLAGS (ref1) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG))
  1745. != (DF_REF_FLAGS (ref2) & ~(DF_REF_REG_MARKER + DF_REF_MW_HARDREG)))
  1746. || DF_REF_BB (ref1) != DF_REF_BB (ref2)
  1747. || DF_REF_INSN_INFO (ref1) != DF_REF_INSN_INFO (ref2))
  1748. return false;
  1749. switch (DF_REF_CLASS (ref1))
  1750. {
  1751. case DF_REF_ARTIFICIAL:
  1752. case DF_REF_BASE:
  1753. return true;
  1754. case DF_REF_REGULAR:
  1755. return DF_REF_LOC (ref1) == DF_REF_LOC (ref2);
  1756. default:
  1757. gcc_unreachable ();
  1758. }
  1759. return false;
  1760. }
  1761. /* Compare REF1 and REF2 for sorting. This is only called from places
  1762. where all of the refs are of the same type, in the same insn, and
  1763. have the same bb. So these fields are not checked. */
  1764. static int
  1765. df_ref_compare (df_ref ref1, df_ref ref2)
  1766. {
  1767. if (DF_REF_CLASS (ref1) != DF_REF_CLASS (ref2))
  1768. return (int)DF_REF_CLASS (ref1) - (int)DF_REF_CLASS (ref2);
  1769. if (DF_REF_REGNO (ref1) != DF_REF_REGNO (ref2))
  1770. return (int)DF_REF_REGNO (ref1) - (int)DF_REF_REGNO (ref2);
  1771. if (DF_REF_TYPE (ref1) != DF_REF_TYPE (ref2))
  1772. return (int)DF_REF_TYPE (ref1) - (int)DF_REF_TYPE (ref2);
  1773. if (DF_REF_REG (ref1) != DF_REF_REG (ref2))
  1774. return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
  1775. /* Cannot look at the LOC field on artificial refs. */
  1776. if (DF_REF_CLASS (ref1) != DF_REF_ARTIFICIAL
  1777. && DF_REF_LOC (ref1) != DF_REF_LOC (ref2))
  1778. return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
  1779. if (DF_REF_FLAGS (ref1) != DF_REF_FLAGS (ref2))
  1780. {
  1781. /* If two refs are identical except that one of them has is from
  1782. a mw and one is not, we need to have the one with the mw
  1783. first. */
  1784. if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG) ==
  1785. DF_REF_FLAGS_IS_SET (ref2, DF_REF_MW_HARDREG))
  1786. return DF_REF_FLAGS (ref1) - DF_REF_FLAGS (ref2);
  1787. else if (DF_REF_FLAGS_IS_SET (ref1, DF_REF_MW_HARDREG))
  1788. return -1;
  1789. else
  1790. return 1;
  1791. }
  1792. return (int)DF_REF_ORDER (ref1) - (int)DF_REF_ORDER (ref2);
  1793. }
  1794. /* Like df_ref_compare, but compare two df_ref* pointers R1 and R2. */
  1795. static int
  1796. df_ref_ptr_compare (const void *r1, const void *r2)
  1797. {
  1798. return df_ref_compare (*(const df_ref *) r1, *(const df_ref *) r2);
  1799. }
  1800. static void
  1801. df_swap_refs (vec<df_ref, va_heap> *ref_vec, int i, int j)
  1802. {
  1803. df_ref tmp = (*ref_vec)[i];
  1804. (*ref_vec)[i] = (*ref_vec)[j];
  1805. (*ref_vec)[j] = tmp;
  1806. }
  1807. /* Sort and compress a set of refs. */
  1808. static void
  1809. df_sort_and_compress_refs (vec<df_ref, va_heap> *ref_vec)
  1810. {
  1811. unsigned int count;
  1812. unsigned int i;
  1813. unsigned int dist = 0;
  1814. count = ref_vec->length ();
  1815. /* If there are 1 or 0 elements, there is nothing to do. */
  1816. if (count < 2)
  1817. return;
  1818. else if (count == 2)
  1819. {
  1820. df_ref r0 = (*ref_vec)[0];
  1821. df_ref r1 = (*ref_vec)[1];
  1822. if (df_ref_compare (r0, r1) > 0)
  1823. df_swap_refs (ref_vec, 0, 1);
  1824. }
  1825. else
  1826. {
  1827. for (i = 0; i < count - 1; i++)
  1828. {
  1829. df_ref r0 = (*ref_vec)[i];
  1830. df_ref r1 = (*ref_vec)[i + 1];
  1831. if (df_ref_compare (r0, r1) >= 0)
  1832. break;
  1833. }
  1834. /* If the array is already strictly ordered,
  1835. which is the most common case for large COUNT case
  1836. (which happens for CALL INSNs),
  1837. no need to sort and filter out duplicate.
  1838. Simply return the count.
  1839. Make sure DF_GET_ADD_REFS adds refs in the increasing order
  1840. of DF_REF_COMPARE. */
  1841. if (i == count - 1)
  1842. return;
  1843. ref_vec->qsort (df_ref_ptr_compare);
  1844. }
  1845. for (i=0; i<count-dist; i++)
  1846. {
  1847. /* Find the next ref that is not equal to the current ref. */
  1848. while (i + dist + 1 < count
  1849. && df_ref_equal_p ((*ref_vec)[i],
  1850. (*ref_vec)[i + dist + 1]))
  1851. {
  1852. df_free_ref ((*ref_vec)[i + dist + 1]);
  1853. dist++;
  1854. }
  1855. /* Copy it down to the next position. */
  1856. if (dist && i + dist + 1 < count)
  1857. (*ref_vec)[i + 1] = (*ref_vec)[i + dist + 1];
  1858. }
  1859. count -= dist;
  1860. ref_vec->truncate (count);
  1861. }
  1862. /* Return true if the contents of two df_ref's are identical.
  1863. It ignores DF_REF_MARKER. */
  1864. static bool
  1865. df_mw_equal_p (struct df_mw_hardreg *mw1, struct df_mw_hardreg *mw2)
  1866. {
  1867. if (!mw2)
  1868. return false;
  1869. return (mw1 == mw2) ||
  1870. (mw1->mw_reg == mw2->mw_reg
  1871. && mw1->type == mw2->type
  1872. && mw1->flags == mw2->flags
  1873. && mw1->start_regno == mw2->start_regno
  1874. && mw1->end_regno == mw2->end_regno);
  1875. }
  1876. /* Compare MW1 and MW2 for sorting. */
  1877. static int
  1878. df_mw_compare (const df_mw_hardreg *mw1, const df_mw_hardreg *mw2)
  1879. {
  1880. if (mw1->type != mw2->type)
  1881. return mw1->type - mw2->type;
  1882. if (mw1->flags != mw2->flags)
  1883. return mw1->flags - mw2->flags;
  1884. if (mw1->start_regno != mw2->start_regno)
  1885. return mw1->start_regno - mw2->start_regno;
  1886. if (mw1->end_regno != mw2->end_regno)
  1887. return mw1->end_regno - mw2->end_regno;
  1888. if (mw1->mw_reg != mw2->mw_reg)
  1889. return mw1->mw_order - mw2->mw_order;
  1890. return 0;
  1891. }
  1892. /* Like df_mw_compare, but compare two df_mw_hardreg** pointers R1 and R2. */
  1893. static int
  1894. df_mw_ptr_compare (const void *m1, const void *m2)
  1895. {
  1896. return df_mw_compare (*(const df_mw_hardreg *const *) m1,
  1897. *(const df_mw_hardreg *const *) m2);
  1898. }
  1899. /* Sort and compress a set of refs. */
  1900. static void
  1901. df_sort_and_compress_mws (vec<df_mw_hardreg_ptr, va_heap> *mw_vec)
  1902. {
  1903. unsigned int count;
  1904. struct df_scan_problem_data *problem_data
  1905. = (struct df_scan_problem_data *) df_scan->problem_data;
  1906. unsigned int i;
  1907. unsigned int dist = 0;
  1908. count = mw_vec->length ();
  1909. if (count < 2)
  1910. return;
  1911. else if (count == 2)
  1912. {
  1913. struct df_mw_hardreg *m0 = (*mw_vec)[0];
  1914. struct df_mw_hardreg *m1 = (*mw_vec)[1];
  1915. if (df_mw_compare (m0, m1) > 0)
  1916. {
  1917. struct df_mw_hardreg *tmp = (*mw_vec)[0];
  1918. (*mw_vec)[0] = (*mw_vec)[1];
  1919. (*mw_vec)[1] = tmp;
  1920. }
  1921. }
  1922. else
  1923. mw_vec->qsort (df_mw_ptr_compare);
  1924. for (i=0; i<count-dist; i++)
  1925. {
  1926. /* Find the next ref that is not equal to the current ref. */
  1927. while (i + dist + 1 < count
  1928. && df_mw_equal_p ((*mw_vec)[i], (*mw_vec)[i + dist + 1]))
  1929. {
  1930. pool_free (problem_data->mw_reg_pool,
  1931. (*mw_vec)[i + dist + 1]);
  1932. dist++;
  1933. }
  1934. /* Copy it down to the next position. */
  1935. if (dist && i + dist + 1 < count)
  1936. (*mw_vec)[i + 1] = (*mw_vec)[i + dist + 1];
  1937. }
  1938. count -= dist;
  1939. mw_vec->truncate (count);
  1940. }
  1941. /* Sort and remove duplicates from the COLLECTION_REC. */
  1942. static void
  1943. df_canonize_collection_rec (struct df_collection_rec *collection_rec)
  1944. {
  1945. df_sort_and_compress_refs (&collection_rec->def_vec);
  1946. df_sort_and_compress_refs (&collection_rec->use_vec);
  1947. df_sort_and_compress_refs (&collection_rec->eq_use_vec);
  1948. df_sort_and_compress_mws (&collection_rec->mw_vec);
  1949. }
  1950. /* Add the new df_ref to appropriate reg_info/ref_info chains. */
  1951. static void
  1952. df_install_ref (df_ref this_ref,
  1953. struct df_reg_info *reg_info,
  1954. struct df_ref_info *ref_info,
  1955. bool add_to_table)
  1956. {
  1957. unsigned int regno = DF_REF_REGNO (this_ref);
  1958. /* Add the ref to the reg_{def,use,eq_use} chain. */
  1959. df_ref head = reg_info->reg_chain;
  1960. reg_info->reg_chain = this_ref;
  1961. reg_info->n_refs++;
  1962. if (DF_REF_FLAGS_IS_SET (this_ref, DF_HARD_REG_LIVE))
  1963. {
  1964. gcc_assert (regno < FIRST_PSEUDO_REGISTER);
  1965. df->hard_regs_live_count[regno]++;
  1966. }
  1967. gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL
  1968. && DF_REF_PREV_REG (this_ref) == NULL);
  1969. DF_REF_NEXT_REG (this_ref) = head;
  1970. /* We cannot actually link to the head of the chain. */
  1971. DF_REF_PREV_REG (this_ref) = NULL;
  1972. if (head)
  1973. DF_REF_PREV_REG (head) = this_ref;
  1974. if (add_to_table)
  1975. {
  1976. gcc_assert (ref_info->ref_order != DF_REF_ORDER_NO_TABLE);
  1977. df_check_and_grow_ref_info (ref_info, 1);
  1978. DF_REF_ID (this_ref) = ref_info->table_size;
  1979. /* Add the ref to the big array of defs. */
  1980. ref_info->refs[ref_info->table_size] = this_ref;
  1981. ref_info->table_size++;
  1982. }
  1983. else
  1984. DF_REF_ID (this_ref) = -1;
  1985. ref_info->total_size++;
  1986. }
  1987. /* This function takes one of the groups of refs (defs, uses or
  1988. eq_uses) and installs the entire group into the insn. It also adds
  1989. each of these refs into the appropriate chains. */
  1990. static df_ref
  1991. df_install_refs (basic_block bb,
  1992. const vec<df_ref, va_heap> *old_vec,
  1993. struct df_reg_info **reg_info,
  1994. struct df_ref_info *ref_info,
  1995. bool is_notes)
  1996. {
  1997. unsigned int count = old_vec->length ();
  1998. if (count)
  1999. {
  2000. bool add_to_table;
  2001. df_ref this_ref;
  2002. unsigned int ix;
  2003. switch (ref_info->ref_order)
  2004. {
  2005. case DF_REF_ORDER_UNORDERED_WITH_NOTES:
  2006. case DF_REF_ORDER_BY_REG_WITH_NOTES:
  2007. case DF_REF_ORDER_BY_INSN_WITH_NOTES:
  2008. ref_info->ref_order = DF_REF_ORDER_UNORDERED_WITH_NOTES;
  2009. add_to_table = true;
  2010. break;
  2011. case DF_REF_ORDER_UNORDERED:
  2012. case DF_REF_ORDER_BY_REG:
  2013. case DF_REF_ORDER_BY_INSN:
  2014. ref_info->ref_order = DF_REF_ORDER_UNORDERED;
  2015. add_to_table = !is_notes;
  2016. break;
  2017. default:
  2018. add_to_table = false;
  2019. break;
  2020. }
  2021. /* Do not add if ref is not in the right blocks. */
  2022. if (add_to_table && df->analyze_subset)
  2023. add_to_table = bitmap_bit_p (df->blocks_to_analyze, bb->index);
  2024. FOR_EACH_VEC_ELT (*old_vec, ix, this_ref)
  2025. {
  2026. DF_REF_NEXT_LOC (this_ref) = (ix + 1 < old_vec->length ()
  2027. ? (*old_vec)[ix + 1]
  2028. : NULL);
  2029. df_install_ref (this_ref, reg_info[DF_REF_REGNO (this_ref)],
  2030. ref_info, add_to_table);
  2031. }
  2032. return (*old_vec)[0];
  2033. }
  2034. else
  2035. return 0;
  2036. }
  2037. /* This function takes the mws installs the entire group into the
  2038. insn. */
  2039. static struct df_mw_hardreg *
  2040. df_install_mws (const vec<df_mw_hardreg_ptr, va_heap> *old_vec)
  2041. {
  2042. unsigned int count = old_vec->length ();
  2043. if (count)
  2044. {
  2045. for (unsigned int i = 0; i < count - 1; i++)
  2046. DF_MWS_NEXT ((*old_vec)[i]) = (*old_vec)[i + 1];
  2047. DF_MWS_NEXT ((*old_vec)[count - 1]) = 0;
  2048. return (*old_vec)[0];
  2049. }
  2050. else
  2051. return 0;
  2052. }
  2053. /* Add a chain of df_refs to appropriate ref chain/reg_info/ref_info
  2054. chains and update other necessary information. */
  2055. static void
  2056. df_refs_add_to_chains (struct df_collection_rec *collection_rec,
  2057. basic_block bb, rtx_insn *insn, unsigned int flags)
  2058. {
  2059. if (insn)
  2060. {
  2061. struct df_insn_info *insn_rec = DF_INSN_INFO_GET (insn);
  2062. /* If there is a vector in the collection rec, add it to the
  2063. insn. A null rec is a signal that the caller will handle the
  2064. chain specially. */
  2065. if (flags & copy_defs)
  2066. {
  2067. gcc_checking_assert (!insn_rec->defs);
  2068. insn_rec->defs
  2069. = df_install_refs (bb, &collection_rec->def_vec,
  2070. df->def_regs,
  2071. &df->def_info, false);
  2072. }
  2073. if (flags & copy_uses)
  2074. {
  2075. gcc_checking_assert (!insn_rec->uses);
  2076. insn_rec->uses
  2077. = df_install_refs (bb, &collection_rec->use_vec,
  2078. df->use_regs,
  2079. &df->use_info, false);
  2080. }
  2081. if (flags & copy_eq_uses)
  2082. {
  2083. gcc_checking_assert (!insn_rec->eq_uses);
  2084. insn_rec->eq_uses
  2085. = df_install_refs (bb, &collection_rec->eq_use_vec,
  2086. df->eq_use_regs,
  2087. &df->use_info, true);
  2088. }
  2089. if (flags & copy_mw)
  2090. {
  2091. gcc_checking_assert (!insn_rec->mw_hardregs);
  2092. insn_rec->mw_hardregs
  2093. = df_install_mws (&collection_rec->mw_vec);
  2094. }
  2095. }
  2096. else
  2097. {
  2098. struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
  2099. gcc_checking_assert (!bb_info->artificial_defs);
  2100. bb_info->artificial_defs
  2101. = df_install_refs (bb, &collection_rec->def_vec,
  2102. df->def_regs,
  2103. &df->def_info, false);
  2104. gcc_checking_assert (!bb_info->artificial_uses);
  2105. bb_info->artificial_uses
  2106. = df_install_refs (bb, &collection_rec->use_vec,
  2107. df->use_regs,
  2108. &df->use_info, false);
  2109. }
  2110. }
  2111. /* Allocate a ref and initialize its fields. */
  2112. static df_ref
  2113. df_ref_create_structure (enum df_ref_class cl,
  2114. struct df_collection_rec *collection_rec,
  2115. rtx reg, rtx *loc,
  2116. basic_block bb, struct df_insn_info *info,
  2117. enum df_ref_type ref_type,
  2118. int ref_flags)
  2119. {
  2120. df_ref this_ref = NULL;
  2121. int regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
  2122. struct df_scan_problem_data *problem_data
  2123. = (struct df_scan_problem_data *) df_scan->problem_data;
  2124. switch (cl)
  2125. {
  2126. case DF_REF_BASE:
  2127. this_ref = (df_ref) pool_alloc (problem_data->ref_base_pool);
  2128. gcc_checking_assert (loc == NULL);
  2129. break;
  2130. case DF_REF_ARTIFICIAL:
  2131. this_ref = (df_ref) pool_alloc (problem_data->ref_artificial_pool);
  2132. this_ref->artificial_ref.bb = bb;
  2133. gcc_checking_assert (loc == NULL);
  2134. break;
  2135. case DF_REF_REGULAR:
  2136. this_ref = (df_ref) pool_alloc (problem_data->ref_regular_pool);
  2137. this_ref->regular_ref.loc = loc;
  2138. gcc_checking_assert (loc);
  2139. break;
  2140. }
  2141. DF_REF_CLASS (this_ref) = cl;
  2142. DF_REF_ID (this_ref) = -1;
  2143. DF_REF_REG (this_ref) = reg;
  2144. DF_REF_REGNO (this_ref) = regno;
  2145. DF_REF_TYPE (this_ref) = ref_type;
  2146. DF_REF_INSN_INFO (this_ref) = info;
  2147. DF_REF_CHAIN (this_ref) = NULL;
  2148. DF_REF_FLAGS (this_ref) = ref_flags;
  2149. DF_REF_NEXT_REG (this_ref) = NULL;
  2150. DF_REF_PREV_REG (this_ref) = NULL;
  2151. DF_REF_ORDER (this_ref) = df->ref_order++;
  2152. /* We need to clear this bit because fwprop, and in the future
  2153. possibly other optimizations sometimes create new refs using ond
  2154. refs as the model. */
  2155. DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE);
  2156. /* See if this ref needs to have DF_HARD_REG_LIVE bit set. */
  2157. if (regno < FIRST_PSEUDO_REGISTER
  2158. && !DF_REF_IS_ARTIFICIAL (this_ref)
  2159. && !DEBUG_INSN_P (DF_REF_INSN (this_ref)))
  2160. {
  2161. if (DF_REF_REG_DEF_P (this_ref))
  2162. {
  2163. if (!DF_REF_FLAGS_IS_SET (this_ref, DF_REF_MAY_CLOBBER))
  2164. DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
  2165. }
  2166. else if (!(TEST_HARD_REG_BIT (elim_reg_set, regno)
  2167. && (regno == FRAME_POINTER_REGNUM
  2168. || regno == ARG_POINTER_REGNUM)))
  2169. DF_REF_FLAGS_SET (this_ref, DF_HARD_REG_LIVE);
  2170. }
  2171. if (collection_rec)
  2172. {
  2173. if (DF_REF_REG_DEF_P (this_ref))
  2174. collection_rec->def_vec.safe_push (this_ref);
  2175. else if (DF_REF_FLAGS (this_ref) & DF_REF_IN_NOTE)
  2176. collection_rec->eq_use_vec.safe_push (this_ref);
  2177. else
  2178. collection_rec->use_vec.safe_push (this_ref);
  2179. }
  2180. else
  2181. df_install_ref_incremental (this_ref);
  2182. return this_ref;
  2183. }
  2184. /* Create new references of type DF_REF_TYPE for each part of register REG
  2185. at address LOC within INSN of BB. */
  2186. static void
  2187. df_ref_record (enum df_ref_class cl,
  2188. struct df_collection_rec *collection_rec,
  2189. rtx reg, rtx *loc,
  2190. basic_block bb, struct df_insn_info *insn_info,
  2191. enum df_ref_type ref_type,
  2192. int ref_flags)
  2193. {
  2194. unsigned int regno;
  2195. gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
  2196. regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
  2197. if (regno < FIRST_PSEUDO_REGISTER)
  2198. {
  2199. struct df_mw_hardreg *hardreg = NULL;
  2200. struct df_scan_problem_data *problem_data
  2201. = (struct df_scan_problem_data *) df_scan->problem_data;
  2202. unsigned int i;
  2203. unsigned int endregno;
  2204. df_ref ref;
  2205. if (GET_CODE (reg) == SUBREG)
  2206. {
  2207. regno += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
  2208. SUBREG_BYTE (reg), GET_MODE (reg));
  2209. endregno = regno + subreg_nregs (reg);
  2210. }
  2211. else
  2212. endregno = END_HARD_REGNO (reg);
  2213. /* If this is a multiword hardreg, we create some extra
  2214. datastructures that will enable us to easily build REG_DEAD
  2215. and REG_UNUSED notes. */
  2216. if (collection_rec
  2217. && (endregno != regno + 1) && insn_info)
  2218. {
  2219. /* Sets to a subreg of a multiword register are partial.
  2220. Sets to a non-subreg of a multiword register are not. */
  2221. if (GET_CODE (reg) == SUBREG)
  2222. ref_flags |= DF_REF_PARTIAL;
  2223. ref_flags |= DF_REF_MW_HARDREG;
  2224. hardreg = (struct df_mw_hardreg *) pool_alloc (problem_data->mw_reg_pool);
  2225. hardreg->type = ref_type;
  2226. hardreg->flags = ref_flags;
  2227. hardreg->mw_reg = reg;
  2228. hardreg->start_regno = regno;
  2229. hardreg->end_regno = endregno - 1;
  2230. hardreg->mw_order = df->ref_order++;
  2231. collection_rec->mw_vec.safe_push (hardreg);
  2232. }
  2233. for (i = regno; i < endregno; i++)
  2234. {
  2235. ref = df_ref_create_structure (cl, collection_rec, regno_reg_rtx[i], loc,
  2236. bb, insn_info, ref_type, ref_flags);
  2237. gcc_assert (ORIGINAL_REGNO (DF_REF_REG (ref)) == i);
  2238. }
  2239. }
  2240. else
  2241. {
  2242. df_ref_create_structure (cl, collection_rec, reg, loc, bb, insn_info,
  2243. ref_type, ref_flags);
  2244. }
  2245. }
  2246. /* A set to a non-paradoxical SUBREG for which the number of word_mode units
  2247. covered by the outer mode is smaller than that covered by the inner mode,
  2248. is a read-modify-write operation.
  2249. This function returns true iff the SUBREG X is such a SUBREG. */
  2250. bool
  2251. df_read_modify_subreg_p (rtx x)
  2252. {
  2253. unsigned int isize, osize;
  2254. if (GET_CODE (x) != SUBREG)
  2255. return false;
  2256. isize = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)));
  2257. osize = GET_MODE_SIZE (GET_MODE (x));
  2258. return isize > osize
  2259. && isize > REGMODE_NATURAL_SIZE (GET_MODE (SUBREG_REG (x)));
  2260. }
  2261. /* Process all the registers defined in the rtx pointed by LOC.
  2262. Autoincrement/decrement definitions will be picked up by df_uses_record.
  2263. Any change here has to be matched in df_find_hard_reg_defs_1. */
  2264. static void
  2265. df_def_record_1 (struct df_collection_rec *collection_rec,
  2266. rtx *loc, basic_block bb, struct df_insn_info *insn_info,
  2267. int flags)
  2268. {
  2269. rtx dst = *loc;
  2270. /* It is legal to have a set destination be a parallel. */
  2271. if (GET_CODE (dst) == PARALLEL)
  2272. {
  2273. int i;
  2274. for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
  2275. {
  2276. rtx temp = XVECEXP (dst, 0, i);
  2277. gcc_assert (GET_CODE (temp) == EXPR_LIST);
  2278. df_def_record_1 (collection_rec, &XEXP (temp, 0),
  2279. bb, insn_info, flags);
  2280. }
  2281. return;
  2282. }
  2283. if (GET_CODE (dst) == STRICT_LOW_PART)
  2284. {
  2285. flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_STRICT_LOW_PART;
  2286. loc = &XEXP (dst, 0);
  2287. dst = *loc;
  2288. }
  2289. if (GET_CODE (dst) == ZERO_EXTRACT)
  2290. {
  2291. flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL | DF_REF_ZERO_EXTRACT;
  2292. loc = &XEXP (dst, 0);
  2293. dst = *loc;
  2294. }
  2295. /* At this point if we do not have a reg or a subreg, just return. */
  2296. if (REG_P (dst))
  2297. {
  2298. df_ref_record (DF_REF_REGULAR, collection_rec,
  2299. dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
  2300. /* We want to keep sp alive everywhere - by making all
  2301. writes to sp also use of sp. */
  2302. if (REGNO (dst) == STACK_POINTER_REGNUM)
  2303. df_ref_record (DF_REF_BASE, collection_rec,
  2304. dst, NULL, bb, insn_info, DF_REF_REG_USE, flags);
  2305. }
  2306. else if (GET_CODE (dst) == SUBREG && REG_P (SUBREG_REG (dst)))
  2307. {
  2308. if (df_read_modify_subreg_p (dst))
  2309. flags |= DF_REF_READ_WRITE | DF_REF_PARTIAL;
  2310. flags |= DF_REF_SUBREG;
  2311. df_ref_record (DF_REF_REGULAR, collection_rec,
  2312. dst, loc, bb, insn_info, DF_REF_REG_DEF, flags);
  2313. }
  2314. }
  2315. /* Process all the registers defined in the pattern rtx, X. Any change
  2316. here has to be matched in df_find_hard_reg_defs. */
  2317. static void
  2318. df_defs_record (struct df_collection_rec *collection_rec,
  2319. rtx x, basic_block bb, struct df_insn_info *insn_info,
  2320. int flags)
  2321. {
  2322. RTX_CODE code = GET_CODE (x);
  2323. int i;
  2324. switch (code)
  2325. {
  2326. case SET:
  2327. df_def_record_1 (collection_rec, &SET_DEST (x), bb, insn_info, flags);
  2328. break;
  2329. case CLOBBER:
  2330. flags |= DF_REF_MUST_CLOBBER;
  2331. df_def_record_1 (collection_rec, &XEXP (x, 0), bb, insn_info, flags);
  2332. break;
  2333. case COND_EXEC:
  2334. df_defs_record (collection_rec, COND_EXEC_CODE (x),
  2335. bb, insn_info, DF_REF_CONDITIONAL);
  2336. break;
  2337. case PARALLEL:
  2338. for (i = 0; i < XVECLEN (x, 0); i++)
  2339. df_defs_record (collection_rec, XVECEXP (x, 0, i),
  2340. bb, insn_info, flags);
  2341. break;
  2342. default:
  2343. /* No DEFs to record in other cases */
  2344. break;
  2345. }
  2346. }
  2347. /* Set bits in *DEFS for hard registers found in the rtx DST, which is the
  2348. destination of a set or clobber. This has to match the logic in
  2349. df_defs_record_1. */
  2350. static void
  2351. df_find_hard_reg_defs_1 (rtx dst, HARD_REG_SET *defs)
  2352. {
  2353. /* It is legal to have a set destination be a parallel. */
  2354. if (GET_CODE (dst) == PARALLEL)
  2355. {
  2356. int i;
  2357. for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
  2358. {
  2359. rtx temp = XVECEXP (dst, 0, i);
  2360. gcc_assert (GET_CODE (temp) == EXPR_LIST);
  2361. df_find_hard_reg_defs_1 (XEXP (temp, 0), defs);
  2362. }
  2363. return;
  2364. }
  2365. if (GET_CODE (dst) == STRICT_LOW_PART)
  2366. dst = XEXP (dst, 0);
  2367. if (GET_CODE (dst) == ZERO_EXTRACT)
  2368. dst = XEXP (dst, 0);
  2369. /* At this point if we do not have a reg or a subreg, just return. */
  2370. if (REG_P (dst) && HARD_REGISTER_P (dst))
  2371. SET_HARD_REG_BIT (*defs, REGNO (dst));
  2372. else if (GET_CODE (dst) == SUBREG
  2373. && REG_P (SUBREG_REG (dst)) && HARD_REGISTER_P (dst))
  2374. SET_HARD_REG_BIT (*defs, REGNO (SUBREG_REG (dst)));
  2375. }
  2376. /* Set bits in *DEFS for hard registers defined in the pattern X. This
  2377. has to match the logic in df_defs_record. */
  2378. static void
  2379. df_find_hard_reg_defs (rtx x, HARD_REG_SET *defs)
  2380. {
  2381. RTX_CODE code = GET_CODE (x);
  2382. int i;
  2383. switch (code)
  2384. {
  2385. case SET:
  2386. df_find_hard_reg_defs_1 (SET_DEST (x), defs);
  2387. break;
  2388. case CLOBBER:
  2389. df_find_hard_reg_defs_1 (XEXP (x, 0), defs);
  2390. break;
  2391. case COND_EXEC:
  2392. df_find_hard_reg_defs (COND_EXEC_CODE (x), defs);
  2393. break;
  2394. case PARALLEL:
  2395. for (i = 0; i < XVECLEN (x, 0); i++)
  2396. df_find_hard_reg_defs (XVECEXP (x, 0, i), defs);
  2397. break;
  2398. default:
  2399. /* No DEFs to record in other cases */
  2400. break;
  2401. }
  2402. }
  2403. /* Process all the registers used in the rtx at address LOC. */
  2404. static void
  2405. df_uses_record (struct df_collection_rec *collection_rec,
  2406. rtx *loc, enum df_ref_type ref_type,
  2407. basic_block bb, struct df_insn_info *insn_info,
  2408. int flags)
  2409. {
  2410. RTX_CODE code;
  2411. rtx x;
  2412. retry:
  2413. x = *loc;
  2414. if (!x)
  2415. return;
  2416. code = GET_CODE (x);
  2417. switch (code)
  2418. {
  2419. case LABEL_REF:
  2420. case SYMBOL_REF:
  2421. case CONST:
  2422. CASE_CONST_ANY:
  2423. case PC:
  2424. case CC0:
  2425. case ADDR_VEC:
  2426. case ADDR_DIFF_VEC:
  2427. return;
  2428. case CLOBBER:
  2429. /* If we are clobbering a MEM, mark any registers inside the address
  2430. as being used. */
  2431. if (MEM_P (XEXP (x, 0)))
  2432. df_uses_record (collection_rec,
  2433. &XEXP (XEXP (x, 0), 0),
  2434. DF_REF_REG_MEM_STORE,
  2435. bb, insn_info,
  2436. flags);
  2437. /* If we're clobbering a REG then we have a def so ignore. */
  2438. return;
  2439. case MEM:
  2440. df_uses_record (collection_rec,
  2441. &XEXP (x, 0), DF_REF_REG_MEM_LOAD,
  2442. bb, insn_info, flags & DF_REF_IN_NOTE);
  2443. return;
  2444. case SUBREG:
  2445. /* While we're here, optimize this case. */
  2446. flags |= DF_REF_PARTIAL;
  2447. /* In case the SUBREG is not of a REG, do not optimize. */
  2448. if (!REG_P (SUBREG_REG (x)))
  2449. {
  2450. loc = &SUBREG_REG (x);
  2451. df_uses_record (collection_rec, loc, ref_type, bb, insn_info, flags);
  2452. return;
  2453. }
  2454. /* ... Fall through ... */
  2455. case REG:
  2456. df_ref_record (DF_REF_REGULAR, collection_rec,
  2457. x, loc, bb, insn_info,
  2458. ref_type, flags);
  2459. return;
  2460. case SIGN_EXTRACT:
  2461. case ZERO_EXTRACT:
  2462. {
  2463. df_uses_record (collection_rec,
  2464. &XEXP (x, 1), ref_type, bb, insn_info, flags);
  2465. df_uses_record (collection_rec,
  2466. &XEXP (x, 2), ref_type, bb, insn_info, flags);
  2467. /* If the parameters to the zero or sign extract are
  2468. constants, strip them off and recurse, otherwise there is
  2469. no information that we can gain from this operation. */
  2470. if (code == ZERO_EXTRACT)
  2471. flags |= DF_REF_ZERO_EXTRACT;
  2472. else
  2473. flags |= DF_REF_SIGN_EXTRACT;
  2474. df_uses_record (collection_rec,
  2475. &XEXP (x, 0), ref_type, bb, insn_info, flags);
  2476. return;
  2477. }
  2478. break;
  2479. case SET:
  2480. {
  2481. rtx dst = SET_DEST (x);
  2482. gcc_assert (!(flags & DF_REF_IN_NOTE));
  2483. df_uses_record (collection_rec,
  2484. &SET_SRC (x), DF_REF_REG_USE, bb, insn_info, flags);
  2485. switch (GET_CODE (dst))
  2486. {
  2487. case SUBREG:
  2488. if (df_read_modify_subreg_p (dst))
  2489. {
  2490. df_uses_record (collection_rec, &SUBREG_REG (dst),
  2491. DF_REF_REG_USE, bb, insn_info,
  2492. flags | DF_REF_READ_WRITE | DF_REF_SUBREG);
  2493. break;
  2494. }
  2495. /* Fall through. */
  2496. case REG:
  2497. case PARALLEL:
  2498. case SCRATCH:
  2499. case PC:
  2500. case CC0:
  2501. break;
  2502. case MEM:
  2503. df_uses_record (collection_rec, &XEXP (dst, 0),
  2504. DF_REF_REG_MEM_STORE, bb, insn_info, flags);
  2505. break;
  2506. case STRICT_LOW_PART:
  2507. {
  2508. rtx *temp = &XEXP (dst, 0);
  2509. /* A strict_low_part uses the whole REG and not just the
  2510. SUBREG. */
  2511. dst = XEXP (dst, 0);
  2512. df_uses_record (collection_rec,
  2513. (GET_CODE (dst) == SUBREG) ? &SUBREG_REG (dst) : temp,
  2514. DF_REF_REG_USE, bb, insn_info,
  2515. DF_REF_READ_WRITE | DF_REF_STRICT_LOW_PART);
  2516. }
  2517. break;
  2518. case ZERO_EXTRACT:
  2519. {
  2520. df_uses_record (collection_rec, &XEXP (dst, 1),
  2521. DF_REF_REG_USE, bb, insn_info, flags);
  2522. df_uses_record (collection_rec, &XEXP (dst, 2),
  2523. DF_REF_REG_USE, bb, insn_info, flags);
  2524. if (GET_CODE (XEXP (dst,0)) == MEM)
  2525. df_uses_record (collection_rec, &XEXP (dst, 0),
  2526. DF_REF_REG_USE, bb, insn_info,
  2527. flags);
  2528. else
  2529. df_uses_record (collection_rec, &XEXP (dst, 0),
  2530. DF_REF_REG_USE, bb, insn_info,
  2531. DF_REF_READ_WRITE | DF_REF_ZERO_EXTRACT);
  2532. }
  2533. break;
  2534. default:
  2535. gcc_unreachable ();
  2536. }
  2537. return;
  2538. }
  2539. case RETURN:
  2540. case SIMPLE_RETURN:
  2541. break;
  2542. case ASM_OPERANDS:
  2543. case UNSPEC_VOLATILE:
  2544. case TRAP_IF:
  2545. case ASM_INPUT:
  2546. {
  2547. /* Traditional and volatile asm instructions must be
  2548. considered to use and clobber all hard registers, all
  2549. pseudo-registers and all of memory. So must TRAP_IF and
  2550. UNSPEC_VOLATILE operations.
  2551. Consider for instance a volatile asm that changes the fpu
  2552. rounding mode. An insn should not be moved across this
  2553. even if it only uses pseudo-regs because it might give an
  2554. incorrectly rounded result.
  2555. However, flow.c's liveness computation did *not* do this,
  2556. giving the reasoning as " ?!? Unfortunately, marking all
  2557. hard registers as live causes massive problems for the
  2558. register allocator and marking all pseudos as live creates
  2559. mountains of uninitialized variable warnings."
  2560. In order to maintain the status quo with regard to liveness
  2561. and uses, we do what flow.c did and just mark any regs we
  2562. can find in ASM_OPERANDS as used. In global asm insns are
  2563. scanned and regs_asm_clobbered is filled out.
  2564. For all ASM_OPERANDS, we must traverse the vector of input
  2565. operands. We can not just fall through here since then we
  2566. would be confused by the ASM_INPUT rtx inside ASM_OPERANDS,
  2567. which do not indicate traditional asms unlike their normal
  2568. usage. */
  2569. if (code == ASM_OPERANDS)
  2570. {
  2571. int j;
  2572. for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
  2573. df_uses_record (collection_rec, &ASM_OPERANDS_INPUT (x, j),
  2574. DF_REF_REG_USE, bb, insn_info, flags);
  2575. return;
  2576. }
  2577. break;
  2578. }
  2579. case VAR_LOCATION:
  2580. df_uses_record (collection_rec,
  2581. &PAT_VAR_LOCATION_LOC (x),
  2582. DF_REF_REG_USE, bb, insn_info, flags);
  2583. return;
  2584. case PRE_DEC:
  2585. case POST_DEC:
  2586. case PRE_INC:
  2587. case POST_INC:
  2588. case PRE_MODIFY:
  2589. case POST_MODIFY:
  2590. gcc_assert (!DEBUG_INSN_P (insn_info->insn));
  2591. /* Catch the def of the register being modified. */
  2592. df_ref_record (DF_REF_REGULAR, collection_rec, XEXP (x, 0), &XEXP (x, 0),
  2593. bb, insn_info,
  2594. DF_REF_REG_DEF,
  2595. flags | DF_REF_READ_WRITE | DF_REF_PRE_POST_MODIFY);
  2596. /* ... Fall through to handle uses ... */
  2597. default:
  2598. break;
  2599. }
  2600. /* Recursively scan the operands of this expression. */
  2601. {
  2602. const char *fmt = GET_RTX_FORMAT (code);
  2603. int i;
  2604. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2605. {
  2606. if (fmt[i] == 'e')
  2607. {
  2608. /* Tail recursive case: save a function call level. */
  2609. if (i == 0)
  2610. {
  2611. loc = &XEXP (x, 0);
  2612. goto retry;
  2613. }
  2614. df_uses_record (collection_rec, &XEXP (x, i), ref_type,
  2615. bb, insn_info, flags);
  2616. }
  2617. else if (fmt[i] == 'E')
  2618. {
  2619. int j;
  2620. for (j = 0; j < XVECLEN (x, i); j++)
  2621. df_uses_record (collection_rec,
  2622. &XVECEXP (x, i, j), ref_type,
  2623. bb, insn_info, flags);
  2624. }
  2625. }
  2626. }
  2627. return;
  2628. }
  2629. /* For all DF_REF_CONDITIONAL defs, add a corresponding uses. */
  2630. static void
  2631. df_get_conditional_uses (struct df_collection_rec *collection_rec)
  2632. {
  2633. unsigned int ix;
  2634. df_ref ref;
  2635. FOR_EACH_VEC_ELT (collection_rec->def_vec, ix, ref)
  2636. {
  2637. if (DF_REF_FLAGS_IS_SET (ref, DF_REF_CONDITIONAL))
  2638. {
  2639. df_ref use;
  2640. use = df_ref_create_structure (DF_REF_CLASS (ref), collection_rec, DF_REF_REG (ref),
  2641. DF_REF_LOC (ref), DF_REF_BB (ref),
  2642. DF_REF_INSN_INFO (ref), DF_REF_REG_USE,
  2643. DF_REF_FLAGS (ref) & ~DF_REF_CONDITIONAL);
  2644. DF_REF_REGNO (use) = DF_REF_REGNO (ref);
  2645. }
  2646. }
  2647. }
  2648. /* Get call's extra defs and uses (track caller-saved registers). */
  2649. static void
  2650. df_get_call_refs (struct df_collection_rec *collection_rec,
  2651. basic_block bb,
  2652. struct df_insn_info *insn_info,
  2653. int flags)
  2654. {
  2655. rtx note;
  2656. bool is_sibling_call;
  2657. unsigned int i;
  2658. HARD_REG_SET defs_generated;
  2659. HARD_REG_SET fn_reg_set_usage;
  2660. CLEAR_HARD_REG_SET (defs_generated);
  2661. df_find_hard_reg_defs (PATTERN (insn_info->insn), &defs_generated);
  2662. is_sibling_call = SIBLING_CALL_P (insn_info->insn);
  2663. get_call_reg_set_usage (insn_info->insn, &fn_reg_set_usage,
  2664. regs_invalidated_by_call);
  2665. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2666. {
  2667. if (i == STACK_POINTER_REGNUM)
  2668. /* The stack ptr is used (honorarily) by a CALL insn. */
  2669. df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
  2670. NULL, bb, insn_info, DF_REF_REG_USE,
  2671. DF_REF_CALL_STACK_USAGE | flags);
  2672. else if (global_regs[i])
  2673. {
  2674. /* Calls to const functions cannot access any global registers and
  2675. calls to pure functions cannot set them. All other calls may
  2676. reference any of the global registers, so they are recorded as
  2677. used. */
  2678. if (!RTL_CONST_CALL_P (insn_info->insn))
  2679. {
  2680. df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
  2681. NULL, bb, insn_info, DF_REF_REG_USE, flags);
  2682. if (!RTL_PURE_CALL_P (insn_info->insn))
  2683. df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
  2684. NULL, bb, insn_info, DF_REF_REG_DEF, flags);
  2685. }
  2686. }
  2687. else if (TEST_HARD_REG_BIT (fn_reg_set_usage, i)
  2688. /* no clobbers for regs that are the result of the call */
  2689. && !TEST_HARD_REG_BIT (defs_generated, i)
  2690. && (!is_sibling_call
  2691. || !bitmap_bit_p (df->exit_block_uses, i)
  2692. || refers_to_regno_p (i, crtl->return_rtx)))
  2693. df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
  2694. NULL, bb, insn_info, DF_REF_REG_DEF,
  2695. DF_REF_MAY_CLOBBER | flags);
  2696. }
  2697. /* Record the registers used to pass arguments, and explicitly
  2698. noted as clobbered. */
  2699. for (note = CALL_INSN_FUNCTION_USAGE (insn_info->insn); note;
  2700. note = XEXP (note, 1))
  2701. {
  2702. if (GET_CODE (XEXP (note, 0)) == USE)
  2703. df_uses_record (collection_rec, &XEXP (XEXP (note, 0), 0),
  2704. DF_REF_REG_USE, bb, insn_info, flags);
  2705. else if (GET_CODE (XEXP (note, 0)) == CLOBBER)
  2706. {
  2707. if (REG_P (XEXP (XEXP (note, 0), 0)))
  2708. {
  2709. unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
  2710. if (!TEST_HARD_REG_BIT (defs_generated, regno))
  2711. df_defs_record (collection_rec, XEXP (note, 0), bb,
  2712. insn_info, flags);
  2713. }
  2714. else
  2715. df_uses_record (collection_rec, &XEXP (note, 0),
  2716. DF_REF_REG_USE, bb, insn_info, flags);
  2717. }
  2718. }
  2719. return;
  2720. }
  2721. /* Collect all refs in the INSN. This function is free of any
  2722. side-effect - it will create and return a lists of df_ref's in the
  2723. COLLECTION_REC without putting those refs into existing ref chains
  2724. and reg chains. */
  2725. static void
  2726. df_insn_refs_collect (struct df_collection_rec *collection_rec,
  2727. basic_block bb, struct df_insn_info *insn_info)
  2728. {
  2729. rtx note;
  2730. bool is_cond_exec = (GET_CODE (PATTERN (insn_info->insn)) == COND_EXEC);
  2731. /* Clear out the collection record. */
  2732. collection_rec->def_vec.truncate (0);
  2733. collection_rec->use_vec.truncate (0);
  2734. collection_rec->eq_use_vec.truncate (0);
  2735. collection_rec->mw_vec.truncate (0);
  2736. /* Process REG_EQUIV/REG_EQUAL notes. */
  2737. for (note = REG_NOTES (insn_info->insn); note;
  2738. note = XEXP (note, 1))
  2739. {
  2740. switch (REG_NOTE_KIND (note))
  2741. {
  2742. case REG_EQUIV:
  2743. case REG_EQUAL:
  2744. df_uses_record (collection_rec,
  2745. &XEXP (note, 0), DF_REF_REG_USE,
  2746. bb, insn_info, DF_REF_IN_NOTE);
  2747. break;
  2748. case REG_NON_LOCAL_GOTO:
  2749. /* The frame ptr is used by a non-local goto. */
  2750. df_ref_record (DF_REF_BASE, collection_rec,
  2751. regno_reg_rtx[FRAME_POINTER_REGNUM],
  2752. NULL, bb, insn_info,
  2753. DF_REF_REG_USE, 0);
  2754. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  2755. df_ref_record (DF_REF_BASE, collection_rec,
  2756. regno_reg_rtx[HARD_FRAME_POINTER_REGNUM],
  2757. NULL, bb, insn_info,
  2758. DF_REF_REG_USE, 0);
  2759. #endif
  2760. break;
  2761. default:
  2762. break;
  2763. }
  2764. }
  2765. /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
  2766. uses from CALL_INSN_FUNCTION_USAGE. */
  2767. if (CALL_P (insn_info->insn))
  2768. df_get_call_refs (collection_rec, bb, insn_info,
  2769. (is_cond_exec) ? DF_REF_CONDITIONAL : 0);
  2770. /* Record other defs. These should be mostly for DF_REF_REGULAR, so
  2771. that a qsort on the defs is unnecessary in most cases. */
  2772. df_defs_record (collection_rec,
  2773. PATTERN (insn_info->insn), bb, insn_info, 0);
  2774. /* Record the register uses. */
  2775. df_uses_record (collection_rec,
  2776. &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0);
  2777. /* DF_REF_CONDITIONAL needs corresponding USES. */
  2778. if (is_cond_exec)
  2779. df_get_conditional_uses (collection_rec);
  2780. df_canonize_collection_rec (collection_rec);
  2781. }
  2782. /* Recompute the luids for the insns in BB. */
  2783. void
  2784. df_recompute_luids (basic_block bb)
  2785. {
  2786. rtx_insn *insn;
  2787. int luid = 0;
  2788. df_grow_insn_info ();
  2789. /* Scan the block an insn at a time from beginning to end. */
  2790. FOR_BB_INSNS (bb, insn)
  2791. {
  2792. struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
  2793. /* Inserting labels does not always trigger the incremental
  2794. rescanning. */
  2795. if (!insn_info)
  2796. {
  2797. gcc_assert (!INSN_P (insn));
  2798. insn_info = df_insn_create_insn_record (insn);
  2799. }
  2800. DF_INSN_INFO_LUID (insn_info) = luid;
  2801. if (INSN_P (insn))
  2802. luid++;
  2803. }
  2804. }
  2805. /* Collect all artificial refs at the block level for BB and add them
  2806. to COLLECTION_REC. */
  2807. static void
  2808. df_bb_refs_collect (struct df_collection_rec *collection_rec, basic_block bb)
  2809. {
  2810. collection_rec->def_vec.truncate (0);
  2811. collection_rec->use_vec.truncate (0);
  2812. collection_rec->eq_use_vec.truncate (0);
  2813. collection_rec->mw_vec.truncate (0);
  2814. if (bb->index == ENTRY_BLOCK)
  2815. {
  2816. df_entry_block_defs_collect (collection_rec, df->entry_block_defs);
  2817. return;
  2818. }
  2819. else if (bb->index == EXIT_BLOCK)
  2820. {
  2821. df_exit_block_uses_collect (collection_rec, df->exit_block_uses);
  2822. return;
  2823. }
  2824. #ifdef EH_RETURN_DATA_REGNO
  2825. if (bb_has_eh_pred (bb))
  2826. {
  2827. unsigned int i;
  2828. /* Mark the registers that will contain data for the handler. */
  2829. for (i = 0; ; ++i)
  2830. {
  2831. unsigned regno = EH_RETURN_DATA_REGNO (i);
  2832. if (regno == INVALID_REGNUM)
  2833. break;
  2834. df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
  2835. bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
  2836. }
  2837. }
  2838. #endif
  2839. /* Add the hard_frame_pointer if this block is the target of a
  2840. non-local goto. */
  2841. if (bb->flags & BB_NON_LOCAL_GOTO_TARGET)
  2842. df_ref_record (DF_REF_ARTIFICIAL, collection_rec, hard_frame_pointer_rtx, NULL,
  2843. bb, NULL, DF_REF_REG_DEF, DF_REF_AT_TOP);
  2844. /* Add the artificial uses. */
  2845. if (bb->index >= NUM_FIXED_BLOCKS)
  2846. {
  2847. bitmap_iterator bi;
  2848. unsigned int regno;
  2849. bitmap au = bb_has_eh_pred (bb)
  2850. ? &df->eh_block_artificial_uses
  2851. : &df->regular_block_artificial_uses;
  2852. EXECUTE_IF_SET_IN_BITMAP (au, 0, regno, bi)
  2853. {
  2854. df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[regno], NULL,
  2855. bb, NULL, DF_REF_REG_USE, 0);
  2856. }
  2857. }
  2858. df_canonize_collection_rec (collection_rec);
  2859. }
  2860. /* Record all the refs within the basic block BB_INDEX and scan the instructions if SCAN_INSNS. */
  2861. void
  2862. df_bb_refs_record (int bb_index, bool scan_insns)
  2863. {
  2864. basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
  2865. rtx_insn *insn;
  2866. int luid = 0;
  2867. if (!df)
  2868. return;
  2869. df_collection_rec collection_rec;
  2870. df_grow_bb_info (df_scan);
  2871. if (scan_insns)
  2872. /* Scan the block an insn at a time from beginning to end. */
  2873. FOR_BB_INSNS (bb, insn)
  2874. {
  2875. struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
  2876. gcc_assert (!insn_info);
  2877. insn_info = df_insn_create_insn_record (insn);
  2878. if (INSN_P (insn))
  2879. {
  2880. /* Record refs within INSN. */
  2881. DF_INSN_INFO_LUID (insn_info) = luid++;
  2882. df_insn_refs_collect (&collection_rec, bb, DF_INSN_INFO_GET (insn));
  2883. df_refs_add_to_chains (&collection_rec, bb, insn, copy_all);
  2884. }
  2885. DF_INSN_INFO_LUID (insn_info) = luid;
  2886. }
  2887. /* Other block level artificial refs */
  2888. df_bb_refs_collect (&collection_rec, bb);
  2889. df_refs_add_to_chains (&collection_rec, bb, NULL, copy_all);
  2890. /* Now that the block has been processed, set the block as dirty so
  2891. LR and LIVE will get it processed. */
  2892. df_set_bb_dirty (bb);
  2893. }
  2894. /* Get the artificial use set for a regular (i.e. non-exit/non-entry)
  2895. block. */
  2896. static void
  2897. df_get_regular_block_artificial_uses (bitmap regular_block_artificial_uses)
  2898. {
  2899. #ifdef EH_USES
  2900. unsigned int i;
  2901. #endif
  2902. bitmap_clear (regular_block_artificial_uses);
  2903. if (reload_completed)
  2904. {
  2905. if (frame_pointer_needed)
  2906. bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
  2907. }
  2908. else
  2909. /* Before reload, there are a few registers that must be forced
  2910. live everywhere -- which might not already be the case for
  2911. blocks within infinite loops. */
  2912. {
  2913. unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
  2914. /* Any reference to any pseudo before reload is a potential
  2915. reference of the frame pointer. */
  2916. bitmap_set_bit (regular_block_artificial_uses, FRAME_POINTER_REGNUM);
  2917. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  2918. bitmap_set_bit (regular_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
  2919. #endif
  2920. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2921. /* Pseudos with argument area equivalences may require
  2922. reloading via the argument pointer. */
  2923. if (fixed_regs[ARG_POINTER_REGNUM])
  2924. bitmap_set_bit (regular_block_artificial_uses, ARG_POINTER_REGNUM);
  2925. #endif
  2926. /* Any constant, or pseudo with constant equivalences, may
  2927. require reloading from memory using the pic register. */
  2928. if (picreg != INVALID_REGNUM
  2929. && fixed_regs[picreg])
  2930. bitmap_set_bit (regular_block_artificial_uses, picreg);
  2931. }
  2932. /* The all-important stack pointer must always be live. */
  2933. bitmap_set_bit (regular_block_artificial_uses, STACK_POINTER_REGNUM);
  2934. #ifdef EH_USES
  2935. /* EH_USES registers are used:
  2936. 1) at all insns that might throw (calls or with -fnon-call-exceptions
  2937. trapping insns)
  2938. 2) in all EH edges
  2939. 3) to support backtraces and/or debugging, anywhere between their
  2940. initialization and where they the saved registers are restored
  2941. from them, including the cases where we don't reach the epilogue
  2942. (noreturn call or infinite loop). */
  2943. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2944. if (EH_USES (i))
  2945. bitmap_set_bit (regular_block_artificial_uses, i);
  2946. #endif
  2947. }
  2948. /* Get the artificial use set for an eh block. */
  2949. static void
  2950. df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses)
  2951. {
  2952. bitmap_clear (eh_block_artificial_uses);
  2953. /* The following code (down through the arg_pointer setting APPEARS
  2954. to be necessary because there is nothing that actually
  2955. describes what the exception handling code may actually need
  2956. to keep alive. */
  2957. if (reload_completed)
  2958. {
  2959. if (frame_pointer_needed)
  2960. {
  2961. bitmap_set_bit (eh_block_artificial_uses, FRAME_POINTER_REGNUM);
  2962. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  2963. bitmap_set_bit (eh_block_artificial_uses, HARD_FRAME_POINTER_REGNUM);
  2964. #endif
  2965. }
  2966. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2967. if (fixed_regs[ARG_POINTER_REGNUM])
  2968. bitmap_set_bit (eh_block_artificial_uses, ARG_POINTER_REGNUM);
  2969. #endif
  2970. }
  2971. }
  2972. /*----------------------------------------------------------------------------
  2973. Specialized hard register scanning functions.
  2974. ----------------------------------------------------------------------------*/
  2975. /* Mark a register in SET. Hard registers in large modes get all
  2976. of their component registers set as well. */
  2977. static void
  2978. df_mark_reg (rtx reg, void *vset)
  2979. {
  2980. bitmap set = (bitmap) vset;
  2981. int regno = REGNO (reg);
  2982. gcc_assert (GET_MODE (reg) != BLKmode);
  2983. if (regno < FIRST_PSEUDO_REGISTER)
  2984. {
  2985. int n = hard_regno_nregs[regno][GET_MODE (reg)];
  2986. bitmap_set_range (set, regno, n);
  2987. }
  2988. else
  2989. bitmap_set_bit (set, regno);
  2990. }
  2991. /* Set the bit for regs that are considered being defined at the entry. */
  2992. static void
  2993. df_get_entry_block_def_set (bitmap entry_block_defs)
  2994. {
  2995. rtx r;
  2996. int i;
  2997. bitmap_clear (entry_block_defs);
  2998. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2999. {
  3000. if (global_regs[i])
  3001. bitmap_set_bit (entry_block_defs, i);
  3002. if (FUNCTION_ARG_REGNO_P (i))
  3003. bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
  3004. }
  3005. /* The always important stack pointer. */
  3006. bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM);
  3007. /* Once the prologue has been generated, all of these registers
  3008. should just show up in the first regular block. */
  3009. if (HAVE_prologue && epilogue_completed)
  3010. {
  3011. /* Defs for the callee saved registers are inserted so that the
  3012. pushes have some defining location. */
  3013. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3014. if ((call_used_regs[i] == 0) && (df_regs_ever_live_p (i)))
  3015. bitmap_set_bit (entry_block_defs, i);
  3016. }
  3017. r = targetm.calls.struct_value_rtx (current_function_decl, true);
  3018. if (r && REG_P (r))
  3019. bitmap_set_bit (entry_block_defs, REGNO (r));
  3020. /* If the function has an incoming STATIC_CHAIN, it has to show up
  3021. in the entry def set. */
  3022. r = targetm.calls.static_chain (current_function_decl, true);
  3023. if (r && REG_P (r))
  3024. bitmap_set_bit (entry_block_defs, REGNO (r));
  3025. if ((!reload_completed) || frame_pointer_needed)
  3026. {
  3027. /* Any reference to any pseudo before reload is a potential
  3028. reference of the frame pointer. */
  3029. bitmap_set_bit (entry_block_defs, FRAME_POINTER_REGNUM);
  3030. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  3031. /* If they are different, also mark the hard frame pointer as live. */
  3032. if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
  3033. bitmap_set_bit (entry_block_defs, HARD_FRAME_POINTER_REGNUM);
  3034. #endif
  3035. }
  3036. /* These registers are live everywhere. */
  3037. if (!reload_completed)
  3038. {
  3039. #ifdef PIC_OFFSET_TABLE_REGNUM
  3040. unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
  3041. #endif
  3042. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  3043. /* Pseudos with argument area equivalences may require
  3044. reloading via the argument pointer. */
  3045. if (fixed_regs[ARG_POINTER_REGNUM])
  3046. bitmap_set_bit (entry_block_defs, ARG_POINTER_REGNUM);
  3047. #endif
  3048. #ifdef PIC_OFFSET_TABLE_REGNUM
  3049. /* Any constant, or pseudo with constant equivalences, may
  3050. require reloading from memory using the pic register. */
  3051. if (picreg != INVALID_REGNUM
  3052. && fixed_regs[picreg])
  3053. bitmap_set_bit (entry_block_defs, picreg);
  3054. #endif
  3055. }
  3056. #ifdef INCOMING_RETURN_ADDR_RTX
  3057. if (REG_P (INCOMING_RETURN_ADDR_RTX))
  3058. bitmap_set_bit (entry_block_defs, REGNO (INCOMING_RETURN_ADDR_RTX));
  3059. #endif
  3060. targetm.extra_live_on_entry (entry_block_defs);
  3061. }
  3062. /* Return the (conservative) set of hard registers that are defined on
  3063. entry to the function.
  3064. It uses df->entry_block_defs to determine which register
  3065. reference to include. */
  3066. static void
  3067. df_entry_block_defs_collect (struct df_collection_rec *collection_rec,
  3068. bitmap entry_block_defs)
  3069. {
  3070. unsigned int i;
  3071. bitmap_iterator bi;
  3072. EXECUTE_IF_SET_IN_BITMAP (entry_block_defs, 0, i, bi)
  3073. {
  3074. df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
  3075. ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_DEF, 0);
  3076. }
  3077. df_canonize_collection_rec (collection_rec);
  3078. }
  3079. /* Record the (conservative) set of hard registers that are defined on
  3080. entry to the function. */
  3081. static void
  3082. df_record_entry_block_defs (bitmap entry_block_defs)
  3083. {
  3084. struct df_collection_rec collection_rec;
  3085. df_entry_block_defs_collect (&collection_rec, entry_block_defs);
  3086. /* Process bb_refs chain */
  3087. df_refs_add_to_chains (&collection_rec,
  3088. BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK),
  3089. NULL,
  3090. copy_defs);
  3091. }
  3092. /* Update the defs in the entry block. */
  3093. void
  3094. df_update_entry_block_defs (void)
  3095. {
  3096. bitmap_head refs;
  3097. bool changed = false;
  3098. bitmap_initialize (&refs, &df_bitmap_obstack);
  3099. df_get_entry_block_def_set (&refs);
  3100. if (df->entry_block_defs)
  3101. {
  3102. if (!bitmap_equal_p (df->entry_block_defs, &refs))
  3103. {
  3104. struct df_scan_bb_info *bb_info = df_scan_get_bb_info (ENTRY_BLOCK);
  3105. df_ref_chain_delete_du_chain (bb_info->artificial_defs);
  3106. df_ref_chain_delete (bb_info->artificial_defs);
  3107. bb_info->artificial_defs = NULL;
  3108. changed = true;
  3109. }
  3110. }
  3111. else
  3112. {
  3113. struct df_scan_problem_data *problem_data
  3114. = (struct df_scan_problem_data *) df_scan->problem_data;
  3115. gcc_unreachable ();
  3116. df->entry_block_defs = BITMAP_ALLOC (&problem_data->reg_bitmaps);
  3117. changed = true;
  3118. }
  3119. if (changed)
  3120. {
  3121. df_record_entry_block_defs (&refs);
  3122. bitmap_copy (df->entry_block_defs, &refs);
  3123. df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK));
  3124. }
  3125. bitmap_clear (&refs);
  3126. }
  3127. /* Set the bit for regs that are considered being used at the exit. */
  3128. static void
  3129. df_get_exit_block_use_set (bitmap exit_block_uses)
  3130. {
  3131. unsigned int i;
  3132. unsigned int picreg = PIC_OFFSET_TABLE_REGNUM;
  3133. bitmap_clear (exit_block_uses);
  3134. /* Stack pointer is always live at the exit. */
  3135. bitmap_set_bit (exit_block_uses, STACK_POINTER_REGNUM);
  3136. /* Mark the frame pointer if needed at the end of the function.
  3137. If we end up eliminating it, it will be removed from the live
  3138. list of each basic block by reload. */
  3139. if ((!reload_completed) || frame_pointer_needed)
  3140. {
  3141. bitmap_set_bit (exit_block_uses, FRAME_POINTER_REGNUM);
  3142. #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
  3143. /* If they are different, also mark the hard frame pointer as live. */
  3144. if (!LOCAL_REGNO (HARD_FRAME_POINTER_REGNUM))
  3145. bitmap_set_bit (exit_block_uses, HARD_FRAME_POINTER_REGNUM);
  3146. #endif
  3147. }
  3148. /* Many architectures have a GP register even without flag_pic.
  3149. Assume the pic register is not in use, or will be handled by
  3150. other means, if it is not fixed. */
  3151. if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
  3152. && picreg != INVALID_REGNUM
  3153. && fixed_regs[picreg])
  3154. bitmap_set_bit (exit_block_uses, picreg);
  3155. /* Mark all global registers, and all registers used by the
  3156. epilogue as being live at the end of the function since they
  3157. may be referenced by our caller. */
  3158. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3159. if (global_regs[i] || EPILOGUE_USES (i))
  3160. bitmap_set_bit (exit_block_uses, i);
  3161. if (HAVE_epilogue && epilogue_completed)
  3162. {
  3163. /* Mark all call-saved registers that we actually used. */
  3164. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3165. if (df_regs_ever_live_p (i) && !LOCAL_REGNO (i)
  3166. && !TEST_HARD_REG_BIT (regs_invalidated_by_call, i))
  3167. bitmap_set_bit (exit_block_uses, i);
  3168. }
  3169. #ifdef EH_RETURN_DATA_REGNO
  3170. /* Mark the registers that will contain data for the handler. */
  3171. if (reload_completed && crtl->calls_eh_return)
  3172. for (i = 0; ; ++i)
  3173. {
  3174. unsigned regno = EH_RETURN_DATA_REGNO (i);
  3175. if (regno == INVALID_REGNUM)
  3176. break;
  3177. bitmap_set_bit (exit_block_uses, regno);
  3178. }
  3179. #endif
  3180. #ifdef EH_RETURN_STACKADJ_RTX
  3181. if ((!HAVE_epilogue || ! epilogue_completed)
  3182. && crtl->calls_eh_return)
  3183. {
  3184. rtx tmp = EH_RETURN_STACKADJ_RTX;
  3185. if (tmp && REG_P (tmp))
  3186. df_mark_reg (tmp, exit_block_uses);
  3187. }
  3188. #endif
  3189. #ifdef EH_RETURN_HANDLER_RTX
  3190. if ((!HAVE_epilogue || ! epilogue_completed)
  3191. && crtl->calls_eh_return)
  3192. {
  3193. rtx tmp = EH_RETURN_HANDLER_RTX;
  3194. if (tmp && REG_P (tmp))
  3195. df_mark_reg (tmp, exit_block_uses);
  3196. }
  3197. #endif
  3198. /* Mark function return value. */
  3199. diddle_return_value (df_mark_reg, (void*) exit_block_uses);
  3200. }
  3201. /* Return the refs of hard registers that are used in the exit block.
  3202. It uses df->exit_block_uses to determine register to include. */
  3203. static void
  3204. df_exit_block_uses_collect (struct df_collection_rec *collection_rec, bitmap exit_block_uses)
  3205. {
  3206. unsigned int i;
  3207. bitmap_iterator bi;
  3208. EXECUTE_IF_SET_IN_BITMAP (exit_block_uses, 0, i, bi)
  3209. df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[i], NULL,
  3210. EXIT_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_USE, 0);
  3211. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  3212. /* It is deliberate that this is not put in the exit block uses but
  3213. I do not know why. */
  3214. if (reload_completed
  3215. && !bitmap_bit_p (exit_block_uses, ARG_POINTER_REGNUM)
  3216. && bb_has_eh_pred (EXIT_BLOCK_PTR_FOR_FN (cfun))
  3217. && fixed_regs[ARG_POINTER_REGNUM])
  3218. df_ref_record (DF_REF_ARTIFICIAL, collection_rec, regno_reg_rtx[ARG_POINTER_REGNUM], NULL,
  3219. EXIT_BLOCK_PTR_FOR_FN (cfun), NULL, DF_REF_REG_USE, 0);
  3220. #endif
  3221. df_canonize_collection_rec (collection_rec);
  3222. }
  3223. /* Record the set of hard registers that are used in the exit block.
  3224. It uses df->exit_block_uses to determine which bit to include. */
  3225. static void
  3226. df_record_exit_block_uses (bitmap exit_block_uses)
  3227. {
  3228. struct df_collection_rec collection_rec;
  3229. df_exit_block_uses_collect (&collection_rec, exit_block_uses);
  3230. /* Process bb_refs chain */
  3231. df_refs_add_to_chains (&collection_rec,
  3232. BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK),
  3233. NULL,
  3234. copy_uses);
  3235. }
  3236. /* Update the uses in the exit block. */
  3237. void
  3238. df_update_exit_block_uses (void)
  3239. {
  3240. bitmap_head refs;
  3241. bool changed = false;
  3242. bitmap_initialize (&refs, &df_bitmap_obstack);
  3243. df_get_exit_block_use_set (&refs);
  3244. if (df->exit_block_uses)
  3245. {
  3246. if (!bitmap_equal_p (df->exit_block_uses, &refs))
  3247. {
  3248. struct df_scan_bb_info *bb_info = df_scan_get_bb_info (EXIT_BLOCK);
  3249. df_ref_chain_delete_du_chain (bb_info->artificial_uses);
  3250. df_ref_chain_delete (bb_info->artificial_uses);
  3251. bb_info->artificial_uses = NULL;
  3252. changed = true;
  3253. }
  3254. }
  3255. else
  3256. {
  3257. struct df_scan_problem_data *problem_data
  3258. = (struct df_scan_problem_data *) df_scan->problem_data;
  3259. gcc_unreachable ();
  3260. df->exit_block_uses = BITMAP_ALLOC (&problem_data->reg_bitmaps);
  3261. changed = true;
  3262. }
  3263. if (changed)
  3264. {
  3265. df_record_exit_block_uses (&refs);
  3266. bitmap_copy (df->exit_block_uses,& refs);
  3267. df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
  3268. }
  3269. bitmap_clear (&refs);
  3270. }
  3271. static bool initialized = false;
  3272. /* Initialize some platform specific structures. */
  3273. void
  3274. df_hard_reg_init (void)
  3275. {
  3276. #ifdef ELIMINABLE_REGS
  3277. int i;
  3278. static const struct {const int from, to; } eliminables[] = ELIMINABLE_REGS;
  3279. #endif
  3280. if (initialized)
  3281. return;
  3282. /* Record which registers will be eliminated. We use this in
  3283. mark_used_regs. */
  3284. CLEAR_HARD_REG_SET (elim_reg_set);
  3285. #ifdef ELIMINABLE_REGS
  3286. for (i = 0; i < (int) ARRAY_SIZE (eliminables); i++)
  3287. SET_HARD_REG_BIT (elim_reg_set, eliminables[i].from);
  3288. #else
  3289. SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
  3290. #endif
  3291. initialized = true;
  3292. }
  3293. /* Recompute the parts of scanning that are based on regs_ever_live
  3294. because something changed in that array. */
  3295. void
  3296. df_update_entry_exit_and_calls (void)
  3297. {
  3298. basic_block bb;
  3299. df_update_entry_block_defs ();
  3300. df_update_exit_block_uses ();
  3301. /* The call insns need to be rescanned because there may be changes
  3302. in the set of registers clobbered across the call. */
  3303. FOR_EACH_BB_FN (bb, cfun)
  3304. {
  3305. rtx_insn *insn;
  3306. FOR_BB_INSNS (bb, insn)
  3307. {
  3308. if (INSN_P (insn) && CALL_P (insn))
  3309. df_insn_rescan (insn);
  3310. }
  3311. }
  3312. }
  3313. /* Return true if hard REG is actually used in the some instruction.
  3314. There are a fair number of conditions that affect the setting of
  3315. this array. See the comment in df.h for df->hard_regs_live_count
  3316. for the conditions that this array is set. */
  3317. bool
  3318. df_hard_reg_used_p (unsigned int reg)
  3319. {
  3320. return df->hard_regs_live_count[reg] != 0;
  3321. }
  3322. /* A count of the number of times REG is actually used in the some
  3323. instruction. There are a fair number of conditions that affect the
  3324. setting of this array. See the comment in df.h for
  3325. df->hard_regs_live_count for the conditions that this array is
  3326. set. */
  3327. unsigned int
  3328. df_hard_reg_used_count (unsigned int reg)
  3329. {
  3330. return df->hard_regs_live_count[reg];
  3331. }
  3332. /* Get the value of regs_ever_live[REGNO]. */
  3333. bool
  3334. df_regs_ever_live_p (unsigned int regno)
  3335. {
  3336. return regs_ever_live[regno];
  3337. }
  3338. /* Set regs_ever_live[REGNO] to VALUE. If this cause regs_ever_live
  3339. to change, schedule that change for the next update. */
  3340. void
  3341. df_set_regs_ever_live (unsigned int regno, bool value)
  3342. {
  3343. if (regs_ever_live[regno] == value)
  3344. return;
  3345. regs_ever_live[regno] = value;
  3346. if (df)
  3347. df->redo_entry_and_exit = true;
  3348. }
  3349. /* Compute "regs_ever_live" information from the underlying df
  3350. information. Set the vector to all false if RESET. */
  3351. void
  3352. df_compute_regs_ever_live (bool reset)
  3353. {
  3354. unsigned int i;
  3355. bool changed = df->redo_entry_and_exit;
  3356. if (reset)
  3357. memset (regs_ever_live, 0, sizeof (regs_ever_live));
  3358. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3359. if ((!regs_ever_live[i]) && df_hard_reg_used_p (i))
  3360. {
  3361. regs_ever_live[i] = true;
  3362. changed = true;
  3363. }
  3364. if (changed)
  3365. df_update_entry_exit_and_calls ();
  3366. df->redo_entry_and_exit = false;
  3367. }
  3368. /*----------------------------------------------------------------------------
  3369. Dataflow ref information verification functions.
  3370. df_reg_chain_mark (refs, regno, is_def, is_eq_use)
  3371. df_reg_chain_verify_unmarked (refs)
  3372. df_refs_verify (vec<stack, va_df_ref>, ref*, bool)
  3373. df_mws_verify (mw*, mw*, bool)
  3374. df_insn_refs_verify (collection_rec, bb, insn, bool)
  3375. df_bb_refs_verify (bb, refs, bool)
  3376. df_bb_verify (bb)
  3377. df_exit_block_bitmap_verify (bool)
  3378. df_entry_block_bitmap_verify (bool)
  3379. df_scan_verify ()
  3380. ----------------------------------------------------------------------------*/
  3381. /* Mark all refs in the reg chain. Verify that all of the registers
  3382. are in the correct chain. */
  3383. static unsigned int
  3384. df_reg_chain_mark (df_ref refs, unsigned int regno,
  3385. bool is_def, bool is_eq_use)
  3386. {
  3387. unsigned int count = 0;
  3388. df_ref ref;
  3389. for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
  3390. {
  3391. gcc_assert (!DF_REF_IS_REG_MARKED (ref));
  3392. /* If there are no def-use or use-def chains, make sure that all
  3393. of the chains are clear. */
  3394. if (!df_chain)
  3395. gcc_assert (!DF_REF_CHAIN (ref));
  3396. /* Check to make sure the ref is in the correct chain. */
  3397. gcc_assert (DF_REF_REGNO (ref) == regno);
  3398. if (is_def)
  3399. gcc_assert (DF_REF_REG_DEF_P (ref));
  3400. else
  3401. gcc_assert (!DF_REF_REG_DEF_P (ref));
  3402. if (is_eq_use)
  3403. gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE));
  3404. else
  3405. gcc_assert ((DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) == 0);
  3406. if (DF_REF_NEXT_REG (ref))
  3407. gcc_assert (DF_REF_PREV_REG (DF_REF_NEXT_REG (ref)) == ref);
  3408. count++;
  3409. DF_REF_REG_MARK (ref);
  3410. }
  3411. return count;
  3412. }
  3413. /* Verify that all of the registers in the chain are unmarked. */
  3414. static void
  3415. df_reg_chain_verify_unmarked (df_ref refs)
  3416. {
  3417. df_ref ref;
  3418. for (ref = refs; ref; ref = DF_REF_NEXT_REG (ref))
  3419. gcc_assert (!DF_REF_IS_REG_MARKED (ref));
  3420. }
  3421. /* Verify that NEW_REC and OLD_REC have exactly the same members. */
  3422. static bool
  3423. df_refs_verify (const vec<df_ref, va_heap> *new_rec, df_ref old_rec,
  3424. bool abort_if_fail)
  3425. {
  3426. unsigned int ix;
  3427. df_ref new_ref;
  3428. FOR_EACH_VEC_ELT (*new_rec, ix, new_ref)
  3429. {
  3430. if (old_rec == NULL || !df_ref_equal_p (new_ref, old_rec))
  3431. {
  3432. if (abort_if_fail)
  3433. gcc_assert (0);
  3434. else
  3435. return false;
  3436. }
  3437. /* Abort if fail is called from the function level verifier. If
  3438. that is the context, mark this reg as being seem. */
  3439. if (abort_if_fail)
  3440. {
  3441. gcc_assert (DF_REF_IS_REG_MARKED (old_rec));
  3442. DF_REF_REG_UNMARK (old_rec);
  3443. }
  3444. old_rec = DF_REF_NEXT_LOC (old_rec);
  3445. }
  3446. if (abort_if_fail)
  3447. gcc_assert (old_rec == NULL);
  3448. else
  3449. return old_rec == NULL;
  3450. return false;
  3451. }
  3452. /* Verify that NEW_REC and OLD_REC have exactly the same members. */
  3453. static bool
  3454. df_mws_verify (const vec<df_mw_hardreg_ptr, va_heap> *new_rec,
  3455. struct df_mw_hardreg *old_rec,
  3456. bool abort_if_fail)
  3457. {
  3458. unsigned int ix;
  3459. struct df_mw_hardreg *new_reg;
  3460. FOR_EACH_VEC_ELT (*new_rec, ix, new_reg)
  3461. {
  3462. if (old_rec == NULL || !df_mw_equal_p (new_reg, old_rec))
  3463. {
  3464. if (abort_if_fail)
  3465. gcc_assert (0);
  3466. else
  3467. return false;
  3468. }
  3469. old_rec = DF_MWS_NEXT (old_rec);
  3470. }
  3471. if (abort_if_fail)
  3472. gcc_assert (old_rec == NULL);
  3473. else
  3474. return old_rec == NULL;
  3475. return false;
  3476. }
  3477. /* Return true if the existing insn refs information is complete and
  3478. correct. Otherwise (i.e. if there's any missing or extra refs),
  3479. return the correct df_ref chain in REFS_RETURN.
  3480. If ABORT_IF_FAIL, leave the refs that are verified (already in the
  3481. ref chain) as DF_REF_MARKED(). If it's false, then it's a per-insn
  3482. verification mode instead of the whole function, so unmark
  3483. everything.
  3484. If ABORT_IF_FAIL is set, this function never returns false. */
  3485. static bool
  3486. df_insn_refs_verify (struct df_collection_rec *collection_rec,
  3487. basic_block bb,
  3488. rtx_insn *insn,
  3489. bool abort_if_fail)
  3490. {
  3491. bool ret1, ret2, ret3, ret4;
  3492. unsigned int uid = INSN_UID (insn);
  3493. struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
  3494. df_insn_refs_collect (collection_rec, bb, insn_info);
  3495. /* Unfortunately we cannot opt out early if one of these is not
  3496. right because the marks will not get cleared. */
  3497. ret1 = df_refs_verify (&collection_rec->def_vec, DF_INSN_UID_DEFS (uid),
  3498. abort_if_fail);
  3499. ret2 = df_refs_verify (&collection_rec->use_vec, DF_INSN_UID_USES (uid),
  3500. abort_if_fail);
  3501. ret3 = df_refs_verify (&collection_rec->eq_use_vec, DF_INSN_UID_EQ_USES (uid),
  3502. abort_if_fail);
  3503. ret4 = df_mws_verify (&collection_rec->mw_vec, DF_INSN_UID_MWS (uid),
  3504. abort_if_fail);
  3505. return (ret1 && ret2 && ret3 && ret4);
  3506. }
  3507. /* Return true if all refs in the basic block are correct and complete.
  3508. Due to df_ref_chain_verify, it will cause all refs
  3509. that are verified to have DF_REF_MARK bit set. */
  3510. static bool
  3511. df_bb_verify (basic_block bb)
  3512. {
  3513. rtx_insn *insn;
  3514. struct df_scan_bb_info *bb_info = df_scan_get_bb_info (bb->index);
  3515. struct df_collection_rec collection_rec;
  3516. gcc_assert (bb_info);
  3517. /* Scan the block, one insn at a time, from beginning to end. */
  3518. FOR_BB_INSNS_REVERSE (bb, insn)
  3519. {
  3520. if (!INSN_P (insn))
  3521. continue;
  3522. df_insn_refs_verify (&collection_rec, bb, insn, true);
  3523. df_free_collection_rec (&collection_rec);
  3524. }
  3525. /* Do the artificial defs and uses. */
  3526. df_bb_refs_collect (&collection_rec, bb);
  3527. df_refs_verify (&collection_rec.def_vec, df_get_artificial_defs (bb->index), true);
  3528. df_refs_verify (&collection_rec.use_vec, df_get_artificial_uses (bb->index), true);
  3529. df_free_collection_rec (&collection_rec);
  3530. return true;
  3531. }
  3532. /* Returns true if the entry block has correct and complete df_ref set.
  3533. If not it either aborts if ABORT_IF_FAIL is true or returns false. */
  3534. static bool
  3535. df_entry_block_bitmap_verify (bool abort_if_fail)
  3536. {
  3537. bitmap_head entry_block_defs;
  3538. bool is_eq;
  3539. bitmap_initialize (&entry_block_defs, &df_bitmap_obstack);
  3540. df_get_entry_block_def_set (&entry_block_defs);
  3541. is_eq = bitmap_equal_p (&entry_block_defs, df->entry_block_defs);
  3542. if (!is_eq && abort_if_fail)
  3543. {
  3544. fprintf (stderr, "entry_block_defs = ");
  3545. df_print_regset (stderr, &entry_block_defs);
  3546. fprintf (stderr, "df->entry_block_defs = ");
  3547. df_print_regset (stderr, df->entry_block_defs);
  3548. gcc_assert (0);
  3549. }
  3550. bitmap_clear (&entry_block_defs);
  3551. return is_eq;
  3552. }
  3553. /* Returns true if the exit block has correct and complete df_ref set.
  3554. If not it either aborts if ABORT_IF_FAIL is true or returns false. */
  3555. static bool
  3556. df_exit_block_bitmap_verify (bool abort_if_fail)
  3557. {
  3558. bitmap_head exit_block_uses;
  3559. bool is_eq;
  3560. bitmap_initialize (&exit_block_uses, &df_bitmap_obstack);
  3561. df_get_exit_block_use_set (&exit_block_uses);
  3562. is_eq = bitmap_equal_p (&exit_block_uses, df->exit_block_uses);
  3563. if (!is_eq && abort_if_fail)
  3564. {
  3565. fprintf (stderr, "exit_block_uses = ");
  3566. df_print_regset (stderr, &exit_block_uses);
  3567. fprintf (stderr, "df->exit_block_uses = ");
  3568. df_print_regset (stderr, df->exit_block_uses);
  3569. gcc_assert (0);
  3570. }
  3571. bitmap_clear (&exit_block_uses);
  3572. return is_eq;
  3573. }
  3574. /* Return true if df_ref information for all insns in all blocks are
  3575. correct and complete. */
  3576. void
  3577. df_scan_verify (void)
  3578. {
  3579. unsigned int i;
  3580. basic_block bb;
  3581. bitmap_head regular_block_artificial_uses;
  3582. bitmap_head eh_block_artificial_uses;
  3583. if (!df)
  3584. return;
  3585. /* Verification is a 4 step process. */
  3586. /* (1) All of the refs are marked by going through the reg chains. */
  3587. for (i = 0; i < DF_REG_SIZE (df); i++)
  3588. {
  3589. gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false)
  3590. == DF_REG_DEF_COUNT (i));
  3591. gcc_assert (df_reg_chain_mark (DF_REG_USE_CHAIN (i), i, false, false)
  3592. == DF_REG_USE_COUNT (i));
  3593. gcc_assert (df_reg_chain_mark (DF_REG_EQ_USE_CHAIN (i), i, false, true)
  3594. == DF_REG_EQ_USE_COUNT (i));
  3595. }
  3596. /* (2) There are various bitmaps whose value may change over the
  3597. course of the compilation. This step recomputes them to make
  3598. sure that they have not slipped out of date. */
  3599. bitmap_initialize (&regular_block_artificial_uses, &df_bitmap_obstack);
  3600. bitmap_initialize (&eh_block_artificial_uses, &df_bitmap_obstack);
  3601. df_get_regular_block_artificial_uses (&regular_block_artificial_uses);
  3602. df_get_eh_block_artificial_uses (&eh_block_artificial_uses);
  3603. bitmap_ior_into (&eh_block_artificial_uses,
  3604. &regular_block_artificial_uses);
  3605. /* Check artificial_uses bitmaps didn't change. */
  3606. gcc_assert (bitmap_equal_p (&regular_block_artificial_uses,
  3607. &df->regular_block_artificial_uses));
  3608. gcc_assert (bitmap_equal_p (&eh_block_artificial_uses,
  3609. &df->eh_block_artificial_uses));
  3610. bitmap_clear (&regular_block_artificial_uses);
  3611. bitmap_clear (&eh_block_artificial_uses);
  3612. /* Verify entry block and exit block. These only verify the bitmaps,
  3613. the refs are verified in df_bb_verify. */
  3614. df_entry_block_bitmap_verify (true);
  3615. df_exit_block_bitmap_verify (true);
  3616. /* (3) All of the insns in all of the blocks are traversed and the
  3617. marks are cleared both in the artificial refs attached to the
  3618. blocks and the real refs inside the insns. It is a failure to
  3619. clear a mark that has not been set as this means that the ref in
  3620. the block or insn was not in the reg chain. */
  3621. FOR_ALL_BB_FN (bb, cfun)
  3622. df_bb_verify (bb);
  3623. /* (4) See if all reg chains are traversed a second time. This time
  3624. a check is made that the marks are clear. A set mark would be a
  3625. from a reg that is not in any insn or basic block. */
  3626. for (i = 0; i < DF_REG_SIZE (df); i++)
  3627. {
  3628. df_reg_chain_verify_unmarked (DF_REG_DEF_CHAIN (i));
  3629. df_reg_chain_verify_unmarked (DF_REG_USE_CHAIN (i));
  3630. df_reg_chain_verify_unmarked (DF_REG_EQ_USE_CHAIN (i));
  3631. }
  3632. }