dse.c 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848
  1. /* RTL dead store elimination.
  2. Copyright (C) 2005-2015 Free Software Foundation, Inc.
  3. Contributed by Richard Sandiford <rsandifor@codesourcery.com>
  4. and Kenneth Zadeck <zadeck@naturalbridge.com>
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 3, or (at your option) any later
  9. version.
  10. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GCC; see the file COPYING3. If not see
  16. <http://www.gnu.org/licenses/>. */
  17. #undef BASELINE
  18. #include "config.h"
  19. #include "system.h"
  20. #include "coretypes.h"
  21. #include "hash-table.h"
  22. #include "tm.h"
  23. #include "rtl.h"
  24. #include "hash-set.h"
  25. #include "machmode.h"
  26. #include "vec.h"
  27. #include "double-int.h"
  28. #include "input.h"
  29. #include "alias.h"
  30. #include "symtab.h"
  31. #include "wide-int.h"
  32. #include "inchash.h"
  33. #include "real.h"
  34. #include "tree.h"
  35. #include "fold-const.h"
  36. #include "stor-layout.h"
  37. #include "tm_p.h"
  38. #include "regs.h"
  39. #include "hard-reg-set.h"
  40. #include "regset.h"
  41. #include "flags.h"
  42. #include "dominance.h"
  43. #include "cfg.h"
  44. #include "cfgrtl.h"
  45. #include "predict.h"
  46. #include "basic-block.h"
  47. #include "df.h"
  48. #include "cselib.h"
  49. #include "tree-pass.h"
  50. #include "alloc-pool.h"
  51. #include "insn-config.h"
  52. #include "hashtab.h"
  53. #include "function.h"
  54. #include "statistics.h"
  55. #include "fixed-value.h"
  56. #include "expmed.h"
  57. #include "dojump.h"
  58. #include "explow.h"
  59. #include "calls.h"
  60. #include "emit-rtl.h"
  61. #include "varasm.h"
  62. #include "stmt.h"
  63. #include "expr.h"
  64. #include "recog.h"
  65. #include "insn-codes.h"
  66. #include "optabs.h"
  67. #include "dbgcnt.h"
  68. #include "target.h"
  69. #include "params.h"
  70. #include "tree-ssa-alias.h"
  71. #include "internal-fn.h"
  72. #include "gimple-expr.h"
  73. #include "is-a.h"
  74. #include "gimple.h"
  75. #include "gimple-ssa.h"
  76. #include "rtl-iter.h"
  77. #include "cfgcleanup.h"
  78. /* This file contains three techniques for performing Dead Store
  79. Elimination (dse).
  80. * The first technique performs dse locally on any base address. It
  81. is based on the cselib which is a local value numbering technique.
  82. This technique is local to a basic block but deals with a fairly
  83. general addresses.
  84. * The second technique performs dse globally but is restricted to
  85. base addresses that are either constant or are relative to the
  86. frame_pointer.
  87. * The third technique, (which is only done after register allocation)
  88. processes the spill spill slots. This differs from the second
  89. technique because it takes advantage of the fact that spilling is
  90. completely free from the effects of aliasing.
  91. Logically, dse is a backwards dataflow problem. A store can be
  92. deleted if it if cannot be reached in the backward direction by any
  93. use of the value being stored. However, the local technique uses a
  94. forwards scan of the basic block because cselib requires that the
  95. block be processed in that order.
  96. The pass is logically broken into 7 steps:
  97. 0) Initialization.
  98. 1) The local algorithm, as well as scanning the insns for the two
  99. global algorithms.
  100. 2) Analysis to see if the global algs are necessary. In the case
  101. of stores base on a constant address, there must be at least two
  102. stores to that address, to make it possible to delete some of the
  103. stores. In the case of stores off of the frame or spill related
  104. stores, only one store to an address is necessary because those
  105. stores die at the end of the function.
  106. 3) Set up the global dataflow equations based on processing the
  107. info parsed in the first step.
  108. 4) Solve the dataflow equations.
  109. 5) Delete the insns that the global analysis has indicated are
  110. unnecessary.
  111. 6) Delete insns that store the same value as preceding store
  112. where the earlier store couldn't be eliminated.
  113. 7) Cleanup.
  114. This step uses cselib and canon_rtx to build the largest expression
  115. possible for each address. This pass is a forwards pass through
  116. each basic block. From the point of view of the global technique,
  117. the first pass could examine a block in either direction. The
  118. forwards ordering is to accommodate cselib.
  119. We make a simplifying assumption: addresses fall into four broad
  120. categories:
  121. 1) base has rtx_varies_p == false, offset is constant.
  122. 2) base has rtx_varies_p == false, offset variable.
  123. 3) base has rtx_varies_p == true, offset constant.
  124. 4) base has rtx_varies_p == true, offset variable.
  125. The local passes are able to process all 4 kinds of addresses. The
  126. global pass only handles 1).
  127. The global problem is formulated as follows:
  128. A store, S1, to address A, where A is not relative to the stack
  129. frame, can be eliminated if all paths from S1 to the end of the
  130. function contain another store to A before a read to A.
  131. If the address A is relative to the stack frame, a store S2 to A
  132. can be eliminated if there are no paths from S2 that reach the
  133. end of the function that read A before another store to A. In
  134. this case S2 can be deleted if there are paths from S2 to the
  135. end of the function that have no reads or writes to A. This
  136. second case allows stores to the stack frame to be deleted that
  137. would otherwise die when the function returns. This cannot be
  138. done if stores_off_frame_dead_at_return is not true. See the doc
  139. for that variable for when this variable is false.
  140. The global problem is formulated as a backwards set union
  141. dataflow problem where the stores are the gens and reads are the
  142. kills. Set union problems are rare and require some special
  143. handling given our representation of bitmaps. A straightforward
  144. implementation requires a lot of bitmaps filled with 1s.
  145. These are expensive and cumbersome in our bitmap formulation so
  146. care has been taken to avoid large vectors filled with 1s. See
  147. the comments in bb_info and in the dataflow confluence functions
  148. for details.
  149. There are two places for further enhancements to this algorithm:
  150. 1) The original dse which was embedded in a pass called flow also
  151. did local address forwarding. For example in
  152. A <- r100
  153. ... <- A
  154. flow would replace the right hand side of the second insn with a
  155. reference to r100. Most of the information is available to add this
  156. to this pass. It has not done it because it is a lot of work in
  157. the case that either r100 is assigned to between the first and
  158. second insn and/or the second insn is a load of part of the value
  159. stored by the first insn.
  160. insn 5 in gcc.c-torture/compile/990203-1.c simple case.
  161. insn 15 in gcc.c-torture/execute/20001017-2.c simple case.
  162. insn 25 in gcc.c-torture/execute/20001026-1.c simple case.
  163. insn 44 in gcc.c-torture/execute/20010910-1.c simple case.
  164. 2) The cleaning up of spill code is quite profitable. It currently
  165. depends on reading tea leaves and chicken entrails left by reload.
  166. This pass depends on reload creating a singleton alias set for each
  167. spill slot and telling the next dse pass which of these alias sets
  168. are the singletons. Rather than analyze the addresses of the
  169. spills, dse's spill processing just does analysis of the loads and
  170. stores that use those alias sets. There are three cases where this
  171. falls short:
  172. a) Reload sometimes creates the slot for one mode of access, and
  173. then inserts loads and/or stores for a smaller mode. In this
  174. case, the current code just punts on the slot. The proper thing
  175. to do is to back out and use one bit vector position for each
  176. byte of the entity associated with the slot. This depends on
  177. KNOWING that reload always generates the accesses for each of the
  178. bytes in some canonical (read that easy to understand several
  179. passes after reload happens) way.
  180. b) Reload sometimes decides that spill slot it allocated was not
  181. large enough for the mode and goes back and allocates more slots
  182. with the same mode and alias set. The backout in this case is a
  183. little more graceful than (a). In this case the slot is unmarked
  184. as being a spill slot and if final address comes out to be based
  185. off the frame pointer, the global algorithm handles this slot.
  186. c) For any pass that may prespill, there is currently no
  187. mechanism to tell the dse pass that the slot being used has the
  188. special properties that reload uses. It may be that all that is
  189. required is to have those passes make the same calls that reload
  190. does, assuming that the alias sets can be manipulated in the same
  191. way. */
  192. /* There are limits to the size of constant offsets we model for the
  193. global problem. There are certainly test cases, that exceed this
  194. limit, however, it is unlikely that there are important programs
  195. that really have constant offsets this size. */
  196. #define MAX_OFFSET (64 * 1024)
  197. /* Obstack for the DSE dataflow bitmaps. We don't want to put these
  198. on the default obstack because these bitmaps can grow quite large
  199. (~2GB for the small (!) test case of PR54146) and we'll hold on to
  200. all that memory until the end of the compiler run.
  201. As a bonus, delete_tree_live_info can destroy all the bitmaps by just
  202. releasing the whole obstack. */
  203. static bitmap_obstack dse_bitmap_obstack;
  204. /* Obstack for other data. As for above: Kinda nice to be able to
  205. throw it all away at the end in one big sweep. */
  206. static struct obstack dse_obstack;
  207. /* Scratch bitmap for cselib's cselib_expand_value_rtx. */
  208. static bitmap scratch = NULL;
  209. struct insn_info;
  210. /* This structure holds information about a candidate store. */
  211. struct store_info
  212. {
  213. /* False means this is a clobber. */
  214. bool is_set;
  215. /* False if a single HOST_WIDE_INT bitmap is used for positions_needed. */
  216. bool is_large;
  217. /* The id of the mem group of the base address. If rtx_varies_p is
  218. true, this is -1. Otherwise, it is the index into the group
  219. table. */
  220. int group_id;
  221. /* This is the cselib value. */
  222. cselib_val *cse_base;
  223. /* This canonized mem. */
  224. rtx mem;
  225. /* Canonized MEM address for use by canon_true_dependence. */
  226. rtx mem_addr;
  227. /* If this is non-zero, it is the alias set of a spill location. */
  228. alias_set_type alias_set;
  229. /* The offset of the first and byte before the last byte associated
  230. with the operation. */
  231. HOST_WIDE_INT begin, end;
  232. union
  233. {
  234. /* A bitmask as wide as the number of bytes in the word that
  235. contains a 1 if the byte may be needed. The store is unused if
  236. all of the bits are 0. This is used if IS_LARGE is false. */
  237. unsigned HOST_WIDE_INT small_bitmask;
  238. struct
  239. {
  240. /* A bitmap with one bit per byte. Cleared bit means the position
  241. is needed. Used if IS_LARGE is false. */
  242. bitmap bmap;
  243. /* Number of set bits (i.e. unneeded bytes) in BITMAP. If it is
  244. equal to END - BEGIN, the whole store is unused. */
  245. int count;
  246. } large;
  247. } positions_needed;
  248. /* The next store info for this insn. */
  249. struct store_info *next;
  250. /* The right hand side of the store. This is used if there is a
  251. subsequent reload of the mems address somewhere later in the
  252. basic block. */
  253. rtx rhs;
  254. /* If rhs is or holds a constant, this contains that constant,
  255. otherwise NULL. */
  256. rtx const_rhs;
  257. /* Set if this store stores the same constant value as REDUNDANT_REASON
  258. insn stored. These aren't eliminated early, because doing that
  259. might prevent the earlier larger store to be eliminated. */
  260. struct insn_info *redundant_reason;
  261. };
  262. /* Return a bitmask with the first N low bits set. */
  263. static unsigned HOST_WIDE_INT
  264. lowpart_bitmask (int n)
  265. {
  266. unsigned HOST_WIDE_INT mask = ~(unsigned HOST_WIDE_INT) 0;
  267. return mask >> (HOST_BITS_PER_WIDE_INT - n);
  268. }
  269. typedef struct store_info *store_info_t;
  270. static alloc_pool cse_store_info_pool;
  271. static alloc_pool rtx_store_info_pool;
  272. /* This structure holds information about a load. These are only
  273. built for rtx bases. */
  274. struct read_info
  275. {
  276. /* The id of the mem group of the base address. */
  277. int group_id;
  278. /* If this is non-zero, it is the alias set of a spill location. */
  279. alias_set_type alias_set;
  280. /* The offset of the first and byte after the last byte associated
  281. with the operation. If begin == end == 0, the read did not have
  282. a constant offset. */
  283. int begin, end;
  284. /* The mem being read. */
  285. rtx mem;
  286. /* The next read_info for this insn. */
  287. struct read_info *next;
  288. };
  289. typedef struct read_info *read_info_t;
  290. static alloc_pool read_info_pool;
  291. /* One of these records is created for each insn. */
  292. struct insn_info
  293. {
  294. /* Set true if the insn contains a store but the insn itself cannot
  295. be deleted. This is set if the insn is a parallel and there is
  296. more than one non dead output or if the insn is in some way
  297. volatile. */
  298. bool cannot_delete;
  299. /* This field is only used by the global algorithm. It is set true
  300. if the insn contains any read of mem except for a (1). This is
  301. also set if the insn is a call or has a clobber mem. If the insn
  302. contains a wild read, the use_rec will be null. */
  303. bool wild_read;
  304. /* This is true only for CALL instructions which could potentially read
  305. any non-frame memory location. This field is used by the global
  306. algorithm. */
  307. bool non_frame_wild_read;
  308. /* This field is only used for the processing of const functions.
  309. These functions cannot read memory, but they can read the stack
  310. because that is where they may get their parms. We need to be
  311. this conservative because, like the store motion pass, we don't
  312. consider CALL_INSN_FUNCTION_USAGE when processing call insns.
  313. Moreover, we need to distinguish two cases:
  314. 1. Before reload (register elimination), the stores related to
  315. outgoing arguments are stack pointer based and thus deemed
  316. of non-constant base in this pass. This requires special
  317. handling but also means that the frame pointer based stores
  318. need not be killed upon encountering a const function call.
  319. 2. After reload, the stores related to outgoing arguments can be
  320. either stack pointer or hard frame pointer based. This means
  321. that we have no other choice than also killing all the frame
  322. pointer based stores upon encountering a const function call.
  323. This field is set after reload for const function calls and before
  324. reload for const tail function calls on targets where arg pointer
  325. is the frame pointer. Having this set is less severe than a wild
  326. read, it just means that all the frame related stores are killed
  327. rather than all the stores. */
  328. bool frame_read;
  329. /* This field is only used for the processing of const functions.
  330. It is set if the insn may contain a stack pointer based store. */
  331. bool stack_pointer_based;
  332. /* This is true if any of the sets within the store contains a
  333. cselib base. Such stores can only be deleted by the local
  334. algorithm. */
  335. bool contains_cselib_groups;
  336. /* The insn. */
  337. rtx_insn *insn;
  338. /* The list of mem sets or mem clobbers that are contained in this
  339. insn. If the insn is deletable, it contains only one mem set.
  340. But it could also contain clobbers. Insns that contain more than
  341. one mem set are not deletable, but each of those mems are here in
  342. order to provide info to delete other insns. */
  343. store_info_t store_rec;
  344. /* The linked list of mem uses in this insn. Only the reads from
  345. rtx bases are listed here. The reads to cselib bases are
  346. completely processed during the first scan and so are never
  347. created. */
  348. read_info_t read_rec;
  349. /* The live fixed registers. We assume only fixed registers can
  350. cause trouble by being clobbered from an expanded pattern;
  351. storing only the live fixed registers (rather than all registers)
  352. means less memory needs to be allocated / copied for the individual
  353. stores. */
  354. regset fixed_regs_live;
  355. /* The prev insn in the basic block. */
  356. struct insn_info * prev_insn;
  357. /* The linked list of insns that are in consideration for removal in
  358. the forwards pass through the basic block. This pointer may be
  359. trash as it is not cleared when a wild read occurs. The only
  360. time it is guaranteed to be correct is when the traversal starts
  361. at active_local_stores. */
  362. struct insn_info * next_local_store;
  363. };
  364. typedef struct insn_info *insn_info_t;
  365. static alloc_pool insn_info_pool;
  366. /* The linked list of stores that are under consideration in this
  367. basic block. */
  368. static insn_info_t active_local_stores;
  369. static int active_local_stores_len;
  370. struct dse_bb_info
  371. {
  372. /* Pointer to the insn info for the last insn in the block. These
  373. are linked so this is how all of the insns are reached. During
  374. scanning this is the current insn being scanned. */
  375. insn_info_t last_insn;
  376. /* The info for the global dataflow problem. */
  377. /* This is set if the transfer function should and in the wild_read
  378. bitmap before applying the kill and gen sets. That vector knocks
  379. out most of the bits in the bitmap and thus speeds up the
  380. operations. */
  381. bool apply_wild_read;
  382. /* The following 4 bitvectors hold information about which positions
  383. of which stores are live or dead. They are indexed by
  384. get_bitmap_index. */
  385. /* The set of store positions that exist in this block before a wild read. */
  386. bitmap gen;
  387. /* The set of load positions that exist in this block above the
  388. same position of a store. */
  389. bitmap kill;
  390. /* The set of stores that reach the top of the block without being
  391. killed by a read.
  392. Do not represent the in if it is all ones. Note that this is
  393. what the bitvector should logically be initialized to for a set
  394. intersection problem. However, like the kill set, this is too
  395. expensive. So initially, the in set will only be created for the
  396. exit block and any block that contains a wild read. */
  397. bitmap in;
  398. /* The set of stores that reach the bottom of the block from it's
  399. successors.
  400. Do not represent the in if it is all ones. Note that this is
  401. what the bitvector should logically be initialized to for a set
  402. intersection problem. However, like the kill and in set, this is
  403. too expensive. So what is done is that the confluence operator
  404. just initializes the vector from one of the out sets of the
  405. successors of the block. */
  406. bitmap out;
  407. /* The following bitvector is indexed by the reg number. It
  408. contains the set of regs that are live at the current instruction
  409. being processed. While it contains info for all of the
  410. registers, only the hard registers are actually examined. It is used
  411. to assure that shift and/or add sequences that are inserted do not
  412. accidentally clobber live hard regs. */
  413. bitmap regs_live;
  414. };
  415. typedef struct dse_bb_info *bb_info_t;
  416. static alloc_pool bb_info_pool;
  417. /* Table to hold all bb_infos. */
  418. static bb_info_t *bb_table;
  419. /* There is a group_info for each rtx base that is used to reference
  420. memory. There are also not many of the rtx bases because they are
  421. very limited in scope. */
  422. struct group_info
  423. {
  424. /* The actual base of the address. */
  425. rtx rtx_base;
  426. /* The sequential id of the base. This allows us to have a
  427. canonical ordering of these that is not based on addresses. */
  428. int id;
  429. /* True if there are any positions that are to be processed
  430. globally. */
  431. bool process_globally;
  432. /* True if the base of this group is either the frame_pointer or
  433. hard_frame_pointer. */
  434. bool frame_related;
  435. /* A mem wrapped around the base pointer for the group in order to do
  436. read dependency. It must be given BLKmode in order to encompass all
  437. the possible offsets from the base. */
  438. rtx base_mem;
  439. /* Canonized version of base_mem's address. */
  440. rtx canon_base_addr;
  441. /* These two sets of two bitmaps are used to keep track of how many
  442. stores are actually referencing that position from this base. We
  443. only do this for rtx bases as this will be used to assign
  444. positions in the bitmaps for the global problem. Bit N is set in
  445. store1 on the first store for offset N. Bit N is set in store2
  446. for the second store to offset N. This is all we need since we
  447. only care about offsets that have two or more stores for them.
  448. The "_n" suffix is for offsets less than 0 and the "_p" suffix is
  449. for 0 and greater offsets.
  450. There is one special case here, for stores into the stack frame,
  451. we will or store1 into store2 before deciding which stores look
  452. at globally. This is because stores to the stack frame that have
  453. no other reads before the end of the function can also be
  454. deleted. */
  455. bitmap store1_n, store1_p, store2_n, store2_p;
  456. /* These bitmaps keep track of offsets in this group escape this function.
  457. An offset escapes if it corresponds to a named variable whose
  458. addressable flag is set. */
  459. bitmap escaped_n, escaped_p;
  460. /* The positions in this bitmap have the same assignments as the in,
  461. out, gen and kill bitmaps. This bitmap is all zeros except for
  462. the positions that are occupied by stores for this group. */
  463. bitmap group_kill;
  464. /* The offset_map is used to map the offsets from this base into
  465. positions in the global bitmaps. It is only created after all of
  466. the all of stores have been scanned and we know which ones we
  467. care about. */
  468. int *offset_map_n, *offset_map_p;
  469. int offset_map_size_n, offset_map_size_p;
  470. };
  471. typedef struct group_info *group_info_t;
  472. typedef const struct group_info *const_group_info_t;
  473. static alloc_pool rtx_group_info_pool;
  474. /* Index into the rtx_group_vec. */
  475. static int rtx_group_next_id;
  476. static vec<group_info_t> rtx_group_vec;
  477. /* This structure holds the set of changes that are being deferred
  478. when removing read operation. See replace_read. */
  479. struct deferred_change
  480. {
  481. /* The mem that is being replaced. */
  482. rtx *loc;
  483. /* The reg it is being replaced with. */
  484. rtx reg;
  485. struct deferred_change *next;
  486. };
  487. typedef struct deferred_change *deferred_change_t;
  488. static alloc_pool deferred_change_pool;
  489. static deferred_change_t deferred_change_list = NULL;
  490. /* The group that holds all of the clear_alias_sets. */
  491. static group_info_t clear_alias_group;
  492. /* The modes of the clear_alias_sets. */
  493. static htab_t clear_alias_mode_table;
  494. /* Hash table element to look up the mode for an alias set. */
  495. struct clear_alias_mode_holder
  496. {
  497. alias_set_type alias_set;
  498. machine_mode mode;
  499. };
  500. /* This is true except if cfun->stdarg -- i.e. we cannot do
  501. this for vararg functions because they play games with the frame. */
  502. static bool stores_off_frame_dead_at_return;
  503. /* Counter for stats. */
  504. static int globally_deleted;
  505. static int locally_deleted;
  506. static int spill_deleted;
  507. static bitmap all_blocks;
  508. /* Locations that are killed by calls in the global phase. */
  509. static bitmap kill_on_calls;
  510. /* The number of bits used in the global bitmaps. */
  511. static unsigned int current_position;
  512. /*----------------------------------------------------------------------------
  513. Zeroth step.
  514. Initialization.
  515. ----------------------------------------------------------------------------*/
  516. /* Find the entry associated with ALIAS_SET. */
  517. static struct clear_alias_mode_holder *
  518. clear_alias_set_lookup (alias_set_type alias_set)
  519. {
  520. struct clear_alias_mode_holder tmp_holder;
  521. void **slot;
  522. tmp_holder.alias_set = alias_set;
  523. slot = htab_find_slot (clear_alias_mode_table, &tmp_holder, NO_INSERT);
  524. gcc_assert (*slot);
  525. return (struct clear_alias_mode_holder *) *slot;
  526. }
  527. /* Hashtable callbacks for maintaining the "bases" field of
  528. store_group_info, given that the addresses are function invariants. */
  529. struct invariant_group_base_hasher : typed_noop_remove <group_info>
  530. {
  531. typedef group_info value_type;
  532. typedef group_info compare_type;
  533. static inline hashval_t hash (const value_type *);
  534. static inline bool equal (const value_type *, const compare_type *);
  535. };
  536. inline bool
  537. invariant_group_base_hasher::equal (const value_type *gi1,
  538. const compare_type *gi2)
  539. {
  540. return rtx_equal_p (gi1->rtx_base, gi2->rtx_base);
  541. }
  542. inline hashval_t
  543. invariant_group_base_hasher::hash (const value_type *gi)
  544. {
  545. int do_not_record;
  546. return hash_rtx (gi->rtx_base, Pmode, &do_not_record, NULL, false);
  547. }
  548. /* Tables of group_info structures, hashed by base value. */
  549. static hash_table<invariant_group_base_hasher> *rtx_group_table;
  550. /* Get the GROUP for BASE. Add a new group if it is not there. */
  551. static group_info_t
  552. get_group_info (rtx base)
  553. {
  554. struct group_info tmp_gi;
  555. group_info_t gi;
  556. group_info **slot;
  557. if (base)
  558. {
  559. /* Find the store_base_info structure for BASE, creating a new one
  560. if necessary. */
  561. tmp_gi.rtx_base = base;
  562. slot = rtx_group_table->find_slot (&tmp_gi, INSERT);
  563. gi = (group_info_t) *slot;
  564. }
  565. else
  566. {
  567. if (!clear_alias_group)
  568. {
  569. clear_alias_group = gi =
  570. (group_info_t) pool_alloc (rtx_group_info_pool);
  571. memset (gi, 0, sizeof (struct group_info));
  572. gi->id = rtx_group_next_id++;
  573. gi->store1_n = BITMAP_ALLOC (&dse_bitmap_obstack);
  574. gi->store1_p = BITMAP_ALLOC (&dse_bitmap_obstack);
  575. gi->store2_n = BITMAP_ALLOC (&dse_bitmap_obstack);
  576. gi->store2_p = BITMAP_ALLOC (&dse_bitmap_obstack);
  577. gi->escaped_p = BITMAP_ALLOC (&dse_bitmap_obstack);
  578. gi->escaped_n = BITMAP_ALLOC (&dse_bitmap_obstack);
  579. gi->group_kill = BITMAP_ALLOC (&dse_bitmap_obstack);
  580. gi->process_globally = false;
  581. gi->offset_map_size_n = 0;
  582. gi->offset_map_size_p = 0;
  583. gi->offset_map_n = NULL;
  584. gi->offset_map_p = NULL;
  585. rtx_group_vec.safe_push (gi);
  586. }
  587. return clear_alias_group;
  588. }
  589. if (gi == NULL)
  590. {
  591. *slot = gi = (group_info_t) pool_alloc (rtx_group_info_pool);
  592. gi->rtx_base = base;
  593. gi->id = rtx_group_next_id++;
  594. gi->base_mem = gen_rtx_MEM (BLKmode, base);
  595. gi->canon_base_addr = canon_rtx (base);
  596. gi->store1_n = BITMAP_ALLOC (&dse_bitmap_obstack);
  597. gi->store1_p = BITMAP_ALLOC (&dse_bitmap_obstack);
  598. gi->store2_n = BITMAP_ALLOC (&dse_bitmap_obstack);
  599. gi->store2_p = BITMAP_ALLOC (&dse_bitmap_obstack);
  600. gi->escaped_p = BITMAP_ALLOC (&dse_bitmap_obstack);
  601. gi->escaped_n = BITMAP_ALLOC (&dse_bitmap_obstack);
  602. gi->group_kill = BITMAP_ALLOC (&dse_bitmap_obstack);
  603. gi->process_globally = false;
  604. gi->frame_related =
  605. (base == frame_pointer_rtx) || (base == hard_frame_pointer_rtx);
  606. gi->offset_map_size_n = 0;
  607. gi->offset_map_size_p = 0;
  608. gi->offset_map_n = NULL;
  609. gi->offset_map_p = NULL;
  610. rtx_group_vec.safe_push (gi);
  611. }
  612. return gi;
  613. }
  614. /* Initialization of data structures. */
  615. static void
  616. dse_step0 (void)
  617. {
  618. locally_deleted = 0;
  619. globally_deleted = 0;
  620. spill_deleted = 0;
  621. bitmap_obstack_initialize (&dse_bitmap_obstack);
  622. gcc_obstack_init (&dse_obstack);
  623. scratch = BITMAP_ALLOC (&reg_obstack);
  624. kill_on_calls = BITMAP_ALLOC (&dse_bitmap_obstack);
  625. rtx_store_info_pool
  626. = create_alloc_pool ("rtx_store_info_pool",
  627. sizeof (struct store_info), 100);
  628. read_info_pool
  629. = create_alloc_pool ("read_info_pool",
  630. sizeof (struct read_info), 100);
  631. insn_info_pool
  632. = create_alloc_pool ("insn_info_pool",
  633. sizeof (struct insn_info), 100);
  634. bb_info_pool
  635. = create_alloc_pool ("bb_info_pool",
  636. sizeof (struct dse_bb_info), 100);
  637. rtx_group_info_pool
  638. = create_alloc_pool ("rtx_group_info_pool",
  639. sizeof (struct group_info), 100);
  640. deferred_change_pool
  641. = create_alloc_pool ("deferred_change_pool",
  642. sizeof (struct deferred_change), 10);
  643. rtx_group_table = new hash_table<invariant_group_base_hasher> (11);
  644. bb_table = XNEWVEC (bb_info_t, last_basic_block_for_fn (cfun));
  645. rtx_group_next_id = 0;
  646. stores_off_frame_dead_at_return = !cfun->stdarg;
  647. init_alias_analysis ();
  648. clear_alias_group = NULL;
  649. }
  650. /*----------------------------------------------------------------------------
  651. First step.
  652. Scan all of the insns. Any random ordering of the blocks is fine.
  653. Each block is scanned in forward order to accommodate cselib which
  654. is used to remove stores with non-constant bases.
  655. ----------------------------------------------------------------------------*/
  656. /* Delete all of the store_info recs from INSN_INFO. */
  657. static void
  658. free_store_info (insn_info_t insn_info)
  659. {
  660. store_info_t store_info = insn_info->store_rec;
  661. while (store_info)
  662. {
  663. store_info_t next = store_info->next;
  664. if (store_info->is_large)
  665. BITMAP_FREE (store_info->positions_needed.large.bmap);
  666. if (store_info->cse_base)
  667. pool_free (cse_store_info_pool, store_info);
  668. else
  669. pool_free (rtx_store_info_pool, store_info);
  670. store_info = next;
  671. }
  672. insn_info->cannot_delete = true;
  673. insn_info->contains_cselib_groups = false;
  674. insn_info->store_rec = NULL;
  675. }
  676. typedef struct
  677. {
  678. rtx_insn *first, *current;
  679. regset fixed_regs_live;
  680. bool failure;
  681. } note_add_store_info;
  682. /* Callback for emit_inc_dec_insn_before via note_stores.
  683. Check if a register is clobbered which is live afterwards. */
  684. static void
  685. note_add_store (rtx loc, const_rtx expr ATTRIBUTE_UNUSED, void *data)
  686. {
  687. rtx_insn *insn;
  688. note_add_store_info *info = (note_add_store_info *) data;
  689. int r, n;
  690. if (!REG_P (loc))
  691. return;
  692. /* If this register is referenced by the current or an earlier insn,
  693. that's OK. E.g. this applies to the register that is being incremented
  694. with this addition. */
  695. for (insn = info->first;
  696. insn != NEXT_INSN (info->current);
  697. insn = NEXT_INSN (insn))
  698. if (reg_referenced_p (loc, PATTERN (insn)))
  699. return;
  700. /* If we come here, we have a clobber of a register that's only OK
  701. if that register is not live. If we don't have liveness information
  702. available, fail now. */
  703. if (!info->fixed_regs_live)
  704. {
  705. info->failure = true;
  706. return;
  707. }
  708. /* Now check if this is a live fixed register. */
  709. r = REGNO (loc);
  710. n = hard_regno_nregs[r][GET_MODE (loc)];
  711. while (--n >= 0)
  712. if (REGNO_REG_SET_P (info->fixed_regs_live, r+n))
  713. info->failure = true;
  714. }
  715. /* Callback for for_each_inc_dec that emits an INSN that sets DEST to
  716. SRC + SRCOFF before insn ARG. */
  717. static int
  718. emit_inc_dec_insn_before (rtx mem ATTRIBUTE_UNUSED,
  719. rtx op ATTRIBUTE_UNUSED,
  720. rtx dest, rtx src, rtx srcoff, void *arg)
  721. {
  722. insn_info_t insn_info = (insn_info_t) arg;
  723. rtx_insn *insn = insn_info->insn, *new_insn, *cur;
  724. note_add_store_info info;
  725. /* We can reuse all operands without copying, because we are about
  726. to delete the insn that contained it. */
  727. if (srcoff)
  728. {
  729. start_sequence ();
  730. emit_insn (gen_add3_insn (dest, src, srcoff));
  731. new_insn = get_insns ();
  732. end_sequence ();
  733. }
  734. else
  735. new_insn = as_a <rtx_insn *> (gen_move_insn (dest, src));
  736. info.first = new_insn;
  737. info.fixed_regs_live = insn_info->fixed_regs_live;
  738. info.failure = false;
  739. for (cur = new_insn; cur; cur = NEXT_INSN (cur))
  740. {
  741. info.current = cur;
  742. note_stores (PATTERN (cur), note_add_store, &info);
  743. }
  744. /* If a failure was flagged above, return 1 so that for_each_inc_dec will
  745. return it immediately, communicating the failure to its caller. */
  746. if (info.failure)
  747. return 1;
  748. emit_insn_before (new_insn, insn);
  749. return 0;
  750. }
  751. /* Before we delete INSN_INFO->INSN, make sure that the auto inc/dec, if it
  752. is there, is split into a separate insn.
  753. Return true on success (or if there was nothing to do), false on failure. */
  754. static bool
  755. check_for_inc_dec_1 (insn_info_t insn_info)
  756. {
  757. rtx_insn *insn = insn_info->insn;
  758. rtx note = find_reg_note (insn, REG_INC, NULL_RTX);
  759. if (note)
  760. return for_each_inc_dec (PATTERN (insn), emit_inc_dec_insn_before,
  761. insn_info) == 0;
  762. return true;
  763. }
  764. /* Entry point for postreload. If you work on reload_cse, or you need this
  765. anywhere else, consider if you can provide register liveness information
  766. and add a parameter to this function so that it can be passed down in
  767. insn_info.fixed_regs_live. */
  768. bool
  769. check_for_inc_dec (rtx_insn *insn)
  770. {
  771. struct insn_info insn_info;
  772. rtx note;
  773. insn_info.insn = insn;
  774. insn_info.fixed_regs_live = NULL;
  775. note = find_reg_note (insn, REG_INC, NULL_RTX);
  776. if (note)
  777. return for_each_inc_dec (PATTERN (insn), emit_inc_dec_insn_before,
  778. &insn_info) == 0;
  779. return true;
  780. }
  781. /* Delete the insn and free all of the fields inside INSN_INFO. */
  782. static void
  783. delete_dead_store_insn (insn_info_t insn_info)
  784. {
  785. read_info_t read_info;
  786. if (!dbg_cnt (dse))
  787. return;
  788. if (!check_for_inc_dec_1 (insn_info))
  789. return;
  790. if (dump_file && (dump_flags & TDF_DETAILS))
  791. {
  792. fprintf (dump_file, "Locally deleting insn %d ",
  793. INSN_UID (insn_info->insn));
  794. if (insn_info->store_rec->alias_set)
  795. fprintf (dump_file, "alias set %d\n",
  796. (int) insn_info->store_rec->alias_set);
  797. else
  798. fprintf (dump_file, "\n");
  799. }
  800. free_store_info (insn_info);
  801. read_info = insn_info->read_rec;
  802. while (read_info)
  803. {
  804. read_info_t next = read_info->next;
  805. pool_free (read_info_pool, read_info);
  806. read_info = next;
  807. }
  808. insn_info->read_rec = NULL;
  809. delete_insn (insn_info->insn);
  810. locally_deleted++;
  811. insn_info->insn = NULL;
  812. insn_info->wild_read = false;
  813. }
  814. /* Return whether DECL, a local variable, can possibly escape the current
  815. function scope. */
  816. static bool
  817. local_variable_can_escape (tree decl)
  818. {
  819. if (TREE_ADDRESSABLE (decl))
  820. return true;
  821. /* If this is a partitioned variable, we need to consider all the variables
  822. in the partition. This is necessary because a store into one of them can
  823. be replaced with a store into another and this may not change the outcome
  824. of the escape analysis. */
  825. if (cfun->gimple_df->decls_to_pointers != NULL)
  826. {
  827. tree *namep = cfun->gimple_df->decls_to_pointers->get (decl);
  828. if (namep)
  829. return TREE_ADDRESSABLE (*namep);
  830. }
  831. return false;
  832. }
  833. /* Return whether EXPR can possibly escape the current function scope. */
  834. static bool
  835. can_escape (tree expr)
  836. {
  837. tree base;
  838. if (!expr)
  839. return true;
  840. base = get_base_address (expr);
  841. if (DECL_P (base)
  842. && !may_be_aliased (base)
  843. && !(TREE_CODE (base) == VAR_DECL
  844. && !DECL_EXTERNAL (base)
  845. && !TREE_STATIC (base)
  846. && local_variable_can_escape (base)))
  847. return false;
  848. return true;
  849. }
  850. /* Set the store* bitmaps offset_map_size* fields in GROUP based on
  851. OFFSET and WIDTH. */
  852. static void
  853. set_usage_bits (group_info_t group, HOST_WIDE_INT offset, HOST_WIDE_INT width,
  854. tree expr)
  855. {
  856. HOST_WIDE_INT i;
  857. bool expr_escapes = can_escape (expr);
  858. if (offset > -MAX_OFFSET && offset + width < MAX_OFFSET)
  859. for (i=offset; i<offset+width; i++)
  860. {
  861. bitmap store1;
  862. bitmap store2;
  863. bitmap escaped;
  864. int ai;
  865. if (i < 0)
  866. {
  867. store1 = group->store1_n;
  868. store2 = group->store2_n;
  869. escaped = group->escaped_n;
  870. ai = -i;
  871. }
  872. else
  873. {
  874. store1 = group->store1_p;
  875. store2 = group->store2_p;
  876. escaped = group->escaped_p;
  877. ai = i;
  878. }
  879. if (!bitmap_set_bit (store1, ai))
  880. bitmap_set_bit (store2, ai);
  881. else
  882. {
  883. if (i < 0)
  884. {
  885. if (group->offset_map_size_n < ai)
  886. group->offset_map_size_n = ai;
  887. }
  888. else
  889. {
  890. if (group->offset_map_size_p < ai)
  891. group->offset_map_size_p = ai;
  892. }
  893. }
  894. if (expr_escapes)
  895. bitmap_set_bit (escaped, ai);
  896. }
  897. }
  898. static void
  899. reset_active_stores (void)
  900. {
  901. active_local_stores = NULL;
  902. active_local_stores_len = 0;
  903. }
  904. /* Free all READ_REC of the LAST_INSN of BB_INFO. */
  905. static void
  906. free_read_records (bb_info_t bb_info)
  907. {
  908. insn_info_t insn_info = bb_info->last_insn;
  909. read_info_t *ptr = &insn_info->read_rec;
  910. while (*ptr)
  911. {
  912. read_info_t next = (*ptr)->next;
  913. if ((*ptr)->alias_set == 0)
  914. {
  915. pool_free (read_info_pool, *ptr);
  916. *ptr = next;
  917. }
  918. else
  919. ptr = &(*ptr)->next;
  920. }
  921. }
  922. /* Set the BB_INFO so that the last insn is marked as a wild read. */
  923. static void
  924. add_wild_read (bb_info_t bb_info)
  925. {
  926. insn_info_t insn_info = bb_info->last_insn;
  927. insn_info->wild_read = true;
  928. free_read_records (bb_info);
  929. reset_active_stores ();
  930. }
  931. /* Set the BB_INFO so that the last insn is marked as a wild read of
  932. non-frame locations. */
  933. static void
  934. add_non_frame_wild_read (bb_info_t bb_info)
  935. {
  936. insn_info_t insn_info = bb_info->last_insn;
  937. insn_info->non_frame_wild_read = true;
  938. free_read_records (bb_info);
  939. reset_active_stores ();
  940. }
  941. /* Return true if X is a constant or one of the registers that behave
  942. as a constant over the life of a function. This is equivalent to
  943. !rtx_varies_p for memory addresses. */
  944. static bool
  945. const_or_frame_p (rtx x)
  946. {
  947. if (CONSTANT_P (x))
  948. return true;
  949. if (GET_CODE (x) == REG)
  950. {
  951. /* Note that we have to test for the actual rtx used for the frame
  952. and arg pointers and not just the register number in case we have
  953. eliminated the frame and/or arg pointer and are using it
  954. for pseudos. */
  955. if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
  956. /* The arg pointer varies if it is not a fixed register. */
  957. || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM])
  958. || x == pic_offset_table_rtx)
  959. return true;
  960. return false;
  961. }
  962. return false;
  963. }
  964. /* Take all reasonable action to put the address of MEM into the form
  965. that we can do analysis on.
  966. The gold standard is to get the address into the form: address +
  967. OFFSET where address is something that rtx_varies_p considers a
  968. constant. When we can get the address in this form, we can do
  969. global analysis on it. Note that for constant bases, address is
  970. not actually returned, only the group_id. The address can be
  971. obtained from that.
  972. If that fails, we try cselib to get a value we can at least use
  973. locally. If that fails we return false.
  974. The GROUP_ID is set to -1 for cselib bases and the index of the
  975. group for non_varying bases.
  976. FOR_READ is true if this is a mem read and false if not. */
  977. static bool
  978. canon_address (rtx mem,
  979. alias_set_type *alias_set_out,
  980. int *group_id,
  981. HOST_WIDE_INT *offset,
  982. cselib_val **base)
  983. {
  984. machine_mode address_mode = get_address_mode (mem);
  985. rtx mem_address = XEXP (mem, 0);
  986. rtx expanded_address, address;
  987. int expanded;
  988. *alias_set_out = 0;
  989. cselib_lookup (mem_address, address_mode, 1, GET_MODE (mem));
  990. if (dump_file && (dump_flags & TDF_DETAILS))
  991. {
  992. fprintf (dump_file, " mem: ");
  993. print_inline_rtx (dump_file, mem_address, 0);
  994. fprintf (dump_file, "\n");
  995. }
  996. /* First see if just canon_rtx (mem_address) is const or frame,
  997. if not, try cselib_expand_value_rtx and call canon_rtx on that. */
  998. address = NULL_RTX;
  999. for (expanded = 0; expanded < 2; expanded++)
  1000. {
  1001. if (expanded)
  1002. {
  1003. /* Use cselib to replace all of the reg references with the full
  1004. expression. This will take care of the case where we have
  1005. r_x = base + offset;
  1006. val = *r_x;
  1007. by making it into
  1008. val = *(base + offset); */
  1009. expanded_address = cselib_expand_value_rtx (mem_address,
  1010. scratch, 5);
  1011. /* If this fails, just go with the address from first
  1012. iteration. */
  1013. if (!expanded_address)
  1014. break;
  1015. }
  1016. else
  1017. expanded_address = mem_address;
  1018. /* Split the address into canonical BASE + OFFSET terms. */
  1019. address = canon_rtx (expanded_address);
  1020. *offset = 0;
  1021. if (dump_file && (dump_flags & TDF_DETAILS))
  1022. {
  1023. if (expanded)
  1024. {
  1025. fprintf (dump_file, "\n after cselib_expand address: ");
  1026. print_inline_rtx (dump_file, expanded_address, 0);
  1027. fprintf (dump_file, "\n");
  1028. }
  1029. fprintf (dump_file, "\n after canon_rtx address: ");
  1030. print_inline_rtx (dump_file, address, 0);
  1031. fprintf (dump_file, "\n");
  1032. }
  1033. if (GET_CODE (address) == CONST)
  1034. address = XEXP (address, 0);
  1035. if (GET_CODE (address) == PLUS
  1036. && CONST_INT_P (XEXP (address, 1)))
  1037. {
  1038. *offset = INTVAL (XEXP (address, 1));
  1039. address = XEXP (address, 0);
  1040. }
  1041. if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (mem))
  1042. && const_or_frame_p (address))
  1043. {
  1044. group_info_t group = get_group_info (address);
  1045. if (dump_file && (dump_flags & TDF_DETAILS))
  1046. fprintf (dump_file, " gid=%d offset=%d \n",
  1047. group->id, (int)*offset);
  1048. *base = NULL;
  1049. *group_id = group->id;
  1050. return true;
  1051. }
  1052. }
  1053. *base = cselib_lookup (address, address_mode, true, GET_MODE (mem));
  1054. *group_id = -1;
  1055. if (*base == NULL)
  1056. {
  1057. if (dump_file && (dump_flags & TDF_DETAILS))
  1058. fprintf (dump_file, " no cselib val - should be a wild read.\n");
  1059. return false;
  1060. }
  1061. if (dump_file && (dump_flags & TDF_DETAILS))
  1062. fprintf (dump_file, " varying cselib base=%u:%u offset = %d\n",
  1063. (*base)->uid, (*base)->hash, (int)*offset);
  1064. return true;
  1065. }
  1066. /* Clear the rhs field from the active_local_stores array. */
  1067. static void
  1068. clear_rhs_from_active_local_stores (void)
  1069. {
  1070. insn_info_t ptr = active_local_stores;
  1071. while (ptr)
  1072. {
  1073. store_info_t store_info = ptr->store_rec;
  1074. /* Skip the clobbers. */
  1075. while (!store_info->is_set)
  1076. store_info = store_info->next;
  1077. store_info->rhs = NULL;
  1078. store_info->const_rhs = NULL;
  1079. ptr = ptr->next_local_store;
  1080. }
  1081. }
  1082. /* Mark byte POS bytes from the beginning of store S_INFO as unneeded. */
  1083. static inline void
  1084. set_position_unneeded (store_info_t s_info, int pos)
  1085. {
  1086. if (__builtin_expect (s_info->is_large, false))
  1087. {
  1088. if (bitmap_set_bit (s_info->positions_needed.large.bmap, pos))
  1089. s_info->positions_needed.large.count++;
  1090. }
  1091. else
  1092. s_info->positions_needed.small_bitmask
  1093. &= ~(((unsigned HOST_WIDE_INT) 1) << pos);
  1094. }
  1095. /* Mark the whole store S_INFO as unneeded. */
  1096. static inline void
  1097. set_all_positions_unneeded (store_info_t s_info)
  1098. {
  1099. if (__builtin_expect (s_info->is_large, false))
  1100. {
  1101. int pos, end = s_info->end - s_info->begin;
  1102. for (pos = 0; pos < end; pos++)
  1103. bitmap_set_bit (s_info->positions_needed.large.bmap, pos);
  1104. s_info->positions_needed.large.count = end;
  1105. }
  1106. else
  1107. s_info->positions_needed.small_bitmask = (unsigned HOST_WIDE_INT) 0;
  1108. }
  1109. /* Return TRUE if any bytes from S_INFO store are needed. */
  1110. static inline bool
  1111. any_positions_needed_p (store_info_t s_info)
  1112. {
  1113. if (__builtin_expect (s_info->is_large, false))
  1114. return (s_info->positions_needed.large.count
  1115. < s_info->end - s_info->begin);
  1116. else
  1117. return (s_info->positions_needed.small_bitmask
  1118. != (unsigned HOST_WIDE_INT) 0);
  1119. }
  1120. /* Return TRUE if all bytes START through START+WIDTH-1 from S_INFO
  1121. store are needed. */
  1122. static inline bool
  1123. all_positions_needed_p (store_info_t s_info, int start, int width)
  1124. {
  1125. if (__builtin_expect (s_info->is_large, false))
  1126. {
  1127. int end = start + width;
  1128. while (start < end)
  1129. if (bitmap_bit_p (s_info->positions_needed.large.bmap, start++))
  1130. return false;
  1131. return true;
  1132. }
  1133. else
  1134. {
  1135. unsigned HOST_WIDE_INT mask = lowpart_bitmask (width) << start;
  1136. return (s_info->positions_needed.small_bitmask & mask) == mask;
  1137. }
  1138. }
  1139. static rtx get_stored_val (store_info_t, machine_mode, HOST_WIDE_INT,
  1140. HOST_WIDE_INT, basic_block, bool);
  1141. /* BODY is an instruction pattern that belongs to INSN. Return 1 if
  1142. there is a candidate store, after adding it to the appropriate
  1143. local store group if so. */
  1144. static int
  1145. record_store (rtx body, bb_info_t bb_info)
  1146. {
  1147. rtx mem, rhs, const_rhs, mem_addr;
  1148. HOST_WIDE_INT offset = 0;
  1149. HOST_WIDE_INT width = 0;
  1150. alias_set_type spill_alias_set;
  1151. insn_info_t insn_info = bb_info->last_insn;
  1152. store_info_t store_info = NULL;
  1153. int group_id;
  1154. cselib_val *base = NULL;
  1155. insn_info_t ptr, last, redundant_reason;
  1156. bool store_is_unused;
  1157. if (GET_CODE (body) != SET && GET_CODE (body) != CLOBBER)
  1158. return 0;
  1159. mem = SET_DEST (body);
  1160. /* If this is not used, then this cannot be used to keep the insn
  1161. from being deleted. On the other hand, it does provide something
  1162. that can be used to prove that another store is dead. */
  1163. store_is_unused
  1164. = (find_reg_note (insn_info->insn, REG_UNUSED, mem) != NULL);
  1165. /* Check whether that value is a suitable memory location. */
  1166. if (!MEM_P (mem))
  1167. {
  1168. /* If the set or clobber is unused, then it does not effect our
  1169. ability to get rid of the entire insn. */
  1170. if (!store_is_unused)
  1171. insn_info->cannot_delete = true;
  1172. return 0;
  1173. }
  1174. /* At this point we know mem is a mem. */
  1175. if (GET_MODE (mem) == BLKmode)
  1176. {
  1177. if (GET_CODE (XEXP (mem, 0)) == SCRATCH)
  1178. {
  1179. if (dump_file && (dump_flags & TDF_DETAILS))
  1180. fprintf (dump_file, " adding wild read for (clobber (mem:BLK (scratch))\n");
  1181. add_wild_read (bb_info);
  1182. insn_info->cannot_delete = true;
  1183. return 0;
  1184. }
  1185. /* Handle (set (mem:BLK (addr) [... S36 ...]) (const_int 0))
  1186. as memset (addr, 0, 36); */
  1187. else if (!MEM_SIZE_KNOWN_P (mem)
  1188. || MEM_SIZE (mem) <= 0
  1189. || MEM_SIZE (mem) > MAX_OFFSET
  1190. || GET_CODE (body) != SET
  1191. || !CONST_INT_P (SET_SRC (body)))
  1192. {
  1193. if (!store_is_unused)
  1194. {
  1195. /* If the set or clobber is unused, then it does not effect our
  1196. ability to get rid of the entire insn. */
  1197. insn_info->cannot_delete = true;
  1198. clear_rhs_from_active_local_stores ();
  1199. }
  1200. return 0;
  1201. }
  1202. }
  1203. /* We can still process a volatile mem, we just cannot delete it. */
  1204. if (MEM_VOLATILE_P (mem))
  1205. insn_info->cannot_delete = true;
  1206. if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
  1207. {
  1208. clear_rhs_from_active_local_stores ();
  1209. return 0;
  1210. }
  1211. if (GET_MODE (mem) == BLKmode)
  1212. width = MEM_SIZE (mem);
  1213. else
  1214. width = GET_MODE_SIZE (GET_MODE (mem));
  1215. if (spill_alias_set)
  1216. {
  1217. bitmap store1 = clear_alias_group->store1_p;
  1218. bitmap store2 = clear_alias_group->store2_p;
  1219. gcc_assert (GET_MODE (mem) != BLKmode);
  1220. if (!bitmap_set_bit (store1, spill_alias_set))
  1221. bitmap_set_bit (store2, spill_alias_set);
  1222. if (clear_alias_group->offset_map_size_p < spill_alias_set)
  1223. clear_alias_group->offset_map_size_p = spill_alias_set;
  1224. store_info = (store_info_t) pool_alloc (rtx_store_info_pool);
  1225. if (dump_file && (dump_flags & TDF_DETAILS))
  1226. fprintf (dump_file, " processing spill store %d(%s)\n",
  1227. (int) spill_alias_set, GET_MODE_NAME (GET_MODE (mem)));
  1228. }
  1229. else if (group_id >= 0)
  1230. {
  1231. /* In the restrictive case where the base is a constant or the
  1232. frame pointer we can do global analysis. */
  1233. group_info_t group
  1234. = rtx_group_vec[group_id];
  1235. tree expr = MEM_EXPR (mem);
  1236. store_info = (store_info_t) pool_alloc (rtx_store_info_pool);
  1237. set_usage_bits (group, offset, width, expr);
  1238. if (dump_file && (dump_flags & TDF_DETAILS))
  1239. fprintf (dump_file, " processing const base store gid=%d[%d..%d)\n",
  1240. group_id, (int)offset, (int)(offset+width));
  1241. }
  1242. else
  1243. {
  1244. if (may_be_sp_based_p (XEXP (mem, 0)))
  1245. insn_info->stack_pointer_based = true;
  1246. insn_info->contains_cselib_groups = true;
  1247. store_info = (store_info_t) pool_alloc (cse_store_info_pool);
  1248. group_id = -1;
  1249. if (dump_file && (dump_flags & TDF_DETAILS))
  1250. fprintf (dump_file, " processing cselib store [%d..%d)\n",
  1251. (int)offset, (int)(offset+width));
  1252. }
  1253. const_rhs = rhs = NULL_RTX;
  1254. if (GET_CODE (body) == SET
  1255. /* No place to keep the value after ra. */
  1256. && !reload_completed
  1257. && (REG_P (SET_SRC (body))
  1258. || GET_CODE (SET_SRC (body)) == SUBREG
  1259. || CONSTANT_P (SET_SRC (body)))
  1260. && !MEM_VOLATILE_P (mem)
  1261. /* Sometimes the store and reload is used for truncation and
  1262. rounding. */
  1263. && !(FLOAT_MODE_P (GET_MODE (mem)) && (flag_float_store)))
  1264. {
  1265. rhs = SET_SRC (body);
  1266. if (CONSTANT_P (rhs))
  1267. const_rhs = rhs;
  1268. else if (body == PATTERN (insn_info->insn))
  1269. {
  1270. rtx tem = find_reg_note (insn_info->insn, REG_EQUAL, NULL_RTX);
  1271. if (tem && CONSTANT_P (XEXP (tem, 0)))
  1272. const_rhs = XEXP (tem, 0);
  1273. }
  1274. if (const_rhs == NULL_RTX && REG_P (rhs))
  1275. {
  1276. rtx tem = cselib_expand_value_rtx (rhs, scratch, 5);
  1277. if (tem && CONSTANT_P (tem))
  1278. const_rhs = tem;
  1279. }
  1280. }
  1281. /* Check to see if this stores causes some other stores to be
  1282. dead. */
  1283. ptr = active_local_stores;
  1284. last = NULL;
  1285. redundant_reason = NULL;
  1286. mem = canon_rtx (mem);
  1287. /* For alias_set != 0 canon_true_dependence should be never called. */
  1288. if (spill_alias_set)
  1289. mem_addr = NULL_RTX;
  1290. else
  1291. {
  1292. if (group_id < 0)
  1293. mem_addr = base->val_rtx;
  1294. else
  1295. {
  1296. group_info_t group
  1297. = rtx_group_vec[group_id];
  1298. mem_addr = group->canon_base_addr;
  1299. }
  1300. /* get_addr can only handle VALUE but cannot handle expr like:
  1301. VALUE + OFFSET, so call get_addr to get original addr for
  1302. mem_addr before plus_constant. */
  1303. mem_addr = get_addr (mem_addr);
  1304. if (offset)
  1305. mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset);
  1306. }
  1307. while (ptr)
  1308. {
  1309. insn_info_t next = ptr->next_local_store;
  1310. store_info_t s_info = ptr->store_rec;
  1311. bool del = true;
  1312. /* Skip the clobbers. We delete the active insn if this insn
  1313. shadows the set. To have been put on the active list, it
  1314. has exactly on set. */
  1315. while (!s_info->is_set)
  1316. s_info = s_info->next;
  1317. if (s_info->alias_set != spill_alias_set)
  1318. del = false;
  1319. else if (s_info->alias_set)
  1320. {
  1321. struct clear_alias_mode_holder *entry
  1322. = clear_alias_set_lookup (s_info->alias_set);
  1323. /* Generally, spills cannot be processed if and of the
  1324. references to the slot have a different mode. But if
  1325. we are in the same block and mode is exactly the same
  1326. between this store and one before in the same block,
  1327. we can still delete it. */
  1328. if ((GET_MODE (mem) == GET_MODE (s_info->mem))
  1329. && (GET_MODE (mem) == entry->mode))
  1330. {
  1331. del = true;
  1332. set_all_positions_unneeded (s_info);
  1333. }
  1334. if (dump_file && (dump_flags & TDF_DETAILS))
  1335. fprintf (dump_file, " trying spill store in insn=%d alias_set=%d\n",
  1336. INSN_UID (ptr->insn), (int) s_info->alias_set);
  1337. }
  1338. else if ((s_info->group_id == group_id)
  1339. && (s_info->cse_base == base))
  1340. {
  1341. HOST_WIDE_INT i;
  1342. if (dump_file && (dump_flags & TDF_DETAILS))
  1343. fprintf (dump_file, " trying store in insn=%d gid=%d[%d..%d)\n",
  1344. INSN_UID (ptr->insn), s_info->group_id,
  1345. (int)s_info->begin, (int)s_info->end);
  1346. /* Even if PTR won't be eliminated as unneeded, if both
  1347. PTR and this insn store the same constant value, we might
  1348. eliminate this insn instead. */
  1349. if (s_info->const_rhs
  1350. && const_rhs
  1351. && offset >= s_info->begin
  1352. && offset + width <= s_info->end
  1353. && all_positions_needed_p (s_info, offset - s_info->begin,
  1354. width))
  1355. {
  1356. if (GET_MODE (mem) == BLKmode)
  1357. {
  1358. if (GET_MODE (s_info->mem) == BLKmode
  1359. && s_info->const_rhs == const_rhs)
  1360. redundant_reason = ptr;
  1361. }
  1362. else if (s_info->const_rhs == const0_rtx
  1363. && const_rhs == const0_rtx)
  1364. redundant_reason = ptr;
  1365. else
  1366. {
  1367. rtx val;
  1368. start_sequence ();
  1369. val = get_stored_val (s_info, GET_MODE (mem),
  1370. offset, offset + width,
  1371. BLOCK_FOR_INSN (insn_info->insn),
  1372. true);
  1373. if (get_insns () != NULL)
  1374. val = NULL_RTX;
  1375. end_sequence ();
  1376. if (val && rtx_equal_p (val, const_rhs))
  1377. redundant_reason = ptr;
  1378. }
  1379. }
  1380. for (i = MAX (offset, s_info->begin);
  1381. i < offset + width && i < s_info->end;
  1382. i++)
  1383. set_position_unneeded (s_info, i - s_info->begin);
  1384. }
  1385. else if (s_info->rhs)
  1386. /* Need to see if it is possible for this store to overwrite
  1387. the value of store_info. If it is, set the rhs to NULL to
  1388. keep it from being used to remove a load. */
  1389. {
  1390. if (canon_true_dependence (s_info->mem,
  1391. GET_MODE (s_info->mem),
  1392. s_info->mem_addr,
  1393. mem, mem_addr))
  1394. {
  1395. s_info->rhs = NULL;
  1396. s_info->const_rhs = NULL;
  1397. }
  1398. }
  1399. /* An insn can be deleted if every position of every one of
  1400. its s_infos is zero. */
  1401. if (any_positions_needed_p (s_info))
  1402. del = false;
  1403. if (del)
  1404. {
  1405. insn_info_t insn_to_delete = ptr;
  1406. active_local_stores_len--;
  1407. if (last)
  1408. last->next_local_store = ptr->next_local_store;
  1409. else
  1410. active_local_stores = ptr->next_local_store;
  1411. if (!insn_to_delete->cannot_delete)
  1412. delete_dead_store_insn (insn_to_delete);
  1413. }
  1414. else
  1415. last = ptr;
  1416. ptr = next;
  1417. }
  1418. /* Finish filling in the store_info. */
  1419. store_info->next = insn_info->store_rec;
  1420. insn_info->store_rec = store_info;
  1421. store_info->mem = mem;
  1422. store_info->alias_set = spill_alias_set;
  1423. store_info->mem_addr = mem_addr;
  1424. store_info->cse_base = base;
  1425. if (width > HOST_BITS_PER_WIDE_INT)
  1426. {
  1427. store_info->is_large = true;
  1428. store_info->positions_needed.large.count = 0;
  1429. store_info->positions_needed.large.bmap = BITMAP_ALLOC (&dse_bitmap_obstack);
  1430. }
  1431. else
  1432. {
  1433. store_info->is_large = false;
  1434. store_info->positions_needed.small_bitmask = lowpart_bitmask (width);
  1435. }
  1436. store_info->group_id = group_id;
  1437. store_info->begin = offset;
  1438. store_info->end = offset + width;
  1439. store_info->is_set = GET_CODE (body) == SET;
  1440. store_info->rhs = rhs;
  1441. store_info->const_rhs = const_rhs;
  1442. store_info->redundant_reason = redundant_reason;
  1443. /* If this is a clobber, we return 0. We will only be able to
  1444. delete this insn if there is only one store USED store, but we
  1445. can use the clobber to delete other stores earlier. */
  1446. return store_info->is_set ? 1 : 0;
  1447. }
  1448. static void
  1449. dump_insn_info (const char * start, insn_info_t insn_info)
  1450. {
  1451. fprintf (dump_file, "%s insn=%d %s\n", start,
  1452. INSN_UID (insn_info->insn),
  1453. insn_info->store_rec ? "has store" : "naked");
  1454. }
  1455. /* If the modes are different and the value's source and target do not
  1456. line up, we need to extract the value from lower part of the rhs of
  1457. the store, shift it, and then put it into a form that can be shoved
  1458. into the read_insn. This function generates a right SHIFT of a
  1459. value that is at least ACCESS_SIZE bytes wide of READ_MODE. The
  1460. shift sequence is returned or NULL if we failed to find a
  1461. shift. */
  1462. static rtx
  1463. find_shift_sequence (int access_size,
  1464. store_info_t store_info,
  1465. machine_mode read_mode,
  1466. int shift, bool speed, bool require_cst)
  1467. {
  1468. machine_mode store_mode = GET_MODE (store_info->mem);
  1469. machine_mode new_mode;
  1470. rtx read_reg = NULL;
  1471. /* Some machines like the x86 have shift insns for each size of
  1472. operand. Other machines like the ppc or the ia-64 may only have
  1473. shift insns that shift values within 32 or 64 bit registers.
  1474. This loop tries to find the smallest shift insn that will right
  1475. justify the value we want to read but is available in one insn on
  1476. the machine. */
  1477. for (new_mode = smallest_mode_for_size (access_size * BITS_PER_UNIT,
  1478. MODE_INT);
  1479. GET_MODE_BITSIZE (new_mode) <= BITS_PER_WORD;
  1480. new_mode = GET_MODE_WIDER_MODE (new_mode))
  1481. {
  1482. rtx target, new_reg, new_lhs;
  1483. rtx_insn *shift_seq, *insn;
  1484. int cost;
  1485. /* If a constant was stored into memory, try to simplify it here,
  1486. otherwise the cost of the shift might preclude this optimization
  1487. e.g. at -Os, even when no actual shift will be needed. */
  1488. if (store_info->const_rhs)
  1489. {
  1490. unsigned int byte = subreg_lowpart_offset (new_mode, store_mode);
  1491. rtx ret = simplify_subreg (new_mode, store_info->const_rhs,
  1492. store_mode, byte);
  1493. if (ret && CONSTANT_P (ret))
  1494. {
  1495. ret = simplify_const_binary_operation (LSHIFTRT, new_mode,
  1496. ret, GEN_INT (shift));
  1497. if (ret && CONSTANT_P (ret))
  1498. {
  1499. byte = subreg_lowpart_offset (read_mode, new_mode);
  1500. ret = simplify_subreg (read_mode, ret, new_mode, byte);
  1501. if (ret && CONSTANT_P (ret)
  1502. && set_src_cost (ret, speed) <= COSTS_N_INSNS (1))
  1503. return ret;
  1504. }
  1505. }
  1506. }
  1507. if (require_cst)
  1508. return NULL_RTX;
  1509. /* Try a wider mode if truncating the store mode to NEW_MODE
  1510. requires a real instruction. */
  1511. if (GET_MODE_BITSIZE (new_mode) < GET_MODE_BITSIZE (store_mode)
  1512. && !TRULY_NOOP_TRUNCATION_MODES_P (new_mode, store_mode))
  1513. continue;
  1514. /* Also try a wider mode if the necessary punning is either not
  1515. desirable or not possible. */
  1516. if (!CONSTANT_P (store_info->rhs)
  1517. && !MODES_TIEABLE_P (new_mode, store_mode))
  1518. continue;
  1519. new_reg = gen_reg_rtx (new_mode);
  1520. start_sequence ();
  1521. /* In theory we could also check for an ashr. Ian Taylor knows
  1522. of one dsp where the cost of these two was not the same. But
  1523. this really is a rare case anyway. */
  1524. target = expand_binop (new_mode, lshr_optab, new_reg,
  1525. GEN_INT (shift), new_reg, 1, OPTAB_DIRECT);
  1526. shift_seq = get_insns ();
  1527. end_sequence ();
  1528. if (target != new_reg || shift_seq == NULL)
  1529. continue;
  1530. cost = 0;
  1531. for (insn = shift_seq; insn != NULL_RTX; insn = NEXT_INSN (insn))
  1532. if (INSN_P (insn))
  1533. cost += insn_rtx_cost (PATTERN (insn), speed);
  1534. /* The computation up to here is essentially independent
  1535. of the arguments and could be precomputed. It may
  1536. not be worth doing so. We could precompute if
  1537. worthwhile or at least cache the results. The result
  1538. technically depends on both SHIFT and ACCESS_SIZE,
  1539. but in practice the answer will depend only on ACCESS_SIZE. */
  1540. if (cost > COSTS_N_INSNS (1))
  1541. continue;
  1542. new_lhs = extract_low_bits (new_mode, store_mode,
  1543. copy_rtx (store_info->rhs));
  1544. if (new_lhs == NULL_RTX)
  1545. continue;
  1546. /* We found an acceptable shift. Generate a move to
  1547. take the value from the store and put it into the
  1548. shift pseudo, then shift it, then generate another
  1549. move to put in into the target of the read. */
  1550. emit_move_insn (new_reg, new_lhs);
  1551. emit_insn (shift_seq);
  1552. read_reg = extract_low_bits (read_mode, new_mode, new_reg);
  1553. break;
  1554. }
  1555. return read_reg;
  1556. }
  1557. /* Call back for note_stores to find the hard regs set or clobbered by
  1558. insn. Data is a bitmap of the hardregs set so far. */
  1559. static void
  1560. look_for_hardregs (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
  1561. {
  1562. bitmap regs_set = (bitmap) data;
  1563. if (REG_P (x)
  1564. && HARD_REGISTER_P (x))
  1565. {
  1566. unsigned int regno = REGNO (x);
  1567. bitmap_set_range (regs_set, regno,
  1568. hard_regno_nregs[regno][GET_MODE (x)]);
  1569. }
  1570. }
  1571. /* Helper function for replace_read and record_store.
  1572. Attempt to return a value stored in STORE_INFO, from READ_BEGIN
  1573. to one before READ_END bytes read in READ_MODE. Return NULL
  1574. if not successful. If REQUIRE_CST is true, return always constant. */
  1575. static rtx
  1576. get_stored_val (store_info_t store_info, machine_mode read_mode,
  1577. HOST_WIDE_INT read_begin, HOST_WIDE_INT read_end,
  1578. basic_block bb, bool require_cst)
  1579. {
  1580. machine_mode store_mode = GET_MODE (store_info->mem);
  1581. int shift;
  1582. int access_size; /* In bytes. */
  1583. rtx read_reg;
  1584. /* To get here the read is within the boundaries of the write so
  1585. shift will never be negative. Start out with the shift being in
  1586. bytes. */
  1587. if (store_mode == BLKmode)
  1588. shift = 0;
  1589. else if (BYTES_BIG_ENDIAN)
  1590. shift = store_info->end - read_end;
  1591. else
  1592. shift = read_begin - store_info->begin;
  1593. access_size = shift + GET_MODE_SIZE (read_mode);
  1594. /* From now on it is bits. */
  1595. shift *= BITS_PER_UNIT;
  1596. if (shift)
  1597. read_reg = find_shift_sequence (access_size, store_info, read_mode, shift,
  1598. optimize_bb_for_speed_p (bb),
  1599. require_cst);
  1600. else if (store_mode == BLKmode)
  1601. {
  1602. /* The store is a memset (addr, const_val, const_size). */
  1603. gcc_assert (CONST_INT_P (store_info->rhs));
  1604. store_mode = int_mode_for_mode (read_mode);
  1605. if (store_mode == BLKmode)
  1606. read_reg = NULL_RTX;
  1607. else if (store_info->rhs == const0_rtx)
  1608. read_reg = extract_low_bits (read_mode, store_mode, const0_rtx);
  1609. else if (GET_MODE_BITSIZE (store_mode) > HOST_BITS_PER_WIDE_INT
  1610. || BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT)
  1611. read_reg = NULL_RTX;
  1612. else
  1613. {
  1614. unsigned HOST_WIDE_INT c
  1615. = INTVAL (store_info->rhs)
  1616. & (((HOST_WIDE_INT) 1 << BITS_PER_UNIT) - 1);
  1617. int shift = BITS_PER_UNIT;
  1618. while (shift < HOST_BITS_PER_WIDE_INT)
  1619. {
  1620. c |= (c << shift);
  1621. shift <<= 1;
  1622. }
  1623. read_reg = gen_int_mode (c, store_mode);
  1624. read_reg = extract_low_bits (read_mode, store_mode, read_reg);
  1625. }
  1626. }
  1627. else if (store_info->const_rhs
  1628. && (require_cst
  1629. || GET_MODE_CLASS (read_mode) != GET_MODE_CLASS (store_mode)))
  1630. read_reg = extract_low_bits (read_mode, store_mode,
  1631. copy_rtx (store_info->const_rhs));
  1632. else
  1633. read_reg = extract_low_bits (read_mode, store_mode,
  1634. copy_rtx (store_info->rhs));
  1635. if (require_cst && read_reg && !CONSTANT_P (read_reg))
  1636. read_reg = NULL_RTX;
  1637. return read_reg;
  1638. }
  1639. /* Take a sequence of:
  1640. A <- r1
  1641. ...
  1642. ... <- A
  1643. and change it into
  1644. r2 <- r1
  1645. A <- r1
  1646. ...
  1647. ... <- r2
  1648. or
  1649. r3 <- extract (r1)
  1650. r3 <- r3 >> shift
  1651. r2 <- extract (r3)
  1652. ... <- r2
  1653. or
  1654. r2 <- extract (r1)
  1655. ... <- r2
  1656. Depending on the alignment and the mode of the store and
  1657. subsequent load.
  1658. The STORE_INFO and STORE_INSN are for the store and READ_INFO
  1659. and READ_INSN are for the read. Return true if the replacement
  1660. went ok. */
  1661. static bool
  1662. replace_read (store_info_t store_info, insn_info_t store_insn,
  1663. read_info_t read_info, insn_info_t read_insn, rtx *loc,
  1664. bitmap regs_live)
  1665. {
  1666. machine_mode store_mode = GET_MODE (store_info->mem);
  1667. machine_mode read_mode = GET_MODE (read_info->mem);
  1668. rtx_insn *insns, *this_insn;
  1669. rtx read_reg;
  1670. basic_block bb;
  1671. if (!dbg_cnt (dse))
  1672. return false;
  1673. /* Create a sequence of instructions to set up the read register.
  1674. This sequence goes immediately before the store and its result
  1675. is read by the load.
  1676. We need to keep this in perspective. We are replacing a read
  1677. with a sequence of insns, but the read will almost certainly be
  1678. in cache, so it is not going to be an expensive one. Thus, we
  1679. are not willing to do a multi insn shift or worse a subroutine
  1680. call to get rid of the read. */
  1681. if (dump_file && (dump_flags & TDF_DETAILS))
  1682. fprintf (dump_file, "trying to replace %smode load in insn %d"
  1683. " from %smode store in insn %d\n",
  1684. GET_MODE_NAME (read_mode), INSN_UID (read_insn->insn),
  1685. GET_MODE_NAME (store_mode), INSN_UID (store_insn->insn));
  1686. start_sequence ();
  1687. bb = BLOCK_FOR_INSN (read_insn->insn);
  1688. read_reg = get_stored_val (store_info,
  1689. read_mode, read_info->begin, read_info->end,
  1690. bb, false);
  1691. if (read_reg == NULL_RTX)
  1692. {
  1693. end_sequence ();
  1694. if (dump_file && (dump_flags & TDF_DETAILS))
  1695. fprintf (dump_file, " -- could not extract bits of stored value\n");
  1696. return false;
  1697. }
  1698. /* Force the value into a new register so that it won't be clobbered
  1699. between the store and the load. */
  1700. read_reg = copy_to_mode_reg (read_mode, read_reg);
  1701. insns = get_insns ();
  1702. end_sequence ();
  1703. if (insns != NULL_RTX)
  1704. {
  1705. /* Now we have to scan the set of new instructions to see if the
  1706. sequence contains and sets of hardregs that happened to be
  1707. live at this point. For instance, this can happen if one of
  1708. the insns sets the CC and the CC happened to be live at that
  1709. point. This does occasionally happen, see PR 37922. */
  1710. bitmap regs_set = BITMAP_ALLOC (&reg_obstack);
  1711. for (this_insn = insns; this_insn != NULL_RTX; this_insn = NEXT_INSN (this_insn))
  1712. note_stores (PATTERN (this_insn), look_for_hardregs, regs_set);
  1713. bitmap_and_into (regs_set, regs_live);
  1714. if (!bitmap_empty_p (regs_set))
  1715. {
  1716. if (dump_file && (dump_flags & TDF_DETAILS))
  1717. {
  1718. fprintf (dump_file,
  1719. "abandoning replacement because sequence clobbers live hardregs:");
  1720. df_print_regset (dump_file, regs_set);
  1721. }
  1722. BITMAP_FREE (regs_set);
  1723. return false;
  1724. }
  1725. BITMAP_FREE (regs_set);
  1726. }
  1727. if (validate_change (read_insn->insn, loc, read_reg, 0))
  1728. {
  1729. deferred_change_t deferred_change =
  1730. (deferred_change_t) pool_alloc (deferred_change_pool);
  1731. /* Insert this right before the store insn where it will be safe
  1732. from later insns that might change it before the read. */
  1733. emit_insn_before (insns, store_insn->insn);
  1734. /* And now for the kludge part: cselib croaks if you just
  1735. return at this point. There are two reasons for this:
  1736. 1) Cselib has an idea of how many pseudos there are and
  1737. that does not include the new ones we just added.
  1738. 2) Cselib does not know about the move insn we added
  1739. above the store_info, and there is no way to tell it
  1740. about it, because it has "moved on".
  1741. Problem (1) is fixable with a certain amount of engineering.
  1742. Problem (2) is requires starting the bb from scratch. This
  1743. could be expensive.
  1744. So we are just going to have to lie. The move/extraction
  1745. insns are not really an issue, cselib did not see them. But
  1746. the use of the new pseudo read_insn is a real problem because
  1747. cselib has not scanned this insn. The way that we solve this
  1748. problem is that we are just going to put the mem back for now
  1749. and when we are finished with the block, we undo this. We
  1750. keep a table of mems to get rid of. At the end of the basic
  1751. block we can put them back. */
  1752. *loc = read_info->mem;
  1753. deferred_change->next = deferred_change_list;
  1754. deferred_change_list = deferred_change;
  1755. deferred_change->loc = loc;
  1756. deferred_change->reg = read_reg;
  1757. /* Get rid of the read_info, from the point of view of the
  1758. rest of dse, play like this read never happened. */
  1759. read_insn->read_rec = read_info->next;
  1760. pool_free (read_info_pool, read_info);
  1761. if (dump_file && (dump_flags & TDF_DETAILS))
  1762. {
  1763. fprintf (dump_file, " -- replaced the loaded MEM with ");
  1764. print_simple_rtl (dump_file, read_reg);
  1765. fprintf (dump_file, "\n");
  1766. }
  1767. return true;
  1768. }
  1769. else
  1770. {
  1771. if (dump_file && (dump_flags & TDF_DETAILS))
  1772. {
  1773. fprintf (dump_file, " -- replacing the loaded MEM with ");
  1774. print_simple_rtl (dump_file, read_reg);
  1775. fprintf (dump_file, " led to an invalid instruction\n");
  1776. }
  1777. return false;
  1778. }
  1779. }
  1780. /* Check the address of MEM *LOC and kill any appropriate stores that may
  1781. be active. */
  1782. static void
  1783. check_mem_read_rtx (rtx *loc, bb_info_t bb_info)
  1784. {
  1785. rtx mem = *loc, mem_addr;
  1786. insn_info_t insn_info;
  1787. HOST_WIDE_INT offset = 0;
  1788. HOST_WIDE_INT width = 0;
  1789. alias_set_type spill_alias_set = 0;
  1790. cselib_val *base = NULL;
  1791. int group_id;
  1792. read_info_t read_info;
  1793. insn_info = bb_info->last_insn;
  1794. if ((MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
  1795. || (MEM_VOLATILE_P (mem)))
  1796. {
  1797. if (dump_file && (dump_flags & TDF_DETAILS))
  1798. fprintf (dump_file, " adding wild read, volatile or barrier.\n");
  1799. add_wild_read (bb_info);
  1800. insn_info->cannot_delete = true;
  1801. return;
  1802. }
  1803. /* If it is reading readonly mem, then there can be no conflict with
  1804. another write. */
  1805. if (MEM_READONLY_P (mem))
  1806. return;
  1807. if (!canon_address (mem, &spill_alias_set, &group_id, &offset, &base))
  1808. {
  1809. if (dump_file && (dump_flags & TDF_DETAILS))
  1810. fprintf (dump_file, " adding wild read, canon_address failure.\n");
  1811. add_wild_read (bb_info);
  1812. return;
  1813. }
  1814. if (GET_MODE (mem) == BLKmode)
  1815. width = -1;
  1816. else
  1817. width = GET_MODE_SIZE (GET_MODE (mem));
  1818. read_info = (read_info_t) pool_alloc (read_info_pool);
  1819. read_info->group_id = group_id;
  1820. read_info->mem = mem;
  1821. read_info->alias_set = spill_alias_set;
  1822. read_info->begin = offset;
  1823. read_info->end = offset + width;
  1824. read_info->next = insn_info->read_rec;
  1825. insn_info->read_rec = read_info;
  1826. /* For alias_set != 0 canon_true_dependence should be never called. */
  1827. if (spill_alias_set)
  1828. mem_addr = NULL_RTX;
  1829. else
  1830. {
  1831. if (group_id < 0)
  1832. mem_addr = base->val_rtx;
  1833. else
  1834. {
  1835. group_info_t group
  1836. = rtx_group_vec[group_id];
  1837. mem_addr = group->canon_base_addr;
  1838. }
  1839. /* get_addr can only handle VALUE but cannot handle expr like:
  1840. VALUE + OFFSET, so call get_addr to get original addr for
  1841. mem_addr before plus_constant. */
  1842. mem_addr = get_addr (mem_addr);
  1843. if (offset)
  1844. mem_addr = plus_constant (get_address_mode (mem), mem_addr, offset);
  1845. }
  1846. /* We ignore the clobbers in store_info. The is mildly aggressive,
  1847. but there really should not be a clobber followed by a read. */
  1848. if (spill_alias_set)
  1849. {
  1850. insn_info_t i_ptr = active_local_stores;
  1851. insn_info_t last = NULL;
  1852. if (dump_file && (dump_flags & TDF_DETAILS))
  1853. fprintf (dump_file, " processing spill load %d\n",
  1854. (int) spill_alias_set);
  1855. while (i_ptr)
  1856. {
  1857. store_info_t store_info = i_ptr->store_rec;
  1858. /* Skip the clobbers. */
  1859. while (!store_info->is_set)
  1860. store_info = store_info->next;
  1861. if (store_info->alias_set == spill_alias_set)
  1862. {
  1863. if (dump_file && (dump_flags & TDF_DETAILS))
  1864. dump_insn_info ("removing from active", i_ptr);
  1865. active_local_stores_len--;
  1866. if (last)
  1867. last->next_local_store = i_ptr->next_local_store;
  1868. else
  1869. active_local_stores = i_ptr->next_local_store;
  1870. }
  1871. else
  1872. last = i_ptr;
  1873. i_ptr = i_ptr->next_local_store;
  1874. }
  1875. }
  1876. else if (group_id >= 0)
  1877. {
  1878. /* This is the restricted case where the base is a constant or
  1879. the frame pointer and offset is a constant. */
  1880. insn_info_t i_ptr = active_local_stores;
  1881. insn_info_t last = NULL;
  1882. if (dump_file && (dump_flags & TDF_DETAILS))
  1883. {
  1884. if (width == -1)
  1885. fprintf (dump_file, " processing const load gid=%d[BLK]\n",
  1886. group_id);
  1887. else
  1888. fprintf (dump_file, " processing const load gid=%d[%d..%d)\n",
  1889. group_id, (int)offset, (int)(offset+width));
  1890. }
  1891. while (i_ptr)
  1892. {
  1893. bool remove = false;
  1894. store_info_t store_info = i_ptr->store_rec;
  1895. /* Skip the clobbers. */
  1896. while (!store_info->is_set)
  1897. store_info = store_info->next;
  1898. /* There are three cases here. */
  1899. if (store_info->group_id < 0)
  1900. /* We have a cselib store followed by a read from a
  1901. const base. */
  1902. remove
  1903. = canon_true_dependence (store_info->mem,
  1904. GET_MODE (store_info->mem),
  1905. store_info->mem_addr,
  1906. mem, mem_addr);
  1907. else if (group_id == store_info->group_id)
  1908. {
  1909. /* This is a block mode load. We may get lucky and
  1910. canon_true_dependence may save the day. */
  1911. if (width == -1)
  1912. remove
  1913. = canon_true_dependence (store_info->mem,
  1914. GET_MODE (store_info->mem),
  1915. store_info->mem_addr,
  1916. mem, mem_addr);
  1917. /* If this read is just reading back something that we just
  1918. stored, rewrite the read. */
  1919. else
  1920. {
  1921. if (store_info->rhs
  1922. && offset >= store_info->begin
  1923. && offset + width <= store_info->end
  1924. && all_positions_needed_p (store_info,
  1925. offset - store_info->begin,
  1926. width)
  1927. && replace_read (store_info, i_ptr, read_info,
  1928. insn_info, loc, bb_info->regs_live))
  1929. return;
  1930. /* The bases are the same, just see if the offsets
  1931. overlap. */
  1932. if ((offset < store_info->end)
  1933. && (offset + width > store_info->begin))
  1934. remove = true;
  1935. }
  1936. }
  1937. /* else
  1938. The else case that is missing here is that the
  1939. bases are constant but different. There is nothing
  1940. to do here because there is no overlap. */
  1941. if (remove)
  1942. {
  1943. if (dump_file && (dump_flags & TDF_DETAILS))
  1944. dump_insn_info ("removing from active", i_ptr);
  1945. active_local_stores_len--;
  1946. if (last)
  1947. last->next_local_store = i_ptr->next_local_store;
  1948. else
  1949. active_local_stores = i_ptr->next_local_store;
  1950. }
  1951. else
  1952. last = i_ptr;
  1953. i_ptr = i_ptr->next_local_store;
  1954. }
  1955. }
  1956. else
  1957. {
  1958. insn_info_t i_ptr = active_local_stores;
  1959. insn_info_t last = NULL;
  1960. if (dump_file && (dump_flags & TDF_DETAILS))
  1961. {
  1962. fprintf (dump_file, " processing cselib load mem:");
  1963. print_inline_rtx (dump_file, mem, 0);
  1964. fprintf (dump_file, "\n");
  1965. }
  1966. while (i_ptr)
  1967. {
  1968. bool remove = false;
  1969. store_info_t store_info = i_ptr->store_rec;
  1970. if (dump_file && (dump_flags & TDF_DETAILS))
  1971. fprintf (dump_file, " processing cselib load against insn %d\n",
  1972. INSN_UID (i_ptr->insn));
  1973. /* Skip the clobbers. */
  1974. while (!store_info->is_set)
  1975. store_info = store_info->next;
  1976. /* If this read is just reading back something that we just
  1977. stored, rewrite the read. */
  1978. if (store_info->rhs
  1979. && store_info->group_id == -1
  1980. && store_info->cse_base == base
  1981. && width != -1
  1982. && offset >= store_info->begin
  1983. && offset + width <= store_info->end
  1984. && all_positions_needed_p (store_info,
  1985. offset - store_info->begin, width)
  1986. && replace_read (store_info, i_ptr, read_info, insn_info, loc,
  1987. bb_info->regs_live))
  1988. return;
  1989. if (!store_info->alias_set)
  1990. remove = canon_true_dependence (store_info->mem,
  1991. GET_MODE (store_info->mem),
  1992. store_info->mem_addr,
  1993. mem, mem_addr);
  1994. if (remove)
  1995. {
  1996. if (dump_file && (dump_flags & TDF_DETAILS))
  1997. dump_insn_info ("removing from active", i_ptr);
  1998. active_local_stores_len--;
  1999. if (last)
  2000. last->next_local_store = i_ptr->next_local_store;
  2001. else
  2002. active_local_stores = i_ptr->next_local_store;
  2003. }
  2004. else
  2005. last = i_ptr;
  2006. i_ptr = i_ptr->next_local_store;
  2007. }
  2008. }
  2009. }
  2010. /* A note_uses callback in which DATA points the INSN_INFO for
  2011. as check_mem_read_rtx. Nullify the pointer if i_m_r_m_r returns
  2012. true for any part of *LOC. */
  2013. static void
  2014. check_mem_read_use (rtx *loc, void *data)
  2015. {
  2016. subrtx_ptr_iterator::array_type array;
  2017. FOR_EACH_SUBRTX_PTR (iter, array, loc, NONCONST)
  2018. {
  2019. rtx *loc = *iter;
  2020. if (MEM_P (*loc))
  2021. check_mem_read_rtx (loc, (bb_info_t) data);
  2022. }
  2023. }
  2024. /* Get arguments passed to CALL_INSN. Return TRUE if successful.
  2025. So far it only handles arguments passed in registers. */
  2026. static bool
  2027. get_call_args (rtx call_insn, tree fn, rtx *args, int nargs)
  2028. {
  2029. CUMULATIVE_ARGS args_so_far_v;
  2030. cumulative_args_t args_so_far;
  2031. tree arg;
  2032. int idx;
  2033. INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
  2034. args_so_far = pack_cumulative_args (&args_so_far_v);
  2035. arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
  2036. for (idx = 0;
  2037. arg != void_list_node && idx < nargs;
  2038. arg = TREE_CHAIN (arg), idx++)
  2039. {
  2040. machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
  2041. rtx reg, link, tmp;
  2042. reg = targetm.calls.function_arg (args_so_far, mode, NULL_TREE, true);
  2043. if (!reg || !REG_P (reg) || GET_MODE (reg) != mode
  2044. || GET_MODE_CLASS (mode) != MODE_INT)
  2045. return false;
  2046. for (link = CALL_INSN_FUNCTION_USAGE (call_insn);
  2047. link;
  2048. link = XEXP (link, 1))
  2049. if (GET_CODE (XEXP (link, 0)) == USE)
  2050. {
  2051. args[idx] = XEXP (XEXP (link, 0), 0);
  2052. if (REG_P (args[idx])
  2053. && REGNO (args[idx]) == REGNO (reg)
  2054. && (GET_MODE (args[idx]) == mode
  2055. || (GET_MODE_CLASS (GET_MODE (args[idx])) == MODE_INT
  2056. && (GET_MODE_SIZE (GET_MODE (args[idx]))
  2057. <= UNITS_PER_WORD)
  2058. && (GET_MODE_SIZE (GET_MODE (args[idx]))
  2059. > GET_MODE_SIZE (mode)))))
  2060. break;
  2061. }
  2062. if (!link)
  2063. return false;
  2064. tmp = cselib_expand_value_rtx (args[idx], scratch, 5);
  2065. if (GET_MODE (args[idx]) != mode)
  2066. {
  2067. if (!tmp || !CONST_INT_P (tmp))
  2068. return false;
  2069. tmp = gen_int_mode (INTVAL (tmp), mode);
  2070. }
  2071. if (tmp)
  2072. args[idx] = tmp;
  2073. targetm.calls.function_arg_advance (args_so_far, mode, NULL_TREE, true);
  2074. }
  2075. if (arg != void_list_node || idx != nargs)
  2076. return false;
  2077. return true;
  2078. }
  2079. /* Return a bitmap of the fixed registers contained in IN. */
  2080. static bitmap
  2081. copy_fixed_regs (const_bitmap in)
  2082. {
  2083. bitmap ret;
  2084. ret = ALLOC_REG_SET (NULL);
  2085. bitmap_and (ret, in, fixed_reg_set_regset);
  2086. return ret;
  2087. }
  2088. /* Apply record_store to all candidate stores in INSN. Mark INSN
  2089. if some part of it is not a candidate store and assigns to a
  2090. non-register target. */
  2091. static void
  2092. scan_insn (bb_info_t bb_info, rtx_insn *insn)
  2093. {
  2094. rtx body;
  2095. insn_info_t insn_info = (insn_info_t) pool_alloc (insn_info_pool);
  2096. int mems_found = 0;
  2097. memset (insn_info, 0, sizeof (struct insn_info));
  2098. if (dump_file && (dump_flags & TDF_DETAILS))
  2099. fprintf (dump_file, "\n**scanning insn=%d\n",
  2100. INSN_UID (insn));
  2101. insn_info->prev_insn = bb_info->last_insn;
  2102. insn_info->insn = insn;
  2103. bb_info->last_insn = insn_info;
  2104. if (DEBUG_INSN_P (insn))
  2105. {
  2106. insn_info->cannot_delete = true;
  2107. return;
  2108. }
  2109. /* Look at all of the uses in the insn. */
  2110. note_uses (&PATTERN (insn), check_mem_read_use, bb_info);
  2111. if (CALL_P (insn))
  2112. {
  2113. bool const_call;
  2114. tree memset_call = NULL_TREE;
  2115. insn_info->cannot_delete = true;
  2116. /* Const functions cannot do anything bad i.e. read memory,
  2117. however, they can read their parameters which may have
  2118. been pushed onto the stack.
  2119. memset and bzero don't read memory either. */
  2120. const_call = RTL_CONST_CALL_P (insn);
  2121. if (!const_call)
  2122. {
  2123. rtx call = get_call_rtx_from (insn);
  2124. if (call && GET_CODE (XEXP (XEXP (call, 0), 0)) == SYMBOL_REF)
  2125. {
  2126. rtx symbol = XEXP (XEXP (call, 0), 0);
  2127. if (SYMBOL_REF_DECL (symbol)
  2128. && TREE_CODE (SYMBOL_REF_DECL (symbol)) == FUNCTION_DECL)
  2129. {
  2130. if ((DECL_BUILT_IN_CLASS (SYMBOL_REF_DECL (symbol))
  2131. == BUILT_IN_NORMAL
  2132. && (DECL_FUNCTION_CODE (SYMBOL_REF_DECL (symbol))
  2133. == BUILT_IN_MEMSET))
  2134. || SYMBOL_REF_DECL (symbol) == block_clear_fn)
  2135. memset_call = SYMBOL_REF_DECL (symbol);
  2136. }
  2137. }
  2138. }
  2139. if (const_call || memset_call)
  2140. {
  2141. insn_info_t i_ptr = active_local_stores;
  2142. insn_info_t last = NULL;
  2143. if (dump_file && (dump_flags & TDF_DETAILS))
  2144. fprintf (dump_file, "%s call %d\n",
  2145. const_call ? "const" : "memset", INSN_UID (insn));
  2146. /* See the head comment of the frame_read field. */
  2147. if (reload_completed
  2148. /* Tail calls are storing their arguments using
  2149. arg pointer. If it is a frame pointer on the target,
  2150. even before reload we need to kill frame pointer based
  2151. stores. */
  2152. || (SIBLING_CALL_P (insn)
  2153. && HARD_FRAME_POINTER_IS_ARG_POINTER))
  2154. insn_info->frame_read = true;
  2155. /* Loop over the active stores and remove those which are
  2156. killed by the const function call. */
  2157. while (i_ptr)
  2158. {
  2159. bool remove_store = false;
  2160. /* The stack pointer based stores are always killed. */
  2161. if (i_ptr->stack_pointer_based)
  2162. remove_store = true;
  2163. /* If the frame is read, the frame related stores are killed. */
  2164. else if (insn_info->frame_read)
  2165. {
  2166. store_info_t store_info = i_ptr->store_rec;
  2167. /* Skip the clobbers. */
  2168. while (!store_info->is_set)
  2169. store_info = store_info->next;
  2170. if (store_info->group_id >= 0
  2171. && rtx_group_vec[store_info->group_id]->frame_related)
  2172. remove_store = true;
  2173. }
  2174. if (remove_store)
  2175. {
  2176. if (dump_file && (dump_flags & TDF_DETAILS))
  2177. dump_insn_info ("removing from active", i_ptr);
  2178. active_local_stores_len--;
  2179. if (last)
  2180. last->next_local_store = i_ptr->next_local_store;
  2181. else
  2182. active_local_stores = i_ptr->next_local_store;
  2183. }
  2184. else
  2185. last = i_ptr;
  2186. i_ptr = i_ptr->next_local_store;
  2187. }
  2188. if (memset_call)
  2189. {
  2190. rtx args[3];
  2191. if (get_call_args (insn, memset_call, args, 3)
  2192. && CONST_INT_P (args[1])
  2193. && CONST_INT_P (args[2])
  2194. && INTVAL (args[2]) > 0)
  2195. {
  2196. rtx mem = gen_rtx_MEM (BLKmode, args[0]);
  2197. set_mem_size (mem, INTVAL (args[2]));
  2198. body = gen_rtx_SET (VOIDmode, mem, args[1]);
  2199. mems_found += record_store (body, bb_info);
  2200. if (dump_file && (dump_flags & TDF_DETAILS))
  2201. fprintf (dump_file, "handling memset as BLKmode store\n");
  2202. if (mems_found == 1)
  2203. {
  2204. if (active_local_stores_len++
  2205. >= PARAM_VALUE (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES))
  2206. {
  2207. active_local_stores_len = 1;
  2208. active_local_stores = NULL;
  2209. }
  2210. insn_info->fixed_regs_live
  2211. = copy_fixed_regs (bb_info->regs_live);
  2212. insn_info->next_local_store = active_local_stores;
  2213. active_local_stores = insn_info;
  2214. }
  2215. }
  2216. }
  2217. }
  2218. else if (SIBLING_CALL_P (insn) && reload_completed)
  2219. /* Arguments for a sibling call that are pushed to memory are passed
  2220. using the incoming argument pointer of the current function. After
  2221. reload that might be (and likely is) frame pointer based. */
  2222. add_wild_read (bb_info);
  2223. else
  2224. /* Every other call, including pure functions, may read any memory
  2225. that is not relative to the frame. */
  2226. add_non_frame_wild_read (bb_info);
  2227. return;
  2228. }
  2229. /* Assuming that there are sets in these insns, we cannot delete
  2230. them. */
  2231. if ((GET_CODE (PATTERN (insn)) == CLOBBER)
  2232. || volatile_refs_p (PATTERN (insn))
  2233. || (!cfun->can_delete_dead_exceptions && !insn_nothrow_p (insn))
  2234. || (RTX_FRAME_RELATED_P (insn))
  2235. || find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX))
  2236. insn_info->cannot_delete = true;
  2237. body = PATTERN (insn);
  2238. if (GET_CODE (body) == PARALLEL)
  2239. {
  2240. int i;
  2241. for (i = 0; i < XVECLEN (body, 0); i++)
  2242. mems_found += record_store (XVECEXP (body, 0, i), bb_info);
  2243. }
  2244. else
  2245. mems_found += record_store (body, bb_info);
  2246. if (dump_file && (dump_flags & TDF_DETAILS))
  2247. fprintf (dump_file, "mems_found = %d, cannot_delete = %s\n",
  2248. mems_found, insn_info->cannot_delete ? "true" : "false");
  2249. /* If we found some sets of mems, add it into the active_local_stores so
  2250. that it can be locally deleted if found dead or used for
  2251. replace_read and redundant constant store elimination. Otherwise mark
  2252. it as cannot delete. This simplifies the processing later. */
  2253. if (mems_found == 1)
  2254. {
  2255. if (active_local_stores_len++
  2256. >= PARAM_VALUE (PARAM_MAX_DSE_ACTIVE_LOCAL_STORES))
  2257. {
  2258. active_local_stores_len = 1;
  2259. active_local_stores = NULL;
  2260. }
  2261. insn_info->fixed_regs_live = copy_fixed_regs (bb_info->regs_live);
  2262. insn_info->next_local_store = active_local_stores;
  2263. active_local_stores = insn_info;
  2264. }
  2265. else
  2266. insn_info->cannot_delete = true;
  2267. }
  2268. /* Remove BASE from the set of active_local_stores. This is a
  2269. callback from cselib that is used to get rid of the stores in
  2270. active_local_stores. */
  2271. static void
  2272. remove_useless_values (cselib_val *base)
  2273. {
  2274. insn_info_t insn_info = active_local_stores;
  2275. insn_info_t last = NULL;
  2276. while (insn_info)
  2277. {
  2278. store_info_t store_info = insn_info->store_rec;
  2279. bool del = false;
  2280. /* If ANY of the store_infos match the cselib group that is
  2281. being deleted, then the insn can not be deleted. */
  2282. while (store_info)
  2283. {
  2284. if ((store_info->group_id == -1)
  2285. && (store_info->cse_base == base))
  2286. {
  2287. del = true;
  2288. break;
  2289. }
  2290. store_info = store_info->next;
  2291. }
  2292. if (del)
  2293. {
  2294. active_local_stores_len--;
  2295. if (last)
  2296. last->next_local_store = insn_info->next_local_store;
  2297. else
  2298. active_local_stores = insn_info->next_local_store;
  2299. free_store_info (insn_info);
  2300. }
  2301. else
  2302. last = insn_info;
  2303. insn_info = insn_info->next_local_store;
  2304. }
  2305. }
  2306. /* Do all of step 1. */
  2307. static void
  2308. dse_step1 (void)
  2309. {
  2310. basic_block bb;
  2311. bitmap regs_live = BITMAP_ALLOC (&reg_obstack);
  2312. cselib_init (0);
  2313. all_blocks = BITMAP_ALLOC (NULL);
  2314. bitmap_set_bit (all_blocks, ENTRY_BLOCK);
  2315. bitmap_set_bit (all_blocks, EXIT_BLOCK);
  2316. FOR_ALL_BB_FN (bb, cfun)
  2317. {
  2318. insn_info_t ptr;
  2319. bb_info_t bb_info = (bb_info_t) pool_alloc (bb_info_pool);
  2320. memset (bb_info, 0, sizeof (struct dse_bb_info));
  2321. bitmap_set_bit (all_blocks, bb->index);
  2322. bb_info->regs_live = regs_live;
  2323. bitmap_copy (regs_live, DF_LR_IN (bb));
  2324. df_simulate_initialize_forwards (bb, regs_live);
  2325. bb_table[bb->index] = bb_info;
  2326. cselib_discard_hook = remove_useless_values;
  2327. if (bb->index >= NUM_FIXED_BLOCKS)
  2328. {
  2329. rtx_insn *insn;
  2330. cse_store_info_pool
  2331. = create_alloc_pool ("cse_store_info_pool",
  2332. sizeof (struct store_info), 100);
  2333. active_local_stores = NULL;
  2334. active_local_stores_len = 0;
  2335. cselib_clear_table ();
  2336. /* Scan the insns. */
  2337. FOR_BB_INSNS (bb, insn)
  2338. {
  2339. if (INSN_P (insn))
  2340. scan_insn (bb_info, insn);
  2341. cselib_process_insn (insn);
  2342. if (INSN_P (insn))
  2343. df_simulate_one_insn_forwards (bb, insn, regs_live);
  2344. }
  2345. /* This is something of a hack, because the global algorithm
  2346. is supposed to take care of the case where stores go dead
  2347. at the end of the function. However, the global
  2348. algorithm must take a more conservative view of block
  2349. mode reads than the local alg does. So to get the case
  2350. where you have a store to the frame followed by a non
  2351. overlapping block more read, we look at the active local
  2352. stores at the end of the function and delete all of the
  2353. frame and spill based ones. */
  2354. if (stores_off_frame_dead_at_return
  2355. && (EDGE_COUNT (bb->succs) == 0
  2356. || (single_succ_p (bb)
  2357. && single_succ (bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)
  2358. && ! crtl->calls_eh_return)))
  2359. {
  2360. insn_info_t i_ptr = active_local_stores;
  2361. while (i_ptr)
  2362. {
  2363. store_info_t store_info = i_ptr->store_rec;
  2364. /* Skip the clobbers. */
  2365. while (!store_info->is_set)
  2366. store_info = store_info->next;
  2367. if (store_info->alias_set && !i_ptr->cannot_delete)
  2368. delete_dead_store_insn (i_ptr);
  2369. else
  2370. if (store_info->group_id >= 0)
  2371. {
  2372. group_info_t group
  2373. = rtx_group_vec[store_info->group_id];
  2374. if (group->frame_related && !i_ptr->cannot_delete)
  2375. delete_dead_store_insn (i_ptr);
  2376. }
  2377. i_ptr = i_ptr->next_local_store;
  2378. }
  2379. }
  2380. /* Get rid of the loads that were discovered in
  2381. replace_read. Cselib is finished with this block. */
  2382. while (deferred_change_list)
  2383. {
  2384. deferred_change_t next = deferred_change_list->next;
  2385. /* There is no reason to validate this change. That was
  2386. done earlier. */
  2387. *deferred_change_list->loc = deferred_change_list->reg;
  2388. pool_free (deferred_change_pool, deferred_change_list);
  2389. deferred_change_list = next;
  2390. }
  2391. /* Get rid of all of the cselib based store_infos in this
  2392. block and mark the containing insns as not being
  2393. deletable. */
  2394. ptr = bb_info->last_insn;
  2395. while (ptr)
  2396. {
  2397. if (ptr->contains_cselib_groups)
  2398. {
  2399. store_info_t s_info = ptr->store_rec;
  2400. while (s_info && !s_info->is_set)
  2401. s_info = s_info->next;
  2402. if (s_info
  2403. && s_info->redundant_reason
  2404. && s_info->redundant_reason->insn
  2405. && !ptr->cannot_delete)
  2406. {
  2407. if (dump_file && (dump_flags & TDF_DETAILS))
  2408. fprintf (dump_file, "Locally deleting insn %d "
  2409. "because insn %d stores the "
  2410. "same value and couldn't be "
  2411. "eliminated\n",
  2412. INSN_UID (ptr->insn),
  2413. INSN_UID (s_info->redundant_reason->insn));
  2414. delete_dead_store_insn (ptr);
  2415. }
  2416. free_store_info (ptr);
  2417. }
  2418. else
  2419. {
  2420. store_info_t s_info;
  2421. /* Free at least positions_needed bitmaps. */
  2422. for (s_info = ptr->store_rec; s_info; s_info = s_info->next)
  2423. if (s_info->is_large)
  2424. {
  2425. BITMAP_FREE (s_info->positions_needed.large.bmap);
  2426. s_info->is_large = false;
  2427. }
  2428. }
  2429. ptr = ptr->prev_insn;
  2430. }
  2431. free_alloc_pool (cse_store_info_pool);
  2432. }
  2433. bb_info->regs_live = NULL;
  2434. }
  2435. BITMAP_FREE (regs_live);
  2436. cselib_finish ();
  2437. rtx_group_table->empty ();
  2438. }
  2439. /*----------------------------------------------------------------------------
  2440. Second step.
  2441. Assign each byte position in the stores that we are going to
  2442. analyze globally to a position in the bitmaps. Returns true if
  2443. there are any bit positions assigned.
  2444. ----------------------------------------------------------------------------*/
  2445. static void
  2446. dse_step2_init (void)
  2447. {
  2448. unsigned int i;
  2449. group_info_t group;
  2450. FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
  2451. {
  2452. /* For all non stack related bases, we only consider a store to
  2453. be deletable if there are two or more stores for that
  2454. position. This is because it takes one store to make the
  2455. other store redundant. However, for the stores that are
  2456. stack related, we consider them if there is only one store
  2457. for the position. We do this because the stack related
  2458. stores can be deleted if their is no read between them and
  2459. the end of the function.
  2460. To make this work in the current framework, we take the stack
  2461. related bases add all of the bits from store1 into store2.
  2462. This has the effect of making the eligible even if there is
  2463. only one store. */
  2464. if (stores_off_frame_dead_at_return && group->frame_related)
  2465. {
  2466. bitmap_ior_into (group->store2_n, group->store1_n);
  2467. bitmap_ior_into (group->store2_p, group->store1_p);
  2468. if (dump_file && (dump_flags & TDF_DETAILS))
  2469. fprintf (dump_file, "group %d is frame related ", i);
  2470. }
  2471. group->offset_map_size_n++;
  2472. group->offset_map_n = XOBNEWVEC (&dse_obstack, int,
  2473. group->offset_map_size_n);
  2474. group->offset_map_size_p++;
  2475. group->offset_map_p = XOBNEWVEC (&dse_obstack, int,
  2476. group->offset_map_size_p);
  2477. group->process_globally = false;
  2478. if (dump_file && (dump_flags & TDF_DETAILS))
  2479. {
  2480. fprintf (dump_file, "group %d(%d+%d): ", i,
  2481. (int)bitmap_count_bits (group->store2_n),
  2482. (int)bitmap_count_bits (group->store2_p));
  2483. bitmap_print (dump_file, group->store2_n, "n ", " ");
  2484. bitmap_print (dump_file, group->store2_p, "p ", "\n");
  2485. }
  2486. }
  2487. }
  2488. /* Init the offset tables for the normal case. */
  2489. static bool
  2490. dse_step2_nospill (void)
  2491. {
  2492. unsigned int i;
  2493. group_info_t group;
  2494. /* Position 0 is unused because 0 is used in the maps to mean
  2495. unused. */
  2496. current_position = 1;
  2497. FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
  2498. {
  2499. bitmap_iterator bi;
  2500. unsigned int j;
  2501. if (group == clear_alias_group)
  2502. continue;
  2503. memset (group->offset_map_n, 0, sizeof (int) * group->offset_map_size_n);
  2504. memset (group->offset_map_p, 0, sizeof (int) * group->offset_map_size_p);
  2505. bitmap_clear (group->group_kill);
  2506. EXECUTE_IF_SET_IN_BITMAP (group->store2_n, 0, j, bi)
  2507. {
  2508. bitmap_set_bit (group->group_kill, current_position);
  2509. if (bitmap_bit_p (group->escaped_n, j))
  2510. bitmap_set_bit (kill_on_calls, current_position);
  2511. group->offset_map_n[j] = current_position++;
  2512. group->process_globally = true;
  2513. }
  2514. EXECUTE_IF_SET_IN_BITMAP (group->store2_p, 0, j, bi)
  2515. {
  2516. bitmap_set_bit (group->group_kill, current_position);
  2517. if (bitmap_bit_p (group->escaped_p, j))
  2518. bitmap_set_bit (kill_on_calls, current_position);
  2519. group->offset_map_p[j] = current_position++;
  2520. group->process_globally = true;
  2521. }
  2522. }
  2523. return current_position != 1;
  2524. }
  2525. /*----------------------------------------------------------------------------
  2526. Third step.
  2527. Build the bit vectors for the transfer functions.
  2528. ----------------------------------------------------------------------------*/
  2529. /* Look up the bitmap index for OFFSET in GROUP_INFO. If it is not
  2530. there, return 0. */
  2531. static int
  2532. get_bitmap_index (group_info_t group_info, HOST_WIDE_INT offset)
  2533. {
  2534. if (offset < 0)
  2535. {
  2536. HOST_WIDE_INT offset_p = -offset;
  2537. if (offset_p >= group_info->offset_map_size_n)
  2538. return 0;
  2539. return group_info->offset_map_n[offset_p];
  2540. }
  2541. else
  2542. {
  2543. if (offset >= group_info->offset_map_size_p)
  2544. return 0;
  2545. return group_info->offset_map_p[offset];
  2546. }
  2547. }
  2548. /* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
  2549. may be NULL. */
  2550. static void
  2551. scan_stores_nospill (store_info_t store_info, bitmap gen, bitmap kill)
  2552. {
  2553. while (store_info)
  2554. {
  2555. HOST_WIDE_INT i;
  2556. group_info_t group_info
  2557. = rtx_group_vec[store_info->group_id];
  2558. if (group_info->process_globally)
  2559. for (i = store_info->begin; i < store_info->end; i++)
  2560. {
  2561. int index = get_bitmap_index (group_info, i);
  2562. if (index != 0)
  2563. {
  2564. bitmap_set_bit (gen, index);
  2565. if (kill)
  2566. bitmap_clear_bit (kill, index);
  2567. }
  2568. }
  2569. store_info = store_info->next;
  2570. }
  2571. }
  2572. /* Process the STORE_INFOs into the bitmaps into GEN and KILL. KILL
  2573. may be NULL. */
  2574. static void
  2575. scan_stores_spill (store_info_t store_info, bitmap gen, bitmap kill)
  2576. {
  2577. while (store_info)
  2578. {
  2579. if (store_info->alias_set)
  2580. {
  2581. int index = get_bitmap_index (clear_alias_group,
  2582. store_info->alias_set);
  2583. if (index != 0)
  2584. {
  2585. bitmap_set_bit (gen, index);
  2586. if (kill)
  2587. bitmap_clear_bit (kill, index);
  2588. }
  2589. }
  2590. store_info = store_info->next;
  2591. }
  2592. }
  2593. /* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
  2594. may be NULL. */
  2595. static void
  2596. scan_reads_nospill (insn_info_t insn_info, bitmap gen, bitmap kill)
  2597. {
  2598. read_info_t read_info = insn_info->read_rec;
  2599. int i;
  2600. group_info_t group;
  2601. /* If this insn reads the frame, kill all the frame related stores. */
  2602. if (insn_info->frame_read)
  2603. {
  2604. FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
  2605. if (group->process_globally && group->frame_related)
  2606. {
  2607. if (kill)
  2608. bitmap_ior_into (kill, group->group_kill);
  2609. bitmap_and_compl_into (gen, group->group_kill);
  2610. }
  2611. }
  2612. if (insn_info->non_frame_wild_read)
  2613. {
  2614. /* Kill all non-frame related stores. Kill all stores of variables that
  2615. escape. */
  2616. if (kill)
  2617. bitmap_ior_into (kill, kill_on_calls);
  2618. bitmap_and_compl_into (gen, kill_on_calls);
  2619. FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
  2620. if (group->process_globally && !group->frame_related)
  2621. {
  2622. if (kill)
  2623. bitmap_ior_into (kill, group->group_kill);
  2624. bitmap_and_compl_into (gen, group->group_kill);
  2625. }
  2626. }
  2627. while (read_info)
  2628. {
  2629. FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
  2630. {
  2631. if (group->process_globally)
  2632. {
  2633. if (i == read_info->group_id)
  2634. {
  2635. if (read_info->begin > read_info->end)
  2636. {
  2637. /* Begin > end for block mode reads. */
  2638. if (kill)
  2639. bitmap_ior_into (kill, group->group_kill);
  2640. bitmap_and_compl_into (gen, group->group_kill);
  2641. }
  2642. else
  2643. {
  2644. /* The groups are the same, just process the
  2645. offsets. */
  2646. HOST_WIDE_INT j;
  2647. for (j = read_info->begin; j < read_info->end; j++)
  2648. {
  2649. int index = get_bitmap_index (group, j);
  2650. if (index != 0)
  2651. {
  2652. if (kill)
  2653. bitmap_set_bit (kill, index);
  2654. bitmap_clear_bit (gen, index);
  2655. }
  2656. }
  2657. }
  2658. }
  2659. else
  2660. {
  2661. /* The groups are different, if the alias sets
  2662. conflict, clear the entire group. We only need
  2663. to apply this test if the read_info is a cselib
  2664. read. Anything with a constant base cannot alias
  2665. something else with a different constant
  2666. base. */
  2667. if ((read_info->group_id < 0)
  2668. && canon_true_dependence (group->base_mem,
  2669. GET_MODE (group->base_mem),
  2670. group->canon_base_addr,
  2671. read_info->mem, NULL_RTX))
  2672. {
  2673. if (kill)
  2674. bitmap_ior_into (kill, group->group_kill);
  2675. bitmap_and_compl_into (gen, group->group_kill);
  2676. }
  2677. }
  2678. }
  2679. }
  2680. read_info = read_info->next;
  2681. }
  2682. }
  2683. /* Process the READ_INFOs into the bitmaps into GEN and KILL. KILL
  2684. may be NULL. */
  2685. static void
  2686. scan_reads_spill (read_info_t read_info, bitmap gen, bitmap kill)
  2687. {
  2688. while (read_info)
  2689. {
  2690. if (read_info->alias_set)
  2691. {
  2692. int index = get_bitmap_index (clear_alias_group,
  2693. read_info->alias_set);
  2694. if (index != 0)
  2695. {
  2696. if (kill)
  2697. bitmap_set_bit (kill, index);
  2698. bitmap_clear_bit (gen, index);
  2699. }
  2700. }
  2701. read_info = read_info->next;
  2702. }
  2703. }
  2704. /* Return the insn in BB_INFO before the first wild read or if there
  2705. are no wild reads in the block, return the last insn. */
  2706. static insn_info_t
  2707. find_insn_before_first_wild_read (bb_info_t bb_info)
  2708. {
  2709. insn_info_t insn_info = bb_info->last_insn;
  2710. insn_info_t last_wild_read = NULL;
  2711. while (insn_info)
  2712. {
  2713. if (insn_info->wild_read)
  2714. {
  2715. last_wild_read = insn_info->prev_insn;
  2716. /* Block starts with wild read. */
  2717. if (!last_wild_read)
  2718. return NULL;
  2719. }
  2720. insn_info = insn_info->prev_insn;
  2721. }
  2722. if (last_wild_read)
  2723. return last_wild_read;
  2724. else
  2725. return bb_info->last_insn;
  2726. }
  2727. /* Scan the insns in BB_INFO starting at PTR and going to the top of
  2728. the block in order to build the gen and kill sets for the block.
  2729. We start at ptr which may be the last insn in the block or may be
  2730. the first insn with a wild read. In the latter case we are able to
  2731. skip the rest of the block because it just does not matter:
  2732. anything that happens is hidden by the wild read. */
  2733. static void
  2734. dse_step3_scan (bool for_spills, basic_block bb)
  2735. {
  2736. bb_info_t bb_info = bb_table[bb->index];
  2737. insn_info_t insn_info;
  2738. if (for_spills)
  2739. /* There are no wild reads in the spill case. */
  2740. insn_info = bb_info->last_insn;
  2741. else
  2742. insn_info = find_insn_before_first_wild_read (bb_info);
  2743. /* In the spill case or in the no_spill case if there is no wild
  2744. read in the block, we will need a kill set. */
  2745. if (insn_info == bb_info->last_insn)
  2746. {
  2747. if (bb_info->kill)
  2748. bitmap_clear (bb_info->kill);
  2749. else
  2750. bb_info->kill = BITMAP_ALLOC (&dse_bitmap_obstack);
  2751. }
  2752. else
  2753. if (bb_info->kill)
  2754. BITMAP_FREE (bb_info->kill);
  2755. while (insn_info)
  2756. {
  2757. /* There may have been code deleted by the dce pass run before
  2758. this phase. */
  2759. if (insn_info->insn && INSN_P (insn_info->insn))
  2760. {
  2761. /* Process the read(s) last. */
  2762. if (for_spills)
  2763. {
  2764. scan_stores_spill (insn_info->store_rec, bb_info->gen, bb_info->kill);
  2765. scan_reads_spill (insn_info->read_rec, bb_info->gen, bb_info->kill);
  2766. }
  2767. else
  2768. {
  2769. scan_stores_nospill (insn_info->store_rec, bb_info->gen, bb_info->kill);
  2770. scan_reads_nospill (insn_info, bb_info->gen, bb_info->kill);
  2771. }
  2772. }
  2773. insn_info = insn_info->prev_insn;
  2774. }
  2775. }
  2776. /* Set the gen set of the exit block, and also any block with no
  2777. successors that does not have a wild read. */
  2778. static void
  2779. dse_step3_exit_block_scan (bb_info_t bb_info)
  2780. {
  2781. /* The gen set is all 0's for the exit block except for the
  2782. frame_pointer_group. */
  2783. if (stores_off_frame_dead_at_return)
  2784. {
  2785. unsigned int i;
  2786. group_info_t group;
  2787. FOR_EACH_VEC_ELT (rtx_group_vec, i, group)
  2788. {
  2789. if (group->process_globally && group->frame_related)
  2790. bitmap_ior_into (bb_info->gen, group->group_kill);
  2791. }
  2792. }
  2793. }
  2794. /* Find all of the blocks that are not backwards reachable from the
  2795. exit block or any block with no successors (BB). These are the
  2796. infinite loops or infinite self loops. These blocks will still
  2797. have their bits set in UNREACHABLE_BLOCKS. */
  2798. static void
  2799. mark_reachable_blocks (sbitmap unreachable_blocks, basic_block bb)
  2800. {
  2801. edge e;
  2802. edge_iterator ei;
  2803. if (bitmap_bit_p (unreachable_blocks, bb->index))
  2804. {
  2805. bitmap_clear_bit (unreachable_blocks, bb->index);
  2806. FOR_EACH_EDGE (e, ei, bb->preds)
  2807. {
  2808. mark_reachable_blocks (unreachable_blocks, e->src);
  2809. }
  2810. }
  2811. }
  2812. /* Build the transfer functions for the function. */
  2813. static void
  2814. dse_step3 (bool for_spills)
  2815. {
  2816. basic_block bb;
  2817. sbitmap unreachable_blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
  2818. sbitmap_iterator sbi;
  2819. bitmap all_ones = NULL;
  2820. unsigned int i;
  2821. bitmap_ones (unreachable_blocks);
  2822. FOR_ALL_BB_FN (bb, cfun)
  2823. {
  2824. bb_info_t bb_info = bb_table[bb->index];
  2825. if (bb_info->gen)
  2826. bitmap_clear (bb_info->gen);
  2827. else
  2828. bb_info->gen = BITMAP_ALLOC (&dse_bitmap_obstack);
  2829. if (bb->index == ENTRY_BLOCK)
  2830. ;
  2831. else if (bb->index == EXIT_BLOCK)
  2832. dse_step3_exit_block_scan (bb_info);
  2833. else
  2834. dse_step3_scan (for_spills, bb);
  2835. if (EDGE_COUNT (bb->succs) == 0)
  2836. mark_reachable_blocks (unreachable_blocks, bb);
  2837. /* If this is the second time dataflow is run, delete the old
  2838. sets. */
  2839. if (bb_info->in)
  2840. BITMAP_FREE (bb_info->in);
  2841. if (bb_info->out)
  2842. BITMAP_FREE (bb_info->out);
  2843. }
  2844. /* For any block in an infinite loop, we must initialize the out set
  2845. to all ones. This could be expensive, but almost never occurs in
  2846. practice. However, it is common in regression tests. */
  2847. EXECUTE_IF_SET_IN_BITMAP (unreachable_blocks, 0, i, sbi)
  2848. {
  2849. if (bitmap_bit_p (all_blocks, i))
  2850. {
  2851. bb_info_t bb_info = bb_table[i];
  2852. if (!all_ones)
  2853. {
  2854. unsigned int j;
  2855. group_info_t group;
  2856. all_ones = BITMAP_ALLOC (&dse_bitmap_obstack);
  2857. FOR_EACH_VEC_ELT (rtx_group_vec, j, group)
  2858. bitmap_ior_into (all_ones, group->group_kill);
  2859. }
  2860. if (!bb_info->out)
  2861. {
  2862. bb_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
  2863. bitmap_copy (bb_info->out, all_ones);
  2864. }
  2865. }
  2866. }
  2867. if (all_ones)
  2868. BITMAP_FREE (all_ones);
  2869. sbitmap_free (unreachable_blocks);
  2870. }
  2871. /*----------------------------------------------------------------------------
  2872. Fourth step.
  2873. Solve the bitvector equations.
  2874. ----------------------------------------------------------------------------*/
  2875. /* Confluence function for blocks with no successors. Create an out
  2876. set from the gen set of the exit block. This block logically has
  2877. the exit block as a successor. */
  2878. static void
  2879. dse_confluence_0 (basic_block bb)
  2880. {
  2881. bb_info_t bb_info = bb_table[bb->index];
  2882. if (bb->index == EXIT_BLOCK)
  2883. return;
  2884. if (!bb_info->out)
  2885. {
  2886. bb_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
  2887. bitmap_copy (bb_info->out, bb_table[EXIT_BLOCK]->gen);
  2888. }
  2889. }
  2890. /* Propagate the information from the in set of the dest of E to the
  2891. out set of the src of E. If the various in or out sets are not
  2892. there, that means they are all ones. */
  2893. static bool
  2894. dse_confluence_n (edge e)
  2895. {
  2896. bb_info_t src_info = bb_table[e->src->index];
  2897. bb_info_t dest_info = bb_table[e->dest->index];
  2898. if (dest_info->in)
  2899. {
  2900. if (src_info->out)
  2901. bitmap_and_into (src_info->out, dest_info->in);
  2902. else
  2903. {
  2904. src_info->out = BITMAP_ALLOC (&dse_bitmap_obstack);
  2905. bitmap_copy (src_info->out, dest_info->in);
  2906. }
  2907. }
  2908. return true;
  2909. }
  2910. /* Propagate the info from the out to the in set of BB_INDEX's basic
  2911. block. There are three cases:
  2912. 1) The block has no kill set. In this case the kill set is all
  2913. ones. It does not matter what the out set of the block is, none of
  2914. the info can reach the top. The only thing that reaches the top is
  2915. the gen set and we just copy the set.
  2916. 2) There is a kill set but no out set and bb has successors. In
  2917. this case we just return. Eventually an out set will be created and
  2918. it is better to wait than to create a set of ones.
  2919. 3) There is both a kill and out set. We apply the obvious transfer
  2920. function.
  2921. */
  2922. static bool
  2923. dse_transfer_function (int bb_index)
  2924. {
  2925. bb_info_t bb_info = bb_table[bb_index];
  2926. if (bb_info->kill)
  2927. {
  2928. if (bb_info->out)
  2929. {
  2930. /* Case 3 above. */
  2931. if (bb_info->in)
  2932. return bitmap_ior_and_compl (bb_info->in, bb_info->gen,
  2933. bb_info->out, bb_info->kill);
  2934. else
  2935. {
  2936. bb_info->in = BITMAP_ALLOC (&dse_bitmap_obstack);
  2937. bitmap_ior_and_compl (bb_info->in, bb_info->gen,
  2938. bb_info->out, bb_info->kill);
  2939. return true;
  2940. }
  2941. }
  2942. else
  2943. /* Case 2 above. */
  2944. return false;
  2945. }
  2946. else
  2947. {
  2948. /* Case 1 above. If there is already an in set, nothing
  2949. happens. */
  2950. if (bb_info->in)
  2951. return false;
  2952. else
  2953. {
  2954. bb_info->in = BITMAP_ALLOC (&dse_bitmap_obstack);
  2955. bitmap_copy (bb_info->in, bb_info->gen);
  2956. return true;
  2957. }
  2958. }
  2959. }
  2960. /* Solve the dataflow equations. */
  2961. static void
  2962. dse_step4 (void)
  2963. {
  2964. df_simple_dataflow (DF_BACKWARD, NULL, dse_confluence_0,
  2965. dse_confluence_n, dse_transfer_function,
  2966. all_blocks, df_get_postorder (DF_BACKWARD),
  2967. df_get_n_blocks (DF_BACKWARD));
  2968. if (dump_file && (dump_flags & TDF_DETAILS))
  2969. {
  2970. basic_block bb;
  2971. fprintf (dump_file, "\n\n*** Global dataflow info after analysis.\n");
  2972. FOR_ALL_BB_FN (bb, cfun)
  2973. {
  2974. bb_info_t bb_info = bb_table[bb->index];
  2975. df_print_bb_index (bb, dump_file);
  2976. if (bb_info->in)
  2977. bitmap_print (dump_file, bb_info->in, " in: ", "\n");
  2978. else
  2979. fprintf (dump_file, " in: *MISSING*\n");
  2980. if (bb_info->gen)
  2981. bitmap_print (dump_file, bb_info->gen, " gen: ", "\n");
  2982. else
  2983. fprintf (dump_file, " gen: *MISSING*\n");
  2984. if (bb_info->kill)
  2985. bitmap_print (dump_file, bb_info->kill, " kill: ", "\n");
  2986. else
  2987. fprintf (dump_file, " kill: *MISSING*\n");
  2988. if (bb_info->out)
  2989. bitmap_print (dump_file, bb_info->out, " out: ", "\n");
  2990. else
  2991. fprintf (dump_file, " out: *MISSING*\n\n");
  2992. }
  2993. }
  2994. }
  2995. /*----------------------------------------------------------------------------
  2996. Fifth step.
  2997. Delete the stores that can only be deleted using the global information.
  2998. ----------------------------------------------------------------------------*/
  2999. static void
  3000. dse_step5_nospill (void)
  3001. {
  3002. basic_block bb;
  3003. FOR_EACH_BB_FN (bb, cfun)
  3004. {
  3005. bb_info_t bb_info = bb_table[bb->index];
  3006. insn_info_t insn_info = bb_info->last_insn;
  3007. bitmap v = bb_info->out;
  3008. while (insn_info)
  3009. {
  3010. bool deleted = false;
  3011. if (dump_file && insn_info->insn)
  3012. {
  3013. fprintf (dump_file, "starting to process insn %d\n",
  3014. INSN_UID (insn_info->insn));
  3015. bitmap_print (dump_file, v, " v: ", "\n");
  3016. }
  3017. /* There may have been code deleted by the dce pass run before
  3018. this phase. */
  3019. if (insn_info->insn
  3020. && INSN_P (insn_info->insn)
  3021. && (!insn_info->cannot_delete)
  3022. && (!bitmap_empty_p (v)))
  3023. {
  3024. store_info_t store_info = insn_info->store_rec;
  3025. /* Try to delete the current insn. */
  3026. deleted = true;
  3027. /* Skip the clobbers. */
  3028. while (!store_info->is_set)
  3029. store_info = store_info->next;
  3030. if (store_info->alias_set)
  3031. deleted = false;
  3032. else
  3033. {
  3034. HOST_WIDE_INT i;
  3035. group_info_t group_info
  3036. = rtx_group_vec[store_info->group_id];
  3037. for (i = store_info->begin; i < store_info->end; i++)
  3038. {
  3039. int index = get_bitmap_index (group_info, i);
  3040. if (dump_file && (dump_flags & TDF_DETAILS))
  3041. fprintf (dump_file, "i = %d, index = %d\n", (int)i, index);
  3042. if (index == 0 || !bitmap_bit_p (v, index))
  3043. {
  3044. if (dump_file && (dump_flags & TDF_DETAILS))
  3045. fprintf (dump_file, "failing at i = %d\n", (int)i);
  3046. deleted = false;
  3047. break;
  3048. }
  3049. }
  3050. }
  3051. if (deleted)
  3052. {
  3053. if (dbg_cnt (dse)
  3054. && check_for_inc_dec_1 (insn_info))
  3055. {
  3056. delete_insn (insn_info->insn);
  3057. insn_info->insn = NULL;
  3058. globally_deleted++;
  3059. }
  3060. }
  3061. }
  3062. /* We do want to process the local info if the insn was
  3063. deleted. For instance, if the insn did a wild read, we
  3064. no longer need to trash the info. */
  3065. if (insn_info->insn
  3066. && INSN_P (insn_info->insn)
  3067. && (!deleted))
  3068. {
  3069. scan_stores_nospill (insn_info->store_rec, v, NULL);
  3070. if (insn_info->wild_read)
  3071. {
  3072. if (dump_file && (dump_flags & TDF_DETAILS))
  3073. fprintf (dump_file, "wild read\n");
  3074. bitmap_clear (v);
  3075. }
  3076. else if (insn_info->read_rec
  3077. || insn_info->non_frame_wild_read)
  3078. {
  3079. if (dump_file && !insn_info->non_frame_wild_read)
  3080. fprintf (dump_file, "regular read\n");
  3081. else if (dump_file && (dump_flags & TDF_DETAILS))
  3082. fprintf (dump_file, "non-frame wild read\n");
  3083. scan_reads_nospill (insn_info, v, NULL);
  3084. }
  3085. }
  3086. insn_info = insn_info->prev_insn;
  3087. }
  3088. }
  3089. }
  3090. /*----------------------------------------------------------------------------
  3091. Sixth step.
  3092. Delete stores made redundant by earlier stores (which store the same
  3093. value) that couldn't be eliminated.
  3094. ----------------------------------------------------------------------------*/
  3095. static void
  3096. dse_step6 (void)
  3097. {
  3098. basic_block bb;
  3099. FOR_ALL_BB_FN (bb, cfun)
  3100. {
  3101. bb_info_t bb_info = bb_table[bb->index];
  3102. insn_info_t insn_info = bb_info->last_insn;
  3103. while (insn_info)
  3104. {
  3105. /* There may have been code deleted by the dce pass run before
  3106. this phase. */
  3107. if (insn_info->insn
  3108. && INSN_P (insn_info->insn)
  3109. && !insn_info->cannot_delete)
  3110. {
  3111. store_info_t s_info = insn_info->store_rec;
  3112. while (s_info && !s_info->is_set)
  3113. s_info = s_info->next;
  3114. if (s_info
  3115. && s_info->redundant_reason
  3116. && s_info->redundant_reason->insn
  3117. && INSN_P (s_info->redundant_reason->insn))
  3118. {
  3119. rtx_insn *rinsn = s_info->redundant_reason->insn;
  3120. if (dump_file && (dump_flags & TDF_DETAILS))
  3121. fprintf (dump_file, "Locally deleting insn %d "
  3122. "because insn %d stores the "
  3123. "same value and couldn't be "
  3124. "eliminated\n",
  3125. INSN_UID (insn_info->insn),
  3126. INSN_UID (rinsn));
  3127. delete_dead_store_insn (insn_info);
  3128. }
  3129. }
  3130. insn_info = insn_info->prev_insn;
  3131. }
  3132. }
  3133. }
  3134. /*----------------------------------------------------------------------------
  3135. Seventh step.
  3136. Destroy everything left standing.
  3137. ----------------------------------------------------------------------------*/
  3138. static void
  3139. dse_step7 (void)
  3140. {
  3141. bitmap_obstack_release (&dse_bitmap_obstack);
  3142. obstack_free (&dse_obstack, NULL);
  3143. end_alias_analysis ();
  3144. free (bb_table);
  3145. delete rtx_group_table;
  3146. rtx_group_table = NULL;
  3147. rtx_group_vec.release ();
  3148. BITMAP_FREE (all_blocks);
  3149. BITMAP_FREE (scratch);
  3150. free_alloc_pool (rtx_store_info_pool);
  3151. free_alloc_pool (read_info_pool);
  3152. free_alloc_pool (insn_info_pool);
  3153. free_alloc_pool (bb_info_pool);
  3154. free_alloc_pool (rtx_group_info_pool);
  3155. free_alloc_pool (deferred_change_pool);
  3156. }
  3157. /* -------------------------------------------------------------------------
  3158. DSE
  3159. ------------------------------------------------------------------------- */
  3160. /* Callback for running pass_rtl_dse. */
  3161. static unsigned int
  3162. rest_of_handle_dse (void)
  3163. {
  3164. df_set_flags (DF_DEFER_INSN_RESCAN);
  3165. /* Need the notes since we must track live hardregs in the forwards
  3166. direction. */
  3167. df_note_add_problem ();
  3168. df_analyze ();
  3169. dse_step0 ();
  3170. dse_step1 ();
  3171. dse_step2_init ();
  3172. if (dse_step2_nospill ())
  3173. {
  3174. df_set_flags (DF_LR_RUN_DCE);
  3175. df_analyze ();
  3176. if (dump_file && (dump_flags & TDF_DETAILS))
  3177. fprintf (dump_file, "doing global processing\n");
  3178. dse_step3 (false);
  3179. dse_step4 ();
  3180. dse_step5_nospill ();
  3181. }
  3182. dse_step6 ();
  3183. dse_step7 ();
  3184. if (dump_file)
  3185. fprintf (dump_file, "dse: local deletions = %d, global deletions = %d, spill deletions = %d\n",
  3186. locally_deleted, globally_deleted, spill_deleted);
  3187. /* DSE can eliminate potentially-trapping MEMs.
  3188. Remove any EH edges associated with them. */
  3189. if ((locally_deleted || globally_deleted)
  3190. && cfun->can_throw_non_call_exceptions
  3191. && purge_all_dead_edges ())
  3192. cleanup_cfg (0);
  3193. return 0;
  3194. }
  3195. namespace {
  3196. const pass_data pass_data_rtl_dse1 =
  3197. {
  3198. RTL_PASS, /* type */
  3199. "dse1", /* name */
  3200. OPTGROUP_NONE, /* optinfo_flags */
  3201. TV_DSE1, /* tv_id */
  3202. 0, /* properties_required */
  3203. 0, /* properties_provided */
  3204. 0, /* properties_destroyed */
  3205. 0, /* todo_flags_start */
  3206. TODO_df_finish, /* todo_flags_finish */
  3207. };
  3208. class pass_rtl_dse1 : public rtl_opt_pass
  3209. {
  3210. public:
  3211. pass_rtl_dse1 (gcc::context *ctxt)
  3212. : rtl_opt_pass (pass_data_rtl_dse1, ctxt)
  3213. {}
  3214. /* opt_pass methods: */
  3215. virtual bool gate (function *)
  3216. {
  3217. return optimize > 0 && flag_dse && dbg_cnt (dse1);
  3218. }
  3219. virtual unsigned int execute (function *) { return rest_of_handle_dse (); }
  3220. }; // class pass_rtl_dse1
  3221. } // anon namespace
  3222. rtl_opt_pass *
  3223. make_pass_rtl_dse1 (gcc::context *ctxt)
  3224. {
  3225. return new pass_rtl_dse1 (ctxt);
  3226. }
  3227. namespace {
  3228. const pass_data pass_data_rtl_dse2 =
  3229. {
  3230. RTL_PASS, /* type */
  3231. "dse2", /* name */
  3232. OPTGROUP_NONE, /* optinfo_flags */
  3233. TV_DSE2, /* tv_id */
  3234. 0, /* properties_required */
  3235. 0, /* properties_provided */
  3236. 0, /* properties_destroyed */
  3237. 0, /* todo_flags_start */
  3238. TODO_df_finish, /* todo_flags_finish */
  3239. };
  3240. class pass_rtl_dse2 : public rtl_opt_pass
  3241. {
  3242. public:
  3243. pass_rtl_dse2 (gcc::context *ctxt)
  3244. : rtl_opt_pass (pass_data_rtl_dse2, ctxt)
  3245. {}
  3246. /* opt_pass methods: */
  3247. virtual bool gate (function *)
  3248. {
  3249. return optimize > 0 && flag_dse && dbg_cnt (dse2);
  3250. }
  3251. virtual unsigned int execute (function *) { return rest_of_handle_dse (); }
  3252. }; // class pass_rtl_dse2
  3253. } // anon namespace
  3254. rtl_opt_pass *
  3255. make_pass_rtl_dse2 (gcc::context *ctxt)
  3256. {
  3257. return new pass_rtl_dse2 (ctxt);
  3258. }