Targets.cpp 238 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513
  1. //===--- Targets.cpp - Implement -arch option and targets -----------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements construction of a TargetInfo object from a
  11. // target triple.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "clang/Basic/TargetInfo.h"
  15. #include "clang/Basic/Builtins.h"
  16. #include "clang/Basic/Diagnostic.h"
  17. #include "clang/Basic/LangOptions.h"
  18. #include "clang/Basic/MacroBuilder.h"
  19. #include "clang/Basic/TargetBuiltins.h"
  20. #include "clang/Basic/TargetOptions.h"
  21. #include "llvm/ADT/APFloat.h"
  22. #include "llvm/ADT/STLExtras.h"
  23. #include "llvm/ADT/StringExtras.h"
  24. #include "llvm/ADT/StringRef.h"
  25. #include "llvm/ADT/StringSwitch.h"
  26. #include "llvm/ADT/Triple.h"
  27. #include "llvm/MC/MCSectionMachO.h"
  28. #include "llvm/Support/ErrorHandling.h"
  29. #include "llvm/Support/TargetParser.h"
  30. #include <algorithm>
  31. #include <memory>
  32. using namespace clang;
  33. //===----------------------------------------------------------------------===//
  34. // Common code shared among targets.
  35. //===----------------------------------------------------------------------===//
  36. #if 0 // HLSL Change Starts - remove unsupported targets
  37. /// DefineStd - Define a macro name and standard variants. For example if
  38. /// MacroName is "unix", then this will define "__unix", "__unix__", and "unix"
  39. /// when in GNU mode.
  40. static void DefineStd(MacroBuilder &Builder, StringRef MacroName,
  41. const LangOptions &Opts) {
  42. assert(MacroName[0] != '_' && "Identifier should be in the user's namespace");
  43. // If in GNU mode (e.g. -std=gnu99 but not -std=c99) define the raw identifier
  44. // in the user's namespace.
  45. if (Opts.GNUMode)
  46. Builder.defineMacro(MacroName);
  47. // Define __unix.
  48. Builder.defineMacro("__" + MacroName);
  49. // Define __unix__.
  50. Builder.defineMacro("__" + MacroName + "__");
  51. }
  52. static void defineCPUMacros(MacroBuilder &Builder, StringRef CPUName,
  53. bool Tuning = true) {
  54. Builder.defineMacro("__" + CPUName);
  55. Builder.defineMacro("__" + CPUName + "__");
  56. if (Tuning)
  57. Builder.defineMacro("__tune_" + CPUName + "__");
  58. }
  59. #endif // HLSL Change Ends - remove unsupported targets
  60. //===----------------------------------------------------------------------===//
  61. // Defines specific to certain operating systems.
  62. //===----------------------------------------------------------------------===//
  63. namespace {
  64. template<typename TgtInfo>
  65. class OSTargetInfo : public TgtInfo {
  66. protected:
  67. virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  68. MacroBuilder &Builder) const=0;
  69. public:
  70. OSTargetInfo(const llvm::Triple &Triple) : TgtInfo(Triple) {}
  71. void getTargetDefines(const LangOptions &Opts,
  72. MacroBuilder &Builder) const override {
  73. TgtInfo::getTargetDefines(Opts, Builder);
  74. getOSDefines(Opts, TgtInfo::getTriple(), Builder);
  75. }
  76. };
  77. } // end anonymous namespace
  78. #if 0 // HLSL Change Starts - remove unsupported targets
  79. static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
  80. const llvm::Triple &Triple,
  81. StringRef &PlatformName,
  82. VersionTuple &PlatformMinVersion) {
  83. Builder.defineMacro("__APPLE_CC__", "6000");
  84. Builder.defineMacro("__APPLE__");
  85. Builder.defineMacro("OBJC_NEW_PROPERTIES");
  86. // AddressSanitizer doesn't play well with source fortification, which is on
  87. // by default on Darwin.
  88. if (Opts.Sanitize.has(SanitizerKind::Address))
  89. Builder.defineMacro("_FORTIFY_SOURCE", "0");
  90. if (!Opts.ObjCAutoRefCount) {
  91. // __weak is always defined, for use in blocks and with objc pointers.
  92. Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
  93. // Darwin defines __strong even in C mode (just to nothing).
  94. if (Opts.getGC() != LangOptions::NonGC)
  95. Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
  96. else
  97. Builder.defineMacro("__strong", "");
  98. // __unsafe_unretained is defined to nothing in non-ARC mode. We even
  99. // allow this in C, since one might have block pointers in structs that
  100. // are used in pure C code and in Objective-C ARC.
  101. Builder.defineMacro("__unsafe_unretained", "");
  102. }
  103. if (Opts.Static)
  104. Builder.defineMacro("__STATIC__");
  105. else
  106. Builder.defineMacro("__DYNAMIC__");
  107. if (Opts.POSIXThreads)
  108. Builder.defineMacro("_REENTRANT");
  109. // Get the platform type and version number from the triple.
  110. unsigned Maj, Min, Rev;
  111. if (Triple.isMacOSX()) {
  112. Triple.getMacOSXVersion(Maj, Min, Rev);
  113. PlatformName = "macosx";
  114. } else {
  115. Triple.getOSVersion(Maj, Min, Rev);
  116. PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
  117. }
  118. // If -target arch-pc-win32-macho option specified, we're
  119. // generating code for Win32 ABI. No need to emit
  120. // __ENVIRONMENT_XX_OS_VERSION_MIN_REQUIRED__.
  121. if (PlatformName == "win32") {
  122. PlatformMinVersion = VersionTuple(Maj, Min, Rev);
  123. return;
  124. }
  125. // Set the appropriate OS version define.
  126. if (Triple.isiOS()) {
  127. assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!");
  128. char Str[6];
  129. Str[0] = '0' + Maj;
  130. Str[1] = '0' + (Min / 10);
  131. Str[2] = '0' + (Min % 10);
  132. Str[3] = '0' + (Rev / 10);
  133. Str[4] = '0' + (Rev % 10);
  134. Str[5] = '\0';
  135. Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__",
  136. Str);
  137. } else if (Triple.isMacOSX()) {
  138. // Note that the Driver allows versions which aren't representable in the
  139. // define (because we only get a single digit for the minor and micro
  140. // revision numbers). So, we limit them to the maximum representable
  141. // version.
  142. assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!");
  143. char Str[7];
  144. if (Maj < 10 || (Maj == 10 && Min < 10)) {
  145. Str[0] = '0' + (Maj / 10);
  146. Str[1] = '0' + (Maj % 10);
  147. Str[2] = '0' + std::min(Min, 9U);
  148. Str[3] = '0' + std::min(Rev, 9U);
  149. Str[4] = '\0';
  150. } else {
  151. // Handle versions > 10.9.
  152. Str[0] = '0' + (Maj / 10);
  153. Str[1] = '0' + (Maj % 10);
  154. Str[2] = '0' + (Min / 10);
  155. Str[3] = '0' + (Min % 10);
  156. Str[4] = '0' + (Rev / 10);
  157. Str[5] = '0' + (Rev % 10);
  158. Str[6] = '\0';
  159. }
  160. Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
  161. }
  162. // Tell users about the kernel if there is one.
  163. if (Triple.isOSDarwin())
  164. Builder.defineMacro("__MACH__");
  165. PlatformMinVersion = VersionTuple(Maj, Min, Rev);
  166. }
  167. namespace {
  168. // CloudABI Target
  169. template <typename Target>
  170. class CloudABITargetInfo : public OSTargetInfo<Target> {
  171. protected:
  172. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  173. MacroBuilder &Builder) const override {
  174. Builder.defineMacro("__CloudABI__");
  175. Builder.defineMacro("__ELF__");
  176. // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
  177. Builder.defineMacro("__STDC_ISO_10646__", "201206L");
  178. Builder.defineMacro("__STDC_UTF_16__");
  179. Builder.defineMacro("__STDC_UTF_32__");
  180. }
  181. public:
  182. CloudABITargetInfo(const llvm::Triple &Triple)
  183. : OSTargetInfo<Target>(Triple) {
  184. this->UserLabelPrefix = "";
  185. }
  186. };
  187. template<typename Target>
  188. class DarwinTargetInfo : public OSTargetInfo<Target> {
  189. protected:
  190. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  191. MacroBuilder &Builder) const override {
  192. getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
  193. this->PlatformMinVersion);
  194. }
  195. public:
  196. DarwinTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  197. this->TLSSupported = Triple.isMacOSX() && !Triple.isMacOSXVersionLT(10, 7);
  198. this->MCountName = "\01mcount";
  199. }
  200. std::string isValidSectionSpecifier(StringRef SR) const override {
  201. // Let MCSectionMachO validate this.
  202. StringRef Segment, Section;
  203. unsigned TAA, StubSize;
  204. bool HasTAA;
  205. return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
  206. TAA, HasTAA, StubSize);
  207. }
  208. const char *getStaticInitSectionSpecifier() const override {
  209. // FIXME: We should return 0 when building kexts.
  210. return "__TEXT,__StaticInit,regular,pure_instructions";
  211. }
  212. /// Darwin does not support protected visibility. Darwin's "default"
  213. /// is very similar to ELF's "protected"; Darwin requires a "weak"
  214. /// attribute on declarations that can be dynamically replaced.
  215. bool hasProtectedVisibility() const override {
  216. return false;
  217. }
  218. };
  219. // DragonFlyBSD Target
  220. template<typename Target>
  221. class DragonFlyBSDTargetInfo : public OSTargetInfo<Target> {
  222. protected:
  223. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  224. MacroBuilder &Builder) const override {
  225. // DragonFly defines; list based off of gcc output
  226. Builder.defineMacro("__DragonFly__");
  227. Builder.defineMacro("__DragonFly_cc_version", "100001");
  228. Builder.defineMacro("__ELF__");
  229. Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
  230. Builder.defineMacro("__tune_i386__");
  231. DefineStd(Builder, "unix", Opts);
  232. }
  233. public:
  234. DragonFlyBSDTargetInfo(const llvm::Triple &Triple)
  235. : OSTargetInfo<Target>(Triple) {
  236. this->UserLabelPrefix = "";
  237. switch (Triple.getArch()) {
  238. default:
  239. case llvm::Triple::x86:
  240. case llvm::Triple::x86_64:
  241. this->MCountName = ".mcount";
  242. break;
  243. }
  244. }
  245. };
  246. // FreeBSD Target
  247. template<typename Target>
  248. class FreeBSDTargetInfo : public OSTargetInfo<Target> {
  249. protected:
  250. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  251. MacroBuilder &Builder) const override {
  252. // FreeBSD defines; list based off of gcc output
  253. unsigned Release = Triple.getOSMajorVersion();
  254. if (Release == 0U)
  255. Release = 8;
  256. Builder.defineMacro("__FreeBSD__", Twine(Release));
  257. Builder.defineMacro("__FreeBSD_cc_version", Twine(Release * 100000U + 1U));
  258. Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
  259. DefineStd(Builder, "unix", Opts);
  260. Builder.defineMacro("__ELF__");
  261. // On FreeBSD, wchar_t contains the number of the code point as
  262. // used by the character set of the locale. These character sets are
  263. // not necessarily a superset of ASCII.
  264. //
  265. // FIXME: This is wrong; the macro refers to the numerical values
  266. // of wchar_t *literals*, which are not locale-dependent. However,
  267. // FreeBSD systems apparently depend on us getting this wrong, and
  268. // setting this to 1 is conforming even if all the basic source
  269. // character literals have the same encoding as char and wchar_t.
  270. Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
  271. }
  272. public:
  273. FreeBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  274. this->UserLabelPrefix = "";
  275. switch (Triple.getArch()) {
  276. default:
  277. case llvm::Triple::x86:
  278. case llvm::Triple::x86_64:
  279. this->MCountName = ".mcount";
  280. break;
  281. case llvm::Triple::mips:
  282. case llvm::Triple::mipsel:
  283. case llvm::Triple::ppc:
  284. case llvm::Triple::ppc64:
  285. case llvm::Triple::ppc64le:
  286. this->MCountName = "_mcount";
  287. break;
  288. case llvm::Triple::arm:
  289. this->MCountName = "__mcount";
  290. break;
  291. }
  292. }
  293. };
  294. // GNU/kFreeBSD Target
  295. template<typename Target>
  296. class KFreeBSDTargetInfo : public OSTargetInfo<Target> {
  297. protected:
  298. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  299. MacroBuilder &Builder) const override {
  300. // GNU/kFreeBSD defines; list based off of gcc output
  301. DefineStd(Builder, "unix", Opts);
  302. Builder.defineMacro("__FreeBSD_kernel__");
  303. Builder.defineMacro("__GLIBC__");
  304. Builder.defineMacro("__ELF__");
  305. if (Opts.POSIXThreads)
  306. Builder.defineMacro("_REENTRANT");
  307. if (Opts.CPlusPlus)
  308. Builder.defineMacro("_GNU_SOURCE");
  309. }
  310. public:
  311. KFreeBSDTargetInfo(const llvm::Triple &Triple)
  312. : OSTargetInfo<Target>(Triple) {
  313. this->UserLabelPrefix = "";
  314. }
  315. };
  316. // Minix Target
  317. template<typename Target>
  318. class MinixTargetInfo : public OSTargetInfo<Target> {
  319. protected:
  320. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  321. MacroBuilder &Builder) const override {
  322. // Minix defines
  323. Builder.defineMacro("__minix", "3");
  324. Builder.defineMacro("_EM_WSIZE", "4");
  325. Builder.defineMacro("_EM_PSIZE", "4");
  326. Builder.defineMacro("_EM_SSIZE", "2");
  327. Builder.defineMacro("_EM_LSIZE", "4");
  328. Builder.defineMacro("_EM_FSIZE", "4");
  329. Builder.defineMacro("_EM_DSIZE", "8");
  330. Builder.defineMacro("__ELF__");
  331. DefineStd(Builder, "unix", Opts);
  332. }
  333. public:
  334. MinixTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  335. this->UserLabelPrefix = "";
  336. }
  337. };
  338. // Linux target
  339. template<typename Target>
  340. class LinuxTargetInfo : public OSTargetInfo<Target> {
  341. protected:
  342. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  343. MacroBuilder &Builder) const override {
  344. // Linux defines; list based off of gcc output
  345. DefineStd(Builder, "unix", Opts);
  346. DefineStd(Builder, "linux", Opts);
  347. Builder.defineMacro("__gnu_linux__");
  348. Builder.defineMacro("__ELF__");
  349. if (Triple.getEnvironment() == llvm::Triple::Android) {
  350. Builder.defineMacro("__ANDROID__", "1");
  351. unsigned Maj, Min, Rev;
  352. Triple.getEnvironmentVersion(Maj, Min, Rev);
  353. this->PlatformName = "android";
  354. this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
  355. }
  356. if (Opts.POSIXThreads)
  357. Builder.defineMacro("_REENTRANT");
  358. if (Opts.CPlusPlus)
  359. Builder.defineMacro("_GNU_SOURCE");
  360. }
  361. public:
  362. LinuxTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  363. this->UserLabelPrefix = "";
  364. this->WIntType = TargetInfo::UnsignedInt;
  365. switch (Triple.getArch()) {
  366. default:
  367. break;
  368. case llvm::Triple::ppc:
  369. case llvm::Triple::ppc64:
  370. case llvm::Triple::ppc64le:
  371. this->MCountName = "_mcount";
  372. break;
  373. }
  374. }
  375. const char *getStaticInitSectionSpecifier() const override {
  376. return ".text.startup";
  377. }
  378. };
  379. // NetBSD Target
  380. template<typename Target>
  381. class NetBSDTargetInfo : public OSTargetInfo<Target> {
  382. protected:
  383. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  384. MacroBuilder &Builder) const override {
  385. // NetBSD defines; list based off of gcc output
  386. Builder.defineMacro("__NetBSD__");
  387. Builder.defineMacro("__unix__");
  388. Builder.defineMacro("__ELF__");
  389. if (Opts.POSIXThreads)
  390. Builder.defineMacro("_POSIX_THREADS");
  391. switch (Triple.getArch()) {
  392. default:
  393. break;
  394. case llvm::Triple::arm:
  395. case llvm::Triple::armeb:
  396. case llvm::Triple::thumb:
  397. case llvm::Triple::thumbeb:
  398. Builder.defineMacro("__ARM_DWARF_EH__");
  399. break;
  400. }
  401. }
  402. public:
  403. NetBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  404. this->UserLabelPrefix = "";
  405. this->MCountName = "_mcount";
  406. }
  407. };
  408. // OpenBSD Target
  409. template<typename Target>
  410. class OpenBSDTargetInfo : public OSTargetInfo<Target> {
  411. protected:
  412. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  413. MacroBuilder &Builder) const override {
  414. // OpenBSD defines; list based off of gcc output
  415. Builder.defineMacro("__OpenBSD__");
  416. DefineStd(Builder, "unix", Opts);
  417. Builder.defineMacro("__ELF__");
  418. if (Opts.POSIXThreads)
  419. Builder.defineMacro("_REENTRANT");
  420. }
  421. public:
  422. OpenBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  423. this->UserLabelPrefix = "";
  424. this->TLSSupported = false;
  425. switch (Triple.getArch()) {
  426. default:
  427. case llvm::Triple::x86:
  428. case llvm::Triple::x86_64:
  429. case llvm::Triple::arm:
  430. case llvm::Triple::sparc:
  431. this->MCountName = "__mcount";
  432. break;
  433. case llvm::Triple::mips64:
  434. case llvm::Triple::mips64el:
  435. case llvm::Triple::ppc:
  436. case llvm::Triple::sparcv9:
  437. this->MCountName = "_mcount";
  438. break;
  439. }
  440. }
  441. };
  442. // Bitrig Target
  443. template<typename Target>
  444. class BitrigTargetInfo : public OSTargetInfo<Target> {
  445. protected:
  446. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  447. MacroBuilder &Builder) const override {
  448. // Bitrig defines; list based off of gcc output
  449. Builder.defineMacro("__Bitrig__");
  450. DefineStd(Builder, "unix", Opts);
  451. Builder.defineMacro("__ELF__");
  452. if (Opts.POSIXThreads)
  453. Builder.defineMacro("_REENTRANT");
  454. switch (Triple.getArch()) {
  455. default:
  456. break;
  457. case llvm::Triple::arm:
  458. case llvm::Triple::armeb:
  459. case llvm::Triple::thumb:
  460. case llvm::Triple::thumbeb:
  461. Builder.defineMacro("__ARM_DWARF_EH__");
  462. break;
  463. }
  464. }
  465. public:
  466. BitrigTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  467. this->UserLabelPrefix = "";
  468. this->MCountName = "__mcount";
  469. }
  470. };
  471. // PSP Target
  472. template<typename Target>
  473. class PSPTargetInfo : public OSTargetInfo<Target> {
  474. protected:
  475. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  476. MacroBuilder &Builder) const override {
  477. // PSP defines; list based on the output of the pspdev gcc toolchain.
  478. Builder.defineMacro("PSP");
  479. Builder.defineMacro("_PSP");
  480. Builder.defineMacro("__psp__");
  481. Builder.defineMacro("__ELF__");
  482. }
  483. public:
  484. PSPTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  485. this->UserLabelPrefix = "";
  486. }
  487. };
  488. // PS3 PPU Target
  489. template<typename Target>
  490. class PS3PPUTargetInfo : public OSTargetInfo<Target> {
  491. protected:
  492. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  493. MacroBuilder &Builder) const override {
  494. // PS3 PPU defines.
  495. Builder.defineMacro("__PPC__");
  496. Builder.defineMacro("__PPU__");
  497. Builder.defineMacro("__CELLOS_LV2__");
  498. Builder.defineMacro("__ELF__");
  499. Builder.defineMacro("__LP32__");
  500. Builder.defineMacro("_ARCH_PPC64");
  501. Builder.defineMacro("__powerpc64__");
  502. }
  503. public:
  504. PS3PPUTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  505. this->UserLabelPrefix = "";
  506. this->LongWidth = this->LongAlign = 32;
  507. this->PointerWidth = this->PointerAlign = 32;
  508. this->IntMaxType = TargetInfo::SignedLongLong;
  509. this->Int64Type = TargetInfo::SignedLongLong;
  510. this->SizeType = TargetInfo::UnsignedInt;
  511. this->DescriptionString = "E-m:e-p:32:32-i64:64-n32:64";
  512. }
  513. };
  514. template <typename Target>
  515. class PS4OSTargetInfo : public OSTargetInfo<Target> {
  516. protected:
  517. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  518. MacroBuilder &Builder) const override {
  519. Builder.defineMacro("__FreeBSD__", "9");
  520. Builder.defineMacro("__FreeBSD_cc_version", "900001");
  521. Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
  522. DefineStd(Builder, "unix", Opts);
  523. Builder.defineMacro("__ELF__");
  524. Builder.defineMacro("__PS4__");
  525. }
  526. public:
  527. PS4OSTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  528. this->WCharType = this->UnsignedShort;
  529. // On PS4, TLS variable cannot be aligned to more than 32 bytes (256 bits).
  530. this->MaxTLSAlign = 256;
  531. this->UserLabelPrefix = "";
  532. switch (Triple.getArch()) {
  533. default:
  534. case llvm::Triple::x86_64:
  535. this->MCountName = ".mcount";
  536. break;
  537. }
  538. }
  539. };
  540. // Solaris target
  541. template<typename Target>
  542. class SolarisTargetInfo : public OSTargetInfo<Target> {
  543. protected:
  544. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  545. MacroBuilder &Builder) const override {
  546. DefineStd(Builder, "sun", Opts);
  547. DefineStd(Builder, "unix", Opts);
  548. Builder.defineMacro("__ELF__");
  549. Builder.defineMacro("__svr4__");
  550. Builder.defineMacro("__SVR4");
  551. // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
  552. // newer, but to 500 for everything else. feature_test.h has a check to
  553. // ensure that you are not using C99 with an old version of X/Open or C89
  554. // with a new version.
  555. if (Opts.C99)
  556. Builder.defineMacro("_XOPEN_SOURCE", "600");
  557. else
  558. Builder.defineMacro("_XOPEN_SOURCE", "500");
  559. if (Opts.CPlusPlus)
  560. Builder.defineMacro("__C99FEATURES__");
  561. Builder.defineMacro("_LARGEFILE_SOURCE");
  562. Builder.defineMacro("_LARGEFILE64_SOURCE");
  563. Builder.defineMacro("__EXTENSIONS__");
  564. Builder.defineMacro("_REENTRANT");
  565. }
  566. public:
  567. SolarisTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  568. this->UserLabelPrefix = "";
  569. this->WCharType = this->SignedInt;
  570. // FIXME: WIntType should be SignedLong
  571. }
  572. };
  573. // Windows target
  574. template<typename Target>
  575. class WindowsTargetInfo : public OSTargetInfo<Target> {
  576. protected:
  577. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  578. MacroBuilder &Builder) const override {
  579. Builder.defineMacro("_WIN32");
  580. }
  581. void getVisualStudioDefines(const LangOptions &Opts,
  582. MacroBuilder &Builder) const {
  583. if (Opts.CPlusPlus) {
  584. if (Opts.RTTIData)
  585. Builder.defineMacro("_CPPRTTI");
  586. if (Opts.CXXExceptions)
  587. Builder.defineMacro("_CPPUNWIND");
  588. }
  589. if (!Opts.CharIsSigned)
  590. Builder.defineMacro("_CHAR_UNSIGNED");
  591. // FIXME: POSIXThreads isn't exactly the option this should be defined for,
  592. // but it works for now.
  593. if (Opts.POSIXThreads)
  594. Builder.defineMacro("_MT");
  595. if (Opts.MSCompatibilityVersion) {
  596. Builder.defineMacro("_MSC_VER",
  597. Twine(Opts.MSCompatibilityVersion / 100000));
  598. Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
  599. // FIXME We cannot encode the revision information into 32-bits
  600. Builder.defineMacro("_MSC_BUILD", Twine(1));
  601. if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
  602. Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
  603. }
  604. if (Opts.MicrosoftExt) {
  605. Builder.defineMacro("_MSC_EXTENSIONS");
  606. if (Opts.CPlusPlus11) {
  607. Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
  608. Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
  609. Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
  610. }
  611. }
  612. Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
  613. }
  614. public:
  615. WindowsTargetInfo(const llvm::Triple &Triple)
  616. : OSTargetInfo<Target>(Triple) {}
  617. };
  618. template <typename Target>
  619. class NaClTargetInfo : public OSTargetInfo<Target> {
  620. protected:
  621. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  622. MacroBuilder &Builder) const override {
  623. if (Opts.POSIXThreads)
  624. Builder.defineMacro("_REENTRANT");
  625. if (Opts.CPlusPlus)
  626. Builder.defineMacro("_GNU_SOURCE");
  627. DefineStd(Builder, "unix", Opts);
  628. Builder.defineMacro("__ELF__");
  629. Builder.defineMacro("__native_client__");
  630. }
  631. public:
  632. NaClTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  633. this->UserLabelPrefix = "";
  634. this->LongAlign = 32;
  635. this->LongWidth = 32;
  636. this->PointerAlign = 32;
  637. this->PointerWidth = 32;
  638. this->IntMaxType = TargetInfo::SignedLongLong;
  639. this->Int64Type = TargetInfo::SignedLongLong;
  640. this->DoubleAlign = 64;
  641. this->LongDoubleWidth = 64;
  642. this->LongDoubleAlign = 64;
  643. this->LongLongWidth = 64;
  644. this->LongLongAlign = 64;
  645. this->SizeType = TargetInfo::UnsignedInt;
  646. this->PtrDiffType = TargetInfo::SignedInt;
  647. this->IntPtrType = TargetInfo::SignedInt;
  648. // RegParmMax is inherited from the underlying architecture
  649. this->LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  650. if (Triple.getArch() == llvm::Triple::arm) {
  651. // Handled in ARM's setABI().
  652. } else if (Triple.getArch() == llvm::Triple::x86) {
  653. this->DescriptionString = "e-m:e-p:32:32-i64:64-n8:16:32-S128";
  654. } else if (Triple.getArch() == llvm::Triple::x86_64) {
  655. this->DescriptionString = "e-m:e-p:32:32-i64:64-n8:16:32:64-S128";
  656. } else if (Triple.getArch() == llvm::Triple::mipsel) {
  657. // Handled on mips' setDescriptionString.
  658. } else {
  659. assert(Triple.getArch() == llvm::Triple::le32);
  660. this->DescriptionString = "e-p:32:32-i64:64";
  661. }
  662. }
  663. };
  664. //===----------------------------------------------------------------------===//
  665. // Specific target implementations.
  666. //===----------------------------------------------------------------------===//
  667. // PPC abstract base class
  668. class PPCTargetInfo : public TargetInfo {
  669. static const Builtin::Info BuiltinInfo[];
  670. static const char * const GCCRegNames[];
  671. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  672. std::string CPU;
  673. // Target cpu features.
  674. bool HasVSX;
  675. bool HasP8Vector;
  676. bool HasP8Crypto;
  677. bool HasDirectMove;
  678. bool HasQPX;
  679. bool HasHTM;
  680. bool HasBPERMD;
  681. bool HasExtDiv;
  682. protected:
  683. std::string ABI;
  684. public:
  685. PPCTargetInfo(const llvm::Triple &Triple)
  686. : TargetInfo(Triple), HasVSX(false), HasP8Vector(false),
  687. HasP8Crypto(false), HasDirectMove(false), HasQPX(false), HasHTM(false),
  688. HasBPERMD(false), HasExtDiv(false) {
  689. BigEndian = (Triple.getArch() != llvm::Triple::ppc64le);
  690. SimdDefaultAlign = 128;
  691. LongDoubleWidth = LongDoubleAlign = 128;
  692. LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble;
  693. }
  694. /// \brief Flags for architecture specific defines.
  695. typedef enum {
  696. ArchDefineNone = 0,
  697. ArchDefineName = 1 << 0, // <name> is substituted for arch name.
  698. ArchDefinePpcgr = 1 << 1,
  699. ArchDefinePpcsq = 1 << 2,
  700. ArchDefine440 = 1 << 3,
  701. ArchDefine603 = 1 << 4,
  702. ArchDefine604 = 1 << 5,
  703. ArchDefinePwr4 = 1 << 6,
  704. ArchDefinePwr5 = 1 << 7,
  705. ArchDefinePwr5x = 1 << 8,
  706. ArchDefinePwr6 = 1 << 9,
  707. ArchDefinePwr6x = 1 << 10,
  708. ArchDefinePwr7 = 1 << 11,
  709. ArchDefinePwr8 = 1 << 12,
  710. ArchDefineA2 = 1 << 13,
  711. ArchDefineA2q = 1 << 14
  712. } ArchDefineTypes;
  713. // Note: GCC recognizes the following additional cpus:
  714. // 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801,
  715. // 821, 823, 8540, 8548, e300c2, e300c3, e500mc64, e6500, 860, cell,
  716. // titan, rs64.
  717. bool setCPU(const std::string &Name) override {
  718. bool CPUKnown = llvm::StringSwitch<bool>(Name)
  719. .Case("generic", true)
  720. .Case("440", true)
  721. .Case("450", true)
  722. .Case("601", true)
  723. .Case("602", true)
  724. .Case("603", true)
  725. .Case("603e", true)
  726. .Case("603ev", true)
  727. .Case("604", true)
  728. .Case("604e", true)
  729. .Case("620", true)
  730. .Case("630", true)
  731. .Case("g3", true)
  732. .Case("7400", true)
  733. .Case("g4", true)
  734. .Case("7450", true)
  735. .Case("g4+", true)
  736. .Case("750", true)
  737. .Case("970", true)
  738. .Case("g5", true)
  739. .Case("a2", true)
  740. .Case("a2q", true)
  741. .Case("e500mc", true)
  742. .Case("e5500", true)
  743. .Case("power3", true)
  744. .Case("pwr3", true)
  745. .Case("power4", true)
  746. .Case("pwr4", true)
  747. .Case("power5", true)
  748. .Case("pwr5", true)
  749. .Case("power5x", true)
  750. .Case("pwr5x", true)
  751. .Case("power6", true)
  752. .Case("pwr6", true)
  753. .Case("power6x", true)
  754. .Case("pwr6x", true)
  755. .Case("power7", true)
  756. .Case("pwr7", true)
  757. .Case("power8", true)
  758. .Case("pwr8", true)
  759. .Case("powerpc", true)
  760. .Case("ppc", true)
  761. .Case("powerpc64", true)
  762. .Case("ppc64", true)
  763. .Case("powerpc64le", true)
  764. .Case("ppc64le", true)
  765. .Default(false);
  766. if (CPUKnown)
  767. CPU = Name;
  768. return CPUKnown;
  769. }
  770. StringRef getABI() const override { return ABI; }
  771. void getTargetBuiltins(const Builtin::Info *&Records,
  772. unsigned &NumRecords) const override {
  773. Records = BuiltinInfo;
  774. NumRecords = clang::PPC::LastTSBuiltin-Builtin::FirstTSBuiltin;
  775. }
  776. bool isCLZForZeroUndef() const override { return false; }
  777. void getTargetDefines(const LangOptions &Opts,
  778. MacroBuilder &Builder) const override;
  779. void getDefaultFeatures(llvm::StringMap<bool> &Features) const override;
  780. bool handleTargetFeatures(std::vector<std::string> &Features,
  781. DiagnosticsEngine &Diags) override;
  782. bool hasFeature(StringRef Feature) const override;
  783. void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
  784. bool Enabled) const override;
  785. void getGCCRegNames(const char * const *&Names,
  786. unsigned &NumNames) const override;
  787. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  788. unsigned &NumAliases) const override;
  789. bool validateAsmConstraint(const char *&Name,
  790. TargetInfo::ConstraintInfo &Info) const override {
  791. switch (*Name) {
  792. default: return false;
  793. case 'O': // Zero
  794. break;
  795. case 'b': // Base register
  796. case 'f': // Floating point register
  797. Info.setAllowsRegister();
  798. break;
  799. // FIXME: The following are added to allow parsing.
  800. // I just took a guess at what the actions should be.
  801. // Also, is more specific checking needed? I.e. specific registers?
  802. case 'd': // Floating point register (containing 64-bit value)
  803. case 'v': // Altivec vector register
  804. Info.setAllowsRegister();
  805. break;
  806. case 'w':
  807. switch (Name[1]) {
  808. case 'd':// VSX vector register to hold vector double data
  809. case 'f':// VSX vector register to hold vector float data
  810. case 's':// VSX vector register to hold scalar float data
  811. case 'a':// Any VSX register
  812. case 'c':// An individual CR bit
  813. break;
  814. default:
  815. return false;
  816. }
  817. Info.setAllowsRegister();
  818. Name++; // Skip over 'w'.
  819. break;
  820. case 'h': // `MQ', `CTR', or `LINK' register
  821. case 'q': // `MQ' register
  822. case 'c': // `CTR' register
  823. case 'l': // `LINK' register
  824. case 'x': // `CR' register (condition register) number 0
  825. case 'y': // `CR' register (condition register)
  826. case 'z': // `XER[CA]' carry bit (part of the XER register)
  827. Info.setAllowsRegister();
  828. break;
  829. case 'I': // Signed 16-bit constant
  830. case 'J': // Unsigned 16-bit constant shifted left 16 bits
  831. // (use `L' instead for SImode constants)
  832. case 'K': // Unsigned 16-bit constant
  833. case 'L': // Signed 16-bit constant shifted left 16 bits
  834. case 'M': // Constant larger than 31
  835. case 'N': // Exact power of 2
  836. case 'P': // Constant whose negation is a signed 16-bit constant
  837. case 'G': // Floating point constant that can be loaded into a
  838. // register with one instruction per word
  839. case 'H': // Integer/Floating point constant that can be loaded
  840. // into a register using three instructions
  841. break;
  842. case 'm': // Memory operand. Note that on PowerPC targets, m can
  843. // include addresses that update the base register. It
  844. // is therefore only safe to use `m' in an asm statement
  845. // if that asm statement accesses the operand exactly once.
  846. // The asm statement must also use `%U<opno>' as a
  847. // placeholder for the "update" flag in the corresponding
  848. // load or store instruction. For example:
  849. // asm ("st%U0 %1,%0" : "=m" (mem) : "r" (val));
  850. // is correct but:
  851. // asm ("st %1,%0" : "=m" (mem) : "r" (val));
  852. // is not. Use es rather than m if you don't want the base
  853. // register to be updated.
  854. case 'e':
  855. if (Name[1] != 's')
  856. return false;
  857. // es: A "stable" memory operand; that is, one which does not
  858. // include any automodification of the base register. Unlike
  859. // `m', this constraint can be used in asm statements that
  860. // might access the operand several times, or that might not
  861. // access it at all.
  862. Info.setAllowsMemory();
  863. Name++; // Skip over 'e'.
  864. break;
  865. case 'Q': // Memory operand that is an offset from a register (it is
  866. // usually better to use `m' or `es' in asm statements)
  867. case 'Z': // Memory operand that is an indexed or indirect from a
  868. // register (it is usually better to use `m' or `es' in
  869. // asm statements)
  870. Info.setAllowsMemory();
  871. Info.setAllowsRegister();
  872. break;
  873. case 'R': // AIX TOC entry
  874. case 'a': // Address operand that is an indexed or indirect from a
  875. // register (`p' is preferable for asm statements)
  876. case 'S': // Constant suitable as a 64-bit mask operand
  877. case 'T': // Constant suitable as a 32-bit mask operand
  878. case 'U': // System V Release 4 small data area reference
  879. case 't': // AND masks that can be performed by two rldic{l, r}
  880. // instructions
  881. case 'W': // Vector constant that does not require memory
  882. case 'j': // Vector constant that is all zeros.
  883. break;
  884. // End FIXME.
  885. }
  886. return true;
  887. }
  888. std::string convertConstraint(const char *&Constraint) const override {
  889. std::string R;
  890. switch (*Constraint) {
  891. case 'e':
  892. case 'w':
  893. // Two-character constraint; add "^" hint for later parsing.
  894. R = std::string("^") + std::string(Constraint, 2);
  895. Constraint++;
  896. break;
  897. default:
  898. return TargetInfo::convertConstraint(Constraint);
  899. }
  900. return R;
  901. }
  902. const char *getClobbers() const override {
  903. return "";
  904. }
  905. int getEHDataRegisterNumber(unsigned RegNo) const override {
  906. if (RegNo == 0) return 3;
  907. if (RegNo == 1) return 4;
  908. return -1;
  909. }
  910. bool hasSjLjLowering() const override {
  911. return true;
  912. }
  913. bool useFloat128ManglingForLongDouble() const override {
  914. return LongDoubleWidth == 128 &&
  915. LongDoubleFormat == &llvm::APFloat::PPCDoubleDouble &&
  916. getTriple().isOSBinFormatELF();
  917. }
  918. };
  919. const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
  920. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  921. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  922. ALL_LANGUAGES },
  923. #include "clang/Basic/BuiltinsPPC.def"
  924. };
  925. /// handleTargetFeatures - Perform initialization based on the user
  926. /// configured set of features.
  927. bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
  928. DiagnosticsEngine &Diags) {
  929. for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
  930. // Ignore disabled features.
  931. if (Features[i][0] == '-')
  932. continue;
  933. StringRef Feature = StringRef(Features[i]).substr(1);
  934. if (Feature == "vsx") {
  935. HasVSX = true;
  936. continue;
  937. }
  938. if (Feature == "bpermd") {
  939. HasBPERMD = true;
  940. continue;
  941. }
  942. if (Feature == "extdiv") {
  943. HasExtDiv = true;
  944. continue;
  945. }
  946. if (Feature == "power8-vector") {
  947. HasP8Vector = true;
  948. continue;
  949. }
  950. if (Feature == "crypto") {
  951. HasP8Crypto = true;
  952. continue;
  953. }
  954. if (Feature == "direct-move") {
  955. HasDirectMove = true;
  956. continue;
  957. }
  958. if (Feature == "qpx") {
  959. HasQPX = true;
  960. continue;
  961. }
  962. if (Feature == "htm") {
  963. HasHTM = true;
  964. continue;
  965. }
  966. // TODO: Finish this list and add an assert that we've handled them
  967. // all.
  968. }
  969. if (!HasVSX && (HasP8Vector || HasDirectMove)) {
  970. if (HasP8Vector)
  971. Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower8-vector" <<
  972. "-mno-vsx";
  973. else if (HasDirectMove)
  974. Diags.Report(diag::err_opt_not_valid_with_opt) << "-mdirect-move" <<
  975. "-mno-vsx";
  976. return false;
  977. }
  978. return true;
  979. }
  980. /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
  981. /// #defines that are not tied to a specific subtarget.
  982. void PPCTargetInfo::getTargetDefines(const LangOptions &Opts,
  983. MacroBuilder &Builder) const {
  984. // Target identification.
  985. Builder.defineMacro("__ppc__");
  986. Builder.defineMacro("__PPC__");
  987. Builder.defineMacro("_ARCH_PPC");
  988. Builder.defineMacro("__powerpc__");
  989. Builder.defineMacro("__POWERPC__");
  990. if (PointerWidth == 64) {
  991. Builder.defineMacro("_ARCH_PPC64");
  992. Builder.defineMacro("__powerpc64__");
  993. Builder.defineMacro("__ppc64__");
  994. Builder.defineMacro("__PPC64__");
  995. }
  996. // Target properties.
  997. if (getTriple().getArch() == llvm::Triple::ppc64le) {
  998. Builder.defineMacro("_LITTLE_ENDIAN");
  999. } else {
  1000. if (getTriple().getOS() != llvm::Triple::NetBSD &&
  1001. getTriple().getOS() != llvm::Triple::OpenBSD)
  1002. Builder.defineMacro("_BIG_ENDIAN");
  1003. }
  1004. // ABI options.
  1005. if (ABI == "elfv1" || ABI == "elfv1-qpx")
  1006. Builder.defineMacro("_CALL_ELF", "1");
  1007. if (ABI == "elfv2")
  1008. Builder.defineMacro("_CALL_ELF", "2");
  1009. // Subtarget options.
  1010. Builder.defineMacro("__NATURAL_ALIGNMENT__");
  1011. Builder.defineMacro("__REGISTER_PREFIX__", "");
  1012. // FIXME: Should be controlled by command line option.
  1013. if (LongDoubleWidth == 128)
  1014. Builder.defineMacro("__LONG_DOUBLE_128__");
  1015. if (Opts.AltiVec) {
  1016. Builder.defineMacro("__VEC__", "10206");
  1017. Builder.defineMacro("__ALTIVEC__");
  1018. }
  1019. // CPU identification.
  1020. ArchDefineTypes defs = (ArchDefineTypes)llvm::StringSwitch<int>(CPU)
  1021. .Case("440", ArchDefineName)
  1022. .Case("450", ArchDefineName | ArchDefine440)
  1023. .Case("601", ArchDefineName)
  1024. .Case("602", ArchDefineName | ArchDefinePpcgr)
  1025. .Case("603", ArchDefineName | ArchDefinePpcgr)
  1026. .Case("603e", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
  1027. .Case("603ev", ArchDefineName | ArchDefine603 | ArchDefinePpcgr)
  1028. .Case("604", ArchDefineName | ArchDefinePpcgr)
  1029. .Case("604e", ArchDefineName | ArchDefine604 | ArchDefinePpcgr)
  1030. .Case("620", ArchDefineName | ArchDefinePpcgr)
  1031. .Case("630", ArchDefineName | ArchDefinePpcgr)
  1032. .Case("7400", ArchDefineName | ArchDefinePpcgr)
  1033. .Case("7450", ArchDefineName | ArchDefinePpcgr)
  1034. .Case("750", ArchDefineName | ArchDefinePpcgr)
  1035. .Case("970", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr
  1036. | ArchDefinePpcsq)
  1037. .Case("a2", ArchDefineA2)
  1038. .Case("a2q", ArchDefineName | ArchDefineA2 | ArchDefineA2q)
  1039. .Case("pwr3", ArchDefinePpcgr)
  1040. .Case("pwr4", ArchDefineName | ArchDefinePpcgr | ArchDefinePpcsq)
  1041. .Case("pwr5", ArchDefineName | ArchDefinePwr4 | ArchDefinePpcgr
  1042. | ArchDefinePpcsq)
  1043. .Case("pwr5x", ArchDefineName | ArchDefinePwr5 | ArchDefinePwr4
  1044. | ArchDefinePpcgr | ArchDefinePpcsq)
  1045. .Case("pwr6", ArchDefineName | ArchDefinePwr5x | ArchDefinePwr5
  1046. | ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
  1047. .Case("pwr6x", ArchDefineName | ArchDefinePwr6 | ArchDefinePwr5x
  1048. | ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr
  1049. | ArchDefinePpcsq)
  1050. .Case("pwr7", ArchDefineName | ArchDefinePwr6x | ArchDefinePwr6
  1051. | ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4
  1052. | ArchDefinePpcgr | ArchDefinePpcsq)
  1053. .Case("pwr8", ArchDefineName | ArchDefinePwr7 | ArchDefinePwr6x
  1054. | ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5
  1055. | ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
  1056. .Case("power3", ArchDefinePpcgr)
  1057. .Case("power4", ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
  1058. .Case("power5", ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr
  1059. | ArchDefinePpcsq)
  1060. .Case("power5x", ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4
  1061. | ArchDefinePpcgr | ArchDefinePpcsq)
  1062. .Case("power6", ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5
  1063. | ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
  1064. .Case("power6x", ArchDefinePwr6x | ArchDefinePwr6 | ArchDefinePwr5x
  1065. | ArchDefinePwr5 | ArchDefinePwr4 | ArchDefinePpcgr
  1066. | ArchDefinePpcsq)
  1067. .Case("power7", ArchDefinePwr7 | ArchDefinePwr6x | ArchDefinePwr6
  1068. | ArchDefinePwr5x | ArchDefinePwr5 | ArchDefinePwr4
  1069. | ArchDefinePpcgr | ArchDefinePpcsq)
  1070. .Case("power8", ArchDefinePwr8 | ArchDefinePwr7 | ArchDefinePwr6x
  1071. | ArchDefinePwr6 | ArchDefinePwr5x | ArchDefinePwr5
  1072. | ArchDefinePwr4 | ArchDefinePpcgr | ArchDefinePpcsq)
  1073. .Default(ArchDefineNone);
  1074. if (defs & ArchDefineName)
  1075. Builder.defineMacro(Twine("_ARCH_", StringRef(CPU).upper()));
  1076. if (defs & ArchDefinePpcgr)
  1077. Builder.defineMacro("_ARCH_PPCGR");
  1078. if (defs & ArchDefinePpcsq)
  1079. Builder.defineMacro("_ARCH_PPCSQ");
  1080. if (defs & ArchDefine440)
  1081. Builder.defineMacro("_ARCH_440");
  1082. if (defs & ArchDefine603)
  1083. Builder.defineMacro("_ARCH_603");
  1084. if (defs & ArchDefine604)
  1085. Builder.defineMacro("_ARCH_604");
  1086. if (defs & ArchDefinePwr4)
  1087. Builder.defineMacro("_ARCH_PWR4");
  1088. if (defs & ArchDefinePwr5)
  1089. Builder.defineMacro("_ARCH_PWR5");
  1090. if (defs & ArchDefinePwr5x)
  1091. Builder.defineMacro("_ARCH_PWR5X");
  1092. if (defs & ArchDefinePwr6)
  1093. Builder.defineMacro("_ARCH_PWR6");
  1094. if (defs & ArchDefinePwr6x)
  1095. Builder.defineMacro("_ARCH_PWR6X");
  1096. if (defs & ArchDefinePwr7)
  1097. Builder.defineMacro("_ARCH_PWR7");
  1098. if (defs & ArchDefinePwr8)
  1099. Builder.defineMacro("_ARCH_PWR8");
  1100. if (defs & ArchDefineA2)
  1101. Builder.defineMacro("_ARCH_A2");
  1102. if (defs & ArchDefineA2q) {
  1103. Builder.defineMacro("_ARCH_A2Q");
  1104. Builder.defineMacro("_ARCH_QP");
  1105. }
  1106. if (getTriple().getVendor() == llvm::Triple::BGQ) {
  1107. Builder.defineMacro("__bg__");
  1108. Builder.defineMacro("__THW_BLUEGENE__");
  1109. Builder.defineMacro("__bgq__");
  1110. Builder.defineMacro("__TOS_BGQ__");
  1111. }
  1112. if (HasVSX)
  1113. Builder.defineMacro("__VSX__");
  1114. if (HasP8Vector)
  1115. Builder.defineMacro("__POWER8_VECTOR__");
  1116. if (HasP8Crypto)
  1117. Builder.defineMacro("__CRYPTO__");
  1118. if (HasHTM)
  1119. Builder.defineMacro("__HTM__");
  1120. if (getTriple().getArch() == llvm::Triple::ppc64le ||
  1121. (defs & ArchDefinePwr8) || (CPU == "pwr8")) {
  1122. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
  1123. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
  1124. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
  1125. if (PointerWidth == 64)
  1126. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
  1127. }
  1128. // FIXME: The following are not yet generated here by Clang, but are
  1129. // generated by GCC:
  1130. //
  1131. // _SOFT_FLOAT_
  1132. // __RECIP_PRECISION__
  1133. // __APPLE_ALTIVEC__
  1134. // __RECIP__
  1135. // __RECIPF__
  1136. // __RSQRTE__
  1137. // __RSQRTEF__
  1138. // _SOFT_DOUBLE_
  1139. // __NO_LWSYNC__
  1140. // __HAVE_BSWAP__
  1141. // __LONGDOUBLE128
  1142. // __CMODEL_MEDIUM__
  1143. // __CMODEL_LARGE__
  1144. // _CALL_SYSV
  1145. // _CALL_DARWIN
  1146. // __NO_FPRS__
  1147. }
  1148. void PPCTargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
  1149. Features["altivec"] = llvm::StringSwitch<bool>(CPU)
  1150. .Case("7400", true)
  1151. .Case("g4", true)
  1152. .Case("7450", true)
  1153. .Case("g4+", true)
  1154. .Case("970", true)
  1155. .Case("g5", true)
  1156. .Case("pwr6", true)
  1157. .Case("pwr7", true)
  1158. .Case("pwr8", true)
  1159. .Case("ppc64", true)
  1160. .Case("ppc64le", true)
  1161. .Default(false);
  1162. Features["qpx"] = (CPU == "a2q");
  1163. Features["crypto"] = llvm::StringSwitch<bool>(CPU)
  1164. .Case("ppc64le", true)
  1165. .Case("pwr8", true)
  1166. .Default(false);
  1167. Features["power8-vector"] = llvm::StringSwitch<bool>(CPU)
  1168. .Case("ppc64le", true)
  1169. .Case("pwr8", true)
  1170. .Default(false);
  1171. Features["bpermd"] = llvm::StringSwitch<bool>(CPU)
  1172. .Case("ppc64le", true)
  1173. .Case("pwr8", true)
  1174. .Case("pwr7", true)
  1175. .Default(false);
  1176. Features["extdiv"] = llvm::StringSwitch<bool>(CPU)
  1177. .Case("ppc64le", true)
  1178. .Case("pwr8", true)
  1179. .Case("pwr7", true)
  1180. .Default(false);
  1181. Features["direct-move"] = llvm::StringSwitch<bool>(CPU)
  1182. .Case("ppc64le", true)
  1183. .Case("pwr8", true)
  1184. .Default(false);
  1185. Features["vsx"] = llvm::StringSwitch<bool>(CPU)
  1186. .Case("ppc64le", true)
  1187. .Case("pwr8", true)
  1188. .Case("pwr7", true)
  1189. .Default(false);
  1190. }
  1191. bool PPCTargetInfo::hasFeature(StringRef Feature) const {
  1192. return llvm::StringSwitch<bool>(Feature)
  1193. .Case("powerpc", true)
  1194. .Case("vsx", HasVSX)
  1195. .Case("power8-vector", HasP8Vector)
  1196. .Case("crypto", HasP8Crypto)
  1197. .Case("direct-move", HasDirectMove)
  1198. .Case("qpx", HasQPX)
  1199. .Case("htm", HasHTM)
  1200. .Case("bpermd", HasBPERMD)
  1201. .Case("extdiv", HasExtDiv)
  1202. .Default(false);
  1203. }
  1204. /* There is no clear way for the target to know which of the features in the
  1205. final feature vector came from defaults and which are actually specified by
  1206. the user. To that end, we use the fact that this function is not called on
  1207. default features - only user specified ones. By the first time this
  1208. function is called, the default features are populated.
  1209. We then keep track of the features that the user specified so that we
  1210. can ensure we do not override a user's request (only defaults).
  1211. For example:
  1212. -mcpu=pwr8 -mno-vsx (should disable vsx and everything that depends on it)
  1213. -mcpu=pwr8 -mdirect-move -mno-vsx (should actually be diagnosed)
  1214. NOTE: Do not call this from PPCTargetInfo::getDefaultFeatures
  1215. */
  1216. void PPCTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
  1217. StringRef Name, bool Enabled) const {
  1218. static llvm::StringMap<bool> ExplicitFeatures;
  1219. ExplicitFeatures[Name] = Enabled;
  1220. // At this point, -mno-vsx turns off the dependent features but we respect
  1221. // the user's requests.
  1222. if (!Enabled && Name == "vsx") {
  1223. Features["direct-move"] = ExplicitFeatures["direct-move"];
  1224. Features["power8-vector"] = ExplicitFeatures["power8-vector"];
  1225. }
  1226. if ((Enabled && Name == "power8-vector") ||
  1227. (Enabled && Name == "direct-move")) {
  1228. if (ExplicitFeatures.find("vsx") == ExplicitFeatures.end()) {
  1229. Features["vsx"] = true;
  1230. }
  1231. }
  1232. Features[Name] = Enabled;
  1233. }
  1234. const char * const PPCTargetInfo::GCCRegNames[] = {
  1235. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  1236. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  1237. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  1238. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
  1239. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
  1240. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
  1241. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
  1242. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
  1243. "mq", "lr", "ctr", "ap",
  1244. "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
  1245. "xer",
  1246. "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1247. "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
  1248. "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
  1249. "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
  1250. "vrsave", "vscr",
  1251. "spe_acc", "spefscr",
  1252. "sfp"
  1253. };
  1254. void PPCTargetInfo::getGCCRegNames(const char * const *&Names,
  1255. unsigned &NumNames) const {
  1256. Names = GCCRegNames;
  1257. NumNames = llvm::array_lengthof(GCCRegNames);
  1258. }
  1259. const TargetInfo::GCCRegAlias PPCTargetInfo::GCCRegAliases[] = {
  1260. // While some of these aliases do map to different registers
  1261. // they still share the same register name.
  1262. { { "0" }, "r0" },
  1263. { { "1"}, "r1" },
  1264. { { "2" }, "r2" },
  1265. { { "3" }, "r3" },
  1266. { { "4" }, "r4" },
  1267. { { "5" }, "r5" },
  1268. { { "6" }, "r6" },
  1269. { { "7" }, "r7" },
  1270. { { "8" }, "r8" },
  1271. { { "9" }, "r9" },
  1272. { { "10" }, "r10" },
  1273. { { "11" }, "r11" },
  1274. { { "12" }, "r12" },
  1275. { { "13" }, "r13" },
  1276. { { "14" }, "r14" },
  1277. { { "15" }, "r15" },
  1278. { { "16" }, "r16" },
  1279. { { "17" }, "r17" },
  1280. { { "18" }, "r18" },
  1281. { { "19" }, "r19" },
  1282. { { "20" }, "r20" },
  1283. { { "21" }, "r21" },
  1284. { { "22" }, "r22" },
  1285. { { "23" }, "r23" },
  1286. { { "24" }, "r24" },
  1287. { { "25" }, "r25" },
  1288. { { "26" }, "r26" },
  1289. { { "27" }, "r27" },
  1290. { { "28" }, "r28" },
  1291. { { "29" }, "r29" },
  1292. { { "30" }, "r30" },
  1293. { { "31" }, "r31" },
  1294. { { "fr0" }, "f0" },
  1295. { { "fr1" }, "f1" },
  1296. { { "fr2" }, "f2" },
  1297. { { "fr3" }, "f3" },
  1298. { { "fr4" }, "f4" },
  1299. { { "fr5" }, "f5" },
  1300. { { "fr6" }, "f6" },
  1301. { { "fr7" }, "f7" },
  1302. { { "fr8" }, "f8" },
  1303. { { "fr9" }, "f9" },
  1304. { { "fr10" }, "f10" },
  1305. { { "fr11" }, "f11" },
  1306. { { "fr12" }, "f12" },
  1307. { { "fr13" }, "f13" },
  1308. { { "fr14" }, "f14" },
  1309. { { "fr15" }, "f15" },
  1310. { { "fr16" }, "f16" },
  1311. { { "fr17" }, "f17" },
  1312. { { "fr18" }, "f18" },
  1313. { { "fr19" }, "f19" },
  1314. { { "fr20" }, "f20" },
  1315. { { "fr21" }, "f21" },
  1316. { { "fr22" }, "f22" },
  1317. { { "fr23" }, "f23" },
  1318. { { "fr24" }, "f24" },
  1319. { { "fr25" }, "f25" },
  1320. { { "fr26" }, "f26" },
  1321. { { "fr27" }, "f27" },
  1322. { { "fr28" }, "f28" },
  1323. { { "fr29" }, "f29" },
  1324. { { "fr30" }, "f30" },
  1325. { { "fr31" }, "f31" },
  1326. { { "cc" }, "cr0" },
  1327. };
  1328. void PPCTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
  1329. unsigned &NumAliases) const {
  1330. Aliases = GCCRegAliases;
  1331. NumAliases = llvm::array_lengthof(GCCRegAliases);
  1332. }
  1333. class PPC32TargetInfo : public PPCTargetInfo {
  1334. public:
  1335. PPC32TargetInfo(const llvm::Triple &Triple) : PPCTargetInfo(Triple) {
  1336. DescriptionString = "E-m:e-p:32:32-i64:64-n32";
  1337. switch (getTriple().getOS()) {
  1338. case llvm::Triple::Linux:
  1339. case llvm::Triple::FreeBSD:
  1340. case llvm::Triple::NetBSD:
  1341. SizeType = UnsignedInt;
  1342. PtrDiffType = SignedInt;
  1343. IntPtrType = SignedInt;
  1344. break;
  1345. default:
  1346. break;
  1347. }
  1348. if (getTriple().getOS() == llvm::Triple::FreeBSD) {
  1349. LongDoubleWidth = LongDoubleAlign = 64;
  1350. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  1351. }
  1352. // PPC32 supports atomics up to 4 bytes.
  1353. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
  1354. }
  1355. BuiltinVaListKind getBuiltinVaListKind() const override {
  1356. // This is the ELF definition, and is overridden by the Darwin sub-target
  1357. return TargetInfo::PowerABIBuiltinVaList;
  1358. }
  1359. };
  1360. // Note: ABI differences may eventually require us to have a separate
  1361. // TargetInfo for little endian.
  1362. class PPC64TargetInfo : public PPCTargetInfo {
  1363. public:
  1364. PPC64TargetInfo(const llvm::Triple &Triple) : PPCTargetInfo(Triple) {
  1365. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  1366. IntMaxType = SignedLong;
  1367. Int64Type = SignedLong;
  1368. if ((Triple.getArch() == llvm::Triple::ppc64le)) {
  1369. DescriptionString = "e-m:e-i64:64-n32:64";
  1370. ABI = "elfv2";
  1371. } else {
  1372. DescriptionString = "E-m:e-i64:64-n32:64";
  1373. ABI = "elfv1";
  1374. }
  1375. switch (getTriple().getOS()) {
  1376. case llvm::Triple::FreeBSD:
  1377. LongDoubleWidth = LongDoubleAlign = 64;
  1378. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  1379. break;
  1380. case llvm::Triple::NetBSD:
  1381. IntMaxType = SignedLongLong;
  1382. Int64Type = SignedLongLong;
  1383. break;
  1384. default:
  1385. break;
  1386. }
  1387. // PPC64 supports atomics up to 8 bytes.
  1388. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  1389. }
  1390. BuiltinVaListKind getBuiltinVaListKind() const override {
  1391. return TargetInfo::CharPtrBuiltinVaList;
  1392. }
  1393. // PPC64 Linux-specific ABI options.
  1394. bool setABI(const std::string &Name) override {
  1395. if (Name == "elfv1" || Name == "elfv1-qpx" || Name == "elfv2") {
  1396. ABI = Name;
  1397. return true;
  1398. }
  1399. return false;
  1400. }
  1401. };
  1402. class DarwinPPC32TargetInfo :
  1403. public DarwinTargetInfo<PPC32TargetInfo> {
  1404. public:
  1405. DarwinPPC32TargetInfo(const llvm::Triple &Triple)
  1406. : DarwinTargetInfo<PPC32TargetInfo>(Triple) {
  1407. HasAlignMac68kSupport = true;
  1408. BoolWidth = BoolAlign = 32; //XXX support -mone-byte-bool?
  1409. PtrDiffType = SignedInt; // for http://llvm.org/bugs/show_bug.cgi?id=15726
  1410. LongLongAlign = 32;
  1411. SuitableAlign = 128;
  1412. DescriptionString = "E-m:o-p:32:32-f64:32:64-n32";
  1413. }
  1414. BuiltinVaListKind getBuiltinVaListKind() const override {
  1415. return TargetInfo::CharPtrBuiltinVaList;
  1416. }
  1417. };
  1418. class DarwinPPC64TargetInfo :
  1419. public DarwinTargetInfo<PPC64TargetInfo> {
  1420. public:
  1421. DarwinPPC64TargetInfo(const llvm::Triple &Triple)
  1422. : DarwinTargetInfo<PPC64TargetInfo>(Triple) {
  1423. HasAlignMac68kSupport = true;
  1424. SuitableAlign = 128;
  1425. DescriptionString = "E-m:o-i64:64-n32:64";
  1426. }
  1427. };
  1428. static const unsigned NVPTXAddrSpaceMap[] = {
  1429. 1, // opencl_global
  1430. 3, // opencl_local
  1431. 4, // opencl_constant
  1432. // FIXME: generic has to be added to the target
  1433. 0, // opencl_generic
  1434. 1, // cuda_device
  1435. 4, // cuda_constant
  1436. 3, // cuda_shared
  1437. };
  1438. class NVPTXTargetInfo : public TargetInfo {
  1439. static const char * const GCCRegNames[];
  1440. static const Builtin::Info BuiltinInfo[];
  1441. // The GPU profiles supported by the NVPTX backend
  1442. enum GPUKind {
  1443. GK_NONE,
  1444. GK_SM20,
  1445. GK_SM21,
  1446. GK_SM30,
  1447. GK_SM35,
  1448. GK_SM37,
  1449. } GPU;
  1450. public:
  1451. NVPTXTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  1452. BigEndian = false;
  1453. TLSSupported = false;
  1454. LongWidth = LongAlign = 64;
  1455. AddrSpaceMap = &NVPTXAddrSpaceMap;
  1456. UseAddrSpaceMapMangling = true;
  1457. // Define available target features
  1458. // These must be defined in sorted order!
  1459. NoAsmVariants = true;
  1460. // Set the default GPU to sm20
  1461. GPU = GK_SM20;
  1462. }
  1463. void getTargetDefines(const LangOptions &Opts,
  1464. MacroBuilder &Builder) const override {
  1465. Builder.defineMacro("__PTX__");
  1466. Builder.defineMacro("__NVPTX__");
  1467. if (Opts.CUDAIsDevice) {
  1468. // Set __CUDA_ARCH__ for the GPU specified.
  1469. std::string CUDAArchCode;
  1470. switch (GPU) {
  1471. case GK_SM20:
  1472. CUDAArchCode = "200";
  1473. break;
  1474. case GK_SM21:
  1475. CUDAArchCode = "210";
  1476. break;
  1477. case GK_SM30:
  1478. CUDAArchCode = "300";
  1479. break;
  1480. case GK_SM35:
  1481. CUDAArchCode = "350";
  1482. break;
  1483. case GK_SM37:
  1484. CUDAArchCode = "370";
  1485. break;
  1486. default:
  1487. llvm_unreachable("Unhandled target CPU");
  1488. }
  1489. Builder.defineMacro("__CUDA_ARCH__", CUDAArchCode);
  1490. }
  1491. }
  1492. void getTargetBuiltins(const Builtin::Info *&Records,
  1493. unsigned &NumRecords) const override {
  1494. Records = BuiltinInfo;
  1495. NumRecords = clang::NVPTX::LastTSBuiltin-Builtin::FirstTSBuiltin;
  1496. }
  1497. bool hasFeature(StringRef Feature) const override {
  1498. return Feature == "ptx" || Feature == "nvptx";
  1499. }
  1500. void getGCCRegNames(const char * const *&Names,
  1501. unsigned &NumNames) const override;
  1502. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  1503. unsigned &NumAliases) const override {
  1504. // No aliases.
  1505. Aliases = nullptr;
  1506. NumAliases = 0;
  1507. }
  1508. bool
  1509. validateAsmConstraint(const char *&Name,
  1510. TargetInfo::ConstraintInfo &Info) const override {
  1511. switch (*Name) {
  1512. default: return false;
  1513. case 'c':
  1514. case 'h':
  1515. case 'r':
  1516. case 'l':
  1517. case 'f':
  1518. case 'd':
  1519. Info.setAllowsRegister();
  1520. return true;
  1521. }
  1522. }
  1523. const char *getClobbers() const override {
  1524. // FIXME: Is this really right?
  1525. return "";
  1526. }
  1527. BuiltinVaListKind getBuiltinVaListKind() const override {
  1528. // FIXME: implement
  1529. return TargetInfo::CharPtrBuiltinVaList;
  1530. }
  1531. bool setCPU(const std::string &Name) override {
  1532. GPU = llvm::StringSwitch<GPUKind>(Name)
  1533. .Case("sm_20", GK_SM20)
  1534. .Case("sm_21", GK_SM21)
  1535. .Case("sm_30", GK_SM30)
  1536. .Case("sm_35", GK_SM35)
  1537. .Case("sm_37", GK_SM37)
  1538. .Default(GK_NONE);
  1539. return GPU != GK_NONE;
  1540. }
  1541. };
  1542. const Builtin::Info NVPTXTargetInfo::BuiltinInfo[] = {
  1543. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  1544. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  1545. ALL_LANGUAGES },
  1546. #include "clang/Basic/BuiltinsNVPTX.def"
  1547. };
  1548. const char * const NVPTXTargetInfo::GCCRegNames[] = {
  1549. "r0"
  1550. };
  1551. void NVPTXTargetInfo::getGCCRegNames(const char * const *&Names,
  1552. unsigned &NumNames) const {
  1553. Names = GCCRegNames;
  1554. NumNames = llvm::array_lengthof(GCCRegNames);
  1555. }
  1556. class NVPTX32TargetInfo : public NVPTXTargetInfo {
  1557. public:
  1558. NVPTX32TargetInfo(const llvm::Triple &Triple) : NVPTXTargetInfo(Triple) {
  1559. PointerWidth = PointerAlign = 32;
  1560. SizeType = TargetInfo::UnsignedInt;
  1561. PtrDiffType = TargetInfo::SignedInt;
  1562. IntPtrType = TargetInfo::SignedInt;
  1563. DescriptionString = "e-p:32:32-i64:64-v16:16-v32:32-n16:32:64";
  1564. }
  1565. };
  1566. class NVPTX64TargetInfo : public NVPTXTargetInfo {
  1567. public:
  1568. NVPTX64TargetInfo(const llvm::Triple &Triple) : NVPTXTargetInfo(Triple) {
  1569. PointerWidth = PointerAlign = 64;
  1570. SizeType = TargetInfo::UnsignedLong;
  1571. PtrDiffType = TargetInfo::SignedLong;
  1572. IntPtrType = TargetInfo::SignedLong;
  1573. DescriptionString = "e-i64:64-v16:16-v32:32-n16:32:64";
  1574. }
  1575. };
  1576. static const unsigned AMDGPUAddrSpaceMap[] = {
  1577. 1, // opencl_global
  1578. 3, // opencl_local
  1579. 2, // opencl_constant
  1580. 4, // opencl_generic
  1581. 1, // cuda_device
  1582. 2, // cuda_constant
  1583. 3 // cuda_shared
  1584. };
  1585. // If you edit the description strings, make sure you update
  1586. // getPointerWidthV().
  1587. static const char *DescriptionStringR600 =
  1588. "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
  1589. "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64";
  1590. static const char *DescriptionStringR600DoubleOps =
  1591. "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
  1592. "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64";
  1593. static const char *DescriptionStringSI =
  1594. "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32-p24:64:64"
  1595. "-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
  1596. "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64";
  1597. class AMDGPUTargetInfo : public TargetInfo {
  1598. static const Builtin::Info BuiltinInfo[];
  1599. static const char * const GCCRegNames[];
  1600. /// \brief The GPU profiles supported by the AMDGPU target.
  1601. enum GPUKind {
  1602. GK_NONE,
  1603. GK_R600,
  1604. GK_R600_DOUBLE_OPS,
  1605. GK_R700,
  1606. GK_R700_DOUBLE_OPS,
  1607. GK_EVERGREEN,
  1608. GK_EVERGREEN_DOUBLE_OPS,
  1609. GK_NORTHERN_ISLANDS,
  1610. GK_CAYMAN,
  1611. GK_SOUTHERN_ISLANDS,
  1612. GK_SEA_ISLANDS,
  1613. GK_VOLCANIC_ISLANDS
  1614. } GPU;
  1615. bool hasFP64:1;
  1616. bool hasFMAF:1;
  1617. bool hasLDEXPF:1;
  1618. public:
  1619. AMDGPUTargetInfo(const llvm::Triple &Triple)
  1620. : TargetInfo(Triple) {
  1621. if (Triple.getArch() == llvm::Triple::amdgcn) {
  1622. DescriptionString = DescriptionStringSI;
  1623. GPU = GK_SOUTHERN_ISLANDS;
  1624. hasFP64 = true;
  1625. hasFMAF = true;
  1626. hasLDEXPF = true;
  1627. } else {
  1628. DescriptionString = DescriptionStringR600;
  1629. GPU = GK_R600;
  1630. hasFP64 = false;
  1631. hasFMAF = false;
  1632. hasLDEXPF = false;
  1633. }
  1634. AddrSpaceMap = &AMDGPUAddrSpaceMap;
  1635. UseAddrSpaceMapMangling = true;
  1636. }
  1637. uint64_t getPointerWidthV(unsigned AddrSpace) const override {
  1638. if (GPU <= GK_CAYMAN)
  1639. return 32;
  1640. switch(AddrSpace) {
  1641. default:
  1642. return 64;
  1643. case 0:
  1644. case 3:
  1645. case 5:
  1646. return 32;
  1647. }
  1648. }
  1649. const char * getClobbers() const override {
  1650. return "";
  1651. }
  1652. void getGCCRegNames(const char * const *&Names,
  1653. unsigned &NumNames) const override;
  1654. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  1655. unsigned &NumAliases) const override {
  1656. Aliases = nullptr;
  1657. NumAliases = 0;
  1658. }
  1659. bool validateAsmConstraint(const char *&Name,
  1660. TargetInfo::ConstraintInfo &info) const override {
  1661. return true;
  1662. }
  1663. void getTargetBuiltins(const Builtin::Info *&Records,
  1664. unsigned &NumRecords) const override {
  1665. Records = BuiltinInfo;
  1666. NumRecords = clang::AMDGPU::LastTSBuiltin - Builtin::FirstTSBuiltin;
  1667. }
  1668. void getTargetDefines(const LangOptions &Opts,
  1669. MacroBuilder &Builder) const override {
  1670. Builder.defineMacro("__R600__");
  1671. if (hasFMAF)
  1672. Builder.defineMacro("__HAS_FMAF__");
  1673. if (hasLDEXPF)
  1674. Builder.defineMacro("__HAS_LDEXPF__");
  1675. if (hasFP64 && Opts.OpenCL) {
  1676. Builder.defineMacro("cl_khr_fp64");
  1677. }
  1678. }
  1679. BuiltinVaListKind getBuiltinVaListKind() const override {
  1680. return TargetInfo::CharPtrBuiltinVaList;
  1681. }
  1682. bool setCPU(const std::string &Name) override {
  1683. GPU = llvm::StringSwitch<GPUKind>(Name)
  1684. .Case("r600" , GK_R600)
  1685. .Case("rv610", GK_R600)
  1686. .Case("rv620", GK_R600)
  1687. .Case("rv630", GK_R600)
  1688. .Case("rv635", GK_R600)
  1689. .Case("rs780", GK_R600)
  1690. .Case("rs880", GK_R600)
  1691. .Case("rv670", GK_R600_DOUBLE_OPS)
  1692. .Case("rv710", GK_R700)
  1693. .Case("rv730", GK_R700)
  1694. .Case("rv740", GK_R700_DOUBLE_OPS)
  1695. .Case("rv770", GK_R700_DOUBLE_OPS)
  1696. .Case("palm", GK_EVERGREEN)
  1697. .Case("cedar", GK_EVERGREEN)
  1698. .Case("sumo", GK_EVERGREEN)
  1699. .Case("sumo2", GK_EVERGREEN)
  1700. .Case("redwood", GK_EVERGREEN)
  1701. .Case("juniper", GK_EVERGREEN)
  1702. .Case("hemlock", GK_EVERGREEN_DOUBLE_OPS)
  1703. .Case("cypress", GK_EVERGREEN_DOUBLE_OPS)
  1704. .Case("barts", GK_NORTHERN_ISLANDS)
  1705. .Case("turks", GK_NORTHERN_ISLANDS)
  1706. .Case("caicos", GK_NORTHERN_ISLANDS)
  1707. .Case("cayman", GK_CAYMAN)
  1708. .Case("aruba", GK_CAYMAN)
  1709. .Case("tahiti", GK_SOUTHERN_ISLANDS)
  1710. .Case("pitcairn", GK_SOUTHERN_ISLANDS)
  1711. .Case("verde", GK_SOUTHERN_ISLANDS)
  1712. .Case("oland", GK_SOUTHERN_ISLANDS)
  1713. .Case("hainan", GK_SOUTHERN_ISLANDS)
  1714. .Case("bonaire", GK_SEA_ISLANDS)
  1715. .Case("kabini", GK_SEA_ISLANDS)
  1716. .Case("kaveri", GK_SEA_ISLANDS)
  1717. .Case("hawaii", GK_SEA_ISLANDS)
  1718. .Case("mullins", GK_SEA_ISLANDS)
  1719. .Case("tonga", GK_VOLCANIC_ISLANDS)
  1720. .Case("iceland", GK_VOLCANIC_ISLANDS)
  1721. .Case("carrizo", GK_VOLCANIC_ISLANDS)
  1722. .Default(GK_NONE);
  1723. if (GPU == GK_NONE) {
  1724. return false;
  1725. }
  1726. // Set the correct data layout
  1727. switch (GPU) {
  1728. case GK_NONE:
  1729. case GK_R600:
  1730. case GK_R700:
  1731. case GK_EVERGREEN:
  1732. case GK_NORTHERN_ISLANDS:
  1733. DescriptionString = DescriptionStringR600;
  1734. hasFP64 = false;
  1735. hasFMAF = false;
  1736. hasLDEXPF = false;
  1737. break;
  1738. case GK_R600_DOUBLE_OPS:
  1739. case GK_R700_DOUBLE_OPS:
  1740. case GK_EVERGREEN_DOUBLE_OPS:
  1741. case GK_CAYMAN:
  1742. DescriptionString = DescriptionStringR600DoubleOps;
  1743. hasFP64 = true;
  1744. hasFMAF = true;
  1745. hasLDEXPF = false;
  1746. break;
  1747. case GK_SOUTHERN_ISLANDS:
  1748. case GK_SEA_ISLANDS:
  1749. case GK_VOLCANIC_ISLANDS:
  1750. DescriptionString = DescriptionStringSI;
  1751. hasFP64 = true;
  1752. hasFMAF = true;
  1753. hasLDEXPF = true;
  1754. break;
  1755. }
  1756. return true;
  1757. }
  1758. };
  1759. const Builtin::Info AMDGPUTargetInfo::BuiltinInfo[] = {
  1760. #define BUILTIN(ID, TYPE, ATTRS) \
  1761. { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  1762. #include "clang/Basic/BuiltinsAMDGPU.def"
  1763. };
  1764. const char * const AMDGPUTargetInfo::GCCRegNames[] = {
  1765. "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
  1766. "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
  1767. "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
  1768. "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
  1769. "v32", "v33", "v34", "v35", "v36", "v37", "v38", "v39",
  1770. "v40", "v41", "v42", "v43", "v44", "v45", "v46", "v47",
  1771. "v48", "v49", "v50", "v51", "v52", "v53", "v54", "v55",
  1772. "v56", "v57", "v58", "v59", "v60", "v61", "v62", "v63",
  1773. "v64", "v65", "v66", "v67", "v68", "v69", "v70", "v71",
  1774. "v72", "v73", "v74", "v75", "v76", "v77", "v78", "v79",
  1775. "v80", "v81", "v82", "v83", "v84", "v85", "v86", "v87",
  1776. "v88", "v89", "v90", "v91", "v92", "v93", "v94", "v95",
  1777. "v96", "v97", "v98", "v99", "v100", "v101", "v102", "v103",
  1778. "v104", "v105", "v106", "v107", "v108", "v109", "v110", "v111",
  1779. "v112", "v113", "v114", "v115", "v116", "v117", "v118", "v119",
  1780. "v120", "v121", "v122", "v123", "v124", "v125", "v126", "v127",
  1781. "v128", "v129", "v130", "v131", "v132", "v133", "v134", "v135",
  1782. "v136", "v137", "v138", "v139", "v140", "v141", "v142", "v143",
  1783. "v144", "v145", "v146", "v147", "v148", "v149", "v150", "v151",
  1784. "v152", "v153", "v154", "v155", "v156", "v157", "v158", "v159",
  1785. "v160", "v161", "v162", "v163", "v164", "v165", "v166", "v167",
  1786. "v168", "v169", "v170", "v171", "v172", "v173", "v174", "v175",
  1787. "v176", "v177", "v178", "v179", "v180", "v181", "v182", "v183",
  1788. "v184", "v185", "v186", "v187", "v188", "v189", "v190", "v191",
  1789. "v192", "v193", "v194", "v195", "v196", "v197", "v198", "v199",
  1790. "v200", "v201", "v202", "v203", "v204", "v205", "v206", "v207",
  1791. "v208", "v209", "v210", "v211", "v212", "v213", "v214", "v215",
  1792. "v216", "v217", "v218", "v219", "v220", "v221", "v222", "v223",
  1793. "v224", "v225", "v226", "v227", "v228", "v229", "v230", "v231",
  1794. "v232", "v233", "v234", "v235", "v236", "v237", "v238", "v239",
  1795. "v240", "v241", "v242", "v243", "v244", "v245", "v246", "v247",
  1796. "v248", "v249", "v250", "v251", "v252", "v253", "v254", "v255",
  1797. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  1798. "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
  1799. "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
  1800. "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
  1801. "s32", "s33", "s34", "s35", "s36", "s37", "s38", "s39",
  1802. "s40", "s41", "s42", "s43", "s44", "s45", "s46", "s47",
  1803. "s48", "s49", "s50", "s51", "s52", "s53", "s54", "s55",
  1804. "s56", "s57", "s58", "s59", "s60", "s61", "s62", "s63",
  1805. "s64", "s65", "s66", "s67", "s68", "s69", "s70", "s71",
  1806. "s72", "s73", "s74", "s75", "s76", "s77", "s78", "s79",
  1807. "s80", "s81", "s82", "s83", "s84", "s85", "s86", "s87",
  1808. "s88", "s89", "s90", "s91", "s92", "s93", "s94", "s95",
  1809. "s96", "s97", "s98", "s99", "s100", "s101", "s102", "s103",
  1810. "s104", "s105", "s106", "s107", "s108", "s109", "s110", "s111",
  1811. "s112", "s113", "s114", "s115", "s116", "s117", "s118", "s119",
  1812. "s120", "s121", "s122", "s123", "s124", "s125", "s126", "s127"
  1813. "exec", "vcc", "scc", "m0", "flat_scr", "exec_lo", "exec_hi",
  1814. "vcc_lo", "vcc_hi", "flat_scr_lo", "flat_scr_hi"
  1815. };
  1816. void AMDGPUTargetInfo::getGCCRegNames(const char * const *&Names,
  1817. unsigned &NumNames) const {
  1818. Names = GCCRegNames;
  1819. NumNames = llvm::array_lengthof(GCCRegNames);
  1820. }
  1821. // Namespace for x86 abstract base class
  1822. const Builtin::Info BuiltinInfo[] = {
  1823. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  1824. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  1825. ALL_LANGUAGES },
  1826. #include "clang/Basic/BuiltinsX86.def"
  1827. };
  1828. static const char* const GCCRegNames[] = {
  1829. "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
  1830. "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)",
  1831. "argp", "flags", "fpcr", "fpsr", "dirflag", "frame",
  1832. "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
  1833. "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7",
  1834. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  1835. "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
  1836. "ymm0", "ymm1", "ymm2", "ymm3", "ymm4", "ymm5", "ymm6", "ymm7",
  1837. "ymm8", "ymm9", "ymm10", "ymm11", "ymm12", "ymm13", "ymm14", "ymm15",
  1838. };
  1839. const TargetInfo::AddlRegName AddlRegNames[] = {
  1840. { { "al", "ah", "eax", "rax" }, 0 },
  1841. { { "bl", "bh", "ebx", "rbx" }, 3 },
  1842. { { "cl", "ch", "ecx", "rcx" }, 2 },
  1843. { { "dl", "dh", "edx", "rdx" }, 1 },
  1844. { { "esi", "rsi" }, 4 },
  1845. { { "edi", "rdi" }, 5 },
  1846. { { "esp", "rsp" }, 7 },
  1847. { { "ebp", "rbp" }, 6 },
  1848. };
  1849. // X86 target abstract base class; x86-32 and x86-64 are very close, so
  1850. // most of the implementation can be shared.
  1851. class X86TargetInfo : public TargetInfo {
  1852. enum X86SSEEnum {
  1853. NoSSE, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42, AVX, AVX2, AVX512F
  1854. } SSELevel;
  1855. enum MMX3DNowEnum {
  1856. NoMMX3DNow, MMX, AMD3DNow, AMD3DNowAthlon
  1857. } MMX3DNowLevel;
  1858. enum XOPEnum {
  1859. NoXOP,
  1860. SSE4A,
  1861. FMA4,
  1862. XOP
  1863. } XOPLevel;
  1864. bool HasAES;
  1865. bool HasPCLMUL;
  1866. bool HasLZCNT;
  1867. bool HasRDRND;
  1868. bool HasFSGSBASE;
  1869. bool HasBMI;
  1870. bool HasBMI2;
  1871. bool HasPOPCNT;
  1872. bool HasRTM;
  1873. bool HasPRFCHW;
  1874. bool HasRDSEED;
  1875. bool HasADX;
  1876. bool HasTBM;
  1877. bool HasFMA;
  1878. bool HasF16C;
  1879. bool HasAVX512CD, HasAVX512ER, HasAVX512PF, HasAVX512DQ, HasAVX512BW,
  1880. HasAVX512VL;
  1881. bool HasSHA;
  1882. bool HasCX16;
  1883. /// \brief Enumeration of all of the X86 CPUs supported by Clang.
  1884. ///
  1885. /// Each enumeration represents a particular CPU supported by Clang. These
  1886. /// loosely correspond to the options passed to '-march' or '-mtune' flags.
  1887. enum CPUKind {
  1888. CK_Generic,
  1889. /// \name i386
  1890. /// i386-generation processors.
  1891. //@{
  1892. CK_i386,
  1893. //@}
  1894. /// \name i486
  1895. /// i486-generation processors.
  1896. //@{
  1897. CK_i486,
  1898. CK_WinChipC6,
  1899. CK_WinChip2,
  1900. CK_C3,
  1901. //@}
  1902. /// \name i586
  1903. /// i586-generation processors, P5 microarchitecture based.
  1904. //@{
  1905. CK_i586,
  1906. CK_Pentium,
  1907. CK_PentiumMMX,
  1908. //@}
  1909. /// \name i686
  1910. /// i686-generation processors, P6 / Pentium M microarchitecture based.
  1911. //@{
  1912. CK_i686,
  1913. CK_PentiumPro,
  1914. CK_Pentium2,
  1915. CK_Pentium3,
  1916. CK_Pentium3M,
  1917. CK_PentiumM,
  1918. CK_C3_2,
  1919. /// This enumerator is a bit odd, as GCC no longer accepts -march=yonah.
  1920. /// Clang however has some logic to suport this.
  1921. // FIXME: Warn, deprecate, and potentially remove this.
  1922. CK_Yonah,
  1923. //@}
  1924. /// \name Netburst
  1925. /// Netburst microarchitecture based processors.
  1926. //@{
  1927. CK_Pentium4,
  1928. CK_Pentium4M,
  1929. CK_Prescott,
  1930. CK_Nocona,
  1931. //@}
  1932. /// \name Core
  1933. /// Core microarchitecture based processors.
  1934. //@{
  1935. CK_Core2,
  1936. /// This enumerator, like \see CK_Yonah, is a bit odd. It is another
  1937. /// codename which GCC no longer accepts as an option to -march, but Clang
  1938. /// has some logic for recognizing it.
  1939. // FIXME: Warn, deprecate, and potentially remove this.
  1940. CK_Penryn,
  1941. //@}
  1942. /// \name Atom
  1943. /// Atom processors
  1944. //@{
  1945. CK_Bonnell,
  1946. CK_Silvermont,
  1947. //@}
  1948. /// \name Nehalem
  1949. /// Nehalem microarchitecture based processors.
  1950. CK_Nehalem,
  1951. /// \name Westmere
  1952. /// Westmere microarchitecture based processors.
  1953. CK_Westmere,
  1954. /// \name Sandy Bridge
  1955. /// Sandy Bridge microarchitecture based processors.
  1956. CK_SandyBridge,
  1957. /// \name Ivy Bridge
  1958. /// Ivy Bridge microarchitecture based processors.
  1959. CK_IvyBridge,
  1960. /// \name Haswell
  1961. /// Haswell microarchitecture based processors.
  1962. CK_Haswell,
  1963. /// \name Broadwell
  1964. /// Broadwell microarchitecture based processors.
  1965. CK_Broadwell,
  1966. /// \name Skylake
  1967. /// Skylake microarchitecture based processors.
  1968. CK_Skylake,
  1969. /// \name Knights Landing
  1970. /// Knights Landing processor.
  1971. CK_KNL,
  1972. /// \name K6
  1973. /// K6 architecture processors.
  1974. //@{
  1975. CK_K6,
  1976. CK_K6_2,
  1977. CK_K6_3,
  1978. //@}
  1979. /// \name K7
  1980. /// K7 architecture processors.
  1981. //@{
  1982. CK_Athlon,
  1983. CK_AthlonThunderbird,
  1984. CK_Athlon4,
  1985. CK_AthlonXP,
  1986. CK_AthlonMP,
  1987. //@}
  1988. /// \name K8
  1989. /// K8 architecture processors.
  1990. //@{
  1991. CK_Athlon64,
  1992. CK_Athlon64SSE3,
  1993. CK_AthlonFX,
  1994. CK_K8,
  1995. CK_K8SSE3,
  1996. CK_Opteron,
  1997. CK_OpteronSSE3,
  1998. CK_AMDFAM10,
  1999. //@}
  2000. /// \name Bobcat
  2001. /// Bobcat architecture processors.
  2002. //@{
  2003. CK_BTVER1,
  2004. CK_BTVER2,
  2005. //@}
  2006. /// \name Bulldozer
  2007. /// Bulldozer architecture processors.
  2008. //@{
  2009. CK_BDVER1,
  2010. CK_BDVER2,
  2011. CK_BDVER3,
  2012. CK_BDVER4,
  2013. //@}
  2014. /// This specification is deprecated and will be removed in the future.
  2015. /// Users should prefer \see CK_K8.
  2016. // FIXME: Warn on this when the CPU is set to it.
  2017. //@{
  2018. CK_x86_64,
  2019. //@}
  2020. /// \name Geode
  2021. /// Geode processors.
  2022. //@{
  2023. CK_Geode
  2024. //@}
  2025. } CPU;
  2026. enum FPMathKind {
  2027. FP_Default,
  2028. FP_SSE,
  2029. FP_387
  2030. } FPMath;
  2031. public:
  2032. X86TargetInfo(const llvm::Triple &Triple)
  2033. : TargetInfo(Triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
  2034. XOPLevel(NoXOP), HasAES(false), HasPCLMUL(false), HasLZCNT(false),
  2035. HasRDRND(false), HasFSGSBASE(false), HasBMI(false), HasBMI2(false),
  2036. HasPOPCNT(false), HasRTM(false), HasPRFCHW(false), HasRDSEED(false),
  2037. HasADX(false), HasTBM(false), HasFMA(false), HasF16C(false),
  2038. HasAVX512CD(false), HasAVX512ER(false), HasAVX512PF(false),
  2039. HasAVX512DQ(false), HasAVX512BW(false), HasAVX512VL(false),
  2040. HasSHA(false), HasCX16(false), CPU(CK_Generic), FPMath(FP_Default) {
  2041. BigEndian = false;
  2042. LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
  2043. }
  2044. unsigned getFloatEvalMethod() const override {
  2045. // X87 evaluates with 80 bits "long double" precision.
  2046. return SSELevel == NoSSE ? 2 : 0;
  2047. }
  2048. void getTargetBuiltins(const Builtin::Info *&Records,
  2049. unsigned &NumRecords) const override {
  2050. Records = BuiltinInfo;
  2051. NumRecords = clang::X86::LastTSBuiltin-Builtin::FirstTSBuiltin;
  2052. }
  2053. void getGCCRegNames(const char * const *&Names,
  2054. unsigned &NumNames) const override {
  2055. Names = GCCRegNames;
  2056. NumNames = llvm::array_lengthof(GCCRegNames);
  2057. }
  2058. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  2059. unsigned &NumAliases) const override {
  2060. Aliases = nullptr;
  2061. NumAliases = 0;
  2062. }
  2063. void getGCCAddlRegNames(const AddlRegName *&Names,
  2064. unsigned &NumNames) const override {
  2065. Names = AddlRegNames;
  2066. NumNames = llvm::array_lengthof(AddlRegNames);
  2067. }
  2068. bool validateCpuSupports(StringRef Name) const override;
  2069. bool validateAsmConstraint(const char *&Name,
  2070. TargetInfo::ConstraintInfo &info) const override;
  2071. bool validateOutputSize(StringRef Constraint, unsigned Size) const override;
  2072. bool validateInputSize(StringRef Constraint, unsigned Size) const override;
  2073. virtual bool validateOperandSize(StringRef Constraint, unsigned Size) const;
  2074. std::string convertConstraint(const char *&Constraint) const override;
  2075. const char *getClobbers() const override {
  2076. return "~{dirflag},~{fpsr},~{flags}";
  2077. }
  2078. void getTargetDefines(const LangOptions &Opts,
  2079. MacroBuilder &Builder) const override;
  2080. static void setSSELevel(llvm::StringMap<bool> &Features, X86SSEEnum Level,
  2081. bool Enabled);
  2082. static void setMMXLevel(llvm::StringMap<bool> &Features, MMX3DNowEnum Level,
  2083. bool Enabled);
  2084. static void setXOPLevel(llvm::StringMap<bool> &Features, XOPEnum Level,
  2085. bool Enabled);
  2086. void setFeatureEnabled(llvm::StringMap<bool> &Features,
  2087. StringRef Name, bool Enabled) const override {
  2088. setFeatureEnabledImpl(Features, Name, Enabled);
  2089. }
  2090. // This exists purely to cut down on the number of virtual calls in
  2091. // getDefaultFeatures which calls this repeatedly.
  2092. static void setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
  2093. StringRef Name, bool Enabled);
  2094. void getDefaultFeatures(llvm::StringMap<bool> &Features) const override;
  2095. bool hasFeature(StringRef Feature) const override;
  2096. bool handleTargetFeatures(std::vector<std::string> &Features,
  2097. DiagnosticsEngine &Diags) override;
  2098. StringRef getABI() const override {
  2099. if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX512F)
  2100. return "avx512";
  2101. else if (getTriple().getArch() == llvm::Triple::x86_64 && SSELevel >= AVX)
  2102. return "avx";
  2103. else if (getTriple().getArch() == llvm::Triple::x86 &&
  2104. MMX3DNowLevel == NoMMX3DNow)
  2105. return "no-mmx";
  2106. return "";
  2107. }
  2108. bool setCPU(const std::string &Name) override {
  2109. CPU = llvm::StringSwitch<CPUKind>(Name)
  2110. .Case("i386", CK_i386)
  2111. .Case("i486", CK_i486)
  2112. .Case("winchip-c6", CK_WinChipC6)
  2113. .Case("winchip2", CK_WinChip2)
  2114. .Case("c3", CK_C3)
  2115. .Case("i586", CK_i586)
  2116. .Case("pentium", CK_Pentium)
  2117. .Case("pentium-mmx", CK_PentiumMMX)
  2118. .Case("i686", CK_i686)
  2119. .Case("pentiumpro", CK_PentiumPro)
  2120. .Case("pentium2", CK_Pentium2)
  2121. .Case("pentium3", CK_Pentium3)
  2122. .Case("pentium3m", CK_Pentium3M)
  2123. .Case("pentium-m", CK_PentiumM)
  2124. .Case("c3-2", CK_C3_2)
  2125. .Case("yonah", CK_Yonah)
  2126. .Case("pentium4", CK_Pentium4)
  2127. .Case("pentium4m", CK_Pentium4M)
  2128. .Case("prescott", CK_Prescott)
  2129. .Case("nocona", CK_Nocona)
  2130. .Case("core2", CK_Core2)
  2131. .Case("penryn", CK_Penryn)
  2132. .Case("bonnell", CK_Bonnell)
  2133. .Case("atom", CK_Bonnell) // Legacy name.
  2134. .Case("silvermont", CK_Silvermont)
  2135. .Case("slm", CK_Silvermont) // Legacy name.
  2136. .Case("nehalem", CK_Nehalem)
  2137. .Case("corei7", CK_Nehalem) // Legacy name.
  2138. .Case("westmere", CK_Westmere)
  2139. .Case("sandybridge", CK_SandyBridge)
  2140. .Case("corei7-avx", CK_SandyBridge) // Legacy name.
  2141. .Case("ivybridge", CK_IvyBridge)
  2142. .Case("core-avx-i", CK_IvyBridge) // Legacy name.
  2143. .Case("haswell", CK_Haswell)
  2144. .Case("core-avx2", CK_Haswell) // Legacy name.
  2145. .Case("broadwell", CK_Broadwell)
  2146. .Case("skylake", CK_Skylake)
  2147. .Case("skx", CK_Skylake) // Legacy name.
  2148. .Case("knl", CK_KNL)
  2149. .Case("k6", CK_K6)
  2150. .Case("k6-2", CK_K6_2)
  2151. .Case("k6-3", CK_K6_3)
  2152. .Case("athlon", CK_Athlon)
  2153. .Case("athlon-tbird", CK_AthlonThunderbird)
  2154. .Case("athlon-4", CK_Athlon4)
  2155. .Case("athlon-xp", CK_AthlonXP)
  2156. .Case("athlon-mp", CK_AthlonMP)
  2157. .Case("athlon64", CK_Athlon64)
  2158. .Case("athlon64-sse3", CK_Athlon64SSE3)
  2159. .Case("athlon-fx", CK_AthlonFX)
  2160. .Case("k8", CK_K8)
  2161. .Case("k8-sse3", CK_K8SSE3)
  2162. .Case("opteron", CK_Opteron)
  2163. .Case("opteron-sse3", CK_OpteronSSE3)
  2164. .Case("barcelona", CK_AMDFAM10)
  2165. .Case("amdfam10", CK_AMDFAM10)
  2166. .Case("btver1", CK_BTVER1)
  2167. .Case("btver2", CK_BTVER2)
  2168. .Case("bdver1", CK_BDVER1)
  2169. .Case("bdver2", CK_BDVER2)
  2170. .Case("bdver3", CK_BDVER3)
  2171. .Case("bdver4", CK_BDVER4)
  2172. .Case("x86-64", CK_x86_64)
  2173. .Case("geode", CK_Geode)
  2174. .Default(CK_Generic);
  2175. // Perform any per-CPU checks necessary to determine if this CPU is
  2176. // acceptable.
  2177. // FIXME: This results in terrible diagnostics. Clang just says the CPU is
  2178. // invalid without explaining *why*.
  2179. switch (CPU) {
  2180. case CK_Generic:
  2181. // No processor selected!
  2182. return false;
  2183. case CK_i386:
  2184. case CK_i486:
  2185. case CK_WinChipC6:
  2186. case CK_WinChip2:
  2187. case CK_C3:
  2188. case CK_i586:
  2189. case CK_Pentium:
  2190. case CK_PentiumMMX:
  2191. case CK_i686:
  2192. case CK_PentiumPro:
  2193. case CK_Pentium2:
  2194. case CK_Pentium3:
  2195. case CK_Pentium3M:
  2196. case CK_PentiumM:
  2197. case CK_Yonah:
  2198. case CK_C3_2:
  2199. case CK_Pentium4:
  2200. case CK_Pentium4M:
  2201. case CK_Prescott:
  2202. case CK_K6:
  2203. case CK_K6_2:
  2204. case CK_K6_3:
  2205. case CK_Athlon:
  2206. case CK_AthlonThunderbird:
  2207. case CK_Athlon4:
  2208. case CK_AthlonXP:
  2209. case CK_AthlonMP:
  2210. case CK_Geode:
  2211. // Only accept certain architectures when compiling in 32-bit mode.
  2212. if (getTriple().getArch() != llvm::Triple::x86)
  2213. return false;
  2214. // Fallthrough
  2215. case CK_Nocona:
  2216. case CK_Core2:
  2217. case CK_Penryn:
  2218. case CK_Bonnell:
  2219. case CK_Silvermont:
  2220. case CK_Nehalem:
  2221. case CK_Westmere:
  2222. case CK_SandyBridge:
  2223. case CK_IvyBridge:
  2224. case CK_Haswell:
  2225. case CK_Broadwell:
  2226. case CK_Skylake:
  2227. case CK_KNL:
  2228. case CK_Athlon64:
  2229. case CK_Athlon64SSE3:
  2230. case CK_AthlonFX:
  2231. case CK_K8:
  2232. case CK_K8SSE3:
  2233. case CK_Opteron:
  2234. case CK_OpteronSSE3:
  2235. case CK_AMDFAM10:
  2236. case CK_BTVER1:
  2237. case CK_BTVER2:
  2238. case CK_BDVER1:
  2239. case CK_BDVER2:
  2240. case CK_BDVER3:
  2241. case CK_BDVER4:
  2242. case CK_x86_64:
  2243. return true;
  2244. }
  2245. llvm_unreachable("Unhandled CPU kind");
  2246. }
  2247. bool setFPMath(StringRef Name) override;
  2248. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  2249. // We accept all non-ARM calling conventions
  2250. return (CC == CC_X86ThisCall ||
  2251. CC == CC_X86FastCall ||
  2252. CC == CC_X86StdCall ||
  2253. CC == CC_X86VectorCall ||
  2254. CC == CC_C ||
  2255. CC == CC_X86Pascal ||
  2256. CC == CC_IntelOclBicc) ? CCCR_OK : CCCR_Warning;
  2257. }
  2258. CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
  2259. return MT == CCMT_Member ? CC_X86ThisCall : CC_C;
  2260. }
  2261. bool hasSjLjLowering() const override {
  2262. return true;
  2263. }
  2264. };
  2265. bool X86TargetInfo::setFPMath(StringRef Name) {
  2266. if (Name == "387") {
  2267. FPMath = FP_387;
  2268. return true;
  2269. }
  2270. if (Name == "sse") {
  2271. FPMath = FP_SSE;
  2272. return true;
  2273. }
  2274. return false;
  2275. }
  2276. void X86TargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
  2277. // FIXME: This *really* should not be here.
  2278. // X86_64 always has SSE2.
  2279. if (getTriple().getArch() == llvm::Triple::x86_64)
  2280. setFeatureEnabledImpl(Features, "sse2", true);
  2281. switch (CPU) {
  2282. case CK_Generic:
  2283. case CK_i386:
  2284. case CK_i486:
  2285. case CK_i586:
  2286. case CK_Pentium:
  2287. case CK_i686:
  2288. case CK_PentiumPro:
  2289. break;
  2290. case CK_PentiumMMX:
  2291. case CK_Pentium2:
  2292. case CK_K6:
  2293. case CK_WinChipC6:
  2294. setFeatureEnabledImpl(Features, "mmx", true);
  2295. break;
  2296. case CK_Pentium3:
  2297. case CK_Pentium3M:
  2298. case CK_C3_2:
  2299. setFeatureEnabledImpl(Features, "sse", true);
  2300. break;
  2301. case CK_PentiumM:
  2302. case CK_Pentium4:
  2303. case CK_Pentium4M:
  2304. case CK_x86_64:
  2305. setFeatureEnabledImpl(Features, "sse2", true);
  2306. break;
  2307. case CK_Yonah:
  2308. case CK_Prescott:
  2309. case CK_Nocona:
  2310. setFeatureEnabledImpl(Features, "sse3", true);
  2311. setFeatureEnabledImpl(Features, "cx16", true);
  2312. break;
  2313. case CK_Core2:
  2314. case CK_Bonnell:
  2315. setFeatureEnabledImpl(Features, "ssse3", true);
  2316. setFeatureEnabledImpl(Features, "cx16", true);
  2317. break;
  2318. case CK_Penryn:
  2319. setFeatureEnabledImpl(Features, "sse4.1", true);
  2320. setFeatureEnabledImpl(Features, "cx16", true);
  2321. break;
  2322. case CK_Skylake:
  2323. setFeatureEnabledImpl(Features, "avx512f", true);
  2324. setFeatureEnabledImpl(Features, "avx512cd", true);
  2325. setFeatureEnabledImpl(Features, "avx512dq", true);
  2326. setFeatureEnabledImpl(Features, "avx512bw", true);
  2327. setFeatureEnabledImpl(Features, "avx512vl", true);
  2328. // FALLTHROUGH
  2329. case CK_Broadwell:
  2330. setFeatureEnabledImpl(Features, "rdseed", true);
  2331. setFeatureEnabledImpl(Features, "adx", true);
  2332. // FALLTHROUGH
  2333. case CK_Haswell:
  2334. setFeatureEnabledImpl(Features, "avx2", true);
  2335. setFeatureEnabledImpl(Features, "lzcnt", true);
  2336. setFeatureEnabledImpl(Features, "bmi", true);
  2337. setFeatureEnabledImpl(Features, "bmi2", true);
  2338. setFeatureEnabledImpl(Features, "rtm", true);
  2339. setFeatureEnabledImpl(Features, "fma", true);
  2340. // FALLTHROUGH
  2341. case CK_IvyBridge:
  2342. setFeatureEnabledImpl(Features, "rdrnd", true);
  2343. setFeatureEnabledImpl(Features, "f16c", true);
  2344. setFeatureEnabledImpl(Features, "fsgsbase", true);
  2345. // FALLTHROUGH
  2346. case CK_SandyBridge:
  2347. setFeatureEnabledImpl(Features, "avx", true);
  2348. // FALLTHROUGH
  2349. case CK_Westmere:
  2350. case CK_Silvermont:
  2351. setFeatureEnabledImpl(Features, "aes", true);
  2352. setFeatureEnabledImpl(Features, "pclmul", true);
  2353. // FALLTHROUGH
  2354. case CK_Nehalem:
  2355. setFeatureEnabledImpl(Features, "sse4.2", true);
  2356. setFeatureEnabledImpl(Features, "cx16", true);
  2357. break;
  2358. case CK_KNL:
  2359. setFeatureEnabledImpl(Features, "avx512f", true);
  2360. setFeatureEnabledImpl(Features, "avx512cd", true);
  2361. setFeatureEnabledImpl(Features, "avx512er", true);
  2362. setFeatureEnabledImpl(Features, "avx512pf", true);
  2363. setFeatureEnabledImpl(Features, "rdseed", true);
  2364. setFeatureEnabledImpl(Features, "adx", true);
  2365. setFeatureEnabledImpl(Features, "lzcnt", true);
  2366. setFeatureEnabledImpl(Features, "bmi", true);
  2367. setFeatureEnabledImpl(Features, "bmi2", true);
  2368. setFeatureEnabledImpl(Features, "rtm", true);
  2369. setFeatureEnabledImpl(Features, "fma", true);
  2370. setFeatureEnabledImpl(Features, "rdrnd", true);
  2371. setFeatureEnabledImpl(Features, "f16c", true);
  2372. setFeatureEnabledImpl(Features, "fsgsbase", true);
  2373. setFeatureEnabledImpl(Features, "aes", true);
  2374. setFeatureEnabledImpl(Features, "pclmul", true);
  2375. setFeatureEnabledImpl(Features, "cx16", true);
  2376. break;
  2377. case CK_K6_2:
  2378. case CK_K6_3:
  2379. case CK_WinChip2:
  2380. case CK_C3:
  2381. setFeatureEnabledImpl(Features, "3dnow", true);
  2382. break;
  2383. case CK_Athlon:
  2384. case CK_AthlonThunderbird:
  2385. case CK_Geode:
  2386. setFeatureEnabledImpl(Features, "3dnowa", true);
  2387. break;
  2388. case CK_Athlon4:
  2389. case CK_AthlonXP:
  2390. case CK_AthlonMP:
  2391. setFeatureEnabledImpl(Features, "sse", true);
  2392. setFeatureEnabledImpl(Features, "3dnowa", true);
  2393. break;
  2394. case CK_K8:
  2395. case CK_Opteron:
  2396. case CK_Athlon64:
  2397. case CK_AthlonFX:
  2398. setFeatureEnabledImpl(Features, "sse2", true);
  2399. setFeatureEnabledImpl(Features, "3dnowa", true);
  2400. break;
  2401. case CK_AMDFAM10:
  2402. setFeatureEnabledImpl(Features, "sse4a", true);
  2403. setFeatureEnabledImpl(Features, "lzcnt", true);
  2404. setFeatureEnabledImpl(Features, "popcnt", true);
  2405. // FALLTHROUGH
  2406. case CK_K8SSE3:
  2407. case CK_OpteronSSE3:
  2408. case CK_Athlon64SSE3:
  2409. setFeatureEnabledImpl(Features, "sse3", true);
  2410. setFeatureEnabledImpl(Features, "3dnowa", true);
  2411. break;
  2412. case CK_BTVER2:
  2413. setFeatureEnabledImpl(Features, "avx", true);
  2414. setFeatureEnabledImpl(Features, "aes", true);
  2415. setFeatureEnabledImpl(Features, "pclmul", true);
  2416. setFeatureEnabledImpl(Features, "bmi", true);
  2417. setFeatureEnabledImpl(Features, "f16c", true);
  2418. // FALLTHROUGH
  2419. case CK_BTVER1:
  2420. setFeatureEnabledImpl(Features, "ssse3", true);
  2421. setFeatureEnabledImpl(Features, "sse4a", true);
  2422. setFeatureEnabledImpl(Features, "lzcnt", true);
  2423. setFeatureEnabledImpl(Features, "popcnt", true);
  2424. setFeatureEnabledImpl(Features, "prfchw", true);
  2425. setFeatureEnabledImpl(Features, "cx16", true);
  2426. break;
  2427. case CK_BDVER4:
  2428. setFeatureEnabledImpl(Features, "avx2", true);
  2429. setFeatureEnabledImpl(Features, "bmi2", true);
  2430. // FALLTHROUGH
  2431. case CK_BDVER3:
  2432. setFeatureEnabledImpl(Features, "fsgsbase", true);
  2433. // FALLTHROUGH
  2434. case CK_BDVER2:
  2435. setFeatureEnabledImpl(Features, "bmi", true);
  2436. setFeatureEnabledImpl(Features, "fma", true);
  2437. setFeatureEnabledImpl(Features, "f16c", true);
  2438. setFeatureEnabledImpl(Features, "tbm", true);
  2439. // FALLTHROUGH
  2440. case CK_BDVER1:
  2441. // xop implies avx, sse4a and fma4.
  2442. setFeatureEnabledImpl(Features, "xop", true);
  2443. setFeatureEnabledImpl(Features, "lzcnt", true);
  2444. setFeatureEnabledImpl(Features, "aes", true);
  2445. setFeatureEnabledImpl(Features, "pclmul", true);
  2446. setFeatureEnabledImpl(Features, "prfchw", true);
  2447. setFeatureEnabledImpl(Features, "cx16", true);
  2448. break;
  2449. }
  2450. }
  2451. void X86TargetInfo::setSSELevel(llvm::StringMap<bool> &Features,
  2452. X86SSEEnum Level, bool Enabled) {
  2453. if (Enabled) {
  2454. switch (Level) {
  2455. case AVX512F:
  2456. Features["avx512f"] = true;
  2457. case AVX2:
  2458. Features["avx2"] = true;
  2459. case AVX:
  2460. Features["avx"] = true;
  2461. case SSE42:
  2462. Features["sse4.2"] = true;
  2463. case SSE41:
  2464. Features["sse4.1"] = true;
  2465. case SSSE3:
  2466. Features["ssse3"] = true;
  2467. case SSE3:
  2468. Features["sse3"] = true;
  2469. case SSE2:
  2470. Features["sse2"] = true;
  2471. case SSE1:
  2472. Features["sse"] = true;
  2473. case NoSSE:
  2474. break;
  2475. }
  2476. return;
  2477. }
  2478. switch (Level) {
  2479. case NoSSE:
  2480. case SSE1:
  2481. Features["sse"] = false;
  2482. case SSE2:
  2483. Features["sse2"] = Features["pclmul"] = Features["aes"] =
  2484. Features["sha"] = false;
  2485. case SSE3:
  2486. Features["sse3"] = false;
  2487. setXOPLevel(Features, NoXOP, false);
  2488. case SSSE3:
  2489. Features["ssse3"] = false;
  2490. case SSE41:
  2491. Features["sse4.1"] = false;
  2492. case SSE42:
  2493. Features["sse4.2"] = false;
  2494. case AVX:
  2495. Features["fma"] = Features["avx"] = Features["f16c"] = false;
  2496. setXOPLevel(Features, FMA4, false);
  2497. case AVX2:
  2498. Features["avx2"] = false;
  2499. case AVX512F:
  2500. Features["avx512f"] = Features["avx512cd"] = Features["avx512er"] =
  2501. Features["avx512pf"] = Features["avx512dq"] = Features["avx512bw"] =
  2502. Features["avx512vl"] = false;
  2503. }
  2504. }
  2505. void X86TargetInfo::setMMXLevel(llvm::StringMap<bool> &Features,
  2506. MMX3DNowEnum Level, bool Enabled) {
  2507. if (Enabled) {
  2508. switch (Level) {
  2509. case AMD3DNowAthlon:
  2510. Features["3dnowa"] = true;
  2511. case AMD3DNow:
  2512. Features["3dnow"] = true;
  2513. case MMX:
  2514. Features["mmx"] = true;
  2515. case NoMMX3DNow:
  2516. break;
  2517. }
  2518. return;
  2519. }
  2520. switch (Level) {
  2521. case NoMMX3DNow:
  2522. case MMX:
  2523. Features["mmx"] = false;
  2524. case AMD3DNow:
  2525. Features["3dnow"] = false;
  2526. case AMD3DNowAthlon:
  2527. Features["3dnowa"] = false;
  2528. }
  2529. }
  2530. void X86TargetInfo::setXOPLevel(llvm::StringMap<bool> &Features, XOPEnum Level,
  2531. bool Enabled) {
  2532. if (Enabled) {
  2533. switch (Level) {
  2534. case XOP:
  2535. Features["xop"] = true;
  2536. case FMA4:
  2537. Features["fma4"] = true;
  2538. setSSELevel(Features, AVX, true);
  2539. case SSE4A:
  2540. Features["sse4a"] = true;
  2541. setSSELevel(Features, SSE3, true);
  2542. case NoXOP:
  2543. break;
  2544. }
  2545. return;
  2546. }
  2547. switch (Level) {
  2548. case NoXOP:
  2549. case SSE4A:
  2550. Features["sse4a"] = false;
  2551. case FMA4:
  2552. Features["fma4"] = false;
  2553. case XOP:
  2554. Features["xop"] = false;
  2555. }
  2556. }
  2557. void X86TargetInfo::setFeatureEnabledImpl(llvm::StringMap<bool> &Features,
  2558. StringRef Name, bool Enabled) {
  2559. // This is a bit of a hack to deal with the sse4 target feature when used
  2560. // as part of the target attribute. We handle sse4 correctly everywhere
  2561. // else. See below for more information on how we handle the sse4 options.
  2562. if (Name != "sse4")
  2563. Features[Name] = Enabled;
  2564. if (Name == "mmx") {
  2565. setMMXLevel(Features, MMX, Enabled);
  2566. } else if (Name == "sse") {
  2567. setSSELevel(Features, SSE1, Enabled);
  2568. } else if (Name == "sse2") {
  2569. setSSELevel(Features, SSE2, Enabled);
  2570. } else if (Name == "sse3") {
  2571. setSSELevel(Features, SSE3, Enabled);
  2572. } else if (Name == "ssse3") {
  2573. setSSELevel(Features, SSSE3, Enabled);
  2574. } else if (Name == "sse4.2") {
  2575. setSSELevel(Features, SSE42, Enabled);
  2576. } else if (Name == "sse4.1") {
  2577. setSSELevel(Features, SSE41, Enabled);
  2578. } else if (Name == "3dnow") {
  2579. setMMXLevel(Features, AMD3DNow, Enabled);
  2580. } else if (Name == "3dnowa") {
  2581. setMMXLevel(Features, AMD3DNowAthlon, Enabled);
  2582. } else if (Name == "aes") {
  2583. if (Enabled)
  2584. setSSELevel(Features, SSE2, Enabled);
  2585. } else if (Name == "pclmul") {
  2586. if (Enabled)
  2587. setSSELevel(Features, SSE2, Enabled);
  2588. } else if (Name == "avx") {
  2589. setSSELevel(Features, AVX, Enabled);
  2590. } else if (Name == "avx2") {
  2591. setSSELevel(Features, AVX2, Enabled);
  2592. } else if (Name == "avx512f") {
  2593. setSSELevel(Features, AVX512F, Enabled);
  2594. } else if (Name == "avx512cd" || Name == "avx512er" || Name == "avx512pf"
  2595. || Name == "avx512dq" || Name == "avx512bw" || Name == "avx512vl") {
  2596. if (Enabled)
  2597. setSSELevel(Features, AVX512F, Enabled);
  2598. } else if (Name == "fma") {
  2599. if (Enabled)
  2600. setSSELevel(Features, AVX, Enabled);
  2601. } else if (Name == "fma4") {
  2602. setXOPLevel(Features, FMA4, Enabled);
  2603. } else if (Name == "xop") {
  2604. setXOPLevel(Features, XOP, Enabled);
  2605. } else if (Name == "sse4a") {
  2606. setXOPLevel(Features, SSE4A, Enabled);
  2607. } else if (Name == "f16c") {
  2608. if (Enabled)
  2609. setSSELevel(Features, AVX, Enabled);
  2610. } else if (Name == "sha") {
  2611. if (Enabled)
  2612. setSSELevel(Features, SSE2, Enabled);
  2613. } else if (Name == "sse4") {
  2614. // We can get here via the __target__ attribute since that's not controlled
  2615. // via the -msse4/-mno-sse4 command line alias. Handle this the same way
  2616. // here - turn on the sse4.2 if enabled, turn off the sse4.1 level if
  2617. // disabled.
  2618. if (Enabled)
  2619. setSSELevel(Features, SSE42, Enabled);
  2620. else
  2621. setSSELevel(Features, SSE41, Enabled);
  2622. }
  2623. }
  2624. /// handleTargetFeatures - Perform initialization based on the user
  2625. /// configured set of features.
  2626. bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
  2627. DiagnosticsEngine &Diags) {
  2628. // Remember the maximum enabled sselevel.
  2629. for (unsigned i = 0, e = Features.size(); i !=e; ++i) {
  2630. // Ignore disabled features.
  2631. if (Features[i][0] == '-')
  2632. continue;
  2633. StringRef Feature = StringRef(Features[i]).substr(1);
  2634. if (Feature == "aes") {
  2635. HasAES = true;
  2636. continue;
  2637. }
  2638. if (Feature == "pclmul") {
  2639. HasPCLMUL = true;
  2640. continue;
  2641. }
  2642. if (Feature == "lzcnt") {
  2643. HasLZCNT = true;
  2644. continue;
  2645. }
  2646. if (Feature == "rdrnd") {
  2647. HasRDRND = true;
  2648. continue;
  2649. }
  2650. if (Feature == "fsgsbase") {
  2651. HasFSGSBASE = true;
  2652. continue;
  2653. }
  2654. if (Feature == "bmi") {
  2655. HasBMI = true;
  2656. continue;
  2657. }
  2658. if (Feature == "bmi2") {
  2659. HasBMI2 = true;
  2660. continue;
  2661. }
  2662. if (Feature == "popcnt") {
  2663. HasPOPCNT = true;
  2664. continue;
  2665. }
  2666. if (Feature == "rtm") {
  2667. HasRTM = true;
  2668. continue;
  2669. }
  2670. if (Feature == "prfchw") {
  2671. HasPRFCHW = true;
  2672. continue;
  2673. }
  2674. if (Feature == "rdseed") {
  2675. HasRDSEED = true;
  2676. continue;
  2677. }
  2678. if (Feature == "adx") {
  2679. HasADX = true;
  2680. continue;
  2681. }
  2682. if (Feature == "tbm") {
  2683. HasTBM = true;
  2684. continue;
  2685. }
  2686. if (Feature == "fma") {
  2687. HasFMA = true;
  2688. continue;
  2689. }
  2690. if (Feature == "f16c") {
  2691. HasF16C = true;
  2692. continue;
  2693. }
  2694. if (Feature == "avx512cd") {
  2695. HasAVX512CD = true;
  2696. continue;
  2697. }
  2698. if (Feature == "avx512er") {
  2699. HasAVX512ER = true;
  2700. continue;
  2701. }
  2702. if (Feature == "avx512pf") {
  2703. HasAVX512PF = true;
  2704. continue;
  2705. }
  2706. if (Feature == "avx512dq") {
  2707. HasAVX512DQ = true;
  2708. continue;
  2709. }
  2710. if (Feature == "avx512bw") {
  2711. HasAVX512BW = true;
  2712. continue;
  2713. }
  2714. if (Feature == "avx512vl") {
  2715. HasAVX512VL = true;
  2716. continue;
  2717. }
  2718. if (Feature == "sha") {
  2719. HasSHA = true;
  2720. continue;
  2721. }
  2722. if (Feature == "cx16") {
  2723. HasCX16 = true;
  2724. continue;
  2725. }
  2726. assert(Features[i][0] == '+' && "Invalid target feature!");
  2727. X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
  2728. .Case("avx512f", AVX512F)
  2729. .Case("avx2", AVX2)
  2730. .Case("avx", AVX)
  2731. .Case("sse4.2", SSE42)
  2732. .Case("sse4.1", SSE41)
  2733. .Case("ssse3", SSSE3)
  2734. .Case("sse3", SSE3)
  2735. .Case("sse2", SSE2)
  2736. .Case("sse", SSE1)
  2737. .Default(NoSSE);
  2738. SSELevel = std::max(SSELevel, Level);
  2739. MMX3DNowEnum ThreeDNowLevel =
  2740. llvm::StringSwitch<MMX3DNowEnum>(Feature)
  2741. .Case("3dnowa", AMD3DNowAthlon)
  2742. .Case("3dnow", AMD3DNow)
  2743. .Case("mmx", MMX)
  2744. .Default(NoMMX3DNow);
  2745. MMX3DNowLevel = std::max(MMX3DNowLevel, ThreeDNowLevel);
  2746. XOPEnum XLevel = llvm::StringSwitch<XOPEnum>(Feature)
  2747. .Case("xop", XOP)
  2748. .Case("fma4", FMA4)
  2749. .Case("sse4a", SSE4A)
  2750. .Default(NoXOP);
  2751. XOPLevel = std::max(XOPLevel, XLevel);
  2752. }
  2753. // Enable popcnt if sse4.2 is enabled and popcnt is not explicitly disabled.
  2754. // Can't do this earlier because we need to be able to explicitly enable
  2755. // popcnt and still disable sse4.2.
  2756. if (!HasPOPCNT && SSELevel >= SSE42 &&
  2757. std::find(Features.begin(), Features.end(), "-popcnt") == Features.end()){
  2758. HasPOPCNT = true;
  2759. Features.push_back("+popcnt");
  2760. }
  2761. // Enable prfchw if 3DNow! is enabled and prfchw is not explicitly disabled.
  2762. if (!HasPRFCHW && MMX3DNowLevel >= AMD3DNow &&
  2763. std::find(Features.begin(), Features.end(), "-prfchw") == Features.end()){
  2764. HasPRFCHW = true;
  2765. Features.push_back("+prfchw");
  2766. }
  2767. // LLVM doesn't have a separate switch for fpmath, so only accept it if it
  2768. // matches the selected sse level.
  2769. if (FPMath == FP_SSE && SSELevel < SSE1) {
  2770. Diags.Report(diag::err_target_unsupported_fpmath) << "sse";
  2771. return false;
  2772. } else if (FPMath == FP_387 && SSELevel >= SSE1) {
  2773. Diags.Report(diag::err_target_unsupported_fpmath) << "387";
  2774. return false;
  2775. }
  2776. // Don't tell the backend if we're turning off mmx; it will end up disabling
  2777. // SSE, which we don't want.
  2778. // Additionally, if SSE is enabled and mmx is not explicitly disabled,
  2779. // then enable MMX.
  2780. std::vector<std::string>::iterator it;
  2781. it = std::find(Features.begin(), Features.end(), "-mmx");
  2782. if (it != Features.end())
  2783. Features.erase(it);
  2784. else if (SSELevel > NoSSE)
  2785. MMX3DNowLevel = std::max(MMX3DNowLevel, MMX);
  2786. SimdDefaultAlign =
  2787. (getABI() == "avx512") ? 512 : (getABI() == "avx") ? 256 : 128;
  2788. return true;
  2789. }
  2790. /// X86TargetInfo::getTargetDefines - Return the set of the X86-specific macro
  2791. /// definitions for this particular subtarget.
  2792. void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
  2793. MacroBuilder &Builder) const {
  2794. // Target identification.
  2795. if (getTriple().getArch() == llvm::Triple::x86_64) {
  2796. Builder.defineMacro("__amd64__");
  2797. Builder.defineMacro("__amd64");
  2798. Builder.defineMacro("__x86_64");
  2799. Builder.defineMacro("__x86_64__");
  2800. if (getTriple().getArchName() == "x86_64h") {
  2801. Builder.defineMacro("__x86_64h");
  2802. Builder.defineMacro("__x86_64h__");
  2803. }
  2804. } else {
  2805. DefineStd(Builder, "i386", Opts);
  2806. }
  2807. // Subtarget options.
  2808. // FIXME: We are hard-coding the tune parameters based on the CPU, but they
  2809. // truly should be based on -mtune options.
  2810. switch (CPU) {
  2811. case CK_Generic:
  2812. break;
  2813. case CK_i386:
  2814. // The rest are coming from the i386 define above.
  2815. Builder.defineMacro("__tune_i386__");
  2816. break;
  2817. case CK_i486:
  2818. case CK_WinChipC6:
  2819. case CK_WinChip2:
  2820. case CK_C3:
  2821. defineCPUMacros(Builder, "i486");
  2822. break;
  2823. case CK_PentiumMMX:
  2824. Builder.defineMacro("__pentium_mmx__");
  2825. Builder.defineMacro("__tune_pentium_mmx__");
  2826. // Fallthrough
  2827. case CK_i586:
  2828. case CK_Pentium:
  2829. defineCPUMacros(Builder, "i586");
  2830. defineCPUMacros(Builder, "pentium");
  2831. break;
  2832. case CK_Pentium3:
  2833. case CK_Pentium3M:
  2834. case CK_PentiumM:
  2835. Builder.defineMacro("__tune_pentium3__");
  2836. // Fallthrough
  2837. case CK_Pentium2:
  2838. case CK_C3_2:
  2839. Builder.defineMacro("__tune_pentium2__");
  2840. // Fallthrough
  2841. case CK_PentiumPro:
  2842. Builder.defineMacro("__tune_i686__");
  2843. Builder.defineMacro("__tune_pentiumpro__");
  2844. // Fallthrough
  2845. case CK_i686:
  2846. Builder.defineMacro("__i686");
  2847. Builder.defineMacro("__i686__");
  2848. // Strangely, __tune_i686__ isn't defined by GCC when CPU == i686.
  2849. Builder.defineMacro("__pentiumpro");
  2850. Builder.defineMacro("__pentiumpro__");
  2851. break;
  2852. case CK_Pentium4:
  2853. case CK_Pentium4M:
  2854. defineCPUMacros(Builder, "pentium4");
  2855. break;
  2856. case CK_Yonah:
  2857. case CK_Prescott:
  2858. case CK_Nocona:
  2859. defineCPUMacros(Builder, "nocona");
  2860. break;
  2861. case CK_Core2:
  2862. case CK_Penryn:
  2863. defineCPUMacros(Builder, "core2");
  2864. break;
  2865. case CK_Bonnell:
  2866. defineCPUMacros(Builder, "atom");
  2867. break;
  2868. case CK_Silvermont:
  2869. defineCPUMacros(Builder, "slm");
  2870. break;
  2871. case CK_Nehalem:
  2872. case CK_Westmere:
  2873. case CK_SandyBridge:
  2874. case CK_IvyBridge:
  2875. case CK_Haswell:
  2876. case CK_Broadwell:
  2877. // FIXME: Historically, we defined this legacy name, it would be nice to
  2878. // remove it at some point. We've never exposed fine-grained names for
  2879. // recent primary x86 CPUs, and we should keep it that way.
  2880. defineCPUMacros(Builder, "corei7");
  2881. break;
  2882. case CK_Skylake:
  2883. // FIXME: Historically, we defined this legacy name, it would be nice to
  2884. // remove it at some point. This is the only fine-grained CPU macro in the
  2885. // main intel CPU line, and it would be better to not have these and force
  2886. // people to use ISA macros.
  2887. defineCPUMacros(Builder, "skx");
  2888. break;
  2889. case CK_KNL:
  2890. defineCPUMacros(Builder, "knl");
  2891. break;
  2892. case CK_K6_2:
  2893. Builder.defineMacro("__k6_2__");
  2894. Builder.defineMacro("__tune_k6_2__");
  2895. // Fallthrough
  2896. case CK_K6_3:
  2897. if (CPU != CK_K6_2) { // In case of fallthrough
  2898. // FIXME: GCC may be enabling these in cases where some other k6
  2899. // architecture is specified but -m3dnow is explicitly provided. The
  2900. // exact semantics need to be determined and emulated here.
  2901. Builder.defineMacro("__k6_3__");
  2902. Builder.defineMacro("__tune_k6_3__");
  2903. }
  2904. // Fallthrough
  2905. case CK_K6:
  2906. defineCPUMacros(Builder, "k6");
  2907. break;
  2908. case CK_Athlon:
  2909. case CK_AthlonThunderbird:
  2910. case CK_Athlon4:
  2911. case CK_AthlonXP:
  2912. case CK_AthlonMP:
  2913. defineCPUMacros(Builder, "athlon");
  2914. if (SSELevel != NoSSE) {
  2915. Builder.defineMacro("__athlon_sse__");
  2916. Builder.defineMacro("__tune_athlon_sse__");
  2917. }
  2918. break;
  2919. case CK_K8:
  2920. case CK_K8SSE3:
  2921. case CK_x86_64:
  2922. case CK_Opteron:
  2923. case CK_OpteronSSE3:
  2924. case CK_Athlon64:
  2925. case CK_Athlon64SSE3:
  2926. case CK_AthlonFX:
  2927. defineCPUMacros(Builder, "k8");
  2928. break;
  2929. case CK_AMDFAM10:
  2930. defineCPUMacros(Builder, "amdfam10");
  2931. break;
  2932. case CK_BTVER1:
  2933. defineCPUMacros(Builder, "btver1");
  2934. break;
  2935. case CK_BTVER2:
  2936. defineCPUMacros(Builder, "btver2");
  2937. break;
  2938. case CK_BDVER1:
  2939. defineCPUMacros(Builder, "bdver1");
  2940. break;
  2941. case CK_BDVER2:
  2942. defineCPUMacros(Builder, "bdver2");
  2943. break;
  2944. case CK_BDVER3:
  2945. defineCPUMacros(Builder, "bdver3");
  2946. break;
  2947. case CK_BDVER4:
  2948. defineCPUMacros(Builder, "bdver4");
  2949. break;
  2950. case CK_Geode:
  2951. defineCPUMacros(Builder, "geode");
  2952. break;
  2953. }
  2954. // Target properties.
  2955. Builder.defineMacro("__REGISTER_PREFIX__", "");
  2956. // Define __NO_MATH_INLINES on linux/x86 so that we don't get inline
  2957. // functions in glibc header files that use FP Stack inline asm which the
  2958. // backend can't deal with (PR879).
  2959. Builder.defineMacro("__NO_MATH_INLINES");
  2960. if (HasAES)
  2961. Builder.defineMacro("__AES__");
  2962. if (HasPCLMUL)
  2963. Builder.defineMacro("__PCLMUL__");
  2964. if (HasLZCNT)
  2965. Builder.defineMacro("__LZCNT__");
  2966. if (HasRDRND)
  2967. Builder.defineMacro("__RDRND__");
  2968. if (HasFSGSBASE)
  2969. Builder.defineMacro("__FSGSBASE__");
  2970. if (HasBMI)
  2971. Builder.defineMacro("__BMI__");
  2972. if (HasBMI2)
  2973. Builder.defineMacro("__BMI2__");
  2974. if (HasPOPCNT)
  2975. Builder.defineMacro("__POPCNT__");
  2976. if (HasRTM)
  2977. Builder.defineMacro("__RTM__");
  2978. if (HasPRFCHW)
  2979. Builder.defineMacro("__PRFCHW__");
  2980. if (HasRDSEED)
  2981. Builder.defineMacro("__RDSEED__");
  2982. if (HasADX)
  2983. Builder.defineMacro("__ADX__");
  2984. if (HasTBM)
  2985. Builder.defineMacro("__TBM__");
  2986. switch (XOPLevel) {
  2987. case XOP:
  2988. Builder.defineMacro("__XOP__");
  2989. case FMA4:
  2990. Builder.defineMacro("__FMA4__");
  2991. case SSE4A:
  2992. Builder.defineMacro("__SSE4A__");
  2993. case NoXOP:
  2994. break;
  2995. }
  2996. if (HasFMA)
  2997. Builder.defineMacro("__FMA__");
  2998. if (HasF16C)
  2999. Builder.defineMacro("__F16C__");
  3000. if (HasAVX512CD)
  3001. Builder.defineMacro("__AVX512CD__");
  3002. if (HasAVX512ER)
  3003. Builder.defineMacro("__AVX512ER__");
  3004. if (HasAVX512PF)
  3005. Builder.defineMacro("__AVX512PF__");
  3006. if (HasAVX512DQ)
  3007. Builder.defineMacro("__AVX512DQ__");
  3008. if (HasAVX512BW)
  3009. Builder.defineMacro("__AVX512BW__");
  3010. if (HasAVX512VL)
  3011. Builder.defineMacro("__AVX512VL__");
  3012. if (HasSHA)
  3013. Builder.defineMacro("__SHA__");
  3014. if (HasCX16)
  3015. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
  3016. // Each case falls through to the previous one here.
  3017. switch (SSELevel) {
  3018. case AVX512F:
  3019. Builder.defineMacro("__AVX512F__");
  3020. case AVX2:
  3021. Builder.defineMacro("__AVX2__");
  3022. case AVX:
  3023. Builder.defineMacro("__AVX__");
  3024. case SSE42:
  3025. Builder.defineMacro("__SSE4_2__");
  3026. case SSE41:
  3027. Builder.defineMacro("__SSE4_1__");
  3028. case SSSE3:
  3029. Builder.defineMacro("__SSSE3__");
  3030. case SSE3:
  3031. Builder.defineMacro("__SSE3__");
  3032. case SSE2:
  3033. Builder.defineMacro("__SSE2__");
  3034. Builder.defineMacro("__SSE2_MATH__"); // -mfp-math=sse always implied.
  3035. case SSE1:
  3036. Builder.defineMacro("__SSE__");
  3037. Builder.defineMacro("__SSE_MATH__"); // -mfp-math=sse always implied.
  3038. case NoSSE:
  3039. break;
  3040. }
  3041. if (Opts.MicrosoftExt && getTriple().getArch() == llvm::Triple::x86) {
  3042. switch (SSELevel) {
  3043. case AVX512F:
  3044. case AVX2:
  3045. case AVX:
  3046. case SSE42:
  3047. case SSE41:
  3048. case SSSE3:
  3049. case SSE3:
  3050. case SSE2:
  3051. Builder.defineMacro("_M_IX86_FP", Twine(2));
  3052. break;
  3053. case SSE1:
  3054. Builder.defineMacro("_M_IX86_FP", Twine(1));
  3055. break;
  3056. default:
  3057. Builder.defineMacro("_M_IX86_FP", Twine(0));
  3058. }
  3059. }
  3060. // Each case falls through to the previous one here.
  3061. switch (MMX3DNowLevel) {
  3062. case AMD3DNowAthlon:
  3063. Builder.defineMacro("__3dNOW_A__");
  3064. case AMD3DNow:
  3065. Builder.defineMacro("__3dNOW__");
  3066. case MMX:
  3067. Builder.defineMacro("__MMX__");
  3068. case NoMMX3DNow:
  3069. break;
  3070. }
  3071. if (CPU >= CK_i486) {
  3072. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
  3073. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
  3074. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
  3075. }
  3076. if (CPU >= CK_i586)
  3077. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
  3078. }
  3079. bool X86TargetInfo::hasFeature(StringRef Feature) const {
  3080. return llvm::StringSwitch<bool>(Feature)
  3081. .Case("aes", HasAES)
  3082. .Case("avx", SSELevel >= AVX)
  3083. .Case("avx2", SSELevel >= AVX2)
  3084. .Case("avx512f", SSELevel >= AVX512F)
  3085. .Case("avx512cd", HasAVX512CD)
  3086. .Case("avx512er", HasAVX512ER)
  3087. .Case("avx512pf", HasAVX512PF)
  3088. .Case("avx512dq", HasAVX512DQ)
  3089. .Case("avx512bw", HasAVX512BW)
  3090. .Case("avx512vl", HasAVX512VL)
  3091. .Case("bmi", HasBMI)
  3092. .Case("bmi2", HasBMI2)
  3093. .Case("cx16", HasCX16)
  3094. .Case("f16c", HasF16C)
  3095. .Case("fma", HasFMA)
  3096. .Case("fma4", XOPLevel >= FMA4)
  3097. .Case("fsgsbase", HasFSGSBASE)
  3098. .Case("lzcnt", HasLZCNT)
  3099. .Case("mm3dnow", MMX3DNowLevel >= AMD3DNow)
  3100. .Case("mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
  3101. .Case("mmx", MMX3DNowLevel >= MMX)
  3102. .Case("pclmul", HasPCLMUL)
  3103. .Case("popcnt", HasPOPCNT)
  3104. .Case("prfchw", HasPRFCHW)
  3105. .Case("rdrnd", HasRDRND)
  3106. .Case("rdseed", HasRDSEED)
  3107. .Case("rtm", HasRTM)
  3108. .Case("sha", HasSHA)
  3109. .Case("sse", SSELevel >= SSE1)
  3110. .Case("sse2", SSELevel >= SSE2)
  3111. .Case("sse3", SSELevel >= SSE3)
  3112. .Case("ssse3", SSELevel >= SSSE3)
  3113. .Case("sse4.1", SSELevel >= SSE41)
  3114. .Case("sse4.2", SSELevel >= SSE42)
  3115. .Case("sse4a", XOPLevel >= SSE4A)
  3116. .Case("tbm", HasTBM)
  3117. .Case("x86", true)
  3118. .Case("x86_32", getTriple().getArch() == llvm::Triple::x86)
  3119. .Case("x86_64", getTriple().getArch() == llvm::Triple::x86_64)
  3120. .Case("xop", XOPLevel >= XOP)
  3121. .Default(false);
  3122. }
  3123. // We can't use a generic validation scheme for the features accepted here
  3124. // versus subtarget features accepted in the target attribute because the
  3125. // bitfield structure that's initialized in the runtime only supports the
  3126. // below currently rather than the full range of subtarget features. (See
  3127. // X86TargetInfo::hasFeature for a somewhat comprehensive list).
  3128. bool X86TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
  3129. return llvm::StringSwitch<bool>(FeatureStr)
  3130. .Case("cmov", true)
  3131. .Case("mmx", true)
  3132. .Case("popcnt", true)
  3133. .Case("sse", true)
  3134. .Case("sse2", true)
  3135. .Case("sse3", true)
  3136. .Case("sse4.1", true)
  3137. .Case("sse4.2", true)
  3138. .Case("avx", true)
  3139. .Case("avx2", true)
  3140. .Case("sse4a", true)
  3141. .Case("fma4", true)
  3142. .Case("xop", true)
  3143. .Case("fma", true)
  3144. .Case("avx512f", true)
  3145. .Case("bmi", true)
  3146. .Case("bmi2", true)
  3147. .Default(false);
  3148. }
  3149. bool
  3150. X86TargetInfo::validateAsmConstraint(const char *&Name,
  3151. TargetInfo::ConstraintInfo &Info) const {
  3152. switch (*Name) {
  3153. default: return false;
  3154. case 'I':
  3155. Info.setRequiresImmediate(0, 31);
  3156. return true;
  3157. case 'J':
  3158. Info.setRequiresImmediate(0, 63);
  3159. return true;
  3160. case 'K':
  3161. Info.setRequiresImmediate(-128, 127);
  3162. return true;
  3163. case 'L':
  3164. // FIXME: properly analyze this constraint:
  3165. // must be one of 0xff, 0xffff, or 0xffffffff
  3166. return true;
  3167. case 'M':
  3168. Info.setRequiresImmediate(0, 3);
  3169. return true;
  3170. case 'N':
  3171. Info.setRequiresImmediate(0, 255);
  3172. return true;
  3173. case 'O':
  3174. Info.setRequiresImmediate(0, 127);
  3175. return true;
  3176. case 'Y': // first letter of a pair:
  3177. switch (*(Name+1)) {
  3178. default: return false;
  3179. case '0': // First SSE register.
  3180. case 't': // Any SSE register, when SSE2 is enabled.
  3181. case 'i': // Any SSE register, when SSE2 and inter-unit moves enabled.
  3182. case 'm': // any MMX register, when inter-unit moves enabled.
  3183. break; // falls through to setAllowsRegister.
  3184. }
  3185. case 'f': // any x87 floating point stack register.
  3186. // Constraint 'f' cannot be used for output operands.
  3187. if (Info.ConstraintStr[0] == '=')
  3188. return false;
  3189. Info.setAllowsRegister();
  3190. return true;
  3191. case 'a': // eax.
  3192. case 'b': // ebx.
  3193. case 'c': // ecx.
  3194. case 'd': // edx.
  3195. case 'S': // esi.
  3196. case 'D': // edi.
  3197. case 'A': // edx:eax.
  3198. case 't': // top of floating point stack.
  3199. case 'u': // second from top of floating point stack.
  3200. case 'q': // Any register accessible as [r]l: a, b, c, and d.
  3201. case 'y': // Any MMX register.
  3202. case 'x': // Any SSE register.
  3203. case 'Q': // Any register accessible as [r]h: a, b, c, and d.
  3204. case 'R': // "Legacy" registers: ax, bx, cx, dx, di, si, sp, bp.
  3205. case 'l': // "Index" registers: any general register that can be used as an
  3206. // index in a base+index memory access.
  3207. Info.setAllowsRegister();
  3208. return true;
  3209. case 'C': // SSE floating point constant.
  3210. case 'G': // x87 floating point constant.
  3211. case 'e': // 32-bit signed integer constant for use with zero-extending
  3212. // x86_64 instructions.
  3213. case 'Z': // 32-bit unsigned integer constant for use with zero-extending
  3214. // x86_64 instructions.
  3215. return true;
  3216. }
  3217. }
  3218. bool X86TargetInfo::validateOutputSize(StringRef Constraint,
  3219. unsigned Size) const {
  3220. // Strip off constraint modifiers.
  3221. while (Constraint[0] == '=' ||
  3222. Constraint[0] == '+' ||
  3223. Constraint[0] == '&')
  3224. Constraint = Constraint.substr(1);
  3225. return validateOperandSize(Constraint, Size);
  3226. }
  3227. bool X86TargetInfo::validateInputSize(StringRef Constraint,
  3228. unsigned Size) const {
  3229. return validateOperandSize(Constraint, Size);
  3230. }
  3231. bool X86TargetInfo::validateOperandSize(StringRef Constraint,
  3232. unsigned Size) const {
  3233. switch (Constraint[0]) {
  3234. default: break;
  3235. case 'y':
  3236. return Size <= 64;
  3237. case 'f':
  3238. case 't':
  3239. case 'u':
  3240. return Size <= 128;
  3241. case 'x':
  3242. // 256-bit ymm registers can be used if target supports AVX.
  3243. return Size <= (SSELevel >= AVX ? 256U : 128U);
  3244. }
  3245. return true;
  3246. }
  3247. std::string
  3248. X86TargetInfo::convertConstraint(const char *&Constraint) const {
  3249. switch (*Constraint) {
  3250. case 'a': return std::string("{ax}");
  3251. case 'b': return std::string("{bx}");
  3252. case 'c': return std::string("{cx}");
  3253. case 'd': return std::string("{dx}");
  3254. case 'S': return std::string("{si}");
  3255. case 'D': return std::string("{di}");
  3256. case 'p': // address
  3257. return std::string("im");
  3258. case 't': // top of floating point stack.
  3259. return std::string("{st}");
  3260. case 'u': // second from top of floating point stack.
  3261. return std::string("{st(1)}"); // second from top of floating point stack.
  3262. default:
  3263. return std::string(1, *Constraint);
  3264. }
  3265. }
  3266. // X86-32 generic target
  3267. class X86_32TargetInfo : public X86TargetInfo {
  3268. public:
  3269. X86_32TargetInfo(const llvm::Triple &Triple) : X86TargetInfo(Triple) {
  3270. DoubleAlign = LongLongAlign = 32;
  3271. LongDoubleWidth = 96;
  3272. LongDoubleAlign = 32;
  3273. SuitableAlign = 128;
  3274. DescriptionString = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128";
  3275. SizeType = UnsignedInt;
  3276. PtrDiffType = SignedInt;
  3277. IntPtrType = SignedInt;
  3278. RegParmMax = 3;
  3279. // Use fpret for all types.
  3280. RealTypeUsesObjCFPRet = ((1 << TargetInfo::Float) |
  3281. (1 << TargetInfo::Double) |
  3282. (1 << TargetInfo::LongDouble));
  3283. // x86-32 has atomics up to 8 bytes
  3284. // FIXME: Check that we actually have cmpxchg8b before setting
  3285. // MaxAtomicInlineWidth. (cmpxchg8b is an i586 instruction.)
  3286. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  3287. }
  3288. BuiltinVaListKind getBuiltinVaListKind() const override {
  3289. return TargetInfo::CharPtrBuiltinVaList;
  3290. }
  3291. int getEHDataRegisterNumber(unsigned RegNo) const override {
  3292. if (RegNo == 0) return 0;
  3293. if (RegNo == 1) return 2;
  3294. return -1;
  3295. }
  3296. bool validateOperandSize(StringRef Constraint,
  3297. unsigned Size) const override {
  3298. switch (Constraint[0]) {
  3299. default: break;
  3300. case 'R':
  3301. case 'q':
  3302. case 'Q':
  3303. case 'a':
  3304. case 'b':
  3305. case 'c':
  3306. case 'd':
  3307. case 'S':
  3308. case 'D':
  3309. return Size <= 32;
  3310. case 'A':
  3311. return Size <= 64;
  3312. }
  3313. return X86TargetInfo::validateOperandSize(Constraint, Size);
  3314. }
  3315. };
  3316. class NetBSDI386TargetInfo : public NetBSDTargetInfo<X86_32TargetInfo> {
  3317. public:
  3318. NetBSDI386TargetInfo(const llvm::Triple &Triple)
  3319. : NetBSDTargetInfo<X86_32TargetInfo>(Triple) {}
  3320. unsigned getFloatEvalMethod() const override {
  3321. unsigned Major, Minor, Micro;
  3322. getTriple().getOSVersion(Major, Minor, Micro);
  3323. // New NetBSD uses the default rounding mode.
  3324. if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 26) || Major == 0)
  3325. return X86_32TargetInfo::getFloatEvalMethod();
  3326. // NetBSD before 6.99.26 defaults to "double" rounding.
  3327. return 1;
  3328. }
  3329. };
  3330. class OpenBSDI386TargetInfo : public OpenBSDTargetInfo<X86_32TargetInfo> {
  3331. public:
  3332. OpenBSDI386TargetInfo(const llvm::Triple &Triple)
  3333. : OpenBSDTargetInfo<X86_32TargetInfo>(Triple) {
  3334. SizeType = UnsignedLong;
  3335. IntPtrType = SignedLong;
  3336. PtrDiffType = SignedLong;
  3337. }
  3338. };
  3339. class BitrigI386TargetInfo : public BitrigTargetInfo<X86_32TargetInfo> {
  3340. public:
  3341. BitrigI386TargetInfo(const llvm::Triple &Triple)
  3342. : BitrigTargetInfo<X86_32TargetInfo>(Triple) {
  3343. SizeType = UnsignedLong;
  3344. IntPtrType = SignedLong;
  3345. PtrDiffType = SignedLong;
  3346. }
  3347. };
  3348. class DarwinI386TargetInfo : public DarwinTargetInfo<X86_32TargetInfo> {
  3349. public:
  3350. DarwinI386TargetInfo(const llvm::Triple &Triple)
  3351. : DarwinTargetInfo<X86_32TargetInfo>(Triple) {
  3352. LongDoubleWidth = 128;
  3353. LongDoubleAlign = 128;
  3354. SuitableAlign = 128;
  3355. MaxVectorAlign = 256;
  3356. SizeType = UnsignedLong;
  3357. IntPtrType = SignedLong;
  3358. DescriptionString = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128";
  3359. HasAlignMac68kSupport = true;
  3360. }
  3361. };
  3362. // x86-32 Windows target
  3363. class WindowsX86_32TargetInfo : public WindowsTargetInfo<X86_32TargetInfo> {
  3364. public:
  3365. WindowsX86_32TargetInfo(const llvm::Triple &Triple)
  3366. : WindowsTargetInfo<X86_32TargetInfo>(Triple) {
  3367. WCharType = UnsignedShort;
  3368. DoubleAlign = LongLongAlign = 64;
  3369. bool IsWinCOFF =
  3370. getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
  3371. DescriptionString = IsWinCOFF
  3372. ? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
  3373. : "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32";
  3374. }
  3375. void getTargetDefines(const LangOptions &Opts,
  3376. MacroBuilder &Builder) const override {
  3377. WindowsTargetInfo<X86_32TargetInfo>::getTargetDefines(Opts, Builder);
  3378. }
  3379. };
  3380. // x86-32 Windows Visual Studio target
  3381. class MicrosoftX86_32TargetInfo : public WindowsX86_32TargetInfo {
  3382. public:
  3383. MicrosoftX86_32TargetInfo(const llvm::Triple &Triple)
  3384. : WindowsX86_32TargetInfo(Triple) {
  3385. LongDoubleWidth = LongDoubleAlign = 64;
  3386. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  3387. }
  3388. void getTargetDefines(const LangOptions &Opts,
  3389. MacroBuilder &Builder) const override {
  3390. WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
  3391. WindowsX86_32TargetInfo::getVisualStudioDefines(Opts, Builder);
  3392. // The value of the following reflects processor type.
  3393. // 300=386, 400=486, 500=Pentium, 600=Blend (default)
  3394. // We lost the original triple, so we use the default.
  3395. Builder.defineMacro("_M_IX86", "600");
  3396. }
  3397. };
  3398. } // end anonymous namespace
  3399. static void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder) {
  3400. // Mingw and cygwin define __declspec(a) to __attribute__((a)). Clang supports
  3401. // __declspec natively under -fms-extensions, but we define a no-op __declspec
  3402. // macro anyway for pre-processor compatibility.
  3403. if (Opts.MicrosoftExt)
  3404. Builder.defineMacro("__declspec", "__declspec");
  3405. else
  3406. Builder.defineMacro("__declspec(a)", "__attribute__((a))");
  3407. if (!Opts.MicrosoftExt) {
  3408. // Provide macros for all the calling convention keywords. Provide both
  3409. // single and double underscore prefixed variants. These are available on
  3410. // x64 as well as x86, even though they have no effect.
  3411. const char *CCs[] = {"cdecl", "stdcall", "fastcall", "thiscall", "pascal"};
  3412. for (const char *CC : CCs) {
  3413. std::string GCCSpelling = "__attribute__((__";
  3414. GCCSpelling += CC;
  3415. GCCSpelling += "__))";
  3416. Builder.defineMacro(Twine("_") + CC, GCCSpelling);
  3417. Builder.defineMacro(Twine("__") + CC, GCCSpelling);
  3418. }
  3419. }
  3420. }
  3421. static void addMinGWDefines(const LangOptions &Opts, MacroBuilder &Builder) {
  3422. Builder.defineMacro("__MSVCRT__");
  3423. Builder.defineMacro("__MINGW32__");
  3424. addCygMingDefines(Opts, Builder);
  3425. }
  3426. namespace {
  3427. // x86-32 MinGW target
  3428. class MinGWX86_32TargetInfo : public WindowsX86_32TargetInfo {
  3429. public:
  3430. MinGWX86_32TargetInfo(const llvm::Triple &Triple)
  3431. : WindowsX86_32TargetInfo(Triple) {}
  3432. void getTargetDefines(const LangOptions &Opts,
  3433. MacroBuilder &Builder) const override {
  3434. WindowsX86_32TargetInfo::getTargetDefines(Opts, Builder);
  3435. DefineStd(Builder, "WIN32", Opts);
  3436. DefineStd(Builder, "WINNT", Opts);
  3437. Builder.defineMacro("_X86_");
  3438. addMinGWDefines(Opts, Builder);
  3439. }
  3440. };
  3441. // x86-32 Cygwin target
  3442. class CygwinX86_32TargetInfo : public X86_32TargetInfo {
  3443. public:
  3444. CygwinX86_32TargetInfo(const llvm::Triple &Triple)
  3445. : X86_32TargetInfo(Triple) {
  3446. TLSSupported = false;
  3447. WCharType = UnsignedShort;
  3448. DoubleAlign = LongLongAlign = 64;
  3449. DescriptionString = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32";
  3450. }
  3451. void getTargetDefines(const LangOptions &Opts,
  3452. MacroBuilder &Builder) const override {
  3453. X86_32TargetInfo::getTargetDefines(Opts, Builder);
  3454. Builder.defineMacro("_X86_");
  3455. Builder.defineMacro("__CYGWIN__");
  3456. Builder.defineMacro("__CYGWIN32__");
  3457. addCygMingDefines(Opts, Builder);
  3458. DefineStd(Builder, "unix", Opts);
  3459. if (Opts.CPlusPlus)
  3460. Builder.defineMacro("_GNU_SOURCE");
  3461. }
  3462. };
  3463. // x86-32 Haiku target
  3464. class HaikuX86_32TargetInfo : public X86_32TargetInfo {
  3465. public:
  3466. HaikuX86_32TargetInfo(const llvm::Triple &Triple) : X86_32TargetInfo(Triple) {
  3467. SizeType = UnsignedLong;
  3468. IntPtrType = SignedLong;
  3469. PtrDiffType = SignedLong;
  3470. ProcessIDType = SignedLong;
  3471. this->UserLabelPrefix = "";
  3472. this->TLSSupported = false;
  3473. }
  3474. void getTargetDefines(const LangOptions &Opts,
  3475. MacroBuilder &Builder) const override {
  3476. X86_32TargetInfo::getTargetDefines(Opts, Builder);
  3477. Builder.defineMacro("__INTEL__");
  3478. Builder.defineMacro("__HAIKU__");
  3479. }
  3480. };
  3481. // RTEMS Target
  3482. template<typename Target>
  3483. class RTEMSTargetInfo : public OSTargetInfo<Target> {
  3484. protected:
  3485. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  3486. MacroBuilder &Builder) const override {
  3487. // RTEMS defines; list based off of gcc output
  3488. Builder.defineMacro("__rtems__");
  3489. Builder.defineMacro("__ELF__");
  3490. }
  3491. public:
  3492. RTEMSTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {
  3493. this->UserLabelPrefix = "";
  3494. switch (Triple.getArch()) {
  3495. default:
  3496. case llvm::Triple::x86:
  3497. // this->MCountName = ".mcount";
  3498. break;
  3499. case llvm::Triple::mips:
  3500. case llvm::Triple::mipsel:
  3501. case llvm::Triple::ppc:
  3502. case llvm::Triple::ppc64:
  3503. case llvm::Triple::ppc64le:
  3504. // this->MCountName = "_mcount";
  3505. break;
  3506. case llvm::Triple::arm:
  3507. // this->MCountName = "__mcount";
  3508. break;
  3509. }
  3510. }
  3511. };
  3512. // x86-32 RTEMS target
  3513. class RTEMSX86_32TargetInfo : public X86_32TargetInfo {
  3514. public:
  3515. RTEMSX86_32TargetInfo(const llvm::Triple &Triple) : X86_32TargetInfo(Triple) {
  3516. SizeType = UnsignedLong;
  3517. IntPtrType = SignedLong;
  3518. PtrDiffType = SignedLong;
  3519. this->UserLabelPrefix = "";
  3520. }
  3521. void getTargetDefines(const LangOptions &Opts,
  3522. MacroBuilder &Builder) const override {
  3523. X86_32TargetInfo::getTargetDefines(Opts, Builder);
  3524. Builder.defineMacro("__INTEL__");
  3525. Builder.defineMacro("__rtems__");
  3526. }
  3527. };
  3528. // x86-64 generic target
  3529. class X86_64TargetInfo : public X86TargetInfo {
  3530. public:
  3531. X86_64TargetInfo(const llvm::Triple &Triple) : X86TargetInfo(Triple) {
  3532. const bool IsX32 = getTriple().getEnvironment() == llvm::Triple::GNUX32;
  3533. bool IsWinCOFF =
  3534. getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
  3535. LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64;
  3536. LongDoubleWidth = 128;
  3537. LongDoubleAlign = 128;
  3538. LargeArrayMinWidth = 128;
  3539. LargeArrayAlign = 128;
  3540. SuitableAlign = 128;
  3541. SizeType = IsX32 ? UnsignedInt : UnsignedLong;
  3542. PtrDiffType = IsX32 ? SignedInt : SignedLong;
  3543. IntPtrType = IsX32 ? SignedInt : SignedLong;
  3544. IntMaxType = IsX32 ? SignedLongLong : SignedLong;
  3545. Int64Type = IsX32 ? SignedLongLong : SignedLong;
  3546. RegParmMax = 6;
  3547. // Pointers are 32-bit in x32.
  3548. DescriptionString = IsX32 ? "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128"
  3549. : IsWinCOFF
  3550. ? "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
  3551. : "e-m:e-i64:64-f80:128-n8:16:32:64-S128";
  3552. // Use fpret only for long double.
  3553. RealTypeUsesObjCFPRet = (1 << TargetInfo::LongDouble);
  3554. // Use fp2ret for _Complex long double.
  3555. ComplexLongDoubleUsesFP2Ret = true;
  3556. // x86-64 has atomics up to 16 bytes.
  3557. MaxAtomicPromoteWidth = 128;
  3558. MaxAtomicInlineWidth = 128;
  3559. }
  3560. BuiltinVaListKind getBuiltinVaListKind() const override {
  3561. return TargetInfo::X86_64ABIBuiltinVaList;
  3562. }
  3563. int getEHDataRegisterNumber(unsigned RegNo) const override {
  3564. if (RegNo == 0) return 0;
  3565. if (RegNo == 1) return 1;
  3566. return -1;
  3567. }
  3568. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  3569. return (CC == CC_C ||
  3570. CC == CC_X86VectorCall ||
  3571. CC == CC_IntelOclBicc ||
  3572. CC == CC_X86_64Win64) ? CCCR_OK : CCCR_Warning;
  3573. }
  3574. CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
  3575. return CC_C;
  3576. }
  3577. // for x32 we need it here explicitly
  3578. bool hasInt128Type() const override { return true; }
  3579. };
  3580. // x86-64 Windows target
  3581. class WindowsX86_64TargetInfo : public WindowsTargetInfo<X86_64TargetInfo> {
  3582. public:
  3583. WindowsX86_64TargetInfo(const llvm::Triple &Triple)
  3584. : WindowsTargetInfo<X86_64TargetInfo>(Triple) {
  3585. WCharType = UnsignedShort;
  3586. LongWidth = LongAlign = 32;
  3587. DoubleAlign = LongLongAlign = 64;
  3588. IntMaxType = SignedLongLong;
  3589. Int64Type = SignedLongLong;
  3590. SizeType = UnsignedLongLong;
  3591. PtrDiffType = SignedLongLong;
  3592. IntPtrType = SignedLongLong;
  3593. this->UserLabelPrefix = "";
  3594. }
  3595. void getTargetDefines(const LangOptions &Opts,
  3596. MacroBuilder &Builder) const override {
  3597. WindowsTargetInfo<X86_64TargetInfo>::getTargetDefines(Opts, Builder);
  3598. Builder.defineMacro("_WIN64");
  3599. }
  3600. BuiltinVaListKind getBuiltinVaListKind() const override {
  3601. return TargetInfo::CharPtrBuiltinVaList;
  3602. }
  3603. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  3604. switch (CC) {
  3605. case CC_X86StdCall:
  3606. case CC_X86ThisCall:
  3607. case CC_X86FastCall:
  3608. return CCCR_Ignore;
  3609. case CC_C:
  3610. case CC_X86VectorCall:
  3611. case CC_IntelOclBicc:
  3612. case CC_X86_64SysV:
  3613. return CCCR_OK;
  3614. default:
  3615. return CCCR_Warning;
  3616. }
  3617. }
  3618. };
  3619. // x86-64 Windows Visual Studio target
  3620. class MicrosoftX86_64TargetInfo : public WindowsX86_64TargetInfo {
  3621. public:
  3622. MicrosoftX86_64TargetInfo(const llvm::Triple &Triple)
  3623. : WindowsX86_64TargetInfo(Triple) {
  3624. LongDoubleWidth = LongDoubleAlign = 64;
  3625. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  3626. }
  3627. void getTargetDefines(const LangOptions &Opts,
  3628. MacroBuilder &Builder) const override {
  3629. WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
  3630. WindowsX86_64TargetInfo::getVisualStudioDefines(Opts, Builder);
  3631. Builder.defineMacro("_M_X64");
  3632. Builder.defineMacro("_M_AMD64");
  3633. }
  3634. };
  3635. // x86-64 MinGW target
  3636. class MinGWX86_64TargetInfo : public WindowsX86_64TargetInfo {
  3637. public:
  3638. MinGWX86_64TargetInfo(const llvm::Triple &Triple)
  3639. : WindowsX86_64TargetInfo(Triple) {}
  3640. void getTargetDefines(const LangOptions &Opts,
  3641. MacroBuilder &Builder) const override {
  3642. WindowsX86_64TargetInfo::getTargetDefines(Opts, Builder);
  3643. DefineStd(Builder, "WIN64", Opts);
  3644. Builder.defineMacro("__MINGW64__");
  3645. addMinGWDefines(Opts, Builder);
  3646. // GCC defines this macro when it is using __gxx_personality_seh0.
  3647. if (!Opts.SjLjExceptions)
  3648. Builder.defineMacro("__SEH__");
  3649. }
  3650. };
  3651. class DarwinX86_64TargetInfo : public DarwinTargetInfo<X86_64TargetInfo> {
  3652. public:
  3653. DarwinX86_64TargetInfo(const llvm::Triple &Triple)
  3654. : DarwinTargetInfo<X86_64TargetInfo>(Triple) {
  3655. Int64Type = SignedLongLong;
  3656. MaxVectorAlign = 256;
  3657. // The 64-bit iOS simulator uses the builtin bool type for Objective-C.
  3658. llvm::Triple T = llvm::Triple(Triple);
  3659. if (T.isiOS())
  3660. UseSignedCharForObjCBool = false;
  3661. DescriptionString = "e-m:o-i64:64-f80:128-n8:16:32:64-S128";
  3662. }
  3663. };
  3664. class OpenBSDX86_64TargetInfo : public OpenBSDTargetInfo<X86_64TargetInfo> {
  3665. public:
  3666. OpenBSDX86_64TargetInfo(const llvm::Triple &Triple)
  3667. : OpenBSDTargetInfo<X86_64TargetInfo>(Triple) {
  3668. IntMaxType = SignedLongLong;
  3669. Int64Type = SignedLongLong;
  3670. }
  3671. };
  3672. class BitrigX86_64TargetInfo : public BitrigTargetInfo<X86_64TargetInfo> {
  3673. public:
  3674. BitrigX86_64TargetInfo(const llvm::Triple &Triple)
  3675. : BitrigTargetInfo<X86_64TargetInfo>(Triple) {
  3676. IntMaxType = SignedLongLong;
  3677. Int64Type = SignedLongLong;
  3678. }
  3679. };
  3680. class ARMTargetInfo : public TargetInfo {
  3681. // Possible FPU choices.
  3682. enum FPUMode {
  3683. VFP2FPU = (1 << 0),
  3684. VFP3FPU = (1 << 1),
  3685. VFP4FPU = (1 << 2),
  3686. NeonFPU = (1 << 3),
  3687. FPARMV8 = (1 << 4)
  3688. };
  3689. // Possible HWDiv features.
  3690. enum HWDivMode {
  3691. HWDivThumb = (1 << 0),
  3692. HWDivARM = (1 << 1)
  3693. };
  3694. static bool FPUModeIsVFP(FPUMode Mode) {
  3695. return Mode & (VFP2FPU | VFP3FPU | VFP4FPU | NeonFPU | FPARMV8);
  3696. }
  3697. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  3698. static const char * const GCCRegNames[];
  3699. std::string ABI, CPU;
  3700. enum {
  3701. FP_Default,
  3702. FP_VFP,
  3703. FP_Neon
  3704. } FPMath;
  3705. unsigned FPU : 5;
  3706. unsigned IsAAPCS : 1;
  3707. unsigned IsThumb : 1;
  3708. unsigned HWDiv : 2;
  3709. // Initialized via features.
  3710. unsigned SoftFloat : 1;
  3711. unsigned SoftFloatABI : 1;
  3712. unsigned CRC : 1;
  3713. unsigned Crypto : 1;
  3714. // ACLE 6.5.1 Hardware floating point
  3715. enum {
  3716. HW_FP_HP = (1 << 1), /// half (16-bit)
  3717. HW_FP_SP = (1 << 2), /// single (32-bit)
  3718. HW_FP_DP = (1 << 3), /// double (64-bit)
  3719. };
  3720. uint32_t HW_FP;
  3721. static const Builtin::Info BuiltinInfo[];
  3722. static bool shouldUseInlineAtomic(const llvm::Triple &T) {
  3723. StringRef ArchName = T.getArchName();
  3724. if (T.getArch() == llvm::Triple::arm ||
  3725. T.getArch() == llvm::Triple::armeb) {
  3726. StringRef VersionStr;
  3727. if (ArchName.startswith("armv"))
  3728. VersionStr = ArchName.substr(4, 1);
  3729. else if (ArchName.startswith("armebv"))
  3730. VersionStr = ArchName.substr(6, 1);
  3731. else
  3732. return false;
  3733. unsigned Version;
  3734. if (VersionStr.getAsInteger(10, Version))
  3735. return false;
  3736. return Version >= 6;
  3737. }
  3738. assert(T.getArch() == llvm::Triple::thumb ||
  3739. T.getArch() == llvm::Triple::thumbeb);
  3740. StringRef VersionStr;
  3741. if (ArchName.startswith("thumbv"))
  3742. VersionStr = ArchName.substr(6, 1);
  3743. else if (ArchName.startswith("thumbebv"))
  3744. VersionStr = ArchName.substr(8, 1);
  3745. else
  3746. return false;
  3747. unsigned Version;
  3748. if (VersionStr.getAsInteger(10, Version))
  3749. return false;
  3750. return Version >= 7;
  3751. }
  3752. void setABIAAPCS() {
  3753. IsAAPCS = true;
  3754. DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 64;
  3755. const llvm::Triple &T = getTriple();
  3756. // size_t is unsigned long on MachO-derived environments, NetBSD and Bitrig.
  3757. if (T.isOSBinFormatMachO() || T.getOS() == llvm::Triple::NetBSD ||
  3758. T.getOS() == llvm::Triple::Bitrig)
  3759. SizeType = UnsignedLong;
  3760. else
  3761. SizeType = UnsignedInt;
  3762. switch (T.getOS()) {
  3763. case llvm::Triple::NetBSD:
  3764. WCharType = SignedInt;
  3765. break;
  3766. case llvm::Triple::Win32:
  3767. WCharType = UnsignedShort;
  3768. break;
  3769. case llvm::Triple::Linux:
  3770. default:
  3771. // AAPCS 7.1.1, ARM-Linux ABI 2.4: type of wchar_t is unsigned int.
  3772. WCharType = UnsignedInt;
  3773. break;
  3774. }
  3775. UseBitFieldTypeAlignment = true;
  3776. ZeroLengthBitfieldBoundary = 0;
  3777. // Thumb1 add sp, #imm requires the immediate value be multiple of 4,
  3778. // so set preferred for small types to 32.
  3779. if (T.isOSBinFormatMachO()) {
  3780. DescriptionString =
  3781. BigEndian ? "E-m:o-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
  3782. : "e-m:o-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64";
  3783. } else if (T.isOSWindows()) {
  3784. assert(!BigEndian && "Windows on ARM does not support big endian");
  3785. DescriptionString = "e"
  3786. "-m:w"
  3787. "-p:32:32"
  3788. "-i64:64"
  3789. "-v128:64:128"
  3790. "-a:0:32"
  3791. "-n32"
  3792. "-S64";
  3793. } else if (T.isOSNaCl()) {
  3794. assert(!BigEndian && "NaCl on ARM does not support big endian");
  3795. DescriptionString = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S128";
  3796. } else {
  3797. DescriptionString =
  3798. BigEndian ? "E-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
  3799. : "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64";
  3800. }
  3801. // FIXME: Enumerated types are variable width in straight AAPCS.
  3802. }
  3803. void setABIAPCS() {
  3804. const llvm::Triple &T = getTriple();
  3805. IsAAPCS = false;
  3806. DoubleAlign = LongLongAlign = LongDoubleAlign = SuitableAlign = 32;
  3807. // size_t is unsigned int on FreeBSD.
  3808. if (T.getOS() == llvm::Triple::FreeBSD)
  3809. SizeType = UnsignedInt;
  3810. else
  3811. SizeType = UnsignedLong;
  3812. // Revert to using SignedInt on apcs-gnu to comply with existing behaviour.
  3813. WCharType = SignedInt;
  3814. // Do not respect the alignment of bit-field types when laying out
  3815. // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
  3816. UseBitFieldTypeAlignment = false;
  3817. /// gcc forces the alignment to 4 bytes, regardless of the type of the
  3818. /// zero length bitfield. This corresponds to EMPTY_FIELD_BOUNDARY in
  3819. /// gcc.
  3820. ZeroLengthBitfieldBoundary = 32;
  3821. if (T.isOSBinFormatMachO())
  3822. DescriptionString =
  3823. BigEndian
  3824. ? "E-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
  3825. : "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32";
  3826. else
  3827. DescriptionString =
  3828. BigEndian
  3829. ? "E-m:e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
  3830. : "e-m:e-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32";
  3831. // FIXME: Override "preferred align" for double and long long.
  3832. }
  3833. public:
  3834. ARMTargetInfo(const llvm::Triple &Triple, bool IsBigEndian)
  3835. : TargetInfo(Triple), CPU("arm1136j-s"), FPMath(FP_Default),
  3836. IsAAPCS(true), HW_FP(0) {
  3837. BigEndian = IsBigEndian;
  3838. switch (getTriple().getOS()) {
  3839. case llvm::Triple::NetBSD:
  3840. PtrDiffType = SignedLong;
  3841. break;
  3842. default:
  3843. PtrDiffType = SignedInt;
  3844. break;
  3845. }
  3846. // {} in inline assembly are neon specifiers, not assembly variant
  3847. // specifiers.
  3848. NoAsmVariants = true;
  3849. // FIXME: Should we just treat this as a feature?
  3850. IsThumb = getTriple().getArchName().startswith("thumb");
  3851. // FIXME: This duplicates code from the driver that sets the -target-abi
  3852. // option - this code is used if -target-abi isn't passed and should
  3853. // be unified in some way.
  3854. if (Triple.isOSBinFormatMachO()) {
  3855. // The backend is hardwired to assume AAPCS for M-class processors, ensure
  3856. // the frontend matches that.
  3857. if (Triple.getEnvironment() == llvm::Triple::EABI ||
  3858. Triple.getOS() == llvm::Triple::UnknownOS ||
  3859. StringRef(CPU).startswith("cortex-m")) {
  3860. setABI("aapcs");
  3861. } else {
  3862. setABI("apcs-gnu");
  3863. }
  3864. } else if (Triple.isOSWindows()) {
  3865. // FIXME: this is invalid for WindowsCE
  3866. setABI("aapcs");
  3867. } else {
  3868. // Select the default based on the platform.
  3869. switch (Triple.getEnvironment()) {
  3870. case llvm::Triple::Android:
  3871. case llvm::Triple::GNUEABI:
  3872. case llvm::Triple::GNUEABIHF:
  3873. setABI("aapcs-linux");
  3874. break;
  3875. case llvm::Triple::EABIHF:
  3876. case llvm::Triple::EABI:
  3877. setABI("aapcs");
  3878. break;
  3879. case llvm::Triple::GNU:
  3880. setABI("apcs-gnu");
  3881. break;
  3882. default:
  3883. if (Triple.getOS() == llvm::Triple::NetBSD)
  3884. setABI("apcs-gnu");
  3885. else
  3886. setABI("aapcs");
  3887. break;
  3888. }
  3889. }
  3890. // ARM targets default to using the ARM C++ ABI.
  3891. TheCXXABI.set(TargetCXXABI::GenericARM);
  3892. // ARM has atomics up to 8 bytes
  3893. MaxAtomicPromoteWidth = 64;
  3894. if (shouldUseInlineAtomic(getTriple()))
  3895. MaxAtomicInlineWidth = 64;
  3896. // Do force alignment of members that follow zero length bitfields. If
  3897. // the alignment of the zero-length bitfield is greater than the member
  3898. // that follows it, `bar', `bar' will be aligned as the type of the
  3899. // zero length bitfield.
  3900. UseZeroLengthBitfieldAlignment = true;
  3901. }
  3902. StringRef getABI() const override { return ABI; }
  3903. bool setABI(const std::string &Name) override {
  3904. ABI = Name;
  3905. // The defaults (above) are for AAPCS, check if we need to change them.
  3906. //
  3907. // FIXME: We need support for -meabi... we could just mangle it into the
  3908. // name.
  3909. if (Name == "apcs-gnu") {
  3910. setABIAPCS();
  3911. return true;
  3912. }
  3913. if (Name == "aapcs" || Name == "aapcs-vfp" || Name == "aapcs-linux") {
  3914. setABIAAPCS();
  3915. return true;
  3916. }
  3917. return false;
  3918. }
  3919. // FIXME: This should be based on Arch attributes, not CPU names.
  3920. void getDefaultFeatures(llvm::StringMap<bool> &Features) const override {
  3921. StringRef ArchName = getTriple().getArchName();
  3922. unsigned ArchKind = llvm::ARMTargetParser::parseArch(ArchName);
  3923. bool IsV8 = (ArchKind == llvm::ARM::AK_ARMV8A ||
  3924. ArchKind == llvm::ARM::AK_ARMV8_1A);
  3925. if (CPU == "arm1136jf-s" || CPU == "arm1176jzf-s" || CPU == "mpcore")
  3926. Features["vfp2"] = true;
  3927. else if (CPU == "cortex-a8" || CPU == "cortex-a9") {
  3928. Features["vfp3"] = true;
  3929. Features["neon"] = true;
  3930. }
  3931. else if (CPU == "cortex-a5") {
  3932. Features["vfp4"] = true;
  3933. Features["neon"] = true;
  3934. } else if (CPU == "swift" || CPU == "cortex-a7" ||
  3935. CPU == "cortex-a12" || CPU == "cortex-a15" ||
  3936. CPU == "cortex-a17" || CPU == "krait") {
  3937. Features["vfp4"] = true;
  3938. Features["neon"] = true;
  3939. Features["hwdiv"] = true;
  3940. Features["hwdiv-arm"] = true;
  3941. } else if (CPU == "cyclone" || CPU == "cortex-a53" || CPU == "cortex-a57" ||
  3942. CPU == "cortex-a72") {
  3943. Features["fp-armv8"] = true;
  3944. Features["neon"] = true;
  3945. Features["hwdiv"] = true;
  3946. Features["hwdiv-arm"] = true;
  3947. Features["crc"] = true;
  3948. Features["crypto"] = true;
  3949. } else if (CPU == "cortex-r5" || CPU == "cortex-r7" || IsV8) {
  3950. Features["hwdiv"] = true;
  3951. Features["hwdiv-arm"] = true;
  3952. } else if (CPU == "cortex-m3" || CPU == "cortex-m4" || CPU == "cortex-m7" ||
  3953. CPU == "sc300" || CPU == "cortex-r4" || CPU == "cortex-r4f") {
  3954. Features["hwdiv"] = true;
  3955. }
  3956. }
  3957. bool handleTargetFeatures(std::vector<std::string> &Features,
  3958. DiagnosticsEngine &Diags) override {
  3959. FPU = 0;
  3960. CRC = 0;
  3961. Crypto = 0;
  3962. SoftFloat = SoftFloatABI = false;
  3963. HWDiv = 0;
  3964. // This does not diagnose illegal cases like having both
  3965. // "+vfpv2" and "+vfpv3" or having "+neon" and "+fp-only-sp".
  3966. uint32_t HW_FP_remove = 0;
  3967. for (const auto &Feature : Features) {
  3968. if (Feature == "+soft-float") {
  3969. SoftFloat = true;
  3970. } else if (Feature == "+soft-float-abi") {
  3971. SoftFloatABI = true;
  3972. } else if (Feature == "+vfp2") {
  3973. FPU |= VFP2FPU;
  3974. HW_FP |= HW_FP_SP | HW_FP_DP;
  3975. } else if (Feature == "+vfp3") {
  3976. FPU |= VFP3FPU;
  3977. HW_FP |= HW_FP_SP | HW_FP_DP;
  3978. } else if (Feature == "+vfp4") {
  3979. FPU |= VFP4FPU;
  3980. HW_FP |= HW_FP_SP | HW_FP_DP | HW_FP_HP;
  3981. } else if (Feature == "+fp-armv8") {
  3982. FPU |= FPARMV8;
  3983. HW_FP |= HW_FP_SP | HW_FP_DP | HW_FP_HP;
  3984. } else if (Feature == "+neon") {
  3985. FPU |= NeonFPU;
  3986. HW_FP |= HW_FP_SP | HW_FP_DP;
  3987. } else if (Feature == "+hwdiv") {
  3988. HWDiv |= HWDivThumb;
  3989. } else if (Feature == "+hwdiv-arm") {
  3990. HWDiv |= HWDivARM;
  3991. } else if (Feature == "+crc") {
  3992. CRC = 1;
  3993. } else if (Feature == "+crypto") {
  3994. Crypto = 1;
  3995. } else if (Feature == "+fp-only-sp") {
  3996. HW_FP_remove |= HW_FP_DP | HW_FP_HP;
  3997. }
  3998. }
  3999. HW_FP &= ~HW_FP_remove;
  4000. if (!(FPU & NeonFPU) && FPMath == FP_Neon) {
  4001. Diags.Report(diag::err_target_unsupported_fpmath) << "neon";
  4002. return false;
  4003. }
  4004. if (FPMath == FP_Neon)
  4005. Features.push_back("+neonfp");
  4006. else if (FPMath == FP_VFP)
  4007. Features.push_back("-neonfp");
  4008. // Remove front-end specific options which the backend handles differently.
  4009. auto Feature =
  4010. std::find(Features.begin(), Features.end(), "+soft-float-abi");
  4011. if (Feature != Features.end())
  4012. Features.erase(Feature);
  4013. return true;
  4014. }
  4015. bool hasFeature(StringRef Feature) const override {
  4016. return llvm::StringSwitch<bool>(Feature)
  4017. .Case("arm", true)
  4018. .Case("softfloat", SoftFloat)
  4019. .Case("thumb", IsThumb)
  4020. .Case("neon", (FPU & NeonFPU) && !SoftFloat)
  4021. .Case("hwdiv", HWDiv & HWDivThumb)
  4022. .Case("hwdiv-arm", HWDiv & HWDivARM)
  4023. .Default(false);
  4024. }
  4025. const char *getCPUDefineSuffix(StringRef Name) const {
  4026. if(Name == "generic") {
  4027. auto subarch = getTriple().getSubArch();
  4028. switch (subarch) {
  4029. case llvm::Triple::SubArchType::ARMSubArch_v8_1a:
  4030. return "8_1A";
  4031. default:
  4032. break;
  4033. }
  4034. }
  4035. unsigned ArchKind = llvm::ARMTargetParser::parseCPUArch(Name);
  4036. if (ArchKind == llvm::ARM::AK_INVALID)
  4037. return "";
  4038. // For most sub-arches, the build attribute CPU name is enough.
  4039. // For Cortex variants, it's slightly different.
  4040. switch(ArchKind) {
  4041. default:
  4042. return llvm::ARMTargetParser::getCPUAttr(ArchKind);
  4043. case llvm::ARM::AK_ARMV6M:
  4044. case llvm::ARM::AK_ARMV6SM:
  4045. return "6M";
  4046. case llvm::ARM::AK_ARMV7:
  4047. case llvm::ARM::AK_ARMV7A:
  4048. case llvm::ARM::AK_ARMV7S:
  4049. return "7A";
  4050. case llvm::ARM::AK_ARMV7R:
  4051. return "7R";
  4052. case llvm::ARM::AK_ARMV7M:
  4053. return "7M";
  4054. case llvm::ARM::AK_ARMV7EM:
  4055. return "7EM";
  4056. case llvm::ARM::AK_ARMV8A:
  4057. return "8A";
  4058. case llvm::ARM::AK_ARMV8_1A:
  4059. return "8_1A";
  4060. }
  4061. }
  4062. const char *getCPUProfile(StringRef Name) const {
  4063. if(Name == "generic") {
  4064. auto subarch = getTriple().getSubArch();
  4065. switch (subarch) {
  4066. case llvm::Triple::SubArchType::ARMSubArch_v8_1a:
  4067. return "A";
  4068. default:
  4069. break;
  4070. }
  4071. }
  4072. unsigned CPUArch = llvm::ARMTargetParser::parseCPUArch(Name);
  4073. if (CPUArch == llvm::ARM::AK_INVALID)
  4074. return "";
  4075. StringRef ArchName = llvm::ARMTargetParser::getArchName(CPUArch);
  4076. switch(llvm::ARMTargetParser::parseArchProfile(ArchName)) {
  4077. case llvm::ARM::PK_A:
  4078. return "A";
  4079. case llvm::ARM::PK_R:
  4080. return "R";
  4081. case llvm::ARM::PK_M:
  4082. return "M";
  4083. default:
  4084. return "";
  4085. }
  4086. }
  4087. bool setCPU(const std::string &Name) override {
  4088. if (!getCPUDefineSuffix(Name))
  4089. return false;
  4090. // Cortex M does not support 8 byte atomics, while general Thumb2 does.
  4091. StringRef Profile = getCPUProfile(Name);
  4092. if (Profile == "M" && MaxAtomicInlineWidth) {
  4093. MaxAtomicPromoteWidth = 32;
  4094. MaxAtomicInlineWidth = 32;
  4095. }
  4096. CPU = Name;
  4097. return true;
  4098. }
  4099. bool setFPMath(StringRef Name) override;
  4100. bool supportsThumb(StringRef ArchName, StringRef CPUArch,
  4101. unsigned CPUArchVer) const {
  4102. return CPUArchVer >= 7 || (CPUArch.find('T') != StringRef::npos) ||
  4103. (CPUArch.find('M') != StringRef::npos);
  4104. }
  4105. bool supportsThumb2(StringRef ArchName, StringRef CPUArch,
  4106. unsigned CPUArchVer) const {
  4107. // We check both CPUArchVer and ArchName because when only triple is
  4108. // specified, the default CPU is arm1136j-s.
  4109. return ArchName.endswith("v6t2") || ArchName.endswith("v7") ||
  4110. ArchName.endswith("v8.1a") ||
  4111. ArchName.endswith("v8") || CPUArch == "6T2" || CPUArchVer >= 7;
  4112. }
  4113. void getTargetDefines(const LangOptions &Opts,
  4114. MacroBuilder &Builder) const override {
  4115. // Target identification.
  4116. Builder.defineMacro("__arm");
  4117. Builder.defineMacro("__arm__");
  4118. // Target properties.
  4119. Builder.defineMacro("__REGISTER_PREFIX__", "");
  4120. StringRef CPUArch = getCPUDefineSuffix(CPU);
  4121. unsigned int CPUArchVer;
  4122. if (CPUArch.substr(0, 1).getAsInteger<unsigned int>(10, CPUArchVer))
  4123. llvm_unreachable("Invalid char for architecture version number");
  4124. Builder.defineMacro("__ARM_ARCH_" + CPUArch + "__");
  4125. // ACLE 6.4.1 ARM/Thumb instruction set architecture
  4126. StringRef CPUProfile = getCPUProfile(CPU);
  4127. StringRef ArchName = getTriple().getArchName();
  4128. // __ARM_ARCH is defined as an integer value indicating the current ARM ISA
  4129. Builder.defineMacro("__ARM_ARCH", CPUArch.substr(0, 1));
  4130. if (CPUArch[0] >= '8') {
  4131. Builder.defineMacro("__ARM_FEATURE_NUMERIC_MAXMIN");
  4132. Builder.defineMacro("__ARM_FEATURE_DIRECTED_ROUNDING");
  4133. }
  4134. // __ARM_ARCH_ISA_ARM is defined to 1 if the core supports the ARM ISA. It
  4135. // is not defined for the M-profile.
  4136. // NOTE that the deffault profile is assumed to be 'A'
  4137. if (CPUProfile.empty() || CPUProfile != "M")
  4138. Builder.defineMacro("__ARM_ARCH_ISA_ARM", "1");
  4139. // __ARM_ARCH_ISA_THUMB is defined to 1 if the core supporst the original
  4140. // Thumb ISA (including v6-M). It is set to 2 if the core supports the
  4141. // Thumb-2 ISA as found in the v6T2 architecture and all v7 architecture.
  4142. if (supportsThumb2(ArchName, CPUArch, CPUArchVer))
  4143. Builder.defineMacro("__ARM_ARCH_ISA_THUMB", "2");
  4144. else if (supportsThumb(ArchName, CPUArch, CPUArchVer))
  4145. Builder.defineMacro("__ARM_ARCH_ISA_THUMB", "1");
  4146. // __ARM_32BIT_STATE is defined to 1 if code is being generated for a 32-bit
  4147. // instruction set such as ARM or Thumb.
  4148. Builder.defineMacro("__ARM_32BIT_STATE", "1");
  4149. // ACLE 6.4.2 Architectural Profile (A, R, M or pre-Cortex)
  4150. // __ARM_ARCH_PROFILE is defined as 'A', 'R', 'M' or 'S', or unset.
  4151. if (!CPUProfile.empty())
  4152. Builder.defineMacro("__ARM_ARCH_PROFILE", "'" + CPUProfile + "'");
  4153. // ACLE 6.5.1 Hardware Floating Point
  4154. if (HW_FP)
  4155. Builder.defineMacro("__ARM_FP", "0x" + llvm::utohexstr(HW_FP));
  4156. // ACLE predefines.
  4157. Builder.defineMacro("__ARM_ACLE", "200");
  4158. // Subtarget options.
  4159. // FIXME: It's more complicated than this and we don't really support
  4160. // interworking.
  4161. // Windows on ARM does not "support" interworking
  4162. if (5 <= CPUArchVer && CPUArchVer <= 8 && !getTriple().isOSWindows())
  4163. Builder.defineMacro("__THUMB_INTERWORK__");
  4164. if (ABI == "aapcs" || ABI == "aapcs-linux" || ABI == "aapcs-vfp") {
  4165. // Embedded targets on Darwin follow AAPCS, but not EABI.
  4166. // Windows on ARM follows AAPCS VFP, but does not conform to EABI.
  4167. if (!getTriple().isOSDarwin() && !getTriple().isOSWindows())
  4168. Builder.defineMacro("__ARM_EABI__");
  4169. Builder.defineMacro("__ARM_PCS", "1");
  4170. if ((!SoftFloat && !SoftFloatABI) || ABI == "aapcs-vfp")
  4171. Builder.defineMacro("__ARM_PCS_VFP", "1");
  4172. }
  4173. if (SoftFloat)
  4174. Builder.defineMacro("__SOFTFP__");
  4175. if (CPU == "xscale")
  4176. Builder.defineMacro("__XSCALE__");
  4177. if (IsThumb) {
  4178. Builder.defineMacro("__THUMBEL__");
  4179. Builder.defineMacro("__thumb__");
  4180. if (supportsThumb2(ArchName, CPUArch, CPUArchVer))
  4181. Builder.defineMacro("__thumb2__");
  4182. }
  4183. if (((HWDiv & HWDivThumb) && IsThumb) || ((HWDiv & HWDivARM) && !IsThumb))
  4184. Builder.defineMacro("__ARM_ARCH_EXT_IDIV__", "1");
  4185. // Note, this is always on in gcc, even though it doesn't make sense.
  4186. Builder.defineMacro("__APCS_32__");
  4187. if (FPUModeIsVFP((FPUMode) FPU)) {
  4188. Builder.defineMacro("__VFP_FP__");
  4189. if (FPU & VFP2FPU)
  4190. Builder.defineMacro("__ARM_VFPV2__");
  4191. if (FPU & VFP3FPU)
  4192. Builder.defineMacro("__ARM_VFPV3__");
  4193. if (FPU & VFP4FPU)
  4194. Builder.defineMacro("__ARM_VFPV4__");
  4195. }
  4196. // This only gets set when Neon instructions are actually available, unlike
  4197. // the VFP define, hence the soft float and arch check. This is subtly
  4198. // different from gcc, we follow the intent which was that it should be set
  4199. // when Neon instructions are actually available.
  4200. if ((FPU & NeonFPU) && !SoftFloat && CPUArchVer >= 7) {
  4201. Builder.defineMacro("__ARM_NEON");
  4202. Builder.defineMacro("__ARM_NEON__");
  4203. }
  4204. Builder.defineMacro("__ARM_SIZEOF_WCHAR_T",
  4205. Opts.ShortWChar ? "2" : "4");
  4206. Builder.defineMacro("__ARM_SIZEOF_MINIMAL_ENUM",
  4207. Opts.ShortEnums ? "1" : "4");
  4208. if (CRC)
  4209. Builder.defineMacro("__ARM_FEATURE_CRC32");
  4210. if (Crypto)
  4211. Builder.defineMacro("__ARM_FEATURE_CRYPTO");
  4212. if (CPUArchVer >= 6 && CPUArch != "6M") {
  4213. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
  4214. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
  4215. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
  4216. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
  4217. }
  4218. bool is5EOrAbove = (CPUArchVer >= 6 ||
  4219. (CPUArchVer == 5 &&
  4220. CPUArch.find('E') != StringRef::npos));
  4221. bool is32Bit = (!IsThumb || supportsThumb2(ArchName, CPUArch, CPUArchVer));
  4222. if (is5EOrAbove && is32Bit && (CPUProfile != "M" || CPUArch == "7EM"))
  4223. Builder.defineMacro("__ARM_FEATURE_DSP");
  4224. }
  4225. void getTargetBuiltins(const Builtin::Info *&Records,
  4226. unsigned &NumRecords) const override {
  4227. Records = BuiltinInfo;
  4228. NumRecords = clang::ARM::LastTSBuiltin-Builtin::FirstTSBuiltin;
  4229. }
  4230. bool isCLZForZeroUndef() const override { return false; }
  4231. BuiltinVaListKind getBuiltinVaListKind() const override {
  4232. return IsAAPCS ? AAPCSABIBuiltinVaList : TargetInfo::VoidPtrBuiltinVaList;
  4233. }
  4234. void getGCCRegNames(const char * const *&Names,
  4235. unsigned &NumNames) const override;
  4236. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  4237. unsigned &NumAliases) const override;
  4238. bool validateAsmConstraint(const char *&Name,
  4239. TargetInfo::ConstraintInfo &Info) const override {
  4240. switch (*Name) {
  4241. default: break;
  4242. case 'l': // r0-r7
  4243. case 'h': // r8-r15
  4244. case 'w': // VFP Floating point register single precision
  4245. case 'P': // VFP Floating point register double precision
  4246. Info.setAllowsRegister();
  4247. return true;
  4248. case 'I':
  4249. case 'J':
  4250. case 'K':
  4251. case 'L':
  4252. case 'M':
  4253. // FIXME
  4254. return true;
  4255. case 'Q': // A memory address that is a single base register.
  4256. Info.setAllowsMemory();
  4257. return true;
  4258. case 'U': // a memory reference...
  4259. switch (Name[1]) {
  4260. case 'q': // ...ARMV4 ldrsb
  4261. case 'v': // ...VFP load/store (reg+constant offset)
  4262. case 'y': // ...iWMMXt load/store
  4263. case 't': // address valid for load/store opaque types wider
  4264. // than 128-bits
  4265. case 'n': // valid address for Neon doubleword vector load/store
  4266. case 'm': // valid address for Neon element and structure load/store
  4267. case 's': // valid address for non-offset loads/stores of quad-word
  4268. // values in four ARM registers
  4269. Info.setAllowsMemory();
  4270. Name++;
  4271. return true;
  4272. }
  4273. }
  4274. return false;
  4275. }
  4276. std::string convertConstraint(const char *&Constraint) const override {
  4277. std::string R;
  4278. switch (*Constraint) {
  4279. case 'U': // Two-character constraint; add "^" hint for later parsing.
  4280. R = std::string("^") + std::string(Constraint, 2);
  4281. Constraint++;
  4282. break;
  4283. case 'p': // 'p' should be translated to 'r' by default.
  4284. R = std::string("r");
  4285. break;
  4286. default:
  4287. return std::string(1, *Constraint);
  4288. }
  4289. return R;
  4290. }
  4291. bool
  4292. validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
  4293. std::string &SuggestedModifier) const override {
  4294. bool isOutput = (Constraint[0] == '=');
  4295. bool isInOut = (Constraint[0] == '+');
  4296. // Strip off constraint modifiers.
  4297. while (Constraint[0] == '=' ||
  4298. Constraint[0] == '+' ||
  4299. Constraint[0] == '&')
  4300. Constraint = Constraint.substr(1);
  4301. switch (Constraint[0]) {
  4302. default: break;
  4303. case 'r': {
  4304. switch (Modifier) {
  4305. default:
  4306. return (isInOut || isOutput || Size <= 64);
  4307. case 'q':
  4308. // A register of size 32 cannot fit a vector type.
  4309. return false;
  4310. }
  4311. }
  4312. }
  4313. return true;
  4314. }
  4315. const char *getClobbers() const override {
  4316. // FIXME: Is this really right?
  4317. return "";
  4318. }
  4319. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  4320. return (CC == CC_AAPCS || CC == CC_AAPCS_VFP) ? CCCR_OK : CCCR_Warning;
  4321. }
  4322. int getEHDataRegisterNumber(unsigned RegNo) const override {
  4323. if (RegNo == 0) return 0;
  4324. if (RegNo == 1) return 1;
  4325. return -1;
  4326. }
  4327. };
  4328. bool ARMTargetInfo::setFPMath(StringRef Name) {
  4329. if (Name == "neon") {
  4330. FPMath = FP_Neon;
  4331. return true;
  4332. } else if (Name == "vfp" || Name == "vfp2" || Name == "vfp3" ||
  4333. Name == "vfp4") {
  4334. FPMath = FP_VFP;
  4335. return true;
  4336. }
  4337. return false;
  4338. }
  4339. const char * const ARMTargetInfo::GCCRegNames[] = {
  4340. // Integer registers
  4341. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  4342. "r8", "r9", "r10", "r11", "r12", "sp", "lr", "pc",
  4343. // Float registers
  4344. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  4345. "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
  4346. "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
  4347. "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
  4348. // Double registers
  4349. "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
  4350. "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15",
  4351. "d16", "d17", "d18", "d19", "d20", "d21", "d22", "d23",
  4352. "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
  4353. // Quad registers
  4354. "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7",
  4355. "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15"
  4356. };
  4357. void ARMTargetInfo::getGCCRegNames(const char * const *&Names,
  4358. unsigned &NumNames) const {
  4359. Names = GCCRegNames;
  4360. NumNames = llvm::array_lengthof(GCCRegNames);
  4361. }
  4362. const TargetInfo::GCCRegAlias ARMTargetInfo::GCCRegAliases[] = {
  4363. { { "a1" }, "r0" },
  4364. { { "a2" }, "r1" },
  4365. { { "a3" }, "r2" },
  4366. { { "a4" }, "r3" },
  4367. { { "v1" }, "r4" },
  4368. { { "v2" }, "r5" },
  4369. { { "v3" }, "r6" },
  4370. { { "v4" }, "r7" },
  4371. { { "v5" }, "r8" },
  4372. { { "v6", "rfp" }, "r9" },
  4373. { { "sl" }, "r10" },
  4374. { { "fp" }, "r11" },
  4375. { { "ip" }, "r12" },
  4376. { { "r13" }, "sp" },
  4377. { { "r14" }, "lr" },
  4378. { { "r15" }, "pc" },
  4379. // The S, D and Q registers overlap, but aren't really aliases; we
  4380. // don't want to substitute one of these for a different-sized one.
  4381. };
  4382. void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
  4383. unsigned &NumAliases) const {
  4384. Aliases = GCCRegAliases;
  4385. NumAliases = llvm::array_lengthof(GCCRegAliases);
  4386. }
  4387. const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
  4388. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  4389. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  4390. ALL_LANGUAGES },
  4391. #include "clang/Basic/BuiltinsNEON.def"
  4392. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  4393. #define LANGBUILTIN(ID, TYPE, ATTRS, LANG) { #ID, TYPE, ATTRS, 0, LANG },
  4394. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  4395. ALL_LANGUAGES },
  4396. #include "clang/Basic/BuiltinsARM.def"
  4397. };
  4398. class ARMleTargetInfo : public ARMTargetInfo {
  4399. public:
  4400. ARMleTargetInfo(const llvm::Triple &Triple)
  4401. : ARMTargetInfo(Triple, false) { }
  4402. void getTargetDefines(const LangOptions &Opts,
  4403. MacroBuilder &Builder) const override {
  4404. Builder.defineMacro("__ARMEL__");
  4405. ARMTargetInfo::getTargetDefines(Opts, Builder);
  4406. }
  4407. };
  4408. class ARMbeTargetInfo : public ARMTargetInfo {
  4409. public:
  4410. ARMbeTargetInfo(const llvm::Triple &Triple)
  4411. : ARMTargetInfo(Triple, true) { }
  4412. void getTargetDefines(const LangOptions &Opts,
  4413. MacroBuilder &Builder) const override {
  4414. Builder.defineMacro("__ARMEB__");
  4415. Builder.defineMacro("__ARM_BIG_ENDIAN");
  4416. ARMTargetInfo::getTargetDefines(Opts, Builder);
  4417. }
  4418. };
  4419. class WindowsARMTargetInfo : public WindowsTargetInfo<ARMleTargetInfo> {
  4420. const llvm::Triple Triple;
  4421. public:
  4422. WindowsARMTargetInfo(const llvm::Triple &Triple)
  4423. : WindowsTargetInfo<ARMleTargetInfo>(Triple), Triple(Triple) {
  4424. TLSSupported = false;
  4425. WCharType = UnsignedShort;
  4426. SizeType = UnsignedInt;
  4427. UserLabelPrefix = "";
  4428. }
  4429. void getVisualStudioDefines(const LangOptions &Opts,
  4430. MacroBuilder &Builder) const {
  4431. WindowsTargetInfo<ARMleTargetInfo>::getVisualStudioDefines(Opts, Builder);
  4432. // FIXME: this is invalid for WindowsCE
  4433. Builder.defineMacro("_M_ARM_NT", "1");
  4434. Builder.defineMacro("_M_ARMT", "_M_ARM");
  4435. Builder.defineMacro("_M_THUMB", "_M_ARM");
  4436. assert((Triple.getArch() == llvm::Triple::arm ||
  4437. Triple.getArch() == llvm::Triple::thumb) &&
  4438. "invalid architecture for Windows ARM target info");
  4439. unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
  4440. Builder.defineMacro("_M_ARM", Triple.getArchName().substr(Offset));
  4441. // TODO map the complete set of values
  4442. // 31: VFPv3 40: VFPv4
  4443. Builder.defineMacro("_M_ARM_FP", "31");
  4444. }
  4445. BuiltinVaListKind getBuiltinVaListKind() const override {
  4446. return TargetInfo::CharPtrBuiltinVaList;
  4447. }
  4448. };
  4449. // Windows ARM + Itanium C++ ABI Target
  4450. class ItaniumWindowsARMleTargetInfo : public WindowsARMTargetInfo {
  4451. public:
  4452. ItaniumWindowsARMleTargetInfo(const llvm::Triple &Triple)
  4453. : WindowsARMTargetInfo(Triple) {
  4454. TheCXXABI.set(TargetCXXABI::GenericARM);
  4455. }
  4456. void getTargetDefines(const LangOptions &Opts,
  4457. MacroBuilder &Builder) const override {
  4458. WindowsARMTargetInfo::getTargetDefines(Opts, Builder);
  4459. if (Opts.MSVCCompat)
  4460. WindowsARMTargetInfo::getVisualStudioDefines(Opts, Builder);
  4461. }
  4462. };
  4463. // Windows ARM, MS (C++) ABI
  4464. class MicrosoftARMleTargetInfo : public WindowsARMTargetInfo {
  4465. public:
  4466. MicrosoftARMleTargetInfo(const llvm::Triple &Triple)
  4467. : WindowsARMTargetInfo(Triple) {
  4468. TheCXXABI.set(TargetCXXABI::Microsoft);
  4469. }
  4470. void getTargetDefines(const LangOptions &Opts,
  4471. MacroBuilder &Builder) const override {
  4472. WindowsARMTargetInfo::getTargetDefines(Opts, Builder);
  4473. WindowsARMTargetInfo::getVisualStudioDefines(Opts, Builder);
  4474. }
  4475. };
  4476. class DarwinARMTargetInfo :
  4477. public DarwinTargetInfo<ARMleTargetInfo> {
  4478. protected:
  4479. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  4480. MacroBuilder &Builder) const override {
  4481. getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
  4482. }
  4483. public:
  4484. DarwinARMTargetInfo(const llvm::Triple &Triple)
  4485. : DarwinTargetInfo<ARMleTargetInfo>(Triple) {
  4486. HasAlignMac68kSupport = true;
  4487. // iOS always has 64-bit atomic instructions.
  4488. // FIXME: This should be based off of the target features in
  4489. // ARMleTargetInfo.
  4490. MaxAtomicInlineWidth = 64;
  4491. // Darwin on iOS uses a variant of the ARM C++ ABI.
  4492. TheCXXABI.set(TargetCXXABI::iOS);
  4493. }
  4494. };
  4495. class AArch64TargetInfo : public TargetInfo {
  4496. virtual void setDescriptionString() = 0;
  4497. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  4498. static const char *const GCCRegNames[];
  4499. enum FPUModeEnum {
  4500. FPUMode,
  4501. NeonMode
  4502. };
  4503. unsigned FPU;
  4504. unsigned CRC;
  4505. unsigned Crypto;
  4506. static const Builtin::Info BuiltinInfo[];
  4507. std::string ABI;
  4508. public:
  4509. AArch64TargetInfo(const llvm::Triple &Triple)
  4510. : TargetInfo(Triple), ABI("aapcs") {
  4511. if (getTriple().getOS() == llvm::Triple::NetBSD) {
  4512. WCharType = SignedInt;
  4513. // NetBSD apparently prefers consistency across ARM targets to consistency
  4514. // across 64-bit targets.
  4515. Int64Type = SignedLongLong;
  4516. IntMaxType = SignedLongLong;
  4517. } else {
  4518. WCharType = UnsignedInt;
  4519. Int64Type = SignedLong;
  4520. IntMaxType = SignedLong;
  4521. }
  4522. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  4523. MaxVectorAlign = 128;
  4524. MaxAtomicInlineWidth = 128;
  4525. MaxAtomicPromoteWidth = 128;
  4526. LongDoubleWidth = LongDoubleAlign = SuitableAlign = 128;
  4527. LongDoubleFormat = &llvm::APFloat::IEEEquad;
  4528. // {} in inline assembly are neon specifiers, not assembly variant
  4529. // specifiers.
  4530. NoAsmVariants = true;
  4531. // AAPCS gives rules for bitfields. 7.1.7 says: "The container type
  4532. // contributes to the alignment of the containing aggregate in the same way
  4533. // a plain (non bit-field) member of that type would, without exception for
  4534. // zero-sized or anonymous bit-fields."
  4535. UseBitFieldTypeAlignment = true;
  4536. UseZeroLengthBitfieldAlignment = true;
  4537. // AArch64 targets default to using the ARM C++ ABI.
  4538. TheCXXABI.set(TargetCXXABI::GenericAArch64);
  4539. }
  4540. StringRef getABI() const override { return ABI; }
  4541. bool setABI(const std::string &Name) override {
  4542. if (Name != "aapcs" && Name != "darwinpcs")
  4543. return false;
  4544. ABI = Name;
  4545. return true;
  4546. }
  4547. bool setCPU(const std::string &Name) override {
  4548. bool CPUKnown = llvm::StringSwitch<bool>(Name)
  4549. .Case("generic", true)
  4550. .Cases("cortex-a53", "cortex-a57", "cortex-a72", true)
  4551. .Case("cyclone", true)
  4552. .Default(false);
  4553. return CPUKnown;
  4554. }
  4555. void getTargetDefines(const LangOptions &Opts,
  4556. MacroBuilder &Builder) const override {
  4557. // Target identification.
  4558. Builder.defineMacro("__aarch64__");
  4559. // Target properties.
  4560. Builder.defineMacro("_LP64");
  4561. Builder.defineMacro("__LP64__");
  4562. // ACLE predefines. Many can only have one possible value on v8 AArch64.
  4563. Builder.defineMacro("__ARM_ACLE", "200");
  4564. Builder.defineMacro("__ARM_ARCH", "8");
  4565. Builder.defineMacro("__ARM_ARCH_PROFILE", "'A'");
  4566. Builder.defineMacro("__ARM_64BIT_STATE");
  4567. Builder.defineMacro("__ARM_PCS_AAPCS64");
  4568. Builder.defineMacro("__ARM_ARCH_ISA_A64");
  4569. Builder.defineMacro("__ARM_FEATURE_UNALIGNED");
  4570. Builder.defineMacro("__ARM_FEATURE_CLZ");
  4571. Builder.defineMacro("__ARM_FEATURE_FMA");
  4572. Builder.defineMacro("__ARM_FEATURE_DIV");
  4573. Builder.defineMacro("__ARM_FEATURE_IDIV"); // As specified in ACLE
  4574. Builder.defineMacro("__ARM_FEATURE_DIV"); // For backwards compatibility
  4575. Builder.defineMacro("__ARM_FEATURE_NUMERIC_MAXMIN");
  4576. Builder.defineMacro("__ARM_FEATURE_DIRECTED_ROUNDING");
  4577. Builder.defineMacro("__ARM_ALIGN_MAX_STACK_PWR", "4");
  4578. // 0xe implies support for half, single and double precision operations.
  4579. Builder.defineMacro("__ARM_FP", "0xe");
  4580. // PCS specifies this for SysV variants, which is all we support. Other ABIs
  4581. // may choose __ARM_FP16_FORMAT_ALTERNATIVE.
  4582. Builder.defineMacro("__ARM_FP16_FORMAT_IEEE");
  4583. if (Opts.FastMath || Opts.FiniteMathOnly)
  4584. Builder.defineMacro("__ARM_FP_FAST");
  4585. if (Opts.C99 && !Opts.Freestanding)
  4586. Builder.defineMacro("__ARM_FP_FENV_ROUNDING");
  4587. Builder.defineMacro("__ARM_SIZEOF_WCHAR_T", Opts.ShortWChar ? "2" : "4");
  4588. Builder.defineMacro("__ARM_SIZEOF_MINIMAL_ENUM",
  4589. Opts.ShortEnums ? "1" : "4");
  4590. if (FPU == NeonMode) {
  4591. Builder.defineMacro("__ARM_NEON");
  4592. // 64-bit NEON supports half, single and double precision operations.
  4593. Builder.defineMacro("__ARM_NEON_FP", "0xe");
  4594. }
  4595. if (CRC)
  4596. Builder.defineMacro("__ARM_FEATURE_CRC32");
  4597. if (Crypto)
  4598. Builder.defineMacro("__ARM_FEATURE_CRYPTO");
  4599. // All of the __sync_(bool|val)_compare_and_swap_(1|2|4|8) builtins work.
  4600. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
  4601. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
  4602. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
  4603. Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
  4604. }
  4605. void getTargetBuiltins(const Builtin::Info *&Records,
  4606. unsigned &NumRecords) const override {
  4607. Records = BuiltinInfo;
  4608. NumRecords = clang::AArch64::LastTSBuiltin - Builtin::FirstTSBuiltin;
  4609. }
  4610. bool hasFeature(StringRef Feature) const override {
  4611. return Feature == "aarch64" ||
  4612. Feature == "arm64" ||
  4613. (Feature == "neon" && FPU == NeonMode);
  4614. }
  4615. bool handleTargetFeatures(std::vector<std::string> &Features,
  4616. DiagnosticsEngine &Diags) override {
  4617. FPU = FPUMode;
  4618. CRC = 0;
  4619. Crypto = 0;
  4620. for (unsigned i = 0, e = Features.size(); i != e; ++i) {
  4621. if (Features[i] == "+neon")
  4622. FPU = NeonMode;
  4623. if (Features[i] == "+crc")
  4624. CRC = 1;
  4625. if (Features[i] == "+crypto")
  4626. Crypto = 1;
  4627. }
  4628. setDescriptionString();
  4629. return true;
  4630. }
  4631. bool isCLZForZeroUndef() const override { return false; }
  4632. BuiltinVaListKind getBuiltinVaListKind() const override {
  4633. return TargetInfo::AArch64ABIBuiltinVaList;
  4634. }
  4635. void getGCCRegNames(const char *const *&Names,
  4636. unsigned &NumNames) const override;
  4637. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  4638. unsigned &NumAliases) const override;
  4639. bool validateAsmConstraint(const char *&Name,
  4640. TargetInfo::ConstraintInfo &Info) const override {
  4641. switch (*Name) {
  4642. default:
  4643. return false;
  4644. case 'w': // Floating point and SIMD registers (V0-V31)
  4645. Info.setAllowsRegister();
  4646. return true;
  4647. case 'I': // Constant that can be used with an ADD instruction
  4648. case 'J': // Constant that can be used with a SUB instruction
  4649. case 'K': // Constant that can be used with a 32-bit logical instruction
  4650. case 'L': // Constant that can be used with a 64-bit logical instruction
  4651. case 'M': // Constant that can be used as a 32-bit MOV immediate
  4652. case 'N': // Constant that can be used as a 64-bit MOV immediate
  4653. case 'Y': // Floating point constant zero
  4654. case 'Z': // Integer constant zero
  4655. return true;
  4656. case 'Q': // A memory reference with base register and no offset
  4657. Info.setAllowsMemory();
  4658. return true;
  4659. case 'S': // A symbolic address
  4660. Info.setAllowsRegister();
  4661. return true;
  4662. case 'U':
  4663. // Ump: A memory address suitable for ldp/stp in SI, DI, SF and DF modes.
  4664. // Utf: A memory address suitable for ldp/stp in TF mode.
  4665. // Usa: An absolute symbolic address.
  4666. // Ush: The high part (bits 32:12) of a pc-relative symbolic address.
  4667. llvm_unreachable("FIXME: Unimplemented support for U* constraints.");
  4668. case 'z': // Zero register, wzr or xzr
  4669. Info.setAllowsRegister();
  4670. return true;
  4671. case 'x': // Floating point and SIMD registers (V0-V15)
  4672. Info.setAllowsRegister();
  4673. return true;
  4674. }
  4675. return false;
  4676. }
  4677. bool
  4678. validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
  4679. std::string &SuggestedModifier) const override {
  4680. // Strip off constraint modifiers.
  4681. while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
  4682. Constraint = Constraint.substr(1);
  4683. switch (Constraint[0]) {
  4684. default:
  4685. return true;
  4686. case 'z':
  4687. case 'r': {
  4688. switch (Modifier) {
  4689. case 'x':
  4690. case 'w':
  4691. // For now assume that the person knows what they're
  4692. // doing with the modifier.
  4693. return true;
  4694. default:
  4695. // By default an 'r' constraint will be in the 'x'
  4696. // registers.
  4697. if (Size == 64)
  4698. return true;
  4699. SuggestedModifier = "w";
  4700. return false;
  4701. }
  4702. }
  4703. }
  4704. }
  4705. const char *getClobbers() const override { return ""; }
  4706. int getEHDataRegisterNumber(unsigned RegNo) const override {
  4707. if (RegNo == 0)
  4708. return 0;
  4709. if (RegNo == 1)
  4710. return 1;
  4711. return -1;
  4712. }
  4713. };
  4714. const char *const AArch64TargetInfo::GCCRegNames[] = {
  4715. // 32-bit Integer registers
  4716. "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10",
  4717. "w11", "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21",
  4718. "w22", "w23", "w24", "w25", "w26", "w27", "w28", "w29", "w30", "wsp",
  4719. // 64-bit Integer registers
  4720. "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10",
  4721. "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21",
  4722. "x22", "x23", "x24", "x25", "x26", "x27", "x28", "fp", "lr", "sp",
  4723. // 32-bit floating point regsisters
  4724. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "s10",
  4725. "s11", "s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19", "s20", "s21",
  4726. "s22", "s23", "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
  4727. // 64-bit floating point regsisters
  4728. "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10",
  4729. "d11", "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19", "d20", "d21",
  4730. "d22", "d23", "d24", "d25", "d26", "d27", "d28", "d29", "d30", "d31",
  4731. // Vector registers
  4732. "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10",
  4733. "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21",
  4734. "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
  4735. };
  4736. void AArch64TargetInfo::getGCCRegNames(const char *const *&Names,
  4737. unsigned &NumNames) const {
  4738. Names = GCCRegNames;
  4739. NumNames = llvm::array_lengthof(GCCRegNames);
  4740. }
  4741. const TargetInfo::GCCRegAlias AArch64TargetInfo::GCCRegAliases[] = {
  4742. { { "w31" }, "wsp" },
  4743. { { "x29" }, "fp" },
  4744. { { "x30" }, "lr" },
  4745. { { "x31" }, "sp" },
  4746. // The S/D/Q and W/X registers overlap, but aren't really aliases; we
  4747. // don't want to substitute one of these for a different-sized one.
  4748. };
  4749. void AArch64TargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
  4750. unsigned &NumAliases) const {
  4751. Aliases = GCCRegAliases;
  4752. NumAliases = llvm::array_lengthof(GCCRegAliases);
  4753. }
  4754. const Builtin::Info AArch64TargetInfo::BuiltinInfo[] = {
  4755. #define BUILTIN(ID, TYPE, ATTRS) \
  4756. { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  4757. #include "clang/Basic/BuiltinsNEON.def"
  4758. #define BUILTIN(ID, TYPE, ATTRS) \
  4759. { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  4760. #include "clang/Basic/BuiltinsAArch64.def"
  4761. };
  4762. class AArch64leTargetInfo : public AArch64TargetInfo {
  4763. void setDescriptionString() override {
  4764. if (getTriple().isOSBinFormatMachO())
  4765. DescriptionString = "e-m:o-i64:64-i128:128-n32:64-S128";
  4766. else
  4767. DescriptionString = "e-m:e-i64:64-i128:128-n32:64-S128";
  4768. }
  4769. public:
  4770. AArch64leTargetInfo(const llvm::Triple &Triple)
  4771. : AArch64TargetInfo(Triple) {
  4772. BigEndian = false;
  4773. }
  4774. void getTargetDefines(const LangOptions &Opts,
  4775. MacroBuilder &Builder) const override {
  4776. Builder.defineMacro("__AARCH64EL__");
  4777. AArch64TargetInfo::getTargetDefines(Opts, Builder);
  4778. }
  4779. };
  4780. class AArch64beTargetInfo : public AArch64TargetInfo {
  4781. void setDescriptionString() override {
  4782. assert(!getTriple().isOSBinFormatMachO());
  4783. DescriptionString = "E-m:e-i64:64-i128:128-n32:64-S128";
  4784. }
  4785. public:
  4786. AArch64beTargetInfo(const llvm::Triple &Triple)
  4787. : AArch64TargetInfo(Triple) { }
  4788. void getTargetDefines(const LangOptions &Opts,
  4789. MacroBuilder &Builder) const override {
  4790. Builder.defineMacro("__AARCH64EB__");
  4791. Builder.defineMacro("__AARCH_BIG_ENDIAN");
  4792. Builder.defineMacro("__ARM_BIG_ENDIAN");
  4793. AArch64TargetInfo::getTargetDefines(Opts, Builder);
  4794. }
  4795. };
  4796. class DarwinAArch64TargetInfo : public DarwinTargetInfo<AArch64leTargetInfo> {
  4797. protected:
  4798. void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
  4799. MacroBuilder &Builder) const override {
  4800. Builder.defineMacro("__AARCH64_SIMD__");
  4801. Builder.defineMacro("__ARM64_ARCH_8__");
  4802. Builder.defineMacro("__ARM_NEON__");
  4803. Builder.defineMacro("__LITTLE_ENDIAN__");
  4804. Builder.defineMacro("__REGISTER_PREFIX__", "");
  4805. Builder.defineMacro("__arm64", "1");
  4806. Builder.defineMacro("__arm64__", "1");
  4807. getDarwinDefines(Builder, Opts, Triple, PlatformName, PlatformMinVersion);
  4808. }
  4809. public:
  4810. DarwinAArch64TargetInfo(const llvm::Triple &Triple)
  4811. : DarwinTargetInfo<AArch64leTargetInfo>(Triple) {
  4812. Int64Type = SignedLongLong;
  4813. WCharType = SignedInt;
  4814. UseSignedCharForObjCBool = false;
  4815. LongDoubleWidth = LongDoubleAlign = SuitableAlign = 64;
  4816. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  4817. TheCXXABI.set(TargetCXXABI::iOS64);
  4818. }
  4819. BuiltinVaListKind getBuiltinVaListKind() const override {
  4820. return TargetInfo::CharPtrBuiltinVaList;
  4821. }
  4822. };
  4823. // Hexagon abstract base class
  4824. class HexagonTargetInfo : public TargetInfo {
  4825. static const Builtin::Info BuiltinInfo[];
  4826. static const char * const GCCRegNames[];
  4827. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  4828. std::string CPU;
  4829. public:
  4830. HexagonTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  4831. BigEndian = false;
  4832. DescriptionString = "e-m:e-p:32:32-i1:32-i64:64-a:0-n32";
  4833. // {} in inline assembly are packet specifiers, not assembly variant
  4834. // specifiers.
  4835. NoAsmVariants = true;
  4836. }
  4837. void getTargetBuiltins(const Builtin::Info *&Records,
  4838. unsigned &NumRecords) const override {
  4839. Records = BuiltinInfo;
  4840. NumRecords = clang::Hexagon::LastTSBuiltin-Builtin::FirstTSBuiltin;
  4841. }
  4842. bool validateAsmConstraint(const char *&Name,
  4843. TargetInfo::ConstraintInfo &Info) const override {
  4844. return true;
  4845. }
  4846. void getTargetDefines(const LangOptions &Opts,
  4847. MacroBuilder &Builder) const override;
  4848. bool hasFeature(StringRef Feature) const override {
  4849. return Feature == "hexagon";
  4850. }
  4851. BuiltinVaListKind getBuiltinVaListKind() const override {
  4852. return TargetInfo::CharPtrBuiltinVaList;
  4853. }
  4854. void getGCCRegNames(const char * const *&Names,
  4855. unsigned &NumNames) const override;
  4856. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  4857. unsigned &NumAliases) const override;
  4858. const char *getClobbers() const override {
  4859. return "";
  4860. }
  4861. static const char *getHexagonCPUSuffix(StringRef Name) {
  4862. return llvm::StringSwitch<const char*>(Name)
  4863. .Case("hexagonv4", "4")
  4864. .Case("hexagonv5", "5")
  4865. .Default(nullptr);
  4866. }
  4867. bool setCPU(const std::string &Name) override {
  4868. if (!getHexagonCPUSuffix(Name))
  4869. return false;
  4870. CPU = Name;
  4871. return true;
  4872. }
  4873. };
  4874. void HexagonTargetInfo::getTargetDefines(const LangOptions &Opts,
  4875. MacroBuilder &Builder) const {
  4876. Builder.defineMacro("qdsp6");
  4877. Builder.defineMacro("__qdsp6", "1");
  4878. Builder.defineMacro("__qdsp6__", "1");
  4879. Builder.defineMacro("hexagon");
  4880. Builder.defineMacro("__hexagon", "1");
  4881. Builder.defineMacro("__hexagon__", "1");
  4882. if(CPU == "hexagonv1") {
  4883. Builder.defineMacro("__HEXAGON_V1__");
  4884. Builder.defineMacro("__HEXAGON_ARCH__", "1");
  4885. if(Opts.HexagonQdsp6Compat) {
  4886. Builder.defineMacro("__QDSP6_V1__");
  4887. Builder.defineMacro("__QDSP6_ARCH__", "1");
  4888. }
  4889. }
  4890. else if(CPU == "hexagonv2") {
  4891. Builder.defineMacro("__HEXAGON_V2__");
  4892. Builder.defineMacro("__HEXAGON_ARCH__", "2");
  4893. if(Opts.HexagonQdsp6Compat) {
  4894. Builder.defineMacro("__QDSP6_V2__");
  4895. Builder.defineMacro("__QDSP6_ARCH__", "2");
  4896. }
  4897. }
  4898. else if(CPU == "hexagonv3") {
  4899. Builder.defineMacro("__HEXAGON_V3__");
  4900. Builder.defineMacro("__HEXAGON_ARCH__", "3");
  4901. if(Opts.HexagonQdsp6Compat) {
  4902. Builder.defineMacro("__QDSP6_V3__");
  4903. Builder.defineMacro("__QDSP6_ARCH__", "3");
  4904. }
  4905. }
  4906. else if(CPU == "hexagonv4") {
  4907. Builder.defineMacro("__HEXAGON_V4__");
  4908. Builder.defineMacro("__HEXAGON_ARCH__", "4");
  4909. if(Opts.HexagonQdsp6Compat) {
  4910. Builder.defineMacro("__QDSP6_V4__");
  4911. Builder.defineMacro("__QDSP6_ARCH__", "4");
  4912. }
  4913. }
  4914. else if(CPU == "hexagonv5") {
  4915. Builder.defineMacro("__HEXAGON_V5__");
  4916. Builder.defineMacro("__HEXAGON_ARCH__", "5");
  4917. if(Opts.HexagonQdsp6Compat) {
  4918. Builder.defineMacro("__QDSP6_V5__");
  4919. Builder.defineMacro("__QDSP6_ARCH__", "5");
  4920. }
  4921. }
  4922. }
  4923. const char * const HexagonTargetInfo::GCCRegNames[] = {
  4924. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  4925. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  4926. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  4927. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
  4928. "p0", "p1", "p2", "p3",
  4929. "sa0", "lc0", "sa1", "lc1", "m0", "m1", "usr", "ugp"
  4930. };
  4931. void HexagonTargetInfo::getGCCRegNames(const char * const *&Names,
  4932. unsigned &NumNames) const {
  4933. Names = GCCRegNames;
  4934. NumNames = llvm::array_lengthof(GCCRegNames);
  4935. }
  4936. const TargetInfo::GCCRegAlias HexagonTargetInfo::GCCRegAliases[] = {
  4937. { { "sp" }, "r29" },
  4938. { { "fp" }, "r30" },
  4939. { { "lr" }, "r31" },
  4940. };
  4941. void HexagonTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
  4942. unsigned &NumAliases) const {
  4943. Aliases = GCCRegAliases;
  4944. NumAliases = llvm::array_lengthof(GCCRegAliases);
  4945. }
  4946. const Builtin::Info HexagonTargetInfo::BuiltinInfo[] = {
  4947. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  4948. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  4949. ALL_LANGUAGES },
  4950. #include "clang/Basic/BuiltinsHexagon.def"
  4951. };
  4952. // Shared base class for SPARC v8 (32-bit) and SPARC v9 (64-bit).
  4953. class SparcTargetInfo : public TargetInfo {
  4954. static const TargetInfo::GCCRegAlias GCCRegAliases[];
  4955. static const char * const GCCRegNames[];
  4956. bool SoftFloat;
  4957. public:
  4958. SparcTargetInfo(const llvm::Triple &Triple)
  4959. : TargetInfo(Triple), SoftFloat(false) {}
  4960. bool handleTargetFeatures(std::vector<std::string> &Features,
  4961. DiagnosticsEngine &Diags) override {
  4962. // The backend doesn't actually handle soft float yet, but in case someone
  4963. // is using the support for the front end continue to support it.
  4964. auto Feature = std::find(Features.begin(), Features.end(), "+soft-float");
  4965. if (Feature != Features.end()) {
  4966. SoftFloat = true;
  4967. Features.erase(Feature);
  4968. }
  4969. return true;
  4970. }
  4971. void getTargetDefines(const LangOptions &Opts,
  4972. MacroBuilder &Builder) const override {
  4973. DefineStd(Builder, "sparc", Opts);
  4974. Builder.defineMacro("__REGISTER_PREFIX__", "");
  4975. if (SoftFloat)
  4976. Builder.defineMacro("SOFT_FLOAT", "1");
  4977. }
  4978. bool hasFeature(StringRef Feature) const override {
  4979. return llvm::StringSwitch<bool>(Feature)
  4980. .Case("softfloat", SoftFloat)
  4981. .Case("sparc", true)
  4982. .Default(false);
  4983. }
  4984. void getTargetBuiltins(const Builtin::Info *&Records,
  4985. unsigned &NumRecords) const override {
  4986. // FIXME: Implement!
  4987. }
  4988. BuiltinVaListKind getBuiltinVaListKind() const override {
  4989. return TargetInfo::VoidPtrBuiltinVaList;
  4990. }
  4991. void getGCCRegNames(const char * const *&Names,
  4992. unsigned &NumNames) const override;
  4993. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  4994. unsigned &NumAliases) const override;
  4995. bool validateAsmConstraint(const char *&Name,
  4996. TargetInfo::ConstraintInfo &info) const override {
  4997. // FIXME: Implement!
  4998. switch (*Name) {
  4999. case 'I': // Signed 13-bit constant
  5000. case 'J': // Zero
  5001. case 'K': // 32-bit constant with the low 12 bits clear
  5002. case 'L': // A constant in the range supported by movcc (11-bit signed imm)
  5003. case 'M': // A constant in the range supported by movrcc (19-bit signed imm)
  5004. case 'N': // Same as 'K' but zext (required for SIMode)
  5005. case 'O': // The constant 4096
  5006. return true;
  5007. }
  5008. return false;
  5009. }
  5010. const char *getClobbers() const override {
  5011. // FIXME: Implement!
  5012. return "";
  5013. }
  5014. };
  5015. const char * const SparcTargetInfo::GCCRegNames[] = {
  5016. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  5017. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  5018. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  5019. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
  5020. };
  5021. void SparcTargetInfo::getGCCRegNames(const char * const *&Names,
  5022. unsigned &NumNames) const {
  5023. Names = GCCRegNames;
  5024. NumNames = llvm::array_lengthof(GCCRegNames);
  5025. }
  5026. const TargetInfo::GCCRegAlias SparcTargetInfo::GCCRegAliases[] = {
  5027. { { "g0" }, "r0" },
  5028. { { "g1" }, "r1" },
  5029. { { "g2" }, "r2" },
  5030. { { "g3" }, "r3" },
  5031. { { "g4" }, "r4" },
  5032. { { "g5" }, "r5" },
  5033. { { "g6" }, "r6" },
  5034. { { "g7" }, "r7" },
  5035. { { "o0" }, "r8" },
  5036. { { "o1" }, "r9" },
  5037. { { "o2" }, "r10" },
  5038. { { "o3" }, "r11" },
  5039. { { "o4" }, "r12" },
  5040. { { "o5" }, "r13" },
  5041. { { "o6", "sp" }, "r14" },
  5042. { { "o7" }, "r15" },
  5043. { { "l0" }, "r16" },
  5044. { { "l1" }, "r17" },
  5045. { { "l2" }, "r18" },
  5046. { { "l3" }, "r19" },
  5047. { { "l4" }, "r20" },
  5048. { { "l5" }, "r21" },
  5049. { { "l6" }, "r22" },
  5050. { { "l7" }, "r23" },
  5051. { { "i0" }, "r24" },
  5052. { { "i1" }, "r25" },
  5053. { { "i2" }, "r26" },
  5054. { { "i3" }, "r27" },
  5055. { { "i4" }, "r28" },
  5056. { { "i5" }, "r29" },
  5057. { { "i6", "fp" }, "r30" },
  5058. { { "i7" }, "r31" },
  5059. };
  5060. void SparcTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
  5061. unsigned &NumAliases) const {
  5062. Aliases = GCCRegAliases;
  5063. NumAliases = llvm::array_lengthof(GCCRegAliases);
  5064. }
  5065. // SPARC v8 is the 32-bit mode selected by Triple::sparc.
  5066. class SparcV8TargetInfo : public SparcTargetInfo {
  5067. public:
  5068. SparcV8TargetInfo(const llvm::Triple &Triple) : SparcTargetInfo(Triple) {
  5069. DescriptionString = "E-m:e-p:32:32-i64:64-f128:64-n32-S64";
  5070. // NetBSD uses long (same as llvm default); everyone else uses int.
  5071. if (getTriple().getOS() == llvm::Triple::NetBSD) {
  5072. SizeType = UnsignedLong;
  5073. IntPtrType = SignedLong;
  5074. PtrDiffType = SignedLong;
  5075. } else {
  5076. SizeType = UnsignedInt;
  5077. IntPtrType = SignedInt;
  5078. PtrDiffType = SignedInt;
  5079. }
  5080. }
  5081. void getTargetDefines(const LangOptions &Opts,
  5082. MacroBuilder &Builder) const override {
  5083. SparcTargetInfo::getTargetDefines(Opts, Builder);
  5084. Builder.defineMacro("__sparcv8");
  5085. }
  5086. };
  5087. // SPARCV8el is the 32-bit little-endian mode selected by Triple::sparcel.
  5088. class SparcV8elTargetInfo : public SparcV8TargetInfo {
  5089. public:
  5090. SparcV8elTargetInfo(const llvm::Triple &Triple) : SparcV8TargetInfo(Triple) {
  5091. DescriptionString = "e-m:e-p:32:32-i64:64-f128:64-n32-S64";
  5092. BigEndian = false;
  5093. }
  5094. };
  5095. // SPARC v9 is the 64-bit mode selected by Triple::sparcv9.
  5096. class SparcV9TargetInfo : public SparcTargetInfo {
  5097. public:
  5098. SparcV9TargetInfo(const llvm::Triple &Triple) : SparcTargetInfo(Triple) {
  5099. // FIXME: Support Sparc quad-precision long double?
  5100. DescriptionString = "E-m:e-i64:64-n32:64-S128";
  5101. // This is an LP64 platform.
  5102. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  5103. // OpenBSD uses long long for int64_t and intmax_t.
  5104. if (getTriple().getOS() == llvm::Triple::OpenBSD)
  5105. IntMaxType = SignedLongLong;
  5106. else
  5107. IntMaxType = SignedLong;
  5108. Int64Type = IntMaxType;
  5109. // The SPARCv8 System V ABI has long double 128-bits in size, but 64-bit
  5110. // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
  5111. LongDoubleWidth = 128;
  5112. LongDoubleAlign = 128;
  5113. LongDoubleFormat = &llvm::APFloat::IEEEquad;
  5114. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  5115. }
  5116. void getTargetDefines(const LangOptions &Opts,
  5117. MacroBuilder &Builder) const override {
  5118. SparcTargetInfo::getTargetDefines(Opts, Builder);
  5119. Builder.defineMacro("__sparcv9");
  5120. Builder.defineMacro("__arch64__");
  5121. // Solaris doesn't need these variants, but the BSDs do.
  5122. if (getTriple().getOS() != llvm::Triple::Solaris) {
  5123. Builder.defineMacro("__sparc64__");
  5124. Builder.defineMacro("__sparc_v9__");
  5125. Builder.defineMacro("__sparcv9__");
  5126. }
  5127. }
  5128. bool setCPU(const std::string &Name) override {
  5129. bool CPUKnown = llvm::StringSwitch<bool>(Name)
  5130. .Case("v9", true)
  5131. .Case("ultrasparc", true)
  5132. .Case("ultrasparc3", true)
  5133. .Case("niagara", true)
  5134. .Case("niagara2", true)
  5135. .Case("niagara3", true)
  5136. .Case("niagara4", true)
  5137. .Default(false);
  5138. // No need to store the CPU yet. There aren't any CPU-specific
  5139. // macros to define.
  5140. return CPUKnown;
  5141. }
  5142. };
  5143. class SystemZTargetInfo : public TargetInfo {
  5144. static const Builtin::Info BuiltinInfo[];
  5145. static const char *const GCCRegNames[];
  5146. std::string CPU;
  5147. bool HasTransactionalExecution;
  5148. bool HasVector;
  5149. public:
  5150. SystemZTargetInfo(const llvm::Triple &Triple)
  5151. : TargetInfo(Triple), CPU("z10"), HasTransactionalExecution(false), HasVector(false) {
  5152. IntMaxType = SignedLong;
  5153. Int64Type = SignedLong;
  5154. TLSSupported = true;
  5155. IntWidth = IntAlign = 32;
  5156. LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
  5157. PointerWidth = PointerAlign = 64;
  5158. LongDoubleWidth = 128;
  5159. LongDoubleAlign = 64;
  5160. LongDoubleFormat = &llvm::APFloat::IEEEquad;
  5161. DefaultAlignForAttributeAligned = 64;
  5162. MinGlobalAlign = 16;
  5163. DescriptionString = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64";
  5164. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  5165. }
  5166. void getTargetDefines(const LangOptions &Opts,
  5167. MacroBuilder &Builder) const override {
  5168. Builder.defineMacro("__s390__");
  5169. Builder.defineMacro("__s390x__");
  5170. Builder.defineMacro("__zarch__");
  5171. Builder.defineMacro("__LONG_DOUBLE_128__");
  5172. if (HasTransactionalExecution)
  5173. Builder.defineMacro("__HTM__");
  5174. if (Opts.ZVector)
  5175. Builder.defineMacro("__VEC__", "10301");
  5176. }
  5177. void getTargetBuiltins(const Builtin::Info *&Records,
  5178. unsigned &NumRecords) const override {
  5179. Records = BuiltinInfo;
  5180. NumRecords = clang::SystemZ::LastTSBuiltin-Builtin::FirstTSBuiltin;
  5181. }
  5182. void getGCCRegNames(const char *const *&Names,
  5183. unsigned &NumNames) const override;
  5184. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  5185. unsigned &NumAliases) const override {
  5186. // No aliases.
  5187. Aliases = nullptr;
  5188. NumAliases = 0;
  5189. }
  5190. bool validateAsmConstraint(const char *&Name,
  5191. TargetInfo::ConstraintInfo &info) const override;
  5192. const char *getClobbers() const override {
  5193. // FIXME: Is this really right?
  5194. return "";
  5195. }
  5196. BuiltinVaListKind getBuiltinVaListKind() const override {
  5197. return TargetInfo::SystemZBuiltinVaList;
  5198. }
  5199. bool setCPU(const std::string &Name) override {
  5200. CPU = Name;
  5201. bool CPUKnown = llvm::StringSwitch<bool>(Name)
  5202. .Case("z10", true)
  5203. .Case("z196", true)
  5204. .Case("zEC12", true)
  5205. .Case("z13", true)
  5206. .Default(false);
  5207. return CPUKnown;
  5208. }
  5209. void getDefaultFeatures(llvm::StringMap<bool> &Features) const override {
  5210. if (CPU == "zEC12")
  5211. Features["transactional-execution"] = true;
  5212. if (CPU == "z13") {
  5213. Features["transactional-execution"] = true;
  5214. Features["vector"] = true;
  5215. }
  5216. }
  5217. bool handleTargetFeatures(std::vector<std::string> &Features,
  5218. DiagnosticsEngine &Diags) override {
  5219. HasTransactionalExecution = false;
  5220. for (unsigned i = 0, e = Features.size(); i != e; ++i) {
  5221. if (Features[i] == "+transactional-execution")
  5222. HasTransactionalExecution = true;
  5223. if (Features[i] == "+vector")
  5224. HasVector = true;
  5225. }
  5226. // If we use the vector ABI, vector types are 64-bit aligned.
  5227. if (HasVector) {
  5228. MaxVectorAlign = 64;
  5229. DescriptionString = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
  5230. "-v128:64-a:8:16-n32:64";
  5231. }
  5232. return true;
  5233. }
  5234. bool hasFeature(StringRef Feature) const override {
  5235. return llvm::StringSwitch<bool>(Feature)
  5236. .Case("systemz", true)
  5237. .Case("htm", HasTransactionalExecution)
  5238. .Case("vx", HasVector)
  5239. .Default(false);
  5240. }
  5241. StringRef getABI() const override {
  5242. if (HasVector)
  5243. return "vector";
  5244. return "";
  5245. }
  5246. bool useFloat128ManglingForLongDouble() const override {
  5247. return true;
  5248. }
  5249. };
  5250. const Builtin::Info SystemZTargetInfo::BuiltinInfo[] = {
  5251. #define BUILTIN(ID, TYPE, ATTRS) \
  5252. { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  5253. #include "clang/Basic/BuiltinsSystemZ.def"
  5254. };
  5255. const char *const SystemZTargetInfo::GCCRegNames[] = {
  5256. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  5257. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  5258. "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
  5259. "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15"
  5260. };
  5261. void SystemZTargetInfo::getGCCRegNames(const char *const *&Names,
  5262. unsigned &NumNames) const {
  5263. Names = GCCRegNames;
  5264. NumNames = llvm::array_lengthof(GCCRegNames);
  5265. }
  5266. bool SystemZTargetInfo::
  5267. validateAsmConstraint(const char *&Name,
  5268. TargetInfo::ConstraintInfo &Info) const {
  5269. switch (*Name) {
  5270. default:
  5271. return false;
  5272. case 'a': // Address register
  5273. case 'd': // Data register (equivalent to 'r')
  5274. case 'f': // Floating-point register
  5275. Info.setAllowsRegister();
  5276. return true;
  5277. case 'I': // Unsigned 8-bit constant
  5278. case 'J': // Unsigned 12-bit constant
  5279. case 'K': // Signed 16-bit constant
  5280. case 'L': // Signed 20-bit displacement (on all targets we support)
  5281. case 'M': // 0x7fffffff
  5282. return true;
  5283. case 'Q': // Memory with base and unsigned 12-bit displacement
  5284. case 'R': // Likewise, plus an index
  5285. case 'S': // Memory with base and signed 20-bit displacement
  5286. case 'T': // Likewise, plus an index
  5287. Info.setAllowsMemory();
  5288. return true;
  5289. }
  5290. }
  5291. class MSP430TargetInfo : public TargetInfo {
  5292. static const char * const GCCRegNames[];
  5293. public:
  5294. MSP430TargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  5295. BigEndian = false;
  5296. TLSSupported = false;
  5297. IntWidth = 16; IntAlign = 16;
  5298. LongWidth = 32; LongLongWidth = 64;
  5299. LongAlign = LongLongAlign = 16;
  5300. PointerWidth = 16; PointerAlign = 16;
  5301. SuitableAlign = 16;
  5302. SizeType = UnsignedInt;
  5303. IntMaxType = SignedLongLong;
  5304. IntPtrType = SignedInt;
  5305. PtrDiffType = SignedInt;
  5306. SigAtomicType = SignedLong;
  5307. DescriptionString = "e-m:e-p:16:16-i32:16:32-a:16-n8:16";
  5308. }
  5309. void getTargetDefines(const LangOptions &Opts,
  5310. MacroBuilder &Builder) const override {
  5311. Builder.defineMacro("MSP430");
  5312. Builder.defineMacro("__MSP430__");
  5313. // FIXME: defines for different 'flavours' of MCU
  5314. }
  5315. void getTargetBuiltins(const Builtin::Info *&Records,
  5316. unsigned &NumRecords) const override {
  5317. // FIXME: Implement.
  5318. Records = nullptr;
  5319. NumRecords = 0;
  5320. }
  5321. bool hasFeature(StringRef Feature) const override {
  5322. return Feature == "msp430";
  5323. }
  5324. void getGCCRegNames(const char * const *&Names,
  5325. unsigned &NumNames) const override;
  5326. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  5327. unsigned &NumAliases) const override {
  5328. // No aliases.
  5329. Aliases = nullptr;
  5330. NumAliases = 0;
  5331. }
  5332. bool
  5333. validateAsmConstraint(const char *&Name,
  5334. TargetInfo::ConstraintInfo &info) const override {
  5335. // FIXME: implement
  5336. switch (*Name) {
  5337. case 'K': // the constant 1
  5338. case 'L': // constant -1^20 .. 1^19
  5339. case 'M': // constant 1-4:
  5340. return true;
  5341. }
  5342. // No target constraints for now.
  5343. return false;
  5344. }
  5345. const char *getClobbers() const override {
  5346. // FIXME: Is this really right?
  5347. return "";
  5348. }
  5349. BuiltinVaListKind getBuiltinVaListKind() const override {
  5350. // FIXME: implement
  5351. return TargetInfo::CharPtrBuiltinVaList;
  5352. }
  5353. };
  5354. const char * const MSP430TargetInfo::GCCRegNames[] = {
  5355. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  5356. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
  5357. };
  5358. void MSP430TargetInfo::getGCCRegNames(const char * const *&Names,
  5359. unsigned &NumNames) const {
  5360. Names = GCCRegNames;
  5361. NumNames = llvm::array_lengthof(GCCRegNames);
  5362. }
  5363. // LLVM and Clang cannot be used directly to output native binaries for
  5364. // target, but is used to compile C code to llvm bitcode with correct
  5365. // type and alignment information.
  5366. //
  5367. // TCE uses the llvm bitcode as input and uses it for generating customized
  5368. // target processor and program binary. TCE co-design environment is
  5369. // publicly available in http://tce.cs.tut.fi
  5370. static const unsigned TCEOpenCLAddrSpaceMap[] = {
  5371. 3, // opencl_global
  5372. 4, // opencl_local
  5373. 5, // opencl_constant
  5374. // FIXME: generic has to be added to the target
  5375. 0, // opencl_generic
  5376. 0, // cuda_device
  5377. 0, // cuda_constant
  5378. 0 // cuda_shared
  5379. };
  5380. class TCETargetInfo : public TargetInfo{
  5381. public:
  5382. TCETargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  5383. TLSSupported = false;
  5384. IntWidth = 32;
  5385. LongWidth = LongLongWidth = 32;
  5386. PointerWidth = 32;
  5387. IntAlign = 32;
  5388. LongAlign = LongLongAlign = 32;
  5389. PointerAlign = 32;
  5390. SuitableAlign = 32;
  5391. SizeType = UnsignedInt;
  5392. IntMaxType = SignedLong;
  5393. IntPtrType = SignedInt;
  5394. PtrDiffType = SignedInt;
  5395. FloatWidth = 32;
  5396. FloatAlign = 32;
  5397. DoubleWidth = 32;
  5398. DoubleAlign = 32;
  5399. LongDoubleWidth = 32;
  5400. LongDoubleAlign = 32;
  5401. FloatFormat = &llvm::APFloat::IEEEsingle;
  5402. DoubleFormat = &llvm::APFloat::IEEEsingle;
  5403. LongDoubleFormat = &llvm::APFloat::IEEEsingle;
  5404. DescriptionString = "E-p:32:32-i8:8:32-i16:16:32-i64:32"
  5405. "-f64:32-v64:32-v128:32-a:0:32-n32";
  5406. AddrSpaceMap = &TCEOpenCLAddrSpaceMap;
  5407. UseAddrSpaceMapMangling = true;
  5408. }
  5409. void getTargetDefines(const LangOptions &Opts,
  5410. MacroBuilder &Builder) const override {
  5411. DefineStd(Builder, "tce", Opts);
  5412. Builder.defineMacro("__TCE__");
  5413. Builder.defineMacro("__TCE_V1__");
  5414. }
  5415. bool hasFeature(StringRef Feature) const override {
  5416. return Feature == "tce";
  5417. }
  5418. void getTargetBuiltins(const Builtin::Info *&Records,
  5419. unsigned &NumRecords) const override {}
  5420. const char *getClobbers() const override {
  5421. return "";
  5422. }
  5423. BuiltinVaListKind getBuiltinVaListKind() const override {
  5424. return TargetInfo::VoidPtrBuiltinVaList;
  5425. }
  5426. void getGCCRegNames(const char * const *&Names,
  5427. unsigned &NumNames) const override {}
  5428. bool validateAsmConstraint(const char *&Name,
  5429. TargetInfo::ConstraintInfo &info) const override{
  5430. return true;
  5431. }
  5432. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  5433. unsigned &NumAliases) const override {}
  5434. };
  5435. class BPFTargetInfo : public TargetInfo {
  5436. public:
  5437. BPFTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  5438. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  5439. SizeType = UnsignedLong;
  5440. PtrDiffType = SignedLong;
  5441. IntPtrType = SignedLong;
  5442. IntMaxType = SignedLong;
  5443. Int64Type = SignedLong;
  5444. RegParmMax = 5;
  5445. if (Triple.getArch() == llvm::Triple::bpfeb) {
  5446. BigEndian = true;
  5447. DescriptionString = "E-m:e-p:64:64-i64:64-n32:64-S128";
  5448. } else {
  5449. BigEndian = false;
  5450. DescriptionString = "e-m:e-p:64:64-i64:64-n32:64-S128";
  5451. }
  5452. MaxAtomicPromoteWidth = 64;
  5453. MaxAtomicInlineWidth = 64;
  5454. TLSSupported = false;
  5455. }
  5456. void getTargetDefines(const LangOptions &Opts,
  5457. MacroBuilder &Builder) const override {
  5458. DefineStd(Builder, "bpf", Opts);
  5459. Builder.defineMacro("__BPF__");
  5460. }
  5461. bool hasFeature(StringRef Feature) const override {
  5462. return Feature == "bpf";
  5463. }
  5464. void getTargetBuiltins(const Builtin::Info *&Records,
  5465. unsigned &NumRecords) const override {}
  5466. const char *getClobbers() const override {
  5467. return "";
  5468. }
  5469. BuiltinVaListKind getBuiltinVaListKind() const override {
  5470. return TargetInfo::VoidPtrBuiltinVaList;
  5471. }
  5472. void getGCCRegNames(const char * const *&Names,
  5473. unsigned &NumNames) const override {
  5474. Names = nullptr;
  5475. NumNames = 0;
  5476. }
  5477. bool validateAsmConstraint(const char *&Name,
  5478. TargetInfo::ConstraintInfo &info) const override {
  5479. return true;
  5480. }
  5481. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  5482. unsigned &NumAliases) const override {
  5483. Aliases = nullptr;
  5484. NumAliases = 0;
  5485. }
  5486. };
  5487. class MipsTargetInfoBase : public TargetInfo {
  5488. virtual void setDescriptionString() = 0;
  5489. static const Builtin::Info BuiltinInfo[];
  5490. std::string CPU;
  5491. bool IsMips16;
  5492. bool IsMicromips;
  5493. bool IsNan2008;
  5494. bool IsSingleFloat;
  5495. enum MipsFloatABI {
  5496. HardFloat, SoftFloat
  5497. } FloatABI;
  5498. enum DspRevEnum {
  5499. NoDSP, DSP1, DSP2
  5500. } DspRev;
  5501. bool HasMSA;
  5502. protected:
  5503. bool HasFP64;
  5504. std::string ABI;
  5505. public:
  5506. MipsTargetInfoBase(const llvm::Triple &Triple, const std::string &ABIStr,
  5507. const std::string &CPUStr)
  5508. : TargetInfo(Triple), CPU(CPUStr), IsMips16(false), IsMicromips(false),
  5509. IsNan2008(false), IsSingleFloat(false), FloatABI(HardFloat),
  5510. DspRev(NoDSP), HasMSA(false), HasFP64(false), ABI(ABIStr) {
  5511. TheCXXABI.set(TargetCXXABI::GenericMIPS);
  5512. }
  5513. bool isNaN2008Default() const {
  5514. return CPU == "mips32r6" || CPU == "mips64r6";
  5515. }
  5516. bool isFP64Default() const {
  5517. return CPU == "mips32r6" || ABI == "n32" || ABI == "n64" || ABI == "64";
  5518. }
  5519. bool isNan2008() const override {
  5520. return IsNan2008;
  5521. }
  5522. StringRef getABI() const override { return ABI; }
  5523. bool setCPU(const std::string &Name) override {
  5524. bool IsMips32 = getTriple().getArch() == llvm::Triple::mips ||
  5525. getTriple().getArch() == llvm::Triple::mipsel;
  5526. CPU = Name;
  5527. return llvm::StringSwitch<bool>(Name)
  5528. .Case("mips1", IsMips32)
  5529. .Case("mips2", IsMips32)
  5530. .Case("mips3", true)
  5531. .Case("mips4", true)
  5532. .Case("mips5", true)
  5533. .Case("mips32", IsMips32)
  5534. .Case("mips32r2", IsMips32)
  5535. .Case("mips32r3", IsMips32)
  5536. .Case("mips32r5", IsMips32)
  5537. .Case("mips32r6", IsMips32)
  5538. .Case("mips64", true)
  5539. .Case("mips64r2", true)
  5540. .Case("mips64r3", true)
  5541. .Case("mips64r5", true)
  5542. .Case("mips64r6", true)
  5543. .Case("octeon", true)
  5544. .Default(false);
  5545. }
  5546. const std::string& getCPU() const { return CPU; }
  5547. void getDefaultFeatures(llvm::StringMap<bool> &Features) const override {
  5548. if (CPU == "octeon")
  5549. Features["mips64r2"] = Features["cnmips"] = true;
  5550. else
  5551. Features[CPU] = true;
  5552. }
  5553. void getTargetDefines(const LangOptions &Opts,
  5554. MacroBuilder &Builder) const override {
  5555. Builder.defineMacro("__mips__");
  5556. Builder.defineMacro("_mips");
  5557. if (Opts.GNUMode)
  5558. Builder.defineMacro("mips");
  5559. Builder.defineMacro("__REGISTER_PREFIX__", "");
  5560. switch (FloatABI) {
  5561. case HardFloat:
  5562. Builder.defineMacro("__mips_hard_float", Twine(1));
  5563. break;
  5564. case SoftFloat:
  5565. Builder.defineMacro("__mips_soft_float", Twine(1));
  5566. break;
  5567. }
  5568. if (IsSingleFloat)
  5569. Builder.defineMacro("__mips_single_float", Twine(1));
  5570. Builder.defineMacro("__mips_fpr", HasFP64 ? Twine(64) : Twine(32));
  5571. Builder.defineMacro("_MIPS_FPSET",
  5572. Twine(32 / (HasFP64 || IsSingleFloat ? 1 : 2)));
  5573. if (IsMips16)
  5574. Builder.defineMacro("__mips16", Twine(1));
  5575. if (IsMicromips)
  5576. Builder.defineMacro("__mips_micromips", Twine(1));
  5577. if (IsNan2008)
  5578. Builder.defineMacro("__mips_nan2008", Twine(1));
  5579. switch (DspRev) {
  5580. default:
  5581. break;
  5582. case DSP1:
  5583. Builder.defineMacro("__mips_dsp_rev", Twine(1));
  5584. Builder.defineMacro("__mips_dsp", Twine(1));
  5585. break;
  5586. case DSP2:
  5587. Builder.defineMacro("__mips_dsp_rev", Twine(2));
  5588. Builder.defineMacro("__mips_dspr2", Twine(1));
  5589. Builder.defineMacro("__mips_dsp", Twine(1));
  5590. break;
  5591. }
  5592. if (HasMSA)
  5593. Builder.defineMacro("__mips_msa", Twine(1));
  5594. Builder.defineMacro("_MIPS_SZPTR", Twine(getPointerWidth(0)));
  5595. Builder.defineMacro("_MIPS_SZINT", Twine(getIntWidth()));
  5596. Builder.defineMacro("_MIPS_SZLONG", Twine(getLongWidth()));
  5597. Builder.defineMacro("_MIPS_ARCH", "\"" + CPU + "\"");
  5598. Builder.defineMacro("_MIPS_ARCH_" + StringRef(CPU).upper());
  5599. }
  5600. void getTargetBuiltins(const Builtin::Info *&Records,
  5601. unsigned &NumRecords) const override {
  5602. Records = BuiltinInfo;
  5603. NumRecords = clang::Mips::LastTSBuiltin - Builtin::FirstTSBuiltin;
  5604. }
  5605. bool hasFeature(StringRef Feature) const override {
  5606. return llvm::StringSwitch<bool>(Feature)
  5607. .Case("mips", true)
  5608. .Case("fp64", HasFP64)
  5609. .Default(false);
  5610. }
  5611. BuiltinVaListKind getBuiltinVaListKind() const override {
  5612. return TargetInfo::VoidPtrBuiltinVaList;
  5613. }
  5614. void getGCCRegNames(const char * const *&Names,
  5615. unsigned &NumNames) const override {
  5616. static const char *const GCCRegNames[] = {
  5617. // CPU register names
  5618. // Must match second column of GCCRegAliases
  5619. "$0", "$1", "$2", "$3", "$4", "$5", "$6", "$7",
  5620. "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15",
  5621. "$16", "$17", "$18", "$19", "$20", "$21", "$22", "$23",
  5622. "$24", "$25", "$26", "$27", "$28", "$29", "$30", "$31",
  5623. // Floating point register names
  5624. "$f0", "$f1", "$f2", "$f3", "$f4", "$f5", "$f6", "$f7",
  5625. "$f8", "$f9", "$f10", "$f11", "$f12", "$f13", "$f14", "$f15",
  5626. "$f16", "$f17", "$f18", "$f19", "$f20", "$f21", "$f22", "$f23",
  5627. "$f24", "$f25", "$f26", "$f27", "$f28", "$f29", "$f30", "$f31",
  5628. // Hi/lo and condition register names
  5629. "hi", "lo", "", "$fcc0","$fcc1","$fcc2","$fcc3","$fcc4",
  5630. "$fcc5","$fcc6","$fcc7",
  5631. // MSA register names
  5632. "$w0", "$w1", "$w2", "$w3", "$w4", "$w5", "$w6", "$w7",
  5633. "$w8", "$w9", "$w10", "$w11", "$w12", "$w13", "$w14", "$w15",
  5634. "$w16", "$w17", "$w18", "$w19", "$w20", "$w21", "$w22", "$w23",
  5635. "$w24", "$w25", "$w26", "$w27", "$w28", "$w29", "$w30", "$w31",
  5636. // MSA control register names
  5637. "$msair", "$msacsr", "$msaaccess", "$msasave", "$msamodify",
  5638. "$msarequest", "$msamap", "$msaunmap"
  5639. };
  5640. Names = GCCRegNames;
  5641. NumNames = llvm::array_lengthof(GCCRegNames);
  5642. }
  5643. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  5644. unsigned &NumAliases) const override = 0;
  5645. bool validateAsmConstraint(const char *&Name,
  5646. TargetInfo::ConstraintInfo &Info) const override {
  5647. switch (*Name) {
  5648. default:
  5649. return false;
  5650. case 'r': // CPU registers.
  5651. case 'd': // Equivalent to "r" unless generating MIPS16 code.
  5652. case 'y': // Equivalent to "r", backward compatibility only.
  5653. case 'f': // floating-point registers.
  5654. case 'c': // $25 for indirect jumps
  5655. case 'l': // lo register
  5656. case 'x': // hilo register pair
  5657. Info.setAllowsRegister();
  5658. return true;
  5659. case 'I': // Signed 16-bit constant
  5660. case 'J': // Integer 0
  5661. case 'K': // Unsigned 16-bit constant
  5662. case 'L': // Signed 32-bit constant, lower 16-bit zeros (for lui)
  5663. case 'M': // Constants not loadable via lui, addiu, or ori
  5664. case 'N': // Constant -1 to -65535
  5665. case 'O': // A signed 15-bit constant
  5666. case 'P': // A constant between 1 go 65535
  5667. return true;
  5668. case 'R': // An address that can be used in a non-macro load or store
  5669. Info.setAllowsMemory();
  5670. return true;
  5671. case 'Z':
  5672. if (Name[1] == 'C') { // An address usable by ll, and sc.
  5673. Info.setAllowsMemory();
  5674. Name++; // Skip over 'Z'.
  5675. return true;
  5676. }
  5677. return false;
  5678. }
  5679. }
  5680. std::string convertConstraint(const char *&Constraint) const override {
  5681. std::string R;
  5682. switch (*Constraint) {
  5683. case 'Z': // Two-character constraint; add "^" hint for later parsing.
  5684. if (Constraint[1] == 'C') {
  5685. R = std::string("^") + std::string(Constraint, 2);
  5686. Constraint++;
  5687. return R;
  5688. }
  5689. break;
  5690. }
  5691. return TargetInfo::convertConstraint(Constraint);
  5692. }
  5693. const char *getClobbers() const override {
  5694. // In GCC, $1 is not widely used in generated code (it's used only in a few
  5695. // specific situations), so there is no real need for users to add it to
  5696. // the clobbers list if they want to use it in their inline assembly code.
  5697. //
  5698. // In LLVM, $1 is treated as a normal GPR and is always allocatable during
  5699. // code generation, so using it in inline assembly without adding it to the
  5700. // clobbers list can cause conflicts between the inline assembly code and
  5701. // the surrounding generated code.
  5702. //
  5703. // Another problem is that LLVM is allowed to choose $1 for inline assembly
  5704. // operands, which will conflict with the ".set at" assembler option (which
  5705. // we use only for inline assembly, in order to maintain compatibility with
  5706. // GCC) and will also conflict with the user's usage of $1.
  5707. //
  5708. // The easiest way to avoid these conflicts and keep $1 as an allocatable
  5709. // register for generated code is to automatically clobber $1 for all inline
  5710. // assembly code.
  5711. //
  5712. // FIXME: We should automatically clobber $1 only for inline assembly code
  5713. // which actually uses it. This would allow LLVM to use $1 for inline
  5714. // assembly operands if the user's assembly code doesn't use it.
  5715. return "~{$1}";
  5716. }
  5717. bool handleTargetFeatures(std::vector<std::string> &Features,
  5718. DiagnosticsEngine &Diags) override {
  5719. IsMips16 = false;
  5720. IsMicromips = false;
  5721. IsNan2008 = isNaN2008Default();
  5722. IsSingleFloat = false;
  5723. FloatABI = HardFloat;
  5724. DspRev = NoDSP;
  5725. HasFP64 = isFP64Default();
  5726. for (std::vector<std::string>::iterator it = Features.begin(),
  5727. ie = Features.end(); it != ie; ++it) {
  5728. if (*it == "+single-float")
  5729. IsSingleFloat = true;
  5730. else if (*it == "+soft-float")
  5731. FloatABI = SoftFloat;
  5732. else if (*it == "+mips16")
  5733. IsMips16 = true;
  5734. else if (*it == "+micromips")
  5735. IsMicromips = true;
  5736. else if (*it == "+dsp")
  5737. DspRev = std::max(DspRev, DSP1);
  5738. else if (*it == "+dspr2")
  5739. DspRev = std::max(DspRev, DSP2);
  5740. else if (*it == "+msa")
  5741. HasMSA = true;
  5742. else if (*it == "+fp64")
  5743. HasFP64 = true;
  5744. else if (*it == "-fp64")
  5745. HasFP64 = false;
  5746. else if (*it == "+nan2008")
  5747. IsNan2008 = true;
  5748. else if (*it == "-nan2008")
  5749. IsNan2008 = false;
  5750. }
  5751. setDescriptionString();
  5752. return true;
  5753. }
  5754. int getEHDataRegisterNumber(unsigned RegNo) const override {
  5755. if (RegNo == 0) return 4;
  5756. if (RegNo == 1) return 5;
  5757. return -1;
  5758. }
  5759. bool isCLZForZeroUndef() const override { return false; }
  5760. };
  5761. const Builtin::Info MipsTargetInfoBase::BuiltinInfo[] = {
  5762. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  5763. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  5764. ALL_LANGUAGES },
  5765. #include "clang/Basic/BuiltinsMips.def"
  5766. };
  5767. class Mips32TargetInfoBase : public MipsTargetInfoBase {
  5768. public:
  5769. Mips32TargetInfoBase(const llvm::Triple &Triple)
  5770. : MipsTargetInfoBase(Triple, "o32", "mips32r2") {
  5771. SizeType = UnsignedInt;
  5772. PtrDiffType = SignedInt;
  5773. Int64Type = SignedLongLong;
  5774. IntMaxType = Int64Type;
  5775. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
  5776. }
  5777. bool setABI(const std::string &Name) override {
  5778. if (Name == "o32" || Name == "eabi") {
  5779. ABI = Name;
  5780. return true;
  5781. }
  5782. return false;
  5783. }
  5784. void getTargetDefines(const LangOptions &Opts,
  5785. MacroBuilder &Builder) const override {
  5786. MipsTargetInfoBase::getTargetDefines(Opts, Builder);
  5787. Builder.defineMacro("__mips", "32");
  5788. Builder.defineMacro("_MIPS_ISA", "_MIPS_ISA_MIPS32");
  5789. const std::string& CPUStr = getCPU();
  5790. if (CPUStr == "mips32")
  5791. Builder.defineMacro("__mips_isa_rev", "1");
  5792. else if (CPUStr == "mips32r2")
  5793. Builder.defineMacro("__mips_isa_rev", "2");
  5794. else if (CPUStr == "mips32r3")
  5795. Builder.defineMacro("__mips_isa_rev", "3");
  5796. else if (CPUStr == "mips32r5")
  5797. Builder.defineMacro("__mips_isa_rev", "5");
  5798. else if (CPUStr == "mips32r6")
  5799. Builder.defineMacro("__mips_isa_rev", "6");
  5800. if (ABI == "o32") {
  5801. Builder.defineMacro("__mips_o32");
  5802. Builder.defineMacro("_ABIO32", "1");
  5803. Builder.defineMacro("_MIPS_SIM", "_ABIO32");
  5804. }
  5805. else if (ABI == "eabi")
  5806. Builder.defineMacro("__mips_eabi");
  5807. else
  5808. llvm_unreachable("Invalid ABI for Mips32.");
  5809. }
  5810. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  5811. unsigned &NumAliases) const override {
  5812. static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
  5813. { { "at" }, "$1" },
  5814. { { "v0" }, "$2" },
  5815. { { "v1" }, "$3" },
  5816. { { "a0" }, "$4" },
  5817. { { "a1" }, "$5" },
  5818. { { "a2" }, "$6" },
  5819. { { "a3" }, "$7" },
  5820. { { "t0" }, "$8" },
  5821. { { "t1" }, "$9" },
  5822. { { "t2" }, "$10" },
  5823. { { "t3" }, "$11" },
  5824. { { "t4" }, "$12" },
  5825. { { "t5" }, "$13" },
  5826. { { "t6" }, "$14" },
  5827. { { "t7" }, "$15" },
  5828. { { "s0" }, "$16" },
  5829. { { "s1" }, "$17" },
  5830. { { "s2" }, "$18" },
  5831. { { "s3" }, "$19" },
  5832. { { "s4" }, "$20" },
  5833. { { "s5" }, "$21" },
  5834. { { "s6" }, "$22" },
  5835. { { "s7" }, "$23" },
  5836. { { "t8" }, "$24" },
  5837. { { "t9" }, "$25" },
  5838. { { "k0" }, "$26" },
  5839. { { "k1" }, "$27" },
  5840. { { "gp" }, "$28" },
  5841. { { "sp","$sp" }, "$29" },
  5842. { { "fp","$fp" }, "$30" },
  5843. { { "ra" }, "$31" }
  5844. };
  5845. Aliases = GCCRegAliases;
  5846. NumAliases = llvm::array_lengthof(GCCRegAliases);
  5847. }
  5848. };
  5849. class Mips32EBTargetInfo : public Mips32TargetInfoBase {
  5850. void setDescriptionString() override {
  5851. DescriptionString = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64";
  5852. }
  5853. public:
  5854. Mips32EBTargetInfo(const llvm::Triple &Triple)
  5855. : Mips32TargetInfoBase(Triple) {
  5856. }
  5857. void getTargetDefines(const LangOptions &Opts,
  5858. MacroBuilder &Builder) const override {
  5859. DefineStd(Builder, "MIPSEB", Opts);
  5860. Builder.defineMacro("_MIPSEB");
  5861. Mips32TargetInfoBase::getTargetDefines(Opts, Builder);
  5862. }
  5863. };
  5864. class Mips32ELTargetInfo : public Mips32TargetInfoBase {
  5865. void setDescriptionString() override {
  5866. DescriptionString = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64";
  5867. }
  5868. public:
  5869. Mips32ELTargetInfo(const llvm::Triple &Triple)
  5870. : Mips32TargetInfoBase(Triple) {
  5871. BigEndian = false;
  5872. }
  5873. void getTargetDefines(const LangOptions &Opts,
  5874. MacroBuilder &Builder) const override {
  5875. DefineStd(Builder, "MIPSEL", Opts);
  5876. Builder.defineMacro("_MIPSEL");
  5877. Mips32TargetInfoBase::getTargetDefines(Opts, Builder);
  5878. }
  5879. };
  5880. class Mips64TargetInfoBase : public MipsTargetInfoBase {
  5881. public:
  5882. Mips64TargetInfoBase(const llvm::Triple &Triple)
  5883. : MipsTargetInfoBase(Triple, "n64", "mips64r2") {
  5884. LongDoubleWidth = LongDoubleAlign = 128;
  5885. LongDoubleFormat = &llvm::APFloat::IEEEquad;
  5886. if (getTriple().getOS() == llvm::Triple::FreeBSD) {
  5887. LongDoubleWidth = LongDoubleAlign = 64;
  5888. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  5889. }
  5890. setN64ABITypes();
  5891. SuitableAlign = 128;
  5892. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  5893. }
  5894. void setN64ABITypes() {
  5895. LongWidth = LongAlign = 64;
  5896. PointerWidth = PointerAlign = 64;
  5897. SizeType = UnsignedLong;
  5898. PtrDiffType = SignedLong;
  5899. Int64Type = SignedLong;
  5900. IntMaxType = Int64Type;
  5901. }
  5902. void setN32ABITypes() {
  5903. LongWidth = LongAlign = 32;
  5904. PointerWidth = PointerAlign = 32;
  5905. SizeType = UnsignedInt;
  5906. PtrDiffType = SignedInt;
  5907. Int64Type = SignedLongLong;
  5908. IntMaxType = Int64Type;
  5909. }
  5910. bool setABI(const std::string &Name) override {
  5911. if (Name == "n32") {
  5912. setN32ABITypes();
  5913. ABI = Name;
  5914. return true;
  5915. }
  5916. if (Name == "n64") {
  5917. setN64ABITypes();
  5918. ABI = Name;
  5919. return true;
  5920. }
  5921. return false;
  5922. }
  5923. void getTargetDefines(const LangOptions &Opts,
  5924. MacroBuilder &Builder) const override {
  5925. MipsTargetInfoBase::getTargetDefines(Opts, Builder);
  5926. Builder.defineMacro("__mips", "64");
  5927. Builder.defineMacro("__mips64");
  5928. Builder.defineMacro("__mips64__");
  5929. Builder.defineMacro("_MIPS_ISA", "_MIPS_ISA_MIPS64");
  5930. const std::string& CPUStr = getCPU();
  5931. if (CPUStr == "mips64")
  5932. Builder.defineMacro("__mips_isa_rev", "1");
  5933. else if (CPUStr == "mips64r2")
  5934. Builder.defineMacro("__mips_isa_rev", "2");
  5935. else if (CPUStr == "mips64r3")
  5936. Builder.defineMacro("__mips_isa_rev", "3");
  5937. else if (CPUStr == "mips64r5")
  5938. Builder.defineMacro("__mips_isa_rev", "5");
  5939. else if (CPUStr == "mips64r6")
  5940. Builder.defineMacro("__mips_isa_rev", "6");
  5941. if (ABI == "n32") {
  5942. Builder.defineMacro("__mips_n32");
  5943. Builder.defineMacro("_ABIN32", "2");
  5944. Builder.defineMacro("_MIPS_SIM", "_ABIN32");
  5945. }
  5946. else if (ABI == "n64") {
  5947. Builder.defineMacro("__mips_n64");
  5948. Builder.defineMacro("_ABI64", "3");
  5949. Builder.defineMacro("_MIPS_SIM", "_ABI64");
  5950. }
  5951. else
  5952. llvm_unreachable("Invalid ABI for Mips64.");
  5953. }
  5954. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  5955. unsigned &NumAliases) const override {
  5956. static const TargetInfo::GCCRegAlias GCCRegAliases[] = {
  5957. { { "at" }, "$1" },
  5958. { { "v0" }, "$2" },
  5959. { { "v1" }, "$3" },
  5960. { { "a0" }, "$4" },
  5961. { { "a1" }, "$5" },
  5962. { { "a2" }, "$6" },
  5963. { { "a3" }, "$7" },
  5964. { { "a4" }, "$8" },
  5965. { { "a5" }, "$9" },
  5966. { { "a6" }, "$10" },
  5967. { { "a7" }, "$11" },
  5968. { { "t0" }, "$12" },
  5969. { { "t1" }, "$13" },
  5970. { { "t2" }, "$14" },
  5971. { { "t3" }, "$15" },
  5972. { { "s0" }, "$16" },
  5973. { { "s1" }, "$17" },
  5974. { { "s2" }, "$18" },
  5975. { { "s3" }, "$19" },
  5976. { { "s4" }, "$20" },
  5977. { { "s5" }, "$21" },
  5978. { { "s6" }, "$22" },
  5979. { { "s7" }, "$23" },
  5980. { { "t8" }, "$24" },
  5981. { { "t9" }, "$25" },
  5982. { { "k0" }, "$26" },
  5983. { { "k1" }, "$27" },
  5984. { { "gp" }, "$28" },
  5985. { { "sp","$sp" }, "$29" },
  5986. { { "fp","$fp" }, "$30" },
  5987. { { "ra" }, "$31" }
  5988. };
  5989. Aliases = GCCRegAliases;
  5990. NumAliases = llvm::array_lengthof(GCCRegAliases);
  5991. }
  5992. bool hasInt128Type() const override { return true; }
  5993. };
  5994. class Mips64EBTargetInfo : public Mips64TargetInfoBase {
  5995. void setDescriptionString() override {
  5996. if (ABI == "n32")
  5997. DescriptionString = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32:64-S128";
  5998. else
  5999. DescriptionString = "E-m:m-i8:8:32-i16:16:32-i64:64-n32:64-S128";
  6000. }
  6001. public:
  6002. Mips64EBTargetInfo(const llvm::Triple &Triple)
  6003. : Mips64TargetInfoBase(Triple) {}
  6004. void getTargetDefines(const LangOptions &Opts,
  6005. MacroBuilder &Builder) const override {
  6006. DefineStd(Builder, "MIPSEB", Opts);
  6007. Builder.defineMacro("_MIPSEB");
  6008. Mips64TargetInfoBase::getTargetDefines(Opts, Builder);
  6009. }
  6010. };
  6011. class Mips64ELTargetInfo : public Mips64TargetInfoBase {
  6012. void setDescriptionString() override {
  6013. if (ABI == "n32")
  6014. DescriptionString = "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32:64-S128";
  6015. else
  6016. DescriptionString = "e-m:m-i8:8:32-i16:16:32-i64:64-n32:64-S128";
  6017. }
  6018. public:
  6019. Mips64ELTargetInfo(const llvm::Triple &Triple)
  6020. : Mips64TargetInfoBase(Triple) {
  6021. // Default ABI is n64.
  6022. BigEndian = false;
  6023. }
  6024. void getTargetDefines(const LangOptions &Opts,
  6025. MacroBuilder &Builder) const override {
  6026. DefineStd(Builder, "MIPSEL", Opts);
  6027. Builder.defineMacro("_MIPSEL");
  6028. Mips64TargetInfoBase::getTargetDefines(Opts, Builder);
  6029. }
  6030. };
  6031. class PNaClTargetInfo : public TargetInfo {
  6032. public:
  6033. PNaClTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  6034. BigEndian = false;
  6035. this->UserLabelPrefix = "";
  6036. this->LongAlign = 32;
  6037. this->LongWidth = 32;
  6038. this->PointerAlign = 32;
  6039. this->PointerWidth = 32;
  6040. this->IntMaxType = TargetInfo::SignedLongLong;
  6041. this->Int64Type = TargetInfo::SignedLongLong;
  6042. this->DoubleAlign = 64;
  6043. this->LongDoubleWidth = 64;
  6044. this->LongDoubleAlign = 64;
  6045. this->SizeType = TargetInfo::UnsignedInt;
  6046. this->PtrDiffType = TargetInfo::SignedInt;
  6047. this->IntPtrType = TargetInfo::SignedInt;
  6048. this->RegParmMax = 0; // Disallow regparm
  6049. }
  6050. void getDefaultFeatures(llvm::StringMap<bool> &Features) const override {
  6051. }
  6052. void getArchDefines(const LangOptions &Opts, MacroBuilder &Builder) const {
  6053. Builder.defineMacro("__le32__");
  6054. Builder.defineMacro("__pnacl__");
  6055. }
  6056. void getTargetDefines(const LangOptions &Opts,
  6057. MacroBuilder &Builder) const override {
  6058. getArchDefines(Opts, Builder);
  6059. }
  6060. bool hasFeature(StringRef Feature) const override {
  6061. return Feature == "pnacl";
  6062. }
  6063. void getTargetBuiltins(const Builtin::Info *&Records,
  6064. unsigned &NumRecords) const override {
  6065. }
  6066. BuiltinVaListKind getBuiltinVaListKind() const override {
  6067. return TargetInfo::PNaClABIBuiltinVaList;
  6068. }
  6069. void getGCCRegNames(const char * const *&Names,
  6070. unsigned &NumNames) const override;
  6071. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  6072. unsigned &NumAliases) const override;
  6073. bool validateAsmConstraint(const char *&Name,
  6074. TargetInfo::ConstraintInfo &Info) const override {
  6075. return false;
  6076. }
  6077. const char *getClobbers() const override {
  6078. return "";
  6079. }
  6080. };
  6081. void PNaClTargetInfo::getGCCRegNames(const char * const *&Names,
  6082. unsigned &NumNames) const {
  6083. Names = nullptr;
  6084. NumNames = 0;
  6085. }
  6086. void PNaClTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
  6087. unsigned &NumAliases) const {
  6088. Aliases = nullptr;
  6089. NumAliases = 0;
  6090. }
  6091. // We attempt to use PNaCl (le32) frontend and Mips32EL backend.
  6092. class NaClMips32ELTargetInfo : public Mips32ELTargetInfo {
  6093. public:
  6094. NaClMips32ELTargetInfo(const llvm::Triple &Triple) :
  6095. Mips32ELTargetInfo(Triple) {
  6096. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 0;
  6097. }
  6098. BuiltinVaListKind getBuiltinVaListKind() const override {
  6099. return TargetInfo::PNaClABIBuiltinVaList;
  6100. }
  6101. };
  6102. class Le64TargetInfo : public TargetInfo {
  6103. static const Builtin::Info BuiltinInfo[];
  6104. public:
  6105. Le64TargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  6106. BigEndian = false;
  6107. NoAsmVariants = true;
  6108. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  6109. MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
  6110. DescriptionString =
  6111. "e-m:e-v128:32-v16:16-v32:32-v96:32-n8:16:32:64-S128";
  6112. }
  6113. void getTargetDefines(const LangOptions &Opts,
  6114. MacroBuilder &Builder) const override {
  6115. DefineStd(Builder, "unix", Opts);
  6116. defineCPUMacros(Builder, "le64", /*Tuning=*/false);
  6117. Builder.defineMacro("__ELF__");
  6118. }
  6119. void getTargetBuiltins(const Builtin::Info *&Records,
  6120. unsigned &NumRecords) const override {
  6121. Records = BuiltinInfo;
  6122. NumRecords = clang::Le64::LastTSBuiltin - Builtin::FirstTSBuiltin;
  6123. }
  6124. BuiltinVaListKind getBuiltinVaListKind() const override {
  6125. return TargetInfo::PNaClABIBuiltinVaList;
  6126. }
  6127. const char *getClobbers() const override { return ""; }
  6128. void getGCCRegNames(const char *const *&Names,
  6129. unsigned &NumNames) const override {
  6130. Names = nullptr;
  6131. NumNames = 0;
  6132. }
  6133. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  6134. unsigned &NumAliases) const override {
  6135. Aliases = nullptr;
  6136. NumAliases = 0;
  6137. }
  6138. bool validateAsmConstraint(const char *&Name,
  6139. TargetInfo::ConstraintInfo &Info) const override {
  6140. return false;
  6141. }
  6142. bool hasProtectedVisibility() const override { return false; }
  6143. };
  6144. } // end anonymous namespace.
  6145. const Builtin::Info Le64TargetInfo::BuiltinInfo[] = {
  6146. #define BUILTIN(ID, TYPE, ATTRS) \
  6147. { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  6148. #include "clang/Basic/BuiltinsLe64.def"
  6149. };
  6150. namespace {
  6151. static const unsigned SPIRAddrSpaceMap[] = {
  6152. 1, // opencl_global
  6153. 3, // opencl_local
  6154. 2, // opencl_constant
  6155. 4, // opencl_generic
  6156. 0, // cuda_device
  6157. 0, // cuda_constant
  6158. 0 // cuda_shared
  6159. };
  6160. class SPIRTargetInfo : public TargetInfo {
  6161. public:
  6162. SPIRTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  6163. assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
  6164. "SPIR target must use unknown OS");
  6165. assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
  6166. "SPIR target must use unknown environment type");
  6167. BigEndian = false;
  6168. TLSSupported = false;
  6169. LongWidth = LongAlign = 64;
  6170. AddrSpaceMap = &SPIRAddrSpaceMap;
  6171. UseAddrSpaceMapMangling = true;
  6172. // Define available target features
  6173. // These must be defined in sorted order!
  6174. NoAsmVariants = true;
  6175. }
  6176. void getTargetDefines(const LangOptions &Opts,
  6177. MacroBuilder &Builder) const override {
  6178. DefineStd(Builder, "SPIR", Opts);
  6179. }
  6180. bool hasFeature(StringRef Feature) const override {
  6181. return Feature == "spir";
  6182. }
  6183. void getTargetBuiltins(const Builtin::Info *&Records,
  6184. unsigned &NumRecords) const override {}
  6185. const char *getClobbers() const override {
  6186. return "";
  6187. }
  6188. void getGCCRegNames(const char * const *&Names,
  6189. unsigned &NumNames) const override {}
  6190. bool
  6191. validateAsmConstraint(const char *&Name,
  6192. TargetInfo::ConstraintInfo &info) const override {
  6193. return true;
  6194. }
  6195. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  6196. unsigned &NumAliases) const override {}
  6197. BuiltinVaListKind getBuiltinVaListKind() const override {
  6198. return TargetInfo::VoidPtrBuiltinVaList;
  6199. }
  6200. CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
  6201. return (CC == CC_SpirFunction ||
  6202. CC == CC_SpirKernel) ? CCCR_OK : CCCR_Warning;
  6203. }
  6204. CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
  6205. return CC_SpirFunction;
  6206. }
  6207. };
  6208. class SPIR32TargetInfo : public SPIRTargetInfo {
  6209. public:
  6210. SPIR32TargetInfo(const llvm::Triple &Triple) : SPIRTargetInfo(Triple) {
  6211. PointerWidth = PointerAlign = 32;
  6212. SizeType = TargetInfo::UnsignedInt;
  6213. PtrDiffType = IntPtrType = TargetInfo::SignedInt;
  6214. DescriptionString
  6215. = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
  6216. "v96:128-v192:256-v256:256-v512:512-v1024:1024";
  6217. }
  6218. void getTargetDefines(const LangOptions &Opts,
  6219. MacroBuilder &Builder) const override {
  6220. DefineStd(Builder, "SPIR32", Opts);
  6221. }
  6222. };
  6223. class SPIR64TargetInfo : public SPIRTargetInfo {
  6224. public:
  6225. SPIR64TargetInfo(const llvm::Triple &Triple) : SPIRTargetInfo(Triple) {
  6226. PointerWidth = PointerAlign = 64;
  6227. SizeType = TargetInfo::UnsignedLong;
  6228. PtrDiffType = IntPtrType = TargetInfo::SignedLong;
  6229. DescriptionString = "e-i64:64-v16:16-v24:32-v32:32-v48:64-"
  6230. "v96:128-v192:256-v256:256-v512:512-v1024:1024";
  6231. }
  6232. void getTargetDefines(const LangOptions &Opts,
  6233. MacroBuilder &Builder) const override {
  6234. DefineStd(Builder, "SPIR64", Opts);
  6235. }
  6236. };
  6237. class XCoreTargetInfo : public TargetInfo {
  6238. static const Builtin::Info BuiltinInfo[];
  6239. public:
  6240. XCoreTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  6241. BigEndian = false;
  6242. NoAsmVariants = true;
  6243. LongLongAlign = 32;
  6244. SuitableAlign = 32;
  6245. DoubleAlign = LongDoubleAlign = 32;
  6246. SizeType = UnsignedInt;
  6247. PtrDiffType = SignedInt;
  6248. IntPtrType = SignedInt;
  6249. WCharType = UnsignedChar;
  6250. WIntType = UnsignedInt;
  6251. UseZeroLengthBitfieldAlignment = true;
  6252. DescriptionString = "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32"
  6253. "-f64:32-a:0:32-n32";
  6254. }
  6255. void getTargetDefines(const LangOptions &Opts,
  6256. MacroBuilder &Builder) const override {
  6257. Builder.defineMacro("__XS1B__");
  6258. }
  6259. void getTargetBuiltins(const Builtin::Info *&Records,
  6260. unsigned &NumRecords) const override {
  6261. Records = BuiltinInfo;
  6262. NumRecords = clang::XCore::LastTSBuiltin-Builtin::FirstTSBuiltin;
  6263. }
  6264. BuiltinVaListKind getBuiltinVaListKind() const override {
  6265. return TargetInfo::VoidPtrBuiltinVaList;
  6266. }
  6267. const char *getClobbers() const override {
  6268. return "";
  6269. }
  6270. void getGCCRegNames(const char * const *&Names,
  6271. unsigned &NumNames) const override {
  6272. static const char * const GCCRegNames[] = {
  6273. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  6274. "r8", "r9", "r10", "r11", "cp", "dp", "sp", "lr"
  6275. };
  6276. Names = GCCRegNames;
  6277. NumNames = llvm::array_lengthof(GCCRegNames);
  6278. }
  6279. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  6280. unsigned &NumAliases) const override {
  6281. Aliases = nullptr;
  6282. NumAliases = 0;
  6283. }
  6284. bool validateAsmConstraint(const char *&Name,
  6285. TargetInfo::ConstraintInfo &Info) const override {
  6286. return false;
  6287. }
  6288. int getEHDataRegisterNumber(unsigned RegNo) const override {
  6289. // R0=ExceptionPointerRegister R1=ExceptionSelectorRegister
  6290. return (RegNo < 2)? RegNo : -1;
  6291. }
  6292. };
  6293. const Builtin::Info XCoreTargetInfo::BuiltinInfo[] = {
  6294. #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
  6295. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
  6296. ALL_LANGUAGES },
  6297. #include "clang/Basic/BuiltinsXCore.def"
  6298. };
  6299. } // end anonymous namespace.
  6300. namespace {
  6301. // x86_32 Android target
  6302. class AndroidX86_32TargetInfo : public LinuxTargetInfo<X86_32TargetInfo> {
  6303. public:
  6304. AndroidX86_32TargetInfo(const llvm::Triple &Triple)
  6305. : LinuxTargetInfo<X86_32TargetInfo>(Triple) {
  6306. SuitableAlign = 32;
  6307. LongDoubleWidth = 64;
  6308. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  6309. }
  6310. };
  6311. } // end anonymous namespace
  6312. namespace {
  6313. // x86_64 Android target
  6314. class AndroidX86_64TargetInfo : public LinuxTargetInfo<X86_64TargetInfo> {
  6315. public:
  6316. AndroidX86_64TargetInfo(const llvm::Triple &Triple)
  6317. : LinuxTargetInfo<X86_64TargetInfo>(Triple) {
  6318. LongDoubleFormat = &llvm::APFloat::IEEEquad;
  6319. }
  6320. bool useFloat128ManglingForLongDouble() const override {
  6321. return true;
  6322. }
  6323. };
  6324. } // end anonymous namespace
  6325. #endif // HLSL Change - remove unsupported targets
  6326. namespace {
  6327. class DXILTargetInfo : public TargetInfo {
  6328. static const Builtin::Info BuiltinInfo[];
  6329. public:
  6330. DXILTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
  6331. BigEndian = false;
  6332. TLSSupported = false;
  6333. LongWidth = LongAlign = 32;
  6334. LongDoubleWidth = LongDoubleAlign = 64;
  6335. LongDoubleFormat = &llvm::APFloat::IEEEdouble;
  6336. BoolWidth = BoolAlign = 32;
  6337. // using the Microsoft ABI.
  6338. TheCXXABI.set(TargetCXXABI::Microsoft);
  6339. }
  6340. void getTargetDefines(const LangOptions &Opts,
  6341. MacroBuilder &Builder) const override {
  6342. // add target defines
  6343. }
  6344. void getTargetBuiltins(const Builtin::Info *&Records,
  6345. unsigned &NumRecords) const override {
  6346. Records = BuiltinInfo;
  6347. NumRecords = clang::DXIL::LastTSBuiltin - Builtin::FirstTSBuiltin;
  6348. }
  6349. bool hasFeature(StringRef Feature) const override {
  6350. return Feature == "dxil";
  6351. }
  6352. const char *getClobbers() const override { return ""; }
  6353. void getGCCRegNames(const char *const *&Names,
  6354. unsigned &NumNames) const override {}
  6355. bool validateAsmConstraint(const char *&Name,
  6356. TargetInfo::ConstraintInfo &info) const override {
  6357. return true;
  6358. }
  6359. void getGCCRegAliases(const GCCRegAlias *&Aliases,
  6360. unsigned &NumAliases) const override {}
  6361. BuiltinVaListKind getBuiltinVaListKind() const override {
  6362. return TargetInfo::CharPtrBuiltinVaList;
  6363. }
  6364. };
  6365. const Builtin::Info DXILTargetInfo::BuiltinInfo[] = {
  6366. #define BUILTIN(ID, TYPE, ATTRS) {#ID, TYPE, ATTRS, 0, ALL_LANGUAGES},
  6367. #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \
  6368. {#ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES},
  6369. #include "clang/Basic/BuiltinsDXIL.def"
  6370. };
  6371. // DXIL 32 target
  6372. class DXIL_32TargetInfo : public DXILTargetInfo {
  6373. public:
  6374. DXIL_32TargetInfo(const llvm::Triple &Triple, const char *descriptionString) : DXILTargetInfo(Triple) {
  6375. // TODO: Update Description for DXIL
  6376. DescriptionString = descriptionString;
  6377. }
  6378. };
  6379. }
  6380. // HLSL Change Ends
  6381. //===----------------------------------------------------------------------===//
  6382. // Driver code
  6383. //===----------------------------------------------------------------------===//
  6384. static TargetInfo *AllocateTarget(const llvm::Triple &Triple, const char* descrptionString) {
  6385. #if 1 // HLSL Change
  6386. return new DXIL_32TargetInfo(Triple, descrptionString);
  6387. #else // HLSL Change
  6388. llvm::Triple::OSType os = Triple.getOS();
  6389. switch (Triple.getArch()) {
  6390. default:
  6391. return nullptr;
  6392. case llvm::Triple::xcore:
  6393. return new XCoreTargetInfo(Triple);
  6394. case llvm::Triple::hexagon:
  6395. return new HexagonTargetInfo(Triple);
  6396. case llvm::Triple::aarch64:
  6397. if (Triple.isOSDarwin())
  6398. return new DarwinAArch64TargetInfo(Triple);
  6399. switch (os) {
  6400. case llvm::Triple::FreeBSD:
  6401. return new FreeBSDTargetInfo<AArch64leTargetInfo>(Triple);
  6402. case llvm::Triple::Linux:
  6403. return new LinuxTargetInfo<AArch64leTargetInfo>(Triple);
  6404. case llvm::Triple::NetBSD:
  6405. return new NetBSDTargetInfo<AArch64leTargetInfo>(Triple);
  6406. default:
  6407. return new AArch64leTargetInfo(Triple);
  6408. }
  6409. case llvm::Triple::aarch64_be:
  6410. switch (os) {
  6411. case llvm::Triple::FreeBSD:
  6412. return new FreeBSDTargetInfo<AArch64beTargetInfo>(Triple);
  6413. case llvm::Triple::Linux:
  6414. return new LinuxTargetInfo<AArch64beTargetInfo>(Triple);
  6415. case llvm::Triple::NetBSD:
  6416. return new NetBSDTargetInfo<AArch64beTargetInfo>(Triple);
  6417. default:
  6418. return new AArch64beTargetInfo(Triple);
  6419. }
  6420. case llvm::Triple::arm:
  6421. case llvm::Triple::thumb:
  6422. if (Triple.isOSBinFormatMachO())
  6423. return new DarwinARMTargetInfo(Triple);
  6424. switch (os) {
  6425. case llvm::Triple::Linux:
  6426. return new LinuxTargetInfo<ARMleTargetInfo>(Triple);
  6427. case llvm::Triple::FreeBSD:
  6428. return new FreeBSDTargetInfo<ARMleTargetInfo>(Triple);
  6429. case llvm::Triple::NetBSD:
  6430. return new NetBSDTargetInfo<ARMleTargetInfo>(Triple);
  6431. case llvm::Triple::OpenBSD:
  6432. return new OpenBSDTargetInfo<ARMleTargetInfo>(Triple);
  6433. case llvm::Triple::Bitrig:
  6434. return new BitrigTargetInfo<ARMleTargetInfo>(Triple);
  6435. case llvm::Triple::RTEMS:
  6436. return new RTEMSTargetInfo<ARMleTargetInfo>(Triple);
  6437. case llvm::Triple::NaCl:
  6438. return new NaClTargetInfo<ARMleTargetInfo>(Triple);
  6439. case llvm::Triple::Win32:
  6440. switch (Triple.getEnvironment()) {
  6441. case llvm::Triple::Itanium:
  6442. return new ItaniumWindowsARMleTargetInfo(Triple);
  6443. case llvm::Triple::MSVC:
  6444. default: // Assume MSVC for unknown environments
  6445. return new MicrosoftARMleTargetInfo(Triple);
  6446. }
  6447. default:
  6448. return new ARMleTargetInfo(Triple);
  6449. }
  6450. case llvm::Triple::armeb:
  6451. case llvm::Triple::thumbeb:
  6452. if (Triple.isOSDarwin())
  6453. return new DarwinARMTargetInfo(Triple);
  6454. switch (os) {
  6455. case llvm::Triple::Linux:
  6456. return new LinuxTargetInfo<ARMbeTargetInfo>(Triple);
  6457. case llvm::Triple::FreeBSD:
  6458. return new FreeBSDTargetInfo<ARMbeTargetInfo>(Triple);
  6459. case llvm::Triple::NetBSD:
  6460. return new NetBSDTargetInfo<ARMbeTargetInfo>(Triple);
  6461. case llvm::Triple::OpenBSD:
  6462. return new OpenBSDTargetInfo<ARMbeTargetInfo>(Triple);
  6463. case llvm::Triple::Bitrig:
  6464. return new BitrigTargetInfo<ARMbeTargetInfo>(Triple);
  6465. case llvm::Triple::RTEMS:
  6466. return new RTEMSTargetInfo<ARMbeTargetInfo>(Triple);
  6467. case llvm::Triple::NaCl:
  6468. return new NaClTargetInfo<ARMbeTargetInfo>(Triple);
  6469. default:
  6470. return new ARMbeTargetInfo(Triple);
  6471. }
  6472. case llvm::Triple::bpfeb:
  6473. case llvm::Triple::bpfel:
  6474. return new BPFTargetInfo(Triple);
  6475. case llvm::Triple::msp430:
  6476. return new MSP430TargetInfo(Triple);
  6477. case llvm::Triple::mips:
  6478. switch (os) {
  6479. case llvm::Triple::Linux:
  6480. return new LinuxTargetInfo<Mips32EBTargetInfo>(Triple);
  6481. case llvm::Triple::RTEMS:
  6482. return new RTEMSTargetInfo<Mips32EBTargetInfo>(Triple);
  6483. case llvm::Triple::FreeBSD:
  6484. return new FreeBSDTargetInfo<Mips32EBTargetInfo>(Triple);
  6485. case llvm::Triple::NetBSD:
  6486. return new NetBSDTargetInfo<Mips32EBTargetInfo>(Triple);
  6487. default:
  6488. return new Mips32EBTargetInfo(Triple);
  6489. }
  6490. case llvm::Triple::mipsel:
  6491. switch (os) {
  6492. case llvm::Triple::Linux:
  6493. return new LinuxTargetInfo<Mips32ELTargetInfo>(Triple);
  6494. case llvm::Triple::RTEMS:
  6495. return new RTEMSTargetInfo<Mips32ELTargetInfo>(Triple);
  6496. case llvm::Triple::FreeBSD:
  6497. return new FreeBSDTargetInfo<Mips32ELTargetInfo>(Triple);
  6498. case llvm::Triple::NetBSD:
  6499. return new NetBSDTargetInfo<Mips32ELTargetInfo>(Triple);
  6500. case llvm::Triple::NaCl:
  6501. return new NaClTargetInfo<NaClMips32ELTargetInfo>(Triple);
  6502. default:
  6503. return new Mips32ELTargetInfo(Triple);
  6504. }
  6505. case llvm::Triple::mips64:
  6506. switch (os) {
  6507. case llvm::Triple::Linux:
  6508. return new LinuxTargetInfo<Mips64EBTargetInfo>(Triple);
  6509. case llvm::Triple::RTEMS:
  6510. return new RTEMSTargetInfo<Mips64EBTargetInfo>(Triple);
  6511. case llvm::Triple::FreeBSD:
  6512. return new FreeBSDTargetInfo<Mips64EBTargetInfo>(Triple);
  6513. case llvm::Triple::NetBSD:
  6514. return new NetBSDTargetInfo<Mips64EBTargetInfo>(Triple);
  6515. case llvm::Triple::OpenBSD:
  6516. return new OpenBSDTargetInfo<Mips64EBTargetInfo>(Triple);
  6517. default:
  6518. return new Mips64EBTargetInfo(Triple);
  6519. }
  6520. case llvm::Triple::mips64el:
  6521. switch (os) {
  6522. case llvm::Triple::Linux:
  6523. return new LinuxTargetInfo<Mips64ELTargetInfo>(Triple);
  6524. case llvm::Triple::RTEMS:
  6525. return new RTEMSTargetInfo<Mips64ELTargetInfo>(Triple);
  6526. case llvm::Triple::FreeBSD:
  6527. return new FreeBSDTargetInfo<Mips64ELTargetInfo>(Triple);
  6528. case llvm::Triple::NetBSD:
  6529. return new NetBSDTargetInfo<Mips64ELTargetInfo>(Triple);
  6530. case llvm::Triple::OpenBSD:
  6531. return new OpenBSDTargetInfo<Mips64ELTargetInfo>(Triple);
  6532. default:
  6533. return new Mips64ELTargetInfo(Triple);
  6534. }
  6535. case llvm::Triple::le32:
  6536. switch (os) {
  6537. case llvm::Triple::NaCl:
  6538. return new NaClTargetInfo<PNaClTargetInfo>(Triple);
  6539. default:
  6540. return nullptr;
  6541. }
  6542. case llvm::Triple::le64:
  6543. return new Le64TargetInfo(Triple);
  6544. case llvm::Triple::ppc:
  6545. if (Triple.isOSDarwin())
  6546. return new DarwinPPC32TargetInfo(Triple);
  6547. switch (os) {
  6548. case llvm::Triple::Linux:
  6549. return new LinuxTargetInfo<PPC32TargetInfo>(Triple);
  6550. case llvm::Triple::FreeBSD:
  6551. return new FreeBSDTargetInfo<PPC32TargetInfo>(Triple);
  6552. case llvm::Triple::NetBSD:
  6553. return new NetBSDTargetInfo<PPC32TargetInfo>(Triple);
  6554. case llvm::Triple::OpenBSD:
  6555. return new OpenBSDTargetInfo<PPC32TargetInfo>(Triple);
  6556. case llvm::Triple::RTEMS:
  6557. return new RTEMSTargetInfo<PPC32TargetInfo>(Triple);
  6558. default:
  6559. return new PPC32TargetInfo(Triple);
  6560. }
  6561. case llvm::Triple::ppc64:
  6562. if (Triple.isOSDarwin())
  6563. return new DarwinPPC64TargetInfo(Triple);
  6564. switch (os) {
  6565. case llvm::Triple::Linux:
  6566. return new LinuxTargetInfo<PPC64TargetInfo>(Triple);
  6567. case llvm::Triple::Lv2:
  6568. return new PS3PPUTargetInfo<PPC64TargetInfo>(Triple);
  6569. case llvm::Triple::FreeBSD:
  6570. return new FreeBSDTargetInfo<PPC64TargetInfo>(Triple);
  6571. case llvm::Triple::NetBSD:
  6572. return new NetBSDTargetInfo<PPC64TargetInfo>(Triple);
  6573. default:
  6574. return new PPC64TargetInfo(Triple);
  6575. }
  6576. case llvm::Triple::ppc64le:
  6577. switch (os) {
  6578. case llvm::Triple::Linux:
  6579. return new LinuxTargetInfo<PPC64TargetInfo>(Triple);
  6580. case llvm::Triple::NetBSD:
  6581. return new NetBSDTargetInfo<PPC64TargetInfo>(Triple);
  6582. default:
  6583. return new PPC64TargetInfo(Triple);
  6584. }
  6585. case llvm::Triple::nvptx:
  6586. return new NVPTX32TargetInfo(Triple);
  6587. case llvm::Triple::nvptx64:
  6588. return new NVPTX64TargetInfo(Triple);
  6589. case llvm::Triple::amdgcn:
  6590. case llvm::Triple::r600:
  6591. return new AMDGPUTargetInfo(Triple);
  6592. case llvm::Triple::sparc:
  6593. switch (os) {
  6594. case llvm::Triple::Linux:
  6595. return new LinuxTargetInfo<SparcV8TargetInfo>(Triple);
  6596. case llvm::Triple::Solaris:
  6597. return new SolarisTargetInfo<SparcV8TargetInfo>(Triple);
  6598. case llvm::Triple::NetBSD:
  6599. return new NetBSDTargetInfo<SparcV8TargetInfo>(Triple);
  6600. case llvm::Triple::OpenBSD:
  6601. return new OpenBSDTargetInfo<SparcV8TargetInfo>(Triple);
  6602. case llvm::Triple::RTEMS:
  6603. return new RTEMSTargetInfo<SparcV8TargetInfo>(Triple);
  6604. default:
  6605. return new SparcV8TargetInfo(Triple);
  6606. }
  6607. // The 'sparcel' architecture copies all the above cases except for Solaris.
  6608. case llvm::Triple::sparcel:
  6609. switch (os) {
  6610. case llvm::Triple::Linux:
  6611. return new LinuxTargetInfo<SparcV8elTargetInfo>(Triple);
  6612. case llvm::Triple::NetBSD:
  6613. return new NetBSDTargetInfo<SparcV8elTargetInfo>(Triple);
  6614. case llvm::Triple::OpenBSD:
  6615. return new OpenBSDTargetInfo<SparcV8elTargetInfo>(Triple);
  6616. case llvm::Triple::RTEMS:
  6617. return new RTEMSTargetInfo<SparcV8elTargetInfo>(Triple);
  6618. default:
  6619. return new SparcV8elTargetInfo(Triple);
  6620. }
  6621. case llvm::Triple::sparcv9:
  6622. switch (os) {
  6623. case llvm::Triple::Linux:
  6624. return new LinuxTargetInfo<SparcV9TargetInfo>(Triple);
  6625. case llvm::Triple::Solaris:
  6626. return new SolarisTargetInfo<SparcV9TargetInfo>(Triple);
  6627. case llvm::Triple::NetBSD:
  6628. return new NetBSDTargetInfo<SparcV9TargetInfo>(Triple);
  6629. case llvm::Triple::OpenBSD:
  6630. return new OpenBSDTargetInfo<SparcV9TargetInfo>(Triple);
  6631. case llvm::Triple::FreeBSD:
  6632. return new FreeBSDTargetInfo<SparcV9TargetInfo>(Triple);
  6633. default:
  6634. return new SparcV9TargetInfo(Triple);
  6635. }
  6636. case llvm::Triple::systemz:
  6637. switch (os) {
  6638. case llvm::Triple::Linux:
  6639. return new LinuxTargetInfo<SystemZTargetInfo>(Triple);
  6640. default:
  6641. return new SystemZTargetInfo(Triple);
  6642. }
  6643. case llvm::Triple::tce:
  6644. return new TCETargetInfo(Triple);
  6645. case llvm::Triple::x86:
  6646. if (Triple.isOSDarwin())
  6647. return new DarwinI386TargetInfo(Triple);
  6648. switch (os) {
  6649. case llvm::Triple::CloudABI:
  6650. return new CloudABITargetInfo<X86_32TargetInfo>(Triple);
  6651. case llvm::Triple::Linux: {
  6652. switch (Triple.getEnvironment()) {
  6653. default:
  6654. return new LinuxTargetInfo<X86_32TargetInfo>(Triple);
  6655. case llvm::Triple::Android:
  6656. return new AndroidX86_32TargetInfo(Triple);
  6657. }
  6658. }
  6659. case llvm::Triple::DragonFly:
  6660. return new DragonFlyBSDTargetInfo<X86_32TargetInfo>(Triple);
  6661. case llvm::Triple::NetBSD:
  6662. return new NetBSDI386TargetInfo(Triple);
  6663. case llvm::Triple::OpenBSD:
  6664. return new OpenBSDI386TargetInfo(Triple);
  6665. case llvm::Triple::Bitrig:
  6666. return new BitrigI386TargetInfo(Triple);
  6667. case llvm::Triple::FreeBSD:
  6668. return new FreeBSDTargetInfo<X86_32TargetInfo>(Triple);
  6669. case llvm::Triple::KFreeBSD:
  6670. return new KFreeBSDTargetInfo<X86_32TargetInfo>(Triple);
  6671. case llvm::Triple::Minix:
  6672. return new MinixTargetInfo<X86_32TargetInfo>(Triple);
  6673. case llvm::Triple::Solaris:
  6674. return new SolarisTargetInfo<X86_32TargetInfo>(Triple);
  6675. case llvm::Triple::Win32: {
  6676. switch (Triple.getEnvironment()) {
  6677. case llvm::Triple::Cygnus:
  6678. return new CygwinX86_32TargetInfo(Triple);
  6679. case llvm::Triple::GNU:
  6680. return new MinGWX86_32TargetInfo(Triple);
  6681. case llvm::Triple::Itanium:
  6682. case llvm::Triple::MSVC:
  6683. default: // Assume MSVC for unknown environments
  6684. return new MicrosoftX86_32TargetInfo(Triple);
  6685. }
  6686. }
  6687. case llvm::Triple::Haiku:
  6688. return new HaikuX86_32TargetInfo(Triple);
  6689. case llvm::Triple::RTEMS:
  6690. return new RTEMSX86_32TargetInfo(Triple);
  6691. case llvm::Triple::NaCl:
  6692. return new NaClTargetInfo<X86_32TargetInfo>(Triple);
  6693. default:
  6694. return new X86_32TargetInfo(Triple);
  6695. }
  6696. case llvm::Triple::x86_64:
  6697. if (Triple.isOSDarwin() || Triple.isOSBinFormatMachO())
  6698. return new DarwinX86_64TargetInfo(Triple);
  6699. switch (os) {
  6700. case llvm::Triple::CloudABI:
  6701. return new CloudABITargetInfo<X86_64TargetInfo>(Triple);
  6702. case llvm::Triple::Linux: {
  6703. switch (Triple.getEnvironment()) {
  6704. default:
  6705. return new LinuxTargetInfo<X86_64TargetInfo>(Triple);
  6706. case llvm::Triple::Android:
  6707. return new AndroidX86_64TargetInfo(Triple);
  6708. }
  6709. }
  6710. case llvm::Triple::DragonFly:
  6711. return new DragonFlyBSDTargetInfo<X86_64TargetInfo>(Triple);
  6712. case llvm::Triple::NetBSD:
  6713. return new NetBSDTargetInfo<X86_64TargetInfo>(Triple);
  6714. case llvm::Triple::OpenBSD:
  6715. return new OpenBSDX86_64TargetInfo(Triple);
  6716. case llvm::Triple::Bitrig:
  6717. return new BitrigX86_64TargetInfo(Triple);
  6718. case llvm::Triple::FreeBSD:
  6719. return new FreeBSDTargetInfo<X86_64TargetInfo>(Triple);
  6720. case llvm::Triple::KFreeBSD:
  6721. return new KFreeBSDTargetInfo<X86_64TargetInfo>(Triple);
  6722. case llvm::Triple::Solaris:
  6723. return new SolarisTargetInfo<X86_64TargetInfo>(Triple);
  6724. case llvm::Triple::Win32: {
  6725. switch (Triple.getEnvironment()) {
  6726. case llvm::Triple::GNU:
  6727. return new MinGWX86_64TargetInfo(Triple);
  6728. case llvm::Triple::MSVC:
  6729. default: // Assume MSVC for unknown environments
  6730. return new MicrosoftX86_64TargetInfo(Triple);
  6731. }
  6732. }
  6733. case llvm::Triple::NaCl:
  6734. return new NaClTargetInfo<X86_64TargetInfo>(Triple);
  6735. case llvm::Triple::PS4:
  6736. return new PS4OSTargetInfo<X86_64TargetInfo>(Triple);
  6737. default:
  6738. return new X86_64TargetInfo(Triple);
  6739. }
  6740. case llvm::Triple::spir: {
  6741. if (Triple.getOS() != llvm::Triple::UnknownOS ||
  6742. Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
  6743. return nullptr;
  6744. return new SPIR32TargetInfo(Triple);
  6745. }
  6746. case llvm::Triple::spir64: {
  6747. if (Triple.getOS() != llvm::Triple::UnknownOS ||
  6748. Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
  6749. return nullptr;
  6750. return new SPIR64TargetInfo(Triple);
  6751. }
  6752. }
  6753. #endif // HLSL Change
  6754. }
  6755. /// CreateTargetInfo - Return the target info object for the specified target
  6756. /// triple.
  6757. TargetInfo *
  6758. TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
  6759. const std::shared_ptr<TargetOptions> &Opts) {
  6760. llvm::Triple Triple(Opts->Triple);
  6761. // Construct the target
  6762. std::unique_ptr<TargetInfo> Target(AllocateTarget(Triple, Opts.get()->DescriptionString));
  6763. if (!Target) {
  6764. Diags.Report(diag::err_target_unknown_triple) << Triple.str();
  6765. return nullptr;
  6766. }
  6767. Target->TargetOpts = Opts;
  6768. // Set the target CPU if specified.
  6769. if (!Opts->CPU.empty() && !Target->setCPU(Opts->CPU)) {
  6770. Diags.Report(diag::err_target_unknown_cpu) << Opts->CPU;
  6771. return nullptr;
  6772. }
  6773. // Set the target ABI if specified.
  6774. if (!Opts->ABI.empty() && !Target->setABI(Opts->ABI)) {
  6775. Diags.Report(diag::err_target_unknown_abi) << Opts->ABI;
  6776. return nullptr;
  6777. }
  6778. // Set the fp math unit.
  6779. if (!Opts->FPMath.empty() && !Target->setFPMath(Opts->FPMath)) {
  6780. Diags.Report(diag::err_target_unknown_fpmath) << Opts->FPMath;
  6781. return nullptr;
  6782. }
  6783. // Compute the default target features, we need the target to handle this
  6784. // because features may have dependencies on one another.
  6785. llvm::StringMap<bool> Features;
  6786. Target->getDefaultFeatures(Features);
  6787. // Apply the user specified deltas.
  6788. for (unsigned I = 0, N = Opts->FeaturesAsWritten.size();
  6789. I < N; ++I) {
  6790. const char *Name = Opts->FeaturesAsWritten[I].c_str();
  6791. // Apply the feature via the target.
  6792. bool Enabled = Name[0] == '+';
  6793. Target->setFeatureEnabled(Features, Name + 1, Enabled);
  6794. }
  6795. // Add the features to the compile options.
  6796. //
  6797. // FIXME: If we are completely confident that we have the right set, we only
  6798. // need to pass the minuses.
  6799. Opts->Features.clear();
  6800. for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
  6801. ie = Features.end(); it != ie; ++it)
  6802. Opts->Features.push_back((it->second ? "+" : "-") + it->first().str());
  6803. if (!Target->handleTargetFeatures(Opts->Features, Diags))
  6804. return nullptr;
  6805. return Target.release();
  6806. }