ARMAsmParser.cpp 459 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480
  1. //===- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions -------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "ARMBaseInstrInfo.h"
  9. #include "ARMFeatures.h"
  10. #include "MCTargetDesc/ARMAddressingModes.h"
  11. #include "MCTargetDesc/ARMBaseInfo.h"
  12. #include "MCTargetDesc/ARMInstPrinter.h"
  13. #include "MCTargetDesc/ARMMCExpr.h"
  14. #include "MCTargetDesc/ARMMCTargetDesc.h"
  15. #include "TargetInfo/ARMTargetInfo.h"
  16. #include "Utils/ARMBaseInfo.h"
  17. #include "llvm/ADT/APFloat.h"
  18. #include "llvm/ADT/APInt.h"
  19. #include "llvm/ADT/None.h"
  20. #include "llvm/ADT/STLExtras.h"
  21. #include "llvm/ADT/SmallSet.h"
  22. #include "llvm/ADT/SmallVector.h"
  23. #include "llvm/ADT/StringMap.h"
  24. #include "llvm/ADT/StringRef.h"
  25. #include "llvm/ADT/StringSet.h"
  26. #include "llvm/ADT/StringSwitch.h"
  27. #include "llvm/ADT/Triple.h"
  28. #include "llvm/ADT/Twine.h"
  29. #include "llvm/MC/MCContext.h"
  30. #include "llvm/MC/MCExpr.h"
  31. #include "llvm/MC/MCInst.h"
  32. #include "llvm/MC/MCInstrDesc.h"
  33. #include "llvm/MC/MCInstrInfo.h"
  34. #include "llvm/MC/MCParser/MCAsmLexer.h"
  35. #include "llvm/MC/MCParser/MCAsmParser.h"
  36. #include "llvm/MC/MCParser/MCAsmParserExtension.h"
  37. #include "llvm/MC/MCParser/MCAsmParserUtils.h"
  38. #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
  39. #include "llvm/MC/MCParser/MCTargetAsmParser.h"
  40. #include "llvm/MC/MCRegisterInfo.h"
  41. #include "llvm/MC/MCSection.h"
  42. #include "llvm/MC/MCStreamer.h"
  43. #include "llvm/MC/MCSubtargetInfo.h"
  44. #include "llvm/MC/MCSymbol.h"
  45. #include "llvm/MC/SubtargetFeature.h"
  46. #include "llvm/MC/TargetRegistry.h"
  47. #include "llvm/Support/ARMBuildAttributes.h"
  48. #include "llvm/Support/ARMEHABI.h"
  49. #include "llvm/Support/Casting.h"
  50. #include "llvm/Support/CommandLine.h"
  51. #include "llvm/Support/Compiler.h"
  52. #include "llvm/Support/ErrorHandling.h"
  53. #include "llvm/Support/MathExtras.h"
  54. #include "llvm/Support/SMLoc.h"
  55. #include "llvm/Support/TargetParser.h"
  56. #include "llvm/Support/raw_ostream.h"
  57. #include <algorithm>
  58. #include <cassert>
  59. #include <cstddef>
  60. #include <cstdint>
  61. #include <iterator>
  62. #include <limits>
  63. #include <memory>
  64. #include <string>
  65. #include <utility>
  66. #include <vector>
  67. #define DEBUG_TYPE "asm-parser"
  68. using namespace llvm;
  69. namespace llvm {
  70. extern const MCInstrDesc ARMInsts[];
  71. } // end namespace llvm
  72. namespace {
  73. enum class ImplicitItModeTy { Always, Never, ARMOnly, ThumbOnly };
  74. static cl::opt<ImplicitItModeTy> ImplicitItMode(
  75. "arm-implicit-it", cl::init(ImplicitItModeTy::ARMOnly),
  76. cl::desc("Allow conditional instructions outdside of an IT block"),
  77. cl::values(clEnumValN(ImplicitItModeTy::Always, "always",
  78. "Accept in both ISAs, emit implicit ITs in Thumb"),
  79. clEnumValN(ImplicitItModeTy::Never, "never",
  80. "Warn in ARM, reject in Thumb"),
  81. clEnumValN(ImplicitItModeTy::ARMOnly, "arm",
  82. "Accept in ARM, reject in Thumb"),
  83. clEnumValN(ImplicitItModeTy::ThumbOnly, "thumb",
  84. "Warn in ARM, emit implicit ITs in Thumb")));
  85. static cl::opt<bool> AddBuildAttributes("arm-add-build-attributes",
  86. cl::init(false));
  87. enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
  88. static inline unsigned extractITMaskBit(unsigned Mask, unsigned Position) {
  89. // Position==0 means we're not in an IT block at all. Position==1
  90. // means we want the first state bit, which is always 0 (Then).
  91. // Position==2 means we want the second state bit, stored at bit 3
  92. // of Mask, and so on downwards. So (5 - Position) will shift the
  93. // right bit down to bit 0, including the always-0 bit at bit 4 for
  94. // the mandatory initial Then.
  95. return (Mask >> (5 - Position) & 1);
  96. }
  97. class UnwindContext {
  98. using Locs = SmallVector<SMLoc, 4>;
  99. MCAsmParser &Parser;
  100. Locs FnStartLocs;
  101. Locs CantUnwindLocs;
  102. Locs PersonalityLocs;
  103. Locs PersonalityIndexLocs;
  104. Locs HandlerDataLocs;
  105. int FPReg;
  106. public:
  107. UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
  108. bool hasFnStart() const { return !FnStartLocs.empty(); }
  109. bool cantUnwind() const { return !CantUnwindLocs.empty(); }
  110. bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
  111. bool hasPersonality() const {
  112. return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
  113. }
  114. void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
  115. void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
  116. void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
  117. void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
  118. void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
  119. void saveFPReg(int Reg) { FPReg = Reg; }
  120. int getFPReg() const { return FPReg; }
  121. void emitFnStartLocNotes() const {
  122. for (const SMLoc &Loc : FnStartLocs)
  123. Parser.Note(Loc, ".fnstart was specified here");
  124. }
  125. void emitCantUnwindLocNotes() const {
  126. for (const SMLoc &Loc : CantUnwindLocs)
  127. Parser.Note(Loc, ".cantunwind was specified here");
  128. }
  129. void emitHandlerDataLocNotes() const {
  130. for (const SMLoc &Loc : HandlerDataLocs)
  131. Parser.Note(Loc, ".handlerdata was specified here");
  132. }
  133. void emitPersonalityLocNotes() const {
  134. for (Locs::const_iterator PI = PersonalityLocs.begin(),
  135. PE = PersonalityLocs.end(),
  136. PII = PersonalityIndexLocs.begin(),
  137. PIE = PersonalityIndexLocs.end();
  138. PI != PE || PII != PIE;) {
  139. if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
  140. Parser.Note(*PI++, ".personality was specified here");
  141. else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
  142. Parser.Note(*PII++, ".personalityindex was specified here");
  143. else
  144. llvm_unreachable(".personality and .personalityindex cannot be "
  145. "at the same location");
  146. }
  147. }
  148. void reset() {
  149. FnStartLocs = Locs();
  150. CantUnwindLocs = Locs();
  151. PersonalityLocs = Locs();
  152. HandlerDataLocs = Locs();
  153. PersonalityIndexLocs = Locs();
  154. FPReg = ARM::SP;
  155. }
  156. };
  157. // Various sets of ARM instruction mnemonics which are used by the asm parser
  158. class ARMMnemonicSets {
  159. StringSet<> CDE;
  160. StringSet<> CDEWithVPTSuffix;
  161. public:
  162. ARMMnemonicSets(const MCSubtargetInfo &STI);
  163. /// Returns true iff a given mnemonic is a CDE instruction
  164. bool isCDEInstr(StringRef Mnemonic) {
  165. // Quick check before searching the set
  166. if (!Mnemonic.startswith("cx") && !Mnemonic.startswith("vcx"))
  167. return false;
  168. return CDE.count(Mnemonic);
  169. }
  170. /// Returns true iff a given mnemonic is a VPT-predicable CDE instruction
  171. /// (possibly with a predication suffix "e" or "t")
  172. bool isVPTPredicableCDEInstr(StringRef Mnemonic) {
  173. if (!Mnemonic.startswith("vcx"))
  174. return false;
  175. return CDEWithVPTSuffix.count(Mnemonic);
  176. }
  177. /// Returns true iff a given mnemonic is an IT-predicable CDE instruction
  178. /// (possibly with a condition suffix)
  179. bool isITPredicableCDEInstr(StringRef Mnemonic) {
  180. if (!Mnemonic.startswith("cx"))
  181. return false;
  182. return Mnemonic.startswith("cx1a") || Mnemonic.startswith("cx1da") ||
  183. Mnemonic.startswith("cx2a") || Mnemonic.startswith("cx2da") ||
  184. Mnemonic.startswith("cx3a") || Mnemonic.startswith("cx3da");
  185. }
  186. /// Return true iff a given mnemonic is an integer CDE instruction with
  187. /// dual-register destination
  188. bool isCDEDualRegInstr(StringRef Mnemonic) {
  189. if (!Mnemonic.startswith("cx"))
  190. return false;
  191. return Mnemonic == "cx1d" || Mnemonic == "cx1da" ||
  192. Mnemonic == "cx2d" || Mnemonic == "cx2da" ||
  193. Mnemonic == "cx3d" || Mnemonic == "cx3da";
  194. }
  195. };
  196. ARMMnemonicSets::ARMMnemonicSets(const MCSubtargetInfo &STI) {
  197. for (StringRef Mnemonic: { "cx1", "cx1a", "cx1d", "cx1da",
  198. "cx2", "cx2a", "cx2d", "cx2da",
  199. "cx3", "cx3a", "cx3d", "cx3da", })
  200. CDE.insert(Mnemonic);
  201. for (StringRef Mnemonic :
  202. {"vcx1", "vcx1a", "vcx2", "vcx2a", "vcx3", "vcx3a"}) {
  203. CDE.insert(Mnemonic);
  204. CDEWithVPTSuffix.insert(Mnemonic);
  205. CDEWithVPTSuffix.insert(std::string(Mnemonic) + "t");
  206. CDEWithVPTSuffix.insert(std::string(Mnemonic) + "e");
  207. }
  208. }
  209. class ARMAsmParser : public MCTargetAsmParser {
  210. const MCRegisterInfo *MRI;
  211. UnwindContext UC;
  212. ARMMnemonicSets MS;
  213. ARMTargetStreamer &getTargetStreamer() {
  214. assert(getParser().getStreamer().getTargetStreamer() &&
  215. "do not have a target streamer");
  216. MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
  217. return static_cast<ARMTargetStreamer &>(TS);
  218. }
  219. // Map of register aliases registers via the .req directive.
  220. StringMap<unsigned> RegisterReqs;
  221. bool NextSymbolIsThumb;
  222. bool useImplicitITThumb() const {
  223. return ImplicitItMode == ImplicitItModeTy::Always ||
  224. ImplicitItMode == ImplicitItModeTy::ThumbOnly;
  225. }
  226. bool useImplicitITARM() const {
  227. return ImplicitItMode == ImplicitItModeTy::Always ||
  228. ImplicitItMode == ImplicitItModeTy::ARMOnly;
  229. }
  230. struct {
  231. ARMCC::CondCodes Cond; // Condition for IT block.
  232. unsigned Mask:4; // Condition mask for instructions.
  233. // Starting at first 1 (from lsb).
  234. // '1' condition as indicated in IT.
  235. // '0' inverse of condition (else).
  236. // Count of instructions in IT block is
  237. // 4 - trailingzeroes(mask)
  238. // Note that this does not have the same encoding
  239. // as in the IT instruction, which also depends
  240. // on the low bit of the condition code.
  241. unsigned CurPosition; // Current position in parsing of IT
  242. // block. In range [0,4], with 0 being the IT
  243. // instruction itself. Initialized according to
  244. // count of instructions in block. ~0U if no
  245. // active IT block.
  246. bool IsExplicit; // true - The IT instruction was present in the
  247. // input, we should not modify it.
  248. // false - The IT instruction was added
  249. // implicitly, we can extend it if that
  250. // would be legal.
  251. } ITState;
  252. SmallVector<MCInst, 4> PendingConditionalInsts;
  253. void flushPendingInstructions(MCStreamer &Out) override {
  254. if (!inImplicitITBlock()) {
  255. assert(PendingConditionalInsts.size() == 0);
  256. return;
  257. }
  258. // Emit the IT instruction
  259. MCInst ITInst;
  260. ITInst.setOpcode(ARM::t2IT);
  261. ITInst.addOperand(MCOperand::createImm(ITState.Cond));
  262. ITInst.addOperand(MCOperand::createImm(ITState.Mask));
  263. Out.emitInstruction(ITInst, getSTI());
  264. // Emit the conditonal instructions
  265. assert(PendingConditionalInsts.size() <= 4);
  266. for (const MCInst &Inst : PendingConditionalInsts) {
  267. Out.emitInstruction(Inst, getSTI());
  268. }
  269. PendingConditionalInsts.clear();
  270. // Clear the IT state
  271. ITState.Mask = 0;
  272. ITState.CurPosition = ~0U;
  273. }
  274. bool inITBlock() { return ITState.CurPosition != ~0U; }
  275. bool inExplicitITBlock() { return inITBlock() && ITState.IsExplicit; }
  276. bool inImplicitITBlock() { return inITBlock() && !ITState.IsExplicit; }
  277. bool lastInITBlock() {
  278. return ITState.CurPosition == 4 - countTrailingZeros(ITState.Mask);
  279. }
  280. void forwardITPosition() {
  281. if (!inITBlock()) return;
  282. // Move to the next instruction in the IT block, if there is one. If not,
  283. // mark the block as done, except for implicit IT blocks, which we leave
  284. // open until we find an instruction that can't be added to it.
  285. unsigned TZ = countTrailingZeros(ITState.Mask);
  286. if (++ITState.CurPosition == 5 - TZ && ITState.IsExplicit)
  287. ITState.CurPosition = ~0U; // Done with the IT block after this.
  288. }
  289. // Rewind the state of the current IT block, removing the last slot from it.
  290. void rewindImplicitITPosition() {
  291. assert(inImplicitITBlock());
  292. assert(ITState.CurPosition > 1);
  293. ITState.CurPosition--;
  294. unsigned TZ = countTrailingZeros(ITState.Mask);
  295. unsigned NewMask = 0;
  296. NewMask |= ITState.Mask & (0xC << TZ);
  297. NewMask |= 0x2 << TZ;
  298. ITState.Mask = NewMask;
  299. }
  300. // Rewind the state of the current IT block, removing the last slot from it.
  301. // If we were at the first slot, this closes the IT block.
  302. void discardImplicitITBlock() {
  303. assert(inImplicitITBlock());
  304. assert(ITState.CurPosition == 1);
  305. ITState.CurPosition = ~0U;
  306. }
  307. // Return the low-subreg of a given Q register.
  308. unsigned getDRegFromQReg(unsigned QReg) const {
  309. return MRI->getSubReg(QReg, ARM::dsub_0);
  310. }
  311. // Get the condition code corresponding to the current IT block slot.
  312. ARMCC::CondCodes currentITCond() {
  313. unsigned MaskBit = extractITMaskBit(ITState.Mask, ITState.CurPosition);
  314. return MaskBit ? ARMCC::getOppositeCondition(ITState.Cond) : ITState.Cond;
  315. }
  316. // Invert the condition of the current IT block slot without changing any
  317. // other slots in the same block.
  318. void invertCurrentITCondition() {
  319. if (ITState.CurPosition == 1) {
  320. ITState.Cond = ARMCC::getOppositeCondition(ITState.Cond);
  321. } else {
  322. ITState.Mask ^= 1 << (5 - ITState.CurPosition);
  323. }
  324. }
  325. // Returns true if the current IT block is full (all 4 slots used).
  326. bool isITBlockFull() {
  327. return inITBlock() && (ITState.Mask & 1);
  328. }
  329. // Extend the current implicit IT block to have one more slot with the given
  330. // condition code.
  331. void extendImplicitITBlock(ARMCC::CondCodes Cond) {
  332. assert(inImplicitITBlock());
  333. assert(!isITBlockFull());
  334. assert(Cond == ITState.Cond ||
  335. Cond == ARMCC::getOppositeCondition(ITState.Cond));
  336. unsigned TZ = countTrailingZeros(ITState.Mask);
  337. unsigned NewMask = 0;
  338. // Keep any existing condition bits.
  339. NewMask |= ITState.Mask & (0xE << TZ);
  340. // Insert the new condition bit.
  341. NewMask |= (Cond != ITState.Cond) << TZ;
  342. // Move the trailing 1 down one bit.
  343. NewMask |= 1 << (TZ - 1);
  344. ITState.Mask = NewMask;
  345. }
  346. // Create a new implicit IT block with a dummy condition code.
  347. void startImplicitITBlock() {
  348. assert(!inITBlock());
  349. ITState.Cond = ARMCC::AL;
  350. ITState.Mask = 8;
  351. ITState.CurPosition = 1;
  352. ITState.IsExplicit = false;
  353. }
  354. // Create a new explicit IT block with the given condition and mask.
  355. // The mask should be in the format used in ARMOperand and
  356. // MCOperand, with a 1 implying 'e', regardless of the low bit of
  357. // the condition.
  358. void startExplicitITBlock(ARMCC::CondCodes Cond, unsigned Mask) {
  359. assert(!inITBlock());
  360. ITState.Cond = Cond;
  361. ITState.Mask = Mask;
  362. ITState.CurPosition = 0;
  363. ITState.IsExplicit = true;
  364. }
  365. struct {
  366. unsigned Mask : 4;
  367. unsigned CurPosition;
  368. } VPTState;
  369. bool inVPTBlock() { return VPTState.CurPosition != ~0U; }
  370. void forwardVPTPosition() {
  371. if (!inVPTBlock()) return;
  372. unsigned TZ = countTrailingZeros(VPTState.Mask);
  373. if (++VPTState.CurPosition == 5 - TZ)
  374. VPTState.CurPosition = ~0U;
  375. }
  376. void Note(SMLoc L, const Twine &Msg, SMRange Range = None) {
  377. return getParser().Note(L, Msg, Range);
  378. }
  379. bool Warning(SMLoc L, const Twine &Msg, SMRange Range = None) {
  380. return getParser().Warning(L, Msg, Range);
  381. }
  382. bool Error(SMLoc L, const Twine &Msg, SMRange Range = None) {
  383. return getParser().Error(L, Msg, Range);
  384. }
  385. bool validatetLDMRegList(const MCInst &Inst, const OperandVector &Operands,
  386. unsigned ListNo, bool IsARPop = false);
  387. bool validatetSTMRegList(const MCInst &Inst, const OperandVector &Operands,
  388. unsigned ListNo);
  389. int tryParseRegister();
  390. bool tryParseRegisterWithWriteBack(OperandVector &);
  391. int tryParseShiftRegister(OperandVector &);
  392. bool parseRegisterList(OperandVector &, bool EnforceOrder = true,
  393. bool AllowRAAC = false);
  394. bool parseMemory(OperandVector &);
  395. bool parseOperand(OperandVector &, StringRef Mnemonic);
  396. bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
  397. bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
  398. unsigned &ShiftAmount);
  399. bool parseLiteralValues(unsigned Size, SMLoc L);
  400. bool parseDirectiveThumb(SMLoc L);
  401. bool parseDirectiveARM(SMLoc L);
  402. bool parseDirectiveThumbFunc(SMLoc L);
  403. bool parseDirectiveCode(SMLoc L);
  404. bool parseDirectiveSyntax(SMLoc L);
  405. bool parseDirectiveReq(StringRef Name, SMLoc L);
  406. bool parseDirectiveUnreq(SMLoc L);
  407. bool parseDirectiveArch(SMLoc L);
  408. bool parseDirectiveEabiAttr(SMLoc L);
  409. bool parseDirectiveCPU(SMLoc L);
  410. bool parseDirectiveFPU(SMLoc L);
  411. bool parseDirectiveFnStart(SMLoc L);
  412. bool parseDirectiveFnEnd(SMLoc L);
  413. bool parseDirectiveCantUnwind(SMLoc L);
  414. bool parseDirectivePersonality(SMLoc L);
  415. bool parseDirectiveHandlerData(SMLoc L);
  416. bool parseDirectiveSetFP(SMLoc L);
  417. bool parseDirectivePad(SMLoc L);
  418. bool parseDirectiveRegSave(SMLoc L, bool IsVector);
  419. bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
  420. bool parseDirectiveLtorg(SMLoc L);
  421. bool parseDirectiveEven(SMLoc L);
  422. bool parseDirectivePersonalityIndex(SMLoc L);
  423. bool parseDirectiveUnwindRaw(SMLoc L);
  424. bool parseDirectiveTLSDescSeq(SMLoc L);
  425. bool parseDirectiveMovSP(SMLoc L);
  426. bool parseDirectiveObjectArch(SMLoc L);
  427. bool parseDirectiveArchExtension(SMLoc L);
  428. bool parseDirectiveAlign(SMLoc L);
  429. bool parseDirectiveThumbSet(SMLoc L);
  430. bool isMnemonicVPTPredicable(StringRef Mnemonic, StringRef ExtraToken);
  431. StringRef splitMnemonic(StringRef Mnemonic, StringRef ExtraToken,
  432. unsigned &PredicationCode,
  433. unsigned &VPTPredicationCode, bool &CarrySetting,
  434. unsigned &ProcessorIMod, StringRef &ITMask);
  435. void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef ExtraToken,
  436. StringRef FullInst, bool &CanAcceptCarrySet,
  437. bool &CanAcceptPredicationCode,
  438. bool &CanAcceptVPTPredicationCode);
  439. bool enableArchExtFeature(StringRef Name, SMLoc &ExtLoc);
  440. void tryConvertingToTwoOperandForm(StringRef Mnemonic, bool CarrySetting,
  441. OperandVector &Operands);
  442. bool CDEConvertDualRegOperand(StringRef Mnemonic, OperandVector &Operands);
  443. bool isThumb() const {
  444. // FIXME: Can tablegen auto-generate this?
  445. return getSTI().getFeatureBits()[ARM::ModeThumb];
  446. }
  447. bool isThumbOne() const {
  448. return isThumb() && !getSTI().getFeatureBits()[ARM::FeatureThumb2];
  449. }
  450. bool isThumbTwo() const {
  451. return isThumb() && getSTI().getFeatureBits()[ARM::FeatureThumb2];
  452. }
  453. bool hasThumb() const {
  454. return getSTI().getFeatureBits()[ARM::HasV4TOps];
  455. }
  456. bool hasThumb2() const {
  457. return getSTI().getFeatureBits()[ARM::FeatureThumb2];
  458. }
  459. bool hasV6Ops() const {
  460. return getSTI().getFeatureBits()[ARM::HasV6Ops];
  461. }
  462. bool hasV6T2Ops() const {
  463. return getSTI().getFeatureBits()[ARM::HasV6T2Ops];
  464. }
  465. bool hasV6MOps() const {
  466. return getSTI().getFeatureBits()[ARM::HasV6MOps];
  467. }
  468. bool hasV7Ops() const {
  469. return getSTI().getFeatureBits()[ARM::HasV7Ops];
  470. }
  471. bool hasV8Ops() const {
  472. return getSTI().getFeatureBits()[ARM::HasV8Ops];
  473. }
  474. bool hasV8MBaseline() const {
  475. return getSTI().getFeatureBits()[ARM::HasV8MBaselineOps];
  476. }
  477. bool hasV8MMainline() const {
  478. return getSTI().getFeatureBits()[ARM::HasV8MMainlineOps];
  479. }
  480. bool hasV8_1MMainline() const {
  481. return getSTI().getFeatureBits()[ARM::HasV8_1MMainlineOps];
  482. }
  483. bool hasMVE() const {
  484. return getSTI().getFeatureBits()[ARM::HasMVEIntegerOps];
  485. }
  486. bool hasMVEFloat() const {
  487. return getSTI().getFeatureBits()[ARM::HasMVEFloatOps];
  488. }
  489. bool hasCDE() const {
  490. return getSTI().getFeatureBits()[ARM::HasCDEOps];
  491. }
  492. bool has8MSecExt() const {
  493. return getSTI().getFeatureBits()[ARM::Feature8MSecExt];
  494. }
  495. bool hasARM() const {
  496. return !getSTI().getFeatureBits()[ARM::FeatureNoARM];
  497. }
  498. bool hasDSP() const {
  499. return getSTI().getFeatureBits()[ARM::FeatureDSP];
  500. }
  501. bool hasD32() const {
  502. return getSTI().getFeatureBits()[ARM::FeatureD32];
  503. }
  504. bool hasV8_1aOps() const {
  505. return getSTI().getFeatureBits()[ARM::HasV8_1aOps];
  506. }
  507. bool hasRAS() const {
  508. return getSTI().getFeatureBits()[ARM::FeatureRAS];
  509. }
  510. void SwitchMode() {
  511. MCSubtargetInfo &STI = copySTI();
  512. auto FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
  513. setAvailableFeatures(FB);
  514. }
  515. void FixModeAfterArchChange(bool WasThumb, SMLoc Loc);
  516. bool isMClass() const {
  517. return getSTI().getFeatureBits()[ARM::FeatureMClass];
  518. }
  519. /// @name Auto-generated Match Functions
  520. /// {
  521. #define GET_ASSEMBLER_HEADER
  522. #include "ARMGenAsmMatcher.inc"
  523. /// }
  524. OperandMatchResultTy parseITCondCode(OperandVector &);
  525. OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
  526. OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
  527. OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
  528. OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
  529. OperandMatchResultTy parseTraceSyncBarrierOptOperand(OperandVector &);
  530. OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
  531. OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
  532. OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
  533. OperandMatchResultTy parseBankedRegOperand(OperandVector &);
  534. OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
  535. int High);
  536. OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
  537. return parsePKHImm(O, "lsl", 0, 31);
  538. }
  539. OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
  540. return parsePKHImm(O, "asr", 1, 32);
  541. }
  542. OperandMatchResultTy parseSetEndImm(OperandVector &);
  543. OperandMatchResultTy parseShifterImm(OperandVector &);
  544. OperandMatchResultTy parseRotImm(OperandVector &);
  545. OperandMatchResultTy parseModImm(OperandVector &);
  546. OperandMatchResultTy parseBitfield(OperandVector &);
  547. OperandMatchResultTy parsePostIdxReg(OperandVector &);
  548. OperandMatchResultTy parseAM3Offset(OperandVector &);
  549. OperandMatchResultTy parseFPImm(OperandVector &);
  550. OperandMatchResultTy parseVectorList(OperandVector &);
  551. OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
  552. SMLoc &EndLoc);
  553. // Asm Match Converter Methods
  554. void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
  555. void cvtThumbBranches(MCInst &Inst, const OperandVector &);
  556. void cvtMVEVMOVQtoDReg(MCInst &Inst, const OperandVector &);
  557. bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
  558. bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out);
  559. bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
  560. bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
  561. bool shouldOmitVectorPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
  562. bool isITBlockTerminator(MCInst &Inst) const;
  563. void fixupGNULDRDAlias(StringRef Mnemonic, OperandVector &Operands);
  564. bool validateLDRDSTRD(MCInst &Inst, const OperandVector &Operands,
  565. bool Load, bool ARMMode, bool Writeback);
  566. public:
  567. enum ARMMatchResultTy {
  568. Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
  569. Match_RequiresNotITBlock,
  570. Match_RequiresV6,
  571. Match_RequiresThumb2,
  572. Match_RequiresV8,
  573. Match_RequiresFlagSetting,
  574. #define GET_OPERAND_DIAGNOSTIC_TYPES
  575. #include "ARMGenAsmMatcher.inc"
  576. };
  577. ARMAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser,
  578. const MCInstrInfo &MII, const MCTargetOptions &Options)
  579. : MCTargetAsmParser(Options, STI, MII), UC(Parser), MS(STI) {
  580. MCAsmParserExtension::Initialize(Parser);
  581. // Cache the MCRegisterInfo.
  582. MRI = getContext().getRegisterInfo();
  583. // Initialize the set of available features.
  584. setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
  585. // Add build attributes based on the selected target.
  586. if (AddBuildAttributes)
  587. getTargetStreamer().emitTargetAttributes(STI);
  588. // Not in an ITBlock to start with.
  589. ITState.CurPosition = ~0U;
  590. VPTState.CurPosition = ~0U;
  591. NextSymbolIsThumb = false;
  592. }
  593. // Implementation of the MCTargetAsmParser interface:
  594. bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
  595. OperandMatchResultTy tryParseRegister(unsigned &RegNo, SMLoc &StartLoc,
  596. SMLoc &EndLoc) override;
  597. bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
  598. SMLoc NameLoc, OperandVector &Operands) override;
  599. bool ParseDirective(AsmToken DirectiveID) override;
  600. unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
  601. unsigned Kind) override;
  602. unsigned checkTargetMatchPredicate(MCInst &Inst) override;
  603. bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
  604. OperandVector &Operands, MCStreamer &Out,
  605. uint64_t &ErrorInfo,
  606. bool MatchingInlineAsm) override;
  607. unsigned MatchInstruction(OperandVector &Operands, MCInst &Inst,
  608. SmallVectorImpl<NearMissInfo> &NearMisses,
  609. bool MatchingInlineAsm, bool &EmitInITBlock,
  610. MCStreamer &Out);
  611. struct NearMissMessage {
  612. SMLoc Loc;
  613. SmallString<128> Message;
  614. };
  615. const char *getCustomOperandDiag(ARMMatchResultTy MatchError);
  616. void FilterNearMisses(SmallVectorImpl<NearMissInfo> &NearMissesIn,
  617. SmallVectorImpl<NearMissMessage> &NearMissesOut,
  618. SMLoc IDLoc, OperandVector &Operands);
  619. void ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses, SMLoc IDLoc,
  620. OperandVector &Operands);
  621. void doBeforeLabelEmit(MCSymbol *Symbol) override;
  622. void onLabelParsed(MCSymbol *Symbol) override;
  623. };
  624. /// ARMOperand - Instances of this class represent a parsed ARM machine
  625. /// operand.
  626. class ARMOperand : public MCParsedAsmOperand {
  627. enum KindTy {
  628. k_CondCode,
  629. k_VPTPred,
  630. k_CCOut,
  631. k_ITCondMask,
  632. k_CoprocNum,
  633. k_CoprocReg,
  634. k_CoprocOption,
  635. k_Immediate,
  636. k_MemBarrierOpt,
  637. k_InstSyncBarrierOpt,
  638. k_TraceSyncBarrierOpt,
  639. k_Memory,
  640. k_PostIndexRegister,
  641. k_MSRMask,
  642. k_BankedReg,
  643. k_ProcIFlags,
  644. k_VectorIndex,
  645. k_Register,
  646. k_RegisterList,
  647. k_RegisterListWithAPSR,
  648. k_DPRRegisterList,
  649. k_SPRRegisterList,
  650. k_FPSRegisterListWithVPR,
  651. k_FPDRegisterListWithVPR,
  652. k_VectorList,
  653. k_VectorListAllLanes,
  654. k_VectorListIndexed,
  655. k_ShiftedRegister,
  656. k_ShiftedImmediate,
  657. k_ShifterImmediate,
  658. k_RotateImmediate,
  659. k_ModifiedImmediate,
  660. k_ConstantPoolImmediate,
  661. k_BitfieldDescriptor,
  662. k_Token,
  663. } Kind;
  664. SMLoc StartLoc, EndLoc, AlignmentLoc;
  665. SmallVector<unsigned, 8> Registers;
  666. struct CCOp {
  667. ARMCC::CondCodes Val;
  668. };
  669. struct VCCOp {
  670. ARMVCC::VPTCodes Val;
  671. };
  672. struct CopOp {
  673. unsigned Val;
  674. };
  675. struct CoprocOptionOp {
  676. unsigned Val;
  677. };
  678. struct ITMaskOp {
  679. unsigned Mask:4;
  680. };
  681. struct MBOptOp {
  682. ARM_MB::MemBOpt Val;
  683. };
  684. struct ISBOptOp {
  685. ARM_ISB::InstSyncBOpt Val;
  686. };
  687. struct TSBOptOp {
  688. ARM_TSB::TraceSyncBOpt Val;
  689. };
  690. struct IFlagsOp {
  691. ARM_PROC::IFlags Val;
  692. };
  693. struct MMaskOp {
  694. unsigned Val;
  695. };
  696. struct BankedRegOp {
  697. unsigned Val;
  698. };
  699. struct TokOp {
  700. const char *Data;
  701. unsigned Length;
  702. };
  703. struct RegOp {
  704. unsigned RegNum;
  705. };
  706. // A vector register list is a sequential list of 1 to 4 registers.
  707. struct VectorListOp {
  708. unsigned RegNum;
  709. unsigned Count;
  710. unsigned LaneIndex;
  711. bool isDoubleSpaced;
  712. };
  713. struct VectorIndexOp {
  714. unsigned Val;
  715. };
  716. struct ImmOp {
  717. const MCExpr *Val;
  718. };
  719. /// Combined record for all forms of ARM address expressions.
  720. struct MemoryOp {
  721. unsigned BaseRegNum;
  722. // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
  723. // was specified.
  724. const MCExpr *OffsetImm; // Offset immediate value
  725. unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
  726. ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
  727. unsigned ShiftImm; // shift for OffsetReg.
  728. unsigned Alignment; // 0 = no alignment specified
  729. // n = alignment in bytes (2, 4, 8, 16, or 32)
  730. unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
  731. };
  732. struct PostIdxRegOp {
  733. unsigned RegNum;
  734. bool isAdd;
  735. ARM_AM::ShiftOpc ShiftTy;
  736. unsigned ShiftImm;
  737. };
  738. struct ShifterImmOp {
  739. bool isASR;
  740. unsigned Imm;
  741. };
  742. struct RegShiftedRegOp {
  743. ARM_AM::ShiftOpc ShiftTy;
  744. unsigned SrcReg;
  745. unsigned ShiftReg;
  746. unsigned ShiftImm;
  747. };
  748. struct RegShiftedImmOp {
  749. ARM_AM::ShiftOpc ShiftTy;
  750. unsigned SrcReg;
  751. unsigned ShiftImm;
  752. };
  753. struct RotImmOp {
  754. unsigned Imm;
  755. };
  756. struct ModImmOp {
  757. unsigned Bits;
  758. unsigned Rot;
  759. };
  760. struct BitfieldOp {
  761. unsigned LSB;
  762. unsigned Width;
  763. };
  764. union {
  765. struct CCOp CC;
  766. struct VCCOp VCC;
  767. struct CopOp Cop;
  768. struct CoprocOptionOp CoprocOption;
  769. struct MBOptOp MBOpt;
  770. struct ISBOptOp ISBOpt;
  771. struct TSBOptOp TSBOpt;
  772. struct ITMaskOp ITMask;
  773. struct IFlagsOp IFlags;
  774. struct MMaskOp MMask;
  775. struct BankedRegOp BankedReg;
  776. struct TokOp Tok;
  777. struct RegOp Reg;
  778. struct VectorListOp VectorList;
  779. struct VectorIndexOp VectorIndex;
  780. struct ImmOp Imm;
  781. struct MemoryOp Memory;
  782. struct PostIdxRegOp PostIdxReg;
  783. struct ShifterImmOp ShifterImm;
  784. struct RegShiftedRegOp RegShiftedReg;
  785. struct RegShiftedImmOp RegShiftedImm;
  786. struct RotImmOp RotImm;
  787. struct ModImmOp ModImm;
  788. struct BitfieldOp Bitfield;
  789. };
  790. public:
  791. ARMOperand(KindTy K) : Kind(K) {}
  792. /// getStartLoc - Get the location of the first token of this operand.
  793. SMLoc getStartLoc() const override { return StartLoc; }
  794. /// getEndLoc - Get the location of the last token of this operand.
  795. SMLoc getEndLoc() const override { return EndLoc; }
  796. /// getLocRange - Get the range between the first and last token of this
  797. /// operand.
  798. SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
  799. /// getAlignmentLoc - Get the location of the Alignment token of this operand.
  800. SMLoc getAlignmentLoc() const {
  801. assert(Kind == k_Memory && "Invalid access!");
  802. return AlignmentLoc;
  803. }
  804. ARMCC::CondCodes getCondCode() const {
  805. assert(Kind == k_CondCode && "Invalid access!");
  806. return CC.Val;
  807. }
  808. ARMVCC::VPTCodes getVPTPred() const {
  809. assert(isVPTPred() && "Invalid access!");
  810. return VCC.Val;
  811. }
  812. unsigned getCoproc() const {
  813. assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
  814. return Cop.Val;
  815. }
  816. StringRef getToken() const {
  817. assert(Kind == k_Token && "Invalid access!");
  818. return StringRef(Tok.Data, Tok.Length);
  819. }
  820. unsigned getReg() const override {
  821. assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
  822. return Reg.RegNum;
  823. }
  824. const SmallVectorImpl<unsigned> &getRegList() const {
  825. assert((Kind == k_RegisterList || Kind == k_RegisterListWithAPSR ||
  826. Kind == k_DPRRegisterList || Kind == k_SPRRegisterList ||
  827. Kind == k_FPSRegisterListWithVPR ||
  828. Kind == k_FPDRegisterListWithVPR) &&
  829. "Invalid access!");
  830. return Registers;
  831. }
  832. const MCExpr *getImm() const {
  833. assert(isImm() && "Invalid access!");
  834. return Imm.Val;
  835. }
  836. const MCExpr *getConstantPoolImm() const {
  837. assert(isConstantPoolImm() && "Invalid access!");
  838. return Imm.Val;
  839. }
  840. unsigned getVectorIndex() const {
  841. assert(Kind == k_VectorIndex && "Invalid access!");
  842. return VectorIndex.Val;
  843. }
  844. ARM_MB::MemBOpt getMemBarrierOpt() const {
  845. assert(Kind == k_MemBarrierOpt && "Invalid access!");
  846. return MBOpt.Val;
  847. }
  848. ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
  849. assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
  850. return ISBOpt.Val;
  851. }
  852. ARM_TSB::TraceSyncBOpt getTraceSyncBarrierOpt() const {
  853. assert(Kind == k_TraceSyncBarrierOpt && "Invalid access!");
  854. return TSBOpt.Val;
  855. }
  856. ARM_PROC::IFlags getProcIFlags() const {
  857. assert(Kind == k_ProcIFlags && "Invalid access!");
  858. return IFlags.Val;
  859. }
  860. unsigned getMSRMask() const {
  861. assert(Kind == k_MSRMask && "Invalid access!");
  862. return MMask.Val;
  863. }
  864. unsigned getBankedReg() const {
  865. assert(Kind == k_BankedReg && "Invalid access!");
  866. return BankedReg.Val;
  867. }
  868. bool isCoprocNum() const { return Kind == k_CoprocNum; }
  869. bool isCoprocReg() const { return Kind == k_CoprocReg; }
  870. bool isCoprocOption() const { return Kind == k_CoprocOption; }
  871. bool isCondCode() const { return Kind == k_CondCode; }
  872. bool isVPTPred() const { return Kind == k_VPTPred; }
  873. bool isCCOut() const { return Kind == k_CCOut; }
  874. bool isITMask() const { return Kind == k_ITCondMask; }
  875. bool isITCondCode() const { return Kind == k_CondCode; }
  876. bool isImm() const override {
  877. return Kind == k_Immediate;
  878. }
  879. bool isARMBranchTarget() const {
  880. if (!isImm()) return false;
  881. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()))
  882. return CE->getValue() % 4 == 0;
  883. return true;
  884. }
  885. bool isThumbBranchTarget() const {
  886. if (!isImm()) return false;
  887. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()))
  888. return CE->getValue() % 2 == 0;
  889. return true;
  890. }
  891. // checks whether this operand is an unsigned offset which fits is a field
  892. // of specified width and scaled by a specific number of bits
  893. template<unsigned width, unsigned scale>
  894. bool isUnsignedOffset() const {
  895. if (!isImm()) return false;
  896. if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
  897. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
  898. int64_t Val = CE->getValue();
  899. int64_t Align = 1LL << scale;
  900. int64_t Max = Align * ((1LL << width) - 1);
  901. return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
  902. }
  903. return false;
  904. }
  905. // checks whether this operand is an signed offset which fits is a field
  906. // of specified width and scaled by a specific number of bits
  907. template<unsigned width, unsigned scale>
  908. bool isSignedOffset() const {
  909. if (!isImm()) return false;
  910. if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
  911. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
  912. int64_t Val = CE->getValue();
  913. int64_t Align = 1LL << scale;
  914. int64_t Max = Align * ((1LL << (width-1)) - 1);
  915. int64_t Min = -Align * (1LL << (width-1));
  916. return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
  917. }
  918. return false;
  919. }
  920. // checks whether this operand is an offset suitable for the LE /
  921. // LETP instructions in Arm v8.1M
  922. bool isLEOffset() const {
  923. if (!isImm()) return false;
  924. if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
  925. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
  926. int64_t Val = CE->getValue();
  927. return Val < 0 && Val >= -4094 && (Val & 1) == 0;
  928. }
  929. return false;
  930. }
  931. // checks whether this operand is a memory operand computed as an offset
  932. // applied to PC. the offset may have 8 bits of magnitude and is represented
  933. // with two bits of shift. textually it may be either [pc, #imm], #imm or
  934. // relocable expression...
  935. bool isThumbMemPC() const {
  936. int64_t Val = 0;
  937. if (isImm()) {
  938. if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
  939. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
  940. if (!CE) return false;
  941. Val = CE->getValue();
  942. }
  943. else if (isGPRMem()) {
  944. if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
  945. if(Memory.BaseRegNum != ARM::PC) return false;
  946. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
  947. Val = CE->getValue();
  948. else
  949. return false;
  950. }
  951. else return false;
  952. return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
  953. }
  954. bool isFPImm() const {
  955. if (!isImm()) return false;
  956. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  957. if (!CE) return false;
  958. int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
  959. return Val != -1;
  960. }
  961. template<int64_t N, int64_t M>
  962. bool isImmediate() const {
  963. if (!isImm()) return false;
  964. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  965. if (!CE) return false;
  966. int64_t Value = CE->getValue();
  967. return Value >= N && Value <= M;
  968. }
  969. template<int64_t N, int64_t M>
  970. bool isImmediateS4() const {
  971. if (!isImm()) return false;
  972. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  973. if (!CE) return false;
  974. int64_t Value = CE->getValue();
  975. return ((Value & 3) == 0) && Value >= N && Value <= M;
  976. }
  977. template<int64_t N, int64_t M>
  978. bool isImmediateS2() const {
  979. if (!isImm()) return false;
  980. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  981. if (!CE) return false;
  982. int64_t Value = CE->getValue();
  983. return ((Value & 1) == 0) && Value >= N && Value <= M;
  984. }
  985. bool isFBits16() const {
  986. return isImmediate<0, 17>();
  987. }
  988. bool isFBits32() const {
  989. return isImmediate<1, 33>();
  990. }
  991. bool isImm8s4() const {
  992. return isImmediateS4<-1020, 1020>();
  993. }
  994. bool isImm7s4() const {
  995. return isImmediateS4<-508, 508>();
  996. }
  997. bool isImm7Shift0() const {
  998. return isImmediate<-127, 127>();
  999. }
  1000. bool isImm7Shift1() const {
  1001. return isImmediateS2<-255, 255>();
  1002. }
  1003. bool isImm7Shift2() const {
  1004. return isImmediateS4<-511, 511>();
  1005. }
  1006. bool isImm7() const {
  1007. return isImmediate<-127, 127>();
  1008. }
  1009. bool isImm0_1020s4() const {
  1010. return isImmediateS4<0, 1020>();
  1011. }
  1012. bool isImm0_508s4() const {
  1013. return isImmediateS4<0, 508>();
  1014. }
  1015. bool isImm0_508s4Neg() const {
  1016. if (!isImm()) return false;
  1017. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1018. if (!CE) return false;
  1019. int64_t Value = -CE->getValue();
  1020. // explicitly exclude zero. we want that to use the normal 0_508 version.
  1021. return ((Value & 3) == 0) && Value > 0 && Value <= 508;
  1022. }
  1023. bool isImm0_4095Neg() const {
  1024. if (!isImm()) return false;
  1025. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1026. if (!CE) return false;
  1027. // isImm0_4095Neg is used with 32-bit immediates only.
  1028. // 32-bit immediates are zero extended to 64-bit when parsed,
  1029. // thus simple -CE->getValue() results in a big negative number,
  1030. // not a small positive number as intended
  1031. if ((CE->getValue() >> 32) > 0) return false;
  1032. uint32_t Value = -static_cast<uint32_t>(CE->getValue());
  1033. return Value > 0 && Value < 4096;
  1034. }
  1035. bool isImm0_7() const {
  1036. return isImmediate<0, 7>();
  1037. }
  1038. bool isImm1_16() const {
  1039. return isImmediate<1, 16>();
  1040. }
  1041. bool isImm1_32() const {
  1042. return isImmediate<1, 32>();
  1043. }
  1044. bool isImm8_255() const {
  1045. return isImmediate<8, 255>();
  1046. }
  1047. bool isImm256_65535Expr() const {
  1048. if (!isImm()) return false;
  1049. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1050. // If it's not a constant expression, it'll generate a fixup and be
  1051. // handled later.
  1052. if (!CE) return true;
  1053. int64_t Value = CE->getValue();
  1054. return Value >= 256 && Value < 65536;
  1055. }
  1056. bool isImm0_65535Expr() const {
  1057. if (!isImm()) return false;
  1058. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1059. // If it's not a constant expression, it'll generate a fixup and be
  1060. // handled later.
  1061. if (!CE) return true;
  1062. int64_t Value = CE->getValue();
  1063. return Value >= 0 && Value < 65536;
  1064. }
  1065. bool isImm24bit() const {
  1066. return isImmediate<0, 0xffffff + 1>();
  1067. }
  1068. bool isImmThumbSR() const {
  1069. return isImmediate<1, 33>();
  1070. }
  1071. template<int shift>
  1072. bool isExpImmValue(uint64_t Value) const {
  1073. uint64_t mask = (1 << shift) - 1;
  1074. if ((Value & mask) != 0 || (Value >> shift) > 0xff)
  1075. return false;
  1076. return true;
  1077. }
  1078. template<int shift>
  1079. bool isExpImm() const {
  1080. if (!isImm()) return false;
  1081. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1082. if (!CE) return false;
  1083. return isExpImmValue<shift>(CE->getValue());
  1084. }
  1085. template<int shift, int size>
  1086. bool isInvertedExpImm() const {
  1087. if (!isImm()) return false;
  1088. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1089. if (!CE) return false;
  1090. uint64_t OriginalValue = CE->getValue();
  1091. uint64_t InvertedValue = OriginalValue ^ (((uint64_t)1 << size) - 1);
  1092. return isExpImmValue<shift>(InvertedValue);
  1093. }
  1094. bool isPKHLSLImm() const {
  1095. return isImmediate<0, 32>();
  1096. }
  1097. bool isPKHASRImm() const {
  1098. return isImmediate<0, 33>();
  1099. }
  1100. bool isAdrLabel() const {
  1101. // If we have an immediate that's not a constant, treat it as a label
  1102. // reference needing a fixup.
  1103. if (isImm() && !isa<MCConstantExpr>(getImm()))
  1104. return true;
  1105. // If it is a constant, it must fit into a modified immediate encoding.
  1106. if (!isImm()) return false;
  1107. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1108. if (!CE) return false;
  1109. int64_t Value = CE->getValue();
  1110. return (ARM_AM::getSOImmVal(Value) != -1 ||
  1111. ARM_AM::getSOImmVal(-Value) != -1);
  1112. }
  1113. bool isT2SOImm() const {
  1114. // If we have an immediate that's not a constant, treat it as an expression
  1115. // needing a fixup.
  1116. if (isImm() && !isa<MCConstantExpr>(getImm())) {
  1117. // We want to avoid matching :upper16: and :lower16: as we want these
  1118. // expressions to match in isImm0_65535Expr()
  1119. const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(getImm());
  1120. return (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
  1121. ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16));
  1122. }
  1123. if (!isImm()) return false;
  1124. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1125. if (!CE) return false;
  1126. int64_t Value = CE->getValue();
  1127. return ARM_AM::getT2SOImmVal(Value) != -1;
  1128. }
  1129. bool isT2SOImmNot() const {
  1130. if (!isImm()) return false;
  1131. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1132. if (!CE) return false;
  1133. int64_t Value = CE->getValue();
  1134. return ARM_AM::getT2SOImmVal(Value) == -1 &&
  1135. ARM_AM::getT2SOImmVal(~Value) != -1;
  1136. }
  1137. bool isT2SOImmNeg() const {
  1138. if (!isImm()) return false;
  1139. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1140. if (!CE) return false;
  1141. int64_t Value = CE->getValue();
  1142. // Only use this when not representable as a plain so_imm.
  1143. return ARM_AM::getT2SOImmVal(Value) == -1 &&
  1144. ARM_AM::getT2SOImmVal(-Value) != -1;
  1145. }
  1146. bool isSetEndImm() const {
  1147. if (!isImm()) return false;
  1148. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1149. if (!CE) return false;
  1150. int64_t Value = CE->getValue();
  1151. return Value == 1 || Value == 0;
  1152. }
  1153. bool isReg() const override { return Kind == k_Register; }
  1154. bool isRegList() const { return Kind == k_RegisterList; }
  1155. bool isRegListWithAPSR() const {
  1156. return Kind == k_RegisterListWithAPSR || Kind == k_RegisterList;
  1157. }
  1158. bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
  1159. bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
  1160. bool isFPSRegListWithVPR() const { return Kind == k_FPSRegisterListWithVPR; }
  1161. bool isFPDRegListWithVPR() const { return Kind == k_FPDRegisterListWithVPR; }
  1162. bool isToken() const override { return Kind == k_Token; }
  1163. bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
  1164. bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
  1165. bool isTraceSyncBarrierOpt() const { return Kind == k_TraceSyncBarrierOpt; }
  1166. bool isMem() const override {
  1167. return isGPRMem() || isMVEMem();
  1168. }
  1169. bool isMVEMem() const {
  1170. if (Kind != k_Memory)
  1171. return false;
  1172. if (Memory.BaseRegNum &&
  1173. !ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Memory.BaseRegNum) &&
  1174. !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(Memory.BaseRegNum))
  1175. return false;
  1176. if (Memory.OffsetRegNum &&
  1177. !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(
  1178. Memory.OffsetRegNum))
  1179. return false;
  1180. return true;
  1181. }
  1182. bool isGPRMem() const {
  1183. if (Kind != k_Memory)
  1184. return false;
  1185. if (Memory.BaseRegNum &&
  1186. !ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Memory.BaseRegNum))
  1187. return false;
  1188. if (Memory.OffsetRegNum &&
  1189. !ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Memory.OffsetRegNum))
  1190. return false;
  1191. return true;
  1192. }
  1193. bool isShifterImm() const { return Kind == k_ShifterImmediate; }
  1194. bool isRegShiftedReg() const {
  1195. return Kind == k_ShiftedRegister &&
  1196. ARMMCRegisterClasses[ARM::GPRRegClassID].contains(
  1197. RegShiftedReg.SrcReg) &&
  1198. ARMMCRegisterClasses[ARM::GPRRegClassID].contains(
  1199. RegShiftedReg.ShiftReg);
  1200. }
  1201. bool isRegShiftedImm() const {
  1202. return Kind == k_ShiftedImmediate &&
  1203. ARMMCRegisterClasses[ARM::GPRRegClassID].contains(
  1204. RegShiftedImm.SrcReg);
  1205. }
  1206. bool isRotImm() const { return Kind == k_RotateImmediate; }
  1207. template<unsigned Min, unsigned Max>
  1208. bool isPowerTwoInRange() const {
  1209. if (!isImm()) return false;
  1210. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1211. if (!CE) return false;
  1212. int64_t Value = CE->getValue();
  1213. return Value > 0 && countPopulation((uint64_t)Value) == 1 &&
  1214. Value >= Min && Value <= Max;
  1215. }
  1216. bool isModImm() const { return Kind == k_ModifiedImmediate; }
  1217. bool isModImmNot() const {
  1218. if (!isImm()) return false;
  1219. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1220. if (!CE) return false;
  1221. int64_t Value = CE->getValue();
  1222. return ARM_AM::getSOImmVal(~Value) != -1;
  1223. }
  1224. bool isModImmNeg() const {
  1225. if (!isImm()) return false;
  1226. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1227. if (!CE) return false;
  1228. int64_t Value = CE->getValue();
  1229. return ARM_AM::getSOImmVal(Value) == -1 &&
  1230. ARM_AM::getSOImmVal(-Value) != -1;
  1231. }
  1232. bool isThumbModImmNeg1_7() const {
  1233. if (!isImm()) return false;
  1234. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1235. if (!CE) return false;
  1236. int32_t Value = -(int32_t)CE->getValue();
  1237. return 0 < Value && Value < 8;
  1238. }
  1239. bool isThumbModImmNeg8_255() const {
  1240. if (!isImm()) return false;
  1241. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1242. if (!CE) return false;
  1243. int32_t Value = -(int32_t)CE->getValue();
  1244. return 7 < Value && Value < 256;
  1245. }
  1246. bool isConstantPoolImm() const { return Kind == k_ConstantPoolImmediate; }
  1247. bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
  1248. bool isPostIdxRegShifted() const {
  1249. return Kind == k_PostIndexRegister &&
  1250. ARMMCRegisterClasses[ARM::GPRRegClassID].contains(PostIdxReg.RegNum);
  1251. }
  1252. bool isPostIdxReg() const {
  1253. return isPostIdxRegShifted() && PostIdxReg.ShiftTy == ARM_AM::no_shift;
  1254. }
  1255. bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
  1256. if (!isGPRMem())
  1257. return false;
  1258. // No offset of any kind.
  1259. return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
  1260. (alignOK || Memory.Alignment == Alignment);
  1261. }
  1262. bool isMemNoOffsetT2(bool alignOK = false, unsigned Alignment = 0) const {
  1263. if (!isGPRMem())
  1264. return false;
  1265. if (!ARMMCRegisterClasses[ARM::GPRnopcRegClassID].contains(
  1266. Memory.BaseRegNum))
  1267. return false;
  1268. // No offset of any kind.
  1269. return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
  1270. (alignOK || Memory.Alignment == Alignment);
  1271. }
  1272. bool isMemNoOffsetT2NoSp(bool alignOK = false, unsigned Alignment = 0) const {
  1273. if (!isGPRMem())
  1274. return false;
  1275. if (!ARMMCRegisterClasses[ARM::rGPRRegClassID].contains(
  1276. Memory.BaseRegNum))
  1277. return false;
  1278. // No offset of any kind.
  1279. return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
  1280. (alignOK || Memory.Alignment == Alignment);
  1281. }
  1282. bool isMemNoOffsetT(bool alignOK = false, unsigned Alignment = 0) const {
  1283. if (!isGPRMem())
  1284. return false;
  1285. if (!ARMMCRegisterClasses[ARM::tGPRRegClassID].contains(
  1286. Memory.BaseRegNum))
  1287. return false;
  1288. // No offset of any kind.
  1289. return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
  1290. (alignOK || Memory.Alignment == Alignment);
  1291. }
  1292. bool isMemPCRelImm12() const {
  1293. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1294. return false;
  1295. // Base register must be PC.
  1296. if (Memory.BaseRegNum != ARM::PC)
  1297. return false;
  1298. // Immediate offset in range [-4095, 4095].
  1299. if (!Memory.OffsetImm) return true;
  1300. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1301. int64_t Val = CE->getValue();
  1302. return (Val > -4096 && Val < 4096) ||
  1303. (Val == std::numeric_limits<int32_t>::min());
  1304. }
  1305. return false;
  1306. }
  1307. bool isAlignedMemory() const {
  1308. return isMemNoOffset(true);
  1309. }
  1310. bool isAlignedMemoryNone() const {
  1311. return isMemNoOffset(false, 0);
  1312. }
  1313. bool isDupAlignedMemoryNone() const {
  1314. return isMemNoOffset(false, 0);
  1315. }
  1316. bool isAlignedMemory16() const {
  1317. if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
  1318. return true;
  1319. return isMemNoOffset(false, 0);
  1320. }
  1321. bool isDupAlignedMemory16() const {
  1322. if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
  1323. return true;
  1324. return isMemNoOffset(false, 0);
  1325. }
  1326. bool isAlignedMemory32() const {
  1327. if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
  1328. return true;
  1329. return isMemNoOffset(false, 0);
  1330. }
  1331. bool isDupAlignedMemory32() const {
  1332. if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
  1333. return true;
  1334. return isMemNoOffset(false, 0);
  1335. }
  1336. bool isAlignedMemory64() const {
  1337. if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
  1338. return true;
  1339. return isMemNoOffset(false, 0);
  1340. }
  1341. bool isDupAlignedMemory64() const {
  1342. if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
  1343. return true;
  1344. return isMemNoOffset(false, 0);
  1345. }
  1346. bool isAlignedMemory64or128() const {
  1347. if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
  1348. return true;
  1349. if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
  1350. return true;
  1351. return isMemNoOffset(false, 0);
  1352. }
  1353. bool isDupAlignedMemory64or128() const {
  1354. if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
  1355. return true;
  1356. if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
  1357. return true;
  1358. return isMemNoOffset(false, 0);
  1359. }
  1360. bool isAlignedMemory64or128or256() const {
  1361. if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
  1362. return true;
  1363. if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
  1364. return true;
  1365. if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
  1366. return true;
  1367. return isMemNoOffset(false, 0);
  1368. }
  1369. bool isAddrMode2() const {
  1370. if (!isGPRMem() || Memory.Alignment != 0) return false;
  1371. // Check for register offset.
  1372. if (Memory.OffsetRegNum) return true;
  1373. // Immediate offset in range [-4095, 4095].
  1374. if (!Memory.OffsetImm) return true;
  1375. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1376. int64_t Val = CE->getValue();
  1377. return Val > -4096 && Val < 4096;
  1378. }
  1379. return false;
  1380. }
  1381. bool isAM2OffsetImm() const {
  1382. if (!isImm()) return false;
  1383. // Immediate offset in range [-4095, 4095].
  1384. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1385. if (!CE) return false;
  1386. int64_t Val = CE->getValue();
  1387. return (Val == std::numeric_limits<int32_t>::min()) ||
  1388. (Val > -4096 && Val < 4096);
  1389. }
  1390. bool isAddrMode3() const {
  1391. // If we have an immediate that's not a constant, treat it as a label
  1392. // reference needing a fixup. If it is a constant, it's something else
  1393. // and we reject it.
  1394. if (isImm() && !isa<MCConstantExpr>(getImm()))
  1395. return true;
  1396. if (!isGPRMem() || Memory.Alignment != 0) return false;
  1397. // No shifts are legal for AM3.
  1398. if (Memory.ShiftType != ARM_AM::no_shift) return false;
  1399. // Check for register offset.
  1400. if (Memory.OffsetRegNum) return true;
  1401. // Immediate offset in range [-255, 255].
  1402. if (!Memory.OffsetImm) return true;
  1403. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1404. int64_t Val = CE->getValue();
  1405. // The #-0 offset is encoded as std::numeric_limits<int32_t>::min(), and
  1406. // we have to check for this too.
  1407. return (Val > -256 && Val < 256) ||
  1408. Val == std::numeric_limits<int32_t>::min();
  1409. }
  1410. return false;
  1411. }
  1412. bool isAM3Offset() const {
  1413. if (isPostIdxReg())
  1414. return true;
  1415. if (!isImm())
  1416. return false;
  1417. // Immediate offset in range [-255, 255].
  1418. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1419. if (!CE) return false;
  1420. int64_t Val = CE->getValue();
  1421. // Special case, #-0 is std::numeric_limits<int32_t>::min().
  1422. return (Val > -256 && Val < 256) ||
  1423. Val == std::numeric_limits<int32_t>::min();
  1424. }
  1425. bool isAddrMode5() const {
  1426. // If we have an immediate that's not a constant, treat it as a label
  1427. // reference needing a fixup. If it is a constant, it's something else
  1428. // and we reject it.
  1429. if (isImm() && !isa<MCConstantExpr>(getImm()))
  1430. return true;
  1431. if (!isGPRMem() || Memory.Alignment != 0) return false;
  1432. // Check for register offset.
  1433. if (Memory.OffsetRegNum) return false;
  1434. // Immediate offset in range [-1020, 1020] and a multiple of 4.
  1435. if (!Memory.OffsetImm) return true;
  1436. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1437. int64_t Val = CE->getValue();
  1438. return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
  1439. Val == std::numeric_limits<int32_t>::min();
  1440. }
  1441. return false;
  1442. }
  1443. bool isAddrMode5FP16() const {
  1444. // If we have an immediate that's not a constant, treat it as a label
  1445. // reference needing a fixup. If it is a constant, it's something else
  1446. // and we reject it.
  1447. if (isImm() && !isa<MCConstantExpr>(getImm()))
  1448. return true;
  1449. if (!isGPRMem() || Memory.Alignment != 0) return false;
  1450. // Check for register offset.
  1451. if (Memory.OffsetRegNum) return false;
  1452. // Immediate offset in range [-510, 510] and a multiple of 2.
  1453. if (!Memory.OffsetImm) return true;
  1454. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1455. int64_t Val = CE->getValue();
  1456. return (Val >= -510 && Val <= 510 && ((Val & 1) == 0)) ||
  1457. Val == std::numeric_limits<int32_t>::min();
  1458. }
  1459. return false;
  1460. }
  1461. bool isMemTBB() const {
  1462. if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
  1463. Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
  1464. return false;
  1465. return true;
  1466. }
  1467. bool isMemTBH() const {
  1468. if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
  1469. Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
  1470. Memory.Alignment != 0 )
  1471. return false;
  1472. return true;
  1473. }
  1474. bool isMemRegOffset() const {
  1475. if (!isGPRMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
  1476. return false;
  1477. return true;
  1478. }
  1479. bool isT2MemRegOffset() const {
  1480. if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
  1481. Memory.Alignment != 0 || Memory.BaseRegNum == ARM::PC)
  1482. return false;
  1483. // Only lsl #{0, 1, 2, 3} allowed.
  1484. if (Memory.ShiftType == ARM_AM::no_shift)
  1485. return true;
  1486. if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
  1487. return false;
  1488. return true;
  1489. }
  1490. bool isMemThumbRR() const {
  1491. // Thumb reg+reg addressing is simple. Just two registers, a base and
  1492. // an offset. No shifts, negations or any other complicating factors.
  1493. if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative ||
  1494. Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
  1495. return false;
  1496. return isARMLowRegister(Memory.BaseRegNum) &&
  1497. (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
  1498. }
  1499. bool isMemThumbRIs4() const {
  1500. if (!isGPRMem() || Memory.OffsetRegNum != 0 ||
  1501. !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
  1502. return false;
  1503. // Immediate offset, multiple of 4 in range [0, 124].
  1504. if (!Memory.OffsetImm) return true;
  1505. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1506. int64_t Val = CE->getValue();
  1507. return Val >= 0 && Val <= 124 && (Val % 4) == 0;
  1508. }
  1509. return false;
  1510. }
  1511. bool isMemThumbRIs2() const {
  1512. if (!isGPRMem() || Memory.OffsetRegNum != 0 ||
  1513. !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
  1514. return false;
  1515. // Immediate offset, multiple of 4 in range [0, 62].
  1516. if (!Memory.OffsetImm) return true;
  1517. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1518. int64_t Val = CE->getValue();
  1519. return Val >= 0 && Val <= 62 && (Val % 2) == 0;
  1520. }
  1521. return false;
  1522. }
  1523. bool isMemThumbRIs1() const {
  1524. if (!isGPRMem() || Memory.OffsetRegNum != 0 ||
  1525. !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
  1526. return false;
  1527. // Immediate offset in range [0, 31].
  1528. if (!Memory.OffsetImm) return true;
  1529. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1530. int64_t Val = CE->getValue();
  1531. return Val >= 0 && Val <= 31;
  1532. }
  1533. return false;
  1534. }
  1535. bool isMemThumbSPI() const {
  1536. if (!isGPRMem() || Memory.OffsetRegNum != 0 ||
  1537. Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
  1538. return false;
  1539. // Immediate offset, multiple of 4 in range [0, 1020].
  1540. if (!Memory.OffsetImm) return true;
  1541. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1542. int64_t Val = CE->getValue();
  1543. return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
  1544. }
  1545. return false;
  1546. }
  1547. bool isMemImm8s4Offset() const {
  1548. // If we have an immediate that's not a constant, treat it as a label
  1549. // reference needing a fixup. If it is a constant, it's something else
  1550. // and we reject it.
  1551. if (isImm() && !isa<MCConstantExpr>(getImm()))
  1552. return true;
  1553. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1554. return false;
  1555. // Immediate offset a multiple of 4 in range [-1020, 1020].
  1556. if (!Memory.OffsetImm) return true;
  1557. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1558. int64_t Val = CE->getValue();
  1559. // Special case, #-0 is std::numeric_limits<int32_t>::min().
  1560. return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) ||
  1561. Val == std::numeric_limits<int32_t>::min();
  1562. }
  1563. return false;
  1564. }
  1565. bool isMemImm7s4Offset() const {
  1566. // If we have an immediate that's not a constant, treat it as a label
  1567. // reference needing a fixup. If it is a constant, it's something else
  1568. // and we reject it.
  1569. if (isImm() && !isa<MCConstantExpr>(getImm()))
  1570. return true;
  1571. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0 ||
  1572. !ARMMCRegisterClasses[ARM::GPRnopcRegClassID].contains(
  1573. Memory.BaseRegNum))
  1574. return false;
  1575. // Immediate offset a multiple of 4 in range [-508, 508].
  1576. if (!Memory.OffsetImm) return true;
  1577. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1578. int64_t Val = CE->getValue();
  1579. // Special case, #-0 is INT32_MIN.
  1580. return (Val >= -508 && Val <= 508 && (Val & 3) == 0) || Val == INT32_MIN;
  1581. }
  1582. return false;
  1583. }
  1584. bool isMemImm0_1020s4Offset() const {
  1585. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1586. return false;
  1587. // Immediate offset a multiple of 4 in range [0, 1020].
  1588. if (!Memory.OffsetImm) return true;
  1589. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1590. int64_t Val = CE->getValue();
  1591. return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
  1592. }
  1593. return false;
  1594. }
  1595. bool isMemImm8Offset() const {
  1596. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1597. return false;
  1598. // Base reg of PC isn't allowed for these encodings.
  1599. if (Memory.BaseRegNum == ARM::PC) return false;
  1600. // Immediate offset in range [-255, 255].
  1601. if (!Memory.OffsetImm) return true;
  1602. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1603. int64_t Val = CE->getValue();
  1604. return (Val == std::numeric_limits<int32_t>::min()) ||
  1605. (Val > -256 && Val < 256);
  1606. }
  1607. return false;
  1608. }
  1609. template<unsigned Bits, unsigned RegClassID>
  1610. bool isMemImm7ShiftedOffset() const {
  1611. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0 ||
  1612. !ARMMCRegisterClasses[RegClassID].contains(Memory.BaseRegNum))
  1613. return false;
  1614. // Expect an immediate offset equal to an element of the range
  1615. // [-127, 127], shifted left by Bits.
  1616. if (!Memory.OffsetImm) return true;
  1617. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1618. int64_t Val = CE->getValue();
  1619. // INT32_MIN is a special-case value (indicating the encoding with
  1620. // zero offset and the subtract bit set)
  1621. if (Val == INT32_MIN)
  1622. return true;
  1623. unsigned Divisor = 1U << Bits;
  1624. // Check that the low bits are zero
  1625. if (Val % Divisor != 0)
  1626. return false;
  1627. // Check that the remaining offset is within range.
  1628. Val /= Divisor;
  1629. return (Val >= -127 && Val <= 127);
  1630. }
  1631. return false;
  1632. }
  1633. template <int shift> bool isMemRegRQOffset() const {
  1634. if (!isMVEMem() || Memory.OffsetImm != nullptr || Memory.Alignment != 0)
  1635. return false;
  1636. if (!ARMMCRegisterClasses[ARM::GPRnopcRegClassID].contains(
  1637. Memory.BaseRegNum))
  1638. return false;
  1639. if (!ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(
  1640. Memory.OffsetRegNum))
  1641. return false;
  1642. if (shift == 0 && Memory.ShiftType != ARM_AM::no_shift)
  1643. return false;
  1644. if (shift > 0 &&
  1645. (Memory.ShiftType != ARM_AM::uxtw || Memory.ShiftImm != shift))
  1646. return false;
  1647. return true;
  1648. }
  1649. template <int shift> bool isMemRegQOffset() const {
  1650. if (!isMVEMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1651. return false;
  1652. if (!ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(
  1653. Memory.BaseRegNum))
  1654. return false;
  1655. if (!Memory.OffsetImm)
  1656. return true;
  1657. static_assert(shift < 56,
  1658. "Such that we dont shift by a value higher than 62");
  1659. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1660. int64_t Val = CE->getValue();
  1661. // The value must be a multiple of (1 << shift)
  1662. if ((Val & ((1U << shift) - 1)) != 0)
  1663. return false;
  1664. // And be in the right range, depending on the amount that it is shifted
  1665. // by. Shift 0, is equal to 7 unsigned bits, the sign bit is set
  1666. // separately.
  1667. int64_t Range = (1U << (7 + shift)) - 1;
  1668. return (Val == INT32_MIN) || (Val > -Range && Val < Range);
  1669. }
  1670. return false;
  1671. }
  1672. bool isMemPosImm8Offset() const {
  1673. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1674. return false;
  1675. // Immediate offset in range [0, 255].
  1676. if (!Memory.OffsetImm) return true;
  1677. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1678. int64_t Val = CE->getValue();
  1679. return Val >= 0 && Val < 256;
  1680. }
  1681. return false;
  1682. }
  1683. bool isMemNegImm8Offset() const {
  1684. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1685. return false;
  1686. // Base reg of PC isn't allowed for these encodings.
  1687. if (Memory.BaseRegNum == ARM::PC) return false;
  1688. // Immediate offset in range [-255, -1].
  1689. if (!Memory.OffsetImm) return false;
  1690. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1691. int64_t Val = CE->getValue();
  1692. return (Val == std::numeric_limits<int32_t>::min()) ||
  1693. (Val > -256 && Val < 0);
  1694. }
  1695. return false;
  1696. }
  1697. bool isMemUImm12Offset() const {
  1698. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1699. return false;
  1700. // Immediate offset in range [0, 4095].
  1701. if (!Memory.OffsetImm) return true;
  1702. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1703. int64_t Val = CE->getValue();
  1704. return (Val >= 0 && Val < 4096);
  1705. }
  1706. return false;
  1707. }
  1708. bool isMemImm12Offset() const {
  1709. // If we have an immediate that's not a constant, treat it as a label
  1710. // reference needing a fixup. If it is a constant, it's something else
  1711. // and we reject it.
  1712. if (isImm() && !isa<MCConstantExpr>(getImm()))
  1713. return true;
  1714. if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
  1715. return false;
  1716. // Immediate offset in range [-4095, 4095].
  1717. if (!Memory.OffsetImm) return true;
  1718. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  1719. int64_t Val = CE->getValue();
  1720. return (Val > -4096 && Val < 4096) ||
  1721. (Val == std::numeric_limits<int32_t>::min());
  1722. }
  1723. // If we have an immediate that's not a constant, treat it as a
  1724. // symbolic expression needing a fixup.
  1725. return true;
  1726. }
  1727. bool isConstPoolAsmImm() const {
  1728. // Delay processing of Constant Pool Immediate, this will turn into
  1729. // a constant. Match no other operand
  1730. return (isConstantPoolImm());
  1731. }
  1732. bool isPostIdxImm8() const {
  1733. if (!isImm()) return false;
  1734. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1735. if (!CE) return false;
  1736. int64_t Val = CE->getValue();
  1737. return (Val > -256 && Val < 256) ||
  1738. (Val == std::numeric_limits<int32_t>::min());
  1739. }
  1740. bool isPostIdxImm8s4() const {
  1741. if (!isImm()) return false;
  1742. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1743. if (!CE) return false;
  1744. int64_t Val = CE->getValue();
  1745. return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
  1746. (Val == std::numeric_limits<int32_t>::min());
  1747. }
  1748. bool isMSRMask() const { return Kind == k_MSRMask; }
  1749. bool isBankedReg() const { return Kind == k_BankedReg; }
  1750. bool isProcIFlags() const { return Kind == k_ProcIFlags; }
  1751. // NEON operands.
  1752. bool isSingleSpacedVectorList() const {
  1753. return Kind == k_VectorList && !VectorList.isDoubleSpaced;
  1754. }
  1755. bool isDoubleSpacedVectorList() const {
  1756. return Kind == k_VectorList && VectorList.isDoubleSpaced;
  1757. }
  1758. bool isVecListOneD() const {
  1759. if (!isSingleSpacedVectorList()) return false;
  1760. return VectorList.Count == 1;
  1761. }
  1762. bool isVecListTwoMQ() const {
  1763. return isSingleSpacedVectorList() && VectorList.Count == 2 &&
  1764. ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(
  1765. VectorList.RegNum);
  1766. }
  1767. bool isVecListDPair() const {
  1768. if (!isSingleSpacedVectorList()) return false;
  1769. return (ARMMCRegisterClasses[ARM::DPairRegClassID]
  1770. .contains(VectorList.RegNum));
  1771. }
  1772. bool isVecListThreeD() const {
  1773. if (!isSingleSpacedVectorList()) return false;
  1774. return VectorList.Count == 3;
  1775. }
  1776. bool isVecListFourD() const {
  1777. if (!isSingleSpacedVectorList()) return false;
  1778. return VectorList.Count == 4;
  1779. }
  1780. bool isVecListDPairSpaced() const {
  1781. if (Kind != k_VectorList) return false;
  1782. if (isSingleSpacedVectorList()) return false;
  1783. return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
  1784. .contains(VectorList.RegNum));
  1785. }
  1786. bool isVecListThreeQ() const {
  1787. if (!isDoubleSpacedVectorList()) return false;
  1788. return VectorList.Count == 3;
  1789. }
  1790. bool isVecListFourQ() const {
  1791. if (!isDoubleSpacedVectorList()) return false;
  1792. return VectorList.Count == 4;
  1793. }
  1794. bool isVecListFourMQ() const {
  1795. return isSingleSpacedVectorList() && VectorList.Count == 4 &&
  1796. ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(
  1797. VectorList.RegNum);
  1798. }
  1799. bool isSingleSpacedVectorAllLanes() const {
  1800. return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
  1801. }
  1802. bool isDoubleSpacedVectorAllLanes() const {
  1803. return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
  1804. }
  1805. bool isVecListOneDAllLanes() const {
  1806. if (!isSingleSpacedVectorAllLanes()) return false;
  1807. return VectorList.Count == 1;
  1808. }
  1809. bool isVecListDPairAllLanes() const {
  1810. if (!isSingleSpacedVectorAllLanes()) return false;
  1811. return (ARMMCRegisterClasses[ARM::DPairRegClassID]
  1812. .contains(VectorList.RegNum));
  1813. }
  1814. bool isVecListDPairSpacedAllLanes() const {
  1815. if (!isDoubleSpacedVectorAllLanes()) return false;
  1816. return VectorList.Count == 2;
  1817. }
  1818. bool isVecListThreeDAllLanes() const {
  1819. if (!isSingleSpacedVectorAllLanes()) return false;
  1820. return VectorList.Count == 3;
  1821. }
  1822. bool isVecListThreeQAllLanes() const {
  1823. if (!isDoubleSpacedVectorAllLanes()) return false;
  1824. return VectorList.Count == 3;
  1825. }
  1826. bool isVecListFourDAllLanes() const {
  1827. if (!isSingleSpacedVectorAllLanes()) return false;
  1828. return VectorList.Count == 4;
  1829. }
  1830. bool isVecListFourQAllLanes() const {
  1831. if (!isDoubleSpacedVectorAllLanes()) return false;
  1832. return VectorList.Count == 4;
  1833. }
  1834. bool isSingleSpacedVectorIndexed() const {
  1835. return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
  1836. }
  1837. bool isDoubleSpacedVectorIndexed() const {
  1838. return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
  1839. }
  1840. bool isVecListOneDByteIndexed() const {
  1841. if (!isSingleSpacedVectorIndexed()) return false;
  1842. return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
  1843. }
  1844. bool isVecListOneDHWordIndexed() const {
  1845. if (!isSingleSpacedVectorIndexed()) return false;
  1846. return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
  1847. }
  1848. bool isVecListOneDWordIndexed() const {
  1849. if (!isSingleSpacedVectorIndexed()) return false;
  1850. return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
  1851. }
  1852. bool isVecListTwoDByteIndexed() const {
  1853. if (!isSingleSpacedVectorIndexed()) return false;
  1854. return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
  1855. }
  1856. bool isVecListTwoDHWordIndexed() const {
  1857. if (!isSingleSpacedVectorIndexed()) return false;
  1858. return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
  1859. }
  1860. bool isVecListTwoQWordIndexed() const {
  1861. if (!isDoubleSpacedVectorIndexed()) return false;
  1862. return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
  1863. }
  1864. bool isVecListTwoQHWordIndexed() const {
  1865. if (!isDoubleSpacedVectorIndexed()) return false;
  1866. return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
  1867. }
  1868. bool isVecListTwoDWordIndexed() const {
  1869. if (!isSingleSpacedVectorIndexed()) return false;
  1870. return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
  1871. }
  1872. bool isVecListThreeDByteIndexed() const {
  1873. if (!isSingleSpacedVectorIndexed()) return false;
  1874. return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
  1875. }
  1876. bool isVecListThreeDHWordIndexed() const {
  1877. if (!isSingleSpacedVectorIndexed()) return false;
  1878. return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
  1879. }
  1880. bool isVecListThreeQWordIndexed() const {
  1881. if (!isDoubleSpacedVectorIndexed()) return false;
  1882. return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
  1883. }
  1884. bool isVecListThreeQHWordIndexed() const {
  1885. if (!isDoubleSpacedVectorIndexed()) return false;
  1886. return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
  1887. }
  1888. bool isVecListThreeDWordIndexed() const {
  1889. if (!isSingleSpacedVectorIndexed()) return false;
  1890. return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
  1891. }
  1892. bool isVecListFourDByteIndexed() const {
  1893. if (!isSingleSpacedVectorIndexed()) return false;
  1894. return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
  1895. }
  1896. bool isVecListFourDHWordIndexed() const {
  1897. if (!isSingleSpacedVectorIndexed()) return false;
  1898. return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
  1899. }
  1900. bool isVecListFourQWordIndexed() const {
  1901. if (!isDoubleSpacedVectorIndexed()) return false;
  1902. return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
  1903. }
  1904. bool isVecListFourQHWordIndexed() const {
  1905. if (!isDoubleSpacedVectorIndexed()) return false;
  1906. return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
  1907. }
  1908. bool isVecListFourDWordIndexed() const {
  1909. if (!isSingleSpacedVectorIndexed()) return false;
  1910. return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
  1911. }
  1912. bool isVectorIndex() const { return Kind == k_VectorIndex; }
  1913. template <unsigned NumLanes>
  1914. bool isVectorIndexInRange() const {
  1915. if (Kind != k_VectorIndex) return false;
  1916. return VectorIndex.Val < NumLanes;
  1917. }
  1918. bool isVectorIndex8() const { return isVectorIndexInRange<8>(); }
  1919. bool isVectorIndex16() const { return isVectorIndexInRange<4>(); }
  1920. bool isVectorIndex32() const { return isVectorIndexInRange<2>(); }
  1921. bool isVectorIndex64() const { return isVectorIndexInRange<1>(); }
  1922. template<int PermittedValue, int OtherPermittedValue>
  1923. bool isMVEPairVectorIndex() const {
  1924. if (Kind != k_VectorIndex) return false;
  1925. return VectorIndex.Val == PermittedValue ||
  1926. VectorIndex.Val == OtherPermittedValue;
  1927. }
  1928. bool isNEONi8splat() const {
  1929. if (!isImm()) return false;
  1930. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1931. // Must be a constant.
  1932. if (!CE) return false;
  1933. int64_t Value = CE->getValue();
  1934. // i8 value splatted across 8 bytes. The immediate is just the 8 byte
  1935. // value.
  1936. return Value >= 0 && Value < 256;
  1937. }
  1938. bool isNEONi16splat() const {
  1939. if (isNEONByteReplicate(2))
  1940. return false; // Leave that for bytes replication and forbid by default.
  1941. if (!isImm())
  1942. return false;
  1943. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1944. // Must be a constant.
  1945. if (!CE) return false;
  1946. unsigned Value = CE->getValue();
  1947. return ARM_AM::isNEONi16splat(Value);
  1948. }
  1949. bool isNEONi16splatNot() const {
  1950. if (!isImm())
  1951. return false;
  1952. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1953. // Must be a constant.
  1954. if (!CE) return false;
  1955. unsigned Value = CE->getValue();
  1956. return ARM_AM::isNEONi16splat(~Value & 0xffff);
  1957. }
  1958. bool isNEONi32splat() const {
  1959. if (isNEONByteReplicate(4))
  1960. return false; // Leave that for bytes replication and forbid by default.
  1961. if (!isImm())
  1962. return false;
  1963. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1964. // Must be a constant.
  1965. if (!CE) return false;
  1966. unsigned Value = CE->getValue();
  1967. return ARM_AM::isNEONi32splat(Value);
  1968. }
  1969. bool isNEONi32splatNot() const {
  1970. if (!isImm())
  1971. return false;
  1972. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1973. // Must be a constant.
  1974. if (!CE) return false;
  1975. unsigned Value = CE->getValue();
  1976. return ARM_AM::isNEONi32splat(~Value);
  1977. }
  1978. static bool isValidNEONi32vmovImm(int64_t Value) {
  1979. // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
  1980. // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
  1981. return ((Value & 0xffffffffffffff00) == 0) ||
  1982. ((Value & 0xffffffffffff00ff) == 0) ||
  1983. ((Value & 0xffffffffff00ffff) == 0) ||
  1984. ((Value & 0xffffffff00ffffff) == 0) ||
  1985. ((Value & 0xffffffffffff00ff) == 0xff) ||
  1986. ((Value & 0xffffffffff00ffff) == 0xffff);
  1987. }
  1988. bool isNEONReplicate(unsigned Width, unsigned NumElems, bool Inv) const {
  1989. assert((Width == 8 || Width == 16 || Width == 32) &&
  1990. "Invalid element width");
  1991. assert(NumElems * Width <= 64 && "Invalid result width");
  1992. if (!isImm())
  1993. return false;
  1994. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  1995. // Must be a constant.
  1996. if (!CE)
  1997. return false;
  1998. int64_t Value = CE->getValue();
  1999. if (!Value)
  2000. return false; // Don't bother with zero.
  2001. if (Inv)
  2002. Value = ~Value;
  2003. uint64_t Mask = (1ull << Width) - 1;
  2004. uint64_t Elem = Value & Mask;
  2005. if (Width == 16 && (Elem & 0x00ff) != 0 && (Elem & 0xff00) != 0)
  2006. return false;
  2007. if (Width == 32 && !isValidNEONi32vmovImm(Elem))
  2008. return false;
  2009. for (unsigned i = 1; i < NumElems; ++i) {
  2010. Value >>= Width;
  2011. if ((Value & Mask) != Elem)
  2012. return false;
  2013. }
  2014. return true;
  2015. }
  2016. bool isNEONByteReplicate(unsigned NumBytes) const {
  2017. return isNEONReplicate(8, NumBytes, false);
  2018. }
  2019. static void checkNeonReplicateArgs(unsigned FromW, unsigned ToW) {
  2020. assert((FromW == 8 || FromW == 16 || FromW == 32) &&
  2021. "Invalid source width");
  2022. assert((ToW == 16 || ToW == 32 || ToW == 64) &&
  2023. "Invalid destination width");
  2024. assert(FromW < ToW && "ToW is not less than FromW");
  2025. }
  2026. template<unsigned FromW, unsigned ToW>
  2027. bool isNEONmovReplicate() const {
  2028. checkNeonReplicateArgs(FromW, ToW);
  2029. if (ToW == 64 && isNEONi64splat())
  2030. return false;
  2031. return isNEONReplicate(FromW, ToW / FromW, false);
  2032. }
  2033. template<unsigned FromW, unsigned ToW>
  2034. bool isNEONinvReplicate() const {
  2035. checkNeonReplicateArgs(FromW, ToW);
  2036. return isNEONReplicate(FromW, ToW / FromW, true);
  2037. }
  2038. bool isNEONi32vmov() const {
  2039. if (isNEONByteReplicate(4))
  2040. return false; // Let it to be classified as byte-replicate case.
  2041. if (!isImm())
  2042. return false;
  2043. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2044. // Must be a constant.
  2045. if (!CE)
  2046. return false;
  2047. return isValidNEONi32vmovImm(CE->getValue());
  2048. }
  2049. bool isNEONi32vmovNeg() const {
  2050. if (!isImm()) return false;
  2051. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2052. // Must be a constant.
  2053. if (!CE) return false;
  2054. return isValidNEONi32vmovImm(~CE->getValue());
  2055. }
  2056. bool isNEONi64splat() const {
  2057. if (!isImm()) return false;
  2058. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2059. // Must be a constant.
  2060. if (!CE) return false;
  2061. uint64_t Value = CE->getValue();
  2062. // i64 value with each byte being either 0 or 0xff.
  2063. for (unsigned i = 0; i < 8; ++i, Value >>= 8)
  2064. if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
  2065. return true;
  2066. }
  2067. template<int64_t Angle, int64_t Remainder>
  2068. bool isComplexRotation() const {
  2069. if (!isImm()) return false;
  2070. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2071. if (!CE) return false;
  2072. uint64_t Value = CE->getValue();
  2073. return (Value % Angle == Remainder && Value <= 270);
  2074. }
  2075. bool isMVELongShift() const {
  2076. if (!isImm()) return false;
  2077. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2078. // Must be a constant.
  2079. if (!CE) return false;
  2080. uint64_t Value = CE->getValue();
  2081. return Value >= 1 && Value <= 32;
  2082. }
  2083. bool isMveSaturateOp() const {
  2084. if (!isImm()) return false;
  2085. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2086. if (!CE) return false;
  2087. uint64_t Value = CE->getValue();
  2088. return Value == 48 || Value == 64;
  2089. }
  2090. bool isITCondCodeNoAL() const {
  2091. if (!isITCondCode()) return false;
  2092. ARMCC::CondCodes CC = getCondCode();
  2093. return CC != ARMCC::AL;
  2094. }
  2095. bool isITCondCodeRestrictedI() const {
  2096. if (!isITCondCode())
  2097. return false;
  2098. ARMCC::CondCodes CC = getCondCode();
  2099. return CC == ARMCC::EQ || CC == ARMCC::NE;
  2100. }
  2101. bool isITCondCodeRestrictedS() const {
  2102. if (!isITCondCode())
  2103. return false;
  2104. ARMCC::CondCodes CC = getCondCode();
  2105. return CC == ARMCC::LT || CC == ARMCC::GT || CC == ARMCC::LE ||
  2106. CC == ARMCC::GE;
  2107. }
  2108. bool isITCondCodeRestrictedU() const {
  2109. if (!isITCondCode())
  2110. return false;
  2111. ARMCC::CondCodes CC = getCondCode();
  2112. return CC == ARMCC::HS || CC == ARMCC::HI;
  2113. }
  2114. bool isITCondCodeRestrictedFP() const {
  2115. if (!isITCondCode())
  2116. return false;
  2117. ARMCC::CondCodes CC = getCondCode();
  2118. return CC == ARMCC::EQ || CC == ARMCC::NE || CC == ARMCC::LT ||
  2119. CC == ARMCC::GT || CC == ARMCC::LE || CC == ARMCC::GE;
  2120. }
  2121. void addExpr(MCInst &Inst, const MCExpr *Expr) const {
  2122. // Add as immediates when possible. Null MCExpr = 0.
  2123. if (!Expr)
  2124. Inst.addOperand(MCOperand::createImm(0));
  2125. else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
  2126. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2127. else
  2128. Inst.addOperand(MCOperand::createExpr(Expr));
  2129. }
  2130. void addARMBranchTargetOperands(MCInst &Inst, unsigned N) const {
  2131. assert(N == 1 && "Invalid number of operands!");
  2132. addExpr(Inst, getImm());
  2133. }
  2134. void addThumbBranchTargetOperands(MCInst &Inst, unsigned N) const {
  2135. assert(N == 1 && "Invalid number of operands!");
  2136. addExpr(Inst, getImm());
  2137. }
  2138. void addCondCodeOperands(MCInst &Inst, unsigned N) const {
  2139. assert(N == 2 && "Invalid number of operands!");
  2140. Inst.addOperand(MCOperand::createImm(unsigned(getCondCode())));
  2141. unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
  2142. Inst.addOperand(MCOperand::createReg(RegNum));
  2143. }
  2144. void addVPTPredNOperands(MCInst &Inst, unsigned N) const {
  2145. assert(N == 3 && "Invalid number of operands!");
  2146. Inst.addOperand(MCOperand::createImm(unsigned(getVPTPred())));
  2147. unsigned RegNum = getVPTPred() == ARMVCC::None ? 0: ARM::P0;
  2148. Inst.addOperand(MCOperand::createReg(RegNum));
  2149. Inst.addOperand(MCOperand::createReg(0));
  2150. }
  2151. void addVPTPredROperands(MCInst &Inst, unsigned N) const {
  2152. assert(N == 4 && "Invalid number of operands!");
  2153. addVPTPredNOperands(Inst, N-1);
  2154. unsigned RegNum;
  2155. if (getVPTPred() == ARMVCC::None) {
  2156. RegNum = 0;
  2157. } else {
  2158. unsigned NextOpIndex = Inst.getNumOperands();
  2159. const MCInstrDesc &MCID = ARMInsts[Inst.getOpcode()];
  2160. int TiedOp = MCID.getOperandConstraint(NextOpIndex, MCOI::TIED_TO);
  2161. assert(TiedOp >= 0 &&
  2162. "Inactive register in vpred_r is not tied to an output!");
  2163. RegNum = Inst.getOperand(TiedOp).getReg();
  2164. }
  2165. Inst.addOperand(MCOperand::createReg(RegNum));
  2166. }
  2167. void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
  2168. assert(N == 1 && "Invalid number of operands!");
  2169. Inst.addOperand(MCOperand::createImm(getCoproc()));
  2170. }
  2171. void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
  2172. assert(N == 1 && "Invalid number of operands!");
  2173. Inst.addOperand(MCOperand::createImm(getCoproc()));
  2174. }
  2175. void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
  2176. assert(N == 1 && "Invalid number of operands!");
  2177. Inst.addOperand(MCOperand::createImm(CoprocOption.Val));
  2178. }
  2179. void addITMaskOperands(MCInst &Inst, unsigned N) const {
  2180. assert(N == 1 && "Invalid number of operands!");
  2181. Inst.addOperand(MCOperand::createImm(ITMask.Mask));
  2182. }
  2183. void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
  2184. assert(N == 1 && "Invalid number of operands!");
  2185. Inst.addOperand(MCOperand::createImm(unsigned(getCondCode())));
  2186. }
  2187. void addITCondCodeInvOperands(MCInst &Inst, unsigned N) const {
  2188. assert(N == 1 && "Invalid number of operands!");
  2189. Inst.addOperand(MCOperand::createImm(unsigned(ARMCC::getOppositeCondition(getCondCode()))));
  2190. }
  2191. void addCCOutOperands(MCInst &Inst, unsigned N) const {
  2192. assert(N == 1 && "Invalid number of operands!");
  2193. Inst.addOperand(MCOperand::createReg(getReg()));
  2194. }
  2195. void addRegOperands(MCInst &Inst, unsigned N) const {
  2196. assert(N == 1 && "Invalid number of operands!");
  2197. Inst.addOperand(MCOperand::createReg(getReg()));
  2198. }
  2199. void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
  2200. assert(N == 3 && "Invalid number of operands!");
  2201. assert(isRegShiftedReg() &&
  2202. "addRegShiftedRegOperands() on non-RegShiftedReg!");
  2203. Inst.addOperand(MCOperand::createReg(RegShiftedReg.SrcReg));
  2204. Inst.addOperand(MCOperand::createReg(RegShiftedReg.ShiftReg));
  2205. Inst.addOperand(MCOperand::createImm(
  2206. ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
  2207. }
  2208. void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
  2209. assert(N == 2 && "Invalid number of operands!");
  2210. assert(isRegShiftedImm() &&
  2211. "addRegShiftedImmOperands() on non-RegShiftedImm!");
  2212. Inst.addOperand(MCOperand::createReg(RegShiftedImm.SrcReg));
  2213. // Shift of #32 is encoded as 0 where permitted
  2214. unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
  2215. Inst.addOperand(MCOperand::createImm(
  2216. ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
  2217. }
  2218. void addShifterImmOperands(MCInst &Inst, unsigned N) const {
  2219. assert(N == 1 && "Invalid number of operands!");
  2220. Inst.addOperand(MCOperand::createImm((ShifterImm.isASR << 5) |
  2221. ShifterImm.Imm));
  2222. }
  2223. void addRegListOperands(MCInst &Inst, unsigned N) const {
  2224. assert(N == 1 && "Invalid number of operands!");
  2225. const SmallVectorImpl<unsigned> &RegList = getRegList();
  2226. for (unsigned Reg : RegList)
  2227. Inst.addOperand(MCOperand::createReg(Reg));
  2228. }
  2229. void addRegListWithAPSROperands(MCInst &Inst, unsigned N) const {
  2230. assert(N == 1 && "Invalid number of operands!");
  2231. const SmallVectorImpl<unsigned> &RegList = getRegList();
  2232. for (unsigned Reg : RegList)
  2233. Inst.addOperand(MCOperand::createReg(Reg));
  2234. }
  2235. void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
  2236. addRegListOperands(Inst, N);
  2237. }
  2238. void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
  2239. addRegListOperands(Inst, N);
  2240. }
  2241. void addFPSRegListWithVPROperands(MCInst &Inst, unsigned N) const {
  2242. addRegListOperands(Inst, N);
  2243. }
  2244. void addFPDRegListWithVPROperands(MCInst &Inst, unsigned N) const {
  2245. addRegListOperands(Inst, N);
  2246. }
  2247. void addRotImmOperands(MCInst &Inst, unsigned N) const {
  2248. assert(N == 1 && "Invalid number of operands!");
  2249. // Encoded as val>>3. The printer handles display as 8, 16, 24.
  2250. Inst.addOperand(MCOperand::createImm(RotImm.Imm >> 3));
  2251. }
  2252. void addModImmOperands(MCInst &Inst, unsigned N) const {
  2253. assert(N == 1 && "Invalid number of operands!");
  2254. // Support for fixups (MCFixup)
  2255. if (isImm())
  2256. return addImmOperands(Inst, N);
  2257. Inst.addOperand(MCOperand::createImm(ModImm.Bits | (ModImm.Rot << 7)));
  2258. }
  2259. void addModImmNotOperands(MCInst &Inst, unsigned N) const {
  2260. assert(N == 1 && "Invalid number of operands!");
  2261. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2262. uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
  2263. Inst.addOperand(MCOperand::createImm(Enc));
  2264. }
  2265. void addModImmNegOperands(MCInst &Inst, unsigned N) const {
  2266. assert(N == 1 && "Invalid number of operands!");
  2267. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2268. uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
  2269. Inst.addOperand(MCOperand::createImm(Enc));
  2270. }
  2271. void addThumbModImmNeg8_255Operands(MCInst &Inst, unsigned N) const {
  2272. assert(N == 1 && "Invalid number of operands!");
  2273. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2274. uint32_t Val = -CE->getValue();
  2275. Inst.addOperand(MCOperand::createImm(Val));
  2276. }
  2277. void addThumbModImmNeg1_7Operands(MCInst &Inst, unsigned N) const {
  2278. assert(N == 1 && "Invalid number of operands!");
  2279. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2280. uint32_t Val = -CE->getValue();
  2281. Inst.addOperand(MCOperand::createImm(Val));
  2282. }
  2283. void addBitfieldOperands(MCInst &Inst, unsigned N) const {
  2284. assert(N == 1 && "Invalid number of operands!");
  2285. // Munge the lsb/width into a bitfield mask.
  2286. unsigned lsb = Bitfield.LSB;
  2287. unsigned width = Bitfield.Width;
  2288. // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
  2289. uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
  2290. (32 - (lsb + width)));
  2291. Inst.addOperand(MCOperand::createImm(Mask));
  2292. }
  2293. void addImmOperands(MCInst &Inst, unsigned N) const {
  2294. assert(N == 1 && "Invalid number of operands!");
  2295. addExpr(Inst, getImm());
  2296. }
  2297. void addFBits16Operands(MCInst &Inst, unsigned N) const {
  2298. assert(N == 1 && "Invalid number of operands!");
  2299. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2300. Inst.addOperand(MCOperand::createImm(16 - CE->getValue()));
  2301. }
  2302. void addFBits32Operands(MCInst &Inst, unsigned N) const {
  2303. assert(N == 1 && "Invalid number of operands!");
  2304. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2305. Inst.addOperand(MCOperand::createImm(32 - CE->getValue()));
  2306. }
  2307. void addFPImmOperands(MCInst &Inst, unsigned N) const {
  2308. assert(N == 1 && "Invalid number of operands!");
  2309. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2310. int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
  2311. Inst.addOperand(MCOperand::createImm(Val));
  2312. }
  2313. void addImm8s4Operands(MCInst &Inst, unsigned N) const {
  2314. assert(N == 1 && "Invalid number of operands!");
  2315. // FIXME: We really want to scale the value here, but the LDRD/STRD
  2316. // instruction don't encode operands that way yet.
  2317. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2318. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2319. }
  2320. void addImm7s4Operands(MCInst &Inst, unsigned N) const {
  2321. assert(N == 1 && "Invalid number of operands!");
  2322. // FIXME: We really want to scale the value here, but the VSTR/VLDR_VSYSR
  2323. // instruction don't encode operands that way yet.
  2324. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2325. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2326. }
  2327. void addImm7Shift0Operands(MCInst &Inst, unsigned N) const {
  2328. assert(N == 1 && "Invalid number of operands!");
  2329. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2330. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2331. }
  2332. void addImm7Shift1Operands(MCInst &Inst, unsigned N) const {
  2333. assert(N == 1 && "Invalid number of operands!");
  2334. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2335. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2336. }
  2337. void addImm7Shift2Operands(MCInst &Inst, unsigned N) const {
  2338. assert(N == 1 && "Invalid number of operands!");
  2339. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2340. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2341. }
  2342. void addImm7Operands(MCInst &Inst, unsigned N) const {
  2343. assert(N == 1 && "Invalid number of operands!");
  2344. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2345. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2346. }
  2347. void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
  2348. assert(N == 1 && "Invalid number of operands!");
  2349. // The immediate is scaled by four in the encoding and is stored
  2350. // in the MCInst as such. Lop off the low two bits here.
  2351. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2352. Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
  2353. }
  2354. void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
  2355. assert(N == 1 && "Invalid number of operands!");
  2356. // The immediate is scaled by four in the encoding and is stored
  2357. // in the MCInst as such. Lop off the low two bits here.
  2358. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2359. Inst.addOperand(MCOperand::createImm(-(CE->getValue() / 4)));
  2360. }
  2361. void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
  2362. assert(N == 1 && "Invalid number of operands!");
  2363. // The immediate is scaled by four in the encoding and is stored
  2364. // in the MCInst as such. Lop off the low two bits here.
  2365. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2366. Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
  2367. }
  2368. void addImm1_16Operands(MCInst &Inst, unsigned N) const {
  2369. assert(N == 1 && "Invalid number of operands!");
  2370. // The constant encodes as the immediate-1, and we store in the instruction
  2371. // the bits as encoded, so subtract off one here.
  2372. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2373. Inst.addOperand(MCOperand::createImm(CE->getValue() - 1));
  2374. }
  2375. void addImm1_32Operands(MCInst &Inst, unsigned N) const {
  2376. assert(N == 1 && "Invalid number of operands!");
  2377. // The constant encodes as the immediate-1, and we store in the instruction
  2378. // the bits as encoded, so subtract off one here.
  2379. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2380. Inst.addOperand(MCOperand::createImm(CE->getValue() - 1));
  2381. }
  2382. void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
  2383. assert(N == 1 && "Invalid number of operands!");
  2384. // The constant encodes as the immediate, except for 32, which encodes as
  2385. // zero.
  2386. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2387. unsigned Imm = CE->getValue();
  2388. Inst.addOperand(MCOperand::createImm((Imm == 32 ? 0 : Imm)));
  2389. }
  2390. void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
  2391. assert(N == 1 && "Invalid number of operands!");
  2392. // An ASR value of 32 encodes as 0, so that's how we want to add it to
  2393. // the instruction as well.
  2394. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2395. int Val = CE->getValue();
  2396. Inst.addOperand(MCOperand::createImm(Val == 32 ? 0 : Val));
  2397. }
  2398. void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
  2399. assert(N == 1 && "Invalid number of operands!");
  2400. // The operand is actually a t2_so_imm, but we have its bitwise
  2401. // negation in the assembly source, so twiddle it here.
  2402. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2403. Inst.addOperand(MCOperand::createImm(~(uint32_t)CE->getValue()));
  2404. }
  2405. void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
  2406. assert(N == 1 && "Invalid number of operands!");
  2407. // The operand is actually a t2_so_imm, but we have its
  2408. // negation in the assembly source, so twiddle it here.
  2409. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2410. Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue()));
  2411. }
  2412. void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
  2413. assert(N == 1 && "Invalid number of operands!");
  2414. // The operand is actually an imm0_4095, but we have its
  2415. // negation in the assembly source, so twiddle it here.
  2416. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2417. Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue()));
  2418. }
  2419. void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
  2420. if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
  2421. Inst.addOperand(MCOperand::createImm(CE->getValue() >> 2));
  2422. return;
  2423. }
  2424. const MCSymbolRefExpr *SR = cast<MCSymbolRefExpr>(Imm.Val);
  2425. Inst.addOperand(MCOperand::createExpr(SR));
  2426. }
  2427. void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
  2428. assert(N == 1 && "Invalid number of operands!");
  2429. if (isImm()) {
  2430. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2431. if (CE) {
  2432. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2433. return;
  2434. }
  2435. const MCSymbolRefExpr *SR = cast<MCSymbolRefExpr>(Imm.Val);
  2436. Inst.addOperand(MCOperand::createExpr(SR));
  2437. return;
  2438. }
  2439. assert(isGPRMem() && "Unknown value type!");
  2440. assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
  2441. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
  2442. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2443. else
  2444. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2445. }
  2446. void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
  2447. assert(N == 1 && "Invalid number of operands!");
  2448. Inst.addOperand(MCOperand::createImm(unsigned(getMemBarrierOpt())));
  2449. }
  2450. void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
  2451. assert(N == 1 && "Invalid number of operands!");
  2452. Inst.addOperand(MCOperand::createImm(unsigned(getInstSyncBarrierOpt())));
  2453. }
  2454. void addTraceSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
  2455. assert(N == 1 && "Invalid number of operands!");
  2456. Inst.addOperand(MCOperand::createImm(unsigned(getTraceSyncBarrierOpt())));
  2457. }
  2458. void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
  2459. assert(N == 1 && "Invalid number of operands!");
  2460. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2461. }
  2462. void addMemNoOffsetT2Operands(MCInst &Inst, unsigned N) const {
  2463. assert(N == 1 && "Invalid number of operands!");
  2464. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2465. }
  2466. void addMemNoOffsetT2NoSpOperands(MCInst &Inst, unsigned N) const {
  2467. assert(N == 1 && "Invalid number of operands!");
  2468. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2469. }
  2470. void addMemNoOffsetTOperands(MCInst &Inst, unsigned N) const {
  2471. assert(N == 1 && "Invalid number of operands!");
  2472. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2473. }
  2474. void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
  2475. assert(N == 1 && "Invalid number of operands!");
  2476. if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
  2477. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2478. else
  2479. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2480. }
  2481. void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
  2482. assert(N == 1 && "Invalid number of operands!");
  2483. assert(isImm() && "Not an immediate!");
  2484. // If we have an immediate that's not a constant, treat it as a label
  2485. // reference needing a fixup.
  2486. if (!isa<MCConstantExpr>(getImm())) {
  2487. Inst.addOperand(MCOperand::createExpr(getImm()));
  2488. return;
  2489. }
  2490. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2491. int Val = CE->getValue();
  2492. Inst.addOperand(MCOperand::createImm(Val));
  2493. }
  2494. void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
  2495. assert(N == 2 && "Invalid number of operands!");
  2496. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2497. Inst.addOperand(MCOperand::createImm(Memory.Alignment));
  2498. }
  2499. void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
  2500. addAlignedMemoryOperands(Inst, N);
  2501. }
  2502. void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
  2503. addAlignedMemoryOperands(Inst, N);
  2504. }
  2505. void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
  2506. addAlignedMemoryOperands(Inst, N);
  2507. }
  2508. void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
  2509. addAlignedMemoryOperands(Inst, N);
  2510. }
  2511. void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
  2512. addAlignedMemoryOperands(Inst, N);
  2513. }
  2514. void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
  2515. addAlignedMemoryOperands(Inst, N);
  2516. }
  2517. void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
  2518. addAlignedMemoryOperands(Inst, N);
  2519. }
  2520. void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
  2521. addAlignedMemoryOperands(Inst, N);
  2522. }
  2523. void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
  2524. addAlignedMemoryOperands(Inst, N);
  2525. }
  2526. void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
  2527. addAlignedMemoryOperands(Inst, N);
  2528. }
  2529. void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
  2530. addAlignedMemoryOperands(Inst, N);
  2531. }
  2532. void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
  2533. assert(N == 3 && "Invalid number of operands!");
  2534. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2535. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2536. if (!Memory.OffsetRegNum) {
  2537. if (!Memory.OffsetImm)
  2538. Inst.addOperand(MCOperand::createImm(0));
  2539. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  2540. int32_t Val = CE->getValue();
  2541. ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
  2542. // Special case for #-0
  2543. if (Val == std::numeric_limits<int32_t>::min())
  2544. Val = 0;
  2545. if (Val < 0)
  2546. Val = -Val;
  2547. Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
  2548. Inst.addOperand(MCOperand::createImm(Val));
  2549. } else
  2550. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2551. } else {
  2552. // For register offset, we encode the shift type and negation flag
  2553. // here.
  2554. int32_t Val =
  2555. ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
  2556. Memory.ShiftImm, Memory.ShiftType);
  2557. Inst.addOperand(MCOperand::createImm(Val));
  2558. }
  2559. }
  2560. void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
  2561. assert(N == 2 && "Invalid number of operands!");
  2562. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2563. assert(CE && "non-constant AM2OffsetImm operand!");
  2564. int32_t Val = CE->getValue();
  2565. ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
  2566. // Special case for #-0
  2567. if (Val == std::numeric_limits<int32_t>::min()) Val = 0;
  2568. if (Val < 0) Val = -Val;
  2569. Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
  2570. Inst.addOperand(MCOperand::createReg(0));
  2571. Inst.addOperand(MCOperand::createImm(Val));
  2572. }
  2573. void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
  2574. assert(N == 3 && "Invalid number of operands!");
  2575. // If we have an immediate that's not a constant, treat it as a label
  2576. // reference needing a fixup. If it is a constant, it's something else
  2577. // and we reject it.
  2578. if (isImm()) {
  2579. Inst.addOperand(MCOperand::createExpr(getImm()));
  2580. Inst.addOperand(MCOperand::createReg(0));
  2581. Inst.addOperand(MCOperand::createImm(0));
  2582. return;
  2583. }
  2584. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2585. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2586. if (!Memory.OffsetRegNum) {
  2587. if (!Memory.OffsetImm)
  2588. Inst.addOperand(MCOperand::createImm(0));
  2589. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  2590. int32_t Val = CE->getValue();
  2591. ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
  2592. // Special case for #-0
  2593. if (Val == std::numeric_limits<int32_t>::min())
  2594. Val = 0;
  2595. if (Val < 0)
  2596. Val = -Val;
  2597. Val = ARM_AM::getAM3Opc(AddSub, Val);
  2598. Inst.addOperand(MCOperand::createImm(Val));
  2599. } else
  2600. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2601. } else {
  2602. // For register offset, we encode the shift type and negation flag
  2603. // here.
  2604. int32_t Val =
  2605. ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
  2606. Inst.addOperand(MCOperand::createImm(Val));
  2607. }
  2608. }
  2609. void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
  2610. assert(N == 2 && "Invalid number of operands!");
  2611. if (Kind == k_PostIndexRegister) {
  2612. int32_t Val =
  2613. ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
  2614. Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum));
  2615. Inst.addOperand(MCOperand::createImm(Val));
  2616. return;
  2617. }
  2618. // Constant offset.
  2619. const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
  2620. int32_t Val = CE->getValue();
  2621. ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
  2622. // Special case for #-0
  2623. if (Val == std::numeric_limits<int32_t>::min()) Val = 0;
  2624. if (Val < 0) Val = -Val;
  2625. Val = ARM_AM::getAM3Opc(AddSub, Val);
  2626. Inst.addOperand(MCOperand::createReg(0));
  2627. Inst.addOperand(MCOperand::createImm(Val));
  2628. }
  2629. void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
  2630. assert(N == 2 && "Invalid number of operands!");
  2631. // If we have an immediate that's not a constant, treat it as a label
  2632. // reference needing a fixup. If it is a constant, it's something else
  2633. // and we reject it.
  2634. if (isImm()) {
  2635. Inst.addOperand(MCOperand::createExpr(getImm()));
  2636. Inst.addOperand(MCOperand::createImm(0));
  2637. return;
  2638. }
  2639. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2640. if (!Memory.OffsetImm)
  2641. Inst.addOperand(MCOperand::createImm(0));
  2642. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  2643. // The lower two bits are always zero and as such are not encoded.
  2644. int32_t Val = CE->getValue() / 4;
  2645. ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
  2646. // Special case for #-0
  2647. if (Val == std::numeric_limits<int32_t>::min())
  2648. Val = 0;
  2649. if (Val < 0)
  2650. Val = -Val;
  2651. Val = ARM_AM::getAM5Opc(AddSub, Val);
  2652. Inst.addOperand(MCOperand::createImm(Val));
  2653. } else
  2654. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2655. }
  2656. void addAddrMode5FP16Operands(MCInst &Inst, unsigned N) const {
  2657. assert(N == 2 && "Invalid number of operands!");
  2658. // If we have an immediate that's not a constant, treat it as a label
  2659. // reference needing a fixup. If it is a constant, it's something else
  2660. // and we reject it.
  2661. if (isImm()) {
  2662. Inst.addOperand(MCOperand::createExpr(getImm()));
  2663. Inst.addOperand(MCOperand::createImm(0));
  2664. return;
  2665. }
  2666. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2667. // The lower bit is always zero and as such is not encoded.
  2668. if (!Memory.OffsetImm)
  2669. Inst.addOperand(MCOperand::createImm(0));
  2670. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) {
  2671. int32_t Val = CE->getValue() / 2;
  2672. ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
  2673. // Special case for #-0
  2674. if (Val == std::numeric_limits<int32_t>::min())
  2675. Val = 0;
  2676. if (Val < 0)
  2677. Val = -Val;
  2678. Val = ARM_AM::getAM5FP16Opc(AddSub, Val);
  2679. Inst.addOperand(MCOperand::createImm(Val));
  2680. } else
  2681. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2682. }
  2683. void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
  2684. assert(N == 2 && "Invalid number of operands!");
  2685. // If we have an immediate that's not a constant, treat it as a label
  2686. // reference needing a fixup. If it is a constant, it's something else
  2687. // and we reject it.
  2688. if (isImm()) {
  2689. Inst.addOperand(MCOperand::createExpr(getImm()));
  2690. Inst.addOperand(MCOperand::createImm(0));
  2691. return;
  2692. }
  2693. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2694. addExpr(Inst, Memory.OffsetImm);
  2695. }
  2696. void addMemImm7s4OffsetOperands(MCInst &Inst, unsigned N) const {
  2697. assert(N == 2 && "Invalid number of operands!");
  2698. // If we have an immediate that's not a constant, treat it as a label
  2699. // reference needing a fixup. If it is a constant, it's something else
  2700. // and we reject it.
  2701. if (isImm()) {
  2702. Inst.addOperand(MCOperand::createExpr(getImm()));
  2703. Inst.addOperand(MCOperand::createImm(0));
  2704. return;
  2705. }
  2706. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2707. addExpr(Inst, Memory.OffsetImm);
  2708. }
  2709. void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
  2710. assert(N == 2 && "Invalid number of operands!");
  2711. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2712. if (!Memory.OffsetImm)
  2713. Inst.addOperand(MCOperand::createImm(0));
  2714. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
  2715. // The lower two bits are always zero and as such are not encoded.
  2716. Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
  2717. else
  2718. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2719. }
  2720. void addMemImmOffsetOperands(MCInst &Inst, unsigned N) const {
  2721. assert(N == 2 && "Invalid number of operands!");
  2722. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2723. addExpr(Inst, Memory.OffsetImm);
  2724. }
  2725. void addMemRegRQOffsetOperands(MCInst &Inst, unsigned N) const {
  2726. assert(N == 2 && "Invalid number of operands!");
  2727. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2728. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2729. }
  2730. void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
  2731. assert(N == 2 && "Invalid number of operands!");
  2732. // If this is an immediate, it's a label reference.
  2733. if (isImm()) {
  2734. addExpr(Inst, getImm());
  2735. Inst.addOperand(MCOperand::createImm(0));
  2736. return;
  2737. }
  2738. // Otherwise, it's a normal memory reg+offset.
  2739. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2740. addExpr(Inst, Memory.OffsetImm);
  2741. }
  2742. void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
  2743. assert(N == 2 && "Invalid number of operands!");
  2744. // If this is an immediate, it's a label reference.
  2745. if (isImm()) {
  2746. addExpr(Inst, getImm());
  2747. Inst.addOperand(MCOperand::createImm(0));
  2748. return;
  2749. }
  2750. // Otherwise, it's a normal memory reg+offset.
  2751. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2752. addExpr(Inst, Memory.OffsetImm);
  2753. }
  2754. void addConstPoolAsmImmOperands(MCInst &Inst, unsigned N) const {
  2755. assert(N == 1 && "Invalid number of operands!");
  2756. // This is container for the immediate that we will create the constant
  2757. // pool from
  2758. addExpr(Inst, getConstantPoolImm());
  2759. }
  2760. void addMemTBBOperands(MCInst &Inst, unsigned N) const {
  2761. assert(N == 2 && "Invalid number of operands!");
  2762. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2763. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2764. }
  2765. void addMemTBHOperands(MCInst &Inst, unsigned N) const {
  2766. assert(N == 2 && "Invalid number of operands!");
  2767. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2768. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2769. }
  2770. void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
  2771. assert(N == 3 && "Invalid number of operands!");
  2772. unsigned Val =
  2773. ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
  2774. Memory.ShiftImm, Memory.ShiftType);
  2775. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2776. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2777. Inst.addOperand(MCOperand::createImm(Val));
  2778. }
  2779. void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
  2780. assert(N == 3 && "Invalid number of operands!");
  2781. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2782. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2783. Inst.addOperand(MCOperand::createImm(Memory.ShiftImm));
  2784. }
  2785. void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
  2786. assert(N == 2 && "Invalid number of operands!");
  2787. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2788. Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum));
  2789. }
  2790. void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
  2791. assert(N == 2 && "Invalid number of operands!");
  2792. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2793. if (!Memory.OffsetImm)
  2794. Inst.addOperand(MCOperand::createImm(0));
  2795. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
  2796. // The lower two bits are always zero and as such are not encoded.
  2797. Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
  2798. else
  2799. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2800. }
  2801. void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
  2802. assert(N == 2 && "Invalid number of operands!");
  2803. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2804. if (!Memory.OffsetImm)
  2805. Inst.addOperand(MCOperand::createImm(0));
  2806. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
  2807. Inst.addOperand(MCOperand::createImm(CE->getValue() / 2));
  2808. else
  2809. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2810. }
  2811. void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
  2812. assert(N == 2 && "Invalid number of operands!");
  2813. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2814. addExpr(Inst, Memory.OffsetImm);
  2815. }
  2816. void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
  2817. assert(N == 2 && "Invalid number of operands!");
  2818. Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum));
  2819. if (!Memory.OffsetImm)
  2820. Inst.addOperand(MCOperand::createImm(0));
  2821. else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm))
  2822. // The lower two bits are always zero and as such are not encoded.
  2823. Inst.addOperand(MCOperand::createImm(CE->getValue() / 4));
  2824. else
  2825. Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm));
  2826. }
  2827. void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
  2828. assert(N == 1 && "Invalid number of operands!");
  2829. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2830. assert(CE && "non-constant post-idx-imm8 operand!");
  2831. int Imm = CE->getValue();
  2832. bool isAdd = Imm >= 0;
  2833. if (Imm == std::numeric_limits<int32_t>::min()) Imm = 0;
  2834. Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
  2835. Inst.addOperand(MCOperand::createImm(Imm));
  2836. }
  2837. void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
  2838. assert(N == 1 && "Invalid number of operands!");
  2839. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
  2840. assert(CE && "non-constant post-idx-imm8s4 operand!");
  2841. int Imm = CE->getValue();
  2842. bool isAdd = Imm >= 0;
  2843. if (Imm == std::numeric_limits<int32_t>::min()) Imm = 0;
  2844. // Immediate is scaled by 4.
  2845. Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
  2846. Inst.addOperand(MCOperand::createImm(Imm));
  2847. }
  2848. void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
  2849. assert(N == 2 && "Invalid number of operands!");
  2850. Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum));
  2851. Inst.addOperand(MCOperand::createImm(PostIdxReg.isAdd));
  2852. }
  2853. void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
  2854. assert(N == 2 && "Invalid number of operands!");
  2855. Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum));
  2856. // The sign, shift type, and shift amount are encoded in a single operand
  2857. // using the AM2 encoding helpers.
  2858. ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
  2859. unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
  2860. PostIdxReg.ShiftTy);
  2861. Inst.addOperand(MCOperand::createImm(Imm));
  2862. }
  2863. void addPowerTwoOperands(MCInst &Inst, unsigned N) const {
  2864. assert(N == 1 && "Invalid number of operands!");
  2865. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2866. Inst.addOperand(MCOperand::createImm(CE->getValue()));
  2867. }
  2868. void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
  2869. assert(N == 1 && "Invalid number of operands!");
  2870. Inst.addOperand(MCOperand::createImm(unsigned(getMSRMask())));
  2871. }
  2872. void addBankedRegOperands(MCInst &Inst, unsigned N) const {
  2873. assert(N == 1 && "Invalid number of operands!");
  2874. Inst.addOperand(MCOperand::createImm(unsigned(getBankedReg())));
  2875. }
  2876. void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
  2877. assert(N == 1 && "Invalid number of operands!");
  2878. Inst.addOperand(MCOperand::createImm(unsigned(getProcIFlags())));
  2879. }
  2880. void addVecListOperands(MCInst &Inst, unsigned N) const {
  2881. assert(N == 1 && "Invalid number of operands!");
  2882. Inst.addOperand(MCOperand::createReg(VectorList.RegNum));
  2883. }
  2884. void addMVEVecListOperands(MCInst &Inst, unsigned N) const {
  2885. assert(N == 1 && "Invalid number of operands!");
  2886. // When we come here, the VectorList field will identify a range
  2887. // of q-registers by its base register and length, and it will
  2888. // have already been error-checked to be the expected length of
  2889. // range and contain only q-regs in the range q0-q7. So we can
  2890. // count on the base register being in the range q0-q6 (for 2
  2891. // regs) or q0-q4 (for 4)
  2892. //
  2893. // The MVE instructions taking a register range of this kind will
  2894. // need an operand in the MQQPR or MQQQQPR class, representing the
  2895. // entire range as a unit. So we must translate into that class,
  2896. // by finding the index of the base register in the MQPR reg
  2897. // class, and returning the super-register at the corresponding
  2898. // index in the target class.
  2899. const MCRegisterClass *RC_in = &ARMMCRegisterClasses[ARM::MQPRRegClassID];
  2900. const MCRegisterClass *RC_out =
  2901. (VectorList.Count == 2) ? &ARMMCRegisterClasses[ARM::MQQPRRegClassID]
  2902. : &ARMMCRegisterClasses[ARM::MQQQQPRRegClassID];
  2903. unsigned I, E = RC_out->getNumRegs();
  2904. for (I = 0; I < E; I++)
  2905. if (RC_in->getRegister(I) == VectorList.RegNum)
  2906. break;
  2907. assert(I < E && "Invalid vector list start register!");
  2908. Inst.addOperand(MCOperand::createReg(RC_out->getRegister(I)));
  2909. }
  2910. void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
  2911. assert(N == 2 && "Invalid number of operands!");
  2912. Inst.addOperand(MCOperand::createReg(VectorList.RegNum));
  2913. Inst.addOperand(MCOperand::createImm(VectorList.LaneIndex));
  2914. }
  2915. void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
  2916. assert(N == 1 && "Invalid number of operands!");
  2917. Inst.addOperand(MCOperand::createImm(getVectorIndex()));
  2918. }
  2919. void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
  2920. assert(N == 1 && "Invalid number of operands!");
  2921. Inst.addOperand(MCOperand::createImm(getVectorIndex()));
  2922. }
  2923. void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
  2924. assert(N == 1 && "Invalid number of operands!");
  2925. Inst.addOperand(MCOperand::createImm(getVectorIndex()));
  2926. }
  2927. void addVectorIndex64Operands(MCInst &Inst, unsigned N) const {
  2928. assert(N == 1 && "Invalid number of operands!");
  2929. Inst.addOperand(MCOperand::createImm(getVectorIndex()));
  2930. }
  2931. void addMVEVectorIndexOperands(MCInst &Inst, unsigned N) const {
  2932. assert(N == 1 && "Invalid number of operands!");
  2933. Inst.addOperand(MCOperand::createImm(getVectorIndex()));
  2934. }
  2935. void addMVEPairVectorIndexOperands(MCInst &Inst, unsigned N) const {
  2936. assert(N == 1 && "Invalid number of operands!");
  2937. Inst.addOperand(MCOperand::createImm(getVectorIndex()));
  2938. }
  2939. void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
  2940. assert(N == 1 && "Invalid number of operands!");
  2941. // The immediate encodes the type of constant as well as the value.
  2942. // Mask in that this is an i8 splat.
  2943. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2944. Inst.addOperand(MCOperand::createImm(CE->getValue() | 0xe00));
  2945. }
  2946. void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
  2947. assert(N == 1 && "Invalid number of operands!");
  2948. // The immediate encodes the type of constant as well as the value.
  2949. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2950. unsigned Value = CE->getValue();
  2951. Value = ARM_AM::encodeNEONi16splat(Value);
  2952. Inst.addOperand(MCOperand::createImm(Value));
  2953. }
  2954. void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
  2955. assert(N == 1 && "Invalid number of operands!");
  2956. // The immediate encodes the type of constant as well as the value.
  2957. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2958. unsigned Value = CE->getValue();
  2959. Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
  2960. Inst.addOperand(MCOperand::createImm(Value));
  2961. }
  2962. void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
  2963. assert(N == 1 && "Invalid number of operands!");
  2964. // The immediate encodes the type of constant as well as the value.
  2965. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2966. unsigned Value = CE->getValue();
  2967. Value = ARM_AM::encodeNEONi32splat(Value);
  2968. Inst.addOperand(MCOperand::createImm(Value));
  2969. }
  2970. void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
  2971. assert(N == 1 && "Invalid number of operands!");
  2972. // The immediate encodes the type of constant as well as the value.
  2973. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2974. unsigned Value = CE->getValue();
  2975. Value = ARM_AM::encodeNEONi32splat(~Value);
  2976. Inst.addOperand(MCOperand::createImm(Value));
  2977. }
  2978. void addNEONi8ReplicateOperands(MCInst &Inst, bool Inv) const {
  2979. // The immediate encodes the type of constant as well as the value.
  2980. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  2981. assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
  2982. Inst.getOpcode() == ARM::VMOVv16i8) &&
  2983. "All instructions that wants to replicate non-zero byte "
  2984. "always must be replaced with VMOVv8i8 or VMOVv16i8.");
  2985. unsigned Value = CE->getValue();
  2986. if (Inv)
  2987. Value = ~Value;
  2988. unsigned B = Value & 0xff;
  2989. B |= 0xe00; // cmode = 0b1110
  2990. Inst.addOperand(MCOperand::createImm(B));
  2991. }
  2992. void addNEONinvi8ReplicateOperands(MCInst &Inst, unsigned N) const {
  2993. assert(N == 1 && "Invalid number of operands!");
  2994. addNEONi8ReplicateOperands(Inst, true);
  2995. }
  2996. static unsigned encodeNeonVMOVImmediate(unsigned Value) {
  2997. if (Value >= 256 && Value <= 0xffff)
  2998. Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
  2999. else if (Value > 0xffff && Value <= 0xffffff)
  3000. Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
  3001. else if (Value > 0xffffff)
  3002. Value = (Value >> 24) | 0x600;
  3003. return Value;
  3004. }
  3005. void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
  3006. assert(N == 1 && "Invalid number of operands!");
  3007. // The immediate encodes the type of constant as well as the value.
  3008. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3009. unsigned Value = encodeNeonVMOVImmediate(CE->getValue());
  3010. Inst.addOperand(MCOperand::createImm(Value));
  3011. }
  3012. void addNEONvmovi8ReplicateOperands(MCInst &Inst, unsigned N) const {
  3013. assert(N == 1 && "Invalid number of operands!");
  3014. addNEONi8ReplicateOperands(Inst, false);
  3015. }
  3016. void addNEONvmovi16ReplicateOperands(MCInst &Inst, unsigned N) const {
  3017. assert(N == 1 && "Invalid number of operands!");
  3018. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3019. assert((Inst.getOpcode() == ARM::VMOVv4i16 ||
  3020. Inst.getOpcode() == ARM::VMOVv8i16 ||
  3021. Inst.getOpcode() == ARM::VMVNv4i16 ||
  3022. Inst.getOpcode() == ARM::VMVNv8i16) &&
  3023. "All instructions that want to replicate non-zero half-word "
  3024. "always must be replaced with V{MOV,MVN}v{4,8}i16.");
  3025. uint64_t Value = CE->getValue();
  3026. unsigned Elem = Value & 0xffff;
  3027. if (Elem >= 256)
  3028. Elem = (Elem >> 8) | 0x200;
  3029. Inst.addOperand(MCOperand::createImm(Elem));
  3030. }
  3031. void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
  3032. assert(N == 1 && "Invalid number of operands!");
  3033. // The immediate encodes the type of constant as well as the value.
  3034. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3035. unsigned Value = encodeNeonVMOVImmediate(~CE->getValue());
  3036. Inst.addOperand(MCOperand::createImm(Value));
  3037. }
  3038. void addNEONvmovi32ReplicateOperands(MCInst &Inst, unsigned N) const {
  3039. assert(N == 1 && "Invalid number of operands!");
  3040. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3041. assert((Inst.getOpcode() == ARM::VMOVv2i32 ||
  3042. Inst.getOpcode() == ARM::VMOVv4i32 ||
  3043. Inst.getOpcode() == ARM::VMVNv2i32 ||
  3044. Inst.getOpcode() == ARM::VMVNv4i32) &&
  3045. "All instructions that want to replicate non-zero word "
  3046. "always must be replaced with V{MOV,MVN}v{2,4}i32.");
  3047. uint64_t Value = CE->getValue();
  3048. unsigned Elem = encodeNeonVMOVImmediate(Value & 0xffffffff);
  3049. Inst.addOperand(MCOperand::createImm(Elem));
  3050. }
  3051. void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
  3052. assert(N == 1 && "Invalid number of operands!");
  3053. // The immediate encodes the type of constant as well as the value.
  3054. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3055. uint64_t Value = CE->getValue();
  3056. unsigned Imm = 0;
  3057. for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
  3058. Imm |= (Value & 1) << i;
  3059. }
  3060. Inst.addOperand(MCOperand::createImm(Imm | 0x1e00));
  3061. }
  3062. void addComplexRotationEvenOperands(MCInst &Inst, unsigned N) const {
  3063. assert(N == 1 && "Invalid number of operands!");
  3064. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3065. Inst.addOperand(MCOperand::createImm(CE->getValue() / 90));
  3066. }
  3067. void addComplexRotationOddOperands(MCInst &Inst, unsigned N) const {
  3068. assert(N == 1 && "Invalid number of operands!");
  3069. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3070. Inst.addOperand(MCOperand::createImm((CE->getValue() - 90) / 180));
  3071. }
  3072. void addMveSaturateOperands(MCInst &Inst, unsigned N) const {
  3073. assert(N == 1 && "Invalid number of operands!");
  3074. const MCConstantExpr *CE = cast<MCConstantExpr>(getImm());
  3075. unsigned Imm = CE->getValue();
  3076. assert((Imm == 48 || Imm == 64) && "Invalid saturate operand");
  3077. Inst.addOperand(MCOperand::createImm(Imm == 48 ? 1 : 0));
  3078. }
  3079. void print(raw_ostream &OS) const override;
  3080. static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
  3081. auto Op = std::make_unique<ARMOperand>(k_ITCondMask);
  3082. Op->ITMask.Mask = Mask;
  3083. Op->StartLoc = S;
  3084. Op->EndLoc = S;
  3085. return Op;
  3086. }
  3087. static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
  3088. SMLoc S) {
  3089. auto Op = std::make_unique<ARMOperand>(k_CondCode);
  3090. Op->CC.Val = CC;
  3091. Op->StartLoc = S;
  3092. Op->EndLoc = S;
  3093. return Op;
  3094. }
  3095. static std::unique_ptr<ARMOperand> CreateVPTPred(ARMVCC::VPTCodes CC,
  3096. SMLoc S) {
  3097. auto Op = std::make_unique<ARMOperand>(k_VPTPred);
  3098. Op->VCC.Val = CC;
  3099. Op->StartLoc = S;
  3100. Op->EndLoc = S;
  3101. return Op;
  3102. }
  3103. static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
  3104. auto Op = std::make_unique<ARMOperand>(k_CoprocNum);
  3105. Op->Cop.Val = CopVal;
  3106. Op->StartLoc = S;
  3107. Op->EndLoc = S;
  3108. return Op;
  3109. }
  3110. static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
  3111. auto Op = std::make_unique<ARMOperand>(k_CoprocReg);
  3112. Op->Cop.Val = CopVal;
  3113. Op->StartLoc = S;
  3114. Op->EndLoc = S;
  3115. return Op;
  3116. }
  3117. static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
  3118. SMLoc E) {
  3119. auto Op = std::make_unique<ARMOperand>(k_CoprocOption);
  3120. Op->Cop.Val = Val;
  3121. Op->StartLoc = S;
  3122. Op->EndLoc = E;
  3123. return Op;
  3124. }
  3125. static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
  3126. auto Op = std::make_unique<ARMOperand>(k_CCOut);
  3127. Op->Reg.RegNum = RegNum;
  3128. Op->StartLoc = S;
  3129. Op->EndLoc = S;
  3130. return Op;
  3131. }
  3132. static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
  3133. auto Op = std::make_unique<ARMOperand>(k_Token);
  3134. Op->Tok.Data = Str.data();
  3135. Op->Tok.Length = Str.size();
  3136. Op->StartLoc = S;
  3137. Op->EndLoc = S;
  3138. return Op;
  3139. }
  3140. static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
  3141. SMLoc E) {
  3142. auto Op = std::make_unique<ARMOperand>(k_Register);
  3143. Op->Reg.RegNum = RegNum;
  3144. Op->StartLoc = S;
  3145. Op->EndLoc = E;
  3146. return Op;
  3147. }
  3148. static std::unique_ptr<ARMOperand>
  3149. CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
  3150. unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
  3151. SMLoc E) {
  3152. auto Op = std::make_unique<ARMOperand>(k_ShiftedRegister);
  3153. Op->RegShiftedReg.ShiftTy = ShTy;
  3154. Op->RegShiftedReg.SrcReg = SrcReg;
  3155. Op->RegShiftedReg.ShiftReg = ShiftReg;
  3156. Op->RegShiftedReg.ShiftImm = ShiftImm;
  3157. Op->StartLoc = S;
  3158. Op->EndLoc = E;
  3159. return Op;
  3160. }
  3161. static std::unique_ptr<ARMOperand>
  3162. CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
  3163. unsigned ShiftImm, SMLoc S, SMLoc E) {
  3164. auto Op = std::make_unique<ARMOperand>(k_ShiftedImmediate);
  3165. Op->RegShiftedImm.ShiftTy = ShTy;
  3166. Op->RegShiftedImm.SrcReg = SrcReg;
  3167. Op->RegShiftedImm.ShiftImm = ShiftImm;
  3168. Op->StartLoc = S;
  3169. Op->EndLoc = E;
  3170. return Op;
  3171. }
  3172. static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
  3173. SMLoc S, SMLoc E) {
  3174. auto Op = std::make_unique<ARMOperand>(k_ShifterImmediate);
  3175. Op->ShifterImm.isASR = isASR;
  3176. Op->ShifterImm.Imm = Imm;
  3177. Op->StartLoc = S;
  3178. Op->EndLoc = E;
  3179. return Op;
  3180. }
  3181. static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
  3182. SMLoc E) {
  3183. auto Op = std::make_unique<ARMOperand>(k_RotateImmediate);
  3184. Op->RotImm.Imm = Imm;
  3185. Op->StartLoc = S;
  3186. Op->EndLoc = E;
  3187. return Op;
  3188. }
  3189. static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
  3190. SMLoc S, SMLoc E) {
  3191. auto Op = std::make_unique<ARMOperand>(k_ModifiedImmediate);
  3192. Op->ModImm.Bits = Bits;
  3193. Op->ModImm.Rot = Rot;
  3194. Op->StartLoc = S;
  3195. Op->EndLoc = E;
  3196. return Op;
  3197. }
  3198. static std::unique_ptr<ARMOperand>
  3199. CreateConstantPoolImm(const MCExpr *Val, SMLoc S, SMLoc E) {
  3200. auto Op = std::make_unique<ARMOperand>(k_ConstantPoolImmediate);
  3201. Op->Imm.Val = Val;
  3202. Op->StartLoc = S;
  3203. Op->EndLoc = E;
  3204. return Op;
  3205. }
  3206. static std::unique_ptr<ARMOperand>
  3207. CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
  3208. auto Op = std::make_unique<ARMOperand>(k_BitfieldDescriptor);
  3209. Op->Bitfield.LSB = LSB;
  3210. Op->Bitfield.Width = Width;
  3211. Op->StartLoc = S;
  3212. Op->EndLoc = E;
  3213. return Op;
  3214. }
  3215. static std::unique_ptr<ARMOperand>
  3216. CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
  3217. SMLoc StartLoc, SMLoc EndLoc) {
  3218. assert(Regs.size() > 0 && "RegList contains no registers?");
  3219. KindTy Kind = k_RegisterList;
  3220. if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
  3221. Regs.front().second)) {
  3222. if (Regs.back().second == ARM::VPR)
  3223. Kind = k_FPDRegisterListWithVPR;
  3224. else
  3225. Kind = k_DPRRegisterList;
  3226. } else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(
  3227. Regs.front().second)) {
  3228. if (Regs.back().second == ARM::VPR)
  3229. Kind = k_FPSRegisterListWithVPR;
  3230. else
  3231. Kind = k_SPRRegisterList;
  3232. }
  3233. if (Kind == k_RegisterList && Regs.back().second == ARM::APSR)
  3234. Kind = k_RegisterListWithAPSR;
  3235. assert(llvm::is_sorted(Regs) && "Register list must be sorted by encoding");
  3236. auto Op = std::make_unique<ARMOperand>(Kind);
  3237. for (const auto &P : Regs)
  3238. Op->Registers.push_back(P.second);
  3239. Op->StartLoc = StartLoc;
  3240. Op->EndLoc = EndLoc;
  3241. return Op;
  3242. }
  3243. static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
  3244. unsigned Count,
  3245. bool isDoubleSpaced,
  3246. SMLoc S, SMLoc E) {
  3247. auto Op = std::make_unique<ARMOperand>(k_VectorList);
  3248. Op->VectorList.RegNum = RegNum;
  3249. Op->VectorList.Count = Count;
  3250. Op->VectorList.isDoubleSpaced = isDoubleSpaced;
  3251. Op->StartLoc = S;
  3252. Op->EndLoc = E;
  3253. return Op;
  3254. }
  3255. static std::unique_ptr<ARMOperand>
  3256. CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
  3257. SMLoc S, SMLoc E) {
  3258. auto Op = std::make_unique<ARMOperand>(k_VectorListAllLanes);
  3259. Op->VectorList.RegNum = RegNum;
  3260. Op->VectorList.Count = Count;
  3261. Op->VectorList.isDoubleSpaced = isDoubleSpaced;
  3262. Op->StartLoc = S;
  3263. Op->EndLoc = E;
  3264. return Op;
  3265. }
  3266. static std::unique_ptr<ARMOperand>
  3267. CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
  3268. bool isDoubleSpaced, SMLoc S, SMLoc E) {
  3269. auto Op = std::make_unique<ARMOperand>(k_VectorListIndexed);
  3270. Op->VectorList.RegNum = RegNum;
  3271. Op->VectorList.Count = Count;
  3272. Op->VectorList.LaneIndex = Index;
  3273. Op->VectorList.isDoubleSpaced = isDoubleSpaced;
  3274. Op->StartLoc = S;
  3275. Op->EndLoc = E;
  3276. return Op;
  3277. }
  3278. static std::unique_ptr<ARMOperand>
  3279. CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
  3280. auto Op = std::make_unique<ARMOperand>(k_VectorIndex);
  3281. Op->VectorIndex.Val = Idx;
  3282. Op->StartLoc = S;
  3283. Op->EndLoc = E;
  3284. return Op;
  3285. }
  3286. static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
  3287. SMLoc E) {
  3288. auto Op = std::make_unique<ARMOperand>(k_Immediate);
  3289. Op->Imm.Val = Val;
  3290. Op->StartLoc = S;
  3291. Op->EndLoc = E;
  3292. return Op;
  3293. }
  3294. static std::unique_ptr<ARMOperand>
  3295. CreateMem(unsigned BaseRegNum, const MCExpr *OffsetImm, unsigned OffsetRegNum,
  3296. ARM_AM::ShiftOpc ShiftType, unsigned ShiftImm, unsigned Alignment,
  3297. bool isNegative, SMLoc S, SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
  3298. auto Op = std::make_unique<ARMOperand>(k_Memory);
  3299. Op->Memory.BaseRegNum = BaseRegNum;
  3300. Op->Memory.OffsetImm = OffsetImm;
  3301. Op->Memory.OffsetRegNum = OffsetRegNum;
  3302. Op->Memory.ShiftType = ShiftType;
  3303. Op->Memory.ShiftImm = ShiftImm;
  3304. Op->Memory.Alignment = Alignment;
  3305. Op->Memory.isNegative = isNegative;
  3306. Op->StartLoc = S;
  3307. Op->EndLoc = E;
  3308. Op->AlignmentLoc = AlignmentLoc;
  3309. return Op;
  3310. }
  3311. static std::unique_ptr<ARMOperand>
  3312. CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
  3313. unsigned ShiftImm, SMLoc S, SMLoc E) {
  3314. auto Op = std::make_unique<ARMOperand>(k_PostIndexRegister);
  3315. Op->PostIdxReg.RegNum = RegNum;
  3316. Op->PostIdxReg.isAdd = isAdd;
  3317. Op->PostIdxReg.ShiftTy = ShiftTy;
  3318. Op->PostIdxReg.ShiftImm = ShiftImm;
  3319. Op->StartLoc = S;
  3320. Op->EndLoc = E;
  3321. return Op;
  3322. }
  3323. static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
  3324. SMLoc S) {
  3325. auto Op = std::make_unique<ARMOperand>(k_MemBarrierOpt);
  3326. Op->MBOpt.Val = Opt;
  3327. Op->StartLoc = S;
  3328. Op->EndLoc = S;
  3329. return Op;
  3330. }
  3331. static std::unique_ptr<ARMOperand>
  3332. CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
  3333. auto Op = std::make_unique<ARMOperand>(k_InstSyncBarrierOpt);
  3334. Op->ISBOpt.Val = Opt;
  3335. Op->StartLoc = S;
  3336. Op->EndLoc = S;
  3337. return Op;
  3338. }
  3339. static std::unique_ptr<ARMOperand>
  3340. CreateTraceSyncBarrierOpt(ARM_TSB::TraceSyncBOpt Opt, SMLoc S) {
  3341. auto Op = std::make_unique<ARMOperand>(k_TraceSyncBarrierOpt);
  3342. Op->TSBOpt.Val = Opt;
  3343. Op->StartLoc = S;
  3344. Op->EndLoc = S;
  3345. return Op;
  3346. }
  3347. static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
  3348. SMLoc S) {
  3349. auto Op = std::make_unique<ARMOperand>(k_ProcIFlags);
  3350. Op->IFlags.Val = IFlags;
  3351. Op->StartLoc = S;
  3352. Op->EndLoc = S;
  3353. return Op;
  3354. }
  3355. static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
  3356. auto Op = std::make_unique<ARMOperand>(k_MSRMask);
  3357. Op->MMask.Val = MMask;
  3358. Op->StartLoc = S;
  3359. Op->EndLoc = S;
  3360. return Op;
  3361. }
  3362. static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
  3363. auto Op = std::make_unique<ARMOperand>(k_BankedReg);
  3364. Op->BankedReg.Val = Reg;
  3365. Op->StartLoc = S;
  3366. Op->EndLoc = S;
  3367. return Op;
  3368. }
  3369. };
  3370. } // end anonymous namespace.
  3371. void ARMOperand::print(raw_ostream &OS) const {
  3372. auto RegName = [](unsigned Reg) {
  3373. if (Reg)
  3374. return ARMInstPrinter::getRegisterName(Reg);
  3375. else
  3376. return "noreg";
  3377. };
  3378. switch (Kind) {
  3379. case k_CondCode:
  3380. OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
  3381. break;
  3382. case k_VPTPred:
  3383. OS << "<ARMVCC::" << ARMVPTPredToString(getVPTPred()) << ">";
  3384. break;
  3385. case k_CCOut:
  3386. OS << "<ccout " << RegName(getReg()) << ">";
  3387. break;
  3388. case k_ITCondMask: {
  3389. static const char *const MaskStr[] = {
  3390. "(invalid)", "(tttt)", "(ttt)", "(ttte)",
  3391. "(tt)", "(ttet)", "(tte)", "(ttee)",
  3392. "(t)", "(tett)", "(tet)", "(tete)",
  3393. "(te)", "(teet)", "(tee)", "(teee)",
  3394. };
  3395. assert((ITMask.Mask & 0xf) == ITMask.Mask);
  3396. OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
  3397. break;
  3398. }
  3399. case k_CoprocNum:
  3400. OS << "<coprocessor number: " << getCoproc() << ">";
  3401. break;
  3402. case k_CoprocReg:
  3403. OS << "<coprocessor register: " << getCoproc() << ">";
  3404. break;
  3405. case k_CoprocOption:
  3406. OS << "<coprocessor option: " << CoprocOption.Val << ">";
  3407. break;
  3408. case k_MSRMask:
  3409. OS << "<mask: " << getMSRMask() << ">";
  3410. break;
  3411. case k_BankedReg:
  3412. OS << "<banked reg: " << getBankedReg() << ">";
  3413. break;
  3414. case k_Immediate:
  3415. OS << *getImm();
  3416. break;
  3417. case k_MemBarrierOpt:
  3418. OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
  3419. break;
  3420. case k_InstSyncBarrierOpt:
  3421. OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
  3422. break;
  3423. case k_TraceSyncBarrierOpt:
  3424. OS << "<ARM_TSB::" << TraceSyncBOptToString(getTraceSyncBarrierOpt()) << ">";
  3425. break;
  3426. case k_Memory:
  3427. OS << "<memory";
  3428. if (Memory.BaseRegNum)
  3429. OS << " base:" << RegName(Memory.BaseRegNum);
  3430. if (Memory.OffsetImm)
  3431. OS << " offset-imm:" << *Memory.OffsetImm;
  3432. if (Memory.OffsetRegNum)
  3433. OS << " offset-reg:" << (Memory.isNegative ? "-" : "")
  3434. << RegName(Memory.OffsetRegNum);
  3435. if (Memory.ShiftType != ARM_AM::no_shift) {
  3436. OS << " shift-type:" << ARM_AM::getShiftOpcStr(Memory.ShiftType);
  3437. OS << " shift-imm:" << Memory.ShiftImm;
  3438. }
  3439. if (Memory.Alignment)
  3440. OS << " alignment:" << Memory.Alignment;
  3441. OS << ">";
  3442. break;
  3443. case k_PostIndexRegister:
  3444. OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
  3445. << RegName(PostIdxReg.RegNum);
  3446. if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
  3447. OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
  3448. << PostIdxReg.ShiftImm;
  3449. OS << ">";
  3450. break;
  3451. case k_ProcIFlags: {
  3452. OS << "<ARM_PROC::";
  3453. unsigned IFlags = getProcIFlags();
  3454. for (int i=2; i >= 0; --i)
  3455. if (IFlags & (1 << i))
  3456. OS << ARM_PROC::IFlagsToString(1 << i);
  3457. OS << ">";
  3458. break;
  3459. }
  3460. case k_Register:
  3461. OS << "<register " << RegName(getReg()) << ">";
  3462. break;
  3463. case k_ShifterImmediate:
  3464. OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
  3465. << " #" << ShifterImm.Imm << ">";
  3466. break;
  3467. case k_ShiftedRegister:
  3468. OS << "<so_reg_reg " << RegName(RegShiftedReg.SrcReg) << " "
  3469. << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy) << " "
  3470. << RegName(RegShiftedReg.ShiftReg) << ">";
  3471. break;
  3472. case k_ShiftedImmediate:
  3473. OS << "<so_reg_imm " << RegName(RegShiftedImm.SrcReg) << " "
  3474. << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy) << " #"
  3475. << RegShiftedImm.ShiftImm << ">";
  3476. break;
  3477. case k_RotateImmediate:
  3478. OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
  3479. break;
  3480. case k_ModifiedImmediate:
  3481. OS << "<mod_imm #" << ModImm.Bits << ", #"
  3482. << ModImm.Rot << ")>";
  3483. break;
  3484. case k_ConstantPoolImmediate:
  3485. OS << "<constant_pool_imm #" << *getConstantPoolImm();
  3486. break;
  3487. case k_BitfieldDescriptor:
  3488. OS << "<bitfield " << "lsb: " << Bitfield.LSB
  3489. << ", width: " << Bitfield.Width << ">";
  3490. break;
  3491. case k_RegisterList:
  3492. case k_RegisterListWithAPSR:
  3493. case k_DPRRegisterList:
  3494. case k_SPRRegisterList:
  3495. case k_FPSRegisterListWithVPR:
  3496. case k_FPDRegisterListWithVPR: {
  3497. OS << "<register_list ";
  3498. const SmallVectorImpl<unsigned> &RegList = getRegList();
  3499. for (SmallVectorImpl<unsigned>::const_iterator
  3500. I = RegList.begin(), E = RegList.end(); I != E; ) {
  3501. OS << RegName(*I);
  3502. if (++I < E) OS << ", ";
  3503. }
  3504. OS << ">";
  3505. break;
  3506. }
  3507. case k_VectorList:
  3508. OS << "<vector_list " << VectorList.Count << " * "
  3509. << RegName(VectorList.RegNum) << ">";
  3510. break;
  3511. case k_VectorListAllLanes:
  3512. OS << "<vector_list(all lanes) " << VectorList.Count << " * "
  3513. << RegName(VectorList.RegNum) << ">";
  3514. break;
  3515. case k_VectorListIndexed:
  3516. OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
  3517. << VectorList.Count << " * " << RegName(VectorList.RegNum) << ">";
  3518. break;
  3519. case k_Token:
  3520. OS << "'" << getToken() << "'";
  3521. break;
  3522. case k_VectorIndex:
  3523. OS << "<vectorindex " << getVectorIndex() << ">";
  3524. break;
  3525. }
  3526. }
  3527. /// @name Auto-generated Match Functions
  3528. /// {
  3529. static unsigned MatchRegisterName(StringRef Name);
  3530. /// }
  3531. bool ARMAsmParser::ParseRegister(unsigned &RegNo,
  3532. SMLoc &StartLoc, SMLoc &EndLoc) {
  3533. const AsmToken &Tok = getParser().getTok();
  3534. StartLoc = Tok.getLoc();
  3535. EndLoc = Tok.getEndLoc();
  3536. RegNo = tryParseRegister();
  3537. return (RegNo == (unsigned)-1);
  3538. }
  3539. OperandMatchResultTy ARMAsmParser::tryParseRegister(unsigned &RegNo,
  3540. SMLoc &StartLoc,
  3541. SMLoc &EndLoc) {
  3542. if (ParseRegister(RegNo, StartLoc, EndLoc))
  3543. return MatchOperand_NoMatch;
  3544. return MatchOperand_Success;
  3545. }
  3546. /// Try to parse a register name. The token must be an Identifier when called,
  3547. /// and if it is a register name the token is eaten and the register number is
  3548. /// returned. Otherwise return -1.
  3549. int ARMAsmParser::tryParseRegister() {
  3550. MCAsmParser &Parser = getParser();
  3551. const AsmToken &Tok = Parser.getTok();
  3552. if (Tok.isNot(AsmToken::Identifier)) return -1;
  3553. std::string lowerCase = Tok.getString().lower();
  3554. unsigned RegNum = MatchRegisterName(lowerCase);
  3555. if (!RegNum) {
  3556. RegNum = StringSwitch<unsigned>(lowerCase)
  3557. .Case("r13", ARM::SP)
  3558. .Case("r14", ARM::LR)
  3559. .Case("r15", ARM::PC)
  3560. .Case("ip", ARM::R12)
  3561. // Additional register name aliases for 'gas' compatibility.
  3562. .Case("a1", ARM::R0)
  3563. .Case("a2", ARM::R1)
  3564. .Case("a3", ARM::R2)
  3565. .Case("a4", ARM::R3)
  3566. .Case("v1", ARM::R4)
  3567. .Case("v2", ARM::R5)
  3568. .Case("v3", ARM::R6)
  3569. .Case("v4", ARM::R7)
  3570. .Case("v5", ARM::R8)
  3571. .Case("v6", ARM::R9)
  3572. .Case("v7", ARM::R10)
  3573. .Case("v8", ARM::R11)
  3574. .Case("sb", ARM::R9)
  3575. .Case("sl", ARM::R10)
  3576. .Case("fp", ARM::R11)
  3577. .Default(0);
  3578. }
  3579. if (!RegNum) {
  3580. // Check for aliases registered via .req. Canonicalize to lower case.
  3581. // That's more consistent since register names are case insensitive, and
  3582. // it's how the original entry was passed in from MC/MCParser/AsmParser.
  3583. StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
  3584. // If no match, return failure.
  3585. if (Entry == RegisterReqs.end())
  3586. return -1;
  3587. Parser.Lex(); // Eat identifier token.
  3588. return Entry->getValue();
  3589. }
  3590. // Some FPUs only have 16 D registers, so D16-D31 are invalid
  3591. if (!hasD32() && RegNum >= ARM::D16 && RegNum <= ARM::D31)
  3592. return -1;
  3593. Parser.Lex(); // Eat identifier token.
  3594. return RegNum;
  3595. }
  3596. // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
  3597. // If a recoverable error occurs, return 1. If an irrecoverable error
  3598. // occurs, return -1. An irrecoverable error is one where tokens have been
  3599. // consumed in the process of trying to parse the shifter (i.e., when it is
  3600. // indeed a shifter operand, but malformed).
  3601. int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
  3602. MCAsmParser &Parser = getParser();
  3603. SMLoc S = Parser.getTok().getLoc();
  3604. const AsmToken &Tok = Parser.getTok();
  3605. if (Tok.isNot(AsmToken::Identifier))
  3606. return -1;
  3607. std::string lowerCase = Tok.getString().lower();
  3608. ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
  3609. .Case("asl", ARM_AM::lsl)
  3610. .Case("lsl", ARM_AM::lsl)
  3611. .Case("lsr", ARM_AM::lsr)
  3612. .Case("asr", ARM_AM::asr)
  3613. .Case("ror", ARM_AM::ror)
  3614. .Case("rrx", ARM_AM::rrx)
  3615. .Default(ARM_AM::no_shift);
  3616. if (ShiftTy == ARM_AM::no_shift)
  3617. return 1;
  3618. Parser.Lex(); // Eat the operator.
  3619. // The source register for the shift has already been added to the
  3620. // operand list, so we need to pop it off and combine it into the shifted
  3621. // register operand instead.
  3622. std::unique_ptr<ARMOperand> PrevOp(
  3623. (ARMOperand *)Operands.pop_back_val().release());
  3624. if (!PrevOp->isReg())
  3625. return Error(PrevOp->getStartLoc(), "shift must be of a register");
  3626. int SrcReg = PrevOp->getReg();
  3627. SMLoc EndLoc;
  3628. int64_t Imm = 0;
  3629. int ShiftReg = 0;
  3630. if (ShiftTy == ARM_AM::rrx) {
  3631. // RRX Doesn't have an explicit shift amount. The encoder expects
  3632. // the shift register to be the same as the source register. Seems odd,
  3633. // but OK.
  3634. ShiftReg = SrcReg;
  3635. } else {
  3636. // Figure out if this is shifted by a constant or a register (for non-RRX).
  3637. if (Parser.getTok().is(AsmToken::Hash) ||
  3638. Parser.getTok().is(AsmToken::Dollar)) {
  3639. Parser.Lex(); // Eat hash.
  3640. SMLoc ImmLoc = Parser.getTok().getLoc();
  3641. const MCExpr *ShiftExpr = nullptr;
  3642. if (getParser().parseExpression(ShiftExpr, EndLoc)) {
  3643. Error(ImmLoc, "invalid immediate shift value");
  3644. return -1;
  3645. }
  3646. // The expression must be evaluatable as an immediate.
  3647. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
  3648. if (!CE) {
  3649. Error(ImmLoc, "invalid immediate shift value");
  3650. return -1;
  3651. }
  3652. // Range check the immediate.
  3653. // lsl, ror: 0 <= imm <= 31
  3654. // lsr, asr: 0 <= imm <= 32
  3655. Imm = CE->getValue();
  3656. if (Imm < 0 ||
  3657. ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
  3658. ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
  3659. Error(ImmLoc, "immediate shift value out of range");
  3660. return -1;
  3661. }
  3662. // shift by zero is a nop. Always send it through as lsl.
  3663. // ('as' compatibility)
  3664. if (Imm == 0)
  3665. ShiftTy = ARM_AM::lsl;
  3666. } else if (Parser.getTok().is(AsmToken::Identifier)) {
  3667. SMLoc L = Parser.getTok().getLoc();
  3668. EndLoc = Parser.getTok().getEndLoc();
  3669. ShiftReg = tryParseRegister();
  3670. if (ShiftReg == -1) {
  3671. Error(L, "expected immediate or register in shift operand");
  3672. return -1;
  3673. }
  3674. } else {
  3675. Error(Parser.getTok().getLoc(),
  3676. "expected immediate or register in shift operand");
  3677. return -1;
  3678. }
  3679. }
  3680. if (ShiftReg && ShiftTy != ARM_AM::rrx)
  3681. Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
  3682. ShiftReg, Imm,
  3683. S, EndLoc));
  3684. else
  3685. Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
  3686. S, EndLoc));
  3687. return 0;
  3688. }
  3689. /// Try to parse a register name. The token must be an Identifier when called.
  3690. /// If it's a register, an AsmOperand is created. Another AsmOperand is created
  3691. /// if there is a "writeback". 'true' if it's not a register.
  3692. ///
  3693. /// TODO this is likely to change to allow different register types and or to
  3694. /// parse for a specific register type.
  3695. bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
  3696. MCAsmParser &Parser = getParser();
  3697. SMLoc RegStartLoc = Parser.getTok().getLoc();
  3698. SMLoc RegEndLoc = Parser.getTok().getEndLoc();
  3699. int RegNo = tryParseRegister();
  3700. if (RegNo == -1)
  3701. return true;
  3702. Operands.push_back(ARMOperand::CreateReg(RegNo, RegStartLoc, RegEndLoc));
  3703. const AsmToken &ExclaimTok = Parser.getTok();
  3704. if (ExclaimTok.is(AsmToken::Exclaim)) {
  3705. Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
  3706. ExclaimTok.getLoc()));
  3707. Parser.Lex(); // Eat exclaim token
  3708. return false;
  3709. }
  3710. // Also check for an index operand. This is only legal for vector registers,
  3711. // but that'll get caught OK in operand matching, so we don't need to
  3712. // explicitly filter everything else out here.
  3713. if (Parser.getTok().is(AsmToken::LBrac)) {
  3714. SMLoc SIdx = Parser.getTok().getLoc();
  3715. Parser.Lex(); // Eat left bracket token.
  3716. const MCExpr *ImmVal;
  3717. if (getParser().parseExpression(ImmVal))
  3718. return true;
  3719. const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
  3720. if (!MCE)
  3721. return TokError("immediate value expected for vector index");
  3722. if (Parser.getTok().isNot(AsmToken::RBrac))
  3723. return Error(Parser.getTok().getLoc(), "']' expected");
  3724. SMLoc E = Parser.getTok().getEndLoc();
  3725. Parser.Lex(); // Eat right bracket token.
  3726. Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
  3727. SIdx, E,
  3728. getContext()));
  3729. }
  3730. return false;
  3731. }
  3732. /// MatchCoprocessorOperandName - Try to parse an coprocessor related
  3733. /// instruction with a symbolic operand name.
  3734. /// We accept "crN" syntax for GAS compatibility.
  3735. /// <operand-name> ::= <prefix><number>
  3736. /// If CoprocOp is 'c', then:
  3737. /// <prefix> ::= c | cr
  3738. /// If CoprocOp is 'p', then :
  3739. /// <prefix> ::= p
  3740. /// <number> ::= integer in range [0, 15]
  3741. static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
  3742. // Use the same layout as the tablegen'erated register name matcher. Ugly,
  3743. // but efficient.
  3744. if (Name.size() < 2 || Name[0] != CoprocOp)
  3745. return -1;
  3746. Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
  3747. switch (Name.size()) {
  3748. default: return -1;
  3749. case 1:
  3750. switch (Name[0]) {
  3751. default: return -1;
  3752. case '0': return 0;
  3753. case '1': return 1;
  3754. case '2': return 2;
  3755. case '3': return 3;
  3756. case '4': return 4;
  3757. case '5': return 5;
  3758. case '6': return 6;
  3759. case '7': return 7;
  3760. case '8': return 8;
  3761. case '9': return 9;
  3762. }
  3763. case 2:
  3764. if (Name[0] != '1')
  3765. return -1;
  3766. switch (Name[1]) {
  3767. default: return -1;
  3768. // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
  3769. // However, old cores (v5/v6) did use them in that way.
  3770. case '0': return 10;
  3771. case '1': return 11;
  3772. case '2': return 12;
  3773. case '3': return 13;
  3774. case '4': return 14;
  3775. case '5': return 15;
  3776. }
  3777. }
  3778. }
  3779. /// parseITCondCode - Try to parse a condition code for an IT instruction.
  3780. OperandMatchResultTy
  3781. ARMAsmParser::parseITCondCode(OperandVector &Operands) {
  3782. MCAsmParser &Parser = getParser();
  3783. SMLoc S = Parser.getTok().getLoc();
  3784. const AsmToken &Tok = Parser.getTok();
  3785. if (!Tok.is(AsmToken::Identifier))
  3786. return MatchOperand_NoMatch;
  3787. unsigned CC = ARMCondCodeFromString(Tok.getString());
  3788. if (CC == ~0U)
  3789. return MatchOperand_NoMatch;
  3790. Parser.Lex(); // Eat the token.
  3791. Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
  3792. return MatchOperand_Success;
  3793. }
  3794. /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
  3795. /// token must be an Identifier when called, and if it is a coprocessor
  3796. /// number, the token is eaten and the operand is added to the operand list.
  3797. OperandMatchResultTy
  3798. ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
  3799. MCAsmParser &Parser = getParser();
  3800. SMLoc S = Parser.getTok().getLoc();
  3801. const AsmToken &Tok = Parser.getTok();
  3802. if (Tok.isNot(AsmToken::Identifier))
  3803. return MatchOperand_NoMatch;
  3804. int Num = MatchCoprocessorOperandName(Tok.getString().lower(), 'p');
  3805. if (Num == -1)
  3806. return MatchOperand_NoMatch;
  3807. if (!isValidCoprocessorNumber(Num, getSTI().getFeatureBits()))
  3808. return MatchOperand_NoMatch;
  3809. Parser.Lex(); // Eat identifier token.
  3810. Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
  3811. return MatchOperand_Success;
  3812. }
  3813. /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
  3814. /// token must be an Identifier when called, and if it is a coprocessor
  3815. /// number, the token is eaten and the operand is added to the operand list.
  3816. OperandMatchResultTy
  3817. ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
  3818. MCAsmParser &Parser = getParser();
  3819. SMLoc S = Parser.getTok().getLoc();
  3820. const AsmToken &Tok = Parser.getTok();
  3821. if (Tok.isNot(AsmToken::Identifier))
  3822. return MatchOperand_NoMatch;
  3823. int Reg = MatchCoprocessorOperandName(Tok.getString().lower(), 'c');
  3824. if (Reg == -1)
  3825. return MatchOperand_NoMatch;
  3826. Parser.Lex(); // Eat identifier token.
  3827. Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
  3828. return MatchOperand_Success;
  3829. }
  3830. /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
  3831. /// coproc_option : '{' imm0_255 '}'
  3832. OperandMatchResultTy
  3833. ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
  3834. MCAsmParser &Parser = getParser();
  3835. SMLoc S = Parser.getTok().getLoc();
  3836. // If this isn't a '{', this isn't a coprocessor immediate operand.
  3837. if (Parser.getTok().isNot(AsmToken::LCurly))
  3838. return MatchOperand_NoMatch;
  3839. Parser.Lex(); // Eat the '{'
  3840. const MCExpr *Expr;
  3841. SMLoc Loc = Parser.getTok().getLoc();
  3842. if (getParser().parseExpression(Expr)) {
  3843. Error(Loc, "illegal expression");
  3844. return MatchOperand_ParseFail;
  3845. }
  3846. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
  3847. if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
  3848. Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
  3849. return MatchOperand_ParseFail;
  3850. }
  3851. int Val = CE->getValue();
  3852. // Check for and consume the closing '}'
  3853. if (Parser.getTok().isNot(AsmToken::RCurly))
  3854. return MatchOperand_ParseFail;
  3855. SMLoc E = Parser.getTok().getEndLoc();
  3856. Parser.Lex(); // Eat the '}'
  3857. Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
  3858. return MatchOperand_Success;
  3859. }
  3860. // For register list parsing, we need to map from raw GPR register numbering
  3861. // to the enumeration values. The enumeration values aren't sorted by
  3862. // register number due to our using "sp", "lr" and "pc" as canonical names.
  3863. static unsigned getNextRegister(unsigned Reg) {
  3864. // If this is a GPR, we need to do it manually, otherwise we can rely
  3865. // on the sort ordering of the enumeration since the other reg-classes
  3866. // are sane.
  3867. if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
  3868. return Reg + 1;
  3869. switch(Reg) {
  3870. default: llvm_unreachable("Invalid GPR number!");
  3871. case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
  3872. case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
  3873. case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
  3874. case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
  3875. case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
  3876. case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
  3877. case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
  3878. case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
  3879. }
  3880. }
  3881. // Insert an <Encoding, Register> pair in an ordered vector. Return true on
  3882. // success, or false, if duplicate encoding found.
  3883. static bool
  3884. insertNoDuplicates(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
  3885. unsigned Enc, unsigned Reg) {
  3886. Regs.emplace_back(Enc, Reg);
  3887. for (auto I = Regs.rbegin(), J = I + 1, E = Regs.rend(); J != E; ++I, ++J) {
  3888. if (J->first == Enc) {
  3889. Regs.erase(J.base());
  3890. return false;
  3891. }
  3892. if (J->first < Enc)
  3893. break;
  3894. std::swap(*I, *J);
  3895. }
  3896. return true;
  3897. }
  3898. /// Parse a register list.
  3899. bool ARMAsmParser::parseRegisterList(OperandVector &Operands, bool EnforceOrder,
  3900. bool AllowRAAC) {
  3901. MCAsmParser &Parser = getParser();
  3902. if (Parser.getTok().isNot(AsmToken::LCurly))
  3903. return TokError("Token is not a Left Curly Brace");
  3904. SMLoc S = Parser.getTok().getLoc();
  3905. Parser.Lex(); // Eat '{' token.
  3906. SMLoc RegLoc = Parser.getTok().getLoc();
  3907. // Check the first register in the list to see what register class
  3908. // this is a list of.
  3909. int Reg = tryParseRegister();
  3910. if (Reg == -1)
  3911. return Error(RegLoc, "register expected");
  3912. if (!AllowRAAC && Reg == ARM::RA_AUTH_CODE)
  3913. return Error(RegLoc, "pseudo-register not allowed");
  3914. // The reglist instructions have at most 16 registers, so reserve
  3915. // space for that many.
  3916. int EReg = 0;
  3917. SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
  3918. // Allow Q regs and just interpret them as the two D sub-registers.
  3919. if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
  3920. Reg = getDRegFromQReg(Reg);
  3921. EReg = MRI->getEncodingValue(Reg);
  3922. Registers.emplace_back(EReg, Reg);
  3923. ++Reg;
  3924. }
  3925. const MCRegisterClass *RC;
  3926. if (Reg == ARM::RA_AUTH_CODE ||
  3927. ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
  3928. RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
  3929. else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
  3930. RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
  3931. else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
  3932. RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
  3933. else if (ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains(Reg))
  3934. RC = &ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID];
  3935. else
  3936. return Error(RegLoc, "invalid register in register list");
  3937. // Store the register.
  3938. EReg = MRI->getEncodingValue(Reg);
  3939. Registers.emplace_back(EReg, Reg);
  3940. // This starts immediately after the first register token in the list,
  3941. // so we can see either a comma or a minus (range separator) as a legal
  3942. // next token.
  3943. while (Parser.getTok().is(AsmToken::Comma) ||
  3944. Parser.getTok().is(AsmToken::Minus)) {
  3945. if (Parser.getTok().is(AsmToken::Minus)) {
  3946. if (Reg == ARM::RA_AUTH_CODE)
  3947. return Error(RegLoc, "pseudo-register not allowed");
  3948. Parser.Lex(); // Eat the minus.
  3949. SMLoc AfterMinusLoc = Parser.getTok().getLoc();
  3950. int EndReg = tryParseRegister();
  3951. if (EndReg == -1)
  3952. return Error(AfterMinusLoc, "register expected");
  3953. if (EndReg == ARM::RA_AUTH_CODE)
  3954. return Error(AfterMinusLoc, "pseudo-register not allowed");
  3955. // Allow Q regs and just interpret them as the two D sub-registers.
  3956. if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
  3957. EndReg = getDRegFromQReg(EndReg) + 1;
  3958. // If the register is the same as the start reg, there's nothing
  3959. // more to do.
  3960. if (Reg == EndReg)
  3961. continue;
  3962. // The register must be in the same register class as the first.
  3963. if ((Reg == ARM::RA_AUTH_CODE &&
  3964. RC != &ARMMCRegisterClasses[ARM::GPRRegClassID]) ||
  3965. (Reg != ARM::RA_AUTH_CODE && !RC->contains(Reg)))
  3966. return Error(AfterMinusLoc, "invalid register in register list");
  3967. // Ranges must go from low to high.
  3968. if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
  3969. return Error(AfterMinusLoc, "bad range in register list");
  3970. // Add all the registers in the range to the register list.
  3971. while (Reg != EndReg) {
  3972. Reg = getNextRegister(Reg);
  3973. EReg = MRI->getEncodingValue(Reg);
  3974. if (!insertNoDuplicates(Registers, EReg, Reg)) {
  3975. Warning(AfterMinusLoc, StringRef("duplicated register (") +
  3976. ARMInstPrinter::getRegisterName(Reg) +
  3977. ") in register list");
  3978. }
  3979. }
  3980. continue;
  3981. }
  3982. Parser.Lex(); // Eat the comma.
  3983. RegLoc = Parser.getTok().getLoc();
  3984. int OldReg = Reg;
  3985. const AsmToken RegTok = Parser.getTok();
  3986. Reg = tryParseRegister();
  3987. if (Reg == -1)
  3988. return Error(RegLoc, "register expected");
  3989. if (!AllowRAAC && Reg == ARM::RA_AUTH_CODE)
  3990. return Error(RegLoc, "pseudo-register not allowed");
  3991. // Allow Q regs and just interpret them as the two D sub-registers.
  3992. bool isQReg = false;
  3993. if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
  3994. Reg = getDRegFromQReg(Reg);
  3995. isQReg = true;
  3996. }
  3997. if (Reg != ARM::RA_AUTH_CODE && !RC->contains(Reg) &&
  3998. RC->getID() == ARMMCRegisterClasses[ARM::GPRRegClassID].getID() &&
  3999. ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains(Reg)) {
  4000. // switch the register classes, as GPRwithAPSRnospRegClassID is a partial
  4001. // subset of GPRRegClassId except it contains APSR as well.
  4002. RC = &ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID];
  4003. }
  4004. if (Reg == ARM::VPR &&
  4005. (RC == &ARMMCRegisterClasses[ARM::SPRRegClassID] ||
  4006. RC == &ARMMCRegisterClasses[ARM::DPRRegClassID] ||
  4007. RC == &ARMMCRegisterClasses[ARM::FPWithVPRRegClassID])) {
  4008. RC = &ARMMCRegisterClasses[ARM::FPWithVPRRegClassID];
  4009. EReg = MRI->getEncodingValue(Reg);
  4010. if (!insertNoDuplicates(Registers, EReg, Reg)) {
  4011. Warning(RegLoc, "duplicated register (" + RegTok.getString() +
  4012. ") in register list");
  4013. }
  4014. continue;
  4015. }
  4016. // The register must be in the same register class as the first.
  4017. if ((Reg == ARM::RA_AUTH_CODE &&
  4018. RC != &ARMMCRegisterClasses[ARM::GPRRegClassID]) ||
  4019. (Reg != ARM::RA_AUTH_CODE && !RC->contains(Reg)))
  4020. return Error(RegLoc, "invalid register in register list");
  4021. // In most cases, the list must be monotonically increasing. An
  4022. // exception is CLRM, which is order-independent anyway, so
  4023. // there's no potential for confusion if you write clrm {r2,r1}
  4024. // instead of clrm {r1,r2}.
  4025. if (EnforceOrder &&
  4026. MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
  4027. if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
  4028. Warning(RegLoc, "register list not in ascending order");
  4029. else if (!ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains(Reg))
  4030. return Error(RegLoc, "register list not in ascending order");
  4031. }
  4032. // VFP register lists must also be contiguous.
  4033. if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
  4034. RC != &ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID] &&
  4035. Reg != OldReg + 1)
  4036. return Error(RegLoc, "non-contiguous register range");
  4037. EReg = MRI->getEncodingValue(Reg);
  4038. if (!insertNoDuplicates(Registers, EReg, Reg)) {
  4039. Warning(RegLoc, "duplicated register (" + RegTok.getString() +
  4040. ") in register list");
  4041. }
  4042. if (isQReg) {
  4043. EReg = MRI->getEncodingValue(++Reg);
  4044. Registers.emplace_back(EReg, Reg);
  4045. }
  4046. }
  4047. if (Parser.getTok().isNot(AsmToken::RCurly))
  4048. return Error(Parser.getTok().getLoc(), "'}' expected");
  4049. SMLoc E = Parser.getTok().getEndLoc();
  4050. Parser.Lex(); // Eat '}' token.
  4051. // Push the register list operand.
  4052. Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
  4053. // The ARM system instruction variants for LDM/STM have a '^' token here.
  4054. if (Parser.getTok().is(AsmToken::Caret)) {
  4055. Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
  4056. Parser.Lex(); // Eat '^' token.
  4057. }
  4058. return false;
  4059. }
  4060. // Helper function to parse the lane index for vector lists.
  4061. OperandMatchResultTy ARMAsmParser::
  4062. parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
  4063. MCAsmParser &Parser = getParser();
  4064. Index = 0; // Always return a defined index value.
  4065. if (Parser.getTok().is(AsmToken::LBrac)) {
  4066. Parser.Lex(); // Eat the '['.
  4067. if (Parser.getTok().is(AsmToken::RBrac)) {
  4068. // "Dn[]" is the 'all lanes' syntax.
  4069. LaneKind = AllLanes;
  4070. EndLoc = Parser.getTok().getEndLoc();
  4071. Parser.Lex(); // Eat the ']'.
  4072. return MatchOperand_Success;
  4073. }
  4074. // There's an optional '#' token here. Normally there wouldn't be, but
  4075. // inline assemble puts one in, and it's friendly to accept that.
  4076. if (Parser.getTok().is(AsmToken::Hash))
  4077. Parser.Lex(); // Eat '#' or '$'.
  4078. const MCExpr *LaneIndex;
  4079. SMLoc Loc = Parser.getTok().getLoc();
  4080. if (getParser().parseExpression(LaneIndex)) {
  4081. Error(Loc, "illegal expression");
  4082. return MatchOperand_ParseFail;
  4083. }
  4084. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
  4085. if (!CE) {
  4086. Error(Loc, "lane index must be empty or an integer");
  4087. return MatchOperand_ParseFail;
  4088. }
  4089. if (Parser.getTok().isNot(AsmToken::RBrac)) {
  4090. Error(Parser.getTok().getLoc(), "']' expected");
  4091. return MatchOperand_ParseFail;
  4092. }
  4093. EndLoc = Parser.getTok().getEndLoc();
  4094. Parser.Lex(); // Eat the ']'.
  4095. int64_t Val = CE->getValue();
  4096. // FIXME: Make this range check context sensitive for .8, .16, .32.
  4097. if (Val < 0 || Val > 7) {
  4098. Error(Parser.getTok().getLoc(), "lane index out of range");
  4099. return MatchOperand_ParseFail;
  4100. }
  4101. Index = Val;
  4102. LaneKind = IndexedLane;
  4103. return MatchOperand_Success;
  4104. }
  4105. LaneKind = NoLanes;
  4106. return MatchOperand_Success;
  4107. }
  4108. // parse a vector register list
  4109. OperandMatchResultTy
  4110. ARMAsmParser::parseVectorList(OperandVector &Operands) {
  4111. MCAsmParser &Parser = getParser();
  4112. VectorLaneTy LaneKind;
  4113. unsigned LaneIndex;
  4114. SMLoc S = Parser.getTok().getLoc();
  4115. // As an extension (to match gas), support a plain D register or Q register
  4116. // (without encosing curly braces) as a single or double entry list,
  4117. // respectively.
  4118. if (!hasMVE() && Parser.getTok().is(AsmToken::Identifier)) {
  4119. SMLoc E = Parser.getTok().getEndLoc();
  4120. int Reg = tryParseRegister();
  4121. if (Reg == -1)
  4122. return MatchOperand_NoMatch;
  4123. if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
  4124. OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
  4125. if (Res != MatchOperand_Success)
  4126. return Res;
  4127. switch (LaneKind) {
  4128. case NoLanes:
  4129. Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
  4130. break;
  4131. case AllLanes:
  4132. Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
  4133. S, E));
  4134. break;
  4135. case IndexedLane:
  4136. Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
  4137. LaneIndex,
  4138. false, S, E));
  4139. break;
  4140. }
  4141. return MatchOperand_Success;
  4142. }
  4143. if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
  4144. Reg = getDRegFromQReg(Reg);
  4145. OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
  4146. if (Res != MatchOperand_Success)
  4147. return Res;
  4148. switch (LaneKind) {
  4149. case NoLanes:
  4150. Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
  4151. &ARMMCRegisterClasses[ARM::DPairRegClassID]);
  4152. Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
  4153. break;
  4154. case AllLanes:
  4155. Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
  4156. &ARMMCRegisterClasses[ARM::DPairRegClassID]);
  4157. Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
  4158. S, E));
  4159. break;
  4160. case IndexedLane:
  4161. Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
  4162. LaneIndex,
  4163. false, S, E));
  4164. break;
  4165. }
  4166. return MatchOperand_Success;
  4167. }
  4168. Error(S, "vector register expected");
  4169. return MatchOperand_ParseFail;
  4170. }
  4171. if (Parser.getTok().isNot(AsmToken::LCurly))
  4172. return MatchOperand_NoMatch;
  4173. Parser.Lex(); // Eat '{' token.
  4174. SMLoc RegLoc = Parser.getTok().getLoc();
  4175. int Reg = tryParseRegister();
  4176. if (Reg == -1) {
  4177. Error(RegLoc, "register expected");
  4178. return MatchOperand_ParseFail;
  4179. }
  4180. unsigned Count = 1;
  4181. int Spacing = 0;
  4182. unsigned FirstReg = Reg;
  4183. if (hasMVE() && !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(Reg)) {
  4184. Error(Parser.getTok().getLoc(), "vector register in range Q0-Q7 expected");
  4185. return MatchOperand_ParseFail;
  4186. }
  4187. // The list is of D registers, but we also allow Q regs and just interpret
  4188. // them as the two D sub-registers.
  4189. else if (!hasMVE() && ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
  4190. FirstReg = Reg = getDRegFromQReg(Reg);
  4191. Spacing = 1; // double-spacing requires explicit D registers, otherwise
  4192. // it's ambiguous with four-register single spaced.
  4193. ++Reg;
  4194. ++Count;
  4195. }
  4196. SMLoc E;
  4197. if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
  4198. return MatchOperand_ParseFail;
  4199. while (Parser.getTok().is(AsmToken::Comma) ||
  4200. Parser.getTok().is(AsmToken::Minus)) {
  4201. if (Parser.getTok().is(AsmToken::Minus)) {
  4202. if (!Spacing)
  4203. Spacing = 1; // Register range implies a single spaced list.
  4204. else if (Spacing == 2) {
  4205. Error(Parser.getTok().getLoc(),
  4206. "sequential registers in double spaced list");
  4207. return MatchOperand_ParseFail;
  4208. }
  4209. Parser.Lex(); // Eat the minus.
  4210. SMLoc AfterMinusLoc = Parser.getTok().getLoc();
  4211. int EndReg = tryParseRegister();
  4212. if (EndReg == -1) {
  4213. Error(AfterMinusLoc, "register expected");
  4214. return MatchOperand_ParseFail;
  4215. }
  4216. // Allow Q regs and just interpret them as the two D sub-registers.
  4217. if (!hasMVE() && ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
  4218. EndReg = getDRegFromQReg(EndReg) + 1;
  4219. // If the register is the same as the start reg, there's nothing
  4220. // more to do.
  4221. if (Reg == EndReg)
  4222. continue;
  4223. // The register must be in the same register class as the first.
  4224. if ((hasMVE() &&
  4225. !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(EndReg)) ||
  4226. (!hasMVE() &&
  4227. !ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg))) {
  4228. Error(AfterMinusLoc, "invalid register in register list");
  4229. return MatchOperand_ParseFail;
  4230. }
  4231. // Ranges must go from low to high.
  4232. if (Reg > EndReg) {
  4233. Error(AfterMinusLoc, "bad range in register list");
  4234. return MatchOperand_ParseFail;
  4235. }
  4236. // Parse the lane specifier if present.
  4237. VectorLaneTy NextLaneKind;
  4238. unsigned NextLaneIndex;
  4239. if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
  4240. MatchOperand_Success)
  4241. return MatchOperand_ParseFail;
  4242. if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
  4243. Error(AfterMinusLoc, "mismatched lane index in register list");
  4244. return MatchOperand_ParseFail;
  4245. }
  4246. // Add all the registers in the range to the register list.
  4247. Count += EndReg - Reg;
  4248. Reg = EndReg;
  4249. continue;
  4250. }
  4251. Parser.Lex(); // Eat the comma.
  4252. RegLoc = Parser.getTok().getLoc();
  4253. int OldReg = Reg;
  4254. Reg = tryParseRegister();
  4255. if (Reg == -1) {
  4256. Error(RegLoc, "register expected");
  4257. return MatchOperand_ParseFail;
  4258. }
  4259. if (hasMVE()) {
  4260. if (!ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(Reg)) {
  4261. Error(RegLoc, "vector register in range Q0-Q7 expected");
  4262. return MatchOperand_ParseFail;
  4263. }
  4264. Spacing = 1;
  4265. }
  4266. // vector register lists must be contiguous.
  4267. // It's OK to use the enumeration values directly here rather, as the
  4268. // VFP register classes have the enum sorted properly.
  4269. //
  4270. // The list is of D registers, but we also allow Q regs and just interpret
  4271. // them as the two D sub-registers.
  4272. else if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
  4273. if (!Spacing)
  4274. Spacing = 1; // Register range implies a single spaced list.
  4275. else if (Spacing == 2) {
  4276. Error(RegLoc,
  4277. "invalid register in double-spaced list (must be 'D' register')");
  4278. return MatchOperand_ParseFail;
  4279. }
  4280. Reg = getDRegFromQReg(Reg);
  4281. if (Reg != OldReg + 1) {
  4282. Error(RegLoc, "non-contiguous register range");
  4283. return MatchOperand_ParseFail;
  4284. }
  4285. ++Reg;
  4286. Count += 2;
  4287. // Parse the lane specifier if present.
  4288. VectorLaneTy NextLaneKind;
  4289. unsigned NextLaneIndex;
  4290. SMLoc LaneLoc = Parser.getTok().getLoc();
  4291. if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
  4292. MatchOperand_Success)
  4293. return MatchOperand_ParseFail;
  4294. if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
  4295. Error(LaneLoc, "mismatched lane index in register list");
  4296. return MatchOperand_ParseFail;
  4297. }
  4298. continue;
  4299. }
  4300. // Normal D register.
  4301. // Figure out the register spacing (single or double) of the list if
  4302. // we don't know it already.
  4303. if (!Spacing)
  4304. Spacing = 1 + (Reg == OldReg + 2);
  4305. // Just check that it's contiguous and keep going.
  4306. if (Reg != OldReg + Spacing) {
  4307. Error(RegLoc, "non-contiguous register range");
  4308. return MatchOperand_ParseFail;
  4309. }
  4310. ++Count;
  4311. // Parse the lane specifier if present.
  4312. VectorLaneTy NextLaneKind;
  4313. unsigned NextLaneIndex;
  4314. SMLoc EndLoc = Parser.getTok().getLoc();
  4315. if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
  4316. return MatchOperand_ParseFail;
  4317. if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
  4318. Error(EndLoc, "mismatched lane index in register list");
  4319. return MatchOperand_ParseFail;
  4320. }
  4321. }
  4322. if (Parser.getTok().isNot(AsmToken::RCurly)) {
  4323. Error(Parser.getTok().getLoc(), "'}' expected");
  4324. return MatchOperand_ParseFail;
  4325. }
  4326. E = Parser.getTok().getEndLoc();
  4327. Parser.Lex(); // Eat '}' token.
  4328. switch (LaneKind) {
  4329. case NoLanes:
  4330. case AllLanes: {
  4331. // Two-register operands have been converted to the
  4332. // composite register classes.
  4333. if (Count == 2 && !hasMVE()) {
  4334. const MCRegisterClass *RC = (Spacing == 1) ?
  4335. &ARMMCRegisterClasses[ARM::DPairRegClassID] :
  4336. &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
  4337. FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
  4338. }
  4339. auto Create = (LaneKind == NoLanes ? ARMOperand::CreateVectorList :
  4340. ARMOperand::CreateVectorListAllLanes);
  4341. Operands.push_back(Create(FirstReg, Count, (Spacing == 2), S, E));
  4342. break;
  4343. }
  4344. case IndexedLane:
  4345. Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
  4346. LaneIndex,
  4347. (Spacing == 2),
  4348. S, E));
  4349. break;
  4350. }
  4351. return MatchOperand_Success;
  4352. }
  4353. /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
  4354. OperandMatchResultTy
  4355. ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
  4356. MCAsmParser &Parser = getParser();
  4357. SMLoc S = Parser.getTok().getLoc();
  4358. const AsmToken &Tok = Parser.getTok();
  4359. unsigned Opt;
  4360. if (Tok.is(AsmToken::Identifier)) {
  4361. StringRef OptStr = Tok.getString();
  4362. Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
  4363. .Case("sy", ARM_MB::SY)
  4364. .Case("st", ARM_MB::ST)
  4365. .Case("ld", ARM_MB::LD)
  4366. .Case("sh", ARM_MB::ISH)
  4367. .Case("ish", ARM_MB::ISH)
  4368. .Case("shst", ARM_MB::ISHST)
  4369. .Case("ishst", ARM_MB::ISHST)
  4370. .Case("ishld", ARM_MB::ISHLD)
  4371. .Case("nsh", ARM_MB::NSH)
  4372. .Case("un", ARM_MB::NSH)
  4373. .Case("nshst", ARM_MB::NSHST)
  4374. .Case("nshld", ARM_MB::NSHLD)
  4375. .Case("unst", ARM_MB::NSHST)
  4376. .Case("osh", ARM_MB::OSH)
  4377. .Case("oshst", ARM_MB::OSHST)
  4378. .Case("oshld", ARM_MB::OSHLD)
  4379. .Default(~0U);
  4380. // ishld, oshld, nshld and ld are only available from ARMv8.
  4381. if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
  4382. Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
  4383. Opt = ~0U;
  4384. if (Opt == ~0U)
  4385. return MatchOperand_NoMatch;
  4386. Parser.Lex(); // Eat identifier token.
  4387. } else if (Tok.is(AsmToken::Hash) ||
  4388. Tok.is(AsmToken::Dollar) ||
  4389. Tok.is(AsmToken::Integer)) {
  4390. if (Parser.getTok().isNot(AsmToken::Integer))
  4391. Parser.Lex(); // Eat '#' or '$'.
  4392. SMLoc Loc = Parser.getTok().getLoc();
  4393. const MCExpr *MemBarrierID;
  4394. if (getParser().parseExpression(MemBarrierID)) {
  4395. Error(Loc, "illegal expression");
  4396. return MatchOperand_ParseFail;
  4397. }
  4398. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
  4399. if (!CE) {
  4400. Error(Loc, "constant expression expected");
  4401. return MatchOperand_ParseFail;
  4402. }
  4403. int Val = CE->getValue();
  4404. if (Val & ~0xf) {
  4405. Error(Loc, "immediate value out of range");
  4406. return MatchOperand_ParseFail;
  4407. }
  4408. Opt = ARM_MB::RESERVED_0 + Val;
  4409. } else
  4410. return MatchOperand_ParseFail;
  4411. Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
  4412. return MatchOperand_Success;
  4413. }
  4414. OperandMatchResultTy
  4415. ARMAsmParser::parseTraceSyncBarrierOptOperand(OperandVector &Operands) {
  4416. MCAsmParser &Parser = getParser();
  4417. SMLoc S = Parser.getTok().getLoc();
  4418. const AsmToken &Tok = Parser.getTok();
  4419. if (Tok.isNot(AsmToken::Identifier))
  4420. return MatchOperand_NoMatch;
  4421. if (!Tok.getString().equals_insensitive("csync"))
  4422. return MatchOperand_NoMatch;
  4423. Parser.Lex(); // Eat identifier token.
  4424. Operands.push_back(ARMOperand::CreateTraceSyncBarrierOpt(ARM_TSB::CSYNC, S));
  4425. return MatchOperand_Success;
  4426. }
  4427. /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
  4428. OperandMatchResultTy
  4429. ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
  4430. MCAsmParser &Parser = getParser();
  4431. SMLoc S = Parser.getTok().getLoc();
  4432. const AsmToken &Tok = Parser.getTok();
  4433. unsigned Opt;
  4434. if (Tok.is(AsmToken::Identifier)) {
  4435. StringRef OptStr = Tok.getString();
  4436. if (OptStr.equals_insensitive("sy"))
  4437. Opt = ARM_ISB::SY;
  4438. else
  4439. return MatchOperand_NoMatch;
  4440. Parser.Lex(); // Eat identifier token.
  4441. } else if (Tok.is(AsmToken::Hash) ||
  4442. Tok.is(AsmToken::Dollar) ||
  4443. Tok.is(AsmToken::Integer)) {
  4444. if (Parser.getTok().isNot(AsmToken::Integer))
  4445. Parser.Lex(); // Eat '#' or '$'.
  4446. SMLoc Loc = Parser.getTok().getLoc();
  4447. const MCExpr *ISBarrierID;
  4448. if (getParser().parseExpression(ISBarrierID)) {
  4449. Error(Loc, "illegal expression");
  4450. return MatchOperand_ParseFail;
  4451. }
  4452. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
  4453. if (!CE) {
  4454. Error(Loc, "constant expression expected");
  4455. return MatchOperand_ParseFail;
  4456. }
  4457. int Val = CE->getValue();
  4458. if (Val & ~0xf) {
  4459. Error(Loc, "immediate value out of range");
  4460. return MatchOperand_ParseFail;
  4461. }
  4462. Opt = ARM_ISB::RESERVED_0 + Val;
  4463. } else
  4464. return MatchOperand_ParseFail;
  4465. Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
  4466. (ARM_ISB::InstSyncBOpt)Opt, S));
  4467. return MatchOperand_Success;
  4468. }
  4469. /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
  4470. OperandMatchResultTy
  4471. ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
  4472. MCAsmParser &Parser = getParser();
  4473. SMLoc S = Parser.getTok().getLoc();
  4474. const AsmToken &Tok = Parser.getTok();
  4475. if (!Tok.is(AsmToken::Identifier))
  4476. return MatchOperand_NoMatch;
  4477. StringRef IFlagsStr = Tok.getString();
  4478. // An iflags string of "none" is interpreted to mean that none of the AIF
  4479. // bits are set. Not a terribly useful instruction, but a valid encoding.
  4480. unsigned IFlags = 0;
  4481. if (IFlagsStr != "none") {
  4482. for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
  4483. unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1).lower())
  4484. .Case("a", ARM_PROC::A)
  4485. .Case("i", ARM_PROC::I)
  4486. .Case("f", ARM_PROC::F)
  4487. .Default(~0U);
  4488. // If some specific iflag is already set, it means that some letter is
  4489. // present more than once, this is not acceptable.
  4490. if (Flag == ~0U || (IFlags & Flag))
  4491. return MatchOperand_NoMatch;
  4492. IFlags |= Flag;
  4493. }
  4494. }
  4495. Parser.Lex(); // Eat identifier token.
  4496. Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
  4497. return MatchOperand_Success;
  4498. }
  4499. /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
  4500. OperandMatchResultTy
  4501. ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
  4502. MCAsmParser &Parser = getParser();
  4503. SMLoc S = Parser.getTok().getLoc();
  4504. const AsmToken &Tok = Parser.getTok();
  4505. if (Tok.is(AsmToken::Integer)) {
  4506. int64_t Val = Tok.getIntVal();
  4507. if (Val > 255 || Val < 0) {
  4508. return MatchOperand_NoMatch;
  4509. }
  4510. unsigned SYSmvalue = Val & 0xFF;
  4511. Parser.Lex();
  4512. Operands.push_back(ARMOperand::CreateMSRMask(SYSmvalue, S));
  4513. return MatchOperand_Success;
  4514. }
  4515. if (!Tok.is(AsmToken::Identifier))
  4516. return MatchOperand_NoMatch;
  4517. StringRef Mask = Tok.getString();
  4518. if (isMClass()) {
  4519. auto TheReg = ARMSysReg::lookupMClassSysRegByName(Mask.lower());
  4520. if (!TheReg || !TheReg->hasRequiredFeatures(getSTI().getFeatureBits()))
  4521. return MatchOperand_NoMatch;
  4522. unsigned SYSmvalue = TheReg->Encoding & 0xFFF;
  4523. Parser.Lex(); // Eat identifier token.
  4524. Operands.push_back(ARMOperand::CreateMSRMask(SYSmvalue, S));
  4525. return MatchOperand_Success;
  4526. }
  4527. // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
  4528. size_t Start = 0, Next = Mask.find('_');
  4529. StringRef Flags = "";
  4530. std::string SpecReg = Mask.slice(Start, Next).lower();
  4531. if (Next != StringRef::npos)
  4532. Flags = Mask.slice(Next+1, Mask.size());
  4533. // FlagsVal contains the complete mask:
  4534. // 3-0: Mask
  4535. // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
  4536. unsigned FlagsVal = 0;
  4537. if (SpecReg == "apsr") {
  4538. FlagsVal = StringSwitch<unsigned>(Flags)
  4539. .Case("nzcvq", 0x8) // same as CPSR_f
  4540. .Case("g", 0x4) // same as CPSR_s
  4541. .Case("nzcvqg", 0xc) // same as CPSR_fs
  4542. .Default(~0U);
  4543. if (FlagsVal == ~0U) {
  4544. if (!Flags.empty())
  4545. return MatchOperand_NoMatch;
  4546. else
  4547. FlagsVal = 8; // No flag
  4548. }
  4549. } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
  4550. // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
  4551. if (Flags == "all" || Flags == "")
  4552. Flags = "fc";
  4553. for (int i = 0, e = Flags.size(); i != e; ++i) {
  4554. unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
  4555. .Case("c", 1)
  4556. .Case("x", 2)
  4557. .Case("s", 4)
  4558. .Case("f", 8)
  4559. .Default(~0U);
  4560. // If some specific flag is already set, it means that some letter is
  4561. // present more than once, this is not acceptable.
  4562. if (Flag == ~0U || (FlagsVal & Flag))
  4563. return MatchOperand_NoMatch;
  4564. FlagsVal |= Flag;
  4565. }
  4566. } else // No match for special register.
  4567. return MatchOperand_NoMatch;
  4568. // Special register without flags is NOT equivalent to "fc" flags.
  4569. // NOTE: This is a divergence from gas' behavior. Uncommenting the following
  4570. // two lines would enable gas compatibility at the expense of breaking
  4571. // round-tripping.
  4572. //
  4573. // if (!FlagsVal)
  4574. // FlagsVal = 0x9;
  4575. // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
  4576. if (SpecReg == "spsr")
  4577. FlagsVal |= 16;
  4578. Parser.Lex(); // Eat identifier token.
  4579. Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
  4580. return MatchOperand_Success;
  4581. }
  4582. /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
  4583. /// use in the MRS/MSR instructions added to support virtualization.
  4584. OperandMatchResultTy
  4585. ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
  4586. MCAsmParser &Parser = getParser();
  4587. SMLoc S = Parser.getTok().getLoc();
  4588. const AsmToken &Tok = Parser.getTok();
  4589. if (!Tok.is(AsmToken::Identifier))
  4590. return MatchOperand_NoMatch;
  4591. StringRef RegName = Tok.getString();
  4592. auto TheReg = ARMBankedReg::lookupBankedRegByName(RegName.lower());
  4593. if (!TheReg)
  4594. return MatchOperand_NoMatch;
  4595. unsigned Encoding = TheReg->Encoding;
  4596. Parser.Lex(); // Eat identifier token.
  4597. Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
  4598. return MatchOperand_Success;
  4599. }
  4600. OperandMatchResultTy
  4601. ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
  4602. int High) {
  4603. MCAsmParser &Parser = getParser();
  4604. const AsmToken &Tok = Parser.getTok();
  4605. if (Tok.isNot(AsmToken::Identifier)) {
  4606. Error(Parser.getTok().getLoc(), Op + " operand expected.");
  4607. return MatchOperand_ParseFail;
  4608. }
  4609. StringRef ShiftName = Tok.getString();
  4610. std::string LowerOp = Op.lower();
  4611. std::string UpperOp = Op.upper();
  4612. if (ShiftName != LowerOp && ShiftName != UpperOp) {
  4613. Error(Parser.getTok().getLoc(), Op + " operand expected.");
  4614. return MatchOperand_ParseFail;
  4615. }
  4616. Parser.Lex(); // Eat shift type token.
  4617. // There must be a '#' and a shift amount.
  4618. if (Parser.getTok().isNot(AsmToken::Hash) &&
  4619. Parser.getTok().isNot(AsmToken::Dollar)) {
  4620. Error(Parser.getTok().getLoc(), "'#' expected");
  4621. return MatchOperand_ParseFail;
  4622. }
  4623. Parser.Lex(); // Eat hash token.
  4624. const MCExpr *ShiftAmount;
  4625. SMLoc Loc = Parser.getTok().getLoc();
  4626. SMLoc EndLoc;
  4627. if (getParser().parseExpression(ShiftAmount, EndLoc)) {
  4628. Error(Loc, "illegal expression");
  4629. return MatchOperand_ParseFail;
  4630. }
  4631. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
  4632. if (!CE) {
  4633. Error(Loc, "constant expression expected");
  4634. return MatchOperand_ParseFail;
  4635. }
  4636. int Val = CE->getValue();
  4637. if (Val < Low || Val > High) {
  4638. Error(Loc, "immediate value out of range");
  4639. return MatchOperand_ParseFail;
  4640. }
  4641. Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
  4642. return MatchOperand_Success;
  4643. }
  4644. OperandMatchResultTy
  4645. ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
  4646. MCAsmParser &Parser = getParser();
  4647. const AsmToken &Tok = Parser.getTok();
  4648. SMLoc S = Tok.getLoc();
  4649. if (Tok.isNot(AsmToken::Identifier)) {
  4650. Error(S, "'be' or 'le' operand expected");
  4651. return MatchOperand_ParseFail;
  4652. }
  4653. int Val = StringSwitch<int>(Tok.getString().lower())
  4654. .Case("be", 1)
  4655. .Case("le", 0)
  4656. .Default(-1);
  4657. Parser.Lex(); // Eat the token.
  4658. if (Val == -1) {
  4659. Error(S, "'be' or 'le' operand expected");
  4660. return MatchOperand_ParseFail;
  4661. }
  4662. Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::create(Val,
  4663. getContext()),
  4664. S, Tok.getEndLoc()));
  4665. return MatchOperand_Success;
  4666. }
  4667. /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
  4668. /// instructions. Legal values are:
  4669. /// lsl #n 'n' in [0,31]
  4670. /// asr #n 'n' in [1,32]
  4671. /// n == 32 encoded as n == 0.
  4672. OperandMatchResultTy
  4673. ARMAsmParser::parseShifterImm(OperandVector &Operands) {
  4674. MCAsmParser &Parser = getParser();
  4675. const AsmToken &Tok = Parser.getTok();
  4676. SMLoc S = Tok.getLoc();
  4677. if (Tok.isNot(AsmToken::Identifier)) {
  4678. Error(S, "shift operator 'asr' or 'lsl' expected");
  4679. return MatchOperand_ParseFail;
  4680. }
  4681. StringRef ShiftName = Tok.getString();
  4682. bool isASR;
  4683. if (ShiftName == "lsl" || ShiftName == "LSL")
  4684. isASR = false;
  4685. else if (ShiftName == "asr" || ShiftName == "ASR")
  4686. isASR = true;
  4687. else {
  4688. Error(S, "shift operator 'asr' or 'lsl' expected");
  4689. return MatchOperand_ParseFail;
  4690. }
  4691. Parser.Lex(); // Eat the operator.
  4692. // A '#' and a shift amount.
  4693. if (Parser.getTok().isNot(AsmToken::Hash) &&
  4694. Parser.getTok().isNot(AsmToken::Dollar)) {
  4695. Error(Parser.getTok().getLoc(), "'#' expected");
  4696. return MatchOperand_ParseFail;
  4697. }
  4698. Parser.Lex(); // Eat hash token.
  4699. SMLoc ExLoc = Parser.getTok().getLoc();
  4700. const MCExpr *ShiftAmount;
  4701. SMLoc EndLoc;
  4702. if (getParser().parseExpression(ShiftAmount, EndLoc)) {
  4703. Error(ExLoc, "malformed shift expression");
  4704. return MatchOperand_ParseFail;
  4705. }
  4706. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
  4707. if (!CE) {
  4708. Error(ExLoc, "shift amount must be an immediate");
  4709. return MatchOperand_ParseFail;
  4710. }
  4711. int64_t Val = CE->getValue();
  4712. if (isASR) {
  4713. // Shift amount must be in [1,32]
  4714. if (Val < 1 || Val > 32) {
  4715. Error(ExLoc, "'asr' shift amount must be in range [1,32]");
  4716. return MatchOperand_ParseFail;
  4717. }
  4718. // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
  4719. if (isThumb() && Val == 32) {
  4720. Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
  4721. return MatchOperand_ParseFail;
  4722. }
  4723. if (Val == 32) Val = 0;
  4724. } else {
  4725. // Shift amount must be in [1,32]
  4726. if (Val < 0 || Val > 31) {
  4727. Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
  4728. return MatchOperand_ParseFail;
  4729. }
  4730. }
  4731. Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
  4732. return MatchOperand_Success;
  4733. }
  4734. /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
  4735. /// of instructions. Legal values are:
  4736. /// ror #n 'n' in {0, 8, 16, 24}
  4737. OperandMatchResultTy
  4738. ARMAsmParser::parseRotImm(OperandVector &Operands) {
  4739. MCAsmParser &Parser = getParser();
  4740. const AsmToken &Tok = Parser.getTok();
  4741. SMLoc S = Tok.getLoc();
  4742. if (Tok.isNot(AsmToken::Identifier))
  4743. return MatchOperand_NoMatch;
  4744. StringRef ShiftName = Tok.getString();
  4745. if (ShiftName != "ror" && ShiftName != "ROR")
  4746. return MatchOperand_NoMatch;
  4747. Parser.Lex(); // Eat the operator.
  4748. // A '#' and a rotate amount.
  4749. if (Parser.getTok().isNot(AsmToken::Hash) &&
  4750. Parser.getTok().isNot(AsmToken::Dollar)) {
  4751. Error(Parser.getTok().getLoc(), "'#' expected");
  4752. return MatchOperand_ParseFail;
  4753. }
  4754. Parser.Lex(); // Eat hash token.
  4755. SMLoc ExLoc = Parser.getTok().getLoc();
  4756. const MCExpr *ShiftAmount;
  4757. SMLoc EndLoc;
  4758. if (getParser().parseExpression(ShiftAmount, EndLoc)) {
  4759. Error(ExLoc, "malformed rotate expression");
  4760. return MatchOperand_ParseFail;
  4761. }
  4762. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
  4763. if (!CE) {
  4764. Error(ExLoc, "rotate amount must be an immediate");
  4765. return MatchOperand_ParseFail;
  4766. }
  4767. int64_t Val = CE->getValue();
  4768. // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
  4769. // normally, zero is represented in asm by omitting the rotate operand
  4770. // entirely.
  4771. if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
  4772. Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
  4773. return MatchOperand_ParseFail;
  4774. }
  4775. Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
  4776. return MatchOperand_Success;
  4777. }
  4778. OperandMatchResultTy
  4779. ARMAsmParser::parseModImm(OperandVector &Operands) {
  4780. MCAsmParser &Parser = getParser();
  4781. MCAsmLexer &Lexer = getLexer();
  4782. int64_t Imm1, Imm2;
  4783. SMLoc S = Parser.getTok().getLoc();
  4784. // 1) A mod_imm operand can appear in the place of a register name:
  4785. // add r0, #mod_imm
  4786. // add r0, r0, #mod_imm
  4787. // to correctly handle the latter, we bail out as soon as we see an
  4788. // identifier.
  4789. //
  4790. // 2) Similarly, we do not want to parse into complex operands:
  4791. // mov r0, #mod_imm
  4792. // mov r0, :lower16:(_foo)
  4793. if (Parser.getTok().is(AsmToken::Identifier) ||
  4794. Parser.getTok().is(AsmToken::Colon))
  4795. return MatchOperand_NoMatch;
  4796. // Hash (dollar) is optional as per the ARMARM
  4797. if (Parser.getTok().is(AsmToken::Hash) ||
  4798. Parser.getTok().is(AsmToken::Dollar)) {
  4799. // Avoid parsing into complex operands (#:)
  4800. if (Lexer.peekTok().is(AsmToken::Colon))
  4801. return MatchOperand_NoMatch;
  4802. // Eat the hash (dollar)
  4803. Parser.Lex();
  4804. }
  4805. SMLoc Sx1, Ex1;
  4806. Sx1 = Parser.getTok().getLoc();
  4807. const MCExpr *Imm1Exp;
  4808. if (getParser().parseExpression(Imm1Exp, Ex1)) {
  4809. Error(Sx1, "malformed expression");
  4810. return MatchOperand_ParseFail;
  4811. }
  4812. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
  4813. if (CE) {
  4814. // Immediate must fit within 32-bits
  4815. Imm1 = CE->getValue();
  4816. int Enc = ARM_AM::getSOImmVal(Imm1);
  4817. if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
  4818. // We have a match!
  4819. Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
  4820. (Enc & 0xF00) >> 7,
  4821. Sx1, Ex1));
  4822. return MatchOperand_Success;
  4823. }
  4824. // We have parsed an immediate which is not for us, fallback to a plain
  4825. // immediate. This can happen for instruction aliases. For an example,
  4826. // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
  4827. // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
  4828. // instruction with a mod_imm operand. The alias is defined such that the
  4829. // parser method is shared, that's why we have to do this here.
  4830. if (Parser.getTok().is(AsmToken::EndOfStatement)) {
  4831. Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
  4832. return MatchOperand_Success;
  4833. }
  4834. } else {
  4835. // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
  4836. // MCFixup). Fallback to a plain immediate.
  4837. Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
  4838. return MatchOperand_Success;
  4839. }
  4840. // From this point onward, we expect the input to be a (#bits, #rot) pair
  4841. if (Parser.getTok().isNot(AsmToken::Comma)) {
  4842. Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
  4843. return MatchOperand_ParseFail;
  4844. }
  4845. if (Imm1 & ~0xFF) {
  4846. Error(Sx1, "immediate operand must a number in the range [0, 255]");
  4847. return MatchOperand_ParseFail;
  4848. }
  4849. // Eat the comma
  4850. Parser.Lex();
  4851. // Repeat for #rot
  4852. SMLoc Sx2, Ex2;
  4853. Sx2 = Parser.getTok().getLoc();
  4854. // Eat the optional hash (dollar)
  4855. if (Parser.getTok().is(AsmToken::Hash) ||
  4856. Parser.getTok().is(AsmToken::Dollar))
  4857. Parser.Lex();
  4858. const MCExpr *Imm2Exp;
  4859. if (getParser().parseExpression(Imm2Exp, Ex2)) {
  4860. Error(Sx2, "malformed expression");
  4861. return MatchOperand_ParseFail;
  4862. }
  4863. CE = dyn_cast<MCConstantExpr>(Imm2Exp);
  4864. if (CE) {
  4865. Imm2 = CE->getValue();
  4866. if (!(Imm2 & ~0x1E)) {
  4867. // We have a match!
  4868. Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
  4869. return MatchOperand_Success;
  4870. }
  4871. Error(Sx2, "immediate operand must an even number in the range [0, 30]");
  4872. return MatchOperand_ParseFail;
  4873. } else {
  4874. Error(Sx2, "constant expression expected");
  4875. return MatchOperand_ParseFail;
  4876. }
  4877. }
  4878. OperandMatchResultTy
  4879. ARMAsmParser::parseBitfield(OperandVector &Operands) {
  4880. MCAsmParser &Parser = getParser();
  4881. SMLoc S = Parser.getTok().getLoc();
  4882. // The bitfield descriptor is really two operands, the LSB and the width.
  4883. if (Parser.getTok().isNot(AsmToken::Hash) &&
  4884. Parser.getTok().isNot(AsmToken::Dollar)) {
  4885. Error(Parser.getTok().getLoc(), "'#' expected");
  4886. return MatchOperand_ParseFail;
  4887. }
  4888. Parser.Lex(); // Eat hash token.
  4889. const MCExpr *LSBExpr;
  4890. SMLoc E = Parser.getTok().getLoc();
  4891. if (getParser().parseExpression(LSBExpr)) {
  4892. Error(E, "malformed immediate expression");
  4893. return MatchOperand_ParseFail;
  4894. }
  4895. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
  4896. if (!CE) {
  4897. Error(E, "'lsb' operand must be an immediate");
  4898. return MatchOperand_ParseFail;
  4899. }
  4900. int64_t LSB = CE->getValue();
  4901. // The LSB must be in the range [0,31]
  4902. if (LSB < 0 || LSB > 31) {
  4903. Error(E, "'lsb' operand must be in the range [0,31]");
  4904. return MatchOperand_ParseFail;
  4905. }
  4906. E = Parser.getTok().getLoc();
  4907. // Expect another immediate operand.
  4908. if (Parser.getTok().isNot(AsmToken::Comma)) {
  4909. Error(Parser.getTok().getLoc(), "too few operands");
  4910. return MatchOperand_ParseFail;
  4911. }
  4912. Parser.Lex(); // Eat hash token.
  4913. if (Parser.getTok().isNot(AsmToken::Hash) &&
  4914. Parser.getTok().isNot(AsmToken::Dollar)) {
  4915. Error(Parser.getTok().getLoc(), "'#' expected");
  4916. return MatchOperand_ParseFail;
  4917. }
  4918. Parser.Lex(); // Eat hash token.
  4919. const MCExpr *WidthExpr;
  4920. SMLoc EndLoc;
  4921. if (getParser().parseExpression(WidthExpr, EndLoc)) {
  4922. Error(E, "malformed immediate expression");
  4923. return MatchOperand_ParseFail;
  4924. }
  4925. CE = dyn_cast<MCConstantExpr>(WidthExpr);
  4926. if (!CE) {
  4927. Error(E, "'width' operand must be an immediate");
  4928. return MatchOperand_ParseFail;
  4929. }
  4930. int64_t Width = CE->getValue();
  4931. // The LSB must be in the range [1,32-lsb]
  4932. if (Width < 1 || Width > 32 - LSB) {
  4933. Error(E, "'width' operand must be in the range [1,32-lsb]");
  4934. return MatchOperand_ParseFail;
  4935. }
  4936. Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
  4937. return MatchOperand_Success;
  4938. }
  4939. OperandMatchResultTy
  4940. ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
  4941. // Check for a post-index addressing register operand. Specifically:
  4942. // postidx_reg := '+' register {, shift}
  4943. // | '-' register {, shift}
  4944. // | register {, shift}
  4945. // This method must return MatchOperand_NoMatch without consuming any tokens
  4946. // in the case where there is no match, as other alternatives take other
  4947. // parse methods.
  4948. MCAsmParser &Parser = getParser();
  4949. AsmToken Tok = Parser.getTok();
  4950. SMLoc S = Tok.getLoc();
  4951. bool haveEaten = false;
  4952. bool isAdd = true;
  4953. if (Tok.is(AsmToken::Plus)) {
  4954. Parser.Lex(); // Eat the '+' token.
  4955. haveEaten = true;
  4956. } else if (Tok.is(AsmToken::Minus)) {
  4957. Parser.Lex(); // Eat the '-' token.
  4958. isAdd = false;
  4959. haveEaten = true;
  4960. }
  4961. SMLoc E = Parser.getTok().getEndLoc();
  4962. int Reg = tryParseRegister();
  4963. if (Reg == -1) {
  4964. if (!haveEaten)
  4965. return MatchOperand_NoMatch;
  4966. Error(Parser.getTok().getLoc(), "register expected");
  4967. return MatchOperand_ParseFail;
  4968. }
  4969. ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
  4970. unsigned ShiftImm = 0;
  4971. if (Parser.getTok().is(AsmToken::Comma)) {
  4972. Parser.Lex(); // Eat the ','.
  4973. if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
  4974. return MatchOperand_ParseFail;
  4975. // FIXME: Only approximates end...may include intervening whitespace.
  4976. E = Parser.getTok().getLoc();
  4977. }
  4978. Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
  4979. ShiftImm, S, E));
  4980. return MatchOperand_Success;
  4981. }
  4982. OperandMatchResultTy
  4983. ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
  4984. // Check for a post-index addressing register operand. Specifically:
  4985. // am3offset := '+' register
  4986. // | '-' register
  4987. // | register
  4988. // | # imm
  4989. // | # + imm
  4990. // | # - imm
  4991. // This method must return MatchOperand_NoMatch without consuming any tokens
  4992. // in the case where there is no match, as other alternatives take other
  4993. // parse methods.
  4994. MCAsmParser &Parser = getParser();
  4995. AsmToken Tok = Parser.getTok();
  4996. SMLoc S = Tok.getLoc();
  4997. // Do immediates first, as we always parse those if we have a '#'.
  4998. if (Parser.getTok().is(AsmToken::Hash) ||
  4999. Parser.getTok().is(AsmToken::Dollar)) {
  5000. Parser.Lex(); // Eat '#' or '$'.
  5001. // Explicitly look for a '-', as we need to encode negative zero
  5002. // differently.
  5003. bool isNegative = Parser.getTok().is(AsmToken::Minus);
  5004. const MCExpr *Offset;
  5005. SMLoc E;
  5006. if (getParser().parseExpression(Offset, E))
  5007. return MatchOperand_ParseFail;
  5008. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
  5009. if (!CE) {
  5010. Error(S, "constant expression expected");
  5011. return MatchOperand_ParseFail;
  5012. }
  5013. // Negative zero is encoded as the flag value
  5014. // std::numeric_limits<int32_t>::min().
  5015. int32_t Val = CE->getValue();
  5016. if (isNegative && Val == 0)
  5017. Val = std::numeric_limits<int32_t>::min();
  5018. Operands.push_back(
  5019. ARMOperand::CreateImm(MCConstantExpr::create(Val, getContext()), S, E));
  5020. return MatchOperand_Success;
  5021. }
  5022. bool haveEaten = false;
  5023. bool isAdd = true;
  5024. if (Tok.is(AsmToken::Plus)) {
  5025. Parser.Lex(); // Eat the '+' token.
  5026. haveEaten = true;
  5027. } else if (Tok.is(AsmToken::Minus)) {
  5028. Parser.Lex(); // Eat the '-' token.
  5029. isAdd = false;
  5030. haveEaten = true;
  5031. }
  5032. Tok = Parser.getTok();
  5033. int Reg = tryParseRegister();
  5034. if (Reg == -1) {
  5035. if (!haveEaten)
  5036. return MatchOperand_NoMatch;
  5037. Error(Tok.getLoc(), "register expected");
  5038. return MatchOperand_ParseFail;
  5039. }
  5040. Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
  5041. 0, S, Tok.getEndLoc()));
  5042. return MatchOperand_Success;
  5043. }
  5044. /// Convert parsed operands to MCInst. Needed here because this instruction
  5045. /// only has two register operands, but multiplication is commutative so
  5046. /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
  5047. void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
  5048. const OperandVector &Operands) {
  5049. ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
  5050. ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
  5051. // If we have a three-operand form, make sure to set Rn to be the operand
  5052. // that isn't the same as Rd.
  5053. unsigned RegOp = 4;
  5054. if (Operands.size() == 6 &&
  5055. ((ARMOperand &)*Operands[4]).getReg() ==
  5056. ((ARMOperand &)*Operands[3]).getReg())
  5057. RegOp = 5;
  5058. ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
  5059. Inst.addOperand(Inst.getOperand(0));
  5060. ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
  5061. }
  5062. void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
  5063. const OperandVector &Operands) {
  5064. int CondOp = -1, ImmOp = -1;
  5065. switch(Inst.getOpcode()) {
  5066. case ARM::tB:
  5067. case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
  5068. case ARM::t2B:
  5069. case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
  5070. default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
  5071. }
  5072. // first decide whether or not the branch should be conditional
  5073. // by looking at it's location relative to an IT block
  5074. if(inITBlock()) {
  5075. // inside an IT block we cannot have any conditional branches. any
  5076. // such instructions needs to be converted to unconditional form
  5077. switch(Inst.getOpcode()) {
  5078. case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
  5079. case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
  5080. }
  5081. } else {
  5082. // outside IT blocks we can only have unconditional branches with AL
  5083. // condition code or conditional branches with non-AL condition code
  5084. unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
  5085. switch(Inst.getOpcode()) {
  5086. case ARM::tB:
  5087. case ARM::tBcc:
  5088. Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
  5089. break;
  5090. case ARM::t2B:
  5091. case ARM::t2Bcc:
  5092. Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
  5093. break;
  5094. }
  5095. }
  5096. // now decide on encoding size based on branch target range
  5097. switch(Inst.getOpcode()) {
  5098. // classify tB as either t2B or t1B based on range of immediate operand
  5099. case ARM::tB: {
  5100. ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
  5101. if (!op.isSignedOffset<11, 1>() && isThumb() && hasV8MBaseline())
  5102. Inst.setOpcode(ARM::t2B);
  5103. break;
  5104. }
  5105. // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
  5106. case ARM::tBcc: {
  5107. ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
  5108. if (!op.isSignedOffset<8, 1>() && isThumb() && hasV8MBaseline())
  5109. Inst.setOpcode(ARM::t2Bcc);
  5110. break;
  5111. }
  5112. }
  5113. ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
  5114. ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
  5115. }
  5116. void ARMAsmParser::cvtMVEVMOVQtoDReg(
  5117. MCInst &Inst, const OperandVector &Operands) {
  5118. // mnemonic, condition code, Rt, Rt2, Qd, idx, Qd again, idx2
  5119. assert(Operands.size() == 8);
  5120. ((ARMOperand &)*Operands[2]).addRegOperands(Inst, 1); // Rt
  5121. ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1); // Rt2
  5122. ((ARMOperand &)*Operands[4]).addRegOperands(Inst, 1); // Qd
  5123. ((ARMOperand &)*Operands[5]).addMVEPairVectorIndexOperands(Inst, 1); // idx
  5124. // skip second copy of Qd in Operands[6]
  5125. ((ARMOperand &)*Operands[7]).addMVEPairVectorIndexOperands(Inst, 1); // idx2
  5126. ((ARMOperand &)*Operands[1]).addCondCodeOperands(Inst, 2); // condition code
  5127. }
  5128. /// Parse an ARM memory expression, return false if successful else return true
  5129. /// or an error. The first token must be a '[' when called.
  5130. bool ARMAsmParser::parseMemory(OperandVector &Operands) {
  5131. MCAsmParser &Parser = getParser();
  5132. SMLoc S, E;
  5133. if (Parser.getTok().isNot(AsmToken::LBrac))
  5134. return TokError("Token is not a Left Bracket");
  5135. S = Parser.getTok().getLoc();
  5136. Parser.Lex(); // Eat left bracket token.
  5137. const AsmToken &BaseRegTok = Parser.getTok();
  5138. int BaseRegNum = tryParseRegister();
  5139. if (BaseRegNum == -1)
  5140. return Error(BaseRegTok.getLoc(), "register expected");
  5141. // The next token must either be a comma, a colon or a closing bracket.
  5142. const AsmToken &Tok = Parser.getTok();
  5143. if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
  5144. !Tok.is(AsmToken::RBrac))
  5145. return Error(Tok.getLoc(), "malformed memory operand");
  5146. if (Tok.is(AsmToken::RBrac)) {
  5147. E = Tok.getEndLoc();
  5148. Parser.Lex(); // Eat right bracket token.
  5149. Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
  5150. ARM_AM::no_shift, 0, 0, false,
  5151. S, E));
  5152. // If there's a pre-indexing writeback marker, '!', just add it as a token
  5153. // operand. It's rather odd, but syntactically valid.
  5154. if (Parser.getTok().is(AsmToken::Exclaim)) {
  5155. Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
  5156. Parser.Lex(); // Eat the '!'.
  5157. }
  5158. return false;
  5159. }
  5160. assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
  5161. "Lost colon or comma in memory operand?!");
  5162. if (Tok.is(AsmToken::Comma)) {
  5163. Parser.Lex(); // Eat the comma.
  5164. }
  5165. // If we have a ':', it's an alignment specifier.
  5166. if (Parser.getTok().is(AsmToken::Colon)) {
  5167. Parser.Lex(); // Eat the ':'.
  5168. E = Parser.getTok().getLoc();
  5169. SMLoc AlignmentLoc = Tok.getLoc();
  5170. const MCExpr *Expr;
  5171. if (getParser().parseExpression(Expr))
  5172. return true;
  5173. // The expression has to be a constant. Memory references with relocations
  5174. // don't come through here, as they use the <label> forms of the relevant
  5175. // instructions.
  5176. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
  5177. if (!CE)
  5178. return Error (E, "constant expression expected");
  5179. unsigned Align = 0;
  5180. switch (CE->getValue()) {
  5181. default:
  5182. return Error(E,
  5183. "alignment specifier must be 16, 32, 64, 128, or 256 bits");
  5184. case 16: Align = 2; break;
  5185. case 32: Align = 4; break;
  5186. case 64: Align = 8; break;
  5187. case 128: Align = 16; break;
  5188. case 256: Align = 32; break;
  5189. }
  5190. // Now we should have the closing ']'
  5191. if (Parser.getTok().isNot(AsmToken::RBrac))
  5192. return Error(Parser.getTok().getLoc(), "']' expected");
  5193. E = Parser.getTok().getEndLoc();
  5194. Parser.Lex(); // Eat right bracket token.
  5195. // Don't worry about range checking the value here. That's handled by
  5196. // the is*() predicates.
  5197. Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
  5198. ARM_AM::no_shift, 0, Align,
  5199. false, S, E, AlignmentLoc));
  5200. // If there's a pre-indexing writeback marker, '!', just add it as a token
  5201. // operand.
  5202. if (Parser.getTok().is(AsmToken::Exclaim)) {
  5203. Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
  5204. Parser.Lex(); // Eat the '!'.
  5205. }
  5206. return false;
  5207. }
  5208. // If we have a '#' or '$', it's an immediate offset, else assume it's a
  5209. // register offset. Be friendly and also accept a plain integer or expression
  5210. // (without a leading hash) for gas compatibility.
  5211. if (Parser.getTok().is(AsmToken::Hash) ||
  5212. Parser.getTok().is(AsmToken::Dollar) ||
  5213. Parser.getTok().is(AsmToken::LParen) ||
  5214. Parser.getTok().is(AsmToken::Integer)) {
  5215. if (Parser.getTok().is(AsmToken::Hash) ||
  5216. Parser.getTok().is(AsmToken::Dollar))
  5217. Parser.Lex(); // Eat '#' or '$'
  5218. E = Parser.getTok().getLoc();
  5219. bool isNegative = getParser().getTok().is(AsmToken::Minus);
  5220. const MCExpr *Offset, *AdjustedOffset;
  5221. if (getParser().parseExpression(Offset))
  5222. return true;
  5223. if (const auto *CE = dyn_cast<MCConstantExpr>(Offset)) {
  5224. // If the constant was #-0, represent it as
  5225. // std::numeric_limits<int32_t>::min().
  5226. int32_t Val = CE->getValue();
  5227. if (isNegative && Val == 0)
  5228. CE = MCConstantExpr::create(std::numeric_limits<int32_t>::min(),
  5229. getContext());
  5230. // Don't worry about range checking the value here. That's handled by
  5231. // the is*() predicates.
  5232. AdjustedOffset = CE;
  5233. } else
  5234. AdjustedOffset = Offset;
  5235. Operands.push_back(ARMOperand::CreateMem(
  5236. BaseRegNum, AdjustedOffset, 0, ARM_AM::no_shift, 0, 0, false, S, E));
  5237. // Now we should have the closing ']'
  5238. if (Parser.getTok().isNot(AsmToken::RBrac))
  5239. return Error(Parser.getTok().getLoc(), "']' expected");
  5240. E = Parser.getTok().getEndLoc();
  5241. Parser.Lex(); // Eat right bracket token.
  5242. // If there's a pre-indexing writeback marker, '!', just add it as a token
  5243. // operand.
  5244. if (Parser.getTok().is(AsmToken::Exclaim)) {
  5245. Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
  5246. Parser.Lex(); // Eat the '!'.
  5247. }
  5248. return false;
  5249. }
  5250. // The register offset is optionally preceded by a '+' or '-'
  5251. bool isNegative = false;
  5252. if (Parser.getTok().is(AsmToken::Minus)) {
  5253. isNegative = true;
  5254. Parser.Lex(); // Eat the '-'.
  5255. } else if (Parser.getTok().is(AsmToken::Plus)) {
  5256. // Nothing to do.
  5257. Parser.Lex(); // Eat the '+'.
  5258. }
  5259. E = Parser.getTok().getLoc();
  5260. int OffsetRegNum = tryParseRegister();
  5261. if (OffsetRegNum == -1)
  5262. return Error(E, "register expected");
  5263. // If there's a shift operator, handle it.
  5264. ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
  5265. unsigned ShiftImm = 0;
  5266. if (Parser.getTok().is(AsmToken::Comma)) {
  5267. Parser.Lex(); // Eat the ','.
  5268. if (parseMemRegOffsetShift(ShiftType, ShiftImm))
  5269. return true;
  5270. }
  5271. // Now we should have the closing ']'
  5272. if (Parser.getTok().isNot(AsmToken::RBrac))
  5273. return Error(Parser.getTok().getLoc(), "']' expected");
  5274. E = Parser.getTok().getEndLoc();
  5275. Parser.Lex(); // Eat right bracket token.
  5276. Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
  5277. ShiftType, ShiftImm, 0, isNegative,
  5278. S, E));
  5279. // If there's a pre-indexing writeback marker, '!', just add it as a token
  5280. // operand.
  5281. if (Parser.getTok().is(AsmToken::Exclaim)) {
  5282. Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
  5283. Parser.Lex(); // Eat the '!'.
  5284. }
  5285. return false;
  5286. }
  5287. /// parseMemRegOffsetShift - one of these two:
  5288. /// ( lsl | lsr | asr | ror ) , # shift_amount
  5289. /// rrx
  5290. /// return true if it parses a shift otherwise it returns false.
  5291. bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
  5292. unsigned &Amount) {
  5293. MCAsmParser &Parser = getParser();
  5294. SMLoc Loc = Parser.getTok().getLoc();
  5295. const AsmToken &Tok = Parser.getTok();
  5296. if (Tok.isNot(AsmToken::Identifier))
  5297. return Error(Loc, "illegal shift operator");
  5298. StringRef ShiftName = Tok.getString();
  5299. if (ShiftName == "lsl" || ShiftName == "LSL" ||
  5300. ShiftName == "asl" || ShiftName == "ASL")
  5301. St = ARM_AM::lsl;
  5302. else if (ShiftName == "lsr" || ShiftName == "LSR")
  5303. St = ARM_AM::lsr;
  5304. else if (ShiftName == "asr" || ShiftName == "ASR")
  5305. St = ARM_AM::asr;
  5306. else if (ShiftName == "ror" || ShiftName == "ROR")
  5307. St = ARM_AM::ror;
  5308. else if (ShiftName == "rrx" || ShiftName == "RRX")
  5309. St = ARM_AM::rrx;
  5310. else if (ShiftName == "uxtw" || ShiftName == "UXTW")
  5311. St = ARM_AM::uxtw;
  5312. else
  5313. return Error(Loc, "illegal shift operator");
  5314. Parser.Lex(); // Eat shift type token.
  5315. // rrx stands alone.
  5316. Amount = 0;
  5317. if (St != ARM_AM::rrx) {
  5318. Loc = Parser.getTok().getLoc();
  5319. // A '#' and a shift amount.
  5320. const AsmToken &HashTok = Parser.getTok();
  5321. if (HashTok.isNot(AsmToken::Hash) &&
  5322. HashTok.isNot(AsmToken::Dollar))
  5323. return Error(HashTok.getLoc(), "'#' expected");
  5324. Parser.Lex(); // Eat hash token.
  5325. const MCExpr *Expr;
  5326. if (getParser().parseExpression(Expr))
  5327. return true;
  5328. // Range check the immediate.
  5329. // lsl, ror: 0 <= imm <= 31
  5330. // lsr, asr: 0 <= imm <= 32
  5331. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
  5332. if (!CE)
  5333. return Error(Loc, "shift amount must be an immediate");
  5334. int64_t Imm = CE->getValue();
  5335. if (Imm < 0 ||
  5336. ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
  5337. ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
  5338. return Error(Loc, "immediate shift value out of range");
  5339. // If <ShiftTy> #0, turn it into a no_shift.
  5340. if (Imm == 0)
  5341. St = ARM_AM::lsl;
  5342. // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
  5343. if (Imm == 32)
  5344. Imm = 0;
  5345. Amount = Imm;
  5346. }
  5347. return false;
  5348. }
  5349. /// parseFPImm - A floating point immediate expression operand.
  5350. OperandMatchResultTy
  5351. ARMAsmParser::parseFPImm(OperandVector &Operands) {
  5352. MCAsmParser &Parser = getParser();
  5353. // Anything that can accept a floating point constant as an operand
  5354. // needs to go through here, as the regular parseExpression is
  5355. // integer only.
  5356. //
  5357. // This routine still creates a generic Immediate operand, containing
  5358. // a bitcast of the 64-bit floating point value. The various operands
  5359. // that accept floats can check whether the value is valid for them
  5360. // via the standard is*() predicates.
  5361. SMLoc S = Parser.getTok().getLoc();
  5362. if (Parser.getTok().isNot(AsmToken::Hash) &&
  5363. Parser.getTok().isNot(AsmToken::Dollar))
  5364. return MatchOperand_NoMatch;
  5365. // Disambiguate the VMOV forms that can accept an FP immediate.
  5366. // vmov.f32 <sreg>, #imm
  5367. // vmov.f64 <dreg>, #imm
  5368. // vmov.f32 <dreg>, #imm @ vector f32x2
  5369. // vmov.f32 <qreg>, #imm @ vector f32x4
  5370. //
  5371. // There are also the NEON VMOV instructions which expect an
  5372. // integer constant. Make sure we don't try to parse an FPImm
  5373. // for these:
  5374. // vmov.i{8|16|32|64} <dreg|qreg>, #imm
  5375. ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
  5376. bool isVmovf = TyOp.isToken() &&
  5377. (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64" ||
  5378. TyOp.getToken() == ".f16");
  5379. ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
  5380. bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
  5381. Mnemonic.getToken() == "fconsts");
  5382. if (!(isVmovf || isFconst))
  5383. return MatchOperand_NoMatch;
  5384. Parser.Lex(); // Eat '#' or '$'.
  5385. // Handle negation, as that still comes through as a separate token.
  5386. bool isNegative = false;
  5387. if (Parser.getTok().is(AsmToken::Minus)) {
  5388. isNegative = true;
  5389. Parser.Lex();
  5390. }
  5391. const AsmToken &Tok = Parser.getTok();
  5392. SMLoc Loc = Tok.getLoc();
  5393. if (Tok.is(AsmToken::Real) && isVmovf) {
  5394. APFloat RealVal(APFloat::IEEEsingle(), Tok.getString());
  5395. uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
  5396. // If we had a '-' in front, toggle the sign bit.
  5397. IntVal ^= (uint64_t)isNegative << 31;
  5398. Parser.Lex(); // Eat the token.
  5399. Operands.push_back(ARMOperand::CreateImm(
  5400. MCConstantExpr::create(IntVal, getContext()),
  5401. S, Parser.getTok().getLoc()));
  5402. return MatchOperand_Success;
  5403. }
  5404. // Also handle plain integers. Instructions which allow floating point
  5405. // immediates also allow a raw encoded 8-bit value.
  5406. if (Tok.is(AsmToken::Integer) && isFconst) {
  5407. int64_t Val = Tok.getIntVal();
  5408. Parser.Lex(); // Eat the token.
  5409. if (Val > 255 || Val < 0) {
  5410. Error(Loc, "encoded floating point value out of range");
  5411. return MatchOperand_ParseFail;
  5412. }
  5413. float RealVal = ARM_AM::getFPImmFloat(Val);
  5414. Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
  5415. Operands.push_back(ARMOperand::CreateImm(
  5416. MCConstantExpr::create(Val, getContext()), S,
  5417. Parser.getTok().getLoc()));
  5418. return MatchOperand_Success;
  5419. }
  5420. Error(Loc, "invalid floating point immediate");
  5421. return MatchOperand_ParseFail;
  5422. }
  5423. /// Parse a arm instruction operand. For now this parses the operand regardless
  5424. /// of the mnemonic.
  5425. bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
  5426. MCAsmParser &Parser = getParser();
  5427. SMLoc S, E;
  5428. // Check if the current operand has a custom associated parser, if so, try to
  5429. // custom parse the operand, or fallback to the general approach.
  5430. OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
  5431. if (ResTy == MatchOperand_Success)
  5432. return false;
  5433. // If there wasn't a custom match, try the generic matcher below. Otherwise,
  5434. // there was a match, but an error occurred, in which case, just return that
  5435. // the operand parsing failed.
  5436. if (ResTy == MatchOperand_ParseFail)
  5437. return true;
  5438. switch (getLexer().getKind()) {
  5439. default:
  5440. Error(Parser.getTok().getLoc(), "unexpected token in operand");
  5441. return true;
  5442. case AsmToken::Identifier: {
  5443. // If we've seen a branch mnemonic, the next operand must be a label. This
  5444. // is true even if the label is a register name. So "br r1" means branch to
  5445. // label "r1".
  5446. bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
  5447. if (!ExpectLabel) {
  5448. if (!tryParseRegisterWithWriteBack(Operands))
  5449. return false;
  5450. int Res = tryParseShiftRegister(Operands);
  5451. if (Res == 0) // success
  5452. return false;
  5453. else if (Res == -1) // irrecoverable error
  5454. return true;
  5455. // If this is VMRS, check for the apsr_nzcv operand.
  5456. if (Mnemonic == "vmrs" &&
  5457. Parser.getTok().getString().equals_insensitive("apsr_nzcv")) {
  5458. S = Parser.getTok().getLoc();
  5459. Parser.Lex();
  5460. Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
  5461. return false;
  5462. }
  5463. }
  5464. // Fall though for the Identifier case that is not a register or a
  5465. // special name.
  5466. LLVM_FALLTHROUGH;
  5467. }
  5468. case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
  5469. case AsmToken::Integer: // things like 1f and 2b as a branch targets
  5470. case AsmToken::String: // quoted label names.
  5471. case AsmToken::Dot: { // . as a branch target
  5472. // This was not a register so parse other operands that start with an
  5473. // identifier (like labels) as expressions and create them as immediates.
  5474. const MCExpr *IdVal;
  5475. S = Parser.getTok().getLoc();
  5476. if (getParser().parseExpression(IdVal))
  5477. return true;
  5478. E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
  5479. Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
  5480. return false;
  5481. }
  5482. case AsmToken::LBrac:
  5483. return parseMemory(Operands);
  5484. case AsmToken::LCurly:
  5485. return parseRegisterList(Operands, !Mnemonic.startswith("clr"));
  5486. case AsmToken::Dollar:
  5487. case AsmToken::Hash: {
  5488. // #42 -> immediate
  5489. // $ 42 -> immediate
  5490. // $foo -> symbol name
  5491. // $42 -> symbol name
  5492. S = Parser.getTok().getLoc();
  5493. // Favor the interpretation of $-prefixed operands as symbol names.
  5494. // Cases where immediates are explicitly expected are handled by their
  5495. // specific ParseMethod implementations.
  5496. auto AdjacentToken = getLexer().peekTok(/*ShouldSkipSpace=*/false);
  5497. bool ExpectIdentifier = Parser.getTok().is(AsmToken::Dollar) &&
  5498. (AdjacentToken.is(AsmToken::Identifier) ||
  5499. AdjacentToken.is(AsmToken::Integer));
  5500. if (!ExpectIdentifier) {
  5501. // Token is not part of identifier. Drop leading $ or # before parsing
  5502. // expression.
  5503. Parser.Lex();
  5504. }
  5505. if (Parser.getTok().isNot(AsmToken::Colon)) {
  5506. bool IsNegative = Parser.getTok().is(AsmToken::Minus);
  5507. const MCExpr *ImmVal;
  5508. if (getParser().parseExpression(ImmVal))
  5509. return true;
  5510. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
  5511. if (CE) {
  5512. int32_t Val = CE->getValue();
  5513. if (IsNegative && Val == 0)
  5514. ImmVal = MCConstantExpr::create(std::numeric_limits<int32_t>::min(),
  5515. getContext());
  5516. }
  5517. E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
  5518. Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
  5519. // There can be a trailing '!' on operands that we want as a separate
  5520. // '!' Token operand. Handle that here. For example, the compatibility
  5521. // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
  5522. if (Parser.getTok().is(AsmToken::Exclaim)) {
  5523. Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
  5524. Parser.getTok().getLoc()));
  5525. Parser.Lex(); // Eat exclaim token
  5526. }
  5527. return false;
  5528. }
  5529. // w/ a ':' after the '#', it's just like a plain ':'.
  5530. LLVM_FALLTHROUGH;
  5531. }
  5532. case AsmToken::Colon: {
  5533. S = Parser.getTok().getLoc();
  5534. // ":lower16:" and ":upper16:" expression prefixes
  5535. // FIXME: Check it's an expression prefix,
  5536. // e.g. (FOO - :lower16:BAR) isn't legal.
  5537. ARMMCExpr::VariantKind RefKind;
  5538. if (parsePrefix(RefKind))
  5539. return true;
  5540. const MCExpr *SubExprVal;
  5541. if (getParser().parseExpression(SubExprVal))
  5542. return true;
  5543. const MCExpr *ExprVal = ARMMCExpr::create(RefKind, SubExprVal,
  5544. getContext());
  5545. E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
  5546. Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
  5547. return false;
  5548. }
  5549. case AsmToken::Equal: {
  5550. S = Parser.getTok().getLoc();
  5551. if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
  5552. return Error(S, "unexpected token in operand");
  5553. Parser.Lex(); // Eat '='
  5554. const MCExpr *SubExprVal;
  5555. if (getParser().parseExpression(SubExprVal))
  5556. return true;
  5557. E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
  5558. // execute-only: we assume that assembly programmers know what they are
  5559. // doing and allow literal pool creation here
  5560. Operands.push_back(ARMOperand::CreateConstantPoolImm(SubExprVal, S, E));
  5561. return false;
  5562. }
  5563. }
  5564. }
  5565. // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
  5566. // :lower16: and :upper16:.
  5567. bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
  5568. MCAsmParser &Parser = getParser();
  5569. RefKind = ARMMCExpr::VK_ARM_None;
  5570. // consume an optional '#' (GNU compatibility)
  5571. if (getLexer().is(AsmToken::Hash))
  5572. Parser.Lex();
  5573. // :lower16: and :upper16: modifiers
  5574. assert(getLexer().is(AsmToken::Colon) && "expected a :");
  5575. Parser.Lex(); // Eat ':'
  5576. if (getLexer().isNot(AsmToken::Identifier)) {
  5577. Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
  5578. return true;
  5579. }
  5580. enum {
  5581. COFF = (1 << MCContext::IsCOFF),
  5582. ELF = (1 << MCContext::IsELF),
  5583. MACHO = (1 << MCContext::IsMachO),
  5584. WASM = (1 << MCContext::IsWasm),
  5585. };
  5586. static const struct PrefixEntry {
  5587. const char *Spelling;
  5588. ARMMCExpr::VariantKind VariantKind;
  5589. uint8_t SupportedFormats;
  5590. } PrefixEntries[] = {
  5591. { "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO },
  5592. { "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO },
  5593. };
  5594. StringRef IDVal = Parser.getTok().getIdentifier();
  5595. const auto &Prefix =
  5596. llvm::find_if(PrefixEntries, [&IDVal](const PrefixEntry &PE) {
  5597. return PE.Spelling == IDVal;
  5598. });
  5599. if (Prefix == std::end(PrefixEntries)) {
  5600. Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
  5601. return true;
  5602. }
  5603. uint8_t CurrentFormat;
  5604. switch (getContext().getObjectFileType()) {
  5605. case MCContext::IsMachO:
  5606. CurrentFormat = MACHO;
  5607. break;
  5608. case MCContext::IsELF:
  5609. CurrentFormat = ELF;
  5610. break;
  5611. case MCContext::IsCOFF:
  5612. CurrentFormat = COFF;
  5613. break;
  5614. case MCContext::IsWasm:
  5615. CurrentFormat = WASM;
  5616. break;
  5617. case MCContext::IsGOFF:
  5618. case MCContext::IsXCOFF:
  5619. llvm_unreachable("unexpected object format");
  5620. break;
  5621. }
  5622. if (~Prefix->SupportedFormats & CurrentFormat) {
  5623. Error(Parser.getTok().getLoc(),
  5624. "cannot represent relocation in the current file format");
  5625. return true;
  5626. }
  5627. RefKind = Prefix->VariantKind;
  5628. Parser.Lex();
  5629. if (getLexer().isNot(AsmToken::Colon)) {
  5630. Error(Parser.getTok().getLoc(), "unexpected token after prefix");
  5631. return true;
  5632. }
  5633. Parser.Lex(); // Eat the last ':'
  5634. return false;
  5635. }
  5636. /// Given a mnemonic, split out possible predication code and carry
  5637. /// setting letters to form a canonical mnemonic and flags.
  5638. //
  5639. // FIXME: Would be nice to autogen this.
  5640. // FIXME: This is a bit of a maze of special cases.
  5641. StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
  5642. StringRef ExtraToken,
  5643. unsigned &PredicationCode,
  5644. unsigned &VPTPredicationCode,
  5645. bool &CarrySetting,
  5646. unsigned &ProcessorIMod,
  5647. StringRef &ITMask) {
  5648. PredicationCode = ARMCC::AL;
  5649. VPTPredicationCode = ARMVCC::None;
  5650. CarrySetting = false;
  5651. ProcessorIMod = 0;
  5652. // Ignore some mnemonics we know aren't predicated forms.
  5653. //
  5654. // FIXME: Would be nice to autogen this.
  5655. if ((Mnemonic == "movs" && isThumb()) ||
  5656. Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
  5657. Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
  5658. Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
  5659. Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
  5660. Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
  5661. Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
  5662. Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
  5663. Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
  5664. Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
  5665. Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
  5666. Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
  5667. Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
  5668. Mnemonic.startswith("vsel") || Mnemonic == "vins" || Mnemonic == "vmovx" ||
  5669. Mnemonic == "bxns" || Mnemonic == "blxns" ||
  5670. Mnemonic == "vdot" || Mnemonic == "vmmla" ||
  5671. Mnemonic == "vudot" || Mnemonic == "vsdot" ||
  5672. Mnemonic == "vcmla" || Mnemonic == "vcadd" ||
  5673. Mnemonic == "vfmal" || Mnemonic == "vfmsl" ||
  5674. Mnemonic == "wls" || Mnemonic == "le" || Mnemonic == "dls" ||
  5675. Mnemonic == "csel" || Mnemonic == "csinc" ||
  5676. Mnemonic == "csinv" || Mnemonic == "csneg" || Mnemonic == "cinc" ||
  5677. Mnemonic == "cinv" || Mnemonic == "cneg" || Mnemonic == "cset" ||
  5678. Mnemonic == "csetm" ||
  5679. Mnemonic == "aut" || Mnemonic == "pac" || Mnemonic == "pacbti" ||
  5680. Mnemonic == "bti")
  5681. return Mnemonic;
  5682. // First, split out any predication code. Ignore mnemonics we know aren't
  5683. // predicated but do have a carry-set and so weren't caught above.
  5684. if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
  5685. Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
  5686. Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
  5687. Mnemonic != "sbcs" && Mnemonic != "rscs" &&
  5688. !(hasMVE() &&
  5689. (Mnemonic == "vmine" ||
  5690. Mnemonic == "vshle" || Mnemonic == "vshlt" || Mnemonic == "vshllt" ||
  5691. Mnemonic == "vrshle" || Mnemonic == "vrshlt" ||
  5692. Mnemonic == "vmvne" || Mnemonic == "vorne" ||
  5693. Mnemonic == "vnege" || Mnemonic == "vnegt" ||
  5694. Mnemonic == "vmule" || Mnemonic == "vmult" ||
  5695. Mnemonic == "vrintne" ||
  5696. Mnemonic == "vcmult" || Mnemonic == "vcmule" ||
  5697. Mnemonic == "vpsele" || Mnemonic == "vpselt" ||
  5698. Mnemonic.startswith("vq")))) {
  5699. unsigned CC = ARMCondCodeFromString(Mnemonic.substr(Mnemonic.size()-2));
  5700. if (CC != ~0U) {
  5701. Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
  5702. PredicationCode = CC;
  5703. }
  5704. }
  5705. // Next, determine if we have a carry setting bit. We explicitly ignore all
  5706. // the instructions we know end in 's'.
  5707. if (Mnemonic.endswith("s") &&
  5708. !(Mnemonic == "cps" || Mnemonic == "mls" ||
  5709. Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
  5710. Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
  5711. Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
  5712. Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
  5713. Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
  5714. Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
  5715. Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
  5716. Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
  5717. Mnemonic == "bxns" || Mnemonic == "blxns" || Mnemonic == "vfmas" ||
  5718. Mnemonic == "vmlas" ||
  5719. (Mnemonic == "movs" && isThumb()))) {
  5720. Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
  5721. CarrySetting = true;
  5722. }
  5723. // The "cps" instruction can have a interrupt mode operand which is glued into
  5724. // the mnemonic. Check if this is the case, split it and parse the imod op
  5725. if (Mnemonic.startswith("cps")) {
  5726. // Split out any imod code.
  5727. unsigned IMod =
  5728. StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
  5729. .Case("ie", ARM_PROC::IE)
  5730. .Case("id", ARM_PROC::ID)
  5731. .Default(~0U);
  5732. if (IMod != ~0U) {
  5733. Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
  5734. ProcessorIMod = IMod;
  5735. }
  5736. }
  5737. if (isMnemonicVPTPredicable(Mnemonic, ExtraToken) && Mnemonic != "vmovlt" &&
  5738. Mnemonic != "vshllt" && Mnemonic != "vrshrnt" && Mnemonic != "vshrnt" &&
  5739. Mnemonic != "vqrshrunt" && Mnemonic != "vqshrunt" &&
  5740. Mnemonic != "vqrshrnt" && Mnemonic != "vqshrnt" && Mnemonic != "vmullt" &&
  5741. Mnemonic != "vqmovnt" && Mnemonic != "vqmovunt" &&
  5742. Mnemonic != "vqmovnt" && Mnemonic != "vmovnt" && Mnemonic != "vqdmullt" &&
  5743. Mnemonic != "vpnot" && Mnemonic != "vcvtt" && Mnemonic != "vcvt") {
  5744. unsigned CC = ARMVectorCondCodeFromString(Mnemonic.substr(Mnemonic.size()-1));
  5745. if (CC != ~0U) {
  5746. Mnemonic = Mnemonic.slice(0, Mnemonic.size()-1);
  5747. VPTPredicationCode = CC;
  5748. }
  5749. return Mnemonic;
  5750. }
  5751. // The "it" instruction has the condition mask on the end of the mnemonic.
  5752. if (Mnemonic.startswith("it")) {
  5753. ITMask = Mnemonic.slice(2, Mnemonic.size());
  5754. Mnemonic = Mnemonic.slice(0, 2);
  5755. }
  5756. if (Mnemonic.startswith("vpst")) {
  5757. ITMask = Mnemonic.slice(4, Mnemonic.size());
  5758. Mnemonic = Mnemonic.slice(0, 4);
  5759. }
  5760. else if (Mnemonic.startswith("vpt")) {
  5761. ITMask = Mnemonic.slice(3, Mnemonic.size());
  5762. Mnemonic = Mnemonic.slice(0, 3);
  5763. }
  5764. return Mnemonic;
  5765. }
  5766. /// Given a canonical mnemonic, determine if the instruction ever allows
  5767. /// inclusion of carry set or predication code operands.
  5768. //
  5769. // FIXME: It would be nice to autogen this.
  5770. void ARMAsmParser::getMnemonicAcceptInfo(StringRef Mnemonic,
  5771. StringRef ExtraToken,
  5772. StringRef FullInst,
  5773. bool &CanAcceptCarrySet,
  5774. bool &CanAcceptPredicationCode,
  5775. bool &CanAcceptVPTPredicationCode) {
  5776. CanAcceptVPTPredicationCode = isMnemonicVPTPredicable(Mnemonic, ExtraToken);
  5777. CanAcceptCarrySet =
  5778. Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
  5779. Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
  5780. Mnemonic == "add" || Mnemonic == "adc" || Mnemonic == "mul" ||
  5781. Mnemonic == "bic" || Mnemonic == "asr" || Mnemonic == "orr" ||
  5782. Mnemonic == "mvn" || Mnemonic == "rsb" || Mnemonic == "rsc" ||
  5783. Mnemonic == "orn" || Mnemonic == "sbc" || Mnemonic == "eor" ||
  5784. Mnemonic == "neg" || Mnemonic == "vfm" || Mnemonic == "vfnm" ||
  5785. (!isThumb() &&
  5786. (Mnemonic == "smull" || Mnemonic == "mov" || Mnemonic == "mla" ||
  5787. Mnemonic == "smlal" || Mnemonic == "umlal" || Mnemonic == "umull"));
  5788. if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
  5789. Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
  5790. Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
  5791. Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
  5792. Mnemonic.startswith("vsel") || Mnemonic == "vmaxnm" ||
  5793. Mnemonic == "vminnm" || Mnemonic == "vcvta" || Mnemonic == "vcvtn" ||
  5794. Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || Mnemonic == "vrinta" ||
  5795. Mnemonic == "vrintn" || Mnemonic == "vrintp" || Mnemonic == "vrintm" ||
  5796. Mnemonic.startswith("aes") || Mnemonic == "hvc" || Mnemonic == "setpan" ||
  5797. Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
  5798. (FullInst.startswith("vmull") && FullInst.endswith(".p64")) ||
  5799. Mnemonic == "vmovx" || Mnemonic == "vins" ||
  5800. Mnemonic == "vudot" || Mnemonic == "vsdot" ||
  5801. Mnemonic == "vcmla" || Mnemonic == "vcadd" ||
  5802. Mnemonic == "vfmal" || Mnemonic == "vfmsl" ||
  5803. Mnemonic == "vfmat" || Mnemonic == "vfmab" ||
  5804. Mnemonic == "vdot" || Mnemonic == "vmmla" ||
  5805. Mnemonic == "sb" || Mnemonic == "ssbb" ||
  5806. Mnemonic == "pssbb" || Mnemonic == "vsmmla" ||
  5807. Mnemonic == "vummla" || Mnemonic == "vusmmla" ||
  5808. Mnemonic == "vusdot" || Mnemonic == "vsudot" ||
  5809. Mnemonic == "bfcsel" || Mnemonic == "wls" ||
  5810. Mnemonic == "dls" || Mnemonic == "le" || Mnemonic == "csel" ||
  5811. Mnemonic == "csinc" || Mnemonic == "csinv" || Mnemonic == "csneg" ||
  5812. Mnemonic == "cinc" || Mnemonic == "cinv" || Mnemonic == "cneg" ||
  5813. Mnemonic == "cset" || Mnemonic == "csetm" ||
  5814. (hasCDE() && MS.isCDEInstr(Mnemonic) &&
  5815. !MS.isITPredicableCDEInstr(Mnemonic)) ||
  5816. Mnemonic.startswith("vpt") || Mnemonic.startswith("vpst") ||
  5817. Mnemonic == "pac" || Mnemonic == "pacbti" || Mnemonic == "aut" ||
  5818. Mnemonic == "bti" ||
  5819. (hasMVE() &&
  5820. (Mnemonic.startswith("vst2") || Mnemonic.startswith("vld2") ||
  5821. Mnemonic.startswith("vst4") || Mnemonic.startswith("vld4") ||
  5822. Mnemonic.startswith("wlstp") || Mnemonic.startswith("dlstp") ||
  5823. Mnemonic.startswith("letp")))) {
  5824. // These mnemonics are never predicable
  5825. CanAcceptPredicationCode = false;
  5826. } else if (!isThumb()) {
  5827. // Some instructions are only predicable in Thumb mode
  5828. CanAcceptPredicationCode =
  5829. Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
  5830. Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
  5831. Mnemonic != "dmb" && Mnemonic != "dfb" && Mnemonic != "dsb" &&
  5832. Mnemonic != "isb" && Mnemonic != "pld" && Mnemonic != "pli" &&
  5833. Mnemonic != "pldw" && Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
  5834. Mnemonic != "stc2" && Mnemonic != "stc2l" &&
  5835. Mnemonic != "tsb" &&
  5836. !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
  5837. } else if (isThumbOne()) {
  5838. if (hasV6MOps())
  5839. CanAcceptPredicationCode = Mnemonic != "movs";
  5840. else
  5841. CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
  5842. } else
  5843. CanAcceptPredicationCode = true;
  5844. }
  5845. // Some Thumb instructions have two operand forms that are not
  5846. // available as three operand, convert to two operand form if possible.
  5847. //
  5848. // FIXME: We would really like to be able to tablegen'erate this.
  5849. void ARMAsmParser::tryConvertingToTwoOperandForm(StringRef Mnemonic,
  5850. bool CarrySetting,
  5851. OperandVector &Operands) {
  5852. if (Operands.size() != 6)
  5853. return;
  5854. const auto &Op3 = static_cast<ARMOperand &>(*Operands[3]);
  5855. auto &Op4 = static_cast<ARMOperand &>(*Operands[4]);
  5856. if (!Op3.isReg() || !Op4.isReg())
  5857. return;
  5858. auto Op3Reg = Op3.getReg();
  5859. auto Op4Reg = Op4.getReg();
  5860. // For most Thumb2 cases we just generate the 3 operand form and reduce
  5861. // it in processInstruction(), but the 3 operand form of ADD (t2ADDrr)
  5862. // won't accept SP or PC so we do the transformation here taking care
  5863. // with immediate range in the 'add sp, sp #imm' case.
  5864. auto &Op5 = static_cast<ARMOperand &>(*Operands[5]);
  5865. if (isThumbTwo()) {
  5866. if (Mnemonic != "add")
  5867. return;
  5868. bool TryTransform = Op3Reg == ARM::PC || Op4Reg == ARM::PC ||
  5869. (Op5.isReg() && Op5.getReg() == ARM::PC);
  5870. if (!TryTransform) {
  5871. TryTransform = (Op3Reg == ARM::SP || Op4Reg == ARM::SP ||
  5872. (Op5.isReg() && Op5.getReg() == ARM::SP)) &&
  5873. !(Op3Reg == ARM::SP && Op4Reg == ARM::SP &&
  5874. Op5.isImm() && !Op5.isImm0_508s4());
  5875. }
  5876. if (!TryTransform)
  5877. return;
  5878. } else if (!isThumbOne())
  5879. return;
  5880. if (!(Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
  5881. Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
  5882. Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
  5883. Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic"))
  5884. return;
  5885. // If first 2 operands of a 3 operand instruction are the same
  5886. // then transform to 2 operand version of the same instruction
  5887. // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
  5888. bool Transform = Op3Reg == Op4Reg;
  5889. // For communtative operations, we might be able to transform if we swap
  5890. // Op4 and Op5. The 'ADD Rdm, SP, Rdm' form is already handled specially
  5891. // as tADDrsp.
  5892. const ARMOperand *LastOp = &Op5;
  5893. bool Swap = false;
  5894. if (!Transform && Op5.isReg() && Op3Reg == Op5.getReg() &&
  5895. ((Mnemonic == "add" && Op4Reg != ARM::SP) ||
  5896. Mnemonic == "and" || Mnemonic == "eor" ||
  5897. Mnemonic == "adc" || Mnemonic == "orr")) {
  5898. Swap = true;
  5899. LastOp = &Op4;
  5900. Transform = true;
  5901. }
  5902. // If both registers are the same then remove one of them from
  5903. // the operand list, with certain exceptions.
  5904. if (Transform) {
  5905. // Don't transform 'adds Rd, Rd, Rm' or 'sub{s} Rd, Rd, Rm' because the
  5906. // 2 operand forms don't exist.
  5907. if (((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub") &&
  5908. LastOp->isReg())
  5909. Transform = false;
  5910. // Don't transform 'add/sub{s} Rd, Rd, #imm' if the immediate fits into
  5911. // 3-bits because the ARMARM says not to.
  5912. if ((Mnemonic == "add" || Mnemonic == "sub") && LastOp->isImm0_7())
  5913. Transform = false;
  5914. }
  5915. if (Transform) {
  5916. if (Swap)
  5917. std::swap(Op4, Op5);
  5918. Operands.erase(Operands.begin() + 3);
  5919. }
  5920. }
  5921. bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
  5922. OperandVector &Operands) {
  5923. // FIXME: This is all horribly hacky. We really need a better way to deal
  5924. // with optional operands like this in the matcher table.
  5925. // The 'mov' mnemonic is special. One variant has a cc_out operand, while
  5926. // another does not. Specifically, the MOVW instruction does not. So we
  5927. // special case it here and remove the defaulted (non-setting) cc_out
  5928. // operand if that's the instruction we're trying to match.
  5929. //
  5930. // We do this as post-processing of the explicit operands rather than just
  5931. // conditionally adding the cc_out in the first place because we need
  5932. // to check the type of the parsed immediate operand.
  5933. if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
  5934. !static_cast<ARMOperand &>(*Operands[4]).isModImm() &&
  5935. static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
  5936. static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
  5937. return true;
  5938. // Register-register 'add' for thumb does not have a cc_out operand
  5939. // when there are only two register operands.
  5940. if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
  5941. static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  5942. static_cast<ARMOperand &>(*Operands[4]).isReg() &&
  5943. static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
  5944. return true;
  5945. // Register-register 'add' for thumb does not have a cc_out operand
  5946. // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
  5947. // have to check the immediate range here since Thumb2 has a variant
  5948. // that can handle a different range and has a cc_out operand.
  5949. if (((isThumb() && Mnemonic == "add") ||
  5950. (isThumbTwo() && Mnemonic == "sub")) &&
  5951. Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  5952. static_cast<ARMOperand &>(*Operands[4]).isReg() &&
  5953. static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
  5954. static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
  5955. ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
  5956. static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
  5957. return true;
  5958. // For Thumb2, add/sub immediate does not have a cc_out operand for the
  5959. // imm0_4095 variant. That's the least-preferred variant when
  5960. // selecting via the generic "add" mnemonic, so to know that we
  5961. // should remove the cc_out operand, we have to explicitly check that
  5962. // it's not one of the other variants. Ugh.
  5963. if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
  5964. Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  5965. static_cast<ARMOperand &>(*Operands[4]).isReg() &&
  5966. static_cast<ARMOperand &>(*Operands[5]).isImm()) {
  5967. // Nest conditions rather than one big 'if' statement for readability.
  5968. //
  5969. // If both registers are low, we're in an IT block, and the immediate is
  5970. // in range, we should use encoding T1 instead, which has a cc_out.
  5971. if (inITBlock() &&
  5972. isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
  5973. isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
  5974. static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
  5975. return false;
  5976. // Check against T3. If the second register is the PC, this is an
  5977. // alternate form of ADR, which uses encoding T4, so check for that too.
  5978. if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
  5979. (static_cast<ARMOperand &>(*Operands[5]).isT2SOImm() ||
  5980. static_cast<ARMOperand &>(*Operands[5]).isT2SOImmNeg()))
  5981. return false;
  5982. // Otherwise, we use encoding T4, which does not have a cc_out
  5983. // operand.
  5984. return true;
  5985. }
  5986. // The thumb2 multiply instruction doesn't have a CCOut register, so
  5987. // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
  5988. // use the 16-bit encoding or not.
  5989. if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
  5990. static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
  5991. static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  5992. static_cast<ARMOperand &>(*Operands[4]).isReg() &&
  5993. static_cast<ARMOperand &>(*Operands[5]).isReg() &&
  5994. // If the registers aren't low regs, the destination reg isn't the
  5995. // same as one of the source regs, or the cc_out operand is zero
  5996. // outside of an IT block, we have to use the 32-bit encoding, so
  5997. // remove the cc_out operand.
  5998. (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
  5999. !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
  6000. !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
  6001. !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
  6002. static_cast<ARMOperand &>(*Operands[5]).getReg() &&
  6003. static_cast<ARMOperand &>(*Operands[3]).getReg() !=
  6004. static_cast<ARMOperand &>(*Operands[4]).getReg())))
  6005. return true;
  6006. // Also check the 'mul' syntax variant that doesn't specify an explicit
  6007. // destination register.
  6008. if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
  6009. static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
  6010. static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  6011. static_cast<ARMOperand &>(*Operands[4]).isReg() &&
  6012. // If the registers aren't low regs or the cc_out operand is zero
  6013. // outside of an IT block, we have to use the 32-bit encoding, so
  6014. // remove the cc_out operand.
  6015. (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
  6016. !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
  6017. !inITBlock()))
  6018. return true;
  6019. // Register-register 'add/sub' for thumb does not have a cc_out operand
  6020. // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
  6021. // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
  6022. // right, this will result in better diagnostics (which operand is off)
  6023. // anyway.
  6024. if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
  6025. (Operands.size() == 5 || Operands.size() == 6) &&
  6026. static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  6027. static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
  6028. static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
  6029. (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
  6030. (Operands.size() == 6 &&
  6031. static_cast<ARMOperand &>(*Operands[5]).isImm()))) {
  6032. // Thumb2 (add|sub){s}{p}.w GPRnopc, sp, #{T2SOImm} has cc_out
  6033. return (!(isThumbTwo() &&
  6034. (static_cast<ARMOperand &>(*Operands[4]).isT2SOImm() ||
  6035. static_cast<ARMOperand &>(*Operands[4]).isT2SOImmNeg())));
  6036. }
  6037. // Fixme: Should join all the thumb+thumb2 (add|sub) in a single if case
  6038. // Thumb2 ADD r0, #4095 -> ADDW r0, r0, #4095 (T4)
  6039. // Thumb2 SUB r0, #4095 -> SUBW r0, r0, #4095
  6040. if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
  6041. (Operands.size() == 5) &&
  6042. static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  6043. static_cast<ARMOperand &>(*Operands[3]).getReg() != ARM::SP &&
  6044. static_cast<ARMOperand &>(*Operands[3]).getReg() != ARM::PC &&
  6045. static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
  6046. static_cast<ARMOperand &>(*Operands[4]).isImm()) {
  6047. const ARMOperand &IMM = static_cast<ARMOperand &>(*Operands[4]);
  6048. if (IMM.isT2SOImm() || IMM.isT2SOImmNeg())
  6049. return false; // add.w / sub.w
  6050. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IMM.getImm())) {
  6051. const int64_t Value = CE->getValue();
  6052. // Thumb1 imm8 sub / add
  6053. if ((Value < ((1 << 7) - 1) << 2) && inITBlock() && (!(Value & 3)) &&
  6054. isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()))
  6055. return false;
  6056. return true; // Thumb2 T4 addw / subw
  6057. }
  6058. }
  6059. return false;
  6060. }
  6061. bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
  6062. OperandVector &Operands) {
  6063. // VRINT{Z, X} have a predicate operand in VFP, but not in NEON
  6064. unsigned RegIdx = 3;
  6065. if ((((Mnemonic == "vrintz" || Mnemonic == "vrintx") && !hasMVE()) ||
  6066. Mnemonic == "vrintr") &&
  6067. (static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32" ||
  6068. static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f16")) {
  6069. if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
  6070. (static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32" ||
  6071. static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f16"))
  6072. RegIdx = 4;
  6073. if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
  6074. (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
  6075. static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
  6076. ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
  6077. static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
  6078. return true;
  6079. }
  6080. return false;
  6081. }
  6082. bool ARMAsmParser::shouldOmitVectorPredicateOperand(StringRef Mnemonic,
  6083. OperandVector &Operands) {
  6084. if (!hasMVE() || Operands.size() < 3)
  6085. return true;
  6086. if (Mnemonic.startswith("vld2") || Mnemonic.startswith("vld4") ||
  6087. Mnemonic.startswith("vst2") || Mnemonic.startswith("vst4"))
  6088. return true;
  6089. if (Mnemonic.startswith("vctp") || Mnemonic.startswith("vpnot"))
  6090. return false;
  6091. if (Mnemonic.startswith("vmov") &&
  6092. !(Mnemonic.startswith("vmovl") || Mnemonic.startswith("vmovn") ||
  6093. Mnemonic.startswith("vmovx"))) {
  6094. for (auto &Operand : Operands) {
  6095. if (static_cast<ARMOperand &>(*Operand).isVectorIndex() ||
  6096. ((*Operand).isReg() &&
  6097. (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(
  6098. (*Operand).getReg()) ||
  6099. ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
  6100. (*Operand).getReg())))) {
  6101. return true;
  6102. }
  6103. }
  6104. return false;
  6105. } else {
  6106. for (auto &Operand : Operands) {
  6107. // We check the larger class QPR instead of just the legal class
  6108. // MQPR, to more accurately report errors when using Q registers
  6109. // outside of the allowed range.
  6110. if (static_cast<ARMOperand &>(*Operand).isVectorIndex() ||
  6111. (Operand->isReg() &&
  6112. (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
  6113. Operand->getReg()))))
  6114. return false;
  6115. }
  6116. return true;
  6117. }
  6118. }
  6119. static bool isDataTypeToken(StringRef Tok) {
  6120. return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
  6121. Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
  6122. Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
  6123. Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
  6124. Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
  6125. Tok == ".f" || Tok == ".d";
  6126. }
  6127. // FIXME: This bit should probably be handled via an explicit match class
  6128. // in the .td files that matches the suffix instead of having it be
  6129. // a literal string token the way it is now.
  6130. static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
  6131. return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
  6132. }
  6133. static void applyMnemonicAliases(StringRef &Mnemonic,
  6134. const FeatureBitset &Features,
  6135. unsigned VariantID);
  6136. // The GNU assembler has aliases of ldrd and strd with the second register
  6137. // omitted. We don't have a way to do that in tablegen, so fix it up here.
  6138. //
  6139. // We have to be careful to not emit an invalid Rt2 here, because the rest of
  6140. // the assembly parser could then generate confusing diagnostics refering to
  6141. // it. If we do find anything that prevents us from doing the transformation we
  6142. // bail out, and let the assembly parser report an error on the instruction as
  6143. // it is written.
  6144. void ARMAsmParser::fixupGNULDRDAlias(StringRef Mnemonic,
  6145. OperandVector &Operands) {
  6146. if (Mnemonic != "ldrd" && Mnemonic != "strd")
  6147. return;
  6148. if (Operands.size() < 4)
  6149. return;
  6150. ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
  6151. ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
  6152. if (!Op2.isReg())
  6153. return;
  6154. if (!Op3.isGPRMem())
  6155. return;
  6156. const MCRegisterClass &GPR = MRI->getRegClass(ARM::GPRRegClassID);
  6157. if (!GPR.contains(Op2.getReg()))
  6158. return;
  6159. unsigned RtEncoding = MRI->getEncodingValue(Op2.getReg());
  6160. if (!isThumb() && (RtEncoding & 1)) {
  6161. // In ARM mode, the registers must be from an aligned pair, this
  6162. // restriction does not apply in Thumb mode.
  6163. return;
  6164. }
  6165. if (Op2.getReg() == ARM::PC)
  6166. return;
  6167. unsigned PairedReg = GPR.getRegister(RtEncoding + 1);
  6168. if (!PairedReg || PairedReg == ARM::PC ||
  6169. (PairedReg == ARM::SP && !hasV8Ops()))
  6170. return;
  6171. Operands.insert(
  6172. Operands.begin() + 3,
  6173. ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
  6174. }
  6175. // Dual-register instruction have the following syntax:
  6176. // <mnemonic> <predicate>? <coproc>, <Rdest>, <Rdest+1>, <Rsrc>, ..., #imm
  6177. // This function tries to remove <Rdest+1> and replace <Rdest> with a pair
  6178. // operand. If the conversion fails an error is diagnosed, and the function
  6179. // returns true.
  6180. bool ARMAsmParser::CDEConvertDualRegOperand(StringRef Mnemonic,
  6181. OperandVector &Operands) {
  6182. assert(MS.isCDEDualRegInstr(Mnemonic));
  6183. bool isPredicable =
  6184. Mnemonic == "cx1da" || Mnemonic == "cx2da" || Mnemonic == "cx3da";
  6185. size_t NumPredOps = isPredicable ? 1 : 0;
  6186. if (Operands.size() <= 3 + NumPredOps)
  6187. return false;
  6188. StringRef Op2Diag(
  6189. "operand must be an even-numbered register in the range [r0, r10]");
  6190. const MCParsedAsmOperand &Op2 = *Operands[2 + NumPredOps];
  6191. if (!Op2.isReg())
  6192. return Error(Op2.getStartLoc(), Op2Diag);
  6193. unsigned RNext;
  6194. unsigned RPair;
  6195. switch (Op2.getReg()) {
  6196. default:
  6197. return Error(Op2.getStartLoc(), Op2Diag);
  6198. case ARM::R0:
  6199. RNext = ARM::R1;
  6200. RPair = ARM::R0_R1;
  6201. break;
  6202. case ARM::R2:
  6203. RNext = ARM::R3;
  6204. RPair = ARM::R2_R3;
  6205. break;
  6206. case ARM::R4:
  6207. RNext = ARM::R5;
  6208. RPair = ARM::R4_R5;
  6209. break;
  6210. case ARM::R6:
  6211. RNext = ARM::R7;
  6212. RPair = ARM::R6_R7;
  6213. break;
  6214. case ARM::R8:
  6215. RNext = ARM::R9;
  6216. RPair = ARM::R8_R9;
  6217. break;
  6218. case ARM::R10:
  6219. RNext = ARM::R11;
  6220. RPair = ARM::R10_R11;
  6221. break;
  6222. }
  6223. const MCParsedAsmOperand &Op3 = *Operands[3 + NumPredOps];
  6224. if (!Op3.isReg() || Op3.getReg() != RNext)
  6225. return Error(Op3.getStartLoc(), "operand must be a consecutive register");
  6226. Operands.erase(Operands.begin() + 3 + NumPredOps);
  6227. Operands[2 + NumPredOps] =
  6228. ARMOperand::CreateReg(RPair, Op2.getStartLoc(), Op2.getEndLoc());
  6229. return false;
  6230. }
  6231. /// Parse an arm instruction mnemonic followed by its operands.
  6232. bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
  6233. SMLoc NameLoc, OperandVector &Operands) {
  6234. MCAsmParser &Parser = getParser();
  6235. // Apply mnemonic aliases before doing anything else, as the destination
  6236. // mnemonic may include suffices and we want to handle them normally.
  6237. // The generic tblgen'erated code does this later, at the start of
  6238. // MatchInstructionImpl(), but that's too late for aliases that include
  6239. // any sort of suffix.
  6240. const FeatureBitset &AvailableFeatures = getAvailableFeatures();
  6241. unsigned AssemblerDialect = getParser().getAssemblerDialect();
  6242. applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
  6243. // First check for the ARM-specific .req directive.
  6244. if (Parser.getTok().is(AsmToken::Identifier) &&
  6245. Parser.getTok().getIdentifier().lower() == ".req") {
  6246. parseDirectiveReq(Name, NameLoc);
  6247. // We always return 'error' for this, as we're done with this
  6248. // statement and don't need to match the 'instruction."
  6249. return true;
  6250. }
  6251. // Create the leading tokens for the mnemonic, split by '.' characters.
  6252. size_t Start = 0, Next = Name.find('.');
  6253. StringRef Mnemonic = Name.slice(Start, Next);
  6254. StringRef ExtraToken = Name.slice(Next, Name.find(' ', Next + 1));
  6255. // Split out the predication code and carry setting flag from the mnemonic.
  6256. unsigned PredicationCode;
  6257. unsigned VPTPredicationCode;
  6258. unsigned ProcessorIMod;
  6259. bool CarrySetting;
  6260. StringRef ITMask;
  6261. Mnemonic = splitMnemonic(Mnemonic, ExtraToken, PredicationCode, VPTPredicationCode,
  6262. CarrySetting, ProcessorIMod, ITMask);
  6263. // In Thumb1, only the branch (B) instruction can be predicated.
  6264. if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
  6265. return Error(NameLoc, "conditional execution not supported in Thumb1");
  6266. }
  6267. Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
  6268. // Handle the mask for IT and VPT instructions. In ARMOperand and
  6269. // MCOperand, this is stored in a format independent of the
  6270. // condition code: the lowest set bit indicates the end of the
  6271. // encoding, and above that, a 1 bit indicates 'else', and an 0
  6272. // indicates 'then'. E.g.
  6273. // IT -> 1000
  6274. // ITx -> x100 (ITT -> 0100, ITE -> 1100)
  6275. // ITxy -> xy10 (e.g. ITET -> 1010)
  6276. // ITxyz -> xyz1 (e.g. ITEET -> 1101)
  6277. // Note: See the ARM::PredBlockMask enum in
  6278. // /lib/Target/ARM/Utils/ARMBaseInfo.h
  6279. if (Mnemonic == "it" || Mnemonic.startswith("vpt") ||
  6280. Mnemonic.startswith("vpst")) {
  6281. SMLoc Loc = Mnemonic == "it" ? SMLoc::getFromPointer(NameLoc.getPointer() + 2) :
  6282. Mnemonic == "vpt" ? SMLoc::getFromPointer(NameLoc.getPointer() + 3) :
  6283. SMLoc::getFromPointer(NameLoc.getPointer() + 4);
  6284. if (ITMask.size() > 3) {
  6285. if (Mnemonic == "it")
  6286. return Error(Loc, "too many conditions on IT instruction");
  6287. return Error(Loc, "too many conditions on VPT instruction");
  6288. }
  6289. unsigned Mask = 8;
  6290. for (char Pos : llvm::reverse(ITMask)) {
  6291. if (Pos != 't' && Pos != 'e') {
  6292. return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
  6293. }
  6294. Mask >>= 1;
  6295. if (Pos == 'e')
  6296. Mask |= 8;
  6297. }
  6298. Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
  6299. }
  6300. // FIXME: This is all a pretty gross hack. We should automatically handle
  6301. // optional operands like this via tblgen.
  6302. // Next, add the CCOut and ConditionCode operands, if needed.
  6303. //
  6304. // For mnemonics which can ever incorporate a carry setting bit or predication
  6305. // code, our matching model involves us always generating CCOut and
  6306. // ConditionCode operands to match the mnemonic "as written" and then we let
  6307. // the matcher deal with finding the right instruction or generating an
  6308. // appropriate error.
  6309. bool CanAcceptCarrySet, CanAcceptPredicationCode, CanAcceptVPTPredicationCode;
  6310. getMnemonicAcceptInfo(Mnemonic, ExtraToken, Name, CanAcceptCarrySet,
  6311. CanAcceptPredicationCode, CanAcceptVPTPredicationCode);
  6312. // If we had a carry-set on an instruction that can't do that, issue an
  6313. // error.
  6314. if (!CanAcceptCarrySet && CarrySetting) {
  6315. return Error(NameLoc, "instruction '" + Mnemonic +
  6316. "' can not set flags, but 's' suffix specified");
  6317. }
  6318. // If we had a predication code on an instruction that can't do that, issue an
  6319. // error.
  6320. if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
  6321. return Error(NameLoc, "instruction '" + Mnemonic +
  6322. "' is not predicable, but condition code specified");
  6323. }
  6324. // If we had a VPT predication code on an instruction that can't do that, issue an
  6325. // error.
  6326. if (!CanAcceptVPTPredicationCode && VPTPredicationCode != ARMVCC::None) {
  6327. return Error(NameLoc, "instruction '" + Mnemonic +
  6328. "' is not VPT predicable, but VPT code T/E is specified");
  6329. }
  6330. // Add the carry setting operand, if necessary.
  6331. if (CanAcceptCarrySet) {
  6332. SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
  6333. Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
  6334. Loc));
  6335. }
  6336. // Add the predication code operand, if necessary.
  6337. if (CanAcceptPredicationCode) {
  6338. SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
  6339. CarrySetting);
  6340. Operands.push_back(ARMOperand::CreateCondCode(
  6341. ARMCC::CondCodes(PredicationCode), Loc));
  6342. }
  6343. // Add the VPT predication code operand, if necessary.
  6344. // FIXME: We don't add them for the instructions filtered below as these can
  6345. // have custom operands which need special parsing. This parsing requires
  6346. // the operand to be in the same place in the OperandVector as their
  6347. // definition in tblgen. Since these instructions may also have the
  6348. // scalar predication operand we do not add the vector one and leave until
  6349. // now to fix it up.
  6350. if (CanAcceptVPTPredicationCode && Mnemonic != "vmov" &&
  6351. !Mnemonic.startswith("vcmp") &&
  6352. !(Mnemonic.startswith("vcvt") && Mnemonic != "vcvta" &&
  6353. Mnemonic != "vcvtn" && Mnemonic != "vcvtp" && Mnemonic != "vcvtm")) {
  6354. SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
  6355. CarrySetting);
  6356. Operands.push_back(ARMOperand::CreateVPTPred(
  6357. ARMVCC::VPTCodes(VPTPredicationCode), Loc));
  6358. }
  6359. // Add the processor imod operand, if necessary.
  6360. if (ProcessorIMod) {
  6361. Operands.push_back(ARMOperand::CreateImm(
  6362. MCConstantExpr::create(ProcessorIMod, getContext()),
  6363. NameLoc, NameLoc));
  6364. } else if (Mnemonic == "cps" && isMClass()) {
  6365. return Error(NameLoc, "instruction 'cps' requires effect for M-class");
  6366. }
  6367. // Add the remaining tokens in the mnemonic.
  6368. while (Next != StringRef::npos) {
  6369. Start = Next;
  6370. Next = Name.find('.', Start + 1);
  6371. ExtraToken = Name.slice(Start, Next);
  6372. // Some NEON instructions have an optional datatype suffix that is
  6373. // completely ignored. Check for that.
  6374. if (isDataTypeToken(ExtraToken) &&
  6375. doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
  6376. continue;
  6377. // For for ARM mode generate an error if the .n qualifier is used.
  6378. if (ExtraToken == ".n" && !isThumb()) {
  6379. SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
  6380. return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
  6381. "arm mode");
  6382. }
  6383. // The .n qualifier is always discarded as that is what the tables
  6384. // and matcher expect. In ARM mode the .w qualifier has no effect,
  6385. // so discard it to avoid errors that can be caused by the matcher.
  6386. if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
  6387. SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
  6388. Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
  6389. }
  6390. }
  6391. // Read the remaining operands.
  6392. if (getLexer().isNot(AsmToken::EndOfStatement)) {
  6393. // Read the first operand.
  6394. if (parseOperand(Operands, Mnemonic)) {
  6395. return true;
  6396. }
  6397. while (parseOptionalToken(AsmToken::Comma)) {
  6398. // Parse and remember the operand.
  6399. if (parseOperand(Operands, Mnemonic)) {
  6400. return true;
  6401. }
  6402. }
  6403. }
  6404. if (parseToken(AsmToken::EndOfStatement, "unexpected token in argument list"))
  6405. return true;
  6406. tryConvertingToTwoOperandForm(Mnemonic, CarrySetting, Operands);
  6407. if (hasCDE() && MS.isCDEInstr(Mnemonic)) {
  6408. // Dual-register instructions use even-odd register pairs as their
  6409. // destination operand, in assembly such pair is spelled as two
  6410. // consecutive registers, without any special syntax. ConvertDualRegOperand
  6411. // tries to convert such operand into register pair, e.g. r2, r3 -> r2_r3.
  6412. // It returns true, if an error message has been emitted. If the function
  6413. // returns false, the function either succeeded or an error (e.g. missing
  6414. // operand) will be diagnosed elsewhere.
  6415. if (MS.isCDEDualRegInstr(Mnemonic)) {
  6416. bool GotError = CDEConvertDualRegOperand(Mnemonic, Operands);
  6417. if (GotError)
  6418. return GotError;
  6419. }
  6420. }
  6421. // Some instructions, mostly Thumb, have forms for the same mnemonic that
  6422. // do and don't have a cc_out optional-def operand. With some spot-checks
  6423. // of the operand list, we can figure out which variant we're trying to
  6424. // parse and adjust accordingly before actually matching. We shouldn't ever
  6425. // try to remove a cc_out operand that was explicitly set on the
  6426. // mnemonic, of course (CarrySetting == true). Reason number #317 the
  6427. // table driven matcher doesn't fit well with the ARM instruction set.
  6428. if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
  6429. Operands.erase(Operands.begin() + 1);
  6430. // Some instructions have the same mnemonic, but don't always
  6431. // have a predicate. Distinguish them here and delete the
  6432. // appropriate predicate if needed. This could be either the scalar
  6433. // predication code or the vector predication code.
  6434. if (PredicationCode == ARMCC::AL &&
  6435. shouldOmitPredicateOperand(Mnemonic, Operands))
  6436. Operands.erase(Operands.begin() + 1);
  6437. if (hasMVE()) {
  6438. if (!shouldOmitVectorPredicateOperand(Mnemonic, Operands) &&
  6439. Mnemonic == "vmov" && PredicationCode == ARMCC::LT) {
  6440. // Very nasty hack to deal with the vector predicated variant of vmovlt
  6441. // the scalar predicated vmov with condition 'lt'. We can not tell them
  6442. // apart until we have parsed their operands.
  6443. Operands.erase(Operands.begin() + 1);
  6444. Operands.erase(Operands.begin());
  6445. SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
  6446. SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
  6447. Mnemonic.size() - 1 + CarrySetting);
  6448. Operands.insert(Operands.begin(),
  6449. ARMOperand::CreateVPTPred(ARMVCC::None, PLoc));
  6450. Operands.insert(Operands.begin(),
  6451. ARMOperand::CreateToken(StringRef("vmovlt"), MLoc));
  6452. } else if (Mnemonic == "vcvt" && PredicationCode == ARMCC::NE &&
  6453. !shouldOmitVectorPredicateOperand(Mnemonic, Operands)) {
  6454. // Another nasty hack to deal with the ambiguity between vcvt with scalar
  6455. // predication 'ne' and vcvtn with vector predication 'e'. As above we
  6456. // can only distinguish between the two after we have parsed their
  6457. // operands.
  6458. Operands.erase(Operands.begin() + 1);
  6459. Operands.erase(Operands.begin());
  6460. SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
  6461. SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
  6462. Mnemonic.size() - 1 + CarrySetting);
  6463. Operands.insert(Operands.begin(),
  6464. ARMOperand::CreateVPTPred(ARMVCC::Else, PLoc));
  6465. Operands.insert(Operands.begin(),
  6466. ARMOperand::CreateToken(StringRef("vcvtn"), MLoc));
  6467. } else if (Mnemonic == "vmul" && PredicationCode == ARMCC::LT &&
  6468. !shouldOmitVectorPredicateOperand(Mnemonic, Operands)) {
  6469. // Another hack, this time to distinguish between scalar predicated vmul
  6470. // with 'lt' predication code and the vector instruction vmullt with
  6471. // vector predication code "none"
  6472. Operands.erase(Operands.begin() + 1);
  6473. Operands.erase(Operands.begin());
  6474. SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
  6475. Operands.insert(Operands.begin(),
  6476. ARMOperand::CreateToken(StringRef("vmullt"), MLoc));
  6477. }
  6478. // For vmov and vcmp, as mentioned earlier, we did not add the vector
  6479. // predication code, since these may contain operands that require
  6480. // special parsing. So now we have to see if they require vector
  6481. // predication and replace the scalar one with the vector predication
  6482. // operand if that is the case.
  6483. else if (Mnemonic == "vmov" || Mnemonic.startswith("vcmp") ||
  6484. (Mnemonic.startswith("vcvt") && !Mnemonic.startswith("vcvta") &&
  6485. !Mnemonic.startswith("vcvtn") && !Mnemonic.startswith("vcvtp") &&
  6486. !Mnemonic.startswith("vcvtm"))) {
  6487. if (!shouldOmitVectorPredicateOperand(Mnemonic, Operands)) {
  6488. // We could not split the vector predicate off vcvt because it might
  6489. // have been the scalar vcvtt instruction. Now we know its a vector
  6490. // instruction, we still need to check whether its the vector
  6491. // predicated vcvt with 'Then' predication or the vector vcvtt. We can
  6492. // distinguish the two based on the suffixes, if it is any of
  6493. // ".f16.f32", ".f32.f16", ".f16.f64" or ".f64.f16" then it is the vcvtt.
  6494. if (Mnemonic.startswith("vcvtt") && Operands.size() >= 4) {
  6495. auto Sz1 = static_cast<ARMOperand &>(*Operands[2]);
  6496. auto Sz2 = static_cast<ARMOperand &>(*Operands[3]);
  6497. if (!(Sz1.isToken() && Sz1.getToken().startswith(".f") &&
  6498. Sz2.isToken() && Sz2.getToken().startswith(".f"))) {
  6499. Operands.erase(Operands.begin());
  6500. SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer());
  6501. VPTPredicationCode = ARMVCC::Then;
  6502. Mnemonic = Mnemonic.substr(0, 4);
  6503. Operands.insert(Operands.begin(),
  6504. ARMOperand::CreateToken(Mnemonic, MLoc));
  6505. }
  6506. }
  6507. Operands.erase(Operands.begin() + 1);
  6508. SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() +
  6509. Mnemonic.size() + CarrySetting);
  6510. Operands.insert(Operands.begin() + 1,
  6511. ARMOperand::CreateVPTPred(
  6512. ARMVCC::VPTCodes(VPTPredicationCode), PLoc));
  6513. }
  6514. } else if (CanAcceptVPTPredicationCode) {
  6515. // For all other instructions, make sure only one of the two
  6516. // predication operands is left behind, depending on whether we should
  6517. // use the vector predication.
  6518. if (shouldOmitVectorPredicateOperand(Mnemonic, Operands)) {
  6519. if (CanAcceptPredicationCode)
  6520. Operands.erase(Operands.begin() + 2);
  6521. else
  6522. Operands.erase(Operands.begin() + 1);
  6523. } else if (CanAcceptPredicationCode && PredicationCode == ARMCC::AL) {
  6524. Operands.erase(Operands.begin() + 1);
  6525. }
  6526. }
  6527. }
  6528. if (VPTPredicationCode != ARMVCC::None) {
  6529. bool usedVPTPredicationCode = false;
  6530. for (unsigned I = 1; I < Operands.size(); ++I)
  6531. if (static_cast<ARMOperand &>(*Operands[I]).isVPTPred())
  6532. usedVPTPredicationCode = true;
  6533. if (!usedVPTPredicationCode) {
  6534. // If we have a VPT predication code and we haven't just turned it
  6535. // into an operand, then it was a mistake for splitMnemonic to
  6536. // separate it from the rest of the mnemonic in the first place,
  6537. // and this may lead to wrong disassembly (e.g. scalar floating
  6538. // point VCMPE is actually a different instruction from VCMP, so
  6539. // we mustn't treat them the same). In that situation, glue it
  6540. // back on.
  6541. Mnemonic = Name.slice(0, Mnemonic.size() + 1);
  6542. Operands.erase(Operands.begin());
  6543. Operands.insert(Operands.begin(),
  6544. ARMOperand::CreateToken(Mnemonic, NameLoc));
  6545. }
  6546. }
  6547. // ARM mode 'blx' need special handling, as the register operand version
  6548. // is predicable, but the label operand version is not. So, we can't rely
  6549. // on the Mnemonic based checking to correctly figure out when to put
  6550. // a k_CondCode operand in the list. If we're trying to match the label
  6551. // version, remove the k_CondCode operand here.
  6552. if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
  6553. static_cast<ARMOperand &>(*Operands[2]).isImm())
  6554. Operands.erase(Operands.begin() + 1);
  6555. // Adjust operands of ldrexd/strexd to MCK_GPRPair.
  6556. // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
  6557. // a single GPRPair reg operand is used in the .td file to replace the two
  6558. // GPRs. However, when parsing from asm, the two GRPs cannot be
  6559. // automatically
  6560. // expressed as a GPRPair, so we have to manually merge them.
  6561. // FIXME: We would really like to be able to tablegen'erate this.
  6562. if (!isThumb() && Operands.size() > 4 &&
  6563. (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
  6564. Mnemonic == "stlexd")) {
  6565. bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
  6566. unsigned Idx = isLoad ? 2 : 3;
  6567. ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
  6568. ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
  6569. const MCRegisterClass &MRC = MRI->getRegClass(ARM::GPRRegClassID);
  6570. // Adjust only if Op1 and Op2 are GPRs.
  6571. if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
  6572. MRC.contains(Op2.getReg())) {
  6573. unsigned Reg1 = Op1.getReg();
  6574. unsigned Reg2 = Op2.getReg();
  6575. unsigned Rt = MRI->getEncodingValue(Reg1);
  6576. unsigned Rt2 = MRI->getEncodingValue(Reg2);
  6577. // Rt2 must be Rt + 1 and Rt must be even.
  6578. if (Rt + 1 != Rt2 || (Rt & 1)) {
  6579. return Error(Op2.getStartLoc(),
  6580. isLoad ? "destination operands must be sequential"
  6581. : "source operands must be sequential");
  6582. }
  6583. unsigned NewReg = MRI->getMatchingSuperReg(
  6584. Reg1, ARM::gsub_0, &(MRI->getRegClass(ARM::GPRPairRegClassID)));
  6585. Operands[Idx] =
  6586. ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
  6587. Operands.erase(Operands.begin() + Idx + 1);
  6588. }
  6589. }
  6590. // GNU Assembler extension (compatibility).
  6591. fixupGNULDRDAlias(Mnemonic, Operands);
  6592. // FIXME: As said above, this is all a pretty gross hack. This instruction
  6593. // does not fit with other "subs" and tblgen.
  6594. // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
  6595. // so the Mnemonic is the original name "subs" and delete the predicate
  6596. // operand so it will match the table entry.
  6597. if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
  6598. static_cast<ARMOperand &>(*Operands[3]).isReg() &&
  6599. static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
  6600. static_cast<ARMOperand &>(*Operands[4]).isReg() &&
  6601. static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
  6602. static_cast<ARMOperand &>(*Operands[5]).isImm()) {
  6603. Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
  6604. Operands.erase(Operands.begin() + 1);
  6605. }
  6606. return false;
  6607. }
  6608. // Validate context-sensitive operand constraints.
  6609. // return 'true' if register list contains non-low GPR registers,
  6610. // 'false' otherwise. If Reg is in the register list or is HiReg, set
  6611. // 'containsReg' to true.
  6612. static bool checkLowRegisterList(const MCInst &Inst, unsigned OpNo,
  6613. unsigned Reg, unsigned HiReg,
  6614. bool &containsReg) {
  6615. containsReg = false;
  6616. for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
  6617. unsigned OpReg = Inst.getOperand(i).getReg();
  6618. if (OpReg == Reg)
  6619. containsReg = true;
  6620. // Anything other than a low register isn't legal here.
  6621. if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
  6622. return true;
  6623. }
  6624. return false;
  6625. }
  6626. // Check if the specified regisgter is in the register list of the inst,
  6627. // starting at the indicated operand number.
  6628. static bool listContainsReg(const MCInst &Inst, unsigned OpNo, unsigned Reg) {
  6629. for (unsigned i = OpNo, e = Inst.getNumOperands(); i < e; ++i) {
  6630. unsigned OpReg = Inst.getOperand(i).getReg();
  6631. if (OpReg == Reg)
  6632. return true;
  6633. }
  6634. return false;
  6635. }
  6636. // Return true if instruction has the interesting property of being
  6637. // allowed in IT blocks, but not being predicable.
  6638. static bool instIsBreakpoint(const MCInst &Inst) {
  6639. return Inst.getOpcode() == ARM::tBKPT ||
  6640. Inst.getOpcode() == ARM::BKPT ||
  6641. Inst.getOpcode() == ARM::tHLT ||
  6642. Inst.getOpcode() == ARM::HLT;
  6643. }
  6644. bool ARMAsmParser::validatetLDMRegList(const MCInst &Inst,
  6645. const OperandVector &Operands,
  6646. unsigned ListNo, bool IsARPop) {
  6647. const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
  6648. bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
  6649. bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
  6650. bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR);
  6651. bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
  6652. if (!IsARPop && ListContainsSP)
  6653. return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
  6654. "SP may not be in the register list");
  6655. else if (ListContainsPC && ListContainsLR)
  6656. return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
  6657. "PC and LR may not be in the register list simultaneously");
  6658. return false;
  6659. }
  6660. bool ARMAsmParser::validatetSTMRegList(const MCInst &Inst,
  6661. const OperandVector &Operands,
  6662. unsigned ListNo) {
  6663. const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
  6664. bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
  6665. bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
  6666. bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
  6667. if (ListContainsSP && ListContainsPC)
  6668. return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
  6669. "SP and PC may not be in the register list");
  6670. else if (ListContainsSP)
  6671. return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
  6672. "SP may not be in the register list");
  6673. else if (ListContainsPC)
  6674. return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
  6675. "PC may not be in the register list");
  6676. return false;
  6677. }
  6678. bool ARMAsmParser::validateLDRDSTRD(MCInst &Inst,
  6679. const OperandVector &Operands,
  6680. bool Load, bool ARMMode, bool Writeback) {
  6681. unsigned RtIndex = Load || !Writeback ? 0 : 1;
  6682. unsigned Rt = MRI->getEncodingValue(Inst.getOperand(RtIndex).getReg());
  6683. unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(RtIndex + 1).getReg());
  6684. if (ARMMode) {
  6685. // Rt can't be R14.
  6686. if (Rt == 14)
  6687. return Error(Operands[3]->getStartLoc(),
  6688. "Rt can't be R14");
  6689. // Rt must be even-numbered.
  6690. if ((Rt & 1) == 1)
  6691. return Error(Operands[3]->getStartLoc(),
  6692. "Rt must be even-numbered");
  6693. // Rt2 must be Rt + 1.
  6694. if (Rt2 != Rt + 1) {
  6695. if (Load)
  6696. return Error(Operands[3]->getStartLoc(),
  6697. "destination operands must be sequential");
  6698. else
  6699. return Error(Operands[3]->getStartLoc(),
  6700. "source operands must be sequential");
  6701. }
  6702. // FIXME: Diagnose m == 15
  6703. // FIXME: Diagnose ldrd with m == t || m == t2.
  6704. }
  6705. if (!ARMMode && Load) {
  6706. if (Rt2 == Rt)
  6707. return Error(Operands[3]->getStartLoc(),
  6708. "destination operands can't be identical");
  6709. }
  6710. if (Writeback) {
  6711. unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
  6712. if (Rn == Rt || Rn == Rt2) {
  6713. if (Load)
  6714. return Error(Operands[3]->getStartLoc(),
  6715. "base register needs to be different from destination "
  6716. "registers");
  6717. else
  6718. return Error(Operands[3]->getStartLoc(),
  6719. "source register and base register can't be identical");
  6720. }
  6721. // FIXME: Diagnose ldrd/strd with writeback and n == 15.
  6722. // (Except the immediate form of ldrd?)
  6723. }
  6724. return false;
  6725. }
  6726. static int findFirstVectorPredOperandIdx(const MCInstrDesc &MCID) {
  6727. for (unsigned i = 0; i < MCID.NumOperands; ++i) {
  6728. if (ARM::isVpred(MCID.OpInfo[i].OperandType))
  6729. return i;
  6730. }
  6731. return -1;
  6732. }
  6733. static bool isVectorPredicable(const MCInstrDesc &MCID) {
  6734. return findFirstVectorPredOperandIdx(MCID) != -1;
  6735. }
  6736. // FIXME: We would really like to be able to tablegen'erate this.
  6737. bool ARMAsmParser::validateInstruction(MCInst &Inst,
  6738. const OperandVector &Operands) {
  6739. const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
  6740. SMLoc Loc = Operands[0]->getStartLoc();
  6741. // Check the IT block state first.
  6742. // NOTE: BKPT and HLT instructions have the interesting property of being
  6743. // allowed in IT blocks, but not being predicable. They just always execute.
  6744. if (inITBlock() && !instIsBreakpoint(Inst)) {
  6745. // The instruction must be predicable.
  6746. if (!MCID.isPredicable())
  6747. return Error(Loc, "instructions in IT block must be predicable");
  6748. ARMCC::CondCodes Cond = ARMCC::CondCodes(
  6749. Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm());
  6750. if (Cond != currentITCond()) {
  6751. // Find the condition code Operand to get its SMLoc information.
  6752. SMLoc CondLoc;
  6753. for (unsigned I = 1; I < Operands.size(); ++I)
  6754. if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
  6755. CondLoc = Operands[I]->getStartLoc();
  6756. return Error(CondLoc, "incorrect condition in IT block; got '" +
  6757. StringRef(ARMCondCodeToString(Cond)) +
  6758. "', but expected '" +
  6759. ARMCondCodeToString(currentITCond()) + "'");
  6760. }
  6761. // Check for non-'al' condition codes outside of the IT block.
  6762. } else if (isThumbTwo() && MCID.isPredicable() &&
  6763. Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
  6764. ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
  6765. Inst.getOpcode() != ARM::t2Bcc &&
  6766. Inst.getOpcode() != ARM::t2BFic) {
  6767. return Error(Loc, "predicated instructions must be in IT block");
  6768. } else if (!isThumb() && !useImplicitITARM() && MCID.isPredicable() &&
  6769. Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
  6770. ARMCC::AL) {
  6771. return Warning(Loc, "predicated instructions should be in IT block");
  6772. } else if (!MCID.isPredicable()) {
  6773. // Check the instruction doesn't have a predicate operand anyway
  6774. // that it's not allowed to use. Sometimes this happens in order
  6775. // to keep instructions the same shape even though one cannot
  6776. // legally be predicated, e.g. vmul.f16 vs vmul.f32.
  6777. for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i) {
  6778. if (MCID.OpInfo[i].isPredicate()) {
  6779. if (Inst.getOperand(i).getImm() != ARMCC::AL)
  6780. return Error(Loc, "instruction is not predicable");
  6781. break;
  6782. }
  6783. }
  6784. }
  6785. // PC-setting instructions in an IT block, but not the last instruction of
  6786. // the block, are UNPREDICTABLE.
  6787. if (inExplicitITBlock() && !lastInITBlock() && isITBlockTerminator(Inst)) {
  6788. return Error(Loc, "instruction must be outside of IT block or the last instruction in an IT block");
  6789. }
  6790. if (inVPTBlock() && !instIsBreakpoint(Inst)) {
  6791. unsigned Bit = extractITMaskBit(VPTState.Mask, VPTState.CurPosition);
  6792. if (!isVectorPredicable(MCID))
  6793. return Error(Loc, "instruction in VPT block must be predicable");
  6794. unsigned Pred = Inst.getOperand(findFirstVectorPredOperandIdx(MCID)).getImm();
  6795. unsigned VPTPred = Bit ? ARMVCC::Else : ARMVCC::Then;
  6796. if (Pred != VPTPred) {
  6797. SMLoc PredLoc;
  6798. for (unsigned I = 1; I < Operands.size(); ++I)
  6799. if (static_cast<ARMOperand &>(*Operands[I]).isVPTPred())
  6800. PredLoc = Operands[I]->getStartLoc();
  6801. return Error(PredLoc, "incorrect predication in VPT block; got '" +
  6802. StringRef(ARMVPTPredToString(ARMVCC::VPTCodes(Pred))) +
  6803. "', but expected '" +
  6804. ARMVPTPredToString(ARMVCC::VPTCodes(VPTPred)) + "'");
  6805. }
  6806. }
  6807. else if (isVectorPredicable(MCID) &&
  6808. Inst.getOperand(findFirstVectorPredOperandIdx(MCID)).getImm() !=
  6809. ARMVCC::None)
  6810. return Error(Loc, "VPT predicated instructions must be in VPT block");
  6811. const unsigned Opcode = Inst.getOpcode();
  6812. switch (Opcode) {
  6813. case ARM::t2IT: {
  6814. // Encoding is unpredictable if it ever results in a notional 'NV'
  6815. // predicate. Since we don't parse 'NV' directly this means an 'AL'
  6816. // predicate with an "else" mask bit.
  6817. unsigned Cond = Inst.getOperand(0).getImm();
  6818. unsigned Mask = Inst.getOperand(1).getImm();
  6819. // Conditions only allowing a 't' are those with no set bit except
  6820. // the lowest-order one that indicates the end of the sequence. In
  6821. // other words, powers of 2.
  6822. if (Cond == ARMCC::AL && countPopulation(Mask) != 1)
  6823. return Error(Loc, "unpredictable IT predicate sequence");
  6824. break;
  6825. }
  6826. case ARM::LDRD:
  6827. if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/true,
  6828. /*Writeback*/false))
  6829. return true;
  6830. break;
  6831. case ARM::LDRD_PRE:
  6832. case ARM::LDRD_POST:
  6833. if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/true,
  6834. /*Writeback*/true))
  6835. return true;
  6836. break;
  6837. case ARM::t2LDRDi8:
  6838. if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/false,
  6839. /*Writeback*/false))
  6840. return true;
  6841. break;
  6842. case ARM::t2LDRD_PRE:
  6843. case ARM::t2LDRD_POST:
  6844. if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/false,
  6845. /*Writeback*/true))
  6846. return true;
  6847. break;
  6848. case ARM::t2BXJ: {
  6849. const unsigned RmReg = Inst.getOperand(0).getReg();
  6850. // Rm = SP is no longer unpredictable in v8-A
  6851. if (RmReg == ARM::SP && !hasV8Ops())
  6852. return Error(Operands[2]->getStartLoc(),
  6853. "r13 (SP) is an unpredictable operand to BXJ");
  6854. return false;
  6855. }
  6856. case ARM::STRD:
  6857. if (validateLDRDSTRD(Inst, Operands, /*Load*/false, /*ARMMode*/true,
  6858. /*Writeback*/false))
  6859. return true;
  6860. break;
  6861. case ARM::STRD_PRE:
  6862. case ARM::STRD_POST:
  6863. if (validateLDRDSTRD(Inst, Operands, /*Load*/false, /*ARMMode*/true,
  6864. /*Writeback*/true))
  6865. return true;
  6866. break;
  6867. case ARM::t2STRD_PRE:
  6868. case ARM::t2STRD_POST:
  6869. if (validateLDRDSTRD(Inst, Operands, /*Load*/false, /*ARMMode*/false,
  6870. /*Writeback*/true))
  6871. return true;
  6872. break;
  6873. case ARM::STR_PRE_IMM:
  6874. case ARM::STR_PRE_REG:
  6875. case ARM::t2STR_PRE:
  6876. case ARM::STR_POST_IMM:
  6877. case ARM::STR_POST_REG:
  6878. case ARM::t2STR_POST:
  6879. case ARM::STRH_PRE:
  6880. case ARM::t2STRH_PRE:
  6881. case ARM::STRH_POST:
  6882. case ARM::t2STRH_POST:
  6883. case ARM::STRB_PRE_IMM:
  6884. case ARM::STRB_PRE_REG:
  6885. case ARM::t2STRB_PRE:
  6886. case ARM::STRB_POST_IMM:
  6887. case ARM::STRB_POST_REG:
  6888. case ARM::t2STRB_POST: {
  6889. // Rt must be different from Rn.
  6890. const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
  6891. const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
  6892. if (Rt == Rn)
  6893. return Error(Operands[3]->getStartLoc(),
  6894. "source register and base register can't be identical");
  6895. return false;
  6896. }
  6897. case ARM::t2LDR_PRE_imm:
  6898. case ARM::t2LDR_POST_imm:
  6899. case ARM::t2STR_PRE_imm:
  6900. case ARM::t2STR_POST_imm: {
  6901. // Rt must be different from Rn.
  6902. const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
  6903. const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(1).getReg());
  6904. if (Rt == Rn)
  6905. return Error(Operands[3]->getStartLoc(),
  6906. "destination register and base register can't be identical");
  6907. if (Inst.getOpcode() == ARM::t2LDR_POST_imm ||
  6908. Inst.getOpcode() == ARM::t2STR_POST_imm) {
  6909. int Imm = Inst.getOperand(2).getImm();
  6910. if (Imm > 255 || Imm < -255)
  6911. return Error(Operands[5]->getStartLoc(),
  6912. "operand must be in range [-255, 255]");
  6913. }
  6914. if (Inst.getOpcode() == ARM::t2STR_PRE_imm ||
  6915. Inst.getOpcode() == ARM::t2STR_POST_imm) {
  6916. if (Inst.getOperand(0).getReg() == ARM::PC) {
  6917. return Error(Operands[3]->getStartLoc(),
  6918. "operand must be a register in range [r0, r14]");
  6919. }
  6920. }
  6921. return false;
  6922. }
  6923. case ARM::LDR_PRE_IMM:
  6924. case ARM::LDR_PRE_REG:
  6925. case ARM::t2LDR_PRE:
  6926. case ARM::LDR_POST_IMM:
  6927. case ARM::LDR_POST_REG:
  6928. case ARM::t2LDR_POST:
  6929. case ARM::LDRH_PRE:
  6930. case ARM::t2LDRH_PRE:
  6931. case ARM::LDRH_POST:
  6932. case ARM::t2LDRH_POST:
  6933. case ARM::LDRSH_PRE:
  6934. case ARM::t2LDRSH_PRE:
  6935. case ARM::LDRSH_POST:
  6936. case ARM::t2LDRSH_POST:
  6937. case ARM::LDRB_PRE_IMM:
  6938. case ARM::LDRB_PRE_REG:
  6939. case ARM::t2LDRB_PRE:
  6940. case ARM::LDRB_POST_IMM:
  6941. case ARM::LDRB_POST_REG:
  6942. case ARM::t2LDRB_POST:
  6943. case ARM::LDRSB_PRE:
  6944. case ARM::t2LDRSB_PRE:
  6945. case ARM::LDRSB_POST:
  6946. case ARM::t2LDRSB_POST: {
  6947. // Rt must be different from Rn.
  6948. const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
  6949. const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
  6950. if (Rt == Rn)
  6951. return Error(Operands[3]->getStartLoc(),
  6952. "destination register and base register can't be identical");
  6953. return false;
  6954. }
  6955. case ARM::MVE_VLDRBU8_rq:
  6956. case ARM::MVE_VLDRBU16_rq:
  6957. case ARM::MVE_VLDRBS16_rq:
  6958. case ARM::MVE_VLDRBU32_rq:
  6959. case ARM::MVE_VLDRBS32_rq:
  6960. case ARM::MVE_VLDRHU16_rq:
  6961. case ARM::MVE_VLDRHU16_rq_u:
  6962. case ARM::MVE_VLDRHU32_rq:
  6963. case ARM::MVE_VLDRHU32_rq_u:
  6964. case ARM::MVE_VLDRHS32_rq:
  6965. case ARM::MVE_VLDRHS32_rq_u:
  6966. case ARM::MVE_VLDRWU32_rq:
  6967. case ARM::MVE_VLDRWU32_rq_u:
  6968. case ARM::MVE_VLDRDU64_rq:
  6969. case ARM::MVE_VLDRDU64_rq_u:
  6970. case ARM::MVE_VLDRWU32_qi:
  6971. case ARM::MVE_VLDRWU32_qi_pre:
  6972. case ARM::MVE_VLDRDU64_qi:
  6973. case ARM::MVE_VLDRDU64_qi_pre: {
  6974. // Qd must be different from Qm.
  6975. unsigned QdIdx = 0, QmIdx = 2;
  6976. bool QmIsPointer = false;
  6977. switch (Opcode) {
  6978. case ARM::MVE_VLDRWU32_qi:
  6979. case ARM::MVE_VLDRDU64_qi:
  6980. QmIdx = 1;
  6981. QmIsPointer = true;
  6982. break;
  6983. case ARM::MVE_VLDRWU32_qi_pre:
  6984. case ARM::MVE_VLDRDU64_qi_pre:
  6985. QdIdx = 1;
  6986. QmIsPointer = true;
  6987. break;
  6988. }
  6989. const unsigned Qd = MRI->getEncodingValue(Inst.getOperand(QdIdx).getReg());
  6990. const unsigned Qm = MRI->getEncodingValue(Inst.getOperand(QmIdx).getReg());
  6991. if (Qd == Qm) {
  6992. return Error(Operands[3]->getStartLoc(),
  6993. Twine("destination vector register and vector ") +
  6994. (QmIsPointer ? "pointer" : "offset") +
  6995. " register can't be identical");
  6996. }
  6997. return false;
  6998. }
  6999. case ARM::SBFX:
  7000. case ARM::t2SBFX:
  7001. case ARM::UBFX:
  7002. case ARM::t2UBFX: {
  7003. // Width must be in range [1, 32-lsb].
  7004. unsigned LSB = Inst.getOperand(2).getImm();
  7005. unsigned Widthm1 = Inst.getOperand(3).getImm();
  7006. if (Widthm1 >= 32 - LSB)
  7007. return Error(Operands[5]->getStartLoc(),
  7008. "bitfield width must be in range [1,32-lsb]");
  7009. return false;
  7010. }
  7011. // Notionally handles ARM::tLDMIA_UPD too.
  7012. case ARM::tLDMIA: {
  7013. // If we're parsing Thumb2, the .w variant is available and handles
  7014. // most cases that are normally illegal for a Thumb1 LDM instruction.
  7015. // We'll make the transformation in processInstruction() if necessary.
  7016. //
  7017. // Thumb LDM instructions are writeback iff the base register is not
  7018. // in the register list.
  7019. unsigned Rn = Inst.getOperand(0).getReg();
  7020. bool HasWritebackToken =
  7021. (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
  7022. static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
  7023. bool ListContainsBase;
  7024. if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
  7025. return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
  7026. "registers must be in range r0-r7");
  7027. // If we should have writeback, then there should be a '!' token.
  7028. if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
  7029. return Error(Operands[2]->getStartLoc(),
  7030. "writeback operator '!' expected");
  7031. // If we should not have writeback, there must not be a '!'. This is
  7032. // true even for the 32-bit wide encodings.
  7033. if (ListContainsBase && HasWritebackToken)
  7034. return Error(Operands[3]->getStartLoc(),
  7035. "writeback operator '!' not allowed when base register "
  7036. "in register list");
  7037. if (validatetLDMRegList(Inst, Operands, 3))
  7038. return true;
  7039. break;
  7040. }
  7041. case ARM::LDMIA_UPD:
  7042. case ARM::LDMDB_UPD:
  7043. case ARM::LDMIB_UPD:
  7044. case ARM::LDMDA_UPD:
  7045. // ARM variants loading and updating the same register are only officially
  7046. // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
  7047. if (!hasV7Ops())
  7048. break;
  7049. if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
  7050. return Error(Operands.back()->getStartLoc(),
  7051. "writeback register not allowed in register list");
  7052. break;
  7053. case ARM::t2LDMIA:
  7054. case ARM::t2LDMDB:
  7055. if (validatetLDMRegList(Inst, Operands, 3))
  7056. return true;
  7057. break;
  7058. case ARM::t2STMIA:
  7059. case ARM::t2STMDB:
  7060. if (validatetSTMRegList(Inst, Operands, 3))
  7061. return true;
  7062. break;
  7063. case ARM::t2LDMIA_UPD:
  7064. case ARM::t2LDMDB_UPD:
  7065. case ARM::t2STMIA_UPD:
  7066. case ARM::t2STMDB_UPD:
  7067. if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
  7068. return Error(Operands.back()->getStartLoc(),
  7069. "writeback register not allowed in register list");
  7070. if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) {
  7071. if (validatetLDMRegList(Inst, Operands, 3))
  7072. return true;
  7073. } else {
  7074. if (validatetSTMRegList(Inst, Operands, 3))
  7075. return true;
  7076. }
  7077. break;
  7078. case ARM::sysLDMIA_UPD:
  7079. case ARM::sysLDMDA_UPD:
  7080. case ARM::sysLDMDB_UPD:
  7081. case ARM::sysLDMIB_UPD:
  7082. if (!listContainsReg(Inst, 3, ARM::PC))
  7083. return Error(Operands[4]->getStartLoc(),
  7084. "writeback register only allowed on system LDM "
  7085. "if PC in register-list");
  7086. break;
  7087. case ARM::sysSTMIA_UPD:
  7088. case ARM::sysSTMDA_UPD:
  7089. case ARM::sysSTMDB_UPD:
  7090. case ARM::sysSTMIB_UPD:
  7091. return Error(Operands[2]->getStartLoc(),
  7092. "system STM cannot have writeback register");
  7093. case ARM::tMUL:
  7094. // The second source operand must be the same register as the destination
  7095. // operand.
  7096. //
  7097. // In this case, we must directly check the parsed operands because the
  7098. // cvtThumbMultiply() function is written in such a way that it guarantees
  7099. // this first statement is always true for the new Inst. Essentially, the
  7100. // destination is unconditionally copied into the second source operand
  7101. // without checking to see if it matches what we actually parsed.
  7102. if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
  7103. ((ARMOperand &)*Operands[5]).getReg()) &&
  7104. (((ARMOperand &)*Operands[3]).getReg() !=
  7105. ((ARMOperand &)*Operands[4]).getReg())) {
  7106. return Error(Operands[3]->getStartLoc(),
  7107. "destination register must match source register");
  7108. }
  7109. break;
  7110. // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
  7111. // so only issue a diagnostic for thumb1. The instructions will be
  7112. // switched to the t2 encodings in processInstruction() if necessary.
  7113. case ARM::tPOP: {
  7114. bool ListContainsBase;
  7115. if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
  7116. !isThumbTwo())
  7117. return Error(Operands[2]->getStartLoc(),
  7118. "registers must be in range r0-r7 or pc");
  7119. if (validatetLDMRegList(Inst, Operands, 2, !isMClass()))
  7120. return true;
  7121. break;
  7122. }
  7123. case ARM::tPUSH: {
  7124. bool ListContainsBase;
  7125. if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
  7126. !isThumbTwo())
  7127. return Error(Operands[2]->getStartLoc(),
  7128. "registers must be in range r0-r7 or lr");
  7129. if (validatetSTMRegList(Inst, Operands, 2))
  7130. return true;
  7131. break;
  7132. }
  7133. case ARM::tSTMIA_UPD: {
  7134. bool ListContainsBase, InvalidLowList;
  7135. InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
  7136. 0, ListContainsBase);
  7137. if (InvalidLowList && !isThumbTwo())
  7138. return Error(Operands[4]->getStartLoc(),
  7139. "registers must be in range r0-r7");
  7140. // This would be converted to a 32-bit stm, but that's not valid if the
  7141. // writeback register is in the list.
  7142. if (InvalidLowList && ListContainsBase)
  7143. return Error(Operands[4]->getStartLoc(),
  7144. "writeback operator '!' not allowed when base register "
  7145. "in register list");
  7146. if (validatetSTMRegList(Inst, Operands, 4))
  7147. return true;
  7148. break;
  7149. }
  7150. case ARM::tADDrSP:
  7151. // If the non-SP source operand and the destination operand are not the
  7152. // same, we need thumb2 (for the wide encoding), or we have an error.
  7153. if (!isThumbTwo() &&
  7154. Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
  7155. return Error(Operands[4]->getStartLoc(),
  7156. "source register must be the same as destination");
  7157. }
  7158. break;
  7159. case ARM::t2ADDrr:
  7160. case ARM::t2ADDrs:
  7161. case ARM::t2SUBrr:
  7162. case ARM::t2SUBrs:
  7163. if (Inst.getOperand(0).getReg() == ARM::SP &&
  7164. Inst.getOperand(1).getReg() != ARM::SP)
  7165. return Error(Operands[4]->getStartLoc(),
  7166. "source register must be sp if destination is sp");
  7167. break;
  7168. // Final range checking for Thumb unconditional branch instructions.
  7169. case ARM::tB:
  7170. if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
  7171. return Error(Operands[2]->getStartLoc(), "branch target out of range");
  7172. break;
  7173. case ARM::t2B: {
  7174. int op = (Operands[2]->isImm()) ? 2 : 3;
  7175. ARMOperand &Operand = static_cast<ARMOperand &>(*Operands[op]);
  7176. // Delay the checks of symbolic expressions until they are resolved.
  7177. if (!isa<MCBinaryExpr>(Operand.getImm()) &&
  7178. !Operand.isSignedOffset<24, 1>())
  7179. return Error(Operands[op]->getStartLoc(), "branch target out of range");
  7180. break;
  7181. }
  7182. // Final range checking for Thumb conditional branch instructions.
  7183. case ARM::tBcc:
  7184. if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
  7185. return Error(Operands[2]->getStartLoc(), "branch target out of range");
  7186. break;
  7187. case ARM::t2Bcc: {
  7188. int Op = (Operands[2]->isImm()) ? 2 : 3;
  7189. if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
  7190. return Error(Operands[Op]->getStartLoc(), "branch target out of range");
  7191. break;
  7192. }
  7193. case ARM::tCBZ:
  7194. case ARM::tCBNZ: {
  7195. if (!static_cast<ARMOperand &>(*Operands[2]).isUnsignedOffset<6, 1>())
  7196. return Error(Operands[2]->getStartLoc(), "branch target out of range");
  7197. break;
  7198. }
  7199. case ARM::MOVi16:
  7200. case ARM::MOVTi16:
  7201. case ARM::t2MOVi16:
  7202. case ARM::t2MOVTi16:
  7203. {
  7204. // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
  7205. // especially when we turn it into a movw and the expression <symbol> does
  7206. // not have a :lower16: or :upper16 as part of the expression. We don't
  7207. // want the behavior of silently truncating, which can be unexpected and
  7208. // lead to bugs that are difficult to find since this is an easy mistake
  7209. // to make.
  7210. int i = (Operands[3]->isImm()) ? 3 : 4;
  7211. ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
  7212. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
  7213. if (CE) break;
  7214. const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
  7215. if (!E) break;
  7216. const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
  7217. if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
  7218. ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
  7219. return Error(
  7220. Op.getStartLoc(),
  7221. "immediate expression for mov requires :lower16: or :upper16");
  7222. break;
  7223. }
  7224. case ARM::HINT:
  7225. case ARM::t2HINT: {
  7226. unsigned Imm8 = Inst.getOperand(0).getImm();
  7227. unsigned Pred = Inst.getOperand(1).getImm();
  7228. // ESB is not predicable (pred must be AL). Without the RAS extension, this
  7229. // behaves as any other unallocated hint.
  7230. if (Imm8 == 0x10 && Pred != ARMCC::AL && hasRAS())
  7231. return Error(Operands[1]->getStartLoc(), "instruction 'esb' is not "
  7232. "predicable, but condition "
  7233. "code specified");
  7234. if (Imm8 == 0x14 && Pred != ARMCC::AL)
  7235. return Error(Operands[1]->getStartLoc(), "instruction 'csdb' is not "
  7236. "predicable, but condition "
  7237. "code specified");
  7238. break;
  7239. }
  7240. case ARM::t2BFi:
  7241. case ARM::t2BFr:
  7242. case ARM::t2BFLi:
  7243. case ARM::t2BFLr: {
  7244. if (!static_cast<ARMOperand &>(*Operands[2]).isUnsignedOffset<4, 1>() ||
  7245. (Inst.getOperand(0).isImm() && Inst.getOperand(0).getImm() == 0))
  7246. return Error(Operands[2]->getStartLoc(),
  7247. "branch location out of range or not a multiple of 2");
  7248. if (Opcode == ARM::t2BFi) {
  7249. if (!static_cast<ARMOperand &>(*Operands[3]).isSignedOffset<16, 1>())
  7250. return Error(Operands[3]->getStartLoc(),
  7251. "branch target out of range or not a multiple of 2");
  7252. } else if (Opcode == ARM::t2BFLi) {
  7253. if (!static_cast<ARMOperand &>(*Operands[3]).isSignedOffset<18, 1>())
  7254. return Error(Operands[3]->getStartLoc(),
  7255. "branch target out of range or not a multiple of 2");
  7256. }
  7257. break;
  7258. }
  7259. case ARM::t2BFic: {
  7260. if (!static_cast<ARMOperand &>(*Operands[1]).isUnsignedOffset<4, 1>() ||
  7261. (Inst.getOperand(0).isImm() && Inst.getOperand(0).getImm() == 0))
  7262. return Error(Operands[1]->getStartLoc(),
  7263. "branch location out of range or not a multiple of 2");
  7264. if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<16, 1>())
  7265. return Error(Operands[2]->getStartLoc(),
  7266. "branch target out of range or not a multiple of 2");
  7267. assert(Inst.getOperand(0).isImm() == Inst.getOperand(2).isImm() &&
  7268. "branch location and else branch target should either both be "
  7269. "immediates or both labels");
  7270. if (Inst.getOperand(0).isImm() && Inst.getOperand(2).isImm()) {
  7271. int Diff = Inst.getOperand(2).getImm() - Inst.getOperand(0).getImm();
  7272. if (Diff != 4 && Diff != 2)
  7273. return Error(
  7274. Operands[3]->getStartLoc(),
  7275. "else branch target must be 2 or 4 greater than the branch location");
  7276. }
  7277. break;
  7278. }
  7279. case ARM::t2CLRM: {
  7280. for (unsigned i = 2; i < Inst.getNumOperands(); i++) {
  7281. if (Inst.getOperand(i).isReg() &&
  7282. !ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains(
  7283. Inst.getOperand(i).getReg())) {
  7284. return Error(Operands[2]->getStartLoc(),
  7285. "invalid register in register list. Valid registers are "
  7286. "r0-r12, lr/r14 and APSR.");
  7287. }
  7288. }
  7289. break;
  7290. }
  7291. case ARM::DSB:
  7292. case ARM::t2DSB: {
  7293. if (Inst.getNumOperands() < 2)
  7294. break;
  7295. unsigned Option = Inst.getOperand(0).getImm();
  7296. unsigned Pred = Inst.getOperand(1).getImm();
  7297. // SSBB and PSSBB (DSB #0|#4) are not predicable (pred must be AL).
  7298. if (Option == 0 && Pred != ARMCC::AL)
  7299. return Error(Operands[1]->getStartLoc(),
  7300. "instruction 'ssbb' is not predicable, but condition code "
  7301. "specified");
  7302. if (Option == 4 && Pred != ARMCC::AL)
  7303. return Error(Operands[1]->getStartLoc(),
  7304. "instruction 'pssbb' is not predicable, but condition code "
  7305. "specified");
  7306. break;
  7307. }
  7308. case ARM::VMOVRRS: {
  7309. // Source registers must be sequential.
  7310. const unsigned Sm = MRI->getEncodingValue(Inst.getOperand(2).getReg());
  7311. const unsigned Sm1 = MRI->getEncodingValue(Inst.getOperand(3).getReg());
  7312. if (Sm1 != Sm + 1)
  7313. return Error(Operands[5]->getStartLoc(),
  7314. "source operands must be sequential");
  7315. break;
  7316. }
  7317. case ARM::VMOVSRR: {
  7318. // Destination registers must be sequential.
  7319. const unsigned Sm = MRI->getEncodingValue(Inst.getOperand(0).getReg());
  7320. const unsigned Sm1 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
  7321. if (Sm1 != Sm + 1)
  7322. return Error(Operands[3]->getStartLoc(),
  7323. "destination operands must be sequential");
  7324. break;
  7325. }
  7326. case ARM::VLDMDIA:
  7327. case ARM::VSTMDIA: {
  7328. ARMOperand &Op = static_cast<ARMOperand&>(*Operands[3]);
  7329. auto &RegList = Op.getRegList();
  7330. if (RegList.size() < 1 || RegList.size() > 16)
  7331. return Error(Operands[3]->getStartLoc(),
  7332. "list of registers must be at least 1 and at most 16");
  7333. break;
  7334. }
  7335. case ARM::MVE_VQDMULLs32bh:
  7336. case ARM::MVE_VQDMULLs32th:
  7337. case ARM::MVE_VCMULf32:
  7338. case ARM::MVE_VMULLBs32:
  7339. case ARM::MVE_VMULLTs32:
  7340. case ARM::MVE_VMULLBu32:
  7341. case ARM::MVE_VMULLTu32: {
  7342. if (Operands[3]->getReg() == Operands[4]->getReg()) {
  7343. return Error (Operands[3]->getStartLoc(),
  7344. "Qd register and Qn register can't be identical");
  7345. }
  7346. if (Operands[3]->getReg() == Operands[5]->getReg()) {
  7347. return Error (Operands[3]->getStartLoc(),
  7348. "Qd register and Qm register can't be identical");
  7349. }
  7350. break;
  7351. }
  7352. case ARM::MVE_VMOV_rr_q: {
  7353. if (Operands[4]->getReg() != Operands[6]->getReg())
  7354. return Error (Operands[4]->getStartLoc(), "Q-registers must be the same");
  7355. if (static_cast<ARMOperand &>(*Operands[5]).getVectorIndex() !=
  7356. static_cast<ARMOperand &>(*Operands[7]).getVectorIndex() + 2)
  7357. return Error (Operands[5]->getStartLoc(), "Q-register indexes must be 2 and 0 or 3 and 1");
  7358. break;
  7359. }
  7360. case ARM::MVE_VMOV_q_rr: {
  7361. if (Operands[2]->getReg() != Operands[4]->getReg())
  7362. return Error (Operands[2]->getStartLoc(), "Q-registers must be the same");
  7363. if (static_cast<ARMOperand &>(*Operands[3]).getVectorIndex() !=
  7364. static_cast<ARMOperand &>(*Operands[5]).getVectorIndex() + 2)
  7365. return Error (Operands[3]->getStartLoc(), "Q-register indexes must be 2 and 0 or 3 and 1");
  7366. break;
  7367. }
  7368. case ARM::UMAAL:
  7369. case ARM::UMLAL:
  7370. case ARM::UMULL:
  7371. case ARM::t2UMAAL:
  7372. case ARM::t2UMLAL:
  7373. case ARM::t2UMULL:
  7374. case ARM::SMLAL:
  7375. case ARM::SMLALBB:
  7376. case ARM::SMLALBT:
  7377. case ARM::SMLALD:
  7378. case ARM::SMLALDX:
  7379. case ARM::SMLALTB:
  7380. case ARM::SMLALTT:
  7381. case ARM::SMLSLD:
  7382. case ARM::SMLSLDX:
  7383. case ARM::SMULL:
  7384. case ARM::t2SMLAL:
  7385. case ARM::t2SMLALBB:
  7386. case ARM::t2SMLALBT:
  7387. case ARM::t2SMLALD:
  7388. case ARM::t2SMLALDX:
  7389. case ARM::t2SMLALTB:
  7390. case ARM::t2SMLALTT:
  7391. case ARM::t2SMLSLD:
  7392. case ARM::t2SMLSLDX:
  7393. case ARM::t2SMULL: {
  7394. unsigned RdHi = Inst.getOperand(0).getReg();
  7395. unsigned RdLo = Inst.getOperand(1).getReg();
  7396. if(RdHi == RdLo) {
  7397. return Error(Loc,
  7398. "unpredictable instruction, RdHi and RdLo must be different");
  7399. }
  7400. break;
  7401. }
  7402. case ARM::CDE_CX1:
  7403. case ARM::CDE_CX1A:
  7404. case ARM::CDE_CX1D:
  7405. case ARM::CDE_CX1DA:
  7406. case ARM::CDE_CX2:
  7407. case ARM::CDE_CX2A:
  7408. case ARM::CDE_CX2D:
  7409. case ARM::CDE_CX2DA:
  7410. case ARM::CDE_CX3:
  7411. case ARM::CDE_CX3A:
  7412. case ARM::CDE_CX3D:
  7413. case ARM::CDE_CX3DA:
  7414. case ARM::CDE_VCX1_vec:
  7415. case ARM::CDE_VCX1_fpsp:
  7416. case ARM::CDE_VCX1_fpdp:
  7417. case ARM::CDE_VCX1A_vec:
  7418. case ARM::CDE_VCX1A_fpsp:
  7419. case ARM::CDE_VCX1A_fpdp:
  7420. case ARM::CDE_VCX2_vec:
  7421. case ARM::CDE_VCX2_fpsp:
  7422. case ARM::CDE_VCX2_fpdp:
  7423. case ARM::CDE_VCX2A_vec:
  7424. case ARM::CDE_VCX2A_fpsp:
  7425. case ARM::CDE_VCX2A_fpdp:
  7426. case ARM::CDE_VCX3_vec:
  7427. case ARM::CDE_VCX3_fpsp:
  7428. case ARM::CDE_VCX3_fpdp:
  7429. case ARM::CDE_VCX3A_vec:
  7430. case ARM::CDE_VCX3A_fpsp:
  7431. case ARM::CDE_VCX3A_fpdp: {
  7432. assert(Inst.getOperand(1).isImm() &&
  7433. "CDE operand 1 must be a coprocessor ID");
  7434. int64_t Coproc = Inst.getOperand(1).getImm();
  7435. if (Coproc < 8 && !ARM::isCDECoproc(Coproc, *STI))
  7436. return Error(Operands[1]->getStartLoc(),
  7437. "coprocessor must be configured as CDE");
  7438. else if (Coproc >= 8)
  7439. return Error(Operands[1]->getStartLoc(),
  7440. "coprocessor must be in the range [p0, p7]");
  7441. break;
  7442. }
  7443. case ARM::t2CDP:
  7444. case ARM::t2CDP2:
  7445. case ARM::t2LDC2L_OFFSET:
  7446. case ARM::t2LDC2L_OPTION:
  7447. case ARM::t2LDC2L_POST:
  7448. case ARM::t2LDC2L_PRE:
  7449. case ARM::t2LDC2_OFFSET:
  7450. case ARM::t2LDC2_OPTION:
  7451. case ARM::t2LDC2_POST:
  7452. case ARM::t2LDC2_PRE:
  7453. case ARM::t2LDCL_OFFSET:
  7454. case ARM::t2LDCL_OPTION:
  7455. case ARM::t2LDCL_POST:
  7456. case ARM::t2LDCL_PRE:
  7457. case ARM::t2LDC_OFFSET:
  7458. case ARM::t2LDC_OPTION:
  7459. case ARM::t2LDC_POST:
  7460. case ARM::t2LDC_PRE:
  7461. case ARM::t2MCR:
  7462. case ARM::t2MCR2:
  7463. case ARM::t2MCRR:
  7464. case ARM::t2MCRR2:
  7465. case ARM::t2MRC:
  7466. case ARM::t2MRC2:
  7467. case ARM::t2MRRC:
  7468. case ARM::t2MRRC2:
  7469. case ARM::t2STC2L_OFFSET:
  7470. case ARM::t2STC2L_OPTION:
  7471. case ARM::t2STC2L_POST:
  7472. case ARM::t2STC2L_PRE:
  7473. case ARM::t2STC2_OFFSET:
  7474. case ARM::t2STC2_OPTION:
  7475. case ARM::t2STC2_POST:
  7476. case ARM::t2STC2_PRE:
  7477. case ARM::t2STCL_OFFSET:
  7478. case ARM::t2STCL_OPTION:
  7479. case ARM::t2STCL_POST:
  7480. case ARM::t2STCL_PRE:
  7481. case ARM::t2STC_OFFSET:
  7482. case ARM::t2STC_OPTION:
  7483. case ARM::t2STC_POST:
  7484. case ARM::t2STC_PRE: {
  7485. unsigned Opcode = Inst.getOpcode();
  7486. // Inst.getOperand indexes operands in the (oops ...) and (iops ...) dags,
  7487. // CopInd is the index of the coprocessor operand.
  7488. size_t CopInd = 0;
  7489. if (Opcode == ARM::t2MRRC || Opcode == ARM::t2MRRC2)
  7490. CopInd = 2;
  7491. else if (Opcode == ARM::t2MRC || Opcode == ARM::t2MRC2)
  7492. CopInd = 1;
  7493. assert(Inst.getOperand(CopInd).isImm() &&
  7494. "Operand must be a coprocessor ID");
  7495. int64_t Coproc = Inst.getOperand(CopInd).getImm();
  7496. // Operands[2] is the coprocessor operand at syntactic level
  7497. if (ARM::isCDECoproc(Coproc, *STI))
  7498. return Error(Operands[2]->getStartLoc(),
  7499. "coprocessor must be configured as GCP");
  7500. break;
  7501. }
  7502. }
  7503. return false;
  7504. }
  7505. static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
  7506. switch(Opc) {
  7507. default: llvm_unreachable("unexpected opcode!");
  7508. // VST1LN
  7509. case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
  7510. case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
  7511. case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
  7512. case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
  7513. case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
  7514. case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
  7515. case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
  7516. case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
  7517. case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
  7518. // VST2LN
  7519. case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
  7520. case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
  7521. case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
  7522. case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
  7523. case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
  7524. case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
  7525. case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
  7526. case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
  7527. case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
  7528. case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
  7529. case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
  7530. case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
  7531. case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
  7532. case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
  7533. case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
  7534. // VST3LN
  7535. case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
  7536. case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
  7537. case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
  7538. case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
  7539. case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
  7540. case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
  7541. case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
  7542. case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
  7543. case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
  7544. case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
  7545. case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
  7546. case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
  7547. case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
  7548. case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
  7549. case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
  7550. // VST3
  7551. case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
  7552. case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
  7553. case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
  7554. case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
  7555. case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
  7556. case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
  7557. case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
  7558. case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
  7559. case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
  7560. case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
  7561. case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
  7562. case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
  7563. case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
  7564. case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
  7565. case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
  7566. case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
  7567. case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
  7568. case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
  7569. // VST4LN
  7570. case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
  7571. case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
  7572. case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
  7573. case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
  7574. case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
  7575. case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
  7576. case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
  7577. case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
  7578. case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
  7579. case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
  7580. case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
  7581. case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
  7582. case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
  7583. case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
  7584. case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
  7585. // VST4
  7586. case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
  7587. case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
  7588. case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
  7589. case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
  7590. case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
  7591. case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
  7592. case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
  7593. case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
  7594. case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
  7595. case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
  7596. case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
  7597. case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
  7598. case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
  7599. case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
  7600. case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
  7601. case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
  7602. case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
  7603. case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
  7604. }
  7605. }
  7606. static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
  7607. switch(Opc) {
  7608. default: llvm_unreachable("unexpected opcode!");
  7609. // VLD1LN
  7610. case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
  7611. case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
  7612. case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
  7613. case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
  7614. case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
  7615. case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
  7616. case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
  7617. case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
  7618. case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
  7619. // VLD2LN
  7620. case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
  7621. case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
  7622. case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
  7623. case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
  7624. case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
  7625. case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
  7626. case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
  7627. case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
  7628. case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
  7629. case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
  7630. case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
  7631. case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
  7632. case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
  7633. case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
  7634. case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
  7635. // VLD3DUP
  7636. case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
  7637. case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
  7638. case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
  7639. case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
  7640. case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
  7641. case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
  7642. case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
  7643. case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
  7644. case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
  7645. case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
  7646. case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
  7647. case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
  7648. case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
  7649. case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
  7650. case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
  7651. case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
  7652. case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
  7653. case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
  7654. // VLD3LN
  7655. case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
  7656. case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
  7657. case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
  7658. case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
  7659. case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
  7660. case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
  7661. case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
  7662. case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
  7663. case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
  7664. case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
  7665. case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
  7666. case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
  7667. case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
  7668. case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
  7669. case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
  7670. // VLD3
  7671. case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
  7672. case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
  7673. case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
  7674. case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
  7675. case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
  7676. case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
  7677. case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
  7678. case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
  7679. case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
  7680. case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
  7681. case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
  7682. case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
  7683. case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
  7684. case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
  7685. case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
  7686. case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
  7687. case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
  7688. case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
  7689. // VLD4LN
  7690. case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
  7691. case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
  7692. case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
  7693. case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
  7694. case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
  7695. case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
  7696. case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
  7697. case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
  7698. case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
  7699. case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
  7700. case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
  7701. case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
  7702. case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
  7703. case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
  7704. case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
  7705. // VLD4DUP
  7706. case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
  7707. case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
  7708. case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
  7709. case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
  7710. case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
  7711. case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
  7712. case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
  7713. case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
  7714. case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
  7715. case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
  7716. case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
  7717. case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
  7718. case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
  7719. case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
  7720. case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
  7721. case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
  7722. case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
  7723. case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
  7724. // VLD4
  7725. case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
  7726. case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
  7727. case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
  7728. case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
  7729. case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
  7730. case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
  7731. case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
  7732. case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
  7733. case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
  7734. case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
  7735. case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
  7736. case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
  7737. case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
  7738. case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
  7739. case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
  7740. case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
  7741. case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
  7742. case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
  7743. }
  7744. }
  7745. bool ARMAsmParser::processInstruction(MCInst &Inst,
  7746. const OperandVector &Operands,
  7747. MCStreamer &Out) {
  7748. // Check if we have the wide qualifier, because if it's present we
  7749. // must avoid selecting a 16-bit thumb instruction.
  7750. bool HasWideQualifier = false;
  7751. for (auto &Op : Operands) {
  7752. ARMOperand &ARMOp = static_cast<ARMOperand&>(*Op);
  7753. if (ARMOp.isToken() && ARMOp.getToken() == ".w") {
  7754. HasWideQualifier = true;
  7755. break;
  7756. }
  7757. }
  7758. switch (Inst.getOpcode()) {
  7759. // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
  7760. case ARM::LDRT_POST:
  7761. case ARM::LDRBT_POST: {
  7762. const unsigned Opcode =
  7763. (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
  7764. : ARM::LDRBT_POST_IMM;
  7765. MCInst TmpInst;
  7766. TmpInst.setOpcode(Opcode);
  7767. TmpInst.addOperand(Inst.getOperand(0));
  7768. TmpInst.addOperand(Inst.getOperand(1));
  7769. TmpInst.addOperand(Inst.getOperand(1));
  7770. TmpInst.addOperand(MCOperand::createReg(0));
  7771. TmpInst.addOperand(MCOperand::createImm(0));
  7772. TmpInst.addOperand(Inst.getOperand(2));
  7773. TmpInst.addOperand(Inst.getOperand(3));
  7774. Inst = TmpInst;
  7775. return true;
  7776. }
  7777. // Alias for 'ldr{sb,h,sh}t Rt, [Rn] {, #imm}' for ommitted immediate.
  7778. case ARM::LDRSBTii:
  7779. case ARM::LDRHTii:
  7780. case ARM::LDRSHTii: {
  7781. MCInst TmpInst;
  7782. if (Inst.getOpcode() == ARM::LDRSBTii)
  7783. TmpInst.setOpcode(ARM::LDRSBTi);
  7784. else if (Inst.getOpcode() == ARM::LDRHTii)
  7785. TmpInst.setOpcode(ARM::LDRHTi);
  7786. else if (Inst.getOpcode() == ARM::LDRSHTii)
  7787. TmpInst.setOpcode(ARM::LDRSHTi);
  7788. TmpInst.addOperand(Inst.getOperand(0));
  7789. TmpInst.addOperand(Inst.getOperand(1));
  7790. TmpInst.addOperand(Inst.getOperand(1));
  7791. TmpInst.addOperand(MCOperand::createImm(256));
  7792. TmpInst.addOperand(Inst.getOperand(2));
  7793. Inst = TmpInst;
  7794. return true;
  7795. }
  7796. // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
  7797. case ARM::STRT_POST:
  7798. case ARM::STRBT_POST: {
  7799. const unsigned Opcode =
  7800. (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
  7801. : ARM::STRBT_POST_IMM;
  7802. MCInst TmpInst;
  7803. TmpInst.setOpcode(Opcode);
  7804. TmpInst.addOperand(Inst.getOperand(1));
  7805. TmpInst.addOperand(Inst.getOperand(0));
  7806. TmpInst.addOperand(Inst.getOperand(1));
  7807. TmpInst.addOperand(MCOperand::createReg(0));
  7808. TmpInst.addOperand(MCOperand::createImm(0));
  7809. TmpInst.addOperand(Inst.getOperand(2));
  7810. TmpInst.addOperand(Inst.getOperand(3));
  7811. Inst = TmpInst;
  7812. return true;
  7813. }
  7814. // Alias for alternate form of 'ADR Rd, #imm' instruction.
  7815. case ARM::ADDri: {
  7816. if (Inst.getOperand(1).getReg() != ARM::PC ||
  7817. Inst.getOperand(5).getReg() != 0 ||
  7818. !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
  7819. return false;
  7820. MCInst TmpInst;
  7821. TmpInst.setOpcode(ARM::ADR);
  7822. TmpInst.addOperand(Inst.getOperand(0));
  7823. if (Inst.getOperand(2).isImm()) {
  7824. // Immediate (mod_imm) will be in its encoded form, we must unencode it
  7825. // before passing it to the ADR instruction.
  7826. unsigned Enc = Inst.getOperand(2).getImm();
  7827. TmpInst.addOperand(MCOperand::createImm(
  7828. ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7)));
  7829. } else {
  7830. // Turn PC-relative expression into absolute expression.
  7831. // Reading PC provides the start of the current instruction + 8 and
  7832. // the transform to adr is biased by that.
  7833. MCSymbol *Dot = getContext().createTempSymbol();
  7834. Out.emitLabel(Dot);
  7835. const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
  7836. const MCExpr *InstPC = MCSymbolRefExpr::create(Dot,
  7837. MCSymbolRefExpr::VK_None,
  7838. getContext());
  7839. const MCExpr *Const8 = MCConstantExpr::create(8, getContext());
  7840. const MCExpr *ReadPC = MCBinaryExpr::createAdd(InstPC, Const8,
  7841. getContext());
  7842. const MCExpr *FixupAddr = MCBinaryExpr::createAdd(ReadPC, OpExpr,
  7843. getContext());
  7844. TmpInst.addOperand(MCOperand::createExpr(FixupAddr));
  7845. }
  7846. TmpInst.addOperand(Inst.getOperand(3));
  7847. TmpInst.addOperand(Inst.getOperand(4));
  7848. Inst = TmpInst;
  7849. return true;
  7850. }
  7851. // Aliases for imm syntax of LDR instructions.
  7852. case ARM::t2LDR_PRE_imm:
  7853. case ARM::t2LDR_POST_imm: {
  7854. MCInst TmpInst;
  7855. TmpInst.setOpcode(Inst.getOpcode() == ARM::t2LDR_PRE_imm ? ARM::t2LDR_PRE
  7856. : ARM::t2LDR_POST);
  7857. TmpInst.addOperand(Inst.getOperand(0)); // Rt
  7858. TmpInst.addOperand(Inst.getOperand(4)); // Rt_wb
  7859. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  7860. TmpInst.addOperand(Inst.getOperand(2)); // imm
  7861. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  7862. Inst = TmpInst;
  7863. return true;
  7864. }
  7865. // Aliases for imm syntax of STR instructions.
  7866. case ARM::t2STR_PRE_imm:
  7867. case ARM::t2STR_POST_imm: {
  7868. MCInst TmpInst;
  7869. TmpInst.setOpcode(Inst.getOpcode() == ARM::t2STR_PRE_imm ? ARM::t2STR_PRE
  7870. : ARM::t2STR_POST);
  7871. TmpInst.addOperand(Inst.getOperand(4)); // Rt_wb
  7872. TmpInst.addOperand(Inst.getOperand(0)); // Rt
  7873. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  7874. TmpInst.addOperand(Inst.getOperand(2)); // imm
  7875. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  7876. Inst = TmpInst;
  7877. return true;
  7878. }
  7879. // Aliases for alternate PC+imm syntax of LDR instructions.
  7880. case ARM::t2LDRpcrel:
  7881. // Select the narrow version if the immediate will fit.
  7882. if (Inst.getOperand(1).getImm() > 0 &&
  7883. Inst.getOperand(1).getImm() <= 0xff &&
  7884. !HasWideQualifier)
  7885. Inst.setOpcode(ARM::tLDRpci);
  7886. else
  7887. Inst.setOpcode(ARM::t2LDRpci);
  7888. return true;
  7889. case ARM::t2LDRBpcrel:
  7890. Inst.setOpcode(ARM::t2LDRBpci);
  7891. return true;
  7892. case ARM::t2LDRHpcrel:
  7893. Inst.setOpcode(ARM::t2LDRHpci);
  7894. return true;
  7895. case ARM::t2LDRSBpcrel:
  7896. Inst.setOpcode(ARM::t2LDRSBpci);
  7897. return true;
  7898. case ARM::t2LDRSHpcrel:
  7899. Inst.setOpcode(ARM::t2LDRSHpci);
  7900. return true;
  7901. case ARM::LDRConstPool:
  7902. case ARM::tLDRConstPool:
  7903. case ARM::t2LDRConstPool: {
  7904. // Pseudo instruction ldr rt, =immediate is converted to a
  7905. // MOV rt, immediate if immediate is known and representable
  7906. // otherwise we create a constant pool entry that we load from.
  7907. MCInst TmpInst;
  7908. if (Inst.getOpcode() == ARM::LDRConstPool)
  7909. TmpInst.setOpcode(ARM::LDRi12);
  7910. else if (Inst.getOpcode() == ARM::tLDRConstPool)
  7911. TmpInst.setOpcode(ARM::tLDRpci);
  7912. else if (Inst.getOpcode() == ARM::t2LDRConstPool)
  7913. TmpInst.setOpcode(ARM::t2LDRpci);
  7914. const ARMOperand &PoolOperand =
  7915. (HasWideQualifier ?
  7916. static_cast<ARMOperand &>(*Operands[4]) :
  7917. static_cast<ARMOperand &>(*Operands[3]));
  7918. const MCExpr *SubExprVal = PoolOperand.getConstantPoolImm();
  7919. // If SubExprVal is a constant we may be able to use a MOV
  7920. if (isa<MCConstantExpr>(SubExprVal) &&
  7921. Inst.getOperand(0).getReg() != ARM::PC &&
  7922. Inst.getOperand(0).getReg() != ARM::SP) {
  7923. int64_t Value =
  7924. (int64_t) (cast<MCConstantExpr>(SubExprVal))->getValue();
  7925. bool UseMov = true;
  7926. bool MovHasS = true;
  7927. if (Inst.getOpcode() == ARM::LDRConstPool) {
  7928. // ARM Constant
  7929. if (ARM_AM::getSOImmVal(Value) != -1) {
  7930. Value = ARM_AM::getSOImmVal(Value);
  7931. TmpInst.setOpcode(ARM::MOVi);
  7932. }
  7933. else if (ARM_AM::getSOImmVal(~Value) != -1) {
  7934. Value = ARM_AM::getSOImmVal(~Value);
  7935. TmpInst.setOpcode(ARM::MVNi);
  7936. }
  7937. else if (hasV6T2Ops() &&
  7938. Value >=0 && Value < 65536) {
  7939. TmpInst.setOpcode(ARM::MOVi16);
  7940. MovHasS = false;
  7941. }
  7942. else
  7943. UseMov = false;
  7944. }
  7945. else {
  7946. // Thumb/Thumb2 Constant
  7947. if (hasThumb2() &&
  7948. ARM_AM::getT2SOImmVal(Value) != -1)
  7949. TmpInst.setOpcode(ARM::t2MOVi);
  7950. else if (hasThumb2() &&
  7951. ARM_AM::getT2SOImmVal(~Value) != -1) {
  7952. TmpInst.setOpcode(ARM::t2MVNi);
  7953. Value = ~Value;
  7954. }
  7955. else if (hasV8MBaseline() &&
  7956. Value >=0 && Value < 65536) {
  7957. TmpInst.setOpcode(ARM::t2MOVi16);
  7958. MovHasS = false;
  7959. }
  7960. else
  7961. UseMov = false;
  7962. }
  7963. if (UseMov) {
  7964. TmpInst.addOperand(Inst.getOperand(0)); // Rt
  7965. TmpInst.addOperand(MCOperand::createImm(Value)); // Immediate
  7966. TmpInst.addOperand(Inst.getOperand(2)); // CondCode
  7967. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  7968. if (MovHasS)
  7969. TmpInst.addOperand(MCOperand::createReg(0)); // S
  7970. Inst = TmpInst;
  7971. return true;
  7972. }
  7973. }
  7974. // No opportunity to use MOV/MVN create constant pool
  7975. const MCExpr *CPLoc =
  7976. getTargetStreamer().addConstantPoolEntry(SubExprVal,
  7977. PoolOperand.getStartLoc());
  7978. TmpInst.addOperand(Inst.getOperand(0)); // Rt
  7979. TmpInst.addOperand(MCOperand::createExpr(CPLoc)); // offset to constpool
  7980. if (TmpInst.getOpcode() == ARM::LDRi12)
  7981. TmpInst.addOperand(MCOperand::createImm(0)); // unused offset
  7982. TmpInst.addOperand(Inst.getOperand(2)); // CondCode
  7983. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  7984. Inst = TmpInst;
  7985. return true;
  7986. }
  7987. // Handle NEON VST complex aliases.
  7988. case ARM::VST1LNdWB_register_Asm_8:
  7989. case ARM::VST1LNdWB_register_Asm_16:
  7990. case ARM::VST1LNdWB_register_Asm_32: {
  7991. MCInst TmpInst;
  7992. // Shuffle the operands around so the lane index operand is in the
  7993. // right place.
  7994. unsigned Spacing;
  7995. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  7996. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  7997. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  7998. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  7999. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8000. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8001. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8002. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8003. TmpInst.addOperand(Inst.getOperand(6));
  8004. Inst = TmpInst;
  8005. return true;
  8006. }
  8007. case ARM::VST2LNdWB_register_Asm_8:
  8008. case ARM::VST2LNdWB_register_Asm_16:
  8009. case ARM::VST2LNdWB_register_Asm_32:
  8010. case ARM::VST2LNqWB_register_Asm_16:
  8011. case ARM::VST2LNqWB_register_Asm_32: {
  8012. MCInst TmpInst;
  8013. // Shuffle the operands around so the lane index operand is in the
  8014. // right place.
  8015. unsigned Spacing;
  8016. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8017. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8018. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8019. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8020. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8021. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8022. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8023. Spacing));
  8024. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8025. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8026. TmpInst.addOperand(Inst.getOperand(6));
  8027. Inst = TmpInst;
  8028. return true;
  8029. }
  8030. case ARM::VST3LNdWB_register_Asm_8:
  8031. case ARM::VST3LNdWB_register_Asm_16:
  8032. case ARM::VST3LNdWB_register_Asm_32:
  8033. case ARM::VST3LNqWB_register_Asm_16:
  8034. case ARM::VST3LNqWB_register_Asm_32: {
  8035. MCInst TmpInst;
  8036. // Shuffle the operands around so the lane index operand is in the
  8037. // right place.
  8038. unsigned Spacing;
  8039. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8040. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8041. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8042. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8043. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8044. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8045. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8046. Spacing));
  8047. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8048. Spacing * 2));
  8049. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8050. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8051. TmpInst.addOperand(Inst.getOperand(6));
  8052. Inst = TmpInst;
  8053. return true;
  8054. }
  8055. case ARM::VST4LNdWB_register_Asm_8:
  8056. case ARM::VST4LNdWB_register_Asm_16:
  8057. case ARM::VST4LNdWB_register_Asm_32:
  8058. case ARM::VST4LNqWB_register_Asm_16:
  8059. case ARM::VST4LNqWB_register_Asm_32: {
  8060. MCInst TmpInst;
  8061. // Shuffle the operands around so the lane index operand is in the
  8062. // right place.
  8063. unsigned Spacing;
  8064. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8065. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8066. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8067. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8068. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8069. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8070. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8071. Spacing));
  8072. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8073. Spacing * 2));
  8074. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8075. Spacing * 3));
  8076. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8077. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8078. TmpInst.addOperand(Inst.getOperand(6));
  8079. Inst = TmpInst;
  8080. return true;
  8081. }
  8082. case ARM::VST1LNdWB_fixed_Asm_8:
  8083. case ARM::VST1LNdWB_fixed_Asm_16:
  8084. case ARM::VST1LNdWB_fixed_Asm_32: {
  8085. MCInst TmpInst;
  8086. // Shuffle the operands around so the lane index operand is in the
  8087. // right place.
  8088. unsigned Spacing;
  8089. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8090. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8091. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8092. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8093. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8094. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8095. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8096. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8097. TmpInst.addOperand(Inst.getOperand(5));
  8098. Inst = TmpInst;
  8099. return true;
  8100. }
  8101. case ARM::VST2LNdWB_fixed_Asm_8:
  8102. case ARM::VST2LNdWB_fixed_Asm_16:
  8103. case ARM::VST2LNdWB_fixed_Asm_32:
  8104. case ARM::VST2LNqWB_fixed_Asm_16:
  8105. case ARM::VST2LNqWB_fixed_Asm_32: {
  8106. MCInst TmpInst;
  8107. // Shuffle the operands around so the lane index operand is in the
  8108. // right place.
  8109. unsigned Spacing;
  8110. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8111. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8112. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8113. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8114. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8115. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8116. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8117. Spacing));
  8118. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8119. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8120. TmpInst.addOperand(Inst.getOperand(5));
  8121. Inst = TmpInst;
  8122. return true;
  8123. }
  8124. case ARM::VST3LNdWB_fixed_Asm_8:
  8125. case ARM::VST3LNdWB_fixed_Asm_16:
  8126. case ARM::VST3LNdWB_fixed_Asm_32:
  8127. case ARM::VST3LNqWB_fixed_Asm_16:
  8128. case ARM::VST3LNqWB_fixed_Asm_32: {
  8129. MCInst TmpInst;
  8130. // Shuffle the operands around so the lane index operand is in the
  8131. // right place.
  8132. unsigned Spacing;
  8133. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8134. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8135. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8136. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8137. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8138. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8139. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8140. Spacing));
  8141. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8142. Spacing * 2));
  8143. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8144. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8145. TmpInst.addOperand(Inst.getOperand(5));
  8146. Inst = TmpInst;
  8147. return true;
  8148. }
  8149. case ARM::VST4LNdWB_fixed_Asm_8:
  8150. case ARM::VST4LNdWB_fixed_Asm_16:
  8151. case ARM::VST4LNdWB_fixed_Asm_32:
  8152. case ARM::VST4LNqWB_fixed_Asm_16:
  8153. case ARM::VST4LNqWB_fixed_Asm_32: {
  8154. MCInst TmpInst;
  8155. // Shuffle the operands around so the lane index operand is in the
  8156. // right place.
  8157. unsigned Spacing;
  8158. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8159. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8160. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8161. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8162. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8163. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8164. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8165. Spacing));
  8166. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8167. Spacing * 2));
  8168. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8169. Spacing * 3));
  8170. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8171. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8172. TmpInst.addOperand(Inst.getOperand(5));
  8173. Inst = TmpInst;
  8174. return true;
  8175. }
  8176. case ARM::VST1LNdAsm_8:
  8177. case ARM::VST1LNdAsm_16:
  8178. case ARM::VST1LNdAsm_32: {
  8179. MCInst TmpInst;
  8180. // Shuffle the operands around so the lane index operand is in the
  8181. // right place.
  8182. unsigned Spacing;
  8183. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8184. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8185. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8186. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8187. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8188. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8189. TmpInst.addOperand(Inst.getOperand(5));
  8190. Inst = TmpInst;
  8191. return true;
  8192. }
  8193. case ARM::VST2LNdAsm_8:
  8194. case ARM::VST2LNdAsm_16:
  8195. case ARM::VST2LNdAsm_32:
  8196. case ARM::VST2LNqAsm_16:
  8197. case ARM::VST2LNqAsm_32: {
  8198. MCInst TmpInst;
  8199. // Shuffle the operands around so the lane index operand is in the
  8200. // right place.
  8201. unsigned Spacing;
  8202. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8203. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8204. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8205. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8206. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8207. Spacing));
  8208. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8209. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8210. TmpInst.addOperand(Inst.getOperand(5));
  8211. Inst = TmpInst;
  8212. return true;
  8213. }
  8214. case ARM::VST3LNdAsm_8:
  8215. case ARM::VST3LNdAsm_16:
  8216. case ARM::VST3LNdAsm_32:
  8217. case ARM::VST3LNqAsm_16:
  8218. case ARM::VST3LNqAsm_32: {
  8219. MCInst TmpInst;
  8220. // Shuffle the operands around so the lane index operand is in the
  8221. // right place.
  8222. unsigned Spacing;
  8223. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8224. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8225. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8226. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8227. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8228. Spacing));
  8229. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8230. Spacing * 2));
  8231. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8232. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8233. TmpInst.addOperand(Inst.getOperand(5));
  8234. Inst = TmpInst;
  8235. return true;
  8236. }
  8237. case ARM::VST4LNdAsm_8:
  8238. case ARM::VST4LNdAsm_16:
  8239. case ARM::VST4LNdAsm_32:
  8240. case ARM::VST4LNqAsm_16:
  8241. case ARM::VST4LNqAsm_32: {
  8242. MCInst TmpInst;
  8243. // Shuffle the operands around so the lane index operand is in the
  8244. // right place.
  8245. unsigned Spacing;
  8246. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8247. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8248. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8249. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8250. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8251. Spacing));
  8252. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8253. Spacing * 2));
  8254. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8255. Spacing * 3));
  8256. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8257. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8258. TmpInst.addOperand(Inst.getOperand(5));
  8259. Inst = TmpInst;
  8260. return true;
  8261. }
  8262. // Handle NEON VLD complex aliases.
  8263. case ARM::VLD1LNdWB_register_Asm_8:
  8264. case ARM::VLD1LNdWB_register_Asm_16:
  8265. case ARM::VLD1LNdWB_register_Asm_32: {
  8266. MCInst TmpInst;
  8267. // Shuffle the operands around so the lane index operand is in the
  8268. // right place.
  8269. unsigned Spacing;
  8270. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8271. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8272. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8273. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8274. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8275. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8276. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8277. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8278. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8279. TmpInst.addOperand(Inst.getOperand(6));
  8280. Inst = TmpInst;
  8281. return true;
  8282. }
  8283. case ARM::VLD2LNdWB_register_Asm_8:
  8284. case ARM::VLD2LNdWB_register_Asm_16:
  8285. case ARM::VLD2LNdWB_register_Asm_32:
  8286. case ARM::VLD2LNqWB_register_Asm_16:
  8287. case ARM::VLD2LNqWB_register_Asm_32: {
  8288. MCInst TmpInst;
  8289. // Shuffle the operands around so the lane index operand is in the
  8290. // right place.
  8291. unsigned Spacing;
  8292. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8293. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8294. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8295. Spacing));
  8296. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8297. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8298. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8299. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8300. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8301. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8302. Spacing));
  8303. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8304. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8305. TmpInst.addOperand(Inst.getOperand(6));
  8306. Inst = TmpInst;
  8307. return true;
  8308. }
  8309. case ARM::VLD3LNdWB_register_Asm_8:
  8310. case ARM::VLD3LNdWB_register_Asm_16:
  8311. case ARM::VLD3LNdWB_register_Asm_32:
  8312. case ARM::VLD3LNqWB_register_Asm_16:
  8313. case ARM::VLD3LNqWB_register_Asm_32: {
  8314. MCInst TmpInst;
  8315. // Shuffle the operands around so the lane index operand is in the
  8316. // right place.
  8317. unsigned Spacing;
  8318. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8319. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8320. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8321. Spacing));
  8322. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8323. Spacing * 2));
  8324. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8325. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8326. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8327. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8328. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8329. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8330. Spacing));
  8331. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8332. Spacing * 2));
  8333. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8334. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8335. TmpInst.addOperand(Inst.getOperand(6));
  8336. Inst = TmpInst;
  8337. return true;
  8338. }
  8339. case ARM::VLD4LNdWB_register_Asm_8:
  8340. case ARM::VLD4LNdWB_register_Asm_16:
  8341. case ARM::VLD4LNdWB_register_Asm_32:
  8342. case ARM::VLD4LNqWB_register_Asm_16:
  8343. case ARM::VLD4LNqWB_register_Asm_32: {
  8344. MCInst TmpInst;
  8345. // Shuffle the operands around so the lane index operand is in the
  8346. // right place.
  8347. unsigned Spacing;
  8348. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8349. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8350. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8351. Spacing));
  8352. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8353. Spacing * 2));
  8354. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8355. Spacing * 3));
  8356. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8357. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8358. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8359. TmpInst.addOperand(Inst.getOperand(4)); // Rm
  8360. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8361. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8362. Spacing));
  8363. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8364. Spacing * 2));
  8365. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8366. Spacing * 3));
  8367. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8368. TmpInst.addOperand(Inst.getOperand(5)); // CondCode
  8369. TmpInst.addOperand(Inst.getOperand(6));
  8370. Inst = TmpInst;
  8371. return true;
  8372. }
  8373. case ARM::VLD1LNdWB_fixed_Asm_8:
  8374. case ARM::VLD1LNdWB_fixed_Asm_16:
  8375. case ARM::VLD1LNdWB_fixed_Asm_32: {
  8376. MCInst TmpInst;
  8377. // Shuffle the operands around so the lane index operand is in the
  8378. // right place.
  8379. unsigned Spacing;
  8380. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8381. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8382. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8383. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8384. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8385. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8386. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8387. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8388. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8389. TmpInst.addOperand(Inst.getOperand(5));
  8390. Inst = TmpInst;
  8391. return true;
  8392. }
  8393. case ARM::VLD2LNdWB_fixed_Asm_8:
  8394. case ARM::VLD2LNdWB_fixed_Asm_16:
  8395. case ARM::VLD2LNdWB_fixed_Asm_32:
  8396. case ARM::VLD2LNqWB_fixed_Asm_16:
  8397. case ARM::VLD2LNqWB_fixed_Asm_32: {
  8398. MCInst TmpInst;
  8399. // Shuffle the operands around so the lane index operand is in the
  8400. // right place.
  8401. unsigned Spacing;
  8402. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8403. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8404. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8405. Spacing));
  8406. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8407. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8408. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8409. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8410. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8411. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8412. Spacing));
  8413. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8414. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8415. TmpInst.addOperand(Inst.getOperand(5));
  8416. Inst = TmpInst;
  8417. return true;
  8418. }
  8419. case ARM::VLD3LNdWB_fixed_Asm_8:
  8420. case ARM::VLD3LNdWB_fixed_Asm_16:
  8421. case ARM::VLD3LNdWB_fixed_Asm_32:
  8422. case ARM::VLD3LNqWB_fixed_Asm_16:
  8423. case ARM::VLD3LNqWB_fixed_Asm_32: {
  8424. MCInst TmpInst;
  8425. // Shuffle the operands around so the lane index operand is in the
  8426. // right place.
  8427. unsigned Spacing;
  8428. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8429. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8430. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8431. Spacing));
  8432. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8433. Spacing * 2));
  8434. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8435. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8436. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8437. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8438. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8439. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8440. Spacing));
  8441. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8442. Spacing * 2));
  8443. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8444. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8445. TmpInst.addOperand(Inst.getOperand(5));
  8446. Inst = TmpInst;
  8447. return true;
  8448. }
  8449. case ARM::VLD4LNdWB_fixed_Asm_8:
  8450. case ARM::VLD4LNdWB_fixed_Asm_16:
  8451. case ARM::VLD4LNdWB_fixed_Asm_32:
  8452. case ARM::VLD4LNqWB_fixed_Asm_16:
  8453. case ARM::VLD4LNqWB_fixed_Asm_32: {
  8454. MCInst TmpInst;
  8455. // Shuffle the operands around so the lane index operand is in the
  8456. // right place.
  8457. unsigned Spacing;
  8458. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8459. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8460. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8461. Spacing));
  8462. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8463. Spacing * 2));
  8464. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8465. Spacing * 3));
  8466. TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
  8467. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8468. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8469. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8470. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8471. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8472. Spacing));
  8473. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8474. Spacing * 2));
  8475. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8476. Spacing * 3));
  8477. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8478. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8479. TmpInst.addOperand(Inst.getOperand(5));
  8480. Inst = TmpInst;
  8481. return true;
  8482. }
  8483. case ARM::VLD1LNdAsm_8:
  8484. case ARM::VLD1LNdAsm_16:
  8485. case ARM::VLD1LNdAsm_32: {
  8486. MCInst TmpInst;
  8487. // Shuffle the operands around so the lane index operand is in the
  8488. // right place.
  8489. unsigned Spacing;
  8490. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8491. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8492. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8493. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8494. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8495. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8496. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8497. TmpInst.addOperand(Inst.getOperand(5));
  8498. Inst = TmpInst;
  8499. return true;
  8500. }
  8501. case ARM::VLD2LNdAsm_8:
  8502. case ARM::VLD2LNdAsm_16:
  8503. case ARM::VLD2LNdAsm_32:
  8504. case ARM::VLD2LNqAsm_16:
  8505. case ARM::VLD2LNqAsm_32: {
  8506. MCInst TmpInst;
  8507. // Shuffle the operands around so the lane index operand is in the
  8508. // right place.
  8509. unsigned Spacing;
  8510. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8511. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8512. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8513. Spacing));
  8514. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8515. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8516. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8517. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8518. Spacing));
  8519. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8520. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8521. TmpInst.addOperand(Inst.getOperand(5));
  8522. Inst = TmpInst;
  8523. return true;
  8524. }
  8525. case ARM::VLD3LNdAsm_8:
  8526. case ARM::VLD3LNdAsm_16:
  8527. case ARM::VLD3LNdAsm_32:
  8528. case ARM::VLD3LNqAsm_16:
  8529. case ARM::VLD3LNqAsm_32: {
  8530. MCInst TmpInst;
  8531. // Shuffle the operands around so the lane index operand is in the
  8532. // right place.
  8533. unsigned Spacing;
  8534. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8535. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8536. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8537. Spacing));
  8538. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8539. Spacing * 2));
  8540. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8541. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8542. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8543. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8544. Spacing));
  8545. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8546. Spacing * 2));
  8547. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8548. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8549. TmpInst.addOperand(Inst.getOperand(5));
  8550. Inst = TmpInst;
  8551. return true;
  8552. }
  8553. case ARM::VLD4LNdAsm_8:
  8554. case ARM::VLD4LNdAsm_16:
  8555. case ARM::VLD4LNdAsm_32:
  8556. case ARM::VLD4LNqAsm_16:
  8557. case ARM::VLD4LNqAsm_32: {
  8558. MCInst TmpInst;
  8559. // Shuffle the operands around so the lane index operand is in the
  8560. // right place.
  8561. unsigned Spacing;
  8562. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8563. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8564. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8565. Spacing));
  8566. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8567. Spacing * 2));
  8568. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8569. Spacing * 3));
  8570. TmpInst.addOperand(Inst.getOperand(2)); // Rn
  8571. TmpInst.addOperand(Inst.getOperand(3)); // alignment
  8572. TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
  8573. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8574. Spacing));
  8575. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8576. Spacing * 2));
  8577. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8578. Spacing * 3));
  8579. TmpInst.addOperand(Inst.getOperand(1)); // lane
  8580. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8581. TmpInst.addOperand(Inst.getOperand(5));
  8582. Inst = TmpInst;
  8583. return true;
  8584. }
  8585. // VLD3DUP single 3-element structure to all lanes instructions.
  8586. case ARM::VLD3DUPdAsm_8:
  8587. case ARM::VLD3DUPdAsm_16:
  8588. case ARM::VLD3DUPdAsm_32:
  8589. case ARM::VLD3DUPqAsm_8:
  8590. case ARM::VLD3DUPqAsm_16:
  8591. case ARM::VLD3DUPqAsm_32: {
  8592. MCInst TmpInst;
  8593. unsigned Spacing;
  8594. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8595. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8596. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8597. Spacing));
  8598. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8599. Spacing * 2));
  8600. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8601. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8602. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8603. TmpInst.addOperand(Inst.getOperand(4));
  8604. Inst = TmpInst;
  8605. return true;
  8606. }
  8607. case ARM::VLD3DUPdWB_fixed_Asm_8:
  8608. case ARM::VLD3DUPdWB_fixed_Asm_16:
  8609. case ARM::VLD3DUPdWB_fixed_Asm_32:
  8610. case ARM::VLD3DUPqWB_fixed_Asm_8:
  8611. case ARM::VLD3DUPqWB_fixed_Asm_16:
  8612. case ARM::VLD3DUPqWB_fixed_Asm_32: {
  8613. MCInst TmpInst;
  8614. unsigned Spacing;
  8615. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8616. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8617. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8618. Spacing));
  8619. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8620. Spacing * 2));
  8621. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8622. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8623. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8624. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8625. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8626. TmpInst.addOperand(Inst.getOperand(4));
  8627. Inst = TmpInst;
  8628. return true;
  8629. }
  8630. case ARM::VLD3DUPdWB_register_Asm_8:
  8631. case ARM::VLD3DUPdWB_register_Asm_16:
  8632. case ARM::VLD3DUPdWB_register_Asm_32:
  8633. case ARM::VLD3DUPqWB_register_Asm_8:
  8634. case ARM::VLD3DUPqWB_register_Asm_16:
  8635. case ARM::VLD3DUPqWB_register_Asm_32: {
  8636. MCInst TmpInst;
  8637. unsigned Spacing;
  8638. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8639. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8640. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8641. Spacing));
  8642. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8643. Spacing * 2));
  8644. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8645. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8646. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8647. TmpInst.addOperand(Inst.getOperand(3)); // Rm
  8648. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8649. TmpInst.addOperand(Inst.getOperand(5));
  8650. Inst = TmpInst;
  8651. return true;
  8652. }
  8653. // VLD3 multiple 3-element structure instructions.
  8654. case ARM::VLD3dAsm_8:
  8655. case ARM::VLD3dAsm_16:
  8656. case ARM::VLD3dAsm_32:
  8657. case ARM::VLD3qAsm_8:
  8658. case ARM::VLD3qAsm_16:
  8659. case ARM::VLD3qAsm_32: {
  8660. MCInst TmpInst;
  8661. unsigned Spacing;
  8662. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8663. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8664. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8665. Spacing));
  8666. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8667. Spacing * 2));
  8668. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8669. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8670. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8671. TmpInst.addOperand(Inst.getOperand(4));
  8672. Inst = TmpInst;
  8673. return true;
  8674. }
  8675. case ARM::VLD3dWB_fixed_Asm_8:
  8676. case ARM::VLD3dWB_fixed_Asm_16:
  8677. case ARM::VLD3dWB_fixed_Asm_32:
  8678. case ARM::VLD3qWB_fixed_Asm_8:
  8679. case ARM::VLD3qWB_fixed_Asm_16:
  8680. case ARM::VLD3qWB_fixed_Asm_32: {
  8681. MCInst TmpInst;
  8682. unsigned Spacing;
  8683. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8684. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8685. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8686. Spacing));
  8687. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8688. Spacing * 2));
  8689. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8690. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8691. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8692. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8693. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8694. TmpInst.addOperand(Inst.getOperand(4));
  8695. Inst = TmpInst;
  8696. return true;
  8697. }
  8698. case ARM::VLD3dWB_register_Asm_8:
  8699. case ARM::VLD3dWB_register_Asm_16:
  8700. case ARM::VLD3dWB_register_Asm_32:
  8701. case ARM::VLD3qWB_register_Asm_8:
  8702. case ARM::VLD3qWB_register_Asm_16:
  8703. case ARM::VLD3qWB_register_Asm_32: {
  8704. MCInst TmpInst;
  8705. unsigned Spacing;
  8706. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8707. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8708. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8709. Spacing));
  8710. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8711. Spacing * 2));
  8712. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8713. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8714. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8715. TmpInst.addOperand(Inst.getOperand(3)); // Rm
  8716. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8717. TmpInst.addOperand(Inst.getOperand(5));
  8718. Inst = TmpInst;
  8719. return true;
  8720. }
  8721. // VLD4DUP single 3-element structure to all lanes instructions.
  8722. case ARM::VLD4DUPdAsm_8:
  8723. case ARM::VLD4DUPdAsm_16:
  8724. case ARM::VLD4DUPdAsm_32:
  8725. case ARM::VLD4DUPqAsm_8:
  8726. case ARM::VLD4DUPqAsm_16:
  8727. case ARM::VLD4DUPqAsm_32: {
  8728. MCInst TmpInst;
  8729. unsigned Spacing;
  8730. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8731. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8732. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8733. Spacing));
  8734. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8735. Spacing * 2));
  8736. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8737. Spacing * 3));
  8738. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8739. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8740. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8741. TmpInst.addOperand(Inst.getOperand(4));
  8742. Inst = TmpInst;
  8743. return true;
  8744. }
  8745. case ARM::VLD4DUPdWB_fixed_Asm_8:
  8746. case ARM::VLD4DUPdWB_fixed_Asm_16:
  8747. case ARM::VLD4DUPdWB_fixed_Asm_32:
  8748. case ARM::VLD4DUPqWB_fixed_Asm_8:
  8749. case ARM::VLD4DUPqWB_fixed_Asm_16:
  8750. case ARM::VLD4DUPqWB_fixed_Asm_32: {
  8751. MCInst TmpInst;
  8752. unsigned Spacing;
  8753. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8754. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8755. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8756. Spacing));
  8757. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8758. Spacing * 2));
  8759. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8760. Spacing * 3));
  8761. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8762. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8763. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8764. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8765. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8766. TmpInst.addOperand(Inst.getOperand(4));
  8767. Inst = TmpInst;
  8768. return true;
  8769. }
  8770. case ARM::VLD4DUPdWB_register_Asm_8:
  8771. case ARM::VLD4DUPdWB_register_Asm_16:
  8772. case ARM::VLD4DUPdWB_register_Asm_32:
  8773. case ARM::VLD4DUPqWB_register_Asm_8:
  8774. case ARM::VLD4DUPqWB_register_Asm_16:
  8775. case ARM::VLD4DUPqWB_register_Asm_32: {
  8776. MCInst TmpInst;
  8777. unsigned Spacing;
  8778. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8779. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8780. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8781. Spacing));
  8782. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8783. Spacing * 2));
  8784. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8785. Spacing * 3));
  8786. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8787. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8788. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8789. TmpInst.addOperand(Inst.getOperand(3)); // Rm
  8790. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8791. TmpInst.addOperand(Inst.getOperand(5));
  8792. Inst = TmpInst;
  8793. return true;
  8794. }
  8795. // VLD4 multiple 4-element structure instructions.
  8796. case ARM::VLD4dAsm_8:
  8797. case ARM::VLD4dAsm_16:
  8798. case ARM::VLD4dAsm_32:
  8799. case ARM::VLD4qAsm_8:
  8800. case ARM::VLD4qAsm_16:
  8801. case ARM::VLD4qAsm_32: {
  8802. MCInst TmpInst;
  8803. unsigned Spacing;
  8804. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8805. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8806. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8807. Spacing));
  8808. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8809. Spacing * 2));
  8810. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8811. Spacing * 3));
  8812. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8813. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8814. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8815. TmpInst.addOperand(Inst.getOperand(4));
  8816. Inst = TmpInst;
  8817. return true;
  8818. }
  8819. case ARM::VLD4dWB_fixed_Asm_8:
  8820. case ARM::VLD4dWB_fixed_Asm_16:
  8821. case ARM::VLD4dWB_fixed_Asm_32:
  8822. case ARM::VLD4qWB_fixed_Asm_8:
  8823. case ARM::VLD4qWB_fixed_Asm_16:
  8824. case ARM::VLD4qWB_fixed_Asm_32: {
  8825. MCInst TmpInst;
  8826. unsigned Spacing;
  8827. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8828. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8829. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8830. Spacing));
  8831. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8832. Spacing * 2));
  8833. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8834. Spacing * 3));
  8835. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8836. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8837. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8838. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8839. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8840. TmpInst.addOperand(Inst.getOperand(4));
  8841. Inst = TmpInst;
  8842. return true;
  8843. }
  8844. case ARM::VLD4dWB_register_Asm_8:
  8845. case ARM::VLD4dWB_register_Asm_16:
  8846. case ARM::VLD4dWB_register_Asm_32:
  8847. case ARM::VLD4qWB_register_Asm_8:
  8848. case ARM::VLD4qWB_register_Asm_16:
  8849. case ARM::VLD4qWB_register_Asm_32: {
  8850. MCInst TmpInst;
  8851. unsigned Spacing;
  8852. TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
  8853. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8854. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8855. Spacing));
  8856. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8857. Spacing * 2));
  8858. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8859. Spacing * 3));
  8860. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8861. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8862. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8863. TmpInst.addOperand(Inst.getOperand(3)); // Rm
  8864. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8865. TmpInst.addOperand(Inst.getOperand(5));
  8866. Inst = TmpInst;
  8867. return true;
  8868. }
  8869. // VST3 multiple 3-element structure instructions.
  8870. case ARM::VST3dAsm_8:
  8871. case ARM::VST3dAsm_16:
  8872. case ARM::VST3dAsm_32:
  8873. case ARM::VST3qAsm_8:
  8874. case ARM::VST3qAsm_16:
  8875. case ARM::VST3qAsm_32: {
  8876. MCInst TmpInst;
  8877. unsigned Spacing;
  8878. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8879. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8880. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8881. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8882. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8883. Spacing));
  8884. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8885. Spacing * 2));
  8886. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8887. TmpInst.addOperand(Inst.getOperand(4));
  8888. Inst = TmpInst;
  8889. return true;
  8890. }
  8891. case ARM::VST3dWB_fixed_Asm_8:
  8892. case ARM::VST3dWB_fixed_Asm_16:
  8893. case ARM::VST3dWB_fixed_Asm_32:
  8894. case ARM::VST3qWB_fixed_Asm_8:
  8895. case ARM::VST3qWB_fixed_Asm_16:
  8896. case ARM::VST3qWB_fixed_Asm_32: {
  8897. MCInst TmpInst;
  8898. unsigned Spacing;
  8899. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8900. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8901. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8902. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8903. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8904. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8905. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8906. Spacing));
  8907. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8908. Spacing * 2));
  8909. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8910. TmpInst.addOperand(Inst.getOperand(4));
  8911. Inst = TmpInst;
  8912. return true;
  8913. }
  8914. case ARM::VST3dWB_register_Asm_8:
  8915. case ARM::VST3dWB_register_Asm_16:
  8916. case ARM::VST3dWB_register_Asm_32:
  8917. case ARM::VST3qWB_register_Asm_8:
  8918. case ARM::VST3qWB_register_Asm_16:
  8919. case ARM::VST3qWB_register_Asm_32: {
  8920. MCInst TmpInst;
  8921. unsigned Spacing;
  8922. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8923. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8924. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8925. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8926. TmpInst.addOperand(Inst.getOperand(3)); // Rm
  8927. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8928. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8929. Spacing));
  8930. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8931. Spacing * 2));
  8932. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  8933. TmpInst.addOperand(Inst.getOperand(5));
  8934. Inst = TmpInst;
  8935. return true;
  8936. }
  8937. // VST4 multiple 3-element structure instructions.
  8938. case ARM::VST4dAsm_8:
  8939. case ARM::VST4dAsm_16:
  8940. case ARM::VST4dAsm_32:
  8941. case ARM::VST4qAsm_8:
  8942. case ARM::VST4qAsm_16:
  8943. case ARM::VST4qAsm_32: {
  8944. MCInst TmpInst;
  8945. unsigned Spacing;
  8946. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8947. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8948. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8949. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8950. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8951. Spacing));
  8952. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8953. Spacing * 2));
  8954. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8955. Spacing * 3));
  8956. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8957. TmpInst.addOperand(Inst.getOperand(4));
  8958. Inst = TmpInst;
  8959. return true;
  8960. }
  8961. case ARM::VST4dWB_fixed_Asm_8:
  8962. case ARM::VST4dWB_fixed_Asm_16:
  8963. case ARM::VST4dWB_fixed_Asm_32:
  8964. case ARM::VST4qWB_fixed_Asm_8:
  8965. case ARM::VST4qWB_fixed_Asm_16:
  8966. case ARM::VST4qWB_fixed_Asm_32: {
  8967. MCInst TmpInst;
  8968. unsigned Spacing;
  8969. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8970. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8971. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8972. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8973. TmpInst.addOperand(MCOperand::createReg(0)); // Rm
  8974. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  8975. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8976. Spacing));
  8977. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8978. Spacing * 2));
  8979. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  8980. Spacing * 3));
  8981. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  8982. TmpInst.addOperand(Inst.getOperand(4));
  8983. Inst = TmpInst;
  8984. return true;
  8985. }
  8986. case ARM::VST4dWB_register_Asm_8:
  8987. case ARM::VST4dWB_register_Asm_16:
  8988. case ARM::VST4dWB_register_Asm_32:
  8989. case ARM::VST4qWB_register_Asm_8:
  8990. case ARM::VST4qWB_register_Asm_16:
  8991. case ARM::VST4qWB_register_Asm_32: {
  8992. MCInst TmpInst;
  8993. unsigned Spacing;
  8994. TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
  8995. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  8996. TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
  8997. TmpInst.addOperand(Inst.getOperand(2)); // alignment
  8998. TmpInst.addOperand(Inst.getOperand(3)); // Rm
  8999. TmpInst.addOperand(Inst.getOperand(0)); // Vd
  9000. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  9001. Spacing));
  9002. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  9003. Spacing * 2));
  9004. TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() +
  9005. Spacing * 3));
  9006. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  9007. TmpInst.addOperand(Inst.getOperand(5));
  9008. Inst = TmpInst;
  9009. return true;
  9010. }
  9011. // Handle encoding choice for the shift-immediate instructions.
  9012. case ARM::t2LSLri:
  9013. case ARM::t2LSRri:
  9014. case ARM::t2ASRri:
  9015. if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
  9016. isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9017. Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
  9018. !HasWideQualifier) {
  9019. unsigned NewOpc;
  9020. switch (Inst.getOpcode()) {
  9021. default: llvm_unreachable("unexpected opcode");
  9022. case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
  9023. case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
  9024. case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
  9025. }
  9026. // The Thumb1 operands aren't in the same order. Awesome, eh?
  9027. MCInst TmpInst;
  9028. TmpInst.setOpcode(NewOpc);
  9029. TmpInst.addOperand(Inst.getOperand(0));
  9030. TmpInst.addOperand(Inst.getOperand(5));
  9031. TmpInst.addOperand(Inst.getOperand(1));
  9032. TmpInst.addOperand(Inst.getOperand(2));
  9033. TmpInst.addOperand(Inst.getOperand(3));
  9034. TmpInst.addOperand(Inst.getOperand(4));
  9035. Inst = TmpInst;
  9036. return true;
  9037. }
  9038. return false;
  9039. // Handle the Thumb2 mode MOV complex aliases.
  9040. case ARM::t2MOVsr:
  9041. case ARM::t2MOVSsr: {
  9042. // Which instruction to expand to depends on the CCOut operand and
  9043. // whether we're in an IT block if the register operands are low
  9044. // registers.
  9045. bool isNarrow = false;
  9046. if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
  9047. isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9048. isARMLowRegister(Inst.getOperand(2).getReg()) &&
  9049. Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
  9050. inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr) &&
  9051. !HasWideQualifier)
  9052. isNarrow = true;
  9053. MCInst TmpInst;
  9054. unsigned newOpc;
  9055. switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
  9056. default: llvm_unreachable("unexpected opcode!");
  9057. case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
  9058. case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
  9059. case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
  9060. case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
  9061. }
  9062. TmpInst.setOpcode(newOpc);
  9063. TmpInst.addOperand(Inst.getOperand(0)); // Rd
  9064. if (isNarrow)
  9065. TmpInst.addOperand(MCOperand::createReg(
  9066. Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
  9067. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9068. TmpInst.addOperand(Inst.getOperand(2)); // Rm
  9069. TmpInst.addOperand(Inst.getOperand(4)); // CondCode
  9070. TmpInst.addOperand(Inst.getOperand(5));
  9071. if (!isNarrow)
  9072. TmpInst.addOperand(MCOperand::createReg(
  9073. Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
  9074. Inst = TmpInst;
  9075. return true;
  9076. }
  9077. case ARM::t2MOVsi:
  9078. case ARM::t2MOVSsi: {
  9079. // Which instruction to expand to depends on the CCOut operand and
  9080. // whether we're in an IT block if the register operands are low
  9081. // registers.
  9082. bool isNarrow = false;
  9083. if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
  9084. isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9085. inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi) &&
  9086. !HasWideQualifier)
  9087. isNarrow = true;
  9088. MCInst TmpInst;
  9089. unsigned newOpc;
  9090. unsigned Shift = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
  9091. unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
  9092. bool isMov = false;
  9093. // MOV rd, rm, LSL #0 is actually a MOV instruction
  9094. if (Shift == ARM_AM::lsl && Amount == 0) {
  9095. isMov = true;
  9096. // The 16-bit encoding of MOV rd, rm, LSL #N is explicitly encoding T2 of
  9097. // MOV (register) in the ARMv8-A and ARMv8-M manuals, and immediate 0 is
  9098. // unpredictable in an IT block so the 32-bit encoding T3 has to be used
  9099. // instead.
  9100. if (inITBlock()) {
  9101. isNarrow = false;
  9102. }
  9103. newOpc = isNarrow ? ARM::tMOVSr : ARM::t2MOVr;
  9104. } else {
  9105. switch(Shift) {
  9106. default: llvm_unreachable("unexpected opcode!");
  9107. case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
  9108. case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
  9109. case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
  9110. case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
  9111. case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
  9112. }
  9113. }
  9114. if (Amount == 32) Amount = 0;
  9115. TmpInst.setOpcode(newOpc);
  9116. TmpInst.addOperand(Inst.getOperand(0)); // Rd
  9117. if (isNarrow && !isMov)
  9118. TmpInst.addOperand(MCOperand::createReg(
  9119. Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
  9120. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9121. if (newOpc != ARM::t2RRX && !isMov)
  9122. TmpInst.addOperand(MCOperand::createImm(Amount));
  9123. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  9124. TmpInst.addOperand(Inst.getOperand(4));
  9125. if (!isNarrow)
  9126. TmpInst.addOperand(MCOperand::createReg(
  9127. Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
  9128. Inst = TmpInst;
  9129. return true;
  9130. }
  9131. // Handle the ARM mode MOV complex aliases.
  9132. case ARM::ASRr:
  9133. case ARM::LSRr:
  9134. case ARM::LSLr:
  9135. case ARM::RORr: {
  9136. ARM_AM::ShiftOpc ShiftTy;
  9137. switch(Inst.getOpcode()) {
  9138. default: llvm_unreachable("unexpected opcode!");
  9139. case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
  9140. case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
  9141. case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
  9142. case ARM::RORr: ShiftTy = ARM_AM::ror; break;
  9143. }
  9144. unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
  9145. MCInst TmpInst;
  9146. TmpInst.setOpcode(ARM::MOVsr);
  9147. TmpInst.addOperand(Inst.getOperand(0)); // Rd
  9148. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9149. TmpInst.addOperand(Inst.getOperand(2)); // Rm
  9150. TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty
  9151. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  9152. TmpInst.addOperand(Inst.getOperand(4));
  9153. TmpInst.addOperand(Inst.getOperand(5)); // cc_out
  9154. Inst = TmpInst;
  9155. return true;
  9156. }
  9157. case ARM::ASRi:
  9158. case ARM::LSRi:
  9159. case ARM::LSLi:
  9160. case ARM::RORi: {
  9161. ARM_AM::ShiftOpc ShiftTy;
  9162. switch(Inst.getOpcode()) {
  9163. default: llvm_unreachable("unexpected opcode!");
  9164. case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
  9165. case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
  9166. case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
  9167. case ARM::RORi: ShiftTy = ARM_AM::ror; break;
  9168. }
  9169. // A shift by zero is a plain MOVr, not a MOVsi.
  9170. unsigned Amt = Inst.getOperand(2).getImm();
  9171. unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
  9172. // A shift by 32 should be encoded as 0 when permitted
  9173. if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
  9174. Amt = 0;
  9175. unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
  9176. MCInst TmpInst;
  9177. TmpInst.setOpcode(Opc);
  9178. TmpInst.addOperand(Inst.getOperand(0)); // Rd
  9179. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9180. if (Opc == ARM::MOVsi)
  9181. TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty
  9182. TmpInst.addOperand(Inst.getOperand(3)); // CondCode
  9183. TmpInst.addOperand(Inst.getOperand(4));
  9184. TmpInst.addOperand(Inst.getOperand(5)); // cc_out
  9185. Inst = TmpInst;
  9186. return true;
  9187. }
  9188. case ARM::RRXi: {
  9189. unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
  9190. MCInst TmpInst;
  9191. TmpInst.setOpcode(ARM::MOVsi);
  9192. TmpInst.addOperand(Inst.getOperand(0)); // Rd
  9193. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9194. TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty
  9195. TmpInst.addOperand(Inst.getOperand(2)); // CondCode
  9196. TmpInst.addOperand(Inst.getOperand(3));
  9197. TmpInst.addOperand(Inst.getOperand(4)); // cc_out
  9198. Inst = TmpInst;
  9199. return true;
  9200. }
  9201. case ARM::t2LDMIA_UPD: {
  9202. // If this is a load of a single register, then we should use
  9203. // a post-indexed LDR instruction instead, per the ARM ARM.
  9204. if (Inst.getNumOperands() != 5)
  9205. return false;
  9206. MCInst TmpInst;
  9207. TmpInst.setOpcode(ARM::t2LDR_POST);
  9208. TmpInst.addOperand(Inst.getOperand(4)); // Rt
  9209. TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
  9210. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9211. TmpInst.addOperand(MCOperand::createImm(4));
  9212. TmpInst.addOperand(Inst.getOperand(2)); // CondCode
  9213. TmpInst.addOperand(Inst.getOperand(3));
  9214. Inst = TmpInst;
  9215. return true;
  9216. }
  9217. case ARM::t2STMDB_UPD: {
  9218. // If this is a store of a single register, then we should use
  9219. // a pre-indexed STR instruction instead, per the ARM ARM.
  9220. if (Inst.getNumOperands() != 5)
  9221. return false;
  9222. MCInst TmpInst;
  9223. TmpInst.setOpcode(ARM::t2STR_PRE);
  9224. TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
  9225. TmpInst.addOperand(Inst.getOperand(4)); // Rt
  9226. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9227. TmpInst.addOperand(MCOperand::createImm(-4));
  9228. TmpInst.addOperand(Inst.getOperand(2)); // CondCode
  9229. TmpInst.addOperand(Inst.getOperand(3));
  9230. Inst = TmpInst;
  9231. return true;
  9232. }
  9233. case ARM::LDMIA_UPD:
  9234. // If this is a load of a single register via a 'pop', then we should use
  9235. // a post-indexed LDR instruction instead, per the ARM ARM.
  9236. if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
  9237. Inst.getNumOperands() == 5) {
  9238. MCInst TmpInst;
  9239. TmpInst.setOpcode(ARM::LDR_POST_IMM);
  9240. TmpInst.addOperand(Inst.getOperand(4)); // Rt
  9241. TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
  9242. TmpInst.addOperand(Inst.getOperand(1)); // Rn
  9243. TmpInst.addOperand(MCOperand::createReg(0)); // am2offset
  9244. TmpInst.addOperand(MCOperand::createImm(4));
  9245. TmpInst.addOperand(Inst.getOperand(2)); // CondCode
  9246. TmpInst.addOperand(Inst.getOperand(3));
  9247. Inst = TmpInst;
  9248. return true;
  9249. }
  9250. break;
  9251. case ARM::STMDB_UPD:
  9252. // If this is a store of a single register via a 'push', then we should use
  9253. // a pre-indexed STR instruction instead, per the ARM ARM.
  9254. if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
  9255. Inst.getNumOperands() == 5) {
  9256. MCInst TmpInst;
  9257. TmpInst.setOpcode(ARM::STR_PRE_IMM);
  9258. TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
  9259. TmpInst.addOperand(Inst.getOperand(4)); // Rt
  9260. TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
  9261. TmpInst.addOperand(MCOperand::createImm(-4));
  9262. TmpInst.addOperand(Inst.getOperand(2)); // CondCode
  9263. TmpInst.addOperand(Inst.getOperand(3));
  9264. Inst = TmpInst;
  9265. }
  9266. break;
  9267. case ARM::t2ADDri12:
  9268. case ARM::t2SUBri12:
  9269. case ARM::t2ADDspImm12:
  9270. case ARM::t2SUBspImm12: {
  9271. // If the immediate fits for encoding T3 and the generic
  9272. // mnemonic was used, encoding T3 is preferred.
  9273. const StringRef Token = static_cast<ARMOperand &>(*Operands[0]).getToken();
  9274. if ((Token != "add" && Token != "sub") ||
  9275. ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
  9276. break;
  9277. switch (Inst.getOpcode()) {
  9278. case ARM::t2ADDri12:
  9279. Inst.setOpcode(ARM::t2ADDri);
  9280. break;
  9281. case ARM::t2SUBri12:
  9282. Inst.setOpcode(ARM::t2SUBri);
  9283. break;
  9284. case ARM::t2ADDspImm12:
  9285. Inst.setOpcode(ARM::t2ADDspImm);
  9286. break;
  9287. case ARM::t2SUBspImm12:
  9288. Inst.setOpcode(ARM::t2SUBspImm);
  9289. break;
  9290. }
  9291. Inst.addOperand(MCOperand::createReg(0)); // cc_out
  9292. return true;
  9293. }
  9294. case ARM::tADDi8:
  9295. // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
  9296. // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
  9297. // to encoding T2 if <Rd> is specified and encoding T2 is preferred
  9298. // to encoding T1 if <Rd> is omitted."
  9299. if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
  9300. Inst.setOpcode(ARM::tADDi3);
  9301. return true;
  9302. }
  9303. break;
  9304. case ARM::tSUBi8:
  9305. // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
  9306. // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
  9307. // to encoding T2 if <Rd> is specified and encoding T2 is preferred
  9308. // to encoding T1 if <Rd> is omitted."
  9309. if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
  9310. Inst.setOpcode(ARM::tSUBi3);
  9311. return true;
  9312. }
  9313. break;
  9314. case ARM::t2ADDri:
  9315. case ARM::t2SUBri: {
  9316. // If the destination and first source operand are the same, and
  9317. // the flags are compatible with the current IT status, use encoding T2
  9318. // instead of T3. For compatibility with the system 'as'. Make sure the
  9319. // wide encoding wasn't explicit.
  9320. if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
  9321. !isARMLowRegister(Inst.getOperand(0).getReg()) ||
  9322. (Inst.getOperand(2).isImm() &&
  9323. (unsigned)Inst.getOperand(2).getImm() > 255) ||
  9324. Inst.getOperand(5).getReg() != (inITBlock() ? 0 : ARM::CPSR) ||
  9325. HasWideQualifier)
  9326. break;
  9327. MCInst TmpInst;
  9328. TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
  9329. ARM::tADDi8 : ARM::tSUBi8);
  9330. TmpInst.addOperand(Inst.getOperand(0));
  9331. TmpInst.addOperand(Inst.getOperand(5));
  9332. TmpInst.addOperand(Inst.getOperand(0));
  9333. TmpInst.addOperand(Inst.getOperand(2));
  9334. TmpInst.addOperand(Inst.getOperand(3));
  9335. TmpInst.addOperand(Inst.getOperand(4));
  9336. Inst = TmpInst;
  9337. return true;
  9338. }
  9339. case ARM::t2ADDspImm:
  9340. case ARM::t2SUBspImm: {
  9341. // Prefer T1 encoding if possible
  9342. if (Inst.getOperand(5).getReg() != 0 || HasWideQualifier)
  9343. break;
  9344. unsigned V = Inst.getOperand(2).getImm();
  9345. if (V & 3 || V > ((1 << 7) - 1) << 2)
  9346. break;
  9347. MCInst TmpInst;
  9348. TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDspImm ? ARM::tADDspi
  9349. : ARM::tSUBspi);
  9350. TmpInst.addOperand(MCOperand::createReg(ARM::SP)); // destination reg
  9351. TmpInst.addOperand(MCOperand::createReg(ARM::SP)); // source reg
  9352. TmpInst.addOperand(MCOperand::createImm(V / 4)); // immediate
  9353. TmpInst.addOperand(Inst.getOperand(3)); // pred
  9354. TmpInst.addOperand(Inst.getOperand(4));
  9355. Inst = TmpInst;
  9356. return true;
  9357. }
  9358. case ARM::t2ADDrr: {
  9359. // If the destination and first source operand are the same, and
  9360. // there's no setting of the flags, use encoding T2 instead of T3.
  9361. // Note that this is only for ADD, not SUB. This mirrors the system
  9362. // 'as' behaviour. Also take advantage of ADD being commutative.
  9363. // Make sure the wide encoding wasn't explicit.
  9364. bool Swap = false;
  9365. auto DestReg = Inst.getOperand(0).getReg();
  9366. bool Transform = DestReg == Inst.getOperand(1).getReg();
  9367. if (!Transform && DestReg == Inst.getOperand(2).getReg()) {
  9368. Transform = true;
  9369. Swap = true;
  9370. }
  9371. if (!Transform ||
  9372. Inst.getOperand(5).getReg() != 0 ||
  9373. HasWideQualifier)
  9374. break;
  9375. MCInst TmpInst;
  9376. TmpInst.setOpcode(ARM::tADDhirr);
  9377. TmpInst.addOperand(Inst.getOperand(0));
  9378. TmpInst.addOperand(Inst.getOperand(0));
  9379. TmpInst.addOperand(Inst.getOperand(Swap ? 1 : 2));
  9380. TmpInst.addOperand(Inst.getOperand(3));
  9381. TmpInst.addOperand(Inst.getOperand(4));
  9382. Inst = TmpInst;
  9383. return true;
  9384. }
  9385. case ARM::tADDrSP:
  9386. // If the non-SP source operand and the destination operand are not the
  9387. // same, we need to use the 32-bit encoding if it's available.
  9388. if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
  9389. Inst.setOpcode(ARM::t2ADDrr);
  9390. Inst.addOperand(MCOperand::createReg(0)); // cc_out
  9391. return true;
  9392. }
  9393. break;
  9394. case ARM::tB:
  9395. // A Thumb conditional branch outside of an IT block is a tBcc.
  9396. if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
  9397. Inst.setOpcode(ARM::tBcc);
  9398. return true;
  9399. }
  9400. break;
  9401. case ARM::t2B:
  9402. // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
  9403. if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
  9404. Inst.setOpcode(ARM::t2Bcc);
  9405. return true;
  9406. }
  9407. break;
  9408. case ARM::t2Bcc:
  9409. // If the conditional is AL or we're in an IT block, we really want t2B.
  9410. if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
  9411. Inst.setOpcode(ARM::t2B);
  9412. return true;
  9413. }
  9414. break;
  9415. case ARM::tBcc:
  9416. // If the conditional is AL, we really want tB.
  9417. if (Inst.getOperand(1).getImm() == ARMCC::AL) {
  9418. Inst.setOpcode(ARM::tB);
  9419. return true;
  9420. }
  9421. break;
  9422. case ARM::tLDMIA: {
  9423. // If the register list contains any high registers, or if the writeback
  9424. // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
  9425. // instead if we're in Thumb2. Otherwise, this should have generated
  9426. // an error in validateInstruction().
  9427. unsigned Rn = Inst.getOperand(0).getReg();
  9428. bool hasWritebackToken =
  9429. (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
  9430. static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
  9431. bool listContainsBase;
  9432. if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
  9433. (!listContainsBase && !hasWritebackToken) ||
  9434. (listContainsBase && hasWritebackToken)) {
  9435. // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
  9436. assert(isThumbTwo());
  9437. Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
  9438. // If we're switching to the updating version, we need to insert
  9439. // the writeback tied operand.
  9440. if (hasWritebackToken)
  9441. Inst.insert(Inst.begin(),
  9442. MCOperand::createReg(Inst.getOperand(0).getReg()));
  9443. return true;
  9444. }
  9445. break;
  9446. }
  9447. case ARM::tSTMIA_UPD: {
  9448. // If the register list contains any high registers, we need to use
  9449. // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
  9450. // should have generated an error in validateInstruction().
  9451. unsigned Rn = Inst.getOperand(0).getReg();
  9452. bool listContainsBase;
  9453. if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
  9454. // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
  9455. assert(isThumbTwo());
  9456. Inst.setOpcode(ARM::t2STMIA_UPD);
  9457. return true;
  9458. }
  9459. break;
  9460. }
  9461. case ARM::tPOP: {
  9462. bool listContainsBase;
  9463. // If the register list contains any high registers, we need to use
  9464. // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
  9465. // should have generated an error in validateInstruction().
  9466. if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
  9467. return false;
  9468. assert(isThumbTwo());
  9469. Inst.setOpcode(ARM::t2LDMIA_UPD);
  9470. // Add the base register and writeback operands.
  9471. Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
  9472. Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
  9473. return true;
  9474. }
  9475. case ARM::tPUSH: {
  9476. bool listContainsBase;
  9477. if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
  9478. return false;
  9479. assert(isThumbTwo());
  9480. Inst.setOpcode(ARM::t2STMDB_UPD);
  9481. // Add the base register and writeback operands.
  9482. Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
  9483. Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP));
  9484. return true;
  9485. }
  9486. case ARM::t2MOVi:
  9487. // If we can use the 16-bit encoding and the user didn't explicitly
  9488. // request the 32-bit variant, transform it here.
  9489. if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
  9490. (Inst.getOperand(1).isImm() &&
  9491. (unsigned)Inst.getOperand(1).getImm() <= 255) &&
  9492. Inst.getOperand(4).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
  9493. !HasWideQualifier) {
  9494. // The operands aren't in the same order for tMOVi8...
  9495. MCInst TmpInst;
  9496. TmpInst.setOpcode(ARM::tMOVi8);
  9497. TmpInst.addOperand(Inst.getOperand(0));
  9498. TmpInst.addOperand(Inst.getOperand(4));
  9499. TmpInst.addOperand(Inst.getOperand(1));
  9500. TmpInst.addOperand(Inst.getOperand(2));
  9501. TmpInst.addOperand(Inst.getOperand(3));
  9502. Inst = TmpInst;
  9503. return true;
  9504. }
  9505. break;
  9506. case ARM::t2MOVr:
  9507. // If we can use the 16-bit encoding and the user didn't explicitly
  9508. // request the 32-bit variant, transform it here.
  9509. if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
  9510. isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9511. Inst.getOperand(2).getImm() == ARMCC::AL &&
  9512. Inst.getOperand(4).getReg() == ARM::CPSR &&
  9513. !HasWideQualifier) {
  9514. // The operands aren't the same for tMOV[S]r... (no cc_out)
  9515. MCInst TmpInst;
  9516. unsigned Op = Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr;
  9517. TmpInst.setOpcode(Op);
  9518. TmpInst.addOperand(Inst.getOperand(0));
  9519. TmpInst.addOperand(Inst.getOperand(1));
  9520. if (Op == ARM::tMOVr) {
  9521. TmpInst.addOperand(Inst.getOperand(2));
  9522. TmpInst.addOperand(Inst.getOperand(3));
  9523. }
  9524. Inst = TmpInst;
  9525. return true;
  9526. }
  9527. break;
  9528. case ARM::t2SXTH:
  9529. case ARM::t2SXTB:
  9530. case ARM::t2UXTH:
  9531. case ARM::t2UXTB:
  9532. // If we can use the 16-bit encoding and the user didn't explicitly
  9533. // request the 32-bit variant, transform it here.
  9534. if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
  9535. isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9536. Inst.getOperand(2).getImm() == 0 &&
  9537. !HasWideQualifier) {
  9538. unsigned NewOpc;
  9539. switch (Inst.getOpcode()) {
  9540. default: llvm_unreachable("Illegal opcode!");
  9541. case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
  9542. case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
  9543. case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
  9544. case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
  9545. }
  9546. // The operands aren't the same for thumb1 (no rotate operand).
  9547. MCInst TmpInst;
  9548. TmpInst.setOpcode(NewOpc);
  9549. TmpInst.addOperand(Inst.getOperand(0));
  9550. TmpInst.addOperand(Inst.getOperand(1));
  9551. TmpInst.addOperand(Inst.getOperand(3));
  9552. TmpInst.addOperand(Inst.getOperand(4));
  9553. Inst = TmpInst;
  9554. return true;
  9555. }
  9556. break;
  9557. case ARM::MOVsi: {
  9558. ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
  9559. // rrx shifts and asr/lsr of #32 is encoded as 0
  9560. if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
  9561. return false;
  9562. if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
  9563. // Shifting by zero is accepted as a vanilla 'MOVr'
  9564. MCInst TmpInst;
  9565. TmpInst.setOpcode(ARM::MOVr);
  9566. TmpInst.addOperand(Inst.getOperand(0));
  9567. TmpInst.addOperand(Inst.getOperand(1));
  9568. TmpInst.addOperand(Inst.getOperand(3));
  9569. TmpInst.addOperand(Inst.getOperand(4));
  9570. TmpInst.addOperand(Inst.getOperand(5));
  9571. Inst = TmpInst;
  9572. return true;
  9573. }
  9574. return false;
  9575. }
  9576. case ARM::ANDrsi:
  9577. case ARM::ORRrsi:
  9578. case ARM::EORrsi:
  9579. case ARM::BICrsi:
  9580. case ARM::SUBrsi:
  9581. case ARM::ADDrsi: {
  9582. unsigned newOpc;
  9583. ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
  9584. if (SOpc == ARM_AM::rrx) return false;
  9585. switch (Inst.getOpcode()) {
  9586. default: llvm_unreachable("unexpected opcode!");
  9587. case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
  9588. case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
  9589. case ARM::EORrsi: newOpc = ARM::EORrr; break;
  9590. case ARM::BICrsi: newOpc = ARM::BICrr; break;
  9591. case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
  9592. case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
  9593. }
  9594. // If the shift is by zero, use the non-shifted instruction definition.
  9595. // The exception is for right shifts, where 0 == 32
  9596. if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
  9597. !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
  9598. MCInst TmpInst;
  9599. TmpInst.setOpcode(newOpc);
  9600. TmpInst.addOperand(Inst.getOperand(0));
  9601. TmpInst.addOperand(Inst.getOperand(1));
  9602. TmpInst.addOperand(Inst.getOperand(2));
  9603. TmpInst.addOperand(Inst.getOperand(4));
  9604. TmpInst.addOperand(Inst.getOperand(5));
  9605. TmpInst.addOperand(Inst.getOperand(6));
  9606. Inst = TmpInst;
  9607. return true;
  9608. }
  9609. return false;
  9610. }
  9611. case ARM::ITasm:
  9612. case ARM::t2IT: {
  9613. // Set up the IT block state according to the IT instruction we just
  9614. // matched.
  9615. assert(!inITBlock() && "nested IT blocks?!");
  9616. startExplicitITBlock(ARMCC::CondCodes(Inst.getOperand(0).getImm()),
  9617. Inst.getOperand(1).getImm());
  9618. break;
  9619. }
  9620. case ARM::t2LSLrr:
  9621. case ARM::t2LSRrr:
  9622. case ARM::t2ASRrr:
  9623. case ARM::t2SBCrr:
  9624. case ARM::t2RORrr:
  9625. case ARM::t2BICrr:
  9626. // Assemblers should use the narrow encodings of these instructions when permissible.
  9627. if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9628. isARMLowRegister(Inst.getOperand(2).getReg())) &&
  9629. Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
  9630. Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
  9631. !HasWideQualifier) {
  9632. unsigned NewOpc;
  9633. switch (Inst.getOpcode()) {
  9634. default: llvm_unreachable("unexpected opcode");
  9635. case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
  9636. case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
  9637. case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
  9638. case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
  9639. case ARM::t2RORrr: NewOpc = ARM::tROR; break;
  9640. case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
  9641. }
  9642. MCInst TmpInst;
  9643. TmpInst.setOpcode(NewOpc);
  9644. TmpInst.addOperand(Inst.getOperand(0));
  9645. TmpInst.addOperand(Inst.getOperand(5));
  9646. TmpInst.addOperand(Inst.getOperand(1));
  9647. TmpInst.addOperand(Inst.getOperand(2));
  9648. TmpInst.addOperand(Inst.getOperand(3));
  9649. TmpInst.addOperand(Inst.getOperand(4));
  9650. Inst = TmpInst;
  9651. return true;
  9652. }
  9653. return false;
  9654. case ARM::t2ANDrr:
  9655. case ARM::t2EORrr:
  9656. case ARM::t2ADCrr:
  9657. case ARM::t2ORRrr:
  9658. // Assemblers should use the narrow encodings of these instructions when permissible.
  9659. // These instructions are special in that they are commutable, so shorter encodings
  9660. // are available more often.
  9661. if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9662. isARMLowRegister(Inst.getOperand(2).getReg())) &&
  9663. (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
  9664. Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
  9665. Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
  9666. !HasWideQualifier) {
  9667. unsigned NewOpc;
  9668. switch (Inst.getOpcode()) {
  9669. default: llvm_unreachable("unexpected opcode");
  9670. case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
  9671. case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
  9672. case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
  9673. case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
  9674. }
  9675. MCInst TmpInst;
  9676. TmpInst.setOpcode(NewOpc);
  9677. TmpInst.addOperand(Inst.getOperand(0));
  9678. TmpInst.addOperand(Inst.getOperand(5));
  9679. if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
  9680. TmpInst.addOperand(Inst.getOperand(1));
  9681. TmpInst.addOperand(Inst.getOperand(2));
  9682. } else {
  9683. TmpInst.addOperand(Inst.getOperand(2));
  9684. TmpInst.addOperand(Inst.getOperand(1));
  9685. }
  9686. TmpInst.addOperand(Inst.getOperand(3));
  9687. TmpInst.addOperand(Inst.getOperand(4));
  9688. Inst = TmpInst;
  9689. return true;
  9690. }
  9691. return false;
  9692. case ARM::MVE_VPST:
  9693. case ARM::MVE_VPTv16i8:
  9694. case ARM::MVE_VPTv8i16:
  9695. case ARM::MVE_VPTv4i32:
  9696. case ARM::MVE_VPTv16u8:
  9697. case ARM::MVE_VPTv8u16:
  9698. case ARM::MVE_VPTv4u32:
  9699. case ARM::MVE_VPTv16s8:
  9700. case ARM::MVE_VPTv8s16:
  9701. case ARM::MVE_VPTv4s32:
  9702. case ARM::MVE_VPTv4f32:
  9703. case ARM::MVE_VPTv8f16:
  9704. case ARM::MVE_VPTv16i8r:
  9705. case ARM::MVE_VPTv8i16r:
  9706. case ARM::MVE_VPTv4i32r:
  9707. case ARM::MVE_VPTv16u8r:
  9708. case ARM::MVE_VPTv8u16r:
  9709. case ARM::MVE_VPTv4u32r:
  9710. case ARM::MVE_VPTv16s8r:
  9711. case ARM::MVE_VPTv8s16r:
  9712. case ARM::MVE_VPTv4s32r:
  9713. case ARM::MVE_VPTv4f32r:
  9714. case ARM::MVE_VPTv8f16r: {
  9715. assert(!inVPTBlock() && "Nested VPT blocks are not allowed");
  9716. MCOperand &MO = Inst.getOperand(0);
  9717. VPTState.Mask = MO.getImm();
  9718. VPTState.CurPosition = 0;
  9719. break;
  9720. }
  9721. }
  9722. return false;
  9723. }
  9724. unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
  9725. // 16-bit thumb arithmetic instructions either require or preclude the 'S'
  9726. // suffix depending on whether they're in an IT block or not.
  9727. unsigned Opc = Inst.getOpcode();
  9728. const MCInstrDesc &MCID = MII.get(Opc);
  9729. if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
  9730. assert(MCID.hasOptionalDef() &&
  9731. "optionally flag setting instruction missing optional def operand");
  9732. assert(MCID.NumOperands == Inst.getNumOperands() &&
  9733. "operand count mismatch!");
  9734. // Find the optional-def operand (cc_out).
  9735. unsigned OpNo;
  9736. for (OpNo = 0;
  9737. !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
  9738. ++OpNo)
  9739. ;
  9740. // If we're parsing Thumb1, reject it completely.
  9741. if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
  9742. return Match_RequiresFlagSetting;
  9743. // If we're parsing Thumb2, which form is legal depends on whether we're
  9744. // in an IT block.
  9745. if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
  9746. !inITBlock())
  9747. return Match_RequiresITBlock;
  9748. if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
  9749. inITBlock())
  9750. return Match_RequiresNotITBlock;
  9751. // LSL with zero immediate is not allowed in an IT block
  9752. if (Opc == ARM::tLSLri && Inst.getOperand(3).getImm() == 0 && inITBlock())
  9753. return Match_RequiresNotITBlock;
  9754. } else if (isThumbOne()) {
  9755. // Some high-register supporting Thumb1 encodings only allow both registers
  9756. // to be from r0-r7 when in Thumb2.
  9757. if (Opc == ARM::tADDhirr && !hasV6MOps() &&
  9758. isARMLowRegister(Inst.getOperand(1).getReg()) &&
  9759. isARMLowRegister(Inst.getOperand(2).getReg()))
  9760. return Match_RequiresThumb2;
  9761. // Others only require ARMv6 or later.
  9762. else if (Opc == ARM::tMOVr && !hasV6Ops() &&
  9763. isARMLowRegister(Inst.getOperand(0).getReg()) &&
  9764. isARMLowRegister(Inst.getOperand(1).getReg()))
  9765. return Match_RequiresV6;
  9766. }
  9767. // Before ARMv8 the rules for when SP is allowed in t2MOVr are more complex
  9768. // than the loop below can handle, so it uses the GPRnopc register class and
  9769. // we do SP handling here.
  9770. if (Opc == ARM::t2MOVr && !hasV8Ops())
  9771. {
  9772. // SP as both source and destination is not allowed
  9773. if (Inst.getOperand(0).getReg() == ARM::SP &&
  9774. Inst.getOperand(1).getReg() == ARM::SP)
  9775. return Match_RequiresV8;
  9776. // When flags-setting SP as either source or destination is not allowed
  9777. if (Inst.getOperand(4).getReg() == ARM::CPSR &&
  9778. (Inst.getOperand(0).getReg() == ARM::SP ||
  9779. Inst.getOperand(1).getReg() == ARM::SP))
  9780. return Match_RequiresV8;
  9781. }
  9782. switch (Inst.getOpcode()) {
  9783. case ARM::VMRS:
  9784. case ARM::VMSR:
  9785. case ARM::VMRS_FPCXTS:
  9786. case ARM::VMRS_FPCXTNS:
  9787. case ARM::VMSR_FPCXTS:
  9788. case ARM::VMSR_FPCXTNS:
  9789. case ARM::VMRS_FPSCR_NZCVQC:
  9790. case ARM::VMSR_FPSCR_NZCVQC:
  9791. case ARM::FMSTAT:
  9792. case ARM::VMRS_VPR:
  9793. case ARM::VMRS_P0:
  9794. case ARM::VMSR_VPR:
  9795. case ARM::VMSR_P0:
  9796. // Use of SP for VMRS/VMSR is only allowed in ARM mode with the exception of
  9797. // ARMv8-A.
  9798. if (Inst.getOperand(0).isReg() && Inst.getOperand(0).getReg() == ARM::SP &&
  9799. (isThumb() && !hasV8Ops()))
  9800. return Match_InvalidOperand;
  9801. break;
  9802. case ARM::t2TBB:
  9803. case ARM::t2TBH:
  9804. // Rn = sp is only allowed with ARMv8-A
  9805. if (!hasV8Ops() && (Inst.getOperand(0).getReg() == ARM::SP))
  9806. return Match_RequiresV8;
  9807. break;
  9808. default:
  9809. break;
  9810. }
  9811. for (unsigned I = 0; I < MCID.NumOperands; ++I)
  9812. if (MCID.OpInfo[I].RegClass == ARM::rGPRRegClassID) {
  9813. // rGPRRegClass excludes PC, and also excluded SP before ARMv8
  9814. const auto &Op = Inst.getOperand(I);
  9815. if (!Op.isReg()) {
  9816. // This can happen in awkward cases with tied operands, e.g. a
  9817. // writeback load/store with a complex addressing mode in
  9818. // which there's an output operand corresponding to the
  9819. // updated written-back base register: the Tablegen-generated
  9820. // AsmMatcher will have written a placeholder operand to that
  9821. // slot in the form of an immediate 0, because it can't
  9822. // generate the register part of the complex addressing-mode
  9823. // operand ahead of time.
  9824. continue;
  9825. }
  9826. unsigned Reg = Op.getReg();
  9827. if ((Reg == ARM::SP) && !hasV8Ops())
  9828. return Match_RequiresV8;
  9829. else if (Reg == ARM::PC)
  9830. return Match_InvalidOperand;
  9831. }
  9832. return Match_Success;
  9833. }
  9834. namespace llvm {
  9835. template <> inline bool IsCPSRDead<MCInst>(const MCInst *Instr) {
  9836. return true; // In an assembly source, no need to second-guess
  9837. }
  9838. } // end namespace llvm
  9839. // Returns true if Inst is unpredictable if it is in and IT block, but is not
  9840. // the last instruction in the block.
  9841. bool ARMAsmParser::isITBlockTerminator(MCInst &Inst) const {
  9842. const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
  9843. // All branch & call instructions terminate IT blocks with the exception of
  9844. // SVC.
  9845. if (MCID.isTerminator() || (MCID.isCall() && Inst.getOpcode() != ARM::tSVC) ||
  9846. MCID.isReturn() || MCID.isBranch() || MCID.isIndirectBranch())
  9847. return true;
  9848. // Any arithmetic instruction which writes to the PC also terminates the IT
  9849. // block.
  9850. if (MCID.hasDefOfPhysReg(Inst, ARM::PC, *MRI))
  9851. return true;
  9852. return false;
  9853. }
  9854. unsigned ARMAsmParser::MatchInstruction(OperandVector &Operands, MCInst &Inst,
  9855. SmallVectorImpl<NearMissInfo> &NearMisses,
  9856. bool MatchingInlineAsm,
  9857. bool &EmitInITBlock,
  9858. MCStreamer &Out) {
  9859. // If we can't use an implicit IT block here, just match as normal.
  9860. if (inExplicitITBlock() || !isThumbTwo() || !useImplicitITThumb())
  9861. return MatchInstructionImpl(Operands, Inst, &NearMisses, MatchingInlineAsm);
  9862. // Try to match the instruction in an extension of the current IT block (if
  9863. // there is one).
  9864. if (inImplicitITBlock()) {
  9865. extendImplicitITBlock(ITState.Cond);
  9866. if (MatchInstructionImpl(Operands, Inst, nullptr, MatchingInlineAsm) ==
  9867. Match_Success) {
  9868. // The match succeded, but we still have to check that the instruction is
  9869. // valid in this implicit IT block.
  9870. const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
  9871. if (MCID.isPredicable()) {
  9872. ARMCC::CondCodes InstCond =
  9873. (ARMCC::CondCodes)Inst.getOperand(MCID.findFirstPredOperandIdx())
  9874. .getImm();
  9875. ARMCC::CondCodes ITCond = currentITCond();
  9876. if (InstCond == ITCond) {
  9877. EmitInITBlock = true;
  9878. return Match_Success;
  9879. } else if (InstCond == ARMCC::getOppositeCondition(ITCond)) {
  9880. invertCurrentITCondition();
  9881. EmitInITBlock = true;
  9882. return Match_Success;
  9883. }
  9884. }
  9885. }
  9886. rewindImplicitITPosition();
  9887. }
  9888. // Finish the current IT block, and try to match outside any IT block.
  9889. flushPendingInstructions(Out);
  9890. unsigned PlainMatchResult =
  9891. MatchInstructionImpl(Operands, Inst, &NearMisses, MatchingInlineAsm);
  9892. if (PlainMatchResult == Match_Success) {
  9893. const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
  9894. if (MCID.isPredicable()) {
  9895. ARMCC::CondCodes InstCond =
  9896. (ARMCC::CondCodes)Inst.getOperand(MCID.findFirstPredOperandIdx())
  9897. .getImm();
  9898. // Some forms of the branch instruction have their own condition code
  9899. // fields, so can be conditionally executed without an IT block.
  9900. if (Inst.getOpcode() == ARM::tBcc || Inst.getOpcode() == ARM::t2Bcc) {
  9901. EmitInITBlock = false;
  9902. return Match_Success;
  9903. }
  9904. if (InstCond == ARMCC::AL) {
  9905. EmitInITBlock = false;
  9906. return Match_Success;
  9907. }
  9908. } else {
  9909. EmitInITBlock = false;
  9910. return Match_Success;
  9911. }
  9912. }
  9913. // Try to match in a new IT block. The matcher doesn't check the actual
  9914. // condition, so we create an IT block with a dummy condition, and fix it up
  9915. // once we know the actual condition.
  9916. startImplicitITBlock();
  9917. if (MatchInstructionImpl(Operands, Inst, nullptr, MatchingInlineAsm) ==
  9918. Match_Success) {
  9919. const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
  9920. if (MCID.isPredicable()) {
  9921. ITState.Cond =
  9922. (ARMCC::CondCodes)Inst.getOperand(MCID.findFirstPredOperandIdx())
  9923. .getImm();
  9924. EmitInITBlock = true;
  9925. return Match_Success;
  9926. }
  9927. }
  9928. discardImplicitITBlock();
  9929. // If none of these succeed, return the error we got when trying to match
  9930. // outside any IT blocks.
  9931. EmitInITBlock = false;
  9932. return PlainMatchResult;
  9933. }
  9934. static std::string ARMMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS,
  9935. unsigned VariantID = 0);
  9936. static const char *getSubtargetFeatureName(uint64_t Val);
  9937. bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
  9938. OperandVector &Operands,
  9939. MCStreamer &Out, uint64_t &ErrorInfo,
  9940. bool MatchingInlineAsm) {
  9941. MCInst Inst;
  9942. unsigned MatchResult;
  9943. bool PendConditionalInstruction = false;
  9944. SmallVector<NearMissInfo, 4> NearMisses;
  9945. MatchResult = MatchInstruction(Operands, Inst, NearMisses, MatchingInlineAsm,
  9946. PendConditionalInstruction, Out);
  9947. switch (MatchResult) {
  9948. case Match_Success:
  9949. LLVM_DEBUG(dbgs() << "Parsed as: ";
  9950. Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode()));
  9951. dbgs() << "\n");
  9952. // Context sensitive operand constraints aren't handled by the matcher,
  9953. // so check them here.
  9954. if (validateInstruction(Inst, Operands)) {
  9955. // Still progress the IT block, otherwise one wrong condition causes
  9956. // nasty cascading errors.
  9957. forwardITPosition();
  9958. forwardVPTPosition();
  9959. return true;
  9960. }
  9961. { // processInstruction() updates inITBlock state, we need to save it away
  9962. bool wasInITBlock = inITBlock();
  9963. // Some instructions need post-processing to, for example, tweak which
  9964. // encoding is selected. Loop on it while changes happen so the
  9965. // individual transformations can chain off each other. E.g.,
  9966. // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
  9967. while (processInstruction(Inst, Operands, Out))
  9968. LLVM_DEBUG(dbgs() << "Changed to: ";
  9969. Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode()));
  9970. dbgs() << "\n");
  9971. // Only after the instruction is fully processed, we can validate it
  9972. if (wasInITBlock && hasV8Ops() && isThumb() &&
  9973. !isV8EligibleForIT(&Inst) && !getTargetOptions().MCNoDeprecatedWarn) {
  9974. Warning(IDLoc, "deprecated instruction in IT block");
  9975. }
  9976. }
  9977. // Only move forward at the very end so that everything in validate
  9978. // and process gets a consistent answer about whether we're in an IT
  9979. // block.
  9980. forwardITPosition();
  9981. forwardVPTPosition();
  9982. // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
  9983. // doesn't actually encode.
  9984. if (Inst.getOpcode() == ARM::ITasm)
  9985. return false;
  9986. Inst.setLoc(IDLoc);
  9987. if (PendConditionalInstruction) {
  9988. PendingConditionalInsts.push_back(Inst);
  9989. if (isITBlockFull() || isITBlockTerminator(Inst))
  9990. flushPendingInstructions(Out);
  9991. } else {
  9992. Out.emitInstruction(Inst, getSTI());
  9993. }
  9994. return false;
  9995. case Match_NearMisses:
  9996. ReportNearMisses(NearMisses, IDLoc, Operands);
  9997. return true;
  9998. case Match_MnemonicFail: {
  9999. FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
  10000. std::string Suggestion = ARMMnemonicSpellCheck(
  10001. ((ARMOperand &)*Operands[0]).getToken(), FBS);
  10002. return Error(IDLoc, "invalid instruction" + Suggestion,
  10003. ((ARMOperand &)*Operands[0]).getLocRange());
  10004. }
  10005. }
  10006. llvm_unreachable("Implement any new match types added!");
  10007. }
  10008. /// parseDirective parses the arm specific directives
  10009. bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
  10010. const MCContext::Environment Format = getContext().getObjectFileType();
  10011. bool IsMachO = Format == MCContext::IsMachO;
  10012. bool IsCOFF = Format == MCContext::IsCOFF;
  10013. std::string IDVal = DirectiveID.getIdentifier().lower();
  10014. if (IDVal == ".word")
  10015. parseLiteralValues(4, DirectiveID.getLoc());
  10016. else if (IDVal == ".short" || IDVal == ".hword")
  10017. parseLiteralValues(2, DirectiveID.getLoc());
  10018. else if (IDVal == ".thumb")
  10019. parseDirectiveThumb(DirectiveID.getLoc());
  10020. else if (IDVal == ".arm")
  10021. parseDirectiveARM(DirectiveID.getLoc());
  10022. else if (IDVal == ".thumb_func")
  10023. parseDirectiveThumbFunc(DirectiveID.getLoc());
  10024. else if (IDVal == ".code")
  10025. parseDirectiveCode(DirectiveID.getLoc());
  10026. else if (IDVal == ".syntax")
  10027. parseDirectiveSyntax(DirectiveID.getLoc());
  10028. else if (IDVal == ".unreq")
  10029. parseDirectiveUnreq(DirectiveID.getLoc());
  10030. else if (IDVal == ".fnend")
  10031. parseDirectiveFnEnd(DirectiveID.getLoc());
  10032. else if (IDVal == ".cantunwind")
  10033. parseDirectiveCantUnwind(DirectiveID.getLoc());
  10034. else if (IDVal == ".personality")
  10035. parseDirectivePersonality(DirectiveID.getLoc());
  10036. else if (IDVal == ".handlerdata")
  10037. parseDirectiveHandlerData(DirectiveID.getLoc());
  10038. else if (IDVal == ".setfp")
  10039. parseDirectiveSetFP(DirectiveID.getLoc());
  10040. else if (IDVal == ".pad")
  10041. parseDirectivePad(DirectiveID.getLoc());
  10042. else if (IDVal == ".save")
  10043. parseDirectiveRegSave(DirectiveID.getLoc(), false);
  10044. else if (IDVal == ".vsave")
  10045. parseDirectiveRegSave(DirectiveID.getLoc(), true);
  10046. else if (IDVal == ".ltorg" || IDVal == ".pool")
  10047. parseDirectiveLtorg(DirectiveID.getLoc());
  10048. else if (IDVal == ".even")
  10049. parseDirectiveEven(DirectiveID.getLoc());
  10050. else if (IDVal == ".personalityindex")
  10051. parseDirectivePersonalityIndex(DirectiveID.getLoc());
  10052. else if (IDVal == ".unwind_raw")
  10053. parseDirectiveUnwindRaw(DirectiveID.getLoc());
  10054. else if (IDVal == ".movsp")
  10055. parseDirectiveMovSP(DirectiveID.getLoc());
  10056. else if (IDVal == ".arch_extension")
  10057. parseDirectiveArchExtension(DirectiveID.getLoc());
  10058. else if (IDVal == ".align")
  10059. return parseDirectiveAlign(DirectiveID.getLoc()); // Use Generic on failure.
  10060. else if (IDVal == ".thumb_set")
  10061. parseDirectiveThumbSet(DirectiveID.getLoc());
  10062. else if (IDVal == ".inst")
  10063. parseDirectiveInst(DirectiveID.getLoc());
  10064. else if (IDVal == ".inst.n")
  10065. parseDirectiveInst(DirectiveID.getLoc(), 'n');
  10066. else if (IDVal == ".inst.w")
  10067. parseDirectiveInst(DirectiveID.getLoc(), 'w');
  10068. else if (!IsMachO && !IsCOFF) {
  10069. if (IDVal == ".arch")
  10070. parseDirectiveArch(DirectiveID.getLoc());
  10071. else if (IDVal == ".cpu")
  10072. parseDirectiveCPU(DirectiveID.getLoc());
  10073. else if (IDVal == ".eabi_attribute")
  10074. parseDirectiveEabiAttr(DirectiveID.getLoc());
  10075. else if (IDVal == ".fpu")
  10076. parseDirectiveFPU(DirectiveID.getLoc());
  10077. else if (IDVal == ".fnstart")
  10078. parseDirectiveFnStart(DirectiveID.getLoc());
  10079. else if (IDVal == ".object_arch")
  10080. parseDirectiveObjectArch(DirectiveID.getLoc());
  10081. else if (IDVal == ".tlsdescseq")
  10082. parseDirectiveTLSDescSeq(DirectiveID.getLoc());
  10083. else
  10084. return true;
  10085. } else
  10086. return true;
  10087. return false;
  10088. }
  10089. /// parseLiteralValues
  10090. /// ::= .hword expression [, expression]*
  10091. /// ::= .short expression [, expression]*
  10092. /// ::= .word expression [, expression]*
  10093. bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
  10094. auto parseOne = [&]() -> bool {
  10095. const MCExpr *Value;
  10096. if (getParser().parseExpression(Value))
  10097. return true;
  10098. getParser().getStreamer().emitValue(Value, Size, L);
  10099. return false;
  10100. };
  10101. return (parseMany(parseOne));
  10102. }
  10103. /// parseDirectiveThumb
  10104. /// ::= .thumb
  10105. bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
  10106. if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive") ||
  10107. check(!hasThumb(), L, "target does not support Thumb mode"))
  10108. return true;
  10109. if (!isThumb())
  10110. SwitchMode();
  10111. getParser().getStreamer().emitAssemblerFlag(MCAF_Code16);
  10112. return false;
  10113. }
  10114. /// parseDirectiveARM
  10115. /// ::= .arm
  10116. bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
  10117. if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive") ||
  10118. check(!hasARM(), L, "target does not support ARM mode"))
  10119. return true;
  10120. if (isThumb())
  10121. SwitchMode();
  10122. getParser().getStreamer().emitAssemblerFlag(MCAF_Code32);
  10123. return false;
  10124. }
  10125. void ARMAsmParser::doBeforeLabelEmit(MCSymbol *Symbol) {
  10126. // We need to flush the current implicit IT block on a label, because it is
  10127. // not legal to branch into an IT block.
  10128. flushPendingInstructions(getStreamer());
  10129. }
  10130. void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
  10131. if (NextSymbolIsThumb) {
  10132. getParser().getStreamer().emitThumbFunc(Symbol);
  10133. NextSymbolIsThumb = false;
  10134. }
  10135. }
  10136. /// parseDirectiveThumbFunc
  10137. /// ::= .thumbfunc symbol_name
  10138. bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
  10139. MCAsmParser &Parser = getParser();
  10140. const auto Format = getContext().getObjectFileType();
  10141. bool IsMachO = Format == MCContext::IsMachO;
  10142. // Darwin asm has (optionally) function name after .thumb_func direction
  10143. // ELF doesn't
  10144. if (IsMachO) {
  10145. if (Parser.getTok().is(AsmToken::Identifier) ||
  10146. Parser.getTok().is(AsmToken::String)) {
  10147. MCSymbol *Func = getParser().getContext().getOrCreateSymbol(
  10148. Parser.getTok().getIdentifier());
  10149. getParser().getStreamer().emitThumbFunc(Func);
  10150. Parser.Lex();
  10151. if (parseToken(AsmToken::EndOfStatement,
  10152. "unexpected token in '.thumb_func' directive"))
  10153. return true;
  10154. return false;
  10155. }
  10156. }
  10157. if (parseToken(AsmToken::EndOfStatement,
  10158. "unexpected token in '.thumb_func' directive"))
  10159. return true;
  10160. // .thumb_func implies .thumb
  10161. if (!isThumb())
  10162. SwitchMode();
  10163. getParser().getStreamer().emitAssemblerFlag(MCAF_Code16);
  10164. NextSymbolIsThumb = true;
  10165. return false;
  10166. }
  10167. /// parseDirectiveSyntax
  10168. /// ::= .syntax unified | divided
  10169. bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
  10170. MCAsmParser &Parser = getParser();
  10171. const AsmToken &Tok = Parser.getTok();
  10172. if (Tok.isNot(AsmToken::Identifier)) {
  10173. Error(L, "unexpected token in .syntax directive");
  10174. return false;
  10175. }
  10176. StringRef Mode = Tok.getString();
  10177. Parser.Lex();
  10178. if (check(Mode == "divided" || Mode == "DIVIDED", L,
  10179. "'.syntax divided' arm assembly not supported") ||
  10180. check(Mode != "unified" && Mode != "UNIFIED", L,
  10181. "unrecognized syntax mode in .syntax directive") ||
  10182. parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
  10183. return true;
  10184. // TODO tell the MC streamer the mode
  10185. // getParser().getStreamer().Emit???();
  10186. return false;
  10187. }
  10188. /// parseDirectiveCode
  10189. /// ::= .code 16 | 32
  10190. bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
  10191. MCAsmParser &Parser = getParser();
  10192. const AsmToken &Tok = Parser.getTok();
  10193. if (Tok.isNot(AsmToken::Integer))
  10194. return Error(L, "unexpected token in .code directive");
  10195. int64_t Val = Parser.getTok().getIntVal();
  10196. if (Val != 16 && Val != 32) {
  10197. Error(L, "invalid operand to .code directive");
  10198. return false;
  10199. }
  10200. Parser.Lex();
  10201. if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
  10202. return true;
  10203. if (Val == 16) {
  10204. if (!hasThumb())
  10205. return Error(L, "target does not support Thumb mode");
  10206. if (!isThumb())
  10207. SwitchMode();
  10208. getParser().getStreamer().emitAssemblerFlag(MCAF_Code16);
  10209. } else {
  10210. if (!hasARM())
  10211. return Error(L, "target does not support ARM mode");
  10212. if (isThumb())
  10213. SwitchMode();
  10214. getParser().getStreamer().emitAssemblerFlag(MCAF_Code32);
  10215. }
  10216. return false;
  10217. }
  10218. /// parseDirectiveReq
  10219. /// ::= name .req registername
  10220. bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
  10221. MCAsmParser &Parser = getParser();
  10222. Parser.Lex(); // Eat the '.req' token.
  10223. unsigned Reg;
  10224. SMLoc SRegLoc, ERegLoc;
  10225. if (check(ParseRegister(Reg, SRegLoc, ERegLoc), SRegLoc,
  10226. "register name expected") ||
  10227. parseToken(AsmToken::EndOfStatement,
  10228. "unexpected input in .req directive."))
  10229. return true;
  10230. if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg)
  10231. return Error(SRegLoc,
  10232. "redefinition of '" + Name + "' does not match original.");
  10233. return false;
  10234. }
  10235. /// parseDirectiveUneq
  10236. /// ::= .unreq registername
  10237. bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
  10238. MCAsmParser &Parser = getParser();
  10239. if (Parser.getTok().isNot(AsmToken::Identifier))
  10240. return Error(L, "unexpected input in .unreq directive.");
  10241. RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
  10242. Parser.Lex(); // Eat the identifier.
  10243. if (parseToken(AsmToken::EndOfStatement,
  10244. "unexpected input in '.unreq' directive"))
  10245. return true;
  10246. return false;
  10247. }
  10248. // After changing arch/CPU, try to put the ARM/Thumb mode back to what it was
  10249. // before, if supported by the new target, or emit mapping symbols for the mode
  10250. // switch.
  10251. void ARMAsmParser::FixModeAfterArchChange(bool WasThumb, SMLoc Loc) {
  10252. if (WasThumb != isThumb()) {
  10253. if (WasThumb && hasThumb()) {
  10254. // Stay in Thumb mode
  10255. SwitchMode();
  10256. } else if (!WasThumb && hasARM()) {
  10257. // Stay in ARM mode
  10258. SwitchMode();
  10259. } else {
  10260. // Mode switch forced, because the new arch doesn't support the old mode.
  10261. getParser().getStreamer().emitAssemblerFlag(isThumb() ? MCAF_Code16
  10262. : MCAF_Code32);
  10263. // Warn about the implcit mode switch. GAS does not switch modes here,
  10264. // but instead stays in the old mode, reporting an error on any following
  10265. // instructions as the mode does not exist on the target.
  10266. Warning(Loc, Twine("new target does not support ") +
  10267. (WasThumb ? "thumb" : "arm") + " mode, switching to " +
  10268. (!WasThumb ? "thumb" : "arm") + " mode");
  10269. }
  10270. }
  10271. }
  10272. /// parseDirectiveArch
  10273. /// ::= .arch token
  10274. bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
  10275. StringRef Arch = getParser().parseStringToEndOfStatement().trim();
  10276. ARM::ArchKind ID = ARM::parseArch(Arch);
  10277. if (ID == ARM::ArchKind::INVALID)
  10278. return Error(L, "Unknown arch name");
  10279. bool WasThumb = isThumb();
  10280. Triple T;
  10281. MCSubtargetInfo &STI = copySTI();
  10282. STI.setDefaultFeatures("", /*TuneCPU*/ "",
  10283. ("+" + ARM::getArchName(ID)).str());
  10284. setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
  10285. FixModeAfterArchChange(WasThumb, L);
  10286. getTargetStreamer().emitArch(ID);
  10287. return false;
  10288. }
  10289. /// parseDirectiveEabiAttr
  10290. /// ::= .eabi_attribute int, int [, "str"]
  10291. /// ::= .eabi_attribute Tag_name, int [, "str"]
  10292. bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
  10293. MCAsmParser &Parser = getParser();
  10294. int64_t Tag;
  10295. SMLoc TagLoc;
  10296. TagLoc = Parser.getTok().getLoc();
  10297. if (Parser.getTok().is(AsmToken::Identifier)) {
  10298. StringRef Name = Parser.getTok().getIdentifier();
  10299. Optional<unsigned> Ret = ELFAttrs::attrTypeFromString(
  10300. Name, ARMBuildAttrs::getARMAttributeTags());
  10301. if (!Ret.hasValue()) {
  10302. Error(TagLoc, "attribute name not recognised: " + Name);
  10303. return false;
  10304. }
  10305. Tag = Ret.getValue();
  10306. Parser.Lex();
  10307. } else {
  10308. const MCExpr *AttrExpr;
  10309. TagLoc = Parser.getTok().getLoc();
  10310. if (Parser.parseExpression(AttrExpr))
  10311. return true;
  10312. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
  10313. if (check(!CE, TagLoc, "expected numeric constant"))
  10314. return true;
  10315. Tag = CE->getValue();
  10316. }
  10317. if (Parser.parseToken(AsmToken::Comma, "comma expected"))
  10318. return true;
  10319. StringRef StringValue = "";
  10320. bool IsStringValue = false;
  10321. int64_t IntegerValue = 0;
  10322. bool IsIntegerValue = false;
  10323. if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
  10324. IsStringValue = true;
  10325. else if (Tag == ARMBuildAttrs::compatibility) {
  10326. IsStringValue = true;
  10327. IsIntegerValue = true;
  10328. } else if (Tag < 32 || Tag % 2 == 0)
  10329. IsIntegerValue = true;
  10330. else if (Tag % 2 == 1)
  10331. IsStringValue = true;
  10332. else
  10333. llvm_unreachable("invalid tag type");
  10334. if (IsIntegerValue) {
  10335. const MCExpr *ValueExpr;
  10336. SMLoc ValueExprLoc = Parser.getTok().getLoc();
  10337. if (Parser.parseExpression(ValueExpr))
  10338. return true;
  10339. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
  10340. if (!CE)
  10341. return Error(ValueExprLoc, "expected numeric constant");
  10342. IntegerValue = CE->getValue();
  10343. }
  10344. if (Tag == ARMBuildAttrs::compatibility) {
  10345. if (Parser.parseToken(AsmToken::Comma, "comma expected"))
  10346. return true;
  10347. }
  10348. if (IsStringValue) {
  10349. if (Parser.getTok().isNot(AsmToken::String))
  10350. return Error(Parser.getTok().getLoc(), "bad string constant");
  10351. StringValue = Parser.getTok().getStringContents();
  10352. Parser.Lex();
  10353. }
  10354. if (Parser.parseToken(AsmToken::EndOfStatement,
  10355. "unexpected token in '.eabi_attribute' directive"))
  10356. return true;
  10357. if (IsIntegerValue && IsStringValue) {
  10358. assert(Tag == ARMBuildAttrs::compatibility);
  10359. getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
  10360. } else if (IsIntegerValue)
  10361. getTargetStreamer().emitAttribute(Tag, IntegerValue);
  10362. else if (IsStringValue)
  10363. getTargetStreamer().emitTextAttribute(Tag, StringValue);
  10364. return false;
  10365. }
  10366. /// parseDirectiveCPU
  10367. /// ::= .cpu str
  10368. bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
  10369. StringRef CPU = getParser().parseStringToEndOfStatement().trim();
  10370. getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
  10371. // FIXME: This is using table-gen data, but should be moved to
  10372. // ARMTargetParser once that is table-gen'd.
  10373. if (!getSTI().isCPUStringValid(CPU))
  10374. return Error(L, "Unknown CPU name");
  10375. bool WasThumb = isThumb();
  10376. MCSubtargetInfo &STI = copySTI();
  10377. STI.setDefaultFeatures(CPU, /*TuneCPU*/ CPU, "");
  10378. setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
  10379. FixModeAfterArchChange(WasThumb, L);
  10380. return false;
  10381. }
  10382. /// parseDirectiveFPU
  10383. /// ::= .fpu str
  10384. bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
  10385. SMLoc FPUNameLoc = getTok().getLoc();
  10386. StringRef FPU = getParser().parseStringToEndOfStatement().trim();
  10387. unsigned ID = ARM::parseFPU(FPU);
  10388. std::vector<StringRef> Features;
  10389. if (!ARM::getFPUFeatures(ID, Features))
  10390. return Error(FPUNameLoc, "Unknown FPU name");
  10391. MCSubtargetInfo &STI = copySTI();
  10392. for (auto Feature : Features)
  10393. STI.ApplyFeatureFlag(Feature);
  10394. setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
  10395. getTargetStreamer().emitFPU(ID);
  10396. return false;
  10397. }
  10398. /// parseDirectiveFnStart
  10399. /// ::= .fnstart
  10400. bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
  10401. if (parseToken(AsmToken::EndOfStatement,
  10402. "unexpected token in '.fnstart' directive"))
  10403. return true;
  10404. if (UC.hasFnStart()) {
  10405. Error(L, ".fnstart starts before the end of previous one");
  10406. UC.emitFnStartLocNotes();
  10407. return true;
  10408. }
  10409. // Reset the unwind directives parser state
  10410. UC.reset();
  10411. getTargetStreamer().emitFnStart();
  10412. UC.recordFnStart(L);
  10413. return false;
  10414. }
  10415. /// parseDirectiveFnEnd
  10416. /// ::= .fnend
  10417. bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
  10418. if (parseToken(AsmToken::EndOfStatement,
  10419. "unexpected token in '.fnend' directive"))
  10420. return true;
  10421. // Check the ordering of unwind directives
  10422. if (!UC.hasFnStart())
  10423. return Error(L, ".fnstart must precede .fnend directive");
  10424. // Reset the unwind directives parser state
  10425. getTargetStreamer().emitFnEnd();
  10426. UC.reset();
  10427. return false;
  10428. }
  10429. /// parseDirectiveCantUnwind
  10430. /// ::= .cantunwind
  10431. bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
  10432. if (parseToken(AsmToken::EndOfStatement,
  10433. "unexpected token in '.cantunwind' directive"))
  10434. return true;
  10435. UC.recordCantUnwind(L);
  10436. // Check the ordering of unwind directives
  10437. if (check(!UC.hasFnStart(), L, ".fnstart must precede .cantunwind directive"))
  10438. return true;
  10439. if (UC.hasHandlerData()) {
  10440. Error(L, ".cantunwind can't be used with .handlerdata directive");
  10441. UC.emitHandlerDataLocNotes();
  10442. return true;
  10443. }
  10444. if (UC.hasPersonality()) {
  10445. Error(L, ".cantunwind can't be used with .personality directive");
  10446. UC.emitPersonalityLocNotes();
  10447. return true;
  10448. }
  10449. getTargetStreamer().emitCantUnwind();
  10450. return false;
  10451. }
  10452. /// parseDirectivePersonality
  10453. /// ::= .personality name
  10454. bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
  10455. MCAsmParser &Parser = getParser();
  10456. bool HasExistingPersonality = UC.hasPersonality();
  10457. // Parse the name of the personality routine
  10458. if (Parser.getTok().isNot(AsmToken::Identifier))
  10459. return Error(L, "unexpected input in .personality directive.");
  10460. StringRef Name(Parser.getTok().getIdentifier());
  10461. Parser.Lex();
  10462. if (parseToken(AsmToken::EndOfStatement,
  10463. "unexpected token in '.personality' directive"))
  10464. return true;
  10465. UC.recordPersonality(L);
  10466. // Check the ordering of unwind directives
  10467. if (!UC.hasFnStart())
  10468. return Error(L, ".fnstart must precede .personality directive");
  10469. if (UC.cantUnwind()) {
  10470. Error(L, ".personality can't be used with .cantunwind directive");
  10471. UC.emitCantUnwindLocNotes();
  10472. return true;
  10473. }
  10474. if (UC.hasHandlerData()) {
  10475. Error(L, ".personality must precede .handlerdata directive");
  10476. UC.emitHandlerDataLocNotes();
  10477. return true;
  10478. }
  10479. if (HasExistingPersonality) {
  10480. Error(L, "multiple personality directives");
  10481. UC.emitPersonalityLocNotes();
  10482. return true;
  10483. }
  10484. MCSymbol *PR = getParser().getContext().getOrCreateSymbol(Name);
  10485. getTargetStreamer().emitPersonality(PR);
  10486. return false;
  10487. }
  10488. /// parseDirectiveHandlerData
  10489. /// ::= .handlerdata
  10490. bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
  10491. if (parseToken(AsmToken::EndOfStatement,
  10492. "unexpected token in '.handlerdata' directive"))
  10493. return true;
  10494. UC.recordHandlerData(L);
  10495. // Check the ordering of unwind directives
  10496. if (!UC.hasFnStart())
  10497. return Error(L, ".fnstart must precede .personality directive");
  10498. if (UC.cantUnwind()) {
  10499. Error(L, ".handlerdata can't be used with .cantunwind directive");
  10500. UC.emitCantUnwindLocNotes();
  10501. return true;
  10502. }
  10503. getTargetStreamer().emitHandlerData();
  10504. return false;
  10505. }
  10506. /// parseDirectiveSetFP
  10507. /// ::= .setfp fpreg, spreg [, offset]
  10508. bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
  10509. MCAsmParser &Parser = getParser();
  10510. // Check the ordering of unwind directives
  10511. if (check(!UC.hasFnStart(), L, ".fnstart must precede .setfp directive") ||
  10512. check(UC.hasHandlerData(), L,
  10513. ".setfp must precede .handlerdata directive"))
  10514. return true;
  10515. // Parse fpreg
  10516. SMLoc FPRegLoc = Parser.getTok().getLoc();
  10517. int FPReg = tryParseRegister();
  10518. if (check(FPReg == -1, FPRegLoc, "frame pointer register expected") ||
  10519. Parser.parseToken(AsmToken::Comma, "comma expected"))
  10520. return true;
  10521. // Parse spreg
  10522. SMLoc SPRegLoc = Parser.getTok().getLoc();
  10523. int SPReg = tryParseRegister();
  10524. if (check(SPReg == -1, SPRegLoc, "stack pointer register expected") ||
  10525. check(SPReg != ARM::SP && SPReg != UC.getFPReg(), SPRegLoc,
  10526. "register should be either $sp or the latest fp register"))
  10527. return true;
  10528. // Update the frame pointer register
  10529. UC.saveFPReg(FPReg);
  10530. // Parse offset
  10531. int64_t Offset = 0;
  10532. if (Parser.parseOptionalToken(AsmToken::Comma)) {
  10533. if (Parser.getTok().isNot(AsmToken::Hash) &&
  10534. Parser.getTok().isNot(AsmToken::Dollar))
  10535. return Error(Parser.getTok().getLoc(), "'#' expected");
  10536. Parser.Lex(); // skip hash token.
  10537. const MCExpr *OffsetExpr;
  10538. SMLoc ExLoc = Parser.getTok().getLoc();
  10539. SMLoc EndLoc;
  10540. if (getParser().parseExpression(OffsetExpr, EndLoc))
  10541. return Error(ExLoc, "malformed setfp offset");
  10542. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
  10543. if (check(!CE, ExLoc, "setfp offset must be an immediate"))
  10544. return true;
  10545. Offset = CE->getValue();
  10546. }
  10547. if (Parser.parseToken(AsmToken::EndOfStatement))
  10548. return true;
  10549. getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
  10550. static_cast<unsigned>(SPReg), Offset);
  10551. return false;
  10552. }
  10553. /// parseDirective
  10554. /// ::= .pad offset
  10555. bool ARMAsmParser::parseDirectivePad(SMLoc L) {
  10556. MCAsmParser &Parser = getParser();
  10557. // Check the ordering of unwind directives
  10558. if (!UC.hasFnStart())
  10559. return Error(L, ".fnstart must precede .pad directive");
  10560. if (UC.hasHandlerData())
  10561. return Error(L, ".pad must precede .handlerdata directive");
  10562. // Parse the offset
  10563. if (Parser.getTok().isNot(AsmToken::Hash) &&
  10564. Parser.getTok().isNot(AsmToken::Dollar))
  10565. return Error(Parser.getTok().getLoc(), "'#' expected");
  10566. Parser.Lex(); // skip hash token.
  10567. const MCExpr *OffsetExpr;
  10568. SMLoc ExLoc = Parser.getTok().getLoc();
  10569. SMLoc EndLoc;
  10570. if (getParser().parseExpression(OffsetExpr, EndLoc))
  10571. return Error(ExLoc, "malformed pad offset");
  10572. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
  10573. if (!CE)
  10574. return Error(ExLoc, "pad offset must be an immediate");
  10575. if (parseToken(AsmToken::EndOfStatement,
  10576. "unexpected token in '.pad' directive"))
  10577. return true;
  10578. getTargetStreamer().emitPad(CE->getValue());
  10579. return false;
  10580. }
  10581. /// parseDirectiveRegSave
  10582. /// ::= .save { registers }
  10583. /// ::= .vsave { registers }
  10584. bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
  10585. // Check the ordering of unwind directives
  10586. if (!UC.hasFnStart())
  10587. return Error(L, ".fnstart must precede .save or .vsave directives");
  10588. if (UC.hasHandlerData())
  10589. return Error(L, ".save or .vsave must precede .handlerdata directive");
  10590. // RAII object to make sure parsed operands are deleted.
  10591. SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
  10592. // Parse the register list
  10593. if (parseRegisterList(Operands, true, true) ||
  10594. parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
  10595. return true;
  10596. ARMOperand &Op = (ARMOperand &)*Operands[0];
  10597. if (!IsVector && !Op.isRegList())
  10598. return Error(L, ".save expects GPR registers");
  10599. if (IsVector && !Op.isDPRRegList())
  10600. return Error(L, ".vsave expects DPR registers");
  10601. getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
  10602. return false;
  10603. }
  10604. /// parseDirectiveInst
  10605. /// ::= .inst opcode [, ...]
  10606. /// ::= .inst.n opcode [, ...]
  10607. /// ::= .inst.w opcode [, ...]
  10608. bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
  10609. int Width = 4;
  10610. if (isThumb()) {
  10611. switch (Suffix) {
  10612. case 'n':
  10613. Width = 2;
  10614. break;
  10615. case 'w':
  10616. break;
  10617. default:
  10618. Width = 0;
  10619. break;
  10620. }
  10621. } else {
  10622. if (Suffix)
  10623. return Error(Loc, "width suffixes are invalid in ARM mode");
  10624. }
  10625. auto parseOne = [&]() -> bool {
  10626. const MCExpr *Expr;
  10627. if (getParser().parseExpression(Expr))
  10628. return true;
  10629. const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
  10630. if (!Value) {
  10631. return Error(Loc, "expected constant expression");
  10632. }
  10633. char CurSuffix = Suffix;
  10634. switch (Width) {
  10635. case 2:
  10636. if (Value->getValue() > 0xffff)
  10637. return Error(Loc, "inst.n operand is too big, use inst.w instead");
  10638. break;
  10639. case 4:
  10640. if (Value->getValue() > 0xffffffff)
  10641. return Error(Loc, StringRef(Suffix ? "inst.w" : "inst") +
  10642. " operand is too big");
  10643. break;
  10644. case 0:
  10645. // Thumb mode, no width indicated. Guess from the opcode, if possible.
  10646. if (Value->getValue() < 0xe800)
  10647. CurSuffix = 'n';
  10648. else if (Value->getValue() >= 0xe8000000)
  10649. CurSuffix = 'w';
  10650. else
  10651. return Error(Loc, "cannot determine Thumb instruction size, "
  10652. "use inst.n/inst.w instead");
  10653. break;
  10654. default:
  10655. llvm_unreachable("only supported widths are 2 and 4");
  10656. }
  10657. getTargetStreamer().emitInst(Value->getValue(), CurSuffix);
  10658. return false;
  10659. };
  10660. if (parseOptionalToken(AsmToken::EndOfStatement))
  10661. return Error(Loc, "expected expression following directive");
  10662. if (parseMany(parseOne))
  10663. return true;
  10664. return false;
  10665. }
  10666. /// parseDirectiveLtorg
  10667. /// ::= .ltorg | .pool
  10668. bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
  10669. if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
  10670. return true;
  10671. getTargetStreamer().emitCurrentConstantPool();
  10672. return false;
  10673. }
  10674. bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
  10675. const MCSection *Section = getStreamer().getCurrentSectionOnly();
  10676. if (parseToken(AsmToken::EndOfStatement, "unexpected token in directive"))
  10677. return true;
  10678. if (!Section) {
  10679. getStreamer().initSections(false, getSTI());
  10680. Section = getStreamer().getCurrentSectionOnly();
  10681. }
  10682. assert(Section && "must have section to emit alignment");
  10683. if (Section->UseCodeAlign())
  10684. getStreamer().emitCodeAlignment(2, &getSTI());
  10685. else
  10686. getStreamer().emitValueToAlignment(2);
  10687. return false;
  10688. }
  10689. /// parseDirectivePersonalityIndex
  10690. /// ::= .personalityindex index
  10691. bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
  10692. MCAsmParser &Parser = getParser();
  10693. bool HasExistingPersonality = UC.hasPersonality();
  10694. const MCExpr *IndexExpression;
  10695. SMLoc IndexLoc = Parser.getTok().getLoc();
  10696. if (Parser.parseExpression(IndexExpression) ||
  10697. parseToken(AsmToken::EndOfStatement,
  10698. "unexpected token in '.personalityindex' directive")) {
  10699. return true;
  10700. }
  10701. UC.recordPersonalityIndex(L);
  10702. if (!UC.hasFnStart()) {
  10703. return Error(L, ".fnstart must precede .personalityindex directive");
  10704. }
  10705. if (UC.cantUnwind()) {
  10706. Error(L, ".personalityindex cannot be used with .cantunwind");
  10707. UC.emitCantUnwindLocNotes();
  10708. return true;
  10709. }
  10710. if (UC.hasHandlerData()) {
  10711. Error(L, ".personalityindex must precede .handlerdata directive");
  10712. UC.emitHandlerDataLocNotes();
  10713. return true;
  10714. }
  10715. if (HasExistingPersonality) {
  10716. Error(L, "multiple personality directives");
  10717. UC.emitPersonalityLocNotes();
  10718. return true;
  10719. }
  10720. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
  10721. if (!CE)
  10722. return Error(IndexLoc, "index must be a constant number");
  10723. if (CE->getValue() < 0 || CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX)
  10724. return Error(IndexLoc,
  10725. "personality routine index should be in range [0-3]");
  10726. getTargetStreamer().emitPersonalityIndex(CE->getValue());
  10727. return false;
  10728. }
  10729. /// parseDirectiveUnwindRaw
  10730. /// ::= .unwind_raw offset, opcode [, opcode...]
  10731. bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
  10732. MCAsmParser &Parser = getParser();
  10733. int64_t StackOffset;
  10734. const MCExpr *OffsetExpr;
  10735. SMLoc OffsetLoc = getLexer().getLoc();
  10736. if (!UC.hasFnStart())
  10737. return Error(L, ".fnstart must precede .unwind_raw directives");
  10738. if (getParser().parseExpression(OffsetExpr))
  10739. return Error(OffsetLoc, "expected expression");
  10740. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
  10741. if (!CE)
  10742. return Error(OffsetLoc, "offset must be a constant");
  10743. StackOffset = CE->getValue();
  10744. if (Parser.parseToken(AsmToken::Comma, "expected comma"))
  10745. return true;
  10746. SmallVector<uint8_t, 16> Opcodes;
  10747. auto parseOne = [&]() -> bool {
  10748. const MCExpr *OE = nullptr;
  10749. SMLoc OpcodeLoc = getLexer().getLoc();
  10750. if (check(getLexer().is(AsmToken::EndOfStatement) ||
  10751. Parser.parseExpression(OE),
  10752. OpcodeLoc, "expected opcode expression"))
  10753. return true;
  10754. const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
  10755. if (!OC)
  10756. return Error(OpcodeLoc, "opcode value must be a constant");
  10757. const int64_t Opcode = OC->getValue();
  10758. if (Opcode & ~0xff)
  10759. return Error(OpcodeLoc, "invalid opcode");
  10760. Opcodes.push_back(uint8_t(Opcode));
  10761. return false;
  10762. };
  10763. // Must have at least 1 element
  10764. SMLoc OpcodeLoc = getLexer().getLoc();
  10765. if (parseOptionalToken(AsmToken::EndOfStatement))
  10766. return Error(OpcodeLoc, "expected opcode expression");
  10767. if (parseMany(parseOne))
  10768. return true;
  10769. getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
  10770. return false;
  10771. }
  10772. /// parseDirectiveTLSDescSeq
  10773. /// ::= .tlsdescseq tls-variable
  10774. bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
  10775. MCAsmParser &Parser = getParser();
  10776. if (getLexer().isNot(AsmToken::Identifier))
  10777. return TokError("expected variable after '.tlsdescseq' directive");
  10778. const MCSymbolRefExpr *SRE =
  10779. MCSymbolRefExpr::create(Parser.getTok().getIdentifier(),
  10780. MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
  10781. Lex();
  10782. if (parseToken(AsmToken::EndOfStatement,
  10783. "unexpected token in '.tlsdescseq' directive"))
  10784. return true;
  10785. getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
  10786. return false;
  10787. }
  10788. /// parseDirectiveMovSP
  10789. /// ::= .movsp reg [, #offset]
  10790. bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
  10791. MCAsmParser &Parser = getParser();
  10792. if (!UC.hasFnStart())
  10793. return Error(L, ".fnstart must precede .movsp directives");
  10794. if (UC.getFPReg() != ARM::SP)
  10795. return Error(L, "unexpected .movsp directive");
  10796. SMLoc SPRegLoc = Parser.getTok().getLoc();
  10797. int SPReg = tryParseRegister();
  10798. if (SPReg == -1)
  10799. return Error(SPRegLoc, "register expected");
  10800. if (SPReg == ARM::SP || SPReg == ARM::PC)
  10801. return Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
  10802. int64_t Offset = 0;
  10803. if (Parser.parseOptionalToken(AsmToken::Comma)) {
  10804. if (Parser.parseToken(AsmToken::Hash, "expected #constant"))
  10805. return true;
  10806. const MCExpr *OffsetExpr;
  10807. SMLoc OffsetLoc = Parser.getTok().getLoc();
  10808. if (Parser.parseExpression(OffsetExpr))
  10809. return Error(OffsetLoc, "malformed offset expression");
  10810. const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
  10811. if (!CE)
  10812. return Error(OffsetLoc, "offset must be an immediate constant");
  10813. Offset = CE->getValue();
  10814. }
  10815. if (parseToken(AsmToken::EndOfStatement,
  10816. "unexpected token in '.movsp' directive"))
  10817. return true;
  10818. getTargetStreamer().emitMovSP(SPReg, Offset);
  10819. UC.saveFPReg(SPReg);
  10820. return false;
  10821. }
  10822. /// parseDirectiveObjectArch
  10823. /// ::= .object_arch name
  10824. bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
  10825. MCAsmParser &Parser = getParser();
  10826. if (getLexer().isNot(AsmToken::Identifier))
  10827. return Error(getLexer().getLoc(), "unexpected token");
  10828. StringRef Arch = Parser.getTok().getString();
  10829. SMLoc ArchLoc = Parser.getTok().getLoc();
  10830. Lex();
  10831. ARM::ArchKind ID = ARM::parseArch(Arch);
  10832. if (ID == ARM::ArchKind::INVALID)
  10833. return Error(ArchLoc, "unknown architecture '" + Arch + "'");
  10834. if (parseToken(AsmToken::EndOfStatement))
  10835. return true;
  10836. getTargetStreamer().emitObjectArch(ID);
  10837. return false;
  10838. }
  10839. /// parseDirectiveAlign
  10840. /// ::= .align
  10841. bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
  10842. // NOTE: if this is not the end of the statement, fall back to the target
  10843. // agnostic handling for this directive which will correctly handle this.
  10844. if (parseOptionalToken(AsmToken::EndOfStatement)) {
  10845. // '.align' is target specifically handled to mean 2**2 byte alignment.
  10846. const MCSection *Section = getStreamer().getCurrentSectionOnly();
  10847. assert(Section && "must have section to emit alignment");
  10848. if (Section->UseCodeAlign())
  10849. getStreamer().emitCodeAlignment(4, &getSTI(), 0);
  10850. else
  10851. getStreamer().emitValueToAlignment(4, 0, 1, 0);
  10852. return false;
  10853. }
  10854. return true;
  10855. }
  10856. /// parseDirectiveThumbSet
  10857. /// ::= .thumb_set name, value
  10858. bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
  10859. MCAsmParser &Parser = getParser();
  10860. StringRef Name;
  10861. if (check(Parser.parseIdentifier(Name),
  10862. "expected identifier after '.thumb_set'") ||
  10863. parseToken(AsmToken::Comma, "expected comma after name '" + Name + "'"))
  10864. return true;
  10865. MCSymbol *Sym;
  10866. const MCExpr *Value;
  10867. if (MCParserUtils::parseAssignmentExpression(Name, /* allow_redef */ true,
  10868. Parser, Sym, Value))
  10869. return true;
  10870. getTargetStreamer().emitThumbSet(Sym, Value);
  10871. return false;
  10872. }
  10873. /// Force static initialization.
  10874. extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMAsmParser() {
  10875. RegisterMCAsmParser<ARMAsmParser> X(getTheARMLETarget());
  10876. RegisterMCAsmParser<ARMAsmParser> Y(getTheARMBETarget());
  10877. RegisterMCAsmParser<ARMAsmParser> A(getTheThumbLETarget());
  10878. RegisterMCAsmParser<ARMAsmParser> B(getTheThumbBETarget());
  10879. }
  10880. #define GET_REGISTER_MATCHER
  10881. #define GET_SUBTARGET_FEATURE_NAME
  10882. #define GET_MATCHER_IMPLEMENTATION
  10883. #define GET_MNEMONIC_SPELL_CHECKER
  10884. #include "ARMGenAsmMatcher.inc"
  10885. // Some diagnostics need to vary with subtarget features, so they are handled
  10886. // here. For example, the DPR class has either 16 or 32 registers, depending
  10887. // on the FPU available.
  10888. const char *
  10889. ARMAsmParser::getCustomOperandDiag(ARMMatchResultTy MatchError) {
  10890. switch (MatchError) {
  10891. // rGPR contains sp starting with ARMv8.
  10892. case Match_rGPR:
  10893. return hasV8Ops() ? "operand must be a register in range [r0, r14]"
  10894. : "operand must be a register in range [r0, r12] or r14";
  10895. // DPR contains 16 registers for some FPUs, and 32 for others.
  10896. case Match_DPR:
  10897. return hasD32() ? "operand must be a register in range [d0, d31]"
  10898. : "operand must be a register in range [d0, d15]";
  10899. case Match_DPR_RegList:
  10900. return hasD32() ? "operand must be a list of registers in range [d0, d31]"
  10901. : "operand must be a list of registers in range [d0, d15]";
  10902. // For all other diags, use the static string from tablegen.
  10903. default:
  10904. return getMatchKindDiag(MatchError);
  10905. }
  10906. }
  10907. // Process the list of near-misses, throwing away ones we don't want to report
  10908. // to the user, and converting the rest to a source location and string that
  10909. // should be reported.
  10910. void
  10911. ARMAsmParser::FilterNearMisses(SmallVectorImpl<NearMissInfo> &NearMissesIn,
  10912. SmallVectorImpl<NearMissMessage> &NearMissesOut,
  10913. SMLoc IDLoc, OperandVector &Operands) {
  10914. // TODO: If operand didn't match, sub in a dummy one and run target
  10915. // predicate, so that we can avoid reporting near-misses that are invalid?
  10916. // TODO: Many operand types dont have SuperClasses set, so we report
  10917. // redundant ones.
  10918. // TODO: Some operands are superclasses of registers (e.g.
  10919. // MCK_RegShiftedImm), we don't have any way to represent that currently.
  10920. // TODO: This is not all ARM-specific, can some of it be factored out?
  10921. // Record some information about near-misses that we have already seen, so
  10922. // that we can avoid reporting redundant ones. For example, if there are
  10923. // variants of an instruction that take 8- and 16-bit immediates, we want
  10924. // to only report the widest one.
  10925. std::multimap<unsigned, unsigned> OperandMissesSeen;
  10926. SmallSet<FeatureBitset, 4> FeatureMissesSeen;
  10927. bool ReportedTooFewOperands = false;
  10928. // Process the near-misses in reverse order, so that we see more general ones
  10929. // first, and so can avoid emitting more specific ones.
  10930. for (NearMissInfo &I : reverse(NearMissesIn)) {
  10931. switch (I.getKind()) {
  10932. case NearMissInfo::NearMissOperand: {
  10933. SMLoc OperandLoc =
  10934. ((ARMOperand &)*Operands[I.getOperandIndex()]).getStartLoc();
  10935. const char *OperandDiag =
  10936. getCustomOperandDiag((ARMMatchResultTy)I.getOperandError());
  10937. // If we have already emitted a message for a superclass, don't also report
  10938. // the sub-class. We consider all operand classes that we don't have a
  10939. // specialised diagnostic for to be equal for the propose of this check,
  10940. // so that we don't report the generic error multiple times on the same
  10941. // operand.
  10942. unsigned DupCheckMatchClass = OperandDiag ? I.getOperandClass() : ~0U;
  10943. auto PrevReports = OperandMissesSeen.equal_range(I.getOperandIndex());
  10944. if (std::any_of(PrevReports.first, PrevReports.second,
  10945. [DupCheckMatchClass](
  10946. const std::pair<unsigned, unsigned> Pair) {
  10947. if (DupCheckMatchClass == ~0U || Pair.second == ~0U)
  10948. return Pair.second == DupCheckMatchClass;
  10949. else
  10950. return isSubclass((MatchClassKind)DupCheckMatchClass,
  10951. (MatchClassKind)Pair.second);
  10952. }))
  10953. break;
  10954. OperandMissesSeen.insert(
  10955. std::make_pair(I.getOperandIndex(), DupCheckMatchClass));
  10956. NearMissMessage Message;
  10957. Message.Loc = OperandLoc;
  10958. if (OperandDiag) {
  10959. Message.Message = OperandDiag;
  10960. } else if (I.getOperandClass() == InvalidMatchClass) {
  10961. Message.Message = "too many operands for instruction";
  10962. } else {
  10963. Message.Message = "invalid operand for instruction";
  10964. LLVM_DEBUG(
  10965. dbgs() << "Missing diagnostic string for operand class "
  10966. << getMatchClassName((MatchClassKind)I.getOperandClass())
  10967. << I.getOperandClass() << ", error " << I.getOperandError()
  10968. << ", opcode " << MII.getName(I.getOpcode()) << "\n");
  10969. }
  10970. NearMissesOut.emplace_back(Message);
  10971. break;
  10972. }
  10973. case NearMissInfo::NearMissFeature: {
  10974. const FeatureBitset &MissingFeatures = I.getFeatures();
  10975. // Don't report the same set of features twice.
  10976. if (FeatureMissesSeen.count(MissingFeatures))
  10977. break;
  10978. FeatureMissesSeen.insert(MissingFeatures);
  10979. // Special case: don't report a feature set which includes arm-mode for
  10980. // targets that don't have ARM mode.
  10981. if (MissingFeatures.test(Feature_IsARMBit) && !hasARM())
  10982. break;
  10983. // Don't report any near-misses that both require switching instruction
  10984. // set, and adding other subtarget features.
  10985. if (isThumb() && MissingFeatures.test(Feature_IsARMBit) &&
  10986. MissingFeatures.count() > 1)
  10987. break;
  10988. if (!isThumb() && MissingFeatures.test(Feature_IsThumbBit) &&
  10989. MissingFeatures.count() > 1)
  10990. break;
  10991. if (!isThumb() && MissingFeatures.test(Feature_IsThumb2Bit) &&
  10992. (MissingFeatures & ~FeatureBitset({Feature_IsThumb2Bit,
  10993. Feature_IsThumbBit})).any())
  10994. break;
  10995. if (isMClass() && MissingFeatures.test(Feature_HasNEONBit))
  10996. break;
  10997. NearMissMessage Message;
  10998. Message.Loc = IDLoc;
  10999. raw_svector_ostream OS(Message.Message);
  11000. OS << "instruction requires:";
  11001. for (unsigned i = 0, e = MissingFeatures.size(); i != e; ++i)
  11002. if (MissingFeatures.test(i))
  11003. OS << ' ' << getSubtargetFeatureName(i);
  11004. NearMissesOut.emplace_back(Message);
  11005. break;
  11006. }
  11007. case NearMissInfo::NearMissPredicate: {
  11008. NearMissMessage Message;
  11009. Message.Loc = IDLoc;
  11010. switch (I.getPredicateError()) {
  11011. case Match_RequiresNotITBlock:
  11012. Message.Message = "flag setting instruction only valid outside IT block";
  11013. break;
  11014. case Match_RequiresITBlock:
  11015. Message.Message = "instruction only valid inside IT block";
  11016. break;
  11017. case Match_RequiresV6:
  11018. Message.Message = "instruction variant requires ARMv6 or later";
  11019. break;
  11020. case Match_RequiresThumb2:
  11021. Message.Message = "instruction variant requires Thumb2";
  11022. break;
  11023. case Match_RequiresV8:
  11024. Message.Message = "instruction variant requires ARMv8 or later";
  11025. break;
  11026. case Match_RequiresFlagSetting:
  11027. Message.Message = "no flag-preserving variant of this instruction available";
  11028. break;
  11029. case Match_InvalidOperand:
  11030. Message.Message = "invalid operand for instruction";
  11031. break;
  11032. default:
  11033. llvm_unreachable("Unhandled target predicate error");
  11034. break;
  11035. }
  11036. NearMissesOut.emplace_back(Message);
  11037. break;
  11038. }
  11039. case NearMissInfo::NearMissTooFewOperands: {
  11040. if (!ReportedTooFewOperands) {
  11041. SMLoc EndLoc = ((ARMOperand &)*Operands.back()).getEndLoc();
  11042. NearMissesOut.emplace_back(NearMissMessage{
  11043. EndLoc, StringRef("too few operands for instruction")});
  11044. ReportedTooFewOperands = true;
  11045. }
  11046. break;
  11047. }
  11048. case NearMissInfo::NoNearMiss:
  11049. // This should never leave the matcher.
  11050. llvm_unreachable("not a near-miss");
  11051. break;
  11052. }
  11053. }
  11054. }
  11055. void ARMAsmParser::ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses,
  11056. SMLoc IDLoc, OperandVector &Operands) {
  11057. SmallVector<NearMissMessage, 4> Messages;
  11058. FilterNearMisses(NearMisses, Messages, IDLoc, Operands);
  11059. if (Messages.size() == 0) {
  11060. // No near-misses were found, so the best we can do is "invalid
  11061. // instruction".
  11062. Error(IDLoc, "invalid instruction");
  11063. } else if (Messages.size() == 1) {
  11064. // One near miss was found, report it as the sole error.
  11065. Error(Messages[0].Loc, Messages[0].Message);
  11066. } else {
  11067. // More than one near miss, so report a generic "invalid instruction"
  11068. // error, followed by notes for each of the near-misses.
  11069. Error(IDLoc, "invalid instruction, any one of the following would fix this:");
  11070. for (auto &M : Messages) {
  11071. Note(M.Loc, M.Message);
  11072. }
  11073. }
  11074. }
  11075. bool ARMAsmParser::enableArchExtFeature(StringRef Name, SMLoc &ExtLoc) {
  11076. // FIXME: This structure should be moved inside ARMTargetParser
  11077. // when we start to table-generate them, and we can use the ARM
  11078. // flags below, that were generated by table-gen.
  11079. static const struct {
  11080. const uint64_t Kind;
  11081. const FeatureBitset ArchCheck;
  11082. const FeatureBitset Features;
  11083. } Extensions[] = {
  11084. {ARM::AEK_CRC, {Feature_HasV8Bit}, {ARM::FeatureCRC}},
  11085. {ARM::AEK_AES,
  11086. {Feature_HasV8Bit},
  11087. {ARM::FeatureAES, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
  11088. {ARM::AEK_SHA2,
  11089. {Feature_HasV8Bit},
  11090. {ARM::FeatureSHA2, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
  11091. {ARM::AEK_CRYPTO,
  11092. {Feature_HasV8Bit},
  11093. {ARM::FeatureCrypto, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
  11094. {ARM::AEK_FP,
  11095. {Feature_HasV8Bit},
  11096. {ARM::FeatureVFP2_SP, ARM::FeatureFPARMv8}},
  11097. {(ARM::AEK_HWDIVTHUMB | ARM::AEK_HWDIVARM),
  11098. {Feature_HasV7Bit, Feature_IsNotMClassBit},
  11099. {ARM::FeatureHWDivThumb, ARM::FeatureHWDivARM}},
  11100. {ARM::AEK_MP,
  11101. {Feature_HasV7Bit, Feature_IsNotMClassBit},
  11102. {ARM::FeatureMP}},
  11103. {ARM::AEK_SIMD,
  11104. {Feature_HasV8Bit},
  11105. {ARM::FeatureNEON, ARM::FeatureVFP2_SP, ARM::FeatureFPARMv8}},
  11106. {ARM::AEK_SEC, {Feature_HasV6KBit}, {ARM::FeatureTrustZone}},
  11107. // FIXME: Only available in A-class, isel not predicated
  11108. {ARM::AEK_VIRT, {Feature_HasV7Bit}, {ARM::FeatureVirtualization}},
  11109. {ARM::AEK_FP16,
  11110. {Feature_HasV8_2aBit},
  11111. {ARM::FeatureFPARMv8, ARM::FeatureFullFP16}},
  11112. {ARM::AEK_RAS, {Feature_HasV8Bit}, {ARM::FeatureRAS}},
  11113. {ARM::AEK_LOB, {Feature_HasV8_1MMainlineBit}, {ARM::FeatureLOB}},
  11114. {ARM::AEK_PACBTI, {Feature_HasV8_1MMainlineBit}, {ARM::FeaturePACBTI}},
  11115. // FIXME: Unsupported extensions.
  11116. {ARM::AEK_OS, {}, {}},
  11117. {ARM::AEK_IWMMXT, {}, {}},
  11118. {ARM::AEK_IWMMXT2, {}, {}},
  11119. {ARM::AEK_MAVERICK, {}, {}},
  11120. {ARM::AEK_XSCALE, {}, {}},
  11121. };
  11122. bool EnableFeature = true;
  11123. if (Name.startswith_insensitive("no")) {
  11124. EnableFeature = false;
  11125. Name = Name.substr(2);
  11126. }
  11127. uint64_t FeatureKind = ARM::parseArchExt(Name);
  11128. if (FeatureKind == ARM::AEK_INVALID)
  11129. return Error(ExtLoc, "unknown architectural extension: " + Name);
  11130. for (const auto &Extension : Extensions) {
  11131. if (Extension.Kind != FeatureKind)
  11132. continue;
  11133. if (Extension.Features.none())
  11134. return Error(ExtLoc, "unsupported architectural extension: " + Name);
  11135. if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck)
  11136. return Error(ExtLoc, "architectural extension '" + Name +
  11137. "' is not "
  11138. "allowed for the current base architecture");
  11139. MCSubtargetInfo &STI = copySTI();
  11140. if (EnableFeature) {
  11141. STI.SetFeatureBitsTransitively(Extension.Features);
  11142. } else {
  11143. STI.ClearFeatureBitsTransitively(Extension.Features);
  11144. }
  11145. FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits());
  11146. setAvailableFeatures(Features);
  11147. return true;
  11148. }
  11149. return false;
  11150. }
  11151. /// parseDirectiveArchExtension
  11152. /// ::= .arch_extension [no]feature
  11153. bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
  11154. MCAsmParser &Parser = getParser();
  11155. if (getLexer().isNot(AsmToken::Identifier))
  11156. return Error(getLexer().getLoc(), "expected architecture extension name");
  11157. StringRef Name = Parser.getTok().getString();
  11158. SMLoc ExtLoc = Parser.getTok().getLoc();
  11159. Lex();
  11160. if (parseToken(AsmToken::EndOfStatement,
  11161. "unexpected token in '.arch_extension' directive"))
  11162. return true;
  11163. if (Name == "nocrypto") {
  11164. enableArchExtFeature("nosha2", ExtLoc);
  11165. enableArchExtFeature("noaes", ExtLoc);
  11166. }
  11167. if (enableArchExtFeature(Name, ExtLoc))
  11168. return false;
  11169. return Error(ExtLoc, "unknown architectural extension: " + Name);
  11170. }
  11171. // Define this matcher function after the auto-generated include so we
  11172. // have the match class enum definitions.
  11173. unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
  11174. unsigned Kind) {
  11175. ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
  11176. // If the kind is a token for a literal immediate, check if our asm
  11177. // operand matches. This is for InstAliases which have a fixed-value
  11178. // immediate in the syntax.
  11179. switch (Kind) {
  11180. default: break;
  11181. case MCK__HASH_0:
  11182. if (Op.isImm())
  11183. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
  11184. if (CE->getValue() == 0)
  11185. return Match_Success;
  11186. break;
  11187. case MCK__HASH_8:
  11188. if (Op.isImm())
  11189. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
  11190. if (CE->getValue() == 8)
  11191. return Match_Success;
  11192. break;
  11193. case MCK__HASH_16:
  11194. if (Op.isImm())
  11195. if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
  11196. if (CE->getValue() == 16)
  11197. return Match_Success;
  11198. break;
  11199. case MCK_ModImm:
  11200. if (Op.isImm()) {
  11201. const MCExpr *SOExpr = Op.getImm();
  11202. int64_t Value;
  11203. if (!SOExpr->evaluateAsAbsolute(Value))
  11204. return Match_Success;
  11205. assert((Value >= std::numeric_limits<int32_t>::min() &&
  11206. Value <= std::numeric_limits<uint32_t>::max()) &&
  11207. "expression value must be representable in 32 bits");
  11208. }
  11209. break;
  11210. case MCK_rGPR:
  11211. if (hasV8Ops() && Op.isReg() && Op.getReg() == ARM::SP)
  11212. return Match_Success;
  11213. return Match_rGPR;
  11214. case MCK_GPRPair:
  11215. if (Op.isReg() &&
  11216. MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
  11217. return Match_Success;
  11218. break;
  11219. }
  11220. return Match_InvalidOperand;
  11221. }
  11222. bool ARMAsmParser::isMnemonicVPTPredicable(StringRef Mnemonic,
  11223. StringRef ExtraToken) {
  11224. if (!hasMVE())
  11225. return false;
  11226. return Mnemonic.startswith("vabav") || Mnemonic.startswith("vaddv") ||
  11227. Mnemonic.startswith("vaddlv") || Mnemonic.startswith("vminnmv") ||
  11228. Mnemonic.startswith("vminnmav") || Mnemonic.startswith("vminv") ||
  11229. Mnemonic.startswith("vminav") || Mnemonic.startswith("vmaxnmv") ||
  11230. Mnemonic.startswith("vmaxnmav") || Mnemonic.startswith("vmaxv") ||
  11231. Mnemonic.startswith("vmaxav") || Mnemonic.startswith("vmladav") ||
  11232. Mnemonic.startswith("vrmlaldavh") || Mnemonic.startswith("vrmlalvh") ||
  11233. Mnemonic.startswith("vmlsdav") || Mnemonic.startswith("vmlav") ||
  11234. Mnemonic.startswith("vmlaldav") || Mnemonic.startswith("vmlalv") ||
  11235. Mnemonic.startswith("vmaxnm") || Mnemonic.startswith("vminnm") ||
  11236. Mnemonic.startswith("vmax") || Mnemonic.startswith("vmin") ||
  11237. Mnemonic.startswith("vshlc") || Mnemonic.startswith("vmovlt") ||
  11238. Mnemonic.startswith("vmovlb") || Mnemonic.startswith("vshll") ||
  11239. Mnemonic.startswith("vrshrn") || Mnemonic.startswith("vshrn") ||
  11240. Mnemonic.startswith("vqrshrun") || Mnemonic.startswith("vqshrun") ||
  11241. Mnemonic.startswith("vqrshrn") || Mnemonic.startswith("vqshrn") ||
  11242. Mnemonic.startswith("vbic") || Mnemonic.startswith("vrev64") ||
  11243. Mnemonic.startswith("vrev32") || Mnemonic.startswith("vrev16") ||
  11244. Mnemonic.startswith("vmvn") || Mnemonic.startswith("veor") ||
  11245. Mnemonic.startswith("vorn") || Mnemonic.startswith("vorr") ||
  11246. Mnemonic.startswith("vand") || Mnemonic.startswith("vmul") ||
  11247. Mnemonic.startswith("vqrdmulh") || Mnemonic.startswith("vqdmulh") ||
  11248. Mnemonic.startswith("vsub") || Mnemonic.startswith("vadd") ||
  11249. Mnemonic.startswith("vqsub") || Mnemonic.startswith("vqadd") ||
  11250. Mnemonic.startswith("vabd") || Mnemonic.startswith("vrhadd") ||
  11251. Mnemonic.startswith("vhsub") || Mnemonic.startswith("vhadd") ||
  11252. Mnemonic.startswith("vdup") || Mnemonic.startswith("vcls") ||
  11253. Mnemonic.startswith("vclz") || Mnemonic.startswith("vneg") ||
  11254. Mnemonic.startswith("vabs") || Mnemonic.startswith("vqneg") ||
  11255. Mnemonic.startswith("vqabs") ||
  11256. (Mnemonic.startswith("vrint") && Mnemonic != "vrintr") ||
  11257. Mnemonic.startswith("vcmla") || Mnemonic.startswith("vfma") ||
  11258. Mnemonic.startswith("vfms") || Mnemonic.startswith("vcadd") ||
  11259. Mnemonic.startswith("vadd") || Mnemonic.startswith("vsub") ||
  11260. Mnemonic.startswith("vshl") || Mnemonic.startswith("vqshl") ||
  11261. Mnemonic.startswith("vqrshl") || Mnemonic.startswith("vrshl") ||
  11262. Mnemonic.startswith("vsri") || Mnemonic.startswith("vsli") ||
  11263. Mnemonic.startswith("vrshr") || Mnemonic.startswith("vshr") ||
  11264. Mnemonic.startswith("vpsel") || Mnemonic.startswith("vcmp") ||
  11265. Mnemonic.startswith("vqdmladh") || Mnemonic.startswith("vqrdmladh") ||
  11266. Mnemonic.startswith("vqdmlsdh") || Mnemonic.startswith("vqrdmlsdh") ||
  11267. Mnemonic.startswith("vcmul") || Mnemonic.startswith("vrmulh") ||
  11268. Mnemonic.startswith("vqmovn") || Mnemonic.startswith("vqmovun") ||
  11269. Mnemonic.startswith("vmovnt") || Mnemonic.startswith("vmovnb") ||
  11270. Mnemonic.startswith("vmaxa") || Mnemonic.startswith("vmaxnma") ||
  11271. Mnemonic.startswith("vhcadd") || Mnemonic.startswith("vadc") ||
  11272. Mnemonic.startswith("vsbc") || Mnemonic.startswith("vrshr") ||
  11273. Mnemonic.startswith("vshr") || Mnemonic.startswith("vstrb") ||
  11274. Mnemonic.startswith("vldrb") ||
  11275. (Mnemonic.startswith("vstrh") && Mnemonic != "vstrhi") ||
  11276. (Mnemonic.startswith("vldrh") && Mnemonic != "vldrhi") ||
  11277. Mnemonic.startswith("vstrw") || Mnemonic.startswith("vldrw") ||
  11278. Mnemonic.startswith("vldrd") || Mnemonic.startswith("vstrd") ||
  11279. Mnemonic.startswith("vqdmull") || Mnemonic.startswith("vbrsr") ||
  11280. Mnemonic.startswith("vfmas") || Mnemonic.startswith("vmlas") ||
  11281. Mnemonic.startswith("vmla") || Mnemonic.startswith("vqdmlash") ||
  11282. Mnemonic.startswith("vqdmlah") || Mnemonic.startswith("vqrdmlash") ||
  11283. Mnemonic.startswith("vqrdmlah") || Mnemonic.startswith("viwdup") ||
  11284. Mnemonic.startswith("vdwdup") || Mnemonic.startswith("vidup") ||
  11285. Mnemonic.startswith("vddup") || Mnemonic.startswith("vctp") ||
  11286. Mnemonic.startswith("vpnot") || Mnemonic.startswith("vbic") ||
  11287. Mnemonic.startswith("vrmlsldavh") || Mnemonic.startswith("vmlsldav") ||
  11288. Mnemonic.startswith("vcvt") ||
  11289. MS.isVPTPredicableCDEInstr(Mnemonic) ||
  11290. (Mnemonic.startswith("vmov") &&
  11291. !(ExtraToken == ".f16" || ExtraToken == ".32" ||
  11292. ExtraToken == ".16" || ExtraToken == ".8"));
  11293. }