rtlanal.c 164 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043
  1. /* Analyze RTL for GNU compiler.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #include "config.h"
  16. #include "system.h"
  17. #include "coretypes.h"
  18. #include "tm.h"
  19. #include "diagnostic-core.h"
  20. #include "hard-reg-set.h"
  21. #include "rtl.h"
  22. #include "insn-config.h"
  23. #include "recog.h"
  24. #include "target.h"
  25. #include "output.h"
  26. #include "tm_p.h"
  27. #include "flags.h"
  28. #include "regs.h"
  29. #include "hashtab.h"
  30. #include "hash-set.h"
  31. #include "vec.h"
  32. #include "machmode.h"
  33. #include "input.h"
  34. #include "function.h"
  35. #include "predict.h"
  36. #include "basic-block.h"
  37. #include "df.h"
  38. #include "symtab.h"
  39. #include "wide-int.h"
  40. #include "inchash.h"
  41. #include "tree.h"
  42. #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */
  43. #include "addresses.h"
  44. #include "rtl-iter.h"
  45. /* Forward declarations */
  46. static void set_of_1 (rtx, const_rtx, void *);
  47. static bool covers_regno_p (const_rtx, unsigned int);
  48. static bool covers_regno_no_parallel_p (const_rtx, unsigned int);
  49. static int computed_jump_p_1 (const_rtx);
  50. static void parms_set (rtx, const_rtx, void *);
  51. static unsigned HOST_WIDE_INT cached_nonzero_bits (const_rtx, machine_mode,
  52. const_rtx, machine_mode,
  53. unsigned HOST_WIDE_INT);
  54. static unsigned HOST_WIDE_INT nonzero_bits1 (const_rtx, machine_mode,
  55. const_rtx, machine_mode,
  56. unsigned HOST_WIDE_INT);
  57. static unsigned int cached_num_sign_bit_copies (const_rtx, machine_mode, const_rtx,
  58. machine_mode,
  59. unsigned int);
  60. static unsigned int num_sign_bit_copies1 (const_rtx, machine_mode, const_rtx,
  61. machine_mode, unsigned int);
  62. rtx_subrtx_bound_info rtx_all_subrtx_bounds[NUM_RTX_CODE];
  63. rtx_subrtx_bound_info rtx_nonconst_subrtx_bounds[NUM_RTX_CODE];
  64. /* Truncation narrows the mode from SOURCE mode to DESTINATION mode.
  65. If TARGET_MODE_REP_EXTENDED (DESTINATION, DESTINATION_REP) is
  66. SIGN_EXTEND then while narrowing we also have to enforce the
  67. representation and sign-extend the value to mode DESTINATION_REP.
  68. If the value is already sign-extended to DESTINATION_REP mode we
  69. can just switch to DESTINATION mode on it. For each pair of
  70. integral modes SOURCE and DESTINATION, when truncating from SOURCE
  71. to DESTINATION, NUM_SIGN_BIT_COPIES_IN_REP[SOURCE][DESTINATION]
  72. contains the number of high-order bits in SOURCE that have to be
  73. copies of the sign-bit so that we can do this mode-switch to
  74. DESTINATION. */
  75. static unsigned int
  76. num_sign_bit_copies_in_rep[MAX_MODE_INT + 1][MAX_MODE_INT + 1];
  77. /* Store X into index I of ARRAY. ARRAY is known to have at least I
  78. elements. Return the new base of ARRAY. */
  79. template <typename T>
  80. typename T::value_type *
  81. generic_subrtx_iterator <T>::add_single_to_queue (array_type &array,
  82. value_type *base,
  83. size_t i, value_type x)
  84. {
  85. if (base == array.stack)
  86. {
  87. if (i < LOCAL_ELEMS)
  88. {
  89. base[i] = x;
  90. return base;
  91. }
  92. gcc_checking_assert (i == LOCAL_ELEMS);
  93. vec_safe_grow (array.heap, i + 1);
  94. base = array.heap->address ();
  95. memcpy (base, array.stack, sizeof (array.stack));
  96. base[LOCAL_ELEMS] = x;
  97. return base;
  98. }
  99. unsigned int length = array.heap->length ();
  100. if (length > i)
  101. {
  102. gcc_checking_assert (base == array.heap->address ());
  103. base[i] = x;
  104. return base;
  105. }
  106. else
  107. {
  108. gcc_checking_assert (i == length);
  109. vec_safe_push (array.heap, x);
  110. return array.heap->address ();
  111. }
  112. }
  113. /* Add the subrtxes of X to worklist ARRAY, starting at END. Return the
  114. number of elements added to the worklist. */
  115. template <typename T>
  116. size_t
  117. generic_subrtx_iterator <T>::add_subrtxes_to_queue (array_type &array,
  118. value_type *base,
  119. size_t end, rtx_type x)
  120. {
  121. enum rtx_code code = GET_CODE (x);
  122. const char *format = GET_RTX_FORMAT (code);
  123. size_t orig_end = end;
  124. if (__builtin_expect (INSN_P (x), false))
  125. {
  126. /* Put the pattern at the top of the queue, since that's what
  127. we're likely to want most. It also allows for the SEQUENCE
  128. code below. */
  129. for (int i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; --i)
  130. if (format[i] == 'e')
  131. {
  132. value_type subx = T::get_value (x->u.fld[i].rt_rtx);
  133. if (__builtin_expect (end < LOCAL_ELEMS, true))
  134. base[end++] = subx;
  135. else
  136. base = add_single_to_queue (array, base, end++, subx);
  137. }
  138. }
  139. else
  140. for (int i = 0; format[i]; ++i)
  141. if (format[i] == 'e')
  142. {
  143. value_type subx = T::get_value (x->u.fld[i].rt_rtx);
  144. if (__builtin_expect (end < LOCAL_ELEMS, true))
  145. base[end++] = subx;
  146. else
  147. base = add_single_to_queue (array, base, end++, subx);
  148. }
  149. else if (format[i] == 'E')
  150. {
  151. unsigned int length = GET_NUM_ELEM (x->u.fld[i].rt_rtvec);
  152. rtx *vec = x->u.fld[i].rt_rtvec->elem;
  153. if (__builtin_expect (end + length <= LOCAL_ELEMS, true))
  154. for (unsigned int j = 0; j < length; j++)
  155. base[end++] = T::get_value (vec[j]);
  156. else
  157. for (unsigned int j = 0; j < length; j++)
  158. base = add_single_to_queue (array, base, end++,
  159. T::get_value (vec[j]));
  160. if (code == SEQUENCE && end == length)
  161. /* If the subrtxes of the sequence fill the entire array then
  162. we know that no other parts of a containing insn are queued.
  163. The caller is therefore iterating over the sequence as a
  164. PATTERN (...), so we also want the patterns of the
  165. subinstructions. */
  166. for (unsigned int j = 0; j < length; j++)
  167. {
  168. typename T::rtx_type x = T::get_rtx (base[j]);
  169. if (INSN_P (x))
  170. base[j] = T::get_value (PATTERN (x));
  171. }
  172. }
  173. return end - orig_end;
  174. }
  175. template <typename T>
  176. void
  177. generic_subrtx_iterator <T>::free_array (array_type &array)
  178. {
  179. vec_free (array.heap);
  180. }
  181. template <typename T>
  182. const size_t generic_subrtx_iterator <T>::LOCAL_ELEMS;
  183. template class generic_subrtx_iterator <const_rtx_accessor>;
  184. template class generic_subrtx_iterator <rtx_var_accessor>;
  185. template class generic_subrtx_iterator <rtx_ptr_accessor>;
  186. /* Return 1 if the value of X is unstable
  187. (would be different at a different point in the program).
  188. The frame pointer, arg pointer, etc. are considered stable
  189. (within one function) and so is anything marked `unchanging'. */
  190. int
  191. rtx_unstable_p (const_rtx x)
  192. {
  193. const RTX_CODE code = GET_CODE (x);
  194. int i;
  195. const char *fmt;
  196. switch (code)
  197. {
  198. case MEM:
  199. return !MEM_READONLY_P (x) || rtx_unstable_p (XEXP (x, 0));
  200. case CONST:
  201. CASE_CONST_ANY:
  202. case SYMBOL_REF:
  203. case LABEL_REF:
  204. return 0;
  205. case REG:
  206. /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
  207. if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
  208. /* The arg pointer varies if it is not a fixed register. */
  209. || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
  210. return 0;
  211. /* ??? When call-clobbered, the value is stable modulo the restore
  212. that must happen after a call. This currently screws up local-alloc
  213. into believing that the restore is not needed. */
  214. if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED && x == pic_offset_table_rtx)
  215. return 0;
  216. return 1;
  217. case ASM_OPERANDS:
  218. if (MEM_VOLATILE_P (x))
  219. return 1;
  220. /* Fall through. */
  221. default:
  222. break;
  223. }
  224. fmt = GET_RTX_FORMAT (code);
  225. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  226. if (fmt[i] == 'e')
  227. {
  228. if (rtx_unstable_p (XEXP (x, i)))
  229. return 1;
  230. }
  231. else if (fmt[i] == 'E')
  232. {
  233. int j;
  234. for (j = 0; j < XVECLEN (x, i); j++)
  235. if (rtx_unstable_p (XVECEXP (x, i, j)))
  236. return 1;
  237. }
  238. return 0;
  239. }
  240. /* Return 1 if X has a value that can vary even between two
  241. executions of the program. 0 means X can be compared reliably
  242. against certain constants or near-constants.
  243. FOR_ALIAS is nonzero if we are called from alias analysis; if it is
  244. zero, we are slightly more conservative.
  245. The frame pointer and the arg pointer are considered constant. */
  246. bool
  247. rtx_varies_p (const_rtx x, bool for_alias)
  248. {
  249. RTX_CODE code;
  250. int i;
  251. const char *fmt;
  252. if (!x)
  253. return 0;
  254. code = GET_CODE (x);
  255. switch (code)
  256. {
  257. case MEM:
  258. return !MEM_READONLY_P (x) || rtx_varies_p (XEXP (x, 0), for_alias);
  259. case CONST:
  260. CASE_CONST_ANY:
  261. case SYMBOL_REF:
  262. case LABEL_REF:
  263. return 0;
  264. case REG:
  265. /* Note that we have to test for the actual rtx used for the frame
  266. and arg pointers and not just the register number in case we have
  267. eliminated the frame and/or arg pointer and are using it
  268. for pseudos. */
  269. if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
  270. /* The arg pointer varies if it is not a fixed register. */
  271. || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
  272. return 0;
  273. if (x == pic_offset_table_rtx
  274. /* ??? When call-clobbered, the value is stable modulo the restore
  275. that must happen after a call. This currently screws up
  276. local-alloc into believing that the restore is not needed, so we
  277. must return 0 only if we are called from alias analysis. */
  278. && (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED || for_alias))
  279. return 0;
  280. return 1;
  281. case LO_SUM:
  282. /* The operand 0 of a LO_SUM is considered constant
  283. (in fact it is related specifically to operand 1)
  284. during alias analysis. */
  285. return (! for_alias && rtx_varies_p (XEXP (x, 0), for_alias))
  286. || rtx_varies_p (XEXP (x, 1), for_alias);
  287. case ASM_OPERANDS:
  288. if (MEM_VOLATILE_P (x))
  289. return 1;
  290. /* Fall through. */
  291. default:
  292. break;
  293. }
  294. fmt = GET_RTX_FORMAT (code);
  295. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  296. if (fmt[i] == 'e')
  297. {
  298. if (rtx_varies_p (XEXP (x, i), for_alias))
  299. return 1;
  300. }
  301. else if (fmt[i] == 'E')
  302. {
  303. int j;
  304. for (j = 0; j < XVECLEN (x, i); j++)
  305. if (rtx_varies_p (XVECEXP (x, i, j), for_alias))
  306. return 1;
  307. }
  308. return 0;
  309. }
  310. /* Return nonzero if the use of X+OFFSET as an address in a MEM with SIZE
  311. bytes can cause a trap. MODE is the mode of the MEM (not that of X) and
  312. UNALIGNED_MEMS controls whether nonzero is returned for unaligned memory
  313. references on strict alignment machines. */
  314. static int
  315. rtx_addr_can_trap_p_1 (const_rtx x, HOST_WIDE_INT offset, HOST_WIDE_INT size,
  316. machine_mode mode, bool unaligned_mems)
  317. {
  318. enum rtx_code code = GET_CODE (x);
  319. /* The offset must be a multiple of the mode size if we are considering
  320. unaligned memory references on strict alignment machines. */
  321. if (STRICT_ALIGNMENT && unaligned_mems && GET_MODE_SIZE (mode) != 0)
  322. {
  323. HOST_WIDE_INT actual_offset = offset;
  324. #ifdef SPARC_STACK_BOUNDARY_HACK
  325. /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
  326. the real alignment of %sp. However, when it does this, the
  327. alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
  328. if (SPARC_STACK_BOUNDARY_HACK
  329. && (x == stack_pointer_rtx || x == hard_frame_pointer_rtx))
  330. actual_offset -= STACK_POINTER_OFFSET;
  331. #endif
  332. if (actual_offset % GET_MODE_SIZE (mode) != 0)
  333. return 1;
  334. }
  335. switch (code)
  336. {
  337. case SYMBOL_REF:
  338. if (SYMBOL_REF_WEAK (x))
  339. return 1;
  340. if (!CONSTANT_POOL_ADDRESS_P (x))
  341. {
  342. tree decl;
  343. HOST_WIDE_INT decl_size;
  344. if (offset < 0)
  345. return 1;
  346. if (size == 0)
  347. size = GET_MODE_SIZE (mode);
  348. if (size == 0)
  349. return offset != 0;
  350. /* If the size of the access or of the symbol is unknown,
  351. assume the worst. */
  352. decl = SYMBOL_REF_DECL (x);
  353. /* Else check that the access is in bounds. TODO: restructure
  354. expr_size/tree_expr_size/int_expr_size and just use the latter. */
  355. if (!decl)
  356. decl_size = -1;
  357. else if (DECL_P (decl) && DECL_SIZE_UNIT (decl))
  358. decl_size = (tree_fits_shwi_p (DECL_SIZE_UNIT (decl))
  359. ? tree_to_shwi (DECL_SIZE_UNIT (decl))
  360. : -1);
  361. else if (TREE_CODE (decl) == STRING_CST)
  362. decl_size = TREE_STRING_LENGTH (decl);
  363. else if (TYPE_SIZE_UNIT (TREE_TYPE (decl)))
  364. decl_size = int_size_in_bytes (TREE_TYPE (decl));
  365. else
  366. decl_size = -1;
  367. return (decl_size <= 0 ? offset != 0 : offset + size > decl_size);
  368. }
  369. return 0;
  370. case LABEL_REF:
  371. return 0;
  372. case REG:
  373. /* Stack references are assumed not to trap, but we need to deal with
  374. nonsensical offsets. */
  375. if (x == frame_pointer_rtx)
  376. {
  377. HOST_WIDE_INT adj_offset = offset - STARTING_FRAME_OFFSET;
  378. if (size == 0)
  379. size = GET_MODE_SIZE (mode);
  380. if (FRAME_GROWS_DOWNWARD)
  381. {
  382. if (adj_offset < frame_offset || adj_offset + size - 1 >= 0)
  383. return 1;
  384. }
  385. else
  386. {
  387. if (adj_offset < 0 || adj_offset + size - 1 >= frame_offset)
  388. return 1;
  389. }
  390. return 0;
  391. }
  392. /* ??? Need to add a similar guard for nonsensical offsets. */
  393. if (x == hard_frame_pointer_rtx
  394. || x == stack_pointer_rtx
  395. /* The arg pointer varies if it is not a fixed register. */
  396. || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
  397. return 0;
  398. /* All of the virtual frame registers are stack references. */
  399. if (REGNO (x) >= FIRST_VIRTUAL_REGISTER
  400. && REGNO (x) <= LAST_VIRTUAL_REGISTER)
  401. return 0;
  402. return 1;
  403. case CONST:
  404. return rtx_addr_can_trap_p_1 (XEXP (x, 0), offset, size,
  405. mode, unaligned_mems);
  406. case PLUS:
  407. /* An address is assumed not to trap if:
  408. - it is the pic register plus a constant. */
  409. if (XEXP (x, 0) == pic_offset_table_rtx && CONSTANT_P (XEXP (x, 1)))
  410. return 0;
  411. /* - or it is an address that can't trap plus a constant integer. */
  412. if (CONST_INT_P (XEXP (x, 1))
  413. && !rtx_addr_can_trap_p_1 (XEXP (x, 0), offset + INTVAL (XEXP (x, 1)),
  414. size, mode, unaligned_mems))
  415. return 0;
  416. return 1;
  417. case LO_SUM:
  418. case PRE_MODIFY:
  419. return rtx_addr_can_trap_p_1 (XEXP (x, 1), offset, size,
  420. mode, unaligned_mems);
  421. case PRE_DEC:
  422. case PRE_INC:
  423. case POST_DEC:
  424. case POST_INC:
  425. case POST_MODIFY:
  426. return rtx_addr_can_trap_p_1 (XEXP (x, 0), offset, size,
  427. mode, unaligned_mems);
  428. default:
  429. break;
  430. }
  431. /* If it isn't one of the case above, it can cause a trap. */
  432. return 1;
  433. }
  434. /* Return nonzero if the use of X as an address in a MEM can cause a trap. */
  435. int
  436. rtx_addr_can_trap_p (const_rtx x)
  437. {
  438. return rtx_addr_can_trap_p_1 (x, 0, 0, VOIDmode, false);
  439. }
  440. /* Return true if X is an address that is known to not be zero. */
  441. bool
  442. nonzero_address_p (const_rtx x)
  443. {
  444. const enum rtx_code code = GET_CODE (x);
  445. switch (code)
  446. {
  447. case SYMBOL_REF:
  448. return !SYMBOL_REF_WEAK (x);
  449. case LABEL_REF:
  450. return true;
  451. case REG:
  452. /* As in rtx_varies_p, we have to use the actual rtx, not reg number. */
  453. if (x == frame_pointer_rtx || x == hard_frame_pointer_rtx
  454. || x == stack_pointer_rtx
  455. || (x == arg_pointer_rtx && fixed_regs[ARG_POINTER_REGNUM]))
  456. return true;
  457. /* All of the virtual frame registers are stack references. */
  458. if (REGNO (x) >= FIRST_VIRTUAL_REGISTER
  459. && REGNO (x) <= LAST_VIRTUAL_REGISTER)
  460. return true;
  461. return false;
  462. case CONST:
  463. return nonzero_address_p (XEXP (x, 0));
  464. case PLUS:
  465. /* Handle PIC references. */
  466. if (XEXP (x, 0) == pic_offset_table_rtx
  467. && CONSTANT_P (XEXP (x, 1)))
  468. return true;
  469. return false;
  470. case PRE_MODIFY:
  471. /* Similar to the above; allow positive offsets. Further, since
  472. auto-inc is only allowed in memories, the register must be a
  473. pointer. */
  474. if (CONST_INT_P (XEXP (x, 1))
  475. && INTVAL (XEXP (x, 1)) > 0)
  476. return true;
  477. return nonzero_address_p (XEXP (x, 0));
  478. case PRE_INC:
  479. /* Similarly. Further, the offset is always positive. */
  480. return true;
  481. case PRE_DEC:
  482. case POST_DEC:
  483. case POST_INC:
  484. case POST_MODIFY:
  485. return nonzero_address_p (XEXP (x, 0));
  486. case LO_SUM:
  487. return nonzero_address_p (XEXP (x, 1));
  488. default:
  489. break;
  490. }
  491. /* If it isn't one of the case above, might be zero. */
  492. return false;
  493. }
  494. /* Return 1 if X refers to a memory location whose address
  495. cannot be compared reliably with constant addresses,
  496. or if X refers to a BLKmode memory object.
  497. FOR_ALIAS is nonzero if we are called from alias analysis; if it is
  498. zero, we are slightly more conservative. */
  499. bool
  500. rtx_addr_varies_p (const_rtx x, bool for_alias)
  501. {
  502. enum rtx_code code;
  503. int i;
  504. const char *fmt;
  505. if (x == 0)
  506. return 0;
  507. code = GET_CODE (x);
  508. if (code == MEM)
  509. return GET_MODE (x) == BLKmode || rtx_varies_p (XEXP (x, 0), for_alias);
  510. fmt = GET_RTX_FORMAT (code);
  511. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  512. if (fmt[i] == 'e')
  513. {
  514. if (rtx_addr_varies_p (XEXP (x, i), for_alias))
  515. return 1;
  516. }
  517. else if (fmt[i] == 'E')
  518. {
  519. int j;
  520. for (j = 0; j < XVECLEN (x, i); j++)
  521. if (rtx_addr_varies_p (XVECEXP (x, i, j), for_alias))
  522. return 1;
  523. }
  524. return 0;
  525. }
  526. /* Return the CALL in X if there is one. */
  527. rtx
  528. get_call_rtx_from (rtx x)
  529. {
  530. if (INSN_P (x))
  531. x = PATTERN (x);
  532. if (GET_CODE (x) == PARALLEL)
  533. x = XVECEXP (x, 0, 0);
  534. if (GET_CODE (x) == SET)
  535. x = SET_SRC (x);
  536. if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
  537. return x;
  538. return NULL_RTX;
  539. }
  540. /* Return the value of the integer term in X, if one is apparent;
  541. otherwise return 0.
  542. Only obvious integer terms are detected.
  543. This is used in cse.c with the `related_value' field. */
  544. HOST_WIDE_INT
  545. get_integer_term (const_rtx x)
  546. {
  547. if (GET_CODE (x) == CONST)
  548. x = XEXP (x, 0);
  549. if (GET_CODE (x) == MINUS
  550. && CONST_INT_P (XEXP (x, 1)))
  551. return - INTVAL (XEXP (x, 1));
  552. if (GET_CODE (x) == PLUS
  553. && CONST_INT_P (XEXP (x, 1)))
  554. return INTVAL (XEXP (x, 1));
  555. return 0;
  556. }
  557. /* If X is a constant, return the value sans apparent integer term;
  558. otherwise return 0.
  559. Only obvious integer terms are detected. */
  560. rtx
  561. get_related_value (const_rtx x)
  562. {
  563. if (GET_CODE (x) != CONST)
  564. return 0;
  565. x = XEXP (x, 0);
  566. if (GET_CODE (x) == PLUS
  567. && CONST_INT_P (XEXP (x, 1)))
  568. return XEXP (x, 0);
  569. else if (GET_CODE (x) == MINUS
  570. && CONST_INT_P (XEXP (x, 1)))
  571. return XEXP (x, 0);
  572. return 0;
  573. }
  574. /* Return true if SYMBOL is a SYMBOL_REF and OFFSET + SYMBOL points
  575. to somewhere in the same object or object_block as SYMBOL. */
  576. bool
  577. offset_within_block_p (const_rtx symbol, HOST_WIDE_INT offset)
  578. {
  579. tree decl;
  580. if (GET_CODE (symbol) != SYMBOL_REF)
  581. return false;
  582. if (offset == 0)
  583. return true;
  584. if (offset > 0)
  585. {
  586. if (CONSTANT_POOL_ADDRESS_P (symbol)
  587. && offset < (int) GET_MODE_SIZE (get_pool_mode (symbol)))
  588. return true;
  589. decl = SYMBOL_REF_DECL (symbol);
  590. if (decl && offset < int_size_in_bytes (TREE_TYPE (decl)))
  591. return true;
  592. }
  593. if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol)
  594. && SYMBOL_REF_BLOCK (symbol)
  595. && SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0
  596. && ((unsigned HOST_WIDE_INT) offset + SYMBOL_REF_BLOCK_OFFSET (symbol)
  597. < (unsigned HOST_WIDE_INT) SYMBOL_REF_BLOCK (symbol)->size))
  598. return true;
  599. return false;
  600. }
  601. /* Split X into a base and a constant offset, storing them in *BASE_OUT
  602. and *OFFSET_OUT respectively. */
  603. void
  604. split_const (rtx x, rtx *base_out, rtx *offset_out)
  605. {
  606. if (GET_CODE (x) == CONST)
  607. {
  608. x = XEXP (x, 0);
  609. if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
  610. {
  611. *base_out = XEXP (x, 0);
  612. *offset_out = XEXP (x, 1);
  613. return;
  614. }
  615. }
  616. *base_out = x;
  617. *offset_out = const0_rtx;
  618. }
  619. /* Return the number of places FIND appears within X. If COUNT_DEST is
  620. zero, we do not count occurrences inside the destination of a SET. */
  621. int
  622. count_occurrences (const_rtx x, const_rtx find, int count_dest)
  623. {
  624. int i, j;
  625. enum rtx_code code;
  626. const char *format_ptr;
  627. int count;
  628. if (x == find)
  629. return 1;
  630. code = GET_CODE (x);
  631. switch (code)
  632. {
  633. case REG:
  634. CASE_CONST_ANY:
  635. case SYMBOL_REF:
  636. case CODE_LABEL:
  637. case PC:
  638. case CC0:
  639. return 0;
  640. case EXPR_LIST:
  641. count = count_occurrences (XEXP (x, 0), find, count_dest);
  642. if (XEXP (x, 1))
  643. count += count_occurrences (XEXP (x, 1), find, count_dest);
  644. return count;
  645. case MEM:
  646. if (MEM_P (find) && rtx_equal_p (x, find))
  647. return 1;
  648. break;
  649. case SET:
  650. if (SET_DEST (x) == find && ! count_dest)
  651. return count_occurrences (SET_SRC (x), find, count_dest);
  652. break;
  653. default:
  654. break;
  655. }
  656. format_ptr = GET_RTX_FORMAT (code);
  657. count = 0;
  658. for (i = 0; i < GET_RTX_LENGTH (code); i++)
  659. {
  660. switch (*format_ptr++)
  661. {
  662. case 'e':
  663. count += count_occurrences (XEXP (x, i), find, count_dest);
  664. break;
  665. case 'E':
  666. for (j = 0; j < XVECLEN (x, i); j++)
  667. count += count_occurrences (XVECEXP (x, i, j), find, count_dest);
  668. break;
  669. }
  670. }
  671. return count;
  672. }
  673. /* Return TRUE if OP is a register or subreg of a register that
  674. holds an unsigned quantity. Otherwise, return FALSE. */
  675. bool
  676. unsigned_reg_p (rtx op)
  677. {
  678. if (REG_P (op)
  679. && REG_EXPR (op)
  680. && TYPE_UNSIGNED (TREE_TYPE (REG_EXPR (op))))
  681. return true;
  682. if (GET_CODE (op) == SUBREG
  683. && SUBREG_PROMOTED_SIGN (op))
  684. return true;
  685. return false;
  686. }
  687. /* Nonzero if register REG appears somewhere within IN.
  688. Also works if REG is not a register; in this case it checks
  689. for a subexpression of IN that is Lisp "equal" to REG. */
  690. int
  691. reg_mentioned_p (const_rtx reg, const_rtx in)
  692. {
  693. const char *fmt;
  694. int i;
  695. enum rtx_code code;
  696. if (in == 0)
  697. return 0;
  698. if (reg == in)
  699. return 1;
  700. if (GET_CODE (in) == LABEL_REF)
  701. return reg == LABEL_REF_LABEL (in);
  702. code = GET_CODE (in);
  703. switch (code)
  704. {
  705. /* Compare registers by number. */
  706. case REG:
  707. return REG_P (reg) && REGNO (in) == REGNO (reg);
  708. /* These codes have no constituent expressions
  709. and are unique. */
  710. case SCRATCH:
  711. case CC0:
  712. case PC:
  713. return 0;
  714. CASE_CONST_ANY:
  715. /* These are kept unique for a given value. */
  716. return 0;
  717. default:
  718. break;
  719. }
  720. if (GET_CODE (reg) == code && rtx_equal_p (reg, in))
  721. return 1;
  722. fmt = GET_RTX_FORMAT (code);
  723. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  724. {
  725. if (fmt[i] == 'E')
  726. {
  727. int j;
  728. for (j = XVECLEN (in, i) - 1; j >= 0; j--)
  729. if (reg_mentioned_p (reg, XVECEXP (in, i, j)))
  730. return 1;
  731. }
  732. else if (fmt[i] == 'e'
  733. && reg_mentioned_p (reg, XEXP (in, i)))
  734. return 1;
  735. }
  736. return 0;
  737. }
  738. /* Return 1 if in between BEG and END, exclusive of BEG and END, there is
  739. no CODE_LABEL insn. */
  740. int
  741. no_labels_between_p (const rtx_insn *beg, const rtx_insn *end)
  742. {
  743. rtx_insn *p;
  744. if (beg == end)
  745. return 0;
  746. for (p = NEXT_INSN (beg); p != end; p = NEXT_INSN (p))
  747. if (LABEL_P (p))
  748. return 0;
  749. return 1;
  750. }
  751. /* Nonzero if register REG is used in an insn between
  752. FROM_INSN and TO_INSN (exclusive of those two). */
  753. int
  754. reg_used_between_p (const_rtx reg, const rtx_insn *from_insn,
  755. const rtx_insn *to_insn)
  756. {
  757. rtx_insn *insn;
  758. if (from_insn == to_insn)
  759. return 0;
  760. for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
  761. if (NONDEBUG_INSN_P (insn)
  762. && (reg_overlap_mentioned_p (reg, PATTERN (insn))
  763. || (CALL_P (insn) && find_reg_fusage (insn, USE, reg))))
  764. return 1;
  765. return 0;
  766. }
  767. /* Nonzero if the old value of X, a register, is referenced in BODY. If X
  768. is entirely replaced by a new value and the only use is as a SET_DEST,
  769. we do not consider it a reference. */
  770. int
  771. reg_referenced_p (const_rtx x, const_rtx body)
  772. {
  773. int i;
  774. switch (GET_CODE (body))
  775. {
  776. case SET:
  777. if (reg_overlap_mentioned_p (x, SET_SRC (body)))
  778. return 1;
  779. /* If the destination is anything other than CC0, PC, a REG or a SUBREG
  780. of a REG that occupies all of the REG, the insn references X if
  781. it is mentioned in the destination. */
  782. if (GET_CODE (SET_DEST (body)) != CC0
  783. && GET_CODE (SET_DEST (body)) != PC
  784. && !REG_P (SET_DEST (body))
  785. && ! (GET_CODE (SET_DEST (body)) == SUBREG
  786. && REG_P (SUBREG_REG (SET_DEST (body)))
  787. && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (body))))
  788. + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
  789. == ((GET_MODE_SIZE (GET_MODE (SET_DEST (body)))
  790. + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
  791. && reg_overlap_mentioned_p (x, SET_DEST (body)))
  792. return 1;
  793. return 0;
  794. case ASM_OPERANDS:
  795. for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
  796. if (reg_overlap_mentioned_p (x, ASM_OPERANDS_INPUT (body, i)))
  797. return 1;
  798. return 0;
  799. case CALL:
  800. case USE:
  801. case IF_THEN_ELSE:
  802. return reg_overlap_mentioned_p (x, body);
  803. case TRAP_IF:
  804. return reg_overlap_mentioned_p (x, TRAP_CONDITION (body));
  805. case PREFETCH:
  806. return reg_overlap_mentioned_p (x, XEXP (body, 0));
  807. case UNSPEC:
  808. case UNSPEC_VOLATILE:
  809. for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
  810. if (reg_overlap_mentioned_p (x, XVECEXP (body, 0, i)))
  811. return 1;
  812. return 0;
  813. case PARALLEL:
  814. for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
  815. if (reg_referenced_p (x, XVECEXP (body, 0, i)))
  816. return 1;
  817. return 0;
  818. case CLOBBER:
  819. if (MEM_P (XEXP (body, 0)))
  820. if (reg_overlap_mentioned_p (x, XEXP (XEXP (body, 0), 0)))
  821. return 1;
  822. return 0;
  823. case COND_EXEC:
  824. if (reg_overlap_mentioned_p (x, COND_EXEC_TEST (body)))
  825. return 1;
  826. return reg_referenced_p (x, COND_EXEC_CODE (body));
  827. default:
  828. return 0;
  829. }
  830. }
  831. /* Nonzero if register REG is set or clobbered in an insn between
  832. FROM_INSN and TO_INSN (exclusive of those two). */
  833. int
  834. reg_set_between_p (const_rtx reg, const rtx_insn *from_insn,
  835. const rtx_insn *to_insn)
  836. {
  837. const rtx_insn *insn;
  838. if (from_insn == to_insn)
  839. return 0;
  840. for (insn = NEXT_INSN (from_insn); insn != to_insn; insn = NEXT_INSN (insn))
  841. if (INSN_P (insn) && reg_set_p (reg, insn))
  842. return 1;
  843. return 0;
  844. }
  845. /* Internals of reg_set_between_p. */
  846. int
  847. reg_set_p (const_rtx reg, const_rtx insn)
  848. {
  849. /* After delay slot handling, call and branch insns might be in a
  850. sequence. Check all the elements there. */
  851. if (INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
  852. {
  853. for (int i = 0; i < XVECLEN (PATTERN (insn), 0); ++i)
  854. if (reg_set_p (reg, XVECEXP (PATTERN (insn), 0, i)))
  855. return true;
  856. return false;
  857. }
  858. /* We can be passed an insn or part of one. If we are passed an insn,
  859. check if a side-effect of the insn clobbers REG. */
  860. if (INSN_P (insn)
  861. && (FIND_REG_INC_NOTE (insn, reg)
  862. || (CALL_P (insn)
  863. && ((REG_P (reg)
  864. && REGNO (reg) < FIRST_PSEUDO_REGISTER
  865. && overlaps_hard_reg_set_p (regs_invalidated_by_call,
  866. GET_MODE (reg), REGNO (reg)))
  867. || MEM_P (reg)
  868. || find_reg_fusage (insn, CLOBBER, reg)))))
  869. return true;
  870. return set_of (reg, insn) != NULL_RTX;
  871. }
  872. /* Similar to reg_set_between_p, but check all registers in X. Return 0
  873. only if none of them are modified between START and END. Return 1 if
  874. X contains a MEM; this routine does use memory aliasing. */
  875. int
  876. modified_between_p (const_rtx x, const rtx_insn *start, const rtx_insn *end)
  877. {
  878. const enum rtx_code code = GET_CODE (x);
  879. const char *fmt;
  880. int i, j;
  881. rtx_insn *insn;
  882. if (start == end)
  883. return 0;
  884. switch (code)
  885. {
  886. CASE_CONST_ANY:
  887. case CONST:
  888. case SYMBOL_REF:
  889. case LABEL_REF:
  890. return 0;
  891. case PC:
  892. case CC0:
  893. return 1;
  894. case MEM:
  895. if (modified_between_p (XEXP (x, 0), start, end))
  896. return 1;
  897. if (MEM_READONLY_P (x))
  898. return 0;
  899. for (insn = NEXT_INSN (start); insn != end; insn = NEXT_INSN (insn))
  900. if (memory_modified_in_insn_p (x, insn))
  901. return 1;
  902. return 0;
  903. break;
  904. case REG:
  905. return reg_set_between_p (x, start, end);
  906. default:
  907. break;
  908. }
  909. fmt = GET_RTX_FORMAT (code);
  910. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  911. {
  912. if (fmt[i] == 'e' && modified_between_p (XEXP (x, i), start, end))
  913. return 1;
  914. else if (fmt[i] == 'E')
  915. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  916. if (modified_between_p (XVECEXP (x, i, j), start, end))
  917. return 1;
  918. }
  919. return 0;
  920. }
  921. /* Similar to reg_set_p, but check all registers in X. Return 0 only if none
  922. of them are modified in INSN. Return 1 if X contains a MEM; this routine
  923. does use memory aliasing. */
  924. int
  925. modified_in_p (const_rtx x, const_rtx insn)
  926. {
  927. const enum rtx_code code = GET_CODE (x);
  928. const char *fmt;
  929. int i, j;
  930. switch (code)
  931. {
  932. CASE_CONST_ANY:
  933. case CONST:
  934. case SYMBOL_REF:
  935. case LABEL_REF:
  936. return 0;
  937. case PC:
  938. case CC0:
  939. return 1;
  940. case MEM:
  941. if (modified_in_p (XEXP (x, 0), insn))
  942. return 1;
  943. if (MEM_READONLY_P (x))
  944. return 0;
  945. if (memory_modified_in_insn_p (x, insn))
  946. return 1;
  947. return 0;
  948. break;
  949. case REG:
  950. return reg_set_p (x, insn);
  951. default:
  952. break;
  953. }
  954. fmt = GET_RTX_FORMAT (code);
  955. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  956. {
  957. if (fmt[i] == 'e' && modified_in_p (XEXP (x, i), insn))
  958. return 1;
  959. else if (fmt[i] == 'E')
  960. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  961. if (modified_in_p (XVECEXP (x, i, j), insn))
  962. return 1;
  963. }
  964. return 0;
  965. }
  966. /* Helper function for set_of. */
  967. struct set_of_data
  968. {
  969. const_rtx found;
  970. const_rtx pat;
  971. };
  972. static void
  973. set_of_1 (rtx x, const_rtx pat, void *data1)
  974. {
  975. struct set_of_data *const data = (struct set_of_data *) (data1);
  976. if (rtx_equal_p (x, data->pat)
  977. || (!MEM_P (x) && reg_overlap_mentioned_p (data->pat, x)))
  978. data->found = pat;
  979. }
  980. /* Give an INSN, return a SET or CLOBBER expression that does modify PAT
  981. (either directly or via STRICT_LOW_PART and similar modifiers). */
  982. const_rtx
  983. set_of (const_rtx pat, const_rtx insn)
  984. {
  985. struct set_of_data data;
  986. data.found = NULL_RTX;
  987. data.pat = pat;
  988. note_stores (INSN_P (insn) ? PATTERN (insn) : insn, set_of_1, &data);
  989. return data.found;
  990. }
  991. /* Add all hard register in X to *PSET. */
  992. void
  993. find_all_hard_regs (const_rtx x, HARD_REG_SET *pset)
  994. {
  995. subrtx_iterator::array_type array;
  996. FOR_EACH_SUBRTX (iter, array, x, NONCONST)
  997. {
  998. const_rtx x = *iter;
  999. if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
  1000. add_to_hard_reg_set (pset, GET_MODE (x), REGNO (x));
  1001. }
  1002. }
  1003. /* This function, called through note_stores, collects sets and
  1004. clobbers of hard registers in a HARD_REG_SET, which is pointed to
  1005. by DATA. */
  1006. void
  1007. record_hard_reg_sets (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
  1008. {
  1009. HARD_REG_SET *pset = (HARD_REG_SET *)data;
  1010. if (REG_P (x) && HARD_REGISTER_P (x))
  1011. add_to_hard_reg_set (pset, GET_MODE (x), REGNO (x));
  1012. }
  1013. /* Examine INSN, and compute the set of hard registers written by it.
  1014. Store it in *PSET. Should only be called after reload. */
  1015. void
  1016. find_all_hard_reg_sets (const_rtx insn, HARD_REG_SET *pset, bool implicit)
  1017. {
  1018. rtx link;
  1019. CLEAR_HARD_REG_SET (*pset);
  1020. note_stores (PATTERN (insn), record_hard_reg_sets, pset);
  1021. if (CALL_P (insn))
  1022. {
  1023. if (implicit)
  1024. IOR_HARD_REG_SET (*pset, call_used_reg_set);
  1025. for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
  1026. record_hard_reg_sets (XEXP (link, 0), NULL, pset);
  1027. }
  1028. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1029. if (REG_NOTE_KIND (link) == REG_INC)
  1030. record_hard_reg_sets (XEXP (link, 0), NULL, pset);
  1031. }
  1032. /* Like record_hard_reg_sets, but called through note_uses. */
  1033. void
  1034. record_hard_reg_uses (rtx *px, void *data)
  1035. {
  1036. find_all_hard_regs (*px, (HARD_REG_SET *) data);
  1037. }
  1038. /* Given an INSN, return a SET expression if this insn has only a single SET.
  1039. It may also have CLOBBERs, USEs, or SET whose output
  1040. will not be used, which we ignore. */
  1041. rtx
  1042. single_set_2 (const rtx_insn *insn, const_rtx pat)
  1043. {
  1044. rtx set = NULL;
  1045. int set_verified = 1;
  1046. int i;
  1047. if (GET_CODE (pat) == PARALLEL)
  1048. {
  1049. for (i = 0; i < XVECLEN (pat, 0); i++)
  1050. {
  1051. rtx sub = XVECEXP (pat, 0, i);
  1052. switch (GET_CODE (sub))
  1053. {
  1054. case USE:
  1055. case CLOBBER:
  1056. break;
  1057. case SET:
  1058. /* We can consider insns having multiple sets, where all
  1059. but one are dead as single set insns. In common case
  1060. only single set is present in the pattern so we want
  1061. to avoid checking for REG_UNUSED notes unless necessary.
  1062. When we reach set first time, we just expect this is
  1063. the single set we are looking for and only when more
  1064. sets are found in the insn, we check them. */
  1065. if (!set_verified)
  1066. {
  1067. if (find_reg_note (insn, REG_UNUSED, SET_DEST (set))
  1068. && !side_effects_p (set))
  1069. set = NULL;
  1070. else
  1071. set_verified = 1;
  1072. }
  1073. if (!set)
  1074. set = sub, set_verified = 0;
  1075. else if (!find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
  1076. || side_effects_p (sub))
  1077. return NULL_RTX;
  1078. break;
  1079. default:
  1080. return NULL_RTX;
  1081. }
  1082. }
  1083. }
  1084. return set;
  1085. }
  1086. /* Given an INSN, return nonzero if it has more than one SET, else return
  1087. zero. */
  1088. int
  1089. multiple_sets (const_rtx insn)
  1090. {
  1091. int found;
  1092. int i;
  1093. /* INSN must be an insn. */
  1094. if (! INSN_P (insn))
  1095. return 0;
  1096. /* Only a PARALLEL can have multiple SETs. */
  1097. if (GET_CODE (PATTERN (insn)) == PARALLEL)
  1098. {
  1099. for (i = 0, found = 0; i < XVECLEN (PATTERN (insn), 0); i++)
  1100. if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
  1101. {
  1102. /* If we have already found a SET, then return now. */
  1103. if (found)
  1104. return 1;
  1105. else
  1106. found = 1;
  1107. }
  1108. }
  1109. /* Either zero or one SET. */
  1110. return 0;
  1111. }
  1112. /* Return nonzero if the destination of SET equals the source
  1113. and there are no side effects. */
  1114. int
  1115. set_noop_p (const_rtx set)
  1116. {
  1117. rtx src = SET_SRC (set);
  1118. rtx dst = SET_DEST (set);
  1119. if (dst == pc_rtx && src == pc_rtx)
  1120. return 1;
  1121. if (MEM_P (dst) && MEM_P (src))
  1122. return rtx_equal_p (dst, src) && !side_effects_p (dst);
  1123. if (GET_CODE (dst) == ZERO_EXTRACT)
  1124. return rtx_equal_p (XEXP (dst, 0), src)
  1125. && ! BYTES_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
  1126. && !side_effects_p (src);
  1127. if (GET_CODE (dst) == STRICT_LOW_PART)
  1128. dst = XEXP (dst, 0);
  1129. if (GET_CODE (src) == SUBREG && GET_CODE (dst) == SUBREG)
  1130. {
  1131. if (SUBREG_BYTE (src) != SUBREG_BYTE (dst))
  1132. return 0;
  1133. src = SUBREG_REG (src);
  1134. dst = SUBREG_REG (dst);
  1135. }
  1136. /* It is a NOOP if destination overlaps with selected src vector
  1137. elements. */
  1138. if (GET_CODE (src) == VEC_SELECT
  1139. && REG_P (XEXP (src, 0)) && REG_P (dst)
  1140. && HARD_REGISTER_P (XEXP (src, 0))
  1141. && HARD_REGISTER_P (dst))
  1142. {
  1143. int i;
  1144. rtx par = XEXP (src, 1);
  1145. rtx src0 = XEXP (src, 0);
  1146. int c0 = INTVAL (XVECEXP (par, 0, 0));
  1147. HOST_WIDE_INT offset = GET_MODE_UNIT_SIZE (GET_MODE (src0)) * c0;
  1148. for (i = 1; i < XVECLEN (par, 0); i++)
  1149. if (INTVAL (XVECEXP (par, 0, i)) != c0 + i)
  1150. return 0;
  1151. return
  1152. simplify_subreg_regno (REGNO (src0), GET_MODE (src0),
  1153. offset, GET_MODE (dst)) == (int) REGNO (dst);
  1154. }
  1155. return (REG_P (src) && REG_P (dst)
  1156. && REGNO (src) == REGNO (dst));
  1157. }
  1158. /* Return nonzero if an insn consists only of SETs, each of which only sets a
  1159. value to itself. */
  1160. int
  1161. noop_move_p (const_rtx insn)
  1162. {
  1163. rtx pat = PATTERN (insn);
  1164. if (INSN_CODE (insn) == NOOP_MOVE_INSN_CODE)
  1165. return 1;
  1166. /* Insns carrying these notes are useful later on. */
  1167. if (find_reg_note (insn, REG_EQUAL, NULL_RTX))
  1168. return 0;
  1169. /* Check the code to be executed for COND_EXEC. */
  1170. if (GET_CODE (pat) == COND_EXEC)
  1171. pat = COND_EXEC_CODE (pat);
  1172. if (GET_CODE (pat) == SET && set_noop_p (pat))
  1173. return 1;
  1174. if (GET_CODE (pat) == PARALLEL)
  1175. {
  1176. int i;
  1177. /* If nothing but SETs of registers to themselves,
  1178. this insn can also be deleted. */
  1179. for (i = 0; i < XVECLEN (pat, 0); i++)
  1180. {
  1181. rtx tem = XVECEXP (pat, 0, i);
  1182. if (GET_CODE (tem) == USE
  1183. || GET_CODE (tem) == CLOBBER)
  1184. continue;
  1185. if (GET_CODE (tem) != SET || ! set_noop_p (tem))
  1186. return 0;
  1187. }
  1188. return 1;
  1189. }
  1190. return 0;
  1191. }
  1192. /* Return nonzero if register in range [REGNO, ENDREGNO)
  1193. appears either explicitly or implicitly in X
  1194. other than being stored into.
  1195. References contained within the substructure at LOC do not count.
  1196. LOC may be zero, meaning don't ignore anything. */
  1197. bool
  1198. refers_to_regno_p (unsigned int regno, unsigned int endregno, const_rtx x,
  1199. rtx *loc)
  1200. {
  1201. int i;
  1202. unsigned int x_regno;
  1203. RTX_CODE code;
  1204. const char *fmt;
  1205. repeat:
  1206. /* The contents of a REG_NONNEG note is always zero, so we must come here
  1207. upon repeat in case the last REG_NOTE is a REG_NONNEG note. */
  1208. if (x == 0)
  1209. return false;
  1210. code = GET_CODE (x);
  1211. switch (code)
  1212. {
  1213. case REG:
  1214. x_regno = REGNO (x);
  1215. /* If we modifying the stack, frame, or argument pointer, it will
  1216. clobber a virtual register. In fact, we could be more precise,
  1217. but it isn't worth it. */
  1218. if ((x_regno == STACK_POINTER_REGNUM
  1219. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  1220. || x_regno == ARG_POINTER_REGNUM
  1221. #endif
  1222. || x_regno == FRAME_POINTER_REGNUM)
  1223. && regno >= FIRST_VIRTUAL_REGISTER && regno <= LAST_VIRTUAL_REGISTER)
  1224. return true;
  1225. return endregno > x_regno && regno < END_REGNO (x);
  1226. case SUBREG:
  1227. /* If this is a SUBREG of a hard reg, we can see exactly which
  1228. registers are being modified. Otherwise, handle normally. */
  1229. if (REG_P (SUBREG_REG (x))
  1230. && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER)
  1231. {
  1232. unsigned int inner_regno = subreg_regno (x);
  1233. unsigned int inner_endregno
  1234. = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER
  1235. ? subreg_nregs (x) : 1);
  1236. return endregno > inner_regno && regno < inner_endregno;
  1237. }
  1238. break;
  1239. case CLOBBER:
  1240. case SET:
  1241. if (&SET_DEST (x) != loc
  1242. /* Note setting a SUBREG counts as referring to the REG it is in for
  1243. a pseudo but not for hard registers since we can
  1244. treat each word individually. */
  1245. && ((GET_CODE (SET_DEST (x)) == SUBREG
  1246. && loc != &SUBREG_REG (SET_DEST (x))
  1247. && REG_P (SUBREG_REG (SET_DEST (x)))
  1248. && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER
  1249. && refers_to_regno_p (regno, endregno,
  1250. SUBREG_REG (SET_DEST (x)), loc))
  1251. || (!REG_P (SET_DEST (x))
  1252. && refers_to_regno_p (regno, endregno, SET_DEST (x), loc))))
  1253. return true;
  1254. if (code == CLOBBER || loc == &SET_SRC (x))
  1255. return false;
  1256. x = SET_SRC (x);
  1257. goto repeat;
  1258. default:
  1259. break;
  1260. }
  1261. /* X does not match, so try its subexpressions. */
  1262. fmt = GET_RTX_FORMAT (code);
  1263. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1264. {
  1265. if (fmt[i] == 'e' && loc != &XEXP (x, i))
  1266. {
  1267. if (i == 0)
  1268. {
  1269. x = XEXP (x, 0);
  1270. goto repeat;
  1271. }
  1272. else
  1273. if (refers_to_regno_p (regno, endregno, XEXP (x, i), loc))
  1274. return true;
  1275. }
  1276. else if (fmt[i] == 'E')
  1277. {
  1278. int j;
  1279. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  1280. if (loc != &XVECEXP (x, i, j)
  1281. && refers_to_regno_p (regno, endregno, XVECEXP (x, i, j), loc))
  1282. return true;
  1283. }
  1284. }
  1285. return false;
  1286. }
  1287. /* Nonzero if modifying X will affect IN. If X is a register or a SUBREG,
  1288. we check if any register number in X conflicts with the relevant register
  1289. numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN
  1290. contains a MEM (we don't bother checking for memory addresses that can't
  1291. conflict because we expect this to be a rare case. */
  1292. int
  1293. reg_overlap_mentioned_p (const_rtx x, const_rtx in)
  1294. {
  1295. unsigned int regno, endregno;
  1296. /* If either argument is a constant, then modifying X can not
  1297. affect IN. Here we look at IN, we can profitably combine
  1298. CONSTANT_P (x) with the switch statement below. */
  1299. if (CONSTANT_P (in))
  1300. return 0;
  1301. recurse:
  1302. switch (GET_CODE (x))
  1303. {
  1304. case STRICT_LOW_PART:
  1305. case ZERO_EXTRACT:
  1306. case SIGN_EXTRACT:
  1307. /* Overly conservative. */
  1308. x = XEXP (x, 0);
  1309. goto recurse;
  1310. case SUBREG:
  1311. regno = REGNO (SUBREG_REG (x));
  1312. if (regno < FIRST_PSEUDO_REGISTER)
  1313. regno = subreg_regno (x);
  1314. endregno = regno + (regno < FIRST_PSEUDO_REGISTER
  1315. ? subreg_nregs (x) : 1);
  1316. goto do_reg;
  1317. case REG:
  1318. regno = REGNO (x);
  1319. endregno = END_REGNO (x);
  1320. do_reg:
  1321. return refers_to_regno_p (regno, endregno, in, (rtx*) 0);
  1322. case MEM:
  1323. {
  1324. const char *fmt;
  1325. int i;
  1326. if (MEM_P (in))
  1327. return 1;
  1328. fmt = GET_RTX_FORMAT (GET_CODE (in));
  1329. for (i = GET_RTX_LENGTH (GET_CODE (in)) - 1; i >= 0; i--)
  1330. if (fmt[i] == 'e')
  1331. {
  1332. if (reg_overlap_mentioned_p (x, XEXP (in, i)))
  1333. return 1;
  1334. }
  1335. else if (fmt[i] == 'E')
  1336. {
  1337. int j;
  1338. for (j = XVECLEN (in, i) - 1; j >= 0; --j)
  1339. if (reg_overlap_mentioned_p (x, XVECEXP (in, i, j)))
  1340. return 1;
  1341. }
  1342. return 0;
  1343. }
  1344. case SCRATCH:
  1345. case PC:
  1346. case CC0:
  1347. return reg_mentioned_p (x, in);
  1348. case PARALLEL:
  1349. {
  1350. int i;
  1351. /* If any register in here refers to it we return true. */
  1352. for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  1353. if (XEXP (XVECEXP (x, 0, i), 0) != 0
  1354. && reg_overlap_mentioned_p (XEXP (XVECEXP (x, 0, i), 0), in))
  1355. return 1;
  1356. return 0;
  1357. }
  1358. default:
  1359. gcc_assert (CONSTANT_P (x));
  1360. return 0;
  1361. }
  1362. }
  1363. /* Call FUN on each register or MEM that is stored into or clobbered by X.
  1364. (X would be the pattern of an insn). DATA is an arbitrary pointer,
  1365. ignored by note_stores, but passed to FUN.
  1366. FUN receives three arguments:
  1367. 1. the REG, MEM, CC0 or PC being stored in or clobbered,
  1368. 2. the SET or CLOBBER rtx that does the store,
  1369. 3. the pointer DATA provided to note_stores.
  1370. If the item being stored in or clobbered is a SUBREG of a hard register,
  1371. the SUBREG will be passed. */
  1372. void
  1373. note_stores (const_rtx x, void (*fun) (rtx, const_rtx, void *), void *data)
  1374. {
  1375. int i;
  1376. if (GET_CODE (x) == COND_EXEC)
  1377. x = COND_EXEC_CODE (x);
  1378. if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
  1379. {
  1380. rtx dest = SET_DEST (x);
  1381. while ((GET_CODE (dest) == SUBREG
  1382. && (!REG_P (SUBREG_REG (dest))
  1383. || REGNO (SUBREG_REG (dest)) >= FIRST_PSEUDO_REGISTER))
  1384. || GET_CODE (dest) == ZERO_EXTRACT
  1385. || GET_CODE (dest) == STRICT_LOW_PART)
  1386. dest = XEXP (dest, 0);
  1387. /* If we have a PARALLEL, SET_DEST is a list of EXPR_LIST expressions,
  1388. each of whose first operand is a register. */
  1389. if (GET_CODE (dest) == PARALLEL)
  1390. {
  1391. for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
  1392. if (XEXP (XVECEXP (dest, 0, i), 0) != 0)
  1393. (*fun) (XEXP (XVECEXP (dest, 0, i), 0), x, data);
  1394. }
  1395. else
  1396. (*fun) (dest, x, data);
  1397. }
  1398. else if (GET_CODE (x) == PARALLEL)
  1399. for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  1400. note_stores (XVECEXP (x, 0, i), fun, data);
  1401. }
  1402. /* Like notes_stores, but call FUN for each expression that is being
  1403. referenced in PBODY, a pointer to the PATTERN of an insn. We only call
  1404. FUN for each expression, not any interior subexpressions. FUN receives a
  1405. pointer to the expression and the DATA passed to this function.
  1406. Note that this is not quite the same test as that done in reg_referenced_p
  1407. since that considers something as being referenced if it is being
  1408. partially set, while we do not. */
  1409. void
  1410. note_uses (rtx *pbody, void (*fun) (rtx *, void *), void *data)
  1411. {
  1412. rtx body = *pbody;
  1413. int i;
  1414. switch (GET_CODE (body))
  1415. {
  1416. case COND_EXEC:
  1417. (*fun) (&COND_EXEC_TEST (body), data);
  1418. note_uses (&COND_EXEC_CODE (body), fun, data);
  1419. return;
  1420. case PARALLEL:
  1421. for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
  1422. note_uses (&XVECEXP (body, 0, i), fun, data);
  1423. return;
  1424. case SEQUENCE:
  1425. for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
  1426. note_uses (&PATTERN (XVECEXP (body, 0, i)), fun, data);
  1427. return;
  1428. case USE:
  1429. (*fun) (&XEXP (body, 0), data);
  1430. return;
  1431. case ASM_OPERANDS:
  1432. for (i = ASM_OPERANDS_INPUT_LENGTH (body) - 1; i >= 0; i--)
  1433. (*fun) (&ASM_OPERANDS_INPUT (body, i), data);
  1434. return;
  1435. case TRAP_IF:
  1436. (*fun) (&TRAP_CONDITION (body), data);
  1437. return;
  1438. case PREFETCH:
  1439. (*fun) (&XEXP (body, 0), data);
  1440. return;
  1441. case UNSPEC:
  1442. case UNSPEC_VOLATILE:
  1443. for (i = XVECLEN (body, 0) - 1; i >= 0; i--)
  1444. (*fun) (&XVECEXP (body, 0, i), data);
  1445. return;
  1446. case CLOBBER:
  1447. if (MEM_P (XEXP (body, 0)))
  1448. (*fun) (&XEXP (XEXP (body, 0), 0), data);
  1449. return;
  1450. case SET:
  1451. {
  1452. rtx dest = SET_DEST (body);
  1453. /* For sets we replace everything in source plus registers in memory
  1454. expression in store and operands of a ZERO_EXTRACT. */
  1455. (*fun) (&SET_SRC (body), data);
  1456. if (GET_CODE (dest) == ZERO_EXTRACT)
  1457. {
  1458. (*fun) (&XEXP (dest, 1), data);
  1459. (*fun) (&XEXP (dest, 2), data);
  1460. }
  1461. while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART)
  1462. dest = XEXP (dest, 0);
  1463. if (MEM_P (dest))
  1464. (*fun) (&XEXP (dest, 0), data);
  1465. }
  1466. return;
  1467. default:
  1468. /* All the other possibilities never store. */
  1469. (*fun) (pbody, data);
  1470. return;
  1471. }
  1472. }
  1473. /* Return nonzero if X's old contents don't survive after INSN.
  1474. This will be true if X is (cc0) or if X is a register and
  1475. X dies in INSN or because INSN entirely sets X.
  1476. "Entirely set" means set directly and not through a SUBREG, or
  1477. ZERO_EXTRACT, so no trace of the old contents remains.
  1478. Likewise, REG_INC does not count.
  1479. REG may be a hard or pseudo reg. Renumbering is not taken into account,
  1480. but for this use that makes no difference, since regs don't overlap
  1481. during their lifetimes. Therefore, this function may be used
  1482. at any time after deaths have been computed.
  1483. If REG is a hard reg that occupies multiple machine registers, this
  1484. function will only return 1 if each of those registers will be replaced
  1485. by INSN. */
  1486. int
  1487. dead_or_set_p (const_rtx insn, const_rtx x)
  1488. {
  1489. unsigned int regno, end_regno;
  1490. unsigned int i;
  1491. /* Can't use cc0_rtx below since this file is used by genattrtab.c. */
  1492. if (GET_CODE (x) == CC0)
  1493. return 1;
  1494. gcc_assert (REG_P (x));
  1495. regno = REGNO (x);
  1496. end_regno = END_REGNO (x);
  1497. for (i = regno; i < end_regno; i++)
  1498. if (! dead_or_set_regno_p (insn, i))
  1499. return 0;
  1500. return 1;
  1501. }
  1502. /* Return TRUE iff DEST is a register or subreg of a register and
  1503. doesn't change the number of words of the inner register, and any
  1504. part of the register is TEST_REGNO. */
  1505. static bool
  1506. covers_regno_no_parallel_p (const_rtx dest, unsigned int test_regno)
  1507. {
  1508. unsigned int regno, endregno;
  1509. if (GET_CODE (dest) == SUBREG
  1510. && (((GET_MODE_SIZE (GET_MODE (dest))
  1511. + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
  1512. == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
  1513. + UNITS_PER_WORD - 1) / UNITS_PER_WORD)))
  1514. dest = SUBREG_REG (dest);
  1515. if (!REG_P (dest))
  1516. return false;
  1517. regno = REGNO (dest);
  1518. endregno = END_REGNO (dest);
  1519. return (test_regno >= regno && test_regno < endregno);
  1520. }
  1521. /* Like covers_regno_no_parallel_p, but also handles PARALLELs where
  1522. any member matches the covers_regno_no_parallel_p criteria. */
  1523. static bool
  1524. covers_regno_p (const_rtx dest, unsigned int test_regno)
  1525. {
  1526. if (GET_CODE (dest) == PARALLEL)
  1527. {
  1528. /* Some targets place small structures in registers for return
  1529. values of functions, and those registers are wrapped in
  1530. PARALLELs that we may see as the destination of a SET. */
  1531. int i;
  1532. for (i = XVECLEN (dest, 0) - 1; i >= 0; i--)
  1533. {
  1534. rtx inner = XEXP (XVECEXP (dest, 0, i), 0);
  1535. if (inner != NULL_RTX
  1536. && covers_regno_no_parallel_p (inner, test_regno))
  1537. return true;
  1538. }
  1539. return false;
  1540. }
  1541. else
  1542. return covers_regno_no_parallel_p (dest, test_regno);
  1543. }
  1544. /* Utility function for dead_or_set_p to check an individual register. */
  1545. int
  1546. dead_or_set_regno_p (const_rtx insn, unsigned int test_regno)
  1547. {
  1548. const_rtx pattern;
  1549. /* See if there is a death note for something that includes TEST_REGNO. */
  1550. if (find_regno_note (insn, REG_DEAD, test_regno))
  1551. return 1;
  1552. if (CALL_P (insn)
  1553. && find_regno_fusage (insn, CLOBBER, test_regno))
  1554. return 1;
  1555. pattern = PATTERN (insn);
  1556. /* If a COND_EXEC is not executed, the value survives. */
  1557. if (GET_CODE (pattern) == COND_EXEC)
  1558. return 0;
  1559. if (GET_CODE (pattern) == SET)
  1560. return covers_regno_p (SET_DEST (pattern), test_regno);
  1561. else if (GET_CODE (pattern) == PARALLEL)
  1562. {
  1563. int i;
  1564. for (i = XVECLEN (pattern, 0) - 1; i >= 0; i--)
  1565. {
  1566. rtx body = XVECEXP (pattern, 0, i);
  1567. if (GET_CODE (body) == COND_EXEC)
  1568. body = COND_EXEC_CODE (body);
  1569. if ((GET_CODE (body) == SET || GET_CODE (body) == CLOBBER)
  1570. && covers_regno_p (SET_DEST (body), test_regno))
  1571. return 1;
  1572. }
  1573. }
  1574. return 0;
  1575. }
  1576. /* Return the reg-note of kind KIND in insn INSN, if there is one.
  1577. If DATUM is nonzero, look for one whose datum is DATUM. */
  1578. rtx
  1579. find_reg_note (const_rtx insn, enum reg_note kind, const_rtx datum)
  1580. {
  1581. rtx link;
  1582. gcc_checking_assert (insn);
  1583. /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
  1584. if (! INSN_P (insn))
  1585. return 0;
  1586. if (datum == 0)
  1587. {
  1588. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1589. if (REG_NOTE_KIND (link) == kind)
  1590. return link;
  1591. return 0;
  1592. }
  1593. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1594. if (REG_NOTE_KIND (link) == kind && datum == XEXP (link, 0))
  1595. return link;
  1596. return 0;
  1597. }
  1598. /* Return the reg-note of kind KIND in insn INSN which applies to register
  1599. number REGNO, if any. Return 0 if there is no such reg-note. Note that
  1600. the REGNO of this NOTE need not be REGNO if REGNO is a hard register;
  1601. it might be the case that the note overlaps REGNO. */
  1602. rtx
  1603. find_regno_note (const_rtx insn, enum reg_note kind, unsigned int regno)
  1604. {
  1605. rtx link;
  1606. /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN. */
  1607. if (! INSN_P (insn))
  1608. return 0;
  1609. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1610. if (REG_NOTE_KIND (link) == kind
  1611. /* Verify that it is a register, so that scratch and MEM won't cause a
  1612. problem here. */
  1613. && REG_P (XEXP (link, 0))
  1614. && REGNO (XEXP (link, 0)) <= regno
  1615. && END_REGNO (XEXP (link, 0)) > regno)
  1616. return link;
  1617. return 0;
  1618. }
  1619. /* Return a REG_EQUIV or REG_EQUAL note if insn has only a single set and
  1620. has such a note. */
  1621. rtx
  1622. find_reg_equal_equiv_note (const_rtx insn)
  1623. {
  1624. rtx link;
  1625. if (!INSN_P (insn))
  1626. return 0;
  1627. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1628. if (REG_NOTE_KIND (link) == REG_EQUAL
  1629. || REG_NOTE_KIND (link) == REG_EQUIV)
  1630. {
  1631. /* FIXME: We should never have REG_EQUAL/REG_EQUIV notes on
  1632. insns that have multiple sets. Checking single_set to
  1633. make sure of this is not the proper check, as explained
  1634. in the comment in set_unique_reg_note.
  1635. This should be changed into an assert. */
  1636. if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
  1637. return 0;
  1638. return link;
  1639. }
  1640. return NULL;
  1641. }
  1642. /* Check whether INSN is a single_set whose source is known to be
  1643. equivalent to a constant. Return that constant if so, otherwise
  1644. return null. */
  1645. rtx
  1646. find_constant_src (const rtx_insn *insn)
  1647. {
  1648. rtx note, set, x;
  1649. set = single_set (insn);
  1650. if (set)
  1651. {
  1652. x = avoid_constant_pool_reference (SET_SRC (set));
  1653. if (CONSTANT_P (x))
  1654. return x;
  1655. }
  1656. note = find_reg_equal_equiv_note (insn);
  1657. if (note && CONSTANT_P (XEXP (note, 0)))
  1658. return XEXP (note, 0);
  1659. return NULL_RTX;
  1660. }
  1661. /* Return true if DATUM, or any overlap of DATUM, of kind CODE is found
  1662. in the CALL_INSN_FUNCTION_USAGE information of INSN. */
  1663. int
  1664. find_reg_fusage (const_rtx insn, enum rtx_code code, const_rtx datum)
  1665. {
  1666. /* If it's not a CALL_INSN, it can't possibly have a
  1667. CALL_INSN_FUNCTION_USAGE field, so don't bother checking. */
  1668. if (!CALL_P (insn))
  1669. return 0;
  1670. gcc_assert (datum);
  1671. if (!REG_P (datum))
  1672. {
  1673. rtx link;
  1674. for (link = CALL_INSN_FUNCTION_USAGE (insn);
  1675. link;
  1676. link = XEXP (link, 1))
  1677. if (GET_CODE (XEXP (link, 0)) == code
  1678. && rtx_equal_p (datum, XEXP (XEXP (link, 0), 0)))
  1679. return 1;
  1680. }
  1681. else
  1682. {
  1683. unsigned int regno = REGNO (datum);
  1684. /* CALL_INSN_FUNCTION_USAGE information cannot contain references
  1685. to pseudo registers, so don't bother checking. */
  1686. if (regno < FIRST_PSEUDO_REGISTER)
  1687. {
  1688. unsigned int end_regno = END_HARD_REGNO (datum);
  1689. unsigned int i;
  1690. for (i = regno; i < end_regno; i++)
  1691. if (find_regno_fusage (insn, code, i))
  1692. return 1;
  1693. }
  1694. }
  1695. return 0;
  1696. }
  1697. /* Return true if REGNO, or any overlap of REGNO, of kind CODE is found
  1698. in the CALL_INSN_FUNCTION_USAGE information of INSN. */
  1699. int
  1700. find_regno_fusage (const_rtx insn, enum rtx_code code, unsigned int regno)
  1701. {
  1702. rtx link;
  1703. /* CALL_INSN_FUNCTION_USAGE information cannot contain references
  1704. to pseudo registers, so don't bother checking. */
  1705. if (regno >= FIRST_PSEUDO_REGISTER
  1706. || !CALL_P (insn) )
  1707. return 0;
  1708. for (link = CALL_INSN_FUNCTION_USAGE (insn); link; link = XEXP (link, 1))
  1709. {
  1710. rtx op, reg;
  1711. if (GET_CODE (op = XEXP (link, 0)) == code
  1712. && REG_P (reg = XEXP (op, 0))
  1713. && REGNO (reg) <= regno
  1714. && END_HARD_REGNO (reg) > regno)
  1715. return 1;
  1716. }
  1717. return 0;
  1718. }
  1719. /* Return true if KIND is an integer REG_NOTE. */
  1720. static bool
  1721. int_reg_note_p (enum reg_note kind)
  1722. {
  1723. return kind == REG_BR_PROB;
  1724. }
  1725. /* Allocate a register note with kind KIND and datum DATUM. LIST is
  1726. stored as the pointer to the next register note. */
  1727. rtx
  1728. alloc_reg_note (enum reg_note kind, rtx datum, rtx list)
  1729. {
  1730. rtx note;
  1731. gcc_checking_assert (!int_reg_note_p (kind));
  1732. switch (kind)
  1733. {
  1734. case REG_CC_SETTER:
  1735. case REG_CC_USER:
  1736. case REG_LABEL_TARGET:
  1737. case REG_LABEL_OPERAND:
  1738. case REG_TM:
  1739. /* These types of register notes use an INSN_LIST rather than an
  1740. EXPR_LIST, so that copying is done right and dumps look
  1741. better. */
  1742. note = alloc_INSN_LIST (datum, list);
  1743. PUT_REG_NOTE_KIND (note, kind);
  1744. break;
  1745. default:
  1746. note = alloc_EXPR_LIST (kind, datum, list);
  1747. break;
  1748. }
  1749. return note;
  1750. }
  1751. /* Add register note with kind KIND and datum DATUM to INSN. */
  1752. void
  1753. add_reg_note (rtx insn, enum reg_note kind, rtx datum)
  1754. {
  1755. REG_NOTES (insn) = alloc_reg_note (kind, datum, REG_NOTES (insn));
  1756. }
  1757. /* Add an integer register note with kind KIND and datum DATUM to INSN. */
  1758. void
  1759. add_int_reg_note (rtx insn, enum reg_note kind, int datum)
  1760. {
  1761. gcc_checking_assert (int_reg_note_p (kind));
  1762. REG_NOTES (insn) = gen_rtx_INT_LIST ((machine_mode) kind,
  1763. datum, REG_NOTES (insn));
  1764. }
  1765. /* Add a register note like NOTE to INSN. */
  1766. void
  1767. add_shallow_copy_of_reg_note (rtx insn, rtx note)
  1768. {
  1769. if (GET_CODE (note) == INT_LIST)
  1770. add_int_reg_note (insn, REG_NOTE_KIND (note), XINT (note, 0));
  1771. else
  1772. add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
  1773. }
  1774. /* Remove register note NOTE from the REG_NOTES of INSN. */
  1775. void
  1776. remove_note (rtx insn, const_rtx note)
  1777. {
  1778. rtx link;
  1779. if (note == NULL_RTX)
  1780. return;
  1781. if (REG_NOTES (insn) == note)
  1782. REG_NOTES (insn) = XEXP (note, 1);
  1783. else
  1784. for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1785. if (XEXP (link, 1) == note)
  1786. {
  1787. XEXP (link, 1) = XEXP (note, 1);
  1788. break;
  1789. }
  1790. switch (REG_NOTE_KIND (note))
  1791. {
  1792. case REG_EQUAL:
  1793. case REG_EQUIV:
  1794. df_notes_rescan (as_a <rtx_insn *> (insn));
  1795. break;
  1796. default:
  1797. break;
  1798. }
  1799. }
  1800. /* Remove REG_EQUAL and/or REG_EQUIV notes if INSN has such notes. */
  1801. void
  1802. remove_reg_equal_equiv_notes (rtx insn)
  1803. {
  1804. rtx *loc;
  1805. loc = &REG_NOTES (insn);
  1806. while (*loc)
  1807. {
  1808. enum reg_note kind = REG_NOTE_KIND (*loc);
  1809. if (kind == REG_EQUAL || kind == REG_EQUIV)
  1810. *loc = XEXP (*loc, 1);
  1811. else
  1812. loc = &XEXP (*loc, 1);
  1813. }
  1814. }
  1815. /* Remove all REG_EQUAL and REG_EQUIV notes referring to REGNO. */
  1816. void
  1817. remove_reg_equal_equiv_notes_for_regno (unsigned int regno)
  1818. {
  1819. df_ref eq_use;
  1820. if (!df)
  1821. return;
  1822. /* This loop is a little tricky. We cannot just go down the chain because
  1823. it is being modified by some actions in the loop. So we just iterate
  1824. over the head. We plan to drain the list anyway. */
  1825. while ((eq_use = DF_REG_EQ_USE_CHAIN (regno)) != NULL)
  1826. {
  1827. rtx_insn *insn = DF_REF_INSN (eq_use);
  1828. rtx note = find_reg_equal_equiv_note (insn);
  1829. /* This assert is generally triggered when someone deletes a REG_EQUAL
  1830. or REG_EQUIV note by hacking the list manually rather than calling
  1831. remove_note. */
  1832. gcc_assert (note);
  1833. remove_note (insn, note);
  1834. }
  1835. }
  1836. /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
  1837. return 1 if it is found. A simple equality test is used to determine if
  1838. NODE matches. */
  1839. int
  1840. in_expr_list_p (const_rtx listp, const_rtx node)
  1841. {
  1842. const_rtx x;
  1843. for (x = listp; x; x = XEXP (x, 1))
  1844. if (node == XEXP (x, 0))
  1845. return 1;
  1846. return 0;
  1847. }
  1848. /* Search LISTP (an EXPR_LIST) for an entry whose first operand is NODE and
  1849. remove that entry from the list if it is found.
  1850. A simple equality test is used to determine if NODE matches. */
  1851. void
  1852. remove_node_from_expr_list (const_rtx node, rtx_expr_list **listp)
  1853. {
  1854. rtx_expr_list *temp = *listp;
  1855. rtx prev = NULL_RTX;
  1856. while (temp)
  1857. {
  1858. if (node == temp->element ())
  1859. {
  1860. /* Splice the node out of the list. */
  1861. if (prev)
  1862. XEXP (prev, 1) = temp->next ();
  1863. else
  1864. *listp = temp->next ();
  1865. return;
  1866. }
  1867. prev = temp;
  1868. temp = temp->next ();
  1869. }
  1870. }
  1871. /* Search LISTP (an INSN_LIST) for an entry whose first operand is NODE and
  1872. remove that entry from the list if it is found.
  1873. A simple equality test is used to determine if NODE matches. */
  1874. void
  1875. remove_node_from_insn_list (const rtx_insn *node, rtx_insn_list **listp)
  1876. {
  1877. rtx_insn_list *temp = *listp;
  1878. rtx prev = NULL;
  1879. while (temp)
  1880. {
  1881. if (node == temp->insn ())
  1882. {
  1883. /* Splice the node out of the list. */
  1884. if (prev)
  1885. XEXP (prev, 1) = temp->next ();
  1886. else
  1887. *listp = temp->next ();
  1888. return;
  1889. }
  1890. prev = temp;
  1891. temp = temp->next ();
  1892. }
  1893. }
  1894. /* Nonzero if X contains any volatile instructions. These are instructions
  1895. which may cause unpredictable machine state instructions, and thus no
  1896. instructions or register uses should be moved or combined across them.
  1897. This includes only volatile asms and UNSPEC_VOLATILE instructions. */
  1898. int
  1899. volatile_insn_p (const_rtx x)
  1900. {
  1901. const RTX_CODE code = GET_CODE (x);
  1902. switch (code)
  1903. {
  1904. case LABEL_REF:
  1905. case SYMBOL_REF:
  1906. case CONST:
  1907. CASE_CONST_ANY:
  1908. case CC0:
  1909. case PC:
  1910. case REG:
  1911. case SCRATCH:
  1912. case CLOBBER:
  1913. case ADDR_VEC:
  1914. case ADDR_DIFF_VEC:
  1915. case CALL:
  1916. case MEM:
  1917. return 0;
  1918. case UNSPEC_VOLATILE:
  1919. return 1;
  1920. case ASM_INPUT:
  1921. case ASM_OPERANDS:
  1922. if (MEM_VOLATILE_P (x))
  1923. return 1;
  1924. default:
  1925. break;
  1926. }
  1927. /* Recursively scan the operands of this expression. */
  1928. {
  1929. const char *const fmt = GET_RTX_FORMAT (code);
  1930. int i;
  1931. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1932. {
  1933. if (fmt[i] == 'e')
  1934. {
  1935. if (volatile_insn_p (XEXP (x, i)))
  1936. return 1;
  1937. }
  1938. else if (fmt[i] == 'E')
  1939. {
  1940. int j;
  1941. for (j = 0; j < XVECLEN (x, i); j++)
  1942. if (volatile_insn_p (XVECEXP (x, i, j)))
  1943. return 1;
  1944. }
  1945. }
  1946. }
  1947. return 0;
  1948. }
  1949. /* Nonzero if X contains any volatile memory references
  1950. UNSPEC_VOLATILE operations or volatile ASM_OPERANDS expressions. */
  1951. int
  1952. volatile_refs_p (const_rtx x)
  1953. {
  1954. const RTX_CODE code = GET_CODE (x);
  1955. switch (code)
  1956. {
  1957. case LABEL_REF:
  1958. case SYMBOL_REF:
  1959. case CONST:
  1960. CASE_CONST_ANY:
  1961. case CC0:
  1962. case PC:
  1963. case REG:
  1964. case SCRATCH:
  1965. case CLOBBER:
  1966. case ADDR_VEC:
  1967. case ADDR_DIFF_VEC:
  1968. return 0;
  1969. case UNSPEC_VOLATILE:
  1970. return 1;
  1971. case MEM:
  1972. case ASM_INPUT:
  1973. case ASM_OPERANDS:
  1974. if (MEM_VOLATILE_P (x))
  1975. return 1;
  1976. default:
  1977. break;
  1978. }
  1979. /* Recursively scan the operands of this expression. */
  1980. {
  1981. const char *const fmt = GET_RTX_FORMAT (code);
  1982. int i;
  1983. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1984. {
  1985. if (fmt[i] == 'e')
  1986. {
  1987. if (volatile_refs_p (XEXP (x, i)))
  1988. return 1;
  1989. }
  1990. else if (fmt[i] == 'E')
  1991. {
  1992. int j;
  1993. for (j = 0; j < XVECLEN (x, i); j++)
  1994. if (volatile_refs_p (XVECEXP (x, i, j)))
  1995. return 1;
  1996. }
  1997. }
  1998. }
  1999. return 0;
  2000. }
  2001. /* Similar to above, except that it also rejects register pre- and post-
  2002. incrementing. */
  2003. int
  2004. side_effects_p (const_rtx x)
  2005. {
  2006. const RTX_CODE code = GET_CODE (x);
  2007. switch (code)
  2008. {
  2009. case LABEL_REF:
  2010. case SYMBOL_REF:
  2011. case CONST:
  2012. CASE_CONST_ANY:
  2013. case CC0:
  2014. case PC:
  2015. case REG:
  2016. case SCRATCH:
  2017. case ADDR_VEC:
  2018. case ADDR_DIFF_VEC:
  2019. case VAR_LOCATION:
  2020. return 0;
  2021. case CLOBBER:
  2022. /* Reject CLOBBER with a non-VOID mode. These are made by combine.c
  2023. when some combination can't be done. If we see one, don't think
  2024. that we can simplify the expression. */
  2025. return (GET_MODE (x) != VOIDmode);
  2026. case PRE_INC:
  2027. case PRE_DEC:
  2028. case POST_INC:
  2029. case POST_DEC:
  2030. case PRE_MODIFY:
  2031. case POST_MODIFY:
  2032. case CALL:
  2033. case UNSPEC_VOLATILE:
  2034. return 1;
  2035. case MEM:
  2036. case ASM_INPUT:
  2037. case ASM_OPERANDS:
  2038. if (MEM_VOLATILE_P (x))
  2039. return 1;
  2040. default:
  2041. break;
  2042. }
  2043. /* Recursively scan the operands of this expression. */
  2044. {
  2045. const char *fmt = GET_RTX_FORMAT (code);
  2046. int i;
  2047. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2048. {
  2049. if (fmt[i] == 'e')
  2050. {
  2051. if (side_effects_p (XEXP (x, i)))
  2052. return 1;
  2053. }
  2054. else if (fmt[i] == 'E')
  2055. {
  2056. int j;
  2057. for (j = 0; j < XVECLEN (x, i); j++)
  2058. if (side_effects_p (XVECEXP (x, i, j)))
  2059. return 1;
  2060. }
  2061. }
  2062. }
  2063. return 0;
  2064. }
  2065. /* Return nonzero if evaluating rtx X might cause a trap.
  2066. FLAGS controls how to consider MEMs. A nonzero means the context
  2067. of the access may have changed from the original, such that the
  2068. address may have become invalid. */
  2069. int
  2070. may_trap_p_1 (const_rtx x, unsigned flags)
  2071. {
  2072. int i;
  2073. enum rtx_code code;
  2074. const char *fmt;
  2075. /* We make no distinction currently, but this function is part of
  2076. the internal target-hooks ABI so we keep the parameter as
  2077. "unsigned flags". */
  2078. bool code_changed = flags != 0;
  2079. if (x == 0)
  2080. return 0;
  2081. code = GET_CODE (x);
  2082. switch (code)
  2083. {
  2084. /* Handle these cases quickly. */
  2085. CASE_CONST_ANY:
  2086. case SYMBOL_REF:
  2087. case LABEL_REF:
  2088. case CONST:
  2089. case PC:
  2090. case CC0:
  2091. case REG:
  2092. case SCRATCH:
  2093. return 0;
  2094. case UNSPEC:
  2095. return targetm.unspec_may_trap_p (x, flags);
  2096. case UNSPEC_VOLATILE:
  2097. case ASM_INPUT:
  2098. case TRAP_IF:
  2099. return 1;
  2100. case ASM_OPERANDS:
  2101. return MEM_VOLATILE_P (x);
  2102. /* Memory ref can trap unless it's a static var or a stack slot. */
  2103. case MEM:
  2104. /* Recognize specific pattern of stack checking probes. */
  2105. if (flag_stack_check
  2106. && MEM_VOLATILE_P (x)
  2107. && XEXP (x, 0) == stack_pointer_rtx)
  2108. return 1;
  2109. if (/* MEM_NOTRAP_P only relates to the actual position of the memory
  2110. reference; moving it out of context such as when moving code
  2111. when optimizing, might cause its address to become invalid. */
  2112. code_changed
  2113. || !MEM_NOTRAP_P (x))
  2114. {
  2115. HOST_WIDE_INT size = MEM_SIZE_KNOWN_P (x) ? MEM_SIZE (x) : 0;
  2116. return rtx_addr_can_trap_p_1 (XEXP (x, 0), 0, size,
  2117. GET_MODE (x), code_changed);
  2118. }
  2119. return 0;
  2120. /* Division by a non-constant might trap. */
  2121. case DIV:
  2122. case MOD:
  2123. case UDIV:
  2124. case UMOD:
  2125. if (HONOR_SNANS (x))
  2126. return 1;
  2127. if (SCALAR_FLOAT_MODE_P (GET_MODE (x)))
  2128. return flag_trapping_math;
  2129. if (!CONSTANT_P (XEXP (x, 1)) || (XEXP (x, 1) == const0_rtx))
  2130. return 1;
  2131. break;
  2132. case EXPR_LIST:
  2133. /* An EXPR_LIST is used to represent a function call. This
  2134. certainly may trap. */
  2135. return 1;
  2136. case GE:
  2137. case GT:
  2138. case LE:
  2139. case LT:
  2140. case LTGT:
  2141. case COMPARE:
  2142. /* Some floating point comparisons may trap. */
  2143. if (!flag_trapping_math)
  2144. break;
  2145. /* ??? There is no machine independent way to check for tests that trap
  2146. when COMPARE is used, though many targets do make this distinction.
  2147. For instance, sparc uses CCFPE for compares which generate exceptions
  2148. and CCFP for compares which do not generate exceptions. */
  2149. if (HONOR_NANS (x))
  2150. return 1;
  2151. /* But often the compare has some CC mode, so check operand
  2152. modes as well. */
  2153. if (HONOR_NANS (XEXP (x, 0))
  2154. || HONOR_NANS (XEXP (x, 1)))
  2155. return 1;
  2156. break;
  2157. case EQ:
  2158. case NE:
  2159. if (HONOR_SNANS (x))
  2160. return 1;
  2161. /* Often comparison is CC mode, so check operand modes. */
  2162. if (HONOR_SNANS (XEXP (x, 0))
  2163. || HONOR_SNANS (XEXP (x, 1)))
  2164. return 1;
  2165. break;
  2166. case FIX:
  2167. /* Conversion of floating point might trap. */
  2168. if (flag_trapping_math && HONOR_NANS (XEXP (x, 0)))
  2169. return 1;
  2170. break;
  2171. case NEG:
  2172. case ABS:
  2173. case SUBREG:
  2174. /* These operations don't trap even with floating point. */
  2175. break;
  2176. default:
  2177. /* Any floating arithmetic may trap. */
  2178. if (SCALAR_FLOAT_MODE_P (GET_MODE (x)) && flag_trapping_math)
  2179. return 1;
  2180. }
  2181. fmt = GET_RTX_FORMAT (code);
  2182. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2183. {
  2184. if (fmt[i] == 'e')
  2185. {
  2186. if (may_trap_p_1 (XEXP (x, i), flags))
  2187. return 1;
  2188. }
  2189. else if (fmt[i] == 'E')
  2190. {
  2191. int j;
  2192. for (j = 0; j < XVECLEN (x, i); j++)
  2193. if (may_trap_p_1 (XVECEXP (x, i, j), flags))
  2194. return 1;
  2195. }
  2196. }
  2197. return 0;
  2198. }
  2199. /* Return nonzero if evaluating rtx X might cause a trap. */
  2200. int
  2201. may_trap_p (const_rtx x)
  2202. {
  2203. return may_trap_p_1 (x, 0);
  2204. }
  2205. /* Same as above, but additionally return nonzero if evaluating rtx X might
  2206. cause a fault. We define a fault for the purpose of this function as a
  2207. erroneous execution condition that cannot be encountered during the normal
  2208. execution of a valid program; the typical example is an unaligned memory
  2209. access on a strict alignment machine. The compiler guarantees that it
  2210. doesn't generate code that will fault from a valid program, but this
  2211. guarantee doesn't mean anything for individual instructions. Consider
  2212. the following example:
  2213. struct S { int d; union { char *cp; int *ip; }; };
  2214. int foo(struct S *s)
  2215. {
  2216. if (s->d == 1)
  2217. return *s->ip;
  2218. else
  2219. return *s->cp;
  2220. }
  2221. on a strict alignment machine. In a valid program, foo will never be
  2222. invoked on a structure for which d is equal to 1 and the underlying
  2223. unique field of the union not aligned on a 4-byte boundary, but the
  2224. expression *s->ip might cause a fault if considered individually.
  2225. At the RTL level, potentially problematic expressions will almost always
  2226. verify may_trap_p; for example, the above dereference can be emitted as
  2227. (mem:SI (reg:P)) and this expression is may_trap_p for a generic register.
  2228. However, suppose that foo is inlined in a caller that causes s->cp to
  2229. point to a local character variable and guarantees that s->d is not set
  2230. to 1; foo may have been effectively translated into pseudo-RTL as:
  2231. if ((reg:SI) == 1)
  2232. (set (reg:SI) (mem:SI (%fp - 7)))
  2233. else
  2234. (set (reg:QI) (mem:QI (%fp - 7)))
  2235. Now (mem:SI (%fp - 7)) is considered as not may_trap_p since it is a
  2236. memory reference to a stack slot, but it will certainly cause a fault
  2237. on a strict alignment machine. */
  2238. int
  2239. may_trap_or_fault_p (const_rtx x)
  2240. {
  2241. return may_trap_p_1 (x, 1);
  2242. }
  2243. /* Return nonzero if X contains a comparison that is not either EQ or NE,
  2244. i.e., an inequality. */
  2245. int
  2246. inequality_comparisons_p (const_rtx x)
  2247. {
  2248. const char *fmt;
  2249. int len, i;
  2250. const enum rtx_code code = GET_CODE (x);
  2251. switch (code)
  2252. {
  2253. case REG:
  2254. case SCRATCH:
  2255. case PC:
  2256. case CC0:
  2257. CASE_CONST_ANY:
  2258. case CONST:
  2259. case LABEL_REF:
  2260. case SYMBOL_REF:
  2261. return 0;
  2262. case LT:
  2263. case LTU:
  2264. case GT:
  2265. case GTU:
  2266. case LE:
  2267. case LEU:
  2268. case GE:
  2269. case GEU:
  2270. return 1;
  2271. default:
  2272. break;
  2273. }
  2274. len = GET_RTX_LENGTH (code);
  2275. fmt = GET_RTX_FORMAT (code);
  2276. for (i = 0; i < len; i++)
  2277. {
  2278. if (fmt[i] == 'e')
  2279. {
  2280. if (inequality_comparisons_p (XEXP (x, i)))
  2281. return 1;
  2282. }
  2283. else if (fmt[i] == 'E')
  2284. {
  2285. int j;
  2286. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2287. if (inequality_comparisons_p (XVECEXP (x, i, j)))
  2288. return 1;
  2289. }
  2290. }
  2291. return 0;
  2292. }
  2293. /* Replace any occurrence of FROM in X with TO. The function does
  2294. not enter into CONST_DOUBLE for the replace.
  2295. Note that copying is not done so X must not be shared unless all copies
  2296. are to be modified. */
  2297. rtx
  2298. replace_rtx (rtx x, rtx from, rtx to)
  2299. {
  2300. int i, j;
  2301. const char *fmt;
  2302. if (x == from)
  2303. return to;
  2304. /* Allow this function to make replacements in EXPR_LISTs. */
  2305. if (x == 0)
  2306. return 0;
  2307. if (GET_CODE (x) == SUBREG)
  2308. {
  2309. rtx new_rtx = replace_rtx (SUBREG_REG (x), from, to);
  2310. if (CONST_INT_P (new_rtx))
  2311. {
  2312. x = simplify_subreg (GET_MODE (x), new_rtx,
  2313. GET_MODE (SUBREG_REG (x)),
  2314. SUBREG_BYTE (x));
  2315. gcc_assert (x);
  2316. }
  2317. else
  2318. SUBREG_REG (x) = new_rtx;
  2319. return x;
  2320. }
  2321. else if (GET_CODE (x) == ZERO_EXTEND)
  2322. {
  2323. rtx new_rtx = replace_rtx (XEXP (x, 0), from, to);
  2324. if (CONST_INT_P (new_rtx))
  2325. {
  2326. x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
  2327. new_rtx, GET_MODE (XEXP (x, 0)));
  2328. gcc_assert (x);
  2329. }
  2330. else
  2331. XEXP (x, 0) = new_rtx;
  2332. return x;
  2333. }
  2334. fmt = GET_RTX_FORMAT (GET_CODE (x));
  2335. for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
  2336. {
  2337. if (fmt[i] == 'e')
  2338. XEXP (x, i) = replace_rtx (XEXP (x, i), from, to);
  2339. else if (fmt[i] == 'E')
  2340. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2341. XVECEXP (x, i, j) = replace_rtx (XVECEXP (x, i, j), from, to);
  2342. }
  2343. return x;
  2344. }
  2345. /* Replace occurrences of the OLD_LABEL in *LOC with NEW_LABEL. Also track
  2346. the change in LABEL_NUSES if UPDATE_LABEL_NUSES. */
  2347. void
  2348. replace_label (rtx *loc, rtx old_label, rtx new_label, bool update_label_nuses)
  2349. {
  2350. /* Handle jump tables specially, since ADDR_{DIFF_,}VECs can be long. */
  2351. rtx x = *loc;
  2352. if (JUMP_TABLE_DATA_P (x))
  2353. {
  2354. x = PATTERN (x);
  2355. rtvec vec = XVEC (x, GET_CODE (x) == ADDR_DIFF_VEC);
  2356. int len = GET_NUM_ELEM (vec);
  2357. for (int i = 0; i < len; ++i)
  2358. {
  2359. rtx ref = RTVEC_ELT (vec, i);
  2360. if (XEXP (ref, 0) == old_label)
  2361. {
  2362. XEXP (ref, 0) = new_label;
  2363. if (update_label_nuses)
  2364. {
  2365. ++LABEL_NUSES (new_label);
  2366. --LABEL_NUSES (old_label);
  2367. }
  2368. }
  2369. }
  2370. return;
  2371. }
  2372. /* If this is a JUMP_INSN, then we also need to fix the JUMP_LABEL
  2373. field. This is not handled by the iterator because it doesn't
  2374. handle unprinted ('0') fields. */
  2375. if (JUMP_P (x) && JUMP_LABEL (x) == old_label)
  2376. JUMP_LABEL (x) = new_label;
  2377. subrtx_ptr_iterator::array_type array;
  2378. FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
  2379. {
  2380. rtx *loc = *iter;
  2381. if (rtx x = *loc)
  2382. {
  2383. if (GET_CODE (x) == SYMBOL_REF
  2384. && CONSTANT_POOL_ADDRESS_P (x))
  2385. {
  2386. rtx c = get_pool_constant (x);
  2387. if (rtx_referenced_p (old_label, c))
  2388. {
  2389. /* Create a copy of constant C; replace the label inside
  2390. but do not update LABEL_NUSES because uses in constant pool
  2391. are not counted. */
  2392. rtx new_c = copy_rtx (c);
  2393. replace_label (&new_c, old_label, new_label, false);
  2394. /* Add the new constant NEW_C to constant pool and replace
  2395. the old reference to constant by new reference. */
  2396. rtx new_mem = force_const_mem (get_pool_mode (x), new_c);
  2397. *loc = replace_rtx (x, x, XEXP (new_mem, 0));
  2398. }
  2399. }
  2400. if ((GET_CODE (x) == LABEL_REF
  2401. || GET_CODE (x) == INSN_LIST)
  2402. && XEXP (x, 0) == old_label)
  2403. {
  2404. XEXP (x, 0) = new_label;
  2405. if (update_label_nuses)
  2406. {
  2407. ++LABEL_NUSES (new_label);
  2408. --LABEL_NUSES (old_label);
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. void
  2415. replace_label_in_insn (rtx_insn *insn, rtx old_label, rtx new_label,
  2416. bool update_label_nuses)
  2417. {
  2418. rtx insn_as_rtx = insn;
  2419. replace_label (&insn_as_rtx, old_label, new_label, update_label_nuses);
  2420. gcc_checking_assert (insn_as_rtx == insn);
  2421. }
  2422. /* Return true if X is referenced in BODY. */
  2423. bool
  2424. rtx_referenced_p (const_rtx x, const_rtx body)
  2425. {
  2426. subrtx_iterator::array_type array;
  2427. FOR_EACH_SUBRTX (iter, array, body, ALL)
  2428. if (const_rtx y = *iter)
  2429. {
  2430. /* Check if a label_ref Y refers to label X. */
  2431. if (GET_CODE (y) == LABEL_REF
  2432. && LABEL_P (x)
  2433. && LABEL_REF_LABEL (y) == x)
  2434. return true;
  2435. if (rtx_equal_p (x, y))
  2436. return true;
  2437. /* If Y is a reference to pool constant traverse the constant. */
  2438. if (GET_CODE (y) == SYMBOL_REF
  2439. && CONSTANT_POOL_ADDRESS_P (y))
  2440. iter.substitute (get_pool_constant (y));
  2441. }
  2442. return false;
  2443. }
  2444. /* If INSN is a tablejump return true and store the label (before jump table) to
  2445. *LABELP and the jump table to *TABLEP. LABELP and TABLEP may be NULL. */
  2446. bool
  2447. tablejump_p (const rtx_insn *insn, rtx *labelp, rtx_jump_table_data **tablep)
  2448. {
  2449. rtx label, table;
  2450. if (!JUMP_P (insn))
  2451. return false;
  2452. label = JUMP_LABEL (insn);
  2453. if (label != NULL_RTX && !ANY_RETURN_P (label)
  2454. && (table = NEXT_INSN (as_a <rtx_insn *> (label))) != NULL_RTX
  2455. && JUMP_TABLE_DATA_P (table))
  2456. {
  2457. if (labelp)
  2458. *labelp = label;
  2459. if (tablep)
  2460. *tablep = as_a <rtx_jump_table_data *> (table);
  2461. return true;
  2462. }
  2463. return false;
  2464. }
  2465. /* A subroutine of computed_jump_p, return 1 if X contains a REG or MEM or
  2466. constant that is not in the constant pool and not in the condition
  2467. of an IF_THEN_ELSE. */
  2468. static int
  2469. computed_jump_p_1 (const_rtx x)
  2470. {
  2471. const enum rtx_code code = GET_CODE (x);
  2472. int i, j;
  2473. const char *fmt;
  2474. switch (code)
  2475. {
  2476. case LABEL_REF:
  2477. case PC:
  2478. return 0;
  2479. case CONST:
  2480. CASE_CONST_ANY:
  2481. case SYMBOL_REF:
  2482. case REG:
  2483. return 1;
  2484. case MEM:
  2485. return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
  2486. && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
  2487. case IF_THEN_ELSE:
  2488. return (computed_jump_p_1 (XEXP (x, 1))
  2489. || computed_jump_p_1 (XEXP (x, 2)));
  2490. default:
  2491. break;
  2492. }
  2493. fmt = GET_RTX_FORMAT (code);
  2494. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2495. {
  2496. if (fmt[i] == 'e'
  2497. && computed_jump_p_1 (XEXP (x, i)))
  2498. return 1;
  2499. else if (fmt[i] == 'E')
  2500. for (j = 0; j < XVECLEN (x, i); j++)
  2501. if (computed_jump_p_1 (XVECEXP (x, i, j)))
  2502. return 1;
  2503. }
  2504. return 0;
  2505. }
  2506. /* Return nonzero if INSN is an indirect jump (aka computed jump).
  2507. Tablejumps and casesi insns are not considered indirect jumps;
  2508. we can recognize them by a (use (label_ref)). */
  2509. int
  2510. computed_jump_p (const_rtx insn)
  2511. {
  2512. int i;
  2513. if (JUMP_P (insn))
  2514. {
  2515. rtx pat = PATTERN (insn);
  2516. /* If we have a JUMP_LABEL set, we're not a computed jump. */
  2517. if (JUMP_LABEL (insn) != NULL)
  2518. return 0;
  2519. if (GET_CODE (pat) == PARALLEL)
  2520. {
  2521. int len = XVECLEN (pat, 0);
  2522. int has_use_labelref = 0;
  2523. for (i = len - 1; i >= 0; i--)
  2524. if (GET_CODE (XVECEXP (pat, 0, i)) == USE
  2525. && (GET_CODE (XEXP (XVECEXP (pat, 0, i), 0))
  2526. == LABEL_REF))
  2527. {
  2528. has_use_labelref = 1;
  2529. break;
  2530. }
  2531. if (! has_use_labelref)
  2532. for (i = len - 1; i >= 0; i--)
  2533. if (GET_CODE (XVECEXP (pat, 0, i)) == SET
  2534. && SET_DEST (XVECEXP (pat, 0, i)) == pc_rtx
  2535. && computed_jump_p_1 (SET_SRC (XVECEXP (pat, 0, i))))
  2536. return 1;
  2537. }
  2538. else if (GET_CODE (pat) == SET
  2539. && SET_DEST (pat) == pc_rtx
  2540. && computed_jump_p_1 (SET_SRC (pat)))
  2541. return 1;
  2542. }
  2543. return 0;
  2544. }
  2545. /* MEM has a PRE/POST-INC/DEC/MODIFY address X. Extract the operands of
  2546. the equivalent add insn and pass the result to FN, using DATA as the
  2547. final argument. */
  2548. static int
  2549. for_each_inc_dec_find_inc_dec (rtx mem, for_each_inc_dec_fn fn, void *data)
  2550. {
  2551. rtx x = XEXP (mem, 0);
  2552. switch (GET_CODE (x))
  2553. {
  2554. case PRE_INC:
  2555. case POST_INC:
  2556. {
  2557. int size = GET_MODE_SIZE (GET_MODE (mem));
  2558. rtx r1 = XEXP (x, 0);
  2559. rtx c = gen_int_mode (size, GET_MODE (r1));
  2560. return fn (mem, x, r1, r1, c, data);
  2561. }
  2562. case PRE_DEC:
  2563. case POST_DEC:
  2564. {
  2565. int size = GET_MODE_SIZE (GET_MODE (mem));
  2566. rtx r1 = XEXP (x, 0);
  2567. rtx c = gen_int_mode (-size, GET_MODE (r1));
  2568. return fn (mem, x, r1, r1, c, data);
  2569. }
  2570. case PRE_MODIFY:
  2571. case POST_MODIFY:
  2572. {
  2573. rtx r1 = XEXP (x, 0);
  2574. rtx add = XEXP (x, 1);
  2575. return fn (mem, x, r1, add, NULL, data);
  2576. }
  2577. default:
  2578. gcc_unreachable ();
  2579. }
  2580. }
  2581. /* Traverse *LOC looking for MEMs that have autoinc addresses.
  2582. For each such autoinc operation found, call FN, passing it
  2583. the innermost enclosing MEM, the operation itself, the RTX modified
  2584. by the operation, two RTXs (the second may be NULL) that, once
  2585. added, represent the value to be held by the modified RTX
  2586. afterwards, and DATA. FN is to return 0 to continue the
  2587. traversal or any other value to have it returned to the caller of
  2588. for_each_inc_dec. */
  2589. int
  2590. for_each_inc_dec (rtx x,
  2591. for_each_inc_dec_fn fn,
  2592. void *data)
  2593. {
  2594. subrtx_var_iterator::array_type array;
  2595. FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
  2596. {
  2597. rtx mem = *iter;
  2598. if (mem
  2599. && MEM_P (mem)
  2600. && GET_RTX_CLASS (GET_CODE (XEXP (mem, 0))) == RTX_AUTOINC)
  2601. {
  2602. int res = for_each_inc_dec_find_inc_dec (mem, fn, data);
  2603. if (res != 0)
  2604. return res;
  2605. iter.skip_subrtxes ();
  2606. }
  2607. }
  2608. return 0;
  2609. }
  2610. /* Searches X for any reference to REGNO, returning the rtx of the
  2611. reference found if any. Otherwise, returns NULL_RTX. */
  2612. rtx
  2613. regno_use_in (unsigned int regno, rtx x)
  2614. {
  2615. const char *fmt;
  2616. int i, j;
  2617. rtx tem;
  2618. if (REG_P (x) && REGNO (x) == regno)
  2619. return x;
  2620. fmt = GET_RTX_FORMAT (GET_CODE (x));
  2621. for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
  2622. {
  2623. if (fmt[i] == 'e')
  2624. {
  2625. if ((tem = regno_use_in (regno, XEXP (x, i))))
  2626. return tem;
  2627. }
  2628. else if (fmt[i] == 'E')
  2629. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2630. if ((tem = regno_use_in (regno , XVECEXP (x, i, j))))
  2631. return tem;
  2632. }
  2633. return NULL_RTX;
  2634. }
  2635. /* Return a value indicating whether OP, an operand of a commutative
  2636. operation, is preferred as the first or second operand. The higher
  2637. the value, the stronger the preference for being the first operand.
  2638. We use negative values to indicate a preference for the first operand
  2639. and positive values for the second operand. */
  2640. int
  2641. commutative_operand_precedence (rtx op)
  2642. {
  2643. enum rtx_code code = GET_CODE (op);
  2644. /* Constants always come the second operand. Prefer "nice" constants. */
  2645. if (code == CONST_INT)
  2646. return -8;
  2647. if (code == CONST_WIDE_INT)
  2648. return -8;
  2649. if (code == CONST_DOUBLE)
  2650. return -7;
  2651. if (code == CONST_FIXED)
  2652. return -7;
  2653. op = avoid_constant_pool_reference (op);
  2654. code = GET_CODE (op);
  2655. switch (GET_RTX_CLASS (code))
  2656. {
  2657. case RTX_CONST_OBJ:
  2658. if (code == CONST_INT)
  2659. return -6;
  2660. if (code == CONST_WIDE_INT)
  2661. return -6;
  2662. if (code == CONST_DOUBLE)
  2663. return -5;
  2664. if (code == CONST_FIXED)
  2665. return -5;
  2666. return -4;
  2667. case RTX_EXTRA:
  2668. /* SUBREGs of objects should come second. */
  2669. if (code == SUBREG && OBJECT_P (SUBREG_REG (op)))
  2670. return -3;
  2671. return 0;
  2672. case RTX_OBJ:
  2673. /* Complex expressions should be the first, so decrease priority
  2674. of objects. Prefer pointer objects over non pointer objects. */
  2675. if ((REG_P (op) && REG_POINTER (op))
  2676. || (MEM_P (op) && MEM_POINTER (op)))
  2677. return -1;
  2678. return -2;
  2679. case RTX_COMM_ARITH:
  2680. /* Prefer operands that are themselves commutative to be first.
  2681. This helps to make things linear. In particular,
  2682. (and (and (reg) (reg)) (not (reg))) is canonical. */
  2683. return 4;
  2684. case RTX_BIN_ARITH:
  2685. /* If only one operand is a binary expression, it will be the first
  2686. operand. In particular, (plus (minus (reg) (reg)) (neg (reg)))
  2687. is canonical, although it will usually be further simplified. */
  2688. return 2;
  2689. case RTX_UNARY:
  2690. /* Then prefer NEG and NOT. */
  2691. if (code == NEG || code == NOT)
  2692. return 1;
  2693. default:
  2694. return 0;
  2695. }
  2696. }
  2697. /* Return 1 iff it is necessary to swap operands of commutative operation
  2698. in order to canonicalize expression. */
  2699. bool
  2700. swap_commutative_operands_p (rtx x, rtx y)
  2701. {
  2702. return (commutative_operand_precedence (x)
  2703. < commutative_operand_precedence (y));
  2704. }
  2705. /* Return 1 if X is an autoincrement side effect and the register is
  2706. not the stack pointer. */
  2707. int
  2708. auto_inc_p (const_rtx x)
  2709. {
  2710. switch (GET_CODE (x))
  2711. {
  2712. case PRE_INC:
  2713. case POST_INC:
  2714. case PRE_DEC:
  2715. case POST_DEC:
  2716. case PRE_MODIFY:
  2717. case POST_MODIFY:
  2718. /* There are no REG_INC notes for SP. */
  2719. if (XEXP (x, 0) != stack_pointer_rtx)
  2720. return 1;
  2721. default:
  2722. break;
  2723. }
  2724. return 0;
  2725. }
  2726. /* Return nonzero if IN contains a piece of rtl that has the address LOC. */
  2727. int
  2728. loc_mentioned_in_p (rtx *loc, const_rtx in)
  2729. {
  2730. enum rtx_code code;
  2731. const char *fmt;
  2732. int i, j;
  2733. if (!in)
  2734. return 0;
  2735. code = GET_CODE (in);
  2736. fmt = GET_RTX_FORMAT (code);
  2737. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2738. {
  2739. if (fmt[i] == 'e')
  2740. {
  2741. if (loc == &XEXP (in, i) || loc_mentioned_in_p (loc, XEXP (in, i)))
  2742. return 1;
  2743. }
  2744. else if (fmt[i] == 'E')
  2745. for (j = XVECLEN (in, i) - 1; j >= 0; j--)
  2746. if (loc == &XVECEXP (in, i, j)
  2747. || loc_mentioned_in_p (loc, XVECEXP (in, i, j)))
  2748. return 1;
  2749. }
  2750. return 0;
  2751. }
  2752. /* Helper function for subreg_lsb. Given a subreg's OUTER_MODE, INNER_MODE,
  2753. and SUBREG_BYTE, return the bit offset where the subreg begins
  2754. (counting from the least significant bit of the operand). */
  2755. unsigned int
  2756. subreg_lsb_1 (machine_mode outer_mode,
  2757. machine_mode inner_mode,
  2758. unsigned int subreg_byte)
  2759. {
  2760. unsigned int bitpos;
  2761. unsigned int byte;
  2762. unsigned int word;
  2763. /* A paradoxical subreg begins at bit position 0. */
  2764. if (GET_MODE_PRECISION (outer_mode) > GET_MODE_PRECISION (inner_mode))
  2765. return 0;
  2766. if (WORDS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
  2767. /* If the subreg crosses a word boundary ensure that
  2768. it also begins and ends on a word boundary. */
  2769. gcc_assert (!((subreg_byte % UNITS_PER_WORD
  2770. + GET_MODE_SIZE (outer_mode)) > UNITS_PER_WORD
  2771. && (subreg_byte % UNITS_PER_WORD
  2772. || GET_MODE_SIZE (outer_mode) % UNITS_PER_WORD)));
  2773. if (WORDS_BIG_ENDIAN)
  2774. word = (GET_MODE_SIZE (inner_mode)
  2775. - (subreg_byte + GET_MODE_SIZE (outer_mode))) / UNITS_PER_WORD;
  2776. else
  2777. word = subreg_byte / UNITS_PER_WORD;
  2778. bitpos = word * BITS_PER_WORD;
  2779. if (BYTES_BIG_ENDIAN)
  2780. byte = (GET_MODE_SIZE (inner_mode)
  2781. - (subreg_byte + GET_MODE_SIZE (outer_mode))) % UNITS_PER_WORD;
  2782. else
  2783. byte = subreg_byte % UNITS_PER_WORD;
  2784. bitpos += byte * BITS_PER_UNIT;
  2785. return bitpos;
  2786. }
  2787. /* Given a subreg X, return the bit offset where the subreg begins
  2788. (counting from the least significant bit of the reg). */
  2789. unsigned int
  2790. subreg_lsb (const_rtx x)
  2791. {
  2792. return subreg_lsb_1 (GET_MODE (x), GET_MODE (SUBREG_REG (x)),
  2793. SUBREG_BYTE (x));
  2794. }
  2795. /* Fill in information about a subreg of a hard register.
  2796. xregno - A regno of an inner hard subreg_reg (or what will become one).
  2797. xmode - The mode of xregno.
  2798. offset - The byte offset.
  2799. ymode - The mode of a top level SUBREG (or what may become one).
  2800. info - Pointer to structure to fill in.
  2801. Rather than considering one particular inner register (and thus one
  2802. particular "outer" register) in isolation, this function really uses
  2803. XREGNO as a model for a sequence of isomorphic hard registers. Thus the
  2804. function does not check whether adding INFO->offset to XREGNO gives
  2805. a valid hard register; even if INFO->offset + XREGNO is out of range,
  2806. there might be another register of the same type that is in range.
  2807. Likewise it doesn't check whether HARD_REGNO_MODE_OK accepts the new
  2808. register, since that can depend on things like whether the final
  2809. register number is even or odd. Callers that want to check whether
  2810. this particular subreg can be replaced by a simple (reg ...) should
  2811. use simplify_subreg_regno. */
  2812. void
  2813. subreg_get_info (unsigned int xregno, machine_mode xmode,
  2814. unsigned int offset, machine_mode ymode,
  2815. struct subreg_info *info)
  2816. {
  2817. int nregs_xmode, nregs_ymode;
  2818. int mode_multiple, nregs_multiple;
  2819. int offset_adj, y_offset, y_offset_adj;
  2820. int regsize_xmode, regsize_ymode;
  2821. bool rknown;
  2822. gcc_assert (xregno < FIRST_PSEUDO_REGISTER);
  2823. rknown = false;
  2824. /* If there are holes in a non-scalar mode in registers, we expect
  2825. that it is made up of its units concatenated together. */
  2826. if (HARD_REGNO_NREGS_HAS_PADDING (xregno, xmode))
  2827. {
  2828. machine_mode xmode_unit;
  2829. nregs_xmode = HARD_REGNO_NREGS_WITH_PADDING (xregno, xmode);
  2830. if (GET_MODE_INNER (xmode) == VOIDmode)
  2831. xmode_unit = xmode;
  2832. else
  2833. xmode_unit = GET_MODE_INNER (xmode);
  2834. gcc_assert (HARD_REGNO_NREGS_HAS_PADDING (xregno, xmode_unit));
  2835. gcc_assert (nregs_xmode
  2836. == (GET_MODE_NUNITS (xmode)
  2837. * HARD_REGNO_NREGS_WITH_PADDING (xregno, xmode_unit)));
  2838. gcc_assert (hard_regno_nregs[xregno][xmode]
  2839. == (hard_regno_nregs[xregno][xmode_unit]
  2840. * GET_MODE_NUNITS (xmode)));
  2841. /* You can only ask for a SUBREG of a value with holes in the middle
  2842. if you don't cross the holes. (Such a SUBREG should be done by
  2843. picking a different register class, or doing it in memory if
  2844. necessary.) An example of a value with holes is XCmode on 32-bit
  2845. x86 with -m128bit-long-double; it's represented in 6 32-bit registers,
  2846. 3 for each part, but in memory it's two 128-bit parts.
  2847. Padding is assumed to be at the end (not necessarily the 'high part')
  2848. of each unit. */
  2849. if ((offset / GET_MODE_SIZE (xmode_unit) + 1
  2850. < GET_MODE_NUNITS (xmode))
  2851. && (offset / GET_MODE_SIZE (xmode_unit)
  2852. != ((offset + GET_MODE_SIZE (ymode) - 1)
  2853. / GET_MODE_SIZE (xmode_unit))))
  2854. {
  2855. info->representable_p = false;
  2856. rknown = true;
  2857. }
  2858. }
  2859. else
  2860. nregs_xmode = hard_regno_nregs[xregno][xmode];
  2861. nregs_ymode = hard_regno_nregs[xregno][ymode];
  2862. /* Paradoxical subregs are otherwise valid. */
  2863. if (!rknown
  2864. && offset == 0
  2865. && GET_MODE_PRECISION (ymode) > GET_MODE_PRECISION (xmode))
  2866. {
  2867. info->representable_p = true;
  2868. /* If this is a big endian paradoxical subreg, which uses more
  2869. actual hard registers than the original register, we must
  2870. return a negative offset so that we find the proper highpart
  2871. of the register. */
  2872. if (GET_MODE_SIZE (ymode) > UNITS_PER_WORD
  2873. ? REG_WORDS_BIG_ENDIAN : BYTES_BIG_ENDIAN)
  2874. info->offset = nregs_xmode - nregs_ymode;
  2875. else
  2876. info->offset = 0;
  2877. info->nregs = nregs_ymode;
  2878. return;
  2879. }
  2880. /* If registers store different numbers of bits in the different
  2881. modes, we cannot generally form this subreg. */
  2882. if (!HARD_REGNO_NREGS_HAS_PADDING (xregno, xmode)
  2883. && !HARD_REGNO_NREGS_HAS_PADDING (xregno, ymode)
  2884. && (GET_MODE_SIZE (xmode) % nregs_xmode) == 0
  2885. && (GET_MODE_SIZE (ymode) % nregs_ymode) == 0)
  2886. {
  2887. regsize_xmode = GET_MODE_SIZE (xmode) / nregs_xmode;
  2888. regsize_ymode = GET_MODE_SIZE (ymode) / nregs_ymode;
  2889. if (!rknown && regsize_xmode > regsize_ymode && nregs_ymode > 1)
  2890. {
  2891. info->representable_p = false;
  2892. info->nregs
  2893. = (GET_MODE_SIZE (ymode) + regsize_xmode - 1) / regsize_xmode;
  2894. info->offset = offset / regsize_xmode;
  2895. return;
  2896. }
  2897. if (!rknown && regsize_ymode > regsize_xmode && nregs_xmode > 1)
  2898. {
  2899. info->representable_p = false;
  2900. info->nregs
  2901. = (GET_MODE_SIZE (ymode) + regsize_xmode - 1) / regsize_xmode;
  2902. info->offset = offset / regsize_xmode;
  2903. return;
  2904. }
  2905. /* Quick exit for the simple and common case of extracting whole
  2906. subregisters from a multiregister value. */
  2907. /* ??? It would be better to integrate this into the code below,
  2908. if we can generalize the concept enough and figure out how
  2909. odd-sized modes can coexist with the other weird cases we support. */
  2910. if (!rknown
  2911. && WORDS_BIG_ENDIAN == REG_WORDS_BIG_ENDIAN
  2912. && regsize_xmode == regsize_ymode
  2913. && (offset % regsize_ymode) == 0)
  2914. {
  2915. info->representable_p = true;
  2916. info->nregs = nregs_ymode;
  2917. info->offset = offset / regsize_ymode;
  2918. gcc_assert (info->offset + info->nregs <= nregs_xmode);
  2919. return;
  2920. }
  2921. }
  2922. /* Lowpart subregs are otherwise valid. */
  2923. if (!rknown && offset == subreg_lowpart_offset (ymode, xmode))
  2924. {
  2925. info->representable_p = true;
  2926. rknown = true;
  2927. if (offset == 0 || nregs_xmode == nregs_ymode)
  2928. {
  2929. info->offset = 0;
  2930. info->nregs = nregs_ymode;
  2931. return;
  2932. }
  2933. }
  2934. /* This should always pass, otherwise we don't know how to verify
  2935. the constraint. These conditions may be relaxed but
  2936. subreg_regno_offset would need to be redesigned. */
  2937. gcc_assert ((GET_MODE_SIZE (xmode) % GET_MODE_SIZE (ymode)) == 0);
  2938. gcc_assert ((nregs_xmode % nregs_ymode) == 0);
  2939. if (WORDS_BIG_ENDIAN != REG_WORDS_BIG_ENDIAN
  2940. && GET_MODE_SIZE (xmode) > UNITS_PER_WORD)
  2941. {
  2942. HOST_WIDE_INT xsize = GET_MODE_SIZE (xmode);
  2943. HOST_WIDE_INT ysize = GET_MODE_SIZE (ymode);
  2944. HOST_WIDE_INT off_low = offset & (ysize - 1);
  2945. HOST_WIDE_INT off_high = offset & ~(ysize - 1);
  2946. offset = (xsize - ysize - off_high) | off_low;
  2947. }
  2948. /* The XMODE value can be seen as a vector of NREGS_XMODE
  2949. values. The subreg must represent a lowpart of given field.
  2950. Compute what field it is. */
  2951. offset_adj = offset;
  2952. offset_adj -= subreg_lowpart_offset (ymode,
  2953. mode_for_size (GET_MODE_BITSIZE (xmode)
  2954. / nregs_xmode,
  2955. MODE_INT, 0));
  2956. /* Size of ymode must not be greater than the size of xmode. */
  2957. mode_multiple = GET_MODE_SIZE (xmode) / GET_MODE_SIZE (ymode);
  2958. gcc_assert (mode_multiple != 0);
  2959. y_offset = offset / GET_MODE_SIZE (ymode);
  2960. y_offset_adj = offset_adj / GET_MODE_SIZE (ymode);
  2961. nregs_multiple = nregs_xmode / nregs_ymode;
  2962. gcc_assert ((offset_adj % GET_MODE_SIZE (ymode)) == 0);
  2963. gcc_assert ((mode_multiple % nregs_multiple) == 0);
  2964. if (!rknown)
  2965. {
  2966. info->representable_p = (!(y_offset_adj % (mode_multiple / nregs_multiple)));
  2967. rknown = true;
  2968. }
  2969. info->offset = (y_offset / (mode_multiple / nregs_multiple)) * nregs_ymode;
  2970. info->nregs = nregs_ymode;
  2971. }
  2972. /* This function returns the regno offset of a subreg expression.
  2973. xregno - A regno of an inner hard subreg_reg (or what will become one).
  2974. xmode - The mode of xregno.
  2975. offset - The byte offset.
  2976. ymode - The mode of a top level SUBREG (or what may become one).
  2977. RETURN - The regno offset which would be used. */
  2978. unsigned int
  2979. subreg_regno_offset (unsigned int xregno, machine_mode xmode,
  2980. unsigned int offset, machine_mode ymode)
  2981. {
  2982. struct subreg_info info;
  2983. subreg_get_info (xregno, xmode, offset, ymode, &info);
  2984. return info.offset;
  2985. }
  2986. /* This function returns true when the offset is representable via
  2987. subreg_offset in the given regno.
  2988. xregno - A regno of an inner hard subreg_reg (or what will become one).
  2989. xmode - The mode of xregno.
  2990. offset - The byte offset.
  2991. ymode - The mode of a top level SUBREG (or what may become one).
  2992. RETURN - Whether the offset is representable. */
  2993. bool
  2994. subreg_offset_representable_p (unsigned int xregno, machine_mode xmode,
  2995. unsigned int offset, machine_mode ymode)
  2996. {
  2997. struct subreg_info info;
  2998. subreg_get_info (xregno, xmode, offset, ymode, &info);
  2999. return info.representable_p;
  3000. }
  3001. /* Return the number of a YMODE register to which
  3002. (subreg:YMODE (reg:XMODE XREGNO) OFFSET)
  3003. can be simplified. Return -1 if the subreg can't be simplified.
  3004. XREGNO is a hard register number. */
  3005. int
  3006. simplify_subreg_regno (unsigned int xregno, machine_mode xmode,
  3007. unsigned int offset, machine_mode ymode)
  3008. {
  3009. struct subreg_info info;
  3010. unsigned int yregno;
  3011. #ifdef CANNOT_CHANGE_MODE_CLASS
  3012. /* Give the backend a chance to disallow the mode change. */
  3013. if (GET_MODE_CLASS (xmode) != MODE_COMPLEX_INT
  3014. && GET_MODE_CLASS (xmode) != MODE_COMPLEX_FLOAT
  3015. && REG_CANNOT_CHANGE_MODE_P (xregno, xmode, ymode)
  3016. /* We can use mode change in LRA for some transformations. */
  3017. && ! lra_in_progress)
  3018. return -1;
  3019. #endif
  3020. /* We shouldn't simplify stack-related registers. */
  3021. if ((!reload_completed || frame_pointer_needed)
  3022. && xregno == FRAME_POINTER_REGNUM)
  3023. return -1;
  3024. if (FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  3025. && xregno == ARG_POINTER_REGNUM)
  3026. return -1;
  3027. if (xregno == STACK_POINTER_REGNUM
  3028. /* We should convert hard stack register in LRA if it is
  3029. possible. */
  3030. && ! lra_in_progress)
  3031. return -1;
  3032. /* Try to get the register offset. */
  3033. subreg_get_info (xregno, xmode, offset, ymode, &info);
  3034. if (!info.representable_p)
  3035. return -1;
  3036. /* Make sure that the offsetted register value is in range. */
  3037. yregno = xregno + info.offset;
  3038. if (!HARD_REGISTER_NUM_P (yregno))
  3039. return -1;
  3040. /* See whether (reg:YMODE YREGNO) is valid.
  3041. ??? We allow invalid registers if (reg:XMODE XREGNO) is also invalid.
  3042. This is a kludge to work around how complex FP arguments are passed
  3043. on IA-64 and should be fixed. See PR target/49226. */
  3044. if (!HARD_REGNO_MODE_OK (yregno, ymode)
  3045. && HARD_REGNO_MODE_OK (xregno, xmode))
  3046. return -1;
  3047. return (int) yregno;
  3048. }
  3049. /* Return the final regno that a subreg expression refers to. */
  3050. unsigned int
  3051. subreg_regno (const_rtx x)
  3052. {
  3053. unsigned int ret;
  3054. rtx subreg = SUBREG_REG (x);
  3055. int regno = REGNO (subreg);
  3056. ret = regno + subreg_regno_offset (regno,
  3057. GET_MODE (subreg),
  3058. SUBREG_BYTE (x),
  3059. GET_MODE (x));
  3060. return ret;
  3061. }
  3062. /* Return the number of registers that a subreg expression refers
  3063. to. */
  3064. unsigned int
  3065. subreg_nregs (const_rtx x)
  3066. {
  3067. return subreg_nregs_with_regno (REGNO (SUBREG_REG (x)), x);
  3068. }
  3069. /* Return the number of registers that a subreg REG with REGNO
  3070. expression refers to. This is a copy of the rtlanal.c:subreg_nregs
  3071. changed so that the regno can be passed in. */
  3072. unsigned int
  3073. subreg_nregs_with_regno (unsigned int regno, const_rtx x)
  3074. {
  3075. struct subreg_info info;
  3076. rtx subreg = SUBREG_REG (x);
  3077. subreg_get_info (regno, GET_MODE (subreg), SUBREG_BYTE (x), GET_MODE (x),
  3078. &info);
  3079. return info.nregs;
  3080. }
  3081. struct parms_set_data
  3082. {
  3083. int nregs;
  3084. HARD_REG_SET regs;
  3085. };
  3086. /* Helper function for noticing stores to parameter registers. */
  3087. static void
  3088. parms_set (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
  3089. {
  3090. struct parms_set_data *const d = (struct parms_set_data *) data;
  3091. if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
  3092. && TEST_HARD_REG_BIT (d->regs, REGNO (x)))
  3093. {
  3094. CLEAR_HARD_REG_BIT (d->regs, REGNO (x));
  3095. d->nregs--;
  3096. }
  3097. }
  3098. /* Look backward for first parameter to be loaded.
  3099. Note that loads of all parameters will not necessarily be
  3100. found if CSE has eliminated some of them (e.g., an argument
  3101. to the outer function is passed down as a parameter).
  3102. Do not skip BOUNDARY. */
  3103. rtx_insn *
  3104. find_first_parameter_load (rtx_insn *call_insn, rtx_insn *boundary)
  3105. {
  3106. struct parms_set_data parm;
  3107. rtx p;
  3108. rtx_insn *before, *first_set;
  3109. /* Since different machines initialize their parameter registers
  3110. in different orders, assume nothing. Collect the set of all
  3111. parameter registers. */
  3112. CLEAR_HARD_REG_SET (parm.regs);
  3113. parm.nregs = 0;
  3114. for (p = CALL_INSN_FUNCTION_USAGE (call_insn); p; p = XEXP (p, 1))
  3115. if (GET_CODE (XEXP (p, 0)) == USE
  3116. && REG_P (XEXP (XEXP (p, 0), 0)))
  3117. {
  3118. gcc_assert (REGNO (XEXP (XEXP (p, 0), 0)) < FIRST_PSEUDO_REGISTER);
  3119. /* We only care about registers which can hold function
  3120. arguments. */
  3121. if (!FUNCTION_ARG_REGNO_P (REGNO (XEXP (XEXP (p, 0), 0))))
  3122. continue;
  3123. SET_HARD_REG_BIT (parm.regs, REGNO (XEXP (XEXP (p, 0), 0)));
  3124. parm.nregs++;
  3125. }
  3126. before = call_insn;
  3127. first_set = call_insn;
  3128. /* Search backward for the first set of a register in this set. */
  3129. while (parm.nregs && before != boundary)
  3130. {
  3131. before = PREV_INSN (before);
  3132. /* It is possible that some loads got CSEed from one call to
  3133. another. Stop in that case. */
  3134. if (CALL_P (before))
  3135. break;
  3136. /* Our caller needs either ensure that we will find all sets
  3137. (in case code has not been optimized yet), or take care
  3138. for possible labels in a way by setting boundary to preceding
  3139. CODE_LABEL. */
  3140. if (LABEL_P (before))
  3141. {
  3142. gcc_assert (before == boundary);
  3143. break;
  3144. }
  3145. if (INSN_P (before))
  3146. {
  3147. int nregs_old = parm.nregs;
  3148. note_stores (PATTERN (before), parms_set, &parm);
  3149. /* If we found something that did not set a parameter reg,
  3150. we're done. Do not keep going, as that might result
  3151. in hoisting an insn before the setting of a pseudo
  3152. that is used by the hoisted insn. */
  3153. if (nregs_old != parm.nregs)
  3154. first_set = before;
  3155. else
  3156. break;
  3157. }
  3158. }
  3159. return first_set;
  3160. }
  3161. /* Return true if we should avoid inserting code between INSN and preceding
  3162. call instruction. */
  3163. bool
  3164. keep_with_call_p (const rtx_insn *insn)
  3165. {
  3166. rtx set;
  3167. if (INSN_P (insn) && (set = single_set (insn)) != NULL)
  3168. {
  3169. if (REG_P (SET_DEST (set))
  3170. && REGNO (SET_DEST (set)) < FIRST_PSEUDO_REGISTER
  3171. && fixed_regs[REGNO (SET_DEST (set))]
  3172. && general_operand (SET_SRC (set), VOIDmode))
  3173. return true;
  3174. if (REG_P (SET_SRC (set))
  3175. && targetm.calls.function_value_regno_p (REGNO (SET_SRC (set)))
  3176. && REG_P (SET_DEST (set))
  3177. && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER)
  3178. return true;
  3179. /* There may be a stack pop just after the call and before the store
  3180. of the return register. Search for the actual store when deciding
  3181. if we can break or not. */
  3182. if (SET_DEST (set) == stack_pointer_rtx)
  3183. {
  3184. /* This CONST_CAST is okay because next_nonnote_insn just
  3185. returns its argument and we assign it to a const_rtx
  3186. variable. */
  3187. const rtx_insn *i2
  3188. = next_nonnote_insn (const_cast<rtx_insn *> (insn));
  3189. if (i2 && keep_with_call_p (i2))
  3190. return true;
  3191. }
  3192. }
  3193. return false;
  3194. }
  3195. /* Return true if LABEL is a target of JUMP_INSN. This applies only
  3196. to non-complex jumps. That is, direct unconditional, conditional,
  3197. and tablejumps, but not computed jumps or returns. It also does
  3198. not apply to the fallthru case of a conditional jump. */
  3199. bool
  3200. label_is_jump_target_p (const_rtx label, const rtx_insn *jump_insn)
  3201. {
  3202. rtx tmp = JUMP_LABEL (jump_insn);
  3203. rtx_jump_table_data *table;
  3204. if (label == tmp)
  3205. return true;
  3206. if (tablejump_p (jump_insn, NULL, &table))
  3207. {
  3208. rtvec vec = table->get_labels ();
  3209. int i, veclen = GET_NUM_ELEM (vec);
  3210. for (i = 0; i < veclen; ++i)
  3211. if (XEXP (RTVEC_ELT (vec, i), 0) == label)
  3212. return true;
  3213. }
  3214. if (find_reg_note (jump_insn, REG_LABEL_TARGET, label))
  3215. return true;
  3216. return false;
  3217. }
  3218. /* Return an estimate of the cost of computing rtx X.
  3219. One use is in cse, to decide which expression to keep in the hash table.
  3220. Another is in rtl generation, to pick the cheapest way to multiply.
  3221. Other uses like the latter are expected in the future.
  3222. X appears as operand OPNO in an expression with code OUTER_CODE.
  3223. SPEED specifies whether costs optimized for speed or size should
  3224. be returned. */
  3225. int
  3226. rtx_cost (rtx x, enum rtx_code outer_code, int opno, bool speed)
  3227. {
  3228. int i, j;
  3229. enum rtx_code code;
  3230. const char *fmt;
  3231. int total;
  3232. int factor;
  3233. if (x == 0)
  3234. return 0;
  3235. /* A size N times larger than UNITS_PER_WORD likely needs N times as
  3236. many insns, taking N times as long. */
  3237. factor = GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD;
  3238. if (factor == 0)
  3239. factor = 1;
  3240. /* Compute the default costs of certain things.
  3241. Note that targetm.rtx_costs can override the defaults. */
  3242. code = GET_CODE (x);
  3243. switch (code)
  3244. {
  3245. case MULT:
  3246. /* Multiplication has time-complexity O(N*N), where N is the
  3247. number of units (translated from digits) when using
  3248. schoolbook long multiplication. */
  3249. total = factor * factor * COSTS_N_INSNS (5);
  3250. break;
  3251. case DIV:
  3252. case UDIV:
  3253. case MOD:
  3254. case UMOD:
  3255. /* Similarly, complexity for schoolbook long division. */
  3256. total = factor * factor * COSTS_N_INSNS (7);
  3257. break;
  3258. case USE:
  3259. /* Used in combine.c as a marker. */
  3260. total = 0;
  3261. break;
  3262. case SET:
  3263. /* A SET doesn't have a mode, so let's look at the SET_DEST to get
  3264. the mode for the factor. */
  3265. factor = GET_MODE_SIZE (GET_MODE (SET_DEST (x))) / UNITS_PER_WORD;
  3266. if (factor == 0)
  3267. factor = 1;
  3268. /* Pass through. */
  3269. default:
  3270. total = factor * COSTS_N_INSNS (1);
  3271. }
  3272. switch (code)
  3273. {
  3274. case REG:
  3275. return 0;
  3276. case SUBREG:
  3277. total = 0;
  3278. /* If we can't tie these modes, make this expensive. The larger
  3279. the mode, the more expensive it is. */
  3280. if (! MODES_TIEABLE_P (GET_MODE (x), GET_MODE (SUBREG_REG (x))))
  3281. return COSTS_N_INSNS (2 + factor);
  3282. break;
  3283. default:
  3284. if (targetm.rtx_costs (x, code, outer_code, opno, &total, speed))
  3285. return total;
  3286. break;
  3287. }
  3288. /* Sum the costs of the sub-rtx's, plus cost of this operation,
  3289. which is already in total. */
  3290. fmt = GET_RTX_FORMAT (code);
  3291. for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3292. if (fmt[i] == 'e')
  3293. total += rtx_cost (XEXP (x, i), code, i, speed);
  3294. else if (fmt[i] == 'E')
  3295. for (j = 0; j < XVECLEN (x, i); j++)
  3296. total += rtx_cost (XVECEXP (x, i, j), code, i, speed);
  3297. return total;
  3298. }
  3299. /* Fill in the structure C with information about both speed and size rtx
  3300. costs for X, which is operand OPNO in an expression with code OUTER. */
  3301. void
  3302. get_full_rtx_cost (rtx x, enum rtx_code outer, int opno,
  3303. struct full_rtx_costs *c)
  3304. {
  3305. c->speed = rtx_cost (x, outer, opno, true);
  3306. c->size = rtx_cost (x, outer, opno, false);
  3307. }
  3308. /* Return cost of address expression X.
  3309. Expect that X is properly formed address reference.
  3310. SPEED parameter specify whether costs optimized for speed or size should
  3311. be returned. */
  3312. int
  3313. address_cost (rtx x, machine_mode mode, addr_space_t as, bool speed)
  3314. {
  3315. /* We may be asked for cost of various unusual addresses, such as operands
  3316. of push instruction. It is not worthwhile to complicate writing
  3317. of the target hook by such cases. */
  3318. if (!memory_address_addr_space_p (mode, x, as))
  3319. return 1000;
  3320. return targetm.address_cost (x, mode, as, speed);
  3321. }
  3322. /* If the target doesn't override, compute the cost as with arithmetic. */
  3323. int
  3324. default_address_cost (rtx x, machine_mode, addr_space_t, bool speed)
  3325. {
  3326. return rtx_cost (x, MEM, 0, speed);
  3327. }
  3328. unsigned HOST_WIDE_INT
  3329. nonzero_bits (const_rtx x, machine_mode mode)
  3330. {
  3331. return cached_nonzero_bits (x, mode, NULL_RTX, VOIDmode, 0);
  3332. }
  3333. unsigned int
  3334. num_sign_bit_copies (const_rtx x, machine_mode mode)
  3335. {
  3336. return cached_num_sign_bit_copies (x, mode, NULL_RTX, VOIDmode, 0);
  3337. }
  3338. /* The function cached_nonzero_bits is a wrapper around nonzero_bits1.
  3339. It avoids exponential behavior in nonzero_bits1 when X has
  3340. identical subexpressions on the first or the second level. */
  3341. static unsigned HOST_WIDE_INT
  3342. cached_nonzero_bits (const_rtx x, machine_mode mode, const_rtx known_x,
  3343. machine_mode known_mode,
  3344. unsigned HOST_WIDE_INT known_ret)
  3345. {
  3346. if (x == known_x && mode == known_mode)
  3347. return known_ret;
  3348. /* Try to find identical subexpressions. If found call
  3349. nonzero_bits1 on X with the subexpressions as KNOWN_X and the
  3350. precomputed value for the subexpression as KNOWN_RET. */
  3351. if (ARITHMETIC_P (x))
  3352. {
  3353. rtx x0 = XEXP (x, 0);
  3354. rtx x1 = XEXP (x, 1);
  3355. /* Check the first level. */
  3356. if (x0 == x1)
  3357. return nonzero_bits1 (x, mode, x0, mode,
  3358. cached_nonzero_bits (x0, mode, known_x,
  3359. known_mode, known_ret));
  3360. /* Check the second level. */
  3361. if (ARITHMETIC_P (x0)
  3362. && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
  3363. return nonzero_bits1 (x, mode, x1, mode,
  3364. cached_nonzero_bits (x1, mode, known_x,
  3365. known_mode, known_ret));
  3366. if (ARITHMETIC_P (x1)
  3367. && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
  3368. return nonzero_bits1 (x, mode, x0, mode,
  3369. cached_nonzero_bits (x0, mode, known_x,
  3370. known_mode, known_ret));
  3371. }
  3372. return nonzero_bits1 (x, mode, known_x, known_mode, known_ret);
  3373. }
  3374. /* We let num_sign_bit_copies recur into nonzero_bits as that is useful.
  3375. We don't let nonzero_bits recur into num_sign_bit_copies, because that
  3376. is less useful. We can't allow both, because that results in exponential
  3377. run time recursion. There is a nullstone testcase that triggered
  3378. this. This macro avoids accidental uses of num_sign_bit_copies. */
  3379. #define cached_num_sign_bit_copies sorry_i_am_preventing_exponential_behavior
  3380. /* Given an expression, X, compute which bits in X can be nonzero.
  3381. We don't care about bits outside of those defined in MODE.
  3382. For most X this is simply GET_MODE_MASK (GET_MODE (MODE)), but if X is
  3383. an arithmetic operation, we can do better. */
  3384. static unsigned HOST_WIDE_INT
  3385. nonzero_bits1 (const_rtx x, machine_mode mode, const_rtx known_x,
  3386. machine_mode known_mode,
  3387. unsigned HOST_WIDE_INT known_ret)
  3388. {
  3389. unsigned HOST_WIDE_INT nonzero = GET_MODE_MASK (mode);
  3390. unsigned HOST_WIDE_INT inner_nz;
  3391. enum rtx_code code;
  3392. machine_mode inner_mode;
  3393. unsigned int mode_width = GET_MODE_PRECISION (mode);
  3394. /* For floating-point and vector values, assume all bits are needed. */
  3395. if (FLOAT_MODE_P (GET_MODE (x)) || FLOAT_MODE_P (mode)
  3396. || VECTOR_MODE_P (GET_MODE (x)) || VECTOR_MODE_P (mode))
  3397. return nonzero;
  3398. /* If X is wider than MODE, use its mode instead. */
  3399. if (GET_MODE_PRECISION (GET_MODE (x)) > mode_width)
  3400. {
  3401. mode = GET_MODE (x);
  3402. nonzero = GET_MODE_MASK (mode);
  3403. mode_width = GET_MODE_PRECISION (mode);
  3404. }
  3405. if (mode_width > HOST_BITS_PER_WIDE_INT)
  3406. /* Our only callers in this case look for single bit values. So
  3407. just return the mode mask. Those tests will then be false. */
  3408. return nonzero;
  3409. #ifndef WORD_REGISTER_OPERATIONS
  3410. /* If MODE is wider than X, but both are a single word for both the host
  3411. and target machines, we can compute this from which bits of the
  3412. object might be nonzero in its own mode, taking into account the fact
  3413. that on many CISC machines, accessing an object in a wider mode
  3414. causes the high-order bits to become undefined. So they are
  3415. not known to be zero. */
  3416. if (GET_MODE (x) != VOIDmode && GET_MODE (x) != mode
  3417. && GET_MODE_PRECISION (GET_MODE (x)) <= BITS_PER_WORD
  3418. && GET_MODE_PRECISION (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT
  3419. && GET_MODE_PRECISION (mode) > GET_MODE_PRECISION (GET_MODE (x)))
  3420. {
  3421. nonzero &= cached_nonzero_bits (x, GET_MODE (x),
  3422. known_x, known_mode, known_ret);
  3423. nonzero |= GET_MODE_MASK (mode) & ~GET_MODE_MASK (GET_MODE (x));
  3424. return nonzero;
  3425. }
  3426. #endif
  3427. code = GET_CODE (x);
  3428. switch (code)
  3429. {
  3430. case REG:
  3431. #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
  3432. /* If pointers extend unsigned and this is a pointer in Pmode, say that
  3433. all the bits above ptr_mode are known to be zero. */
  3434. /* As we do not know which address space the pointer is referring to,
  3435. we can do this only if the target does not support different pointer
  3436. or address modes depending on the address space. */
  3437. if (target_default_pointer_address_modes_p ()
  3438. && POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
  3439. && REG_POINTER (x))
  3440. nonzero &= GET_MODE_MASK (ptr_mode);
  3441. #endif
  3442. /* Include declared information about alignment of pointers. */
  3443. /* ??? We don't properly preserve REG_POINTER changes across
  3444. pointer-to-integer casts, so we can't trust it except for
  3445. things that we know must be pointers. See execute/960116-1.c. */
  3446. if ((x == stack_pointer_rtx
  3447. || x == frame_pointer_rtx
  3448. || x == arg_pointer_rtx)
  3449. && REGNO_POINTER_ALIGN (REGNO (x)))
  3450. {
  3451. unsigned HOST_WIDE_INT alignment
  3452. = REGNO_POINTER_ALIGN (REGNO (x)) / BITS_PER_UNIT;
  3453. #ifdef PUSH_ROUNDING
  3454. /* If PUSH_ROUNDING is defined, it is possible for the
  3455. stack to be momentarily aligned only to that amount,
  3456. so we pick the least alignment. */
  3457. if (x == stack_pointer_rtx && PUSH_ARGS)
  3458. alignment = MIN ((unsigned HOST_WIDE_INT) PUSH_ROUNDING (1),
  3459. alignment);
  3460. #endif
  3461. nonzero &= ~(alignment - 1);
  3462. }
  3463. {
  3464. unsigned HOST_WIDE_INT nonzero_for_hook = nonzero;
  3465. rtx new_rtx = rtl_hooks.reg_nonzero_bits (x, mode, known_x,
  3466. known_mode, known_ret,
  3467. &nonzero_for_hook);
  3468. if (new_rtx)
  3469. nonzero_for_hook &= cached_nonzero_bits (new_rtx, mode, known_x,
  3470. known_mode, known_ret);
  3471. return nonzero_for_hook;
  3472. }
  3473. case CONST_INT:
  3474. #ifdef SHORT_IMMEDIATES_SIGN_EXTEND
  3475. /* If X is negative in MODE, sign-extend the value. */
  3476. if (INTVAL (x) > 0
  3477. && mode_width < BITS_PER_WORD
  3478. && (UINTVAL (x) & ((unsigned HOST_WIDE_INT) 1 << (mode_width - 1)))
  3479. != 0)
  3480. return UINTVAL (x) | (HOST_WIDE_INT_M1U << mode_width);
  3481. #endif
  3482. return UINTVAL (x);
  3483. case MEM:
  3484. #ifdef LOAD_EXTEND_OP
  3485. /* In many, if not most, RISC machines, reading a byte from memory
  3486. zeros the rest of the register. Noticing that fact saves a lot
  3487. of extra zero-extends. */
  3488. if (LOAD_EXTEND_OP (GET_MODE (x)) == ZERO_EXTEND)
  3489. nonzero &= GET_MODE_MASK (GET_MODE (x));
  3490. #endif
  3491. break;
  3492. case EQ: case NE:
  3493. case UNEQ: case LTGT:
  3494. case GT: case GTU: case UNGT:
  3495. case LT: case LTU: case UNLT:
  3496. case GE: case GEU: case UNGE:
  3497. case LE: case LEU: case UNLE:
  3498. case UNORDERED: case ORDERED:
  3499. /* If this produces an integer result, we know which bits are set.
  3500. Code here used to clear bits outside the mode of X, but that is
  3501. now done above. */
  3502. /* Mind that MODE is the mode the caller wants to look at this
  3503. operation in, and not the actual operation mode. We can wind
  3504. up with (subreg:DI (gt:V4HI x y)), and we don't have anything
  3505. that describes the results of a vector compare. */
  3506. if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
  3507. && mode_width <= HOST_BITS_PER_WIDE_INT)
  3508. nonzero = STORE_FLAG_VALUE;
  3509. break;
  3510. case NEG:
  3511. #if 0
  3512. /* Disabled to avoid exponential mutual recursion between nonzero_bits
  3513. and num_sign_bit_copies. */
  3514. if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
  3515. == GET_MODE_PRECISION (GET_MODE (x)))
  3516. nonzero = 1;
  3517. #endif
  3518. if (GET_MODE_PRECISION (GET_MODE (x)) < mode_width)
  3519. nonzero |= (GET_MODE_MASK (mode) & ~GET_MODE_MASK (GET_MODE (x)));
  3520. break;
  3521. case ABS:
  3522. #if 0
  3523. /* Disabled to avoid exponential mutual recursion between nonzero_bits
  3524. and num_sign_bit_copies. */
  3525. if (num_sign_bit_copies (XEXP (x, 0), GET_MODE (x))
  3526. == GET_MODE_PRECISION (GET_MODE (x)))
  3527. nonzero = 1;
  3528. #endif
  3529. break;
  3530. case TRUNCATE:
  3531. nonzero &= (cached_nonzero_bits (XEXP (x, 0), mode,
  3532. known_x, known_mode, known_ret)
  3533. & GET_MODE_MASK (mode));
  3534. break;
  3535. case ZERO_EXTEND:
  3536. nonzero &= cached_nonzero_bits (XEXP (x, 0), mode,
  3537. known_x, known_mode, known_ret);
  3538. if (GET_MODE (XEXP (x, 0)) != VOIDmode)
  3539. nonzero &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
  3540. break;
  3541. case SIGN_EXTEND:
  3542. /* If the sign bit is known clear, this is the same as ZERO_EXTEND.
  3543. Otherwise, show all the bits in the outer mode but not the inner
  3544. may be nonzero. */
  3545. inner_nz = cached_nonzero_bits (XEXP (x, 0), mode,
  3546. known_x, known_mode, known_ret);
  3547. if (GET_MODE (XEXP (x, 0)) != VOIDmode)
  3548. {
  3549. inner_nz &= GET_MODE_MASK (GET_MODE (XEXP (x, 0)));
  3550. if (val_signbit_known_set_p (GET_MODE (XEXP (x, 0)), inner_nz))
  3551. inner_nz |= (GET_MODE_MASK (mode)
  3552. & ~GET_MODE_MASK (GET_MODE (XEXP (x, 0))));
  3553. }
  3554. nonzero &= inner_nz;
  3555. break;
  3556. case AND:
  3557. nonzero &= cached_nonzero_bits (XEXP (x, 0), mode,
  3558. known_x, known_mode, known_ret)
  3559. & cached_nonzero_bits (XEXP (x, 1), mode,
  3560. known_x, known_mode, known_ret);
  3561. break;
  3562. case XOR: case IOR:
  3563. case UMIN: case UMAX: case SMIN: case SMAX:
  3564. {
  3565. unsigned HOST_WIDE_INT nonzero0
  3566. = cached_nonzero_bits (XEXP (x, 0), mode,
  3567. known_x, known_mode, known_ret);
  3568. /* Don't call nonzero_bits for the second time if it cannot change
  3569. anything. */
  3570. if ((nonzero & nonzero0) != nonzero)
  3571. nonzero &= nonzero0
  3572. | cached_nonzero_bits (XEXP (x, 1), mode,
  3573. known_x, known_mode, known_ret);
  3574. }
  3575. break;
  3576. case PLUS: case MINUS:
  3577. case MULT:
  3578. case DIV: case UDIV:
  3579. case MOD: case UMOD:
  3580. /* We can apply the rules of arithmetic to compute the number of
  3581. high- and low-order zero bits of these operations. We start by
  3582. computing the width (position of the highest-order nonzero bit)
  3583. and the number of low-order zero bits for each value. */
  3584. {
  3585. unsigned HOST_WIDE_INT nz0
  3586. = cached_nonzero_bits (XEXP (x, 0), mode,
  3587. known_x, known_mode, known_ret);
  3588. unsigned HOST_WIDE_INT nz1
  3589. = cached_nonzero_bits (XEXP (x, 1), mode,
  3590. known_x, known_mode, known_ret);
  3591. int sign_index = GET_MODE_PRECISION (GET_MODE (x)) - 1;
  3592. int width0 = floor_log2 (nz0) + 1;
  3593. int width1 = floor_log2 (nz1) + 1;
  3594. int low0 = floor_log2 (nz0 & -nz0);
  3595. int low1 = floor_log2 (nz1 & -nz1);
  3596. unsigned HOST_WIDE_INT op0_maybe_minusp
  3597. = nz0 & ((unsigned HOST_WIDE_INT) 1 << sign_index);
  3598. unsigned HOST_WIDE_INT op1_maybe_minusp
  3599. = nz1 & ((unsigned HOST_WIDE_INT) 1 << sign_index);
  3600. unsigned int result_width = mode_width;
  3601. int result_low = 0;
  3602. switch (code)
  3603. {
  3604. case PLUS:
  3605. result_width = MAX (width0, width1) + 1;
  3606. result_low = MIN (low0, low1);
  3607. break;
  3608. case MINUS:
  3609. result_low = MIN (low0, low1);
  3610. break;
  3611. case MULT:
  3612. result_width = width0 + width1;
  3613. result_low = low0 + low1;
  3614. break;
  3615. case DIV:
  3616. if (width1 == 0)
  3617. break;
  3618. if (!op0_maybe_minusp && !op1_maybe_minusp)
  3619. result_width = width0;
  3620. break;
  3621. case UDIV:
  3622. if (width1 == 0)
  3623. break;
  3624. result_width = width0;
  3625. break;
  3626. case MOD:
  3627. if (width1 == 0)
  3628. break;
  3629. if (!op0_maybe_minusp && !op1_maybe_minusp)
  3630. result_width = MIN (width0, width1);
  3631. result_low = MIN (low0, low1);
  3632. break;
  3633. case UMOD:
  3634. if (width1 == 0)
  3635. break;
  3636. result_width = MIN (width0, width1);
  3637. result_low = MIN (low0, low1);
  3638. break;
  3639. default:
  3640. gcc_unreachable ();
  3641. }
  3642. if (result_width < mode_width)
  3643. nonzero &= ((unsigned HOST_WIDE_INT) 1 << result_width) - 1;
  3644. if (result_low > 0)
  3645. nonzero &= ~(((unsigned HOST_WIDE_INT) 1 << result_low) - 1);
  3646. }
  3647. break;
  3648. case ZERO_EXTRACT:
  3649. if (CONST_INT_P (XEXP (x, 1))
  3650. && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
  3651. nonzero &= ((unsigned HOST_WIDE_INT) 1 << INTVAL (XEXP (x, 1))) - 1;
  3652. break;
  3653. case SUBREG:
  3654. /* If this is a SUBREG formed for a promoted variable that has
  3655. been zero-extended, we know that at least the high-order bits
  3656. are zero, though others might be too. */
  3657. if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_UNSIGNED_P (x))
  3658. nonzero = GET_MODE_MASK (GET_MODE (x))
  3659. & cached_nonzero_bits (SUBREG_REG (x), GET_MODE (x),
  3660. known_x, known_mode, known_ret);
  3661. inner_mode = GET_MODE (SUBREG_REG (x));
  3662. /* If the inner mode is a single word for both the host and target
  3663. machines, we can compute this from which bits of the inner
  3664. object might be nonzero. */
  3665. if (GET_MODE_PRECISION (inner_mode) <= BITS_PER_WORD
  3666. && (GET_MODE_PRECISION (inner_mode) <= HOST_BITS_PER_WIDE_INT))
  3667. {
  3668. nonzero &= cached_nonzero_bits (SUBREG_REG (x), mode,
  3669. known_x, known_mode, known_ret);
  3670. #if defined (WORD_REGISTER_OPERATIONS) && defined (LOAD_EXTEND_OP)
  3671. /* If this is a typical RISC machine, we only have to worry
  3672. about the way loads are extended. */
  3673. if ((LOAD_EXTEND_OP (inner_mode) == SIGN_EXTEND
  3674. ? val_signbit_known_set_p (inner_mode, nonzero)
  3675. : LOAD_EXTEND_OP (inner_mode) != ZERO_EXTEND)
  3676. || !MEM_P (SUBREG_REG (x)))
  3677. #endif
  3678. {
  3679. /* On many CISC machines, accessing an object in a wider mode
  3680. causes the high-order bits to become undefined. So they are
  3681. not known to be zero. */
  3682. if (GET_MODE_PRECISION (GET_MODE (x))
  3683. > GET_MODE_PRECISION (inner_mode))
  3684. nonzero |= (GET_MODE_MASK (GET_MODE (x))
  3685. & ~GET_MODE_MASK (inner_mode));
  3686. }
  3687. }
  3688. break;
  3689. case ASHIFTRT:
  3690. case LSHIFTRT:
  3691. case ASHIFT:
  3692. case ROTATE:
  3693. /* The nonzero bits are in two classes: any bits within MODE
  3694. that aren't in GET_MODE (x) are always significant. The rest of the
  3695. nonzero bits are those that are significant in the operand of
  3696. the shift when shifted the appropriate number of bits. This
  3697. shows that high-order bits are cleared by the right shift and
  3698. low-order bits by left shifts. */
  3699. if (CONST_INT_P (XEXP (x, 1))
  3700. && INTVAL (XEXP (x, 1)) >= 0
  3701. && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT
  3702. && INTVAL (XEXP (x, 1)) < GET_MODE_PRECISION (GET_MODE (x)))
  3703. {
  3704. machine_mode inner_mode = GET_MODE (x);
  3705. unsigned int width = GET_MODE_PRECISION (inner_mode);
  3706. int count = INTVAL (XEXP (x, 1));
  3707. unsigned HOST_WIDE_INT mode_mask = GET_MODE_MASK (inner_mode);
  3708. unsigned HOST_WIDE_INT op_nonzero
  3709. = cached_nonzero_bits (XEXP (x, 0), mode,
  3710. known_x, known_mode, known_ret);
  3711. unsigned HOST_WIDE_INT inner = op_nonzero & mode_mask;
  3712. unsigned HOST_WIDE_INT outer = 0;
  3713. if (mode_width > width)
  3714. outer = (op_nonzero & nonzero & ~mode_mask);
  3715. if (code == LSHIFTRT)
  3716. inner >>= count;
  3717. else if (code == ASHIFTRT)
  3718. {
  3719. inner >>= count;
  3720. /* If the sign bit may have been nonzero before the shift, we
  3721. need to mark all the places it could have been copied to
  3722. by the shift as possibly nonzero. */
  3723. if (inner & ((unsigned HOST_WIDE_INT) 1 << (width - 1 - count)))
  3724. inner |= (((unsigned HOST_WIDE_INT) 1 << count) - 1)
  3725. << (width - count);
  3726. }
  3727. else if (code == ASHIFT)
  3728. inner <<= count;
  3729. else
  3730. inner = ((inner << (count % width)
  3731. | (inner >> (width - (count % width)))) & mode_mask);
  3732. nonzero &= (outer | inner);
  3733. }
  3734. break;
  3735. case FFS:
  3736. case POPCOUNT:
  3737. /* This is at most the number of bits in the mode. */
  3738. nonzero = ((unsigned HOST_WIDE_INT) 2 << (floor_log2 (mode_width))) - 1;
  3739. break;
  3740. case CLZ:
  3741. /* If CLZ has a known value at zero, then the nonzero bits are
  3742. that value, plus the number of bits in the mode minus one. */
  3743. if (CLZ_DEFINED_VALUE_AT_ZERO (mode, nonzero))
  3744. nonzero
  3745. |= ((unsigned HOST_WIDE_INT) 1 << (floor_log2 (mode_width))) - 1;
  3746. else
  3747. nonzero = -1;
  3748. break;
  3749. case CTZ:
  3750. /* If CTZ has a known value at zero, then the nonzero bits are
  3751. that value, plus the number of bits in the mode minus one. */
  3752. if (CTZ_DEFINED_VALUE_AT_ZERO (mode, nonzero))
  3753. nonzero
  3754. |= ((unsigned HOST_WIDE_INT) 1 << (floor_log2 (mode_width))) - 1;
  3755. else
  3756. nonzero = -1;
  3757. break;
  3758. case CLRSB:
  3759. /* This is at most the number of bits in the mode minus 1. */
  3760. nonzero = ((unsigned HOST_WIDE_INT) 1 << (floor_log2 (mode_width))) - 1;
  3761. break;
  3762. case PARITY:
  3763. nonzero = 1;
  3764. break;
  3765. case IF_THEN_ELSE:
  3766. {
  3767. unsigned HOST_WIDE_INT nonzero_true
  3768. = cached_nonzero_bits (XEXP (x, 1), mode,
  3769. known_x, known_mode, known_ret);
  3770. /* Don't call nonzero_bits for the second time if it cannot change
  3771. anything. */
  3772. if ((nonzero & nonzero_true) != nonzero)
  3773. nonzero &= nonzero_true
  3774. | cached_nonzero_bits (XEXP (x, 2), mode,
  3775. known_x, known_mode, known_ret);
  3776. }
  3777. break;
  3778. default:
  3779. break;
  3780. }
  3781. return nonzero;
  3782. }
  3783. /* See the macro definition above. */
  3784. #undef cached_num_sign_bit_copies
  3785. /* The function cached_num_sign_bit_copies is a wrapper around
  3786. num_sign_bit_copies1. It avoids exponential behavior in
  3787. num_sign_bit_copies1 when X has identical subexpressions on the
  3788. first or the second level. */
  3789. static unsigned int
  3790. cached_num_sign_bit_copies (const_rtx x, machine_mode mode, const_rtx known_x,
  3791. machine_mode known_mode,
  3792. unsigned int known_ret)
  3793. {
  3794. if (x == known_x && mode == known_mode)
  3795. return known_ret;
  3796. /* Try to find identical subexpressions. If found call
  3797. num_sign_bit_copies1 on X with the subexpressions as KNOWN_X and
  3798. the precomputed value for the subexpression as KNOWN_RET. */
  3799. if (ARITHMETIC_P (x))
  3800. {
  3801. rtx x0 = XEXP (x, 0);
  3802. rtx x1 = XEXP (x, 1);
  3803. /* Check the first level. */
  3804. if (x0 == x1)
  3805. return
  3806. num_sign_bit_copies1 (x, mode, x0, mode,
  3807. cached_num_sign_bit_copies (x0, mode, known_x,
  3808. known_mode,
  3809. known_ret));
  3810. /* Check the second level. */
  3811. if (ARITHMETIC_P (x0)
  3812. && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1)))
  3813. return
  3814. num_sign_bit_copies1 (x, mode, x1, mode,
  3815. cached_num_sign_bit_copies (x1, mode, known_x,
  3816. known_mode,
  3817. known_ret));
  3818. if (ARITHMETIC_P (x1)
  3819. && (x0 == XEXP (x1, 0) || x0 == XEXP (x1, 1)))
  3820. return
  3821. num_sign_bit_copies1 (x, mode, x0, mode,
  3822. cached_num_sign_bit_copies (x0, mode, known_x,
  3823. known_mode,
  3824. known_ret));
  3825. }
  3826. return num_sign_bit_copies1 (x, mode, known_x, known_mode, known_ret);
  3827. }
  3828. /* Return the number of bits at the high-order end of X that are known to
  3829. be equal to the sign bit. X will be used in mode MODE; if MODE is
  3830. VOIDmode, X will be used in its own mode. The returned value will always
  3831. be between 1 and the number of bits in MODE. */
  3832. static unsigned int
  3833. num_sign_bit_copies1 (const_rtx x, machine_mode mode, const_rtx known_x,
  3834. machine_mode known_mode,
  3835. unsigned int known_ret)
  3836. {
  3837. enum rtx_code code = GET_CODE (x);
  3838. unsigned int bitwidth = GET_MODE_PRECISION (mode);
  3839. int num0, num1, result;
  3840. unsigned HOST_WIDE_INT nonzero;
  3841. /* If we weren't given a mode, use the mode of X. If the mode is still
  3842. VOIDmode, we don't know anything. Likewise if one of the modes is
  3843. floating-point. */
  3844. if (mode == VOIDmode)
  3845. mode = GET_MODE (x);
  3846. if (mode == VOIDmode || FLOAT_MODE_P (mode) || FLOAT_MODE_P (GET_MODE (x))
  3847. || VECTOR_MODE_P (GET_MODE (x)) || VECTOR_MODE_P (mode))
  3848. return 1;
  3849. /* For a smaller object, just ignore the high bits. */
  3850. if (bitwidth < GET_MODE_PRECISION (GET_MODE (x)))
  3851. {
  3852. num0 = cached_num_sign_bit_copies (x, GET_MODE (x),
  3853. known_x, known_mode, known_ret);
  3854. return MAX (1,
  3855. num0 - (int) (GET_MODE_PRECISION (GET_MODE (x)) - bitwidth));
  3856. }
  3857. if (GET_MODE (x) != VOIDmode && bitwidth > GET_MODE_PRECISION (GET_MODE (x)))
  3858. {
  3859. #ifndef WORD_REGISTER_OPERATIONS
  3860. /* If this machine does not do all register operations on the entire
  3861. register and MODE is wider than the mode of X, we can say nothing
  3862. at all about the high-order bits. */
  3863. return 1;
  3864. #else
  3865. /* Likewise on machines that do, if the mode of the object is smaller
  3866. than a word and loads of that size don't sign extend, we can say
  3867. nothing about the high order bits. */
  3868. if (GET_MODE_PRECISION (GET_MODE (x)) < BITS_PER_WORD
  3869. #ifdef LOAD_EXTEND_OP
  3870. && LOAD_EXTEND_OP (GET_MODE (x)) != SIGN_EXTEND
  3871. #endif
  3872. )
  3873. return 1;
  3874. #endif
  3875. }
  3876. switch (code)
  3877. {
  3878. case REG:
  3879. #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
  3880. /* If pointers extend signed and this is a pointer in Pmode, say that
  3881. all the bits above ptr_mode are known to be sign bit copies. */
  3882. /* As we do not know which address space the pointer is referring to,
  3883. we can do this only if the target does not support different pointer
  3884. or address modes depending on the address space. */
  3885. if (target_default_pointer_address_modes_p ()
  3886. && ! POINTERS_EXTEND_UNSIGNED && GET_MODE (x) == Pmode
  3887. && mode == Pmode && REG_POINTER (x))
  3888. return GET_MODE_PRECISION (Pmode) - GET_MODE_PRECISION (ptr_mode) + 1;
  3889. #endif
  3890. {
  3891. unsigned int copies_for_hook = 1, copies = 1;
  3892. rtx new_rtx = rtl_hooks.reg_num_sign_bit_copies (x, mode, known_x,
  3893. known_mode, known_ret,
  3894. &copies_for_hook);
  3895. if (new_rtx)
  3896. copies = cached_num_sign_bit_copies (new_rtx, mode, known_x,
  3897. known_mode, known_ret);
  3898. if (copies > 1 || copies_for_hook > 1)
  3899. return MAX (copies, copies_for_hook);
  3900. /* Else, use nonzero_bits to guess num_sign_bit_copies (see below). */
  3901. }
  3902. break;
  3903. case MEM:
  3904. #ifdef LOAD_EXTEND_OP
  3905. /* Some RISC machines sign-extend all loads of smaller than a word. */
  3906. if (LOAD_EXTEND_OP (GET_MODE (x)) == SIGN_EXTEND)
  3907. return MAX (1, ((int) bitwidth
  3908. - (int) GET_MODE_PRECISION (GET_MODE (x)) + 1));
  3909. #endif
  3910. break;
  3911. case CONST_INT:
  3912. /* If the constant is negative, take its 1's complement and remask.
  3913. Then see how many zero bits we have. */
  3914. nonzero = UINTVAL (x) & GET_MODE_MASK (mode);
  3915. if (bitwidth <= HOST_BITS_PER_WIDE_INT
  3916. && (nonzero & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  3917. nonzero = (~nonzero) & GET_MODE_MASK (mode);
  3918. return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1);
  3919. case SUBREG:
  3920. /* If this is a SUBREG for a promoted object that is sign-extended
  3921. and we are looking at it in a wider mode, we know that at least the
  3922. high-order bits are known to be sign bit copies. */
  3923. if (SUBREG_PROMOTED_VAR_P (x) && SUBREG_PROMOTED_SIGNED_P (x))
  3924. {
  3925. num0 = cached_num_sign_bit_copies (SUBREG_REG (x), mode,
  3926. known_x, known_mode, known_ret);
  3927. return MAX ((int) bitwidth
  3928. - (int) GET_MODE_PRECISION (GET_MODE (x)) + 1,
  3929. num0);
  3930. }
  3931. /* For a smaller object, just ignore the high bits. */
  3932. if (bitwidth <= GET_MODE_PRECISION (GET_MODE (SUBREG_REG (x))))
  3933. {
  3934. num0 = cached_num_sign_bit_copies (SUBREG_REG (x), VOIDmode,
  3935. known_x, known_mode, known_ret);
  3936. return MAX (1, (num0
  3937. - (int) (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (x)))
  3938. - bitwidth)));
  3939. }
  3940. #ifdef WORD_REGISTER_OPERATIONS
  3941. #ifdef LOAD_EXTEND_OP
  3942. /* For paradoxical SUBREGs on machines where all register operations
  3943. affect the entire register, just look inside. Note that we are
  3944. passing MODE to the recursive call, so the number of sign bit copies
  3945. will remain relative to that mode, not the inner mode. */
  3946. /* This works only if loads sign extend. Otherwise, if we get a
  3947. reload for the inner part, it may be loaded from the stack, and
  3948. then we lose all sign bit copies that existed before the store
  3949. to the stack. */
  3950. if (paradoxical_subreg_p (x)
  3951. && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (x))) == SIGN_EXTEND
  3952. && MEM_P (SUBREG_REG (x)))
  3953. return cached_num_sign_bit_copies (SUBREG_REG (x), mode,
  3954. known_x, known_mode, known_ret);
  3955. #endif
  3956. #endif
  3957. break;
  3958. case SIGN_EXTRACT:
  3959. if (CONST_INT_P (XEXP (x, 1)))
  3960. return MAX (1, (int) bitwidth - INTVAL (XEXP (x, 1)));
  3961. break;
  3962. case SIGN_EXTEND:
  3963. return (bitwidth - GET_MODE_PRECISION (GET_MODE (XEXP (x, 0)))
  3964. + cached_num_sign_bit_copies (XEXP (x, 0), VOIDmode,
  3965. known_x, known_mode, known_ret));
  3966. case TRUNCATE:
  3967. /* For a smaller object, just ignore the high bits. */
  3968. num0 = cached_num_sign_bit_copies (XEXP (x, 0), VOIDmode,
  3969. known_x, known_mode, known_ret);
  3970. return MAX (1, (num0 - (int) (GET_MODE_PRECISION (GET_MODE (XEXP (x, 0)))
  3971. - bitwidth)));
  3972. case NOT:
  3973. return cached_num_sign_bit_copies (XEXP (x, 0), mode,
  3974. known_x, known_mode, known_ret);
  3975. case ROTATE: case ROTATERT:
  3976. /* If we are rotating left by a number of bits less than the number
  3977. of sign bit copies, we can just subtract that amount from the
  3978. number. */
  3979. if (CONST_INT_P (XEXP (x, 1))
  3980. && INTVAL (XEXP (x, 1)) >= 0
  3981. && INTVAL (XEXP (x, 1)) < (int) bitwidth)
  3982. {
  3983. num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  3984. known_x, known_mode, known_ret);
  3985. return MAX (1, num0 - (code == ROTATE ? INTVAL (XEXP (x, 1))
  3986. : (int) bitwidth - INTVAL (XEXP (x, 1))));
  3987. }
  3988. break;
  3989. case NEG:
  3990. /* In general, this subtracts one sign bit copy. But if the value
  3991. is known to be positive, the number of sign bit copies is the
  3992. same as that of the input. Finally, if the input has just one bit
  3993. that might be nonzero, all the bits are copies of the sign bit. */
  3994. num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  3995. known_x, known_mode, known_ret);
  3996. if (bitwidth > HOST_BITS_PER_WIDE_INT)
  3997. return num0 > 1 ? num0 - 1 : 1;
  3998. nonzero = nonzero_bits (XEXP (x, 0), mode);
  3999. if (nonzero == 1)
  4000. return bitwidth;
  4001. if (num0 > 1
  4002. && (((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero))
  4003. num0--;
  4004. return num0;
  4005. case IOR: case AND: case XOR:
  4006. case SMIN: case SMAX: case UMIN: case UMAX:
  4007. /* Logical operations will preserve the number of sign-bit copies.
  4008. MIN and MAX operations always return one of the operands. */
  4009. num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  4010. known_x, known_mode, known_ret);
  4011. num1 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
  4012. known_x, known_mode, known_ret);
  4013. /* If num1 is clearing some of the top bits then regardless of
  4014. the other term, we are guaranteed to have at least that many
  4015. high-order zero bits. */
  4016. if (code == AND
  4017. && num1 > 1
  4018. && bitwidth <= HOST_BITS_PER_WIDE_INT
  4019. && CONST_INT_P (XEXP (x, 1))
  4020. && (UINTVAL (XEXP (x, 1))
  4021. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) == 0)
  4022. return num1;
  4023. /* Similarly for IOR when setting high-order bits. */
  4024. if (code == IOR
  4025. && num1 > 1
  4026. && bitwidth <= HOST_BITS_PER_WIDE_INT
  4027. && CONST_INT_P (XEXP (x, 1))
  4028. && (UINTVAL (XEXP (x, 1))
  4029. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  4030. return num1;
  4031. return MIN (num0, num1);
  4032. case PLUS: case MINUS:
  4033. /* For addition and subtraction, we can have a 1-bit carry. However,
  4034. if we are subtracting 1 from a positive number, there will not
  4035. be such a carry. Furthermore, if the positive number is known to
  4036. be 0 or 1, we know the result is either -1 or 0. */
  4037. if (code == PLUS && XEXP (x, 1) == constm1_rtx
  4038. && bitwidth <= HOST_BITS_PER_WIDE_INT)
  4039. {
  4040. nonzero = nonzero_bits (XEXP (x, 0), mode);
  4041. if ((((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1)) & nonzero) == 0)
  4042. return (nonzero == 1 || nonzero == 0 ? bitwidth
  4043. : bitwidth - floor_log2 (nonzero) - 1);
  4044. }
  4045. num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  4046. known_x, known_mode, known_ret);
  4047. num1 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
  4048. known_x, known_mode, known_ret);
  4049. result = MAX (1, MIN (num0, num1) - 1);
  4050. return result;
  4051. case MULT:
  4052. /* The number of bits of the product is the sum of the number of
  4053. bits of both terms. However, unless one of the terms if known
  4054. to be positive, we must allow for an additional bit since negating
  4055. a negative number can remove one sign bit copy. */
  4056. num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  4057. known_x, known_mode, known_ret);
  4058. num1 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
  4059. known_x, known_mode, known_ret);
  4060. result = bitwidth - (bitwidth - num0) - (bitwidth - num1);
  4061. if (result > 0
  4062. && (bitwidth > HOST_BITS_PER_WIDE_INT
  4063. || (((nonzero_bits (XEXP (x, 0), mode)
  4064. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  4065. && ((nonzero_bits (XEXP (x, 1), mode)
  4066. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1)))
  4067. != 0))))
  4068. result--;
  4069. return MAX (1, result);
  4070. case UDIV:
  4071. /* The result must be <= the first operand. If the first operand
  4072. has the high bit set, we know nothing about the number of sign
  4073. bit copies. */
  4074. if (bitwidth > HOST_BITS_PER_WIDE_INT)
  4075. return 1;
  4076. else if ((nonzero_bits (XEXP (x, 0), mode)
  4077. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  4078. return 1;
  4079. else
  4080. return cached_num_sign_bit_copies (XEXP (x, 0), mode,
  4081. known_x, known_mode, known_ret);
  4082. case UMOD:
  4083. /* The result must be <= the second operand. If the second operand
  4084. has (or just might have) the high bit set, we know nothing about
  4085. the number of sign bit copies. */
  4086. if (bitwidth > HOST_BITS_PER_WIDE_INT)
  4087. return 1;
  4088. else if ((nonzero_bits (XEXP (x, 1), mode)
  4089. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  4090. return 1;
  4091. else
  4092. return cached_num_sign_bit_copies (XEXP (x, 1), mode,
  4093. known_x, known_mode, known_ret);
  4094. case DIV:
  4095. /* Similar to unsigned division, except that we have to worry about
  4096. the case where the divisor is negative, in which case we have
  4097. to add 1. */
  4098. result = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  4099. known_x, known_mode, known_ret);
  4100. if (result > 1
  4101. && (bitwidth > HOST_BITS_PER_WIDE_INT
  4102. || (nonzero_bits (XEXP (x, 1), mode)
  4103. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0))
  4104. result--;
  4105. return result;
  4106. case MOD:
  4107. result = cached_num_sign_bit_copies (XEXP (x, 1), mode,
  4108. known_x, known_mode, known_ret);
  4109. if (result > 1
  4110. && (bitwidth > HOST_BITS_PER_WIDE_INT
  4111. || (nonzero_bits (XEXP (x, 1), mode)
  4112. & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0))
  4113. result--;
  4114. return result;
  4115. case ASHIFTRT:
  4116. /* Shifts by a constant add to the number of bits equal to the
  4117. sign bit. */
  4118. num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  4119. known_x, known_mode, known_ret);
  4120. if (CONST_INT_P (XEXP (x, 1))
  4121. && INTVAL (XEXP (x, 1)) > 0
  4122. && INTVAL (XEXP (x, 1)) < GET_MODE_PRECISION (GET_MODE (x)))
  4123. num0 = MIN ((int) bitwidth, num0 + INTVAL (XEXP (x, 1)));
  4124. return num0;
  4125. case ASHIFT:
  4126. /* Left shifts destroy copies. */
  4127. if (!CONST_INT_P (XEXP (x, 1))
  4128. || INTVAL (XEXP (x, 1)) < 0
  4129. || INTVAL (XEXP (x, 1)) >= (int) bitwidth
  4130. || INTVAL (XEXP (x, 1)) >= GET_MODE_PRECISION (GET_MODE (x)))
  4131. return 1;
  4132. num0 = cached_num_sign_bit_copies (XEXP (x, 0), mode,
  4133. known_x, known_mode, known_ret);
  4134. return MAX (1, num0 - INTVAL (XEXP (x, 1)));
  4135. case IF_THEN_ELSE:
  4136. num0 = cached_num_sign_bit_copies (XEXP (x, 1), mode,
  4137. known_x, known_mode, known_ret);
  4138. num1 = cached_num_sign_bit_copies (XEXP (x, 2), mode,
  4139. known_x, known_mode, known_ret);
  4140. return MIN (num0, num1);
  4141. case EQ: case NE: case GE: case GT: case LE: case LT:
  4142. case UNEQ: case LTGT: case UNGE: case UNGT: case UNLE: case UNLT:
  4143. case GEU: case GTU: case LEU: case LTU:
  4144. case UNORDERED: case ORDERED:
  4145. /* If the constant is negative, take its 1's complement and remask.
  4146. Then see how many zero bits we have. */
  4147. nonzero = STORE_FLAG_VALUE;
  4148. if (bitwidth <= HOST_BITS_PER_WIDE_INT
  4149. && (nonzero & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))) != 0)
  4150. nonzero = (~nonzero) & GET_MODE_MASK (mode);
  4151. return (nonzero == 0 ? bitwidth : bitwidth - floor_log2 (nonzero) - 1);
  4152. default:
  4153. break;
  4154. }
  4155. /* If we haven't been able to figure it out by one of the above rules,
  4156. see if some of the high-order bits are known to be zero. If so,
  4157. count those bits and return one less than that amount. If we can't
  4158. safely compute the mask for this mode, always return BITWIDTH. */
  4159. bitwidth = GET_MODE_PRECISION (mode);
  4160. if (bitwidth > HOST_BITS_PER_WIDE_INT)
  4161. return 1;
  4162. nonzero = nonzero_bits (x, mode);
  4163. return nonzero & ((unsigned HOST_WIDE_INT) 1 << (bitwidth - 1))
  4164. ? 1 : bitwidth - floor_log2 (nonzero) - 1;
  4165. }
  4166. /* Calculate the rtx_cost of a single instruction. A return value of
  4167. zero indicates an instruction pattern without a known cost. */
  4168. int
  4169. insn_rtx_cost (rtx pat, bool speed)
  4170. {
  4171. int i, cost;
  4172. rtx set;
  4173. /* Extract the single set rtx from the instruction pattern.
  4174. We can't use single_set since we only have the pattern. */
  4175. if (GET_CODE (pat) == SET)
  4176. set = pat;
  4177. else if (GET_CODE (pat) == PARALLEL)
  4178. {
  4179. set = NULL_RTX;
  4180. for (i = 0; i < XVECLEN (pat, 0); i++)
  4181. {
  4182. rtx x = XVECEXP (pat, 0, i);
  4183. if (GET_CODE (x) == SET)
  4184. {
  4185. if (set)
  4186. return 0;
  4187. set = x;
  4188. }
  4189. }
  4190. if (!set)
  4191. return 0;
  4192. }
  4193. else
  4194. return 0;
  4195. cost = set_src_cost (SET_SRC (set), speed);
  4196. return cost > 0 ? cost : COSTS_N_INSNS (1);
  4197. }
  4198. /* Returns estimate on cost of computing SEQ. */
  4199. unsigned
  4200. seq_cost (const rtx_insn *seq, bool speed)
  4201. {
  4202. unsigned cost = 0;
  4203. rtx set;
  4204. for (; seq; seq = NEXT_INSN (seq))
  4205. {
  4206. set = single_set (seq);
  4207. if (set)
  4208. cost += set_rtx_cost (set, speed);
  4209. else
  4210. cost++;
  4211. }
  4212. return cost;
  4213. }
  4214. /* Given an insn INSN and condition COND, return the condition in a
  4215. canonical form to simplify testing by callers. Specifically:
  4216. (1) The code will always be a comparison operation (EQ, NE, GT, etc.).
  4217. (2) Both operands will be machine operands; (cc0) will have been replaced.
  4218. (3) If an operand is a constant, it will be the second operand.
  4219. (4) (LE x const) will be replaced with (LT x <const+1>) and similarly
  4220. for GE, GEU, and LEU.
  4221. If the condition cannot be understood, or is an inequality floating-point
  4222. comparison which needs to be reversed, 0 will be returned.
  4223. If REVERSE is nonzero, then reverse the condition prior to canonizing it.
  4224. If EARLIEST is nonzero, it is a pointer to a place where the earliest
  4225. insn used in locating the condition was found. If a replacement test
  4226. of the condition is desired, it should be placed in front of that
  4227. insn and we will be sure that the inputs are still valid.
  4228. If WANT_REG is nonzero, we wish the condition to be relative to that
  4229. register, if possible. Therefore, do not canonicalize the condition
  4230. further. If ALLOW_CC_MODE is nonzero, allow the condition returned
  4231. to be a compare to a CC mode register.
  4232. If VALID_AT_INSN_P, the condition must be valid at both *EARLIEST
  4233. and at INSN. */
  4234. rtx
  4235. canonicalize_condition (rtx_insn *insn, rtx cond, int reverse,
  4236. rtx_insn **earliest,
  4237. rtx want_reg, int allow_cc_mode, int valid_at_insn_p)
  4238. {
  4239. enum rtx_code code;
  4240. rtx_insn *prev = insn;
  4241. const_rtx set;
  4242. rtx tem;
  4243. rtx op0, op1;
  4244. int reverse_code = 0;
  4245. machine_mode mode;
  4246. basic_block bb = BLOCK_FOR_INSN (insn);
  4247. code = GET_CODE (cond);
  4248. mode = GET_MODE (cond);
  4249. op0 = XEXP (cond, 0);
  4250. op1 = XEXP (cond, 1);
  4251. if (reverse)
  4252. code = reversed_comparison_code (cond, insn);
  4253. if (code == UNKNOWN)
  4254. return 0;
  4255. if (earliest)
  4256. *earliest = insn;
  4257. /* If we are comparing a register with zero, see if the register is set
  4258. in the previous insn to a COMPARE or a comparison operation. Perform
  4259. the same tests as a function of STORE_FLAG_VALUE as find_comparison_args
  4260. in cse.c */
  4261. while ((GET_RTX_CLASS (code) == RTX_COMPARE
  4262. || GET_RTX_CLASS (code) == RTX_COMM_COMPARE)
  4263. && op1 == CONST0_RTX (GET_MODE (op0))
  4264. && op0 != want_reg)
  4265. {
  4266. /* Set nonzero when we find something of interest. */
  4267. rtx x = 0;
  4268. #ifdef HAVE_cc0
  4269. /* If comparison with cc0, import actual comparison from compare
  4270. insn. */
  4271. if (op0 == cc0_rtx)
  4272. {
  4273. if ((prev = prev_nonnote_insn (prev)) == 0
  4274. || !NONJUMP_INSN_P (prev)
  4275. || (set = single_set (prev)) == 0
  4276. || SET_DEST (set) != cc0_rtx)
  4277. return 0;
  4278. op0 = SET_SRC (set);
  4279. op1 = CONST0_RTX (GET_MODE (op0));
  4280. if (earliest)
  4281. *earliest = prev;
  4282. }
  4283. #endif
  4284. /* If this is a COMPARE, pick up the two things being compared. */
  4285. if (GET_CODE (op0) == COMPARE)
  4286. {
  4287. op1 = XEXP (op0, 1);
  4288. op0 = XEXP (op0, 0);
  4289. continue;
  4290. }
  4291. else if (!REG_P (op0))
  4292. break;
  4293. /* Go back to the previous insn. Stop if it is not an INSN. We also
  4294. stop if it isn't a single set or if it has a REG_INC note because
  4295. we don't want to bother dealing with it. */
  4296. prev = prev_nonnote_nondebug_insn (prev);
  4297. if (prev == 0
  4298. || !NONJUMP_INSN_P (prev)
  4299. || FIND_REG_INC_NOTE (prev, NULL_RTX)
  4300. /* In cfglayout mode, there do not have to be labels at the
  4301. beginning of a block, or jumps at the end, so the previous
  4302. conditions would not stop us when we reach bb boundary. */
  4303. || BLOCK_FOR_INSN (prev) != bb)
  4304. break;
  4305. set = set_of (op0, prev);
  4306. if (set
  4307. && (GET_CODE (set) != SET
  4308. || !rtx_equal_p (SET_DEST (set), op0)))
  4309. break;
  4310. /* If this is setting OP0, get what it sets it to if it looks
  4311. relevant. */
  4312. if (set)
  4313. {
  4314. machine_mode inner_mode = GET_MODE (SET_DEST (set));
  4315. #ifdef FLOAT_STORE_FLAG_VALUE
  4316. REAL_VALUE_TYPE fsfv;
  4317. #endif
  4318. /* ??? We may not combine comparisons done in a CCmode with
  4319. comparisons not done in a CCmode. This is to aid targets
  4320. like Alpha that have an IEEE compliant EQ instruction, and
  4321. a non-IEEE compliant BEQ instruction. The use of CCmode is
  4322. actually artificial, simply to prevent the combination, but
  4323. should not affect other platforms.
  4324. However, we must allow VOIDmode comparisons to match either
  4325. CCmode or non-CCmode comparison, because some ports have
  4326. modeless comparisons inside branch patterns.
  4327. ??? This mode check should perhaps look more like the mode check
  4328. in simplify_comparison in combine. */
  4329. if (((GET_MODE_CLASS (mode) == MODE_CC)
  4330. != (GET_MODE_CLASS (inner_mode) == MODE_CC))
  4331. && mode != VOIDmode
  4332. && inner_mode != VOIDmode)
  4333. break;
  4334. if (GET_CODE (SET_SRC (set)) == COMPARE
  4335. || (((code == NE
  4336. || (code == LT
  4337. && val_signbit_known_set_p (inner_mode,
  4338. STORE_FLAG_VALUE))
  4339. #ifdef FLOAT_STORE_FLAG_VALUE
  4340. || (code == LT
  4341. && SCALAR_FLOAT_MODE_P (inner_mode)
  4342. && (fsfv = FLOAT_STORE_FLAG_VALUE (inner_mode),
  4343. REAL_VALUE_NEGATIVE (fsfv)))
  4344. #endif
  4345. ))
  4346. && COMPARISON_P (SET_SRC (set))))
  4347. x = SET_SRC (set);
  4348. else if (((code == EQ
  4349. || (code == GE
  4350. && val_signbit_known_set_p (inner_mode,
  4351. STORE_FLAG_VALUE))
  4352. #ifdef FLOAT_STORE_FLAG_VALUE
  4353. || (code == GE
  4354. && SCALAR_FLOAT_MODE_P (inner_mode)
  4355. && (fsfv = FLOAT_STORE_FLAG_VALUE (inner_mode),
  4356. REAL_VALUE_NEGATIVE (fsfv)))
  4357. #endif
  4358. ))
  4359. && COMPARISON_P (SET_SRC (set)))
  4360. {
  4361. reverse_code = 1;
  4362. x = SET_SRC (set);
  4363. }
  4364. else if ((code == EQ || code == NE)
  4365. && GET_CODE (SET_SRC (set)) == XOR)
  4366. /* Handle sequences like:
  4367. (set op0 (xor X Y))
  4368. ...(eq|ne op0 (const_int 0))...
  4369. in which case:
  4370. (eq op0 (const_int 0)) reduces to (eq X Y)
  4371. (ne op0 (const_int 0)) reduces to (ne X Y)
  4372. This is the form used by MIPS16, for example. */
  4373. x = SET_SRC (set);
  4374. else
  4375. break;
  4376. }
  4377. else if (reg_set_p (op0, prev))
  4378. /* If this sets OP0, but not directly, we have to give up. */
  4379. break;
  4380. if (x)
  4381. {
  4382. /* If the caller is expecting the condition to be valid at INSN,
  4383. make sure X doesn't change before INSN. */
  4384. if (valid_at_insn_p)
  4385. if (modified_in_p (x, prev) || modified_between_p (x, prev, insn))
  4386. break;
  4387. if (COMPARISON_P (x))
  4388. code = GET_CODE (x);
  4389. if (reverse_code)
  4390. {
  4391. code = reversed_comparison_code (x, prev);
  4392. if (code == UNKNOWN)
  4393. return 0;
  4394. reverse_code = 0;
  4395. }
  4396. op0 = XEXP (x, 0), op1 = XEXP (x, 1);
  4397. if (earliest)
  4398. *earliest = prev;
  4399. }
  4400. }
  4401. /* If constant is first, put it last. */
  4402. if (CONSTANT_P (op0))
  4403. code = swap_condition (code), tem = op0, op0 = op1, op1 = tem;
  4404. /* If OP0 is the result of a comparison, we weren't able to find what
  4405. was really being compared, so fail. */
  4406. if (!allow_cc_mode
  4407. && GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
  4408. return 0;
  4409. /* Canonicalize any ordered comparison with integers involving equality
  4410. if we can do computations in the relevant mode and we do not
  4411. overflow. */
  4412. if (GET_MODE_CLASS (GET_MODE (op0)) != MODE_CC
  4413. && CONST_INT_P (op1)
  4414. && GET_MODE (op0) != VOIDmode
  4415. && GET_MODE_PRECISION (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
  4416. {
  4417. HOST_WIDE_INT const_val = INTVAL (op1);
  4418. unsigned HOST_WIDE_INT uconst_val = const_val;
  4419. unsigned HOST_WIDE_INT max_val
  4420. = (unsigned HOST_WIDE_INT) GET_MODE_MASK (GET_MODE (op0));
  4421. switch (code)
  4422. {
  4423. case LE:
  4424. if ((unsigned HOST_WIDE_INT) const_val != max_val >> 1)
  4425. code = LT, op1 = gen_int_mode (const_val + 1, GET_MODE (op0));
  4426. break;
  4427. /* When cross-compiling, const_val might be sign-extended from
  4428. BITS_PER_WORD to HOST_BITS_PER_WIDE_INT */
  4429. case GE:
  4430. if ((const_val & max_val)
  4431. != ((unsigned HOST_WIDE_INT) 1
  4432. << (GET_MODE_PRECISION (GET_MODE (op0)) - 1)))
  4433. code = GT, op1 = gen_int_mode (const_val - 1, GET_MODE (op0));
  4434. break;
  4435. case LEU:
  4436. if (uconst_val < max_val)
  4437. code = LTU, op1 = gen_int_mode (uconst_val + 1, GET_MODE (op0));
  4438. break;
  4439. case GEU:
  4440. if (uconst_val != 0)
  4441. code = GTU, op1 = gen_int_mode (uconst_val - 1, GET_MODE (op0));
  4442. break;
  4443. default:
  4444. break;
  4445. }
  4446. }
  4447. /* Never return CC0; return zero instead. */
  4448. if (CC0_P (op0))
  4449. return 0;
  4450. return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
  4451. }
  4452. /* Given a jump insn JUMP, return the condition that will cause it to branch
  4453. to its JUMP_LABEL. If the condition cannot be understood, or is an
  4454. inequality floating-point comparison which needs to be reversed, 0 will
  4455. be returned.
  4456. If EARLIEST is nonzero, it is a pointer to a place where the earliest
  4457. insn used in locating the condition was found. If a replacement test
  4458. of the condition is desired, it should be placed in front of that
  4459. insn and we will be sure that the inputs are still valid. If EARLIEST
  4460. is null, the returned condition will be valid at INSN.
  4461. If ALLOW_CC_MODE is nonzero, allow the condition returned to be a
  4462. compare CC mode register.
  4463. VALID_AT_INSN_P is the same as for canonicalize_condition. */
  4464. rtx
  4465. get_condition (rtx_insn *jump, rtx_insn **earliest, int allow_cc_mode,
  4466. int valid_at_insn_p)
  4467. {
  4468. rtx cond;
  4469. int reverse;
  4470. rtx set;
  4471. /* If this is not a standard conditional jump, we can't parse it. */
  4472. if (!JUMP_P (jump)
  4473. || ! any_condjump_p (jump))
  4474. return 0;
  4475. set = pc_set (jump);
  4476. cond = XEXP (SET_SRC (set), 0);
  4477. /* If this branches to JUMP_LABEL when the condition is false, reverse
  4478. the condition. */
  4479. reverse
  4480. = GET_CODE (XEXP (SET_SRC (set), 2)) == LABEL_REF
  4481. && LABEL_REF_LABEL (XEXP (SET_SRC (set), 2)) == JUMP_LABEL (jump);
  4482. return canonicalize_condition (jump, cond, reverse, earliest, NULL_RTX,
  4483. allow_cc_mode, valid_at_insn_p);
  4484. }
  4485. /* Initialize the table NUM_SIGN_BIT_COPIES_IN_REP based on
  4486. TARGET_MODE_REP_EXTENDED.
  4487. Note that we assume that the property of
  4488. TARGET_MODE_REP_EXTENDED(B, C) is sticky to the integral modes
  4489. narrower than mode B. I.e., if A is a mode narrower than B then in
  4490. order to be able to operate on it in mode B, mode A needs to
  4491. satisfy the requirements set by the representation of mode B. */
  4492. static void
  4493. init_num_sign_bit_copies_in_rep (void)
  4494. {
  4495. machine_mode mode, in_mode;
  4496. for (in_mode = GET_CLASS_NARROWEST_MODE (MODE_INT); in_mode != VOIDmode;
  4497. in_mode = GET_MODE_WIDER_MODE (mode))
  4498. for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != in_mode;
  4499. mode = GET_MODE_WIDER_MODE (mode))
  4500. {
  4501. machine_mode i;
  4502. /* Currently, it is assumed that TARGET_MODE_REP_EXTENDED
  4503. extends to the next widest mode. */
  4504. gcc_assert (targetm.mode_rep_extended (mode, in_mode) == UNKNOWN
  4505. || GET_MODE_WIDER_MODE (mode) == in_mode);
  4506. /* We are in in_mode. Count how many bits outside of mode
  4507. have to be copies of the sign-bit. */
  4508. for (i = mode; i != in_mode; i = GET_MODE_WIDER_MODE (i))
  4509. {
  4510. machine_mode wider = GET_MODE_WIDER_MODE (i);
  4511. if (targetm.mode_rep_extended (i, wider) == SIGN_EXTEND
  4512. /* We can only check sign-bit copies starting from the
  4513. top-bit. In order to be able to check the bits we
  4514. have already seen we pretend that subsequent bits
  4515. have to be sign-bit copies too. */
  4516. || num_sign_bit_copies_in_rep [in_mode][mode])
  4517. num_sign_bit_copies_in_rep [in_mode][mode]
  4518. += GET_MODE_PRECISION (wider) - GET_MODE_PRECISION (i);
  4519. }
  4520. }
  4521. }
  4522. /* Suppose that truncation from the machine mode of X to MODE is not a
  4523. no-op. See if there is anything special about X so that we can
  4524. assume it already contains a truncated value of MODE. */
  4525. bool
  4526. truncated_to_mode (machine_mode mode, const_rtx x)
  4527. {
  4528. /* This register has already been used in MODE without explicit
  4529. truncation. */
  4530. if (REG_P (x) && rtl_hooks.reg_truncated_to_mode (mode, x))
  4531. return true;
  4532. /* See if we already satisfy the requirements of MODE. If yes we
  4533. can just switch to MODE. */
  4534. if (num_sign_bit_copies_in_rep[GET_MODE (x)][mode]
  4535. && (num_sign_bit_copies (x, GET_MODE (x))
  4536. >= num_sign_bit_copies_in_rep[GET_MODE (x)][mode] + 1))
  4537. return true;
  4538. return false;
  4539. }
  4540. /* Return true if RTX code CODE has a single sequence of zero or more
  4541. "e" operands and no rtvec operands. Initialize its rtx_all_subrtx_bounds
  4542. entry in that case. */
  4543. static bool
  4544. setup_reg_subrtx_bounds (unsigned int code)
  4545. {
  4546. const char *format = GET_RTX_FORMAT ((enum rtx_code) code);
  4547. unsigned int i = 0;
  4548. for (; format[i] != 'e'; ++i)
  4549. {
  4550. if (!format[i])
  4551. /* No subrtxes. Leave start and count as 0. */
  4552. return true;
  4553. if (format[i] == 'E' || format[i] == 'V')
  4554. return false;
  4555. }
  4556. /* Record the sequence of 'e's. */
  4557. rtx_all_subrtx_bounds[code].start = i;
  4558. do
  4559. ++i;
  4560. while (format[i] == 'e');
  4561. rtx_all_subrtx_bounds[code].count = i - rtx_all_subrtx_bounds[code].start;
  4562. /* rtl-iter.h relies on this. */
  4563. gcc_checking_assert (rtx_all_subrtx_bounds[code].count <= 3);
  4564. for (; format[i]; ++i)
  4565. if (format[i] == 'E' || format[i] == 'V' || format[i] == 'e')
  4566. return false;
  4567. return true;
  4568. }
  4569. /* Initialize rtx_all_subrtx_bounds. */
  4570. void
  4571. init_rtlanal (void)
  4572. {
  4573. int i;
  4574. for (i = 0; i < NUM_RTX_CODE; i++)
  4575. {
  4576. if (!setup_reg_subrtx_bounds (i))
  4577. rtx_all_subrtx_bounds[i].count = UCHAR_MAX;
  4578. if (GET_RTX_CLASS (i) != RTX_CONST_OBJ)
  4579. rtx_nonconst_subrtx_bounds[i] = rtx_all_subrtx_bounds[i];
  4580. }
  4581. init_num_sign_bit_copies_in_rep ();
  4582. }
  4583. /* Check whether this is a constant pool constant. */
  4584. bool
  4585. constant_pool_constant_p (rtx x)
  4586. {
  4587. x = avoid_constant_pool_reference (x);
  4588. return CONST_DOUBLE_P (x);
  4589. }
  4590. /* If M is a bitmask that selects a field of low-order bits within an item but
  4591. not the entire word, return the length of the field. Return -1 otherwise.
  4592. M is used in machine mode MODE. */
  4593. int
  4594. low_bitmask_len (machine_mode mode, unsigned HOST_WIDE_INT m)
  4595. {
  4596. if (mode != VOIDmode)
  4597. {
  4598. if (GET_MODE_PRECISION (mode) > HOST_BITS_PER_WIDE_INT)
  4599. return -1;
  4600. m &= GET_MODE_MASK (mode);
  4601. }
  4602. return exact_log2 (m + 1);
  4603. }
  4604. /* Return the mode of MEM's address. */
  4605. machine_mode
  4606. get_address_mode (rtx mem)
  4607. {
  4608. machine_mode mode;
  4609. gcc_assert (MEM_P (mem));
  4610. mode = GET_MODE (XEXP (mem, 0));
  4611. if (mode != VOIDmode)
  4612. return mode;
  4613. return targetm.addr_space.address_mode (MEM_ADDR_SPACE (mem));
  4614. }
  4615. /* Split up a CONST_DOUBLE or integer constant rtx
  4616. into two rtx's for single words,
  4617. storing in *FIRST the word that comes first in memory in the target
  4618. and in *SECOND the other.
  4619. TODO: This function needs to be rewritten to work on any size
  4620. integer. */
  4621. void
  4622. split_double (rtx value, rtx *first, rtx *second)
  4623. {
  4624. if (CONST_INT_P (value))
  4625. {
  4626. if (HOST_BITS_PER_WIDE_INT >= (2 * BITS_PER_WORD))
  4627. {
  4628. /* In this case the CONST_INT holds both target words.
  4629. Extract the bits from it into two word-sized pieces.
  4630. Sign extend each half to HOST_WIDE_INT. */
  4631. unsigned HOST_WIDE_INT low, high;
  4632. unsigned HOST_WIDE_INT mask, sign_bit, sign_extend;
  4633. unsigned bits_per_word = BITS_PER_WORD;
  4634. /* Set sign_bit to the most significant bit of a word. */
  4635. sign_bit = 1;
  4636. sign_bit <<= bits_per_word - 1;
  4637. /* Set mask so that all bits of the word are set. We could
  4638. have used 1 << BITS_PER_WORD instead of basing the
  4639. calculation on sign_bit. However, on machines where
  4640. HOST_BITS_PER_WIDE_INT == BITS_PER_WORD, it could cause a
  4641. compiler warning, even though the code would never be
  4642. executed. */
  4643. mask = sign_bit << 1;
  4644. mask--;
  4645. /* Set sign_extend as any remaining bits. */
  4646. sign_extend = ~mask;
  4647. /* Pick the lower word and sign-extend it. */
  4648. low = INTVAL (value);
  4649. low &= mask;
  4650. if (low & sign_bit)
  4651. low |= sign_extend;
  4652. /* Pick the higher word, shifted to the least significant
  4653. bits, and sign-extend it. */
  4654. high = INTVAL (value);
  4655. high >>= bits_per_word - 1;
  4656. high >>= 1;
  4657. high &= mask;
  4658. if (high & sign_bit)
  4659. high |= sign_extend;
  4660. /* Store the words in the target machine order. */
  4661. if (WORDS_BIG_ENDIAN)
  4662. {
  4663. *first = GEN_INT (high);
  4664. *second = GEN_INT (low);
  4665. }
  4666. else
  4667. {
  4668. *first = GEN_INT (low);
  4669. *second = GEN_INT (high);
  4670. }
  4671. }
  4672. else
  4673. {
  4674. /* The rule for using CONST_INT for a wider mode
  4675. is that we regard the value as signed.
  4676. So sign-extend it. */
  4677. rtx high = (INTVAL (value) < 0 ? constm1_rtx : const0_rtx);
  4678. if (WORDS_BIG_ENDIAN)
  4679. {
  4680. *first = high;
  4681. *second = value;
  4682. }
  4683. else
  4684. {
  4685. *first = value;
  4686. *second = high;
  4687. }
  4688. }
  4689. }
  4690. else if (GET_CODE (value) == CONST_WIDE_INT)
  4691. {
  4692. /* All of this is scary code and needs to be converted to
  4693. properly work with any size integer. */
  4694. gcc_assert (CONST_WIDE_INT_NUNITS (value) == 2);
  4695. if (WORDS_BIG_ENDIAN)
  4696. {
  4697. *first = GEN_INT (CONST_WIDE_INT_ELT (value, 1));
  4698. *second = GEN_INT (CONST_WIDE_INT_ELT (value, 0));
  4699. }
  4700. else
  4701. {
  4702. *first = GEN_INT (CONST_WIDE_INT_ELT (value, 0));
  4703. *second = GEN_INT (CONST_WIDE_INT_ELT (value, 1));
  4704. }
  4705. }
  4706. else if (!CONST_DOUBLE_P (value))
  4707. {
  4708. if (WORDS_BIG_ENDIAN)
  4709. {
  4710. *first = const0_rtx;
  4711. *second = value;
  4712. }
  4713. else
  4714. {
  4715. *first = value;
  4716. *second = const0_rtx;
  4717. }
  4718. }
  4719. else if (GET_MODE (value) == VOIDmode
  4720. /* This is the old way we did CONST_DOUBLE integers. */
  4721. || GET_MODE_CLASS (GET_MODE (value)) == MODE_INT)
  4722. {
  4723. /* In an integer, the words are defined as most and least significant.
  4724. So order them by the target's convention. */
  4725. if (WORDS_BIG_ENDIAN)
  4726. {
  4727. *first = GEN_INT (CONST_DOUBLE_HIGH (value));
  4728. *second = GEN_INT (CONST_DOUBLE_LOW (value));
  4729. }
  4730. else
  4731. {
  4732. *first = GEN_INT (CONST_DOUBLE_LOW (value));
  4733. *second = GEN_INT (CONST_DOUBLE_HIGH (value));
  4734. }
  4735. }
  4736. else
  4737. {
  4738. REAL_VALUE_TYPE r;
  4739. long l[2];
  4740. REAL_VALUE_FROM_CONST_DOUBLE (r, value);
  4741. /* Note, this converts the REAL_VALUE_TYPE to the target's
  4742. format, splits up the floating point double and outputs
  4743. exactly 32 bits of it into each of l[0] and l[1] --
  4744. not necessarily BITS_PER_WORD bits. */
  4745. REAL_VALUE_TO_TARGET_DOUBLE (r, l);
  4746. /* If 32 bits is an entire word for the target, but not for the host,
  4747. then sign-extend on the host so that the number will look the same
  4748. way on the host that it would on the target. See for instance
  4749. simplify_unary_operation. The #if is needed to avoid compiler
  4750. warnings. */
  4751. #if HOST_BITS_PER_LONG > 32
  4752. if (BITS_PER_WORD < HOST_BITS_PER_LONG && BITS_PER_WORD == 32)
  4753. {
  4754. if (l[0] & ((long) 1 << 31))
  4755. l[0] |= ((long) (-1) << 32);
  4756. if (l[1] & ((long) 1 << 31))
  4757. l[1] |= ((long) (-1) << 32);
  4758. }
  4759. #endif
  4760. *first = GEN_INT (l[0]);
  4761. *second = GEN_INT (l[1]);
  4762. }
  4763. }
  4764. /* Return true if X is a sign_extract or zero_extract from the least
  4765. significant bit. */
  4766. static bool
  4767. lsb_bitfield_op_p (rtx x)
  4768. {
  4769. if (GET_RTX_CLASS (GET_CODE (x)) == RTX_BITFIELD_OPS)
  4770. {
  4771. machine_mode mode = GET_MODE (XEXP (x, 0));
  4772. HOST_WIDE_INT len = INTVAL (XEXP (x, 1));
  4773. HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
  4774. return (pos == (BITS_BIG_ENDIAN ? GET_MODE_PRECISION (mode) - len : 0));
  4775. }
  4776. return false;
  4777. }
  4778. /* Strip outer address "mutations" from LOC and return a pointer to the
  4779. inner value. If OUTER_CODE is nonnull, store the code of the innermost
  4780. stripped expression there.
  4781. "Mutations" either convert between modes or apply some kind of
  4782. extension, truncation or alignment. */
  4783. rtx *
  4784. strip_address_mutations (rtx *loc, enum rtx_code *outer_code)
  4785. {
  4786. for (;;)
  4787. {
  4788. enum rtx_code code = GET_CODE (*loc);
  4789. if (GET_RTX_CLASS (code) == RTX_UNARY)
  4790. /* Things like SIGN_EXTEND, ZERO_EXTEND and TRUNCATE can be
  4791. used to convert between pointer sizes. */
  4792. loc = &XEXP (*loc, 0);
  4793. else if (lsb_bitfield_op_p (*loc))
  4794. /* A [SIGN|ZERO]_EXTRACT from the least significant bit effectively
  4795. acts as a combined truncation and extension. */
  4796. loc = &XEXP (*loc, 0);
  4797. else if (code == AND && CONST_INT_P (XEXP (*loc, 1)))
  4798. /* (and ... (const_int -X)) is used to align to X bytes. */
  4799. loc = &XEXP (*loc, 0);
  4800. else if (code == SUBREG
  4801. && !OBJECT_P (SUBREG_REG (*loc))
  4802. && subreg_lowpart_p (*loc))
  4803. /* (subreg (operator ...) ...) inside and is used for mode
  4804. conversion too. */
  4805. loc = &SUBREG_REG (*loc);
  4806. else
  4807. return loc;
  4808. if (outer_code)
  4809. *outer_code = code;
  4810. }
  4811. }
  4812. /* Return true if CODE applies some kind of scale. The scaled value is
  4813. is the first operand and the scale is the second. */
  4814. static bool
  4815. binary_scale_code_p (enum rtx_code code)
  4816. {
  4817. return (code == MULT
  4818. || code == ASHIFT
  4819. /* Needed by ARM targets. */
  4820. || code == ASHIFTRT
  4821. || code == LSHIFTRT
  4822. || code == ROTATE
  4823. || code == ROTATERT);
  4824. }
  4825. /* If *INNER can be interpreted as a base, return a pointer to the inner term
  4826. (see address_info). Return null otherwise. */
  4827. static rtx *
  4828. get_base_term (rtx *inner)
  4829. {
  4830. if (GET_CODE (*inner) == LO_SUM)
  4831. inner = strip_address_mutations (&XEXP (*inner, 0));
  4832. if (REG_P (*inner)
  4833. || MEM_P (*inner)
  4834. || GET_CODE (*inner) == SUBREG
  4835. || GET_CODE (*inner) == SCRATCH)
  4836. return inner;
  4837. return 0;
  4838. }
  4839. /* If *INNER can be interpreted as an index, return a pointer to the inner term
  4840. (see address_info). Return null otherwise. */
  4841. static rtx *
  4842. get_index_term (rtx *inner)
  4843. {
  4844. /* At present, only constant scales are allowed. */
  4845. if (binary_scale_code_p (GET_CODE (*inner)) && CONSTANT_P (XEXP (*inner, 1)))
  4846. inner = strip_address_mutations (&XEXP (*inner, 0));
  4847. if (REG_P (*inner)
  4848. || MEM_P (*inner)
  4849. || GET_CODE (*inner) == SUBREG
  4850. || GET_CODE (*inner) == SCRATCH)
  4851. return inner;
  4852. return 0;
  4853. }
  4854. /* Set the segment part of address INFO to LOC, given that INNER is the
  4855. unmutated value. */
  4856. static void
  4857. set_address_segment (struct address_info *info, rtx *loc, rtx *inner)
  4858. {
  4859. gcc_assert (!info->segment);
  4860. info->segment = loc;
  4861. info->segment_term = inner;
  4862. }
  4863. /* Set the base part of address INFO to LOC, given that INNER is the
  4864. unmutated value. */
  4865. static void
  4866. set_address_base (struct address_info *info, rtx *loc, rtx *inner)
  4867. {
  4868. gcc_assert (!info->base);
  4869. info->base = loc;
  4870. info->base_term = inner;
  4871. }
  4872. /* Set the index part of address INFO to LOC, given that INNER is the
  4873. unmutated value. */
  4874. static void
  4875. set_address_index (struct address_info *info, rtx *loc, rtx *inner)
  4876. {
  4877. gcc_assert (!info->index);
  4878. info->index = loc;
  4879. info->index_term = inner;
  4880. }
  4881. /* Set the displacement part of address INFO to LOC, given that INNER
  4882. is the constant term. */
  4883. static void
  4884. set_address_disp (struct address_info *info, rtx *loc, rtx *inner)
  4885. {
  4886. gcc_assert (!info->disp);
  4887. info->disp = loc;
  4888. info->disp_term = inner;
  4889. }
  4890. /* INFO->INNER describes a {PRE,POST}_{INC,DEC} address. Set up the
  4891. rest of INFO accordingly. */
  4892. static void
  4893. decompose_incdec_address (struct address_info *info)
  4894. {
  4895. info->autoinc_p = true;
  4896. rtx *base = &XEXP (*info->inner, 0);
  4897. set_address_base (info, base, base);
  4898. gcc_checking_assert (info->base == info->base_term);
  4899. /* These addresses are only valid when the size of the addressed
  4900. value is known. */
  4901. gcc_checking_assert (info->mode != VOIDmode);
  4902. }
  4903. /* INFO->INNER describes a {PRE,POST}_MODIFY address. Set up the rest
  4904. of INFO accordingly. */
  4905. static void
  4906. decompose_automod_address (struct address_info *info)
  4907. {
  4908. info->autoinc_p = true;
  4909. rtx *base = &XEXP (*info->inner, 0);
  4910. set_address_base (info, base, base);
  4911. gcc_checking_assert (info->base == info->base_term);
  4912. rtx plus = XEXP (*info->inner, 1);
  4913. gcc_assert (GET_CODE (plus) == PLUS);
  4914. info->base_term2 = &XEXP (plus, 0);
  4915. gcc_checking_assert (rtx_equal_p (*info->base_term, *info->base_term2));
  4916. rtx *step = &XEXP (plus, 1);
  4917. rtx *inner_step = strip_address_mutations (step);
  4918. if (CONSTANT_P (*inner_step))
  4919. set_address_disp (info, step, inner_step);
  4920. else
  4921. set_address_index (info, step, inner_step);
  4922. }
  4923. /* Treat *LOC as a tree of PLUS operands and store pointers to the summed
  4924. values in [PTR, END). Return a pointer to the end of the used array. */
  4925. static rtx **
  4926. extract_plus_operands (rtx *loc, rtx **ptr, rtx **end)
  4927. {
  4928. rtx x = *loc;
  4929. if (GET_CODE (x) == PLUS)
  4930. {
  4931. ptr = extract_plus_operands (&XEXP (x, 0), ptr, end);
  4932. ptr = extract_plus_operands (&XEXP (x, 1), ptr, end);
  4933. }
  4934. else
  4935. {
  4936. gcc_assert (ptr != end);
  4937. *ptr++ = loc;
  4938. }
  4939. return ptr;
  4940. }
  4941. /* Evaluate the likelihood of X being a base or index value, returning
  4942. positive if it is likely to be a base, negative if it is likely to be
  4943. an index, and 0 if we can't tell. Make the magnitude of the return
  4944. value reflect the amount of confidence we have in the answer.
  4945. MODE, AS, OUTER_CODE and INDEX_CODE are as for ok_for_base_p_1. */
  4946. static int
  4947. baseness (rtx x, machine_mode mode, addr_space_t as,
  4948. enum rtx_code outer_code, enum rtx_code index_code)
  4949. {
  4950. /* Believe *_POINTER unless the address shape requires otherwise. */
  4951. if (REG_P (x) && REG_POINTER (x))
  4952. return 2;
  4953. if (MEM_P (x) && MEM_POINTER (x))
  4954. return 2;
  4955. if (REG_P (x) && HARD_REGISTER_P (x))
  4956. {
  4957. /* X is a hard register. If it only fits one of the base
  4958. or index classes, choose that interpretation. */
  4959. int regno = REGNO (x);
  4960. bool base_p = ok_for_base_p_1 (regno, mode, as, outer_code, index_code);
  4961. bool index_p = REGNO_OK_FOR_INDEX_P (regno);
  4962. if (base_p != index_p)
  4963. return base_p ? 1 : -1;
  4964. }
  4965. return 0;
  4966. }
  4967. /* INFO->INNER describes a normal, non-automodified address.
  4968. Fill in the rest of INFO accordingly. */
  4969. static void
  4970. decompose_normal_address (struct address_info *info)
  4971. {
  4972. /* Treat the address as the sum of up to four values. */
  4973. rtx *ops[4];
  4974. size_t n_ops = extract_plus_operands (info->inner, ops,
  4975. ops + ARRAY_SIZE (ops)) - ops;
  4976. /* If there is more than one component, any base component is in a PLUS. */
  4977. if (n_ops > 1)
  4978. info->base_outer_code = PLUS;
  4979. /* Try to classify each sum operand now. Leave those that could be
  4980. either a base or an index in OPS. */
  4981. rtx *inner_ops[4];
  4982. size_t out = 0;
  4983. for (size_t in = 0; in < n_ops; ++in)
  4984. {
  4985. rtx *loc = ops[in];
  4986. rtx *inner = strip_address_mutations (loc);
  4987. if (CONSTANT_P (*inner))
  4988. set_address_disp (info, loc, inner);
  4989. else if (GET_CODE (*inner) == UNSPEC)
  4990. set_address_segment (info, loc, inner);
  4991. else
  4992. {
  4993. /* The only other possibilities are a base or an index. */
  4994. rtx *base_term = get_base_term (inner);
  4995. rtx *index_term = get_index_term (inner);
  4996. gcc_assert (base_term || index_term);
  4997. if (!base_term)
  4998. set_address_index (info, loc, index_term);
  4999. else if (!index_term)
  5000. set_address_base (info, loc, base_term);
  5001. else
  5002. {
  5003. gcc_assert (base_term == index_term);
  5004. ops[out] = loc;
  5005. inner_ops[out] = base_term;
  5006. ++out;
  5007. }
  5008. }
  5009. }
  5010. /* Classify the remaining OPS members as bases and indexes. */
  5011. if (out == 1)
  5012. {
  5013. /* If we haven't seen a base or an index yet, assume that this is
  5014. the base. If we were confident that another term was the base
  5015. or index, treat the remaining operand as the other kind. */
  5016. if (!info->base)
  5017. set_address_base (info, ops[0], inner_ops[0]);
  5018. else
  5019. set_address_index (info, ops[0], inner_ops[0]);
  5020. }
  5021. else if (out == 2)
  5022. {
  5023. /* In the event of a tie, assume the base comes first. */
  5024. if (baseness (*inner_ops[0], info->mode, info->as, PLUS,
  5025. GET_CODE (*ops[1]))
  5026. >= baseness (*inner_ops[1], info->mode, info->as, PLUS,
  5027. GET_CODE (*ops[0])))
  5028. {
  5029. set_address_base (info, ops[0], inner_ops[0]);
  5030. set_address_index (info, ops[1], inner_ops[1]);
  5031. }
  5032. else
  5033. {
  5034. set_address_base (info, ops[1], inner_ops[1]);
  5035. set_address_index (info, ops[0], inner_ops[0]);
  5036. }
  5037. }
  5038. else
  5039. gcc_assert (out == 0);
  5040. }
  5041. /* Describe address *LOC in *INFO. MODE is the mode of the addressed value,
  5042. or VOIDmode if not known. AS is the address space associated with LOC.
  5043. OUTER_CODE is MEM if *LOC is a MEM address and ADDRESS otherwise. */
  5044. void
  5045. decompose_address (struct address_info *info, rtx *loc, machine_mode mode,
  5046. addr_space_t as, enum rtx_code outer_code)
  5047. {
  5048. memset (info, 0, sizeof (*info));
  5049. info->mode = mode;
  5050. info->as = as;
  5051. info->addr_outer_code = outer_code;
  5052. info->outer = loc;
  5053. info->inner = strip_address_mutations (loc, &outer_code);
  5054. info->base_outer_code = outer_code;
  5055. switch (GET_CODE (*info->inner))
  5056. {
  5057. case PRE_DEC:
  5058. case PRE_INC:
  5059. case POST_DEC:
  5060. case POST_INC:
  5061. decompose_incdec_address (info);
  5062. break;
  5063. case PRE_MODIFY:
  5064. case POST_MODIFY:
  5065. decompose_automod_address (info);
  5066. break;
  5067. default:
  5068. decompose_normal_address (info);
  5069. break;
  5070. }
  5071. }
  5072. /* Describe address operand LOC in INFO. */
  5073. void
  5074. decompose_lea_address (struct address_info *info, rtx *loc)
  5075. {
  5076. decompose_address (info, loc, VOIDmode, ADDR_SPACE_GENERIC, ADDRESS);
  5077. }
  5078. /* Describe the address of MEM X in INFO. */
  5079. void
  5080. decompose_mem_address (struct address_info *info, rtx x)
  5081. {
  5082. gcc_assert (MEM_P (x));
  5083. decompose_address (info, &XEXP (x, 0), GET_MODE (x),
  5084. MEM_ADDR_SPACE (x), MEM);
  5085. }
  5086. /* Update INFO after a change to the address it describes. */
  5087. void
  5088. update_address (struct address_info *info)
  5089. {
  5090. decompose_address (info, info->outer, info->mode, info->as,
  5091. info->addr_outer_code);
  5092. }
  5093. /* Return the scale applied to *INFO->INDEX_TERM, or 0 if the index is
  5094. more complicated than that. */
  5095. HOST_WIDE_INT
  5096. get_index_scale (const struct address_info *info)
  5097. {
  5098. rtx index = *info->index;
  5099. if (GET_CODE (index) == MULT
  5100. && CONST_INT_P (XEXP (index, 1))
  5101. && info->index_term == &XEXP (index, 0))
  5102. return INTVAL (XEXP (index, 1));
  5103. if (GET_CODE (index) == ASHIFT
  5104. && CONST_INT_P (XEXP (index, 1))
  5105. && info->index_term == &XEXP (index, 0))
  5106. return (HOST_WIDE_INT) 1 << INTVAL (XEXP (index, 1));
  5107. if (info->index == info->index_term)
  5108. return 1;
  5109. return 0;
  5110. }
  5111. /* Return the "index code" of INFO, in the form required by
  5112. ok_for_base_p_1. */
  5113. enum rtx_code
  5114. get_index_code (const struct address_info *info)
  5115. {
  5116. if (info->index)
  5117. return GET_CODE (*info->index);
  5118. if (info->disp)
  5119. return GET_CODE (*info->disp);
  5120. return SCRATCH;
  5121. }
  5122. /* Return true if X contains a thread-local symbol. */
  5123. bool
  5124. tls_referenced_p (const_rtx x)
  5125. {
  5126. if (!targetm.have_tls)
  5127. return false;
  5128. subrtx_iterator::array_type array;
  5129. FOR_EACH_SUBRTX (iter, array, x, ALL)
  5130. if (GET_CODE (*iter) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (*iter) != 0)
  5131. return true;
  5132. return false;
  5133. }