mips.c 600 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627
  1. /* Subroutines used for MIPS code generation.
  2. Copyright (C) 1989-2015 Free Software Foundation, Inc.
  3. Contributed by A. Lichnewsky, lich@inria.inria.fr.
  4. Changes by Michael Meissner, meissner@osf.org.
  5. 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
  6. Brendan Eich, brendan@microunity.com.
  7. This file is part of GCC.
  8. GCC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 3, or (at your option)
  11. any later version.
  12. GCC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with GCC; see the file COPYING3. If not see
  18. <http://www.gnu.org/licenses/>. */
  19. #include "config.h"
  20. #include "system.h"
  21. #include "coretypes.h"
  22. #include "tm.h"
  23. #include "rtl.h"
  24. #include "regs.h"
  25. #include "hard-reg-set.h"
  26. #include "insn-config.h"
  27. #include "conditions.h"
  28. #include "insn-attr.h"
  29. #include "recog.h"
  30. #include "output.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 "varasm.h"
  43. #include "stringpool.h"
  44. #include "stor-layout.h"
  45. #include "calls.h"
  46. #include "function.h"
  47. #include "hashtab.h"
  48. #include "flags.h"
  49. #include "statistics.h"
  50. #include "real.h"
  51. #include "fixed-value.h"
  52. #include "expmed.h"
  53. #include "dojump.h"
  54. #include "explow.h"
  55. #include "emit-rtl.h"
  56. #include "stmt.h"
  57. #include "expr.h"
  58. #include "insn-codes.h"
  59. #include "optabs.h"
  60. #include "libfuncs.h"
  61. #include "reload.h"
  62. #include "tm_p.h"
  63. #include "ggc.h"
  64. #include "gstab.h"
  65. #include "hash-table.h"
  66. #include "debug.h"
  67. #include "target.h"
  68. #include "target-def.h"
  69. #include "common/common-target.h"
  70. #include "langhooks.h"
  71. #include "dominance.h"
  72. #include "cfg.h"
  73. #include "cfgrtl.h"
  74. #include "cfganal.h"
  75. #include "lcm.h"
  76. #include "cfgbuild.h"
  77. #include "cfgcleanup.h"
  78. #include "predict.h"
  79. #include "basic-block.h"
  80. #include "sched-int.h"
  81. #include "tree-ssa-alias.h"
  82. #include "internal-fn.h"
  83. #include "gimple-fold.h"
  84. #include "tree-eh.h"
  85. #include "gimple-expr.h"
  86. #include "is-a.h"
  87. #include "gimple.h"
  88. #include "gimplify.h"
  89. #include "bitmap.h"
  90. #include "diagnostic.h"
  91. #include "target-globals.h"
  92. #include "opts.h"
  93. #include "tree-pass.h"
  94. #include "context.h"
  95. #include "hash-map.h"
  96. #include "plugin-api.h"
  97. #include "ipa-ref.h"
  98. #include "cgraph.h"
  99. #include "builtins.h"
  100. #include "rtl-iter.h"
  101. /* True if X is an UNSPEC wrapper around a SYMBOL_REF or LABEL_REF. */
  102. #define UNSPEC_ADDRESS_P(X) \
  103. (GET_CODE (X) == UNSPEC \
  104. && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \
  105. && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES)
  106. /* Extract the symbol or label from UNSPEC wrapper X. */
  107. #define UNSPEC_ADDRESS(X) \
  108. XVECEXP (X, 0, 0)
  109. /* Extract the symbol type from UNSPEC wrapper X. */
  110. #define UNSPEC_ADDRESS_TYPE(X) \
  111. ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST))
  112. /* The maximum distance between the top of the stack frame and the
  113. value $sp has when we save and restore registers.
  114. The value for normal-mode code must be a SMALL_OPERAND and must
  115. preserve the maximum stack alignment. We therefore use a value
  116. of 0x7ff0 in this case.
  117. microMIPS LWM and SWM support 12-bit offsets (from -0x800 to 0x7ff),
  118. so we use a maximum of 0x7f0 for TARGET_MICROMIPS.
  119. MIPS16e SAVE and RESTORE instructions can adjust the stack pointer by
  120. up to 0x7f8 bytes and can usually save or restore all the registers
  121. that we need to save or restore. (Note that we can only use these
  122. instructions for o32, for which the stack alignment is 8 bytes.)
  123. We use a maximum gap of 0x100 or 0x400 for MIPS16 code when SAVE and
  124. RESTORE are not available. We can then use unextended instructions
  125. to save and restore registers, and to allocate and deallocate the top
  126. part of the frame. */
  127. #define MIPS_MAX_FIRST_STACK_STEP \
  128. (!TARGET_COMPRESSION ? 0x7ff0 \
  129. : TARGET_MICROMIPS || GENERATE_MIPS16E_SAVE_RESTORE ? 0x7f8 \
  130. : TARGET_64BIT ? 0x100 : 0x400)
  131. /* True if INSN is a mips.md pattern or asm statement. */
  132. /* ??? This test exists through the compiler, perhaps it should be
  133. moved to rtl.h. */
  134. #define USEFUL_INSN_P(INSN) \
  135. (NONDEBUG_INSN_P (INSN) \
  136. && GET_CODE (PATTERN (INSN)) != USE \
  137. && GET_CODE (PATTERN (INSN)) != CLOBBER)
  138. /* If INSN is a delayed branch sequence, return the first instruction
  139. in the sequence, otherwise return INSN itself. */
  140. #define SEQ_BEGIN(INSN) \
  141. (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
  142. ? as_a <rtx_insn *> (XVECEXP (PATTERN (INSN), 0, 0)) \
  143. : (INSN))
  144. /* Likewise for the last instruction in a delayed branch sequence. */
  145. #define SEQ_END(INSN) \
  146. (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
  147. ? as_a <rtx_insn *> (XVECEXP (PATTERN (INSN), \
  148. 0, \
  149. XVECLEN (PATTERN (INSN), 0) - 1)) \
  150. : (INSN))
  151. /* Execute the following loop body with SUBINSN set to each instruction
  152. between SEQ_BEGIN (INSN) and SEQ_END (INSN) inclusive. */
  153. #define FOR_EACH_SUBINSN(SUBINSN, INSN) \
  154. for ((SUBINSN) = SEQ_BEGIN (INSN); \
  155. (SUBINSN) != NEXT_INSN (SEQ_END (INSN)); \
  156. (SUBINSN) = NEXT_INSN (SUBINSN))
  157. /* True if bit BIT is set in VALUE. */
  158. #define BITSET_P(VALUE, BIT) (((VALUE) & (1 << (BIT))) != 0)
  159. /* Return the opcode for a ptr_mode load of the form:
  160. l[wd] DEST, OFFSET(BASE). */
  161. #define MIPS_LOAD_PTR(DEST, OFFSET, BASE) \
  162. (((ptr_mode == DImode ? 0x37 : 0x23) << 26) \
  163. | ((BASE) << 21) \
  164. | ((DEST) << 16) \
  165. | (OFFSET))
  166. /* Return the opcode to move register SRC into register DEST. */
  167. #define MIPS_MOVE(DEST, SRC) \
  168. ((TARGET_64BIT ? 0x2d : 0x21) \
  169. | ((DEST) << 11) \
  170. | ((SRC) << 21))
  171. /* Return the opcode for:
  172. lui DEST, VALUE. */
  173. #define MIPS_LUI(DEST, VALUE) \
  174. ((0xf << 26) | ((DEST) << 16) | (VALUE))
  175. /* Return the opcode to jump to register DEST. When the JR opcode is not
  176. available use JALR $0, DEST. */
  177. #define MIPS_JR(DEST) \
  178. (((DEST) << 21) | (ISA_HAS_JR ? 0x8 : 0x9))
  179. /* Return the opcode for:
  180. bal . + (1 + OFFSET) * 4. */
  181. #define MIPS_BAL(OFFSET) \
  182. ((0x1 << 26) | (0x11 << 16) | (OFFSET))
  183. /* Return the usual opcode for a nop. */
  184. #define MIPS_NOP 0
  185. /* Classifies an address.
  186. ADDRESS_REG
  187. A natural register + offset address. The register satisfies
  188. mips_valid_base_register_p and the offset is a const_arith_operand.
  189. ADDRESS_LO_SUM
  190. A LO_SUM rtx. The first operand is a valid base register and
  191. the second operand is a symbolic address.
  192. ADDRESS_CONST_INT
  193. A signed 16-bit constant address.
  194. ADDRESS_SYMBOLIC:
  195. A constant symbolic address. */
  196. enum mips_address_type {
  197. ADDRESS_REG,
  198. ADDRESS_LO_SUM,
  199. ADDRESS_CONST_INT,
  200. ADDRESS_SYMBOLIC
  201. };
  202. /* Macros to create an enumeration identifier for a function prototype. */
  203. #define MIPS_FTYPE_NAME1(A, B) MIPS_##A##_FTYPE_##B
  204. #define MIPS_FTYPE_NAME2(A, B, C) MIPS_##A##_FTYPE_##B##_##C
  205. #define MIPS_FTYPE_NAME3(A, B, C, D) MIPS_##A##_FTYPE_##B##_##C##_##D
  206. #define MIPS_FTYPE_NAME4(A, B, C, D, E) MIPS_##A##_FTYPE_##B##_##C##_##D##_##E
  207. /* Classifies the prototype of a built-in function. */
  208. enum mips_function_type {
  209. #define DEF_MIPS_FTYPE(NARGS, LIST) MIPS_FTYPE_NAME##NARGS LIST,
  210. #include "config/mips/mips-ftypes.def"
  211. #undef DEF_MIPS_FTYPE
  212. MIPS_MAX_FTYPE_MAX
  213. };
  214. /* Specifies how a built-in function should be converted into rtl. */
  215. enum mips_builtin_type {
  216. /* The function corresponds directly to an .md pattern. The return
  217. value is mapped to operand 0 and the arguments are mapped to
  218. operands 1 and above. */
  219. MIPS_BUILTIN_DIRECT,
  220. /* The function corresponds directly to an .md pattern. There is no return
  221. value and the arguments are mapped to operands 0 and above. */
  222. MIPS_BUILTIN_DIRECT_NO_TARGET,
  223. /* The function corresponds to a comparison instruction followed by
  224. a mips_cond_move_tf_ps pattern. The first two arguments are the
  225. values to compare and the second two arguments are the vector
  226. operands for the movt.ps or movf.ps instruction (in assembly order). */
  227. MIPS_BUILTIN_MOVF,
  228. MIPS_BUILTIN_MOVT,
  229. /* The function corresponds to a V2SF comparison instruction. Operand 0
  230. of this instruction is the result of the comparison, which has mode
  231. CCV2 or CCV4. The function arguments are mapped to operands 1 and
  232. above. The function's return value is an SImode boolean that is
  233. true under the following conditions:
  234. MIPS_BUILTIN_CMP_ANY: one of the registers is true
  235. MIPS_BUILTIN_CMP_ALL: all of the registers are true
  236. MIPS_BUILTIN_CMP_LOWER: the first register is true
  237. MIPS_BUILTIN_CMP_UPPER: the second register is true. */
  238. MIPS_BUILTIN_CMP_ANY,
  239. MIPS_BUILTIN_CMP_ALL,
  240. MIPS_BUILTIN_CMP_UPPER,
  241. MIPS_BUILTIN_CMP_LOWER,
  242. /* As above, but the instruction only sets a single $fcc register. */
  243. MIPS_BUILTIN_CMP_SINGLE,
  244. /* For generating bposge32 branch instructions in MIPS32 DSP ASE. */
  245. MIPS_BUILTIN_BPOSGE32
  246. };
  247. /* Invoke MACRO (COND) for each C.cond.fmt condition. */
  248. #define MIPS_FP_CONDITIONS(MACRO) \
  249. MACRO (f), \
  250. MACRO (un), \
  251. MACRO (eq), \
  252. MACRO (ueq), \
  253. MACRO (olt), \
  254. MACRO (ult), \
  255. MACRO (ole), \
  256. MACRO (ule), \
  257. MACRO (sf), \
  258. MACRO (ngle), \
  259. MACRO (seq), \
  260. MACRO (ngl), \
  261. MACRO (lt), \
  262. MACRO (nge), \
  263. MACRO (le), \
  264. MACRO (ngt)
  265. /* Enumerates the codes above as MIPS_FP_COND_<X>. */
  266. #define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## X
  267. enum mips_fp_condition {
  268. MIPS_FP_CONDITIONS (DECLARE_MIPS_COND)
  269. };
  270. #undef DECLARE_MIPS_COND
  271. /* Index X provides the string representation of MIPS_FP_COND_<X>. */
  272. #define STRINGIFY(X) #X
  273. static const char *const mips_fp_conditions[] = {
  274. MIPS_FP_CONDITIONS (STRINGIFY)
  275. };
  276. #undef STRINGIFY
  277. /* A class used to control a comdat-style stub that we output in each
  278. translation unit that needs it. */
  279. class mips_one_only_stub {
  280. public:
  281. virtual ~mips_one_only_stub () {}
  282. /* Return the name of the stub. */
  283. virtual const char *get_name () = 0;
  284. /* Output the body of the function to asm_out_file. */
  285. virtual void output_body () = 0;
  286. };
  287. /* Tuning information that is automatically derived from other sources
  288. (such as the scheduler). */
  289. static struct {
  290. /* The architecture and tuning settings that this structure describes. */
  291. enum processor arch;
  292. enum processor tune;
  293. /* True if this structure describes MIPS16 settings. */
  294. bool mips16_p;
  295. /* True if the structure has been initialized. */
  296. bool initialized_p;
  297. /* True if "MULT $0, $0" is preferable to "MTLO $0; MTHI $0"
  298. when optimizing for speed. */
  299. bool fast_mult_zero_zero_p;
  300. } mips_tuning_info;
  301. /* Information about a function's frame layout. */
  302. struct GTY(()) mips_frame_info {
  303. /* The size of the frame in bytes. */
  304. HOST_WIDE_INT total_size;
  305. /* The number of bytes allocated to variables. */
  306. HOST_WIDE_INT var_size;
  307. /* The number of bytes allocated to outgoing function arguments. */
  308. HOST_WIDE_INT args_size;
  309. /* The number of bytes allocated to the .cprestore slot, or 0 if there
  310. is no such slot. */
  311. HOST_WIDE_INT cprestore_size;
  312. /* Bit X is set if the function saves or restores GPR X. */
  313. unsigned int mask;
  314. /* Likewise FPR X. */
  315. unsigned int fmask;
  316. /* Likewise doubleword accumulator X ($acX). */
  317. unsigned int acc_mask;
  318. /* The number of GPRs, FPRs, doubleword accumulators and COP0
  319. registers saved. */
  320. unsigned int num_gp;
  321. unsigned int num_fp;
  322. unsigned int num_acc;
  323. unsigned int num_cop0_regs;
  324. /* The offset of the topmost GPR, FPR, accumulator and COP0-register
  325. save slots from the top of the frame, or zero if no such slots are
  326. needed. */
  327. HOST_WIDE_INT gp_save_offset;
  328. HOST_WIDE_INT fp_save_offset;
  329. HOST_WIDE_INT acc_save_offset;
  330. HOST_WIDE_INT cop0_save_offset;
  331. /* Likewise, but giving offsets from the bottom of the frame. */
  332. HOST_WIDE_INT gp_sp_offset;
  333. HOST_WIDE_INT fp_sp_offset;
  334. HOST_WIDE_INT acc_sp_offset;
  335. HOST_WIDE_INT cop0_sp_offset;
  336. /* Similar, but the value passed to _mcount. */
  337. HOST_WIDE_INT ra_fp_offset;
  338. /* The offset of arg_pointer_rtx from the bottom of the frame. */
  339. HOST_WIDE_INT arg_pointer_offset;
  340. /* The offset of hard_frame_pointer_rtx from the bottom of the frame. */
  341. HOST_WIDE_INT hard_frame_pointer_offset;
  342. };
  343. struct GTY(()) machine_function {
  344. /* The next floating-point condition-code register to allocate
  345. for ISA_HAS_8CC targets, relative to ST_REG_FIRST. */
  346. unsigned int next_fcc;
  347. /* The register returned by mips16_gp_pseudo_reg; see there for details. */
  348. rtx mips16_gp_pseudo_rtx;
  349. /* The number of extra stack bytes taken up by register varargs.
  350. This area is allocated by the callee at the very top of the frame. */
  351. int varargs_size;
  352. /* The current frame information, calculated by mips_compute_frame_info. */
  353. struct mips_frame_info frame;
  354. /* The register to use as the function's global pointer, or INVALID_REGNUM
  355. if the function doesn't need one. */
  356. unsigned int global_pointer;
  357. /* How many instructions it takes to load a label into $AT, or 0 if
  358. this property hasn't yet been calculated. */
  359. unsigned int load_label_num_insns;
  360. /* True if mips_adjust_insn_length should ignore an instruction's
  361. hazard attribute. */
  362. bool ignore_hazard_length_p;
  363. /* True if the whole function is suitable for .set noreorder and
  364. .set nomacro. */
  365. bool all_noreorder_p;
  366. /* True if the function has "inflexible" and "flexible" references
  367. to the global pointer. See mips_cfun_has_inflexible_gp_ref_p
  368. and mips_cfun_has_flexible_gp_ref_p for details. */
  369. bool has_inflexible_gp_insn_p;
  370. bool has_flexible_gp_insn_p;
  371. /* True if the function's prologue must load the global pointer
  372. value into pic_offset_table_rtx and store the same value in
  373. the function's cprestore slot (if any). Even if this value
  374. is currently false, we may decide to set it to true later;
  375. see mips_must_initialize_gp_p () for details. */
  376. bool must_initialize_gp_p;
  377. /* True if the current function must restore $gp after any potential
  378. clobber. This value is only meaningful during the first post-epilogue
  379. split_insns pass; see mips_must_initialize_gp_p () for details. */
  380. bool must_restore_gp_when_clobbered_p;
  381. /* True if this is an interrupt handler. */
  382. bool interrupt_handler_p;
  383. /* True if this is an interrupt handler that uses shadow registers. */
  384. bool use_shadow_register_set_p;
  385. /* True if this is an interrupt handler that should keep interrupts
  386. masked. */
  387. bool keep_interrupts_masked_p;
  388. /* True if this is an interrupt handler that should use DERET
  389. instead of ERET. */
  390. bool use_debug_exception_return_p;
  391. };
  392. /* Information about a single argument. */
  393. struct mips_arg_info {
  394. /* True if the argument is passed in a floating-point register, or
  395. would have been if we hadn't run out of registers. */
  396. bool fpr_p;
  397. /* The number of words passed in registers, rounded up. */
  398. unsigned int reg_words;
  399. /* For EABI, the offset of the first register from GP_ARG_FIRST or
  400. FP_ARG_FIRST. For other ABIs, the offset of the first register from
  401. the start of the ABI's argument structure (see the CUMULATIVE_ARGS
  402. comment for details).
  403. The value is MAX_ARGS_IN_REGISTERS if the argument is passed entirely
  404. on the stack. */
  405. unsigned int reg_offset;
  406. /* The number of words that must be passed on the stack, rounded up. */
  407. unsigned int stack_words;
  408. /* The offset from the start of the stack overflow area of the argument's
  409. first stack word. Only meaningful when STACK_WORDS is nonzero. */
  410. unsigned int stack_offset;
  411. };
  412. /* Information about an address described by mips_address_type.
  413. ADDRESS_CONST_INT
  414. No fields are used.
  415. ADDRESS_REG
  416. REG is the base register and OFFSET is the constant offset.
  417. ADDRESS_LO_SUM
  418. REG and OFFSET are the operands to the LO_SUM and SYMBOL_TYPE
  419. is the type of symbol it references.
  420. ADDRESS_SYMBOLIC
  421. SYMBOL_TYPE is the type of symbol that the address references. */
  422. struct mips_address_info {
  423. enum mips_address_type type;
  424. rtx reg;
  425. rtx offset;
  426. enum mips_symbol_type symbol_type;
  427. };
  428. /* One stage in a constant building sequence. These sequences have
  429. the form:
  430. A = VALUE[0]
  431. A = A CODE[1] VALUE[1]
  432. A = A CODE[2] VALUE[2]
  433. ...
  434. where A is an accumulator, each CODE[i] is a binary rtl operation
  435. and each VALUE[i] is a constant integer. CODE[0] is undefined. */
  436. struct mips_integer_op {
  437. enum rtx_code code;
  438. unsigned HOST_WIDE_INT value;
  439. };
  440. /* The largest number of operations needed to load an integer constant.
  441. The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
  442. When the lowest bit is clear, we can try, but reject a sequence with
  443. an extra SLL at the end. */
  444. #define MIPS_MAX_INTEGER_OPS 7
  445. /* Information about a MIPS16e SAVE or RESTORE instruction. */
  446. struct mips16e_save_restore_info {
  447. /* The number of argument registers saved by a SAVE instruction.
  448. 0 for RESTORE instructions. */
  449. unsigned int nargs;
  450. /* Bit X is set if the instruction saves or restores GPR X. */
  451. unsigned int mask;
  452. /* The total number of bytes to allocate. */
  453. HOST_WIDE_INT size;
  454. };
  455. /* Costs of various operations on the different architectures. */
  456. struct mips_rtx_cost_data
  457. {
  458. unsigned short fp_add;
  459. unsigned short fp_mult_sf;
  460. unsigned short fp_mult_df;
  461. unsigned short fp_div_sf;
  462. unsigned short fp_div_df;
  463. unsigned short int_mult_si;
  464. unsigned short int_mult_di;
  465. unsigned short int_div_si;
  466. unsigned short int_div_di;
  467. unsigned short branch_cost;
  468. unsigned short memory_latency;
  469. };
  470. /* Global variables for machine-dependent things. */
  471. /* The -G setting, or the configuration's default small-data limit if
  472. no -G option is given. */
  473. static unsigned int mips_small_data_threshold;
  474. /* The number of file directives written by mips_output_filename. */
  475. int num_source_filenames;
  476. /* The name that appeared in the last .file directive written by
  477. mips_output_filename, or "" if mips_output_filename hasn't
  478. written anything yet. */
  479. const char *current_function_file = "";
  480. /* Arrays that map GCC register numbers to debugger register numbers. */
  481. int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
  482. int mips_dwarf_regno[FIRST_PSEUDO_REGISTER];
  483. /* Information about the current function's epilogue, used only while
  484. expanding it. */
  485. static struct {
  486. /* A list of queued REG_CFA_RESTORE notes. */
  487. rtx cfa_restores;
  488. /* The CFA is currently defined as CFA_REG + CFA_OFFSET. */
  489. rtx cfa_reg;
  490. HOST_WIDE_INT cfa_offset;
  491. /* The offset of the CFA from the stack pointer while restoring
  492. registers. */
  493. HOST_WIDE_INT cfa_restore_sp_offset;
  494. } mips_epilogue;
  495. /* The nesting depth of the PRINT_OPERAND '%(', '%<' and '%[' constructs. */
  496. struct mips_asm_switch mips_noreorder = { "reorder", 0 };
  497. struct mips_asm_switch mips_nomacro = { "macro", 0 };
  498. struct mips_asm_switch mips_noat = { "at", 0 };
  499. /* True if we're writing out a branch-likely instruction rather than a
  500. normal branch. */
  501. static bool mips_branch_likely;
  502. /* The current instruction-set architecture. */
  503. enum processor mips_arch;
  504. const struct mips_cpu_info *mips_arch_info;
  505. /* The processor that we should tune the code for. */
  506. enum processor mips_tune;
  507. const struct mips_cpu_info *mips_tune_info;
  508. /* The ISA level associated with mips_arch. */
  509. int mips_isa;
  510. /* The ISA revision level. This is 0 for MIPS I to V and N for
  511. MIPS{32,64}rN. */
  512. int mips_isa_rev;
  513. /* The architecture selected by -mipsN, or null if -mipsN wasn't used. */
  514. static const struct mips_cpu_info *mips_isa_option_info;
  515. /* Which cost information to use. */
  516. static const struct mips_rtx_cost_data *mips_cost;
  517. /* The ambient target flags, excluding MASK_MIPS16. */
  518. static int mips_base_target_flags;
  519. /* The default compression mode. */
  520. unsigned int mips_base_compression_flags;
  521. /* The ambient values of other global variables. */
  522. static int mips_base_schedule_insns; /* flag_schedule_insns */
  523. static int mips_base_reorder_blocks_and_partition; /* flag_reorder... */
  524. static int mips_base_move_loop_invariants; /* flag_move_loop_invariants */
  525. static int mips_base_align_loops; /* align_loops */
  526. static int mips_base_align_jumps; /* align_jumps */
  527. static int mips_base_align_functions; /* align_functions */
  528. /* Index [M][R] is true if register R is allowed to hold a value of mode M. */
  529. bool mips_hard_regno_mode_ok[(int) MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
  530. /* Index C is true if character C is a valid PRINT_OPERAND punctation
  531. character. */
  532. static bool mips_print_operand_punct[256];
  533. static GTY (()) int mips_output_filename_first_time = 1;
  534. /* mips_split_p[X] is true if symbols of type X can be split by
  535. mips_split_symbol. */
  536. bool mips_split_p[NUM_SYMBOL_TYPES];
  537. /* mips_split_hi_p[X] is true if the high parts of symbols of type X
  538. can be split by mips_split_symbol. */
  539. bool mips_split_hi_p[NUM_SYMBOL_TYPES];
  540. /* mips_use_pcrel_pool_p[X] is true if symbols of type X should be
  541. forced into a PC-relative constant pool. */
  542. bool mips_use_pcrel_pool_p[NUM_SYMBOL_TYPES];
  543. /* mips_lo_relocs[X] is the relocation to use when a symbol of type X
  544. appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or
  545. if they are matched by a special .md file pattern. */
  546. const char *mips_lo_relocs[NUM_SYMBOL_TYPES];
  547. /* Likewise for HIGHs. */
  548. const char *mips_hi_relocs[NUM_SYMBOL_TYPES];
  549. /* Target state for MIPS16. */
  550. struct target_globals *mips16_globals;
  551. /* Cached value of can_issue_more. This is cached in mips_variable_issue hook
  552. and returned from mips_sched_reorder2. */
  553. static int cached_can_issue_more;
  554. /* The stubs for various MIPS16 support functions, if used. */
  555. static mips_one_only_stub *mips16_rdhwr_stub;
  556. static mips_one_only_stub *mips16_get_fcsr_stub;
  557. static mips_one_only_stub *mips16_set_fcsr_stub;
  558. /* Index R is the smallest register class that contains register R. */
  559. const enum reg_class mips_regno_to_class[FIRST_PSEUDO_REGISTER] = {
  560. LEA_REGS, LEA_REGS, M16_STORE_REGS, V1_REG,
  561. M16_STORE_REGS, M16_STORE_REGS, M16_STORE_REGS, M16_STORE_REGS,
  562. LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
  563. LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
  564. M16_REGS, M16_STORE_REGS, LEA_REGS, LEA_REGS,
  565. LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
  566. T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
  567. LEA_REGS, M16_SP_REGS, LEA_REGS, LEA_REGS,
  568. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  569. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  570. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  571. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  572. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  573. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  574. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  575. FP_REGS, FP_REGS, FP_REGS, FP_REGS,
  576. MD0_REG, MD1_REG, NO_REGS, ST_REGS,
  577. ST_REGS, ST_REGS, ST_REGS, ST_REGS,
  578. ST_REGS, ST_REGS, ST_REGS, NO_REGS,
  579. NO_REGS, FRAME_REGS, FRAME_REGS, NO_REGS,
  580. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  581. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  582. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  583. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  584. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  585. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  586. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  587. COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
  588. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  589. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  590. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  591. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  592. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  593. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  594. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  595. COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
  596. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  597. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  598. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  599. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  600. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  601. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  602. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  603. COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
  604. DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS,
  605. DSP_ACC_REGS, DSP_ACC_REGS, ALL_REGS, ALL_REGS,
  606. ALL_REGS, ALL_REGS, ALL_REGS, ALL_REGS
  607. };
  608. /* The value of TARGET_ATTRIBUTE_TABLE. */
  609. static const struct attribute_spec mips_attribute_table[] = {
  610. /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
  611. om_diagnostic } */
  612. { "long_call", 0, 0, false, true, true, NULL, false },
  613. { "far", 0, 0, false, true, true, NULL, false },
  614. { "near", 0, 0, false, true, true, NULL, false },
  615. /* We would really like to treat "mips16" and "nomips16" as type
  616. attributes, but GCC doesn't provide the hooks we need to support
  617. the right conversion rules. As declaration attributes, they affect
  618. code generation but don't carry other semantics. */
  619. { "mips16", 0, 0, true, false, false, NULL, false },
  620. { "nomips16", 0, 0, true, false, false, NULL, false },
  621. { "micromips", 0, 0, true, false, false, NULL, false },
  622. { "nomicromips", 0, 0, true, false, false, NULL, false },
  623. { "nocompression", 0, 0, true, false, false, NULL, false },
  624. /* Allow functions to be specified as interrupt handlers */
  625. { "interrupt", 0, 0, false, true, true, NULL, false },
  626. { "use_shadow_register_set", 0, 0, false, true, true, NULL, false },
  627. { "keep_interrupts_masked", 0, 0, false, true, true, NULL, false },
  628. { "use_debug_exception_return", 0, 0, false, true, true, NULL, false },
  629. { NULL, 0, 0, false, false, false, NULL, false }
  630. };
  631. /* A table describing all the processors GCC knows about; see
  632. mips-cpus.def for details. */
  633. static const struct mips_cpu_info mips_cpu_info_table[] = {
  634. #define MIPS_CPU(NAME, CPU, ISA, FLAGS) \
  635. { NAME, CPU, ISA, FLAGS },
  636. #include "mips-cpus.def"
  637. #undef MIPS_CPU
  638. };
  639. /* Default costs. If these are used for a processor we should look
  640. up the actual costs. */
  641. #define DEFAULT_COSTS COSTS_N_INSNS (6), /* fp_add */ \
  642. COSTS_N_INSNS (7), /* fp_mult_sf */ \
  643. COSTS_N_INSNS (8), /* fp_mult_df */ \
  644. COSTS_N_INSNS (23), /* fp_div_sf */ \
  645. COSTS_N_INSNS (36), /* fp_div_df */ \
  646. COSTS_N_INSNS (10), /* int_mult_si */ \
  647. COSTS_N_INSNS (10), /* int_mult_di */ \
  648. COSTS_N_INSNS (69), /* int_div_si */ \
  649. COSTS_N_INSNS (69), /* int_div_di */ \
  650. 2, /* branch_cost */ \
  651. 4 /* memory_latency */
  652. /* Floating-point costs for processors without an FPU. Just assume that
  653. all floating-point libcalls are very expensive. */
  654. #define SOFT_FP_COSTS COSTS_N_INSNS (256), /* fp_add */ \
  655. COSTS_N_INSNS (256), /* fp_mult_sf */ \
  656. COSTS_N_INSNS (256), /* fp_mult_df */ \
  657. COSTS_N_INSNS (256), /* fp_div_sf */ \
  658. COSTS_N_INSNS (256) /* fp_div_df */
  659. /* Costs to use when optimizing for size. */
  660. static const struct mips_rtx_cost_data mips_rtx_cost_optimize_size = {
  661. COSTS_N_INSNS (1), /* fp_add */
  662. COSTS_N_INSNS (1), /* fp_mult_sf */
  663. COSTS_N_INSNS (1), /* fp_mult_df */
  664. COSTS_N_INSNS (1), /* fp_div_sf */
  665. COSTS_N_INSNS (1), /* fp_div_df */
  666. COSTS_N_INSNS (1), /* int_mult_si */
  667. COSTS_N_INSNS (1), /* int_mult_di */
  668. COSTS_N_INSNS (1), /* int_div_si */
  669. COSTS_N_INSNS (1), /* int_div_di */
  670. 2, /* branch_cost */
  671. 4 /* memory_latency */
  672. };
  673. /* Costs to use when optimizing for speed, indexed by processor. */
  674. static const struct mips_rtx_cost_data
  675. mips_rtx_cost_data[NUM_PROCESSOR_VALUES] = {
  676. { /* R3000 */
  677. COSTS_N_INSNS (2), /* fp_add */
  678. COSTS_N_INSNS (4), /* fp_mult_sf */
  679. COSTS_N_INSNS (5), /* fp_mult_df */
  680. COSTS_N_INSNS (12), /* fp_div_sf */
  681. COSTS_N_INSNS (19), /* fp_div_df */
  682. COSTS_N_INSNS (12), /* int_mult_si */
  683. COSTS_N_INSNS (12), /* int_mult_di */
  684. COSTS_N_INSNS (35), /* int_div_si */
  685. COSTS_N_INSNS (35), /* int_div_di */
  686. 1, /* branch_cost */
  687. 4 /* memory_latency */
  688. },
  689. { /* 4KC */
  690. SOFT_FP_COSTS,
  691. COSTS_N_INSNS (6), /* int_mult_si */
  692. COSTS_N_INSNS (6), /* int_mult_di */
  693. COSTS_N_INSNS (36), /* int_div_si */
  694. COSTS_N_INSNS (36), /* int_div_di */
  695. 1, /* branch_cost */
  696. 4 /* memory_latency */
  697. },
  698. { /* 4KP */
  699. SOFT_FP_COSTS,
  700. COSTS_N_INSNS (36), /* int_mult_si */
  701. COSTS_N_INSNS (36), /* int_mult_di */
  702. COSTS_N_INSNS (37), /* int_div_si */
  703. COSTS_N_INSNS (37), /* int_div_di */
  704. 1, /* branch_cost */
  705. 4 /* memory_latency */
  706. },
  707. { /* 5KC */
  708. SOFT_FP_COSTS,
  709. COSTS_N_INSNS (4), /* int_mult_si */
  710. COSTS_N_INSNS (11), /* int_mult_di */
  711. COSTS_N_INSNS (36), /* int_div_si */
  712. COSTS_N_INSNS (68), /* int_div_di */
  713. 1, /* branch_cost */
  714. 4 /* memory_latency */
  715. },
  716. { /* 5KF */
  717. COSTS_N_INSNS (4), /* fp_add */
  718. COSTS_N_INSNS (4), /* fp_mult_sf */
  719. COSTS_N_INSNS (5), /* fp_mult_df */
  720. COSTS_N_INSNS (17), /* fp_div_sf */
  721. COSTS_N_INSNS (32), /* fp_div_df */
  722. COSTS_N_INSNS (4), /* int_mult_si */
  723. COSTS_N_INSNS (11), /* int_mult_di */
  724. COSTS_N_INSNS (36), /* int_div_si */
  725. COSTS_N_INSNS (68), /* int_div_di */
  726. 1, /* branch_cost */
  727. 4 /* memory_latency */
  728. },
  729. { /* 20KC */
  730. COSTS_N_INSNS (4), /* fp_add */
  731. COSTS_N_INSNS (4), /* fp_mult_sf */
  732. COSTS_N_INSNS (5), /* fp_mult_df */
  733. COSTS_N_INSNS (17), /* fp_div_sf */
  734. COSTS_N_INSNS (32), /* fp_div_df */
  735. COSTS_N_INSNS (4), /* int_mult_si */
  736. COSTS_N_INSNS (7), /* int_mult_di */
  737. COSTS_N_INSNS (42), /* int_div_si */
  738. COSTS_N_INSNS (72), /* int_div_di */
  739. 1, /* branch_cost */
  740. 4 /* memory_latency */
  741. },
  742. { /* 24KC */
  743. SOFT_FP_COSTS,
  744. COSTS_N_INSNS (5), /* int_mult_si */
  745. COSTS_N_INSNS (5), /* int_mult_di */
  746. COSTS_N_INSNS (41), /* int_div_si */
  747. COSTS_N_INSNS (41), /* int_div_di */
  748. 1, /* branch_cost */
  749. 4 /* memory_latency */
  750. },
  751. { /* 24KF2_1 */
  752. COSTS_N_INSNS (8), /* fp_add */
  753. COSTS_N_INSNS (8), /* fp_mult_sf */
  754. COSTS_N_INSNS (10), /* fp_mult_df */
  755. COSTS_N_INSNS (34), /* fp_div_sf */
  756. COSTS_N_INSNS (64), /* fp_div_df */
  757. COSTS_N_INSNS (5), /* int_mult_si */
  758. COSTS_N_INSNS (5), /* int_mult_di */
  759. COSTS_N_INSNS (41), /* int_div_si */
  760. COSTS_N_INSNS (41), /* int_div_di */
  761. 1, /* branch_cost */
  762. 4 /* memory_latency */
  763. },
  764. { /* 24KF1_1 */
  765. COSTS_N_INSNS (4), /* fp_add */
  766. COSTS_N_INSNS (4), /* fp_mult_sf */
  767. COSTS_N_INSNS (5), /* fp_mult_df */
  768. COSTS_N_INSNS (17), /* fp_div_sf */
  769. COSTS_N_INSNS (32), /* fp_div_df */
  770. COSTS_N_INSNS (5), /* int_mult_si */
  771. COSTS_N_INSNS (5), /* int_mult_di */
  772. COSTS_N_INSNS (41), /* int_div_si */
  773. COSTS_N_INSNS (41), /* int_div_di */
  774. 1, /* branch_cost */
  775. 4 /* memory_latency */
  776. },
  777. { /* 74KC */
  778. SOFT_FP_COSTS,
  779. COSTS_N_INSNS (5), /* int_mult_si */
  780. COSTS_N_INSNS (5), /* int_mult_di */
  781. COSTS_N_INSNS (41), /* int_div_si */
  782. COSTS_N_INSNS (41), /* int_div_di */
  783. 1, /* branch_cost */
  784. 4 /* memory_latency */
  785. },
  786. { /* 74KF2_1 */
  787. COSTS_N_INSNS (8), /* fp_add */
  788. COSTS_N_INSNS (8), /* fp_mult_sf */
  789. COSTS_N_INSNS (10), /* fp_mult_df */
  790. COSTS_N_INSNS (34), /* fp_div_sf */
  791. COSTS_N_INSNS (64), /* fp_div_df */
  792. COSTS_N_INSNS (5), /* int_mult_si */
  793. COSTS_N_INSNS (5), /* int_mult_di */
  794. COSTS_N_INSNS (41), /* int_div_si */
  795. COSTS_N_INSNS (41), /* int_div_di */
  796. 1, /* branch_cost */
  797. 4 /* memory_latency */
  798. },
  799. { /* 74KF1_1 */
  800. COSTS_N_INSNS (4), /* fp_add */
  801. COSTS_N_INSNS (4), /* fp_mult_sf */
  802. COSTS_N_INSNS (5), /* fp_mult_df */
  803. COSTS_N_INSNS (17), /* fp_div_sf */
  804. COSTS_N_INSNS (32), /* fp_div_df */
  805. COSTS_N_INSNS (5), /* int_mult_si */
  806. COSTS_N_INSNS (5), /* int_mult_di */
  807. COSTS_N_INSNS (41), /* int_div_si */
  808. COSTS_N_INSNS (41), /* int_div_di */
  809. 1, /* branch_cost */
  810. 4 /* memory_latency */
  811. },
  812. { /* 74KF3_2 */
  813. COSTS_N_INSNS (6), /* fp_add */
  814. COSTS_N_INSNS (6), /* fp_mult_sf */
  815. COSTS_N_INSNS (7), /* fp_mult_df */
  816. COSTS_N_INSNS (25), /* fp_div_sf */
  817. COSTS_N_INSNS (48), /* fp_div_df */
  818. COSTS_N_INSNS (5), /* int_mult_si */
  819. COSTS_N_INSNS (5), /* int_mult_di */
  820. COSTS_N_INSNS (41), /* int_div_si */
  821. COSTS_N_INSNS (41), /* int_div_di */
  822. 1, /* branch_cost */
  823. 4 /* memory_latency */
  824. },
  825. { /* Loongson-2E */
  826. DEFAULT_COSTS
  827. },
  828. { /* Loongson-2F */
  829. DEFAULT_COSTS
  830. },
  831. { /* Loongson-3A */
  832. DEFAULT_COSTS
  833. },
  834. { /* M4k */
  835. DEFAULT_COSTS
  836. },
  837. /* Octeon */
  838. {
  839. SOFT_FP_COSTS,
  840. COSTS_N_INSNS (5), /* int_mult_si */
  841. COSTS_N_INSNS (5), /* int_mult_di */
  842. COSTS_N_INSNS (72), /* int_div_si */
  843. COSTS_N_INSNS (72), /* int_div_di */
  844. 1, /* branch_cost */
  845. 4 /* memory_latency */
  846. },
  847. /* Octeon II */
  848. {
  849. SOFT_FP_COSTS,
  850. COSTS_N_INSNS (6), /* int_mult_si */
  851. COSTS_N_INSNS (6), /* int_mult_di */
  852. COSTS_N_INSNS (18), /* int_div_si */
  853. COSTS_N_INSNS (35), /* int_div_di */
  854. 4, /* branch_cost */
  855. 4 /* memory_latency */
  856. },
  857. /* Octeon III */
  858. {
  859. COSTS_N_INSNS (6), /* fp_add */
  860. COSTS_N_INSNS (6), /* fp_mult_sf */
  861. COSTS_N_INSNS (7), /* fp_mult_df */
  862. COSTS_N_INSNS (25), /* fp_div_sf */
  863. COSTS_N_INSNS (48), /* fp_div_df */
  864. COSTS_N_INSNS (6), /* int_mult_si */
  865. COSTS_N_INSNS (6), /* int_mult_di */
  866. COSTS_N_INSNS (18), /* int_div_si */
  867. COSTS_N_INSNS (35), /* int_div_di */
  868. 4, /* branch_cost */
  869. 4 /* memory_latency */
  870. },
  871. { /* R3900 */
  872. COSTS_N_INSNS (2), /* fp_add */
  873. COSTS_N_INSNS (4), /* fp_mult_sf */
  874. COSTS_N_INSNS (5), /* fp_mult_df */
  875. COSTS_N_INSNS (12), /* fp_div_sf */
  876. COSTS_N_INSNS (19), /* fp_div_df */
  877. COSTS_N_INSNS (2), /* int_mult_si */
  878. COSTS_N_INSNS (2), /* int_mult_di */
  879. COSTS_N_INSNS (35), /* int_div_si */
  880. COSTS_N_INSNS (35), /* int_div_di */
  881. 1, /* branch_cost */
  882. 4 /* memory_latency */
  883. },
  884. { /* R6000 */
  885. COSTS_N_INSNS (3), /* fp_add */
  886. COSTS_N_INSNS (5), /* fp_mult_sf */
  887. COSTS_N_INSNS (6), /* fp_mult_df */
  888. COSTS_N_INSNS (15), /* fp_div_sf */
  889. COSTS_N_INSNS (16), /* fp_div_df */
  890. COSTS_N_INSNS (17), /* int_mult_si */
  891. COSTS_N_INSNS (17), /* int_mult_di */
  892. COSTS_N_INSNS (38), /* int_div_si */
  893. COSTS_N_INSNS (38), /* int_div_di */
  894. 2, /* branch_cost */
  895. 6 /* memory_latency */
  896. },
  897. { /* R4000 */
  898. COSTS_N_INSNS (6), /* fp_add */
  899. COSTS_N_INSNS (7), /* fp_mult_sf */
  900. COSTS_N_INSNS (8), /* fp_mult_df */
  901. COSTS_N_INSNS (23), /* fp_div_sf */
  902. COSTS_N_INSNS (36), /* fp_div_df */
  903. COSTS_N_INSNS (10), /* int_mult_si */
  904. COSTS_N_INSNS (10), /* int_mult_di */
  905. COSTS_N_INSNS (69), /* int_div_si */
  906. COSTS_N_INSNS (69), /* int_div_di */
  907. 2, /* branch_cost */
  908. 6 /* memory_latency */
  909. },
  910. { /* R4100 */
  911. DEFAULT_COSTS
  912. },
  913. { /* R4111 */
  914. DEFAULT_COSTS
  915. },
  916. { /* R4120 */
  917. DEFAULT_COSTS
  918. },
  919. { /* R4130 */
  920. /* The only costs that appear to be updated here are
  921. integer multiplication. */
  922. SOFT_FP_COSTS,
  923. COSTS_N_INSNS (4), /* int_mult_si */
  924. COSTS_N_INSNS (6), /* int_mult_di */
  925. COSTS_N_INSNS (69), /* int_div_si */
  926. COSTS_N_INSNS (69), /* int_div_di */
  927. 1, /* branch_cost */
  928. 4 /* memory_latency */
  929. },
  930. { /* R4300 */
  931. DEFAULT_COSTS
  932. },
  933. { /* R4600 */
  934. DEFAULT_COSTS
  935. },
  936. { /* R4650 */
  937. DEFAULT_COSTS
  938. },
  939. { /* R4700 */
  940. DEFAULT_COSTS
  941. },
  942. { /* R5000 */
  943. COSTS_N_INSNS (6), /* fp_add */
  944. COSTS_N_INSNS (4), /* fp_mult_sf */
  945. COSTS_N_INSNS (5), /* fp_mult_df */
  946. COSTS_N_INSNS (23), /* fp_div_sf */
  947. COSTS_N_INSNS (36), /* fp_div_df */
  948. COSTS_N_INSNS (5), /* int_mult_si */
  949. COSTS_N_INSNS (5), /* int_mult_di */
  950. COSTS_N_INSNS (36), /* int_div_si */
  951. COSTS_N_INSNS (36), /* int_div_di */
  952. 1, /* branch_cost */
  953. 4 /* memory_latency */
  954. },
  955. { /* R5400 */
  956. COSTS_N_INSNS (6), /* fp_add */
  957. COSTS_N_INSNS (5), /* fp_mult_sf */
  958. COSTS_N_INSNS (6), /* fp_mult_df */
  959. COSTS_N_INSNS (30), /* fp_div_sf */
  960. COSTS_N_INSNS (59), /* fp_div_df */
  961. COSTS_N_INSNS (3), /* int_mult_si */
  962. COSTS_N_INSNS (4), /* int_mult_di */
  963. COSTS_N_INSNS (42), /* int_div_si */
  964. COSTS_N_INSNS (74), /* int_div_di */
  965. 1, /* branch_cost */
  966. 4 /* memory_latency */
  967. },
  968. { /* R5500 */
  969. COSTS_N_INSNS (6), /* fp_add */
  970. COSTS_N_INSNS (5), /* fp_mult_sf */
  971. COSTS_N_INSNS (6), /* fp_mult_df */
  972. COSTS_N_INSNS (30), /* fp_div_sf */
  973. COSTS_N_INSNS (59), /* fp_div_df */
  974. COSTS_N_INSNS (5), /* int_mult_si */
  975. COSTS_N_INSNS (9), /* int_mult_di */
  976. COSTS_N_INSNS (42), /* int_div_si */
  977. COSTS_N_INSNS (74), /* int_div_di */
  978. 1, /* branch_cost */
  979. 4 /* memory_latency */
  980. },
  981. { /* R5900 */
  982. COSTS_N_INSNS (4), /* fp_add */
  983. COSTS_N_INSNS (4), /* fp_mult_sf */
  984. COSTS_N_INSNS (256), /* fp_mult_df */
  985. COSTS_N_INSNS (8), /* fp_div_sf */
  986. COSTS_N_INSNS (256), /* fp_div_df */
  987. COSTS_N_INSNS (4), /* int_mult_si */
  988. COSTS_N_INSNS (256), /* int_mult_di */
  989. COSTS_N_INSNS (37), /* int_div_si */
  990. COSTS_N_INSNS (256), /* int_div_di */
  991. 1, /* branch_cost */
  992. 4 /* memory_latency */
  993. },
  994. { /* R7000 */
  995. /* The only costs that are changed here are
  996. integer multiplication. */
  997. COSTS_N_INSNS (6), /* fp_add */
  998. COSTS_N_INSNS (7), /* fp_mult_sf */
  999. COSTS_N_INSNS (8), /* fp_mult_df */
  1000. COSTS_N_INSNS (23), /* fp_div_sf */
  1001. COSTS_N_INSNS (36), /* fp_div_df */
  1002. COSTS_N_INSNS (5), /* int_mult_si */
  1003. COSTS_N_INSNS (9), /* int_mult_di */
  1004. COSTS_N_INSNS (69), /* int_div_si */
  1005. COSTS_N_INSNS (69), /* int_div_di */
  1006. 1, /* branch_cost */
  1007. 4 /* memory_latency */
  1008. },
  1009. { /* R8000 */
  1010. DEFAULT_COSTS
  1011. },
  1012. { /* R9000 */
  1013. /* The only costs that are changed here are
  1014. integer multiplication. */
  1015. COSTS_N_INSNS (6), /* fp_add */
  1016. COSTS_N_INSNS (7), /* fp_mult_sf */
  1017. COSTS_N_INSNS (8), /* fp_mult_df */
  1018. COSTS_N_INSNS (23), /* fp_div_sf */
  1019. COSTS_N_INSNS (36), /* fp_div_df */
  1020. COSTS_N_INSNS (3), /* int_mult_si */
  1021. COSTS_N_INSNS (8), /* int_mult_di */
  1022. COSTS_N_INSNS (69), /* int_div_si */
  1023. COSTS_N_INSNS (69), /* int_div_di */
  1024. 1, /* branch_cost */
  1025. 4 /* memory_latency */
  1026. },
  1027. { /* R1x000 */
  1028. COSTS_N_INSNS (2), /* fp_add */
  1029. COSTS_N_INSNS (2), /* fp_mult_sf */
  1030. COSTS_N_INSNS (2), /* fp_mult_df */
  1031. COSTS_N_INSNS (12), /* fp_div_sf */
  1032. COSTS_N_INSNS (19), /* fp_div_df */
  1033. COSTS_N_INSNS (5), /* int_mult_si */
  1034. COSTS_N_INSNS (9), /* int_mult_di */
  1035. COSTS_N_INSNS (34), /* int_div_si */
  1036. COSTS_N_INSNS (66), /* int_div_di */
  1037. 1, /* branch_cost */
  1038. 4 /* memory_latency */
  1039. },
  1040. { /* SB1 */
  1041. /* These costs are the same as the SB-1A below. */
  1042. COSTS_N_INSNS (4), /* fp_add */
  1043. COSTS_N_INSNS (4), /* fp_mult_sf */
  1044. COSTS_N_INSNS (4), /* fp_mult_df */
  1045. COSTS_N_INSNS (24), /* fp_div_sf */
  1046. COSTS_N_INSNS (32), /* fp_div_df */
  1047. COSTS_N_INSNS (3), /* int_mult_si */
  1048. COSTS_N_INSNS (4), /* int_mult_di */
  1049. COSTS_N_INSNS (36), /* int_div_si */
  1050. COSTS_N_INSNS (68), /* int_div_di */
  1051. 1, /* branch_cost */
  1052. 4 /* memory_latency */
  1053. },
  1054. { /* SB1-A */
  1055. /* These costs are the same as the SB-1 above. */
  1056. COSTS_N_INSNS (4), /* fp_add */
  1057. COSTS_N_INSNS (4), /* fp_mult_sf */
  1058. COSTS_N_INSNS (4), /* fp_mult_df */
  1059. COSTS_N_INSNS (24), /* fp_div_sf */
  1060. COSTS_N_INSNS (32), /* fp_div_df */
  1061. COSTS_N_INSNS (3), /* int_mult_si */
  1062. COSTS_N_INSNS (4), /* int_mult_di */
  1063. COSTS_N_INSNS (36), /* int_div_si */
  1064. COSTS_N_INSNS (68), /* int_div_di */
  1065. 1, /* branch_cost */
  1066. 4 /* memory_latency */
  1067. },
  1068. { /* SR71000 */
  1069. DEFAULT_COSTS
  1070. },
  1071. { /* XLR */
  1072. SOFT_FP_COSTS,
  1073. COSTS_N_INSNS (8), /* int_mult_si */
  1074. COSTS_N_INSNS (8), /* int_mult_di */
  1075. COSTS_N_INSNS (72), /* int_div_si */
  1076. COSTS_N_INSNS (72), /* int_div_di */
  1077. 1, /* branch_cost */
  1078. 4 /* memory_latency */
  1079. },
  1080. { /* XLP */
  1081. /* These costs are the same as 5KF above. */
  1082. COSTS_N_INSNS (4), /* fp_add */
  1083. COSTS_N_INSNS (4), /* fp_mult_sf */
  1084. COSTS_N_INSNS (5), /* fp_mult_df */
  1085. COSTS_N_INSNS (17), /* fp_div_sf */
  1086. COSTS_N_INSNS (32), /* fp_div_df */
  1087. COSTS_N_INSNS (4), /* int_mult_si */
  1088. COSTS_N_INSNS (11), /* int_mult_di */
  1089. COSTS_N_INSNS (36), /* int_div_si */
  1090. COSTS_N_INSNS (68), /* int_div_di */
  1091. 1, /* branch_cost */
  1092. 4 /* memory_latency */
  1093. },
  1094. { /* P5600 */
  1095. COSTS_N_INSNS (4), /* fp_add */
  1096. COSTS_N_INSNS (5), /* fp_mult_sf */
  1097. COSTS_N_INSNS (5), /* fp_mult_df */
  1098. COSTS_N_INSNS (17), /* fp_div_sf */
  1099. COSTS_N_INSNS (17), /* fp_div_df */
  1100. COSTS_N_INSNS (5), /* int_mult_si */
  1101. COSTS_N_INSNS (5), /* int_mult_di */
  1102. COSTS_N_INSNS (8), /* int_div_si */
  1103. COSTS_N_INSNS (8), /* int_div_di */
  1104. 2, /* branch_cost */
  1105. 4 /* memory_latency */
  1106. },
  1107. { /* W32 */
  1108. COSTS_N_INSNS (4), /* fp_add */
  1109. COSTS_N_INSNS (4), /* fp_mult_sf */
  1110. COSTS_N_INSNS (5), /* fp_mult_df */
  1111. COSTS_N_INSNS (17), /* fp_div_sf */
  1112. COSTS_N_INSNS (32), /* fp_div_df */
  1113. COSTS_N_INSNS (5), /* int_mult_si */
  1114. COSTS_N_INSNS (5), /* int_mult_di */
  1115. COSTS_N_INSNS (41), /* int_div_si */
  1116. COSTS_N_INSNS (41), /* int_div_di */
  1117. 1, /* branch_cost */
  1118. 4 /* memory_latency */
  1119. },
  1120. { /* W64 */
  1121. COSTS_N_INSNS (4), /* fp_add */
  1122. COSTS_N_INSNS (4), /* fp_mult_sf */
  1123. COSTS_N_INSNS (5), /* fp_mult_df */
  1124. COSTS_N_INSNS (17), /* fp_div_sf */
  1125. COSTS_N_INSNS (32), /* fp_div_df */
  1126. COSTS_N_INSNS (5), /* int_mult_si */
  1127. COSTS_N_INSNS (5), /* int_mult_di */
  1128. COSTS_N_INSNS (41), /* int_div_si */
  1129. COSTS_N_INSNS (41), /* int_div_di */
  1130. 1, /* branch_cost */
  1131. 4 /* memory_latency */
  1132. }
  1133. };
  1134. static rtx mips_find_pic_call_symbol (rtx_insn *, rtx, bool);
  1135. static int mips_register_move_cost (machine_mode, reg_class_t,
  1136. reg_class_t);
  1137. static unsigned int mips_function_arg_boundary (machine_mode, const_tree);
  1138. static machine_mode mips_get_reg_raw_mode (int regno);
  1139. struct mips16_flip_traits : default_hashmap_traits
  1140. {
  1141. static hashval_t hash (const char *s) { return htab_hash_string (s); }
  1142. static bool
  1143. equal_keys (const char *a, const char *b)
  1144. {
  1145. return !strcmp (a, b);
  1146. }
  1147. };
  1148. /* This hash table keeps track of implicit "mips16" and "nomips16" attributes
  1149. for -mflip_mips16. It maps decl names onto a boolean mode setting. */
  1150. static GTY (()) hash_map<const char *, bool, mips16_flip_traits> *
  1151. mflip_mips16_htab;
  1152. /* True if -mflip-mips16 should next add an attribute for the default MIPS16
  1153. mode, false if it should next add an attribute for the opposite mode. */
  1154. static GTY(()) bool mips16_flipper;
  1155. /* DECL is a function that needs a default "mips16" or "nomips16" attribute
  1156. for -mflip-mips16. Return true if it should use "mips16" and false if
  1157. it should use "nomips16". */
  1158. static bool
  1159. mflip_mips16_use_mips16_p (tree decl)
  1160. {
  1161. const char *name;
  1162. bool base_is_mips16 = (mips_base_compression_flags & MASK_MIPS16) != 0;
  1163. /* Use the opposite of the command-line setting for anonymous decls. */
  1164. if (!DECL_NAME (decl))
  1165. return !base_is_mips16;
  1166. if (!mflip_mips16_htab)
  1167. mflip_mips16_htab
  1168. = hash_map<const char *, bool, mips16_flip_traits>::create_ggc (37);
  1169. name = IDENTIFIER_POINTER (DECL_NAME (decl));
  1170. bool existed;
  1171. bool *slot = &mflip_mips16_htab->get_or_insert (name, &existed);
  1172. if (!existed)
  1173. {
  1174. mips16_flipper = !mips16_flipper;
  1175. *slot = mips16_flipper ? !base_is_mips16 : base_is_mips16;
  1176. }
  1177. return *slot;
  1178. }
  1179. /* Predicates to test for presence of "near" and "far"/"long_call"
  1180. attributes on the given TYPE. */
  1181. static bool
  1182. mips_near_type_p (const_tree type)
  1183. {
  1184. return lookup_attribute ("near", TYPE_ATTRIBUTES (type)) != NULL;
  1185. }
  1186. static bool
  1187. mips_far_type_p (const_tree type)
  1188. {
  1189. return (lookup_attribute ("long_call", TYPE_ATTRIBUTES (type)) != NULL
  1190. || lookup_attribute ("far", TYPE_ATTRIBUTES (type)) != NULL);
  1191. }
  1192. /* Check if the interrupt attribute is set for a function. */
  1193. static bool
  1194. mips_interrupt_type_p (tree type)
  1195. {
  1196. return lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type)) != NULL;
  1197. }
  1198. /* Check if the attribute to use shadow register set is set for a function. */
  1199. static bool
  1200. mips_use_shadow_register_set_p (tree type)
  1201. {
  1202. return lookup_attribute ("use_shadow_register_set",
  1203. TYPE_ATTRIBUTES (type)) != NULL;
  1204. }
  1205. /* Check if the attribute to keep interrupts masked is set for a function. */
  1206. static bool
  1207. mips_keep_interrupts_masked_p (tree type)
  1208. {
  1209. return lookup_attribute ("keep_interrupts_masked",
  1210. TYPE_ATTRIBUTES (type)) != NULL;
  1211. }
  1212. /* Check if the attribute to use debug exception return is set for
  1213. a function. */
  1214. static bool
  1215. mips_use_debug_exception_return_p (tree type)
  1216. {
  1217. return lookup_attribute ("use_debug_exception_return",
  1218. TYPE_ATTRIBUTES (type)) != NULL;
  1219. }
  1220. /* Return the set of compression modes that are explicitly required
  1221. by the attributes in ATTRIBUTES. */
  1222. static unsigned int
  1223. mips_get_compress_on_flags (tree attributes)
  1224. {
  1225. unsigned int flags = 0;
  1226. if (lookup_attribute ("mips16", attributes) != NULL)
  1227. flags |= MASK_MIPS16;
  1228. if (lookup_attribute ("micromips", attributes) != NULL)
  1229. flags |= MASK_MICROMIPS;
  1230. return flags;
  1231. }
  1232. /* Return the set of compression modes that are explicitly forbidden
  1233. by the attributes in ATTRIBUTES. */
  1234. static unsigned int
  1235. mips_get_compress_off_flags (tree attributes)
  1236. {
  1237. unsigned int flags = 0;
  1238. if (lookup_attribute ("nocompression", attributes) != NULL)
  1239. flags |= MASK_MIPS16 | MASK_MICROMIPS;
  1240. if (lookup_attribute ("nomips16", attributes) != NULL)
  1241. flags |= MASK_MIPS16;
  1242. if (lookup_attribute ("nomicromips", attributes) != NULL)
  1243. flags |= MASK_MICROMIPS;
  1244. return flags;
  1245. }
  1246. /* Return the compression mode that should be used for function DECL.
  1247. Return the ambient setting if DECL is null. */
  1248. static unsigned int
  1249. mips_get_compress_mode (tree decl)
  1250. {
  1251. unsigned int flags, force_on;
  1252. flags = mips_base_compression_flags;
  1253. if (decl)
  1254. {
  1255. /* Nested functions must use the same frame pointer as their
  1256. parent and must therefore use the same ISA mode. */
  1257. tree parent = decl_function_context (decl);
  1258. if (parent)
  1259. decl = parent;
  1260. force_on = mips_get_compress_on_flags (DECL_ATTRIBUTES (decl));
  1261. if (force_on)
  1262. return force_on;
  1263. flags &= ~mips_get_compress_off_flags (DECL_ATTRIBUTES (decl));
  1264. }
  1265. return flags;
  1266. }
  1267. /* Return the attribute name associated with MASK_MIPS16 and MASK_MICROMIPS
  1268. flags FLAGS. */
  1269. static const char *
  1270. mips_get_compress_on_name (unsigned int flags)
  1271. {
  1272. if (flags == MASK_MIPS16)
  1273. return "mips16";
  1274. return "micromips";
  1275. }
  1276. /* Return the attribute name that forbids MASK_MIPS16 and MASK_MICROMIPS
  1277. flags FLAGS. */
  1278. static const char *
  1279. mips_get_compress_off_name (unsigned int flags)
  1280. {
  1281. if (flags == MASK_MIPS16)
  1282. return "nomips16";
  1283. if (flags == MASK_MICROMIPS)
  1284. return "nomicromips";
  1285. return "nocompression";
  1286. }
  1287. /* Implement TARGET_COMP_TYPE_ATTRIBUTES. */
  1288. static int
  1289. mips_comp_type_attributes (const_tree type1, const_tree type2)
  1290. {
  1291. /* Disallow mixed near/far attributes. */
  1292. if (mips_far_type_p (type1) && mips_near_type_p (type2))
  1293. return 0;
  1294. if (mips_near_type_p (type1) && mips_far_type_p (type2))
  1295. return 0;
  1296. return 1;
  1297. }
  1298. /* Implement TARGET_INSERT_ATTRIBUTES. */
  1299. static void
  1300. mips_insert_attributes (tree decl, tree *attributes)
  1301. {
  1302. const char *name;
  1303. unsigned int compression_flags, nocompression_flags;
  1304. /* Check for "mips16" and "nomips16" attributes. */
  1305. compression_flags = mips_get_compress_on_flags (*attributes);
  1306. nocompression_flags = mips_get_compress_off_flags (*attributes);
  1307. if (TREE_CODE (decl) != FUNCTION_DECL)
  1308. {
  1309. if (nocompression_flags)
  1310. error ("%qs attribute only applies to functions",
  1311. mips_get_compress_off_name (nocompression_flags));
  1312. if (compression_flags)
  1313. error ("%qs attribute only applies to functions",
  1314. mips_get_compress_on_name (nocompression_flags));
  1315. }
  1316. else
  1317. {
  1318. compression_flags |= mips_get_compress_on_flags (DECL_ATTRIBUTES (decl));
  1319. nocompression_flags |=
  1320. mips_get_compress_off_flags (DECL_ATTRIBUTES (decl));
  1321. if (compression_flags && nocompression_flags)
  1322. error ("%qE cannot have both %qs and %qs attributes",
  1323. DECL_NAME (decl), mips_get_compress_on_name (compression_flags),
  1324. mips_get_compress_off_name (nocompression_flags));
  1325. if (compression_flags & MASK_MIPS16
  1326. && compression_flags & MASK_MICROMIPS)
  1327. error ("%qE cannot have both %qs and %qs attributes",
  1328. DECL_NAME (decl), "mips16", "micromips");
  1329. if (TARGET_FLIP_MIPS16
  1330. && !DECL_ARTIFICIAL (decl)
  1331. && compression_flags == 0
  1332. && nocompression_flags == 0)
  1333. {
  1334. /* Implement -mflip-mips16. If DECL has neither a "nomips16" nor a
  1335. "mips16" attribute, arbitrarily pick one. We must pick the same
  1336. setting for duplicate declarations of a function. */
  1337. name = mflip_mips16_use_mips16_p (decl) ? "mips16" : "nomips16";
  1338. *attributes = tree_cons (get_identifier (name), NULL, *attributes);
  1339. name = "nomicromips";
  1340. *attributes = tree_cons (get_identifier (name), NULL, *attributes);
  1341. }
  1342. }
  1343. }
  1344. /* Implement TARGET_MERGE_DECL_ATTRIBUTES. */
  1345. static tree
  1346. mips_merge_decl_attributes (tree olddecl, tree newdecl)
  1347. {
  1348. unsigned int diff;
  1349. diff = (mips_get_compress_on_flags (DECL_ATTRIBUTES (olddecl))
  1350. ^ mips_get_compress_on_flags (DECL_ATTRIBUTES (newdecl)));
  1351. if (diff)
  1352. error ("%qE redeclared with conflicting %qs attributes",
  1353. DECL_NAME (newdecl), mips_get_compress_on_name (diff));
  1354. diff = (mips_get_compress_off_flags (DECL_ATTRIBUTES (olddecl))
  1355. ^ mips_get_compress_off_flags (DECL_ATTRIBUTES (newdecl)));
  1356. if (diff)
  1357. error ("%qE redeclared with conflicting %qs attributes",
  1358. DECL_NAME (newdecl), mips_get_compress_off_name (diff));
  1359. return merge_attributes (DECL_ATTRIBUTES (olddecl),
  1360. DECL_ATTRIBUTES (newdecl));
  1361. }
  1362. /* Implement TARGET_CAN_INLINE_P. */
  1363. static bool
  1364. mips_can_inline_p (tree caller, tree callee)
  1365. {
  1366. if (mips_get_compress_mode (callee) != mips_get_compress_mode (caller))
  1367. return false;
  1368. return default_target_can_inline_p (caller, callee);
  1369. }
  1370. /* If X is a PLUS of a CONST_INT, return the two terms in *BASE_PTR
  1371. and *OFFSET_PTR. Return X in *BASE_PTR and 0 in *OFFSET_PTR otherwise. */
  1372. static void
  1373. mips_split_plus (rtx x, rtx *base_ptr, HOST_WIDE_INT *offset_ptr)
  1374. {
  1375. if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
  1376. {
  1377. *base_ptr = XEXP (x, 0);
  1378. *offset_ptr = INTVAL (XEXP (x, 1));
  1379. }
  1380. else
  1381. {
  1382. *base_ptr = x;
  1383. *offset_ptr = 0;
  1384. }
  1385. }
  1386. static unsigned int mips_build_integer (struct mips_integer_op *,
  1387. unsigned HOST_WIDE_INT);
  1388. /* A subroutine of mips_build_integer, with the same interface.
  1389. Assume that the final action in the sequence should be a left shift. */
  1390. static unsigned int
  1391. mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value)
  1392. {
  1393. unsigned int i, shift;
  1394. /* Shift VALUE right until its lowest bit is set. Shift arithmetically
  1395. since signed numbers are easier to load than unsigned ones. */
  1396. shift = 0;
  1397. while ((value & 1) == 0)
  1398. value /= 2, shift++;
  1399. i = mips_build_integer (codes, value);
  1400. codes[i].code = ASHIFT;
  1401. codes[i].value = shift;
  1402. return i + 1;
  1403. }
  1404. /* As for mips_build_shift, but assume that the final action will be
  1405. an IOR or PLUS operation. */
  1406. static unsigned int
  1407. mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value)
  1408. {
  1409. unsigned HOST_WIDE_INT high;
  1410. unsigned int i;
  1411. high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
  1412. if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
  1413. {
  1414. /* The constant is too complex to load with a simple LUI/ORI pair,
  1415. so we want to give the recursive call as many trailing zeros as
  1416. possible. In this case, we know bit 16 is set and that the
  1417. low 16 bits form a negative number. If we subtract that number
  1418. from VALUE, we will clear at least the lowest 17 bits, maybe more. */
  1419. i = mips_build_integer (codes, CONST_HIGH_PART (value));
  1420. codes[i].code = PLUS;
  1421. codes[i].value = CONST_LOW_PART (value);
  1422. }
  1423. else
  1424. {
  1425. /* Either this is a simple LUI/ORI pair, or clearing the lowest 16
  1426. bits gives a value with at least 17 trailing zeros. */
  1427. i = mips_build_integer (codes, high);
  1428. codes[i].code = IOR;
  1429. codes[i].value = value & 0xffff;
  1430. }
  1431. return i + 1;
  1432. }
  1433. /* Fill CODES with a sequence of rtl operations to load VALUE.
  1434. Return the number of operations needed. */
  1435. static unsigned int
  1436. mips_build_integer (struct mips_integer_op *codes,
  1437. unsigned HOST_WIDE_INT value)
  1438. {
  1439. if (SMALL_OPERAND (value)
  1440. || SMALL_OPERAND_UNSIGNED (value)
  1441. || LUI_OPERAND (value))
  1442. {
  1443. /* The value can be loaded with a single instruction. */
  1444. codes[0].code = UNKNOWN;
  1445. codes[0].value = value;
  1446. return 1;
  1447. }
  1448. else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
  1449. {
  1450. /* Either the constant is a simple LUI/ORI combination or its
  1451. lowest bit is set. We don't want to shift in this case. */
  1452. return mips_build_lower (codes, value);
  1453. }
  1454. else if ((value & 0xffff) == 0)
  1455. {
  1456. /* The constant will need at least three actions. The lowest
  1457. 16 bits are clear, so the final action will be a shift. */
  1458. return mips_build_shift (codes, value);
  1459. }
  1460. else
  1461. {
  1462. /* The final action could be a shift, add or inclusive OR.
  1463. Rather than use a complex condition to select the best
  1464. approach, try both mips_build_shift and mips_build_lower
  1465. and pick the one that gives the shortest sequence.
  1466. Note that this case is only used once per constant. */
  1467. struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
  1468. unsigned int cost, alt_cost;
  1469. cost = mips_build_shift (codes, value);
  1470. alt_cost = mips_build_lower (alt_codes, value);
  1471. if (alt_cost < cost)
  1472. {
  1473. memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
  1474. cost = alt_cost;
  1475. }
  1476. return cost;
  1477. }
  1478. }
  1479. /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
  1480. static bool
  1481. mips_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
  1482. {
  1483. return mips_const_insns (x) > 0;
  1484. }
  1485. /* Return a SYMBOL_REF for a MIPS16 function called NAME. */
  1486. static rtx
  1487. mips16_stub_function (const char *name)
  1488. {
  1489. rtx x;
  1490. x = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
  1491. SYMBOL_REF_FLAGS (x) |= (SYMBOL_FLAG_EXTERNAL | SYMBOL_FLAG_FUNCTION);
  1492. return x;
  1493. }
  1494. /* Return a legitimate call address for STUB, given that STUB is a MIPS16
  1495. support function. */
  1496. static rtx
  1497. mips16_stub_call_address (mips_one_only_stub *stub)
  1498. {
  1499. rtx fn = mips16_stub_function (stub->get_name ());
  1500. SYMBOL_REF_FLAGS (fn) |= SYMBOL_FLAG_LOCAL;
  1501. if (!call_insn_operand (fn, VOIDmode))
  1502. fn = force_reg (Pmode, fn);
  1503. return fn;
  1504. }
  1505. /* A stub for moving the thread pointer into TLS_GET_TP_REGNUM. */
  1506. class mips16_rdhwr_one_only_stub : public mips_one_only_stub
  1507. {
  1508. virtual const char *get_name ();
  1509. virtual void output_body ();
  1510. };
  1511. const char *
  1512. mips16_rdhwr_one_only_stub::get_name ()
  1513. {
  1514. return "__mips16_rdhwr";
  1515. }
  1516. void
  1517. mips16_rdhwr_one_only_stub::output_body ()
  1518. {
  1519. fprintf (asm_out_file,
  1520. "\t.set\tpush\n"
  1521. "\t.set\tmips32r2\n"
  1522. "\t.set\tnoreorder\n"
  1523. "\trdhwr\t$3,$29\n"
  1524. "\t.set\tpop\n"
  1525. "\tj\t$31\n");
  1526. }
  1527. /* A stub for moving the FCSR into GET_FCSR_REGNUM. */
  1528. class mips16_get_fcsr_one_only_stub : public mips_one_only_stub
  1529. {
  1530. virtual const char *get_name ();
  1531. virtual void output_body ();
  1532. };
  1533. const char *
  1534. mips16_get_fcsr_one_only_stub::get_name ()
  1535. {
  1536. return "__mips16_get_fcsr";
  1537. }
  1538. void
  1539. mips16_get_fcsr_one_only_stub::output_body ()
  1540. {
  1541. fprintf (asm_out_file,
  1542. "\tcfc1\t%s,$31\n"
  1543. "\tj\t$31\n", reg_names[GET_FCSR_REGNUM]);
  1544. }
  1545. /* A stub for moving SET_FCSR_REGNUM into the FCSR. */
  1546. class mips16_set_fcsr_one_only_stub : public mips_one_only_stub
  1547. {
  1548. virtual const char *get_name ();
  1549. virtual void output_body ();
  1550. };
  1551. const char *
  1552. mips16_set_fcsr_one_only_stub::get_name ()
  1553. {
  1554. return "__mips16_set_fcsr";
  1555. }
  1556. void
  1557. mips16_set_fcsr_one_only_stub::output_body ()
  1558. {
  1559. fprintf (asm_out_file,
  1560. "\tctc1\t%s,$31\n"
  1561. "\tj\t$31\n", reg_names[SET_FCSR_REGNUM]);
  1562. }
  1563. /* Return true if symbols of type TYPE require a GOT access. */
  1564. static bool
  1565. mips_got_symbol_type_p (enum mips_symbol_type type)
  1566. {
  1567. switch (type)
  1568. {
  1569. case SYMBOL_GOT_PAGE_OFST:
  1570. case SYMBOL_GOT_DISP:
  1571. return true;
  1572. default:
  1573. return false;
  1574. }
  1575. }
  1576. /* Return true if X is a thread-local symbol. */
  1577. static bool
  1578. mips_tls_symbol_p (rtx x)
  1579. {
  1580. return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0;
  1581. }
  1582. /* Return true if SYMBOL_REF X is associated with a global symbol
  1583. (in the STB_GLOBAL sense). */
  1584. static bool
  1585. mips_global_symbol_p (const_rtx x)
  1586. {
  1587. const_tree decl = SYMBOL_REF_DECL (x);
  1588. if (!decl)
  1589. return !SYMBOL_REF_LOCAL_P (x) || SYMBOL_REF_EXTERNAL_P (x);
  1590. /* Weakref symbols are not TREE_PUBLIC, but their targets are global
  1591. or weak symbols. Relocations in the object file will be against
  1592. the target symbol, so it's that symbol's binding that matters here. */
  1593. return DECL_P (decl) && (TREE_PUBLIC (decl) || DECL_WEAK (decl));
  1594. }
  1595. /* Return true if function X is a libgcc MIPS16 stub function. */
  1596. static bool
  1597. mips16_stub_function_p (const_rtx x)
  1598. {
  1599. return (GET_CODE (x) == SYMBOL_REF
  1600. && strncmp (XSTR (x, 0), "__mips16_", 9) == 0);
  1601. }
  1602. /* Return true if function X is a locally-defined and locally-binding
  1603. MIPS16 function. */
  1604. static bool
  1605. mips16_local_function_p (const_rtx x)
  1606. {
  1607. return (GET_CODE (x) == SYMBOL_REF
  1608. && SYMBOL_REF_LOCAL_P (x)
  1609. && !SYMBOL_REF_EXTERNAL_P (x)
  1610. && (mips_get_compress_mode (SYMBOL_REF_DECL (x)) & MASK_MIPS16));
  1611. }
  1612. /* Return true if SYMBOL_REF X binds locally. */
  1613. static bool
  1614. mips_symbol_binds_local_p (const_rtx x)
  1615. {
  1616. return (SYMBOL_REF_DECL (x)
  1617. ? targetm.binds_local_p (SYMBOL_REF_DECL (x))
  1618. : SYMBOL_REF_LOCAL_P (x));
  1619. }
  1620. /* Return true if rtx constants of mode MODE should be put into a small
  1621. data section. */
  1622. static bool
  1623. mips_rtx_constant_in_small_data_p (machine_mode mode)
  1624. {
  1625. return (!TARGET_EMBEDDED_DATA
  1626. && TARGET_LOCAL_SDATA
  1627. && GET_MODE_SIZE (mode) <= mips_small_data_threshold);
  1628. }
  1629. /* Return true if X should not be moved directly into register $25.
  1630. We need this because many versions of GAS will treat "la $25,foo" as
  1631. part of a call sequence and so allow a global "foo" to be lazily bound. */
  1632. bool
  1633. mips_dangerous_for_la25_p (rtx x)
  1634. {
  1635. return (!TARGET_EXPLICIT_RELOCS
  1636. && TARGET_USE_GOT
  1637. && GET_CODE (x) == SYMBOL_REF
  1638. && mips_global_symbol_p (x));
  1639. }
  1640. /* Return true if calls to X might need $25 to be valid on entry. */
  1641. bool
  1642. mips_use_pic_fn_addr_reg_p (const_rtx x)
  1643. {
  1644. if (!TARGET_USE_PIC_FN_ADDR_REG)
  1645. return false;
  1646. /* MIPS16 stub functions are guaranteed not to use $25. */
  1647. if (mips16_stub_function_p (x))
  1648. return false;
  1649. if (GET_CODE (x) == SYMBOL_REF)
  1650. {
  1651. /* If PLTs and copy relocations are available, the static linker
  1652. will make sure that $25 is valid on entry to the target function. */
  1653. if (TARGET_ABICALLS_PIC0)
  1654. return false;
  1655. /* Locally-defined functions use absolute accesses to set up
  1656. the global pointer. */
  1657. if (TARGET_ABSOLUTE_ABICALLS
  1658. && mips_symbol_binds_local_p (x)
  1659. && !SYMBOL_REF_EXTERNAL_P (x))
  1660. return false;
  1661. }
  1662. return true;
  1663. }
  1664. /* Return the method that should be used to access SYMBOL_REF or
  1665. LABEL_REF X in context CONTEXT. */
  1666. static enum mips_symbol_type
  1667. mips_classify_symbol (const_rtx x, enum mips_symbol_context context)
  1668. {
  1669. if (TARGET_RTP_PIC)
  1670. return SYMBOL_GOT_DISP;
  1671. if (GET_CODE (x) == LABEL_REF)
  1672. {
  1673. /* Only return SYMBOL_PC_RELATIVE if we are generating MIPS16
  1674. code and if we know that the label is in the current function's
  1675. text section. LABEL_REFs are used for jump tables as well as
  1676. text labels, so we must check whether jump tables live in the
  1677. text section. */
  1678. if (TARGET_MIPS16_SHORT_JUMP_TABLES
  1679. && !LABEL_REF_NONLOCAL_P (x))
  1680. return SYMBOL_PC_RELATIVE;
  1681. if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS)
  1682. return SYMBOL_GOT_PAGE_OFST;
  1683. return SYMBOL_ABSOLUTE;
  1684. }
  1685. gcc_assert (GET_CODE (x) == SYMBOL_REF);
  1686. if (SYMBOL_REF_TLS_MODEL (x))
  1687. return SYMBOL_TLS;
  1688. if (CONSTANT_POOL_ADDRESS_P (x))
  1689. {
  1690. if (TARGET_MIPS16_TEXT_LOADS)
  1691. return SYMBOL_PC_RELATIVE;
  1692. if (TARGET_MIPS16_PCREL_LOADS && context == SYMBOL_CONTEXT_MEM)
  1693. return SYMBOL_PC_RELATIVE;
  1694. if (mips_rtx_constant_in_small_data_p (get_pool_mode (x)))
  1695. return SYMBOL_GP_RELATIVE;
  1696. }
  1697. /* Do not use small-data accesses for weak symbols; they may end up
  1698. being zero. */
  1699. if (TARGET_GPOPT && SYMBOL_REF_SMALL_P (x) && !SYMBOL_REF_WEAK (x))
  1700. return SYMBOL_GP_RELATIVE;
  1701. /* Don't use GOT accesses for locally-binding symbols when -mno-shared
  1702. is in effect. */
  1703. if (TARGET_ABICALLS_PIC2
  1704. && !(TARGET_ABSOLUTE_ABICALLS && mips_symbol_binds_local_p (x)))
  1705. {
  1706. /* There are three cases to consider:
  1707. - o32 PIC (either with or without explicit relocs)
  1708. - n32/n64 PIC without explicit relocs
  1709. - n32/n64 PIC with explicit relocs
  1710. In the first case, both local and global accesses will use an
  1711. R_MIPS_GOT16 relocation. We must correctly predict which of
  1712. the two semantics (local or global) the assembler and linker
  1713. will apply. The choice depends on the symbol's binding rather
  1714. than its visibility.
  1715. In the second case, the assembler will not use R_MIPS_GOT16
  1716. relocations, but it chooses between local and global accesses
  1717. in the same way as for o32 PIC.
  1718. In the third case we have more freedom since both forms of
  1719. access will work for any kind of symbol. However, there seems
  1720. little point in doing things differently. */
  1721. if (mips_global_symbol_p (x))
  1722. return SYMBOL_GOT_DISP;
  1723. return SYMBOL_GOT_PAGE_OFST;
  1724. }
  1725. return SYMBOL_ABSOLUTE;
  1726. }
  1727. /* Classify the base of symbolic expression X, given that X appears in
  1728. context CONTEXT. */
  1729. static enum mips_symbol_type
  1730. mips_classify_symbolic_expression (rtx x, enum mips_symbol_context context)
  1731. {
  1732. rtx offset;
  1733. split_const (x, &x, &offset);
  1734. if (UNSPEC_ADDRESS_P (x))
  1735. return UNSPEC_ADDRESS_TYPE (x);
  1736. return mips_classify_symbol (x, context);
  1737. }
  1738. /* Return true if OFFSET is within the range [0, ALIGN), where ALIGN
  1739. is the alignment in bytes of SYMBOL_REF X. */
  1740. static bool
  1741. mips_offset_within_alignment_p (rtx x, HOST_WIDE_INT offset)
  1742. {
  1743. HOST_WIDE_INT align;
  1744. align = SYMBOL_REF_DECL (x) ? DECL_ALIGN_UNIT (SYMBOL_REF_DECL (x)) : 1;
  1745. return IN_RANGE (offset, 0, align - 1);
  1746. }
  1747. /* Return true if X is a symbolic constant that can be used in context
  1748. CONTEXT. If it is, store the type of the symbol in *SYMBOL_TYPE. */
  1749. bool
  1750. mips_symbolic_constant_p (rtx x, enum mips_symbol_context context,
  1751. enum mips_symbol_type *symbol_type)
  1752. {
  1753. rtx offset;
  1754. split_const (x, &x, &offset);
  1755. if (UNSPEC_ADDRESS_P (x))
  1756. {
  1757. *symbol_type = UNSPEC_ADDRESS_TYPE (x);
  1758. x = UNSPEC_ADDRESS (x);
  1759. }
  1760. else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
  1761. {
  1762. *symbol_type = mips_classify_symbol (x, context);
  1763. if (*symbol_type == SYMBOL_TLS)
  1764. return false;
  1765. }
  1766. else
  1767. return false;
  1768. if (offset == const0_rtx)
  1769. return true;
  1770. /* Check whether a nonzero offset is valid for the underlying
  1771. relocations. */
  1772. switch (*symbol_type)
  1773. {
  1774. case SYMBOL_ABSOLUTE:
  1775. case SYMBOL_64_HIGH:
  1776. case SYMBOL_64_MID:
  1777. case SYMBOL_64_LOW:
  1778. /* If the target has 64-bit pointers and the object file only
  1779. supports 32-bit symbols, the values of those symbols will be
  1780. sign-extended. In this case we can't allow an arbitrary offset
  1781. in case the 32-bit value X + OFFSET has a different sign from X. */
  1782. if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS)
  1783. return offset_within_block_p (x, INTVAL (offset));
  1784. /* In other cases the relocations can handle any offset. */
  1785. return true;
  1786. case SYMBOL_PC_RELATIVE:
  1787. /* Allow constant pool references to be converted to LABEL+CONSTANT.
  1788. In this case, we no longer have access to the underlying constant,
  1789. but the original symbol-based access was known to be valid. */
  1790. if (GET_CODE (x) == LABEL_REF)
  1791. return true;
  1792. /* Fall through. */
  1793. case SYMBOL_GP_RELATIVE:
  1794. /* Make sure that the offset refers to something within the
  1795. same object block. This should guarantee that the final
  1796. PC- or GP-relative offset is within the 16-bit limit. */
  1797. return offset_within_block_p (x, INTVAL (offset));
  1798. case SYMBOL_GOT_PAGE_OFST:
  1799. case SYMBOL_GOTOFF_PAGE:
  1800. /* If the symbol is global, the GOT entry will contain the symbol's
  1801. address, and we will apply a 16-bit offset after loading it.
  1802. If the symbol is local, the linker should provide enough local
  1803. GOT entries for a 16-bit offset, but larger offsets may lead
  1804. to GOT overflow. */
  1805. return SMALL_INT (offset);
  1806. case SYMBOL_TPREL:
  1807. case SYMBOL_DTPREL:
  1808. /* There is no carry between the HI and LO REL relocations, so the
  1809. offset is only valid if we know it won't lead to such a carry. */
  1810. return mips_offset_within_alignment_p (x, INTVAL (offset));
  1811. case SYMBOL_GOT_DISP:
  1812. case SYMBOL_GOTOFF_DISP:
  1813. case SYMBOL_GOTOFF_CALL:
  1814. case SYMBOL_GOTOFF_LOADGP:
  1815. case SYMBOL_TLSGD:
  1816. case SYMBOL_TLSLDM:
  1817. case SYMBOL_GOTTPREL:
  1818. case SYMBOL_TLS:
  1819. case SYMBOL_HALF:
  1820. return false;
  1821. }
  1822. gcc_unreachable ();
  1823. }
  1824. /* Like mips_symbol_insns, but treat extended MIPS16 instructions as a
  1825. single instruction. We rely on the fact that, in the worst case,
  1826. all instructions involved in a MIPS16 address calculation are usually
  1827. extended ones. */
  1828. static int
  1829. mips_symbol_insns_1 (enum mips_symbol_type type, machine_mode mode)
  1830. {
  1831. if (mips_use_pcrel_pool_p[(int) type])
  1832. {
  1833. if (mode == MAX_MACHINE_MODE)
  1834. /* LEAs will be converted into constant-pool references by
  1835. mips_reorg. */
  1836. type = SYMBOL_PC_RELATIVE;
  1837. else
  1838. /* The constant must be loaded and then dereferenced. */
  1839. return 0;
  1840. }
  1841. switch (type)
  1842. {
  1843. case SYMBOL_ABSOLUTE:
  1844. /* When using 64-bit symbols, we need 5 preparatory instructions,
  1845. such as:
  1846. lui $at,%highest(symbol)
  1847. daddiu $at,$at,%higher(symbol)
  1848. dsll $at,$at,16
  1849. daddiu $at,$at,%hi(symbol)
  1850. dsll $at,$at,16
  1851. The final address is then $at + %lo(symbol). With 32-bit
  1852. symbols we just need a preparatory LUI for normal mode and
  1853. a preparatory LI and SLL for MIPS16. */
  1854. return ABI_HAS_64BIT_SYMBOLS ? 6 : TARGET_MIPS16 ? 3 : 2;
  1855. case SYMBOL_GP_RELATIVE:
  1856. /* Treat GP-relative accesses as taking a single instruction on
  1857. MIPS16 too; the copy of $gp can often be shared. */
  1858. return 1;
  1859. case SYMBOL_PC_RELATIVE:
  1860. /* PC-relative constants can be only be used with ADDIUPC,
  1861. DADDIUPC, LWPC and LDPC. */
  1862. if (mode == MAX_MACHINE_MODE
  1863. || GET_MODE_SIZE (mode) == 4
  1864. || GET_MODE_SIZE (mode) == 8)
  1865. return 1;
  1866. /* The constant must be loaded using ADDIUPC or DADDIUPC first. */
  1867. return 0;
  1868. case SYMBOL_GOT_DISP:
  1869. /* The constant will have to be loaded from the GOT before it
  1870. is used in an address. */
  1871. if (mode != MAX_MACHINE_MODE)
  1872. return 0;
  1873. /* Fall through. */
  1874. case SYMBOL_GOT_PAGE_OFST:
  1875. /* Unless -funit-at-a-time is in effect, we can't be sure whether the
  1876. local/global classification is accurate. The worst cases are:
  1877. (1) For local symbols when generating o32 or o64 code. The assembler
  1878. will use:
  1879. lw $at,%got(symbol)
  1880. nop
  1881. ...and the final address will be $at + %lo(symbol).
  1882. (2) For global symbols when -mxgot. The assembler will use:
  1883. lui $at,%got_hi(symbol)
  1884. (d)addu $at,$at,$gp
  1885. ...and the final address will be $at + %got_lo(symbol). */
  1886. return 3;
  1887. case SYMBOL_GOTOFF_PAGE:
  1888. case SYMBOL_GOTOFF_DISP:
  1889. case SYMBOL_GOTOFF_CALL:
  1890. case SYMBOL_GOTOFF_LOADGP:
  1891. case SYMBOL_64_HIGH:
  1892. case SYMBOL_64_MID:
  1893. case SYMBOL_64_LOW:
  1894. case SYMBOL_TLSGD:
  1895. case SYMBOL_TLSLDM:
  1896. case SYMBOL_DTPREL:
  1897. case SYMBOL_GOTTPREL:
  1898. case SYMBOL_TPREL:
  1899. case SYMBOL_HALF:
  1900. /* A 16-bit constant formed by a single relocation, or a 32-bit
  1901. constant formed from a high 16-bit relocation and a low 16-bit
  1902. relocation. Use mips_split_p to determine which. 32-bit
  1903. constants need an "lui; addiu" sequence for normal mode and
  1904. an "li; sll; addiu" sequence for MIPS16 mode. */
  1905. return !mips_split_p[type] ? 1 : TARGET_MIPS16 ? 3 : 2;
  1906. case SYMBOL_TLS:
  1907. /* We don't treat a bare TLS symbol as a constant. */
  1908. return 0;
  1909. }
  1910. gcc_unreachable ();
  1911. }
  1912. /* If MODE is MAX_MACHINE_MODE, return the number of instructions needed
  1913. to load symbols of type TYPE into a register. Return 0 if the given
  1914. type of symbol cannot be used as an immediate operand.
  1915. Otherwise, return the number of instructions needed to load or store
  1916. values of mode MODE to or from addresses of type TYPE. Return 0 if
  1917. the given type of symbol is not valid in addresses.
  1918. In both cases, instruction counts are based off BASE_INSN_LENGTH. */
  1919. static int
  1920. mips_symbol_insns (enum mips_symbol_type type, machine_mode mode)
  1921. {
  1922. return mips_symbol_insns_1 (type, mode) * (TARGET_MIPS16 ? 2 : 1);
  1923. }
  1924. /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
  1925. static bool
  1926. mips_cannot_force_const_mem (machine_mode mode, rtx x)
  1927. {
  1928. enum mips_symbol_type type;
  1929. rtx base, offset;
  1930. /* There is no assembler syntax for expressing an address-sized
  1931. high part. */
  1932. if (GET_CODE (x) == HIGH)
  1933. return true;
  1934. /* As an optimization, reject constants that mips_legitimize_move
  1935. can expand inline.
  1936. Suppose we have a multi-instruction sequence that loads constant C
  1937. into register R. If R does not get allocated a hard register, and
  1938. R is used in an operand that allows both registers and memory
  1939. references, reload will consider forcing C into memory and using
  1940. one of the instruction's memory alternatives. Returning false
  1941. here will force it to use an input reload instead. */
  1942. if (CONST_INT_P (x) && mips_legitimate_constant_p (mode, x))
  1943. return true;
  1944. split_const (x, &base, &offset);
  1945. if (mips_symbolic_constant_p (base, SYMBOL_CONTEXT_LEA, &type))
  1946. {
  1947. /* See whether we explicitly want these symbols in the pool. */
  1948. if (mips_use_pcrel_pool_p[(int) type])
  1949. return false;
  1950. /* The same optimization as for CONST_INT. */
  1951. if (SMALL_INT (offset) && mips_symbol_insns (type, MAX_MACHINE_MODE) > 0)
  1952. return true;
  1953. /* If MIPS16 constant pools live in the text section, they should
  1954. not refer to anything that might need run-time relocation. */
  1955. if (TARGET_MIPS16_PCREL_LOADS && mips_got_symbol_type_p (type))
  1956. return true;
  1957. }
  1958. /* TLS symbols must be computed by mips_legitimize_move. */
  1959. if (tls_referenced_p (x))
  1960. return true;
  1961. return false;
  1962. }
  1963. /* Implement TARGET_USE_BLOCKS_FOR_CONSTANT_P. We can't use blocks for
  1964. constants when we're using a per-function constant pool. */
  1965. static bool
  1966. mips_use_blocks_for_constant_p (machine_mode mode ATTRIBUTE_UNUSED,
  1967. const_rtx x ATTRIBUTE_UNUSED)
  1968. {
  1969. return !TARGET_MIPS16_PCREL_LOADS;
  1970. }
  1971. /* Return true if register REGNO is a valid base register for mode MODE.
  1972. STRICT_P is true if REG_OK_STRICT is in effect. */
  1973. int
  1974. mips_regno_mode_ok_for_base_p (int regno, machine_mode mode,
  1975. bool strict_p)
  1976. {
  1977. if (!HARD_REGISTER_NUM_P (regno))
  1978. {
  1979. if (!strict_p)
  1980. return true;
  1981. regno = reg_renumber[regno];
  1982. }
  1983. /* These fake registers will be eliminated to either the stack or
  1984. hard frame pointer, both of which are usually valid base registers.
  1985. Reload deals with the cases where the eliminated form isn't valid. */
  1986. if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
  1987. return true;
  1988. /* In MIPS16 mode, the stack pointer can only address word and doubleword
  1989. values, nothing smaller. */
  1990. if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM)
  1991. return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
  1992. return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno);
  1993. }
  1994. /* Return true if X is a valid base register for mode MODE.
  1995. STRICT_P is true if REG_OK_STRICT is in effect. */
  1996. static bool
  1997. mips_valid_base_register_p (rtx x, machine_mode mode, bool strict_p)
  1998. {
  1999. if (!strict_p && GET_CODE (x) == SUBREG)
  2000. x = SUBREG_REG (x);
  2001. return (REG_P (x)
  2002. && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict_p));
  2003. }
  2004. /* Return true if, for every base register BASE_REG, (plus BASE_REG X)
  2005. can address a value of mode MODE. */
  2006. static bool
  2007. mips_valid_offset_p (rtx x, machine_mode mode)
  2008. {
  2009. /* Check that X is a signed 16-bit number. */
  2010. if (!const_arith_operand (x, Pmode))
  2011. return false;
  2012. /* We may need to split multiword moves, so make sure that every word
  2013. is accessible. */
  2014. if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
  2015. && !SMALL_OPERAND (INTVAL (x) + GET_MODE_SIZE (mode) - UNITS_PER_WORD))
  2016. return false;
  2017. return true;
  2018. }
  2019. /* Return true if a LO_SUM can address a value of mode MODE when the
  2020. LO_SUM symbol has type SYMBOL_TYPE. */
  2021. static bool
  2022. mips_valid_lo_sum_p (enum mips_symbol_type symbol_type, machine_mode mode)
  2023. {
  2024. /* Check that symbols of type SYMBOL_TYPE can be used to access values
  2025. of mode MODE. */
  2026. if (mips_symbol_insns (symbol_type, mode) == 0)
  2027. return false;
  2028. /* Check that there is a known low-part relocation. */
  2029. if (mips_lo_relocs[symbol_type] == NULL)
  2030. return false;
  2031. /* We may need to split multiword moves, so make sure that each word
  2032. can be accessed without inducing a carry. This is mainly needed
  2033. for o64, which has historically only guaranteed 64-bit alignment
  2034. for 128-bit types. */
  2035. if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
  2036. && GET_MODE_BITSIZE (mode) > GET_MODE_ALIGNMENT (mode))
  2037. return false;
  2038. return true;
  2039. }
  2040. /* Return true if X is a valid address for machine mode MODE. If it is,
  2041. fill in INFO appropriately. STRICT_P is true if REG_OK_STRICT is in
  2042. effect. */
  2043. static bool
  2044. mips_classify_address (struct mips_address_info *info, rtx x,
  2045. machine_mode mode, bool strict_p)
  2046. {
  2047. switch (GET_CODE (x))
  2048. {
  2049. case REG:
  2050. case SUBREG:
  2051. info->type = ADDRESS_REG;
  2052. info->reg = x;
  2053. info->offset = const0_rtx;
  2054. return mips_valid_base_register_p (info->reg, mode, strict_p);
  2055. case PLUS:
  2056. info->type = ADDRESS_REG;
  2057. info->reg = XEXP (x, 0);
  2058. info->offset = XEXP (x, 1);
  2059. return (mips_valid_base_register_p (info->reg, mode, strict_p)
  2060. && mips_valid_offset_p (info->offset, mode));
  2061. case LO_SUM:
  2062. info->type = ADDRESS_LO_SUM;
  2063. info->reg = XEXP (x, 0);
  2064. info->offset = XEXP (x, 1);
  2065. /* We have to trust the creator of the LO_SUM to do something vaguely
  2066. sane. Target-independent code that creates a LO_SUM should also
  2067. create and verify the matching HIGH. Target-independent code that
  2068. adds an offset to a LO_SUM must prove that the offset will not
  2069. induce a carry. Failure to do either of these things would be
  2070. a bug, and we are not required to check for it here. The MIPS
  2071. backend itself should only create LO_SUMs for valid symbolic
  2072. constants, with the high part being either a HIGH or a copy
  2073. of _gp. */
  2074. info->symbol_type
  2075. = mips_classify_symbolic_expression (info->offset, SYMBOL_CONTEXT_MEM);
  2076. return (mips_valid_base_register_p (info->reg, mode, strict_p)
  2077. && mips_valid_lo_sum_p (info->symbol_type, mode));
  2078. case CONST_INT:
  2079. /* Small-integer addresses don't occur very often, but they
  2080. are legitimate if $0 is a valid base register. */
  2081. info->type = ADDRESS_CONST_INT;
  2082. return !TARGET_MIPS16 && SMALL_INT (x);
  2083. case CONST:
  2084. case LABEL_REF:
  2085. case SYMBOL_REF:
  2086. info->type = ADDRESS_SYMBOLIC;
  2087. return (mips_symbolic_constant_p (x, SYMBOL_CONTEXT_MEM,
  2088. &info->symbol_type)
  2089. && mips_symbol_insns (info->symbol_type, mode) > 0
  2090. && !mips_split_p[info->symbol_type]);
  2091. default:
  2092. return false;
  2093. }
  2094. }
  2095. /* Implement TARGET_LEGITIMATE_ADDRESS_P. */
  2096. static bool
  2097. mips_legitimate_address_p (machine_mode mode, rtx x, bool strict_p)
  2098. {
  2099. struct mips_address_info addr;
  2100. return mips_classify_address (&addr, x, mode, strict_p);
  2101. }
  2102. /* Return true if X is a legitimate $sp-based address for mode MDOE. */
  2103. bool
  2104. mips_stack_address_p (rtx x, machine_mode mode)
  2105. {
  2106. struct mips_address_info addr;
  2107. return (mips_classify_address (&addr, x, mode, false)
  2108. && addr.type == ADDRESS_REG
  2109. && addr.reg == stack_pointer_rtx);
  2110. }
  2111. /* Return true if ADDR matches the pattern for the LWXS load scaled indexed
  2112. address instruction. Note that such addresses are not considered
  2113. legitimate in the TARGET_LEGITIMATE_ADDRESS_P sense, because their use
  2114. is so restricted. */
  2115. static bool
  2116. mips_lwxs_address_p (rtx addr)
  2117. {
  2118. if (ISA_HAS_LWXS
  2119. && GET_CODE (addr) == PLUS
  2120. && REG_P (XEXP (addr, 1)))
  2121. {
  2122. rtx offset = XEXP (addr, 0);
  2123. if (GET_CODE (offset) == MULT
  2124. && REG_P (XEXP (offset, 0))
  2125. && CONST_INT_P (XEXP (offset, 1))
  2126. && INTVAL (XEXP (offset, 1)) == 4)
  2127. return true;
  2128. }
  2129. return false;
  2130. }
  2131. /* Return true if ADDR matches the pattern for the L{B,H,W,D}{,U}X load
  2132. indexed address instruction. Note that such addresses are
  2133. not considered legitimate in the TARGET_LEGITIMATE_ADDRESS_P
  2134. sense, because their use is so restricted. */
  2135. static bool
  2136. mips_lx_address_p (rtx addr, machine_mode mode)
  2137. {
  2138. if (GET_CODE (addr) != PLUS
  2139. || !REG_P (XEXP (addr, 0))
  2140. || !REG_P (XEXP (addr, 1)))
  2141. return false;
  2142. if (ISA_HAS_LBX && mode == QImode)
  2143. return true;
  2144. if (ISA_HAS_LHX && mode == HImode)
  2145. return true;
  2146. if (ISA_HAS_LWX && mode == SImode)
  2147. return true;
  2148. if (ISA_HAS_LDX && mode == DImode)
  2149. return true;
  2150. return false;
  2151. }
  2152. /* Return true if a value at OFFSET bytes from base register BASE can be
  2153. accessed using an unextended MIPS16 instruction. MODE is the mode of
  2154. the value.
  2155. Usually the offset in an unextended instruction is a 5-bit field.
  2156. The offset is unsigned and shifted left once for LH and SH, twice
  2157. for LW and SW, and so on. An exception is LWSP and SWSP, which have
  2158. an 8-bit immediate field that's shifted left twice. */
  2159. static bool
  2160. mips16_unextended_reference_p (machine_mode mode, rtx base,
  2161. unsigned HOST_WIDE_INT offset)
  2162. {
  2163. if (mode != BLKmode && offset % GET_MODE_SIZE (mode) == 0)
  2164. {
  2165. if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
  2166. return offset < 256U * GET_MODE_SIZE (mode);
  2167. return offset < 32U * GET_MODE_SIZE (mode);
  2168. }
  2169. return false;
  2170. }
  2171. /* Return the number of instructions needed to load or store a value
  2172. of mode MODE at address X, assuming that BASE_INSN_LENGTH is the
  2173. length of one instruction. Return 0 if X isn't valid for MODE.
  2174. Assume that multiword moves may need to be split into word moves
  2175. if MIGHT_SPLIT_P, otherwise assume that a single load or store is
  2176. enough. */
  2177. int
  2178. mips_address_insns (rtx x, machine_mode mode, bool might_split_p)
  2179. {
  2180. struct mips_address_info addr;
  2181. int factor;
  2182. /* BLKmode is used for single unaligned loads and stores and should
  2183. not count as a multiword mode. (GET_MODE_SIZE (BLKmode) is pretty
  2184. meaningless, so we have to single it out as a special case one way
  2185. or the other.) */
  2186. if (mode != BLKmode && might_split_p)
  2187. factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  2188. else
  2189. factor = 1;
  2190. if (mips_classify_address (&addr, x, mode, false))
  2191. switch (addr.type)
  2192. {
  2193. case ADDRESS_REG:
  2194. if (TARGET_MIPS16
  2195. && !mips16_unextended_reference_p (mode, addr.reg,
  2196. UINTVAL (addr.offset)))
  2197. return factor * 2;
  2198. return factor;
  2199. case ADDRESS_LO_SUM:
  2200. return TARGET_MIPS16 ? factor * 2 : factor;
  2201. case ADDRESS_CONST_INT:
  2202. return factor;
  2203. case ADDRESS_SYMBOLIC:
  2204. return factor * mips_symbol_insns (addr.symbol_type, mode);
  2205. }
  2206. return 0;
  2207. }
  2208. /* Return true if X fits within an unsigned field of BITS bits that is
  2209. shifted left SHIFT bits before being used. */
  2210. bool
  2211. mips_unsigned_immediate_p (unsigned HOST_WIDE_INT x, int bits, int shift = 0)
  2212. {
  2213. return (x & ((1 << shift) - 1)) == 0 && x < ((unsigned) 1 << (shift + bits));
  2214. }
  2215. /* Return true if X fits within a signed field of BITS bits that is
  2216. shifted left SHIFT bits before being used. */
  2217. bool
  2218. mips_signed_immediate_p (unsigned HOST_WIDE_INT x, int bits, int shift = 0)
  2219. {
  2220. x += 1 << (bits + shift - 1);
  2221. return mips_unsigned_immediate_p (x, bits, shift);
  2222. }
  2223. /* Return true if X is legitimate for accessing values of mode MODE,
  2224. if it is based on a MIPS16 register, and if the offset satisfies
  2225. OFFSET_PREDICATE. */
  2226. bool
  2227. m16_based_address_p (rtx x, machine_mode mode,
  2228. insn_operand_predicate_fn offset_predicate)
  2229. {
  2230. struct mips_address_info addr;
  2231. return (mips_classify_address (&addr, x, mode, false)
  2232. && addr.type == ADDRESS_REG
  2233. && M16_REG_P (REGNO (addr.reg))
  2234. && offset_predicate (addr.offset, mode));
  2235. }
  2236. /* Return true if X is a legitimate address that conforms to the requirements
  2237. for a microMIPS LWSP or SWSP insn. */
  2238. bool
  2239. lwsp_swsp_address_p (rtx x, machine_mode mode)
  2240. {
  2241. struct mips_address_info addr;
  2242. return (mips_classify_address (&addr, x, mode, false)
  2243. && addr.type == ADDRESS_REG
  2244. && REGNO (addr.reg) == STACK_POINTER_REGNUM
  2245. && uw5_operand (addr.offset, mode));
  2246. }
  2247. /* Return true if X is a legitimate address with a 12-bit offset.
  2248. MODE is the mode of the value being accessed. */
  2249. bool
  2250. umips_12bit_offset_address_p (rtx x, machine_mode mode)
  2251. {
  2252. struct mips_address_info addr;
  2253. return (mips_classify_address (&addr, x, mode, false)
  2254. && addr.type == ADDRESS_REG
  2255. && CONST_INT_P (addr.offset)
  2256. && UMIPS_12BIT_OFFSET_P (INTVAL (addr.offset)));
  2257. }
  2258. /* Return true if X is a legitimate address with a 9-bit offset.
  2259. MODE is the mode of the value being accessed. */
  2260. bool
  2261. mips_9bit_offset_address_p (rtx x, machine_mode mode)
  2262. {
  2263. struct mips_address_info addr;
  2264. return (mips_classify_address (&addr, x, mode, false)
  2265. && addr.type == ADDRESS_REG
  2266. && CONST_INT_P (addr.offset)
  2267. && MIPS_9BIT_OFFSET_P (INTVAL (addr.offset)));
  2268. }
  2269. /* Return the number of instructions needed to load constant X,
  2270. assuming that BASE_INSN_LENGTH is the length of one instruction.
  2271. Return 0 if X isn't a valid constant. */
  2272. int
  2273. mips_const_insns (rtx x)
  2274. {
  2275. struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
  2276. enum mips_symbol_type symbol_type;
  2277. rtx offset;
  2278. switch (GET_CODE (x))
  2279. {
  2280. case HIGH:
  2281. if (!mips_symbolic_constant_p (XEXP (x, 0), SYMBOL_CONTEXT_LEA,
  2282. &symbol_type)
  2283. || !mips_split_p[symbol_type])
  2284. return 0;
  2285. /* This is simply an LUI for normal mode. It is an extended
  2286. LI followed by an extended SLL for MIPS16. */
  2287. return TARGET_MIPS16 ? 4 : 1;
  2288. case CONST_INT:
  2289. if (TARGET_MIPS16)
  2290. /* Unsigned 8-bit constants can be loaded using an unextended
  2291. LI instruction. Unsigned 16-bit constants can be loaded
  2292. using an extended LI. Negative constants must be loaded
  2293. using LI and then negated. */
  2294. return (IN_RANGE (INTVAL (x), 0, 255) ? 1
  2295. : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
  2296. : IN_RANGE (-INTVAL (x), 0, 255) ? 2
  2297. : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
  2298. : 0);
  2299. return mips_build_integer (codes, INTVAL (x));
  2300. case CONST_DOUBLE:
  2301. case CONST_VECTOR:
  2302. /* Allow zeros for normal mode, where we can use $0. */
  2303. return !TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0;
  2304. case CONST:
  2305. if (CONST_GP_P (x))
  2306. return 1;
  2307. /* See if we can refer to X directly. */
  2308. if (mips_symbolic_constant_p (x, SYMBOL_CONTEXT_LEA, &symbol_type))
  2309. return mips_symbol_insns (symbol_type, MAX_MACHINE_MODE);
  2310. /* Otherwise try splitting the constant into a base and offset.
  2311. If the offset is a 16-bit value, we can load the base address
  2312. into a register and then use (D)ADDIU to add in the offset.
  2313. If the offset is larger, we can load the base and offset
  2314. into separate registers and add them together with (D)ADDU.
  2315. However, the latter is only possible before reload; during
  2316. and after reload, we must have the option of forcing the
  2317. constant into the pool instead. */
  2318. split_const (x, &x, &offset);
  2319. if (offset != 0)
  2320. {
  2321. int n = mips_const_insns (x);
  2322. if (n != 0)
  2323. {
  2324. if (SMALL_INT (offset))
  2325. return n + 1;
  2326. else if (!targetm.cannot_force_const_mem (GET_MODE (x), x))
  2327. return n + 1 + mips_build_integer (codes, INTVAL (offset));
  2328. }
  2329. }
  2330. return 0;
  2331. case SYMBOL_REF:
  2332. case LABEL_REF:
  2333. return mips_symbol_insns (mips_classify_symbol (x, SYMBOL_CONTEXT_LEA),
  2334. MAX_MACHINE_MODE);
  2335. default:
  2336. return 0;
  2337. }
  2338. }
  2339. /* X is a doubleword constant that can be handled by splitting it into
  2340. two words and loading each word separately. Return the number of
  2341. instructions required to do this, assuming that BASE_INSN_LENGTH
  2342. is the length of one instruction. */
  2343. int
  2344. mips_split_const_insns (rtx x)
  2345. {
  2346. unsigned int low, high;
  2347. low = mips_const_insns (mips_subword (x, false));
  2348. high = mips_const_insns (mips_subword (x, true));
  2349. gcc_assert (low > 0 && high > 0);
  2350. return low + high;
  2351. }
  2352. /* Return the number of instructions needed to implement INSN,
  2353. given that it loads from or stores to MEM. Assume that
  2354. BASE_INSN_LENGTH is the length of one instruction. */
  2355. int
  2356. mips_load_store_insns (rtx mem, rtx_insn *insn)
  2357. {
  2358. machine_mode mode;
  2359. bool might_split_p;
  2360. rtx set;
  2361. gcc_assert (MEM_P (mem));
  2362. mode = GET_MODE (mem);
  2363. /* Try to prove that INSN does not need to be split. */
  2364. might_split_p = GET_MODE_SIZE (mode) > UNITS_PER_WORD;
  2365. if (might_split_p)
  2366. {
  2367. set = single_set (insn);
  2368. if (set && !mips_split_move_insn_p (SET_DEST (set), SET_SRC (set), insn))
  2369. might_split_p = false;
  2370. }
  2371. return mips_address_insns (XEXP (mem, 0), mode, might_split_p);
  2372. }
  2373. /* Return the number of instructions needed for an integer division,
  2374. assuming that BASE_INSN_LENGTH is the length of one instruction. */
  2375. int
  2376. mips_idiv_insns (void)
  2377. {
  2378. int count;
  2379. count = 1;
  2380. if (TARGET_CHECK_ZERO_DIV)
  2381. {
  2382. if (GENERATE_DIVIDE_TRAPS)
  2383. count++;
  2384. else
  2385. count += 2;
  2386. }
  2387. if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
  2388. count++;
  2389. return count;
  2390. }
  2391. /* Emit a move from SRC to DEST. Assume that the move expanders can
  2392. handle all moves if !can_create_pseudo_p (). The distinction is
  2393. important because, unlike emit_move_insn, the move expanders know
  2394. how to force Pmode objects into the constant pool even when the
  2395. constant pool address is not itself legitimate. */
  2396. rtx_insn *
  2397. mips_emit_move (rtx dest, rtx src)
  2398. {
  2399. return (can_create_pseudo_p ()
  2400. ? emit_move_insn (dest, src)
  2401. : emit_move_insn_1 (dest, src));
  2402. }
  2403. /* Emit a move from SRC to DEST, splitting compound moves into individual
  2404. instructions. SPLIT_TYPE is the type of split to perform. */
  2405. static void
  2406. mips_emit_move_or_split (rtx dest, rtx src, enum mips_split_type split_type)
  2407. {
  2408. if (mips_split_move_p (dest, src, split_type))
  2409. mips_split_move (dest, src, split_type);
  2410. else
  2411. mips_emit_move (dest, src);
  2412. }
  2413. /* Emit an instruction of the form (set TARGET (CODE OP0)). */
  2414. static void
  2415. mips_emit_unary (enum rtx_code code, rtx target, rtx op0)
  2416. {
  2417. emit_insn (gen_rtx_SET (VOIDmode, target,
  2418. gen_rtx_fmt_e (code, GET_MODE (op0), op0)));
  2419. }
  2420. /* Compute (CODE OP0) and store the result in a new register of mode MODE.
  2421. Return that new register. */
  2422. static rtx
  2423. mips_force_unary (machine_mode mode, enum rtx_code code, rtx op0)
  2424. {
  2425. rtx reg;
  2426. reg = gen_reg_rtx (mode);
  2427. mips_emit_unary (code, reg, op0);
  2428. return reg;
  2429. }
  2430. /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */
  2431. void
  2432. mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1)
  2433. {
  2434. emit_insn (gen_rtx_SET (VOIDmode, target,
  2435. gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
  2436. }
  2437. /* Compute (CODE OP0 OP1) and store the result in a new register
  2438. of mode MODE. Return that new register. */
  2439. static rtx
  2440. mips_force_binary (machine_mode mode, enum rtx_code code, rtx op0, rtx op1)
  2441. {
  2442. rtx reg;
  2443. reg = gen_reg_rtx (mode);
  2444. mips_emit_binary (code, reg, op0, op1);
  2445. return reg;
  2446. }
  2447. /* Copy VALUE to a register and return that register. If new pseudos
  2448. are allowed, copy it into a new register, otherwise use DEST. */
  2449. static rtx
  2450. mips_force_temporary (rtx dest, rtx value)
  2451. {
  2452. if (can_create_pseudo_p ())
  2453. return force_reg (Pmode, value);
  2454. else
  2455. {
  2456. mips_emit_move (dest, value);
  2457. return dest;
  2458. }
  2459. }
  2460. /* Emit a call sequence with call pattern PATTERN and return the call
  2461. instruction itself (which is not necessarily the last instruction
  2462. emitted). ORIG_ADDR is the original, unlegitimized address,
  2463. ADDR is the legitimized form, and LAZY_P is true if the call
  2464. address is lazily-bound. */
  2465. static rtx_insn *
  2466. mips_emit_call_insn (rtx pattern, rtx orig_addr, rtx addr, bool lazy_p)
  2467. {
  2468. rtx_insn *insn;
  2469. rtx reg;
  2470. insn = emit_call_insn (pattern);
  2471. if (TARGET_MIPS16 && mips_use_pic_fn_addr_reg_p (orig_addr))
  2472. {
  2473. /* MIPS16 JALRs only take MIPS16 registers. If the target
  2474. function requires $25 to be valid on entry, we must copy it
  2475. there separately. The move instruction can be put in the
  2476. call's delay slot. */
  2477. reg = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
  2478. emit_insn_before (gen_move_insn (reg, addr), insn);
  2479. use_reg (&CALL_INSN_FUNCTION_USAGE (insn), reg);
  2480. }
  2481. if (lazy_p)
  2482. /* Lazy-binding stubs require $gp to be valid on entry. */
  2483. use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
  2484. if (TARGET_USE_GOT)
  2485. {
  2486. /* See the comment above load_call<mode> for details. */
  2487. use_reg (&CALL_INSN_FUNCTION_USAGE (insn),
  2488. gen_rtx_REG (Pmode, GOT_VERSION_REGNUM));
  2489. emit_insn (gen_update_got_version ());
  2490. }
  2491. if (TARGET_MIPS16
  2492. && TARGET_EXPLICIT_RELOCS
  2493. && TARGET_CALL_CLOBBERED_GP)
  2494. {
  2495. rtx post_call_tmp_reg = gen_rtx_REG (word_mode, POST_CALL_TMP_REG);
  2496. clobber_reg (&CALL_INSN_FUNCTION_USAGE (insn), post_call_tmp_reg);
  2497. }
  2498. return insn;
  2499. }
  2500. /* Wrap symbol or label BASE in an UNSPEC address of type SYMBOL_TYPE,
  2501. then add CONST_INT OFFSET to the result. */
  2502. static rtx
  2503. mips_unspec_address_offset (rtx base, rtx offset,
  2504. enum mips_symbol_type symbol_type)
  2505. {
  2506. base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base),
  2507. UNSPEC_ADDRESS_FIRST + symbol_type);
  2508. if (offset != const0_rtx)
  2509. base = gen_rtx_PLUS (Pmode, base, offset);
  2510. return gen_rtx_CONST (Pmode, base);
  2511. }
  2512. /* Return an UNSPEC address with underlying address ADDRESS and symbol
  2513. type SYMBOL_TYPE. */
  2514. rtx
  2515. mips_unspec_address (rtx address, enum mips_symbol_type symbol_type)
  2516. {
  2517. rtx base, offset;
  2518. split_const (address, &base, &offset);
  2519. return mips_unspec_address_offset (base, offset, symbol_type);
  2520. }
  2521. /* If OP is an UNSPEC address, return the address to which it refers,
  2522. otherwise return OP itself. */
  2523. rtx
  2524. mips_strip_unspec_address (rtx op)
  2525. {
  2526. rtx base, offset;
  2527. split_const (op, &base, &offset);
  2528. if (UNSPEC_ADDRESS_P (base))
  2529. op = plus_constant (Pmode, UNSPEC_ADDRESS (base), INTVAL (offset));
  2530. return op;
  2531. }
  2532. /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
  2533. high part to BASE and return the result. Just return BASE otherwise.
  2534. TEMP is as for mips_force_temporary.
  2535. The returned expression can be used as the first operand to a LO_SUM. */
  2536. static rtx
  2537. mips_unspec_offset_high (rtx temp, rtx base, rtx addr,
  2538. enum mips_symbol_type symbol_type)
  2539. {
  2540. if (mips_split_p[symbol_type])
  2541. {
  2542. addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type));
  2543. addr = mips_force_temporary (temp, addr);
  2544. base = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base));
  2545. }
  2546. return base;
  2547. }
  2548. /* Return an instruction that copies $gp into register REG. We want
  2549. GCC to treat the register's value as constant, so that its value
  2550. can be rematerialized on demand. */
  2551. static rtx
  2552. gen_load_const_gp (rtx reg)
  2553. {
  2554. return PMODE_INSN (gen_load_const_gp, (reg));
  2555. }
  2556. /* Return a pseudo register that contains the value of $gp throughout
  2557. the current function. Such registers are needed by MIPS16 functions,
  2558. for which $gp itself is not a valid base register or addition operand. */
  2559. static rtx
  2560. mips16_gp_pseudo_reg (void)
  2561. {
  2562. if (cfun->machine->mips16_gp_pseudo_rtx == NULL_RTX)
  2563. {
  2564. rtx_insn *scan;
  2565. cfun->machine->mips16_gp_pseudo_rtx = gen_reg_rtx (Pmode);
  2566. push_topmost_sequence ();
  2567. scan = get_insns ();
  2568. while (NEXT_INSN (scan) && !INSN_P (NEXT_INSN (scan)))
  2569. scan = NEXT_INSN (scan);
  2570. rtx set = gen_load_const_gp (cfun->machine->mips16_gp_pseudo_rtx);
  2571. rtx_insn *insn = emit_insn_after (set, scan);
  2572. INSN_LOCATION (insn) = 0;
  2573. pop_topmost_sequence ();
  2574. }
  2575. return cfun->machine->mips16_gp_pseudo_rtx;
  2576. }
  2577. /* Return a base register that holds pic_offset_table_rtx.
  2578. TEMP, if nonnull, is a scratch Pmode base register. */
  2579. rtx
  2580. mips_pic_base_register (rtx temp)
  2581. {
  2582. if (!TARGET_MIPS16)
  2583. return pic_offset_table_rtx;
  2584. if (currently_expanding_to_rtl)
  2585. return mips16_gp_pseudo_reg ();
  2586. if (can_create_pseudo_p ())
  2587. temp = gen_reg_rtx (Pmode);
  2588. if (TARGET_USE_GOT)
  2589. /* The first post-reload split exposes all references to $gp
  2590. (both uses and definitions). All references must remain
  2591. explicit after that point.
  2592. It is safe to introduce uses of $gp at any time, so for
  2593. simplicity, we do that before the split too. */
  2594. mips_emit_move (temp, pic_offset_table_rtx);
  2595. else
  2596. emit_insn (gen_load_const_gp (temp));
  2597. return temp;
  2598. }
  2599. /* Return the RHS of a load_call<mode> insn. */
  2600. static rtx
  2601. mips_unspec_call (rtx reg, rtx symbol)
  2602. {
  2603. rtvec vec;
  2604. vec = gen_rtvec (3, reg, symbol, gen_rtx_REG (SImode, GOT_VERSION_REGNUM));
  2605. return gen_rtx_UNSPEC (Pmode, vec, UNSPEC_LOAD_CALL);
  2606. }
  2607. /* If SRC is the RHS of a load_call<mode> insn, return the underlying symbol
  2608. reference. Return NULL_RTX otherwise. */
  2609. static rtx
  2610. mips_strip_unspec_call (rtx src)
  2611. {
  2612. if (GET_CODE (src) == UNSPEC && XINT (src, 1) == UNSPEC_LOAD_CALL)
  2613. return mips_strip_unspec_address (XVECEXP (src, 0, 1));
  2614. return NULL_RTX;
  2615. }
  2616. /* Create and return a GOT reference of type TYPE for address ADDR.
  2617. TEMP, if nonnull, is a scratch Pmode base register. */
  2618. rtx
  2619. mips_got_load (rtx temp, rtx addr, enum mips_symbol_type type)
  2620. {
  2621. rtx base, high, lo_sum_symbol;
  2622. base = mips_pic_base_register (temp);
  2623. /* If we used the temporary register to load $gp, we can't use
  2624. it for the high part as well. */
  2625. if (temp != NULL && reg_overlap_mentioned_p (base, temp))
  2626. temp = NULL;
  2627. high = mips_unspec_offset_high (temp, base, addr, type);
  2628. lo_sum_symbol = mips_unspec_address (addr, type);
  2629. if (type == SYMBOL_GOTOFF_CALL)
  2630. return mips_unspec_call (high, lo_sum_symbol);
  2631. else
  2632. return PMODE_INSN (gen_unspec_got, (high, lo_sum_symbol));
  2633. }
  2634. /* If MODE is MAX_MACHINE_MODE, ADDR appears as a move operand, otherwise
  2635. it appears in a MEM of that mode. Return true if ADDR is a legitimate
  2636. constant in that context and can be split into high and low parts.
  2637. If so, and if LOW_OUT is nonnull, emit the high part and store the
  2638. low part in *LOW_OUT. Leave *LOW_OUT unchanged otherwise.
  2639. TEMP is as for mips_force_temporary and is used to load the high
  2640. part into a register.
  2641. When MODE is MAX_MACHINE_MODE, the low part is guaranteed to be
  2642. a legitimize SET_SRC for an .md pattern, otherwise the low part
  2643. is guaranteed to be a legitimate address for mode MODE. */
  2644. bool
  2645. mips_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out)
  2646. {
  2647. enum mips_symbol_context context;
  2648. enum mips_symbol_type symbol_type;
  2649. rtx high;
  2650. context = (mode == MAX_MACHINE_MODE
  2651. ? SYMBOL_CONTEXT_LEA
  2652. : SYMBOL_CONTEXT_MEM);
  2653. if (GET_CODE (addr) == HIGH && context == SYMBOL_CONTEXT_LEA)
  2654. {
  2655. addr = XEXP (addr, 0);
  2656. if (mips_symbolic_constant_p (addr, context, &symbol_type)
  2657. && mips_symbol_insns (symbol_type, mode) > 0
  2658. && mips_split_hi_p[symbol_type])
  2659. {
  2660. if (low_out)
  2661. switch (symbol_type)
  2662. {
  2663. case SYMBOL_GOT_PAGE_OFST:
  2664. /* The high part of a page/ofst pair is loaded from the GOT. */
  2665. *low_out = mips_got_load (temp, addr, SYMBOL_GOTOFF_PAGE);
  2666. break;
  2667. default:
  2668. gcc_unreachable ();
  2669. }
  2670. return true;
  2671. }
  2672. }
  2673. else
  2674. {
  2675. if (mips_symbolic_constant_p (addr, context, &symbol_type)
  2676. && mips_symbol_insns (symbol_type, mode) > 0
  2677. && mips_split_p[symbol_type])
  2678. {
  2679. if (low_out)
  2680. switch (symbol_type)
  2681. {
  2682. case SYMBOL_GOT_DISP:
  2683. /* SYMBOL_GOT_DISP symbols are loaded from the GOT. */
  2684. *low_out = mips_got_load (temp, addr, SYMBOL_GOTOFF_DISP);
  2685. break;
  2686. case SYMBOL_GP_RELATIVE:
  2687. high = mips_pic_base_register (temp);
  2688. *low_out = gen_rtx_LO_SUM (Pmode, high, addr);
  2689. break;
  2690. default:
  2691. high = gen_rtx_HIGH (Pmode, copy_rtx (addr));
  2692. high = mips_force_temporary (temp, high);
  2693. *low_out = gen_rtx_LO_SUM (Pmode, high, addr);
  2694. break;
  2695. }
  2696. return true;
  2697. }
  2698. }
  2699. return false;
  2700. }
  2701. /* Return a legitimate address for REG + OFFSET. TEMP is as for
  2702. mips_force_temporary; it is only needed when OFFSET is not a
  2703. SMALL_OPERAND. */
  2704. static rtx
  2705. mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset)
  2706. {
  2707. if (!SMALL_OPERAND (offset))
  2708. {
  2709. rtx high;
  2710. if (TARGET_MIPS16)
  2711. {
  2712. /* Load the full offset into a register so that we can use
  2713. an unextended instruction for the address itself. */
  2714. high = GEN_INT (offset);
  2715. offset = 0;
  2716. }
  2717. else
  2718. {
  2719. /* Leave OFFSET as a 16-bit offset and put the excess in HIGH.
  2720. The addition inside the macro CONST_HIGH_PART may cause an
  2721. overflow, so we need to force a sign-extension check. */
  2722. high = gen_int_mode (CONST_HIGH_PART (offset), Pmode);
  2723. offset = CONST_LOW_PART (offset);
  2724. }
  2725. high = mips_force_temporary (temp, high);
  2726. reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg));
  2727. }
  2728. return plus_constant (Pmode, reg, offset);
  2729. }
  2730. /* The __tls_get_attr symbol. */
  2731. static GTY(()) rtx mips_tls_symbol;
  2732. /* Return an instruction sequence that calls __tls_get_addr. SYM is
  2733. the TLS symbol we are referencing and TYPE is the symbol type to use
  2734. (either global dynamic or local dynamic). V0 is an RTX for the
  2735. return value location. */
  2736. static rtx
  2737. mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0)
  2738. {
  2739. rtx insn, loc, a0;
  2740. a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST);
  2741. if (!mips_tls_symbol)
  2742. mips_tls_symbol = init_one_libfunc ("__tls_get_addr");
  2743. loc = mips_unspec_address (sym, type);
  2744. start_sequence ();
  2745. emit_insn (gen_rtx_SET (Pmode, a0,
  2746. gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, loc)));
  2747. insn = mips_expand_call (MIPS_CALL_NORMAL, v0, mips_tls_symbol,
  2748. const0_rtx, NULL_RTX, false);
  2749. RTL_CONST_CALL_P (insn) = 1;
  2750. use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
  2751. insn = get_insns ();
  2752. end_sequence ();
  2753. return insn;
  2754. }
  2755. /* Return a pseudo register that contains the current thread pointer. */
  2756. rtx
  2757. mips_expand_thread_pointer (rtx tp)
  2758. {
  2759. rtx fn;
  2760. if (TARGET_MIPS16)
  2761. {
  2762. if (!mips16_rdhwr_stub)
  2763. mips16_rdhwr_stub = new mips16_rdhwr_one_only_stub ();
  2764. fn = mips16_stub_call_address (mips16_rdhwr_stub);
  2765. emit_insn (PMODE_INSN (gen_tls_get_tp_mips16, (tp, fn)));
  2766. }
  2767. else
  2768. emit_insn (PMODE_INSN (gen_tls_get_tp, (tp)));
  2769. return tp;
  2770. }
  2771. static rtx
  2772. mips_get_tp (void)
  2773. {
  2774. return mips_expand_thread_pointer (gen_reg_rtx (Pmode));
  2775. }
  2776. /* Generate the code to access LOC, a thread-local SYMBOL_REF, and return
  2777. its address. The return value will be both a valid address and a valid
  2778. SET_SRC (either a REG or a LO_SUM). */
  2779. static rtx
  2780. mips_legitimize_tls_address (rtx loc)
  2781. {
  2782. rtx dest, insn, v0, tp, tmp1, tmp2, eqv, offset;
  2783. enum tls_model model;
  2784. model = SYMBOL_REF_TLS_MODEL (loc);
  2785. /* Only TARGET_ABICALLS code can have more than one module; other
  2786. code must be be static and should not use a GOT. All TLS models
  2787. reduce to local exec in this situation. */
  2788. if (!TARGET_ABICALLS)
  2789. model = TLS_MODEL_LOCAL_EXEC;
  2790. switch (model)
  2791. {
  2792. case TLS_MODEL_GLOBAL_DYNAMIC:
  2793. v0 = gen_rtx_REG (Pmode, GP_RETURN);
  2794. insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0);
  2795. dest = gen_reg_rtx (Pmode);
  2796. emit_libcall_block (insn, dest, v0, loc);
  2797. break;
  2798. case TLS_MODEL_LOCAL_DYNAMIC:
  2799. v0 = gen_rtx_REG (Pmode, GP_RETURN);
  2800. insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0);
  2801. tmp1 = gen_reg_rtx (Pmode);
  2802. /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
  2803. share the LDM result with other LD model accesses. */
  2804. eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
  2805. UNSPEC_TLS_LDM);
  2806. emit_libcall_block (insn, tmp1, v0, eqv);
  2807. offset = mips_unspec_address (loc, SYMBOL_DTPREL);
  2808. if (mips_split_p[SYMBOL_DTPREL])
  2809. {
  2810. tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL);
  2811. dest = gen_rtx_LO_SUM (Pmode, tmp2, offset);
  2812. }
  2813. else
  2814. dest = expand_binop (Pmode, add_optab, tmp1, offset,
  2815. 0, 0, OPTAB_DIRECT);
  2816. break;
  2817. case TLS_MODEL_INITIAL_EXEC:
  2818. tp = mips_get_tp ();
  2819. tmp1 = gen_reg_rtx (Pmode);
  2820. tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
  2821. if (Pmode == DImode)
  2822. emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2));
  2823. else
  2824. emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2));
  2825. dest = gen_reg_rtx (Pmode);
  2826. emit_insn (gen_add3_insn (dest, tmp1, tp));
  2827. break;
  2828. case TLS_MODEL_LOCAL_EXEC:
  2829. tmp1 = mips_get_tp ();
  2830. offset = mips_unspec_address (loc, SYMBOL_TPREL);
  2831. if (mips_split_p[SYMBOL_TPREL])
  2832. {
  2833. tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_TPREL);
  2834. dest = gen_rtx_LO_SUM (Pmode, tmp2, offset);
  2835. }
  2836. else
  2837. dest = expand_binop (Pmode, add_optab, tmp1, offset,
  2838. 0, 0, OPTAB_DIRECT);
  2839. break;
  2840. default:
  2841. gcc_unreachable ();
  2842. }
  2843. return dest;
  2844. }
  2845. /* Implement "TARGET = __builtin_mips_get_fcsr ()" for MIPS16,
  2846. using a stub. */
  2847. void
  2848. mips16_expand_get_fcsr (rtx target)
  2849. {
  2850. if (!mips16_get_fcsr_stub)
  2851. mips16_get_fcsr_stub = new mips16_get_fcsr_one_only_stub ();
  2852. rtx fn = mips16_stub_call_address (mips16_get_fcsr_stub);
  2853. emit_insn (PMODE_INSN (gen_mips_get_fcsr_mips16, (fn)));
  2854. emit_move_insn (target, gen_rtx_REG (SImode, GET_FCSR_REGNUM));
  2855. }
  2856. /* Implement __builtin_mips_set_fcsr (TARGET) for MIPS16, using a stub. */
  2857. void
  2858. mips16_expand_set_fcsr (rtx newval)
  2859. {
  2860. if (!mips16_set_fcsr_stub)
  2861. mips16_set_fcsr_stub = new mips16_set_fcsr_one_only_stub ();
  2862. rtx fn = mips16_stub_call_address (mips16_set_fcsr_stub);
  2863. emit_move_insn (gen_rtx_REG (SImode, SET_FCSR_REGNUM), newval);
  2864. emit_insn (PMODE_INSN (gen_mips_set_fcsr_mips16, (fn)));
  2865. }
  2866. /* If X is not a valid address for mode MODE, force it into a register. */
  2867. static rtx
  2868. mips_force_address (rtx x, machine_mode mode)
  2869. {
  2870. if (!mips_legitimate_address_p (mode, x, false))
  2871. x = force_reg (Pmode, x);
  2872. return x;
  2873. }
  2874. /* This function is used to implement LEGITIMIZE_ADDRESS. If X can
  2875. be legitimized in a way that the generic machinery might not expect,
  2876. return a new address, otherwise return NULL. MODE is the mode of
  2877. the memory being accessed. */
  2878. static rtx
  2879. mips_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
  2880. machine_mode mode)
  2881. {
  2882. rtx base, addr;
  2883. HOST_WIDE_INT offset;
  2884. if (mips_tls_symbol_p (x))
  2885. return mips_legitimize_tls_address (x);
  2886. /* See if the address can split into a high part and a LO_SUM. */
  2887. if (mips_split_symbol (NULL, x, mode, &addr))
  2888. return mips_force_address (addr, mode);
  2889. /* Handle BASE + OFFSET using mips_add_offset. */
  2890. mips_split_plus (x, &base, &offset);
  2891. if (offset != 0)
  2892. {
  2893. if (!mips_valid_base_register_p (base, mode, false))
  2894. base = copy_to_mode_reg (Pmode, base);
  2895. addr = mips_add_offset (NULL, base, offset);
  2896. return mips_force_address (addr, mode);
  2897. }
  2898. return x;
  2899. }
  2900. /* Load VALUE into DEST. TEMP is as for mips_force_temporary. */
  2901. void
  2902. mips_move_integer (rtx temp, rtx dest, unsigned HOST_WIDE_INT value)
  2903. {
  2904. struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
  2905. machine_mode mode;
  2906. unsigned int i, num_ops;
  2907. rtx x;
  2908. mode = GET_MODE (dest);
  2909. num_ops = mips_build_integer (codes, value);
  2910. /* Apply each binary operation to X. Invariant: X is a legitimate
  2911. source operand for a SET pattern. */
  2912. x = GEN_INT (codes[0].value);
  2913. for (i = 1; i < num_ops; i++)
  2914. {
  2915. if (!can_create_pseudo_p ())
  2916. {
  2917. emit_insn (gen_rtx_SET (VOIDmode, temp, x));
  2918. x = temp;
  2919. }
  2920. else
  2921. x = force_reg (mode, x);
  2922. x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
  2923. }
  2924. emit_insn (gen_rtx_SET (VOIDmode, dest, x));
  2925. }
  2926. /* Subroutine of mips_legitimize_move. Move constant SRC into register
  2927. DEST given that SRC satisfies immediate_operand but doesn't satisfy
  2928. move_operand. */
  2929. static void
  2930. mips_legitimize_const_move (machine_mode mode, rtx dest, rtx src)
  2931. {
  2932. rtx base, offset;
  2933. /* Split moves of big integers into smaller pieces. */
  2934. if (splittable_const_int_operand (src, mode))
  2935. {
  2936. mips_move_integer (dest, dest, INTVAL (src));
  2937. return;
  2938. }
  2939. /* Split moves of symbolic constants into high/low pairs. */
  2940. if (mips_split_symbol (dest, src, MAX_MACHINE_MODE, &src))
  2941. {
  2942. emit_insn (gen_rtx_SET (VOIDmode, dest, src));
  2943. return;
  2944. }
  2945. /* Generate the appropriate access sequences for TLS symbols. */
  2946. if (mips_tls_symbol_p (src))
  2947. {
  2948. mips_emit_move (dest, mips_legitimize_tls_address (src));
  2949. return;
  2950. }
  2951. /* If we have (const (plus symbol offset)), and that expression cannot
  2952. be forced into memory, load the symbol first and add in the offset.
  2953. In non-MIPS16 mode, prefer to do this even if the constant _can_ be
  2954. forced into memory, as it usually produces better code. */
  2955. split_const (src, &base, &offset);
  2956. if (offset != const0_rtx
  2957. && (targetm.cannot_force_const_mem (mode, src)
  2958. || (!TARGET_MIPS16 && can_create_pseudo_p ())))
  2959. {
  2960. base = mips_force_temporary (dest, base);
  2961. mips_emit_move (dest, mips_add_offset (NULL, base, INTVAL (offset)));
  2962. return;
  2963. }
  2964. src = force_const_mem (mode, src);
  2965. /* When using explicit relocs, constant pool references are sometimes
  2966. not legitimate addresses. */
  2967. mips_split_symbol (dest, XEXP (src, 0), mode, &XEXP (src, 0));
  2968. mips_emit_move (dest, src);
  2969. }
  2970. /* If (set DEST SRC) is not a valid move instruction, emit an equivalent
  2971. sequence that is valid. */
  2972. bool
  2973. mips_legitimize_move (machine_mode mode, rtx dest, rtx src)
  2974. {
  2975. if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
  2976. {
  2977. mips_emit_move (dest, force_reg (mode, src));
  2978. return true;
  2979. }
  2980. /* We need to deal with constants that would be legitimate
  2981. immediate_operands but aren't legitimate move_operands. */
  2982. if (CONSTANT_P (src) && !move_operand (src, mode))
  2983. {
  2984. mips_legitimize_const_move (mode, dest, src);
  2985. set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
  2986. return true;
  2987. }
  2988. return false;
  2989. }
  2990. /* Return true if value X in context CONTEXT is a small-data address
  2991. that can be rewritten as a LO_SUM. */
  2992. static bool
  2993. mips_rewrite_small_data_p (rtx x, enum mips_symbol_context context)
  2994. {
  2995. enum mips_symbol_type symbol_type;
  2996. return (mips_lo_relocs[SYMBOL_GP_RELATIVE]
  2997. && !mips_split_p[SYMBOL_GP_RELATIVE]
  2998. && mips_symbolic_constant_p (x, context, &symbol_type)
  2999. && symbol_type == SYMBOL_GP_RELATIVE);
  3000. }
  3001. /* Return true if OP refers to small data symbols directly, not through
  3002. a LO_SUM. CONTEXT is the context in which X appears. */
  3003. static int
  3004. mips_small_data_pattern_1 (rtx x, enum mips_symbol_context context)
  3005. {
  3006. subrtx_var_iterator::array_type array;
  3007. FOR_EACH_SUBRTX_VAR (iter, array, x, ALL)
  3008. {
  3009. rtx x = *iter;
  3010. /* Ignore things like "g" constraints in asms. We make no particular
  3011. guarantee about which symbolic constants are acceptable as asm operands
  3012. versus which must be forced into a GPR. */
  3013. if (GET_CODE (x) == LO_SUM || GET_CODE (x) == ASM_OPERANDS)
  3014. iter.skip_subrtxes ();
  3015. else if (MEM_P (x))
  3016. {
  3017. if (mips_small_data_pattern_1 (XEXP (x, 0), SYMBOL_CONTEXT_MEM))
  3018. return true;
  3019. iter.skip_subrtxes ();
  3020. }
  3021. else if (mips_rewrite_small_data_p (x, context))
  3022. return true;
  3023. }
  3024. return false;
  3025. }
  3026. /* Return true if OP refers to small data symbols directly, not through
  3027. a LO_SUM. */
  3028. bool
  3029. mips_small_data_pattern_p (rtx op)
  3030. {
  3031. return mips_small_data_pattern_1 (op, SYMBOL_CONTEXT_LEA);
  3032. }
  3033. /* Rewrite *LOC so that it refers to small data using explicit
  3034. relocations. CONTEXT is the context in which *LOC appears. */
  3035. static void
  3036. mips_rewrite_small_data_1 (rtx *loc, enum mips_symbol_context context)
  3037. {
  3038. subrtx_ptr_iterator::array_type array;
  3039. FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL)
  3040. {
  3041. rtx *loc = *iter;
  3042. if (MEM_P (*loc))
  3043. {
  3044. mips_rewrite_small_data_1 (&XEXP (*loc, 0), SYMBOL_CONTEXT_MEM);
  3045. iter.skip_subrtxes ();
  3046. }
  3047. else if (mips_rewrite_small_data_p (*loc, context))
  3048. {
  3049. *loc = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, *loc);
  3050. iter.skip_subrtxes ();
  3051. }
  3052. else if (GET_CODE (*loc) == LO_SUM)
  3053. iter.skip_subrtxes ();
  3054. }
  3055. }
  3056. /* Rewrite instruction pattern PATTERN so that it refers to small data
  3057. using explicit relocations. */
  3058. rtx
  3059. mips_rewrite_small_data (rtx pattern)
  3060. {
  3061. pattern = copy_insn (pattern);
  3062. mips_rewrite_small_data_1 (&pattern, SYMBOL_CONTEXT_LEA);
  3063. return pattern;
  3064. }
  3065. /* The cost of loading values from the constant pool. It should be
  3066. larger than the cost of any constant we want to synthesize inline. */
  3067. #define CONSTANT_POOL_COST COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 8)
  3068. /* Return the cost of X when used as an operand to the MIPS16 instruction
  3069. that implements CODE. Return -1 if there is no such instruction, or if
  3070. X is not a valid immediate operand for it. */
  3071. static int
  3072. mips16_constant_cost (int code, HOST_WIDE_INT x)
  3073. {
  3074. switch (code)
  3075. {
  3076. case ASHIFT:
  3077. case ASHIFTRT:
  3078. case LSHIFTRT:
  3079. /* Shifts by between 1 and 8 bits (inclusive) are unextended,
  3080. other shifts are extended. The shift patterns truncate the shift
  3081. count to the right size, so there are no out-of-range values. */
  3082. if (IN_RANGE (x, 1, 8))
  3083. return 0;
  3084. return COSTS_N_INSNS (1);
  3085. case PLUS:
  3086. if (IN_RANGE (x, -128, 127))
  3087. return 0;
  3088. if (SMALL_OPERAND (x))
  3089. return COSTS_N_INSNS (1);
  3090. return -1;
  3091. case LEU:
  3092. /* Like LE, but reject the always-true case. */
  3093. if (x == -1)
  3094. return -1;
  3095. case LE:
  3096. /* We add 1 to the immediate and use SLT. */
  3097. x += 1;
  3098. case XOR:
  3099. /* We can use CMPI for an xor with an unsigned 16-bit X. */
  3100. case LT:
  3101. case LTU:
  3102. if (IN_RANGE (x, 0, 255))
  3103. return 0;
  3104. if (SMALL_OPERAND_UNSIGNED (x))
  3105. return COSTS_N_INSNS (1);
  3106. return -1;
  3107. case EQ:
  3108. case NE:
  3109. /* Equality comparisons with 0 are cheap. */
  3110. if (x == 0)
  3111. return 0;
  3112. return -1;
  3113. default:
  3114. return -1;
  3115. }
  3116. }
  3117. /* Return true if there is a non-MIPS16 instruction that implements CODE
  3118. and if that instruction accepts X as an immediate operand. */
  3119. static int
  3120. mips_immediate_operand_p (int code, HOST_WIDE_INT x)
  3121. {
  3122. switch (code)
  3123. {
  3124. case ASHIFT:
  3125. case ASHIFTRT:
  3126. case LSHIFTRT:
  3127. /* All shift counts are truncated to a valid constant. */
  3128. return true;
  3129. case ROTATE:
  3130. case ROTATERT:
  3131. /* Likewise rotates, if the target supports rotates at all. */
  3132. return ISA_HAS_ROR;
  3133. case AND:
  3134. case IOR:
  3135. case XOR:
  3136. /* These instructions take 16-bit unsigned immediates. */
  3137. return SMALL_OPERAND_UNSIGNED (x);
  3138. case PLUS:
  3139. case LT:
  3140. case LTU:
  3141. /* These instructions take 16-bit signed immediates. */
  3142. return SMALL_OPERAND (x);
  3143. case EQ:
  3144. case NE:
  3145. case GT:
  3146. case GTU:
  3147. /* The "immediate" forms of these instructions are really
  3148. implemented as comparisons with register 0. */
  3149. return x == 0;
  3150. case GE:
  3151. case GEU:
  3152. /* Likewise, meaning that the only valid immediate operand is 1. */
  3153. return x == 1;
  3154. case LE:
  3155. /* We add 1 to the immediate and use SLT. */
  3156. return SMALL_OPERAND (x + 1);
  3157. case LEU:
  3158. /* Likewise SLTU, but reject the always-true case. */
  3159. return SMALL_OPERAND (x + 1) && x + 1 != 0;
  3160. case SIGN_EXTRACT:
  3161. case ZERO_EXTRACT:
  3162. /* The bit position and size are immediate operands. */
  3163. return ISA_HAS_EXT_INS;
  3164. default:
  3165. /* By default assume that $0 can be used for 0. */
  3166. return x == 0;
  3167. }
  3168. }
  3169. /* Return the cost of binary operation X, given that the instruction
  3170. sequence for a word-sized or smaller operation has cost SINGLE_COST
  3171. and that the sequence of a double-word operation has cost DOUBLE_COST.
  3172. If SPEED is true, optimize for speed otherwise optimize for size. */
  3173. static int
  3174. mips_binary_cost (rtx x, int single_cost, int double_cost, bool speed)
  3175. {
  3176. int cost;
  3177. if (GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD * 2)
  3178. cost = double_cost;
  3179. else
  3180. cost = single_cost;
  3181. return (cost
  3182. + set_src_cost (XEXP (x, 0), speed)
  3183. + rtx_cost (XEXP (x, 1), GET_CODE (x), 1, speed));
  3184. }
  3185. /* Return the cost of floating-point multiplications of mode MODE. */
  3186. static int
  3187. mips_fp_mult_cost (machine_mode mode)
  3188. {
  3189. return mode == DFmode ? mips_cost->fp_mult_df : mips_cost->fp_mult_sf;
  3190. }
  3191. /* Return the cost of floating-point divisions of mode MODE. */
  3192. static int
  3193. mips_fp_div_cost (machine_mode mode)
  3194. {
  3195. return mode == DFmode ? mips_cost->fp_div_df : mips_cost->fp_div_sf;
  3196. }
  3197. /* Return the cost of sign-extending OP to mode MODE, not including the
  3198. cost of OP itself. */
  3199. static int
  3200. mips_sign_extend_cost (machine_mode mode, rtx op)
  3201. {
  3202. if (MEM_P (op))
  3203. /* Extended loads are as cheap as unextended ones. */
  3204. return 0;
  3205. if (TARGET_64BIT && mode == DImode && GET_MODE (op) == SImode)
  3206. /* A sign extension from SImode to DImode in 64-bit mode is free. */
  3207. return 0;
  3208. if (ISA_HAS_SEB_SEH || GENERATE_MIPS16E)
  3209. /* We can use SEB or SEH. */
  3210. return COSTS_N_INSNS (1);
  3211. /* We need to use a shift left and a shift right. */
  3212. return COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 2);
  3213. }
  3214. /* Return the cost of zero-extending OP to mode MODE, not including the
  3215. cost of OP itself. */
  3216. static int
  3217. mips_zero_extend_cost (machine_mode mode, rtx op)
  3218. {
  3219. if (MEM_P (op))
  3220. /* Extended loads are as cheap as unextended ones. */
  3221. return 0;
  3222. if (TARGET_64BIT && mode == DImode && GET_MODE (op) == SImode)
  3223. /* We need a shift left by 32 bits and a shift right by 32 bits. */
  3224. return COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 2);
  3225. if (GENERATE_MIPS16E)
  3226. /* We can use ZEB or ZEH. */
  3227. return COSTS_N_INSNS (1);
  3228. if (TARGET_MIPS16)
  3229. /* We need to load 0xff or 0xffff into a register and use AND. */
  3230. return COSTS_N_INSNS (GET_MODE (op) == QImode ? 2 : 3);
  3231. /* We can use ANDI. */
  3232. return COSTS_N_INSNS (1);
  3233. }
  3234. /* Return the cost of moving between two registers of mode MODE,
  3235. assuming that the move will be in pieces of at most UNITS bytes. */
  3236. static int
  3237. mips_set_reg_reg_piece_cost (machine_mode mode, unsigned int units)
  3238. {
  3239. return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units);
  3240. }
  3241. /* Return the cost of moving between two registers of mode MODE. */
  3242. static int
  3243. mips_set_reg_reg_cost (machine_mode mode)
  3244. {
  3245. switch (GET_MODE_CLASS (mode))
  3246. {
  3247. case MODE_CC:
  3248. return mips_set_reg_reg_piece_cost (mode, GET_MODE_SIZE (CCmode));
  3249. case MODE_FLOAT:
  3250. case MODE_COMPLEX_FLOAT:
  3251. case MODE_VECTOR_FLOAT:
  3252. if (TARGET_HARD_FLOAT)
  3253. return mips_set_reg_reg_piece_cost (mode, UNITS_PER_HWFPVALUE);
  3254. /* Fall through */
  3255. default:
  3256. return mips_set_reg_reg_piece_cost (mode, UNITS_PER_WORD);
  3257. }
  3258. }
  3259. /* Implement TARGET_RTX_COSTS. */
  3260. static bool
  3261. mips_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED,
  3262. int *total, bool speed)
  3263. {
  3264. machine_mode mode = GET_MODE (x);
  3265. bool float_mode_p = FLOAT_MODE_P (mode);
  3266. int cost;
  3267. rtx addr;
  3268. /* The cost of a COMPARE is hard to define for MIPS. COMPAREs don't
  3269. appear in the instruction stream, and the cost of a comparison is
  3270. really the cost of the branch or scc condition. At the time of
  3271. writing, GCC only uses an explicit outer COMPARE code when optabs
  3272. is testing whether a constant is expensive enough to force into a
  3273. register. We want optabs to pass such constants through the MIPS
  3274. expanders instead, so make all constants very cheap here. */
  3275. if (outer_code == COMPARE)
  3276. {
  3277. gcc_assert (CONSTANT_P (x));
  3278. *total = 0;
  3279. return true;
  3280. }
  3281. switch (code)
  3282. {
  3283. case CONST_INT:
  3284. /* Treat *clear_upper32-style ANDs as having zero cost in the
  3285. second operand. The cost is entirely in the first operand.
  3286. ??? This is needed because we would otherwise try to CSE
  3287. the constant operand. Although that's the right thing for
  3288. instructions that continue to be a register operation throughout
  3289. compilation, it is disastrous for instructions that could
  3290. later be converted into a memory operation. */
  3291. if (TARGET_64BIT
  3292. && outer_code == AND
  3293. && UINTVAL (x) == 0xffffffff)
  3294. {
  3295. *total = 0;
  3296. return true;
  3297. }
  3298. if (TARGET_MIPS16)
  3299. {
  3300. cost = mips16_constant_cost (outer_code, INTVAL (x));
  3301. if (cost >= 0)
  3302. {
  3303. *total = cost;
  3304. return true;
  3305. }
  3306. }
  3307. else
  3308. {
  3309. /* When not optimizing for size, we care more about the cost
  3310. of hot code, and hot code is often in a loop. If a constant
  3311. operand needs to be forced into a register, we will often be
  3312. able to hoist the constant load out of the loop, so the load
  3313. should not contribute to the cost. */
  3314. if (speed || mips_immediate_operand_p (outer_code, INTVAL (x)))
  3315. {
  3316. *total = 0;
  3317. return true;
  3318. }
  3319. }
  3320. /* Fall through. */
  3321. case CONST:
  3322. case SYMBOL_REF:
  3323. case LABEL_REF:
  3324. case CONST_DOUBLE:
  3325. if (force_to_mem_operand (x, VOIDmode))
  3326. {
  3327. *total = COSTS_N_INSNS (1);
  3328. return true;
  3329. }
  3330. cost = mips_const_insns (x);
  3331. if (cost > 0)
  3332. {
  3333. /* If the constant is likely to be stored in a GPR, SETs of
  3334. single-insn constants are as cheap as register sets; we
  3335. never want to CSE them.
  3336. Don't reduce the cost of storing a floating-point zero in
  3337. FPRs. If we have a zero in an FPR for other reasons, we
  3338. can get better cfg-cleanup and delayed-branch results by
  3339. using it consistently, rather than using $0 sometimes and
  3340. an FPR at other times. Also, moves between floating-point
  3341. registers are sometimes cheaper than (D)MTC1 $0. */
  3342. if (cost == 1
  3343. && outer_code == SET
  3344. && !(float_mode_p && TARGET_HARD_FLOAT))
  3345. cost = 0;
  3346. /* When non-MIPS16 code loads a constant N>1 times, we rarely
  3347. want to CSE the constant itself. It is usually better to
  3348. have N copies of the last operation in the sequence and one
  3349. shared copy of the other operations. (Note that this is
  3350. not true for MIPS16 code, where the final operation in the
  3351. sequence is often an extended instruction.)
  3352. Also, if we have a CONST_INT, we don't know whether it is
  3353. for a word or doubleword operation, so we cannot rely on
  3354. the result of mips_build_integer. */
  3355. else if (!TARGET_MIPS16
  3356. && (outer_code == SET || mode == VOIDmode))
  3357. cost = 1;
  3358. *total = COSTS_N_INSNS (cost);
  3359. return true;
  3360. }
  3361. /* The value will need to be fetched from the constant pool. */
  3362. *total = CONSTANT_POOL_COST;
  3363. return true;
  3364. case MEM:
  3365. /* If the address is legitimate, return the number of
  3366. instructions it needs. */
  3367. addr = XEXP (x, 0);
  3368. cost = mips_address_insns (addr, mode, true);
  3369. if (cost > 0)
  3370. {
  3371. *total = COSTS_N_INSNS (cost + 1);
  3372. return true;
  3373. }
  3374. /* Check for a scaled indexed address. */
  3375. if (mips_lwxs_address_p (addr)
  3376. || mips_lx_address_p (addr, mode))
  3377. {
  3378. *total = COSTS_N_INSNS (2);
  3379. return true;
  3380. }
  3381. /* Otherwise use the default handling. */
  3382. return false;
  3383. case FFS:
  3384. *total = COSTS_N_INSNS (6);
  3385. return false;
  3386. case NOT:
  3387. *total = COSTS_N_INSNS (GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1);
  3388. return false;
  3389. case AND:
  3390. /* Check for a *clear_upper32 pattern and treat it like a zero
  3391. extension. See the pattern's comment for details. */
  3392. if (TARGET_64BIT
  3393. && mode == DImode
  3394. && CONST_INT_P (XEXP (x, 1))
  3395. && UINTVAL (XEXP (x, 1)) == 0xffffffff)
  3396. {
  3397. *total = (mips_zero_extend_cost (mode, XEXP (x, 0))
  3398. + set_src_cost (XEXP (x, 0), speed));
  3399. return true;
  3400. }
  3401. if (ISA_HAS_CINS && CONST_INT_P (XEXP (x, 1)))
  3402. {
  3403. rtx op = XEXP (x, 0);
  3404. if (GET_CODE (op) == ASHIFT
  3405. && CONST_INT_P (XEXP (op, 1))
  3406. && mask_low_and_shift_p (mode, XEXP (x, 1), XEXP (op, 1), 32))
  3407. {
  3408. *total = COSTS_N_INSNS (1) + set_src_cost (XEXP (op, 0), speed);
  3409. return true;
  3410. }
  3411. }
  3412. /* (AND (NOT op0) (NOT op1) is a nor operation that can be done in
  3413. a single instruction. */
  3414. if (!TARGET_MIPS16
  3415. && GET_CODE (XEXP (x, 0)) == NOT
  3416. && GET_CODE (XEXP (x, 1)) == NOT)
  3417. {
  3418. cost = GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1;
  3419. *total = (COSTS_N_INSNS (cost)
  3420. + set_src_cost (XEXP (XEXP (x, 0), 0), speed)
  3421. + set_src_cost (XEXP (XEXP (x, 1), 0), speed));
  3422. return true;
  3423. }
  3424. /* Fall through. */
  3425. case IOR:
  3426. case XOR:
  3427. /* Double-word operations use two single-word operations. */
  3428. *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (2),
  3429. speed);
  3430. return true;
  3431. case ASHIFT:
  3432. case ASHIFTRT:
  3433. case LSHIFTRT:
  3434. case ROTATE:
  3435. case ROTATERT:
  3436. if (CONSTANT_P (XEXP (x, 1)))
  3437. *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (4),
  3438. speed);
  3439. else
  3440. *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (12),
  3441. speed);
  3442. return true;
  3443. case ABS:
  3444. if (float_mode_p)
  3445. *total = mips_cost->fp_add;
  3446. else
  3447. *total = COSTS_N_INSNS (4);
  3448. return false;
  3449. case LO_SUM:
  3450. /* Low-part immediates need an extended MIPS16 instruction. */
  3451. *total = (COSTS_N_INSNS (TARGET_MIPS16 ? 2 : 1)
  3452. + set_src_cost (XEXP (x, 0), speed));
  3453. return true;
  3454. case LT:
  3455. case LTU:
  3456. case LE:
  3457. case LEU:
  3458. case GT:
  3459. case GTU:
  3460. case GE:
  3461. case GEU:
  3462. case EQ:
  3463. case NE:
  3464. case UNORDERED:
  3465. case LTGT:
  3466. /* Branch comparisons have VOIDmode, so use the first operand's
  3467. mode instead. */
  3468. mode = GET_MODE (XEXP (x, 0));
  3469. if (FLOAT_MODE_P (mode))
  3470. {
  3471. *total = mips_cost->fp_add;
  3472. return false;
  3473. }
  3474. *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (4),
  3475. speed);
  3476. return true;
  3477. case MINUS:
  3478. if (float_mode_p
  3479. && (ISA_HAS_NMADD4_NMSUB4 || ISA_HAS_NMADD3_NMSUB3)
  3480. && TARGET_FUSED_MADD
  3481. && !HONOR_NANS (mode)
  3482. && !HONOR_SIGNED_ZEROS (mode))
  3483. {
  3484. /* See if we can use NMADD or NMSUB. See mips.md for the
  3485. associated patterns. */
  3486. rtx op0 = XEXP (x, 0);
  3487. rtx op1 = XEXP (x, 1);
  3488. if (GET_CODE (op0) == MULT && GET_CODE (XEXP (op0, 0)) == NEG)
  3489. {
  3490. *total = (mips_fp_mult_cost (mode)
  3491. + set_src_cost (XEXP (XEXP (op0, 0), 0), speed)
  3492. + set_src_cost (XEXP (op0, 1), speed)
  3493. + set_src_cost (op1, speed));
  3494. return true;
  3495. }
  3496. if (GET_CODE (op1) == MULT)
  3497. {
  3498. *total = (mips_fp_mult_cost (mode)
  3499. + set_src_cost (op0, speed)
  3500. + set_src_cost (XEXP (op1, 0), speed)
  3501. + set_src_cost (XEXP (op1, 1), speed));
  3502. return true;
  3503. }
  3504. }
  3505. /* Fall through. */
  3506. case PLUS:
  3507. if (float_mode_p)
  3508. {
  3509. /* If this is part of a MADD or MSUB, treat the PLUS as
  3510. being free. */
  3511. if ((ISA_HAS_FP_MADD4_MSUB4 || ISA_HAS_FP_MADD3_MSUB3)
  3512. && TARGET_FUSED_MADD
  3513. && GET_CODE (XEXP (x, 0)) == MULT)
  3514. *total = 0;
  3515. else
  3516. *total = mips_cost->fp_add;
  3517. return false;
  3518. }
  3519. /* If it's an add + mult (which is equivalent to shift left) and
  3520. it's immediate operand satisfies const_immlsa_operand predicate. */
  3521. if (((ISA_HAS_LSA && mode == SImode)
  3522. || (ISA_HAS_DLSA && mode == DImode))
  3523. && GET_CODE (XEXP (x, 0)) == MULT)
  3524. {
  3525. rtx op2 = XEXP (XEXP (x, 0), 1);
  3526. if (const_immlsa_operand (op2, mode))
  3527. {
  3528. *total = (COSTS_N_INSNS (1)
  3529. + set_src_cost (XEXP (XEXP (x, 0), 0), speed)
  3530. + set_src_cost (XEXP (x, 1), speed));
  3531. return true;
  3532. }
  3533. }
  3534. /* Double-word operations require three single-word operations and
  3535. an SLTU. The MIPS16 version then needs to move the result of
  3536. the SLTU from $24 to a MIPS16 register. */
  3537. *total = mips_binary_cost (x, COSTS_N_INSNS (1),
  3538. COSTS_N_INSNS (TARGET_MIPS16 ? 5 : 4),
  3539. speed);
  3540. return true;
  3541. case NEG:
  3542. if (float_mode_p
  3543. && (ISA_HAS_NMADD4_NMSUB4 || ISA_HAS_NMADD3_NMSUB3)
  3544. && TARGET_FUSED_MADD
  3545. && !HONOR_NANS (mode)
  3546. && HONOR_SIGNED_ZEROS (mode))
  3547. {
  3548. /* See if we can use NMADD or NMSUB. See mips.md for the
  3549. associated patterns. */
  3550. rtx op = XEXP (x, 0);
  3551. if ((GET_CODE (op) == PLUS || GET_CODE (op) == MINUS)
  3552. && GET_CODE (XEXP (op, 0)) == MULT)
  3553. {
  3554. *total = (mips_fp_mult_cost (mode)
  3555. + set_src_cost (XEXP (XEXP (op, 0), 0), speed)
  3556. + set_src_cost (XEXP (XEXP (op, 0), 1), speed)
  3557. + set_src_cost (XEXP (op, 1), speed));
  3558. return true;
  3559. }
  3560. }
  3561. if (float_mode_p)
  3562. *total = mips_cost->fp_add;
  3563. else
  3564. *total = COSTS_N_INSNS (GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 4 : 1);
  3565. return false;
  3566. case FMA:
  3567. if (ISA_HAS_FP_MADDF_MSUBF)
  3568. *total = mips_fp_mult_cost (mode);
  3569. return false;
  3570. case MULT:
  3571. if (float_mode_p)
  3572. *total = mips_fp_mult_cost (mode);
  3573. else if (mode == DImode && !TARGET_64BIT)
  3574. /* Synthesized from 2 mulsi3s, 1 mulsidi3 and two additions,
  3575. where the mulsidi3 always includes an MFHI and an MFLO. */
  3576. *total = (speed
  3577. ? mips_cost->int_mult_si * 3 + 6
  3578. : COSTS_N_INSNS (ISA_HAS_MUL3 ? 7 : 9));
  3579. else if (!speed)
  3580. *total = COSTS_N_INSNS ((ISA_HAS_MUL3 || ISA_HAS_R6MUL) ? 1 : 2) + 1;
  3581. else if (mode == DImode)
  3582. *total = mips_cost->int_mult_di;
  3583. else
  3584. *total = mips_cost->int_mult_si;
  3585. return false;
  3586. case DIV:
  3587. /* Check for a reciprocal. */
  3588. if (float_mode_p
  3589. && ISA_HAS_FP_RECIP_RSQRT (mode)
  3590. && flag_unsafe_math_optimizations
  3591. && XEXP (x, 0) == CONST1_RTX (mode))
  3592. {
  3593. if (outer_code == SQRT || GET_CODE (XEXP (x, 1)) == SQRT)
  3594. /* An rsqrt<mode>a or rsqrt<mode>b pattern. Count the
  3595. division as being free. */
  3596. *total = set_src_cost (XEXP (x, 1), speed);
  3597. else
  3598. *total = (mips_fp_div_cost (mode)
  3599. + set_src_cost (XEXP (x, 1), speed));
  3600. return true;
  3601. }
  3602. /* Fall through. */
  3603. case SQRT:
  3604. case MOD:
  3605. if (float_mode_p)
  3606. {
  3607. *total = mips_fp_div_cost (mode);
  3608. return false;
  3609. }
  3610. /* Fall through. */
  3611. case UDIV:
  3612. case UMOD:
  3613. if (!speed)
  3614. {
  3615. /* It is our responsibility to make division by a power of 2
  3616. as cheap as 2 register additions if we want the division
  3617. expanders to be used for such operations; see the setting
  3618. of sdiv_pow2_cheap in optabs.c. Using (D)DIV for MIPS16
  3619. should always produce shorter code than using
  3620. expand_sdiv2_pow2. */
  3621. if (TARGET_MIPS16
  3622. && CONST_INT_P (XEXP (x, 1))
  3623. && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
  3624. {
  3625. *total = COSTS_N_INSNS (2) + set_src_cost (XEXP (x, 0), speed);
  3626. return true;
  3627. }
  3628. *total = COSTS_N_INSNS (mips_idiv_insns ());
  3629. }
  3630. else if (mode == DImode)
  3631. *total = mips_cost->int_div_di;
  3632. else
  3633. *total = mips_cost->int_div_si;
  3634. return false;
  3635. case SIGN_EXTEND:
  3636. *total = mips_sign_extend_cost (mode, XEXP (x, 0));
  3637. return false;
  3638. case ZERO_EXTEND:
  3639. if (outer_code == SET
  3640. && ISA_HAS_BADDU
  3641. && (GET_CODE (XEXP (x, 0)) == TRUNCATE
  3642. || GET_CODE (XEXP (x, 0)) == SUBREG)
  3643. && GET_MODE (XEXP (x, 0)) == QImode
  3644. && GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS)
  3645. {
  3646. *total = set_src_cost (XEXP (XEXP (x, 0), 0), speed);
  3647. return true;
  3648. }
  3649. *total = mips_zero_extend_cost (mode, XEXP (x, 0));
  3650. return false;
  3651. case TRUNCATE:
  3652. /* Costings for highpart multiplies. Matching patterns of the form:
  3653. (lshiftrt:DI (mult:DI (sign_extend:DI (...)
  3654. (sign_extend:DI (...))
  3655. (const_int 32)
  3656. */
  3657. if (ISA_HAS_R6MUL
  3658. && (GET_CODE (XEXP (x, 0)) == ASHIFTRT
  3659. || GET_CODE (XEXP (x, 0)) == LSHIFTRT)
  3660. && CONST_INT_P (XEXP (XEXP (x, 0), 1))
  3661. && ((INTVAL (XEXP (XEXP (x, 0), 1)) == 32
  3662. && GET_MODE (XEXP (x, 0)) == DImode)
  3663. || (ISA_HAS_R6DMUL
  3664. && INTVAL (XEXP (XEXP (x, 0), 1)) == 64
  3665. && GET_MODE (XEXP (x, 0)) == TImode))
  3666. && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
  3667. && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND
  3668. && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == SIGN_EXTEND)
  3669. || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND
  3670. && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1))
  3671. == ZERO_EXTEND))))
  3672. {
  3673. if (!speed)
  3674. *total = COSTS_N_INSNS (1) + 1;
  3675. else if (mode == DImode)
  3676. *total = mips_cost->int_mult_di;
  3677. else
  3678. *total = mips_cost->int_mult_si;
  3679. /* Sign extension is free, zero extension costs for DImode when
  3680. on a 64bit core / when DMUL is present. */
  3681. for (int i = 0; i < 2; ++i)
  3682. {
  3683. rtx op = XEXP (XEXP (XEXP (x, 0), 0), i);
  3684. if (ISA_HAS_R6DMUL
  3685. && GET_CODE (op) == ZERO_EXTEND
  3686. && GET_MODE (op) == DImode)
  3687. *total += rtx_cost (op, MULT, i, speed);
  3688. else
  3689. *total += rtx_cost (XEXP (op, 0), GET_CODE (op), 0, speed);
  3690. }
  3691. return true;
  3692. }
  3693. return false;
  3694. case FLOAT:
  3695. case UNSIGNED_FLOAT:
  3696. case FIX:
  3697. case FLOAT_EXTEND:
  3698. case FLOAT_TRUNCATE:
  3699. *total = mips_cost->fp_add;
  3700. return false;
  3701. case SET:
  3702. if (register_operand (SET_DEST (x), VOIDmode)
  3703. && reg_or_0_operand (SET_SRC (x), VOIDmode))
  3704. {
  3705. *total = mips_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
  3706. return true;
  3707. }
  3708. return false;
  3709. default:
  3710. return false;
  3711. }
  3712. }
  3713. /* Implement TARGET_ADDRESS_COST. */
  3714. static int
  3715. mips_address_cost (rtx addr, machine_mode mode,
  3716. addr_space_t as ATTRIBUTE_UNUSED,
  3717. bool speed ATTRIBUTE_UNUSED)
  3718. {
  3719. return mips_address_insns (addr, mode, false);
  3720. }
  3721. /* Information about a single instruction in a multi-instruction
  3722. asm sequence. */
  3723. struct mips_multi_member {
  3724. /* True if this is a label, false if it is code. */
  3725. bool is_label_p;
  3726. /* The output_asm_insn format of the instruction. */
  3727. const char *format;
  3728. /* The operands to the instruction. */
  3729. rtx operands[MAX_RECOG_OPERANDS];
  3730. };
  3731. typedef struct mips_multi_member mips_multi_member;
  3732. /* The instructions that make up the current multi-insn sequence. */
  3733. static vec<mips_multi_member> mips_multi_members;
  3734. /* How many instructions (as opposed to labels) are in the current
  3735. multi-insn sequence. */
  3736. static unsigned int mips_multi_num_insns;
  3737. /* Start a new multi-insn sequence. */
  3738. static void
  3739. mips_multi_start (void)
  3740. {
  3741. mips_multi_members.truncate (0);
  3742. mips_multi_num_insns = 0;
  3743. }
  3744. /* Add a new, uninitialized member to the current multi-insn sequence. */
  3745. static struct mips_multi_member *
  3746. mips_multi_add (void)
  3747. {
  3748. mips_multi_member empty;
  3749. return mips_multi_members.safe_push (empty);
  3750. }
  3751. /* Add a normal insn with the given asm format to the current multi-insn
  3752. sequence. The other arguments are a null-terminated list of operands. */
  3753. static void
  3754. mips_multi_add_insn (const char *format, ...)
  3755. {
  3756. struct mips_multi_member *member;
  3757. va_list ap;
  3758. unsigned int i;
  3759. rtx op;
  3760. member = mips_multi_add ();
  3761. member->is_label_p = false;
  3762. member->format = format;
  3763. va_start (ap, format);
  3764. i = 0;
  3765. while ((op = va_arg (ap, rtx)))
  3766. member->operands[i++] = op;
  3767. va_end (ap);
  3768. mips_multi_num_insns++;
  3769. }
  3770. /* Add the given label definition to the current multi-insn sequence.
  3771. The definition should include the colon. */
  3772. static void
  3773. mips_multi_add_label (const char *label)
  3774. {
  3775. struct mips_multi_member *member;
  3776. member = mips_multi_add ();
  3777. member->is_label_p = true;
  3778. member->format = label;
  3779. }
  3780. /* Return the index of the last member of the current multi-insn sequence. */
  3781. static unsigned int
  3782. mips_multi_last_index (void)
  3783. {
  3784. return mips_multi_members.length () - 1;
  3785. }
  3786. /* Add a copy of an existing instruction to the current multi-insn
  3787. sequence. I is the index of the instruction that should be copied. */
  3788. static void
  3789. mips_multi_copy_insn (unsigned int i)
  3790. {
  3791. struct mips_multi_member *member;
  3792. member = mips_multi_add ();
  3793. memcpy (member, &mips_multi_members[i], sizeof (*member));
  3794. gcc_assert (!member->is_label_p);
  3795. }
  3796. /* Change the operand of an existing instruction in the current
  3797. multi-insn sequence. I is the index of the instruction,
  3798. OP is the index of the operand, and X is the new value. */
  3799. static void
  3800. mips_multi_set_operand (unsigned int i, unsigned int op, rtx x)
  3801. {
  3802. mips_multi_members[i].operands[op] = x;
  3803. }
  3804. /* Write out the asm code for the current multi-insn sequence. */
  3805. static void
  3806. mips_multi_write (void)
  3807. {
  3808. struct mips_multi_member *member;
  3809. unsigned int i;
  3810. FOR_EACH_VEC_ELT (mips_multi_members, i, member)
  3811. if (member->is_label_p)
  3812. fprintf (asm_out_file, "%s\n", member->format);
  3813. else
  3814. output_asm_insn (member->format, member->operands);
  3815. }
  3816. /* Return one word of double-word value OP, taking into account the fixed
  3817. endianness of certain registers. HIGH_P is true to select the high part,
  3818. false to select the low part. */
  3819. rtx
  3820. mips_subword (rtx op, bool high_p)
  3821. {
  3822. unsigned int byte, offset;
  3823. machine_mode mode;
  3824. mode = GET_MODE (op);
  3825. if (mode == VOIDmode)
  3826. mode = TARGET_64BIT ? TImode : DImode;
  3827. if (TARGET_BIG_ENDIAN ? !high_p : high_p)
  3828. byte = UNITS_PER_WORD;
  3829. else
  3830. byte = 0;
  3831. if (FP_REG_RTX_P (op))
  3832. {
  3833. /* Paired FPRs are always ordered little-endian. */
  3834. offset = (UNITS_PER_WORD < UNITS_PER_HWFPVALUE ? high_p : byte != 0);
  3835. return gen_rtx_REG (word_mode, REGNO (op) + offset);
  3836. }
  3837. if (MEM_P (op))
  3838. return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
  3839. return simplify_gen_subreg (word_mode, op, mode, byte);
  3840. }
  3841. /* Return true if SRC should be moved into DEST using "MULT $0, $0".
  3842. SPLIT_TYPE is the condition under which moves should be split. */
  3843. static bool
  3844. mips_mult_move_p (rtx dest, rtx src, enum mips_split_type split_type)
  3845. {
  3846. return ((split_type != SPLIT_FOR_SPEED
  3847. || mips_tuning_info.fast_mult_zero_zero_p)
  3848. && src == const0_rtx
  3849. && REG_P (dest)
  3850. && GET_MODE_SIZE (GET_MODE (dest)) == 2 * UNITS_PER_WORD
  3851. && (ISA_HAS_DSP_MULT
  3852. ? ACC_REG_P (REGNO (dest))
  3853. : MD_REG_P (REGNO (dest))));
  3854. }
  3855. /* Return true if a move from SRC to DEST should be split into two.
  3856. SPLIT_TYPE describes the split condition. */
  3857. bool
  3858. mips_split_move_p (rtx dest, rtx src, enum mips_split_type split_type)
  3859. {
  3860. /* Check whether the move can be done using some variant of MULT $0,$0. */
  3861. if (mips_mult_move_p (dest, src, split_type))
  3862. return false;
  3863. /* FPR-to-FPR moves can be done in a single instruction, if they're
  3864. allowed at all. */
  3865. unsigned int size = GET_MODE_SIZE (GET_MODE (dest));
  3866. if (size == 8 && FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
  3867. return false;
  3868. /* Check for floating-point loads and stores. */
  3869. if (size == 8 && ISA_HAS_LDC1_SDC1)
  3870. {
  3871. if (FP_REG_RTX_P (dest) && MEM_P (src))
  3872. return false;
  3873. if (FP_REG_RTX_P (src) && MEM_P (dest))
  3874. return false;
  3875. }
  3876. /* Otherwise split all multiword moves. */
  3877. return size > UNITS_PER_WORD;
  3878. }
  3879. /* Split a move from SRC to DEST, given that mips_split_move_p holds.
  3880. SPLIT_TYPE describes the split condition. */
  3881. void
  3882. mips_split_move (rtx dest, rtx src, enum mips_split_type split_type)
  3883. {
  3884. rtx low_dest;
  3885. gcc_checking_assert (mips_split_move_p (dest, src, split_type));
  3886. if (FP_REG_RTX_P (dest) || FP_REG_RTX_P (src))
  3887. {
  3888. if (!TARGET_64BIT && GET_MODE (dest) == DImode)
  3889. emit_insn (gen_move_doubleword_fprdi (dest, src));
  3890. else if (!TARGET_64BIT && GET_MODE (dest) == DFmode)
  3891. emit_insn (gen_move_doubleword_fprdf (dest, src));
  3892. else if (!TARGET_64BIT && GET_MODE (dest) == V2SFmode)
  3893. emit_insn (gen_move_doubleword_fprv2sf (dest, src));
  3894. else if (!TARGET_64BIT && GET_MODE (dest) == V2SImode)
  3895. emit_insn (gen_move_doubleword_fprv2si (dest, src));
  3896. else if (!TARGET_64BIT && GET_MODE (dest) == V4HImode)
  3897. emit_insn (gen_move_doubleword_fprv4hi (dest, src));
  3898. else if (!TARGET_64BIT && GET_MODE (dest) == V8QImode)
  3899. emit_insn (gen_move_doubleword_fprv8qi (dest, src));
  3900. else if (TARGET_64BIT && GET_MODE (dest) == TFmode)
  3901. emit_insn (gen_move_doubleword_fprtf (dest, src));
  3902. else
  3903. gcc_unreachable ();
  3904. }
  3905. else if (REG_P (dest) && REGNO (dest) == MD_REG_FIRST)
  3906. {
  3907. low_dest = mips_subword (dest, false);
  3908. mips_emit_move (low_dest, mips_subword (src, false));
  3909. if (TARGET_64BIT)
  3910. emit_insn (gen_mthidi_ti (dest, mips_subword (src, true), low_dest));
  3911. else
  3912. emit_insn (gen_mthisi_di (dest, mips_subword (src, true), low_dest));
  3913. }
  3914. else if (REG_P (src) && REGNO (src) == MD_REG_FIRST)
  3915. {
  3916. mips_emit_move (mips_subword (dest, false), mips_subword (src, false));
  3917. if (TARGET_64BIT)
  3918. emit_insn (gen_mfhidi_ti (mips_subword (dest, true), src));
  3919. else
  3920. emit_insn (gen_mfhisi_di (mips_subword (dest, true), src));
  3921. }
  3922. else
  3923. {
  3924. /* The operation can be split into two normal moves. Decide in
  3925. which order to do them. */
  3926. low_dest = mips_subword (dest, false);
  3927. if (REG_P (low_dest)
  3928. && reg_overlap_mentioned_p (low_dest, src))
  3929. {
  3930. mips_emit_move (mips_subword (dest, true), mips_subword (src, true));
  3931. mips_emit_move (low_dest, mips_subword (src, false));
  3932. }
  3933. else
  3934. {
  3935. mips_emit_move (low_dest, mips_subword (src, false));
  3936. mips_emit_move (mips_subword (dest, true), mips_subword (src, true));
  3937. }
  3938. }
  3939. }
  3940. /* Return the split type for instruction INSN. */
  3941. static enum mips_split_type
  3942. mips_insn_split_type (rtx insn)
  3943. {
  3944. basic_block bb = BLOCK_FOR_INSN (insn);
  3945. if (bb)
  3946. {
  3947. if (optimize_bb_for_speed_p (bb))
  3948. return SPLIT_FOR_SPEED;
  3949. else
  3950. return SPLIT_FOR_SIZE;
  3951. }
  3952. /* Once CFG information has been removed, we should trust the optimization
  3953. decisions made by previous passes and only split where necessary. */
  3954. return SPLIT_IF_NECESSARY;
  3955. }
  3956. /* Return true if a move from SRC to DEST in INSN should be split. */
  3957. bool
  3958. mips_split_move_insn_p (rtx dest, rtx src, rtx insn)
  3959. {
  3960. return mips_split_move_p (dest, src, mips_insn_split_type (insn));
  3961. }
  3962. /* Split a move from SRC to DEST in INSN, given that mips_split_move_insn_p
  3963. holds. */
  3964. void
  3965. mips_split_move_insn (rtx dest, rtx src, rtx insn)
  3966. {
  3967. mips_split_move (dest, src, mips_insn_split_type (insn));
  3968. }
  3969. /* Return the appropriate instructions to move SRC into DEST. Assume
  3970. that SRC is operand 1 and DEST is operand 0. */
  3971. const char *
  3972. mips_output_move (rtx dest, rtx src)
  3973. {
  3974. enum rtx_code dest_code, src_code;
  3975. machine_mode mode;
  3976. enum mips_symbol_type symbol_type;
  3977. bool dbl_p;
  3978. dest_code = GET_CODE (dest);
  3979. src_code = GET_CODE (src);
  3980. mode = GET_MODE (dest);
  3981. dbl_p = (GET_MODE_SIZE (mode) == 8);
  3982. if (mips_split_move_p (dest, src, SPLIT_IF_NECESSARY))
  3983. return "#";
  3984. if ((src_code == REG && GP_REG_P (REGNO (src)))
  3985. || (!TARGET_MIPS16 && src == CONST0_RTX (mode)))
  3986. {
  3987. if (dest_code == REG)
  3988. {
  3989. if (GP_REG_P (REGNO (dest)))
  3990. return "move\t%0,%z1";
  3991. if (mips_mult_move_p (dest, src, SPLIT_IF_NECESSARY))
  3992. {
  3993. if (ISA_HAS_DSP_MULT)
  3994. return "mult\t%q0,%.,%.";
  3995. else
  3996. return "mult\t%.,%.";
  3997. }
  3998. /* Moves to HI are handled by special .md insns. */
  3999. if (REGNO (dest) == LO_REGNUM)
  4000. return "mtlo\t%z1";
  4001. if (DSP_ACC_REG_P (REGNO (dest)))
  4002. {
  4003. static char retval[] = "mt__\t%z1,%q0";
  4004. retval[2] = reg_names[REGNO (dest)][4];
  4005. retval[3] = reg_names[REGNO (dest)][5];
  4006. return retval;
  4007. }
  4008. if (FP_REG_P (REGNO (dest)))
  4009. return dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0";
  4010. if (ALL_COP_REG_P (REGNO (dest)))
  4011. {
  4012. static char retval[] = "dmtc_\t%z1,%0";
  4013. retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
  4014. return dbl_p ? retval : retval + 1;
  4015. }
  4016. }
  4017. if (dest_code == MEM)
  4018. switch (GET_MODE_SIZE (mode))
  4019. {
  4020. case 1: return "sb\t%z1,%0";
  4021. case 2: return "sh\t%z1,%0";
  4022. case 4: return "sw\t%z1,%0";
  4023. case 8: return "sd\t%z1,%0";
  4024. }
  4025. }
  4026. if (dest_code == REG && GP_REG_P (REGNO (dest)))
  4027. {
  4028. if (src_code == REG)
  4029. {
  4030. /* Moves from HI are handled by special .md insns. */
  4031. if (REGNO (src) == LO_REGNUM)
  4032. {
  4033. /* When generating VR4120 or VR4130 code, we use MACC and
  4034. DMACC instead of MFLO. This avoids both the normal
  4035. MIPS III HI/LO hazards and the errata related to
  4036. -mfix-vr4130. */
  4037. if (ISA_HAS_MACCHI)
  4038. return dbl_p ? "dmacc\t%0,%.,%." : "macc\t%0,%.,%.";
  4039. return "mflo\t%0";
  4040. }
  4041. if (DSP_ACC_REG_P (REGNO (src)))
  4042. {
  4043. static char retval[] = "mf__\t%0,%q1";
  4044. retval[2] = reg_names[REGNO (src)][4];
  4045. retval[3] = reg_names[REGNO (src)][5];
  4046. return retval;
  4047. }
  4048. if (FP_REG_P (REGNO (src)))
  4049. return dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1";
  4050. if (ALL_COP_REG_P (REGNO (src)))
  4051. {
  4052. static char retval[] = "dmfc_\t%0,%1";
  4053. retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
  4054. return dbl_p ? retval : retval + 1;
  4055. }
  4056. }
  4057. if (src_code == MEM)
  4058. switch (GET_MODE_SIZE (mode))
  4059. {
  4060. case 1: return "lbu\t%0,%1";
  4061. case 2: return "lhu\t%0,%1";
  4062. case 4: return "lw\t%0,%1";
  4063. case 8: return "ld\t%0,%1";
  4064. }
  4065. if (src_code == CONST_INT)
  4066. {
  4067. /* Don't use the X format for the operand itself, because that
  4068. will give out-of-range numbers for 64-bit hosts and 32-bit
  4069. targets. */
  4070. if (!TARGET_MIPS16)
  4071. return "li\t%0,%1\t\t\t# %X1";
  4072. if (SMALL_OPERAND_UNSIGNED (INTVAL (src)))
  4073. return "li\t%0,%1";
  4074. if (SMALL_OPERAND_UNSIGNED (-INTVAL (src)))
  4075. return "#";
  4076. }
  4077. if (src_code == HIGH)
  4078. return TARGET_MIPS16 ? "#" : "lui\t%0,%h1";
  4079. if (CONST_GP_P (src))
  4080. return "move\t%0,%1";
  4081. if (mips_symbolic_constant_p (src, SYMBOL_CONTEXT_LEA, &symbol_type)
  4082. && mips_lo_relocs[symbol_type] != 0)
  4083. {
  4084. /* A signed 16-bit constant formed by applying a relocation
  4085. operator to a symbolic address. */
  4086. gcc_assert (!mips_split_p[symbol_type]);
  4087. return "li\t%0,%R1";
  4088. }
  4089. if (symbolic_operand (src, VOIDmode))
  4090. {
  4091. gcc_assert (TARGET_MIPS16
  4092. ? TARGET_MIPS16_TEXT_LOADS
  4093. : !TARGET_EXPLICIT_RELOCS);
  4094. return dbl_p ? "dla\t%0,%1" : "la\t%0,%1";
  4095. }
  4096. }
  4097. if (src_code == REG && FP_REG_P (REGNO (src)))
  4098. {
  4099. if (dest_code == REG && FP_REG_P (REGNO (dest)))
  4100. {
  4101. if (GET_MODE (dest) == V2SFmode)
  4102. return "mov.ps\t%0,%1";
  4103. else
  4104. return dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1";
  4105. }
  4106. if (dest_code == MEM)
  4107. return dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0";
  4108. }
  4109. if (dest_code == REG && FP_REG_P (REGNO (dest)))
  4110. {
  4111. if (src_code == MEM)
  4112. return dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1";
  4113. }
  4114. if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
  4115. {
  4116. static char retval[] = "l_c_\t%0,%1";
  4117. retval[1] = (dbl_p ? 'd' : 'w');
  4118. retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
  4119. return retval;
  4120. }
  4121. if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
  4122. {
  4123. static char retval[] = "s_c_\t%1,%0";
  4124. retval[1] = (dbl_p ? 'd' : 'w');
  4125. retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
  4126. return retval;
  4127. }
  4128. gcc_unreachable ();
  4129. }
  4130. /* Return true if CMP1 is a suitable second operand for integer ordering
  4131. test CODE. See also the *sCC patterns in mips.md. */
  4132. static bool
  4133. mips_int_order_operand_ok_p (enum rtx_code code, rtx cmp1)
  4134. {
  4135. switch (code)
  4136. {
  4137. case GT:
  4138. case GTU:
  4139. return reg_or_0_operand (cmp1, VOIDmode);
  4140. case GE:
  4141. case GEU:
  4142. return !TARGET_MIPS16 && cmp1 == const1_rtx;
  4143. case LT:
  4144. case LTU:
  4145. return arith_operand (cmp1, VOIDmode);
  4146. case LE:
  4147. return sle_operand (cmp1, VOIDmode);
  4148. case LEU:
  4149. return sleu_operand (cmp1, VOIDmode);
  4150. default:
  4151. gcc_unreachable ();
  4152. }
  4153. }
  4154. /* Return true if *CMP1 (of mode MODE) is a valid second operand for
  4155. integer ordering test *CODE, or if an equivalent combination can
  4156. be formed by adjusting *CODE and *CMP1. When returning true, update
  4157. *CODE and *CMP1 with the chosen code and operand, otherwise leave
  4158. them alone. */
  4159. static bool
  4160. mips_canonicalize_int_order_test (enum rtx_code *code, rtx *cmp1,
  4161. machine_mode mode)
  4162. {
  4163. HOST_WIDE_INT plus_one;
  4164. if (mips_int_order_operand_ok_p (*code, *cmp1))
  4165. return true;
  4166. if (CONST_INT_P (*cmp1))
  4167. switch (*code)
  4168. {
  4169. case LE:
  4170. plus_one = trunc_int_for_mode (UINTVAL (*cmp1) + 1, mode);
  4171. if (INTVAL (*cmp1) < plus_one)
  4172. {
  4173. *code = LT;
  4174. *cmp1 = force_reg (mode, GEN_INT (plus_one));
  4175. return true;
  4176. }
  4177. break;
  4178. case LEU:
  4179. plus_one = trunc_int_for_mode (UINTVAL (*cmp1) + 1, mode);
  4180. if (plus_one != 0)
  4181. {
  4182. *code = LTU;
  4183. *cmp1 = force_reg (mode, GEN_INT (plus_one));
  4184. return true;
  4185. }
  4186. break;
  4187. default:
  4188. break;
  4189. }
  4190. return false;
  4191. }
  4192. /* Compare CMP0 and CMP1 using ordering test CODE and store the result
  4193. in TARGET. CMP0 and TARGET are register_operands. If INVERT_PTR
  4194. is nonnull, it's OK to set TARGET to the inverse of the result and
  4195. flip *INVERT_PTR instead. */
  4196. static void
  4197. mips_emit_int_order_test (enum rtx_code code, bool *invert_ptr,
  4198. rtx target, rtx cmp0, rtx cmp1)
  4199. {
  4200. machine_mode mode;
  4201. /* First see if there is a MIPS instruction that can do this operation.
  4202. If not, try doing the same for the inverse operation. If that also
  4203. fails, force CMP1 into a register and try again. */
  4204. mode = GET_MODE (cmp0);
  4205. if (mips_canonicalize_int_order_test (&code, &cmp1, mode))
  4206. mips_emit_binary (code, target, cmp0, cmp1);
  4207. else
  4208. {
  4209. enum rtx_code inv_code = reverse_condition (code);
  4210. if (!mips_canonicalize_int_order_test (&inv_code, &cmp1, mode))
  4211. {
  4212. cmp1 = force_reg (mode, cmp1);
  4213. mips_emit_int_order_test (code, invert_ptr, target, cmp0, cmp1);
  4214. }
  4215. else if (invert_ptr == 0)
  4216. {
  4217. rtx inv_target;
  4218. inv_target = mips_force_binary (GET_MODE (target),
  4219. inv_code, cmp0, cmp1);
  4220. mips_emit_binary (XOR, target, inv_target, const1_rtx);
  4221. }
  4222. else
  4223. {
  4224. *invert_ptr = !*invert_ptr;
  4225. mips_emit_binary (inv_code, target, cmp0, cmp1);
  4226. }
  4227. }
  4228. }
  4229. /* Return a register that is zero iff CMP0 and CMP1 are equal.
  4230. The register will have the same mode as CMP0. */
  4231. static rtx
  4232. mips_zero_if_equal (rtx cmp0, rtx cmp1)
  4233. {
  4234. if (cmp1 == const0_rtx)
  4235. return cmp0;
  4236. if (uns_arith_operand (cmp1, VOIDmode))
  4237. return expand_binop (GET_MODE (cmp0), xor_optab,
  4238. cmp0, cmp1, 0, 0, OPTAB_DIRECT);
  4239. return expand_binop (GET_MODE (cmp0), sub_optab,
  4240. cmp0, cmp1, 0, 0, OPTAB_DIRECT);
  4241. }
  4242. /* Convert *CODE into a code that can be used in a floating-point
  4243. scc instruction (C.cond.fmt). Return true if the values of
  4244. the condition code registers will be inverted, with 0 indicating
  4245. that the condition holds. */
  4246. static bool
  4247. mips_reversed_fp_cond (enum rtx_code *code)
  4248. {
  4249. switch (*code)
  4250. {
  4251. case NE:
  4252. case LTGT:
  4253. case ORDERED:
  4254. *code = reverse_condition_maybe_unordered (*code);
  4255. return true;
  4256. default:
  4257. return false;
  4258. }
  4259. }
  4260. /* Allocate a floating-point condition-code register of mode MODE.
  4261. These condition code registers are used for certain kinds
  4262. of compound operation, such as compare and branches, vconds,
  4263. and built-in functions. At expand time, their use is entirely
  4264. controlled by MIPS-specific code and is entirely internal
  4265. to these compound operations.
  4266. We could (and did in the past) expose condition-code values
  4267. as pseudo registers and leave the register allocator to pick
  4268. appropriate registers. The problem is that it is not practically
  4269. possible for the rtl optimizers to guarantee that no spills will
  4270. be needed, even when AVOID_CCMODE_COPIES is defined. We would
  4271. therefore need spill and reload sequences to handle the worst case.
  4272. Although such sequences do exist, they are very expensive and are
  4273. not something we'd want to use. This is especially true of CCV2 and
  4274. CCV4, where all the shuffling would greatly outweigh whatever benefit
  4275. the vectorization itself provides.
  4276. The main benefit of having more than one condition-code register
  4277. is to allow the pipelining of operations, especially those involving
  4278. comparisons and conditional moves. We don't really expect the
  4279. registers to be live for long periods, and certainly never want
  4280. them to be live across calls.
  4281. Also, there should be no penalty attached to using all the available
  4282. registers. They are simply bits in the same underlying FPU control
  4283. register.
  4284. We therefore expose the hardware registers from the outset and use
  4285. a simple round-robin allocation scheme. */
  4286. static rtx
  4287. mips_allocate_fcc (machine_mode mode)
  4288. {
  4289. unsigned int regno, count;
  4290. gcc_assert (TARGET_HARD_FLOAT && ISA_HAS_8CC);
  4291. if (mode == CCmode)
  4292. count = 1;
  4293. else if (mode == CCV2mode)
  4294. count = 2;
  4295. else if (mode == CCV4mode)
  4296. count = 4;
  4297. else
  4298. gcc_unreachable ();
  4299. cfun->machine->next_fcc += -cfun->machine->next_fcc & (count - 1);
  4300. if (cfun->machine->next_fcc > ST_REG_LAST - ST_REG_FIRST)
  4301. cfun->machine->next_fcc = 0;
  4302. regno = ST_REG_FIRST + cfun->machine->next_fcc;
  4303. cfun->machine->next_fcc += count;
  4304. return gen_rtx_REG (mode, regno);
  4305. }
  4306. /* Convert a comparison into something that can be used in a branch or
  4307. conditional move. On entry, *OP0 and *OP1 are the values being
  4308. compared and *CODE is the code used to compare them.
  4309. Update *CODE, *OP0 and *OP1 so that they describe the final comparison.
  4310. If NEED_EQ_NE_P, then only EQ or NE comparisons against zero are possible,
  4311. otherwise any standard branch condition can be used. The standard branch
  4312. conditions are:
  4313. - EQ or NE between two registers.
  4314. - any comparison between a register and zero. */
  4315. static void
  4316. mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p)
  4317. {
  4318. rtx cmp_op0 = *op0;
  4319. rtx cmp_op1 = *op1;
  4320. if (GET_MODE_CLASS (GET_MODE (*op0)) == MODE_INT)
  4321. {
  4322. if (!need_eq_ne_p && *op1 == const0_rtx)
  4323. ;
  4324. else if (*code == EQ || *code == NE)
  4325. {
  4326. if (need_eq_ne_p)
  4327. {
  4328. *op0 = mips_zero_if_equal (cmp_op0, cmp_op1);
  4329. *op1 = const0_rtx;
  4330. }
  4331. else
  4332. *op1 = force_reg (GET_MODE (cmp_op0), cmp_op1);
  4333. }
  4334. else
  4335. {
  4336. /* The comparison needs a separate scc instruction. Store the
  4337. result of the scc in *OP0 and compare it against zero. */
  4338. bool invert = false;
  4339. *op0 = gen_reg_rtx (GET_MODE (cmp_op0));
  4340. mips_emit_int_order_test (*code, &invert, *op0, cmp_op0, cmp_op1);
  4341. *code = (invert ? EQ : NE);
  4342. *op1 = const0_rtx;
  4343. }
  4344. }
  4345. else if (ALL_FIXED_POINT_MODE_P (GET_MODE (cmp_op0)))
  4346. {
  4347. *op0 = gen_rtx_REG (CCDSPmode, CCDSP_CC_REGNUM);
  4348. mips_emit_binary (*code, *op0, cmp_op0, cmp_op1);
  4349. *code = NE;
  4350. *op1 = const0_rtx;
  4351. }
  4352. else
  4353. {
  4354. enum rtx_code cmp_code;
  4355. /* Floating-point tests use a separate C.cond.fmt or CMP.cond.fmt
  4356. comparison to set a register. The branch or conditional move will
  4357. then compare that register against zero.
  4358. Set CMP_CODE to the code of the comparison instruction and
  4359. *CODE to the code that the branch or move should use. */
  4360. cmp_code = *code;
  4361. if (ISA_HAS_CCF)
  4362. {
  4363. /* All FP conditions can be implemented directly with CMP.cond.fmt
  4364. or by reversing the operands. */
  4365. *code = NE;
  4366. *op0 = gen_reg_rtx (CCFmode);
  4367. }
  4368. else
  4369. {
  4370. /* Three FP conditions cannot be implemented by reversing the
  4371. operands for C.cond.fmt, instead a reversed condition code is
  4372. required and a test for false. */
  4373. *code = mips_reversed_fp_cond (&cmp_code) ? EQ : NE;
  4374. if (ISA_HAS_8CC)
  4375. *op0 = mips_allocate_fcc (CCmode);
  4376. else
  4377. *op0 = gen_rtx_REG (CCmode, FPSW_REGNUM);
  4378. }
  4379. *op1 = const0_rtx;
  4380. mips_emit_binary (cmp_code, *op0, cmp_op0, cmp_op1);
  4381. }
  4382. }
  4383. /* Try performing the comparison in OPERANDS[1], whose arms are OPERANDS[2]
  4384. and OPERAND[3]. Store the result in OPERANDS[0].
  4385. On 64-bit targets, the mode of the comparison and target will always be
  4386. SImode, thus possibly narrower than that of the comparison's operands. */
  4387. void
  4388. mips_expand_scc (rtx operands[])
  4389. {
  4390. rtx target = operands[0];
  4391. enum rtx_code code = GET_CODE (operands[1]);
  4392. rtx op0 = operands[2];
  4393. rtx op1 = operands[3];
  4394. gcc_assert (GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT);
  4395. if (code == EQ || code == NE)
  4396. {
  4397. if (ISA_HAS_SEQ_SNE
  4398. && reg_imm10_operand (op1, GET_MODE (op1)))
  4399. mips_emit_binary (code, target, op0, op1);
  4400. else
  4401. {
  4402. rtx zie = mips_zero_if_equal (op0, op1);
  4403. mips_emit_binary (code, target, zie, const0_rtx);
  4404. }
  4405. }
  4406. else
  4407. mips_emit_int_order_test (code, 0, target, op0, op1);
  4408. }
  4409. /* Compare OPERANDS[1] with OPERANDS[2] using comparison code
  4410. CODE and jump to OPERANDS[3] if the condition holds. */
  4411. void
  4412. mips_expand_conditional_branch (rtx *operands)
  4413. {
  4414. enum rtx_code code = GET_CODE (operands[0]);
  4415. rtx op0 = operands[1];
  4416. rtx op1 = operands[2];
  4417. rtx condition;
  4418. mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16);
  4419. condition = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
  4420. emit_jump_insn (gen_condjump (condition, operands[3]));
  4421. }
  4422. /* Implement:
  4423. (set temp (COND:CCV2 CMP_OP0 CMP_OP1))
  4424. (set DEST (unspec [TRUE_SRC FALSE_SRC temp] UNSPEC_MOVE_TF_PS)) */
  4425. void
  4426. mips_expand_vcondv2sf (rtx dest, rtx true_src, rtx false_src,
  4427. enum rtx_code cond, rtx cmp_op0, rtx cmp_op1)
  4428. {
  4429. rtx cmp_result;
  4430. bool reversed_p;
  4431. reversed_p = mips_reversed_fp_cond (&cond);
  4432. cmp_result = mips_allocate_fcc (CCV2mode);
  4433. emit_insn (gen_scc_ps (cmp_result,
  4434. gen_rtx_fmt_ee (cond, VOIDmode, cmp_op0, cmp_op1)));
  4435. if (reversed_p)
  4436. emit_insn (gen_mips_cond_move_tf_ps (dest, false_src, true_src,
  4437. cmp_result));
  4438. else
  4439. emit_insn (gen_mips_cond_move_tf_ps (dest, true_src, false_src,
  4440. cmp_result));
  4441. }
  4442. /* Perform the comparison in OPERANDS[1]. Move OPERANDS[2] into OPERANDS[0]
  4443. if the condition holds, otherwise move OPERANDS[3] into OPERANDS[0]. */
  4444. void
  4445. mips_expand_conditional_move (rtx *operands)
  4446. {
  4447. rtx cond;
  4448. enum rtx_code code = GET_CODE (operands[1]);
  4449. rtx op0 = XEXP (operands[1], 0);
  4450. rtx op1 = XEXP (operands[1], 1);
  4451. mips_emit_compare (&code, &op0, &op1, true);
  4452. cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);
  4453. /* There is no direct support for general conditional GP move involving
  4454. two registers using SEL. */
  4455. if (ISA_HAS_SEL
  4456. && INTEGRAL_MODE_P (GET_MODE (operands[2]))
  4457. && register_operand (operands[2], VOIDmode)
  4458. && register_operand (operands[3], VOIDmode))
  4459. {
  4460. machine_mode mode = GET_MODE (operands[0]);
  4461. rtx temp = gen_reg_rtx (mode);
  4462. rtx temp2 = gen_reg_rtx (mode);
  4463. emit_insn (gen_rtx_SET (VOIDmode, temp,
  4464. gen_rtx_IF_THEN_ELSE (mode, cond,
  4465. operands[2], const0_rtx)));
  4466. /* Flip the test for the second operand. */
  4467. cond = gen_rtx_fmt_ee ((code == EQ) ? NE : EQ, GET_MODE (op0), op0, op1);
  4468. emit_insn (gen_rtx_SET (VOIDmode, temp2,
  4469. gen_rtx_IF_THEN_ELSE (mode, cond,
  4470. operands[3], const0_rtx)));
  4471. /* Merge the two results, at least one is guaranteed to be zero. */
  4472. emit_insn (gen_rtx_SET (VOIDmode, operands[0],
  4473. gen_rtx_IOR (mode, temp, temp2)));
  4474. }
  4475. else
  4476. {
  4477. if (FLOAT_MODE_P (GET_MODE (operands[2])) && !ISA_HAS_SEL)
  4478. {
  4479. operands[2] = force_reg (GET_MODE (operands[0]), operands[2]);
  4480. operands[3] = force_reg (GET_MODE (operands[0]), operands[3]);
  4481. }
  4482. emit_insn (gen_rtx_SET (VOIDmode, operands[0],
  4483. gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]), cond,
  4484. operands[2], operands[3])));
  4485. }
  4486. }
  4487. /* Perform the comparison in COMPARISON, then trap if the condition holds. */
  4488. void
  4489. mips_expand_conditional_trap (rtx comparison)
  4490. {
  4491. rtx op0, op1;
  4492. machine_mode mode;
  4493. enum rtx_code code;
  4494. /* MIPS conditional trap instructions don't have GT or LE flavors,
  4495. so we must swap the operands and convert to LT and GE respectively. */
  4496. code = GET_CODE (comparison);
  4497. switch (code)
  4498. {
  4499. case GT:
  4500. case LE:
  4501. case GTU:
  4502. case LEU:
  4503. code = swap_condition (code);
  4504. op0 = XEXP (comparison, 1);
  4505. op1 = XEXP (comparison, 0);
  4506. break;
  4507. default:
  4508. op0 = XEXP (comparison, 0);
  4509. op1 = XEXP (comparison, 1);
  4510. break;
  4511. }
  4512. mode = GET_MODE (XEXP (comparison, 0));
  4513. op0 = force_reg (mode, op0);
  4514. if (!(ISA_HAS_COND_TRAPI
  4515. ? arith_operand (op1, mode)
  4516. : reg_or_0_operand (op1, mode)))
  4517. op1 = force_reg (mode, op1);
  4518. emit_insn (gen_rtx_TRAP_IF (VOIDmode,
  4519. gen_rtx_fmt_ee (code, mode, op0, op1),
  4520. const0_rtx));
  4521. }
  4522. /* Initialize *CUM for a call to a function of type FNTYPE. */
  4523. void
  4524. mips_init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype)
  4525. {
  4526. memset (cum, 0, sizeof (*cum));
  4527. cum->prototype = (fntype && prototype_p (fntype));
  4528. cum->gp_reg_found = (cum->prototype && stdarg_p (fntype));
  4529. }
  4530. /* Fill INFO with information about a single argument. CUM is the
  4531. cumulative state for earlier arguments. MODE is the mode of this
  4532. argument and TYPE is its type (if known). NAMED is true if this
  4533. is a named (fixed) argument rather than a variable one. */
  4534. static void
  4535. mips_get_arg_info (struct mips_arg_info *info, const CUMULATIVE_ARGS *cum,
  4536. machine_mode mode, const_tree type, bool named)
  4537. {
  4538. bool doubleword_aligned_p;
  4539. unsigned int num_bytes, num_words, max_regs;
  4540. /* Work out the size of the argument. */
  4541. num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
  4542. num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  4543. /* Decide whether it should go in a floating-point register, assuming
  4544. one is free. Later code checks for availability.
  4545. The checks against UNITS_PER_FPVALUE handle the soft-float and
  4546. single-float cases. */
  4547. switch (mips_abi)
  4548. {
  4549. case ABI_EABI:
  4550. /* The EABI conventions have traditionally been defined in terms
  4551. of TYPE_MODE, regardless of the actual type. */
  4552. info->fpr_p = ((GET_MODE_CLASS (mode) == MODE_FLOAT
  4553. || mode == V2SFmode)
  4554. && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
  4555. break;
  4556. case ABI_32:
  4557. case ABI_O64:
  4558. /* Only leading floating-point scalars are passed in
  4559. floating-point registers. We also handle vector floats the same
  4560. say, which is OK because they are not covered by the standard ABI. */
  4561. gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode);
  4562. info->fpr_p = (!cum->gp_reg_found
  4563. && cum->arg_number < 2
  4564. && (type == 0
  4565. || SCALAR_FLOAT_TYPE_P (type)
  4566. || VECTOR_FLOAT_TYPE_P (type))
  4567. && (GET_MODE_CLASS (mode) == MODE_FLOAT
  4568. || mode == V2SFmode)
  4569. && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
  4570. break;
  4571. case ABI_N32:
  4572. case ABI_64:
  4573. /* Scalar, complex and vector floating-point types are passed in
  4574. floating-point registers, as long as this is a named rather
  4575. than a variable argument. */
  4576. gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode);
  4577. info->fpr_p = (named
  4578. && (type == 0 || FLOAT_TYPE_P (type))
  4579. && (GET_MODE_CLASS (mode) == MODE_FLOAT
  4580. || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
  4581. || mode == V2SFmode)
  4582. && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_FPVALUE);
  4583. /* ??? According to the ABI documentation, the real and imaginary
  4584. parts of complex floats should be passed in individual registers.
  4585. The real and imaginary parts of stack arguments are supposed
  4586. to be contiguous and there should be an extra word of padding
  4587. at the end.
  4588. This has two problems. First, it makes it impossible to use a
  4589. single "void *" va_list type, since register and stack arguments
  4590. are passed differently. (At the time of writing, MIPSpro cannot
  4591. handle complex float varargs correctly.) Second, it's unclear
  4592. what should happen when there is only one register free.
  4593. For now, we assume that named complex floats should go into FPRs
  4594. if there are two FPRs free, otherwise they should be passed in the
  4595. same way as a struct containing two floats. */
  4596. if (info->fpr_p
  4597. && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
  4598. && GET_MODE_UNIT_SIZE (mode) < UNITS_PER_FPVALUE)
  4599. {
  4600. if (cum->num_gprs >= MAX_ARGS_IN_REGISTERS - 1)
  4601. info->fpr_p = false;
  4602. else
  4603. num_words = 2;
  4604. }
  4605. break;
  4606. default:
  4607. gcc_unreachable ();
  4608. }
  4609. /* See whether the argument has doubleword alignment. */
  4610. doubleword_aligned_p = (mips_function_arg_boundary (mode, type)
  4611. > BITS_PER_WORD);
  4612. /* Set REG_OFFSET to the register count we're interested in.
  4613. The EABI allocates the floating-point registers separately,
  4614. but the other ABIs allocate them like integer registers. */
  4615. info->reg_offset = (mips_abi == ABI_EABI && info->fpr_p
  4616. ? cum->num_fprs
  4617. : cum->num_gprs);
  4618. /* Advance to an even register if the argument is doubleword-aligned. */
  4619. if (doubleword_aligned_p)
  4620. info->reg_offset += info->reg_offset & 1;
  4621. /* Work out the offset of a stack argument. */
  4622. info->stack_offset = cum->stack_words;
  4623. if (doubleword_aligned_p)
  4624. info->stack_offset += info->stack_offset & 1;
  4625. max_regs = MAX_ARGS_IN_REGISTERS - info->reg_offset;
  4626. /* Partition the argument between registers and stack. */
  4627. info->reg_words = MIN (num_words, max_regs);
  4628. info->stack_words = num_words - info->reg_words;
  4629. }
  4630. /* INFO describes a register argument that has the normal format for the
  4631. argument's mode. Return the register it uses, assuming that FPRs are
  4632. available if HARD_FLOAT_P. */
  4633. static unsigned int
  4634. mips_arg_regno (const struct mips_arg_info *info, bool hard_float_p)
  4635. {
  4636. if (!info->fpr_p || !hard_float_p)
  4637. return GP_ARG_FIRST + info->reg_offset;
  4638. else if (mips_abi == ABI_32 && TARGET_DOUBLE_FLOAT && info->reg_offset > 0)
  4639. /* In o32, the second argument is always passed in $f14
  4640. for TARGET_DOUBLE_FLOAT, regardless of whether the
  4641. first argument was a word or doubleword. */
  4642. return FP_ARG_FIRST + 2;
  4643. else
  4644. return FP_ARG_FIRST + info->reg_offset;
  4645. }
  4646. /* Implement TARGET_STRICT_ARGUMENT_NAMING. */
  4647. static bool
  4648. mips_strict_argument_naming (cumulative_args_t ca ATTRIBUTE_UNUSED)
  4649. {
  4650. return !TARGET_OLDABI;
  4651. }
  4652. /* Implement TARGET_FUNCTION_ARG. */
  4653. static rtx
  4654. mips_function_arg (cumulative_args_t cum_v, machine_mode mode,
  4655. const_tree type, bool named)
  4656. {
  4657. CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
  4658. struct mips_arg_info info;
  4659. /* We will be called with a mode of VOIDmode after the last argument
  4660. has been seen. Whatever we return will be passed to the call expander.
  4661. If we need a MIPS16 fp_code, return a REG with the code stored as
  4662. the mode. */
  4663. if (mode == VOIDmode)
  4664. {
  4665. if (TARGET_MIPS16 && cum->fp_code != 0)
  4666. return gen_rtx_REG ((machine_mode) cum->fp_code, 0);
  4667. else
  4668. return NULL;
  4669. }
  4670. mips_get_arg_info (&info, cum, mode, type, named);
  4671. /* Return straight away if the whole argument is passed on the stack. */
  4672. if (info.reg_offset == MAX_ARGS_IN_REGISTERS)
  4673. return NULL;
  4674. /* The n32 and n64 ABIs say that if any 64-bit chunk of the structure
  4675. contains a double in its entirety, then that 64-bit chunk is passed
  4676. in a floating-point register. */
  4677. if (TARGET_NEWABI
  4678. && TARGET_HARD_FLOAT
  4679. && named
  4680. && type != 0
  4681. && TREE_CODE (type) == RECORD_TYPE
  4682. && TYPE_SIZE_UNIT (type)
  4683. && tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
  4684. {
  4685. tree field;
  4686. /* First check to see if there is any such field. */
  4687. for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
  4688. if (TREE_CODE (field) == FIELD_DECL
  4689. && SCALAR_FLOAT_TYPE_P (TREE_TYPE (field))
  4690. && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD
  4691. && tree_fits_shwi_p (bit_position (field))
  4692. && int_bit_position (field) % BITS_PER_WORD == 0)
  4693. break;
  4694. if (field != 0)
  4695. {
  4696. /* Now handle the special case by returning a PARALLEL
  4697. indicating where each 64-bit chunk goes. INFO.REG_WORDS
  4698. chunks are passed in registers. */
  4699. unsigned int i;
  4700. HOST_WIDE_INT bitpos;
  4701. rtx ret;
  4702. /* assign_parms checks the mode of ENTRY_PARM, so we must
  4703. use the actual mode here. */
  4704. ret = gen_rtx_PARALLEL (mode, rtvec_alloc (info.reg_words));
  4705. bitpos = 0;
  4706. field = TYPE_FIELDS (type);
  4707. for (i = 0; i < info.reg_words; i++)
  4708. {
  4709. rtx reg;
  4710. for (; field; field = DECL_CHAIN (field))
  4711. if (TREE_CODE (field) == FIELD_DECL
  4712. && int_bit_position (field) >= bitpos)
  4713. break;
  4714. if (field
  4715. && int_bit_position (field) == bitpos
  4716. && SCALAR_FLOAT_TYPE_P (TREE_TYPE (field))
  4717. && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD)
  4718. reg = gen_rtx_REG (DFmode, FP_ARG_FIRST + info.reg_offset + i);
  4719. else
  4720. reg = gen_rtx_REG (DImode, GP_ARG_FIRST + info.reg_offset + i);
  4721. XVECEXP (ret, 0, i)
  4722. = gen_rtx_EXPR_LIST (VOIDmode, reg,
  4723. GEN_INT (bitpos / BITS_PER_UNIT));
  4724. bitpos += BITS_PER_WORD;
  4725. }
  4726. return ret;
  4727. }
  4728. }
  4729. /* Handle the n32/n64 conventions for passing complex floating-point
  4730. arguments in FPR pairs. The real part goes in the lower register
  4731. and the imaginary part goes in the upper register. */
  4732. if (TARGET_NEWABI
  4733. && info.fpr_p
  4734. && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
  4735. {
  4736. rtx real, imag;
  4737. machine_mode inner;
  4738. unsigned int regno;
  4739. inner = GET_MODE_INNER (mode);
  4740. regno = FP_ARG_FIRST + info.reg_offset;
  4741. if (info.reg_words * UNITS_PER_WORD == GET_MODE_SIZE (inner))
  4742. {
  4743. /* Real part in registers, imaginary part on stack. */
  4744. gcc_assert (info.stack_words == info.reg_words);
  4745. return gen_rtx_REG (inner, regno);
  4746. }
  4747. else
  4748. {
  4749. gcc_assert (info.stack_words == 0);
  4750. real = gen_rtx_EXPR_LIST (VOIDmode,
  4751. gen_rtx_REG (inner, regno),
  4752. const0_rtx);
  4753. imag = gen_rtx_EXPR_LIST (VOIDmode,
  4754. gen_rtx_REG (inner,
  4755. regno + info.reg_words / 2),
  4756. GEN_INT (GET_MODE_SIZE (inner)));
  4757. return gen_rtx_PARALLEL (mode, gen_rtvec (2, real, imag));
  4758. }
  4759. }
  4760. return gen_rtx_REG (mode, mips_arg_regno (&info, TARGET_HARD_FLOAT));
  4761. }
  4762. /* Implement TARGET_FUNCTION_ARG_ADVANCE. */
  4763. static void
  4764. mips_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
  4765. const_tree type, bool named)
  4766. {
  4767. CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
  4768. struct mips_arg_info info;
  4769. mips_get_arg_info (&info, cum, mode, type, named);
  4770. if (!info.fpr_p)
  4771. cum->gp_reg_found = true;
  4772. /* See the comment above the CUMULATIVE_ARGS structure in mips.h for
  4773. an explanation of what this code does. It assumes that we're using
  4774. either the o32 or the o64 ABI, both of which pass at most 2 arguments
  4775. in FPRs. */
  4776. if (cum->arg_number < 2 && info.fpr_p)
  4777. cum->fp_code += (mode == SFmode ? 1 : 2) << (cum->arg_number * 2);
  4778. /* Advance the register count. This has the effect of setting
  4779. num_gprs to MAX_ARGS_IN_REGISTERS if a doubleword-aligned
  4780. argument required us to skip the final GPR and pass the whole
  4781. argument on the stack. */
  4782. if (mips_abi != ABI_EABI || !info.fpr_p)
  4783. cum->num_gprs = info.reg_offset + info.reg_words;
  4784. else if (info.reg_words > 0)
  4785. cum->num_fprs += MAX_FPRS_PER_FMT;
  4786. /* Advance the stack word count. */
  4787. if (info.stack_words > 0)
  4788. cum->stack_words = info.stack_offset + info.stack_words;
  4789. cum->arg_number++;
  4790. }
  4791. /* Implement TARGET_ARG_PARTIAL_BYTES. */
  4792. static int
  4793. mips_arg_partial_bytes (cumulative_args_t cum,
  4794. machine_mode mode, tree type, bool named)
  4795. {
  4796. struct mips_arg_info info;
  4797. mips_get_arg_info (&info, get_cumulative_args (cum), mode, type, named);
  4798. return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0;
  4799. }
  4800. /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at
  4801. least PARM_BOUNDARY bits of alignment, but will be given anything up
  4802. to STACK_BOUNDARY bits if the type requires it. */
  4803. static unsigned int
  4804. mips_function_arg_boundary (machine_mode mode, const_tree type)
  4805. {
  4806. unsigned int alignment;
  4807. alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode);
  4808. if (alignment < PARM_BOUNDARY)
  4809. alignment = PARM_BOUNDARY;
  4810. if (alignment > STACK_BOUNDARY)
  4811. alignment = STACK_BOUNDARY;
  4812. return alignment;
  4813. }
  4814. /* Implement TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE. */
  4815. static machine_mode
  4816. mips_get_reg_raw_mode (int regno)
  4817. {
  4818. if (TARGET_FLOATXX && FP_REG_P (regno))
  4819. return DFmode;
  4820. return default_get_reg_raw_mode (regno);
  4821. }
  4822. /* Return true if FUNCTION_ARG_PADDING (MODE, TYPE) should return
  4823. upward rather than downward. In other words, return true if the
  4824. first byte of the stack slot has useful data, false if the last
  4825. byte does. */
  4826. bool
  4827. mips_pad_arg_upward (machine_mode mode, const_tree type)
  4828. {
  4829. /* On little-endian targets, the first byte of every stack argument
  4830. is passed in the first byte of the stack slot. */
  4831. if (!BYTES_BIG_ENDIAN)
  4832. return true;
  4833. /* Otherwise, integral types are padded downward: the last byte of a
  4834. stack argument is passed in the last byte of the stack slot. */
  4835. if (type != 0
  4836. ? (INTEGRAL_TYPE_P (type)
  4837. || POINTER_TYPE_P (type)
  4838. || FIXED_POINT_TYPE_P (type))
  4839. : (SCALAR_INT_MODE_P (mode)
  4840. || ALL_SCALAR_FIXED_POINT_MODE_P (mode)))
  4841. return false;
  4842. /* Big-endian o64 pads floating-point arguments downward. */
  4843. if (mips_abi == ABI_O64)
  4844. if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
  4845. return false;
  4846. /* Other types are padded upward for o32, o64, n32 and n64. */
  4847. if (mips_abi != ABI_EABI)
  4848. return true;
  4849. /* Arguments smaller than a stack slot are padded downward. */
  4850. if (mode != BLKmode)
  4851. return GET_MODE_BITSIZE (mode) >= PARM_BOUNDARY;
  4852. else
  4853. return int_size_in_bytes (type) >= (PARM_BOUNDARY / BITS_PER_UNIT);
  4854. }
  4855. /* Likewise BLOCK_REG_PADDING (MODE, TYPE, ...). Return !BYTES_BIG_ENDIAN
  4856. if the least significant byte of the register has useful data. Return
  4857. the opposite if the most significant byte does. */
  4858. bool
  4859. mips_pad_reg_upward (machine_mode mode, tree type)
  4860. {
  4861. /* No shifting is required for floating-point arguments. */
  4862. if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
  4863. return !BYTES_BIG_ENDIAN;
  4864. /* Otherwise, apply the same padding to register arguments as we do
  4865. to stack arguments. */
  4866. return mips_pad_arg_upward (mode, type);
  4867. }
  4868. /* Return nonzero when an argument must be passed by reference. */
  4869. static bool
  4870. mips_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
  4871. machine_mode mode, const_tree type,
  4872. bool named ATTRIBUTE_UNUSED)
  4873. {
  4874. if (mips_abi == ABI_EABI)
  4875. {
  4876. int size;
  4877. /* ??? How should SCmode be handled? */
  4878. if (mode == DImode || mode == DFmode
  4879. || mode == DQmode || mode == UDQmode
  4880. || mode == DAmode || mode == UDAmode)
  4881. return 0;
  4882. size = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
  4883. return size == -1 || size > UNITS_PER_WORD;
  4884. }
  4885. else
  4886. {
  4887. /* If we have a variable-sized parameter, we have no choice. */
  4888. return targetm.calls.must_pass_in_stack (mode, type);
  4889. }
  4890. }
  4891. /* Implement TARGET_CALLEE_COPIES. */
  4892. static bool
  4893. mips_callee_copies (cumulative_args_t cum ATTRIBUTE_UNUSED,
  4894. machine_mode mode ATTRIBUTE_UNUSED,
  4895. const_tree type ATTRIBUTE_UNUSED, bool named)
  4896. {
  4897. return mips_abi == ABI_EABI && named;
  4898. }
  4899. /* See whether VALTYPE is a record whose fields should be returned in
  4900. floating-point registers. If so, return the number of fields and
  4901. list them in FIELDS (which should have two elements). Return 0
  4902. otherwise.
  4903. For n32 & n64, a structure with one or two fields is returned in
  4904. floating-point registers as long as every field has a floating-point
  4905. type. */
  4906. static int
  4907. mips_fpr_return_fields (const_tree valtype, tree *fields)
  4908. {
  4909. tree field;
  4910. int i;
  4911. if (!TARGET_NEWABI)
  4912. return 0;
  4913. if (TREE_CODE (valtype) != RECORD_TYPE)
  4914. return 0;
  4915. i = 0;
  4916. for (field = TYPE_FIELDS (valtype); field != 0; field = DECL_CHAIN (field))
  4917. {
  4918. if (TREE_CODE (field) != FIELD_DECL)
  4919. continue;
  4920. if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (field)))
  4921. return 0;
  4922. if (i == 2)
  4923. return 0;
  4924. fields[i++] = field;
  4925. }
  4926. return i;
  4927. }
  4928. /* Implement TARGET_RETURN_IN_MSB. For n32 & n64, we should return
  4929. a value in the most significant part of $2/$3 if:
  4930. - the target is big-endian;
  4931. - the value has a structure or union type (we generalize this to
  4932. cover aggregates from other languages too); and
  4933. - the structure is not returned in floating-point registers. */
  4934. static bool
  4935. mips_return_in_msb (const_tree valtype)
  4936. {
  4937. tree fields[2];
  4938. return (TARGET_NEWABI
  4939. && TARGET_BIG_ENDIAN
  4940. && AGGREGATE_TYPE_P (valtype)
  4941. && mips_fpr_return_fields (valtype, fields) == 0);
  4942. }
  4943. /* Return true if the function return value MODE will get returned in a
  4944. floating-point register. */
  4945. static bool
  4946. mips_return_mode_in_fpr_p (machine_mode mode)
  4947. {
  4948. gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode);
  4949. return ((GET_MODE_CLASS (mode) == MODE_FLOAT
  4950. || mode == V2SFmode
  4951. || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
  4952. && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_HWFPVALUE);
  4953. }
  4954. /* Return the representation of an FPR return register when the
  4955. value being returned in FP_RETURN has mode VALUE_MODE and the
  4956. return type itself has mode TYPE_MODE. On NewABI targets,
  4957. the two modes may be different for structures like:
  4958. struct __attribute__((packed)) foo { float f; }
  4959. where we return the SFmode value of "f" in FP_RETURN, but where
  4960. the structure itself has mode BLKmode. */
  4961. static rtx
  4962. mips_return_fpr_single (machine_mode type_mode,
  4963. machine_mode value_mode)
  4964. {
  4965. rtx x;
  4966. x = gen_rtx_REG (value_mode, FP_RETURN);
  4967. if (type_mode != value_mode)
  4968. {
  4969. x = gen_rtx_EXPR_LIST (VOIDmode, x, const0_rtx);
  4970. x = gen_rtx_PARALLEL (type_mode, gen_rtvec (1, x));
  4971. }
  4972. return x;
  4973. }
  4974. /* Return a composite value in a pair of floating-point registers.
  4975. MODE1 and OFFSET1 are the mode and byte offset for the first value,
  4976. likewise MODE2 and OFFSET2 for the second. MODE is the mode of the
  4977. complete value.
  4978. For n32 & n64, $f0 always holds the first value and $f2 the second.
  4979. Otherwise the values are packed together as closely as possible. */
  4980. static rtx
  4981. mips_return_fpr_pair (machine_mode mode,
  4982. machine_mode mode1, HOST_WIDE_INT offset1,
  4983. machine_mode mode2, HOST_WIDE_INT offset2)
  4984. {
  4985. int inc;
  4986. inc = (TARGET_NEWABI || mips_abi == ABI_32 ? 2 : MAX_FPRS_PER_FMT);
  4987. return gen_rtx_PARALLEL
  4988. (mode,
  4989. gen_rtvec (2,
  4990. gen_rtx_EXPR_LIST (VOIDmode,
  4991. gen_rtx_REG (mode1, FP_RETURN),
  4992. GEN_INT (offset1)),
  4993. gen_rtx_EXPR_LIST (VOIDmode,
  4994. gen_rtx_REG (mode2, FP_RETURN + inc),
  4995. GEN_INT (offset2))));
  4996. }
  4997. /* Implement TARGET_FUNCTION_VALUE and TARGET_LIBCALL_VALUE.
  4998. For normal calls, VALTYPE is the return type and MODE is VOIDmode.
  4999. For libcalls, VALTYPE is null and MODE is the mode of the return value. */
  5000. static rtx
  5001. mips_function_value_1 (const_tree valtype, const_tree fn_decl_or_type,
  5002. machine_mode mode)
  5003. {
  5004. if (valtype)
  5005. {
  5006. tree fields[2];
  5007. int unsigned_p;
  5008. const_tree func;
  5009. if (fn_decl_or_type && DECL_P (fn_decl_or_type))
  5010. func = fn_decl_or_type;
  5011. else
  5012. func = NULL;
  5013. mode = TYPE_MODE (valtype);
  5014. unsigned_p = TYPE_UNSIGNED (valtype);
  5015. /* Since TARGET_PROMOTE_FUNCTION_MODE unconditionally promotes,
  5016. return values, promote the mode here too. */
  5017. mode = promote_function_mode (valtype, mode, &unsigned_p, func, 1);
  5018. /* Handle structures whose fields are returned in $f0/$f2. */
  5019. switch (mips_fpr_return_fields (valtype, fields))
  5020. {
  5021. case 1:
  5022. return mips_return_fpr_single (mode,
  5023. TYPE_MODE (TREE_TYPE (fields[0])));
  5024. case 2:
  5025. return mips_return_fpr_pair (mode,
  5026. TYPE_MODE (TREE_TYPE (fields[0])),
  5027. int_byte_position (fields[0]),
  5028. TYPE_MODE (TREE_TYPE (fields[1])),
  5029. int_byte_position (fields[1]));
  5030. }
  5031. /* If a value is passed in the most significant part of a register, see
  5032. whether we have to round the mode up to a whole number of words. */
  5033. if (mips_return_in_msb (valtype))
  5034. {
  5035. HOST_WIDE_INT size = int_size_in_bytes (valtype);
  5036. if (size % UNITS_PER_WORD != 0)
  5037. {
  5038. size += UNITS_PER_WORD - size % UNITS_PER_WORD;
  5039. mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
  5040. }
  5041. }
  5042. /* For EABI, the class of return register depends entirely on MODE.
  5043. For example, "struct { some_type x; }" and "union { some_type x; }"
  5044. are returned in the same way as a bare "some_type" would be.
  5045. Other ABIs only use FPRs for scalar, complex or vector types. */
  5046. if (mips_abi != ABI_EABI && !FLOAT_TYPE_P (valtype))
  5047. return gen_rtx_REG (mode, GP_RETURN);
  5048. }
  5049. if (!TARGET_MIPS16)
  5050. {
  5051. /* Handle long doubles for n32 & n64. */
  5052. if (mode == TFmode)
  5053. return mips_return_fpr_pair (mode,
  5054. DImode, 0,
  5055. DImode, GET_MODE_SIZE (mode) / 2);
  5056. if (mips_return_mode_in_fpr_p (mode))
  5057. {
  5058. if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
  5059. return mips_return_fpr_pair (mode,
  5060. GET_MODE_INNER (mode), 0,
  5061. GET_MODE_INNER (mode),
  5062. GET_MODE_SIZE (mode) / 2);
  5063. else
  5064. return gen_rtx_REG (mode, FP_RETURN);
  5065. }
  5066. }
  5067. return gen_rtx_REG (mode, GP_RETURN);
  5068. }
  5069. /* Implement TARGET_FUNCTION_VALUE. */
  5070. static rtx
  5071. mips_function_value (const_tree valtype, const_tree fn_decl_or_type,
  5072. bool outgoing ATTRIBUTE_UNUSED)
  5073. {
  5074. return mips_function_value_1 (valtype, fn_decl_or_type, VOIDmode);
  5075. }
  5076. /* Implement TARGET_LIBCALL_VALUE. */
  5077. static rtx
  5078. mips_libcall_value (machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
  5079. {
  5080. return mips_function_value_1 (NULL_TREE, NULL_TREE, mode);
  5081. }
  5082. /* Implement TARGET_FUNCTION_VALUE_REGNO_P.
  5083. On the MIPS, R2 R3 and F0 F2 are the only register thus used. */
  5084. static bool
  5085. mips_function_value_regno_p (const unsigned int regno)
  5086. {
  5087. /* Most types only require one GPR or one FPR for return values but for
  5088. hard-float two FPRs can be used for _Complex types (for all ABIs)
  5089. and long doubles (for n64). */
  5090. if (regno == GP_RETURN
  5091. || regno == FP_RETURN
  5092. || (FP_RETURN != GP_RETURN
  5093. && regno == FP_RETURN + 2))
  5094. return true;
  5095. /* For o32 FP32, _Complex double will be returned in four 32-bit registers.
  5096. This does not apply to o32 FPXX as floating-point function argument and
  5097. return registers are described as 64-bit even though floating-point
  5098. registers are primarily described as 32-bit internally.
  5099. See: mips_get_reg_raw_mode. */
  5100. if ((mips_abi == ABI_32 && TARGET_FLOAT32)
  5101. && FP_RETURN != GP_RETURN
  5102. && (regno == FP_RETURN + 1
  5103. || regno == FP_RETURN + 3))
  5104. return true;
  5105. return false;
  5106. }
  5107. /* Implement TARGET_RETURN_IN_MEMORY. Under the o32 and o64 ABIs,
  5108. all BLKmode objects are returned in memory. Under the n32, n64
  5109. and embedded ABIs, small structures are returned in a register.
  5110. Objects with varying size must still be returned in memory, of
  5111. course. */
  5112. static bool
  5113. mips_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED)
  5114. {
  5115. return (TARGET_OLDABI
  5116. ? TYPE_MODE (type) == BLKmode
  5117. : !IN_RANGE (int_size_in_bytes (type), 0, 2 * UNITS_PER_WORD));
  5118. }
  5119. /* Implement TARGET_SETUP_INCOMING_VARARGS. */
  5120. static void
  5121. mips_setup_incoming_varargs (cumulative_args_t cum, machine_mode mode,
  5122. tree type, int *pretend_size ATTRIBUTE_UNUSED,
  5123. int no_rtl)
  5124. {
  5125. CUMULATIVE_ARGS local_cum;
  5126. int gp_saved, fp_saved;
  5127. /* The caller has advanced CUM up to, but not beyond, the last named
  5128. argument. Advance a local copy of CUM past the last "real" named
  5129. argument, to find out how many registers are left over. */
  5130. local_cum = *get_cumulative_args (cum);
  5131. mips_function_arg_advance (pack_cumulative_args (&local_cum), mode, type,
  5132. true);
  5133. /* Found out how many registers we need to save. */
  5134. gp_saved = MAX_ARGS_IN_REGISTERS - local_cum.num_gprs;
  5135. fp_saved = (EABI_FLOAT_VARARGS_P
  5136. ? MAX_ARGS_IN_REGISTERS - local_cum.num_fprs
  5137. : 0);
  5138. if (!no_rtl)
  5139. {
  5140. if (gp_saved > 0)
  5141. {
  5142. rtx ptr, mem;
  5143. ptr = plus_constant (Pmode, virtual_incoming_args_rtx,
  5144. REG_PARM_STACK_SPACE (cfun->decl)
  5145. - gp_saved * UNITS_PER_WORD);
  5146. mem = gen_frame_mem (BLKmode, ptr);
  5147. set_mem_alias_set (mem, get_varargs_alias_set ());
  5148. move_block_from_reg (local_cum.num_gprs + GP_ARG_FIRST,
  5149. mem, gp_saved);
  5150. }
  5151. if (fp_saved > 0)
  5152. {
  5153. /* We can't use move_block_from_reg, because it will use
  5154. the wrong mode. */
  5155. machine_mode mode;
  5156. int off, i;
  5157. /* Set OFF to the offset from virtual_incoming_args_rtx of
  5158. the first float register. The FP save area lies below
  5159. the integer one, and is aligned to UNITS_PER_FPVALUE bytes. */
  5160. off = (-gp_saved * UNITS_PER_WORD) & -UNITS_PER_FPVALUE;
  5161. off -= fp_saved * UNITS_PER_FPREG;
  5162. mode = TARGET_SINGLE_FLOAT ? SFmode : DFmode;
  5163. for (i = local_cum.num_fprs; i < MAX_ARGS_IN_REGISTERS;
  5164. i += MAX_FPRS_PER_FMT)
  5165. {
  5166. rtx ptr, mem;
  5167. ptr = plus_constant (Pmode, virtual_incoming_args_rtx, off);
  5168. mem = gen_frame_mem (mode, ptr);
  5169. set_mem_alias_set (mem, get_varargs_alias_set ());
  5170. mips_emit_move (mem, gen_rtx_REG (mode, FP_ARG_FIRST + i));
  5171. off += UNITS_PER_HWFPVALUE;
  5172. }
  5173. }
  5174. }
  5175. if (REG_PARM_STACK_SPACE (cfun->decl) == 0)
  5176. cfun->machine->varargs_size = (gp_saved * UNITS_PER_WORD
  5177. + fp_saved * UNITS_PER_FPREG);
  5178. }
  5179. /* Implement TARGET_BUILTIN_VA_LIST. */
  5180. static tree
  5181. mips_build_builtin_va_list (void)
  5182. {
  5183. if (EABI_FLOAT_VARARGS_P)
  5184. {
  5185. /* We keep 3 pointers, and two offsets.
  5186. Two pointers are to the overflow area, which starts at the CFA.
  5187. One of these is constant, for addressing into the GPR save area
  5188. below it. The other is advanced up the stack through the
  5189. overflow region.
  5190. The third pointer is to the bottom of the GPR save area.
  5191. Since the FPR save area is just below it, we can address
  5192. FPR slots off this pointer.
  5193. We also keep two one-byte offsets, which are to be subtracted
  5194. from the constant pointers to yield addresses in the GPR and
  5195. FPR save areas. These are downcounted as float or non-float
  5196. arguments are used, and when they get to zero, the argument
  5197. must be obtained from the overflow region. */
  5198. tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff, f_res, record;
  5199. tree array, index;
  5200. record = lang_hooks.types.make_type (RECORD_TYPE);
  5201. f_ovfl = build_decl (BUILTINS_LOCATION,
  5202. FIELD_DECL, get_identifier ("__overflow_argptr"),
  5203. ptr_type_node);
  5204. f_gtop = build_decl (BUILTINS_LOCATION,
  5205. FIELD_DECL, get_identifier ("__gpr_top"),
  5206. ptr_type_node);
  5207. f_ftop = build_decl (BUILTINS_LOCATION,
  5208. FIELD_DECL, get_identifier ("__fpr_top"),
  5209. ptr_type_node);
  5210. f_goff = build_decl (BUILTINS_LOCATION,
  5211. FIELD_DECL, get_identifier ("__gpr_offset"),
  5212. unsigned_char_type_node);
  5213. f_foff = build_decl (BUILTINS_LOCATION,
  5214. FIELD_DECL, get_identifier ("__fpr_offset"),
  5215. unsigned_char_type_node);
  5216. /* Explicitly pad to the size of a pointer, so that -Wpadded won't
  5217. warn on every user file. */
  5218. index = build_int_cst (NULL_TREE, GET_MODE_SIZE (ptr_mode) - 2 - 1);
  5219. array = build_array_type (unsigned_char_type_node,
  5220. build_index_type (index));
  5221. f_res = build_decl (BUILTINS_LOCATION,
  5222. FIELD_DECL, get_identifier ("__reserved"), array);
  5223. DECL_FIELD_CONTEXT (f_ovfl) = record;
  5224. DECL_FIELD_CONTEXT (f_gtop) = record;
  5225. DECL_FIELD_CONTEXT (f_ftop) = record;
  5226. DECL_FIELD_CONTEXT (f_goff) = record;
  5227. DECL_FIELD_CONTEXT (f_foff) = record;
  5228. DECL_FIELD_CONTEXT (f_res) = record;
  5229. TYPE_FIELDS (record) = f_ovfl;
  5230. DECL_CHAIN (f_ovfl) = f_gtop;
  5231. DECL_CHAIN (f_gtop) = f_ftop;
  5232. DECL_CHAIN (f_ftop) = f_goff;
  5233. DECL_CHAIN (f_goff) = f_foff;
  5234. DECL_CHAIN (f_foff) = f_res;
  5235. layout_type (record);
  5236. return record;
  5237. }
  5238. else
  5239. /* Otherwise, we use 'void *'. */
  5240. return ptr_type_node;
  5241. }
  5242. /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
  5243. static void
  5244. mips_va_start (tree valist, rtx nextarg)
  5245. {
  5246. if (EABI_FLOAT_VARARGS_P)
  5247. {
  5248. const CUMULATIVE_ARGS *cum;
  5249. tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff;
  5250. tree ovfl, gtop, ftop, goff, foff;
  5251. tree t;
  5252. int gpr_save_area_size;
  5253. int fpr_save_area_size;
  5254. int fpr_offset;
  5255. cum = &crtl->args.info;
  5256. gpr_save_area_size
  5257. = (MAX_ARGS_IN_REGISTERS - cum->num_gprs) * UNITS_PER_WORD;
  5258. fpr_save_area_size
  5259. = (MAX_ARGS_IN_REGISTERS - cum->num_fprs) * UNITS_PER_FPREG;
  5260. f_ovfl = TYPE_FIELDS (va_list_type_node);
  5261. f_gtop = DECL_CHAIN (f_ovfl);
  5262. f_ftop = DECL_CHAIN (f_gtop);
  5263. f_goff = DECL_CHAIN (f_ftop);
  5264. f_foff = DECL_CHAIN (f_goff);
  5265. ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl,
  5266. NULL_TREE);
  5267. gtop = build3 (COMPONENT_REF, TREE_TYPE (f_gtop), valist, f_gtop,
  5268. NULL_TREE);
  5269. ftop = build3 (COMPONENT_REF, TREE_TYPE (f_ftop), valist, f_ftop,
  5270. NULL_TREE);
  5271. goff = build3 (COMPONENT_REF, TREE_TYPE (f_goff), valist, f_goff,
  5272. NULL_TREE);
  5273. foff = build3 (COMPONENT_REF, TREE_TYPE (f_foff), valist, f_foff,
  5274. NULL_TREE);
  5275. /* Emit code to initialize OVFL, which points to the next varargs
  5276. stack argument. CUM->STACK_WORDS gives the number of stack
  5277. words used by named arguments. */
  5278. t = make_tree (TREE_TYPE (ovfl), virtual_incoming_args_rtx);
  5279. if (cum->stack_words > 0)
  5280. t = fold_build_pointer_plus_hwi (t, cum->stack_words * UNITS_PER_WORD);
  5281. t = build2 (MODIFY_EXPR, TREE_TYPE (ovfl), ovfl, t);
  5282. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  5283. /* Emit code to initialize GTOP, the top of the GPR save area. */
  5284. t = make_tree (TREE_TYPE (gtop), virtual_incoming_args_rtx);
  5285. t = build2 (MODIFY_EXPR, TREE_TYPE (gtop), gtop, t);
  5286. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  5287. /* Emit code to initialize FTOP, the top of the FPR save area.
  5288. This address is gpr_save_area_bytes below GTOP, rounded
  5289. down to the next fp-aligned boundary. */
  5290. t = make_tree (TREE_TYPE (ftop), virtual_incoming_args_rtx);
  5291. fpr_offset = gpr_save_area_size + UNITS_PER_FPVALUE - 1;
  5292. fpr_offset &= -UNITS_PER_FPVALUE;
  5293. if (fpr_offset)
  5294. t = fold_build_pointer_plus_hwi (t, -fpr_offset);
  5295. t = build2 (MODIFY_EXPR, TREE_TYPE (ftop), ftop, t);
  5296. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  5297. /* Emit code to initialize GOFF, the offset from GTOP of the
  5298. next GPR argument. */
  5299. t = build2 (MODIFY_EXPR, TREE_TYPE (goff), goff,
  5300. build_int_cst (TREE_TYPE (goff), gpr_save_area_size));
  5301. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  5302. /* Likewise emit code to initialize FOFF, the offset from FTOP
  5303. of the next FPR argument. */
  5304. t = build2 (MODIFY_EXPR, TREE_TYPE (foff), foff,
  5305. build_int_cst (TREE_TYPE (foff), fpr_save_area_size));
  5306. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  5307. }
  5308. else
  5309. {
  5310. nextarg = plus_constant (Pmode, nextarg, -cfun->machine->varargs_size);
  5311. std_expand_builtin_va_start (valist, nextarg);
  5312. }
  5313. }
  5314. /* Like std_gimplify_va_arg_expr, but apply alignment to zero-sized
  5315. types as well. */
  5316. static tree
  5317. mips_std_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
  5318. gimple_seq *post_p)
  5319. {
  5320. tree addr, t, type_size, rounded_size, valist_tmp;
  5321. unsigned HOST_WIDE_INT align, boundary;
  5322. bool indirect;
  5323. indirect = pass_by_reference (NULL, TYPE_MODE (type), type, false);
  5324. if (indirect)
  5325. type = build_pointer_type (type);
  5326. align = PARM_BOUNDARY / BITS_PER_UNIT;
  5327. boundary = targetm.calls.function_arg_boundary (TYPE_MODE (type), type);
  5328. /* When we align parameter on stack for caller, if the parameter
  5329. alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
  5330. aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee
  5331. here with caller. */
  5332. if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
  5333. boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
  5334. boundary /= BITS_PER_UNIT;
  5335. /* Hoist the valist value into a temporary for the moment. */
  5336. valist_tmp = get_initialized_tmp_var (valist, pre_p, NULL);
  5337. /* va_list pointer is aligned to PARM_BOUNDARY. If argument actually
  5338. requires greater alignment, we must perform dynamic alignment. */
  5339. if (boundary > align)
  5340. {
  5341. t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
  5342. fold_build_pointer_plus_hwi (valist_tmp, boundary - 1));
  5343. gimplify_and_add (t, pre_p);
  5344. t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
  5345. fold_build2 (BIT_AND_EXPR, TREE_TYPE (valist),
  5346. valist_tmp,
  5347. build_int_cst (TREE_TYPE (valist), -boundary)));
  5348. gimplify_and_add (t, pre_p);
  5349. }
  5350. else
  5351. boundary = align;
  5352. /* If the actual alignment is less than the alignment of the type,
  5353. adjust the type accordingly so that we don't assume strict alignment
  5354. when dereferencing the pointer. */
  5355. boundary *= BITS_PER_UNIT;
  5356. if (boundary < TYPE_ALIGN (type))
  5357. {
  5358. type = build_variant_type_copy (type);
  5359. TYPE_ALIGN (type) = boundary;
  5360. }
  5361. /* Compute the rounded size of the type. */
  5362. type_size = size_in_bytes (type);
  5363. rounded_size = round_up (type_size, align);
  5364. /* Reduce rounded_size so it's sharable with the postqueue. */
  5365. gimplify_expr (&rounded_size, pre_p, post_p, is_gimple_val, fb_rvalue);
  5366. /* Get AP. */
  5367. addr = valist_tmp;
  5368. if (PAD_VARARGS_DOWN && !integer_zerop (rounded_size))
  5369. {
  5370. /* Small args are padded downward. */
  5371. t = fold_build2_loc (input_location, GT_EXPR, sizetype,
  5372. rounded_size, size_int (align));
  5373. t = fold_build3 (COND_EXPR, sizetype, t, size_zero_node,
  5374. size_binop (MINUS_EXPR, rounded_size, type_size));
  5375. addr = fold_build_pointer_plus (addr, t);
  5376. }
  5377. /* Compute new value for AP. */
  5378. t = fold_build_pointer_plus (valist_tmp, rounded_size);
  5379. t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist, t);
  5380. gimplify_and_add (t, pre_p);
  5381. addr = fold_convert (build_pointer_type (type), addr);
  5382. if (indirect)
  5383. addr = build_va_arg_indirect_ref (addr);
  5384. return build_va_arg_indirect_ref (addr);
  5385. }
  5386. /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
  5387. static tree
  5388. mips_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
  5389. gimple_seq *post_p)
  5390. {
  5391. tree addr;
  5392. bool indirect_p;
  5393. indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
  5394. if (indirect_p)
  5395. type = build_pointer_type (type);
  5396. if (!EABI_FLOAT_VARARGS_P)
  5397. addr = mips_std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
  5398. else
  5399. {
  5400. tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff;
  5401. tree ovfl, top, off, align;
  5402. HOST_WIDE_INT size, rsize, osize;
  5403. tree t, u;
  5404. f_ovfl = TYPE_FIELDS (va_list_type_node);
  5405. f_gtop = DECL_CHAIN (f_ovfl);
  5406. f_ftop = DECL_CHAIN (f_gtop);
  5407. f_goff = DECL_CHAIN (f_ftop);
  5408. f_foff = DECL_CHAIN (f_goff);
  5409. /* Let:
  5410. TOP be the top of the GPR or FPR save area;
  5411. OFF be the offset from TOP of the next register;
  5412. ADDR_RTX be the address of the argument;
  5413. SIZE be the number of bytes in the argument type;
  5414. RSIZE be the number of bytes used to store the argument
  5415. when it's in the register save area; and
  5416. OSIZE be the number of bytes used to store it when it's
  5417. in the stack overflow area.
  5418. The code we want is:
  5419. 1: off &= -rsize; // round down
  5420. 2: if (off != 0)
  5421. 3: {
  5422. 4: addr_rtx = top - off + (BYTES_BIG_ENDIAN ? RSIZE - SIZE : 0);
  5423. 5: off -= rsize;
  5424. 6: }
  5425. 7: else
  5426. 8: {
  5427. 9: ovfl = ((intptr_t) ovfl + osize - 1) & -osize;
  5428. 10: addr_rtx = ovfl + (BYTES_BIG_ENDIAN ? OSIZE - SIZE : 0);
  5429. 11: ovfl += osize;
  5430. 14: }
  5431. [1] and [9] can sometimes be optimized away. */
  5432. ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl,
  5433. NULL_TREE);
  5434. size = int_size_in_bytes (type);
  5435. if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_FLOAT
  5436. && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FPVALUE)
  5437. {
  5438. top = build3 (COMPONENT_REF, TREE_TYPE (f_ftop),
  5439. unshare_expr (valist), f_ftop, NULL_TREE);
  5440. off = build3 (COMPONENT_REF, TREE_TYPE (f_foff),
  5441. unshare_expr (valist), f_foff, NULL_TREE);
  5442. /* When va_start saves FPR arguments to the stack, each slot
  5443. takes up UNITS_PER_HWFPVALUE bytes, regardless of the
  5444. argument's precision. */
  5445. rsize = UNITS_PER_HWFPVALUE;
  5446. /* Overflow arguments are padded to UNITS_PER_WORD bytes
  5447. (= PARM_BOUNDARY bits). This can be different from RSIZE
  5448. in two cases:
  5449. (1) On 32-bit targets when TYPE is a structure such as:
  5450. struct s { float f; };
  5451. Such structures are passed in paired FPRs, so RSIZE
  5452. will be 8 bytes. However, the structure only takes
  5453. up 4 bytes of memory, so OSIZE will only be 4.
  5454. (2) In combinations such as -mgp64 -msingle-float
  5455. -fshort-double. Doubles passed in registers will then take
  5456. up 4 (UNITS_PER_HWFPVALUE) bytes, but those passed on the
  5457. stack take up UNITS_PER_WORD bytes. */
  5458. osize = MAX (GET_MODE_SIZE (TYPE_MODE (type)), UNITS_PER_WORD);
  5459. }
  5460. else
  5461. {
  5462. top = build3 (COMPONENT_REF, TREE_TYPE (f_gtop),
  5463. unshare_expr (valist), f_gtop, NULL_TREE);
  5464. off = build3 (COMPONENT_REF, TREE_TYPE (f_goff),
  5465. unshare_expr (valist), f_goff, NULL_TREE);
  5466. rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
  5467. if (rsize > UNITS_PER_WORD)
  5468. {
  5469. /* [1] Emit code for: off &= -rsize. */
  5470. t = build2 (BIT_AND_EXPR, TREE_TYPE (off), unshare_expr (off),
  5471. build_int_cst (TREE_TYPE (off), -rsize));
  5472. gimplify_assign (unshare_expr (off), t, pre_p);
  5473. }
  5474. osize = rsize;
  5475. }
  5476. /* [2] Emit code to branch if off == 0. */
  5477. t = build2 (NE_EXPR, boolean_type_node, unshare_expr (off),
  5478. build_int_cst (TREE_TYPE (off), 0));
  5479. addr = build3 (COND_EXPR, ptr_type_node, t, NULL_TREE, NULL_TREE);
  5480. /* [5] Emit code for: off -= rsize. We do this as a form of
  5481. post-decrement not available to C. */
  5482. t = fold_convert (TREE_TYPE (off), build_int_cst (NULL_TREE, rsize));
  5483. t = build2 (POSTDECREMENT_EXPR, TREE_TYPE (off), off, t);
  5484. /* [4] Emit code for:
  5485. addr_rtx = top - off + (BYTES_BIG_ENDIAN ? RSIZE - SIZE : 0). */
  5486. t = fold_convert (sizetype, t);
  5487. t = fold_build1 (NEGATE_EXPR, sizetype, t);
  5488. t = fold_build_pointer_plus (top, t);
  5489. if (BYTES_BIG_ENDIAN && rsize > size)
  5490. t = fold_build_pointer_plus_hwi (t, rsize - size);
  5491. COND_EXPR_THEN (addr) = t;
  5492. if (osize > UNITS_PER_WORD)
  5493. {
  5494. /* [9] Emit: ovfl = ((intptr_t) ovfl + osize - 1) & -osize. */
  5495. t = fold_build_pointer_plus_hwi (unshare_expr (ovfl), osize - 1);
  5496. u = build_int_cst (TREE_TYPE (t), -osize);
  5497. t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, u);
  5498. align = build2 (MODIFY_EXPR, TREE_TYPE (ovfl),
  5499. unshare_expr (ovfl), t);
  5500. }
  5501. else
  5502. align = NULL;
  5503. /* [10, 11] Emit code for:
  5504. addr_rtx = ovfl + (BYTES_BIG_ENDIAN ? OSIZE - SIZE : 0)
  5505. ovfl += osize. */
  5506. u = fold_convert (TREE_TYPE (ovfl), build_int_cst (NULL_TREE, osize));
  5507. t = build2 (POSTINCREMENT_EXPR, TREE_TYPE (ovfl), ovfl, u);
  5508. if (BYTES_BIG_ENDIAN && osize > size)
  5509. t = fold_build_pointer_plus_hwi (t, osize - size);
  5510. /* String [9] and [10, 11] together. */
  5511. if (align)
  5512. t = build2 (COMPOUND_EXPR, TREE_TYPE (t), align, t);
  5513. COND_EXPR_ELSE (addr) = t;
  5514. addr = fold_convert (build_pointer_type (type), addr);
  5515. addr = build_va_arg_indirect_ref (addr);
  5516. }
  5517. if (indirect_p)
  5518. addr = build_va_arg_indirect_ref (addr);
  5519. return addr;
  5520. }
  5521. /* Declare a unique, locally-binding function called NAME, then start
  5522. its definition. */
  5523. static void
  5524. mips_start_unique_function (const char *name)
  5525. {
  5526. tree decl;
  5527. decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
  5528. get_identifier (name),
  5529. build_function_type_list (void_type_node, NULL_TREE));
  5530. DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
  5531. NULL_TREE, void_type_node);
  5532. TREE_PUBLIC (decl) = 1;
  5533. TREE_STATIC (decl) = 1;
  5534. cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
  5535. targetm.asm_out.unique_section (decl, 0);
  5536. switch_to_section (get_named_section (decl, NULL, 0));
  5537. targetm.asm_out.globalize_label (asm_out_file, name);
  5538. fputs ("\t.hidden\t", asm_out_file);
  5539. assemble_name (asm_out_file, name);
  5540. putc ('\n', asm_out_file);
  5541. }
  5542. /* Start a definition of function NAME. MIPS16_P indicates whether the
  5543. function contains MIPS16 code. */
  5544. static void
  5545. mips_start_function_definition (const char *name, bool mips16_p)
  5546. {
  5547. if (mips16_p)
  5548. fprintf (asm_out_file, "\t.set\tmips16\n");
  5549. else
  5550. fprintf (asm_out_file, "\t.set\tnomips16\n");
  5551. if (TARGET_MICROMIPS)
  5552. fprintf (asm_out_file, "\t.set\tmicromips\n");
  5553. #ifdef HAVE_GAS_MICROMIPS
  5554. else
  5555. fprintf (asm_out_file, "\t.set\tnomicromips\n");
  5556. #endif
  5557. if (!flag_inhibit_size_directive)
  5558. {
  5559. fputs ("\t.ent\t", asm_out_file);
  5560. assemble_name (asm_out_file, name);
  5561. fputs ("\n", asm_out_file);
  5562. }
  5563. ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, name, "function");
  5564. /* Start the definition proper. */
  5565. assemble_name (asm_out_file, name);
  5566. fputs (":\n", asm_out_file);
  5567. }
  5568. /* End a function definition started by mips_start_function_definition. */
  5569. static void
  5570. mips_end_function_definition (const char *name)
  5571. {
  5572. if (!flag_inhibit_size_directive)
  5573. {
  5574. fputs ("\t.end\t", asm_out_file);
  5575. assemble_name (asm_out_file, name);
  5576. fputs ("\n", asm_out_file);
  5577. }
  5578. }
  5579. /* If *STUB_PTR points to a stub, output a comdat-style definition for it,
  5580. then free *STUB_PTR. */
  5581. static void
  5582. mips_finish_stub (mips_one_only_stub **stub_ptr)
  5583. {
  5584. mips_one_only_stub *stub = *stub_ptr;
  5585. if (!stub)
  5586. return;
  5587. const char *name = stub->get_name ();
  5588. mips_start_unique_function (name);
  5589. mips_start_function_definition (name, false);
  5590. stub->output_body ();
  5591. mips_end_function_definition (name);
  5592. delete stub;
  5593. *stub_ptr = 0;
  5594. }
  5595. /* Return true if calls to X can use R_MIPS_CALL* relocations. */
  5596. static bool
  5597. mips_ok_for_lazy_binding_p (rtx x)
  5598. {
  5599. return (TARGET_USE_GOT
  5600. && GET_CODE (x) == SYMBOL_REF
  5601. && !SYMBOL_REF_BIND_NOW_P (x)
  5602. && !mips_symbol_binds_local_p (x));
  5603. }
  5604. /* Load function address ADDR into register DEST. TYPE is as for
  5605. mips_expand_call. Return true if we used an explicit lazy-binding
  5606. sequence. */
  5607. static bool
  5608. mips_load_call_address (enum mips_call_type type, rtx dest, rtx addr)
  5609. {
  5610. /* If we're generating PIC, and this call is to a global function,
  5611. try to allow its address to be resolved lazily. This isn't
  5612. possible for sibcalls when $gp is call-saved because the value
  5613. of $gp on entry to the stub would be our caller's gp, not ours. */
  5614. if (TARGET_EXPLICIT_RELOCS
  5615. && !(type == MIPS_CALL_SIBCALL && TARGET_CALL_SAVED_GP)
  5616. && mips_ok_for_lazy_binding_p (addr))
  5617. {
  5618. addr = mips_got_load (dest, addr, SYMBOL_GOTOFF_CALL);
  5619. emit_insn (gen_rtx_SET (VOIDmode, dest, addr));
  5620. return true;
  5621. }
  5622. else
  5623. {
  5624. mips_emit_move (dest, addr);
  5625. return false;
  5626. }
  5627. }
  5628. struct local_alias_traits : default_hashmap_traits
  5629. {
  5630. static hashval_t hash (rtx);
  5631. static bool equal_keys (rtx, rtx);
  5632. };
  5633. /* Each locally-defined hard-float MIPS16 function has a local symbol
  5634. associated with it. This hash table maps the function symbol (FUNC)
  5635. to the local symbol (LOCAL). */
  5636. static GTY (()) hash_map<rtx, rtx, local_alias_traits> *mips16_local_aliases;
  5637. /* Hash table callbacks for mips16_local_aliases. */
  5638. hashval_t
  5639. local_alias_traits::hash (rtx func)
  5640. {
  5641. return htab_hash_string (XSTR (func, 0));
  5642. }
  5643. bool
  5644. local_alias_traits::equal_keys (rtx func1, rtx func2)
  5645. {
  5646. return rtx_equal_p (func1, func2);
  5647. }
  5648. /* FUNC is the symbol for a locally-defined hard-float MIPS16 function.
  5649. Return a local alias for it, creating a new one if necessary. */
  5650. static rtx
  5651. mips16_local_alias (rtx func)
  5652. {
  5653. /* Create the hash table if this is the first call. */
  5654. if (mips16_local_aliases == NULL)
  5655. mips16_local_aliases
  5656. = hash_map<rtx, rtx, local_alias_traits>::create_ggc (37);
  5657. /* Look up the function symbol, creating a new entry if need be. */
  5658. bool existed;
  5659. rtx *slot = &mips16_local_aliases->get_or_insert (func, &existed);
  5660. gcc_assert (slot != NULL);
  5661. if (!existed)
  5662. {
  5663. const char *func_name, *local_name;
  5664. rtx local;
  5665. /* Create a new SYMBOL_REF for the local symbol. The choice of
  5666. __fn_local_* is based on the __fn_stub_* names that we've
  5667. traditionally used for the non-MIPS16 stub. */
  5668. func_name = targetm.strip_name_encoding (XSTR (func, 0));
  5669. local_name = ACONCAT (("__fn_local_", func_name, NULL));
  5670. local = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (local_name));
  5671. SYMBOL_REF_FLAGS (local) = SYMBOL_REF_FLAGS (func) | SYMBOL_FLAG_LOCAL;
  5672. /* Create a new structure to represent the mapping. */
  5673. *slot = local;
  5674. }
  5675. return *slot;
  5676. }
  5677. /* A chained list of functions for which mips16_build_call_stub has already
  5678. generated a stub. NAME is the name of the function and FP_RET_P is true
  5679. if the function returns a value in floating-point registers. */
  5680. struct mips16_stub {
  5681. struct mips16_stub *next;
  5682. char *name;
  5683. bool fp_ret_p;
  5684. };
  5685. static struct mips16_stub *mips16_stubs;
  5686. /* Return the two-character string that identifies floating-point
  5687. return mode MODE in the name of a MIPS16 function stub. */
  5688. static const char *
  5689. mips16_call_stub_mode_suffix (machine_mode mode)
  5690. {
  5691. if (mode == SFmode)
  5692. return "sf";
  5693. else if (mode == DFmode)
  5694. return "df";
  5695. else if (mode == SCmode)
  5696. return "sc";
  5697. else if (mode == DCmode)
  5698. return "dc";
  5699. else if (mode == V2SFmode)
  5700. {
  5701. gcc_assert (TARGET_PAIRED_SINGLE_FLOAT);
  5702. return "df";
  5703. }
  5704. else
  5705. gcc_unreachable ();
  5706. }
  5707. /* Write instructions to move a 32-bit value between general register
  5708. GPREG and floating-point register FPREG. DIRECTION is 't' to move
  5709. from GPREG to FPREG and 'f' to move in the opposite direction. */
  5710. static void
  5711. mips_output_32bit_xfer (char direction, unsigned int gpreg, unsigned int fpreg)
  5712. {
  5713. fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
  5714. reg_names[gpreg], reg_names[fpreg]);
  5715. }
  5716. /* Likewise for 64-bit values. */
  5717. static void
  5718. mips_output_64bit_xfer (char direction, unsigned int gpreg, unsigned int fpreg)
  5719. {
  5720. if (TARGET_64BIT)
  5721. fprintf (asm_out_file, "\tdm%cc1\t%s,%s\n", direction,
  5722. reg_names[gpreg], reg_names[fpreg]);
  5723. else if (ISA_HAS_MXHC1)
  5724. {
  5725. fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
  5726. reg_names[gpreg + TARGET_BIG_ENDIAN], reg_names[fpreg]);
  5727. fprintf (asm_out_file, "\tm%chc1\t%s,%s\n", direction,
  5728. reg_names[gpreg + TARGET_LITTLE_ENDIAN], reg_names[fpreg]);
  5729. }
  5730. else if (TARGET_FLOATXX && direction == 't')
  5731. {
  5732. /* Use the argument save area to move via memory. */
  5733. fprintf (asm_out_file, "\tsw\t%s,0($sp)\n", reg_names[gpreg]);
  5734. fprintf (asm_out_file, "\tsw\t%s,4($sp)\n", reg_names[gpreg + 1]);
  5735. fprintf (asm_out_file, "\tldc1\t%s,0($sp)\n", reg_names[fpreg]);
  5736. }
  5737. else if (TARGET_FLOATXX && direction == 'f')
  5738. {
  5739. /* Use the argument save area to move via memory. */
  5740. fprintf (asm_out_file, "\tsdc1\t%s,0($sp)\n", reg_names[fpreg]);
  5741. fprintf (asm_out_file, "\tlw\t%s,0($sp)\n", reg_names[gpreg]);
  5742. fprintf (asm_out_file, "\tlw\t%s,4($sp)\n", reg_names[gpreg + 1]);
  5743. }
  5744. else
  5745. {
  5746. /* Move the least-significant word. */
  5747. fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
  5748. reg_names[gpreg + TARGET_BIG_ENDIAN], reg_names[fpreg]);
  5749. /* ...then the most significant word. */
  5750. fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
  5751. reg_names[gpreg + TARGET_LITTLE_ENDIAN], reg_names[fpreg + 1]);
  5752. }
  5753. }
  5754. /* Write out code to move floating-point arguments into or out of
  5755. general registers. FP_CODE is the code describing which arguments
  5756. are present (see the comment above the definition of CUMULATIVE_ARGS
  5757. in mips.h). DIRECTION is as for mips_output_32bit_xfer. */
  5758. static void
  5759. mips_output_args_xfer (int fp_code, char direction)
  5760. {
  5761. unsigned int gparg, fparg, f;
  5762. CUMULATIVE_ARGS cum;
  5763. /* This code only works for o32 and o64. */
  5764. gcc_assert (TARGET_OLDABI);
  5765. mips_init_cumulative_args (&cum, NULL);
  5766. for (f = (unsigned int) fp_code; f != 0; f >>= 2)
  5767. {
  5768. machine_mode mode;
  5769. struct mips_arg_info info;
  5770. if ((f & 3) == 1)
  5771. mode = SFmode;
  5772. else if ((f & 3) == 2)
  5773. mode = DFmode;
  5774. else
  5775. gcc_unreachable ();
  5776. mips_get_arg_info (&info, &cum, mode, NULL, true);
  5777. gparg = mips_arg_regno (&info, false);
  5778. fparg = mips_arg_regno (&info, true);
  5779. if (mode == SFmode)
  5780. mips_output_32bit_xfer (direction, gparg, fparg);
  5781. else
  5782. mips_output_64bit_xfer (direction, gparg, fparg);
  5783. mips_function_arg_advance (pack_cumulative_args (&cum), mode, NULL, true);
  5784. }
  5785. }
  5786. /* Write a MIPS16 stub for the current function. This stub is used
  5787. for functions which take arguments in the floating-point registers.
  5788. It is normal-mode code that moves the floating-point arguments
  5789. into the general registers and then jumps to the MIPS16 code. */
  5790. static void
  5791. mips16_build_function_stub (void)
  5792. {
  5793. const char *fnname, *alias_name, *separator;
  5794. char *secname, *stubname;
  5795. tree stubdecl;
  5796. unsigned int f;
  5797. rtx symbol, alias;
  5798. /* Create the name of the stub, and its unique section. */
  5799. symbol = XEXP (DECL_RTL (current_function_decl), 0);
  5800. alias = mips16_local_alias (symbol);
  5801. fnname = targetm.strip_name_encoding (XSTR (symbol, 0));
  5802. alias_name = targetm.strip_name_encoding (XSTR (alias, 0));
  5803. secname = ACONCAT ((".mips16.fn.", fnname, NULL));
  5804. stubname = ACONCAT (("__fn_stub_", fnname, NULL));
  5805. /* Build a decl for the stub. */
  5806. stubdecl = build_decl (BUILTINS_LOCATION,
  5807. FUNCTION_DECL, get_identifier (stubname),
  5808. build_function_type_list (void_type_node, NULL_TREE));
  5809. set_decl_section_name (stubdecl, secname);
  5810. DECL_RESULT (stubdecl) = build_decl (BUILTINS_LOCATION,
  5811. RESULT_DECL, NULL_TREE, void_type_node);
  5812. /* Output a comment. */
  5813. fprintf (asm_out_file, "\t# Stub function for %s (",
  5814. current_function_name ());
  5815. separator = "";
  5816. for (f = (unsigned int) crtl->args.info.fp_code; f != 0; f >>= 2)
  5817. {
  5818. fprintf (asm_out_file, "%s%s", separator,
  5819. (f & 3) == 1 ? "float" : "double");
  5820. separator = ", ";
  5821. }
  5822. fprintf (asm_out_file, ")\n");
  5823. /* Start the function definition. */
  5824. assemble_start_function (stubdecl, stubname);
  5825. mips_start_function_definition (stubname, false);
  5826. /* If generating pic2 code, either set up the global pointer or
  5827. switch to pic0. */
  5828. if (TARGET_ABICALLS_PIC2)
  5829. {
  5830. if (TARGET_ABSOLUTE_ABICALLS)
  5831. fprintf (asm_out_file, "\t.option\tpic0\n");
  5832. else
  5833. {
  5834. output_asm_insn ("%(.cpload\t%^%)", NULL);
  5835. /* Emit an R_MIPS_NONE relocation to tell the linker what the
  5836. target function is. Use a local GOT access when loading the
  5837. symbol, to cut down on the number of unnecessary GOT entries
  5838. for stubs that aren't needed. */
  5839. output_asm_insn (".reloc\t0,R_MIPS_NONE,%0", &symbol);
  5840. symbol = alias;
  5841. }
  5842. }
  5843. /* Load the address of the MIPS16 function into $25. Do this first so
  5844. that targets with coprocessor interlocks can use an MFC1 to fill the
  5845. delay slot. */
  5846. output_asm_insn ("la\t%^,%0", &symbol);
  5847. /* Move the arguments from floating-point registers to general registers. */
  5848. mips_output_args_xfer (crtl->args.info.fp_code, 'f');
  5849. /* Jump to the MIPS16 function. */
  5850. output_asm_insn ("jr\t%^", NULL);
  5851. if (TARGET_ABICALLS_PIC2 && TARGET_ABSOLUTE_ABICALLS)
  5852. fprintf (asm_out_file, "\t.option\tpic2\n");
  5853. mips_end_function_definition (stubname);
  5854. /* If the linker needs to create a dynamic symbol for the target
  5855. function, it will associate the symbol with the stub (which,
  5856. unlike the target function, follows the proper calling conventions).
  5857. It is therefore useful to have a local alias for the target function,
  5858. so that it can still be identified as MIPS16 code. As an optimization,
  5859. this symbol can also be used for indirect MIPS16 references from
  5860. within this file. */
  5861. ASM_OUTPUT_DEF (asm_out_file, alias_name, fnname);
  5862. switch_to_section (function_section (current_function_decl));
  5863. }
  5864. /* The current function is a MIPS16 function that returns a value in an FPR.
  5865. Copy the return value from its soft-float to its hard-float location.
  5866. libgcc2 has special non-MIPS16 helper functions for each case. */
  5867. static void
  5868. mips16_copy_fpr_return_value (void)
  5869. {
  5870. rtx fn, insn, retval;
  5871. tree return_type;
  5872. machine_mode return_mode;
  5873. const char *name;
  5874. return_type = DECL_RESULT (current_function_decl);
  5875. return_mode = DECL_MODE (return_type);
  5876. name = ACONCAT (("__mips16_ret_",
  5877. mips16_call_stub_mode_suffix (return_mode),
  5878. NULL));
  5879. fn = mips16_stub_function (name);
  5880. /* The function takes arguments in $2 (and possibly $3), so calls
  5881. to it cannot be lazily bound. */
  5882. SYMBOL_REF_FLAGS (fn) |= SYMBOL_FLAG_BIND_NOW;
  5883. /* Model the call as something that takes the GPR return value as
  5884. argument and returns an "updated" value. */
  5885. retval = gen_rtx_REG (return_mode, GP_RETURN);
  5886. insn = mips_expand_call (MIPS_CALL_EPILOGUE, retval, fn,
  5887. const0_rtx, NULL_RTX, false);
  5888. use_reg (&CALL_INSN_FUNCTION_USAGE (insn), retval);
  5889. }
  5890. /* Consider building a stub for a MIPS16 call to function *FN_PTR.
  5891. RETVAL is the location of the return value, or null if this is
  5892. a "call" rather than a "call_value". ARGS_SIZE is the size of the
  5893. arguments and FP_CODE is the code built by mips_function_arg;
  5894. see the comment before the fp_code field in CUMULATIVE_ARGS for details.
  5895. There are three alternatives:
  5896. - If a stub was needed, emit the call and return the call insn itself.
  5897. - If we can avoid using a stub by redirecting the call, set *FN_PTR
  5898. to the new target and return null.
  5899. - If *FN_PTR doesn't need a stub, return null and leave *FN_PTR
  5900. unmodified.
  5901. A stub is needed for calls to functions that, in normal mode,
  5902. receive arguments in FPRs or return values in FPRs. The stub
  5903. copies the arguments from their soft-float positions to their
  5904. hard-float positions, calls the real function, then copies the
  5905. return value from its hard-float position to its soft-float
  5906. position.
  5907. We can emit a JAL to *FN_PTR even when *FN_PTR might need a stub.
  5908. If *FN_PTR turns out to be to a non-MIPS16 function, the linker
  5909. automatically redirects the JAL to the stub, otherwise the JAL
  5910. continues to call FN directly. */
  5911. static rtx_insn *
  5912. mips16_build_call_stub (rtx retval, rtx *fn_ptr, rtx args_size, int fp_code)
  5913. {
  5914. const char *fnname;
  5915. bool fp_ret_p;
  5916. struct mips16_stub *l;
  5917. rtx_insn *insn;
  5918. rtx pattern, fn;
  5919. /* We don't need to do anything if we aren't in MIPS16 mode, or if
  5920. we were invoked with the -msoft-float option. */
  5921. if (!TARGET_MIPS16 || TARGET_SOFT_FLOAT_ABI)
  5922. return NULL;
  5923. /* Figure out whether the value might come back in a floating-point
  5924. register. */
  5925. fp_ret_p = retval && mips_return_mode_in_fpr_p (GET_MODE (retval));
  5926. /* We don't need to do anything if there were no floating-point
  5927. arguments and the value will not be returned in a floating-point
  5928. register. */
  5929. if (fp_code == 0 && !fp_ret_p)
  5930. return NULL;
  5931. /* We don't need to do anything if this is a call to a special
  5932. MIPS16 support function. */
  5933. fn = *fn_ptr;
  5934. if (mips16_stub_function_p (fn))
  5935. return NULL;
  5936. /* If we're calling a locally-defined MIPS16 function, we know that
  5937. it will return values in both the "soft-float" and "hard-float"
  5938. registers. There is no need to use a stub to move the latter
  5939. to the former. */
  5940. if (fp_code == 0 && mips16_local_function_p (fn))
  5941. return NULL;
  5942. /* This code will only work for o32 and o64 abis. The other ABI's
  5943. require more sophisticated support. */
  5944. gcc_assert (TARGET_OLDABI);
  5945. /* If we're calling via a function pointer, use one of the magic
  5946. libgcc.a stubs provided for each (FP_CODE, FP_RET_P) combination.
  5947. Each stub expects the function address to arrive in register $2. */
  5948. if (GET_CODE (fn) != SYMBOL_REF
  5949. || !call_insn_operand (fn, VOIDmode))
  5950. {
  5951. char buf[30];
  5952. rtx stub_fn, addr;
  5953. rtx_insn *insn;
  5954. bool lazy_p;
  5955. /* If this is a locally-defined and locally-binding function,
  5956. avoid the stub by calling the local alias directly. */
  5957. if (mips16_local_function_p (fn))
  5958. {
  5959. *fn_ptr = mips16_local_alias (fn);
  5960. return NULL;
  5961. }
  5962. /* Create a SYMBOL_REF for the libgcc.a function. */
  5963. if (fp_ret_p)
  5964. sprintf (buf, "__mips16_call_stub_%s_%d",
  5965. mips16_call_stub_mode_suffix (GET_MODE (retval)),
  5966. fp_code);
  5967. else
  5968. sprintf (buf, "__mips16_call_stub_%d", fp_code);
  5969. stub_fn = mips16_stub_function (buf);
  5970. /* The function uses $2 as an argument, so calls to it
  5971. cannot be lazily bound. */
  5972. SYMBOL_REF_FLAGS (stub_fn) |= SYMBOL_FLAG_BIND_NOW;
  5973. /* Load the target function into $2. */
  5974. addr = gen_rtx_REG (Pmode, GP_REG_FIRST + 2);
  5975. lazy_p = mips_load_call_address (MIPS_CALL_NORMAL, addr, fn);
  5976. /* Emit the call. */
  5977. insn = mips_expand_call (MIPS_CALL_NORMAL, retval, stub_fn,
  5978. args_size, NULL_RTX, lazy_p);
  5979. /* Tell GCC that this call does indeed use the value of $2. */
  5980. use_reg (&CALL_INSN_FUNCTION_USAGE (insn), addr);
  5981. /* If we are handling a floating-point return value, we need to
  5982. save $18 in the function prologue. Putting a note on the
  5983. call will mean that df_regs_ever_live_p ($18) will be true if the
  5984. call is not eliminated, and we can check that in the prologue
  5985. code. */
  5986. if (fp_ret_p)
  5987. CALL_INSN_FUNCTION_USAGE (insn) =
  5988. gen_rtx_EXPR_LIST (VOIDmode,
  5989. gen_rtx_CLOBBER (VOIDmode,
  5990. gen_rtx_REG (word_mode, 18)),
  5991. CALL_INSN_FUNCTION_USAGE (insn));
  5992. return insn;
  5993. }
  5994. /* We know the function we are going to call. If we have already
  5995. built a stub, we don't need to do anything further. */
  5996. fnname = targetm.strip_name_encoding (XSTR (fn, 0));
  5997. for (l = mips16_stubs; l != NULL; l = l->next)
  5998. if (strcmp (l->name, fnname) == 0)
  5999. break;
  6000. if (l == NULL)
  6001. {
  6002. const char *separator;
  6003. char *secname, *stubname;
  6004. tree stubid, stubdecl;
  6005. unsigned int f;
  6006. /* If the function does not return in FPRs, the special stub
  6007. section is named
  6008. .mips16.call.FNNAME
  6009. If the function does return in FPRs, the stub section is named
  6010. .mips16.call.fp.FNNAME
  6011. Build a decl for the stub. */
  6012. secname = ACONCAT ((".mips16.call.", fp_ret_p ? "fp." : "",
  6013. fnname, NULL));
  6014. stubname = ACONCAT (("__call_stub_", fp_ret_p ? "fp_" : "",
  6015. fnname, NULL));
  6016. stubid = get_identifier (stubname);
  6017. stubdecl = build_decl (BUILTINS_LOCATION,
  6018. FUNCTION_DECL, stubid,
  6019. build_function_type_list (void_type_node,
  6020. NULL_TREE));
  6021. set_decl_section_name (stubdecl, secname);
  6022. DECL_RESULT (stubdecl) = build_decl (BUILTINS_LOCATION,
  6023. RESULT_DECL, NULL_TREE,
  6024. void_type_node);
  6025. /* Output a comment. */
  6026. fprintf (asm_out_file, "\t# Stub function to call %s%s (",
  6027. (fp_ret_p
  6028. ? (GET_MODE (retval) == SFmode ? "float " : "double ")
  6029. : ""),
  6030. fnname);
  6031. separator = "";
  6032. for (f = (unsigned int) fp_code; f != 0; f >>= 2)
  6033. {
  6034. fprintf (asm_out_file, "%s%s", separator,
  6035. (f & 3) == 1 ? "float" : "double");
  6036. separator = ", ";
  6037. }
  6038. fprintf (asm_out_file, ")\n");
  6039. /* Start the function definition. */
  6040. assemble_start_function (stubdecl, stubname);
  6041. mips_start_function_definition (stubname, false);
  6042. if (fp_ret_p)
  6043. {
  6044. fprintf (asm_out_file, "\t.cfi_startproc\n");
  6045. /* Create a fake CFA 4 bytes below the stack pointer.
  6046. This works around unwinders (like libgcc's) that expect
  6047. the CFA for non-signal frames to be unique. */
  6048. fprintf (asm_out_file, "\t.cfi_def_cfa 29,-4\n");
  6049. /* "Save" $sp in itself so we don't use the fake CFA.
  6050. This is: DW_CFA_val_expression r29, { DW_OP_reg29 }. */
  6051. fprintf (asm_out_file, "\t.cfi_escape 0x16,29,1,0x6d\n");
  6052. /* Save the return address in $18. The stub's caller knows
  6053. that $18 might be clobbered, even though $18 is usually
  6054. a call-saved register.
  6055. Do it early on in case the last move to a floating-point
  6056. register can be scheduled into the delay slot of the
  6057. call we are about to make. */
  6058. fprintf (asm_out_file, "\tmove\t%s,%s\n",
  6059. reg_names[GP_REG_FIRST + 18],
  6060. reg_names[RETURN_ADDR_REGNUM]);
  6061. }
  6062. else
  6063. {
  6064. /* Load the address of the MIPS16 function into $25. Do this
  6065. first so that targets with coprocessor interlocks can use
  6066. an MFC1 to fill the delay slot. */
  6067. if (TARGET_EXPLICIT_RELOCS)
  6068. {
  6069. output_asm_insn ("lui\t%^,%%hi(%0)", &fn);
  6070. output_asm_insn ("addiu\t%^,%^,%%lo(%0)", &fn);
  6071. }
  6072. else
  6073. output_asm_insn ("la\t%^,%0", &fn);
  6074. }
  6075. /* Move the arguments from general registers to floating-point
  6076. registers. */
  6077. mips_output_args_xfer (fp_code, 't');
  6078. if (fp_ret_p)
  6079. {
  6080. /* Now call the non-MIPS16 function. */
  6081. output_asm_insn (MIPS_CALL ("jal", &fn, 0, -1), &fn);
  6082. fprintf (asm_out_file, "\t.cfi_register 31,18\n");
  6083. /* Move the result from floating-point registers to
  6084. general registers. */
  6085. switch (GET_MODE (retval))
  6086. {
  6087. case SCmode:
  6088. mips_output_32bit_xfer ('f', GP_RETURN + TARGET_BIG_ENDIAN,
  6089. TARGET_BIG_ENDIAN
  6090. ? FP_REG_FIRST + 2
  6091. : FP_REG_FIRST);
  6092. mips_output_32bit_xfer ('f', GP_RETURN + TARGET_LITTLE_ENDIAN,
  6093. TARGET_LITTLE_ENDIAN
  6094. ? FP_REG_FIRST + 2
  6095. : FP_REG_FIRST);
  6096. if (GET_MODE (retval) == SCmode && TARGET_64BIT)
  6097. {
  6098. /* On 64-bit targets, complex floats are returned in
  6099. a single GPR, such that "sd" on a suitably-aligned
  6100. target would store the value correctly. */
  6101. fprintf (asm_out_file, "\tdsll\t%s,%s,32\n",
  6102. reg_names[GP_RETURN + TARGET_BIG_ENDIAN],
  6103. reg_names[GP_RETURN + TARGET_BIG_ENDIAN]);
  6104. fprintf (asm_out_file, "\tdsll\t%s,%s,32\n",
  6105. reg_names[GP_RETURN + TARGET_LITTLE_ENDIAN],
  6106. reg_names[GP_RETURN + TARGET_LITTLE_ENDIAN]);
  6107. fprintf (asm_out_file, "\tdsrl\t%s,%s,32\n",
  6108. reg_names[GP_RETURN + TARGET_BIG_ENDIAN],
  6109. reg_names[GP_RETURN + TARGET_BIG_ENDIAN]);
  6110. fprintf (asm_out_file, "\tor\t%s,%s,%s\n",
  6111. reg_names[GP_RETURN],
  6112. reg_names[GP_RETURN],
  6113. reg_names[GP_RETURN + 1]);
  6114. }
  6115. break;
  6116. case SFmode:
  6117. mips_output_32bit_xfer ('f', GP_RETURN, FP_REG_FIRST);
  6118. break;
  6119. case DCmode:
  6120. mips_output_64bit_xfer ('f', GP_RETURN + (8 / UNITS_PER_WORD),
  6121. FP_REG_FIRST + 2);
  6122. /* Fall though. */
  6123. case DFmode:
  6124. case V2SFmode:
  6125. gcc_assert (TARGET_PAIRED_SINGLE_FLOAT
  6126. || GET_MODE (retval) != V2SFmode);
  6127. mips_output_64bit_xfer ('f', GP_RETURN, FP_REG_FIRST);
  6128. break;
  6129. default:
  6130. gcc_unreachable ();
  6131. }
  6132. fprintf (asm_out_file, "\tjr\t%s\n", reg_names[GP_REG_FIRST + 18]);
  6133. fprintf (asm_out_file, "\t.cfi_endproc\n");
  6134. }
  6135. else
  6136. {
  6137. /* Jump to the previously-loaded address. */
  6138. output_asm_insn ("jr\t%^", NULL);
  6139. }
  6140. #ifdef ASM_DECLARE_FUNCTION_SIZE
  6141. ASM_DECLARE_FUNCTION_SIZE (asm_out_file, stubname, stubdecl);
  6142. #endif
  6143. mips_end_function_definition (stubname);
  6144. /* Record this stub. */
  6145. l = XNEW (struct mips16_stub);
  6146. l->name = xstrdup (fnname);
  6147. l->fp_ret_p = fp_ret_p;
  6148. l->next = mips16_stubs;
  6149. mips16_stubs = l;
  6150. }
  6151. /* If we expect a floating-point return value, but we've built a
  6152. stub which does not expect one, then we're in trouble. We can't
  6153. use the existing stub, because it won't handle the floating-point
  6154. value. We can't build a new stub, because the linker won't know
  6155. which stub to use for the various calls in this object file.
  6156. Fortunately, this case is illegal, since it means that a function
  6157. was declared in two different ways in a single compilation. */
  6158. if (fp_ret_p && !l->fp_ret_p)
  6159. error ("cannot handle inconsistent calls to %qs", fnname);
  6160. if (retval == NULL_RTX)
  6161. pattern = gen_call_internal_direct (fn, args_size);
  6162. else
  6163. pattern = gen_call_value_internal_direct (retval, fn, args_size);
  6164. insn = mips_emit_call_insn (pattern, fn, fn, false);
  6165. /* If we are calling a stub which handles a floating-point return
  6166. value, we need to arrange to save $18 in the prologue. We do this
  6167. by marking the function call as using the register. The prologue
  6168. will later see that it is used, and emit code to save it. */
  6169. if (fp_ret_p)
  6170. CALL_INSN_FUNCTION_USAGE (insn) =
  6171. gen_rtx_EXPR_LIST (VOIDmode,
  6172. gen_rtx_CLOBBER (VOIDmode,
  6173. gen_rtx_REG (word_mode, 18)),
  6174. CALL_INSN_FUNCTION_USAGE (insn));
  6175. return insn;
  6176. }
  6177. /* Expand a call of type TYPE. RESULT is where the result will go (null
  6178. for "call"s and "sibcall"s), ADDR is the address of the function,
  6179. ARGS_SIZE is the size of the arguments and AUX is the value passed
  6180. to us by mips_function_arg. LAZY_P is true if this call already
  6181. involves a lazily-bound function address (such as when calling
  6182. functions through a MIPS16 hard-float stub).
  6183. Return the call itself. */
  6184. rtx_insn *
  6185. mips_expand_call (enum mips_call_type type, rtx result, rtx addr,
  6186. rtx args_size, rtx aux, bool lazy_p)
  6187. {
  6188. rtx orig_addr, pattern;
  6189. rtx_insn *insn;
  6190. int fp_code;
  6191. fp_code = aux == 0 ? 0 : (int) GET_MODE (aux);
  6192. insn = mips16_build_call_stub (result, &addr, args_size, fp_code);
  6193. if (insn)
  6194. {
  6195. gcc_assert (!lazy_p && type == MIPS_CALL_NORMAL);
  6196. return insn;
  6197. }
  6198. orig_addr = addr;
  6199. if (!call_insn_operand (addr, VOIDmode))
  6200. {
  6201. if (type == MIPS_CALL_EPILOGUE)
  6202. addr = MIPS_EPILOGUE_TEMP (Pmode);
  6203. else
  6204. addr = gen_reg_rtx (Pmode);
  6205. lazy_p |= mips_load_call_address (type, addr, orig_addr);
  6206. }
  6207. if (result == 0)
  6208. {
  6209. rtx (*fn) (rtx, rtx);
  6210. if (type == MIPS_CALL_SIBCALL)
  6211. fn = gen_sibcall_internal;
  6212. else
  6213. fn = gen_call_internal;
  6214. pattern = fn (addr, args_size);
  6215. }
  6216. else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2)
  6217. {
  6218. /* Handle return values created by mips_return_fpr_pair. */
  6219. rtx (*fn) (rtx, rtx, rtx, rtx);
  6220. rtx reg1, reg2;
  6221. if (type == MIPS_CALL_SIBCALL)
  6222. fn = gen_sibcall_value_multiple_internal;
  6223. else
  6224. fn = gen_call_value_multiple_internal;
  6225. reg1 = XEXP (XVECEXP (result, 0, 0), 0);
  6226. reg2 = XEXP (XVECEXP (result, 0, 1), 0);
  6227. pattern = fn (reg1, addr, args_size, reg2);
  6228. }
  6229. else
  6230. {
  6231. rtx (*fn) (rtx, rtx, rtx);
  6232. if (type == MIPS_CALL_SIBCALL)
  6233. fn = gen_sibcall_value_internal;
  6234. else
  6235. fn = gen_call_value_internal;
  6236. /* Handle return values created by mips_return_fpr_single. */
  6237. if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 1)
  6238. result = XEXP (XVECEXP (result, 0, 0), 0);
  6239. pattern = fn (result, addr, args_size);
  6240. }
  6241. return mips_emit_call_insn (pattern, orig_addr, addr, lazy_p);
  6242. }
  6243. /* Split call instruction INSN into a $gp-clobbering call and
  6244. (where necessary) an instruction to restore $gp from its save slot.
  6245. CALL_PATTERN is the pattern of the new call. */
  6246. void
  6247. mips_split_call (rtx insn, rtx call_pattern)
  6248. {
  6249. emit_call_insn (call_pattern);
  6250. if (!find_reg_note (insn, REG_NORETURN, 0))
  6251. mips_restore_gp_from_cprestore_slot (gen_rtx_REG (Pmode,
  6252. POST_CALL_TMP_REG));
  6253. }
  6254. /* Return true if a call to DECL may need to use JALX. */
  6255. static bool
  6256. mips_call_may_need_jalx_p (tree decl)
  6257. {
  6258. /* If the current translation unit would use a different mode for DECL,
  6259. assume that the call needs JALX. */
  6260. if (mips_get_compress_mode (decl) != TARGET_COMPRESSION)
  6261. return true;
  6262. /* mips_get_compress_mode is always accurate for locally-binding
  6263. functions in the current translation unit. */
  6264. if (!DECL_EXTERNAL (decl) && targetm.binds_local_p (decl))
  6265. return false;
  6266. /* When -minterlink-compressed is in effect, assume that functions
  6267. could use a different encoding mode unless an attribute explicitly
  6268. tells us otherwise. */
  6269. if (TARGET_INTERLINK_COMPRESSED)
  6270. {
  6271. if (!TARGET_COMPRESSION
  6272. && mips_get_compress_off_flags (DECL_ATTRIBUTES (decl)) ==0)
  6273. return true;
  6274. if (TARGET_COMPRESSION
  6275. && mips_get_compress_on_flags (DECL_ATTRIBUTES (decl)) == 0)
  6276. return true;
  6277. }
  6278. return false;
  6279. }
  6280. /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL. */
  6281. static bool
  6282. mips_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
  6283. {
  6284. if (!TARGET_SIBCALLS)
  6285. return false;
  6286. /* Interrupt handlers need special epilogue code and therefore can't
  6287. use sibcalls. */
  6288. if (mips_interrupt_type_p (TREE_TYPE (current_function_decl)))
  6289. return false;
  6290. /* Direct Js are only possible to functions that use the same ISA encoding.
  6291. There is no JX counterpoart of JALX. */
  6292. if (decl
  6293. && const_call_insn_operand (XEXP (DECL_RTL (decl), 0), VOIDmode)
  6294. && mips_call_may_need_jalx_p (decl))
  6295. return false;
  6296. /* Sibling calls should not prevent lazy binding. Lazy-binding stubs
  6297. require $gp to be valid on entry, so sibcalls can only use stubs
  6298. if $gp is call-clobbered. */
  6299. if (decl
  6300. && TARGET_CALL_SAVED_GP
  6301. && !TARGET_ABICALLS_PIC0
  6302. && !targetm.binds_local_p (decl))
  6303. return false;
  6304. /* Otherwise OK. */
  6305. return true;
  6306. }
  6307. /* Implement TARGET_USE_MOVE_BY_PIECES_INFRASTRUCTURE_P. */
  6308. bool
  6309. mips_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size,
  6310. unsigned int align,
  6311. enum by_pieces_operation op,
  6312. bool speed_p)
  6313. {
  6314. if (op == STORE_BY_PIECES)
  6315. return mips_store_by_pieces_p (size, align);
  6316. if (op == MOVE_BY_PIECES && HAVE_movmemsi)
  6317. {
  6318. /* movmemsi is meant to generate code that is at least as good as
  6319. move_by_pieces. However, movmemsi effectively uses a by-pieces
  6320. implementation both for moves smaller than a word and for
  6321. word-aligned moves of no more than MIPS_MAX_MOVE_BYTES_STRAIGHT
  6322. bytes. We should allow the tree-level optimisers to do such
  6323. moves by pieces, as it often exposes other optimization
  6324. opportunities. We might as well continue to use movmemsi at
  6325. the rtl level though, as it produces better code when
  6326. scheduling is disabled (such as at -O). */
  6327. if (currently_expanding_to_rtl)
  6328. return false;
  6329. if (align < BITS_PER_WORD)
  6330. return size < UNITS_PER_WORD;
  6331. return size <= MIPS_MAX_MOVE_BYTES_STRAIGHT;
  6332. }
  6333. return default_use_by_pieces_infrastructure_p (size, align, op, speed_p);
  6334. }
  6335. /* Implement a handler for STORE_BY_PIECES operations
  6336. for TARGET_USE_MOVE_BY_PIECES_INFRASTRUCTURE_P. */
  6337. bool
  6338. mips_store_by_pieces_p (unsigned HOST_WIDE_INT size, unsigned int align)
  6339. {
  6340. /* Storing by pieces involves moving constants into registers
  6341. of size MIN (ALIGN, BITS_PER_WORD), then storing them.
  6342. We need to decide whether it is cheaper to load the address of
  6343. constant data into a register and use a block move instead. */
  6344. /* If the data is only byte aligned, then:
  6345. (a1) A block move of less than 4 bytes would involve three 3 LBs and
  6346. 3 SBs. We might as well use 3 single-instruction LIs and 3 SBs
  6347. instead.
  6348. (a2) A block move of 4 bytes from aligned source data can use an
  6349. LW/SWL/SWR sequence. This is often better than the 4 LIs and
  6350. 4 SBs that we would generate when storing by pieces. */
  6351. if (align <= BITS_PER_UNIT)
  6352. return size < 4;
  6353. /* If the data is 2-byte aligned, then:
  6354. (b1) A block move of less than 4 bytes would use a combination of LBs,
  6355. LHs, SBs and SHs. We get better code by using single-instruction
  6356. LIs, SBs and SHs instead.
  6357. (b2) A block move of 4 bytes from aligned source data would again use
  6358. an LW/SWL/SWR sequence. In most cases, loading the address of
  6359. the source data would require at least one extra instruction.
  6360. It is often more efficient to use 2 single-instruction LIs and
  6361. 2 SHs instead.
  6362. (b3) A block move of up to 3 additional bytes would be like (b1).
  6363. (b4) A block move of 8 bytes from aligned source data can use two
  6364. LW/SWL/SWR sequences or a single LD/SDL/SDR sequence. Both
  6365. sequences are better than the 4 LIs and 4 SHs that we'd generate
  6366. when storing by pieces.
  6367. The reasoning for higher alignments is similar:
  6368. (c1) A block move of less than 4 bytes would be the same as (b1).
  6369. (c2) A block move of 4 bytes would use an LW/SW sequence. Again,
  6370. loading the address of the source data would typically require
  6371. at least one extra instruction. It is generally better to use
  6372. LUI/ORI/SW instead.
  6373. (c3) A block move of up to 3 additional bytes would be like (b1).
  6374. (c4) A block move of 8 bytes can use two LW/SW sequences or a single
  6375. LD/SD sequence, and in these cases we've traditionally preferred
  6376. the memory copy over the more bulky constant moves. */
  6377. return size < 8;
  6378. }
  6379. /* Emit straight-line code to move LENGTH bytes from SRC to DEST.
  6380. Assume that the areas do not overlap. */
  6381. static void
  6382. mips_block_move_straight (rtx dest, rtx src, HOST_WIDE_INT length)
  6383. {
  6384. HOST_WIDE_INT offset, delta;
  6385. unsigned HOST_WIDE_INT bits;
  6386. int i;
  6387. machine_mode mode;
  6388. rtx *regs;
  6389. /* Work out how many bits to move at a time. If both operands have
  6390. half-word alignment, it is usually better to move in half words.
  6391. For instance, lh/lh/sh/sh is usually better than lwl/lwr/swl/swr
  6392. and lw/lw/sw/sw is usually better than ldl/ldr/sdl/sdr.
  6393. Otherwise move word-sized chunks. */
  6394. if (MEM_ALIGN (src) == BITS_PER_WORD / 2
  6395. && MEM_ALIGN (dest) == BITS_PER_WORD / 2)
  6396. bits = BITS_PER_WORD / 2;
  6397. else
  6398. bits = BITS_PER_WORD;
  6399. mode = mode_for_size (bits, MODE_INT, 0);
  6400. delta = bits / BITS_PER_UNIT;
  6401. /* Allocate a buffer for the temporary registers. */
  6402. regs = XALLOCAVEC (rtx, length / delta);
  6403. /* Load as many BITS-sized chunks as possible. Use a normal load if
  6404. the source has enough alignment, otherwise use left/right pairs. */
  6405. for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
  6406. {
  6407. regs[i] = gen_reg_rtx (mode);
  6408. if (MEM_ALIGN (src) >= bits)
  6409. mips_emit_move (regs[i], adjust_address (src, mode, offset));
  6410. else
  6411. {
  6412. rtx part = adjust_address (src, BLKmode, offset);
  6413. set_mem_size (part, delta);
  6414. if (!mips_expand_ext_as_unaligned_load (regs[i], part, bits, 0, 0))
  6415. gcc_unreachable ();
  6416. }
  6417. }
  6418. /* Copy the chunks to the destination. */
  6419. for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
  6420. if (MEM_ALIGN (dest) >= bits)
  6421. mips_emit_move (adjust_address (dest, mode, offset), regs[i]);
  6422. else
  6423. {
  6424. rtx part = adjust_address (dest, BLKmode, offset);
  6425. set_mem_size (part, delta);
  6426. if (!mips_expand_ins_as_unaligned_store (part, regs[i], bits, 0))
  6427. gcc_unreachable ();
  6428. }
  6429. /* Mop up any left-over bytes. */
  6430. if (offset < length)
  6431. {
  6432. src = adjust_address (src, BLKmode, offset);
  6433. dest = adjust_address (dest, BLKmode, offset);
  6434. move_by_pieces (dest, src, length - offset,
  6435. MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), 0);
  6436. }
  6437. }
  6438. /* Helper function for doing a loop-based block operation on memory
  6439. reference MEM. Each iteration of the loop will operate on LENGTH
  6440. bytes of MEM.
  6441. Create a new base register for use within the loop and point it to
  6442. the start of MEM. Create a new memory reference that uses this
  6443. register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
  6444. static void
  6445. mips_adjust_block_mem (rtx mem, HOST_WIDE_INT length,
  6446. rtx *loop_reg, rtx *loop_mem)
  6447. {
  6448. *loop_reg = copy_addr_to_reg (XEXP (mem, 0));
  6449. /* Although the new mem does not refer to a known location,
  6450. it does keep up to LENGTH bytes of alignment. */
  6451. *loop_mem = change_address (mem, BLKmode, *loop_reg);
  6452. set_mem_align (*loop_mem, MIN (MEM_ALIGN (mem), length * BITS_PER_UNIT));
  6453. }
  6454. /* Move LENGTH bytes from SRC to DEST using a loop that moves BYTES_PER_ITER
  6455. bytes at a time. LENGTH must be at least BYTES_PER_ITER. Assume that
  6456. the memory regions do not overlap. */
  6457. static void
  6458. mips_block_move_loop (rtx dest, rtx src, HOST_WIDE_INT length,
  6459. HOST_WIDE_INT bytes_per_iter)
  6460. {
  6461. rtx_code_label *label;
  6462. rtx src_reg, dest_reg, final_src, test;
  6463. HOST_WIDE_INT leftover;
  6464. leftover = length % bytes_per_iter;
  6465. length -= leftover;
  6466. /* Create registers and memory references for use within the loop. */
  6467. mips_adjust_block_mem (src, bytes_per_iter, &src_reg, &src);
  6468. mips_adjust_block_mem (dest, bytes_per_iter, &dest_reg, &dest);
  6469. /* Calculate the value that SRC_REG should have after the last iteration
  6470. of the loop. */
  6471. final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length),
  6472. 0, 0, OPTAB_WIDEN);
  6473. /* Emit the start of the loop. */
  6474. label = gen_label_rtx ();
  6475. emit_label (label);
  6476. /* Emit the loop body. */
  6477. mips_block_move_straight (dest, src, bytes_per_iter);
  6478. /* Move on to the next block. */
  6479. mips_emit_move (src_reg, plus_constant (Pmode, src_reg, bytes_per_iter));
  6480. mips_emit_move (dest_reg, plus_constant (Pmode, dest_reg, bytes_per_iter));
  6481. /* Emit the loop condition. */
  6482. test = gen_rtx_NE (VOIDmode, src_reg, final_src);
  6483. if (Pmode == DImode)
  6484. emit_jump_insn (gen_cbranchdi4 (test, src_reg, final_src, label));
  6485. else
  6486. emit_jump_insn (gen_cbranchsi4 (test, src_reg, final_src, label));
  6487. /* Mop up any left-over bytes. */
  6488. if (leftover)
  6489. mips_block_move_straight (dest, src, leftover);
  6490. }
  6491. /* Expand a movmemsi instruction, which copies LENGTH bytes from
  6492. memory reference SRC to memory reference DEST. */
  6493. bool
  6494. mips_expand_block_move (rtx dest, rtx src, rtx length)
  6495. {
  6496. /* Disable entirely for R6 initially. */
  6497. if (!ISA_HAS_LWL_LWR)
  6498. return false;
  6499. if (CONST_INT_P (length))
  6500. {
  6501. if (INTVAL (length) <= MIPS_MAX_MOVE_BYTES_STRAIGHT)
  6502. {
  6503. mips_block_move_straight (dest, src, INTVAL (length));
  6504. return true;
  6505. }
  6506. else if (optimize)
  6507. {
  6508. mips_block_move_loop (dest, src, INTVAL (length),
  6509. MIPS_MAX_MOVE_BYTES_PER_LOOP_ITER);
  6510. return true;
  6511. }
  6512. }
  6513. return false;
  6514. }
  6515. /* Expand a loop of synci insns for the address range [BEGIN, END). */
  6516. void
  6517. mips_expand_synci_loop (rtx begin, rtx end)
  6518. {
  6519. rtx inc, cmp_result, mask, length;
  6520. rtx_code_label *label, *end_label;
  6521. /* Create end_label. */
  6522. end_label = gen_label_rtx ();
  6523. /* Check if begin equals end. */
  6524. cmp_result = gen_rtx_EQ (VOIDmode, begin, end);
  6525. emit_jump_insn (gen_condjump (cmp_result, end_label));
  6526. /* Load INC with the cache line size (rdhwr INC,$1). */
  6527. inc = gen_reg_rtx (Pmode);
  6528. emit_insn (PMODE_INSN (gen_rdhwr_synci_step, (inc)));
  6529. /* Check if inc is 0. */
  6530. cmp_result = gen_rtx_EQ (VOIDmode, inc, const0_rtx);
  6531. emit_jump_insn (gen_condjump (cmp_result, end_label));
  6532. /* Calculate mask. */
  6533. mask = mips_force_unary (Pmode, NEG, inc);
  6534. /* Mask out begin by mask. */
  6535. begin = mips_force_binary (Pmode, AND, begin, mask);
  6536. /* Calculate length. */
  6537. length = mips_force_binary (Pmode, MINUS, end, begin);
  6538. /* Loop back to here. */
  6539. label = gen_label_rtx ();
  6540. emit_label (label);
  6541. emit_insn (gen_synci (begin));
  6542. /* Update length. */
  6543. mips_emit_binary (MINUS, length, length, inc);
  6544. /* Update begin. */
  6545. mips_emit_binary (PLUS, begin, begin, inc);
  6546. /* Check if length is greater than 0. */
  6547. cmp_result = gen_rtx_GT (VOIDmode, length, const0_rtx);
  6548. emit_jump_insn (gen_condjump (cmp_result, label));
  6549. emit_label (end_label);
  6550. }
  6551. /* Expand a QI or HI mode atomic memory operation.
  6552. GENERATOR contains a pointer to the gen_* function that generates
  6553. the SI mode underlying atomic operation using masks that we
  6554. calculate.
  6555. RESULT is the return register for the operation. Its value is NULL
  6556. if unused.
  6557. MEM is the location of the atomic access.
  6558. OLDVAL is the first operand for the operation.
  6559. NEWVAL is the optional second operand for the operation. Its value
  6560. is NULL if unused. */
  6561. void
  6562. mips_expand_atomic_qihi (union mips_gen_fn_ptrs generator,
  6563. rtx result, rtx mem, rtx oldval, rtx newval)
  6564. {
  6565. rtx orig_addr, memsi_addr, memsi, shift, shiftsi, unshifted_mask;
  6566. rtx unshifted_mask_reg, mask, inverted_mask, si_op;
  6567. rtx res = NULL;
  6568. machine_mode mode;
  6569. mode = GET_MODE (mem);
  6570. /* Compute the address of the containing SImode value. */
  6571. orig_addr = force_reg (Pmode, XEXP (mem, 0));
  6572. memsi_addr = mips_force_binary (Pmode, AND, orig_addr,
  6573. force_reg (Pmode, GEN_INT (-4)));
  6574. /* Create a memory reference for it. */
  6575. memsi = gen_rtx_MEM (SImode, memsi_addr);
  6576. set_mem_alias_set (memsi, ALIAS_SET_MEMORY_BARRIER);
  6577. MEM_VOLATILE_P (memsi) = MEM_VOLATILE_P (mem);
  6578. /* Work out the byte offset of the QImode or HImode value,
  6579. counting from the least significant byte. */
  6580. shift = mips_force_binary (Pmode, AND, orig_addr, GEN_INT (3));
  6581. if (TARGET_BIG_ENDIAN)
  6582. mips_emit_binary (XOR, shift, shift, GEN_INT (mode == QImode ? 3 : 2));
  6583. /* Multiply by eight to convert the shift value from bytes to bits. */
  6584. mips_emit_binary (ASHIFT, shift, shift, GEN_INT (3));
  6585. /* Make the final shift an SImode value, so that it can be used in
  6586. SImode operations. */
  6587. shiftsi = force_reg (SImode, gen_lowpart (SImode, shift));
  6588. /* Set MASK to an inclusive mask of the QImode or HImode value. */
  6589. unshifted_mask = GEN_INT (GET_MODE_MASK (mode));
  6590. unshifted_mask_reg = force_reg (SImode, unshifted_mask);
  6591. mask = mips_force_binary (SImode, ASHIFT, unshifted_mask_reg, shiftsi);
  6592. /* Compute the equivalent exclusive mask. */
  6593. inverted_mask = gen_reg_rtx (SImode);
  6594. emit_insn (gen_rtx_SET (VOIDmode, inverted_mask,
  6595. gen_rtx_NOT (SImode, mask)));
  6596. /* Shift the old value into place. */
  6597. if (oldval != const0_rtx)
  6598. {
  6599. oldval = convert_modes (SImode, mode, oldval, true);
  6600. oldval = force_reg (SImode, oldval);
  6601. oldval = mips_force_binary (SImode, ASHIFT, oldval, shiftsi);
  6602. }
  6603. /* Do the same for the new value. */
  6604. if (newval && newval != const0_rtx)
  6605. {
  6606. newval = convert_modes (SImode, mode, newval, true);
  6607. newval = force_reg (SImode, newval);
  6608. newval = mips_force_binary (SImode, ASHIFT, newval, shiftsi);
  6609. }
  6610. /* Do the SImode atomic access. */
  6611. if (result)
  6612. res = gen_reg_rtx (SImode);
  6613. if (newval)
  6614. si_op = generator.fn_6 (res, memsi, mask, inverted_mask, oldval, newval);
  6615. else if (result)
  6616. si_op = generator.fn_5 (res, memsi, mask, inverted_mask, oldval);
  6617. else
  6618. si_op = generator.fn_4 (memsi, mask, inverted_mask, oldval);
  6619. emit_insn (si_op);
  6620. if (result)
  6621. {
  6622. /* Shift and convert the result. */
  6623. mips_emit_binary (AND, res, res, mask);
  6624. mips_emit_binary (LSHIFTRT, res, res, shiftsi);
  6625. mips_emit_move (result, gen_lowpart (GET_MODE (result), res));
  6626. }
  6627. }
  6628. /* Return true if it is possible to use left/right accesses for a
  6629. bitfield of WIDTH bits starting BITPOS bits into BLKmode memory OP.
  6630. When returning true, update *LEFT and *RIGHT as follows:
  6631. *LEFT is a QImode reference to the first byte if big endian or
  6632. the last byte if little endian. This address can be used in the
  6633. left-side instructions (LWL, SWL, LDL, SDL).
  6634. *RIGHT is a QImode reference to the opposite end of the field and
  6635. can be used in the patterning right-side instruction. */
  6636. static bool
  6637. mips_get_unaligned_mem (rtx op, HOST_WIDE_INT width, HOST_WIDE_INT bitpos,
  6638. rtx *left, rtx *right)
  6639. {
  6640. rtx first, last;
  6641. /* Check that the size is valid. */
  6642. if (width != 32 && (!TARGET_64BIT || width != 64))
  6643. return false;
  6644. /* We can only access byte-aligned values. Since we are always passed
  6645. a reference to the first byte of the field, it is not necessary to
  6646. do anything with BITPOS after this check. */
  6647. if (bitpos % BITS_PER_UNIT != 0)
  6648. return false;
  6649. /* Reject aligned bitfields: we want to use a normal load or store
  6650. instead of a left/right pair. */
  6651. if (MEM_ALIGN (op) >= width)
  6652. return false;
  6653. /* Get references to both ends of the field. */
  6654. first = adjust_address (op, QImode, 0);
  6655. last = adjust_address (op, QImode, width / BITS_PER_UNIT - 1);
  6656. /* Allocate to LEFT and RIGHT according to endianness. LEFT should
  6657. correspond to the MSB and RIGHT to the LSB. */
  6658. if (TARGET_BIG_ENDIAN)
  6659. *left = first, *right = last;
  6660. else
  6661. *left = last, *right = first;
  6662. return true;
  6663. }
  6664. /* Try to use left/right loads to expand an "extv" or "extzv" pattern.
  6665. DEST, SRC, WIDTH and BITPOS are the operands passed to the expander;
  6666. the operation is the equivalent of:
  6667. (set DEST (*_extract SRC WIDTH BITPOS))
  6668. Return true on success. */
  6669. bool
  6670. mips_expand_ext_as_unaligned_load (rtx dest, rtx src, HOST_WIDE_INT width,
  6671. HOST_WIDE_INT bitpos, bool unsigned_p)
  6672. {
  6673. rtx left, right, temp;
  6674. rtx dest1 = NULL_RTX;
  6675. /* If TARGET_64BIT, the destination of a 32-bit "extz" or "extzv" will
  6676. be a DImode, create a new temp and emit a zero extend at the end. */
  6677. if (GET_MODE (dest) == DImode
  6678. && REG_P (dest)
  6679. && GET_MODE_BITSIZE (SImode) == width)
  6680. {
  6681. dest1 = dest;
  6682. dest = gen_reg_rtx (SImode);
  6683. }
  6684. if (!mips_get_unaligned_mem (src, width, bitpos, &left, &right))
  6685. return false;
  6686. temp = gen_reg_rtx (GET_MODE (dest));
  6687. if (GET_MODE (dest) == DImode)
  6688. {
  6689. emit_insn (gen_mov_ldl (temp, src, left));
  6690. emit_insn (gen_mov_ldr (dest, copy_rtx (src), right, temp));
  6691. }
  6692. else
  6693. {
  6694. emit_insn (gen_mov_lwl (temp, src, left));
  6695. emit_insn (gen_mov_lwr (dest, copy_rtx (src), right, temp));
  6696. }
  6697. /* If we were loading 32bits and the original register was DI then
  6698. sign/zero extend into the orignal dest. */
  6699. if (dest1)
  6700. {
  6701. if (unsigned_p)
  6702. emit_insn (gen_zero_extendsidi2 (dest1, dest));
  6703. else
  6704. emit_insn (gen_extendsidi2 (dest1, dest));
  6705. }
  6706. return true;
  6707. }
  6708. /* Try to use left/right stores to expand an "ins" pattern. DEST, WIDTH,
  6709. BITPOS and SRC are the operands passed to the expander; the operation
  6710. is the equivalent of:
  6711. (set (zero_extract DEST WIDTH BITPOS) SRC)
  6712. Return true on success. */
  6713. bool
  6714. mips_expand_ins_as_unaligned_store (rtx dest, rtx src, HOST_WIDE_INT width,
  6715. HOST_WIDE_INT bitpos)
  6716. {
  6717. rtx left, right;
  6718. machine_mode mode;
  6719. if (!mips_get_unaligned_mem (dest, width, bitpos, &left, &right))
  6720. return false;
  6721. mode = mode_for_size (width, MODE_INT, 0);
  6722. src = gen_lowpart (mode, src);
  6723. if (mode == DImode)
  6724. {
  6725. emit_insn (gen_mov_sdl (dest, src, left));
  6726. emit_insn (gen_mov_sdr (copy_rtx (dest), copy_rtx (src), right));
  6727. }
  6728. else
  6729. {
  6730. emit_insn (gen_mov_swl (dest, src, left));
  6731. emit_insn (gen_mov_swr (copy_rtx (dest), copy_rtx (src), right));
  6732. }
  6733. return true;
  6734. }
  6735. /* Return true if X is a MEM with the same size as MODE. */
  6736. bool
  6737. mips_mem_fits_mode_p (machine_mode mode, rtx x)
  6738. {
  6739. return (MEM_P (x)
  6740. && MEM_SIZE_KNOWN_P (x)
  6741. && MEM_SIZE (x) == GET_MODE_SIZE (mode));
  6742. }
  6743. /* Return true if (zero_extract OP WIDTH BITPOS) can be used as the
  6744. source of an "ext" instruction or the destination of an "ins"
  6745. instruction. OP must be a register operand and the following
  6746. conditions must hold:
  6747. 0 <= BITPOS < GET_MODE_BITSIZE (GET_MODE (op))
  6748. 0 < WIDTH <= GET_MODE_BITSIZE (GET_MODE (op))
  6749. 0 < BITPOS + WIDTH <= GET_MODE_BITSIZE (GET_MODE (op))
  6750. Also reject lengths equal to a word as they are better handled
  6751. by the move patterns. */
  6752. bool
  6753. mips_use_ins_ext_p (rtx op, HOST_WIDE_INT width, HOST_WIDE_INT bitpos)
  6754. {
  6755. if (!ISA_HAS_EXT_INS
  6756. || !register_operand (op, VOIDmode)
  6757. || GET_MODE_BITSIZE (GET_MODE (op)) > BITS_PER_WORD)
  6758. return false;
  6759. if (!IN_RANGE (width, 1, GET_MODE_BITSIZE (GET_MODE (op)) - 1))
  6760. return false;
  6761. if (bitpos < 0 || bitpos + width > GET_MODE_BITSIZE (GET_MODE (op)))
  6762. return false;
  6763. return true;
  6764. }
  6765. /* Check if MASK and SHIFT are valid in mask-low-and-shift-left
  6766. operation if MAXLEN is the maxium length of consecutive bits that
  6767. can make up MASK. MODE is the mode of the operation. See
  6768. mask_low_and_shift_len for the actual definition. */
  6769. bool
  6770. mask_low_and_shift_p (machine_mode mode, rtx mask, rtx shift, int maxlen)
  6771. {
  6772. return IN_RANGE (mask_low_and_shift_len (mode, mask, shift), 1, maxlen);
  6773. }
  6774. /* Return true iff OP1 and OP2 are valid operands together for the
  6775. *and<MODE>3 and *and<MODE>3_mips16 patterns. For the cases to consider,
  6776. see the table in the comment before the pattern. */
  6777. bool
  6778. and_operands_ok (machine_mode mode, rtx op1, rtx op2)
  6779. {
  6780. return (memory_operand (op1, mode)
  6781. ? and_load_operand (op2, mode)
  6782. : and_reg_operand (op2, mode));
  6783. }
  6784. /* The canonical form of a mask-low-and-shift-left operation is
  6785. (and (ashift X SHIFT) MASK) where MASK has the lower SHIFT number of bits
  6786. cleared. Thus we need to shift MASK to the right before checking if it
  6787. is a valid mask value. MODE is the mode of the operation. If true
  6788. return the length of the mask, otherwise return -1. */
  6789. int
  6790. mask_low_and_shift_len (machine_mode mode, rtx mask, rtx shift)
  6791. {
  6792. HOST_WIDE_INT shval;
  6793. shval = INTVAL (shift) & (GET_MODE_BITSIZE (mode) - 1);
  6794. return exact_log2 ((UINTVAL (mask) >> shval) + 1);
  6795. }
  6796. /* Return true if -msplit-addresses is selected and should be honored.
  6797. -msplit-addresses is a half-way house between explicit relocations
  6798. and the traditional assembler macros. It can split absolute 32-bit
  6799. symbolic constants into a high/lo_sum pair but uses macros for other
  6800. sorts of access.
  6801. Like explicit relocation support for REL targets, it relies
  6802. on GNU extensions in the assembler and the linker.
  6803. Although this code should work for -O0, it has traditionally
  6804. been treated as an optimization. */
  6805. static bool
  6806. mips_split_addresses_p (void)
  6807. {
  6808. return (TARGET_SPLIT_ADDRESSES
  6809. && optimize
  6810. && !TARGET_MIPS16
  6811. && !flag_pic
  6812. && !ABI_HAS_64BIT_SYMBOLS);
  6813. }
  6814. /* (Re-)Initialize mips_split_p, mips_lo_relocs and mips_hi_relocs. */
  6815. static void
  6816. mips_init_relocs (void)
  6817. {
  6818. memset (mips_split_p, '\0', sizeof (mips_split_p));
  6819. memset (mips_split_hi_p, '\0', sizeof (mips_split_hi_p));
  6820. memset (mips_use_pcrel_pool_p, '\0', sizeof (mips_use_pcrel_pool_p));
  6821. memset (mips_hi_relocs, '\0', sizeof (mips_hi_relocs));
  6822. memset (mips_lo_relocs, '\0', sizeof (mips_lo_relocs));
  6823. if (TARGET_MIPS16_PCREL_LOADS)
  6824. mips_use_pcrel_pool_p[SYMBOL_ABSOLUTE] = true;
  6825. else
  6826. {
  6827. if (ABI_HAS_64BIT_SYMBOLS)
  6828. {
  6829. if (TARGET_EXPLICIT_RELOCS)
  6830. {
  6831. mips_split_p[SYMBOL_64_HIGH] = true;
  6832. mips_hi_relocs[SYMBOL_64_HIGH] = "%highest(";
  6833. mips_lo_relocs[SYMBOL_64_HIGH] = "%higher(";
  6834. mips_split_p[SYMBOL_64_MID] = true;
  6835. mips_hi_relocs[SYMBOL_64_MID] = "%higher(";
  6836. mips_lo_relocs[SYMBOL_64_MID] = "%hi(";
  6837. mips_split_p[SYMBOL_64_LOW] = true;
  6838. mips_hi_relocs[SYMBOL_64_LOW] = "%hi(";
  6839. mips_lo_relocs[SYMBOL_64_LOW] = "%lo(";
  6840. mips_split_p[SYMBOL_ABSOLUTE] = true;
  6841. mips_lo_relocs[SYMBOL_ABSOLUTE] = "%lo(";
  6842. }
  6843. }
  6844. else
  6845. {
  6846. if (TARGET_EXPLICIT_RELOCS
  6847. || mips_split_addresses_p ()
  6848. || TARGET_MIPS16)
  6849. {
  6850. mips_split_p[SYMBOL_ABSOLUTE] = true;
  6851. mips_hi_relocs[SYMBOL_ABSOLUTE] = "%hi(";
  6852. mips_lo_relocs[SYMBOL_ABSOLUTE] = "%lo(";
  6853. }
  6854. }
  6855. }
  6856. if (TARGET_MIPS16)
  6857. {
  6858. /* The high part is provided by a pseudo copy of $gp. */
  6859. mips_split_p[SYMBOL_GP_RELATIVE] = true;
  6860. mips_lo_relocs[SYMBOL_GP_RELATIVE] = "%gprel(";
  6861. }
  6862. else if (TARGET_EXPLICIT_RELOCS)
  6863. /* Small data constants are kept whole until after reload,
  6864. then lowered by mips_rewrite_small_data. */
  6865. mips_lo_relocs[SYMBOL_GP_RELATIVE] = "%gp_rel(";
  6866. if (TARGET_EXPLICIT_RELOCS)
  6867. {
  6868. mips_split_p[SYMBOL_GOT_PAGE_OFST] = true;
  6869. if (TARGET_NEWABI)
  6870. {
  6871. mips_lo_relocs[SYMBOL_GOTOFF_PAGE] = "%got_page(";
  6872. mips_lo_relocs[SYMBOL_GOT_PAGE_OFST] = "%got_ofst(";
  6873. }
  6874. else
  6875. {
  6876. mips_lo_relocs[SYMBOL_GOTOFF_PAGE] = "%got(";
  6877. mips_lo_relocs[SYMBOL_GOT_PAGE_OFST] = "%lo(";
  6878. }
  6879. if (TARGET_MIPS16)
  6880. /* Expose the use of $28 as soon as possible. */
  6881. mips_split_hi_p[SYMBOL_GOT_PAGE_OFST] = true;
  6882. if (TARGET_XGOT)
  6883. {
  6884. /* The HIGH and LO_SUM are matched by special .md patterns. */
  6885. mips_split_p[SYMBOL_GOT_DISP] = true;
  6886. mips_split_p[SYMBOL_GOTOFF_DISP] = true;
  6887. mips_hi_relocs[SYMBOL_GOTOFF_DISP] = "%got_hi(";
  6888. mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got_lo(";
  6889. mips_split_p[SYMBOL_GOTOFF_CALL] = true;
  6890. mips_hi_relocs[SYMBOL_GOTOFF_CALL] = "%call_hi(";
  6891. mips_lo_relocs[SYMBOL_GOTOFF_CALL] = "%call_lo(";
  6892. }
  6893. else
  6894. {
  6895. if (TARGET_NEWABI)
  6896. mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got_disp(";
  6897. else
  6898. mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got(";
  6899. mips_lo_relocs[SYMBOL_GOTOFF_CALL] = "%call16(";
  6900. if (TARGET_MIPS16)
  6901. /* Expose the use of $28 as soon as possible. */
  6902. mips_split_p[SYMBOL_GOT_DISP] = true;
  6903. }
  6904. }
  6905. if (TARGET_NEWABI)
  6906. {
  6907. mips_split_p[SYMBOL_GOTOFF_LOADGP] = true;
  6908. mips_hi_relocs[SYMBOL_GOTOFF_LOADGP] = "%hi(%neg(%gp_rel(";
  6909. mips_lo_relocs[SYMBOL_GOTOFF_LOADGP] = "%lo(%neg(%gp_rel(";
  6910. }
  6911. mips_lo_relocs[SYMBOL_TLSGD] = "%tlsgd(";
  6912. mips_lo_relocs[SYMBOL_TLSLDM] = "%tlsldm(";
  6913. if (TARGET_MIPS16_PCREL_LOADS)
  6914. {
  6915. mips_use_pcrel_pool_p[SYMBOL_DTPREL] = true;
  6916. mips_use_pcrel_pool_p[SYMBOL_TPREL] = true;
  6917. }
  6918. else
  6919. {
  6920. mips_split_p[SYMBOL_DTPREL] = true;
  6921. mips_hi_relocs[SYMBOL_DTPREL] = "%dtprel_hi(";
  6922. mips_lo_relocs[SYMBOL_DTPREL] = "%dtprel_lo(";
  6923. mips_split_p[SYMBOL_TPREL] = true;
  6924. mips_hi_relocs[SYMBOL_TPREL] = "%tprel_hi(";
  6925. mips_lo_relocs[SYMBOL_TPREL] = "%tprel_lo(";
  6926. }
  6927. mips_lo_relocs[SYMBOL_GOTTPREL] = "%gottprel(";
  6928. mips_lo_relocs[SYMBOL_HALF] = "%half(";
  6929. }
  6930. /* Print symbolic operand OP, which is part of a HIGH or LO_SUM
  6931. in context CONTEXT. RELOCS is the array of relocations to use. */
  6932. static void
  6933. mips_print_operand_reloc (FILE *file, rtx op, enum mips_symbol_context context,
  6934. const char **relocs)
  6935. {
  6936. enum mips_symbol_type symbol_type;
  6937. const char *p;
  6938. symbol_type = mips_classify_symbolic_expression (op, context);
  6939. gcc_assert (relocs[symbol_type]);
  6940. fputs (relocs[symbol_type], file);
  6941. output_addr_const (file, mips_strip_unspec_address (op));
  6942. for (p = relocs[symbol_type]; *p != 0; p++)
  6943. if (*p == '(')
  6944. fputc (')', file);
  6945. }
  6946. /* Start a new block with the given asm switch enabled. If we need
  6947. to print a directive, emit PREFIX before it and SUFFIX after it. */
  6948. static void
  6949. mips_push_asm_switch_1 (struct mips_asm_switch *asm_switch,
  6950. const char *prefix, const char *suffix)
  6951. {
  6952. if (asm_switch->nesting_level == 0)
  6953. fprintf (asm_out_file, "%s.set\tno%s%s", prefix, asm_switch->name, suffix);
  6954. asm_switch->nesting_level++;
  6955. }
  6956. /* Likewise, but end a block. */
  6957. static void
  6958. mips_pop_asm_switch_1 (struct mips_asm_switch *asm_switch,
  6959. const char *prefix, const char *suffix)
  6960. {
  6961. gcc_assert (asm_switch->nesting_level);
  6962. asm_switch->nesting_level--;
  6963. if (asm_switch->nesting_level == 0)
  6964. fprintf (asm_out_file, "%s.set\t%s%s", prefix, asm_switch->name, suffix);
  6965. }
  6966. /* Wrappers around mips_push_asm_switch_1 and mips_pop_asm_switch_1
  6967. that either print a complete line or print nothing. */
  6968. void
  6969. mips_push_asm_switch (struct mips_asm_switch *asm_switch)
  6970. {
  6971. mips_push_asm_switch_1 (asm_switch, "\t", "\n");
  6972. }
  6973. void
  6974. mips_pop_asm_switch (struct mips_asm_switch *asm_switch)
  6975. {
  6976. mips_pop_asm_switch_1 (asm_switch, "\t", "\n");
  6977. }
  6978. /* Print the text for PRINT_OPERAND punctation character CH to FILE.
  6979. The punctuation characters are:
  6980. '(' Start a nested ".set noreorder" block.
  6981. ')' End a nested ".set noreorder" block.
  6982. '[' Start a nested ".set noat" block.
  6983. ']' End a nested ".set noat" block.
  6984. '<' Start a nested ".set nomacro" block.
  6985. '>' End a nested ".set nomacro" block.
  6986. '*' Behave like %(%< if generating a delayed-branch sequence.
  6987. '#' Print a nop if in a ".set noreorder" block.
  6988. '/' Like '#', but do nothing within a delayed-branch sequence.
  6989. '?' Print "l" if mips_branch_likely is true
  6990. '~' Print a nop if mips_branch_likely is true
  6991. '.' Print the name of the register with a hard-wired zero (zero or $0).
  6992. '@' Print the name of the assembler temporary register (at or $1).
  6993. '^' Print the name of the pic call-through register (t9 or $25).
  6994. '+' Print the name of the gp register (usually gp or $28).
  6995. '$' Print the name of the stack pointer register (sp or $29).
  6996. ':' Print "c" to use the compact version if the delay slot is a nop.
  6997. '!' Print "s" to use the short version if the delay slot contains a
  6998. 16-bit instruction.
  6999. See also mips_init_print_operand_pucnt. */
  7000. static void
  7001. mips_print_operand_punctuation (FILE *file, int ch)
  7002. {
  7003. switch (ch)
  7004. {
  7005. case '(':
  7006. mips_push_asm_switch_1 (&mips_noreorder, "", "\n\t");
  7007. break;
  7008. case ')':
  7009. mips_pop_asm_switch_1 (&mips_noreorder, "\n\t", "");
  7010. break;
  7011. case '[':
  7012. mips_push_asm_switch_1 (&mips_noat, "", "\n\t");
  7013. break;
  7014. case ']':
  7015. mips_pop_asm_switch_1 (&mips_noat, "\n\t", "");
  7016. break;
  7017. case '<':
  7018. mips_push_asm_switch_1 (&mips_nomacro, "", "\n\t");
  7019. break;
  7020. case '>':
  7021. mips_pop_asm_switch_1 (&mips_nomacro, "\n\t", "");
  7022. break;
  7023. case '*':
  7024. if (final_sequence != 0)
  7025. {
  7026. mips_print_operand_punctuation (file, '(');
  7027. mips_print_operand_punctuation (file, '<');
  7028. }
  7029. break;
  7030. case '#':
  7031. if (mips_noreorder.nesting_level > 0)
  7032. fputs ("\n\tnop", file);
  7033. break;
  7034. case '/':
  7035. /* Print an extra newline so that the delayed insn is separated
  7036. from the following ones. This looks neater and is consistent
  7037. with non-nop delayed sequences. */
  7038. if (mips_noreorder.nesting_level > 0 && final_sequence == 0)
  7039. fputs ("\n\tnop\n", file);
  7040. break;
  7041. case '?':
  7042. if (mips_branch_likely)
  7043. putc ('l', file);
  7044. break;
  7045. case '~':
  7046. if (mips_branch_likely)
  7047. fputs ("\n\tnop", file);
  7048. break;
  7049. case '.':
  7050. fputs (reg_names[GP_REG_FIRST + 0], file);
  7051. break;
  7052. case '@':
  7053. fputs (reg_names[AT_REGNUM], file);
  7054. break;
  7055. case '^':
  7056. fputs (reg_names[PIC_FUNCTION_ADDR_REGNUM], file);
  7057. break;
  7058. case '+':
  7059. fputs (reg_names[PIC_OFFSET_TABLE_REGNUM], file);
  7060. break;
  7061. case '$':
  7062. fputs (reg_names[STACK_POINTER_REGNUM], file);
  7063. break;
  7064. case ':':
  7065. /* When final_sequence is 0, the delay slot will be a nop. We can
  7066. use the compact version for microMIPS. */
  7067. if (final_sequence == 0)
  7068. putc ('c', file);
  7069. break;
  7070. case '!':
  7071. /* If the delay slot instruction is short, then use the
  7072. compact version. */
  7073. if (final_sequence == 0
  7074. || get_attr_length (final_sequence->insn (1)) == 2)
  7075. putc ('s', file);
  7076. break;
  7077. default:
  7078. gcc_unreachable ();
  7079. break;
  7080. }
  7081. }
  7082. /* Initialize mips_print_operand_punct. */
  7083. static void
  7084. mips_init_print_operand_punct (void)
  7085. {
  7086. const char *p;
  7087. for (p = "()[]<>*#/?~.@^+$:!"; *p; p++)
  7088. mips_print_operand_punct[(unsigned char) *p] = true;
  7089. }
  7090. /* PRINT_OPERAND prefix LETTER refers to the integer branch instruction
  7091. associated with condition CODE. Print the condition part of the
  7092. opcode to FILE. */
  7093. static void
  7094. mips_print_int_branch_condition (FILE *file, enum rtx_code code, int letter)
  7095. {
  7096. switch (code)
  7097. {
  7098. case EQ:
  7099. case NE:
  7100. case GT:
  7101. case GE:
  7102. case LT:
  7103. case LE:
  7104. case GTU:
  7105. case GEU:
  7106. case LTU:
  7107. case LEU:
  7108. /* Conveniently, the MIPS names for these conditions are the same
  7109. as their RTL equivalents. */
  7110. fputs (GET_RTX_NAME (code), file);
  7111. break;
  7112. default:
  7113. output_operand_lossage ("'%%%c' is not a valid operand prefix", letter);
  7114. break;
  7115. }
  7116. }
  7117. /* Likewise floating-point branches. */
  7118. static void
  7119. mips_print_float_branch_condition (FILE *file, enum rtx_code code, int letter)
  7120. {
  7121. switch (code)
  7122. {
  7123. case EQ:
  7124. if (ISA_HAS_CCF)
  7125. fputs ("c1eqz", file);
  7126. else
  7127. fputs ("c1f", file);
  7128. break;
  7129. case NE:
  7130. if (ISA_HAS_CCF)
  7131. fputs ("c1nez", file);
  7132. else
  7133. fputs ("c1t", file);
  7134. break;
  7135. default:
  7136. output_operand_lossage ("'%%%c' is not a valid operand prefix", letter);
  7137. break;
  7138. }
  7139. }
  7140. /* Implement TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
  7141. static bool
  7142. mips_print_operand_punct_valid_p (unsigned char code)
  7143. {
  7144. return mips_print_operand_punct[code];
  7145. }
  7146. /* Implement TARGET_PRINT_OPERAND. The MIPS-specific operand codes are:
  7147. 'X' Print CONST_INT OP in hexadecimal format.
  7148. 'x' Print the low 16 bits of CONST_INT OP in hexadecimal format.
  7149. 'd' Print CONST_INT OP in decimal.
  7150. 'm' Print one less than CONST_INT OP in decimal.
  7151. 'y' Print exact log2 of CONST_INT OP in decimal.
  7152. 'h' Print the high-part relocation associated with OP, after stripping
  7153. any outermost HIGH.
  7154. 'R' Print the low-part relocation associated with OP.
  7155. 'C' Print the integer branch condition for comparison OP.
  7156. 'N' Print the inverse of the integer branch condition for comparison OP.
  7157. 'F' Print the FPU branch condition for comparison OP.
  7158. 'W' Print the inverse of the FPU branch condition for comparison OP.
  7159. 'T' Print 'f' for (eq:CC ...), 't' for (ne:CC ...),
  7160. 'z' for (eq:?I ...), 'n' for (ne:?I ...).
  7161. 't' Like 'T', but with the EQ/NE cases reversed
  7162. 'Y' Print mips_fp_conditions[INTVAL (OP)]
  7163. 'Z' Print OP and a comma for ISA_HAS_8CC, otherwise print nothing.
  7164. 'q' Print a DSP accumulator register.
  7165. 'D' Print the second part of a double-word register or memory operand.
  7166. 'L' Print the low-order register in a double-word register operand.
  7167. 'M' Print high-order register in a double-word register operand.
  7168. 'z' Print $0 if OP is zero, otherwise print OP normally.
  7169. 'b' Print the address of a memory operand, without offset. */
  7170. static void
  7171. mips_print_operand (FILE *file, rtx op, int letter)
  7172. {
  7173. enum rtx_code code;
  7174. if (mips_print_operand_punct_valid_p (letter))
  7175. {
  7176. mips_print_operand_punctuation (file, letter);
  7177. return;
  7178. }
  7179. gcc_assert (op);
  7180. code = GET_CODE (op);
  7181. switch (letter)
  7182. {
  7183. case 'X':
  7184. if (CONST_INT_P (op))
  7185. fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (op));
  7186. else
  7187. output_operand_lossage ("invalid use of '%%%c'", letter);
  7188. break;
  7189. case 'x':
  7190. if (CONST_INT_P (op))
  7191. fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (op) & 0xffff);
  7192. else
  7193. output_operand_lossage ("invalid use of '%%%c'", letter);
  7194. break;
  7195. case 'd':
  7196. if (CONST_INT_P (op))
  7197. fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op));
  7198. else
  7199. output_operand_lossage ("invalid use of '%%%c'", letter);
  7200. break;
  7201. case 'm':
  7202. if (CONST_INT_P (op))
  7203. fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op) - 1);
  7204. else
  7205. output_operand_lossage ("invalid use of '%%%c'", letter);
  7206. break;
  7207. case 'y':
  7208. if (CONST_INT_P (op))
  7209. {
  7210. int val = exact_log2 (INTVAL (op));
  7211. if (val != -1)
  7212. fprintf (file, "%d", val);
  7213. else
  7214. output_operand_lossage ("invalid use of '%%%c'", letter);
  7215. }
  7216. else
  7217. output_operand_lossage ("invalid use of '%%%c'", letter);
  7218. break;
  7219. case 'h':
  7220. if (code == HIGH)
  7221. op = XEXP (op, 0);
  7222. mips_print_operand_reloc (file, op, SYMBOL_CONTEXT_LEA, mips_hi_relocs);
  7223. break;
  7224. case 'R':
  7225. mips_print_operand_reloc (file, op, SYMBOL_CONTEXT_LEA, mips_lo_relocs);
  7226. break;
  7227. case 'C':
  7228. mips_print_int_branch_condition (file, code, letter);
  7229. break;
  7230. case 'N':
  7231. mips_print_int_branch_condition (file, reverse_condition (code), letter);
  7232. break;
  7233. case 'F':
  7234. mips_print_float_branch_condition (file, code, letter);
  7235. break;
  7236. case 'W':
  7237. mips_print_float_branch_condition (file, reverse_condition (code),
  7238. letter);
  7239. break;
  7240. case 'T':
  7241. case 't':
  7242. {
  7243. int truth = (code == NE) == (letter == 'T');
  7244. fputc ("zfnt"[truth * 2 + ST_REG_P (REGNO (XEXP (op, 0)))], file);
  7245. }
  7246. break;
  7247. case 'Y':
  7248. if (code == CONST_INT && UINTVAL (op) < ARRAY_SIZE (mips_fp_conditions))
  7249. fputs (mips_fp_conditions[UINTVAL (op)], file);
  7250. else
  7251. output_operand_lossage ("'%%%c' is not a valid operand prefix",
  7252. letter);
  7253. break;
  7254. case 'Z':
  7255. if (ISA_HAS_8CC || ISA_HAS_CCF)
  7256. {
  7257. mips_print_operand (file, op, 0);
  7258. fputc (',', file);
  7259. }
  7260. break;
  7261. case 'q':
  7262. if (code == REG && MD_REG_P (REGNO (op)))
  7263. fprintf (file, "$ac0");
  7264. else if (code == REG && DSP_ACC_REG_P (REGNO (op)))
  7265. fprintf (file, "$ac%c", reg_names[REGNO (op)][3]);
  7266. else
  7267. output_operand_lossage ("invalid use of '%%%c'", letter);
  7268. break;
  7269. default:
  7270. switch (code)
  7271. {
  7272. case REG:
  7273. {
  7274. unsigned int regno = REGNO (op);
  7275. if ((letter == 'M' && TARGET_LITTLE_ENDIAN)
  7276. || (letter == 'L' && TARGET_BIG_ENDIAN)
  7277. || letter == 'D')
  7278. regno++;
  7279. else if (letter && letter != 'z' && letter != 'M' && letter != 'L')
  7280. output_operand_lossage ("invalid use of '%%%c'", letter);
  7281. /* We need to print $0 .. $31 for COP0 registers. */
  7282. if (COP0_REG_P (regno))
  7283. fprintf (file, "$%s", &reg_names[regno][4]);
  7284. else
  7285. fprintf (file, "%s", reg_names[regno]);
  7286. }
  7287. break;
  7288. case MEM:
  7289. if (letter == 'D')
  7290. output_address (plus_constant (Pmode, XEXP (op, 0), 4));
  7291. else if (letter == 'b')
  7292. {
  7293. gcc_assert (REG_P (XEXP (op, 0)));
  7294. mips_print_operand (file, XEXP (op, 0), 0);
  7295. }
  7296. else if (letter && letter != 'z')
  7297. output_operand_lossage ("invalid use of '%%%c'", letter);
  7298. else
  7299. output_address (XEXP (op, 0));
  7300. break;
  7301. default:
  7302. if (letter == 'z' && op == CONST0_RTX (GET_MODE (op)))
  7303. fputs (reg_names[GP_REG_FIRST], file);
  7304. else if (letter && letter != 'z')
  7305. output_operand_lossage ("invalid use of '%%%c'", letter);
  7306. else if (CONST_GP_P (op))
  7307. fputs (reg_names[GLOBAL_POINTER_REGNUM], file);
  7308. else
  7309. output_addr_const (file, mips_strip_unspec_address (op));
  7310. break;
  7311. }
  7312. }
  7313. }
  7314. /* Implement TARGET_PRINT_OPERAND_ADDRESS. */
  7315. static void
  7316. mips_print_operand_address (FILE *file, rtx x)
  7317. {
  7318. struct mips_address_info addr;
  7319. if (mips_classify_address (&addr, x, word_mode, true))
  7320. switch (addr.type)
  7321. {
  7322. case ADDRESS_REG:
  7323. mips_print_operand (file, addr.offset, 0);
  7324. fprintf (file, "(%s)", reg_names[REGNO (addr.reg)]);
  7325. return;
  7326. case ADDRESS_LO_SUM:
  7327. mips_print_operand_reloc (file, addr.offset, SYMBOL_CONTEXT_MEM,
  7328. mips_lo_relocs);
  7329. fprintf (file, "(%s)", reg_names[REGNO (addr.reg)]);
  7330. return;
  7331. case ADDRESS_CONST_INT:
  7332. output_addr_const (file, x);
  7333. fprintf (file, "(%s)", reg_names[GP_REG_FIRST]);
  7334. return;
  7335. case ADDRESS_SYMBOLIC:
  7336. output_addr_const (file, mips_strip_unspec_address (x));
  7337. return;
  7338. }
  7339. gcc_unreachable ();
  7340. }
  7341. /* Implement TARGET_ENCODE_SECTION_INFO. */
  7342. static void
  7343. mips_encode_section_info (tree decl, rtx rtl, int first)
  7344. {
  7345. default_encode_section_info (decl, rtl, first);
  7346. if (TREE_CODE (decl) == FUNCTION_DECL)
  7347. {
  7348. rtx symbol = XEXP (rtl, 0);
  7349. tree type = TREE_TYPE (decl);
  7350. /* Encode whether the symbol is short or long. */
  7351. if ((TARGET_LONG_CALLS && !mips_near_type_p (type))
  7352. || mips_far_type_p (type))
  7353. SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LONG_CALL;
  7354. }
  7355. }
  7356. /* Implement TARGET_SELECT_RTX_SECTION. */
  7357. static section *
  7358. mips_select_rtx_section (machine_mode mode, rtx x,
  7359. unsigned HOST_WIDE_INT align)
  7360. {
  7361. /* ??? Consider using mergeable small data sections. */
  7362. if (mips_rtx_constant_in_small_data_p (mode))
  7363. return get_named_section (NULL, ".sdata", 0);
  7364. return default_elf_select_rtx_section (mode, x, align);
  7365. }
  7366. /* Implement TARGET_ASM_FUNCTION_RODATA_SECTION.
  7367. The complication here is that, with the combination TARGET_ABICALLS
  7368. && !TARGET_ABSOLUTE_ABICALLS && !TARGET_GPWORD, jump tables will use
  7369. absolute addresses, and should therefore not be included in the
  7370. read-only part of a DSO. Handle such cases by selecting a normal
  7371. data section instead of a read-only one. The logic apes that in
  7372. default_function_rodata_section. */
  7373. static section *
  7374. mips_function_rodata_section (tree decl)
  7375. {
  7376. if (!TARGET_ABICALLS || TARGET_ABSOLUTE_ABICALLS || TARGET_GPWORD)
  7377. return default_function_rodata_section (decl);
  7378. if (decl && DECL_SECTION_NAME (decl))
  7379. {
  7380. const char *name = DECL_SECTION_NAME (decl);
  7381. if (DECL_COMDAT_GROUP (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
  7382. {
  7383. char *rname = ASTRDUP (name);
  7384. rname[14] = 'd';
  7385. return get_section (rname, SECTION_LINKONCE | SECTION_WRITE, decl);
  7386. }
  7387. else if (flag_function_sections
  7388. && flag_data_sections
  7389. && strncmp (name, ".text.", 6) == 0)
  7390. {
  7391. char *rname = ASTRDUP (name);
  7392. memcpy (rname + 1, "data", 4);
  7393. return get_section (rname, SECTION_WRITE, decl);
  7394. }
  7395. }
  7396. return data_section;
  7397. }
  7398. /* Implement TARGET_IN_SMALL_DATA_P. */
  7399. static bool
  7400. mips_in_small_data_p (const_tree decl)
  7401. {
  7402. unsigned HOST_WIDE_INT size;
  7403. if (TREE_CODE (decl) == STRING_CST || TREE_CODE (decl) == FUNCTION_DECL)
  7404. return false;
  7405. /* We don't yet generate small-data references for -mabicalls
  7406. or VxWorks RTP code. See the related -G handling in
  7407. mips_option_override. */
  7408. if (TARGET_ABICALLS || TARGET_VXWORKS_RTP)
  7409. return false;
  7410. if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl) != 0)
  7411. {
  7412. const char *name;
  7413. /* Reject anything that isn't in a known small-data section. */
  7414. name = DECL_SECTION_NAME (decl);
  7415. if (strcmp (name, ".sdata") != 0 && strcmp (name, ".sbss") != 0)
  7416. return false;
  7417. /* If a symbol is defined externally, the assembler will use the
  7418. usual -G rules when deciding how to implement macros. */
  7419. if (mips_lo_relocs[SYMBOL_GP_RELATIVE] || !DECL_EXTERNAL (decl))
  7420. return true;
  7421. }
  7422. else if (TARGET_EMBEDDED_DATA)
  7423. {
  7424. /* Don't put constants into the small data section: we want them
  7425. to be in ROM rather than RAM. */
  7426. if (TREE_CODE (decl) != VAR_DECL)
  7427. return false;
  7428. if (TREE_READONLY (decl)
  7429. && !TREE_SIDE_EFFECTS (decl)
  7430. && (!DECL_INITIAL (decl) || TREE_CONSTANT (DECL_INITIAL (decl))))
  7431. return false;
  7432. }
  7433. /* Enforce -mlocal-sdata. */
  7434. if (!TARGET_LOCAL_SDATA && !TREE_PUBLIC (decl))
  7435. return false;
  7436. /* Enforce -mextern-sdata. */
  7437. if (!TARGET_EXTERN_SDATA && DECL_P (decl))
  7438. {
  7439. if (DECL_EXTERNAL (decl))
  7440. return false;
  7441. if (DECL_COMMON (decl) && DECL_INITIAL (decl) == NULL)
  7442. return false;
  7443. }
  7444. /* We have traditionally not treated zero-sized objects as small data,
  7445. so this is now effectively part of the ABI. */
  7446. size = int_size_in_bytes (TREE_TYPE (decl));
  7447. return size > 0 && size <= mips_small_data_threshold;
  7448. }
  7449. /* Implement TARGET_USE_ANCHORS_FOR_SYMBOL_P. We don't want to use
  7450. anchors for small data: the GP register acts as an anchor in that
  7451. case. We also don't want to use them for PC-relative accesses,
  7452. where the PC acts as an anchor. */
  7453. static bool
  7454. mips_use_anchors_for_symbol_p (const_rtx symbol)
  7455. {
  7456. switch (mips_classify_symbol (symbol, SYMBOL_CONTEXT_MEM))
  7457. {
  7458. case SYMBOL_PC_RELATIVE:
  7459. case SYMBOL_GP_RELATIVE:
  7460. return false;
  7461. default:
  7462. return default_use_anchors_for_symbol_p (symbol);
  7463. }
  7464. }
  7465. /* The MIPS debug format wants all automatic variables and arguments
  7466. to be in terms of the virtual frame pointer (stack pointer before
  7467. any adjustment in the function), while the MIPS 3.0 linker wants
  7468. the frame pointer to be the stack pointer after the initial
  7469. adjustment. So, we do the adjustment here. The arg pointer (which
  7470. is eliminated) points to the virtual frame pointer, while the frame
  7471. pointer (which may be eliminated) points to the stack pointer after
  7472. the initial adjustments. */
  7473. HOST_WIDE_INT
  7474. mips_debugger_offset (rtx addr, HOST_WIDE_INT offset)
  7475. {
  7476. rtx offset2 = const0_rtx;
  7477. rtx reg = eliminate_constant_term (addr, &offset2);
  7478. if (offset == 0)
  7479. offset = INTVAL (offset2);
  7480. if (reg == stack_pointer_rtx
  7481. || reg == frame_pointer_rtx
  7482. || reg == hard_frame_pointer_rtx)
  7483. {
  7484. offset -= cfun->machine->frame.total_size;
  7485. if (reg == hard_frame_pointer_rtx)
  7486. offset += cfun->machine->frame.hard_frame_pointer_offset;
  7487. }
  7488. return offset;
  7489. }
  7490. /* Implement ASM_OUTPUT_EXTERNAL. */
  7491. void
  7492. mips_output_external (FILE *file, tree decl, const char *name)
  7493. {
  7494. default_elf_asm_output_external (file, decl, name);
  7495. /* We output the name if and only if TREE_SYMBOL_REFERENCED is
  7496. set in order to avoid putting out names that are never really
  7497. used. */
  7498. if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
  7499. {
  7500. if (!TARGET_EXPLICIT_RELOCS && mips_in_small_data_p (decl))
  7501. {
  7502. /* When using assembler macros, emit .extern directives for
  7503. all small-data externs so that the assembler knows how
  7504. big they are.
  7505. In most cases it would be safe (though pointless) to emit
  7506. .externs for other symbols too. One exception is when an
  7507. object is within the -G limit but declared by the user to
  7508. be in a section other than .sbss or .sdata. */
  7509. fputs ("\t.extern\t", file);
  7510. assemble_name (file, name);
  7511. fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC "\n",
  7512. int_size_in_bytes (TREE_TYPE (decl)));
  7513. }
  7514. }
  7515. }
  7516. /* Implement TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
  7517. static void
  7518. mips_output_filename (FILE *stream, const char *name)
  7519. {
  7520. /* If we are emitting DWARF-2, let dwarf2out handle the ".file"
  7521. directives. */
  7522. if (write_symbols == DWARF2_DEBUG)
  7523. return;
  7524. else if (mips_output_filename_first_time)
  7525. {
  7526. mips_output_filename_first_time = 0;
  7527. num_source_filenames += 1;
  7528. current_function_file = name;
  7529. fprintf (stream, "\t.file\t%d ", num_source_filenames);
  7530. output_quoted_string (stream, name);
  7531. putc ('\n', stream);
  7532. }
  7533. /* If we are emitting stabs, let dbxout.c handle this (except for
  7534. the mips_output_filename_first_time case). */
  7535. else if (write_symbols == DBX_DEBUG)
  7536. return;
  7537. else if (name != current_function_file
  7538. && strcmp (name, current_function_file) != 0)
  7539. {
  7540. num_source_filenames += 1;
  7541. current_function_file = name;
  7542. fprintf (stream, "\t.file\t%d ", num_source_filenames);
  7543. output_quoted_string (stream, name);
  7544. putc ('\n', stream);
  7545. }
  7546. }
  7547. /* Implement TARGET_ASM_OUTPUT_DWARF_DTPREL. */
  7548. static void ATTRIBUTE_UNUSED
  7549. mips_output_dwarf_dtprel (FILE *file, int size, rtx x)
  7550. {
  7551. switch (size)
  7552. {
  7553. case 4:
  7554. fputs ("\t.dtprelword\t", file);
  7555. break;
  7556. case 8:
  7557. fputs ("\t.dtpreldword\t", file);
  7558. break;
  7559. default:
  7560. gcc_unreachable ();
  7561. }
  7562. output_addr_const (file, x);
  7563. fputs ("+0x8000", file);
  7564. }
  7565. /* Implement TARGET_DWARF_REGISTER_SPAN. */
  7566. static rtx
  7567. mips_dwarf_register_span (rtx reg)
  7568. {
  7569. rtx high, low;
  7570. machine_mode mode;
  7571. /* TARGET_FLOATXX is implemented as 32-bit floating-point registers but
  7572. ensures that double-precision registers are treated as if they were
  7573. 64-bit physical registers. The code will run correctly with 32-bit or
  7574. 64-bit registers which means that dwarf information cannot be precise
  7575. for all scenarios. We choose to state that the 64-bit values are stored
  7576. in a single 64-bit 'piece'. This slightly unusual construct can then be
  7577. interpreted as either a pair of registers if the registers are 32-bit or
  7578. a single 64-bit register depending on hardware. */
  7579. mode = GET_MODE (reg);
  7580. if (FP_REG_P (REGNO (reg))
  7581. && TARGET_FLOATXX
  7582. && GET_MODE_SIZE (mode) > UNITS_PER_FPREG)
  7583. {
  7584. return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, reg));
  7585. }
  7586. /* By default, GCC maps increasing register numbers to increasing
  7587. memory locations, but paired FPRs are always little-endian,
  7588. regardless of the prevailing endianness. */
  7589. else if (FP_REG_P (REGNO (reg))
  7590. && TARGET_BIG_ENDIAN
  7591. && MAX_FPRS_PER_FMT > 1
  7592. && GET_MODE_SIZE (mode) > UNITS_PER_FPREG)
  7593. {
  7594. gcc_assert (GET_MODE_SIZE (mode) == UNITS_PER_HWFPVALUE);
  7595. high = mips_subword (reg, true);
  7596. low = mips_subword (reg, false);
  7597. return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, high, low));
  7598. }
  7599. return NULL_RTX;
  7600. }
  7601. /* Implement TARGET_DWARF_FRAME_REG_MODE. */
  7602. static machine_mode
  7603. mips_dwarf_frame_reg_mode (int regno)
  7604. {
  7605. machine_mode mode = default_dwarf_frame_reg_mode (regno);
  7606. if (FP_REG_P (regno) && mips_abi == ABI_32 && TARGET_FLOAT64)
  7607. mode = SImode;
  7608. return mode;
  7609. }
  7610. /* DSP ALU can bypass data with no delays for the following pairs. */
  7611. enum insn_code dspalu_bypass_table[][2] =
  7612. {
  7613. {CODE_FOR_mips_addsc, CODE_FOR_mips_addwc},
  7614. {CODE_FOR_mips_cmpu_eq_qb, CODE_FOR_mips_pick_qb},
  7615. {CODE_FOR_mips_cmpu_lt_qb, CODE_FOR_mips_pick_qb},
  7616. {CODE_FOR_mips_cmpu_le_qb, CODE_FOR_mips_pick_qb},
  7617. {CODE_FOR_mips_cmp_eq_ph, CODE_FOR_mips_pick_ph},
  7618. {CODE_FOR_mips_cmp_lt_ph, CODE_FOR_mips_pick_ph},
  7619. {CODE_FOR_mips_cmp_le_ph, CODE_FOR_mips_pick_ph},
  7620. {CODE_FOR_mips_wrdsp, CODE_FOR_mips_insv}
  7621. };
  7622. int
  7623. mips_dspalu_bypass_p (rtx out_insn, rtx in_insn)
  7624. {
  7625. int i;
  7626. int num_bypass = ARRAY_SIZE (dspalu_bypass_table);
  7627. enum insn_code out_icode = (enum insn_code) INSN_CODE (out_insn);
  7628. enum insn_code in_icode = (enum insn_code) INSN_CODE (in_insn);
  7629. for (i = 0; i < num_bypass; i++)
  7630. {
  7631. if (out_icode == dspalu_bypass_table[i][0]
  7632. && in_icode == dspalu_bypass_table[i][1])
  7633. return true;
  7634. }
  7635. return false;
  7636. }
  7637. /* Implement ASM_OUTPUT_ASCII. */
  7638. void
  7639. mips_output_ascii (FILE *stream, const char *string, size_t len)
  7640. {
  7641. size_t i;
  7642. int cur_pos;
  7643. cur_pos = 17;
  7644. fprintf (stream, "\t.ascii\t\"");
  7645. for (i = 0; i < len; i++)
  7646. {
  7647. int c;
  7648. c = (unsigned char) string[i];
  7649. if (ISPRINT (c))
  7650. {
  7651. if (c == '\\' || c == '\"')
  7652. {
  7653. putc ('\\', stream);
  7654. cur_pos++;
  7655. }
  7656. putc (c, stream);
  7657. cur_pos++;
  7658. }
  7659. else
  7660. {
  7661. fprintf (stream, "\\%03o", c);
  7662. cur_pos += 4;
  7663. }
  7664. if (cur_pos > 72 && i+1 < len)
  7665. {
  7666. cur_pos = 17;
  7667. fprintf (stream, "\"\n\t.ascii\t\"");
  7668. }
  7669. }
  7670. fprintf (stream, "\"\n");
  7671. }
  7672. /* Return the pseudo-op for full SYMBOL_(D)TPREL address *ADDR.
  7673. Update *ADDR with the operand that should be printed. */
  7674. const char *
  7675. mips_output_tls_reloc_directive (rtx *addr)
  7676. {
  7677. enum mips_symbol_type type;
  7678. type = mips_classify_symbolic_expression (*addr, SYMBOL_CONTEXT_LEA);
  7679. *addr = mips_strip_unspec_address (*addr);
  7680. switch (type)
  7681. {
  7682. case SYMBOL_DTPREL:
  7683. return Pmode == SImode ? ".dtprelword\t%0" : ".dtpreldword\t%0";
  7684. case SYMBOL_TPREL:
  7685. return Pmode == SImode ? ".tprelword\t%0" : ".tpreldword\t%0";
  7686. default:
  7687. gcc_unreachable ();
  7688. }
  7689. }
  7690. /* Emit either a label, .comm, or .lcomm directive. When using assembler
  7691. macros, mark the symbol as written so that mips_asm_output_external
  7692. won't emit an .extern for it. STREAM is the output file, NAME is the
  7693. name of the symbol, INIT_STRING is the string that should be written
  7694. before the symbol and FINAL_STRING is the string that should be
  7695. written after it. FINAL_STRING is a printf format that consumes the
  7696. remaining arguments. */
  7697. void
  7698. mips_declare_object (FILE *stream, const char *name, const char *init_string,
  7699. const char *final_string, ...)
  7700. {
  7701. va_list ap;
  7702. fputs (init_string, stream);
  7703. assemble_name (stream, name);
  7704. va_start (ap, final_string);
  7705. vfprintf (stream, final_string, ap);
  7706. va_end (ap);
  7707. if (!TARGET_EXPLICIT_RELOCS)
  7708. {
  7709. tree name_tree = get_identifier (name);
  7710. TREE_ASM_WRITTEN (name_tree) = 1;
  7711. }
  7712. }
  7713. /* Declare a common object of SIZE bytes using asm directive INIT_STRING.
  7714. NAME is the name of the object and ALIGN is the required alignment
  7715. in bytes. TAKES_ALIGNMENT_P is true if the directive takes a third
  7716. alignment argument. */
  7717. void
  7718. mips_declare_common_object (FILE *stream, const char *name,
  7719. const char *init_string,
  7720. unsigned HOST_WIDE_INT size,
  7721. unsigned int align, bool takes_alignment_p)
  7722. {
  7723. if (!takes_alignment_p)
  7724. {
  7725. size += (align / BITS_PER_UNIT) - 1;
  7726. size -= size % (align / BITS_PER_UNIT);
  7727. mips_declare_object (stream, name, init_string,
  7728. "," HOST_WIDE_INT_PRINT_UNSIGNED "\n", size);
  7729. }
  7730. else
  7731. mips_declare_object (stream, name, init_string,
  7732. "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
  7733. size, align / BITS_PER_UNIT);
  7734. }
  7735. /* Implement ASM_OUTPUT_ALIGNED_DECL_COMMON. This is usually the same as the
  7736. elfos.h version, but we also need to handle -muninit-const-in-rodata. */
  7737. void
  7738. mips_output_aligned_decl_common (FILE *stream, tree decl, const char *name,
  7739. unsigned HOST_WIDE_INT size,
  7740. unsigned int align)
  7741. {
  7742. /* If the target wants uninitialized const declarations in
  7743. .rdata then don't put them in .comm. */
  7744. if (TARGET_EMBEDDED_DATA
  7745. && TARGET_UNINIT_CONST_IN_RODATA
  7746. && TREE_CODE (decl) == VAR_DECL
  7747. && TREE_READONLY (decl)
  7748. && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
  7749. {
  7750. if (TREE_PUBLIC (decl) && DECL_NAME (decl))
  7751. targetm.asm_out.globalize_label (stream, name);
  7752. switch_to_section (readonly_data_section);
  7753. ASM_OUTPUT_ALIGN (stream, floor_log2 (align / BITS_PER_UNIT));
  7754. mips_declare_object (stream, name, "",
  7755. ":\n\t.space\t" HOST_WIDE_INT_PRINT_UNSIGNED "\n",
  7756. size);
  7757. }
  7758. else
  7759. mips_declare_common_object (stream, name, "\n\t.comm\t",
  7760. size, align, true);
  7761. }
  7762. #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
  7763. extern int size_directive_output;
  7764. /* Implement ASM_DECLARE_OBJECT_NAME. This is like most of the standard ELF
  7765. definitions except that it uses mips_declare_object to emit the label. */
  7766. void
  7767. mips_declare_object_name (FILE *stream, const char *name,
  7768. tree decl ATTRIBUTE_UNUSED)
  7769. {
  7770. #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
  7771. ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
  7772. #endif
  7773. size_directive_output = 0;
  7774. if (!flag_inhibit_size_directive && DECL_SIZE (decl))
  7775. {
  7776. HOST_WIDE_INT size;
  7777. size_directive_output = 1;
  7778. size = int_size_in_bytes (TREE_TYPE (decl));
  7779. ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
  7780. }
  7781. mips_declare_object (stream, name, "", ":\n");
  7782. }
  7783. /* Implement ASM_FINISH_DECLARE_OBJECT. This is generic ELF stuff. */
  7784. void
  7785. mips_finish_declare_object (FILE *stream, tree decl, int top_level, int at_end)
  7786. {
  7787. const char *name;
  7788. name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
  7789. if (!flag_inhibit_size_directive
  7790. && DECL_SIZE (decl) != 0
  7791. && !at_end
  7792. && top_level
  7793. && DECL_INITIAL (decl) == error_mark_node
  7794. && !size_directive_output)
  7795. {
  7796. HOST_WIDE_INT size;
  7797. size_directive_output = 1;
  7798. size = int_size_in_bytes (TREE_TYPE (decl));
  7799. ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
  7800. }
  7801. }
  7802. #endif
  7803. /* Return the FOO in the name of the ".mdebug.FOO" section associated
  7804. with the current ABI. */
  7805. static const char *
  7806. mips_mdebug_abi_name (void)
  7807. {
  7808. switch (mips_abi)
  7809. {
  7810. case ABI_32:
  7811. return "abi32";
  7812. case ABI_O64:
  7813. return "abiO64";
  7814. case ABI_N32:
  7815. return "abiN32";
  7816. case ABI_64:
  7817. return "abi64";
  7818. case ABI_EABI:
  7819. return TARGET_64BIT ? "eabi64" : "eabi32";
  7820. default:
  7821. gcc_unreachable ();
  7822. }
  7823. }
  7824. /* Implement TARGET_ASM_FILE_START. */
  7825. static void
  7826. mips_file_start (void)
  7827. {
  7828. default_file_start ();
  7829. /* Generate a special section to describe the ABI switches used to
  7830. produce the resultant binary. */
  7831. /* Record the ABI itself. Modern versions of binutils encode
  7832. this information in the ELF header flags, but GDB needs the
  7833. information in order to correctly debug binaries produced by
  7834. older binutils. See the function mips_gdbarch_init in
  7835. gdb/mips-tdep.c. */
  7836. fprintf (asm_out_file, "\t.section .mdebug.%s\n\t.previous\n",
  7837. mips_mdebug_abi_name ());
  7838. /* There is no ELF header flag to distinguish long32 forms of the
  7839. EABI from long64 forms. Emit a special section to help tools
  7840. such as GDB. Do the same for o64, which is sometimes used with
  7841. -mlong64. */
  7842. if (mips_abi == ABI_EABI || mips_abi == ABI_O64)
  7843. fprintf (asm_out_file, "\t.section .gcc_compiled_long%d\n"
  7844. "\t.previous\n", TARGET_LONG64 ? 64 : 32);
  7845. /* Record the NaN encoding. */
  7846. if (HAVE_AS_NAN || mips_nan != MIPS_IEEE_754_DEFAULT)
  7847. fprintf (asm_out_file, "\t.nan\t%s\n",
  7848. mips_nan == MIPS_IEEE_754_2008 ? "2008" : "legacy");
  7849. #ifdef HAVE_AS_DOT_MODULE
  7850. /* Record the FP ABI. See below for comments. */
  7851. if (TARGET_NO_FLOAT)
  7852. #ifdef HAVE_AS_GNU_ATTRIBUTE
  7853. fputs ("\t.gnu_attribute 4, 0\n", asm_out_file);
  7854. #else
  7855. ;
  7856. #endif
  7857. else if (!TARGET_HARD_FLOAT_ABI)
  7858. fputs ("\t.module\tsoftfloat\n", asm_out_file);
  7859. else if (!TARGET_DOUBLE_FLOAT)
  7860. fputs ("\t.module\tsinglefloat\n", asm_out_file);
  7861. else if (TARGET_FLOATXX)
  7862. fputs ("\t.module\tfp=xx\n", asm_out_file);
  7863. else if (TARGET_FLOAT64)
  7864. fputs ("\t.module\tfp=64\n", asm_out_file);
  7865. else
  7866. fputs ("\t.module\tfp=32\n", asm_out_file);
  7867. if (TARGET_ODD_SPREG)
  7868. fputs ("\t.module\toddspreg\n", asm_out_file);
  7869. else
  7870. fputs ("\t.module\tnooddspreg\n", asm_out_file);
  7871. #else
  7872. #ifdef HAVE_AS_GNU_ATTRIBUTE
  7873. {
  7874. int attr;
  7875. /* No floating-point operations, -mno-float. */
  7876. if (TARGET_NO_FLOAT)
  7877. attr = 0;
  7878. /* Soft-float code, -msoft-float. */
  7879. else if (!TARGET_HARD_FLOAT_ABI)
  7880. attr = 3;
  7881. /* Single-float code, -msingle-float. */
  7882. else if (!TARGET_DOUBLE_FLOAT)
  7883. attr = 2;
  7884. /* 64-bit FP registers on a 32-bit target, -mips32r2 -mfp64.
  7885. Reserved attr=4.
  7886. This case used 12 callee-saved double-precision registers
  7887. and is deprecated. */
  7888. /* 64-bit or 32-bit FP registers on a 32-bit target, -mfpxx. */
  7889. else if (TARGET_FLOATXX)
  7890. attr = 5;
  7891. /* 64-bit FP registers on a 32-bit target, -mfp64 -modd-spreg. */
  7892. else if (mips_abi == ABI_32 && TARGET_FLOAT64 && TARGET_ODD_SPREG)
  7893. attr = 6;
  7894. /* 64-bit FP registers on a 32-bit target, -mfp64 -mno-odd-spreg. */
  7895. else if (mips_abi == ABI_32 && TARGET_FLOAT64)
  7896. attr = 7;
  7897. /* Regular FP code, FP regs same size as GP regs, -mdouble-float. */
  7898. else
  7899. attr = 1;
  7900. fprintf (asm_out_file, "\t.gnu_attribute 4, %d\n", attr);
  7901. }
  7902. #endif
  7903. #endif
  7904. /* If TARGET_ABICALLS, tell GAS to generate -KPIC code. */
  7905. if (TARGET_ABICALLS)
  7906. {
  7907. fprintf (asm_out_file, "\t.abicalls\n");
  7908. if (TARGET_ABICALLS_PIC0)
  7909. fprintf (asm_out_file, "\t.option\tpic0\n");
  7910. }
  7911. if (flag_verbose_asm)
  7912. fprintf (asm_out_file, "\n%s -G value = %d, Arch = %s, ISA = %d\n",
  7913. ASM_COMMENT_START,
  7914. mips_small_data_threshold, mips_arch_info->name, mips_isa);
  7915. }
  7916. /* Implement TARGET_ASM_CODE_END. */
  7917. static void
  7918. mips_code_end (void)
  7919. {
  7920. mips_finish_stub (&mips16_rdhwr_stub);
  7921. mips_finish_stub (&mips16_get_fcsr_stub);
  7922. mips_finish_stub (&mips16_set_fcsr_stub);
  7923. }
  7924. /* Make the last instruction frame-related and note that it performs
  7925. the operation described by FRAME_PATTERN. */
  7926. static void
  7927. mips_set_frame_expr (rtx frame_pattern)
  7928. {
  7929. rtx_insn *insn;
  7930. insn = get_last_insn ();
  7931. RTX_FRAME_RELATED_P (insn) = 1;
  7932. REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
  7933. frame_pattern,
  7934. REG_NOTES (insn));
  7935. }
  7936. /* Return a frame-related rtx that stores REG at MEM.
  7937. REG must be a single register. */
  7938. static rtx
  7939. mips_frame_set (rtx mem, rtx reg)
  7940. {
  7941. rtx set;
  7942. set = gen_rtx_SET (VOIDmode, mem, reg);
  7943. RTX_FRAME_RELATED_P (set) = 1;
  7944. return set;
  7945. }
  7946. /* Record that the epilogue has restored call-saved register REG. */
  7947. static void
  7948. mips_add_cfa_restore (rtx reg)
  7949. {
  7950. mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
  7951. mips_epilogue.cfa_restores);
  7952. }
  7953. /* If a MIPS16e SAVE or RESTORE instruction saves or restores register
  7954. mips16e_s2_s8_regs[X], it must also save the registers in indexes
  7955. X + 1 onwards. Likewise mips16e_a0_a3_regs. */
  7956. static const unsigned char mips16e_s2_s8_regs[] = {
  7957. 30, 23, 22, 21, 20, 19, 18
  7958. };
  7959. static const unsigned char mips16e_a0_a3_regs[] = {
  7960. 4, 5, 6, 7
  7961. };
  7962. /* A list of the registers that can be saved by the MIPS16e SAVE instruction,
  7963. ordered from the uppermost in memory to the lowest in memory. */
  7964. static const unsigned char mips16e_save_restore_regs[] = {
  7965. 31, 30, 23, 22, 21, 20, 19, 18, 17, 16, 7, 6, 5, 4
  7966. };
  7967. /* Return the index of the lowest X in the range [0, SIZE) for which
  7968. bit REGS[X] is set in MASK. Return SIZE if there is no such X. */
  7969. static unsigned int
  7970. mips16e_find_first_register (unsigned int mask, const unsigned char *regs,
  7971. unsigned int size)
  7972. {
  7973. unsigned int i;
  7974. for (i = 0; i < size; i++)
  7975. if (BITSET_P (mask, regs[i]))
  7976. break;
  7977. return i;
  7978. }
  7979. /* *MASK_PTR is a mask of general-purpose registers and *NUM_REGS_PTR
  7980. is the number of set bits. If *MASK_PTR contains REGS[X] for some X
  7981. in [0, SIZE), adjust *MASK_PTR and *NUM_REGS_PTR so that the same
  7982. is true for all indexes (X, SIZE). */
  7983. static void
  7984. mips16e_mask_registers (unsigned int *mask_ptr, const unsigned char *regs,
  7985. unsigned int size, unsigned int *num_regs_ptr)
  7986. {
  7987. unsigned int i;
  7988. i = mips16e_find_first_register (*mask_ptr, regs, size);
  7989. for (i++; i < size; i++)
  7990. if (!BITSET_P (*mask_ptr, regs[i]))
  7991. {
  7992. *num_regs_ptr += 1;
  7993. *mask_ptr |= 1 << regs[i];
  7994. }
  7995. }
  7996. /* Return a simplified form of X using the register values in REG_VALUES.
  7997. REG_VALUES[R] is the last value assigned to hard register R, or null
  7998. if R has not been modified.
  7999. This function is rather limited, but is good enough for our purposes. */
  8000. static rtx
  8001. mips16e_collect_propagate_value (rtx x, rtx *reg_values)
  8002. {
  8003. x = avoid_constant_pool_reference (x);
  8004. if (UNARY_P (x))
  8005. {
  8006. rtx x0 = mips16e_collect_propagate_value (XEXP (x, 0), reg_values);
  8007. return simplify_gen_unary (GET_CODE (x), GET_MODE (x),
  8008. x0, GET_MODE (XEXP (x, 0)));
  8009. }
  8010. if (ARITHMETIC_P (x))
  8011. {
  8012. rtx x0 = mips16e_collect_propagate_value (XEXP (x, 0), reg_values);
  8013. rtx x1 = mips16e_collect_propagate_value (XEXP (x, 1), reg_values);
  8014. return simplify_gen_binary (GET_CODE (x), GET_MODE (x), x0, x1);
  8015. }
  8016. if (REG_P (x)
  8017. && reg_values[REGNO (x)]
  8018. && !rtx_unstable_p (reg_values[REGNO (x)]))
  8019. return reg_values[REGNO (x)];
  8020. return x;
  8021. }
  8022. /* Return true if (set DEST SRC) stores an argument register into its
  8023. caller-allocated save slot, storing the number of that argument
  8024. register in *REGNO_PTR if so. REG_VALUES is as for
  8025. mips16e_collect_propagate_value. */
  8026. static bool
  8027. mips16e_collect_argument_save_p (rtx dest, rtx src, rtx *reg_values,
  8028. unsigned int *regno_ptr)
  8029. {
  8030. unsigned int argno, regno;
  8031. HOST_WIDE_INT offset, required_offset;
  8032. rtx addr, base;
  8033. /* Check that this is a word-mode store. */
  8034. if (!MEM_P (dest) || !REG_P (src) || GET_MODE (dest) != word_mode)
  8035. return false;
  8036. /* Check that the register being saved is an unmodified argument
  8037. register. */
  8038. regno = REGNO (src);
  8039. if (!IN_RANGE (regno, GP_ARG_FIRST, GP_ARG_LAST) || reg_values[regno])
  8040. return false;
  8041. argno = regno - GP_ARG_FIRST;
  8042. /* Check whether the address is an appropriate stack-pointer or
  8043. frame-pointer access. */
  8044. addr = mips16e_collect_propagate_value (XEXP (dest, 0), reg_values);
  8045. mips_split_plus (addr, &base, &offset);
  8046. required_offset = cfun->machine->frame.total_size + argno * UNITS_PER_WORD;
  8047. if (base == hard_frame_pointer_rtx)
  8048. required_offset -= cfun->machine->frame.hard_frame_pointer_offset;
  8049. else if (base != stack_pointer_rtx)
  8050. return false;
  8051. if (offset != required_offset)
  8052. return false;
  8053. *regno_ptr = regno;
  8054. return true;
  8055. }
  8056. /* A subroutine of mips_expand_prologue, called only when generating
  8057. MIPS16e SAVE instructions. Search the start of the function for any
  8058. instructions that save argument registers into their caller-allocated
  8059. save slots. Delete such instructions and return a value N such that
  8060. saving [GP_ARG_FIRST, GP_ARG_FIRST + N) would make all the deleted
  8061. instructions redundant. */
  8062. static unsigned int
  8063. mips16e_collect_argument_saves (void)
  8064. {
  8065. rtx reg_values[FIRST_PSEUDO_REGISTER];
  8066. rtx_insn *insn, *next;
  8067. rtx set, dest, src;
  8068. unsigned int nargs, regno;
  8069. push_topmost_sequence ();
  8070. nargs = 0;
  8071. memset (reg_values, 0, sizeof (reg_values));
  8072. for (insn = get_insns (); insn; insn = next)
  8073. {
  8074. next = NEXT_INSN (insn);
  8075. if (NOTE_P (insn) || DEBUG_INSN_P (insn))
  8076. continue;
  8077. if (!INSN_P (insn))
  8078. break;
  8079. set = PATTERN (insn);
  8080. if (GET_CODE (set) != SET)
  8081. break;
  8082. dest = SET_DEST (set);
  8083. src = SET_SRC (set);
  8084. if (mips16e_collect_argument_save_p (dest, src, reg_values, &regno))
  8085. {
  8086. if (!BITSET_P (cfun->machine->frame.mask, regno))
  8087. {
  8088. delete_insn (insn);
  8089. nargs = MAX (nargs, (regno - GP_ARG_FIRST) + 1);
  8090. }
  8091. }
  8092. else if (REG_P (dest) && GET_MODE (dest) == word_mode)
  8093. reg_values[REGNO (dest)]
  8094. = mips16e_collect_propagate_value (src, reg_values);
  8095. else
  8096. break;
  8097. }
  8098. pop_topmost_sequence ();
  8099. return nargs;
  8100. }
  8101. /* Return a move between register REGNO and memory location SP + OFFSET.
  8102. REG_PARM_P is true if SP + OFFSET belongs to REG_PARM_STACK_SPACE.
  8103. Make the move a load if RESTORE_P, otherwise make it a store. */
  8104. static rtx
  8105. mips16e_save_restore_reg (bool restore_p, bool reg_parm_p,
  8106. HOST_WIDE_INT offset, unsigned int regno)
  8107. {
  8108. rtx reg, mem;
  8109. mem = gen_frame_mem (SImode, plus_constant (Pmode, stack_pointer_rtx,
  8110. offset));
  8111. reg = gen_rtx_REG (SImode, regno);
  8112. if (restore_p)
  8113. {
  8114. mips_add_cfa_restore (reg);
  8115. return gen_rtx_SET (VOIDmode, reg, mem);
  8116. }
  8117. if (reg_parm_p)
  8118. return gen_rtx_SET (VOIDmode, mem, reg);
  8119. return mips_frame_set (mem, reg);
  8120. }
  8121. /* Return RTL for a MIPS16e SAVE or RESTORE instruction; RESTORE_P says which.
  8122. The instruction must:
  8123. - Allocate or deallocate SIZE bytes in total; SIZE is known
  8124. to be nonzero.
  8125. - Save or restore as many registers in *MASK_PTR as possible.
  8126. The instruction saves the first registers at the top of the
  8127. allocated area, with the other registers below it.
  8128. - Save NARGS argument registers above the allocated area.
  8129. (NARGS is always zero if RESTORE_P.)
  8130. The SAVE and RESTORE instructions cannot save and restore all general
  8131. registers, so there may be some registers left over for the caller to
  8132. handle. Destructively modify *MASK_PTR so that it contains the registers
  8133. that still need to be saved or restored. The caller can save these
  8134. registers in the memory immediately below *OFFSET_PTR, which is a
  8135. byte offset from the bottom of the allocated stack area. */
  8136. static rtx
  8137. mips16e_build_save_restore (bool restore_p, unsigned int *mask_ptr,
  8138. HOST_WIDE_INT *offset_ptr, unsigned int nargs,
  8139. HOST_WIDE_INT size)
  8140. {
  8141. rtx pattern, set;
  8142. HOST_WIDE_INT offset, top_offset;
  8143. unsigned int i, regno;
  8144. int n;
  8145. gcc_assert (cfun->machine->frame.num_fp == 0);
  8146. /* Calculate the number of elements in the PARALLEL. We need one element
  8147. for the stack adjustment, one for each argument register save, and one
  8148. for each additional register move. */
  8149. n = 1 + nargs;
  8150. for (i = 0; i < ARRAY_SIZE (mips16e_save_restore_regs); i++)
  8151. if (BITSET_P (*mask_ptr, mips16e_save_restore_regs[i]))
  8152. n++;
  8153. /* Create the final PARALLEL. */
  8154. pattern = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (n));
  8155. n = 0;
  8156. /* Add the stack pointer adjustment. */
  8157. set = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
  8158. plus_constant (Pmode, stack_pointer_rtx,
  8159. restore_p ? size : -size));
  8160. RTX_FRAME_RELATED_P (set) = 1;
  8161. XVECEXP (pattern, 0, n++) = set;
  8162. /* Stack offsets in the PARALLEL are relative to the old stack pointer. */
  8163. top_offset = restore_p ? size : 0;
  8164. /* Save the arguments. */
  8165. for (i = 0; i < nargs; i++)
  8166. {
  8167. offset = top_offset + i * UNITS_PER_WORD;
  8168. set = mips16e_save_restore_reg (restore_p, true, offset,
  8169. GP_ARG_FIRST + i);
  8170. XVECEXP (pattern, 0, n++) = set;
  8171. }
  8172. /* Then fill in the other register moves. */
  8173. offset = top_offset;
  8174. for (i = 0; i < ARRAY_SIZE (mips16e_save_restore_regs); i++)
  8175. {
  8176. regno = mips16e_save_restore_regs[i];
  8177. if (BITSET_P (*mask_ptr, regno))
  8178. {
  8179. offset -= UNITS_PER_WORD;
  8180. set = mips16e_save_restore_reg (restore_p, false, offset, regno);
  8181. XVECEXP (pattern, 0, n++) = set;
  8182. *mask_ptr &= ~(1 << regno);
  8183. }
  8184. }
  8185. /* Tell the caller what offset it should use for the remaining registers. */
  8186. *offset_ptr = size + (offset - top_offset);
  8187. gcc_assert (n == XVECLEN (pattern, 0));
  8188. return pattern;
  8189. }
  8190. /* PATTERN is a PARALLEL whose first element adds ADJUST to the stack
  8191. pointer. Return true if PATTERN matches the kind of instruction
  8192. generated by mips16e_build_save_restore. If INFO is nonnull,
  8193. initialize it when returning true. */
  8194. bool
  8195. mips16e_save_restore_pattern_p (rtx pattern, HOST_WIDE_INT adjust,
  8196. struct mips16e_save_restore_info *info)
  8197. {
  8198. unsigned int i, nargs, mask, extra;
  8199. HOST_WIDE_INT top_offset, save_offset, offset;
  8200. rtx set, reg, mem, base;
  8201. int n;
  8202. if (!GENERATE_MIPS16E_SAVE_RESTORE)
  8203. return false;
  8204. /* Stack offsets in the PARALLEL are relative to the old stack pointer. */
  8205. top_offset = adjust > 0 ? adjust : 0;
  8206. /* Interpret all other members of the PARALLEL. */
  8207. save_offset = top_offset - UNITS_PER_WORD;
  8208. mask = 0;
  8209. nargs = 0;
  8210. i = 0;
  8211. for (n = 1; n < XVECLEN (pattern, 0); n++)
  8212. {
  8213. /* Check that we have a SET. */
  8214. set = XVECEXP (pattern, 0, n);
  8215. if (GET_CODE (set) != SET)
  8216. return false;
  8217. /* Check that the SET is a load (if restoring) or a store
  8218. (if saving). */
  8219. mem = adjust > 0 ? SET_SRC (set) : SET_DEST (set);
  8220. if (!MEM_P (mem))
  8221. return false;
  8222. /* Check that the address is the sum of the stack pointer and a
  8223. possibly-zero constant offset. */
  8224. mips_split_plus (XEXP (mem, 0), &base, &offset);
  8225. if (base != stack_pointer_rtx)
  8226. return false;
  8227. /* Check that SET's other operand is a register. */
  8228. reg = adjust > 0 ? SET_DEST (set) : SET_SRC (set);
  8229. if (!REG_P (reg))
  8230. return false;
  8231. /* Check for argument saves. */
  8232. if (offset == top_offset + nargs * UNITS_PER_WORD
  8233. && REGNO (reg) == GP_ARG_FIRST + nargs)
  8234. nargs++;
  8235. else if (offset == save_offset)
  8236. {
  8237. while (mips16e_save_restore_regs[i++] != REGNO (reg))
  8238. if (i == ARRAY_SIZE (mips16e_save_restore_regs))
  8239. return false;
  8240. mask |= 1 << REGNO (reg);
  8241. save_offset -= UNITS_PER_WORD;
  8242. }
  8243. else
  8244. return false;
  8245. }
  8246. /* Check that the restrictions on register ranges are met. */
  8247. extra = 0;
  8248. mips16e_mask_registers (&mask, mips16e_s2_s8_regs,
  8249. ARRAY_SIZE (mips16e_s2_s8_regs), &extra);
  8250. mips16e_mask_registers (&mask, mips16e_a0_a3_regs,
  8251. ARRAY_SIZE (mips16e_a0_a3_regs), &extra);
  8252. if (extra != 0)
  8253. return false;
  8254. /* Make sure that the topmost argument register is not saved twice.
  8255. The checks above ensure that the same is then true for the other
  8256. argument registers. */
  8257. if (nargs > 0 && BITSET_P (mask, GP_ARG_FIRST + nargs - 1))
  8258. return false;
  8259. /* Pass back information, if requested. */
  8260. if (info)
  8261. {
  8262. info->nargs = nargs;
  8263. info->mask = mask;
  8264. info->size = (adjust > 0 ? adjust : -adjust);
  8265. }
  8266. return true;
  8267. }
  8268. /* Add a MIPS16e SAVE or RESTORE register-range argument to string S
  8269. for the register range [MIN_REG, MAX_REG]. Return a pointer to
  8270. the null terminator. */
  8271. static char *
  8272. mips16e_add_register_range (char *s, unsigned int min_reg,
  8273. unsigned int max_reg)
  8274. {
  8275. if (min_reg != max_reg)
  8276. s += sprintf (s, ",%s-%s", reg_names[min_reg], reg_names[max_reg]);
  8277. else
  8278. s += sprintf (s, ",%s", reg_names[min_reg]);
  8279. return s;
  8280. }
  8281. /* Return the assembly instruction for a MIPS16e SAVE or RESTORE instruction.
  8282. PATTERN and ADJUST are as for mips16e_save_restore_pattern_p. */
  8283. const char *
  8284. mips16e_output_save_restore (rtx pattern, HOST_WIDE_INT adjust)
  8285. {
  8286. static char buffer[300];
  8287. struct mips16e_save_restore_info info;
  8288. unsigned int i, end;
  8289. char *s;
  8290. /* Parse the pattern. */
  8291. if (!mips16e_save_restore_pattern_p (pattern, adjust, &info))
  8292. gcc_unreachable ();
  8293. /* Add the mnemonic. */
  8294. s = strcpy (buffer, adjust > 0 ? "restore\t" : "save\t");
  8295. s += strlen (s);
  8296. /* Save the arguments. */
  8297. if (info.nargs > 1)
  8298. s += sprintf (s, "%s-%s,", reg_names[GP_ARG_FIRST],
  8299. reg_names[GP_ARG_FIRST + info.nargs - 1]);
  8300. else if (info.nargs == 1)
  8301. s += sprintf (s, "%s,", reg_names[GP_ARG_FIRST]);
  8302. /* Emit the amount of stack space to allocate or deallocate. */
  8303. s += sprintf (s, "%d", (int) info.size);
  8304. /* Save or restore $16. */
  8305. if (BITSET_P (info.mask, 16))
  8306. s += sprintf (s, ",%s", reg_names[GP_REG_FIRST + 16]);
  8307. /* Save or restore $17. */
  8308. if (BITSET_P (info.mask, 17))
  8309. s += sprintf (s, ",%s", reg_names[GP_REG_FIRST + 17]);
  8310. /* Save or restore registers in the range $s2...$s8, which
  8311. mips16e_s2_s8_regs lists in decreasing order. Note that this
  8312. is a software register range; the hardware registers are not
  8313. numbered consecutively. */
  8314. end = ARRAY_SIZE (mips16e_s2_s8_regs);
  8315. i = mips16e_find_first_register (info.mask, mips16e_s2_s8_regs, end);
  8316. if (i < end)
  8317. s = mips16e_add_register_range (s, mips16e_s2_s8_regs[end - 1],
  8318. mips16e_s2_s8_regs[i]);
  8319. /* Save or restore registers in the range $a0...$a3. */
  8320. end = ARRAY_SIZE (mips16e_a0_a3_regs);
  8321. i = mips16e_find_first_register (info.mask, mips16e_a0_a3_regs, end);
  8322. if (i < end)
  8323. s = mips16e_add_register_range (s, mips16e_a0_a3_regs[i],
  8324. mips16e_a0_a3_regs[end - 1]);
  8325. /* Save or restore $31. */
  8326. if (BITSET_P (info.mask, RETURN_ADDR_REGNUM))
  8327. s += sprintf (s, ",%s", reg_names[RETURN_ADDR_REGNUM]);
  8328. return buffer;
  8329. }
  8330. /* Return true if the current function returns its value in a floating-point
  8331. register in MIPS16 mode. */
  8332. static bool
  8333. mips16_cfun_returns_in_fpr_p (void)
  8334. {
  8335. tree return_type = DECL_RESULT (current_function_decl);
  8336. return (TARGET_MIPS16
  8337. && TARGET_HARD_FLOAT_ABI
  8338. && !aggregate_value_p (return_type, current_function_decl)
  8339. && mips_return_mode_in_fpr_p (DECL_MODE (return_type)));
  8340. }
  8341. /* Return true if predicate PRED is true for at least one instruction.
  8342. Cache the result in *CACHE, and assume that the result is true
  8343. if *CACHE is already true. */
  8344. static bool
  8345. mips_find_gp_ref (bool *cache, bool (*pred) (rtx_insn *))
  8346. {
  8347. rtx_insn *insn;
  8348. if (!*cache)
  8349. {
  8350. push_topmost_sequence ();
  8351. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  8352. if (USEFUL_INSN_P (insn) && pred (insn))
  8353. {
  8354. *cache = true;
  8355. break;
  8356. }
  8357. pop_topmost_sequence ();
  8358. }
  8359. return *cache;
  8360. }
  8361. /* Return true if INSN refers to the global pointer in an "inflexible" way.
  8362. See mips_cfun_has_inflexible_gp_ref_p for details. */
  8363. static bool
  8364. mips_insn_has_inflexible_gp_ref_p (rtx_insn *insn)
  8365. {
  8366. /* Uses of pic_offset_table_rtx in CALL_INSN_FUNCTION_USAGE
  8367. indicate that the target could be a traditional MIPS
  8368. lazily-binding stub. */
  8369. return find_reg_fusage (insn, USE, pic_offset_table_rtx);
  8370. }
  8371. /* Return true if the current function refers to the global pointer
  8372. in a way that forces $28 to be valid. This means that we can't
  8373. change the choice of global pointer, even for NewABI code.
  8374. One example of this (and one which needs several checks) is that
  8375. $28 must be valid when calling traditional MIPS lazy-binding stubs.
  8376. (This restriction does not apply to PLTs.) */
  8377. static bool
  8378. mips_cfun_has_inflexible_gp_ref_p (void)
  8379. {
  8380. /* If the function has a nonlocal goto, $28 must hold the correct
  8381. global pointer for the target function. That is, the target
  8382. of the goto implicitly uses $28. */
  8383. if (crtl->has_nonlocal_goto)
  8384. return true;
  8385. if (TARGET_ABICALLS_PIC2)
  8386. {
  8387. /* Symbolic accesses implicitly use the global pointer unless
  8388. -mexplicit-relocs is in effect. JAL macros to symbolic addresses
  8389. might go to traditional MIPS lazy-binding stubs. */
  8390. if (!TARGET_EXPLICIT_RELOCS)
  8391. return true;
  8392. /* FUNCTION_PROFILER includes a JAL to _mcount, which again
  8393. can be lazily-bound. */
  8394. if (crtl->profile)
  8395. return true;
  8396. /* MIPS16 functions that return in FPRs need to call an
  8397. external libgcc routine. This call is only made explict
  8398. during mips_expand_epilogue, and it too might be lazily bound. */
  8399. if (mips16_cfun_returns_in_fpr_p ())
  8400. return true;
  8401. }
  8402. return mips_find_gp_ref (&cfun->machine->has_inflexible_gp_insn_p,
  8403. mips_insn_has_inflexible_gp_ref_p);
  8404. }
  8405. /* Return true if INSN refers to the global pointer in a "flexible" way.
  8406. See mips_cfun_has_flexible_gp_ref_p for details. */
  8407. static bool
  8408. mips_insn_has_flexible_gp_ref_p (rtx_insn *insn)
  8409. {
  8410. return (get_attr_got (insn) != GOT_UNSET
  8411. || mips_small_data_pattern_p (PATTERN (insn))
  8412. || reg_overlap_mentioned_p (pic_offset_table_rtx, PATTERN (insn)));
  8413. }
  8414. /* Return true if the current function references the global pointer,
  8415. but if those references do not inherently require the global pointer
  8416. to be $28. Assume !mips_cfun_has_inflexible_gp_ref_p (). */
  8417. static bool
  8418. mips_cfun_has_flexible_gp_ref_p (void)
  8419. {
  8420. /* Reload can sometimes introduce constant pool references
  8421. into a function that otherwise didn't need them. For example,
  8422. suppose we have an instruction like:
  8423. (set (reg:DF R1) (float:DF (reg:SI R2)))
  8424. If R2 turns out to be a constant such as 1, the instruction may
  8425. have a REG_EQUAL note saying that R1 == 1.0. Reload then has
  8426. the option of using this constant if R2 doesn't get allocated
  8427. to a register.
  8428. In cases like these, reload will have added the constant to the
  8429. pool but no instruction will yet refer to it. */
  8430. if (TARGET_ABICALLS_PIC2 && !reload_completed && crtl->uses_const_pool)
  8431. return true;
  8432. return mips_find_gp_ref (&cfun->machine->has_flexible_gp_insn_p,
  8433. mips_insn_has_flexible_gp_ref_p);
  8434. }
  8435. /* Return the register that should be used as the global pointer
  8436. within this function. Return INVALID_REGNUM if the function
  8437. doesn't need a global pointer. */
  8438. static unsigned int
  8439. mips_global_pointer (void)
  8440. {
  8441. unsigned int regno;
  8442. /* $gp is always available unless we're using a GOT. */
  8443. if (!TARGET_USE_GOT)
  8444. return GLOBAL_POINTER_REGNUM;
  8445. /* If there are inflexible references to $gp, we must use the
  8446. standard register. */
  8447. if (mips_cfun_has_inflexible_gp_ref_p ())
  8448. return GLOBAL_POINTER_REGNUM;
  8449. /* If there are no current references to $gp, then the only uses
  8450. we can introduce later are those involved in long branches. */
  8451. if (TARGET_ABSOLUTE_JUMPS && !mips_cfun_has_flexible_gp_ref_p ())
  8452. return INVALID_REGNUM;
  8453. /* If the global pointer is call-saved, try to use a call-clobbered
  8454. alternative. */
  8455. if (TARGET_CALL_SAVED_GP && crtl->is_leaf)
  8456. for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++)
  8457. if (!df_regs_ever_live_p (regno)
  8458. && call_really_used_regs[regno]
  8459. && !fixed_regs[regno]
  8460. && regno != PIC_FUNCTION_ADDR_REGNUM)
  8461. return regno;
  8462. return GLOBAL_POINTER_REGNUM;
  8463. }
  8464. /* Return true if the current function's prologue must load the global
  8465. pointer value into pic_offset_table_rtx and store the same value in
  8466. the function's cprestore slot (if any).
  8467. One problem we have to deal with is that, when emitting GOT-based
  8468. position independent code, long-branch sequences will need to load
  8469. the address of the branch target from the GOT. We don't know until
  8470. the very end of compilation whether (and where) the function needs
  8471. long branches, so we must ensure that _any_ branch can access the
  8472. global pointer in some form. However, we do not want to pessimize
  8473. the usual case in which all branches are short.
  8474. We handle this as follows:
  8475. (1) During reload, we set cfun->machine->global_pointer to
  8476. INVALID_REGNUM if we _know_ that the current function
  8477. doesn't need a global pointer. This is only valid if
  8478. long branches don't need the GOT.
  8479. Otherwise, we assume that we might need a global pointer
  8480. and pick an appropriate register.
  8481. (2) If cfun->machine->global_pointer != INVALID_REGNUM,
  8482. we ensure that the global pointer is available at every
  8483. block boundary bar entry and exit. We do this in one of two ways:
  8484. - If the function has a cprestore slot, we ensure that this
  8485. slot is valid at every branch. However, as explained in
  8486. point (6) below, there is no guarantee that pic_offset_table_rtx
  8487. itself is valid if new uses of the global pointer are introduced
  8488. after the first post-epilogue split.
  8489. We guarantee that the cprestore slot is valid by loading it
  8490. into a fake register, CPRESTORE_SLOT_REGNUM. We then make
  8491. this register live at every block boundary bar function entry
  8492. and exit. It is then invalid to move the load (and thus the
  8493. preceding store) across a block boundary.
  8494. - If the function has no cprestore slot, we guarantee that
  8495. pic_offset_table_rtx itself is valid at every branch.
  8496. See mips_eh_uses for the handling of the register liveness.
  8497. (3) During prologue and epilogue generation, we emit "ghost"
  8498. placeholder instructions to manipulate the global pointer.
  8499. (4) During prologue generation, we set cfun->machine->must_initialize_gp_p
  8500. and cfun->machine->must_restore_gp_when_clobbered_p if we already know
  8501. that the function needs a global pointer. (There is no need to set
  8502. them earlier than this, and doing it as late as possible leads to
  8503. fewer false positives.)
  8504. (5) If cfun->machine->must_initialize_gp_p is true during a
  8505. split_insns pass, we split the ghost instructions into real
  8506. instructions. These split instructions can then be optimized in
  8507. the usual way. Otherwise, we keep the ghost instructions intact,
  8508. and optimize for the case where they aren't needed. We still
  8509. have the option of splitting them later, if we need to introduce
  8510. new uses of the global pointer.
  8511. For example, the scheduler ignores a ghost instruction that
  8512. stores $28 to the stack, but it handles the split form of
  8513. the ghost instruction as an ordinary store.
  8514. (6) [OldABI only.] If cfun->machine->must_restore_gp_when_clobbered_p
  8515. is true during the first post-epilogue split_insns pass, we split
  8516. calls and restore_gp patterns into instructions that explicitly
  8517. load pic_offset_table_rtx from the cprestore slot. Otherwise,
  8518. we split these patterns into instructions that _don't_ load from
  8519. the cprestore slot.
  8520. If cfun->machine->must_restore_gp_when_clobbered_p is true at the
  8521. time of the split, then any instructions that exist at that time
  8522. can make free use of pic_offset_table_rtx. However, if we want
  8523. to introduce new uses of the global pointer after the split,
  8524. we must explicitly load the value from the cprestore slot, since
  8525. pic_offset_table_rtx itself might not be valid at a given point
  8526. in the function.
  8527. The idea is that we want to be able to delete redundant
  8528. loads from the cprestore slot in the usual case where no
  8529. long branches are needed.
  8530. (7) If cfun->machine->must_initialize_gp_p is still false at the end
  8531. of md_reorg, we decide whether the global pointer is needed for
  8532. long branches. If so, we set cfun->machine->must_initialize_gp_p
  8533. to true and split the ghost instructions into real instructions
  8534. at that stage.
  8535. Note that the ghost instructions must have a zero length for three reasons:
  8536. - Giving the length of the underlying $gp sequence might cause
  8537. us to use long branches in cases where they aren't really needed.
  8538. - They would perturb things like alignment calculations.
  8539. - More importantly, the hazard detection in md_reorg relies on
  8540. empty instructions having a zero length.
  8541. If we find a long branch and split the ghost instructions at the
  8542. end of md_reorg, the split could introduce more long branches.
  8543. That isn't a problem though, because we still do the split before
  8544. the final shorten_branches pass.
  8545. This is extremely ugly, but it seems like the best compromise between
  8546. correctness and efficiency. */
  8547. bool
  8548. mips_must_initialize_gp_p (void)
  8549. {
  8550. return cfun->machine->must_initialize_gp_p;
  8551. }
  8552. /* Return true if REGNO is a register that is ordinarily call-clobbered
  8553. but must nevertheless be preserved by an interrupt handler. */
  8554. static bool
  8555. mips_interrupt_extra_call_saved_reg_p (unsigned int regno)
  8556. {
  8557. if ((ISA_HAS_HILO || TARGET_DSP)
  8558. && MD_REG_P (regno))
  8559. return true;
  8560. if (TARGET_DSP && DSP_ACC_REG_P (regno))
  8561. return true;
  8562. if (GP_REG_P (regno) && !cfun->machine->use_shadow_register_set_p)
  8563. {
  8564. /* $0 is hard-wired. */
  8565. if (regno == GP_REG_FIRST)
  8566. return false;
  8567. /* The interrupt handler can treat kernel registers as
  8568. scratch registers. */
  8569. if (KERNEL_REG_P (regno))
  8570. return false;
  8571. /* The function will return the stack pointer to its original value
  8572. anyway. */
  8573. if (regno == STACK_POINTER_REGNUM)
  8574. return false;
  8575. /* Otherwise, return true for registers that aren't ordinarily
  8576. call-clobbered. */
  8577. return call_really_used_regs[regno];
  8578. }
  8579. return false;
  8580. }
  8581. /* Return true if the current function should treat register REGNO
  8582. as call-saved. */
  8583. static bool
  8584. mips_cfun_call_saved_reg_p (unsigned int regno)
  8585. {
  8586. /* If the user makes an ordinarily-call-saved register global,
  8587. that register is no longer call-saved. */
  8588. if (global_regs[regno])
  8589. return false;
  8590. /* Interrupt handlers need to save extra registers. */
  8591. if (cfun->machine->interrupt_handler_p
  8592. && mips_interrupt_extra_call_saved_reg_p (regno))
  8593. return true;
  8594. /* call_insns preserve $28 unless they explicitly say otherwise,
  8595. so call_really_used_regs[] treats $28 as call-saved. However,
  8596. we want the ABI property rather than the default call_insn
  8597. property here. */
  8598. return (regno == GLOBAL_POINTER_REGNUM
  8599. ? TARGET_CALL_SAVED_GP
  8600. : !call_really_used_regs[regno]);
  8601. }
  8602. /* Return true if the function body might clobber register REGNO.
  8603. We know that REGNO is call-saved. */
  8604. static bool
  8605. mips_cfun_might_clobber_call_saved_reg_p (unsigned int regno)
  8606. {
  8607. /* Some functions should be treated as clobbering all call-saved
  8608. registers. */
  8609. if (crtl->saves_all_registers)
  8610. return true;
  8611. /* DF handles cases where a register is explicitly referenced in
  8612. the rtl. Incoming values are passed in call-clobbered registers,
  8613. so we can assume that any live call-saved register is set within
  8614. the function. */
  8615. if (df_regs_ever_live_p (regno))
  8616. return true;
  8617. /* Check for registers that are clobbered by FUNCTION_PROFILER.
  8618. These clobbers are not explicit in the rtl. */
  8619. if (crtl->profile && MIPS_SAVE_REG_FOR_PROFILING_P (regno))
  8620. return true;
  8621. /* If we're using a call-saved global pointer, the function's
  8622. prologue will need to set it up. */
  8623. if (cfun->machine->global_pointer == regno)
  8624. return true;
  8625. /* The function's prologue will need to set the frame pointer if
  8626. frame_pointer_needed. */
  8627. if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
  8628. return true;
  8629. /* If a MIPS16 function returns a value in FPRs, its epilogue
  8630. will need to call an external libgcc routine. This yet-to-be
  8631. generated call_insn will clobber $31. */
  8632. if (regno == RETURN_ADDR_REGNUM && mips16_cfun_returns_in_fpr_p ())
  8633. return true;
  8634. /* If REGNO is ordinarily call-clobbered, we must assume that any
  8635. called function could modify it. */
  8636. if (cfun->machine->interrupt_handler_p
  8637. && !crtl->is_leaf
  8638. && mips_interrupt_extra_call_saved_reg_p (regno))
  8639. return true;
  8640. return false;
  8641. }
  8642. /* Return true if the current function must save register REGNO. */
  8643. static bool
  8644. mips_save_reg_p (unsigned int regno)
  8645. {
  8646. if (mips_cfun_call_saved_reg_p (regno))
  8647. {
  8648. if (mips_cfun_might_clobber_call_saved_reg_p (regno))
  8649. return true;
  8650. /* Save both registers in an FPR pair if either one is used. This is
  8651. needed for the case when MIN_FPRS_PER_FMT == 1, which allows the odd
  8652. register to be used without the even register. */
  8653. if (FP_REG_P (regno)
  8654. && MAX_FPRS_PER_FMT == 2
  8655. && mips_cfun_might_clobber_call_saved_reg_p (regno + 1))
  8656. return true;
  8657. }
  8658. /* We need to save the incoming return address if __builtin_eh_return
  8659. is being used to set a different return address. */
  8660. if (regno == RETURN_ADDR_REGNUM && crtl->calls_eh_return)
  8661. return true;
  8662. return false;
  8663. }
  8664. /* Populate the current function's mips_frame_info structure.
  8665. MIPS stack frames look like:
  8666. +-------------------------------+
  8667. | |
  8668. | incoming stack arguments |
  8669. | |
  8670. +-------------------------------+
  8671. | |
  8672. | caller-allocated save area |
  8673. A | for register arguments |
  8674. | |
  8675. +-------------------------------+ <-- incoming stack pointer
  8676. | |
  8677. | callee-allocated save area |
  8678. B | for arguments that are |
  8679. | split between registers and |
  8680. | the stack |
  8681. | |
  8682. +-------------------------------+ <-- arg_pointer_rtx
  8683. | |
  8684. C | callee-allocated save area |
  8685. | for register varargs |
  8686. | |
  8687. +-------------------------------+ <-- frame_pointer_rtx
  8688. | | + cop0_sp_offset
  8689. | COP0 reg save area | + UNITS_PER_WORD
  8690. | |
  8691. +-------------------------------+ <-- frame_pointer_rtx + acc_sp_offset
  8692. | | + UNITS_PER_WORD
  8693. | accumulator save area |
  8694. | |
  8695. +-------------------------------+ <-- stack_pointer_rtx + fp_sp_offset
  8696. | | + UNITS_PER_HWFPVALUE
  8697. | FPR save area |
  8698. | |
  8699. +-------------------------------+ <-- stack_pointer_rtx + gp_sp_offset
  8700. | | + UNITS_PER_WORD
  8701. | GPR save area |
  8702. | |
  8703. +-------------------------------+ <-- frame_pointer_rtx with
  8704. | | \ -fstack-protector
  8705. | local variables | | var_size
  8706. | | /
  8707. +-------------------------------+
  8708. | | \
  8709. | $gp save area | | cprestore_size
  8710. | | /
  8711. P +-------------------------------+ <-- hard_frame_pointer_rtx for
  8712. | | \ MIPS16 code
  8713. | outgoing stack arguments | |
  8714. | | |
  8715. +-------------------------------+ | args_size
  8716. | | |
  8717. | caller-allocated save area | |
  8718. | for register arguments | |
  8719. | | /
  8720. +-------------------------------+ <-- stack_pointer_rtx
  8721. frame_pointer_rtx without
  8722. -fstack-protector
  8723. hard_frame_pointer_rtx for
  8724. non-MIPS16 code.
  8725. At least two of A, B and C will be empty.
  8726. Dynamic stack allocations such as alloca insert data at point P.
  8727. They decrease stack_pointer_rtx but leave frame_pointer_rtx and
  8728. hard_frame_pointer_rtx unchanged. */
  8729. static void
  8730. mips_compute_frame_info (void)
  8731. {
  8732. struct mips_frame_info *frame;
  8733. HOST_WIDE_INT offset, size;
  8734. unsigned int regno, i;
  8735. /* Set this function's interrupt properties. */
  8736. if (mips_interrupt_type_p (TREE_TYPE (current_function_decl)))
  8737. {
  8738. if (mips_isa_rev < 2)
  8739. error ("the %<interrupt%> attribute requires a MIPS32r2 processor or greater");
  8740. else if (TARGET_HARD_FLOAT)
  8741. error ("the %<interrupt%> attribute requires %<-msoft-float%>");
  8742. else if (TARGET_MIPS16)
  8743. error ("interrupt handlers cannot be MIPS16 functions");
  8744. else
  8745. {
  8746. cfun->machine->interrupt_handler_p = true;
  8747. cfun->machine->use_shadow_register_set_p =
  8748. mips_use_shadow_register_set_p (TREE_TYPE (current_function_decl));
  8749. cfun->machine->keep_interrupts_masked_p =
  8750. mips_keep_interrupts_masked_p (TREE_TYPE (current_function_decl));
  8751. cfun->machine->use_debug_exception_return_p =
  8752. mips_use_debug_exception_return_p (TREE_TYPE
  8753. (current_function_decl));
  8754. }
  8755. }
  8756. frame = &cfun->machine->frame;
  8757. memset (frame, 0, sizeof (*frame));
  8758. size = get_frame_size ();
  8759. cfun->machine->global_pointer = mips_global_pointer ();
  8760. /* The first two blocks contain the outgoing argument area and the $gp save
  8761. slot. This area isn't needed in leaf functions, but if the
  8762. target-independent frame size is nonzero, we have already committed to
  8763. allocating these in STARTING_FRAME_OFFSET for !FRAME_GROWS_DOWNWARD. */
  8764. if ((size == 0 || FRAME_GROWS_DOWNWARD) && crtl->is_leaf)
  8765. {
  8766. /* The MIPS 3.0 linker does not like functions that dynamically
  8767. allocate the stack and have 0 for STACK_DYNAMIC_OFFSET, since it
  8768. looks like we are trying to create a second frame pointer to the
  8769. function, so allocate some stack space to make it happy. */
  8770. if (cfun->calls_alloca)
  8771. frame->args_size = REG_PARM_STACK_SPACE (cfun->decl);
  8772. else
  8773. frame->args_size = 0;
  8774. frame->cprestore_size = 0;
  8775. }
  8776. else
  8777. {
  8778. frame->args_size = crtl->outgoing_args_size;
  8779. frame->cprestore_size = MIPS_GP_SAVE_AREA_SIZE;
  8780. }
  8781. offset = frame->args_size + frame->cprestore_size;
  8782. /* Move above the local variables. */
  8783. frame->var_size = MIPS_STACK_ALIGN (size);
  8784. offset += frame->var_size;
  8785. /* Find out which GPRs we need to save. */
  8786. for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++)
  8787. if (mips_save_reg_p (regno))
  8788. {
  8789. frame->num_gp++;
  8790. frame->mask |= 1 << (regno - GP_REG_FIRST);
  8791. }
  8792. /* If this function calls eh_return, we must also save and restore the
  8793. EH data registers. */
  8794. if (crtl->calls_eh_return)
  8795. for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; i++)
  8796. {
  8797. frame->num_gp++;
  8798. frame->mask |= 1 << (EH_RETURN_DATA_REGNO (i) - GP_REG_FIRST);
  8799. }
  8800. /* The MIPS16e SAVE and RESTORE instructions have two ranges of registers:
  8801. $a3-$a0 and $s2-$s8. If we save one register in the range, we must
  8802. save all later registers too. */
  8803. if (GENERATE_MIPS16E_SAVE_RESTORE)
  8804. {
  8805. mips16e_mask_registers (&frame->mask, mips16e_s2_s8_regs,
  8806. ARRAY_SIZE (mips16e_s2_s8_regs), &frame->num_gp);
  8807. mips16e_mask_registers (&frame->mask, mips16e_a0_a3_regs,
  8808. ARRAY_SIZE (mips16e_a0_a3_regs), &frame->num_gp);
  8809. }
  8810. /* Move above the GPR save area. */
  8811. if (frame->num_gp > 0)
  8812. {
  8813. offset += MIPS_STACK_ALIGN (frame->num_gp * UNITS_PER_WORD);
  8814. frame->gp_sp_offset = offset - UNITS_PER_WORD;
  8815. }
  8816. /* Find out which FPRs we need to save. This loop must iterate over
  8817. the same space as its companion in mips_for_each_saved_gpr_and_fpr. */
  8818. if (TARGET_HARD_FLOAT)
  8819. for (regno = FP_REG_FIRST; regno <= FP_REG_LAST; regno += MAX_FPRS_PER_FMT)
  8820. if (mips_save_reg_p (regno))
  8821. {
  8822. frame->num_fp += MAX_FPRS_PER_FMT;
  8823. frame->fmask |= ~(~0 << MAX_FPRS_PER_FMT) << (regno - FP_REG_FIRST);
  8824. }
  8825. /* Move above the FPR save area. */
  8826. if (frame->num_fp > 0)
  8827. {
  8828. offset += MIPS_STACK_ALIGN (frame->num_fp * UNITS_PER_FPREG);
  8829. frame->fp_sp_offset = offset - UNITS_PER_HWFPVALUE;
  8830. }
  8831. /* Add in space for the interrupt context information. */
  8832. if (cfun->machine->interrupt_handler_p)
  8833. {
  8834. /* Check HI/LO. */
  8835. if (mips_save_reg_p (LO_REGNUM) || mips_save_reg_p (HI_REGNUM))
  8836. {
  8837. frame->num_acc++;
  8838. frame->acc_mask |= (1 << 0);
  8839. }
  8840. /* Check accumulators 1, 2, 3. */
  8841. for (i = DSP_ACC_REG_FIRST; i <= DSP_ACC_REG_LAST; i += 2)
  8842. if (mips_save_reg_p (i) || mips_save_reg_p (i + 1))
  8843. {
  8844. frame->num_acc++;
  8845. frame->acc_mask |= 1 << (((i - DSP_ACC_REG_FIRST) / 2) + 1);
  8846. }
  8847. /* All interrupt context functions need space to preserve STATUS. */
  8848. frame->num_cop0_regs++;
  8849. /* If we don't keep interrupts masked, we need to save EPC. */
  8850. if (!cfun->machine->keep_interrupts_masked_p)
  8851. frame->num_cop0_regs++;
  8852. }
  8853. /* Move above the accumulator save area. */
  8854. if (frame->num_acc > 0)
  8855. {
  8856. /* Each accumulator needs 2 words. */
  8857. offset += frame->num_acc * 2 * UNITS_PER_WORD;
  8858. frame->acc_sp_offset = offset - UNITS_PER_WORD;
  8859. }
  8860. /* Move above the COP0 register save area. */
  8861. if (frame->num_cop0_regs > 0)
  8862. {
  8863. offset += frame->num_cop0_regs * UNITS_PER_WORD;
  8864. frame->cop0_sp_offset = offset - UNITS_PER_WORD;
  8865. }
  8866. /* Move above the callee-allocated varargs save area. */
  8867. offset += MIPS_STACK_ALIGN (cfun->machine->varargs_size);
  8868. frame->arg_pointer_offset = offset;
  8869. /* Move above the callee-allocated area for pretend stack arguments. */
  8870. offset += crtl->args.pretend_args_size;
  8871. frame->total_size = offset;
  8872. /* Work out the offsets of the save areas from the top of the frame. */
  8873. if (frame->gp_sp_offset > 0)
  8874. frame->gp_save_offset = frame->gp_sp_offset - offset;
  8875. if (frame->fp_sp_offset > 0)
  8876. frame->fp_save_offset = frame->fp_sp_offset - offset;
  8877. if (frame->acc_sp_offset > 0)
  8878. frame->acc_save_offset = frame->acc_sp_offset - offset;
  8879. if (frame->num_cop0_regs > 0)
  8880. frame->cop0_save_offset = frame->cop0_sp_offset - offset;
  8881. /* MIPS16 code offsets the frame pointer by the size of the outgoing
  8882. arguments. This tends to increase the chances of using unextended
  8883. instructions for local variables and incoming arguments. */
  8884. if (TARGET_MIPS16)
  8885. frame->hard_frame_pointer_offset = frame->args_size;
  8886. }
  8887. /* Return the style of GP load sequence that is being used for the
  8888. current function. */
  8889. enum mips_loadgp_style
  8890. mips_current_loadgp_style (void)
  8891. {
  8892. if (!TARGET_USE_GOT || cfun->machine->global_pointer == INVALID_REGNUM)
  8893. return LOADGP_NONE;
  8894. if (TARGET_RTP_PIC)
  8895. return LOADGP_RTP;
  8896. if (TARGET_ABSOLUTE_ABICALLS)
  8897. return LOADGP_ABSOLUTE;
  8898. return TARGET_NEWABI ? LOADGP_NEWABI : LOADGP_OLDABI;
  8899. }
  8900. /* Implement TARGET_FRAME_POINTER_REQUIRED. */
  8901. static bool
  8902. mips_frame_pointer_required (void)
  8903. {
  8904. /* If the function contains dynamic stack allocations, we need to
  8905. use the frame pointer to access the static parts of the frame. */
  8906. if (cfun->calls_alloca)
  8907. return true;
  8908. /* In MIPS16 mode, we need a frame pointer for a large frame; otherwise,
  8909. reload may be unable to compute the address of a local variable,
  8910. since there is no way to add a large constant to the stack pointer
  8911. without using a second temporary register. */
  8912. if (TARGET_MIPS16)
  8913. {
  8914. mips_compute_frame_info ();
  8915. if (!SMALL_OPERAND (cfun->machine->frame.total_size))
  8916. return true;
  8917. }
  8918. return false;
  8919. }
  8920. /* Make sure that we're not trying to eliminate to the wrong hard frame
  8921. pointer. */
  8922. static bool
  8923. mips_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
  8924. {
  8925. return (to == HARD_FRAME_POINTER_REGNUM || to == STACK_POINTER_REGNUM);
  8926. }
  8927. /* Implement INITIAL_ELIMINATION_OFFSET. FROM is either the frame pointer
  8928. or argument pointer. TO is either the stack pointer or hard frame
  8929. pointer. */
  8930. HOST_WIDE_INT
  8931. mips_initial_elimination_offset (int from, int to)
  8932. {
  8933. HOST_WIDE_INT offset;
  8934. mips_compute_frame_info ();
  8935. /* Set OFFSET to the offset from the end-of-prologue stack pointer. */
  8936. switch (from)
  8937. {
  8938. case FRAME_POINTER_REGNUM:
  8939. if (FRAME_GROWS_DOWNWARD)
  8940. offset = (cfun->machine->frame.args_size
  8941. + cfun->machine->frame.cprestore_size
  8942. + cfun->machine->frame.var_size);
  8943. else
  8944. offset = 0;
  8945. break;
  8946. case ARG_POINTER_REGNUM:
  8947. offset = cfun->machine->frame.arg_pointer_offset;
  8948. break;
  8949. default:
  8950. gcc_unreachable ();
  8951. }
  8952. if (to == HARD_FRAME_POINTER_REGNUM)
  8953. offset -= cfun->machine->frame.hard_frame_pointer_offset;
  8954. return offset;
  8955. }
  8956. /* Implement TARGET_EXTRA_LIVE_ON_ENTRY. */
  8957. static void
  8958. mips_extra_live_on_entry (bitmap regs)
  8959. {
  8960. if (TARGET_USE_GOT)
  8961. {
  8962. /* PIC_FUNCTION_ADDR_REGNUM is live if we need it to set up
  8963. the global pointer. */
  8964. if (!TARGET_ABSOLUTE_ABICALLS)
  8965. bitmap_set_bit (regs, PIC_FUNCTION_ADDR_REGNUM);
  8966. /* The prologue may set MIPS16_PIC_TEMP_REGNUM to the value of
  8967. the global pointer. */
  8968. if (TARGET_MIPS16)
  8969. bitmap_set_bit (regs, MIPS16_PIC_TEMP_REGNUM);
  8970. /* See the comment above load_call<mode> for details. */
  8971. bitmap_set_bit (regs, GOT_VERSION_REGNUM);
  8972. }
  8973. }
  8974. /* Implement RETURN_ADDR_RTX. We do not support moving back to a
  8975. previous frame. */
  8976. rtx
  8977. mips_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
  8978. {
  8979. if (count != 0)
  8980. return const0_rtx;
  8981. return get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM);
  8982. }
  8983. /* Emit code to change the current function's return address to
  8984. ADDRESS. SCRATCH is available as a scratch register, if needed.
  8985. ADDRESS and SCRATCH are both word-mode GPRs. */
  8986. void
  8987. mips_set_return_address (rtx address, rtx scratch)
  8988. {
  8989. rtx slot_address;
  8990. gcc_assert (BITSET_P (cfun->machine->frame.mask, RETURN_ADDR_REGNUM));
  8991. slot_address = mips_add_offset (scratch, stack_pointer_rtx,
  8992. cfun->machine->frame.gp_sp_offset);
  8993. mips_emit_move (gen_frame_mem (GET_MODE (address), slot_address), address);
  8994. }
  8995. /* Return true if the current function has a cprestore slot. */
  8996. bool
  8997. mips_cfun_has_cprestore_slot_p (void)
  8998. {
  8999. return (cfun->machine->global_pointer != INVALID_REGNUM
  9000. && cfun->machine->frame.cprestore_size > 0);
  9001. }
  9002. /* Fill *BASE and *OFFSET such that *BASE + *OFFSET refers to the
  9003. cprestore slot. LOAD_P is true if the caller wants to load from
  9004. the cprestore slot; it is false if the caller wants to store to
  9005. the slot. */
  9006. static void
  9007. mips_get_cprestore_base_and_offset (rtx *base, HOST_WIDE_INT *offset,
  9008. bool load_p)
  9009. {
  9010. const struct mips_frame_info *frame;
  9011. frame = &cfun->machine->frame;
  9012. /* .cprestore always uses the stack pointer instead of the frame pointer.
  9013. We have a free choice for direct stores for non-MIPS16 functions,
  9014. and for MIPS16 functions whose cprestore slot is in range of the
  9015. stack pointer. Using the stack pointer would sometimes give more
  9016. (early) scheduling freedom, but using the frame pointer would
  9017. sometimes give more (late) scheduling freedom. It's hard to
  9018. predict which applies to a given function, so let's keep things
  9019. simple.
  9020. Loads must always use the frame pointer in functions that call
  9021. alloca, and there's little benefit to using the stack pointer
  9022. otherwise. */
  9023. if (frame_pointer_needed && !(TARGET_CPRESTORE_DIRECTIVE && !load_p))
  9024. {
  9025. *base = hard_frame_pointer_rtx;
  9026. *offset = frame->args_size - frame->hard_frame_pointer_offset;
  9027. }
  9028. else
  9029. {
  9030. *base = stack_pointer_rtx;
  9031. *offset = frame->args_size;
  9032. }
  9033. }
  9034. /* Return true if X is the load or store address of the cprestore slot;
  9035. LOAD_P says which. */
  9036. bool
  9037. mips_cprestore_address_p (rtx x, bool load_p)
  9038. {
  9039. rtx given_base, required_base;
  9040. HOST_WIDE_INT given_offset, required_offset;
  9041. mips_split_plus (x, &given_base, &given_offset);
  9042. mips_get_cprestore_base_and_offset (&required_base, &required_offset, load_p);
  9043. return given_base == required_base && given_offset == required_offset;
  9044. }
  9045. /* Return a MEM rtx for the cprestore slot. LOAD_P is true if we are
  9046. going to load from it, false if we are going to store to it.
  9047. Use TEMP as a temporary register if need be. */
  9048. static rtx
  9049. mips_cprestore_slot (rtx temp, bool load_p)
  9050. {
  9051. rtx base;
  9052. HOST_WIDE_INT offset;
  9053. mips_get_cprestore_base_and_offset (&base, &offset, load_p);
  9054. return gen_frame_mem (Pmode, mips_add_offset (temp, base, offset));
  9055. }
  9056. /* Emit instructions to save global pointer value GP into cprestore
  9057. slot MEM. OFFSET is the offset that MEM applies to the base register.
  9058. MEM may not be a legitimate address. If it isn't, TEMP is a
  9059. temporary register that can be used, otherwise it is a SCRATCH. */
  9060. void
  9061. mips_save_gp_to_cprestore_slot (rtx mem, rtx offset, rtx gp, rtx temp)
  9062. {
  9063. if (TARGET_CPRESTORE_DIRECTIVE)
  9064. {
  9065. gcc_assert (gp == pic_offset_table_rtx);
  9066. emit_insn (PMODE_INSN (gen_cprestore, (mem, offset)));
  9067. }
  9068. else
  9069. mips_emit_move (mips_cprestore_slot (temp, false), gp);
  9070. }
  9071. /* Restore $gp from its save slot, using TEMP as a temporary base register
  9072. if need be. This function is for o32 and o64 abicalls only.
  9073. See mips_must_initialize_gp_p for details about how we manage the
  9074. global pointer. */
  9075. void
  9076. mips_restore_gp_from_cprestore_slot (rtx temp)
  9077. {
  9078. gcc_assert (TARGET_ABICALLS && TARGET_OLDABI && epilogue_completed);
  9079. if (!cfun->machine->must_restore_gp_when_clobbered_p)
  9080. {
  9081. emit_note (NOTE_INSN_DELETED);
  9082. return;
  9083. }
  9084. if (TARGET_MIPS16)
  9085. {
  9086. mips_emit_move (temp, mips_cprestore_slot (temp, true));
  9087. mips_emit_move (pic_offset_table_rtx, temp);
  9088. }
  9089. else
  9090. mips_emit_move (pic_offset_table_rtx, mips_cprestore_slot (temp, true));
  9091. if (!TARGET_EXPLICIT_RELOCS)
  9092. emit_insn (gen_blockage ());
  9093. }
  9094. /* A function to save or store a register. The first argument is the
  9095. register and the second is the stack slot. */
  9096. typedef void (*mips_save_restore_fn) (rtx, rtx);
  9097. /* Use FN to save or restore register REGNO. MODE is the register's
  9098. mode and OFFSET is the offset of its save slot from the current
  9099. stack pointer. */
  9100. static void
  9101. mips_save_restore_reg (machine_mode mode, int regno,
  9102. HOST_WIDE_INT offset, mips_save_restore_fn fn)
  9103. {
  9104. rtx mem;
  9105. mem = gen_frame_mem (mode, plus_constant (Pmode, stack_pointer_rtx,
  9106. offset));
  9107. fn (gen_rtx_REG (mode, regno), mem);
  9108. }
  9109. /* Call FN for each accumlator that is saved by the current function.
  9110. SP_OFFSET is the offset of the current stack pointer from the start
  9111. of the frame. */
  9112. static void
  9113. mips_for_each_saved_acc (HOST_WIDE_INT sp_offset, mips_save_restore_fn fn)
  9114. {
  9115. HOST_WIDE_INT offset;
  9116. int regno;
  9117. offset = cfun->machine->frame.acc_sp_offset - sp_offset;
  9118. if (BITSET_P (cfun->machine->frame.acc_mask, 0))
  9119. {
  9120. mips_save_restore_reg (word_mode, LO_REGNUM, offset, fn);
  9121. offset -= UNITS_PER_WORD;
  9122. mips_save_restore_reg (word_mode, HI_REGNUM, offset, fn);
  9123. offset -= UNITS_PER_WORD;
  9124. }
  9125. for (regno = DSP_ACC_REG_FIRST; regno <= DSP_ACC_REG_LAST; regno++)
  9126. if (BITSET_P (cfun->machine->frame.acc_mask,
  9127. ((regno - DSP_ACC_REG_FIRST) / 2) + 1))
  9128. {
  9129. mips_save_restore_reg (word_mode, regno, offset, fn);
  9130. offset -= UNITS_PER_WORD;
  9131. }
  9132. }
  9133. /* Save register REG to MEM. Make the instruction frame-related. */
  9134. static void
  9135. mips_save_reg (rtx reg, rtx mem)
  9136. {
  9137. if (GET_MODE (reg) == DFmode
  9138. && (!TARGET_FLOAT64
  9139. || mips_abi == ABI_32))
  9140. {
  9141. rtx x1, x2;
  9142. mips_emit_move_or_split (mem, reg, SPLIT_IF_NECESSARY);
  9143. x1 = mips_frame_set (mips_subword (mem, false),
  9144. mips_subword (reg, false));
  9145. x2 = mips_frame_set (mips_subword (mem, true),
  9146. mips_subword (reg, true));
  9147. mips_set_frame_expr (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, x1, x2)));
  9148. }
  9149. else
  9150. mips_emit_save_slot_move (mem, reg, MIPS_PROLOGUE_TEMP (GET_MODE (reg)));
  9151. }
  9152. /* Capture the register combinations that are allowed in a SWM or LWM
  9153. instruction. The entries are ordered by number of registers set in
  9154. the mask. We also ignore the single register encodings because a
  9155. normal SW/LW is preferred. */
  9156. static const unsigned int umips_swm_mask[17] = {
  9157. 0xc0ff0000, 0x80ff0000, 0x40ff0000, 0x807f0000,
  9158. 0x00ff0000, 0x803f0000, 0x007f0000, 0x801f0000,
  9159. 0x003f0000, 0x800f0000, 0x001f0000, 0x80070000,
  9160. 0x000f0000, 0x80030000, 0x00070000, 0x80010000,
  9161. 0x00030000
  9162. };
  9163. static const unsigned int umips_swm_encoding[17] = {
  9164. 25, 24, 9, 23, 8, 22, 7, 21, 6, 20, 5, 19, 4, 18, 3, 17, 2
  9165. };
  9166. /* Try to use a microMIPS LWM or SWM instruction to save or restore
  9167. as many GPRs in *MASK as possible. *OFFSET is the offset from the
  9168. stack pointer of the topmost save slot.
  9169. Remove from *MASK all registers that were handled using LWM and SWM.
  9170. Update *OFFSET so that it points to the first unused save slot. */
  9171. static bool
  9172. umips_build_save_restore (mips_save_restore_fn fn,
  9173. unsigned *mask, HOST_WIDE_INT *offset)
  9174. {
  9175. int nregs;
  9176. unsigned int i, j;
  9177. rtx pattern, set, reg, mem;
  9178. HOST_WIDE_INT this_offset;
  9179. rtx this_base;
  9180. /* Try matching $16 to $31 (s0 to ra). */
  9181. for (i = 0; i < ARRAY_SIZE (umips_swm_mask); i++)
  9182. if ((*mask & 0xffff0000) == umips_swm_mask[i])
  9183. break;
  9184. if (i == ARRAY_SIZE (umips_swm_mask))
  9185. return false;
  9186. /* Get the offset of the lowest save slot. */
  9187. nregs = (umips_swm_encoding[i] & 0xf) + (umips_swm_encoding[i] >> 4);
  9188. this_offset = *offset - UNITS_PER_WORD * (nregs - 1);
  9189. /* LWM/SWM can only support offsets from -2048 to 2047. */
  9190. if (!UMIPS_12BIT_OFFSET_P (this_offset))
  9191. return false;
  9192. /* Create the final PARALLEL. */
  9193. pattern = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs));
  9194. this_base = stack_pointer_rtx;
  9195. /* For registers $16-$23 and $30. */
  9196. for (j = 0; j < (umips_swm_encoding[i] & 0xf); j++)
  9197. {
  9198. HOST_WIDE_INT offset = this_offset + j * UNITS_PER_WORD;
  9199. mem = gen_frame_mem (SImode, plus_constant (Pmode, this_base, offset));
  9200. unsigned int regno = (j != 8) ? 16 + j : 30;
  9201. *mask &= ~(1 << regno);
  9202. reg = gen_rtx_REG (SImode, regno);
  9203. if (fn == mips_save_reg)
  9204. set = mips_frame_set (mem, reg);
  9205. else
  9206. {
  9207. set = gen_rtx_SET (VOIDmode, reg, mem);
  9208. mips_add_cfa_restore (reg);
  9209. }
  9210. XVECEXP (pattern, 0, j) = set;
  9211. }
  9212. /* For register $31. */
  9213. if (umips_swm_encoding[i] >> 4)
  9214. {
  9215. HOST_WIDE_INT offset = this_offset + j * UNITS_PER_WORD;
  9216. *mask &= ~(1 << 31);
  9217. mem = gen_frame_mem (SImode, plus_constant (Pmode, this_base, offset));
  9218. reg = gen_rtx_REG (SImode, 31);
  9219. if (fn == mips_save_reg)
  9220. set = mips_frame_set (mem, reg);
  9221. else
  9222. {
  9223. set = gen_rtx_SET (VOIDmode, reg, mem);
  9224. mips_add_cfa_restore (reg);
  9225. }
  9226. XVECEXP (pattern, 0, j) = set;
  9227. }
  9228. pattern = emit_insn (pattern);
  9229. if (fn == mips_save_reg)
  9230. RTX_FRAME_RELATED_P (pattern) = 1;
  9231. /* Adjust the last offset. */
  9232. *offset -= UNITS_PER_WORD * nregs;
  9233. return true;
  9234. }
  9235. /* Call FN for each register that is saved by the current function.
  9236. SP_OFFSET is the offset of the current stack pointer from the start
  9237. of the frame. */
  9238. static void
  9239. mips_for_each_saved_gpr_and_fpr (HOST_WIDE_INT sp_offset,
  9240. mips_save_restore_fn fn)
  9241. {
  9242. machine_mode fpr_mode;
  9243. int regno;
  9244. const struct mips_frame_info *frame = &cfun->machine->frame;
  9245. HOST_WIDE_INT offset;
  9246. unsigned int mask;
  9247. /* Save registers starting from high to low. The debuggers prefer at least
  9248. the return register be stored at func+4, and also it allows us not to
  9249. need a nop in the epilogue if at least one register is reloaded in
  9250. addition to return address. */
  9251. offset = frame->gp_sp_offset - sp_offset;
  9252. mask = frame->mask;
  9253. if (TARGET_MICROMIPS)
  9254. umips_build_save_restore (fn, &mask, &offset);
  9255. for (regno = GP_REG_LAST; regno >= GP_REG_FIRST; regno--)
  9256. if (BITSET_P (mask, regno - GP_REG_FIRST))
  9257. {
  9258. /* Record the ra offset for use by mips_function_profiler. */
  9259. if (regno == RETURN_ADDR_REGNUM)
  9260. cfun->machine->frame.ra_fp_offset = offset + sp_offset;
  9261. mips_save_restore_reg (word_mode, regno, offset, fn);
  9262. offset -= UNITS_PER_WORD;
  9263. }
  9264. /* This loop must iterate over the same space as its companion in
  9265. mips_compute_frame_info. */
  9266. offset = cfun->machine->frame.fp_sp_offset - sp_offset;
  9267. fpr_mode = (TARGET_SINGLE_FLOAT ? SFmode : DFmode);
  9268. for (regno = FP_REG_LAST - MAX_FPRS_PER_FMT + 1;
  9269. regno >= FP_REG_FIRST;
  9270. regno -= MAX_FPRS_PER_FMT)
  9271. if (BITSET_P (cfun->machine->frame.fmask, regno - FP_REG_FIRST))
  9272. {
  9273. if (!TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT
  9274. && (fixed_regs[regno] || fixed_regs[regno + 1]))
  9275. {
  9276. if (fixed_regs[regno])
  9277. mips_save_restore_reg (SFmode, regno + 1, offset, fn);
  9278. else
  9279. mips_save_restore_reg (SFmode, regno, offset, fn);
  9280. }
  9281. else
  9282. mips_save_restore_reg (fpr_mode, regno, offset, fn);
  9283. offset -= GET_MODE_SIZE (fpr_mode);
  9284. }
  9285. }
  9286. /* Return true if a move between register REGNO and its save slot (MEM)
  9287. can be done in a single move. LOAD_P is true if we are loading
  9288. from the slot, false if we are storing to it. */
  9289. static bool
  9290. mips_direct_save_slot_move_p (unsigned int regno, rtx mem, bool load_p)
  9291. {
  9292. /* There is a specific MIPS16 instruction for saving $31 to the stack. */
  9293. if (TARGET_MIPS16 && !load_p && regno == RETURN_ADDR_REGNUM)
  9294. return false;
  9295. return mips_secondary_reload_class (REGNO_REG_CLASS (regno),
  9296. GET_MODE (mem), mem, load_p) == NO_REGS;
  9297. }
  9298. /* Emit a move from SRC to DEST, given that one of them is a register
  9299. save slot and that the other is a register. TEMP is a temporary
  9300. GPR of the same mode that is available if need be. */
  9301. void
  9302. mips_emit_save_slot_move (rtx dest, rtx src, rtx temp)
  9303. {
  9304. unsigned int regno;
  9305. rtx mem;
  9306. if (REG_P (src))
  9307. {
  9308. regno = REGNO (src);
  9309. mem = dest;
  9310. }
  9311. else
  9312. {
  9313. regno = REGNO (dest);
  9314. mem = src;
  9315. }
  9316. if (regno == cfun->machine->global_pointer && !mips_must_initialize_gp_p ())
  9317. {
  9318. /* We don't yet know whether we'll need this instruction or not.
  9319. Postpone the decision by emitting a ghost move. This move
  9320. is specifically not frame-related; only the split version is. */
  9321. if (TARGET_64BIT)
  9322. emit_insn (gen_move_gpdi (dest, src));
  9323. else
  9324. emit_insn (gen_move_gpsi (dest, src));
  9325. return;
  9326. }
  9327. if (regno == HI_REGNUM)
  9328. {
  9329. if (REG_P (dest))
  9330. {
  9331. mips_emit_move (temp, src);
  9332. if (TARGET_64BIT)
  9333. emit_insn (gen_mthisi_di (gen_rtx_REG (TImode, MD_REG_FIRST),
  9334. temp, gen_rtx_REG (DImode, LO_REGNUM)));
  9335. else
  9336. emit_insn (gen_mthisi_di (gen_rtx_REG (DImode, MD_REG_FIRST),
  9337. temp, gen_rtx_REG (SImode, LO_REGNUM)));
  9338. }
  9339. else
  9340. {
  9341. if (TARGET_64BIT)
  9342. emit_insn (gen_mfhidi_ti (temp,
  9343. gen_rtx_REG (TImode, MD_REG_FIRST)));
  9344. else
  9345. emit_insn (gen_mfhisi_di (temp,
  9346. gen_rtx_REG (DImode, MD_REG_FIRST)));
  9347. mips_emit_move (dest, temp);
  9348. }
  9349. }
  9350. else if (mips_direct_save_slot_move_p (regno, mem, mem == src))
  9351. mips_emit_move (dest, src);
  9352. else
  9353. {
  9354. gcc_assert (!reg_overlap_mentioned_p (dest, temp));
  9355. mips_emit_move (temp, src);
  9356. mips_emit_move (dest, temp);
  9357. }
  9358. if (MEM_P (dest))
  9359. mips_set_frame_expr (mips_frame_set (dest, src));
  9360. }
  9361. /* If we're generating n32 or n64 abicalls, and the current function
  9362. does not use $28 as its global pointer, emit a cplocal directive.
  9363. Use pic_offset_table_rtx as the argument to the directive. */
  9364. static void
  9365. mips_output_cplocal (void)
  9366. {
  9367. if (!TARGET_EXPLICIT_RELOCS
  9368. && mips_must_initialize_gp_p ()
  9369. && cfun->machine->global_pointer != GLOBAL_POINTER_REGNUM)
  9370. output_asm_insn (".cplocal %+", 0);
  9371. }
  9372. /* Implement TARGET_OUTPUT_FUNCTION_PROLOGUE. */
  9373. static void
  9374. mips_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
  9375. {
  9376. const char *fnname;
  9377. /* In MIPS16 mode, we may need to generate a non-MIPS16 stub to handle
  9378. floating-point arguments. */
  9379. if (TARGET_MIPS16
  9380. && TARGET_HARD_FLOAT_ABI
  9381. && crtl->args.info.fp_code != 0)
  9382. mips16_build_function_stub ();
  9383. /* Get the function name the same way that toplev.c does before calling
  9384. assemble_start_function. This is needed so that the name used here
  9385. exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
  9386. fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
  9387. mips_start_function_definition (fnname, TARGET_MIPS16);
  9388. /* Output MIPS-specific frame information. */
  9389. if (!flag_inhibit_size_directive)
  9390. {
  9391. const struct mips_frame_info *frame;
  9392. frame = &cfun->machine->frame;
  9393. /* .frame FRAMEREG, FRAMESIZE, RETREG. */
  9394. fprintf (file,
  9395. "\t.frame\t%s," HOST_WIDE_INT_PRINT_DEC ",%s\t\t"
  9396. "# vars= " HOST_WIDE_INT_PRINT_DEC
  9397. ", regs= %d/%d"
  9398. ", args= " HOST_WIDE_INT_PRINT_DEC
  9399. ", gp= " HOST_WIDE_INT_PRINT_DEC "\n",
  9400. reg_names[frame_pointer_needed
  9401. ? HARD_FRAME_POINTER_REGNUM
  9402. : STACK_POINTER_REGNUM],
  9403. (frame_pointer_needed
  9404. ? frame->total_size - frame->hard_frame_pointer_offset
  9405. : frame->total_size),
  9406. reg_names[RETURN_ADDR_REGNUM],
  9407. frame->var_size,
  9408. frame->num_gp, frame->num_fp,
  9409. frame->args_size,
  9410. frame->cprestore_size);
  9411. /* .mask MASK, OFFSET. */
  9412. fprintf (file, "\t.mask\t0x%08x," HOST_WIDE_INT_PRINT_DEC "\n",
  9413. frame->mask, frame->gp_save_offset);
  9414. /* .fmask MASK, OFFSET. */
  9415. fprintf (file, "\t.fmask\t0x%08x," HOST_WIDE_INT_PRINT_DEC "\n",
  9416. frame->fmask, frame->fp_save_offset);
  9417. }
  9418. /* Handle the initialization of $gp for SVR4 PIC, if applicable.
  9419. Also emit the ".set noreorder; .set nomacro" sequence for functions
  9420. that need it. */
  9421. if (mips_must_initialize_gp_p ()
  9422. && mips_current_loadgp_style () == LOADGP_OLDABI)
  9423. {
  9424. if (TARGET_MIPS16)
  9425. {
  9426. /* This is a fixed-form sequence. The position of the
  9427. first two instructions is important because of the
  9428. way _gp_disp is defined. */
  9429. output_asm_insn ("li\t$2,%%hi(_gp_disp)", 0);
  9430. output_asm_insn ("addiu\t$3,$pc,%%lo(_gp_disp)", 0);
  9431. output_asm_insn ("sll\t$2,16", 0);
  9432. output_asm_insn ("addu\t$2,$3", 0);
  9433. }
  9434. else
  9435. {
  9436. /* .cpload must be in a .set noreorder but not a
  9437. .set nomacro block. */
  9438. mips_push_asm_switch (&mips_noreorder);
  9439. output_asm_insn (".cpload\t%^", 0);
  9440. if (!cfun->machine->all_noreorder_p)
  9441. mips_pop_asm_switch (&mips_noreorder);
  9442. else
  9443. mips_push_asm_switch (&mips_nomacro);
  9444. }
  9445. }
  9446. else if (cfun->machine->all_noreorder_p)
  9447. {
  9448. mips_push_asm_switch (&mips_noreorder);
  9449. mips_push_asm_switch (&mips_nomacro);
  9450. }
  9451. /* Tell the assembler which register we're using as the global
  9452. pointer. This is needed for thunks, since they can use either
  9453. explicit relocs or assembler macros. */
  9454. mips_output_cplocal ();
  9455. }
  9456. /* Implement TARGET_OUTPUT_FUNCTION_EPILOGUE. */
  9457. static void
  9458. mips_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
  9459. HOST_WIDE_INT size ATTRIBUTE_UNUSED)
  9460. {
  9461. const char *fnname;
  9462. /* Reinstate the normal $gp. */
  9463. SET_REGNO (pic_offset_table_rtx, GLOBAL_POINTER_REGNUM);
  9464. mips_output_cplocal ();
  9465. if (cfun->machine->all_noreorder_p)
  9466. {
  9467. mips_pop_asm_switch (&mips_nomacro);
  9468. mips_pop_asm_switch (&mips_noreorder);
  9469. }
  9470. /* Get the function name the same way that toplev.c does before calling
  9471. assemble_start_function. This is needed so that the name used here
  9472. exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
  9473. fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
  9474. mips_end_function_definition (fnname);
  9475. }
  9476. /* Emit an optimisation barrier for accesses to the current frame. */
  9477. static void
  9478. mips_frame_barrier (void)
  9479. {
  9480. emit_clobber (gen_frame_mem (BLKmode, stack_pointer_rtx));
  9481. }
  9482. /* The __gnu_local_gp symbol. */
  9483. static GTY(()) rtx mips_gnu_local_gp;
  9484. /* If we're generating n32 or n64 abicalls, emit instructions
  9485. to set up the global pointer. */
  9486. static void
  9487. mips_emit_loadgp (void)
  9488. {
  9489. rtx addr, offset, incoming_address, base, index, pic_reg;
  9490. pic_reg = TARGET_MIPS16 ? MIPS16_PIC_TEMP : pic_offset_table_rtx;
  9491. switch (mips_current_loadgp_style ())
  9492. {
  9493. case LOADGP_ABSOLUTE:
  9494. if (mips_gnu_local_gp == NULL)
  9495. {
  9496. mips_gnu_local_gp = gen_rtx_SYMBOL_REF (Pmode, "__gnu_local_gp");
  9497. SYMBOL_REF_FLAGS (mips_gnu_local_gp) |= SYMBOL_FLAG_LOCAL;
  9498. }
  9499. emit_insn (PMODE_INSN (gen_loadgp_absolute,
  9500. (pic_reg, mips_gnu_local_gp)));
  9501. break;
  9502. case LOADGP_OLDABI:
  9503. /* Added by mips_output_function_prologue. */
  9504. break;
  9505. case LOADGP_NEWABI:
  9506. addr = XEXP (DECL_RTL (current_function_decl), 0);
  9507. offset = mips_unspec_address (addr, SYMBOL_GOTOFF_LOADGP);
  9508. incoming_address = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
  9509. emit_insn (PMODE_INSN (gen_loadgp_newabi,
  9510. (pic_reg, offset, incoming_address)));
  9511. break;
  9512. case LOADGP_RTP:
  9513. base = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (VXWORKS_GOTT_BASE));
  9514. index = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (VXWORKS_GOTT_INDEX));
  9515. emit_insn (PMODE_INSN (gen_loadgp_rtp, (pic_reg, base, index)));
  9516. break;
  9517. default:
  9518. return;
  9519. }
  9520. if (TARGET_MIPS16)
  9521. emit_insn (PMODE_INSN (gen_copygp_mips16,
  9522. (pic_offset_table_rtx, pic_reg)));
  9523. /* Emit a blockage if there are implicit uses of the GP register.
  9524. This includes profiled functions, because FUNCTION_PROFILE uses
  9525. a jal macro. */
  9526. if (!TARGET_EXPLICIT_RELOCS || crtl->profile)
  9527. emit_insn (gen_loadgp_blockage ());
  9528. }
  9529. #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
  9530. #if PROBE_INTERVAL > 32768
  9531. #error Cannot use indexed addressing mode for stack probing
  9532. #endif
  9533. /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
  9534. inclusive. These are offsets from the current stack pointer. */
  9535. static void
  9536. mips_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
  9537. {
  9538. if (TARGET_MIPS16)
  9539. sorry ("-fstack-check=specific not implemented for MIPS16");
  9540. /* See if we have a constant small number of probes to generate. If so,
  9541. that's the easy case. */
  9542. if (first + size <= 32768)
  9543. {
  9544. HOST_WIDE_INT i;
  9545. /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
  9546. it exceeds SIZE. If only one probe is needed, this will not
  9547. generate any code. Then probe at FIRST + SIZE. */
  9548. for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
  9549. emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
  9550. -(first + i)));
  9551. emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
  9552. -(first + size)));
  9553. }
  9554. /* Otherwise, do the same as above, but in a loop. Note that we must be
  9555. extra careful with variables wrapping around because we might be at
  9556. the very top (or the very bottom) of the address space and we have
  9557. to be able to handle this case properly; in particular, we use an
  9558. equality test for the loop condition. */
  9559. else
  9560. {
  9561. HOST_WIDE_INT rounded_size;
  9562. rtx r3 = MIPS_PROLOGUE_TEMP (Pmode);
  9563. rtx r12 = MIPS_PROLOGUE_TEMP2 (Pmode);
  9564. /* Sanity check for the addressing mode we're going to use. */
  9565. gcc_assert (first <= 32768);
  9566. /* Step 1: round SIZE to the previous multiple of the interval. */
  9567. rounded_size = size & -PROBE_INTERVAL;
  9568. /* Step 2: compute initial and final value of the loop counter. */
  9569. /* TEST_ADDR = SP + FIRST. */
  9570. emit_insn (gen_rtx_SET (VOIDmode, r3,
  9571. plus_constant (Pmode, stack_pointer_rtx,
  9572. -first)));
  9573. /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
  9574. if (rounded_size > 32768)
  9575. {
  9576. emit_move_insn (r12, GEN_INT (rounded_size));
  9577. emit_insn (gen_rtx_SET (VOIDmode, r12,
  9578. gen_rtx_MINUS (Pmode, r3, r12)));
  9579. }
  9580. else
  9581. emit_insn (gen_rtx_SET (VOIDmode, r12,
  9582. plus_constant (Pmode, r3, -rounded_size)));
  9583. /* Step 3: the loop
  9584. while (TEST_ADDR != LAST_ADDR)
  9585. {
  9586. TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
  9587. probe at TEST_ADDR
  9588. }
  9589. probes at FIRST + N * PROBE_INTERVAL for values of N from 1
  9590. until it is equal to ROUNDED_SIZE. */
  9591. emit_insn (PMODE_INSN (gen_probe_stack_range, (r3, r3, r12)));
  9592. /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
  9593. that SIZE is equal to ROUNDED_SIZE. */
  9594. if (size != rounded_size)
  9595. emit_stack_probe (plus_constant (Pmode, r12, rounded_size - size));
  9596. }
  9597. /* Make sure nothing is scheduled before we are done. */
  9598. emit_insn (gen_blockage ());
  9599. }
  9600. /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
  9601. absolute addresses. */
  9602. const char *
  9603. mips_output_probe_stack_range (rtx reg1, rtx reg2)
  9604. {
  9605. static int labelno = 0;
  9606. char loop_lab[32], end_lab[32], tmp[64];
  9607. rtx xops[2];
  9608. ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
  9609. ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
  9610. ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
  9611. /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
  9612. xops[0] = reg1;
  9613. xops[1] = reg2;
  9614. strcpy (tmp, "%(%<beq\t%0,%1,");
  9615. output_asm_insn (strcat (tmp, &end_lab[1]), xops);
  9616. /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
  9617. xops[1] = GEN_INT (-PROBE_INTERVAL);
  9618. if (TARGET_64BIT && TARGET_LONG64)
  9619. output_asm_insn ("daddiu\t%0,%0,%1", xops);
  9620. else
  9621. output_asm_insn ("addiu\t%0,%0,%1", xops);
  9622. /* Probe at TEST_ADDR and branch. */
  9623. fprintf (asm_out_file, "\tb\t");
  9624. assemble_name_raw (asm_out_file, loop_lab);
  9625. fputc ('\n', asm_out_file);
  9626. if (TARGET_64BIT)
  9627. output_asm_insn ("sd\t$0,0(%0)%)", xops);
  9628. else
  9629. output_asm_insn ("sw\t$0,0(%0)%)", xops);
  9630. ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
  9631. return "";
  9632. }
  9633. /* Return true if X contains a kernel register. */
  9634. static bool
  9635. mips_refers_to_kernel_reg_p (const_rtx x)
  9636. {
  9637. subrtx_iterator::array_type array;
  9638. FOR_EACH_SUBRTX (iter, array, x, NONCONST)
  9639. if (REG_P (*iter) && KERNEL_REG_P (REGNO (*iter)))
  9640. return true;
  9641. return false;
  9642. }
  9643. /* Expand the "prologue" pattern. */
  9644. void
  9645. mips_expand_prologue (void)
  9646. {
  9647. const struct mips_frame_info *frame;
  9648. HOST_WIDE_INT size;
  9649. unsigned int nargs;
  9650. if (cfun->machine->global_pointer != INVALID_REGNUM)
  9651. {
  9652. /* Check whether an insn uses pic_offset_table_rtx, either explicitly
  9653. or implicitly. If so, we can commit to using a global pointer
  9654. straight away, otherwise we need to defer the decision. */
  9655. if (mips_cfun_has_inflexible_gp_ref_p ()
  9656. || mips_cfun_has_flexible_gp_ref_p ())
  9657. {
  9658. cfun->machine->must_initialize_gp_p = true;
  9659. cfun->machine->must_restore_gp_when_clobbered_p = true;
  9660. }
  9661. SET_REGNO (pic_offset_table_rtx, cfun->machine->global_pointer);
  9662. }
  9663. frame = &cfun->machine->frame;
  9664. size = frame->total_size;
  9665. if (flag_stack_usage_info)
  9666. current_function_static_stack_size = size;
  9667. if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
  9668. {
  9669. if (crtl->is_leaf && !cfun->calls_alloca)
  9670. {
  9671. if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
  9672. mips_emit_probe_stack_range (STACK_CHECK_PROTECT,
  9673. size - STACK_CHECK_PROTECT);
  9674. }
  9675. else if (size > 0)
  9676. mips_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
  9677. }
  9678. /* Save the registers. Allocate up to MIPS_MAX_FIRST_STACK_STEP
  9679. bytes beforehand; this is enough to cover the register save area
  9680. without going out of range. */
  9681. if (((frame->mask | frame->fmask | frame->acc_mask) != 0)
  9682. || frame->num_cop0_regs > 0)
  9683. {
  9684. HOST_WIDE_INT step1;
  9685. step1 = MIN (size, MIPS_MAX_FIRST_STACK_STEP);
  9686. if (GENERATE_MIPS16E_SAVE_RESTORE)
  9687. {
  9688. HOST_WIDE_INT offset;
  9689. unsigned int mask, regno;
  9690. /* Try to merge argument stores into the save instruction. */
  9691. nargs = mips16e_collect_argument_saves ();
  9692. /* Build the save instruction. */
  9693. mask = frame->mask;
  9694. rtx insn = mips16e_build_save_restore (false, &mask, &offset,
  9695. nargs, step1);
  9696. RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
  9697. mips_frame_barrier ();
  9698. size -= step1;
  9699. /* Check if we need to save other registers. */
  9700. for (regno = GP_REG_FIRST; regno < GP_REG_LAST; regno++)
  9701. if (BITSET_P (mask, regno - GP_REG_FIRST))
  9702. {
  9703. offset -= UNITS_PER_WORD;
  9704. mips_save_restore_reg (word_mode, regno,
  9705. offset, mips_save_reg);
  9706. }
  9707. }
  9708. else
  9709. {
  9710. if (cfun->machine->interrupt_handler_p)
  9711. {
  9712. HOST_WIDE_INT offset;
  9713. rtx mem;
  9714. /* If this interrupt is using a shadow register set, we need to
  9715. get the stack pointer from the previous register set. */
  9716. if (cfun->machine->use_shadow_register_set_p)
  9717. emit_insn (gen_mips_rdpgpr (stack_pointer_rtx,
  9718. stack_pointer_rtx));
  9719. if (!cfun->machine->keep_interrupts_masked_p)
  9720. {
  9721. /* Move from COP0 Cause to K0. */
  9722. emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K0_REG_NUM),
  9723. gen_rtx_REG (SImode,
  9724. COP0_CAUSE_REG_NUM)));
  9725. /* Move from COP0 EPC to K1. */
  9726. emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM),
  9727. gen_rtx_REG (SImode,
  9728. COP0_EPC_REG_NUM)));
  9729. }
  9730. /* Allocate the first part of the frame. */
  9731. rtx insn = gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx,
  9732. GEN_INT (-step1));
  9733. RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
  9734. mips_frame_barrier ();
  9735. size -= step1;
  9736. /* Start at the uppermost location for saving. */
  9737. offset = frame->cop0_sp_offset - size;
  9738. if (!cfun->machine->keep_interrupts_masked_p)
  9739. {
  9740. /* Push EPC into its stack slot. */
  9741. mem = gen_frame_mem (word_mode,
  9742. plus_constant (Pmode, stack_pointer_rtx,
  9743. offset));
  9744. mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM));
  9745. offset -= UNITS_PER_WORD;
  9746. }
  9747. /* Move from COP0 Status to K1. */
  9748. emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM),
  9749. gen_rtx_REG (SImode,
  9750. COP0_STATUS_REG_NUM)));
  9751. /* Right justify the RIPL in k0. */
  9752. if (!cfun->machine->keep_interrupts_masked_p)
  9753. emit_insn (gen_lshrsi3 (gen_rtx_REG (SImode, K0_REG_NUM),
  9754. gen_rtx_REG (SImode, K0_REG_NUM),
  9755. GEN_INT (CAUSE_IPL)));
  9756. /* Push Status into its stack slot. */
  9757. mem = gen_frame_mem (word_mode,
  9758. plus_constant (Pmode, stack_pointer_rtx,
  9759. offset));
  9760. mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM));
  9761. offset -= UNITS_PER_WORD;
  9762. /* Insert the RIPL into our copy of SR (k1) as the new IPL. */
  9763. if (!cfun->machine->keep_interrupts_masked_p)
  9764. emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
  9765. GEN_INT (6),
  9766. GEN_INT (SR_IPL),
  9767. gen_rtx_REG (SImode, K0_REG_NUM)));
  9768. if (!cfun->machine->keep_interrupts_masked_p)
  9769. /* Enable interrupts by clearing the KSU ERL and EXL bits.
  9770. IE is already the correct value, so we don't have to do
  9771. anything explicit. */
  9772. emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
  9773. GEN_INT (4),
  9774. GEN_INT (SR_EXL),
  9775. gen_rtx_REG (SImode, GP_REG_FIRST)));
  9776. else
  9777. /* Disable interrupts by clearing the KSU, ERL, EXL,
  9778. and IE bits. */
  9779. emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
  9780. GEN_INT (5),
  9781. GEN_INT (SR_IE),
  9782. gen_rtx_REG (SImode, GP_REG_FIRST)));
  9783. }
  9784. else
  9785. {
  9786. rtx insn = gen_add3_insn (stack_pointer_rtx,
  9787. stack_pointer_rtx,
  9788. GEN_INT (-step1));
  9789. RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
  9790. mips_frame_barrier ();
  9791. size -= step1;
  9792. }
  9793. mips_for_each_saved_acc (size, mips_save_reg);
  9794. mips_for_each_saved_gpr_and_fpr (size, mips_save_reg);
  9795. }
  9796. }
  9797. /* Allocate the rest of the frame. */
  9798. if (size > 0)
  9799. {
  9800. if (SMALL_OPERAND (-size))
  9801. RTX_FRAME_RELATED_P (emit_insn (gen_add3_insn (stack_pointer_rtx,
  9802. stack_pointer_rtx,
  9803. GEN_INT (-size)))) = 1;
  9804. else
  9805. {
  9806. mips_emit_move (MIPS_PROLOGUE_TEMP (Pmode), GEN_INT (size));
  9807. if (TARGET_MIPS16)
  9808. {
  9809. /* There are no instructions to add or subtract registers
  9810. from the stack pointer, so use the frame pointer as a
  9811. temporary. We should always be using a frame pointer
  9812. in this case anyway. */
  9813. gcc_assert (frame_pointer_needed);
  9814. mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx);
  9815. emit_insn (gen_sub3_insn (hard_frame_pointer_rtx,
  9816. hard_frame_pointer_rtx,
  9817. MIPS_PROLOGUE_TEMP (Pmode)));
  9818. mips_emit_move (stack_pointer_rtx, hard_frame_pointer_rtx);
  9819. }
  9820. else
  9821. emit_insn (gen_sub3_insn (stack_pointer_rtx,
  9822. stack_pointer_rtx,
  9823. MIPS_PROLOGUE_TEMP (Pmode)));
  9824. /* Describe the combined effect of the previous instructions. */
  9825. mips_set_frame_expr
  9826. (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
  9827. plus_constant (Pmode, stack_pointer_rtx, -size)));
  9828. }
  9829. mips_frame_barrier ();
  9830. }
  9831. /* Set up the frame pointer, if we're using one. */
  9832. if (frame_pointer_needed)
  9833. {
  9834. HOST_WIDE_INT offset;
  9835. offset = frame->hard_frame_pointer_offset;
  9836. if (offset == 0)
  9837. {
  9838. rtx insn = mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx);
  9839. RTX_FRAME_RELATED_P (insn) = 1;
  9840. }
  9841. else if (SMALL_OPERAND (offset))
  9842. {
  9843. rtx insn = gen_add3_insn (hard_frame_pointer_rtx,
  9844. stack_pointer_rtx, GEN_INT (offset));
  9845. RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
  9846. }
  9847. else
  9848. {
  9849. mips_emit_move (MIPS_PROLOGUE_TEMP (Pmode), GEN_INT (offset));
  9850. mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx);
  9851. emit_insn (gen_add3_insn (hard_frame_pointer_rtx,
  9852. hard_frame_pointer_rtx,
  9853. MIPS_PROLOGUE_TEMP (Pmode)));
  9854. mips_set_frame_expr
  9855. (gen_rtx_SET (VOIDmode, hard_frame_pointer_rtx,
  9856. plus_constant (Pmode, stack_pointer_rtx, offset)));
  9857. }
  9858. }
  9859. mips_emit_loadgp ();
  9860. /* Initialize the $gp save slot. */
  9861. if (mips_cfun_has_cprestore_slot_p ())
  9862. {
  9863. rtx base, mem, gp, temp;
  9864. HOST_WIDE_INT offset;
  9865. mips_get_cprestore_base_and_offset (&base, &offset, false);
  9866. mem = gen_frame_mem (Pmode, plus_constant (Pmode, base, offset));
  9867. gp = TARGET_MIPS16 ? MIPS16_PIC_TEMP : pic_offset_table_rtx;
  9868. temp = (SMALL_OPERAND (offset)
  9869. ? gen_rtx_SCRATCH (Pmode)
  9870. : MIPS_PROLOGUE_TEMP (Pmode));
  9871. emit_insn (PMODE_INSN (gen_potential_cprestore,
  9872. (mem, GEN_INT (offset), gp, temp)));
  9873. mips_get_cprestore_base_and_offset (&base, &offset, true);
  9874. mem = gen_frame_mem (Pmode, plus_constant (Pmode, base, offset));
  9875. emit_insn (PMODE_INSN (gen_use_cprestore, (mem)));
  9876. }
  9877. /* We need to search back to the last use of K0 or K1. */
  9878. if (cfun->machine->interrupt_handler_p)
  9879. {
  9880. rtx_insn *insn;
  9881. for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn))
  9882. if (INSN_P (insn)
  9883. && mips_refers_to_kernel_reg_p (PATTERN (insn)))
  9884. break;
  9885. /* Emit a move from K1 to COP0 Status after insn. */
  9886. gcc_assert (insn != NULL_RTX);
  9887. emit_insn_after (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM),
  9888. gen_rtx_REG (SImode, K1_REG_NUM)),
  9889. insn);
  9890. }
  9891. /* If we are profiling, make sure no instructions are scheduled before
  9892. the call to mcount. */
  9893. if (crtl->profile)
  9894. emit_insn (gen_blockage ());
  9895. }
  9896. /* Attach all pending register saves to the previous instruction.
  9897. Return that instruction. */
  9898. static rtx_insn *
  9899. mips_epilogue_emit_cfa_restores (void)
  9900. {
  9901. rtx_insn *insn;
  9902. insn = get_last_insn ();
  9903. gcc_assert (insn && !REG_NOTES (insn));
  9904. if (mips_epilogue.cfa_restores)
  9905. {
  9906. RTX_FRAME_RELATED_P (insn) = 1;
  9907. REG_NOTES (insn) = mips_epilogue.cfa_restores;
  9908. mips_epilogue.cfa_restores = 0;
  9909. }
  9910. return insn;
  9911. }
  9912. /* Like mips_epilogue_emit_cfa_restores, but also record that the CFA is
  9913. now at REG + OFFSET. */
  9914. static void
  9915. mips_epilogue_set_cfa (rtx reg, HOST_WIDE_INT offset)
  9916. {
  9917. rtx_insn *insn;
  9918. insn = mips_epilogue_emit_cfa_restores ();
  9919. if (reg != mips_epilogue.cfa_reg || offset != mips_epilogue.cfa_offset)
  9920. {
  9921. RTX_FRAME_RELATED_P (insn) = 1;
  9922. REG_NOTES (insn) = alloc_reg_note (REG_CFA_DEF_CFA,
  9923. plus_constant (Pmode, reg, offset),
  9924. REG_NOTES (insn));
  9925. mips_epilogue.cfa_reg = reg;
  9926. mips_epilogue.cfa_offset = offset;
  9927. }
  9928. }
  9929. /* Emit instructions to restore register REG from slot MEM. Also update
  9930. the cfa_restores list. */
  9931. static void
  9932. mips_restore_reg (rtx reg, rtx mem)
  9933. {
  9934. /* There's no MIPS16 instruction to load $31 directly. Load into
  9935. $7 instead and adjust the return insn appropriately. */
  9936. if (TARGET_MIPS16 && REGNO (reg) == RETURN_ADDR_REGNUM)
  9937. reg = gen_rtx_REG (GET_MODE (reg), GP_REG_FIRST + 7);
  9938. else if (GET_MODE (reg) == DFmode
  9939. && (!TARGET_FLOAT64
  9940. || mips_abi == ABI_32))
  9941. {
  9942. mips_add_cfa_restore (mips_subword (reg, true));
  9943. mips_add_cfa_restore (mips_subword (reg, false));
  9944. }
  9945. else
  9946. mips_add_cfa_restore (reg);
  9947. mips_emit_save_slot_move (reg, mem, MIPS_EPILOGUE_TEMP (GET_MODE (reg)));
  9948. if (REGNO (reg) == REGNO (mips_epilogue.cfa_reg))
  9949. /* The CFA is currently defined in terms of the register whose
  9950. value we have just restored. Redefine the CFA in terms of
  9951. the stack pointer. */
  9952. mips_epilogue_set_cfa (stack_pointer_rtx,
  9953. mips_epilogue.cfa_restore_sp_offset);
  9954. }
  9955. /* Emit code to set the stack pointer to BASE + OFFSET, given that
  9956. BASE + OFFSET is NEW_FRAME_SIZE bytes below the top of the frame.
  9957. BASE, if not the stack pointer, is available as a temporary. */
  9958. static void
  9959. mips_deallocate_stack (rtx base, rtx offset, HOST_WIDE_INT new_frame_size)
  9960. {
  9961. if (base == stack_pointer_rtx && offset == const0_rtx)
  9962. return;
  9963. mips_frame_barrier ();
  9964. if (offset == const0_rtx)
  9965. {
  9966. emit_move_insn (stack_pointer_rtx, base);
  9967. mips_epilogue_set_cfa (stack_pointer_rtx, new_frame_size);
  9968. }
  9969. else if (TARGET_MIPS16 && base != stack_pointer_rtx)
  9970. {
  9971. emit_insn (gen_add3_insn (base, base, offset));
  9972. mips_epilogue_set_cfa (base, new_frame_size);
  9973. emit_move_insn (stack_pointer_rtx, base);
  9974. }
  9975. else
  9976. {
  9977. emit_insn (gen_add3_insn (stack_pointer_rtx, base, offset));
  9978. mips_epilogue_set_cfa (stack_pointer_rtx, new_frame_size);
  9979. }
  9980. }
  9981. /* Emit any instructions needed before a return. */
  9982. void
  9983. mips_expand_before_return (void)
  9984. {
  9985. /* When using a call-clobbered gp, we start out with unified call
  9986. insns that include instructions to restore the gp. We then split
  9987. these unified calls after reload. These split calls explicitly
  9988. clobber gp, so there is no need to define
  9989. PIC_OFFSET_TABLE_REG_CALL_CLOBBERED.
  9990. For consistency, we should also insert an explicit clobber of $28
  9991. before return insns, so that the post-reload optimizers know that
  9992. the register is not live on exit. */
  9993. if (TARGET_CALL_CLOBBERED_GP)
  9994. emit_clobber (pic_offset_table_rtx);
  9995. }
  9996. /* Expand an "epilogue" or "sibcall_epilogue" pattern; SIBCALL_P
  9997. says which. */
  9998. void
  9999. mips_expand_epilogue (bool sibcall_p)
  10000. {
  10001. const struct mips_frame_info *frame;
  10002. HOST_WIDE_INT step1, step2;
  10003. rtx base, adjust;
  10004. rtx_insn *insn;
  10005. bool use_jraddiusp_p = false;
  10006. if (!sibcall_p && mips_can_use_return_insn ())
  10007. {
  10008. emit_jump_insn (gen_return ());
  10009. return;
  10010. }
  10011. /* In MIPS16 mode, if the return value should go into a floating-point
  10012. register, we need to call a helper routine to copy it over. */
  10013. if (mips16_cfun_returns_in_fpr_p ())
  10014. mips16_copy_fpr_return_value ();
  10015. /* Split the frame into two. STEP1 is the amount of stack we should
  10016. deallocate before restoring the registers. STEP2 is the amount we
  10017. should deallocate afterwards.
  10018. Start off by assuming that no registers need to be restored. */
  10019. frame = &cfun->machine->frame;
  10020. step1 = frame->total_size;
  10021. step2 = 0;
  10022. /* Work out which register holds the frame address. */
  10023. if (!frame_pointer_needed)
  10024. base = stack_pointer_rtx;
  10025. else
  10026. {
  10027. base = hard_frame_pointer_rtx;
  10028. step1 -= frame->hard_frame_pointer_offset;
  10029. }
  10030. mips_epilogue.cfa_reg = base;
  10031. mips_epilogue.cfa_offset = step1;
  10032. mips_epilogue.cfa_restores = NULL_RTX;
  10033. /* If we need to restore registers, deallocate as much stack as
  10034. possible in the second step without going out of range. */
  10035. if ((frame->mask | frame->fmask | frame->acc_mask) != 0
  10036. || frame->num_cop0_regs > 0)
  10037. {
  10038. step2 = MIN (step1, MIPS_MAX_FIRST_STACK_STEP);
  10039. step1 -= step2;
  10040. }
  10041. /* Get an rtx for STEP1 that we can add to BASE. */
  10042. adjust = GEN_INT (step1);
  10043. if (!SMALL_OPERAND (step1))
  10044. {
  10045. mips_emit_move (MIPS_EPILOGUE_TEMP (Pmode), adjust);
  10046. adjust = MIPS_EPILOGUE_TEMP (Pmode);
  10047. }
  10048. mips_deallocate_stack (base, adjust, step2);
  10049. /* If we're using addressing macros, $gp is implicitly used by all
  10050. SYMBOL_REFs. We must emit a blockage insn before restoring $gp
  10051. from the stack. */
  10052. if (TARGET_CALL_SAVED_GP && !TARGET_EXPLICIT_RELOCS)
  10053. emit_insn (gen_blockage ());
  10054. mips_epilogue.cfa_restore_sp_offset = step2;
  10055. if (GENERATE_MIPS16E_SAVE_RESTORE && frame->mask != 0)
  10056. {
  10057. unsigned int regno, mask;
  10058. HOST_WIDE_INT offset;
  10059. rtx restore;
  10060. /* Generate the restore instruction. */
  10061. mask = frame->mask;
  10062. restore = mips16e_build_save_restore (true, &mask, &offset, 0, step2);
  10063. /* Restore any other registers manually. */
  10064. for (regno = GP_REG_FIRST; regno < GP_REG_LAST; regno++)
  10065. if (BITSET_P (mask, regno - GP_REG_FIRST))
  10066. {
  10067. offset -= UNITS_PER_WORD;
  10068. mips_save_restore_reg (word_mode, regno, offset, mips_restore_reg);
  10069. }
  10070. /* Restore the remaining registers and deallocate the final bit
  10071. of the frame. */
  10072. mips_frame_barrier ();
  10073. emit_insn (restore);
  10074. mips_epilogue_set_cfa (stack_pointer_rtx, 0);
  10075. }
  10076. else
  10077. {
  10078. /* Restore the registers. */
  10079. mips_for_each_saved_acc (frame->total_size - step2, mips_restore_reg);
  10080. mips_for_each_saved_gpr_and_fpr (frame->total_size - step2,
  10081. mips_restore_reg);
  10082. if (cfun->machine->interrupt_handler_p)
  10083. {
  10084. HOST_WIDE_INT offset;
  10085. rtx mem;
  10086. offset = frame->cop0_sp_offset - (frame->total_size - step2);
  10087. if (!cfun->machine->keep_interrupts_masked_p)
  10088. {
  10089. /* Restore the original EPC. */
  10090. mem = gen_frame_mem (word_mode,
  10091. plus_constant (Pmode, stack_pointer_rtx,
  10092. offset));
  10093. mips_emit_move (gen_rtx_REG (word_mode, K0_REG_NUM), mem);
  10094. offset -= UNITS_PER_WORD;
  10095. /* Move to COP0 EPC. */
  10096. emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_EPC_REG_NUM),
  10097. gen_rtx_REG (SImode, K0_REG_NUM)));
  10098. }
  10099. /* Restore the original Status. */
  10100. mem = gen_frame_mem (word_mode,
  10101. plus_constant (Pmode, stack_pointer_rtx,
  10102. offset));
  10103. mips_emit_move (gen_rtx_REG (word_mode, K0_REG_NUM), mem);
  10104. offset -= UNITS_PER_WORD;
  10105. /* If we don't use shadow register set, we need to update SP. */
  10106. if (!cfun->machine->use_shadow_register_set_p)
  10107. mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0);
  10108. else
  10109. /* The choice of position is somewhat arbitrary in this case. */
  10110. mips_epilogue_emit_cfa_restores ();
  10111. /* Move to COP0 Status. */
  10112. emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM),
  10113. gen_rtx_REG (SImode, K0_REG_NUM)));
  10114. }
  10115. else if (TARGET_MICROMIPS
  10116. && !crtl->calls_eh_return
  10117. && !sibcall_p
  10118. && step2 > 0
  10119. && mips_unsigned_immediate_p (step2, 5, 2))
  10120. use_jraddiusp_p = true;
  10121. else
  10122. /* Deallocate the final bit of the frame. */
  10123. mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0);
  10124. }
  10125. if (!use_jraddiusp_p)
  10126. gcc_assert (!mips_epilogue.cfa_restores);
  10127. /* Add in the __builtin_eh_return stack adjustment. We need to
  10128. use a temporary in MIPS16 code. */
  10129. if (crtl->calls_eh_return)
  10130. {
  10131. if (TARGET_MIPS16)
  10132. {
  10133. mips_emit_move (MIPS_EPILOGUE_TEMP (Pmode), stack_pointer_rtx);
  10134. emit_insn (gen_add3_insn (MIPS_EPILOGUE_TEMP (Pmode),
  10135. MIPS_EPILOGUE_TEMP (Pmode),
  10136. EH_RETURN_STACKADJ_RTX));
  10137. mips_emit_move (stack_pointer_rtx, MIPS_EPILOGUE_TEMP (Pmode));
  10138. }
  10139. else
  10140. emit_insn (gen_add3_insn (stack_pointer_rtx,
  10141. stack_pointer_rtx,
  10142. EH_RETURN_STACKADJ_RTX));
  10143. }
  10144. if (!sibcall_p)
  10145. {
  10146. mips_expand_before_return ();
  10147. if (cfun->machine->interrupt_handler_p)
  10148. {
  10149. /* Interrupt handlers generate eret or deret. */
  10150. if (cfun->machine->use_debug_exception_return_p)
  10151. emit_jump_insn (gen_mips_deret ());
  10152. else
  10153. emit_jump_insn (gen_mips_eret ());
  10154. }
  10155. else
  10156. {
  10157. rtx pat;
  10158. /* When generating MIPS16 code, the normal
  10159. mips_for_each_saved_gpr_and_fpr path will restore the return
  10160. address into $7 rather than $31. */
  10161. if (TARGET_MIPS16
  10162. && !GENERATE_MIPS16E_SAVE_RESTORE
  10163. && BITSET_P (frame->mask, RETURN_ADDR_REGNUM))
  10164. {
  10165. /* simple_returns cannot rely on values that are only available
  10166. on paths through the epilogue (because return paths that do
  10167. not pass through the epilogue may nevertheless reuse a
  10168. simple_return that occurs at the end of the epilogue).
  10169. Use a normal return here instead. */
  10170. rtx reg = gen_rtx_REG (Pmode, GP_REG_FIRST + 7);
  10171. pat = gen_return_internal (reg);
  10172. }
  10173. else if (use_jraddiusp_p)
  10174. pat = gen_jraddiusp (GEN_INT (step2));
  10175. else
  10176. {
  10177. rtx reg = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
  10178. pat = gen_simple_return_internal (reg);
  10179. }
  10180. emit_jump_insn (pat);
  10181. if (use_jraddiusp_p)
  10182. mips_epilogue_set_cfa (stack_pointer_rtx, step2);
  10183. }
  10184. }
  10185. /* Search from the beginning to the first use of K0 or K1. */
  10186. if (cfun->machine->interrupt_handler_p
  10187. && !cfun->machine->keep_interrupts_masked_p)
  10188. {
  10189. for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
  10190. if (INSN_P (insn)
  10191. && mips_refers_to_kernel_reg_p (PATTERN (insn)))
  10192. break;
  10193. gcc_assert (insn != NULL_RTX);
  10194. /* Insert disable interrupts before the first use of K0 or K1. */
  10195. emit_insn_before (gen_mips_di (), insn);
  10196. emit_insn_before (gen_mips_ehb (), insn);
  10197. }
  10198. }
  10199. /* Return nonzero if this function is known to have a null epilogue.
  10200. This allows the optimizer to omit jumps to jumps if no stack
  10201. was created. */
  10202. bool
  10203. mips_can_use_return_insn (void)
  10204. {
  10205. /* Interrupt handlers need to go through the epilogue. */
  10206. if (cfun->machine->interrupt_handler_p)
  10207. return false;
  10208. if (!reload_completed)
  10209. return false;
  10210. if (crtl->profile)
  10211. return false;
  10212. /* In MIPS16 mode, a function that returns a floating-point value
  10213. needs to arrange to copy the return value into the floating-point
  10214. registers. */
  10215. if (mips16_cfun_returns_in_fpr_p ())
  10216. return false;
  10217. return cfun->machine->frame.total_size == 0;
  10218. }
  10219. /* Return true if register REGNO can store a value of mode MODE.
  10220. The result of this function is cached in mips_hard_regno_mode_ok. */
  10221. static bool
  10222. mips_hard_regno_mode_ok_p (unsigned int regno, machine_mode mode)
  10223. {
  10224. unsigned int size;
  10225. enum mode_class mclass;
  10226. if (mode == CCV2mode)
  10227. return (ISA_HAS_8CC
  10228. && ST_REG_P (regno)
  10229. && (regno - ST_REG_FIRST) % 2 == 0);
  10230. if (mode == CCV4mode)
  10231. return (ISA_HAS_8CC
  10232. && ST_REG_P (regno)
  10233. && (regno - ST_REG_FIRST) % 4 == 0);
  10234. if (mode == CCmode)
  10235. return ISA_HAS_8CC ? ST_REG_P (regno) : regno == FPSW_REGNUM;
  10236. size = GET_MODE_SIZE (mode);
  10237. mclass = GET_MODE_CLASS (mode);
  10238. if (GP_REG_P (regno) && mode != CCFmode)
  10239. return ((regno - GP_REG_FIRST) & 1) == 0 || size <= UNITS_PER_WORD;
  10240. if (FP_REG_P (regno)
  10241. && (((regno - FP_REG_FIRST) % MAX_FPRS_PER_FMT) == 0
  10242. || (MIN_FPRS_PER_FMT == 1 && size <= UNITS_PER_FPREG)))
  10243. {
  10244. /* Deny use of odd-numbered registers for 32-bit data for
  10245. the o32 FP64A ABI. */
  10246. if (TARGET_O32_FP64A_ABI && size <= 4 && (regno & 1) != 0)
  10247. return false;
  10248. /* The FPXX ABI requires double-precision values to be placed in
  10249. even-numbered registers. Disallow odd-numbered registers with
  10250. CCFmode because CCFmode double-precision compares will write a
  10251. 64-bit value to a register. */
  10252. if (mode == CCFmode)
  10253. return !(TARGET_FLOATXX && (regno & 1) != 0);
  10254. /* Allow 64-bit vector modes for Loongson-2E/2F. */
  10255. if (TARGET_LOONGSON_VECTORS
  10256. && (mode == V2SImode
  10257. || mode == V4HImode
  10258. || mode == V8QImode
  10259. || mode == DImode))
  10260. return true;
  10261. if (mclass == MODE_FLOAT
  10262. || mclass == MODE_COMPLEX_FLOAT
  10263. || mclass == MODE_VECTOR_FLOAT)
  10264. return size <= UNITS_PER_FPVALUE;
  10265. /* Allow integer modes that fit into a single register. We need
  10266. to put integers into FPRs when using instructions like CVT
  10267. and TRUNC. There's no point allowing sizes smaller than a word,
  10268. because the FPU has no appropriate load/store instructions. */
  10269. if (mclass == MODE_INT)
  10270. return size >= MIN_UNITS_PER_WORD && size <= UNITS_PER_FPREG;
  10271. }
  10272. /* Don't allow vector modes in accumulators. */
  10273. if (ACC_REG_P (regno)
  10274. && !VECTOR_MODE_P (mode)
  10275. && (INTEGRAL_MODE_P (mode) || ALL_FIXED_POINT_MODE_P (mode)))
  10276. {
  10277. if (MD_REG_P (regno))
  10278. {
  10279. /* After a multiplication or division, clobbering HI makes
  10280. the value of LO unpredictable, and vice versa. This means
  10281. that, for all interesting cases, HI and LO are effectively
  10282. a single register.
  10283. We model this by requiring that any value that uses HI
  10284. also uses LO. */
  10285. if (size <= UNITS_PER_WORD * 2)
  10286. return regno == (size <= UNITS_PER_WORD ? LO_REGNUM : MD_REG_FIRST);
  10287. }
  10288. else
  10289. {
  10290. /* DSP accumulators do not have the same restrictions as
  10291. HI and LO, so we can treat them as normal doubleword
  10292. registers. */
  10293. if (size <= UNITS_PER_WORD)
  10294. return true;
  10295. if (size <= UNITS_PER_WORD * 2
  10296. && ((regno - DSP_ACC_REG_FIRST) & 1) == 0)
  10297. return true;
  10298. }
  10299. }
  10300. if (ALL_COP_REG_P (regno))
  10301. return mclass == MODE_INT && size <= UNITS_PER_WORD;
  10302. if (regno == GOT_VERSION_REGNUM)
  10303. return mode == SImode;
  10304. return false;
  10305. }
  10306. /* Implement HARD_REGNO_NREGS. */
  10307. unsigned int
  10308. mips_hard_regno_nregs (int regno, machine_mode mode)
  10309. {
  10310. if (ST_REG_P (regno))
  10311. /* The size of FP status registers is always 4, because they only hold
  10312. CCmode values, and CCmode is always considered to be 4 bytes wide. */
  10313. return (GET_MODE_SIZE (mode) + 3) / 4;
  10314. if (FP_REG_P (regno))
  10315. return (GET_MODE_SIZE (mode) + UNITS_PER_FPREG - 1) / UNITS_PER_FPREG;
  10316. /* All other registers are word-sized. */
  10317. return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  10318. }
  10319. /* Implement CLASS_MAX_NREGS, taking the maximum of the cases
  10320. in mips_hard_regno_nregs. */
  10321. int
  10322. mips_class_max_nregs (enum reg_class rclass, machine_mode mode)
  10323. {
  10324. int size;
  10325. HARD_REG_SET left;
  10326. size = 0x8000;
  10327. COPY_HARD_REG_SET (left, reg_class_contents[(int) rclass]);
  10328. if (hard_reg_set_intersect_p (left, reg_class_contents[(int) ST_REGS]))
  10329. {
  10330. if (HARD_REGNO_MODE_OK (ST_REG_FIRST, mode))
  10331. size = MIN (size, 4);
  10332. AND_COMPL_HARD_REG_SET (left, reg_class_contents[(int) ST_REGS]);
  10333. }
  10334. if (hard_reg_set_intersect_p (left, reg_class_contents[(int) FP_REGS]))
  10335. {
  10336. if (HARD_REGNO_MODE_OK (FP_REG_FIRST, mode))
  10337. size = MIN (size, UNITS_PER_FPREG);
  10338. AND_COMPL_HARD_REG_SET (left, reg_class_contents[(int) FP_REGS]);
  10339. }
  10340. if (!hard_reg_set_empty_p (left))
  10341. size = MIN (size, UNITS_PER_WORD);
  10342. return (GET_MODE_SIZE (mode) + size - 1) / size;
  10343. }
  10344. /* Implement CANNOT_CHANGE_MODE_CLASS. */
  10345. bool
  10346. mips_cannot_change_mode_class (machine_mode from,
  10347. machine_mode to,
  10348. enum reg_class rclass)
  10349. {
  10350. /* Allow conversions between different Loongson integer vectors,
  10351. and between those vectors and DImode. */
  10352. if (GET_MODE_SIZE (from) == 8 && GET_MODE_SIZE (to) == 8
  10353. && INTEGRAL_MODE_P (from) && INTEGRAL_MODE_P (to))
  10354. return false;
  10355. /* Otherwise, there are several problems with changing the modes of
  10356. values in floating-point registers:
  10357. - When a multi-word value is stored in paired floating-point
  10358. registers, the first register always holds the low word. We
  10359. therefore can't allow FPRs to change between single-word and
  10360. multi-word modes on big-endian targets.
  10361. - GCC assumes that each word of a multiword register can be
  10362. accessed individually using SUBREGs. This is not true for
  10363. floating-point registers if they are bigger than a word.
  10364. - Loading a 32-bit value into a 64-bit floating-point register
  10365. will not sign-extend the value, despite what LOAD_EXTEND_OP
  10366. says. We can't allow FPRs to change from SImode to a wider
  10367. mode on 64-bit targets.
  10368. - If the FPU has already interpreted a value in one format, we
  10369. must not ask it to treat the value as having a different
  10370. format.
  10371. We therefore disallow all mode changes involving FPRs. */
  10372. return reg_classes_intersect_p (FP_REGS, rclass);
  10373. }
  10374. /* Implement target hook small_register_classes_for_mode_p. */
  10375. static bool
  10376. mips_small_register_classes_for_mode_p (machine_mode mode
  10377. ATTRIBUTE_UNUSED)
  10378. {
  10379. return TARGET_MIPS16;
  10380. }
  10381. /* Return true if moves in mode MODE can use the FPU's mov.fmt instruction. */
  10382. static bool
  10383. mips_mode_ok_for_mov_fmt_p (machine_mode mode)
  10384. {
  10385. switch (mode)
  10386. {
  10387. case CCFmode:
  10388. case SFmode:
  10389. return TARGET_HARD_FLOAT;
  10390. case DFmode:
  10391. return TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT;
  10392. case V2SFmode:
  10393. return TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT;
  10394. default:
  10395. return false;
  10396. }
  10397. }
  10398. /* Implement MODES_TIEABLE_P. */
  10399. bool
  10400. mips_modes_tieable_p (machine_mode mode1, machine_mode mode2)
  10401. {
  10402. /* FPRs allow no mode punning, so it's not worth tying modes if we'd
  10403. prefer to put one of them in FPRs. */
  10404. return (mode1 == mode2
  10405. || (!mips_mode_ok_for_mov_fmt_p (mode1)
  10406. && !mips_mode_ok_for_mov_fmt_p (mode2)));
  10407. }
  10408. /* Implement TARGET_PREFERRED_RELOAD_CLASS. */
  10409. static reg_class_t
  10410. mips_preferred_reload_class (rtx x, reg_class_t rclass)
  10411. {
  10412. if (mips_dangerous_for_la25_p (x) && reg_class_subset_p (LEA_REGS, rclass))
  10413. return LEA_REGS;
  10414. if (reg_class_subset_p (FP_REGS, rclass)
  10415. && mips_mode_ok_for_mov_fmt_p (GET_MODE (x)))
  10416. return FP_REGS;
  10417. if (reg_class_subset_p (GR_REGS, rclass))
  10418. rclass = GR_REGS;
  10419. if (TARGET_MIPS16 && reg_class_subset_p (M16_REGS, rclass))
  10420. rclass = M16_REGS;
  10421. return rclass;
  10422. }
  10423. /* RCLASS is a class involved in a REGISTER_MOVE_COST calculation.
  10424. Return a "canonical" class to represent it in later calculations. */
  10425. static reg_class_t
  10426. mips_canonicalize_move_class (reg_class_t rclass)
  10427. {
  10428. /* All moves involving accumulator registers have the same cost. */
  10429. if (reg_class_subset_p (rclass, ACC_REGS))
  10430. rclass = ACC_REGS;
  10431. /* Likewise promote subclasses of general registers to the most
  10432. interesting containing class. */
  10433. if (TARGET_MIPS16 && reg_class_subset_p (rclass, M16_REGS))
  10434. rclass = M16_REGS;
  10435. else if (reg_class_subset_p (rclass, GENERAL_REGS))
  10436. rclass = GENERAL_REGS;
  10437. return rclass;
  10438. }
  10439. /* Return the cost of moving a value from a register of class FROM to a GPR.
  10440. Return 0 for classes that are unions of other classes handled by this
  10441. function. */
  10442. static int
  10443. mips_move_to_gpr_cost (reg_class_t from)
  10444. {
  10445. switch (from)
  10446. {
  10447. case M16_REGS:
  10448. case GENERAL_REGS:
  10449. /* A MIPS16 MOVE instruction, or a non-MIPS16 MOVE macro. */
  10450. return 2;
  10451. case ACC_REGS:
  10452. /* MFLO and MFHI. */
  10453. return 6;
  10454. case FP_REGS:
  10455. /* MFC1, etc. */
  10456. return 4;
  10457. case COP0_REGS:
  10458. case COP2_REGS:
  10459. case COP3_REGS:
  10460. /* This choice of value is historical. */
  10461. return 5;
  10462. default:
  10463. return 0;
  10464. }
  10465. }
  10466. /* Return the cost of moving a value from a GPR to a register of class TO.
  10467. Return 0 for classes that are unions of other classes handled by this
  10468. function. */
  10469. static int
  10470. mips_move_from_gpr_cost (reg_class_t to)
  10471. {
  10472. switch (to)
  10473. {
  10474. case M16_REGS:
  10475. case GENERAL_REGS:
  10476. /* A MIPS16 MOVE instruction, or a non-MIPS16 MOVE macro. */
  10477. return 2;
  10478. case ACC_REGS:
  10479. /* MTLO and MTHI. */
  10480. return 6;
  10481. case FP_REGS:
  10482. /* MTC1, etc. */
  10483. return 4;
  10484. case COP0_REGS:
  10485. case COP2_REGS:
  10486. case COP3_REGS:
  10487. /* This choice of value is historical. */
  10488. return 5;
  10489. default:
  10490. return 0;
  10491. }
  10492. }
  10493. /* Implement TARGET_REGISTER_MOVE_COST. Return 0 for classes that are the
  10494. maximum of the move costs for subclasses; regclass will work out
  10495. the maximum for us. */
  10496. static int
  10497. mips_register_move_cost (machine_mode mode,
  10498. reg_class_t from, reg_class_t to)
  10499. {
  10500. reg_class_t dregs;
  10501. int cost1, cost2;
  10502. from = mips_canonicalize_move_class (from);
  10503. to = mips_canonicalize_move_class (to);
  10504. /* Handle moves that can be done without using general-purpose registers. */
  10505. if (from == FP_REGS)
  10506. {
  10507. if (to == FP_REGS && mips_mode_ok_for_mov_fmt_p (mode))
  10508. /* MOV.FMT. */
  10509. return 4;
  10510. }
  10511. /* Handle cases in which only one class deviates from the ideal. */
  10512. dregs = TARGET_MIPS16 ? M16_REGS : GENERAL_REGS;
  10513. if (from == dregs)
  10514. return mips_move_from_gpr_cost (to);
  10515. if (to == dregs)
  10516. return mips_move_to_gpr_cost (from);
  10517. /* Handles cases that require a GPR temporary. */
  10518. cost1 = mips_move_to_gpr_cost (from);
  10519. if (cost1 != 0)
  10520. {
  10521. cost2 = mips_move_from_gpr_cost (to);
  10522. if (cost2 != 0)
  10523. return cost1 + cost2;
  10524. }
  10525. return 0;
  10526. }
  10527. /* Implement TARGET_REGISTER_PRIORITY. */
  10528. static int
  10529. mips_register_priority (int hard_regno)
  10530. {
  10531. /* Treat MIPS16 registers with higher priority than other regs. */
  10532. if (TARGET_MIPS16
  10533. && TEST_HARD_REG_BIT (reg_class_contents[M16_REGS], hard_regno))
  10534. return 1;
  10535. return 0;
  10536. }
  10537. /* Implement TARGET_MEMORY_MOVE_COST. */
  10538. static int
  10539. mips_memory_move_cost (machine_mode mode, reg_class_t rclass, bool in)
  10540. {
  10541. return (mips_cost->memory_latency
  10542. + memory_move_secondary_cost (mode, rclass, in));
  10543. }
  10544. /* Implement SECONDARY_MEMORY_NEEDED. */
  10545. bool
  10546. mips_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
  10547. machine_mode mode)
  10548. {
  10549. /* Ignore spilled pseudos. */
  10550. if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
  10551. return false;
  10552. if (((class1 == FP_REGS) != (class2 == FP_REGS))
  10553. && ((TARGET_FLOATXX && !ISA_HAS_MXHC1)
  10554. || TARGET_O32_FP64A_ABI)
  10555. && GET_MODE_SIZE (mode) >= 8)
  10556. return true;
  10557. return false;
  10558. }
  10559. /* Return the register class required for a secondary register when
  10560. copying between one of the registers in RCLASS and value X, which
  10561. has mode MODE. X is the source of the move if IN_P, otherwise it
  10562. is the destination. Return NO_REGS if no secondary register is
  10563. needed. */
  10564. enum reg_class
  10565. mips_secondary_reload_class (enum reg_class rclass,
  10566. machine_mode mode, rtx x, bool)
  10567. {
  10568. int regno;
  10569. /* If X is a constant that cannot be loaded into $25, it must be loaded
  10570. into some other GPR. No other register class allows a direct move. */
  10571. if (mips_dangerous_for_la25_p (x))
  10572. return reg_class_subset_p (rclass, LEA_REGS) ? NO_REGS : LEA_REGS;
  10573. regno = true_regnum (x);
  10574. if (TARGET_MIPS16)
  10575. {
  10576. /* In MIPS16 mode, every move must involve a member of M16_REGS. */
  10577. if (!reg_class_subset_p (rclass, M16_REGS) && !M16_REG_P (regno))
  10578. return M16_REGS;
  10579. return NO_REGS;
  10580. }
  10581. /* Copying from accumulator registers to anywhere other than a general
  10582. register requires a temporary general register. */
  10583. if (reg_class_subset_p (rclass, ACC_REGS))
  10584. return GP_REG_P (regno) ? NO_REGS : GR_REGS;
  10585. if (ACC_REG_P (regno))
  10586. return reg_class_subset_p (rclass, GR_REGS) ? NO_REGS : GR_REGS;
  10587. if (reg_class_subset_p (rclass, FP_REGS))
  10588. {
  10589. if (regno < 0
  10590. || (MEM_P (x)
  10591. && (GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8)))
  10592. /* In this case we can use lwc1, swc1, ldc1 or sdc1. We'll use
  10593. pairs of lwc1s and swc1s if ldc1 and sdc1 are not supported. */
  10594. return NO_REGS;
  10595. if (GP_REG_P (regno) || x == CONST0_RTX (mode))
  10596. /* In this case we can use mtc1, mfc1, dmtc1 or dmfc1. */
  10597. return NO_REGS;
  10598. if (CONSTANT_P (x) && !targetm.cannot_force_const_mem (mode, x))
  10599. /* We can force the constant to memory and use lwc1
  10600. and ldc1. As above, we will use pairs of lwc1s if
  10601. ldc1 is not supported. */
  10602. return NO_REGS;
  10603. if (FP_REG_P (regno) && mips_mode_ok_for_mov_fmt_p (mode))
  10604. /* In this case we can use mov.fmt. */
  10605. return NO_REGS;
  10606. /* Otherwise, we need to reload through an integer register. */
  10607. return GR_REGS;
  10608. }
  10609. if (FP_REG_P (regno))
  10610. return reg_class_subset_p (rclass, GR_REGS) ? NO_REGS : GR_REGS;
  10611. return NO_REGS;
  10612. }
  10613. /* Implement TARGET_MODE_REP_EXTENDED. */
  10614. static int
  10615. mips_mode_rep_extended (machine_mode mode, machine_mode mode_rep)
  10616. {
  10617. /* On 64-bit targets, SImode register values are sign-extended to DImode. */
  10618. if (TARGET_64BIT && mode == SImode && mode_rep == DImode)
  10619. return SIGN_EXTEND;
  10620. return UNKNOWN;
  10621. }
  10622. /* Implement TARGET_VALID_POINTER_MODE. */
  10623. static bool
  10624. mips_valid_pointer_mode (machine_mode mode)
  10625. {
  10626. return mode == SImode || (TARGET_64BIT && mode == DImode);
  10627. }
  10628. /* Implement TARGET_VECTOR_MODE_SUPPORTED_P. */
  10629. static bool
  10630. mips_vector_mode_supported_p (machine_mode mode)
  10631. {
  10632. switch (mode)
  10633. {
  10634. case V2SFmode:
  10635. return TARGET_PAIRED_SINGLE_FLOAT;
  10636. case V2HImode:
  10637. case V4QImode:
  10638. case V2HQmode:
  10639. case V2UHQmode:
  10640. case V2HAmode:
  10641. case V2UHAmode:
  10642. case V4QQmode:
  10643. case V4UQQmode:
  10644. return TARGET_DSP;
  10645. case V2SImode:
  10646. case V4HImode:
  10647. case V8QImode:
  10648. return TARGET_LOONGSON_VECTORS;
  10649. default:
  10650. return false;
  10651. }
  10652. }
  10653. /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. */
  10654. static bool
  10655. mips_scalar_mode_supported_p (machine_mode mode)
  10656. {
  10657. if (ALL_FIXED_POINT_MODE_P (mode)
  10658. && GET_MODE_PRECISION (mode) <= 2 * BITS_PER_WORD)
  10659. return true;
  10660. return default_scalar_mode_supported_p (mode);
  10661. }
  10662. /* Implement TARGET_VECTORIZE_PREFERRED_SIMD_MODE. */
  10663. static machine_mode
  10664. mips_preferred_simd_mode (machine_mode mode ATTRIBUTE_UNUSED)
  10665. {
  10666. if (TARGET_PAIRED_SINGLE_FLOAT
  10667. && mode == SFmode)
  10668. return V2SFmode;
  10669. return word_mode;
  10670. }
  10671. /* Implement TARGET_INIT_LIBFUNCS. */
  10672. static void
  10673. mips_init_libfuncs (void)
  10674. {
  10675. if (TARGET_FIX_VR4120)
  10676. {
  10677. /* Register the special divsi3 and modsi3 functions needed to work
  10678. around VR4120 division errata. */
  10679. set_optab_libfunc (sdiv_optab, SImode, "__vr4120_divsi3");
  10680. set_optab_libfunc (smod_optab, SImode, "__vr4120_modsi3");
  10681. }
  10682. if (TARGET_MIPS16 && TARGET_HARD_FLOAT_ABI)
  10683. {
  10684. /* Register the MIPS16 -mhard-float stubs. */
  10685. set_optab_libfunc (add_optab, SFmode, "__mips16_addsf3");
  10686. set_optab_libfunc (sub_optab, SFmode, "__mips16_subsf3");
  10687. set_optab_libfunc (smul_optab, SFmode, "__mips16_mulsf3");
  10688. set_optab_libfunc (sdiv_optab, SFmode, "__mips16_divsf3");
  10689. set_optab_libfunc (eq_optab, SFmode, "__mips16_eqsf2");
  10690. set_optab_libfunc (ne_optab, SFmode, "__mips16_nesf2");
  10691. set_optab_libfunc (gt_optab, SFmode, "__mips16_gtsf2");
  10692. set_optab_libfunc (ge_optab, SFmode, "__mips16_gesf2");
  10693. set_optab_libfunc (lt_optab, SFmode, "__mips16_ltsf2");
  10694. set_optab_libfunc (le_optab, SFmode, "__mips16_lesf2");
  10695. set_optab_libfunc (unord_optab, SFmode, "__mips16_unordsf2");
  10696. set_conv_libfunc (sfix_optab, SImode, SFmode, "__mips16_fix_truncsfsi");
  10697. set_conv_libfunc (sfloat_optab, SFmode, SImode, "__mips16_floatsisf");
  10698. set_conv_libfunc (ufloat_optab, SFmode, SImode, "__mips16_floatunsisf");
  10699. if (TARGET_DOUBLE_FLOAT)
  10700. {
  10701. set_optab_libfunc (add_optab, DFmode, "__mips16_adddf3");
  10702. set_optab_libfunc (sub_optab, DFmode, "__mips16_subdf3");
  10703. set_optab_libfunc (smul_optab, DFmode, "__mips16_muldf3");
  10704. set_optab_libfunc (sdiv_optab, DFmode, "__mips16_divdf3");
  10705. set_optab_libfunc (eq_optab, DFmode, "__mips16_eqdf2");
  10706. set_optab_libfunc (ne_optab, DFmode, "__mips16_nedf2");
  10707. set_optab_libfunc (gt_optab, DFmode, "__mips16_gtdf2");
  10708. set_optab_libfunc (ge_optab, DFmode, "__mips16_gedf2");
  10709. set_optab_libfunc (lt_optab, DFmode, "__mips16_ltdf2");
  10710. set_optab_libfunc (le_optab, DFmode, "__mips16_ledf2");
  10711. set_optab_libfunc (unord_optab, DFmode, "__mips16_unorddf2");
  10712. set_conv_libfunc (sext_optab, DFmode, SFmode,
  10713. "__mips16_extendsfdf2");
  10714. set_conv_libfunc (trunc_optab, SFmode, DFmode,
  10715. "__mips16_truncdfsf2");
  10716. set_conv_libfunc (sfix_optab, SImode, DFmode,
  10717. "__mips16_fix_truncdfsi");
  10718. set_conv_libfunc (sfloat_optab, DFmode, SImode,
  10719. "__mips16_floatsidf");
  10720. set_conv_libfunc (ufloat_optab, DFmode, SImode,
  10721. "__mips16_floatunsidf");
  10722. }
  10723. }
  10724. /* The MIPS16 ISA does not have an encoding for "sync", so we rely
  10725. on an external non-MIPS16 routine to implement __sync_synchronize.
  10726. Similarly for the rest of the ll/sc libfuncs. */
  10727. if (TARGET_MIPS16)
  10728. {
  10729. synchronize_libfunc = init_one_libfunc ("__sync_synchronize");
  10730. init_sync_libfuncs (UNITS_PER_WORD);
  10731. }
  10732. }
  10733. /* Build up a multi-insn sequence that loads label TARGET into $AT. */
  10734. static void
  10735. mips_process_load_label (rtx target)
  10736. {
  10737. rtx base, gp, intop;
  10738. HOST_WIDE_INT offset;
  10739. mips_multi_start ();
  10740. switch (mips_abi)
  10741. {
  10742. case ABI_N32:
  10743. mips_multi_add_insn ("lw\t%@,%%got_page(%0)(%+)", target, 0);
  10744. mips_multi_add_insn ("addiu\t%@,%@,%%got_ofst(%0)", target, 0);
  10745. break;
  10746. case ABI_64:
  10747. mips_multi_add_insn ("ld\t%@,%%got_page(%0)(%+)", target, 0);
  10748. mips_multi_add_insn ("daddiu\t%@,%@,%%got_ofst(%0)", target, 0);
  10749. break;
  10750. default:
  10751. gp = pic_offset_table_rtx;
  10752. if (mips_cfun_has_cprestore_slot_p ())
  10753. {
  10754. gp = gen_rtx_REG (Pmode, AT_REGNUM);
  10755. mips_get_cprestore_base_and_offset (&base, &offset, true);
  10756. if (!SMALL_OPERAND (offset))
  10757. {
  10758. intop = GEN_INT (CONST_HIGH_PART (offset));
  10759. mips_multi_add_insn ("lui\t%0,%1", gp, intop, 0);
  10760. mips_multi_add_insn ("addu\t%0,%0,%1", gp, base, 0);
  10761. base = gp;
  10762. offset = CONST_LOW_PART (offset);
  10763. }
  10764. intop = GEN_INT (offset);
  10765. if (ISA_HAS_LOAD_DELAY)
  10766. mips_multi_add_insn ("lw\t%0,%1(%2)%#", gp, intop, base, 0);
  10767. else
  10768. mips_multi_add_insn ("lw\t%0,%1(%2)", gp, intop, base, 0);
  10769. }
  10770. if (ISA_HAS_LOAD_DELAY)
  10771. mips_multi_add_insn ("lw\t%@,%%got(%0)(%1)%#", target, gp, 0);
  10772. else
  10773. mips_multi_add_insn ("lw\t%@,%%got(%0)(%1)", target, gp, 0);
  10774. mips_multi_add_insn ("addiu\t%@,%@,%%lo(%0)", target, 0);
  10775. break;
  10776. }
  10777. }
  10778. /* Return the number of instructions needed to load a label into $AT. */
  10779. static unsigned int
  10780. mips_load_label_num_insns (void)
  10781. {
  10782. if (cfun->machine->load_label_num_insns == 0)
  10783. {
  10784. mips_process_load_label (pc_rtx);
  10785. cfun->machine->load_label_num_insns = mips_multi_num_insns;
  10786. }
  10787. return cfun->machine->load_label_num_insns;
  10788. }
  10789. /* Emit an asm sequence to start a noat block and load the address
  10790. of a label into $1. */
  10791. void
  10792. mips_output_load_label (rtx target)
  10793. {
  10794. mips_push_asm_switch (&mips_noat);
  10795. if (TARGET_EXPLICIT_RELOCS)
  10796. {
  10797. mips_process_load_label (target);
  10798. mips_multi_write ();
  10799. }
  10800. else
  10801. {
  10802. if (Pmode == DImode)
  10803. output_asm_insn ("dla\t%@,%0", &target);
  10804. else
  10805. output_asm_insn ("la\t%@,%0", &target);
  10806. }
  10807. }
  10808. /* Return the length of INSN. LENGTH is the initial length computed by
  10809. attributes in the machine-description file. */
  10810. int
  10811. mips_adjust_insn_length (rtx_insn *insn, int length)
  10812. {
  10813. /* mips.md uses MAX_PIC_BRANCH_LENGTH as a placeholder for the length
  10814. of a PIC long-branch sequence. Substitute the correct value. */
  10815. if (length == MAX_PIC_BRANCH_LENGTH
  10816. && JUMP_P (insn)
  10817. && INSN_CODE (insn) >= 0
  10818. && get_attr_type (insn) == TYPE_BRANCH)
  10819. {
  10820. /* Add the branch-over instruction and its delay slot, if this
  10821. is a conditional branch. */
  10822. length = simplejump_p (insn) ? 0 : 8;
  10823. /* Add the size of a load into $AT. */
  10824. length += BASE_INSN_LENGTH * mips_load_label_num_insns ();
  10825. /* Add the length of an indirect jump, ignoring the delay slot. */
  10826. length += TARGET_COMPRESSION ? 2 : 4;
  10827. }
  10828. /* A unconditional jump has an unfilled delay slot if it is not part
  10829. of a sequence. A conditional jump normally has a delay slot, but
  10830. does not on MIPS16. */
  10831. if (CALL_P (insn) || (TARGET_MIPS16 ? simplejump_p (insn) : JUMP_P (insn)))
  10832. length += TARGET_MIPS16 ? 2 : 4;
  10833. /* See how many nops might be needed to avoid hardware hazards. */
  10834. if (!cfun->machine->ignore_hazard_length_p
  10835. && INSN_P (insn)
  10836. && INSN_CODE (insn) >= 0)
  10837. switch (get_attr_hazard (insn))
  10838. {
  10839. case HAZARD_NONE:
  10840. break;
  10841. case HAZARD_DELAY:
  10842. length += NOP_INSN_LENGTH;
  10843. break;
  10844. case HAZARD_HILO:
  10845. length += NOP_INSN_LENGTH * 2;
  10846. break;
  10847. }
  10848. return length;
  10849. }
  10850. /* Return the assembly code for INSN, which has the operands given by
  10851. OPERANDS, and which branches to OPERANDS[0] if some condition is true.
  10852. BRANCH_IF_TRUE is the asm template that should be used if OPERANDS[0]
  10853. is in range of a direct branch. BRANCH_IF_FALSE is an inverted
  10854. version of BRANCH_IF_TRUE. */
  10855. const char *
  10856. mips_output_conditional_branch (rtx_insn *insn, rtx *operands,
  10857. const char *branch_if_true,
  10858. const char *branch_if_false)
  10859. {
  10860. unsigned int length;
  10861. rtx taken;
  10862. gcc_assert (LABEL_P (operands[0]));
  10863. length = get_attr_length (insn);
  10864. if (length <= 8)
  10865. {
  10866. /* Just a simple conditional branch. */
  10867. mips_branch_likely = (final_sequence && INSN_ANNULLED_BRANCH_P (insn));
  10868. return branch_if_true;
  10869. }
  10870. /* Generate a reversed branch around a direct jump. This fallback does
  10871. not use branch-likely instructions. */
  10872. mips_branch_likely = false;
  10873. rtx_code_label *not_taken = gen_label_rtx ();
  10874. taken = operands[0];
  10875. /* Generate the reversed branch to NOT_TAKEN. */
  10876. operands[0] = not_taken;
  10877. output_asm_insn (branch_if_false, operands);
  10878. /* If INSN has a delay slot, we must provide delay slots for both the
  10879. branch to NOT_TAKEN and the conditional jump. We must also ensure
  10880. that INSN's delay slot is executed in the appropriate cases. */
  10881. if (final_sequence)
  10882. {
  10883. /* This first delay slot will always be executed, so use INSN's
  10884. delay slot if is not annulled. */
  10885. if (!INSN_ANNULLED_BRANCH_P (insn))
  10886. {
  10887. final_scan_insn (final_sequence->insn (1),
  10888. asm_out_file, optimize, 1, NULL);
  10889. final_sequence->insn (1)->set_deleted ();
  10890. }
  10891. else
  10892. output_asm_insn ("nop", 0);
  10893. fprintf (asm_out_file, "\n");
  10894. }
  10895. /* Output the unconditional branch to TAKEN. */
  10896. if (TARGET_ABSOLUTE_JUMPS)
  10897. output_asm_insn (MIPS_ABSOLUTE_JUMP ("j\t%0%/"), &taken);
  10898. else
  10899. {
  10900. mips_output_load_label (taken);
  10901. output_asm_insn ("jr\t%@%]%/", 0);
  10902. }
  10903. /* Now deal with its delay slot; see above. */
  10904. if (final_sequence)
  10905. {
  10906. /* This delay slot will only be executed if the branch is taken.
  10907. Use INSN's delay slot if is annulled. */
  10908. if (INSN_ANNULLED_BRANCH_P (insn))
  10909. {
  10910. final_scan_insn (final_sequence->insn (1),
  10911. asm_out_file, optimize, 1, NULL);
  10912. final_sequence->insn (1)->set_deleted ();
  10913. }
  10914. else
  10915. output_asm_insn ("nop", 0);
  10916. fprintf (asm_out_file, "\n");
  10917. }
  10918. /* Output NOT_TAKEN. */
  10919. targetm.asm_out.internal_label (asm_out_file, "L",
  10920. CODE_LABEL_NUMBER (not_taken));
  10921. return "";
  10922. }
  10923. /* Return the assembly code for INSN, which branches to OPERANDS[0]
  10924. if some ordering condition is true. The condition is given by
  10925. OPERANDS[1] if !INVERTED_P, otherwise it is the inverse of
  10926. OPERANDS[1]. OPERANDS[2] is the comparison's first operand;
  10927. its second is always zero. */
  10928. const char *
  10929. mips_output_order_conditional_branch (rtx_insn *insn, rtx *operands, bool inverted_p)
  10930. {
  10931. const char *branch[2];
  10932. /* Make BRANCH[1] branch to OPERANDS[0] when the condition is true.
  10933. Make BRANCH[0] branch on the inverse condition. */
  10934. switch (GET_CODE (operands[1]))
  10935. {
  10936. /* These cases are equivalent to comparisons against zero. */
  10937. case LEU:
  10938. inverted_p = !inverted_p;
  10939. /* Fall through. */
  10940. case GTU:
  10941. branch[!inverted_p] = MIPS_BRANCH ("bne", "%2,%.,%0");
  10942. branch[inverted_p] = MIPS_BRANCH ("beq", "%2,%.,%0");
  10943. break;
  10944. /* These cases are always true or always false. */
  10945. case LTU:
  10946. inverted_p = !inverted_p;
  10947. /* Fall through. */
  10948. case GEU:
  10949. branch[!inverted_p] = MIPS_BRANCH ("beq", "%.,%.,%0");
  10950. branch[inverted_p] = MIPS_BRANCH ("bne", "%.,%.,%0");
  10951. break;
  10952. default:
  10953. branch[!inverted_p] = MIPS_BRANCH ("b%C1z", "%2,%0");
  10954. branch[inverted_p] = MIPS_BRANCH ("b%N1z", "%2,%0");
  10955. break;
  10956. }
  10957. return mips_output_conditional_branch (insn, operands, branch[1], branch[0]);
  10958. }
  10959. /* Start a block of code that needs access to the LL, SC and SYNC
  10960. instructions. */
  10961. static void
  10962. mips_start_ll_sc_sync_block (void)
  10963. {
  10964. if (!ISA_HAS_LL_SC)
  10965. {
  10966. output_asm_insn (".set\tpush", 0);
  10967. if (TARGET_64BIT)
  10968. output_asm_insn (".set\tmips3", 0);
  10969. else
  10970. output_asm_insn (".set\tmips2", 0);
  10971. }
  10972. }
  10973. /* End a block started by mips_start_ll_sc_sync_block. */
  10974. static void
  10975. mips_end_ll_sc_sync_block (void)
  10976. {
  10977. if (!ISA_HAS_LL_SC)
  10978. output_asm_insn (".set\tpop", 0);
  10979. }
  10980. /* Output and/or return the asm template for a sync instruction. */
  10981. const char *
  10982. mips_output_sync (void)
  10983. {
  10984. mips_start_ll_sc_sync_block ();
  10985. output_asm_insn ("sync", 0);
  10986. mips_end_ll_sc_sync_block ();
  10987. return "";
  10988. }
  10989. /* Return the asm template associated with sync_insn1 value TYPE.
  10990. IS_64BIT_P is true if we want a 64-bit rather than 32-bit operation. */
  10991. static const char *
  10992. mips_sync_insn1_template (enum attr_sync_insn1 type, bool is_64bit_p)
  10993. {
  10994. switch (type)
  10995. {
  10996. case SYNC_INSN1_MOVE:
  10997. return "move\t%0,%z2";
  10998. case SYNC_INSN1_LI:
  10999. return "li\t%0,%2";
  11000. case SYNC_INSN1_ADDU:
  11001. return is_64bit_p ? "daddu\t%0,%1,%z2" : "addu\t%0,%1,%z2";
  11002. case SYNC_INSN1_ADDIU:
  11003. return is_64bit_p ? "daddiu\t%0,%1,%2" : "addiu\t%0,%1,%2";
  11004. case SYNC_INSN1_SUBU:
  11005. return is_64bit_p ? "dsubu\t%0,%1,%z2" : "subu\t%0,%1,%z2";
  11006. case SYNC_INSN1_AND:
  11007. return "and\t%0,%1,%z2";
  11008. case SYNC_INSN1_ANDI:
  11009. return "andi\t%0,%1,%2";
  11010. case SYNC_INSN1_OR:
  11011. return "or\t%0,%1,%z2";
  11012. case SYNC_INSN1_ORI:
  11013. return "ori\t%0,%1,%2";
  11014. case SYNC_INSN1_XOR:
  11015. return "xor\t%0,%1,%z2";
  11016. case SYNC_INSN1_XORI:
  11017. return "xori\t%0,%1,%2";
  11018. }
  11019. gcc_unreachable ();
  11020. }
  11021. /* Return the asm template associated with sync_insn2 value TYPE. */
  11022. static const char *
  11023. mips_sync_insn2_template (enum attr_sync_insn2 type)
  11024. {
  11025. switch (type)
  11026. {
  11027. case SYNC_INSN2_NOP:
  11028. gcc_unreachable ();
  11029. case SYNC_INSN2_AND:
  11030. return "and\t%0,%1,%z2";
  11031. case SYNC_INSN2_XOR:
  11032. return "xor\t%0,%1,%z2";
  11033. case SYNC_INSN2_NOT:
  11034. return "nor\t%0,%1,%.";
  11035. }
  11036. gcc_unreachable ();
  11037. }
  11038. /* OPERANDS are the operands to a sync loop instruction and INDEX is
  11039. the value of the one of the sync_* attributes. Return the operand
  11040. referred to by the attribute, or DEFAULT_VALUE if the insn doesn't
  11041. have the associated attribute. */
  11042. static rtx
  11043. mips_get_sync_operand (rtx *operands, int index, rtx default_value)
  11044. {
  11045. if (index > 0)
  11046. default_value = operands[index - 1];
  11047. return default_value;
  11048. }
  11049. /* INSN is a sync loop with operands OPERANDS. Build up a multi-insn
  11050. sequence for it. */
  11051. static void
  11052. mips_process_sync_loop (rtx_insn *insn, rtx *operands)
  11053. {
  11054. rtx at, mem, oldval, newval, inclusive_mask, exclusive_mask;
  11055. rtx required_oldval, insn1_op2, tmp1, tmp2, tmp3, cmp;
  11056. unsigned int tmp3_insn;
  11057. enum attr_sync_insn1 insn1;
  11058. enum attr_sync_insn2 insn2;
  11059. bool is_64bit_p;
  11060. int memmodel_attr;
  11061. enum memmodel model;
  11062. /* Read an operand from the sync_WHAT attribute and store it in
  11063. variable WHAT. DEFAULT is the default value if no attribute
  11064. is specified. */
  11065. #define READ_OPERAND(WHAT, DEFAULT) \
  11066. WHAT = mips_get_sync_operand (operands, (int) get_attr_sync_##WHAT (insn), \
  11067. DEFAULT)
  11068. /* Read the memory. */
  11069. READ_OPERAND (mem, 0);
  11070. gcc_assert (mem);
  11071. is_64bit_p = (GET_MODE_BITSIZE (GET_MODE (mem)) == 64);
  11072. /* Read the other attributes. */
  11073. at = gen_rtx_REG (GET_MODE (mem), AT_REGNUM);
  11074. READ_OPERAND (oldval, at);
  11075. READ_OPERAND (cmp, 0);
  11076. READ_OPERAND (newval, at);
  11077. READ_OPERAND (inclusive_mask, 0);
  11078. READ_OPERAND (exclusive_mask, 0);
  11079. READ_OPERAND (required_oldval, 0);
  11080. READ_OPERAND (insn1_op2, 0);
  11081. insn1 = get_attr_sync_insn1 (insn);
  11082. insn2 = get_attr_sync_insn2 (insn);
  11083. /* Don't bother setting CMP result that is never used. */
  11084. if (cmp && find_reg_note (insn, REG_UNUSED, cmp))
  11085. cmp = 0;
  11086. memmodel_attr = get_attr_sync_memmodel (insn);
  11087. switch (memmodel_attr)
  11088. {
  11089. case 10:
  11090. model = MEMMODEL_ACQ_REL;
  11091. break;
  11092. case 11:
  11093. model = MEMMODEL_ACQUIRE;
  11094. break;
  11095. default:
  11096. model = (enum memmodel) INTVAL (operands[memmodel_attr]);
  11097. }
  11098. mips_multi_start ();
  11099. /* Output the release side of the memory barrier. */
  11100. if (need_atomic_barrier_p (model, true))
  11101. {
  11102. if (required_oldval == 0 && TARGET_OCTEON)
  11103. {
  11104. /* Octeon doesn't reorder reads, so a full barrier can be
  11105. created by using SYNCW to order writes combined with the
  11106. write from the following SC. When the SC successfully
  11107. completes, we know that all preceding writes are also
  11108. committed to the coherent memory system. It is possible
  11109. for a single SYNCW to fail, but a pair of them will never
  11110. fail, so we use two. */
  11111. mips_multi_add_insn ("syncw", NULL);
  11112. mips_multi_add_insn ("syncw", NULL);
  11113. }
  11114. else
  11115. mips_multi_add_insn ("sync", NULL);
  11116. }
  11117. /* Output the branch-back label. */
  11118. mips_multi_add_label ("1:");
  11119. /* OLDVAL = *MEM. */
  11120. mips_multi_add_insn (is_64bit_p ? "lld\t%0,%1" : "ll\t%0,%1",
  11121. oldval, mem, NULL);
  11122. /* if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2. */
  11123. if (required_oldval)
  11124. {
  11125. if (inclusive_mask == 0)
  11126. tmp1 = oldval;
  11127. else
  11128. {
  11129. gcc_assert (oldval != at);
  11130. mips_multi_add_insn ("and\t%0,%1,%2",
  11131. at, oldval, inclusive_mask, NULL);
  11132. tmp1 = at;
  11133. }
  11134. mips_multi_add_insn ("bne\t%0,%z1,2f", tmp1, required_oldval, NULL);
  11135. /* CMP = 0 [delay slot]. */
  11136. if (cmp)
  11137. mips_multi_add_insn ("li\t%0,0", cmp, NULL);
  11138. }
  11139. /* $TMP1 = OLDVAL & EXCLUSIVE_MASK. */
  11140. if (exclusive_mask == 0)
  11141. tmp1 = const0_rtx;
  11142. else
  11143. {
  11144. gcc_assert (oldval != at);
  11145. mips_multi_add_insn ("and\t%0,%1,%z2",
  11146. at, oldval, exclusive_mask, NULL);
  11147. tmp1 = at;
  11148. }
  11149. /* $TMP2 = INSN1 (OLDVAL, INSN1_OP2).
  11150. We can ignore moves if $TMP4 != INSN1_OP2, since we'll still emit
  11151. at least one instruction in that case. */
  11152. if (insn1 == SYNC_INSN1_MOVE
  11153. && (tmp1 != const0_rtx || insn2 != SYNC_INSN2_NOP))
  11154. tmp2 = insn1_op2;
  11155. else
  11156. {
  11157. mips_multi_add_insn (mips_sync_insn1_template (insn1, is_64bit_p),
  11158. newval, oldval, insn1_op2, NULL);
  11159. tmp2 = newval;
  11160. }
  11161. /* $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK). */
  11162. if (insn2 == SYNC_INSN2_NOP)
  11163. tmp3 = tmp2;
  11164. else
  11165. {
  11166. mips_multi_add_insn (mips_sync_insn2_template (insn2),
  11167. newval, tmp2, inclusive_mask, NULL);
  11168. tmp3 = newval;
  11169. }
  11170. tmp3_insn = mips_multi_last_index ();
  11171. /* $AT = $TMP1 | $TMP3. */
  11172. if (tmp1 == const0_rtx || tmp3 == const0_rtx)
  11173. {
  11174. mips_multi_set_operand (tmp3_insn, 0, at);
  11175. tmp3 = at;
  11176. }
  11177. else
  11178. {
  11179. gcc_assert (tmp1 != tmp3);
  11180. mips_multi_add_insn ("or\t%0,%1,%2", at, tmp1, tmp3, NULL);
  11181. }
  11182. /* if (!commit (*MEM = $AT)) goto 1.
  11183. This will sometimes be a delayed branch; see the write code below
  11184. for details. */
  11185. mips_multi_add_insn (is_64bit_p ? "scd\t%0,%1" : "sc\t%0,%1", at, mem, NULL);
  11186. /* When using branch likely (-mfix-r10000), the delay slot instruction
  11187. will be annulled on false. The normal delay slot instructions
  11188. calculate the overall result of the atomic operation and must not
  11189. be annulled. To ensure this behaviour unconditionally use a NOP
  11190. in the delay slot for the branch likely case. */
  11191. mips_multi_add_insn ("beq%?\t%0,%.,1b%~", at, NULL);
  11192. /* if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]. */
  11193. if (insn1 != SYNC_INSN1_MOVE && insn1 != SYNC_INSN1_LI && tmp3 != newval)
  11194. {
  11195. mips_multi_copy_insn (tmp3_insn);
  11196. mips_multi_set_operand (mips_multi_last_index (), 0, newval);
  11197. }
  11198. else if (!(required_oldval && cmp) && !mips_branch_likely)
  11199. mips_multi_add_insn ("nop", NULL);
  11200. /* CMP = 1 -- either standalone or in a delay slot. */
  11201. if (required_oldval && cmp)
  11202. mips_multi_add_insn ("li\t%0,1", cmp, NULL);
  11203. /* Output the acquire side of the memory barrier. */
  11204. if (TARGET_SYNC_AFTER_SC && need_atomic_barrier_p (model, false))
  11205. mips_multi_add_insn ("sync", NULL);
  11206. /* Output the exit label, if needed. */
  11207. if (required_oldval)
  11208. mips_multi_add_label ("2:");
  11209. #undef READ_OPERAND
  11210. }
  11211. /* Output and/or return the asm template for sync loop INSN, which has
  11212. the operands given by OPERANDS. */
  11213. const char *
  11214. mips_output_sync_loop (rtx_insn *insn, rtx *operands)
  11215. {
  11216. /* Use branch-likely instructions to work around the LL/SC R10000
  11217. errata. */
  11218. mips_branch_likely = TARGET_FIX_R10000;
  11219. mips_process_sync_loop (insn, operands);
  11220. mips_push_asm_switch (&mips_noreorder);
  11221. mips_push_asm_switch (&mips_nomacro);
  11222. mips_push_asm_switch (&mips_noat);
  11223. mips_start_ll_sc_sync_block ();
  11224. mips_multi_write ();
  11225. mips_end_ll_sc_sync_block ();
  11226. mips_pop_asm_switch (&mips_noat);
  11227. mips_pop_asm_switch (&mips_nomacro);
  11228. mips_pop_asm_switch (&mips_noreorder);
  11229. return "";
  11230. }
  11231. /* Return the number of individual instructions in sync loop INSN,
  11232. which has the operands given by OPERANDS. */
  11233. unsigned int
  11234. mips_sync_loop_insns (rtx_insn *insn, rtx *operands)
  11235. {
  11236. /* Use branch-likely instructions to work around the LL/SC R10000
  11237. errata. */
  11238. mips_branch_likely = TARGET_FIX_R10000;
  11239. mips_process_sync_loop (insn, operands);
  11240. return mips_multi_num_insns;
  11241. }
  11242. /* Return the assembly code for DIV or DDIV instruction DIVISION, which has
  11243. the operands given by OPERANDS. Add in a divide-by-zero check if needed.
  11244. When working around R4000 and R4400 errata, we need to make sure that
  11245. the division is not immediately followed by a shift[1][2]. We also
  11246. need to stop the division from being put into a branch delay slot[3].
  11247. The easiest way to avoid both problems is to add a nop after the
  11248. division. When a divide-by-zero check is needed, this nop can be
  11249. used to fill the branch delay slot.
  11250. [1] If a double-word or a variable shift executes immediately
  11251. after starting an integer division, the shift may give an
  11252. incorrect result. See quotations of errata #16 and #28 from
  11253. "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
  11254. in mips.md for details.
  11255. [2] A similar bug to [1] exists for all revisions of the
  11256. R4000 and the R4400 when run in an MC configuration.
  11257. From "MIPS R4000MC Errata, Processor Revision 2.2 and 3.0":
  11258. "19. In this following sequence:
  11259. ddiv (or ddivu or div or divu)
  11260. dsll32 (or dsrl32, dsra32)
  11261. if an MPT stall occurs, while the divide is slipping the cpu
  11262. pipeline, then the following double shift would end up with an
  11263. incorrect result.
  11264. Workaround: The compiler needs to avoid generating any
  11265. sequence with divide followed by extended double shift."
  11266. This erratum is also present in "MIPS R4400MC Errata, Processor
  11267. Revision 1.0" and "MIPS R4400MC Errata, Processor Revision 2.0
  11268. & 3.0" as errata #10 and #4, respectively.
  11269. [3] From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
  11270. (also valid for MIPS R4000MC processors):
  11271. "52. R4000SC: This bug does not apply for the R4000PC.
  11272. There are two flavors of this bug:
  11273. 1) If the instruction just after divide takes an RF exception
  11274. (tlb-refill, tlb-invalid) and gets an instruction cache
  11275. miss (both primary and secondary) and the line which is
  11276. currently in secondary cache at this index had the first
  11277. data word, where the bits 5..2 are set, then R4000 would
  11278. get a wrong result for the div.
  11279. ##1
  11280. nop
  11281. div r8, r9
  11282. ------------------- # end-of page. -tlb-refill
  11283. nop
  11284. ##2
  11285. nop
  11286. div r8, r9
  11287. ------------------- # end-of page. -tlb-invalid
  11288. nop
  11289. 2) If the divide is in the taken branch delay slot, where the
  11290. target takes RF exception and gets an I-cache miss for the
  11291. exception vector or where I-cache miss occurs for the
  11292. target address, under the above mentioned scenarios, the
  11293. div would get wrong results.
  11294. ##1
  11295. j r2 # to next page mapped or unmapped
  11296. div r8,r9 # this bug would be there as long
  11297. # as there is an ICache miss and
  11298. nop # the "data pattern" is present
  11299. ##2
  11300. beq r0, r0, NextPage # to Next page
  11301. div r8,r9
  11302. nop
  11303. This bug is present for div, divu, ddiv, and ddivu
  11304. instructions.
  11305. Workaround: For item 1), OS could make sure that the next page
  11306. after the divide instruction is also mapped. For item 2), the
  11307. compiler could make sure that the divide instruction is not in
  11308. the branch delay slot."
  11309. These processors have PRId values of 0x00004220 and 0x00004300 for
  11310. the R4000 and 0x00004400, 0x00004500 and 0x00004600 for the R4400. */
  11311. const char *
  11312. mips_output_division (const char *division, rtx *operands)
  11313. {
  11314. const char *s;
  11315. s = division;
  11316. if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
  11317. {
  11318. output_asm_insn (s, operands);
  11319. s = "nop";
  11320. }
  11321. if (TARGET_CHECK_ZERO_DIV)
  11322. {
  11323. if (TARGET_MIPS16)
  11324. {
  11325. output_asm_insn (s, operands);
  11326. s = "bnez\t%2,1f\n\tbreak\t7\n1:";
  11327. }
  11328. else if (GENERATE_DIVIDE_TRAPS)
  11329. {
  11330. /* Avoid long replay penalty on load miss by putting the trap before
  11331. the divide. */
  11332. if (TUNE_74K)
  11333. output_asm_insn ("teq\t%2,%.,7", operands);
  11334. else
  11335. {
  11336. output_asm_insn (s, operands);
  11337. s = "teq\t%2,%.,7";
  11338. }
  11339. }
  11340. else
  11341. {
  11342. output_asm_insn ("%(bne\t%2,%.,1f", operands);
  11343. output_asm_insn (s, operands);
  11344. s = "break\t7%)\n1:";
  11345. }
  11346. }
  11347. return s;
  11348. }
  11349. /* Return true if destination of IN_INSN is used as add source in
  11350. OUT_INSN. Both IN_INSN and OUT_INSN are of type fmadd. Example:
  11351. madd.s dst, x, y, z
  11352. madd.s a, dst, b, c */
  11353. bool
  11354. mips_fmadd_bypass (rtx_insn *out_insn, rtx_insn *in_insn)
  11355. {
  11356. int dst_reg, src_reg;
  11357. gcc_assert (get_attr_type (in_insn) == TYPE_FMADD);
  11358. gcc_assert (get_attr_type (out_insn) == TYPE_FMADD);
  11359. extract_insn (in_insn);
  11360. dst_reg = REG_P (recog_data.operand[0]);
  11361. extract_insn (out_insn);
  11362. src_reg = REG_P (recog_data.operand[1]);
  11363. if (dst_reg == src_reg)
  11364. return true;
  11365. return false;
  11366. }
  11367. /* Return true if IN_INSN is a multiply-add or multiply-subtract
  11368. instruction and if OUT_INSN assigns to the accumulator operand. */
  11369. bool
  11370. mips_linked_madd_p (rtx_insn *out_insn, rtx_insn *in_insn)
  11371. {
  11372. enum attr_accum_in accum_in;
  11373. int accum_in_opnum;
  11374. rtx accum_in_op;
  11375. if (recog_memoized (in_insn) < 0)
  11376. return false;
  11377. accum_in = get_attr_accum_in (in_insn);
  11378. if (accum_in == ACCUM_IN_NONE)
  11379. return false;
  11380. accum_in_opnum = accum_in - ACCUM_IN_0;
  11381. extract_insn (in_insn);
  11382. gcc_assert (accum_in_opnum < recog_data.n_operands);
  11383. accum_in_op = recog_data.operand[accum_in_opnum];
  11384. return reg_set_p (accum_in_op, out_insn);
  11385. }
  11386. /* True if the dependency between OUT_INSN and IN_INSN is on the store
  11387. data rather than the address. We need this because the cprestore
  11388. pattern is type "store", but is defined using an UNSPEC_VOLATILE,
  11389. which causes the default routine to abort. We just return false
  11390. for that case. */
  11391. bool
  11392. mips_store_data_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn)
  11393. {
  11394. if (GET_CODE (PATTERN (in_insn)) == UNSPEC_VOLATILE)
  11395. return false;
  11396. return !store_data_bypass_p (out_insn, in_insn);
  11397. }
  11398. /* Variables and flags used in scheduler hooks when tuning for
  11399. Loongson 2E/2F. */
  11400. static struct
  11401. {
  11402. /* Variables to support Loongson 2E/2F round-robin [F]ALU1/2 dispatch
  11403. strategy. */
  11404. /* If true, then next ALU1/2 instruction will go to ALU1. */
  11405. bool alu1_turn_p;
  11406. /* If true, then next FALU1/2 unstruction will go to FALU1. */
  11407. bool falu1_turn_p;
  11408. /* Codes to query if [f]alu{1,2}_core units are subscribed or not. */
  11409. int alu1_core_unit_code;
  11410. int alu2_core_unit_code;
  11411. int falu1_core_unit_code;
  11412. int falu2_core_unit_code;
  11413. /* True if current cycle has a multi instruction.
  11414. This flag is used in mips_ls2_dfa_post_advance_cycle. */
  11415. bool cycle_has_multi_p;
  11416. /* Instructions to subscribe ls2_[f]alu{1,2}_turn_enabled units.
  11417. These are used in mips_ls2_dfa_post_advance_cycle to initialize
  11418. DFA state.
  11419. E.g., when alu1_turn_enabled_insn is issued it makes next ALU1/2
  11420. instruction to go ALU1. */
  11421. rtx_insn *alu1_turn_enabled_insn;
  11422. rtx_insn *alu2_turn_enabled_insn;
  11423. rtx_insn *falu1_turn_enabled_insn;
  11424. rtx_insn *falu2_turn_enabled_insn;
  11425. } mips_ls2;
  11426. /* Implement TARGET_SCHED_ADJUST_COST. We assume that anti and output
  11427. dependencies have no cost, except on the 20Kc where output-dependence
  11428. is treated like input-dependence. */
  11429. static int
  11430. mips_adjust_cost (rtx_insn *insn ATTRIBUTE_UNUSED, rtx link,
  11431. rtx_insn *dep ATTRIBUTE_UNUSED, int cost)
  11432. {
  11433. if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT
  11434. && TUNE_20KC)
  11435. return cost;
  11436. if (REG_NOTE_KIND (link) != 0)
  11437. return 0;
  11438. return cost;
  11439. }
  11440. /* Return the number of instructions that can be issued per cycle. */
  11441. static int
  11442. mips_issue_rate (void)
  11443. {
  11444. switch (mips_tune)
  11445. {
  11446. case PROCESSOR_74KC:
  11447. case PROCESSOR_74KF2_1:
  11448. case PROCESSOR_74KF1_1:
  11449. case PROCESSOR_74KF3_2:
  11450. /* The 74k is not strictly quad-issue cpu, but can be seen as one
  11451. by the scheduler. It can issue 1 ALU, 1 AGEN and 2 FPU insns,
  11452. but in reality only a maximum of 3 insns can be issued as
  11453. floating-point loads and stores also require a slot in the
  11454. AGEN pipe. */
  11455. case PROCESSOR_R10000:
  11456. /* All R10K Processors are quad-issue (being the first MIPS
  11457. processors to support this feature). */
  11458. return 4;
  11459. case PROCESSOR_20KC:
  11460. case PROCESSOR_R4130:
  11461. case PROCESSOR_R5400:
  11462. case PROCESSOR_R5500:
  11463. case PROCESSOR_R5900:
  11464. case PROCESSOR_R7000:
  11465. case PROCESSOR_R9000:
  11466. case PROCESSOR_OCTEON:
  11467. case PROCESSOR_OCTEON2:
  11468. case PROCESSOR_OCTEON3:
  11469. return 2;
  11470. case PROCESSOR_SB1:
  11471. case PROCESSOR_SB1A:
  11472. /* This is actually 4, but we get better performance if we claim 3.
  11473. This is partly because of unwanted speculative code motion with the
  11474. larger number, and partly because in most common cases we can't
  11475. reach the theoretical max of 4. */
  11476. return 3;
  11477. case PROCESSOR_LOONGSON_2E:
  11478. case PROCESSOR_LOONGSON_2F:
  11479. case PROCESSOR_LOONGSON_3A:
  11480. case PROCESSOR_P5600:
  11481. return 4;
  11482. case PROCESSOR_XLP:
  11483. return (reload_completed ? 4 : 3);
  11484. default:
  11485. return 1;
  11486. }
  11487. }
  11488. /* Implement TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN hook for Loongson2. */
  11489. static void
  11490. mips_ls2_init_dfa_post_cycle_insn (void)
  11491. {
  11492. start_sequence ();
  11493. emit_insn (gen_ls2_alu1_turn_enabled_insn ());
  11494. mips_ls2.alu1_turn_enabled_insn = get_insns ();
  11495. end_sequence ();
  11496. start_sequence ();
  11497. emit_insn (gen_ls2_alu2_turn_enabled_insn ());
  11498. mips_ls2.alu2_turn_enabled_insn = get_insns ();
  11499. end_sequence ();
  11500. start_sequence ();
  11501. emit_insn (gen_ls2_falu1_turn_enabled_insn ());
  11502. mips_ls2.falu1_turn_enabled_insn = get_insns ();
  11503. end_sequence ();
  11504. start_sequence ();
  11505. emit_insn (gen_ls2_falu2_turn_enabled_insn ());
  11506. mips_ls2.falu2_turn_enabled_insn = get_insns ();
  11507. end_sequence ();
  11508. mips_ls2.alu1_core_unit_code = get_cpu_unit_code ("ls2_alu1_core");
  11509. mips_ls2.alu2_core_unit_code = get_cpu_unit_code ("ls2_alu2_core");
  11510. mips_ls2.falu1_core_unit_code = get_cpu_unit_code ("ls2_falu1_core");
  11511. mips_ls2.falu2_core_unit_code = get_cpu_unit_code ("ls2_falu2_core");
  11512. }
  11513. /* Implement TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN hook.
  11514. Init data used in mips_dfa_post_advance_cycle. */
  11515. static void
  11516. mips_init_dfa_post_cycle_insn (void)
  11517. {
  11518. if (TUNE_LOONGSON_2EF)
  11519. mips_ls2_init_dfa_post_cycle_insn ();
  11520. }
  11521. /* Initialize STATE when scheduling for Loongson 2E/2F.
  11522. Support round-robin dispatch scheme by enabling only one of
  11523. ALU1/ALU2 and one of FALU1/FALU2 units for ALU1/2 and FALU1/2 instructions
  11524. respectively. */
  11525. static void
  11526. mips_ls2_dfa_post_advance_cycle (state_t state)
  11527. {
  11528. if (cpu_unit_reservation_p (state, mips_ls2.alu1_core_unit_code))
  11529. {
  11530. /* Though there are no non-pipelined ALU1 insns,
  11531. we can get an instruction of type 'multi' before reload. */
  11532. gcc_assert (mips_ls2.cycle_has_multi_p);
  11533. mips_ls2.alu1_turn_p = false;
  11534. }
  11535. mips_ls2.cycle_has_multi_p = false;
  11536. if (cpu_unit_reservation_p (state, mips_ls2.alu2_core_unit_code))
  11537. /* We have a non-pipelined alu instruction in the core,
  11538. adjust round-robin counter. */
  11539. mips_ls2.alu1_turn_p = true;
  11540. if (mips_ls2.alu1_turn_p)
  11541. {
  11542. if (state_transition (state, mips_ls2.alu1_turn_enabled_insn) >= 0)
  11543. gcc_unreachable ();
  11544. }
  11545. else
  11546. {
  11547. if (state_transition (state, mips_ls2.alu2_turn_enabled_insn) >= 0)
  11548. gcc_unreachable ();
  11549. }
  11550. if (cpu_unit_reservation_p (state, mips_ls2.falu1_core_unit_code))
  11551. {
  11552. /* There are no non-pipelined FALU1 insns. */
  11553. gcc_unreachable ();
  11554. mips_ls2.falu1_turn_p = false;
  11555. }
  11556. if (cpu_unit_reservation_p (state, mips_ls2.falu2_core_unit_code))
  11557. /* We have a non-pipelined falu instruction in the core,
  11558. adjust round-robin counter. */
  11559. mips_ls2.falu1_turn_p = true;
  11560. if (mips_ls2.falu1_turn_p)
  11561. {
  11562. if (state_transition (state, mips_ls2.falu1_turn_enabled_insn) >= 0)
  11563. gcc_unreachable ();
  11564. }
  11565. else
  11566. {
  11567. if (state_transition (state, mips_ls2.falu2_turn_enabled_insn) >= 0)
  11568. gcc_unreachable ();
  11569. }
  11570. }
  11571. /* Implement TARGET_SCHED_DFA_POST_ADVANCE_CYCLE.
  11572. This hook is being called at the start of each cycle. */
  11573. static void
  11574. mips_dfa_post_advance_cycle (void)
  11575. {
  11576. if (TUNE_LOONGSON_2EF)
  11577. mips_ls2_dfa_post_advance_cycle (curr_state);
  11578. }
  11579. /* Implement TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD. This should
  11580. be as wide as the scheduling freedom in the DFA. */
  11581. static int
  11582. mips_multipass_dfa_lookahead (void)
  11583. {
  11584. /* Can schedule up to 4 of the 6 function units in any one cycle. */
  11585. if (TUNE_SB1)
  11586. return 4;
  11587. if (TUNE_LOONGSON_2EF || TUNE_LOONGSON_3A)
  11588. return 4;
  11589. if (TUNE_OCTEON)
  11590. return 2;
  11591. if (TUNE_P5600)
  11592. return 4;
  11593. return 0;
  11594. }
  11595. /* Remove the instruction at index LOWER from ready queue READY and
  11596. reinsert it in front of the instruction at index HIGHER. LOWER must
  11597. be <= HIGHER. */
  11598. static void
  11599. mips_promote_ready (rtx_insn **ready, int lower, int higher)
  11600. {
  11601. rtx_insn *new_head;
  11602. int i;
  11603. new_head = ready[lower];
  11604. for (i = lower; i < higher; i++)
  11605. ready[i] = ready[i + 1];
  11606. ready[i] = new_head;
  11607. }
  11608. /* If the priority of the instruction at POS2 in the ready queue READY
  11609. is within LIMIT units of that of the instruction at POS1, swap the
  11610. instructions if POS2 is not already less than POS1. */
  11611. static void
  11612. mips_maybe_swap_ready (rtx_insn **ready, int pos1, int pos2, int limit)
  11613. {
  11614. if (pos1 < pos2
  11615. && INSN_PRIORITY (ready[pos1]) + limit >= INSN_PRIORITY (ready[pos2]))
  11616. {
  11617. rtx_insn *temp;
  11618. temp = ready[pos1];
  11619. ready[pos1] = ready[pos2];
  11620. ready[pos2] = temp;
  11621. }
  11622. }
  11623. /* Used by TUNE_MACC_CHAINS to record the last scheduled instruction
  11624. that may clobber hi or lo. */
  11625. static rtx_insn *mips_macc_chains_last_hilo;
  11626. /* A TUNE_MACC_CHAINS helper function. Record that instruction INSN has
  11627. been scheduled, updating mips_macc_chains_last_hilo appropriately. */
  11628. static void
  11629. mips_macc_chains_record (rtx_insn *insn)
  11630. {
  11631. if (get_attr_may_clobber_hilo (insn))
  11632. mips_macc_chains_last_hilo = insn;
  11633. }
  11634. /* A TUNE_MACC_CHAINS helper function. Search ready queue READY, which
  11635. has NREADY elements, looking for a multiply-add or multiply-subtract
  11636. instruction that is cumulative with mips_macc_chains_last_hilo.
  11637. If there is one, promote it ahead of anything else that might
  11638. clobber hi or lo. */
  11639. static void
  11640. mips_macc_chains_reorder (rtx_insn **ready, int nready)
  11641. {
  11642. int i, j;
  11643. if (mips_macc_chains_last_hilo != 0)
  11644. for (i = nready - 1; i >= 0; i--)
  11645. if (mips_linked_madd_p (mips_macc_chains_last_hilo, ready[i]))
  11646. {
  11647. for (j = nready - 1; j > i; j--)
  11648. if (recog_memoized (ready[j]) >= 0
  11649. && get_attr_may_clobber_hilo (ready[j]))
  11650. {
  11651. mips_promote_ready (ready, i, j);
  11652. break;
  11653. }
  11654. break;
  11655. }
  11656. }
  11657. /* The last instruction to be scheduled. */
  11658. static rtx_insn *vr4130_last_insn;
  11659. /* A note_stores callback used by vr4130_true_reg_dependence_p. DATA
  11660. points to an rtx that is initially an instruction. Nullify the rtx
  11661. if the instruction uses the value of register X. */
  11662. static void
  11663. vr4130_true_reg_dependence_p_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
  11664. void *data)
  11665. {
  11666. rtx *insn_ptr;
  11667. insn_ptr = (rtx *) data;
  11668. if (REG_P (x)
  11669. && *insn_ptr != 0
  11670. && reg_referenced_p (x, PATTERN (*insn_ptr)))
  11671. *insn_ptr = 0;
  11672. }
  11673. /* Return true if there is true register dependence between vr4130_last_insn
  11674. and INSN. */
  11675. static bool
  11676. vr4130_true_reg_dependence_p (rtx insn)
  11677. {
  11678. note_stores (PATTERN (vr4130_last_insn),
  11679. vr4130_true_reg_dependence_p_1, &insn);
  11680. return insn == 0;
  11681. }
  11682. /* A TUNE_MIPS4130 helper function. Given that INSN1 is at the head of
  11683. the ready queue and that INSN2 is the instruction after it, return
  11684. true if it is worth promoting INSN2 ahead of INSN1. Look for cases
  11685. in which INSN1 and INSN2 can probably issue in parallel, but for
  11686. which (INSN2, INSN1) should be less sensitive to instruction
  11687. alignment than (INSN1, INSN2). See 4130.md for more details. */
  11688. static bool
  11689. vr4130_swap_insns_p (rtx_insn *insn1, rtx_insn *insn2)
  11690. {
  11691. sd_iterator_def sd_it;
  11692. dep_t dep;
  11693. /* Check for the following case:
  11694. 1) there is some other instruction X with an anti dependence on INSN1;
  11695. 2) X has a higher priority than INSN2; and
  11696. 3) X is an arithmetic instruction (and thus has no unit restrictions).
  11697. If INSN1 is the last instruction blocking X, it would better to
  11698. choose (INSN1, X) over (INSN2, INSN1). */
  11699. FOR_EACH_DEP (insn1, SD_LIST_FORW, sd_it, dep)
  11700. if (DEP_TYPE (dep) == REG_DEP_ANTI
  11701. && INSN_PRIORITY (DEP_CON (dep)) > INSN_PRIORITY (insn2)
  11702. && recog_memoized (DEP_CON (dep)) >= 0
  11703. && get_attr_vr4130_class (DEP_CON (dep)) == VR4130_CLASS_ALU)
  11704. return false;
  11705. if (vr4130_last_insn != 0
  11706. && recog_memoized (insn1) >= 0
  11707. && recog_memoized (insn2) >= 0)
  11708. {
  11709. /* See whether INSN1 and INSN2 use different execution units,
  11710. or if they are both ALU-type instructions. If so, they can
  11711. probably execute in parallel. */
  11712. enum attr_vr4130_class class1 = get_attr_vr4130_class (insn1);
  11713. enum attr_vr4130_class class2 = get_attr_vr4130_class (insn2);
  11714. if (class1 != class2 || class1 == VR4130_CLASS_ALU)
  11715. {
  11716. /* If only one of the instructions has a dependence on
  11717. vr4130_last_insn, prefer to schedule the other one first. */
  11718. bool dep1_p = vr4130_true_reg_dependence_p (insn1);
  11719. bool dep2_p = vr4130_true_reg_dependence_p (insn2);
  11720. if (dep1_p != dep2_p)
  11721. return dep1_p;
  11722. /* Prefer to schedule INSN2 ahead of INSN1 if vr4130_last_insn
  11723. is not an ALU-type instruction and if INSN1 uses the same
  11724. execution unit. (Note that if this condition holds, we already
  11725. know that INSN2 uses a different execution unit.) */
  11726. if (class1 != VR4130_CLASS_ALU
  11727. && recog_memoized (vr4130_last_insn) >= 0
  11728. && class1 == get_attr_vr4130_class (vr4130_last_insn))
  11729. return true;
  11730. }
  11731. }
  11732. return false;
  11733. }
  11734. /* A TUNE_MIPS4130 helper function. (READY, NREADY) describes a ready
  11735. queue with at least two instructions. Swap the first two if
  11736. vr4130_swap_insns_p says that it could be worthwhile. */
  11737. static void
  11738. vr4130_reorder (rtx_insn **ready, int nready)
  11739. {
  11740. if (vr4130_swap_insns_p (ready[nready - 1], ready[nready - 2]))
  11741. mips_promote_ready (ready, nready - 2, nready - 1);
  11742. }
  11743. /* Record whether last 74k AGEN instruction was a load or store. */
  11744. static enum attr_type mips_last_74k_agen_insn = TYPE_UNKNOWN;
  11745. /* Initialize mips_last_74k_agen_insn from INSN. A null argument
  11746. resets to TYPE_UNKNOWN state. */
  11747. static void
  11748. mips_74k_agen_init (rtx_insn *insn)
  11749. {
  11750. if (!insn || CALL_P (insn) || JUMP_P (insn))
  11751. mips_last_74k_agen_insn = TYPE_UNKNOWN;
  11752. else
  11753. {
  11754. enum attr_type type = get_attr_type (insn);
  11755. if (type == TYPE_LOAD || type == TYPE_STORE)
  11756. mips_last_74k_agen_insn = type;
  11757. }
  11758. }
  11759. /* A TUNE_74K helper function. The 74K AGEN pipeline likes multiple
  11760. loads to be grouped together, and multiple stores to be grouped
  11761. together. Swap things around in the ready queue to make this happen. */
  11762. static void
  11763. mips_74k_agen_reorder (rtx_insn **ready, int nready)
  11764. {
  11765. int i;
  11766. int store_pos, load_pos;
  11767. store_pos = -1;
  11768. load_pos = -1;
  11769. for (i = nready - 1; i >= 0; i--)
  11770. {
  11771. rtx_insn *insn = ready[i];
  11772. if (USEFUL_INSN_P (insn))
  11773. switch (get_attr_type (insn))
  11774. {
  11775. case TYPE_STORE:
  11776. if (store_pos == -1)
  11777. store_pos = i;
  11778. break;
  11779. case TYPE_LOAD:
  11780. if (load_pos == -1)
  11781. load_pos = i;
  11782. break;
  11783. default:
  11784. break;
  11785. }
  11786. }
  11787. if (load_pos == -1 || store_pos == -1)
  11788. return;
  11789. switch (mips_last_74k_agen_insn)
  11790. {
  11791. case TYPE_UNKNOWN:
  11792. /* Prefer to schedule loads since they have a higher latency. */
  11793. case TYPE_LOAD:
  11794. /* Swap loads to the front of the queue. */
  11795. mips_maybe_swap_ready (ready, load_pos, store_pos, 4);
  11796. break;
  11797. case TYPE_STORE:
  11798. /* Swap stores to the front of the queue. */
  11799. mips_maybe_swap_ready (ready, store_pos, load_pos, 4);
  11800. break;
  11801. default:
  11802. break;
  11803. }
  11804. }
  11805. /* Implement TARGET_SCHED_INIT. */
  11806. static void
  11807. mips_sched_init (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
  11808. int max_ready ATTRIBUTE_UNUSED)
  11809. {
  11810. mips_macc_chains_last_hilo = 0;
  11811. vr4130_last_insn = 0;
  11812. mips_74k_agen_init (NULL);
  11813. /* When scheduling for Loongson2, branch instructions go to ALU1,
  11814. therefore basic block is most likely to start with round-robin counter
  11815. pointed to ALU2. */
  11816. mips_ls2.alu1_turn_p = false;
  11817. mips_ls2.falu1_turn_p = true;
  11818. }
  11819. /* Subroutine used by TARGET_SCHED_REORDER and TARGET_SCHED_REORDER2. */
  11820. static void
  11821. mips_sched_reorder_1 (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
  11822. rtx_insn **ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED)
  11823. {
  11824. if (!reload_completed
  11825. && TUNE_MACC_CHAINS
  11826. && *nreadyp > 0)
  11827. mips_macc_chains_reorder (ready, *nreadyp);
  11828. if (reload_completed
  11829. && TUNE_MIPS4130
  11830. && !TARGET_VR4130_ALIGN
  11831. && *nreadyp > 1)
  11832. vr4130_reorder (ready, *nreadyp);
  11833. if (TUNE_74K)
  11834. mips_74k_agen_reorder (ready, *nreadyp);
  11835. }
  11836. /* Implement TARGET_SCHED_REORDER. */
  11837. static int
  11838. mips_sched_reorder (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
  11839. rtx_insn **ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED)
  11840. {
  11841. mips_sched_reorder_1 (file, verbose, ready, nreadyp, cycle);
  11842. return mips_issue_rate ();
  11843. }
  11844. /* Implement TARGET_SCHED_REORDER2. */
  11845. static int
  11846. mips_sched_reorder2 (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
  11847. rtx_insn **ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED)
  11848. {
  11849. mips_sched_reorder_1 (file, verbose, ready, nreadyp, cycle);
  11850. return cached_can_issue_more;
  11851. }
  11852. /* Update round-robin counters for ALU1/2 and FALU1/2. */
  11853. static void
  11854. mips_ls2_variable_issue (rtx_insn *insn)
  11855. {
  11856. if (mips_ls2.alu1_turn_p)
  11857. {
  11858. if (cpu_unit_reservation_p (curr_state, mips_ls2.alu1_core_unit_code))
  11859. mips_ls2.alu1_turn_p = false;
  11860. }
  11861. else
  11862. {
  11863. if (cpu_unit_reservation_p (curr_state, mips_ls2.alu2_core_unit_code))
  11864. mips_ls2.alu1_turn_p = true;
  11865. }
  11866. if (mips_ls2.falu1_turn_p)
  11867. {
  11868. if (cpu_unit_reservation_p (curr_state, mips_ls2.falu1_core_unit_code))
  11869. mips_ls2.falu1_turn_p = false;
  11870. }
  11871. else
  11872. {
  11873. if (cpu_unit_reservation_p (curr_state, mips_ls2.falu2_core_unit_code))
  11874. mips_ls2.falu1_turn_p = true;
  11875. }
  11876. if (recog_memoized (insn) >= 0)
  11877. mips_ls2.cycle_has_multi_p |= (get_attr_type (insn) == TYPE_MULTI);
  11878. }
  11879. /* Implement TARGET_SCHED_VARIABLE_ISSUE. */
  11880. static int
  11881. mips_variable_issue (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
  11882. rtx_insn *insn, int more)
  11883. {
  11884. /* Ignore USEs and CLOBBERs; don't count them against the issue rate. */
  11885. if (USEFUL_INSN_P (insn))
  11886. {
  11887. if (get_attr_type (insn) != TYPE_GHOST)
  11888. more--;
  11889. if (!reload_completed && TUNE_MACC_CHAINS)
  11890. mips_macc_chains_record (insn);
  11891. vr4130_last_insn = insn;
  11892. if (TUNE_74K)
  11893. mips_74k_agen_init (insn);
  11894. else if (TUNE_LOONGSON_2EF)
  11895. mips_ls2_variable_issue (insn);
  11896. }
  11897. /* Instructions of type 'multi' should all be split before
  11898. the second scheduling pass. */
  11899. gcc_assert (!reload_completed
  11900. || recog_memoized (insn) < 0
  11901. || get_attr_type (insn) != TYPE_MULTI);
  11902. cached_can_issue_more = more;
  11903. return more;
  11904. }
  11905. /* Given that we have an rtx of the form (prefetch ... WRITE LOCALITY),
  11906. return the first operand of the associated PREF or PREFX insn. */
  11907. rtx
  11908. mips_prefetch_cookie (rtx write, rtx locality)
  11909. {
  11910. /* store_streamed / load_streamed. */
  11911. if (INTVAL (locality) <= 0)
  11912. return GEN_INT (INTVAL (write) + 4);
  11913. /* store / load. */
  11914. if (INTVAL (locality) <= 2)
  11915. return write;
  11916. /* store_retained / load_retained. */
  11917. return GEN_INT (INTVAL (write) + 6);
  11918. }
  11919. /* Flags that indicate when a built-in function is available.
  11920. BUILTIN_AVAIL_NON_MIPS16
  11921. The function is available on the current target if !TARGET_MIPS16.
  11922. BUILTIN_AVAIL_MIPS16
  11923. The function is available on the current target if TARGET_MIPS16. */
  11924. #define BUILTIN_AVAIL_NON_MIPS16 1
  11925. #define BUILTIN_AVAIL_MIPS16 2
  11926. /* Declare an availability predicate for built-in functions that
  11927. require non-MIPS16 mode and also require COND to be true.
  11928. NAME is the main part of the predicate's name. */
  11929. #define AVAIL_NON_MIPS16(NAME, COND) \
  11930. static unsigned int \
  11931. mips_builtin_avail_##NAME (void) \
  11932. { \
  11933. return (COND) ? BUILTIN_AVAIL_NON_MIPS16 : 0; \
  11934. }
  11935. /* Declare an availability predicate for built-in functions that
  11936. support both MIPS16 and non-MIPS16 code and also require COND
  11937. to be true. NAME is the main part of the predicate's name. */
  11938. #define AVAIL_ALL(NAME, COND) \
  11939. static unsigned int \
  11940. mips_builtin_avail_##NAME (void) \
  11941. { \
  11942. return (COND) ? BUILTIN_AVAIL_NON_MIPS16 | BUILTIN_AVAIL_MIPS16 : 0; \
  11943. }
  11944. /* This structure describes a single built-in function. */
  11945. struct mips_builtin_description {
  11946. /* The code of the main .md file instruction. See mips_builtin_type
  11947. for more information. */
  11948. enum insn_code icode;
  11949. /* The floating-point comparison code to use with ICODE, if any. */
  11950. enum mips_fp_condition cond;
  11951. /* The name of the built-in function. */
  11952. const char *name;
  11953. /* Specifies how the function should be expanded. */
  11954. enum mips_builtin_type builtin_type;
  11955. /* The function's prototype. */
  11956. enum mips_function_type function_type;
  11957. /* Whether the function is available. */
  11958. unsigned int (*avail) (void);
  11959. };
  11960. AVAIL_ALL (hard_float, TARGET_HARD_FLOAT_ABI)
  11961. AVAIL_NON_MIPS16 (paired_single, TARGET_PAIRED_SINGLE_FLOAT)
  11962. AVAIL_NON_MIPS16 (sb1_paired_single, TARGET_SB1 && TARGET_PAIRED_SINGLE_FLOAT)
  11963. AVAIL_NON_MIPS16 (mips3d, TARGET_MIPS3D)
  11964. AVAIL_NON_MIPS16 (dsp, TARGET_DSP)
  11965. AVAIL_NON_MIPS16 (dspr2, TARGET_DSPR2)
  11966. AVAIL_NON_MIPS16 (dsp_32, !TARGET_64BIT && TARGET_DSP)
  11967. AVAIL_NON_MIPS16 (dsp_64, TARGET_64BIT && TARGET_DSP)
  11968. AVAIL_NON_MIPS16 (dspr2_32, !TARGET_64BIT && TARGET_DSPR2)
  11969. AVAIL_NON_MIPS16 (loongson, TARGET_LOONGSON_VECTORS)
  11970. AVAIL_NON_MIPS16 (cache, TARGET_CACHE_BUILTIN)
  11971. /* Construct a mips_builtin_description from the given arguments.
  11972. INSN is the name of the associated instruction pattern, without the
  11973. leading CODE_FOR_mips_.
  11974. CODE is the floating-point condition code associated with the
  11975. function. It can be 'f' if the field is not applicable.
  11976. NAME is the name of the function itself, without the leading
  11977. "__builtin_mips_".
  11978. BUILTIN_TYPE and FUNCTION_TYPE are mips_builtin_description fields.
  11979. AVAIL is the name of the availability predicate, without the leading
  11980. mips_builtin_avail_. */
  11981. #define MIPS_BUILTIN(INSN, COND, NAME, BUILTIN_TYPE, \
  11982. FUNCTION_TYPE, AVAIL) \
  11983. { CODE_FOR_mips_ ## INSN, MIPS_FP_COND_ ## COND, \
  11984. "__builtin_mips_" NAME, BUILTIN_TYPE, FUNCTION_TYPE, \
  11985. mips_builtin_avail_ ## AVAIL }
  11986. /* Define __builtin_mips_<INSN>, which is a MIPS_BUILTIN_DIRECT function
  11987. mapped to instruction CODE_FOR_mips_<INSN>, FUNCTION_TYPE and AVAIL
  11988. are as for MIPS_BUILTIN. */
  11989. #define DIRECT_BUILTIN(INSN, FUNCTION_TYPE, AVAIL) \
  11990. MIPS_BUILTIN (INSN, f, #INSN, MIPS_BUILTIN_DIRECT, FUNCTION_TYPE, AVAIL)
  11991. /* Define __builtin_mips_<INSN>_<COND>_{s,d} functions, both of which
  11992. are subject to mips_builtin_avail_<AVAIL>. */
  11993. #define CMP_SCALAR_BUILTINS(INSN, COND, AVAIL) \
  11994. MIPS_BUILTIN (INSN ## _cond_s, COND, #INSN "_" #COND "_s", \
  11995. MIPS_BUILTIN_CMP_SINGLE, MIPS_INT_FTYPE_SF_SF, AVAIL), \
  11996. MIPS_BUILTIN (INSN ## _cond_d, COND, #INSN "_" #COND "_d", \
  11997. MIPS_BUILTIN_CMP_SINGLE, MIPS_INT_FTYPE_DF_DF, AVAIL)
  11998. /* Define __builtin_mips_{any,all,upper,lower}_<INSN>_<COND>_ps.
  11999. The lower and upper forms are subject to mips_builtin_avail_<AVAIL>
  12000. while the any and all forms are subject to mips_builtin_avail_mips3d. */
  12001. #define CMP_PS_BUILTINS(INSN, COND, AVAIL) \
  12002. MIPS_BUILTIN (INSN ## _cond_ps, COND, "any_" #INSN "_" #COND "_ps", \
  12003. MIPS_BUILTIN_CMP_ANY, MIPS_INT_FTYPE_V2SF_V2SF, \
  12004. mips3d), \
  12005. MIPS_BUILTIN (INSN ## _cond_ps, COND, "all_" #INSN "_" #COND "_ps", \
  12006. MIPS_BUILTIN_CMP_ALL, MIPS_INT_FTYPE_V2SF_V2SF, \
  12007. mips3d), \
  12008. MIPS_BUILTIN (INSN ## _cond_ps, COND, "lower_" #INSN "_" #COND "_ps", \
  12009. MIPS_BUILTIN_CMP_LOWER, MIPS_INT_FTYPE_V2SF_V2SF, \
  12010. AVAIL), \
  12011. MIPS_BUILTIN (INSN ## _cond_ps, COND, "upper_" #INSN "_" #COND "_ps", \
  12012. MIPS_BUILTIN_CMP_UPPER, MIPS_INT_FTYPE_V2SF_V2SF, \
  12013. AVAIL)
  12014. /* Define __builtin_mips_{any,all}_<INSN>_<COND>_4s. The functions
  12015. are subject to mips_builtin_avail_mips3d. */
  12016. #define CMP_4S_BUILTINS(INSN, COND) \
  12017. MIPS_BUILTIN (INSN ## _cond_4s, COND, "any_" #INSN "_" #COND "_4s", \
  12018. MIPS_BUILTIN_CMP_ANY, \
  12019. MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF, mips3d), \
  12020. MIPS_BUILTIN (INSN ## _cond_4s, COND, "all_" #INSN "_" #COND "_4s", \
  12021. MIPS_BUILTIN_CMP_ALL, \
  12022. MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF, mips3d)
  12023. /* Define __builtin_mips_mov{t,f}_<INSN>_<COND>_ps. The comparison
  12024. instruction requires mips_builtin_avail_<AVAIL>. */
  12025. #define MOVTF_BUILTINS(INSN, COND, AVAIL) \
  12026. MIPS_BUILTIN (INSN ## _cond_ps, COND, "movt_" #INSN "_" #COND "_ps", \
  12027. MIPS_BUILTIN_MOVT, MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF, \
  12028. AVAIL), \
  12029. MIPS_BUILTIN (INSN ## _cond_ps, COND, "movf_" #INSN "_" #COND "_ps", \
  12030. MIPS_BUILTIN_MOVF, MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF, \
  12031. AVAIL)
  12032. /* Define all the built-in functions related to C.cond.fmt condition COND. */
  12033. #define CMP_BUILTINS(COND) \
  12034. MOVTF_BUILTINS (c, COND, paired_single), \
  12035. MOVTF_BUILTINS (cabs, COND, mips3d), \
  12036. CMP_SCALAR_BUILTINS (cabs, COND, mips3d), \
  12037. CMP_PS_BUILTINS (c, COND, paired_single), \
  12038. CMP_PS_BUILTINS (cabs, COND, mips3d), \
  12039. CMP_4S_BUILTINS (c, COND), \
  12040. CMP_4S_BUILTINS (cabs, COND)
  12041. /* Define __builtin_mips_<INSN>, which is a MIPS_BUILTIN_DIRECT_NO_TARGET
  12042. function mapped to instruction CODE_FOR_mips_<INSN>, FUNCTION_TYPE
  12043. and AVAIL are as for MIPS_BUILTIN. */
  12044. #define DIRECT_NO_TARGET_BUILTIN(INSN, FUNCTION_TYPE, AVAIL) \
  12045. MIPS_BUILTIN (INSN, f, #INSN, MIPS_BUILTIN_DIRECT_NO_TARGET, \
  12046. FUNCTION_TYPE, AVAIL)
  12047. /* Define __builtin_mips_bposge<VALUE>. <VALUE> is 32 for the MIPS32 DSP
  12048. branch instruction. AVAIL is as for MIPS_BUILTIN. */
  12049. #define BPOSGE_BUILTIN(VALUE, AVAIL) \
  12050. MIPS_BUILTIN (bposge, f, "bposge" #VALUE, \
  12051. MIPS_BUILTIN_BPOSGE ## VALUE, MIPS_SI_FTYPE_VOID, AVAIL)
  12052. /* Define a Loongson MIPS_BUILTIN_DIRECT function __builtin_loongson_<FN_NAME>
  12053. for instruction CODE_FOR_loongson_<INSN>. FUNCTION_TYPE is a
  12054. builtin_description field. */
  12055. #define LOONGSON_BUILTIN_ALIAS(INSN, FN_NAME, FUNCTION_TYPE) \
  12056. { CODE_FOR_loongson_ ## INSN, MIPS_FP_COND_f, \
  12057. "__builtin_loongson_" #FN_NAME, MIPS_BUILTIN_DIRECT, \
  12058. FUNCTION_TYPE, mips_builtin_avail_loongson }
  12059. /* Define a Loongson MIPS_BUILTIN_DIRECT function __builtin_loongson_<INSN>
  12060. for instruction CODE_FOR_loongson_<INSN>. FUNCTION_TYPE is a
  12061. builtin_description field. */
  12062. #define LOONGSON_BUILTIN(INSN, FUNCTION_TYPE) \
  12063. LOONGSON_BUILTIN_ALIAS (INSN, INSN, FUNCTION_TYPE)
  12064. /* Like LOONGSON_BUILTIN, but add _<SUFFIX> to the end of the function name.
  12065. We use functions of this form when the same insn can be usefully applied
  12066. to more than one datatype. */
  12067. #define LOONGSON_BUILTIN_SUFFIX(INSN, SUFFIX, FUNCTION_TYPE) \
  12068. LOONGSON_BUILTIN_ALIAS (INSN, INSN ## _ ## SUFFIX, FUNCTION_TYPE)
  12069. #define CODE_FOR_mips_sqrt_ps CODE_FOR_sqrtv2sf2
  12070. #define CODE_FOR_mips_addq_ph CODE_FOR_addv2hi3
  12071. #define CODE_FOR_mips_addu_qb CODE_FOR_addv4qi3
  12072. #define CODE_FOR_mips_subq_ph CODE_FOR_subv2hi3
  12073. #define CODE_FOR_mips_subu_qb CODE_FOR_subv4qi3
  12074. #define CODE_FOR_mips_mul_ph CODE_FOR_mulv2hi3
  12075. #define CODE_FOR_mips_mult CODE_FOR_mulsidi3_32bit
  12076. #define CODE_FOR_mips_multu CODE_FOR_umulsidi3_32bit
  12077. #define CODE_FOR_loongson_packsswh CODE_FOR_vec_pack_ssat_v2si
  12078. #define CODE_FOR_loongson_packsshb CODE_FOR_vec_pack_ssat_v4hi
  12079. #define CODE_FOR_loongson_packushb CODE_FOR_vec_pack_usat_v4hi
  12080. #define CODE_FOR_loongson_paddw CODE_FOR_addv2si3
  12081. #define CODE_FOR_loongson_paddh CODE_FOR_addv4hi3
  12082. #define CODE_FOR_loongson_paddb CODE_FOR_addv8qi3
  12083. #define CODE_FOR_loongson_paddsh CODE_FOR_ssaddv4hi3
  12084. #define CODE_FOR_loongson_paddsb CODE_FOR_ssaddv8qi3
  12085. #define CODE_FOR_loongson_paddush CODE_FOR_usaddv4hi3
  12086. #define CODE_FOR_loongson_paddusb CODE_FOR_usaddv8qi3
  12087. #define CODE_FOR_loongson_pmaxsh CODE_FOR_smaxv4hi3
  12088. #define CODE_FOR_loongson_pmaxub CODE_FOR_umaxv8qi3
  12089. #define CODE_FOR_loongson_pminsh CODE_FOR_sminv4hi3
  12090. #define CODE_FOR_loongson_pminub CODE_FOR_uminv8qi3
  12091. #define CODE_FOR_loongson_pmulhuh CODE_FOR_umulv4hi3_highpart
  12092. #define CODE_FOR_loongson_pmulhh CODE_FOR_smulv4hi3_highpart
  12093. #define CODE_FOR_loongson_pmullh CODE_FOR_mulv4hi3
  12094. #define CODE_FOR_loongson_psllh CODE_FOR_ashlv4hi3
  12095. #define CODE_FOR_loongson_psllw CODE_FOR_ashlv2si3
  12096. #define CODE_FOR_loongson_psrlh CODE_FOR_lshrv4hi3
  12097. #define CODE_FOR_loongson_psrlw CODE_FOR_lshrv2si3
  12098. #define CODE_FOR_loongson_psrah CODE_FOR_ashrv4hi3
  12099. #define CODE_FOR_loongson_psraw CODE_FOR_ashrv2si3
  12100. #define CODE_FOR_loongson_psubw CODE_FOR_subv2si3
  12101. #define CODE_FOR_loongson_psubh CODE_FOR_subv4hi3
  12102. #define CODE_FOR_loongson_psubb CODE_FOR_subv8qi3
  12103. #define CODE_FOR_loongson_psubsh CODE_FOR_sssubv4hi3
  12104. #define CODE_FOR_loongson_psubsb CODE_FOR_sssubv8qi3
  12105. #define CODE_FOR_loongson_psubush CODE_FOR_ussubv4hi3
  12106. #define CODE_FOR_loongson_psubusb CODE_FOR_ussubv8qi3
  12107. static const struct mips_builtin_description mips_builtins[] = {
  12108. #define MIPS_GET_FCSR 0
  12109. DIRECT_BUILTIN (get_fcsr, MIPS_USI_FTYPE_VOID, hard_float),
  12110. #define MIPS_SET_FCSR 1
  12111. DIRECT_NO_TARGET_BUILTIN (set_fcsr, MIPS_VOID_FTYPE_USI, hard_float),
  12112. DIRECT_BUILTIN (pll_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
  12113. DIRECT_BUILTIN (pul_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
  12114. DIRECT_BUILTIN (plu_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
  12115. DIRECT_BUILTIN (puu_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
  12116. DIRECT_BUILTIN (cvt_ps_s, MIPS_V2SF_FTYPE_SF_SF, paired_single),
  12117. DIRECT_BUILTIN (cvt_s_pl, MIPS_SF_FTYPE_V2SF, paired_single),
  12118. DIRECT_BUILTIN (cvt_s_pu, MIPS_SF_FTYPE_V2SF, paired_single),
  12119. DIRECT_BUILTIN (abs_ps, MIPS_V2SF_FTYPE_V2SF, paired_single),
  12120. DIRECT_BUILTIN (alnv_ps, MIPS_V2SF_FTYPE_V2SF_V2SF_INT, paired_single),
  12121. DIRECT_BUILTIN (addr_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
  12122. DIRECT_BUILTIN (mulr_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
  12123. DIRECT_BUILTIN (cvt_pw_ps, MIPS_V2SF_FTYPE_V2SF, mips3d),
  12124. DIRECT_BUILTIN (cvt_ps_pw, MIPS_V2SF_FTYPE_V2SF, mips3d),
  12125. DIRECT_BUILTIN (recip1_s, MIPS_SF_FTYPE_SF, mips3d),
  12126. DIRECT_BUILTIN (recip1_d, MIPS_DF_FTYPE_DF, mips3d),
  12127. DIRECT_BUILTIN (recip1_ps, MIPS_V2SF_FTYPE_V2SF, mips3d),
  12128. DIRECT_BUILTIN (recip2_s, MIPS_SF_FTYPE_SF_SF, mips3d),
  12129. DIRECT_BUILTIN (recip2_d, MIPS_DF_FTYPE_DF_DF, mips3d),
  12130. DIRECT_BUILTIN (recip2_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
  12131. DIRECT_BUILTIN (rsqrt1_s, MIPS_SF_FTYPE_SF, mips3d),
  12132. DIRECT_BUILTIN (rsqrt1_d, MIPS_DF_FTYPE_DF, mips3d),
  12133. DIRECT_BUILTIN (rsqrt1_ps, MIPS_V2SF_FTYPE_V2SF, mips3d),
  12134. DIRECT_BUILTIN (rsqrt2_s, MIPS_SF_FTYPE_SF_SF, mips3d),
  12135. DIRECT_BUILTIN (rsqrt2_d, MIPS_DF_FTYPE_DF_DF, mips3d),
  12136. DIRECT_BUILTIN (rsqrt2_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
  12137. MIPS_FP_CONDITIONS (CMP_BUILTINS),
  12138. /* Built-in functions for the SB-1 processor. */
  12139. DIRECT_BUILTIN (sqrt_ps, MIPS_V2SF_FTYPE_V2SF, sb1_paired_single),
  12140. /* Built-in functions for the DSP ASE (32-bit and 64-bit). */
  12141. DIRECT_BUILTIN (addq_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
  12142. DIRECT_BUILTIN (addq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
  12143. DIRECT_BUILTIN (addq_s_w, MIPS_SI_FTYPE_SI_SI, dsp),
  12144. DIRECT_BUILTIN (addu_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
  12145. DIRECT_BUILTIN (addu_s_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
  12146. DIRECT_BUILTIN (subq_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
  12147. DIRECT_BUILTIN (subq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
  12148. DIRECT_BUILTIN (subq_s_w, MIPS_SI_FTYPE_SI_SI, dsp),
  12149. DIRECT_BUILTIN (subu_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
  12150. DIRECT_BUILTIN (subu_s_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
  12151. DIRECT_BUILTIN (addsc, MIPS_SI_FTYPE_SI_SI, dsp),
  12152. DIRECT_BUILTIN (addwc, MIPS_SI_FTYPE_SI_SI, dsp),
  12153. DIRECT_BUILTIN (modsub, MIPS_SI_FTYPE_SI_SI, dsp),
  12154. DIRECT_BUILTIN (raddu_w_qb, MIPS_SI_FTYPE_V4QI, dsp),
  12155. DIRECT_BUILTIN (absq_s_ph, MIPS_V2HI_FTYPE_V2HI, dsp),
  12156. DIRECT_BUILTIN (absq_s_w, MIPS_SI_FTYPE_SI, dsp),
  12157. DIRECT_BUILTIN (precrq_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dsp),
  12158. DIRECT_BUILTIN (precrq_ph_w, MIPS_V2HI_FTYPE_SI_SI, dsp),
  12159. DIRECT_BUILTIN (precrq_rs_ph_w, MIPS_V2HI_FTYPE_SI_SI, dsp),
  12160. DIRECT_BUILTIN (precrqu_s_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dsp),
  12161. DIRECT_BUILTIN (preceq_w_phl, MIPS_SI_FTYPE_V2HI, dsp),
  12162. DIRECT_BUILTIN (preceq_w_phr, MIPS_SI_FTYPE_V2HI, dsp),
  12163. DIRECT_BUILTIN (precequ_ph_qbl, MIPS_V2HI_FTYPE_V4QI, dsp),
  12164. DIRECT_BUILTIN (precequ_ph_qbr, MIPS_V2HI_FTYPE_V4QI, dsp),
  12165. DIRECT_BUILTIN (precequ_ph_qbla, MIPS_V2HI_FTYPE_V4QI, dsp),
  12166. DIRECT_BUILTIN (precequ_ph_qbra, MIPS_V2HI_FTYPE_V4QI, dsp),
  12167. DIRECT_BUILTIN (preceu_ph_qbl, MIPS_V2HI_FTYPE_V4QI, dsp),
  12168. DIRECT_BUILTIN (preceu_ph_qbr, MIPS_V2HI_FTYPE_V4QI, dsp),
  12169. DIRECT_BUILTIN (preceu_ph_qbla, MIPS_V2HI_FTYPE_V4QI, dsp),
  12170. DIRECT_BUILTIN (preceu_ph_qbra, MIPS_V2HI_FTYPE_V4QI, dsp),
  12171. DIRECT_BUILTIN (shll_qb, MIPS_V4QI_FTYPE_V4QI_SI, dsp),
  12172. DIRECT_BUILTIN (shll_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
  12173. DIRECT_BUILTIN (shll_s_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
  12174. DIRECT_BUILTIN (shll_s_w, MIPS_SI_FTYPE_SI_SI, dsp),
  12175. DIRECT_BUILTIN (shrl_qb, MIPS_V4QI_FTYPE_V4QI_SI, dsp),
  12176. DIRECT_BUILTIN (shra_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
  12177. DIRECT_BUILTIN (shra_r_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
  12178. DIRECT_BUILTIN (shra_r_w, MIPS_SI_FTYPE_SI_SI, dsp),
  12179. DIRECT_BUILTIN (muleu_s_ph_qbl, MIPS_V2HI_FTYPE_V4QI_V2HI, dsp),
  12180. DIRECT_BUILTIN (muleu_s_ph_qbr, MIPS_V2HI_FTYPE_V4QI_V2HI, dsp),
  12181. DIRECT_BUILTIN (mulq_rs_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
  12182. DIRECT_BUILTIN (muleq_s_w_phl, MIPS_SI_FTYPE_V2HI_V2HI, dsp),
  12183. DIRECT_BUILTIN (muleq_s_w_phr, MIPS_SI_FTYPE_V2HI_V2HI, dsp),
  12184. DIRECT_BUILTIN (bitrev, MIPS_SI_FTYPE_SI, dsp),
  12185. DIRECT_BUILTIN (insv, MIPS_SI_FTYPE_SI_SI, dsp),
  12186. DIRECT_BUILTIN (repl_qb, MIPS_V4QI_FTYPE_SI, dsp),
  12187. DIRECT_BUILTIN (repl_ph, MIPS_V2HI_FTYPE_SI, dsp),
  12188. DIRECT_NO_TARGET_BUILTIN (cmpu_eq_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp),
  12189. DIRECT_NO_TARGET_BUILTIN (cmpu_lt_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp),
  12190. DIRECT_NO_TARGET_BUILTIN (cmpu_le_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp),
  12191. DIRECT_BUILTIN (cmpgu_eq_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp),
  12192. DIRECT_BUILTIN (cmpgu_lt_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp),
  12193. DIRECT_BUILTIN (cmpgu_le_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp),
  12194. DIRECT_NO_TARGET_BUILTIN (cmp_eq_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp),
  12195. DIRECT_NO_TARGET_BUILTIN (cmp_lt_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp),
  12196. DIRECT_NO_TARGET_BUILTIN (cmp_le_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp),
  12197. DIRECT_BUILTIN (pick_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
  12198. DIRECT_BUILTIN (pick_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
  12199. DIRECT_BUILTIN (packrl_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
  12200. DIRECT_NO_TARGET_BUILTIN (wrdsp, MIPS_VOID_FTYPE_SI_SI, dsp),
  12201. DIRECT_BUILTIN (rddsp, MIPS_SI_FTYPE_SI, dsp),
  12202. DIRECT_BUILTIN (lbux, MIPS_SI_FTYPE_POINTER_SI, dsp),
  12203. DIRECT_BUILTIN (lhx, MIPS_SI_FTYPE_POINTER_SI, dsp),
  12204. DIRECT_BUILTIN (lwx, MIPS_SI_FTYPE_POINTER_SI, dsp),
  12205. BPOSGE_BUILTIN (32, dsp),
  12206. /* The following are for the MIPS DSP ASE REV 2 (32-bit and 64-bit). */
  12207. DIRECT_BUILTIN (absq_s_qb, MIPS_V4QI_FTYPE_V4QI, dspr2),
  12208. DIRECT_BUILTIN (addu_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12209. DIRECT_BUILTIN (addu_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12210. DIRECT_BUILTIN (adduh_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
  12211. DIRECT_BUILTIN (adduh_r_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
  12212. DIRECT_BUILTIN (append, MIPS_SI_FTYPE_SI_SI_SI, dspr2),
  12213. DIRECT_BUILTIN (balign, MIPS_SI_FTYPE_SI_SI_SI, dspr2),
  12214. DIRECT_BUILTIN (cmpgdu_eq_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2),
  12215. DIRECT_BUILTIN (cmpgdu_lt_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2),
  12216. DIRECT_BUILTIN (cmpgdu_le_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2),
  12217. DIRECT_BUILTIN (mul_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12218. DIRECT_BUILTIN (mul_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12219. DIRECT_BUILTIN (mulq_rs_w, MIPS_SI_FTYPE_SI_SI, dspr2),
  12220. DIRECT_BUILTIN (mulq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12221. DIRECT_BUILTIN (mulq_s_w, MIPS_SI_FTYPE_SI_SI, dspr2),
  12222. DIRECT_BUILTIN (precr_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dspr2),
  12223. DIRECT_BUILTIN (precr_sra_ph_w, MIPS_V2HI_FTYPE_SI_SI_SI, dspr2),
  12224. DIRECT_BUILTIN (precr_sra_r_ph_w, MIPS_V2HI_FTYPE_SI_SI_SI, dspr2),
  12225. DIRECT_BUILTIN (prepend, MIPS_SI_FTYPE_SI_SI_SI, dspr2),
  12226. DIRECT_BUILTIN (shra_qb, MIPS_V4QI_FTYPE_V4QI_SI, dspr2),
  12227. DIRECT_BUILTIN (shra_r_qb, MIPS_V4QI_FTYPE_V4QI_SI, dspr2),
  12228. DIRECT_BUILTIN (shrl_ph, MIPS_V2HI_FTYPE_V2HI_SI, dspr2),
  12229. DIRECT_BUILTIN (subu_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12230. DIRECT_BUILTIN (subu_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12231. DIRECT_BUILTIN (subuh_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
  12232. DIRECT_BUILTIN (subuh_r_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
  12233. DIRECT_BUILTIN (addqh_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12234. DIRECT_BUILTIN (addqh_r_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12235. DIRECT_BUILTIN (addqh_w, MIPS_SI_FTYPE_SI_SI, dspr2),
  12236. DIRECT_BUILTIN (addqh_r_w, MIPS_SI_FTYPE_SI_SI, dspr2),
  12237. DIRECT_BUILTIN (subqh_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12238. DIRECT_BUILTIN (subqh_r_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
  12239. DIRECT_BUILTIN (subqh_w, MIPS_SI_FTYPE_SI_SI, dspr2),
  12240. DIRECT_BUILTIN (subqh_r_w, MIPS_SI_FTYPE_SI_SI, dspr2),
  12241. /* Built-in functions for the DSP ASE (32-bit only). */
  12242. DIRECT_BUILTIN (dpau_h_qbl, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
  12243. DIRECT_BUILTIN (dpau_h_qbr, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
  12244. DIRECT_BUILTIN (dpsu_h_qbl, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
  12245. DIRECT_BUILTIN (dpsu_h_qbr, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
  12246. DIRECT_BUILTIN (dpaq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
  12247. DIRECT_BUILTIN (dpsq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
  12248. DIRECT_BUILTIN (mulsaq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
  12249. DIRECT_BUILTIN (dpaq_sa_l_w, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
  12250. DIRECT_BUILTIN (dpsq_sa_l_w, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
  12251. DIRECT_BUILTIN (maq_s_w_phl, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
  12252. DIRECT_BUILTIN (maq_s_w_phr, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
  12253. DIRECT_BUILTIN (maq_sa_w_phl, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
  12254. DIRECT_BUILTIN (maq_sa_w_phr, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
  12255. DIRECT_BUILTIN (extr_w, MIPS_SI_FTYPE_DI_SI, dsp_32),
  12256. DIRECT_BUILTIN (extr_r_w, MIPS_SI_FTYPE_DI_SI, dsp_32),
  12257. DIRECT_BUILTIN (extr_rs_w, MIPS_SI_FTYPE_DI_SI, dsp_32),
  12258. DIRECT_BUILTIN (extr_s_h, MIPS_SI_FTYPE_DI_SI, dsp_32),
  12259. DIRECT_BUILTIN (extp, MIPS_SI_FTYPE_DI_SI, dsp_32),
  12260. DIRECT_BUILTIN (extpdp, MIPS_SI_FTYPE_DI_SI, dsp_32),
  12261. DIRECT_BUILTIN (shilo, MIPS_DI_FTYPE_DI_SI, dsp_32),
  12262. DIRECT_BUILTIN (mthlip, MIPS_DI_FTYPE_DI_SI, dsp_32),
  12263. DIRECT_BUILTIN (madd, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
  12264. DIRECT_BUILTIN (maddu, MIPS_DI_FTYPE_DI_USI_USI, dsp_32),
  12265. DIRECT_BUILTIN (msub, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
  12266. DIRECT_BUILTIN (msubu, MIPS_DI_FTYPE_DI_USI_USI, dsp_32),
  12267. DIRECT_BUILTIN (mult, MIPS_DI_FTYPE_SI_SI, dsp_32),
  12268. DIRECT_BUILTIN (multu, MIPS_DI_FTYPE_USI_USI, dsp_32),
  12269. /* Built-in functions for the DSP ASE (64-bit only). */
  12270. DIRECT_BUILTIN (ldx, MIPS_DI_FTYPE_POINTER_SI, dsp_64),
  12271. /* The following are for the MIPS DSP ASE REV 2 (32-bit only). */
  12272. DIRECT_BUILTIN (dpa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12273. DIRECT_BUILTIN (dps_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12274. DIRECT_BUILTIN (mulsa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12275. DIRECT_BUILTIN (dpax_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12276. DIRECT_BUILTIN (dpsx_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12277. DIRECT_BUILTIN (dpaqx_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12278. DIRECT_BUILTIN (dpaqx_sa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12279. DIRECT_BUILTIN (dpsqx_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12280. DIRECT_BUILTIN (dpsqx_sa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
  12281. /* Builtin functions for ST Microelectronics Loongson-2E/2F cores. */
  12282. LOONGSON_BUILTIN (packsswh, MIPS_V4HI_FTYPE_V2SI_V2SI),
  12283. LOONGSON_BUILTIN (packsshb, MIPS_V8QI_FTYPE_V4HI_V4HI),
  12284. LOONGSON_BUILTIN (packushb, MIPS_UV8QI_FTYPE_UV4HI_UV4HI),
  12285. LOONGSON_BUILTIN_SUFFIX (paddw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
  12286. LOONGSON_BUILTIN_SUFFIX (paddh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12287. LOONGSON_BUILTIN_SUFFIX (paddb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12288. LOONGSON_BUILTIN_SUFFIX (paddw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
  12289. LOONGSON_BUILTIN_SUFFIX (paddh, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12290. LOONGSON_BUILTIN_SUFFIX (paddb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12291. LOONGSON_BUILTIN_SUFFIX (paddd, u, MIPS_UDI_FTYPE_UDI_UDI),
  12292. LOONGSON_BUILTIN_SUFFIX (paddd, s, MIPS_DI_FTYPE_DI_DI),
  12293. LOONGSON_BUILTIN (paddsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12294. LOONGSON_BUILTIN (paddsb, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12295. LOONGSON_BUILTIN (paddush, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12296. LOONGSON_BUILTIN (paddusb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12297. LOONGSON_BUILTIN_ALIAS (pandn_d, pandn_ud, MIPS_UDI_FTYPE_UDI_UDI),
  12298. LOONGSON_BUILTIN_ALIAS (pandn_w, pandn_uw, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
  12299. LOONGSON_BUILTIN_ALIAS (pandn_h, pandn_uh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12300. LOONGSON_BUILTIN_ALIAS (pandn_b, pandn_ub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12301. LOONGSON_BUILTIN_ALIAS (pandn_d, pandn_sd, MIPS_DI_FTYPE_DI_DI),
  12302. LOONGSON_BUILTIN_ALIAS (pandn_w, pandn_sw, MIPS_V2SI_FTYPE_V2SI_V2SI),
  12303. LOONGSON_BUILTIN_ALIAS (pandn_h, pandn_sh, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12304. LOONGSON_BUILTIN_ALIAS (pandn_b, pandn_sb, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12305. LOONGSON_BUILTIN (pavgh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12306. LOONGSON_BUILTIN (pavgb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12307. LOONGSON_BUILTIN_SUFFIX (pcmpeqw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
  12308. LOONGSON_BUILTIN_SUFFIX (pcmpeqh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12309. LOONGSON_BUILTIN_SUFFIX (pcmpeqb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12310. LOONGSON_BUILTIN_SUFFIX (pcmpeqw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
  12311. LOONGSON_BUILTIN_SUFFIX (pcmpeqh, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12312. LOONGSON_BUILTIN_SUFFIX (pcmpeqb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12313. LOONGSON_BUILTIN_SUFFIX (pcmpgtw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
  12314. LOONGSON_BUILTIN_SUFFIX (pcmpgth, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12315. LOONGSON_BUILTIN_SUFFIX (pcmpgtb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12316. LOONGSON_BUILTIN_SUFFIX (pcmpgtw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
  12317. LOONGSON_BUILTIN_SUFFIX (pcmpgth, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12318. LOONGSON_BUILTIN_SUFFIX (pcmpgtb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12319. LOONGSON_BUILTIN_SUFFIX (pextrh, u, MIPS_UV4HI_FTYPE_UV4HI_USI),
  12320. LOONGSON_BUILTIN_SUFFIX (pextrh, s, MIPS_V4HI_FTYPE_V4HI_USI),
  12321. LOONGSON_BUILTIN_SUFFIX (pinsrh_0, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12322. LOONGSON_BUILTIN_SUFFIX (pinsrh_1, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12323. LOONGSON_BUILTIN_SUFFIX (pinsrh_2, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12324. LOONGSON_BUILTIN_SUFFIX (pinsrh_3, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12325. LOONGSON_BUILTIN_SUFFIX (pinsrh_0, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12326. LOONGSON_BUILTIN_SUFFIX (pinsrh_1, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12327. LOONGSON_BUILTIN_SUFFIX (pinsrh_2, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12328. LOONGSON_BUILTIN_SUFFIX (pinsrh_3, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12329. LOONGSON_BUILTIN (pmaddhw, MIPS_V2SI_FTYPE_V4HI_V4HI),
  12330. LOONGSON_BUILTIN (pmaxsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12331. LOONGSON_BUILTIN (pmaxub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12332. LOONGSON_BUILTIN (pminsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12333. LOONGSON_BUILTIN (pminub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12334. LOONGSON_BUILTIN_SUFFIX (pmovmskb, u, MIPS_UV8QI_FTYPE_UV8QI),
  12335. LOONGSON_BUILTIN_SUFFIX (pmovmskb, s, MIPS_V8QI_FTYPE_V8QI),
  12336. LOONGSON_BUILTIN (pmulhuh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12337. LOONGSON_BUILTIN (pmulhh, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12338. LOONGSON_BUILTIN (pmullh, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12339. LOONGSON_BUILTIN (pmuluw, MIPS_UDI_FTYPE_UV2SI_UV2SI),
  12340. LOONGSON_BUILTIN (pasubub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12341. LOONGSON_BUILTIN (biadd, MIPS_UV4HI_FTYPE_UV8QI),
  12342. LOONGSON_BUILTIN (psadbh, MIPS_UV4HI_FTYPE_UV8QI_UV8QI),
  12343. LOONGSON_BUILTIN_SUFFIX (pshufh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
  12344. LOONGSON_BUILTIN_SUFFIX (pshufh, s, MIPS_V4HI_FTYPE_V4HI_UQI),
  12345. LOONGSON_BUILTIN_SUFFIX (psllh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
  12346. LOONGSON_BUILTIN_SUFFIX (psllh, s, MIPS_V4HI_FTYPE_V4HI_UQI),
  12347. LOONGSON_BUILTIN_SUFFIX (psllw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI),
  12348. LOONGSON_BUILTIN_SUFFIX (psllw, s, MIPS_V2SI_FTYPE_V2SI_UQI),
  12349. LOONGSON_BUILTIN_SUFFIX (psrah, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
  12350. LOONGSON_BUILTIN_SUFFIX (psrah, s, MIPS_V4HI_FTYPE_V4HI_UQI),
  12351. LOONGSON_BUILTIN_SUFFIX (psraw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI),
  12352. LOONGSON_BUILTIN_SUFFIX (psraw, s, MIPS_V2SI_FTYPE_V2SI_UQI),
  12353. LOONGSON_BUILTIN_SUFFIX (psrlh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
  12354. LOONGSON_BUILTIN_SUFFIX (psrlh, s, MIPS_V4HI_FTYPE_V4HI_UQI),
  12355. LOONGSON_BUILTIN_SUFFIX (psrlw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI),
  12356. LOONGSON_BUILTIN_SUFFIX (psrlw, s, MIPS_V2SI_FTYPE_V2SI_UQI),
  12357. LOONGSON_BUILTIN_SUFFIX (psubw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
  12358. LOONGSON_BUILTIN_SUFFIX (psubh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12359. LOONGSON_BUILTIN_SUFFIX (psubb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12360. LOONGSON_BUILTIN_SUFFIX (psubw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
  12361. LOONGSON_BUILTIN_SUFFIX (psubh, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12362. LOONGSON_BUILTIN_SUFFIX (psubb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12363. LOONGSON_BUILTIN_SUFFIX (psubd, u, MIPS_UDI_FTYPE_UDI_UDI),
  12364. LOONGSON_BUILTIN_SUFFIX (psubd, s, MIPS_DI_FTYPE_DI_DI),
  12365. LOONGSON_BUILTIN (psubsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12366. LOONGSON_BUILTIN (psubsb, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12367. LOONGSON_BUILTIN (psubush, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12368. LOONGSON_BUILTIN (psubusb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12369. LOONGSON_BUILTIN_SUFFIX (punpckhbh, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12370. LOONGSON_BUILTIN_SUFFIX (punpckhhw, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12371. LOONGSON_BUILTIN_SUFFIX (punpckhwd, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
  12372. LOONGSON_BUILTIN_SUFFIX (punpckhbh, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12373. LOONGSON_BUILTIN_SUFFIX (punpckhhw, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12374. LOONGSON_BUILTIN_SUFFIX (punpckhwd, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
  12375. LOONGSON_BUILTIN_SUFFIX (punpcklbh, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
  12376. LOONGSON_BUILTIN_SUFFIX (punpcklhw, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
  12377. LOONGSON_BUILTIN_SUFFIX (punpcklwd, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
  12378. LOONGSON_BUILTIN_SUFFIX (punpcklbh, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
  12379. LOONGSON_BUILTIN_SUFFIX (punpcklhw, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
  12380. LOONGSON_BUILTIN_SUFFIX (punpcklwd, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
  12381. /* Sundry other built-in functions. */
  12382. DIRECT_NO_TARGET_BUILTIN (cache, MIPS_VOID_FTYPE_SI_CVPOINTER, cache)
  12383. };
  12384. /* Index I is the function declaration for mips_builtins[I], or null if the
  12385. function isn't defined on this target. */
  12386. static GTY(()) tree mips_builtin_decls[ARRAY_SIZE (mips_builtins)];
  12387. /* MODE is a vector mode whose elements have type TYPE. Return the type
  12388. of the vector itself. */
  12389. static tree
  12390. mips_builtin_vector_type (tree type, machine_mode mode)
  12391. {
  12392. static tree types[2 * (int) MAX_MACHINE_MODE];
  12393. int mode_index;
  12394. mode_index = (int) mode;
  12395. if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type))
  12396. mode_index += MAX_MACHINE_MODE;
  12397. if (types[mode_index] == NULL_TREE)
  12398. types[mode_index] = build_vector_type_for_mode (type, mode);
  12399. return types[mode_index];
  12400. }
  12401. /* Return a type for 'const volatile void *'. */
  12402. static tree
  12403. mips_build_cvpointer_type (void)
  12404. {
  12405. static tree cache;
  12406. if (cache == NULL_TREE)
  12407. cache = build_pointer_type (build_qualified_type
  12408. (void_type_node,
  12409. TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE));
  12410. return cache;
  12411. }
  12412. /* Source-level argument types. */
  12413. #define MIPS_ATYPE_VOID void_type_node
  12414. #define MIPS_ATYPE_INT integer_type_node
  12415. #define MIPS_ATYPE_POINTER ptr_type_node
  12416. #define MIPS_ATYPE_CVPOINTER mips_build_cvpointer_type ()
  12417. /* Standard mode-based argument types. */
  12418. #define MIPS_ATYPE_UQI unsigned_intQI_type_node
  12419. #define MIPS_ATYPE_SI intSI_type_node
  12420. #define MIPS_ATYPE_USI unsigned_intSI_type_node
  12421. #define MIPS_ATYPE_DI intDI_type_node
  12422. #define MIPS_ATYPE_UDI unsigned_intDI_type_node
  12423. #define MIPS_ATYPE_SF float_type_node
  12424. #define MIPS_ATYPE_DF double_type_node
  12425. /* Vector argument types. */
  12426. #define MIPS_ATYPE_V2SF mips_builtin_vector_type (float_type_node, V2SFmode)
  12427. #define MIPS_ATYPE_V2HI mips_builtin_vector_type (intHI_type_node, V2HImode)
  12428. #define MIPS_ATYPE_V2SI mips_builtin_vector_type (intSI_type_node, V2SImode)
  12429. #define MIPS_ATYPE_V4QI mips_builtin_vector_type (intQI_type_node, V4QImode)
  12430. #define MIPS_ATYPE_V4HI mips_builtin_vector_type (intHI_type_node, V4HImode)
  12431. #define MIPS_ATYPE_V8QI mips_builtin_vector_type (intQI_type_node, V8QImode)
  12432. #define MIPS_ATYPE_UV2SI \
  12433. mips_builtin_vector_type (unsigned_intSI_type_node, V2SImode)
  12434. #define MIPS_ATYPE_UV4HI \
  12435. mips_builtin_vector_type (unsigned_intHI_type_node, V4HImode)
  12436. #define MIPS_ATYPE_UV8QI \
  12437. mips_builtin_vector_type (unsigned_intQI_type_node, V8QImode)
  12438. /* MIPS_FTYPE_ATYPESN takes N MIPS_FTYPES-like type codes and lists
  12439. their associated MIPS_ATYPEs. */
  12440. #define MIPS_FTYPE_ATYPES1(A, B) \
  12441. MIPS_ATYPE_##A, MIPS_ATYPE_##B
  12442. #define MIPS_FTYPE_ATYPES2(A, B, C) \
  12443. MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C
  12444. #define MIPS_FTYPE_ATYPES3(A, B, C, D) \
  12445. MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C, MIPS_ATYPE_##D
  12446. #define MIPS_FTYPE_ATYPES4(A, B, C, D, E) \
  12447. MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C, MIPS_ATYPE_##D, \
  12448. MIPS_ATYPE_##E
  12449. /* Return the function type associated with function prototype TYPE. */
  12450. static tree
  12451. mips_build_function_type (enum mips_function_type type)
  12452. {
  12453. static tree types[(int) MIPS_MAX_FTYPE_MAX];
  12454. if (types[(int) type] == NULL_TREE)
  12455. switch (type)
  12456. {
  12457. #define DEF_MIPS_FTYPE(NUM, ARGS) \
  12458. case MIPS_FTYPE_NAME##NUM ARGS: \
  12459. types[(int) type] \
  12460. = build_function_type_list (MIPS_FTYPE_ATYPES##NUM ARGS, \
  12461. NULL_TREE); \
  12462. break;
  12463. #include "config/mips/mips-ftypes.def"
  12464. #undef DEF_MIPS_FTYPE
  12465. default:
  12466. gcc_unreachable ();
  12467. }
  12468. return types[(int) type];
  12469. }
  12470. /* Implement TARGET_INIT_BUILTINS. */
  12471. static void
  12472. mips_init_builtins (void)
  12473. {
  12474. const struct mips_builtin_description *d;
  12475. unsigned int i;
  12476. /* Iterate through all of the bdesc arrays, initializing all of the
  12477. builtin functions. */
  12478. for (i = 0; i < ARRAY_SIZE (mips_builtins); i++)
  12479. {
  12480. d = &mips_builtins[i];
  12481. if (d->avail ())
  12482. mips_builtin_decls[i]
  12483. = add_builtin_function (d->name,
  12484. mips_build_function_type (d->function_type),
  12485. i, BUILT_IN_MD, NULL, NULL);
  12486. }
  12487. }
  12488. /* Implement TARGET_BUILTIN_DECL. */
  12489. static tree
  12490. mips_builtin_decl (unsigned int code, bool initialize_p ATTRIBUTE_UNUSED)
  12491. {
  12492. if (code >= ARRAY_SIZE (mips_builtins))
  12493. return error_mark_node;
  12494. return mips_builtin_decls[code];
  12495. }
  12496. /* Take argument ARGNO from EXP's argument list and convert it into
  12497. an expand operand. Store the operand in *OP. */
  12498. static void
  12499. mips_prepare_builtin_arg (struct expand_operand *op, tree exp,
  12500. unsigned int argno)
  12501. {
  12502. tree arg;
  12503. rtx value;
  12504. arg = CALL_EXPR_ARG (exp, argno);
  12505. value = expand_normal (arg);
  12506. create_input_operand (op, value, TYPE_MODE (TREE_TYPE (arg)));
  12507. }
  12508. /* Expand instruction ICODE as part of a built-in function sequence.
  12509. Use the first NOPS elements of OPS as the instruction's operands.
  12510. HAS_TARGET_P is true if operand 0 is a target; it is false if the
  12511. instruction has no target.
  12512. Return the target rtx if HAS_TARGET_P, otherwise return const0_rtx. */
  12513. static rtx
  12514. mips_expand_builtin_insn (enum insn_code icode, unsigned int nops,
  12515. struct expand_operand *ops, bool has_target_p)
  12516. {
  12517. if (!maybe_expand_insn (icode, nops, ops))
  12518. {
  12519. error ("invalid argument to built-in function");
  12520. return has_target_p ? gen_reg_rtx (ops[0].mode) : const0_rtx;
  12521. }
  12522. return has_target_p ? ops[0].value : const0_rtx;
  12523. }
  12524. /* Expand a floating-point comparison for built-in function call EXP.
  12525. The first NARGS arguments are the values to be compared. ICODE is
  12526. the .md pattern that does the comparison and COND is the condition
  12527. that is being tested. Return an rtx for the result. */
  12528. static rtx
  12529. mips_expand_builtin_compare_1 (enum insn_code icode,
  12530. enum mips_fp_condition cond,
  12531. tree exp, int nargs)
  12532. {
  12533. struct expand_operand ops[MAX_RECOG_OPERANDS];
  12534. rtx output;
  12535. int opno, argno;
  12536. /* The instruction should have a target operand, an operand for each
  12537. argument, and an operand for COND. */
  12538. gcc_assert (nargs + 2 == insn_data[(int) icode].n_generator_args);
  12539. output = mips_allocate_fcc (insn_data[(int) icode].operand[0].mode);
  12540. opno = 0;
  12541. create_fixed_operand (&ops[opno++], output);
  12542. for (argno = 0; argno < nargs; argno++)
  12543. mips_prepare_builtin_arg (&ops[opno++], exp, argno);
  12544. create_integer_operand (&ops[opno++], (int) cond);
  12545. return mips_expand_builtin_insn (icode, opno, ops, true);
  12546. }
  12547. /* Expand a MIPS_BUILTIN_DIRECT or MIPS_BUILTIN_DIRECT_NO_TARGET function;
  12548. HAS_TARGET_P says which. EXP is the CALL_EXPR that calls the function
  12549. and ICODE is the code of the associated .md pattern. TARGET, if nonnull,
  12550. suggests a good place to put the result. */
  12551. static rtx
  12552. mips_expand_builtin_direct (enum insn_code icode, rtx target, tree exp,
  12553. bool has_target_p)
  12554. {
  12555. struct expand_operand ops[MAX_RECOG_OPERANDS];
  12556. int opno, argno;
  12557. /* Map any target to operand 0. */
  12558. opno = 0;
  12559. if (has_target_p)
  12560. create_output_operand (&ops[opno++], target, TYPE_MODE (TREE_TYPE (exp)));
  12561. /* Map the arguments to the other operands. */
  12562. gcc_assert (opno + call_expr_nargs (exp)
  12563. == insn_data[icode].n_generator_args);
  12564. for (argno = 0; argno < call_expr_nargs (exp); argno++)
  12565. mips_prepare_builtin_arg (&ops[opno++], exp, argno);
  12566. return mips_expand_builtin_insn (icode, opno, ops, has_target_p);
  12567. }
  12568. /* Expand a __builtin_mips_movt_*_ps or __builtin_mips_movf_*_ps
  12569. function; TYPE says which. EXP is the CALL_EXPR that calls the
  12570. function, ICODE is the instruction that should be used to compare
  12571. the first two arguments, and COND is the condition it should test.
  12572. TARGET, if nonnull, suggests a good place to put the result. */
  12573. static rtx
  12574. mips_expand_builtin_movtf (enum mips_builtin_type type,
  12575. enum insn_code icode, enum mips_fp_condition cond,
  12576. rtx target, tree exp)
  12577. {
  12578. struct expand_operand ops[4];
  12579. rtx cmp_result;
  12580. cmp_result = mips_expand_builtin_compare_1 (icode, cond, exp, 2);
  12581. create_output_operand (&ops[0], target, TYPE_MODE (TREE_TYPE (exp)));
  12582. if (type == MIPS_BUILTIN_MOVT)
  12583. {
  12584. mips_prepare_builtin_arg (&ops[2], exp, 2);
  12585. mips_prepare_builtin_arg (&ops[1], exp, 3);
  12586. }
  12587. else
  12588. {
  12589. mips_prepare_builtin_arg (&ops[1], exp, 2);
  12590. mips_prepare_builtin_arg (&ops[2], exp, 3);
  12591. }
  12592. create_fixed_operand (&ops[3], cmp_result);
  12593. return mips_expand_builtin_insn (CODE_FOR_mips_cond_move_tf_ps,
  12594. 4, ops, true);
  12595. }
  12596. /* Move VALUE_IF_TRUE into TARGET if CONDITION is true; move VALUE_IF_FALSE
  12597. into TARGET otherwise. Return TARGET. */
  12598. static rtx
  12599. mips_builtin_branch_and_move (rtx condition, rtx target,
  12600. rtx value_if_true, rtx value_if_false)
  12601. {
  12602. rtx_code_label *true_label, *done_label;
  12603. true_label = gen_label_rtx ();
  12604. done_label = gen_label_rtx ();
  12605. /* First assume that CONDITION is false. */
  12606. mips_emit_move (target, value_if_false);
  12607. /* Branch to TRUE_LABEL if CONDITION is true and DONE_LABEL otherwise. */
  12608. emit_jump_insn (gen_condjump (condition, true_label));
  12609. emit_jump_insn (gen_jump (done_label));
  12610. emit_barrier ();
  12611. /* Fix TARGET if CONDITION is true. */
  12612. emit_label (true_label);
  12613. mips_emit_move (target, value_if_true);
  12614. emit_label (done_label);
  12615. return target;
  12616. }
  12617. /* Expand a comparison built-in function of type BUILTIN_TYPE. EXP is
  12618. the CALL_EXPR that calls the function, ICODE is the code of the
  12619. comparison instruction, and COND is the condition it should test.
  12620. TARGET, if nonnull, suggests a good place to put the boolean result. */
  12621. static rtx
  12622. mips_expand_builtin_compare (enum mips_builtin_type builtin_type,
  12623. enum insn_code icode, enum mips_fp_condition cond,
  12624. rtx target, tree exp)
  12625. {
  12626. rtx offset, condition, cmp_result;
  12627. if (target == 0 || GET_MODE (target) != SImode)
  12628. target = gen_reg_rtx (SImode);
  12629. cmp_result = mips_expand_builtin_compare_1 (icode, cond, exp,
  12630. call_expr_nargs (exp));
  12631. /* If the comparison sets more than one register, we define the result
  12632. to be 0 if all registers are false and -1 if all registers are true.
  12633. The value of the complete result is indeterminate otherwise. */
  12634. switch (builtin_type)
  12635. {
  12636. case MIPS_BUILTIN_CMP_ALL:
  12637. condition = gen_rtx_NE (VOIDmode, cmp_result, constm1_rtx);
  12638. return mips_builtin_branch_and_move (condition, target,
  12639. const0_rtx, const1_rtx);
  12640. case MIPS_BUILTIN_CMP_UPPER:
  12641. case MIPS_BUILTIN_CMP_LOWER:
  12642. offset = GEN_INT (builtin_type == MIPS_BUILTIN_CMP_UPPER);
  12643. condition = gen_single_cc (cmp_result, offset);
  12644. return mips_builtin_branch_and_move (condition, target,
  12645. const1_rtx, const0_rtx);
  12646. default:
  12647. condition = gen_rtx_NE (VOIDmode, cmp_result, const0_rtx);
  12648. return mips_builtin_branch_and_move (condition, target,
  12649. const1_rtx, const0_rtx);
  12650. }
  12651. }
  12652. /* Expand a bposge built-in function of type BUILTIN_TYPE. TARGET,
  12653. if nonnull, suggests a good place to put the boolean result. */
  12654. static rtx
  12655. mips_expand_builtin_bposge (enum mips_builtin_type builtin_type, rtx target)
  12656. {
  12657. rtx condition, cmp_result;
  12658. int cmp_value;
  12659. if (target == 0 || GET_MODE (target) != SImode)
  12660. target = gen_reg_rtx (SImode);
  12661. cmp_result = gen_rtx_REG (CCDSPmode, CCDSP_PO_REGNUM);
  12662. if (builtin_type == MIPS_BUILTIN_BPOSGE32)
  12663. cmp_value = 32;
  12664. else
  12665. gcc_assert (0);
  12666. condition = gen_rtx_GE (VOIDmode, cmp_result, GEN_INT (cmp_value));
  12667. return mips_builtin_branch_and_move (condition, target,
  12668. const1_rtx, const0_rtx);
  12669. }
  12670. /* Implement TARGET_EXPAND_BUILTIN. */
  12671. static rtx
  12672. mips_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
  12673. machine_mode mode, int ignore)
  12674. {
  12675. tree fndecl;
  12676. unsigned int fcode, avail;
  12677. const struct mips_builtin_description *d;
  12678. fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
  12679. fcode = DECL_FUNCTION_CODE (fndecl);
  12680. gcc_assert (fcode < ARRAY_SIZE (mips_builtins));
  12681. d = &mips_builtins[fcode];
  12682. avail = d->avail ();
  12683. gcc_assert (avail != 0);
  12684. if (TARGET_MIPS16 && !(avail & BUILTIN_AVAIL_MIPS16))
  12685. {
  12686. error ("built-in function %qE not supported for MIPS16",
  12687. DECL_NAME (fndecl));
  12688. return ignore ? const0_rtx : CONST0_RTX (mode);
  12689. }
  12690. switch (d->builtin_type)
  12691. {
  12692. case MIPS_BUILTIN_DIRECT:
  12693. return mips_expand_builtin_direct (d->icode, target, exp, true);
  12694. case MIPS_BUILTIN_DIRECT_NO_TARGET:
  12695. return mips_expand_builtin_direct (d->icode, target, exp, false);
  12696. case MIPS_BUILTIN_MOVT:
  12697. case MIPS_BUILTIN_MOVF:
  12698. return mips_expand_builtin_movtf (d->builtin_type, d->icode,
  12699. d->cond, target, exp);
  12700. case MIPS_BUILTIN_CMP_ANY:
  12701. case MIPS_BUILTIN_CMP_ALL:
  12702. case MIPS_BUILTIN_CMP_UPPER:
  12703. case MIPS_BUILTIN_CMP_LOWER:
  12704. case MIPS_BUILTIN_CMP_SINGLE:
  12705. return mips_expand_builtin_compare (d->builtin_type, d->icode,
  12706. d->cond, target, exp);
  12707. case MIPS_BUILTIN_BPOSGE32:
  12708. return mips_expand_builtin_bposge (d->builtin_type, target);
  12709. }
  12710. gcc_unreachable ();
  12711. }
  12712. /* An entry in the MIPS16 constant pool. VALUE is the pool constant,
  12713. MODE is its mode, and LABEL is the CODE_LABEL associated with it. */
  12714. struct mips16_constant {
  12715. struct mips16_constant *next;
  12716. rtx value;
  12717. rtx_code_label *label;
  12718. machine_mode mode;
  12719. };
  12720. /* Information about an incomplete MIPS16 constant pool. FIRST is the
  12721. first constant, HIGHEST_ADDRESS is the highest address that the first
  12722. byte of the pool can have, and INSN_ADDRESS is the current instruction
  12723. address. */
  12724. struct mips16_constant_pool {
  12725. struct mips16_constant *first;
  12726. int highest_address;
  12727. int insn_address;
  12728. };
  12729. /* Add constant VALUE to POOL and return its label. MODE is the
  12730. value's mode (used for CONST_INTs, etc.). */
  12731. static rtx_code_label *
  12732. mips16_add_constant (struct mips16_constant_pool *pool,
  12733. rtx value, machine_mode mode)
  12734. {
  12735. struct mips16_constant **p, *c;
  12736. bool first_of_size_p;
  12737. /* See whether the constant is already in the pool. If so, return the
  12738. existing label, otherwise leave P pointing to the place where the
  12739. constant should be added.
  12740. Keep the pool sorted in increasing order of mode size so that we can
  12741. reduce the number of alignments needed. */
  12742. first_of_size_p = true;
  12743. for (p = &pool->first; *p != 0; p = &(*p)->next)
  12744. {
  12745. if (mode == (*p)->mode && rtx_equal_p (value, (*p)->value))
  12746. return (*p)->label;
  12747. if (GET_MODE_SIZE (mode) < GET_MODE_SIZE ((*p)->mode))
  12748. break;
  12749. if (GET_MODE_SIZE (mode) == GET_MODE_SIZE ((*p)->mode))
  12750. first_of_size_p = false;
  12751. }
  12752. /* In the worst case, the constant needed by the earliest instruction
  12753. will end up at the end of the pool. The entire pool must then be
  12754. accessible from that instruction.
  12755. When adding the first constant, set the pool's highest address to
  12756. the address of the first out-of-range byte. Adjust this address
  12757. downwards each time a new constant is added. */
  12758. if (pool->first == 0)
  12759. /* For LWPC, ADDIUPC and DADDIUPC, the base PC value is the address
  12760. of the instruction with the lowest two bits clear. The base PC
  12761. value for LDPC has the lowest three bits clear. Assume the worst
  12762. case here; namely that the PC-relative instruction occupies the
  12763. last 2 bytes in an aligned word. */
  12764. pool->highest_address = pool->insn_address - (UNITS_PER_WORD - 2) + 0x8000;
  12765. pool->highest_address -= GET_MODE_SIZE (mode);
  12766. if (first_of_size_p)
  12767. /* Take into account the worst possible padding due to alignment. */
  12768. pool->highest_address -= GET_MODE_SIZE (mode) - 1;
  12769. /* Create a new entry. */
  12770. c = XNEW (struct mips16_constant);
  12771. c->value = value;
  12772. c->mode = mode;
  12773. c->label = gen_label_rtx ();
  12774. c->next = *p;
  12775. *p = c;
  12776. return c->label;
  12777. }
  12778. /* Output constant VALUE after instruction INSN and return the last
  12779. instruction emitted. MODE is the mode of the constant. */
  12780. static rtx_insn *
  12781. mips16_emit_constants_1 (machine_mode mode, rtx value, rtx_insn *insn)
  12782. {
  12783. if (SCALAR_INT_MODE_P (mode) || ALL_SCALAR_FIXED_POINT_MODE_P (mode))
  12784. {
  12785. rtx size = GEN_INT (GET_MODE_SIZE (mode));
  12786. return emit_insn_after (gen_consttable_int (value, size), insn);
  12787. }
  12788. if (SCALAR_FLOAT_MODE_P (mode))
  12789. return emit_insn_after (gen_consttable_float (value), insn);
  12790. if (VECTOR_MODE_P (mode))
  12791. {
  12792. int i;
  12793. for (i = 0; i < CONST_VECTOR_NUNITS (value); i++)
  12794. insn = mips16_emit_constants_1 (GET_MODE_INNER (mode),
  12795. CONST_VECTOR_ELT (value, i), insn);
  12796. return insn;
  12797. }
  12798. gcc_unreachable ();
  12799. }
  12800. /* Dump out the constants in CONSTANTS after INSN. */
  12801. static void
  12802. mips16_emit_constants (struct mips16_constant *constants, rtx_insn *insn)
  12803. {
  12804. struct mips16_constant *c, *next;
  12805. int align;
  12806. align = 0;
  12807. for (c = constants; c != NULL; c = next)
  12808. {
  12809. /* If necessary, increase the alignment of PC. */
  12810. if (align < GET_MODE_SIZE (c->mode))
  12811. {
  12812. int align_log = floor_log2 (GET_MODE_SIZE (c->mode));
  12813. insn = emit_insn_after (gen_align (GEN_INT (align_log)), insn);
  12814. }
  12815. align = GET_MODE_SIZE (c->mode);
  12816. insn = emit_label_after (c->label, insn);
  12817. insn = mips16_emit_constants_1 (c->mode, c->value, insn);
  12818. next = c->next;
  12819. free (c);
  12820. }
  12821. emit_barrier_after (insn);
  12822. }
  12823. /* Return the length of instruction INSN. */
  12824. static int
  12825. mips16_insn_length (rtx_insn *insn)
  12826. {
  12827. if (JUMP_TABLE_DATA_P (insn))
  12828. {
  12829. rtx body = PATTERN (insn);
  12830. if (GET_CODE (body) == ADDR_VEC)
  12831. return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, 0);
  12832. else if (GET_CODE (body) == ADDR_DIFF_VEC)
  12833. return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, 1);
  12834. else
  12835. gcc_unreachable ();
  12836. }
  12837. return get_attr_length (insn);
  12838. }
  12839. /* If *X is a symbolic constant that refers to the constant pool, add
  12840. the constant to POOL and rewrite *X to use the constant's label. */
  12841. static void
  12842. mips16_rewrite_pool_constant (struct mips16_constant_pool *pool, rtx *x)
  12843. {
  12844. rtx base, offset;
  12845. rtx_code_label *label;
  12846. split_const (*x, &base, &offset);
  12847. if (GET_CODE (base) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (base))
  12848. {
  12849. label = mips16_add_constant (pool, copy_rtx (get_pool_constant (base)),
  12850. get_pool_mode (base));
  12851. base = gen_rtx_LABEL_REF (Pmode, label);
  12852. *x = mips_unspec_address_offset (base, offset, SYMBOL_PC_RELATIVE);
  12853. }
  12854. }
  12855. /* Rewrite INSN so that constant pool references refer to the constant's
  12856. label instead. */
  12857. static void
  12858. mips16_rewrite_pool_refs (rtx_insn *insn, struct mips16_constant_pool *pool)
  12859. {
  12860. subrtx_ptr_iterator::array_type array;
  12861. FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), ALL)
  12862. {
  12863. rtx *loc = *iter;
  12864. if (force_to_mem_operand (*loc, Pmode))
  12865. {
  12866. rtx mem = force_const_mem (GET_MODE (*loc), *loc);
  12867. validate_change (insn, loc, mem, false);
  12868. }
  12869. if (MEM_P (*loc))
  12870. {
  12871. mips16_rewrite_pool_constant (pool, &XEXP (*loc, 0));
  12872. iter.skip_subrtxes ();
  12873. }
  12874. else
  12875. {
  12876. if (TARGET_MIPS16_TEXT_LOADS)
  12877. mips16_rewrite_pool_constant (pool, loc);
  12878. if (GET_CODE (*loc) == CONST
  12879. /* Don't rewrite the __mips16_rdwr symbol. */
  12880. || (GET_CODE (*loc) == UNSPEC
  12881. && XINT (*loc, 1) == UNSPEC_TLS_GET_TP))
  12882. iter.skip_subrtxes ();
  12883. }
  12884. }
  12885. }
  12886. /* Return whether CFG is used in mips_reorg. */
  12887. static bool
  12888. mips_cfg_in_reorg (void)
  12889. {
  12890. return (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE
  12891. || TARGET_RELAX_PIC_CALLS);
  12892. }
  12893. /* Build MIPS16 constant pools. Split the instructions if SPLIT_P,
  12894. otherwise assume that they are already split. */
  12895. static void
  12896. mips16_lay_out_constants (bool split_p)
  12897. {
  12898. struct mips16_constant_pool pool;
  12899. rtx_insn *insn, *barrier;
  12900. if (!TARGET_MIPS16_PCREL_LOADS)
  12901. return;
  12902. if (split_p)
  12903. {
  12904. if (mips_cfg_in_reorg ())
  12905. split_all_insns ();
  12906. else
  12907. split_all_insns_noflow ();
  12908. }
  12909. barrier = 0;
  12910. memset (&pool, 0, sizeof (pool));
  12911. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  12912. {
  12913. /* Rewrite constant pool references in INSN. */
  12914. if (USEFUL_INSN_P (insn))
  12915. mips16_rewrite_pool_refs (insn, &pool);
  12916. pool.insn_address += mips16_insn_length (insn);
  12917. if (pool.first != NULL)
  12918. {
  12919. /* If there are no natural barriers between the first user of
  12920. the pool and the highest acceptable address, we'll need to
  12921. create a new instruction to jump around the constant pool.
  12922. In the worst case, this instruction will be 4 bytes long.
  12923. If it's too late to do this transformation after INSN,
  12924. do it immediately before INSN. */
  12925. if (barrier == 0 && pool.insn_address + 4 > pool.highest_address)
  12926. {
  12927. rtx_code_label *label;
  12928. rtx_insn *jump;
  12929. label = gen_label_rtx ();
  12930. jump = emit_jump_insn_before (gen_jump (label), insn);
  12931. JUMP_LABEL (jump) = label;
  12932. LABEL_NUSES (label) = 1;
  12933. barrier = emit_barrier_after (jump);
  12934. emit_label_after (label, barrier);
  12935. pool.insn_address += 4;
  12936. }
  12937. /* See whether the constant pool is now out of range of the first
  12938. user. If so, output the constants after the previous barrier.
  12939. Note that any instructions between BARRIER and INSN (inclusive)
  12940. will use negative offsets to refer to the pool. */
  12941. if (pool.insn_address > pool.highest_address)
  12942. {
  12943. mips16_emit_constants (pool.first, barrier);
  12944. pool.first = NULL;
  12945. barrier = 0;
  12946. }
  12947. else if (BARRIER_P (insn))
  12948. barrier = insn;
  12949. }
  12950. }
  12951. mips16_emit_constants (pool.first, get_last_insn ());
  12952. }
  12953. /* Return true if it is worth r10k_simplify_address's while replacing
  12954. an address with X. We are looking for constants, and for addresses
  12955. at a known offset from the incoming stack pointer. */
  12956. static bool
  12957. r10k_simplified_address_p (rtx x)
  12958. {
  12959. if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
  12960. x = XEXP (x, 0);
  12961. return x == virtual_incoming_args_rtx || CONSTANT_P (x);
  12962. }
  12963. /* X is an expression that appears in INSN. Try to use the UD chains
  12964. to simplify it, returning the simplified form on success and the
  12965. original form otherwise. Replace the incoming value of $sp with
  12966. virtual_incoming_args_rtx (which should never occur in X otherwise). */
  12967. static rtx
  12968. r10k_simplify_address (rtx x, rtx_insn *insn)
  12969. {
  12970. rtx newx, op0, op1, set, note;
  12971. rtx_insn *def_insn;
  12972. df_ref use, def;
  12973. struct df_link *defs;
  12974. newx = NULL_RTX;
  12975. if (UNARY_P (x))
  12976. {
  12977. op0 = r10k_simplify_address (XEXP (x, 0), insn);
  12978. if (op0 != XEXP (x, 0))
  12979. newx = simplify_gen_unary (GET_CODE (x), GET_MODE (x),
  12980. op0, GET_MODE (XEXP (x, 0)));
  12981. }
  12982. else if (BINARY_P (x))
  12983. {
  12984. op0 = r10k_simplify_address (XEXP (x, 0), insn);
  12985. op1 = r10k_simplify_address (XEXP (x, 1), insn);
  12986. if (op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
  12987. newx = simplify_gen_binary (GET_CODE (x), GET_MODE (x), op0, op1);
  12988. }
  12989. else if (GET_CODE (x) == LO_SUM)
  12990. {
  12991. /* LO_SUMs can be offset from HIGHs, if we know they won't
  12992. overflow. See mips_classify_address for the rationale behind
  12993. the lax check. */
  12994. op0 = r10k_simplify_address (XEXP (x, 0), insn);
  12995. if (GET_CODE (op0) == HIGH)
  12996. newx = XEXP (x, 1);
  12997. }
  12998. else if (REG_P (x))
  12999. {
  13000. /* Uses are recorded by regno_reg_rtx, not X itself. */
  13001. use = df_find_use (insn, regno_reg_rtx[REGNO (x)]);
  13002. gcc_assert (use);
  13003. defs = DF_REF_CHAIN (use);
  13004. /* Require a single definition. */
  13005. if (defs && defs->next == NULL)
  13006. {
  13007. def = defs->ref;
  13008. if (DF_REF_IS_ARTIFICIAL (def))
  13009. {
  13010. /* Replace the incoming value of $sp with
  13011. virtual_incoming_args_rtx. */
  13012. if (x == stack_pointer_rtx
  13013. && DF_REF_BB (def) == ENTRY_BLOCK_PTR_FOR_FN (cfun))
  13014. newx = virtual_incoming_args_rtx;
  13015. }
  13016. else if (dominated_by_p (CDI_DOMINATORS, DF_REF_BB (use),
  13017. DF_REF_BB (def)))
  13018. {
  13019. /* Make sure that DEF_INSN is a single set of REG. */
  13020. def_insn = DF_REF_INSN (def);
  13021. if (NONJUMP_INSN_P (def_insn))
  13022. {
  13023. set = single_set (def_insn);
  13024. if (set && rtx_equal_p (SET_DEST (set), x))
  13025. {
  13026. /* Prefer to use notes, since the def-use chains
  13027. are often shorter. */
  13028. note = find_reg_equal_equiv_note (def_insn);
  13029. if (note)
  13030. newx = XEXP (note, 0);
  13031. else
  13032. newx = SET_SRC (set);
  13033. newx = r10k_simplify_address (newx, def_insn);
  13034. }
  13035. }
  13036. }
  13037. }
  13038. }
  13039. if (newx && r10k_simplified_address_p (newx))
  13040. return newx;
  13041. return x;
  13042. }
  13043. /* Return true if ADDRESS is known to be an uncached address
  13044. on R10K systems. */
  13045. static bool
  13046. r10k_uncached_address_p (unsigned HOST_WIDE_INT address)
  13047. {
  13048. unsigned HOST_WIDE_INT upper;
  13049. /* Check for KSEG1. */
  13050. if (address + 0x60000000 < 0x20000000)
  13051. return true;
  13052. /* Check for uncached XKPHYS addresses. */
  13053. if (Pmode == DImode)
  13054. {
  13055. upper = (address >> 40) & 0xf9ffff;
  13056. if (upper == 0x900000 || upper == 0xb80000)
  13057. return true;
  13058. }
  13059. return false;
  13060. }
  13061. /* Return true if we can prove that an access to address X in instruction
  13062. INSN would be safe from R10K speculation. This X is a general
  13063. expression; it might not be a legitimate address. */
  13064. static bool
  13065. r10k_safe_address_p (rtx x, rtx_insn *insn)
  13066. {
  13067. rtx base, offset;
  13068. HOST_WIDE_INT offset_val;
  13069. x = r10k_simplify_address (x, insn);
  13070. /* Check for references to the stack frame. It doesn't really matter
  13071. how much of the frame has been allocated at INSN; -mr10k-cache-barrier
  13072. allows us to assume that accesses to any part of the eventual frame
  13073. is safe from speculation at any point in the function. */
  13074. mips_split_plus (x, &base, &offset_val);
  13075. if (base == virtual_incoming_args_rtx
  13076. && offset_val >= -cfun->machine->frame.total_size
  13077. && offset_val < cfun->machine->frame.args_size)
  13078. return true;
  13079. /* Check for uncached addresses. */
  13080. if (CONST_INT_P (x))
  13081. return r10k_uncached_address_p (INTVAL (x));
  13082. /* Check for accesses to a static object. */
  13083. split_const (x, &base, &offset);
  13084. return offset_within_block_p (base, INTVAL (offset));
  13085. }
  13086. /* Return true if a MEM with MEM_EXPR EXPR and MEM_OFFSET OFFSET is
  13087. an in-range access to an automatic variable, or to an object with
  13088. a link-time-constant address. */
  13089. static bool
  13090. r10k_safe_mem_expr_p (tree expr, unsigned HOST_WIDE_INT offset)
  13091. {
  13092. HOST_WIDE_INT bitoffset, bitsize;
  13093. tree inner, var_offset;
  13094. machine_mode mode;
  13095. int unsigned_p, volatile_p;
  13096. inner = get_inner_reference (expr, &bitsize, &bitoffset, &var_offset, &mode,
  13097. &unsigned_p, &volatile_p, false);
  13098. if (!DECL_P (inner) || !DECL_SIZE_UNIT (inner) || var_offset)
  13099. return false;
  13100. offset += bitoffset / BITS_PER_UNIT;
  13101. return offset < tree_to_uhwi (DECL_SIZE_UNIT (inner));
  13102. }
  13103. /* Return true if X contains a MEM that is not safe from R10K speculation.
  13104. INSN is the instruction that contains X. */
  13105. static bool
  13106. r10k_needs_protection_p_1 (rtx x, rtx_insn *insn)
  13107. {
  13108. subrtx_var_iterator::array_type array;
  13109. FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST)
  13110. {
  13111. rtx mem = *iter;
  13112. if (MEM_P (mem))
  13113. {
  13114. if ((MEM_EXPR (mem)
  13115. && MEM_OFFSET_KNOWN_P (mem)
  13116. && r10k_safe_mem_expr_p (MEM_EXPR (mem), MEM_OFFSET (mem)))
  13117. || r10k_safe_address_p (XEXP (mem, 0), insn))
  13118. iter.skip_subrtxes ();
  13119. else
  13120. return true;
  13121. }
  13122. }
  13123. return false;
  13124. }
  13125. /* A note_stores callback for which DATA points to an instruction pointer.
  13126. If *DATA is nonnull, make it null if it X contains a MEM that is not
  13127. safe from R10K speculation. */
  13128. static void
  13129. r10k_needs_protection_p_store (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
  13130. void *data)
  13131. {
  13132. rtx_insn **insn_ptr;
  13133. insn_ptr = (rtx_insn **) data;
  13134. if (*insn_ptr && r10k_needs_protection_p_1 (x, *insn_ptr))
  13135. *insn_ptr = NULL;
  13136. }
  13137. /* X is the pattern of a call instruction. Return true if the call is
  13138. not to a declared function. */
  13139. static bool
  13140. r10k_needs_protection_p_call (const_rtx x)
  13141. {
  13142. subrtx_iterator::array_type array;
  13143. FOR_EACH_SUBRTX (iter, array, x, NONCONST)
  13144. {
  13145. const_rtx mem = *iter;
  13146. if (MEM_P (mem))
  13147. {
  13148. const_rtx addr = XEXP (mem, 0);
  13149. if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DECL (addr))
  13150. iter.skip_subrtxes ();
  13151. else
  13152. return true;
  13153. }
  13154. }
  13155. return false;
  13156. }
  13157. /* Return true if instruction INSN needs to be protected by an R10K
  13158. cache barrier. */
  13159. static bool
  13160. r10k_needs_protection_p (rtx_insn *insn)
  13161. {
  13162. if (CALL_P (insn))
  13163. return r10k_needs_protection_p_call (PATTERN (insn));
  13164. if (mips_r10k_cache_barrier == R10K_CACHE_BARRIER_STORE)
  13165. {
  13166. note_stores (PATTERN (insn), r10k_needs_protection_p_store, &insn);
  13167. return insn == NULL_RTX;
  13168. }
  13169. return r10k_needs_protection_p_1 (PATTERN (insn), insn);
  13170. }
  13171. /* Return true if BB is only reached by blocks in PROTECTED_BBS and if every
  13172. edge is unconditional. */
  13173. static bool
  13174. r10k_protected_bb_p (basic_block bb, sbitmap protected_bbs)
  13175. {
  13176. edge_iterator ei;
  13177. edge e;
  13178. FOR_EACH_EDGE (e, ei, bb->preds)
  13179. if (!single_succ_p (e->src)
  13180. || !bitmap_bit_p (protected_bbs, e->src->index)
  13181. || (e->flags & EDGE_COMPLEX) != 0)
  13182. return false;
  13183. return true;
  13184. }
  13185. /* Implement -mr10k-cache-barrier= for the current function. */
  13186. static void
  13187. r10k_insert_cache_barriers (void)
  13188. {
  13189. int *rev_post_order;
  13190. unsigned int i, n;
  13191. basic_block bb;
  13192. sbitmap protected_bbs;
  13193. rtx_insn *insn, *end;
  13194. rtx unprotected_region;
  13195. if (TARGET_MIPS16)
  13196. {
  13197. sorry ("%qs does not support MIPS16 code", "-mr10k-cache-barrier");
  13198. return;
  13199. }
  13200. /* Calculate dominators. */
  13201. calculate_dominance_info (CDI_DOMINATORS);
  13202. /* Bit X of PROTECTED_BBS is set if the last operation in basic block
  13203. X is protected by a cache barrier. */
  13204. protected_bbs = sbitmap_alloc (last_basic_block_for_fn (cfun));
  13205. bitmap_clear (protected_bbs);
  13206. /* Iterate over the basic blocks in reverse post-order. */
  13207. rev_post_order = XNEWVEC (int, last_basic_block_for_fn (cfun));
  13208. n = pre_and_rev_post_order_compute (NULL, rev_post_order, false);
  13209. for (i = 0; i < n; i++)
  13210. {
  13211. bb = BASIC_BLOCK_FOR_FN (cfun, rev_post_order[i]);
  13212. /* If this block is only reached by unconditional edges, and if the
  13213. source of every edge is protected, the beginning of the block is
  13214. also protected. */
  13215. if (r10k_protected_bb_p (bb, protected_bbs))
  13216. unprotected_region = NULL_RTX;
  13217. else
  13218. unprotected_region = pc_rtx;
  13219. end = NEXT_INSN (BB_END (bb));
  13220. /* UNPROTECTED_REGION is:
  13221. - null if we are processing a protected region,
  13222. - pc_rtx if we are processing an unprotected region but have
  13223. not yet found the first instruction in it
  13224. - the first instruction in an unprotected region otherwise. */
  13225. for (insn = BB_HEAD (bb); insn != end; insn = NEXT_INSN (insn))
  13226. {
  13227. if (unprotected_region && USEFUL_INSN_P (insn))
  13228. {
  13229. if (recog_memoized (insn) == CODE_FOR_mips_cache)
  13230. /* This CACHE instruction protects the following code. */
  13231. unprotected_region = NULL_RTX;
  13232. else
  13233. {
  13234. /* See if INSN is the first instruction in this
  13235. unprotected region. */
  13236. if (unprotected_region == pc_rtx)
  13237. unprotected_region = insn;
  13238. /* See if INSN needs to be protected. If so,
  13239. we must insert a cache barrier somewhere between
  13240. PREV_INSN (UNPROTECTED_REGION) and INSN. It isn't
  13241. clear which position is better performance-wise,
  13242. but as a tie-breaker, we assume that it is better
  13243. to allow delay slots to be back-filled where
  13244. possible, and that it is better not to insert
  13245. barriers in the middle of already-scheduled code.
  13246. We therefore insert the barrier at the beginning
  13247. of the region. */
  13248. if (r10k_needs_protection_p (insn))
  13249. {
  13250. emit_insn_before (gen_r10k_cache_barrier (),
  13251. unprotected_region);
  13252. unprotected_region = NULL_RTX;
  13253. }
  13254. }
  13255. }
  13256. if (CALL_P (insn))
  13257. /* The called function is not required to protect the exit path.
  13258. The code that follows a call is therefore unprotected. */
  13259. unprotected_region = pc_rtx;
  13260. }
  13261. /* Record whether the end of this block is protected. */
  13262. if (unprotected_region == NULL_RTX)
  13263. bitmap_set_bit (protected_bbs, bb->index);
  13264. }
  13265. XDELETEVEC (rev_post_order);
  13266. sbitmap_free (protected_bbs);
  13267. free_dominance_info (CDI_DOMINATORS);
  13268. }
  13269. /* If INSN is a call, return the underlying CALL expr. Return NULL_RTX
  13270. otherwise. If INSN has two call rtx, then store the second one in
  13271. SECOND_CALL. */
  13272. static rtx
  13273. mips_call_expr_from_insn (rtx_insn *insn, rtx *second_call)
  13274. {
  13275. rtx x;
  13276. rtx x2;
  13277. if (!CALL_P (insn))
  13278. return NULL_RTX;
  13279. x = PATTERN (insn);
  13280. if (GET_CODE (x) == PARALLEL)
  13281. {
  13282. /* Calls returning complex values have two CALL rtx. Look for the second
  13283. one here, and return it via the SECOND_CALL arg. */
  13284. x2 = XVECEXP (x, 0, 1);
  13285. if (GET_CODE (x2) == SET)
  13286. x2 = XEXP (x2, 1);
  13287. if (GET_CODE (x2) == CALL)
  13288. *second_call = x2;
  13289. x = XVECEXP (x, 0, 0);
  13290. }
  13291. if (GET_CODE (x) == SET)
  13292. x = XEXP (x, 1);
  13293. gcc_assert (GET_CODE (x) == CALL);
  13294. return x;
  13295. }
  13296. /* REG is set in DEF. See if the definition is one of the ways we load a
  13297. register with a symbol address for a mips_use_pic_fn_addr_reg_p call.
  13298. If it is, return the symbol reference of the function, otherwise return
  13299. NULL_RTX.
  13300. If RECURSE_P is true, use mips_find_pic_call_symbol to interpret
  13301. the values of source registers, otherwise treat such registers as
  13302. having an unknown value. */
  13303. static rtx
  13304. mips_pic_call_symbol_from_set (df_ref def, rtx reg, bool recurse_p)
  13305. {
  13306. rtx_insn *def_insn;
  13307. rtx set;
  13308. if (DF_REF_IS_ARTIFICIAL (def))
  13309. return NULL_RTX;
  13310. def_insn = DF_REF_INSN (def);
  13311. set = single_set (def_insn);
  13312. if (set && rtx_equal_p (SET_DEST (set), reg))
  13313. {
  13314. rtx note, src, symbol;
  13315. /* First see whether the source is a plain symbol. This is used
  13316. when calling symbols that are not lazily bound. */
  13317. src = SET_SRC (set);
  13318. if (GET_CODE (src) == SYMBOL_REF)
  13319. return src;
  13320. /* Handle %call16 references. */
  13321. symbol = mips_strip_unspec_call (src);
  13322. if (symbol)
  13323. {
  13324. gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
  13325. return symbol;
  13326. }
  13327. /* If we have something more complicated, look for a
  13328. REG_EQUAL or REG_EQUIV note. */
  13329. note = find_reg_equal_equiv_note (def_insn);
  13330. if (note && GET_CODE (XEXP (note, 0)) == SYMBOL_REF)
  13331. return XEXP (note, 0);
  13332. /* Follow at most one simple register copy. Such copies are
  13333. interesting in cases like:
  13334. for (...)
  13335. {
  13336. locally_binding_fn (...);
  13337. }
  13338. and:
  13339. locally_binding_fn (...);
  13340. ...
  13341. locally_binding_fn (...);
  13342. where the load of locally_binding_fn can legitimately be
  13343. hoisted or shared. However, we do not expect to see complex
  13344. chains of copies, so a full worklist solution to the problem
  13345. would probably be overkill. */
  13346. if (recurse_p && REG_P (src))
  13347. return mips_find_pic_call_symbol (def_insn, src, false);
  13348. }
  13349. return NULL_RTX;
  13350. }
  13351. /* Find the definition of the use of REG in INSN. See if the definition
  13352. is one of the ways we load a register with a symbol address for a
  13353. mips_use_pic_fn_addr_reg_p call. If it is return the symbol reference
  13354. of the function, otherwise return NULL_RTX. RECURSE_P is as for
  13355. mips_pic_call_symbol_from_set. */
  13356. static rtx
  13357. mips_find_pic_call_symbol (rtx_insn *insn, rtx reg, bool recurse_p)
  13358. {
  13359. df_ref use;
  13360. struct df_link *defs;
  13361. rtx symbol;
  13362. use = df_find_use (insn, regno_reg_rtx[REGNO (reg)]);
  13363. if (!use)
  13364. return NULL_RTX;
  13365. defs = DF_REF_CHAIN (use);
  13366. if (!defs)
  13367. return NULL_RTX;
  13368. symbol = mips_pic_call_symbol_from_set (defs->ref, reg, recurse_p);
  13369. if (!symbol)
  13370. return NULL_RTX;
  13371. /* If we have more than one definition, they need to be identical. */
  13372. for (defs = defs->next; defs; defs = defs->next)
  13373. {
  13374. rtx other;
  13375. other = mips_pic_call_symbol_from_set (defs->ref, reg, recurse_p);
  13376. if (!rtx_equal_p (symbol, other))
  13377. return NULL_RTX;
  13378. }
  13379. return symbol;
  13380. }
  13381. /* Replace the args_size operand of the call expression CALL with the
  13382. call-attribute UNSPEC and fill in SYMBOL as the function symbol. */
  13383. static void
  13384. mips_annotate_pic_call_expr (rtx call, rtx symbol)
  13385. {
  13386. rtx args_size;
  13387. args_size = XEXP (call, 1);
  13388. XEXP (call, 1) = gen_rtx_UNSPEC (GET_MODE (args_size),
  13389. gen_rtvec (2, args_size, symbol),
  13390. UNSPEC_CALL_ATTR);
  13391. }
  13392. /* OPERANDS[ARGS_SIZE_OPNO] is the arg_size operand of a CALL expression. See
  13393. if instead of the arg_size argument it contains the call attributes. If
  13394. yes return true along with setting OPERANDS[ARGS_SIZE_OPNO] to the function
  13395. symbol from the call attributes. Also return false if ARGS_SIZE_OPNO is
  13396. -1. */
  13397. bool
  13398. mips_get_pic_call_symbol (rtx *operands, int args_size_opno)
  13399. {
  13400. rtx args_size, symbol;
  13401. if (!TARGET_RELAX_PIC_CALLS || args_size_opno == -1)
  13402. return false;
  13403. args_size = operands[args_size_opno];
  13404. if (GET_CODE (args_size) != UNSPEC)
  13405. return false;
  13406. gcc_assert (XINT (args_size, 1) == UNSPEC_CALL_ATTR);
  13407. symbol = XVECEXP (args_size, 0, 1);
  13408. gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
  13409. operands[args_size_opno] = symbol;
  13410. return true;
  13411. }
  13412. /* Use DF to annotate PIC indirect calls with the function symbol they
  13413. dispatch to. */
  13414. static void
  13415. mips_annotate_pic_calls (void)
  13416. {
  13417. basic_block bb;
  13418. rtx_insn *insn;
  13419. FOR_EACH_BB_FN (bb, cfun)
  13420. FOR_BB_INSNS (bb, insn)
  13421. {
  13422. rtx call, reg, symbol, second_call;
  13423. second_call = 0;
  13424. call = mips_call_expr_from_insn (insn, &second_call);
  13425. if (!call)
  13426. continue;
  13427. gcc_assert (MEM_P (XEXP (call, 0)));
  13428. reg = XEXP (XEXP (call, 0), 0);
  13429. if (!REG_P (reg))
  13430. continue;
  13431. symbol = mips_find_pic_call_symbol (insn, reg, true);
  13432. if (symbol)
  13433. {
  13434. mips_annotate_pic_call_expr (call, symbol);
  13435. if (second_call)
  13436. mips_annotate_pic_call_expr (second_call, symbol);
  13437. }
  13438. }
  13439. }
  13440. /* A temporary variable used by note_uses callbacks, etc. */
  13441. static rtx_insn *mips_sim_insn;
  13442. /* A structure representing the state of the processor pipeline.
  13443. Used by the mips_sim_* family of functions. */
  13444. struct mips_sim {
  13445. /* The maximum number of instructions that can be issued in a cycle.
  13446. (Caches mips_issue_rate.) */
  13447. unsigned int issue_rate;
  13448. /* The current simulation time. */
  13449. unsigned int time;
  13450. /* How many more instructions can be issued in the current cycle. */
  13451. unsigned int insns_left;
  13452. /* LAST_SET[X].INSN is the last instruction to set register X.
  13453. LAST_SET[X].TIME is the time at which that instruction was issued.
  13454. INSN is null if no instruction has yet set register X. */
  13455. struct {
  13456. rtx_insn *insn;
  13457. unsigned int time;
  13458. } last_set[FIRST_PSEUDO_REGISTER];
  13459. /* The pipeline's current DFA state. */
  13460. state_t dfa_state;
  13461. };
  13462. /* Reset STATE to the initial simulation state. */
  13463. static void
  13464. mips_sim_reset (struct mips_sim *state)
  13465. {
  13466. curr_state = state->dfa_state;
  13467. state->time = 0;
  13468. state->insns_left = state->issue_rate;
  13469. memset (&state->last_set, 0, sizeof (state->last_set));
  13470. state_reset (curr_state);
  13471. targetm.sched.init (0, false, 0);
  13472. advance_state (curr_state);
  13473. }
  13474. /* Initialize STATE before its first use. DFA_STATE points to an
  13475. allocated but uninitialized DFA state. */
  13476. static void
  13477. mips_sim_init (struct mips_sim *state, state_t dfa_state)
  13478. {
  13479. if (targetm.sched.init_dfa_pre_cycle_insn)
  13480. targetm.sched.init_dfa_pre_cycle_insn ();
  13481. if (targetm.sched.init_dfa_post_cycle_insn)
  13482. targetm.sched.init_dfa_post_cycle_insn ();
  13483. state->issue_rate = mips_issue_rate ();
  13484. state->dfa_state = dfa_state;
  13485. mips_sim_reset (state);
  13486. }
  13487. /* Advance STATE by one clock cycle. */
  13488. static void
  13489. mips_sim_next_cycle (struct mips_sim *state)
  13490. {
  13491. curr_state = state->dfa_state;
  13492. state->time++;
  13493. state->insns_left = state->issue_rate;
  13494. advance_state (curr_state);
  13495. }
  13496. /* Advance simulation state STATE until instruction INSN can read
  13497. register REG. */
  13498. static void
  13499. mips_sim_wait_reg (struct mips_sim *state, rtx_insn *insn, rtx reg)
  13500. {
  13501. unsigned int regno, end_regno;
  13502. end_regno = END_REGNO (reg);
  13503. for (regno = REGNO (reg); regno < end_regno; regno++)
  13504. if (state->last_set[regno].insn != 0)
  13505. {
  13506. unsigned int t;
  13507. t = (state->last_set[regno].time
  13508. + insn_latency (state->last_set[regno].insn, insn));
  13509. while (state->time < t)
  13510. mips_sim_next_cycle (state);
  13511. }
  13512. }
  13513. /* A note_uses callback. For each register in *X, advance simulation
  13514. state DATA until mips_sim_insn can read the register's value. */
  13515. static void
  13516. mips_sim_wait_regs_1 (rtx *x, void *data)
  13517. {
  13518. subrtx_var_iterator::array_type array;
  13519. FOR_EACH_SUBRTX_VAR (iter, array, *x, NONCONST)
  13520. if (REG_P (*iter))
  13521. mips_sim_wait_reg ((struct mips_sim *) data, mips_sim_insn, *iter);
  13522. }
  13523. /* Advance simulation state STATE until all of INSN's register
  13524. dependencies are satisfied. */
  13525. static void
  13526. mips_sim_wait_regs (struct mips_sim *state, rtx_insn *insn)
  13527. {
  13528. mips_sim_insn = insn;
  13529. note_uses (&PATTERN (insn), mips_sim_wait_regs_1, state);
  13530. }
  13531. /* Advance simulation state STATE until the units required by
  13532. instruction INSN are available. */
  13533. static void
  13534. mips_sim_wait_units (struct mips_sim *state, rtx_insn *insn)
  13535. {
  13536. state_t tmp_state;
  13537. tmp_state = alloca (state_size ());
  13538. while (state->insns_left == 0
  13539. || (memcpy (tmp_state, state->dfa_state, state_size ()),
  13540. state_transition (tmp_state, insn) >= 0))
  13541. mips_sim_next_cycle (state);
  13542. }
  13543. /* Advance simulation state STATE until INSN is ready to issue. */
  13544. static void
  13545. mips_sim_wait_insn (struct mips_sim *state, rtx_insn *insn)
  13546. {
  13547. mips_sim_wait_regs (state, insn);
  13548. mips_sim_wait_units (state, insn);
  13549. }
  13550. /* mips_sim_insn has just set X. Update the LAST_SET array
  13551. in simulation state DATA. */
  13552. static void
  13553. mips_sim_record_set (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
  13554. {
  13555. struct mips_sim *state;
  13556. state = (struct mips_sim *) data;
  13557. if (REG_P (x))
  13558. {
  13559. unsigned int regno, end_regno;
  13560. end_regno = END_REGNO (x);
  13561. for (regno = REGNO (x); regno < end_regno; regno++)
  13562. {
  13563. state->last_set[regno].insn = mips_sim_insn;
  13564. state->last_set[regno].time = state->time;
  13565. }
  13566. }
  13567. }
  13568. /* Issue instruction INSN in scheduler state STATE. Assume that INSN
  13569. can issue immediately (i.e., that mips_sim_wait_insn has already
  13570. been called). */
  13571. static void
  13572. mips_sim_issue_insn (struct mips_sim *state, rtx_insn *insn)
  13573. {
  13574. curr_state = state->dfa_state;
  13575. state_transition (curr_state, insn);
  13576. state->insns_left = targetm.sched.variable_issue (0, false, insn,
  13577. state->insns_left);
  13578. mips_sim_insn = insn;
  13579. note_stores (PATTERN (insn), mips_sim_record_set, state);
  13580. }
  13581. /* Simulate issuing a NOP in state STATE. */
  13582. static void
  13583. mips_sim_issue_nop (struct mips_sim *state)
  13584. {
  13585. if (state->insns_left == 0)
  13586. mips_sim_next_cycle (state);
  13587. state->insns_left--;
  13588. }
  13589. /* Update simulation state STATE so that it's ready to accept the instruction
  13590. after INSN. INSN should be part of the main rtl chain, not a member of a
  13591. SEQUENCE. */
  13592. static void
  13593. mips_sim_finish_insn (struct mips_sim *state, rtx_insn *insn)
  13594. {
  13595. /* If INSN is a jump with an implicit delay slot, simulate a nop. */
  13596. if (JUMP_P (insn))
  13597. mips_sim_issue_nop (state);
  13598. switch (GET_CODE (SEQ_BEGIN (insn)))
  13599. {
  13600. case CODE_LABEL:
  13601. case CALL_INSN:
  13602. /* We can't predict the processor state after a call or label. */
  13603. mips_sim_reset (state);
  13604. break;
  13605. case JUMP_INSN:
  13606. /* The delay slots of branch likely instructions are only executed
  13607. when the branch is taken. Therefore, if the caller has simulated
  13608. the delay slot instruction, STATE does not really reflect the state
  13609. of the pipeline for the instruction after the delay slot. Also,
  13610. branch likely instructions tend to incur a penalty when not taken,
  13611. so there will probably be an extra delay between the branch and
  13612. the instruction after the delay slot. */
  13613. if (INSN_ANNULLED_BRANCH_P (SEQ_BEGIN (insn)))
  13614. mips_sim_reset (state);
  13615. break;
  13616. default:
  13617. break;
  13618. }
  13619. }
  13620. /* Use simulator state STATE to calculate the execution time of
  13621. instruction sequence SEQ. */
  13622. static unsigned int
  13623. mips_seq_time (struct mips_sim *state, rtx_insn *seq)
  13624. {
  13625. mips_sim_reset (state);
  13626. for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn))
  13627. {
  13628. mips_sim_wait_insn (state, insn);
  13629. mips_sim_issue_insn (state, insn);
  13630. }
  13631. return state->time;
  13632. }
  13633. /* Return the execution-time cost of mips_tuning_info.fast_mult_zero_zero_p
  13634. setting SETTING, using STATE to simulate instruction sequences. */
  13635. static unsigned int
  13636. mips_mult_zero_zero_cost (struct mips_sim *state, bool setting)
  13637. {
  13638. mips_tuning_info.fast_mult_zero_zero_p = setting;
  13639. start_sequence ();
  13640. machine_mode dword_mode = TARGET_64BIT ? TImode : DImode;
  13641. rtx hilo = gen_rtx_REG (dword_mode, MD_REG_FIRST);
  13642. mips_emit_move_or_split (hilo, const0_rtx, SPLIT_FOR_SPEED);
  13643. /* If the target provides mulsidi3_32bit then that's the most likely
  13644. consumer of the result. Test for bypasses. */
  13645. if (dword_mode == DImode && HAVE_maddsidi4)
  13646. {
  13647. rtx gpr = gen_rtx_REG (SImode, GP_REG_FIRST + 4);
  13648. emit_insn (gen_maddsidi4 (hilo, gpr, gpr, hilo));
  13649. }
  13650. unsigned int time = mips_seq_time (state, get_insns ());
  13651. end_sequence ();
  13652. return time;
  13653. }
  13654. /* Check the relative speeds of "MULT $0,$0" and "MTLO $0; MTHI $0"
  13655. and set up mips_tuning_info.fast_mult_zero_zero_p accordingly.
  13656. Prefer MULT -- which is shorter -- in the event of a tie. */
  13657. static void
  13658. mips_set_fast_mult_zero_zero_p (struct mips_sim *state)
  13659. {
  13660. if (TARGET_MIPS16 || !ISA_HAS_HILO)
  13661. /* No MTLO or MTHI available for MIPS16. Also, when there are no HI or LO
  13662. registers then there is no reason to zero them, arbitrarily choose to
  13663. say that "MULT $0,$0" would be faster. */
  13664. mips_tuning_info.fast_mult_zero_zero_p = true;
  13665. else
  13666. {
  13667. unsigned int true_time = mips_mult_zero_zero_cost (state, true);
  13668. unsigned int false_time = mips_mult_zero_zero_cost (state, false);
  13669. mips_tuning_info.fast_mult_zero_zero_p = (true_time <= false_time);
  13670. }
  13671. }
  13672. /* Set up costs based on the current architecture and tuning settings. */
  13673. static void
  13674. mips_set_tuning_info (void)
  13675. {
  13676. if (mips_tuning_info.initialized_p
  13677. && mips_tuning_info.arch == mips_arch
  13678. && mips_tuning_info.tune == mips_tune
  13679. && mips_tuning_info.mips16_p == TARGET_MIPS16)
  13680. return;
  13681. mips_tuning_info.arch = mips_arch;
  13682. mips_tuning_info.tune = mips_tune;
  13683. mips_tuning_info.mips16_p = TARGET_MIPS16;
  13684. mips_tuning_info.initialized_p = true;
  13685. dfa_start ();
  13686. struct mips_sim state;
  13687. mips_sim_init (&state, alloca (state_size ()));
  13688. mips_set_fast_mult_zero_zero_p (&state);
  13689. dfa_finish ();
  13690. }
  13691. /* Implement TARGET_EXPAND_TO_RTL_HOOK. */
  13692. static void
  13693. mips_expand_to_rtl_hook (void)
  13694. {
  13695. /* We need to call this at a point where we can safely create sequences
  13696. of instructions, so TARGET_OVERRIDE_OPTIONS is too early. We also
  13697. need to call it at a point where the DFA infrastructure is not
  13698. already in use, so we can't just call it lazily on demand.
  13699. At present, mips_tuning_info is only needed during post-expand
  13700. RTL passes such as split_insns, so this hook should be early enough.
  13701. We may need to move the call elsewhere if mips_tuning_info starts
  13702. to be used for other things (such as rtx_costs, or expanders that
  13703. could be called during gimple optimization). */
  13704. mips_set_tuning_info ();
  13705. }
  13706. /* The VR4130 pipeline issues aligned pairs of instructions together,
  13707. but it stalls the second instruction if it depends on the first.
  13708. In order to cut down the amount of logic required, this dependence
  13709. check is not based on a full instruction decode. Instead, any non-SPECIAL
  13710. instruction is assumed to modify the register specified by bits 20-16
  13711. (which is usually the "rt" field).
  13712. In BEQ, BEQL, BNE and BNEL instructions, the rt field is actually an
  13713. input, so we can end up with a false dependence between the branch
  13714. and its delay slot. If this situation occurs in instruction INSN,
  13715. try to avoid it by swapping rs and rt. */
  13716. static void
  13717. vr4130_avoid_branch_rt_conflict (rtx_insn *insn)
  13718. {
  13719. rtx_insn *first, *second;
  13720. first = SEQ_BEGIN (insn);
  13721. second = SEQ_END (insn);
  13722. if (JUMP_P (first)
  13723. && NONJUMP_INSN_P (second)
  13724. && GET_CODE (PATTERN (first)) == SET
  13725. && GET_CODE (SET_DEST (PATTERN (first))) == PC
  13726. && GET_CODE (SET_SRC (PATTERN (first))) == IF_THEN_ELSE)
  13727. {
  13728. /* Check for the right kind of condition. */
  13729. rtx cond = XEXP (SET_SRC (PATTERN (first)), 0);
  13730. if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
  13731. && REG_P (XEXP (cond, 0))
  13732. && REG_P (XEXP (cond, 1))
  13733. && reg_referenced_p (XEXP (cond, 1), PATTERN (second))
  13734. && !reg_referenced_p (XEXP (cond, 0), PATTERN (second)))
  13735. {
  13736. /* SECOND mentions the rt register but not the rs register. */
  13737. rtx tmp = XEXP (cond, 0);
  13738. XEXP (cond, 0) = XEXP (cond, 1);
  13739. XEXP (cond, 1) = tmp;
  13740. }
  13741. }
  13742. }
  13743. /* Implement -mvr4130-align. Go through each basic block and simulate the
  13744. processor pipeline. If we find that a pair of instructions could execute
  13745. in parallel, and the first of those instructions is not 8-byte aligned,
  13746. insert a nop to make it aligned. */
  13747. static void
  13748. vr4130_align_insns (void)
  13749. {
  13750. struct mips_sim state;
  13751. rtx_insn *insn, *subinsn, *last, *last2, *next;
  13752. bool aligned_p;
  13753. dfa_start ();
  13754. /* LAST is the last instruction before INSN to have a nonzero length.
  13755. LAST2 is the last such instruction before LAST. */
  13756. last = 0;
  13757. last2 = 0;
  13758. /* ALIGNED_P is true if INSN is known to be at an aligned address. */
  13759. aligned_p = true;
  13760. mips_sim_init (&state, alloca (state_size ()));
  13761. for (insn = get_insns (); insn != 0; insn = next)
  13762. {
  13763. unsigned int length;
  13764. next = NEXT_INSN (insn);
  13765. /* See the comment above vr4130_avoid_branch_rt_conflict for details.
  13766. This isn't really related to the alignment pass, but we do it on
  13767. the fly to avoid a separate instruction walk. */
  13768. vr4130_avoid_branch_rt_conflict (insn);
  13769. length = get_attr_length (insn);
  13770. if (length > 0 && USEFUL_INSN_P (insn))
  13771. FOR_EACH_SUBINSN (subinsn, insn)
  13772. {
  13773. mips_sim_wait_insn (&state, subinsn);
  13774. /* If we want this instruction to issue in parallel with the
  13775. previous one, make sure that the previous instruction is
  13776. aligned. There are several reasons why this isn't worthwhile
  13777. when the second instruction is a call:
  13778. - Calls are less likely to be performance critical,
  13779. - There's a good chance that the delay slot can execute
  13780. in parallel with the call.
  13781. - The return address would then be unaligned.
  13782. In general, if we're going to insert a nop between instructions
  13783. X and Y, it's better to insert it immediately after X. That
  13784. way, if the nop makes Y aligned, it will also align any labels
  13785. between X and Y. */
  13786. if (state.insns_left != state.issue_rate
  13787. && !CALL_P (subinsn))
  13788. {
  13789. if (subinsn == SEQ_BEGIN (insn) && aligned_p)
  13790. {
  13791. /* SUBINSN is the first instruction in INSN and INSN is
  13792. aligned. We want to align the previous instruction
  13793. instead, so insert a nop between LAST2 and LAST.
  13794. Note that LAST could be either a single instruction
  13795. or a branch with a delay slot. In the latter case,
  13796. LAST, like INSN, is already aligned, but the delay
  13797. slot must have some extra delay that stops it from
  13798. issuing at the same time as the branch. We therefore
  13799. insert a nop before the branch in order to align its
  13800. delay slot. */
  13801. gcc_assert (last2);
  13802. emit_insn_after (gen_nop (), last2);
  13803. aligned_p = false;
  13804. }
  13805. else if (subinsn != SEQ_BEGIN (insn) && !aligned_p)
  13806. {
  13807. /* SUBINSN is the delay slot of INSN, but INSN is
  13808. currently unaligned. Insert a nop between
  13809. LAST and INSN to align it. */
  13810. gcc_assert (last);
  13811. emit_insn_after (gen_nop (), last);
  13812. aligned_p = true;
  13813. }
  13814. }
  13815. mips_sim_issue_insn (&state, subinsn);
  13816. }
  13817. mips_sim_finish_insn (&state, insn);
  13818. /* Update LAST, LAST2 and ALIGNED_P for the next instruction. */
  13819. length = get_attr_length (insn);
  13820. if (length > 0)
  13821. {
  13822. /* If the instruction is an asm statement or multi-instruction
  13823. mips.md patern, the length is only an estimate. Insert an
  13824. 8 byte alignment after it so that the following instructions
  13825. can be handled correctly. */
  13826. if (NONJUMP_INSN_P (SEQ_BEGIN (insn))
  13827. && (recog_memoized (insn) < 0 || length >= 8))
  13828. {
  13829. next = emit_insn_after (gen_align (GEN_INT (3)), insn);
  13830. next = NEXT_INSN (next);
  13831. mips_sim_next_cycle (&state);
  13832. aligned_p = true;
  13833. }
  13834. else if (length & 4)
  13835. aligned_p = !aligned_p;
  13836. last2 = last;
  13837. last = insn;
  13838. }
  13839. /* See whether INSN is an aligned label. */
  13840. if (LABEL_P (insn) && label_to_alignment (insn) >= 3)
  13841. aligned_p = true;
  13842. }
  13843. dfa_finish ();
  13844. }
  13845. /* This structure records that the current function has a LO_SUM
  13846. involving SYMBOL_REF or LABEL_REF BASE and that MAX_OFFSET is
  13847. the largest offset applied to BASE by all such LO_SUMs. */
  13848. struct mips_lo_sum_offset {
  13849. rtx base;
  13850. HOST_WIDE_INT offset;
  13851. };
  13852. /* Return a hash value for SYMBOL_REF or LABEL_REF BASE. */
  13853. static hashval_t
  13854. mips_hash_base (rtx base)
  13855. {
  13856. int do_not_record_p;
  13857. return hash_rtx (base, GET_MODE (base), &do_not_record_p, NULL, false);
  13858. }
  13859. /* Hashtable helpers. */
  13860. struct mips_lo_sum_offset_hasher : typed_free_remove <mips_lo_sum_offset>
  13861. {
  13862. typedef mips_lo_sum_offset value_type;
  13863. typedef rtx_def compare_type;
  13864. static inline hashval_t hash (const value_type *);
  13865. static inline bool equal (const value_type *, const compare_type *);
  13866. };
  13867. /* Hash-table callbacks for mips_lo_sum_offsets. */
  13868. inline hashval_t
  13869. mips_lo_sum_offset_hasher::hash (const value_type *entry)
  13870. {
  13871. return mips_hash_base (entry->base);
  13872. }
  13873. inline bool
  13874. mips_lo_sum_offset_hasher::equal (const value_type *entry,
  13875. const compare_type *value)
  13876. {
  13877. return rtx_equal_p (entry->base, value);
  13878. }
  13879. typedef hash_table<mips_lo_sum_offset_hasher> mips_offset_table;
  13880. /* Look up symbolic constant X in HTAB, which is a hash table of
  13881. mips_lo_sum_offsets. If OPTION is NO_INSERT, return true if X can be
  13882. paired with a recorded LO_SUM, otherwise record X in the table. */
  13883. static bool
  13884. mips_lo_sum_offset_lookup (mips_offset_table *htab, rtx x,
  13885. enum insert_option option)
  13886. {
  13887. rtx base, offset;
  13888. mips_lo_sum_offset **slot;
  13889. struct mips_lo_sum_offset *entry;
  13890. /* Split X into a base and offset. */
  13891. split_const (x, &base, &offset);
  13892. if (UNSPEC_ADDRESS_P (base))
  13893. base = UNSPEC_ADDRESS (base);
  13894. /* Look up the base in the hash table. */
  13895. slot = htab->find_slot_with_hash (base, mips_hash_base (base), option);
  13896. if (slot == NULL)
  13897. return false;
  13898. entry = (struct mips_lo_sum_offset *) *slot;
  13899. if (option == INSERT)
  13900. {
  13901. if (entry == NULL)
  13902. {
  13903. entry = XNEW (struct mips_lo_sum_offset);
  13904. entry->base = base;
  13905. entry->offset = INTVAL (offset);
  13906. *slot = entry;
  13907. }
  13908. else
  13909. {
  13910. if (INTVAL (offset) > entry->offset)
  13911. entry->offset = INTVAL (offset);
  13912. }
  13913. }
  13914. return INTVAL (offset) <= entry->offset;
  13915. }
  13916. /* Search X for LO_SUMs and record them in HTAB. */
  13917. static void
  13918. mips_record_lo_sums (const_rtx x, mips_offset_table *htab)
  13919. {
  13920. subrtx_iterator::array_type array;
  13921. FOR_EACH_SUBRTX (iter, array, x, NONCONST)
  13922. if (GET_CODE (*iter) == LO_SUM)
  13923. mips_lo_sum_offset_lookup (htab, XEXP (*iter, 1), INSERT);
  13924. }
  13925. /* Return true if INSN is a SET of an orphaned high-part relocation.
  13926. HTAB is a hash table of mips_lo_sum_offsets that describes all the
  13927. LO_SUMs in the current function. */
  13928. static bool
  13929. mips_orphaned_high_part_p (mips_offset_table *htab, rtx_insn *insn)
  13930. {
  13931. enum mips_symbol_type type;
  13932. rtx x, set;
  13933. set = single_set (insn);
  13934. if (set)
  13935. {
  13936. /* Check for %his. */
  13937. x = SET_SRC (set);
  13938. if (GET_CODE (x) == HIGH
  13939. && absolute_symbolic_operand (XEXP (x, 0), VOIDmode))
  13940. return !mips_lo_sum_offset_lookup (htab, XEXP (x, 0), NO_INSERT);
  13941. /* Check for local %gots (and %got_pages, which is redundant but OK). */
  13942. if (GET_CODE (x) == UNSPEC
  13943. && XINT (x, 1) == UNSPEC_LOAD_GOT
  13944. && mips_symbolic_constant_p (XVECEXP (x, 0, 1),
  13945. SYMBOL_CONTEXT_LEA, &type)
  13946. && type == SYMBOL_GOTOFF_PAGE)
  13947. return !mips_lo_sum_offset_lookup (htab, XVECEXP (x, 0, 1), NO_INSERT);
  13948. }
  13949. return false;
  13950. }
  13951. /* Subroutine of mips_reorg_process_insns. If there is a hazard between
  13952. INSN and a previous instruction, avoid it by inserting nops after
  13953. instruction AFTER.
  13954. *DELAYED_REG and *HILO_DELAY describe the hazards that apply at
  13955. this point. If *DELAYED_REG is non-null, INSN must wait a cycle
  13956. before using the value of that register. *HILO_DELAY counts the
  13957. number of instructions since the last hilo hazard (that is,
  13958. the number of instructions since the last MFLO or MFHI).
  13959. After inserting nops for INSN, update *DELAYED_REG and *HILO_DELAY
  13960. for the next instruction.
  13961. LO_REG is an rtx for the LO register, used in dependence checking. */
  13962. static void
  13963. mips_avoid_hazard (rtx_insn *after, rtx_insn *insn, int *hilo_delay,
  13964. rtx *delayed_reg, rtx lo_reg)
  13965. {
  13966. rtx pattern, set;
  13967. int nops, ninsns;
  13968. pattern = PATTERN (insn);
  13969. /* Do not put the whole function in .set noreorder if it contains
  13970. an asm statement. We don't know whether there will be hazards
  13971. between the asm statement and the gcc-generated code. */
  13972. if (GET_CODE (pattern) == ASM_INPUT || asm_noperands (pattern) >= 0)
  13973. cfun->machine->all_noreorder_p = false;
  13974. /* Ignore zero-length instructions (barriers and the like). */
  13975. ninsns = get_attr_length (insn) / 4;
  13976. if (ninsns == 0)
  13977. return;
  13978. /* Work out how many nops are needed. Note that we only care about
  13979. registers that are explicitly mentioned in the instruction's pattern.
  13980. It doesn't matter that calls use the argument registers or that they
  13981. clobber hi and lo. */
  13982. if (*hilo_delay < 2 && reg_set_p (lo_reg, pattern))
  13983. nops = 2 - *hilo_delay;
  13984. else if (*delayed_reg != 0 && reg_referenced_p (*delayed_reg, pattern))
  13985. nops = 1;
  13986. else
  13987. nops = 0;
  13988. /* Insert the nops between this instruction and the previous one.
  13989. Each new nop takes us further from the last hilo hazard. */
  13990. *hilo_delay += nops;
  13991. while (nops-- > 0)
  13992. emit_insn_after (gen_hazard_nop (), after);
  13993. /* Set up the state for the next instruction. */
  13994. *hilo_delay += ninsns;
  13995. *delayed_reg = 0;
  13996. if (INSN_CODE (insn) >= 0)
  13997. switch (get_attr_hazard (insn))
  13998. {
  13999. case HAZARD_NONE:
  14000. break;
  14001. case HAZARD_HILO:
  14002. *hilo_delay = 0;
  14003. break;
  14004. case HAZARD_DELAY:
  14005. set = single_set (insn);
  14006. gcc_assert (set);
  14007. *delayed_reg = SET_DEST (set);
  14008. break;
  14009. }
  14010. }
  14011. /* Go through the instruction stream and insert nops where necessary.
  14012. Also delete any high-part relocations whose partnering low parts
  14013. are now all dead. See if the whole function can then be put into
  14014. .set noreorder and .set nomacro. */
  14015. static void
  14016. mips_reorg_process_insns (void)
  14017. {
  14018. rtx_insn *insn, *last_insn, *subinsn, *next_insn;
  14019. rtx lo_reg, delayed_reg;
  14020. int hilo_delay;
  14021. /* Force all instructions to be split into their final form. */
  14022. split_all_insns_noflow ();
  14023. /* Recalculate instruction lengths without taking nops into account. */
  14024. cfun->machine->ignore_hazard_length_p = true;
  14025. shorten_branches (get_insns ());
  14026. cfun->machine->all_noreorder_p = true;
  14027. /* We don't track MIPS16 PC-relative offsets closely enough to make
  14028. a good job of "set .noreorder" code in MIPS16 mode. */
  14029. if (TARGET_MIPS16)
  14030. cfun->machine->all_noreorder_p = false;
  14031. /* Code that doesn't use explicit relocs can't be ".set nomacro". */
  14032. if (!TARGET_EXPLICIT_RELOCS)
  14033. cfun->machine->all_noreorder_p = false;
  14034. /* Profiled functions can't be all noreorder because the profiler
  14035. support uses assembler macros. */
  14036. if (crtl->profile)
  14037. cfun->machine->all_noreorder_p = false;
  14038. /* Code compiled with -mfix-vr4120, -mfix-rm7000 or -mfix-24k can't be
  14039. all noreorder because we rely on the assembler to work around some
  14040. errata. The R5900 too has several bugs. */
  14041. if (TARGET_FIX_VR4120
  14042. || TARGET_FIX_RM7000
  14043. || TARGET_FIX_24K
  14044. || TARGET_MIPS5900)
  14045. cfun->machine->all_noreorder_p = false;
  14046. /* The same is true for -mfix-vr4130 if we might generate MFLO or
  14047. MFHI instructions. Note that we avoid using MFLO and MFHI if
  14048. the VR4130 MACC and DMACC instructions are available instead;
  14049. see the *mfhilo_{si,di}_macc patterns. */
  14050. if (TARGET_FIX_VR4130 && !ISA_HAS_MACCHI)
  14051. cfun->machine->all_noreorder_p = false;
  14052. mips_offset_table htab (37);
  14053. /* Make a first pass over the instructions, recording all the LO_SUMs. */
  14054. for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
  14055. FOR_EACH_SUBINSN (subinsn, insn)
  14056. if (USEFUL_INSN_P (subinsn))
  14057. {
  14058. rtx body = PATTERN (insn);
  14059. int noperands = asm_noperands (body);
  14060. if (noperands >= 0)
  14061. {
  14062. rtx *ops = XALLOCAVEC (rtx, noperands);
  14063. bool *used = XALLOCAVEC (bool, noperands);
  14064. const char *string = decode_asm_operands (body, ops, NULL, NULL,
  14065. NULL, NULL);
  14066. get_referenced_operands (string, used, noperands);
  14067. for (int i = 0; i < noperands; ++i)
  14068. if (used[i])
  14069. mips_record_lo_sums (ops[i], &htab);
  14070. }
  14071. else
  14072. mips_record_lo_sums (PATTERN (subinsn), &htab);
  14073. }
  14074. last_insn = 0;
  14075. hilo_delay = 2;
  14076. delayed_reg = 0;
  14077. lo_reg = gen_rtx_REG (SImode, LO_REGNUM);
  14078. /* Make a second pass over the instructions. Delete orphaned
  14079. high-part relocations or turn them into NOPs. Avoid hazards
  14080. by inserting NOPs. */
  14081. for (insn = get_insns (); insn != 0; insn = next_insn)
  14082. {
  14083. next_insn = NEXT_INSN (insn);
  14084. if (USEFUL_INSN_P (insn))
  14085. {
  14086. if (GET_CODE (PATTERN (insn)) == SEQUENCE)
  14087. {
  14088. /* If we find an orphaned high-part relocation in a delay
  14089. slot, it's easier to turn that instruction into a NOP than
  14090. to delete it. The delay slot will be a NOP either way. */
  14091. FOR_EACH_SUBINSN (subinsn, insn)
  14092. if (INSN_P (subinsn))
  14093. {
  14094. if (mips_orphaned_high_part_p (&htab, subinsn))
  14095. {
  14096. PATTERN (subinsn) = gen_nop ();
  14097. INSN_CODE (subinsn) = CODE_FOR_nop;
  14098. }
  14099. mips_avoid_hazard (last_insn, subinsn, &hilo_delay,
  14100. &delayed_reg, lo_reg);
  14101. }
  14102. last_insn = insn;
  14103. }
  14104. else
  14105. {
  14106. /* INSN is a single instruction. Delete it if it's an
  14107. orphaned high-part relocation. */
  14108. if (mips_orphaned_high_part_p (&htab, insn))
  14109. delete_insn (insn);
  14110. /* Also delete cache barriers if the last instruction
  14111. was an annulled branch. INSN will not be speculatively
  14112. executed. */
  14113. else if (recog_memoized (insn) == CODE_FOR_r10k_cache_barrier
  14114. && last_insn
  14115. && JUMP_P (SEQ_BEGIN (last_insn))
  14116. && INSN_ANNULLED_BRANCH_P (SEQ_BEGIN (last_insn)))
  14117. delete_insn (insn);
  14118. else
  14119. {
  14120. mips_avoid_hazard (last_insn, insn, &hilo_delay,
  14121. &delayed_reg, lo_reg);
  14122. last_insn = insn;
  14123. }
  14124. }
  14125. }
  14126. }
  14127. }
  14128. /* Return true if the function has a long branch instruction. */
  14129. static bool
  14130. mips_has_long_branch_p (void)
  14131. {
  14132. rtx_insn *insn, *subinsn;
  14133. int normal_length;
  14134. /* We need up-to-date instruction lengths. */
  14135. shorten_branches (get_insns ());
  14136. /* Look for a branch that is longer than normal. The normal length for
  14137. non-MIPS16 branches is 8, because the length includes the delay slot.
  14138. It is 4 for MIPS16, because MIPS16 branches are extended instructions,
  14139. but they have no delay slot. */
  14140. normal_length = (TARGET_MIPS16 ? 4 : 8);
  14141. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  14142. FOR_EACH_SUBINSN (subinsn, insn)
  14143. if (JUMP_P (subinsn)
  14144. && get_attr_length (subinsn) > normal_length
  14145. && (any_condjump_p (subinsn) || any_uncondjump_p (subinsn)))
  14146. return true;
  14147. return false;
  14148. }
  14149. /* If we are using a GOT, but have not decided to use a global pointer yet,
  14150. see whether we need one to implement long branches. Convert the ghost
  14151. global-pointer instructions into real ones if so. */
  14152. static bool
  14153. mips_expand_ghost_gp_insns (void)
  14154. {
  14155. /* Quick exit if we already know that we will or won't need a
  14156. global pointer. */
  14157. if (!TARGET_USE_GOT
  14158. || cfun->machine->global_pointer == INVALID_REGNUM
  14159. || mips_must_initialize_gp_p ())
  14160. return false;
  14161. /* Run a full check for long branches. */
  14162. if (!mips_has_long_branch_p ())
  14163. return false;
  14164. /* We've now established that we need $gp. */
  14165. cfun->machine->must_initialize_gp_p = true;
  14166. split_all_insns_noflow ();
  14167. return true;
  14168. }
  14169. /* Subroutine of mips_reorg to manage passes that require DF. */
  14170. static void
  14171. mips_df_reorg (void)
  14172. {
  14173. /* Create def-use chains. */
  14174. df_set_flags (DF_EQ_NOTES);
  14175. df_chain_add_problem (DF_UD_CHAIN);
  14176. df_analyze ();
  14177. if (TARGET_RELAX_PIC_CALLS)
  14178. mips_annotate_pic_calls ();
  14179. if (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE)
  14180. r10k_insert_cache_barriers ();
  14181. df_finish_pass (false);
  14182. }
  14183. /* Emit code to load LABEL_REF SRC into MIPS16 register DEST. This is
  14184. called very late in mips_reorg, but the caller is required to run
  14185. mips16_lay_out_constants on the result. */
  14186. static void
  14187. mips16_load_branch_target (rtx dest, rtx src)
  14188. {
  14189. if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS)
  14190. {
  14191. rtx page, low;
  14192. if (mips_cfun_has_cprestore_slot_p ())
  14193. mips_emit_move (dest, mips_cprestore_slot (dest, true));
  14194. else
  14195. mips_emit_move (dest, pic_offset_table_rtx);
  14196. page = mips_unspec_address (src, SYMBOL_GOTOFF_PAGE);
  14197. low = mips_unspec_address (src, SYMBOL_GOT_PAGE_OFST);
  14198. emit_insn (gen_rtx_SET (VOIDmode, dest,
  14199. PMODE_INSN (gen_unspec_got, (dest, page))));
  14200. emit_insn (gen_rtx_SET (VOIDmode, dest,
  14201. gen_rtx_LO_SUM (Pmode, dest, low)));
  14202. }
  14203. else
  14204. {
  14205. src = mips_unspec_address (src, SYMBOL_ABSOLUTE);
  14206. mips_emit_move (dest, src);
  14207. }
  14208. }
  14209. /* If we're compiling a MIPS16 function, look for and split any long branches.
  14210. This must be called after all other instruction modifications in
  14211. mips_reorg. */
  14212. static void
  14213. mips16_split_long_branches (void)
  14214. {
  14215. bool something_changed;
  14216. if (!TARGET_MIPS16)
  14217. return;
  14218. /* Loop until the alignments for all targets are sufficient. */
  14219. do
  14220. {
  14221. rtx_insn *insn;
  14222. shorten_branches (get_insns ());
  14223. something_changed = false;
  14224. for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  14225. if (JUMP_P (insn)
  14226. && get_attr_length (insn) > 4
  14227. && (any_condjump_p (insn) || any_uncondjump_p (insn)))
  14228. {
  14229. rtx old_label, temp, saved_temp;
  14230. rtx_code_label *new_label;
  14231. rtx target;
  14232. rtx_insn *jump, *jump_sequence;
  14233. start_sequence ();
  14234. /* Free up a MIPS16 register by saving it in $1. */
  14235. saved_temp = gen_rtx_REG (Pmode, AT_REGNUM);
  14236. temp = gen_rtx_REG (Pmode, GP_REG_FIRST + 2);
  14237. emit_move_insn (saved_temp, temp);
  14238. /* Load the branch target into TEMP. */
  14239. old_label = JUMP_LABEL (insn);
  14240. target = gen_rtx_LABEL_REF (Pmode, old_label);
  14241. mips16_load_branch_target (temp, target);
  14242. /* Jump to the target and restore the register's
  14243. original value. */
  14244. jump = emit_jump_insn (PMODE_INSN (gen_indirect_jump_and_restore,
  14245. (temp, temp, saved_temp)));
  14246. JUMP_LABEL (jump) = old_label;
  14247. LABEL_NUSES (old_label)++;
  14248. /* Rewrite any symbolic references that are supposed to use
  14249. a PC-relative constant pool. */
  14250. mips16_lay_out_constants (false);
  14251. if (simplejump_p (insn))
  14252. /* We're going to replace INSN with a longer form. */
  14253. new_label = NULL;
  14254. else
  14255. {
  14256. /* Create a branch-around label for the original
  14257. instruction. */
  14258. new_label = gen_label_rtx ();
  14259. emit_label (new_label);
  14260. }
  14261. jump_sequence = get_insns ();
  14262. end_sequence ();
  14263. emit_insn_after (jump_sequence, insn);
  14264. if (new_label)
  14265. invert_jump (insn, new_label, false);
  14266. else
  14267. delete_insn (insn);
  14268. something_changed = true;
  14269. }
  14270. }
  14271. while (something_changed);
  14272. }
  14273. /* Implement TARGET_MACHINE_DEPENDENT_REORG. */
  14274. static void
  14275. mips_reorg (void)
  14276. {
  14277. /* Restore the BLOCK_FOR_INSN pointers, which are needed by DF. Also during
  14278. insn splitting in mips16_lay_out_constants, DF insn info is only kept up
  14279. to date if the CFG is available. */
  14280. if (mips_cfg_in_reorg ())
  14281. compute_bb_for_insn ();
  14282. mips16_lay_out_constants (true);
  14283. if (mips_cfg_in_reorg ())
  14284. {
  14285. mips_df_reorg ();
  14286. free_bb_for_insn ();
  14287. }
  14288. }
  14289. /* We use a machine specific pass to do a second machine dependent reorg
  14290. pass after delay branch scheduling. */
  14291. static unsigned int
  14292. mips_machine_reorg2 (void)
  14293. {
  14294. mips_reorg_process_insns ();
  14295. if (!TARGET_MIPS16
  14296. && TARGET_EXPLICIT_RELOCS
  14297. && TUNE_MIPS4130
  14298. && TARGET_VR4130_ALIGN)
  14299. vr4130_align_insns ();
  14300. if (mips_expand_ghost_gp_insns ())
  14301. /* The expansion could invalidate some of the VR4130 alignment
  14302. optimizations, but this should be an extremely rare case anyhow. */
  14303. mips_reorg_process_insns ();
  14304. mips16_split_long_branches ();
  14305. return 0;
  14306. }
  14307. namespace {
  14308. const pass_data pass_data_mips_machine_reorg2 =
  14309. {
  14310. RTL_PASS, /* type */
  14311. "mach2", /* name */
  14312. OPTGROUP_NONE, /* optinfo_flags */
  14313. TV_MACH_DEP, /* tv_id */
  14314. 0, /* properties_required */
  14315. 0, /* properties_provided */
  14316. 0, /* properties_destroyed */
  14317. 0, /* todo_flags_start */
  14318. 0, /* todo_flags_finish */
  14319. };
  14320. class pass_mips_machine_reorg2 : public rtl_opt_pass
  14321. {
  14322. public:
  14323. pass_mips_machine_reorg2(gcc::context *ctxt)
  14324. : rtl_opt_pass(pass_data_mips_machine_reorg2, ctxt)
  14325. {}
  14326. /* opt_pass methods: */
  14327. virtual unsigned int execute (function *) { return mips_machine_reorg2 (); }
  14328. }; // class pass_mips_machine_reorg2
  14329. } // anon namespace
  14330. rtl_opt_pass *
  14331. make_pass_mips_machine_reorg2 (gcc::context *ctxt)
  14332. {
  14333. return new pass_mips_machine_reorg2 (ctxt);
  14334. }
  14335. /* Implement TARGET_ASM_OUTPUT_MI_THUNK. Generate rtl rather than asm text
  14336. in order to avoid duplicating too much logic from elsewhere. */
  14337. static void
  14338. mips_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
  14339. HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
  14340. tree function)
  14341. {
  14342. rtx this_rtx, temp1, temp2, fnaddr;
  14343. rtx_insn *insn;
  14344. bool use_sibcall_p;
  14345. /* Pretend to be a post-reload pass while generating rtl. */
  14346. reload_completed = 1;
  14347. /* Mark the end of the (empty) prologue. */
  14348. emit_note (NOTE_INSN_PROLOGUE_END);
  14349. /* Determine if we can use a sibcall to call FUNCTION directly. */
  14350. fnaddr = XEXP (DECL_RTL (function), 0);
  14351. use_sibcall_p = (mips_function_ok_for_sibcall (function, NULL)
  14352. && const_call_insn_operand (fnaddr, Pmode));
  14353. /* Determine if we need to load FNADDR from the GOT. */
  14354. if (!use_sibcall_p
  14355. && (mips_got_symbol_type_p
  14356. (mips_classify_symbol (fnaddr, SYMBOL_CONTEXT_LEA))))
  14357. {
  14358. /* Pick a global pointer. Use a call-clobbered register if
  14359. TARGET_CALL_SAVED_GP. */
  14360. cfun->machine->global_pointer
  14361. = TARGET_CALL_SAVED_GP ? 15 : GLOBAL_POINTER_REGNUM;
  14362. cfun->machine->must_initialize_gp_p = true;
  14363. SET_REGNO (pic_offset_table_rtx, cfun->machine->global_pointer);
  14364. /* Set up the global pointer for n32 or n64 abicalls. */
  14365. mips_emit_loadgp ();
  14366. }
  14367. /* We need two temporary registers in some cases. */
  14368. temp1 = gen_rtx_REG (Pmode, 2);
  14369. temp2 = gen_rtx_REG (Pmode, 3);
  14370. /* Find out which register contains the "this" pointer. */
  14371. if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
  14372. this_rtx = gen_rtx_REG (Pmode, GP_ARG_FIRST + 1);
  14373. else
  14374. this_rtx = gen_rtx_REG (Pmode, GP_ARG_FIRST);
  14375. /* Add DELTA to THIS_RTX. */
  14376. if (delta != 0)
  14377. {
  14378. rtx offset = GEN_INT (delta);
  14379. if (!SMALL_OPERAND (delta))
  14380. {
  14381. mips_emit_move (temp1, offset);
  14382. offset = temp1;
  14383. }
  14384. emit_insn (gen_add3_insn (this_rtx, this_rtx, offset));
  14385. }
  14386. /* If needed, add *(*THIS_RTX + VCALL_OFFSET) to THIS_RTX. */
  14387. if (vcall_offset != 0)
  14388. {
  14389. rtx addr;
  14390. /* Set TEMP1 to *THIS_RTX. */
  14391. mips_emit_move (temp1, gen_rtx_MEM (Pmode, this_rtx));
  14392. /* Set ADDR to a legitimate address for *THIS_RTX + VCALL_OFFSET. */
  14393. addr = mips_add_offset (temp2, temp1, vcall_offset);
  14394. /* Load the offset and add it to THIS_RTX. */
  14395. mips_emit_move (temp1, gen_rtx_MEM (Pmode, addr));
  14396. emit_insn (gen_add3_insn (this_rtx, this_rtx, temp1));
  14397. }
  14398. /* Jump to the target function. Use a sibcall if direct jumps are
  14399. allowed, otherwise load the address into a register first. */
  14400. if (use_sibcall_p)
  14401. {
  14402. insn = emit_call_insn (gen_sibcall_internal (fnaddr, const0_rtx));
  14403. SIBLING_CALL_P (insn) = 1;
  14404. }
  14405. else
  14406. {
  14407. /* This is messy. GAS treats "la $25,foo" as part of a call
  14408. sequence and may allow a global "foo" to be lazily bound.
  14409. The general move patterns therefore reject this combination.
  14410. In this context, lazy binding would actually be OK
  14411. for TARGET_CALL_CLOBBERED_GP, but it's still wrong for
  14412. TARGET_CALL_SAVED_GP; see mips_load_call_address.
  14413. We must therefore load the address via a temporary
  14414. register if mips_dangerous_for_la25_p.
  14415. If we jump to the temporary register rather than $25,
  14416. the assembler can use the move insn to fill the jump's
  14417. delay slot.
  14418. We can use the same technique for MIPS16 code, where $25
  14419. is not a valid JR register. */
  14420. if (TARGET_USE_PIC_FN_ADDR_REG
  14421. && !TARGET_MIPS16
  14422. && !mips_dangerous_for_la25_p (fnaddr))
  14423. temp1 = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
  14424. mips_load_call_address (MIPS_CALL_SIBCALL, temp1, fnaddr);
  14425. if (TARGET_USE_PIC_FN_ADDR_REG
  14426. && REGNO (temp1) != PIC_FUNCTION_ADDR_REGNUM)
  14427. mips_emit_move (gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM), temp1);
  14428. emit_jump_insn (gen_indirect_jump (temp1));
  14429. }
  14430. /* Run just enough of rest_of_compilation. This sequence was
  14431. "borrowed" from alpha.c. */
  14432. insn = get_insns ();
  14433. split_all_insns_noflow ();
  14434. mips16_lay_out_constants (true);
  14435. shorten_branches (insn);
  14436. final_start_function (insn, file, 1);
  14437. final (insn, file, 1);
  14438. final_end_function ();
  14439. /* Clean up the vars set above. Note that final_end_function resets
  14440. the global pointer for us. */
  14441. reload_completed = 0;
  14442. }
  14443. /* The last argument passed to mips_set_compression_mode,
  14444. or negative if the function hasn't been called yet. */
  14445. static unsigned int old_compression_mode = -1;
  14446. /* Set up the target-dependent global state for ISA mode COMPRESSION_MODE,
  14447. which is either MASK_MIPS16 or MASK_MICROMIPS. */
  14448. static void
  14449. mips_set_compression_mode (unsigned int compression_mode)
  14450. {
  14451. if (compression_mode == old_compression_mode)
  14452. return;
  14453. /* Restore base settings of various flags. */
  14454. target_flags = mips_base_target_flags;
  14455. flag_schedule_insns = mips_base_schedule_insns;
  14456. flag_reorder_blocks_and_partition = mips_base_reorder_blocks_and_partition;
  14457. flag_move_loop_invariants = mips_base_move_loop_invariants;
  14458. align_loops = mips_base_align_loops;
  14459. align_jumps = mips_base_align_jumps;
  14460. align_functions = mips_base_align_functions;
  14461. target_flags &= ~(MASK_MIPS16 | MASK_MICROMIPS);
  14462. target_flags |= compression_mode;
  14463. if (compression_mode & MASK_MIPS16)
  14464. {
  14465. /* Switch to MIPS16 mode. */
  14466. target_flags |= MASK_MIPS16;
  14467. /* Turn off SYNCI if it was on, MIPS16 doesn't support it. */
  14468. target_flags &= ~MASK_SYNCI;
  14469. /* Don't run the scheduler before reload, since it tends to
  14470. increase register pressure. */
  14471. flag_schedule_insns = 0;
  14472. /* Don't do hot/cold partitioning. mips16_lay_out_constants expects
  14473. the whole function to be in a single section. */
  14474. flag_reorder_blocks_and_partition = 0;
  14475. /* Don't move loop invariants, because it tends to increase
  14476. register pressure. It also introduces an extra move in cases
  14477. where the constant is the first operand in a two-operand binary
  14478. instruction, or when it forms a register argument to a functon
  14479. call. */
  14480. flag_move_loop_invariants = 0;
  14481. target_flags |= MASK_EXPLICIT_RELOCS;
  14482. /* Experiments suggest we get the best overall section-anchor
  14483. results from using the range of an unextended LW or SW. Code
  14484. that makes heavy use of byte or short accesses can do better
  14485. with ranges of 0...31 and 0...63 respectively, but most code is
  14486. sensitive to the range of LW and SW instead. */
  14487. targetm.min_anchor_offset = 0;
  14488. targetm.max_anchor_offset = 127;
  14489. targetm.const_anchor = 0;
  14490. /* MIPS16 has no BAL instruction. */
  14491. target_flags &= ~MASK_RELAX_PIC_CALLS;
  14492. /* The R4000 errata don't apply to any known MIPS16 cores.
  14493. It's simpler to make the R4000 fixes and MIPS16 mode
  14494. mutually exclusive. */
  14495. target_flags &= ~MASK_FIX_R4000;
  14496. if (flag_pic && !TARGET_OLDABI)
  14497. sorry ("MIPS16 PIC for ABIs other than o32 and o64");
  14498. if (TARGET_XGOT)
  14499. sorry ("MIPS16 -mxgot code");
  14500. if (TARGET_HARD_FLOAT_ABI && !TARGET_OLDABI)
  14501. sorry ("hard-float MIPS16 code for ABIs other than o32 and o64");
  14502. }
  14503. else
  14504. {
  14505. /* Switch to microMIPS or the standard encoding. */
  14506. if (TARGET_MICROMIPS)
  14507. /* Avoid branch likely. */
  14508. target_flags &= ~MASK_BRANCHLIKELY;
  14509. /* Provide default values for align_* for 64-bit targets. */
  14510. if (TARGET_64BIT)
  14511. {
  14512. if (align_loops == 0)
  14513. align_loops = 8;
  14514. if (align_jumps == 0)
  14515. align_jumps = 8;
  14516. if (align_functions == 0)
  14517. align_functions = 8;
  14518. }
  14519. targetm.min_anchor_offset = -32768;
  14520. targetm.max_anchor_offset = 32767;
  14521. targetm.const_anchor = 0x8000;
  14522. }
  14523. /* (Re)initialize MIPS target internals for new ISA. */
  14524. mips_init_relocs ();
  14525. if (compression_mode & MASK_MIPS16)
  14526. {
  14527. if (!mips16_globals)
  14528. mips16_globals = save_target_globals_default_opts ();
  14529. else
  14530. restore_target_globals (mips16_globals);
  14531. }
  14532. else
  14533. restore_target_globals (&default_target_globals);
  14534. old_compression_mode = compression_mode;
  14535. }
  14536. /* Implement TARGET_SET_CURRENT_FUNCTION. Decide whether the current
  14537. function should use the MIPS16 or microMIPS ISA and switch modes
  14538. accordingly. */
  14539. static void
  14540. mips_set_current_function (tree fndecl)
  14541. {
  14542. mips_set_compression_mode (mips_get_compress_mode (fndecl));
  14543. }
  14544. /* Allocate a chunk of memory for per-function machine-dependent data. */
  14545. static struct machine_function *
  14546. mips_init_machine_status (void)
  14547. {
  14548. return ggc_cleared_alloc<machine_function> ();
  14549. }
  14550. /* Return the processor associated with the given ISA level, or null
  14551. if the ISA isn't valid. */
  14552. static const struct mips_cpu_info *
  14553. mips_cpu_info_from_isa (int isa)
  14554. {
  14555. unsigned int i;
  14556. for (i = 0; i < ARRAY_SIZE (mips_cpu_info_table); i++)
  14557. if (mips_cpu_info_table[i].isa == isa)
  14558. return mips_cpu_info_table + i;
  14559. return NULL;
  14560. }
  14561. /* Return a mips_cpu_info entry determined by an option valued
  14562. OPT. */
  14563. static const struct mips_cpu_info *
  14564. mips_cpu_info_from_opt (int opt)
  14565. {
  14566. switch (opt)
  14567. {
  14568. case MIPS_ARCH_OPTION_FROM_ABI:
  14569. /* 'from-abi' selects the most compatible architecture for the
  14570. given ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit
  14571. ABIs. For the EABIs, we have to decide whether we're using
  14572. the 32-bit or 64-bit version. */
  14573. return mips_cpu_info_from_isa (ABI_NEEDS_32BIT_REGS ? 1
  14574. : ABI_NEEDS_64BIT_REGS ? 3
  14575. : (TARGET_64BIT ? 3 : 1));
  14576. case MIPS_ARCH_OPTION_NATIVE:
  14577. gcc_unreachable ();
  14578. default:
  14579. return &mips_cpu_info_table[opt];
  14580. }
  14581. }
  14582. /* Return a default mips_cpu_info entry, given that no -march= option
  14583. was explicitly specified. */
  14584. static const struct mips_cpu_info *
  14585. mips_default_arch (void)
  14586. {
  14587. #if defined (MIPS_CPU_STRING_DEFAULT)
  14588. unsigned int i;
  14589. for (i = 0; i < ARRAY_SIZE (mips_cpu_info_table); i++)
  14590. if (strcmp (mips_cpu_info_table[i].name, MIPS_CPU_STRING_DEFAULT) == 0)
  14591. return mips_cpu_info_table + i;
  14592. gcc_unreachable ();
  14593. #elif defined (MIPS_ISA_DEFAULT)
  14594. return mips_cpu_info_from_isa (MIPS_ISA_DEFAULT);
  14595. #else
  14596. /* 'from-abi' makes a good default: you get whatever the ABI
  14597. requires. */
  14598. return mips_cpu_info_from_opt (MIPS_ARCH_OPTION_FROM_ABI);
  14599. #endif
  14600. }
  14601. /* Set up globals to generate code for the ISA or processor
  14602. described by INFO. */
  14603. static void
  14604. mips_set_architecture (const struct mips_cpu_info *info)
  14605. {
  14606. if (info != 0)
  14607. {
  14608. mips_arch_info = info;
  14609. mips_arch = info->cpu;
  14610. mips_isa = info->isa;
  14611. if (mips_isa < 32)
  14612. mips_isa_rev = 0;
  14613. else
  14614. mips_isa_rev = (mips_isa & 31) + 1;
  14615. }
  14616. }
  14617. /* Likewise for tuning. */
  14618. static void
  14619. mips_set_tune (const struct mips_cpu_info *info)
  14620. {
  14621. if (info != 0)
  14622. {
  14623. mips_tune_info = info;
  14624. mips_tune = info->cpu;
  14625. }
  14626. }
  14627. /* Implement TARGET_OPTION_OVERRIDE. */
  14628. static void
  14629. mips_option_override (void)
  14630. {
  14631. int i, start, regno, mode;
  14632. if (global_options_set.x_mips_isa_option)
  14633. mips_isa_option_info = &mips_cpu_info_table[mips_isa_option];
  14634. #ifdef SUBTARGET_OVERRIDE_OPTIONS
  14635. SUBTARGET_OVERRIDE_OPTIONS;
  14636. #endif
  14637. /* MIPS16 and microMIPS cannot coexist. */
  14638. if (TARGET_MICROMIPS && TARGET_MIPS16)
  14639. error ("unsupported combination: %s", "-mips16 -mmicromips");
  14640. /* Save the base compression state and process flags as though we
  14641. were generating uncompressed code. */
  14642. mips_base_compression_flags = TARGET_COMPRESSION;
  14643. target_flags &= ~TARGET_COMPRESSION;
  14644. /* -mno-float overrides -mhard-float and -msoft-float. */
  14645. if (TARGET_NO_FLOAT)
  14646. {
  14647. target_flags |= MASK_SOFT_FLOAT_ABI;
  14648. target_flags_explicit |= MASK_SOFT_FLOAT_ABI;
  14649. }
  14650. if (TARGET_FLIP_MIPS16)
  14651. TARGET_INTERLINK_COMPRESSED = 1;
  14652. /* Set the small data limit. */
  14653. mips_small_data_threshold = (global_options_set.x_g_switch_value
  14654. ? g_switch_value
  14655. : MIPS_DEFAULT_GVALUE);
  14656. /* The following code determines the architecture and register size.
  14657. Similar code was added to GAS 2.14 (see tc-mips.c:md_after_parse_args()).
  14658. The GAS and GCC code should be kept in sync as much as possible. */
  14659. if (global_options_set.x_mips_arch_option)
  14660. mips_set_architecture (mips_cpu_info_from_opt (mips_arch_option));
  14661. if (mips_isa_option_info != 0)
  14662. {
  14663. if (mips_arch_info == 0)
  14664. mips_set_architecture (mips_isa_option_info);
  14665. else if (mips_arch_info->isa != mips_isa_option_info->isa)
  14666. error ("%<-%s%> conflicts with the other architecture options, "
  14667. "which specify a %s processor",
  14668. mips_isa_option_info->name,
  14669. mips_cpu_info_from_isa (mips_arch_info->isa)->name);
  14670. }
  14671. if (mips_arch_info == 0)
  14672. mips_set_architecture (mips_default_arch ());
  14673. if (ABI_NEEDS_64BIT_REGS && !ISA_HAS_64BIT_REGS)
  14674. error ("%<-march=%s%> is not compatible with the selected ABI",
  14675. mips_arch_info->name);
  14676. /* Optimize for mips_arch, unless -mtune selects a different processor. */
  14677. if (global_options_set.x_mips_tune_option)
  14678. mips_set_tune (mips_cpu_info_from_opt (mips_tune_option));
  14679. if (mips_tune_info == 0)
  14680. mips_set_tune (mips_arch_info);
  14681. if ((target_flags_explicit & MASK_64BIT) != 0)
  14682. {
  14683. /* The user specified the size of the integer registers. Make sure
  14684. it agrees with the ABI and ISA. */
  14685. if (TARGET_64BIT && !ISA_HAS_64BIT_REGS)
  14686. error ("%<-mgp64%> used with a 32-bit processor");
  14687. else if (!TARGET_64BIT && ABI_NEEDS_64BIT_REGS)
  14688. error ("%<-mgp32%> used with a 64-bit ABI");
  14689. else if (TARGET_64BIT && ABI_NEEDS_32BIT_REGS)
  14690. error ("%<-mgp64%> used with a 32-bit ABI");
  14691. }
  14692. else
  14693. {
  14694. /* Infer the integer register size from the ABI and processor.
  14695. Restrict ourselves to 32-bit registers if that's all the
  14696. processor has, or if the ABI cannot handle 64-bit registers. */
  14697. if (ABI_NEEDS_32BIT_REGS || !ISA_HAS_64BIT_REGS)
  14698. target_flags &= ~MASK_64BIT;
  14699. else
  14700. target_flags |= MASK_64BIT;
  14701. }
  14702. if ((target_flags_explicit & MASK_FLOAT64) != 0)
  14703. {
  14704. if (mips_isa_rev >= 6 && !TARGET_FLOAT64)
  14705. error ("the %qs architecture does not support %<-mfp32%>",
  14706. mips_arch_info->name);
  14707. else if (TARGET_SINGLE_FLOAT && TARGET_FLOAT64)
  14708. error ("unsupported combination: %s", "-mfp64 -msingle-float");
  14709. else if (TARGET_64BIT && TARGET_DOUBLE_FLOAT && !TARGET_FLOAT64)
  14710. error ("unsupported combination: %s", "-mgp64 -mfp32 -mdouble-float");
  14711. else if (!TARGET_64BIT && TARGET_FLOAT64)
  14712. {
  14713. if (!ISA_HAS_MXHC1)
  14714. error ("%<-mgp32%> and %<-mfp64%> can only be combined if"
  14715. " the target supports the mfhc1 and mthc1 instructions");
  14716. else if (mips_abi != ABI_32)
  14717. error ("%<-mgp32%> and %<-mfp64%> can only be combined when using"
  14718. " the o32 ABI");
  14719. }
  14720. }
  14721. else
  14722. {
  14723. /* -msingle-float selects 32-bit float registers. On r6 and later,
  14724. -mdouble-float selects 64-bit float registers, since the old paired
  14725. register model is not supported. In other cases the float registers
  14726. should be the same size as the integer ones. */
  14727. if (mips_isa_rev >= 6 && TARGET_DOUBLE_FLOAT && !TARGET_FLOATXX)
  14728. target_flags |= MASK_FLOAT64;
  14729. else if (TARGET_64BIT && TARGET_DOUBLE_FLOAT)
  14730. target_flags |= MASK_FLOAT64;
  14731. else
  14732. target_flags &= ~MASK_FLOAT64;
  14733. }
  14734. if (mips_abi != ABI_32 && TARGET_FLOATXX)
  14735. error ("%<-mfpxx%> can only be used with the o32 ABI");
  14736. else if (TARGET_FLOAT64 && TARGET_FLOATXX)
  14737. error ("unsupported combination: %s", "-mfp64 -mfpxx");
  14738. else if (ISA_MIPS1 && !TARGET_FLOAT32)
  14739. error ("%<-march=%s%> requires %<-mfp32%>", mips_arch_info->name);
  14740. else if (TARGET_FLOATXX && !mips_lra_flag)
  14741. error ("%<-mfpxx%> requires %<-mlra%>");
  14742. /* End of code shared with GAS. */
  14743. /* The R5900 FPU only supports single precision. */
  14744. if (TARGET_MIPS5900 && TARGET_HARD_FLOAT_ABI && TARGET_DOUBLE_FLOAT)
  14745. error ("unsupported combination: %s",
  14746. "-march=r5900 -mhard-float -mdouble-float");
  14747. /* If a -mlong* option was given, check that it matches the ABI,
  14748. otherwise infer the -mlong* setting from the other options. */
  14749. if ((target_flags_explicit & MASK_LONG64) != 0)
  14750. {
  14751. if (TARGET_LONG64)
  14752. {
  14753. if (mips_abi == ABI_N32)
  14754. error ("%qs is incompatible with %qs", "-mabi=n32", "-mlong64");
  14755. else if (mips_abi == ABI_32)
  14756. error ("%qs is incompatible with %qs", "-mabi=32", "-mlong64");
  14757. else if (mips_abi == ABI_O64 && TARGET_ABICALLS)
  14758. /* We have traditionally allowed non-abicalls code to use
  14759. an LP64 form of o64. However, it would take a bit more
  14760. effort to support the combination of 32-bit GOT entries
  14761. and 64-bit pointers, so we treat the abicalls case as
  14762. an error. */
  14763. error ("the combination of %qs and %qs is incompatible with %qs",
  14764. "-mabi=o64", "-mabicalls", "-mlong64");
  14765. }
  14766. else
  14767. {
  14768. if (mips_abi == ABI_64)
  14769. error ("%qs is incompatible with %qs", "-mabi=64", "-mlong32");
  14770. }
  14771. }
  14772. else
  14773. {
  14774. if ((mips_abi == ABI_EABI && TARGET_64BIT) || mips_abi == ABI_64)
  14775. target_flags |= MASK_LONG64;
  14776. else
  14777. target_flags &= ~MASK_LONG64;
  14778. }
  14779. if (!TARGET_OLDABI)
  14780. flag_pcc_struct_return = 0;
  14781. /* Decide which rtx_costs structure to use. */
  14782. if (optimize_size)
  14783. mips_cost = &mips_rtx_cost_optimize_size;
  14784. else
  14785. mips_cost = &mips_rtx_cost_data[mips_tune];
  14786. /* If the user hasn't specified a branch cost, use the processor's
  14787. default. */
  14788. if (mips_branch_cost == 0)
  14789. mips_branch_cost = mips_cost->branch_cost;
  14790. /* If neither -mbranch-likely nor -mno-branch-likely was given
  14791. on the command line, set MASK_BRANCHLIKELY based on the target
  14792. architecture and tuning flags. Annulled delay slots are a
  14793. size win, so we only consider the processor-specific tuning
  14794. for !optimize_size. */
  14795. if ((target_flags_explicit & MASK_BRANCHLIKELY) == 0)
  14796. {
  14797. if (ISA_HAS_BRANCHLIKELY
  14798. && (optimize_size
  14799. || (mips_tune_info->tune_flags & PTF_AVOID_BRANCHLIKELY) == 0))
  14800. target_flags |= MASK_BRANCHLIKELY;
  14801. else
  14802. target_flags &= ~MASK_BRANCHLIKELY;
  14803. }
  14804. else if (TARGET_BRANCHLIKELY && !ISA_HAS_BRANCHLIKELY)
  14805. warning (0, "the %qs architecture does not support branch-likely"
  14806. " instructions", mips_arch_info->name);
  14807. /* If the user hasn't specified -mimadd or -mno-imadd set
  14808. MASK_IMADD based on the target architecture and tuning
  14809. flags. */
  14810. if ((target_flags_explicit & MASK_IMADD) == 0)
  14811. {
  14812. if (ISA_HAS_MADD_MSUB &&
  14813. (mips_tune_info->tune_flags & PTF_AVOID_IMADD) == 0)
  14814. target_flags |= MASK_IMADD;
  14815. else
  14816. target_flags &= ~MASK_IMADD;
  14817. }
  14818. else if (TARGET_IMADD && !ISA_HAS_MADD_MSUB)
  14819. warning (0, "the %qs architecture does not support madd or msub"
  14820. " instructions", mips_arch_info->name);
  14821. /* If neither -modd-spreg nor -mno-odd-spreg was given on the command
  14822. line, set MASK_ODD_SPREG based on the ISA and ABI. */
  14823. if ((target_flags_explicit & MASK_ODD_SPREG) == 0)
  14824. {
  14825. /* Disable TARGET_ODD_SPREG when using the o32 FPXX ABI. */
  14826. if (!ISA_HAS_ODD_SPREG || TARGET_FLOATXX)
  14827. target_flags &= ~MASK_ODD_SPREG;
  14828. else
  14829. target_flags |= MASK_ODD_SPREG;
  14830. }
  14831. else if (TARGET_ODD_SPREG && !ISA_HAS_ODD_SPREG)
  14832. warning (0, "the %qs architecture does not support odd single-precision"
  14833. " registers", mips_arch_info->name);
  14834. if (!TARGET_ODD_SPREG && TARGET_64BIT)
  14835. {
  14836. error ("unsupported combination: %s", "-mgp64 -mno-odd-spreg");
  14837. /* Allow compilation to continue further even though invalid output
  14838. will be produced. */
  14839. target_flags |= MASK_ODD_SPREG;
  14840. }
  14841. /* The effect of -mabicalls isn't defined for the EABI. */
  14842. if (mips_abi == ABI_EABI && TARGET_ABICALLS)
  14843. {
  14844. error ("unsupported combination: %s", "-mabicalls -mabi=eabi");
  14845. target_flags &= ~MASK_ABICALLS;
  14846. }
  14847. /* PIC requires -mabicalls. */
  14848. if (flag_pic)
  14849. {
  14850. if (mips_abi == ABI_EABI)
  14851. error ("cannot generate position-independent code for %qs",
  14852. "-mabi=eabi");
  14853. else if (!TARGET_ABICALLS)
  14854. error ("position-independent code requires %qs", "-mabicalls");
  14855. }
  14856. if (TARGET_ABICALLS_PIC2)
  14857. /* We need to set flag_pic for executables as well as DSOs
  14858. because we may reference symbols that are not defined in
  14859. the final executable. (MIPS does not use things like
  14860. copy relocs, for example.)
  14861. There is a body of code that uses __PIC__ to distinguish
  14862. between -mabicalls and -mno-abicalls code. The non-__PIC__
  14863. variant is usually appropriate for TARGET_ABICALLS_PIC0, as
  14864. long as any indirect jumps use $25. */
  14865. flag_pic = 1;
  14866. /* -mvr4130-align is a "speed over size" optimization: it usually produces
  14867. faster code, but at the expense of more nops. Enable it at -O3 and
  14868. above. */
  14869. if (optimize > 2 && (target_flags_explicit & MASK_VR4130_ALIGN) == 0)
  14870. target_flags |= MASK_VR4130_ALIGN;
  14871. /* Prefer a call to memcpy over inline code when optimizing for size,
  14872. though see MOVE_RATIO in mips.h. */
  14873. if (optimize_size && (target_flags_explicit & MASK_MEMCPY) == 0)
  14874. target_flags |= MASK_MEMCPY;
  14875. /* If we have a nonzero small-data limit, check that the -mgpopt
  14876. setting is consistent with the other target flags. */
  14877. if (mips_small_data_threshold > 0)
  14878. {
  14879. if (!TARGET_GPOPT)
  14880. {
  14881. if (!TARGET_EXPLICIT_RELOCS)
  14882. error ("%<-mno-gpopt%> needs %<-mexplicit-relocs%>");
  14883. TARGET_LOCAL_SDATA = false;
  14884. TARGET_EXTERN_SDATA = false;
  14885. }
  14886. else
  14887. {
  14888. if (TARGET_VXWORKS_RTP)
  14889. warning (0, "cannot use small-data accesses for %qs", "-mrtp");
  14890. if (TARGET_ABICALLS)
  14891. warning (0, "cannot use small-data accesses for %qs",
  14892. "-mabicalls");
  14893. }
  14894. }
  14895. /* Set NaN and ABS defaults. */
  14896. if (mips_nan == MIPS_IEEE_754_DEFAULT && !ISA_HAS_IEEE_754_LEGACY)
  14897. mips_nan = MIPS_IEEE_754_2008;
  14898. if (mips_abs == MIPS_IEEE_754_DEFAULT && !ISA_HAS_IEEE_754_LEGACY)
  14899. mips_abs = MIPS_IEEE_754_2008;
  14900. /* Check for IEEE 754 legacy/2008 support. */
  14901. if ((mips_nan == MIPS_IEEE_754_LEGACY
  14902. || mips_abs == MIPS_IEEE_754_LEGACY)
  14903. && !ISA_HAS_IEEE_754_LEGACY)
  14904. warning (0, "the %qs architecture does not support %<-m%s=legacy%>",
  14905. mips_arch_info->name,
  14906. mips_nan == MIPS_IEEE_754_LEGACY ? "nan" : "abs");
  14907. if ((mips_nan == MIPS_IEEE_754_2008
  14908. || mips_abs == MIPS_IEEE_754_2008)
  14909. && !ISA_HAS_IEEE_754_2008)
  14910. warning (0, "the %qs architecture does not support %<-m%s=2008%>",
  14911. mips_arch_info->name,
  14912. mips_nan == MIPS_IEEE_754_2008 ? "nan" : "abs");
  14913. /* Pre-IEEE 754-2008 MIPS hardware has a quirky almost-IEEE format
  14914. for all its floating point. */
  14915. if (mips_nan != MIPS_IEEE_754_2008)
  14916. {
  14917. REAL_MODE_FORMAT (SFmode) = &mips_single_format;
  14918. REAL_MODE_FORMAT (DFmode) = &mips_double_format;
  14919. REAL_MODE_FORMAT (TFmode) = &mips_quad_format;
  14920. }
  14921. /* Make sure that the user didn't turn off paired single support when
  14922. MIPS-3D support is requested. */
  14923. if (TARGET_MIPS3D
  14924. && (target_flags_explicit & MASK_PAIRED_SINGLE_FLOAT)
  14925. && !TARGET_PAIRED_SINGLE_FLOAT)
  14926. error ("%<-mips3d%> requires %<-mpaired-single%>");
  14927. /* If TARGET_MIPS3D, enable MASK_PAIRED_SINGLE_FLOAT. */
  14928. if (TARGET_MIPS3D)
  14929. target_flags |= MASK_PAIRED_SINGLE_FLOAT;
  14930. /* Make sure that when TARGET_PAIRED_SINGLE_FLOAT is true, TARGET_FLOAT64
  14931. and TARGET_HARD_FLOAT_ABI are both true. */
  14932. if (TARGET_PAIRED_SINGLE_FLOAT && !(TARGET_FLOAT64 && TARGET_HARD_FLOAT_ABI))
  14933. {
  14934. error ("%qs must be used with %qs",
  14935. TARGET_MIPS3D ? "-mips3d" : "-mpaired-single",
  14936. TARGET_HARD_FLOAT_ABI ? "-mfp64" : "-mhard-float");
  14937. target_flags &= ~MASK_PAIRED_SINGLE_FLOAT;
  14938. TARGET_MIPS3D = 0;
  14939. }
  14940. /* Make sure that -mpaired-single is only used on ISAs that support it.
  14941. We must disable it otherwise since it relies on other ISA properties
  14942. like ISA_HAS_8CC having their normal values. */
  14943. if (TARGET_PAIRED_SINGLE_FLOAT && !ISA_HAS_PAIRED_SINGLE)
  14944. {
  14945. error ("the %qs architecture does not support paired-single"
  14946. " instructions", mips_arch_info->name);
  14947. target_flags &= ~MASK_PAIRED_SINGLE_FLOAT;
  14948. TARGET_MIPS3D = 0;
  14949. }
  14950. if (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE
  14951. && !TARGET_CACHE_BUILTIN)
  14952. {
  14953. error ("%qs requires a target that provides the %qs instruction",
  14954. "-mr10k-cache-barrier", "cache");
  14955. mips_r10k_cache_barrier = R10K_CACHE_BARRIER_NONE;
  14956. }
  14957. /* If TARGET_DSPR2, enable TARGET_DSP. */
  14958. if (TARGET_DSPR2)
  14959. TARGET_DSP = true;
  14960. if (TARGET_DSP && mips_isa_rev >= 6)
  14961. {
  14962. error ("the %qs architecture does not support DSP instructions",
  14963. mips_arch_info->name);
  14964. TARGET_DSP = false;
  14965. TARGET_DSPR2 = false;
  14966. }
  14967. /* .eh_frame addresses should be the same width as a C pointer.
  14968. Most MIPS ABIs support only one pointer size, so the assembler
  14969. will usually know exactly how big an .eh_frame address is.
  14970. Unfortunately, this is not true of the 64-bit EABI. The ABI was
  14971. originally defined to use 64-bit pointers (i.e. it is LP64), and
  14972. this is still the default mode. However, we also support an n32-like
  14973. ILP32 mode, which is selected by -mlong32. The problem is that the
  14974. assembler has traditionally not had an -mlong option, so it has
  14975. traditionally not known whether we're using the ILP32 or LP64 form.
  14976. As it happens, gas versions up to and including 2.19 use _32-bit_
  14977. addresses for EABI64 .cfi_* directives. This is wrong for the
  14978. default LP64 mode, so we can't use the directives by default.
  14979. Moreover, since gas's current behavior is at odds with gcc's
  14980. default behavior, it seems unwise to rely on future versions
  14981. of gas behaving the same way. We therefore avoid using .cfi
  14982. directives for -mlong32 as well. */
  14983. if (mips_abi == ABI_EABI && TARGET_64BIT)
  14984. flag_dwarf2_cfi_asm = 0;
  14985. /* .cfi_* directives generate a read-only section, so fall back on
  14986. manual .eh_frame creation if we need the section to be writable. */
  14987. if (TARGET_WRITABLE_EH_FRAME)
  14988. flag_dwarf2_cfi_asm = 0;
  14989. mips_init_print_operand_punct ();
  14990. /* Set up array to map GCC register number to debug register number.
  14991. Ignore the special purpose register numbers. */
  14992. for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  14993. {
  14994. mips_dbx_regno[i] = IGNORED_DWARF_REGNUM;
  14995. if (GP_REG_P (i) || FP_REG_P (i) || ALL_COP_REG_P (i))
  14996. mips_dwarf_regno[i] = i;
  14997. else
  14998. mips_dwarf_regno[i] = INVALID_REGNUM;
  14999. }
  15000. start = GP_DBX_FIRST - GP_REG_FIRST;
  15001. for (i = GP_REG_FIRST; i <= GP_REG_LAST; i++)
  15002. mips_dbx_regno[i] = i + start;
  15003. start = FP_DBX_FIRST - FP_REG_FIRST;
  15004. for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
  15005. mips_dbx_regno[i] = i + start;
  15006. /* Accumulator debug registers use big-endian ordering. */
  15007. mips_dbx_regno[HI_REGNUM] = MD_DBX_FIRST + 0;
  15008. mips_dbx_regno[LO_REGNUM] = MD_DBX_FIRST + 1;
  15009. mips_dwarf_regno[HI_REGNUM] = MD_REG_FIRST + 0;
  15010. mips_dwarf_regno[LO_REGNUM] = MD_REG_FIRST + 1;
  15011. for (i = DSP_ACC_REG_FIRST; i <= DSP_ACC_REG_LAST; i += 2)
  15012. {
  15013. mips_dwarf_regno[i + TARGET_LITTLE_ENDIAN] = i;
  15014. mips_dwarf_regno[i + TARGET_BIG_ENDIAN] = i + 1;
  15015. }
  15016. /* Set up mips_hard_regno_mode_ok. */
  15017. for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
  15018. for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  15019. mips_hard_regno_mode_ok[mode][regno]
  15020. = mips_hard_regno_mode_ok_p (regno, (machine_mode) mode);
  15021. /* Function to allocate machine-dependent function status. */
  15022. init_machine_status = &mips_init_machine_status;
  15023. /* Default to working around R4000 errata only if the processor
  15024. was selected explicitly. */
  15025. if ((target_flags_explicit & MASK_FIX_R4000) == 0
  15026. && strcmp (mips_arch_info->name, "r4000") == 0)
  15027. target_flags |= MASK_FIX_R4000;
  15028. /* Default to working around R4400 errata only if the processor
  15029. was selected explicitly. */
  15030. if ((target_flags_explicit & MASK_FIX_R4400) == 0
  15031. && strcmp (mips_arch_info->name, "r4400") == 0)
  15032. target_flags |= MASK_FIX_R4400;
  15033. /* Default to working around R10000 errata only if the processor
  15034. was selected explicitly. */
  15035. if ((target_flags_explicit & MASK_FIX_R10000) == 0
  15036. && strcmp (mips_arch_info->name, "r10000") == 0)
  15037. target_flags |= MASK_FIX_R10000;
  15038. /* Make sure that branch-likely instructions available when using
  15039. -mfix-r10000. The instructions are not available if either:
  15040. 1. -mno-branch-likely was passed.
  15041. 2. The selected ISA does not support branch-likely and
  15042. the command line does not include -mbranch-likely. */
  15043. if (TARGET_FIX_R10000
  15044. && ((target_flags_explicit & MASK_BRANCHLIKELY) == 0
  15045. ? !ISA_HAS_BRANCHLIKELY
  15046. : !TARGET_BRANCHLIKELY))
  15047. sorry ("%qs requires branch-likely instructions", "-mfix-r10000");
  15048. if (TARGET_SYNCI && !ISA_HAS_SYNCI)
  15049. {
  15050. warning (0, "the %qs architecture does not support the synci "
  15051. "instruction", mips_arch_info->name);
  15052. target_flags &= ~MASK_SYNCI;
  15053. }
  15054. /* Only optimize PIC indirect calls if they are actually required. */
  15055. if (!TARGET_USE_GOT || !TARGET_EXPLICIT_RELOCS)
  15056. target_flags &= ~MASK_RELAX_PIC_CALLS;
  15057. /* Save base state of options. */
  15058. mips_base_target_flags = target_flags;
  15059. mips_base_schedule_insns = flag_schedule_insns;
  15060. mips_base_reorder_blocks_and_partition = flag_reorder_blocks_and_partition;
  15061. mips_base_move_loop_invariants = flag_move_loop_invariants;
  15062. mips_base_align_loops = align_loops;
  15063. mips_base_align_jumps = align_jumps;
  15064. mips_base_align_functions = align_functions;
  15065. /* Now select the ISA mode.
  15066. Do all CPP-sensitive stuff in uncompressed mode; we'll switch modes
  15067. later if required. */
  15068. mips_set_compression_mode (0);
  15069. /* We register a second machine specific reorg pass after delay slot
  15070. filling. Registering the pass must be done at start up. It's
  15071. convenient to do it here. */
  15072. opt_pass *new_pass = make_pass_mips_machine_reorg2 (g);
  15073. struct register_pass_info insert_pass_mips_machine_reorg2 =
  15074. {
  15075. new_pass, /* pass */
  15076. "dbr", /* reference_pass_name */
  15077. 1, /* ref_pass_instance_number */
  15078. PASS_POS_INSERT_AFTER /* po_op */
  15079. };
  15080. register_pass (&insert_pass_mips_machine_reorg2);
  15081. if (TARGET_HARD_FLOAT_ABI && TARGET_MIPS5900)
  15082. REAL_MODE_FORMAT (SFmode) = &spu_single_format;
  15083. }
  15084. /* Swap the register information for registers I and I + 1, which
  15085. currently have the wrong endianness. Note that the registers'
  15086. fixedness and call-clobberedness might have been set on the
  15087. command line. */
  15088. static void
  15089. mips_swap_registers (unsigned int i)
  15090. {
  15091. int tmpi;
  15092. const char *tmps;
  15093. #define SWAP_INT(X, Y) (tmpi = (X), (X) = (Y), (Y) = tmpi)
  15094. #define SWAP_STRING(X, Y) (tmps = (X), (X) = (Y), (Y) = tmps)
  15095. SWAP_INT (fixed_regs[i], fixed_regs[i + 1]);
  15096. SWAP_INT (call_used_regs[i], call_used_regs[i + 1]);
  15097. SWAP_INT (call_really_used_regs[i], call_really_used_regs[i + 1]);
  15098. SWAP_STRING (reg_names[i], reg_names[i + 1]);
  15099. #undef SWAP_STRING
  15100. #undef SWAP_INT
  15101. }
  15102. /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
  15103. static void
  15104. mips_conditional_register_usage (void)
  15105. {
  15106. if (ISA_HAS_DSP)
  15107. {
  15108. /* These DSP control register fields are global. */
  15109. global_regs[CCDSP_PO_REGNUM] = 1;
  15110. global_regs[CCDSP_SC_REGNUM] = 1;
  15111. }
  15112. else
  15113. AND_COMPL_HARD_REG_SET (accessible_reg_set,
  15114. reg_class_contents[(int) DSP_ACC_REGS]);
  15115. if (!ISA_HAS_HILO)
  15116. AND_COMPL_HARD_REG_SET (accessible_reg_set,
  15117. reg_class_contents[(int) MD_REGS]);
  15118. if (!TARGET_HARD_FLOAT)
  15119. {
  15120. AND_COMPL_HARD_REG_SET (accessible_reg_set,
  15121. reg_class_contents[(int) FP_REGS]);
  15122. AND_COMPL_HARD_REG_SET (accessible_reg_set,
  15123. reg_class_contents[(int) ST_REGS]);
  15124. }
  15125. else if (!ISA_HAS_8CC)
  15126. {
  15127. /* We only have a single condition-code register. We implement
  15128. this by fixing all the condition-code registers and generating
  15129. RTL that refers directly to ST_REG_FIRST. */
  15130. AND_COMPL_HARD_REG_SET (accessible_reg_set,
  15131. reg_class_contents[(int) ST_REGS]);
  15132. if (!ISA_HAS_CCF)
  15133. SET_HARD_REG_BIT (accessible_reg_set, FPSW_REGNUM);
  15134. fixed_regs[FPSW_REGNUM] = call_used_regs[FPSW_REGNUM] = 1;
  15135. }
  15136. if (TARGET_MIPS16)
  15137. {
  15138. /* In MIPS16 mode, we prohibit the unused $s registers, since they
  15139. are call-saved, and saving them via a MIPS16 register would
  15140. probably waste more time than just reloading the value.
  15141. We permit the $t temporary registers when optimizing for speed
  15142. but not when optimizing for space because using them results in
  15143. code that is larger (but faster) then not using them. We do
  15144. allow $24 (t8) because it is used in CMP and CMPI instructions
  15145. and $25 (t9) because it is used as the function call address in
  15146. SVR4 PIC code. */
  15147. fixed_regs[18] = call_used_regs[18] = 1;
  15148. fixed_regs[19] = call_used_regs[19] = 1;
  15149. fixed_regs[20] = call_used_regs[20] = 1;
  15150. fixed_regs[21] = call_used_regs[21] = 1;
  15151. fixed_regs[22] = call_used_regs[22] = 1;
  15152. fixed_regs[23] = call_used_regs[23] = 1;
  15153. fixed_regs[26] = call_used_regs[26] = 1;
  15154. fixed_regs[27] = call_used_regs[27] = 1;
  15155. fixed_regs[30] = call_used_regs[30] = 1;
  15156. if (optimize_size)
  15157. {
  15158. fixed_regs[8] = call_used_regs[8] = 1;
  15159. fixed_regs[9] = call_used_regs[9] = 1;
  15160. fixed_regs[10] = call_used_regs[10] = 1;
  15161. fixed_regs[11] = call_used_regs[11] = 1;
  15162. fixed_regs[12] = call_used_regs[12] = 1;
  15163. fixed_regs[13] = call_used_regs[13] = 1;
  15164. fixed_regs[14] = call_used_regs[14] = 1;
  15165. fixed_regs[15] = call_used_regs[15] = 1;
  15166. }
  15167. /* Do not allow HI and LO to be treated as register operands.
  15168. There are no MTHI or MTLO instructions (or any real need
  15169. for them) and one-way registers cannot easily be reloaded. */
  15170. AND_COMPL_HARD_REG_SET (operand_reg_set,
  15171. reg_class_contents[(int) MD_REGS]);
  15172. }
  15173. /* $f20-$f23 are call-clobbered for n64. */
  15174. if (mips_abi == ABI_64)
  15175. {
  15176. int regno;
  15177. for (regno = FP_REG_FIRST + 20; regno < FP_REG_FIRST + 24; regno++)
  15178. call_really_used_regs[regno] = call_used_regs[regno] = 1;
  15179. }
  15180. /* Odd registers in the range $f21-$f31 (inclusive) are call-clobbered
  15181. for n32 and o32 FP64. */
  15182. if (mips_abi == ABI_N32
  15183. || (mips_abi == ABI_32
  15184. && TARGET_FLOAT64))
  15185. {
  15186. int regno;
  15187. for (regno = FP_REG_FIRST + 21; regno <= FP_REG_FIRST + 31; regno+=2)
  15188. call_really_used_regs[regno] = call_used_regs[regno] = 1;
  15189. }
  15190. /* Make sure that double-register accumulator values are correctly
  15191. ordered for the current endianness. */
  15192. if (TARGET_LITTLE_ENDIAN)
  15193. {
  15194. unsigned int regno;
  15195. mips_swap_registers (MD_REG_FIRST);
  15196. for (regno = DSP_ACC_REG_FIRST; regno <= DSP_ACC_REG_LAST; regno += 2)
  15197. mips_swap_registers (regno);
  15198. }
  15199. }
  15200. /* Implement EH_USES. */
  15201. bool
  15202. mips_eh_uses (unsigned int regno)
  15203. {
  15204. if (reload_completed && !TARGET_ABSOLUTE_JUMPS)
  15205. {
  15206. /* We need to force certain registers to be live in order to handle
  15207. PIC long branches correctly. See mips_must_initialize_gp_p for
  15208. details. */
  15209. if (mips_cfun_has_cprestore_slot_p ())
  15210. {
  15211. if (regno == CPRESTORE_SLOT_REGNUM)
  15212. return true;
  15213. }
  15214. else
  15215. {
  15216. if (cfun->machine->global_pointer == regno)
  15217. return true;
  15218. }
  15219. }
  15220. return false;
  15221. }
  15222. /* Implement EPILOGUE_USES. */
  15223. bool
  15224. mips_epilogue_uses (unsigned int regno)
  15225. {
  15226. /* Say that the epilogue uses the return address register. Note that
  15227. in the case of sibcalls, the values "used by the epilogue" are
  15228. considered live at the start of the called function. */
  15229. if (regno == RETURN_ADDR_REGNUM)
  15230. return true;
  15231. /* If using a GOT, say that the epilogue also uses GOT_VERSION_REGNUM.
  15232. See the comment above load_call<mode> for details. */
  15233. if (TARGET_USE_GOT && (regno) == GOT_VERSION_REGNUM)
  15234. return true;
  15235. /* An interrupt handler must preserve some registers that are
  15236. ordinarily call-clobbered. */
  15237. if (cfun->machine->interrupt_handler_p
  15238. && mips_interrupt_extra_call_saved_reg_p (regno))
  15239. return true;
  15240. return false;
  15241. }
  15242. /* Return true if INSN needs to be wrapped in ".set noat".
  15243. INSN has NOPERANDS operands, stored in OPVEC. */
  15244. static bool
  15245. mips_need_noat_wrapper_p (rtx_insn *insn, rtx *opvec, int noperands)
  15246. {
  15247. if (recog_memoized (insn) >= 0)
  15248. {
  15249. subrtx_iterator::array_type array;
  15250. for (int i = 0; i < noperands; i++)
  15251. FOR_EACH_SUBRTX (iter, array, opvec[i], NONCONST)
  15252. if (REG_P (*iter) && REGNO (*iter) == AT_REGNUM)
  15253. return true;
  15254. }
  15255. return false;
  15256. }
  15257. /* Implement FINAL_PRESCAN_INSN. */
  15258. void
  15259. mips_final_prescan_insn (rtx_insn *insn, rtx *opvec, int noperands)
  15260. {
  15261. if (mips_need_noat_wrapper_p (insn, opvec, noperands))
  15262. mips_push_asm_switch (&mips_noat);
  15263. }
  15264. /* Implement TARGET_ASM_FINAL_POSTSCAN_INSN. */
  15265. static void
  15266. mips_final_postscan_insn (FILE *file ATTRIBUTE_UNUSED, rtx_insn *insn,
  15267. rtx *opvec, int noperands)
  15268. {
  15269. if (mips_need_noat_wrapper_p (insn, opvec, noperands))
  15270. mips_pop_asm_switch (&mips_noat);
  15271. }
  15272. /* Return the function that is used to expand the <u>mulsidi3 pattern.
  15273. EXT_CODE is the code of the extension used. Return NULL if widening
  15274. multiplication shouldn't be used. */
  15275. mulsidi3_gen_fn
  15276. mips_mulsidi3_gen_fn (enum rtx_code ext_code)
  15277. {
  15278. bool signed_p;
  15279. signed_p = ext_code == SIGN_EXTEND;
  15280. if (TARGET_64BIT)
  15281. {
  15282. /* Don't use widening multiplication with MULT when we have DMUL. Even
  15283. with the extension of its input operands DMUL is faster. Note that
  15284. the extension is not needed for signed multiplication. In order to
  15285. ensure that we always remove the redundant sign-extension in this
  15286. case we still expand mulsidi3 for DMUL. */
  15287. if (ISA_HAS_R6DMUL)
  15288. return signed_p ? gen_mulsidi3_64bit_r6dmul : NULL;
  15289. if (ISA_HAS_DMUL3)
  15290. return signed_p ? gen_mulsidi3_64bit_dmul : NULL;
  15291. if (TARGET_MIPS16)
  15292. return (signed_p
  15293. ? gen_mulsidi3_64bit_mips16
  15294. : gen_umulsidi3_64bit_mips16);
  15295. if (TARGET_FIX_R4000)
  15296. return NULL;
  15297. return signed_p ? gen_mulsidi3_64bit : gen_umulsidi3_64bit;
  15298. }
  15299. else
  15300. {
  15301. if (ISA_HAS_R6MUL)
  15302. return (signed_p ? gen_mulsidi3_32bit_r6 : gen_umulsidi3_32bit_r6);
  15303. if (TARGET_MIPS16)
  15304. return (signed_p
  15305. ? gen_mulsidi3_32bit_mips16
  15306. : gen_umulsidi3_32bit_mips16);
  15307. if (TARGET_FIX_R4000 && !ISA_HAS_DSP)
  15308. return signed_p ? gen_mulsidi3_32bit_r4000 : gen_umulsidi3_32bit_r4000;
  15309. return signed_p ? gen_mulsidi3_32bit : gen_umulsidi3_32bit;
  15310. }
  15311. }
  15312. /* Return true if PATTERN matches the kind of instruction generated by
  15313. umips_build_save_restore. SAVE_P is true for store. */
  15314. bool
  15315. umips_save_restore_pattern_p (bool save_p, rtx pattern)
  15316. {
  15317. int n;
  15318. unsigned int i;
  15319. HOST_WIDE_INT first_offset = 0;
  15320. rtx first_base = 0;
  15321. unsigned int regmask = 0;
  15322. for (n = 0; n < XVECLEN (pattern, 0); n++)
  15323. {
  15324. rtx set, reg, mem, this_base;
  15325. HOST_WIDE_INT this_offset;
  15326. /* Check that we have a SET. */
  15327. set = XVECEXP (pattern, 0, n);
  15328. if (GET_CODE (set) != SET)
  15329. return false;
  15330. /* Check that the SET is a load (if restoring) or a store
  15331. (if saving). */
  15332. mem = save_p ? SET_DEST (set) : SET_SRC (set);
  15333. if (!MEM_P (mem) || MEM_VOLATILE_P (mem))
  15334. return false;
  15335. /* Check that the address is the sum of base and a possibly-zero
  15336. constant offset. Determine if the offset is in range. */
  15337. mips_split_plus (XEXP (mem, 0), &this_base, &this_offset);
  15338. if (!REG_P (this_base))
  15339. return false;
  15340. if (n == 0)
  15341. {
  15342. if (!UMIPS_12BIT_OFFSET_P (this_offset))
  15343. return false;
  15344. first_base = this_base;
  15345. first_offset = this_offset;
  15346. }
  15347. else
  15348. {
  15349. /* Check that the save slots are consecutive. */
  15350. if (REGNO (this_base) != REGNO (first_base)
  15351. || this_offset != first_offset + UNITS_PER_WORD * n)
  15352. return false;
  15353. }
  15354. /* Check that SET's other operand is a register. */
  15355. reg = save_p ? SET_SRC (set) : SET_DEST (set);
  15356. if (!REG_P (reg))
  15357. return false;
  15358. regmask |= 1 << REGNO (reg);
  15359. }
  15360. for (i = 0; i < ARRAY_SIZE (umips_swm_mask); i++)
  15361. if (regmask == umips_swm_mask[i])
  15362. return true;
  15363. return false;
  15364. }
  15365. /* Return the assembly instruction for microMIPS LWM or SWM.
  15366. SAVE_P and PATTERN are as for umips_save_restore_pattern_p. */
  15367. const char *
  15368. umips_output_save_restore (bool save_p, rtx pattern)
  15369. {
  15370. static char buffer[300];
  15371. char *s;
  15372. int n;
  15373. HOST_WIDE_INT offset;
  15374. rtx base, mem, set, last_set, last_reg;
  15375. /* Parse the pattern. */
  15376. gcc_assert (umips_save_restore_pattern_p (save_p, pattern));
  15377. s = strcpy (buffer, save_p ? "swm\t" : "lwm\t");
  15378. s += strlen (s);
  15379. n = XVECLEN (pattern, 0);
  15380. set = XVECEXP (pattern, 0, 0);
  15381. mem = save_p ? SET_DEST (set) : SET_SRC (set);
  15382. mips_split_plus (XEXP (mem, 0), &base, &offset);
  15383. last_set = XVECEXP (pattern, 0, n - 1);
  15384. last_reg = save_p ? SET_SRC (last_set) : SET_DEST (last_set);
  15385. if (REGNO (last_reg) == 31)
  15386. n--;
  15387. gcc_assert (n <= 9);
  15388. if (n == 0)
  15389. ;
  15390. else if (n == 1)
  15391. s += sprintf (s, "%s,", reg_names[16]);
  15392. else if (n < 9)
  15393. s += sprintf (s, "%s-%s,", reg_names[16], reg_names[15 + n]);
  15394. else if (n == 9)
  15395. s += sprintf (s, "%s-%s,%s,", reg_names[16], reg_names[23],
  15396. reg_names[30]);
  15397. if (REGNO (last_reg) == 31)
  15398. s += sprintf (s, "%s,", reg_names[31]);
  15399. s += sprintf (s, "%d(%s)", (int)offset, reg_names[REGNO (base)]);
  15400. return buffer;
  15401. }
  15402. /* Return true if MEM1 and MEM2 use the same base register, and the
  15403. offset of MEM2 equals the offset of MEM1 plus 4. FIRST_REG is the
  15404. register into (from) which the contents of MEM1 will be loaded
  15405. (stored), depending on the value of LOAD_P.
  15406. SWAP_P is true when the 1st and 2nd instructions are swapped. */
  15407. static bool
  15408. umips_load_store_pair_p_1 (bool load_p, bool swap_p,
  15409. rtx first_reg, rtx mem1, rtx mem2)
  15410. {
  15411. rtx base1, base2;
  15412. HOST_WIDE_INT offset1, offset2;
  15413. if (!MEM_P (mem1) || !MEM_P (mem2))
  15414. return false;
  15415. mips_split_plus (XEXP (mem1, 0), &base1, &offset1);
  15416. mips_split_plus (XEXP (mem2, 0), &base2, &offset2);
  15417. if (!REG_P (base1) || !rtx_equal_p (base1, base2))
  15418. return false;
  15419. /* Avoid invalid load pair instructions. */
  15420. if (load_p && REGNO (first_reg) == REGNO (base1))
  15421. return false;
  15422. /* We must avoid this case for anti-dependence.
  15423. Ex: lw $3, 4($3)
  15424. lw $2, 0($3)
  15425. first_reg is $2, but the base is $3. */
  15426. if (load_p
  15427. && swap_p
  15428. && REGNO (first_reg) + 1 == REGNO (base1))
  15429. return false;
  15430. if (offset2 != offset1 + 4)
  15431. return false;
  15432. if (!UMIPS_12BIT_OFFSET_P (offset1))
  15433. return false;
  15434. return true;
  15435. }
  15436. /* OPERANDS describes the operands to a pair of SETs, in the order
  15437. dest1, src1, dest2, src2. Return true if the operands can be used
  15438. in an LWP or SWP instruction; LOAD_P says which. */
  15439. bool
  15440. umips_load_store_pair_p (bool load_p, rtx *operands)
  15441. {
  15442. rtx reg1, reg2, mem1, mem2;
  15443. if (load_p)
  15444. {
  15445. reg1 = operands[0];
  15446. reg2 = operands[2];
  15447. mem1 = operands[1];
  15448. mem2 = operands[3];
  15449. }
  15450. else
  15451. {
  15452. reg1 = operands[1];
  15453. reg2 = operands[3];
  15454. mem1 = operands[0];
  15455. mem2 = operands[2];
  15456. }
  15457. if (REGNO (reg2) == REGNO (reg1) + 1)
  15458. return umips_load_store_pair_p_1 (load_p, false, reg1, mem1, mem2);
  15459. if (REGNO (reg1) == REGNO (reg2) + 1)
  15460. return umips_load_store_pair_p_1 (load_p, true, reg2, mem2, mem1);
  15461. return false;
  15462. }
  15463. /* Return the assembly instruction for a microMIPS LWP or SWP in which
  15464. the first register is REG and the first memory slot is MEM.
  15465. LOAD_P is true for LWP. */
  15466. static void
  15467. umips_output_load_store_pair_1 (bool load_p, rtx reg, rtx mem)
  15468. {
  15469. rtx ops[] = {reg, mem};
  15470. if (load_p)
  15471. output_asm_insn ("lwp\t%0,%1", ops);
  15472. else
  15473. output_asm_insn ("swp\t%0,%1", ops);
  15474. }
  15475. /* Output the assembly instruction for a microMIPS LWP or SWP instruction.
  15476. LOAD_P and OPERANDS are as for umips_load_store_pair_p. */
  15477. void
  15478. umips_output_load_store_pair (bool load_p, rtx *operands)
  15479. {
  15480. rtx reg1, reg2, mem1, mem2;
  15481. if (load_p)
  15482. {
  15483. reg1 = operands[0];
  15484. reg2 = operands[2];
  15485. mem1 = operands[1];
  15486. mem2 = operands[3];
  15487. }
  15488. else
  15489. {
  15490. reg1 = operands[1];
  15491. reg2 = operands[3];
  15492. mem1 = operands[0];
  15493. mem2 = operands[2];
  15494. }
  15495. if (REGNO (reg2) == REGNO (reg1) + 1)
  15496. {
  15497. umips_output_load_store_pair_1 (load_p, reg1, mem1);
  15498. return;
  15499. }
  15500. gcc_assert (REGNO (reg1) == REGNO (reg2) + 1);
  15501. umips_output_load_store_pair_1 (load_p, reg2, mem2);
  15502. }
  15503. /* Return true if REG1 and REG2 match the criteria for a movep insn. */
  15504. bool
  15505. umips_movep_target_p (rtx reg1, rtx reg2)
  15506. {
  15507. int regno1, regno2, pair;
  15508. unsigned int i;
  15509. static const int match[8] = {
  15510. 0x00000060, /* 5, 6 */
  15511. 0x000000a0, /* 5, 7 */
  15512. 0x000000c0, /* 6, 7 */
  15513. 0x00200010, /* 4, 21 */
  15514. 0x00400010, /* 4, 22 */
  15515. 0x00000030, /* 4, 5 */
  15516. 0x00000050, /* 4, 6 */
  15517. 0x00000090 /* 4, 7 */
  15518. };
  15519. if (!REG_P (reg1) || !REG_P (reg2))
  15520. return false;
  15521. regno1 = REGNO (reg1);
  15522. regno2 = REGNO (reg2);
  15523. if (!GP_REG_P (regno1) || !GP_REG_P (regno2))
  15524. return false;
  15525. pair = (1 << regno1) | (1 << regno2);
  15526. for (i = 0; i < ARRAY_SIZE (match); i++)
  15527. if (pair == match[i])
  15528. return true;
  15529. return false;
  15530. }
  15531. /* Return the size in bytes of the trampoline code, padded to
  15532. TRAMPOLINE_ALIGNMENT bits. The static chain pointer and target
  15533. function address immediately follow. */
  15534. int
  15535. mips_trampoline_code_size (void)
  15536. {
  15537. if (TARGET_USE_PIC_FN_ADDR_REG)
  15538. return 4 * 4;
  15539. else if (ptr_mode == DImode)
  15540. return 8 * 4;
  15541. else if (ISA_HAS_LOAD_DELAY)
  15542. return 6 * 4;
  15543. else
  15544. return 4 * 4;
  15545. }
  15546. /* Implement TARGET_TRAMPOLINE_INIT. */
  15547. static void
  15548. mips_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
  15549. {
  15550. rtx addr, end_addr, high, low, opcode, mem;
  15551. rtx trampoline[8];
  15552. unsigned int i, j;
  15553. HOST_WIDE_INT end_addr_offset, static_chain_offset, target_function_offset;
  15554. /* Work out the offsets of the pointers from the start of the
  15555. trampoline code. */
  15556. end_addr_offset = mips_trampoline_code_size ();
  15557. static_chain_offset = end_addr_offset;
  15558. target_function_offset = static_chain_offset + GET_MODE_SIZE (ptr_mode);
  15559. /* Get pointers to the beginning and end of the code block. */
  15560. addr = force_reg (Pmode, XEXP (m_tramp, 0));
  15561. end_addr = mips_force_binary (Pmode, PLUS, addr, GEN_INT (end_addr_offset));
  15562. #define OP(X) gen_int_mode (X, SImode)
  15563. /* Build up the code in TRAMPOLINE. */
  15564. i = 0;
  15565. if (TARGET_USE_PIC_FN_ADDR_REG)
  15566. {
  15567. /* $25 contains the address of the trampoline. Emit code of the form:
  15568. l[wd] $1, target_function_offset($25)
  15569. l[wd] $static_chain, static_chain_offset($25)
  15570. jr $1
  15571. move $25,$1. */
  15572. trampoline[i++] = OP (MIPS_LOAD_PTR (AT_REGNUM,
  15573. target_function_offset,
  15574. PIC_FUNCTION_ADDR_REGNUM));
  15575. trampoline[i++] = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM,
  15576. static_chain_offset,
  15577. PIC_FUNCTION_ADDR_REGNUM));
  15578. trampoline[i++] = OP (MIPS_JR (AT_REGNUM));
  15579. trampoline[i++] = OP (MIPS_MOVE (PIC_FUNCTION_ADDR_REGNUM, AT_REGNUM));
  15580. }
  15581. else if (ptr_mode == DImode)
  15582. {
  15583. /* It's too cumbersome to create the full 64-bit address, so let's
  15584. instead use:
  15585. move $1, $31
  15586. bal 1f
  15587. nop
  15588. 1: l[wd] $25, target_function_offset - 12($31)
  15589. l[wd] $static_chain, static_chain_offset - 12($31)
  15590. jr $25
  15591. move $31, $1
  15592. where 12 is the offset of "1:" from the start of the code block. */
  15593. trampoline[i++] = OP (MIPS_MOVE (AT_REGNUM, RETURN_ADDR_REGNUM));
  15594. trampoline[i++] = OP (MIPS_BAL (1));
  15595. trampoline[i++] = OP (MIPS_NOP);
  15596. trampoline[i++] = OP (MIPS_LOAD_PTR (PIC_FUNCTION_ADDR_REGNUM,
  15597. target_function_offset - 12,
  15598. RETURN_ADDR_REGNUM));
  15599. trampoline[i++] = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM,
  15600. static_chain_offset - 12,
  15601. RETURN_ADDR_REGNUM));
  15602. trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM));
  15603. trampoline[i++] = OP (MIPS_MOVE (RETURN_ADDR_REGNUM, AT_REGNUM));
  15604. }
  15605. else
  15606. {
  15607. /* If the target has load delays, emit:
  15608. lui $1, %hi(end_addr)
  15609. lw $25, %lo(end_addr + ...)($1)
  15610. lw $static_chain, %lo(end_addr + ...)($1)
  15611. jr $25
  15612. nop
  15613. Otherwise emit:
  15614. lui $1, %hi(end_addr)
  15615. lw $25, %lo(end_addr + ...)($1)
  15616. jr $25
  15617. lw $static_chain, %lo(end_addr + ...)($1). */
  15618. /* Split END_ADDR into %hi and %lo values. Trampolines are aligned
  15619. to 64 bits, so the %lo value will have the bottom 3 bits clear. */
  15620. high = expand_simple_binop (SImode, PLUS, end_addr, GEN_INT (0x8000),
  15621. NULL, false, OPTAB_WIDEN);
  15622. high = expand_simple_binop (SImode, LSHIFTRT, high, GEN_INT (16),
  15623. NULL, false, OPTAB_WIDEN);
  15624. low = convert_to_mode (SImode, gen_lowpart (HImode, end_addr), true);
  15625. /* Emit the LUI. */
  15626. opcode = OP (MIPS_LUI (AT_REGNUM, 0));
  15627. trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, high,
  15628. NULL, false, OPTAB_WIDEN);
  15629. /* Emit the load of the target function. */
  15630. opcode = OP (MIPS_LOAD_PTR (PIC_FUNCTION_ADDR_REGNUM,
  15631. target_function_offset - end_addr_offset,
  15632. AT_REGNUM));
  15633. trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low,
  15634. NULL, false, OPTAB_WIDEN);
  15635. /* Emit the JR here, if we can. */
  15636. if (!ISA_HAS_LOAD_DELAY)
  15637. trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM));
  15638. /* Emit the load of the static chain register. */
  15639. opcode = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM,
  15640. static_chain_offset - end_addr_offset,
  15641. AT_REGNUM));
  15642. trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low,
  15643. NULL, false, OPTAB_WIDEN);
  15644. /* Emit the JR, if we couldn't above. */
  15645. if (ISA_HAS_LOAD_DELAY)
  15646. {
  15647. trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM));
  15648. trampoline[i++] = OP (MIPS_NOP);
  15649. }
  15650. }
  15651. #undef OP
  15652. /* Copy the trampoline code. Leave any padding uninitialized. */
  15653. for (j = 0; j < i; j++)
  15654. {
  15655. mem = adjust_address (m_tramp, SImode, j * GET_MODE_SIZE (SImode));
  15656. mips_emit_move (mem, trampoline[j]);
  15657. }
  15658. /* Set up the static chain pointer field. */
  15659. mem = adjust_address (m_tramp, ptr_mode, static_chain_offset);
  15660. mips_emit_move (mem, chain_value);
  15661. /* Set up the target function field. */
  15662. mem = adjust_address (m_tramp, ptr_mode, target_function_offset);
  15663. mips_emit_move (mem, XEXP (DECL_RTL (fndecl), 0));
  15664. /* Flush the code part of the trampoline. */
  15665. emit_insn (gen_add3_insn (end_addr, addr, GEN_INT (TRAMPOLINE_SIZE)));
  15666. emit_insn (gen_clear_cache (addr, end_addr));
  15667. }
  15668. /* Implement FUNCTION_PROFILER. */
  15669. void mips_function_profiler (FILE *file)
  15670. {
  15671. if (TARGET_MIPS16)
  15672. sorry ("mips16 function profiling");
  15673. if (TARGET_LONG_CALLS)
  15674. {
  15675. /* For TARGET_LONG_CALLS use $3 for the address of _mcount. */
  15676. if (Pmode == DImode)
  15677. fprintf (file, "\tdla\t%s,_mcount\n", reg_names[3]);
  15678. else
  15679. fprintf (file, "\tla\t%s,_mcount\n", reg_names[3]);
  15680. }
  15681. mips_push_asm_switch (&mips_noat);
  15682. fprintf (file, "\tmove\t%s,%s\t\t# save current return address\n",
  15683. reg_names[AT_REGNUM], reg_names[RETURN_ADDR_REGNUM]);
  15684. /* _mcount treats $2 as the static chain register. */
  15685. if (cfun->static_chain_decl != NULL)
  15686. fprintf (file, "\tmove\t%s,%s\n", reg_names[2],
  15687. reg_names[STATIC_CHAIN_REGNUM]);
  15688. if (TARGET_MCOUNT_RA_ADDRESS)
  15689. {
  15690. /* If TARGET_MCOUNT_RA_ADDRESS load $12 with the address of the
  15691. ra save location. */
  15692. if (cfun->machine->frame.ra_fp_offset == 0)
  15693. /* ra not saved, pass zero. */
  15694. fprintf (file, "\tmove\t%s,%s\n", reg_names[12], reg_names[0]);
  15695. else
  15696. fprintf (file, "\t%s\t%s," HOST_WIDE_INT_PRINT_DEC "(%s)\n",
  15697. Pmode == DImode ? "dla" : "la", reg_names[12],
  15698. cfun->machine->frame.ra_fp_offset,
  15699. reg_names[STACK_POINTER_REGNUM]);
  15700. }
  15701. if (!TARGET_NEWABI)
  15702. fprintf (file,
  15703. "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from stack\n",
  15704. TARGET_64BIT ? "dsubu" : "subu",
  15705. reg_names[STACK_POINTER_REGNUM],
  15706. reg_names[STACK_POINTER_REGNUM],
  15707. Pmode == DImode ? 16 : 8);
  15708. if (TARGET_LONG_CALLS)
  15709. fprintf (file, "\tjalr\t%s\n", reg_names[3]);
  15710. else
  15711. fprintf (file, "\tjal\t_mcount\n");
  15712. mips_pop_asm_switch (&mips_noat);
  15713. /* _mcount treats $2 as the static chain register. */
  15714. if (cfun->static_chain_decl != NULL)
  15715. fprintf (file, "\tmove\t%s,%s\n", reg_names[STATIC_CHAIN_REGNUM],
  15716. reg_names[2]);
  15717. }
  15718. /* Implement TARGET_SHIFT_TRUNCATION_MASK. We want to keep the default
  15719. behaviour of TARGET_SHIFT_TRUNCATION_MASK for non-vector modes even
  15720. when TARGET_LOONGSON_VECTORS is true. */
  15721. static unsigned HOST_WIDE_INT
  15722. mips_shift_truncation_mask (machine_mode mode)
  15723. {
  15724. if (TARGET_LOONGSON_VECTORS && VECTOR_MODE_P (mode))
  15725. return 0;
  15726. return GET_MODE_BITSIZE (mode) - 1;
  15727. }
  15728. /* Implement TARGET_PREPARE_PCH_SAVE. */
  15729. static void
  15730. mips_prepare_pch_save (void)
  15731. {
  15732. /* We are called in a context where the current MIPS16 vs. non-MIPS16
  15733. setting should be irrelevant. The question then is: which setting
  15734. makes most sense at load time?
  15735. The PCH is loaded before the first token is read. We should never
  15736. have switched into MIPS16 mode by that point, and thus should not
  15737. have populated mips16_globals. Nor can we load the entire contents
  15738. of mips16_globals from the PCH file, because mips16_globals contains
  15739. a combination of GGC and non-GGC data.
  15740. There is therefore no point in trying save the GGC part of
  15741. mips16_globals to the PCH file, or to preserve MIPS16ness across
  15742. the PCH save and load. The loading compiler would not have access
  15743. to the non-GGC parts of mips16_globals (either from the PCH file,
  15744. or from a copy that the loading compiler generated itself) and would
  15745. have to call target_reinit anyway.
  15746. It therefore seems best to switch back to non-MIPS16 mode at
  15747. save time, and to ensure that mips16_globals remains null after
  15748. a PCH load. */
  15749. mips_set_compression_mode (0);
  15750. mips16_globals = 0;
  15751. }
  15752. /* Generate or test for an insn that supports a constant permutation. */
  15753. #define MAX_VECT_LEN 8
  15754. struct expand_vec_perm_d
  15755. {
  15756. rtx target, op0, op1;
  15757. unsigned char perm[MAX_VECT_LEN];
  15758. machine_mode vmode;
  15759. unsigned char nelt;
  15760. bool one_vector_p;
  15761. bool testing_p;
  15762. };
  15763. /* Construct (set target (vec_select op0 (parallel perm))) and
  15764. return true if that's a valid instruction in the active ISA. */
  15765. static bool
  15766. mips_expand_vselect (rtx target, rtx op0,
  15767. const unsigned char *perm, unsigned nelt)
  15768. {
  15769. rtx rperm[MAX_VECT_LEN], x;
  15770. rtx_insn *insn;
  15771. unsigned i;
  15772. for (i = 0; i < nelt; ++i)
  15773. rperm[i] = GEN_INT (perm[i]);
  15774. x = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, rperm));
  15775. x = gen_rtx_VEC_SELECT (GET_MODE (target), op0, x);
  15776. x = gen_rtx_SET (VOIDmode, target, x);
  15777. insn = emit_insn (x);
  15778. if (recog_memoized (insn) < 0)
  15779. {
  15780. remove_insn (insn);
  15781. return false;
  15782. }
  15783. return true;
  15784. }
  15785. /* Similar, but generate a vec_concat from op0 and op1 as well. */
  15786. static bool
  15787. mips_expand_vselect_vconcat (rtx target, rtx op0, rtx op1,
  15788. const unsigned char *perm, unsigned nelt)
  15789. {
  15790. machine_mode v2mode;
  15791. rtx x;
  15792. v2mode = GET_MODE_2XWIDER_MODE (GET_MODE (op0));
  15793. x = gen_rtx_VEC_CONCAT (v2mode, op0, op1);
  15794. return mips_expand_vselect (target, x, perm, nelt);
  15795. }
  15796. /* Recognize patterns for even-odd extraction. */
  15797. static bool
  15798. mips_expand_vpc_loongson_even_odd (struct expand_vec_perm_d *d)
  15799. {
  15800. unsigned i, odd, nelt = d->nelt;
  15801. rtx t0, t1, t2, t3;
  15802. if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS))
  15803. return false;
  15804. /* Even-odd for V2SI/V2SFmode is matched by interleave directly. */
  15805. if (nelt < 4)
  15806. return false;
  15807. odd = d->perm[0];
  15808. if (odd > 1)
  15809. return false;
  15810. for (i = 1; i < nelt; ++i)
  15811. if (d->perm[i] != i * 2 + odd)
  15812. return false;
  15813. if (d->testing_p)
  15814. return true;
  15815. /* We need 2*log2(N)-1 operations to achieve odd/even with interleave. */
  15816. t0 = gen_reg_rtx (d->vmode);
  15817. t1 = gen_reg_rtx (d->vmode);
  15818. switch (d->vmode)
  15819. {
  15820. case V4HImode:
  15821. emit_insn (gen_loongson_punpckhhw (t0, d->op0, d->op1));
  15822. emit_insn (gen_loongson_punpcklhw (t1, d->op0, d->op1));
  15823. if (odd)
  15824. emit_insn (gen_loongson_punpckhhw (d->target, t1, t0));
  15825. else
  15826. emit_insn (gen_loongson_punpcklhw (d->target, t1, t0));
  15827. break;
  15828. case V8QImode:
  15829. t2 = gen_reg_rtx (d->vmode);
  15830. t3 = gen_reg_rtx (d->vmode);
  15831. emit_insn (gen_loongson_punpckhbh (t0, d->op0, d->op1));
  15832. emit_insn (gen_loongson_punpcklbh (t1, d->op0, d->op1));
  15833. emit_insn (gen_loongson_punpckhbh (t2, t1, t0));
  15834. emit_insn (gen_loongson_punpcklbh (t3, t1, t0));
  15835. if (odd)
  15836. emit_insn (gen_loongson_punpckhbh (d->target, t3, t2));
  15837. else
  15838. emit_insn (gen_loongson_punpcklbh (d->target, t3, t2));
  15839. break;
  15840. default:
  15841. gcc_unreachable ();
  15842. }
  15843. return true;
  15844. }
  15845. /* Recognize patterns for the Loongson PSHUFH instruction. */
  15846. static bool
  15847. mips_expand_vpc_loongson_pshufh (struct expand_vec_perm_d *d)
  15848. {
  15849. unsigned i, mask;
  15850. rtx rmask;
  15851. if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS))
  15852. return false;
  15853. if (d->vmode != V4HImode)
  15854. return false;
  15855. if (d->testing_p)
  15856. return true;
  15857. /* Convert the selector into the packed 8-bit form for pshufh. */
  15858. /* Recall that loongson is little-endian only. No big-endian
  15859. adjustment required. */
  15860. for (i = mask = 0; i < 4; i++)
  15861. mask |= (d->perm[i] & 3) << (i * 2);
  15862. rmask = force_reg (SImode, GEN_INT (mask));
  15863. if (d->one_vector_p)
  15864. emit_insn (gen_loongson_pshufh (d->target, d->op0, rmask));
  15865. else
  15866. {
  15867. rtx t0, t1, x, merge, rmerge[4];
  15868. t0 = gen_reg_rtx (V4HImode);
  15869. t1 = gen_reg_rtx (V4HImode);
  15870. emit_insn (gen_loongson_pshufh (t1, d->op1, rmask));
  15871. emit_insn (gen_loongson_pshufh (t0, d->op0, rmask));
  15872. for (i = 0; i < 4; ++i)
  15873. rmerge[i] = (d->perm[i] & 4 ? constm1_rtx : const0_rtx);
  15874. merge = gen_rtx_CONST_VECTOR (V4HImode, gen_rtvec_v (4, rmerge));
  15875. merge = force_reg (V4HImode, merge);
  15876. x = gen_rtx_AND (V4HImode, merge, t1);
  15877. emit_insn (gen_rtx_SET (VOIDmode, t1, x));
  15878. x = gen_rtx_NOT (V4HImode, merge);
  15879. x = gen_rtx_AND (V4HImode, x, t0);
  15880. emit_insn (gen_rtx_SET (VOIDmode, t0, x));
  15881. x = gen_rtx_IOR (V4HImode, t0, t1);
  15882. emit_insn (gen_rtx_SET (VOIDmode, d->target, x));
  15883. }
  15884. return true;
  15885. }
  15886. /* Recognize broadcast patterns for the Loongson. */
  15887. static bool
  15888. mips_expand_vpc_loongson_bcast (struct expand_vec_perm_d *d)
  15889. {
  15890. unsigned i, elt;
  15891. rtx t0, t1;
  15892. if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS))
  15893. return false;
  15894. /* Note that we've already matched V2SI via punpck and V4HI via pshufh. */
  15895. if (d->vmode != V8QImode)
  15896. return false;
  15897. if (!d->one_vector_p)
  15898. return false;
  15899. elt = d->perm[0];
  15900. for (i = 1; i < 8; ++i)
  15901. if (d->perm[i] != elt)
  15902. return false;
  15903. if (d->testing_p)
  15904. return true;
  15905. /* With one interleave we put two of the desired element adjacent. */
  15906. t0 = gen_reg_rtx (V8QImode);
  15907. if (elt < 4)
  15908. emit_insn (gen_loongson_punpcklbh (t0, d->op0, d->op0));
  15909. else
  15910. emit_insn (gen_loongson_punpckhbh (t0, d->op0, d->op0));
  15911. /* Shuffle that one HImode element into all locations. */
  15912. elt &= 3;
  15913. elt *= 0x55;
  15914. t1 = gen_reg_rtx (V4HImode);
  15915. emit_insn (gen_loongson_pshufh (t1, gen_lowpart (V4HImode, t0),
  15916. force_reg (SImode, GEN_INT (elt))));
  15917. emit_move_insn (d->target, gen_lowpart (V8QImode, t1));
  15918. return true;
  15919. }
  15920. static bool
  15921. mips_expand_vec_perm_const_1 (struct expand_vec_perm_d *d)
  15922. {
  15923. unsigned int i, nelt = d->nelt;
  15924. unsigned char perm2[MAX_VECT_LEN];
  15925. if (d->one_vector_p)
  15926. {
  15927. /* Try interleave with alternating operands. */
  15928. memcpy (perm2, d->perm, sizeof(perm2));
  15929. for (i = 1; i < nelt; i += 2)
  15930. perm2[i] += nelt;
  15931. if (mips_expand_vselect_vconcat (d->target, d->op0, d->op1, perm2, nelt))
  15932. return true;
  15933. }
  15934. else
  15935. {
  15936. if (mips_expand_vselect_vconcat (d->target, d->op0, d->op1,
  15937. d->perm, nelt))
  15938. return true;
  15939. /* Try again with swapped operands. */
  15940. for (i = 0; i < nelt; ++i)
  15941. perm2[i] = (d->perm[i] + nelt) & (2 * nelt - 1);
  15942. if (mips_expand_vselect_vconcat (d->target, d->op1, d->op0, perm2, nelt))
  15943. return true;
  15944. }
  15945. if (mips_expand_vpc_loongson_even_odd (d))
  15946. return true;
  15947. if (mips_expand_vpc_loongson_pshufh (d))
  15948. return true;
  15949. if (mips_expand_vpc_loongson_bcast (d))
  15950. return true;
  15951. return false;
  15952. }
  15953. /* Expand a vec_perm_const pattern. */
  15954. bool
  15955. mips_expand_vec_perm_const (rtx operands[4])
  15956. {
  15957. struct expand_vec_perm_d d;
  15958. int i, nelt, which;
  15959. unsigned char orig_perm[MAX_VECT_LEN];
  15960. rtx sel;
  15961. bool ok;
  15962. d.target = operands[0];
  15963. d.op0 = operands[1];
  15964. d.op1 = operands[2];
  15965. sel = operands[3];
  15966. d.vmode = GET_MODE (d.target);
  15967. gcc_assert (VECTOR_MODE_P (d.vmode));
  15968. d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
  15969. d.testing_p = false;
  15970. for (i = which = 0; i < nelt; ++i)
  15971. {
  15972. rtx e = XVECEXP (sel, 0, i);
  15973. int ei = INTVAL (e) & (2 * nelt - 1);
  15974. which |= (ei < nelt ? 1 : 2);
  15975. orig_perm[i] = ei;
  15976. }
  15977. memcpy (d.perm, orig_perm, MAX_VECT_LEN);
  15978. switch (which)
  15979. {
  15980. default:
  15981. gcc_unreachable();
  15982. case 3:
  15983. d.one_vector_p = false;
  15984. if (!rtx_equal_p (d.op0, d.op1))
  15985. break;
  15986. /* FALLTHRU */
  15987. case 2:
  15988. for (i = 0; i < nelt; ++i)
  15989. d.perm[i] &= nelt - 1;
  15990. d.op0 = d.op1;
  15991. d.one_vector_p = true;
  15992. break;
  15993. case 1:
  15994. d.op1 = d.op0;
  15995. d.one_vector_p = true;
  15996. break;
  15997. }
  15998. ok = mips_expand_vec_perm_const_1 (&d);
  15999. /* If we were given a two-vector permutation which just happened to
  16000. have both input vectors equal, we folded this into a one-vector
  16001. permutation. There are several loongson patterns that are matched
  16002. via direct vec_select+vec_concat expansion, but we do not have
  16003. support in mips_expand_vec_perm_const_1 to guess the adjustment
  16004. that should be made for a single operand. Just try again with
  16005. the original permutation. */
  16006. if (!ok && which == 3)
  16007. {
  16008. d.op0 = operands[1];
  16009. d.op1 = operands[2];
  16010. d.one_vector_p = false;
  16011. memcpy (d.perm, orig_perm, MAX_VECT_LEN);
  16012. ok = mips_expand_vec_perm_const_1 (&d);
  16013. }
  16014. return ok;
  16015. }
  16016. /* Implement TARGET_VECTORIZE_VEC_PERM_CONST_OK. */
  16017. static bool
  16018. mips_vectorize_vec_perm_const_ok (machine_mode vmode,
  16019. const unsigned char *sel)
  16020. {
  16021. struct expand_vec_perm_d d;
  16022. unsigned int i, nelt, which;
  16023. bool ret;
  16024. d.vmode = vmode;
  16025. d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
  16026. d.testing_p = true;
  16027. memcpy (d.perm, sel, nelt);
  16028. /* Categorize the set of elements in the selector. */
  16029. for (i = which = 0; i < nelt; ++i)
  16030. {
  16031. unsigned char e = d.perm[i];
  16032. gcc_assert (e < 2 * nelt);
  16033. which |= (e < nelt ? 1 : 2);
  16034. }
  16035. /* For all elements from second vector, fold the elements to first. */
  16036. if (which == 2)
  16037. for (i = 0; i < nelt; ++i)
  16038. d.perm[i] -= nelt;
  16039. /* Check whether the mask can be applied to the vector type. */
  16040. d.one_vector_p = (which != 3);
  16041. d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1);
  16042. d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2);
  16043. if (!d.one_vector_p)
  16044. d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3);
  16045. start_sequence ();
  16046. ret = mips_expand_vec_perm_const_1 (&d);
  16047. end_sequence ();
  16048. return ret;
  16049. }
  16050. /* Expand an integral vector unpack operation. */
  16051. void
  16052. mips_expand_vec_unpack (rtx operands[2], bool unsigned_p, bool high_p)
  16053. {
  16054. machine_mode imode = GET_MODE (operands[1]);
  16055. rtx (*unpack) (rtx, rtx, rtx);
  16056. rtx (*cmpgt) (rtx, rtx, rtx);
  16057. rtx tmp, dest, zero;
  16058. switch (imode)
  16059. {
  16060. case V8QImode:
  16061. if (high_p)
  16062. unpack = gen_loongson_punpckhbh;
  16063. else
  16064. unpack = gen_loongson_punpcklbh;
  16065. cmpgt = gen_loongson_pcmpgtb;
  16066. break;
  16067. case V4HImode:
  16068. if (high_p)
  16069. unpack = gen_loongson_punpckhhw;
  16070. else
  16071. unpack = gen_loongson_punpcklhw;
  16072. cmpgt = gen_loongson_pcmpgth;
  16073. break;
  16074. default:
  16075. gcc_unreachable ();
  16076. }
  16077. zero = force_reg (imode, CONST0_RTX (imode));
  16078. if (unsigned_p)
  16079. tmp = zero;
  16080. else
  16081. {
  16082. tmp = gen_reg_rtx (imode);
  16083. emit_insn (cmpgt (tmp, zero, operands[1]));
  16084. }
  16085. dest = gen_reg_rtx (imode);
  16086. emit_insn (unpack (dest, operands[1], tmp));
  16087. emit_move_insn (operands[0], gen_lowpart (GET_MODE (operands[0]), dest));
  16088. }
  16089. /* A subroutine of mips_expand_vec_init, match constant vector elements. */
  16090. static inline bool
  16091. mips_constant_elt_p (rtx x)
  16092. {
  16093. return CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE;
  16094. }
  16095. /* A subroutine of mips_expand_vec_init, expand via broadcast. */
  16096. static void
  16097. mips_expand_vi_broadcast (machine_mode vmode, rtx target, rtx elt)
  16098. {
  16099. struct expand_vec_perm_d d;
  16100. rtx t1;
  16101. bool ok;
  16102. if (elt != const0_rtx)
  16103. elt = force_reg (GET_MODE_INNER (vmode), elt);
  16104. if (REG_P (elt))
  16105. elt = gen_lowpart (DImode, elt);
  16106. t1 = gen_reg_rtx (vmode);
  16107. switch (vmode)
  16108. {
  16109. case V8QImode:
  16110. emit_insn (gen_loongson_vec_init1_v8qi (t1, elt));
  16111. break;
  16112. case V4HImode:
  16113. emit_insn (gen_loongson_vec_init1_v4hi (t1, elt));
  16114. break;
  16115. default:
  16116. gcc_unreachable ();
  16117. }
  16118. memset (&d, 0, sizeof (d));
  16119. d.target = target;
  16120. d.op0 = t1;
  16121. d.op1 = t1;
  16122. d.vmode = vmode;
  16123. d.nelt = GET_MODE_NUNITS (vmode);
  16124. d.one_vector_p = true;
  16125. ok = mips_expand_vec_perm_const_1 (&d);
  16126. gcc_assert (ok);
  16127. }
  16128. /* A subroutine of mips_expand_vec_init, replacing all of the non-constant
  16129. elements of VALS with zeros, copy the constant vector to TARGET. */
  16130. static void
  16131. mips_expand_vi_constant (machine_mode vmode, unsigned nelt,
  16132. rtx target, rtx vals)
  16133. {
  16134. rtvec vec = shallow_copy_rtvec (XVEC (vals, 0));
  16135. unsigned i;
  16136. for (i = 0; i < nelt; ++i)
  16137. {
  16138. if (!mips_constant_elt_p (RTVEC_ELT (vec, i)))
  16139. RTVEC_ELT (vec, i) = const0_rtx;
  16140. }
  16141. emit_move_insn (target, gen_rtx_CONST_VECTOR (vmode, vec));
  16142. }
  16143. /* A subroutine of mips_expand_vec_init, expand via pinsrh. */
  16144. static void
  16145. mips_expand_vi_loongson_one_pinsrh (rtx target, rtx vals, unsigned one_var)
  16146. {
  16147. mips_expand_vi_constant (V4HImode, 4, target, vals);
  16148. emit_insn (gen_vec_setv4hi (target, target, XVECEXP (vals, 0, one_var),
  16149. GEN_INT (one_var)));
  16150. }
  16151. /* A subroutine of mips_expand_vec_init, expand anything via memory. */
  16152. static void
  16153. mips_expand_vi_general (machine_mode vmode, machine_mode imode,
  16154. unsigned nelt, unsigned nvar, rtx target, rtx vals)
  16155. {
  16156. rtx mem = assign_stack_temp (vmode, GET_MODE_SIZE (vmode));
  16157. unsigned int i, isize = GET_MODE_SIZE (imode);
  16158. if (nvar < nelt)
  16159. mips_expand_vi_constant (vmode, nelt, mem, vals);
  16160. for (i = 0; i < nelt; ++i)
  16161. {
  16162. rtx x = XVECEXP (vals, 0, i);
  16163. if (!mips_constant_elt_p (x))
  16164. emit_move_insn (adjust_address (mem, imode, i * isize), x);
  16165. }
  16166. emit_move_insn (target, mem);
  16167. }
  16168. /* Expand a vector initialization. */
  16169. void
  16170. mips_expand_vector_init (rtx target, rtx vals)
  16171. {
  16172. machine_mode vmode = GET_MODE (target);
  16173. machine_mode imode = GET_MODE_INNER (vmode);
  16174. unsigned i, nelt = GET_MODE_NUNITS (vmode);
  16175. unsigned nvar = 0, one_var = -1u;
  16176. bool all_same = true;
  16177. rtx x;
  16178. for (i = 0; i < nelt; ++i)
  16179. {
  16180. x = XVECEXP (vals, 0, i);
  16181. if (!mips_constant_elt_p (x))
  16182. nvar++, one_var = i;
  16183. if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
  16184. all_same = false;
  16185. }
  16186. /* Load constants from the pool, or whatever's handy. */
  16187. if (nvar == 0)
  16188. {
  16189. emit_move_insn (target, gen_rtx_CONST_VECTOR (vmode, XVEC (vals, 0)));
  16190. return;
  16191. }
  16192. /* For two-part initialization, always use CONCAT. */
  16193. if (nelt == 2)
  16194. {
  16195. rtx op0 = force_reg (imode, XVECEXP (vals, 0, 0));
  16196. rtx op1 = force_reg (imode, XVECEXP (vals, 0, 1));
  16197. x = gen_rtx_VEC_CONCAT (vmode, op0, op1);
  16198. emit_insn (gen_rtx_SET (VOIDmode, target, x));
  16199. return;
  16200. }
  16201. /* Loongson is the only cpu with vectors with more elements. */
  16202. gcc_assert (TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS);
  16203. /* If all values are identical, broadcast the value. */
  16204. if (all_same)
  16205. {
  16206. mips_expand_vi_broadcast (vmode, target, XVECEXP (vals, 0, 0));
  16207. return;
  16208. }
  16209. /* If we've only got one non-variable V4HImode, use PINSRH. */
  16210. if (nvar == 1 && vmode == V4HImode)
  16211. {
  16212. mips_expand_vi_loongson_one_pinsrh (target, vals, one_var);
  16213. return;
  16214. }
  16215. mips_expand_vi_general (vmode, imode, nelt, nvar, target, vals);
  16216. }
  16217. /* Expand a vector reduction. */
  16218. void
  16219. mips_expand_vec_reduc (rtx target, rtx in, rtx (*gen)(rtx, rtx, rtx))
  16220. {
  16221. machine_mode vmode = GET_MODE (in);
  16222. unsigned char perm2[2];
  16223. rtx last, next, fold, x;
  16224. bool ok;
  16225. last = in;
  16226. fold = gen_reg_rtx (vmode);
  16227. switch (vmode)
  16228. {
  16229. case V2SFmode:
  16230. /* Use PUL/PLU to produce { L, H } op { H, L }.
  16231. By reversing the pair order, rather than a pure interleave high,
  16232. we avoid erroneous exceptional conditions that we might otherwise
  16233. produce from the computation of H op H. */
  16234. perm2[0] = 1;
  16235. perm2[1] = 2;
  16236. ok = mips_expand_vselect_vconcat (fold, last, last, perm2, 2);
  16237. gcc_assert (ok);
  16238. break;
  16239. case V2SImode:
  16240. /* Use interleave to produce { H, L } op { H, H }. */
  16241. emit_insn (gen_loongson_punpckhwd (fold, last, last));
  16242. break;
  16243. case V4HImode:
  16244. /* Perform the first reduction with interleave,
  16245. and subsequent reductions with shifts. */
  16246. emit_insn (gen_loongson_punpckhwd_hi (fold, last, last));
  16247. next = gen_reg_rtx (vmode);
  16248. emit_insn (gen (next, last, fold));
  16249. last = next;
  16250. fold = gen_reg_rtx (vmode);
  16251. x = force_reg (SImode, GEN_INT (16));
  16252. emit_insn (gen_vec_shr_v4hi (fold, last, x));
  16253. break;
  16254. case V8QImode:
  16255. emit_insn (gen_loongson_punpckhwd_qi (fold, last, last));
  16256. next = gen_reg_rtx (vmode);
  16257. emit_insn (gen (next, last, fold));
  16258. last = next;
  16259. fold = gen_reg_rtx (vmode);
  16260. x = force_reg (SImode, GEN_INT (16));
  16261. emit_insn (gen_vec_shr_v8qi (fold, last, x));
  16262. next = gen_reg_rtx (vmode);
  16263. emit_insn (gen (next, last, fold));
  16264. last = next;
  16265. fold = gen_reg_rtx (vmode);
  16266. x = force_reg (SImode, GEN_INT (8));
  16267. emit_insn (gen_vec_shr_v8qi (fold, last, x));
  16268. break;
  16269. default:
  16270. gcc_unreachable ();
  16271. }
  16272. emit_insn (gen (target, last, fold));
  16273. }
  16274. /* Expand a vector minimum/maximum. */
  16275. void
  16276. mips_expand_vec_minmax (rtx target, rtx op0, rtx op1,
  16277. rtx (*cmp) (rtx, rtx, rtx), bool min_p)
  16278. {
  16279. machine_mode vmode = GET_MODE (target);
  16280. rtx tc, t0, t1, x;
  16281. tc = gen_reg_rtx (vmode);
  16282. t0 = gen_reg_rtx (vmode);
  16283. t1 = gen_reg_rtx (vmode);
  16284. /* op0 > op1 */
  16285. emit_insn (cmp (tc, op0, op1));
  16286. x = gen_rtx_AND (vmode, tc, (min_p ? op1 : op0));
  16287. emit_insn (gen_rtx_SET (VOIDmode, t0, x));
  16288. x = gen_rtx_NOT (vmode, tc);
  16289. x = gen_rtx_AND (vmode, x, (min_p ? op0 : op1));
  16290. emit_insn (gen_rtx_SET (VOIDmode, t1, x));
  16291. x = gen_rtx_IOR (vmode, t0, t1);
  16292. emit_insn (gen_rtx_SET (VOIDmode, target, x));
  16293. }
  16294. /* Implement HARD_REGNO_CALLER_SAVE_MODE. */
  16295. machine_mode
  16296. mips_hard_regno_caller_save_mode (unsigned int regno,
  16297. unsigned int nregs,
  16298. machine_mode mode)
  16299. {
  16300. /* For performance, avoid saving/restoring upper parts of a register
  16301. by returning MODE as save mode when the mode is known. */
  16302. if (mode == VOIDmode)
  16303. return choose_hard_reg_mode (regno, nregs, false);
  16304. else
  16305. return mode;
  16306. }
  16307. /* Implement TARGET_CASE_VALUES_THRESHOLD. */
  16308. unsigned int
  16309. mips_case_values_threshold (void)
  16310. {
  16311. /* In MIPS16 mode using a larger case threshold generates smaller code. */
  16312. if (TARGET_MIPS16 && optimize_size)
  16313. return 10;
  16314. else
  16315. return default_case_values_threshold ();
  16316. }
  16317. /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */
  16318. static void
  16319. mips_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
  16320. {
  16321. if (!TARGET_HARD_FLOAT_ABI)
  16322. return;
  16323. tree exceptions_var = create_tmp_var (MIPS_ATYPE_USI);
  16324. tree fcsr_orig_var = create_tmp_var (MIPS_ATYPE_USI);
  16325. tree fcsr_mod_var = create_tmp_var (MIPS_ATYPE_USI);
  16326. tree get_fcsr = mips_builtin_decls[MIPS_GET_FCSR];
  16327. tree set_fcsr = mips_builtin_decls[MIPS_SET_FCSR];
  16328. tree get_fcsr_hold_call = build_call_expr (get_fcsr, 0);
  16329. tree hold_assign_orig = build2 (MODIFY_EXPR, MIPS_ATYPE_USI,
  16330. fcsr_orig_var, get_fcsr_hold_call);
  16331. tree hold_mod_val = build2 (BIT_AND_EXPR, MIPS_ATYPE_USI, fcsr_orig_var,
  16332. build_int_cst (MIPS_ATYPE_USI, 0xfffff003));
  16333. tree hold_assign_mod = build2 (MODIFY_EXPR, MIPS_ATYPE_USI,
  16334. fcsr_mod_var, hold_mod_val);
  16335. tree set_fcsr_hold_call = build_call_expr (set_fcsr, 1, fcsr_mod_var);
  16336. tree hold_all = build2 (COMPOUND_EXPR, MIPS_ATYPE_USI,
  16337. hold_assign_orig, hold_assign_mod);
  16338. *hold = build2 (COMPOUND_EXPR, void_type_node, hold_all,
  16339. set_fcsr_hold_call);
  16340. *clear = build_call_expr (set_fcsr, 1, fcsr_mod_var);
  16341. tree get_fcsr_update_call = build_call_expr (get_fcsr, 0);
  16342. *update = build2 (MODIFY_EXPR, MIPS_ATYPE_USI,
  16343. exceptions_var, get_fcsr_update_call);
  16344. tree set_fcsr_update_call = build_call_expr (set_fcsr, 1, fcsr_orig_var);
  16345. *update = build2 (COMPOUND_EXPR, void_type_node, *update,
  16346. set_fcsr_update_call);
  16347. tree atomic_feraiseexcept
  16348. = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
  16349. tree int_exceptions_var = fold_convert (integer_type_node,
  16350. exceptions_var);
  16351. tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
  16352. 1, int_exceptions_var);
  16353. *update = build2 (COMPOUND_EXPR, void_type_node, *update,
  16354. atomic_feraiseexcept_call);
  16355. }
  16356. /* Implement TARGET_SPILL_CLASS. */
  16357. static reg_class_t
  16358. mips_spill_class (reg_class_t rclass ATTRIBUTE_UNUSED,
  16359. machine_mode mode ATTRIBUTE_UNUSED)
  16360. {
  16361. if (TARGET_MIPS16)
  16362. return SPILL_REGS;
  16363. return NO_REGS;
  16364. }
  16365. /* Implement TARGET_LRA_P. */
  16366. static bool
  16367. mips_lra_p (void)
  16368. {
  16369. return mips_lra_flag;
  16370. }
  16371. /* Initialize the GCC target structure. */
  16372. #undef TARGET_ASM_ALIGNED_HI_OP
  16373. #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
  16374. #undef TARGET_ASM_ALIGNED_SI_OP
  16375. #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
  16376. #undef TARGET_ASM_ALIGNED_DI_OP
  16377. #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
  16378. #undef TARGET_OPTION_OVERRIDE
  16379. #define TARGET_OPTION_OVERRIDE mips_option_override
  16380. #undef TARGET_LEGITIMIZE_ADDRESS
  16381. #define TARGET_LEGITIMIZE_ADDRESS mips_legitimize_address
  16382. #undef TARGET_ASM_FUNCTION_PROLOGUE
  16383. #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
  16384. #undef TARGET_ASM_FUNCTION_EPILOGUE
  16385. #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
  16386. #undef TARGET_ASM_SELECT_RTX_SECTION
  16387. #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
  16388. #undef TARGET_ASM_FUNCTION_RODATA_SECTION
  16389. #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section
  16390. #undef TARGET_SCHED_INIT
  16391. #define TARGET_SCHED_INIT mips_sched_init
  16392. #undef TARGET_SCHED_REORDER
  16393. #define TARGET_SCHED_REORDER mips_sched_reorder
  16394. #undef TARGET_SCHED_REORDER2
  16395. #define TARGET_SCHED_REORDER2 mips_sched_reorder2
  16396. #undef TARGET_SCHED_VARIABLE_ISSUE
  16397. #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue
  16398. #undef TARGET_SCHED_ADJUST_COST
  16399. #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
  16400. #undef TARGET_SCHED_ISSUE_RATE
  16401. #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
  16402. #undef TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN
  16403. #define TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN mips_init_dfa_post_cycle_insn
  16404. #undef TARGET_SCHED_DFA_POST_ADVANCE_CYCLE
  16405. #define TARGET_SCHED_DFA_POST_ADVANCE_CYCLE mips_dfa_post_advance_cycle
  16406. #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
  16407. #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
  16408. mips_multipass_dfa_lookahead
  16409. #undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P
  16410. #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P \
  16411. mips_small_register_classes_for_mode_p
  16412. #undef TARGET_FUNCTION_OK_FOR_SIBCALL
  16413. #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
  16414. #undef TARGET_INSERT_ATTRIBUTES
  16415. #define TARGET_INSERT_ATTRIBUTES mips_insert_attributes
  16416. #undef TARGET_MERGE_DECL_ATTRIBUTES
  16417. #define TARGET_MERGE_DECL_ATTRIBUTES mips_merge_decl_attributes
  16418. #undef TARGET_CAN_INLINE_P
  16419. #define TARGET_CAN_INLINE_P mips_can_inline_p
  16420. #undef TARGET_SET_CURRENT_FUNCTION
  16421. #define TARGET_SET_CURRENT_FUNCTION mips_set_current_function
  16422. #undef TARGET_VALID_POINTER_MODE
  16423. #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
  16424. #undef TARGET_REGISTER_MOVE_COST
  16425. #define TARGET_REGISTER_MOVE_COST mips_register_move_cost
  16426. #undef TARGET_REGISTER_PRIORITY
  16427. #define TARGET_REGISTER_PRIORITY mips_register_priority
  16428. #undef TARGET_MEMORY_MOVE_COST
  16429. #define TARGET_MEMORY_MOVE_COST mips_memory_move_cost
  16430. #undef TARGET_RTX_COSTS
  16431. #define TARGET_RTX_COSTS mips_rtx_costs
  16432. #undef TARGET_ADDRESS_COST
  16433. #define TARGET_ADDRESS_COST mips_address_cost
  16434. #undef TARGET_IN_SMALL_DATA_P
  16435. #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
  16436. #undef TARGET_MACHINE_DEPENDENT_REORG
  16437. #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
  16438. #undef TARGET_PREFERRED_RELOAD_CLASS
  16439. #define TARGET_PREFERRED_RELOAD_CLASS mips_preferred_reload_class
  16440. #undef TARGET_EXPAND_TO_RTL_HOOK
  16441. #define TARGET_EXPAND_TO_RTL_HOOK mips_expand_to_rtl_hook
  16442. #undef TARGET_ASM_FILE_START
  16443. #define TARGET_ASM_FILE_START mips_file_start
  16444. #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
  16445. #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
  16446. #undef TARGET_ASM_CODE_END
  16447. #define TARGET_ASM_CODE_END mips_code_end
  16448. #undef TARGET_INIT_LIBFUNCS
  16449. #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
  16450. #undef TARGET_BUILD_BUILTIN_VA_LIST
  16451. #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
  16452. #undef TARGET_EXPAND_BUILTIN_VA_START
  16453. #define TARGET_EXPAND_BUILTIN_VA_START mips_va_start
  16454. #undef TARGET_GIMPLIFY_VA_ARG_EXPR
  16455. #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr
  16456. #undef TARGET_PROMOTE_FUNCTION_MODE
  16457. #define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote
  16458. #undef TARGET_PROMOTE_PROTOTYPES
  16459. #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
  16460. #undef TARGET_FUNCTION_VALUE
  16461. #define TARGET_FUNCTION_VALUE mips_function_value
  16462. #undef TARGET_LIBCALL_VALUE
  16463. #define TARGET_LIBCALL_VALUE mips_libcall_value
  16464. #undef TARGET_FUNCTION_VALUE_REGNO_P
  16465. #define TARGET_FUNCTION_VALUE_REGNO_P mips_function_value_regno_p
  16466. #undef TARGET_RETURN_IN_MEMORY
  16467. #define TARGET_RETURN_IN_MEMORY mips_return_in_memory
  16468. #undef TARGET_RETURN_IN_MSB
  16469. #define TARGET_RETURN_IN_MSB mips_return_in_msb
  16470. #undef TARGET_ASM_OUTPUT_MI_THUNK
  16471. #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk
  16472. #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
  16473. #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
  16474. #undef TARGET_PRINT_OPERAND
  16475. #define TARGET_PRINT_OPERAND mips_print_operand
  16476. #undef TARGET_PRINT_OPERAND_ADDRESS
  16477. #define TARGET_PRINT_OPERAND_ADDRESS mips_print_operand_address
  16478. #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
  16479. #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mips_print_operand_punct_valid_p
  16480. #undef TARGET_SETUP_INCOMING_VARARGS
  16481. #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs
  16482. #undef TARGET_STRICT_ARGUMENT_NAMING
  16483. #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming
  16484. #undef TARGET_MUST_PASS_IN_STACK
  16485. #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
  16486. #undef TARGET_PASS_BY_REFERENCE
  16487. #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference
  16488. #undef TARGET_CALLEE_COPIES
  16489. #define TARGET_CALLEE_COPIES mips_callee_copies
  16490. #undef TARGET_ARG_PARTIAL_BYTES
  16491. #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes
  16492. #undef TARGET_FUNCTION_ARG
  16493. #define TARGET_FUNCTION_ARG mips_function_arg
  16494. #undef TARGET_FUNCTION_ARG_ADVANCE
  16495. #define TARGET_FUNCTION_ARG_ADVANCE mips_function_arg_advance
  16496. #undef TARGET_FUNCTION_ARG_BOUNDARY
  16497. #define TARGET_FUNCTION_ARG_BOUNDARY mips_function_arg_boundary
  16498. #undef TARGET_GET_RAW_RESULT_MODE
  16499. #define TARGET_GET_RAW_RESULT_MODE mips_get_reg_raw_mode
  16500. #undef TARGET_GET_RAW_ARG_MODE
  16501. #define TARGET_GET_RAW_ARG_MODE mips_get_reg_raw_mode
  16502. #undef TARGET_MODE_REP_EXTENDED
  16503. #define TARGET_MODE_REP_EXTENDED mips_mode_rep_extended
  16504. #undef TARGET_VECTOR_MODE_SUPPORTED_P
  16505. #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p
  16506. #undef TARGET_SCALAR_MODE_SUPPORTED_P
  16507. #define TARGET_SCALAR_MODE_SUPPORTED_P mips_scalar_mode_supported_p
  16508. #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
  16509. #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE mips_preferred_simd_mode
  16510. #undef TARGET_INIT_BUILTINS
  16511. #define TARGET_INIT_BUILTINS mips_init_builtins
  16512. #undef TARGET_BUILTIN_DECL
  16513. #define TARGET_BUILTIN_DECL mips_builtin_decl
  16514. #undef TARGET_EXPAND_BUILTIN
  16515. #define TARGET_EXPAND_BUILTIN mips_expand_builtin
  16516. #undef TARGET_HAVE_TLS
  16517. #define TARGET_HAVE_TLS HAVE_AS_TLS
  16518. #undef TARGET_CANNOT_FORCE_CONST_MEM
  16519. #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
  16520. #undef TARGET_LEGITIMATE_CONSTANT_P
  16521. #define TARGET_LEGITIMATE_CONSTANT_P mips_legitimate_constant_p
  16522. #undef TARGET_ENCODE_SECTION_INFO
  16523. #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
  16524. #undef TARGET_ATTRIBUTE_TABLE
  16525. #define TARGET_ATTRIBUTE_TABLE mips_attribute_table
  16526. /* All our function attributes are related to how out-of-line copies should
  16527. be compiled or called. They don't in themselves prevent inlining. */
  16528. #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
  16529. #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
  16530. #undef TARGET_EXTRA_LIVE_ON_ENTRY
  16531. #define TARGET_EXTRA_LIVE_ON_ENTRY mips_extra_live_on_entry
  16532. #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
  16533. #define TARGET_USE_BLOCKS_FOR_CONSTANT_P mips_use_blocks_for_constant_p
  16534. #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
  16535. #define TARGET_USE_ANCHORS_FOR_SYMBOL_P mips_use_anchors_for_symbol_p
  16536. #undef TARGET_COMP_TYPE_ATTRIBUTES
  16537. #define TARGET_COMP_TYPE_ATTRIBUTES mips_comp_type_attributes
  16538. #ifdef HAVE_AS_DTPRELWORD
  16539. #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
  16540. #define TARGET_ASM_OUTPUT_DWARF_DTPREL mips_output_dwarf_dtprel
  16541. #endif
  16542. #undef TARGET_DWARF_REGISTER_SPAN
  16543. #define TARGET_DWARF_REGISTER_SPAN mips_dwarf_register_span
  16544. #undef TARGET_DWARF_FRAME_REG_MODE
  16545. #define TARGET_DWARF_FRAME_REG_MODE mips_dwarf_frame_reg_mode
  16546. #undef TARGET_ASM_FINAL_POSTSCAN_INSN
  16547. #define TARGET_ASM_FINAL_POSTSCAN_INSN mips_final_postscan_insn
  16548. #undef TARGET_LEGITIMATE_ADDRESS_P
  16549. #define TARGET_LEGITIMATE_ADDRESS_P mips_legitimate_address_p
  16550. #undef TARGET_FRAME_POINTER_REQUIRED
  16551. #define TARGET_FRAME_POINTER_REQUIRED mips_frame_pointer_required
  16552. #undef TARGET_CAN_ELIMINATE
  16553. #define TARGET_CAN_ELIMINATE mips_can_eliminate
  16554. #undef TARGET_CONDITIONAL_REGISTER_USAGE
  16555. #define TARGET_CONDITIONAL_REGISTER_USAGE mips_conditional_register_usage
  16556. #undef TARGET_TRAMPOLINE_INIT
  16557. #define TARGET_TRAMPOLINE_INIT mips_trampoline_init
  16558. #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
  16559. #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mips_output_filename
  16560. #undef TARGET_SHIFT_TRUNCATION_MASK
  16561. #define TARGET_SHIFT_TRUNCATION_MASK mips_shift_truncation_mask
  16562. #undef TARGET_PREPARE_PCH_SAVE
  16563. #define TARGET_PREPARE_PCH_SAVE mips_prepare_pch_save
  16564. #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
  16565. #define TARGET_VECTORIZE_VEC_PERM_CONST_OK mips_vectorize_vec_perm_const_ok
  16566. #undef TARGET_CASE_VALUES_THRESHOLD
  16567. #define TARGET_CASE_VALUES_THRESHOLD mips_case_values_threshold
  16568. #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
  16569. #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV mips_atomic_assign_expand_fenv
  16570. #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
  16571. #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
  16572. #undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
  16573. #define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
  16574. mips_use_by_pieces_infrastructure_p
  16575. #undef TARGET_SPILL_CLASS
  16576. #define TARGET_SPILL_CLASS mips_spill_class
  16577. #undef TARGET_LRA_P
  16578. #define TARGET_LRA_P mips_lra_p
  16579. struct gcc_target targetm = TARGET_INITIALIZER;
  16580. #include "gt-mips.h"