aarch64.c 305 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471
  1. /* Machine description for AArch64 architecture.
  2. Copyright (C) 2009-2015 Free Software Foundation, Inc.
  3. Contributed by ARM Ltd.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "tm.h"
  20. #include "insn-codes.h"
  21. #include "rtl.h"
  22. #include "insn-attr.h"
  23. #include "hash-set.h"
  24. #include "machmode.h"
  25. #include "vec.h"
  26. #include "double-int.h"
  27. #include "input.h"
  28. #include "alias.h"
  29. #include "symtab.h"
  30. #include "wide-int.h"
  31. #include "inchash.h"
  32. #include "tree.h"
  33. #include "fold-const.h"
  34. #include "stringpool.h"
  35. #include "stor-layout.h"
  36. #include "calls.h"
  37. #include "varasm.h"
  38. #include "regs.h"
  39. #include "dominance.h"
  40. #include "cfg.h"
  41. #include "cfgrtl.h"
  42. #include "cfganal.h"
  43. #include "lcm.h"
  44. #include "cfgbuild.h"
  45. #include "cfgcleanup.h"
  46. #include "predict.h"
  47. #include "basic-block.h"
  48. #include "df.h"
  49. #include "hard-reg-set.h"
  50. #include "output.h"
  51. #include "hashtab.h"
  52. #include "function.h"
  53. #include "flags.h"
  54. #include "statistics.h"
  55. #include "real.h"
  56. #include "fixed-value.h"
  57. #include "insn-config.h"
  58. #include "expmed.h"
  59. #include "dojump.h"
  60. #include "explow.h"
  61. #include "emit-rtl.h"
  62. #include "stmt.h"
  63. #include "expr.h"
  64. #include "reload.h"
  65. #include "toplev.h"
  66. #include "target.h"
  67. #include "target-def.h"
  68. #include "targhooks.h"
  69. #include "ggc.h"
  70. #include "tm_p.h"
  71. #include "recog.h"
  72. #include "langhooks.h"
  73. #include "diagnostic-core.h"
  74. #include "hash-table.h"
  75. #include "tree-ssa-alias.h"
  76. #include "internal-fn.h"
  77. #include "gimple-fold.h"
  78. #include "tree-eh.h"
  79. #include "gimple-expr.h"
  80. #include "is-a.h"
  81. #include "gimple.h"
  82. #include "gimplify.h"
  83. #include "optabs.h"
  84. #include "dwarf2.h"
  85. #include "cfgloop.h"
  86. #include "tree-vectorizer.h"
  87. #include "aarch64-cost-tables.h"
  88. #include "dumpfile.h"
  89. #include "builtins.h"
  90. #include "rtl-iter.h"
  91. #include "tm-constrs.h"
  92. #include "sched-int.h"
  93. /* Defined for convenience. */
  94. #define POINTER_BYTES (POINTER_SIZE / BITS_PER_UNIT)
  95. /* Classifies an address.
  96. ADDRESS_REG_IMM
  97. A simple base register plus immediate offset.
  98. ADDRESS_REG_WB
  99. A base register indexed by immediate offset with writeback.
  100. ADDRESS_REG_REG
  101. A base register indexed by (optionally scaled) register.
  102. ADDRESS_REG_UXTW
  103. A base register indexed by (optionally scaled) zero-extended register.
  104. ADDRESS_REG_SXTW
  105. A base register indexed by (optionally scaled) sign-extended register.
  106. ADDRESS_LO_SUM
  107. A LO_SUM rtx with a base register and "LO12" symbol relocation.
  108. ADDRESS_SYMBOLIC:
  109. A constant symbolic address, in pc-relative literal pool. */
  110. enum aarch64_address_type {
  111. ADDRESS_REG_IMM,
  112. ADDRESS_REG_WB,
  113. ADDRESS_REG_REG,
  114. ADDRESS_REG_UXTW,
  115. ADDRESS_REG_SXTW,
  116. ADDRESS_LO_SUM,
  117. ADDRESS_SYMBOLIC
  118. };
  119. struct aarch64_address_info {
  120. enum aarch64_address_type type;
  121. rtx base;
  122. rtx offset;
  123. int shift;
  124. enum aarch64_symbol_type symbol_type;
  125. };
  126. struct simd_immediate_info
  127. {
  128. rtx value;
  129. int shift;
  130. int element_width;
  131. bool mvn;
  132. bool msl;
  133. };
  134. /* The current code model. */
  135. enum aarch64_code_model aarch64_cmodel;
  136. #ifdef HAVE_AS_TLS
  137. #undef TARGET_HAVE_TLS
  138. #define TARGET_HAVE_TLS 1
  139. #endif
  140. static bool aarch64_composite_type_p (const_tree, machine_mode);
  141. static bool aarch64_vfp_is_call_or_return_candidate (machine_mode,
  142. const_tree,
  143. machine_mode *, int *,
  144. bool *);
  145. static void aarch64_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
  146. static void aarch64_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
  147. static void aarch64_override_options_after_change (void);
  148. static bool aarch64_vector_mode_supported_p (machine_mode);
  149. static unsigned bit_count (unsigned HOST_WIDE_INT);
  150. static bool aarch64_vectorize_vec_perm_const_ok (machine_mode vmode,
  151. const unsigned char *sel);
  152. static int aarch64_address_cost (rtx, machine_mode, addr_space_t, bool);
  153. /* Major revision number of the ARM Architecture implemented by the target. */
  154. unsigned aarch64_architecture_version;
  155. /* The processor for which instructions should be scheduled. */
  156. enum aarch64_processor aarch64_tune = cortexa53;
  157. /* The current tuning set. */
  158. const struct tune_params *aarch64_tune_params;
  159. /* Mask to specify which instructions we are allowed to generate. */
  160. unsigned long aarch64_isa_flags = 0;
  161. /* Mask to specify which instruction scheduling options should be used. */
  162. unsigned long aarch64_tune_flags = 0;
  163. /* Tuning parameters. */
  164. static const struct cpu_addrcost_table generic_addrcost_table =
  165. {
  166. {
  167. 0, /* hi */
  168. 0, /* si */
  169. 0, /* di */
  170. 0, /* ti */
  171. },
  172. 0, /* pre_modify */
  173. 0, /* post_modify */
  174. 0, /* register_offset */
  175. 0, /* register_extend */
  176. 0 /* imm_offset */
  177. };
  178. static const struct cpu_addrcost_table cortexa57_addrcost_table =
  179. {
  180. {
  181. 1, /* hi */
  182. 0, /* si */
  183. 0, /* di */
  184. 1, /* ti */
  185. },
  186. 0, /* pre_modify */
  187. 0, /* post_modify */
  188. 0, /* register_offset */
  189. 0, /* register_extend */
  190. 0, /* imm_offset */
  191. };
  192. static const struct cpu_addrcost_table xgene1_addrcost_table =
  193. {
  194. {
  195. 1, /* hi */
  196. 0, /* si */
  197. 0, /* di */
  198. 1, /* ti */
  199. },
  200. 1, /* pre_modify */
  201. 0, /* post_modify */
  202. 0, /* register_offset */
  203. 1, /* register_extend */
  204. 0, /* imm_offset */
  205. };
  206. static const struct cpu_regmove_cost generic_regmove_cost =
  207. {
  208. 1, /* GP2GP */
  209. /* Avoid the use of slow int<->fp moves for spilling by setting
  210. their cost higher than memmov_cost. */
  211. 5, /* GP2FP */
  212. 5, /* FP2GP */
  213. 2 /* FP2FP */
  214. };
  215. static const struct cpu_regmove_cost cortexa57_regmove_cost =
  216. {
  217. 1, /* GP2GP */
  218. /* Avoid the use of slow int<->fp moves for spilling by setting
  219. their cost higher than memmov_cost. */
  220. 5, /* GP2FP */
  221. 5, /* FP2GP */
  222. 2 /* FP2FP */
  223. };
  224. static const struct cpu_regmove_cost cortexa53_regmove_cost =
  225. {
  226. 1, /* GP2GP */
  227. /* Avoid the use of slow int<->fp moves for spilling by setting
  228. their cost higher than memmov_cost. */
  229. 5, /* GP2FP */
  230. 5, /* FP2GP */
  231. 2 /* FP2FP */
  232. };
  233. static const struct cpu_regmove_cost thunderx_regmove_cost =
  234. {
  235. 2, /* GP2GP */
  236. 2, /* GP2FP */
  237. 6, /* FP2GP */
  238. 4 /* FP2FP */
  239. };
  240. static const struct cpu_regmove_cost xgene1_regmove_cost =
  241. {
  242. 1, /* GP2GP */
  243. /* Avoid the use of slow int<->fp moves for spilling by setting
  244. their cost higher than memmov_cost. */
  245. 8, /* GP2FP */
  246. 8, /* FP2GP */
  247. 2 /* FP2FP */
  248. };
  249. /* Generic costs for vector insn classes. */
  250. static const struct cpu_vector_cost generic_vector_cost =
  251. {
  252. 1, /* scalar_stmt_cost */
  253. 1, /* scalar_load_cost */
  254. 1, /* scalar_store_cost */
  255. 1, /* vec_stmt_cost */
  256. 1, /* vec_to_scalar_cost */
  257. 1, /* scalar_to_vec_cost */
  258. 1, /* vec_align_load_cost */
  259. 1, /* vec_unalign_load_cost */
  260. 1, /* vec_unalign_store_cost */
  261. 1, /* vec_store_cost */
  262. 3, /* cond_taken_branch_cost */
  263. 1 /* cond_not_taken_branch_cost */
  264. };
  265. /* Generic costs for vector insn classes. */
  266. static const struct cpu_vector_cost cortexa57_vector_cost =
  267. {
  268. 1, /* scalar_stmt_cost */
  269. 4, /* scalar_load_cost */
  270. 1, /* scalar_store_cost */
  271. 3, /* vec_stmt_cost */
  272. 8, /* vec_to_scalar_cost */
  273. 8, /* scalar_to_vec_cost */
  274. 5, /* vec_align_load_cost */
  275. 5, /* vec_unalign_load_cost */
  276. 1, /* vec_unalign_store_cost */
  277. 1, /* vec_store_cost */
  278. 1, /* cond_taken_branch_cost */
  279. 1 /* cond_not_taken_branch_cost */
  280. };
  281. /* Generic costs for vector insn classes. */
  282. static const struct cpu_vector_cost xgene1_vector_cost =
  283. {
  284. 1, /* scalar_stmt_cost */
  285. 5, /* scalar_load_cost */
  286. 1, /* scalar_store_cost */
  287. 2, /* vec_stmt_cost */
  288. 4, /* vec_to_scalar_cost */
  289. 4, /* scalar_to_vec_cost */
  290. 10, /* vec_align_load_cost */
  291. 10, /* vec_unalign_load_cost */
  292. 2, /* vec_unalign_store_cost */
  293. 2, /* vec_store_cost */
  294. 2, /* cond_taken_branch_cost */
  295. 1 /* cond_not_taken_branch_cost */
  296. };
  297. #define AARCH64_FUSE_NOTHING (0)
  298. #define AARCH64_FUSE_MOV_MOVK (1 << 0)
  299. #define AARCH64_FUSE_ADRP_ADD (1 << 1)
  300. #define AARCH64_FUSE_MOVK_MOVK (1 << 2)
  301. #define AARCH64_FUSE_ADRP_LDR (1 << 3)
  302. #define AARCH64_FUSE_CMP_BRANCH (1 << 4)
  303. static const struct tune_params generic_tunings =
  304. {
  305. &cortexa57_extra_costs,
  306. &generic_addrcost_table,
  307. &generic_regmove_cost,
  308. &generic_vector_cost,
  309. 4, /* memmov_cost */
  310. 2, /* issue_rate */
  311. AARCH64_FUSE_NOTHING, /* fuseable_ops */
  312. 8, /* function_align. */
  313. 8, /* jump_align. */
  314. 4, /* loop_align. */
  315. 2, /* int_reassoc_width. */
  316. 4, /* fp_reassoc_width. */
  317. 1 /* vec_reassoc_width. */
  318. };
  319. static const struct tune_params cortexa53_tunings =
  320. {
  321. &cortexa53_extra_costs,
  322. &generic_addrcost_table,
  323. &cortexa53_regmove_cost,
  324. &generic_vector_cost,
  325. 4, /* memmov_cost */
  326. 2, /* issue_rate */
  327. (AARCH64_FUSE_MOV_MOVK | AARCH64_FUSE_ADRP_ADD
  328. | AARCH64_FUSE_MOVK_MOVK | AARCH64_FUSE_ADRP_LDR), /* fuseable_ops */
  329. 8, /* function_align. */
  330. 8, /* jump_align. */
  331. 4, /* loop_align. */
  332. 2, /* int_reassoc_width. */
  333. 4, /* fp_reassoc_width. */
  334. 1 /* vec_reassoc_width. */
  335. };
  336. static const struct tune_params cortexa57_tunings =
  337. {
  338. &cortexa57_extra_costs,
  339. &cortexa57_addrcost_table,
  340. &cortexa57_regmove_cost,
  341. &cortexa57_vector_cost,
  342. 4, /* memmov_cost */
  343. 3, /* issue_rate */
  344. (AARCH64_FUSE_MOV_MOVK | AARCH64_FUSE_ADRP_ADD
  345. | AARCH64_FUSE_MOVK_MOVK), /* fuseable_ops */
  346. 16, /* function_align. */
  347. 8, /* jump_align. */
  348. 4, /* loop_align. */
  349. 2, /* int_reassoc_width. */
  350. 4, /* fp_reassoc_width. */
  351. 1 /* vec_reassoc_width. */
  352. };
  353. static const struct tune_params thunderx_tunings =
  354. {
  355. &thunderx_extra_costs,
  356. &generic_addrcost_table,
  357. &thunderx_regmove_cost,
  358. &generic_vector_cost,
  359. 6, /* memmov_cost */
  360. 2, /* issue_rate */
  361. AARCH64_FUSE_CMP_BRANCH, /* fuseable_ops */
  362. 8, /* function_align. */
  363. 8, /* jump_align. */
  364. 8, /* loop_align. */
  365. 2, /* int_reassoc_width. */
  366. 4, /* fp_reassoc_width. */
  367. 1 /* vec_reassoc_width. */
  368. };
  369. static const struct tune_params xgene1_tunings =
  370. {
  371. &xgene1_extra_costs,
  372. &xgene1_addrcost_table,
  373. &xgene1_regmove_cost,
  374. &xgene1_vector_cost,
  375. 6, /* memmov_cost */
  376. 4, /* issue_rate */
  377. AARCH64_FUSE_NOTHING, /* fuseable_ops */
  378. 16, /* function_align. */
  379. 8, /* jump_align. */
  380. 16, /* loop_align. */
  381. 2, /* int_reassoc_width. */
  382. 4, /* fp_reassoc_width. */
  383. 1 /* vec_reassoc_width. */
  384. };
  385. /* A processor implementing AArch64. */
  386. struct processor
  387. {
  388. const char *const name;
  389. enum aarch64_processor core;
  390. const char *arch;
  391. unsigned architecture_version;
  392. const unsigned long flags;
  393. const struct tune_params *const tune;
  394. };
  395. /* Processor cores implementing AArch64. */
  396. static const struct processor all_cores[] =
  397. {
  398. #define AARCH64_CORE(NAME, IDENT, SCHED, ARCH, FLAGS, COSTS) \
  399. {NAME, SCHED, #ARCH, ARCH, FLAGS, &COSTS##_tunings},
  400. #include "aarch64-cores.def"
  401. #undef AARCH64_CORE
  402. {"generic", cortexa53, "8", 8, AARCH64_FL_FOR_ARCH8, &generic_tunings},
  403. {NULL, aarch64_none, NULL, 0, 0, NULL}
  404. };
  405. /* Architectures implementing AArch64. */
  406. static const struct processor all_architectures[] =
  407. {
  408. #define AARCH64_ARCH(NAME, CORE, ARCH, FLAGS) \
  409. {NAME, CORE, #ARCH, ARCH, FLAGS, NULL},
  410. #include "aarch64-arches.def"
  411. #undef AARCH64_ARCH
  412. {NULL, aarch64_none, NULL, 0, 0, NULL}
  413. };
  414. /* Target specification. These are populated as commandline arguments
  415. are processed, or NULL if not specified. */
  416. static const struct processor *selected_arch;
  417. static const struct processor *selected_cpu;
  418. static const struct processor *selected_tune;
  419. #define AARCH64_CPU_DEFAULT_FLAGS ((selected_cpu) ? selected_cpu->flags : 0)
  420. /* An ISA extension in the co-processor and main instruction set space. */
  421. struct aarch64_option_extension
  422. {
  423. const char *const name;
  424. const unsigned long flags_on;
  425. const unsigned long flags_off;
  426. };
  427. /* ISA extensions in AArch64. */
  428. static const struct aarch64_option_extension all_extensions[] =
  429. {
  430. #define AARCH64_OPT_EXTENSION(NAME, FLAGS_ON, FLAGS_OFF) \
  431. {NAME, FLAGS_ON, FLAGS_OFF},
  432. #include "aarch64-option-extensions.def"
  433. #undef AARCH64_OPT_EXTENSION
  434. {NULL, 0, 0}
  435. };
  436. /* Used to track the size of an address when generating a pre/post
  437. increment address. */
  438. static machine_mode aarch64_memory_reference_mode;
  439. /* A table of valid AArch64 "bitmask immediate" values for
  440. logical instructions. */
  441. #define AARCH64_NUM_BITMASKS 5334
  442. static unsigned HOST_WIDE_INT aarch64_bitmasks[AARCH64_NUM_BITMASKS];
  443. typedef enum aarch64_cond_code
  444. {
  445. AARCH64_EQ = 0, AARCH64_NE, AARCH64_CS, AARCH64_CC, AARCH64_MI, AARCH64_PL,
  446. AARCH64_VS, AARCH64_VC, AARCH64_HI, AARCH64_LS, AARCH64_GE, AARCH64_LT,
  447. AARCH64_GT, AARCH64_LE, AARCH64_AL, AARCH64_NV
  448. }
  449. aarch64_cc;
  450. #define AARCH64_INVERSE_CONDITION_CODE(X) ((aarch64_cc) (((int) X) ^ 1))
  451. /* The condition codes of the processor, and the inverse function. */
  452. static const char * const aarch64_condition_codes[] =
  453. {
  454. "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
  455. "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"
  456. };
  457. static unsigned int
  458. aarch64_min_divisions_for_recip_mul (enum machine_mode mode ATTRIBUTE_UNUSED)
  459. {
  460. return 2;
  461. }
  462. static int
  463. aarch64_reassociation_width (unsigned opc ATTRIBUTE_UNUSED,
  464. enum machine_mode mode)
  465. {
  466. if (VECTOR_MODE_P (mode))
  467. return aarch64_tune_params->vec_reassoc_width;
  468. if (INTEGRAL_MODE_P (mode))
  469. return aarch64_tune_params->int_reassoc_width;
  470. if (FLOAT_MODE_P (mode))
  471. return aarch64_tune_params->fp_reassoc_width;
  472. return 1;
  473. }
  474. /* Provide a mapping from gcc register numbers to dwarf register numbers. */
  475. unsigned
  476. aarch64_dbx_register_number (unsigned regno)
  477. {
  478. if (GP_REGNUM_P (regno))
  479. return AARCH64_DWARF_R0 + regno - R0_REGNUM;
  480. else if (regno == SP_REGNUM)
  481. return AARCH64_DWARF_SP;
  482. else if (FP_REGNUM_P (regno))
  483. return AARCH64_DWARF_V0 + regno - V0_REGNUM;
  484. /* Return values >= DWARF_FRAME_REGISTERS indicate that there is no
  485. equivalent DWARF register. */
  486. return DWARF_FRAME_REGISTERS;
  487. }
  488. /* Return TRUE if MODE is any of the large INT modes. */
  489. static bool
  490. aarch64_vect_struct_mode_p (machine_mode mode)
  491. {
  492. return mode == OImode || mode == CImode || mode == XImode;
  493. }
  494. /* Return TRUE if MODE is any of the vector modes. */
  495. static bool
  496. aarch64_vector_mode_p (machine_mode mode)
  497. {
  498. return aarch64_vector_mode_supported_p (mode)
  499. || aarch64_vect_struct_mode_p (mode);
  500. }
  501. /* Implement target hook TARGET_ARRAY_MODE_SUPPORTED_P. */
  502. static bool
  503. aarch64_array_mode_supported_p (machine_mode mode,
  504. unsigned HOST_WIDE_INT nelems)
  505. {
  506. if (TARGET_SIMD
  507. && AARCH64_VALID_SIMD_QREG_MODE (mode)
  508. && (nelems >= 2 && nelems <= 4))
  509. return true;
  510. return false;
  511. }
  512. /* Implement HARD_REGNO_NREGS. */
  513. int
  514. aarch64_hard_regno_nregs (unsigned regno, machine_mode mode)
  515. {
  516. switch (aarch64_regno_regclass (regno))
  517. {
  518. case FP_REGS:
  519. case FP_LO_REGS:
  520. return (GET_MODE_SIZE (mode) + UNITS_PER_VREG - 1) / UNITS_PER_VREG;
  521. default:
  522. return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  523. }
  524. gcc_unreachable ();
  525. }
  526. /* Implement HARD_REGNO_MODE_OK. */
  527. int
  528. aarch64_hard_regno_mode_ok (unsigned regno, machine_mode mode)
  529. {
  530. if (GET_MODE_CLASS (mode) == MODE_CC)
  531. return regno == CC_REGNUM;
  532. if (regno == SP_REGNUM)
  533. /* The purpose of comparing with ptr_mode is to support the
  534. global register variable associated with the stack pointer
  535. register via the syntax of asm ("wsp") in ILP32. */
  536. return mode == Pmode || mode == ptr_mode;
  537. if (regno == FRAME_POINTER_REGNUM || regno == ARG_POINTER_REGNUM)
  538. return mode == Pmode;
  539. if (GP_REGNUM_P (regno) && ! aarch64_vect_struct_mode_p (mode))
  540. return 1;
  541. if (FP_REGNUM_P (regno))
  542. {
  543. if (aarch64_vect_struct_mode_p (mode))
  544. return
  545. (regno + aarch64_hard_regno_nregs (regno, mode) - 1) <= V31_REGNUM;
  546. else
  547. return 1;
  548. }
  549. return 0;
  550. }
  551. /* Implement HARD_REGNO_CALLER_SAVE_MODE. */
  552. machine_mode
  553. aarch64_hard_regno_caller_save_mode (unsigned regno, unsigned nregs,
  554. machine_mode mode)
  555. {
  556. /* Handle modes that fit within single registers. */
  557. if (nregs == 1 && GET_MODE_SIZE (mode) <= 16)
  558. {
  559. if (GET_MODE_SIZE (mode) >= 4)
  560. return mode;
  561. else
  562. return SImode;
  563. }
  564. /* Fall back to generic for multi-reg and very large modes. */
  565. else
  566. return choose_hard_reg_mode (regno, nregs, false);
  567. }
  568. /* Return true if calls to DECL should be treated as
  569. long-calls (ie called via a register). */
  570. static bool
  571. aarch64_decl_is_long_call_p (const_tree decl ATTRIBUTE_UNUSED)
  572. {
  573. return false;
  574. }
  575. /* Return true if calls to symbol-ref SYM should be treated as
  576. long-calls (ie called via a register). */
  577. bool
  578. aarch64_is_long_call_p (rtx sym)
  579. {
  580. return aarch64_decl_is_long_call_p (SYMBOL_REF_DECL (sym));
  581. }
  582. /* Return true if the offsets to a zero/sign-extract operation
  583. represent an expression that matches an extend operation. The
  584. operands represent the paramters from
  585. (extract:MODE (mult (reg) (MULT_IMM)) (EXTRACT_IMM) (const_int 0)). */
  586. bool
  587. aarch64_is_extend_from_extract (machine_mode mode, rtx mult_imm,
  588. rtx extract_imm)
  589. {
  590. HOST_WIDE_INT mult_val, extract_val;
  591. if (! CONST_INT_P (mult_imm) || ! CONST_INT_P (extract_imm))
  592. return false;
  593. mult_val = INTVAL (mult_imm);
  594. extract_val = INTVAL (extract_imm);
  595. if (extract_val > 8
  596. && extract_val < GET_MODE_BITSIZE (mode)
  597. && exact_log2 (extract_val & ~7) > 0
  598. && (extract_val & 7) <= 4
  599. && mult_val == (1 << (extract_val & 7)))
  600. return true;
  601. return false;
  602. }
  603. /* Emit an insn that's a simple single-set. Both the operands must be
  604. known to be valid. */
  605. inline static rtx
  606. emit_set_insn (rtx x, rtx y)
  607. {
  608. return emit_insn (gen_rtx_SET (VOIDmode, x, y));
  609. }
  610. /* X and Y are two things to compare using CODE. Emit the compare insn and
  611. return the rtx for register 0 in the proper mode. */
  612. rtx
  613. aarch64_gen_compare_reg (RTX_CODE code, rtx x, rtx y)
  614. {
  615. machine_mode mode = SELECT_CC_MODE (code, x, y);
  616. rtx cc_reg = gen_rtx_REG (mode, CC_REGNUM);
  617. emit_set_insn (cc_reg, gen_rtx_COMPARE (mode, x, y));
  618. return cc_reg;
  619. }
  620. /* Build the SYMBOL_REF for __tls_get_addr. */
  621. static GTY(()) rtx tls_get_addr_libfunc;
  622. rtx
  623. aarch64_tls_get_addr (void)
  624. {
  625. if (!tls_get_addr_libfunc)
  626. tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr");
  627. return tls_get_addr_libfunc;
  628. }
  629. /* Return the TLS model to use for ADDR. */
  630. static enum tls_model
  631. tls_symbolic_operand_type (rtx addr)
  632. {
  633. enum tls_model tls_kind = TLS_MODEL_NONE;
  634. rtx sym, addend;
  635. if (GET_CODE (addr) == CONST)
  636. {
  637. split_const (addr, &sym, &addend);
  638. if (GET_CODE (sym) == SYMBOL_REF)
  639. tls_kind = SYMBOL_REF_TLS_MODEL (sym);
  640. }
  641. else if (GET_CODE (addr) == SYMBOL_REF)
  642. tls_kind = SYMBOL_REF_TLS_MODEL (addr);
  643. return tls_kind;
  644. }
  645. /* We'll allow lo_sum's in addresses in our legitimate addresses
  646. so that combine would take care of combining addresses where
  647. necessary, but for generation purposes, we'll generate the address
  648. as :
  649. RTL Absolute
  650. tmp = hi (symbol_ref); adrp x1, foo
  651. dest = lo_sum (tmp, symbol_ref); add dest, x1, :lo_12:foo
  652. nop
  653. PIC TLS
  654. adrp x1, :got:foo adrp tmp, :tlsgd:foo
  655. ldr x1, [:got_lo12:foo] add dest, tmp, :tlsgd_lo12:foo
  656. bl __tls_get_addr
  657. nop
  658. Load TLS symbol, depending on TLS mechanism and TLS access model.
  659. Global Dynamic - Traditional TLS:
  660. adrp tmp, :tlsgd:imm
  661. add dest, tmp, #:tlsgd_lo12:imm
  662. bl __tls_get_addr
  663. Global Dynamic - TLS Descriptors:
  664. adrp dest, :tlsdesc:imm
  665. ldr tmp, [dest, #:tlsdesc_lo12:imm]
  666. add dest, dest, #:tlsdesc_lo12:imm
  667. blr tmp
  668. mrs tp, tpidr_el0
  669. add dest, dest, tp
  670. Initial Exec:
  671. mrs tp, tpidr_el0
  672. adrp tmp, :gottprel:imm
  673. ldr dest, [tmp, #:gottprel_lo12:imm]
  674. add dest, dest, tp
  675. Local Exec:
  676. mrs tp, tpidr_el0
  677. add t0, tp, #:tprel_hi12:imm, lsl #12
  678. add t0, t0, #:tprel_lo12_nc:imm
  679. */
  680. static void
  681. aarch64_load_symref_appropriately (rtx dest, rtx imm,
  682. enum aarch64_symbol_type type)
  683. {
  684. switch (type)
  685. {
  686. case SYMBOL_SMALL_ABSOLUTE:
  687. {
  688. /* In ILP32, the mode of dest can be either SImode or DImode. */
  689. rtx tmp_reg = dest;
  690. machine_mode mode = GET_MODE (dest);
  691. gcc_assert (mode == Pmode || mode == ptr_mode);
  692. if (can_create_pseudo_p ())
  693. tmp_reg = gen_reg_rtx (mode);
  694. emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, imm));
  695. emit_insn (gen_add_losym (dest, tmp_reg, imm));
  696. return;
  697. }
  698. case SYMBOL_TINY_ABSOLUTE:
  699. emit_insn (gen_rtx_SET (Pmode, dest, imm));
  700. return;
  701. case SYMBOL_SMALL_GOT:
  702. {
  703. /* In ILP32, the mode of dest can be either SImode or DImode,
  704. while the got entry is always of SImode size. The mode of
  705. dest depends on how dest is used: if dest is assigned to a
  706. pointer (e.g. in the memory), it has SImode; it may have
  707. DImode if dest is dereferenced to access the memeory.
  708. This is why we have to handle three different ldr_got_small
  709. patterns here (two patterns for ILP32). */
  710. rtx tmp_reg = dest;
  711. machine_mode mode = GET_MODE (dest);
  712. if (can_create_pseudo_p ())
  713. tmp_reg = gen_reg_rtx (mode);
  714. emit_move_insn (tmp_reg, gen_rtx_HIGH (mode, imm));
  715. if (mode == ptr_mode)
  716. {
  717. if (mode == DImode)
  718. emit_insn (gen_ldr_got_small_di (dest, tmp_reg, imm));
  719. else
  720. emit_insn (gen_ldr_got_small_si (dest, tmp_reg, imm));
  721. }
  722. else
  723. {
  724. gcc_assert (mode == Pmode);
  725. emit_insn (gen_ldr_got_small_sidi (dest, tmp_reg, imm));
  726. }
  727. return;
  728. }
  729. case SYMBOL_SMALL_TLSGD:
  730. {
  731. rtx_insn *insns;
  732. rtx result = gen_rtx_REG (Pmode, R0_REGNUM);
  733. start_sequence ();
  734. aarch64_emit_call_insn (gen_tlsgd_small (result, imm));
  735. insns = get_insns ();
  736. end_sequence ();
  737. RTL_CONST_CALL_P (insns) = 1;
  738. emit_libcall_block (insns, dest, result, imm);
  739. return;
  740. }
  741. case SYMBOL_SMALL_TLSDESC:
  742. {
  743. machine_mode mode = GET_MODE (dest);
  744. rtx x0 = gen_rtx_REG (mode, R0_REGNUM);
  745. rtx tp;
  746. gcc_assert (mode == Pmode || mode == ptr_mode);
  747. /* In ILP32, the got entry is always of SImode size. Unlike
  748. small GOT, the dest is fixed at reg 0. */
  749. if (TARGET_ILP32)
  750. emit_insn (gen_tlsdesc_small_si (imm));
  751. else
  752. emit_insn (gen_tlsdesc_small_di (imm));
  753. tp = aarch64_load_tp (NULL);
  754. if (mode != Pmode)
  755. tp = gen_lowpart (mode, tp);
  756. emit_insn (gen_rtx_SET (mode, dest, gen_rtx_PLUS (mode, tp, x0)));
  757. set_unique_reg_note (get_last_insn (), REG_EQUIV, imm);
  758. return;
  759. }
  760. case SYMBOL_SMALL_GOTTPREL:
  761. {
  762. /* In ILP32, the mode of dest can be either SImode or DImode,
  763. while the got entry is always of SImode size. The mode of
  764. dest depends on how dest is used: if dest is assigned to a
  765. pointer (e.g. in the memory), it has SImode; it may have
  766. DImode if dest is dereferenced to access the memeory.
  767. This is why we have to handle three different tlsie_small
  768. patterns here (two patterns for ILP32). */
  769. machine_mode mode = GET_MODE (dest);
  770. rtx tmp_reg = gen_reg_rtx (mode);
  771. rtx tp = aarch64_load_tp (NULL);
  772. if (mode == ptr_mode)
  773. {
  774. if (mode == DImode)
  775. emit_insn (gen_tlsie_small_di (tmp_reg, imm));
  776. else
  777. {
  778. emit_insn (gen_tlsie_small_si (tmp_reg, imm));
  779. tp = gen_lowpart (mode, tp);
  780. }
  781. }
  782. else
  783. {
  784. gcc_assert (mode == Pmode);
  785. emit_insn (gen_tlsie_small_sidi (tmp_reg, imm));
  786. }
  787. emit_insn (gen_rtx_SET (mode, dest, gen_rtx_PLUS (mode, tp, tmp_reg)));
  788. set_unique_reg_note (get_last_insn (), REG_EQUIV, imm);
  789. return;
  790. }
  791. case SYMBOL_SMALL_TPREL:
  792. {
  793. rtx tp = aarch64_load_tp (NULL);
  794. if (GET_MODE (dest) != Pmode)
  795. tp = gen_lowpart (GET_MODE (dest), tp);
  796. emit_insn (gen_tlsle_small (dest, tp, imm));
  797. set_unique_reg_note (get_last_insn (), REG_EQUIV, imm);
  798. return;
  799. }
  800. case SYMBOL_TINY_GOT:
  801. emit_insn (gen_ldr_got_tiny (dest, imm));
  802. return;
  803. default:
  804. gcc_unreachable ();
  805. }
  806. }
  807. /* Emit a move from SRC to DEST. Assume that the move expanders can
  808. handle all moves if !can_create_pseudo_p (). The distinction is
  809. important because, unlike emit_move_insn, the move expanders know
  810. how to force Pmode objects into the constant pool even when the
  811. constant pool address is not itself legitimate. */
  812. static rtx
  813. aarch64_emit_move (rtx dest, rtx src)
  814. {
  815. return (can_create_pseudo_p ()
  816. ? emit_move_insn (dest, src)
  817. : emit_move_insn_1 (dest, src));
  818. }
  819. /* Split a 128-bit move operation into two 64-bit move operations,
  820. taking care to handle partial overlap of register to register
  821. copies. Special cases are needed when moving between GP regs and
  822. FP regs. SRC can be a register, constant or memory; DST a register
  823. or memory. If either operand is memory it must not have any side
  824. effects. */
  825. void
  826. aarch64_split_128bit_move (rtx dst, rtx src)
  827. {
  828. rtx dst_lo, dst_hi;
  829. rtx src_lo, src_hi;
  830. machine_mode mode = GET_MODE (dst);
  831. gcc_assert (mode == TImode || mode == TFmode);
  832. gcc_assert (!(side_effects_p (src) || side_effects_p (dst)));
  833. gcc_assert (mode == GET_MODE (src) || GET_MODE (src) == VOIDmode);
  834. if (REG_P (dst) && REG_P (src))
  835. {
  836. int src_regno = REGNO (src);
  837. int dst_regno = REGNO (dst);
  838. /* Handle FP <-> GP regs. */
  839. if (FP_REGNUM_P (dst_regno) && GP_REGNUM_P (src_regno))
  840. {
  841. src_lo = gen_lowpart (word_mode, src);
  842. src_hi = gen_highpart (word_mode, src);
  843. if (mode == TImode)
  844. {
  845. emit_insn (gen_aarch64_movtilow_di (dst, src_lo));
  846. emit_insn (gen_aarch64_movtihigh_di (dst, src_hi));
  847. }
  848. else
  849. {
  850. emit_insn (gen_aarch64_movtflow_di (dst, src_lo));
  851. emit_insn (gen_aarch64_movtfhigh_di (dst, src_hi));
  852. }
  853. return;
  854. }
  855. else if (GP_REGNUM_P (dst_regno) && FP_REGNUM_P (src_regno))
  856. {
  857. dst_lo = gen_lowpart (word_mode, dst);
  858. dst_hi = gen_highpart (word_mode, dst);
  859. if (mode == TImode)
  860. {
  861. emit_insn (gen_aarch64_movdi_tilow (dst_lo, src));
  862. emit_insn (gen_aarch64_movdi_tihigh (dst_hi, src));
  863. }
  864. else
  865. {
  866. emit_insn (gen_aarch64_movdi_tflow (dst_lo, src));
  867. emit_insn (gen_aarch64_movdi_tfhigh (dst_hi, src));
  868. }
  869. return;
  870. }
  871. }
  872. dst_lo = gen_lowpart (word_mode, dst);
  873. dst_hi = gen_highpart (word_mode, dst);
  874. src_lo = gen_lowpart (word_mode, src);
  875. src_hi = gen_highpart_mode (word_mode, mode, src);
  876. /* At most one pairing may overlap. */
  877. if (reg_overlap_mentioned_p (dst_lo, src_hi))
  878. {
  879. aarch64_emit_move (dst_hi, src_hi);
  880. aarch64_emit_move (dst_lo, src_lo);
  881. }
  882. else
  883. {
  884. aarch64_emit_move (dst_lo, src_lo);
  885. aarch64_emit_move (dst_hi, src_hi);
  886. }
  887. }
  888. bool
  889. aarch64_split_128bit_move_p (rtx dst, rtx src)
  890. {
  891. return (! REG_P (src)
  892. || ! (FP_REGNUM_P (REGNO (dst)) && FP_REGNUM_P (REGNO (src))));
  893. }
  894. /* Split a complex SIMD combine. */
  895. void
  896. aarch64_split_simd_combine (rtx dst, rtx src1, rtx src2)
  897. {
  898. machine_mode src_mode = GET_MODE (src1);
  899. machine_mode dst_mode = GET_MODE (dst);
  900. gcc_assert (VECTOR_MODE_P (dst_mode));
  901. if (REG_P (dst) && REG_P (src1) && REG_P (src2))
  902. {
  903. rtx (*gen) (rtx, rtx, rtx);
  904. switch (src_mode)
  905. {
  906. case V8QImode:
  907. gen = gen_aarch64_simd_combinev8qi;
  908. break;
  909. case V4HImode:
  910. gen = gen_aarch64_simd_combinev4hi;
  911. break;
  912. case V2SImode:
  913. gen = gen_aarch64_simd_combinev2si;
  914. break;
  915. case V2SFmode:
  916. gen = gen_aarch64_simd_combinev2sf;
  917. break;
  918. case DImode:
  919. gen = gen_aarch64_simd_combinedi;
  920. break;
  921. case DFmode:
  922. gen = gen_aarch64_simd_combinedf;
  923. break;
  924. default:
  925. gcc_unreachable ();
  926. }
  927. emit_insn (gen (dst, src1, src2));
  928. return;
  929. }
  930. }
  931. /* Split a complex SIMD move. */
  932. void
  933. aarch64_split_simd_move (rtx dst, rtx src)
  934. {
  935. machine_mode src_mode = GET_MODE (src);
  936. machine_mode dst_mode = GET_MODE (dst);
  937. gcc_assert (VECTOR_MODE_P (dst_mode));
  938. if (REG_P (dst) && REG_P (src))
  939. {
  940. rtx (*gen) (rtx, rtx);
  941. gcc_assert (VECTOR_MODE_P (src_mode));
  942. switch (src_mode)
  943. {
  944. case V16QImode:
  945. gen = gen_aarch64_split_simd_movv16qi;
  946. break;
  947. case V8HImode:
  948. gen = gen_aarch64_split_simd_movv8hi;
  949. break;
  950. case V4SImode:
  951. gen = gen_aarch64_split_simd_movv4si;
  952. break;
  953. case V2DImode:
  954. gen = gen_aarch64_split_simd_movv2di;
  955. break;
  956. case V4SFmode:
  957. gen = gen_aarch64_split_simd_movv4sf;
  958. break;
  959. case V2DFmode:
  960. gen = gen_aarch64_split_simd_movv2df;
  961. break;
  962. default:
  963. gcc_unreachable ();
  964. }
  965. emit_insn (gen (dst, src));
  966. return;
  967. }
  968. }
  969. static rtx
  970. aarch64_force_temporary (machine_mode mode, rtx x, rtx value)
  971. {
  972. if (can_create_pseudo_p ())
  973. return force_reg (mode, value);
  974. else
  975. {
  976. x = aarch64_emit_move (x, value);
  977. return x;
  978. }
  979. }
  980. static rtx
  981. aarch64_add_offset (machine_mode mode, rtx temp, rtx reg, HOST_WIDE_INT offset)
  982. {
  983. if (!aarch64_plus_immediate (GEN_INT (offset), mode))
  984. {
  985. rtx high;
  986. /* Load the full offset into a register. This
  987. might be improvable in the future. */
  988. high = GEN_INT (offset);
  989. offset = 0;
  990. high = aarch64_force_temporary (mode, temp, high);
  991. reg = aarch64_force_temporary (mode, temp,
  992. gen_rtx_PLUS (mode, high, reg));
  993. }
  994. return plus_constant (mode, reg, offset);
  995. }
  996. static int
  997. aarch64_internal_mov_immediate (rtx dest, rtx imm, bool generate,
  998. machine_mode mode)
  999. {
  1000. unsigned HOST_WIDE_INT mask;
  1001. int i;
  1002. bool first;
  1003. unsigned HOST_WIDE_INT val;
  1004. bool subtargets;
  1005. rtx subtarget;
  1006. int one_match, zero_match, first_not_ffff_match;
  1007. int num_insns = 0;
  1008. if (CONST_INT_P (imm) && aarch64_move_imm (INTVAL (imm), mode))
  1009. {
  1010. if (generate)
  1011. emit_insn (gen_rtx_SET (VOIDmode, dest, imm));
  1012. num_insns++;
  1013. return num_insns;
  1014. }
  1015. if (mode == SImode)
  1016. {
  1017. /* We know we can't do this in 1 insn, and we must be able to do it
  1018. in two; so don't mess around looking for sequences that don't buy
  1019. us anything. */
  1020. if (generate)
  1021. {
  1022. emit_insn (gen_rtx_SET (VOIDmode, dest,
  1023. GEN_INT (INTVAL (imm) & 0xffff)));
  1024. emit_insn (gen_insv_immsi (dest, GEN_INT (16),
  1025. GEN_INT ((INTVAL (imm) >> 16) & 0xffff)));
  1026. }
  1027. num_insns += 2;
  1028. return num_insns;
  1029. }
  1030. /* Remaining cases are all for DImode. */
  1031. val = INTVAL (imm);
  1032. subtargets = optimize && can_create_pseudo_p ();
  1033. one_match = 0;
  1034. zero_match = 0;
  1035. mask = 0xffff;
  1036. first_not_ffff_match = -1;
  1037. for (i = 0; i < 64; i += 16, mask <<= 16)
  1038. {
  1039. if ((val & mask) == mask)
  1040. one_match++;
  1041. else
  1042. {
  1043. if (first_not_ffff_match < 0)
  1044. first_not_ffff_match = i;
  1045. if ((val & mask) == 0)
  1046. zero_match++;
  1047. }
  1048. }
  1049. if (one_match == 2)
  1050. {
  1051. /* Set one of the quarters and then insert back into result. */
  1052. mask = 0xffffll << first_not_ffff_match;
  1053. if (generate)
  1054. {
  1055. emit_insn (gen_rtx_SET (VOIDmode, dest, GEN_INT (val | mask)));
  1056. emit_insn (gen_insv_immdi (dest, GEN_INT (first_not_ffff_match),
  1057. GEN_INT ((val >> first_not_ffff_match)
  1058. & 0xffff)));
  1059. }
  1060. num_insns += 2;
  1061. return num_insns;
  1062. }
  1063. if (zero_match == 2)
  1064. goto simple_sequence;
  1065. mask = 0x0ffff0000UL;
  1066. for (i = 16; i < 64; i += 16, mask <<= 16)
  1067. {
  1068. HOST_WIDE_INT comp = mask & ~(mask - 1);
  1069. if (aarch64_uimm12_shift (val - (val & mask)))
  1070. {
  1071. if (generate)
  1072. {
  1073. subtarget = subtargets ? gen_reg_rtx (DImode) : dest;
  1074. emit_insn (gen_rtx_SET (VOIDmode, subtarget,
  1075. GEN_INT (val & mask)));
  1076. emit_insn (gen_adddi3 (dest, subtarget,
  1077. GEN_INT (val - (val & mask))));
  1078. }
  1079. num_insns += 2;
  1080. return num_insns;
  1081. }
  1082. else if (aarch64_uimm12_shift (-(val - ((val + comp) & mask))))
  1083. {
  1084. if (generate)
  1085. {
  1086. subtarget = subtargets ? gen_reg_rtx (DImode) : dest;
  1087. emit_insn (gen_rtx_SET (VOIDmode, subtarget,
  1088. GEN_INT ((val + comp) & mask)));
  1089. emit_insn (gen_adddi3 (dest, subtarget,
  1090. GEN_INT (val - ((val + comp) & mask))));
  1091. }
  1092. num_insns += 2;
  1093. return num_insns;
  1094. }
  1095. else if (aarch64_uimm12_shift (val - ((val - comp) | ~mask)))
  1096. {
  1097. if (generate)
  1098. {
  1099. subtarget = subtargets ? gen_reg_rtx (DImode) : dest;
  1100. emit_insn (gen_rtx_SET (VOIDmode, subtarget,
  1101. GEN_INT ((val - comp) | ~mask)));
  1102. emit_insn (gen_adddi3 (dest, subtarget,
  1103. GEN_INT (val - ((val - comp) | ~mask))));
  1104. }
  1105. num_insns += 2;
  1106. return num_insns;
  1107. }
  1108. else if (aarch64_uimm12_shift (-(val - (val | ~mask))))
  1109. {
  1110. if (generate)
  1111. {
  1112. subtarget = subtargets ? gen_reg_rtx (DImode) : dest;
  1113. emit_insn (gen_rtx_SET (VOIDmode, subtarget,
  1114. GEN_INT (val | ~mask)));
  1115. emit_insn (gen_adddi3 (dest, subtarget,
  1116. GEN_INT (val - (val | ~mask))));
  1117. }
  1118. num_insns += 2;
  1119. return num_insns;
  1120. }
  1121. }
  1122. /* See if we can do it by arithmetically combining two
  1123. immediates. */
  1124. for (i = 0; i < AARCH64_NUM_BITMASKS; i++)
  1125. {
  1126. int j;
  1127. mask = 0xffff;
  1128. if (aarch64_uimm12_shift (val - aarch64_bitmasks[i])
  1129. || aarch64_uimm12_shift (-val + aarch64_bitmasks[i]))
  1130. {
  1131. if (generate)
  1132. {
  1133. subtarget = subtargets ? gen_reg_rtx (DImode) : dest;
  1134. emit_insn (gen_rtx_SET (VOIDmode, subtarget,
  1135. GEN_INT (aarch64_bitmasks[i])));
  1136. emit_insn (gen_adddi3 (dest, subtarget,
  1137. GEN_INT (val - aarch64_bitmasks[i])));
  1138. }
  1139. num_insns += 2;
  1140. return num_insns;
  1141. }
  1142. for (j = 0; j < 64; j += 16, mask <<= 16)
  1143. {
  1144. if ((aarch64_bitmasks[i] & ~mask) == (val & ~mask))
  1145. {
  1146. if (generate)
  1147. {
  1148. emit_insn (gen_rtx_SET (VOIDmode, dest,
  1149. GEN_INT (aarch64_bitmasks[i])));
  1150. emit_insn (gen_insv_immdi (dest, GEN_INT (j),
  1151. GEN_INT ((val >> j) & 0xffff)));
  1152. }
  1153. num_insns += 2;
  1154. return num_insns;
  1155. }
  1156. }
  1157. }
  1158. /* See if we can do it by logically combining two immediates. */
  1159. for (i = 0; i < AARCH64_NUM_BITMASKS; i++)
  1160. {
  1161. if ((aarch64_bitmasks[i] & val) == aarch64_bitmasks[i])
  1162. {
  1163. int j;
  1164. for (j = i + 1; j < AARCH64_NUM_BITMASKS; j++)
  1165. if (val == (aarch64_bitmasks[i] | aarch64_bitmasks[j]))
  1166. {
  1167. if (generate)
  1168. {
  1169. subtarget = subtargets ? gen_reg_rtx (mode) : dest;
  1170. emit_insn (gen_rtx_SET (VOIDmode, subtarget,
  1171. GEN_INT (aarch64_bitmasks[i])));
  1172. emit_insn (gen_iordi3 (dest, subtarget,
  1173. GEN_INT (aarch64_bitmasks[j])));
  1174. }
  1175. num_insns += 2;
  1176. return num_insns;
  1177. }
  1178. }
  1179. else if ((val & aarch64_bitmasks[i]) == val)
  1180. {
  1181. int j;
  1182. for (j = i + 1; j < AARCH64_NUM_BITMASKS; j++)
  1183. if (val == (aarch64_bitmasks[j] & aarch64_bitmasks[i]))
  1184. {
  1185. if (generate)
  1186. {
  1187. subtarget = subtargets ? gen_reg_rtx (mode) : dest;
  1188. emit_insn (gen_rtx_SET (VOIDmode, subtarget,
  1189. GEN_INT (aarch64_bitmasks[j])));
  1190. emit_insn (gen_anddi3 (dest, subtarget,
  1191. GEN_INT (aarch64_bitmasks[i])));
  1192. }
  1193. num_insns += 2;
  1194. return num_insns;
  1195. }
  1196. }
  1197. }
  1198. if (one_match > zero_match)
  1199. {
  1200. /* Set either first three quarters or all but the third. */
  1201. mask = 0xffffll << (16 - first_not_ffff_match);
  1202. if (generate)
  1203. emit_insn (gen_rtx_SET (VOIDmode, dest,
  1204. GEN_INT (val | mask | 0xffffffff00000000ull)));
  1205. num_insns ++;
  1206. /* Now insert other two quarters. */
  1207. for (i = first_not_ffff_match + 16, mask <<= (first_not_ffff_match << 1);
  1208. i < 64; i += 16, mask <<= 16)
  1209. {
  1210. if ((val & mask) != mask)
  1211. {
  1212. if (generate)
  1213. emit_insn (gen_insv_immdi (dest, GEN_INT (i),
  1214. GEN_INT ((val >> i) & 0xffff)));
  1215. num_insns ++;
  1216. }
  1217. }
  1218. return num_insns;
  1219. }
  1220. simple_sequence:
  1221. first = true;
  1222. mask = 0xffff;
  1223. for (i = 0; i < 64; i += 16, mask <<= 16)
  1224. {
  1225. if ((val & mask) != 0)
  1226. {
  1227. if (first)
  1228. {
  1229. if (generate)
  1230. emit_insn (gen_rtx_SET (VOIDmode, dest,
  1231. GEN_INT (val & mask)));
  1232. num_insns ++;
  1233. first = false;
  1234. }
  1235. else
  1236. {
  1237. if (generate)
  1238. emit_insn (gen_insv_immdi (dest, GEN_INT (i),
  1239. GEN_INT ((val >> i) & 0xffff)));
  1240. num_insns ++;
  1241. }
  1242. }
  1243. }
  1244. return num_insns;
  1245. }
  1246. void
  1247. aarch64_expand_mov_immediate (rtx dest, rtx imm)
  1248. {
  1249. machine_mode mode = GET_MODE (dest);
  1250. gcc_assert (mode == SImode || mode == DImode);
  1251. /* Check on what type of symbol it is. */
  1252. if (GET_CODE (imm) == SYMBOL_REF
  1253. || GET_CODE (imm) == LABEL_REF
  1254. || GET_CODE (imm) == CONST)
  1255. {
  1256. rtx mem, base, offset;
  1257. enum aarch64_symbol_type sty;
  1258. /* If we have (const (plus symbol offset)), separate out the offset
  1259. before we start classifying the symbol. */
  1260. split_const (imm, &base, &offset);
  1261. sty = aarch64_classify_symbol (base, offset, SYMBOL_CONTEXT_ADR);
  1262. switch (sty)
  1263. {
  1264. case SYMBOL_FORCE_TO_MEM:
  1265. if (offset != const0_rtx
  1266. && targetm.cannot_force_const_mem (mode, imm))
  1267. {
  1268. gcc_assert (can_create_pseudo_p ());
  1269. base = aarch64_force_temporary (mode, dest, base);
  1270. base = aarch64_add_offset (mode, NULL, base, INTVAL (offset));
  1271. aarch64_emit_move (dest, base);
  1272. return;
  1273. }
  1274. mem = force_const_mem (ptr_mode, imm);
  1275. gcc_assert (mem);
  1276. if (mode != ptr_mode)
  1277. mem = gen_rtx_ZERO_EXTEND (mode, mem);
  1278. emit_insn (gen_rtx_SET (VOIDmode, dest, mem));
  1279. return;
  1280. case SYMBOL_SMALL_TLSGD:
  1281. case SYMBOL_SMALL_TLSDESC:
  1282. case SYMBOL_SMALL_GOTTPREL:
  1283. case SYMBOL_SMALL_GOT:
  1284. case SYMBOL_TINY_GOT:
  1285. if (offset != const0_rtx)
  1286. {
  1287. gcc_assert(can_create_pseudo_p ());
  1288. base = aarch64_force_temporary (mode, dest, base);
  1289. base = aarch64_add_offset (mode, NULL, base, INTVAL (offset));
  1290. aarch64_emit_move (dest, base);
  1291. return;
  1292. }
  1293. /* FALLTHRU */
  1294. case SYMBOL_SMALL_TPREL:
  1295. case SYMBOL_SMALL_ABSOLUTE:
  1296. case SYMBOL_TINY_ABSOLUTE:
  1297. aarch64_load_symref_appropriately (dest, imm, sty);
  1298. return;
  1299. default:
  1300. gcc_unreachable ();
  1301. }
  1302. }
  1303. if (!CONST_INT_P (imm))
  1304. {
  1305. if (GET_CODE (imm) == HIGH)
  1306. emit_insn (gen_rtx_SET (VOIDmode, dest, imm));
  1307. else
  1308. {
  1309. rtx mem = force_const_mem (mode, imm);
  1310. gcc_assert (mem);
  1311. emit_insn (gen_rtx_SET (VOIDmode, dest, mem));
  1312. }
  1313. return;
  1314. }
  1315. aarch64_internal_mov_immediate (dest, imm, true, GET_MODE (dest));
  1316. }
  1317. static bool
  1318. aarch64_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
  1319. tree exp ATTRIBUTE_UNUSED)
  1320. {
  1321. /* Currently, always true. */
  1322. return true;
  1323. }
  1324. /* Implement TARGET_PASS_BY_REFERENCE. */
  1325. static bool
  1326. aarch64_pass_by_reference (cumulative_args_t pcum ATTRIBUTE_UNUSED,
  1327. machine_mode mode,
  1328. const_tree type,
  1329. bool named ATTRIBUTE_UNUSED)
  1330. {
  1331. HOST_WIDE_INT size;
  1332. machine_mode dummymode;
  1333. int nregs;
  1334. /* GET_MODE_SIZE (BLKmode) is useless since it is 0. */
  1335. size = (mode == BLKmode && type)
  1336. ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
  1337. /* Aggregates are passed by reference based on their size. */
  1338. if (type && AGGREGATE_TYPE_P (type))
  1339. {
  1340. size = int_size_in_bytes (type);
  1341. }
  1342. /* Variable sized arguments are always returned by reference. */
  1343. if (size < 0)
  1344. return true;
  1345. /* Can this be a candidate to be passed in fp/simd register(s)? */
  1346. if (aarch64_vfp_is_call_or_return_candidate (mode, type,
  1347. &dummymode, &nregs,
  1348. NULL))
  1349. return false;
  1350. /* Arguments which are variable sized or larger than 2 registers are
  1351. passed by reference unless they are a homogenous floating point
  1352. aggregate. */
  1353. return size > 2 * UNITS_PER_WORD;
  1354. }
  1355. /* Return TRUE if VALTYPE is padded to its least significant bits. */
  1356. static bool
  1357. aarch64_return_in_msb (const_tree valtype)
  1358. {
  1359. machine_mode dummy_mode;
  1360. int dummy_int;
  1361. /* Never happens in little-endian mode. */
  1362. if (!BYTES_BIG_ENDIAN)
  1363. return false;
  1364. /* Only composite types smaller than or equal to 16 bytes can
  1365. be potentially returned in registers. */
  1366. if (!aarch64_composite_type_p (valtype, TYPE_MODE (valtype))
  1367. || int_size_in_bytes (valtype) <= 0
  1368. || int_size_in_bytes (valtype) > 16)
  1369. return false;
  1370. /* But not a composite that is an HFA (Homogeneous Floating-point Aggregate)
  1371. or an HVA (Homogeneous Short-Vector Aggregate); such a special composite
  1372. is always passed/returned in the least significant bits of fp/simd
  1373. register(s). */
  1374. if (aarch64_vfp_is_call_or_return_candidate (TYPE_MODE (valtype), valtype,
  1375. &dummy_mode, &dummy_int, NULL))
  1376. return false;
  1377. return true;
  1378. }
  1379. /* Implement TARGET_FUNCTION_VALUE.
  1380. Define how to find the value returned by a function. */
  1381. static rtx
  1382. aarch64_function_value (const_tree type, const_tree func,
  1383. bool outgoing ATTRIBUTE_UNUSED)
  1384. {
  1385. machine_mode mode;
  1386. int unsignedp;
  1387. int count;
  1388. machine_mode ag_mode;
  1389. mode = TYPE_MODE (type);
  1390. if (INTEGRAL_TYPE_P (type))
  1391. mode = promote_function_mode (type, mode, &unsignedp, func, 1);
  1392. if (aarch64_return_in_msb (type))
  1393. {
  1394. HOST_WIDE_INT size = int_size_in_bytes (type);
  1395. if (size % UNITS_PER_WORD != 0)
  1396. {
  1397. size += UNITS_PER_WORD - size % UNITS_PER_WORD;
  1398. mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
  1399. }
  1400. }
  1401. if (aarch64_vfp_is_call_or_return_candidate (mode, type,
  1402. &ag_mode, &count, NULL))
  1403. {
  1404. if (!aarch64_composite_type_p (type, mode))
  1405. {
  1406. gcc_assert (count == 1 && mode == ag_mode);
  1407. return gen_rtx_REG (mode, V0_REGNUM);
  1408. }
  1409. else
  1410. {
  1411. int i;
  1412. rtx par;
  1413. par = gen_rtx_PARALLEL (mode, rtvec_alloc (count));
  1414. for (i = 0; i < count; i++)
  1415. {
  1416. rtx tmp = gen_rtx_REG (ag_mode, V0_REGNUM + i);
  1417. tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp,
  1418. GEN_INT (i * GET_MODE_SIZE (ag_mode)));
  1419. XVECEXP (par, 0, i) = tmp;
  1420. }
  1421. return par;
  1422. }
  1423. }
  1424. else
  1425. return gen_rtx_REG (mode, R0_REGNUM);
  1426. }
  1427. /* Implements TARGET_FUNCTION_VALUE_REGNO_P.
  1428. Return true if REGNO is the number of a hard register in which the values
  1429. of called function may come back. */
  1430. static bool
  1431. aarch64_function_value_regno_p (const unsigned int regno)
  1432. {
  1433. /* Maximum of 16 bytes can be returned in the general registers. Examples
  1434. of 16-byte return values are: 128-bit integers and 16-byte small
  1435. structures (excluding homogeneous floating-point aggregates). */
  1436. if (regno == R0_REGNUM || regno == R1_REGNUM)
  1437. return true;
  1438. /* Up to four fp/simd registers can return a function value, e.g. a
  1439. homogeneous floating-point aggregate having four members. */
  1440. if (regno >= V0_REGNUM && regno < V0_REGNUM + HA_MAX_NUM_FLDS)
  1441. return TARGET_FLOAT;
  1442. return false;
  1443. }
  1444. /* Implement TARGET_RETURN_IN_MEMORY.
  1445. If the type T of the result of a function is such that
  1446. void func (T arg)
  1447. would require that arg be passed as a value in a register (or set of
  1448. registers) according to the parameter passing rules, then the result
  1449. is returned in the same registers as would be used for such an
  1450. argument. */
  1451. static bool
  1452. aarch64_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED)
  1453. {
  1454. HOST_WIDE_INT size;
  1455. machine_mode ag_mode;
  1456. int count;
  1457. if (!AGGREGATE_TYPE_P (type)
  1458. && TREE_CODE (type) != COMPLEX_TYPE
  1459. && TREE_CODE (type) != VECTOR_TYPE)
  1460. /* Simple scalar types always returned in registers. */
  1461. return false;
  1462. if (aarch64_vfp_is_call_or_return_candidate (TYPE_MODE (type),
  1463. type,
  1464. &ag_mode,
  1465. &count,
  1466. NULL))
  1467. return false;
  1468. /* Types larger than 2 registers returned in memory. */
  1469. size = int_size_in_bytes (type);
  1470. return (size < 0 || size > 2 * UNITS_PER_WORD);
  1471. }
  1472. static bool
  1473. aarch64_vfp_is_call_candidate (cumulative_args_t pcum_v, machine_mode mode,
  1474. const_tree type, int *nregs)
  1475. {
  1476. CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v);
  1477. return aarch64_vfp_is_call_or_return_candidate (mode,
  1478. type,
  1479. &pcum->aapcs_vfp_rmode,
  1480. nregs,
  1481. NULL);
  1482. }
  1483. /* Given MODE and TYPE of a function argument, return the alignment in
  1484. bits. The idea is to suppress any stronger alignment requested by
  1485. the user and opt for the natural alignment (specified in AAPCS64 \S 4.1).
  1486. This is a helper function for local use only. */
  1487. static unsigned int
  1488. aarch64_function_arg_alignment (machine_mode mode, const_tree type)
  1489. {
  1490. unsigned int alignment;
  1491. if (type)
  1492. {
  1493. if (!integer_zerop (TYPE_SIZE (type)))
  1494. {
  1495. if (TYPE_MODE (type) == mode)
  1496. alignment = TYPE_ALIGN (type);
  1497. else
  1498. alignment = GET_MODE_ALIGNMENT (mode);
  1499. }
  1500. else
  1501. alignment = 0;
  1502. }
  1503. else
  1504. alignment = GET_MODE_ALIGNMENT (mode);
  1505. return alignment;
  1506. }
  1507. /* Layout a function argument according to the AAPCS64 rules. The rule
  1508. numbers refer to the rule numbers in the AAPCS64. */
  1509. static void
  1510. aarch64_layout_arg (cumulative_args_t pcum_v, machine_mode mode,
  1511. const_tree type,
  1512. bool named ATTRIBUTE_UNUSED)
  1513. {
  1514. CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v);
  1515. int ncrn, nvrn, nregs;
  1516. bool allocate_ncrn, allocate_nvrn;
  1517. HOST_WIDE_INT size;
  1518. /* We need to do this once per argument. */
  1519. if (pcum->aapcs_arg_processed)
  1520. return;
  1521. pcum->aapcs_arg_processed = true;
  1522. /* Size in bytes, rounded to the nearest multiple of 8 bytes. */
  1523. size
  1524. = AARCH64_ROUND_UP (type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode),
  1525. UNITS_PER_WORD);
  1526. allocate_ncrn = (type) ? !(FLOAT_TYPE_P (type)) : !FLOAT_MODE_P (mode);
  1527. allocate_nvrn = aarch64_vfp_is_call_candidate (pcum_v,
  1528. mode,
  1529. type,
  1530. &nregs);
  1531. /* allocate_ncrn may be false-positive, but allocate_nvrn is quite reliable.
  1532. The following code thus handles passing by SIMD/FP registers first. */
  1533. nvrn = pcum->aapcs_nvrn;
  1534. /* C1 - C5 for floating point, homogenous floating point aggregates (HFA)
  1535. and homogenous short-vector aggregates (HVA). */
  1536. if (allocate_nvrn)
  1537. {
  1538. if (nvrn + nregs <= NUM_FP_ARG_REGS)
  1539. {
  1540. pcum->aapcs_nextnvrn = nvrn + nregs;
  1541. if (!aarch64_composite_type_p (type, mode))
  1542. {
  1543. gcc_assert (nregs == 1);
  1544. pcum->aapcs_reg = gen_rtx_REG (mode, V0_REGNUM + nvrn);
  1545. }
  1546. else
  1547. {
  1548. rtx par;
  1549. int i;
  1550. par = gen_rtx_PARALLEL (mode, rtvec_alloc (nregs));
  1551. for (i = 0; i < nregs; i++)
  1552. {
  1553. rtx tmp = gen_rtx_REG (pcum->aapcs_vfp_rmode,
  1554. V0_REGNUM + nvrn + i);
  1555. tmp = gen_rtx_EXPR_LIST
  1556. (VOIDmode, tmp,
  1557. GEN_INT (i * GET_MODE_SIZE (pcum->aapcs_vfp_rmode)));
  1558. XVECEXP (par, 0, i) = tmp;
  1559. }
  1560. pcum->aapcs_reg = par;
  1561. }
  1562. return;
  1563. }
  1564. else
  1565. {
  1566. /* C.3 NSRN is set to 8. */
  1567. pcum->aapcs_nextnvrn = NUM_FP_ARG_REGS;
  1568. goto on_stack;
  1569. }
  1570. }
  1571. ncrn = pcum->aapcs_ncrn;
  1572. nregs = size / UNITS_PER_WORD;
  1573. /* C6 - C9. though the sign and zero extension semantics are
  1574. handled elsewhere. This is the case where the argument fits
  1575. entirely general registers. */
  1576. if (allocate_ncrn && (ncrn + nregs <= NUM_ARG_REGS))
  1577. {
  1578. unsigned int alignment = aarch64_function_arg_alignment (mode, type);
  1579. gcc_assert (nregs == 0 || nregs == 1 || nregs == 2);
  1580. /* C.8 if the argument has an alignment of 16 then the NGRN is
  1581. rounded up to the next even number. */
  1582. if (nregs == 2 && alignment == 16 * BITS_PER_UNIT && ncrn % 2)
  1583. {
  1584. ++ncrn;
  1585. gcc_assert (ncrn + nregs <= NUM_ARG_REGS);
  1586. }
  1587. /* NREGS can be 0 when e.g. an empty structure is to be passed.
  1588. A reg is still generated for it, but the caller should be smart
  1589. enough not to use it. */
  1590. if (nregs == 0 || nregs == 1 || GET_MODE_CLASS (mode) == MODE_INT)
  1591. {
  1592. pcum->aapcs_reg = gen_rtx_REG (mode, R0_REGNUM + ncrn);
  1593. }
  1594. else
  1595. {
  1596. rtx par;
  1597. int i;
  1598. par = gen_rtx_PARALLEL (mode, rtvec_alloc (nregs));
  1599. for (i = 0; i < nregs; i++)
  1600. {
  1601. rtx tmp = gen_rtx_REG (word_mode, R0_REGNUM + ncrn + i);
  1602. tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp,
  1603. GEN_INT (i * UNITS_PER_WORD));
  1604. XVECEXP (par, 0, i) = tmp;
  1605. }
  1606. pcum->aapcs_reg = par;
  1607. }
  1608. pcum->aapcs_nextncrn = ncrn + nregs;
  1609. return;
  1610. }
  1611. /* C.11 */
  1612. pcum->aapcs_nextncrn = NUM_ARG_REGS;
  1613. /* The argument is passed on stack; record the needed number of words for
  1614. this argument and align the total size if necessary. */
  1615. on_stack:
  1616. pcum->aapcs_stack_words = size / UNITS_PER_WORD;
  1617. if (aarch64_function_arg_alignment (mode, type) == 16 * BITS_PER_UNIT)
  1618. pcum->aapcs_stack_size = AARCH64_ROUND_UP (pcum->aapcs_stack_size,
  1619. 16 / UNITS_PER_WORD);
  1620. return;
  1621. }
  1622. /* Implement TARGET_FUNCTION_ARG. */
  1623. static rtx
  1624. aarch64_function_arg (cumulative_args_t pcum_v, machine_mode mode,
  1625. const_tree type, bool named)
  1626. {
  1627. CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v);
  1628. gcc_assert (pcum->pcs_variant == ARM_PCS_AAPCS64);
  1629. if (mode == VOIDmode)
  1630. return NULL_RTX;
  1631. aarch64_layout_arg (pcum_v, mode, type, named);
  1632. return pcum->aapcs_reg;
  1633. }
  1634. void
  1635. aarch64_init_cumulative_args (CUMULATIVE_ARGS *pcum,
  1636. const_tree fntype ATTRIBUTE_UNUSED,
  1637. rtx libname ATTRIBUTE_UNUSED,
  1638. const_tree fndecl ATTRIBUTE_UNUSED,
  1639. unsigned n_named ATTRIBUTE_UNUSED)
  1640. {
  1641. pcum->aapcs_ncrn = 0;
  1642. pcum->aapcs_nvrn = 0;
  1643. pcum->aapcs_nextncrn = 0;
  1644. pcum->aapcs_nextnvrn = 0;
  1645. pcum->pcs_variant = ARM_PCS_AAPCS64;
  1646. pcum->aapcs_reg = NULL_RTX;
  1647. pcum->aapcs_arg_processed = false;
  1648. pcum->aapcs_stack_words = 0;
  1649. pcum->aapcs_stack_size = 0;
  1650. return;
  1651. }
  1652. static void
  1653. aarch64_function_arg_advance (cumulative_args_t pcum_v,
  1654. machine_mode mode,
  1655. const_tree type,
  1656. bool named)
  1657. {
  1658. CUMULATIVE_ARGS *pcum = get_cumulative_args (pcum_v);
  1659. if (pcum->pcs_variant == ARM_PCS_AAPCS64)
  1660. {
  1661. aarch64_layout_arg (pcum_v, mode, type, named);
  1662. gcc_assert ((pcum->aapcs_reg != NULL_RTX)
  1663. != (pcum->aapcs_stack_words != 0));
  1664. pcum->aapcs_arg_processed = false;
  1665. pcum->aapcs_ncrn = pcum->aapcs_nextncrn;
  1666. pcum->aapcs_nvrn = pcum->aapcs_nextnvrn;
  1667. pcum->aapcs_stack_size += pcum->aapcs_stack_words;
  1668. pcum->aapcs_stack_words = 0;
  1669. pcum->aapcs_reg = NULL_RTX;
  1670. }
  1671. }
  1672. bool
  1673. aarch64_function_arg_regno_p (unsigned regno)
  1674. {
  1675. return ((GP_REGNUM_P (regno) && regno < R0_REGNUM + NUM_ARG_REGS)
  1676. || (FP_REGNUM_P (regno) && regno < V0_REGNUM + NUM_FP_ARG_REGS));
  1677. }
  1678. /* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least
  1679. PARM_BOUNDARY bits of alignment, but will be given anything up
  1680. to STACK_BOUNDARY bits if the type requires it. This makes sure
  1681. that both before and after the layout of each argument, the Next
  1682. Stacked Argument Address (NSAA) will have a minimum alignment of
  1683. 8 bytes. */
  1684. static unsigned int
  1685. aarch64_function_arg_boundary (machine_mode mode, const_tree type)
  1686. {
  1687. unsigned int alignment = aarch64_function_arg_alignment (mode, type);
  1688. if (alignment < PARM_BOUNDARY)
  1689. alignment = PARM_BOUNDARY;
  1690. if (alignment > STACK_BOUNDARY)
  1691. alignment = STACK_BOUNDARY;
  1692. return alignment;
  1693. }
  1694. /* For use by FUNCTION_ARG_PADDING (MODE, TYPE).
  1695. Return true if an argument passed on the stack should be padded upwards,
  1696. i.e. if the least-significant byte of the stack slot has useful data.
  1697. Small aggregate types are placed in the lowest memory address.
  1698. The related parameter passing rules are B.4, C.3, C.5 and C.14. */
  1699. bool
  1700. aarch64_pad_arg_upward (machine_mode mode, const_tree type)
  1701. {
  1702. /* On little-endian targets, the least significant byte of every stack
  1703. argument is passed at the lowest byte address of the stack slot. */
  1704. if (!BYTES_BIG_ENDIAN)
  1705. return true;
  1706. /* Otherwise, integral, floating-point and pointer types are padded downward:
  1707. the least significant byte of a stack argument is passed at the highest
  1708. byte address of the stack slot. */
  1709. if (type
  1710. ? (INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type)
  1711. || POINTER_TYPE_P (type))
  1712. : (SCALAR_INT_MODE_P (mode) || SCALAR_FLOAT_MODE_P (mode)))
  1713. return false;
  1714. /* Everything else padded upward, i.e. data in first byte of stack slot. */
  1715. return true;
  1716. }
  1717. /* Similarly, for use by BLOCK_REG_PADDING (MODE, TYPE, FIRST).
  1718. It specifies padding for the last (may also be the only)
  1719. element of a block move between registers and memory. If
  1720. assuming the block is in the memory, padding upward means that
  1721. the last element is padded after its highest significant byte,
  1722. while in downward padding, the last element is padded at the
  1723. its least significant byte side.
  1724. Small aggregates and small complex types are always padded
  1725. upwards.
  1726. We don't need to worry about homogeneous floating-point or
  1727. short-vector aggregates; their move is not affected by the
  1728. padding direction determined here. Regardless of endianness,
  1729. each element of such an aggregate is put in the least
  1730. significant bits of a fp/simd register.
  1731. Return !BYTES_BIG_ENDIAN if the least significant byte of the
  1732. register has useful data, and return the opposite if the most
  1733. significant byte does. */
  1734. bool
  1735. aarch64_pad_reg_upward (machine_mode mode, const_tree type,
  1736. bool first ATTRIBUTE_UNUSED)
  1737. {
  1738. /* Small composite types are always padded upward. */
  1739. if (BYTES_BIG_ENDIAN && aarch64_composite_type_p (type, mode))
  1740. {
  1741. HOST_WIDE_INT size = (type ? int_size_in_bytes (type)
  1742. : GET_MODE_SIZE (mode));
  1743. if (size < 2 * UNITS_PER_WORD)
  1744. return true;
  1745. }
  1746. /* Otherwise, use the default padding. */
  1747. return !BYTES_BIG_ENDIAN;
  1748. }
  1749. static machine_mode
  1750. aarch64_libgcc_cmp_return_mode (void)
  1751. {
  1752. return SImode;
  1753. }
  1754. static bool
  1755. aarch64_frame_pointer_required (void)
  1756. {
  1757. /* In aarch64_override_options_after_change
  1758. flag_omit_leaf_frame_pointer turns off the frame pointer by
  1759. default. Turn it back on now if we've not got a leaf
  1760. function. */
  1761. if (flag_omit_leaf_frame_pointer
  1762. && (!crtl->is_leaf || df_regs_ever_live_p (LR_REGNUM)))
  1763. return true;
  1764. return false;
  1765. }
  1766. /* Mark the registers that need to be saved by the callee and calculate
  1767. the size of the callee-saved registers area and frame record (both FP
  1768. and LR may be omitted). */
  1769. static void
  1770. aarch64_layout_frame (void)
  1771. {
  1772. HOST_WIDE_INT offset = 0;
  1773. int regno;
  1774. if (reload_completed && cfun->machine->frame.laid_out)
  1775. return;
  1776. #define SLOT_NOT_REQUIRED (-2)
  1777. #define SLOT_REQUIRED (-1)
  1778. cfun->machine->frame.wb_candidate1 = FIRST_PSEUDO_REGISTER;
  1779. cfun->machine->frame.wb_candidate2 = FIRST_PSEUDO_REGISTER;
  1780. /* First mark all the registers that really need to be saved... */
  1781. for (regno = R0_REGNUM; regno <= R30_REGNUM; regno++)
  1782. cfun->machine->frame.reg_offset[regno] = SLOT_NOT_REQUIRED;
  1783. for (regno = V0_REGNUM; regno <= V31_REGNUM; regno++)
  1784. cfun->machine->frame.reg_offset[regno] = SLOT_NOT_REQUIRED;
  1785. /* ... that includes the eh data registers (if needed)... */
  1786. if (crtl->calls_eh_return)
  1787. for (regno = 0; EH_RETURN_DATA_REGNO (regno) != INVALID_REGNUM; regno++)
  1788. cfun->machine->frame.reg_offset[EH_RETURN_DATA_REGNO (regno)]
  1789. = SLOT_REQUIRED;
  1790. /* ... and any callee saved register that dataflow says is live. */
  1791. for (regno = R0_REGNUM; regno <= R30_REGNUM; regno++)
  1792. if (df_regs_ever_live_p (regno)
  1793. && (regno == R30_REGNUM
  1794. || !call_used_regs[regno]))
  1795. cfun->machine->frame.reg_offset[regno] = SLOT_REQUIRED;
  1796. for (regno = V0_REGNUM; regno <= V31_REGNUM; regno++)
  1797. if (df_regs_ever_live_p (regno)
  1798. && !call_used_regs[regno])
  1799. cfun->machine->frame.reg_offset[regno] = SLOT_REQUIRED;
  1800. if (frame_pointer_needed)
  1801. {
  1802. /* FP and LR are placed in the linkage record. */
  1803. cfun->machine->frame.reg_offset[R29_REGNUM] = 0;
  1804. cfun->machine->frame.wb_candidate1 = R29_REGNUM;
  1805. cfun->machine->frame.reg_offset[R30_REGNUM] = UNITS_PER_WORD;
  1806. cfun->machine->frame.wb_candidate2 = R30_REGNUM;
  1807. cfun->machine->frame.hardfp_offset = 2 * UNITS_PER_WORD;
  1808. offset += 2 * UNITS_PER_WORD;
  1809. }
  1810. /* Now assign stack slots for them. */
  1811. for (regno = R0_REGNUM; regno <= R30_REGNUM; regno++)
  1812. if (cfun->machine->frame.reg_offset[regno] == SLOT_REQUIRED)
  1813. {
  1814. cfun->machine->frame.reg_offset[regno] = offset;
  1815. if (cfun->machine->frame.wb_candidate1 == FIRST_PSEUDO_REGISTER)
  1816. cfun->machine->frame.wb_candidate1 = regno;
  1817. else if (cfun->machine->frame.wb_candidate2 == FIRST_PSEUDO_REGISTER)
  1818. cfun->machine->frame.wb_candidate2 = regno;
  1819. offset += UNITS_PER_WORD;
  1820. }
  1821. for (regno = V0_REGNUM; regno <= V31_REGNUM; regno++)
  1822. if (cfun->machine->frame.reg_offset[regno] == SLOT_REQUIRED)
  1823. {
  1824. cfun->machine->frame.reg_offset[regno] = offset;
  1825. if (cfun->machine->frame.wb_candidate1 == FIRST_PSEUDO_REGISTER)
  1826. cfun->machine->frame.wb_candidate1 = regno;
  1827. else if (cfun->machine->frame.wb_candidate2 == FIRST_PSEUDO_REGISTER
  1828. && cfun->machine->frame.wb_candidate1 >= V0_REGNUM)
  1829. cfun->machine->frame.wb_candidate2 = regno;
  1830. offset += UNITS_PER_WORD;
  1831. }
  1832. cfun->machine->frame.padding0 =
  1833. (AARCH64_ROUND_UP (offset, STACK_BOUNDARY / BITS_PER_UNIT) - offset);
  1834. offset = AARCH64_ROUND_UP (offset, STACK_BOUNDARY / BITS_PER_UNIT);
  1835. cfun->machine->frame.saved_regs_size = offset;
  1836. cfun->machine->frame.hard_fp_offset
  1837. = AARCH64_ROUND_UP (cfun->machine->frame.saved_varargs_size
  1838. + get_frame_size ()
  1839. + cfun->machine->frame.saved_regs_size,
  1840. STACK_BOUNDARY / BITS_PER_UNIT);
  1841. cfun->machine->frame.frame_size
  1842. = AARCH64_ROUND_UP (cfun->machine->frame.hard_fp_offset
  1843. + crtl->outgoing_args_size,
  1844. STACK_BOUNDARY / BITS_PER_UNIT);
  1845. cfun->machine->frame.laid_out = true;
  1846. }
  1847. static bool
  1848. aarch64_register_saved_on_entry (int regno)
  1849. {
  1850. return cfun->machine->frame.reg_offset[regno] >= 0;
  1851. }
  1852. static unsigned
  1853. aarch64_next_callee_save (unsigned regno, unsigned limit)
  1854. {
  1855. while (regno <= limit && !aarch64_register_saved_on_entry (regno))
  1856. regno ++;
  1857. return regno;
  1858. }
  1859. static void
  1860. aarch64_pushwb_single_reg (machine_mode mode, unsigned regno,
  1861. HOST_WIDE_INT adjustment)
  1862. {
  1863. rtx base_rtx = stack_pointer_rtx;
  1864. rtx insn, reg, mem;
  1865. reg = gen_rtx_REG (mode, regno);
  1866. mem = gen_rtx_PRE_MODIFY (Pmode, base_rtx,
  1867. plus_constant (Pmode, base_rtx, -adjustment));
  1868. mem = gen_rtx_MEM (mode, mem);
  1869. insn = emit_move_insn (mem, reg);
  1870. RTX_FRAME_RELATED_P (insn) = 1;
  1871. }
  1872. static rtx
  1873. aarch64_gen_storewb_pair (machine_mode mode, rtx base, rtx reg, rtx reg2,
  1874. HOST_WIDE_INT adjustment)
  1875. {
  1876. switch (mode)
  1877. {
  1878. case DImode:
  1879. return gen_storewb_pairdi_di (base, base, reg, reg2,
  1880. GEN_INT (-adjustment),
  1881. GEN_INT (UNITS_PER_WORD - adjustment));
  1882. case DFmode:
  1883. return gen_storewb_pairdf_di (base, base, reg, reg2,
  1884. GEN_INT (-adjustment),
  1885. GEN_INT (UNITS_PER_WORD - adjustment));
  1886. default:
  1887. gcc_unreachable ();
  1888. }
  1889. }
  1890. static void
  1891. aarch64_pushwb_pair_reg (machine_mode mode, unsigned regno1,
  1892. unsigned regno2, HOST_WIDE_INT adjustment)
  1893. {
  1894. rtx_insn *insn;
  1895. rtx reg1 = gen_rtx_REG (mode, regno1);
  1896. rtx reg2 = gen_rtx_REG (mode, regno2);
  1897. insn = emit_insn (aarch64_gen_storewb_pair (mode, stack_pointer_rtx, reg1,
  1898. reg2, adjustment));
  1899. RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 2)) = 1;
  1900. RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
  1901. RTX_FRAME_RELATED_P (insn) = 1;
  1902. }
  1903. static rtx
  1904. aarch64_gen_loadwb_pair (machine_mode mode, rtx base, rtx reg, rtx reg2,
  1905. HOST_WIDE_INT adjustment)
  1906. {
  1907. switch (mode)
  1908. {
  1909. case DImode:
  1910. return gen_loadwb_pairdi_di (base, base, reg, reg2, GEN_INT (adjustment),
  1911. GEN_INT (UNITS_PER_WORD));
  1912. case DFmode:
  1913. return gen_loadwb_pairdf_di (base, base, reg, reg2, GEN_INT (adjustment),
  1914. GEN_INT (UNITS_PER_WORD));
  1915. default:
  1916. gcc_unreachable ();
  1917. }
  1918. }
  1919. static rtx
  1920. aarch64_gen_store_pair (machine_mode mode, rtx mem1, rtx reg1, rtx mem2,
  1921. rtx reg2)
  1922. {
  1923. switch (mode)
  1924. {
  1925. case DImode:
  1926. return gen_store_pairdi (mem1, reg1, mem2, reg2);
  1927. case DFmode:
  1928. return gen_store_pairdf (mem1, reg1, mem2, reg2);
  1929. default:
  1930. gcc_unreachable ();
  1931. }
  1932. }
  1933. static rtx
  1934. aarch64_gen_load_pair (machine_mode mode, rtx reg1, rtx mem1, rtx reg2,
  1935. rtx mem2)
  1936. {
  1937. switch (mode)
  1938. {
  1939. case DImode:
  1940. return gen_load_pairdi (reg1, mem1, reg2, mem2);
  1941. case DFmode:
  1942. return gen_load_pairdf (reg1, mem1, reg2, mem2);
  1943. default:
  1944. gcc_unreachable ();
  1945. }
  1946. }
  1947. static void
  1948. aarch64_save_callee_saves (machine_mode mode, HOST_WIDE_INT start_offset,
  1949. unsigned start, unsigned limit, bool skip_wb)
  1950. {
  1951. rtx_insn *insn;
  1952. rtx (*gen_mem_ref) (machine_mode, rtx) = (frame_pointer_needed
  1953. ? gen_frame_mem : gen_rtx_MEM);
  1954. unsigned regno;
  1955. unsigned regno2;
  1956. for (regno = aarch64_next_callee_save (start, limit);
  1957. regno <= limit;
  1958. regno = aarch64_next_callee_save (regno + 1, limit))
  1959. {
  1960. rtx reg, mem;
  1961. HOST_WIDE_INT offset;
  1962. if (skip_wb
  1963. && (regno == cfun->machine->frame.wb_candidate1
  1964. || regno == cfun->machine->frame.wb_candidate2))
  1965. continue;
  1966. reg = gen_rtx_REG (mode, regno);
  1967. offset = start_offset + cfun->machine->frame.reg_offset[regno];
  1968. mem = gen_mem_ref (mode, plus_constant (Pmode, stack_pointer_rtx,
  1969. offset));
  1970. regno2 = aarch64_next_callee_save (regno + 1, limit);
  1971. if (regno2 <= limit
  1972. && ((cfun->machine->frame.reg_offset[regno] + UNITS_PER_WORD)
  1973. == cfun->machine->frame.reg_offset[regno2]))
  1974. {
  1975. rtx reg2 = gen_rtx_REG (mode, regno2);
  1976. rtx mem2;
  1977. offset = start_offset + cfun->machine->frame.reg_offset[regno2];
  1978. mem2 = gen_mem_ref (mode, plus_constant (Pmode, stack_pointer_rtx,
  1979. offset));
  1980. insn = emit_insn (aarch64_gen_store_pair (mode, mem, reg, mem2,
  1981. reg2));
  1982. /* The first part of a frame-related parallel insn is
  1983. always assumed to be relevant to the frame
  1984. calculations; subsequent parts, are only
  1985. frame-related if explicitly marked. */
  1986. RTX_FRAME_RELATED_P (XVECEXP (PATTERN (insn), 0, 1)) = 1;
  1987. regno = regno2;
  1988. }
  1989. else
  1990. insn = emit_move_insn (mem, reg);
  1991. RTX_FRAME_RELATED_P (insn) = 1;
  1992. }
  1993. }
  1994. static void
  1995. aarch64_restore_callee_saves (machine_mode mode,
  1996. HOST_WIDE_INT start_offset, unsigned start,
  1997. unsigned limit, bool skip_wb, rtx *cfi_ops)
  1998. {
  1999. rtx base_rtx = stack_pointer_rtx;
  2000. rtx (*gen_mem_ref) (machine_mode, rtx) = (frame_pointer_needed
  2001. ? gen_frame_mem : gen_rtx_MEM);
  2002. unsigned regno;
  2003. unsigned regno2;
  2004. HOST_WIDE_INT offset;
  2005. for (regno = aarch64_next_callee_save (start, limit);
  2006. regno <= limit;
  2007. regno = aarch64_next_callee_save (regno + 1, limit))
  2008. {
  2009. rtx reg, mem;
  2010. if (skip_wb
  2011. && (regno == cfun->machine->frame.wb_candidate1
  2012. || regno == cfun->machine->frame.wb_candidate2))
  2013. continue;
  2014. reg = gen_rtx_REG (mode, regno);
  2015. offset = start_offset + cfun->machine->frame.reg_offset[regno];
  2016. mem = gen_mem_ref (mode, plus_constant (Pmode, base_rtx, offset));
  2017. regno2 = aarch64_next_callee_save (regno + 1, limit);
  2018. if (regno2 <= limit
  2019. && ((cfun->machine->frame.reg_offset[regno] + UNITS_PER_WORD)
  2020. == cfun->machine->frame.reg_offset[regno2]))
  2021. {
  2022. rtx reg2 = gen_rtx_REG (mode, regno2);
  2023. rtx mem2;
  2024. offset = start_offset + cfun->machine->frame.reg_offset[regno2];
  2025. mem2 = gen_mem_ref (mode, plus_constant (Pmode, base_rtx, offset));
  2026. emit_insn (aarch64_gen_load_pair (mode, reg, mem, reg2, mem2));
  2027. *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg2, *cfi_ops);
  2028. regno = regno2;
  2029. }
  2030. else
  2031. emit_move_insn (reg, mem);
  2032. *cfi_ops = alloc_reg_note (REG_CFA_RESTORE, reg, *cfi_ops);
  2033. }
  2034. }
  2035. /* AArch64 stack frames generated by this compiler look like:
  2036. +-------------------------------+
  2037. | |
  2038. | incoming stack arguments |
  2039. | |
  2040. +-------------------------------+
  2041. | | <-- incoming stack pointer (aligned)
  2042. | callee-allocated save area |
  2043. | for register varargs |
  2044. | |
  2045. +-------------------------------+
  2046. | local variables | <-- frame_pointer_rtx
  2047. | |
  2048. +-------------------------------+
  2049. | padding0 | \
  2050. +-------------------------------+ |
  2051. | callee-saved registers | | frame.saved_regs_size
  2052. +-------------------------------+ |
  2053. | LR' | |
  2054. +-------------------------------+ |
  2055. | FP' | / <- hard_frame_pointer_rtx (aligned)
  2056. +-------------------------------+
  2057. | dynamic allocation |
  2058. +-------------------------------+
  2059. | padding |
  2060. +-------------------------------+
  2061. | outgoing stack arguments | <-- arg_pointer
  2062. | |
  2063. +-------------------------------+
  2064. | | <-- stack_pointer_rtx (aligned)
  2065. Dynamic stack allocations via alloca() decrease stack_pointer_rtx
  2066. but leave frame_pointer_rtx and hard_frame_pointer_rtx
  2067. unchanged. */
  2068. /* Generate the prologue instructions for entry into a function.
  2069. Establish the stack frame by decreasing the stack pointer with a
  2070. properly calculated size and, if necessary, create a frame record
  2071. filled with the values of LR and previous frame pointer. The
  2072. current FP is also set up if it is in use. */
  2073. void
  2074. aarch64_expand_prologue (void)
  2075. {
  2076. /* sub sp, sp, #<frame_size>
  2077. stp {fp, lr}, [sp, #<frame_size> - 16]
  2078. add fp, sp, #<frame_size> - hardfp_offset
  2079. stp {cs_reg}, [fp, #-16] etc.
  2080. sub sp, sp, <final_adjustment_if_any>
  2081. */
  2082. HOST_WIDE_INT frame_size, offset;
  2083. HOST_WIDE_INT fp_offset; /* Offset from hard FP to SP. */
  2084. HOST_WIDE_INT hard_fp_offset;
  2085. rtx_insn *insn;
  2086. aarch64_layout_frame ();
  2087. offset = frame_size = cfun->machine->frame.frame_size;
  2088. hard_fp_offset = cfun->machine->frame.hard_fp_offset;
  2089. fp_offset = frame_size - hard_fp_offset;
  2090. if (flag_stack_usage_info)
  2091. current_function_static_stack_size = frame_size;
  2092. /* Store pairs and load pairs have a range only -512 to 504. */
  2093. if (offset >= 512)
  2094. {
  2095. /* When the frame has a large size, an initial decrease is done on
  2096. the stack pointer to jump over the callee-allocated save area for
  2097. register varargs, the local variable area and/or the callee-saved
  2098. register area. This will allow the pre-index write-back
  2099. store pair instructions to be used for setting up the stack frame
  2100. efficiently. */
  2101. offset = hard_fp_offset;
  2102. if (offset >= 512)
  2103. offset = cfun->machine->frame.saved_regs_size;
  2104. frame_size -= (offset + crtl->outgoing_args_size);
  2105. fp_offset = 0;
  2106. if (frame_size >= 0x1000000)
  2107. {
  2108. rtx op0 = gen_rtx_REG (Pmode, IP0_REGNUM);
  2109. emit_move_insn (op0, GEN_INT (-frame_size));
  2110. insn = emit_insn (gen_add2_insn (stack_pointer_rtx, op0));
  2111. add_reg_note (insn, REG_CFA_ADJUST_CFA,
  2112. gen_rtx_SET (VOIDmode, stack_pointer_rtx,
  2113. plus_constant (Pmode, stack_pointer_rtx,
  2114. -frame_size)));
  2115. RTX_FRAME_RELATED_P (insn) = 1;
  2116. }
  2117. else if (frame_size > 0)
  2118. {
  2119. int hi_ofs = frame_size & 0xfff000;
  2120. int lo_ofs = frame_size & 0x000fff;
  2121. if (hi_ofs)
  2122. {
  2123. insn = emit_insn (gen_add2_insn
  2124. (stack_pointer_rtx, GEN_INT (-hi_ofs)));
  2125. RTX_FRAME_RELATED_P (insn) = 1;
  2126. }
  2127. if (lo_ofs)
  2128. {
  2129. insn = emit_insn (gen_add2_insn
  2130. (stack_pointer_rtx, GEN_INT (-lo_ofs)));
  2131. RTX_FRAME_RELATED_P (insn) = 1;
  2132. }
  2133. }
  2134. }
  2135. else
  2136. frame_size = -1;
  2137. if (offset > 0)
  2138. {
  2139. bool skip_wb = false;
  2140. if (frame_pointer_needed)
  2141. {
  2142. skip_wb = true;
  2143. if (fp_offset)
  2144. {
  2145. insn = emit_insn (gen_add2_insn (stack_pointer_rtx,
  2146. GEN_INT (-offset)));
  2147. RTX_FRAME_RELATED_P (insn) = 1;
  2148. aarch64_save_callee_saves (DImode, fp_offset, R29_REGNUM,
  2149. R30_REGNUM, false);
  2150. }
  2151. else
  2152. aarch64_pushwb_pair_reg (DImode, R29_REGNUM, R30_REGNUM, offset);
  2153. /* Set up frame pointer to point to the location of the
  2154. previous frame pointer on the stack. */
  2155. insn = emit_insn (gen_add3_insn (hard_frame_pointer_rtx,
  2156. stack_pointer_rtx,
  2157. GEN_INT (fp_offset)));
  2158. RTX_FRAME_RELATED_P (insn) = 1;
  2159. emit_insn (gen_stack_tie (stack_pointer_rtx, hard_frame_pointer_rtx));
  2160. }
  2161. else
  2162. {
  2163. unsigned reg1 = cfun->machine->frame.wb_candidate1;
  2164. unsigned reg2 = cfun->machine->frame.wb_candidate2;
  2165. if (fp_offset
  2166. || reg1 == FIRST_PSEUDO_REGISTER
  2167. || (reg2 == FIRST_PSEUDO_REGISTER
  2168. && offset >= 256))
  2169. {
  2170. insn = emit_insn (gen_add2_insn (stack_pointer_rtx,
  2171. GEN_INT (-offset)));
  2172. RTX_FRAME_RELATED_P (insn) = 1;
  2173. }
  2174. else
  2175. {
  2176. machine_mode mode1 = (reg1 <= R30_REGNUM) ? DImode : DFmode;
  2177. skip_wb = true;
  2178. if (reg2 == FIRST_PSEUDO_REGISTER)
  2179. aarch64_pushwb_single_reg (mode1, reg1, offset);
  2180. else
  2181. aarch64_pushwb_pair_reg (mode1, reg1, reg2, offset);
  2182. }
  2183. }
  2184. aarch64_save_callee_saves (DImode, fp_offset, R0_REGNUM, R30_REGNUM,
  2185. skip_wb);
  2186. aarch64_save_callee_saves (DFmode, fp_offset, V0_REGNUM, V31_REGNUM,
  2187. skip_wb);
  2188. }
  2189. /* when offset >= 512,
  2190. sub sp, sp, #<outgoing_args_size> */
  2191. if (frame_size > -1)
  2192. {
  2193. if (crtl->outgoing_args_size > 0)
  2194. {
  2195. insn = emit_insn (gen_add2_insn
  2196. (stack_pointer_rtx,
  2197. GEN_INT (- crtl->outgoing_args_size)));
  2198. RTX_FRAME_RELATED_P (insn) = 1;
  2199. }
  2200. }
  2201. }
  2202. /* Return TRUE if we can use a simple_return insn.
  2203. This function checks whether the callee saved stack is empty, which
  2204. means no restore actions are need. The pro_and_epilogue will use
  2205. this to check whether shrink-wrapping opt is feasible. */
  2206. bool
  2207. aarch64_use_return_insn_p (void)
  2208. {
  2209. if (!reload_completed)
  2210. return false;
  2211. if (crtl->profile)
  2212. return false;
  2213. aarch64_layout_frame ();
  2214. return cfun->machine->frame.frame_size == 0;
  2215. }
  2216. /* Generate the epilogue instructions for returning from a function. */
  2217. void
  2218. aarch64_expand_epilogue (bool for_sibcall)
  2219. {
  2220. HOST_WIDE_INT frame_size, offset;
  2221. HOST_WIDE_INT fp_offset;
  2222. HOST_WIDE_INT hard_fp_offset;
  2223. rtx_insn *insn;
  2224. /* We need to add memory barrier to prevent read from deallocated stack. */
  2225. bool need_barrier_p = (get_frame_size () != 0
  2226. || cfun->machine->frame.saved_varargs_size);
  2227. aarch64_layout_frame ();
  2228. offset = frame_size = cfun->machine->frame.frame_size;
  2229. hard_fp_offset = cfun->machine->frame.hard_fp_offset;
  2230. fp_offset = frame_size - hard_fp_offset;
  2231. /* Store pairs and load pairs have a range only -512 to 504. */
  2232. if (offset >= 512)
  2233. {
  2234. offset = hard_fp_offset;
  2235. if (offset >= 512)
  2236. offset = cfun->machine->frame.saved_regs_size;
  2237. frame_size -= (offset + crtl->outgoing_args_size);
  2238. fp_offset = 0;
  2239. if (!frame_pointer_needed && crtl->outgoing_args_size > 0)
  2240. {
  2241. insn = emit_insn (gen_add2_insn
  2242. (stack_pointer_rtx,
  2243. GEN_INT (crtl->outgoing_args_size)));
  2244. RTX_FRAME_RELATED_P (insn) = 1;
  2245. }
  2246. }
  2247. else
  2248. frame_size = -1;
  2249. /* If there were outgoing arguments or we've done dynamic stack
  2250. allocation, then restore the stack pointer from the frame
  2251. pointer. This is at most one insn and more efficient than using
  2252. GCC's internal mechanism. */
  2253. if (frame_pointer_needed
  2254. && (crtl->outgoing_args_size || cfun->calls_alloca))
  2255. {
  2256. if (cfun->calls_alloca)
  2257. emit_insn (gen_stack_tie (stack_pointer_rtx, stack_pointer_rtx));
  2258. insn = emit_insn (gen_add3_insn (stack_pointer_rtx,
  2259. hard_frame_pointer_rtx,
  2260. GEN_INT (0)));
  2261. offset = offset - fp_offset;
  2262. }
  2263. if (offset > 0)
  2264. {
  2265. unsigned reg1 = cfun->machine->frame.wb_candidate1;
  2266. unsigned reg2 = cfun->machine->frame.wb_candidate2;
  2267. bool skip_wb = true;
  2268. rtx cfi_ops = NULL;
  2269. if (frame_pointer_needed)
  2270. fp_offset = 0;
  2271. else if (fp_offset
  2272. || reg1 == FIRST_PSEUDO_REGISTER
  2273. || (reg2 == FIRST_PSEUDO_REGISTER
  2274. && offset >= 256))
  2275. skip_wb = false;
  2276. aarch64_restore_callee_saves (DImode, fp_offset, R0_REGNUM, R30_REGNUM,
  2277. skip_wb, &cfi_ops);
  2278. aarch64_restore_callee_saves (DFmode, fp_offset, V0_REGNUM, V31_REGNUM,
  2279. skip_wb, &cfi_ops);
  2280. if (need_barrier_p)
  2281. emit_insn (gen_stack_tie (stack_pointer_rtx, stack_pointer_rtx));
  2282. if (skip_wb)
  2283. {
  2284. machine_mode mode1 = (reg1 <= R30_REGNUM) ? DImode : DFmode;
  2285. rtx rreg1 = gen_rtx_REG (mode1, reg1);
  2286. cfi_ops = alloc_reg_note (REG_CFA_RESTORE, rreg1, cfi_ops);
  2287. if (reg2 == FIRST_PSEUDO_REGISTER)
  2288. {
  2289. rtx mem = plus_constant (Pmode, stack_pointer_rtx, offset);
  2290. mem = gen_rtx_POST_MODIFY (Pmode, stack_pointer_rtx, mem);
  2291. mem = gen_rtx_MEM (mode1, mem);
  2292. insn = emit_move_insn (rreg1, mem);
  2293. }
  2294. else
  2295. {
  2296. rtx rreg2 = gen_rtx_REG (mode1, reg2);
  2297. cfi_ops = alloc_reg_note (REG_CFA_RESTORE, rreg2, cfi_ops);
  2298. insn = emit_insn (aarch64_gen_loadwb_pair
  2299. (mode1, stack_pointer_rtx, rreg1,
  2300. rreg2, offset));
  2301. }
  2302. }
  2303. else
  2304. {
  2305. insn = emit_insn (gen_add2_insn (stack_pointer_rtx,
  2306. GEN_INT (offset)));
  2307. }
  2308. /* Reset the CFA to be SP + FRAME_SIZE. */
  2309. rtx new_cfa = stack_pointer_rtx;
  2310. if (frame_size > 0)
  2311. new_cfa = plus_constant (Pmode, new_cfa, frame_size);
  2312. cfi_ops = alloc_reg_note (REG_CFA_DEF_CFA, new_cfa, cfi_ops);
  2313. REG_NOTES (insn) = cfi_ops;
  2314. RTX_FRAME_RELATED_P (insn) = 1;
  2315. }
  2316. if (frame_size > 0)
  2317. {
  2318. if (need_barrier_p)
  2319. emit_insn (gen_stack_tie (stack_pointer_rtx, stack_pointer_rtx));
  2320. if (frame_size >= 0x1000000)
  2321. {
  2322. rtx op0 = gen_rtx_REG (Pmode, IP0_REGNUM);
  2323. emit_move_insn (op0, GEN_INT (frame_size));
  2324. insn = emit_insn (gen_add2_insn (stack_pointer_rtx, op0));
  2325. }
  2326. else
  2327. {
  2328. int hi_ofs = frame_size & 0xfff000;
  2329. int lo_ofs = frame_size & 0x000fff;
  2330. if (hi_ofs && lo_ofs)
  2331. {
  2332. insn = emit_insn (gen_add2_insn
  2333. (stack_pointer_rtx, GEN_INT (hi_ofs)));
  2334. RTX_FRAME_RELATED_P (insn) = 1;
  2335. frame_size = lo_ofs;
  2336. }
  2337. insn = emit_insn (gen_add2_insn
  2338. (stack_pointer_rtx, GEN_INT (frame_size)));
  2339. }
  2340. /* Reset the CFA to be SP + 0. */
  2341. add_reg_note (insn, REG_CFA_DEF_CFA, stack_pointer_rtx);
  2342. RTX_FRAME_RELATED_P (insn) = 1;
  2343. }
  2344. /* Stack adjustment for exception handler. */
  2345. if (crtl->calls_eh_return)
  2346. {
  2347. /* We need to unwind the stack by the offset computed by
  2348. EH_RETURN_STACKADJ_RTX. We have already reset the CFA
  2349. to be SP; letting the CFA move during this adjustment
  2350. is just as correct as retaining the CFA from the body
  2351. of the function. Therefore, do nothing special. */
  2352. emit_insn (gen_add2_insn (stack_pointer_rtx, EH_RETURN_STACKADJ_RTX));
  2353. }
  2354. emit_use (gen_rtx_REG (DImode, LR_REGNUM));
  2355. if (!for_sibcall)
  2356. emit_jump_insn (ret_rtx);
  2357. }
  2358. /* Return the place to copy the exception unwinding return address to.
  2359. This will probably be a stack slot, but could (in theory be the
  2360. return register). */
  2361. rtx
  2362. aarch64_final_eh_return_addr (void)
  2363. {
  2364. HOST_WIDE_INT fp_offset;
  2365. aarch64_layout_frame ();
  2366. fp_offset = cfun->machine->frame.frame_size
  2367. - cfun->machine->frame.hard_fp_offset;
  2368. if (cfun->machine->frame.reg_offset[LR_REGNUM] < 0)
  2369. return gen_rtx_REG (DImode, LR_REGNUM);
  2370. /* DSE and CSELIB do not detect an alias between sp+k1 and fp+k2. This can
  2371. result in a store to save LR introduced by builtin_eh_return () being
  2372. incorrectly deleted because the alias is not detected.
  2373. So in the calculation of the address to copy the exception unwinding
  2374. return address to, we note 2 cases.
  2375. If FP is needed and the fp_offset is 0, it means that SP = FP and hence
  2376. we return a SP-relative location since all the addresses are SP-relative
  2377. in this case. This prevents the store from being optimized away.
  2378. If the fp_offset is not 0, then the addresses will be FP-relative and
  2379. therefore we return a FP-relative location. */
  2380. if (frame_pointer_needed)
  2381. {
  2382. if (fp_offset)
  2383. return gen_frame_mem (DImode,
  2384. plus_constant (Pmode, hard_frame_pointer_rtx, UNITS_PER_WORD));
  2385. else
  2386. return gen_frame_mem (DImode,
  2387. plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD));
  2388. }
  2389. /* If FP is not needed, we calculate the location of LR, which would be
  2390. at the top of the saved registers block. */
  2391. return gen_frame_mem (DImode,
  2392. plus_constant (Pmode,
  2393. stack_pointer_rtx,
  2394. fp_offset
  2395. + cfun->machine->frame.saved_regs_size
  2396. - 2 * UNITS_PER_WORD));
  2397. }
  2398. /* Possibly output code to build up a constant in a register. For
  2399. the benefit of the costs infrastructure, returns the number of
  2400. instructions which would be emitted. GENERATE inhibits or
  2401. enables code generation. */
  2402. static int
  2403. aarch64_build_constant (int regnum, HOST_WIDE_INT val, bool generate)
  2404. {
  2405. int insns = 0;
  2406. if (aarch64_bitmask_imm (val, DImode))
  2407. {
  2408. if (generate)
  2409. emit_move_insn (gen_rtx_REG (Pmode, regnum), GEN_INT (val));
  2410. insns = 1;
  2411. }
  2412. else
  2413. {
  2414. int i;
  2415. int ncount = 0;
  2416. int zcount = 0;
  2417. HOST_WIDE_INT valp = val >> 16;
  2418. HOST_WIDE_INT valm;
  2419. HOST_WIDE_INT tval;
  2420. for (i = 16; i < 64; i += 16)
  2421. {
  2422. valm = (valp & 0xffff);
  2423. if (valm != 0)
  2424. ++ zcount;
  2425. if (valm != 0xffff)
  2426. ++ ncount;
  2427. valp >>= 16;
  2428. }
  2429. /* zcount contains the number of additional MOVK instructions
  2430. required if the constant is built up with an initial MOVZ instruction,
  2431. while ncount is the number of MOVK instructions required if starting
  2432. with a MOVN instruction. Choose the sequence that yields the fewest
  2433. number of instructions, preferring MOVZ instructions when they are both
  2434. the same. */
  2435. if (ncount < zcount)
  2436. {
  2437. if (generate)
  2438. emit_move_insn (gen_rtx_REG (Pmode, regnum),
  2439. GEN_INT (val | ~(HOST_WIDE_INT) 0xffff));
  2440. tval = 0xffff;
  2441. insns++;
  2442. }
  2443. else
  2444. {
  2445. if (generate)
  2446. emit_move_insn (gen_rtx_REG (Pmode, regnum),
  2447. GEN_INT (val & 0xffff));
  2448. tval = 0;
  2449. insns++;
  2450. }
  2451. val >>= 16;
  2452. for (i = 16; i < 64; i += 16)
  2453. {
  2454. if ((val & 0xffff) != tval)
  2455. {
  2456. if (generate)
  2457. emit_insn (gen_insv_immdi (gen_rtx_REG (Pmode, regnum),
  2458. GEN_INT (i),
  2459. GEN_INT (val & 0xffff)));
  2460. insns++;
  2461. }
  2462. val >>= 16;
  2463. }
  2464. }
  2465. return insns;
  2466. }
  2467. static void
  2468. aarch64_add_constant (int regnum, int scratchreg, HOST_WIDE_INT delta)
  2469. {
  2470. HOST_WIDE_INT mdelta = delta;
  2471. rtx this_rtx = gen_rtx_REG (Pmode, regnum);
  2472. rtx scratch_rtx = gen_rtx_REG (Pmode, scratchreg);
  2473. if (mdelta < 0)
  2474. mdelta = -mdelta;
  2475. if (mdelta >= 4096 * 4096)
  2476. {
  2477. (void) aarch64_build_constant (scratchreg, delta, true);
  2478. emit_insn (gen_add3_insn (this_rtx, this_rtx, scratch_rtx));
  2479. }
  2480. else if (mdelta > 0)
  2481. {
  2482. if (mdelta >= 4096)
  2483. {
  2484. emit_insn (gen_rtx_SET (Pmode, scratch_rtx, GEN_INT (mdelta / 4096)));
  2485. rtx shift = gen_rtx_ASHIFT (Pmode, scratch_rtx, GEN_INT (12));
  2486. if (delta < 0)
  2487. emit_insn (gen_rtx_SET (Pmode, this_rtx,
  2488. gen_rtx_MINUS (Pmode, this_rtx, shift)));
  2489. else
  2490. emit_insn (gen_rtx_SET (Pmode, this_rtx,
  2491. gen_rtx_PLUS (Pmode, this_rtx, shift)));
  2492. }
  2493. if (mdelta % 4096 != 0)
  2494. {
  2495. scratch_rtx = GEN_INT ((delta < 0 ? -1 : 1) * (mdelta % 4096));
  2496. emit_insn (gen_rtx_SET (Pmode, this_rtx,
  2497. gen_rtx_PLUS (Pmode, this_rtx, scratch_rtx)));
  2498. }
  2499. }
  2500. }
  2501. /* Output code to add DELTA to the first argument, and then jump
  2502. to FUNCTION. Used for C++ multiple inheritance. */
  2503. static void
  2504. aarch64_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED,
  2505. HOST_WIDE_INT delta,
  2506. HOST_WIDE_INT vcall_offset,
  2507. tree function)
  2508. {
  2509. /* The this pointer is always in x0. Note that this differs from
  2510. Arm where the this pointer maybe bumped to r1 if r0 is required
  2511. to return a pointer to an aggregate. On AArch64 a result value
  2512. pointer will be in x8. */
  2513. int this_regno = R0_REGNUM;
  2514. rtx this_rtx, temp0, temp1, addr, funexp;
  2515. rtx_insn *insn;
  2516. reload_completed = 1;
  2517. emit_note (NOTE_INSN_PROLOGUE_END);
  2518. if (vcall_offset == 0)
  2519. aarch64_add_constant (this_regno, IP1_REGNUM, delta);
  2520. else
  2521. {
  2522. gcc_assert ((vcall_offset & (POINTER_BYTES - 1)) == 0);
  2523. this_rtx = gen_rtx_REG (Pmode, this_regno);
  2524. temp0 = gen_rtx_REG (Pmode, IP0_REGNUM);
  2525. temp1 = gen_rtx_REG (Pmode, IP1_REGNUM);
  2526. addr = this_rtx;
  2527. if (delta != 0)
  2528. {
  2529. if (delta >= -256 && delta < 256)
  2530. addr = gen_rtx_PRE_MODIFY (Pmode, this_rtx,
  2531. plus_constant (Pmode, this_rtx, delta));
  2532. else
  2533. aarch64_add_constant (this_regno, IP1_REGNUM, delta);
  2534. }
  2535. if (Pmode == ptr_mode)
  2536. aarch64_emit_move (temp0, gen_rtx_MEM (ptr_mode, addr));
  2537. else
  2538. aarch64_emit_move (temp0,
  2539. gen_rtx_ZERO_EXTEND (Pmode,
  2540. gen_rtx_MEM (ptr_mode, addr)));
  2541. if (vcall_offset >= -256 && vcall_offset < 4096 * POINTER_BYTES)
  2542. addr = plus_constant (Pmode, temp0, vcall_offset);
  2543. else
  2544. {
  2545. (void) aarch64_build_constant (IP1_REGNUM, vcall_offset, true);
  2546. addr = gen_rtx_PLUS (Pmode, temp0, temp1);
  2547. }
  2548. if (Pmode == ptr_mode)
  2549. aarch64_emit_move (temp1, gen_rtx_MEM (ptr_mode,addr));
  2550. else
  2551. aarch64_emit_move (temp1,
  2552. gen_rtx_SIGN_EXTEND (Pmode,
  2553. gen_rtx_MEM (ptr_mode, addr)));
  2554. emit_insn (gen_add2_insn (this_rtx, temp1));
  2555. }
  2556. /* Generate a tail call to the target function. */
  2557. if (!TREE_USED (function))
  2558. {
  2559. assemble_external (function);
  2560. TREE_USED (function) = 1;
  2561. }
  2562. funexp = XEXP (DECL_RTL (function), 0);
  2563. funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
  2564. insn = emit_call_insn (gen_sibcall (funexp, const0_rtx, NULL_RTX));
  2565. SIBLING_CALL_P (insn) = 1;
  2566. insn = get_insns ();
  2567. shorten_branches (insn);
  2568. final_start_function (insn, file, 1);
  2569. final (insn, file, 1);
  2570. final_end_function ();
  2571. /* Stop pretending to be a post-reload pass. */
  2572. reload_completed = 0;
  2573. }
  2574. static bool
  2575. aarch64_tls_referenced_p (rtx x)
  2576. {
  2577. if (!TARGET_HAVE_TLS)
  2578. return false;
  2579. subrtx_iterator::array_type array;
  2580. FOR_EACH_SUBRTX (iter, array, x, ALL)
  2581. {
  2582. const_rtx x = *iter;
  2583. if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0)
  2584. return true;
  2585. /* Don't recurse into UNSPEC_TLS looking for TLS symbols; these are
  2586. TLS offsets, not real symbol references. */
  2587. if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS)
  2588. iter.skip_subrtxes ();
  2589. }
  2590. return false;
  2591. }
  2592. static int
  2593. aarch64_bitmasks_cmp (const void *i1, const void *i2)
  2594. {
  2595. const unsigned HOST_WIDE_INT *imm1 = (const unsigned HOST_WIDE_INT *) i1;
  2596. const unsigned HOST_WIDE_INT *imm2 = (const unsigned HOST_WIDE_INT *) i2;
  2597. if (*imm1 < *imm2)
  2598. return -1;
  2599. if (*imm1 > *imm2)
  2600. return +1;
  2601. return 0;
  2602. }
  2603. static void
  2604. aarch64_build_bitmask_table (void)
  2605. {
  2606. unsigned HOST_WIDE_INT mask, imm;
  2607. unsigned int log_e, e, s, r;
  2608. unsigned int nimms = 0;
  2609. for (log_e = 1; log_e <= 6; log_e++)
  2610. {
  2611. e = 1 << log_e;
  2612. if (e == 64)
  2613. mask = ~(HOST_WIDE_INT) 0;
  2614. else
  2615. mask = ((HOST_WIDE_INT) 1 << e) - 1;
  2616. for (s = 1; s < e; s++)
  2617. {
  2618. for (r = 0; r < e; r++)
  2619. {
  2620. /* set s consecutive bits to 1 (s < 64) */
  2621. imm = ((unsigned HOST_WIDE_INT)1 << s) - 1;
  2622. /* rotate right by r */
  2623. if (r != 0)
  2624. imm = ((imm >> r) | (imm << (e - r))) & mask;
  2625. /* replicate the constant depending on SIMD size */
  2626. switch (log_e) {
  2627. case 1: imm |= (imm << 2);
  2628. case 2: imm |= (imm << 4);
  2629. case 3: imm |= (imm << 8);
  2630. case 4: imm |= (imm << 16);
  2631. case 5: imm |= (imm << 32);
  2632. case 6:
  2633. break;
  2634. default:
  2635. gcc_unreachable ();
  2636. }
  2637. gcc_assert (nimms < AARCH64_NUM_BITMASKS);
  2638. aarch64_bitmasks[nimms++] = imm;
  2639. }
  2640. }
  2641. }
  2642. gcc_assert (nimms == AARCH64_NUM_BITMASKS);
  2643. qsort (aarch64_bitmasks, nimms, sizeof (aarch64_bitmasks[0]),
  2644. aarch64_bitmasks_cmp);
  2645. }
  2646. /* Return true if val can be encoded as a 12-bit unsigned immediate with
  2647. a left shift of 0 or 12 bits. */
  2648. bool
  2649. aarch64_uimm12_shift (HOST_WIDE_INT val)
  2650. {
  2651. return ((val & (((HOST_WIDE_INT) 0xfff) << 0)) == val
  2652. || (val & (((HOST_WIDE_INT) 0xfff) << 12)) == val
  2653. );
  2654. }
  2655. /* Return true if val is an immediate that can be loaded into a
  2656. register by a MOVZ instruction. */
  2657. static bool
  2658. aarch64_movw_imm (HOST_WIDE_INT val, machine_mode mode)
  2659. {
  2660. if (GET_MODE_SIZE (mode) > 4)
  2661. {
  2662. if ((val & (((HOST_WIDE_INT) 0xffff) << 32)) == val
  2663. || (val & (((HOST_WIDE_INT) 0xffff) << 48)) == val)
  2664. return 1;
  2665. }
  2666. else
  2667. {
  2668. /* Ignore sign extension. */
  2669. val &= (HOST_WIDE_INT) 0xffffffff;
  2670. }
  2671. return ((val & (((HOST_WIDE_INT) 0xffff) << 0)) == val
  2672. || (val & (((HOST_WIDE_INT) 0xffff) << 16)) == val);
  2673. }
  2674. /* Return true if val is a valid bitmask immediate. */
  2675. bool
  2676. aarch64_bitmask_imm (HOST_WIDE_INT val, machine_mode mode)
  2677. {
  2678. if (GET_MODE_SIZE (mode) < 8)
  2679. {
  2680. /* Replicate bit pattern. */
  2681. val &= (HOST_WIDE_INT) 0xffffffff;
  2682. val |= val << 32;
  2683. }
  2684. return bsearch (&val, aarch64_bitmasks, AARCH64_NUM_BITMASKS,
  2685. sizeof (aarch64_bitmasks[0]), aarch64_bitmasks_cmp) != NULL;
  2686. }
  2687. /* Return true if val is an immediate that can be loaded into a
  2688. register in a single instruction. */
  2689. bool
  2690. aarch64_move_imm (HOST_WIDE_INT val, machine_mode mode)
  2691. {
  2692. if (aarch64_movw_imm (val, mode) || aarch64_movw_imm (~val, mode))
  2693. return 1;
  2694. return aarch64_bitmask_imm (val, mode);
  2695. }
  2696. static bool
  2697. aarch64_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
  2698. {
  2699. rtx base, offset;
  2700. if (GET_CODE (x) == HIGH)
  2701. return true;
  2702. split_const (x, &base, &offset);
  2703. if (GET_CODE (base) == SYMBOL_REF || GET_CODE (base) == LABEL_REF)
  2704. {
  2705. if (aarch64_classify_symbol (base, offset, SYMBOL_CONTEXT_ADR)
  2706. != SYMBOL_FORCE_TO_MEM)
  2707. return true;
  2708. else
  2709. /* Avoid generating a 64-bit relocation in ILP32; leave
  2710. to aarch64_expand_mov_immediate to handle it properly. */
  2711. return mode != ptr_mode;
  2712. }
  2713. return aarch64_tls_referenced_p (x);
  2714. }
  2715. /* Return true if register REGNO is a valid index register.
  2716. STRICT_P is true if REG_OK_STRICT is in effect. */
  2717. bool
  2718. aarch64_regno_ok_for_index_p (int regno, bool strict_p)
  2719. {
  2720. if (!HARD_REGISTER_NUM_P (regno))
  2721. {
  2722. if (!strict_p)
  2723. return true;
  2724. if (!reg_renumber)
  2725. return false;
  2726. regno = reg_renumber[regno];
  2727. }
  2728. return GP_REGNUM_P (regno);
  2729. }
  2730. /* Return true if register REGNO is a valid base register for mode MODE.
  2731. STRICT_P is true if REG_OK_STRICT is in effect. */
  2732. bool
  2733. aarch64_regno_ok_for_base_p (int regno, bool strict_p)
  2734. {
  2735. if (!HARD_REGISTER_NUM_P (regno))
  2736. {
  2737. if (!strict_p)
  2738. return true;
  2739. if (!reg_renumber)
  2740. return false;
  2741. regno = reg_renumber[regno];
  2742. }
  2743. /* The fake registers will be eliminated to either the stack or
  2744. hard frame pointer, both of which are usually valid base registers.
  2745. Reload deals with the cases where the eliminated form isn't valid. */
  2746. return (GP_REGNUM_P (regno)
  2747. || regno == SP_REGNUM
  2748. || regno == FRAME_POINTER_REGNUM
  2749. || regno == ARG_POINTER_REGNUM);
  2750. }
  2751. /* Return true if X is a valid base register for mode MODE.
  2752. STRICT_P is true if REG_OK_STRICT is in effect. */
  2753. static bool
  2754. aarch64_base_register_rtx_p (rtx x, bool strict_p)
  2755. {
  2756. if (!strict_p && GET_CODE (x) == SUBREG)
  2757. x = SUBREG_REG (x);
  2758. return (REG_P (x) && aarch64_regno_ok_for_base_p (REGNO (x), strict_p));
  2759. }
  2760. /* Return true if address offset is a valid index. If it is, fill in INFO
  2761. appropriately. STRICT_P is true if REG_OK_STRICT is in effect. */
  2762. static bool
  2763. aarch64_classify_index (struct aarch64_address_info *info, rtx x,
  2764. machine_mode mode, bool strict_p)
  2765. {
  2766. enum aarch64_address_type type;
  2767. rtx index;
  2768. int shift;
  2769. /* (reg:P) */
  2770. if ((REG_P (x) || GET_CODE (x) == SUBREG)
  2771. && GET_MODE (x) == Pmode)
  2772. {
  2773. type = ADDRESS_REG_REG;
  2774. index = x;
  2775. shift = 0;
  2776. }
  2777. /* (sign_extend:DI (reg:SI)) */
  2778. else if ((GET_CODE (x) == SIGN_EXTEND
  2779. || GET_CODE (x) == ZERO_EXTEND)
  2780. && GET_MODE (x) == DImode
  2781. && GET_MODE (XEXP (x, 0)) == SImode)
  2782. {
  2783. type = (GET_CODE (x) == SIGN_EXTEND)
  2784. ? ADDRESS_REG_SXTW : ADDRESS_REG_UXTW;
  2785. index = XEXP (x, 0);
  2786. shift = 0;
  2787. }
  2788. /* (mult:DI (sign_extend:DI (reg:SI)) (const_int scale)) */
  2789. else if (GET_CODE (x) == MULT
  2790. && (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND
  2791. || GET_CODE (XEXP (x, 0)) == ZERO_EXTEND)
  2792. && GET_MODE (XEXP (x, 0)) == DImode
  2793. && GET_MODE (XEXP (XEXP (x, 0), 0)) == SImode
  2794. && CONST_INT_P (XEXP (x, 1)))
  2795. {
  2796. type = (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
  2797. ? ADDRESS_REG_SXTW : ADDRESS_REG_UXTW;
  2798. index = XEXP (XEXP (x, 0), 0);
  2799. shift = exact_log2 (INTVAL (XEXP (x, 1)));
  2800. }
  2801. /* (ashift:DI (sign_extend:DI (reg:SI)) (const_int shift)) */
  2802. else if (GET_CODE (x) == ASHIFT
  2803. && (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND
  2804. || GET_CODE (XEXP (x, 0)) == ZERO_EXTEND)
  2805. && GET_MODE (XEXP (x, 0)) == DImode
  2806. && GET_MODE (XEXP (XEXP (x, 0), 0)) == SImode
  2807. && CONST_INT_P (XEXP (x, 1)))
  2808. {
  2809. type = (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
  2810. ? ADDRESS_REG_SXTW : ADDRESS_REG_UXTW;
  2811. index = XEXP (XEXP (x, 0), 0);
  2812. shift = INTVAL (XEXP (x, 1));
  2813. }
  2814. /* (sign_extract:DI (mult:DI (reg:DI) (const_int scale)) 32+shift 0) */
  2815. else if ((GET_CODE (x) == SIGN_EXTRACT
  2816. || GET_CODE (x) == ZERO_EXTRACT)
  2817. && GET_MODE (x) == DImode
  2818. && GET_CODE (XEXP (x, 0)) == MULT
  2819. && GET_MODE (XEXP (XEXP (x, 0), 0)) == DImode
  2820. && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
  2821. {
  2822. type = (GET_CODE (x) == SIGN_EXTRACT)
  2823. ? ADDRESS_REG_SXTW : ADDRESS_REG_UXTW;
  2824. index = XEXP (XEXP (x, 0), 0);
  2825. shift = exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)));
  2826. if (INTVAL (XEXP (x, 1)) != 32 + shift
  2827. || INTVAL (XEXP (x, 2)) != 0)
  2828. shift = -1;
  2829. }
  2830. /* (and:DI (mult:DI (reg:DI) (const_int scale))
  2831. (const_int 0xffffffff<<shift)) */
  2832. else if (GET_CODE (x) == AND
  2833. && GET_MODE (x) == DImode
  2834. && GET_CODE (XEXP (x, 0)) == MULT
  2835. && GET_MODE (XEXP (XEXP (x, 0), 0)) == DImode
  2836. && CONST_INT_P (XEXP (XEXP (x, 0), 1))
  2837. && CONST_INT_P (XEXP (x, 1)))
  2838. {
  2839. type = ADDRESS_REG_UXTW;
  2840. index = XEXP (XEXP (x, 0), 0);
  2841. shift = exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)));
  2842. if (INTVAL (XEXP (x, 1)) != (HOST_WIDE_INT)0xffffffff << shift)
  2843. shift = -1;
  2844. }
  2845. /* (sign_extract:DI (ashift:DI (reg:DI) (const_int shift)) 32+shift 0) */
  2846. else if ((GET_CODE (x) == SIGN_EXTRACT
  2847. || GET_CODE (x) == ZERO_EXTRACT)
  2848. && GET_MODE (x) == DImode
  2849. && GET_CODE (XEXP (x, 0)) == ASHIFT
  2850. && GET_MODE (XEXP (XEXP (x, 0), 0)) == DImode
  2851. && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
  2852. {
  2853. type = (GET_CODE (x) == SIGN_EXTRACT)
  2854. ? ADDRESS_REG_SXTW : ADDRESS_REG_UXTW;
  2855. index = XEXP (XEXP (x, 0), 0);
  2856. shift = INTVAL (XEXP (XEXP (x, 0), 1));
  2857. if (INTVAL (XEXP (x, 1)) != 32 + shift
  2858. || INTVAL (XEXP (x, 2)) != 0)
  2859. shift = -1;
  2860. }
  2861. /* (and:DI (ashift:DI (reg:DI) (const_int shift))
  2862. (const_int 0xffffffff<<shift)) */
  2863. else if (GET_CODE (x) == AND
  2864. && GET_MODE (x) == DImode
  2865. && GET_CODE (XEXP (x, 0)) == ASHIFT
  2866. && GET_MODE (XEXP (XEXP (x, 0), 0)) == DImode
  2867. && CONST_INT_P (XEXP (XEXP (x, 0), 1))
  2868. && CONST_INT_P (XEXP (x, 1)))
  2869. {
  2870. type = ADDRESS_REG_UXTW;
  2871. index = XEXP (XEXP (x, 0), 0);
  2872. shift = INTVAL (XEXP (XEXP (x, 0), 1));
  2873. if (INTVAL (XEXP (x, 1)) != (HOST_WIDE_INT)0xffffffff << shift)
  2874. shift = -1;
  2875. }
  2876. /* (mult:P (reg:P) (const_int scale)) */
  2877. else if (GET_CODE (x) == MULT
  2878. && GET_MODE (x) == Pmode
  2879. && GET_MODE (XEXP (x, 0)) == Pmode
  2880. && CONST_INT_P (XEXP (x, 1)))
  2881. {
  2882. type = ADDRESS_REG_REG;
  2883. index = XEXP (x, 0);
  2884. shift = exact_log2 (INTVAL (XEXP (x, 1)));
  2885. }
  2886. /* (ashift:P (reg:P) (const_int shift)) */
  2887. else if (GET_CODE (x) == ASHIFT
  2888. && GET_MODE (x) == Pmode
  2889. && GET_MODE (XEXP (x, 0)) == Pmode
  2890. && CONST_INT_P (XEXP (x, 1)))
  2891. {
  2892. type = ADDRESS_REG_REG;
  2893. index = XEXP (x, 0);
  2894. shift = INTVAL (XEXP (x, 1));
  2895. }
  2896. else
  2897. return false;
  2898. if (GET_CODE (index) == SUBREG)
  2899. index = SUBREG_REG (index);
  2900. if ((shift == 0 ||
  2901. (shift > 0 && shift <= 3
  2902. && (1 << shift) == GET_MODE_SIZE (mode)))
  2903. && REG_P (index)
  2904. && aarch64_regno_ok_for_index_p (REGNO (index), strict_p))
  2905. {
  2906. info->type = type;
  2907. info->offset = index;
  2908. info->shift = shift;
  2909. return true;
  2910. }
  2911. return false;
  2912. }
  2913. bool
  2914. aarch64_offset_7bit_signed_scaled_p (machine_mode mode, HOST_WIDE_INT offset)
  2915. {
  2916. return (offset >= -64 * GET_MODE_SIZE (mode)
  2917. && offset < 64 * GET_MODE_SIZE (mode)
  2918. && offset % GET_MODE_SIZE (mode) == 0);
  2919. }
  2920. static inline bool
  2921. offset_9bit_signed_unscaled_p (machine_mode mode ATTRIBUTE_UNUSED,
  2922. HOST_WIDE_INT offset)
  2923. {
  2924. return offset >= -256 && offset < 256;
  2925. }
  2926. static inline bool
  2927. offset_12bit_unsigned_scaled_p (machine_mode mode, HOST_WIDE_INT offset)
  2928. {
  2929. return (offset >= 0
  2930. && offset < 4096 * GET_MODE_SIZE (mode)
  2931. && offset % GET_MODE_SIZE (mode) == 0);
  2932. }
  2933. /* Return true if X is a valid address for machine mode MODE. If it is,
  2934. fill in INFO appropriately. STRICT_P is true if REG_OK_STRICT is in
  2935. effect. OUTER_CODE is PARALLEL for a load/store pair. */
  2936. static bool
  2937. aarch64_classify_address (struct aarch64_address_info *info,
  2938. rtx x, machine_mode mode,
  2939. RTX_CODE outer_code, bool strict_p)
  2940. {
  2941. enum rtx_code code = GET_CODE (x);
  2942. rtx op0, op1;
  2943. /* On BE, we use load/store pair for all large int mode load/stores. */
  2944. bool load_store_pair_p = (outer_code == PARALLEL
  2945. || (BYTES_BIG_ENDIAN
  2946. && aarch64_vect_struct_mode_p (mode)));
  2947. bool allow_reg_index_p =
  2948. !load_store_pair_p
  2949. && (GET_MODE_SIZE (mode) != 16 || aarch64_vector_mode_supported_p (mode))
  2950. && !aarch64_vect_struct_mode_p (mode);
  2951. /* On LE, for AdvSIMD, don't support anything other than POST_INC or
  2952. REG addressing. */
  2953. if (aarch64_vect_struct_mode_p (mode) && !BYTES_BIG_ENDIAN
  2954. && (code != POST_INC && code != REG))
  2955. return false;
  2956. switch (code)
  2957. {
  2958. case REG:
  2959. case SUBREG:
  2960. info->type = ADDRESS_REG_IMM;
  2961. info->base = x;
  2962. info->offset = const0_rtx;
  2963. return aarch64_base_register_rtx_p (x, strict_p);
  2964. case PLUS:
  2965. op0 = XEXP (x, 0);
  2966. op1 = XEXP (x, 1);
  2967. if (! strict_p
  2968. && REG_P (op0)
  2969. && (op0 == virtual_stack_vars_rtx
  2970. || op0 == frame_pointer_rtx
  2971. || op0 == arg_pointer_rtx)
  2972. && CONST_INT_P (op1))
  2973. {
  2974. info->type = ADDRESS_REG_IMM;
  2975. info->base = op0;
  2976. info->offset = op1;
  2977. return true;
  2978. }
  2979. if (GET_MODE_SIZE (mode) != 0
  2980. && CONST_INT_P (op1)
  2981. && aarch64_base_register_rtx_p (op0, strict_p))
  2982. {
  2983. HOST_WIDE_INT offset = INTVAL (op1);
  2984. info->type = ADDRESS_REG_IMM;
  2985. info->base = op0;
  2986. info->offset = op1;
  2987. /* TImode and TFmode values are allowed in both pairs of X
  2988. registers and individual Q registers. The available
  2989. address modes are:
  2990. X,X: 7-bit signed scaled offset
  2991. Q: 9-bit signed offset
  2992. We conservatively require an offset representable in either mode.
  2993. */
  2994. if (mode == TImode || mode == TFmode)
  2995. return (aarch64_offset_7bit_signed_scaled_p (mode, offset)
  2996. && offset_9bit_signed_unscaled_p (mode, offset));
  2997. /* A 7bit offset check because OImode will emit a ldp/stp
  2998. instruction (only big endian will get here).
  2999. For ldp/stp instructions, the offset is scaled for the size of a
  3000. single element of the pair. */
  3001. if (mode == OImode)
  3002. return aarch64_offset_7bit_signed_scaled_p (TImode, offset);
  3003. /* Three 9/12 bit offsets checks because CImode will emit three
  3004. ldr/str instructions (only big endian will get here). */
  3005. if (mode == CImode)
  3006. return (aarch64_offset_7bit_signed_scaled_p (TImode, offset)
  3007. && (offset_9bit_signed_unscaled_p (V16QImode, offset + 32)
  3008. || offset_12bit_unsigned_scaled_p (V16QImode,
  3009. offset + 32)));
  3010. /* Two 7bit offsets checks because XImode will emit two ldp/stp
  3011. instructions (only big endian will get here). */
  3012. if (mode == XImode)
  3013. return (aarch64_offset_7bit_signed_scaled_p (TImode, offset)
  3014. && aarch64_offset_7bit_signed_scaled_p (TImode,
  3015. offset + 32));
  3016. if (load_store_pair_p)
  3017. return ((GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8)
  3018. && aarch64_offset_7bit_signed_scaled_p (mode, offset));
  3019. else
  3020. return (offset_9bit_signed_unscaled_p (mode, offset)
  3021. || offset_12bit_unsigned_scaled_p (mode, offset));
  3022. }
  3023. if (allow_reg_index_p)
  3024. {
  3025. /* Look for base + (scaled/extended) index register. */
  3026. if (aarch64_base_register_rtx_p (op0, strict_p)
  3027. && aarch64_classify_index (info, op1, mode, strict_p))
  3028. {
  3029. info->base = op0;
  3030. return true;
  3031. }
  3032. if (aarch64_base_register_rtx_p (op1, strict_p)
  3033. && aarch64_classify_index (info, op0, mode, strict_p))
  3034. {
  3035. info->base = op1;
  3036. return true;
  3037. }
  3038. }
  3039. return false;
  3040. case POST_INC:
  3041. case POST_DEC:
  3042. case PRE_INC:
  3043. case PRE_DEC:
  3044. info->type = ADDRESS_REG_WB;
  3045. info->base = XEXP (x, 0);
  3046. info->offset = NULL_RTX;
  3047. return aarch64_base_register_rtx_p (info->base, strict_p);
  3048. case POST_MODIFY:
  3049. case PRE_MODIFY:
  3050. info->type = ADDRESS_REG_WB;
  3051. info->base = XEXP (x, 0);
  3052. if (GET_CODE (XEXP (x, 1)) == PLUS
  3053. && CONST_INT_P (XEXP (XEXP (x, 1), 1))
  3054. && rtx_equal_p (XEXP (XEXP (x, 1), 0), info->base)
  3055. && aarch64_base_register_rtx_p (info->base, strict_p))
  3056. {
  3057. HOST_WIDE_INT offset;
  3058. info->offset = XEXP (XEXP (x, 1), 1);
  3059. offset = INTVAL (info->offset);
  3060. /* TImode and TFmode values are allowed in both pairs of X
  3061. registers and individual Q registers. The available
  3062. address modes are:
  3063. X,X: 7-bit signed scaled offset
  3064. Q: 9-bit signed offset
  3065. We conservatively require an offset representable in either mode.
  3066. */
  3067. if (mode == TImode || mode == TFmode)
  3068. return (aarch64_offset_7bit_signed_scaled_p (mode, offset)
  3069. && offset_9bit_signed_unscaled_p (mode, offset));
  3070. if (load_store_pair_p)
  3071. return ((GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8)
  3072. && aarch64_offset_7bit_signed_scaled_p (mode, offset));
  3073. else
  3074. return offset_9bit_signed_unscaled_p (mode, offset);
  3075. }
  3076. return false;
  3077. case CONST:
  3078. case SYMBOL_REF:
  3079. case LABEL_REF:
  3080. /* load literal: pc-relative constant pool entry. Only supported
  3081. for SI mode or larger. */
  3082. info->type = ADDRESS_SYMBOLIC;
  3083. if (!load_store_pair_p && GET_MODE_SIZE (mode) >= 4)
  3084. {
  3085. rtx sym, addend;
  3086. split_const (x, &sym, &addend);
  3087. return (GET_CODE (sym) == LABEL_REF
  3088. || (GET_CODE (sym) == SYMBOL_REF
  3089. && CONSTANT_POOL_ADDRESS_P (sym)));
  3090. }
  3091. return false;
  3092. case LO_SUM:
  3093. info->type = ADDRESS_LO_SUM;
  3094. info->base = XEXP (x, 0);
  3095. info->offset = XEXP (x, 1);
  3096. if (allow_reg_index_p
  3097. && aarch64_base_register_rtx_p (info->base, strict_p))
  3098. {
  3099. rtx sym, offs;
  3100. split_const (info->offset, &sym, &offs);
  3101. if (GET_CODE (sym) == SYMBOL_REF
  3102. && (aarch64_classify_symbol (sym, offs, SYMBOL_CONTEXT_MEM)
  3103. == SYMBOL_SMALL_ABSOLUTE))
  3104. {
  3105. /* The symbol and offset must be aligned to the access size. */
  3106. unsigned int align;
  3107. unsigned int ref_size;
  3108. if (CONSTANT_POOL_ADDRESS_P (sym))
  3109. align = GET_MODE_ALIGNMENT (get_pool_mode (sym));
  3110. else if (TREE_CONSTANT_POOL_ADDRESS_P (sym))
  3111. {
  3112. tree exp = SYMBOL_REF_DECL (sym);
  3113. align = TYPE_ALIGN (TREE_TYPE (exp));
  3114. align = CONSTANT_ALIGNMENT (exp, align);
  3115. }
  3116. else if (SYMBOL_REF_DECL (sym))
  3117. align = DECL_ALIGN (SYMBOL_REF_DECL (sym));
  3118. else if (SYMBOL_REF_HAS_BLOCK_INFO_P (sym)
  3119. && SYMBOL_REF_BLOCK (sym) != NULL)
  3120. align = SYMBOL_REF_BLOCK (sym)->alignment;
  3121. else
  3122. align = BITS_PER_UNIT;
  3123. ref_size = GET_MODE_SIZE (mode);
  3124. if (ref_size == 0)
  3125. ref_size = GET_MODE_SIZE (DImode);
  3126. return ((INTVAL (offs) & (ref_size - 1)) == 0
  3127. && ((align / BITS_PER_UNIT) & (ref_size - 1)) == 0);
  3128. }
  3129. }
  3130. return false;
  3131. default:
  3132. return false;
  3133. }
  3134. }
  3135. bool
  3136. aarch64_symbolic_address_p (rtx x)
  3137. {
  3138. rtx offset;
  3139. split_const (x, &x, &offset);
  3140. return GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF;
  3141. }
  3142. /* Classify the base of symbolic expression X, given that X appears in
  3143. context CONTEXT. */
  3144. enum aarch64_symbol_type
  3145. aarch64_classify_symbolic_expression (rtx x,
  3146. enum aarch64_symbol_context context)
  3147. {
  3148. rtx offset;
  3149. split_const (x, &x, &offset);
  3150. return aarch64_classify_symbol (x, offset, context);
  3151. }
  3152. /* Return TRUE if X is a legitimate address for accessing memory in
  3153. mode MODE. */
  3154. static bool
  3155. aarch64_legitimate_address_hook_p (machine_mode mode, rtx x, bool strict_p)
  3156. {
  3157. struct aarch64_address_info addr;
  3158. return aarch64_classify_address (&addr, x, mode, MEM, strict_p);
  3159. }
  3160. /* Return TRUE if X is a legitimate address for accessing memory in
  3161. mode MODE. OUTER_CODE will be PARALLEL if this is a load/store
  3162. pair operation. */
  3163. bool
  3164. aarch64_legitimate_address_p (machine_mode mode, rtx x,
  3165. RTX_CODE outer_code, bool strict_p)
  3166. {
  3167. struct aarch64_address_info addr;
  3168. return aarch64_classify_address (&addr, x, mode, outer_code, strict_p);
  3169. }
  3170. /* Return TRUE if rtx X is immediate constant 0.0 */
  3171. bool
  3172. aarch64_float_const_zero_rtx_p (rtx x)
  3173. {
  3174. REAL_VALUE_TYPE r;
  3175. if (GET_MODE (x) == VOIDmode)
  3176. return false;
  3177. REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  3178. if (REAL_VALUE_MINUS_ZERO (r))
  3179. return !HONOR_SIGNED_ZEROS (GET_MODE (x));
  3180. return REAL_VALUES_EQUAL (r, dconst0);
  3181. }
  3182. /* Return the fixed registers used for condition codes. */
  3183. static bool
  3184. aarch64_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
  3185. {
  3186. *p1 = CC_REGNUM;
  3187. *p2 = INVALID_REGNUM;
  3188. return true;
  3189. }
  3190. /* Emit call insn with PAT and do aarch64-specific handling. */
  3191. void
  3192. aarch64_emit_call_insn (rtx pat)
  3193. {
  3194. rtx insn = emit_call_insn (pat);
  3195. rtx *fusage = &CALL_INSN_FUNCTION_USAGE (insn);
  3196. clobber_reg (fusage, gen_rtx_REG (word_mode, IP0_REGNUM));
  3197. clobber_reg (fusage, gen_rtx_REG (word_mode, IP1_REGNUM));
  3198. }
  3199. machine_mode
  3200. aarch64_select_cc_mode (RTX_CODE code, rtx x, rtx y)
  3201. {
  3202. /* All floating point compares return CCFP if it is an equality
  3203. comparison, and CCFPE otherwise. */
  3204. if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
  3205. {
  3206. switch (code)
  3207. {
  3208. case EQ:
  3209. case NE:
  3210. case UNORDERED:
  3211. case ORDERED:
  3212. case UNLT:
  3213. case UNLE:
  3214. case UNGT:
  3215. case UNGE:
  3216. case UNEQ:
  3217. case LTGT:
  3218. return CCFPmode;
  3219. case LT:
  3220. case LE:
  3221. case GT:
  3222. case GE:
  3223. return CCFPEmode;
  3224. default:
  3225. gcc_unreachable ();
  3226. }
  3227. }
  3228. if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
  3229. && y == const0_rtx
  3230. && (code == EQ || code == NE || code == LT || code == GE)
  3231. && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS || GET_CODE (x) == AND
  3232. || GET_CODE (x) == NEG))
  3233. return CC_NZmode;
  3234. /* A compare with a shifted operand. Because of canonicalization,
  3235. the comparison will have to be swapped when we emit the assembly
  3236. code. */
  3237. if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
  3238. && (REG_P (y) || GET_CODE (y) == SUBREG)
  3239. && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT
  3240. || GET_CODE (x) == LSHIFTRT
  3241. || GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND))
  3242. return CC_SWPmode;
  3243. /* Similarly for a negated operand, but we can only do this for
  3244. equalities. */
  3245. if ((GET_MODE (x) == SImode || GET_MODE (x) == DImode)
  3246. && (REG_P (y) || GET_CODE (y) == SUBREG)
  3247. && (code == EQ || code == NE)
  3248. && GET_CODE (x) == NEG)
  3249. return CC_Zmode;
  3250. /* A compare of a mode narrower than SI mode against zero can be done
  3251. by extending the value in the comparison. */
  3252. if ((GET_MODE (x) == QImode || GET_MODE (x) == HImode)
  3253. && y == const0_rtx)
  3254. /* Only use sign-extension if we really need it. */
  3255. return ((code == GT || code == GE || code == LE || code == LT)
  3256. ? CC_SESWPmode : CC_ZESWPmode);
  3257. /* For everything else, return CCmode. */
  3258. return CCmode;
  3259. }
  3260. static int
  3261. aarch64_get_condition_code_1 (enum machine_mode, enum rtx_code);
  3262. int
  3263. aarch64_get_condition_code (rtx x)
  3264. {
  3265. machine_mode mode = GET_MODE (XEXP (x, 0));
  3266. enum rtx_code comp_code = GET_CODE (x);
  3267. if (GET_MODE_CLASS (mode) != MODE_CC)
  3268. mode = SELECT_CC_MODE (comp_code, XEXP (x, 0), XEXP (x, 1));
  3269. return aarch64_get_condition_code_1 (mode, comp_code);
  3270. }
  3271. static int
  3272. aarch64_get_condition_code_1 (enum machine_mode mode, enum rtx_code comp_code)
  3273. {
  3274. int ne = -1, eq = -1;
  3275. switch (mode)
  3276. {
  3277. case CCFPmode:
  3278. case CCFPEmode:
  3279. switch (comp_code)
  3280. {
  3281. case GE: return AARCH64_GE;
  3282. case GT: return AARCH64_GT;
  3283. case LE: return AARCH64_LS;
  3284. case LT: return AARCH64_MI;
  3285. case NE: return AARCH64_NE;
  3286. case EQ: return AARCH64_EQ;
  3287. case ORDERED: return AARCH64_VC;
  3288. case UNORDERED: return AARCH64_VS;
  3289. case UNLT: return AARCH64_LT;
  3290. case UNLE: return AARCH64_LE;
  3291. case UNGT: return AARCH64_HI;
  3292. case UNGE: return AARCH64_PL;
  3293. default: return -1;
  3294. }
  3295. break;
  3296. case CC_DNEmode:
  3297. ne = AARCH64_NE;
  3298. eq = AARCH64_EQ;
  3299. break;
  3300. case CC_DEQmode:
  3301. ne = AARCH64_EQ;
  3302. eq = AARCH64_NE;
  3303. break;
  3304. case CC_DGEmode:
  3305. ne = AARCH64_GE;
  3306. eq = AARCH64_LT;
  3307. break;
  3308. case CC_DLTmode:
  3309. ne = AARCH64_LT;
  3310. eq = AARCH64_GE;
  3311. break;
  3312. case CC_DGTmode:
  3313. ne = AARCH64_GT;
  3314. eq = AARCH64_LE;
  3315. break;
  3316. case CC_DLEmode:
  3317. ne = AARCH64_LE;
  3318. eq = AARCH64_GT;
  3319. break;
  3320. case CC_DGEUmode:
  3321. ne = AARCH64_CS;
  3322. eq = AARCH64_CC;
  3323. break;
  3324. case CC_DLTUmode:
  3325. ne = AARCH64_CC;
  3326. eq = AARCH64_CS;
  3327. break;
  3328. case CC_DGTUmode:
  3329. ne = AARCH64_HI;
  3330. eq = AARCH64_LS;
  3331. break;
  3332. case CC_DLEUmode:
  3333. ne = AARCH64_LS;
  3334. eq = AARCH64_HI;
  3335. break;
  3336. case CCmode:
  3337. switch (comp_code)
  3338. {
  3339. case NE: return AARCH64_NE;
  3340. case EQ: return AARCH64_EQ;
  3341. case GE: return AARCH64_GE;
  3342. case GT: return AARCH64_GT;
  3343. case LE: return AARCH64_LE;
  3344. case LT: return AARCH64_LT;
  3345. case GEU: return AARCH64_CS;
  3346. case GTU: return AARCH64_HI;
  3347. case LEU: return AARCH64_LS;
  3348. case LTU: return AARCH64_CC;
  3349. default: return -1;
  3350. }
  3351. break;
  3352. case CC_SWPmode:
  3353. case CC_ZESWPmode:
  3354. case CC_SESWPmode:
  3355. switch (comp_code)
  3356. {
  3357. case NE: return AARCH64_NE;
  3358. case EQ: return AARCH64_EQ;
  3359. case GE: return AARCH64_LE;
  3360. case GT: return AARCH64_LT;
  3361. case LE: return AARCH64_GE;
  3362. case LT: return AARCH64_GT;
  3363. case GEU: return AARCH64_LS;
  3364. case GTU: return AARCH64_CC;
  3365. case LEU: return AARCH64_CS;
  3366. case LTU: return AARCH64_HI;
  3367. default: return -1;
  3368. }
  3369. break;
  3370. case CC_NZmode:
  3371. switch (comp_code)
  3372. {
  3373. case NE: return AARCH64_NE;
  3374. case EQ: return AARCH64_EQ;
  3375. case GE: return AARCH64_PL;
  3376. case LT: return AARCH64_MI;
  3377. default: return -1;
  3378. }
  3379. break;
  3380. case CC_Zmode:
  3381. switch (comp_code)
  3382. {
  3383. case NE: return AARCH64_NE;
  3384. case EQ: return AARCH64_EQ;
  3385. default: return -1;
  3386. }
  3387. break;
  3388. default:
  3389. return -1;
  3390. break;
  3391. }
  3392. if (comp_code == NE)
  3393. return ne;
  3394. if (comp_code == EQ)
  3395. return eq;
  3396. return -1;
  3397. }
  3398. bool
  3399. aarch64_const_vec_all_same_in_range_p (rtx x,
  3400. HOST_WIDE_INT minval,
  3401. HOST_WIDE_INT maxval)
  3402. {
  3403. HOST_WIDE_INT firstval;
  3404. int count, i;
  3405. if (GET_CODE (x) != CONST_VECTOR
  3406. || GET_MODE_CLASS (GET_MODE (x)) != MODE_VECTOR_INT)
  3407. return false;
  3408. firstval = INTVAL (CONST_VECTOR_ELT (x, 0));
  3409. if (firstval < minval || firstval > maxval)
  3410. return false;
  3411. count = CONST_VECTOR_NUNITS (x);
  3412. for (i = 1; i < count; i++)
  3413. if (INTVAL (CONST_VECTOR_ELT (x, i)) != firstval)
  3414. return false;
  3415. return true;
  3416. }
  3417. bool
  3418. aarch64_const_vec_all_same_int_p (rtx x, HOST_WIDE_INT val)
  3419. {
  3420. return aarch64_const_vec_all_same_in_range_p (x, val, val);
  3421. }
  3422. static unsigned
  3423. bit_count (unsigned HOST_WIDE_INT value)
  3424. {
  3425. unsigned count = 0;
  3426. while (value)
  3427. {
  3428. count++;
  3429. value &= value - 1;
  3430. }
  3431. return count;
  3432. }
  3433. /* N Z C V. */
  3434. #define AARCH64_CC_V 1
  3435. #define AARCH64_CC_C (1 << 1)
  3436. #define AARCH64_CC_Z (1 << 2)
  3437. #define AARCH64_CC_N (1 << 3)
  3438. /* N Z C V flags for ccmp. The first code is for AND op and the other
  3439. is for IOR op. Indexed by AARCH64_COND_CODE. */
  3440. static const int aarch64_nzcv_codes[][2] =
  3441. {
  3442. {AARCH64_CC_Z, 0}, /* EQ, Z == 1. */
  3443. {0, AARCH64_CC_Z}, /* NE, Z == 0. */
  3444. {AARCH64_CC_C, 0}, /* CS, C == 1. */
  3445. {0, AARCH64_CC_C}, /* CC, C == 0. */
  3446. {AARCH64_CC_N, 0}, /* MI, N == 1. */
  3447. {0, AARCH64_CC_N}, /* PL, N == 0. */
  3448. {AARCH64_CC_V, 0}, /* VS, V == 1. */
  3449. {0, AARCH64_CC_V}, /* VC, V == 0. */
  3450. {AARCH64_CC_C, 0}, /* HI, C ==1 && Z == 0. */
  3451. {0, AARCH64_CC_C}, /* LS, !(C == 1 && Z == 0). */
  3452. {0, AARCH64_CC_V}, /* GE, N == V. */
  3453. {AARCH64_CC_V, 0}, /* LT, N != V. */
  3454. {0, AARCH64_CC_Z}, /* GT, Z == 0 && N == V. */
  3455. {AARCH64_CC_Z, 0}, /* LE, !(Z == 0 && N == V). */
  3456. {0, 0}, /* AL, Any. */
  3457. {0, 0}, /* NV, Any. */
  3458. };
  3459. int
  3460. aarch64_ccmp_mode_to_code (enum machine_mode mode)
  3461. {
  3462. switch (mode)
  3463. {
  3464. case CC_DNEmode:
  3465. return NE;
  3466. case CC_DEQmode:
  3467. return EQ;
  3468. case CC_DLEmode:
  3469. return LE;
  3470. case CC_DGTmode:
  3471. return GT;
  3472. case CC_DLTmode:
  3473. return LT;
  3474. case CC_DGEmode:
  3475. return GE;
  3476. case CC_DLEUmode:
  3477. return LEU;
  3478. case CC_DGTUmode:
  3479. return GTU;
  3480. case CC_DLTUmode:
  3481. return LTU;
  3482. case CC_DGEUmode:
  3483. return GEU;
  3484. default:
  3485. gcc_unreachable ();
  3486. }
  3487. }
  3488. void
  3489. aarch64_print_operand (FILE *f, rtx x, char code)
  3490. {
  3491. switch (code)
  3492. {
  3493. /* An integer or symbol address without a preceding # sign. */
  3494. case 'c':
  3495. switch (GET_CODE (x))
  3496. {
  3497. case CONST_INT:
  3498. fprintf (f, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
  3499. break;
  3500. case SYMBOL_REF:
  3501. output_addr_const (f, x);
  3502. break;
  3503. case CONST:
  3504. if (GET_CODE (XEXP (x, 0)) == PLUS
  3505. && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF)
  3506. {
  3507. output_addr_const (f, x);
  3508. break;
  3509. }
  3510. /* Fall through. */
  3511. default:
  3512. output_operand_lossage ("Unsupported operand for code '%c'", code);
  3513. }
  3514. break;
  3515. case 'e':
  3516. /* Print the sign/zero-extend size as a character 8->b, 16->h, 32->w. */
  3517. {
  3518. int n;
  3519. if (!CONST_INT_P (x)
  3520. || (n = exact_log2 (INTVAL (x) & ~7)) <= 0)
  3521. {
  3522. output_operand_lossage ("invalid operand for '%%%c'", code);
  3523. return;
  3524. }
  3525. switch (n)
  3526. {
  3527. case 3:
  3528. fputc ('b', f);
  3529. break;
  3530. case 4:
  3531. fputc ('h', f);
  3532. break;
  3533. case 5:
  3534. fputc ('w', f);
  3535. break;
  3536. default:
  3537. output_operand_lossage ("invalid operand for '%%%c'", code);
  3538. return;
  3539. }
  3540. }
  3541. break;
  3542. case 'p':
  3543. {
  3544. int n;
  3545. /* Print N such that 2^N == X. */
  3546. if (!CONST_INT_P (x) || (n = exact_log2 (INTVAL (x))) < 0)
  3547. {
  3548. output_operand_lossage ("invalid operand for '%%%c'", code);
  3549. return;
  3550. }
  3551. asm_fprintf (f, "%d", n);
  3552. }
  3553. break;
  3554. case 'P':
  3555. /* Print the number of non-zero bits in X (a const_int). */
  3556. if (!CONST_INT_P (x))
  3557. {
  3558. output_operand_lossage ("invalid operand for '%%%c'", code);
  3559. return;
  3560. }
  3561. asm_fprintf (f, "%u", bit_count (INTVAL (x)));
  3562. break;
  3563. case 'H':
  3564. /* Print the higher numbered register of a pair (TImode) of regs. */
  3565. if (!REG_P (x) || !GP_REGNUM_P (REGNO (x) + 1))
  3566. {
  3567. output_operand_lossage ("invalid operand for '%%%c'", code);
  3568. return;
  3569. }
  3570. asm_fprintf (f, "%s", reg_names [REGNO (x) + 1]);
  3571. break;
  3572. case 'm':
  3573. {
  3574. int cond_code;
  3575. /* Print a condition (eq, ne, etc). */
  3576. /* CONST_TRUE_RTX means always -- that's the default. */
  3577. if (x == const_true_rtx)
  3578. return;
  3579. if (!COMPARISON_P (x))
  3580. {
  3581. output_operand_lossage ("invalid operand for '%%%c'", code);
  3582. return;
  3583. }
  3584. cond_code = aarch64_get_condition_code (x);
  3585. gcc_assert (cond_code >= 0);
  3586. fputs (aarch64_condition_codes[cond_code], f);
  3587. }
  3588. break;
  3589. case 'M':
  3590. {
  3591. int cond_code;
  3592. /* Print the inverse of a condition (eq <-> ne, etc). */
  3593. /* CONST_TRUE_RTX means never -- that's the default. */
  3594. if (x == const_true_rtx)
  3595. {
  3596. fputs ("nv", f);
  3597. return;
  3598. }
  3599. if (!COMPARISON_P (x))
  3600. {
  3601. output_operand_lossage ("invalid operand for '%%%c'", code);
  3602. return;
  3603. }
  3604. cond_code = aarch64_get_condition_code (x);
  3605. gcc_assert (cond_code >= 0);
  3606. fputs (aarch64_condition_codes[AARCH64_INVERSE_CONDITION_CODE
  3607. (cond_code)], f);
  3608. }
  3609. break;
  3610. case 'b':
  3611. case 'h':
  3612. case 's':
  3613. case 'd':
  3614. case 'q':
  3615. /* Print a scalar FP/SIMD register name. */
  3616. if (!REG_P (x) || !FP_REGNUM_P (REGNO (x)))
  3617. {
  3618. output_operand_lossage ("incompatible floating point / vector register operand for '%%%c'", code);
  3619. return;
  3620. }
  3621. asm_fprintf (f, "%c%d", code, REGNO (x) - V0_REGNUM);
  3622. break;
  3623. case 'S':
  3624. case 'T':
  3625. case 'U':
  3626. case 'V':
  3627. /* Print the first FP/SIMD register name in a list. */
  3628. if (!REG_P (x) || !FP_REGNUM_P (REGNO (x)))
  3629. {
  3630. output_operand_lossage ("incompatible floating point / vector register operand for '%%%c'", code);
  3631. return;
  3632. }
  3633. asm_fprintf (f, "v%d", REGNO (x) - V0_REGNUM + (code - 'S'));
  3634. break;
  3635. case 'R':
  3636. /* Print a scalar FP/SIMD register name + 1. */
  3637. if (!REG_P (x) || !FP_REGNUM_P (REGNO (x)))
  3638. {
  3639. output_operand_lossage ("incompatible floating point / vector register operand for '%%%c'", code);
  3640. return;
  3641. }
  3642. asm_fprintf (f, "q%d", REGNO (x) - V0_REGNUM + 1);
  3643. break;
  3644. case 'X':
  3645. /* Print bottom 16 bits of integer constant in hex. */
  3646. if (!CONST_INT_P (x))
  3647. {
  3648. output_operand_lossage ("invalid operand for '%%%c'", code);
  3649. return;
  3650. }
  3651. asm_fprintf (f, "0x%wx", UINTVAL (x) & 0xffff);
  3652. break;
  3653. case 'w':
  3654. case 'x':
  3655. /* Print a general register name or the zero register (32-bit or
  3656. 64-bit). */
  3657. if (x == const0_rtx
  3658. || (CONST_DOUBLE_P (x) && aarch64_float_const_zero_rtx_p (x)))
  3659. {
  3660. asm_fprintf (f, "%czr", code);
  3661. break;
  3662. }
  3663. if (REG_P (x) && GP_REGNUM_P (REGNO (x)))
  3664. {
  3665. asm_fprintf (f, "%c%d", code, REGNO (x) - R0_REGNUM);
  3666. break;
  3667. }
  3668. if (REG_P (x) && REGNO (x) == SP_REGNUM)
  3669. {
  3670. asm_fprintf (f, "%ssp", code == 'w' ? "w" : "");
  3671. break;
  3672. }
  3673. /* Fall through */
  3674. case 0:
  3675. /* Print a normal operand, if it's a general register, then we
  3676. assume DImode. */
  3677. if (x == NULL)
  3678. {
  3679. output_operand_lossage ("missing operand");
  3680. return;
  3681. }
  3682. switch (GET_CODE (x))
  3683. {
  3684. case REG:
  3685. asm_fprintf (f, "%s", reg_names [REGNO (x)]);
  3686. break;
  3687. case MEM:
  3688. aarch64_memory_reference_mode = GET_MODE (x);
  3689. output_address (XEXP (x, 0));
  3690. break;
  3691. case LABEL_REF:
  3692. case SYMBOL_REF:
  3693. output_addr_const (asm_out_file, x);
  3694. break;
  3695. case CONST_INT:
  3696. asm_fprintf (f, "%wd", INTVAL (x));
  3697. break;
  3698. case CONST_VECTOR:
  3699. if (GET_MODE_CLASS (GET_MODE (x)) == MODE_VECTOR_INT)
  3700. {
  3701. gcc_assert (
  3702. aarch64_const_vec_all_same_in_range_p (x,
  3703. HOST_WIDE_INT_MIN,
  3704. HOST_WIDE_INT_MAX));
  3705. asm_fprintf (f, "%wd", INTVAL (CONST_VECTOR_ELT (x, 0)));
  3706. }
  3707. else if (aarch64_simd_imm_zero_p (x, GET_MODE (x)))
  3708. {
  3709. fputc ('0', f);
  3710. }
  3711. else
  3712. gcc_unreachable ();
  3713. break;
  3714. case CONST_DOUBLE:
  3715. /* CONST_DOUBLE can represent a double-width integer.
  3716. In this case, the mode of x is VOIDmode. */
  3717. if (GET_MODE (x) == VOIDmode)
  3718. ; /* Do Nothing. */
  3719. else if (aarch64_float_const_zero_rtx_p (x))
  3720. {
  3721. fputc ('0', f);
  3722. break;
  3723. }
  3724. else if (aarch64_float_const_representable_p (x))
  3725. {
  3726. #define buf_size 20
  3727. char float_buf[buf_size] = {'\0'};
  3728. REAL_VALUE_TYPE r;
  3729. REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  3730. real_to_decimal_for_mode (float_buf, &r,
  3731. buf_size, buf_size,
  3732. 1, GET_MODE (x));
  3733. asm_fprintf (asm_out_file, "%s", float_buf);
  3734. break;
  3735. #undef buf_size
  3736. }
  3737. output_operand_lossage ("invalid constant");
  3738. return;
  3739. default:
  3740. output_operand_lossage ("invalid operand");
  3741. return;
  3742. }
  3743. break;
  3744. case 'A':
  3745. if (GET_CODE (x) == HIGH)
  3746. x = XEXP (x, 0);
  3747. switch (aarch64_classify_symbolic_expression (x, SYMBOL_CONTEXT_ADR))
  3748. {
  3749. case SYMBOL_SMALL_GOT:
  3750. asm_fprintf (asm_out_file, ":got:");
  3751. break;
  3752. case SYMBOL_SMALL_TLSGD:
  3753. asm_fprintf (asm_out_file, ":tlsgd:");
  3754. break;
  3755. case SYMBOL_SMALL_TLSDESC:
  3756. asm_fprintf (asm_out_file, ":tlsdesc:");
  3757. break;
  3758. case SYMBOL_SMALL_GOTTPREL:
  3759. asm_fprintf (asm_out_file, ":gottprel:");
  3760. break;
  3761. case SYMBOL_SMALL_TPREL:
  3762. asm_fprintf (asm_out_file, ":tprel:");
  3763. break;
  3764. case SYMBOL_TINY_GOT:
  3765. gcc_unreachable ();
  3766. break;
  3767. default:
  3768. break;
  3769. }
  3770. output_addr_const (asm_out_file, x);
  3771. break;
  3772. case 'L':
  3773. switch (aarch64_classify_symbolic_expression (x, SYMBOL_CONTEXT_ADR))
  3774. {
  3775. case SYMBOL_SMALL_GOT:
  3776. asm_fprintf (asm_out_file, ":lo12:");
  3777. break;
  3778. case SYMBOL_SMALL_TLSGD:
  3779. asm_fprintf (asm_out_file, ":tlsgd_lo12:");
  3780. break;
  3781. case SYMBOL_SMALL_TLSDESC:
  3782. asm_fprintf (asm_out_file, ":tlsdesc_lo12:");
  3783. break;
  3784. case SYMBOL_SMALL_GOTTPREL:
  3785. asm_fprintf (asm_out_file, ":gottprel_lo12:");
  3786. break;
  3787. case SYMBOL_SMALL_TPREL:
  3788. asm_fprintf (asm_out_file, ":tprel_lo12_nc:");
  3789. break;
  3790. case SYMBOL_TINY_GOT:
  3791. asm_fprintf (asm_out_file, ":got:");
  3792. break;
  3793. default:
  3794. break;
  3795. }
  3796. output_addr_const (asm_out_file, x);
  3797. break;
  3798. case 'G':
  3799. switch (aarch64_classify_symbolic_expression (x, SYMBOL_CONTEXT_ADR))
  3800. {
  3801. case SYMBOL_SMALL_TPREL:
  3802. asm_fprintf (asm_out_file, ":tprel_hi12:");
  3803. break;
  3804. default:
  3805. break;
  3806. }
  3807. output_addr_const (asm_out_file, x);
  3808. break;
  3809. case 'K':
  3810. {
  3811. int cond_code;
  3812. /* Print nzcv. */
  3813. if (!COMPARISON_P (x))
  3814. {
  3815. output_operand_lossage ("invalid operand for '%%%c'", code);
  3816. return;
  3817. }
  3818. cond_code = aarch64_get_condition_code_1 (CCmode, GET_CODE (x));
  3819. gcc_assert (cond_code >= 0);
  3820. asm_fprintf (f, "%d", aarch64_nzcv_codes[cond_code][0]);
  3821. }
  3822. break;
  3823. case 'k':
  3824. {
  3825. int cond_code;
  3826. /* Print nzcv. */
  3827. if (!COMPARISON_P (x))
  3828. {
  3829. output_operand_lossage ("invalid operand for '%%%c'", code);
  3830. return;
  3831. }
  3832. cond_code = aarch64_get_condition_code_1 (CCmode, GET_CODE (x));
  3833. gcc_assert (cond_code >= 0);
  3834. asm_fprintf (f, "%d", aarch64_nzcv_codes[cond_code][1]);
  3835. }
  3836. break;
  3837. default:
  3838. output_operand_lossage ("invalid operand prefix '%%%c'", code);
  3839. return;
  3840. }
  3841. }
  3842. void
  3843. aarch64_print_operand_address (FILE *f, rtx x)
  3844. {
  3845. struct aarch64_address_info addr;
  3846. if (aarch64_classify_address (&addr, x, aarch64_memory_reference_mode,
  3847. MEM, true))
  3848. switch (addr.type)
  3849. {
  3850. case ADDRESS_REG_IMM:
  3851. if (addr.offset == const0_rtx)
  3852. asm_fprintf (f, "[%s]", reg_names [REGNO (addr.base)]);
  3853. else
  3854. asm_fprintf (f, "[%s, %wd]", reg_names [REGNO (addr.base)],
  3855. INTVAL (addr.offset));
  3856. return;
  3857. case ADDRESS_REG_REG:
  3858. if (addr.shift == 0)
  3859. asm_fprintf (f, "[%s, %s]", reg_names [REGNO (addr.base)],
  3860. reg_names [REGNO (addr.offset)]);
  3861. else
  3862. asm_fprintf (f, "[%s, %s, lsl %u]", reg_names [REGNO (addr.base)],
  3863. reg_names [REGNO (addr.offset)], addr.shift);
  3864. return;
  3865. case ADDRESS_REG_UXTW:
  3866. if (addr.shift == 0)
  3867. asm_fprintf (f, "[%s, w%d, uxtw]", reg_names [REGNO (addr.base)],
  3868. REGNO (addr.offset) - R0_REGNUM);
  3869. else
  3870. asm_fprintf (f, "[%s, w%d, uxtw %u]", reg_names [REGNO (addr.base)],
  3871. REGNO (addr.offset) - R0_REGNUM, addr.shift);
  3872. return;
  3873. case ADDRESS_REG_SXTW:
  3874. if (addr.shift == 0)
  3875. asm_fprintf (f, "[%s, w%d, sxtw]", reg_names [REGNO (addr.base)],
  3876. REGNO (addr.offset) - R0_REGNUM);
  3877. else
  3878. asm_fprintf (f, "[%s, w%d, sxtw %u]", reg_names [REGNO (addr.base)],
  3879. REGNO (addr.offset) - R0_REGNUM, addr.shift);
  3880. return;
  3881. case ADDRESS_REG_WB:
  3882. switch (GET_CODE (x))
  3883. {
  3884. case PRE_INC:
  3885. asm_fprintf (f, "[%s, %d]!", reg_names [REGNO (addr.base)],
  3886. GET_MODE_SIZE (aarch64_memory_reference_mode));
  3887. return;
  3888. case POST_INC:
  3889. asm_fprintf (f, "[%s], %d", reg_names [REGNO (addr.base)],
  3890. GET_MODE_SIZE (aarch64_memory_reference_mode));
  3891. return;
  3892. case PRE_DEC:
  3893. asm_fprintf (f, "[%s, -%d]!", reg_names [REGNO (addr.base)],
  3894. GET_MODE_SIZE (aarch64_memory_reference_mode));
  3895. return;
  3896. case POST_DEC:
  3897. asm_fprintf (f, "[%s], -%d", reg_names [REGNO (addr.base)],
  3898. GET_MODE_SIZE (aarch64_memory_reference_mode));
  3899. return;
  3900. case PRE_MODIFY:
  3901. asm_fprintf (f, "[%s, %wd]!", reg_names [REGNO (addr.base)],
  3902. INTVAL (addr.offset));
  3903. return;
  3904. case POST_MODIFY:
  3905. asm_fprintf (f, "[%s], %wd", reg_names [REGNO (addr.base)],
  3906. INTVAL (addr.offset));
  3907. return;
  3908. default:
  3909. break;
  3910. }
  3911. break;
  3912. case ADDRESS_LO_SUM:
  3913. asm_fprintf (f, "[%s, #:lo12:", reg_names [REGNO (addr.base)]);
  3914. output_addr_const (f, addr.offset);
  3915. asm_fprintf (f, "]");
  3916. return;
  3917. case ADDRESS_SYMBOLIC:
  3918. break;
  3919. }
  3920. output_addr_const (f, x);
  3921. }
  3922. bool
  3923. aarch64_label_mentioned_p (rtx x)
  3924. {
  3925. const char *fmt;
  3926. int i;
  3927. if (GET_CODE (x) == LABEL_REF)
  3928. return true;
  3929. /* UNSPEC_TLS entries for a symbol include a LABEL_REF for the
  3930. referencing instruction, but they are constant offsets, not
  3931. symbols. */
  3932. if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLS)
  3933. return false;
  3934. fmt = GET_RTX_FORMAT (GET_CODE (x));
  3935. for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
  3936. {
  3937. if (fmt[i] == 'E')
  3938. {
  3939. int j;
  3940. for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  3941. if (aarch64_label_mentioned_p (XVECEXP (x, i, j)))
  3942. return 1;
  3943. }
  3944. else if (fmt[i] == 'e' && aarch64_label_mentioned_p (XEXP (x, i)))
  3945. return 1;
  3946. }
  3947. return 0;
  3948. }
  3949. /* Implement REGNO_REG_CLASS. */
  3950. enum reg_class
  3951. aarch64_regno_regclass (unsigned regno)
  3952. {
  3953. if (GP_REGNUM_P (regno))
  3954. return GENERAL_REGS;
  3955. if (regno == SP_REGNUM)
  3956. return STACK_REG;
  3957. if (regno == FRAME_POINTER_REGNUM
  3958. || regno == ARG_POINTER_REGNUM)
  3959. return POINTER_REGS;
  3960. if (FP_REGNUM_P (regno))
  3961. return FP_LO_REGNUM_P (regno) ? FP_LO_REGS : FP_REGS;
  3962. return NO_REGS;
  3963. }
  3964. static rtx
  3965. aarch64_legitimize_address (rtx x, rtx /* orig_x */, machine_mode mode)
  3966. {
  3967. /* Try to split X+CONST into Y=X+(CONST & ~mask), Y+(CONST&mask),
  3968. where mask is selected by alignment and size of the offset.
  3969. We try to pick as large a range for the offset as possible to
  3970. maximize the chance of a CSE. However, for aligned addresses
  3971. we limit the range to 4k so that structures with different sized
  3972. elements are likely to use the same base. */
  3973. if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
  3974. {
  3975. HOST_WIDE_INT offset = INTVAL (XEXP (x, 1));
  3976. HOST_WIDE_INT base_offset;
  3977. /* Does it look like we'll need a load/store-pair operation? */
  3978. if (GET_MODE_SIZE (mode) > 16
  3979. || mode == TImode)
  3980. base_offset = ((offset + 64 * GET_MODE_SIZE (mode))
  3981. & ~((128 * GET_MODE_SIZE (mode)) - 1));
  3982. /* For offsets aren't a multiple of the access size, the limit is
  3983. -256...255. */
  3984. else if (offset & (GET_MODE_SIZE (mode) - 1))
  3985. base_offset = (offset + 0x100) & ~0x1ff;
  3986. else
  3987. base_offset = offset & ~0xfff;
  3988. if (base_offset == 0)
  3989. return x;
  3990. offset -= base_offset;
  3991. rtx base_reg = gen_reg_rtx (Pmode);
  3992. rtx val = force_operand (plus_constant (Pmode, XEXP (x, 0), base_offset),
  3993. NULL_RTX);
  3994. emit_move_insn (base_reg, val);
  3995. x = plus_constant (Pmode, base_reg, offset);
  3996. }
  3997. return x;
  3998. }
  3999. /* Try a machine-dependent way of reloading an illegitimate address
  4000. operand. If we find one, push the reload and return the new rtx. */
  4001. rtx
  4002. aarch64_legitimize_reload_address (rtx *x_p,
  4003. machine_mode mode,
  4004. int opnum, int type,
  4005. int ind_levels ATTRIBUTE_UNUSED)
  4006. {
  4007. rtx x = *x_p;
  4008. /* Do not allow mem (plus (reg, const)) if vector struct mode. */
  4009. if (aarch64_vect_struct_mode_p (mode)
  4010. && GET_CODE (x) == PLUS
  4011. && REG_P (XEXP (x, 0))
  4012. && CONST_INT_P (XEXP (x, 1)))
  4013. {
  4014. rtx orig_rtx = x;
  4015. x = copy_rtx (x);
  4016. push_reload (orig_rtx, NULL_RTX, x_p, NULL,
  4017. BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
  4018. opnum, (enum reload_type) type);
  4019. return x;
  4020. }
  4021. /* We must recognize output that we have already generated ourselves. */
  4022. if (GET_CODE (x) == PLUS
  4023. && GET_CODE (XEXP (x, 0)) == PLUS
  4024. && REG_P (XEXP (XEXP (x, 0), 0))
  4025. && CONST_INT_P (XEXP (XEXP (x, 0), 1))
  4026. && CONST_INT_P (XEXP (x, 1)))
  4027. {
  4028. push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
  4029. BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
  4030. opnum, (enum reload_type) type);
  4031. return x;
  4032. }
  4033. /* We wish to handle large displacements off a base register by splitting
  4034. the addend across an add and the mem insn. This can cut the number of
  4035. extra insns needed from 3 to 1. It is only useful for load/store of a
  4036. single register with 12 bit offset field. */
  4037. if (GET_CODE (x) == PLUS
  4038. && REG_P (XEXP (x, 0))
  4039. && CONST_INT_P (XEXP (x, 1))
  4040. && HARD_REGISTER_P (XEXP (x, 0))
  4041. && mode != TImode
  4042. && mode != TFmode
  4043. && aarch64_regno_ok_for_base_p (REGNO (XEXP (x, 0)), true))
  4044. {
  4045. HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
  4046. HOST_WIDE_INT low = val & 0xfff;
  4047. HOST_WIDE_INT high = val - low;
  4048. HOST_WIDE_INT offs;
  4049. rtx cst;
  4050. machine_mode xmode = GET_MODE (x);
  4051. /* In ILP32, xmode can be either DImode or SImode. */
  4052. gcc_assert (xmode == DImode || xmode == SImode);
  4053. /* Reload non-zero BLKmode offsets. This is because we cannot ascertain
  4054. BLKmode alignment. */
  4055. if (GET_MODE_SIZE (mode) == 0)
  4056. return NULL_RTX;
  4057. offs = low % GET_MODE_SIZE (mode);
  4058. /* Align misaligned offset by adjusting high part to compensate. */
  4059. if (offs != 0)
  4060. {
  4061. if (aarch64_uimm12_shift (high + offs))
  4062. {
  4063. /* Align down. */
  4064. low = low - offs;
  4065. high = high + offs;
  4066. }
  4067. else
  4068. {
  4069. /* Align up. */
  4070. offs = GET_MODE_SIZE (mode) - offs;
  4071. low = low + offs;
  4072. high = high + (low & 0x1000) - offs;
  4073. low &= 0xfff;
  4074. }
  4075. }
  4076. /* Check for overflow. */
  4077. if (high + low != val)
  4078. return NULL_RTX;
  4079. cst = GEN_INT (high);
  4080. if (!aarch64_uimm12_shift (high))
  4081. cst = force_const_mem (xmode, cst);
  4082. /* Reload high part into base reg, leaving the low part
  4083. in the mem instruction.
  4084. Note that replacing this gen_rtx_PLUS with plus_constant is
  4085. wrong in this case because we rely on the
  4086. (plus (plus reg c1) c2) structure being preserved so that
  4087. XEXP (*p, 0) in push_reload below uses the correct term. */
  4088. x = gen_rtx_PLUS (xmode,
  4089. gen_rtx_PLUS (xmode, XEXP (x, 0), cst),
  4090. GEN_INT (low));
  4091. push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
  4092. BASE_REG_CLASS, xmode, VOIDmode, 0, 0,
  4093. opnum, (enum reload_type) type);
  4094. return x;
  4095. }
  4096. return NULL_RTX;
  4097. }
  4098. static reg_class_t
  4099. aarch64_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x,
  4100. reg_class_t rclass,
  4101. machine_mode mode,
  4102. secondary_reload_info *sri)
  4103. {
  4104. /* Without the TARGET_SIMD instructions we cannot move a Q register
  4105. to a Q register directly. We need a scratch. */
  4106. if (REG_P (x) && (mode == TFmode || mode == TImode) && mode == GET_MODE (x)
  4107. && FP_REGNUM_P (REGNO (x)) && !TARGET_SIMD
  4108. && reg_class_subset_p (rclass, FP_REGS))
  4109. {
  4110. if (mode == TFmode)
  4111. sri->icode = CODE_FOR_aarch64_reload_movtf;
  4112. else if (mode == TImode)
  4113. sri->icode = CODE_FOR_aarch64_reload_movti;
  4114. return NO_REGS;
  4115. }
  4116. /* A TFmode or TImode memory access should be handled via an FP_REGS
  4117. because AArch64 has richer addressing modes for LDR/STR instructions
  4118. than LDP/STP instructions. */
  4119. if (TARGET_FLOAT && rclass == GENERAL_REGS
  4120. && GET_MODE_SIZE (mode) == 16 && MEM_P (x))
  4121. return FP_REGS;
  4122. if (rclass == FP_REGS && (mode == TImode || mode == TFmode) && CONSTANT_P(x))
  4123. return GENERAL_REGS;
  4124. return NO_REGS;
  4125. }
  4126. static bool
  4127. aarch64_can_eliminate (const int from, const int to)
  4128. {
  4129. /* If we need a frame pointer, we must eliminate FRAME_POINTER_REGNUM into
  4130. HARD_FRAME_POINTER_REGNUM and not into STACK_POINTER_REGNUM. */
  4131. if (frame_pointer_needed)
  4132. {
  4133. if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
  4134. return true;
  4135. if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
  4136. return false;
  4137. if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM
  4138. && !cfun->calls_alloca)
  4139. return true;
  4140. if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
  4141. return true;
  4142. return false;
  4143. }
  4144. else
  4145. {
  4146. /* If we decided that we didn't need a leaf frame pointer but then used
  4147. LR in the function, then we'll want a frame pointer after all, so
  4148. prevent this elimination to ensure a frame pointer is used. */
  4149. if (to == STACK_POINTER_REGNUM
  4150. && flag_omit_leaf_frame_pointer
  4151. && df_regs_ever_live_p (LR_REGNUM))
  4152. return false;
  4153. }
  4154. return true;
  4155. }
  4156. HOST_WIDE_INT
  4157. aarch64_initial_elimination_offset (unsigned from, unsigned to)
  4158. {
  4159. aarch64_layout_frame ();
  4160. if (to == HARD_FRAME_POINTER_REGNUM)
  4161. {
  4162. if (from == ARG_POINTER_REGNUM)
  4163. return cfun->machine->frame.frame_size - crtl->outgoing_args_size;
  4164. if (from == FRAME_POINTER_REGNUM)
  4165. return (cfun->machine->frame.hard_fp_offset
  4166. - cfun->machine->frame.saved_varargs_size);
  4167. }
  4168. if (to == STACK_POINTER_REGNUM)
  4169. {
  4170. if (from == FRAME_POINTER_REGNUM)
  4171. return (cfun->machine->frame.frame_size
  4172. - cfun->machine->frame.saved_varargs_size);
  4173. }
  4174. return cfun->machine->frame.frame_size;
  4175. }
  4176. /* Implement RETURN_ADDR_RTX. We do not support moving back to a
  4177. previous frame. */
  4178. rtx
  4179. aarch64_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
  4180. {
  4181. if (count != 0)
  4182. return const0_rtx;
  4183. return get_hard_reg_initial_val (Pmode, LR_REGNUM);
  4184. }
  4185. static void
  4186. aarch64_asm_trampoline_template (FILE *f)
  4187. {
  4188. if (TARGET_ILP32)
  4189. {
  4190. asm_fprintf (f, "\tldr\tw%d, .+16\n", IP1_REGNUM - R0_REGNUM);
  4191. asm_fprintf (f, "\tldr\tw%d, .+16\n", STATIC_CHAIN_REGNUM - R0_REGNUM);
  4192. }
  4193. else
  4194. {
  4195. asm_fprintf (f, "\tldr\t%s, .+16\n", reg_names [IP1_REGNUM]);
  4196. asm_fprintf (f, "\tldr\t%s, .+20\n", reg_names [STATIC_CHAIN_REGNUM]);
  4197. }
  4198. asm_fprintf (f, "\tbr\t%s\n", reg_names [IP1_REGNUM]);
  4199. assemble_aligned_integer (4, const0_rtx);
  4200. assemble_aligned_integer (POINTER_BYTES, const0_rtx);
  4201. assemble_aligned_integer (POINTER_BYTES, const0_rtx);
  4202. }
  4203. static void
  4204. aarch64_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
  4205. {
  4206. rtx fnaddr, mem, a_tramp;
  4207. const int tramp_code_sz = 16;
  4208. /* Don't need to copy the trailing D-words, we fill those in below. */
  4209. emit_block_move (m_tramp, assemble_trampoline_template (),
  4210. GEN_INT (tramp_code_sz), BLOCK_OP_NORMAL);
  4211. mem = adjust_address (m_tramp, ptr_mode, tramp_code_sz);
  4212. fnaddr = XEXP (DECL_RTL (fndecl), 0);
  4213. if (GET_MODE (fnaddr) != ptr_mode)
  4214. fnaddr = convert_memory_address (ptr_mode, fnaddr);
  4215. emit_move_insn (mem, fnaddr);
  4216. mem = adjust_address (m_tramp, ptr_mode, tramp_code_sz + POINTER_BYTES);
  4217. emit_move_insn (mem, chain_value);
  4218. /* XXX We should really define a "clear_cache" pattern and use
  4219. gen_clear_cache(). */
  4220. a_tramp = XEXP (m_tramp, 0);
  4221. emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__clear_cache"),
  4222. LCT_NORMAL, VOIDmode, 2, a_tramp, ptr_mode,
  4223. plus_constant (ptr_mode, a_tramp, TRAMPOLINE_SIZE),
  4224. ptr_mode);
  4225. }
  4226. static unsigned char
  4227. aarch64_class_max_nregs (reg_class_t regclass, machine_mode mode)
  4228. {
  4229. switch (regclass)
  4230. {
  4231. case CALLER_SAVE_REGS:
  4232. case POINTER_REGS:
  4233. case GENERAL_REGS:
  4234. case ALL_REGS:
  4235. case FP_REGS:
  4236. case FP_LO_REGS:
  4237. return
  4238. aarch64_vector_mode_p (mode) ? (GET_MODE_SIZE (mode) + 15) / 16 :
  4239. (GET_MODE_SIZE (mode) + 7) / 8;
  4240. case STACK_REG:
  4241. return 1;
  4242. case NO_REGS:
  4243. return 0;
  4244. default:
  4245. break;
  4246. }
  4247. gcc_unreachable ();
  4248. }
  4249. static reg_class_t
  4250. aarch64_preferred_reload_class (rtx x, reg_class_t regclass)
  4251. {
  4252. if (regclass == POINTER_REGS)
  4253. return GENERAL_REGS;
  4254. if (regclass == STACK_REG)
  4255. {
  4256. if (REG_P(x)
  4257. && reg_class_subset_p (REGNO_REG_CLASS (REGNO (x)), POINTER_REGS))
  4258. return regclass;
  4259. return NO_REGS;
  4260. }
  4261. /* If it's an integer immediate that MOVI can't handle, then
  4262. FP_REGS is not an option, so we return NO_REGS instead. */
  4263. if (CONST_INT_P (x) && reg_class_subset_p (regclass, FP_REGS)
  4264. && !aarch64_simd_imm_scalar_p (x, GET_MODE (x)))
  4265. return NO_REGS;
  4266. /* Register eliminiation can result in a request for
  4267. SP+constant->FP_REGS. We cannot support such operations which
  4268. use SP as source and an FP_REG as destination, so reject out
  4269. right now. */
  4270. if (! reg_class_subset_p (regclass, GENERAL_REGS) && GET_CODE (x) == PLUS)
  4271. {
  4272. rtx lhs = XEXP (x, 0);
  4273. /* Look through a possible SUBREG introduced by ILP32. */
  4274. if (GET_CODE (lhs) == SUBREG)
  4275. lhs = SUBREG_REG (lhs);
  4276. gcc_assert (REG_P (lhs));
  4277. gcc_assert (reg_class_subset_p (REGNO_REG_CLASS (REGNO (lhs)),
  4278. POINTER_REGS));
  4279. return NO_REGS;
  4280. }
  4281. return regclass;
  4282. }
  4283. void
  4284. aarch64_asm_output_labelref (FILE* f, const char *name)
  4285. {
  4286. asm_fprintf (f, "%U%s", name);
  4287. }
  4288. static void
  4289. aarch64_elf_asm_constructor (rtx symbol, int priority)
  4290. {
  4291. if (priority == DEFAULT_INIT_PRIORITY)
  4292. default_ctor_section_asm_out_constructor (symbol, priority);
  4293. else
  4294. {
  4295. section *s;
  4296. char buf[18];
  4297. snprintf (buf, sizeof (buf), ".init_array.%.5u", priority);
  4298. s = get_section (buf, SECTION_WRITE, NULL);
  4299. switch_to_section (s);
  4300. assemble_align (POINTER_SIZE);
  4301. assemble_aligned_integer (POINTER_BYTES, symbol);
  4302. }
  4303. }
  4304. static void
  4305. aarch64_elf_asm_destructor (rtx symbol, int priority)
  4306. {
  4307. if (priority == DEFAULT_INIT_PRIORITY)
  4308. default_dtor_section_asm_out_destructor (symbol, priority);
  4309. else
  4310. {
  4311. section *s;
  4312. char buf[18];
  4313. snprintf (buf, sizeof (buf), ".fini_array.%.5u", priority);
  4314. s = get_section (buf, SECTION_WRITE, NULL);
  4315. switch_to_section (s);
  4316. assemble_align (POINTER_SIZE);
  4317. assemble_aligned_integer (POINTER_BYTES, symbol);
  4318. }
  4319. }
  4320. const char*
  4321. aarch64_output_casesi (rtx *operands)
  4322. {
  4323. char buf[100];
  4324. char label[100];
  4325. rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
  4326. int index;
  4327. static const char *const patterns[4][2] =
  4328. {
  4329. {
  4330. "ldrb\t%w3, [%0,%w1,uxtw]",
  4331. "add\t%3, %4, %w3, sxtb #2"
  4332. },
  4333. {
  4334. "ldrh\t%w3, [%0,%w1,uxtw #1]",
  4335. "add\t%3, %4, %w3, sxth #2"
  4336. },
  4337. {
  4338. "ldr\t%w3, [%0,%w1,uxtw #2]",
  4339. "add\t%3, %4, %w3, sxtw #2"
  4340. },
  4341. /* We assume that DImode is only generated when not optimizing and
  4342. that we don't really need 64-bit address offsets. That would
  4343. imply an object file with 8GB of code in a single function! */
  4344. {
  4345. "ldr\t%w3, [%0,%w1,uxtw #2]",
  4346. "add\t%3, %4, %w3, sxtw #2"
  4347. }
  4348. };
  4349. gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
  4350. index = exact_log2 (GET_MODE_SIZE (GET_MODE (diff_vec)));
  4351. gcc_assert (index >= 0 && index <= 3);
  4352. /* Need to implement table size reduction, by chaning the code below. */
  4353. output_asm_insn (patterns[index][0], operands);
  4354. ASM_GENERATE_INTERNAL_LABEL (label, "Lrtx", CODE_LABEL_NUMBER (operands[2]));
  4355. snprintf (buf, sizeof (buf),
  4356. "adr\t%%4, %s", targetm.strip_name_encoding (label));
  4357. output_asm_insn (buf, operands);
  4358. output_asm_insn (patterns[index][1], operands);
  4359. output_asm_insn ("br\t%3", operands);
  4360. assemble_label (asm_out_file, label);
  4361. return "";
  4362. }
  4363. /* Return size in bits of an arithmetic operand which is shifted/scaled and
  4364. masked such that it is suitable for a UXTB, UXTH, or UXTW extend
  4365. operator. */
  4366. int
  4367. aarch64_uxt_size (int shift, HOST_WIDE_INT mask)
  4368. {
  4369. if (shift >= 0 && shift <= 3)
  4370. {
  4371. int size;
  4372. for (size = 8; size <= 32; size *= 2)
  4373. {
  4374. HOST_WIDE_INT bits = ((HOST_WIDE_INT)1U << size) - 1;
  4375. if (mask == bits << shift)
  4376. return size;
  4377. }
  4378. }
  4379. return 0;
  4380. }
  4381. static bool
  4382. aarch64_use_blocks_for_constant_p (machine_mode mode ATTRIBUTE_UNUSED,
  4383. const_rtx x ATTRIBUTE_UNUSED)
  4384. {
  4385. /* We can't use blocks for constants when we're using a per-function
  4386. constant pool. */
  4387. return false;
  4388. }
  4389. static section *
  4390. aarch64_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED,
  4391. rtx x ATTRIBUTE_UNUSED,
  4392. unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
  4393. {
  4394. /* Force all constant pool entries into the current function section. */
  4395. return function_section (current_function_decl);
  4396. }
  4397. /* Costs. */
  4398. /* Helper function for rtx cost calculation. Strip a shift expression
  4399. from X. Returns the inner operand if successful, or the original
  4400. expression on failure. */
  4401. static rtx
  4402. aarch64_strip_shift (rtx x)
  4403. {
  4404. rtx op = x;
  4405. /* We accept both ROTATERT and ROTATE: since the RHS must be a constant
  4406. we can convert both to ROR during final output. */
  4407. if ((GET_CODE (op) == ASHIFT
  4408. || GET_CODE (op) == ASHIFTRT
  4409. || GET_CODE (op) == LSHIFTRT
  4410. || GET_CODE (op) == ROTATERT
  4411. || GET_CODE (op) == ROTATE)
  4412. && CONST_INT_P (XEXP (op, 1)))
  4413. return XEXP (op, 0);
  4414. if (GET_CODE (op) == MULT
  4415. && CONST_INT_P (XEXP (op, 1))
  4416. && ((unsigned) exact_log2 (INTVAL (XEXP (op, 1)))) < 64)
  4417. return XEXP (op, 0);
  4418. return x;
  4419. }
  4420. /* Helper function for rtx cost calculation. Strip an extend
  4421. expression from X. Returns the inner operand if successful, or the
  4422. original expression on failure. We deal with a number of possible
  4423. canonicalization variations here. */
  4424. static rtx
  4425. aarch64_strip_extend (rtx x)
  4426. {
  4427. rtx op = x;
  4428. /* Zero and sign extraction of a widened value. */
  4429. if ((GET_CODE (op) == ZERO_EXTRACT || GET_CODE (op) == SIGN_EXTRACT)
  4430. && XEXP (op, 2) == const0_rtx
  4431. && GET_CODE (XEXP (op, 0)) == MULT
  4432. && aarch64_is_extend_from_extract (GET_MODE (op), XEXP (XEXP (op, 0), 1),
  4433. XEXP (op, 1)))
  4434. return XEXP (XEXP (op, 0), 0);
  4435. /* It can also be represented (for zero-extend) as an AND with an
  4436. immediate. */
  4437. if (GET_CODE (op) == AND
  4438. && GET_CODE (XEXP (op, 0)) == MULT
  4439. && CONST_INT_P (XEXP (XEXP (op, 0), 1))
  4440. && CONST_INT_P (XEXP (op, 1))
  4441. && aarch64_uxt_size (exact_log2 (INTVAL (XEXP (XEXP (op, 0), 1))),
  4442. INTVAL (XEXP (op, 1))) != 0)
  4443. return XEXP (XEXP (op, 0), 0);
  4444. /* Now handle extended register, as this may also have an optional
  4445. left shift by 1..4. */
  4446. if (GET_CODE (op) == ASHIFT
  4447. && CONST_INT_P (XEXP (op, 1))
  4448. && ((unsigned HOST_WIDE_INT) INTVAL (XEXP (op, 1))) <= 4)
  4449. op = XEXP (op, 0);
  4450. if (GET_CODE (op) == ZERO_EXTEND
  4451. || GET_CODE (op) == SIGN_EXTEND)
  4452. op = XEXP (op, 0);
  4453. if (op != x)
  4454. return op;
  4455. return x;
  4456. }
  4457. /* Helper function for rtx cost calculation. Calculate the cost of
  4458. a MULT, which may be part of a multiply-accumulate rtx. Return
  4459. the calculated cost of the expression, recursing manually in to
  4460. operands where needed. */
  4461. static int
  4462. aarch64_rtx_mult_cost (rtx x, int code, int outer, bool speed)
  4463. {
  4464. rtx op0, op1;
  4465. const struct cpu_cost_table *extra_cost
  4466. = aarch64_tune_params->insn_extra_cost;
  4467. int cost = 0;
  4468. bool maybe_fma = (outer == PLUS || outer == MINUS);
  4469. machine_mode mode = GET_MODE (x);
  4470. gcc_checking_assert (code == MULT);
  4471. op0 = XEXP (x, 0);
  4472. op1 = XEXP (x, 1);
  4473. if (VECTOR_MODE_P (mode))
  4474. mode = GET_MODE_INNER (mode);
  4475. /* Integer multiply/fma. */
  4476. if (GET_MODE_CLASS (mode) == MODE_INT)
  4477. {
  4478. /* The multiply will be canonicalized as a shift, cost it as such. */
  4479. if (CONST_INT_P (op1)
  4480. && exact_log2 (INTVAL (op1)) > 0)
  4481. {
  4482. if (speed)
  4483. {
  4484. if (maybe_fma)
  4485. /* ADD (shifted register). */
  4486. cost += extra_cost->alu.arith_shift;
  4487. else
  4488. /* LSL (immediate). */
  4489. cost += extra_cost->alu.shift;
  4490. }
  4491. cost += rtx_cost (op0, GET_CODE (op0), 0, speed);
  4492. return cost;
  4493. }
  4494. /* Integer multiplies or FMAs have zero/sign extending variants. */
  4495. if ((GET_CODE (op0) == ZERO_EXTEND
  4496. && GET_CODE (op1) == ZERO_EXTEND)
  4497. || (GET_CODE (op0) == SIGN_EXTEND
  4498. && GET_CODE (op1) == SIGN_EXTEND))
  4499. {
  4500. cost += rtx_cost (XEXP (op0, 0), MULT, 0, speed)
  4501. + rtx_cost (XEXP (op1, 0), MULT, 1, speed);
  4502. if (speed)
  4503. {
  4504. if (maybe_fma)
  4505. /* MADD/SMADDL/UMADDL. */
  4506. cost += extra_cost->mult[0].extend_add;
  4507. else
  4508. /* MUL/SMULL/UMULL. */
  4509. cost += extra_cost->mult[0].extend;
  4510. }
  4511. return cost;
  4512. }
  4513. /* This is either an integer multiply or an FMA. In both cases
  4514. we want to recurse and cost the operands. */
  4515. cost += rtx_cost (op0, MULT, 0, speed)
  4516. + rtx_cost (op1, MULT, 1, speed);
  4517. if (speed)
  4518. {
  4519. if (maybe_fma)
  4520. /* MADD. */
  4521. cost += extra_cost->mult[mode == DImode].add;
  4522. else
  4523. /* MUL. */
  4524. cost += extra_cost->mult[mode == DImode].simple;
  4525. }
  4526. return cost;
  4527. }
  4528. else
  4529. {
  4530. if (speed)
  4531. {
  4532. /* Floating-point FMA/FMUL can also support negations of the
  4533. operands. */
  4534. if (GET_CODE (op0) == NEG)
  4535. op0 = XEXP (op0, 0);
  4536. if (GET_CODE (op1) == NEG)
  4537. op1 = XEXP (op1, 0);
  4538. if (maybe_fma)
  4539. /* FMADD/FNMADD/FNMSUB/FMSUB. */
  4540. cost += extra_cost->fp[mode == DFmode].fma;
  4541. else
  4542. /* FMUL/FNMUL. */
  4543. cost += extra_cost->fp[mode == DFmode].mult;
  4544. }
  4545. cost += rtx_cost (op0, MULT, 0, speed)
  4546. + rtx_cost (op1, MULT, 1, speed);
  4547. return cost;
  4548. }
  4549. }
  4550. static int
  4551. aarch64_address_cost (rtx x,
  4552. machine_mode mode,
  4553. addr_space_t as ATTRIBUTE_UNUSED,
  4554. bool speed)
  4555. {
  4556. enum rtx_code c = GET_CODE (x);
  4557. const struct cpu_addrcost_table *addr_cost = aarch64_tune_params->addr_cost;
  4558. struct aarch64_address_info info;
  4559. int cost = 0;
  4560. info.shift = 0;
  4561. if (!aarch64_classify_address (&info, x, mode, c, false))
  4562. {
  4563. if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF)
  4564. {
  4565. /* This is a CONST or SYMBOL ref which will be split
  4566. in a different way depending on the code model in use.
  4567. Cost it through the generic infrastructure. */
  4568. int cost_symbol_ref = rtx_cost (x, MEM, 1, speed);
  4569. /* Divide through by the cost of one instruction to
  4570. bring it to the same units as the address costs. */
  4571. cost_symbol_ref /= COSTS_N_INSNS (1);
  4572. /* The cost is then the cost of preparing the address,
  4573. followed by an immediate (possibly 0) offset. */
  4574. return cost_symbol_ref + addr_cost->imm_offset;
  4575. }
  4576. else
  4577. {
  4578. /* This is most likely a jump table from a case
  4579. statement. */
  4580. return addr_cost->register_offset;
  4581. }
  4582. }
  4583. switch (info.type)
  4584. {
  4585. case ADDRESS_LO_SUM:
  4586. case ADDRESS_SYMBOLIC:
  4587. case ADDRESS_REG_IMM:
  4588. cost += addr_cost->imm_offset;
  4589. break;
  4590. case ADDRESS_REG_WB:
  4591. if (c == PRE_INC || c == PRE_DEC || c == PRE_MODIFY)
  4592. cost += addr_cost->pre_modify;
  4593. else if (c == POST_INC || c == POST_DEC || c == POST_MODIFY)
  4594. cost += addr_cost->post_modify;
  4595. else
  4596. gcc_unreachable ();
  4597. break;
  4598. case ADDRESS_REG_REG:
  4599. cost += addr_cost->register_offset;
  4600. break;
  4601. case ADDRESS_REG_UXTW:
  4602. case ADDRESS_REG_SXTW:
  4603. cost += addr_cost->register_extend;
  4604. break;
  4605. default:
  4606. gcc_unreachable ();
  4607. }
  4608. if (info.shift > 0)
  4609. {
  4610. /* For the sake of calculating the cost of the shifted register
  4611. component, we can treat same sized modes in the same way. */
  4612. switch (GET_MODE_BITSIZE (mode))
  4613. {
  4614. case 16:
  4615. cost += addr_cost->addr_scale_costs.hi;
  4616. break;
  4617. case 32:
  4618. cost += addr_cost->addr_scale_costs.si;
  4619. break;
  4620. case 64:
  4621. cost += addr_cost->addr_scale_costs.di;
  4622. break;
  4623. /* We can't tell, or this is a 128-bit vector. */
  4624. default:
  4625. cost += addr_cost->addr_scale_costs.ti;
  4626. break;
  4627. }
  4628. }
  4629. return cost;
  4630. }
  4631. /* Return true if the RTX X in mode MODE is a zero or sign extract
  4632. usable in an ADD or SUB (extended register) instruction. */
  4633. static bool
  4634. aarch64_rtx_arith_op_extract_p (rtx x, machine_mode mode)
  4635. {
  4636. /* Catch add with a sign extract.
  4637. This is add_<optab><mode>_multp2. */
  4638. if (GET_CODE (x) == SIGN_EXTRACT
  4639. || GET_CODE (x) == ZERO_EXTRACT)
  4640. {
  4641. rtx op0 = XEXP (x, 0);
  4642. rtx op1 = XEXP (x, 1);
  4643. rtx op2 = XEXP (x, 2);
  4644. if (GET_CODE (op0) == MULT
  4645. && CONST_INT_P (op1)
  4646. && op2 == const0_rtx
  4647. && CONST_INT_P (XEXP (op0, 1))
  4648. && aarch64_is_extend_from_extract (mode,
  4649. XEXP (op0, 1),
  4650. op1))
  4651. {
  4652. return true;
  4653. }
  4654. }
  4655. return false;
  4656. }
  4657. static bool
  4658. aarch64_frint_unspec_p (unsigned int u)
  4659. {
  4660. switch (u)
  4661. {
  4662. case UNSPEC_FRINTZ:
  4663. case UNSPEC_FRINTP:
  4664. case UNSPEC_FRINTM:
  4665. case UNSPEC_FRINTA:
  4666. case UNSPEC_FRINTN:
  4667. case UNSPEC_FRINTX:
  4668. case UNSPEC_FRINTI:
  4669. return true;
  4670. default:
  4671. return false;
  4672. }
  4673. }
  4674. /* Calculate the cost of calculating (if_then_else (OP0) (OP1) (OP2)),
  4675. storing it in *COST. Result is true if the total cost of the operation
  4676. has now been calculated. */
  4677. static bool
  4678. aarch64_if_then_else_costs (rtx op0, rtx op1, rtx op2, int *cost, bool speed)
  4679. {
  4680. rtx inner;
  4681. rtx comparator;
  4682. enum rtx_code cmpcode;
  4683. if (COMPARISON_P (op0))
  4684. {
  4685. inner = XEXP (op0, 0);
  4686. comparator = XEXP (op0, 1);
  4687. cmpcode = GET_CODE (op0);
  4688. }
  4689. else
  4690. {
  4691. inner = op0;
  4692. comparator = const0_rtx;
  4693. cmpcode = NE;
  4694. }
  4695. if (GET_CODE (op1) == PC || GET_CODE (op2) == PC)
  4696. {
  4697. /* Conditional branch. */
  4698. if (GET_MODE_CLASS (GET_MODE (inner)) == MODE_CC)
  4699. return true;
  4700. else
  4701. {
  4702. if (cmpcode == NE || cmpcode == EQ)
  4703. {
  4704. if (comparator == const0_rtx)
  4705. {
  4706. /* TBZ/TBNZ/CBZ/CBNZ. */
  4707. if (GET_CODE (inner) == ZERO_EXTRACT)
  4708. /* TBZ/TBNZ. */
  4709. *cost += rtx_cost (XEXP (inner, 0), ZERO_EXTRACT,
  4710. 0, speed);
  4711. else
  4712. /* CBZ/CBNZ. */
  4713. *cost += rtx_cost (inner, cmpcode, 0, speed);
  4714. return true;
  4715. }
  4716. }
  4717. else if (cmpcode == LT || cmpcode == GE)
  4718. {
  4719. /* TBZ/TBNZ. */
  4720. if (comparator == const0_rtx)
  4721. return true;
  4722. }
  4723. }
  4724. }
  4725. else if (GET_MODE_CLASS (GET_MODE (inner)) == MODE_CC)
  4726. {
  4727. /* It's a conditional operation based on the status flags,
  4728. so it must be some flavor of CSEL. */
  4729. /* CSNEG, CSINV, and CSINC are handled for free as part of CSEL. */
  4730. if (GET_CODE (op1) == NEG
  4731. || GET_CODE (op1) == NOT
  4732. || (GET_CODE (op1) == PLUS && XEXP (op1, 1) == const1_rtx))
  4733. op1 = XEXP (op1, 0);
  4734. *cost += rtx_cost (op1, IF_THEN_ELSE, 1, speed);
  4735. *cost += rtx_cost (op2, IF_THEN_ELSE, 2, speed);
  4736. return true;
  4737. }
  4738. /* We don't know what this is, cost all operands. */
  4739. return false;
  4740. }
  4741. /* Calculate the cost of calculating X, storing it in *COST. Result
  4742. is true if the total cost of the operation has now been calculated. */
  4743. static bool
  4744. aarch64_rtx_costs (rtx x, int code, int outer ATTRIBUTE_UNUSED,
  4745. int param ATTRIBUTE_UNUSED, int *cost, bool speed)
  4746. {
  4747. rtx op0, op1, op2;
  4748. const struct cpu_cost_table *extra_cost
  4749. = aarch64_tune_params->insn_extra_cost;
  4750. machine_mode mode = GET_MODE (x);
  4751. /* By default, assume that everything has equivalent cost to the
  4752. cheapest instruction. Any additional costs are applied as a delta
  4753. above this default. */
  4754. *cost = COSTS_N_INSNS (1);
  4755. /* TODO: The cost infrastructure currently does not handle
  4756. vector operations. Assume that all vector operations
  4757. are equally expensive. */
  4758. if (VECTOR_MODE_P (mode))
  4759. {
  4760. if (speed)
  4761. *cost += extra_cost->vect.alu;
  4762. return true;
  4763. }
  4764. switch (code)
  4765. {
  4766. case SET:
  4767. /* The cost depends entirely on the operands to SET. */
  4768. *cost = 0;
  4769. op0 = SET_DEST (x);
  4770. op1 = SET_SRC (x);
  4771. switch (GET_CODE (op0))
  4772. {
  4773. case MEM:
  4774. if (speed)
  4775. {
  4776. rtx address = XEXP (op0, 0);
  4777. if (GET_MODE_CLASS (mode) == MODE_INT)
  4778. *cost += extra_cost->ldst.store;
  4779. else if (mode == SFmode)
  4780. *cost += extra_cost->ldst.storef;
  4781. else if (mode == DFmode)
  4782. *cost += extra_cost->ldst.stored;
  4783. *cost +=
  4784. COSTS_N_INSNS (aarch64_address_cost (address, mode,
  4785. 0, speed));
  4786. }
  4787. *cost += rtx_cost (op1, SET, 1, speed);
  4788. return true;
  4789. case SUBREG:
  4790. if (! REG_P (SUBREG_REG (op0)))
  4791. *cost += rtx_cost (SUBREG_REG (op0), SET, 0, speed);
  4792. /* Fall through. */
  4793. case REG:
  4794. /* const0_rtx is in general free, but we will use an
  4795. instruction to set a register to 0. */
  4796. if (REG_P (op1) || op1 == const0_rtx)
  4797. {
  4798. /* The cost is 1 per register copied. */
  4799. int n_minus_1 = (GET_MODE_SIZE (GET_MODE (op0)) - 1)
  4800. / UNITS_PER_WORD;
  4801. *cost = COSTS_N_INSNS (n_minus_1 + 1);
  4802. }
  4803. else
  4804. /* Cost is just the cost of the RHS of the set. */
  4805. *cost += rtx_cost (op1, SET, 1, speed);
  4806. return true;
  4807. case ZERO_EXTRACT:
  4808. case SIGN_EXTRACT:
  4809. /* Bit-field insertion. Strip any redundant widening of
  4810. the RHS to meet the width of the target. */
  4811. if (GET_CODE (op1) == SUBREG)
  4812. op1 = SUBREG_REG (op1);
  4813. if ((GET_CODE (op1) == ZERO_EXTEND
  4814. || GET_CODE (op1) == SIGN_EXTEND)
  4815. && CONST_INT_P (XEXP (op0, 1))
  4816. && (GET_MODE_BITSIZE (GET_MODE (XEXP (op1, 0)))
  4817. >= INTVAL (XEXP (op0, 1))))
  4818. op1 = XEXP (op1, 0);
  4819. if (CONST_INT_P (op1))
  4820. {
  4821. /* MOV immediate is assumed to always be cheap. */
  4822. *cost = COSTS_N_INSNS (1);
  4823. }
  4824. else
  4825. {
  4826. /* BFM. */
  4827. if (speed)
  4828. *cost += extra_cost->alu.bfi;
  4829. *cost += rtx_cost (op1, (enum rtx_code) code, 1, speed);
  4830. }
  4831. return true;
  4832. default:
  4833. /* We can't make sense of this, assume default cost. */
  4834. *cost = COSTS_N_INSNS (1);
  4835. return false;
  4836. }
  4837. return false;
  4838. case CONST_INT:
  4839. /* If an instruction can incorporate a constant within the
  4840. instruction, the instruction's expression avoids calling
  4841. rtx_cost() on the constant. If rtx_cost() is called on a
  4842. constant, then it is usually because the constant must be
  4843. moved into a register by one or more instructions.
  4844. The exception is constant 0, which can be expressed
  4845. as XZR/WZR and is therefore free. The exception to this is
  4846. if we have (set (reg) (const0_rtx)) in which case we must cost
  4847. the move. However, we can catch that when we cost the SET, so
  4848. we don't need to consider that here. */
  4849. if (x == const0_rtx)
  4850. *cost = 0;
  4851. else
  4852. {
  4853. /* To an approximation, building any other constant is
  4854. proportionally expensive to the number of instructions
  4855. required to build that constant. This is true whether we
  4856. are compiling for SPEED or otherwise. */
  4857. *cost = COSTS_N_INSNS (aarch64_internal_mov_immediate
  4858. (NULL_RTX, x, false, mode));
  4859. }
  4860. return true;
  4861. case CONST_DOUBLE:
  4862. if (speed)
  4863. {
  4864. /* mov[df,sf]_aarch64. */
  4865. if (aarch64_float_const_representable_p (x))
  4866. /* FMOV (scalar immediate). */
  4867. *cost += extra_cost->fp[mode == DFmode].fpconst;
  4868. else if (!aarch64_float_const_zero_rtx_p (x))
  4869. {
  4870. /* This will be a load from memory. */
  4871. if (mode == DFmode)
  4872. *cost += extra_cost->ldst.loadd;
  4873. else
  4874. *cost += extra_cost->ldst.loadf;
  4875. }
  4876. else
  4877. /* Otherwise this is +0.0. We get this using MOVI d0, #0
  4878. or MOV v0.s[0], wzr - neither of which are modeled by the
  4879. cost tables. Just use the default cost. */
  4880. {
  4881. }
  4882. }
  4883. return true;
  4884. case MEM:
  4885. if (speed)
  4886. {
  4887. /* For loads we want the base cost of a load, plus an
  4888. approximation for the additional cost of the addressing
  4889. mode. */
  4890. rtx address = XEXP (x, 0);
  4891. if (GET_MODE_CLASS (mode) == MODE_INT)
  4892. *cost += extra_cost->ldst.load;
  4893. else if (mode == SFmode)
  4894. *cost += extra_cost->ldst.loadf;
  4895. else if (mode == DFmode)
  4896. *cost += extra_cost->ldst.loadd;
  4897. *cost +=
  4898. COSTS_N_INSNS (aarch64_address_cost (address, mode,
  4899. 0, speed));
  4900. }
  4901. return true;
  4902. case NEG:
  4903. op0 = XEXP (x, 0);
  4904. if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
  4905. {
  4906. if (GET_RTX_CLASS (GET_CODE (op0)) == RTX_COMPARE
  4907. || GET_RTX_CLASS (GET_CODE (op0)) == RTX_COMM_COMPARE)
  4908. {
  4909. /* CSETM. */
  4910. *cost += rtx_cost (XEXP (op0, 0), NEG, 0, speed);
  4911. return true;
  4912. }
  4913. /* Cost this as SUB wzr, X. */
  4914. op0 = CONST0_RTX (GET_MODE (x));
  4915. op1 = XEXP (x, 0);
  4916. goto cost_minus;
  4917. }
  4918. if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
  4919. {
  4920. /* Support (neg(fma...)) as a single instruction only if
  4921. sign of zeros is unimportant. This matches the decision
  4922. making in aarch64.md. */
  4923. if (GET_CODE (op0) == FMA && !HONOR_SIGNED_ZEROS (GET_MODE (op0)))
  4924. {
  4925. /* FNMADD. */
  4926. *cost = rtx_cost (op0, NEG, 0, speed);
  4927. return true;
  4928. }
  4929. if (speed)
  4930. /* FNEG. */
  4931. *cost += extra_cost->fp[mode == DFmode].neg;
  4932. return false;
  4933. }
  4934. return false;
  4935. case CLRSB:
  4936. case CLZ:
  4937. if (speed)
  4938. *cost += extra_cost->alu.clz;
  4939. return false;
  4940. case COMPARE:
  4941. op0 = XEXP (x, 0);
  4942. op1 = XEXP (x, 1);
  4943. if (op1 == const0_rtx
  4944. && GET_CODE (op0) == AND)
  4945. {
  4946. x = op0;
  4947. goto cost_logic;
  4948. }
  4949. if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT)
  4950. {
  4951. /* TODO: A write to the CC flags possibly costs extra, this
  4952. needs encoding in the cost tables. */
  4953. /* CC_ZESWPmode supports zero extend for free. */
  4954. if (GET_MODE (x) == CC_ZESWPmode && GET_CODE (op0) == ZERO_EXTEND)
  4955. op0 = XEXP (op0, 0);
  4956. /* ANDS. */
  4957. if (GET_CODE (op0) == AND)
  4958. {
  4959. x = op0;
  4960. goto cost_logic;
  4961. }
  4962. if (GET_CODE (op0) == PLUS)
  4963. {
  4964. /* ADDS (and CMN alias). */
  4965. x = op0;
  4966. goto cost_plus;
  4967. }
  4968. if (GET_CODE (op0) == MINUS)
  4969. {
  4970. /* SUBS. */
  4971. x = op0;
  4972. goto cost_minus;
  4973. }
  4974. if (GET_CODE (op1) == NEG)
  4975. {
  4976. /* CMN. */
  4977. if (speed)
  4978. *cost += extra_cost->alu.arith;
  4979. *cost += rtx_cost (op0, COMPARE, 0, speed);
  4980. *cost += rtx_cost (XEXP (op1, 0), NEG, 1, speed);
  4981. return true;
  4982. }
  4983. /* CMP.
  4984. Compare can freely swap the order of operands, and
  4985. canonicalization puts the more complex operation first.
  4986. But the integer MINUS logic expects the shift/extend
  4987. operation in op1. */
  4988. if (! (REG_P (op0)
  4989. || (GET_CODE (op0) == SUBREG && REG_P (SUBREG_REG (op0)))))
  4990. {
  4991. op0 = XEXP (x, 1);
  4992. op1 = XEXP (x, 0);
  4993. }
  4994. goto cost_minus;
  4995. }
  4996. if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_FLOAT)
  4997. {
  4998. /* FCMP. */
  4999. if (speed)
  5000. *cost += extra_cost->fp[mode == DFmode].compare;
  5001. if (CONST_DOUBLE_P (op1) && aarch64_float_const_zero_rtx_p (op1))
  5002. {
  5003. /* FCMP supports constant 0.0 for no extra cost. */
  5004. return true;
  5005. }
  5006. return false;
  5007. }
  5008. return false;
  5009. case MINUS:
  5010. {
  5011. op0 = XEXP (x, 0);
  5012. op1 = XEXP (x, 1);
  5013. cost_minus:
  5014. /* Detect valid immediates. */
  5015. if ((GET_MODE_CLASS (mode) == MODE_INT
  5016. || (GET_MODE_CLASS (mode) == MODE_CC
  5017. && GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT))
  5018. && CONST_INT_P (op1)
  5019. && aarch64_uimm12_shift (INTVAL (op1)))
  5020. {
  5021. *cost += rtx_cost (op0, MINUS, 0, speed);
  5022. if (speed)
  5023. /* SUB(S) (immediate). */
  5024. *cost += extra_cost->alu.arith;
  5025. return true;
  5026. }
  5027. /* Look for SUB (extended register). */
  5028. if (aarch64_rtx_arith_op_extract_p (op1, mode))
  5029. {
  5030. if (speed)
  5031. *cost += extra_cost->alu.arith_shift;
  5032. *cost += rtx_cost (XEXP (XEXP (op1, 0), 0),
  5033. (enum rtx_code) GET_CODE (op1),
  5034. 0, speed);
  5035. return true;
  5036. }
  5037. rtx new_op1 = aarch64_strip_extend (op1);
  5038. /* Cost this as an FMA-alike operation. */
  5039. if ((GET_CODE (new_op1) == MULT
  5040. || GET_CODE (new_op1) == ASHIFT)
  5041. && code != COMPARE)
  5042. {
  5043. *cost += aarch64_rtx_mult_cost (new_op1, MULT,
  5044. (enum rtx_code) code,
  5045. speed);
  5046. *cost += rtx_cost (op0, MINUS, 0, speed);
  5047. return true;
  5048. }
  5049. *cost += rtx_cost (new_op1, MINUS, 1, speed);
  5050. if (speed)
  5051. {
  5052. if (GET_MODE_CLASS (mode) == MODE_INT)
  5053. /* SUB(S). */
  5054. *cost += extra_cost->alu.arith;
  5055. else if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  5056. /* FSUB. */
  5057. *cost += extra_cost->fp[mode == DFmode].addsub;
  5058. }
  5059. return true;
  5060. }
  5061. case PLUS:
  5062. {
  5063. rtx new_op0;
  5064. op0 = XEXP (x, 0);
  5065. op1 = XEXP (x, 1);
  5066. cost_plus:
  5067. if (GET_RTX_CLASS (GET_CODE (op0)) == RTX_COMPARE
  5068. || GET_RTX_CLASS (GET_CODE (op0)) == RTX_COMM_COMPARE)
  5069. {
  5070. /* CSINC. */
  5071. *cost += rtx_cost (XEXP (op0, 0), PLUS, 0, speed);
  5072. *cost += rtx_cost (op1, PLUS, 1, speed);
  5073. return true;
  5074. }
  5075. if (GET_MODE_CLASS (mode) == MODE_INT
  5076. && CONST_INT_P (op1)
  5077. && aarch64_uimm12_shift (INTVAL (op1)))
  5078. {
  5079. *cost += rtx_cost (op0, PLUS, 0, speed);
  5080. if (speed)
  5081. /* ADD (immediate). */
  5082. *cost += extra_cost->alu.arith;
  5083. return true;
  5084. }
  5085. /* Look for ADD (extended register). */
  5086. if (aarch64_rtx_arith_op_extract_p (op0, mode))
  5087. {
  5088. if (speed)
  5089. *cost += extra_cost->alu.arith_shift;
  5090. *cost += rtx_cost (XEXP (XEXP (op0, 0), 0),
  5091. (enum rtx_code) GET_CODE (op0),
  5092. 0, speed);
  5093. return true;
  5094. }
  5095. /* Strip any extend, leave shifts behind as we will
  5096. cost them through mult_cost. */
  5097. new_op0 = aarch64_strip_extend (op0);
  5098. if (GET_CODE (new_op0) == MULT
  5099. || GET_CODE (new_op0) == ASHIFT)
  5100. {
  5101. *cost += aarch64_rtx_mult_cost (new_op0, MULT, PLUS,
  5102. speed);
  5103. *cost += rtx_cost (op1, PLUS, 1, speed);
  5104. return true;
  5105. }
  5106. *cost += (rtx_cost (new_op0, PLUS, 0, speed)
  5107. + rtx_cost (op1, PLUS, 1, speed));
  5108. if (speed)
  5109. {
  5110. if (GET_MODE_CLASS (mode) == MODE_INT)
  5111. /* ADD. */
  5112. *cost += extra_cost->alu.arith;
  5113. else if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  5114. /* FADD. */
  5115. *cost += extra_cost->fp[mode == DFmode].addsub;
  5116. }
  5117. return true;
  5118. }
  5119. case BSWAP:
  5120. *cost = COSTS_N_INSNS (1);
  5121. if (speed)
  5122. *cost += extra_cost->alu.rev;
  5123. return false;
  5124. case IOR:
  5125. if (aarch_rev16_p (x))
  5126. {
  5127. *cost = COSTS_N_INSNS (1);
  5128. if (speed)
  5129. *cost += extra_cost->alu.rev;
  5130. return true;
  5131. }
  5132. /* Fall through. */
  5133. case XOR:
  5134. case AND:
  5135. cost_logic:
  5136. op0 = XEXP (x, 0);
  5137. op1 = XEXP (x, 1);
  5138. if (code == AND
  5139. && GET_CODE (op0) == MULT
  5140. && CONST_INT_P (XEXP (op0, 1))
  5141. && CONST_INT_P (op1)
  5142. && aarch64_uxt_size (exact_log2 (INTVAL (XEXP (op0, 1))),
  5143. INTVAL (op1)) != 0)
  5144. {
  5145. /* This is a UBFM/SBFM. */
  5146. *cost += rtx_cost (XEXP (op0, 0), ZERO_EXTRACT, 0, speed);
  5147. if (speed)
  5148. *cost += extra_cost->alu.bfx;
  5149. return true;
  5150. }
  5151. if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
  5152. {
  5153. /* We possibly get the immediate for free, this is not
  5154. modelled. */
  5155. if (CONST_INT_P (op1)
  5156. && aarch64_bitmask_imm (INTVAL (op1), GET_MODE (x)))
  5157. {
  5158. *cost += rtx_cost (op0, (enum rtx_code) code, 0, speed);
  5159. if (speed)
  5160. *cost += extra_cost->alu.logical;
  5161. return true;
  5162. }
  5163. else
  5164. {
  5165. rtx new_op0 = op0;
  5166. /* Handle ORN, EON, or BIC. */
  5167. if (GET_CODE (op0) == NOT)
  5168. op0 = XEXP (op0, 0);
  5169. new_op0 = aarch64_strip_shift (op0);
  5170. /* If we had a shift on op0 then this is a logical-shift-
  5171. by-register/immediate operation. Otherwise, this is just
  5172. a logical operation. */
  5173. if (speed)
  5174. {
  5175. if (new_op0 != op0)
  5176. {
  5177. /* Shift by immediate. */
  5178. if (CONST_INT_P (XEXP (op0, 1)))
  5179. *cost += extra_cost->alu.log_shift;
  5180. else
  5181. *cost += extra_cost->alu.log_shift_reg;
  5182. }
  5183. else
  5184. *cost += extra_cost->alu.logical;
  5185. }
  5186. /* In both cases we want to cost both operands. */
  5187. *cost += rtx_cost (new_op0, (enum rtx_code) code, 0, speed)
  5188. + rtx_cost (op1, (enum rtx_code) code, 1, speed);
  5189. return true;
  5190. }
  5191. }
  5192. return false;
  5193. case NOT:
  5194. /* MVN. */
  5195. if (speed)
  5196. *cost += extra_cost->alu.logical;
  5197. /* The logical instruction could have the shifted register form,
  5198. but the cost is the same if the shift is processed as a separate
  5199. instruction, so we don't bother with it here. */
  5200. return false;
  5201. case ZERO_EXTEND:
  5202. op0 = XEXP (x, 0);
  5203. /* If a value is written in SI mode, then zero extended to DI
  5204. mode, the operation will in general be free as a write to
  5205. a 'w' register implicitly zeroes the upper bits of an 'x'
  5206. register. However, if this is
  5207. (set (reg) (zero_extend (reg)))
  5208. we must cost the explicit register move. */
  5209. if (mode == DImode
  5210. && GET_MODE (op0) == SImode
  5211. && outer == SET)
  5212. {
  5213. int op_cost = rtx_cost (XEXP (x, 0), ZERO_EXTEND, 0, speed);
  5214. if (!op_cost && speed)
  5215. /* MOV. */
  5216. *cost += extra_cost->alu.extend;
  5217. else
  5218. /* Free, the cost is that of the SI mode operation. */
  5219. *cost = op_cost;
  5220. return true;
  5221. }
  5222. else if (MEM_P (XEXP (x, 0)))
  5223. {
  5224. /* All loads can zero extend to any size for free. */
  5225. *cost = rtx_cost (XEXP (x, 0), ZERO_EXTEND, param, speed);
  5226. return true;
  5227. }
  5228. /* UXTB/UXTH. */
  5229. if (speed)
  5230. *cost += extra_cost->alu.extend;
  5231. return false;
  5232. case SIGN_EXTEND:
  5233. if (MEM_P (XEXP (x, 0)))
  5234. {
  5235. /* LDRSH. */
  5236. if (speed)
  5237. {
  5238. rtx address = XEXP (XEXP (x, 0), 0);
  5239. *cost += extra_cost->ldst.load_sign_extend;
  5240. *cost +=
  5241. COSTS_N_INSNS (aarch64_address_cost (address, mode,
  5242. 0, speed));
  5243. }
  5244. return true;
  5245. }
  5246. if (speed)
  5247. *cost += extra_cost->alu.extend;
  5248. return false;
  5249. case ASHIFT:
  5250. op0 = XEXP (x, 0);
  5251. op1 = XEXP (x, 1);
  5252. if (CONST_INT_P (op1))
  5253. {
  5254. /* LSL (immediate), UBMF, UBFIZ and friends. These are all
  5255. aliases. */
  5256. if (speed)
  5257. *cost += extra_cost->alu.shift;
  5258. /* We can incorporate zero/sign extend for free. */
  5259. if (GET_CODE (op0) == ZERO_EXTEND
  5260. || GET_CODE (op0) == SIGN_EXTEND)
  5261. op0 = XEXP (op0, 0);
  5262. *cost += rtx_cost (op0, ASHIFT, 0, speed);
  5263. return true;
  5264. }
  5265. else
  5266. {
  5267. /* LSLV. */
  5268. if (speed)
  5269. *cost += extra_cost->alu.shift_reg;
  5270. return false; /* All arguments need to be in registers. */
  5271. }
  5272. case ROTATE:
  5273. case ROTATERT:
  5274. case LSHIFTRT:
  5275. case ASHIFTRT:
  5276. op0 = XEXP (x, 0);
  5277. op1 = XEXP (x, 1);
  5278. if (CONST_INT_P (op1))
  5279. {
  5280. /* ASR (immediate) and friends. */
  5281. if (speed)
  5282. *cost += extra_cost->alu.shift;
  5283. *cost += rtx_cost (op0, (enum rtx_code) code, 0, speed);
  5284. return true;
  5285. }
  5286. else
  5287. {
  5288. /* ASR (register) and friends. */
  5289. if (speed)
  5290. *cost += extra_cost->alu.shift_reg;
  5291. return false; /* All arguments need to be in registers. */
  5292. }
  5293. case SYMBOL_REF:
  5294. if (aarch64_cmodel == AARCH64_CMODEL_LARGE)
  5295. {
  5296. /* LDR. */
  5297. if (speed)
  5298. *cost += extra_cost->ldst.load;
  5299. }
  5300. else if (aarch64_cmodel == AARCH64_CMODEL_SMALL
  5301. || aarch64_cmodel == AARCH64_CMODEL_SMALL_PIC)
  5302. {
  5303. /* ADRP, followed by ADD. */
  5304. *cost += COSTS_N_INSNS (1);
  5305. if (speed)
  5306. *cost += 2 * extra_cost->alu.arith;
  5307. }
  5308. else if (aarch64_cmodel == AARCH64_CMODEL_TINY
  5309. || aarch64_cmodel == AARCH64_CMODEL_TINY_PIC)
  5310. {
  5311. /* ADR. */
  5312. if (speed)
  5313. *cost += extra_cost->alu.arith;
  5314. }
  5315. if (flag_pic)
  5316. {
  5317. /* One extra load instruction, after accessing the GOT. */
  5318. *cost += COSTS_N_INSNS (1);
  5319. if (speed)
  5320. *cost += extra_cost->ldst.load;
  5321. }
  5322. return true;
  5323. case HIGH:
  5324. case LO_SUM:
  5325. /* ADRP/ADD (immediate). */
  5326. if (speed)
  5327. *cost += extra_cost->alu.arith;
  5328. return true;
  5329. case ZERO_EXTRACT:
  5330. case SIGN_EXTRACT:
  5331. /* UBFX/SBFX. */
  5332. if (speed)
  5333. *cost += extra_cost->alu.bfx;
  5334. /* We can trust that the immediates used will be correct (there
  5335. are no by-register forms), so we need only cost op0. */
  5336. *cost += rtx_cost (XEXP (x, 0), (enum rtx_code) code, 0, speed);
  5337. return true;
  5338. case MULT:
  5339. *cost += aarch64_rtx_mult_cost (x, MULT, 0, speed);
  5340. /* aarch64_rtx_mult_cost always handles recursion to its
  5341. operands. */
  5342. return true;
  5343. case MOD:
  5344. case UMOD:
  5345. if (speed)
  5346. {
  5347. if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
  5348. *cost += (extra_cost->mult[GET_MODE (x) == DImode].add
  5349. + extra_cost->mult[GET_MODE (x) == DImode].idiv);
  5350. else if (GET_MODE (x) == DFmode)
  5351. *cost += (extra_cost->fp[1].mult
  5352. + extra_cost->fp[1].div);
  5353. else if (GET_MODE (x) == SFmode)
  5354. *cost += (extra_cost->fp[0].mult
  5355. + extra_cost->fp[0].div);
  5356. }
  5357. return false; /* All arguments need to be in registers. */
  5358. case DIV:
  5359. case UDIV:
  5360. case SQRT:
  5361. if (speed)
  5362. {
  5363. if (GET_MODE_CLASS (mode) == MODE_INT)
  5364. /* There is no integer SQRT, so only DIV and UDIV can get
  5365. here. */
  5366. *cost += extra_cost->mult[mode == DImode].idiv;
  5367. else
  5368. *cost += extra_cost->fp[mode == DFmode].div;
  5369. }
  5370. return false; /* All arguments need to be in registers. */
  5371. case IF_THEN_ELSE:
  5372. return aarch64_if_then_else_costs (XEXP (x, 0), XEXP (x, 1),
  5373. XEXP (x, 2), cost, speed);
  5374. case EQ:
  5375. case NE:
  5376. case GT:
  5377. case GTU:
  5378. case LT:
  5379. case LTU:
  5380. case GE:
  5381. case GEU:
  5382. case LE:
  5383. case LEU:
  5384. return false; /* All arguments must be in registers. */
  5385. case FMA:
  5386. op0 = XEXP (x, 0);
  5387. op1 = XEXP (x, 1);
  5388. op2 = XEXP (x, 2);
  5389. if (speed)
  5390. *cost += extra_cost->fp[mode == DFmode].fma;
  5391. /* FMSUB, FNMADD, and FNMSUB are free. */
  5392. if (GET_CODE (op0) == NEG)
  5393. op0 = XEXP (op0, 0);
  5394. if (GET_CODE (op2) == NEG)
  5395. op2 = XEXP (op2, 0);
  5396. /* aarch64_fnma4_elt_to_64v2df has the NEG as operand 1,
  5397. and the by-element operand as operand 0. */
  5398. if (GET_CODE (op1) == NEG)
  5399. op1 = XEXP (op1, 0);
  5400. /* Catch vector-by-element operations. The by-element operand can
  5401. either be (vec_duplicate (vec_select (x))) or just
  5402. (vec_select (x)), depending on whether we are multiplying by
  5403. a vector or a scalar.
  5404. Canonicalization is not very good in these cases, FMA4 will put the
  5405. by-element operand as operand 0, FNMA4 will have it as operand 1. */
  5406. if (GET_CODE (op0) == VEC_DUPLICATE)
  5407. op0 = XEXP (op0, 0);
  5408. else if (GET_CODE (op1) == VEC_DUPLICATE)
  5409. op1 = XEXP (op1, 0);
  5410. if (GET_CODE (op0) == VEC_SELECT)
  5411. op0 = XEXP (op0, 0);
  5412. else if (GET_CODE (op1) == VEC_SELECT)
  5413. op1 = XEXP (op1, 0);
  5414. /* If the remaining parameters are not registers,
  5415. get the cost to put them into registers. */
  5416. *cost += rtx_cost (op0, FMA, 0, speed);
  5417. *cost += rtx_cost (op1, FMA, 1, speed);
  5418. *cost += rtx_cost (op2, FMA, 2, speed);
  5419. return true;
  5420. case FLOAT_EXTEND:
  5421. if (speed)
  5422. *cost += extra_cost->fp[mode == DFmode].widen;
  5423. return false;
  5424. case FLOAT_TRUNCATE:
  5425. if (speed)
  5426. *cost += extra_cost->fp[mode == DFmode].narrow;
  5427. return false;
  5428. case FIX:
  5429. case UNSIGNED_FIX:
  5430. x = XEXP (x, 0);
  5431. /* Strip the rounding part. They will all be implemented
  5432. by the fcvt* family of instructions anyway. */
  5433. if (GET_CODE (x) == UNSPEC)
  5434. {
  5435. unsigned int uns_code = XINT (x, 1);
  5436. if (uns_code == UNSPEC_FRINTA
  5437. || uns_code == UNSPEC_FRINTM
  5438. || uns_code == UNSPEC_FRINTN
  5439. || uns_code == UNSPEC_FRINTP
  5440. || uns_code == UNSPEC_FRINTZ)
  5441. x = XVECEXP (x, 0, 0);
  5442. }
  5443. if (speed)
  5444. *cost += extra_cost->fp[GET_MODE (x) == DFmode].toint;
  5445. *cost += rtx_cost (x, (enum rtx_code) code, 0, speed);
  5446. return true;
  5447. case ABS:
  5448. if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  5449. {
  5450. /* FABS and FNEG are analogous. */
  5451. if (speed)
  5452. *cost += extra_cost->fp[mode == DFmode].neg;
  5453. }
  5454. else
  5455. {
  5456. /* Integer ABS will either be split to
  5457. two arithmetic instructions, or will be an ABS
  5458. (scalar), which we don't model. */
  5459. *cost = COSTS_N_INSNS (2);
  5460. if (speed)
  5461. *cost += 2 * extra_cost->alu.arith;
  5462. }
  5463. return false;
  5464. case SMAX:
  5465. case SMIN:
  5466. if (speed)
  5467. {
  5468. /* FMAXNM/FMINNM/FMAX/FMIN.
  5469. TODO: This may not be accurate for all implementations, but
  5470. we do not model this in the cost tables. */
  5471. *cost += extra_cost->fp[mode == DFmode].addsub;
  5472. }
  5473. return false;
  5474. case UNSPEC:
  5475. /* The floating point round to integer frint* instructions. */
  5476. if (aarch64_frint_unspec_p (XINT (x, 1)))
  5477. {
  5478. if (speed)
  5479. *cost += extra_cost->fp[mode == DFmode].roundint;
  5480. return false;
  5481. }
  5482. if (XINT (x, 1) == UNSPEC_RBIT)
  5483. {
  5484. if (speed)
  5485. *cost += extra_cost->alu.rev;
  5486. return false;
  5487. }
  5488. break;
  5489. case TRUNCATE:
  5490. /* Decompose <su>muldi3_highpart. */
  5491. if (/* (truncate:DI */
  5492. mode == DImode
  5493. /* (lshiftrt:TI */
  5494. && GET_MODE (XEXP (x, 0)) == TImode
  5495. && GET_CODE (XEXP (x, 0)) == LSHIFTRT
  5496. /* (mult:TI */
  5497. && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
  5498. /* (ANY_EXTEND:TI (reg:DI))
  5499. (ANY_EXTEND:TI (reg:DI))) */
  5500. && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND
  5501. && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == ZERO_EXTEND)
  5502. || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND
  5503. && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == SIGN_EXTEND))
  5504. && GET_MODE (XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 0)) == DImode
  5505. && GET_MODE (XEXP (XEXP (XEXP (XEXP (x, 0), 0), 1), 0)) == DImode
  5506. /* (const_int 64) */
  5507. && CONST_INT_P (XEXP (XEXP (x, 0), 1))
  5508. && UINTVAL (XEXP (XEXP (x, 0), 1)) == 64)
  5509. {
  5510. /* UMULH/SMULH. */
  5511. if (speed)
  5512. *cost += extra_cost->mult[mode == DImode].extend;
  5513. *cost += rtx_cost (XEXP (XEXP (XEXP (XEXP (x, 0), 0), 0), 0),
  5514. MULT, 0, speed);
  5515. *cost += rtx_cost (XEXP (XEXP (XEXP (XEXP (x, 0), 0), 1), 0),
  5516. MULT, 1, speed);
  5517. return true;
  5518. }
  5519. /* Fall through. */
  5520. default:
  5521. break;
  5522. }
  5523. if (dump_file && (dump_flags & TDF_DETAILS))
  5524. fprintf (dump_file,
  5525. "\nFailed to cost RTX. Assuming default cost.\n");
  5526. return true;
  5527. }
  5528. /* Wrapper around aarch64_rtx_costs, dumps the partial, or total cost
  5529. calculated for X. This cost is stored in *COST. Returns true
  5530. if the total cost of X was calculated. */
  5531. static bool
  5532. aarch64_rtx_costs_wrapper (rtx x, int code, int outer,
  5533. int param, int *cost, bool speed)
  5534. {
  5535. bool result = aarch64_rtx_costs (x, code, outer, param, cost, speed);
  5536. if (dump_file && (dump_flags & TDF_DETAILS))
  5537. {
  5538. print_rtl_single (dump_file, x);
  5539. fprintf (dump_file, "\n%s cost: %d (%s)\n",
  5540. speed ? "Hot" : "Cold",
  5541. *cost, result ? "final" : "partial");
  5542. }
  5543. return result;
  5544. }
  5545. static int
  5546. aarch64_register_move_cost (machine_mode mode,
  5547. reg_class_t from_i, reg_class_t to_i)
  5548. {
  5549. enum reg_class from = (enum reg_class) from_i;
  5550. enum reg_class to = (enum reg_class) to_i;
  5551. const struct cpu_regmove_cost *regmove_cost
  5552. = aarch64_tune_params->regmove_cost;
  5553. /* Caller save and pointer regs are equivalent to GENERAL_REGS. */
  5554. if (to == CALLER_SAVE_REGS || to == POINTER_REGS)
  5555. to = GENERAL_REGS;
  5556. if (from == CALLER_SAVE_REGS || from == POINTER_REGS)
  5557. from = GENERAL_REGS;
  5558. /* Moving between GPR and stack cost is the same as GP2GP. */
  5559. if ((from == GENERAL_REGS && to == STACK_REG)
  5560. || (to == GENERAL_REGS && from == STACK_REG))
  5561. return regmove_cost->GP2GP;
  5562. /* To/From the stack register, we move via the gprs. */
  5563. if (to == STACK_REG || from == STACK_REG)
  5564. return aarch64_register_move_cost (mode, from, GENERAL_REGS)
  5565. + aarch64_register_move_cost (mode, GENERAL_REGS, to);
  5566. if (GET_MODE_SIZE (mode) == 16)
  5567. {
  5568. /* 128-bit operations on general registers require 2 instructions. */
  5569. if (from == GENERAL_REGS && to == GENERAL_REGS)
  5570. return regmove_cost->GP2GP * 2;
  5571. else if (from == GENERAL_REGS)
  5572. return regmove_cost->GP2FP * 2;
  5573. else if (to == GENERAL_REGS)
  5574. return regmove_cost->FP2GP * 2;
  5575. /* When AdvSIMD instructions are disabled it is not possible to move
  5576. a 128-bit value directly between Q registers. This is handled in
  5577. secondary reload. A general register is used as a scratch to move
  5578. the upper DI value and the lower DI value is moved directly,
  5579. hence the cost is the sum of three moves. */
  5580. if (! TARGET_SIMD)
  5581. return regmove_cost->GP2FP + regmove_cost->FP2GP + regmove_cost->FP2FP;
  5582. return regmove_cost->FP2FP;
  5583. }
  5584. if (from == GENERAL_REGS && to == GENERAL_REGS)
  5585. return regmove_cost->GP2GP;
  5586. else if (from == GENERAL_REGS)
  5587. return regmove_cost->GP2FP;
  5588. else if (to == GENERAL_REGS)
  5589. return regmove_cost->FP2GP;
  5590. return regmove_cost->FP2FP;
  5591. }
  5592. static int
  5593. aarch64_memory_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
  5594. reg_class_t rclass ATTRIBUTE_UNUSED,
  5595. bool in ATTRIBUTE_UNUSED)
  5596. {
  5597. return aarch64_tune_params->memmov_cost;
  5598. }
  5599. /* Return the number of instructions that can be issued per cycle. */
  5600. static int
  5601. aarch64_sched_issue_rate (void)
  5602. {
  5603. return aarch64_tune_params->issue_rate;
  5604. }
  5605. static int
  5606. aarch64_sched_first_cycle_multipass_dfa_lookahead (void)
  5607. {
  5608. int issue_rate = aarch64_sched_issue_rate ();
  5609. return issue_rate > 1 && !sched_fusion ? issue_rate : 0;
  5610. }
  5611. /* Vectorizer cost model target hooks. */
  5612. /* Implement targetm.vectorize.builtin_vectorization_cost. */
  5613. static int
  5614. aarch64_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
  5615. tree vectype,
  5616. int misalign ATTRIBUTE_UNUSED)
  5617. {
  5618. unsigned elements;
  5619. switch (type_of_cost)
  5620. {
  5621. case scalar_stmt:
  5622. return aarch64_tune_params->vec_costs->scalar_stmt_cost;
  5623. case scalar_load:
  5624. return aarch64_tune_params->vec_costs->scalar_load_cost;
  5625. case scalar_store:
  5626. return aarch64_tune_params->vec_costs->scalar_store_cost;
  5627. case vector_stmt:
  5628. return aarch64_tune_params->vec_costs->vec_stmt_cost;
  5629. case vector_load:
  5630. return aarch64_tune_params->vec_costs->vec_align_load_cost;
  5631. case vector_store:
  5632. return aarch64_tune_params->vec_costs->vec_store_cost;
  5633. case vec_to_scalar:
  5634. return aarch64_tune_params->vec_costs->vec_to_scalar_cost;
  5635. case scalar_to_vec:
  5636. return aarch64_tune_params->vec_costs->scalar_to_vec_cost;
  5637. case unaligned_load:
  5638. return aarch64_tune_params->vec_costs->vec_unalign_load_cost;
  5639. case unaligned_store:
  5640. return aarch64_tune_params->vec_costs->vec_unalign_store_cost;
  5641. case cond_branch_taken:
  5642. return aarch64_tune_params->vec_costs->cond_taken_branch_cost;
  5643. case cond_branch_not_taken:
  5644. return aarch64_tune_params->vec_costs->cond_not_taken_branch_cost;
  5645. case vec_perm:
  5646. case vec_promote_demote:
  5647. return aarch64_tune_params->vec_costs->vec_stmt_cost;
  5648. case vec_construct:
  5649. elements = TYPE_VECTOR_SUBPARTS (vectype);
  5650. return elements / 2 + 1;
  5651. default:
  5652. gcc_unreachable ();
  5653. }
  5654. }
  5655. /* Implement targetm.vectorize.add_stmt_cost. */
  5656. static unsigned
  5657. aarch64_add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
  5658. struct _stmt_vec_info *stmt_info, int misalign,
  5659. enum vect_cost_model_location where)
  5660. {
  5661. unsigned *cost = (unsigned *) data;
  5662. unsigned retval = 0;
  5663. if (flag_vect_cost_model)
  5664. {
  5665. tree vectype = stmt_info ? stmt_vectype (stmt_info) : NULL_TREE;
  5666. int stmt_cost =
  5667. aarch64_builtin_vectorization_cost (kind, vectype, misalign);
  5668. /* Statements in an inner loop relative to the loop being
  5669. vectorized are weighted more heavily. The value here is
  5670. a function (linear for now) of the loop nest level. */
  5671. if (where == vect_body && stmt_info && stmt_in_inner_loop_p (stmt_info))
  5672. {
  5673. loop_vec_info loop_info = STMT_VINFO_LOOP_VINFO (stmt_info);
  5674. struct loop *loop = LOOP_VINFO_LOOP (loop_info);
  5675. unsigned nest_level = loop_depth (loop);
  5676. count *= nest_level;
  5677. }
  5678. retval = (unsigned) (count * stmt_cost);
  5679. cost[where] += retval;
  5680. }
  5681. return retval;
  5682. }
  5683. static void initialize_aarch64_code_model (void);
  5684. /* Parse the architecture extension string. */
  5685. static void
  5686. aarch64_parse_extension (char *str)
  5687. {
  5688. /* The extension string is parsed left to right. */
  5689. const struct aarch64_option_extension *opt = NULL;
  5690. /* Flag to say whether we are adding or removing an extension. */
  5691. int adding_ext = -1;
  5692. while (str != NULL && *str != 0)
  5693. {
  5694. char *ext;
  5695. size_t len;
  5696. str++;
  5697. ext = strchr (str, '+');
  5698. if (ext != NULL)
  5699. len = ext - str;
  5700. else
  5701. len = strlen (str);
  5702. if (len >= 2 && strncmp (str, "no", 2) == 0)
  5703. {
  5704. adding_ext = 0;
  5705. len -= 2;
  5706. str += 2;
  5707. }
  5708. else if (len > 0)
  5709. adding_ext = 1;
  5710. if (len == 0)
  5711. {
  5712. error ("missing feature modifier after %qs", adding_ext ? "+"
  5713. : "+no");
  5714. return;
  5715. }
  5716. /* Scan over the extensions table trying to find an exact match. */
  5717. for (opt = all_extensions; opt->name != NULL; opt++)
  5718. {
  5719. if (strlen (opt->name) == len && strncmp (opt->name, str, len) == 0)
  5720. {
  5721. /* Add or remove the extension. */
  5722. if (adding_ext)
  5723. aarch64_isa_flags |= opt->flags_on;
  5724. else
  5725. aarch64_isa_flags &= ~(opt->flags_off);
  5726. break;
  5727. }
  5728. }
  5729. if (opt->name == NULL)
  5730. {
  5731. /* Extension not found in list. */
  5732. error ("unknown feature modifier %qs", str);
  5733. return;
  5734. }
  5735. str = ext;
  5736. };
  5737. return;
  5738. }
  5739. /* Parse the ARCH string. */
  5740. static void
  5741. aarch64_parse_arch (void)
  5742. {
  5743. char *ext;
  5744. const struct processor *arch;
  5745. char *str = (char *) alloca (strlen (aarch64_arch_string) + 1);
  5746. size_t len;
  5747. strcpy (str, aarch64_arch_string);
  5748. ext = strchr (str, '+');
  5749. if (ext != NULL)
  5750. len = ext - str;
  5751. else
  5752. len = strlen (str);
  5753. if (len == 0)
  5754. {
  5755. error ("missing arch name in -march=%qs", str);
  5756. return;
  5757. }
  5758. /* Loop through the list of supported ARCHs to find a match. */
  5759. for (arch = all_architectures; arch->name != NULL; arch++)
  5760. {
  5761. if (strlen (arch->name) == len && strncmp (arch->name, str, len) == 0)
  5762. {
  5763. selected_arch = arch;
  5764. aarch64_isa_flags = selected_arch->flags;
  5765. if (!selected_cpu)
  5766. selected_cpu = &all_cores[selected_arch->core];
  5767. if (ext != NULL)
  5768. {
  5769. /* ARCH string contains at least one extension. */
  5770. aarch64_parse_extension (ext);
  5771. }
  5772. if (strcmp (selected_arch->arch, selected_cpu->arch))
  5773. {
  5774. warning (0, "switch -mcpu=%s conflicts with -march=%s switch",
  5775. selected_cpu->name, selected_arch->name);
  5776. }
  5777. return;
  5778. }
  5779. }
  5780. /* ARCH name not found in list. */
  5781. error ("unknown value %qs for -march", str);
  5782. return;
  5783. }
  5784. /* Parse the CPU string. */
  5785. static void
  5786. aarch64_parse_cpu (void)
  5787. {
  5788. char *ext;
  5789. const struct processor *cpu;
  5790. char *str = (char *) alloca (strlen (aarch64_cpu_string) + 1);
  5791. size_t len;
  5792. strcpy (str, aarch64_cpu_string);
  5793. ext = strchr (str, '+');
  5794. if (ext != NULL)
  5795. len = ext - str;
  5796. else
  5797. len = strlen (str);
  5798. if (len == 0)
  5799. {
  5800. error ("missing cpu name in -mcpu=%qs", str);
  5801. return;
  5802. }
  5803. /* Loop through the list of supported CPUs to find a match. */
  5804. for (cpu = all_cores; cpu->name != NULL; cpu++)
  5805. {
  5806. if (strlen (cpu->name) == len && strncmp (cpu->name, str, len) == 0)
  5807. {
  5808. selected_cpu = cpu;
  5809. aarch64_isa_flags = selected_cpu->flags;
  5810. if (ext != NULL)
  5811. {
  5812. /* CPU string contains at least one extension. */
  5813. aarch64_parse_extension (ext);
  5814. }
  5815. return;
  5816. }
  5817. }
  5818. /* CPU name not found in list. */
  5819. error ("unknown value %qs for -mcpu", str);
  5820. return;
  5821. }
  5822. /* Parse the TUNE string. */
  5823. static void
  5824. aarch64_parse_tune (void)
  5825. {
  5826. const struct processor *cpu;
  5827. char *str = (char *) alloca (strlen (aarch64_tune_string) + 1);
  5828. strcpy (str, aarch64_tune_string);
  5829. /* Loop through the list of supported CPUs to find a match. */
  5830. for (cpu = all_cores; cpu->name != NULL; cpu++)
  5831. {
  5832. if (strcmp (cpu->name, str) == 0)
  5833. {
  5834. selected_tune = cpu;
  5835. return;
  5836. }
  5837. }
  5838. /* CPU name not found in list. */
  5839. error ("unknown value %qs for -mtune", str);
  5840. return;
  5841. }
  5842. /* Implement TARGET_OPTION_OVERRIDE. */
  5843. static void
  5844. aarch64_override_options (void)
  5845. {
  5846. /* -mcpu=CPU is shorthand for -march=ARCH_FOR_CPU, -mtune=CPU.
  5847. If either of -march or -mtune is given, they override their
  5848. respective component of -mcpu.
  5849. So, first parse AARCH64_CPU_STRING, then the others, be careful
  5850. with -march as, if -mcpu is not present on the command line, march
  5851. must set a sensible default CPU. */
  5852. if (aarch64_cpu_string)
  5853. {
  5854. aarch64_parse_cpu ();
  5855. }
  5856. if (aarch64_arch_string)
  5857. {
  5858. aarch64_parse_arch ();
  5859. }
  5860. if (aarch64_tune_string)
  5861. {
  5862. aarch64_parse_tune ();
  5863. }
  5864. #ifndef HAVE_AS_MABI_OPTION
  5865. /* The compiler may have been configured with 2.23.* binutils, which does
  5866. not have support for ILP32. */
  5867. if (TARGET_ILP32)
  5868. error ("Assembler does not support -mabi=ilp32");
  5869. #endif
  5870. initialize_aarch64_code_model ();
  5871. aarch64_build_bitmask_table ();
  5872. /* This target defaults to strict volatile bitfields. */
  5873. if (flag_strict_volatile_bitfields < 0 && abi_version_at_least (2))
  5874. flag_strict_volatile_bitfields = 1;
  5875. /* If the user did not specify a processor, choose the default
  5876. one for them. This will be the CPU set during configuration using
  5877. --with-cpu, otherwise it is "generic". */
  5878. if (!selected_cpu)
  5879. {
  5880. selected_cpu = &all_cores[TARGET_CPU_DEFAULT & 0x3f];
  5881. aarch64_isa_flags = TARGET_CPU_DEFAULT >> 6;
  5882. }
  5883. gcc_assert (selected_cpu);
  5884. if (!selected_tune)
  5885. selected_tune = selected_cpu;
  5886. aarch64_tune_flags = selected_tune->flags;
  5887. aarch64_tune = selected_tune->core;
  5888. aarch64_tune_params = selected_tune->tune;
  5889. aarch64_architecture_version = selected_cpu->architecture_version;
  5890. if (aarch64_fix_a53_err835769 == 2)
  5891. {
  5892. #ifdef TARGET_FIX_ERR_A53_835769_DEFAULT
  5893. aarch64_fix_a53_err835769 = 1;
  5894. #else
  5895. aarch64_fix_a53_err835769 = 0;
  5896. #endif
  5897. }
  5898. aarch64_override_options_after_change ();
  5899. }
  5900. /* Implement targetm.override_options_after_change. */
  5901. static void
  5902. aarch64_override_options_after_change (void)
  5903. {
  5904. if (flag_omit_frame_pointer)
  5905. flag_omit_leaf_frame_pointer = false;
  5906. else if (flag_omit_leaf_frame_pointer)
  5907. flag_omit_frame_pointer = true;
  5908. /* If not optimizing for size, set the default
  5909. alignment to what the target wants */
  5910. if (!optimize_size)
  5911. {
  5912. if (align_loops <= 0)
  5913. align_loops = aarch64_tune_params->loop_align;
  5914. if (align_jumps <= 0)
  5915. align_jumps = aarch64_tune_params->jump_align;
  5916. if (align_functions <= 0)
  5917. align_functions = aarch64_tune_params->function_align;
  5918. }
  5919. }
  5920. static struct machine_function *
  5921. aarch64_init_machine_status (void)
  5922. {
  5923. struct machine_function *machine;
  5924. machine = ggc_cleared_alloc<machine_function> ();
  5925. return machine;
  5926. }
  5927. void
  5928. aarch64_init_expanders (void)
  5929. {
  5930. init_machine_status = aarch64_init_machine_status;
  5931. }
  5932. /* A checking mechanism for the implementation of the various code models. */
  5933. static void
  5934. initialize_aarch64_code_model (void)
  5935. {
  5936. if (flag_pic)
  5937. {
  5938. switch (aarch64_cmodel_var)
  5939. {
  5940. case AARCH64_CMODEL_TINY:
  5941. aarch64_cmodel = AARCH64_CMODEL_TINY_PIC;
  5942. break;
  5943. case AARCH64_CMODEL_SMALL:
  5944. aarch64_cmodel = AARCH64_CMODEL_SMALL_PIC;
  5945. break;
  5946. case AARCH64_CMODEL_LARGE:
  5947. sorry ("code model %qs with -f%s", "large",
  5948. flag_pic > 1 ? "PIC" : "pic");
  5949. default:
  5950. gcc_unreachable ();
  5951. }
  5952. }
  5953. else
  5954. aarch64_cmodel = aarch64_cmodel_var;
  5955. }
  5956. /* Return true if SYMBOL_REF X binds locally. */
  5957. static bool
  5958. aarch64_symbol_binds_local_p (const_rtx x)
  5959. {
  5960. return (SYMBOL_REF_DECL (x)
  5961. ? targetm.binds_local_p (SYMBOL_REF_DECL (x))
  5962. : SYMBOL_REF_LOCAL_P (x));
  5963. }
  5964. /* Return true if SYMBOL_REF X is thread local */
  5965. static bool
  5966. aarch64_tls_symbol_p (rtx x)
  5967. {
  5968. if (! TARGET_HAVE_TLS)
  5969. return false;
  5970. if (GET_CODE (x) != SYMBOL_REF)
  5971. return false;
  5972. return SYMBOL_REF_TLS_MODEL (x) != 0;
  5973. }
  5974. /* Classify a TLS symbol into one of the TLS kinds. */
  5975. enum aarch64_symbol_type
  5976. aarch64_classify_tls_symbol (rtx x)
  5977. {
  5978. enum tls_model tls_kind = tls_symbolic_operand_type (x);
  5979. switch (tls_kind)
  5980. {
  5981. case TLS_MODEL_GLOBAL_DYNAMIC:
  5982. case TLS_MODEL_LOCAL_DYNAMIC:
  5983. return TARGET_TLS_DESC ? SYMBOL_SMALL_TLSDESC : SYMBOL_SMALL_TLSGD;
  5984. case TLS_MODEL_INITIAL_EXEC:
  5985. return SYMBOL_SMALL_GOTTPREL;
  5986. case TLS_MODEL_LOCAL_EXEC:
  5987. return SYMBOL_SMALL_TPREL;
  5988. case TLS_MODEL_EMULATED:
  5989. case TLS_MODEL_NONE:
  5990. return SYMBOL_FORCE_TO_MEM;
  5991. default:
  5992. gcc_unreachable ();
  5993. }
  5994. }
  5995. /* Return the method that should be used to access SYMBOL_REF or
  5996. LABEL_REF X in context CONTEXT. */
  5997. enum aarch64_symbol_type
  5998. aarch64_classify_symbol (rtx x, rtx offset,
  5999. enum aarch64_symbol_context context ATTRIBUTE_UNUSED)
  6000. {
  6001. if (GET_CODE (x) == LABEL_REF)
  6002. {
  6003. switch (aarch64_cmodel)
  6004. {
  6005. case AARCH64_CMODEL_LARGE:
  6006. return SYMBOL_FORCE_TO_MEM;
  6007. case AARCH64_CMODEL_TINY_PIC:
  6008. case AARCH64_CMODEL_TINY:
  6009. return SYMBOL_TINY_ABSOLUTE;
  6010. case AARCH64_CMODEL_SMALL_PIC:
  6011. case AARCH64_CMODEL_SMALL:
  6012. return SYMBOL_SMALL_ABSOLUTE;
  6013. default:
  6014. gcc_unreachable ();
  6015. }
  6016. }
  6017. if (GET_CODE (x) == SYMBOL_REF)
  6018. {
  6019. if (aarch64_cmodel == AARCH64_CMODEL_LARGE)
  6020. return SYMBOL_FORCE_TO_MEM;
  6021. if (aarch64_tls_symbol_p (x))
  6022. return aarch64_classify_tls_symbol (x);
  6023. switch (aarch64_cmodel)
  6024. {
  6025. case AARCH64_CMODEL_TINY:
  6026. /* When we retreive symbol + offset address, we have to make sure
  6027. the offset does not cause overflow of the final address. But
  6028. we have no way of knowing the address of symbol at compile time
  6029. so we can't accurately say if the distance between the PC and
  6030. symbol + offset is outside the addressible range of +/-1M in the
  6031. TINY code model. So we rely on images not being greater than
  6032. 1M and cap the offset at 1M and anything beyond 1M will have to
  6033. be loaded using an alternative mechanism. */
  6034. if (SYMBOL_REF_WEAK (x)
  6035. || INTVAL (offset) < -1048575 || INTVAL (offset) > 1048575)
  6036. return SYMBOL_FORCE_TO_MEM;
  6037. return SYMBOL_TINY_ABSOLUTE;
  6038. case AARCH64_CMODEL_SMALL:
  6039. /* Same reasoning as the tiny code model, but the offset cap here is
  6040. 4G. */
  6041. if (SYMBOL_REF_WEAK (x)
  6042. || !IN_RANGE (INTVAL (offset), HOST_WIDE_INT_C (-4294967263),
  6043. HOST_WIDE_INT_C (4294967264)))
  6044. return SYMBOL_FORCE_TO_MEM;
  6045. return SYMBOL_SMALL_ABSOLUTE;
  6046. case AARCH64_CMODEL_TINY_PIC:
  6047. if (!aarch64_symbol_binds_local_p (x))
  6048. return SYMBOL_TINY_GOT;
  6049. return SYMBOL_TINY_ABSOLUTE;
  6050. case AARCH64_CMODEL_SMALL_PIC:
  6051. if (!aarch64_symbol_binds_local_p (x))
  6052. return SYMBOL_SMALL_GOT;
  6053. return SYMBOL_SMALL_ABSOLUTE;
  6054. default:
  6055. gcc_unreachable ();
  6056. }
  6057. }
  6058. /* By default push everything into the constant pool. */
  6059. return SYMBOL_FORCE_TO_MEM;
  6060. }
  6061. bool
  6062. aarch64_constant_address_p (rtx x)
  6063. {
  6064. return (CONSTANT_P (x) && memory_address_p (DImode, x));
  6065. }
  6066. bool
  6067. aarch64_legitimate_pic_operand_p (rtx x)
  6068. {
  6069. if (GET_CODE (x) == SYMBOL_REF
  6070. || (GET_CODE (x) == CONST
  6071. && GET_CODE (XEXP (x, 0)) == PLUS
  6072. && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))
  6073. return false;
  6074. return true;
  6075. }
  6076. /* Return true if X holds either a quarter-precision or
  6077. floating-point +0.0 constant. */
  6078. static bool
  6079. aarch64_valid_floating_const (machine_mode mode, rtx x)
  6080. {
  6081. if (!CONST_DOUBLE_P (x))
  6082. return false;
  6083. /* TODO: We could handle moving 0.0 to a TFmode register,
  6084. but first we would like to refactor the movtf_aarch64
  6085. to be more amicable to split moves properly and
  6086. correctly gate on TARGET_SIMD. For now - reject all
  6087. constants which are not to SFmode or DFmode registers. */
  6088. if (!(mode == SFmode || mode == DFmode))
  6089. return false;
  6090. if (aarch64_float_const_zero_rtx_p (x))
  6091. return true;
  6092. return aarch64_float_const_representable_p (x);
  6093. }
  6094. static bool
  6095. aarch64_legitimate_constant_p (machine_mode mode, rtx x)
  6096. {
  6097. /* Do not allow vector struct mode constants. We could support
  6098. 0 and -1 easily, but they need support in aarch64-simd.md. */
  6099. if (TARGET_SIMD && aarch64_vect_struct_mode_p (mode))
  6100. return false;
  6101. /* This could probably go away because
  6102. we now decompose CONST_INTs according to expand_mov_immediate. */
  6103. if ((GET_CODE (x) == CONST_VECTOR
  6104. && aarch64_simd_valid_immediate (x, mode, false, NULL))
  6105. || CONST_INT_P (x) || aarch64_valid_floating_const (mode, x))
  6106. return !targetm.cannot_force_const_mem (mode, x);
  6107. if (GET_CODE (x) == HIGH
  6108. && aarch64_valid_symref (XEXP (x, 0), GET_MODE (XEXP (x, 0))))
  6109. return true;
  6110. return aarch64_constant_address_p (x);
  6111. }
  6112. rtx
  6113. aarch64_load_tp (rtx target)
  6114. {
  6115. if (!target
  6116. || GET_MODE (target) != Pmode
  6117. || !register_operand (target, Pmode))
  6118. target = gen_reg_rtx (Pmode);
  6119. /* Can return in any reg. */
  6120. emit_insn (gen_aarch64_load_tp_hard (target));
  6121. return target;
  6122. }
  6123. /* On AAPCS systems, this is the "struct __va_list". */
  6124. static GTY(()) tree va_list_type;
  6125. /* Implement TARGET_BUILD_BUILTIN_VA_LIST.
  6126. Return the type to use as __builtin_va_list.
  6127. AAPCS64 \S 7.1.4 requires that va_list be a typedef for a type defined as:
  6128. struct __va_list
  6129. {
  6130. void *__stack;
  6131. void *__gr_top;
  6132. void *__vr_top;
  6133. int __gr_offs;
  6134. int __vr_offs;
  6135. }; */
  6136. static tree
  6137. aarch64_build_builtin_va_list (void)
  6138. {
  6139. tree va_list_name;
  6140. tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff;
  6141. /* Create the type. */
  6142. va_list_type = lang_hooks.types.make_type (RECORD_TYPE);
  6143. /* Give it the required name. */
  6144. va_list_name = build_decl (BUILTINS_LOCATION,
  6145. TYPE_DECL,
  6146. get_identifier ("__va_list"),
  6147. va_list_type);
  6148. DECL_ARTIFICIAL (va_list_name) = 1;
  6149. TYPE_NAME (va_list_type) = va_list_name;
  6150. TYPE_STUB_DECL (va_list_type) = va_list_name;
  6151. /* Create the fields. */
  6152. f_stack = build_decl (BUILTINS_LOCATION,
  6153. FIELD_DECL, get_identifier ("__stack"),
  6154. ptr_type_node);
  6155. f_grtop = build_decl (BUILTINS_LOCATION,
  6156. FIELD_DECL, get_identifier ("__gr_top"),
  6157. ptr_type_node);
  6158. f_vrtop = build_decl (BUILTINS_LOCATION,
  6159. FIELD_DECL, get_identifier ("__vr_top"),
  6160. ptr_type_node);
  6161. f_groff = build_decl (BUILTINS_LOCATION,
  6162. FIELD_DECL, get_identifier ("__gr_offs"),
  6163. integer_type_node);
  6164. f_vroff = build_decl (BUILTINS_LOCATION,
  6165. FIELD_DECL, get_identifier ("__vr_offs"),
  6166. integer_type_node);
  6167. DECL_ARTIFICIAL (f_stack) = 1;
  6168. DECL_ARTIFICIAL (f_grtop) = 1;
  6169. DECL_ARTIFICIAL (f_vrtop) = 1;
  6170. DECL_ARTIFICIAL (f_groff) = 1;
  6171. DECL_ARTIFICIAL (f_vroff) = 1;
  6172. DECL_FIELD_CONTEXT (f_stack) = va_list_type;
  6173. DECL_FIELD_CONTEXT (f_grtop) = va_list_type;
  6174. DECL_FIELD_CONTEXT (f_vrtop) = va_list_type;
  6175. DECL_FIELD_CONTEXT (f_groff) = va_list_type;
  6176. DECL_FIELD_CONTEXT (f_vroff) = va_list_type;
  6177. TYPE_FIELDS (va_list_type) = f_stack;
  6178. DECL_CHAIN (f_stack) = f_grtop;
  6179. DECL_CHAIN (f_grtop) = f_vrtop;
  6180. DECL_CHAIN (f_vrtop) = f_groff;
  6181. DECL_CHAIN (f_groff) = f_vroff;
  6182. /* Compute its layout. */
  6183. layout_type (va_list_type);
  6184. return va_list_type;
  6185. }
  6186. /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
  6187. static void
  6188. aarch64_expand_builtin_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
  6189. {
  6190. const CUMULATIVE_ARGS *cum;
  6191. tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff;
  6192. tree stack, grtop, vrtop, groff, vroff;
  6193. tree t;
  6194. int gr_save_area_size;
  6195. int vr_save_area_size;
  6196. int vr_offset;
  6197. cum = &crtl->args.info;
  6198. gr_save_area_size
  6199. = (NUM_ARG_REGS - cum->aapcs_ncrn) * UNITS_PER_WORD;
  6200. vr_save_area_size
  6201. = (NUM_FP_ARG_REGS - cum->aapcs_nvrn) * UNITS_PER_VREG;
  6202. if (!TARGET_FLOAT)
  6203. {
  6204. if (cum->aapcs_nvrn > 0)
  6205. sorry ("%qs and floating point or vector arguments",
  6206. "-mgeneral-regs-only");
  6207. vr_save_area_size = 0;
  6208. }
  6209. f_stack = TYPE_FIELDS (va_list_type_node);
  6210. f_grtop = DECL_CHAIN (f_stack);
  6211. f_vrtop = DECL_CHAIN (f_grtop);
  6212. f_groff = DECL_CHAIN (f_vrtop);
  6213. f_vroff = DECL_CHAIN (f_groff);
  6214. stack = build3 (COMPONENT_REF, TREE_TYPE (f_stack), valist, f_stack,
  6215. NULL_TREE);
  6216. grtop = build3 (COMPONENT_REF, TREE_TYPE (f_grtop), valist, f_grtop,
  6217. NULL_TREE);
  6218. vrtop = build3 (COMPONENT_REF, TREE_TYPE (f_vrtop), valist, f_vrtop,
  6219. NULL_TREE);
  6220. groff = build3 (COMPONENT_REF, TREE_TYPE (f_groff), valist, f_groff,
  6221. NULL_TREE);
  6222. vroff = build3 (COMPONENT_REF, TREE_TYPE (f_vroff), valist, f_vroff,
  6223. NULL_TREE);
  6224. /* Emit code to initialize STACK, which points to the next varargs stack
  6225. argument. CUM->AAPCS_STACK_SIZE gives the number of stack words used
  6226. by named arguments. STACK is 8-byte aligned. */
  6227. t = make_tree (TREE_TYPE (stack), virtual_incoming_args_rtx);
  6228. if (cum->aapcs_stack_size > 0)
  6229. t = fold_build_pointer_plus_hwi (t, cum->aapcs_stack_size * UNITS_PER_WORD);
  6230. t = build2 (MODIFY_EXPR, TREE_TYPE (stack), stack, t);
  6231. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  6232. /* Emit code to initialize GRTOP, the top of the GR save area.
  6233. virtual_incoming_args_rtx should have been 16 byte aligned. */
  6234. t = make_tree (TREE_TYPE (grtop), virtual_incoming_args_rtx);
  6235. t = build2 (MODIFY_EXPR, TREE_TYPE (grtop), grtop, t);
  6236. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  6237. /* Emit code to initialize VRTOP, the top of the VR save area.
  6238. This address is gr_save_area_bytes below GRTOP, rounded
  6239. down to the next 16-byte boundary. */
  6240. t = make_tree (TREE_TYPE (vrtop), virtual_incoming_args_rtx);
  6241. vr_offset = AARCH64_ROUND_UP (gr_save_area_size,
  6242. STACK_BOUNDARY / BITS_PER_UNIT);
  6243. if (vr_offset)
  6244. t = fold_build_pointer_plus_hwi (t, -vr_offset);
  6245. t = build2 (MODIFY_EXPR, TREE_TYPE (vrtop), vrtop, t);
  6246. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  6247. /* Emit code to initialize GROFF, the offset from GRTOP of the
  6248. next GPR argument. */
  6249. t = build2 (MODIFY_EXPR, TREE_TYPE (groff), groff,
  6250. build_int_cst (TREE_TYPE (groff), -gr_save_area_size));
  6251. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  6252. /* Likewise emit code to initialize VROFF, the offset from FTOP
  6253. of the next VR argument. */
  6254. t = build2 (MODIFY_EXPR, TREE_TYPE (vroff), vroff,
  6255. build_int_cst (TREE_TYPE (vroff), -vr_save_area_size));
  6256. expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
  6257. }
  6258. /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
  6259. static tree
  6260. aarch64_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
  6261. gimple_seq *post_p ATTRIBUTE_UNUSED)
  6262. {
  6263. tree addr;
  6264. bool indirect_p;
  6265. bool is_ha; /* is HFA or HVA. */
  6266. bool dw_align; /* double-word align. */
  6267. machine_mode ag_mode = VOIDmode;
  6268. int nregs;
  6269. machine_mode mode;
  6270. tree f_stack, f_grtop, f_vrtop, f_groff, f_vroff;
  6271. tree stack, f_top, f_off, off, arg, roundup, on_stack;
  6272. HOST_WIDE_INT size, rsize, adjust, align;
  6273. tree t, u, cond1, cond2;
  6274. indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
  6275. if (indirect_p)
  6276. type = build_pointer_type (type);
  6277. mode = TYPE_MODE (type);
  6278. f_stack = TYPE_FIELDS (va_list_type_node);
  6279. f_grtop = DECL_CHAIN (f_stack);
  6280. f_vrtop = DECL_CHAIN (f_grtop);
  6281. f_groff = DECL_CHAIN (f_vrtop);
  6282. f_vroff = DECL_CHAIN (f_groff);
  6283. stack = build3 (COMPONENT_REF, TREE_TYPE (f_stack), unshare_expr (valist),
  6284. f_stack, NULL_TREE);
  6285. size = int_size_in_bytes (type);
  6286. align = aarch64_function_arg_alignment (mode, type) / BITS_PER_UNIT;
  6287. dw_align = false;
  6288. adjust = 0;
  6289. if (aarch64_vfp_is_call_or_return_candidate (mode,
  6290. type,
  6291. &ag_mode,
  6292. &nregs,
  6293. &is_ha))
  6294. {
  6295. /* TYPE passed in fp/simd registers. */
  6296. if (!TARGET_FLOAT)
  6297. sorry ("%qs and floating point or vector arguments",
  6298. "-mgeneral-regs-only");
  6299. f_top = build3 (COMPONENT_REF, TREE_TYPE (f_vrtop),
  6300. unshare_expr (valist), f_vrtop, NULL_TREE);
  6301. f_off = build3 (COMPONENT_REF, TREE_TYPE (f_vroff),
  6302. unshare_expr (valist), f_vroff, NULL_TREE);
  6303. rsize = nregs * UNITS_PER_VREG;
  6304. if (is_ha)
  6305. {
  6306. if (BYTES_BIG_ENDIAN && GET_MODE_SIZE (ag_mode) < UNITS_PER_VREG)
  6307. adjust = UNITS_PER_VREG - GET_MODE_SIZE (ag_mode);
  6308. }
  6309. else if (BLOCK_REG_PADDING (mode, type, 1) == downward
  6310. && size < UNITS_PER_VREG)
  6311. {
  6312. adjust = UNITS_PER_VREG - size;
  6313. }
  6314. }
  6315. else
  6316. {
  6317. /* TYPE passed in general registers. */
  6318. f_top = build3 (COMPONENT_REF, TREE_TYPE (f_grtop),
  6319. unshare_expr (valist), f_grtop, NULL_TREE);
  6320. f_off = build3 (COMPONENT_REF, TREE_TYPE (f_groff),
  6321. unshare_expr (valist), f_groff, NULL_TREE);
  6322. rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
  6323. nregs = rsize / UNITS_PER_WORD;
  6324. if (align > 8)
  6325. dw_align = true;
  6326. if (BLOCK_REG_PADDING (mode, type, 1) == downward
  6327. && size < UNITS_PER_WORD)
  6328. {
  6329. adjust = UNITS_PER_WORD - size;
  6330. }
  6331. }
  6332. /* Get a local temporary for the field value. */
  6333. off = get_initialized_tmp_var (f_off, pre_p, NULL);
  6334. /* Emit code to branch if off >= 0. */
  6335. t = build2 (GE_EXPR, boolean_type_node, off,
  6336. build_int_cst (TREE_TYPE (off), 0));
  6337. cond1 = build3 (COND_EXPR, ptr_type_node, t, NULL_TREE, NULL_TREE);
  6338. if (dw_align)
  6339. {
  6340. /* Emit: offs = (offs + 15) & -16. */
  6341. t = build2 (PLUS_EXPR, TREE_TYPE (off), off,
  6342. build_int_cst (TREE_TYPE (off), 15));
  6343. t = build2 (BIT_AND_EXPR, TREE_TYPE (off), t,
  6344. build_int_cst (TREE_TYPE (off), -16));
  6345. roundup = build2 (MODIFY_EXPR, TREE_TYPE (off), off, t);
  6346. }
  6347. else
  6348. roundup = NULL;
  6349. /* Update ap.__[g|v]r_offs */
  6350. t = build2 (PLUS_EXPR, TREE_TYPE (off), off,
  6351. build_int_cst (TREE_TYPE (off), rsize));
  6352. t = build2 (MODIFY_EXPR, TREE_TYPE (f_off), unshare_expr (f_off), t);
  6353. /* String up. */
  6354. if (roundup)
  6355. t = build2 (COMPOUND_EXPR, TREE_TYPE (t), roundup, t);
  6356. /* [cond2] if (ap.__[g|v]r_offs > 0) */
  6357. u = build2 (GT_EXPR, boolean_type_node, unshare_expr (f_off),
  6358. build_int_cst (TREE_TYPE (f_off), 0));
  6359. cond2 = build3 (COND_EXPR, ptr_type_node, u, NULL_TREE, NULL_TREE);
  6360. /* String up: make sure the assignment happens before the use. */
  6361. t = build2 (COMPOUND_EXPR, TREE_TYPE (cond2), t, cond2);
  6362. COND_EXPR_ELSE (cond1) = t;
  6363. /* Prepare the trees handling the argument that is passed on the stack;
  6364. the top level node will store in ON_STACK. */
  6365. arg = get_initialized_tmp_var (stack, pre_p, NULL);
  6366. if (align > 8)
  6367. {
  6368. /* if (alignof(type) > 8) (arg = arg + 15) & -16; */
  6369. t = fold_convert (intDI_type_node, arg);
  6370. t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
  6371. build_int_cst (TREE_TYPE (t), 15));
  6372. t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
  6373. build_int_cst (TREE_TYPE (t), -16));
  6374. t = fold_convert (TREE_TYPE (arg), t);
  6375. roundup = build2 (MODIFY_EXPR, TREE_TYPE (arg), arg, t);
  6376. }
  6377. else
  6378. roundup = NULL;
  6379. /* Advance ap.__stack */
  6380. t = fold_convert (intDI_type_node, arg);
  6381. t = build2 (PLUS_EXPR, TREE_TYPE (t), t,
  6382. build_int_cst (TREE_TYPE (t), size + 7));
  6383. t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
  6384. build_int_cst (TREE_TYPE (t), -8));
  6385. t = fold_convert (TREE_TYPE (arg), t);
  6386. t = build2 (MODIFY_EXPR, TREE_TYPE (stack), unshare_expr (stack), t);
  6387. /* String up roundup and advance. */
  6388. if (roundup)
  6389. t = build2 (COMPOUND_EXPR, TREE_TYPE (t), roundup, t);
  6390. /* String up with arg */
  6391. on_stack = build2 (COMPOUND_EXPR, TREE_TYPE (arg), t, arg);
  6392. /* Big-endianness related address adjustment. */
  6393. if (BLOCK_REG_PADDING (mode, type, 1) == downward
  6394. && size < UNITS_PER_WORD)
  6395. {
  6396. t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (arg), arg,
  6397. size_int (UNITS_PER_WORD - size));
  6398. on_stack = build2 (COMPOUND_EXPR, TREE_TYPE (arg), on_stack, t);
  6399. }
  6400. COND_EXPR_THEN (cond1) = unshare_expr (on_stack);
  6401. COND_EXPR_THEN (cond2) = unshare_expr (on_stack);
  6402. /* Adjustment to OFFSET in the case of BIG_ENDIAN. */
  6403. t = off;
  6404. if (adjust)
  6405. t = build2 (PREINCREMENT_EXPR, TREE_TYPE (off), off,
  6406. build_int_cst (TREE_TYPE (off), adjust));
  6407. t = fold_convert (sizetype, t);
  6408. t = build2 (POINTER_PLUS_EXPR, TREE_TYPE (f_top), f_top, t);
  6409. if (is_ha)
  6410. {
  6411. /* type ha; // treat as "struct {ftype field[n];}"
  6412. ... [computing offs]
  6413. for (i = 0; i <nregs; ++i, offs += 16)
  6414. ha.field[i] = *((ftype *)(ap.__vr_top + offs));
  6415. return ha; */
  6416. int i;
  6417. tree tmp_ha, field_t, field_ptr_t;
  6418. /* Declare a local variable. */
  6419. tmp_ha = create_tmp_var_raw (type, "ha");
  6420. gimple_add_tmp_var (tmp_ha);
  6421. /* Establish the base type. */
  6422. switch (ag_mode)
  6423. {
  6424. case SFmode:
  6425. field_t = float_type_node;
  6426. field_ptr_t = float_ptr_type_node;
  6427. break;
  6428. case DFmode:
  6429. field_t = double_type_node;
  6430. field_ptr_t = double_ptr_type_node;
  6431. break;
  6432. case TFmode:
  6433. field_t = long_double_type_node;
  6434. field_ptr_t = long_double_ptr_type_node;
  6435. break;
  6436. /* The half precision and quad precision are not fully supported yet. Enable
  6437. the following code after the support is complete. Need to find the correct
  6438. type node for __fp16 *. */
  6439. #if 0
  6440. case HFmode:
  6441. field_t = float_type_node;
  6442. field_ptr_t = float_ptr_type_node;
  6443. break;
  6444. #endif
  6445. case V2SImode:
  6446. case V4SImode:
  6447. {
  6448. tree innertype = make_signed_type (GET_MODE_PRECISION (SImode));
  6449. field_t = build_vector_type_for_mode (innertype, ag_mode);
  6450. field_ptr_t = build_pointer_type (field_t);
  6451. }
  6452. break;
  6453. default:
  6454. gcc_assert (0);
  6455. }
  6456. /* *(field_ptr_t)&ha = *((field_ptr_t)vr_saved_area */
  6457. tmp_ha = build1 (ADDR_EXPR, field_ptr_t, tmp_ha);
  6458. addr = t;
  6459. t = fold_convert (field_ptr_t, addr);
  6460. t = build2 (MODIFY_EXPR, field_t,
  6461. build1 (INDIRECT_REF, field_t, tmp_ha),
  6462. build1 (INDIRECT_REF, field_t, t));
  6463. /* ha.field[i] = *((field_ptr_t)vr_saved_area + i) */
  6464. for (i = 1; i < nregs; ++i)
  6465. {
  6466. addr = fold_build_pointer_plus_hwi (addr, UNITS_PER_VREG);
  6467. u = fold_convert (field_ptr_t, addr);
  6468. u = build2 (MODIFY_EXPR, field_t,
  6469. build2 (MEM_REF, field_t, tmp_ha,
  6470. build_int_cst (field_ptr_t,
  6471. (i *
  6472. int_size_in_bytes (field_t)))),
  6473. build1 (INDIRECT_REF, field_t, u));
  6474. t = build2 (COMPOUND_EXPR, TREE_TYPE (t), t, u);
  6475. }
  6476. u = fold_convert (TREE_TYPE (f_top), tmp_ha);
  6477. t = build2 (COMPOUND_EXPR, TREE_TYPE (f_top), t, u);
  6478. }
  6479. COND_EXPR_ELSE (cond2) = t;
  6480. addr = fold_convert (build_pointer_type (type), cond1);
  6481. addr = build_va_arg_indirect_ref (addr);
  6482. if (indirect_p)
  6483. addr = build_va_arg_indirect_ref (addr);
  6484. return addr;
  6485. }
  6486. /* Implement TARGET_SETUP_INCOMING_VARARGS. */
  6487. static void
  6488. aarch64_setup_incoming_varargs (cumulative_args_t cum_v, machine_mode mode,
  6489. tree type, int *pretend_size ATTRIBUTE_UNUSED,
  6490. int no_rtl)
  6491. {
  6492. CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
  6493. CUMULATIVE_ARGS local_cum;
  6494. int gr_saved, vr_saved;
  6495. /* The caller has advanced CUM up to, but not beyond, the last named
  6496. argument. Advance a local copy of CUM past the last "real" named
  6497. argument, to find out how many registers are left over. */
  6498. local_cum = *cum;
  6499. aarch64_function_arg_advance (pack_cumulative_args(&local_cum), mode, type, true);
  6500. /* Found out how many registers we need to save. */
  6501. gr_saved = NUM_ARG_REGS - local_cum.aapcs_ncrn;
  6502. vr_saved = NUM_FP_ARG_REGS - local_cum.aapcs_nvrn;
  6503. if (!TARGET_FLOAT)
  6504. {
  6505. if (local_cum.aapcs_nvrn > 0)
  6506. sorry ("%qs and floating point or vector arguments",
  6507. "-mgeneral-regs-only");
  6508. vr_saved = 0;
  6509. }
  6510. if (!no_rtl)
  6511. {
  6512. if (gr_saved > 0)
  6513. {
  6514. rtx ptr, mem;
  6515. /* virtual_incoming_args_rtx should have been 16-byte aligned. */
  6516. ptr = plus_constant (Pmode, virtual_incoming_args_rtx,
  6517. - gr_saved * UNITS_PER_WORD);
  6518. mem = gen_frame_mem (BLKmode, ptr);
  6519. set_mem_alias_set (mem, get_varargs_alias_set ());
  6520. move_block_from_reg (local_cum.aapcs_ncrn + R0_REGNUM,
  6521. mem, gr_saved);
  6522. }
  6523. if (vr_saved > 0)
  6524. {
  6525. /* We can't use move_block_from_reg, because it will use
  6526. the wrong mode, storing D regs only. */
  6527. machine_mode mode = TImode;
  6528. int off, i;
  6529. /* Set OFF to the offset from virtual_incoming_args_rtx of
  6530. the first vector register. The VR save area lies below
  6531. the GR one, and is aligned to 16 bytes. */
  6532. off = -AARCH64_ROUND_UP (gr_saved * UNITS_PER_WORD,
  6533. STACK_BOUNDARY / BITS_PER_UNIT);
  6534. off -= vr_saved * UNITS_PER_VREG;
  6535. for (i = local_cum.aapcs_nvrn; i < NUM_FP_ARG_REGS; ++i)
  6536. {
  6537. rtx ptr, mem;
  6538. ptr = plus_constant (Pmode, virtual_incoming_args_rtx, off);
  6539. mem = gen_frame_mem (mode, ptr);
  6540. set_mem_alias_set (mem, get_varargs_alias_set ());
  6541. aarch64_emit_move (mem, gen_rtx_REG (mode, V0_REGNUM + i));
  6542. off += UNITS_PER_VREG;
  6543. }
  6544. }
  6545. }
  6546. /* We don't save the size into *PRETEND_SIZE because we want to avoid
  6547. any complication of having crtl->args.pretend_args_size changed. */
  6548. cfun->machine->frame.saved_varargs_size
  6549. = (AARCH64_ROUND_UP (gr_saved * UNITS_PER_WORD,
  6550. STACK_BOUNDARY / BITS_PER_UNIT)
  6551. + vr_saved * UNITS_PER_VREG);
  6552. }
  6553. static void
  6554. aarch64_conditional_register_usage (void)
  6555. {
  6556. int i;
  6557. if (!TARGET_FLOAT)
  6558. {
  6559. for (i = V0_REGNUM; i <= V31_REGNUM; i++)
  6560. {
  6561. fixed_regs[i] = 1;
  6562. call_used_regs[i] = 1;
  6563. }
  6564. }
  6565. }
  6566. /* Walk down the type tree of TYPE counting consecutive base elements.
  6567. If *MODEP is VOIDmode, then set it to the first valid floating point
  6568. type. If a non-floating point type is found, or if a floating point
  6569. type that doesn't match a non-VOIDmode *MODEP is found, then return -1,
  6570. otherwise return the count in the sub-tree. */
  6571. static int
  6572. aapcs_vfp_sub_candidate (const_tree type, machine_mode *modep)
  6573. {
  6574. machine_mode mode;
  6575. HOST_WIDE_INT size;
  6576. switch (TREE_CODE (type))
  6577. {
  6578. case REAL_TYPE:
  6579. mode = TYPE_MODE (type);
  6580. if (mode != DFmode && mode != SFmode && mode != TFmode)
  6581. return -1;
  6582. if (*modep == VOIDmode)
  6583. *modep = mode;
  6584. if (*modep == mode)
  6585. return 1;
  6586. break;
  6587. case COMPLEX_TYPE:
  6588. mode = TYPE_MODE (TREE_TYPE (type));
  6589. if (mode != DFmode && mode != SFmode && mode != TFmode)
  6590. return -1;
  6591. if (*modep == VOIDmode)
  6592. *modep = mode;
  6593. if (*modep == mode)
  6594. return 2;
  6595. break;
  6596. case VECTOR_TYPE:
  6597. /* Use V2SImode and V4SImode as representatives of all 64-bit
  6598. and 128-bit vector types. */
  6599. size = int_size_in_bytes (type);
  6600. switch (size)
  6601. {
  6602. case 8:
  6603. mode = V2SImode;
  6604. break;
  6605. case 16:
  6606. mode = V4SImode;
  6607. break;
  6608. default:
  6609. return -1;
  6610. }
  6611. if (*modep == VOIDmode)
  6612. *modep = mode;
  6613. /* Vector modes are considered to be opaque: two vectors are
  6614. equivalent for the purposes of being homogeneous aggregates
  6615. if they are the same size. */
  6616. if (*modep == mode)
  6617. return 1;
  6618. break;
  6619. case ARRAY_TYPE:
  6620. {
  6621. int count;
  6622. tree index = TYPE_DOMAIN (type);
  6623. /* Can't handle incomplete types nor sizes that are not
  6624. fixed. */
  6625. if (!COMPLETE_TYPE_P (type)
  6626. || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  6627. return -1;
  6628. count = aapcs_vfp_sub_candidate (TREE_TYPE (type), modep);
  6629. if (count == -1
  6630. || !index
  6631. || !TYPE_MAX_VALUE (index)
  6632. || !tree_fits_uhwi_p (TYPE_MAX_VALUE (index))
  6633. || !TYPE_MIN_VALUE (index)
  6634. || !tree_fits_uhwi_p (TYPE_MIN_VALUE (index))
  6635. || count < 0)
  6636. return -1;
  6637. count *= (1 + tree_to_uhwi (TYPE_MAX_VALUE (index))
  6638. - tree_to_uhwi (TYPE_MIN_VALUE (index)));
  6639. /* There must be no padding. */
  6640. if (wi::ne_p (TYPE_SIZE (type), count * GET_MODE_BITSIZE (*modep)))
  6641. return -1;
  6642. return count;
  6643. }
  6644. case RECORD_TYPE:
  6645. {
  6646. int count = 0;
  6647. int sub_count;
  6648. tree field;
  6649. /* Can't handle incomplete types nor sizes that are not
  6650. fixed. */
  6651. if (!COMPLETE_TYPE_P (type)
  6652. || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  6653. return -1;
  6654. for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  6655. {
  6656. if (TREE_CODE (field) != FIELD_DECL)
  6657. continue;
  6658. sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep);
  6659. if (sub_count < 0)
  6660. return -1;
  6661. count += sub_count;
  6662. }
  6663. /* There must be no padding. */
  6664. if (wi::ne_p (TYPE_SIZE (type), count * GET_MODE_BITSIZE (*modep)))
  6665. return -1;
  6666. return count;
  6667. }
  6668. case UNION_TYPE:
  6669. case QUAL_UNION_TYPE:
  6670. {
  6671. /* These aren't very interesting except in a degenerate case. */
  6672. int count = 0;
  6673. int sub_count;
  6674. tree field;
  6675. /* Can't handle incomplete types nor sizes that are not
  6676. fixed. */
  6677. if (!COMPLETE_TYPE_P (type)
  6678. || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  6679. return -1;
  6680. for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  6681. {
  6682. if (TREE_CODE (field) != FIELD_DECL)
  6683. continue;
  6684. sub_count = aapcs_vfp_sub_candidate (TREE_TYPE (field), modep);
  6685. if (sub_count < 0)
  6686. return -1;
  6687. count = count > sub_count ? count : sub_count;
  6688. }
  6689. /* There must be no padding. */
  6690. if (wi::ne_p (TYPE_SIZE (type), count * GET_MODE_BITSIZE (*modep)))
  6691. return -1;
  6692. return count;
  6693. }
  6694. default:
  6695. break;
  6696. }
  6697. return -1;
  6698. }
  6699. /* Return TRUE if the type, as described by TYPE and MODE, is a composite
  6700. type as described in AAPCS64 \S 4.3. This includes aggregate, union and
  6701. array types. The C99 floating-point complex types are also considered
  6702. as composite types, according to AAPCS64 \S 7.1.1. The complex integer
  6703. types, which are GCC extensions and out of the scope of AAPCS64, are
  6704. treated as composite types here as well.
  6705. Note that MODE itself is not sufficient in determining whether a type
  6706. is such a composite type or not. This is because
  6707. stor-layout.c:compute_record_mode may have already changed the MODE
  6708. (BLKmode) of a RECORD_TYPE TYPE to some other mode. For example, a
  6709. structure with only one field may have its MODE set to the mode of the
  6710. field. Also an integer mode whose size matches the size of the
  6711. RECORD_TYPE type may be used to substitute the original mode
  6712. (i.e. BLKmode) in certain circumstances. In other words, MODE cannot be
  6713. solely relied on. */
  6714. static bool
  6715. aarch64_composite_type_p (const_tree type,
  6716. machine_mode mode)
  6717. {
  6718. if (type && (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE))
  6719. return true;
  6720. if (mode == BLKmode
  6721. || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
  6722. || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
  6723. return true;
  6724. return false;
  6725. }
  6726. /* Return TRUE if the type, as described by TYPE and MODE, is a short vector
  6727. type as described in AAPCS64 \S 4.1.2.
  6728. See the comment above aarch64_composite_type_p for the notes on MODE. */
  6729. static bool
  6730. aarch64_short_vector_p (const_tree type,
  6731. machine_mode mode)
  6732. {
  6733. HOST_WIDE_INT size = -1;
  6734. if (type && TREE_CODE (type) == VECTOR_TYPE)
  6735. size = int_size_in_bytes (type);
  6736. else if (!aarch64_composite_type_p (type, mode)
  6737. && (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
  6738. || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT))
  6739. size = GET_MODE_SIZE (mode);
  6740. return (size == 8 || size == 16) ? true : false;
  6741. }
  6742. /* Return TRUE if an argument, whose type is described by TYPE and MODE,
  6743. shall be passed or returned in simd/fp register(s) (providing these
  6744. parameter passing registers are available).
  6745. Upon successful return, *COUNT returns the number of needed registers,
  6746. *BASE_MODE returns the mode of the individual register and when IS_HAF
  6747. is not NULL, *IS_HA indicates whether or not the argument is a homogeneous
  6748. floating-point aggregate or a homogeneous short-vector aggregate. */
  6749. static bool
  6750. aarch64_vfp_is_call_or_return_candidate (machine_mode mode,
  6751. const_tree type,
  6752. machine_mode *base_mode,
  6753. int *count,
  6754. bool *is_ha)
  6755. {
  6756. machine_mode new_mode = VOIDmode;
  6757. bool composite_p = aarch64_composite_type_p (type, mode);
  6758. if (is_ha != NULL) *is_ha = false;
  6759. if ((!composite_p && GET_MODE_CLASS (mode) == MODE_FLOAT)
  6760. || aarch64_short_vector_p (type, mode))
  6761. {
  6762. *count = 1;
  6763. new_mode = mode;
  6764. }
  6765. else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
  6766. {
  6767. if (is_ha != NULL) *is_ha = true;
  6768. *count = 2;
  6769. new_mode = GET_MODE_INNER (mode);
  6770. }
  6771. else if (type && composite_p)
  6772. {
  6773. int ag_count = aapcs_vfp_sub_candidate (type, &new_mode);
  6774. if (ag_count > 0 && ag_count <= HA_MAX_NUM_FLDS)
  6775. {
  6776. if (is_ha != NULL) *is_ha = true;
  6777. *count = ag_count;
  6778. }
  6779. else
  6780. return false;
  6781. }
  6782. else
  6783. return false;
  6784. *base_mode = new_mode;
  6785. return true;
  6786. }
  6787. /* Implement TARGET_STRUCT_VALUE_RTX. */
  6788. static rtx
  6789. aarch64_struct_value_rtx (tree fndecl ATTRIBUTE_UNUSED,
  6790. int incoming ATTRIBUTE_UNUSED)
  6791. {
  6792. return gen_rtx_REG (Pmode, AARCH64_STRUCT_VALUE_REGNUM);
  6793. }
  6794. /* Implements target hook vector_mode_supported_p. */
  6795. static bool
  6796. aarch64_vector_mode_supported_p (machine_mode mode)
  6797. {
  6798. if (TARGET_SIMD
  6799. && (mode == V4SImode || mode == V8HImode
  6800. || mode == V16QImode || mode == V2DImode
  6801. || mode == V2SImode || mode == V4HImode
  6802. || mode == V8QImode || mode == V2SFmode
  6803. || mode == V4SFmode || mode == V2DFmode
  6804. || mode == V1DFmode))
  6805. return true;
  6806. return false;
  6807. }
  6808. /* Return appropriate SIMD container
  6809. for MODE within a vector of WIDTH bits. */
  6810. static machine_mode
  6811. aarch64_simd_container_mode (machine_mode mode, unsigned width)
  6812. {
  6813. gcc_assert (width == 64 || width == 128);
  6814. if (TARGET_SIMD)
  6815. {
  6816. if (width == 128)
  6817. switch (mode)
  6818. {
  6819. case DFmode:
  6820. return V2DFmode;
  6821. case SFmode:
  6822. return V4SFmode;
  6823. case SImode:
  6824. return V4SImode;
  6825. case HImode:
  6826. return V8HImode;
  6827. case QImode:
  6828. return V16QImode;
  6829. case DImode:
  6830. return V2DImode;
  6831. default:
  6832. break;
  6833. }
  6834. else
  6835. switch (mode)
  6836. {
  6837. case SFmode:
  6838. return V2SFmode;
  6839. case SImode:
  6840. return V2SImode;
  6841. case HImode:
  6842. return V4HImode;
  6843. case QImode:
  6844. return V8QImode;
  6845. default:
  6846. break;
  6847. }
  6848. }
  6849. return word_mode;
  6850. }
  6851. /* Return 128-bit container as the preferred SIMD mode for MODE. */
  6852. static machine_mode
  6853. aarch64_preferred_simd_mode (machine_mode mode)
  6854. {
  6855. return aarch64_simd_container_mode (mode, 128);
  6856. }
  6857. /* Return the bitmask of possible vector sizes for the vectorizer
  6858. to iterate over. */
  6859. static unsigned int
  6860. aarch64_autovectorize_vector_sizes (void)
  6861. {
  6862. return (16 | 8);
  6863. }
  6864. /* Implement TARGET_MANGLE_TYPE. */
  6865. static const char *
  6866. aarch64_mangle_type (const_tree type)
  6867. {
  6868. /* The AArch64 ABI documents say that "__va_list" has to be
  6869. managled as if it is in the "std" namespace. */
  6870. if (lang_hooks.types_compatible_p (CONST_CAST_TREE (type), va_list_type))
  6871. return "St9__va_list";
  6872. /* Mangle AArch64-specific internal types. TYPE_NAME is non-NULL_TREE for
  6873. builtin types. */
  6874. if (TYPE_NAME (type) != NULL)
  6875. return aarch64_mangle_builtin_type (type);
  6876. /* Use the default mangling. */
  6877. return NULL;
  6878. }
  6879. /* Return true if the rtx_insn contains a MEM RTX somewhere
  6880. in it. */
  6881. static bool
  6882. has_memory_op (rtx_insn *mem_insn)
  6883. {
  6884. subrtx_iterator::array_type array;
  6885. FOR_EACH_SUBRTX (iter, array, PATTERN (mem_insn), ALL)
  6886. if (MEM_P (*iter))
  6887. return true;
  6888. return false;
  6889. }
  6890. /* Find the first rtx_insn before insn that will generate an assembly
  6891. instruction. */
  6892. static rtx_insn *
  6893. aarch64_prev_real_insn (rtx_insn *insn)
  6894. {
  6895. if (!insn)
  6896. return NULL;
  6897. do
  6898. {
  6899. insn = prev_real_insn (insn);
  6900. }
  6901. while (insn && recog_memoized (insn) < 0);
  6902. return insn;
  6903. }
  6904. static bool
  6905. is_madd_op (enum attr_type t1)
  6906. {
  6907. unsigned int i;
  6908. /* A number of these may be AArch32 only. */
  6909. enum attr_type mlatypes[] = {
  6910. TYPE_MLA, TYPE_MLAS, TYPE_SMLAD, TYPE_SMLADX, TYPE_SMLAL, TYPE_SMLALD,
  6911. TYPE_SMLALS, TYPE_SMLALXY, TYPE_SMLAWX, TYPE_SMLAWY, TYPE_SMLAXY,
  6912. TYPE_SMMLA, TYPE_UMLAL, TYPE_UMLALS,TYPE_SMLSD, TYPE_SMLSDX, TYPE_SMLSLD
  6913. };
  6914. for (i = 0; i < sizeof (mlatypes) / sizeof (enum attr_type); i++)
  6915. {
  6916. if (t1 == mlatypes[i])
  6917. return true;
  6918. }
  6919. return false;
  6920. }
  6921. /* Check if there is a register dependency between a load and the insn
  6922. for which we hold recog_data. */
  6923. static bool
  6924. dep_between_memop_and_curr (rtx memop)
  6925. {
  6926. rtx load_reg;
  6927. int opno;
  6928. gcc_assert (GET_CODE (memop) == SET);
  6929. if (!REG_P (SET_DEST (memop)))
  6930. return false;
  6931. load_reg = SET_DEST (memop);
  6932. for (opno = 1; opno < recog_data.n_operands; opno++)
  6933. {
  6934. rtx operand = recog_data.operand[opno];
  6935. if (REG_P (operand)
  6936. && reg_overlap_mentioned_p (load_reg, operand))
  6937. return true;
  6938. }
  6939. return false;
  6940. }
  6941. /* When working around the Cortex-A53 erratum 835769,
  6942. given rtx_insn INSN, return true if it is a 64-bit multiply-accumulate
  6943. instruction and has a preceding memory instruction such that a NOP
  6944. should be inserted between them. */
  6945. bool
  6946. aarch64_madd_needs_nop (rtx_insn* insn)
  6947. {
  6948. enum attr_type attr_type;
  6949. rtx_insn *prev;
  6950. rtx body;
  6951. if (!aarch64_fix_a53_err835769)
  6952. return false;
  6953. if (recog_memoized (insn) < 0)
  6954. return false;
  6955. attr_type = get_attr_type (insn);
  6956. if (!is_madd_op (attr_type))
  6957. return false;
  6958. prev = aarch64_prev_real_insn (insn);
  6959. /* aarch64_prev_real_insn can call recog_memoized on insns other than INSN.
  6960. Restore recog state to INSN to avoid state corruption. */
  6961. extract_constrain_insn_cached (insn);
  6962. if (!prev || !has_memory_op (prev))
  6963. return false;
  6964. body = single_set (prev);
  6965. /* If the previous insn is a memory op and there is no dependency between
  6966. it and the DImode madd, emit a NOP between them. If body is NULL then we
  6967. have a complex memory operation, probably a load/store pair.
  6968. Be conservative for now and emit a NOP. */
  6969. if (GET_MODE (recog_data.operand[0]) == DImode
  6970. && (!body || !dep_between_memop_and_curr (body)))
  6971. return true;
  6972. return false;
  6973. }
  6974. /* Implement FINAL_PRESCAN_INSN. */
  6975. void
  6976. aarch64_final_prescan_insn (rtx_insn *insn)
  6977. {
  6978. if (aarch64_madd_needs_nop (insn))
  6979. fprintf (asm_out_file, "\tnop // between mem op and mult-accumulate\n");
  6980. }
  6981. /* Return the equivalent letter for size. */
  6982. static char
  6983. sizetochar (int size)
  6984. {
  6985. switch (size)
  6986. {
  6987. case 64: return 'd';
  6988. case 32: return 's';
  6989. case 16: return 'h';
  6990. case 8 : return 'b';
  6991. default: gcc_unreachable ();
  6992. }
  6993. }
  6994. /* Return true iff x is a uniform vector of floating-point
  6995. constants, and the constant can be represented in
  6996. quarter-precision form. Note, as aarch64_float_const_representable
  6997. rejects both +0.0 and -0.0, we will also reject +0.0 and -0.0. */
  6998. static bool
  6999. aarch64_vect_float_const_representable_p (rtx x)
  7000. {
  7001. int i = 0;
  7002. REAL_VALUE_TYPE r0, ri;
  7003. rtx x0, xi;
  7004. if (GET_MODE_CLASS (GET_MODE (x)) != MODE_VECTOR_FLOAT)
  7005. return false;
  7006. x0 = CONST_VECTOR_ELT (x, 0);
  7007. if (!CONST_DOUBLE_P (x0))
  7008. return false;
  7009. REAL_VALUE_FROM_CONST_DOUBLE (r0, x0);
  7010. for (i = 1; i < CONST_VECTOR_NUNITS (x); i++)
  7011. {
  7012. xi = CONST_VECTOR_ELT (x, i);
  7013. if (!CONST_DOUBLE_P (xi))
  7014. return false;
  7015. REAL_VALUE_FROM_CONST_DOUBLE (ri, xi);
  7016. if (!REAL_VALUES_EQUAL (r0, ri))
  7017. return false;
  7018. }
  7019. return aarch64_float_const_representable_p (x0);
  7020. }
  7021. /* Return true for valid and false for invalid. */
  7022. bool
  7023. aarch64_simd_valid_immediate (rtx op, machine_mode mode, bool inverse,
  7024. struct simd_immediate_info *info)
  7025. {
  7026. #define CHECK(STRIDE, ELSIZE, CLASS, TEST, SHIFT, NEG) \
  7027. matches = 1; \
  7028. for (i = 0; i < idx; i += (STRIDE)) \
  7029. if (!(TEST)) \
  7030. matches = 0; \
  7031. if (matches) \
  7032. { \
  7033. immtype = (CLASS); \
  7034. elsize = (ELSIZE); \
  7035. eshift = (SHIFT); \
  7036. emvn = (NEG); \
  7037. break; \
  7038. }
  7039. unsigned int i, elsize = 0, idx = 0, n_elts = CONST_VECTOR_NUNITS (op);
  7040. unsigned int innersize = GET_MODE_SIZE (GET_MODE_INNER (mode));
  7041. unsigned char bytes[16];
  7042. int immtype = -1, matches;
  7043. unsigned int invmask = inverse ? 0xff : 0;
  7044. int eshift, emvn;
  7045. if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
  7046. {
  7047. if (! (aarch64_simd_imm_zero_p (op, mode)
  7048. || aarch64_vect_float_const_representable_p (op)))
  7049. return false;
  7050. if (info)
  7051. {
  7052. info->value = CONST_VECTOR_ELT (op, 0);
  7053. info->element_width = GET_MODE_BITSIZE (GET_MODE (info->value));
  7054. info->mvn = false;
  7055. info->shift = 0;
  7056. }
  7057. return true;
  7058. }
  7059. /* Splat vector constant out into a byte vector. */
  7060. for (i = 0; i < n_elts; i++)
  7061. {
  7062. /* The vector is provided in gcc endian-neutral fashion. For aarch64_be,
  7063. it must be laid out in the vector register in reverse order. */
  7064. rtx el = CONST_VECTOR_ELT (op, BYTES_BIG_ENDIAN ? (n_elts - 1 - i) : i);
  7065. unsigned HOST_WIDE_INT elpart;
  7066. unsigned int part, parts;
  7067. if (CONST_INT_P (el))
  7068. {
  7069. elpart = INTVAL (el);
  7070. parts = 1;
  7071. }
  7072. else if (GET_CODE (el) == CONST_DOUBLE)
  7073. {
  7074. elpart = CONST_DOUBLE_LOW (el);
  7075. parts = 2;
  7076. }
  7077. else
  7078. gcc_unreachable ();
  7079. for (part = 0; part < parts; part++)
  7080. {
  7081. unsigned int byte;
  7082. for (byte = 0; byte < innersize; byte++)
  7083. {
  7084. bytes[idx++] = (elpart & 0xff) ^ invmask;
  7085. elpart >>= BITS_PER_UNIT;
  7086. }
  7087. if (GET_CODE (el) == CONST_DOUBLE)
  7088. elpart = CONST_DOUBLE_HIGH (el);
  7089. }
  7090. }
  7091. /* Sanity check. */
  7092. gcc_assert (idx == GET_MODE_SIZE (mode));
  7093. do
  7094. {
  7095. CHECK (4, 32, 0, bytes[i] == bytes[0] && bytes[i + 1] == 0
  7096. && bytes[i + 2] == 0 && bytes[i + 3] == 0, 0, 0);
  7097. CHECK (4, 32, 1, bytes[i] == 0 && bytes[i + 1] == bytes[1]
  7098. && bytes[i + 2] == 0 && bytes[i + 3] == 0, 8, 0);
  7099. CHECK (4, 32, 2, bytes[i] == 0 && bytes[i + 1] == 0
  7100. && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0, 16, 0);
  7101. CHECK (4, 32, 3, bytes[i] == 0 && bytes[i + 1] == 0
  7102. && bytes[i + 2] == 0 && bytes[i + 3] == bytes[3], 24, 0);
  7103. CHECK (2, 16, 4, bytes[i] == bytes[0] && bytes[i + 1] == 0, 0, 0);
  7104. CHECK (2, 16, 5, bytes[i] == 0 && bytes[i + 1] == bytes[1], 8, 0);
  7105. CHECK (4, 32, 6, bytes[i] == bytes[0] && bytes[i + 1] == 0xff
  7106. && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff, 0, 1);
  7107. CHECK (4, 32, 7, bytes[i] == 0xff && bytes[i + 1] == bytes[1]
  7108. && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff, 8, 1);
  7109. CHECK (4, 32, 8, bytes[i] == 0xff && bytes[i + 1] == 0xff
  7110. && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff, 16, 1);
  7111. CHECK (4, 32, 9, bytes[i] == 0xff && bytes[i + 1] == 0xff
  7112. && bytes[i + 2] == 0xff && bytes[i + 3] == bytes[3], 24, 1);
  7113. CHECK (2, 16, 10, bytes[i] == bytes[0] && bytes[i + 1] == 0xff, 0, 1);
  7114. CHECK (2, 16, 11, bytes[i] == 0xff && bytes[i + 1] == bytes[1], 8, 1);
  7115. CHECK (4, 32, 12, bytes[i] == 0xff && bytes[i + 1] == bytes[1]
  7116. && bytes[i + 2] == 0 && bytes[i + 3] == 0, 8, 0);
  7117. CHECK (4, 32, 13, bytes[i] == 0 && bytes[i + 1] == bytes[1]
  7118. && bytes[i + 2] == 0xff && bytes[i + 3] == 0xff, 8, 1);
  7119. CHECK (4, 32, 14, bytes[i] == 0xff && bytes[i + 1] == 0xff
  7120. && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0, 16, 0);
  7121. CHECK (4, 32, 15, bytes[i] == 0 && bytes[i + 1] == 0
  7122. && bytes[i + 2] == bytes[2] && bytes[i + 3] == 0xff, 16, 1);
  7123. CHECK (1, 8, 16, bytes[i] == bytes[0], 0, 0);
  7124. CHECK (1, 64, 17, (bytes[i] == 0 || bytes[i] == 0xff)
  7125. && bytes[i] == bytes[(i + 8) % idx], 0, 0);
  7126. }
  7127. while (0);
  7128. if (immtype == -1)
  7129. return false;
  7130. if (info)
  7131. {
  7132. info->element_width = elsize;
  7133. info->mvn = emvn != 0;
  7134. info->shift = eshift;
  7135. unsigned HOST_WIDE_INT imm = 0;
  7136. if (immtype >= 12 && immtype <= 15)
  7137. info->msl = true;
  7138. /* Un-invert bytes of recognized vector, if necessary. */
  7139. if (invmask != 0)
  7140. for (i = 0; i < idx; i++)
  7141. bytes[i] ^= invmask;
  7142. if (immtype == 17)
  7143. {
  7144. /* FIXME: Broken on 32-bit H_W_I hosts. */
  7145. gcc_assert (sizeof (HOST_WIDE_INT) == 8);
  7146. for (i = 0; i < 8; i++)
  7147. imm |= (unsigned HOST_WIDE_INT) (bytes[i] ? 0xff : 0)
  7148. << (i * BITS_PER_UNIT);
  7149. info->value = GEN_INT (imm);
  7150. }
  7151. else
  7152. {
  7153. for (i = 0; i < elsize / BITS_PER_UNIT; i++)
  7154. imm |= (unsigned HOST_WIDE_INT) bytes[i] << (i * BITS_PER_UNIT);
  7155. /* Construct 'abcdefgh' because the assembler cannot handle
  7156. generic constants. */
  7157. if (info->mvn)
  7158. imm = ~imm;
  7159. imm = (imm >> info->shift) & 0xff;
  7160. info->value = GEN_INT (imm);
  7161. }
  7162. }
  7163. return true;
  7164. #undef CHECK
  7165. }
  7166. /* Check of immediate shift constants are within range. */
  7167. bool
  7168. aarch64_simd_shift_imm_p (rtx x, machine_mode mode, bool left)
  7169. {
  7170. int bit_width = GET_MODE_UNIT_SIZE (mode) * BITS_PER_UNIT;
  7171. if (left)
  7172. return aarch64_const_vec_all_same_in_range_p (x, 0, bit_width - 1);
  7173. else
  7174. return aarch64_const_vec_all_same_in_range_p (x, 1, bit_width);
  7175. }
  7176. /* Return true if X is a uniform vector where all elements
  7177. are either the floating-point constant 0.0 or the
  7178. integer constant 0. */
  7179. bool
  7180. aarch64_simd_imm_zero_p (rtx x, machine_mode mode)
  7181. {
  7182. return x == CONST0_RTX (mode);
  7183. }
  7184. bool
  7185. aarch64_simd_imm_scalar_p (rtx x, machine_mode mode ATTRIBUTE_UNUSED)
  7186. {
  7187. HOST_WIDE_INT imm = INTVAL (x);
  7188. int i;
  7189. for (i = 0; i < 8; i++)
  7190. {
  7191. unsigned int byte = imm & 0xff;
  7192. if (byte != 0xff && byte != 0)
  7193. return false;
  7194. imm >>= 8;
  7195. }
  7196. return true;
  7197. }
  7198. bool
  7199. aarch64_mov_operand_p (rtx x,
  7200. enum aarch64_symbol_context context,
  7201. machine_mode mode)
  7202. {
  7203. if (GET_CODE (x) == HIGH
  7204. && aarch64_valid_symref (XEXP (x, 0), GET_MODE (XEXP (x, 0))))
  7205. return true;
  7206. if (CONST_INT_P (x))
  7207. return true;
  7208. if (GET_CODE (x) == SYMBOL_REF && mode == DImode && CONSTANT_ADDRESS_P (x))
  7209. return true;
  7210. return aarch64_classify_symbolic_expression (x, context)
  7211. == SYMBOL_TINY_ABSOLUTE;
  7212. }
  7213. /* Return a const_int vector of VAL. */
  7214. rtx
  7215. aarch64_simd_gen_const_vector_dup (machine_mode mode, int val)
  7216. {
  7217. int nunits = GET_MODE_NUNITS (mode);
  7218. rtvec v = rtvec_alloc (nunits);
  7219. int i;
  7220. for (i=0; i < nunits; i++)
  7221. RTVEC_ELT (v, i) = GEN_INT (val);
  7222. return gen_rtx_CONST_VECTOR (mode, v);
  7223. }
  7224. /* Check OP is a legal scalar immediate for the MOVI instruction. */
  7225. bool
  7226. aarch64_simd_scalar_immediate_valid_for_move (rtx op, machine_mode mode)
  7227. {
  7228. machine_mode vmode;
  7229. gcc_assert (!VECTOR_MODE_P (mode));
  7230. vmode = aarch64_preferred_simd_mode (mode);
  7231. rtx op_v = aarch64_simd_gen_const_vector_dup (vmode, INTVAL (op));
  7232. return aarch64_simd_valid_immediate (op_v, vmode, false, NULL);
  7233. }
  7234. /* Construct and return a PARALLEL RTX vector with elements numbering the
  7235. lanes of either the high (HIGH == TRUE) or low (HIGH == FALSE) half of
  7236. the vector - from the perspective of the architecture. This does not
  7237. line up with GCC's perspective on lane numbers, so we end up with
  7238. different masks depending on our target endian-ness. The diagram
  7239. below may help. We must draw the distinction when building masks
  7240. which select one half of the vector. An instruction selecting
  7241. architectural low-lanes for a big-endian target, must be described using
  7242. a mask selecting GCC high-lanes.
  7243. Big-Endian Little-Endian
  7244. GCC 0 1 2 3 3 2 1 0
  7245. | x | x | x | x | | x | x | x | x |
  7246. Architecture 3 2 1 0 3 2 1 0
  7247. Low Mask: { 2, 3 } { 0, 1 }
  7248. High Mask: { 0, 1 } { 2, 3 }
  7249. */
  7250. rtx
  7251. aarch64_simd_vect_par_cnst_half (machine_mode mode, bool high)
  7252. {
  7253. int nunits = GET_MODE_NUNITS (mode);
  7254. rtvec v = rtvec_alloc (nunits / 2);
  7255. int high_base = nunits / 2;
  7256. int low_base = 0;
  7257. int base;
  7258. rtx t1;
  7259. int i;
  7260. if (BYTES_BIG_ENDIAN)
  7261. base = high ? low_base : high_base;
  7262. else
  7263. base = high ? high_base : low_base;
  7264. for (i = 0; i < nunits / 2; i++)
  7265. RTVEC_ELT (v, i) = GEN_INT (base + i);
  7266. t1 = gen_rtx_PARALLEL (mode, v);
  7267. return t1;
  7268. }
  7269. /* Check OP for validity as a PARALLEL RTX vector with elements
  7270. numbering the lanes of either the high (HIGH == TRUE) or low lanes,
  7271. from the perspective of the architecture. See the diagram above
  7272. aarch64_simd_vect_par_cnst_half for more details. */
  7273. bool
  7274. aarch64_simd_check_vect_par_cnst_half (rtx op, machine_mode mode,
  7275. bool high)
  7276. {
  7277. rtx ideal = aarch64_simd_vect_par_cnst_half (mode, high);
  7278. HOST_WIDE_INT count_op = XVECLEN (op, 0);
  7279. HOST_WIDE_INT count_ideal = XVECLEN (ideal, 0);
  7280. int i = 0;
  7281. if (!VECTOR_MODE_P (mode))
  7282. return false;
  7283. if (count_op != count_ideal)
  7284. return false;
  7285. for (i = 0; i < count_ideal; i++)
  7286. {
  7287. rtx elt_op = XVECEXP (op, 0, i);
  7288. rtx elt_ideal = XVECEXP (ideal, 0, i);
  7289. if (!CONST_INT_P (elt_op)
  7290. || INTVAL (elt_ideal) != INTVAL (elt_op))
  7291. return false;
  7292. }
  7293. return true;
  7294. }
  7295. /* Bounds-check lanes. Ensure OPERAND lies between LOW (inclusive) and
  7296. HIGH (exclusive). */
  7297. void
  7298. aarch64_simd_lane_bounds (rtx operand, HOST_WIDE_INT low, HOST_WIDE_INT high,
  7299. const_tree exp)
  7300. {
  7301. HOST_WIDE_INT lane;
  7302. gcc_assert (CONST_INT_P (operand));
  7303. lane = INTVAL (operand);
  7304. if (lane < low || lane >= high)
  7305. {
  7306. if (exp)
  7307. error ("%Klane %ld out of range %ld - %ld", exp, lane, low, high - 1);
  7308. else
  7309. error ("lane %ld out of range %ld - %ld", lane, low, high - 1);
  7310. }
  7311. }
  7312. /* Emit code to place a AdvSIMD pair result in memory locations (with equal
  7313. registers). */
  7314. void
  7315. aarch64_simd_emit_pair_result_insn (machine_mode mode,
  7316. rtx (*intfn) (rtx, rtx, rtx), rtx destaddr,
  7317. rtx op1)
  7318. {
  7319. rtx mem = gen_rtx_MEM (mode, destaddr);
  7320. rtx tmp1 = gen_reg_rtx (mode);
  7321. rtx tmp2 = gen_reg_rtx (mode);
  7322. emit_insn (intfn (tmp1, op1, tmp2));
  7323. emit_move_insn (mem, tmp1);
  7324. mem = adjust_address (mem, mode, GET_MODE_SIZE (mode));
  7325. emit_move_insn (mem, tmp2);
  7326. }
  7327. /* Return TRUE if OP is a valid vector addressing mode. */
  7328. bool
  7329. aarch64_simd_mem_operand_p (rtx op)
  7330. {
  7331. return MEM_P (op) && (GET_CODE (XEXP (op, 0)) == POST_INC
  7332. || REG_P (XEXP (op, 0)));
  7333. }
  7334. /* Emit a register copy from operand to operand, taking care not to
  7335. early-clobber source registers in the process.
  7336. COUNT is the number of components into which the copy needs to be
  7337. decomposed. */
  7338. void
  7339. aarch64_simd_emit_reg_reg_move (rtx *operands, enum machine_mode mode,
  7340. unsigned int count)
  7341. {
  7342. unsigned int i;
  7343. int rdest = REGNO (operands[0]);
  7344. int rsrc = REGNO (operands[1]);
  7345. if (!reg_overlap_mentioned_p (operands[0], operands[1])
  7346. || rdest < rsrc)
  7347. for (i = 0; i < count; i++)
  7348. emit_move_insn (gen_rtx_REG (mode, rdest + i),
  7349. gen_rtx_REG (mode, rsrc + i));
  7350. else
  7351. for (i = 0; i < count; i++)
  7352. emit_move_insn (gen_rtx_REG (mode, rdest + count - i - 1),
  7353. gen_rtx_REG (mode, rsrc + count - i - 1));
  7354. }
  7355. /* Compute and return the length of aarch64_simd_mov<mode>, where <mode> is
  7356. one of VSTRUCT modes: OI, CI or XI. */
  7357. int
  7358. aarch64_simd_attr_length_move (rtx_insn *insn)
  7359. {
  7360. machine_mode mode;
  7361. extract_insn_cached (insn);
  7362. if (REG_P (recog_data.operand[0]) && REG_P (recog_data.operand[1]))
  7363. {
  7364. mode = GET_MODE (recog_data.operand[0]);
  7365. switch (mode)
  7366. {
  7367. case OImode:
  7368. return 8;
  7369. case CImode:
  7370. return 12;
  7371. case XImode:
  7372. return 16;
  7373. default:
  7374. gcc_unreachable ();
  7375. }
  7376. }
  7377. return 4;
  7378. }
  7379. /* Compute and return the length of aarch64_simd_reglist<mode>, where <mode> is
  7380. one of VSTRUCT modes: OI, CI, EI, or XI. */
  7381. int
  7382. aarch64_simd_attr_length_rglist (enum machine_mode mode)
  7383. {
  7384. return (GET_MODE_SIZE (mode) / UNITS_PER_VREG) * 4;
  7385. }
  7386. /* Implement target hook TARGET_VECTOR_ALIGNMENT. The AAPCS64 sets the maximum
  7387. alignment of a vector to 128 bits. */
  7388. static HOST_WIDE_INT
  7389. aarch64_simd_vector_alignment (const_tree type)
  7390. {
  7391. HOST_WIDE_INT align = tree_to_shwi (TYPE_SIZE (type));
  7392. return MIN (align, 128);
  7393. }
  7394. /* Implement target hook TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE. */
  7395. static bool
  7396. aarch64_simd_vector_alignment_reachable (const_tree type, bool is_packed)
  7397. {
  7398. if (is_packed)
  7399. return false;
  7400. /* We guarantee alignment for vectors up to 128-bits. */
  7401. if (tree_int_cst_compare (TYPE_SIZE (type),
  7402. bitsize_int (BIGGEST_ALIGNMENT)) > 0)
  7403. return false;
  7404. /* Vectors whose size is <= BIGGEST_ALIGNMENT are naturally aligned. */
  7405. return true;
  7406. }
  7407. /* If VALS is a vector constant that can be loaded into a register
  7408. using DUP, generate instructions to do so and return an RTX to
  7409. assign to the register. Otherwise return NULL_RTX. */
  7410. static rtx
  7411. aarch64_simd_dup_constant (rtx vals)
  7412. {
  7413. machine_mode mode = GET_MODE (vals);
  7414. machine_mode inner_mode = GET_MODE_INNER (mode);
  7415. int n_elts = GET_MODE_NUNITS (mode);
  7416. bool all_same = true;
  7417. rtx x;
  7418. int i;
  7419. if (GET_CODE (vals) != CONST_VECTOR)
  7420. return NULL_RTX;
  7421. for (i = 1; i < n_elts; ++i)
  7422. {
  7423. x = CONST_VECTOR_ELT (vals, i);
  7424. if (!rtx_equal_p (x, CONST_VECTOR_ELT (vals, 0)))
  7425. all_same = false;
  7426. }
  7427. if (!all_same)
  7428. return NULL_RTX;
  7429. /* We can load this constant by using DUP and a constant in a
  7430. single ARM register. This will be cheaper than a vector
  7431. load. */
  7432. x = copy_to_mode_reg (inner_mode, CONST_VECTOR_ELT (vals, 0));
  7433. return gen_rtx_VEC_DUPLICATE (mode, x);
  7434. }
  7435. /* Generate code to load VALS, which is a PARALLEL containing only
  7436. constants (for vec_init) or CONST_VECTOR, efficiently into a
  7437. register. Returns an RTX to copy into the register, or NULL_RTX
  7438. for a PARALLEL that can not be converted into a CONST_VECTOR. */
  7439. static rtx
  7440. aarch64_simd_make_constant (rtx vals)
  7441. {
  7442. machine_mode mode = GET_MODE (vals);
  7443. rtx const_dup;
  7444. rtx const_vec = NULL_RTX;
  7445. int n_elts = GET_MODE_NUNITS (mode);
  7446. int n_const = 0;
  7447. int i;
  7448. if (GET_CODE (vals) == CONST_VECTOR)
  7449. const_vec = vals;
  7450. else if (GET_CODE (vals) == PARALLEL)
  7451. {
  7452. /* A CONST_VECTOR must contain only CONST_INTs and
  7453. CONST_DOUBLEs, but CONSTANT_P allows more (e.g. SYMBOL_REF).
  7454. Only store valid constants in a CONST_VECTOR. */
  7455. for (i = 0; i < n_elts; ++i)
  7456. {
  7457. rtx x = XVECEXP (vals, 0, i);
  7458. if (CONST_INT_P (x) || CONST_DOUBLE_P (x))
  7459. n_const++;
  7460. }
  7461. if (n_const == n_elts)
  7462. const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0));
  7463. }
  7464. else
  7465. gcc_unreachable ();
  7466. if (const_vec != NULL_RTX
  7467. && aarch64_simd_valid_immediate (const_vec, mode, false, NULL))
  7468. /* Load using MOVI/MVNI. */
  7469. return const_vec;
  7470. else if ((const_dup = aarch64_simd_dup_constant (vals)) != NULL_RTX)
  7471. /* Loaded using DUP. */
  7472. return const_dup;
  7473. else if (const_vec != NULL_RTX)
  7474. /* Load from constant pool. We can not take advantage of single-cycle
  7475. LD1 because we need a PC-relative addressing mode. */
  7476. return const_vec;
  7477. else
  7478. /* A PARALLEL containing something not valid inside CONST_VECTOR.
  7479. We can not construct an initializer. */
  7480. return NULL_RTX;
  7481. }
  7482. void
  7483. aarch64_expand_vector_init (rtx target, rtx vals)
  7484. {
  7485. machine_mode mode = GET_MODE (target);
  7486. machine_mode inner_mode = GET_MODE_INNER (mode);
  7487. int n_elts = GET_MODE_NUNITS (mode);
  7488. int n_var = 0, one_var = -1;
  7489. bool all_same = true;
  7490. rtx x, mem;
  7491. int i;
  7492. x = XVECEXP (vals, 0, 0);
  7493. if (!CONST_INT_P (x) && !CONST_DOUBLE_P (x))
  7494. n_var = 1, one_var = 0;
  7495. for (i = 1; i < n_elts; ++i)
  7496. {
  7497. x = XVECEXP (vals, 0, i);
  7498. if (!CONST_INT_P (x) && !CONST_DOUBLE_P (x))
  7499. ++n_var, one_var = i;
  7500. if (!rtx_equal_p (x, XVECEXP (vals, 0, 0)))
  7501. all_same = false;
  7502. }
  7503. if (n_var == 0)
  7504. {
  7505. rtx constant = aarch64_simd_make_constant (vals);
  7506. if (constant != NULL_RTX)
  7507. {
  7508. emit_move_insn (target, constant);
  7509. return;
  7510. }
  7511. }
  7512. /* Splat a single non-constant element if we can. */
  7513. if (all_same)
  7514. {
  7515. x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, 0));
  7516. aarch64_emit_move (target, gen_rtx_VEC_DUPLICATE (mode, x));
  7517. return;
  7518. }
  7519. /* One field is non-constant. Load constant then overwrite varying
  7520. field. This is more efficient than using the stack. */
  7521. if (n_var == 1)
  7522. {
  7523. rtx copy = copy_rtx (vals);
  7524. rtx index = GEN_INT (one_var);
  7525. enum insn_code icode;
  7526. /* Load constant part of vector, substitute neighboring value for
  7527. varying element. */
  7528. XVECEXP (copy, 0, one_var) = XVECEXP (vals, 0, one_var ^ 1);
  7529. aarch64_expand_vector_init (target, copy);
  7530. /* Insert variable. */
  7531. x = copy_to_mode_reg (inner_mode, XVECEXP (vals, 0, one_var));
  7532. icode = optab_handler (vec_set_optab, mode);
  7533. gcc_assert (icode != CODE_FOR_nothing);
  7534. emit_insn (GEN_FCN (icode) (target, x, index));
  7535. return;
  7536. }
  7537. /* Construct the vector in memory one field at a time
  7538. and load the whole vector. */
  7539. mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
  7540. for (i = 0; i < n_elts; i++)
  7541. emit_move_insn (adjust_address_nv (mem, inner_mode,
  7542. i * GET_MODE_SIZE (inner_mode)),
  7543. XVECEXP (vals, 0, i));
  7544. emit_move_insn (target, mem);
  7545. }
  7546. static unsigned HOST_WIDE_INT
  7547. aarch64_shift_truncation_mask (machine_mode mode)
  7548. {
  7549. return
  7550. (aarch64_vector_mode_supported_p (mode)
  7551. || aarch64_vect_struct_mode_p (mode)) ? 0 : (GET_MODE_BITSIZE (mode) - 1);
  7552. }
  7553. #ifndef TLS_SECTION_ASM_FLAG
  7554. #define TLS_SECTION_ASM_FLAG 'T'
  7555. #endif
  7556. void
  7557. aarch64_elf_asm_named_section (const char *name, unsigned int flags,
  7558. tree decl ATTRIBUTE_UNUSED)
  7559. {
  7560. char flagchars[10], *f = flagchars;
  7561. /* If we have already declared this section, we can use an
  7562. abbreviated form to switch back to it -- unless this section is
  7563. part of a COMDAT groups, in which case GAS requires the full
  7564. declaration every time. */
  7565. if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
  7566. && (flags & SECTION_DECLARED))
  7567. {
  7568. fprintf (asm_out_file, "\t.section\t%s\n", name);
  7569. return;
  7570. }
  7571. if (!(flags & SECTION_DEBUG))
  7572. *f++ = 'a';
  7573. if (flags & SECTION_WRITE)
  7574. *f++ = 'w';
  7575. if (flags & SECTION_CODE)
  7576. *f++ = 'x';
  7577. if (flags & SECTION_SMALL)
  7578. *f++ = 's';
  7579. if (flags & SECTION_MERGE)
  7580. *f++ = 'M';
  7581. if (flags & SECTION_STRINGS)
  7582. *f++ = 'S';
  7583. if (flags & SECTION_TLS)
  7584. *f++ = TLS_SECTION_ASM_FLAG;
  7585. if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
  7586. *f++ = 'G';
  7587. *f = '\0';
  7588. fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
  7589. if (!(flags & SECTION_NOTYPE))
  7590. {
  7591. const char *type;
  7592. const char *format;
  7593. if (flags & SECTION_BSS)
  7594. type = "nobits";
  7595. else
  7596. type = "progbits";
  7597. #ifdef TYPE_OPERAND_FMT
  7598. format = "," TYPE_OPERAND_FMT;
  7599. #else
  7600. format = ",@%s";
  7601. #endif
  7602. fprintf (asm_out_file, format, type);
  7603. if (flags & SECTION_ENTSIZE)
  7604. fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
  7605. if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
  7606. {
  7607. if (TREE_CODE (decl) == IDENTIFIER_NODE)
  7608. fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
  7609. else
  7610. fprintf (asm_out_file, ",%s,comdat",
  7611. IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
  7612. }
  7613. }
  7614. putc ('\n', asm_out_file);
  7615. }
  7616. /* Select a format to encode pointers in exception handling data. */
  7617. int
  7618. aarch64_asm_preferred_eh_data_format (int code ATTRIBUTE_UNUSED, int global)
  7619. {
  7620. int type;
  7621. switch (aarch64_cmodel)
  7622. {
  7623. case AARCH64_CMODEL_TINY:
  7624. case AARCH64_CMODEL_TINY_PIC:
  7625. case AARCH64_CMODEL_SMALL:
  7626. case AARCH64_CMODEL_SMALL_PIC:
  7627. /* text+got+data < 4Gb. 4-byte signed relocs are sufficient
  7628. for everything. */
  7629. type = DW_EH_PE_sdata4;
  7630. break;
  7631. default:
  7632. /* No assumptions here. 8-byte relocs required. */
  7633. type = DW_EH_PE_sdata8;
  7634. break;
  7635. }
  7636. return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
  7637. }
  7638. /* Emit load exclusive. */
  7639. static void
  7640. aarch64_emit_load_exclusive (machine_mode mode, rtx rval,
  7641. rtx mem, rtx model_rtx)
  7642. {
  7643. rtx (*gen) (rtx, rtx, rtx);
  7644. switch (mode)
  7645. {
  7646. case QImode: gen = gen_aarch64_load_exclusiveqi; break;
  7647. case HImode: gen = gen_aarch64_load_exclusivehi; break;
  7648. case SImode: gen = gen_aarch64_load_exclusivesi; break;
  7649. case DImode: gen = gen_aarch64_load_exclusivedi; break;
  7650. default:
  7651. gcc_unreachable ();
  7652. }
  7653. emit_insn (gen (rval, mem, model_rtx));
  7654. }
  7655. /* Emit store exclusive. */
  7656. static void
  7657. aarch64_emit_store_exclusive (machine_mode mode, rtx bval,
  7658. rtx rval, rtx mem, rtx model_rtx)
  7659. {
  7660. rtx (*gen) (rtx, rtx, rtx, rtx);
  7661. switch (mode)
  7662. {
  7663. case QImode: gen = gen_aarch64_store_exclusiveqi; break;
  7664. case HImode: gen = gen_aarch64_store_exclusivehi; break;
  7665. case SImode: gen = gen_aarch64_store_exclusivesi; break;
  7666. case DImode: gen = gen_aarch64_store_exclusivedi; break;
  7667. default:
  7668. gcc_unreachable ();
  7669. }
  7670. emit_insn (gen (bval, rval, mem, model_rtx));
  7671. }
  7672. /* Mark the previous jump instruction as unlikely. */
  7673. static void
  7674. aarch64_emit_unlikely_jump (rtx insn)
  7675. {
  7676. int very_unlikely = REG_BR_PROB_BASE / 100 - 1;
  7677. insn = emit_jump_insn (insn);
  7678. add_int_reg_note (insn, REG_BR_PROB, very_unlikely);
  7679. }
  7680. /* Expand a compare and swap pattern. */
  7681. void
  7682. aarch64_expand_compare_and_swap (rtx operands[])
  7683. {
  7684. rtx bval, rval, mem, oldval, newval, is_weak, mod_s, mod_f, x;
  7685. machine_mode mode, cmp_mode;
  7686. rtx (*gen) (rtx, rtx, rtx, rtx, rtx, rtx, rtx);
  7687. bval = operands[0];
  7688. rval = operands[1];
  7689. mem = operands[2];
  7690. oldval = operands[3];
  7691. newval = operands[4];
  7692. is_weak = operands[5];
  7693. mod_s = operands[6];
  7694. mod_f = operands[7];
  7695. mode = GET_MODE (mem);
  7696. cmp_mode = mode;
  7697. /* Normally the succ memory model must be stronger than fail, but in the
  7698. unlikely event of fail being ACQUIRE and succ being RELEASE we need to
  7699. promote succ to ACQ_REL so that we don't lose the acquire semantics. */
  7700. if (INTVAL (mod_f) == MEMMODEL_ACQUIRE
  7701. && INTVAL (mod_s) == MEMMODEL_RELEASE)
  7702. mod_s = GEN_INT (MEMMODEL_ACQ_REL);
  7703. switch (mode)
  7704. {
  7705. case QImode:
  7706. case HImode:
  7707. /* For short modes, we're going to perform the comparison in SImode,
  7708. so do the zero-extension now. */
  7709. cmp_mode = SImode;
  7710. rval = gen_reg_rtx (SImode);
  7711. oldval = convert_modes (SImode, mode, oldval, true);
  7712. /* Fall through. */
  7713. case SImode:
  7714. case DImode:
  7715. /* Force the value into a register if needed. */
  7716. if (!aarch64_plus_operand (oldval, mode))
  7717. oldval = force_reg (cmp_mode, oldval);
  7718. break;
  7719. default:
  7720. gcc_unreachable ();
  7721. }
  7722. switch (mode)
  7723. {
  7724. case QImode: gen = gen_atomic_compare_and_swapqi_1; break;
  7725. case HImode: gen = gen_atomic_compare_and_swaphi_1; break;
  7726. case SImode: gen = gen_atomic_compare_and_swapsi_1; break;
  7727. case DImode: gen = gen_atomic_compare_and_swapdi_1; break;
  7728. default:
  7729. gcc_unreachable ();
  7730. }
  7731. emit_insn (gen (rval, mem, oldval, newval, is_weak, mod_s, mod_f));
  7732. if (mode == QImode || mode == HImode)
  7733. emit_move_insn (operands[1], gen_lowpart (mode, rval));
  7734. x = gen_rtx_REG (CCmode, CC_REGNUM);
  7735. x = gen_rtx_EQ (SImode, x, const0_rtx);
  7736. emit_insn (gen_rtx_SET (VOIDmode, bval, x));
  7737. }
  7738. /* Split a compare and swap pattern. */
  7739. void
  7740. aarch64_split_compare_and_swap (rtx operands[])
  7741. {
  7742. rtx rval, mem, oldval, newval, scratch;
  7743. machine_mode mode;
  7744. bool is_weak;
  7745. rtx_code_label *label1, *label2;
  7746. rtx x, cond;
  7747. rval = operands[0];
  7748. mem = operands[1];
  7749. oldval = operands[2];
  7750. newval = operands[3];
  7751. is_weak = (operands[4] != const0_rtx);
  7752. scratch = operands[7];
  7753. mode = GET_MODE (mem);
  7754. label1 = NULL;
  7755. if (!is_weak)
  7756. {
  7757. label1 = gen_label_rtx ();
  7758. emit_label (label1);
  7759. }
  7760. label2 = gen_label_rtx ();
  7761. aarch64_emit_load_exclusive (mode, rval, mem, operands[5]);
  7762. cond = aarch64_gen_compare_reg (NE, rval, oldval);
  7763. x = gen_rtx_NE (VOIDmode, cond, const0_rtx);
  7764. x = gen_rtx_IF_THEN_ELSE (VOIDmode, x,
  7765. gen_rtx_LABEL_REF (Pmode, label2), pc_rtx);
  7766. aarch64_emit_unlikely_jump (gen_rtx_SET (VOIDmode, pc_rtx, x));
  7767. aarch64_emit_store_exclusive (mode, scratch, mem, newval, operands[5]);
  7768. if (!is_weak)
  7769. {
  7770. x = gen_rtx_NE (VOIDmode, scratch, const0_rtx);
  7771. x = gen_rtx_IF_THEN_ELSE (VOIDmode, x,
  7772. gen_rtx_LABEL_REF (Pmode, label1), pc_rtx);
  7773. aarch64_emit_unlikely_jump (gen_rtx_SET (VOIDmode, pc_rtx, x));
  7774. }
  7775. else
  7776. {
  7777. cond = gen_rtx_REG (CCmode, CC_REGNUM);
  7778. x = gen_rtx_COMPARE (CCmode, scratch, const0_rtx);
  7779. emit_insn (gen_rtx_SET (VOIDmode, cond, x));
  7780. }
  7781. emit_label (label2);
  7782. }
  7783. /* Split an atomic operation. */
  7784. void
  7785. aarch64_split_atomic_op (enum rtx_code code, rtx old_out, rtx new_out, rtx mem,
  7786. rtx value, rtx model_rtx, rtx cond)
  7787. {
  7788. machine_mode mode = GET_MODE (mem);
  7789. machine_mode wmode = (mode == DImode ? DImode : SImode);
  7790. rtx_code_label *label;
  7791. rtx x;
  7792. label = gen_label_rtx ();
  7793. emit_label (label);
  7794. if (new_out)
  7795. new_out = gen_lowpart (wmode, new_out);
  7796. if (old_out)
  7797. old_out = gen_lowpart (wmode, old_out);
  7798. else
  7799. old_out = new_out;
  7800. value = simplify_gen_subreg (wmode, value, mode, 0);
  7801. aarch64_emit_load_exclusive (mode, old_out, mem, model_rtx);
  7802. switch (code)
  7803. {
  7804. case SET:
  7805. new_out = value;
  7806. break;
  7807. case NOT:
  7808. x = gen_rtx_AND (wmode, old_out, value);
  7809. emit_insn (gen_rtx_SET (VOIDmode, new_out, x));
  7810. x = gen_rtx_NOT (wmode, new_out);
  7811. emit_insn (gen_rtx_SET (VOIDmode, new_out, x));
  7812. break;
  7813. case MINUS:
  7814. if (CONST_INT_P (value))
  7815. {
  7816. value = GEN_INT (-INTVAL (value));
  7817. code = PLUS;
  7818. }
  7819. /* Fall through. */
  7820. default:
  7821. x = gen_rtx_fmt_ee (code, wmode, old_out, value);
  7822. emit_insn (gen_rtx_SET (VOIDmode, new_out, x));
  7823. break;
  7824. }
  7825. aarch64_emit_store_exclusive (mode, cond, mem,
  7826. gen_lowpart (mode, new_out), model_rtx);
  7827. x = gen_rtx_NE (VOIDmode, cond, const0_rtx);
  7828. x = gen_rtx_IF_THEN_ELSE (VOIDmode, x,
  7829. gen_rtx_LABEL_REF (Pmode, label), pc_rtx);
  7830. aarch64_emit_unlikely_jump (gen_rtx_SET (VOIDmode, pc_rtx, x));
  7831. }
  7832. static void
  7833. aarch64_print_extension (void)
  7834. {
  7835. const struct aarch64_option_extension *opt = NULL;
  7836. for (opt = all_extensions; opt->name != NULL; opt++)
  7837. if ((aarch64_isa_flags & opt->flags_on) == opt->flags_on)
  7838. asm_fprintf (asm_out_file, "+%s", opt->name);
  7839. asm_fprintf (asm_out_file, "\n");
  7840. }
  7841. static void
  7842. aarch64_start_file (void)
  7843. {
  7844. if (selected_arch)
  7845. {
  7846. asm_fprintf (asm_out_file, "\t.arch %s", selected_arch->name);
  7847. aarch64_print_extension ();
  7848. }
  7849. else if (selected_cpu)
  7850. {
  7851. const char *truncated_name
  7852. = aarch64_rewrite_selected_cpu (selected_cpu->name);
  7853. asm_fprintf (asm_out_file, "\t.cpu %s", truncated_name);
  7854. aarch64_print_extension ();
  7855. }
  7856. default_file_start();
  7857. }
  7858. /* Target hook for c_mode_for_suffix. */
  7859. static machine_mode
  7860. aarch64_c_mode_for_suffix (char suffix)
  7861. {
  7862. if (suffix == 'q')
  7863. return TFmode;
  7864. return VOIDmode;
  7865. }
  7866. /* We can only represent floating point constants which will fit in
  7867. "quarter-precision" values. These values are characterised by
  7868. a sign bit, a 4-bit mantissa and a 3-bit exponent. And are given
  7869. by:
  7870. (-1)^s * (n/16) * 2^r
  7871. Where:
  7872. 's' is the sign bit.
  7873. 'n' is an integer in the range 16 <= n <= 31.
  7874. 'r' is an integer in the range -3 <= r <= 4. */
  7875. /* Return true iff X can be represented by a quarter-precision
  7876. floating point immediate operand X. Note, we cannot represent 0.0. */
  7877. bool
  7878. aarch64_float_const_representable_p (rtx x)
  7879. {
  7880. /* This represents our current view of how many bits
  7881. make up the mantissa. */
  7882. int point_pos = 2 * HOST_BITS_PER_WIDE_INT - 1;
  7883. int exponent;
  7884. unsigned HOST_WIDE_INT mantissa, mask;
  7885. REAL_VALUE_TYPE r, m;
  7886. bool fail;
  7887. if (!CONST_DOUBLE_P (x))
  7888. return false;
  7889. if (GET_MODE (x) == VOIDmode)
  7890. return false;
  7891. REAL_VALUE_FROM_CONST_DOUBLE (r, x);
  7892. /* We cannot represent infinities, NaNs or +/-zero. We won't
  7893. know if we have +zero until we analyse the mantissa, but we
  7894. can reject the other invalid values. */
  7895. if (REAL_VALUE_ISINF (r) || REAL_VALUE_ISNAN (r)
  7896. || REAL_VALUE_MINUS_ZERO (r))
  7897. return false;
  7898. /* Extract exponent. */
  7899. r = real_value_abs (&r);
  7900. exponent = REAL_EXP (&r);
  7901. /* For the mantissa, we expand into two HOST_WIDE_INTS, apart from the
  7902. highest (sign) bit, with a fixed binary point at bit point_pos.
  7903. m1 holds the low part of the mantissa, m2 the high part.
  7904. WARNING: If we ever have a representation using more than 2 * H_W_I - 1
  7905. bits for the mantissa, this can fail (low bits will be lost). */
  7906. real_ldexp (&m, &r, point_pos - exponent);
  7907. wide_int w = real_to_integer (&m, &fail, HOST_BITS_PER_WIDE_INT * 2);
  7908. /* If the low part of the mantissa has bits set we cannot represent
  7909. the value. */
  7910. if (w.elt (0) != 0)
  7911. return false;
  7912. /* We have rejected the lower HOST_WIDE_INT, so update our
  7913. understanding of how many bits lie in the mantissa and
  7914. look only at the high HOST_WIDE_INT. */
  7915. mantissa = w.elt (1);
  7916. point_pos -= HOST_BITS_PER_WIDE_INT;
  7917. /* We can only represent values with a mantissa of the form 1.xxxx. */
  7918. mask = ((unsigned HOST_WIDE_INT)1 << (point_pos - 5)) - 1;
  7919. if ((mantissa & mask) != 0)
  7920. return false;
  7921. /* Having filtered unrepresentable values, we may now remove all
  7922. but the highest 5 bits. */
  7923. mantissa >>= point_pos - 5;
  7924. /* We cannot represent the value 0.0, so reject it. This is handled
  7925. elsewhere. */
  7926. if (mantissa == 0)
  7927. return false;
  7928. /* Then, as bit 4 is always set, we can mask it off, leaving
  7929. the mantissa in the range [0, 15]. */
  7930. mantissa &= ~(1 << 4);
  7931. gcc_assert (mantissa <= 15);
  7932. /* GCC internally does not use IEEE754-like encoding (where normalized
  7933. significands are in the range [1, 2). GCC uses [0.5, 1) (see real.c).
  7934. Our mantissa values are shifted 4 places to the left relative to
  7935. normalized IEEE754 so we must modify the exponent returned by REAL_EXP
  7936. by 5 places to correct for GCC's representation. */
  7937. exponent = 5 - exponent;
  7938. return (exponent >= 0 && exponent <= 7);
  7939. }
  7940. char*
  7941. aarch64_output_simd_mov_immediate (rtx const_vector,
  7942. machine_mode mode,
  7943. unsigned width)
  7944. {
  7945. bool is_valid;
  7946. static char templ[40];
  7947. const char *mnemonic;
  7948. const char *shift_op;
  7949. unsigned int lane_count = 0;
  7950. char element_char;
  7951. struct simd_immediate_info info = { NULL_RTX, 0, 0, false, false };
  7952. /* This will return true to show const_vector is legal for use as either
  7953. a AdvSIMD MOVI instruction (or, implicitly, MVNI) immediate. It will
  7954. also update INFO to show how the immediate should be generated. */
  7955. is_valid = aarch64_simd_valid_immediate (const_vector, mode, false, &info);
  7956. gcc_assert (is_valid);
  7957. element_char = sizetochar (info.element_width);
  7958. lane_count = width / info.element_width;
  7959. mode = GET_MODE_INNER (mode);
  7960. if (mode == SFmode || mode == DFmode)
  7961. {
  7962. gcc_assert (info.shift == 0 && ! info.mvn);
  7963. if (aarch64_float_const_zero_rtx_p (info.value))
  7964. info.value = GEN_INT (0);
  7965. else
  7966. {
  7967. #define buf_size 20
  7968. REAL_VALUE_TYPE r;
  7969. REAL_VALUE_FROM_CONST_DOUBLE (r, info.value);
  7970. char float_buf[buf_size] = {'\0'};
  7971. real_to_decimal_for_mode (float_buf, &r, buf_size, buf_size, 1, mode);
  7972. #undef buf_size
  7973. if (lane_count == 1)
  7974. snprintf (templ, sizeof (templ), "fmov\t%%d0, %s", float_buf);
  7975. else
  7976. snprintf (templ, sizeof (templ), "fmov\t%%0.%d%c, %s",
  7977. lane_count, element_char, float_buf);
  7978. return templ;
  7979. }
  7980. }
  7981. mnemonic = info.mvn ? "mvni" : "movi";
  7982. shift_op = info.msl ? "msl" : "lsl";
  7983. if (lane_count == 1)
  7984. snprintf (templ, sizeof (templ), "%s\t%%d0, " HOST_WIDE_INT_PRINT_HEX,
  7985. mnemonic, UINTVAL (info.value));
  7986. else if (info.shift)
  7987. snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " HOST_WIDE_INT_PRINT_HEX
  7988. ", %s %d", mnemonic, lane_count, element_char,
  7989. UINTVAL (info.value), shift_op, info.shift);
  7990. else
  7991. snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, " HOST_WIDE_INT_PRINT_HEX,
  7992. mnemonic, lane_count, element_char, UINTVAL (info.value));
  7993. return templ;
  7994. }
  7995. char*
  7996. aarch64_output_scalar_simd_mov_immediate (rtx immediate,
  7997. machine_mode mode)
  7998. {
  7999. machine_mode vmode;
  8000. gcc_assert (!VECTOR_MODE_P (mode));
  8001. vmode = aarch64_simd_container_mode (mode, 64);
  8002. rtx v_op = aarch64_simd_gen_const_vector_dup (vmode, INTVAL (immediate));
  8003. return aarch64_output_simd_mov_immediate (v_op, vmode, 64);
  8004. }
  8005. /* Split operands into moves from op[1] + op[2] into op[0]. */
  8006. void
  8007. aarch64_split_combinev16qi (rtx operands[3])
  8008. {
  8009. unsigned int dest = REGNO (operands[0]);
  8010. unsigned int src1 = REGNO (operands[1]);
  8011. unsigned int src2 = REGNO (operands[2]);
  8012. machine_mode halfmode = GET_MODE (operands[1]);
  8013. unsigned int halfregs = HARD_REGNO_NREGS (src1, halfmode);
  8014. rtx destlo, desthi;
  8015. gcc_assert (halfmode == V16QImode);
  8016. if (src1 == dest && src2 == dest + halfregs)
  8017. {
  8018. /* No-op move. Can't split to nothing; emit something. */
  8019. emit_note (NOTE_INSN_DELETED);
  8020. return;
  8021. }
  8022. /* Preserve register attributes for variable tracking. */
  8023. destlo = gen_rtx_REG_offset (operands[0], halfmode, dest, 0);
  8024. desthi = gen_rtx_REG_offset (operands[0], halfmode, dest + halfregs,
  8025. GET_MODE_SIZE (halfmode));
  8026. /* Special case of reversed high/low parts. */
  8027. if (reg_overlap_mentioned_p (operands[2], destlo)
  8028. && reg_overlap_mentioned_p (operands[1], desthi))
  8029. {
  8030. emit_insn (gen_xorv16qi3 (operands[1], operands[1], operands[2]));
  8031. emit_insn (gen_xorv16qi3 (operands[2], operands[1], operands[2]));
  8032. emit_insn (gen_xorv16qi3 (operands[1], operands[1], operands[2]));
  8033. }
  8034. else if (!reg_overlap_mentioned_p (operands[2], destlo))
  8035. {
  8036. /* Try to avoid unnecessary moves if part of the result
  8037. is in the right place already. */
  8038. if (src1 != dest)
  8039. emit_move_insn (destlo, operands[1]);
  8040. if (src2 != dest + halfregs)
  8041. emit_move_insn (desthi, operands[2]);
  8042. }
  8043. else
  8044. {
  8045. if (src2 != dest + halfregs)
  8046. emit_move_insn (desthi, operands[2]);
  8047. if (src1 != dest)
  8048. emit_move_insn (destlo, operands[1]);
  8049. }
  8050. }
  8051. /* vec_perm support. */
  8052. #define MAX_VECT_LEN 16
  8053. struct expand_vec_perm_d
  8054. {
  8055. rtx target, op0, op1;
  8056. unsigned char perm[MAX_VECT_LEN];
  8057. machine_mode vmode;
  8058. unsigned char nelt;
  8059. bool one_vector_p;
  8060. bool testing_p;
  8061. };
  8062. /* Generate a variable permutation. */
  8063. static void
  8064. aarch64_expand_vec_perm_1 (rtx target, rtx op0, rtx op1, rtx sel)
  8065. {
  8066. machine_mode vmode = GET_MODE (target);
  8067. bool one_vector_p = rtx_equal_p (op0, op1);
  8068. gcc_checking_assert (vmode == V8QImode || vmode == V16QImode);
  8069. gcc_checking_assert (GET_MODE (op0) == vmode);
  8070. gcc_checking_assert (GET_MODE (op1) == vmode);
  8071. gcc_checking_assert (GET_MODE (sel) == vmode);
  8072. gcc_checking_assert (TARGET_SIMD);
  8073. if (one_vector_p)
  8074. {
  8075. if (vmode == V8QImode)
  8076. {
  8077. /* Expand the argument to a V16QI mode by duplicating it. */
  8078. rtx pair = gen_reg_rtx (V16QImode);
  8079. emit_insn (gen_aarch64_combinev8qi (pair, op0, op0));
  8080. emit_insn (gen_aarch64_tbl1v8qi (target, pair, sel));
  8081. }
  8082. else
  8083. {
  8084. emit_insn (gen_aarch64_tbl1v16qi (target, op0, sel));
  8085. }
  8086. }
  8087. else
  8088. {
  8089. rtx pair;
  8090. if (vmode == V8QImode)
  8091. {
  8092. pair = gen_reg_rtx (V16QImode);
  8093. emit_insn (gen_aarch64_combinev8qi (pair, op0, op1));
  8094. emit_insn (gen_aarch64_tbl1v8qi (target, pair, sel));
  8095. }
  8096. else
  8097. {
  8098. pair = gen_reg_rtx (OImode);
  8099. emit_insn (gen_aarch64_combinev16qi (pair, op0, op1));
  8100. emit_insn (gen_aarch64_tbl2v16qi (target, pair, sel));
  8101. }
  8102. }
  8103. }
  8104. void
  8105. aarch64_expand_vec_perm (rtx target, rtx op0, rtx op1, rtx sel)
  8106. {
  8107. machine_mode vmode = GET_MODE (target);
  8108. unsigned int nelt = GET_MODE_NUNITS (vmode);
  8109. bool one_vector_p = rtx_equal_p (op0, op1);
  8110. rtx mask;
  8111. /* The TBL instruction does not use a modulo index, so we must take care
  8112. of that ourselves. */
  8113. mask = aarch64_simd_gen_const_vector_dup (vmode,
  8114. one_vector_p ? nelt - 1 : 2 * nelt - 1);
  8115. sel = expand_simple_binop (vmode, AND, sel, mask, NULL, 0, OPTAB_LIB_WIDEN);
  8116. /* For big-endian, we also need to reverse the index within the vector
  8117. (but not which vector). */
  8118. if (BYTES_BIG_ENDIAN)
  8119. {
  8120. /* If one_vector_p, mask is a vector of (nelt - 1)'s already. */
  8121. if (!one_vector_p)
  8122. mask = aarch64_simd_gen_const_vector_dup (vmode, nelt - 1);
  8123. sel = expand_simple_binop (vmode, XOR, sel, mask,
  8124. NULL, 0, OPTAB_LIB_WIDEN);
  8125. }
  8126. aarch64_expand_vec_perm_1 (target, op0, op1, sel);
  8127. }
  8128. /* Recognize patterns suitable for the TRN instructions. */
  8129. static bool
  8130. aarch64_evpc_trn (struct expand_vec_perm_d *d)
  8131. {
  8132. unsigned int i, odd, mask, nelt = d->nelt;
  8133. rtx out, in0, in1, x;
  8134. rtx (*gen) (rtx, rtx, rtx);
  8135. machine_mode vmode = d->vmode;
  8136. if (GET_MODE_UNIT_SIZE (vmode) > 8)
  8137. return false;
  8138. /* Note that these are little-endian tests.
  8139. We correct for big-endian later. */
  8140. if (d->perm[0] == 0)
  8141. odd = 0;
  8142. else if (d->perm[0] == 1)
  8143. odd = 1;
  8144. else
  8145. return false;
  8146. mask = (d->one_vector_p ? nelt - 1 : 2 * nelt - 1);
  8147. for (i = 0; i < nelt; i += 2)
  8148. {
  8149. if (d->perm[i] != i + odd)
  8150. return false;
  8151. if (d->perm[i + 1] != ((i + nelt + odd) & mask))
  8152. return false;
  8153. }
  8154. /* Success! */
  8155. if (d->testing_p)
  8156. return true;
  8157. in0 = d->op0;
  8158. in1 = d->op1;
  8159. if (BYTES_BIG_ENDIAN)
  8160. {
  8161. x = in0, in0 = in1, in1 = x;
  8162. odd = !odd;
  8163. }
  8164. out = d->target;
  8165. if (odd)
  8166. {
  8167. switch (vmode)
  8168. {
  8169. case V16QImode: gen = gen_aarch64_trn2v16qi; break;
  8170. case V8QImode: gen = gen_aarch64_trn2v8qi; break;
  8171. case V8HImode: gen = gen_aarch64_trn2v8hi; break;
  8172. case V4HImode: gen = gen_aarch64_trn2v4hi; break;
  8173. case V4SImode: gen = gen_aarch64_trn2v4si; break;
  8174. case V2SImode: gen = gen_aarch64_trn2v2si; break;
  8175. case V2DImode: gen = gen_aarch64_trn2v2di; break;
  8176. case V4SFmode: gen = gen_aarch64_trn2v4sf; break;
  8177. case V2SFmode: gen = gen_aarch64_trn2v2sf; break;
  8178. case V2DFmode: gen = gen_aarch64_trn2v2df; break;
  8179. default:
  8180. return false;
  8181. }
  8182. }
  8183. else
  8184. {
  8185. switch (vmode)
  8186. {
  8187. case V16QImode: gen = gen_aarch64_trn1v16qi; break;
  8188. case V8QImode: gen = gen_aarch64_trn1v8qi; break;
  8189. case V8HImode: gen = gen_aarch64_trn1v8hi; break;
  8190. case V4HImode: gen = gen_aarch64_trn1v4hi; break;
  8191. case V4SImode: gen = gen_aarch64_trn1v4si; break;
  8192. case V2SImode: gen = gen_aarch64_trn1v2si; break;
  8193. case V2DImode: gen = gen_aarch64_trn1v2di; break;
  8194. case V4SFmode: gen = gen_aarch64_trn1v4sf; break;
  8195. case V2SFmode: gen = gen_aarch64_trn1v2sf; break;
  8196. case V2DFmode: gen = gen_aarch64_trn1v2df; break;
  8197. default:
  8198. return false;
  8199. }
  8200. }
  8201. emit_insn (gen (out, in0, in1));
  8202. return true;
  8203. }
  8204. /* Recognize patterns suitable for the UZP instructions. */
  8205. static bool
  8206. aarch64_evpc_uzp (struct expand_vec_perm_d *d)
  8207. {
  8208. unsigned int i, odd, mask, nelt = d->nelt;
  8209. rtx out, in0, in1, x;
  8210. rtx (*gen) (rtx, rtx, rtx);
  8211. machine_mode vmode = d->vmode;
  8212. if (GET_MODE_UNIT_SIZE (vmode) > 8)
  8213. return false;
  8214. /* Note that these are little-endian tests.
  8215. We correct for big-endian later. */
  8216. if (d->perm[0] == 0)
  8217. odd = 0;
  8218. else if (d->perm[0] == 1)
  8219. odd = 1;
  8220. else
  8221. return false;
  8222. mask = (d->one_vector_p ? nelt - 1 : 2 * nelt - 1);
  8223. for (i = 0; i < nelt; i++)
  8224. {
  8225. unsigned elt = (i * 2 + odd) & mask;
  8226. if (d->perm[i] != elt)
  8227. return false;
  8228. }
  8229. /* Success! */
  8230. if (d->testing_p)
  8231. return true;
  8232. in0 = d->op0;
  8233. in1 = d->op1;
  8234. if (BYTES_BIG_ENDIAN)
  8235. {
  8236. x = in0, in0 = in1, in1 = x;
  8237. odd = !odd;
  8238. }
  8239. out = d->target;
  8240. if (odd)
  8241. {
  8242. switch (vmode)
  8243. {
  8244. case V16QImode: gen = gen_aarch64_uzp2v16qi; break;
  8245. case V8QImode: gen = gen_aarch64_uzp2v8qi; break;
  8246. case V8HImode: gen = gen_aarch64_uzp2v8hi; break;
  8247. case V4HImode: gen = gen_aarch64_uzp2v4hi; break;
  8248. case V4SImode: gen = gen_aarch64_uzp2v4si; break;
  8249. case V2SImode: gen = gen_aarch64_uzp2v2si; break;
  8250. case V2DImode: gen = gen_aarch64_uzp2v2di; break;
  8251. case V4SFmode: gen = gen_aarch64_uzp2v4sf; break;
  8252. case V2SFmode: gen = gen_aarch64_uzp2v2sf; break;
  8253. case V2DFmode: gen = gen_aarch64_uzp2v2df; break;
  8254. default:
  8255. return false;
  8256. }
  8257. }
  8258. else
  8259. {
  8260. switch (vmode)
  8261. {
  8262. case V16QImode: gen = gen_aarch64_uzp1v16qi; break;
  8263. case V8QImode: gen = gen_aarch64_uzp1v8qi; break;
  8264. case V8HImode: gen = gen_aarch64_uzp1v8hi; break;
  8265. case V4HImode: gen = gen_aarch64_uzp1v4hi; break;
  8266. case V4SImode: gen = gen_aarch64_uzp1v4si; break;
  8267. case V2SImode: gen = gen_aarch64_uzp1v2si; break;
  8268. case V2DImode: gen = gen_aarch64_uzp1v2di; break;
  8269. case V4SFmode: gen = gen_aarch64_uzp1v4sf; break;
  8270. case V2SFmode: gen = gen_aarch64_uzp1v2sf; break;
  8271. case V2DFmode: gen = gen_aarch64_uzp1v2df; break;
  8272. default:
  8273. return false;
  8274. }
  8275. }
  8276. emit_insn (gen (out, in0, in1));
  8277. return true;
  8278. }
  8279. /* Recognize patterns suitable for the ZIP instructions. */
  8280. static bool
  8281. aarch64_evpc_zip (struct expand_vec_perm_d *d)
  8282. {
  8283. unsigned int i, high, mask, nelt = d->nelt;
  8284. rtx out, in0, in1, x;
  8285. rtx (*gen) (rtx, rtx, rtx);
  8286. machine_mode vmode = d->vmode;
  8287. if (GET_MODE_UNIT_SIZE (vmode) > 8)
  8288. return false;
  8289. /* Note that these are little-endian tests.
  8290. We correct for big-endian later. */
  8291. high = nelt / 2;
  8292. if (d->perm[0] == high)
  8293. /* Do Nothing. */
  8294. ;
  8295. else if (d->perm[0] == 0)
  8296. high = 0;
  8297. else
  8298. return false;
  8299. mask = (d->one_vector_p ? nelt - 1 : 2 * nelt - 1);
  8300. for (i = 0; i < nelt / 2; i++)
  8301. {
  8302. unsigned elt = (i + high) & mask;
  8303. if (d->perm[i * 2] != elt)
  8304. return false;
  8305. elt = (elt + nelt) & mask;
  8306. if (d->perm[i * 2 + 1] != elt)
  8307. return false;
  8308. }
  8309. /* Success! */
  8310. if (d->testing_p)
  8311. return true;
  8312. in0 = d->op0;
  8313. in1 = d->op1;
  8314. if (BYTES_BIG_ENDIAN)
  8315. {
  8316. x = in0, in0 = in1, in1 = x;
  8317. high = !high;
  8318. }
  8319. out = d->target;
  8320. if (high)
  8321. {
  8322. switch (vmode)
  8323. {
  8324. case V16QImode: gen = gen_aarch64_zip2v16qi; break;
  8325. case V8QImode: gen = gen_aarch64_zip2v8qi; break;
  8326. case V8HImode: gen = gen_aarch64_zip2v8hi; break;
  8327. case V4HImode: gen = gen_aarch64_zip2v4hi; break;
  8328. case V4SImode: gen = gen_aarch64_zip2v4si; break;
  8329. case V2SImode: gen = gen_aarch64_zip2v2si; break;
  8330. case V2DImode: gen = gen_aarch64_zip2v2di; break;
  8331. case V4SFmode: gen = gen_aarch64_zip2v4sf; break;
  8332. case V2SFmode: gen = gen_aarch64_zip2v2sf; break;
  8333. case V2DFmode: gen = gen_aarch64_zip2v2df; break;
  8334. default:
  8335. return false;
  8336. }
  8337. }
  8338. else
  8339. {
  8340. switch (vmode)
  8341. {
  8342. case V16QImode: gen = gen_aarch64_zip1v16qi; break;
  8343. case V8QImode: gen = gen_aarch64_zip1v8qi; break;
  8344. case V8HImode: gen = gen_aarch64_zip1v8hi; break;
  8345. case V4HImode: gen = gen_aarch64_zip1v4hi; break;
  8346. case V4SImode: gen = gen_aarch64_zip1v4si; break;
  8347. case V2SImode: gen = gen_aarch64_zip1v2si; break;
  8348. case V2DImode: gen = gen_aarch64_zip1v2di; break;
  8349. case V4SFmode: gen = gen_aarch64_zip1v4sf; break;
  8350. case V2SFmode: gen = gen_aarch64_zip1v2sf; break;
  8351. case V2DFmode: gen = gen_aarch64_zip1v2df; break;
  8352. default:
  8353. return false;
  8354. }
  8355. }
  8356. emit_insn (gen (out, in0, in1));
  8357. return true;
  8358. }
  8359. /* Recognize patterns for the EXT insn. */
  8360. static bool
  8361. aarch64_evpc_ext (struct expand_vec_perm_d *d)
  8362. {
  8363. unsigned int i, nelt = d->nelt;
  8364. rtx (*gen) (rtx, rtx, rtx, rtx);
  8365. rtx offset;
  8366. unsigned int location = d->perm[0]; /* Always < nelt. */
  8367. /* Check if the extracted indices are increasing by one. */
  8368. for (i = 1; i < nelt; i++)
  8369. {
  8370. unsigned int required = location + i;
  8371. if (d->one_vector_p)
  8372. {
  8373. /* We'll pass the same vector in twice, so allow indices to wrap. */
  8374. required &= (nelt - 1);
  8375. }
  8376. if (d->perm[i] != required)
  8377. return false;
  8378. }
  8379. switch (d->vmode)
  8380. {
  8381. case V16QImode: gen = gen_aarch64_extv16qi; break;
  8382. case V8QImode: gen = gen_aarch64_extv8qi; break;
  8383. case V4HImode: gen = gen_aarch64_extv4hi; break;
  8384. case V8HImode: gen = gen_aarch64_extv8hi; break;
  8385. case V2SImode: gen = gen_aarch64_extv2si; break;
  8386. case V4SImode: gen = gen_aarch64_extv4si; break;
  8387. case V2SFmode: gen = gen_aarch64_extv2sf; break;
  8388. case V4SFmode: gen = gen_aarch64_extv4sf; break;
  8389. case V2DImode: gen = gen_aarch64_extv2di; break;
  8390. case V2DFmode: gen = gen_aarch64_extv2df; break;
  8391. default:
  8392. return false;
  8393. }
  8394. /* Success! */
  8395. if (d->testing_p)
  8396. return true;
  8397. /* The case where (location == 0) is a no-op for both big- and little-endian,
  8398. and is removed by the mid-end at optimization levels -O1 and higher. */
  8399. if (BYTES_BIG_ENDIAN && (location != 0))
  8400. {
  8401. /* After setup, we want the high elements of the first vector (stored
  8402. at the LSB end of the register), and the low elements of the second
  8403. vector (stored at the MSB end of the register). So swap. */
  8404. std::swap (d->op0, d->op1);
  8405. /* location != 0 (above), so safe to assume (nelt - location) < nelt. */
  8406. location = nelt - location;
  8407. }
  8408. offset = GEN_INT (location);
  8409. emit_insn (gen (d->target, d->op0, d->op1, offset));
  8410. return true;
  8411. }
  8412. /* Recognize patterns for the REV insns. */
  8413. static bool
  8414. aarch64_evpc_rev (struct expand_vec_perm_d *d)
  8415. {
  8416. unsigned int i, j, diff, nelt = d->nelt;
  8417. rtx (*gen) (rtx, rtx);
  8418. if (!d->one_vector_p)
  8419. return false;
  8420. diff = d->perm[0];
  8421. switch (diff)
  8422. {
  8423. case 7:
  8424. switch (d->vmode)
  8425. {
  8426. case V16QImode: gen = gen_aarch64_rev64v16qi; break;
  8427. case V8QImode: gen = gen_aarch64_rev64v8qi; break;
  8428. default:
  8429. return false;
  8430. }
  8431. break;
  8432. case 3:
  8433. switch (d->vmode)
  8434. {
  8435. case V16QImode: gen = gen_aarch64_rev32v16qi; break;
  8436. case V8QImode: gen = gen_aarch64_rev32v8qi; break;
  8437. case V8HImode: gen = gen_aarch64_rev64v8hi; break;
  8438. case V4HImode: gen = gen_aarch64_rev64v4hi; break;
  8439. default:
  8440. return false;
  8441. }
  8442. break;
  8443. case 1:
  8444. switch (d->vmode)
  8445. {
  8446. case V16QImode: gen = gen_aarch64_rev16v16qi; break;
  8447. case V8QImode: gen = gen_aarch64_rev16v8qi; break;
  8448. case V8HImode: gen = gen_aarch64_rev32v8hi; break;
  8449. case V4HImode: gen = gen_aarch64_rev32v4hi; break;
  8450. case V4SImode: gen = gen_aarch64_rev64v4si; break;
  8451. case V2SImode: gen = gen_aarch64_rev64v2si; break;
  8452. case V4SFmode: gen = gen_aarch64_rev64v4sf; break;
  8453. case V2SFmode: gen = gen_aarch64_rev64v2sf; break;
  8454. default:
  8455. return false;
  8456. }
  8457. break;
  8458. default:
  8459. return false;
  8460. }
  8461. for (i = 0; i < nelt ; i += diff + 1)
  8462. for (j = 0; j <= diff; j += 1)
  8463. {
  8464. /* This is guaranteed to be true as the value of diff
  8465. is 7, 3, 1 and we should have enough elements in the
  8466. queue to generate this. Getting a vector mask with a
  8467. value of diff other than these values implies that
  8468. something is wrong by the time we get here. */
  8469. gcc_assert (i + j < nelt);
  8470. if (d->perm[i + j] != i + diff - j)
  8471. return false;
  8472. }
  8473. /* Success! */
  8474. if (d->testing_p)
  8475. return true;
  8476. emit_insn (gen (d->target, d->op0));
  8477. return true;
  8478. }
  8479. static bool
  8480. aarch64_evpc_dup (struct expand_vec_perm_d *d)
  8481. {
  8482. rtx (*gen) (rtx, rtx, rtx);
  8483. rtx out = d->target;
  8484. rtx in0;
  8485. machine_mode vmode = d->vmode;
  8486. unsigned int i, elt, nelt = d->nelt;
  8487. rtx lane;
  8488. elt = d->perm[0];
  8489. for (i = 1; i < nelt; i++)
  8490. {
  8491. if (elt != d->perm[i])
  8492. return false;
  8493. }
  8494. /* The generic preparation in aarch64_expand_vec_perm_const_1
  8495. swaps the operand order and the permute indices if it finds
  8496. d->perm[0] to be in the second operand. Thus, we can always
  8497. use d->op0 and need not do any extra arithmetic to get the
  8498. correct lane number. */
  8499. in0 = d->op0;
  8500. lane = GEN_INT (elt); /* The pattern corrects for big-endian. */
  8501. switch (vmode)
  8502. {
  8503. case V16QImode: gen = gen_aarch64_dup_lanev16qi; break;
  8504. case V8QImode: gen = gen_aarch64_dup_lanev8qi; break;
  8505. case V8HImode: gen = gen_aarch64_dup_lanev8hi; break;
  8506. case V4HImode: gen = gen_aarch64_dup_lanev4hi; break;
  8507. case V4SImode: gen = gen_aarch64_dup_lanev4si; break;
  8508. case V2SImode: gen = gen_aarch64_dup_lanev2si; break;
  8509. case V2DImode: gen = gen_aarch64_dup_lanev2di; break;
  8510. case V4SFmode: gen = gen_aarch64_dup_lanev4sf; break;
  8511. case V2SFmode: gen = gen_aarch64_dup_lanev2sf; break;
  8512. case V2DFmode: gen = gen_aarch64_dup_lanev2df; break;
  8513. default:
  8514. return false;
  8515. }
  8516. emit_insn (gen (out, in0, lane));
  8517. return true;
  8518. }
  8519. static bool
  8520. aarch64_evpc_tbl (struct expand_vec_perm_d *d)
  8521. {
  8522. rtx rperm[MAX_VECT_LEN], sel;
  8523. machine_mode vmode = d->vmode;
  8524. unsigned int i, nelt = d->nelt;
  8525. if (d->testing_p)
  8526. return true;
  8527. /* Generic code will try constant permutation twice. Once with the
  8528. original mode and again with the elements lowered to QImode.
  8529. So wait and don't do the selector expansion ourselves. */
  8530. if (vmode != V8QImode && vmode != V16QImode)
  8531. return false;
  8532. for (i = 0; i < nelt; ++i)
  8533. {
  8534. int nunits = GET_MODE_NUNITS (vmode);
  8535. /* If big-endian and two vectors we end up with a weird mixed-endian
  8536. mode on NEON. Reverse the index within each word but not the word
  8537. itself. */
  8538. rperm[i] = GEN_INT (BYTES_BIG_ENDIAN ? d->perm[i] ^ (nunits - 1)
  8539. : d->perm[i]);
  8540. }
  8541. sel = gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (nelt, rperm));
  8542. sel = force_reg (vmode, sel);
  8543. aarch64_expand_vec_perm_1 (d->target, d->op0, d->op1, sel);
  8544. return true;
  8545. }
  8546. static bool
  8547. aarch64_expand_vec_perm_const_1 (struct expand_vec_perm_d *d)
  8548. {
  8549. /* The pattern matching functions above are written to look for a small
  8550. number to begin the sequence (0, 1, N/2). If we begin with an index
  8551. from the second operand, we can swap the operands. */
  8552. if (d->perm[0] >= d->nelt)
  8553. {
  8554. unsigned i, nelt = d->nelt;
  8555. gcc_assert (nelt == (nelt & -nelt));
  8556. for (i = 0; i < nelt; ++i)
  8557. d->perm[i] ^= nelt; /* Keep the same index, but in the other vector. */
  8558. std::swap (d->op0, d->op1);
  8559. }
  8560. if (TARGET_SIMD)
  8561. {
  8562. if (aarch64_evpc_rev (d))
  8563. return true;
  8564. else if (aarch64_evpc_ext (d))
  8565. return true;
  8566. else if (aarch64_evpc_dup (d))
  8567. return true;
  8568. else if (aarch64_evpc_zip (d))
  8569. return true;
  8570. else if (aarch64_evpc_uzp (d))
  8571. return true;
  8572. else if (aarch64_evpc_trn (d))
  8573. return true;
  8574. return aarch64_evpc_tbl (d);
  8575. }
  8576. return false;
  8577. }
  8578. /* Expand a vec_perm_const pattern. */
  8579. bool
  8580. aarch64_expand_vec_perm_const (rtx target, rtx op0, rtx op1, rtx sel)
  8581. {
  8582. struct expand_vec_perm_d d;
  8583. int i, nelt, which;
  8584. d.target = target;
  8585. d.op0 = op0;
  8586. d.op1 = op1;
  8587. d.vmode = GET_MODE (target);
  8588. gcc_assert (VECTOR_MODE_P (d.vmode));
  8589. d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
  8590. d.testing_p = false;
  8591. for (i = which = 0; i < nelt; ++i)
  8592. {
  8593. rtx e = XVECEXP (sel, 0, i);
  8594. int ei = INTVAL (e) & (2 * nelt - 1);
  8595. which |= (ei < nelt ? 1 : 2);
  8596. d.perm[i] = ei;
  8597. }
  8598. switch (which)
  8599. {
  8600. default:
  8601. gcc_unreachable ();
  8602. case 3:
  8603. d.one_vector_p = false;
  8604. if (!rtx_equal_p (op0, op1))
  8605. break;
  8606. /* The elements of PERM do not suggest that only the first operand
  8607. is used, but both operands are identical. Allow easier matching
  8608. of the permutation by folding the permutation into the single
  8609. input vector. */
  8610. /* Fall Through. */
  8611. case 2:
  8612. for (i = 0; i < nelt; ++i)
  8613. d.perm[i] &= nelt - 1;
  8614. d.op0 = op1;
  8615. d.one_vector_p = true;
  8616. break;
  8617. case 1:
  8618. d.op1 = op0;
  8619. d.one_vector_p = true;
  8620. break;
  8621. }
  8622. return aarch64_expand_vec_perm_const_1 (&d);
  8623. }
  8624. static bool
  8625. aarch64_vectorize_vec_perm_const_ok (machine_mode vmode,
  8626. const unsigned char *sel)
  8627. {
  8628. struct expand_vec_perm_d d;
  8629. unsigned int i, nelt, which;
  8630. bool ret;
  8631. d.vmode = vmode;
  8632. d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
  8633. d.testing_p = true;
  8634. memcpy (d.perm, sel, nelt);
  8635. /* Calculate whether all elements are in one vector. */
  8636. for (i = which = 0; i < nelt; ++i)
  8637. {
  8638. unsigned char e = d.perm[i];
  8639. gcc_assert (e < 2 * nelt);
  8640. which |= (e < nelt ? 1 : 2);
  8641. }
  8642. /* If all elements are from the second vector, reindex as if from the
  8643. first vector. */
  8644. if (which == 2)
  8645. for (i = 0; i < nelt; ++i)
  8646. d.perm[i] -= nelt;
  8647. /* Check whether the mask can be applied to a single vector. */
  8648. d.one_vector_p = (which != 3);
  8649. d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1);
  8650. d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2);
  8651. if (!d.one_vector_p)
  8652. d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3);
  8653. start_sequence ();
  8654. ret = aarch64_expand_vec_perm_const_1 (&d);
  8655. end_sequence ();
  8656. return ret;
  8657. }
  8658. rtx
  8659. aarch64_reverse_mask (enum machine_mode mode)
  8660. {
  8661. /* We have to reverse each vector because we dont have
  8662. a permuted load that can reverse-load according to ABI rules. */
  8663. rtx mask;
  8664. rtvec v = rtvec_alloc (16);
  8665. int i, j;
  8666. int nunits = GET_MODE_NUNITS (mode);
  8667. int usize = GET_MODE_UNIT_SIZE (mode);
  8668. gcc_assert (BYTES_BIG_ENDIAN);
  8669. gcc_assert (AARCH64_VALID_SIMD_QREG_MODE (mode));
  8670. for (i = 0; i < nunits; i++)
  8671. for (j = 0; j < usize; j++)
  8672. RTVEC_ELT (v, i * usize + j) = GEN_INT ((i + 1) * usize - 1 - j);
  8673. mask = gen_rtx_CONST_VECTOR (V16QImode, v);
  8674. return force_reg (V16QImode, mask);
  8675. }
  8676. /* Implement MODES_TIEABLE_P. */
  8677. bool
  8678. aarch64_modes_tieable_p (machine_mode mode1, machine_mode mode2)
  8679. {
  8680. if (GET_MODE_CLASS (mode1) == GET_MODE_CLASS (mode2))
  8681. return true;
  8682. /* We specifically want to allow elements of "structure" modes to
  8683. be tieable to the structure. This more general condition allows
  8684. other rarer situations too. */
  8685. if (TARGET_SIMD
  8686. && aarch64_vector_mode_p (mode1)
  8687. && aarch64_vector_mode_p (mode2))
  8688. return true;
  8689. return false;
  8690. }
  8691. /* Return a new RTX holding the result of moving POINTER forward by
  8692. AMOUNT bytes. */
  8693. static rtx
  8694. aarch64_move_pointer (rtx pointer, int amount)
  8695. {
  8696. rtx next = plus_constant (Pmode, XEXP (pointer, 0), amount);
  8697. return adjust_automodify_address (pointer, GET_MODE (pointer),
  8698. next, amount);
  8699. }
  8700. /* Return a new RTX holding the result of moving POINTER forward by the
  8701. size of the mode it points to. */
  8702. static rtx
  8703. aarch64_progress_pointer (rtx pointer)
  8704. {
  8705. HOST_WIDE_INT amount = GET_MODE_SIZE (GET_MODE (pointer));
  8706. return aarch64_move_pointer (pointer, amount);
  8707. }
  8708. /* Copy one MODE sized block from SRC to DST, then progress SRC and DST by
  8709. MODE bytes. */
  8710. static void
  8711. aarch64_copy_one_block_and_progress_pointers (rtx *src, rtx *dst,
  8712. machine_mode mode)
  8713. {
  8714. rtx reg = gen_reg_rtx (mode);
  8715. /* "Cast" the pointers to the correct mode. */
  8716. *src = adjust_address (*src, mode, 0);
  8717. *dst = adjust_address (*dst, mode, 0);
  8718. /* Emit the memcpy. */
  8719. emit_move_insn (reg, *src);
  8720. emit_move_insn (*dst, reg);
  8721. /* Move the pointers forward. */
  8722. *src = aarch64_progress_pointer (*src);
  8723. *dst = aarch64_progress_pointer (*dst);
  8724. }
  8725. /* Expand movmem, as if from a __builtin_memcpy. Return true if
  8726. we succeed, otherwise return false. */
  8727. bool
  8728. aarch64_expand_movmem (rtx *operands)
  8729. {
  8730. unsigned int n;
  8731. rtx dst = operands[0];
  8732. rtx src = operands[1];
  8733. rtx base;
  8734. bool speed_p = !optimize_function_for_size_p (cfun);
  8735. /* When optimizing for size, give a better estimate of the length of a
  8736. memcpy call, but use the default otherwise. */
  8737. unsigned int max_instructions = (speed_p ? 15 : AARCH64_CALL_RATIO) / 2;
  8738. /* We can't do anything smart if the amount to copy is not constant. */
  8739. if (!CONST_INT_P (operands[2]))
  8740. return false;
  8741. n = UINTVAL (operands[2]);
  8742. /* Try to keep the number of instructions low. For cases below 16 bytes we
  8743. need to make at most two moves. For cases above 16 bytes it will be one
  8744. move for each 16 byte chunk, then at most two additional moves. */
  8745. if (((n / 16) + (n % 16 ? 2 : 0)) > max_instructions)
  8746. return false;
  8747. base = copy_to_mode_reg (Pmode, XEXP (dst, 0));
  8748. dst = adjust_automodify_address (dst, VOIDmode, base, 0);
  8749. base = copy_to_mode_reg (Pmode, XEXP (src, 0));
  8750. src = adjust_automodify_address (src, VOIDmode, base, 0);
  8751. /* Simple cases. Copy 0-3 bytes, as (if applicable) a 2-byte, then a
  8752. 1-byte chunk. */
  8753. if (n < 4)
  8754. {
  8755. if (n >= 2)
  8756. {
  8757. aarch64_copy_one_block_and_progress_pointers (&src, &dst, HImode);
  8758. n -= 2;
  8759. }
  8760. if (n == 1)
  8761. aarch64_copy_one_block_and_progress_pointers (&src, &dst, QImode);
  8762. return true;
  8763. }
  8764. /* Copy 4-8 bytes. First a 4-byte chunk, then (if applicable) a second
  8765. 4-byte chunk, partially overlapping with the previously copied chunk. */
  8766. if (n < 8)
  8767. {
  8768. aarch64_copy_one_block_and_progress_pointers (&src, &dst, SImode);
  8769. n -= 4;
  8770. if (n > 0)
  8771. {
  8772. int move = n - 4;
  8773. src = aarch64_move_pointer (src, move);
  8774. dst = aarch64_move_pointer (dst, move);
  8775. aarch64_copy_one_block_and_progress_pointers (&src, &dst, SImode);
  8776. }
  8777. return true;
  8778. }
  8779. /* Copy more than 8 bytes. Copy chunks of 16 bytes until we run out of
  8780. them, then (if applicable) an 8-byte chunk. */
  8781. while (n >= 8)
  8782. {
  8783. if (n / 16)
  8784. {
  8785. aarch64_copy_one_block_and_progress_pointers (&src, &dst, TImode);
  8786. n -= 16;
  8787. }
  8788. else
  8789. {
  8790. aarch64_copy_one_block_and_progress_pointers (&src, &dst, DImode);
  8791. n -= 8;
  8792. }
  8793. }
  8794. /* Finish the final bytes of the copy. We can always do this in one
  8795. instruction. We either copy the exact amount we need, or partially
  8796. overlap with the previous chunk we copied and copy 8-bytes. */
  8797. if (n == 0)
  8798. return true;
  8799. else if (n == 1)
  8800. aarch64_copy_one_block_and_progress_pointers (&src, &dst, QImode);
  8801. else if (n == 2)
  8802. aarch64_copy_one_block_and_progress_pointers (&src, &dst, HImode);
  8803. else if (n == 4)
  8804. aarch64_copy_one_block_and_progress_pointers (&src, &dst, SImode);
  8805. else
  8806. {
  8807. if (n == 3)
  8808. {
  8809. src = aarch64_move_pointer (src, -1);
  8810. dst = aarch64_move_pointer (dst, -1);
  8811. aarch64_copy_one_block_and_progress_pointers (&src, &dst, SImode);
  8812. }
  8813. else
  8814. {
  8815. int move = n - 8;
  8816. src = aarch64_move_pointer (src, move);
  8817. dst = aarch64_move_pointer (dst, move);
  8818. aarch64_copy_one_block_and_progress_pointers (&src, &dst, DImode);
  8819. }
  8820. }
  8821. return true;
  8822. }
  8823. /* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */
  8824. static unsigned HOST_WIDE_INT
  8825. aarch64_asan_shadow_offset (void)
  8826. {
  8827. return (HOST_WIDE_INT_1 << 36);
  8828. }
  8829. static bool
  8830. aarch64_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size,
  8831. unsigned int align,
  8832. enum by_pieces_operation op,
  8833. bool speed_p)
  8834. {
  8835. /* STORE_BY_PIECES can be used when copying a constant string, but
  8836. in that case each 64-bit chunk takes 5 insns instead of 2 (LDR/STR).
  8837. For now we always fail this and let the move_by_pieces code copy
  8838. the string from read-only memory. */
  8839. if (op == STORE_BY_PIECES)
  8840. return false;
  8841. return default_use_by_pieces_infrastructure_p (size, align, op, speed_p);
  8842. }
  8843. static enum machine_mode
  8844. aarch64_code_to_ccmode (enum rtx_code code)
  8845. {
  8846. switch (code)
  8847. {
  8848. case NE:
  8849. return CC_DNEmode;
  8850. case EQ:
  8851. return CC_DEQmode;
  8852. case LE:
  8853. return CC_DLEmode;
  8854. case LT:
  8855. return CC_DLTmode;
  8856. case GE:
  8857. return CC_DGEmode;
  8858. case GT:
  8859. return CC_DGTmode;
  8860. case LEU:
  8861. return CC_DLEUmode;
  8862. case LTU:
  8863. return CC_DLTUmode;
  8864. case GEU:
  8865. return CC_DGEUmode;
  8866. case GTU:
  8867. return CC_DGTUmode;
  8868. default:
  8869. return CCmode;
  8870. }
  8871. }
  8872. static rtx
  8873. aarch64_gen_ccmp_first (rtx *prep_seq, rtx *gen_seq,
  8874. int code, tree treeop0, tree treeop1)
  8875. {
  8876. enum machine_mode op_mode, cmp_mode, cc_mode;
  8877. rtx op0, op1, cmp, target;
  8878. int unsignedp = TYPE_UNSIGNED (TREE_TYPE (treeop0));
  8879. enum insn_code icode;
  8880. struct expand_operand ops[4];
  8881. cc_mode = aarch64_code_to_ccmode ((enum rtx_code) code);
  8882. if (cc_mode == CCmode)
  8883. return NULL_RTX;
  8884. start_sequence ();
  8885. expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  8886. op_mode = GET_MODE (op0);
  8887. if (op_mode == VOIDmode)
  8888. op_mode = GET_MODE (op1);
  8889. switch (op_mode)
  8890. {
  8891. case QImode:
  8892. case HImode:
  8893. case SImode:
  8894. cmp_mode = SImode;
  8895. icode = CODE_FOR_cmpsi;
  8896. break;
  8897. case DImode:
  8898. cmp_mode = DImode;
  8899. icode = CODE_FOR_cmpdi;
  8900. break;
  8901. default:
  8902. end_sequence ();
  8903. return NULL_RTX;
  8904. }
  8905. op0 = prepare_operand (icode, op0, 2, op_mode, cmp_mode, unsignedp);
  8906. op1 = prepare_operand (icode, op1, 3, op_mode, cmp_mode, unsignedp);
  8907. if (!op0 || !op1)
  8908. {
  8909. end_sequence ();
  8910. return NULL_RTX;
  8911. }
  8912. *prep_seq = get_insns ();
  8913. end_sequence ();
  8914. cmp = gen_rtx_fmt_ee ((enum rtx_code) code, cmp_mode, op0, op1);
  8915. target = gen_rtx_REG (CCmode, CC_REGNUM);
  8916. create_output_operand (&ops[0], target, CCmode);
  8917. create_fixed_operand (&ops[1], cmp);
  8918. create_fixed_operand (&ops[2], op0);
  8919. create_fixed_operand (&ops[3], op1);
  8920. start_sequence ();
  8921. if (!maybe_expand_insn (icode, 4, ops))
  8922. {
  8923. end_sequence ();
  8924. return NULL_RTX;
  8925. }
  8926. *gen_seq = get_insns ();
  8927. end_sequence ();
  8928. return gen_rtx_REG (cc_mode, CC_REGNUM);
  8929. }
  8930. static rtx
  8931. aarch64_gen_ccmp_next (rtx *prep_seq, rtx *gen_seq, rtx prev, int cmp_code,
  8932. tree treeop0, tree treeop1, int bit_code)
  8933. {
  8934. rtx op0, op1, cmp0, cmp1, target;
  8935. enum machine_mode op_mode, cmp_mode, cc_mode;
  8936. int unsignedp = TYPE_UNSIGNED (TREE_TYPE (treeop0));
  8937. enum insn_code icode = CODE_FOR_ccmp_andsi;
  8938. struct expand_operand ops[6];
  8939. cc_mode = aarch64_code_to_ccmode ((enum rtx_code) cmp_code);
  8940. if (cc_mode == CCmode)
  8941. return NULL_RTX;
  8942. push_to_sequence ((rtx_insn*) *prep_seq);
  8943. expand_operands (treeop0, treeop1, NULL_RTX, &op0, &op1, EXPAND_NORMAL);
  8944. op_mode = GET_MODE (op0);
  8945. if (op_mode == VOIDmode)
  8946. op_mode = GET_MODE (op1);
  8947. switch (op_mode)
  8948. {
  8949. case QImode:
  8950. case HImode:
  8951. case SImode:
  8952. cmp_mode = SImode;
  8953. icode = (enum rtx_code) bit_code == AND ? CODE_FOR_ccmp_andsi
  8954. : CODE_FOR_ccmp_iorsi;
  8955. break;
  8956. case DImode:
  8957. cmp_mode = DImode;
  8958. icode = (enum rtx_code) bit_code == AND ? CODE_FOR_ccmp_anddi
  8959. : CODE_FOR_ccmp_iordi;
  8960. break;
  8961. default:
  8962. end_sequence ();
  8963. return NULL_RTX;
  8964. }
  8965. op0 = prepare_operand (icode, op0, 2, op_mode, cmp_mode, unsignedp);
  8966. op1 = prepare_operand (icode, op1, 3, op_mode, cmp_mode, unsignedp);
  8967. if (!op0 || !op1)
  8968. {
  8969. end_sequence ();
  8970. return NULL_RTX;
  8971. }
  8972. *prep_seq = get_insns ();
  8973. end_sequence ();
  8974. target = gen_rtx_REG (cc_mode, CC_REGNUM);
  8975. cmp1 = gen_rtx_fmt_ee ((enum rtx_code) cmp_code, cmp_mode, op0, op1);
  8976. cmp0 = gen_rtx_fmt_ee (NE, cmp_mode, prev, const0_rtx);
  8977. create_fixed_operand (&ops[0], prev);
  8978. create_fixed_operand (&ops[1], target);
  8979. create_fixed_operand (&ops[2], op0);
  8980. create_fixed_operand (&ops[3], op1);
  8981. create_fixed_operand (&ops[4], cmp0);
  8982. create_fixed_operand (&ops[5], cmp1);
  8983. push_to_sequence ((rtx_insn*) *gen_seq);
  8984. if (!maybe_expand_insn (icode, 6, ops))
  8985. {
  8986. end_sequence ();
  8987. return NULL_RTX;
  8988. }
  8989. *gen_seq = get_insns ();
  8990. end_sequence ();
  8991. return target;
  8992. }
  8993. #undef TARGET_GEN_CCMP_FIRST
  8994. #define TARGET_GEN_CCMP_FIRST aarch64_gen_ccmp_first
  8995. #undef TARGET_GEN_CCMP_NEXT
  8996. #define TARGET_GEN_CCMP_NEXT aarch64_gen_ccmp_next
  8997. /* Implement TARGET_SCHED_MACRO_FUSION_P. Return true if target supports
  8998. instruction fusion of some sort. */
  8999. static bool
  9000. aarch64_macro_fusion_p (void)
  9001. {
  9002. return aarch64_tune_params->fuseable_ops != AARCH64_FUSE_NOTHING;
  9003. }
  9004. /* Implement TARGET_SCHED_MACRO_FUSION_PAIR_P. Return true if PREV and CURR
  9005. should be kept together during scheduling. */
  9006. static bool
  9007. aarch_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr)
  9008. {
  9009. rtx set_dest;
  9010. rtx prev_set = single_set (prev);
  9011. rtx curr_set = single_set (curr);
  9012. /* prev and curr are simple SET insns i.e. no flag setting or branching. */
  9013. bool simple_sets_p = prev_set && curr_set && !any_condjump_p (curr);
  9014. if (!aarch64_macro_fusion_p ())
  9015. return false;
  9016. if (simple_sets_p
  9017. && (aarch64_tune_params->fuseable_ops & AARCH64_FUSE_MOV_MOVK))
  9018. {
  9019. /* We are trying to match:
  9020. prev (mov) == (set (reg r0) (const_int imm16))
  9021. curr (movk) == (set (zero_extract (reg r0)
  9022. (const_int 16)
  9023. (const_int 16))
  9024. (const_int imm16_1)) */
  9025. set_dest = SET_DEST (curr_set);
  9026. if (GET_CODE (set_dest) == ZERO_EXTRACT
  9027. && CONST_INT_P (SET_SRC (curr_set))
  9028. && CONST_INT_P (SET_SRC (prev_set))
  9029. && CONST_INT_P (XEXP (set_dest, 2))
  9030. && INTVAL (XEXP (set_dest, 2)) == 16
  9031. && REG_P (XEXP (set_dest, 0))
  9032. && REG_P (SET_DEST (prev_set))
  9033. && REGNO (XEXP (set_dest, 0)) == REGNO (SET_DEST (prev_set)))
  9034. {
  9035. return true;
  9036. }
  9037. }
  9038. if (simple_sets_p
  9039. && (aarch64_tune_params->fuseable_ops & AARCH64_FUSE_ADRP_ADD))
  9040. {
  9041. /* We're trying to match:
  9042. prev (adrp) == (set (reg r1)
  9043. (high (symbol_ref ("SYM"))))
  9044. curr (add) == (set (reg r0)
  9045. (lo_sum (reg r1)
  9046. (symbol_ref ("SYM"))))
  9047. Note that r0 need not necessarily be the same as r1, especially
  9048. during pre-regalloc scheduling. */
  9049. if (satisfies_constraint_Ush (SET_SRC (prev_set))
  9050. && REG_P (SET_DEST (prev_set)) && REG_P (SET_DEST (curr_set)))
  9051. {
  9052. if (GET_CODE (SET_SRC (curr_set)) == LO_SUM
  9053. && REG_P (XEXP (SET_SRC (curr_set), 0))
  9054. && REGNO (XEXP (SET_SRC (curr_set), 0))
  9055. == REGNO (SET_DEST (prev_set))
  9056. && rtx_equal_p (XEXP (SET_SRC (prev_set), 0),
  9057. XEXP (SET_SRC (curr_set), 1)))
  9058. return true;
  9059. }
  9060. }
  9061. if (simple_sets_p
  9062. && (aarch64_tune_params->fuseable_ops & AARCH64_FUSE_MOVK_MOVK))
  9063. {
  9064. /* We're trying to match:
  9065. prev (movk) == (set (zero_extract (reg r0)
  9066. (const_int 16)
  9067. (const_int 32))
  9068. (const_int imm16_1))
  9069. curr (movk) == (set (zero_extract (reg r0)
  9070. (const_int 16)
  9071. (const_int 48))
  9072. (const_int imm16_2)) */
  9073. if (GET_CODE (SET_DEST (prev_set)) == ZERO_EXTRACT
  9074. && GET_CODE (SET_DEST (curr_set)) == ZERO_EXTRACT
  9075. && REG_P (XEXP (SET_DEST (prev_set), 0))
  9076. && REG_P (XEXP (SET_DEST (curr_set), 0))
  9077. && REGNO (XEXP (SET_DEST (prev_set), 0))
  9078. == REGNO (XEXP (SET_DEST (curr_set), 0))
  9079. && CONST_INT_P (XEXP (SET_DEST (prev_set), 2))
  9080. && CONST_INT_P (XEXP (SET_DEST (curr_set), 2))
  9081. && INTVAL (XEXP (SET_DEST (prev_set), 2)) == 32
  9082. && INTVAL (XEXP (SET_DEST (curr_set), 2)) == 48
  9083. && CONST_INT_P (SET_SRC (prev_set))
  9084. && CONST_INT_P (SET_SRC (curr_set)))
  9085. return true;
  9086. }
  9087. if (simple_sets_p
  9088. && (aarch64_tune_params->fuseable_ops & AARCH64_FUSE_ADRP_LDR))
  9089. {
  9090. /* We're trying to match:
  9091. prev (adrp) == (set (reg r0)
  9092. (high (symbol_ref ("SYM"))))
  9093. curr (ldr) == (set (reg r1)
  9094. (mem (lo_sum (reg r0)
  9095. (symbol_ref ("SYM")))))
  9096. or
  9097. curr (ldr) == (set (reg r1)
  9098. (zero_extend (mem
  9099. (lo_sum (reg r0)
  9100. (symbol_ref ("SYM")))))) */
  9101. if (satisfies_constraint_Ush (SET_SRC (prev_set))
  9102. && REG_P (SET_DEST (prev_set)) && REG_P (SET_DEST (curr_set)))
  9103. {
  9104. rtx curr_src = SET_SRC (curr_set);
  9105. if (GET_CODE (curr_src) == ZERO_EXTEND)
  9106. curr_src = XEXP (curr_src, 0);
  9107. if (MEM_P (curr_src) && GET_CODE (XEXP (curr_src, 0)) == LO_SUM
  9108. && REG_P (XEXP (XEXP (curr_src, 0), 0))
  9109. && REGNO (XEXP (XEXP (curr_src, 0), 0))
  9110. == REGNO (SET_DEST (prev_set))
  9111. && rtx_equal_p (XEXP (XEXP (curr_src, 0), 1),
  9112. XEXP (SET_SRC (prev_set), 0)))
  9113. return true;
  9114. }
  9115. }
  9116. if ((aarch64_tune_params->fuseable_ops & AARCH64_FUSE_CMP_BRANCH)
  9117. && any_condjump_p (curr))
  9118. {
  9119. enum attr_type prev_type = get_attr_type (prev);
  9120. /* FIXME: this misses some which is considered simple arthematic
  9121. instructions for ThunderX. Simple shifts are missed here. */
  9122. if (prev_type == TYPE_ALUS_SREG
  9123. || prev_type == TYPE_ALUS_IMM
  9124. || prev_type == TYPE_LOGICS_REG
  9125. || prev_type == TYPE_LOGICS_IMM)
  9126. return true;
  9127. }
  9128. return false;
  9129. }
  9130. /* If MEM is in the form of [base+offset], extract the two parts
  9131. of address and set to BASE and OFFSET, otherwise return false
  9132. after clearing BASE and OFFSET. */
  9133. bool
  9134. extract_base_offset_in_addr (rtx mem, rtx *base, rtx *offset)
  9135. {
  9136. rtx addr;
  9137. gcc_assert (MEM_P (mem));
  9138. addr = XEXP (mem, 0);
  9139. if (REG_P (addr))
  9140. {
  9141. *base = addr;
  9142. *offset = const0_rtx;
  9143. return true;
  9144. }
  9145. if (GET_CODE (addr) == PLUS
  9146. && REG_P (XEXP (addr, 0)) && CONST_INT_P (XEXP (addr, 1)))
  9147. {
  9148. *base = XEXP (addr, 0);
  9149. *offset = XEXP (addr, 1);
  9150. return true;
  9151. }
  9152. *base = NULL_RTX;
  9153. *offset = NULL_RTX;
  9154. return false;
  9155. }
  9156. /* Types for scheduling fusion. */
  9157. enum sched_fusion_type
  9158. {
  9159. SCHED_FUSION_NONE = 0,
  9160. SCHED_FUSION_LD_SIGN_EXTEND,
  9161. SCHED_FUSION_LD_ZERO_EXTEND,
  9162. SCHED_FUSION_LD,
  9163. SCHED_FUSION_ST,
  9164. SCHED_FUSION_NUM
  9165. };
  9166. /* If INSN is a load or store of address in the form of [base+offset],
  9167. extract the two parts and set to BASE and OFFSET. Return scheduling
  9168. fusion type this INSN is. */
  9169. static enum sched_fusion_type
  9170. fusion_load_store (rtx_insn *insn, rtx *base, rtx *offset)
  9171. {
  9172. rtx x, dest, src;
  9173. enum sched_fusion_type fusion = SCHED_FUSION_LD;
  9174. gcc_assert (INSN_P (insn));
  9175. x = PATTERN (insn);
  9176. if (GET_CODE (x) != SET)
  9177. return SCHED_FUSION_NONE;
  9178. src = SET_SRC (x);
  9179. dest = SET_DEST (x);
  9180. if (GET_MODE (dest) != SImode && GET_MODE (dest) != DImode
  9181. && GET_MODE (dest) != SFmode && GET_MODE (dest) != DFmode)
  9182. return SCHED_FUSION_NONE;
  9183. if (GET_CODE (src) == SIGN_EXTEND)
  9184. {
  9185. fusion = SCHED_FUSION_LD_SIGN_EXTEND;
  9186. src = XEXP (src, 0);
  9187. if (GET_CODE (src) != MEM || GET_MODE (src) != SImode)
  9188. return SCHED_FUSION_NONE;
  9189. }
  9190. else if (GET_CODE (src) == ZERO_EXTEND)
  9191. {
  9192. fusion = SCHED_FUSION_LD_ZERO_EXTEND;
  9193. src = XEXP (src, 0);
  9194. if (GET_CODE (src) != MEM || GET_MODE (src) != SImode)
  9195. return SCHED_FUSION_NONE;
  9196. }
  9197. if (GET_CODE (src) == MEM && REG_P (dest))
  9198. extract_base_offset_in_addr (src, base, offset);
  9199. else if (GET_CODE (dest) == MEM && (REG_P (src) || src == const0_rtx))
  9200. {
  9201. fusion = SCHED_FUSION_ST;
  9202. extract_base_offset_in_addr (dest, base, offset);
  9203. }
  9204. else
  9205. return SCHED_FUSION_NONE;
  9206. if (*base == NULL_RTX || *offset == NULL_RTX)
  9207. fusion = SCHED_FUSION_NONE;
  9208. return fusion;
  9209. }
  9210. /* Implement the TARGET_SCHED_FUSION_PRIORITY hook.
  9211. Currently we only support to fuse ldr or str instructions, so FUSION_PRI
  9212. and PRI are only calculated for these instructions. For other instruction,
  9213. FUSION_PRI and PRI are simply set to MAX_PRI - 1. In the future, other
  9214. type instruction fusion can be added by returning different priorities.
  9215. It's important that irrelevant instructions get the largest FUSION_PRI. */
  9216. static void
  9217. aarch64_sched_fusion_priority (rtx_insn *insn, int max_pri,
  9218. int *fusion_pri, int *pri)
  9219. {
  9220. int tmp, off_val;
  9221. rtx base, offset;
  9222. enum sched_fusion_type fusion;
  9223. gcc_assert (INSN_P (insn));
  9224. tmp = max_pri - 1;
  9225. fusion = fusion_load_store (insn, &base, &offset);
  9226. if (fusion == SCHED_FUSION_NONE)
  9227. {
  9228. *pri = tmp;
  9229. *fusion_pri = tmp;
  9230. return;
  9231. }
  9232. /* Set FUSION_PRI according to fusion type and base register. */
  9233. *fusion_pri = tmp - fusion * FIRST_PSEUDO_REGISTER - REGNO (base);
  9234. /* Calculate PRI. */
  9235. tmp /= 2;
  9236. /* INSN with smaller offset goes first. */
  9237. off_val = (int)(INTVAL (offset));
  9238. if (off_val >= 0)
  9239. tmp -= (off_val & 0xfffff);
  9240. else
  9241. tmp += ((- off_val) & 0xfffff);
  9242. *pri = tmp;
  9243. return;
  9244. }
  9245. /* Given OPERANDS of consecutive load/store, check if we can merge
  9246. them into ldp/stp. LOAD is true if they are load instructions.
  9247. MODE is the mode of memory operands. */
  9248. bool
  9249. aarch64_operands_ok_for_ldpstp (rtx *operands, bool load,
  9250. enum machine_mode mode)
  9251. {
  9252. HOST_WIDE_INT offval_1, offval_2, msize;
  9253. enum reg_class rclass_1, rclass_2;
  9254. rtx mem_1, mem_2, reg_1, reg_2, base_1, base_2, offset_1, offset_2;
  9255. if (load)
  9256. {
  9257. mem_1 = operands[1];
  9258. mem_2 = operands[3];
  9259. reg_1 = operands[0];
  9260. reg_2 = operands[2];
  9261. gcc_assert (REG_P (reg_1) && REG_P (reg_2));
  9262. if (REGNO (reg_1) == REGNO (reg_2))
  9263. return false;
  9264. }
  9265. else
  9266. {
  9267. mem_1 = operands[0];
  9268. mem_2 = operands[2];
  9269. reg_1 = operands[1];
  9270. reg_2 = operands[3];
  9271. }
  9272. /* The mems cannot be volatile. */
  9273. if (MEM_VOLATILE_P (mem_1) || MEM_VOLATILE_P (mem_2))
  9274. return false;
  9275. /* Check if the addresses are in the form of [base+offset]. */
  9276. extract_base_offset_in_addr (mem_1, &base_1, &offset_1);
  9277. if (base_1 == NULL_RTX || offset_1 == NULL_RTX)
  9278. return false;
  9279. extract_base_offset_in_addr (mem_2, &base_2, &offset_2);
  9280. if (base_2 == NULL_RTX || offset_2 == NULL_RTX)
  9281. return false;
  9282. /* Check if the bases are same. */
  9283. if (!rtx_equal_p (base_1, base_2))
  9284. return false;
  9285. offval_1 = INTVAL (offset_1);
  9286. offval_2 = INTVAL (offset_2);
  9287. msize = GET_MODE_SIZE (mode);
  9288. /* Check if the offsets are consecutive. */
  9289. if (offval_1 != (offval_2 + msize) && offval_2 != (offval_1 + msize))
  9290. return false;
  9291. /* Check if the addresses are clobbered by load. */
  9292. if (load)
  9293. {
  9294. if (reg_mentioned_p (reg_1, mem_1))
  9295. return false;
  9296. /* In increasing order, the last load can clobber the address. */
  9297. if (offval_1 > offval_2 && reg_mentioned_p (reg_2, mem_2))
  9298. return false;
  9299. }
  9300. if (REG_P (reg_1) && FP_REGNUM_P (REGNO (reg_1)))
  9301. rclass_1 = FP_REGS;
  9302. else
  9303. rclass_1 = GENERAL_REGS;
  9304. if (REG_P (reg_2) && FP_REGNUM_P (REGNO (reg_2)))
  9305. rclass_2 = FP_REGS;
  9306. else
  9307. rclass_2 = GENERAL_REGS;
  9308. /* Check if the registers are of same class. */
  9309. if (rclass_1 != rclass_2)
  9310. return false;
  9311. return true;
  9312. }
  9313. /* Given OPERANDS of consecutive load/store, check if we can merge
  9314. them into ldp/stp by adjusting the offset. LOAD is true if they
  9315. are load instructions. MODE is the mode of memory operands.
  9316. Given below consecutive stores:
  9317. str w1, [xb, 0x100]
  9318. str w1, [xb, 0x104]
  9319. str w1, [xb, 0x108]
  9320. str w1, [xb, 0x10c]
  9321. Though the offsets are out of the range supported by stp, we can
  9322. still pair them after adjusting the offset, like:
  9323. add scratch, xb, 0x100
  9324. stp w1, w1, [scratch]
  9325. stp w1, w1, [scratch, 0x8]
  9326. The peephole patterns detecting this opportunity should guarantee
  9327. the scratch register is avaliable. */
  9328. bool
  9329. aarch64_operands_adjust_ok_for_ldpstp (rtx *operands, bool load,
  9330. enum machine_mode mode)
  9331. {
  9332. enum reg_class rclass_1, rclass_2, rclass_3, rclass_4;
  9333. HOST_WIDE_INT offval_1, offval_2, offval_3, offval_4, msize;
  9334. rtx mem_1, mem_2, mem_3, mem_4, reg_1, reg_2, reg_3, reg_4;
  9335. rtx base_1, base_2, base_3, base_4, offset_1, offset_2, offset_3, offset_4;
  9336. if (load)
  9337. {
  9338. reg_1 = operands[0];
  9339. mem_1 = operands[1];
  9340. reg_2 = operands[2];
  9341. mem_2 = operands[3];
  9342. reg_3 = operands[4];
  9343. mem_3 = operands[5];
  9344. reg_4 = operands[6];
  9345. mem_4 = operands[7];
  9346. gcc_assert (REG_P (reg_1) && REG_P (reg_2)
  9347. && REG_P (reg_3) && REG_P (reg_4));
  9348. if (REGNO (reg_1) == REGNO (reg_2) || REGNO (reg_3) == REGNO (reg_4))
  9349. return false;
  9350. }
  9351. else
  9352. {
  9353. mem_1 = operands[0];
  9354. reg_1 = operands[1];
  9355. mem_2 = operands[2];
  9356. reg_2 = operands[3];
  9357. mem_3 = operands[4];
  9358. reg_3 = operands[5];
  9359. mem_4 = operands[6];
  9360. reg_4 = operands[7];
  9361. }
  9362. /* Skip if memory operand is by itslef valid for ldp/stp. */
  9363. if (!MEM_P (mem_1) || aarch64_mem_pair_operand (mem_1, mode))
  9364. return false;
  9365. /* The mems cannot be volatile. */
  9366. if (MEM_VOLATILE_P (mem_1) || MEM_VOLATILE_P (mem_2)
  9367. || MEM_VOLATILE_P (mem_3) ||MEM_VOLATILE_P (mem_4))
  9368. return false;
  9369. /* Check if the addresses are in the form of [base+offset]. */
  9370. extract_base_offset_in_addr (mem_1, &base_1, &offset_1);
  9371. if (base_1 == NULL_RTX || offset_1 == NULL_RTX)
  9372. return false;
  9373. extract_base_offset_in_addr (mem_2, &base_2, &offset_2);
  9374. if (base_2 == NULL_RTX || offset_2 == NULL_RTX)
  9375. return false;
  9376. extract_base_offset_in_addr (mem_3, &base_3, &offset_3);
  9377. if (base_3 == NULL_RTX || offset_3 == NULL_RTX)
  9378. return false;
  9379. extract_base_offset_in_addr (mem_4, &base_4, &offset_4);
  9380. if (base_4 == NULL_RTX || offset_4 == NULL_RTX)
  9381. return false;
  9382. /* Check if the bases are same. */
  9383. if (!rtx_equal_p (base_1, base_2)
  9384. || !rtx_equal_p (base_2, base_3)
  9385. || !rtx_equal_p (base_3, base_4))
  9386. return false;
  9387. offval_1 = INTVAL (offset_1);
  9388. offval_2 = INTVAL (offset_2);
  9389. offval_3 = INTVAL (offset_3);
  9390. offval_4 = INTVAL (offset_4);
  9391. msize = GET_MODE_SIZE (mode);
  9392. /* Check if the offsets are consecutive. */
  9393. if ((offval_1 != (offval_2 + msize)
  9394. || offval_1 != (offval_3 + msize * 2)
  9395. || offval_1 != (offval_4 + msize * 3))
  9396. && (offval_4 != (offval_3 + msize)
  9397. || offval_4 != (offval_2 + msize * 2)
  9398. || offval_4 != (offval_1 + msize * 3)))
  9399. return false;
  9400. /* Check if the addresses are clobbered by load. */
  9401. if (load)
  9402. {
  9403. if (reg_mentioned_p (reg_1, mem_1)
  9404. || reg_mentioned_p (reg_2, mem_2)
  9405. || reg_mentioned_p (reg_3, mem_3))
  9406. return false;
  9407. /* In increasing order, the last load can clobber the address. */
  9408. if (offval_1 > offval_2 && reg_mentioned_p (reg_4, mem_4))
  9409. return false;
  9410. }
  9411. if (REG_P (reg_1) && FP_REGNUM_P (REGNO (reg_1)))
  9412. rclass_1 = FP_REGS;
  9413. else
  9414. rclass_1 = GENERAL_REGS;
  9415. if (REG_P (reg_2) && FP_REGNUM_P (REGNO (reg_2)))
  9416. rclass_2 = FP_REGS;
  9417. else
  9418. rclass_2 = GENERAL_REGS;
  9419. if (REG_P (reg_3) && FP_REGNUM_P (REGNO (reg_3)))
  9420. rclass_3 = FP_REGS;
  9421. else
  9422. rclass_3 = GENERAL_REGS;
  9423. if (REG_P (reg_4) && FP_REGNUM_P (REGNO (reg_4)))
  9424. rclass_4 = FP_REGS;
  9425. else
  9426. rclass_4 = GENERAL_REGS;
  9427. /* Check if the registers are of same class. */
  9428. if (rclass_1 != rclass_2 || rclass_2 != rclass_3 || rclass_3 != rclass_4)
  9429. return false;
  9430. return true;
  9431. }
  9432. /* Given OPERANDS of consecutive load/store, this function pairs them
  9433. into ldp/stp after adjusting the offset. It depends on the fact
  9434. that addresses of load/store instructions are in increasing order.
  9435. MODE is the mode of memory operands. CODE is the rtl operator
  9436. which should be applied to all memory operands, it's SIGN_EXTEND,
  9437. ZERO_EXTEND or UNKNOWN. */
  9438. bool
  9439. aarch64_gen_adjusted_ldpstp (rtx *operands, bool load,
  9440. enum machine_mode mode, RTX_CODE code)
  9441. {
  9442. rtx base, offset, t1, t2;
  9443. rtx mem_1, mem_2, mem_3, mem_4;
  9444. HOST_WIDE_INT off_val, abs_off, adj_off, new_off, stp_off_limit, msize;
  9445. if (load)
  9446. {
  9447. mem_1 = operands[1];
  9448. mem_2 = operands[3];
  9449. mem_3 = operands[5];
  9450. mem_4 = operands[7];
  9451. }
  9452. else
  9453. {
  9454. mem_1 = operands[0];
  9455. mem_2 = operands[2];
  9456. mem_3 = operands[4];
  9457. mem_4 = operands[6];
  9458. gcc_assert (code == UNKNOWN);
  9459. }
  9460. extract_base_offset_in_addr (mem_1, &base, &offset);
  9461. gcc_assert (base != NULL_RTX && offset != NULL_RTX);
  9462. /* Adjust offset thus it can fit in ldp/stp instruction. */
  9463. msize = GET_MODE_SIZE (mode);
  9464. stp_off_limit = msize * 0x40;
  9465. off_val = INTVAL (offset);
  9466. abs_off = (off_val < 0) ? -off_val : off_val;
  9467. new_off = abs_off % stp_off_limit;
  9468. adj_off = abs_off - new_off;
  9469. /* Further adjust to make sure all offsets are OK. */
  9470. if ((new_off + msize * 2) >= stp_off_limit)
  9471. {
  9472. adj_off += stp_off_limit;
  9473. new_off -= stp_off_limit;
  9474. }
  9475. /* Make sure the adjustment can be done with ADD/SUB instructions. */
  9476. if (adj_off >= 0x1000)
  9477. return false;
  9478. if (off_val < 0)
  9479. {
  9480. adj_off = -adj_off;
  9481. new_off = -new_off;
  9482. }
  9483. /* Create new memory references. */
  9484. mem_1 = change_address (mem_1, VOIDmode,
  9485. plus_constant (DImode, operands[8], new_off));
  9486. /* Check if the adjusted address is OK for ldp/stp. */
  9487. if (!aarch64_mem_pair_operand (mem_1, mode))
  9488. return false;
  9489. msize = GET_MODE_SIZE (mode);
  9490. mem_2 = change_address (mem_2, VOIDmode,
  9491. plus_constant (DImode,
  9492. operands[8],
  9493. new_off + msize));
  9494. mem_3 = change_address (mem_3, VOIDmode,
  9495. plus_constant (DImode,
  9496. operands[8],
  9497. new_off + msize * 2));
  9498. mem_4 = change_address (mem_4, VOIDmode,
  9499. plus_constant (DImode,
  9500. operands[8],
  9501. new_off + msize * 3));
  9502. if (code == ZERO_EXTEND)
  9503. {
  9504. mem_1 = gen_rtx_ZERO_EXTEND (DImode, mem_1);
  9505. mem_2 = gen_rtx_ZERO_EXTEND (DImode, mem_2);
  9506. mem_3 = gen_rtx_ZERO_EXTEND (DImode, mem_3);
  9507. mem_4 = gen_rtx_ZERO_EXTEND (DImode, mem_4);
  9508. }
  9509. else if (code == SIGN_EXTEND)
  9510. {
  9511. mem_1 = gen_rtx_SIGN_EXTEND (DImode, mem_1);
  9512. mem_2 = gen_rtx_SIGN_EXTEND (DImode, mem_2);
  9513. mem_3 = gen_rtx_SIGN_EXTEND (DImode, mem_3);
  9514. mem_4 = gen_rtx_SIGN_EXTEND (DImode, mem_4);
  9515. }
  9516. if (load)
  9517. {
  9518. operands[1] = mem_1;
  9519. operands[3] = mem_2;
  9520. operands[5] = mem_3;
  9521. operands[7] = mem_4;
  9522. }
  9523. else
  9524. {
  9525. operands[0] = mem_1;
  9526. operands[2] = mem_2;
  9527. operands[4] = mem_3;
  9528. operands[6] = mem_4;
  9529. }
  9530. /* Emit adjusting instruction. */
  9531. emit_insn (gen_rtx_SET (VOIDmode, operands[8],
  9532. plus_constant (DImode, base, adj_off)));
  9533. /* Emit ldp/stp instructions. */
  9534. t1 = gen_rtx_SET (VOIDmode, operands[0], operands[1]);
  9535. t2 = gen_rtx_SET (VOIDmode, operands[2], operands[3]);
  9536. emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, t1, t2)));
  9537. t1 = gen_rtx_SET (VOIDmode, operands[4], operands[5]);
  9538. t2 = gen_rtx_SET (VOIDmode, operands[6], operands[7]);
  9539. emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, t1, t2)));
  9540. return true;
  9541. }
  9542. #undef TARGET_ADDRESS_COST
  9543. #define TARGET_ADDRESS_COST aarch64_address_cost
  9544. /* This hook will determines whether unnamed bitfields affect the alignment
  9545. of the containing structure. The hook returns true if the structure
  9546. should inherit the alignment requirements of an unnamed bitfield's
  9547. type. */
  9548. #undef TARGET_ALIGN_ANON_BITFIELD
  9549. #define TARGET_ALIGN_ANON_BITFIELD hook_bool_void_true
  9550. #undef TARGET_ASM_ALIGNED_DI_OP
  9551. #define TARGET_ASM_ALIGNED_DI_OP "\t.xword\t"
  9552. #undef TARGET_ASM_ALIGNED_HI_OP
  9553. #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
  9554. #undef TARGET_ASM_ALIGNED_SI_OP
  9555. #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
  9556. #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
  9557. #define TARGET_ASM_CAN_OUTPUT_MI_THUNK \
  9558. hook_bool_const_tree_hwi_hwi_const_tree_true
  9559. #undef TARGET_ASM_FILE_START
  9560. #define TARGET_ASM_FILE_START aarch64_start_file
  9561. #undef TARGET_ASM_OUTPUT_MI_THUNK
  9562. #define TARGET_ASM_OUTPUT_MI_THUNK aarch64_output_mi_thunk
  9563. #undef TARGET_ASM_SELECT_RTX_SECTION
  9564. #define TARGET_ASM_SELECT_RTX_SECTION aarch64_select_rtx_section
  9565. #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
  9566. #define TARGET_ASM_TRAMPOLINE_TEMPLATE aarch64_asm_trampoline_template
  9567. #undef TARGET_BUILD_BUILTIN_VA_LIST
  9568. #define TARGET_BUILD_BUILTIN_VA_LIST aarch64_build_builtin_va_list
  9569. #undef TARGET_CALLEE_COPIES
  9570. #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_false
  9571. #undef TARGET_CAN_ELIMINATE
  9572. #define TARGET_CAN_ELIMINATE aarch64_can_eliminate
  9573. #undef TARGET_CANNOT_FORCE_CONST_MEM
  9574. #define TARGET_CANNOT_FORCE_CONST_MEM aarch64_cannot_force_const_mem
  9575. #undef TARGET_CONDITIONAL_REGISTER_USAGE
  9576. #define TARGET_CONDITIONAL_REGISTER_USAGE aarch64_conditional_register_usage
  9577. /* Only the least significant bit is used for initialization guard
  9578. variables. */
  9579. #undef TARGET_CXX_GUARD_MASK_BIT
  9580. #define TARGET_CXX_GUARD_MASK_BIT hook_bool_void_true
  9581. #undef TARGET_C_MODE_FOR_SUFFIX
  9582. #define TARGET_C_MODE_FOR_SUFFIX aarch64_c_mode_for_suffix
  9583. #ifdef TARGET_BIG_ENDIAN_DEFAULT
  9584. #undef TARGET_DEFAULT_TARGET_FLAGS
  9585. #define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_END)
  9586. #endif
  9587. #undef TARGET_CLASS_MAX_NREGS
  9588. #define TARGET_CLASS_MAX_NREGS aarch64_class_max_nregs
  9589. #undef TARGET_BUILTIN_DECL
  9590. #define TARGET_BUILTIN_DECL aarch64_builtin_decl
  9591. #undef TARGET_EXPAND_BUILTIN
  9592. #define TARGET_EXPAND_BUILTIN aarch64_expand_builtin
  9593. #undef TARGET_EXPAND_BUILTIN_VA_START
  9594. #define TARGET_EXPAND_BUILTIN_VA_START aarch64_expand_builtin_va_start
  9595. #undef TARGET_FOLD_BUILTIN
  9596. #define TARGET_FOLD_BUILTIN aarch64_fold_builtin
  9597. #undef TARGET_FUNCTION_ARG
  9598. #define TARGET_FUNCTION_ARG aarch64_function_arg
  9599. #undef TARGET_FUNCTION_ARG_ADVANCE
  9600. #define TARGET_FUNCTION_ARG_ADVANCE aarch64_function_arg_advance
  9601. #undef TARGET_FUNCTION_ARG_BOUNDARY
  9602. #define TARGET_FUNCTION_ARG_BOUNDARY aarch64_function_arg_boundary
  9603. #undef TARGET_FUNCTION_OK_FOR_SIBCALL
  9604. #define TARGET_FUNCTION_OK_FOR_SIBCALL aarch64_function_ok_for_sibcall
  9605. #undef TARGET_FUNCTION_VALUE
  9606. #define TARGET_FUNCTION_VALUE aarch64_function_value
  9607. #undef TARGET_FUNCTION_VALUE_REGNO_P
  9608. #define TARGET_FUNCTION_VALUE_REGNO_P aarch64_function_value_regno_p
  9609. #undef TARGET_FRAME_POINTER_REQUIRED
  9610. #define TARGET_FRAME_POINTER_REQUIRED aarch64_frame_pointer_required
  9611. #undef TARGET_GIMPLE_FOLD_BUILTIN
  9612. #define TARGET_GIMPLE_FOLD_BUILTIN aarch64_gimple_fold_builtin
  9613. #undef TARGET_GIMPLIFY_VA_ARG_EXPR
  9614. #define TARGET_GIMPLIFY_VA_ARG_EXPR aarch64_gimplify_va_arg_expr
  9615. #undef TARGET_INIT_BUILTINS
  9616. #define TARGET_INIT_BUILTINS aarch64_init_builtins
  9617. #undef TARGET_LEGITIMATE_ADDRESS_P
  9618. #define TARGET_LEGITIMATE_ADDRESS_P aarch64_legitimate_address_hook_p
  9619. #undef TARGET_LEGITIMATE_CONSTANT_P
  9620. #define TARGET_LEGITIMATE_CONSTANT_P aarch64_legitimate_constant_p
  9621. #undef TARGET_LIBGCC_CMP_RETURN_MODE
  9622. #define TARGET_LIBGCC_CMP_RETURN_MODE aarch64_libgcc_cmp_return_mode
  9623. #undef TARGET_LRA_P
  9624. #define TARGET_LRA_P hook_bool_void_true
  9625. #undef TARGET_MANGLE_TYPE
  9626. #define TARGET_MANGLE_TYPE aarch64_mangle_type
  9627. #undef TARGET_MEMORY_MOVE_COST
  9628. #define TARGET_MEMORY_MOVE_COST aarch64_memory_move_cost
  9629. #undef TARGET_MIN_DIVISIONS_FOR_RECIP_MUL
  9630. #define TARGET_MIN_DIVISIONS_FOR_RECIP_MUL aarch64_min_divisions_for_recip_mul
  9631. #undef TARGET_MUST_PASS_IN_STACK
  9632. #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
  9633. /* This target hook should return true if accesses to volatile bitfields
  9634. should use the narrowest mode possible. It should return false if these
  9635. accesses should use the bitfield container type. */
  9636. #undef TARGET_NARROW_VOLATILE_BITFIELD
  9637. #define TARGET_NARROW_VOLATILE_BITFIELD hook_bool_void_false
  9638. #undef TARGET_OPTION_OVERRIDE
  9639. #define TARGET_OPTION_OVERRIDE aarch64_override_options
  9640. #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
  9641. #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE \
  9642. aarch64_override_options_after_change
  9643. #undef TARGET_PASS_BY_REFERENCE
  9644. #define TARGET_PASS_BY_REFERENCE aarch64_pass_by_reference
  9645. #undef TARGET_PREFERRED_RELOAD_CLASS
  9646. #define TARGET_PREFERRED_RELOAD_CLASS aarch64_preferred_reload_class
  9647. #undef TARGET_SCHED_REASSOCIATION_WIDTH
  9648. #define TARGET_SCHED_REASSOCIATION_WIDTH aarch64_reassociation_width
  9649. #undef TARGET_SECONDARY_RELOAD
  9650. #define TARGET_SECONDARY_RELOAD aarch64_secondary_reload
  9651. #undef TARGET_SHIFT_TRUNCATION_MASK
  9652. #define TARGET_SHIFT_TRUNCATION_MASK aarch64_shift_truncation_mask
  9653. #undef TARGET_SETUP_INCOMING_VARARGS
  9654. #define TARGET_SETUP_INCOMING_VARARGS aarch64_setup_incoming_varargs
  9655. #undef TARGET_STRUCT_VALUE_RTX
  9656. #define TARGET_STRUCT_VALUE_RTX aarch64_struct_value_rtx
  9657. #undef TARGET_REGISTER_MOVE_COST
  9658. #define TARGET_REGISTER_MOVE_COST aarch64_register_move_cost
  9659. #undef TARGET_RETURN_IN_MEMORY
  9660. #define TARGET_RETURN_IN_MEMORY aarch64_return_in_memory
  9661. #undef TARGET_RETURN_IN_MSB
  9662. #define TARGET_RETURN_IN_MSB aarch64_return_in_msb
  9663. #undef TARGET_RTX_COSTS
  9664. #define TARGET_RTX_COSTS aarch64_rtx_costs_wrapper
  9665. #undef TARGET_SCHED_ISSUE_RATE
  9666. #define TARGET_SCHED_ISSUE_RATE aarch64_sched_issue_rate
  9667. #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
  9668. #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
  9669. aarch64_sched_first_cycle_multipass_dfa_lookahead
  9670. #undef TARGET_TRAMPOLINE_INIT
  9671. #define TARGET_TRAMPOLINE_INIT aarch64_trampoline_init
  9672. #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
  9673. #define TARGET_USE_BLOCKS_FOR_CONSTANT_P aarch64_use_blocks_for_constant_p
  9674. #undef TARGET_VECTOR_MODE_SUPPORTED_P
  9675. #define TARGET_VECTOR_MODE_SUPPORTED_P aarch64_vector_mode_supported_p
  9676. #undef TARGET_ARRAY_MODE_SUPPORTED_P
  9677. #define TARGET_ARRAY_MODE_SUPPORTED_P aarch64_array_mode_supported_p
  9678. #undef TARGET_VECTORIZE_ADD_STMT_COST
  9679. #define TARGET_VECTORIZE_ADD_STMT_COST aarch64_add_stmt_cost
  9680. #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
  9681. #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
  9682. aarch64_builtin_vectorization_cost
  9683. #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
  9684. #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE aarch64_preferred_simd_mode
  9685. #undef TARGET_VECTORIZE_BUILTINS
  9686. #define TARGET_VECTORIZE_BUILTINS
  9687. #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
  9688. #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
  9689. aarch64_builtin_vectorized_function
  9690. #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
  9691. #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
  9692. aarch64_autovectorize_vector_sizes
  9693. #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
  9694. #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV \
  9695. aarch64_atomic_assign_expand_fenv
  9696. /* Section anchor support. */
  9697. #undef TARGET_MIN_ANCHOR_OFFSET
  9698. #define TARGET_MIN_ANCHOR_OFFSET -256
  9699. /* Limit the maximum anchor offset to 4k-1, since that's the limit for a
  9700. byte offset; we can do much more for larger data types, but have no way
  9701. to determine the size of the access. We assume accesses are aligned. */
  9702. #undef TARGET_MAX_ANCHOR_OFFSET
  9703. #define TARGET_MAX_ANCHOR_OFFSET 4095
  9704. #undef TARGET_VECTOR_ALIGNMENT
  9705. #define TARGET_VECTOR_ALIGNMENT aarch64_simd_vector_alignment
  9706. #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
  9707. #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE \
  9708. aarch64_simd_vector_alignment_reachable
  9709. /* vec_perm support. */
  9710. #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
  9711. #define TARGET_VECTORIZE_VEC_PERM_CONST_OK \
  9712. aarch64_vectorize_vec_perm_const_ok
  9713. #undef TARGET_FIXED_CONDITION_CODE_REGS
  9714. #define TARGET_FIXED_CONDITION_CODE_REGS aarch64_fixed_condition_code_regs
  9715. #undef TARGET_FLAGS_REGNUM
  9716. #define TARGET_FLAGS_REGNUM CC_REGNUM
  9717. #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
  9718. #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
  9719. #undef TARGET_ASAN_SHADOW_OFFSET
  9720. #define TARGET_ASAN_SHADOW_OFFSET aarch64_asan_shadow_offset
  9721. #undef TARGET_LEGITIMIZE_ADDRESS
  9722. #define TARGET_LEGITIMIZE_ADDRESS aarch64_legitimize_address
  9723. #undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P
  9724. #define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \
  9725. aarch64_use_by_pieces_infrastructure_p
  9726. #undef TARGET_CAN_USE_DOLOOP_P
  9727. #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost
  9728. #undef TARGET_SCHED_MACRO_FUSION_P
  9729. #define TARGET_SCHED_MACRO_FUSION_P aarch64_macro_fusion_p
  9730. #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
  9731. #define TARGET_SCHED_MACRO_FUSION_PAIR_P aarch_macro_fusion_pair_p
  9732. #undef TARGET_SCHED_FUSION_PRIORITY
  9733. #define TARGET_SCHED_FUSION_PRIORITY aarch64_sched_fusion_priority
  9734. #undef TARGET_RELAXED_ORDERING
  9735. #define TARGET_RELAXED_ORDERING true
  9736. struct gcc_target targetm = TARGET_INITIALIZER;
  9737. #include "gt-aarch64.h"