function.c 198 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778
  1. /* Expands front end tree to back end RTL for GCC.
  2. Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. /* This file handles the generation of rtl code from tree structure
  16. at the level of the function as a whole.
  17. It creates the rtl expressions for parameters and auto variables
  18. and has full responsibility for allocating stack slots.
  19. `expand_function_start' is called at the beginning of a function,
  20. before the function body is parsed, and `expand_function_end' is
  21. called after parsing the body.
  22. Call `assign_stack_local' to allocate a stack slot for a local variable.
  23. This is usually done during the RTL generation for the function body,
  24. but it can also be done in the reload pass when a pseudo-register does
  25. not get a hard register. */
  26. #include "config.h"
  27. #include "system.h"
  28. #include "coretypes.h"
  29. #include "tm.h"
  30. #include "rtl-error.h"
  31. #include "hash-set.h"
  32. #include "machmode.h"
  33. #include "vec.h"
  34. #include "double-int.h"
  35. #include "input.h"
  36. #include "alias.h"
  37. #include "symtab.h"
  38. #include "wide-int.h"
  39. #include "inchash.h"
  40. #include "tree.h"
  41. #include "fold-const.h"
  42. #include "stor-layout.h"
  43. #include "varasm.h"
  44. #include "stringpool.h"
  45. #include "flags.h"
  46. #include "except.h"
  47. #include "hashtab.h"
  48. #include "hard-reg-set.h"
  49. #include "function.h"
  50. #include "rtl.h"
  51. #include "statistics.h"
  52. #include "real.h"
  53. #include "fixed-value.h"
  54. #include "insn-config.h"
  55. #include "expmed.h"
  56. #include "dojump.h"
  57. #include "explow.h"
  58. #include "calls.h"
  59. #include "emit-rtl.h"
  60. #include "stmt.h"
  61. #include "expr.h"
  62. #include "insn-codes.h"
  63. #include "optabs.h"
  64. #include "libfuncs.h"
  65. #include "regs.h"
  66. #include "recog.h"
  67. #include "output.h"
  68. #include "tm_p.h"
  69. #include "langhooks.h"
  70. #include "target.h"
  71. #include "common/common-target.h"
  72. #include "gimple-expr.h"
  73. #include "gimplify.h"
  74. #include "tree-pass.h"
  75. #include "predict.h"
  76. #include "dominance.h"
  77. #include "cfg.h"
  78. #include "cfgrtl.h"
  79. #include "cfganal.h"
  80. #include "cfgbuild.h"
  81. #include "cfgcleanup.h"
  82. #include "basic-block.h"
  83. #include "df.h"
  84. #include "params.h"
  85. #include "bb-reorder.h"
  86. #include "shrink-wrap.h"
  87. #include "toplev.h"
  88. #include "rtl-iter.h"
  89. #include "tree-chkp.h"
  90. #include "rtl-chkp.h"
  91. /* So we can assign to cfun in this file. */
  92. #undef cfun
  93. #ifndef STACK_ALIGNMENT_NEEDED
  94. #define STACK_ALIGNMENT_NEEDED 1
  95. #endif
  96. #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
  97. /* Round a value to the lowest integer less than it that is a multiple of
  98. the required alignment. Avoid using division in case the value is
  99. negative. Assume the alignment is a power of two. */
  100. #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
  101. /* Similar, but round to the next highest integer that meets the
  102. alignment. */
  103. #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
  104. /* Nonzero once virtual register instantiation has been done.
  105. assign_stack_local uses frame_pointer_rtx when this is nonzero.
  106. calls.c:emit_library_call_value_1 uses it to set up
  107. post-instantiation libcalls. */
  108. int virtuals_instantiated;
  109. /* Assign unique numbers to labels generated for profiling, debugging, etc. */
  110. static GTY(()) int funcdef_no;
  111. /* These variables hold pointers to functions to create and destroy
  112. target specific, per-function data structures. */
  113. struct machine_function * (*init_machine_status) (void);
  114. /* The currently compiled function. */
  115. struct function *cfun = 0;
  116. /* These hashes record the prologue and epilogue insns. */
  117. struct insn_cache_hasher : ggc_cache_hasher<rtx>
  118. {
  119. static hashval_t hash (rtx x) { return htab_hash_pointer (x); }
  120. static bool equal (rtx a, rtx b) { return a == b; }
  121. };
  122. static GTY((cache))
  123. hash_table<insn_cache_hasher> *prologue_insn_hash;
  124. static GTY((cache))
  125. hash_table<insn_cache_hasher> *epilogue_insn_hash;
  126. hash_table<used_type_hasher> *types_used_by_vars_hash = NULL;
  127. vec<tree, va_gc> *types_used_by_cur_var_decl;
  128. /* Forward declarations. */
  129. static struct temp_slot *find_temp_slot_from_address (rtx);
  130. static void pad_to_arg_alignment (struct args_size *, int, struct args_size *);
  131. static void pad_below (struct args_size *, machine_mode, tree);
  132. static void reorder_blocks_1 (rtx_insn *, tree, vec<tree> *);
  133. static int all_blocks (tree, tree *);
  134. static tree *get_block_vector (tree, int *);
  135. extern tree debug_find_var_in_block_tree (tree, tree);
  136. /* We always define `record_insns' even if it's not used so that we
  137. can always export `prologue_epilogue_contains'. */
  138. static void record_insns (rtx_insn *, rtx, hash_table<insn_cache_hasher> **)
  139. ATTRIBUTE_UNUSED;
  140. static bool contains (const_rtx, hash_table<insn_cache_hasher> *);
  141. static void prepare_function_start (void);
  142. static void do_clobber_return_reg (rtx, void *);
  143. static void do_use_return_reg (rtx, void *);
  144. /* Stack of nested functions. */
  145. /* Keep track of the cfun stack. */
  146. typedef struct function *function_p;
  147. static vec<function_p> function_context_stack;
  148. /* Save the current context for compilation of a nested function.
  149. This is called from language-specific code. */
  150. void
  151. push_function_context (void)
  152. {
  153. if (cfun == 0)
  154. allocate_struct_function (NULL, false);
  155. function_context_stack.safe_push (cfun);
  156. set_cfun (NULL);
  157. }
  158. /* Restore the last saved context, at the end of a nested function.
  159. This function is called from language-specific code. */
  160. void
  161. pop_function_context (void)
  162. {
  163. struct function *p = function_context_stack.pop ();
  164. set_cfun (p);
  165. current_function_decl = p->decl;
  166. /* Reset variables that have known state during rtx generation. */
  167. virtuals_instantiated = 0;
  168. generating_concat_p = 1;
  169. }
  170. /* Clear out all parts of the state in F that can safely be discarded
  171. after the function has been parsed, but not compiled, to let
  172. garbage collection reclaim the memory. */
  173. void
  174. free_after_parsing (struct function *f)
  175. {
  176. f->language = 0;
  177. }
  178. /* Clear out all parts of the state in F that can safely be discarded
  179. after the function has been compiled, to let garbage collection
  180. reclaim the memory. */
  181. void
  182. free_after_compilation (struct function *f)
  183. {
  184. prologue_insn_hash = NULL;
  185. epilogue_insn_hash = NULL;
  186. free (crtl->emit.regno_pointer_align);
  187. memset (crtl, 0, sizeof (struct rtl_data));
  188. f->eh = NULL;
  189. f->machine = NULL;
  190. f->cfg = NULL;
  191. regno_reg_rtx = NULL;
  192. }
  193. /* Return size needed for stack frame based on slots so far allocated.
  194. This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
  195. the caller may have to do that. */
  196. HOST_WIDE_INT
  197. get_frame_size (void)
  198. {
  199. if (FRAME_GROWS_DOWNWARD)
  200. return -frame_offset;
  201. else
  202. return frame_offset;
  203. }
  204. /* Issue an error message and return TRUE if frame OFFSET overflows in
  205. the signed target pointer arithmetics for function FUNC. Otherwise
  206. return FALSE. */
  207. bool
  208. frame_offset_overflow (HOST_WIDE_INT offset, tree func)
  209. {
  210. unsigned HOST_WIDE_INT size = FRAME_GROWS_DOWNWARD ? -offset : offset;
  211. if (size > ((unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (Pmode) - 1))
  212. /* Leave room for the fixed part of the frame. */
  213. - 64 * UNITS_PER_WORD)
  214. {
  215. error_at (DECL_SOURCE_LOCATION (func),
  216. "total size of local objects too large");
  217. return TRUE;
  218. }
  219. return FALSE;
  220. }
  221. /* Return stack slot alignment in bits for TYPE and MODE. */
  222. static unsigned int
  223. get_stack_local_alignment (tree type, machine_mode mode)
  224. {
  225. unsigned int alignment;
  226. if (mode == BLKmode)
  227. alignment = BIGGEST_ALIGNMENT;
  228. else
  229. alignment = GET_MODE_ALIGNMENT (mode);
  230. /* Allow the frond-end to (possibly) increase the alignment of this
  231. stack slot. */
  232. if (! type)
  233. type = lang_hooks.types.type_for_mode (mode, 0);
  234. return STACK_SLOT_ALIGNMENT (type, mode, alignment);
  235. }
  236. /* Determine whether it is possible to fit a stack slot of size SIZE and
  237. alignment ALIGNMENT into an area in the stack frame that starts at
  238. frame offset START and has a length of LENGTH. If so, store the frame
  239. offset to be used for the stack slot in *POFFSET and return true;
  240. return false otherwise. This function will extend the frame size when
  241. given a start/length pair that lies at the end of the frame. */
  242. static bool
  243. try_fit_stack_local (HOST_WIDE_INT start, HOST_WIDE_INT length,
  244. HOST_WIDE_INT size, unsigned int alignment,
  245. HOST_WIDE_INT *poffset)
  246. {
  247. HOST_WIDE_INT this_frame_offset;
  248. int frame_off, frame_alignment, frame_phase;
  249. /* Calculate how many bytes the start of local variables is off from
  250. stack alignment. */
  251. frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
  252. frame_off = STARTING_FRAME_OFFSET % frame_alignment;
  253. frame_phase = frame_off ? frame_alignment - frame_off : 0;
  254. /* Round the frame offset to the specified alignment. */
  255. /* We must be careful here, since FRAME_OFFSET might be negative and
  256. division with a negative dividend isn't as well defined as we might
  257. like. So we instead assume that ALIGNMENT is a power of two and
  258. use logical operations which are unambiguous. */
  259. if (FRAME_GROWS_DOWNWARD)
  260. this_frame_offset
  261. = (FLOOR_ROUND (start + length - size - frame_phase,
  262. (unsigned HOST_WIDE_INT) alignment)
  263. + frame_phase);
  264. else
  265. this_frame_offset
  266. = (CEIL_ROUND (start - frame_phase,
  267. (unsigned HOST_WIDE_INT) alignment)
  268. + frame_phase);
  269. /* See if it fits. If this space is at the edge of the frame,
  270. consider extending the frame to make it fit. Our caller relies on
  271. this when allocating a new slot. */
  272. if (frame_offset == start && this_frame_offset < frame_offset)
  273. frame_offset = this_frame_offset;
  274. else if (this_frame_offset < start)
  275. return false;
  276. else if (start + length == frame_offset
  277. && this_frame_offset + size > start + length)
  278. frame_offset = this_frame_offset + size;
  279. else if (this_frame_offset + size > start + length)
  280. return false;
  281. *poffset = this_frame_offset;
  282. return true;
  283. }
  284. /* Create a new frame_space structure describing free space in the stack
  285. frame beginning at START and ending at END, and chain it into the
  286. function's frame_space_list. */
  287. static void
  288. add_frame_space (HOST_WIDE_INT start, HOST_WIDE_INT end)
  289. {
  290. struct frame_space *space = ggc_alloc<frame_space> ();
  291. space->next = crtl->frame_space_list;
  292. crtl->frame_space_list = space;
  293. space->start = start;
  294. space->length = end - start;
  295. }
  296. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  297. with machine mode MODE.
  298. ALIGN controls the amount of alignment for the address of the slot:
  299. 0 means according to MODE,
  300. -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
  301. -2 means use BITS_PER_UNIT,
  302. positive specifies alignment boundary in bits.
  303. KIND has ASLK_REDUCE_ALIGN bit set if it is OK to reduce
  304. alignment and ASLK_RECORD_PAD bit set if we should remember
  305. extra space we allocated for alignment purposes. When we are
  306. called from assign_stack_temp_for_type, it is not set so we don't
  307. track the same stack slot in two independent lists.
  308. We do not round to stack_boundary here. */
  309. rtx
  310. assign_stack_local_1 (machine_mode mode, HOST_WIDE_INT size,
  311. int align, int kind)
  312. {
  313. rtx x, addr;
  314. int bigend_correction = 0;
  315. HOST_WIDE_INT slot_offset = 0, old_frame_offset;
  316. unsigned int alignment, alignment_in_bits;
  317. if (align == 0)
  318. {
  319. alignment = get_stack_local_alignment (NULL, mode);
  320. alignment /= BITS_PER_UNIT;
  321. }
  322. else if (align == -1)
  323. {
  324. alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  325. size = CEIL_ROUND (size, alignment);
  326. }
  327. else if (align == -2)
  328. alignment = 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
  329. else
  330. alignment = align / BITS_PER_UNIT;
  331. alignment_in_bits = alignment * BITS_PER_UNIT;
  332. /* Ignore alignment if it exceeds MAX_SUPPORTED_STACK_ALIGNMENT. */
  333. if (alignment_in_bits > MAX_SUPPORTED_STACK_ALIGNMENT)
  334. {
  335. alignment_in_bits = MAX_SUPPORTED_STACK_ALIGNMENT;
  336. alignment = alignment_in_bits / BITS_PER_UNIT;
  337. }
  338. if (SUPPORTS_STACK_ALIGNMENT)
  339. {
  340. if (crtl->stack_alignment_estimated < alignment_in_bits)
  341. {
  342. if (!crtl->stack_realign_processed)
  343. crtl->stack_alignment_estimated = alignment_in_bits;
  344. else
  345. {
  346. /* If stack is realigned and stack alignment value
  347. hasn't been finalized, it is OK not to increase
  348. stack_alignment_estimated. The bigger alignment
  349. requirement is recorded in stack_alignment_needed
  350. below. */
  351. gcc_assert (!crtl->stack_realign_finalized);
  352. if (!crtl->stack_realign_needed)
  353. {
  354. /* It is OK to reduce the alignment as long as the
  355. requested size is 0 or the estimated stack
  356. alignment >= mode alignment. */
  357. gcc_assert ((kind & ASLK_REDUCE_ALIGN)
  358. || size == 0
  359. || (crtl->stack_alignment_estimated
  360. >= GET_MODE_ALIGNMENT (mode)));
  361. alignment_in_bits = crtl->stack_alignment_estimated;
  362. alignment = alignment_in_bits / BITS_PER_UNIT;
  363. }
  364. }
  365. }
  366. }
  367. if (crtl->stack_alignment_needed < alignment_in_bits)
  368. crtl->stack_alignment_needed = alignment_in_bits;
  369. if (crtl->max_used_stack_slot_alignment < alignment_in_bits)
  370. crtl->max_used_stack_slot_alignment = alignment_in_bits;
  371. if (mode != BLKmode || size != 0)
  372. {
  373. if (kind & ASLK_RECORD_PAD)
  374. {
  375. struct frame_space **psp;
  376. for (psp = &crtl->frame_space_list; *psp; psp = &(*psp)->next)
  377. {
  378. struct frame_space *space = *psp;
  379. if (!try_fit_stack_local (space->start, space->length, size,
  380. alignment, &slot_offset))
  381. continue;
  382. *psp = space->next;
  383. if (slot_offset > space->start)
  384. add_frame_space (space->start, slot_offset);
  385. if (slot_offset + size < space->start + space->length)
  386. add_frame_space (slot_offset + size,
  387. space->start + space->length);
  388. goto found_space;
  389. }
  390. }
  391. }
  392. else if (!STACK_ALIGNMENT_NEEDED)
  393. {
  394. slot_offset = frame_offset;
  395. goto found_space;
  396. }
  397. old_frame_offset = frame_offset;
  398. if (FRAME_GROWS_DOWNWARD)
  399. {
  400. frame_offset -= size;
  401. try_fit_stack_local (frame_offset, size, size, alignment, &slot_offset);
  402. if (kind & ASLK_RECORD_PAD)
  403. {
  404. if (slot_offset > frame_offset)
  405. add_frame_space (frame_offset, slot_offset);
  406. if (slot_offset + size < old_frame_offset)
  407. add_frame_space (slot_offset + size, old_frame_offset);
  408. }
  409. }
  410. else
  411. {
  412. frame_offset += size;
  413. try_fit_stack_local (old_frame_offset, size, size, alignment, &slot_offset);
  414. if (kind & ASLK_RECORD_PAD)
  415. {
  416. if (slot_offset > old_frame_offset)
  417. add_frame_space (old_frame_offset, slot_offset);
  418. if (slot_offset + size < frame_offset)
  419. add_frame_space (slot_offset + size, frame_offset);
  420. }
  421. }
  422. found_space:
  423. /* On a big-endian machine, if we are allocating more space than we will use,
  424. use the least significant bytes of those that are allocated. */
  425. if (BYTES_BIG_ENDIAN && mode != BLKmode && GET_MODE_SIZE (mode) < size)
  426. bigend_correction = size - GET_MODE_SIZE (mode);
  427. /* If we have already instantiated virtual registers, return the actual
  428. address relative to the frame pointer. */
  429. if (virtuals_instantiated)
  430. addr = plus_constant (Pmode, frame_pointer_rtx,
  431. trunc_int_for_mode
  432. (slot_offset + bigend_correction
  433. + STARTING_FRAME_OFFSET, Pmode));
  434. else
  435. addr = plus_constant (Pmode, virtual_stack_vars_rtx,
  436. trunc_int_for_mode
  437. (slot_offset + bigend_correction,
  438. Pmode));
  439. x = gen_rtx_MEM (mode, addr);
  440. set_mem_align (x, alignment_in_bits);
  441. MEM_NOTRAP_P (x) = 1;
  442. stack_slot_list
  443. = gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list);
  444. if (frame_offset_overflow (frame_offset, current_function_decl))
  445. frame_offset = 0;
  446. return x;
  447. }
  448. /* Wrap up assign_stack_local_1 with last parameter as false. */
  449. rtx
  450. assign_stack_local (machine_mode mode, HOST_WIDE_INT size, int align)
  451. {
  452. return assign_stack_local_1 (mode, size, align, ASLK_RECORD_PAD);
  453. }
  454. /* In order to evaluate some expressions, such as function calls returning
  455. structures in memory, we need to temporarily allocate stack locations.
  456. We record each allocated temporary in the following structure.
  457. Associated with each temporary slot is a nesting level. When we pop up
  458. one level, all temporaries associated with the previous level are freed.
  459. Normally, all temporaries are freed after the execution of the statement
  460. in which they were created. However, if we are inside a ({...}) grouping,
  461. the result may be in a temporary and hence must be preserved. If the
  462. result could be in a temporary, we preserve it if we can determine which
  463. one it is in. If we cannot determine which temporary may contain the
  464. result, all temporaries are preserved. A temporary is preserved by
  465. pretending it was allocated at the previous nesting level. */
  466. struct GTY(()) temp_slot {
  467. /* Points to next temporary slot. */
  468. struct temp_slot *next;
  469. /* Points to previous temporary slot. */
  470. struct temp_slot *prev;
  471. /* The rtx to used to reference the slot. */
  472. rtx slot;
  473. /* The size, in units, of the slot. */
  474. HOST_WIDE_INT size;
  475. /* The type of the object in the slot, or zero if it doesn't correspond
  476. to a type. We use this to determine whether a slot can be reused.
  477. It can be reused if objects of the type of the new slot will always
  478. conflict with objects of the type of the old slot. */
  479. tree type;
  480. /* The alignment (in bits) of the slot. */
  481. unsigned int align;
  482. /* Nonzero if this temporary is currently in use. */
  483. char in_use;
  484. /* Nesting level at which this slot is being used. */
  485. int level;
  486. /* The offset of the slot from the frame_pointer, including extra space
  487. for alignment. This info is for combine_temp_slots. */
  488. HOST_WIDE_INT base_offset;
  489. /* The size of the slot, including extra space for alignment. This
  490. info is for combine_temp_slots. */
  491. HOST_WIDE_INT full_size;
  492. };
  493. /* Entry for the below hash table. */
  494. struct GTY((for_user)) temp_slot_address_entry {
  495. hashval_t hash;
  496. rtx address;
  497. struct temp_slot *temp_slot;
  498. };
  499. struct temp_address_hasher : ggc_hasher<temp_slot_address_entry *>
  500. {
  501. static hashval_t hash (temp_slot_address_entry *);
  502. static bool equal (temp_slot_address_entry *, temp_slot_address_entry *);
  503. };
  504. /* A table of addresses that represent a stack slot. The table is a mapping
  505. from address RTXen to a temp slot. */
  506. static GTY(()) hash_table<temp_address_hasher> *temp_slot_address_table;
  507. static size_t n_temp_slots_in_use;
  508. /* Removes temporary slot TEMP from LIST. */
  509. static void
  510. cut_slot_from_list (struct temp_slot *temp, struct temp_slot **list)
  511. {
  512. if (temp->next)
  513. temp->next->prev = temp->prev;
  514. if (temp->prev)
  515. temp->prev->next = temp->next;
  516. else
  517. *list = temp->next;
  518. temp->prev = temp->next = NULL;
  519. }
  520. /* Inserts temporary slot TEMP to LIST. */
  521. static void
  522. insert_slot_to_list (struct temp_slot *temp, struct temp_slot **list)
  523. {
  524. temp->next = *list;
  525. if (*list)
  526. (*list)->prev = temp;
  527. temp->prev = NULL;
  528. *list = temp;
  529. }
  530. /* Returns the list of used temp slots at LEVEL. */
  531. static struct temp_slot **
  532. temp_slots_at_level (int level)
  533. {
  534. if (level >= (int) vec_safe_length (used_temp_slots))
  535. vec_safe_grow_cleared (used_temp_slots, level + 1);
  536. return &(*used_temp_slots)[level];
  537. }
  538. /* Returns the maximal temporary slot level. */
  539. static int
  540. max_slot_level (void)
  541. {
  542. if (!used_temp_slots)
  543. return -1;
  544. return used_temp_slots->length () - 1;
  545. }
  546. /* Moves temporary slot TEMP to LEVEL. */
  547. static void
  548. move_slot_to_level (struct temp_slot *temp, int level)
  549. {
  550. cut_slot_from_list (temp, temp_slots_at_level (temp->level));
  551. insert_slot_to_list (temp, temp_slots_at_level (level));
  552. temp->level = level;
  553. }
  554. /* Make temporary slot TEMP available. */
  555. static void
  556. make_slot_available (struct temp_slot *temp)
  557. {
  558. cut_slot_from_list (temp, temp_slots_at_level (temp->level));
  559. insert_slot_to_list (temp, &avail_temp_slots);
  560. temp->in_use = 0;
  561. temp->level = -1;
  562. n_temp_slots_in_use--;
  563. }
  564. /* Compute the hash value for an address -> temp slot mapping.
  565. The value is cached on the mapping entry. */
  566. static hashval_t
  567. temp_slot_address_compute_hash (struct temp_slot_address_entry *t)
  568. {
  569. int do_not_record = 0;
  570. return hash_rtx (t->address, GET_MODE (t->address),
  571. &do_not_record, NULL, false);
  572. }
  573. /* Return the hash value for an address -> temp slot mapping. */
  574. hashval_t
  575. temp_address_hasher::hash (temp_slot_address_entry *t)
  576. {
  577. return t->hash;
  578. }
  579. /* Compare two address -> temp slot mapping entries. */
  580. bool
  581. temp_address_hasher::equal (temp_slot_address_entry *t1,
  582. temp_slot_address_entry *t2)
  583. {
  584. return exp_equiv_p (t1->address, t2->address, 0, true);
  585. }
  586. /* Add ADDRESS as an alias of TEMP_SLOT to the addess -> temp slot mapping. */
  587. static void
  588. insert_temp_slot_address (rtx address, struct temp_slot *temp_slot)
  589. {
  590. struct temp_slot_address_entry *t = ggc_alloc<temp_slot_address_entry> ();
  591. t->address = address;
  592. t->temp_slot = temp_slot;
  593. t->hash = temp_slot_address_compute_hash (t);
  594. *temp_slot_address_table->find_slot_with_hash (t, t->hash, INSERT) = t;
  595. }
  596. /* Remove an address -> temp slot mapping entry if the temp slot is
  597. not in use anymore. Callback for remove_unused_temp_slot_addresses. */
  598. int
  599. remove_unused_temp_slot_addresses_1 (temp_slot_address_entry **slot, void *)
  600. {
  601. const struct temp_slot_address_entry *t = *slot;
  602. if (! t->temp_slot->in_use)
  603. temp_slot_address_table->clear_slot (slot);
  604. return 1;
  605. }
  606. /* Remove all mappings of addresses to unused temp slots. */
  607. static void
  608. remove_unused_temp_slot_addresses (void)
  609. {
  610. /* Use quicker clearing if there aren't any active temp slots. */
  611. if (n_temp_slots_in_use)
  612. temp_slot_address_table->traverse
  613. <void *, remove_unused_temp_slot_addresses_1> (NULL);
  614. else
  615. temp_slot_address_table->empty ();
  616. }
  617. /* Find the temp slot corresponding to the object at address X. */
  618. static struct temp_slot *
  619. find_temp_slot_from_address (rtx x)
  620. {
  621. struct temp_slot *p;
  622. struct temp_slot_address_entry tmp, *t;
  623. /* First try the easy way:
  624. See if X exists in the address -> temp slot mapping. */
  625. tmp.address = x;
  626. tmp.temp_slot = NULL;
  627. tmp.hash = temp_slot_address_compute_hash (&tmp);
  628. t = temp_slot_address_table->find_with_hash (&tmp, tmp.hash);
  629. if (t)
  630. return t->temp_slot;
  631. /* If we have a sum involving a register, see if it points to a temp
  632. slot. */
  633. if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
  634. && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
  635. return p;
  636. else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 1))
  637. && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
  638. return p;
  639. /* Last resort: Address is a virtual stack var address. */
  640. if (GET_CODE (x) == PLUS
  641. && XEXP (x, 0) == virtual_stack_vars_rtx
  642. && CONST_INT_P (XEXP (x, 1)))
  643. {
  644. int i;
  645. for (i = max_slot_level (); i >= 0; i--)
  646. for (p = *temp_slots_at_level (i); p; p = p->next)
  647. {
  648. if (INTVAL (XEXP (x, 1)) >= p->base_offset
  649. && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size)
  650. return p;
  651. }
  652. }
  653. return NULL;
  654. }
  655. /* Allocate a temporary stack slot and record it for possible later
  656. reuse.
  657. MODE is the machine mode to be given to the returned rtx.
  658. SIZE is the size in units of the space required. We do no rounding here
  659. since assign_stack_local will do any required rounding.
  660. TYPE is the type that will be used for the stack slot. */
  661. rtx
  662. assign_stack_temp_for_type (machine_mode mode, HOST_WIDE_INT size,
  663. tree type)
  664. {
  665. unsigned int align;
  666. struct temp_slot *p, *best_p = 0, *selected = NULL, **pp;
  667. rtx slot;
  668. /* If SIZE is -1 it means that somebody tried to allocate a temporary
  669. of a variable size. */
  670. gcc_assert (size != -1);
  671. align = get_stack_local_alignment (type, mode);
  672. /* Try to find an available, already-allocated temporary of the proper
  673. mode which meets the size and alignment requirements. Choose the
  674. smallest one with the closest alignment.
  675. If assign_stack_temp is called outside of the tree->rtl expansion,
  676. we cannot reuse the stack slots (that may still refer to
  677. VIRTUAL_STACK_VARS_REGNUM). */
  678. if (!virtuals_instantiated)
  679. {
  680. for (p = avail_temp_slots; p; p = p->next)
  681. {
  682. if (p->align >= align && p->size >= size
  683. && GET_MODE (p->slot) == mode
  684. && objects_must_conflict_p (p->type, type)
  685. && (best_p == 0 || best_p->size > p->size
  686. || (best_p->size == p->size && best_p->align > p->align)))
  687. {
  688. if (p->align == align && p->size == size)
  689. {
  690. selected = p;
  691. cut_slot_from_list (selected, &avail_temp_slots);
  692. best_p = 0;
  693. break;
  694. }
  695. best_p = p;
  696. }
  697. }
  698. }
  699. /* Make our best, if any, the one to use. */
  700. if (best_p)
  701. {
  702. selected = best_p;
  703. cut_slot_from_list (selected, &avail_temp_slots);
  704. /* If there are enough aligned bytes left over, make them into a new
  705. temp_slot so that the extra bytes don't get wasted. Do this only
  706. for BLKmode slots, so that we can be sure of the alignment. */
  707. if (GET_MODE (best_p->slot) == BLKmode)
  708. {
  709. int alignment = best_p->align / BITS_PER_UNIT;
  710. HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
  711. if (best_p->size - rounded_size >= alignment)
  712. {
  713. p = ggc_alloc<temp_slot> ();
  714. p->in_use = 0;
  715. p->size = best_p->size - rounded_size;
  716. p->base_offset = best_p->base_offset + rounded_size;
  717. p->full_size = best_p->full_size - rounded_size;
  718. p->slot = adjust_address_nv (best_p->slot, BLKmode, rounded_size);
  719. p->align = best_p->align;
  720. p->type = best_p->type;
  721. insert_slot_to_list (p, &avail_temp_slots);
  722. stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
  723. stack_slot_list);
  724. best_p->size = rounded_size;
  725. best_p->full_size = rounded_size;
  726. }
  727. }
  728. }
  729. /* If we still didn't find one, make a new temporary. */
  730. if (selected == 0)
  731. {
  732. HOST_WIDE_INT frame_offset_old = frame_offset;
  733. p = ggc_alloc<temp_slot> ();
  734. /* We are passing an explicit alignment request to assign_stack_local.
  735. One side effect of that is assign_stack_local will not round SIZE
  736. to ensure the frame offset remains suitably aligned.
  737. So for requests which depended on the rounding of SIZE, we go ahead
  738. and round it now. We also make sure ALIGNMENT is at least
  739. BIGGEST_ALIGNMENT. */
  740. gcc_assert (mode != BLKmode || align == BIGGEST_ALIGNMENT);
  741. p->slot = assign_stack_local_1 (mode,
  742. (mode == BLKmode
  743. ? CEIL_ROUND (size,
  744. (int) align
  745. / BITS_PER_UNIT)
  746. : size),
  747. align, 0);
  748. p->align = align;
  749. /* The following slot size computation is necessary because we don't
  750. know the actual size of the temporary slot until assign_stack_local
  751. has performed all the frame alignment and size rounding for the
  752. requested temporary. Note that extra space added for alignment
  753. can be either above or below this stack slot depending on which
  754. way the frame grows. We include the extra space if and only if it
  755. is above this slot. */
  756. if (FRAME_GROWS_DOWNWARD)
  757. p->size = frame_offset_old - frame_offset;
  758. else
  759. p->size = size;
  760. /* Now define the fields used by combine_temp_slots. */
  761. if (FRAME_GROWS_DOWNWARD)
  762. {
  763. p->base_offset = frame_offset;
  764. p->full_size = frame_offset_old - frame_offset;
  765. }
  766. else
  767. {
  768. p->base_offset = frame_offset_old;
  769. p->full_size = frame_offset - frame_offset_old;
  770. }
  771. selected = p;
  772. }
  773. p = selected;
  774. p->in_use = 1;
  775. p->type = type;
  776. p->level = temp_slot_level;
  777. n_temp_slots_in_use++;
  778. pp = temp_slots_at_level (p->level);
  779. insert_slot_to_list (p, pp);
  780. insert_temp_slot_address (XEXP (p->slot, 0), p);
  781. /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
  782. slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
  783. stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
  784. /* If we know the alias set for the memory that will be used, use
  785. it. If there's no TYPE, then we don't know anything about the
  786. alias set for the memory. */
  787. set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
  788. set_mem_align (slot, align);
  789. /* If a type is specified, set the relevant flags. */
  790. if (type != 0)
  791. MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
  792. MEM_NOTRAP_P (slot) = 1;
  793. return slot;
  794. }
  795. /* Allocate a temporary stack slot and record it for possible later
  796. reuse. First two arguments are same as in preceding function. */
  797. rtx
  798. assign_stack_temp (machine_mode mode, HOST_WIDE_INT size)
  799. {
  800. return assign_stack_temp_for_type (mode, size, NULL_TREE);
  801. }
  802. /* Assign a temporary.
  803. If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
  804. and so that should be used in error messages. In either case, we
  805. allocate of the given type.
  806. MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
  807. it is 0 if a register is OK.
  808. DONT_PROMOTE is 1 if we should not promote values in register
  809. to wider modes. */
  810. rtx
  811. assign_temp (tree type_or_decl, int memory_required,
  812. int dont_promote ATTRIBUTE_UNUSED)
  813. {
  814. tree type, decl;
  815. machine_mode mode;
  816. #ifdef PROMOTE_MODE
  817. int unsignedp;
  818. #endif
  819. if (DECL_P (type_or_decl))
  820. decl = type_or_decl, type = TREE_TYPE (decl);
  821. else
  822. decl = NULL, type = type_or_decl;
  823. mode = TYPE_MODE (type);
  824. #ifdef PROMOTE_MODE
  825. unsignedp = TYPE_UNSIGNED (type);
  826. #endif
  827. if (mode == BLKmode || memory_required)
  828. {
  829. HOST_WIDE_INT size = int_size_in_bytes (type);
  830. rtx tmp;
  831. /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
  832. problems with allocating the stack space. */
  833. if (size == 0)
  834. size = 1;
  835. /* Unfortunately, we don't yet know how to allocate variable-sized
  836. temporaries. However, sometimes we can find a fixed upper limit on
  837. the size, so try that instead. */
  838. else if (size == -1)
  839. size = max_int_size_in_bytes (type);
  840. /* The size of the temporary may be too large to fit into an integer. */
  841. /* ??? Not sure this should happen except for user silliness, so limit
  842. this to things that aren't compiler-generated temporaries. The
  843. rest of the time we'll die in assign_stack_temp_for_type. */
  844. if (decl && size == -1
  845. && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
  846. {
  847. error ("size of variable %q+D is too large", decl);
  848. size = 1;
  849. }
  850. tmp = assign_stack_temp_for_type (mode, size, type);
  851. return tmp;
  852. }
  853. #ifdef PROMOTE_MODE
  854. if (! dont_promote)
  855. mode = promote_mode (type, mode, &unsignedp);
  856. #endif
  857. return gen_reg_rtx (mode);
  858. }
  859. /* Combine temporary stack slots which are adjacent on the stack.
  860. This allows for better use of already allocated stack space. This is only
  861. done for BLKmode slots because we can be sure that we won't have alignment
  862. problems in this case. */
  863. static void
  864. combine_temp_slots (void)
  865. {
  866. struct temp_slot *p, *q, *next, *next_q;
  867. int num_slots;
  868. /* We can't combine slots, because the information about which slot
  869. is in which alias set will be lost. */
  870. if (flag_strict_aliasing)
  871. return;
  872. /* If there are a lot of temp slots, don't do anything unless
  873. high levels of optimization. */
  874. if (! flag_expensive_optimizations)
  875. for (p = avail_temp_slots, num_slots = 0; p; p = p->next, num_slots++)
  876. if (num_slots > 100 || (num_slots > 10 && optimize == 0))
  877. return;
  878. for (p = avail_temp_slots; p; p = next)
  879. {
  880. int delete_p = 0;
  881. next = p->next;
  882. if (GET_MODE (p->slot) != BLKmode)
  883. continue;
  884. for (q = p->next; q; q = next_q)
  885. {
  886. int delete_q = 0;
  887. next_q = q->next;
  888. if (GET_MODE (q->slot) != BLKmode)
  889. continue;
  890. if (p->base_offset + p->full_size == q->base_offset)
  891. {
  892. /* Q comes after P; combine Q into P. */
  893. p->size += q->size;
  894. p->full_size += q->full_size;
  895. delete_q = 1;
  896. }
  897. else if (q->base_offset + q->full_size == p->base_offset)
  898. {
  899. /* P comes after Q; combine P into Q. */
  900. q->size += p->size;
  901. q->full_size += p->full_size;
  902. delete_p = 1;
  903. break;
  904. }
  905. if (delete_q)
  906. cut_slot_from_list (q, &avail_temp_slots);
  907. }
  908. /* Either delete P or advance past it. */
  909. if (delete_p)
  910. cut_slot_from_list (p, &avail_temp_slots);
  911. }
  912. }
  913. /* Indicate that NEW_RTX is an alternate way of referring to the temp
  914. slot that previously was known by OLD_RTX. */
  915. void
  916. update_temp_slot_address (rtx old_rtx, rtx new_rtx)
  917. {
  918. struct temp_slot *p;
  919. if (rtx_equal_p (old_rtx, new_rtx))
  920. return;
  921. p = find_temp_slot_from_address (old_rtx);
  922. /* If we didn't find one, see if both OLD_RTX is a PLUS. If so, and
  923. NEW_RTX is a register, see if one operand of the PLUS is a
  924. temporary location. If so, NEW_RTX points into it. Otherwise,
  925. if both OLD_RTX and NEW_RTX are a PLUS and if there is a register
  926. in common between them. If so, try a recursive call on those
  927. values. */
  928. if (p == 0)
  929. {
  930. if (GET_CODE (old_rtx) != PLUS)
  931. return;
  932. if (REG_P (new_rtx))
  933. {
  934. update_temp_slot_address (XEXP (old_rtx, 0), new_rtx);
  935. update_temp_slot_address (XEXP (old_rtx, 1), new_rtx);
  936. return;
  937. }
  938. else if (GET_CODE (new_rtx) != PLUS)
  939. return;
  940. if (rtx_equal_p (XEXP (old_rtx, 0), XEXP (new_rtx, 0)))
  941. update_temp_slot_address (XEXP (old_rtx, 1), XEXP (new_rtx, 1));
  942. else if (rtx_equal_p (XEXP (old_rtx, 1), XEXP (new_rtx, 0)))
  943. update_temp_slot_address (XEXP (old_rtx, 0), XEXP (new_rtx, 1));
  944. else if (rtx_equal_p (XEXP (old_rtx, 0), XEXP (new_rtx, 1)))
  945. update_temp_slot_address (XEXP (old_rtx, 1), XEXP (new_rtx, 0));
  946. else if (rtx_equal_p (XEXP (old_rtx, 1), XEXP (new_rtx, 1)))
  947. update_temp_slot_address (XEXP (old_rtx, 0), XEXP (new_rtx, 0));
  948. return;
  949. }
  950. /* Otherwise add an alias for the temp's address. */
  951. insert_temp_slot_address (new_rtx, p);
  952. }
  953. /* If X could be a reference to a temporary slot, mark that slot as
  954. belonging to the to one level higher than the current level. If X
  955. matched one of our slots, just mark that one. Otherwise, we can't
  956. easily predict which it is, so upgrade all of them.
  957. This is called when an ({...}) construct occurs and a statement
  958. returns a value in memory. */
  959. void
  960. preserve_temp_slots (rtx x)
  961. {
  962. struct temp_slot *p = 0, *next;
  963. if (x == 0)
  964. return;
  965. /* If X is a register that is being used as a pointer, see if we have
  966. a temporary slot we know it points to. */
  967. if (REG_P (x) && REG_POINTER (x))
  968. p = find_temp_slot_from_address (x);
  969. /* If X is not in memory or is at a constant address, it cannot be in
  970. a temporary slot. */
  971. if (p == 0 && (!MEM_P (x) || CONSTANT_P (XEXP (x, 0))))
  972. return;
  973. /* First see if we can find a match. */
  974. if (p == 0)
  975. p = find_temp_slot_from_address (XEXP (x, 0));
  976. if (p != 0)
  977. {
  978. if (p->level == temp_slot_level)
  979. move_slot_to_level (p, temp_slot_level - 1);
  980. return;
  981. }
  982. /* Otherwise, preserve all non-kept slots at this level. */
  983. for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
  984. {
  985. next = p->next;
  986. move_slot_to_level (p, temp_slot_level - 1);
  987. }
  988. }
  989. /* Free all temporaries used so far. This is normally called at the
  990. end of generating code for a statement. */
  991. void
  992. free_temp_slots (void)
  993. {
  994. struct temp_slot *p, *next;
  995. bool some_available = false;
  996. for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
  997. {
  998. next = p->next;
  999. make_slot_available (p);
  1000. some_available = true;
  1001. }
  1002. if (some_available)
  1003. {
  1004. remove_unused_temp_slot_addresses ();
  1005. combine_temp_slots ();
  1006. }
  1007. }
  1008. /* Push deeper into the nesting level for stack temporaries. */
  1009. void
  1010. push_temp_slots (void)
  1011. {
  1012. temp_slot_level++;
  1013. }
  1014. /* Pop a temporary nesting level. All slots in use in the current level
  1015. are freed. */
  1016. void
  1017. pop_temp_slots (void)
  1018. {
  1019. free_temp_slots ();
  1020. temp_slot_level--;
  1021. }
  1022. /* Initialize temporary slots. */
  1023. void
  1024. init_temp_slots (void)
  1025. {
  1026. /* We have not allocated any temporaries yet. */
  1027. avail_temp_slots = 0;
  1028. vec_alloc (used_temp_slots, 0);
  1029. temp_slot_level = 0;
  1030. n_temp_slots_in_use = 0;
  1031. /* Set up the table to map addresses to temp slots. */
  1032. if (! temp_slot_address_table)
  1033. temp_slot_address_table = hash_table<temp_address_hasher>::create_ggc (32);
  1034. else
  1035. temp_slot_address_table->empty ();
  1036. }
  1037. /* Functions and data structures to keep track of the values hard regs
  1038. had at the start of the function. */
  1039. /* Private type used by get_hard_reg_initial_reg, get_hard_reg_initial_val,
  1040. and has_hard_reg_initial_val.. */
  1041. typedef struct GTY(()) initial_value_pair {
  1042. rtx hard_reg;
  1043. rtx pseudo;
  1044. } initial_value_pair;
  1045. /* ??? This could be a VEC but there is currently no way to define an
  1046. opaque VEC type. This could be worked around by defining struct
  1047. initial_value_pair in function.h. */
  1048. typedef struct GTY(()) initial_value_struct {
  1049. int num_entries;
  1050. int max_entries;
  1051. initial_value_pair * GTY ((length ("%h.num_entries"))) entries;
  1052. } initial_value_struct;
  1053. /* If a pseudo represents an initial hard reg (or expression), return
  1054. it, else return NULL_RTX. */
  1055. rtx
  1056. get_hard_reg_initial_reg (rtx reg)
  1057. {
  1058. struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
  1059. int i;
  1060. if (ivs == 0)
  1061. return NULL_RTX;
  1062. for (i = 0; i < ivs->num_entries; i++)
  1063. if (rtx_equal_p (ivs->entries[i].pseudo, reg))
  1064. return ivs->entries[i].hard_reg;
  1065. return NULL_RTX;
  1066. }
  1067. /* Make sure that there's a pseudo register of mode MODE that stores the
  1068. initial value of hard register REGNO. Return an rtx for such a pseudo. */
  1069. rtx
  1070. get_hard_reg_initial_val (machine_mode mode, unsigned int regno)
  1071. {
  1072. struct initial_value_struct *ivs;
  1073. rtx rv;
  1074. rv = has_hard_reg_initial_val (mode, regno);
  1075. if (rv)
  1076. return rv;
  1077. ivs = crtl->hard_reg_initial_vals;
  1078. if (ivs == 0)
  1079. {
  1080. ivs = ggc_alloc<initial_value_struct> ();
  1081. ivs->num_entries = 0;
  1082. ivs->max_entries = 5;
  1083. ivs->entries = ggc_vec_alloc<initial_value_pair> (5);
  1084. crtl->hard_reg_initial_vals = ivs;
  1085. }
  1086. if (ivs->num_entries >= ivs->max_entries)
  1087. {
  1088. ivs->max_entries += 5;
  1089. ivs->entries = GGC_RESIZEVEC (initial_value_pair, ivs->entries,
  1090. ivs->max_entries);
  1091. }
  1092. ivs->entries[ivs->num_entries].hard_reg = gen_rtx_REG (mode, regno);
  1093. ivs->entries[ivs->num_entries].pseudo = gen_reg_rtx (mode);
  1094. return ivs->entries[ivs->num_entries++].pseudo;
  1095. }
  1096. /* See if get_hard_reg_initial_val has been used to create a pseudo
  1097. for the initial value of hard register REGNO in mode MODE. Return
  1098. the associated pseudo if so, otherwise return NULL. */
  1099. rtx
  1100. has_hard_reg_initial_val (machine_mode mode, unsigned int regno)
  1101. {
  1102. struct initial_value_struct *ivs;
  1103. int i;
  1104. ivs = crtl->hard_reg_initial_vals;
  1105. if (ivs != 0)
  1106. for (i = 0; i < ivs->num_entries; i++)
  1107. if (GET_MODE (ivs->entries[i].hard_reg) == mode
  1108. && REGNO (ivs->entries[i].hard_reg) == regno)
  1109. return ivs->entries[i].pseudo;
  1110. return NULL_RTX;
  1111. }
  1112. unsigned int
  1113. emit_initial_value_sets (void)
  1114. {
  1115. struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
  1116. int i;
  1117. rtx_insn *seq;
  1118. if (ivs == 0)
  1119. return 0;
  1120. start_sequence ();
  1121. for (i = 0; i < ivs->num_entries; i++)
  1122. emit_move_insn (ivs->entries[i].pseudo, ivs->entries[i].hard_reg);
  1123. seq = get_insns ();
  1124. end_sequence ();
  1125. emit_insn_at_entry (seq);
  1126. return 0;
  1127. }
  1128. /* Return the hardreg-pseudoreg initial values pair entry I and
  1129. TRUE if I is a valid entry, or FALSE if I is not a valid entry. */
  1130. bool
  1131. initial_value_entry (int i, rtx *hreg, rtx *preg)
  1132. {
  1133. struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
  1134. if (!ivs || i >= ivs->num_entries)
  1135. return false;
  1136. *hreg = ivs->entries[i].hard_reg;
  1137. *preg = ivs->entries[i].pseudo;
  1138. return true;
  1139. }
  1140. /* These routines are responsible for converting virtual register references
  1141. to the actual hard register references once RTL generation is complete.
  1142. The following four variables are used for communication between the
  1143. routines. They contain the offsets of the virtual registers from their
  1144. respective hard registers. */
  1145. static int in_arg_offset;
  1146. static int var_offset;
  1147. static int dynamic_offset;
  1148. static int out_arg_offset;
  1149. static int cfa_offset;
  1150. /* In most machines, the stack pointer register is equivalent to the bottom
  1151. of the stack. */
  1152. #ifndef STACK_POINTER_OFFSET
  1153. #define STACK_POINTER_OFFSET 0
  1154. #endif
  1155. #if defined (REG_PARM_STACK_SPACE) && !defined (INCOMING_REG_PARM_STACK_SPACE)
  1156. #define INCOMING_REG_PARM_STACK_SPACE REG_PARM_STACK_SPACE
  1157. #endif
  1158. /* If not defined, pick an appropriate default for the offset of dynamically
  1159. allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
  1160. INCOMING_REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
  1161. #ifndef STACK_DYNAMIC_OFFSET
  1162. /* The bottom of the stack points to the actual arguments. If
  1163. REG_PARM_STACK_SPACE is defined, this includes the space for the register
  1164. parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
  1165. stack space for register parameters is not pushed by the caller, but
  1166. rather part of the fixed stack areas and hence not included in
  1167. `crtl->outgoing_args_size'. Nevertheless, we must allow
  1168. for it when allocating stack dynamic objects. */
  1169. #ifdef INCOMING_REG_PARM_STACK_SPACE
  1170. #define STACK_DYNAMIC_OFFSET(FNDECL) \
  1171. ((ACCUMULATE_OUTGOING_ARGS \
  1172. ? (crtl->outgoing_args_size \
  1173. + (OUTGOING_REG_PARM_STACK_SPACE ((!(FNDECL) ? NULL_TREE : TREE_TYPE (FNDECL))) ? 0 \
  1174. : INCOMING_REG_PARM_STACK_SPACE (FNDECL))) \
  1175. : 0) + (STACK_POINTER_OFFSET))
  1176. #else
  1177. #define STACK_DYNAMIC_OFFSET(FNDECL) \
  1178. ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0) \
  1179. + (STACK_POINTER_OFFSET))
  1180. #endif
  1181. #endif
  1182. /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
  1183. is a virtual register, return the equivalent hard register and set the
  1184. offset indirectly through the pointer. Otherwise, return 0. */
  1185. static rtx
  1186. instantiate_new_reg (rtx x, HOST_WIDE_INT *poffset)
  1187. {
  1188. rtx new_rtx;
  1189. HOST_WIDE_INT offset;
  1190. if (x == virtual_incoming_args_rtx)
  1191. {
  1192. if (stack_realign_drap)
  1193. {
  1194. /* Replace virtual_incoming_args_rtx with internal arg
  1195. pointer if DRAP is used to realign stack. */
  1196. new_rtx = crtl->args.internal_arg_pointer;
  1197. offset = 0;
  1198. }
  1199. else
  1200. new_rtx = arg_pointer_rtx, offset = in_arg_offset;
  1201. }
  1202. else if (x == virtual_stack_vars_rtx)
  1203. new_rtx = frame_pointer_rtx, offset = var_offset;
  1204. else if (x == virtual_stack_dynamic_rtx)
  1205. new_rtx = stack_pointer_rtx, offset = dynamic_offset;
  1206. else if (x == virtual_outgoing_args_rtx)
  1207. new_rtx = stack_pointer_rtx, offset = out_arg_offset;
  1208. else if (x == virtual_cfa_rtx)
  1209. {
  1210. #ifdef FRAME_POINTER_CFA_OFFSET
  1211. new_rtx = frame_pointer_rtx;
  1212. #else
  1213. new_rtx = arg_pointer_rtx;
  1214. #endif
  1215. offset = cfa_offset;
  1216. }
  1217. else if (x == virtual_preferred_stack_boundary_rtx)
  1218. {
  1219. new_rtx = GEN_INT (crtl->preferred_stack_boundary / BITS_PER_UNIT);
  1220. offset = 0;
  1221. }
  1222. else
  1223. return NULL_RTX;
  1224. *poffset = offset;
  1225. return new_rtx;
  1226. }
  1227. /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
  1228. registers present inside of *LOC. The expression is simplified,
  1229. as much as possible, but is not to be considered "valid" in any sense
  1230. implied by the target. Return true if any change is made. */
  1231. static bool
  1232. instantiate_virtual_regs_in_rtx (rtx *loc)
  1233. {
  1234. if (!*loc)
  1235. return false;
  1236. bool changed = false;
  1237. subrtx_ptr_iterator::array_type array;
  1238. FOR_EACH_SUBRTX_PTR (iter, array, loc, NONCONST)
  1239. {
  1240. rtx *loc = *iter;
  1241. if (rtx x = *loc)
  1242. {
  1243. rtx new_rtx;
  1244. HOST_WIDE_INT offset;
  1245. switch (GET_CODE (x))
  1246. {
  1247. case REG:
  1248. new_rtx = instantiate_new_reg (x, &offset);
  1249. if (new_rtx)
  1250. {
  1251. *loc = plus_constant (GET_MODE (x), new_rtx, offset);
  1252. changed = true;
  1253. }
  1254. iter.skip_subrtxes ();
  1255. break;
  1256. case PLUS:
  1257. new_rtx = instantiate_new_reg (XEXP (x, 0), &offset);
  1258. if (new_rtx)
  1259. {
  1260. XEXP (x, 0) = new_rtx;
  1261. *loc = plus_constant (GET_MODE (x), x, offset, true);
  1262. changed = true;
  1263. iter.skip_subrtxes ();
  1264. break;
  1265. }
  1266. /* FIXME -- from old code */
  1267. /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
  1268. we can commute the PLUS and SUBREG because pointers into the
  1269. frame are well-behaved. */
  1270. break;
  1271. default:
  1272. break;
  1273. }
  1274. }
  1275. }
  1276. return changed;
  1277. }
  1278. /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X
  1279. matches the predicate for insn CODE operand OPERAND. */
  1280. static int
  1281. safe_insn_predicate (int code, int operand, rtx x)
  1282. {
  1283. return code < 0 || insn_operand_matches ((enum insn_code) code, operand, x);
  1284. }
  1285. /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
  1286. registers present inside of insn. The result will be a valid insn. */
  1287. static void
  1288. instantiate_virtual_regs_in_insn (rtx_insn *insn)
  1289. {
  1290. HOST_WIDE_INT offset;
  1291. int insn_code, i;
  1292. bool any_change = false;
  1293. rtx set, new_rtx, x;
  1294. rtx_insn *seq;
  1295. /* There are some special cases to be handled first. */
  1296. set = single_set (insn);
  1297. if (set)
  1298. {
  1299. /* We're allowed to assign to a virtual register. This is interpreted
  1300. to mean that the underlying register gets assigned the inverse
  1301. transformation. This is used, for example, in the handling of
  1302. non-local gotos. */
  1303. new_rtx = instantiate_new_reg (SET_DEST (set), &offset);
  1304. if (new_rtx)
  1305. {
  1306. start_sequence ();
  1307. instantiate_virtual_regs_in_rtx (&SET_SRC (set));
  1308. x = simplify_gen_binary (PLUS, GET_MODE (new_rtx), SET_SRC (set),
  1309. gen_int_mode (-offset, GET_MODE (new_rtx)));
  1310. x = force_operand (x, new_rtx);
  1311. if (x != new_rtx)
  1312. emit_move_insn (new_rtx, x);
  1313. seq = get_insns ();
  1314. end_sequence ();
  1315. emit_insn_before (seq, insn);
  1316. delete_insn (insn);
  1317. return;
  1318. }
  1319. /* Handle a straight copy from a virtual register by generating a
  1320. new add insn. The difference between this and falling through
  1321. to the generic case is avoiding a new pseudo and eliminating a
  1322. move insn in the initial rtl stream. */
  1323. new_rtx = instantiate_new_reg (SET_SRC (set), &offset);
  1324. if (new_rtx && offset != 0
  1325. && REG_P (SET_DEST (set))
  1326. && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
  1327. {
  1328. start_sequence ();
  1329. x = expand_simple_binop (GET_MODE (SET_DEST (set)), PLUS, new_rtx,
  1330. gen_int_mode (offset,
  1331. GET_MODE (SET_DEST (set))),
  1332. SET_DEST (set), 1, OPTAB_LIB_WIDEN);
  1333. if (x != SET_DEST (set))
  1334. emit_move_insn (SET_DEST (set), x);
  1335. seq = get_insns ();
  1336. end_sequence ();
  1337. emit_insn_before (seq, insn);
  1338. delete_insn (insn);
  1339. return;
  1340. }
  1341. extract_insn (insn);
  1342. insn_code = INSN_CODE (insn);
  1343. /* Handle a plus involving a virtual register by determining if the
  1344. operands remain valid if they're modified in place. */
  1345. if (GET_CODE (SET_SRC (set)) == PLUS
  1346. && recog_data.n_operands >= 3
  1347. && recog_data.operand_loc[1] == &XEXP (SET_SRC (set), 0)
  1348. && recog_data.operand_loc[2] == &XEXP (SET_SRC (set), 1)
  1349. && CONST_INT_P (recog_data.operand[2])
  1350. && (new_rtx = instantiate_new_reg (recog_data.operand[1], &offset)))
  1351. {
  1352. offset += INTVAL (recog_data.operand[2]);
  1353. /* If the sum is zero, then replace with a plain move. */
  1354. if (offset == 0
  1355. && REG_P (SET_DEST (set))
  1356. && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
  1357. {
  1358. start_sequence ();
  1359. emit_move_insn (SET_DEST (set), new_rtx);
  1360. seq = get_insns ();
  1361. end_sequence ();
  1362. emit_insn_before (seq, insn);
  1363. delete_insn (insn);
  1364. return;
  1365. }
  1366. x = gen_int_mode (offset, recog_data.operand_mode[2]);
  1367. /* Using validate_change and apply_change_group here leaves
  1368. recog_data in an invalid state. Since we know exactly what
  1369. we want to check, do those two by hand. */
  1370. if (safe_insn_predicate (insn_code, 1, new_rtx)
  1371. && safe_insn_predicate (insn_code, 2, x))
  1372. {
  1373. *recog_data.operand_loc[1] = recog_data.operand[1] = new_rtx;
  1374. *recog_data.operand_loc[2] = recog_data.operand[2] = x;
  1375. any_change = true;
  1376. /* Fall through into the regular operand fixup loop in
  1377. order to take care of operands other than 1 and 2. */
  1378. }
  1379. }
  1380. }
  1381. else
  1382. {
  1383. extract_insn (insn);
  1384. insn_code = INSN_CODE (insn);
  1385. }
  1386. /* In the general case, we expect virtual registers to appear only in
  1387. operands, and then only as either bare registers or inside memories. */
  1388. for (i = 0; i < recog_data.n_operands; ++i)
  1389. {
  1390. x = recog_data.operand[i];
  1391. switch (GET_CODE (x))
  1392. {
  1393. case MEM:
  1394. {
  1395. rtx addr = XEXP (x, 0);
  1396. if (!instantiate_virtual_regs_in_rtx (&addr))
  1397. continue;
  1398. start_sequence ();
  1399. x = replace_equiv_address (x, addr, true);
  1400. /* It may happen that the address with the virtual reg
  1401. was valid (e.g. based on the virtual stack reg, which might
  1402. be acceptable to the predicates with all offsets), whereas
  1403. the address now isn't anymore, for instance when the address
  1404. is still offsetted, but the base reg isn't virtual-stack-reg
  1405. anymore. Below we would do a force_reg on the whole operand,
  1406. but this insn might actually only accept memory. Hence,
  1407. before doing that last resort, try to reload the address into
  1408. a register, so this operand stays a MEM. */
  1409. if (!safe_insn_predicate (insn_code, i, x))
  1410. {
  1411. addr = force_reg (GET_MODE (addr), addr);
  1412. x = replace_equiv_address (x, addr, true);
  1413. }
  1414. seq = get_insns ();
  1415. end_sequence ();
  1416. if (seq)
  1417. emit_insn_before (seq, insn);
  1418. }
  1419. break;
  1420. case REG:
  1421. new_rtx = instantiate_new_reg (x, &offset);
  1422. if (new_rtx == NULL)
  1423. continue;
  1424. if (offset == 0)
  1425. x = new_rtx;
  1426. else
  1427. {
  1428. start_sequence ();
  1429. /* Careful, special mode predicates may have stuff in
  1430. insn_data[insn_code].operand[i].mode that isn't useful
  1431. to us for computing a new value. */
  1432. /* ??? Recognize address_operand and/or "p" constraints
  1433. to see if (plus new offset) is a valid before we put
  1434. this through expand_simple_binop. */
  1435. x = expand_simple_binop (GET_MODE (x), PLUS, new_rtx,
  1436. gen_int_mode (offset, GET_MODE (x)),
  1437. NULL_RTX, 1, OPTAB_LIB_WIDEN);
  1438. seq = get_insns ();
  1439. end_sequence ();
  1440. emit_insn_before (seq, insn);
  1441. }
  1442. break;
  1443. case SUBREG:
  1444. new_rtx = instantiate_new_reg (SUBREG_REG (x), &offset);
  1445. if (new_rtx == NULL)
  1446. continue;
  1447. if (offset != 0)
  1448. {
  1449. start_sequence ();
  1450. new_rtx = expand_simple_binop
  1451. (GET_MODE (new_rtx), PLUS, new_rtx,
  1452. gen_int_mode (offset, GET_MODE (new_rtx)),
  1453. NULL_RTX, 1, OPTAB_LIB_WIDEN);
  1454. seq = get_insns ();
  1455. end_sequence ();
  1456. emit_insn_before (seq, insn);
  1457. }
  1458. x = simplify_gen_subreg (recog_data.operand_mode[i], new_rtx,
  1459. GET_MODE (new_rtx), SUBREG_BYTE (x));
  1460. gcc_assert (x);
  1461. break;
  1462. default:
  1463. continue;
  1464. }
  1465. /* At this point, X contains the new value for the operand.
  1466. Validate the new value vs the insn predicate. Note that
  1467. asm insns will have insn_code -1 here. */
  1468. if (!safe_insn_predicate (insn_code, i, x))
  1469. {
  1470. start_sequence ();
  1471. if (REG_P (x))
  1472. {
  1473. gcc_assert (REGNO (x) <= LAST_VIRTUAL_REGISTER);
  1474. x = copy_to_reg (x);
  1475. }
  1476. else
  1477. x = force_reg (insn_data[insn_code].operand[i].mode, x);
  1478. seq = get_insns ();
  1479. end_sequence ();
  1480. if (seq)
  1481. emit_insn_before (seq, insn);
  1482. }
  1483. *recog_data.operand_loc[i] = recog_data.operand[i] = x;
  1484. any_change = true;
  1485. }
  1486. if (any_change)
  1487. {
  1488. /* Propagate operand changes into the duplicates. */
  1489. for (i = 0; i < recog_data.n_dups; ++i)
  1490. *recog_data.dup_loc[i]
  1491. = copy_rtx (recog_data.operand[(unsigned)recog_data.dup_num[i]]);
  1492. /* Force re-recognition of the instruction for validation. */
  1493. INSN_CODE (insn) = -1;
  1494. }
  1495. if (asm_noperands (PATTERN (insn)) >= 0)
  1496. {
  1497. if (!check_asm_operands (PATTERN (insn)))
  1498. {
  1499. error_for_asm (insn, "impossible constraint in %<asm%>");
  1500. /* For asm goto, instead of fixing up all the edges
  1501. just clear the template and clear input operands
  1502. (asm goto doesn't have any output operands). */
  1503. if (JUMP_P (insn))
  1504. {
  1505. rtx asm_op = extract_asm_operands (PATTERN (insn));
  1506. ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup ("");
  1507. ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0);
  1508. ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0);
  1509. }
  1510. else
  1511. delete_insn (insn);
  1512. }
  1513. }
  1514. else
  1515. {
  1516. if (recog_memoized (insn) < 0)
  1517. fatal_insn_not_found (insn);
  1518. }
  1519. }
  1520. /* Subroutine of instantiate_decls. Given RTL representing a decl,
  1521. do any instantiation required. */
  1522. void
  1523. instantiate_decl_rtl (rtx x)
  1524. {
  1525. rtx addr;
  1526. if (x == 0)
  1527. return;
  1528. /* If this is a CONCAT, recurse for the pieces. */
  1529. if (GET_CODE (x) == CONCAT)
  1530. {
  1531. instantiate_decl_rtl (XEXP (x, 0));
  1532. instantiate_decl_rtl (XEXP (x, 1));
  1533. return;
  1534. }
  1535. /* If this is not a MEM, no need to do anything. Similarly if the
  1536. address is a constant or a register that is not a virtual register. */
  1537. if (!MEM_P (x))
  1538. return;
  1539. addr = XEXP (x, 0);
  1540. if (CONSTANT_P (addr)
  1541. || (REG_P (addr)
  1542. && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
  1543. || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
  1544. return;
  1545. instantiate_virtual_regs_in_rtx (&XEXP (x, 0));
  1546. }
  1547. /* Helper for instantiate_decls called via walk_tree: Process all decls
  1548. in the given DECL_VALUE_EXPR. */
  1549. static tree
  1550. instantiate_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
  1551. {
  1552. tree t = *tp;
  1553. if (! EXPR_P (t))
  1554. {
  1555. *walk_subtrees = 0;
  1556. if (DECL_P (t))
  1557. {
  1558. if (DECL_RTL_SET_P (t))
  1559. instantiate_decl_rtl (DECL_RTL (t));
  1560. if (TREE_CODE (t) == PARM_DECL && DECL_NAMELESS (t)
  1561. && DECL_INCOMING_RTL (t))
  1562. instantiate_decl_rtl (DECL_INCOMING_RTL (t));
  1563. if ((TREE_CODE (t) == VAR_DECL
  1564. || TREE_CODE (t) == RESULT_DECL)
  1565. && DECL_HAS_VALUE_EXPR_P (t))
  1566. {
  1567. tree v = DECL_VALUE_EXPR (t);
  1568. walk_tree (&v, instantiate_expr, NULL, NULL);
  1569. }
  1570. }
  1571. }
  1572. return NULL;
  1573. }
  1574. /* Subroutine of instantiate_decls: Process all decls in the given
  1575. BLOCK node and all its subblocks. */
  1576. static void
  1577. instantiate_decls_1 (tree let)
  1578. {
  1579. tree t;
  1580. for (t = BLOCK_VARS (let); t; t = DECL_CHAIN (t))
  1581. {
  1582. if (DECL_RTL_SET_P (t))
  1583. instantiate_decl_rtl (DECL_RTL (t));
  1584. if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
  1585. {
  1586. tree v = DECL_VALUE_EXPR (t);
  1587. walk_tree (&v, instantiate_expr, NULL, NULL);
  1588. }
  1589. }
  1590. /* Process all subblocks. */
  1591. for (t = BLOCK_SUBBLOCKS (let); t; t = BLOCK_CHAIN (t))
  1592. instantiate_decls_1 (t);
  1593. }
  1594. /* Scan all decls in FNDECL (both variables and parameters) and instantiate
  1595. all virtual registers in their DECL_RTL's. */
  1596. static void
  1597. instantiate_decls (tree fndecl)
  1598. {
  1599. tree decl;
  1600. unsigned ix;
  1601. /* Process all parameters of the function. */
  1602. for (decl = DECL_ARGUMENTS (fndecl); decl; decl = DECL_CHAIN (decl))
  1603. {
  1604. instantiate_decl_rtl (DECL_RTL (decl));
  1605. instantiate_decl_rtl (DECL_INCOMING_RTL (decl));
  1606. if (DECL_HAS_VALUE_EXPR_P (decl))
  1607. {
  1608. tree v = DECL_VALUE_EXPR (decl);
  1609. walk_tree (&v, instantiate_expr, NULL, NULL);
  1610. }
  1611. }
  1612. if ((decl = DECL_RESULT (fndecl))
  1613. && TREE_CODE (decl) == RESULT_DECL)
  1614. {
  1615. if (DECL_RTL_SET_P (decl))
  1616. instantiate_decl_rtl (DECL_RTL (decl));
  1617. if (DECL_HAS_VALUE_EXPR_P (decl))
  1618. {
  1619. tree v = DECL_VALUE_EXPR (decl);
  1620. walk_tree (&v, instantiate_expr, NULL, NULL);
  1621. }
  1622. }
  1623. /* Process the saved static chain if it exists. */
  1624. decl = DECL_STRUCT_FUNCTION (fndecl)->static_chain_decl;
  1625. if (decl && DECL_HAS_VALUE_EXPR_P (decl))
  1626. instantiate_decl_rtl (DECL_RTL (DECL_VALUE_EXPR (decl)));
  1627. /* Now process all variables defined in the function or its subblocks. */
  1628. instantiate_decls_1 (DECL_INITIAL (fndecl));
  1629. FOR_EACH_LOCAL_DECL (cfun, ix, decl)
  1630. if (DECL_RTL_SET_P (decl))
  1631. instantiate_decl_rtl (DECL_RTL (decl));
  1632. vec_free (cfun->local_decls);
  1633. }
  1634. /* Pass through the INSNS of function FNDECL and convert virtual register
  1635. references to hard register references. */
  1636. static unsigned int
  1637. instantiate_virtual_regs (void)
  1638. {
  1639. rtx_insn *insn;
  1640. /* Compute the offsets to use for this function. */
  1641. in_arg_offset = FIRST_PARM_OFFSET (current_function_decl);
  1642. var_offset = STARTING_FRAME_OFFSET;
  1643. dynamic_offset = STACK_DYNAMIC_OFFSET (current_function_decl);
  1644. out_arg_offset = STACK_POINTER_OFFSET;
  1645. #ifdef FRAME_POINTER_CFA_OFFSET
  1646. cfa_offset = FRAME_POINTER_CFA_OFFSET (current_function_decl);
  1647. #else
  1648. cfa_offset = ARG_POINTER_CFA_OFFSET (current_function_decl);
  1649. #endif
  1650. /* Initialize recognition, indicating that volatile is OK. */
  1651. init_recog ();
  1652. /* Scan through all the insns, instantiating every virtual register still
  1653. present. */
  1654. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  1655. if (INSN_P (insn))
  1656. {
  1657. /* These patterns in the instruction stream can never be recognized.
  1658. Fortunately, they shouldn't contain virtual registers either. */
  1659. if (GET_CODE (PATTERN (insn)) == USE
  1660. || GET_CODE (PATTERN (insn)) == CLOBBER
  1661. || GET_CODE (PATTERN (insn)) == ASM_INPUT)
  1662. continue;
  1663. else if (DEBUG_INSN_P (insn))
  1664. instantiate_virtual_regs_in_rtx (&INSN_VAR_LOCATION (insn));
  1665. else
  1666. instantiate_virtual_regs_in_insn (insn);
  1667. if (insn->deleted ())
  1668. continue;
  1669. instantiate_virtual_regs_in_rtx (&REG_NOTES (insn));
  1670. /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
  1671. if (CALL_P (insn))
  1672. instantiate_virtual_regs_in_rtx (&CALL_INSN_FUNCTION_USAGE (insn));
  1673. }
  1674. /* Instantiate the virtual registers in the DECLs for debugging purposes. */
  1675. instantiate_decls (current_function_decl);
  1676. targetm.instantiate_decls ();
  1677. /* Indicate that, from now on, assign_stack_local should use
  1678. frame_pointer_rtx. */
  1679. virtuals_instantiated = 1;
  1680. return 0;
  1681. }
  1682. namespace {
  1683. const pass_data pass_data_instantiate_virtual_regs =
  1684. {
  1685. RTL_PASS, /* type */
  1686. "vregs", /* name */
  1687. OPTGROUP_NONE, /* optinfo_flags */
  1688. TV_NONE, /* tv_id */
  1689. 0, /* properties_required */
  1690. 0, /* properties_provided */
  1691. 0, /* properties_destroyed */
  1692. 0, /* todo_flags_start */
  1693. 0, /* todo_flags_finish */
  1694. };
  1695. class pass_instantiate_virtual_regs : public rtl_opt_pass
  1696. {
  1697. public:
  1698. pass_instantiate_virtual_regs (gcc::context *ctxt)
  1699. : rtl_opt_pass (pass_data_instantiate_virtual_regs, ctxt)
  1700. {}
  1701. /* opt_pass methods: */
  1702. virtual unsigned int execute (function *)
  1703. {
  1704. return instantiate_virtual_regs ();
  1705. }
  1706. }; // class pass_instantiate_virtual_regs
  1707. } // anon namespace
  1708. rtl_opt_pass *
  1709. make_pass_instantiate_virtual_regs (gcc::context *ctxt)
  1710. {
  1711. return new pass_instantiate_virtual_regs (ctxt);
  1712. }
  1713. /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
  1714. This means a type for which function calls must pass an address to the
  1715. function or get an address back from the function.
  1716. EXP may be a type node or an expression (whose type is tested). */
  1717. int
  1718. aggregate_value_p (const_tree exp, const_tree fntype)
  1719. {
  1720. const_tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
  1721. int i, regno, nregs;
  1722. rtx reg;
  1723. if (fntype)
  1724. switch (TREE_CODE (fntype))
  1725. {
  1726. case CALL_EXPR:
  1727. {
  1728. tree fndecl = get_callee_fndecl (fntype);
  1729. if (fndecl)
  1730. fntype = TREE_TYPE (fndecl);
  1731. else if (CALL_EXPR_FN (fntype))
  1732. fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (fntype)));
  1733. else
  1734. /* For internal functions, assume nothing needs to be
  1735. returned in memory. */
  1736. return 0;
  1737. }
  1738. break;
  1739. case FUNCTION_DECL:
  1740. fntype = TREE_TYPE (fntype);
  1741. break;
  1742. case FUNCTION_TYPE:
  1743. case METHOD_TYPE:
  1744. break;
  1745. case IDENTIFIER_NODE:
  1746. fntype = NULL_TREE;
  1747. break;
  1748. default:
  1749. /* We don't expect other tree types here. */
  1750. gcc_unreachable ();
  1751. }
  1752. if (VOID_TYPE_P (type))
  1753. return 0;
  1754. /* If a record should be passed the same as its first (and only) member
  1755. don't pass it as an aggregate. */
  1756. if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
  1757. return aggregate_value_p (first_field (type), fntype);
  1758. /* If the front end has decided that this needs to be passed by
  1759. reference, do so. */
  1760. if ((TREE_CODE (exp) == PARM_DECL || TREE_CODE (exp) == RESULT_DECL)
  1761. && DECL_BY_REFERENCE (exp))
  1762. return 1;
  1763. /* Function types that are TREE_ADDRESSABLE force return in memory. */
  1764. if (fntype && TREE_ADDRESSABLE (fntype))
  1765. return 1;
  1766. /* Types that are TREE_ADDRESSABLE must be constructed in memory,
  1767. and thus can't be returned in registers. */
  1768. if (TREE_ADDRESSABLE (type))
  1769. return 1;
  1770. if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
  1771. return 1;
  1772. if (targetm.calls.return_in_memory (type, fntype))
  1773. return 1;
  1774. /* Make sure we have suitable call-clobbered regs to return
  1775. the value in; if not, we must return it in memory. */
  1776. reg = hard_function_value (type, 0, fntype, 0);
  1777. /* If we have something other than a REG (e.g. a PARALLEL), then assume
  1778. it is OK. */
  1779. if (!REG_P (reg))
  1780. return 0;
  1781. regno = REGNO (reg);
  1782. nregs = hard_regno_nregs[regno][TYPE_MODE (type)];
  1783. for (i = 0; i < nregs; i++)
  1784. if (! call_used_regs[regno + i])
  1785. return 1;
  1786. return 0;
  1787. }
  1788. /* Return true if we should assign DECL a pseudo register; false if it
  1789. should live on the local stack. */
  1790. bool
  1791. use_register_for_decl (const_tree decl)
  1792. {
  1793. if (!targetm.calls.allocate_stack_slots_for_args ())
  1794. return true;
  1795. /* Honor volatile. */
  1796. if (TREE_SIDE_EFFECTS (decl))
  1797. return false;
  1798. /* Honor addressability. */
  1799. if (TREE_ADDRESSABLE (decl))
  1800. return false;
  1801. /* Decl is implicitly addressible by bound stores and loads
  1802. if it is an aggregate holding bounds. */
  1803. if (chkp_function_instrumented_p (current_function_decl)
  1804. && TREE_TYPE (decl)
  1805. && !BOUNDED_P (decl)
  1806. && chkp_type_has_pointer (TREE_TYPE (decl)))
  1807. return false;
  1808. /* Only register-like things go in registers. */
  1809. if (DECL_MODE (decl) == BLKmode)
  1810. return false;
  1811. /* If -ffloat-store specified, don't put explicit float variables
  1812. into registers. */
  1813. /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
  1814. propagates values across these stores, and it probably shouldn't. */
  1815. if (flag_float_store && FLOAT_TYPE_P (TREE_TYPE (decl)))
  1816. return false;
  1817. /* If we're not interested in tracking debugging information for
  1818. this decl, then we can certainly put it in a register. */
  1819. if (DECL_IGNORED_P (decl))
  1820. return true;
  1821. if (optimize)
  1822. return true;
  1823. if (!DECL_REGISTER (decl))
  1824. return false;
  1825. switch (TREE_CODE (TREE_TYPE (decl)))
  1826. {
  1827. case RECORD_TYPE:
  1828. case UNION_TYPE:
  1829. case QUAL_UNION_TYPE:
  1830. /* When not optimizing, disregard register keyword for variables with
  1831. types containing methods, otherwise the methods won't be callable
  1832. from the debugger. */
  1833. if (TYPE_METHODS (TREE_TYPE (decl)))
  1834. return false;
  1835. break;
  1836. default:
  1837. break;
  1838. }
  1839. return true;
  1840. }
  1841. /* Return true if TYPE should be passed by invisible reference. */
  1842. bool
  1843. pass_by_reference (CUMULATIVE_ARGS *ca, machine_mode mode,
  1844. tree type, bool named_arg)
  1845. {
  1846. if (type)
  1847. {
  1848. /* If this type contains non-trivial constructors, then it is
  1849. forbidden for the middle-end to create any new copies. */
  1850. if (TREE_ADDRESSABLE (type))
  1851. return true;
  1852. /* GCC post 3.4 passes *all* variable sized types by reference. */
  1853. if (!TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  1854. return true;
  1855. /* If a record type should be passed the same as its first (and only)
  1856. member, use the type and mode of that member. */
  1857. if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
  1858. {
  1859. type = TREE_TYPE (first_field (type));
  1860. mode = TYPE_MODE (type);
  1861. }
  1862. }
  1863. return targetm.calls.pass_by_reference (pack_cumulative_args (ca), mode,
  1864. type, named_arg);
  1865. }
  1866. /* Return true if TYPE, which is passed by reference, should be callee
  1867. copied instead of caller copied. */
  1868. bool
  1869. reference_callee_copied (CUMULATIVE_ARGS *ca, machine_mode mode,
  1870. tree type, bool named_arg)
  1871. {
  1872. if (type && TREE_ADDRESSABLE (type))
  1873. return false;
  1874. return targetm.calls.callee_copies (pack_cumulative_args (ca), mode, type,
  1875. named_arg);
  1876. }
  1877. /* Structures to communicate between the subroutines of assign_parms.
  1878. The first holds data persistent across all parameters, the second
  1879. is cleared out for each parameter. */
  1880. struct assign_parm_data_all
  1881. {
  1882. /* When INIT_CUMULATIVE_ARGS gets revamped, allocating CUMULATIVE_ARGS
  1883. should become a job of the target or otherwise encapsulated. */
  1884. CUMULATIVE_ARGS args_so_far_v;
  1885. cumulative_args_t args_so_far;
  1886. struct args_size stack_args_size;
  1887. tree function_result_decl;
  1888. tree orig_fnargs;
  1889. rtx_insn *first_conversion_insn;
  1890. rtx_insn *last_conversion_insn;
  1891. HOST_WIDE_INT pretend_args_size;
  1892. HOST_WIDE_INT extra_pretend_bytes;
  1893. int reg_parm_stack_space;
  1894. };
  1895. struct assign_parm_data_one
  1896. {
  1897. tree nominal_type;
  1898. tree passed_type;
  1899. rtx entry_parm;
  1900. rtx stack_parm;
  1901. machine_mode nominal_mode;
  1902. machine_mode passed_mode;
  1903. machine_mode promoted_mode;
  1904. struct locate_and_pad_arg_data locate;
  1905. int partial;
  1906. BOOL_BITFIELD named_arg : 1;
  1907. BOOL_BITFIELD passed_pointer : 1;
  1908. BOOL_BITFIELD on_stack : 1;
  1909. BOOL_BITFIELD loaded_in_reg : 1;
  1910. };
  1911. struct bounds_parm_data
  1912. {
  1913. assign_parm_data_one parm_data;
  1914. tree bounds_parm;
  1915. tree ptr_parm;
  1916. rtx ptr_entry;
  1917. int bound_no;
  1918. };
  1919. /* A subroutine of assign_parms. Initialize ALL. */
  1920. static void
  1921. assign_parms_initialize_all (struct assign_parm_data_all *all)
  1922. {
  1923. tree fntype ATTRIBUTE_UNUSED;
  1924. memset (all, 0, sizeof (*all));
  1925. fntype = TREE_TYPE (current_function_decl);
  1926. #ifdef INIT_CUMULATIVE_INCOMING_ARGS
  1927. INIT_CUMULATIVE_INCOMING_ARGS (all->args_so_far_v, fntype, NULL_RTX);
  1928. #else
  1929. INIT_CUMULATIVE_ARGS (all->args_so_far_v, fntype, NULL_RTX,
  1930. current_function_decl, -1);
  1931. #endif
  1932. all->args_so_far = pack_cumulative_args (&all->args_so_far_v);
  1933. #ifdef INCOMING_REG_PARM_STACK_SPACE
  1934. all->reg_parm_stack_space
  1935. = INCOMING_REG_PARM_STACK_SPACE (current_function_decl);
  1936. #endif
  1937. }
  1938. /* If ARGS contains entries with complex types, split the entry into two
  1939. entries of the component type. Return a new list of substitutions are
  1940. needed, else the old list. */
  1941. static void
  1942. split_complex_args (vec<tree> *args)
  1943. {
  1944. unsigned i;
  1945. tree p;
  1946. FOR_EACH_VEC_ELT (*args, i, p)
  1947. {
  1948. tree type = TREE_TYPE (p);
  1949. if (TREE_CODE (type) == COMPLEX_TYPE
  1950. && targetm.calls.split_complex_arg (type))
  1951. {
  1952. tree decl;
  1953. tree subtype = TREE_TYPE (type);
  1954. bool addressable = TREE_ADDRESSABLE (p);
  1955. /* Rewrite the PARM_DECL's type with its component. */
  1956. p = copy_node (p);
  1957. TREE_TYPE (p) = subtype;
  1958. DECL_ARG_TYPE (p) = TREE_TYPE (DECL_ARG_TYPE (p));
  1959. DECL_MODE (p) = VOIDmode;
  1960. DECL_SIZE (p) = NULL;
  1961. DECL_SIZE_UNIT (p) = NULL;
  1962. /* If this arg must go in memory, put it in a pseudo here.
  1963. We can't allow it to go in memory as per normal parms,
  1964. because the usual place might not have the imag part
  1965. adjacent to the real part. */
  1966. DECL_ARTIFICIAL (p) = addressable;
  1967. DECL_IGNORED_P (p) = addressable;
  1968. TREE_ADDRESSABLE (p) = 0;
  1969. layout_decl (p, 0);
  1970. (*args)[i] = p;
  1971. /* Build a second synthetic decl. */
  1972. decl = build_decl (EXPR_LOCATION (p),
  1973. PARM_DECL, NULL_TREE, subtype);
  1974. DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (p);
  1975. DECL_ARTIFICIAL (decl) = addressable;
  1976. DECL_IGNORED_P (decl) = addressable;
  1977. layout_decl (decl, 0);
  1978. args->safe_insert (++i, decl);
  1979. }
  1980. }
  1981. }
  1982. /* A subroutine of assign_parms. Adjust the parameter list to incorporate
  1983. the hidden struct return argument, and (abi willing) complex args.
  1984. Return the new parameter list. */
  1985. static vec<tree>
  1986. assign_parms_augmented_arg_list (struct assign_parm_data_all *all)
  1987. {
  1988. tree fndecl = current_function_decl;
  1989. tree fntype = TREE_TYPE (fndecl);
  1990. vec<tree> fnargs = vNULL;
  1991. tree arg;
  1992. for (arg = DECL_ARGUMENTS (fndecl); arg; arg = DECL_CHAIN (arg))
  1993. fnargs.safe_push (arg);
  1994. all->orig_fnargs = DECL_ARGUMENTS (fndecl);
  1995. /* If struct value address is treated as the first argument, make it so. */
  1996. if (aggregate_value_p (DECL_RESULT (fndecl), fndecl)
  1997. && ! cfun->returns_pcc_struct
  1998. && targetm.calls.struct_value_rtx (TREE_TYPE (fndecl), 1) == 0)
  1999. {
  2000. tree type = build_pointer_type (TREE_TYPE (fntype));
  2001. tree decl;
  2002. decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
  2003. PARM_DECL, get_identifier (".result_ptr"), type);
  2004. DECL_ARG_TYPE (decl) = type;
  2005. DECL_ARTIFICIAL (decl) = 1;
  2006. DECL_NAMELESS (decl) = 1;
  2007. TREE_CONSTANT (decl) = 1;
  2008. DECL_CHAIN (decl) = all->orig_fnargs;
  2009. all->orig_fnargs = decl;
  2010. fnargs.safe_insert (0, decl);
  2011. all->function_result_decl = decl;
  2012. /* If function is instrumented then bounds of the
  2013. passed structure address is the second argument. */
  2014. if (chkp_function_instrumented_p (fndecl))
  2015. {
  2016. decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
  2017. PARM_DECL, get_identifier (".result_bnd"),
  2018. pointer_bounds_type_node);
  2019. DECL_ARG_TYPE (decl) = pointer_bounds_type_node;
  2020. DECL_ARTIFICIAL (decl) = 1;
  2021. DECL_NAMELESS (decl) = 1;
  2022. TREE_CONSTANT (decl) = 1;
  2023. DECL_CHAIN (decl) = DECL_CHAIN (all->orig_fnargs);
  2024. DECL_CHAIN (all->orig_fnargs) = decl;
  2025. fnargs.safe_insert (1, decl);
  2026. }
  2027. }
  2028. /* If the target wants to split complex arguments into scalars, do so. */
  2029. if (targetm.calls.split_complex_arg)
  2030. split_complex_args (&fnargs);
  2031. return fnargs;
  2032. }
  2033. /* A subroutine of assign_parms. Examine PARM and pull out type and mode
  2034. data for the parameter. Incorporate ABI specifics such as pass-by-
  2035. reference and type promotion. */
  2036. static void
  2037. assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm,
  2038. struct assign_parm_data_one *data)
  2039. {
  2040. tree nominal_type, passed_type;
  2041. machine_mode nominal_mode, passed_mode, promoted_mode;
  2042. int unsignedp;
  2043. memset (data, 0, sizeof (*data));
  2044. /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */
  2045. if (!cfun->stdarg)
  2046. data->named_arg = 1; /* No variadic parms. */
  2047. else if (DECL_CHAIN (parm))
  2048. data->named_arg = 1; /* Not the last non-variadic parm. */
  2049. else if (targetm.calls.strict_argument_naming (all->args_so_far))
  2050. data->named_arg = 1; /* Only variadic ones are unnamed. */
  2051. else
  2052. data->named_arg = 0; /* Treat as variadic. */
  2053. nominal_type = TREE_TYPE (parm);
  2054. passed_type = DECL_ARG_TYPE (parm);
  2055. /* Look out for errors propagating this far. Also, if the parameter's
  2056. type is void then its value doesn't matter. */
  2057. if (TREE_TYPE (parm) == error_mark_node
  2058. /* This can happen after weird syntax errors
  2059. or if an enum type is defined among the parms. */
  2060. || TREE_CODE (parm) != PARM_DECL
  2061. || passed_type == NULL
  2062. || VOID_TYPE_P (nominal_type))
  2063. {
  2064. nominal_type = passed_type = void_type_node;
  2065. nominal_mode = passed_mode = promoted_mode = VOIDmode;
  2066. goto egress;
  2067. }
  2068. /* Find mode of arg as it is passed, and mode of arg as it should be
  2069. during execution of this function. */
  2070. passed_mode = TYPE_MODE (passed_type);
  2071. nominal_mode = TYPE_MODE (nominal_type);
  2072. /* If the parm is to be passed as a transparent union or record, use the
  2073. type of the first field for the tests below. We have already verified
  2074. that the modes are the same. */
  2075. if ((TREE_CODE (passed_type) == UNION_TYPE
  2076. || TREE_CODE (passed_type) == RECORD_TYPE)
  2077. && TYPE_TRANSPARENT_AGGR (passed_type))
  2078. passed_type = TREE_TYPE (first_field (passed_type));
  2079. /* See if this arg was passed by invisible reference. */
  2080. if (pass_by_reference (&all->args_so_far_v, passed_mode,
  2081. passed_type, data->named_arg))
  2082. {
  2083. passed_type = nominal_type = build_pointer_type (passed_type);
  2084. data->passed_pointer = true;
  2085. passed_mode = nominal_mode = TYPE_MODE (nominal_type);
  2086. }
  2087. /* Find mode as it is passed by the ABI. */
  2088. unsignedp = TYPE_UNSIGNED (passed_type);
  2089. promoted_mode = promote_function_mode (passed_type, passed_mode, &unsignedp,
  2090. TREE_TYPE (current_function_decl), 0);
  2091. egress:
  2092. data->nominal_type = nominal_type;
  2093. data->passed_type = passed_type;
  2094. data->nominal_mode = nominal_mode;
  2095. data->passed_mode = passed_mode;
  2096. data->promoted_mode = promoted_mode;
  2097. }
  2098. /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */
  2099. static void
  2100. assign_parms_setup_varargs (struct assign_parm_data_all *all,
  2101. struct assign_parm_data_one *data, bool no_rtl)
  2102. {
  2103. int varargs_pretend_bytes = 0;
  2104. targetm.calls.setup_incoming_varargs (all->args_so_far,
  2105. data->promoted_mode,
  2106. data->passed_type,
  2107. &varargs_pretend_bytes, no_rtl);
  2108. /* If the back-end has requested extra stack space, record how much is
  2109. needed. Do not change pretend_args_size otherwise since it may be
  2110. nonzero from an earlier partial argument. */
  2111. if (varargs_pretend_bytes > 0)
  2112. all->pretend_args_size = varargs_pretend_bytes;
  2113. }
  2114. /* A subroutine of assign_parms. Set DATA->ENTRY_PARM corresponding to
  2115. the incoming location of the current parameter. */
  2116. static void
  2117. assign_parm_find_entry_rtl (struct assign_parm_data_all *all,
  2118. struct assign_parm_data_one *data)
  2119. {
  2120. HOST_WIDE_INT pretend_bytes = 0;
  2121. rtx entry_parm;
  2122. bool in_regs;
  2123. if (data->promoted_mode == VOIDmode)
  2124. {
  2125. data->entry_parm = data->stack_parm = const0_rtx;
  2126. return;
  2127. }
  2128. entry_parm = targetm.calls.function_incoming_arg (all->args_so_far,
  2129. data->promoted_mode,
  2130. data->passed_type,
  2131. data->named_arg);
  2132. if (entry_parm == 0)
  2133. data->promoted_mode = data->passed_mode;
  2134. /* Determine parm's home in the stack, in case it arrives in the stack
  2135. or we should pretend it did. Compute the stack position and rtx where
  2136. the argument arrives and its size.
  2137. There is one complexity here: If this was a parameter that would
  2138. have been passed in registers, but wasn't only because it is
  2139. __builtin_va_alist, we want locate_and_pad_parm to treat it as if
  2140. it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
  2141. In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0
  2142. as it was the previous time. */
  2143. in_regs = (entry_parm != 0) || POINTER_BOUNDS_TYPE_P (data->passed_type);
  2144. #ifdef STACK_PARMS_IN_REG_PARM_AREA
  2145. in_regs = true;
  2146. #endif
  2147. if (!in_regs && !data->named_arg)
  2148. {
  2149. if (targetm.calls.pretend_outgoing_varargs_named (all->args_so_far))
  2150. {
  2151. rtx tem;
  2152. tem = targetm.calls.function_incoming_arg (all->args_so_far,
  2153. data->promoted_mode,
  2154. data->passed_type, true);
  2155. in_regs = tem != NULL;
  2156. }
  2157. }
  2158. /* If this parameter was passed both in registers and in the stack, use
  2159. the copy on the stack. */
  2160. if (targetm.calls.must_pass_in_stack (data->promoted_mode,
  2161. data->passed_type))
  2162. entry_parm = 0;
  2163. if (entry_parm)
  2164. {
  2165. int partial;
  2166. partial = targetm.calls.arg_partial_bytes (all->args_so_far,
  2167. data->promoted_mode,
  2168. data->passed_type,
  2169. data->named_arg);
  2170. data->partial = partial;
  2171. /* The caller might already have allocated stack space for the
  2172. register parameters. */
  2173. if (partial != 0 && all->reg_parm_stack_space == 0)
  2174. {
  2175. /* Part of this argument is passed in registers and part
  2176. is passed on the stack. Ask the prologue code to extend
  2177. the stack part so that we can recreate the full value.
  2178. PRETEND_BYTES is the size of the registers we need to store.
  2179. CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
  2180. stack space that the prologue should allocate.
  2181. Internally, gcc assumes that the argument pointer is aligned
  2182. to STACK_BOUNDARY bits. This is used both for alignment
  2183. optimizations (see init_emit) and to locate arguments that are
  2184. aligned to more than PARM_BOUNDARY bits. We must preserve this
  2185. invariant by rounding CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to
  2186. a stack boundary. */
  2187. /* We assume at most one partial arg, and it must be the first
  2188. argument on the stack. */
  2189. gcc_assert (!all->extra_pretend_bytes && !all->pretend_args_size);
  2190. pretend_bytes = partial;
  2191. all->pretend_args_size = CEIL_ROUND (pretend_bytes, STACK_BYTES);
  2192. /* We want to align relative to the actual stack pointer, so
  2193. don't include this in the stack size until later. */
  2194. all->extra_pretend_bytes = all->pretend_args_size;
  2195. }
  2196. }
  2197. locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs,
  2198. all->reg_parm_stack_space,
  2199. entry_parm ? data->partial : 0, current_function_decl,
  2200. &all->stack_args_size, &data->locate);
  2201. /* Update parm_stack_boundary if this parameter is passed in the
  2202. stack. */
  2203. if (!in_regs && crtl->parm_stack_boundary < data->locate.boundary)
  2204. crtl->parm_stack_boundary = data->locate.boundary;
  2205. /* Adjust offsets to include the pretend args. */
  2206. pretend_bytes = all->extra_pretend_bytes - pretend_bytes;
  2207. data->locate.slot_offset.constant += pretend_bytes;
  2208. data->locate.offset.constant += pretend_bytes;
  2209. data->entry_parm = entry_parm;
  2210. }
  2211. /* A subroutine of assign_parms. If there is actually space on the stack
  2212. for this parm, count it in stack_args_size and return true. */
  2213. static bool
  2214. assign_parm_is_stack_parm (struct assign_parm_data_all *all,
  2215. struct assign_parm_data_one *data)
  2216. {
  2217. /* Bounds are never passed on the stack to keep compatibility
  2218. with not instrumented code. */
  2219. if (POINTER_BOUNDS_TYPE_P (data->passed_type))
  2220. return false;
  2221. /* Trivially true if we've no incoming register. */
  2222. else if (data->entry_parm == NULL)
  2223. ;
  2224. /* Also true if we're partially in registers and partially not,
  2225. since we've arranged to drop the entire argument on the stack. */
  2226. else if (data->partial != 0)
  2227. ;
  2228. /* Also true if the target says that it's passed in both registers
  2229. and on the stack. */
  2230. else if (GET_CODE (data->entry_parm) == PARALLEL
  2231. && XEXP (XVECEXP (data->entry_parm, 0, 0), 0) == NULL_RTX)
  2232. ;
  2233. /* Also true if the target says that there's stack allocated for
  2234. all register parameters. */
  2235. else if (all->reg_parm_stack_space > 0)
  2236. ;
  2237. /* Otherwise, no, this parameter has no ABI defined stack slot. */
  2238. else
  2239. return false;
  2240. all->stack_args_size.constant += data->locate.size.constant;
  2241. if (data->locate.size.var)
  2242. ADD_PARM_SIZE (all->stack_args_size, data->locate.size.var);
  2243. return true;
  2244. }
  2245. /* A subroutine of assign_parms. Given that this parameter is allocated
  2246. stack space by the ABI, find it. */
  2247. static void
  2248. assign_parm_find_stack_rtl (tree parm, struct assign_parm_data_one *data)
  2249. {
  2250. rtx offset_rtx, stack_parm;
  2251. unsigned int align, boundary;
  2252. /* If we're passing this arg using a reg, make its stack home the
  2253. aligned stack slot. */
  2254. if (data->entry_parm)
  2255. offset_rtx = ARGS_SIZE_RTX (data->locate.slot_offset);
  2256. else
  2257. offset_rtx = ARGS_SIZE_RTX (data->locate.offset);
  2258. stack_parm = crtl->args.internal_arg_pointer;
  2259. if (offset_rtx != const0_rtx)
  2260. stack_parm = gen_rtx_PLUS (Pmode, stack_parm, offset_rtx);
  2261. stack_parm = gen_rtx_MEM (data->promoted_mode, stack_parm);
  2262. if (!data->passed_pointer)
  2263. {
  2264. set_mem_attributes (stack_parm, parm, 1);
  2265. /* set_mem_attributes could set MEM_SIZE to the passed mode's size,
  2266. while promoted mode's size is needed. */
  2267. if (data->promoted_mode != BLKmode
  2268. && data->promoted_mode != DECL_MODE (parm))
  2269. {
  2270. set_mem_size (stack_parm, GET_MODE_SIZE (data->promoted_mode));
  2271. if (MEM_EXPR (stack_parm) && MEM_OFFSET_KNOWN_P (stack_parm))
  2272. {
  2273. int offset = subreg_lowpart_offset (DECL_MODE (parm),
  2274. data->promoted_mode);
  2275. if (offset)
  2276. set_mem_offset (stack_parm, MEM_OFFSET (stack_parm) - offset);
  2277. }
  2278. }
  2279. }
  2280. boundary = data->locate.boundary;
  2281. align = BITS_PER_UNIT;
  2282. /* If we're padding upward, we know that the alignment of the slot
  2283. is TARGET_FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
  2284. intentionally forcing upward padding. Otherwise we have to come
  2285. up with a guess at the alignment based on OFFSET_RTX. */
  2286. if (data->locate.where_pad != downward || data->entry_parm)
  2287. align = boundary;
  2288. else if (CONST_INT_P (offset_rtx))
  2289. {
  2290. align = INTVAL (offset_rtx) * BITS_PER_UNIT | boundary;
  2291. align = align & -align;
  2292. }
  2293. set_mem_align (stack_parm, align);
  2294. if (data->entry_parm)
  2295. set_reg_attrs_for_parm (data->entry_parm, stack_parm);
  2296. data->stack_parm = stack_parm;
  2297. }
  2298. /* A subroutine of assign_parms. Adjust DATA->ENTRY_RTL such that it's
  2299. always valid and contiguous. */
  2300. static void
  2301. assign_parm_adjust_entry_rtl (struct assign_parm_data_one *data)
  2302. {
  2303. rtx entry_parm = data->entry_parm;
  2304. rtx stack_parm = data->stack_parm;
  2305. /* If this parm was passed part in regs and part in memory, pretend it
  2306. arrived entirely in memory by pushing the register-part onto the stack.
  2307. In the special case of a DImode or DFmode that is split, we could put
  2308. it together in a pseudoreg directly, but for now that's not worth
  2309. bothering with. */
  2310. if (data->partial != 0)
  2311. {
  2312. /* Handle calls that pass values in multiple non-contiguous
  2313. locations. The Irix 6 ABI has examples of this. */
  2314. if (GET_CODE (entry_parm) == PARALLEL)
  2315. emit_group_store (validize_mem (copy_rtx (stack_parm)), entry_parm,
  2316. data->passed_type,
  2317. int_size_in_bytes (data->passed_type));
  2318. else
  2319. {
  2320. gcc_assert (data->partial % UNITS_PER_WORD == 0);
  2321. move_block_from_reg (REGNO (entry_parm),
  2322. validize_mem (copy_rtx (stack_parm)),
  2323. data->partial / UNITS_PER_WORD);
  2324. }
  2325. entry_parm = stack_parm;
  2326. }
  2327. /* If we didn't decide this parm came in a register, by default it came
  2328. on the stack. */
  2329. else if (entry_parm == NULL)
  2330. entry_parm = stack_parm;
  2331. /* When an argument is passed in multiple locations, we can't make use
  2332. of this information, but we can save some copying if the whole argument
  2333. is passed in a single register. */
  2334. else if (GET_CODE (entry_parm) == PARALLEL
  2335. && data->nominal_mode != BLKmode
  2336. && data->passed_mode != BLKmode)
  2337. {
  2338. size_t i, len = XVECLEN (entry_parm, 0);
  2339. for (i = 0; i < len; i++)
  2340. if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
  2341. && REG_P (XEXP (XVECEXP (entry_parm, 0, i), 0))
  2342. && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
  2343. == data->passed_mode)
  2344. && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
  2345. {
  2346. entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
  2347. break;
  2348. }
  2349. }
  2350. data->entry_parm = entry_parm;
  2351. }
  2352. /* A subroutine of assign_parms. Reconstitute any values which were
  2353. passed in multiple registers and would fit in a single register. */
  2354. static void
  2355. assign_parm_remove_parallels (struct assign_parm_data_one *data)
  2356. {
  2357. rtx entry_parm = data->entry_parm;
  2358. /* Convert the PARALLEL to a REG of the same mode as the parallel.
  2359. This can be done with register operations rather than on the
  2360. stack, even if we will store the reconstituted parameter on the
  2361. stack later. */
  2362. if (GET_CODE (entry_parm) == PARALLEL && GET_MODE (entry_parm) != BLKmode)
  2363. {
  2364. rtx parmreg = gen_reg_rtx (GET_MODE (entry_parm));
  2365. emit_group_store (parmreg, entry_parm, data->passed_type,
  2366. GET_MODE_SIZE (GET_MODE (entry_parm)));
  2367. entry_parm = parmreg;
  2368. }
  2369. data->entry_parm = entry_parm;
  2370. }
  2371. /* A subroutine of assign_parms. Adjust DATA->STACK_RTL such that it's
  2372. always valid and properly aligned. */
  2373. static void
  2374. assign_parm_adjust_stack_rtl (struct assign_parm_data_one *data)
  2375. {
  2376. rtx stack_parm = data->stack_parm;
  2377. /* If we can't trust the parm stack slot to be aligned enough for its
  2378. ultimate type, don't use that slot after entry. We'll make another
  2379. stack slot, if we need one. */
  2380. if (stack_parm
  2381. && ((STRICT_ALIGNMENT
  2382. && GET_MODE_ALIGNMENT (data->nominal_mode) > MEM_ALIGN (stack_parm))
  2383. || (data->nominal_type
  2384. && TYPE_ALIGN (data->nominal_type) > MEM_ALIGN (stack_parm)
  2385. && MEM_ALIGN (stack_parm) < PREFERRED_STACK_BOUNDARY)))
  2386. stack_parm = NULL;
  2387. /* If parm was passed in memory, and we need to convert it on entry,
  2388. don't store it back in that same slot. */
  2389. else if (data->entry_parm == stack_parm
  2390. && data->nominal_mode != BLKmode
  2391. && data->nominal_mode != data->passed_mode)
  2392. stack_parm = NULL;
  2393. /* If stack protection is in effect for this function, don't leave any
  2394. pointers in their passed stack slots. */
  2395. else if (crtl->stack_protect_guard
  2396. && (flag_stack_protect == 2
  2397. || data->passed_pointer
  2398. || POINTER_TYPE_P (data->nominal_type)))
  2399. stack_parm = NULL;
  2400. data->stack_parm = stack_parm;
  2401. }
  2402. /* A subroutine of assign_parms. Return true if the current parameter
  2403. should be stored as a BLKmode in the current frame. */
  2404. static bool
  2405. assign_parm_setup_block_p (struct assign_parm_data_one *data)
  2406. {
  2407. if (data->nominal_mode == BLKmode)
  2408. return true;
  2409. if (GET_MODE (data->entry_parm) == BLKmode)
  2410. return true;
  2411. #ifdef BLOCK_REG_PADDING
  2412. /* Only assign_parm_setup_block knows how to deal with register arguments
  2413. that are padded at the least significant end. */
  2414. if (REG_P (data->entry_parm)
  2415. && GET_MODE_SIZE (data->promoted_mode) < UNITS_PER_WORD
  2416. && (BLOCK_REG_PADDING (data->passed_mode, data->passed_type, 1)
  2417. == (BYTES_BIG_ENDIAN ? upward : downward)))
  2418. return true;
  2419. #endif
  2420. return false;
  2421. }
  2422. /* A subroutine of assign_parms. Arrange for the parameter to be
  2423. present and valid in DATA->STACK_RTL. */
  2424. static void
  2425. assign_parm_setup_block (struct assign_parm_data_all *all,
  2426. tree parm, struct assign_parm_data_one *data)
  2427. {
  2428. rtx entry_parm = data->entry_parm;
  2429. rtx stack_parm = data->stack_parm;
  2430. HOST_WIDE_INT size;
  2431. HOST_WIDE_INT size_stored;
  2432. if (GET_CODE (entry_parm) == PARALLEL)
  2433. entry_parm = emit_group_move_into_temps (entry_parm);
  2434. size = int_size_in_bytes (data->passed_type);
  2435. size_stored = CEIL_ROUND (size, UNITS_PER_WORD);
  2436. if (stack_parm == 0)
  2437. {
  2438. DECL_ALIGN (parm) = MAX (DECL_ALIGN (parm), BITS_PER_WORD);
  2439. stack_parm = assign_stack_local (BLKmode, size_stored,
  2440. DECL_ALIGN (parm));
  2441. if (GET_MODE_SIZE (GET_MODE (entry_parm)) == size)
  2442. PUT_MODE (stack_parm, GET_MODE (entry_parm));
  2443. set_mem_attributes (stack_parm, parm, 1);
  2444. }
  2445. /* If a BLKmode arrives in registers, copy it to a stack slot. Handle
  2446. calls that pass values in multiple non-contiguous locations. */
  2447. if (REG_P (entry_parm) || GET_CODE (entry_parm) == PARALLEL)
  2448. {
  2449. rtx mem;
  2450. /* Note that we will be storing an integral number of words.
  2451. So we have to be careful to ensure that we allocate an
  2452. integral number of words. We do this above when we call
  2453. assign_stack_local if space was not allocated in the argument
  2454. list. If it was, this will not work if PARM_BOUNDARY is not
  2455. a multiple of BITS_PER_WORD. It isn't clear how to fix this
  2456. if it becomes a problem. Exception is when BLKmode arrives
  2457. with arguments not conforming to word_mode. */
  2458. if (data->stack_parm == 0)
  2459. ;
  2460. else if (GET_CODE (entry_parm) == PARALLEL)
  2461. ;
  2462. else
  2463. gcc_assert (!size || !(PARM_BOUNDARY % BITS_PER_WORD));
  2464. mem = validize_mem (copy_rtx (stack_parm));
  2465. /* Handle values in multiple non-contiguous locations. */
  2466. if (GET_CODE (entry_parm) == PARALLEL)
  2467. {
  2468. push_to_sequence2 (all->first_conversion_insn,
  2469. all->last_conversion_insn);
  2470. emit_group_store (mem, entry_parm, data->passed_type, size);
  2471. all->first_conversion_insn = get_insns ();
  2472. all->last_conversion_insn = get_last_insn ();
  2473. end_sequence ();
  2474. }
  2475. else if (size == 0)
  2476. ;
  2477. /* If SIZE is that of a mode no bigger than a word, just use
  2478. that mode's store operation. */
  2479. else if (size <= UNITS_PER_WORD)
  2480. {
  2481. machine_mode mode
  2482. = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
  2483. if (mode != BLKmode
  2484. #ifdef BLOCK_REG_PADDING
  2485. && (size == UNITS_PER_WORD
  2486. || (BLOCK_REG_PADDING (mode, data->passed_type, 1)
  2487. != (BYTES_BIG_ENDIAN ? upward : downward)))
  2488. #endif
  2489. )
  2490. {
  2491. rtx reg;
  2492. /* We are really truncating a word_mode value containing
  2493. SIZE bytes into a value of mode MODE. If such an
  2494. operation requires no actual instructions, we can refer
  2495. to the value directly in mode MODE, otherwise we must
  2496. start with the register in word_mode and explicitly
  2497. convert it. */
  2498. if (TRULY_NOOP_TRUNCATION (size * BITS_PER_UNIT, BITS_PER_WORD))
  2499. reg = gen_rtx_REG (mode, REGNO (entry_parm));
  2500. else
  2501. {
  2502. reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
  2503. reg = convert_to_mode (mode, copy_to_reg (reg), 1);
  2504. }
  2505. emit_move_insn (change_address (mem, mode, 0), reg);
  2506. }
  2507. /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
  2508. machine must be aligned to the left before storing
  2509. to memory. Note that the previous test doesn't
  2510. handle all cases (e.g. SIZE == 3). */
  2511. else if (size != UNITS_PER_WORD
  2512. #ifdef BLOCK_REG_PADDING
  2513. && (BLOCK_REG_PADDING (mode, data->passed_type, 1)
  2514. == downward)
  2515. #else
  2516. && BYTES_BIG_ENDIAN
  2517. #endif
  2518. )
  2519. {
  2520. rtx tem, x;
  2521. int by = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
  2522. rtx reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
  2523. x = expand_shift (LSHIFT_EXPR, word_mode, reg, by, NULL_RTX, 1);
  2524. tem = change_address (mem, word_mode, 0);
  2525. emit_move_insn (tem, x);
  2526. }
  2527. else
  2528. move_block_from_reg (REGNO (entry_parm), mem,
  2529. size_stored / UNITS_PER_WORD);
  2530. }
  2531. else
  2532. move_block_from_reg (REGNO (entry_parm), mem,
  2533. size_stored / UNITS_PER_WORD);
  2534. }
  2535. else if (data->stack_parm == 0)
  2536. {
  2537. push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
  2538. emit_block_move (stack_parm, data->entry_parm, GEN_INT (size),
  2539. BLOCK_OP_NORMAL);
  2540. all->first_conversion_insn = get_insns ();
  2541. all->last_conversion_insn = get_last_insn ();
  2542. end_sequence ();
  2543. }
  2544. data->stack_parm = stack_parm;
  2545. SET_DECL_RTL (parm, stack_parm);
  2546. }
  2547. /* A subroutine of assign_parms. Allocate a pseudo to hold the current
  2548. parameter. Get it there. Perform all ABI specified conversions. */
  2549. static void
  2550. assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
  2551. struct assign_parm_data_one *data)
  2552. {
  2553. rtx parmreg, validated_mem;
  2554. rtx equiv_stack_parm;
  2555. machine_mode promoted_nominal_mode;
  2556. int unsignedp = TYPE_UNSIGNED (TREE_TYPE (parm));
  2557. bool did_conversion = false;
  2558. bool need_conversion, moved;
  2559. /* Store the parm in a pseudoregister during the function, but we may
  2560. need to do it in a wider mode. Using 2 here makes the result
  2561. consistent with promote_decl_mode and thus expand_expr_real_1. */
  2562. promoted_nominal_mode
  2563. = promote_function_mode (data->nominal_type, data->nominal_mode, &unsignedp,
  2564. TREE_TYPE (current_function_decl), 2);
  2565. parmreg = gen_reg_rtx (promoted_nominal_mode);
  2566. if (!DECL_ARTIFICIAL (parm))
  2567. mark_user_reg (parmreg);
  2568. /* If this was an item that we received a pointer to,
  2569. set DECL_RTL appropriately. */
  2570. if (data->passed_pointer)
  2571. {
  2572. rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data->passed_type)), parmreg);
  2573. set_mem_attributes (x, parm, 1);
  2574. SET_DECL_RTL (parm, x);
  2575. }
  2576. else
  2577. SET_DECL_RTL (parm, parmreg);
  2578. assign_parm_remove_parallels (data);
  2579. /* Copy the value into the register, thus bridging between
  2580. assign_parm_find_data_types and expand_expr_real_1. */
  2581. equiv_stack_parm = data->stack_parm;
  2582. validated_mem = validize_mem (copy_rtx (data->entry_parm));
  2583. need_conversion = (data->nominal_mode != data->passed_mode
  2584. || promoted_nominal_mode != data->promoted_mode);
  2585. moved = false;
  2586. if (need_conversion
  2587. && GET_MODE_CLASS (data->nominal_mode) == MODE_INT
  2588. && data->nominal_mode == data->passed_mode
  2589. && data->nominal_mode == GET_MODE (data->entry_parm))
  2590. {
  2591. /* ENTRY_PARM has been converted to PROMOTED_MODE, its
  2592. mode, by the caller. We now have to convert it to
  2593. NOMINAL_MODE, if different. However, PARMREG may be in
  2594. a different mode than NOMINAL_MODE if it is being stored
  2595. promoted.
  2596. If ENTRY_PARM is a hard register, it might be in a register
  2597. not valid for operating in its mode (e.g., an odd-numbered
  2598. register for a DFmode). In that case, moves are the only
  2599. thing valid, so we can't do a convert from there. This
  2600. occurs when the calling sequence allow such misaligned
  2601. usages.
  2602. In addition, the conversion may involve a call, which could
  2603. clobber parameters which haven't been copied to pseudo
  2604. registers yet.
  2605. First, we try to emit an insn which performs the necessary
  2606. conversion. We verify that this insn does not clobber any
  2607. hard registers. */
  2608. enum insn_code icode;
  2609. rtx op0, op1;
  2610. icode = can_extend_p (promoted_nominal_mode, data->passed_mode,
  2611. unsignedp);
  2612. op0 = parmreg;
  2613. op1 = validated_mem;
  2614. if (icode != CODE_FOR_nothing
  2615. && insn_operand_matches (icode, 0, op0)
  2616. && insn_operand_matches (icode, 1, op1))
  2617. {
  2618. enum rtx_code code = unsignedp ? ZERO_EXTEND : SIGN_EXTEND;
  2619. rtx_insn *insn, *insns;
  2620. rtx t = op1;
  2621. HARD_REG_SET hardregs;
  2622. start_sequence ();
  2623. /* If op1 is a hard register that is likely spilled, first
  2624. force it into a pseudo, otherwise combiner might extend
  2625. its lifetime too much. */
  2626. if (GET_CODE (t) == SUBREG)
  2627. t = SUBREG_REG (t);
  2628. if (REG_P (t)
  2629. && HARD_REGISTER_P (t)
  2630. && ! TEST_HARD_REG_BIT (fixed_reg_set, REGNO (t))
  2631. && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (t))))
  2632. {
  2633. t = gen_reg_rtx (GET_MODE (op1));
  2634. emit_move_insn (t, op1);
  2635. }
  2636. else
  2637. t = op1;
  2638. rtx pat = gen_extend_insn (op0, t, promoted_nominal_mode,
  2639. data->passed_mode, unsignedp);
  2640. emit_insn (pat);
  2641. insns = get_insns ();
  2642. moved = true;
  2643. CLEAR_HARD_REG_SET (hardregs);
  2644. for (insn = insns; insn && moved; insn = NEXT_INSN (insn))
  2645. {
  2646. if (INSN_P (insn))
  2647. note_stores (PATTERN (insn), record_hard_reg_sets,
  2648. &hardregs);
  2649. if (!hard_reg_set_empty_p (hardregs))
  2650. moved = false;
  2651. }
  2652. end_sequence ();
  2653. if (moved)
  2654. {
  2655. emit_insn (insns);
  2656. if (equiv_stack_parm != NULL_RTX)
  2657. equiv_stack_parm = gen_rtx_fmt_e (code, GET_MODE (parmreg),
  2658. equiv_stack_parm);
  2659. }
  2660. }
  2661. }
  2662. if (moved)
  2663. /* Nothing to do. */
  2664. ;
  2665. else if (need_conversion)
  2666. {
  2667. /* We did not have an insn to convert directly, or the sequence
  2668. generated appeared unsafe. We must first copy the parm to a
  2669. pseudo reg, and save the conversion until after all
  2670. parameters have been moved. */
  2671. int save_tree_used;
  2672. rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
  2673. emit_move_insn (tempreg, validated_mem);
  2674. push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
  2675. tempreg = convert_to_mode (data->nominal_mode, tempreg, unsignedp);
  2676. if (GET_CODE (tempreg) == SUBREG
  2677. && GET_MODE (tempreg) == data->nominal_mode
  2678. && REG_P (SUBREG_REG (tempreg))
  2679. && data->nominal_mode == data->passed_mode
  2680. && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (data->entry_parm)
  2681. && GET_MODE_SIZE (GET_MODE (tempreg))
  2682. < GET_MODE_SIZE (GET_MODE (data->entry_parm)))
  2683. {
  2684. /* The argument is already sign/zero extended, so note it
  2685. into the subreg. */
  2686. SUBREG_PROMOTED_VAR_P (tempreg) = 1;
  2687. SUBREG_PROMOTED_SET (tempreg, unsignedp);
  2688. }
  2689. /* TREE_USED gets set erroneously during expand_assignment. */
  2690. save_tree_used = TREE_USED (parm);
  2691. expand_assignment (parm, make_tree (data->nominal_type, tempreg), false);
  2692. TREE_USED (parm) = save_tree_used;
  2693. all->first_conversion_insn = get_insns ();
  2694. all->last_conversion_insn = get_last_insn ();
  2695. end_sequence ();
  2696. did_conversion = true;
  2697. }
  2698. else
  2699. emit_move_insn (parmreg, validated_mem);
  2700. /* If we were passed a pointer but the actual value can safely live
  2701. in a register, retrieve it and use it directly. */
  2702. if (data->passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode)
  2703. {
  2704. /* We can't use nominal_mode, because it will have been set to
  2705. Pmode above. We must use the actual mode of the parm. */
  2706. if (use_register_for_decl (parm))
  2707. {
  2708. parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
  2709. mark_user_reg (parmreg);
  2710. }
  2711. else
  2712. {
  2713. int align = STACK_SLOT_ALIGNMENT (TREE_TYPE (parm),
  2714. TYPE_MODE (TREE_TYPE (parm)),
  2715. TYPE_ALIGN (TREE_TYPE (parm)));
  2716. parmreg
  2717. = assign_stack_local (TYPE_MODE (TREE_TYPE (parm)),
  2718. GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parm))),
  2719. align);
  2720. set_mem_attributes (parmreg, parm, 1);
  2721. }
  2722. if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
  2723. {
  2724. rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
  2725. int unsigned_p = TYPE_UNSIGNED (TREE_TYPE (parm));
  2726. push_to_sequence2 (all->first_conversion_insn,
  2727. all->last_conversion_insn);
  2728. emit_move_insn (tempreg, DECL_RTL (parm));
  2729. tempreg = convert_to_mode (GET_MODE (parmreg), tempreg, unsigned_p);
  2730. emit_move_insn (parmreg, tempreg);
  2731. all->first_conversion_insn = get_insns ();
  2732. all->last_conversion_insn = get_last_insn ();
  2733. end_sequence ();
  2734. did_conversion = true;
  2735. }
  2736. else
  2737. emit_move_insn (parmreg, DECL_RTL (parm));
  2738. SET_DECL_RTL (parm, parmreg);
  2739. /* STACK_PARM is the pointer, not the parm, and PARMREG is
  2740. now the parm. */
  2741. data->stack_parm = NULL;
  2742. }
  2743. /* Mark the register as eliminable if we did no conversion and it was
  2744. copied from memory at a fixed offset, and the arg pointer was not
  2745. copied to a pseudo-reg. If the arg pointer is a pseudo reg or the
  2746. offset formed an invalid address, such memory-equivalences as we
  2747. make here would screw up life analysis for it. */
  2748. if (data->nominal_mode == data->passed_mode
  2749. && !did_conversion
  2750. && data->stack_parm != 0
  2751. && MEM_P (data->stack_parm)
  2752. && data->locate.offset.var == 0
  2753. && reg_mentioned_p (virtual_incoming_args_rtx,
  2754. XEXP (data->stack_parm, 0)))
  2755. {
  2756. rtx_insn *linsn = get_last_insn ();
  2757. rtx_insn *sinsn;
  2758. rtx set;
  2759. /* Mark complex types separately. */
  2760. if (GET_CODE (parmreg) == CONCAT)
  2761. {
  2762. machine_mode submode
  2763. = GET_MODE_INNER (GET_MODE (parmreg));
  2764. int regnor = REGNO (XEXP (parmreg, 0));
  2765. int regnoi = REGNO (XEXP (parmreg, 1));
  2766. rtx stackr = adjust_address_nv (data->stack_parm, submode, 0);
  2767. rtx stacki = adjust_address_nv (data->stack_parm, submode,
  2768. GET_MODE_SIZE (submode));
  2769. /* Scan backwards for the set of the real and
  2770. imaginary parts. */
  2771. for (sinsn = linsn; sinsn != 0;
  2772. sinsn = prev_nonnote_insn (sinsn))
  2773. {
  2774. set = single_set (sinsn);
  2775. if (set == 0)
  2776. continue;
  2777. if (SET_DEST (set) == regno_reg_rtx [regnoi])
  2778. set_unique_reg_note (sinsn, REG_EQUIV, stacki);
  2779. else if (SET_DEST (set) == regno_reg_rtx [regnor])
  2780. set_unique_reg_note (sinsn, REG_EQUIV, stackr);
  2781. }
  2782. }
  2783. else
  2784. set_dst_reg_note (linsn, REG_EQUIV, equiv_stack_parm, parmreg);
  2785. }
  2786. /* For pointer data type, suggest pointer register. */
  2787. if (POINTER_TYPE_P (TREE_TYPE (parm)))
  2788. mark_reg_pointer (parmreg,
  2789. TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
  2790. }
  2791. /* A subroutine of assign_parms. Allocate stack space to hold the current
  2792. parameter. Get it there. Perform all ABI specified conversions. */
  2793. static void
  2794. assign_parm_setup_stack (struct assign_parm_data_all *all, tree parm,
  2795. struct assign_parm_data_one *data)
  2796. {
  2797. /* Value must be stored in the stack slot STACK_PARM during function
  2798. execution. */
  2799. bool to_conversion = false;
  2800. assign_parm_remove_parallels (data);
  2801. if (data->promoted_mode != data->nominal_mode)
  2802. {
  2803. /* Conversion is required. */
  2804. rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
  2805. emit_move_insn (tempreg, validize_mem (copy_rtx (data->entry_parm)));
  2806. push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
  2807. to_conversion = true;
  2808. data->entry_parm = convert_to_mode (data->nominal_mode, tempreg,
  2809. TYPE_UNSIGNED (TREE_TYPE (parm)));
  2810. if (data->stack_parm)
  2811. {
  2812. int offset = subreg_lowpart_offset (data->nominal_mode,
  2813. GET_MODE (data->stack_parm));
  2814. /* ??? This may need a big-endian conversion on sparc64. */
  2815. data->stack_parm
  2816. = adjust_address (data->stack_parm, data->nominal_mode, 0);
  2817. if (offset && MEM_OFFSET_KNOWN_P (data->stack_parm))
  2818. set_mem_offset (data->stack_parm,
  2819. MEM_OFFSET (data->stack_parm) + offset);
  2820. }
  2821. }
  2822. if (data->entry_parm != data->stack_parm)
  2823. {
  2824. rtx src, dest;
  2825. if (data->stack_parm == 0)
  2826. {
  2827. int align = STACK_SLOT_ALIGNMENT (data->passed_type,
  2828. GET_MODE (data->entry_parm),
  2829. TYPE_ALIGN (data->passed_type));
  2830. data->stack_parm
  2831. = assign_stack_local (GET_MODE (data->entry_parm),
  2832. GET_MODE_SIZE (GET_MODE (data->entry_parm)),
  2833. align);
  2834. set_mem_attributes (data->stack_parm, parm, 1);
  2835. }
  2836. dest = validize_mem (copy_rtx (data->stack_parm));
  2837. src = validize_mem (copy_rtx (data->entry_parm));
  2838. if (MEM_P (src))
  2839. {
  2840. /* Use a block move to handle potentially misaligned entry_parm. */
  2841. if (!to_conversion)
  2842. push_to_sequence2 (all->first_conversion_insn,
  2843. all->last_conversion_insn);
  2844. to_conversion = true;
  2845. emit_block_move (dest, src,
  2846. GEN_INT (int_size_in_bytes (data->passed_type)),
  2847. BLOCK_OP_NORMAL);
  2848. }
  2849. else
  2850. emit_move_insn (dest, src);
  2851. }
  2852. if (to_conversion)
  2853. {
  2854. all->first_conversion_insn = get_insns ();
  2855. all->last_conversion_insn = get_last_insn ();
  2856. end_sequence ();
  2857. }
  2858. SET_DECL_RTL (parm, data->stack_parm);
  2859. }
  2860. /* A subroutine of assign_parms. If the ABI splits complex arguments, then
  2861. undo the frobbing that we did in assign_parms_augmented_arg_list. */
  2862. static void
  2863. assign_parms_unsplit_complex (struct assign_parm_data_all *all,
  2864. vec<tree> fnargs)
  2865. {
  2866. tree parm;
  2867. tree orig_fnargs = all->orig_fnargs;
  2868. unsigned i = 0;
  2869. for (parm = orig_fnargs; parm; parm = TREE_CHAIN (parm), ++i)
  2870. {
  2871. if (TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
  2872. && targetm.calls.split_complex_arg (TREE_TYPE (parm)))
  2873. {
  2874. rtx tmp, real, imag;
  2875. machine_mode inner = GET_MODE_INNER (DECL_MODE (parm));
  2876. real = DECL_RTL (fnargs[i]);
  2877. imag = DECL_RTL (fnargs[i + 1]);
  2878. if (inner != GET_MODE (real))
  2879. {
  2880. real = gen_lowpart_SUBREG (inner, real);
  2881. imag = gen_lowpart_SUBREG (inner, imag);
  2882. }
  2883. if (TREE_ADDRESSABLE (parm))
  2884. {
  2885. rtx rmem, imem;
  2886. HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (parm));
  2887. int align = STACK_SLOT_ALIGNMENT (TREE_TYPE (parm),
  2888. DECL_MODE (parm),
  2889. TYPE_ALIGN (TREE_TYPE (parm)));
  2890. /* split_complex_arg put the real and imag parts in
  2891. pseudos. Move them to memory. */
  2892. tmp = assign_stack_local (DECL_MODE (parm), size, align);
  2893. set_mem_attributes (tmp, parm, 1);
  2894. rmem = adjust_address_nv (tmp, inner, 0);
  2895. imem = adjust_address_nv (tmp, inner, GET_MODE_SIZE (inner));
  2896. push_to_sequence2 (all->first_conversion_insn,
  2897. all->last_conversion_insn);
  2898. emit_move_insn (rmem, real);
  2899. emit_move_insn (imem, imag);
  2900. all->first_conversion_insn = get_insns ();
  2901. all->last_conversion_insn = get_last_insn ();
  2902. end_sequence ();
  2903. }
  2904. else
  2905. tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
  2906. SET_DECL_RTL (parm, tmp);
  2907. real = DECL_INCOMING_RTL (fnargs[i]);
  2908. imag = DECL_INCOMING_RTL (fnargs[i + 1]);
  2909. if (inner != GET_MODE (real))
  2910. {
  2911. real = gen_lowpart_SUBREG (inner, real);
  2912. imag = gen_lowpart_SUBREG (inner, imag);
  2913. }
  2914. tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
  2915. set_decl_incoming_rtl (parm, tmp, false);
  2916. i++;
  2917. }
  2918. }
  2919. }
  2920. /* Load bounds of PARM from bounds table. */
  2921. static void
  2922. assign_parm_load_bounds (struct assign_parm_data_one *data,
  2923. tree parm,
  2924. rtx entry,
  2925. unsigned bound_no)
  2926. {
  2927. bitmap_iterator bi;
  2928. unsigned i, offs = 0;
  2929. int bnd_no = -1;
  2930. rtx slot = NULL, ptr = NULL;
  2931. if (parm)
  2932. {
  2933. bitmap slots;
  2934. bitmap_obstack_initialize (NULL);
  2935. slots = BITMAP_ALLOC (NULL);
  2936. chkp_find_bound_slots (TREE_TYPE (parm), slots);
  2937. EXECUTE_IF_SET_IN_BITMAP (slots, 0, i, bi)
  2938. {
  2939. if (bound_no)
  2940. bound_no--;
  2941. else
  2942. {
  2943. bnd_no = i;
  2944. break;
  2945. }
  2946. }
  2947. BITMAP_FREE (slots);
  2948. bitmap_obstack_release (NULL);
  2949. }
  2950. /* We may have bounds not associated with any pointer. */
  2951. if (bnd_no != -1)
  2952. offs = bnd_no * POINTER_SIZE / BITS_PER_UNIT;
  2953. /* Find associated pointer. */
  2954. if (bnd_no == -1)
  2955. {
  2956. /* If bounds are not associated with any bounds,
  2957. then it is passed in a register or special slot. */
  2958. gcc_assert (data->entry_parm);
  2959. ptr = const0_rtx;
  2960. }
  2961. else if (MEM_P (entry))
  2962. slot = adjust_address (entry, Pmode, offs);
  2963. else if (REG_P (entry))
  2964. ptr = gen_rtx_REG (Pmode, REGNO (entry) + bnd_no);
  2965. else if (GET_CODE (entry) == PARALLEL)
  2966. ptr = chkp_get_value_with_offs (entry, GEN_INT (offs));
  2967. else
  2968. gcc_unreachable ();
  2969. data->entry_parm = targetm.calls.load_bounds_for_arg (slot, ptr,
  2970. data->entry_parm);
  2971. }
  2972. /* Assign RTL expressions to the function's bounds parameters BNDARGS. */
  2973. static void
  2974. assign_bounds (vec<bounds_parm_data> &bndargs,
  2975. struct assign_parm_data_all &all)
  2976. {
  2977. unsigned i, pass, handled = 0;
  2978. bounds_parm_data *pbdata;
  2979. if (!bndargs.exists ())
  2980. return;
  2981. /* We make few passes to store input bounds. Firstly handle bounds
  2982. passed in registers. After that we load bounds passed in special
  2983. slots. Finally we load bounds from Bounds Table. */
  2984. for (pass = 0; pass < 3; pass++)
  2985. FOR_EACH_VEC_ELT (bndargs, i, pbdata)
  2986. {
  2987. /* Pass 0 => regs only. */
  2988. if (pass == 0
  2989. && (!pbdata->parm_data.entry_parm
  2990. || GET_CODE (pbdata->parm_data.entry_parm) != REG))
  2991. continue;
  2992. /* Pass 1 => slots only. */
  2993. else if (pass == 1
  2994. && (!pbdata->parm_data.entry_parm
  2995. || GET_CODE (pbdata->parm_data.entry_parm) == REG))
  2996. continue;
  2997. /* Pass 2 => BT only. */
  2998. else if (pass == 2
  2999. && pbdata->parm_data.entry_parm)
  3000. continue;
  3001. if (!pbdata->parm_data.entry_parm
  3002. || GET_CODE (pbdata->parm_data.entry_parm) != REG)
  3003. assign_parm_load_bounds (&pbdata->parm_data, pbdata->ptr_parm,
  3004. pbdata->ptr_entry, pbdata->bound_no);
  3005. set_decl_incoming_rtl (pbdata->bounds_parm,
  3006. pbdata->parm_data.entry_parm, false);
  3007. if (assign_parm_setup_block_p (&pbdata->parm_data))
  3008. assign_parm_setup_block (&all, pbdata->bounds_parm,
  3009. &pbdata->parm_data);
  3010. else if (pbdata->parm_data.passed_pointer
  3011. || use_register_for_decl (pbdata->bounds_parm))
  3012. assign_parm_setup_reg (&all, pbdata->bounds_parm,
  3013. &pbdata->parm_data);
  3014. else
  3015. assign_parm_setup_stack (&all, pbdata->bounds_parm,
  3016. &pbdata->parm_data);
  3017. /* Count handled bounds to make sure we miss nothing. */
  3018. handled++;
  3019. }
  3020. gcc_assert (handled == bndargs.length ());
  3021. bndargs.release ();
  3022. }
  3023. /* Assign RTL expressions to the function's parameters. This may involve
  3024. copying them into registers and using those registers as the DECL_RTL. */
  3025. static void
  3026. assign_parms (tree fndecl)
  3027. {
  3028. struct assign_parm_data_all all;
  3029. tree parm;
  3030. vec<tree> fnargs;
  3031. unsigned i, bound_no = 0;
  3032. tree last_arg = NULL;
  3033. rtx last_arg_entry = NULL;
  3034. vec<bounds_parm_data> bndargs = vNULL;
  3035. bounds_parm_data bdata;
  3036. crtl->args.internal_arg_pointer
  3037. = targetm.calls.internal_arg_pointer ();
  3038. assign_parms_initialize_all (&all);
  3039. fnargs = assign_parms_augmented_arg_list (&all);
  3040. FOR_EACH_VEC_ELT (fnargs, i, parm)
  3041. {
  3042. struct assign_parm_data_one data;
  3043. /* Extract the type of PARM; adjust it according to ABI. */
  3044. assign_parm_find_data_types (&all, parm, &data);
  3045. /* Early out for errors and void parameters. */
  3046. if (data.passed_mode == VOIDmode)
  3047. {
  3048. SET_DECL_RTL (parm, const0_rtx);
  3049. DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
  3050. continue;
  3051. }
  3052. /* Estimate stack alignment from parameter alignment. */
  3053. if (SUPPORTS_STACK_ALIGNMENT)
  3054. {
  3055. unsigned int align
  3056. = targetm.calls.function_arg_boundary (data.promoted_mode,
  3057. data.passed_type);
  3058. align = MINIMUM_ALIGNMENT (data.passed_type, data.promoted_mode,
  3059. align);
  3060. if (TYPE_ALIGN (data.nominal_type) > align)
  3061. align = MINIMUM_ALIGNMENT (data.nominal_type,
  3062. TYPE_MODE (data.nominal_type),
  3063. TYPE_ALIGN (data.nominal_type));
  3064. if (crtl->stack_alignment_estimated < align)
  3065. {
  3066. gcc_assert (!crtl->stack_realign_processed);
  3067. crtl->stack_alignment_estimated = align;
  3068. }
  3069. }
  3070. /* Find out where the parameter arrives in this function. */
  3071. assign_parm_find_entry_rtl (&all, &data);
  3072. /* Find out where stack space for this parameter might be. */
  3073. if (assign_parm_is_stack_parm (&all, &data))
  3074. {
  3075. assign_parm_find_stack_rtl (parm, &data);
  3076. assign_parm_adjust_entry_rtl (&data);
  3077. }
  3078. if (!POINTER_BOUNDS_TYPE_P (data.passed_type))
  3079. {
  3080. /* Remember where last non bounds arg was passed in case
  3081. we have to load associated bounds for it from Bounds
  3082. Table. */
  3083. last_arg = parm;
  3084. last_arg_entry = data.entry_parm;
  3085. bound_no = 0;
  3086. }
  3087. /* Record permanently how this parm was passed. */
  3088. if (data.passed_pointer)
  3089. {
  3090. rtx incoming_rtl
  3091. = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data.passed_type)),
  3092. data.entry_parm);
  3093. set_decl_incoming_rtl (parm, incoming_rtl, true);
  3094. }
  3095. else
  3096. set_decl_incoming_rtl (parm, data.entry_parm, false);
  3097. /* Boudns should be loaded in the particular order to
  3098. have registers allocated correctly. Collect info about
  3099. input bounds and load them later. */
  3100. if (POINTER_BOUNDS_TYPE_P (data.passed_type))
  3101. {
  3102. /* Expect bounds in instrumented functions only. */
  3103. gcc_assert (chkp_function_instrumented_p (fndecl));
  3104. bdata.parm_data = data;
  3105. bdata.bounds_parm = parm;
  3106. bdata.ptr_parm = last_arg;
  3107. bdata.ptr_entry = last_arg_entry;
  3108. bdata.bound_no = bound_no;
  3109. bndargs.safe_push (bdata);
  3110. }
  3111. else
  3112. {
  3113. assign_parm_adjust_stack_rtl (&data);
  3114. if (assign_parm_setup_block_p (&data))
  3115. assign_parm_setup_block (&all, parm, &data);
  3116. else if (data.passed_pointer || use_register_for_decl (parm))
  3117. assign_parm_setup_reg (&all, parm, &data);
  3118. else
  3119. assign_parm_setup_stack (&all, parm, &data);
  3120. }
  3121. if (cfun->stdarg && !DECL_CHAIN (parm))
  3122. {
  3123. int pretend_bytes = 0;
  3124. assign_parms_setup_varargs (&all, &data, false);
  3125. if (chkp_function_instrumented_p (fndecl))
  3126. {
  3127. /* We expect this is the last parm. Otherwise it is wrong
  3128. to assign bounds right now. */
  3129. gcc_assert (i == (fnargs.length () - 1));
  3130. assign_bounds (bndargs, all);
  3131. targetm.calls.setup_incoming_vararg_bounds (all.args_so_far,
  3132. data.promoted_mode,
  3133. data.passed_type,
  3134. &pretend_bytes,
  3135. false);
  3136. }
  3137. }
  3138. /* Update info on where next arg arrives in registers. */
  3139. targetm.calls.function_arg_advance (all.args_so_far, data.promoted_mode,
  3140. data.passed_type, data.named_arg);
  3141. if (POINTER_BOUNDS_TYPE_P (data.passed_type))
  3142. bound_no++;
  3143. }
  3144. assign_bounds (bndargs, all);
  3145. if (targetm.calls.split_complex_arg)
  3146. assign_parms_unsplit_complex (&all, fnargs);
  3147. fnargs.release ();
  3148. /* Output all parameter conversion instructions (possibly including calls)
  3149. now that all parameters have been copied out of hard registers. */
  3150. emit_insn (all.first_conversion_insn);
  3151. /* Estimate reload stack alignment from scalar return mode. */
  3152. if (SUPPORTS_STACK_ALIGNMENT)
  3153. {
  3154. if (DECL_RESULT (fndecl))
  3155. {
  3156. tree type = TREE_TYPE (DECL_RESULT (fndecl));
  3157. machine_mode mode = TYPE_MODE (type);
  3158. if (mode != BLKmode
  3159. && mode != VOIDmode
  3160. && !AGGREGATE_TYPE_P (type))
  3161. {
  3162. unsigned int align = GET_MODE_ALIGNMENT (mode);
  3163. if (crtl->stack_alignment_estimated < align)
  3164. {
  3165. gcc_assert (!crtl->stack_realign_processed);
  3166. crtl->stack_alignment_estimated = align;
  3167. }
  3168. }
  3169. }
  3170. }
  3171. /* If we are receiving a struct value address as the first argument, set up
  3172. the RTL for the function result. As this might require code to convert
  3173. the transmitted address to Pmode, we do this here to ensure that possible
  3174. preliminary conversions of the address have been emitted already. */
  3175. if (all.function_result_decl)
  3176. {
  3177. tree result = DECL_RESULT (current_function_decl);
  3178. rtx addr = DECL_RTL (all.function_result_decl);
  3179. rtx x;
  3180. if (DECL_BY_REFERENCE (result))
  3181. {
  3182. SET_DECL_VALUE_EXPR (result, all.function_result_decl);
  3183. x = addr;
  3184. }
  3185. else
  3186. {
  3187. SET_DECL_VALUE_EXPR (result,
  3188. build1 (INDIRECT_REF, TREE_TYPE (result),
  3189. all.function_result_decl));
  3190. addr = convert_memory_address (Pmode, addr);
  3191. x = gen_rtx_MEM (DECL_MODE (result), addr);
  3192. set_mem_attributes (x, result, 1);
  3193. }
  3194. DECL_HAS_VALUE_EXPR_P (result) = 1;
  3195. SET_DECL_RTL (result, x);
  3196. }
  3197. /* We have aligned all the args, so add space for the pretend args. */
  3198. crtl->args.pretend_args_size = all.pretend_args_size;
  3199. all.stack_args_size.constant += all.extra_pretend_bytes;
  3200. crtl->args.size = all.stack_args_size.constant;
  3201. /* Adjust function incoming argument size for alignment and
  3202. minimum length. */
  3203. crtl->args.size = MAX (crtl->args.size, all.reg_parm_stack_space);
  3204. crtl->args.size = CEIL_ROUND (crtl->args.size,
  3205. PARM_BOUNDARY / BITS_PER_UNIT);
  3206. #ifdef ARGS_GROW_DOWNWARD
  3207. crtl->args.arg_offset_rtx
  3208. = (all.stack_args_size.var == 0 ? GEN_INT (-all.stack_args_size.constant)
  3209. : expand_expr (size_diffop (all.stack_args_size.var,
  3210. size_int (-all.stack_args_size.constant)),
  3211. NULL_RTX, VOIDmode, EXPAND_NORMAL));
  3212. #else
  3213. crtl->args.arg_offset_rtx = ARGS_SIZE_RTX (all.stack_args_size);
  3214. #endif
  3215. /* See how many bytes, if any, of its args a function should try to pop
  3216. on return. */
  3217. crtl->args.pops_args = targetm.calls.return_pops_args (fndecl,
  3218. TREE_TYPE (fndecl),
  3219. crtl->args.size);
  3220. /* For stdarg.h function, save info about
  3221. regs and stack space used by the named args. */
  3222. crtl->args.info = all.args_so_far_v;
  3223. /* Set the rtx used for the function return value. Put this in its
  3224. own variable so any optimizers that need this information don't have
  3225. to include tree.h. Do this here so it gets done when an inlined
  3226. function gets output. */
  3227. crtl->return_rtx
  3228. = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
  3229. ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
  3230. /* If scalar return value was computed in a pseudo-reg, or was a named
  3231. return value that got dumped to the stack, copy that to the hard
  3232. return register. */
  3233. if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
  3234. {
  3235. tree decl_result = DECL_RESULT (fndecl);
  3236. rtx decl_rtl = DECL_RTL (decl_result);
  3237. if (REG_P (decl_rtl)
  3238. ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
  3239. : DECL_REGISTER (decl_result))
  3240. {
  3241. rtx real_decl_rtl;
  3242. real_decl_rtl = targetm.calls.function_value (TREE_TYPE (decl_result),
  3243. fndecl, true);
  3244. if (chkp_function_instrumented_p (fndecl))
  3245. crtl->return_bnd
  3246. = targetm.calls.chkp_function_value_bounds (TREE_TYPE (decl_result),
  3247. fndecl, true);
  3248. REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
  3249. /* The delay slot scheduler assumes that crtl->return_rtx
  3250. holds the hard register containing the return value, not a
  3251. temporary pseudo. */
  3252. crtl->return_rtx = real_decl_rtl;
  3253. }
  3254. }
  3255. }
  3256. /* A subroutine of gimplify_parameters, invoked via walk_tree.
  3257. For all seen types, gimplify their sizes. */
  3258. static tree
  3259. gimplify_parm_type (tree *tp, int *walk_subtrees, void *data)
  3260. {
  3261. tree t = *tp;
  3262. *walk_subtrees = 0;
  3263. if (TYPE_P (t))
  3264. {
  3265. if (POINTER_TYPE_P (t))
  3266. *walk_subtrees = 1;
  3267. else if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t))
  3268. && !TYPE_SIZES_GIMPLIFIED (t))
  3269. {
  3270. gimplify_type_sizes (t, (gimple_seq *) data);
  3271. *walk_subtrees = 1;
  3272. }
  3273. }
  3274. return NULL;
  3275. }
  3276. /* Gimplify the parameter list for current_function_decl. This involves
  3277. evaluating SAVE_EXPRs of variable sized parameters and generating code
  3278. to implement callee-copies reference parameters. Returns a sequence of
  3279. statements to add to the beginning of the function. */
  3280. gimple_seq
  3281. gimplify_parameters (void)
  3282. {
  3283. struct assign_parm_data_all all;
  3284. tree parm;
  3285. gimple_seq stmts = NULL;
  3286. vec<tree> fnargs;
  3287. unsigned i;
  3288. assign_parms_initialize_all (&all);
  3289. fnargs = assign_parms_augmented_arg_list (&all);
  3290. FOR_EACH_VEC_ELT (fnargs, i, parm)
  3291. {
  3292. struct assign_parm_data_one data;
  3293. /* Extract the type of PARM; adjust it according to ABI. */
  3294. assign_parm_find_data_types (&all, parm, &data);
  3295. /* Early out for errors and void parameters. */
  3296. if (data.passed_mode == VOIDmode || DECL_SIZE (parm) == NULL)
  3297. continue;
  3298. /* Update info on where next arg arrives in registers. */
  3299. targetm.calls.function_arg_advance (all.args_so_far, data.promoted_mode,
  3300. data.passed_type, data.named_arg);
  3301. /* ??? Once upon a time variable_size stuffed parameter list
  3302. SAVE_EXPRs (amongst others) onto a pending sizes list. This
  3303. turned out to be less than manageable in the gimple world.
  3304. Now we have to hunt them down ourselves. */
  3305. walk_tree_without_duplicates (&data.passed_type,
  3306. gimplify_parm_type, &stmts);
  3307. if (TREE_CODE (DECL_SIZE_UNIT (parm)) != INTEGER_CST)
  3308. {
  3309. gimplify_one_sizepos (&DECL_SIZE (parm), &stmts);
  3310. gimplify_one_sizepos (&DECL_SIZE_UNIT (parm), &stmts);
  3311. }
  3312. if (data.passed_pointer)
  3313. {
  3314. tree type = TREE_TYPE (data.passed_type);
  3315. if (reference_callee_copied (&all.args_so_far_v, TYPE_MODE (type),
  3316. type, data.named_arg))
  3317. {
  3318. tree local, t;
  3319. /* For constant-sized objects, this is trivial; for
  3320. variable-sized objects, we have to play games. */
  3321. if (TREE_CODE (DECL_SIZE_UNIT (parm)) == INTEGER_CST
  3322. && !(flag_stack_check == GENERIC_STACK_CHECK
  3323. && compare_tree_int (DECL_SIZE_UNIT (parm),
  3324. STACK_CHECK_MAX_VAR_SIZE) > 0))
  3325. {
  3326. local = create_tmp_var (type, get_name (parm));
  3327. DECL_IGNORED_P (local) = 0;
  3328. /* If PARM was addressable, move that flag over
  3329. to the local copy, as its address will be taken,
  3330. not the PARMs. Keep the parms address taken
  3331. as we'll query that flag during gimplification. */
  3332. if (TREE_ADDRESSABLE (parm))
  3333. TREE_ADDRESSABLE (local) = 1;
  3334. else if (TREE_CODE (type) == COMPLEX_TYPE
  3335. || TREE_CODE (type) == VECTOR_TYPE)
  3336. DECL_GIMPLE_REG_P (local) = 1;
  3337. }
  3338. else
  3339. {
  3340. tree ptr_type, addr;
  3341. ptr_type = build_pointer_type (type);
  3342. addr = create_tmp_reg (ptr_type, get_name (parm));
  3343. DECL_IGNORED_P (addr) = 0;
  3344. local = build_fold_indirect_ref (addr);
  3345. t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
  3346. t = build_call_expr (t, 2, DECL_SIZE_UNIT (parm),
  3347. size_int (DECL_ALIGN (parm)));
  3348. /* The call has been built for a variable-sized object. */
  3349. CALL_ALLOCA_FOR_VAR_P (t) = 1;
  3350. t = fold_convert (ptr_type, t);
  3351. t = build2 (MODIFY_EXPR, TREE_TYPE (addr), addr, t);
  3352. gimplify_and_add (t, &stmts);
  3353. }
  3354. gimplify_assign (local, parm, &stmts);
  3355. SET_DECL_VALUE_EXPR (parm, local);
  3356. DECL_HAS_VALUE_EXPR_P (parm) = 1;
  3357. }
  3358. }
  3359. }
  3360. fnargs.release ();
  3361. return stmts;
  3362. }
  3363. /* Compute the size and offset from the start of the stacked arguments for a
  3364. parm passed in mode PASSED_MODE and with type TYPE.
  3365. INITIAL_OFFSET_PTR points to the current offset into the stacked
  3366. arguments.
  3367. The starting offset and size for this parm are returned in
  3368. LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
  3369. nonzero, the offset is that of stack slot, which is returned in
  3370. LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
  3371. padding required from the initial offset ptr to the stack slot.
  3372. IN_REGS is nonzero if the argument will be passed in registers. It will
  3373. never be set if REG_PARM_STACK_SPACE is not defined.
  3374. REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
  3375. for arguments which are passed in registers.
  3376. FNDECL is the function in which the argument was defined.
  3377. There are two types of rounding that are done. The first, controlled by
  3378. TARGET_FUNCTION_ARG_BOUNDARY, forces the offset from the start of the
  3379. argument list to be aligned to the specific boundary (in bits). This
  3380. rounding affects the initial and starting offsets, but not the argument
  3381. size.
  3382. The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
  3383. optionally rounds the size of the parm to PARM_BOUNDARY. The
  3384. initial offset is not affected by this rounding, while the size always
  3385. is and the starting offset may be. */
  3386. /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
  3387. INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
  3388. callers pass in the total size of args so far as
  3389. INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
  3390. void
  3391. locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs,
  3392. int reg_parm_stack_space, int partial,
  3393. tree fndecl ATTRIBUTE_UNUSED,
  3394. struct args_size *initial_offset_ptr,
  3395. struct locate_and_pad_arg_data *locate)
  3396. {
  3397. tree sizetree;
  3398. enum direction where_pad;
  3399. unsigned int boundary, round_boundary;
  3400. int part_size_in_regs;
  3401. /* If we have found a stack parm before we reach the end of the
  3402. area reserved for registers, skip that area. */
  3403. if (! in_regs)
  3404. {
  3405. if (reg_parm_stack_space > 0)
  3406. {
  3407. if (initial_offset_ptr->var)
  3408. {
  3409. initial_offset_ptr->var
  3410. = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
  3411. ssize_int (reg_parm_stack_space));
  3412. initial_offset_ptr->constant = 0;
  3413. }
  3414. else if (initial_offset_ptr->constant < reg_parm_stack_space)
  3415. initial_offset_ptr->constant = reg_parm_stack_space;
  3416. }
  3417. }
  3418. part_size_in_regs = (reg_parm_stack_space == 0 ? partial : 0);
  3419. sizetree
  3420. = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
  3421. where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
  3422. boundary = targetm.calls.function_arg_boundary (passed_mode, type);
  3423. round_boundary = targetm.calls.function_arg_round_boundary (passed_mode,
  3424. type);
  3425. locate->where_pad = where_pad;
  3426. /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */
  3427. if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
  3428. boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
  3429. locate->boundary = boundary;
  3430. if (SUPPORTS_STACK_ALIGNMENT)
  3431. {
  3432. /* stack_alignment_estimated can't change after stack has been
  3433. realigned. */
  3434. if (crtl->stack_alignment_estimated < boundary)
  3435. {
  3436. if (!crtl->stack_realign_processed)
  3437. crtl->stack_alignment_estimated = boundary;
  3438. else
  3439. {
  3440. /* If stack is realigned and stack alignment value
  3441. hasn't been finalized, it is OK not to increase
  3442. stack_alignment_estimated. The bigger alignment
  3443. requirement is recorded in stack_alignment_needed
  3444. below. */
  3445. gcc_assert (!crtl->stack_realign_finalized
  3446. && crtl->stack_realign_needed);
  3447. }
  3448. }
  3449. }
  3450. /* Remember if the outgoing parameter requires extra alignment on the
  3451. calling function side. */
  3452. if (crtl->stack_alignment_needed < boundary)
  3453. crtl->stack_alignment_needed = boundary;
  3454. if (crtl->preferred_stack_boundary < boundary)
  3455. crtl->preferred_stack_boundary = boundary;
  3456. #ifdef ARGS_GROW_DOWNWARD
  3457. locate->slot_offset.constant = -initial_offset_ptr->constant;
  3458. if (initial_offset_ptr->var)
  3459. locate->slot_offset.var = size_binop (MINUS_EXPR, ssize_int (0),
  3460. initial_offset_ptr->var);
  3461. {
  3462. tree s2 = sizetree;
  3463. if (where_pad != none
  3464. && (!tree_fits_uhwi_p (sizetree)
  3465. || (tree_to_uhwi (sizetree) * BITS_PER_UNIT) % round_boundary))
  3466. s2 = round_up (s2, round_boundary / BITS_PER_UNIT);
  3467. SUB_PARM_SIZE (locate->slot_offset, s2);
  3468. }
  3469. locate->slot_offset.constant += part_size_in_regs;
  3470. if (!in_regs || reg_parm_stack_space > 0)
  3471. pad_to_arg_alignment (&locate->slot_offset, boundary,
  3472. &locate->alignment_pad);
  3473. locate->size.constant = (-initial_offset_ptr->constant
  3474. - locate->slot_offset.constant);
  3475. if (initial_offset_ptr->var)
  3476. locate->size.var = size_binop (MINUS_EXPR,
  3477. size_binop (MINUS_EXPR,
  3478. ssize_int (0),
  3479. initial_offset_ptr->var),
  3480. locate->slot_offset.var);
  3481. /* Pad_below needs the pre-rounded size to know how much to pad
  3482. below. */
  3483. locate->offset = locate->slot_offset;
  3484. if (where_pad == downward)
  3485. pad_below (&locate->offset, passed_mode, sizetree);
  3486. #else /* !ARGS_GROW_DOWNWARD */
  3487. if (!in_regs || reg_parm_stack_space > 0)
  3488. pad_to_arg_alignment (initial_offset_ptr, boundary,
  3489. &locate->alignment_pad);
  3490. locate->slot_offset = *initial_offset_ptr;
  3491. #ifdef PUSH_ROUNDING
  3492. if (passed_mode != BLKmode)
  3493. sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
  3494. #endif
  3495. /* Pad_below needs the pre-rounded size to know how much to pad below
  3496. so this must be done before rounding up. */
  3497. locate->offset = locate->slot_offset;
  3498. if (where_pad == downward)
  3499. pad_below (&locate->offset, passed_mode, sizetree);
  3500. if (where_pad != none
  3501. && (!tree_fits_uhwi_p (sizetree)
  3502. || (tree_to_uhwi (sizetree) * BITS_PER_UNIT) % round_boundary))
  3503. sizetree = round_up (sizetree, round_boundary / BITS_PER_UNIT);
  3504. ADD_PARM_SIZE (locate->size, sizetree);
  3505. locate->size.constant -= part_size_in_regs;
  3506. #endif /* ARGS_GROW_DOWNWARD */
  3507. #ifdef FUNCTION_ARG_OFFSET
  3508. locate->offset.constant += FUNCTION_ARG_OFFSET (passed_mode, type);
  3509. #endif
  3510. }
  3511. /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
  3512. BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
  3513. static void
  3514. pad_to_arg_alignment (struct args_size *offset_ptr, int boundary,
  3515. struct args_size *alignment_pad)
  3516. {
  3517. tree save_var = NULL_TREE;
  3518. HOST_WIDE_INT save_constant = 0;
  3519. int boundary_in_bytes = boundary / BITS_PER_UNIT;
  3520. HOST_WIDE_INT sp_offset = STACK_POINTER_OFFSET;
  3521. #ifdef SPARC_STACK_BOUNDARY_HACK
  3522. /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
  3523. the real alignment of %sp. However, when it does this, the
  3524. alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
  3525. if (SPARC_STACK_BOUNDARY_HACK)
  3526. sp_offset = 0;
  3527. #endif
  3528. if (boundary > PARM_BOUNDARY)
  3529. {
  3530. save_var = offset_ptr->var;
  3531. save_constant = offset_ptr->constant;
  3532. }
  3533. alignment_pad->var = NULL_TREE;
  3534. alignment_pad->constant = 0;
  3535. if (boundary > BITS_PER_UNIT)
  3536. {
  3537. if (offset_ptr->var)
  3538. {
  3539. tree sp_offset_tree = ssize_int (sp_offset);
  3540. tree offset = size_binop (PLUS_EXPR,
  3541. ARGS_SIZE_TREE (*offset_ptr),
  3542. sp_offset_tree);
  3543. #ifdef ARGS_GROW_DOWNWARD
  3544. tree rounded = round_down (offset, boundary / BITS_PER_UNIT);
  3545. #else
  3546. tree rounded = round_up (offset, boundary / BITS_PER_UNIT);
  3547. #endif
  3548. offset_ptr->var = size_binop (MINUS_EXPR, rounded, sp_offset_tree);
  3549. /* ARGS_SIZE_TREE includes constant term. */
  3550. offset_ptr->constant = 0;
  3551. if (boundary > PARM_BOUNDARY)
  3552. alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
  3553. save_var);
  3554. }
  3555. else
  3556. {
  3557. offset_ptr->constant = -sp_offset +
  3558. #ifdef ARGS_GROW_DOWNWARD
  3559. FLOOR_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
  3560. #else
  3561. CEIL_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
  3562. #endif
  3563. if (boundary > PARM_BOUNDARY)
  3564. alignment_pad->constant = offset_ptr->constant - save_constant;
  3565. }
  3566. }
  3567. }
  3568. static void
  3569. pad_below (struct args_size *offset_ptr, machine_mode passed_mode, tree sizetree)
  3570. {
  3571. if (passed_mode != BLKmode)
  3572. {
  3573. if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
  3574. offset_ptr->constant
  3575. += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
  3576. / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
  3577. - GET_MODE_SIZE (passed_mode));
  3578. }
  3579. else
  3580. {
  3581. if (TREE_CODE (sizetree) != INTEGER_CST
  3582. || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
  3583. {
  3584. /* Round the size up to multiple of PARM_BOUNDARY bits. */
  3585. tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  3586. /* Add it in. */
  3587. ADD_PARM_SIZE (*offset_ptr, s2);
  3588. SUB_PARM_SIZE (*offset_ptr, sizetree);
  3589. }
  3590. }
  3591. }
  3592. /* True if register REGNO was alive at a place where `setjmp' was
  3593. called and was set more than once or is an argument. Such regs may
  3594. be clobbered by `longjmp'. */
  3595. static bool
  3596. regno_clobbered_at_setjmp (bitmap setjmp_crosses, int regno)
  3597. {
  3598. /* There appear to be cases where some local vars never reach the
  3599. backend but have bogus regnos. */
  3600. if (regno >= max_reg_num ())
  3601. return false;
  3602. return ((REG_N_SETS (regno) > 1
  3603. || REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)),
  3604. regno))
  3605. && REGNO_REG_SET_P (setjmp_crosses, regno));
  3606. }
  3607. /* Walk the tree of blocks describing the binding levels within a
  3608. function and warn about variables the might be killed by setjmp or
  3609. vfork. This is done after calling flow_analysis before register
  3610. allocation since that will clobber the pseudo-regs to hard
  3611. regs. */
  3612. static void
  3613. setjmp_vars_warning (bitmap setjmp_crosses, tree block)
  3614. {
  3615. tree decl, sub;
  3616. for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
  3617. {
  3618. if (TREE_CODE (decl) == VAR_DECL
  3619. && DECL_RTL_SET_P (decl)
  3620. && REG_P (DECL_RTL (decl))
  3621. && regno_clobbered_at_setjmp (setjmp_crosses, REGNO (DECL_RTL (decl))))
  3622. warning (OPT_Wclobbered, "variable %q+D might be clobbered by"
  3623. " %<longjmp%> or %<vfork%>", decl);
  3624. }
  3625. for (sub = BLOCK_SUBBLOCKS (block); sub; sub = BLOCK_CHAIN (sub))
  3626. setjmp_vars_warning (setjmp_crosses, sub);
  3627. }
  3628. /* Do the appropriate part of setjmp_vars_warning
  3629. but for arguments instead of local variables. */
  3630. static void
  3631. setjmp_args_warning (bitmap setjmp_crosses)
  3632. {
  3633. tree decl;
  3634. for (decl = DECL_ARGUMENTS (current_function_decl);
  3635. decl; decl = DECL_CHAIN (decl))
  3636. if (DECL_RTL (decl) != 0
  3637. && REG_P (DECL_RTL (decl))
  3638. && regno_clobbered_at_setjmp (setjmp_crosses, REGNO (DECL_RTL (decl))))
  3639. warning (OPT_Wclobbered,
  3640. "argument %q+D might be clobbered by %<longjmp%> or %<vfork%>",
  3641. decl);
  3642. }
  3643. /* Generate warning messages for variables live across setjmp. */
  3644. void
  3645. generate_setjmp_warnings (void)
  3646. {
  3647. bitmap setjmp_crosses = regstat_get_setjmp_crosses ();
  3648. if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS
  3649. || bitmap_empty_p (setjmp_crosses))
  3650. return;
  3651. setjmp_vars_warning (setjmp_crosses, DECL_INITIAL (current_function_decl));
  3652. setjmp_args_warning (setjmp_crosses);
  3653. }
  3654. /* Reverse the order of elements in the fragment chain T of blocks,
  3655. and return the new head of the chain (old last element).
  3656. In addition to that clear BLOCK_SAME_RANGE flags when needed
  3657. and adjust BLOCK_SUPERCONTEXT from the super fragment to
  3658. its super fragment origin. */
  3659. static tree
  3660. block_fragments_nreverse (tree t)
  3661. {
  3662. tree prev = 0, block, next, prev_super = 0;
  3663. tree super = BLOCK_SUPERCONTEXT (t);
  3664. if (BLOCK_FRAGMENT_ORIGIN (super))
  3665. super = BLOCK_FRAGMENT_ORIGIN (super);
  3666. for (block = t; block; block = next)
  3667. {
  3668. next = BLOCK_FRAGMENT_CHAIN (block);
  3669. BLOCK_FRAGMENT_CHAIN (block) = prev;
  3670. if ((prev && !BLOCK_SAME_RANGE (prev))
  3671. || (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (block))
  3672. != prev_super))
  3673. BLOCK_SAME_RANGE (block) = 0;
  3674. prev_super = BLOCK_SUPERCONTEXT (block);
  3675. BLOCK_SUPERCONTEXT (block) = super;
  3676. prev = block;
  3677. }
  3678. t = BLOCK_FRAGMENT_ORIGIN (t);
  3679. if (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (t))
  3680. != prev_super)
  3681. BLOCK_SAME_RANGE (t) = 0;
  3682. BLOCK_SUPERCONTEXT (t) = super;
  3683. return prev;
  3684. }
  3685. /* Reverse the order of elements in the chain T of blocks,
  3686. and return the new head of the chain (old last element).
  3687. Also do the same on subblocks and reverse the order of elements
  3688. in BLOCK_FRAGMENT_CHAIN as well. */
  3689. static tree
  3690. blocks_nreverse_all (tree t)
  3691. {
  3692. tree prev = 0, block, next;
  3693. for (block = t; block; block = next)
  3694. {
  3695. next = BLOCK_CHAIN (block);
  3696. BLOCK_CHAIN (block) = prev;
  3697. if (BLOCK_FRAGMENT_CHAIN (block)
  3698. && BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE)
  3699. {
  3700. BLOCK_FRAGMENT_CHAIN (block)
  3701. = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block));
  3702. if (!BLOCK_SAME_RANGE (BLOCK_FRAGMENT_CHAIN (block)))
  3703. BLOCK_SAME_RANGE (block) = 0;
  3704. }
  3705. BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block));
  3706. prev = block;
  3707. }
  3708. return prev;
  3709. }
  3710. /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
  3711. and create duplicate blocks. */
  3712. /* ??? Need an option to either create block fragments or to create
  3713. abstract origin duplicates of a source block. It really depends
  3714. on what optimization has been performed. */
  3715. void
  3716. reorder_blocks (void)
  3717. {
  3718. tree block = DECL_INITIAL (current_function_decl);
  3719. if (block == NULL_TREE)
  3720. return;
  3721. auto_vec<tree, 10> block_stack;
  3722. /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
  3723. clear_block_marks (block);
  3724. /* Prune the old trees away, so that they don't get in the way. */
  3725. BLOCK_SUBBLOCKS (block) = NULL_TREE;
  3726. BLOCK_CHAIN (block) = NULL_TREE;
  3727. /* Recreate the block tree from the note nesting. */
  3728. reorder_blocks_1 (get_insns (), block, &block_stack);
  3729. BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block));
  3730. }
  3731. /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
  3732. void
  3733. clear_block_marks (tree block)
  3734. {
  3735. while (block)
  3736. {
  3737. TREE_ASM_WRITTEN (block) = 0;
  3738. clear_block_marks (BLOCK_SUBBLOCKS (block));
  3739. block = BLOCK_CHAIN (block);
  3740. }
  3741. }
  3742. static void
  3743. reorder_blocks_1 (rtx_insn *insns, tree current_block,
  3744. vec<tree> *p_block_stack)
  3745. {
  3746. rtx_insn *insn;
  3747. tree prev_beg = NULL_TREE, prev_end = NULL_TREE;
  3748. for (insn = insns; insn; insn = NEXT_INSN (insn))
  3749. {
  3750. if (NOTE_P (insn))
  3751. {
  3752. if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_BEG)
  3753. {
  3754. tree block = NOTE_BLOCK (insn);
  3755. tree origin;
  3756. gcc_assert (BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE);
  3757. origin = block;
  3758. if (prev_end)
  3759. BLOCK_SAME_RANGE (prev_end) = 0;
  3760. prev_end = NULL_TREE;
  3761. /* If we have seen this block before, that means it now
  3762. spans multiple address regions. Create a new fragment. */
  3763. if (TREE_ASM_WRITTEN (block))
  3764. {
  3765. tree new_block = copy_node (block);
  3766. BLOCK_SAME_RANGE (new_block) = 0;
  3767. BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
  3768. BLOCK_FRAGMENT_CHAIN (new_block)
  3769. = BLOCK_FRAGMENT_CHAIN (origin);
  3770. BLOCK_FRAGMENT_CHAIN (origin) = new_block;
  3771. NOTE_BLOCK (insn) = new_block;
  3772. block = new_block;
  3773. }
  3774. if (prev_beg == current_block && prev_beg)
  3775. BLOCK_SAME_RANGE (block) = 1;
  3776. prev_beg = origin;
  3777. BLOCK_SUBBLOCKS (block) = 0;
  3778. TREE_ASM_WRITTEN (block) = 1;
  3779. /* When there's only one block for the entire function,
  3780. current_block == block and we mustn't do this, it
  3781. will cause infinite recursion. */
  3782. if (block != current_block)
  3783. {
  3784. tree super;
  3785. if (block != origin)
  3786. gcc_assert (BLOCK_SUPERCONTEXT (origin) == current_block
  3787. || BLOCK_FRAGMENT_ORIGIN (BLOCK_SUPERCONTEXT
  3788. (origin))
  3789. == current_block);
  3790. if (p_block_stack->is_empty ())
  3791. super = current_block;
  3792. else
  3793. {
  3794. super = p_block_stack->last ();
  3795. gcc_assert (super == current_block
  3796. || BLOCK_FRAGMENT_ORIGIN (super)
  3797. == current_block);
  3798. }
  3799. BLOCK_SUPERCONTEXT (block) = super;
  3800. BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
  3801. BLOCK_SUBBLOCKS (current_block) = block;
  3802. current_block = origin;
  3803. }
  3804. p_block_stack->safe_push (block);
  3805. }
  3806. else if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_END)
  3807. {
  3808. NOTE_BLOCK (insn) = p_block_stack->pop ();
  3809. current_block = BLOCK_SUPERCONTEXT (current_block);
  3810. if (BLOCK_FRAGMENT_ORIGIN (current_block))
  3811. current_block = BLOCK_FRAGMENT_ORIGIN (current_block);
  3812. prev_beg = NULL_TREE;
  3813. prev_end = BLOCK_SAME_RANGE (NOTE_BLOCK (insn))
  3814. ? NOTE_BLOCK (insn) : NULL_TREE;
  3815. }
  3816. }
  3817. else
  3818. {
  3819. prev_beg = NULL_TREE;
  3820. if (prev_end)
  3821. BLOCK_SAME_RANGE (prev_end) = 0;
  3822. prev_end = NULL_TREE;
  3823. }
  3824. }
  3825. }
  3826. /* Reverse the order of elements in the chain T of blocks,
  3827. and return the new head of the chain (old last element). */
  3828. tree
  3829. blocks_nreverse (tree t)
  3830. {
  3831. tree prev = 0, block, next;
  3832. for (block = t; block; block = next)
  3833. {
  3834. next = BLOCK_CHAIN (block);
  3835. BLOCK_CHAIN (block) = prev;
  3836. prev = block;
  3837. }
  3838. return prev;
  3839. }
  3840. /* Concatenate two chains of blocks (chained through BLOCK_CHAIN)
  3841. by modifying the last node in chain 1 to point to chain 2. */
  3842. tree
  3843. block_chainon (tree op1, tree op2)
  3844. {
  3845. tree t1;
  3846. if (!op1)
  3847. return op2;
  3848. if (!op2)
  3849. return op1;
  3850. for (t1 = op1; BLOCK_CHAIN (t1); t1 = BLOCK_CHAIN (t1))
  3851. continue;
  3852. BLOCK_CHAIN (t1) = op2;
  3853. #ifdef ENABLE_TREE_CHECKING
  3854. {
  3855. tree t2;
  3856. for (t2 = op2; t2; t2 = BLOCK_CHAIN (t2))
  3857. gcc_assert (t2 != t1);
  3858. }
  3859. #endif
  3860. return op1;
  3861. }
  3862. /* Count the subblocks of the list starting with BLOCK. If VECTOR is
  3863. non-NULL, list them all into VECTOR, in a depth-first preorder
  3864. traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
  3865. blocks. */
  3866. static int
  3867. all_blocks (tree block, tree *vector)
  3868. {
  3869. int n_blocks = 0;
  3870. while (block)
  3871. {
  3872. TREE_ASM_WRITTEN (block) = 0;
  3873. /* Record this block. */
  3874. if (vector)
  3875. vector[n_blocks] = block;
  3876. ++n_blocks;
  3877. /* Record the subblocks, and their subblocks... */
  3878. n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
  3879. vector ? vector + n_blocks : 0);
  3880. block = BLOCK_CHAIN (block);
  3881. }
  3882. return n_blocks;
  3883. }
  3884. /* Return a vector containing all the blocks rooted at BLOCK. The
  3885. number of elements in the vector is stored in N_BLOCKS_P. The
  3886. vector is dynamically allocated; it is the caller's responsibility
  3887. to call `free' on the pointer returned. */
  3888. static tree *
  3889. get_block_vector (tree block, int *n_blocks_p)
  3890. {
  3891. tree *block_vector;
  3892. *n_blocks_p = all_blocks (block, NULL);
  3893. block_vector = XNEWVEC (tree, *n_blocks_p);
  3894. all_blocks (block, block_vector);
  3895. return block_vector;
  3896. }
  3897. static GTY(()) int next_block_index = 2;
  3898. /* Set BLOCK_NUMBER for all the blocks in FN. */
  3899. void
  3900. number_blocks (tree fn)
  3901. {
  3902. int i;
  3903. int n_blocks;
  3904. tree *block_vector;
  3905. /* For SDB and XCOFF debugging output, we start numbering the blocks
  3906. from 1 within each function, rather than keeping a running
  3907. count. */
  3908. #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
  3909. if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
  3910. next_block_index = 1;
  3911. #endif
  3912. block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
  3913. /* The top-level BLOCK isn't numbered at all. */
  3914. for (i = 1; i < n_blocks; ++i)
  3915. /* We number the blocks from two. */
  3916. BLOCK_NUMBER (block_vector[i]) = next_block_index++;
  3917. free (block_vector);
  3918. return;
  3919. }
  3920. /* If VAR is present in a subblock of BLOCK, return the subblock. */
  3921. DEBUG_FUNCTION tree
  3922. debug_find_var_in_block_tree (tree var, tree block)
  3923. {
  3924. tree t;
  3925. for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
  3926. if (t == var)
  3927. return block;
  3928. for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
  3929. {
  3930. tree ret = debug_find_var_in_block_tree (var, t);
  3931. if (ret)
  3932. return ret;
  3933. }
  3934. return NULL_TREE;
  3935. }
  3936. /* Keep track of whether we're in a dummy function context. If we are,
  3937. we don't want to invoke the set_current_function hook, because we'll
  3938. get into trouble if the hook calls target_reinit () recursively or
  3939. when the initial initialization is not yet complete. */
  3940. static bool in_dummy_function;
  3941. /* Invoke the target hook when setting cfun. Update the optimization options
  3942. if the function uses different options than the default. */
  3943. static void
  3944. invoke_set_current_function_hook (tree fndecl)
  3945. {
  3946. if (!in_dummy_function)
  3947. {
  3948. tree opts = ((fndecl)
  3949. ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl)
  3950. : optimization_default_node);
  3951. if (!opts)
  3952. opts = optimization_default_node;
  3953. /* Change optimization options if needed. */
  3954. if (optimization_current_node != opts)
  3955. {
  3956. optimization_current_node = opts;
  3957. cl_optimization_restore (&global_options, TREE_OPTIMIZATION (opts));
  3958. }
  3959. targetm.set_current_function (fndecl);
  3960. this_fn_optabs = this_target_optabs;
  3961. if (opts != optimization_default_node)
  3962. {
  3963. init_tree_optimization_optabs (opts);
  3964. if (TREE_OPTIMIZATION_OPTABS (opts))
  3965. this_fn_optabs = (struct target_optabs *)
  3966. TREE_OPTIMIZATION_OPTABS (opts);
  3967. }
  3968. }
  3969. }
  3970. /* cfun should never be set directly; use this function. */
  3971. void
  3972. set_cfun (struct function *new_cfun)
  3973. {
  3974. if (cfun != new_cfun)
  3975. {
  3976. cfun = new_cfun;
  3977. invoke_set_current_function_hook (new_cfun ? new_cfun->decl : NULL_TREE);
  3978. }
  3979. }
  3980. /* Initialized with NOGC, making this poisonous to the garbage collector. */
  3981. static vec<function_p> cfun_stack;
  3982. /* Push the current cfun onto the stack, and set cfun to new_cfun. Also set
  3983. current_function_decl accordingly. */
  3984. void
  3985. push_cfun (struct function *new_cfun)
  3986. {
  3987. gcc_assert ((!cfun && !current_function_decl)
  3988. || (cfun && current_function_decl == cfun->decl));
  3989. cfun_stack.safe_push (cfun);
  3990. current_function_decl = new_cfun ? new_cfun->decl : NULL_TREE;
  3991. set_cfun (new_cfun);
  3992. }
  3993. /* Pop cfun from the stack. Also set current_function_decl accordingly. */
  3994. void
  3995. pop_cfun (void)
  3996. {
  3997. struct function *new_cfun = cfun_stack.pop ();
  3998. /* When in_dummy_function, we do have a cfun but current_function_decl is
  3999. NULL. We also allow pushing NULL cfun and subsequently changing
  4000. current_function_decl to something else and have both restored by
  4001. pop_cfun. */
  4002. gcc_checking_assert (in_dummy_function
  4003. || !cfun
  4004. || current_function_decl == cfun->decl);
  4005. set_cfun (new_cfun);
  4006. current_function_decl = new_cfun ? new_cfun->decl : NULL_TREE;
  4007. }
  4008. /* Return value of funcdef and increase it. */
  4009. int
  4010. get_next_funcdef_no (void)
  4011. {
  4012. return funcdef_no++;
  4013. }
  4014. /* Return value of funcdef. */
  4015. int
  4016. get_last_funcdef_no (void)
  4017. {
  4018. return funcdef_no;
  4019. }
  4020. /* Allocate a function structure for FNDECL and set its contents
  4021. to the defaults. Set cfun to the newly-allocated object.
  4022. Some of the helper functions invoked during initialization assume
  4023. that cfun has already been set. Therefore, assign the new object
  4024. directly into cfun and invoke the back end hook explicitly at the
  4025. very end, rather than initializing a temporary and calling set_cfun
  4026. on it.
  4027. ABSTRACT_P is true if this is a function that will never be seen by
  4028. the middle-end. Such functions are front-end concepts (like C++
  4029. function templates) that do not correspond directly to functions
  4030. placed in object files. */
  4031. void
  4032. allocate_struct_function (tree fndecl, bool abstract_p)
  4033. {
  4034. tree fntype = fndecl ? TREE_TYPE (fndecl) : NULL_TREE;
  4035. cfun = ggc_cleared_alloc<function> ();
  4036. init_eh_for_function ();
  4037. if (init_machine_status)
  4038. cfun->machine = (*init_machine_status) ();
  4039. #ifdef OVERRIDE_ABI_FORMAT
  4040. OVERRIDE_ABI_FORMAT (fndecl);
  4041. #endif
  4042. if (fndecl != NULL_TREE)
  4043. {
  4044. DECL_STRUCT_FUNCTION (fndecl) = cfun;
  4045. cfun->decl = fndecl;
  4046. current_function_funcdef_no = get_next_funcdef_no ();
  4047. }
  4048. invoke_set_current_function_hook (fndecl);
  4049. if (fndecl != NULL_TREE)
  4050. {
  4051. tree result = DECL_RESULT (fndecl);
  4052. if (!abstract_p && aggregate_value_p (result, fndecl))
  4053. {
  4054. #ifdef PCC_STATIC_STRUCT_RETURN
  4055. cfun->returns_pcc_struct = 1;
  4056. #endif
  4057. cfun->returns_struct = 1;
  4058. }
  4059. cfun->stdarg = stdarg_p (fntype);
  4060. /* Assume all registers in stdarg functions need to be saved. */
  4061. cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE;
  4062. cfun->va_list_fpr_size = VA_LIST_MAX_FPR_SIZE;
  4063. /* ??? This could be set on a per-function basis by the front-end
  4064. but is this worth the hassle? */
  4065. cfun->can_throw_non_call_exceptions = flag_non_call_exceptions;
  4066. cfun->can_delete_dead_exceptions = flag_delete_dead_exceptions;
  4067. if (!profile_flag && !flag_instrument_function_entry_exit)
  4068. DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl) = 1;
  4069. }
  4070. }
  4071. /* This is like allocate_struct_function, but pushes a new cfun for FNDECL
  4072. instead of just setting it. */
  4073. void
  4074. push_struct_function (tree fndecl)
  4075. {
  4076. /* When in_dummy_function we might be in the middle of a pop_cfun and
  4077. current_function_decl and cfun may not match. */
  4078. gcc_assert (in_dummy_function
  4079. || (!cfun && !current_function_decl)
  4080. || (cfun && current_function_decl == cfun->decl));
  4081. cfun_stack.safe_push (cfun);
  4082. current_function_decl = fndecl;
  4083. allocate_struct_function (fndecl, false);
  4084. }
  4085. /* Reset crtl and other non-struct-function variables to defaults as
  4086. appropriate for emitting rtl at the start of a function. */
  4087. static void
  4088. prepare_function_start (void)
  4089. {
  4090. gcc_assert (!crtl->emit.x_last_insn);
  4091. init_temp_slots ();
  4092. init_emit ();
  4093. init_varasm_status ();
  4094. init_expr ();
  4095. default_rtl_profile ();
  4096. if (flag_stack_usage_info)
  4097. {
  4098. cfun->su = ggc_cleared_alloc<stack_usage> ();
  4099. cfun->su->static_stack_size = -1;
  4100. }
  4101. cse_not_expected = ! optimize;
  4102. /* Caller save not needed yet. */
  4103. caller_save_needed = 0;
  4104. /* We haven't done register allocation yet. */
  4105. reg_renumber = 0;
  4106. /* Indicate that we have not instantiated virtual registers yet. */
  4107. virtuals_instantiated = 0;
  4108. /* Indicate that we want CONCATs now. */
  4109. generating_concat_p = 1;
  4110. /* Indicate we have no need of a frame pointer yet. */
  4111. frame_pointer_needed = 0;
  4112. }
  4113. /* Initialize the rtl expansion mechanism so that we can do simple things
  4114. like generate sequences. This is used to provide a context during global
  4115. initialization of some passes. You must call expand_dummy_function_end
  4116. to exit this context. */
  4117. void
  4118. init_dummy_function_start (void)
  4119. {
  4120. gcc_assert (!in_dummy_function);
  4121. in_dummy_function = true;
  4122. push_struct_function (NULL_TREE);
  4123. prepare_function_start ();
  4124. }
  4125. /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
  4126. and initialize static variables for generating RTL for the statements
  4127. of the function. */
  4128. void
  4129. init_function_start (tree subr)
  4130. {
  4131. if (subr && DECL_STRUCT_FUNCTION (subr))
  4132. set_cfun (DECL_STRUCT_FUNCTION (subr));
  4133. else
  4134. allocate_struct_function (subr, false);
  4135. /* Initialize backend, if needed. */
  4136. initialize_rtl ();
  4137. prepare_function_start ();
  4138. decide_function_section (subr);
  4139. /* Warn if this value is an aggregate type,
  4140. regardless of which calling convention we are using for it. */
  4141. if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
  4142. warning (OPT_Waggregate_return, "function returns an aggregate");
  4143. }
  4144. /* Expand code to verify the stack_protect_guard. This is invoked at
  4145. the end of a function to be protected. */
  4146. #ifndef HAVE_stack_protect_test
  4147. # define HAVE_stack_protect_test 0
  4148. # define gen_stack_protect_test(x, y, z) (gcc_unreachable (), NULL_RTX)
  4149. #endif
  4150. void
  4151. stack_protect_epilogue (void)
  4152. {
  4153. tree guard_decl = targetm.stack_protect_guard ();
  4154. rtx_code_label *label = gen_label_rtx ();
  4155. rtx x, y, tmp;
  4156. x = expand_normal (crtl->stack_protect_guard);
  4157. y = expand_normal (guard_decl);
  4158. /* Allow the target to compare Y with X without leaking either into
  4159. a register. */
  4160. switch ((int) (HAVE_stack_protect_test != 0))
  4161. {
  4162. case 1:
  4163. tmp = gen_stack_protect_test (x, y, label);
  4164. if (tmp)
  4165. {
  4166. emit_insn (tmp);
  4167. break;
  4168. }
  4169. /* FALLTHRU */
  4170. default:
  4171. emit_cmp_and_jump_insns (x, y, EQ, NULL_RTX, ptr_mode, 1, label);
  4172. break;
  4173. }
  4174. /* The noreturn predictor has been moved to the tree level. The rtl-level
  4175. predictors estimate this branch about 20%, which isn't enough to get
  4176. things moved out of line. Since this is the only extant case of adding
  4177. a noreturn function at the rtl level, it doesn't seem worth doing ought
  4178. except adding the prediction by hand. */
  4179. tmp = get_last_insn ();
  4180. if (JUMP_P (tmp))
  4181. predict_insn_def (as_a <rtx_insn *> (tmp), PRED_NORETURN, TAKEN);
  4182. expand_call (targetm.stack_protect_fail (), NULL_RTX, /*ignore=*/true);
  4183. free_temp_slots ();
  4184. emit_label (label);
  4185. }
  4186. /* Start the RTL for a new function, and set variables used for
  4187. emitting RTL.
  4188. SUBR is the FUNCTION_DECL node.
  4189. PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
  4190. the function's parameters, which must be run at any return statement. */
  4191. void
  4192. expand_function_start (tree subr)
  4193. {
  4194. /* Make sure volatile mem refs aren't considered
  4195. valid operands of arithmetic insns. */
  4196. init_recog_no_volatile ();
  4197. crtl->profile
  4198. = (profile_flag
  4199. && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
  4200. crtl->limit_stack
  4201. = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
  4202. /* Make the label for return statements to jump to. Do not special
  4203. case machines with special return instructions -- they will be
  4204. handled later during jump, ifcvt, or epilogue creation. */
  4205. return_label = gen_label_rtx ();
  4206. /* Initialize rtx used to return the value. */
  4207. /* Do this before assign_parms so that we copy the struct value address
  4208. before any library calls that assign parms might generate. */
  4209. /* Decide whether to return the value in memory or in a register. */
  4210. if (aggregate_value_p (DECL_RESULT (subr), subr))
  4211. {
  4212. /* Returning something that won't go in a register. */
  4213. rtx value_address = 0;
  4214. #ifdef PCC_STATIC_STRUCT_RETURN
  4215. if (cfun->returns_pcc_struct)
  4216. {
  4217. int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
  4218. value_address = assemble_static_space (size);
  4219. }
  4220. else
  4221. #endif
  4222. {
  4223. rtx sv = targetm.calls.struct_value_rtx (TREE_TYPE (subr), 2);
  4224. /* Expect to be passed the address of a place to store the value.
  4225. If it is passed as an argument, assign_parms will take care of
  4226. it. */
  4227. if (sv)
  4228. {
  4229. value_address = gen_reg_rtx (Pmode);
  4230. emit_move_insn (value_address, sv);
  4231. }
  4232. }
  4233. if (value_address)
  4234. {
  4235. rtx x = value_address;
  4236. if (!DECL_BY_REFERENCE (DECL_RESULT (subr)))
  4237. {
  4238. x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), x);
  4239. set_mem_attributes (x, DECL_RESULT (subr), 1);
  4240. }
  4241. SET_DECL_RTL (DECL_RESULT (subr), x);
  4242. }
  4243. }
  4244. else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
  4245. /* If return mode is void, this decl rtl should not be used. */
  4246. SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
  4247. else
  4248. {
  4249. /* Compute the return values into a pseudo reg, which we will copy
  4250. into the true return register after the cleanups are done. */
  4251. tree return_type = TREE_TYPE (DECL_RESULT (subr));
  4252. if (TYPE_MODE (return_type) != BLKmode
  4253. && targetm.calls.return_in_msb (return_type))
  4254. /* expand_function_end will insert the appropriate padding in
  4255. this case. Use the return value's natural (unpadded) mode
  4256. within the function proper. */
  4257. SET_DECL_RTL (DECL_RESULT (subr),
  4258. gen_reg_rtx (TYPE_MODE (return_type)));
  4259. else
  4260. {
  4261. /* In order to figure out what mode to use for the pseudo, we
  4262. figure out what the mode of the eventual return register will
  4263. actually be, and use that. */
  4264. rtx hard_reg = hard_function_value (return_type, subr, 0, 1);
  4265. /* Structures that are returned in registers are not
  4266. aggregate_value_p, so we may see a PARALLEL or a REG. */
  4267. if (REG_P (hard_reg))
  4268. SET_DECL_RTL (DECL_RESULT (subr),
  4269. gen_reg_rtx (GET_MODE (hard_reg)));
  4270. else
  4271. {
  4272. gcc_assert (GET_CODE (hard_reg) == PARALLEL);
  4273. SET_DECL_RTL (DECL_RESULT (subr), gen_group_rtx (hard_reg));
  4274. }
  4275. }
  4276. /* Set DECL_REGISTER flag so that expand_function_end will copy the
  4277. result to the real return register(s). */
  4278. DECL_REGISTER (DECL_RESULT (subr)) = 1;
  4279. if (chkp_function_instrumented_p (current_function_decl))
  4280. {
  4281. tree return_type = TREE_TYPE (DECL_RESULT (subr));
  4282. rtx bounds = targetm.calls.chkp_function_value_bounds (return_type,
  4283. subr, 1);
  4284. SET_DECL_BOUNDS_RTL (DECL_RESULT (subr), bounds);
  4285. }
  4286. }
  4287. /* Initialize rtx for parameters and local variables.
  4288. In some cases this requires emitting insns. */
  4289. assign_parms (subr);
  4290. /* If function gets a static chain arg, store it. */
  4291. if (cfun->static_chain_decl)
  4292. {
  4293. tree parm = cfun->static_chain_decl;
  4294. rtx local, chain, insn;
  4295. local = gen_reg_rtx (Pmode);
  4296. chain = targetm.calls.static_chain (current_function_decl, true);
  4297. set_decl_incoming_rtl (parm, chain, false);
  4298. SET_DECL_RTL (parm, local);
  4299. mark_reg_pointer (local, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
  4300. insn = emit_move_insn (local, chain);
  4301. /* Mark the register as eliminable, similar to parameters. */
  4302. if (MEM_P (chain)
  4303. && reg_mentioned_p (arg_pointer_rtx, XEXP (chain, 0)))
  4304. set_dst_reg_note (insn, REG_EQUIV, chain, local);
  4305. /* If we aren't optimizing, save the static chain onto the stack. */
  4306. if (!optimize)
  4307. {
  4308. tree saved_static_chain_decl
  4309. = build_decl (DECL_SOURCE_LOCATION (parm), VAR_DECL,
  4310. DECL_NAME (parm), TREE_TYPE (parm));
  4311. rtx saved_static_chain_rtx
  4312. = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
  4313. SET_DECL_RTL (saved_static_chain_decl, saved_static_chain_rtx);
  4314. emit_move_insn (saved_static_chain_rtx, chain);
  4315. SET_DECL_VALUE_EXPR (parm, saved_static_chain_decl);
  4316. DECL_HAS_VALUE_EXPR_P (parm) = 1;
  4317. }
  4318. }
  4319. /* If the function receives a non-local goto, then store the
  4320. bits we need to restore the frame pointer. */
  4321. if (cfun->nonlocal_goto_save_area)
  4322. {
  4323. tree t_save;
  4324. rtx r_save;
  4325. tree var = TREE_OPERAND (cfun->nonlocal_goto_save_area, 0);
  4326. gcc_assert (DECL_RTL_SET_P (var));
  4327. t_save = build4 (ARRAY_REF,
  4328. TREE_TYPE (TREE_TYPE (cfun->nonlocal_goto_save_area)),
  4329. cfun->nonlocal_goto_save_area,
  4330. integer_zero_node, NULL_TREE, NULL_TREE);
  4331. r_save = expand_expr (t_save, NULL_RTX, VOIDmode, EXPAND_WRITE);
  4332. gcc_assert (GET_MODE (r_save) == Pmode);
  4333. emit_move_insn (r_save, targetm.builtin_setjmp_frame_value ());
  4334. update_nonlocal_goto_save_area ();
  4335. }
  4336. /* The following was moved from init_function_start.
  4337. The move is supposed to make sdb output more accurate. */
  4338. /* Indicate the beginning of the function body,
  4339. as opposed to parm setup. */
  4340. emit_note (NOTE_INSN_FUNCTION_BEG);
  4341. gcc_assert (NOTE_P (get_last_insn ()));
  4342. parm_birth_insn = get_last_insn ();
  4343. if (crtl->profile)
  4344. {
  4345. #ifdef PROFILE_HOOK
  4346. PROFILE_HOOK (current_function_funcdef_no);
  4347. #endif
  4348. }
  4349. /* If we are doing generic stack checking, the probe should go here. */
  4350. if (flag_stack_check == GENERIC_STACK_CHECK)
  4351. stack_check_probe_note = emit_note (NOTE_INSN_DELETED);
  4352. }
  4353. /* Undo the effects of init_dummy_function_start. */
  4354. void
  4355. expand_dummy_function_end (void)
  4356. {
  4357. gcc_assert (in_dummy_function);
  4358. /* End any sequences that failed to be closed due to syntax errors. */
  4359. while (in_sequence_p ())
  4360. end_sequence ();
  4361. /* Outside function body, can't compute type's actual size
  4362. until next function's body starts. */
  4363. free_after_parsing (cfun);
  4364. free_after_compilation (cfun);
  4365. pop_cfun ();
  4366. in_dummy_function = false;
  4367. }
  4368. /* Helper for diddle_return_value. */
  4369. void
  4370. diddle_return_value_1 (void (*doit) (rtx, void *), void *arg, rtx outgoing)
  4371. {
  4372. if (! outgoing)
  4373. return;
  4374. if (REG_P (outgoing))
  4375. (*doit) (outgoing, arg);
  4376. else if (GET_CODE (outgoing) == PARALLEL)
  4377. {
  4378. int i;
  4379. for (i = 0; i < XVECLEN (outgoing, 0); i++)
  4380. {
  4381. rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
  4382. if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
  4383. (*doit) (x, arg);
  4384. }
  4385. }
  4386. }
  4387. /* Call DOIT for each hard register used as a return value from
  4388. the current function. */
  4389. void
  4390. diddle_return_value (void (*doit) (rtx, void *), void *arg)
  4391. {
  4392. diddle_return_value_1 (doit, arg, crtl->return_rtx);
  4393. diddle_return_value_1 (doit, arg, crtl->return_bnd);
  4394. }
  4395. static void
  4396. do_clobber_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
  4397. {
  4398. emit_clobber (reg);
  4399. }
  4400. void
  4401. clobber_return_register (void)
  4402. {
  4403. diddle_return_value (do_clobber_return_reg, NULL);
  4404. /* In case we do use pseudo to return value, clobber it too. */
  4405. if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
  4406. {
  4407. tree decl_result = DECL_RESULT (current_function_decl);
  4408. rtx decl_rtl = DECL_RTL (decl_result);
  4409. if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
  4410. {
  4411. do_clobber_return_reg (decl_rtl, NULL);
  4412. }
  4413. }
  4414. }
  4415. static void
  4416. do_use_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
  4417. {
  4418. emit_use (reg);
  4419. }
  4420. static void
  4421. use_return_register (void)
  4422. {
  4423. diddle_return_value (do_use_return_reg, NULL);
  4424. }
  4425. /* Possibly warn about unused parameters. */
  4426. void
  4427. do_warn_unused_parameter (tree fn)
  4428. {
  4429. tree decl;
  4430. for (decl = DECL_ARGUMENTS (fn);
  4431. decl; decl = DECL_CHAIN (decl))
  4432. if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
  4433. && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)
  4434. && !TREE_NO_WARNING (decl))
  4435. warning (OPT_Wunused_parameter, "unused parameter %q+D", decl);
  4436. }
  4437. /* Set the location of the insn chain starting at INSN to LOC. */
  4438. static void
  4439. set_insn_locations (rtx_insn *insn, int loc)
  4440. {
  4441. while (insn != NULL)
  4442. {
  4443. if (INSN_P (insn))
  4444. INSN_LOCATION (insn) = loc;
  4445. insn = NEXT_INSN (insn);
  4446. }
  4447. }
  4448. /* Generate RTL for the end of the current function. */
  4449. void
  4450. expand_function_end (void)
  4451. {
  4452. rtx clobber_after;
  4453. /* If arg_pointer_save_area was referenced only from a nested
  4454. function, we will not have initialized it yet. Do that now. */
  4455. if (arg_pointer_save_area && ! crtl->arg_pointer_save_area_init)
  4456. get_arg_pointer_save_area ();
  4457. /* If we are doing generic stack checking and this function makes calls,
  4458. do a stack probe at the start of the function to ensure we have enough
  4459. space for another stack frame. */
  4460. if (flag_stack_check == GENERIC_STACK_CHECK)
  4461. {
  4462. rtx_insn *insn, *seq;
  4463. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  4464. if (CALL_P (insn))
  4465. {
  4466. rtx max_frame_size = GEN_INT (STACK_CHECK_MAX_FRAME_SIZE);
  4467. start_sequence ();
  4468. if (STACK_CHECK_MOVING_SP)
  4469. anti_adjust_stack_and_probe (max_frame_size, true);
  4470. else
  4471. probe_stack_range (STACK_OLD_CHECK_PROTECT, max_frame_size);
  4472. seq = get_insns ();
  4473. end_sequence ();
  4474. set_insn_locations (seq, prologue_location);
  4475. emit_insn_before (seq, stack_check_probe_note);
  4476. break;
  4477. }
  4478. }
  4479. /* End any sequences that failed to be closed due to syntax errors. */
  4480. while (in_sequence_p ())
  4481. end_sequence ();
  4482. clear_pending_stack_adjust ();
  4483. do_pending_stack_adjust ();
  4484. /* Output a linenumber for the end of the function.
  4485. SDB depends on this. */
  4486. set_curr_insn_location (input_location);
  4487. /* Before the return label (if any), clobber the return
  4488. registers so that they are not propagated live to the rest of
  4489. the function. This can only happen with functions that drop
  4490. through; if there had been a return statement, there would
  4491. have either been a return rtx, or a jump to the return label.
  4492. We delay actual code generation after the current_function_value_rtx
  4493. is computed. */
  4494. clobber_after = get_last_insn ();
  4495. /* Output the label for the actual return from the function. */
  4496. emit_label (return_label);
  4497. if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
  4498. {
  4499. /* Let except.c know where it should emit the call to unregister
  4500. the function context for sjlj exceptions. */
  4501. if (flag_exceptions)
  4502. sjlj_emit_function_exit_after (get_last_insn ());
  4503. }
  4504. else
  4505. {
  4506. /* We want to ensure that instructions that may trap are not
  4507. moved into the epilogue by scheduling, because we don't
  4508. always emit unwind information for the epilogue. */
  4509. if (cfun->can_throw_non_call_exceptions)
  4510. emit_insn (gen_blockage ());
  4511. }
  4512. /* If this is an implementation of throw, do what's necessary to
  4513. communicate between __builtin_eh_return and the epilogue. */
  4514. expand_eh_return ();
  4515. /* If scalar return value was computed in a pseudo-reg, or was a named
  4516. return value that got dumped to the stack, copy that to the hard
  4517. return register. */
  4518. if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
  4519. {
  4520. tree decl_result = DECL_RESULT (current_function_decl);
  4521. rtx decl_rtl = DECL_RTL (decl_result);
  4522. if (REG_P (decl_rtl)
  4523. ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
  4524. : DECL_REGISTER (decl_result))
  4525. {
  4526. rtx real_decl_rtl = crtl->return_rtx;
  4527. /* This should be set in assign_parms. */
  4528. gcc_assert (REG_FUNCTION_VALUE_P (real_decl_rtl));
  4529. /* If this is a BLKmode structure being returned in registers,
  4530. then use the mode computed in expand_return. Note that if
  4531. decl_rtl is memory, then its mode may have been changed,
  4532. but that crtl->return_rtx has not. */
  4533. if (GET_MODE (real_decl_rtl) == BLKmode)
  4534. PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
  4535. /* If a non-BLKmode return value should be padded at the least
  4536. significant end of the register, shift it left by the appropriate
  4537. amount. BLKmode results are handled using the group load/store
  4538. machinery. */
  4539. if (TYPE_MODE (TREE_TYPE (decl_result)) != BLKmode
  4540. && REG_P (real_decl_rtl)
  4541. && targetm.calls.return_in_msb (TREE_TYPE (decl_result)))
  4542. {
  4543. emit_move_insn (gen_rtx_REG (GET_MODE (decl_rtl),
  4544. REGNO (real_decl_rtl)),
  4545. decl_rtl);
  4546. shift_return_value (GET_MODE (decl_rtl), true, real_decl_rtl);
  4547. }
  4548. /* If a named return value dumped decl_return to memory, then
  4549. we may need to re-do the PROMOTE_MODE signed/unsigned
  4550. extension. */
  4551. else if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
  4552. {
  4553. int unsignedp = TYPE_UNSIGNED (TREE_TYPE (decl_result));
  4554. promote_function_mode (TREE_TYPE (decl_result),
  4555. GET_MODE (decl_rtl), &unsignedp,
  4556. TREE_TYPE (current_function_decl), 1);
  4557. convert_move (real_decl_rtl, decl_rtl, unsignedp);
  4558. }
  4559. else if (GET_CODE (real_decl_rtl) == PARALLEL)
  4560. {
  4561. /* If expand_function_start has created a PARALLEL for decl_rtl,
  4562. move the result to the real return registers. Otherwise, do
  4563. a group load from decl_rtl for a named return. */
  4564. if (GET_CODE (decl_rtl) == PARALLEL)
  4565. emit_group_move (real_decl_rtl, decl_rtl);
  4566. else
  4567. emit_group_load (real_decl_rtl, decl_rtl,
  4568. TREE_TYPE (decl_result),
  4569. int_size_in_bytes (TREE_TYPE (decl_result)));
  4570. }
  4571. /* In the case of complex integer modes smaller than a word, we'll
  4572. need to generate some non-trivial bitfield insertions. Do that
  4573. on a pseudo and not the hard register. */
  4574. else if (GET_CODE (decl_rtl) == CONCAT
  4575. && GET_MODE_CLASS (GET_MODE (decl_rtl)) == MODE_COMPLEX_INT
  4576. && GET_MODE_BITSIZE (GET_MODE (decl_rtl)) <= BITS_PER_WORD)
  4577. {
  4578. int old_generating_concat_p;
  4579. rtx tmp;
  4580. old_generating_concat_p = generating_concat_p;
  4581. generating_concat_p = 0;
  4582. tmp = gen_reg_rtx (GET_MODE (decl_rtl));
  4583. generating_concat_p = old_generating_concat_p;
  4584. emit_move_insn (tmp, decl_rtl);
  4585. emit_move_insn (real_decl_rtl, tmp);
  4586. }
  4587. else
  4588. emit_move_insn (real_decl_rtl, decl_rtl);
  4589. }
  4590. }
  4591. /* If returning a structure, arrange to return the address of the value
  4592. in a place where debuggers expect to find it.
  4593. If returning a structure PCC style,
  4594. the caller also depends on this value.
  4595. And cfun->returns_pcc_struct is not necessarily set. */
  4596. if ((cfun->returns_struct || cfun->returns_pcc_struct)
  4597. && !targetm.calls.omit_struct_return_reg)
  4598. {
  4599. rtx value_address = DECL_RTL (DECL_RESULT (current_function_decl));
  4600. tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
  4601. rtx outgoing;
  4602. if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
  4603. type = TREE_TYPE (type);
  4604. else
  4605. value_address = XEXP (value_address, 0);
  4606. outgoing = targetm.calls.function_value (build_pointer_type (type),
  4607. current_function_decl, true);
  4608. /* Mark this as a function return value so integrate will delete the
  4609. assignment and USE below when inlining this function. */
  4610. REG_FUNCTION_VALUE_P (outgoing) = 1;
  4611. /* The address may be ptr_mode and OUTGOING may be Pmode. */
  4612. value_address = convert_memory_address (GET_MODE (outgoing),
  4613. value_address);
  4614. emit_move_insn (outgoing, value_address);
  4615. /* Show return register used to hold result (in this case the address
  4616. of the result. */
  4617. crtl->return_rtx = outgoing;
  4618. }
  4619. /* Emit the actual code to clobber return register. Don't emit
  4620. it if clobber_after is a barrier, then the previous basic block
  4621. certainly doesn't fall thru into the exit block. */
  4622. if (!BARRIER_P (clobber_after))
  4623. {
  4624. rtx seq;
  4625. start_sequence ();
  4626. clobber_return_register ();
  4627. seq = get_insns ();
  4628. end_sequence ();
  4629. emit_insn_after (seq, clobber_after);
  4630. }
  4631. /* Output the label for the naked return from the function. */
  4632. if (naked_return_label)
  4633. emit_label (naked_return_label);
  4634. /* @@@ This is a kludge. We want to ensure that instructions that
  4635. may trap are not moved into the epilogue by scheduling, because
  4636. we don't always emit unwind information for the epilogue. */
  4637. if (cfun->can_throw_non_call_exceptions
  4638. && targetm_common.except_unwind_info (&global_options) != UI_SJLJ)
  4639. emit_insn (gen_blockage ());
  4640. /* If stack protection is enabled for this function, check the guard. */
  4641. if (crtl->stack_protect_guard)
  4642. stack_protect_epilogue ();
  4643. /* If we had calls to alloca, and this machine needs
  4644. an accurate stack pointer to exit the function,
  4645. insert some code to save and restore the stack pointer. */
  4646. if (! EXIT_IGNORE_STACK
  4647. && cfun->calls_alloca)
  4648. {
  4649. rtx tem = 0, seq;
  4650. start_sequence ();
  4651. emit_stack_save (SAVE_FUNCTION, &tem);
  4652. seq = get_insns ();
  4653. end_sequence ();
  4654. emit_insn_before (seq, parm_birth_insn);
  4655. emit_stack_restore (SAVE_FUNCTION, tem);
  4656. }
  4657. /* ??? This should no longer be necessary since stupid is no longer with
  4658. us, but there are some parts of the compiler (eg reload_combine, and
  4659. sh mach_dep_reorg) that still try and compute their own lifetime info
  4660. instead of using the general framework. */
  4661. use_return_register ();
  4662. }
  4663. rtx
  4664. get_arg_pointer_save_area (void)
  4665. {
  4666. rtx ret = arg_pointer_save_area;
  4667. if (! ret)
  4668. {
  4669. ret = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
  4670. arg_pointer_save_area = ret;
  4671. }
  4672. if (! crtl->arg_pointer_save_area_init)
  4673. {
  4674. rtx seq;
  4675. /* Save the arg pointer at the beginning of the function. The
  4676. generated stack slot may not be a valid memory address, so we
  4677. have to check it and fix it if necessary. */
  4678. start_sequence ();
  4679. emit_move_insn (validize_mem (copy_rtx (ret)),
  4680. crtl->args.internal_arg_pointer);
  4681. seq = get_insns ();
  4682. end_sequence ();
  4683. push_topmost_sequence ();
  4684. emit_insn_after (seq, entry_of_function ());
  4685. pop_topmost_sequence ();
  4686. crtl->arg_pointer_save_area_init = true;
  4687. }
  4688. return ret;
  4689. }
  4690. /* Add a list of INSNS to the hash HASHP, possibly allocating HASHP
  4691. for the first time. */
  4692. static void
  4693. record_insns (rtx_insn *insns, rtx end, hash_table<insn_cache_hasher> **hashp)
  4694. {
  4695. rtx_insn *tmp;
  4696. hash_table<insn_cache_hasher> *hash = *hashp;
  4697. if (hash == NULL)
  4698. *hashp = hash = hash_table<insn_cache_hasher>::create_ggc (17);
  4699. for (tmp = insns; tmp != end; tmp = NEXT_INSN (tmp))
  4700. {
  4701. rtx *slot = hash->find_slot (tmp, INSERT);
  4702. gcc_assert (*slot == NULL);
  4703. *slot = tmp;
  4704. }
  4705. }
  4706. /* INSN has been duplicated or replaced by as COPY, perhaps by duplicating a
  4707. basic block, splitting or peepholes. If INSN is a prologue or epilogue
  4708. insn, then record COPY as well. */
  4709. void
  4710. maybe_copy_prologue_epilogue_insn (rtx insn, rtx copy)
  4711. {
  4712. hash_table<insn_cache_hasher> *hash;
  4713. rtx *slot;
  4714. hash = epilogue_insn_hash;
  4715. if (!hash || !hash->find (insn))
  4716. {
  4717. hash = prologue_insn_hash;
  4718. if (!hash || !hash->find (insn))
  4719. return;
  4720. }
  4721. slot = hash->find_slot (copy, INSERT);
  4722. gcc_assert (*slot == NULL);
  4723. *slot = copy;
  4724. }
  4725. /* Determine if any INSNs in HASH are, or are part of, INSN. Because
  4726. we can be running after reorg, SEQUENCE rtl is possible. */
  4727. static bool
  4728. contains (const_rtx insn, hash_table<insn_cache_hasher> *hash)
  4729. {
  4730. if (hash == NULL)
  4731. return false;
  4732. if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
  4733. {
  4734. rtx_sequence *seq = as_a <rtx_sequence *> (PATTERN (insn));
  4735. int i;
  4736. for (i = seq->len () - 1; i >= 0; i--)
  4737. if (hash->find (seq->element (i)))
  4738. return true;
  4739. return false;
  4740. }
  4741. return hash->find (const_cast<rtx> (insn)) != NULL;
  4742. }
  4743. int
  4744. prologue_epilogue_contains (const_rtx insn)
  4745. {
  4746. if (contains (insn, prologue_insn_hash))
  4747. return 1;
  4748. if (contains (insn, epilogue_insn_hash))
  4749. return 1;
  4750. return 0;
  4751. }
  4752. #ifdef HAVE_return
  4753. /* Insert use of return register before the end of BB. */
  4754. static void
  4755. emit_use_return_register_into_block (basic_block bb)
  4756. {
  4757. rtx seq, insn;
  4758. start_sequence ();
  4759. use_return_register ();
  4760. seq = get_insns ();
  4761. end_sequence ();
  4762. insn = BB_END (bb);
  4763. #ifdef HAVE_cc0
  4764. if (reg_mentioned_p (cc0_rtx, PATTERN (insn)))
  4765. insn = prev_cc0_setter (insn);
  4766. #endif
  4767. emit_insn_before (seq, insn);
  4768. }
  4769. /* Create a return pattern, either simple_return or return, depending on
  4770. simple_p. */
  4771. static rtx
  4772. gen_return_pattern (bool simple_p)
  4773. {
  4774. #ifdef HAVE_simple_return
  4775. return simple_p ? gen_simple_return () : gen_return ();
  4776. #else
  4777. gcc_assert (!simple_p);
  4778. return gen_return ();
  4779. #endif
  4780. }
  4781. /* Insert an appropriate return pattern at the end of block BB. This
  4782. also means updating block_for_insn appropriately. SIMPLE_P is
  4783. the same as in gen_return_pattern and passed to it. */
  4784. void
  4785. emit_return_into_block (bool simple_p, basic_block bb)
  4786. {
  4787. rtx jump, pat;
  4788. jump = emit_jump_insn_after (gen_return_pattern (simple_p), BB_END (bb));
  4789. pat = PATTERN (jump);
  4790. if (GET_CODE (pat) == PARALLEL)
  4791. pat = XVECEXP (pat, 0, 0);
  4792. gcc_assert (ANY_RETURN_P (pat));
  4793. JUMP_LABEL (jump) = pat;
  4794. }
  4795. #endif
  4796. /* Set JUMP_LABEL for a return insn. */
  4797. void
  4798. set_return_jump_label (rtx returnjump)
  4799. {
  4800. rtx pat = PATTERN (returnjump);
  4801. if (GET_CODE (pat) == PARALLEL)
  4802. pat = XVECEXP (pat, 0, 0);
  4803. if (ANY_RETURN_P (pat))
  4804. JUMP_LABEL (returnjump) = pat;
  4805. else
  4806. JUMP_LABEL (returnjump) = ret_rtx;
  4807. }
  4808. #if defined (HAVE_return) || defined (HAVE_simple_return)
  4809. /* Return true if there are any active insns between HEAD and TAIL. */
  4810. bool
  4811. active_insn_between (rtx_insn *head, rtx_insn *tail)
  4812. {
  4813. while (tail)
  4814. {
  4815. if (active_insn_p (tail))
  4816. return true;
  4817. if (tail == head)
  4818. return false;
  4819. tail = PREV_INSN (tail);
  4820. }
  4821. return false;
  4822. }
  4823. /* LAST_BB is a block that exits, and empty of active instructions.
  4824. Examine its predecessors for jumps that can be converted to
  4825. (conditional) returns. */
  4826. vec<edge>
  4827. convert_jumps_to_returns (basic_block last_bb, bool simple_p,
  4828. vec<edge> unconverted ATTRIBUTE_UNUSED)
  4829. {
  4830. int i;
  4831. basic_block bb;
  4832. rtx label;
  4833. edge_iterator ei;
  4834. edge e;
  4835. auto_vec<basic_block> src_bbs (EDGE_COUNT (last_bb->preds));
  4836. FOR_EACH_EDGE (e, ei, last_bb->preds)
  4837. if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
  4838. src_bbs.quick_push (e->src);
  4839. label = BB_HEAD (last_bb);
  4840. FOR_EACH_VEC_ELT (src_bbs, i, bb)
  4841. {
  4842. rtx_insn *jump = BB_END (bb);
  4843. if (!JUMP_P (jump) || JUMP_LABEL (jump) != label)
  4844. continue;
  4845. e = find_edge (bb, last_bb);
  4846. /* If we have an unconditional jump, we can replace that
  4847. with a simple return instruction. */
  4848. if (simplejump_p (jump))
  4849. {
  4850. /* The use of the return register might be present in the exit
  4851. fallthru block. Either:
  4852. - removing the use is safe, and we should remove the use in
  4853. the exit fallthru block, or
  4854. - removing the use is not safe, and we should add it here.
  4855. For now, we conservatively choose the latter. Either of the
  4856. 2 helps in crossjumping. */
  4857. emit_use_return_register_into_block (bb);
  4858. emit_return_into_block (simple_p, bb);
  4859. delete_insn (jump);
  4860. }
  4861. /* If we have a conditional jump branching to the last
  4862. block, we can try to replace that with a conditional
  4863. return instruction. */
  4864. else if (condjump_p (jump))
  4865. {
  4866. rtx dest;
  4867. if (simple_p)
  4868. dest = simple_return_rtx;
  4869. else
  4870. dest = ret_rtx;
  4871. if (!redirect_jump (jump, dest, 0))
  4872. {
  4873. #ifdef HAVE_simple_return
  4874. if (simple_p)
  4875. {
  4876. if (dump_file)
  4877. fprintf (dump_file,
  4878. "Failed to redirect bb %d branch.\n", bb->index);
  4879. unconverted.safe_push (e);
  4880. }
  4881. #endif
  4882. continue;
  4883. }
  4884. /* See comment in simplejump_p case above. */
  4885. emit_use_return_register_into_block (bb);
  4886. /* If this block has only one successor, it both jumps
  4887. and falls through to the fallthru block, so we can't
  4888. delete the edge. */
  4889. if (single_succ_p (bb))
  4890. continue;
  4891. }
  4892. else
  4893. {
  4894. #ifdef HAVE_simple_return
  4895. if (simple_p)
  4896. {
  4897. if (dump_file)
  4898. fprintf (dump_file,
  4899. "Failed to redirect bb %d branch.\n", bb->index);
  4900. unconverted.safe_push (e);
  4901. }
  4902. #endif
  4903. continue;
  4904. }
  4905. /* Fix up the CFG for the successful change we just made. */
  4906. redirect_edge_succ (e, EXIT_BLOCK_PTR_FOR_FN (cfun));
  4907. e->flags &= ~EDGE_CROSSING;
  4908. }
  4909. src_bbs.release ();
  4910. return unconverted;
  4911. }
  4912. /* Emit a return insn for the exit fallthru block. */
  4913. basic_block
  4914. emit_return_for_exit (edge exit_fallthru_edge, bool simple_p)
  4915. {
  4916. basic_block last_bb = exit_fallthru_edge->src;
  4917. if (JUMP_P (BB_END (last_bb)))
  4918. {
  4919. last_bb = split_edge (exit_fallthru_edge);
  4920. exit_fallthru_edge = single_succ_edge (last_bb);
  4921. }
  4922. emit_barrier_after (BB_END (last_bb));
  4923. emit_return_into_block (simple_p, last_bb);
  4924. exit_fallthru_edge->flags &= ~EDGE_FALLTHRU;
  4925. return last_bb;
  4926. }
  4927. #endif
  4928. /* Generate the prologue and epilogue RTL if the machine supports it. Thread
  4929. this into place with notes indicating where the prologue ends and where
  4930. the epilogue begins. Update the basic block information when possible.
  4931. Notes on epilogue placement:
  4932. There are several kinds of edges to the exit block:
  4933. * a single fallthru edge from LAST_BB
  4934. * possibly, edges from blocks containing sibcalls
  4935. * possibly, fake edges from infinite loops
  4936. The epilogue is always emitted on the fallthru edge from the last basic
  4937. block in the function, LAST_BB, into the exit block.
  4938. If LAST_BB is empty except for a label, it is the target of every
  4939. other basic block in the function that ends in a return. If a
  4940. target has a return or simple_return pattern (possibly with
  4941. conditional variants), these basic blocks can be changed so that a
  4942. return insn is emitted into them, and their target is adjusted to
  4943. the real exit block.
  4944. Notes on shrink wrapping: We implement a fairly conservative
  4945. version of shrink-wrapping rather than the textbook one. We only
  4946. generate a single prologue and a single epilogue. This is
  4947. sufficient to catch a number of interesting cases involving early
  4948. exits.
  4949. First, we identify the blocks that require the prologue to occur before
  4950. them. These are the ones that modify a call-saved register, or reference
  4951. any of the stack or frame pointer registers. To simplify things, we then
  4952. mark everything reachable from these blocks as also requiring a prologue.
  4953. This takes care of loops automatically, and avoids the need to examine
  4954. whether MEMs reference the frame, since it is sufficient to check for
  4955. occurrences of the stack or frame pointer.
  4956. We then compute the set of blocks for which the need for a prologue
  4957. is anticipatable (borrowing terminology from the shrink-wrapping
  4958. description in Muchnick's book). These are the blocks which either
  4959. require a prologue themselves, or those that have only successors
  4960. where the prologue is anticipatable. The prologue needs to be
  4961. inserted on all edges from BB1->BB2 where BB2 is in ANTIC and BB1
  4962. is not. For the moment, we ensure that only one such edge exists.
  4963. The epilogue is placed as described above, but we make a
  4964. distinction between inserting return and simple_return patterns
  4965. when modifying other blocks that end in a return. Blocks that end
  4966. in a sibcall omit the sibcall_epilogue if the block is not in
  4967. ANTIC. */
  4968. void
  4969. thread_prologue_and_epilogue_insns (void)
  4970. {
  4971. bool inserted;
  4972. #ifdef HAVE_simple_return
  4973. vec<edge> unconverted_simple_returns = vNULL;
  4974. bitmap_head bb_flags;
  4975. #endif
  4976. rtx_insn *returnjump;
  4977. rtx_insn *epilogue_end ATTRIBUTE_UNUSED;
  4978. rtx_insn *prologue_seq ATTRIBUTE_UNUSED, *split_prologue_seq ATTRIBUTE_UNUSED;
  4979. edge e, entry_edge, orig_entry_edge, exit_fallthru_edge;
  4980. edge_iterator ei;
  4981. df_analyze ();
  4982. rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun));
  4983. inserted = false;
  4984. epilogue_end = NULL;
  4985. returnjump = NULL;
  4986. /* Can't deal with multiple successors of the entry block at the
  4987. moment. Function should always have at least one entry
  4988. point. */
  4989. gcc_assert (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
  4990. entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
  4991. orig_entry_edge = entry_edge;
  4992. split_prologue_seq = NULL;
  4993. if (flag_split_stack
  4994. && (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun->decl))
  4995. == NULL))
  4996. {
  4997. #ifndef HAVE_split_stack_prologue
  4998. gcc_unreachable ();
  4999. #else
  5000. gcc_assert (HAVE_split_stack_prologue);
  5001. start_sequence ();
  5002. emit_insn (gen_split_stack_prologue ());
  5003. split_prologue_seq = get_insns ();
  5004. end_sequence ();
  5005. record_insns (split_prologue_seq, NULL, &prologue_insn_hash);
  5006. set_insn_locations (split_prologue_seq, prologue_location);
  5007. #endif
  5008. }
  5009. prologue_seq = NULL;
  5010. #ifdef HAVE_prologue
  5011. if (HAVE_prologue)
  5012. {
  5013. start_sequence ();
  5014. rtx_insn *seq = safe_as_a <rtx_insn *> (gen_prologue ());
  5015. emit_insn (seq);
  5016. /* Insert an explicit USE for the frame pointer
  5017. if the profiling is on and the frame pointer is required. */
  5018. if (crtl->profile && frame_pointer_needed)
  5019. emit_use (hard_frame_pointer_rtx);
  5020. /* Retain a map of the prologue insns. */
  5021. record_insns (seq, NULL, &prologue_insn_hash);
  5022. emit_note (NOTE_INSN_PROLOGUE_END);
  5023. /* Ensure that instructions are not moved into the prologue when
  5024. profiling is on. The call to the profiling routine can be
  5025. emitted within the live range of a call-clobbered register. */
  5026. if (!targetm.profile_before_prologue () && crtl->profile)
  5027. emit_insn (gen_blockage ());
  5028. prologue_seq = get_insns ();
  5029. end_sequence ();
  5030. set_insn_locations (prologue_seq, prologue_location);
  5031. }
  5032. #endif
  5033. #ifdef HAVE_simple_return
  5034. bitmap_initialize (&bb_flags, &bitmap_default_obstack);
  5035. /* Try to perform a kind of shrink-wrapping, making sure the
  5036. prologue/epilogue is emitted only around those parts of the
  5037. function that require it. */
  5038. try_shrink_wrapping (&entry_edge, orig_entry_edge, &bb_flags, prologue_seq);
  5039. #endif
  5040. if (split_prologue_seq != NULL_RTX)
  5041. {
  5042. insert_insn_on_edge (split_prologue_seq, orig_entry_edge);
  5043. inserted = true;
  5044. }
  5045. if (prologue_seq != NULL_RTX)
  5046. {
  5047. insert_insn_on_edge (prologue_seq, entry_edge);
  5048. inserted = true;
  5049. }
  5050. /* If the exit block has no non-fake predecessors, we don't need
  5051. an epilogue. */
  5052. FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
  5053. if ((e->flags & EDGE_FAKE) == 0)
  5054. break;
  5055. if (e == NULL)
  5056. goto epilogue_done;
  5057. rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
  5058. exit_fallthru_edge = find_fallthru_edge (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds);
  5059. #ifdef HAVE_simple_return
  5060. if (entry_edge != orig_entry_edge)
  5061. exit_fallthru_edge
  5062. = get_unconverted_simple_return (exit_fallthru_edge, bb_flags,
  5063. &unconverted_simple_returns,
  5064. &returnjump);
  5065. #endif
  5066. #ifdef HAVE_return
  5067. if (HAVE_return)
  5068. {
  5069. if (exit_fallthru_edge == NULL)
  5070. goto epilogue_done;
  5071. if (optimize)
  5072. {
  5073. basic_block last_bb = exit_fallthru_edge->src;
  5074. if (LABEL_P (BB_HEAD (last_bb))
  5075. && !active_insn_between (BB_HEAD (last_bb), BB_END (last_bb)))
  5076. convert_jumps_to_returns (last_bb, false, vNULL);
  5077. if (EDGE_COUNT (last_bb->preds) != 0
  5078. && single_succ_p (last_bb))
  5079. {
  5080. last_bb = emit_return_for_exit (exit_fallthru_edge, false);
  5081. epilogue_end = returnjump = BB_END (last_bb);
  5082. #ifdef HAVE_simple_return
  5083. /* Emitting the return may add a basic block.
  5084. Fix bb_flags for the added block. */
  5085. if (last_bb != exit_fallthru_edge->src)
  5086. bitmap_set_bit (&bb_flags, last_bb->index);
  5087. #endif
  5088. goto epilogue_done;
  5089. }
  5090. }
  5091. }
  5092. #endif
  5093. /* A small fib -- epilogue is not yet completed, but we wish to re-use
  5094. this marker for the splits of EH_RETURN patterns, and nothing else
  5095. uses the flag in the meantime. */
  5096. epilogue_completed = 1;
  5097. #ifdef HAVE_eh_return
  5098. /* Find non-fallthru edges that end with EH_RETURN instructions. On
  5099. some targets, these get split to a special version of the epilogue
  5100. code. In order to be able to properly annotate these with unwind
  5101. info, try to split them now. If we get a valid split, drop an
  5102. EPILOGUE_BEG note and mark the insns as epilogue insns. */
  5103. FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
  5104. {
  5105. rtx_insn *prev, *last, *trial;
  5106. if (e->flags & EDGE_FALLTHRU)
  5107. continue;
  5108. last = BB_END (e->src);
  5109. if (!eh_returnjump_p (last))
  5110. continue;
  5111. prev = PREV_INSN (last);
  5112. trial = try_split (PATTERN (last), last, 1);
  5113. if (trial == last)
  5114. continue;
  5115. record_insns (NEXT_INSN (prev), NEXT_INSN (trial), &epilogue_insn_hash);
  5116. emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev);
  5117. }
  5118. #endif
  5119. /* If nothing falls through into the exit block, we don't need an
  5120. epilogue. */
  5121. if (exit_fallthru_edge == NULL)
  5122. goto epilogue_done;
  5123. #ifdef HAVE_epilogue
  5124. if (HAVE_epilogue)
  5125. {
  5126. start_sequence ();
  5127. epilogue_end = emit_note (NOTE_INSN_EPILOGUE_BEG);
  5128. rtx_insn *seq = as_a <rtx_insn *> (gen_epilogue ());
  5129. if (seq)
  5130. emit_jump_insn (seq);
  5131. /* Retain a map of the epilogue insns. */
  5132. record_insns (seq, NULL, &epilogue_insn_hash);
  5133. set_insn_locations (seq, epilogue_location);
  5134. seq = get_insns ();
  5135. returnjump = get_last_insn ();
  5136. end_sequence ();
  5137. insert_insn_on_edge (seq, exit_fallthru_edge);
  5138. inserted = true;
  5139. if (JUMP_P (returnjump))
  5140. set_return_jump_label (returnjump);
  5141. }
  5142. else
  5143. #endif
  5144. {
  5145. basic_block cur_bb;
  5146. if (! next_active_insn (BB_END (exit_fallthru_edge->src)))
  5147. goto epilogue_done;
  5148. /* We have a fall-through edge to the exit block, the source is not
  5149. at the end of the function, and there will be an assembler epilogue
  5150. at the end of the function.
  5151. We can't use force_nonfallthru here, because that would try to
  5152. use return. Inserting a jump 'by hand' is extremely messy, so
  5153. we take advantage of cfg_layout_finalize using
  5154. fixup_fallthru_exit_predecessor. */
  5155. cfg_layout_initialize (0);
  5156. FOR_EACH_BB_FN (cur_bb, cfun)
  5157. if (cur_bb->index >= NUM_FIXED_BLOCKS
  5158. && cur_bb->next_bb->index >= NUM_FIXED_BLOCKS)
  5159. cur_bb->aux = cur_bb->next_bb;
  5160. cfg_layout_finalize ();
  5161. }
  5162. epilogue_done:
  5163. default_rtl_profile ();
  5164. if (inserted)
  5165. {
  5166. sbitmap blocks;
  5167. commit_edge_insertions ();
  5168. /* Look for basic blocks within the prologue insns. */
  5169. blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
  5170. bitmap_clear (blocks);
  5171. bitmap_set_bit (blocks, entry_edge->dest->index);
  5172. bitmap_set_bit (blocks, orig_entry_edge->dest->index);
  5173. find_many_sub_basic_blocks (blocks);
  5174. sbitmap_free (blocks);
  5175. /* The epilogue insns we inserted may cause the exit edge to no longer
  5176. be fallthru. */
  5177. FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
  5178. {
  5179. if (((e->flags & EDGE_FALLTHRU) != 0)
  5180. && returnjump_p (BB_END (e->src)))
  5181. e->flags &= ~EDGE_FALLTHRU;
  5182. }
  5183. }
  5184. #ifdef HAVE_simple_return
  5185. convert_to_simple_return (entry_edge, orig_entry_edge, bb_flags, returnjump,
  5186. unconverted_simple_returns);
  5187. #endif
  5188. #ifdef HAVE_sibcall_epilogue
  5189. /* Emit sibling epilogues before any sibling call sites. */
  5190. for (ei = ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds); (e =
  5191. ei_safe_edge (ei));
  5192. )
  5193. {
  5194. basic_block bb = e->src;
  5195. rtx_insn *insn = BB_END (bb);
  5196. rtx ep_seq;
  5197. if (!CALL_P (insn)
  5198. || ! SIBLING_CALL_P (insn)
  5199. #ifdef HAVE_simple_return
  5200. || (entry_edge != orig_entry_edge
  5201. && !bitmap_bit_p (&bb_flags, bb->index))
  5202. #endif
  5203. )
  5204. {
  5205. ei_next (&ei);
  5206. continue;
  5207. }
  5208. ep_seq = gen_sibcall_epilogue ();
  5209. if (ep_seq)
  5210. {
  5211. start_sequence ();
  5212. emit_note (NOTE_INSN_EPILOGUE_BEG);
  5213. emit_insn (ep_seq);
  5214. rtx_insn *seq = get_insns ();
  5215. end_sequence ();
  5216. /* Retain a map of the epilogue insns. Used in life analysis to
  5217. avoid getting rid of sibcall epilogue insns. Do this before we
  5218. actually emit the sequence. */
  5219. record_insns (seq, NULL, &epilogue_insn_hash);
  5220. set_insn_locations (seq, epilogue_location);
  5221. emit_insn_before (seq, insn);
  5222. }
  5223. ei_next (&ei);
  5224. }
  5225. #endif
  5226. #ifdef HAVE_epilogue
  5227. if (epilogue_end)
  5228. {
  5229. rtx_insn *insn, *next;
  5230. /* Similarly, move any line notes that appear after the epilogue.
  5231. There is no need, however, to be quite so anal about the existence
  5232. of such a note. Also possibly move
  5233. NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
  5234. info generation. */
  5235. for (insn = epilogue_end; insn; insn = next)
  5236. {
  5237. next = NEXT_INSN (insn);
  5238. if (NOTE_P (insn)
  5239. && (NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG))
  5240. reorder_insns (insn, insn, PREV_INSN (epilogue_end));
  5241. }
  5242. }
  5243. #endif
  5244. #ifdef HAVE_simple_return
  5245. bitmap_clear (&bb_flags);
  5246. #endif
  5247. /* Threading the prologue and epilogue changes the artificial refs
  5248. in the entry and exit blocks. */
  5249. epilogue_completed = 1;
  5250. df_update_entry_exit_and_calls ();
  5251. }
  5252. /* Reposition the prologue-end and epilogue-begin notes after
  5253. instruction scheduling. */
  5254. void
  5255. reposition_prologue_and_epilogue_notes (void)
  5256. {
  5257. #if defined (HAVE_prologue) || defined (HAVE_epilogue) \
  5258. || defined (HAVE_sibcall_epilogue)
  5259. /* Since the hash table is created on demand, the fact that it is
  5260. non-null is a signal that it is non-empty. */
  5261. if (prologue_insn_hash != NULL)
  5262. {
  5263. size_t len = prologue_insn_hash->elements ();
  5264. rtx_insn *insn, *last = NULL, *note = NULL;
  5265. /* Scan from the beginning until we reach the last prologue insn. */
  5266. /* ??? While we do have the CFG intact, there are two problems:
  5267. (1) The prologue can contain loops (typically probing the stack),
  5268. which means that the end of the prologue isn't in the first bb.
  5269. (2) Sometimes the PROLOGUE_END note gets pushed into the next bb. */
  5270. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  5271. {
  5272. if (NOTE_P (insn))
  5273. {
  5274. if (NOTE_KIND (insn) == NOTE_INSN_PROLOGUE_END)
  5275. note = insn;
  5276. }
  5277. else if (contains (insn, prologue_insn_hash))
  5278. {
  5279. last = insn;
  5280. if (--len == 0)
  5281. break;
  5282. }
  5283. }
  5284. if (last)
  5285. {
  5286. if (note == NULL)
  5287. {
  5288. /* Scan forward looking for the PROLOGUE_END note. It should
  5289. be right at the beginning of the block, possibly with other
  5290. insn notes that got moved there. */
  5291. for (note = NEXT_INSN (last); ; note = NEXT_INSN (note))
  5292. {
  5293. if (NOTE_P (note)
  5294. && NOTE_KIND (note) == NOTE_INSN_PROLOGUE_END)
  5295. break;
  5296. }
  5297. }
  5298. /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
  5299. if (LABEL_P (last))
  5300. last = NEXT_INSN (last);
  5301. reorder_insns (note, note, last);
  5302. }
  5303. }
  5304. if (epilogue_insn_hash != NULL)
  5305. {
  5306. edge_iterator ei;
  5307. edge e;
  5308. FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
  5309. {
  5310. rtx_insn *insn, *first = NULL, *note = NULL;
  5311. basic_block bb = e->src;
  5312. /* Scan from the beginning until we reach the first epilogue insn. */
  5313. FOR_BB_INSNS (bb, insn)
  5314. {
  5315. if (NOTE_P (insn))
  5316. {
  5317. if (NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
  5318. {
  5319. note = insn;
  5320. if (first != NULL)
  5321. break;
  5322. }
  5323. }
  5324. else if (first == NULL && contains (insn, epilogue_insn_hash))
  5325. {
  5326. first = insn;
  5327. if (note != NULL)
  5328. break;
  5329. }
  5330. }
  5331. if (note)
  5332. {
  5333. /* If the function has a single basic block, and no real
  5334. epilogue insns (e.g. sibcall with no cleanup), the
  5335. epilogue note can get scheduled before the prologue
  5336. note. If we have frame related prologue insns, having
  5337. them scanned during the epilogue will result in a crash.
  5338. In this case re-order the epilogue note to just before
  5339. the last insn in the block. */
  5340. if (first == NULL)
  5341. first = BB_END (bb);
  5342. if (PREV_INSN (first) != note)
  5343. reorder_insns (note, note, PREV_INSN (first));
  5344. }
  5345. }
  5346. }
  5347. #endif /* HAVE_prologue or HAVE_epilogue */
  5348. }
  5349. /* Returns the name of function declared by FNDECL. */
  5350. const char *
  5351. fndecl_name (tree fndecl)
  5352. {
  5353. if (fndecl == NULL)
  5354. return "(nofn)";
  5355. return lang_hooks.decl_printable_name (fndecl, 2);
  5356. }
  5357. /* Returns the name of function FN. */
  5358. const char *
  5359. function_name (struct function *fn)
  5360. {
  5361. tree fndecl = (fn == NULL) ? NULL : fn->decl;
  5362. return fndecl_name (fndecl);
  5363. }
  5364. /* Returns the name of the current function. */
  5365. const char *
  5366. current_function_name (void)
  5367. {
  5368. return function_name (cfun);
  5369. }
  5370. static unsigned int
  5371. rest_of_handle_check_leaf_regs (void)
  5372. {
  5373. #ifdef LEAF_REGISTERS
  5374. crtl->uses_only_leaf_regs
  5375. = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
  5376. #endif
  5377. return 0;
  5378. }
  5379. /* Insert a TYPE into the used types hash table of CFUN. */
  5380. static void
  5381. used_types_insert_helper (tree type, struct function *func)
  5382. {
  5383. if (type != NULL && func != NULL)
  5384. {
  5385. if (func->used_types_hash == NULL)
  5386. func->used_types_hash = hash_set<tree>::create_ggc (37);
  5387. func->used_types_hash->add (type);
  5388. }
  5389. }
  5390. /* Given a type, insert it into the used hash table in cfun. */
  5391. void
  5392. used_types_insert (tree t)
  5393. {
  5394. while (POINTER_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE)
  5395. if (TYPE_NAME (t))
  5396. break;
  5397. else
  5398. t = TREE_TYPE (t);
  5399. if (TREE_CODE (t) == ERROR_MARK)
  5400. return;
  5401. if (TYPE_NAME (t) == NULL_TREE
  5402. || TYPE_NAME (t) == TYPE_NAME (TYPE_MAIN_VARIANT (t)))
  5403. t = TYPE_MAIN_VARIANT (t);
  5404. if (debug_info_level > DINFO_LEVEL_NONE)
  5405. {
  5406. if (cfun)
  5407. used_types_insert_helper (t, cfun);
  5408. else
  5409. {
  5410. /* So this might be a type referenced by a global variable.
  5411. Record that type so that we can later decide to emit its
  5412. debug information. */
  5413. vec_safe_push (types_used_by_cur_var_decl, t);
  5414. }
  5415. }
  5416. }
  5417. /* Helper to Hash a struct types_used_by_vars_entry. */
  5418. static hashval_t
  5419. hash_types_used_by_vars_entry (const struct types_used_by_vars_entry *entry)
  5420. {
  5421. gcc_assert (entry && entry->var_decl && entry->type);
  5422. return iterative_hash_object (entry->type,
  5423. iterative_hash_object (entry->var_decl, 0));
  5424. }
  5425. /* Hash function of the types_used_by_vars_entry hash table. */
  5426. hashval_t
  5427. used_type_hasher::hash (types_used_by_vars_entry *entry)
  5428. {
  5429. return hash_types_used_by_vars_entry (entry);
  5430. }
  5431. /*Equality function of the types_used_by_vars_entry hash table. */
  5432. bool
  5433. used_type_hasher::equal (types_used_by_vars_entry *e1,
  5434. types_used_by_vars_entry *e2)
  5435. {
  5436. return (e1->var_decl == e2->var_decl && e1->type == e2->type);
  5437. }
  5438. /* Inserts an entry into the types_used_by_vars_hash hash table. */
  5439. void
  5440. types_used_by_var_decl_insert (tree type, tree var_decl)
  5441. {
  5442. if (type != NULL && var_decl != NULL)
  5443. {
  5444. types_used_by_vars_entry **slot;
  5445. struct types_used_by_vars_entry e;
  5446. e.var_decl = var_decl;
  5447. e.type = type;
  5448. if (types_used_by_vars_hash == NULL)
  5449. types_used_by_vars_hash
  5450. = hash_table<used_type_hasher>::create_ggc (37);
  5451. slot = types_used_by_vars_hash->find_slot (&e, INSERT);
  5452. if (*slot == NULL)
  5453. {
  5454. struct types_used_by_vars_entry *entry;
  5455. entry = ggc_alloc<types_used_by_vars_entry> ();
  5456. entry->type = type;
  5457. entry->var_decl = var_decl;
  5458. *slot = entry;
  5459. }
  5460. }
  5461. }
  5462. namespace {
  5463. const pass_data pass_data_leaf_regs =
  5464. {
  5465. RTL_PASS, /* type */
  5466. "*leaf_regs", /* name */
  5467. OPTGROUP_NONE, /* optinfo_flags */
  5468. TV_NONE, /* tv_id */
  5469. 0, /* properties_required */
  5470. 0, /* properties_provided */
  5471. 0, /* properties_destroyed */
  5472. 0, /* todo_flags_start */
  5473. 0, /* todo_flags_finish */
  5474. };
  5475. class pass_leaf_regs : public rtl_opt_pass
  5476. {
  5477. public:
  5478. pass_leaf_regs (gcc::context *ctxt)
  5479. : rtl_opt_pass (pass_data_leaf_regs, ctxt)
  5480. {}
  5481. /* opt_pass methods: */
  5482. virtual unsigned int execute (function *)
  5483. {
  5484. return rest_of_handle_check_leaf_regs ();
  5485. }
  5486. }; // class pass_leaf_regs
  5487. } // anon namespace
  5488. rtl_opt_pass *
  5489. make_pass_leaf_regs (gcc::context *ctxt)
  5490. {
  5491. return new pass_leaf_regs (ctxt);
  5492. }
  5493. static unsigned int
  5494. rest_of_handle_thread_prologue_and_epilogue (void)
  5495. {
  5496. if (optimize)
  5497. cleanup_cfg (CLEANUP_EXPENSIVE);
  5498. /* On some machines, the prologue and epilogue code, or parts thereof,
  5499. can be represented as RTL. Doing so lets us schedule insns between
  5500. it and the rest of the code and also allows delayed branch
  5501. scheduling to operate in the epilogue. */
  5502. thread_prologue_and_epilogue_insns ();
  5503. /* Shrink-wrapping can result in unreachable edges in the epilogue,
  5504. see PR57320. */
  5505. cleanup_cfg (0);
  5506. /* The stack usage info is finalized during prologue expansion. */
  5507. if (flag_stack_usage_info)
  5508. output_stack_usage ();
  5509. return 0;
  5510. }
  5511. namespace {
  5512. const pass_data pass_data_thread_prologue_and_epilogue =
  5513. {
  5514. RTL_PASS, /* type */
  5515. "pro_and_epilogue", /* name */
  5516. OPTGROUP_NONE, /* optinfo_flags */
  5517. TV_THREAD_PROLOGUE_AND_EPILOGUE, /* tv_id */
  5518. 0, /* properties_required */
  5519. 0, /* properties_provided */
  5520. 0, /* properties_destroyed */
  5521. 0, /* todo_flags_start */
  5522. ( TODO_df_verify | TODO_df_finish ), /* todo_flags_finish */
  5523. };
  5524. class pass_thread_prologue_and_epilogue : public rtl_opt_pass
  5525. {
  5526. public:
  5527. pass_thread_prologue_and_epilogue (gcc::context *ctxt)
  5528. : rtl_opt_pass (pass_data_thread_prologue_and_epilogue, ctxt)
  5529. {}
  5530. /* opt_pass methods: */
  5531. virtual unsigned int execute (function *)
  5532. {
  5533. return rest_of_handle_thread_prologue_and_epilogue ();
  5534. }
  5535. }; // class pass_thread_prologue_and_epilogue
  5536. } // anon namespace
  5537. rtl_opt_pass *
  5538. make_pass_thread_prologue_and_epilogue (gcc::context *ctxt)
  5539. {
  5540. return new pass_thread_prologue_and_epilogue (ctxt);
  5541. }
  5542. /* This mini-pass fixes fall-out from SSA in asm statements that have
  5543. in-out constraints. Say you start with
  5544. orig = inout;
  5545. asm ("": "+mr" (inout));
  5546. use (orig);
  5547. which is transformed very early to use explicit output and match operands:
  5548. orig = inout;
  5549. asm ("": "=mr" (inout) : "0" (inout));
  5550. use (orig);
  5551. Or, after SSA and copyprop,
  5552. asm ("": "=mr" (inout_2) : "0" (inout_1));
  5553. use (inout_1);
  5554. Clearly inout_2 and inout_1 can't be coalesced easily anymore, as
  5555. they represent two separate values, so they will get different pseudo
  5556. registers during expansion. Then, since the two operands need to match
  5557. per the constraints, but use different pseudo registers, reload can
  5558. only register a reload for these operands. But reloads can only be
  5559. satisfied by hardregs, not by memory, so we need a register for this
  5560. reload, just because we are presented with non-matching operands.
  5561. So, even though we allow memory for this operand, no memory can be
  5562. used for it, just because the two operands don't match. This can
  5563. cause reload failures on register-starved targets.
  5564. So it's a symptom of reload not being able to use memory for reloads
  5565. or, alternatively it's also a symptom of both operands not coming into
  5566. reload as matching (in which case the pseudo could go to memory just
  5567. fine, as the alternative allows it, and no reload would be necessary).
  5568. We fix the latter problem here, by transforming
  5569. asm ("": "=mr" (inout_2) : "0" (inout_1));
  5570. back to
  5571. inout_2 = inout_1;
  5572. asm ("": "=mr" (inout_2) : "0" (inout_2)); */
  5573. static void
  5574. match_asm_constraints_1 (rtx_insn *insn, rtx *p_sets, int noutputs)
  5575. {
  5576. int i;
  5577. bool changed = false;
  5578. rtx op = SET_SRC (p_sets[0]);
  5579. int ninputs = ASM_OPERANDS_INPUT_LENGTH (op);
  5580. rtvec inputs = ASM_OPERANDS_INPUT_VEC (op);
  5581. bool *output_matched = XALLOCAVEC (bool, noutputs);
  5582. memset (output_matched, 0, noutputs * sizeof (bool));
  5583. for (i = 0; i < ninputs; i++)
  5584. {
  5585. rtx input, output;
  5586. rtx_insn *insns;
  5587. const char *constraint = ASM_OPERANDS_INPUT_CONSTRAINT (op, i);
  5588. char *end;
  5589. int match, j;
  5590. if (*constraint == '%')
  5591. constraint++;
  5592. match = strtoul (constraint, &end, 10);
  5593. if (end == constraint)
  5594. continue;
  5595. gcc_assert (match < noutputs);
  5596. output = SET_DEST (p_sets[match]);
  5597. input = RTVEC_ELT (inputs, i);
  5598. /* Only do the transformation for pseudos. */
  5599. if (! REG_P (output)
  5600. || rtx_equal_p (output, input)
  5601. || (GET_MODE (input) != VOIDmode
  5602. && GET_MODE (input) != GET_MODE (output)))
  5603. continue;
  5604. /* We can't do anything if the output is also used as input,
  5605. as we're going to overwrite it. */
  5606. for (j = 0; j < ninputs; j++)
  5607. if (reg_overlap_mentioned_p (output, RTVEC_ELT (inputs, j)))
  5608. break;
  5609. if (j != ninputs)
  5610. continue;
  5611. /* Avoid changing the same input several times. For
  5612. asm ("" : "=mr" (out1), "=mr" (out2) : "0" (in), "1" (in));
  5613. only change in once (to out1), rather than changing it
  5614. first to out1 and afterwards to out2. */
  5615. if (i > 0)
  5616. {
  5617. for (j = 0; j < noutputs; j++)
  5618. if (output_matched[j] && input == SET_DEST (p_sets[j]))
  5619. break;
  5620. if (j != noutputs)
  5621. continue;
  5622. }
  5623. output_matched[match] = true;
  5624. start_sequence ();
  5625. emit_move_insn (output, input);
  5626. insns = get_insns ();
  5627. end_sequence ();
  5628. emit_insn_before (insns, insn);
  5629. /* Now replace all mentions of the input with output. We can't
  5630. just replace the occurrence in inputs[i], as the register might
  5631. also be used in some other input (or even in an address of an
  5632. output), which would mean possibly increasing the number of
  5633. inputs by one (namely 'output' in addition), which might pose
  5634. a too complicated problem for reload to solve. E.g. this situation:
  5635. asm ("" : "=r" (output), "=m" (input) : "0" (input))
  5636. Here 'input' is used in two occurrences as input (once for the
  5637. input operand, once for the address in the second output operand).
  5638. If we would replace only the occurrence of the input operand (to
  5639. make the matching) we would be left with this:
  5640. output = input
  5641. asm ("" : "=r" (output), "=m" (input) : "0" (output))
  5642. Now we suddenly have two different input values (containing the same
  5643. value, but different pseudos) where we formerly had only one.
  5644. With more complicated asms this might lead to reload failures
  5645. which wouldn't have happen without this pass. So, iterate over
  5646. all operands and replace all occurrences of the register used. */
  5647. for (j = 0; j < noutputs; j++)
  5648. if (!rtx_equal_p (SET_DEST (p_sets[j]), input)
  5649. && reg_overlap_mentioned_p (input, SET_DEST (p_sets[j])))
  5650. SET_DEST (p_sets[j]) = replace_rtx (SET_DEST (p_sets[j]),
  5651. input, output);
  5652. for (j = 0; j < ninputs; j++)
  5653. if (reg_overlap_mentioned_p (input, RTVEC_ELT (inputs, j)))
  5654. RTVEC_ELT (inputs, j) = replace_rtx (RTVEC_ELT (inputs, j),
  5655. input, output);
  5656. changed = true;
  5657. }
  5658. if (changed)
  5659. df_insn_rescan (insn);
  5660. }
  5661. /* Add the decl D to the local_decls list of FUN. */
  5662. void
  5663. add_local_decl (struct function *fun, tree d)
  5664. {
  5665. gcc_assert (TREE_CODE (d) == VAR_DECL);
  5666. vec_safe_push (fun->local_decls, d);
  5667. }
  5668. namespace {
  5669. const pass_data pass_data_match_asm_constraints =
  5670. {
  5671. RTL_PASS, /* type */
  5672. "asmcons", /* name */
  5673. OPTGROUP_NONE, /* optinfo_flags */
  5674. TV_NONE, /* tv_id */
  5675. 0, /* properties_required */
  5676. 0, /* properties_provided */
  5677. 0, /* properties_destroyed */
  5678. 0, /* todo_flags_start */
  5679. 0, /* todo_flags_finish */
  5680. };
  5681. class pass_match_asm_constraints : public rtl_opt_pass
  5682. {
  5683. public:
  5684. pass_match_asm_constraints (gcc::context *ctxt)
  5685. : rtl_opt_pass (pass_data_match_asm_constraints, ctxt)
  5686. {}
  5687. /* opt_pass methods: */
  5688. virtual unsigned int execute (function *);
  5689. }; // class pass_match_asm_constraints
  5690. unsigned
  5691. pass_match_asm_constraints::execute (function *fun)
  5692. {
  5693. basic_block bb;
  5694. rtx_insn *insn;
  5695. rtx pat, *p_sets;
  5696. int noutputs;
  5697. if (!crtl->has_asm_statement)
  5698. return 0;
  5699. df_set_flags (DF_DEFER_INSN_RESCAN);
  5700. FOR_EACH_BB_FN (bb, fun)
  5701. {
  5702. FOR_BB_INSNS (bb, insn)
  5703. {
  5704. if (!INSN_P (insn))
  5705. continue;
  5706. pat = PATTERN (insn);
  5707. if (GET_CODE (pat) == PARALLEL)
  5708. p_sets = &XVECEXP (pat, 0, 0), noutputs = XVECLEN (pat, 0);
  5709. else if (GET_CODE (pat) == SET)
  5710. p_sets = &PATTERN (insn), noutputs = 1;
  5711. else
  5712. continue;
  5713. if (GET_CODE (*p_sets) == SET
  5714. && GET_CODE (SET_SRC (*p_sets)) == ASM_OPERANDS)
  5715. match_asm_constraints_1 (insn, p_sets, noutputs);
  5716. }
  5717. }
  5718. return TODO_df_finish;
  5719. }
  5720. } // anon namespace
  5721. rtl_opt_pass *
  5722. make_pass_match_asm_constraints (gcc::context *ctxt)
  5723. {
  5724. return new pass_match_asm_constraints (ctxt);
  5725. }
  5726. #include "gt-function.h"