expr.c 348 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507
  1. /* Convert tree expression to rtl instructions, for GNU compiler.
  2. Copyright (C) 1988-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 "machmode.h"
  20. #include "rtl.h"
  21. #include "hash-set.h"
  22. #include "vec.h"
  23. #include "double-int.h"
  24. #include "input.h"
  25. #include "alias.h"
  26. #include "symtab.h"
  27. #include "wide-int.h"
  28. #include "inchash.h"
  29. #include "tree.h"
  30. #include "fold-const.h"
  31. #include "stringpool.h"
  32. #include "stor-layout.h"
  33. #include "attribs.h"
  34. #include "varasm.h"
  35. #include "flags.h"
  36. #include "regs.h"
  37. #include "hard-reg-set.h"
  38. #include "except.h"
  39. #include "function.h"
  40. #include "insn-config.h"
  41. #include "insn-attr.h"
  42. #include "hashtab.h"
  43. #include "statistics.h"
  44. #include "real.h"
  45. #include "fixed-value.h"
  46. #include "expmed.h"
  47. #include "dojump.h"
  48. #include "explow.h"
  49. #include "calls.h"
  50. #include "emit-rtl.h"
  51. #include "stmt.h"
  52. /* Include expr.h after insn-config.h so we get HAVE_conditional_move. */
  53. #include "expr.h"
  54. #include "insn-codes.h"
  55. #include "optabs.h"
  56. #include "libfuncs.h"
  57. #include "recog.h"
  58. #include "reload.h"
  59. #include "typeclass.h"
  60. #include "toplev.h"
  61. #include "langhooks.h"
  62. #include "intl.h"
  63. #include "tm_p.h"
  64. #include "tree-iterator.h"
  65. #include "predict.h"
  66. #include "dominance.h"
  67. #include "cfg.h"
  68. #include "basic-block.h"
  69. #include "tree-ssa-alias.h"
  70. #include "internal-fn.h"
  71. #include "gimple-expr.h"
  72. #include "is-a.h"
  73. #include "gimple.h"
  74. #include "gimple-ssa.h"
  75. #include "hash-map.h"
  76. #include "plugin-api.h"
  77. #include "ipa-ref.h"
  78. #include "cgraph.h"
  79. #include "tree-ssanames.h"
  80. #include "target.h"
  81. #include "common/common-target.h"
  82. #include "timevar.h"
  83. #include "df.h"
  84. #include "diagnostic.h"
  85. #include "tree-ssa-live.h"
  86. #include "tree-outof-ssa.h"
  87. #include "target-globals.h"
  88. #include "params.h"
  89. #include "tree-ssa-address.h"
  90. #include "cfgexpand.h"
  91. #include "builtins.h"
  92. #include "tree-chkp.h"
  93. #include "rtl-chkp.h"
  94. #include "ccmp.h"
  95. #ifndef STACK_PUSH_CODE
  96. #ifdef STACK_GROWS_DOWNWARD
  97. #define STACK_PUSH_CODE PRE_DEC
  98. #else
  99. #define STACK_PUSH_CODE PRE_INC
  100. #endif
  101. #endif
  102. /* If this is nonzero, we do not bother generating VOLATILE
  103. around volatile memory references, and we are willing to
  104. output indirect addresses. If cse is to follow, we reject
  105. indirect addresses so a useful potential cse is generated;
  106. if it is used only once, instruction combination will produce
  107. the same indirect address eventually. */
  108. int cse_not_expected;
  109. /* This structure is used by move_by_pieces to describe the move to
  110. be performed. */
  111. struct move_by_pieces_d
  112. {
  113. rtx to;
  114. rtx to_addr;
  115. int autinc_to;
  116. int explicit_inc_to;
  117. rtx from;
  118. rtx from_addr;
  119. int autinc_from;
  120. int explicit_inc_from;
  121. unsigned HOST_WIDE_INT len;
  122. HOST_WIDE_INT offset;
  123. int reverse;
  124. };
  125. /* This structure is used by store_by_pieces to describe the clear to
  126. be performed. */
  127. struct store_by_pieces_d
  128. {
  129. rtx to;
  130. rtx to_addr;
  131. int autinc_to;
  132. int explicit_inc_to;
  133. unsigned HOST_WIDE_INT len;
  134. HOST_WIDE_INT offset;
  135. rtx (*constfun) (void *, HOST_WIDE_INT, machine_mode);
  136. void *constfundata;
  137. int reverse;
  138. };
  139. static void move_by_pieces_1 (insn_gen_fn, machine_mode,
  140. struct move_by_pieces_d *);
  141. static bool block_move_libcall_safe_for_call_parm (void);
  142. static bool emit_block_move_via_movmem (rtx, rtx, rtx, unsigned, unsigned, HOST_WIDE_INT,
  143. unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
  144. unsigned HOST_WIDE_INT);
  145. static tree emit_block_move_libcall_fn (int);
  146. static void emit_block_move_via_loop (rtx, rtx, rtx, unsigned);
  147. static rtx clear_by_pieces_1 (void *, HOST_WIDE_INT, machine_mode);
  148. static void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
  149. static void store_by_pieces_1 (struct store_by_pieces_d *, unsigned int);
  150. static void store_by_pieces_2 (insn_gen_fn, machine_mode,
  151. struct store_by_pieces_d *);
  152. static tree clear_storage_libcall_fn (int);
  153. static rtx_insn *compress_float_constant (rtx, rtx);
  154. static rtx get_subtarget (rtx);
  155. static void store_constructor_field (rtx, unsigned HOST_WIDE_INT,
  156. HOST_WIDE_INT, machine_mode,
  157. tree, int, alias_set_type);
  158. static void store_constructor (tree, rtx, int, HOST_WIDE_INT);
  159. static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT,
  160. unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT,
  161. machine_mode, tree, alias_set_type, bool);
  162. static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (const_tree, const_tree);
  163. static int is_aligning_offset (const_tree, const_tree);
  164. static rtx reduce_to_bit_field_precision (rtx, rtx, tree);
  165. static rtx do_store_flag (sepops, rtx, machine_mode);
  166. #ifdef PUSH_ROUNDING
  167. static void emit_single_push_insn (machine_mode, rtx, tree);
  168. #endif
  169. static void do_tablejump (rtx, machine_mode, rtx, rtx, rtx, int);
  170. static rtx const_vector_from_tree (tree);
  171. static tree tree_expr_size (const_tree);
  172. static HOST_WIDE_INT int_expr_size (tree);
  173. /* This is run to set up which modes can be used
  174. directly in memory and to initialize the block move optab. It is run
  175. at the beginning of compilation and when the target is reinitialized. */
  176. void
  177. init_expr_target (void)
  178. {
  179. rtx insn, pat;
  180. machine_mode mode;
  181. int num_clobbers;
  182. rtx mem, mem1;
  183. rtx reg;
  184. /* Try indexing by frame ptr and try by stack ptr.
  185. It is known that on the Convex the stack ptr isn't a valid index.
  186. With luck, one or the other is valid on any machine. */
  187. mem = gen_rtx_MEM (VOIDmode, stack_pointer_rtx);
  188. mem1 = gen_rtx_MEM (VOIDmode, frame_pointer_rtx);
  189. /* A scratch register we can modify in-place below to avoid
  190. useless RTL allocations. */
  191. reg = gen_rtx_REG (VOIDmode, -1);
  192. insn = rtx_alloc (INSN);
  193. pat = gen_rtx_SET (VOIDmode, NULL_RTX, NULL_RTX);
  194. PATTERN (insn) = pat;
  195. for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES;
  196. mode = (machine_mode) ((int) mode + 1))
  197. {
  198. int regno;
  199. direct_load[(int) mode] = direct_store[(int) mode] = 0;
  200. PUT_MODE (mem, mode);
  201. PUT_MODE (mem1, mode);
  202. PUT_MODE (reg, mode);
  203. /* See if there is some register that can be used in this mode and
  204. directly loaded or stored from memory. */
  205. if (mode != VOIDmode && mode != BLKmode)
  206. for (regno = 0; regno < FIRST_PSEUDO_REGISTER
  207. && (direct_load[(int) mode] == 0 || direct_store[(int) mode] == 0);
  208. regno++)
  209. {
  210. if (! HARD_REGNO_MODE_OK (regno, mode))
  211. continue;
  212. SET_REGNO (reg, regno);
  213. SET_SRC (pat) = mem;
  214. SET_DEST (pat) = reg;
  215. if (recog (pat, insn, &num_clobbers) >= 0)
  216. direct_load[(int) mode] = 1;
  217. SET_SRC (pat) = mem1;
  218. SET_DEST (pat) = reg;
  219. if (recog (pat, insn, &num_clobbers) >= 0)
  220. direct_load[(int) mode] = 1;
  221. SET_SRC (pat) = reg;
  222. SET_DEST (pat) = mem;
  223. if (recog (pat, insn, &num_clobbers) >= 0)
  224. direct_store[(int) mode] = 1;
  225. SET_SRC (pat) = reg;
  226. SET_DEST (pat) = mem1;
  227. if (recog (pat, insn, &num_clobbers) >= 0)
  228. direct_store[(int) mode] = 1;
  229. }
  230. }
  231. mem = gen_rtx_MEM (VOIDmode, gen_rtx_raw_REG (Pmode, 10000));
  232. for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
  233. mode = GET_MODE_WIDER_MODE (mode))
  234. {
  235. machine_mode srcmode;
  236. for (srcmode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); srcmode != mode;
  237. srcmode = GET_MODE_WIDER_MODE (srcmode))
  238. {
  239. enum insn_code ic;
  240. ic = can_extend_p (mode, srcmode, 0);
  241. if (ic == CODE_FOR_nothing)
  242. continue;
  243. PUT_MODE (mem, srcmode);
  244. if (insn_operand_matches (ic, 1, mem))
  245. float_extend_from_mem[mode][srcmode] = true;
  246. }
  247. }
  248. }
  249. /* This is run at the start of compiling a function. */
  250. void
  251. init_expr (void)
  252. {
  253. memset (&crtl->expr, 0, sizeof (crtl->expr));
  254. }
  255. /* Copy data from FROM to TO, where the machine modes are not the same.
  256. Both modes may be integer, or both may be floating, or both may be
  257. fixed-point.
  258. UNSIGNEDP should be nonzero if FROM is an unsigned type.
  259. This causes zero-extension instead of sign-extension. */
  260. void
  261. convert_move (rtx to, rtx from, int unsignedp)
  262. {
  263. machine_mode to_mode = GET_MODE (to);
  264. machine_mode from_mode = GET_MODE (from);
  265. int to_real = SCALAR_FLOAT_MODE_P (to_mode);
  266. int from_real = SCALAR_FLOAT_MODE_P (from_mode);
  267. enum insn_code code;
  268. rtx libcall;
  269. /* rtx code for making an equivalent value. */
  270. enum rtx_code equiv_code = (unsignedp < 0 ? UNKNOWN
  271. : (unsignedp ? ZERO_EXTEND : SIGN_EXTEND));
  272. gcc_assert (to_real == from_real);
  273. gcc_assert (to_mode != BLKmode);
  274. gcc_assert (from_mode != BLKmode);
  275. /* If the source and destination are already the same, then there's
  276. nothing to do. */
  277. if (to == from)
  278. return;
  279. /* If FROM is a SUBREG that indicates that we have already done at least
  280. the required extension, strip it. We don't handle such SUBREGs as
  281. TO here. */
  282. if (GET_CODE (from) == SUBREG && SUBREG_PROMOTED_VAR_P (from)
  283. && (GET_MODE_PRECISION (GET_MODE (SUBREG_REG (from)))
  284. >= GET_MODE_PRECISION (to_mode))
  285. && SUBREG_CHECK_PROMOTED_SIGN (from, unsignedp))
  286. from = gen_lowpart (to_mode, from), from_mode = to_mode;
  287. gcc_assert (GET_CODE (to) != SUBREG || !SUBREG_PROMOTED_VAR_P (to));
  288. if (to_mode == from_mode
  289. || (from_mode == VOIDmode && CONSTANT_P (from)))
  290. {
  291. emit_move_insn (to, from);
  292. return;
  293. }
  294. if (VECTOR_MODE_P (to_mode) || VECTOR_MODE_P (from_mode))
  295. {
  296. gcc_assert (GET_MODE_BITSIZE (from_mode) == GET_MODE_BITSIZE (to_mode));
  297. if (VECTOR_MODE_P (to_mode))
  298. from = simplify_gen_subreg (to_mode, from, GET_MODE (from), 0);
  299. else
  300. to = simplify_gen_subreg (from_mode, to, GET_MODE (to), 0);
  301. emit_move_insn (to, from);
  302. return;
  303. }
  304. if (GET_CODE (to) == CONCAT && GET_CODE (from) == CONCAT)
  305. {
  306. convert_move (XEXP (to, 0), XEXP (from, 0), unsignedp);
  307. convert_move (XEXP (to, 1), XEXP (from, 1), unsignedp);
  308. return;
  309. }
  310. if (to_real)
  311. {
  312. rtx value;
  313. rtx_insn *insns;
  314. convert_optab tab;
  315. gcc_assert ((GET_MODE_PRECISION (from_mode)
  316. != GET_MODE_PRECISION (to_mode))
  317. || (DECIMAL_FLOAT_MODE_P (from_mode)
  318. != DECIMAL_FLOAT_MODE_P (to_mode)));
  319. if (GET_MODE_PRECISION (from_mode) == GET_MODE_PRECISION (to_mode))
  320. /* Conversion between decimal float and binary float, same size. */
  321. tab = DECIMAL_FLOAT_MODE_P (from_mode) ? trunc_optab : sext_optab;
  322. else if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode))
  323. tab = sext_optab;
  324. else
  325. tab = trunc_optab;
  326. /* Try converting directly if the insn is supported. */
  327. code = convert_optab_handler (tab, to_mode, from_mode);
  328. if (code != CODE_FOR_nothing)
  329. {
  330. emit_unop_insn (code, to, from,
  331. tab == sext_optab ? FLOAT_EXTEND : FLOAT_TRUNCATE);
  332. return;
  333. }
  334. /* Otherwise use a libcall. */
  335. libcall = convert_optab_libfunc (tab, to_mode, from_mode);
  336. /* Is this conversion implemented yet? */
  337. gcc_assert (libcall);
  338. start_sequence ();
  339. value = emit_library_call_value (libcall, NULL_RTX, LCT_CONST, to_mode,
  340. 1, from, from_mode);
  341. insns = get_insns ();
  342. end_sequence ();
  343. emit_libcall_block (insns, to, value,
  344. tab == trunc_optab ? gen_rtx_FLOAT_TRUNCATE (to_mode,
  345. from)
  346. : gen_rtx_FLOAT_EXTEND (to_mode, from));
  347. return;
  348. }
  349. /* Handle pointer conversion. */ /* SPEE 900220. */
  350. /* If the target has a converter from FROM_MODE to TO_MODE, use it. */
  351. {
  352. convert_optab ctab;
  353. if (GET_MODE_PRECISION (from_mode) > GET_MODE_PRECISION (to_mode))
  354. ctab = trunc_optab;
  355. else if (unsignedp)
  356. ctab = zext_optab;
  357. else
  358. ctab = sext_optab;
  359. if (convert_optab_handler (ctab, to_mode, from_mode)
  360. != CODE_FOR_nothing)
  361. {
  362. emit_unop_insn (convert_optab_handler (ctab, to_mode, from_mode),
  363. to, from, UNKNOWN);
  364. return;
  365. }
  366. }
  367. /* Targets are expected to provide conversion insns between PxImode and
  368. xImode for all MODE_PARTIAL_INT modes they use, but no others. */
  369. if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT)
  370. {
  371. machine_mode full_mode
  372. = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT);
  373. gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode)
  374. != CODE_FOR_nothing);
  375. if (full_mode != from_mode)
  376. from = convert_to_mode (full_mode, from, unsignedp);
  377. emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, full_mode),
  378. to, from, UNKNOWN);
  379. return;
  380. }
  381. if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT)
  382. {
  383. rtx new_from;
  384. machine_mode full_mode
  385. = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT);
  386. convert_optab ctab = unsignedp ? zext_optab : sext_optab;
  387. enum insn_code icode;
  388. icode = convert_optab_handler (ctab, full_mode, from_mode);
  389. gcc_assert (icode != CODE_FOR_nothing);
  390. if (to_mode == full_mode)
  391. {
  392. emit_unop_insn (icode, to, from, UNKNOWN);
  393. return;
  394. }
  395. new_from = gen_reg_rtx (full_mode);
  396. emit_unop_insn (icode, new_from, from, UNKNOWN);
  397. /* else proceed to integer conversions below. */
  398. from_mode = full_mode;
  399. from = new_from;
  400. }
  401. /* Make sure both are fixed-point modes or both are not. */
  402. gcc_assert (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode) ==
  403. ALL_SCALAR_FIXED_POINT_MODE_P (to_mode));
  404. if (ALL_SCALAR_FIXED_POINT_MODE_P (from_mode))
  405. {
  406. /* If we widen from_mode to to_mode and they are in the same class,
  407. we won't saturate the result.
  408. Otherwise, always saturate the result to play safe. */
  409. if (GET_MODE_CLASS (from_mode) == GET_MODE_CLASS (to_mode)
  410. && GET_MODE_SIZE (from_mode) < GET_MODE_SIZE (to_mode))
  411. expand_fixed_convert (to, from, 0, 0);
  412. else
  413. expand_fixed_convert (to, from, 0, 1);
  414. return;
  415. }
  416. /* Now both modes are integers. */
  417. /* Handle expanding beyond a word. */
  418. if (GET_MODE_PRECISION (from_mode) < GET_MODE_PRECISION (to_mode)
  419. && GET_MODE_PRECISION (to_mode) > BITS_PER_WORD)
  420. {
  421. rtx_insn *insns;
  422. rtx lowpart;
  423. rtx fill_value;
  424. rtx lowfrom;
  425. int i;
  426. machine_mode lowpart_mode;
  427. int nwords = CEIL (GET_MODE_SIZE (to_mode), UNITS_PER_WORD);
  428. /* Try converting directly if the insn is supported. */
  429. if ((code = can_extend_p (to_mode, from_mode, unsignedp))
  430. != CODE_FOR_nothing)
  431. {
  432. /* If FROM is a SUBREG, put it into a register. Do this
  433. so that we always generate the same set of insns for
  434. better cse'ing; if an intermediate assignment occurred,
  435. we won't be doing the operation directly on the SUBREG. */
  436. if (optimize > 0 && GET_CODE (from) == SUBREG)
  437. from = force_reg (from_mode, from);
  438. emit_unop_insn (code, to, from, equiv_code);
  439. return;
  440. }
  441. /* Next, try converting via full word. */
  442. else if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD
  443. && ((code = can_extend_p (to_mode, word_mode, unsignedp))
  444. != CODE_FOR_nothing))
  445. {
  446. rtx word_to = gen_reg_rtx (word_mode);
  447. if (REG_P (to))
  448. {
  449. if (reg_overlap_mentioned_p (to, from))
  450. from = force_reg (from_mode, from);
  451. emit_clobber (to);
  452. }
  453. convert_move (word_to, from, unsignedp);
  454. emit_unop_insn (code, to, word_to, equiv_code);
  455. return;
  456. }
  457. /* No special multiword conversion insn; do it by hand. */
  458. start_sequence ();
  459. /* Since we will turn this into a no conflict block, we must ensure the
  460. the source does not overlap the target so force it into an isolated
  461. register when maybe so. Likewise for any MEM input, since the
  462. conversion sequence might require several references to it and we
  463. must ensure we're getting the same value every time. */
  464. if (MEM_P (from) || reg_overlap_mentioned_p (to, from))
  465. from = force_reg (from_mode, from);
  466. /* Get a copy of FROM widened to a word, if necessary. */
  467. if (GET_MODE_PRECISION (from_mode) < BITS_PER_WORD)
  468. lowpart_mode = word_mode;
  469. else
  470. lowpart_mode = from_mode;
  471. lowfrom = convert_to_mode (lowpart_mode, from, unsignedp);
  472. lowpart = gen_lowpart (lowpart_mode, to);
  473. emit_move_insn (lowpart, lowfrom);
  474. /* Compute the value to put in each remaining word. */
  475. if (unsignedp)
  476. fill_value = const0_rtx;
  477. else
  478. fill_value = emit_store_flag_force (gen_reg_rtx (word_mode),
  479. LT, lowfrom, const0_rtx,
  480. lowpart_mode, 0, -1);
  481. /* Fill the remaining words. */
  482. for (i = GET_MODE_SIZE (lowpart_mode) / UNITS_PER_WORD; i < nwords; i++)
  483. {
  484. int index = (WORDS_BIG_ENDIAN ? nwords - i - 1 : i);
  485. rtx subword = operand_subword (to, index, 1, to_mode);
  486. gcc_assert (subword);
  487. if (fill_value != subword)
  488. emit_move_insn (subword, fill_value);
  489. }
  490. insns = get_insns ();
  491. end_sequence ();
  492. emit_insn (insns);
  493. return;
  494. }
  495. /* Truncating multi-word to a word or less. */
  496. if (GET_MODE_PRECISION (from_mode) > BITS_PER_WORD
  497. && GET_MODE_PRECISION (to_mode) <= BITS_PER_WORD)
  498. {
  499. if (!((MEM_P (from)
  500. && ! MEM_VOLATILE_P (from)
  501. && direct_load[(int) to_mode]
  502. && ! mode_dependent_address_p (XEXP (from, 0),
  503. MEM_ADDR_SPACE (from)))
  504. || REG_P (from)
  505. || GET_CODE (from) == SUBREG))
  506. from = force_reg (from_mode, from);
  507. convert_move (to, gen_lowpart (word_mode, from), 0);
  508. return;
  509. }
  510. /* Now follow all the conversions between integers
  511. no more than a word long. */
  512. /* For truncation, usually we can just refer to FROM in a narrower mode. */
  513. if (GET_MODE_BITSIZE (to_mode) < GET_MODE_BITSIZE (from_mode)
  514. && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, from_mode))
  515. {
  516. if (!((MEM_P (from)
  517. && ! MEM_VOLATILE_P (from)
  518. && direct_load[(int) to_mode]
  519. && ! mode_dependent_address_p (XEXP (from, 0),
  520. MEM_ADDR_SPACE (from)))
  521. || REG_P (from)
  522. || GET_CODE (from) == SUBREG))
  523. from = force_reg (from_mode, from);
  524. if (REG_P (from) && REGNO (from) < FIRST_PSEUDO_REGISTER
  525. && ! HARD_REGNO_MODE_OK (REGNO (from), to_mode))
  526. from = copy_to_reg (from);
  527. emit_move_insn (to, gen_lowpart (to_mode, from));
  528. return;
  529. }
  530. /* Handle extension. */
  531. if (GET_MODE_PRECISION (to_mode) > GET_MODE_PRECISION (from_mode))
  532. {
  533. /* Convert directly if that works. */
  534. if ((code = can_extend_p (to_mode, from_mode, unsignedp))
  535. != CODE_FOR_nothing)
  536. {
  537. emit_unop_insn (code, to, from, equiv_code);
  538. return;
  539. }
  540. else
  541. {
  542. machine_mode intermediate;
  543. rtx tmp;
  544. int shift_amount;
  545. /* Search for a mode to convert via. */
  546. for (intermediate = from_mode; intermediate != VOIDmode;
  547. intermediate = GET_MODE_WIDER_MODE (intermediate))
  548. if (((can_extend_p (to_mode, intermediate, unsignedp)
  549. != CODE_FOR_nothing)
  550. || (GET_MODE_SIZE (to_mode) < GET_MODE_SIZE (intermediate)
  551. && TRULY_NOOP_TRUNCATION_MODES_P (to_mode, intermediate)))
  552. && (can_extend_p (intermediate, from_mode, unsignedp)
  553. != CODE_FOR_nothing))
  554. {
  555. convert_move (to, convert_to_mode (intermediate, from,
  556. unsignedp), unsignedp);
  557. return;
  558. }
  559. /* No suitable intermediate mode.
  560. Generate what we need with shifts. */
  561. shift_amount = (GET_MODE_PRECISION (to_mode)
  562. - GET_MODE_PRECISION (from_mode));
  563. from = gen_lowpart (to_mode, force_reg (from_mode, from));
  564. tmp = expand_shift (LSHIFT_EXPR, to_mode, from, shift_amount,
  565. to, unsignedp);
  566. tmp = expand_shift (RSHIFT_EXPR, to_mode, tmp, shift_amount,
  567. to, unsignedp);
  568. if (tmp != to)
  569. emit_move_insn (to, tmp);
  570. return;
  571. }
  572. }
  573. /* Support special truncate insns for certain modes. */
  574. if (convert_optab_handler (trunc_optab, to_mode,
  575. from_mode) != CODE_FOR_nothing)
  576. {
  577. emit_unop_insn (convert_optab_handler (trunc_optab, to_mode, from_mode),
  578. to, from, UNKNOWN);
  579. return;
  580. }
  581. /* Handle truncation of volatile memrefs, and so on;
  582. the things that couldn't be truncated directly,
  583. and for which there was no special instruction.
  584. ??? Code above formerly short-circuited this, for most integer
  585. mode pairs, with a force_reg in from_mode followed by a recursive
  586. call to this routine. Appears always to have been wrong. */
  587. if (GET_MODE_PRECISION (to_mode) < GET_MODE_PRECISION (from_mode))
  588. {
  589. rtx temp = force_reg (to_mode, gen_lowpart (to_mode, from));
  590. emit_move_insn (to, temp);
  591. return;
  592. }
  593. /* Mode combination is not recognized. */
  594. gcc_unreachable ();
  595. }
  596. /* Return an rtx for a value that would result
  597. from converting X to mode MODE.
  598. Both X and MODE may be floating, or both integer.
  599. UNSIGNEDP is nonzero if X is an unsigned value.
  600. This can be done by referring to a part of X in place
  601. or by copying to a new temporary with conversion. */
  602. rtx
  603. convert_to_mode (machine_mode mode, rtx x, int unsignedp)
  604. {
  605. return convert_modes (mode, VOIDmode, x, unsignedp);
  606. }
  607. /* Return an rtx for a value that would result
  608. from converting X from mode OLDMODE to mode MODE.
  609. Both modes may be floating, or both integer.
  610. UNSIGNEDP is nonzero if X is an unsigned value.
  611. This can be done by referring to a part of X in place
  612. or by copying to a new temporary with conversion.
  613. You can give VOIDmode for OLDMODE, if you are sure X has a nonvoid mode. */
  614. rtx
  615. convert_modes (machine_mode mode, machine_mode oldmode, rtx x, int unsignedp)
  616. {
  617. rtx temp;
  618. /* If FROM is a SUBREG that indicates that we have already done at least
  619. the required extension, strip it. */
  620. if (GET_CODE (x) == SUBREG && SUBREG_PROMOTED_VAR_P (x)
  621. && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) >= GET_MODE_SIZE (mode)
  622. && SUBREG_CHECK_PROMOTED_SIGN (x, unsignedp))
  623. x = gen_lowpart (mode, SUBREG_REG (x));
  624. if (GET_MODE (x) != VOIDmode)
  625. oldmode = GET_MODE (x);
  626. if (mode == oldmode)
  627. return x;
  628. if (CONST_SCALAR_INT_P (x) && GET_MODE_CLASS (mode) == MODE_INT)
  629. {
  630. /* If the caller did not tell us the old mode, then there is not
  631. much to do with respect to canonicalization. We have to
  632. assume that all the bits are significant. */
  633. if (GET_MODE_CLASS (oldmode) != MODE_INT)
  634. oldmode = MAX_MODE_INT;
  635. wide_int w = wide_int::from (std::make_pair (x, oldmode),
  636. GET_MODE_PRECISION (mode),
  637. unsignedp ? UNSIGNED : SIGNED);
  638. return immed_wide_int_const (w, mode);
  639. }
  640. /* We can do this with a gen_lowpart if both desired and current modes
  641. are integer, and this is either a constant integer, a register, or a
  642. non-volatile MEM. */
  643. if (GET_MODE_CLASS (mode) == MODE_INT
  644. && GET_MODE_CLASS (oldmode) == MODE_INT
  645. && GET_MODE_PRECISION (mode) <= GET_MODE_PRECISION (oldmode)
  646. && ((MEM_P (x) && !MEM_VOLATILE_P (x) && direct_load[(int) mode])
  647. || (REG_P (x)
  648. && (!HARD_REGISTER_P (x)
  649. || HARD_REGNO_MODE_OK (REGNO (x), mode))
  650. && TRULY_NOOP_TRUNCATION_MODES_P (mode, GET_MODE (x)))))
  651. return gen_lowpart (mode, x);
  652. /* Converting from integer constant into mode is always equivalent to an
  653. subreg operation. */
  654. if (VECTOR_MODE_P (mode) && GET_MODE (x) == VOIDmode)
  655. {
  656. gcc_assert (GET_MODE_BITSIZE (mode) == GET_MODE_BITSIZE (oldmode));
  657. return simplify_gen_subreg (mode, x, oldmode, 0);
  658. }
  659. temp = gen_reg_rtx (mode);
  660. convert_move (temp, x, unsignedp);
  661. return temp;
  662. }
  663. /* Return the largest alignment we can use for doing a move (or store)
  664. of MAX_PIECES. ALIGN is the largest alignment we could use. */
  665. static unsigned int
  666. alignment_for_piecewise_move (unsigned int max_pieces, unsigned int align)
  667. {
  668. machine_mode tmode;
  669. tmode = mode_for_size (max_pieces * BITS_PER_UNIT, MODE_INT, 1);
  670. if (align >= GET_MODE_ALIGNMENT (tmode))
  671. align = GET_MODE_ALIGNMENT (tmode);
  672. else
  673. {
  674. machine_mode tmode, xmode;
  675. for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT), xmode = tmode;
  676. tmode != VOIDmode;
  677. xmode = tmode, tmode = GET_MODE_WIDER_MODE (tmode))
  678. if (GET_MODE_SIZE (tmode) > max_pieces
  679. || SLOW_UNALIGNED_ACCESS (tmode, align))
  680. break;
  681. align = MAX (align, GET_MODE_ALIGNMENT (xmode));
  682. }
  683. return align;
  684. }
  685. /* Return the widest integer mode no wider than SIZE. If no such mode
  686. can be found, return VOIDmode. */
  687. static machine_mode
  688. widest_int_mode_for_size (unsigned int size)
  689. {
  690. machine_mode tmode, mode = VOIDmode;
  691. for (tmode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  692. tmode != VOIDmode; tmode = GET_MODE_WIDER_MODE (tmode))
  693. if (GET_MODE_SIZE (tmode) < size)
  694. mode = tmode;
  695. return mode;
  696. }
  697. /* Determine whether the LEN bytes can be moved by using several move
  698. instructions. Return nonzero if a call to move_by_pieces should
  699. succeed. */
  700. int
  701. can_move_by_pieces (unsigned HOST_WIDE_INT len,
  702. unsigned int align)
  703. {
  704. return targetm.use_by_pieces_infrastructure_p (len, align, MOVE_BY_PIECES,
  705. optimize_insn_for_speed_p ());
  706. }
  707. /* Generate several move instructions to copy LEN bytes from block FROM to
  708. block TO. (These are MEM rtx's with BLKmode).
  709. If PUSH_ROUNDING is defined and TO is NULL, emit_single_push_insn is
  710. used to push FROM to the stack.
  711. ALIGN is maximum stack alignment we can assume.
  712. If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
  713. mempcpy, and if ENDP is 2 return memory the end minus one byte ala
  714. stpcpy. */
  715. rtx
  716. move_by_pieces (rtx to, rtx from, unsigned HOST_WIDE_INT len,
  717. unsigned int align, int endp)
  718. {
  719. struct move_by_pieces_d data;
  720. machine_mode to_addr_mode;
  721. machine_mode from_addr_mode = get_address_mode (from);
  722. rtx to_addr, from_addr = XEXP (from, 0);
  723. unsigned int max_size = MOVE_MAX_PIECES + 1;
  724. enum insn_code icode;
  725. align = MIN (to ? MEM_ALIGN (to) : align, MEM_ALIGN (from));
  726. data.offset = 0;
  727. data.from_addr = from_addr;
  728. if (to)
  729. {
  730. to_addr_mode = get_address_mode (to);
  731. to_addr = XEXP (to, 0);
  732. data.to = to;
  733. data.autinc_to
  734. = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
  735. || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
  736. data.reverse
  737. = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
  738. }
  739. else
  740. {
  741. to_addr_mode = VOIDmode;
  742. to_addr = NULL_RTX;
  743. data.to = NULL_RTX;
  744. data.autinc_to = 1;
  745. #ifdef STACK_GROWS_DOWNWARD
  746. data.reverse = 1;
  747. #else
  748. data.reverse = 0;
  749. #endif
  750. }
  751. data.to_addr = to_addr;
  752. data.from = from;
  753. data.autinc_from
  754. = (GET_CODE (from_addr) == PRE_INC || GET_CODE (from_addr) == PRE_DEC
  755. || GET_CODE (from_addr) == POST_INC
  756. || GET_CODE (from_addr) == POST_DEC);
  757. data.explicit_inc_from = 0;
  758. data.explicit_inc_to = 0;
  759. if (data.reverse) data.offset = len;
  760. data.len = len;
  761. /* If copying requires more than two move insns,
  762. copy addresses to registers (to make displacements shorter)
  763. and use post-increment if available. */
  764. if (!(data.autinc_from && data.autinc_to)
  765. && move_by_pieces_ninsns (len, align, max_size) > 2)
  766. {
  767. /* Find the mode of the largest move...
  768. MODE might not be used depending on the definitions of the
  769. USE_* macros below. */
  770. machine_mode mode ATTRIBUTE_UNUSED
  771. = widest_int_mode_for_size (max_size);
  772. if (USE_LOAD_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_from)
  773. {
  774. data.from_addr = copy_to_mode_reg (from_addr_mode,
  775. plus_constant (from_addr_mode,
  776. from_addr, len));
  777. data.autinc_from = 1;
  778. data.explicit_inc_from = -1;
  779. }
  780. if (USE_LOAD_POST_INCREMENT (mode) && ! data.autinc_from)
  781. {
  782. data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
  783. data.autinc_from = 1;
  784. data.explicit_inc_from = 1;
  785. }
  786. if (!data.autinc_from && CONSTANT_P (from_addr))
  787. data.from_addr = copy_to_mode_reg (from_addr_mode, from_addr);
  788. if (USE_STORE_PRE_DECREMENT (mode) && data.reverse && ! data.autinc_to)
  789. {
  790. data.to_addr = copy_to_mode_reg (to_addr_mode,
  791. plus_constant (to_addr_mode,
  792. to_addr, len));
  793. data.autinc_to = 1;
  794. data.explicit_inc_to = -1;
  795. }
  796. if (USE_STORE_POST_INCREMENT (mode) && ! data.reverse && ! data.autinc_to)
  797. {
  798. data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
  799. data.autinc_to = 1;
  800. data.explicit_inc_to = 1;
  801. }
  802. if (!data.autinc_to && CONSTANT_P (to_addr))
  803. data.to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
  804. }
  805. align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
  806. /* First move what we can in the largest integer mode, then go to
  807. successively smaller modes. */
  808. while (max_size > 1 && data.len > 0)
  809. {
  810. machine_mode mode = widest_int_mode_for_size (max_size);
  811. if (mode == VOIDmode)
  812. break;
  813. icode = optab_handler (mov_optab, mode);
  814. if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
  815. move_by_pieces_1 (GEN_FCN (icode), mode, &data);
  816. max_size = GET_MODE_SIZE (mode);
  817. }
  818. /* The code above should have handled everything. */
  819. gcc_assert (!data.len);
  820. if (endp)
  821. {
  822. rtx to1;
  823. gcc_assert (!data.reverse);
  824. if (data.autinc_to)
  825. {
  826. if (endp == 2)
  827. {
  828. if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
  829. emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
  830. else
  831. data.to_addr = copy_to_mode_reg (to_addr_mode,
  832. plus_constant (to_addr_mode,
  833. data.to_addr,
  834. -1));
  835. }
  836. to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
  837. data.offset);
  838. }
  839. else
  840. {
  841. if (endp == 2)
  842. --data.offset;
  843. to1 = adjust_address (data.to, QImode, data.offset);
  844. }
  845. return to1;
  846. }
  847. else
  848. return data.to;
  849. }
  850. /* Return number of insns required to move L bytes by pieces.
  851. ALIGN (in bits) is maximum alignment we can assume. */
  852. unsigned HOST_WIDE_INT
  853. move_by_pieces_ninsns (unsigned HOST_WIDE_INT l, unsigned int align,
  854. unsigned int max_size)
  855. {
  856. unsigned HOST_WIDE_INT n_insns = 0;
  857. align = alignment_for_piecewise_move (MOVE_MAX_PIECES, align);
  858. while (max_size > 1 && l > 0)
  859. {
  860. machine_mode mode;
  861. enum insn_code icode;
  862. mode = widest_int_mode_for_size (max_size);
  863. if (mode == VOIDmode)
  864. break;
  865. icode = optab_handler (mov_optab, mode);
  866. if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
  867. n_insns += l / GET_MODE_SIZE (mode), l %= GET_MODE_SIZE (mode);
  868. max_size = GET_MODE_SIZE (mode);
  869. }
  870. gcc_assert (!l);
  871. return n_insns;
  872. }
  873. /* Subroutine of move_by_pieces. Move as many bytes as appropriate
  874. with move instructions for mode MODE. GENFUN is the gen_... function
  875. to make a move insn for that mode. DATA has all the other info. */
  876. static void
  877. move_by_pieces_1 (insn_gen_fn genfun, machine_mode mode,
  878. struct move_by_pieces_d *data)
  879. {
  880. unsigned int size = GET_MODE_SIZE (mode);
  881. rtx to1 = NULL_RTX, from1;
  882. while (data->len >= size)
  883. {
  884. if (data->reverse)
  885. data->offset -= size;
  886. if (data->to)
  887. {
  888. if (data->autinc_to)
  889. to1 = adjust_automodify_address (data->to, mode, data->to_addr,
  890. data->offset);
  891. else
  892. to1 = adjust_address (data->to, mode, data->offset);
  893. }
  894. if (data->autinc_from)
  895. from1 = adjust_automodify_address (data->from, mode, data->from_addr,
  896. data->offset);
  897. else
  898. from1 = adjust_address (data->from, mode, data->offset);
  899. if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
  900. emit_insn (gen_add2_insn (data->to_addr,
  901. gen_int_mode (-(HOST_WIDE_INT) size,
  902. GET_MODE (data->to_addr))));
  903. if (HAVE_PRE_DECREMENT && data->explicit_inc_from < 0)
  904. emit_insn (gen_add2_insn (data->from_addr,
  905. gen_int_mode (-(HOST_WIDE_INT) size,
  906. GET_MODE (data->from_addr))));
  907. if (data->to)
  908. emit_insn ((*genfun) (to1, from1));
  909. else
  910. {
  911. #ifdef PUSH_ROUNDING
  912. emit_single_push_insn (mode, from1, NULL);
  913. #else
  914. gcc_unreachable ();
  915. #endif
  916. }
  917. if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
  918. emit_insn (gen_add2_insn (data->to_addr,
  919. gen_int_mode (size,
  920. GET_MODE (data->to_addr))));
  921. if (HAVE_POST_INCREMENT && data->explicit_inc_from > 0)
  922. emit_insn (gen_add2_insn (data->from_addr,
  923. gen_int_mode (size,
  924. GET_MODE (data->from_addr))));
  925. if (! data->reverse)
  926. data->offset += size;
  927. data->len -= size;
  928. }
  929. }
  930. /* Emit code to move a block Y to a block X. This may be done with
  931. string-move instructions, with multiple scalar move instructions,
  932. or with a library call.
  933. Both X and Y must be MEM rtx's (perhaps inside VOLATILE) with mode BLKmode.
  934. SIZE is an rtx that says how long they are.
  935. ALIGN is the maximum alignment we can assume they have.
  936. METHOD describes what kind of copy this is, and what mechanisms may be used.
  937. MIN_SIZE is the minimal size of block to move
  938. MAX_SIZE is the maximal size of block to move, if it can not be represented
  939. in unsigned HOST_WIDE_INT, than it is mask of all ones.
  940. Return the address of the new block, if memcpy is called and returns it,
  941. 0 otherwise. */
  942. rtx
  943. emit_block_move_hints (rtx x, rtx y, rtx size, enum block_op_methods method,
  944. unsigned int expected_align, HOST_WIDE_INT expected_size,
  945. unsigned HOST_WIDE_INT min_size,
  946. unsigned HOST_WIDE_INT max_size,
  947. unsigned HOST_WIDE_INT probable_max_size)
  948. {
  949. bool may_use_call;
  950. rtx retval = 0;
  951. unsigned int align;
  952. gcc_assert (size);
  953. if (CONST_INT_P (size)
  954. && INTVAL (size) == 0)
  955. return 0;
  956. switch (method)
  957. {
  958. case BLOCK_OP_NORMAL:
  959. case BLOCK_OP_TAILCALL:
  960. may_use_call = true;
  961. break;
  962. case BLOCK_OP_CALL_PARM:
  963. may_use_call = block_move_libcall_safe_for_call_parm ();
  964. /* Make inhibit_defer_pop nonzero around the library call
  965. to force it to pop the arguments right away. */
  966. NO_DEFER_POP;
  967. break;
  968. case BLOCK_OP_NO_LIBCALL:
  969. may_use_call = false;
  970. break;
  971. default:
  972. gcc_unreachable ();
  973. }
  974. gcc_assert (MEM_P (x) && MEM_P (y));
  975. align = MIN (MEM_ALIGN (x), MEM_ALIGN (y));
  976. gcc_assert (align >= BITS_PER_UNIT);
  977. /* Make sure we've got BLKmode addresses; store_one_arg can decide that
  978. block copy is more efficient for other large modes, e.g. DCmode. */
  979. x = adjust_address (x, BLKmode, 0);
  980. y = adjust_address (y, BLKmode, 0);
  981. /* Set MEM_SIZE as appropriate for this block copy. The main place this
  982. can be incorrect is coming from __builtin_memcpy. */
  983. if (CONST_INT_P (size))
  984. {
  985. x = shallow_copy_rtx (x);
  986. y = shallow_copy_rtx (y);
  987. set_mem_size (x, INTVAL (size));
  988. set_mem_size (y, INTVAL (size));
  989. }
  990. if (CONST_INT_P (size) && can_move_by_pieces (INTVAL (size), align))
  991. move_by_pieces (x, y, INTVAL (size), align, 0);
  992. else if (emit_block_move_via_movmem (x, y, size, align,
  993. expected_align, expected_size,
  994. min_size, max_size, probable_max_size))
  995. ;
  996. else if (may_use_call
  997. && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (x))
  998. && ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (y)))
  999. {
  1000. /* Since x and y are passed to a libcall, mark the corresponding
  1001. tree EXPR as addressable. */
  1002. tree y_expr = MEM_EXPR (y);
  1003. tree x_expr = MEM_EXPR (x);
  1004. if (y_expr)
  1005. mark_addressable (y_expr);
  1006. if (x_expr)
  1007. mark_addressable (x_expr);
  1008. retval = emit_block_move_via_libcall (x, y, size,
  1009. method == BLOCK_OP_TAILCALL);
  1010. }
  1011. else
  1012. emit_block_move_via_loop (x, y, size, align);
  1013. if (method == BLOCK_OP_CALL_PARM)
  1014. OK_DEFER_POP;
  1015. return retval;
  1016. }
  1017. rtx
  1018. emit_block_move (rtx x, rtx y, rtx size, enum block_op_methods method)
  1019. {
  1020. unsigned HOST_WIDE_INT max, min = 0;
  1021. if (GET_CODE (size) == CONST_INT)
  1022. min = max = UINTVAL (size);
  1023. else
  1024. max = GET_MODE_MASK (GET_MODE (size));
  1025. return emit_block_move_hints (x, y, size, method, 0, -1,
  1026. min, max, max);
  1027. }
  1028. /* A subroutine of emit_block_move. Returns true if calling the
  1029. block move libcall will not clobber any parameters which may have
  1030. already been placed on the stack. */
  1031. static bool
  1032. block_move_libcall_safe_for_call_parm (void)
  1033. {
  1034. #if defined (REG_PARM_STACK_SPACE)
  1035. tree fn;
  1036. #endif
  1037. /* If arguments are pushed on the stack, then they're safe. */
  1038. if (PUSH_ARGS)
  1039. return true;
  1040. /* If registers go on the stack anyway, any argument is sure to clobber
  1041. an outgoing argument. */
  1042. #if defined (REG_PARM_STACK_SPACE)
  1043. fn = emit_block_move_libcall_fn (false);
  1044. /* Avoid set but not used warning if *REG_PARM_STACK_SPACE doesn't
  1045. depend on its argument. */
  1046. (void) fn;
  1047. if (OUTGOING_REG_PARM_STACK_SPACE ((!fn ? NULL_TREE : TREE_TYPE (fn)))
  1048. && REG_PARM_STACK_SPACE (fn) != 0)
  1049. return false;
  1050. #endif
  1051. /* If any argument goes in memory, then it might clobber an outgoing
  1052. argument. */
  1053. {
  1054. CUMULATIVE_ARGS args_so_far_v;
  1055. cumulative_args_t args_so_far;
  1056. tree fn, arg;
  1057. fn = emit_block_move_libcall_fn (false);
  1058. INIT_CUMULATIVE_ARGS (args_so_far_v, TREE_TYPE (fn), NULL_RTX, 0, 3);
  1059. args_so_far = pack_cumulative_args (&args_so_far_v);
  1060. arg = TYPE_ARG_TYPES (TREE_TYPE (fn));
  1061. for ( ; arg != void_list_node ; arg = TREE_CHAIN (arg))
  1062. {
  1063. machine_mode mode = TYPE_MODE (TREE_VALUE (arg));
  1064. rtx tmp = targetm.calls.function_arg (args_so_far, mode,
  1065. NULL_TREE, true);
  1066. if (!tmp || !REG_P (tmp))
  1067. return false;
  1068. if (targetm.calls.arg_partial_bytes (args_so_far, mode, NULL, 1))
  1069. return false;
  1070. targetm.calls.function_arg_advance (args_so_far, mode,
  1071. NULL_TREE, true);
  1072. }
  1073. }
  1074. return true;
  1075. }
  1076. /* A subroutine of emit_block_move. Expand a movmem pattern;
  1077. return true if successful. */
  1078. static bool
  1079. emit_block_move_via_movmem (rtx x, rtx y, rtx size, unsigned int align,
  1080. unsigned int expected_align, HOST_WIDE_INT expected_size,
  1081. unsigned HOST_WIDE_INT min_size,
  1082. unsigned HOST_WIDE_INT max_size,
  1083. unsigned HOST_WIDE_INT probable_max_size)
  1084. {
  1085. int save_volatile_ok = volatile_ok;
  1086. machine_mode mode;
  1087. if (expected_align < align)
  1088. expected_align = align;
  1089. if (expected_size != -1)
  1090. {
  1091. if ((unsigned HOST_WIDE_INT)expected_size > probable_max_size)
  1092. expected_size = probable_max_size;
  1093. if ((unsigned HOST_WIDE_INT)expected_size < min_size)
  1094. expected_size = min_size;
  1095. }
  1096. /* Since this is a move insn, we don't care about volatility. */
  1097. volatile_ok = 1;
  1098. /* Try the most limited insn first, because there's no point
  1099. including more than one in the machine description unless
  1100. the more limited one has some advantage. */
  1101. for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
  1102. mode = GET_MODE_WIDER_MODE (mode))
  1103. {
  1104. enum insn_code code = direct_optab_handler (movmem_optab, mode);
  1105. if (code != CODE_FOR_nothing
  1106. /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
  1107. here because if SIZE is less than the mode mask, as it is
  1108. returned by the macro, it will definitely be less than the
  1109. actual mode mask. Since SIZE is within the Pmode address
  1110. space, we limit MODE to Pmode. */
  1111. && ((CONST_INT_P (size)
  1112. && ((unsigned HOST_WIDE_INT) INTVAL (size)
  1113. <= (GET_MODE_MASK (mode) >> 1)))
  1114. || max_size <= (GET_MODE_MASK (mode) >> 1)
  1115. || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
  1116. {
  1117. struct expand_operand ops[9];
  1118. unsigned int nops;
  1119. /* ??? When called via emit_block_move_for_call, it'd be
  1120. nice if there were some way to inform the backend, so
  1121. that it doesn't fail the expansion because it thinks
  1122. emitting the libcall would be more efficient. */
  1123. nops = insn_data[(int) code].n_generator_args;
  1124. gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
  1125. create_fixed_operand (&ops[0], x);
  1126. create_fixed_operand (&ops[1], y);
  1127. /* The check above guarantees that this size conversion is valid. */
  1128. create_convert_operand_to (&ops[2], size, mode, true);
  1129. create_integer_operand (&ops[3], align / BITS_PER_UNIT);
  1130. if (nops >= 6)
  1131. {
  1132. create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
  1133. create_integer_operand (&ops[5], expected_size);
  1134. }
  1135. if (nops >= 8)
  1136. {
  1137. create_integer_operand (&ops[6], min_size);
  1138. /* If we can not represent the maximal size,
  1139. make parameter NULL. */
  1140. if ((HOST_WIDE_INT) max_size != -1)
  1141. create_integer_operand (&ops[7], max_size);
  1142. else
  1143. create_fixed_operand (&ops[7], NULL);
  1144. }
  1145. if (nops == 9)
  1146. {
  1147. /* If we can not represent the maximal size,
  1148. make parameter NULL. */
  1149. if ((HOST_WIDE_INT) probable_max_size != -1)
  1150. create_integer_operand (&ops[8], probable_max_size);
  1151. else
  1152. create_fixed_operand (&ops[8], NULL);
  1153. }
  1154. if (maybe_expand_insn (code, nops, ops))
  1155. {
  1156. volatile_ok = save_volatile_ok;
  1157. return true;
  1158. }
  1159. }
  1160. }
  1161. volatile_ok = save_volatile_ok;
  1162. return false;
  1163. }
  1164. /* A subroutine of emit_block_move. Expand a call to memcpy.
  1165. Return the return value from memcpy, 0 otherwise. */
  1166. rtx
  1167. emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall)
  1168. {
  1169. rtx dst_addr, src_addr;
  1170. tree call_expr, fn, src_tree, dst_tree, size_tree;
  1171. machine_mode size_mode;
  1172. rtx retval;
  1173. /* Emit code to copy the addresses of DST and SRC and SIZE into new
  1174. pseudos. We can then place those new pseudos into a VAR_DECL and
  1175. use them later. */
  1176. dst_addr = copy_addr_to_reg (XEXP (dst, 0));
  1177. src_addr = copy_addr_to_reg (XEXP (src, 0));
  1178. dst_addr = convert_memory_address (ptr_mode, dst_addr);
  1179. src_addr = convert_memory_address (ptr_mode, src_addr);
  1180. dst_tree = make_tree (ptr_type_node, dst_addr);
  1181. src_tree = make_tree (ptr_type_node, src_addr);
  1182. size_mode = TYPE_MODE (sizetype);
  1183. size = convert_to_mode (size_mode, size, 1);
  1184. size = copy_to_mode_reg (size_mode, size);
  1185. /* It is incorrect to use the libcall calling conventions to call
  1186. memcpy in this context. This could be a user call to memcpy and
  1187. the user may wish to examine the return value from memcpy. For
  1188. targets where libcalls and normal calls have different conventions
  1189. for returning pointers, we could end up generating incorrect code. */
  1190. size_tree = make_tree (sizetype, size);
  1191. fn = emit_block_move_libcall_fn (true);
  1192. call_expr = build_call_expr (fn, 3, dst_tree, src_tree, size_tree);
  1193. CALL_EXPR_TAILCALL (call_expr) = tailcall;
  1194. retval = expand_normal (call_expr);
  1195. return retval;
  1196. }
  1197. /* A subroutine of emit_block_move_via_libcall. Create the tree node
  1198. for the function we use for block copies. */
  1199. static GTY(()) tree block_move_fn;
  1200. void
  1201. init_block_move_fn (const char *asmspec)
  1202. {
  1203. if (!block_move_fn)
  1204. {
  1205. tree args, fn, attrs, attr_args;
  1206. fn = get_identifier ("memcpy");
  1207. args = build_function_type_list (ptr_type_node, ptr_type_node,
  1208. const_ptr_type_node, sizetype,
  1209. NULL_TREE);
  1210. fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
  1211. DECL_EXTERNAL (fn) = 1;
  1212. TREE_PUBLIC (fn) = 1;
  1213. DECL_ARTIFICIAL (fn) = 1;
  1214. TREE_NOTHROW (fn) = 1;
  1215. DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
  1216. DECL_VISIBILITY_SPECIFIED (fn) = 1;
  1217. attr_args = build_tree_list (NULL_TREE, build_string (1, "1"));
  1218. attrs = tree_cons (get_identifier ("fn spec"), attr_args, NULL);
  1219. decl_attributes (&fn, attrs, ATTR_FLAG_BUILT_IN);
  1220. block_move_fn = fn;
  1221. }
  1222. if (asmspec)
  1223. set_user_assembler_name (block_move_fn, asmspec);
  1224. }
  1225. static tree
  1226. emit_block_move_libcall_fn (int for_call)
  1227. {
  1228. static bool emitted_extern;
  1229. if (!block_move_fn)
  1230. init_block_move_fn (NULL);
  1231. if (for_call && !emitted_extern)
  1232. {
  1233. emitted_extern = true;
  1234. make_decl_rtl (block_move_fn);
  1235. }
  1236. return block_move_fn;
  1237. }
  1238. /* A subroutine of emit_block_move. Copy the data via an explicit
  1239. loop. This is used only when libcalls are forbidden. */
  1240. /* ??? It'd be nice to copy in hunks larger than QImode. */
  1241. static void
  1242. emit_block_move_via_loop (rtx x, rtx y, rtx size,
  1243. unsigned int align ATTRIBUTE_UNUSED)
  1244. {
  1245. rtx_code_label *cmp_label, *top_label;
  1246. rtx iter, x_addr, y_addr, tmp;
  1247. machine_mode x_addr_mode = get_address_mode (x);
  1248. machine_mode y_addr_mode = get_address_mode (y);
  1249. machine_mode iter_mode;
  1250. iter_mode = GET_MODE (size);
  1251. if (iter_mode == VOIDmode)
  1252. iter_mode = word_mode;
  1253. top_label = gen_label_rtx ();
  1254. cmp_label = gen_label_rtx ();
  1255. iter = gen_reg_rtx (iter_mode);
  1256. emit_move_insn (iter, const0_rtx);
  1257. x_addr = force_operand (XEXP (x, 0), NULL_RTX);
  1258. y_addr = force_operand (XEXP (y, 0), NULL_RTX);
  1259. do_pending_stack_adjust ();
  1260. emit_jump (cmp_label);
  1261. emit_label (top_label);
  1262. tmp = convert_modes (x_addr_mode, iter_mode, iter, true);
  1263. x_addr = simplify_gen_binary (PLUS, x_addr_mode, x_addr, tmp);
  1264. if (x_addr_mode != y_addr_mode)
  1265. tmp = convert_modes (y_addr_mode, iter_mode, iter, true);
  1266. y_addr = simplify_gen_binary (PLUS, y_addr_mode, y_addr, tmp);
  1267. x = change_address (x, QImode, x_addr);
  1268. y = change_address (y, QImode, y_addr);
  1269. emit_move_insn (x, y);
  1270. tmp = expand_simple_binop (iter_mode, PLUS, iter, const1_rtx, iter,
  1271. true, OPTAB_LIB_WIDEN);
  1272. if (tmp != iter)
  1273. emit_move_insn (iter, tmp);
  1274. emit_label (cmp_label);
  1275. emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
  1276. true, top_label, REG_BR_PROB_BASE * 90 / 100);
  1277. }
  1278. /* Copy all or part of a value X into registers starting at REGNO.
  1279. The number of registers to be filled is NREGS. */
  1280. void
  1281. move_block_to_reg (int regno, rtx x, int nregs, machine_mode mode)
  1282. {
  1283. int i;
  1284. #ifdef HAVE_load_multiple
  1285. rtx pat;
  1286. rtx_insn *last;
  1287. #endif
  1288. if (nregs == 0)
  1289. return;
  1290. if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
  1291. x = validize_mem (force_const_mem (mode, x));
  1292. /* See if the machine can do this with a load multiple insn. */
  1293. #ifdef HAVE_load_multiple
  1294. if (HAVE_load_multiple)
  1295. {
  1296. last = get_last_insn ();
  1297. pat = gen_load_multiple (gen_rtx_REG (word_mode, regno), x,
  1298. GEN_INT (nregs));
  1299. if (pat)
  1300. {
  1301. emit_insn (pat);
  1302. return;
  1303. }
  1304. else
  1305. delete_insns_since (last);
  1306. }
  1307. #endif
  1308. for (i = 0; i < nregs; i++)
  1309. emit_move_insn (gen_rtx_REG (word_mode, regno + i),
  1310. operand_subword_force (x, i, mode));
  1311. }
  1312. /* Copy all or part of a BLKmode value X out of registers starting at REGNO.
  1313. The number of registers to be filled is NREGS. */
  1314. void
  1315. move_block_from_reg (int regno, rtx x, int nregs)
  1316. {
  1317. int i;
  1318. if (nregs == 0)
  1319. return;
  1320. /* See if the machine can do this with a store multiple insn. */
  1321. #ifdef HAVE_store_multiple
  1322. if (HAVE_store_multiple)
  1323. {
  1324. rtx_insn *last = get_last_insn ();
  1325. rtx pat = gen_store_multiple (x, gen_rtx_REG (word_mode, regno),
  1326. GEN_INT (nregs));
  1327. if (pat)
  1328. {
  1329. emit_insn (pat);
  1330. return;
  1331. }
  1332. else
  1333. delete_insns_since (last);
  1334. }
  1335. #endif
  1336. for (i = 0; i < nregs; i++)
  1337. {
  1338. rtx tem = operand_subword (x, i, 1, BLKmode);
  1339. gcc_assert (tem);
  1340. emit_move_insn (tem, gen_rtx_REG (word_mode, regno + i));
  1341. }
  1342. }
  1343. /* Generate a PARALLEL rtx for a new non-consecutive group of registers from
  1344. ORIG, where ORIG is a non-consecutive group of registers represented by
  1345. a PARALLEL. The clone is identical to the original except in that the
  1346. original set of registers is replaced by a new set of pseudo registers.
  1347. The new set has the same modes as the original set. */
  1348. rtx
  1349. gen_group_rtx (rtx orig)
  1350. {
  1351. int i, length;
  1352. rtx *tmps;
  1353. gcc_assert (GET_CODE (orig) == PARALLEL);
  1354. length = XVECLEN (orig, 0);
  1355. tmps = XALLOCAVEC (rtx, length);
  1356. /* Skip a NULL entry in first slot. */
  1357. i = XEXP (XVECEXP (orig, 0, 0), 0) ? 0 : 1;
  1358. if (i)
  1359. tmps[0] = 0;
  1360. for (; i < length; i++)
  1361. {
  1362. machine_mode mode = GET_MODE (XEXP (XVECEXP (orig, 0, i), 0));
  1363. rtx offset = XEXP (XVECEXP (orig, 0, i), 1);
  1364. tmps[i] = gen_rtx_EXPR_LIST (VOIDmode, gen_reg_rtx (mode), offset);
  1365. }
  1366. return gen_rtx_PARALLEL (GET_MODE (orig), gen_rtvec_v (length, tmps));
  1367. }
  1368. /* A subroutine of emit_group_load. Arguments as for emit_group_load,
  1369. except that values are placed in TMPS[i], and must later be moved
  1370. into corresponding XEXP (XVECEXP (DST, 0, i), 0) element. */
  1371. static void
  1372. emit_group_load_1 (rtx *tmps, rtx dst, rtx orig_src, tree type, int ssize)
  1373. {
  1374. rtx src;
  1375. int start, i;
  1376. machine_mode m = GET_MODE (orig_src);
  1377. gcc_assert (GET_CODE (dst) == PARALLEL);
  1378. if (m != VOIDmode
  1379. && !SCALAR_INT_MODE_P (m)
  1380. && !MEM_P (orig_src)
  1381. && GET_CODE (orig_src) != CONCAT)
  1382. {
  1383. machine_mode imode = int_mode_for_mode (GET_MODE (orig_src));
  1384. if (imode == BLKmode)
  1385. src = assign_stack_temp (GET_MODE (orig_src), ssize);
  1386. else
  1387. src = gen_reg_rtx (imode);
  1388. if (imode != BLKmode)
  1389. src = gen_lowpart (GET_MODE (orig_src), src);
  1390. emit_move_insn (src, orig_src);
  1391. /* ...and back again. */
  1392. if (imode != BLKmode)
  1393. src = gen_lowpart (imode, src);
  1394. emit_group_load_1 (tmps, dst, src, type, ssize);
  1395. return;
  1396. }
  1397. /* Check for a NULL entry, used to indicate that the parameter goes
  1398. both on the stack and in registers. */
  1399. if (XEXP (XVECEXP (dst, 0, 0), 0))
  1400. start = 0;
  1401. else
  1402. start = 1;
  1403. /* Process the pieces. */
  1404. for (i = start; i < XVECLEN (dst, 0); i++)
  1405. {
  1406. machine_mode mode = GET_MODE (XEXP (XVECEXP (dst, 0, i), 0));
  1407. HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (dst, 0, i), 1));
  1408. unsigned int bytelen = GET_MODE_SIZE (mode);
  1409. int shift = 0;
  1410. /* Handle trailing fragments that run over the size of the struct. */
  1411. if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
  1412. {
  1413. /* Arrange to shift the fragment to where it belongs.
  1414. extract_bit_field loads to the lsb of the reg. */
  1415. if (
  1416. #ifdef BLOCK_REG_PADDING
  1417. BLOCK_REG_PADDING (GET_MODE (orig_src), type, i == start)
  1418. == (BYTES_BIG_ENDIAN ? upward : downward)
  1419. #else
  1420. BYTES_BIG_ENDIAN
  1421. #endif
  1422. )
  1423. shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
  1424. bytelen = ssize - bytepos;
  1425. gcc_assert (bytelen > 0);
  1426. }
  1427. /* If we won't be loading directly from memory, protect the real source
  1428. from strange tricks we might play; but make sure that the source can
  1429. be loaded directly into the destination. */
  1430. src = orig_src;
  1431. if (!MEM_P (orig_src)
  1432. && (!CONSTANT_P (orig_src)
  1433. || (GET_MODE (orig_src) != mode
  1434. && GET_MODE (orig_src) != VOIDmode)))
  1435. {
  1436. if (GET_MODE (orig_src) == VOIDmode)
  1437. src = gen_reg_rtx (mode);
  1438. else
  1439. src = gen_reg_rtx (GET_MODE (orig_src));
  1440. emit_move_insn (src, orig_src);
  1441. }
  1442. /* Optimize the access just a bit. */
  1443. if (MEM_P (src)
  1444. && (! SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (src))
  1445. || MEM_ALIGN (src) >= GET_MODE_ALIGNMENT (mode))
  1446. && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
  1447. && bytelen == GET_MODE_SIZE (mode))
  1448. {
  1449. tmps[i] = gen_reg_rtx (mode);
  1450. emit_move_insn (tmps[i], adjust_address (src, mode, bytepos));
  1451. }
  1452. else if (COMPLEX_MODE_P (mode)
  1453. && GET_MODE (src) == mode
  1454. && bytelen == GET_MODE_SIZE (mode))
  1455. /* Let emit_move_complex do the bulk of the work. */
  1456. tmps[i] = src;
  1457. else if (GET_CODE (src) == CONCAT)
  1458. {
  1459. unsigned int slen = GET_MODE_SIZE (GET_MODE (src));
  1460. unsigned int slen0 = GET_MODE_SIZE (GET_MODE (XEXP (src, 0)));
  1461. if ((bytepos == 0 && bytelen == slen0)
  1462. || (bytepos != 0 && bytepos + bytelen <= slen))
  1463. {
  1464. /* The following assumes that the concatenated objects all
  1465. have the same size. In this case, a simple calculation
  1466. can be used to determine the object and the bit field
  1467. to be extracted. */
  1468. tmps[i] = XEXP (src, bytepos / slen0);
  1469. if (! CONSTANT_P (tmps[i])
  1470. && (!REG_P (tmps[i]) || GET_MODE (tmps[i]) != mode))
  1471. tmps[i] = extract_bit_field (tmps[i], bytelen * BITS_PER_UNIT,
  1472. (bytepos % slen0) * BITS_PER_UNIT,
  1473. 1, NULL_RTX, mode, mode);
  1474. }
  1475. else
  1476. {
  1477. rtx mem;
  1478. gcc_assert (!bytepos);
  1479. mem = assign_stack_temp (GET_MODE (src), slen);
  1480. emit_move_insn (mem, src);
  1481. tmps[i] = extract_bit_field (mem, bytelen * BITS_PER_UNIT,
  1482. 0, 1, NULL_RTX, mode, mode);
  1483. }
  1484. }
  1485. /* FIXME: A SIMD parallel will eventually lead to a subreg of a
  1486. SIMD register, which is currently broken. While we get GCC
  1487. to emit proper RTL for these cases, let's dump to memory. */
  1488. else if (VECTOR_MODE_P (GET_MODE (dst))
  1489. && REG_P (src))
  1490. {
  1491. int slen = GET_MODE_SIZE (GET_MODE (src));
  1492. rtx mem;
  1493. mem = assign_stack_temp (GET_MODE (src), slen);
  1494. emit_move_insn (mem, src);
  1495. tmps[i] = adjust_address (mem, mode, (int) bytepos);
  1496. }
  1497. else if (CONSTANT_P (src) && GET_MODE (dst) != BLKmode
  1498. && XVECLEN (dst, 0) > 1)
  1499. tmps[i] = simplify_gen_subreg (mode, src, GET_MODE (dst), bytepos);
  1500. else if (CONSTANT_P (src))
  1501. {
  1502. HOST_WIDE_INT len = (HOST_WIDE_INT) bytelen;
  1503. if (len == ssize)
  1504. tmps[i] = src;
  1505. else
  1506. {
  1507. rtx first, second;
  1508. /* TODO: const_wide_int can have sizes other than this... */
  1509. gcc_assert (2 * len == ssize);
  1510. split_double (src, &first, &second);
  1511. if (i)
  1512. tmps[i] = second;
  1513. else
  1514. tmps[i] = first;
  1515. }
  1516. }
  1517. else if (REG_P (src) && GET_MODE (src) == mode)
  1518. tmps[i] = src;
  1519. else
  1520. tmps[i] = extract_bit_field (src, bytelen * BITS_PER_UNIT,
  1521. bytepos * BITS_PER_UNIT, 1, NULL_RTX,
  1522. mode, mode);
  1523. if (shift)
  1524. tmps[i] = expand_shift (LSHIFT_EXPR, mode, tmps[i],
  1525. shift, tmps[i], 0);
  1526. }
  1527. }
  1528. /* Emit code to move a block SRC of type TYPE to a block DST,
  1529. where DST is non-consecutive registers represented by a PARALLEL.
  1530. SSIZE represents the total size of block ORIG_SRC in bytes, or -1
  1531. if not known. */
  1532. void
  1533. emit_group_load (rtx dst, rtx src, tree type, int ssize)
  1534. {
  1535. rtx *tmps;
  1536. int i;
  1537. tmps = XALLOCAVEC (rtx, XVECLEN (dst, 0));
  1538. emit_group_load_1 (tmps, dst, src, type, ssize);
  1539. /* Copy the extracted pieces into the proper (probable) hard regs. */
  1540. for (i = 0; i < XVECLEN (dst, 0); i++)
  1541. {
  1542. rtx d = XEXP (XVECEXP (dst, 0, i), 0);
  1543. if (d == NULL)
  1544. continue;
  1545. emit_move_insn (d, tmps[i]);
  1546. }
  1547. }
  1548. /* Similar, but load SRC into new pseudos in a format that looks like
  1549. PARALLEL. This can later be fed to emit_group_move to get things
  1550. in the right place. */
  1551. rtx
  1552. emit_group_load_into_temps (rtx parallel, rtx src, tree type, int ssize)
  1553. {
  1554. rtvec vec;
  1555. int i;
  1556. vec = rtvec_alloc (XVECLEN (parallel, 0));
  1557. emit_group_load_1 (&RTVEC_ELT (vec, 0), parallel, src, type, ssize);
  1558. /* Convert the vector to look just like the original PARALLEL, except
  1559. with the computed values. */
  1560. for (i = 0; i < XVECLEN (parallel, 0); i++)
  1561. {
  1562. rtx e = XVECEXP (parallel, 0, i);
  1563. rtx d = XEXP (e, 0);
  1564. if (d)
  1565. {
  1566. d = force_reg (GET_MODE (d), RTVEC_ELT (vec, i));
  1567. e = alloc_EXPR_LIST (REG_NOTE_KIND (e), d, XEXP (e, 1));
  1568. }
  1569. RTVEC_ELT (vec, i) = e;
  1570. }
  1571. return gen_rtx_PARALLEL (GET_MODE (parallel), vec);
  1572. }
  1573. /* Emit code to move a block SRC to block DST, where SRC and DST are
  1574. non-consecutive groups of registers, each represented by a PARALLEL. */
  1575. void
  1576. emit_group_move (rtx dst, rtx src)
  1577. {
  1578. int i;
  1579. gcc_assert (GET_CODE (src) == PARALLEL
  1580. && GET_CODE (dst) == PARALLEL
  1581. && XVECLEN (src, 0) == XVECLEN (dst, 0));
  1582. /* Skip first entry if NULL. */
  1583. for (i = XEXP (XVECEXP (src, 0, 0), 0) ? 0 : 1; i < XVECLEN (src, 0); i++)
  1584. emit_move_insn (XEXP (XVECEXP (dst, 0, i), 0),
  1585. XEXP (XVECEXP (src, 0, i), 0));
  1586. }
  1587. /* Move a group of registers represented by a PARALLEL into pseudos. */
  1588. rtx
  1589. emit_group_move_into_temps (rtx src)
  1590. {
  1591. rtvec vec = rtvec_alloc (XVECLEN (src, 0));
  1592. int i;
  1593. for (i = 0; i < XVECLEN (src, 0); i++)
  1594. {
  1595. rtx e = XVECEXP (src, 0, i);
  1596. rtx d = XEXP (e, 0);
  1597. if (d)
  1598. e = alloc_EXPR_LIST (REG_NOTE_KIND (e), copy_to_reg (d), XEXP (e, 1));
  1599. RTVEC_ELT (vec, i) = e;
  1600. }
  1601. return gen_rtx_PARALLEL (GET_MODE (src), vec);
  1602. }
  1603. /* Emit code to move a block SRC to a block ORIG_DST of type TYPE,
  1604. where SRC is non-consecutive registers represented by a PARALLEL.
  1605. SSIZE represents the total size of block ORIG_DST, or -1 if not
  1606. known. */
  1607. void
  1608. emit_group_store (rtx orig_dst, rtx src, tree type ATTRIBUTE_UNUSED, int ssize)
  1609. {
  1610. rtx *tmps, dst;
  1611. int start, finish, i;
  1612. machine_mode m = GET_MODE (orig_dst);
  1613. gcc_assert (GET_CODE (src) == PARALLEL);
  1614. if (!SCALAR_INT_MODE_P (m)
  1615. && !MEM_P (orig_dst) && GET_CODE (orig_dst) != CONCAT)
  1616. {
  1617. machine_mode imode = int_mode_for_mode (GET_MODE (orig_dst));
  1618. if (imode == BLKmode)
  1619. dst = assign_stack_temp (GET_MODE (orig_dst), ssize);
  1620. else
  1621. dst = gen_reg_rtx (imode);
  1622. emit_group_store (dst, src, type, ssize);
  1623. if (imode != BLKmode)
  1624. dst = gen_lowpart (GET_MODE (orig_dst), dst);
  1625. emit_move_insn (orig_dst, dst);
  1626. return;
  1627. }
  1628. /* Check for a NULL entry, used to indicate that the parameter goes
  1629. both on the stack and in registers. */
  1630. if (XEXP (XVECEXP (src, 0, 0), 0))
  1631. start = 0;
  1632. else
  1633. start = 1;
  1634. finish = XVECLEN (src, 0);
  1635. tmps = XALLOCAVEC (rtx, finish);
  1636. /* Copy the (probable) hard regs into pseudos. */
  1637. for (i = start; i < finish; i++)
  1638. {
  1639. rtx reg = XEXP (XVECEXP (src, 0, i), 0);
  1640. if (!REG_P (reg) || REGNO (reg) < FIRST_PSEUDO_REGISTER)
  1641. {
  1642. tmps[i] = gen_reg_rtx (GET_MODE (reg));
  1643. emit_move_insn (tmps[i], reg);
  1644. }
  1645. else
  1646. tmps[i] = reg;
  1647. }
  1648. /* If we won't be storing directly into memory, protect the real destination
  1649. from strange tricks we might play. */
  1650. dst = orig_dst;
  1651. if (GET_CODE (dst) == PARALLEL)
  1652. {
  1653. rtx temp;
  1654. /* We can get a PARALLEL dst if there is a conditional expression in
  1655. a return statement. In that case, the dst and src are the same,
  1656. so no action is necessary. */
  1657. if (rtx_equal_p (dst, src))
  1658. return;
  1659. /* It is unclear if we can ever reach here, but we may as well handle
  1660. it. Allocate a temporary, and split this into a store/load to/from
  1661. the temporary. */
  1662. temp = assign_stack_temp (GET_MODE (dst), ssize);
  1663. emit_group_store (temp, src, type, ssize);
  1664. emit_group_load (dst, temp, type, ssize);
  1665. return;
  1666. }
  1667. else if (!MEM_P (dst) && GET_CODE (dst) != CONCAT)
  1668. {
  1669. machine_mode outer = GET_MODE (dst);
  1670. machine_mode inner;
  1671. HOST_WIDE_INT bytepos;
  1672. bool done = false;
  1673. rtx temp;
  1674. if (!REG_P (dst) || REGNO (dst) < FIRST_PSEUDO_REGISTER)
  1675. dst = gen_reg_rtx (outer);
  1676. /* Make life a bit easier for combine. */
  1677. /* If the first element of the vector is the low part
  1678. of the destination mode, use a paradoxical subreg to
  1679. initialize the destination. */
  1680. if (start < finish)
  1681. {
  1682. inner = GET_MODE (tmps[start]);
  1683. bytepos = subreg_lowpart_offset (inner, outer);
  1684. if (INTVAL (XEXP (XVECEXP (src, 0, start), 1)) == bytepos)
  1685. {
  1686. temp = simplify_gen_subreg (outer, tmps[start],
  1687. inner, 0);
  1688. if (temp)
  1689. {
  1690. emit_move_insn (dst, temp);
  1691. done = true;
  1692. start++;
  1693. }
  1694. }
  1695. }
  1696. /* If the first element wasn't the low part, try the last. */
  1697. if (!done
  1698. && start < finish - 1)
  1699. {
  1700. inner = GET_MODE (tmps[finish - 1]);
  1701. bytepos = subreg_lowpart_offset (inner, outer);
  1702. if (INTVAL (XEXP (XVECEXP (src, 0, finish - 1), 1)) == bytepos)
  1703. {
  1704. temp = simplify_gen_subreg (outer, tmps[finish - 1],
  1705. inner, 0);
  1706. if (temp)
  1707. {
  1708. emit_move_insn (dst, temp);
  1709. done = true;
  1710. finish--;
  1711. }
  1712. }
  1713. }
  1714. /* Otherwise, simply initialize the result to zero. */
  1715. if (!done)
  1716. emit_move_insn (dst, CONST0_RTX (outer));
  1717. }
  1718. /* Process the pieces. */
  1719. for (i = start; i < finish; i++)
  1720. {
  1721. HOST_WIDE_INT bytepos = INTVAL (XEXP (XVECEXP (src, 0, i), 1));
  1722. machine_mode mode = GET_MODE (tmps[i]);
  1723. unsigned int bytelen = GET_MODE_SIZE (mode);
  1724. unsigned int adj_bytelen;
  1725. rtx dest = dst;
  1726. /* Handle trailing fragments that run over the size of the struct. */
  1727. if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
  1728. adj_bytelen = ssize - bytepos;
  1729. else
  1730. adj_bytelen = bytelen;
  1731. if (GET_CODE (dst) == CONCAT)
  1732. {
  1733. if (bytepos + adj_bytelen
  1734. <= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
  1735. dest = XEXP (dst, 0);
  1736. else if (bytepos >= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0))))
  1737. {
  1738. bytepos -= GET_MODE_SIZE (GET_MODE (XEXP (dst, 0)));
  1739. dest = XEXP (dst, 1);
  1740. }
  1741. else
  1742. {
  1743. machine_mode dest_mode = GET_MODE (dest);
  1744. machine_mode tmp_mode = GET_MODE (tmps[i]);
  1745. gcc_assert (bytepos == 0 && XVECLEN (src, 0));
  1746. if (GET_MODE_ALIGNMENT (dest_mode)
  1747. >= GET_MODE_ALIGNMENT (tmp_mode))
  1748. {
  1749. dest = assign_stack_temp (dest_mode,
  1750. GET_MODE_SIZE (dest_mode));
  1751. emit_move_insn (adjust_address (dest,
  1752. tmp_mode,
  1753. bytepos),
  1754. tmps[i]);
  1755. dst = dest;
  1756. }
  1757. else
  1758. {
  1759. dest = assign_stack_temp (tmp_mode,
  1760. GET_MODE_SIZE (tmp_mode));
  1761. emit_move_insn (dest, tmps[i]);
  1762. dst = adjust_address (dest, dest_mode, bytepos);
  1763. }
  1764. break;
  1765. }
  1766. }
  1767. /* Handle trailing fragments that run over the size of the struct. */
  1768. if (ssize >= 0 && bytepos + (HOST_WIDE_INT) bytelen > ssize)
  1769. {
  1770. /* store_bit_field always takes its value from the lsb.
  1771. Move the fragment to the lsb if it's not already there. */
  1772. if (
  1773. #ifdef BLOCK_REG_PADDING
  1774. BLOCK_REG_PADDING (GET_MODE (orig_dst), type, i == start)
  1775. == (BYTES_BIG_ENDIAN ? upward : downward)
  1776. #else
  1777. BYTES_BIG_ENDIAN
  1778. #endif
  1779. )
  1780. {
  1781. int shift = (bytelen - (ssize - bytepos)) * BITS_PER_UNIT;
  1782. tmps[i] = expand_shift (RSHIFT_EXPR, mode, tmps[i],
  1783. shift, tmps[i], 0);
  1784. }
  1785. /* Make sure not to write past the end of the struct. */
  1786. store_bit_field (dest,
  1787. adj_bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
  1788. bytepos * BITS_PER_UNIT, ssize * BITS_PER_UNIT - 1,
  1789. VOIDmode, tmps[i]);
  1790. }
  1791. /* Optimize the access just a bit. */
  1792. else if (MEM_P (dest)
  1793. && (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (dest))
  1794. || MEM_ALIGN (dest) >= GET_MODE_ALIGNMENT (mode))
  1795. && bytepos * BITS_PER_UNIT % GET_MODE_ALIGNMENT (mode) == 0
  1796. && bytelen == GET_MODE_SIZE (mode))
  1797. emit_move_insn (adjust_address (dest, mode, bytepos), tmps[i]);
  1798. else
  1799. store_bit_field (dest, bytelen * BITS_PER_UNIT, bytepos * BITS_PER_UNIT,
  1800. 0, 0, mode, tmps[i]);
  1801. }
  1802. /* Copy from the pseudo into the (probable) hard reg. */
  1803. if (orig_dst != dst)
  1804. emit_move_insn (orig_dst, dst);
  1805. }
  1806. /* Return a form of X that does not use a PARALLEL. TYPE is the type
  1807. of the value stored in X. */
  1808. rtx
  1809. maybe_emit_group_store (rtx x, tree type)
  1810. {
  1811. machine_mode mode = TYPE_MODE (type);
  1812. gcc_checking_assert (GET_MODE (x) == VOIDmode || GET_MODE (x) == mode);
  1813. if (GET_CODE (x) == PARALLEL)
  1814. {
  1815. rtx result = gen_reg_rtx (mode);
  1816. emit_group_store (result, x, type, int_size_in_bytes (type));
  1817. return result;
  1818. }
  1819. return x;
  1820. }
  1821. /* Copy a BLKmode object of TYPE out of a register SRCREG into TARGET.
  1822. This is used on targets that return BLKmode values in registers. */
  1823. void
  1824. copy_blkmode_from_reg (rtx target, rtx srcreg, tree type)
  1825. {
  1826. unsigned HOST_WIDE_INT bytes = int_size_in_bytes (type);
  1827. rtx src = NULL, dst = NULL;
  1828. unsigned HOST_WIDE_INT bitsize = MIN (TYPE_ALIGN (type), BITS_PER_WORD);
  1829. unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0;
  1830. machine_mode mode = GET_MODE (srcreg);
  1831. machine_mode tmode = GET_MODE (target);
  1832. machine_mode copy_mode;
  1833. /* BLKmode registers created in the back-end shouldn't have survived. */
  1834. gcc_assert (mode != BLKmode);
  1835. /* If the structure doesn't take up a whole number of words, see whether
  1836. SRCREG is padded on the left or on the right. If it's on the left,
  1837. set PADDING_CORRECTION to the number of bits to skip.
  1838. In most ABIs, the structure will be returned at the least end of
  1839. the register, which translates to right padding on little-endian
  1840. targets and left padding on big-endian targets. The opposite
  1841. holds if the structure is returned at the most significant
  1842. end of the register. */
  1843. if (bytes % UNITS_PER_WORD != 0
  1844. && (targetm.calls.return_in_msb (type)
  1845. ? !BYTES_BIG_ENDIAN
  1846. : BYTES_BIG_ENDIAN))
  1847. padding_correction
  1848. = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD) * BITS_PER_UNIT));
  1849. /* We can use a single move if we have an exact mode for the size. */
  1850. else if (MEM_P (target)
  1851. && (!SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target))
  1852. || MEM_ALIGN (target) >= GET_MODE_ALIGNMENT (mode))
  1853. && bytes == GET_MODE_SIZE (mode))
  1854. {
  1855. emit_move_insn (adjust_address (target, mode, 0), srcreg);
  1856. return;
  1857. }
  1858. /* And if we additionally have the same mode for a register. */
  1859. else if (REG_P (target)
  1860. && GET_MODE (target) == mode
  1861. && bytes == GET_MODE_SIZE (mode))
  1862. {
  1863. emit_move_insn (target, srcreg);
  1864. return;
  1865. }
  1866. /* This code assumes srcreg is at least a full word. If it isn't, copy it
  1867. into a new pseudo which is a full word. */
  1868. if (GET_MODE_SIZE (mode) < UNITS_PER_WORD)
  1869. {
  1870. srcreg = convert_to_mode (word_mode, srcreg, TYPE_UNSIGNED (type));
  1871. mode = word_mode;
  1872. }
  1873. /* Copy the structure BITSIZE bits at a time. If the target lives in
  1874. memory, take care of not reading/writing past its end by selecting
  1875. a copy mode suited to BITSIZE. This should always be possible given
  1876. how it is computed.
  1877. If the target lives in register, make sure not to select a copy mode
  1878. larger than the mode of the register.
  1879. We could probably emit more efficient code for machines which do not use
  1880. strict alignment, but it doesn't seem worth the effort at the current
  1881. time. */
  1882. copy_mode = word_mode;
  1883. if (MEM_P (target))
  1884. {
  1885. machine_mode mem_mode = mode_for_size (bitsize, MODE_INT, 1);
  1886. if (mem_mode != BLKmode)
  1887. copy_mode = mem_mode;
  1888. }
  1889. else if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
  1890. copy_mode = tmode;
  1891. for (bitpos = 0, xbitpos = padding_correction;
  1892. bitpos < bytes * BITS_PER_UNIT;
  1893. bitpos += bitsize, xbitpos += bitsize)
  1894. {
  1895. /* We need a new source operand each time xbitpos is on a
  1896. word boundary and when xbitpos == padding_correction
  1897. (the first time through). */
  1898. if (xbitpos % BITS_PER_WORD == 0 || xbitpos == padding_correction)
  1899. src = operand_subword_force (srcreg, xbitpos / BITS_PER_WORD, mode);
  1900. /* We need a new destination operand each time bitpos is on
  1901. a word boundary. */
  1902. if (REG_P (target) && GET_MODE_BITSIZE (tmode) < BITS_PER_WORD)
  1903. dst = target;
  1904. else if (bitpos % BITS_PER_WORD == 0)
  1905. dst = operand_subword (target, bitpos / BITS_PER_WORD, 1, tmode);
  1906. /* Use xbitpos for the source extraction (right justified) and
  1907. bitpos for the destination store (left justified). */
  1908. store_bit_field (dst, bitsize, bitpos % BITS_PER_WORD, 0, 0, copy_mode,
  1909. extract_bit_field (src, bitsize,
  1910. xbitpos % BITS_PER_WORD, 1,
  1911. NULL_RTX, copy_mode, copy_mode));
  1912. }
  1913. }
  1914. /* Copy BLKmode value SRC into a register of mode MODE. Return the
  1915. register if it contains any data, otherwise return null.
  1916. This is used on targets that return BLKmode values in registers. */
  1917. rtx
  1918. copy_blkmode_to_reg (machine_mode mode, tree src)
  1919. {
  1920. int i, n_regs;
  1921. unsigned HOST_WIDE_INT bitpos, xbitpos, padding_correction = 0, bytes;
  1922. unsigned int bitsize;
  1923. rtx *dst_words, dst, x, src_word = NULL_RTX, dst_word = NULL_RTX;
  1924. machine_mode dst_mode;
  1925. gcc_assert (TYPE_MODE (TREE_TYPE (src)) == BLKmode);
  1926. x = expand_normal (src);
  1927. bytes = int_size_in_bytes (TREE_TYPE (src));
  1928. if (bytes == 0)
  1929. return NULL_RTX;
  1930. /* If the structure doesn't take up a whole number of words, see
  1931. whether the register value should be padded on the left or on
  1932. the right. Set PADDING_CORRECTION to the number of padding
  1933. bits needed on the left side.
  1934. In most ABIs, the structure will be returned at the least end of
  1935. the register, which translates to right padding on little-endian
  1936. targets and left padding on big-endian targets. The opposite
  1937. holds if the structure is returned at the most significant
  1938. end of the register. */
  1939. if (bytes % UNITS_PER_WORD != 0
  1940. && (targetm.calls.return_in_msb (TREE_TYPE (src))
  1941. ? !BYTES_BIG_ENDIAN
  1942. : BYTES_BIG_ENDIAN))
  1943. padding_correction = (BITS_PER_WORD - ((bytes % UNITS_PER_WORD)
  1944. * BITS_PER_UNIT));
  1945. n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  1946. dst_words = XALLOCAVEC (rtx, n_regs);
  1947. bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD);
  1948. /* Copy the structure BITSIZE bits at a time. */
  1949. for (bitpos = 0, xbitpos = padding_correction;
  1950. bitpos < bytes * BITS_PER_UNIT;
  1951. bitpos += bitsize, xbitpos += bitsize)
  1952. {
  1953. /* We need a new destination pseudo each time xbitpos is
  1954. on a word boundary and when xbitpos == padding_correction
  1955. (the first time through). */
  1956. if (xbitpos % BITS_PER_WORD == 0
  1957. || xbitpos == padding_correction)
  1958. {
  1959. /* Generate an appropriate register. */
  1960. dst_word = gen_reg_rtx (word_mode);
  1961. dst_words[xbitpos / BITS_PER_WORD] = dst_word;
  1962. /* Clear the destination before we move anything into it. */
  1963. emit_move_insn (dst_word, CONST0_RTX (word_mode));
  1964. }
  1965. /* We need a new source operand each time bitpos is on a word
  1966. boundary. */
  1967. if (bitpos % BITS_PER_WORD == 0)
  1968. src_word = operand_subword_force (x, bitpos / BITS_PER_WORD, BLKmode);
  1969. /* Use bitpos for the source extraction (left justified) and
  1970. xbitpos for the destination store (right justified). */
  1971. store_bit_field (dst_word, bitsize, xbitpos % BITS_PER_WORD,
  1972. 0, 0, word_mode,
  1973. extract_bit_field (src_word, bitsize,
  1974. bitpos % BITS_PER_WORD, 1,
  1975. NULL_RTX, word_mode, word_mode));
  1976. }
  1977. if (mode == BLKmode)
  1978. {
  1979. /* Find the smallest integer mode large enough to hold the
  1980. entire structure. */
  1981. for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
  1982. mode != VOIDmode;
  1983. mode = GET_MODE_WIDER_MODE (mode))
  1984. /* Have we found a large enough mode? */
  1985. if (GET_MODE_SIZE (mode) >= bytes)
  1986. break;
  1987. /* A suitable mode should have been found. */
  1988. gcc_assert (mode != VOIDmode);
  1989. }
  1990. if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
  1991. dst_mode = word_mode;
  1992. else
  1993. dst_mode = mode;
  1994. dst = gen_reg_rtx (dst_mode);
  1995. for (i = 0; i < n_regs; i++)
  1996. emit_move_insn (operand_subword (dst, i, 0, dst_mode), dst_words[i]);
  1997. if (mode != dst_mode)
  1998. dst = gen_lowpart (mode, dst);
  1999. return dst;
  2000. }
  2001. /* Add a USE expression for REG to the (possibly empty) list pointed
  2002. to by CALL_FUSAGE. REG must denote a hard register. */
  2003. void
  2004. use_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
  2005. {
  2006. gcc_assert (REG_P (reg));
  2007. if (!HARD_REGISTER_P (reg))
  2008. return;
  2009. *call_fusage
  2010. = gen_rtx_EXPR_LIST (mode, gen_rtx_USE (VOIDmode, reg), *call_fusage);
  2011. }
  2012. /* Add a CLOBBER expression for REG to the (possibly empty) list pointed
  2013. to by CALL_FUSAGE. REG must denote a hard register. */
  2014. void
  2015. clobber_reg_mode (rtx *call_fusage, rtx reg, machine_mode mode)
  2016. {
  2017. gcc_assert (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER);
  2018. *call_fusage
  2019. = gen_rtx_EXPR_LIST (mode, gen_rtx_CLOBBER (VOIDmode, reg), *call_fusage);
  2020. }
  2021. /* Add USE expressions to *CALL_FUSAGE for each of NREGS consecutive regs,
  2022. starting at REGNO. All of these registers must be hard registers. */
  2023. void
  2024. use_regs (rtx *call_fusage, int regno, int nregs)
  2025. {
  2026. int i;
  2027. gcc_assert (regno + nregs <= FIRST_PSEUDO_REGISTER);
  2028. for (i = 0; i < nregs; i++)
  2029. use_reg (call_fusage, regno_reg_rtx[regno + i]);
  2030. }
  2031. /* Add USE expressions to *CALL_FUSAGE for each REG contained in the
  2032. PARALLEL REGS. This is for calls that pass values in multiple
  2033. non-contiguous locations. The Irix 6 ABI has examples of this. */
  2034. void
  2035. use_group_regs (rtx *call_fusage, rtx regs)
  2036. {
  2037. int i;
  2038. for (i = 0; i < XVECLEN (regs, 0); i++)
  2039. {
  2040. rtx reg = XEXP (XVECEXP (regs, 0, i), 0);
  2041. /* A NULL entry means the parameter goes both on the stack and in
  2042. registers. This can also be a MEM for targets that pass values
  2043. partially on the stack and partially in registers. */
  2044. if (reg != 0 && REG_P (reg))
  2045. use_reg (call_fusage, reg);
  2046. }
  2047. }
  2048. /* Return the defining gimple statement for SSA_NAME NAME if it is an
  2049. assigment and the code of the expresion on the RHS is CODE. Return
  2050. NULL otherwise. */
  2051. static gimple
  2052. get_def_for_expr (tree name, enum tree_code code)
  2053. {
  2054. gimple def_stmt;
  2055. if (TREE_CODE (name) != SSA_NAME)
  2056. return NULL;
  2057. def_stmt = get_gimple_for_ssa_name (name);
  2058. if (!def_stmt
  2059. || gimple_assign_rhs_code (def_stmt) != code)
  2060. return NULL;
  2061. return def_stmt;
  2062. }
  2063. #ifdef HAVE_conditional_move
  2064. /* Return the defining gimple statement for SSA_NAME NAME if it is an
  2065. assigment and the class of the expresion on the RHS is CLASS. Return
  2066. NULL otherwise. */
  2067. static gimple
  2068. get_def_for_expr_class (tree name, enum tree_code_class tclass)
  2069. {
  2070. gimple def_stmt;
  2071. if (TREE_CODE (name) != SSA_NAME)
  2072. return NULL;
  2073. def_stmt = get_gimple_for_ssa_name (name);
  2074. if (!def_stmt
  2075. || TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) != tclass)
  2076. return NULL;
  2077. return def_stmt;
  2078. }
  2079. #endif
  2080. /* Determine whether the LEN bytes generated by CONSTFUN can be
  2081. stored to memory using several move instructions. CONSTFUNDATA is
  2082. a pointer which will be passed as argument in every CONSTFUN call.
  2083. ALIGN is maximum alignment we can assume. MEMSETP is true if this is
  2084. a memset operation and false if it's a copy of a constant string.
  2085. Return nonzero if a call to store_by_pieces should succeed. */
  2086. int
  2087. can_store_by_pieces (unsigned HOST_WIDE_INT len,
  2088. rtx (*constfun) (void *, HOST_WIDE_INT, machine_mode),
  2089. void *constfundata, unsigned int align, bool memsetp)
  2090. {
  2091. unsigned HOST_WIDE_INT l;
  2092. unsigned int max_size;
  2093. HOST_WIDE_INT offset = 0;
  2094. machine_mode mode;
  2095. enum insn_code icode;
  2096. int reverse;
  2097. /* cst is set but not used if LEGITIMATE_CONSTANT doesn't use it. */
  2098. rtx cst ATTRIBUTE_UNUSED;
  2099. if (len == 0)
  2100. return 1;
  2101. if (!targetm.use_by_pieces_infrastructure_p (len, align,
  2102. memsetp
  2103. ? SET_BY_PIECES
  2104. : STORE_BY_PIECES,
  2105. optimize_insn_for_speed_p ()))
  2106. return 0;
  2107. align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
  2108. /* We would first store what we can in the largest integer mode, then go to
  2109. successively smaller modes. */
  2110. for (reverse = 0;
  2111. reverse <= (HAVE_PRE_DECREMENT || HAVE_POST_DECREMENT);
  2112. reverse++)
  2113. {
  2114. l = len;
  2115. max_size = STORE_MAX_PIECES + 1;
  2116. while (max_size > 1 && l > 0)
  2117. {
  2118. mode = widest_int_mode_for_size (max_size);
  2119. if (mode == VOIDmode)
  2120. break;
  2121. icode = optab_handler (mov_optab, mode);
  2122. if (icode != CODE_FOR_nothing
  2123. && align >= GET_MODE_ALIGNMENT (mode))
  2124. {
  2125. unsigned int size = GET_MODE_SIZE (mode);
  2126. while (l >= size)
  2127. {
  2128. if (reverse)
  2129. offset -= size;
  2130. cst = (*constfun) (constfundata, offset, mode);
  2131. if (!targetm.legitimate_constant_p (mode, cst))
  2132. return 0;
  2133. if (!reverse)
  2134. offset += size;
  2135. l -= size;
  2136. }
  2137. }
  2138. max_size = GET_MODE_SIZE (mode);
  2139. }
  2140. /* The code above should have handled everything. */
  2141. gcc_assert (!l);
  2142. }
  2143. return 1;
  2144. }
  2145. /* Generate several move instructions to store LEN bytes generated by
  2146. CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
  2147. pointer which will be passed as argument in every CONSTFUN call.
  2148. ALIGN is maximum alignment we can assume. MEMSETP is true if this is
  2149. a memset operation and false if it's a copy of a constant string.
  2150. If ENDP is 0 return to, if ENDP is 1 return memory at the end ala
  2151. mempcpy, and if ENDP is 2 return memory the end minus one byte ala
  2152. stpcpy. */
  2153. rtx
  2154. store_by_pieces (rtx to, unsigned HOST_WIDE_INT len,
  2155. rtx (*constfun) (void *, HOST_WIDE_INT, machine_mode),
  2156. void *constfundata, unsigned int align, bool memsetp, int endp)
  2157. {
  2158. machine_mode to_addr_mode = get_address_mode (to);
  2159. struct store_by_pieces_d data;
  2160. if (len == 0)
  2161. {
  2162. gcc_assert (endp != 2);
  2163. return to;
  2164. }
  2165. gcc_assert (targetm.use_by_pieces_infrastructure_p
  2166. (len, align,
  2167. memsetp
  2168. ? SET_BY_PIECES
  2169. : STORE_BY_PIECES,
  2170. optimize_insn_for_speed_p ()));
  2171. data.constfun = constfun;
  2172. data.constfundata = constfundata;
  2173. data.len = len;
  2174. data.to = to;
  2175. store_by_pieces_1 (&data, align);
  2176. if (endp)
  2177. {
  2178. rtx to1;
  2179. gcc_assert (!data.reverse);
  2180. if (data.autinc_to)
  2181. {
  2182. if (endp == 2)
  2183. {
  2184. if (HAVE_POST_INCREMENT && data.explicit_inc_to > 0)
  2185. emit_insn (gen_add2_insn (data.to_addr, constm1_rtx));
  2186. else
  2187. data.to_addr = copy_to_mode_reg (to_addr_mode,
  2188. plus_constant (to_addr_mode,
  2189. data.to_addr,
  2190. -1));
  2191. }
  2192. to1 = adjust_automodify_address (data.to, QImode, data.to_addr,
  2193. data.offset);
  2194. }
  2195. else
  2196. {
  2197. if (endp == 2)
  2198. --data.offset;
  2199. to1 = adjust_address (data.to, QImode, data.offset);
  2200. }
  2201. return to1;
  2202. }
  2203. else
  2204. return data.to;
  2205. }
  2206. /* Generate several move instructions to clear LEN bytes of block TO. (A MEM
  2207. rtx with BLKmode). ALIGN is maximum alignment we can assume. */
  2208. static void
  2209. clear_by_pieces (rtx to, unsigned HOST_WIDE_INT len, unsigned int align)
  2210. {
  2211. struct store_by_pieces_d data;
  2212. if (len == 0)
  2213. return;
  2214. data.constfun = clear_by_pieces_1;
  2215. data.constfundata = NULL;
  2216. data.len = len;
  2217. data.to = to;
  2218. store_by_pieces_1 (&data, align);
  2219. }
  2220. /* Callback routine for clear_by_pieces.
  2221. Return const0_rtx unconditionally. */
  2222. static rtx
  2223. clear_by_pieces_1 (void *data ATTRIBUTE_UNUSED,
  2224. HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
  2225. machine_mode mode ATTRIBUTE_UNUSED)
  2226. {
  2227. return const0_rtx;
  2228. }
  2229. /* Subroutine of clear_by_pieces and store_by_pieces.
  2230. Generate several move instructions to store LEN bytes of block TO. (A MEM
  2231. rtx with BLKmode). ALIGN is maximum alignment we can assume. */
  2232. static void
  2233. store_by_pieces_1 (struct store_by_pieces_d *data ATTRIBUTE_UNUSED,
  2234. unsigned int align ATTRIBUTE_UNUSED)
  2235. {
  2236. machine_mode to_addr_mode = get_address_mode (data->to);
  2237. rtx to_addr = XEXP (data->to, 0);
  2238. unsigned int max_size = STORE_MAX_PIECES + 1;
  2239. enum insn_code icode;
  2240. data->offset = 0;
  2241. data->to_addr = to_addr;
  2242. data->autinc_to
  2243. = (GET_CODE (to_addr) == PRE_INC || GET_CODE (to_addr) == PRE_DEC
  2244. || GET_CODE (to_addr) == POST_INC || GET_CODE (to_addr) == POST_DEC);
  2245. data->explicit_inc_to = 0;
  2246. data->reverse
  2247. = (GET_CODE (to_addr) == PRE_DEC || GET_CODE (to_addr) == POST_DEC);
  2248. if (data->reverse)
  2249. data->offset = data->len;
  2250. /* If storing requires more than two move insns,
  2251. copy addresses to registers (to make displacements shorter)
  2252. and use post-increment if available. */
  2253. if (!data->autinc_to
  2254. && move_by_pieces_ninsns (data->len, align, max_size) > 2)
  2255. {
  2256. /* Determine the main mode we'll be using.
  2257. MODE might not be used depending on the definitions of the
  2258. USE_* macros below. */
  2259. machine_mode mode ATTRIBUTE_UNUSED
  2260. = widest_int_mode_for_size (max_size);
  2261. if (USE_STORE_PRE_DECREMENT (mode) && data->reverse && ! data->autinc_to)
  2262. {
  2263. data->to_addr = copy_to_mode_reg (to_addr_mode,
  2264. plus_constant (to_addr_mode,
  2265. to_addr,
  2266. data->len));
  2267. data->autinc_to = 1;
  2268. data->explicit_inc_to = -1;
  2269. }
  2270. if (USE_STORE_POST_INCREMENT (mode) && ! data->reverse
  2271. && ! data->autinc_to)
  2272. {
  2273. data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
  2274. data->autinc_to = 1;
  2275. data->explicit_inc_to = 1;
  2276. }
  2277. if ( !data->autinc_to && CONSTANT_P (to_addr))
  2278. data->to_addr = copy_to_mode_reg (to_addr_mode, to_addr);
  2279. }
  2280. align = alignment_for_piecewise_move (STORE_MAX_PIECES, align);
  2281. /* First store what we can in the largest integer mode, then go to
  2282. successively smaller modes. */
  2283. while (max_size > 1 && data->len > 0)
  2284. {
  2285. machine_mode mode = widest_int_mode_for_size (max_size);
  2286. if (mode == VOIDmode)
  2287. break;
  2288. icode = optab_handler (mov_optab, mode);
  2289. if (icode != CODE_FOR_nothing && align >= GET_MODE_ALIGNMENT (mode))
  2290. store_by_pieces_2 (GEN_FCN (icode), mode, data);
  2291. max_size = GET_MODE_SIZE (mode);
  2292. }
  2293. /* The code above should have handled everything. */
  2294. gcc_assert (!data->len);
  2295. }
  2296. /* Subroutine of store_by_pieces_1. Store as many bytes as appropriate
  2297. with move instructions for mode MODE. GENFUN is the gen_... function
  2298. to make a move insn for that mode. DATA has all the other info. */
  2299. static void
  2300. store_by_pieces_2 (insn_gen_fn genfun, machine_mode mode,
  2301. struct store_by_pieces_d *data)
  2302. {
  2303. unsigned int size = GET_MODE_SIZE (mode);
  2304. rtx to1, cst;
  2305. while (data->len >= size)
  2306. {
  2307. if (data->reverse)
  2308. data->offset -= size;
  2309. if (data->autinc_to)
  2310. to1 = adjust_automodify_address (data->to, mode, data->to_addr,
  2311. data->offset);
  2312. else
  2313. to1 = adjust_address (data->to, mode, data->offset);
  2314. if (HAVE_PRE_DECREMENT && data->explicit_inc_to < 0)
  2315. emit_insn (gen_add2_insn (data->to_addr,
  2316. gen_int_mode (-(HOST_WIDE_INT) size,
  2317. GET_MODE (data->to_addr))));
  2318. cst = (*data->constfun) (data->constfundata, data->offset, mode);
  2319. emit_insn ((*genfun) (to1, cst));
  2320. if (HAVE_POST_INCREMENT && data->explicit_inc_to > 0)
  2321. emit_insn (gen_add2_insn (data->to_addr,
  2322. gen_int_mode (size,
  2323. GET_MODE (data->to_addr))));
  2324. if (! data->reverse)
  2325. data->offset += size;
  2326. data->len -= size;
  2327. }
  2328. }
  2329. /* Write zeros through the storage of OBJECT. If OBJECT has BLKmode, SIZE is
  2330. its length in bytes. */
  2331. rtx
  2332. clear_storage_hints (rtx object, rtx size, enum block_op_methods method,
  2333. unsigned int expected_align, HOST_WIDE_INT expected_size,
  2334. unsigned HOST_WIDE_INT min_size,
  2335. unsigned HOST_WIDE_INT max_size,
  2336. unsigned HOST_WIDE_INT probable_max_size)
  2337. {
  2338. machine_mode mode = GET_MODE (object);
  2339. unsigned int align;
  2340. gcc_assert (method == BLOCK_OP_NORMAL || method == BLOCK_OP_TAILCALL);
  2341. /* If OBJECT is not BLKmode and SIZE is the same size as its mode,
  2342. just move a zero. Otherwise, do this a piece at a time. */
  2343. if (mode != BLKmode
  2344. && CONST_INT_P (size)
  2345. && INTVAL (size) == (HOST_WIDE_INT) GET_MODE_SIZE (mode))
  2346. {
  2347. rtx zero = CONST0_RTX (mode);
  2348. if (zero != NULL)
  2349. {
  2350. emit_move_insn (object, zero);
  2351. return NULL;
  2352. }
  2353. if (COMPLEX_MODE_P (mode))
  2354. {
  2355. zero = CONST0_RTX (GET_MODE_INNER (mode));
  2356. if (zero != NULL)
  2357. {
  2358. write_complex_part (object, zero, 0);
  2359. write_complex_part (object, zero, 1);
  2360. return NULL;
  2361. }
  2362. }
  2363. }
  2364. if (size == const0_rtx)
  2365. return NULL;
  2366. align = MEM_ALIGN (object);
  2367. if (CONST_INT_P (size)
  2368. && targetm.use_by_pieces_infrastructure_p (INTVAL (size), align,
  2369. CLEAR_BY_PIECES,
  2370. optimize_insn_for_speed_p ()))
  2371. clear_by_pieces (object, INTVAL (size), align);
  2372. else if (set_storage_via_setmem (object, size, const0_rtx, align,
  2373. expected_align, expected_size,
  2374. min_size, max_size, probable_max_size))
  2375. ;
  2376. else if (ADDR_SPACE_GENERIC_P (MEM_ADDR_SPACE (object)))
  2377. return set_storage_via_libcall (object, size, const0_rtx,
  2378. method == BLOCK_OP_TAILCALL);
  2379. else
  2380. gcc_unreachable ();
  2381. return NULL;
  2382. }
  2383. rtx
  2384. clear_storage (rtx object, rtx size, enum block_op_methods method)
  2385. {
  2386. unsigned HOST_WIDE_INT max, min = 0;
  2387. if (GET_CODE (size) == CONST_INT)
  2388. min = max = UINTVAL (size);
  2389. else
  2390. max = GET_MODE_MASK (GET_MODE (size));
  2391. return clear_storage_hints (object, size, method, 0, -1, min, max, max);
  2392. }
  2393. /* A subroutine of clear_storage. Expand a call to memset.
  2394. Return the return value of memset, 0 otherwise. */
  2395. rtx
  2396. set_storage_via_libcall (rtx object, rtx size, rtx val, bool tailcall)
  2397. {
  2398. tree call_expr, fn, object_tree, size_tree, val_tree;
  2399. machine_mode size_mode;
  2400. rtx retval;
  2401. /* Emit code to copy OBJECT and SIZE into new pseudos. We can then
  2402. place those into new pseudos into a VAR_DECL and use them later. */
  2403. object = copy_addr_to_reg (XEXP (object, 0));
  2404. size_mode = TYPE_MODE (sizetype);
  2405. size = convert_to_mode (size_mode, size, 1);
  2406. size = copy_to_mode_reg (size_mode, size);
  2407. /* It is incorrect to use the libcall calling conventions to call
  2408. memset in this context. This could be a user call to memset and
  2409. the user may wish to examine the return value from memset. For
  2410. targets where libcalls and normal calls have different conventions
  2411. for returning pointers, we could end up generating incorrect code. */
  2412. object_tree = make_tree (ptr_type_node, object);
  2413. if (!CONST_INT_P (val))
  2414. val = convert_to_mode (TYPE_MODE (integer_type_node), val, 1);
  2415. size_tree = make_tree (sizetype, size);
  2416. val_tree = make_tree (integer_type_node, val);
  2417. fn = clear_storage_libcall_fn (true);
  2418. call_expr = build_call_expr (fn, 3, object_tree, val_tree, size_tree);
  2419. CALL_EXPR_TAILCALL (call_expr) = tailcall;
  2420. retval = expand_normal (call_expr);
  2421. return retval;
  2422. }
  2423. /* A subroutine of set_storage_via_libcall. Create the tree node
  2424. for the function we use for block clears. */
  2425. tree block_clear_fn;
  2426. void
  2427. init_block_clear_fn (const char *asmspec)
  2428. {
  2429. if (!block_clear_fn)
  2430. {
  2431. tree fn, args;
  2432. fn = get_identifier ("memset");
  2433. args = build_function_type_list (ptr_type_node, ptr_type_node,
  2434. integer_type_node, sizetype,
  2435. NULL_TREE);
  2436. fn = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL, fn, args);
  2437. DECL_EXTERNAL (fn) = 1;
  2438. TREE_PUBLIC (fn) = 1;
  2439. DECL_ARTIFICIAL (fn) = 1;
  2440. TREE_NOTHROW (fn) = 1;
  2441. DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
  2442. DECL_VISIBILITY_SPECIFIED (fn) = 1;
  2443. block_clear_fn = fn;
  2444. }
  2445. if (asmspec)
  2446. set_user_assembler_name (block_clear_fn, asmspec);
  2447. }
  2448. static tree
  2449. clear_storage_libcall_fn (int for_call)
  2450. {
  2451. static bool emitted_extern;
  2452. if (!block_clear_fn)
  2453. init_block_clear_fn (NULL);
  2454. if (for_call && !emitted_extern)
  2455. {
  2456. emitted_extern = true;
  2457. make_decl_rtl (block_clear_fn);
  2458. }
  2459. return block_clear_fn;
  2460. }
  2461. /* Expand a setmem pattern; return true if successful. */
  2462. bool
  2463. set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int align,
  2464. unsigned int expected_align, HOST_WIDE_INT expected_size,
  2465. unsigned HOST_WIDE_INT min_size,
  2466. unsigned HOST_WIDE_INT max_size,
  2467. unsigned HOST_WIDE_INT probable_max_size)
  2468. {
  2469. /* Try the most limited insn first, because there's no point
  2470. including more than one in the machine description unless
  2471. the more limited one has some advantage. */
  2472. machine_mode mode;
  2473. if (expected_align < align)
  2474. expected_align = align;
  2475. if (expected_size != -1)
  2476. {
  2477. if ((unsigned HOST_WIDE_INT)expected_size > max_size)
  2478. expected_size = max_size;
  2479. if ((unsigned HOST_WIDE_INT)expected_size < min_size)
  2480. expected_size = min_size;
  2481. }
  2482. for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
  2483. mode = GET_MODE_WIDER_MODE (mode))
  2484. {
  2485. enum insn_code code = direct_optab_handler (setmem_optab, mode);
  2486. if (code != CODE_FOR_nothing
  2487. /* We don't need MODE to be narrower than BITS_PER_HOST_WIDE_INT
  2488. here because if SIZE is less than the mode mask, as it is
  2489. returned by the macro, it will definitely be less than the
  2490. actual mode mask. Since SIZE is within the Pmode address
  2491. space, we limit MODE to Pmode. */
  2492. && ((CONST_INT_P (size)
  2493. && ((unsigned HOST_WIDE_INT) INTVAL (size)
  2494. <= (GET_MODE_MASK (mode) >> 1)))
  2495. || max_size <= (GET_MODE_MASK (mode) >> 1)
  2496. || GET_MODE_BITSIZE (mode) >= GET_MODE_BITSIZE (Pmode)))
  2497. {
  2498. struct expand_operand ops[9];
  2499. unsigned int nops;
  2500. nops = insn_data[(int) code].n_generator_args;
  2501. gcc_assert (nops == 4 || nops == 6 || nops == 8 || nops == 9);
  2502. create_fixed_operand (&ops[0], object);
  2503. /* The check above guarantees that this size conversion is valid. */
  2504. create_convert_operand_to (&ops[1], size, mode, true);
  2505. create_convert_operand_from (&ops[2], val, byte_mode, true);
  2506. create_integer_operand (&ops[3], align / BITS_PER_UNIT);
  2507. if (nops >= 6)
  2508. {
  2509. create_integer_operand (&ops[4], expected_align / BITS_PER_UNIT);
  2510. create_integer_operand (&ops[5], expected_size);
  2511. }
  2512. if (nops >= 8)
  2513. {
  2514. create_integer_operand (&ops[6], min_size);
  2515. /* If we can not represent the maximal size,
  2516. make parameter NULL. */
  2517. if ((HOST_WIDE_INT) max_size != -1)
  2518. create_integer_operand (&ops[7], max_size);
  2519. else
  2520. create_fixed_operand (&ops[7], NULL);
  2521. }
  2522. if (nops == 9)
  2523. {
  2524. /* If we can not represent the maximal size,
  2525. make parameter NULL. */
  2526. if ((HOST_WIDE_INT) probable_max_size != -1)
  2527. create_integer_operand (&ops[8], probable_max_size);
  2528. else
  2529. create_fixed_operand (&ops[8], NULL);
  2530. }
  2531. if (maybe_expand_insn (code, nops, ops))
  2532. return true;
  2533. }
  2534. }
  2535. return false;
  2536. }
  2537. /* Write to one of the components of the complex value CPLX. Write VAL to
  2538. the real part if IMAG_P is false, and the imaginary part if its true. */
  2539. void
  2540. write_complex_part (rtx cplx, rtx val, bool imag_p)
  2541. {
  2542. machine_mode cmode;
  2543. machine_mode imode;
  2544. unsigned ibitsize;
  2545. if (GET_CODE (cplx) == CONCAT)
  2546. {
  2547. emit_move_insn (XEXP (cplx, imag_p), val);
  2548. return;
  2549. }
  2550. cmode = GET_MODE (cplx);
  2551. imode = GET_MODE_INNER (cmode);
  2552. ibitsize = GET_MODE_BITSIZE (imode);
  2553. /* For MEMs simplify_gen_subreg may generate an invalid new address
  2554. because, e.g., the original address is considered mode-dependent
  2555. by the target, which restricts simplify_subreg from invoking
  2556. adjust_address_nv. Instead of preparing fallback support for an
  2557. invalid address, we call adjust_address_nv directly. */
  2558. if (MEM_P (cplx))
  2559. {
  2560. emit_move_insn (adjust_address_nv (cplx, imode,
  2561. imag_p ? GET_MODE_SIZE (imode) : 0),
  2562. val);
  2563. return;
  2564. }
  2565. /* If the sub-object is at least word sized, then we know that subregging
  2566. will work. This special case is important, since store_bit_field
  2567. wants to operate on integer modes, and there's rarely an OImode to
  2568. correspond to TCmode. */
  2569. if (ibitsize >= BITS_PER_WORD
  2570. /* For hard regs we have exact predicates. Assume we can split
  2571. the original object if it spans an even number of hard regs.
  2572. This special case is important for SCmode on 64-bit platforms
  2573. where the natural size of floating-point regs is 32-bit. */
  2574. || (REG_P (cplx)
  2575. && REGNO (cplx) < FIRST_PSEUDO_REGISTER
  2576. && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
  2577. {
  2578. rtx part = simplify_gen_subreg (imode, cplx, cmode,
  2579. imag_p ? GET_MODE_SIZE (imode) : 0);
  2580. if (part)
  2581. {
  2582. emit_move_insn (part, val);
  2583. return;
  2584. }
  2585. else
  2586. /* simplify_gen_subreg may fail for sub-word MEMs. */
  2587. gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
  2588. }
  2589. store_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0, 0, 0, imode, val);
  2590. }
  2591. /* Extract one of the components of the complex value CPLX. Extract the
  2592. real part if IMAG_P is false, and the imaginary part if it's true. */
  2593. static rtx
  2594. read_complex_part (rtx cplx, bool imag_p)
  2595. {
  2596. machine_mode cmode, imode;
  2597. unsigned ibitsize;
  2598. if (GET_CODE (cplx) == CONCAT)
  2599. return XEXP (cplx, imag_p);
  2600. cmode = GET_MODE (cplx);
  2601. imode = GET_MODE_INNER (cmode);
  2602. ibitsize = GET_MODE_BITSIZE (imode);
  2603. /* Special case reads from complex constants that got spilled to memory. */
  2604. if (MEM_P (cplx) && GET_CODE (XEXP (cplx, 0)) == SYMBOL_REF)
  2605. {
  2606. tree decl = SYMBOL_REF_DECL (XEXP (cplx, 0));
  2607. if (decl && TREE_CODE (decl) == COMPLEX_CST)
  2608. {
  2609. tree part = imag_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
  2610. if (CONSTANT_CLASS_P (part))
  2611. return expand_expr (part, NULL_RTX, imode, EXPAND_NORMAL);
  2612. }
  2613. }
  2614. /* For MEMs simplify_gen_subreg may generate an invalid new address
  2615. because, e.g., the original address is considered mode-dependent
  2616. by the target, which restricts simplify_subreg from invoking
  2617. adjust_address_nv. Instead of preparing fallback support for an
  2618. invalid address, we call adjust_address_nv directly. */
  2619. if (MEM_P (cplx))
  2620. return adjust_address_nv (cplx, imode,
  2621. imag_p ? GET_MODE_SIZE (imode) : 0);
  2622. /* If the sub-object is at least word sized, then we know that subregging
  2623. will work. This special case is important, since extract_bit_field
  2624. wants to operate on integer modes, and there's rarely an OImode to
  2625. correspond to TCmode. */
  2626. if (ibitsize >= BITS_PER_WORD
  2627. /* For hard regs we have exact predicates. Assume we can split
  2628. the original object if it spans an even number of hard regs.
  2629. This special case is important for SCmode on 64-bit platforms
  2630. where the natural size of floating-point regs is 32-bit. */
  2631. || (REG_P (cplx)
  2632. && REGNO (cplx) < FIRST_PSEUDO_REGISTER
  2633. && hard_regno_nregs[REGNO (cplx)][cmode] % 2 == 0))
  2634. {
  2635. rtx ret = simplify_gen_subreg (imode, cplx, cmode,
  2636. imag_p ? GET_MODE_SIZE (imode) : 0);
  2637. if (ret)
  2638. return ret;
  2639. else
  2640. /* simplify_gen_subreg may fail for sub-word MEMs. */
  2641. gcc_assert (MEM_P (cplx) && ibitsize < BITS_PER_WORD);
  2642. }
  2643. return extract_bit_field (cplx, ibitsize, imag_p ? ibitsize : 0,
  2644. true, NULL_RTX, imode, imode);
  2645. }
  2646. /* A subroutine of emit_move_insn_1. Yet another lowpart generator.
  2647. NEW_MODE and OLD_MODE are the same size. Return NULL if X cannot be
  2648. represented in NEW_MODE. If FORCE is true, this will never happen, as
  2649. we'll force-create a SUBREG if needed. */
  2650. static rtx
  2651. emit_move_change_mode (machine_mode new_mode,
  2652. machine_mode old_mode, rtx x, bool force)
  2653. {
  2654. rtx ret;
  2655. if (push_operand (x, GET_MODE (x)))
  2656. {
  2657. ret = gen_rtx_MEM (new_mode, XEXP (x, 0));
  2658. MEM_COPY_ATTRIBUTES (ret, x);
  2659. }
  2660. else if (MEM_P (x))
  2661. {
  2662. /* We don't have to worry about changing the address since the
  2663. size in bytes is supposed to be the same. */
  2664. if (reload_in_progress)
  2665. {
  2666. /* Copy the MEM to change the mode and move any
  2667. substitutions from the old MEM to the new one. */
  2668. ret = adjust_address_nv (x, new_mode, 0);
  2669. copy_replacements (x, ret);
  2670. }
  2671. else
  2672. ret = adjust_address (x, new_mode, 0);
  2673. }
  2674. else
  2675. {
  2676. /* Note that we do want simplify_subreg's behavior of validating
  2677. that the new mode is ok for a hard register. If we were to use
  2678. simplify_gen_subreg, we would create the subreg, but would
  2679. probably run into the target not being able to implement it. */
  2680. /* Except, of course, when FORCE is true, when this is exactly what
  2681. we want. Which is needed for CCmodes on some targets. */
  2682. if (force)
  2683. ret = simplify_gen_subreg (new_mode, x, old_mode, 0);
  2684. else
  2685. ret = simplify_subreg (new_mode, x, old_mode, 0);
  2686. }
  2687. return ret;
  2688. }
  2689. /* A subroutine of emit_move_insn_1. Generate a move from Y into X using
  2690. an integer mode of the same size as MODE. Returns the instruction
  2691. emitted, or NULL if such a move could not be generated. */
  2692. static rtx_insn *
  2693. emit_move_via_integer (machine_mode mode, rtx x, rtx y, bool force)
  2694. {
  2695. machine_mode imode;
  2696. enum insn_code code;
  2697. /* There must exist a mode of the exact size we require. */
  2698. imode = int_mode_for_mode (mode);
  2699. if (imode == BLKmode)
  2700. return NULL;
  2701. /* The target must support moves in this mode. */
  2702. code = optab_handler (mov_optab, imode);
  2703. if (code == CODE_FOR_nothing)
  2704. return NULL;
  2705. x = emit_move_change_mode (imode, mode, x, force);
  2706. if (x == NULL_RTX)
  2707. return NULL;
  2708. y = emit_move_change_mode (imode, mode, y, force);
  2709. if (y == NULL_RTX)
  2710. return NULL;
  2711. return emit_insn (GEN_FCN (code) (x, y));
  2712. }
  2713. /* A subroutine of emit_move_insn_1. X is a push_operand in MODE.
  2714. Return an equivalent MEM that does not use an auto-increment. */
  2715. rtx
  2716. emit_move_resolve_push (machine_mode mode, rtx x)
  2717. {
  2718. enum rtx_code code = GET_CODE (XEXP (x, 0));
  2719. HOST_WIDE_INT adjust;
  2720. rtx temp;
  2721. adjust = GET_MODE_SIZE (mode);
  2722. #ifdef PUSH_ROUNDING
  2723. adjust = PUSH_ROUNDING (adjust);
  2724. #endif
  2725. if (code == PRE_DEC || code == POST_DEC)
  2726. adjust = -adjust;
  2727. else if (code == PRE_MODIFY || code == POST_MODIFY)
  2728. {
  2729. rtx expr = XEXP (XEXP (x, 0), 1);
  2730. HOST_WIDE_INT val;
  2731. gcc_assert (GET_CODE (expr) == PLUS || GET_CODE (expr) == MINUS);
  2732. gcc_assert (CONST_INT_P (XEXP (expr, 1)));
  2733. val = INTVAL (XEXP (expr, 1));
  2734. if (GET_CODE (expr) == MINUS)
  2735. val = -val;
  2736. gcc_assert (adjust == val || adjust == -val);
  2737. adjust = val;
  2738. }
  2739. /* Do not use anti_adjust_stack, since we don't want to update
  2740. stack_pointer_delta. */
  2741. temp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
  2742. gen_int_mode (adjust, Pmode), stack_pointer_rtx,
  2743. 0, OPTAB_LIB_WIDEN);
  2744. if (temp != stack_pointer_rtx)
  2745. emit_move_insn (stack_pointer_rtx, temp);
  2746. switch (code)
  2747. {
  2748. case PRE_INC:
  2749. case PRE_DEC:
  2750. case PRE_MODIFY:
  2751. temp = stack_pointer_rtx;
  2752. break;
  2753. case POST_INC:
  2754. case POST_DEC:
  2755. case POST_MODIFY:
  2756. temp = plus_constant (Pmode, stack_pointer_rtx, -adjust);
  2757. break;
  2758. default:
  2759. gcc_unreachable ();
  2760. }
  2761. return replace_equiv_address (x, temp);
  2762. }
  2763. /* A subroutine of emit_move_complex. Generate a move from Y into X.
  2764. X is known to satisfy push_operand, and MODE is known to be complex.
  2765. Returns the last instruction emitted. */
  2766. rtx_insn *
  2767. emit_move_complex_push (machine_mode mode, rtx x, rtx y)
  2768. {
  2769. machine_mode submode = GET_MODE_INNER (mode);
  2770. bool imag_first;
  2771. #ifdef PUSH_ROUNDING
  2772. unsigned int submodesize = GET_MODE_SIZE (submode);
  2773. /* In case we output to the stack, but the size is smaller than the
  2774. machine can push exactly, we need to use move instructions. */
  2775. if (PUSH_ROUNDING (submodesize) != submodesize)
  2776. {
  2777. x = emit_move_resolve_push (mode, x);
  2778. return emit_move_insn (x, y);
  2779. }
  2780. #endif
  2781. /* Note that the real part always precedes the imag part in memory
  2782. regardless of machine's endianness. */
  2783. switch (GET_CODE (XEXP (x, 0)))
  2784. {
  2785. case PRE_DEC:
  2786. case POST_DEC:
  2787. imag_first = true;
  2788. break;
  2789. case PRE_INC:
  2790. case POST_INC:
  2791. imag_first = false;
  2792. break;
  2793. default:
  2794. gcc_unreachable ();
  2795. }
  2796. emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
  2797. read_complex_part (y, imag_first));
  2798. return emit_move_insn (gen_rtx_MEM (submode, XEXP (x, 0)),
  2799. read_complex_part (y, !imag_first));
  2800. }
  2801. /* A subroutine of emit_move_complex. Perform the move from Y to X
  2802. via two moves of the parts. Returns the last instruction emitted. */
  2803. rtx_insn *
  2804. emit_move_complex_parts (rtx x, rtx y)
  2805. {
  2806. /* Show the output dies here. This is necessary for SUBREGs
  2807. of pseudos since we cannot track their lifetimes correctly;
  2808. hard regs shouldn't appear here except as return values. */
  2809. if (!reload_completed && !reload_in_progress
  2810. && REG_P (x) && !reg_overlap_mentioned_p (x, y))
  2811. emit_clobber (x);
  2812. write_complex_part (x, read_complex_part (y, false), false);
  2813. write_complex_part (x, read_complex_part (y, true), true);
  2814. return get_last_insn ();
  2815. }
  2816. /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
  2817. MODE is known to be complex. Returns the last instruction emitted. */
  2818. static rtx_insn *
  2819. emit_move_complex (machine_mode mode, rtx x, rtx y)
  2820. {
  2821. bool try_int;
  2822. /* Need to take special care for pushes, to maintain proper ordering
  2823. of the data, and possibly extra padding. */
  2824. if (push_operand (x, mode))
  2825. return emit_move_complex_push (mode, x, y);
  2826. /* See if we can coerce the target into moving both values at once, except
  2827. for floating point where we favor moving as parts if this is easy. */
  2828. if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
  2829. && optab_handler (mov_optab, GET_MODE_INNER (mode)) != CODE_FOR_nothing
  2830. && !(REG_P (x)
  2831. && HARD_REGISTER_P (x)
  2832. && hard_regno_nregs[REGNO (x)][mode] == 1)
  2833. && !(REG_P (y)
  2834. && HARD_REGISTER_P (y)
  2835. && hard_regno_nregs[REGNO (y)][mode] == 1))
  2836. try_int = false;
  2837. /* Not possible if the values are inherently not adjacent. */
  2838. else if (GET_CODE (x) == CONCAT || GET_CODE (y) == CONCAT)
  2839. try_int = false;
  2840. /* Is possible if both are registers (or subregs of registers). */
  2841. else if (register_operand (x, mode) && register_operand (y, mode))
  2842. try_int = true;
  2843. /* If one of the operands is a memory, and alignment constraints
  2844. are friendly enough, we may be able to do combined memory operations.
  2845. We do not attempt this if Y is a constant because that combination is
  2846. usually better with the by-parts thing below. */
  2847. else if ((MEM_P (x) ? !CONSTANT_P (y) : MEM_P (y))
  2848. && (!STRICT_ALIGNMENT
  2849. || get_mode_alignment (mode) == BIGGEST_ALIGNMENT))
  2850. try_int = true;
  2851. else
  2852. try_int = false;
  2853. if (try_int)
  2854. {
  2855. rtx_insn *ret;
  2856. /* For memory to memory moves, optimal behavior can be had with the
  2857. existing block move logic. */
  2858. if (MEM_P (x) && MEM_P (y))
  2859. {
  2860. emit_block_move (x, y, GEN_INT (GET_MODE_SIZE (mode)),
  2861. BLOCK_OP_NO_LIBCALL);
  2862. return get_last_insn ();
  2863. }
  2864. ret = emit_move_via_integer (mode, x, y, true);
  2865. if (ret)
  2866. return ret;
  2867. }
  2868. return emit_move_complex_parts (x, y);
  2869. }
  2870. /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
  2871. MODE is known to be MODE_CC. Returns the last instruction emitted. */
  2872. static rtx_insn *
  2873. emit_move_ccmode (machine_mode mode, rtx x, rtx y)
  2874. {
  2875. rtx_insn *ret;
  2876. /* Assume all MODE_CC modes are equivalent; if we have movcc, use it. */
  2877. if (mode != CCmode)
  2878. {
  2879. enum insn_code code = optab_handler (mov_optab, CCmode);
  2880. if (code != CODE_FOR_nothing)
  2881. {
  2882. x = emit_move_change_mode (CCmode, mode, x, true);
  2883. y = emit_move_change_mode (CCmode, mode, y, true);
  2884. return emit_insn (GEN_FCN (code) (x, y));
  2885. }
  2886. }
  2887. /* Otherwise, find the MODE_INT mode of the same width. */
  2888. ret = emit_move_via_integer (mode, x, y, false);
  2889. gcc_assert (ret != NULL);
  2890. return ret;
  2891. }
  2892. /* Return true if word I of OP lies entirely in the
  2893. undefined bits of a paradoxical subreg. */
  2894. static bool
  2895. undefined_operand_subword_p (const_rtx op, int i)
  2896. {
  2897. machine_mode innermode, innermostmode;
  2898. int offset;
  2899. if (GET_CODE (op) != SUBREG)
  2900. return false;
  2901. innermode = GET_MODE (op);
  2902. innermostmode = GET_MODE (SUBREG_REG (op));
  2903. offset = i * UNITS_PER_WORD + SUBREG_BYTE (op);
  2904. /* The SUBREG_BYTE represents offset, as if the value were stored in
  2905. memory, except for a paradoxical subreg where we define
  2906. SUBREG_BYTE to be 0; undo this exception as in
  2907. simplify_subreg. */
  2908. if (SUBREG_BYTE (op) == 0
  2909. && GET_MODE_SIZE (innermostmode) < GET_MODE_SIZE (innermode))
  2910. {
  2911. int difference = (GET_MODE_SIZE (innermostmode) - GET_MODE_SIZE (innermode));
  2912. if (WORDS_BIG_ENDIAN)
  2913. offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
  2914. if (BYTES_BIG_ENDIAN)
  2915. offset += difference % UNITS_PER_WORD;
  2916. }
  2917. if (offset >= GET_MODE_SIZE (innermostmode)
  2918. || offset <= -GET_MODE_SIZE (word_mode))
  2919. return true;
  2920. return false;
  2921. }
  2922. /* A subroutine of emit_move_insn_1. Generate a move from Y into X.
  2923. MODE is any multi-word or full-word mode that lacks a move_insn
  2924. pattern. Note that you will get better code if you define such
  2925. patterns, even if they must turn into multiple assembler instructions. */
  2926. static rtx_insn *
  2927. emit_move_multi_word (machine_mode mode, rtx x, rtx y)
  2928. {
  2929. rtx_insn *last_insn = 0;
  2930. rtx_insn *seq;
  2931. rtx inner;
  2932. bool need_clobber;
  2933. int i;
  2934. gcc_assert (GET_MODE_SIZE (mode) >= UNITS_PER_WORD);
  2935. /* If X is a push on the stack, do the push now and replace
  2936. X with a reference to the stack pointer. */
  2937. if (push_operand (x, mode))
  2938. x = emit_move_resolve_push (mode, x);
  2939. /* If we are in reload, see if either operand is a MEM whose address
  2940. is scheduled for replacement. */
  2941. if (reload_in_progress && MEM_P (x)
  2942. && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
  2943. x = replace_equiv_address_nv (x, inner);
  2944. if (reload_in_progress && MEM_P (y)
  2945. && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
  2946. y = replace_equiv_address_nv (y, inner);
  2947. start_sequence ();
  2948. need_clobber = false;
  2949. for (i = 0;
  2950. i < (GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD;
  2951. i++)
  2952. {
  2953. rtx xpart = operand_subword (x, i, 1, mode);
  2954. rtx ypart;
  2955. /* Do not generate code for a move if it would come entirely
  2956. from the undefined bits of a paradoxical subreg. */
  2957. if (undefined_operand_subword_p (y, i))
  2958. continue;
  2959. ypart = operand_subword (y, i, 1, mode);
  2960. /* If we can't get a part of Y, put Y into memory if it is a
  2961. constant. Otherwise, force it into a register. Then we must
  2962. be able to get a part of Y. */
  2963. if (ypart == 0 && CONSTANT_P (y))
  2964. {
  2965. y = use_anchored_address (force_const_mem (mode, y));
  2966. ypart = operand_subword (y, i, 1, mode);
  2967. }
  2968. else if (ypart == 0)
  2969. ypart = operand_subword_force (y, i, mode);
  2970. gcc_assert (xpart && ypart);
  2971. need_clobber |= (GET_CODE (xpart) == SUBREG);
  2972. last_insn = emit_move_insn (xpart, ypart);
  2973. }
  2974. seq = get_insns ();
  2975. end_sequence ();
  2976. /* Show the output dies here. This is necessary for SUBREGs
  2977. of pseudos since we cannot track their lifetimes correctly;
  2978. hard regs shouldn't appear here except as return values.
  2979. We never want to emit such a clobber after reload. */
  2980. if (x != y
  2981. && ! (reload_in_progress || reload_completed)
  2982. && need_clobber != 0)
  2983. emit_clobber (x);
  2984. emit_insn (seq);
  2985. return last_insn;
  2986. }
  2987. /* Low level part of emit_move_insn.
  2988. Called just like emit_move_insn, but assumes X and Y
  2989. are basically valid. */
  2990. rtx_insn *
  2991. emit_move_insn_1 (rtx x, rtx y)
  2992. {
  2993. machine_mode mode = GET_MODE (x);
  2994. enum insn_code code;
  2995. gcc_assert ((unsigned int) mode < (unsigned int) MAX_MACHINE_MODE);
  2996. code = optab_handler (mov_optab, mode);
  2997. if (code != CODE_FOR_nothing)
  2998. return emit_insn (GEN_FCN (code) (x, y));
  2999. /* Expand complex moves by moving real part and imag part. */
  3000. if (COMPLEX_MODE_P (mode))
  3001. return emit_move_complex (mode, x, y);
  3002. if (GET_MODE_CLASS (mode) == MODE_DECIMAL_FLOAT
  3003. || ALL_FIXED_POINT_MODE_P (mode))
  3004. {
  3005. rtx_insn *result = emit_move_via_integer (mode, x, y, true);
  3006. /* If we can't find an integer mode, use multi words. */
  3007. if (result)
  3008. return result;
  3009. else
  3010. return emit_move_multi_word (mode, x, y);
  3011. }
  3012. if (GET_MODE_CLASS (mode) == MODE_CC)
  3013. return emit_move_ccmode (mode, x, y);
  3014. /* Try using a move pattern for the corresponding integer mode. This is
  3015. only safe when simplify_subreg can convert MODE constants into integer
  3016. constants. At present, it can only do this reliably if the value
  3017. fits within a HOST_WIDE_INT. */
  3018. if (!CONSTANT_P (y) || GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
  3019. {
  3020. rtx_insn *ret = emit_move_via_integer (mode, x, y, lra_in_progress);
  3021. if (ret)
  3022. {
  3023. if (! lra_in_progress || recog (PATTERN (ret), ret, 0) >= 0)
  3024. return ret;
  3025. }
  3026. }
  3027. return emit_move_multi_word (mode, x, y);
  3028. }
  3029. /* Generate code to copy Y into X.
  3030. Both Y and X must have the same mode, except that
  3031. Y can be a constant with VOIDmode.
  3032. This mode cannot be BLKmode; use emit_block_move for that.
  3033. Return the last instruction emitted. */
  3034. rtx_insn *
  3035. emit_move_insn (rtx x, rtx y)
  3036. {
  3037. machine_mode mode = GET_MODE (x);
  3038. rtx y_cst = NULL_RTX;
  3039. rtx_insn *last_insn;
  3040. rtx set;
  3041. gcc_assert (mode != BLKmode
  3042. && (GET_MODE (y) == mode || GET_MODE (y) == VOIDmode));
  3043. if (CONSTANT_P (y))
  3044. {
  3045. if (optimize
  3046. && SCALAR_FLOAT_MODE_P (GET_MODE (x))
  3047. && (last_insn = compress_float_constant (x, y)))
  3048. return last_insn;
  3049. y_cst = y;
  3050. if (!targetm.legitimate_constant_p (mode, y))
  3051. {
  3052. y = force_const_mem (mode, y);
  3053. /* If the target's cannot_force_const_mem prevented the spill,
  3054. assume that the target's move expanders will also take care
  3055. of the non-legitimate constant. */
  3056. if (!y)
  3057. y = y_cst;
  3058. else
  3059. y = use_anchored_address (y);
  3060. }
  3061. }
  3062. /* If X or Y are memory references, verify that their addresses are valid
  3063. for the machine. */
  3064. if (MEM_P (x)
  3065. && (! memory_address_addr_space_p (GET_MODE (x), XEXP (x, 0),
  3066. MEM_ADDR_SPACE (x))
  3067. && ! push_operand (x, GET_MODE (x))))
  3068. x = validize_mem (x);
  3069. if (MEM_P (y)
  3070. && ! memory_address_addr_space_p (GET_MODE (y), XEXP (y, 0),
  3071. MEM_ADDR_SPACE (y)))
  3072. y = validize_mem (y);
  3073. gcc_assert (mode != BLKmode);
  3074. last_insn = emit_move_insn_1 (x, y);
  3075. if (y_cst && REG_P (x)
  3076. && (set = single_set (last_insn)) != NULL_RTX
  3077. && SET_DEST (set) == x
  3078. && ! rtx_equal_p (y_cst, SET_SRC (set)))
  3079. set_unique_reg_note (last_insn, REG_EQUAL, copy_rtx (y_cst));
  3080. return last_insn;
  3081. }
  3082. /* Generate the body of an instruction to copy Y into X.
  3083. It may be a list of insns, if one insn isn't enough. */
  3084. rtx
  3085. gen_move_insn (rtx x, rtx y)
  3086. {
  3087. rtx_insn *seq;
  3088. start_sequence ();
  3089. emit_move_insn_1 (x, y);
  3090. seq = get_insns ();
  3091. end_sequence ();
  3092. return seq;
  3093. }
  3094. /* If Y is representable exactly in a narrower mode, and the target can
  3095. perform the extension directly from constant or memory, then emit the
  3096. move as an extension. */
  3097. static rtx_insn *
  3098. compress_float_constant (rtx x, rtx y)
  3099. {
  3100. machine_mode dstmode = GET_MODE (x);
  3101. machine_mode orig_srcmode = GET_MODE (y);
  3102. machine_mode srcmode;
  3103. REAL_VALUE_TYPE r;
  3104. int oldcost, newcost;
  3105. bool speed = optimize_insn_for_speed_p ();
  3106. REAL_VALUE_FROM_CONST_DOUBLE (r, y);
  3107. if (targetm.legitimate_constant_p (dstmode, y))
  3108. oldcost = set_src_cost (y, speed);
  3109. else
  3110. oldcost = set_src_cost (force_const_mem (dstmode, y), speed);
  3111. for (srcmode = GET_CLASS_NARROWEST_MODE (GET_MODE_CLASS (orig_srcmode));
  3112. srcmode != orig_srcmode;
  3113. srcmode = GET_MODE_WIDER_MODE (srcmode))
  3114. {
  3115. enum insn_code ic;
  3116. rtx trunc_y;
  3117. rtx_insn *last_insn;
  3118. /* Skip if the target can't extend this way. */
  3119. ic = can_extend_p (dstmode, srcmode, 0);
  3120. if (ic == CODE_FOR_nothing)
  3121. continue;
  3122. /* Skip if the narrowed value isn't exact. */
  3123. if (! exact_real_truncate (srcmode, &r))
  3124. continue;
  3125. trunc_y = CONST_DOUBLE_FROM_REAL_VALUE (r, srcmode);
  3126. if (targetm.legitimate_constant_p (srcmode, trunc_y))
  3127. {
  3128. /* Skip if the target needs extra instructions to perform
  3129. the extension. */
  3130. if (!insn_operand_matches (ic, 1, trunc_y))
  3131. continue;
  3132. /* This is valid, but may not be cheaper than the original. */
  3133. newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
  3134. speed);
  3135. if (oldcost < newcost)
  3136. continue;
  3137. }
  3138. else if (float_extend_from_mem[dstmode][srcmode])
  3139. {
  3140. trunc_y = force_const_mem (srcmode, trunc_y);
  3141. /* This is valid, but may not be cheaper than the original. */
  3142. newcost = set_src_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y),
  3143. speed);
  3144. if (oldcost < newcost)
  3145. continue;
  3146. trunc_y = validize_mem (trunc_y);
  3147. }
  3148. else
  3149. continue;
  3150. /* For CSE's benefit, force the compressed constant pool entry
  3151. into a new pseudo. This constant may be used in different modes,
  3152. and if not, combine will put things back together for us. */
  3153. trunc_y = force_reg (srcmode, trunc_y);
  3154. /* If x is a hard register, perform the extension into a pseudo,
  3155. so that e.g. stack realignment code is aware of it. */
  3156. rtx target = x;
  3157. if (REG_P (x) && HARD_REGISTER_P (x))
  3158. target = gen_reg_rtx (dstmode);
  3159. emit_unop_insn (ic, target, trunc_y, UNKNOWN);
  3160. last_insn = get_last_insn ();
  3161. if (REG_P (target))
  3162. set_unique_reg_note (last_insn, REG_EQUAL, y);
  3163. if (target != x)
  3164. return emit_move_insn (x, target);
  3165. return last_insn;
  3166. }
  3167. return NULL;
  3168. }
  3169. /* Pushing data onto the stack. */
  3170. /* Push a block of length SIZE (perhaps variable)
  3171. and return an rtx to address the beginning of the block.
  3172. The value may be virtual_outgoing_args_rtx.
  3173. EXTRA is the number of bytes of padding to push in addition to SIZE.
  3174. BELOW nonzero means this padding comes at low addresses;
  3175. otherwise, the padding comes at high addresses. */
  3176. rtx
  3177. push_block (rtx size, int extra, int below)
  3178. {
  3179. rtx temp;
  3180. size = convert_modes (Pmode, ptr_mode, size, 1);
  3181. if (CONSTANT_P (size))
  3182. anti_adjust_stack (plus_constant (Pmode, size, extra));
  3183. else if (REG_P (size) && extra == 0)
  3184. anti_adjust_stack (size);
  3185. else
  3186. {
  3187. temp = copy_to_mode_reg (Pmode, size);
  3188. if (extra != 0)
  3189. temp = expand_binop (Pmode, add_optab, temp,
  3190. gen_int_mode (extra, Pmode),
  3191. temp, 0, OPTAB_LIB_WIDEN);
  3192. anti_adjust_stack (temp);
  3193. }
  3194. #ifndef STACK_GROWS_DOWNWARD
  3195. if (0)
  3196. #else
  3197. if (1)
  3198. #endif
  3199. {
  3200. temp = virtual_outgoing_args_rtx;
  3201. if (extra != 0 && below)
  3202. temp = plus_constant (Pmode, temp, extra);
  3203. }
  3204. else
  3205. {
  3206. if (CONST_INT_P (size))
  3207. temp = plus_constant (Pmode, virtual_outgoing_args_rtx,
  3208. -INTVAL (size) - (below ? 0 : extra));
  3209. else if (extra != 0 && !below)
  3210. temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
  3211. negate_rtx (Pmode, plus_constant (Pmode, size,
  3212. extra)));
  3213. else
  3214. temp = gen_rtx_PLUS (Pmode, virtual_outgoing_args_rtx,
  3215. negate_rtx (Pmode, size));
  3216. }
  3217. return memory_address (GET_CLASS_NARROWEST_MODE (MODE_INT), temp);
  3218. }
  3219. /* A utility routine that returns the base of an auto-inc memory, or NULL. */
  3220. static rtx
  3221. mem_autoinc_base (rtx mem)
  3222. {
  3223. if (MEM_P (mem))
  3224. {
  3225. rtx addr = XEXP (mem, 0);
  3226. if (GET_RTX_CLASS (GET_CODE (addr)) == RTX_AUTOINC)
  3227. return XEXP (addr, 0);
  3228. }
  3229. return NULL;
  3230. }
  3231. /* A utility routine used here, in reload, and in try_split. The insns
  3232. after PREV up to and including LAST are known to adjust the stack,
  3233. with a final value of END_ARGS_SIZE. Iterate backward from LAST
  3234. placing notes as appropriate. PREV may be NULL, indicating the
  3235. entire insn sequence prior to LAST should be scanned.
  3236. The set of allowed stack pointer modifications is small:
  3237. (1) One or more auto-inc style memory references (aka pushes),
  3238. (2) One or more addition/subtraction with the SP as destination,
  3239. (3) A single move insn with the SP as destination,
  3240. (4) A call_pop insn,
  3241. (5) Noreturn call insns if !ACCUMULATE_OUTGOING_ARGS.
  3242. Insns in the sequence that do not modify the SP are ignored,
  3243. except for noreturn calls.
  3244. The return value is the amount of adjustment that can be trivially
  3245. verified, via immediate operand or auto-inc. If the adjustment
  3246. cannot be trivially extracted, the return value is INT_MIN. */
  3247. HOST_WIDE_INT
  3248. find_args_size_adjust (rtx_insn *insn)
  3249. {
  3250. rtx dest, set, pat;
  3251. int i;
  3252. pat = PATTERN (insn);
  3253. set = NULL;
  3254. /* Look for a call_pop pattern. */
  3255. if (CALL_P (insn))
  3256. {
  3257. /* We have to allow non-call_pop patterns for the case
  3258. of emit_single_push_insn of a TLS address. */
  3259. if (GET_CODE (pat) != PARALLEL)
  3260. return 0;
  3261. /* All call_pop have a stack pointer adjust in the parallel.
  3262. The call itself is always first, and the stack adjust is
  3263. usually last, so search from the end. */
  3264. for (i = XVECLEN (pat, 0) - 1; i > 0; --i)
  3265. {
  3266. set = XVECEXP (pat, 0, i);
  3267. if (GET_CODE (set) != SET)
  3268. continue;
  3269. dest = SET_DEST (set);
  3270. if (dest == stack_pointer_rtx)
  3271. break;
  3272. }
  3273. /* We'd better have found the stack pointer adjust. */
  3274. if (i == 0)
  3275. return 0;
  3276. /* Fall through to process the extracted SET and DEST
  3277. as if it was a standalone insn. */
  3278. }
  3279. else if (GET_CODE (pat) == SET)
  3280. set = pat;
  3281. else if ((set = single_set (insn)) != NULL)
  3282. ;
  3283. else if (GET_CODE (pat) == PARALLEL)
  3284. {
  3285. /* ??? Some older ports use a parallel with a stack adjust
  3286. and a store for a PUSH_ROUNDING pattern, rather than a
  3287. PRE/POST_MODIFY rtx. Don't force them to update yet... */
  3288. /* ??? See h8300 and m68k, pushqi1. */
  3289. for (i = XVECLEN (pat, 0) - 1; i >= 0; --i)
  3290. {
  3291. set = XVECEXP (pat, 0, i);
  3292. if (GET_CODE (set) != SET)
  3293. continue;
  3294. dest = SET_DEST (set);
  3295. if (dest == stack_pointer_rtx)
  3296. break;
  3297. /* We do not expect an auto-inc of the sp in the parallel. */
  3298. gcc_checking_assert (mem_autoinc_base (dest) != stack_pointer_rtx);
  3299. gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
  3300. != stack_pointer_rtx);
  3301. }
  3302. if (i < 0)
  3303. return 0;
  3304. }
  3305. else
  3306. return 0;
  3307. dest = SET_DEST (set);
  3308. /* Look for direct modifications of the stack pointer. */
  3309. if (REG_P (dest) && REGNO (dest) == STACK_POINTER_REGNUM)
  3310. {
  3311. /* Look for a trivial adjustment, otherwise assume nothing. */
  3312. /* Note that the SPU restore_stack_block pattern refers to
  3313. the stack pointer in V4SImode. Consider that non-trivial. */
  3314. if (SCALAR_INT_MODE_P (GET_MODE (dest))
  3315. && GET_CODE (SET_SRC (set)) == PLUS
  3316. && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
  3317. && CONST_INT_P (XEXP (SET_SRC (set), 1)))
  3318. return INTVAL (XEXP (SET_SRC (set), 1));
  3319. /* ??? Reload can generate no-op moves, which will be cleaned
  3320. up later. Recognize it and continue searching. */
  3321. else if (rtx_equal_p (dest, SET_SRC (set)))
  3322. return 0;
  3323. else
  3324. return HOST_WIDE_INT_MIN;
  3325. }
  3326. else
  3327. {
  3328. rtx mem, addr;
  3329. /* Otherwise only think about autoinc patterns. */
  3330. if (mem_autoinc_base (dest) == stack_pointer_rtx)
  3331. {
  3332. mem = dest;
  3333. gcc_checking_assert (mem_autoinc_base (SET_SRC (set))
  3334. != stack_pointer_rtx);
  3335. }
  3336. else if (mem_autoinc_base (SET_SRC (set)) == stack_pointer_rtx)
  3337. mem = SET_SRC (set);
  3338. else
  3339. return 0;
  3340. addr = XEXP (mem, 0);
  3341. switch (GET_CODE (addr))
  3342. {
  3343. case PRE_INC:
  3344. case POST_INC:
  3345. return GET_MODE_SIZE (GET_MODE (mem));
  3346. case PRE_DEC:
  3347. case POST_DEC:
  3348. return -GET_MODE_SIZE (GET_MODE (mem));
  3349. case PRE_MODIFY:
  3350. case POST_MODIFY:
  3351. addr = XEXP (addr, 1);
  3352. gcc_assert (GET_CODE (addr) == PLUS);
  3353. gcc_assert (XEXP (addr, 0) == stack_pointer_rtx);
  3354. gcc_assert (CONST_INT_P (XEXP (addr, 1)));
  3355. return INTVAL (XEXP (addr, 1));
  3356. default:
  3357. gcc_unreachable ();
  3358. }
  3359. }
  3360. }
  3361. int
  3362. fixup_args_size_notes (rtx_insn *prev, rtx_insn *last, int end_args_size)
  3363. {
  3364. int args_size = end_args_size;
  3365. bool saw_unknown = false;
  3366. rtx_insn *insn;
  3367. for (insn = last; insn != prev; insn = PREV_INSN (insn))
  3368. {
  3369. HOST_WIDE_INT this_delta;
  3370. if (!NONDEBUG_INSN_P (insn))
  3371. continue;
  3372. this_delta = find_args_size_adjust (insn);
  3373. if (this_delta == 0)
  3374. {
  3375. if (!CALL_P (insn)
  3376. || ACCUMULATE_OUTGOING_ARGS
  3377. || find_reg_note (insn, REG_NORETURN, NULL_RTX) == NULL_RTX)
  3378. continue;
  3379. }
  3380. gcc_assert (!saw_unknown);
  3381. if (this_delta == HOST_WIDE_INT_MIN)
  3382. saw_unknown = true;
  3383. add_reg_note (insn, REG_ARGS_SIZE, GEN_INT (args_size));
  3384. #ifdef STACK_GROWS_DOWNWARD
  3385. this_delta = -(unsigned HOST_WIDE_INT) this_delta;
  3386. #endif
  3387. args_size -= this_delta;
  3388. }
  3389. return saw_unknown ? INT_MIN : args_size;
  3390. }
  3391. #ifdef PUSH_ROUNDING
  3392. /* Emit single push insn. */
  3393. static void
  3394. emit_single_push_insn_1 (machine_mode mode, rtx x, tree type)
  3395. {
  3396. rtx dest_addr;
  3397. unsigned rounded_size = PUSH_ROUNDING (GET_MODE_SIZE (mode));
  3398. rtx dest;
  3399. enum insn_code icode;
  3400. stack_pointer_delta += PUSH_ROUNDING (GET_MODE_SIZE (mode));
  3401. /* If there is push pattern, use it. Otherwise try old way of throwing
  3402. MEM representing push operation to move expander. */
  3403. icode = optab_handler (push_optab, mode);
  3404. if (icode != CODE_FOR_nothing)
  3405. {
  3406. struct expand_operand ops[1];
  3407. create_input_operand (&ops[0], x, mode);
  3408. if (maybe_expand_insn (icode, 1, ops))
  3409. return;
  3410. }
  3411. if (GET_MODE_SIZE (mode) == rounded_size)
  3412. dest_addr = gen_rtx_fmt_e (STACK_PUSH_CODE, Pmode, stack_pointer_rtx);
  3413. /* If we are to pad downward, adjust the stack pointer first and
  3414. then store X into the stack location using an offset. This is
  3415. because emit_move_insn does not know how to pad; it does not have
  3416. access to type. */
  3417. else if (FUNCTION_ARG_PADDING (mode, type) == downward)
  3418. {
  3419. unsigned padding_size = rounded_size - GET_MODE_SIZE (mode);
  3420. HOST_WIDE_INT offset;
  3421. emit_move_insn (stack_pointer_rtx,
  3422. expand_binop (Pmode,
  3423. #ifdef STACK_GROWS_DOWNWARD
  3424. sub_optab,
  3425. #else
  3426. add_optab,
  3427. #endif
  3428. stack_pointer_rtx,
  3429. gen_int_mode (rounded_size, Pmode),
  3430. NULL_RTX, 0, OPTAB_LIB_WIDEN));
  3431. offset = (HOST_WIDE_INT) padding_size;
  3432. #ifdef STACK_GROWS_DOWNWARD
  3433. if (STACK_PUSH_CODE == POST_DEC)
  3434. /* We have already decremented the stack pointer, so get the
  3435. previous value. */
  3436. offset += (HOST_WIDE_INT) rounded_size;
  3437. #else
  3438. if (STACK_PUSH_CODE == POST_INC)
  3439. /* We have already incremented the stack pointer, so get the
  3440. previous value. */
  3441. offset -= (HOST_WIDE_INT) rounded_size;
  3442. #endif
  3443. dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
  3444. gen_int_mode (offset, Pmode));
  3445. }
  3446. else
  3447. {
  3448. #ifdef STACK_GROWS_DOWNWARD
  3449. /* ??? This seems wrong if STACK_PUSH_CODE == POST_DEC. */
  3450. dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
  3451. gen_int_mode (-(HOST_WIDE_INT) rounded_size,
  3452. Pmode));
  3453. #else
  3454. /* ??? This seems wrong if STACK_PUSH_CODE == POST_INC. */
  3455. dest_addr = gen_rtx_PLUS (Pmode, stack_pointer_rtx,
  3456. gen_int_mode (rounded_size, Pmode));
  3457. #endif
  3458. dest_addr = gen_rtx_PRE_MODIFY (Pmode, stack_pointer_rtx, dest_addr);
  3459. }
  3460. dest = gen_rtx_MEM (mode, dest_addr);
  3461. if (type != 0)
  3462. {
  3463. set_mem_attributes (dest, type, 1);
  3464. if (cfun->tail_call_marked)
  3465. /* Function incoming arguments may overlap with sibling call
  3466. outgoing arguments and we cannot allow reordering of reads
  3467. from function arguments with stores to outgoing arguments
  3468. of sibling calls. */
  3469. set_mem_alias_set (dest, 0);
  3470. }
  3471. emit_move_insn (dest, x);
  3472. }
  3473. /* Emit and annotate a single push insn. */
  3474. static void
  3475. emit_single_push_insn (machine_mode mode, rtx x, tree type)
  3476. {
  3477. int delta, old_delta = stack_pointer_delta;
  3478. rtx_insn *prev = get_last_insn ();
  3479. rtx_insn *last;
  3480. emit_single_push_insn_1 (mode, x, type);
  3481. last = get_last_insn ();
  3482. /* Notice the common case where we emitted exactly one insn. */
  3483. if (PREV_INSN (last) == prev)
  3484. {
  3485. add_reg_note (last, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta));
  3486. return;
  3487. }
  3488. delta = fixup_args_size_notes (prev, last, stack_pointer_delta);
  3489. gcc_assert (delta == INT_MIN || delta == old_delta);
  3490. }
  3491. #endif
  3492. /* Generate code to push X onto the stack, assuming it has mode MODE and
  3493. type TYPE.
  3494. MODE is redundant except when X is a CONST_INT (since they don't
  3495. carry mode info).
  3496. SIZE is an rtx for the size of data to be copied (in bytes),
  3497. needed only if X is BLKmode.
  3498. ALIGN (in bits) is maximum alignment we can assume.
  3499. If PARTIAL and REG are both nonzero, then copy that many of the first
  3500. bytes of X into registers starting with REG, and push the rest of X.
  3501. The amount of space pushed is decreased by PARTIAL bytes.
  3502. REG must be a hard register in this case.
  3503. If REG is zero but PARTIAL is not, take any all others actions for an
  3504. argument partially in registers, but do not actually load any
  3505. registers.
  3506. EXTRA is the amount in bytes of extra space to leave next to this arg.
  3507. This is ignored if an argument block has already been allocated.
  3508. On a machine that lacks real push insns, ARGS_ADDR is the address of
  3509. the bottom of the argument block for this call. We use indexing off there
  3510. to store the arg. On machines with push insns, ARGS_ADDR is 0 when a
  3511. argument block has not been preallocated.
  3512. ARGS_SO_FAR is the size of args previously pushed for this call.
  3513. REG_PARM_STACK_SPACE is nonzero if functions require stack space
  3514. for arguments passed in registers. If nonzero, it will be the number
  3515. of bytes required. */
  3516. void
  3517. emit_push_insn (rtx x, machine_mode mode, tree type, rtx size,
  3518. unsigned int align, int partial, rtx reg, int extra,
  3519. rtx args_addr, rtx args_so_far, int reg_parm_stack_space,
  3520. rtx alignment_pad)
  3521. {
  3522. rtx xinner;
  3523. enum direction stack_direction
  3524. #ifdef STACK_GROWS_DOWNWARD
  3525. = downward;
  3526. #else
  3527. = upward;
  3528. #endif
  3529. /* Decide where to pad the argument: `downward' for below,
  3530. `upward' for above, or `none' for don't pad it.
  3531. Default is below for small data on big-endian machines; else above. */
  3532. enum direction where_pad = FUNCTION_ARG_PADDING (mode, type);
  3533. /* Invert direction if stack is post-decrement.
  3534. FIXME: why? */
  3535. if (STACK_PUSH_CODE == POST_DEC)
  3536. if (where_pad != none)
  3537. where_pad = (where_pad == downward ? upward : downward);
  3538. xinner = x;
  3539. if (mode == BLKmode
  3540. || (STRICT_ALIGNMENT && align < GET_MODE_ALIGNMENT (mode)))
  3541. {
  3542. /* Copy a block into the stack, entirely or partially. */
  3543. rtx temp;
  3544. int used;
  3545. int offset;
  3546. int skip;
  3547. offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
  3548. used = partial - offset;
  3549. if (mode != BLKmode)
  3550. {
  3551. /* A value is to be stored in an insufficiently aligned
  3552. stack slot; copy via a suitably aligned slot if
  3553. necessary. */
  3554. size = GEN_INT (GET_MODE_SIZE (mode));
  3555. if (!MEM_P (xinner))
  3556. {
  3557. temp = assign_temp (type, 1, 1);
  3558. emit_move_insn (temp, xinner);
  3559. xinner = temp;
  3560. }
  3561. }
  3562. gcc_assert (size);
  3563. /* USED is now the # of bytes we need not copy to the stack
  3564. because registers will take care of them. */
  3565. if (partial != 0)
  3566. xinner = adjust_address (xinner, BLKmode, used);
  3567. /* If the partial register-part of the arg counts in its stack size,
  3568. skip the part of stack space corresponding to the registers.
  3569. Otherwise, start copying to the beginning of the stack space,
  3570. by setting SKIP to 0. */
  3571. skip = (reg_parm_stack_space == 0) ? 0 : used;
  3572. #ifdef PUSH_ROUNDING
  3573. /* Do it with several push insns if that doesn't take lots of insns
  3574. and if there is no difficulty with push insns that skip bytes
  3575. on the stack for alignment purposes. */
  3576. if (args_addr == 0
  3577. && PUSH_ARGS
  3578. && CONST_INT_P (size)
  3579. && skip == 0
  3580. && MEM_ALIGN (xinner) >= align
  3581. && can_move_by_pieces ((unsigned) INTVAL (size) - used, align)
  3582. /* Here we avoid the case of a structure whose weak alignment
  3583. forces many pushes of a small amount of data,
  3584. and such small pushes do rounding that causes trouble. */
  3585. && ((! SLOW_UNALIGNED_ACCESS (word_mode, align))
  3586. || align >= BIGGEST_ALIGNMENT
  3587. || (PUSH_ROUNDING (align / BITS_PER_UNIT)
  3588. == (align / BITS_PER_UNIT)))
  3589. && (HOST_WIDE_INT) PUSH_ROUNDING (INTVAL (size)) == INTVAL (size))
  3590. {
  3591. /* Push padding now if padding above and stack grows down,
  3592. or if padding below and stack grows up.
  3593. But if space already allocated, this has already been done. */
  3594. if (extra && args_addr == 0
  3595. && where_pad != none && where_pad != stack_direction)
  3596. anti_adjust_stack (GEN_INT (extra));
  3597. move_by_pieces (NULL, xinner, INTVAL (size) - used, align, 0);
  3598. }
  3599. else
  3600. #endif /* PUSH_ROUNDING */
  3601. {
  3602. rtx target;
  3603. /* Otherwise make space on the stack and copy the data
  3604. to the address of that space. */
  3605. /* Deduct words put into registers from the size we must copy. */
  3606. if (partial != 0)
  3607. {
  3608. if (CONST_INT_P (size))
  3609. size = GEN_INT (INTVAL (size) - used);
  3610. else
  3611. size = expand_binop (GET_MODE (size), sub_optab, size,
  3612. gen_int_mode (used, GET_MODE (size)),
  3613. NULL_RTX, 0, OPTAB_LIB_WIDEN);
  3614. }
  3615. /* Get the address of the stack space.
  3616. In this case, we do not deal with EXTRA separately.
  3617. A single stack adjust will do. */
  3618. if (! args_addr)
  3619. {
  3620. temp = push_block (size, extra, where_pad == downward);
  3621. extra = 0;
  3622. }
  3623. else if (CONST_INT_P (args_so_far))
  3624. temp = memory_address (BLKmode,
  3625. plus_constant (Pmode, args_addr,
  3626. skip + INTVAL (args_so_far)));
  3627. else
  3628. temp = memory_address (BLKmode,
  3629. plus_constant (Pmode,
  3630. gen_rtx_PLUS (Pmode,
  3631. args_addr,
  3632. args_so_far),
  3633. skip));
  3634. if (!ACCUMULATE_OUTGOING_ARGS)
  3635. {
  3636. /* If the source is referenced relative to the stack pointer,
  3637. copy it to another register to stabilize it. We do not need
  3638. to do this if we know that we won't be changing sp. */
  3639. if (reg_mentioned_p (virtual_stack_dynamic_rtx, temp)
  3640. || reg_mentioned_p (virtual_outgoing_args_rtx, temp))
  3641. temp = copy_to_reg (temp);
  3642. }
  3643. target = gen_rtx_MEM (BLKmode, temp);
  3644. /* We do *not* set_mem_attributes here, because incoming arguments
  3645. may overlap with sibling call outgoing arguments and we cannot
  3646. allow reordering of reads from function arguments with stores
  3647. to outgoing arguments of sibling calls. We do, however, want
  3648. to record the alignment of the stack slot. */
  3649. /* ALIGN may well be better aligned than TYPE, e.g. due to
  3650. PARM_BOUNDARY. Assume the caller isn't lying. */
  3651. set_mem_align (target, align);
  3652. emit_block_move (target, xinner, size, BLOCK_OP_CALL_PARM);
  3653. }
  3654. }
  3655. else if (partial > 0)
  3656. {
  3657. /* Scalar partly in registers. */
  3658. int size = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
  3659. int i;
  3660. int not_stack;
  3661. /* # bytes of start of argument
  3662. that we must make space for but need not store. */
  3663. int offset = partial % (PARM_BOUNDARY / BITS_PER_UNIT);
  3664. int args_offset = INTVAL (args_so_far);
  3665. int skip;
  3666. /* Push padding now if padding above and stack grows down,
  3667. or if padding below and stack grows up.
  3668. But if space already allocated, this has already been done. */
  3669. if (extra && args_addr == 0
  3670. && where_pad != none && where_pad != stack_direction)
  3671. anti_adjust_stack (GEN_INT (extra));
  3672. /* If we make space by pushing it, we might as well push
  3673. the real data. Otherwise, we can leave OFFSET nonzero
  3674. and leave the space uninitialized. */
  3675. if (args_addr == 0)
  3676. offset = 0;
  3677. /* Now NOT_STACK gets the number of words that we don't need to
  3678. allocate on the stack. Convert OFFSET to words too. */
  3679. not_stack = (partial - offset) / UNITS_PER_WORD;
  3680. offset /= UNITS_PER_WORD;
  3681. /* If the partial register-part of the arg counts in its stack size,
  3682. skip the part of stack space corresponding to the registers.
  3683. Otherwise, start copying to the beginning of the stack space,
  3684. by setting SKIP to 0. */
  3685. skip = (reg_parm_stack_space == 0) ? 0 : not_stack;
  3686. if (CONSTANT_P (x) && !targetm.legitimate_constant_p (mode, x))
  3687. x = validize_mem (force_const_mem (mode, x));
  3688. /* If X is a hard register in a non-integer mode, copy it into a pseudo;
  3689. SUBREGs of such registers are not allowed. */
  3690. if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER
  3691. && GET_MODE_CLASS (GET_MODE (x)) != MODE_INT))
  3692. x = copy_to_reg (x);
  3693. /* Loop over all the words allocated on the stack for this arg. */
  3694. /* We can do it by words, because any scalar bigger than a word
  3695. has a size a multiple of a word. */
  3696. for (i = size - 1; i >= not_stack; i--)
  3697. if (i >= not_stack + offset)
  3698. emit_push_insn (operand_subword_force (x, i, mode),
  3699. word_mode, NULL_TREE, NULL_RTX, align, 0, NULL_RTX,
  3700. 0, args_addr,
  3701. GEN_INT (args_offset + ((i - not_stack + skip)
  3702. * UNITS_PER_WORD)),
  3703. reg_parm_stack_space, alignment_pad);
  3704. }
  3705. else
  3706. {
  3707. rtx addr;
  3708. rtx dest;
  3709. /* Push padding now if padding above and stack grows down,
  3710. or if padding below and stack grows up.
  3711. But if space already allocated, this has already been done. */
  3712. if (extra && args_addr == 0
  3713. && where_pad != none && where_pad != stack_direction)
  3714. anti_adjust_stack (GEN_INT (extra));
  3715. #ifdef PUSH_ROUNDING
  3716. if (args_addr == 0 && PUSH_ARGS)
  3717. emit_single_push_insn (mode, x, type);
  3718. else
  3719. #endif
  3720. {
  3721. if (CONST_INT_P (args_so_far))
  3722. addr
  3723. = memory_address (mode,
  3724. plus_constant (Pmode, args_addr,
  3725. INTVAL (args_so_far)));
  3726. else
  3727. addr = memory_address (mode, gen_rtx_PLUS (Pmode, args_addr,
  3728. args_so_far));
  3729. dest = gen_rtx_MEM (mode, addr);
  3730. /* We do *not* set_mem_attributes here, because incoming arguments
  3731. may overlap with sibling call outgoing arguments and we cannot
  3732. allow reordering of reads from function arguments with stores
  3733. to outgoing arguments of sibling calls. We do, however, want
  3734. to record the alignment of the stack slot. */
  3735. /* ALIGN may well be better aligned than TYPE, e.g. due to
  3736. PARM_BOUNDARY. Assume the caller isn't lying. */
  3737. set_mem_align (dest, align);
  3738. emit_move_insn (dest, x);
  3739. }
  3740. }
  3741. /* If part should go in registers, copy that part
  3742. into the appropriate registers. Do this now, at the end,
  3743. since mem-to-mem copies above may do function calls. */
  3744. if (partial > 0 && reg != 0)
  3745. {
  3746. /* Handle calls that pass values in multiple non-contiguous locations.
  3747. The Irix 6 ABI has examples of this. */
  3748. if (GET_CODE (reg) == PARALLEL)
  3749. emit_group_load (reg, x, type, -1);
  3750. else
  3751. {
  3752. gcc_assert (partial % UNITS_PER_WORD == 0);
  3753. move_block_to_reg (REGNO (reg), x, partial / UNITS_PER_WORD, mode);
  3754. }
  3755. }
  3756. if (extra && args_addr == 0 && where_pad == stack_direction)
  3757. anti_adjust_stack (GEN_INT (extra));
  3758. if (alignment_pad && args_addr == 0)
  3759. anti_adjust_stack (alignment_pad);
  3760. }
  3761. /* Return X if X can be used as a subtarget in a sequence of arithmetic
  3762. operations. */
  3763. static rtx
  3764. get_subtarget (rtx x)
  3765. {
  3766. return (optimize
  3767. || x == 0
  3768. /* Only registers can be subtargets. */
  3769. || !REG_P (x)
  3770. /* Don't use hard regs to avoid extending their life. */
  3771. || REGNO (x) < FIRST_PSEUDO_REGISTER
  3772. ? 0 : x);
  3773. }
  3774. /* A subroutine of expand_assignment. Optimize FIELD op= VAL, where
  3775. FIELD is a bitfield. Returns true if the optimization was successful,
  3776. and there's nothing else to do. */
  3777. static bool
  3778. optimize_bitfield_assignment_op (unsigned HOST_WIDE_INT bitsize,
  3779. unsigned HOST_WIDE_INT bitpos,
  3780. unsigned HOST_WIDE_INT bitregion_start,
  3781. unsigned HOST_WIDE_INT bitregion_end,
  3782. machine_mode mode1, rtx str_rtx,
  3783. tree to, tree src)
  3784. {
  3785. machine_mode str_mode = GET_MODE (str_rtx);
  3786. unsigned int str_bitsize = GET_MODE_BITSIZE (str_mode);
  3787. tree op0, op1;
  3788. rtx value, result;
  3789. optab binop;
  3790. gimple srcstmt;
  3791. enum tree_code code;
  3792. if (mode1 != VOIDmode
  3793. || bitsize >= BITS_PER_WORD
  3794. || str_bitsize > BITS_PER_WORD
  3795. || TREE_SIDE_EFFECTS (to)
  3796. || TREE_THIS_VOLATILE (to))
  3797. return false;
  3798. STRIP_NOPS (src);
  3799. if (TREE_CODE (src) != SSA_NAME)
  3800. return false;
  3801. if (TREE_CODE (TREE_TYPE (src)) != INTEGER_TYPE)
  3802. return false;
  3803. srcstmt = get_gimple_for_ssa_name (src);
  3804. if (!srcstmt
  3805. || TREE_CODE_CLASS (gimple_assign_rhs_code (srcstmt)) != tcc_binary)
  3806. return false;
  3807. code = gimple_assign_rhs_code (srcstmt);
  3808. op0 = gimple_assign_rhs1 (srcstmt);
  3809. /* If OP0 is an SSA_NAME, then we want to walk the use-def chain
  3810. to find its initialization. Hopefully the initialization will
  3811. be from a bitfield load. */
  3812. if (TREE_CODE (op0) == SSA_NAME)
  3813. {
  3814. gimple op0stmt = get_gimple_for_ssa_name (op0);
  3815. /* We want to eventually have OP0 be the same as TO, which
  3816. should be a bitfield. */
  3817. if (!op0stmt
  3818. || !is_gimple_assign (op0stmt)
  3819. || gimple_assign_rhs_code (op0stmt) != TREE_CODE (to))
  3820. return false;
  3821. op0 = gimple_assign_rhs1 (op0stmt);
  3822. }
  3823. op1 = gimple_assign_rhs2 (srcstmt);
  3824. if (!operand_equal_p (to, op0, 0))
  3825. return false;
  3826. if (MEM_P (str_rtx))
  3827. {
  3828. unsigned HOST_WIDE_INT offset1;
  3829. if (str_bitsize == 0 || str_bitsize > BITS_PER_WORD)
  3830. str_mode = word_mode;
  3831. str_mode = get_best_mode (bitsize, bitpos,
  3832. bitregion_start, bitregion_end,
  3833. MEM_ALIGN (str_rtx), str_mode, 0);
  3834. if (str_mode == VOIDmode)
  3835. return false;
  3836. str_bitsize = GET_MODE_BITSIZE (str_mode);
  3837. offset1 = bitpos;
  3838. bitpos %= str_bitsize;
  3839. offset1 = (offset1 - bitpos) / BITS_PER_UNIT;
  3840. str_rtx = adjust_address (str_rtx, str_mode, offset1);
  3841. }
  3842. else if (!REG_P (str_rtx) && GET_CODE (str_rtx) != SUBREG)
  3843. return false;
  3844. /* If the bit field covers the whole REG/MEM, store_field
  3845. will likely generate better code. */
  3846. if (bitsize >= str_bitsize)
  3847. return false;
  3848. /* We can't handle fields split across multiple entities. */
  3849. if (bitpos + bitsize > str_bitsize)
  3850. return false;
  3851. if (BYTES_BIG_ENDIAN)
  3852. bitpos = str_bitsize - bitpos - bitsize;
  3853. switch (code)
  3854. {
  3855. case PLUS_EXPR:
  3856. case MINUS_EXPR:
  3857. /* For now, just optimize the case of the topmost bitfield
  3858. where we don't need to do any masking and also
  3859. 1 bit bitfields where xor can be used.
  3860. We might win by one instruction for the other bitfields
  3861. too if insv/extv instructions aren't used, so that
  3862. can be added later. */
  3863. if (bitpos + bitsize != str_bitsize
  3864. && (bitsize != 1 || TREE_CODE (op1) != INTEGER_CST))
  3865. break;
  3866. value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
  3867. value = convert_modes (str_mode,
  3868. TYPE_MODE (TREE_TYPE (op1)), value,
  3869. TYPE_UNSIGNED (TREE_TYPE (op1)));
  3870. /* We may be accessing data outside the field, which means
  3871. we can alias adjacent data. */
  3872. if (MEM_P (str_rtx))
  3873. {
  3874. str_rtx = shallow_copy_rtx (str_rtx);
  3875. set_mem_alias_set (str_rtx, 0);
  3876. set_mem_expr (str_rtx, 0);
  3877. }
  3878. binop = code == PLUS_EXPR ? add_optab : sub_optab;
  3879. if (bitsize == 1 && bitpos + bitsize != str_bitsize)
  3880. {
  3881. value = expand_and (str_mode, value, const1_rtx, NULL);
  3882. binop = xor_optab;
  3883. }
  3884. value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
  3885. result = expand_binop (str_mode, binop, str_rtx,
  3886. value, str_rtx, 1, OPTAB_WIDEN);
  3887. if (result != str_rtx)
  3888. emit_move_insn (str_rtx, result);
  3889. return true;
  3890. case BIT_IOR_EXPR:
  3891. case BIT_XOR_EXPR:
  3892. if (TREE_CODE (op1) != INTEGER_CST)
  3893. break;
  3894. value = expand_expr (op1, NULL_RTX, str_mode, EXPAND_NORMAL);
  3895. value = convert_modes (str_mode,
  3896. TYPE_MODE (TREE_TYPE (op1)), value,
  3897. TYPE_UNSIGNED (TREE_TYPE (op1)));
  3898. /* We may be accessing data outside the field, which means
  3899. we can alias adjacent data. */
  3900. if (MEM_P (str_rtx))
  3901. {
  3902. str_rtx = shallow_copy_rtx (str_rtx);
  3903. set_mem_alias_set (str_rtx, 0);
  3904. set_mem_expr (str_rtx, 0);
  3905. }
  3906. binop = code == BIT_IOR_EXPR ? ior_optab : xor_optab;
  3907. if (bitpos + bitsize != str_bitsize)
  3908. {
  3909. rtx mask = gen_int_mode (((unsigned HOST_WIDE_INT) 1 << bitsize) - 1,
  3910. str_mode);
  3911. value = expand_and (str_mode, value, mask, NULL_RTX);
  3912. }
  3913. value = expand_shift (LSHIFT_EXPR, str_mode, value, bitpos, NULL_RTX, 1);
  3914. result = expand_binop (str_mode, binop, str_rtx,
  3915. value, str_rtx, 1, OPTAB_WIDEN);
  3916. if (result != str_rtx)
  3917. emit_move_insn (str_rtx, result);
  3918. return true;
  3919. default:
  3920. break;
  3921. }
  3922. return false;
  3923. }
  3924. /* In the C++ memory model, consecutive bit fields in a structure are
  3925. considered one memory location.
  3926. Given a COMPONENT_REF EXP at position (BITPOS, OFFSET), this function
  3927. returns the bit range of consecutive bits in which this COMPONENT_REF
  3928. belongs. The values are returned in *BITSTART and *BITEND. *BITPOS
  3929. and *OFFSET may be adjusted in the process.
  3930. If the access does not need to be restricted, 0 is returned in both
  3931. *BITSTART and *BITEND. */
  3932. static void
  3933. get_bit_range (unsigned HOST_WIDE_INT *bitstart,
  3934. unsigned HOST_WIDE_INT *bitend,
  3935. tree exp,
  3936. HOST_WIDE_INT *bitpos,
  3937. tree *offset)
  3938. {
  3939. HOST_WIDE_INT bitoffset;
  3940. tree field, repr;
  3941. gcc_assert (TREE_CODE (exp) == COMPONENT_REF);
  3942. field = TREE_OPERAND (exp, 1);
  3943. repr = DECL_BIT_FIELD_REPRESENTATIVE (field);
  3944. /* If we do not have a DECL_BIT_FIELD_REPRESENTATIVE there is no
  3945. need to limit the range we can access. */
  3946. if (!repr)
  3947. {
  3948. *bitstart = *bitend = 0;
  3949. return;
  3950. }
  3951. /* If we have a DECL_BIT_FIELD_REPRESENTATIVE but the enclosing record is
  3952. part of a larger bit field, then the representative does not serve any
  3953. useful purpose. This can occur in Ada. */
  3954. if (handled_component_p (TREE_OPERAND (exp, 0)))
  3955. {
  3956. machine_mode rmode;
  3957. HOST_WIDE_INT rbitsize, rbitpos;
  3958. tree roffset;
  3959. int unsignedp;
  3960. int volatilep = 0;
  3961. get_inner_reference (TREE_OPERAND (exp, 0), &rbitsize, &rbitpos,
  3962. &roffset, &rmode, &unsignedp, &volatilep, false);
  3963. if ((rbitpos % BITS_PER_UNIT) != 0)
  3964. {
  3965. *bitstart = *bitend = 0;
  3966. return;
  3967. }
  3968. }
  3969. /* Compute the adjustment to bitpos from the offset of the field
  3970. relative to the representative. DECL_FIELD_OFFSET of field and
  3971. repr are the same by construction if they are not constants,
  3972. see finish_bitfield_layout. */
  3973. if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field))
  3974. && tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr)))
  3975. bitoffset = (tree_to_uhwi (DECL_FIELD_OFFSET (field))
  3976. - tree_to_uhwi (DECL_FIELD_OFFSET (repr))) * BITS_PER_UNIT;
  3977. else
  3978. bitoffset = 0;
  3979. bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
  3980. - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
  3981. /* If the adjustment is larger than bitpos, we would have a negative bit
  3982. position for the lower bound and this may wreak havoc later. Adjust
  3983. offset and bitpos to make the lower bound non-negative in that case. */
  3984. if (bitoffset > *bitpos)
  3985. {
  3986. HOST_WIDE_INT adjust = bitoffset - *bitpos;
  3987. gcc_assert ((adjust % BITS_PER_UNIT) == 0);
  3988. *bitpos += adjust;
  3989. if (*offset == NULL_TREE)
  3990. *offset = size_int (-adjust / BITS_PER_UNIT);
  3991. else
  3992. *offset
  3993. = size_binop (MINUS_EXPR, *offset, size_int (adjust / BITS_PER_UNIT));
  3994. *bitstart = 0;
  3995. }
  3996. else
  3997. *bitstart = *bitpos - bitoffset;
  3998. *bitend = *bitstart + tree_to_uhwi (DECL_SIZE (repr)) - 1;
  3999. }
  4000. /* Returns true if ADDR is an ADDR_EXPR of a DECL that does not reside
  4001. in memory and has non-BLKmode. DECL_RTL must not be a MEM; if
  4002. DECL_RTL was not set yet, return NORTL. */
  4003. static inline bool
  4004. addr_expr_of_non_mem_decl_p_1 (tree addr, bool nortl)
  4005. {
  4006. if (TREE_CODE (addr) != ADDR_EXPR)
  4007. return false;
  4008. tree base = TREE_OPERAND (addr, 0);
  4009. if (!DECL_P (base)
  4010. || TREE_ADDRESSABLE (base)
  4011. || DECL_MODE (base) == BLKmode)
  4012. return false;
  4013. if (!DECL_RTL_SET_P (base))
  4014. return nortl;
  4015. return (!MEM_P (DECL_RTL (base)));
  4016. }
  4017. /* Returns true if the MEM_REF REF refers to an object that does not
  4018. reside in memory and has non-BLKmode. */
  4019. static inline bool
  4020. mem_ref_refers_to_non_mem_p (tree ref)
  4021. {
  4022. tree base = TREE_OPERAND (ref, 0);
  4023. return addr_expr_of_non_mem_decl_p_1 (base, false);
  4024. }
  4025. /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL
  4026. is true, try generating a nontemporal store. */
  4027. void
  4028. expand_assignment (tree to, tree from, bool nontemporal)
  4029. {
  4030. rtx to_rtx = 0;
  4031. rtx result;
  4032. machine_mode mode;
  4033. unsigned int align;
  4034. enum insn_code icode;
  4035. /* Don't crash if the lhs of the assignment was erroneous. */
  4036. if (TREE_CODE (to) == ERROR_MARK)
  4037. {
  4038. expand_normal (from);
  4039. return;
  4040. }
  4041. /* Optimize away no-op moves without side-effects. */
  4042. if (operand_equal_p (to, from, 0))
  4043. return;
  4044. /* Handle misaligned stores. */
  4045. mode = TYPE_MODE (TREE_TYPE (to));
  4046. if ((TREE_CODE (to) == MEM_REF
  4047. || TREE_CODE (to) == TARGET_MEM_REF)
  4048. && mode != BLKmode
  4049. && !mem_ref_refers_to_non_mem_p (to)
  4050. && ((align = get_object_alignment (to))
  4051. < GET_MODE_ALIGNMENT (mode))
  4052. && (((icode = optab_handler (movmisalign_optab, mode))
  4053. != CODE_FOR_nothing)
  4054. || SLOW_UNALIGNED_ACCESS (mode, align)))
  4055. {
  4056. rtx reg, mem;
  4057. reg = expand_expr (from, NULL_RTX, VOIDmode, EXPAND_NORMAL);
  4058. reg = force_not_mem (reg);
  4059. mem = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
  4060. if (icode != CODE_FOR_nothing)
  4061. {
  4062. struct expand_operand ops[2];
  4063. create_fixed_operand (&ops[0], mem);
  4064. create_input_operand (&ops[1], reg, mode);
  4065. /* The movmisalign<mode> pattern cannot fail, else the assignment
  4066. would silently be omitted. */
  4067. expand_insn (icode, 2, ops);
  4068. }
  4069. else
  4070. store_bit_field (mem, GET_MODE_BITSIZE (mode), 0, 0, 0, mode, reg);
  4071. return;
  4072. }
  4073. /* Assignment of a structure component needs special treatment
  4074. if the structure component's rtx is not simply a MEM.
  4075. Assignment of an array element at a constant index, and assignment of
  4076. an array element in an unaligned packed structure field, has the same
  4077. problem. Same for (partially) storing into a non-memory object. */
  4078. if (handled_component_p (to)
  4079. || (TREE_CODE (to) == MEM_REF
  4080. && mem_ref_refers_to_non_mem_p (to))
  4081. || TREE_CODE (TREE_TYPE (to)) == ARRAY_TYPE)
  4082. {
  4083. machine_mode mode1;
  4084. HOST_WIDE_INT bitsize, bitpos;
  4085. unsigned HOST_WIDE_INT bitregion_start = 0;
  4086. unsigned HOST_WIDE_INT bitregion_end = 0;
  4087. tree offset;
  4088. int unsignedp;
  4089. int volatilep = 0;
  4090. tree tem;
  4091. push_temp_slots ();
  4092. tem = get_inner_reference (to, &bitsize, &bitpos, &offset, &mode1,
  4093. &unsignedp, &volatilep, true);
  4094. /* Make sure bitpos is not negative, it can wreak havoc later. */
  4095. if (bitpos < 0)
  4096. {
  4097. gcc_assert (offset == NULL_TREE);
  4098. offset = size_int (bitpos >> (BITS_PER_UNIT == 8
  4099. ? 3 : exact_log2 (BITS_PER_UNIT)));
  4100. bitpos &= BITS_PER_UNIT - 1;
  4101. }
  4102. if (TREE_CODE (to) == COMPONENT_REF
  4103. && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
  4104. get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos, &offset);
  4105. /* The C++ memory model naturally applies to byte-aligned fields.
  4106. However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
  4107. BITSIZE are not byte-aligned, there is no need to limit the range
  4108. we can access. This can occur with packed structures in Ada. */
  4109. else if (bitsize > 0
  4110. && bitsize % BITS_PER_UNIT == 0
  4111. && bitpos % BITS_PER_UNIT == 0)
  4112. {
  4113. bitregion_start = bitpos;
  4114. bitregion_end = bitpos + bitsize - 1;
  4115. }
  4116. to_rtx = expand_expr (tem, NULL_RTX, VOIDmode, EXPAND_WRITE);
  4117. /* If the field has a mode, we want to access it in the
  4118. field's mode, not the computed mode.
  4119. If a MEM has VOIDmode (external with incomplete type),
  4120. use BLKmode for it instead. */
  4121. if (MEM_P (to_rtx))
  4122. {
  4123. if (mode1 != VOIDmode)
  4124. to_rtx = adjust_address (to_rtx, mode1, 0);
  4125. else if (GET_MODE (to_rtx) == VOIDmode)
  4126. to_rtx = adjust_address (to_rtx, BLKmode, 0);
  4127. }
  4128. if (offset != 0)
  4129. {
  4130. machine_mode address_mode;
  4131. rtx offset_rtx;
  4132. if (!MEM_P (to_rtx))
  4133. {
  4134. /* We can get constant negative offsets into arrays with broken
  4135. user code. Translate this to a trap instead of ICEing. */
  4136. gcc_assert (TREE_CODE (offset) == INTEGER_CST);
  4137. expand_builtin_trap ();
  4138. to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
  4139. }
  4140. offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
  4141. address_mode = get_address_mode (to_rtx);
  4142. if (GET_MODE (offset_rtx) != address_mode)
  4143. offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
  4144. /* If we have an expression in OFFSET_RTX and a non-zero
  4145. byte offset in BITPOS, adding the byte offset before the
  4146. OFFSET_RTX results in better intermediate code, which makes
  4147. later rtl optimization passes perform better.
  4148. We prefer intermediate code like this:
  4149. r124:DI=r123:DI+0x18
  4150. [r124:DI]=r121:DI
  4151. ... instead of ...
  4152. r124:DI=r123:DI+0x10
  4153. [r124:DI+0x8]=r121:DI
  4154. This is only done for aligned data values, as these can
  4155. be expected to result in single move instructions. */
  4156. if (mode1 != VOIDmode
  4157. && bitpos != 0
  4158. && bitsize > 0
  4159. && (bitpos % bitsize) == 0
  4160. && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
  4161. && MEM_ALIGN (to_rtx) >= GET_MODE_ALIGNMENT (mode1))
  4162. {
  4163. to_rtx = adjust_address (to_rtx, mode1, bitpos / BITS_PER_UNIT);
  4164. bitregion_start = 0;
  4165. if (bitregion_end >= (unsigned HOST_WIDE_INT) bitpos)
  4166. bitregion_end -= bitpos;
  4167. bitpos = 0;
  4168. }
  4169. to_rtx = offset_address (to_rtx, offset_rtx,
  4170. highest_pow2_factor_for_target (to,
  4171. offset));
  4172. }
  4173. /* No action is needed if the target is not a memory and the field
  4174. lies completely outside that target. This can occur if the source
  4175. code contains an out-of-bounds access to a small array. */
  4176. if (!MEM_P (to_rtx)
  4177. && GET_MODE (to_rtx) != BLKmode
  4178. && (unsigned HOST_WIDE_INT) bitpos
  4179. >= GET_MODE_PRECISION (GET_MODE (to_rtx)))
  4180. {
  4181. expand_normal (from);
  4182. result = NULL;
  4183. }
  4184. /* Handle expand_expr of a complex value returning a CONCAT. */
  4185. else if (GET_CODE (to_rtx) == CONCAT)
  4186. {
  4187. unsigned short mode_bitsize = GET_MODE_BITSIZE (GET_MODE (to_rtx));
  4188. if (COMPLEX_MODE_P (TYPE_MODE (TREE_TYPE (from)))
  4189. && bitpos == 0
  4190. && bitsize == mode_bitsize)
  4191. result = store_expr (from, to_rtx, false, nontemporal);
  4192. else if (bitsize == mode_bitsize / 2
  4193. && (bitpos == 0 || bitpos == mode_bitsize / 2))
  4194. result = store_expr (from, XEXP (to_rtx, bitpos != 0), false,
  4195. nontemporal);
  4196. else if (bitpos + bitsize <= mode_bitsize / 2)
  4197. result = store_field (XEXP (to_rtx, 0), bitsize, bitpos,
  4198. bitregion_start, bitregion_end,
  4199. mode1, from,
  4200. get_alias_set (to), nontemporal);
  4201. else if (bitpos >= mode_bitsize / 2)
  4202. result = store_field (XEXP (to_rtx, 1), bitsize,
  4203. bitpos - mode_bitsize / 2,
  4204. bitregion_start, bitregion_end,
  4205. mode1, from,
  4206. get_alias_set (to), nontemporal);
  4207. else if (bitpos == 0 && bitsize == mode_bitsize)
  4208. {
  4209. rtx from_rtx;
  4210. result = expand_normal (from);
  4211. from_rtx = simplify_gen_subreg (GET_MODE (to_rtx), result,
  4212. TYPE_MODE (TREE_TYPE (from)), 0);
  4213. emit_move_insn (XEXP (to_rtx, 0),
  4214. read_complex_part (from_rtx, false));
  4215. emit_move_insn (XEXP (to_rtx, 1),
  4216. read_complex_part (from_rtx, true));
  4217. }
  4218. else
  4219. {
  4220. rtx temp = assign_stack_temp (GET_MODE (to_rtx),
  4221. GET_MODE_SIZE (GET_MODE (to_rtx)));
  4222. write_complex_part (temp, XEXP (to_rtx, 0), false);
  4223. write_complex_part (temp, XEXP (to_rtx, 1), true);
  4224. result = store_field (temp, bitsize, bitpos,
  4225. bitregion_start, bitregion_end,
  4226. mode1, from,
  4227. get_alias_set (to), nontemporal);
  4228. emit_move_insn (XEXP (to_rtx, 0), read_complex_part (temp, false));
  4229. emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true));
  4230. }
  4231. }
  4232. else
  4233. {
  4234. if (MEM_P (to_rtx))
  4235. {
  4236. /* If the field is at offset zero, we could have been given the
  4237. DECL_RTX of the parent struct. Don't munge it. */
  4238. to_rtx = shallow_copy_rtx (to_rtx);
  4239. set_mem_attributes_minus_bitpos (to_rtx, to, 0, bitpos);
  4240. if (volatilep)
  4241. MEM_VOLATILE_P (to_rtx) = 1;
  4242. }
  4243. if (optimize_bitfield_assignment_op (bitsize, bitpos,
  4244. bitregion_start, bitregion_end,
  4245. mode1,
  4246. to_rtx, to, from))
  4247. result = NULL;
  4248. else
  4249. result = store_field (to_rtx, bitsize, bitpos,
  4250. bitregion_start, bitregion_end,
  4251. mode1, from,
  4252. get_alias_set (to), nontemporal);
  4253. }
  4254. if (result)
  4255. preserve_temp_slots (result);
  4256. pop_temp_slots ();
  4257. return;
  4258. }
  4259. /* If the rhs is a function call and its value is not an aggregate,
  4260. call the function before we start to compute the lhs.
  4261. This is needed for correct code for cases such as
  4262. val = setjmp (buf) on machines where reference to val
  4263. requires loading up part of an address in a separate insn.
  4264. Don't do this if TO is a VAR_DECL or PARM_DECL whose DECL_RTL is REG
  4265. since it might be a promoted variable where the zero- or sign- extension
  4266. needs to be done. Handling this in the normal way is safe because no
  4267. computation is done before the call. The same is true for SSA names. */
  4268. if (TREE_CODE (from) == CALL_EXPR && ! aggregate_value_p (from, from)
  4269. && COMPLETE_TYPE_P (TREE_TYPE (from))
  4270. && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) == INTEGER_CST
  4271. && ! (((TREE_CODE (to) == VAR_DECL
  4272. || TREE_CODE (to) == PARM_DECL
  4273. || TREE_CODE (to) == RESULT_DECL)
  4274. && REG_P (DECL_RTL (to)))
  4275. || TREE_CODE (to) == SSA_NAME))
  4276. {
  4277. rtx value;
  4278. rtx bounds;
  4279. push_temp_slots ();
  4280. value = expand_normal (from);
  4281. /* Split value and bounds to store them separately. */
  4282. chkp_split_slot (value, &value, &bounds);
  4283. if (to_rtx == 0)
  4284. to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
  4285. /* Handle calls that return values in multiple non-contiguous locations.
  4286. The Irix 6 ABI has examples of this. */
  4287. if (GET_CODE (to_rtx) == PARALLEL)
  4288. {
  4289. if (GET_CODE (value) == PARALLEL)
  4290. emit_group_move (to_rtx, value);
  4291. else
  4292. emit_group_load (to_rtx, value, TREE_TYPE (from),
  4293. int_size_in_bytes (TREE_TYPE (from)));
  4294. }
  4295. else if (GET_CODE (value) == PARALLEL)
  4296. emit_group_store (to_rtx, value, TREE_TYPE (from),
  4297. int_size_in_bytes (TREE_TYPE (from)));
  4298. else if (GET_MODE (to_rtx) == BLKmode)
  4299. {
  4300. /* Handle calls that return BLKmode values in registers. */
  4301. if (REG_P (value))
  4302. copy_blkmode_from_reg (to_rtx, value, TREE_TYPE (from));
  4303. else
  4304. emit_block_move (to_rtx, value, expr_size (from), BLOCK_OP_NORMAL);
  4305. }
  4306. else
  4307. {
  4308. if (POINTER_TYPE_P (TREE_TYPE (to)))
  4309. value = convert_memory_address_addr_space
  4310. (GET_MODE (to_rtx), value,
  4311. TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (to))));
  4312. emit_move_insn (to_rtx, value);
  4313. }
  4314. /* Store bounds if required. */
  4315. if (bounds
  4316. && (BOUNDED_P (to) || chkp_type_has_pointer (TREE_TYPE (to))))
  4317. {
  4318. gcc_assert (MEM_P (to_rtx));
  4319. chkp_emit_bounds_store (bounds, value, to_rtx);
  4320. }
  4321. preserve_temp_slots (to_rtx);
  4322. pop_temp_slots ();
  4323. return;
  4324. }
  4325. /* Ordinary treatment. Expand TO to get a REG or MEM rtx. */
  4326. to_rtx = expand_expr (to, NULL_RTX, VOIDmode, EXPAND_WRITE);
  4327. /* Don't move directly into a return register. */
  4328. if (TREE_CODE (to) == RESULT_DECL
  4329. && (REG_P (to_rtx) || GET_CODE (to_rtx) == PARALLEL))
  4330. {
  4331. rtx temp;
  4332. push_temp_slots ();
  4333. /* If the source is itself a return value, it still is in a pseudo at
  4334. this point so we can move it back to the return register directly. */
  4335. if (REG_P (to_rtx)
  4336. && TYPE_MODE (TREE_TYPE (from)) == BLKmode
  4337. && TREE_CODE (from) != CALL_EXPR)
  4338. temp = copy_blkmode_to_reg (GET_MODE (to_rtx), from);
  4339. else
  4340. temp = expand_expr (from, NULL_RTX, GET_MODE (to_rtx), EXPAND_NORMAL);
  4341. /* Handle calls that return values in multiple non-contiguous locations.
  4342. The Irix 6 ABI has examples of this. */
  4343. if (GET_CODE (to_rtx) == PARALLEL)
  4344. {
  4345. if (GET_CODE (temp) == PARALLEL)
  4346. emit_group_move (to_rtx, temp);
  4347. else
  4348. emit_group_load (to_rtx, temp, TREE_TYPE (from),
  4349. int_size_in_bytes (TREE_TYPE (from)));
  4350. }
  4351. else if (temp)
  4352. emit_move_insn (to_rtx, temp);
  4353. preserve_temp_slots (to_rtx);
  4354. pop_temp_slots ();
  4355. return;
  4356. }
  4357. /* In case we are returning the contents of an object which overlaps
  4358. the place the value is being stored, use a safe function when copying
  4359. a value through a pointer into a structure value return block. */
  4360. if (TREE_CODE (to) == RESULT_DECL
  4361. && TREE_CODE (from) == INDIRECT_REF
  4362. && ADDR_SPACE_GENERIC_P
  4363. (TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (from, 0)))))
  4364. && refs_may_alias_p (to, from)
  4365. && cfun->returns_struct
  4366. && !cfun->returns_pcc_struct)
  4367. {
  4368. rtx from_rtx, size;
  4369. push_temp_slots ();
  4370. size = expr_size (from);
  4371. from_rtx = expand_normal (from);
  4372. emit_library_call (memmove_libfunc, LCT_NORMAL,
  4373. VOIDmode, 3, XEXP (to_rtx, 0), Pmode,
  4374. XEXP (from_rtx, 0), Pmode,
  4375. convert_to_mode (TYPE_MODE (sizetype),
  4376. size, TYPE_UNSIGNED (sizetype)),
  4377. TYPE_MODE (sizetype));
  4378. preserve_temp_slots (to_rtx);
  4379. pop_temp_slots ();
  4380. return;
  4381. }
  4382. /* Compute FROM and store the value in the rtx we got. */
  4383. push_temp_slots ();
  4384. result = store_expr_with_bounds (from, to_rtx, 0, nontemporal, to);
  4385. preserve_temp_slots (result);
  4386. pop_temp_slots ();
  4387. return;
  4388. }
  4389. /* Emits nontemporal store insn that moves FROM to TO. Returns true if this
  4390. succeeded, false otherwise. */
  4391. bool
  4392. emit_storent_insn (rtx to, rtx from)
  4393. {
  4394. struct expand_operand ops[2];
  4395. machine_mode mode = GET_MODE (to);
  4396. enum insn_code code = optab_handler (storent_optab, mode);
  4397. if (code == CODE_FOR_nothing)
  4398. return false;
  4399. create_fixed_operand (&ops[0], to);
  4400. create_input_operand (&ops[1], from, mode);
  4401. return maybe_expand_insn (code, 2, ops);
  4402. }
  4403. /* Generate code for computing expression EXP,
  4404. and storing the value into TARGET.
  4405. If the mode is BLKmode then we may return TARGET itself.
  4406. It turns out that in BLKmode it doesn't cause a problem.
  4407. because C has no operators that could combine two different
  4408. assignments into the same BLKmode object with different values
  4409. with no sequence point. Will other languages need this to
  4410. be more thorough?
  4411. If CALL_PARAM_P is nonzero, this is a store into a call param on the
  4412. stack, and block moves may need to be treated specially.
  4413. If NONTEMPORAL is true, try using a nontemporal store instruction.
  4414. If BTARGET is not NULL then computed bounds of EXP are
  4415. associated with BTARGET. */
  4416. rtx
  4417. store_expr_with_bounds (tree exp, rtx target, int call_param_p,
  4418. bool nontemporal, tree btarget)
  4419. {
  4420. rtx temp;
  4421. rtx alt_rtl = NULL_RTX;
  4422. location_t loc = curr_insn_location ();
  4423. if (VOID_TYPE_P (TREE_TYPE (exp)))
  4424. {
  4425. /* C++ can generate ?: expressions with a throw expression in one
  4426. branch and an rvalue in the other. Here, we resolve attempts to
  4427. store the throw expression's nonexistent result. */
  4428. gcc_assert (!call_param_p);
  4429. expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
  4430. return NULL_RTX;
  4431. }
  4432. if (TREE_CODE (exp) == COMPOUND_EXPR)
  4433. {
  4434. /* Perform first part of compound expression, then assign from second
  4435. part. */
  4436. expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
  4437. call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
  4438. return store_expr_with_bounds (TREE_OPERAND (exp, 1), target,
  4439. call_param_p, nontemporal, btarget);
  4440. }
  4441. else if (TREE_CODE (exp) == COND_EXPR && GET_MODE (target) == BLKmode)
  4442. {
  4443. /* For conditional expression, get safe form of the target. Then
  4444. test the condition, doing the appropriate assignment on either
  4445. side. This avoids the creation of unnecessary temporaries.
  4446. For non-BLKmode, it is more efficient not to do this. */
  4447. rtx_code_label *lab1 = gen_label_rtx (), *lab2 = gen_label_rtx ();
  4448. do_pending_stack_adjust ();
  4449. NO_DEFER_POP;
  4450. jumpifnot (TREE_OPERAND (exp, 0), lab1, -1);
  4451. store_expr_with_bounds (TREE_OPERAND (exp, 1), target, call_param_p,
  4452. nontemporal, btarget);
  4453. emit_jump_insn (gen_jump (lab2));
  4454. emit_barrier ();
  4455. emit_label (lab1);
  4456. store_expr_with_bounds (TREE_OPERAND (exp, 2), target, call_param_p,
  4457. nontemporal, btarget);
  4458. emit_label (lab2);
  4459. OK_DEFER_POP;
  4460. return NULL_RTX;
  4461. }
  4462. else if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target))
  4463. /* If this is a scalar in a register that is stored in a wider mode
  4464. than the declared mode, compute the result into its declared mode
  4465. and then convert to the wider mode. Our value is the computed
  4466. expression. */
  4467. {
  4468. rtx inner_target = 0;
  4469. /* We can do the conversion inside EXP, which will often result
  4470. in some optimizations. Do the conversion in two steps: first
  4471. change the signedness, if needed, then the extend. But don't
  4472. do this if the type of EXP is a subtype of something else
  4473. since then the conversion might involve more than just
  4474. converting modes. */
  4475. if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
  4476. && TREE_TYPE (TREE_TYPE (exp)) == 0
  4477. && GET_MODE_PRECISION (GET_MODE (target))
  4478. == TYPE_PRECISION (TREE_TYPE (exp)))
  4479. {
  4480. if (!SUBREG_CHECK_PROMOTED_SIGN (target,
  4481. TYPE_UNSIGNED (TREE_TYPE (exp))))
  4482. {
  4483. /* Some types, e.g. Fortran's logical*4, won't have a signed
  4484. version, so use the mode instead. */
  4485. tree ntype
  4486. = (signed_or_unsigned_type_for
  4487. (SUBREG_PROMOTED_SIGN (target), TREE_TYPE (exp)));
  4488. if (ntype == NULL)
  4489. ntype = lang_hooks.types.type_for_mode
  4490. (TYPE_MODE (TREE_TYPE (exp)),
  4491. SUBREG_PROMOTED_SIGN (target));
  4492. exp = fold_convert_loc (loc, ntype, exp);
  4493. }
  4494. exp = fold_convert_loc (loc, lang_hooks.types.type_for_mode
  4495. (GET_MODE (SUBREG_REG (target)),
  4496. SUBREG_PROMOTED_SIGN (target)),
  4497. exp);
  4498. inner_target = SUBREG_REG (target);
  4499. }
  4500. temp = expand_expr (exp, inner_target, VOIDmode,
  4501. call_param_p ? EXPAND_STACK_PARM : EXPAND_NORMAL);
  4502. /* Handle bounds returned by call. */
  4503. if (TREE_CODE (exp) == CALL_EXPR)
  4504. {
  4505. rtx bounds;
  4506. chkp_split_slot (temp, &temp, &bounds);
  4507. if (bounds && btarget)
  4508. {
  4509. gcc_assert (TREE_CODE (btarget) == SSA_NAME);
  4510. rtx tmp = targetm.calls.load_returned_bounds (bounds);
  4511. chkp_set_rtl_bounds (btarget, tmp);
  4512. }
  4513. }
  4514. /* If TEMP is a VOIDmode constant, use convert_modes to make
  4515. sure that we properly convert it. */
  4516. if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode)
  4517. {
  4518. temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
  4519. temp, SUBREG_PROMOTED_SIGN (target));
  4520. temp = convert_modes (GET_MODE (SUBREG_REG (target)),
  4521. GET_MODE (target), temp,
  4522. SUBREG_PROMOTED_SIGN (target));
  4523. }
  4524. convert_move (SUBREG_REG (target), temp,
  4525. SUBREG_PROMOTED_SIGN (target));
  4526. return NULL_RTX;
  4527. }
  4528. else if ((TREE_CODE (exp) == STRING_CST
  4529. || (TREE_CODE (exp) == MEM_REF
  4530. && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
  4531. && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
  4532. == STRING_CST
  4533. && integer_zerop (TREE_OPERAND (exp, 1))))
  4534. && !nontemporal && !call_param_p
  4535. && MEM_P (target))
  4536. {
  4537. /* Optimize initialization of an array with a STRING_CST. */
  4538. HOST_WIDE_INT exp_len, str_copy_len;
  4539. rtx dest_mem;
  4540. tree str = TREE_CODE (exp) == STRING_CST
  4541. ? exp : TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
  4542. exp_len = int_expr_size (exp);
  4543. if (exp_len <= 0)
  4544. goto normal_expr;
  4545. if (TREE_STRING_LENGTH (str) <= 0)
  4546. goto normal_expr;
  4547. str_copy_len = strlen (TREE_STRING_POINTER (str));
  4548. if (str_copy_len < TREE_STRING_LENGTH (str) - 1)
  4549. goto normal_expr;
  4550. str_copy_len = TREE_STRING_LENGTH (str);
  4551. if ((STORE_MAX_PIECES & (STORE_MAX_PIECES - 1)) == 0
  4552. && TREE_STRING_POINTER (str)[TREE_STRING_LENGTH (str) - 1] == '\0')
  4553. {
  4554. str_copy_len += STORE_MAX_PIECES - 1;
  4555. str_copy_len &= ~(STORE_MAX_PIECES - 1);
  4556. }
  4557. str_copy_len = MIN (str_copy_len, exp_len);
  4558. if (!can_store_by_pieces (str_copy_len, builtin_strncpy_read_str,
  4559. CONST_CAST (char *, TREE_STRING_POINTER (str)),
  4560. MEM_ALIGN (target), false))
  4561. goto normal_expr;
  4562. dest_mem = target;
  4563. dest_mem = store_by_pieces (dest_mem,
  4564. str_copy_len, builtin_strncpy_read_str,
  4565. CONST_CAST (char *,
  4566. TREE_STRING_POINTER (str)),
  4567. MEM_ALIGN (target), false,
  4568. exp_len > str_copy_len ? 1 : 0);
  4569. if (exp_len > str_copy_len)
  4570. clear_storage (adjust_address (dest_mem, BLKmode, 0),
  4571. GEN_INT (exp_len - str_copy_len),
  4572. BLOCK_OP_NORMAL);
  4573. return NULL_RTX;
  4574. }
  4575. else
  4576. {
  4577. rtx tmp_target;
  4578. normal_expr:
  4579. /* If we want to use a nontemporal store, force the value to
  4580. register first. */
  4581. tmp_target = nontemporal ? NULL_RTX : target;
  4582. temp = expand_expr_real (exp, tmp_target, GET_MODE (target),
  4583. (call_param_p
  4584. ? EXPAND_STACK_PARM : EXPAND_NORMAL),
  4585. &alt_rtl, false);
  4586. /* Handle bounds returned by call. */
  4587. if (TREE_CODE (exp) == CALL_EXPR)
  4588. {
  4589. rtx bounds;
  4590. chkp_split_slot (temp, &temp, &bounds);
  4591. if (bounds && btarget)
  4592. {
  4593. gcc_assert (TREE_CODE (btarget) == SSA_NAME);
  4594. rtx tmp = targetm.calls.load_returned_bounds (bounds);
  4595. chkp_set_rtl_bounds (btarget, tmp);
  4596. }
  4597. }
  4598. }
  4599. /* If TEMP is a VOIDmode constant and the mode of the type of EXP is not
  4600. the same as that of TARGET, adjust the constant. This is needed, for
  4601. example, in case it is a CONST_DOUBLE or CONST_WIDE_INT and we want
  4602. only a word-sized value. */
  4603. if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
  4604. && TREE_CODE (exp) != ERROR_MARK
  4605. && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
  4606. temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
  4607. temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
  4608. /* If value was not generated in the target, store it there.
  4609. Convert the value to TARGET's type first if necessary and emit the
  4610. pending incrementations that have been queued when expanding EXP.
  4611. Note that we cannot emit the whole queue blindly because this will
  4612. effectively disable the POST_INC optimization later.
  4613. If TEMP and TARGET compare equal according to rtx_equal_p, but
  4614. one or both of them are volatile memory refs, we have to distinguish
  4615. two cases:
  4616. - expand_expr has used TARGET. In this case, we must not generate
  4617. another copy. This can be detected by TARGET being equal according
  4618. to == .
  4619. - expand_expr has not used TARGET - that means that the source just
  4620. happens to have the same RTX form. Since temp will have been created
  4621. by expand_expr, it will compare unequal according to == .
  4622. We must generate a copy in this case, to reach the correct number
  4623. of volatile memory references. */
  4624. if ((! rtx_equal_p (temp, target)
  4625. || (temp != target && (side_effects_p (temp)
  4626. || side_effects_p (target))))
  4627. && TREE_CODE (exp) != ERROR_MARK
  4628. /* If store_expr stores a DECL whose DECL_RTL(exp) == TARGET,
  4629. but TARGET is not valid memory reference, TEMP will differ
  4630. from TARGET although it is really the same location. */
  4631. && !(alt_rtl
  4632. && rtx_equal_p (alt_rtl, target)
  4633. && !side_effects_p (alt_rtl)
  4634. && !side_effects_p (target))
  4635. /* If there's nothing to copy, don't bother. Don't call
  4636. expr_size unless necessary, because some front-ends (C++)
  4637. expr_size-hook must not be given objects that are not
  4638. supposed to be bit-copied or bit-initialized. */
  4639. && expr_size (exp) != const0_rtx)
  4640. {
  4641. if (GET_MODE (temp) != GET_MODE (target) && GET_MODE (temp) != VOIDmode)
  4642. {
  4643. if (GET_MODE (target) == BLKmode)
  4644. {
  4645. /* Handle calls that return BLKmode values in registers. */
  4646. if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
  4647. copy_blkmode_from_reg (target, temp, TREE_TYPE (exp));
  4648. else
  4649. store_bit_field (target,
  4650. INTVAL (expr_size (exp)) * BITS_PER_UNIT,
  4651. 0, 0, 0, GET_MODE (temp), temp);
  4652. }
  4653. else
  4654. convert_move (target, temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
  4655. }
  4656. else if (GET_MODE (temp) == BLKmode && TREE_CODE (exp) == STRING_CST)
  4657. {
  4658. /* Handle copying a string constant into an array. The string
  4659. constant may be shorter than the array. So copy just the string's
  4660. actual length, and clear the rest. First get the size of the data
  4661. type of the string, which is actually the size of the target. */
  4662. rtx size = expr_size (exp);
  4663. if (CONST_INT_P (size)
  4664. && INTVAL (size) < TREE_STRING_LENGTH (exp))
  4665. emit_block_move (target, temp, size,
  4666. (call_param_p
  4667. ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
  4668. else
  4669. {
  4670. machine_mode pointer_mode
  4671. = targetm.addr_space.pointer_mode (MEM_ADDR_SPACE (target));
  4672. machine_mode address_mode = get_address_mode (target);
  4673. /* Compute the size of the data to copy from the string. */
  4674. tree copy_size
  4675. = size_binop_loc (loc, MIN_EXPR,
  4676. make_tree (sizetype, size),
  4677. size_int (TREE_STRING_LENGTH (exp)));
  4678. rtx copy_size_rtx
  4679. = expand_expr (copy_size, NULL_RTX, VOIDmode,
  4680. (call_param_p
  4681. ? EXPAND_STACK_PARM : EXPAND_NORMAL));
  4682. rtx_code_label *label = 0;
  4683. /* Copy that much. */
  4684. copy_size_rtx = convert_to_mode (pointer_mode, copy_size_rtx,
  4685. TYPE_UNSIGNED (sizetype));
  4686. emit_block_move (target, temp, copy_size_rtx,
  4687. (call_param_p
  4688. ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
  4689. /* Figure out how much is left in TARGET that we have to clear.
  4690. Do all calculations in pointer_mode. */
  4691. if (CONST_INT_P (copy_size_rtx))
  4692. {
  4693. size = plus_constant (address_mode, size,
  4694. -INTVAL (copy_size_rtx));
  4695. target = adjust_address (target, BLKmode,
  4696. INTVAL (copy_size_rtx));
  4697. }
  4698. else
  4699. {
  4700. size = expand_binop (TYPE_MODE (sizetype), sub_optab, size,
  4701. copy_size_rtx, NULL_RTX, 0,
  4702. OPTAB_LIB_WIDEN);
  4703. if (GET_MODE (copy_size_rtx) != address_mode)
  4704. copy_size_rtx = convert_to_mode (address_mode,
  4705. copy_size_rtx,
  4706. TYPE_UNSIGNED (sizetype));
  4707. target = offset_address (target, copy_size_rtx,
  4708. highest_pow2_factor (copy_size));
  4709. label = gen_label_rtx ();
  4710. emit_cmp_and_jump_insns (size, const0_rtx, LT, NULL_RTX,
  4711. GET_MODE (size), 0, label);
  4712. }
  4713. if (size != const0_rtx)
  4714. clear_storage (target, size, BLOCK_OP_NORMAL);
  4715. if (label)
  4716. emit_label (label);
  4717. }
  4718. }
  4719. /* Handle calls that return values in multiple non-contiguous locations.
  4720. The Irix 6 ABI has examples of this. */
  4721. else if (GET_CODE (target) == PARALLEL)
  4722. {
  4723. if (GET_CODE (temp) == PARALLEL)
  4724. emit_group_move (target, temp);
  4725. else
  4726. emit_group_load (target, temp, TREE_TYPE (exp),
  4727. int_size_in_bytes (TREE_TYPE (exp)));
  4728. }
  4729. else if (GET_CODE (temp) == PARALLEL)
  4730. emit_group_store (target, temp, TREE_TYPE (exp),
  4731. int_size_in_bytes (TREE_TYPE (exp)));
  4732. else if (GET_MODE (temp) == BLKmode)
  4733. emit_block_move (target, temp, expr_size (exp),
  4734. (call_param_p
  4735. ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
  4736. /* If we emit a nontemporal store, there is nothing else to do. */
  4737. else if (nontemporal && emit_storent_insn (target, temp))
  4738. ;
  4739. else
  4740. {
  4741. temp = force_operand (temp, target);
  4742. if (temp != target)
  4743. emit_move_insn (target, temp);
  4744. }
  4745. }
  4746. return NULL_RTX;
  4747. }
  4748. /* Same as store_expr_with_bounds but ignoring bounds of EXP. */
  4749. rtx
  4750. store_expr (tree exp, rtx target, int call_param_p, bool nontemporal)
  4751. {
  4752. return store_expr_with_bounds (exp, target, call_param_p, nontemporal, NULL);
  4753. }
  4754. /* Return true if field F of structure TYPE is a flexible array. */
  4755. static bool
  4756. flexible_array_member_p (const_tree f, const_tree type)
  4757. {
  4758. const_tree tf;
  4759. tf = TREE_TYPE (f);
  4760. return (DECL_CHAIN (f) == NULL
  4761. && TREE_CODE (tf) == ARRAY_TYPE
  4762. && TYPE_DOMAIN (tf)
  4763. && TYPE_MIN_VALUE (TYPE_DOMAIN (tf))
  4764. && integer_zerop (TYPE_MIN_VALUE (TYPE_DOMAIN (tf)))
  4765. && !TYPE_MAX_VALUE (TYPE_DOMAIN (tf))
  4766. && int_size_in_bytes (type) >= 0);
  4767. }
  4768. /* If FOR_CTOR_P, return the number of top-level elements that a constructor
  4769. must have in order for it to completely initialize a value of type TYPE.
  4770. Return -1 if the number isn't known.
  4771. If !FOR_CTOR_P, return an estimate of the number of scalars in TYPE. */
  4772. static HOST_WIDE_INT
  4773. count_type_elements (const_tree type, bool for_ctor_p)
  4774. {
  4775. switch (TREE_CODE (type))
  4776. {
  4777. case ARRAY_TYPE:
  4778. {
  4779. tree nelts;
  4780. nelts = array_type_nelts (type);
  4781. if (nelts && tree_fits_uhwi_p (nelts))
  4782. {
  4783. unsigned HOST_WIDE_INT n;
  4784. n = tree_to_uhwi (nelts) + 1;
  4785. if (n == 0 || for_ctor_p)
  4786. return n;
  4787. else
  4788. return n * count_type_elements (TREE_TYPE (type), false);
  4789. }
  4790. return for_ctor_p ? -1 : 1;
  4791. }
  4792. case RECORD_TYPE:
  4793. {
  4794. unsigned HOST_WIDE_INT n;
  4795. tree f;
  4796. n = 0;
  4797. for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
  4798. if (TREE_CODE (f) == FIELD_DECL)
  4799. {
  4800. if (!for_ctor_p)
  4801. n += count_type_elements (TREE_TYPE (f), false);
  4802. else if (!flexible_array_member_p (f, type))
  4803. /* Don't count flexible arrays, which are not supposed
  4804. to be initialized. */
  4805. n += 1;
  4806. }
  4807. return n;
  4808. }
  4809. case UNION_TYPE:
  4810. case QUAL_UNION_TYPE:
  4811. {
  4812. tree f;
  4813. HOST_WIDE_INT n, m;
  4814. gcc_assert (!for_ctor_p);
  4815. /* Estimate the number of scalars in each field and pick the
  4816. maximum. Other estimates would do instead; the idea is simply
  4817. to make sure that the estimate is not sensitive to the ordering
  4818. of the fields. */
  4819. n = 1;
  4820. for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
  4821. if (TREE_CODE (f) == FIELD_DECL)
  4822. {
  4823. m = count_type_elements (TREE_TYPE (f), false);
  4824. /* If the field doesn't span the whole union, add an extra
  4825. scalar for the rest. */
  4826. if (simple_cst_equal (TYPE_SIZE (TREE_TYPE (f)),
  4827. TYPE_SIZE (type)) != 1)
  4828. m++;
  4829. if (n < m)
  4830. n = m;
  4831. }
  4832. return n;
  4833. }
  4834. case COMPLEX_TYPE:
  4835. return 2;
  4836. case VECTOR_TYPE:
  4837. return TYPE_VECTOR_SUBPARTS (type);
  4838. case INTEGER_TYPE:
  4839. case REAL_TYPE:
  4840. case FIXED_POINT_TYPE:
  4841. case ENUMERAL_TYPE:
  4842. case BOOLEAN_TYPE:
  4843. case POINTER_TYPE:
  4844. case OFFSET_TYPE:
  4845. case REFERENCE_TYPE:
  4846. case NULLPTR_TYPE:
  4847. return 1;
  4848. case ERROR_MARK:
  4849. return 0;
  4850. case VOID_TYPE:
  4851. case METHOD_TYPE:
  4852. case FUNCTION_TYPE:
  4853. case LANG_TYPE:
  4854. default:
  4855. gcc_unreachable ();
  4856. }
  4857. }
  4858. /* Helper for categorize_ctor_elements. Identical interface. */
  4859. static bool
  4860. categorize_ctor_elements_1 (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
  4861. HOST_WIDE_INT *p_init_elts, bool *p_complete)
  4862. {
  4863. unsigned HOST_WIDE_INT idx;
  4864. HOST_WIDE_INT nz_elts, init_elts, num_fields;
  4865. tree value, purpose, elt_type;
  4866. /* Whether CTOR is a valid constant initializer, in accordance with what
  4867. initializer_constant_valid_p does. If inferred from the constructor
  4868. elements, true until proven otherwise. */
  4869. bool const_from_elts_p = constructor_static_from_elts_p (ctor);
  4870. bool const_p = const_from_elts_p ? true : TREE_STATIC (ctor);
  4871. nz_elts = 0;
  4872. init_elts = 0;
  4873. num_fields = 0;
  4874. elt_type = NULL_TREE;
  4875. FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
  4876. {
  4877. HOST_WIDE_INT mult = 1;
  4878. if (purpose && TREE_CODE (purpose) == RANGE_EXPR)
  4879. {
  4880. tree lo_index = TREE_OPERAND (purpose, 0);
  4881. tree hi_index = TREE_OPERAND (purpose, 1);
  4882. if (tree_fits_uhwi_p (lo_index) && tree_fits_uhwi_p (hi_index))
  4883. mult = (tree_to_uhwi (hi_index)
  4884. - tree_to_uhwi (lo_index) + 1);
  4885. }
  4886. num_fields += mult;
  4887. elt_type = TREE_TYPE (value);
  4888. switch (TREE_CODE (value))
  4889. {
  4890. case CONSTRUCTOR:
  4891. {
  4892. HOST_WIDE_INT nz = 0, ic = 0;
  4893. bool const_elt_p = categorize_ctor_elements_1 (value, &nz, &ic,
  4894. p_complete);
  4895. nz_elts += mult * nz;
  4896. init_elts += mult * ic;
  4897. if (const_from_elts_p && const_p)
  4898. const_p = const_elt_p;
  4899. }
  4900. break;
  4901. case INTEGER_CST:
  4902. case REAL_CST:
  4903. case FIXED_CST:
  4904. if (!initializer_zerop (value))
  4905. nz_elts += mult;
  4906. init_elts += mult;
  4907. break;
  4908. case STRING_CST:
  4909. nz_elts += mult * TREE_STRING_LENGTH (value);
  4910. init_elts += mult * TREE_STRING_LENGTH (value);
  4911. break;
  4912. case COMPLEX_CST:
  4913. if (!initializer_zerop (TREE_REALPART (value)))
  4914. nz_elts += mult;
  4915. if (!initializer_zerop (TREE_IMAGPART (value)))
  4916. nz_elts += mult;
  4917. init_elts += mult;
  4918. break;
  4919. case VECTOR_CST:
  4920. {
  4921. unsigned i;
  4922. for (i = 0; i < VECTOR_CST_NELTS (value); ++i)
  4923. {
  4924. tree v = VECTOR_CST_ELT (value, i);
  4925. if (!initializer_zerop (v))
  4926. nz_elts += mult;
  4927. init_elts += mult;
  4928. }
  4929. }
  4930. break;
  4931. default:
  4932. {
  4933. HOST_WIDE_INT tc = count_type_elements (elt_type, false);
  4934. nz_elts += mult * tc;
  4935. init_elts += mult * tc;
  4936. if (const_from_elts_p && const_p)
  4937. const_p = initializer_constant_valid_p (value, elt_type)
  4938. != NULL_TREE;
  4939. }
  4940. break;
  4941. }
  4942. }
  4943. if (*p_complete && !complete_ctor_at_level_p (TREE_TYPE (ctor),
  4944. num_fields, elt_type))
  4945. *p_complete = false;
  4946. *p_nz_elts += nz_elts;
  4947. *p_init_elts += init_elts;
  4948. return const_p;
  4949. }
  4950. /* Examine CTOR to discover:
  4951. * how many scalar fields are set to nonzero values,
  4952. and place it in *P_NZ_ELTS;
  4953. * how many scalar fields in total are in CTOR,
  4954. and place it in *P_ELT_COUNT.
  4955. * whether the constructor is complete -- in the sense that every
  4956. meaningful byte is explicitly given a value --
  4957. and place it in *P_COMPLETE.
  4958. Return whether or not CTOR is a valid static constant initializer, the same
  4959. as "initializer_constant_valid_p (CTOR, TREE_TYPE (CTOR)) != 0". */
  4960. bool
  4961. categorize_ctor_elements (const_tree ctor, HOST_WIDE_INT *p_nz_elts,
  4962. HOST_WIDE_INT *p_init_elts, bool *p_complete)
  4963. {
  4964. *p_nz_elts = 0;
  4965. *p_init_elts = 0;
  4966. *p_complete = true;
  4967. return categorize_ctor_elements_1 (ctor, p_nz_elts, p_init_elts, p_complete);
  4968. }
  4969. /* TYPE is initialized by a constructor with NUM_ELTS elements, the last
  4970. of which had type LAST_TYPE. Each element was itself a complete
  4971. initializer, in the sense that every meaningful byte was explicitly
  4972. given a value. Return true if the same is true for the constructor
  4973. as a whole. */
  4974. bool
  4975. complete_ctor_at_level_p (const_tree type, HOST_WIDE_INT num_elts,
  4976. const_tree last_type)
  4977. {
  4978. if (TREE_CODE (type) == UNION_TYPE
  4979. || TREE_CODE (type) == QUAL_UNION_TYPE)
  4980. {
  4981. if (num_elts == 0)
  4982. return false;
  4983. gcc_assert (num_elts == 1 && last_type);
  4984. /* ??? We could look at each element of the union, and find the
  4985. largest element. Which would avoid comparing the size of the
  4986. initialized element against any tail padding in the union.
  4987. Doesn't seem worth the effort... */
  4988. return simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (last_type)) == 1;
  4989. }
  4990. return count_type_elements (type, true) == num_elts;
  4991. }
  4992. /* Return 1 if EXP contains mostly (3/4) zeros. */
  4993. static int
  4994. mostly_zeros_p (const_tree exp)
  4995. {
  4996. if (TREE_CODE (exp) == CONSTRUCTOR)
  4997. {
  4998. HOST_WIDE_INT nz_elts, init_elts;
  4999. bool complete_p;
  5000. categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
  5001. return !complete_p || nz_elts < init_elts / 4;
  5002. }
  5003. return initializer_zerop (exp);
  5004. }
  5005. /* Return 1 if EXP contains all zeros. */
  5006. static int
  5007. all_zeros_p (const_tree exp)
  5008. {
  5009. if (TREE_CODE (exp) == CONSTRUCTOR)
  5010. {
  5011. HOST_WIDE_INT nz_elts, init_elts;
  5012. bool complete_p;
  5013. categorize_ctor_elements (exp, &nz_elts, &init_elts, &complete_p);
  5014. return nz_elts == 0;
  5015. }
  5016. return initializer_zerop (exp);
  5017. }
  5018. /* Helper function for store_constructor.
  5019. TARGET, BITSIZE, BITPOS, MODE, EXP are as for store_field.
  5020. CLEARED is as for store_constructor.
  5021. ALIAS_SET is the alias set to use for any stores.
  5022. This provides a recursive shortcut back to store_constructor when it isn't
  5023. necessary to go through store_field. This is so that we can pass through
  5024. the cleared field to let store_constructor know that we may not have to
  5025. clear a substructure if the outer structure has already been cleared. */
  5026. static void
  5027. store_constructor_field (rtx target, unsigned HOST_WIDE_INT bitsize,
  5028. HOST_WIDE_INT bitpos, machine_mode mode,
  5029. tree exp, int cleared, alias_set_type alias_set)
  5030. {
  5031. if (TREE_CODE (exp) == CONSTRUCTOR
  5032. /* We can only call store_constructor recursively if the size and
  5033. bit position are on a byte boundary. */
  5034. && bitpos % BITS_PER_UNIT == 0
  5035. && (bitsize > 0 && bitsize % BITS_PER_UNIT == 0)
  5036. /* If we have a nonzero bitpos for a register target, then we just
  5037. let store_field do the bitfield handling. This is unlikely to
  5038. generate unnecessary clear instructions anyways. */
  5039. && (bitpos == 0 || MEM_P (target)))
  5040. {
  5041. if (MEM_P (target))
  5042. target
  5043. = adjust_address (target,
  5044. GET_MODE (target) == BLKmode
  5045. || 0 != (bitpos
  5046. % GET_MODE_ALIGNMENT (GET_MODE (target)))
  5047. ? BLKmode : VOIDmode, bitpos / BITS_PER_UNIT);
  5048. /* Update the alias set, if required. */
  5049. if (MEM_P (target) && ! MEM_KEEP_ALIAS_SET_P (target)
  5050. && MEM_ALIAS_SET (target) != 0)
  5051. {
  5052. target = copy_rtx (target);
  5053. set_mem_alias_set (target, alias_set);
  5054. }
  5055. store_constructor (exp, target, cleared, bitsize / BITS_PER_UNIT);
  5056. }
  5057. else
  5058. store_field (target, bitsize, bitpos, 0, 0, mode, exp, alias_set, false);
  5059. }
  5060. /* Returns the number of FIELD_DECLs in TYPE. */
  5061. static int
  5062. fields_length (const_tree type)
  5063. {
  5064. tree t = TYPE_FIELDS (type);
  5065. int count = 0;
  5066. for (; t; t = DECL_CHAIN (t))
  5067. if (TREE_CODE (t) == FIELD_DECL)
  5068. ++count;
  5069. return count;
  5070. }
  5071. /* Store the value of constructor EXP into the rtx TARGET.
  5072. TARGET is either a REG or a MEM; we know it cannot conflict, since
  5073. safe_from_p has been called.
  5074. CLEARED is true if TARGET is known to have been zero'd.
  5075. SIZE is the number of bytes of TARGET we are allowed to modify: this
  5076. may not be the same as the size of EXP if we are assigning to a field
  5077. which has been packed to exclude padding bits. */
  5078. static void
  5079. store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
  5080. {
  5081. tree type = TREE_TYPE (exp);
  5082. #ifdef WORD_REGISTER_OPERATIONS
  5083. HOST_WIDE_INT exp_size = int_size_in_bytes (type);
  5084. #endif
  5085. switch (TREE_CODE (type))
  5086. {
  5087. case RECORD_TYPE:
  5088. case UNION_TYPE:
  5089. case QUAL_UNION_TYPE:
  5090. {
  5091. unsigned HOST_WIDE_INT idx;
  5092. tree field, value;
  5093. /* If size is zero or the target is already cleared, do nothing. */
  5094. if (size == 0 || cleared)
  5095. cleared = 1;
  5096. /* We either clear the aggregate or indicate the value is dead. */
  5097. else if ((TREE_CODE (type) == UNION_TYPE
  5098. || TREE_CODE (type) == QUAL_UNION_TYPE)
  5099. && ! CONSTRUCTOR_ELTS (exp))
  5100. /* If the constructor is empty, clear the union. */
  5101. {
  5102. clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
  5103. cleared = 1;
  5104. }
  5105. /* If we are building a static constructor into a register,
  5106. set the initial value as zero so we can fold the value into
  5107. a constant. But if more than one register is involved,
  5108. this probably loses. */
  5109. else if (REG_P (target) && TREE_STATIC (exp)
  5110. && GET_MODE_SIZE (GET_MODE (target)) <= UNITS_PER_WORD)
  5111. {
  5112. emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
  5113. cleared = 1;
  5114. }
  5115. /* If the constructor has fewer fields than the structure or
  5116. if we are initializing the structure to mostly zeros, clear
  5117. the whole structure first. Don't do this if TARGET is a
  5118. register whose mode size isn't equal to SIZE since
  5119. clear_storage can't handle this case. */
  5120. else if (size > 0
  5121. && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp))
  5122. != fields_length (type))
  5123. || mostly_zeros_p (exp))
  5124. && (!REG_P (target)
  5125. || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target))
  5126. == size)))
  5127. {
  5128. clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
  5129. cleared = 1;
  5130. }
  5131. if (REG_P (target) && !cleared)
  5132. emit_clobber (target);
  5133. /* Store each element of the constructor into the
  5134. corresponding field of TARGET. */
  5135. FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
  5136. {
  5137. machine_mode mode;
  5138. HOST_WIDE_INT bitsize;
  5139. HOST_WIDE_INT bitpos = 0;
  5140. tree offset;
  5141. rtx to_rtx = target;
  5142. /* Just ignore missing fields. We cleared the whole
  5143. structure, above, if any fields are missing. */
  5144. if (field == 0)
  5145. continue;
  5146. if (cleared && initializer_zerop (value))
  5147. continue;
  5148. if (tree_fits_uhwi_p (DECL_SIZE (field)))
  5149. bitsize = tree_to_uhwi (DECL_SIZE (field));
  5150. else
  5151. bitsize = -1;
  5152. mode = DECL_MODE (field);
  5153. if (DECL_BIT_FIELD (field))
  5154. mode = VOIDmode;
  5155. offset = DECL_FIELD_OFFSET (field);
  5156. if (tree_fits_shwi_p (offset)
  5157. && tree_fits_shwi_p (bit_position (field)))
  5158. {
  5159. bitpos = int_bit_position (field);
  5160. offset = 0;
  5161. }
  5162. else
  5163. bitpos = tree_to_shwi (DECL_FIELD_BIT_OFFSET (field));
  5164. if (offset)
  5165. {
  5166. machine_mode address_mode;
  5167. rtx offset_rtx;
  5168. offset
  5169. = SUBSTITUTE_PLACEHOLDER_IN_EXPR (offset,
  5170. make_tree (TREE_TYPE (exp),
  5171. target));
  5172. offset_rtx = expand_normal (offset);
  5173. gcc_assert (MEM_P (to_rtx));
  5174. address_mode = get_address_mode (to_rtx);
  5175. if (GET_MODE (offset_rtx) != address_mode)
  5176. offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
  5177. to_rtx = offset_address (to_rtx, offset_rtx,
  5178. highest_pow2_factor (offset));
  5179. }
  5180. #ifdef WORD_REGISTER_OPERATIONS
  5181. /* If this initializes a field that is smaller than a
  5182. word, at the start of a word, try to widen it to a full
  5183. word. This special case allows us to output C++ member
  5184. function initializations in a form that the optimizers
  5185. can understand. */
  5186. if (REG_P (target)
  5187. && bitsize < BITS_PER_WORD
  5188. && bitpos % BITS_PER_WORD == 0
  5189. && GET_MODE_CLASS (mode) == MODE_INT
  5190. && TREE_CODE (value) == INTEGER_CST
  5191. && exp_size >= 0
  5192. && bitpos + BITS_PER_WORD <= exp_size * BITS_PER_UNIT)
  5193. {
  5194. tree type = TREE_TYPE (value);
  5195. if (TYPE_PRECISION (type) < BITS_PER_WORD)
  5196. {
  5197. type = lang_hooks.types.type_for_mode
  5198. (word_mode, TYPE_UNSIGNED (type));
  5199. value = fold_convert (type, value);
  5200. }
  5201. if (BYTES_BIG_ENDIAN)
  5202. value
  5203. = fold_build2 (LSHIFT_EXPR, type, value,
  5204. build_int_cst (type,
  5205. BITS_PER_WORD - bitsize));
  5206. bitsize = BITS_PER_WORD;
  5207. mode = word_mode;
  5208. }
  5209. #endif
  5210. if (MEM_P (to_rtx) && !MEM_KEEP_ALIAS_SET_P (to_rtx)
  5211. && DECL_NONADDRESSABLE_P (field))
  5212. {
  5213. to_rtx = copy_rtx (to_rtx);
  5214. MEM_KEEP_ALIAS_SET_P (to_rtx) = 1;
  5215. }
  5216. store_constructor_field (to_rtx, bitsize, bitpos, mode,
  5217. value, cleared,
  5218. get_alias_set (TREE_TYPE (field)));
  5219. }
  5220. break;
  5221. }
  5222. case ARRAY_TYPE:
  5223. {
  5224. tree value, index;
  5225. unsigned HOST_WIDE_INT i;
  5226. int need_to_clear;
  5227. tree domain;
  5228. tree elttype = TREE_TYPE (type);
  5229. int const_bounds_p;
  5230. HOST_WIDE_INT minelt = 0;
  5231. HOST_WIDE_INT maxelt = 0;
  5232. domain = TYPE_DOMAIN (type);
  5233. const_bounds_p = (TYPE_MIN_VALUE (domain)
  5234. && TYPE_MAX_VALUE (domain)
  5235. && tree_fits_shwi_p (TYPE_MIN_VALUE (domain))
  5236. && tree_fits_shwi_p (TYPE_MAX_VALUE (domain)));
  5237. /* If we have constant bounds for the range of the type, get them. */
  5238. if (const_bounds_p)
  5239. {
  5240. minelt = tree_to_shwi (TYPE_MIN_VALUE (domain));
  5241. maxelt = tree_to_shwi (TYPE_MAX_VALUE (domain));
  5242. }
  5243. /* If the constructor has fewer elements than the array, clear
  5244. the whole array first. Similarly if this is static
  5245. constructor of a non-BLKmode object. */
  5246. if (cleared)
  5247. need_to_clear = 0;
  5248. else if (REG_P (target) && TREE_STATIC (exp))
  5249. need_to_clear = 1;
  5250. else
  5251. {
  5252. unsigned HOST_WIDE_INT idx;
  5253. tree index, value;
  5254. HOST_WIDE_INT count = 0, zero_count = 0;
  5255. need_to_clear = ! const_bounds_p;
  5256. /* This loop is a more accurate version of the loop in
  5257. mostly_zeros_p (it handles RANGE_EXPR in an index). It
  5258. is also needed to check for missing elements. */
  5259. FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
  5260. {
  5261. HOST_WIDE_INT this_node_count;
  5262. if (need_to_clear)
  5263. break;
  5264. if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
  5265. {
  5266. tree lo_index = TREE_OPERAND (index, 0);
  5267. tree hi_index = TREE_OPERAND (index, 1);
  5268. if (! tree_fits_uhwi_p (lo_index)
  5269. || ! tree_fits_uhwi_p (hi_index))
  5270. {
  5271. need_to_clear = 1;
  5272. break;
  5273. }
  5274. this_node_count = (tree_to_uhwi (hi_index)
  5275. - tree_to_uhwi (lo_index) + 1);
  5276. }
  5277. else
  5278. this_node_count = 1;
  5279. count += this_node_count;
  5280. if (mostly_zeros_p (value))
  5281. zero_count += this_node_count;
  5282. }
  5283. /* Clear the entire array first if there are any missing
  5284. elements, or if the incidence of zero elements is >=
  5285. 75%. */
  5286. if (! need_to_clear
  5287. && (count < maxelt - minelt + 1
  5288. || 4 * zero_count >= 3 * count))
  5289. need_to_clear = 1;
  5290. }
  5291. if (need_to_clear && size > 0)
  5292. {
  5293. if (REG_P (target))
  5294. emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
  5295. else
  5296. clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
  5297. cleared = 1;
  5298. }
  5299. if (!cleared && REG_P (target))
  5300. /* Inform later passes that the old value is dead. */
  5301. emit_clobber (target);
  5302. /* Store each element of the constructor into the
  5303. corresponding element of TARGET, determined by counting the
  5304. elements. */
  5305. FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
  5306. {
  5307. machine_mode mode;
  5308. HOST_WIDE_INT bitsize;
  5309. HOST_WIDE_INT bitpos;
  5310. rtx xtarget = target;
  5311. if (cleared && initializer_zerop (value))
  5312. continue;
  5313. mode = TYPE_MODE (elttype);
  5314. if (mode == BLKmode)
  5315. bitsize = (tree_fits_uhwi_p (TYPE_SIZE (elttype))
  5316. ? tree_to_uhwi (TYPE_SIZE (elttype))
  5317. : -1);
  5318. else
  5319. bitsize = GET_MODE_BITSIZE (mode);
  5320. if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
  5321. {
  5322. tree lo_index = TREE_OPERAND (index, 0);
  5323. tree hi_index = TREE_OPERAND (index, 1);
  5324. rtx index_r, pos_rtx;
  5325. HOST_WIDE_INT lo, hi, count;
  5326. tree position;
  5327. /* If the range is constant and "small", unroll the loop. */
  5328. if (const_bounds_p
  5329. && tree_fits_shwi_p (lo_index)
  5330. && tree_fits_shwi_p (hi_index)
  5331. && (lo = tree_to_shwi (lo_index),
  5332. hi = tree_to_shwi (hi_index),
  5333. count = hi - lo + 1,
  5334. (!MEM_P (target)
  5335. || count <= 2
  5336. || (tree_fits_uhwi_p (TYPE_SIZE (elttype))
  5337. && (tree_to_uhwi (TYPE_SIZE (elttype)) * count
  5338. <= 40 * 8)))))
  5339. {
  5340. lo -= minelt; hi -= minelt;
  5341. for (; lo <= hi; lo++)
  5342. {
  5343. bitpos = lo * tree_to_shwi (TYPE_SIZE (elttype));
  5344. if (MEM_P (target)
  5345. && !MEM_KEEP_ALIAS_SET_P (target)
  5346. && TREE_CODE (type) == ARRAY_TYPE
  5347. && TYPE_NONALIASED_COMPONENT (type))
  5348. {
  5349. target = copy_rtx (target);
  5350. MEM_KEEP_ALIAS_SET_P (target) = 1;
  5351. }
  5352. store_constructor_field
  5353. (target, bitsize, bitpos, mode, value, cleared,
  5354. get_alias_set (elttype));
  5355. }
  5356. }
  5357. else
  5358. {
  5359. rtx_code_label *loop_start = gen_label_rtx ();
  5360. rtx_code_label *loop_end = gen_label_rtx ();
  5361. tree exit_cond;
  5362. expand_normal (hi_index);
  5363. index = build_decl (EXPR_LOCATION (exp),
  5364. VAR_DECL, NULL_TREE, domain);
  5365. index_r = gen_reg_rtx (promote_decl_mode (index, NULL));
  5366. SET_DECL_RTL (index, index_r);
  5367. store_expr (lo_index, index_r, 0, false);
  5368. /* Build the head of the loop. */
  5369. do_pending_stack_adjust ();
  5370. emit_label (loop_start);
  5371. /* Assign value to element index. */
  5372. position =
  5373. fold_convert (ssizetype,
  5374. fold_build2 (MINUS_EXPR,
  5375. TREE_TYPE (index),
  5376. index,
  5377. TYPE_MIN_VALUE (domain)));
  5378. position =
  5379. size_binop (MULT_EXPR, position,
  5380. fold_convert (ssizetype,
  5381. TYPE_SIZE_UNIT (elttype)));
  5382. pos_rtx = expand_normal (position);
  5383. xtarget = offset_address (target, pos_rtx,
  5384. highest_pow2_factor (position));
  5385. xtarget = adjust_address (xtarget, mode, 0);
  5386. if (TREE_CODE (value) == CONSTRUCTOR)
  5387. store_constructor (value, xtarget, cleared,
  5388. bitsize / BITS_PER_UNIT);
  5389. else
  5390. store_expr (value, xtarget, 0, false);
  5391. /* Generate a conditional jump to exit the loop. */
  5392. exit_cond = build2 (LT_EXPR, integer_type_node,
  5393. index, hi_index);
  5394. jumpif (exit_cond, loop_end, -1);
  5395. /* Update the loop counter, and jump to the head of
  5396. the loop. */
  5397. expand_assignment (index,
  5398. build2 (PLUS_EXPR, TREE_TYPE (index),
  5399. index, integer_one_node),
  5400. false);
  5401. emit_jump (loop_start);
  5402. /* Build the end of the loop. */
  5403. emit_label (loop_end);
  5404. }
  5405. }
  5406. else if ((index != 0 && ! tree_fits_shwi_p (index))
  5407. || ! tree_fits_uhwi_p (TYPE_SIZE (elttype)))
  5408. {
  5409. tree position;
  5410. if (index == 0)
  5411. index = ssize_int (1);
  5412. if (minelt)
  5413. index = fold_convert (ssizetype,
  5414. fold_build2 (MINUS_EXPR,
  5415. TREE_TYPE (index),
  5416. index,
  5417. TYPE_MIN_VALUE (domain)));
  5418. position =
  5419. size_binop (MULT_EXPR, index,
  5420. fold_convert (ssizetype,
  5421. TYPE_SIZE_UNIT (elttype)));
  5422. xtarget = offset_address (target,
  5423. expand_normal (position),
  5424. highest_pow2_factor (position));
  5425. xtarget = adjust_address (xtarget, mode, 0);
  5426. store_expr (value, xtarget, 0, false);
  5427. }
  5428. else
  5429. {
  5430. if (index != 0)
  5431. bitpos = ((tree_to_shwi (index) - minelt)
  5432. * tree_to_uhwi (TYPE_SIZE (elttype)));
  5433. else
  5434. bitpos = (i * tree_to_uhwi (TYPE_SIZE (elttype)));
  5435. if (MEM_P (target) && !MEM_KEEP_ALIAS_SET_P (target)
  5436. && TREE_CODE (type) == ARRAY_TYPE
  5437. && TYPE_NONALIASED_COMPONENT (type))
  5438. {
  5439. target = copy_rtx (target);
  5440. MEM_KEEP_ALIAS_SET_P (target) = 1;
  5441. }
  5442. store_constructor_field (target, bitsize, bitpos, mode, value,
  5443. cleared, get_alias_set (elttype));
  5444. }
  5445. }
  5446. break;
  5447. }
  5448. case VECTOR_TYPE:
  5449. {
  5450. unsigned HOST_WIDE_INT idx;
  5451. constructor_elt *ce;
  5452. int i;
  5453. int need_to_clear;
  5454. int icode = CODE_FOR_nothing;
  5455. tree elttype = TREE_TYPE (type);
  5456. int elt_size = tree_to_uhwi (TYPE_SIZE (elttype));
  5457. machine_mode eltmode = TYPE_MODE (elttype);
  5458. HOST_WIDE_INT bitsize;
  5459. HOST_WIDE_INT bitpos;
  5460. rtvec vector = NULL;
  5461. unsigned n_elts;
  5462. alias_set_type alias;
  5463. gcc_assert (eltmode != BLKmode);
  5464. n_elts = TYPE_VECTOR_SUBPARTS (type);
  5465. if (REG_P (target) && VECTOR_MODE_P (GET_MODE (target)))
  5466. {
  5467. machine_mode mode = GET_MODE (target);
  5468. icode = (int) optab_handler (vec_init_optab, mode);
  5469. /* Don't use vec_init<mode> if some elements have VECTOR_TYPE. */
  5470. if (icode != CODE_FOR_nothing)
  5471. {
  5472. tree value;
  5473. FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
  5474. if (TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE)
  5475. {
  5476. icode = CODE_FOR_nothing;
  5477. break;
  5478. }
  5479. }
  5480. if (icode != CODE_FOR_nothing)
  5481. {
  5482. unsigned int i;
  5483. vector = rtvec_alloc (n_elts);
  5484. for (i = 0; i < n_elts; i++)
  5485. RTVEC_ELT (vector, i) = CONST0_RTX (GET_MODE_INNER (mode));
  5486. }
  5487. }
  5488. /* If the constructor has fewer elements than the vector,
  5489. clear the whole array first. Similarly if this is static
  5490. constructor of a non-BLKmode object. */
  5491. if (cleared)
  5492. need_to_clear = 0;
  5493. else if (REG_P (target) && TREE_STATIC (exp))
  5494. need_to_clear = 1;
  5495. else
  5496. {
  5497. unsigned HOST_WIDE_INT count = 0, zero_count = 0;
  5498. tree value;
  5499. FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
  5500. {
  5501. int n_elts_here = tree_to_uhwi
  5502. (int_const_binop (TRUNC_DIV_EXPR,
  5503. TYPE_SIZE (TREE_TYPE (value)),
  5504. TYPE_SIZE (elttype)));
  5505. count += n_elts_here;
  5506. if (mostly_zeros_p (value))
  5507. zero_count += n_elts_here;
  5508. }
  5509. /* Clear the entire vector first if there are any missing elements,
  5510. or if the incidence of zero elements is >= 75%. */
  5511. need_to_clear = (count < n_elts || 4 * zero_count >= 3 * count);
  5512. }
  5513. if (need_to_clear && size > 0 && !vector)
  5514. {
  5515. if (REG_P (target))
  5516. emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
  5517. else
  5518. clear_storage (target, GEN_INT (size), BLOCK_OP_NORMAL);
  5519. cleared = 1;
  5520. }
  5521. /* Inform later passes that the old value is dead. */
  5522. if (!cleared && !vector && REG_P (target))
  5523. emit_move_insn (target, CONST0_RTX (GET_MODE (target)));
  5524. if (MEM_P (target))
  5525. alias = MEM_ALIAS_SET (target);
  5526. else
  5527. alias = get_alias_set (elttype);
  5528. /* Store each element of the constructor into the corresponding
  5529. element of TARGET, determined by counting the elements. */
  5530. for (idx = 0, i = 0;
  5531. vec_safe_iterate (CONSTRUCTOR_ELTS (exp), idx, &ce);
  5532. idx++, i += bitsize / elt_size)
  5533. {
  5534. HOST_WIDE_INT eltpos;
  5535. tree value = ce->value;
  5536. bitsize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (value)));
  5537. if (cleared && initializer_zerop (value))
  5538. continue;
  5539. if (ce->index)
  5540. eltpos = tree_to_uhwi (ce->index);
  5541. else
  5542. eltpos = i;
  5543. if (vector)
  5544. {
  5545. /* vec_init<mode> should not be used if there are VECTOR_TYPE
  5546. elements. */
  5547. gcc_assert (TREE_CODE (TREE_TYPE (value)) != VECTOR_TYPE);
  5548. RTVEC_ELT (vector, eltpos)
  5549. = expand_normal (value);
  5550. }
  5551. else
  5552. {
  5553. machine_mode value_mode =
  5554. TREE_CODE (TREE_TYPE (value)) == VECTOR_TYPE
  5555. ? TYPE_MODE (TREE_TYPE (value))
  5556. : eltmode;
  5557. bitpos = eltpos * elt_size;
  5558. store_constructor_field (target, bitsize, bitpos, value_mode,
  5559. value, cleared, alias);
  5560. }
  5561. }
  5562. if (vector)
  5563. emit_insn (GEN_FCN (icode)
  5564. (target,
  5565. gen_rtx_PARALLEL (GET_MODE (target), vector)));
  5566. break;
  5567. }
  5568. default:
  5569. gcc_unreachable ();
  5570. }
  5571. }
  5572. /* Store the value of EXP (an expression tree)
  5573. into a subfield of TARGET which has mode MODE and occupies
  5574. BITSIZE bits, starting BITPOS bits from the start of TARGET.
  5575. If MODE is VOIDmode, it means that we are storing into a bit-field.
  5576. BITREGION_START is bitpos of the first bitfield in this region.
  5577. BITREGION_END is the bitpos of the ending bitfield in this region.
  5578. These two fields are 0, if the C++ memory model does not apply,
  5579. or we are not interested in keeping track of bitfield regions.
  5580. Always return const0_rtx unless we have something particular to
  5581. return.
  5582. ALIAS_SET is the alias set for the destination. This value will
  5583. (in general) be different from that for TARGET, since TARGET is a
  5584. reference to the containing structure.
  5585. If NONTEMPORAL is true, try generating a nontemporal store. */
  5586. static rtx
  5587. store_field (rtx target, HOST_WIDE_INT bitsize, HOST_WIDE_INT bitpos,
  5588. unsigned HOST_WIDE_INT bitregion_start,
  5589. unsigned HOST_WIDE_INT bitregion_end,
  5590. machine_mode mode, tree exp,
  5591. alias_set_type alias_set, bool nontemporal)
  5592. {
  5593. if (TREE_CODE (exp) == ERROR_MARK)
  5594. return const0_rtx;
  5595. /* If we have nothing to store, do nothing unless the expression has
  5596. side-effects. */
  5597. if (bitsize == 0)
  5598. return expand_expr (exp, const0_rtx, VOIDmode, EXPAND_NORMAL);
  5599. if (GET_CODE (target) == CONCAT)
  5600. {
  5601. /* We're storing into a struct containing a single __complex. */
  5602. gcc_assert (!bitpos);
  5603. return store_expr (exp, target, 0, nontemporal);
  5604. }
  5605. /* If the structure is in a register or if the component
  5606. is a bit field, we cannot use addressing to access it.
  5607. Use bit-field techniques or SUBREG to store in it. */
  5608. if (mode == VOIDmode
  5609. || (mode != BLKmode && ! direct_store[(int) mode]
  5610. && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
  5611. && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
  5612. || REG_P (target)
  5613. || GET_CODE (target) == SUBREG
  5614. /* If the field isn't aligned enough to store as an ordinary memref,
  5615. store it as a bit field. */
  5616. || (mode != BLKmode
  5617. && ((((MEM_ALIGN (target) < GET_MODE_ALIGNMENT (mode))
  5618. || bitpos % GET_MODE_ALIGNMENT (mode))
  5619. && SLOW_UNALIGNED_ACCESS (mode, MEM_ALIGN (target)))
  5620. || (bitpos % BITS_PER_UNIT != 0)))
  5621. || (bitsize >= 0 && mode != BLKmode
  5622. && GET_MODE_BITSIZE (mode) > bitsize)
  5623. /* If the RHS and field are a constant size and the size of the
  5624. RHS isn't the same size as the bitfield, we must use bitfield
  5625. operations. */
  5626. || (bitsize >= 0
  5627. && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
  5628. && compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)), bitsize) != 0)
  5629. /* If we are expanding a MEM_REF of a non-BLKmode non-addressable
  5630. decl we must use bitfield operations. */
  5631. || (bitsize >= 0
  5632. && TREE_CODE (exp) == MEM_REF
  5633. && TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR
  5634. && DECL_P (TREE_OPERAND (TREE_OPERAND (exp, 0), 0))
  5635. && !TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (exp, 0),0 ))
  5636. && DECL_MODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) != BLKmode))
  5637. {
  5638. rtx temp;
  5639. gimple nop_def;
  5640. /* If EXP is a NOP_EXPR of precision less than its mode, then that
  5641. implies a mask operation. If the precision is the same size as
  5642. the field we're storing into, that mask is redundant. This is
  5643. particularly common with bit field assignments generated by the
  5644. C front end. */
  5645. nop_def = get_def_for_expr (exp, NOP_EXPR);
  5646. if (nop_def)
  5647. {
  5648. tree type = TREE_TYPE (exp);
  5649. if (INTEGRAL_TYPE_P (type)
  5650. && TYPE_PRECISION (type) < GET_MODE_BITSIZE (TYPE_MODE (type))
  5651. && bitsize == TYPE_PRECISION (type))
  5652. {
  5653. tree op = gimple_assign_rhs1 (nop_def);
  5654. type = TREE_TYPE (op);
  5655. if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) >= bitsize)
  5656. exp = op;
  5657. }
  5658. }
  5659. temp = expand_normal (exp);
  5660. /* If BITSIZE is narrower than the size of the type of EXP
  5661. we will be narrowing TEMP. Normally, what's wanted are the
  5662. low-order bits. However, if EXP's type is a record and this is
  5663. big-endian machine, we want the upper BITSIZE bits. */
  5664. if (BYTES_BIG_ENDIAN && GET_MODE_CLASS (GET_MODE (temp)) == MODE_INT
  5665. && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (temp))
  5666. && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  5667. temp = expand_shift (RSHIFT_EXPR, GET_MODE (temp), temp,
  5668. GET_MODE_BITSIZE (GET_MODE (temp)) - bitsize,
  5669. NULL_RTX, 1);
  5670. /* Unless MODE is VOIDmode or BLKmode, convert TEMP to MODE. */
  5671. if (mode != VOIDmode && mode != BLKmode
  5672. && mode != TYPE_MODE (TREE_TYPE (exp)))
  5673. temp = convert_modes (mode, TYPE_MODE (TREE_TYPE (exp)), temp, 1);
  5674. /* If TEMP is not a PARALLEL (see below) and its mode and that of TARGET
  5675. are both BLKmode, both must be in memory and BITPOS must be aligned
  5676. on a byte boundary. If so, we simply do a block copy. Likewise for
  5677. a BLKmode-like TARGET. */
  5678. if (GET_CODE (temp) != PARALLEL
  5679. && GET_MODE (temp) == BLKmode
  5680. && (GET_MODE (target) == BLKmode
  5681. || (MEM_P (target)
  5682. && GET_MODE_CLASS (GET_MODE (target)) == MODE_INT
  5683. && (bitpos % BITS_PER_UNIT) == 0
  5684. && (bitsize % BITS_PER_UNIT) == 0)))
  5685. {
  5686. gcc_assert (MEM_P (target) && MEM_P (temp)
  5687. && (bitpos % BITS_PER_UNIT) == 0);
  5688. target = adjust_address (target, VOIDmode, bitpos / BITS_PER_UNIT);
  5689. emit_block_move (target, temp,
  5690. GEN_INT ((bitsize + BITS_PER_UNIT - 1)
  5691. / BITS_PER_UNIT),
  5692. BLOCK_OP_NORMAL);
  5693. return const0_rtx;
  5694. }
  5695. /* Handle calls that return values in multiple non-contiguous locations.
  5696. The Irix 6 ABI has examples of this. */
  5697. if (GET_CODE (temp) == PARALLEL)
  5698. {
  5699. HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
  5700. rtx temp_target;
  5701. if (mode == BLKmode || mode == VOIDmode)
  5702. mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
  5703. temp_target = gen_reg_rtx (mode);
  5704. emit_group_store (temp_target, temp, TREE_TYPE (exp), size);
  5705. temp = temp_target;
  5706. }
  5707. else if (mode == BLKmode)
  5708. {
  5709. /* Handle calls that return BLKmode values in registers. */
  5710. if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR)
  5711. {
  5712. rtx temp_target = gen_reg_rtx (GET_MODE (temp));
  5713. copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp));
  5714. temp = temp_target;
  5715. }
  5716. else
  5717. {
  5718. HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
  5719. rtx temp_target;
  5720. mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT);
  5721. temp_target = gen_reg_rtx (mode);
  5722. temp_target
  5723. = extract_bit_field (temp, size * BITS_PER_UNIT, 0, 1,
  5724. temp_target, mode, mode);
  5725. temp = temp_target;
  5726. }
  5727. }
  5728. /* Store the value in the bitfield. */
  5729. store_bit_field (target, bitsize, bitpos,
  5730. bitregion_start, bitregion_end,
  5731. mode, temp);
  5732. return const0_rtx;
  5733. }
  5734. else
  5735. {
  5736. /* Now build a reference to just the desired component. */
  5737. rtx to_rtx = adjust_address (target, mode, bitpos / BITS_PER_UNIT);
  5738. if (to_rtx == target)
  5739. to_rtx = copy_rtx (to_rtx);
  5740. if (!MEM_KEEP_ALIAS_SET_P (to_rtx) && MEM_ALIAS_SET (to_rtx) != 0)
  5741. set_mem_alias_set (to_rtx, alias_set);
  5742. return store_expr (exp, to_rtx, 0, nontemporal);
  5743. }
  5744. }
  5745. /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
  5746. an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
  5747. codes and find the ultimate containing object, which we return.
  5748. We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
  5749. bit position, and *PUNSIGNEDP to the signedness of the field.
  5750. If the position of the field is variable, we store a tree
  5751. giving the variable offset (in units) in *POFFSET.
  5752. This offset is in addition to the bit position.
  5753. If the position is not variable, we store 0 in *POFFSET.
  5754. If any of the extraction expressions is volatile,
  5755. we store 1 in *PVOLATILEP. Otherwise we don't change that.
  5756. If the field is a non-BLKmode bit-field, *PMODE is set to VOIDmode.
  5757. Otherwise, it is a mode that can be used to access the field.
  5758. If the field describes a variable-sized object, *PMODE is set to
  5759. BLKmode and *PBITSIZE is set to -1. An access cannot be made in
  5760. this case, but the address of the object can be found.
  5761. If KEEP_ALIGNING is true and the target is STRICT_ALIGNMENT, we don't
  5762. look through nodes that serve as markers of a greater alignment than
  5763. the one that can be deduced from the expression. These nodes make it
  5764. possible for front-ends to prevent temporaries from being created by
  5765. the middle-end on alignment considerations. For that purpose, the
  5766. normal operating mode at high-level is to always pass FALSE so that
  5767. the ultimate containing object is really returned; moreover, the
  5768. associated predicate handled_component_p will always return TRUE
  5769. on these nodes, thus indicating that they are essentially handled
  5770. by get_inner_reference. TRUE should only be passed when the caller
  5771. is scanning the expression in order to build another representation
  5772. and specifically knows how to handle these nodes; as such, this is
  5773. the normal operating mode in the RTL expanders. */
  5774. tree
  5775. get_inner_reference (tree exp, HOST_WIDE_INT *pbitsize,
  5776. HOST_WIDE_INT *pbitpos, tree *poffset,
  5777. machine_mode *pmode, int *punsignedp,
  5778. int *pvolatilep, bool keep_aligning)
  5779. {
  5780. tree size_tree = 0;
  5781. machine_mode mode = VOIDmode;
  5782. bool blkmode_bitfield = false;
  5783. tree offset = size_zero_node;
  5784. offset_int bit_offset = 0;
  5785. /* First get the mode, signedness, and size. We do this from just the
  5786. outermost expression. */
  5787. *pbitsize = -1;
  5788. if (TREE_CODE (exp) == COMPONENT_REF)
  5789. {
  5790. tree field = TREE_OPERAND (exp, 1);
  5791. size_tree = DECL_SIZE (field);
  5792. if (flag_strict_volatile_bitfields > 0
  5793. && TREE_THIS_VOLATILE (exp)
  5794. && DECL_BIT_FIELD_TYPE (field)
  5795. && DECL_MODE (field) != BLKmode)
  5796. /* Volatile bitfields should be accessed in the mode of the
  5797. field's type, not the mode computed based on the bit
  5798. size. */
  5799. mode = TYPE_MODE (DECL_BIT_FIELD_TYPE (field));
  5800. else if (!DECL_BIT_FIELD (field))
  5801. mode = DECL_MODE (field);
  5802. else if (DECL_MODE (field) == BLKmode)
  5803. blkmode_bitfield = true;
  5804. *punsignedp = DECL_UNSIGNED (field);
  5805. }
  5806. else if (TREE_CODE (exp) == BIT_FIELD_REF)
  5807. {
  5808. size_tree = TREE_OPERAND (exp, 1);
  5809. *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
  5810. || TYPE_UNSIGNED (TREE_TYPE (exp)));
  5811. /* For vector types, with the correct size of access, use the mode of
  5812. inner type. */
  5813. if (TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == VECTOR_TYPE
  5814. && TREE_TYPE (exp) == TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)))
  5815. && tree_int_cst_equal (size_tree, TYPE_SIZE (TREE_TYPE (exp))))
  5816. mode = TYPE_MODE (TREE_TYPE (exp));
  5817. }
  5818. else
  5819. {
  5820. mode = TYPE_MODE (TREE_TYPE (exp));
  5821. *punsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
  5822. if (mode == BLKmode)
  5823. size_tree = TYPE_SIZE (TREE_TYPE (exp));
  5824. else
  5825. *pbitsize = GET_MODE_BITSIZE (mode);
  5826. }
  5827. if (size_tree != 0)
  5828. {
  5829. if (! tree_fits_uhwi_p (size_tree))
  5830. mode = BLKmode, *pbitsize = -1;
  5831. else
  5832. *pbitsize = tree_to_uhwi (size_tree);
  5833. }
  5834. /* Compute cumulative bit-offset for nested component-refs and array-refs,
  5835. and find the ultimate containing object. */
  5836. while (1)
  5837. {
  5838. switch (TREE_CODE (exp))
  5839. {
  5840. case BIT_FIELD_REF:
  5841. bit_offset += wi::to_offset (TREE_OPERAND (exp, 2));
  5842. break;
  5843. case COMPONENT_REF:
  5844. {
  5845. tree field = TREE_OPERAND (exp, 1);
  5846. tree this_offset = component_ref_field_offset (exp);
  5847. /* If this field hasn't been filled in yet, don't go past it.
  5848. This should only happen when folding expressions made during
  5849. type construction. */
  5850. if (this_offset == 0)
  5851. break;
  5852. offset = size_binop (PLUS_EXPR, offset, this_offset);
  5853. bit_offset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field));
  5854. /* ??? Right now we don't do anything with DECL_OFFSET_ALIGN. */
  5855. }
  5856. break;
  5857. case ARRAY_REF:
  5858. case ARRAY_RANGE_REF:
  5859. {
  5860. tree index = TREE_OPERAND (exp, 1);
  5861. tree low_bound = array_ref_low_bound (exp);
  5862. tree unit_size = array_ref_element_size (exp);
  5863. /* We assume all arrays have sizes that are a multiple of a byte.
  5864. First subtract the lower bound, if any, in the type of the
  5865. index, then convert to sizetype and multiply by the size of
  5866. the array element. */
  5867. if (! integer_zerop (low_bound))
  5868. index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
  5869. index, low_bound);
  5870. offset = size_binop (PLUS_EXPR, offset,
  5871. size_binop (MULT_EXPR,
  5872. fold_convert (sizetype, index),
  5873. unit_size));
  5874. }
  5875. break;
  5876. case REALPART_EXPR:
  5877. break;
  5878. case IMAGPART_EXPR:
  5879. bit_offset += *pbitsize;
  5880. break;
  5881. case VIEW_CONVERT_EXPR:
  5882. if (keep_aligning && STRICT_ALIGNMENT
  5883. && (TYPE_ALIGN (TREE_TYPE (exp))
  5884. > TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0))))
  5885. && (TYPE_ALIGN (TREE_TYPE (TREE_OPERAND (exp, 0)))
  5886. < BIGGEST_ALIGNMENT)
  5887. && (TYPE_ALIGN_OK (TREE_TYPE (exp))
  5888. || TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (exp, 0)))))
  5889. goto done;
  5890. break;
  5891. case MEM_REF:
  5892. /* Hand back the decl for MEM[&decl, off]. */
  5893. if (TREE_CODE (TREE_OPERAND (exp, 0)) == ADDR_EXPR)
  5894. {
  5895. tree off = TREE_OPERAND (exp, 1);
  5896. if (!integer_zerop (off))
  5897. {
  5898. offset_int boff, coff = mem_ref_offset (exp);
  5899. boff = wi::lshift (coff, LOG2_BITS_PER_UNIT);
  5900. bit_offset += boff;
  5901. }
  5902. exp = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
  5903. }
  5904. goto done;
  5905. default:
  5906. goto done;
  5907. }
  5908. /* If any reference in the chain is volatile, the effect is volatile. */
  5909. if (TREE_THIS_VOLATILE (exp))
  5910. *pvolatilep = 1;
  5911. exp = TREE_OPERAND (exp, 0);
  5912. }
  5913. done:
  5914. /* If OFFSET is constant, see if we can return the whole thing as a
  5915. constant bit position. Make sure to handle overflow during
  5916. this conversion. */
  5917. if (TREE_CODE (offset) == INTEGER_CST)
  5918. {
  5919. offset_int tem = wi::sext (wi::to_offset (offset),
  5920. TYPE_PRECISION (sizetype));
  5921. tem = wi::lshift (tem, LOG2_BITS_PER_UNIT);
  5922. tem += bit_offset;
  5923. if (wi::fits_shwi_p (tem))
  5924. {
  5925. *pbitpos = tem.to_shwi ();
  5926. *poffset = offset = NULL_TREE;
  5927. }
  5928. }
  5929. /* Otherwise, split it up. */
  5930. if (offset)
  5931. {
  5932. /* Avoid returning a negative bitpos as this may wreak havoc later. */
  5933. if (wi::neg_p (bit_offset) || !wi::fits_shwi_p (bit_offset))
  5934. {
  5935. offset_int mask = wi::mask <offset_int> (LOG2_BITS_PER_UNIT, false);
  5936. offset_int tem = bit_offset.and_not (mask);
  5937. /* TEM is the bitpos rounded to BITS_PER_UNIT towards -Inf.
  5938. Subtract it to BIT_OFFSET and add it (scaled) to OFFSET. */
  5939. bit_offset -= tem;
  5940. tem = wi::arshift (tem, LOG2_BITS_PER_UNIT);
  5941. offset = size_binop (PLUS_EXPR, offset,
  5942. wide_int_to_tree (sizetype, tem));
  5943. }
  5944. *pbitpos = bit_offset.to_shwi ();
  5945. *poffset = offset;
  5946. }
  5947. /* We can use BLKmode for a byte-aligned BLKmode bitfield. */
  5948. if (mode == VOIDmode
  5949. && blkmode_bitfield
  5950. && (*pbitpos % BITS_PER_UNIT) == 0
  5951. && (*pbitsize % BITS_PER_UNIT) == 0)
  5952. *pmode = BLKmode;
  5953. else
  5954. *pmode = mode;
  5955. return exp;
  5956. }
  5957. /* Return a tree of sizetype representing the size, in bytes, of the element
  5958. of EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
  5959. tree
  5960. array_ref_element_size (tree exp)
  5961. {
  5962. tree aligned_size = TREE_OPERAND (exp, 3);
  5963. tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0)));
  5964. location_t loc = EXPR_LOCATION (exp);
  5965. /* If a size was specified in the ARRAY_REF, it's the size measured
  5966. in alignment units of the element type. So multiply by that value. */
  5967. if (aligned_size)
  5968. {
  5969. /* ??? tree_ssa_useless_type_conversion will eliminate casts to
  5970. sizetype from another type of the same width and signedness. */
  5971. if (TREE_TYPE (aligned_size) != sizetype)
  5972. aligned_size = fold_convert_loc (loc, sizetype, aligned_size);
  5973. return size_binop_loc (loc, MULT_EXPR, aligned_size,
  5974. size_int (TYPE_ALIGN_UNIT (elmt_type)));
  5975. }
  5976. /* Otherwise, take the size from that of the element type. Substitute
  5977. any PLACEHOLDER_EXPR that we have. */
  5978. else
  5979. return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (elmt_type), exp);
  5980. }
  5981. /* Return a tree representing the lower bound of the array mentioned in
  5982. EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
  5983. tree
  5984. array_ref_low_bound (tree exp)
  5985. {
  5986. tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
  5987. /* If a lower bound is specified in EXP, use it. */
  5988. if (TREE_OPERAND (exp, 2))
  5989. return TREE_OPERAND (exp, 2);
  5990. /* Otherwise, if there is a domain type and it has a lower bound, use it,
  5991. substituting for a PLACEHOLDER_EXPR as needed. */
  5992. if (domain_type && TYPE_MIN_VALUE (domain_type))
  5993. return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MIN_VALUE (domain_type), exp);
  5994. /* Otherwise, return a zero of the appropriate type. */
  5995. return build_int_cst (TREE_TYPE (TREE_OPERAND (exp, 1)), 0);
  5996. }
  5997. /* Returns true if REF is an array reference to an array at the end of
  5998. a structure. If this is the case, the array may be allocated larger
  5999. than its upper bound implies. */
  6000. bool
  6001. array_at_struct_end_p (tree ref)
  6002. {
  6003. if (TREE_CODE (ref) != ARRAY_REF
  6004. && TREE_CODE (ref) != ARRAY_RANGE_REF)
  6005. return false;
  6006. while (handled_component_p (ref))
  6007. {
  6008. /* If the reference chain contains a component reference to a
  6009. non-union type and there follows another field the reference
  6010. is not at the end of a structure. */
  6011. if (TREE_CODE (ref) == COMPONENT_REF
  6012. && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 0))) == RECORD_TYPE)
  6013. {
  6014. tree nextf = DECL_CHAIN (TREE_OPERAND (ref, 1));
  6015. while (nextf && TREE_CODE (nextf) != FIELD_DECL)
  6016. nextf = DECL_CHAIN (nextf);
  6017. if (nextf)
  6018. return false;
  6019. }
  6020. ref = TREE_OPERAND (ref, 0);
  6021. }
  6022. /* If the reference is based on a declared entity, the size of the array
  6023. is constrained by its given domain. */
  6024. if (DECL_P (ref))
  6025. return false;
  6026. return true;
  6027. }
  6028. /* Return a tree representing the upper bound of the array mentioned in
  6029. EXP, an ARRAY_REF or an ARRAY_RANGE_REF. */
  6030. tree
  6031. array_ref_up_bound (tree exp)
  6032. {
  6033. tree domain_type = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
  6034. /* If there is a domain type and it has an upper bound, use it, substituting
  6035. for a PLACEHOLDER_EXPR as needed. */
  6036. if (domain_type && TYPE_MAX_VALUE (domain_type))
  6037. return SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_MAX_VALUE (domain_type), exp);
  6038. /* Otherwise fail. */
  6039. return NULL_TREE;
  6040. }
  6041. /* Return a tree representing the offset, in bytes, of the field referenced
  6042. by EXP. This does not include any offset in DECL_FIELD_BIT_OFFSET. */
  6043. tree
  6044. component_ref_field_offset (tree exp)
  6045. {
  6046. tree aligned_offset = TREE_OPERAND (exp, 2);
  6047. tree field = TREE_OPERAND (exp, 1);
  6048. location_t loc = EXPR_LOCATION (exp);
  6049. /* If an offset was specified in the COMPONENT_REF, it's the offset measured
  6050. in units of DECL_OFFSET_ALIGN / BITS_PER_UNIT. So multiply by that
  6051. value. */
  6052. if (aligned_offset)
  6053. {
  6054. /* ??? tree_ssa_useless_type_conversion will eliminate casts to
  6055. sizetype from another type of the same width and signedness. */
  6056. if (TREE_TYPE (aligned_offset) != sizetype)
  6057. aligned_offset = fold_convert_loc (loc, sizetype, aligned_offset);
  6058. return size_binop_loc (loc, MULT_EXPR, aligned_offset,
  6059. size_int (DECL_OFFSET_ALIGN (field)
  6060. / BITS_PER_UNIT));
  6061. }
  6062. /* Otherwise, take the offset from that of the field. Substitute
  6063. any PLACEHOLDER_EXPR that we have. */
  6064. else
  6065. return SUBSTITUTE_PLACEHOLDER_IN_EXPR (DECL_FIELD_OFFSET (field), exp);
  6066. }
  6067. /* Alignment in bits the TARGET of an assignment may be assumed to have. */
  6068. static unsigned HOST_WIDE_INT
  6069. target_align (const_tree target)
  6070. {
  6071. /* We might have a chain of nested references with intermediate misaligning
  6072. bitfields components, so need to recurse to find out. */
  6073. unsigned HOST_WIDE_INT this_align, outer_align;
  6074. switch (TREE_CODE (target))
  6075. {
  6076. case BIT_FIELD_REF:
  6077. return 1;
  6078. case COMPONENT_REF:
  6079. this_align = DECL_ALIGN (TREE_OPERAND (target, 1));
  6080. outer_align = target_align (TREE_OPERAND (target, 0));
  6081. return MIN (this_align, outer_align);
  6082. case ARRAY_REF:
  6083. case ARRAY_RANGE_REF:
  6084. this_align = TYPE_ALIGN (TREE_TYPE (target));
  6085. outer_align = target_align (TREE_OPERAND (target, 0));
  6086. return MIN (this_align, outer_align);
  6087. CASE_CONVERT:
  6088. case NON_LVALUE_EXPR:
  6089. case VIEW_CONVERT_EXPR:
  6090. this_align = TYPE_ALIGN (TREE_TYPE (target));
  6091. outer_align = target_align (TREE_OPERAND (target, 0));
  6092. return MAX (this_align, outer_align);
  6093. default:
  6094. return TYPE_ALIGN (TREE_TYPE (target));
  6095. }
  6096. }
  6097. /* Given an rtx VALUE that may contain additions and multiplications, return
  6098. an equivalent value that just refers to a register, memory, or constant.
  6099. This is done by generating instructions to perform the arithmetic and
  6100. returning a pseudo-register containing the value.
  6101. The returned value may be a REG, SUBREG, MEM or constant. */
  6102. rtx
  6103. force_operand (rtx value, rtx target)
  6104. {
  6105. rtx op1, op2;
  6106. /* Use subtarget as the target for operand 0 of a binary operation. */
  6107. rtx subtarget = get_subtarget (target);
  6108. enum rtx_code code = GET_CODE (value);
  6109. /* Check for subreg applied to an expression produced by loop optimizer. */
  6110. if (code == SUBREG
  6111. && !REG_P (SUBREG_REG (value))
  6112. && !MEM_P (SUBREG_REG (value)))
  6113. {
  6114. value
  6115. = simplify_gen_subreg (GET_MODE (value),
  6116. force_reg (GET_MODE (SUBREG_REG (value)),
  6117. force_operand (SUBREG_REG (value),
  6118. NULL_RTX)),
  6119. GET_MODE (SUBREG_REG (value)),
  6120. SUBREG_BYTE (value));
  6121. code = GET_CODE (value);
  6122. }
  6123. /* Check for a PIC address load. */
  6124. if ((code == PLUS || code == MINUS)
  6125. && XEXP (value, 0) == pic_offset_table_rtx
  6126. && (GET_CODE (XEXP (value, 1)) == SYMBOL_REF
  6127. || GET_CODE (XEXP (value, 1)) == LABEL_REF
  6128. || GET_CODE (XEXP (value, 1)) == CONST))
  6129. {
  6130. if (!subtarget)
  6131. subtarget = gen_reg_rtx (GET_MODE (value));
  6132. emit_move_insn (subtarget, value);
  6133. return subtarget;
  6134. }
  6135. if (ARITHMETIC_P (value))
  6136. {
  6137. op2 = XEXP (value, 1);
  6138. if (!CONSTANT_P (op2) && !(REG_P (op2) && op2 != subtarget))
  6139. subtarget = 0;
  6140. if (code == MINUS && CONST_INT_P (op2))
  6141. {
  6142. code = PLUS;
  6143. op2 = negate_rtx (GET_MODE (value), op2);
  6144. }
  6145. /* Check for an addition with OP2 a constant integer and our first
  6146. operand a PLUS of a virtual register and something else. In that
  6147. case, we want to emit the sum of the virtual register and the
  6148. constant first and then add the other value. This allows virtual
  6149. register instantiation to simply modify the constant rather than
  6150. creating another one around this addition. */
  6151. if (code == PLUS && CONST_INT_P (op2)
  6152. && GET_CODE (XEXP (value, 0)) == PLUS
  6153. && REG_P (XEXP (XEXP (value, 0), 0))
  6154. && REGNO (XEXP (XEXP (value, 0), 0)) >= FIRST_VIRTUAL_REGISTER
  6155. && REGNO (XEXP (XEXP (value, 0), 0)) <= LAST_VIRTUAL_REGISTER)
  6156. {
  6157. rtx temp = expand_simple_binop (GET_MODE (value), code,
  6158. XEXP (XEXP (value, 0), 0), op2,
  6159. subtarget, 0, OPTAB_LIB_WIDEN);
  6160. return expand_simple_binop (GET_MODE (value), code, temp,
  6161. force_operand (XEXP (XEXP (value,
  6162. 0), 1), 0),
  6163. target, 0, OPTAB_LIB_WIDEN);
  6164. }
  6165. op1 = force_operand (XEXP (value, 0), subtarget);
  6166. op2 = force_operand (op2, NULL_RTX);
  6167. switch (code)
  6168. {
  6169. case MULT:
  6170. return expand_mult (GET_MODE (value), op1, op2, target, 1);
  6171. case DIV:
  6172. if (!INTEGRAL_MODE_P (GET_MODE (value)))
  6173. return expand_simple_binop (GET_MODE (value), code, op1, op2,
  6174. target, 1, OPTAB_LIB_WIDEN);
  6175. else
  6176. return expand_divmod (0,
  6177. FLOAT_MODE_P (GET_MODE (value))
  6178. ? RDIV_EXPR : TRUNC_DIV_EXPR,
  6179. GET_MODE (value), op1, op2, target, 0);
  6180. case MOD:
  6181. return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
  6182. target, 0);
  6183. case UDIV:
  6184. return expand_divmod (0, TRUNC_DIV_EXPR, GET_MODE (value), op1, op2,
  6185. target, 1);
  6186. case UMOD:
  6187. return expand_divmod (1, TRUNC_MOD_EXPR, GET_MODE (value), op1, op2,
  6188. target, 1);
  6189. case ASHIFTRT:
  6190. return expand_simple_binop (GET_MODE (value), code, op1, op2,
  6191. target, 0, OPTAB_LIB_WIDEN);
  6192. default:
  6193. return expand_simple_binop (GET_MODE (value), code, op1, op2,
  6194. target, 1, OPTAB_LIB_WIDEN);
  6195. }
  6196. }
  6197. if (UNARY_P (value))
  6198. {
  6199. if (!target)
  6200. target = gen_reg_rtx (GET_MODE (value));
  6201. op1 = force_operand (XEXP (value, 0), NULL_RTX);
  6202. switch (code)
  6203. {
  6204. case ZERO_EXTEND:
  6205. case SIGN_EXTEND:
  6206. case TRUNCATE:
  6207. case FLOAT_EXTEND:
  6208. case FLOAT_TRUNCATE:
  6209. convert_move (target, op1, code == ZERO_EXTEND);
  6210. return target;
  6211. case FIX:
  6212. case UNSIGNED_FIX:
  6213. expand_fix (target, op1, code == UNSIGNED_FIX);
  6214. return target;
  6215. case FLOAT:
  6216. case UNSIGNED_FLOAT:
  6217. expand_float (target, op1, code == UNSIGNED_FLOAT);
  6218. return target;
  6219. default:
  6220. return expand_simple_unop (GET_MODE (value), code, op1, target, 0);
  6221. }
  6222. }
  6223. #ifdef INSN_SCHEDULING
  6224. /* On machines that have insn scheduling, we want all memory reference to be
  6225. explicit, so we need to deal with such paradoxical SUBREGs. */
  6226. if (paradoxical_subreg_p (value) && MEM_P (SUBREG_REG (value)))
  6227. value
  6228. = simplify_gen_subreg (GET_MODE (value),
  6229. force_reg (GET_MODE (SUBREG_REG (value)),
  6230. force_operand (SUBREG_REG (value),
  6231. NULL_RTX)),
  6232. GET_MODE (SUBREG_REG (value)),
  6233. SUBREG_BYTE (value));
  6234. #endif
  6235. return value;
  6236. }
  6237. /* Subroutine of expand_expr: return nonzero iff there is no way that
  6238. EXP can reference X, which is being modified. TOP_P is nonzero if this
  6239. call is going to be used to determine whether we need a temporary
  6240. for EXP, as opposed to a recursive call to this function.
  6241. It is always safe for this routine to return zero since it merely
  6242. searches for optimization opportunities. */
  6243. int
  6244. safe_from_p (const_rtx x, tree exp, int top_p)
  6245. {
  6246. rtx exp_rtl = 0;
  6247. int i, nops;
  6248. if (x == 0
  6249. /* If EXP has varying size, we MUST use a target since we currently
  6250. have no way of allocating temporaries of variable size
  6251. (except for arrays that have TYPE_ARRAY_MAX_SIZE set).
  6252. So we assume here that something at a higher level has prevented a
  6253. clash. This is somewhat bogus, but the best we can do. Only
  6254. do this when X is BLKmode and when we are at the top level. */
  6255. || (top_p && TREE_TYPE (exp) != 0 && COMPLETE_TYPE_P (TREE_TYPE (exp))
  6256. && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST
  6257. && (TREE_CODE (TREE_TYPE (exp)) != ARRAY_TYPE
  6258. || TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)) == NULL_TREE
  6259. || TREE_CODE (TYPE_ARRAY_MAX_SIZE (TREE_TYPE (exp)))
  6260. != INTEGER_CST)
  6261. && GET_MODE (x) == BLKmode)
  6262. /* If X is in the outgoing argument area, it is always safe. */
  6263. || (MEM_P (x)
  6264. && (XEXP (x, 0) == virtual_outgoing_args_rtx
  6265. || (GET_CODE (XEXP (x, 0)) == PLUS
  6266. && XEXP (XEXP (x, 0), 0) == virtual_outgoing_args_rtx))))
  6267. return 1;
  6268. /* If this is a subreg of a hard register, declare it unsafe, otherwise,
  6269. find the underlying pseudo. */
  6270. if (GET_CODE (x) == SUBREG)
  6271. {
  6272. x = SUBREG_REG (x);
  6273. if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
  6274. return 0;
  6275. }
  6276. /* Now look at our tree code and possibly recurse. */
  6277. switch (TREE_CODE_CLASS (TREE_CODE (exp)))
  6278. {
  6279. case tcc_declaration:
  6280. exp_rtl = DECL_RTL_IF_SET (exp);
  6281. break;
  6282. case tcc_constant:
  6283. return 1;
  6284. case tcc_exceptional:
  6285. if (TREE_CODE (exp) == TREE_LIST)
  6286. {
  6287. while (1)
  6288. {
  6289. if (TREE_VALUE (exp) && !safe_from_p (x, TREE_VALUE (exp), 0))
  6290. return 0;
  6291. exp = TREE_CHAIN (exp);
  6292. if (!exp)
  6293. return 1;
  6294. if (TREE_CODE (exp) != TREE_LIST)
  6295. return safe_from_p (x, exp, 0);
  6296. }
  6297. }
  6298. else if (TREE_CODE (exp) == CONSTRUCTOR)
  6299. {
  6300. constructor_elt *ce;
  6301. unsigned HOST_WIDE_INT idx;
  6302. FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (exp), idx, ce)
  6303. if ((ce->index != NULL_TREE && !safe_from_p (x, ce->index, 0))
  6304. || !safe_from_p (x, ce->value, 0))
  6305. return 0;
  6306. return 1;
  6307. }
  6308. else if (TREE_CODE (exp) == ERROR_MARK)
  6309. return 1; /* An already-visited SAVE_EXPR? */
  6310. else
  6311. return 0;
  6312. case tcc_statement:
  6313. /* The only case we look at here is the DECL_INITIAL inside a
  6314. DECL_EXPR. */
  6315. return (TREE_CODE (exp) != DECL_EXPR
  6316. || TREE_CODE (DECL_EXPR_DECL (exp)) != VAR_DECL
  6317. || !DECL_INITIAL (DECL_EXPR_DECL (exp))
  6318. || safe_from_p (x, DECL_INITIAL (DECL_EXPR_DECL (exp)), 0));
  6319. case tcc_binary:
  6320. case tcc_comparison:
  6321. if (!safe_from_p (x, TREE_OPERAND (exp, 1), 0))
  6322. return 0;
  6323. /* Fall through. */
  6324. case tcc_unary:
  6325. return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
  6326. case tcc_expression:
  6327. case tcc_reference:
  6328. case tcc_vl_exp:
  6329. /* Now do code-specific tests. EXP_RTL is set to any rtx we find in
  6330. the expression. If it is set, we conflict iff we are that rtx or
  6331. both are in memory. Otherwise, we check all operands of the
  6332. expression recursively. */
  6333. switch (TREE_CODE (exp))
  6334. {
  6335. case ADDR_EXPR:
  6336. /* If the operand is static or we are static, we can't conflict.
  6337. Likewise if we don't conflict with the operand at all. */
  6338. if (staticp (TREE_OPERAND (exp, 0))
  6339. || TREE_STATIC (exp)
  6340. || safe_from_p (x, TREE_OPERAND (exp, 0), 0))
  6341. return 1;
  6342. /* Otherwise, the only way this can conflict is if we are taking
  6343. the address of a DECL a that address if part of X, which is
  6344. very rare. */
  6345. exp = TREE_OPERAND (exp, 0);
  6346. if (DECL_P (exp))
  6347. {
  6348. if (!DECL_RTL_SET_P (exp)
  6349. || !MEM_P (DECL_RTL (exp)))
  6350. return 0;
  6351. else
  6352. exp_rtl = XEXP (DECL_RTL (exp), 0);
  6353. }
  6354. break;
  6355. case MEM_REF:
  6356. if (MEM_P (x)
  6357. && alias_sets_conflict_p (MEM_ALIAS_SET (x),
  6358. get_alias_set (exp)))
  6359. return 0;
  6360. break;
  6361. case CALL_EXPR:
  6362. /* Assume that the call will clobber all hard registers and
  6363. all of memory. */
  6364. if ((REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
  6365. || MEM_P (x))
  6366. return 0;
  6367. break;
  6368. case WITH_CLEANUP_EXPR:
  6369. case CLEANUP_POINT_EXPR:
  6370. /* Lowered by gimplify.c. */
  6371. gcc_unreachable ();
  6372. case SAVE_EXPR:
  6373. return safe_from_p (x, TREE_OPERAND (exp, 0), 0);
  6374. default:
  6375. break;
  6376. }
  6377. /* If we have an rtx, we do not need to scan our operands. */
  6378. if (exp_rtl)
  6379. break;
  6380. nops = TREE_OPERAND_LENGTH (exp);
  6381. for (i = 0; i < nops; i++)
  6382. if (TREE_OPERAND (exp, i) != 0
  6383. && ! safe_from_p (x, TREE_OPERAND (exp, i), 0))
  6384. return 0;
  6385. break;
  6386. case tcc_type:
  6387. /* Should never get a type here. */
  6388. gcc_unreachable ();
  6389. }
  6390. /* If we have an rtl, find any enclosed object. Then see if we conflict
  6391. with it. */
  6392. if (exp_rtl)
  6393. {
  6394. if (GET_CODE (exp_rtl) == SUBREG)
  6395. {
  6396. exp_rtl = SUBREG_REG (exp_rtl);
  6397. if (REG_P (exp_rtl)
  6398. && REGNO (exp_rtl) < FIRST_PSEUDO_REGISTER)
  6399. return 0;
  6400. }
  6401. /* If the rtl is X, then it is not safe. Otherwise, it is unless both
  6402. are memory and they conflict. */
  6403. return ! (rtx_equal_p (x, exp_rtl)
  6404. || (MEM_P (x) && MEM_P (exp_rtl)
  6405. && true_dependence (exp_rtl, VOIDmode, x)));
  6406. }
  6407. /* If we reach here, it is safe. */
  6408. return 1;
  6409. }
  6410. /* Return the highest power of two that EXP is known to be a multiple of.
  6411. This is used in updating alignment of MEMs in array references. */
  6412. unsigned HOST_WIDE_INT
  6413. highest_pow2_factor (const_tree exp)
  6414. {
  6415. unsigned HOST_WIDE_INT ret;
  6416. int trailing_zeros = tree_ctz (exp);
  6417. if (trailing_zeros >= HOST_BITS_PER_WIDE_INT)
  6418. return BIGGEST_ALIGNMENT;
  6419. ret = (unsigned HOST_WIDE_INT) 1 << trailing_zeros;
  6420. if (ret > BIGGEST_ALIGNMENT)
  6421. return BIGGEST_ALIGNMENT;
  6422. return ret;
  6423. }
  6424. /* Similar, except that the alignment requirements of TARGET are
  6425. taken into account. Assume it is at least as aligned as its
  6426. type, unless it is a COMPONENT_REF in which case the layout of
  6427. the structure gives the alignment. */
  6428. static unsigned HOST_WIDE_INT
  6429. highest_pow2_factor_for_target (const_tree target, const_tree exp)
  6430. {
  6431. unsigned HOST_WIDE_INT talign = target_align (target) / BITS_PER_UNIT;
  6432. unsigned HOST_WIDE_INT factor = highest_pow2_factor (exp);
  6433. return MAX (factor, talign);
  6434. }
  6435. #ifdef HAVE_conditional_move
  6436. /* Convert the tree comparison code TCODE to the rtl one where the
  6437. signedness is UNSIGNEDP. */
  6438. static enum rtx_code
  6439. convert_tree_comp_to_rtx (enum tree_code tcode, int unsignedp)
  6440. {
  6441. enum rtx_code code;
  6442. switch (tcode)
  6443. {
  6444. case EQ_EXPR:
  6445. code = EQ;
  6446. break;
  6447. case NE_EXPR:
  6448. code = NE;
  6449. break;
  6450. case LT_EXPR:
  6451. code = unsignedp ? LTU : LT;
  6452. break;
  6453. case LE_EXPR:
  6454. code = unsignedp ? LEU : LE;
  6455. break;
  6456. case GT_EXPR:
  6457. code = unsignedp ? GTU : GT;
  6458. break;
  6459. case GE_EXPR:
  6460. code = unsignedp ? GEU : GE;
  6461. break;
  6462. case UNORDERED_EXPR:
  6463. code = UNORDERED;
  6464. break;
  6465. case ORDERED_EXPR:
  6466. code = ORDERED;
  6467. break;
  6468. case UNLT_EXPR:
  6469. code = UNLT;
  6470. break;
  6471. case UNLE_EXPR:
  6472. code = UNLE;
  6473. break;
  6474. case UNGT_EXPR:
  6475. code = UNGT;
  6476. break;
  6477. case UNGE_EXPR:
  6478. code = UNGE;
  6479. break;
  6480. case UNEQ_EXPR:
  6481. code = UNEQ;
  6482. break;
  6483. case LTGT_EXPR:
  6484. code = LTGT;
  6485. break;
  6486. default:
  6487. gcc_unreachable ();
  6488. }
  6489. return code;
  6490. }
  6491. #endif
  6492. /* Subroutine of expand_expr. Expand the two operands of a binary
  6493. expression EXP0 and EXP1 placing the results in OP0 and OP1.
  6494. The value may be stored in TARGET if TARGET is nonzero. The
  6495. MODIFIER argument is as documented by expand_expr. */
  6496. void
  6497. expand_operands (tree exp0, tree exp1, rtx target, rtx *op0, rtx *op1,
  6498. enum expand_modifier modifier)
  6499. {
  6500. if (! safe_from_p (target, exp1, 1))
  6501. target = 0;
  6502. if (operand_equal_p (exp0, exp1, 0))
  6503. {
  6504. *op0 = expand_expr (exp0, target, VOIDmode, modifier);
  6505. *op1 = copy_rtx (*op0);
  6506. }
  6507. else
  6508. {
  6509. /* If we need to preserve evaluation order, copy exp0 into its own
  6510. temporary variable so that it can't be clobbered by exp1. */
  6511. if (flag_evaluation_order && TREE_SIDE_EFFECTS (exp1))
  6512. exp0 = save_expr (exp0);
  6513. *op0 = expand_expr (exp0, target, VOIDmode, modifier);
  6514. *op1 = expand_expr (exp1, NULL_RTX, VOIDmode, modifier);
  6515. }
  6516. }
  6517. /* Return a MEM that contains constant EXP. DEFER is as for
  6518. output_constant_def and MODIFIER is as for expand_expr. */
  6519. static rtx
  6520. expand_expr_constant (tree exp, int defer, enum expand_modifier modifier)
  6521. {
  6522. rtx mem;
  6523. mem = output_constant_def (exp, defer);
  6524. if (modifier != EXPAND_INITIALIZER)
  6525. mem = use_anchored_address (mem);
  6526. return mem;
  6527. }
  6528. /* A subroutine of expand_expr_addr_expr. Evaluate the address of EXP.
  6529. The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
  6530. static rtx
  6531. expand_expr_addr_expr_1 (tree exp, rtx target, machine_mode tmode,
  6532. enum expand_modifier modifier, addr_space_t as)
  6533. {
  6534. rtx result, subtarget;
  6535. tree inner, offset;
  6536. HOST_WIDE_INT bitsize, bitpos;
  6537. int volatilep, unsignedp;
  6538. machine_mode mode1;
  6539. /* If we are taking the address of a constant and are at the top level,
  6540. we have to use output_constant_def since we can't call force_const_mem
  6541. at top level. */
  6542. /* ??? This should be considered a front-end bug. We should not be
  6543. generating ADDR_EXPR of something that isn't an LVALUE. The only
  6544. exception here is STRING_CST. */
  6545. if (CONSTANT_CLASS_P (exp))
  6546. {
  6547. result = XEXP (expand_expr_constant (exp, 0, modifier), 0);
  6548. if (modifier < EXPAND_SUM)
  6549. result = force_operand (result, target);
  6550. return result;
  6551. }
  6552. /* Everything must be something allowed by is_gimple_addressable. */
  6553. switch (TREE_CODE (exp))
  6554. {
  6555. case INDIRECT_REF:
  6556. /* This case will happen via recursion for &a->b. */
  6557. return expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
  6558. case MEM_REF:
  6559. {
  6560. tree tem = TREE_OPERAND (exp, 0);
  6561. if (!integer_zerop (TREE_OPERAND (exp, 1)))
  6562. tem = fold_build_pointer_plus (tem, TREE_OPERAND (exp, 1));
  6563. return expand_expr (tem, target, tmode, modifier);
  6564. }
  6565. case CONST_DECL:
  6566. /* Expand the initializer like constants above. */
  6567. result = XEXP (expand_expr_constant (DECL_INITIAL (exp),
  6568. 0, modifier), 0);
  6569. if (modifier < EXPAND_SUM)
  6570. result = force_operand (result, target);
  6571. return result;
  6572. case REALPART_EXPR:
  6573. /* The real part of the complex number is always first, therefore
  6574. the address is the same as the address of the parent object. */
  6575. offset = 0;
  6576. bitpos = 0;
  6577. inner = TREE_OPERAND (exp, 0);
  6578. break;
  6579. case IMAGPART_EXPR:
  6580. /* The imaginary part of the complex number is always second.
  6581. The expression is therefore always offset by the size of the
  6582. scalar type. */
  6583. offset = 0;
  6584. bitpos = GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp)));
  6585. inner = TREE_OPERAND (exp, 0);
  6586. break;
  6587. case COMPOUND_LITERAL_EXPR:
  6588. /* Allow COMPOUND_LITERAL_EXPR in initializers or coming from
  6589. initializers, if e.g. rtl_for_decl_init is called on DECL_INITIAL
  6590. with COMPOUND_LITERAL_EXPRs in it, or ARRAY_REF on a const static
  6591. array with address of COMPOUND_LITERAL_EXPR in DECL_INITIAL;
  6592. the initializers aren't gimplified. */
  6593. if (COMPOUND_LITERAL_EXPR_DECL (exp)
  6594. && TREE_STATIC (COMPOUND_LITERAL_EXPR_DECL (exp)))
  6595. return expand_expr_addr_expr_1 (COMPOUND_LITERAL_EXPR_DECL (exp),
  6596. target, tmode, modifier, as);
  6597. /* FALLTHRU */
  6598. default:
  6599. /* If the object is a DECL, then expand it for its rtl. Don't bypass
  6600. expand_expr, as that can have various side effects; LABEL_DECLs for
  6601. example, may not have their DECL_RTL set yet. Expand the rtl of
  6602. CONSTRUCTORs too, which should yield a memory reference for the
  6603. constructor's contents. Assume language specific tree nodes can
  6604. be expanded in some interesting way. */
  6605. gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
  6606. if (DECL_P (exp)
  6607. || TREE_CODE (exp) == CONSTRUCTOR
  6608. || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
  6609. {
  6610. result = expand_expr (exp, target, tmode,
  6611. modifier == EXPAND_INITIALIZER
  6612. ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
  6613. /* If the DECL isn't in memory, then the DECL wasn't properly
  6614. marked TREE_ADDRESSABLE, which will be either a front-end
  6615. or a tree optimizer bug. */
  6616. if (TREE_ADDRESSABLE (exp)
  6617. && ! MEM_P (result)
  6618. && ! targetm.calls.allocate_stack_slots_for_args ())
  6619. {
  6620. error ("local frame unavailable (naked function?)");
  6621. return result;
  6622. }
  6623. else
  6624. gcc_assert (MEM_P (result));
  6625. result = XEXP (result, 0);
  6626. /* ??? Is this needed anymore? */
  6627. if (DECL_P (exp))
  6628. TREE_USED (exp) = 1;
  6629. if (modifier != EXPAND_INITIALIZER
  6630. && modifier != EXPAND_CONST_ADDRESS
  6631. && modifier != EXPAND_SUM)
  6632. result = force_operand (result, target);
  6633. return result;
  6634. }
  6635. /* Pass FALSE as the last argument to get_inner_reference although
  6636. we are expanding to RTL. The rationale is that we know how to
  6637. handle "aligning nodes" here: we can just bypass them because
  6638. they won't change the final object whose address will be returned
  6639. (they actually exist only for that purpose). */
  6640. inner = get_inner_reference (exp, &bitsize, &bitpos, &offset,
  6641. &mode1, &unsignedp, &volatilep, false);
  6642. break;
  6643. }
  6644. /* We must have made progress. */
  6645. gcc_assert (inner != exp);
  6646. subtarget = offset || bitpos ? NULL_RTX : target;
  6647. /* For VIEW_CONVERT_EXPR, where the outer alignment is bigger than
  6648. inner alignment, force the inner to be sufficiently aligned. */
  6649. if (CONSTANT_CLASS_P (inner)
  6650. && TYPE_ALIGN (TREE_TYPE (inner)) < TYPE_ALIGN (TREE_TYPE (exp)))
  6651. {
  6652. inner = copy_node (inner);
  6653. TREE_TYPE (inner) = copy_node (TREE_TYPE (inner));
  6654. TYPE_ALIGN (TREE_TYPE (inner)) = TYPE_ALIGN (TREE_TYPE (exp));
  6655. TYPE_USER_ALIGN (TREE_TYPE (inner)) = 1;
  6656. }
  6657. result = expand_expr_addr_expr_1 (inner, subtarget, tmode, modifier, as);
  6658. if (offset)
  6659. {
  6660. rtx tmp;
  6661. if (modifier != EXPAND_NORMAL)
  6662. result = force_operand (result, NULL);
  6663. tmp = expand_expr (offset, NULL_RTX, tmode,
  6664. modifier == EXPAND_INITIALIZER
  6665. ? EXPAND_INITIALIZER : EXPAND_NORMAL);
  6666. /* expand_expr is allowed to return an object in a mode other
  6667. than TMODE. If it did, we need to convert. */
  6668. if (GET_MODE (tmp) != VOIDmode && tmode != GET_MODE (tmp))
  6669. tmp = convert_modes (tmode, GET_MODE (tmp),
  6670. tmp, TYPE_UNSIGNED (TREE_TYPE (offset)));
  6671. result = convert_memory_address_addr_space (tmode, result, as);
  6672. tmp = convert_memory_address_addr_space (tmode, tmp, as);
  6673. if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
  6674. result = simplify_gen_binary (PLUS, tmode, result, tmp);
  6675. else
  6676. {
  6677. subtarget = bitpos ? NULL_RTX : target;
  6678. result = expand_simple_binop (tmode, PLUS, result, tmp, subtarget,
  6679. 1, OPTAB_LIB_WIDEN);
  6680. }
  6681. }
  6682. if (bitpos)
  6683. {
  6684. /* Someone beforehand should have rejected taking the address
  6685. of such an object. */
  6686. gcc_assert ((bitpos % BITS_PER_UNIT) == 0);
  6687. result = convert_memory_address_addr_space (tmode, result, as);
  6688. result = plus_constant (tmode, result, bitpos / BITS_PER_UNIT);
  6689. if (modifier < EXPAND_SUM)
  6690. result = force_operand (result, target);
  6691. }
  6692. return result;
  6693. }
  6694. /* A subroutine of expand_expr. Evaluate EXP, which is an ADDR_EXPR.
  6695. The TARGET, TMODE and MODIFIER arguments are as for expand_expr. */
  6696. static rtx
  6697. expand_expr_addr_expr (tree exp, rtx target, machine_mode tmode,
  6698. enum expand_modifier modifier)
  6699. {
  6700. addr_space_t as = ADDR_SPACE_GENERIC;
  6701. machine_mode address_mode = Pmode;
  6702. machine_mode pointer_mode = ptr_mode;
  6703. machine_mode rmode;
  6704. rtx result;
  6705. /* Target mode of VOIDmode says "whatever's natural". */
  6706. if (tmode == VOIDmode)
  6707. tmode = TYPE_MODE (TREE_TYPE (exp));
  6708. if (POINTER_TYPE_P (TREE_TYPE (exp)))
  6709. {
  6710. as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)));
  6711. address_mode = targetm.addr_space.address_mode (as);
  6712. pointer_mode = targetm.addr_space.pointer_mode (as);
  6713. }
  6714. /* We can get called with some Weird Things if the user does silliness
  6715. like "(short) &a". In that case, convert_memory_address won't do
  6716. the right thing, so ignore the given target mode. */
  6717. if (tmode != address_mode && tmode != pointer_mode)
  6718. tmode = address_mode;
  6719. result = expand_expr_addr_expr_1 (TREE_OPERAND (exp, 0), target,
  6720. tmode, modifier, as);
  6721. /* Despite expand_expr claims concerning ignoring TMODE when not
  6722. strictly convenient, stuff breaks if we don't honor it. Note
  6723. that combined with the above, we only do this for pointer modes. */
  6724. rmode = GET_MODE (result);
  6725. if (rmode == VOIDmode)
  6726. rmode = tmode;
  6727. if (rmode != tmode)
  6728. result = convert_memory_address_addr_space (tmode, result, as);
  6729. return result;
  6730. }
  6731. /* Generate code for computing CONSTRUCTOR EXP.
  6732. An rtx for the computed value is returned. If AVOID_TEMP_MEM
  6733. is TRUE, instead of creating a temporary variable in memory
  6734. NULL is returned and the caller needs to handle it differently. */
  6735. static rtx
  6736. expand_constructor (tree exp, rtx target, enum expand_modifier modifier,
  6737. bool avoid_temp_mem)
  6738. {
  6739. tree type = TREE_TYPE (exp);
  6740. machine_mode mode = TYPE_MODE (type);
  6741. /* Try to avoid creating a temporary at all. This is possible
  6742. if all of the initializer is zero.
  6743. FIXME: try to handle all [0..255] initializers we can handle
  6744. with memset. */
  6745. if (TREE_STATIC (exp)
  6746. && !TREE_ADDRESSABLE (exp)
  6747. && target != 0 && mode == BLKmode
  6748. && all_zeros_p (exp))
  6749. {
  6750. clear_storage (target, expr_size (exp), BLOCK_OP_NORMAL);
  6751. return target;
  6752. }
  6753. /* All elts simple constants => refer to a constant in memory. But
  6754. if this is a non-BLKmode mode, let it store a field at a time
  6755. since that should make a CONST_INT, CONST_WIDE_INT or
  6756. CONST_DOUBLE when we fold. Likewise, if we have a target we can
  6757. use, it is best to store directly into the target unless the type
  6758. is large enough that memcpy will be used. If we are making an
  6759. initializer and all operands are constant, put it in memory as
  6760. well.
  6761. FIXME: Avoid trying to fill vector constructors piece-meal.
  6762. Output them with output_constant_def below unless we're sure
  6763. they're zeros. This should go away when vector initializers
  6764. are treated like VECTOR_CST instead of arrays. */
  6765. if ((TREE_STATIC (exp)
  6766. && ((mode == BLKmode
  6767. && ! (target != 0 && safe_from_p (target, exp, 1)))
  6768. || TREE_ADDRESSABLE (exp)
  6769. || (tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
  6770. && (! can_move_by_pieces
  6771. (tree_to_uhwi (TYPE_SIZE_UNIT (type)),
  6772. TYPE_ALIGN (type)))
  6773. && ! mostly_zeros_p (exp))))
  6774. || ((modifier == EXPAND_INITIALIZER || modifier == EXPAND_CONST_ADDRESS)
  6775. && TREE_CONSTANT (exp)))
  6776. {
  6777. rtx constructor;
  6778. if (avoid_temp_mem)
  6779. return NULL_RTX;
  6780. constructor = expand_expr_constant (exp, 1, modifier);
  6781. if (modifier != EXPAND_CONST_ADDRESS
  6782. && modifier != EXPAND_INITIALIZER
  6783. && modifier != EXPAND_SUM)
  6784. constructor = validize_mem (constructor);
  6785. return constructor;
  6786. }
  6787. /* Handle calls that pass values in multiple non-contiguous
  6788. locations. The Irix 6 ABI has examples of this. */
  6789. if (target == 0 || ! safe_from_p (target, exp, 1)
  6790. || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM)
  6791. {
  6792. if (avoid_temp_mem)
  6793. return NULL_RTX;
  6794. target = assign_temp (type, TREE_ADDRESSABLE (exp), 1);
  6795. }
  6796. store_constructor (exp, target, 0, int_expr_size (exp));
  6797. return target;
  6798. }
  6799. /* expand_expr: generate code for computing expression EXP.
  6800. An rtx for the computed value is returned. The value is never null.
  6801. In the case of a void EXP, const0_rtx is returned.
  6802. The value may be stored in TARGET if TARGET is nonzero.
  6803. TARGET is just a suggestion; callers must assume that
  6804. the rtx returned may not be the same as TARGET.
  6805. If TARGET is CONST0_RTX, it means that the value will be ignored.
  6806. If TMODE is not VOIDmode, it suggests generating the
  6807. result in mode TMODE. But this is done only when convenient.
  6808. Otherwise, TMODE is ignored and the value generated in its natural mode.
  6809. TMODE is just a suggestion; callers must assume that
  6810. the rtx returned may not have mode TMODE.
  6811. Note that TARGET may have neither TMODE nor MODE. In that case, it
  6812. probably will not be used.
  6813. If MODIFIER is EXPAND_SUM then when EXP is an addition
  6814. we can return an rtx of the form (MULT (REG ...) (CONST_INT ...))
  6815. or a nest of (PLUS ...) and (MINUS ...) where the terms are
  6816. products as above, or REG or MEM, or constant.
  6817. Ordinarily in such cases we would output mul or add instructions
  6818. and then return a pseudo reg containing the sum.
  6819. EXPAND_INITIALIZER is much like EXPAND_SUM except that
  6820. it also marks a label as absolutely required (it can't be dead).
  6821. It also makes a ZERO_EXTEND or SIGN_EXTEND instead of emitting extend insns.
  6822. This is used for outputting expressions used in initializers.
  6823. EXPAND_CONST_ADDRESS says that it is okay to return a MEM
  6824. with a constant address even if that address is not normally legitimate.
  6825. EXPAND_INITIALIZER and EXPAND_SUM also have this effect.
  6826. EXPAND_STACK_PARM is used when expanding to a TARGET on the stack for
  6827. a call parameter. Such targets require special care as we haven't yet
  6828. marked TARGET so that it's safe from being trashed by libcalls. We
  6829. don't want to use TARGET for anything but the final result;
  6830. Intermediate values must go elsewhere. Additionally, calls to
  6831. emit_block_move will be flagged with BLOCK_OP_CALL_PARM.
  6832. If EXP is a VAR_DECL whose DECL_RTL was a MEM with an invalid
  6833. address, and ALT_RTL is non-NULL, then *ALT_RTL is set to the
  6834. DECL_RTL of the VAR_DECL. *ALT_RTL is also set if EXP is a
  6835. COMPOUND_EXPR whose second argument is such a VAR_DECL, and so on
  6836. recursively.
  6837. If INNER_REFERENCE_P is true, we are expanding an inner reference.
  6838. In this case, we don't adjust a returned MEM rtx that wouldn't be
  6839. sufficiently aligned for its mode; instead, it's up to the caller
  6840. to deal with it afterwards. This is used to make sure that unaligned
  6841. base objects for which out-of-bounds accesses are supported, for
  6842. example record types with trailing arrays, aren't realigned behind
  6843. the back of the caller.
  6844. The normal operating mode is to pass FALSE for this parameter. */
  6845. rtx
  6846. expand_expr_real (tree exp, rtx target, machine_mode tmode,
  6847. enum expand_modifier modifier, rtx *alt_rtl,
  6848. bool inner_reference_p)
  6849. {
  6850. rtx ret;
  6851. /* Handle ERROR_MARK before anybody tries to access its type. */
  6852. if (TREE_CODE (exp) == ERROR_MARK
  6853. || (TREE_CODE (TREE_TYPE (exp)) == ERROR_MARK))
  6854. {
  6855. ret = CONST0_RTX (tmode);
  6856. return ret ? ret : const0_rtx;
  6857. }
  6858. ret = expand_expr_real_1 (exp, target, tmode, modifier, alt_rtl,
  6859. inner_reference_p);
  6860. return ret;
  6861. }
  6862. /* Try to expand the conditional expression which is represented by
  6863. TREEOP0 ? TREEOP1 : TREEOP2 using conditonal moves. If succeseds
  6864. return the rtl reg which repsents the result. Otherwise return
  6865. NULL_RTL. */
  6866. static rtx
  6867. expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
  6868. tree treeop1 ATTRIBUTE_UNUSED,
  6869. tree treeop2 ATTRIBUTE_UNUSED)
  6870. {
  6871. #ifdef HAVE_conditional_move
  6872. rtx insn;
  6873. rtx op00, op01, op1, op2;
  6874. enum rtx_code comparison_code;
  6875. machine_mode comparison_mode;
  6876. gimple srcstmt;
  6877. rtx temp;
  6878. tree type = TREE_TYPE (treeop1);
  6879. int unsignedp = TYPE_UNSIGNED (type);
  6880. machine_mode mode = TYPE_MODE (type);
  6881. machine_mode orig_mode = mode;
  6882. /* If we cannot do a conditional move on the mode, try doing it
  6883. with the promoted mode. */
  6884. if (!can_conditionally_move_p (mode))
  6885. {
  6886. mode = promote_mode (type, mode, &unsignedp);
  6887. if (!can_conditionally_move_p (mode))
  6888. return NULL_RTX;
  6889. temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */
  6890. }
  6891. else
  6892. temp = assign_temp (type, 0, 1);
  6893. start_sequence ();
  6894. expand_operands (treeop1, treeop2,
  6895. temp, &op1, &op2, EXPAND_NORMAL);
  6896. if (TREE_CODE (treeop0) == SSA_NAME
  6897. && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison)))
  6898. {
  6899. tree type = TREE_TYPE (gimple_assign_rhs1 (srcstmt));
  6900. enum tree_code cmpcode = gimple_assign_rhs_code (srcstmt);
  6901. op00 = expand_normal (gimple_assign_rhs1 (srcstmt));
  6902. op01 = expand_normal (gimple_assign_rhs2 (srcstmt));
  6903. comparison_mode = TYPE_MODE (type);
  6904. unsignedp = TYPE_UNSIGNED (type);
  6905. comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
  6906. }
  6907. else if (TREE_CODE_CLASS (TREE_CODE (treeop0)) == tcc_comparison)
  6908. {
  6909. tree type = TREE_TYPE (TREE_OPERAND (treeop0, 0));
  6910. enum tree_code cmpcode = TREE_CODE (treeop0);
  6911. op00 = expand_normal (TREE_OPERAND (treeop0, 0));
  6912. op01 = expand_normal (TREE_OPERAND (treeop0, 1));
  6913. unsignedp = TYPE_UNSIGNED (type);
  6914. comparison_mode = TYPE_MODE (type);
  6915. comparison_code = convert_tree_comp_to_rtx (cmpcode, unsignedp);
  6916. }
  6917. else
  6918. {
  6919. op00 = expand_normal (treeop0);
  6920. op01 = const0_rtx;
  6921. comparison_code = NE;
  6922. comparison_mode = GET_MODE (op00);
  6923. if (comparison_mode == VOIDmode)
  6924. comparison_mode = TYPE_MODE (TREE_TYPE (treeop0));
  6925. }
  6926. if (GET_MODE (op1) != mode)
  6927. op1 = gen_lowpart (mode, op1);
  6928. if (GET_MODE (op2) != mode)
  6929. op2 = gen_lowpart (mode, op2);
  6930. /* Try to emit the conditional move. */
  6931. insn = emit_conditional_move (temp, comparison_code,
  6932. op00, op01, comparison_mode,
  6933. op1, op2, mode,
  6934. unsignedp);
  6935. /* If we could do the conditional move, emit the sequence,
  6936. and return. */
  6937. if (insn)
  6938. {
  6939. rtx_insn *seq = get_insns ();
  6940. end_sequence ();
  6941. emit_insn (seq);
  6942. return convert_modes (orig_mode, mode, temp, 0);
  6943. }
  6944. /* Otherwise discard the sequence and fall back to code with
  6945. branches. */
  6946. end_sequence ();
  6947. #endif
  6948. return NULL_RTX;
  6949. }
  6950. rtx
  6951. expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
  6952. enum expand_modifier modifier)
  6953. {
  6954. rtx op0, op1, op2, temp;
  6955. tree type;
  6956. int unsignedp;
  6957. machine_mode mode;
  6958. enum tree_code code = ops->code;
  6959. optab this_optab;
  6960. rtx subtarget, original_target;
  6961. int ignore;
  6962. bool reduce_bit_field;
  6963. location_t loc = ops->location;
  6964. tree treeop0, treeop1, treeop2;
  6965. #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \
  6966. ? reduce_to_bit_field_precision ((expr), \
  6967. target, \
  6968. type) \
  6969. : (expr))
  6970. type = ops->type;
  6971. mode = TYPE_MODE (type);
  6972. unsignedp = TYPE_UNSIGNED (type);
  6973. treeop0 = ops->op0;
  6974. treeop1 = ops->op1;
  6975. treeop2 = ops->op2;
  6976. /* We should be called only on simple (binary or unary) expressions,
  6977. exactly those that are valid in gimple expressions that aren't
  6978. GIMPLE_SINGLE_RHS (or invalid). */
  6979. gcc_assert (get_gimple_rhs_class (code) == GIMPLE_UNARY_RHS
  6980. || get_gimple_rhs_class (code) == GIMPLE_BINARY_RHS
  6981. || get_gimple_rhs_class (code) == GIMPLE_TERNARY_RHS);
  6982. ignore = (target == const0_rtx
  6983. || ((CONVERT_EXPR_CODE_P (code)
  6984. || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
  6985. && TREE_CODE (type) == VOID_TYPE));
  6986. /* We should be called only if we need the result. */
  6987. gcc_assert (!ignore);
  6988. /* An operation in what may be a bit-field type needs the
  6989. result to be reduced to the precision of the bit-field type,
  6990. which is narrower than that of the type's mode. */
  6991. reduce_bit_field = (INTEGRAL_TYPE_P (type)
  6992. && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
  6993. if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
  6994. target = 0;
  6995. /* Use subtarget as the target for operand 0 of a binary operation. */
  6996. subtarget = get_subtarget (target);
  6997. original_target = target;
  6998. switch (code)
  6999. {
  7000. case NON_LVALUE_EXPR:
  7001. case PAREN_EXPR:
  7002. CASE_CONVERT:
  7003. if (treeop0 == error_mark_node)
  7004. return const0_rtx;
  7005. if (TREE_CODE (type) == UNION_TYPE)
  7006. {
  7007. tree valtype = TREE_TYPE (treeop0);
  7008. /* If both input and output are BLKmode, this conversion isn't doing
  7009. anything except possibly changing memory attribute. */
  7010. if (mode == BLKmode && TYPE_MODE (valtype) == BLKmode)
  7011. {
  7012. rtx result = expand_expr (treeop0, target, tmode,
  7013. modifier);
  7014. result = copy_rtx (result);
  7015. set_mem_attributes (result, type, 0);
  7016. return result;
  7017. }
  7018. if (target == 0)
  7019. {
  7020. if (TYPE_MODE (type) != BLKmode)
  7021. target = gen_reg_rtx (TYPE_MODE (type));
  7022. else
  7023. target = assign_temp (type, 1, 1);
  7024. }
  7025. if (MEM_P (target))
  7026. /* Store data into beginning of memory target. */
  7027. store_expr (treeop0,
  7028. adjust_address (target, TYPE_MODE (valtype), 0),
  7029. modifier == EXPAND_STACK_PARM,
  7030. false);
  7031. else
  7032. {
  7033. gcc_assert (REG_P (target));
  7034. /* Store this field into a union of the proper type. */
  7035. store_field (target,
  7036. MIN ((int_size_in_bytes (TREE_TYPE
  7037. (treeop0))
  7038. * BITS_PER_UNIT),
  7039. (HOST_WIDE_INT) GET_MODE_BITSIZE (mode)),
  7040. 0, 0, 0, TYPE_MODE (valtype), treeop0, 0, false);
  7041. }
  7042. /* Return the entire union. */
  7043. return target;
  7044. }
  7045. if (mode == TYPE_MODE (TREE_TYPE (treeop0)))
  7046. {
  7047. op0 = expand_expr (treeop0, target, VOIDmode,
  7048. modifier);
  7049. /* If the signedness of the conversion differs and OP0 is
  7050. a promoted SUBREG, clear that indication since we now
  7051. have to do the proper extension. */
  7052. if (TYPE_UNSIGNED (TREE_TYPE (treeop0)) != unsignedp
  7053. && GET_CODE (op0) == SUBREG)
  7054. SUBREG_PROMOTED_VAR_P (op0) = 0;
  7055. return REDUCE_BIT_FIELD (op0);
  7056. }
  7057. op0 = expand_expr (treeop0, NULL_RTX, mode,
  7058. modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier);
  7059. if (GET_MODE (op0) == mode)
  7060. ;
  7061. /* If OP0 is a constant, just convert it into the proper mode. */
  7062. else if (CONSTANT_P (op0))
  7063. {
  7064. tree inner_type = TREE_TYPE (treeop0);
  7065. machine_mode inner_mode = GET_MODE (op0);
  7066. if (inner_mode == VOIDmode)
  7067. inner_mode = TYPE_MODE (inner_type);
  7068. if (modifier == EXPAND_INITIALIZER)
  7069. op0 = simplify_gen_subreg (mode, op0, inner_mode,
  7070. subreg_lowpart_offset (mode,
  7071. inner_mode));
  7072. else
  7073. op0= convert_modes (mode, inner_mode, op0,
  7074. TYPE_UNSIGNED (inner_type));
  7075. }
  7076. else if (modifier == EXPAND_INITIALIZER)
  7077. op0 = gen_rtx_fmt_e (unsignedp ? ZERO_EXTEND : SIGN_EXTEND, mode, op0);
  7078. else if (target == 0)
  7079. op0 = convert_to_mode (mode, op0,
  7080. TYPE_UNSIGNED (TREE_TYPE
  7081. (treeop0)));
  7082. else
  7083. {
  7084. convert_move (target, op0,
  7085. TYPE_UNSIGNED (TREE_TYPE (treeop0)));
  7086. op0 = target;
  7087. }
  7088. return REDUCE_BIT_FIELD (op0);
  7089. case ADDR_SPACE_CONVERT_EXPR:
  7090. {
  7091. tree treeop0_type = TREE_TYPE (treeop0);
  7092. addr_space_t as_to;
  7093. addr_space_t as_from;
  7094. gcc_assert (POINTER_TYPE_P (type));
  7095. gcc_assert (POINTER_TYPE_P (treeop0_type));
  7096. as_to = TYPE_ADDR_SPACE (TREE_TYPE (type));
  7097. as_from = TYPE_ADDR_SPACE (TREE_TYPE (treeop0_type));
  7098. /* Conversions between pointers to the same address space should
  7099. have been implemented via CONVERT_EXPR / NOP_EXPR. */
  7100. gcc_assert (as_to != as_from);
  7101. /* Ask target code to handle conversion between pointers
  7102. to overlapping address spaces. */
  7103. if (targetm.addr_space.subset_p (as_to, as_from)
  7104. || targetm.addr_space.subset_p (as_from, as_to))
  7105. {
  7106. op0 = expand_expr (treeop0, NULL_RTX, VOIDmode, modifier);
  7107. op0 = targetm.addr_space.convert (op0, treeop0_type, type);
  7108. gcc_assert (op0);
  7109. return op0;
  7110. }
  7111. /* For disjoint address spaces, converting anything but
  7112. a null pointer invokes undefined behaviour. We simply
  7113. always return a null pointer here. */
  7114. return CONST0_RTX (mode);
  7115. }
  7116. case POINTER_PLUS_EXPR:
  7117. /* Even though the sizetype mode and the pointer's mode can be different
  7118. expand is able to handle this correctly and get the correct result out
  7119. of the PLUS_EXPR code. */
  7120. /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
  7121. if sizetype precision is smaller than pointer precision. */
  7122. if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
  7123. treeop1 = fold_convert_loc (loc, type,
  7124. fold_convert_loc (loc, ssizetype,
  7125. treeop1));
  7126. /* If sizetype precision is larger than pointer precision, truncate the
  7127. offset to have matching modes. */
  7128. else if (TYPE_PRECISION (sizetype) > TYPE_PRECISION (type))
  7129. treeop1 = fold_convert_loc (loc, type, treeop1);
  7130. case PLUS_EXPR:
  7131. /* If we are adding a constant, a VAR_DECL that is sp, fp, or ap, and
  7132. something else, make sure we add the register to the constant and
  7133. then to the other thing. This case can occur during strength
  7134. reduction and doing it this way will produce better code if the
  7135. frame pointer or argument pointer is eliminated.
  7136. fold-const.c will ensure that the constant is always in the inner
  7137. PLUS_EXPR, so the only case we need to do anything about is if
  7138. sp, ap, or fp is our second argument, in which case we must swap
  7139. the innermost first argument and our second argument. */
  7140. if (TREE_CODE (treeop0) == PLUS_EXPR
  7141. && TREE_CODE (TREE_OPERAND (treeop0, 1)) == INTEGER_CST
  7142. && TREE_CODE (treeop1) == VAR_DECL
  7143. && (DECL_RTL (treeop1) == frame_pointer_rtx
  7144. || DECL_RTL (treeop1) == stack_pointer_rtx
  7145. || DECL_RTL (treeop1) == arg_pointer_rtx))
  7146. {
  7147. gcc_unreachable ();
  7148. }
  7149. /* If the result is to be ptr_mode and we are adding an integer to
  7150. something, we might be forming a constant. So try to use
  7151. plus_constant. If it produces a sum and we can't accept it,
  7152. use force_operand. This allows P = &ARR[const] to generate
  7153. efficient code on machines where a SYMBOL_REF is not a valid
  7154. address.
  7155. If this is an EXPAND_SUM call, always return the sum. */
  7156. if (modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER
  7157. || (mode == ptr_mode && (unsignedp || ! flag_trapv)))
  7158. {
  7159. if (modifier == EXPAND_STACK_PARM)
  7160. target = 0;
  7161. if (TREE_CODE (treeop0) == INTEGER_CST
  7162. && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
  7163. && TREE_CONSTANT (treeop1))
  7164. {
  7165. rtx constant_part;
  7166. HOST_WIDE_INT wc;
  7167. machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop1));
  7168. op1 = expand_expr (treeop1, subtarget, VOIDmode,
  7169. EXPAND_SUM);
  7170. /* Use wi::shwi to ensure that the constant is
  7171. truncated according to the mode of OP1, then sign extended
  7172. to a HOST_WIDE_INT. Using the constant directly can result
  7173. in non-canonical RTL in a 64x32 cross compile. */
  7174. wc = TREE_INT_CST_LOW (treeop0);
  7175. constant_part =
  7176. immed_wide_int_const (wi::shwi (wc, wmode), wmode);
  7177. op1 = plus_constant (mode, op1, INTVAL (constant_part));
  7178. if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
  7179. op1 = force_operand (op1, target);
  7180. return REDUCE_BIT_FIELD (op1);
  7181. }
  7182. else if (TREE_CODE (treeop1) == INTEGER_CST
  7183. && GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT
  7184. && TREE_CONSTANT (treeop0))
  7185. {
  7186. rtx constant_part;
  7187. HOST_WIDE_INT wc;
  7188. machine_mode wmode = TYPE_MODE (TREE_TYPE (treeop0));
  7189. op0 = expand_expr (treeop0, subtarget, VOIDmode,
  7190. (modifier == EXPAND_INITIALIZER
  7191. ? EXPAND_INITIALIZER : EXPAND_SUM));
  7192. if (! CONSTANT_P (op0))
  7193. {
  7194. op1 = expand_expr (treeop1, NULL_RTX,
  7195. VOIDmode, modifier);
  7196. /* Return a PLUS if modifier says it's OK. */
  7197. if (modifier == EXPAND_SUM
  7198. || modifier == EXPAND_INITIALIZER)
  7199. return simplify_gen_binary (PLUS, mode, op0, op1);
  7200. goto binop2;
  7201. }
  7202. /* Use wi::shwi to ensure that the constant is
  7203. truncated according to the mode of OP1, then sign extended
  7204. to a HOST_WIDE_INT. Using the constant directly can result
  7205. in non-canonical RTL in a 64x32 cross compile. */
  7206. wc = TREE_INT_CST_LOW (treeop1);
  7207. constant_part
  7208. = immed_wide_int_const (wi::shwi (wc, wmode), wmode);
  7209. op0 = plus_constant (mode, op0, INTVAL (constant_part));
  7210. if (modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
  7211. op0 = force_operand (op0, target);
  7212. return REDUCE_BIT_FIELD (op0);
  7213. }
  7214. }
  7215. /* Use TER to expand pointer addition of a negated value
  7216. as pointer subtraction. */
  7217. if ((POINTER_TYPE_P (TREE_TYPE (treeop0))
  7218. || (TREE_CODE (TREE_TYPE (treeop0)) == VECTOR_TYPE
  7219. && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (treeop0)))))
  7220. && TREE_CODE (treeop1) == SSA_NAME
  7221. && TYPE_MODE (TREE_TYPE (treeop0))
  7222. == TYPE_MODE (TREE_TYPE (treeop1)))
  7223. {
  7224. gimple def = get_def_for_expr (treeop1, NEGATE_EXPR);
  7225. if (def)
  7226. {
  7227. treeop1 = gimple_assign_rhs1 (def);
  7228. code = MINUS_EXPR;
  7229. goto do_minus;
  7230. }
  7231. }
  7232. /* No sense saving up arithmetic to be done
  7233. if it's all in the wrong mode to form part of an address.
  7234. And force_operand won't know whether to sign-extend or
  7235. zero-extend. */
  7236. if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
  7237. || mode != ptr_mode)
  7238. {
  7239. expand_operands (treeop0, treeop1,
  7240. subtarget, &op0, &op1, EXPAND_NORMAL);
  7241. if (op0 == const0_rtx)
  7242. return op1;
  7243. if (op1 == const0_rtx)
  7244. return op0;
  7245. goto binop2;
  7246. }
  7247. expand_operands (treeop0, treeop1,
  7248. subtarget, &op0, &op1, modifier);
  7249. return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
  7250. case MINUS_EXPR:
  7251. do_minus:
  7252. /* For initializers, we are allowed to return a MINUS of two
  7253. symbolic constants. Here we handle all cases when both operands
  7254. are constant. */
  7255. /* Handle difference of two symbolic constants,
  7256. for the sake of an initializer. */
  7257. if ((modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
  7258. && really_constant_p (treeop0)
  7259. && really_constant_p (treeop1))
  7260. {
  7261. expand_operands (treeop0, treeop1,
  7262. NULL_RTX, &op0, &op1, modifier);
  7263. /* If the last operand is a CONST_INT, use plus_constant of
  7264. the negated constant. Else make the MINUS. */
  7265. if (CONST_INT_P (op1))
  7266. return REDUCE_BIT_FIELD (plus_constant (mode, op0,
  7267. -INTVAL (op1)));
  7268. else
  7269. return REDUCE_BIT_FIELD (gen_rtx_MINUS (mode, op0, op1));
  7270. }
  7271. /* No sense saving up arithmetic to be done
  7272. if it's all in the wrong mode to form part of an address.
  7273. And force_operand won't know whether to sign-extend or
  7274. zero-extend. */
  7275. if ((modifier != EXPAND_SUM && modifier != EXPAND_INITIALIZER)
  7276. || mode != ptr_mode)
  7277. goto binop;
  7278. expand_operands (treeop0, treeop1,
  7279. subtarget, &op0, &op1, modifier);
  7280. /* Convert A - const to A + (-const). */
  7281. if (CONST_INT_P (op1))
  7282. {
  7283. op1 = negate_rtx (mode, op1);
  7284. return REDUCE_BIT_FIELD (simplify_gen_binary (PLUS, mode, op0, op1));
  7285. }
  7286. goto binop2;
  7287. case WIDEN_MULT_PLUS_EXPR:
  7288. case WIDEN_MULT_MINUS_EXPR:
  7289. expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  7290. op2 = expand_normal (treeop2);
  7291. target = expand_widen_pattern_expr (ops, op0, op1, op2,
  7292. target, unsignedp);
  7293. return target;
  7294. case WIDEN_MULT_EXPR:
  7295. /* If first operand is constant, swap them.
  7296. Thus the following special case checks need only
  7297. check the second operand. */
  7298. if (TREE_CODE (treeop0) == INTEGER_CST)
  7299. {
  7300. tree t1 = treeop0;
  7301. treeop0 = treeop1;
  7302. treeop1 = t1;
  7303. }
  7304. /* First, check if we have a multiplication of one signed and one
  7305. unsigned operand. */
  7306. if (TREE_CODE (treeop1) != INTEGER_CST
  7307. && (TYPE_UNSIGNED (TREE_TYPE (treeop0))
  7308. != TYPE_UNSIGNED (TREE_TYPE (treeop1))))
  7309. {
  7310. machine_mode innermode = TYPE_MODE (TREE_TYPE (treeop0));
  7311. this_optab = usmul_widen_optab;
  7312. if (find_widening_optab_handler (this_optab, mode, innermode, 0)
  7313. != CODE_FOR_nothing)
  7314. {
  7315. if (TYPE_UNSIGNED (TREE_TYPE (treeop0)))
  7316. expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
  7317. EXPAND_NORMAL);
  7318. else
  7319. expand_operands (treeop0, treeop1, NULL_RTX, &op1, &op0,
  7320. EXPAND_NORMAL);
  7321. /* op0 and op1 might still be constant, despite the above
  7322. != INTEGER_CST check. Handle it. */
  7323. if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
  7324. {
  7325. op0 = convert_modes (innermode, mode, op0, true);
  7326. op1 = convert_modes (innermode, mode, op1, false);
  7327. return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
  7328. target, unsignedp));
  7329. }
  7330. goto binop3;
  7331. }
  7332. }
  7333. /* Check for a multiplication with matching signedness. */
  7334. else if ((TREE_CODE (treeop1) == INTEGER_CST
  7335. && int_fits_type_p (treeop1, TREE_TYPE (treeop0)))
  7336. || (TYPE_UNSIGNED (TREE_TYPE (treeop1))
  7337. == TYPE_UNSIGNED (TREE_TYPE (treeop0))))
  7338. {
  7339. tree op0type = TREE_TYPE (treeop0);
  7340. machine_mode innermode = TYPE_MODE (op0type);
  7341. bool zextend_p = TYPE_UNSIGNED (op0type);
  7342. optab other_optab = zextend_p ? smul_widen_optab : umul_widen_optab;
  7343. this_optab = zextend_p ? umul_widen_optab : smul_widen_optab;
  7344. if (TREE_CODE (treeop0) != INTEGER_CST)
  7345. {
  7346. if (find_widening_optab_handler (this_optab, mode, innermode, 0)
  7347. != CODE_FOR_nothing)
  7348. {
  7349. expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1,
  7350. EXPAND_NORMAL);
  7351. /* op0 and op1 might still be constant, despite the above
  7352. != INTEGER_CST check. Handle it. */
  7353. if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
  7354. {
  7355. widen_mult_const:
  7356. op0 = convert_modes (innermode, mode, op0, zextend_p);
  7357. op1
  7358. = convert_modes (innermode, mode, op1,
  7359. TYPE_UNSIGNED (TREE_TYPE (treeop1)));
  7360. return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1,
  7361. target,
  7362. unsignedp));
  7363. }
  7364. temp = expand_widening_mult (mode, op0, op1, target,
  7365. unsignedp, this_optab);
  7366. return REDUCE_BIT_FIELD (temp);
  7367. }
  7368. if (find_widening_optab_handler (other_optab, mode, innermode, 0)
  7369. != CODE_FOR_nothing
  7370. && innermode == word_mode)
  7371. {
  7372. rtx htem, hipart;
  7373. op0 = expand_normal (treeop0);
  7374. if (TREE_CODE (treeop1) == INTEGER_CST)
  7375. op1 = convert_modes (innermode, mode,
  7376. expand_normal (treeop1),
  7377. TYPE_UNSIGNED (TREE_TYPE (treeop1)));
  7378. else
  7379. op1 = expand_normal (treeop1);
  7380. /* op0 and op1 might still be constant, despite the above
  7381. != INTEGER_CST check. Handle it. */
  7382. if (GET_MODE (op0) == VOIDmode && GET_MODE (op1) == VOIDmode)
  7383. goto widen_mult_const;
  7384. temp = expand_binop (mode, other_optab, op0, op1, target,
  7385. unsignedp, OPTAB_LIB_WIDEN);
  7386. hipart = gen_highpart (innermode, temp);
  7387. htem = expand_mult_highpart_adjust (innermode, hipart,
  7388. op0, op1, hipart,
  7389. zextend_p);
  7390. if (htem != hipart)
  7391. emit_move_insn (hipart, htem);
  7392. return REDUCE_BIT_FIELD (temp);
  7393. }
  7394. }
  7395. }
  7396. treeop0 = fold_build1 (CONVERT_EXPR, type, treeop0);
  7397. treeop1 = fold_build1 (CONVERT_EXPR, type, treeop1);
  7398. expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
  7399. return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
  7400. case FMA_EXPR:
  7401. {
  7402. optab opt = fma_optab;
  7403. gimple def0, def2;
  7404. /* If there is no insn for FMA, emit it as __builtin_fma{,f,l}
  7405. call. */
  7406. if (optab_handler (fma_optab, mode) == CODE_FOR_nothing)
  7407. {
  7408. tree fn = mathfn_built_in (TREE_TYPE (treeop0), BUILT_IN_FMA);
  7409. tree call_expr;
  7410. gcc_assert (fn != NULL_TREE);
  7411. call_expr = build_call_expr (fn, 3, treeop0, treeop1, treeop2);
  7412. return expand_builtin (call_expr, target, subtarget, mode, false);
  7413. }
  7414. def0 = get_def_for_expr (treeop0, NEGATE_EXPR);
  7415. /* The multiplication is commutative - look at its 2nd operand
  7416. if the first isn't fed by a negate. */
  7417. if (!def0)
  7418. {
  7419. def0 = get_def_for_expr (treeop1, NEGATE_EXPR);
  7420. /* Swap operands if the 2nd operand is fed by a negate. */
  7421. if (def0)
  7422. {
  7423. tree tem = treeop0;
  7424. treeop0 = treeop1;
  7425. treeop1 = tem;
  7426. }
  7427. }
  7428. def2 = get_def_for_expr (treeop2, NEGATE_EXPR);
  7429. op0 = op2 = NULL;
  7430. if (def0 && def2
  7431. && optab_handler (fnms_optab, mode) != CODE_FOR_nothing)
  7432. {
  7433. opt = fnms_optab;
  7434. op0 = expand_normal (gimple_assign_rhs1 (def0));
  7435. op2 = expand_normal (gimple_assign_rhs1 (def2));
  7436. }
  7437. else if (def0
  7438. && optab_handler (fnma_optab, mode) != CODE_FOR_nothing)
  7439. {
  7440. opt = fnma_optab;
  7441. op0 = expand_normal (gimple_assign_rhs1 (def0));
  7442. }
  7443. else if (def2
  7444. && optab_handler (fms_optab, mode) != CODE_FOR_nothing)
  7445. {
  7446. opt = fms_optab;
  7447. op2 = expand_normal (gimple_assign_rhs1 (def2));
  7448. }
  7449. if (op0 == NULL)
  7450. op0 = expand_expr (treeop0, subtarget, VOIDmode, EXPAND_NORMAL);
  7451. if (op2 == NULL)
  7452. op2 = expand_normal (treeop2);
  7453. op1 = expand_normal (treeop1);
  7454. return expand_ternary_op (TYPE_MODE (type), opt,
  7455. op0, op1, op2, target, 0);
  7456. }
  7457. case MULT_EXPR:
  7458. /* If this is a fixed-point operation, then we cannot use the code
  7459. below because "expand_mult" doesn't support sat/no-sat fixed-point
  7460. multiplications. */
  7461. if (ALL_FIXED_POINT_MODE_P (mode))
  7462. goto binop;
  7463. /* If first operand is constant, swap them.
  7464. Thus the following special case checks need only
  7465. check the second operand. */
  7466. if (TREE_CODE (treeop0) == INTEGER_CST)
  7467. {
  7468. tree t1 = treeop0;
  7469. treeop0 = treeop1;
  7470. treeop1 = t1;
  7471. }
  7472. /* Attempt to return something suitable for generating an
  7473. indexed address, for machines that support that. */
  7474. if (modifier == EXPAND_SUM && mode == ptr_mode
  7475. && tree_fits_shwi_p (treeop1))
  7476. {
  7477. tree exp1 = treeop1;
  7478. op0 = expand_expr (treeop0, subtarget, VOIDmode,
  7479. EXPAND_SUM);
  7480. if (!REG_P (op0))
  7481. op0 = force_operand (op0, NULL_RTX);
  7482. if (!REG_P (op0))
  7483. op0 = copy_to_mode_reg (mode, op0);
  7484. return REDUCE_BIT_FIELD (gen_rtx_MULT (mode, op0,
  7485. gen_int_mode (tree_to_shwi (exp1),
  7486. TYPE_MODE (TREE_TYPE (exp1)))));
  7487. }
  7488. if (modifier == EXPAND_STACK_PARM)
  7489. target = 0;
  7490. expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
  7491. return REDUCE_BIT_FIELD (expand_mult (mode, op0, op1, target, unsignedp));
  7492. case TRUNC_DIV_EXPR:
  7493. case FLOOR_DIV_EXPR:
  7494. case CEIL_DIV_EXPR:
  7495. case ROUND_DIV_EXPR:
  7496. case EXACT_DIV_EXPR:
  7497. /* If this is a fixed-point operation, then we cannot use the code
  7498. below because "expand_divmod" doesn't support sat/no-sat fixed-point
  7499. divisions. */
  7500. if (ALL_FIXED_POINT_MODE_P (mode))
  7501. goto binop;
  7502. if (modifier == EXPAND_STACK_PARM)
  7503. target = 0;
  7504. /* Possible optimization: compute the dividend with EXPAND_SUM
  7505. then if the divisor is constant can optimize the case
  7506. where some terms of the dividend have coeffs divisible by it. */
  7507. expand_operands (treeop0, treeop1,
  7508. subtarget, &op0, &op1, EXPAND_NORMAL);
  7509. return expand_divmod (0, code, mode, op0, op1, target, unsignedp);
  7510. case RDIV_EXPR:
  7511. goto binop;
  7512. case MULT_HIGHPART_EXPR:
  7513. expand_operands (treeop0, treeop1, subtarget, &op0, &op1, EXPAND_NORMAL);
  7514. temp = expand_mult_highpart (mode, op0, op1, target, unsignedp);
  7515. gcc_assert (temp);
  7516. return temp;
  7517. case TRUNC_MOD_EXPR:
  7518. case FLOOR_MOD_EXPR:
  7519. case CEIL_MOD_EXPR:
  7520. case ROUND_MOD_EXPR:
  7521. if (modifier == EXPAND_STACK_PARM)
  7522. target = 0;
  7523. expand_operands (treeop0, treeop1,
  7524. subtarget, &op0, &op1, EXPAND_NORMAL);
  7525. return expand_divmod (1, code, mode, op0, op1, target, unsignedp);
  7526. case FIXED_CONVERT_EXPR:
  7527. op0 = expand_normal (treeop0);
  7528. if (target == 0 || modifier == EXPAND_STACK_PARM)
  7529. target = gen_reg_rtx (mode);
  7530. if ((TREE_CODE (TREE_TYPE (treeop0)) == INTEGER_TYPE
  7531. && TYPE_UNSIGNED (TREE_TYPE (treeop0)))
  7532. || (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)))
  7533. expand_fixed_convert (target, op0, 1, TYPE_SATURATING (type));
  7534. else
  7535. expand_fixed_convert (target, op0, 0, TYPE_SATURATING (type));
  7536. return target;
  7537. case FIX_TRUNC_EXPR:
  7538. op0 = expand_normal (treeop0);
  7539. if (target == 0 || modifier == EXPAND_STACK_PARM)
  7540. target = gen_reg_rtx (mode);
  7541. expand_fix (target, op0, unsignedp);
  7542. return target;
  7543. case FLOAT_EXPR:
  7544. op0 = expand_normal (treeop0);
  7545. if (target == 0 || modifier == EXPAND_STACK_PARM)
  7546. target = gen_reg_rtx (mode);
  7547. /* expand_float can't figure out what to do if FROM has VOIDmode.
  7548. So give it the correct mode. With -O, cse will optimize this. */
  7549. if (GET_MODE (op0) == VOIDmode)
  7550. op0 = copy_to_mode_reg (TYPE_MODE (TREE_TYPE (treeop0)),
  7551. op0);
  7552. expand_float (target, op0,
  7553. TYPE_UNSIGNED (TREE_TYPE (treeop0)));
  7554. return target;
  7555. case NEGATE_EXPR:
  7556. op0 = expand_expr (treeop0, subtarget,
  7557. VOIDmode, EXPAND_NORMAL);
  7558. if (modifier == EXPAND_STACK_PARM)
  7559. target = 0;
  7560. temp = expand_unop (mode,
  7561. optab_for_tree_code (NEGATE_EXPR, type,
  7562. optab_default),
  7563. op0, target, 0);
  7564. gcc_assert (temp);
  7565. return REDUCE_BIT_FIELD (temp);
  7566. case ABS_EXPR:
  7567. op0 = expand_expr (treeop0, subtarget,
  7568. VOIDmode, EXPAND_NORMAL);
  7569. if (modifier == EXPAND_STACK_PARM)
  7570. target = 0;
  7571. /* ABS_EXPR is not valid for complex arguments. */
  7572. gcc_assert (GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
  7573. && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT);
  7574. /* Unsigned abs is simply the operand. Testing here means we don't
  7575. risk generating incorrect code below. */
  7576. if (TYPE_UNSIGNED (type))
  7577. return op0;
  7578. return expand_abs (mode, op0, target, unsignedp,
  7579. safe_from_p (target, treeop0, 1));
  7580. case MAX_EXPR:
  7581. case MIN_EXPR:
  7582. target = original_target;
  7583. if (target == 0
  7584. || modifier == EXPAND_STACK_PARM
  7585. || (MEM_P (target) && MEM_VOLATILE_P (target))
  7586. || GET_MODE (target) != mode
  7587. || (REG_P (target)
  7588. && REGNO (target) < FIRST_PSEUDO_REGISTER))
  7589. target = gen_reg_rtx (mode);
  7590. expand_operands (treeop0, treeop1,
  7591. target, &op0, &op1, EXPAND_NORMAL);
  7592. /* First try to do it with a special MIN or MAX instruction.
  7593. If that does not win, use a conditional jump to select the proper
  7594. value. */
  7595. this_optab = optab_for_tree_code (code, type, optab_default);
  7596. temp = expand_binop (mode, this_optab, op0, op1, target, unsignedp,
  7597. OPTAB_WIDEN);
  7598. if (temp != 0)
  7599. return temp;
  7600. /* At this point, a MEM target is no longer useful; we will get better
  7601. code without it. */
  7602. if (! REG_P (target))
  7603. target = gen_reg_rtx (mode);
  7604. /* If op1 was placed in target, swap op0 and op1. */
  7605. if (target != op0 && target == op1)
  7606. {
  7607. temp = op0;
  7608. op0 = op1;
  7609. op1 = temp;
  7610. }
  7611. /* We generate better code and avoid problems with op1 mentioning
  7612. target by forcing op1 into a pseudo if it isn't a constant. */
  7613. if (! CONSTANT_P (op1))
  7614. op1 = force_reg (mode, op1);
  7615. {
  7616. enum rtx_code comparison_code;
  7617. rtx cmpop1 = op1;
  7618. if (code == MAX_EXPR)
  7619. comparison_code = unsignedp ? GEU : GE;
  7620. else
  7621. comparison_code = unsignedp ? LEU : LE;
  7622. /* Canonicalize to comparisons against 0. */
  7623. if (op1 == const1_rtx)
  7624. {
  7625. /* Converting (a >= 1 ? a : 1) into (a > 0 ? a : 1)
  7626. or (a != 0 ? a : 1) for unsigned.
  7627. For MIN we are safe converting (a <= 1 ? a : 1)
  7628. into (a <= 0 ? a : 1) */
  7629. cmpop1 = const0_rtx;
  7630. if (code == MAX_EXPR)
  7631. comparison_code = unsignedp ? NE : GT;
  7632. }
  7633. if (op1 == constm1_rtx && !unsignedp)
  7634. {
  7635. /* Converting (a >= -1 ? a : -1) into (a >= 0 ? a : -1)
  7636. and (a <= -1 ? a : -1) into (a < 0 ? a : -1) */
  7637. cmpop1 = const0_rtx;
  7638. if (code == MIN_EXPR)
  7639. comparison_code = LT;
  7640. }
  7641. #ifdef HAVE_conditional_move
  7642. /* Use a conditional move if possible. */
  7643. if (can_conditionally_move_p (mode))
  7644. {
  7645. rtx insn;
  7646. start_sequence ();
  7647. /* Try to emit the conditional move. */
  7648. insn = emit_conditional_move (target, comparison_code,
  7649. op0, cmpop1, mode,
  7650. op0, op1, mode,
  7651. unsignedp);
  7652. /* If we could do the conditional move, emit the sequence,
  7653. and return. */
  7654. if (insn)
  7655. {
  7656. rtx_insn *seq = get_insns ();
  7657. end_sequence ();
  7658. emit_insn (seq);
  7659. return target;
  7660. }
  7661. /* Otherwise discard the sequence and fall back to code with
  7662. branches. */
  7663. end_sequence ();
  7664. }
  7665. #endif
  7666. if (target != op0)
  7667. emit_move_insn (target, op0);
  7668. temp = gen_label_rtx ();
  7669. do_compare_rtx_and_jump (target, cmpop1, comparison_code,
  7670. unsignedp, mode, NULL_RTX, NULL_RTX, temp,
  7671. -1);
  7672. }
  7673. emit_move_insn (target, op1);
  7674. emit_label (temp);
  7675. return target;
  7676. case BIT_NOT_EXPR:
  7677. op0 = expand_expr (treeop0, subtarget,
  7678. VOIDmode, EXPAND_NORMAL);
  7679. if (modifier == EXPAND_STACK_PARM)
  7680. target = 0;
  7681. /* In case we have to reduce the result to bitfield precision
  7682. for unsigned bitfield expand this as XOR with a proper constant
  7683. instead. */
  7684. if (reduce_bit_field && TYPE_UNSIGNED (type))
  7685. {
  7686. wide_int mask = wi::mask (TYPE_PRECISION (type),
  7687. false, GET_MODE_PRECISION (mode));
  7688. temp = expand_binop (mode, xor_optab, op0,
  7689. immed_wide_int_const (mask, mode),
  7690. target, 1, OPTAB_LIB_WIDEN);
  7691. }
  7692. else
  7693. temp = expand_unop (mode, one_cmpl_optab, op0, target, 1);
  7694. gcc_assert (temp);
  7695. return temp;
  7696. /* ??? Can optimize bitwise operations with one arg constant.
  7697. Can optimize (a bitwise1 n) bitwise2 (a bitwise3 b)
  7698. and (a bitwise1 b) bitwise2 b (etc)
  7699. but that is probably not worth while. */
  7700. case BIT_AND_EXPR:
  7701. case BIT_IOR_EXPR:
  7702. case BIT_XOR_EXPR:
  7703. goto binop;
  7704. case LROTATE_EXPR:
  7705. case RROTATE_EXPR:
  7706. gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
  7707. || (GET_MODE_PRECISION (TYPE_MODE (type))
  7708. == TYPE_PRECISION (type)));
  7709. /* fall through */
  7710. case LSHIFT_EXPR:
  7711. case RSHIFT_EXPR:
  7712. /* If this is a fixed-point operation, then we cannot use the code
  7713. below because "expand_shift" doesn't support sat/no-sat fixed-point
  7714. shifts. */
  7715. if (ALL_FIXED_POINT_MODE_P (mode))
  7716. goto binop;
  7717. if (! safe_from_p (subtarget, treeop1, 1))
  7718. subtarget = 0;
  7719. if (modifier == EXPAND_STACK_PARM)
  7720. target = 0;
  7721. op0 = expand_expr (treeop0, subtarget,
  7722. VOIDmode, EXPAND_NORMAL);
  7723. temp = expand_variable_shift (code, mode, op0, treeop1, target,
  7724. unsignedp);
  7725. if (code == LSHIFT_EXPR)
  7726. temp = REDUCE_BIT_FIELD (temp);
  7727. return temp;
  7728. /* Could determine the answer when only additive constants differ. Also,
  7729. the addition of one can be handled by changing the condition. */
  7730. case LT_EXPR:
  7731. case LE_EXPR:
  7732. case GT_EXPR:
  7733. case GE_EXPR:
  7734. case EQ_EXPR:
  7735. case NE_EXPR:
  7736. case UNORDERED_EXPR:
  7737. case ORDERED_EXPR:
  7738. case UNLT_EXPR:
  7739. case UNLE_EXPR:
  7740. case UNGT_EXPR:
  7741. case UNGE_EXPR:
  7742. case UNEQ_EXPR:
  7743. case LTGT_EXPR:
  7744. temp = do_store_flag (ops,
  7745. modifier != EXPAND_STACK_PARM ? target : NULL_RTX,
  7746. tmode != VOIDmode ? tmode : mode);
  7747. if (temp)
  7748. return temp;
  7749. /* Use a compare and a jump for BLKmode comparisons, or for function
  7750. type comparisons is HAVE_canonicalize_funcptr_for_compare. */
  7751. if ((target == 0
  7752. || modifier == EXPAND_STACK_PARM
  7753. || ! safe_from_p (target, treeop0, 1)
  7754. || ! safe_from_p (target, treeop1, 1)
  7755. /* Make sure we don't have a hard reg (such as function's return
  7756. value) live across basic blocks, if not optimizing. */
  7757. || (!optimize && REG_P (target)
  7758. && REGNO (target) < FIRST_PSEUDO_REGISTER)))
  7759. target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
  7760. emit_move_insn (target, const0_rtx);
  7761. op1 = gen_label_rtx ();
  7762. jumpifnot_1 (code, treeop0, treeop1, op1, -1);
  7763. if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
  7764. emit_move_insn (target, constm1_rtx);
  7765. else
  7766. emit_move_insn (target, const1_rtx);
  7767. emit_label (op1);
  7768. return target;
  7769. case COMPLEX_EXPR:
  7770. /* Get the rtx code of the operands. */
  7771. op0 = expand_normal (treeop0);
  7772. op1 = expand_normal (treeop1);
  7773. if (!target)
  7774. target = gen_reg_rtx (TYPE_MODE (type));
  7775. else
  7776. /* If target overlaps with op1, then either we need to force
  7777. op1 into a pseudo (if target also overlaps with op0),
  7778. or write the complex parts in reverse order. */
  7779. switch (GET_CODE (target))
  7780. {
  7781. case CONCAT:
  7782. if (reg_overlap_mentioned_p (XEXP (target, 0), op1))
  7783. {
  7784. if (reg_overlap_mentioned_p (XEXP (target, 1), op0))
  7785. {
  7786. complex_expr_force_op1:
  7787. temp = gen_reg_rtx (GET_MODE_INNER (GET_MODE (target)));
  7788. emit_move_insn (temp, op1);
  7789. op1 = temp;
  7790. break;
  7791. }
  7792. complex_expr_swap_order:
  7793. /* Move the imaginary (op1) and real (op0) parts to their
  7794. location. */
  7795. write_complex_part (target, op1, true);
  7796. write_complex_part (target, op0, false);
  7797. return target;
  7798. }
  7799. break;
  7800. case MEM:
  7801. temp = adjust_address_nv (target,
  7802. GET_MODE_INNER (GET_MODE (target)), 0);
  7803. if (reg_overlap_mentioned_p (temp, op1))
  7804. {
  7805. machine_mode imode = GET_MODE_INNER (GET_MODE (target));
  7806. temp = adjust_address_nv (target, imode,
  7807. GET_MODE_SIZE (imode));
  7808. if (reg_overlap_mentioned_p (temp, op0))
  7809. goto complex_expr_force_op1;
  7810. goto complex_expr_swap_order;
  7811. }
  7812. break;
  7813. default:
  7814. if (reg_overlap_mentioned_p (target, op1))
  7815. {
  7816. if (reg_overlap_mentioned_p (target, op0))
  7817. goto complex_expr_force_op1;
  7818. goto complex_expr_swap_order;
  7819. }
  7820. break;
  7821. }
  7822. /* Move the real (op0) and imaginary (op1) parts to their location. */
  7823. write_complex_part (target, op0, false);
  7824. write_complex_part (target, op1, true);
  7825. return target;
  7826. case WIDEN_SUM_EXPR:
  7827. {
  7828. tree oprnd0 = treeop0;
  7829. tree oprnd1 = treeop1;
  7830. expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  7831. target = expand_widen_pattern_expr (ops, op0, NULL_RTX, op1,
  7832. target, unsignedp);
  7833. return target;
  7834. }
  7835. case REDUC_MAX_EXPR:
  7836. case REDUC_MIN_EXPR:
  7837. case REDUC_PLUS_EXPR:
  7838. {
  7839. op0 = expand_normal (treeop0);
  7840. this_optab = optab_for_tree_code (code, type, optab_default);
  7841. machine_mode vec_mode = TYPE_MODE (TREE_TYPE (treeop0));
  7842. if (optab_handler (this_optab, vec_mode) != CODE_FOR_nothing)
  7843. {
  7844. struct expand_operand ops[2];
  7845. enum insn_code icode = optab_handler (this_optab, vec_mode);
  7846. create_output_operand (&ops[0], target, mode);
  7847. create_input_operand (&ops[1], op0, vec_mode);
  7848. if (maybe_expand_insn (icode, 2, ops))
  7849. {
  7850. target = ops[0].value;
  7851. if (GET_MODE (target) != mode)
  7852. return gen_lowpart (tmode, target);
  7853. return target;
  7854. }
  7855. }
  7856. /* Fall back to optab with vector result, and then extract scalar. */
  7857. this_optab = scalar_reduc_to_vector (this_optab, type);
  7858. temp = expand_unop (vec_mode, this_optab, op0, NULL_RTX, unsignedp);
  7859. gcc_assert (temp);
  7860. /* The tree code produces a scalar result, but (somewhat by convention)
  7861. the optab produces a vector with the result in element 0 if
  7862. little-endian, or element N-1 if big-endian. So pull the scalar
  7863. result out of that element. */
  7864. int index = BYTES_BIG_ENDIAN ? GET_MODE_NUNITS (vec_mode) - 1 : 0;
  7865. int bitsize = GET_MODE_BITSIZE (GET_MODE_INNER (vec_mode));
  7866. temp = extract_bit_field (temp, bitsize, bitsize * index, unsignedp,
  7867. target, mode, mode);
  7868. gcc_assert (temp);
  7869. return temp;
  7870. }
  7871. case VEC_UNPACK_HI_EXPR:
  7872. case VEC_UNPACK_LO_EXPR:
  7873. {
  7874. op0 = expand_normal (treeop0);
  7875. temp = expand_widen_pattern_expr (ops, op0, NULL_RTX, NULL_RTX,
  7876. target, unsignedp);
  7877. gcc_assert (temp);
  7878. return temp;
  7879. }
  7880. case VEC_UNPACK_FLOAT_HI_EXPR:
  7881. case VEC_UNPACK_FLOAT_LO_EXPR:
  7882. {
  7883. op0 = expand_normal (treeop0);
  7884. /* The signedness is determined from input operand. */
  7885. temp = expand_widen_pattern_expr
  7886. (ops, op0, NULL_RTX, NULL_RTX,
  7887. target, TYPE_UNSIGNED (TREE_TYPE (treeop0)));
  7888. gcc_assert (temp);
  7889. return temp;
  7890. }
  7891. case VEC_WIDEN_MULT_HI_EXPR:
  7892. case VEC_WIDEN_MULT_LO_EXPR:
  7893. case VEC_WIDEN_MULT_EVEN_EXPR:
  7894. case VEC_WIDEN_MULT_ODD_EXPR:
  7895. case VEC_WIDEN_LSHIFT_HI_EXPR:
  7896. case VEC_WIDEN_LSHIFT_LO_EXPR:
  7897. expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  7898. target = expand_widen_pattern_expr (ops, op0, op1, NULL_RTX,
  7899. target, unsignedp);
  7900. gcc_assert (target);
  7901. return target;
  7902. case VEC_PACK_TRUNC_EXPR:
  7903. case VEC_PACK_SAT_EXPR:
  7904. case VEC_PACK_FIX_TRUNC_EXPR:
  7905. mode = TYPE_MODE (TREE_TYPE (treeop0));
  7906. goto binop;
  7907. case VEC_PERM_EXPR:
  7908. expand_operands (treeop0, treeop1, target, &op0, &op1, EXPAND_NORMAL);
  7909. op2 = expand_normal (treeop2);
  7910. /* Careful here: if the target doesn't support integral vector modes,
  7911. a constant selection vector could wind up smooshed into a normal
  7912. integral constant. */
  7913. if (CONSTANT_P (op2) && GET_CODE (op2) != CONST_VECTOR)
  7914. {
  7915. tree sel_type = TREE_TYPE (treeop2);
  7916. machine_mode vmode
  7917. = mode_for_vector (TYPE_MODE (TREE_TYPE (sel_type)),
  7918. TYPE_VECTOR_SUBPARTS (sel_type));
  7919. gcc_assert (GET_MODE_CLASS (vmode) == MODE_VECTOR_INT);
  7920. op2 = simplify_subreg (vmode, op2, TYPE_MODE (sel_type), 0);
  7921. gcc_assert (op2 && GET_CODE (op2) == CONST_VECTOR);
  7922. }
  7923. else
  7924. gcc_assert (GET_MODE_CLASS (GET_MODE (op2)) == MODE_VECTOR_INT);
  7925. temp = expand_vec_perm (mode, op0, op1, op2, target);
  7926. gcc_assert (temp);
  7927. return temp;
  7928. case DOT_PROD_EXPR:
  7929. {
  7930. tree oprnd0 = treeop0;
  7931. tree oprnd1 = treeop1;
  7932. tree oprnd2 = treeop2;
  7933. rtx op2;
  7934. expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  7935. op2 = expand_normal (oprnd2);
  7936. target = expand_widen_pattern_expr (ops, op0, op1, op2,
  7937. target, unsignedp);
  7938. return target;
  7939. }
  7940. case SAD_EXPR:
  7941. {
  7942. tree oprnd0 = treeop0;
  7943. tree oprnd1 = treeop1;
  7944. tree oprnd2 = treeop2;
  7945. rtx op2;
  7946. expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  7947. op2 = expand_normal (oprnd2);
  7948. target = expand_widen_pattern_expr (ops, op0, op1, op2,
  7949. target, unsignedp);
  7950. return target;
  7951. }
  7952. case REALIGN_LOAD_EXPR:
  7953. {
  7954. tree oprnd0 = treeop0;
  7955. tree oprnd1 = treeop1;
  7956. tree oprnd2 = treeop2;
  7957. rtx op2;
  7958. this_optab = optab_for_tree_code (code, type, optab_default);
  7959. expand_operands (oprnd0, oprnd1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  7960. op2 = expand_normal (oprnd2);
  7961. temp = expand_ternary_op (mode, this_optab, op0, op1, op2,
  7962. target, unsignedp);
  7963. gcc_assert (temp);
  7964. return temp;
  7965. }
  7966. case COND_EXPR:
  7967. /* A COND_EXPR with its type being VOID_TYPE represents a
  7968. conditional jump and is handled in
  7969. expand_gimple_cond_expr. */
  7970. gcc_assert (!VOID_TYPE_P (type));
  7971. /* Note that COND_EXPRs whose type is a structure or union
  7972. are required to be constructed to contain assignments of
  7973. a temporary variable, so that we can evaluate them here
  7974. for side effect only. If type is void, we must do likewise. */
  7975. gcc_assert (!TREE_ADDRESSABLE (type)
  7976. && !ignore
  7977. && TREE_TYPE (treeop1) != void_type_node
  7978. && TREE_TYPE (treeop2) != void_type_node);
  7979. temp = expand_cond_expr_using_cmove (treeop0, treeop1, treeop2);
  7980. if (temp)
  7981. return temp;
  7982. /* If we are not to produce a result, we have no target. Otherwise,
  7983. if a target was specified use it; it will not be used as an
  7984. intermediate target unless it is safe. If no target, use a
  7985. temporary. */
  7986. if (modifier != EXPAND_STACK_PARM
  7987. && original_target
  7988. && safe_from_p (original_target, treeop0, 1)
  7989. && GET_MODE (original_target) == mode
  7990. && !MEM_P (original_target))
  7991. temp = original_target;
  7992. else
  7993. temp = assign_temp (type, 0, 1);
  7994. do_pending_stack_adjust ();
  7995. NO_DEFER_POP;
  7996. op0 = gen_label_rtx ();
  7997. op1 = gen_label_rtx ();
  7998. jumpifnot (treeop0, op0, -1);
  7999. store_expr (treeop1, temp,
  8000. modifier == EXPAND_STACK_PARM,
  8001. false);
  8002. emit_jump_insn (gen_jump (op1));
  8003. emit_barrier ();
  8004. emit_label (op0);
  8005. store_expr (treeop2, temp,
  8006. modifier == EXPAND_STACK_PARM,
  8007. false);
  8008. emit_label (op1);
  8009. OK_DEFER_POP;
  8010. return temp;
  8011. case VEC_COND_EXPR:
  8012. target = expand_vec_cond_expr (type, treeop0, treeop1, treeop2, target);
  8013. return target;
  8014. default:
  8015. gcc_unreachable ();
  8016. }
  8017. /* Here to do an ordinary binary operator. */
  8018. binop:
  8019. expand_operands (treeop0, treeop1,
  8020. subtarget, &op0, &op1, EXPAND_NORMAL);
  8021. binop2:
  8022. this_optab = optab_for_tree_code (code, type, optab_default);
  8023. binop3:
  8024. if (modifier == EXPAND_STACK_PARM)
  8025. target = 0;
  8026. temp = expand_binop (mode, this_optab, op0, op1, target,
  8027. unsignedp, OPTAB_LIB_WIDEN);
  8028. gcc_assert (temp);
  8029. /* Bitwise operations do not need bitfield reduction as we expect their
  8030. operands being properly truncated. */
  8031. if (code == BIT_XOR_EXPR
  8032. || code == BIT_AND_EXPR
  8033. || code == BIT_IOR_EXPR)
  8034. return temp;
  8035. return REDUCE_BIT_FIELD (temp);
  8036. }
  8037. #undef REDUCE_BIT_FIELD
  8038. /* Return TRUE if expression STMT is suitable for replacement.
  8039. Never consider memory loads as replaceable, because those don't ever lead
  8040. into constant expressions. */
  8041. static bool
  8042. stmt_is_replaceable_p (gimple stmt)
  8043. {
  8044. if (ssa_is_replaceable_p (stmt))
  8045. {
  8046. /* Don't move around loads. */
  8047. if (!gimple_assign_single_p (stmt)
  8048. || is_gimple_val (gimple_assign_rhs1 (stmt)))
  8049. return true;
  8050. }
  8051. return false;
  8052. }
  8053. rtx
  8054. expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
  8055. enum expand_modifier modifier, rtx *alt_rtl,
  8056. bool inner_reference_p)
  8057. {
  8058. rtx op0, op1, temp, decl_rtl;
  8059. tree type;
  8060. int unsignedp;
  8061. machine_mode mode;
  8062. enum tree_code code = TREE_CODE (exp);
  8063. rtx subtarget, original_target;
  8064. int ignore;
  8065. tree context;
  8066. bool reduce_bit_field;
  8067. location_t loc = EXPR_LOCATION (exp);
  8068. struct separate_ops ops;
  8069. tree treeop0, treeop1, treeop2;
  8070. tree ssa_name = NULL_TREE;
  8071. gimple g;
  8072. type = TREE_TYPE (exp);
  8073. mode = TYPE_MODE (type);
  8074. unsignedp = TYPE_UNSIGNED (type);
  8075. treeop0 = treeop1 = treeop2 = NULL_TREE;
  8076. if (!VL_EXP_CLASS_P (exp))
  8077. switch (TREE_CODE_LENGTH (code))
  8078. {
  8079. default:
  8080. case 3: treeop2 = TREE_OPERAND (exp, 2);
  8081. case 2: treeop1 = TREE_OPERAND (exp, 1);
  8082. case 1: treeop0 = TREE_OPERAND (exp, 0);
  8083. case 0: break;
  8084. }
  8085. ops.code = code;
  8086. ops.type = type;
  8087. ops.op0 = treeop0;
  8088. ops.op1 = treeop1;
  8089. ops.op2 = treeop2;
  8090. ops.location = loc;
  8091. ignore = (target == const0_rtx
  8092. || ((CONVERT_EXPR_CODE_P (code)
  8093. || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
  8094. && TREE_CODE (type) == VOID_TYPE));
  8095. /* An operation in what may be a bit-field type needs the
  8096. result to be reduced to the precision of the bit-field type,
  8097. which is narrower than that of the type's mode. */
  8098. reduce_bit_field = (!ignore
  8099. && INTEGRAL_TYPE_P (type)
  8100. && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
  8101. /* If we are going to ignore this result, we need only do something
  8102. if there is a side-effect somewhere in the expression. If there
  8103. is, short-circuit the most common cases here. Note that we must
  8104. not call expand_expr with anything but const0_rtx in case this
  8105. is an initial expansion of a size that contains a PLACEHOLDER_EXPR. */
  8106. if (ignore)
  8107. {
  8108. if (! TREE_SIDE_EFFECTS (exp))
  8109. return const0_rtx;
  8110. /* Ensure we reference a volatile object even if value is ignored, but
  8111. don't do this if all we are doing is taking its address. */
  8112. if (TREE_THIS_VOLATILE (exp)
  8113. && TREE_CODE (exp) != FUNCTION_DECL
  8114. && mode != VOIDmode && mode != BLKmode
  8115. && modifier != EXPAND_CONST_ADDRESS)
  8116. {
  8117. temp = expand_expr (exp, NULL_RTX, VOIDmode, modifier);
  8118. if (MEM_P (temp))
  8119. copy_to_reg (temp);
  8120. return const0_rtx;
  8121. }
  8122. if (TREE_CODE_CLASS (code) == tcc_unary
  8123. || code == BIT_FIELD_REF
  8124. || code == COMPONENT_REF
  8125. || code == INDIRECT_REF)
  8126. return expand_expr (treeop0, const0_rtx, VOIDmode,
  8127. modifier);
  8128. else if (TREE_CODE_CLASS (code) == tcc_binary
  8129. || TREE_CODE_CLASS (code) == tcc_comparison
  8130. || code == ARRAY_REF || code == ARRAY_RANGE_REF)
  8131. {
  8132. expand_expr (treeop0, const0_rtx, VOIDmode, modifier);
  8133. expand_expr (treeop1, const0_rtx, VOIDmode, modifier);
  8134. return const0_rtx;
  8135. }
  8136. target = 0;
  8137. }
  8138. if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
  8139. target = 0;
  8140. /* Use subtarget as the target for operand 0 of a binary operation. */
  8141. subtarget = get_subtarget (target);
  8142. original_target = target;
  8143. switch (code)
  8144. {
  8145. case LABEL_DECL:
  8146. {
  8147. tree function = decl_function_context (exp);
  8148. temp = label_rtx (exp);
  8149. temp = gen_rtx_LABEL_REF (Pmode, temp);
  8150. if (function != current_function_decl
  8151. && function != 0)
  8152. LABEL_REF_NONLOCAL_P (temp) = 1;
  8153. temp = gen_rtx_MEM (FUNCTION_MODE, temp);
  8154. return temp;
  8155. }
  8156. case SSA_NAME:
  8157. /* ??? ivopts calls expander, without any preparation from
  8158. out-of-ssa. So fake instructions as if this was an access to the
  8159. base variable. This unnecessarily allocates a pseudo, see how we can
  8160. reuse it, if partition base vars have it set already. */
  8161. if (!currently_expanding_to_rtl)
  8162. {
  8163. tree var = SSA_NAME_VAR (exp);
  8164. if (var && DECL_RTL_SET_P (var))
  8165. return DECL_RTL (var);
  8166. return gen_raw_REG (TYPE_MODE (TREE_TYPE (exp)),
  8167. LAST_VIRTUAL_REGISTER + 1);
  8168. }
  8169. g = get_gimple_for_ssa_name (exp);
  8170. /* For EXPAND_INITIALIZER try harder to get something simpler. */
  8171. if (g == NULL
  8172. && modifier == EXPAND_INITIALIZER
  8173. && !SSA_NAME_IS_DEFAULT_DEF (exp)
  8174. && (optimize || DECL_IGNORED_P (SSA_NAME_VAR (exp)))
  8175. && stmt_is_replaceable_p (SSA_NAME_DEF_STMT (exp)))
  8176. g = SSA_NAME_DEF_STMT (exp);
  8177. if (g)
  8178. {
  8179. rtx r;
  8180. ops.code = gimple_assign_rhs_code (g);
  8181. switch (get_gimple_rhs_class (ops.code))
  8182. {
  8183. case GIMPLE_TERNARY_RHS:
  8184. ops.op2 = gimple_assign_rhs3 (g);
  8185. /* Fallthru */
  8186. case GIMPLE_BINARY_RHS:
  8187. ops.op1 = gimple_assign_rhs2 (g);
  8188. /* Try to expand conditonal compare. */
  8189. if (targetm.gen_ccmp_first)
  8190. {
  8191. gcc_checking_assert (targetm.gen_ccmp_next != NULL);
  8192. r = expand_ccmp_expr (g);
  8193. if (r)
  8194. break;
  8195. }
  8196. /* Fallthru */
  8197. case GIMPLE_UNARY_RHS:
  8198. ops.op0 = gimple_assign_rhs1 (g);
  8199. ops.type = TREE_TYPE (gimple_assign_lhs (g));
  8200. ops.location = gimple_location (g);
  8201. r = expand_expr_real_2 (&ops, target, tmode, modifier);
  8202. break;
  8203. case GIMPLE_SINGLE_RHS:
  8204. {
  8205. location_t saved_loc = curr_insn_location ();
  8206. set_curr_insn_location (gimple_location (g));
  8207. r = expand_expr_real (gimple_assign_rhs1 (g), target,
  8208. tmode, modifier, NULL, inner_reference_p);
  8209. set_curr_insn_location (saved_loc);
  8210. break;
  8211. }
  8212. default:
  8213. gcc_unreachable ();
  8214. }
  8215. if (REG_P (r) && !REG_EXPR (r))
  8216. set_reg_attrs_for_decl_rtl (SSA_NAME_VAR (exp), r);
  8217. return r;
  8218. }
  8219. ssa_name = exp;
  8220. decl_rtl = get_rtx_for_ssa_name (ssa_name);
  8221. exp = SSA_NAME_VAR (ssa_name);
  8222. goto expand_decl_rtl;
  8223. case PARM_DECL:
  8224. case VAR_DECL:
  8225. /* If a static var's type was incomplete when the decl was written,
  8226. but the type is complete now, lay out the decl now. */
  8227. if (DECL_SIZE (exp) == 0
  8228. && COMPLETE_OR_UNBOUND_ARRAY_TYPE_P (TREE_TYPE (exp))
  8229. && (TREE_STATIC (exp) || DECL_EXTERNAL (exp)))
  8230. layout_decl (exp, 0);
  8231. /* ... fall through ... */
  8232. case FUNCTION_DECL:
  8233. case RESULT_DECL:
  8234. decl_rtl = DECL_RTL (exp);
  8235. expand_decl_rtl:
  8236. gcc_assert (decl_rtl);
  8237. decl_rtl = copy_rtx (decl_rtl);
  8238. /* Record writes to register variables. */
  8239. if (modifier == EXPAND_WRITE
  8240. && REG_P (decl_rtl)
  8241. && HARD_REGISTER_P (decl_rtl))
  8242. add_to_hard_reg_set (&crtl->asm_clobbers,
  8243. GET_MODE (decl_rtl), REGNO (decl_rtl));
  8244. /* Ensure variable marked as used even if it doesn't go through
  8245. a parser. If it hasn't be used yet, write out an external
  8246. definition. */
  8247. TREE_USED (exp) = 1;
  8248. /* Show we haven't gotten RTL for this yet. */
  8249. temp = 0;
  8250. /* Variables inherited from containing functions should have
  8251. been lowered by this point. */
  8252. context = decl_function_context (exp);
  8253. gcc_assert (SCOPE_FILE_SCOPE_P (context)
  8254. || context == current_function_decl
  8255. || TREE_STATIC (exp)
  8256. || DECL_EXTERNAL (exp)
  8257. /* ??? C++ creates functions that are not TREE_STATIC. */
  8258. || TREE_CODE (exp) == FUNCTION_DECL);
  8259. /* This is the case of an array whose size is to be determined
  8260. from its initializer, while the initializer is still being parsed.
  8261. ??? We aren't parsing while expanding anymore. */
  8262. if (MEM_P (decl_rtl) && REG_P (XEXP (decl_rtl, 0)))
  8263. temp = validize_mem (decl_rtl);
  8264. /* If DECL_RTL is memory, we are in the normal case and the
  8265. address is not valid, get the address into a register. */
  8266. else if (MEM_P (decl_rtl) && modifier != EXPAND_INITIALIZER)
  8267. {
  8268. if (alt_rtl)
  8269. *alt_rtl = decl_rtl;
  8270. decl_rtl = use_anchored_address (decl_rtl);
  8271. if (modifier != EXPAND_CONST_ADDRESS
  8272. && modifier != EXPAND_SUM
  8273. && !memory_address_addr_space_p (DECL_MODE (exp),
  8274. XEXP (decl_rtl, 0),
  8275. MEM_ADDR_SPACE (decl_rtl)))
  8276. temp = replace_equiv_address (decl_rtl,
  8277. copy_rtx (XEXP (decl_rtl, 0)));
  8278. }
  8279. /* If we got something, return it. But first, set the alignment
  8280. if the address is a register. */
  8281. if (temp != 0)
  8282. {
  8283. if (MEM_P (temp) && REG_P (XEXP (temp, 0)))
  8284. mark_reg_pointer (XEXP (temp, 0), DECL_ALIGN (exp));
  8285. return temp;
  8286. }
  8287. /* If the mode of DECL_RTL does not match that of the decl,
  8288. there are two cases: we are dealing with a BLKmode value
  8289. that is returned in a register, or we are dealing with
  8290. a promoted value. In the latter case, return a SUBREG
  8291. of the wanted mode, but mark it so that we know that it
  8292. was already extended. */
  8293. if (REG_P (decl_rtl)
  8294. && DECL_MODE (exp) != BLKmode
  8295. && GET_MODE (decl_rtl) != DECL_MODE (exp))
  8296. {
  8297. machine_mode pmode;
  8298. /* Get the signedness to be used for this variable. Ensure we get
  8299. the same mode we got when the variable was declared. */
  8300. if (code == SSA_NAME
  8301. && (g = SSA_NAME_DEF_STMT (ssa_name))
  8302. && gimple_code (g) == GIMPLE_CALL
  8303. && !gimple_call_internal_p (g))
  8304. pmode = promote_function_mode (type, mode, &unsignedp,
  8305. gimple_call_fntype (g),
  8306. 2);
  8307. else
  8308. pmode = promote_decl_mode (exp, &unsignedp);
  8309. gcc_assert (GET_MODE (decl_rtl) == pmode);
  8310. temp = gen_lowpart_SUBREG (mode, decl_rtl);
  8311. SUBREG_PROMOTED_VAR_P (temp) = 1;
  8312. SUBREG_PROMOTED_SET (temp, unsignedp);
  8313. return temp;
  8314. }
  8315. return decl_rtl;
  8316. case INTEGER_CST:
  8317. /* Given that TYPE_PRECISION (type) is not always equal to
  8318. GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
  8319. the former to the latter according to the signedness of the
  8320. type. */
  8321. temp = immed_wide_int_const (wide_int::from
  8322. (exp,
  8323. GET_MODE_PRECISION (TYPE_MODE (type)),
  8324. TYPE_SIGN (type)),
  8325. TYPE_MODE (type));
  8326. return temp;
  8327. case VECTOR_CST:
  8328. {
  8329. tree tmp = NULL_TREE;
  8330. if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
  8331. || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT
  8332. || GET_MODE_CLASS (mode) == MODE_VECTOR_FRACT
  8333. || GET_MODE_CLASS (mode) == MODE_VECTOR_UFRACT
  8334. || GET_MODE_CLASS (mode) == MODE_VECTOR_ACCUM
  8335. || GET_MODE_CLASS (mode) == MODE_VECTOR_UACCUM)
  8336. return const_vector_from_tree (exp);
  8337. if (GET_MODE_CLASS (mode) == MODE_INT)
  8338. {
  8339. tree type_for_mode = lang_hooks.types.type_for_mode (mode, 1);
  8340. if (type_for_mode)
  8341. tmp = fold_unary_loc (loc, VIEW_CONVERT_EXPR, type_for_mode, exp);
  8342. }
  8343. if (!tmp)
  8344. {
  8345. vec<constructor_elt, va_gc> *v;
  8346. unsigned i;
  8347. vec_alloc (v, VECTOR_CST_NELTS (exp));
  8348. for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
  8349. CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, VECTOR_CST_ELT (exp, i));
  8350. tmp = build_constructor (type, v);
  8351. }
  8352. return expand_expr (tmp, ignore ? const0_rtx : target,
  8353. tmode, modifier);
  8354. }
  8355. case CONST_DECL:
  8356. return expand_expr (DECL_INITIAL (exp), target, VOIDmode, modifier);
  8357. case REAL_CST:
  8358. /* If optimized, generate immediate CONST_DOUBLE
  8359. which will be turned into memory by reload if necessary.
  8360. We used to force a register so that loop.c could see it. But
  8361. this does not allow gen_* patterns to perform optimizations with
  8362. the constants. It also produces two insns in cases like "x = 1.0;".
  8363. On most machines, floating-point constants are not permitted in
  8364. many insns, so we'd end up copying it to a register in any case.
  8365. Now, we do the copying in expand_binop, if appropriate. */
  8366. return CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (exp),
  8367. TYPE_MODE (TREE_TYPE (exp)));
  8368. case FIXED_CST:
  8369. return CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (exp),
  8370. TYPE_MODE (TREE_TYPE (exp)));
  8371. case COMPLEX_CST:
  8372. /* Handle evaluating a complex constant in a CONCAT target. */
  8373. if (original_target && GET_CODE (original_target) == CONCAT)
  8374. {
  8375. machine_mode mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
  8376. rtx rtarg, itarg;
  8377. rtarg = XEXP (original_target, 0);
  8378. itarg = XEXP (original_target, 1);
  8379. /* Move the real and imaginary parts separately. */
  8380. op0 = expand_expr (TREE_REALPART (exp), rtarg, mode, EXPAND_NORMAL);
  8381. op1 = expand_expr (TREE_IMAGPART (exp), itarg, mode, EXPAND_NORMAL);
  8382. if (op0 != rtarg)
  8383. emit_move_insn (rtarg, op0);
  8384. if (op1 != itarg)
  8385. emit_move_insn (itarg, op1);
  8386. return original_target;
  8387. }
  8388. /* ... fall through ... */
  8389. case STRING_CST:
  8390. temp = expand_expr_constant (exp, 1, modifier);
  8391. /* temp contains a constant address.
  8392. On RISC machines where a constant address isn't valid,
  8393. make some insns to get that address into a register. */
  8394. if (modifier != EXPAND_CONST_ADDRESS
  8395. && modifier != EXPAND_INITIALIZER
  8396. && modifier != EXPAND_SUM
  8397. && ! memory_address_addr_space_p (mode, XEXP (temp, 0),
  8398. MEM_ADDR_SPACE (temp)))
  8399. return replace_equiv_address (temp,
  8400. copy_rtx (XEXP (temp, 0)));
  8401. return temp;
  8402. case SAVE_EXPR:
  8403. {
  8404. tree val = treeop0;
  8405. rtx ret = expand_expr_real_1 (val, target, tmode, modifier, alt_rtl,
  8406. inner_reference_p);
  8407. if (!SAVE_EXPR_RESOLVED_P (exp))
  8408. {
  8409. /* We can indeed still hit this case, typically via builtin
  8410. expanders calling save_expr immediately before expanding
  8411. something. Assume this means that we only have to deal
  8412. with non-BLKmode values. */
  8413. gcc_assert (GET_MODE (ret) != BLKmode);
  8414. val = build_decl (curr_insn_location (),
  8415. VAR_DECL, NULL, TREE_TYPE (exp));
  8416. DECL_ARTIFICIAL (val) = 1;
  8417. DECL_IGNORED_P (val) = 1;
  8418. treeop0 = val;
  8419. TREE_OPERAND (exp, 0) = treeop0;
  8420. SAVE_EXPR_RESOLVED_P (exp) = 1;
  8421. if (!CONSTANT_P (ret))
  8422. ret = copy_to_reg (ret);
  8423. SET_DECL_RTL (val, ret);
  8424. }
  8425. return ret;
  8426. }
  8427. case CONSTRUCTOR:
  8428. /* If we don't need the result, just ensure we evaluate any
  8429. subexpressions. */
  8430. if (ignore)
  8431. {
  8432. unsigned HOST_WIDE_INT idx;
  8433. tree value;
  8434. FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
  8435. expand_expr (value, const0_rtx, VOIDmode, EXPAND_NORMAL);
  8436. return const0_rtx;
  8437. }
  8438. return expand_constructor (exp, target, modifier, false);
  8439. case TARGET_MEM_REF:
  8440. {
  8441. addr_space_t as
  8442. = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
  8443. enum insn_code icode;
  8444. unsigned int align;
  8445. op0 = addr_for_mem_ref (exp, as, true);
  8446. op0 = memory_address_addr_space (mode, op0, as);
  8447. temp = gen_rtx_MEM (mode, op0);
  8448. set_mem_attributes (temp, exp, 0);
  8449. set_mem_addr_space (temp, as);
  8450. align = get_object_alignment (exp);
  8451. if (modifier != EXPAND_WRITE
  8452. && modifier != EXPAND_MEMORY
  8453. && mode != BLKmode
  8454. && align < GET_MODE_ALIGNMENT (mode)
  8455. /* If the target does not have special handling for unaligned
  8456. loads of mode then it can use regular moves for them. */
  8457. && ((icode = optab_handler (movmisalign_optab, mode))
  8458. != CODE_FOR_nothing))
  8459. {
  8460. struct expand_operand ops[2];
  8461. /* We've already validated the memory, and we're creating a
  8462. new pseudo destination. The predicates really can't fail,
  8463. nor can the generator. */
  8464. create_output_operand (&ops[0], NULL_RTX, mode);
  8465. create_fixed_operand (&ops[1], temp);
  8466. expand_insn (icode, 2, ops);
  8467. temp = ops[0].value;
  8468. }
  8469. return temp;
  8470. }
  8471. case MEM_REF:
  8472. {
  8473. addr_space_t as
  8474. = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (exp, 0))));
  8475. machine_mode address_mode;
  8476. tree base = TREE_OPERAND (exp, 0);
  8477. gimple def_stmt;
  8478. enum insn_code icode;
  8479. unsigned align;
  8480. /* Handle expansion of non-aliased memory with non-BLKmode. That
  8481. might end up in a register. */
  8482. if (mem_ref_refers_to_non_mem_p (exp))
  8483. {
  8484. HOST_WIDE_INT offset = mem_ref_offset (exp).to_short_addr ();
  8485. base = TREE_OPERAND (base, 0);
  8486. if (offset == 0
  8487. && tree_fits_uhwi_p (TYPE_SIZE (type))
  8488. && (GET_MODE_BITSIZE (DECL_MODE (base))
  8489. == tree_to_uhwi (TYPE_SIZE (type))))
  8490. return expand_expr (build1 (VIEW_CONVERT_EXPR, type, base),
  8491. target, tmode, modifier);
  8492. if (TYPE_MODE (type) == BLKmode)
  8493. {
  8494. temp = assign_stack_temp (DECL_MODE (base),
  8495. GET_MODE_SIZE (DECL_MODE (base)));
  8496. store_expr (base, temp, 0, false);
  8497. temp = adjust_address (temp, BLKmode, offset);
  8498. set_mem_size (temp, int_size_in_bytes (type));
  8499. return temp;
  8500. }
  8501. exp = build3 (BIT_FIELD_REF, type, base, TYPE_SIZE (type),
  8502. bitsize_int (offset * BITS_PER_UNIT));
  8503. return expand_expr (exp, target, tmode, modifier);
  8504. }
  8505. address_mode = targetm.addr_space.address_mode (as);
  8506. base = TREE_OPERAND (exp, 0);
  8507. if ((def_stmt = get_def_for_expr (base, BIT_AND_EXPR)))
  8508. {
  8509. tree mask = gimple_assign_rhs2 (def_stmt);
  8510. base = build2 (BIT_AND_EXPR, TREE_TYPE (base),
  8511. gimple_assign_rhs1 (def_stmt), mask);
  8512. TREE_OPERAND (exp, 0) = base;
  8513. }
  8514. align = get_object_alignment (exp);
  8515. op0 = expand_expr (base, NULL_RTX, VOIDmode, EXPAND_SUM);
  8516. op0 = memory_address_addr_space (mode, op0, as);
  8517. if (!integer_zerop (TREE_OPERAND (exp, 1)))
  8518. {
  8519. rtx off = immed_wide_int_const (mem_ref_offset (exp), address_mode);
  8520. op0 = simplify_gen_binary (PLUS, address_mode, op0, off);
  8521. op0 = memory_address_addr_space (mode, op0, as);
  8522. }
  8523. temp = gen_rtx_MEM (mode, op0);
  8524. set_mem_attributes (temp, exp, 0);
  8525. set_mem_addr_space (temp, as);
  8526. if (TREE_THIS_VOLATILE (exp))
  8527. MEM_VOLATILE_P (temp) = 1;
  8528. if (modifier != EXPAND_WRITE
  8529. && modifier != EXPAND_MEMORY
  8530. && !inner_reference_p
  8531. && mode != BLKmode
  8532. && align < GET_MODE_ALIGNMENT (mode))
  8533. {
  8534. if ((icode = optab_handler (movmisalign_optab, mode))
  8535. != CODE_FOR_nothing)
  8536. {
  8537. struct expand_operand ops[2];
  8538. /* We've already validated the memory, and we're creating a
  8539. new pseudo destination. The predicates really can't fail,
  8540. nor can the generator. */
  8541. create_output_operand (&ops[0], NULL_RTX, mode);
  8542. create_fixed_operand (&ops[1], temp);
  8543. expand_insn (icode, 2, ops);
  8544. temp = ops[0].value;
  8545. }
  8546. else if (SLOW_UNALIGNED_ACCESS (mode, align))
  8547. temp = extract_bit_field (temp, GET_MODE_BITSIZE (mode),
  8548. 0, TYPE_UNSIGNED (TREE_TYPE (exp)),
  8549. (modifier == EXPAND_STACK_PARM
  8550. ? NULL_RTX : target),
  8551. mode, mode);
  8552. }
  8553. return temp;
  8554. }
  8555. case ARRAY_REF:
  8556. {
  8557. tree array = treeop0;
  8558. tree index = treeop1;
  8559. tree init;
  8560. /* Fold an expression like: "foo"[2].
  8561. This is not done in fold so it won't happen inside &.
  8562. Don't fold if this is for wide characters since it's too
  8563. difficult to do correctly and this is a very rare case. */
  8564. if (modifier != EXPAND_CONST_ADDRESS
  8565. && modifier != EXPAND_INITIALIZER
  8566. && modifier != EXPAND_MEMORY)
  8567. {
  8568. tree t = fold_read_from_constant_string (exp);
  8569. if (t)
  8570. return expand_expr (t, target, tmode, modifier);
  8571. }
  8572. /* If this is a constant index into a constant array,
  8573. just get the value from the array. Handle both the cases when
  8574. we have an explicit constructor and when our operand is a variable
  8575. that was declared const. */
  8576. if (modifier != EXPAND_CONST_ADDRESS
  8577. && modifier != EXPAND_INITIALIZER
  8578. && modifier != EXPAND_MEMORY
  8579. && TREE_CODE (array) == CONSTRUCTOR
  8580. && ! TREE_SIDE_EFFECTS (array)
  8581. && TREE_CODE (index) == INTEGER_CST)
  8582. {
  8583. unsigned HOST_WIDE_INT ix;
  8584. tree field, value;
  8585. FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
  8586. field, value)
  8587. if (tree_int_cst_equal (field, index))
  8588. {
  8589. if (!TREE_SIDE_EFFECTS (value))
  8590. return expand_expr (fold (value), target, tmode, modifier);
  8591. break;
  8592. }
  8593. }
  8594. else if (optimize >= 1
  8595. && modifier != EXPAND_CONST_ADDRESS
  8596. && modifier != EXPAND_INITIALIZER
  8597. && modifier != EXPAND_MEMORY
  8598. && TREE_READONLY (array) && ! TREE_SIDE_EFFECTS (array)
  8599. && TREE_CODE (index) == INTEGER_CST
  8600. && (TREE_CODE (array) == VAR_DECL
  8601. || TREE_CODE (array) == CONST_DECL)
  8602. && (init = ctor_for_folding (array)) != error_mark_node)
  8603. {
  8604. if (init == NULL_TREE)
  8605. {
  8606. tree value = build_zero_cst (type);
  8607. if (TREE_CODE (value) == CONSTRUCTOR)
  8608. {
  8609. /* If VALUE is a CONSTRUCTOR, this optimization is only
  8610. useful if this doesn't store the CONSTRUCTOR into
  8611. memory. If it does, it is more efficient to just
  8612. load the data from the array directly. */
  8613. rtx ret = expand_constructor (value, target,
  8614. modifier, true);
  8615. if (ret == NULL_RTX)
  8616. value = NULL_TREE;
  8617. }
  8618. if (value)
  8619. return expand_expr (value, target, tmode, modifier);
  8620. }
  8621. else if (TREE_CODE (init) == CONSTRUCTOR)
  8622. {
  8623. unsigned HOST_WIDE_INT ix;
  8624. tree field, value;
  8625. FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
  8626. field, value)
  8627. if (tree_int_cst_equal (field, index))
  8628. {
  8629. if (TREE_SIDE_EFFECTS (value))
  8630. break;
  8631. if (TREE_CODE (value) == CONSTRUCTOR)
  8632. {
  8633. /* If VALUE is a CONSTRUCTOR, this
  8634. optimization is only useful if
  8635. this doesn't store the CONSTRUCTOR
  8636. into memory. If it does, it is more
  8637. efficient to just load the data from
  8638. the array directly. */
  8639. rtx ret = expand_constructor (value, target,
  8640. modifier, true);
  8641. if (ret == NULL_RTX)
  8642. break;
  8643. }
  8644. return
  8645. expand_expr (fold (value), target, tmode, modifier);
  8646. }
  8647. }
  8648. else if (TREE_CODE (init) == STRING_CST)
  8649. {
  8650. tree low_bound = array_ref_low_bound (exp);
  8651. tree index1 = fold_convert_loc (loc, sizetype, treeop1);
  8652. /* Optimize the special case of a zero lower bound.
  8653. We convert the lower bound to sizetype to avoid problems
  8654. with constant folding. E.g. suppose the lower bound is
  8655. 1 and its mode is QI. Without the conversion
  8656. (ARRAY + (INDEX - (unsigned char)1))
  8657. becomes
  8658. (ARRAY + (-(unsigned char)1) + INDEX)
  8659. which becomes
  8660. (ARRAY + 255 + INDEX). Oops! */
  8661. if (!integer_zerop (low_bound))
  8662. index1 = size_diffop_loc (loc, index1,
  8663. fold_convert_loc (loc, sizetype,
  8664. low_bound));
  8665. if (compare_tree_int (index1, TREE_STRING_LENGTH (init)) < 0)
  8666. {
  8667. tree type = TREE_TYPE (TREE_TYPE (init));
  8668. machine_mode mode = TYPE_MODE (type);
  8669. if (GET_MODE_CLASS (mode) == MODE_INT
  8670. && GET_MODE_SIZE (mode) == 1)
  8671. return gen_int_mode (TREE_STRING_POINTER (init)
  8672. [TREE_INT_CST_LOW (index1)],
  8673. mode);
  8674. }
  8675. }
  8676. }
  8677. }
  8678. goto normal_inner_ref;
  8679. case COMPONENT_REF:
  8680. /* If the operand is a CONSTRUCTOR, we can just extract the
  8681. appropriate field if it is present. */
  8682. if (TREE_CODE (treeop0) == CONSTRUCTOR)
  8683. {
  8684. unsigned HOST_WIDE_INT idx;
  8685. tree field, value;
  8686. FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (treeop0),
  8687. idx, field, value)
  8688. if (field == treeop1
  8689. /* We can normally use the value of the field in the
  8690. CONSTRUCTOR. However, if this is a bitfield in
  8691. an integral mode that we can fit in a HOST_WIDE_INT,
  8692. we must mask only the number of bits in the bitfield,
  8693. since this is done implicitly by the constructor. If
  8694. the bitfield does not meet either of those conditions,
  8695. we can't do this optimization. */
  8696. && (! DECL_BIT_FIELD (field)
  8697. || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
  8698. && (GET_MODE_PRECISION (DECL_MODE (field))
  8699. <= HOST_BITS_PER_WIDE_INT))))
  8700. {
  8701. if (DECL_BIT_FIELD (field)
  8702. && modifier == EXPAND_STACK_PARM)
  8703. target = 0;
  8704. op0 = expand_expr (value, target, tmode, modifier);
  8705. if (DECL_BIT_FIELD (field))
  8706. {
  8707. HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
  8708. machine_mode imode = TYPE_MODE (TREE_TYPE (field));
  8709. if (TYPE_UNSIGNED (TREE_TYPE (field)))
  8710. {
  8711. op1 = gen_int_mode (((HOST_WIDE_INT) 1 << bitsize) - 1,
  8712. imode);
  8713. op0 = expand_and (imode, op0, op1, target);
  8714. }
  8715. else
  8716. {
  8717. int count = GET_MODE_PRECISION (imode) - bitsize;
  8718. op0 = expand_shift (LSHIFT_EXPR, imode, op0, count,
  8719. target, 0);
  8720. op0 = expand_shift (RSHIFT_EXPR, imode, op0, count,
  8721. target, 0);
  8722. }
  8723. }
  8724. return op0;
  8725. }
  8726. }
  8727. goto normal_inner_ref;
  8728. case BIT_FIELD_REF:
  8729. case ARRAY_RANGE_REF:
  8730. normal_inner_ref:
  8731. {
  8732. machine_mode mode1, mode2;
  8733. HOST_WIDE_INT bitsize, bitpos;
  8734. tree offset;
  8735. int volatilep = 0, must_force_mem;
  8736. tree tem = get_inner_reference (exp, &bitsize, &bitpos, &offset,
  8737. &mode1, &unsignedp, &volatilep, true);
  8738. rtx orig_op0, memloc;
  8739. bool clear_mem_expr = false;
  8740. /* If we got back the original object, something is wrong. Perhaps
  8741. we are evaluating an expression too early. In any event, don't
  8742. infinitely recurse. */
  8743. gcc_assert (tem != exp);
  8744. /* If TEM's type is a union of variable size, pass TARGET to the inner
  8745. computation, since it will need a temporary and TARGET is known
  8746. to have to do. This occurs in unchecked conversion in Ada. */
  8747. orig_op0 = op0
  8748. = expand_expr_real (tem,
  8749. (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
  8750. && COMPLETE_TYPE_P (TREE_TYPE (tem))
  8751. && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
  8752. != INTEGER_CST)
  8753. && modifier != EXPAND_STACK_PARM
  8754. ? target : NULL_RTX),
  8755. VOIDmode,
  8756. modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
  8757. NULL, true);
  8758. /* If the field has a mode, we want to access it in the
  8759. field's mode, not the computed mode.
  8760. If a MEM has VOIDmode (external with incomplete type),
  8761. use BLKmode for it instead. */
  8762. if (MEM_P (op0))
  8763. {
  8764. if (mode1 != VOIDmode)
  8765. op0 = adjust_address (op0, mode1, 0);
  8766. else if (GET_MODE (op0) == VOIDmode)
  8767. op0 = adjust_address (op0, BLKmode, 0);
  8768. }
  8769. mode2
  8770. = CONSTANT_P (op0) ? TYPE_MODE (TREE_TYPE (tem)) : GET_MODE (op0);
  8771. /* If we have either an offset, a BLKmode result, or a reference
  8772. outside the underlying object, we must force it to memory.
  8773. Such a case can occur in Ada if we have unchecked conversion
  8774. of an expression from a scalar type to an aggregate type or
  8775. for an ARRAY_RANGE_REF whose type is BLKmode, or if we were
  8776. passed a partially uninitialized object or a view-conversion
  8777. to a larger size. */
  8778. must_force_mem = (offset
  8779. || mode1 == BLKmode
  8780. || bitpos + bitsize > GET_MODE_BITSIZE (mode2));
  8781. /* Handle CONCAT first. */
  8782. if (GET_CODE (op0) == CONCAT && !must_force_mem)
  8783. {
  8784. if (bitpos == 0
  8785. && bitsize == GET_MODE_BITSIZE (GET_MODE (op0)))
  8786. return op0;
  8787. if (bitpos == 0
  8788. && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
  8789. && bitsize)
  8790. {
  8791. op0 = XEXP (op0, 0);
  8792. mode2 = GET_MODE (op0);
  8793. }
  8794. else if (bitpos == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))
  8795. && bitsize == GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 1)))
  8796. && bitpos
  8797. && bitsize)
  8798. {
  8799. op0 = XEXP (op0, 1);
  8800. bitpos = 0;
  8801. mode2 = GET_MODE (op0);
  8802. }
  8803. else
  8804. /* Otherwise force into memory. */
  8805. must_force_mem = 1;
  8806. }
  8807. /* If this is a constant, put it in a register if it is a legitimate
  8808. constant and we don't need a memory reference. */
  8809. if (CONSTANT_P (op0)
  8810. && mode2 != BLKmode
  8811. && targetm.legitimate_constant_p (mode2, op0)
  8812. && !must_force_mem)
  8813. op0 = force_reg (mode2, op0);
  8814. /* Otherwise, if this is a constant, try to force it to the constant
  8815. pool. Note that back-ends, e.g. MIPS, may refuse to do so if it
  8816. is a legitimate constant. */
  8817. else if (CONSTANT_P (op0) && (memloc = force_const_mem (mode2, op0)))
  8818. op0 = validize_mem (memloc);
  8819. /* Otherwise, if this is a constant or the object is not in memory
  8820. and need be, put it there. */
  8821. else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem))
  8822. {
  8823. memloc = assign_temp (TREE_TYPE (tem), 1, 1);
  8824. emit_move_insn (memloc, op0);
  8825. op0 = memloc;
  8826. clear_mem_expr = true;
  8827. }
  8828. if (offset)
  8829. {
  8830. machine_mode address_mode;
  8831. rtx offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode,
  8832. EXPAND_SUM);
  8833. gcc_assert (MEM_P (op0));
  8834. address_mode = get_address_mode (op0);
  8835. if (GET_MODE (offset_rtx) != address_mode)
  8836. offset_rtx = convert_to_mode (address_mode, offset_rtx, 0);
  8837. /* See the comment in expand_assignment for the rationale. */
  8838. if (mode1 != VOIDmode
  8839. && bitpos != 0
  8840. && bitsize > 0
  8841. && (bitpos % bitsize) == 0
  8842. && (bitsize % GET_MODE_ALIGNMENT (mode1)) == 0
  8843. && MEM_ALIGN (op0) >= GET_MODE_ALIGNMENT (mode1))
  8844. {
  8845. op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
  8846. bitpos = 0;
  8847. }
  8848. op0 = offset_address (op0, offset_rtx,
  8849. highest_pow2_factor (offset));
  8850. }
  8851. /* If OFFSET is making OP0 more aligned than BIGGEST_ALIGNMENT,
  8852. record its alignment as BIGGEST_ALIGNMENT. */
  8853. if (MEM_P (op0) && bitpos == 0 && offset != 0
  8854. && is_aligning_offset (offset, tem))
  8855. set_mem_align (op0, BIGGEST_ALIGNMENT);
  8856. /* Don't forget about volatility even if this is a bitfield. */
  8857. if (MEM_P (op0) && volatilep && ! MEM_VOLATILE_P (op0))
  8858. {
  8859. if (op0 == orig_op0)
  8860. op0 = copy_rtx (op0);
  8861. MEM_VOLATILE_P (op0) = 1;
  8862. }
  8863. /* In cases where an aligned union has an unaligned object
  8864. as a field, we might be extracting a BLKmode value from
  8865. an integer-mode (e.g., SImode) object. Handle this case
  8866. by doing the extract into an object as wide as the field
  8867. (which we know to be the width of a basic mode), then
  8868. storing into memory, and changing the mode to BLKmode. */
  8869. if (mode1 == VOIDmode
  8870. || REG_P (op0) || GET_CODE (op0) == SUBREG
  8871. || (mode1 != BLKmode && ! direct_load[(int) mode1]
  8872. && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
  8873. && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
  8874. && modifier != EXPAND_CONST_ADDRESS
  8875. && modifier != EXPAND_INITIALIZER
  8876. && modifier != EXPAND_MEMORY)
  8877. /* If the bitfield is volatile and the bitsize
  8878. is narrower than the access size of the bitfield,
  8879. we need to extract bitfields from the access. */
  8880. || (volatilep && TREE_CODE (exp) == COMPONENT_REF
  8881. && DECL_BIT_FIELD_TYPE (TREE_OPERAND (exp, 1))
  8882. && mode1 != BLKmode
  8883. && bitsize < GET_MODE_SIZE (mode1) * BITS_PER_UNIT)
  8884. /* If the field isn't aligned enough to fetch as a memref,
  8885. fetch it as a bit field. */
  8886. || (mode1 != BLKmode
  8887. && (((TYPE_ALIGN (TREE_TYPE (tem)) < GET_MODE_ALIGNMENT (mode)
  8888. || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)
  8889. || (MEM_P (op0)
  8890. && (MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode1)
  8891. || (bitpos % GET_MODE_ALIGNMENT (mode1) != 0))))
  8892. && modifier != EXPAND_MEMORY
  8893. && ((modifier == EXPAND_CONST_ADDRESS
  8894. || modifier == EXPAND_INITIALIZER)
  8895. ? STRICT_ALIGNMENT
  8896. : SLOW_UNALIGNED_ACCESS (mode1, MEM_ALIGN (op0))))
  8897. || (bitpos % BITS_PER_UNIT != 0)))
  8898. /* If the type and the field are a constant size and the
  8899. size of the type isn't the same size as the bitfield,
  8900. we must use bitfield operations. */
  8901. || (bitsize >= 0
  8902. && TYPE_SIZE (TREE_TYPE (exp))
  8903. && TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) == INTEGER_CST
  8904. && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
  8905. bitsize)))
  8906. {
  8907. machine_mode ext_mode = mode;
  8908. if (ext_mode == BLKmode
  8909. && ! (target != 0 && MEM_P (op0)
  8910. && MEM_P (target)
  8911. && bitpos % BITS_PER_UNIT == 0))
  8912. ext_mode = mode_for_size (bitsize, MODE_INT, 1);
  8913. if (ext_mode == BLKmode)
  8914. {
  8915. if (target == 0)
  8916. target = assign_temp (type, 1, 1);
  8917. /* ??? Unlike the similar test a few lines below, this one is
  8918. very likely obsolete. */
  8919. if (bitsize == 0)
  8920. return target;
  8921. /* In this case, BITPOS must start at a byte boundary and
  8922. TARGET, if specified, must be a MEM. */
  8923. gcc_assert (MEM_P (op0)
  8924. && (!target || MEM_P (target))
  8925. && !(bitpos % BITS_PER_UNIT));
  8926. emit_block_move (target,
  8927. adjust_address (op0, VOIDmode,
  8928. bitpos / BITS_PER_UNIT),
  8929. GEN_INT ((bitsize + BITS_PER_UNIT - 1)
  8930. / BITS_PER_UNIT),
  8931. (modifier == EXPAND_STACK_PARM
  8932. ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
  8933. return target;
  8934. }
  8935. /* If we have nothing to extract, the result will be 0 for targets
  8936. with SHIFT_COUNT_TRUNCATED == 0 and garbage otherwise. Always
  8937. return 0 for the sake of consistency, as reading a zero-sized
  8938. bitfield is valid in Ada and the value is fully specified. */
  8939. if (bitsize == 0)
  8940. return const0_rtx;
  8941. op0 = validize_mem (op0);
  8942. if (MEM_P (op0) && REG_P (XEXP (op0, 0)))
  8943. mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
  8944. op0 = extract_bit_field (op0, bitsize, bitpos, unsignedp,
  8945. (modifier == EXPAND_STACK_PARM
  8946. ? NULL_RTX : target),
  8947. ext_mode, ext_mode);
  8948. /* If the result is a record type and BITSIZE is narrower than
  8949. the mode of OP0, an integral mode, and this is a big endian
  8950. machine, we must put the field into the high-order bits. */
  8951. if (TREE_CODE (type) == RECORD_TYPE && BYTES_BIG_ENDIAN
  8952. && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
  8953. && bitsize < (HOST_WIDE_INT) GET_MODE_BITSIZE (GET_MODE (op0)))
  8954. op0 = expand_shift (LSHIFT_EXPR, GET_MODE (op0), op0,
  8955. GET_MODE_BITSIZE (GET_MODE (op0))
  8956. - bitsize, op0, 1);
  8957. /* If the result type is BLKmode, store the data into a temporary
  8958. of the appropriate type, but with the mode corresponding to the
  8959. mode for the data we have (op0's mode). */
  8960. if (mode == BLKmode)
  8961. {
  8962. rtx new_rtx
  8963. = assign_stack_temp_for_type (ext_mode,
  8964. GET_MODE_BITSIZE (ext_mode),
  8965. type);
  8966. emit_move_insn (new_rtx, op0);
  8967. op0 = copy_rtx (new_rtx);
  8968. PUT_MODE (op0, BLKmode);
  8969. }
  8970. return op0;
  8971. }
  8972. /* If the result is BLKmode, use that to access the object
  8973. now as well. */
  8974. if (mode == BLKmode)
  8975. mode1 = BLKmode;
  8976. /* Get a reference to just this component. */
  8977. if (modifier == EXPAND_CONST_ADDRESS
  8978. || modifier == EXPAND_SUM || modifier == EXPAND_INITIALIZER)
  8979. op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT);
  8980. else
  8981. op0 = adjust_address (op0, mode1, bitpos / BITS_PER_UNIT);
  8982. if (op0 == orig_op0)
  8983. op0 = copy_rtx (op0);
  8984. set_mem_attributes (op0, exp, 0);
  8985. if (REG_P (XEXP (op0, 0)))
  8986. mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
  8987. /* If op0 is a temporary because the original expressions was forced
  8988. to memory, clear MEM_EXPR so that the original expression cannot
  8989. be marked as addressable through MEM_EXPR of the temporary. */
  8990. if (clear_mem_expr)
  8991. set_mem_expr (op0, NULL_TREE);
  8992. MEM_VOLATILE_P (op0) |= volatilep;
  8993. if (mode == mode1 || mode1 == BLKmode || mode1 == tmode
  8994. || modifier == EXPAND_CONST_ADDRESS
  8995. || modifier == EXPAND_INITIALIZER)
  8996. return op0;
  8997. if (target == 0)
  8998. target = gen_reg_rtx (tmode != VOIDmode ? tmode : mode);
  8999. convert_move (target, op0, unsignedp);
  9000. return target;
  9001. }
  9002. case OBJ_TYPE_REF:
  9003. return expand_expr (OBJ_TYPE_REF_EXPR (exp), target, tmode, modifier);
  9004. case CALL_EXPR:
  9005. /* All valid uses of __builtin_va_arg_pack () are removed during
  9006. inlining. */
  9007. if (CALL_EXPR_VA_ARG_PACK (exp))
  9008. error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
  9009. {
  9010. tree fndecl = get_callee_fndecl (exp), attr;
  9011. if (fndecl
  9012. && (attr = lookup_attribute ("error",
  9013. DECL_ATTRIBUTES (fndecl))) != NULL)
  9014. error ("%Kcall to %qs declared with attribute error: %s",
  9015. exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
  9016. TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
  9017. if (fndecl
  9018. && (attr = lookup_attribute ("warning",
  9019. DECL_ATTRIBUTES (fndecl))) != NULL)
  9020. warning_at (tree_nonartificial_location (exp),
  9021. 0, "%Kcall to %qs declared with attribute warning: %s",
  9022. exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
  9023. TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
  9024. /* Check for a built-in function. */
  9025. if (fndecl && DECL_BUILT_IN (fndecl))
  9026. {
  9027. gcc_assert (DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_FRONTEND);
  9028. if (CALL_WITH_BOUNDS_P (exp))
  9029. return expand_builtin_with_bounds (exp, target, subtarget,
  9030. tmode, ignore);
  9031. else
  9032. return expand_builtin (exp, target, subtarget, tmode, ignore);
  9033. }
  9034. }
  9035. return expand_call (exp, target, ignore);
  9036. case VIEW_CONVERT_EXPR:
  9037. op0 = NULL_RTX;
  9038. /* If we are converting to BLKmode, try to avoid an intermediate
  9039. temporary by fetching an inner memory reference. */
  9040. if (mode == BLKmode
  9041. && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
  9042. && TYPE_MODE (TREE_TYPE (treeop0)) != BLKmode
  9043. && handled_component_p (treeop0))
  9044. {
  9045. machine_mode mode1;
  9046. HOST_WIDE_INT bitsize, bitpos;
  9047. tree offset;
  9048. int unsignedp;
  9049. int volatilep = 0;
  9050. tree tem
  9051. = get_inner_reference (treeop0, &bitsize, &bitpos,
  9052. &offset, &mode1, &unsignedp, &volatilep,
  9053. true);
  9054. rtx orig_op0;
  9055. /* ??? We should work harder and deal with non-zero offsets. */
  9056. if (!offset
  9057. && (bitpos % BITS_PER_UNIT) == 0
  9058. && bitsize >= 0
  9059. && compare_tree_int (TYPE_SIZE (type), bitsize) == 0)
  9060. {
  9061. /* See the normal_inner_ref case for the rationale. */
  9062. orig_op0
  9063. = expand_expr_real (tem,
  9064. (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
  9065. && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
  9066. != INTEGER_CST)
  9067. && modifier != EXPAND_STACK_PARM
  9068. ? target : NULL_RTX),
  9069. VOIDmode,
  9070. modifier == EXPAND_SUM ? EXPAND_NORMAL : modifier,
  9071. NULL, true);
  9072. if (MEM_P (orig_op0))
  9073. {
  9074. op0 = orig_op0;
  9075. /* Get a reference to just this component. */
  9076. if (modifier == EXPAND_CONST_ADDRESS
  9077. || modifier == EXPAND_SUM
  9078. || modifier == EXPAND_INITIALIZER)
  9079. op0 = adjust_address_nv (op0, mode, bitpos / BITS_PER_UNIT);
  9080. else
  9081. op0 = adjust_address (op0, mode, bitpos / BITS_PER_UNIT);
  9082. if (op0 == orig_op0)
  9083. op0 = copy_rtx (op0);
  9084. set_mem_attributes (op0, treeop0, 0);
  9085. if (REG_P (XEXP (op0, 0)))
  9086. mark_reg_pointer (XEXP (op0, 0), MEM_ALIGN (op0));
  9087. MEM_VOLATILE_P (op0) |= volatilep;
  9088. }
  9089. }
  9090. }
  9091. if (!op0)
  9092. op0 = expand_expr_real (treeop0, NULL_RTX, VOIDmode, modifier,
  9093. NULL, inner_reference_p);
  9094. /* If the input and output modes are both the same, we are done. */
  9095. if (mode == GET_MODE (op0))
  9096. ;
  9097. /* If neither mode is BLKmode, and both modes are the same size
  9098. then we can use gen_lowpart. */
  9099. else if (mode != BLKmode && GET_MODE (op0) != BLKmode
  9100. && (GET_MODE_PRECISION (mode)
  9101. == GET_MODE_PRECISION (GET_MODE (op0)))
  9102. && !COMPLEX_MODE_P (GET_MODE (op0)))
  9103. {
  9104. if (GET_CODE (op0) == SUBREG)
  9105. op0 = force_reg (GET_MODE (op0), op0);
  9106. temp = gen_lowpart_common (mode, op0);
  9107. if (temp)
  9108. op0 = temp;
  9109. else
  9110. {
  9111. if (!REG_P (op0) && !MEM_P (op0))
  9112. op0 = force_reg (GET_MODE (op0), op0);
  9113. op0 = gen_lowpart (mode, op0);
  9114. }
  9115. }
  9116. /* If both types are integral, convert from one mode to the other. */
  9117. else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0)))
  9118. op0 = convert_modes (mode, GET_MODE (op0), op0,
  9119. TYPE_UNSIGNED (TREE_TYPE (treeop0)));
  9120. /* If the output type is a bit-field type, do an extraction. */
  9121. else if (reduce_bit_field)
  9122. return extract_bit_field (op0, TYPE_PRECISION (type), 0,
  9123. TYPE_UNSIGNED (type), NULL_RTX,
  9124. mode, mode);
  9125. /* As a last resort, spill op0 to memory, and reload it in a
  9126. different mode. */
  9127. else if (!MEM_P (op0))
  9128. {
  9129. /* If the operand is not a MEM, force it into memory. Since we
  9130. are going to be changing the mode of the MEM, don't call
  9131. force_const_mem for constants because we don't allow pool
  9132. constants to change mode. */
  9133. tree inner_type = TREE_TYPE (treeop0);
  9134. gcc_assert (!TREE_ADDRESSABLE (exp));
  9135. if (target == 0 || GET_MODE (target) != TYPE_MODE (inner_type))
  9136. target
  9137. = assign_stack_temp_for_type
  9138. (TYPE_MODE (inner_type),
  9139. GET_MODE_SIZE (TYPE_MODE (inner_type)), inner_type);
  9140. emit_move_insn (target, op0);
  9141. op0 = target;
  9142. }
  9143. /* If OP0 is (now) a MEM, we need to deal with alignment issues. If the
  9144. output type is such that the operand is known to be aligned, indicate
  9145. that it is. Otherwise, we need only be concerned about alignment for
  9146. non-BLKmode results. */
  9147. if (MEM_P (op0))
  9148. {
  9149. enum insn_code icode;
  9150. if (TYPE_ALIGN_OK (type))
  9151. {
  9152. /* ??? Copying the MEM without substantially changing it might
  9153. run afoul of the code handling volatile memory references in
  9154. store_expr, which assumes that TARGET is returned unmodified
  9155. if it has been used. */
  9156. op0 = copy_rtx (op0);
  9157. set_mem_align (op0, MAX (MEM_ALIGN (op0), TYPE_ALIGN (type)));
  9158. }
  9159. else if (modifier != EXPAND_WRITE
  9160. && modifier != EXPAND_MEMORY
  9161. && !inner_reference_p
  9162. && mode != BLKmode
  9163. && MEM_ALIGN (op0) < GET_MODE_ALIGNMENT (mode))
  9164. {
  9165. /* If the target does have special handling for unaligned
  9166. loads of mode then use them. */
  9167. if ((icode = optab_handler (movmisalign_optab, mode))
  9168. != CODE_FOR_nothing)
  9169. {
  9170. rtx reg, insn;
  9171. op0 = adjust_address (op0, mode, 0);
  9172. /* We've already validated the memory, and we're creating a
  9173. new pseudo destination. The predicates really can't
  9174. fail. */
  9175. reg = gen_reg_rtx (mode);
  9176. /* Nor can the insn generator. */
  9177. insn = GEN_FCN (icode) (reg, op0);
  9178. emit_insn (insn);
  9179. return reg;
  9180. }
  9181. else if (STRICT_ALIGNMENT)
  9182. {
  9183. tree inner_type = TREE_TYPE (treeop0);
  9184. HOST_WIDE_INT temp_size
  9185. = MAX (int_size_in_bytes (inner_type),
  9186. (HOST_WIDE_INT) GET_MODE_SIZE (mode));
  9187. rtx new_rtx
  9188. = assign_stack_temp_for_type (mode, temp_size, type);
  9189. rtx new_with_op0_mode
  9190. = adjust_address (new_rtx, GET_MODE (op0), 0);
  9191. gcc_assert (!TREE_ADDRESSABLE (exp));
  9192. if (GET_MODE (op0) == BLKmode)
  9193. emit_block_move (new_with_op0_mode, op0,
  9194. GEN_INT (GET_MODE_SIZE (mode)),
  9195. (modifier == EXPAND_STACK_PARM
  9196. ? BLOCK_OP_CALL_PARM : BLOCK_OP_NORMAL));
  9197. else
  9198. emit_move_insn (new_with_op0_mode, op0);
  9199. op0 = new_rtx;
  9200. }
  9201. }
  9202. op0 = adjust_address (op0, mode, 0);
  9203. }
  9204. return op0;
  9205. case MODIFY_EXPR:
  9206. {
  9207. tree lhs = treeop0;
  9208. tree rhs = treeop1;
  9209. gcc_assert (ignore);
  9210. /* Check for |= or &= of a bitfield of size one into another bitfield
  9211. of size 1. In this case, (unless we need the result of the
  9212. assignment) we can do this more efficiently with a
  9213. test followed by an assignment, if necessary.
  9214. ??? At this point, we can't get a BIT_FIELD_REF here. But if
  9215. things change so we do, this code should be enhanced to
  9216. support it. */
  9217. if (TREE_CODE (lhs) == COMPONENT_REF
  9218. && (TREE_CODE (rhs) == BIT_IOR_EXPR
  9219. || TREE_CODE (rhs) == BIT_AND_EXPR)
  9220. && TREE_OPERAND (rhs, 0) == lhs
  9221. && TREE_CODE (TREE_OPERAND (rhs, 1)) == COMPONENT_REF
  9222. && integer_onep (DECL_SIZE (TREE_OPERAND (lhs, 1)))
  9223. && integer_onep (DECL_SIZE (TREE_OPERAND (TREE_OPERAND (rhs, 1), 1))))
  9224. {
  9225. rtx_code_label *label = gen_label_rtx ();
  9226. int value = TREE_CODE (rhs) == BIT_IOR_EXPR;
  9227. do_jump (TREE_OPERAND (rhs, 1),
  9228. value ? label : 0,
  9229. value ? 0 : label, -1);
  9230. expand_assignment (lhs, build_int_cst (TREE_TYPE (rhs), value),
  9231. false);
  9232. do_pending_stack_adjust ();
  9233. emit_label (label);
  9234. return const0_rtx;
  9235. }
  9236. expand_assignment (lhs, rhs, false);
  9237. return const0_rtx;
  9238. }
  9239. case ADDR_EXPR:
  9240. return expand_expr_addr_expr (exp, target, tmode, modifier);
  9241. case REALPART_EXPR:
  9242. op0 = expand_normal (treeop0);
  9243. return read_complex_part (op0, false);
  9244. case IMAGPART_EXPR:
  9245. op0 = expand_normal (treeop0);
  9246. return read_complex_part (op0, true);
  9247. case RETURN_EXPR:
  9248. case LABEL_EXPR:
  9249. case GOTO_EXPR:
  9250. case SWITCH_EXPR:
  9251. case ASM_EXPR:
  9252. /* Expanded in cfgexpand.c. */
  9253. gcc_unreachable ();
  9254. case TRY_CATCH_EXPR:
  9255. case CATCH_EXPR:
  9256. case EH_FILTER_EXPR:
  9257. case TRY_FINALLY_EXPR:
  9258. /* Lowered by tree-eh.c. */
  9259. gcc_unreachable ();
  9260. case WITH_CLEANUP_EXPR:
  9261. case CLEANUP_POINT_EXPR:
  9262. case TARGET_EXPR:
  9263. case CASE_LABEL_EXPR:
  9264. case VA_ARG_EXPR:
  9265. case BIND_EXPR:
  9266. case INIT_EXPR:
  9267. case CONJ_EXPR:
  9268. case COMPOUND_EXPR:
  9269. case PREINCREMENT_EXPR:
  9270. case PREDECREMENT_EXPR:
  9271. case POSTINCREMENT_EXPR:
  9272. case POSTDECREMENT_EXPR:
  9273. case LOOP_EXPR:
  9274. case EXIT_EXPR:
  9275. case COMPOUND_LITERAL_EXPR:
  9276. /* Lowered by gimplify.c. */
  9277. gcc_unreachable ();
  9278. case FDESC_EXPR:
  9279. /* Function descriptors are not valid except for as
  9280. initialization constants, and should not be expanded. */
  9281. gcc_unreachable ();
  9282. case WITH_SIZE_EXPR:
  9283. /* WITH_SIZE_EXPR expands to its first argument. The caller should
  9284. have pulled out the size to use in whatever context it needed. */
  9285. return expand_expr_real (treeop0, original_target, tmode,
  9286. modifier, alt_rtl, inner_reference_p);
  9287. default:
  9288. return expand_expr_real_2 (&ops, target, tmode, modifier);
  9289. }
  9290. }
  9291. /* Subroutine of above: reduce EXP to the precision of TYPE (in the
  9292. signedness of TYPE), possibly returning the result in TARGET. */
  9293. static rtx
  9294. reduce_to_bit_field_precision (rtx exp, rtx target, tree type)
  9295. {
  9296. HOST_WIDE_INT prec = TYPE_PRECISION (type);
  9297. if (target && GET_MODE (target) != GET_MODE (exp))
  9298. target = 0;
  9299. /* For constant values, reduce using build_int_cst_type. */
  9300. if (CONST_INT_P (exp))
  9301. {
  9302. HOST_WIDE_INT value = INTVAL (exp);
  9303. tree t = build_int_cst_type (type, value);
  9304. return expand_expr (t, target, VOIDmode, EXPAND_NORMAL);
  9305. }
  9306. else if (TYPE_UNSIGNED (type))
  9307. {
  9308. machine_mode mode = GET_MODE (exp);
  9309. rtx mask = immed_wide_int_const
  9310. (wi::mask (prec, false, GET_MODE_PRECISION (mode)), mode);
  9311. return expand_and (mode, exp, mask, target);
  9312. }
  9313. else
  9314. {
  9315. int count = GET_MODE_PRECISION (GET_MODE (exp)) - prec;
  9316. exp = expand_shift (LSHIFT_EXPR, GET_MODE (exp),
  9317. exp, count, target, 0);
  9318. return expand_shift (RSHIFT_EXPR, GET_MODE (exp),
  9319. exp, count, target, 0);
  9320. }
  9321. }
  9322. /* Subroutine of above: returns 1 if OFFSET corresponds to an offset that
  9323. when applied to the address of EXP produces an address known to be
  9324. aligned more than BIGGEST_ALIGNMENT. */
  9325. static int
  9326. is_aligning_offset (const_tree offset, const_tree exp)
  9327. {
  9328. /* Strip off any conversions. */
  9329. while (CONVERT_EXPR_P (offset))
  9330. offset = TREE_OPERAND (offset, 0);
  9331. /* We must now have a BIT_AND_EXPR with a constant that is one less than
  9332. power of 2 and which is larger than BIGGEST_ALIGNMENT. */
  9333. if (TREE_CODE (offset) != BIT_AND_EXPR
  9334. || !tree_fits_uhwi_p (TREE_OPERAND (offset, 1))
  9335. || compare_tree_int (TREE_OPERAND (offset, 1),
  9336. BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
  9337. || exact_log2 (tree_to_uhwi (TREE_OPERAND (offset, 1)) + 1) < 0)
  9338. return 0;
  9339. /* Look at the first operand of BIT_AND_EXPR and strip any conversion.
  9340. It must be NEGATE_EXPR. Then strip any more conversions. */
  9341. offset = TREE_OPERAND (offset, 0);
  9342. while (CONVERT_EXPR_P (offset))
  9343. offset = TREE_OPERAND (offset, 0);
  9344. if (TREE_CODE (offset) != NEGATE_EXPR)
  9345. return 0;
  9346. offset = TREE_OPERAND (offset, 0);
  9347. while (CONVERT_EXPR_P (offset))
  9348. offset = TREE_OPERAND (offset, 0);
  9349. /* This must now be the address of EXP. */
  9350. return TREE_CODE (offset) == ADDR_EXPR && TREE_OPERAND (offset, 0) == exp;
  9351. }
  9352. /* Return the tree node if an ARG corresponds to a string constant or zero
  9353. if it doesn't. If we return nonzero, set *PTR_OFFSET to the offset
  9354. in bytes within the string that ARG is accessing. The type of the
  9355. offset will be `sizetype'. */
  9356. tree
  9357. string_constant (tree arg, tree *ptr_offset)
  9358. {
  9359. tree array, offset, lower_bound;
  9360. STRIP_NOPS (arg);
  9361. if (TREE_CODE (arg) == ADDR_EXPR)
  9362. {
  9363. if (TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
  9364. {
  9365. *ptr_offset = size_zero_node;
  9366. return TREE_OPERAND (arg, 0);
  9367. }
  9368. else if (TREE_CODE (TREE_OPERAND (arg, 0)) == VAR_DECL)
  9369. {
  9370. array = TREE_OPERAND (arg, 0);
  9371. offset = size_zero_node;
  9372. }
  9373. else if (TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF)
  9374. {
  9375. array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
  9376. offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
  9377. if (TREE_CODE (array) != STRING_CST
  9378. && TREE_CODE (array) != VAR_DECL)
  9379. return 0;
  9380. /* Check if the array has a nonzero lower bound. */
  9381. lower_bound = array_ref_low_bound (TREE_OPERAND (arg, 0));
  9382. if (!integer_zerop (lower_bound))
  9383. {
  9384. /* If the offset and base aren't both constants, return 0. */
  9385. if (TREE_CODE (lower_bound) != INTEGER_CST)
  9386. return 0;
  9387. if (TREE_CODE (offset) != INTEGER_CST)
  9388. return 0;
  9389. /* Adjust offset by the lower bound. */
  9390. offset = size_diffop (fold_convert (sizetype, offset),
  9391. fold_convert (sizetype, lower_bound));
  9392. }
  9393. }
  9394. else if (TREE_CODE (TREE_OPERAND (arg, 0)) == MEM_REF)
  9395. {
  9396. array = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
  9397. offset = TREE_OPERAND (TREE_OPERAND (arg, 0), 1);
  9398. if (TREE_CODE (array) != ADDR_EXPR)
  9399. return 0;
  9400. array = TREE_OPERAND (array, 0);
  9401. if (TREE_CODE (array) != STRING_CST
  9402. && TREE_CODE (array) != VAR_DECL)
  9403. return 0;
  9404. }
  9405. else
  9406. return 0;
  9407. }
  9408. else if (TREE_CODE (arg) == PLUS_EXPR || TREE_CODE (arg) == POINTER_PLUS_EXPR)
  9409. {
  9410. tree arg0 = TREE_OPERAND (arg, 0);
  9411. tree arg1 = TREE_OPERAND (arg, 1);
  9412. STRIP_NOPS (arg0);
  9413. STRIP_NOPS (arg1);
  9414. if (TREE_CODE (arg0) == ADDR_EXPR
  9415. && (TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST
  9416. || TREE_CODE (TREE_OPERAND (arg0, 0)) == VAR_DECL))
  9417. {
  9418. array = TREE_OPERAND (arg0, 0);
  9419. offset = arg1;
  9420. }
  9421. else if (TREE_CODE (arg1) == ADDR_EXPR
  9422. && (TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST
  9423. || TREE_CODE (TREE_OPERAND (arg1, 0)) == VAR_DECL))
  9424. {
  9425. array = TREE_OPERAND (arg1, 0);
  9426. offset = arg0;
  9427. }
  9428. else
  9429. return 0;
  9430. }
  9431. else
  9432. return 0;
  9433. if (TREE_CODE (array) == STRING_CST)
  9434. {
  9435. *ptr_offset = fold_convert (sizetype, offset);
  9436. return array;
  9437. }
  9438. else if (TREE_CODE (array) == VAR_DECL
  9439. || TREE_CODE (array) == CONST_DECL)
  9440. {
  9441. int length;
  9442. tree init = ctor_for_folding (array);
  9443. /* Variables initialized to string literals can be handled too. */
  9444. if (init == error_mark_node
  9445. || !init
  9446. || TREE_CODE (init) != STRING_CST)
  9447. return 0;
  9448. /* Avoid const char foo[4] = "abcde"; */
  9449. if (DECL_SIZE_UNIT (array) == NULL_TREE
  9450. || TREE_CODE (DECL_SIZE_UNIT (array)) != INTEGER_CST
  9451. || (length = TREE_STRING_LENGTH (init)) <= 0
  9452. || compare_tree_int (DECL_SIZE_UNIT (array), length) < 0)
  9453. return 0;
  9454. /* If variable is bigger than the string literal, OFFSET must be constant
  9455. and inside of the bounds of the string literal. */
  9456. offset = fold_convert (sizetype, offset);
  9457. if (compare_tree_int (DECL_SIZE_UNIT (array), length) > 0
  9458. && (! tree_fits_uhwi_p (offset)
  9459. || compare_tree_int (offset, length) >= 0))
  9460. return 0;
  9461. *ptr_offset = offset;
  9462. return init;
  9463. }
  9464. return 0;
  9465. }
  9466. /* Generate code to calculate OPS, and exploded expression
  9467. using a store-flag instruction and return an rtx for the result.
  9468. OPS reflects a comparison.
  9469. If TARGET is nonzero, store the result there if convenient.
  9470. Return zero if there is no suitable set-flag instruction
  9471. available on this machine.
  9472. Once expand_expr has been called on the arguments of the comparison,
  9473. we are committed to doing the store flag, since it is not safe to
  9474. re-evaluate the expression. We emit the store-flag insn by calling
  9475. emit_store_flag, but only expand the arguments if we have a reason
  9476. to believe that emit_store_flag will be successful. If we think that
  9477. it will, but it isn't, we have to simulate the store-flag with a
  9478. set/jump/set sequence. */
  9479. static rtx
  9480. do_store_flag (sepops ops, rtx target, machine_mode mode)
  9481. {
  9482. enum rtx_code code;
  9483. tree arg0, arg1, type;
  9484. tree tem;
  9485. machine_mode operand_mode;
  9486. int unsignedp;
  9487. rtx op0, op1;
  9488. rtx subtarget = target;
  9489. location_t loc = ops->location;
  9490. arg0 = ops->op0;
  9491. arg1 = ops->op1;
  9492. /* Don't crash if the comparison was erroneous. */
  9493. if (arg0 == error_mark_node || arg1 == error_mark_node)
  9494. return const0_rtx;
  9495. type = TREE_TYPE (arg0);
  9496. operand_mode = TYPE_MODE (type);
  9497. unsignedp = TYPE_UNSIGNED (type);
  9498. /* We won't bother with BLKmode store-flag operations because it would mean
  9499. passing a lot of information to emit_store_flag. */
  9500. if (operand_mode == BLKmode)
  9501. return 0;
  9502. /* We won't bother with store-flag operations involving function pointers
  9503. when function pointers must be canonicalized before comparisons. */
  9504. #ifdef HAVE_canonicalize_funcptr_for_compare
  9505. if (HAVE_canonicalize_funcptr_for_compare
  9506. && ((TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE
  9507. && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg0)))
  9508. == FUNCTION_TYPE))
  9509. || (TREE_CODE (TREE_TYPE (arg1)) == POINTER_TYPE
  9510. && (TREE_CODE (TREE_TYPE (TREE_TYPE (arg1)))
  9511. == FUNCTION_TYPE))))
  9512. return 0;
  9513. #endif
  9514. STRIP_NOPS (arg0);
  9515. STRIP_NOPS (arg1);
  9516. /* For vector typed comparisons emit code to generate the desired
  9517. all-ones or all-zeros mask. Conveniently use the VEC_COND_EXPR
  9518. expander for this. */
  9519. if (TREE_CODE (ops->type) == VECTOR_TYPE)
  9520. {
  9521. tree ifexp = build2 (ops->code, ops->type, arg0, arg1);
  9522. tree if_true = constant_boolean_node (true, ops->type);
  9523. tree if_false = constant_boolean_node (false, ops->type);
  9524. return expand_vec_cond_expr (ops->type, ifexp, if_true, if_false, target);
  9525. }
  9526. /* Get the rtx comparison code to use. We know that EXP is a comparison
  9527. operation of some type. Some comparisons against 1 and -1 can be
  9528. converted to comparisons with zero. Do so here so that the tests
  9529. below will be aware that we have a comparison with zero. These
  9530. tests will not catch constants in the first operand, but constants
  9531. are rarely passed as the first operand. */
  9532. switch (ops->code)
  9533. {
  9534. case EQ_EXPR:
  9535. code = EQ;
  9536. break;
  9537. case NE_EXPR:
  9538. code = NE;
  9539. break;
  9540. case LT_EXPR:
  9541. if (integer_onep (arg1))
  9542. arg1 = integer_zero_node, code = unsignedp ? LEU : LE;
  9543. else
  9544. code = unsignedp ? LTU : LT;
  9545. break;
  9546. case LE_EXPR:
  9547. if (! unsignedp && integer_all_onesp (arg1))
  9548. arg1 = integer_zero_node, code = LT;
  9549. else
  9550. code = unsignedp ? LEU : LE;
  9551. break;
  9552. case GT_EXPR:
  9553. if (! unsignedp && integer_all_onesp (arg1))
  9554. arg1 = integer_zero_node, code = GE;
  9555. else
  9556. code = unsignedp ? GTU : GT;
  9557. break;
  9558. case GE_EXPR:
  9559. if (integer_onep (arg1))
  9560. arg1 = integer_zero_node, code = unsignedp ? GTU : GT;
  9561. else
  9562. code = unsignedp ? GEU : GE;
  9563. break;
  9564. case UNORDERED_EXPR:
  9565. code = UNORDERED;
  9566. break;
  9567. case ORDERED_EXPR:
  9568. code = ORDERED;
  9569. break;
  9570. case UNLT_EXPR:
  9571. code = UNLT;
  9572. break;
  9573. case UNLE_EXPR:
  9574. code = UNLE;
  9575. break;
  9576. case UNGT_EXPR:
  9577. code = UNGT;
  9578. break;
  9579. case UNGE_EXPR:
  9580. code = UNGE;
  9581. break;
  9582. case UNEQ_EXPR:
  9583. code = UNEQ;
  9584. break;
  9585. case LTGT_EXPR:
  9586. code = LTGT;
  9587. break;
  9588. default:
  9589. gcc_unreachable ();
  9590. }
  9591. /* Put a constant second. */
  9592. if (TREE_CODE (arg0) == REAL_CST || TREE_CODE (arg0) == INTEGER_CST
  9593. || TREE_CODE (arg0) == FIXED_CST)
  9594. {
  9595. tem = arg0; arg0 = arg1; arg1 = tem;
  9596. code = swap_condition (code);
  9597. }
  9598. /* If this is an equality or inequality test of a single bit, we can
  9599. do this by shifting the bit being tested to the low-order bit and
  9600. masking the result with the constant 1. If the condition was EQ,
  9601. we xor it with 1. This does not require an scc insn and is faster
  9602. than an scc insn even if we have it.
  9603. The code to make this transformation was moved into fold_single_bit_test,
  9604. so we just call into the folder and expand its result. */
  9605. if ((code == NE || code == EQ)
  9606. && integer_zerop (arg1)
  9607. && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type)))
  9608. {
  9609. gimple srcstmt = get_def_for_expr (arg0, BIT_AND_EXPR);
  9610. if (srcstmt
  9611. && integer_pow2p (gimple_assign_rhs2 (srcstmt)))
  9612. {
  9613. enum tree_code tcode = code == NE ? NE_EXPR : EQ_EXPR;
  9614. tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
  9615. tree temp = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg1),
  9616. gimple_assign_rhs1 (srcstmt),
  9617. gimple_assign_rhs2 (srcstmt));
  9618. temp = fold_single_bit_test (loc, tcode, temp, arg1, type);
  9619. if (temp)
  9620. return expand_expr (temp, target, VOIDmode, EXPAND_NORMAL);
  9621. }
  9622. }
  9623. if (! get_subtarget (target)
  9624. || GET_MODE (subtarget) != operand_mode)
  9625. subtarget = 0;
  9626. expand_operands (arg0, arg1, subtarget, &op0, &op1, EXPAND_NORMAL);
  9627. if (target == 0)
  9628. target = gen_reg_rtx (mode);
  9629. /* Try a cstore if possible. */
  9630. return emit_store_flag_force (target, code, op0, op1,
  9631. operand_mode, unsignedp,
  9632. (TYPE_PRECISION (ops->type) == 1
  9633. && !TYPE_UNSIGNED (ops->type)) ? -1 : 1);
  9634. }
  9635. /* Stubs in case we haven't got a casesi insn. */
  9636. #ifndef HAVE_casesi
  9637. # define HAVE_casesi 0
  9638. # define gen_casesi(a, b, c, d, e) (0)
  9639. # define CODE_FOR_casesi CODE_FOR_nothing
  9640. #endif
  9641. /* Attempt to generate a casesi instruction. Returns 1 if successful,
  9642. 0 otherwise (i.e. if there is no casesi instruction).
  9643. DEFAULT_PROBABILITY is the probability of jumping to the default
  9644. label. */
  9645. int
  9646. try_casesi (tree index_type, tree index_expr, tree minval, tree range,
  9647. rtx table_label, rtx default_label, rtx fallback_label,
  9648. int default_probability)
  9649. {
  9650. struct expand_operand ops[5];
  9651. machine_mode index_mode = SImode;
  9652. rtx op1, op2, index;
  9653. if (! HAVE_casesi)
  9654. return 0;
  9655. /* Convert the index to SImode. */
  9656. if (GET_MODE_BITSIZE (TYPE_MODE (index_type)) > GET_MODE_BITSIZE (index_mode))
  9657. {
  9658. machine_mode omode = TYPE_MODE (index_type);
  9659. rtx rangertx = expand_normal (range);
  9660. /* We must handle the endpoints in the original mode. */
  9661. index_expr = build2 (MINUS_EXPR, index_type,
  9662. index_expr, minval);
  9663. minval = integer_zero_node;
  9664. index = expand_normal (index_expr);
  9665. if (default_label)
  9666. emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
  9667. omode, 1, default_label,
  9668. default_probability);
  9669. /* Now we can safely truncate. */
  9670. index = convert_to_mode (index_mode, index, 0);
  9671. }
  9672. else
  9673. {
  9674. if (TYPE_MODE (index_type) != index_mode)
  9675. {
  9676. index_type = lang_hooks.types.type_for_mode (index_mode, 0);
  9677. index_expr = fold_convert (index_type, index_expr);
  9678. }
  9679. index = expand_normal (index_expr);
  9680. }
  9681. do_pending_stack_adjust ();
  9682. op1 = expand_normal (minval);
  9683. op2 = expand_normal (range);
  9684. create_input_operand (&ops[0], index, index_mode);
  9685. create_convert_operand_from_type (&ops[1], op1, TREE_TYPE (minval));
  9686. create_convert_operand_from_type (&ops[2], op2, TREE_TYPE (range));
  9687. create_fixed_operand (&ops[3], table_label);
  9688. create_fixed_operand (&ops[4], (default_label
  9689. ? default_label
  9690. : fallback_label));
  9691. expand_jump_insn (CODE_FOR_casesi, 5, ops);
  9692. return 1;
  9693. }
  9694. /* Attempt to generate a tablejump instruction; same concept. */
  9695. #ifndef HAVE_tablejump
  9696. #define HAVE_tablejump 0
  9697. #define gen_tablejump(x, y) (0)
  9698. #endif
  9699. /* Subroutine of the next function.
  9700. INDEX is the value being switched on, with the lowest value
  9701. in the table already subtracted.
  9702. MODE is its expected mode (needed if INDEX is constant).
  9703. RANGE is the length of the jump table.
  9704. TABLE_LABEL is a CODE_LABEL rtx for the table itself.
  9705. DEFAULT_LABEL is a CODE_LABEL rtx to jump to if the
  9706. index value is out of range.
  9707. DEFAULT_PROBABILITY is the probability of jumping to
  9708. the default label. */
  9709. static void
  9710. do_tablejump (rtx index, machine_mode mode, rtx range, rtx table_label,
  9711. rtx default_label, int default_probability)
  9712. {
  9713. rtx temp, vector;
  9714. if (INTVAL (range) > cfun->cfg->max_jumptable_ents)
  9715. cfun->cfg->max_jumptable_ents = INTVAL (range);
  9716. /* Do an unsigned comparison (in the proper mode) between the index
  9717. expression and the value which represents the length of the range.
  9718. Since we just finished subtracting the lower bound of the range
  9719. from the index expression, this comparison allows us to simultaneously
  9720. check that the original index expression value is both greater than
  9721. or equal to the minimum value of the range and less than or equal to
  9722. the maximum value of the range. */
  9723. if (default_label)
  9724. emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, mode, 1,
  9725. default_label, default_probability);
  9726. /* If index is in range, it must fit in Pmode.
  9727. Convert to Pmode so we can index with it. */
  9728. if (mode != Pmode)
  9729. index = convert_to_mode (Pmode, index, 1);
  9730. /* Don't let a MEM slip through, because then INDEX that comes
  9731. out of PIC_CASE_VECTOR_ADDRESS won't be a valid address,
  9732. and break_out_memory_refs will go to work on it and mess it up. */
  9733. #ifdef PIC_CASE_VECTOR_ADDRESS
  9734. if (flag_pic && !REG_P (index))
  9735. index = copy_to_mode_reg (Pmode, index);
  9736. #endif
  9737. /* ??? The only correct use of CASE_VECTOR_MODE is the one inside the
  9738. GET_MODE_SIZE, because this indicates how large insns are. The other
  9739. uses should all be Pmode, because they are addresses. This code
  9740. could fail if addresses and insns are not the same size. */
  9741. index = simplify_gen_binary (MULT, Pmode, index,
  9742. gen_int_mode (GET_MODE_SIZE (CASE_VECTOR_MODE),
  9743. Pmode));
  9744. index = simplify_gen_binary (PLUS, Pmode, index,
  9745. gen_rtx_LABEL_REF (Pmode, table_label));
  9746. #ifdef PIC_CASE_VECTOR_ADDRESS
  9747. if (flag_pic)
  9748. index = PIC_CASE_VECTOR_ADDRESS (index);
  9749. else
  9750. #endif
  9751. index = memory_address (CASE_VECTOR_MODE, index);
  9752. temp = gen_reg_rtx (CASE_VECTOR_MODE);
  9753. vector = gen_const_mem (CASE_VECTOR_MODE, index);
  9754. convert_move (temp, vector, 0);
  9755. emit_jump_insn (gen_tablejump (temp, table_label));
  9756. /* If we are generating PIC code or if the table is PC-relative, the
  9757. table and JUMP_INSN must be adjacent, so don't output a BARRIER. */
  9758. if (! CASE_VECTOR_PC_RELATIVE && ! flag_pic)
  9759. emit_barrier ();
  9760. }
  9761. int
  9762. try_tablejump (tree index_type, tree index_expr, tree minval, tree range,
  9763. rtx table_label, rtx default_label, int default_probability)
  9764. {
  9765. rtx index;
  9766. if (! HAVE_tablejump)
  9767. return 0;
  9768. index_expr = fold_build2 (MINUS_EXPR, index_type,
  9769. fold_convert (index_type, index_expr),
  9770. fold_convert (index_type, minval));
  9771. index = expand_normal (index_expr);
  9772. do_pending_stack_adjust ();
  9773. do_tablejump (index, TYPE_MODE (index_type),
  9774. convert_modes (TYPE_MODE (index_type),
  9775. TYPE_MODE (TREE_TYPE (range)),
  9776. expand_normal (range),
  9777. TYPE_UNSIGNED (TREE_TYPE (range))),
  9778. table_label, default_label, default_probability);
  9779. return 1;
  9780. }
  9781. /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */
  9782. static rtx
  9783. const_vector_from_tree (tree exp)
  9784. {
  9785. rtvec v;
  9786. unsigned i;
  9787. int units;
  9788. tree elt;
  9789. machine_mode inner, mode;
  9790. mode = TYPE_MODE (TREE_TYPE (exp));
  9791. if (initializer_zerop (exp))
  9792. return CONST0_RTX (mode);
  9793. units = GET_MODE_NUNITS (mode);
  9794. inner = GET_MODE_INNER (mode);
  9795. v = rtvec_alloc (units);
  9796. for (i = 0; i < VECTOR_CST_NELTS (exp); ++i)
  9797. {
  9798. elt = VECTOR_CST_ELT (exp, i);
  9799. if (TREE_CODE (elt) == REAL_CST)
  9800. RTVEC_ELT (v, i) = CONST_DOUBLE_FROM_REAL_VALUE (TREE_REAL_CST (elt),
  9801. inner);
  9802. else if (TREE_CODE (elt) == FIXED_CST)
  9803. RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
  9804. inner);
  9805. else
  9806. RTVEC_ELT (v, i) = immed_wide_int_const (elt, inner);
  9807. }
  9808. return gen_rtx_CONST_VECTOR (mode, v);
  9809. }
  9810. /* Build a decl for a personality function given a language prefix. */
  9811. tree
  9812. build_personality_function (const char *lang)
  9813. {
  9814. const char *unwind_and_version;
  9815. tree decl, type;
  9816. char *name;
  9817. switch (targetm_common.except_unwind_info (&global_options))
  9818. {
  9819. case UI_NONE:
  9820. return NULL;
  9821. case UI_SJLJ:
  9822. unwind_and_version = "_sj0";
  9823. break;
  9824. case UI_DWARF2:
  9825. case UI_TARGET:
  9826. unwind_and_version = "_v0";
  9827. break;
  9828. case UI_SEH:
  9829. unwind_and_version = "_seh0";
  9830. break;
  9831. default:
  9832. gcc_unreachable ();
  9833. }
  9834. name = ACONCAT (("__", lang, "_personality", unwind_and_version, NULL));
  9835. type = build_function_type_list (integer_type_node, integer_type_node,
  9836. long_long_unsigned_type_node,
  9837. ptr_type_node, ptr_type_node, NULL_TREE);
  9838. decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
  9839. get_identifier (name), type);
  9840. DECL_ARTIFICIAL (decl) = 1;
  9841. DECL_EXTERNAL (decl) = 1;
  9842. TREE_PUBLIC (decl) = 1;
  9843. /* Zap the nonsensical SYMBOL_REF_DECL for this. What we're left with
  9844. are the flags assigned by targetm.encode_section_info. */
  9845. SET_SYMBOL_REF_DECL (XEXP (DECL_RTL (decl), 0), NULL);
  9846. return decl;
  9847. }
  9848. /* Extracts the personality function of DECL and returns the corresponding
  9849. libfunc. */
  9850. rtx
  9851. get_personality_function (tree decl)
  9852. {
  9853. tree personality = DECL_FUNCTION_PERSONALITY (decl);
  9854. enum eh_personality_kind pk;
  9855. pk = function_needs_eh_personality (DECL_STRUCT_FUNCTION (decl));
  9856. if (pk == eh_personality_none)
  9857. return NULL;
  9858. if (!personality
  9859. && pk == eh_personality_any)
  9860. personality = lang_hooks.eh_personality ();
  9861. if (pk == eh_personality_lang)
  9862. gcc_assert (personality != NULL_TREE);
  9863. return XEXP (DECL_RTL (personality), 0);
  9864. }
  9865. /* Returns a tree for the size of EXP in bytes. */
  9866. static tree
  9867. tree_expr_size (const_tree exp)
  9868. {
  9869. if (DECL_P (exp)
  9870. && DECL_SIZE_UNIT (exp) != 0)
  9871. return DECL_SIZE_UNIT (exp);
  9872. else
  9873. return size_in_bytes (TREE_TYPE (exp));
  9874. }
  9875. /* Return an rtx for the size in bytes of the value of EXP. */
  9876. rtx
  9877. expr_size (tree exp)
  9878. {
  9879. tree size;
  9880. if (TREE_CODE (exp) == WITH_SIZE_EXPR)
  9881. size = TREE_OPERAND (exp, 1);
  9882. else
  9883. {
  9884. size = tree_expr_size (exp);
  9885. gcc_assert (size);
  9886. gcc_assert (size == SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, exp));
  9887. }
  9888. return expand_expr (size, NULL_RTX, TYPE_MODE (sizetype), EXPAND_NORMAL);
  9889. }
  9890. /* Return a wide integer for the size in bytes of the value of EXP, or -1
  9891. if the size can vary or is larger than an integer. */
  9892. static HOST_WIDE_INT
  9893. int_expr_size (tree exp)
  9894. {
  9895. tree size;
  9896. if (TREE_CODE (exp) == WITH_SIZE_EXPR)
  9897. size = TREE_OPERAND (exp, 1);
  9898. else
  9899. {
  9900. size = tree_expr_size (exp);
  9901. gcc_assert (size);
  9902. }
  9903. if (size == 0 || !tree_fits_shwi_p (size))
  9904. return -1;
  9905. return tree_to_shwi (size);
  9906. }
  9907. #include "gt-expr.h"