ARMInstrThumb2.td 222 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755
  1. //===-- ARMInstrThumb2.td - Thumb2 support for ARM ---------*- tablegen -*-===//
  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. //
  9. // This file describes the Thumb2 instruction set.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. // IT block predicate field
  13. def it_pred_asmoperand : AsmOperandClass {
  14. let Name = "ITCondCode";
  15. let ParserMethod = "parseITCondCode";
  16. }
  17. def it_pred : Operand<i32> {
  18. let PrintMethod = "printMandatoryPredicateOperand";
  19. let ParserMatchClass = it_pred_asmoperand;
  20. }
  21. // IT block condition mask
  22. def it_mask_asmoperand : AsmOperandClass { let Name = "ITMask"; }
  23. def it_mask : Operand<i32> {
  24. let PrintMethod = "printThumbITMask";
  25. let ParserMatchClass = it_mask_asmoperand;
  26. let EncoderMethod = "getITMaskOpValue";
  27. }
  28. // t2_shift_imm: An integer that encodes a shift amount and the type of shift
  29. // (asr or lsl). The 6-bit immediate encodes as:
  30. // {5} 0 ==> lsl
  31. // 1 asr
  32. // {4-0} imm5 shift amount.
  33. // asr #32 not allowed
  34. def t2_shift_imm : Operand<i32> {
  35. let PrintMethod = "printShiftImmOperand";
  36. let ParserMatchClass = ShifterImmAsmOperand;
  37. let DecoderMethod = "DecodeT2ShifterImmOperand";
  38. }
  39. def mve_shift_imm : AsmOperandClass {
  40. let Name = "MVELongShift";
  41. let RenderMethod = "addImmOperands";
  42. let DiagnosticString = "operand must be an immediate in the range [1,32]";
  43. }
  44. def long_shift : Operand<i32>,
  45. ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]> {
  46. let ParserMatchClass = mve_shift_imm;
  47. let DecoderMethod = "DecodeLongShiftOperand";
  48. }
  49. // Shifted operands. No register controlled shifts for Thumb2.
  50. // Note: We do not support rrx shifted operands yet.
  51. def t2_so_reg : Operand<i32>, // reg imm
  52. ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
  53. [shl,srl,sra,rotr]> {
  54. let EncoderMethod = "getT2SORegOpValue";
  55. let PrintMethod = "printT2SOOperand";
  56. let DecoderMethod = "DecodeSORegImmOperand";
  57. let ParserMatchClass = ShiftedImmAsmOperand;
  58. let MIOperandInfo = (ops rGPR, i32imm);
  59. }
  60. // Same as above, but only matching on a single use node.
  61. def t2_so_reg_oneuse : Operand<i32>,
  62. ComplexPattern<i32, 2,
  63. "SelectShiftImmShifterOperandOneUse",
  64. [shl,srl,sra,rotr]>;
  65. // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
  66. def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
  67. return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
  68. MVT::i32);
  69. }]>;
  70. // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
  71. def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
  72. return CurDAG->getTargetConstant(-((int)N->getZExtValue()), SDLoc(N),
  73. MVT::i32);
  74. }]>;
  75. // so_imm_notSext_XFORM - Return a so_imm value packed into the format
  76. // described for so_imm_notSext def below, with sign extension from 16
  77. // bits.
  78. def t2_so_imm_notSext16_XFORM : SDNodeXForm<imm, [{
  79. APInt apIntN = N->getAPIntValue();
  80. unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
  81. return CurDAG->getTargetConstant(~N16bitSignExt, SDLoc(N), MVT::i32);
  82. }]>;
  83. // t2_so_imm - Match a 32-bit immediate operand, which is an
  84. // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
  85. // immediate splatted into multiple bytes of the word.
  86. def t2_so_imm_asmoperand : AsmOperandClass {
  87. let Name = "T2SOImm";
  88. let RenderMethod = "addImmOperands";
  89. }
  90. def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
  91. return ARM_AM::getT2SOImmVal(Imm) != -1;
  92. }]> {
  93. let ParserMatchClass = t2_so_imm_asmoperand;
  94. let EncoderMethod = "getT2SOImmOpValue";
  95. let DecoderMethod = "DecodeT2SOImm";
  96. }
  97. // t2_so_imm_not - Match an immediate that is a complement
  98. // of a t2_so_imm.
  99. // Note: this pattern doesn't require an encoder method and such, as it's
  100. // only used on aliases (Pat<> and InstAlias<>). The actual encoding
  101. // is handled by the destination instructions, which use t2_so_imm.
  102. def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; }
  103. def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{
  104. return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
  105. }], t2_so_imm_not_XFORM> {
  106. let ParserMatchClass = t2_so_imm_not_asmoperand;
  107. }
  108. // t2_so_imm_notSext - match an immediate that is a complement of a t2_so_imm
  109. // if the upper 16 bits are zero.
  110. def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{
  111. APInt apIntN = N->getAPIntValue();
  112. if (!apIntN.isIntN(16)) return false;
  113. unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
  114. return ARM_AM::getT2SOImmVal(~N16bitSignExt) != -1;
  115. }], t2_so_imm_notSext16_XFORM> {
  116. let ParserMatchClass = t2_so_imm_not_asmoperand;
  117. }
  118. // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
  119. def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
  120. def t2_so_imm_neg : Operand<i32>, ImmLeaf<i32, [{
  121. return Imm && ARM_AM::getT2SOImmVal(-(uint32_t)Imm) != -1;
  122. }], t2_so_imm_neg_XFORM> {
  123. let ParserMatchClass = t2_so_imm_neg_asmoperand;
  124. }
  125. /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0,4095].
  126. def imm0_4095_asmoperand: ImmAsmOperand<0,4095> { let Name = "Imm0_4095"; }
  127. def imm0_4095 : Operand<i32>, ImmLeaf<i32, [{
  128. return Imm >= 0 && Imm < 4096;
  129. }]> {
  130. let ParserMatchClass = imm0_4095_asmoperand;
  131. }
  132. def imm0_4095_neg_asmoperand: AsmOperandClass { let Name = "Imm0_4095Neg"; }
  133. def imm0_4095_neg : Operand<i32>, PatLeaf<(i32 imm), [{
  134. return (uint32_t)(-N->getZExtValue()) < 4096;
  135. }], imm_neg_XFORM> {
  136. let ParserMatchClass = imm0_4095_neg_asmoperand;
  137. }
  138. def imm1_255_neg : PatLeaf<(i32 imm), [{
  139. uint32_t Val = -N->getZExtValue();
  140. return (Val > 0 && Val < 255);
  141. }], imm_neg_XFORM>;
  142. def imm0_255_not : PatLeaf<(i32 imm), [{
  143. return (uint32_t)(~N->getZExtValue()) < 255;
  144. }], imm_not_XFORM>;
  145. def lo5AllOne : PatLeaf<(i32 imm), [{
  146. // Returns true if all low 5-bits are 1.
  147. return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
  148. }]>;
  149. // Define Thumb2 specific addressing modes.
  150. // t2_addr_offset_none := reg
  151. def MemNoOffsetT2AsmOperand
  152. : AsmOperandClass { let Name = "MemNoOffsetT2"; }
  153. def t2_addr_offset_none : MemOperand {
  154. let PrintMethod = "printAddrMode7Operand";
  155. let DecoderMethod = "DecodeGPRnopcRegisterClass";
  156. let ParserMatchClass = MemNoOffsetT2AsmOperand;
  157. let MIOperandInfo = (ops GPRnopc:$base);
  158. }
  159. // t2_nosp_addr_offset_none := reg
  160. def MemNoOffsetT2NoSpAsmOperand
  161. : AsmOperandClass { let Name = "MemNoOffsetT2NoSp"; }
  162. def t2_nosp_addr_offset_none : MemOperand {
  163. let PrintMethod = "printAddrMode7Operand";
  164. let DecoderMethod = "DecoderGPRRegisterClass";
  165. let ParserMatchClass = MemNoOffsetT2NoSpAsmOperand;
  166. let MIOperandInfo = (ops rGPR:$base);
  167. }
  168. // t2addrmode_imm12 := reg + imm12
  169. def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
  170. def t2addrmode_imm12 : MemOperand,
  171. ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
  172. let PrintMethod = "printAddrModeImm12Operand<false>";
  173. let EncoderMethod = "getAddrModeImm12OpValue";
  174. let DecoderMethod = "DecodeT2AddrModeImm12";
  175. let ParserMatchClass = t2addrmode_imm12_asmoperand;
  176. let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
  177. }
  178. // t2ldrlabel := imm12
  179. def t2ldrlabel : MemOperand {
  180. let EncoderMethod = "getAddrModeImm12OpValue";
  181. let PrintMethod = "printThumbLdrLabelOperand";
  182. }
  183. def t2ldr_pcrel_imm12_asmoperand : AsmOperandClass {let Name = "MemPCRelImm12";}
  184. def t2ldr_pcrel_imm12 : Operand<i32> {
  185. let ParserMatchClass = t2ldr_pcrel_imm12_asmoperand;
  186. // used for assembler pseudo instruction and maps to t2ldrlabel, so
  187. // doesn't need encoder or print methods of its own.
  188. }
  189. // ADR instruction labels.
  190. def t2adrlabel : Operand<i32> {
  191. let EncoderMethod = "getT2AdrLabelOpValue";
  192. let PrintMethod = "printAdrLabelOperand<0>";
  193. }
  194. // t2addrmode_posimm8 := reg + imm8
  195. def MemPosImm8OffsetAsmOperand : AsmOperandClass {
  196. let Name="MemPosImm8Offset";
  197. let RenderMethod = "addMemImmOffsetOperands";
  198. }
  199. def t2addrmode_posimm8 : MemOperand {
  200. let PrintMethod = "printT2AddrModeImm8Operand<false>";
  201. let EncoderMethod = "getT2AddrModeImmOpValue<8,0>";
  202. let DecoderMethod = "DecodeT2AddrModeImm8";
  203. let ParserMatchClass = MemPosImm8OffsetAsmOperand;
  204. let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
  205. }
  206. // t2addrmode_negimm8 := reg - imm8
  207. def MemNegImm8OffsetAsmOperand : AsmOperandClass {
  208. let Name="MemNegImm8Offset";
  209. let RenderMethod = "addMemImmOffsetOperands";
  210. }
  211. def t2addrmode_negimm8 : MemOperand,
  212. ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
  213. let PrintMethod = "printT2AddrModeImm8Operand<false>";
  214. let EncoderMethod = "getT2AddrModeImmOpValue<8,0>";
  215. let DecoderMethod = "DecodeT2AddrModeImm8";
  216. let ParserMatchClass = MemNegImm8OffsetAsmOperand;
  217. let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
  218. }
  219. // t2addrmode_imm8 := reg +/- imm8
  220. def MemImm8OffsetAsmOperand : AsmOperandClass {
  221. let Name = "MemImm8Offset";
  222. let RenderMethod = "addMemImmOffsetOperands";
  223. }
  224. class T2AddrMode_Imm8 : MemOperand,
  225. ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
  226. let EncoderMethod = "getT2AddrModeImmOpValue<8,0>";
  227. let DecoderMethod = "DecodeT2AddrModeImm8";
  228. let ParserMatchClass = MemImm8OffsetAsmOperand;
  229. let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
  230. }
  231. def t2addrmode_imm8 : T2AddrMode_Imm8 {
  232. let PrintMethod = "printT2AddrModeImm8Operand<false>";
  233. }
  234. def t2addrmode_imm8_pre : T2AddrMode_Imm8 {
  235. let PrintMethod = "printT2AddrModeImm8Operand<true>";
  236. }
  237. def t2am_imm8_offset : MemOperand,
  238. ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
  239. [], [SDNPWantRoot]> {
  240. let PrintMethod = "printT2AddrModeImm8OffsetOperand";
  241. let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
  242. let DecoderMethod = "DecodeT2Imm8";
  243. }
  244. // t2addrmode_imm8s4 := reg +/- (imm8 << 2)
  245. def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
  246. class T2AddrMode_Imm8s4 : MemOperand,
  247. ComplexPattern<i32, 2, "SelectT2AddrModeImm8<2>", []> {
  248. let EncoderMethod = "getT2AddrModeImm8s4OpValue";
  249. let DecoderMethod = "DecodeT2AddrModeImm8s4";
  250. let ParserMatchClass = MemImm8s4OffsetAsmOperand;
  251. let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
  252. }
  253. def t2addrmode_imm8s4 : T2AddrMode_Imm8s4 {
  254. let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
  255. }
  256. def t2addrmode_imm8s4_pre : T2AddrMode_Imm8s4 {
  257. let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
  258. }
  259. def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
  260. def t2am_imm8s4_offset : MemOperand {
  261. let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
  262. let EncoderMethod = "getT2ScaledImmOpValue<8,2>";
  263. let DecoderMethod = "DecodeT2Imm8S4";
  264. }
  265. // t2addrmode_imm7s4 := reg +/- (imm7 << 2)
  266. def MemImm7s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm7s4Offset";}
  267. class T2AddrMode_Imm7s4 : MemOperand {
  268. let EncoderMethod = "getT2AddrModeImm7s4OpValue";
  269. let DecoderMethod = "DecodeT2AddrModeImm7<2,0>";
  270. let ParserMatchClass = MemImm7s4OffsetAsmOperand;
  271. let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
  272. }
  273. def t2addrmode_imm7s4 : T2AddrMode_Imm7s4 {
  274. // They are printed the same way as the imm8 version
  275. let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
  276. }
  277. def t2addrmode_imm7s4_pre : T2AddrMode_Imm7s4 {
  278. // They are printed the same way as the imm8 version
  279. let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
  280. }
  281. def t2am_imm7s4_offset_asmoperand : AsmOperandClass { let Name = "Imm7s4"; }
  282. def t2am_imm7s4_offset : MemOperand {
  283. // They are printed the same way as the imm8 version
  284. let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
  285. let ParserMatchClass = t2am_imm7s4_offset_asmoperand;
  286. let EncoderMethod = "getT2ScaledImmOpValue<7,2>";
  287. let DecoderMethod = "DecodeT2Imm7S4";
  288. }
  289. // t2addrmode_imm0_1020s4 := reg + (imm8 << 2)
  290. def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
  291. let Name = "MemImm0_1020s4Offset";
  292. }
  293. def t2addrmode_imm0_1020s4 : MemOperand,
  294. ComplexPattern<i32, 2, "SelectT2AddrModeExclusive"> {
  295. let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
  296. let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
  297. let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
  298. let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
  299. let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
  300. }
  301. // t2addrmode_so_reg := reg + (reg << imm2)
  302. def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
  303. def t2addrmode_so_reg : MemOperand,
  304. ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
  305. let PrintMethod = "printT2AddrModeSoRegOperand";
  306. let EncoderMethod = "getT2AddrModeSORegOpValue";
  307. let DecoderMethod = "DecodeT2AddrModeSOReg";
  308. let ParserMatchClass = t2addrmode_so_reg_asmoperand;
  309. let MIOperandInfo = (ops GPRnopc:$base, rGPR:$offsreg, i32imm:$offsimm);
  310. }
  311. // Addresses for the TBB/TBH instructions.
  312. def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
  313. def addrmode_tbb : MemOperand {
  314. let PrintMethod = "printAddrModeTBB";
  315. let ParserMatchClass = addrmode_tbb_asmoperand;
  316. let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
  317. }
  318. def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
  319. def addrmode_tbh : MemOperand {
  320. let PrintMethod = "printAddrModeTBH";
  321. let ParserMatchClass = addrmode_tbh_asmoperand;
  322. let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
  323. }
  324. // Define ARMv8.1-M specific addressing modes.
  325. // Label operands for BF/BFL/WLS/DLS/LE
  326. class BFLabelOp<string signed, string isNeg, string zeroPermitted, string size,
  327. string fixup>
  328. : Operand<OtherVT> {
  329. let EncoderMethod = !strconcat("getBFTargetOpValue<", isNeg, ", ",
  330. fixup, ">");
  331. let OperandType = "OPERAND_PCREL";
  332. let DecoderMethod = !strconcat("DecodeBFLabelOperand<", signed, ", ",
  333. isNeg, ", ", zeroPermitted, ", ", size, ">");
  334. }
  335. def bflabel_u4 : BFLabelOp<"false", "false", "false", "4", "ARM::fixup_bf_branch">;
  336. def bflabel_s12 : BFLabelOp<"true", "false", "true", "12", "ARM::fixup_bfc_target">;
  337. def bflabel_s16 : BFLabelOp<"true", "false", "true", "16", "ARM::fixup_bf_target">;
  338. def bflabel_s18 : BFLabelOp<"true", "false", "true", "18", "ARM::fixup_bfl_target">;
  339. def wlslabel_u11_asmoperand : AsmOperandClass {
  340. let Name = "WLSLabel";
  341. let RenderMethod = "addImmOperands";
  342. let PredicateMethod = "isUnsignedOffset<11, 1>";
  343. let DiagnosticString =
  344. "loop end is out of range or not a positive multiple of 2";
  345. }
  346. def wlslabel_u11 : BFLabelOp<"false", "false", "true", "11", "ARM::fixup_wls"> {
  347. let ParserMatchClass = wlslabel_u11_asmoperand;
  348. }
  349. def lelabel_u11_asmoperand : AsmOperandClass {
  350. let Name = "LELabel";
  351. let RenderMethod = "addImmOperands";
  352. let PredicateMethod = "isLEOffset";
  353. let DiagnosticString =
  354. "loop start is out of range or not a negative multiple of 2";
  355. }
  356. def lelabel_u11 : BFLabelOp<"false", "true", "true", "11", "ARM::fixup_le"> {
  357. let ParserMatchClass = lelabel_u11_asmoperand;
  358. }
  359. def bfafter_target : Operand<OtherVT> {
  360. let EncoderMethod = "getBFAfterTargetOpValue";
  361. let OperandType = "OPERAND_PCREL";
  362. let DecoderMethod = "DecodeBFAfterTargetOperand";
  363. }
  364. // pred operand excluding AL
  365. def pred_noal_asmoperand : AsmOperandClass {
  366. let Name = "CondCodeNoAL";
  367. let RenderMethod = "addITCondCodeOperands";
  368. let PredicateMethod = "isITCondCodeNoAL";
  369. let ParserMethod = "parseITCondCode";
  370. }
  371. def pred_noal : Operand<i32> {
  372. let PrintMethod = "printMandatoryPredicateOperand";
  373. let ParserMatchClass = pred_noal_asmoperand;
  374. let DecoderMethod = "DecodePredNoALOperand";
  375. }
  376. // CSEL aliases inverted predicate
  377. def pred_noal_inv_asmoperand : AsmOperandClass {
  378. let Name = "CondCodeNoALInv";
  379. let RenderMethod = "addITCondCodeInvOperands";
  380. let PredicateMethod = "isITCondCodeNoAL";
  381. let ParserMethod = "parseITCondCode";
  382. }
  383. def pred_noal_inv : Operand<i32> {
  384. let PrintMethod = "printMandatoryInvertedPredicateOperand";
  385. let ParserMatchClass = pred_noal_inv_asmoperand;
  386. }
  387. //===----------------------------------------------------------------------===//
  388. // Multiclass helpers...
  389. //
  390. class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
  391. string opc, string asm, list<dag> pattern>
  392. : T2I<oops, iops, itin, opc, asm, pattern> {
  393. bits<4> Rd;
  394. bits<12> imm;
  395. let Inst{11-8} = Rd;
  396. let Inst{26} = imm{11};
  397. let Inst{14-12} = imm{10-8};
  398. let Inst{7-0} = imm{7-0};
  399. }
  400. class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
  401. string opc, string asm, list<dag> pattern>
  402. : T2sI<oops, iops, itin, opc, asm, pattern> {
  403. bits<4> Rd;
  404. bits<4> Rn;
  405. bits<12> imm;
  406. let Inst{11-8} = Rd;
  407. let Inst{26} = imm{11};
  408. let Inst{14-12} = imm{10-8};
  409. let Inst{7-0} = imm{7-0};
  410. }
  411. class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
  412. string opc, string asm, list<dag> pattern>
  413. : T2I<oops, iops, itin, opc, asm, pattern> {
  414. bits<4> Rn;
  415. bits<12> imm;
  416. let Inst{19-16} = Rn;
  417. let Inst{26} = imm{11};
  418. let Inst{14-12} = imm{10-8};
  419. let Inst{7-0} = imm{7-0};
  420. }
  421. class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
  422. string opc, string asm, list<dag> pattern>
  423. : T2I<oops, iops, itin, opc, asm, pattern> {
  424. bits<4> Rd;
  425. bits<12> ShiftedRm;
  426. let Inst{11-8} = Rd;
  427. let Inst{3-0} = ShiftedRm{3-0};
  428. let Inst{5-4} = ShiftedRm{6-5};
  429. let Inst{14-12} = ShiftedRm{11-9};
  430. let Inst{7-6} = ShiftedRm{8-7};
  431. }
  432. class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
  433. string opc, string asm, list<dag> pattern>
  434. : T2sI<oops, iops, itin, opc, asm, pattern> {
  435. bits<4> Rd;
  436. bits<12> ShiftedRm;
  437. let Inst{11-8} = Rd;
  438. let Inst{3-0} = ShiftedRm{3-0};
  439. let Inst{5-4} = ShiftedRm{6-5};
  440. let Inst{14-12} = ShiftedRm{11-9};
  441. let Inst{7-6} = ShiftedRm{8-7};
  442. }
  443. class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
  444. string opc, string asm, list<dag> pattern>
  445. : T2I<oops, iops, itin, opc, asm, pattern> {
  446. bits<4> Rn;
  447. bits<12> ShiftedRm;
  448. let Inst{19-16} = Rn;
  449. let Inst{3-0} = ShiftedRm{3-0};
  450. let Inst{5-4} = ShiftedRm{6-5};
  451. let Inst{14-12} = ShiftedRm{11-9};
  452. let Inst{7-6} = ShiftedRm{8-7};
  453. }
  454. class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
  455. string opc, string asm, list<dag> pattern>
  456. : T2I<oops, iops, itin, opc, asm, pattern> {
  457. bits<4> Rd;
  458. bits<4> Rm;
  459. let Inst{11-8} = Rd;
  460. let Inst{3-0} = Rm;
  461. }
  462. class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
  463. string opc, string asm, list<dag> pattern>
  464. : T2sI<oops, iops, itin, opc, asm, pattern> {
  465. bits<4> Rd;
  466. bits<4> Rm;
  467. let Inst{11-8} = Rd;
  468. let Inst{3-0} = Rm;
  469. }
  470. class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
  471. string opc, string asm, list<dag> pattern>
  472. : T2I<oops, iops, itin, opc, asm, pattern> {
  473. bits<4> Rn;
  474. bits<4> Rm;
  475. let Inst{19-16} = Rn;
  476. let Inst{3-0} = Rm;
  477. }
  478. class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
  479. string opc, string asm, list<dag> pattern>
  480. : T2I<oops, iops, itin, opc, asm, pattern> {
  481. bits<4> Rd;
  482. bits<4> Rn;
  483. bits<12> imm;
  484. let Inst{11-8} = Rd;
  485. let Inst{19-16} = Rn;
  486. let Inst{26} = imm{11};
  487. let Inst{14-12} = imm{10-8};
  488. let Inst{7-0} = imm{7-0};
  489. }
  490. class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
  491. string opc, string asm, list<dag> pattern>
  492. : T2sI<oops, iops, itin, opc, asm, pattern> {
  493. bits<4> Rd;
  494. bits<4> Rn;
  495. bits<12> imm;
  496. let Inst{11-8} = Rd;
  497. let Inst{19-16} = Rn;
  498. let Inst{26} = imm{11};
  499. let Inst{14-12} = imm{10-8};
  500. let Inst{7-0} = imm{7-0};
  501. }
  502. class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
  503. string opc, string asm, list<dag> pattern>
  504. : T2I<oops, iops, itin, opc, asm, pattern> {
  505. bits<4> Rd;
  506. bits<4> Rm;
  507. bits<5> imm;
  508. let Inst{11-8} = Rd;
  509. let Inst{3-0} = Rm;
  510. let Inst{14-12} = imm{4-2};
  511. let Inst{7-6} = imm{1-0};
  512. }
  513. class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
  514. string opc, string asm, list<dag> pattern>
  515. : T2sI<oops, iops, itin, opc, asm, pattern> {
  516. bits<4> Rd;
  517. bits<4> Rm;
  518. bits<5> imm;
  519. let Inst{11-8} = Rd;
  520. let Inst{3-0} = Rm;
  521. let Inst{14-12} = imm{4-2};
  522. let Inst{7-6} = imm{1-0};
  523. }
  524. class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
  525. string opc, string asm, list<dag> pattern>
  526. : T2I<oops, iops, itin, opc, asm, pattern> {
  527. bits<4> Rd;
  528. bits<4> Rn;
  529. bits<4> Rm;
  530. let Inst{11-8} = Rd;
  531. let Inst{19-16} = Rn;
  532. let Inst{3-0} = Rm;
  533. }
  534. class T2ThreeRegNoP<dag oops, dag iops, InstrItinClass itin,
  535. string asm, list<dag> pattern>
  536. : T2XI<oops, iops, itin, asm, pattern> {
  537. bits<4> Rd;
  538. bits<4> Rn;
  539. bits<4> Rm;
  540. let Inst{11-8} = Rd;
  541. let Inst{19-16} = Rn;
  542. let Inst{3-0} = Rm;
  543. }
  544. class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
  545. string opc, string asm, list<dag> pattern>
  546. : T2sI<oops, iops, itin, opc, asm, pattern> {
  547. bits<4> Rd;
  548. bits<4> Rn;
  549. bits<4> Rm;
  550. let Inst{11-8} = Rd;
  551. let Inst{19-16} = Rn;
  552. let Inst{3-0} = Rm;
  553. }
  554. class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
  555. string opc, string asm, list<dag> pattern>
  556. : T2I<oops, iops, itin, opc, asm, pattern> {
  557. bits<4> Rd;
  558. bits<4> Rn;
  559. bits<12> ShiftedRm;
  560. let Inst{11-8} = Rd;
  561. let Inst{19-16} = Rn;
  562. let Inst{3-0} = ShiftedRm{3-0};
  563. let Inst{5-4} = ShiftedRm{6-5};
  564. let Inst{14-12} = ShiftedRm{11-9};
  565. let Inst{7-6} = ShiftedRm{8-7};
  566. }
  567. class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
  568. string opc, string asm, list<dag> pattern>
  569. : T2sI<oops, iops, itin, opc, asm, pattern> {
  570. bits<4> Rd;
  571. bits<4> Rn;
  572. bits<12> ShiftedRm;
  573. let Inst{11-8} = Rd;
  574. let Inst{19-16} = Rn;
  575. let Inst{3-0} = ShiftedRm{3-0};
  576. let Inst{5-4} = ShiftedRm{6-5};
  577. let Inst{14-12} = ShiftedRm{11-9};
  578. let Inst{7-6} = ShiftedRm{8-7};
  579. }
  580. class T2FourReg<dag oops, dag iops, InstrItinClass itin,
  581. string opc, string asm, list<dag> pattern>
  582. : T2I<oops, iops, itin, opc, asm, pattern> {
  583. bits<4> Rd;
  584. bits<4> Rn;
  585. bits<4> Rm;
  586. bits<4> Ra;
  587. let Inst{19-16} = Rn;
  588. let Inst{15-12} = Ra;
  589. let Inst{11-8} = Rd;
  590. let Inst{3-0} = Rm;
  591. }
  592. class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
  593. string opc, list<dag> pattern>
  594. : T2I<(outs rGPR:$RdLo, rGPR:$RdHi), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
  595. opc, "\t$RdLo, $RdHi, $Rn, $Rm", pattern>,
  596. Sched<[WriteMUL64Lo, WriteMUL64Hi, ReadMUL, ReadMUL]> {
  597. bits<4> RdLo;
  598. bits<4> RdHi;
  599. bits<4> Rn;
  600. bits<4> Rm;
  601. let Inst{31-23} = 0b111110111;
  602. let Inst{22-20} = opc22_20;
  603. let Inst{19-16} = Rn;
  604. let Inst{15-12} = RdLo;
  605. let Inst{11-8} = RdHi;
  606. let Inst{7-4} = opc7_4;
  607. let Inst{3-0} = Rm;
  608. }
  609. class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4, string opc>
  610. : T2I<(outs rGPR:$RdLo, rGPR:$RdHi),
  611. (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
  612. opc, "\t$RdLo, $RdHi, $Rn, $Rm", []>,
  613. RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">,
  614. Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]> {
  615. bits<4> RdLo;
  616. bits<4> RdHi;
  617. bits<4> Rn;
  618. bits<4> Rm;
  619. let Inst{31-23} = 0b111110111;
  620. let Inst{22-20} = opc22_20;
  621. let Inst{19-16} = Rn;
  622. let Inst{15-12} = RdLo;
  623. let Inst{11-8} = RdHi;
  624. let Inst{7-4} = opc7_4;
  625. let Inst{3-0} = Rm;
  626. }
  627. /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
  628. /// binary operation that produces a value. These are predicable and can be
  629. /// changed to modify CPSR.
  630. multiclass T2I_bin_irs<bits<4> opcod, string opc,
  631. InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
  632. SDPatternOperator opnode, bit Commutable = 0,
  633. string wide = ""> {
  634. // shifted imm
  635. def ri : T2sTwoRegImm<
  636. (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
  637. opc, "\t$Rd, $Rn, $imm",
  638. [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
  639. Sched<[WriteALU, ReadALU]> {
  640. let Inst{31-27} = 0b11110;
  641. let Inst{25} = 0;
  642. let Inst{24-21} = opcod;
  643. let Inst{15} = 0;
  644. }
  645. // register
  646. def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
  647. opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
  648. [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
  649. Sched<[WriteALU, ReadALU, ReadALU]> {
  650. let isCommutable = Commutable;
  651. let Inst{31-27} = 0b11101;
  652. let Inst{26-25} = 0b01;
  653. let Inst{24-21} = opcod;
  654. let Inst{15} = 0b0;
  655. // In most of these instructions, and most versions of the Arm
  656. // architecture, bit 15 of this encoding is listed as (0) rather
  657. // than 0, i.e. setting it to 1 is UNPREDICTABLE or a soft-fail
  658. // rather than a hard failure. In v8.1-M, this requirement is
  659. // upgraded to a hard one for ORR, so that the encodings with 1
  660. // in this bit can be reused for other instructions (such as
  661. // CSEL). Setting Unpredictable{15} = 1 here would reintroduce
  662. // that encoding clash in the auto- generated MC decoder, so I
  663. // comment it out.
  664. let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1);
  665. let Inst{14-12} = 0b000; // imm3
  666. let Inst{7-6} = 0b00; // imm2
  667. let Inst{5-4} = 0b00; // type
  668. }
  669. // shifted register
  670. def rs : T2sTwoRegShiftedReg<
  671. (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
  672. opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
  673. [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
  674. Sched<[WriteALUsi, ReadALU]> {
  675. let Inst{31-27} = 0b11101;
  676. let Inst{26-25} = 0b01;
  677. let Inst{24-21} = opcod;
  678. let Inst{15} = 0;
  679. let Unpredictable{15} = !if(!eq(opcod, 0b0010), 0b0, 0b1); // see above
  680. }
  681. // Assembly aliases for optional destination operand when it's the same
  682. // as the source operand.
  683. def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
  684. (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn,
  685. t2_so_imm:$imm, pred:$p,
  686. cc_out:$s)>;
  687. def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
  688. (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn,
  689. rGPR:$Rm, pred:$p,
  690. cc_out:$s)>;
  691. def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
  692. (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn,
  693. t2_so_reg:$shift, pred:$p,
  694. cc_out:$s)>;
  695. }
  696. /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
  697. // the ".w" suffix to indicate that they are wide.
  698. multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
  699. InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
  700. SDPatternOperator opnode, bit Commutable = 0> :
  701. T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> {
  702. // Assembler aliases w/ the ".w" suffix.
  703. def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"),
  704. (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p,
  705. cc_out:$s)>;
  706. // Assembler aliases w/o the ".w" suffix.
  707. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
  708. (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
  709. cc_out:$s)>;
  710. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
  711. (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift,
  712. pred:$p, cc_out:$s)>;
  713. // and with the optional destination operand, too.
  714. def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"),
  715. (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm,
  716. pred:$p, cc_out:$s)>;
  717. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
  718. (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
  719. cc_out:$s)>;
  720. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
  721. (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift,
  722. pred:$p, cc_out:$s)>;
  723. }
  724. /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
  725. /// reversed. The 'rr' form is only defined for the disassembler; for codegen
  726. /// it is equivalent to the T2I_bin_irs counterpart.
  727. multiclass T2I_rbin_irs<bits<4> opcod, string opc, SDNode opnode> {
  728. // shifted imm
  729. def ri : T2sTwoRegImm<
  730. (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
  731. opc, ".w\t$Rd, $Rn, $imm",
  732. [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]>,
  733. Sched<[WriteALU, ReadALU]> {
  734. let Inst{31-27} = 0b11110;
  735. let Inst{25} = 0;
  736. let Inst{24-21} = opcod;
  737. let Inst{15} = 0;
  738. }
  739. // register
  740. def rr : T2sThreeReg<
  741. (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
  742. opc, "\t$Rd, $Rn, $Rm",
  743. [/* For disassembly only; pattern left blank */]>,
  744. Sched<[WriteALU, ReadALU, ReadALU]> {
  745. let Inst{31-27} = 0b11101;
  746. let Inst{26-25} = 0b01;
  747. let Inst{24-21} = opcod;
  748. let Inst{14-12} = 0b000; // imm3
  749. let Inst{7-6} = 0b00; // imm2
  750. let Inst{5-4} = 0b00; // type
  751. }
  752. // shifted register
  753. def rs : T2sTwoRegShiftedReg<
  754. (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
  755. IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
  756. [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>,
  757. Sched<[WriteALUsi, ReadALU]> {
  758. let Inst{31-27} = 0b11101;
  759. let Inst{26-25} = 0b01;
  760. let Inst{24-21} = opcod;
  761. }
  762. }
  763. /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
  764. /// instruction modifies the CPSR register.
  765. ///
  766. /// These opcodes will be converted to the real non-S opcodes by
  767. /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
  768. let hasPostISelHook = 1, Defs = [CPSR] in {
  769. multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
  770. InstrItinClass iis, SDNode opnode,
  771. bit Commutable = 0> {
  772. // shifted imm
  773. def ri : t2PseudoInst<(outs rGPR:$Rd),
  774. (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
  775. 4, iii,
  776. [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
  777. t2_so_imm:$imm))]>,
  778. Sched<[WriteALU, ReadALU]>;
  779. // register
  780. def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
  781. 4, iir,
  782. [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
  783. rGPR:$Rm))]>,
  784. Sched<[WriteALU, ReadALU, ReadALU]> {
  785. let isCommutable = Commutable;
  786. }
  787. // shifted register
  788. def rs : t2PseudoInst<(outs rGPR:$Rd),
  789. (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
  790. 4, iis,
  791. [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
  792. t2_so_reg:$ShiftedRm))]>,
  793. Sched<[WriteALUsi, ReadALUsr]>;
  794. }
  795. }
  796. /// T2I_rbin_s_is - Same as T2I_bin_s_irs, except selection DAG
  797. /// operands are reversed.
  798. let hasPostISelHook = 1, Defs = [CPSR] in {
  799. multiclass T2I_rbin_s_is<SDNode opnode> {
  800. // shifted imm
  801. def ri : t2PseudoInst<(outs rGPR:$Rd),
  802. (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p),
  803. 4, IIC_iALUi,
  804. [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
  805. rGPR:$Rn))]>,
  806. Sched<[WriteALU, ReadALU]>;
  807. // shifted register
  808. def rs : t2PseudoInst<(outs rGPR:$Rd),
  809. (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
  810. 4, IIC_iALUsi,
  811. [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
  812. rGPR:$Rn))]>,
  813. Sched<[WriteALUsi, ReadALU]>;
  814. }
  815. }
  816. /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
  817. /// patterns for a binary operation that produces a value.
  818. multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, SDNode opnode,
  819. bit Commutable = 0> {
  820. // shifted imm
  821. // The register-immediate version is re-materializable. This is useful
  822. // in particular for taking the address of a local.
  823. let isReMaterializable = 1 in {
  824. def spImm : T2sTwoRegImm<
  825. (outs GPRsp:$Rd), (ins GPRsp:$Rn, t2_so_imm:$imm), IIC_iALUi,
  826. opc, ".w\t$Rd, $Rn, $imm",
  827. []>,
  828. Sched<[WriteALU, ReadALU]> {
  829. let Rn = 13;
  830. let Rd = 13;
  831. let Inst{31-27} = 0b11110;
  832. let Inst{25-24} = 0b01;
  833. let Inst{23-21} = op23_21;
  834. let Inst{15} = 0;
  835. let DecoderMethod = "DecodeT2AddSubSPImm";
  836. }
  837. def ri : T2sTwoRegImm<
  838. (outs rGPR:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
  839. opc, ".w\t$Rd, $Rn, $imm",
  840. [(set rGPR:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]>,
  841. Sched<[WriteALU, ReadALU]> {
  842. let Inst{31-27} = 0b11110;
  843. let Inst{25} = 0;
  844. let Inst{24} = 1;
  845. let Inst{23-21} = op23_21;
  846. let Inst{15} = 0;
  847. }
  848. }
  849. // 12-bit imm
  850. def ri12 : T2I<
  851. (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
  852. !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
  853. [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]>,
  854. Sched<[WriteALU, ReadALU]> {
  855. bits<4> Rd;
  856. bits<4> Rn;
  857. bits<12> imm;
  858. let Inst{31-27} = 0b11110;
  859. let Inst{26} = imm{11};
  860. let Inst{25-24} = 0b10;
  861. let Inst{23-21} = op23_21;
  862. let Inst{20} = 0; // The S bit.
  863. let Inst{19-16} = Rn;
  864. let Inst{15} = 0;
  865. let Inst{14-12} = imm{10-8};
  866. let Inst{11-8} = Rd;
  867. let Inst{7-0} = imm{7-0};
  868. }
  869. def spImm12 : T2I<
  870. (outs GPRsp:$Rd), (ins GPRsp:$Rn, imm0_4095:$imm), IIC_iALUi,
  871. !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
  872. []>,
  873. Sched<[WriteALU, ReadALU]> {
  874. bits<4> Rd = 13;
  875. bits<4> Rn = 13;
  876. bits<12> imm;
  877. let Inst{31-27} = 0b11110;
  878. let Inst{26} = imm{11};
  879. let Inst{25-24} = 0b10;
  880. let Inst{23-21} = op23_21;
  881. let Inst{20} = 0; // The S bit.
  882. let Inst{19-16} = Rn;
  883. let Inst{15} = 0;
  884. let Inst{14-12} = imm{10-8};
  885. let Inst{11-8} = Rd;
  886. let Inst{7-0} = imm{7-0};
  887. let DecoderMethod = "DecodeT2AddSubSPImm";
  888. }
  889. // register
  890. def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
  891. IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
  892. [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]>,
  893. Sched<[WriteALU, ReadALU, ReadALU]> {
  894. let isCommutable = Commutable;
  895. let Inst{31-27} = 0b11101;
  896. let Inst{26-25} = 0b01;
  897. let Inst{24} = 1;
  898. let Inst{23-21} = op23_21;
  899. let Inst{14-12} = 0b000; // imm3
  900. let Inst{7-6} = 0b00; // imm2
  901. let Inst{5-4} = 0b00; // type
  902. }
  903. // shifted register
  904. def rs : T2sTwoRegShiftedReg<
  905. (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
  906. IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
  907. [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]>,
  908. Sched<[WriteALUsi, ReadALU]> {
  909. let Inst{31-27} = 0b11101;
  910. let Inst{26-25} = 0b01;
  911. let Inst{24} = 1;
  912. let Inst{23-21} = op23_21;
  913. }
  914. }
  915. /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
  916. /// for a binary operation that produces a value and use the carry
  917. /// bit. It's not predicable.
  918. let Defs = [CPSR], Uses = [CPSR] in {
  919. multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, SDNode opnode,
  920. bit Commutable = 0> {
  921. // shifted imm
  922. def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
  923. IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
  924. [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
  925. Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU]> {
  926. let Inst{31-27} = 0b11110;
  927. let Inst{25} = 0;
  928. let Inst{24-21} = opcod;
  929. let Inst{15} = 0;
  930. }
  931. // register
  932. def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
  933. opc, ".w\t$Rd, $Rn, $Rm",
  934. [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
  935. Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU, ReadALU]> {
  936. let isCommutable = Commutable;
  937. let Inst{31-27} = 0b11101;
  938. let Inst{26-25} = 0b01;
  939. let Inst{24-21} = opcod;
  940. let Inst{14-12} = 0b000; // imm3
  941. let Inst{7-6} = 0b00; // imm2
  942. let Inst{5-4} = 0b00; // type
  943. }
  944. // shifted register
  945. def rs : T2sTwoRegShiftedReg<
  946. (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
  947. IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
  948. [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
  949. Requires<[IsThumb2]>, Sched<[WriteALUsi, ReadALU]> {
  950. let Inst{31-27} = 0b11101;
  951. let Inst{26-25} = 0b01;
  952. let Inst{24-21} = opcod;
  953. }
  954. }
  955. }
  956. /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
  957. // rotate operation that produces a value.
  958. multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, SDNode opnode> {
  959. // 5-bit imm
  960. def ri : T2sTwoRegShiftImm<
  961. (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
  962. opc, ".w\t$Rd, $Rm, $imm",
  963. [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]>,
  964. Sched<[WriteALU]> {
  965. let Inst{31-27} = 0b11101;
  966. let Inst{26-21} = 0b010010;
  967. let Inst{19-16} = 0b1111; // Rn
  968. let Inst{15} = 0b0;
  969. let Inst{5-4} = opcod;
  970. }
  971. // register
  972. def rr : T2sThreeReg<
  973. (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
  974. opc, ".w\t$Rd, $Rn, $Rm",
  975. [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
  976. Sched<[WriteALU]> {
  977. let Inst{31-27} = 0b11111;
  978. let Inst{26-23} = 0b0100;
  979. let Inst{22-21} = opcod;
  980. let Inst{15-12} = 0b1111;
  981. let Inst{7-4} = 0b0000;
  982. }
  983. // Optional destination register
  984. def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
  985. (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
  986. cc_out:$s)>;
  987. def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
  988. (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
  989. cc_out:$s)>;
  990. // Assembler aliases w/o the ".w" suffix.
  991. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
  992. (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p,
  993. cc_out:$s)>;
  994. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
  995. (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
  996. cc_out:$s)>;
  997. // and with the optional destination operand, too.
  998. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
  999. (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
  1000. cc_out:$s)>;
  1001. def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
  1002. (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
  1003. cc_out:$s)>;
  1004. }
  1005. /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
  1006. /// patterns. Similar to T2I_bin_irs except the instruction does not produce
  1007. /// a explicit result, only implicitly set CPSR.
  1008. multiclass T2I_cmp_irs<bits<4> opcod, string opc, RegisterClass LHSGPR,
  1009. InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
  1010. SDPatternOperator opnode> {
  1011. let isCompare = 1, Defs = [CPSR] in {
  1012. // shifted imm
  1013. def ri : T2OneRegCmpImm<
  1014. (outs), (ins LHSGPR:$Rn, t2_so_imm:$imm), iii,
  1015. opc, ".w\t$Rn, $imm",
  1016. [(opnode LHSGPR:$Rn, t2_so_imm:$imm)]>, Sched<[WriteCMP]> {
  1017. let Inst{31-27} = 0b11110;
  1018. let Inst{25} = 0;
  1019. let Inst{24-21} = opcod;
  1020. let Inst{20} = 1; // The S bit.
  1021. let Inst{15} = 0;
  1022. let Inst{11-8} = 0b1111; // Rd
  1023. }
  1024. // register
  1025. def rr : T2TwoRegCmp<
  1026. (outs), (ins LHSGPR:$Rn, rGPR:$Rm), iir,
  1027. opc, ".w\t$Rn, $Rm",
  1028. [(opnode LHSGPR:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP]> {
  1029. let Inst{31-27} = 0b11101;
  1030. let Inst{26-25} = 0b01;
  1031. let Inst{24-21} = opcod;
  1032. let Inst{20} = 1; // The S bit.
  1033. let Inst{14-12} = 0b000; // imm3
  1034. let Inst{11-8} = 0b1111; // Rd
  1035. let Inst{7-6} = 0b00; // imm2
  1036. let Inst{5-4} = 0b00; // type
  1037. }
  1038. // shifted register
  1039. def rs : T2OneRegCmpShiftedReg<
  1040. (outs), (ins LHSGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
  1041. opc, ".w\t$Rn, $ShiftedRm",
  1042. [(opnode LHSGPR:$Rn, t2_so_reg:$ShiftedRm)]>,
  1043. Sched<[WriteCMPsi]> {
  1044. let Inst{31-27} = 0b11101;
  1045. let Inst{26-25} = 0b01;
  1046. let Inst{24-21} = opcod;
  1047. let Inst{20} = 1; // The S bit.
  1048. let Inst{11-8} = 0b1111; // Rd
  1049. }
  1050. }
  1051. // Assembler aliases w/o the ".w" suffix.
  1052. // No alias here for 'rr' version as not all instantiations of this
  1053. // multiclass want one (CMP in particular, does not).
  1054. def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
  1055. (!cast<Instruction>(NAME#"ri") LHSGPR:$Rn, t2_so_imm:$imm, pred:$p)>;
  1056. def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
  1057. (!cast<Instruction>(NAME#"rs") LHSGPR:$Rn, t2_so_reg:$shift, pred:$p)>;
  1058. }
  1059. /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
  1060. multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
  1061. InstrItinClass iii, InstrItinClass iis, RegisterClass target,
  1062. PatFrag opnode> {
  1063. def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
  1064. opc, ".w\t$Rt, $addr",
  1065. [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]>,
  1066. Sched<[WriteLd]> {
  1067. bits<4> Rt;
  1068. bits<17> addr;
  1069. let Inst{31-25} = 0b1111100;
  1070. let Inst{24} = signed;
  1071. let Inst{23} = 1;
  1072. let Inst{22-21} = opcod;
  1073. let Inst{20} = 1; // load
  1074. let Inst{19-16} = addr{16-13}; // Rn
  1075. let Inst{15-12} = Rt;
  1076. let Inst{11-0} = addr{11-0}; // imm
  1077. let DecoderMethod = "DecodeT2LoadImm12";
  1078. }
  1079. def i8 : T2Ii8n <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
  1080. opc, "\t$Rt, $addr",
  1081. [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]>,
  1082. Sched<[WriteLd]> {
  1083. bits<4> Rt;
  1084. bits<13> addr;
  1085. let Inst{31-27} = 0b11111;
  1086. let Inst{26-25} = 0b00;
  1087. let Inst{24} = signed;
  1088. let Inst{23} = 0;
  1089. let Inst{22-21} = opcod;
  1090. let Inst{20} = 1; // load
  1091. let Inst{19-16} = addr{12-9}; // Rn
  1092. let Inst{15-12} = Rt;
  1093. let Inst{11} = 1;
  1094. // Offset: index==TRUE, wback==FALSE
  1095. let Inst{10} = 1; // The P bit.
  1096. let Inst{9} = addr{8}; // U
  1097. let Inst{8} = 0; // The W bit.
  1098. let Inst{7-0} = addr{7-0}; // imm
  1099. let DecoderMethod = "DecodeT2LoadImm8";
  1100. }
  1101. def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
  1102. opc, ".w\t$Rt, $addr",
  1103. [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]>,
  1104. Sched<[WriteLd]> {
  1105. let Inst{31-27} = 0b11111;
  1106. let Inst{26-25} = 0b00;
  1107. let Inst{24} = signed;
  1108. let Inst{23} = 0;
  1109. let Inst{22-21} = opcod;
  1110. let Inst{20} = 1; // load
  1111. let Inst{11-6} = 0b000000;
  1112. bits<4> Rt;
  1113. let Inst{15-12} = Rt;
  1114. bits<10> addr;
  1115. let Inst{19-16} = addr{9-6}; // Rn
  1116. let Inst{3-0} = addr{5-2}; // Rm
  1117. let Inst{5-4} = addr{1-0}; // imm
  1118. let DecoderMethod = "DecodeT2LoadShift";
  1119. }
  1120. // pci variant is very similar to i12, but supports negative offsets
  1121. // from the PC.
  1122. def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
  1123. opc, ".w\t$Rt, $addr",
  1124. [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]>,
  1125. Sched<[WriteLd]> {
  1126. let isReMaterializable = 1;
  1127. let Inst{31-27} = 0b11111;
  1128. let Inst{26-25} = 0b00;
  1129. let Inst{24} = signed;
  1130. let Inst{22-21} = opcod;
  1131. let Inst{20} = 1; // load
  1132. let Inst{19-16} = 0b1111; // Rn
  1133. bits<4> Rt;
  1134. let Inst{15-12} = Rt{3-0};
  1135. bits<13> addr;
  1136. let Inst{23} = addr{12}; // add = (U == '1')
  1137. let Inst{11-0} = addr{11-0};
  1138. let DecoderMethod = "DecodeT2LoadLabel";
  1139. }
  1140. }
  1141. /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
  1142. multiclass T2I_st<bits<2> opcod, string opc,
  1143. InstrItinClass iii, InstrItinClass iis, RegisterClass target,
  1144. PatFrag opnode> {
  1145. def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
  1146. opc, ".w\t$Rt, $addr",
  1147. [(opnode target:$Rt, t2addrmode_imm12:$addr)]>,
  1148. Sched<[WriteST]> {
  1149. let Inst{31-27} = 0b11111;
  1150. let Inst{26-23} = 0b0001;
  1151. let Inst{22-21} = opcod;
  1152. let Inst{20} = 0; // !load
  1153. bits<4> Rt;
  1154. let Inst{15-12} = Rt;
  1155. bits<17> addr;
  1156. let addr{12} = 1; // add = TRUE
  1157. let Inst{19-16} = addr{16-13}; // Rn
  1158. let Inst{23} = addr{12}; // U
  1159. let Inst{11-0} = addr{11-0}; // imm
  1160. }
  1161. def i8 : T2Ii8n <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
  1162. opc, "\t$Rt, $addr",
  1163. [(opnode target:$Rt, t2addrmode_negimm8:$addr)]>,
  1164. Sched<[WriteST]> {
  1165. let Inst{31-27} = 0b11111;
  1166. let Inst{26-23} = 0b0000;
  1167. let Inst{22-21} = opcod;
  1168. let Inst{20} = 0; // !load
  1169. let Inst{11} = 1;
  1170. // Offset: index==TRUE, wback==FALSE
  1171. let Inst{10} = 1; // The P bit.
  1172. let Inst{8} = 0; // The W bit.
  1173. bits<4> Rt;
  1174. let Inst{15-12} = Rt;
  1175. bits<13> addr;
  1176. let Inst{19-16} = addr{12-9}; // Rn
  1177. let Inst{9} = addr{8}; // U
  1178. let Inst{7-0} = addr{7-0}; // imm
  1179. }
  1180. def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
  1181. opc, ".w\t$Rt, $addr",
  1182. [(opnode target:$Rt, t2addrmode_so_reg:$addr)]>,
  1183. Sched<[WriteST]> {
  1184. let Inst{31-27} = 0b11111;
  1185. let Inst{26-23} = 0b0000;
  1186. let Inst{22-21} = opcod;
  1187. let Inst{20} = 0; // !load
  1188. let Inst{11-6} = 0b000000;
  1189. bits<4> Rt;
  1190. let Inst{15-12} = Rt;
  1191. bits<10> addr;
  1192. let Inst{19-16} = addr{9-6}; // Rn
  1193. let Inst{3-0} = addr{5-2}; // Rm
  1194. let Inst{5-4} = addr{1-0}; // imm
  1195. }
  1196. }
  1197. /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
  1198. /// register and one whose operand is a register rotated by 8/16/24.
  1199. class T2I_ext_rrot_base<bits<3> opcod, dag iops, dag oops,
  1200. string opc, string oprs,
  1201. list<dag> pattern>
  1202. : T2TwoReg<iops, oops, IIC_iEXTr, opc, oprs, pattern> {
  1203. bits<2> rot;
  1204. let Inst{31-27} = 0b11111;
  1205. let Inst{26-23} = 0b0100;
  1206. let Inst{22-20} = opcod;
  1207. let Inst{19-16} = 0b1111; // Rn
  1208. let Inst{15-12} = 0b1111;
  1209. let Inst{7} = 1;
  1210. let Inst{5-4} = rot; // rotate
  1211. }
  1212. class T2I_ext_rrot<bits<3> opcod, string opc>
  1213. : T2I_ext_rrot_base<opcod,
  1214. (outs rGPR:$Rd),
  1215. (ins rGPR:$Rm, rot_imm:$rot),
  1216. opc, ".w\t$Rd, $Rm$rot", []>,
  1217. Requires<[IsThumb2]>,
  1218. Sched<[WriteALU, ReadALU]>;
  1219. // UXTB16, SXTB16 - Requires HasDSP, does not need the .w qualifier.
  1220. class T2I_ext_rrot_xtb16<bits<3> opcod, string opc>
  1221. : T2I_ext_rrot_base<opcod,
  1222. (outs rGPR:$Rd),
  1223. (ins rGPR:$Rm, rot_imm:$rot),
  1224. opc, "\t$Rd, $Rm$rot", []>,
  1225. Requires<[HasDSP, IsThumb2]>,
  1226. Sched<[WriteALU, ReadALU]>;
  1227. /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
  1228. /// register and one whose operand is a register rotated by 8/16/24.
  1229. class T2I_exta_rrot<bits<3> opcod, string opc>
  1230. : T2ThreeReg<(outs rGPR:$Rd),
  1231. (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
  1232. IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
  1233. Requires<[HasDSP, IsThumb2]>,
  1234. Sched<[WriteALU, ReadALU]> {
  1235. bits<2> rot;
  1236. let Inst{31-27} = 0b11111;
  1237. let Inst{26-23} = 0b0100;
  1238. let Inst{22-20} = opcod;
  1239. let Inst{15-12} = 0b1111;
  1240. let Inst{7} = 1;
  1241. let Inst{5-4} = rot;
  1242. }
  1243. //===----------------------------------------------------------------------===//
  1244. // Instructions
  1245. //===----------------------------------------------------------------------===//
  1246. //===----------------------------------------------------------------------===//
  1247. // Miscellaneous Instructions.
  1248. //
  1249. class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
  1250. string asm, list<dag> pattern>
  1251. : T2XI<oops, iops, itin, asm, pattern> {
  1252. bits<4> Rd;
  1253. bits<12> label;
  1254. let Inst{11-8} = Rd;
  1255. let Inst{26} = label{11};
  1256. let Inst{14-12} = label{10-8};
  1257. let Inst{7-0} = label{7-0};
  1258. }
  1259. // LEApcrel - Load a pc-relative address into a register without offending the
  1260. // assembler.
  1261. def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
  1262. (ins t2adrlabel:$addr, pred:$p),
  1263. IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []>,
  1264. Sched<[WriteALU, ReadALU]> {
  1265. let Inst{31-27} = 0b11110;
  1266. let Inst{25-24} = 0b10;
  1267. // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
  1268. let Inst{22} = 0;
  1269. let Inst{20} = 0;
  1270. let Inst{19-16} = 0b1111; // Rn
  1271. let Inst{15} = 0;
  1272. bits<4> Rd;
  1273. bits<13> addr;
  1274. let Inst{11-8} = Rd;
  1275. let Inst{23} = addr{12};
  1276. let Inst{21} = addr{12};
  1277. let Inst{26} = addr{11};
  1278. let Inst{14-12} = addr{10-8};
  1279. let Inst{7-0} = addr{7-0};
  1280. let DecoderMethod = "DecodeT2Adr";
  1281. }
  1282. let hasSideEffects = 0, isReMaterializable = 1 in
  1283. def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
  1284. 4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
  1285. let hasSideEffects = 1 in
  1286. def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
  1287. (ins i32imm:$label, pred:$p),
  1288. 4, IIC_iALUi,
  1289. []>, Sched<[WriteALU, ReadALU]>;
  1290. //===----------------------------------------------------------------------===//
  1291. // Load / store Instructions.
  1292. //
  1293. // Load
  1294. let canFoldAsLoad = 1, isReMaterializable = 1 in
  1295. defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR, load>;
  1296. // Loads with zero extension
  1297. defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
  1298. GPRnopc, zextloadi16>;
  1299. defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
  1300. GPRnopc, zextloadi8>;
  1301. // Loads with sign extension
  1302. defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
  1303. GPRnopc, sextloadi16>;
  1304. defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
  1305. GPRnopc, sextloadi8>;
  1306. let mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1 in {
  1307. // Load doubleword
  1308. def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
  1309. (ins t2addrmode_imm8s4:$addr),
  1310. IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "",
  1311. [(set rGPR:$Rt, rGPR:$Rt2, (ARMldrd t2addrmode_imm8s4:$addr))]>,
  1312. Sched<[WriteLd]>;
  1313. } // mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1
  1314. // zextload i1 -> zextload i8
  1315. def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
  1316. (t2LDRBi12 t2addrmode_imm12:$addr)>;
  1317. def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
  1318. (t2LDRBi8 t2addrmode_negimm8:$addr)>;
  1319. def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
  1320. (t2LDRBs t2addrmode_so_reg:$addr)>;
  1321. def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
  1322. (t2LDRBpci tconstpool:$addr)>;
  1323. // extload -> zextload
  1324. // FIXME: Reduce the number of patterns by legalizing extload to zextload
  1325. // earlier?
  1326. def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
  1327. (t2LDRBi12 t2addrmode_imm12:$addr)>;
  1328. def : T2Pat<(extloadi1 t2addrmode_negimm8:$addr),
  1329. (t2LDRBi8 t2addrmode_negimm8:$addr)>;
  1330. def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
  1331. (t2LDRBs t2addrmode_so_reg:$addr)>;
  1332. def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
  1333. (t2LDRBpci tconstpool:$addr)>;
  1334. def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
  1335. (t2LDRBi12 t2addrmode_imm12:$addr)>;
  1336. def : T2Pat<(extloadi8 t2addrmode_negimm8:$addr),
  1337. (t2LDRBi8 t2addrmode_negimm8:$addr)>;
  1338. def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
  1339. (t2LDRBs t2addrmode_so_reg:$addr)>;
  1340. def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
  1341. (t2LDRBpci tconstpool:$addr)>;
  1342. def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
  1343. (t2LDRHi12 t2addrmode_imm12:$addr)>;
  1344. def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
  1345. (t2LDRHi8 t2addrmode_negimm8:$addr)>;
  1346. def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
  1347. (t2LDRHs t2addrmode_so_reg:$addr)>;
  1348. def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
  1349. (t2LDRHpci tconstpool:$addr)>;
  1350. // FIXME: The destination register of the loads and stores can't be PC, but
  1351. // can be SP. We need another regclass (similar to rGPR) to represent
  1352. // that. Not a pressing issue since these are selected manually,
  1353. // not via pattern.
  1354. // Indexed loads
  1355. let mayLoad = 1, hasSideEffects = 0 in {
  1356. def t2LDR_PRE : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
  1357. (ins t2addrmode_imm8_pre:$addr),
  1358. AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
  1359. "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
  1360. Sched<[WriteLd]>;
  1361. def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
  1362. (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
  1363. AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
  1364. "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
  1365. Sched<[WriteLd]>;
  1366. def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
  1367. (ins t2addrmode_imm8_pre:$addr),
  1368. AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
  1369. "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
  1370. Sched<[WriteLd]>;
  1371. def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
  1372. (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
  1373. AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
  1374. "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
  1375. Sched<[WriteLd]>;
  1376. def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
  1377. (ins t2addrmode_imm8_pre:$addr),
  1378. AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
  1379. "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>,
  1380. Sched<[WriteLd]>;
  1381. def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
  1382. (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
  1383. AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
  1384. "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
  1385. Sched<[WriteLd]>;
  1386. def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
  1387. (ins t2addrmode_imm8_pre:$addr),
  1388. AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
  1389. "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
  1390. []>, Sched<[WriteLd]>;
  1391. def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
  1392. (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
  1393. AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
  1394. "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
  1395. Sched<[WriteLd]>;
  1396. def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
  1397. (ins t2addrmode_imm8_pre:$addr),
  1398. AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
  1399. "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
  1400. []>, Sched<[WriteLd]>;
  1401. def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
  1402. (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
  1403. AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
  1404. "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>,
  1405. Sched<[WriteLd]>;
  1406. } // mayLoad = 1, hasSideEffects = 0
  1407. // F5.1.72 LDR (immediate) T4
  1408. // .w suffixes; Constraints can't be used on t2InstAlias to describe
  1409. // "$Rn = $Rn_wb" on POST or "$addr.base = $Rn_wb" on PRE.
  1410. def t2LDR_PRE_imm : t2AsmPseudo<"ldr${p}.w $Rt, $addr!",
  1411. (ins GPR:$Rt, t2addrmode_imm8_pre:$addr, pred:$p)>;
  1412. def t2LDR_POST_imm : t2AsmPseudo<"ldr${p}.w $Rt, $Rn, $imm",
  1413. (ins GPR:$Rt, addr_offset_none:$Rn, t2am_imm8_offset:$imm, pred:$p)>;
  1414. // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
  1415. // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
  1416. class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
  1417. : T2Ii8p<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
  1418. "\t$Rt, $addr", []>, Sched<[WriteLd]> {
  1419. bits<4> Rt;
  1420. bits<13> addr;
  1421. let Inst{31-27} = 0b11111;
  1422. let Inst{26-25} = 0b00;
  1423. let Inst{24} = signed;
  1424. let Inst{23} = 0;
  1425. let Inst{22-21} = type;
  1426. let Inst{20} = 1; // load
  1427. let Inst{19-16} = addr{12-9};
  1428. let Inst{15-12} = Rt;
  1429. let Inst{11} = 1;
  1430. let Inst{10-8} = 0b110; // PUW.
  1431. let Inst{7-0} = addr{7-0};
  1432. let DecoderMethod = "DecodeT2LoadT";
  1433. }
  1434. def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
  1435. def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
  1436. def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
  1437. def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
  1438. def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
  1439. class T2Ildacq<bits<4> bits23_20, bits<2> bit54, dag oops, dag iops,
  1440. string opc, string asm, list<dag> pattern>
  1441. : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary,
  1442. opc, asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]> {
  1443. bits<4> Rt;
  1444. bits<4> addr;
  1445. let Inst{31-27} = 0b11101;
  1446. let Inst{26-24} = 0b000;
  1447. let Inst{23-20} = bits23_20;
  1448. let Inst{11-6} = 0b111110;
  1449. let Inst{5-4} = bit54;
  1450. let Inst{3-0} = 0b1111;
  1451. // Encode instruction operands
  1452. let Inst{19-16} = addr;
  1453. let Inst{15-12} = Rt;
  1454. }
  1455. def t2LDA : T2Ildacq<0b1101, 0b10, (outs rGPR:$Rt),
  1456. (ins addr_offset_none:$addr), "lda", "\t$Rt, $addr", []>,
  1457. Sched<[WriteLd]>;
  1458. def t2LDAB : T2Ildacq<0b1101, 0b00, (outs rGPR:$Rt),
  1459. (ins addr_offset_none:$addr), "ldab", "\t$Rt, $addr", []>,
  1460. Sched<[WriteLd]>;
  1461. def t2LDAH : T2Ildacq<0b1101, 0b01, (outs rGPR:$Rt),
  1462. (ins addr_offset_none:$addr), "ldah", "\t$Rt, $addr", []>,
  1463. Sched<[WriteLd]>;
  1464. // Store
  1465. defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR, store>;
  1466. defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
  1467. rGPR, truncstorei8>;
  1468. defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
  1469. rGPR, truncstorei16>;
  1470. // Store doubleword
  1471. let mayStore = 1, hasSideEffects = 0, hasExtraSrcRegAllocReq = 1 in
  1472. def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
  1473. (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
  1474. IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "",
  1475. [(ARMstrd rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr)]>,
  1476. Sched<[WriteST]>;
  1477. // Indexed stores
  1478. let mayStore = 1, hasSideEffects = 0 in {
  1479. def t2STR_PRE : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
  1480. (ins GPRnopc:$Rt, t2addrmode_imm8_pre:$addr),
  1481. AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
  1482. "str", "\t$Rt, $addr!",
  1483. "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
  1484. Sched<[WriteST]>;
  1485. def t2STRH_PRE : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
  1486. (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
  1487. AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
  1488. "strh", "\t$Rt, $addr!",
  1489. "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
  1490. Sched<[WriteST]>;
  1491. def t2STRB_PRE : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
  1492. (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
  1493. AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
  1494. "strb", "\t$Rt, $addr!",
  1495. "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>,
  1496. Sched<[WriteST]>;
  1497. } // mayStore = 1, hasSideEffects = 0
  1498. def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
  1499. (ins GPRnopc:$Rt, addr_offset_none:$Rn,
  1500. t2am_imm8_offset:$offset),
  1501. AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
  1502. "str", "\t$Rt, $Rn$offset",
  1503. "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
  1504. [(set GPRnopc:$Rn_wb,
  1505. (post_store GPRnopc:$Rt, addr_offset_none:$Rn,
  1506. t2am_imm8_offset:$offset))]>,
  1507. Sched<[WriteST]>;
  1508. def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
  1509. (ins rGPR:$Rt, addr_offset_none:$Rn,
  1510. t2am_imm8_offset:$offset),
  1511. AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
  1512. "strh", "\t$Rt, $Rn$offset",
  1513. "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
  1514. [(set GPRnopc:$Rn_wb,
  1515. (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
  1516. t2am_imm8_offset:$offset))]>,
  1517. Sched<[WriteST]>;
  1518. def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
  1519. (ins rGPR:$Rt, addr_offset_none:$Rn,
  1520. t2am_imm8_offset:$offset),
  1521. AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
  1522. "strb", "\t$Rt, $Rn$offset",
  1523. "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
  1524. [(set GPRnopc:$Rn_wb,
  1525. (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
  1526. t2am_imm8_offset:$offset))]>,
  1527. Sched<[WriteST]>;
  1528. // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
  1529. // put the patterns on the instruction definitions directly as ISel wants
  1530. // the address base and offset to be separate operands, not a single
  1531. // complex operand like we represent the instructions themselves. The
  1532. // pseudos map between the two.
  1533. let usesCustomInserter = 1,
  1534. Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
  1535. def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
  1536. (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
  1537. 4, IIC_iStore_ru,
  1538. [(set GPRnopc:$Rn_wb,
  1539. (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
  1540. Sched<[WriteST]>;
  1541. def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
  1542. (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
  1543. 4, IIC_iStore_ru,
  1544. [(set GPRnopc:$Rn_wb,
  1545. (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
  1546. Sched<[WriteST]>;
  1547. def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
  1548. (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
  1549. 4, IIC_iStore_ru,
  1550. [(set GPRnopc:$Rn_wb,
  1551. (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>,
  1552. Sched<[WriteST]>;
  1553. }
  1554. // F5.1.229 STR (immediate) T4
  1555. // .w suffixes; Constraints can't be used on t2InstAlias to describe
  1556. // "$Rn = $Rn_wb,@earlyclobber $Rn_wb" on POST or
  1557. // "$addr.base = $Rn_wb,@earlyclobber $Rn_wb" on PRE.
  1558. def t2STR_PRE_imm : t2AsmPseudo<"str${p}.w $Rt, $addr!",
  1559. (ins GPR:$Rt, t2addrmode_imm8_pre:$addr, pred:$p)>;
  1560. def t2STR_POST_imm : t2AsmPseudo<"str${p}.w $Rt, $Rn, $imm",
  1561. (ins GPR:$Rt, addr_offset_none:$Rn, t2am_imm8_offset:$imm, pred:$p)>;
  1562. // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
  1563. // only.
  1564. // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
  1565. class T2IstT<bits<2> type, string opc, InstrItinClass ii>
  1566. : T2Ii8p<(outs), (ins rGPR:$Rt, t2addrmode_posimm8:$addr), ii, opc,
  1567. "\t$Rt, $addr", []>, Sched<[WriteST]> {
  1568. let Inst{31-27} = 0b11111;
  1569. let Inst{26-25} = 0b00;
  1570. let Inst{24} = 0; // not signed
  1571. let Inst{23} = 0;
  1572. let Inst{22-21} = type;
  1573. let Inst{20} = 0; // store
  1574. let Inst{11} = 1;
  1575. let Inst{10-8} = 0b110; // PUW
  1576. bits<4> Rt;
  1577. bits<13> addr;
  1578. let Inst{15-12} = Rt;
  1579. let Inst{19-16} = addr{12-9};
  1580. let Inst{7-0} = addr{7-0};
  1581. }
  1582. def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
  1583. def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
  1584. def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
  1585. // ldrd / strd pre / post variants
  1586. let mayLoad = 1, hasSideEffects = 0 in
  1587. def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
  1588. (ins t2addrmode_imm8s4_pre:$addr), IIC_iLoad_d_ru,
  1589. "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []>,
  1590. Sched<[WriteLd]> {
  1591. let DecoderMethod = "DecodeT2LDRDPreInstruction";
  1592. }
  1593. let mayLoad = 1, hasSideEffects = 0 in
  1594. def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
  1595. (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
  1596. IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
  1597. "$addr.base = $wb", []>, Sched<[WriteLd]>;
  1598. let mayStore = 1, hasSideEffects = 0 in
  1599. def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
  1600. (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4_pre:$addr),
  1601. IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
  1602. "$addr.base = $wb", []>, Sched<[WriteST]> {
  1603. let DecoderMethod = "DecodeT2STRDPreInstruction";
  1604. }
  1605. let mayStore = 1, hasSideEffects = 0 in
  1606. def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
  1607. (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
  1608. t2am_imm8s4_offset:$imm),
  1609. IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
  1610. "$addr.base = $wb", []>, Sched<[WriteST]>;
  1611. class T2Istrrel<bits<2> bit54, dag oops, dag iops,
  1612. string opc, string asm, list<dag> pattern>
  1613. : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, opc,
  1614. asm, "", pattern>, Requires<[IsThumb, HasAcquireRelease]>,
  1615. Sched<[WriteST]> {
  1616. bits<4> Rt;
  1617. bits<4> addr;
  1618. let Inst{31-27} = 0b11101;
  1619. let Inst{26-20} = 0b0001100;
  1620. let Inst{11-6} = 0b111110;
  1621. let Inst{5-4} = bit54;
  1622. let Inst{3-0} = 0b1111;
  1623. // Encode instruction operands
  1624. let Inst{19-16} = addr;
  1625. let Inst{15-12} = Rt;
  1626. }
  1627. def t2STL : T2Istrrel<0b10, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
  1628. "stl", "\t$Rt, $addr", []>;
  1629. def t2STLB : T2Istrrel<0b00, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
  1630. "stlb", "\t$Rt, $addr", []>;
  1631. def t2STLH : T2Istrrel<0b01, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
  1632. "stlh", "\t$Rt, $addr", []>;
  1633. // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
  1634. // data/instruction access.
  1635. // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
  1636. // (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
  1637. multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
  1638. def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
  1639. "\t$addr",
  1640. [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]>,
  1641. Sched<[WritePreLd]> {
  1642. let Inst{31-25} = 0b1111100;
  1643. let Inst{24} = instr;
  1644. let Inst{23} = 1;
  1645. let Inst{22} = 0;
  1646. let Inst{21} = write;
  1647. let Inst{20} = 1;
  1648. let Inst{15-12} = 0b1111;
  1649. bits<17> addr;
  1650. let Inst{19-16} = addr{16-13}; // Rn
  1651. let Inst{11-0} = addr{11-0}; // imm12
  1652. let DecoderMethod = "DecodeT2LoadImm12";
  1653. }
  1654. def i8 : T2Ii8n<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
  1655. "\t$addr",
  1656. [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]>,
  1657. Sched<[WritePreLd]> {
  1658. let Inst{31-25} = 0b1111100;
  1659. let Inst{24} = instr;
  1660. let Inst{23} = 0; // U = 0
  1661. let Inst{22} = 0;
  1662. let Inst{21} = write;
  1663. let Inst{20} = 1;
  1664. let Inst{15-12} = 0b1111;
  1665. let Inst{11-8} = 0b1100;
  1666. bits<13> addr;
  1667. let Inst{19-16} = addr{12-9}; // Rn
  1668. let Inst{7-0} = addr{7-0}; // imm8
  1669. let DecoderMethod = "DecodeT2LoadImm8";
  1670. }
  1671. def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
  1672. "\t$addr",
  1673. [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]>,
  1674. Sched<[WritePreLd]> {
  1675. let Inst{31-25} = 0b1111100;
  1676. let Inst{24} = instr;
  1677. let Inst{23} = 0; // add = TRUE for T1
  1678. let Inst{22} = 0;
  1679. let Inst{21} = write;
  1680. let Inst{20} = 1;
  1681. let Inst{15-12} = 0b1111;
  1682. let Inst{11-6} = 0b000000;
  1683. bits<10> addr;
  1684. let Inst{19-16} = addr{9-6}; // Rn
  1685. let Inst{3-0} = addr{5-2}; // Rm
  1686. let Inst{5-4} = addr{1-0}; // imm2
  1687. let DecoderMethod = "DecodeT2LoadShift";
  1688. }
  1689. }
  1690. defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
  1691. defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
  1692. defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
  1693. // PLD/PLDW/PLI aliases w/ the optional .w suffix
  1694. def : t2InstAlias<"pld${p}.w\t$addr",
  1695. (t2PLDi12 t2addrmode_imm12:$addr, pred:$p)>;
  1696. def : t2InstAlias<"pld${p}.w\t$addr",
  1697. (t2PLDi8 t2addrmode_negimm8:$addr, pred:$p)>;
  1698. def : t2InstAlias<"pld${p}.w\t$addr",
  1699. (t2PLDs t2addrmode_so_reg:$addr, pred:$p)>;
  1700. def : InstAlias<"pldw${p}.w\t$addr",
  1701. (t2PLDWi12 t2addrmode_imm12:$addr, pred:$p), 0>,
  1702. Requires<[IsThumb2,HasV7,HasMP]>;
  1703. def : InstAlias<"pldw${p}.w\t$addr",
  1704. (t2PLDWi8 t2addrmode_negimm8:$addr, pred:$p), 0>,
  1705. Requires<[IsThumb2,HasV7,HasMP]>;
  1706. def : InstAlias<"pldw${p}.w\t$addr",
  1707. (t2PLDWs t2addrmode_so_reg:$addr, pred:$p), 0>,
  1708. Requires<[IsThumb2,HasV7,HasMP]>;
  1709. def : InstAlias<"pli${p}.w\t$addr",
  1710. (t2PLIi12 t2addrmode_imm12:$addr, pred:$p), 0>,
  1711. Requires<[IsThumb2,HasV7]>;
  1712. def : InstAlias<"pli${p}.w\t$addr",
  1713. (t2PLIi8 t2addrmode_negimm8:$addr, pred:$p), 0>,
  1714. Requires<[IsThumb2,HasV7]>;
  1715. def : InstAlias<"pli${p}.w\t$addr",
  1716. (t2PLIs t2addrmode_so_reg:$addr, pred:$p), 0>,
  1717. Requires<[IsThumb2,HasV7]>;
  1718. // pci variant is very similar to i12, but supports negative offsets
  1719. // from the PC. Only PLD and PLI have pci variants (not PLDW)
  1720. class T2Iplpci<bits<1> inst, string opc> : T2Ipc<(outs), (ins t2ldrlabel:$addr),
  1721. IIC_Preload, opc, "\t$addr",
  1722. [(ARMPreload (ARMWrapper tconstpool:$addr),
  1723. (i32 0), (i32 inst))]>, Sched<[WritePreLd]> {
  1724. let Inst{31-25} = 0b1111100;
  1725. let Inst{24} = inst;
  1726. let Inst{22-20} = 0b001;
  1727. let Inst{19-16} = 0b1111;
  1728. let Inst{15-12} = 0b1111;
  1729. bits<13> addr;
  1730. let Inst{23} = addr{12}; // add = (U == '1')
  1731. let Inst{11-0} = addr{11-0}; // imm12
  1732. let DecoderMethod = "DecodeT2LoadLabel";
  1733. }
  1734. def t2PLDpci : T2Iplpci<0, "pld">, Requires<[IsThumb2]>;
  1735. def t2PLIpci : T2Iplpci<1, "pli">, Requires<[IsThumb2,HasV7]>;
  1736. def : t2InstAlias<"pld${p}.w $addr",
  1737. (t2PLDpci t2ldrlabel:$addr, pred:$p)>;
  1738. def : InstAlias<"pli${p}.w $addr",
  1739. (t2PLIpci t2ldrlabel:$addr, pred:$p), 0>,
  1740. Requires<[IsThumb2,HasV7]>;
  1741. // PLD/PLI with alternate literal form.
  1742. def : t2InstAlias<"pld${p} $addr",
  1743. (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
  1744. def : InstAlias<"pli${p} $addr",
  1745. (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p), 0>,
  1746. Requires<[IsThumb2,HasV7]>;
  1747. def : t2InstAlias<"pld${p}.w $addr",
  1748. (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
  1749. def : InstAlias<"pli${p}.w $addr",
  1750. (t2PLIpci t2ldr_pcrel_imm12:$addr, pred:$p), 0>,
  1751. Requires<[IsThumb2,HasV7]>;
  1752. //===----------------------------------------------------------------------===//
  1753. // Load / store multiple Instructions.
  1754. //
  1755. multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
  1756. InstrItinClass itin_upd, bit L_bit> {
  1757. def IA :
  1758. T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1759. itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
  1760. bits<4> Rn;
  1761. bits<16> regs;
  1762. let Inst{31-27} = 0b11101;
  1763. let Inst{26-25} = 0b00;
  1764. let Inst{24-23} = 0b01; // Increment After
  1765. let Inst{22} = 0;
  1766. let Inst{21} = 0; // No writeback
  1767. let Inst{20} = L_bit;
  1768. let Inst{19-16} = Rn;
  1769. let Inst{15-0} = regs;
  1770. }
  1771. def IA_UPD :
  1772. T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1773. itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
  1774. bits<4> Rn;
  1775. bits<16> regs;
  1776. let Inst{31-27} = 0b11101;
  1777. let Inst{26-25} = 0b00;
  1778. let Inst{24-23} = 0b01; // Increment After
  1779. let Inst{22} = 0;
  1780. let Inst{21} = 1; // Writeback
  1781. let Inst{20} = L_bit;
  1782. let Inst{19-16} = Rn;
  1783. let Inst{15-0} = regs;
  1784. }
  1785. def DB :
  1786. T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1787. itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
  1788. bits<4> Rn;
  1789. bits<16> regs;
  1790. let Inst{31-27} = 0b11101;
  1791. let Inst{26-25} = 0b00;
  1792. let Inst{24-23} = 0b10; // Decrement Before
  1793. let Inst{22} = 0;
  1794. let Inst{21} = 0; // No writeback
  1795. let Inst{20} = L_bit;
  1796. let Inst{19-16} = Rn;
  1797. let Inst{15-0} = regs;
  1798. }
  1799. def DB_UPD :
  1800. T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1801. itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
  1802. bits<4> Rn;
  1803. bits<16> regs;
  1804. let Inst{31-27} = 0b11101;
  1805. let Inst{26-25} = 0b00;
  1806. let Inst{24-23} = 0b10; // Decrement Before
  1807. let Inst{22} = 0;
  1808. let Inst{21} = 1; // Writeback
  1809. let Inst{20} = L_bit;
  1810. let Inst{19-16} = Rn;
  1811. let Inst{15-0} = regs;
  1812. }
  1813. }
  1814. let hasSideEffects = 0 in {
  1815. let mayLoad = 1, hasExtraDefRegAllocReq = 1, variadicOpsAreDefs = 1 in
  1816. defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
  1817. multiclass thumb2_st_mult<string asm, InstrItinClass itin,
  1818. InstrItinClass itin_upd, bit L_bit> {
  1819. def IA :
  1820. T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1821. itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
  1822. bits<4> Rn;
  1823. bits<16> regs;
  1824. let Inst{31-27} = 0b11101;
  1825. let Inst{26-25} = 0b00;
  1826. let Inst{24-23} = 0b01; // Increment After
  1827. let Inst{22} = 0;
  1828. let Inst{21} = 0; // No writeback
  1829. let Inst{20} = L_bit;
  1830. let Inst{19-16} = Rn;
  1831. let Inst{15} = 0;
  1832. let Inst{14} = regs{14};
  1833. let Inst{13} = 0;
  1834. let Inst{12-0} = regs{12-0};
  1835. }
  1836. def IA_UPD :
  1837. T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1838. itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
  1839. bits<4> Rn;
  1840. bits<16> regs;
  1841. let Inst{31-27} = 0b11101;
  1842. let Inst{26-25} = 0b00;
  1843. let Inst{24-23} = 0b01; // Increment After
  1844. let Inst{22} = 0;
  1845. let Inst{21} = 1; // Writeback
  1846. let Inst{20} = L_bit;
  1847. let Inst{19-16} = Rn;
  1848. let Inst{15} = 0;
  1849. let Inst{14} = regs{14};
  1850. let Inst{13} = 0;
  1851. let Inst{12-0} = regs{12-0};
  1852. }
  1853. def DB :
  1854. T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1855. itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
  1856. bits<4> Rn;
  1857. bits<16> regs;
  1858. let Inst{31-27} = 0b11101;
  1859. let Inst{26-25} = 0b00;
  1860. let Inst{24-23} = 0b10; // Decrement Before
  1861. let Inst{22} = 0;
  1862. let Inst{21} = 0; // No writeback
  1863. let Inst{20} = L_bit;
  1864. let Inst{19-16} = Rn;
  1865. let Inst{15} = 0;
  1866. let Inst{14} = regs{14};
  1867. let Inst{13} = 0;
  1868. let Inst{12-0} = regs{12-0};
  1869. }
  1870. def DB_UPD :
  1871. T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
  1872. itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
  1873. bits<4> Rn;
  1874. bits<16> regs;
  1875. let Inst{31-27} = 0b11101;
  1876. let Inst{26-25} = 0b00;
  1877. let Inst{24-23} = 0b10; // Decrement Before
  1878. let Inst{22} = 0;
  1879. let Inst{21} = 1; // Writeback
  1880. let Inst{20} = L_bit;
  1881. let Inst{19-16} = Rn;
  1882. let Inst{15} = 0;
  1883. let Inst{14} = regs{14};
  1884. let Inst{13} = 0;
  1885. let Inst{12-0} = regs{12-0};
  1886. }
  1887. }
  1888. let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
  1889. defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
  1890. } // hasSideEffects
  1891. //===----------------------------------------------------------------------===//
  1892. // Move Instructions.
  1893. //
  1894. let hasSideEffects = 0 in
  1895. def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rm), IIC_iMOVr,
  1896. "mov", ".w\t$Rd, $Rm", []>, Sched<[WriteALU]> {
  1897. let Inst{31-27} = 0b11101;
  1898. let Inst{26-25} = 0b01;
  1899. let Inst{24-21} = 0b0010;
  1900. let Inst{19-16} = 0b1111; // Rn
  1901. let Inst{15} = 0b0;
  1902. let Inst{14-12} = 0b000;
  1903. let Inst{7-4} = 0b0000;
  1904. }
  1905. def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
  1906. pred:$p, zero_reg)>;
  1907. def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
  1908. pred:$p, CPSR)>;
  1909. def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm,
  1910. pred:$p, CPSR)>;
  1911. // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
  1912. let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
  1913. AddedComplexity = 1 in
  1914. def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
  1915. "mov", ".w\t$Rd, $imm",
  1916. [(set rGPR:$Rd, t2_so_imm:$imm)]>, Sched<[WriteALU]> {
  1917. let Inst{31-27} = 0b11110;
  1918. let Inst{25} = 0;
  1919. let Inst{24-21} = 0b0010;
  1920. let Inst{19-16} = 0b1111; // Rn
  1921. let Inst{15} = 0;
  1922. }
  1923. // cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
  1924. // Use aliases to get that to play nice here.
  1925. def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
  1926. pred:$p, CPSR)>;
  1927. def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
  1928. pred:$p, CPSR)>;
  1929. def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
  1930. pred:$p, zero_reg)>;
  1931. def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
  1932. pred:$p, zero_reg)>;
  1933. let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
  1934. def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
  1935. "movw", "\t$Rd, $imm",
  1936. [(set rGPR:$Rd, imm0_65535:$imm)]>, Sched<[WriteALU]>,
  1937. Requires<[IsThumb, HasV8MBaseline]> {
  1938. let Inst{31-27} = 0b11110;
  1939. let Inst{25} = 1;
  1940. let Inst{24-21} = 0b0010;
  1941. let Inst{20} = 0; // The S bit.
  1942. let Inst{15} = 0;
  1943. bits<4> Rd;
  1944. bits<16> imm;
  1945. let Inst{11-8} = Rd;
  1946. let Inst{19-16} = imm{15-12};
  1947. let Inst{26} = imm{11};
  1948. let Inst{14-12} = imm{10-8};
  1949. let Inst{7-0} = imm{7-0};
  1950. let DecoderMethod = "DecodeT2MOVTWInstruction";
  1951. }
  1952. def : InstAlias<"mov${p} $Rd, $imm",
  1953. (t2MOVi16 rGPR:$Rd, imm256_65535_expr:$imm, pred:$p), 0>,
  1954. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteALU]>;
  1955. // This gets lowered to a single 4-byte instructions
  1956. let Size = 4 in
  1957. def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
  1958. (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
  1959. Sched<[WriteALU]>;
  1960. let Constraints = "$src = $Rd" in {
  1961. def t2MOVTi16 : T2I<(outs rGPR:$Rd),
  1962. (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
  1963. "movt", "\t$Rd, $imm",
  1964. [(set rGPR:$Rd,
  1965. (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]>,
  1966. Sched<[WriteALU]>,
  1967. Requires<[IsThumb, HasV8MBaseline]> {
  1968. let Inst{31-27} = 0b11110;
  1969. let Inst{25} = 1;
  1970. let Inst{24-21} = 0b0110;
  1971. let Inst{20} = 0; // The S bit.
  1972. let Inst{15} = 0;
  1973. bits<4> Rd;
  1974. bits<16> imm;
  1975. let Inst{11-8} = Rd;
  1976. let Inst{19-16} = imm{15-12};
  1977. let Inst{26} = imm{11};
  1978. let Inst{14-12} = imm{10-8};
  1979. let Inst{7-0} = imm{7-0};
  1980. let DecoderMethod = "DecodeT2MOVTWInstruction";
  1981. }
  1982. // This gets lowered to a single 4-byte instructions
  1983. let Size = 4 in
  1984. def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
  1985. (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
  1986. Sched<[WriteALU]>, Requires<[IsThumb, HasV8MBaseline]>;
  1987. } // Constraints
  1988. def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
  1989. //===----------------------------------------------------------------------===//
  1990. // Extend Instructions.
  1991. //
  1992. // Sign extenders
  1993. def t2SXTB : T2I_ext_rrot<0b100, "sxtb">;
  1994. def t2SXTH : T2I_ext_rrot<0b000, "sxth">;
  1995. def t2SXTB16 : T2I_ext_rrot_xtb16<0b010, "sxtb16">;
  1996. def t2SXTAB : T2I_exta_rrot<0b100, "sxtab">;
  1997. def t2SXTAH : T2I_exta_rrot<0b000, "sxtah">;
  1998. def t2SXTAB16 : T2I_exta_rrot<0b010, "sxtab16">;
  1999. def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i8),
  2000. (t2SXTB rGPR:$Rn, rot_imm:$rot)>;
  2001. def : T2Pat<(sext_inreg (rotr rGPR:$Rn, rot_imm:$rot), i16),
  2002. (t2SXTH rGPR:$Rn, rot_imm:$rot)>;
  2003. def : Thumb2DSPPat<(add rGPR:$Rn,
  2004. (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i8)),
  2005. (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2006. def : Thumb2DSPPat<(add rGPR:$Rn,
  2007. (sext_inreg (rotr rGPR:$Rm, rot_imm:$rot), i16)),
  2008. (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2009. def : Thumb2DSPPat<(int_arm_sxtb16 rGPR:$Rn),
  2010. (t2SXTB16 rGPR:$Rn, 0)>;
  2011. def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, rGPR:$Rm),
  2012. (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
  2013. def : Thumb2DSPPat<(int_arm_sxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
  2014. (t2SXTB16 rGPR:$Rn, rot_imm:$rot)>;
  2015. def : Thumb2DSPPat<(int_arm_sxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
  2016. (t2SXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2017. // A simple right-shift can also be used in most cases (the exception is the
  2018. // SXTH operations with a rotate of 24: there the non-contiguous bits are
  2019. // relevant).
  2020. def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
  2021. (srl rGPR:$Rm, rot_imm:$rot), i8)),
  2022. (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2023. def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
  2024. (srl rGPR:$Rm, imm8_or_16:$rot), i16)),
  2025. (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2026. def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
  2027. (rotr rGPR:$Rm, (i32 24)), i16)),
  2028. (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
  2029. def : Thumb2DSPPat<(add rGPR:$Rn, (sext_inreg
  2030. (or (srl rGPR:$Rm, (i32 24)),
  2031. (shl rGPR:$Rm, (i32 8))), i16)),
  2032. (t2SXTAH rGPR:$Rn, rGPR:$Rm, (i32 3))>;
  2033. // Zero extenders
  2034. let AddedComplexity = 16 in {
  2035. def t2UXTB : T2I_ext_rrot<0b101, "uxtb">;
  2036. def t2UXTH : T2I_ext_rrot<0b001, "uxth">;
  2037. def t2UXTB16 : T2I_ext_rrot_xtb16<0b011, "uxtb16">;
  2038. def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x000000FF),
  2039. (t2UXTB rGPR:$Rm, rot_imm:$rot)>;
  2040. def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x0000FFFF),
  2041. (t2UXTH rGPR:$Rm, rot_imm:$rot)>;
  2042. def : Thumb2DSPPat<(and (rotr rGPR:$Rm, rot_imm:$rot), 0x00FF00FF),
  2043. (t2UXTB16 rGPR:$Rm, rot_imm:$rot)>;
  2044. def : Thumb2DSPPat<(int_arm_uxtb16 rGPR:$Rm),
  2045. (t2UXTB16 rGPR:$Rm, 0)>;
  2046. def : Thumb2DSPPat<(int_arm_uxtb16 (rotr rGPR:$Rn, rot_imm:$rot)),
  2047. (t2UXTB16 rGPR:$Rn, rot_imm:$rot)>;
  2048. // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
  2049. // The transformation should probably be done as a combiner action
  2050. // instead so we can include a check for masking back in the upper
  2051. // eight bits of the source into the lower eight bits of the result.
  2052. //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
  2053. // (t2UXTB16 rGPR:$Src, 3)>,
  2054. // Requires<[HasDSP, IsThumb2]>;
  2055. def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
  2056. (t2UXTB16 rGPR:$Src, 1)>,
  2057. Requires<[HasDSP, IsThumb2]>;
  2058. def t2UXTAB : T2I_exta_rrot<0b101, "uxtab">;
  2059. def t2UXTAH : T2I_exta_rrot<0b001, "uxtah">;
  2060. def t2UXTAB16 : T2I_exta_rrot<0b011, "uxtab16">;
  2061. def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
  2062. 0x00FF)),
  2063. (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2064. def : Thumb2DSPPat<(add rGPR:$Rn, (and (rotr rGPR:$Rm, rot_imm:$rot),
  2065. 0xFFFF)),
  2066. (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2067. def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, rot_imm:$rot),
  2068. 0xFF)),
  2069. (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2070. def : Thumb2DSPPat<(add rGPR:$Rn, (and (srl rGPR:$Rm, imm8_or_16:$rot),
  2071. 0xFFFF)),
  2072. (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2073. def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, rGPR:$Rm),
  2074. (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, 0)>;
  2075. def : Thumb2DSPPat<(int_arm_uxtab16 rGPR:$Rn, (rotr rGPR:$Rm, rot_imm:$rot)),
  2076. (t2UXTAB16 rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>;
  2077. }
  2078. //===----------------------------------------------------------------------===//
  2079. // Arithmetic Instructions.
  2080. //
  2081. let isAdd = 1 in
  2082. defm t2ADD : T2I_bin_ii12rs<0b000, "add", add, 1>;
  2083. defm t2SUB : T2I_bin_ii12rs<0b101, "sub", sub>;
  2084. // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
  2085. //
  2086. // Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
  2087. // selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
  2088. // AdjustInstrPostInstrSelection where we determine whether or not to
  2089. // set the "s" bit based on CPSR liveness.
  2090. //
  2091. // FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
  2092. // support for an optional CPSR definition that corresponds to the DAG
  2093. // node's second value. We can then eliminate the implicit def of CPSR.
  2094. defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMaddc, 1>;
  2095. defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi, ARMsubc>;
  2096. def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_imm:$imm),
  2097. (t2SUBSri $Rn, t2_so_imm:$imm)>;
  2098. def : T2Pat<(ARMsubs GPRnopc:$Rn, rGPR:$Rm), (t2SUBSrr $Rn, $Rm)>;
  2099. def : T2Pat<(ARMsubs GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
  2100. (t2SUBSrs $Rn, t2_so_reg:$ShiftedRm)>;
  2101. let hasPostISelHook = 1 in {
  2102. defm t2ADC : T2I_adde_sube_irs<0b1010, "adc", ARMadde, 1>;
  2103. defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc", ARMsube>;
  2104. }
  2105. def : t2InstSubst<"adc${s}${p} $rd, $rn, $imm",
  2106. (t2SBCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
  2107. def : t2InstSubst<"sbc${s}${p} $rd, $rn, $imm",
  2108. (t2ADCri rGPR:$rd, rGPR:$rn, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
  2109. def : t2InstSubst<"add${s}${p}.w $rd, $rn, $imm",
  2110. (t2SUBri rGPR:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
  2111. def : t2InstSubst<"sub${s}${p}.w $rd, $rn, $imm",
  2112. (t2ADDri rGPR:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
  2113. def : t2InstSubst<"subw${p} $Rd, $Rn, $imm",
  2114. (t2ADDri12 rGPR:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  2115. def : t2InstSubst<"sub${s}${p} $rd, $rn, $imm",
  2116. (t2ADDri rGPR:$rd, GPRnopc:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
  2117. def : t2InstSubst<"sub${p} $rd, $rn, $imm",
  2118. (t2ADDri12 rGPR:$rd, GPR:$rn, imm0_4095_neg:$imm, pred:$p)>;
  2119. // SP to SP alike
  2120. def : t2InstSubst<"add${s}${p}.w $rd, $rn, $imm",
  2121. (t2SUBspImm GPRsp:$rd, GPRsp:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
  2122. def : t2InstSubst<"sub${s}${p}.w $rd, $rn, $imm",
  2123. (t2ADDspImm GPRsp:$rd, GPRsp:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
  2124. def : t2InstSubst<"subw${p} $Rd, $Rn, $imm",
  2125. (t2ADDspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  2126. def : t2InstSubst<"sub${s}${p} $rd, $rn, $imm",
  2127. (t2ADDspImm GPRsp:$rd, GPRsp:$rn, t2_so_imm_neg:$imm, pred:$p, s_cc_out:$s)>;
  2128. def : t2InstSubst<"sub${p} $rd, $rn, $imm",
  2129. (t2ADDspImm12 GPRsp:$rd, GPRsp:$rn, imm0_4095_neg:$imm, pred:$p)>;
  2130. // RSB
  2131. defm t2RSB : T2I_rbin_irs <0b1110, "rsb", sub>;
  2132. // FIXME: Eliminate them if we can write def : Pat patterns which defines
  2133. // CPSR and the implicit def of CPSR is not needed.
  2134. defm t2RSBS : T2I_rbin_s_is <ARMsubc>;
  2135. // (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
  2136. // The assume-no-carry-in form uses the negation of the input since add/sub
  2137. // assume opposite meanings of the carry flag (i.e., carry == !borrow).
  2138. // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
  2139. // details.
  2140. // The AddedComplexity preferences the first variant over the others since
  2141. // it can be shrunk to a 16-bit wide encoding, while the others cannot.
  2142. let AddedComplexity = 1 in
  2143. def : T2Pat<(add rGPR:$src, imm1_255_neg:$imm),
  2144. (t2SUBri rGPR:$src, imm1_255_neg:$imm)>;
  2145. def : T2Pat<(add rGPR:$src, t2_so_imm_neg:$imm),
  2146. (t2SUBri rGPR:$src, t2_so_imm_neg:$imm)>;
  2147. def : T2Pat<(add rGPR:$src, imm0_4095_neg:$imm),
  2148. (t2SUBri12 rGPR:$src, imm0_4095_neg:$imm)>;
  2149. def : T2Pat<(add GPR:$src, imm0_65535_neg:$imm),
  2150. (t2SUBrr GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
  2151. // Do the same for v8m targets since they support movw with a 16-bit value.
  2152. def : T1Pat<(add tGPR:$src, imm0_65535_neg:$imm),
  2153. (tSUBrr tGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>,
  2154. Requires<[HasV8MBaseline]>;
  2155. let AddedComplexity = 1 in
  2156. def : T2Pat<(ARMaddc rGPR:$src, imm1_255_neg:$imm),
  2157. (t2SUBSri rGPR:$src, imm1_255_neg:$imm)>;
  2158. def : T2Pat<(ARMaddc rGPR:$src, t2_so_imm_neg:$imm),
  2159. (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
  2160. def : T2Pat<(ARMaddc rGPR:$src, imm0_65535_neg:$imm),
  2161. (t2SUBSrr rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
  2162. // The with-carry-in form matches bitwise not instead of the negation.
  2163. // Effectively, the inverse interpretation of the carry flag already accounts
  2164. // for part of the negation.
  2165. let AddedComplexity = 1 in
  2166. def : T2Pat<(ARMadde rGPR:$src, imm0_255_not:$imm, CPSR),
  2167. (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
  2168. def : T2Pat<(ARMadde rGPR:$src, t2_so_imm_not:$imm, CPSR),
  2169. (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
  2170. def : T2Pat<(ARMadde rGPR:$src, imm0_65535_neg:$imm, CPSR),
  2171. (t2SBCrr rGPR:$src, (t2MOVi16 (imm_not_XFORM imm:$imm)))>;
  2172. def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
  2173. NoItinerary, "sel", "\t$Rd, $Rn, $Rm",
  2174. [(set GPR:$Rd, (int_arm_sel GPR:$Rn, GPR:$Rm))]>,
  2175. Requires<[IsThumb2, HasDSP]> {
  2176. let Inst{31-27} = 0b11111;
  2177. let Inst{26-24} = 0b010;
  2178. let Inst{23} = 0b1;
  2179. let Inst{22-20} = 0b010;
  2180. let Inst{15-12} = 0b1111;
  2181. let Inst{7} = 0b1;
  2182. let Inst{6-4} = 0b000;
  2183. }
  2184. // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
  2185. // And Miscellaneous operations -- for disassembly only
  2186. class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
  2187. list<dag> pat, dag iops, string asm>
  2188. : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
  2189. Requires<[IsThumb2, HasDSP]> {
  2190. let Inst{31-27} = 0b11111;
  2191. let Inst{26-23} = 0b0101;
  2192. let Inst{22-20} = op22_20;
  2193. let Inst{15-12} = 0b1111;
  2194. let Inst{7-4} = op7_4;
  2195. bits<4> Rd;
  2196. bits<4> Rn;
  2197. bits<4> Rm;
  2198. let Inst{11-8} = Rd;
  2199. let Inst{19-16} = Rn;
  2200. let Inst{3-0} = Rm;
  2201. }
  2202. class T2I_pam_intrinsics<bits<3> op22_20, bits<4> op7_4, string opc,
  2203. Intrinsic intrinsic>
  2204. : T2I_pam<op22_20, op7_4, opc,
  2205. [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))],
  2206. (ins rGPR:$Rn, rGPR:$Rm), "\t$Rd, $Rn, $Rm">;
  2207. class T2I_pam_intrinsics_rev<bits<3> op22_20, bits<4> op7_4, string opc>
  2208. : T2I_pam<op22_20, op7_4, opc, [],
  2209. (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
  2210. // Saturating add/subtract
  2211. def t2QADD16 : T2I_pam_intrinsics<0b001, 0b0001, "qadd16", int_arm_qadd16>;
  2212. def t2QADD8 : T2I_pam_intrinsics<0b000, 0b0001, "qadd8", int_arm_qadd8>;
  2213. def t2QASX : T2I_pam_intrinsics<0b010, 0b0001, "qasx", int_arm_qasx>;
  2214. def t2UQSUB8 : T2I_pam_intrinsics<0b100, 0b0101, "uqsub8", int_arm_uqsub8>;
  2215. def t2QSAX : T2I_pam_intrinsics<0b110, 0b0001, "qsax", int_arm_qsax>;
  2216. def t2QSUB16 : T2I_pam_intrinsics<0b101, 0b0001, "qsub16", int_arm_qsub16>;
  2217. def t2QSUB8 : T2I_pam_intrinsics<0b100, 0b0001, "qsub8", int_arm_qsub8>;
  2218. def t2UQADD16 : T2I_pam_intrinsics<0b001, 0b0101, "uqadd16", int_arm_uqadd16>;
  2219. def t2UQADD8 : T2I_pam_intrinsics<0b000, 0b0101, "uqadd8", int_arm_uqadd8>;
  2220. def t2UQASX : T2I_pam_intrinsics<0b010, 0b0101, "uqasx", int_arm_uqasx>;
  2221. def t2UQSAX : T2I_pam_intrinsics<0b110, 0b0101, "uqsax", int_arm_uqsax>;
  2222. def t2UQSUB16 : T2I_pam_intrinsics<0b101, 0b0101, "uqsub16", int_arm_uqsub16>;
  2223. def t2QADD : T2I_pam_intrinsics_rev<0b000, 0b1000, "qadd">;
  2224. def t2QSUB : T2I_pam_intrinsics_rev<0b000, 0b1010, "qsub">;
  2225. def t2QDADD : T2I_pam_intrinsics_rev<0b000, 0b1001, "qdadd">;
  2226. def t2QDSUB : T2I_pam_intrinsics_rev<0b000, 0b1011, "qdsub">;
  2227. def : Thumb2DSPPat<(int_arm_qadd rGPR:$Rm, rGPR:$Rn),
  2228. (t2QADD rGPR:$Rm, rGPR:$Rn)>;
  2229. def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, rGPR:$Rn),
  2230. (t2QSUB rGPR:$Rm, rGPR:$Rn)>;
  2231. def : Thumb2DSPPat<(int_arm_qadd rGPR:$Rm, (int_arm_qadd rGPR:$Rn, rGPR:$Rn)),
  2232. (t2QDADD rGPR:$Rm, rGPR:$Rn)>;
  2233. def : Thumb2DSPPat<(int_arm_qsub rGPR:$Rm, (int_arm_qadd rGPR:$Rn, rGPR:$Rn)),
  2234. (t2QDSUB rGPR:$Rm, rGPR:$Rn)>;
  2235. def : Thumb2DSPPat<(saddsat rGPR:$Rm, rGPR:$Rn),
  2236. (t2QADD rGPR:$Rm, rGPR:$Rn)>;
  2237. def : Thumb2DSPPat<(ssubsat rGPR:$Rm, rGPR:$Rn),
  2238. (t2QSUB rGPR:$Rm, rGPR:$Rn)>;
  2239. def : Thumb2DSPPat<(saddsat rGPR:$Rm, (saddsat rGPR:$Rn, rGPR:$Rn)),
  2240. (t2QDADD rGPR:$Rm, rGPR:$Rn)>;
  2241. def : Thumb2DSPPat<(ssubsat rGPR:$Rm, (saddsat rGPR:$Rn, rGPR:$Rn)),
  2242. (t2QDSUB rGPR:$Rm, rGPR:$Rn)>;
  2243. def : Thumb2DSPPat<(ARMqadd8b rGPR:$Rm, rGPR:$Rn),
  2244. (t2QADD8 rGPR:$Rm, rGPR:$Rn)>;
  2245. def : Thumb2DSPPat<(ARMqsub8b rGPR:$Rm, rGPR:$Rn),
  2246. (t2QSUB8 rGPR:$Rm, rGPR:$Rn)>;
  2247. def : Thumb2DSPPat<(ARMqadd16b rGPR:$Rm, rGPR:$Rn),
  2248. (t2QADD16 rGPR:$Rm, rGPR:$Rn)>;
  2249. def : Thumb2DSPPat<(ARMqsub16b rGPR:$Rm, rGPR:$Rn),
  2250. (t2QSUB16 rGPR:$Rm, rGPR:$Rn)>;
  2251. def : Thumb2DSPPat<(ARMuqadd8b rGPR:$Rm, rGPR:$Rn),
  2252. (t2UQADD8 rGPR:$Rm, rGPR:$Rn)>;
  2253. def : Thumb2DSPPat<(ARMuqsub8b rGPR:$Rm, rGPR:$Rn),
  2254. (t2UQSUB8 rGPR:$Rm, rGPR:$Rn)>;
  2255. def : Thumb2DSPPat<(ARMuqadd16b rGPR:$Rm, rGPR:$Rn),
  2256. (t2UQADD16 rGPR:$Rm, rGPR:$Rn)>;
  2257. def : Thumb2DSPPat<(ARMuqsub16b rGPR:$Rm, rGPR:$Rn),
  2258. (t2UQSUB16 rGPR:$Rm, rGPR:$Rn)>;
  2259. // Signed/Unsigned add/subtract
  2260. def t2SASX : T2I_pam_intrinsics<0b010, 0b0000, "sasx", int_arm_sasx>;
  2261. def t2SADD16 : T2I_pam_intrinsics<0b001, 0b0000, "sadd16", int_arm_sadd16>;
  2262. def t2SADD8 : T2I_pam_intrinsics<0b000, 0b0000, "sadd8", int_arm_sadd8>;
  2263. def t2SSAX : T2I_pam_intrinsics<0b110, 0b0000, "ssax", int_arm_ssax>;
  2264. def t2SSUB16 : T2I_pam_intrinsics<0b101, 0b0000, "ssub16", int_arm_ssub16>;
  2265. def t2SSUB8 : T2I_pam_intrinsics<0b100, 0b0000, "ssub8", int_arm_ssub8>;
  2266. def t2UASX : T2I_pam_intrinsics<0b010, 0b0100, "uasx", int_arm_uasx>;
  2267. def t2UADD16 : T2I_pam_intrinsics<0b001, 0b0100, "uadd16", int_arm_uadd16>;
  2268. def t2UADD8 : T2I_pam_intrinsics<0b000, 0b0100, "uadd8", int_arm_uadd8>;
  2269. def t2USAX : T2I_pam_intrinsics<0b110, 0b0100, "usax", int_arm_usax>;
  2270. def t2USUB16 : T2I_pam_intrinsics<0b101, 0b0100, "usub16", int_arm_usub16>;
  2271. def t2USUB8 : T2I_pam_intrinsics<0b100, 0b0100, "usub8", int_arm_usub8>;
  2272. // Signed/Unsigned halving add/subtract
  2273. def t2SHASX : T2I_pam_intrinsics<0b010, 0b0010, "shasx", int_arm_shasx>;
  2274. def t2SHADD16 : T2I_pam_intrinsics<0b001, 0b0010, "shadd16", int_arm_shadd16>;
  2275. def t2SHADD8 : T2I_pam_intrinsics<0b000, 0b0010, "shadd8", int_arm_shadd8>;
  2276. def t2SHSAX : T2I_pam_intrinsics<0b110, 0b0010, "shsax", int_arm_shsax>;
  2277. def t2SHSUB16 : T2I_pam_intrinsics<0b101, 0b0010, "shsub16", int_arm_shsub16>;
  2278. def t2SHSUB8 : T2I_pam_intrinsics<0b100, 0b0010, "shsub8", int_arm_shsub8>;
  2279. def t2UHASX : T2I_pam_intrinsics<0b010, 0b0110, "uhasx", int_arm_uhasx>;
  2280. def t2UHADD16 : T2I_pam_intrinsics<0b001, 0b0110, "uhadd16", int_arm_uhadd16>;
  2281. def t2UHADD8 : T2I_pam_intrinsics<0b000, 0b0110, "uhadd8", int_arm_uhadd8>;
  2282. def t2UHSAX : T2I_pam_intrinsics<0b110, 0b0110, "uhsax", int_arm_uhsax>;
  2283. def t2UHSUB16 : T2I_pam_intrinsics<0b101, 0b0110, "uhsub16", int_arm_uhsub16>;
  2284. def t2UHSUB8 : T2I_pam_intrinsics<0b100, 0b0110, "uhsub8", int_arm_uhsub8>;
  2285. // Helper class for disassembly only
  2286. // A6.3.16 & A6.3.17
  2287. // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
  2288. class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
  2289. dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
  2290. : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
  2291. let Inst{31-27} = 0b11111;
  2292. let Inst{26-24} = 0b011;
  2293. let Inst{23} = long;
  2294. let Inst{22-20} = op22_20;
  2295. let Inst{7-4} = op7_4;
  2296. }
  2297. class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
  2298. dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
  2299. : T2FourReg<oops, iops, itin, opc, asm, pattern> {
  2300. let Inst{31-27} = 0b11111;
  2301. let Inst{26-24} = 0b011;
  2302. let Inst{23} = long;
  2303. let Inst{22-20} = op22_20;
  2304. let Inst{7-4} = op7_4;
  2305. }
  2306. // Unsigned Sum of Absolute Differences [and Accumulate].
  2307. def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
  2308. (ins rGPR:$Rn, rGPR:$Rm),
  2309. NoItinerary, "usad8", "\t$Rd, $Rn, $Rm",
  2310. [(set rGPR:$Rd, (int_arm_usad8 rGPR:$Rn, rGPR:$Rm))]>,
  2311. Requires<[IsThumb2, HasDSP]> {
  2312. let Inst{15-12} = 0b1111;
  2313. }
  2314. def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
  2315. (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
  2316. "usada8", "\t$Rd, $Rn, $Rm, $Ra",
  2317. [(set rGPR:$Rd, (int_arm_usada8 rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
  2318. Requires<[IsThumb2, HasDSP]>;
  2319. // Signed/Unsigned saturate.
  2320. class T2SatI<dag iops, string opc, string asm>
  2321. : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, []> {
  2322. bits<4> Rd;
  2323. bits<4> Rn;
  2324. bits<5> sat_imm;
  2325. bits<6> sh;
  2326. let Inst{31-24} = 0b11110011;
  2327. let Inst{21} = sh{5};
  2328. let Inst{20} = 0;
  2329. let Inst{19-16} = Rn;
  2330. let Inst{15} = 0;
  2331. let Inst{14-12} = sh{4-2};
  2332. let Inst{11-8} = Rd;
  2333. let Inst{7-6} = sh{1-0};
  2334. let Inst{5} = 0;
  2335. let Inst{4-0} = sat_imm;
  2336. }
  2337. def t2SSAT: T2SatI<(ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
  2338. "ssat", "\t$Rd, $sat_imm, $Rn$sh">,
  2339. Requires<[IsThumb2]>, Sched<[WriteALU]> {
  2340. let Inst{23-22} = 0b00;
  2341. let Inst{5} = 0;
  2342. }
  2343. def t2SSAT16: T2SatI<(ins imm1_16:$sat_imm, rGPR:$Rn),
  2344. "ssat16", "\t$Rd, $sat_imm, $Rn">,
  2345. Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
  2346. let Inst{23-22} = 0b00;
  2347. let sh = 0b100000;
  2348. let Inst{4} = 0;
  2349. }
  2350. def t2USAT: T2SatI<(ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
  2351. "usat", "\t$Rd, $sat_imm, $Rn$sh">,
  2352. Requires<[IsThumb2]>, Sched<[WriteALU]> {
  2353. let Inst{23-22} = 0b10;
  2354. }
  2355. def t2USAT16: T2SatI<(ins imm0_15:$sat_imm, rGPR:$Rn),
  2356. "usat16", "\t$Rd, $sat_imm, $Rn">,
  2357. Requires<[IsThumb2, HasDSP]>, Sched<[WriteALU]> {
  2358. let Inst{23-22} = 0b10;
  2359. let sh = 0b100000;
  2360. let Inst{4} = 0;
  2361. }
  2362. def : T2Pat<(ARMssat GPRnopc:$Rn, imm0_31:$imm),
  2363. (t2SSAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
  2364. def : T2Pat<(ARMusat GPRnopc:$Rn, imm0_31:$imm),
  2365. (t2USAT imm0_31:$imm, GPRnopc:$Rn, 0)>;
  2366. def : T2Pat<(int_arm_ssat GPR:$a, imm1_32:$pos),
  2367. (t2SSAT imm1_32:$pos, GPR:$a, 0)>;
  2368. def : T2Pat<(int_arm_usat GPR:$a, imm0_31:$pos),
  2369. (t2USAT imm0_31:$pos, GPR:$a, 0)>;
  2370. def : T2Pat<(int_arm_ssat16 GPR:$a, imm1_16:$pos),
  2371. (t2SSAT16 imm1_16:$pos, GPR:$a)>;
  2372. def : T2Pat<(int_arm_usat16 GPR:$a, imm0_15:$pos),
  2373. (t2USAT16 imm0_15:$pos, GPR:$a)>;
  2374. def : T2Pat<(int_arm_ssat (shl GPRnopc:$a, imm0_31:$shft), imm1_32:$pos),
  2375. (t2SSAT imm1_32:$pos, GPRnopc:$a, imm0_31:$shft)>;
  2376. def : T2Pat<(int_arm_ssat (sra GPRnopc:$a, asr_imm:$shft), imm1_32:$pos),
  2377. (t2SSAT imm1_32:$pos, GPRnopc:$a, asr_imm:$shft)>;
  2378. def : T2Pat<(int_arm_usat (shl GPRnopc:$a, imm0_31:$shft), imm0_31:$pos),
  2379. (t2USAT imm0_31:$pos, GPRnopc:$a, imm0_31:$shft)>;
  2380. def : T2Pat<(int_arm_usat (sra GPRnopc:$a, asr_imm:$shft), imm0_31:$pos),
  2381. (t2USAT imm0_31:$pos, GPRnopc:$a, asr_imm:$shft)>;
  2382. def : T2Pat<(ARMssat (shl GPRnopc:$a, imm0_31:$shft), imm0_31:$pos),
  2383. (t2SSAT imm0_31:$pos, GPRnopc:$a, imm0_31:$shft)>;
  2384. def : T2Pat<(ARMssat (sra GPRnopc:$Rn, asr_imm:$shft), imm0_31:$pos),
  2385. (t2SSAT imm0_31:$pos, GPRnopc:$Rn, asr_imm:$shft)>;
  2386. def : T2Pat<(ARMusat (shl GPRnopc:$a, imm0_31:$shft), imm0_31:$pos),
  2387. (t2USAT imm0_31:$pos, GPRnopc:$a, imm0_31:$shft)>;
  2388. def : T2Pat<(ARMusat (sra GPRnopc:$Rn, asr_imm:$shft), imm0_31:$pos),
  2389. (t2USAT imm0_31:$pos, GPRnopc:$Rn, asr_imm:$shft)>;
  2390. //===----------------------------------------------------------------------===//
  2391. // Shift and rotate Instructions.
  2392. //
  2393. defm t2LSL : T2I_sh_ir<0b00, "lsl", imm1_31, shl>;
  2394. defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, srl>;
  2395. defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, sra>;
  2396. defm t2ROR : T2I_sh_ir<0b11, "ror", imm1_31, rotr>;
  2397. // LSL #0 is actually MOV, and has slightly different permitted registers to
  2398. // LSL with non-zero shift
  2399. def : t2InstAlias<"lsl${s}${p} $Rd, $Rm, #0",
  2400. (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
  2401. def : t2InstAlias<"lsl${s}${p}.w $Rd, $Rm, #0",
  2402. (t2MOVr GPRnopc:$Rd, GPRnopc:$Rm, pred:$p, cc_out:$s)>;
  2403. // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
  2404. def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
  2405. (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
  2406. let Uses = [CPSR] in {
  2407. def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
  2408. "rrx", "\t$Rd, $Rm",
  2409. [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]>, Sched<[WriteALU]> {
  2410. let Inst{31-27} = 0b11101;
  2411. let Inst{26-25} = 0b01;
  2412. let Inst{24-21} = 0b0010;
  2413. let Inst{19-16} = 0b1111; // Rn
  2414. let Inst{15} = 0b0;
  2415. let Unpredictable{15} = 0b1;
  2416. let Inst{14-12} = 0b000;
  2417. let Inst{7-4} = 0b0011;
  2418. }
  2419. }
  2420. let isCodeGenOnly = 1, Defs = [CPSR] in {
  2421. def t2MOVsrl_flag : T2TwoRegShiftImm<
  2422. (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
  2423. "lsrs", ".w\t$Rd, $Rm, #1",
  2424. [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]>,
  2425. Sched<[WriteALU]> {
  2426. let Inst{31-27} = 0b11101;
  2427. let Inst{26-25} = 0b01;
  2428. let Inst{24-21} = 0b0010;
  2429. let Inst{20} = 1; // The S bit.
  2430. let Inst{19-16} = 0b1111; // Rn
  2431. let Inst{5-4} = 0b01; // Shift type.
  2432. // Shift amount = Inst{14-12:7-6} = 1.
  2433. let Inst{14-12} = 0b000;
  2434. let Inst{7-6} = 0b01;
  2435. }
  2436. def t2MOVsra_flag : T2TwoRegShiftImm<
  2437. (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
  2438. "asrs", ".w\t$Rd, $Rm, #1",
  2439. [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]>,
  2440. Sched<[WriteALU]> {
  2441. let Inst{31-27} = 0b11101;
  2442. let Inst{26-25} = 0b01;
  2443. let Inst{24-21} = 0b0010;
  2444. let Inst{20} = 1; // The S bit.
  2445. let Inst{19-16} = 0b1111; // Rn
  2446. let Inst{5-4} = 0b10; // Shift type.
  2447. // Shift amount = Inst{14-12:7-6} = 1.
  2448. let Inst{14-12} = 0b000;
  2449. let Inst{7-6} = 0b01;
  2450. }
  2451. }
  2452. //===----------------------------------------------------------------------===//
  2453. // Bitwise Instructions.
  2454. //
  2455. defm t2AND : T2I_bin_w_irs<0b0000, "and",
  2456. IIC_iBITi, IIC_iBITr, IIC_iBITsi, and, 1>;
  2457. defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
  2458. IIC_iBITi, IIC_iBITr, IIC_iBITsi, or, 1>;
  2459. defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
  2460. IIC_iBITi, IIC_iBITr, IIC_iBITsi, xor, 1>;
  2461. defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
  2462. IIC_iBITi, IIC_iBITr, IIC_iBITsi,
  2463. BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
  2464. class T2BitFI<dag oops, dag iops, InstrItinClass itin,
  2465. string opc, string asm, list<dag> pattern>
  2466. : T2I<oops, iops, itin, opc, asm, pattern> {
  2467. bits<4> Rd;
  2468. bits<5> msb;
  2469. bits<5> lsb;
  2470. let Inst{11-8} = Rd;
  2471. let Inst{4-0} = msb{4-0};
  2472. let Inst{14-12} = lsb{4-2};
  2473. let Inst{7-6} = lsb{1-0};
  2474. }
  2475. class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
  2476. string opc, string asm, list<dag> pattern>
  2477. : T2BitFI<oops, iops, itin, opc, asm, pattern> {
  2478. bits<4> Rn;
  2479. let Inst{19-16} = Rn;
  2480. }
  2481. let Constraints = "$src = $Rd" in
  2482. def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
  2483. IIC_iUNAsi, "bfc", "\t$Rd, $imm",
  2484. [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
  2485. let Inst{31-27} = 0b11110;
  2486. let Inst{26} = 0; // should be 0.
  2487. let Inst{25} = 1;
  2488. let Inst{24-20} = 0b10110;
  2489. let Inst{19-16} = 0b1111; // Rn
  2490. let Inst{15} = 0;
  2491. let Inst{5} = 0; // should be 0.
  2492. bits<10> imm;
  2493. let msb{4-0} = imm{9-5};
  2494. let lsb{4-0} = imm{4-0};
  2495. }
  2496. def t2SBFX: T2TwoRegBitFI<
  2497. (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
  2498. IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
  2499. let Inst{31-27} = 0b11110;
  2500. let Inst{25} = 1;
  2501. let Inst{24-20} = 0b10100;
  2502. let Inst{15} = 0;
  2503. let hasSideEffects = 0;
  2504. }
  2505. def t2UBFX: T2TwoRegBitFI<
  2506. (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
  2507. IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []>, Sched<[WriteALU]> {
  2508. let Inst{31-27} = 0b11110;
  2509. let Inst{25} = 1;
  2510. let Inst{24-20} = 0b11100;
  2511. let Inst{15} = 0;
  2512. let hasSideEffects = 0;
  2513. }
  2514. // A8.8.247 UDF - Undefined (Encoding T2)
  2515. def t2UDF : T2XI<(outs), (ins imm0_65535:$imm16), IIC_Br, "udf.w\t$imm16",
  2516. [(int_arm_undefined imm0_65535:$imm16)]> {
  2517. bits<16> imm16;
  2518. let Inst{31-29} = 0b111;
  2519. let Inst{28-27} = 0b10;
  2520. let Inst{26-20} = 0b1111111;
  2521. let Inst{19-16} = imm16{15-12};
  2522. let Inst{15} = 0b1;
  2523. let Inst{14-12} = 0b010;
  2524. let Inst{11-0} = imm16{11-0};
  2525. }
  2526. // A8.6.18 BFI - Bitfield insert (Encoding T1)
  2527. let Constraints = "$src = $Rd" in {
  2528. def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
  2529. (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
  2530. IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
  2531. [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
  2532. bf_inv_mask_imm:$imm))]>, Sched<[WriteALU]> {
  2533. let Inst{31-27} = 0b11110;
  2534. let Inst{26} = 0; // should be 0.
  2535. let Inst{25} = 1;
  2536. let Inst{24-20} = 0b10110;
  2537. let Inst{15} = 0;
  2538. let Inst{5} = 0; // should be 0.
  2539. bits<10> imm;
  2540. let msb{4-0} = imm{9-5};
  2541. let lsb{4-0} = imm{4-0};
  2542. }
  2543. }
  2544. defm t2ORN : T2I_bin_irs<0b0011, "orn",
  2545. IIC_iBITi, IIC_iBITr, IIC_iBITsi,
  2546. BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
  2547. def : t2InstAlias<"orn${s}${p}.w $Rd, $Rn, $imm",
  2548. (t2ORNri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  2549. def : t2InstAlias<"orn${s}${p}.w $Rd, $Rn, $Rm",
  2550. (t2ORNrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  2551. def : t2InstAlias<"orn${s}${p}.w $Rd, $Rn, $ShiftedRm",
  2552. (t2ORNrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
  2553. /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
  2554. /// unary operation that produces a value. These are predicable and can be
  2555. /// changed to modify CPSR.
  2556. multiclass T2I_un_irs<bits<4> opcod, string opc,
  2557. InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
  2558. PatFrag opnode,
  2559. bit Cheap = 0, bit ReMat = 0, bit MoveImm = 0> {
  2560. // shifted imm
  2561. def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
  2562. opc, "\t$Rd, $imm",
  2563. [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]>, Sched<[WriteALU]> {
  2564. let isAsCheapAsAMove = Cheap;
  2565. let isReMaterializable = ReMat;
  2566. let isMoveImm = MoveImm;
  2567. let Inst{31-27} = 0b11110;
  2568. let Inst{25} = 0;
  2569. let Inst{24-21} = opcod;
  2570. let Inst{19-16} = 0b1111; // Rn
  2571. let Inst{15} = 0;
  2572. }
  2573. // register
  2574. def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
  2575. opc, ".w\t$Rd, $Rm",
  2576. [(set rGPR:$Rd, (opnode rGPR:$Rm))]>, Sched<[WriteALU]> {
  2577. let Inst{31-27} = 0b11101;
  2578. let Inst{26-25} = 0b01;
  2579. let Inst{24-21} = opcod;
  2580. let Inst{19-16} = 0b1111; // Rn
  2581. let Inst{14-12} = 0b000; // imm3
  2582. let Inst{7-6} = 0b00; // imm2
  2583. let Inst{5-4} = 0b00; // type
  2584. }
  2585. // shifted register
  2586. def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
  2587. opc, ".w\t$Rd, $ShiftedRm",
  2588. [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]>,
  2589. Sched<[WriteALU]> {
  2590. let Inst{31-27} = 0b11101;
  2591. let Inst{26-25} = 0b01;
  2592. let Inst{24-21} = opcod;
  2593. let Inst{19-16} = 0b1111; // Rn
  2594. }
  2595. }
  2596. // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
  2597. let AddedComplexity = 1 in
  2598. defm t2MVN : T2I_un_irs <0b0011, "mvn",
  2599. IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
  2600. not, 1, 1, 1>;
  2601. let AddedComplexity = 1 in
  2602. def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
  2603. (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
  2604. // so_imm_notSext is needed instead of so_imm_not, as the value of imm
  2605. // will match the extended, not the original bitWidth for $src.
  2606. def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm),
  2607. (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>;
  2608. // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
  2609. def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
  2610. (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
  2611. Requires<[IsThumb2]>;
  2612. def : T2Pat<(t2_so_imm_not:$src),
  2613. (t2MVNi t2_so_imm_not:$src)>;
  2614. // There are shorter Thumb encodings for ADD than ORR, so to increase
  2615. // Thumb2SizeReduction's chances later on we select a t2ADD for an or where
  2616. // possible.
  2617. def : T2Pat<(or AddLikeOrOp:$Rn, t2_so_imm:$imm),
  2618. (t2ADDri rGPR:$Rn, t2_so_imm:$imm)>;
  2619. def : T2Pat<(or AddLikeOrOp:$Rn, imm0_4095:$Rm),
  2620. (t2ADDri12 rGPR:$Rn, imm0_4095:$Rm)>;
  2621. def : T2Pat<(or AddLikeOrOp:$Rn, non_imm32:$Rm),
  2622. (t2ADDrr $Rn, $Rm)>;
  2623. //===----------------------------------------------------------------------===//
  2624. // Multiply Instructions.
  2625. //
  2626. let isCommutable = 1 in
  2627. def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
  2628. "mul", "\t$Rd, $Rn, $Rm",
  2629. [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]>,
  2630. Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
  2631. let Inst{31-27} = 0b11111;
  2632. let Inst{26-23} = 0b0110;
  2633. let Inst{22-20} = 0b000;
  2634. let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
  2635. let Inst{7-4} = 0b0000; // Multiply
  2636. }
  2637. class T2FourRegMLA<bits<4> op7_4, string opc, list<dag> pattern>
  2638. : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
  2639. opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
  2640. Requires<[IsThumb2, UseMulOps]>,
  2641. Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
  2642. let Inst{31-27} = 0b11111;
  2643. let Inst{26-23} = 0b0110;
  2644. let Inst{22-20} = 0b000;
  2645. let Inst{7-4} = op7_4;
  2646. }
  2647. def t2MLA : T2FourRegMLA<0b0000, "mla",
  2648. [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm),
  2649. rGPR:$Ra))]>;
  2650. def t2MLS: T2FourRegMLA<0b0001, "mls",
  2651. [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn,
  2652. rGPR:$Rm)))]>;
  2653. // Extra precision multiplies with low / high results
  2654. let hasSideEffects = 0 in {
  2655. let isCommutable = 1 in {
  2656. def t2SMULL : T2MulLong<0b000, 0b0000, "smull",
  2657. [(set rGPR:$RdLo, rGPR:$RdHi,
  2658. (smullohi rGPR:$Rn, rGPR:$Rm))]>;
  2659. def t2UMULL : T2MulLong<0b010, 0b0000, "umull",
  2660. [(set rGPR:$RdLo, rGPR:$RdHi,
  2661. (umullohi rGPR:$Rn, rGPR:$Rm))]>;
  2662. } // isCommutable
  2663. // Multiply + accumulate
  2664. def t2SMLAL : T2MlaLong<0b100, 0b0000, "smlal">;
  2665. def t2UMLAL : T2MlaLong<0b110, 0b0000, "umlal">;
  2666. def t2UMAAL : T2MlaLong<0b110, 0b0110, "umaal">, Requires<[IsThumb2, HasDSP]>;
  2667. } // hasSideEffects
  2668. // Rounding variants of the below included for disassembly only
  2669. // Most significant word multiply
  2670. class T2SMMUL<bits<4> op7_4, string opc, list<dag> pattern>
  2671. : T2ThreeReg<(outs rGPR:$Rd),
  2672. (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
  2673. opc, "\t$Rd, $Rn, $Rm", pattern>,
  2674. Requires<[IsThumb2, HasDSP]>,
  2675. Sched<[WriteMUL32, ReadMUL, ReadMUL]> {
  2676. let Inst{31-27} = 0b11111;
  2677. let Inst{26-23} = 0b0110;
  2678. let Inst{22-20} = 0b101;
  2679. let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
  2680. let Inst{7-4} = op7_4;
  2681. }
  2682. def t2SMMUL : T2SMMUL<0b0000, "smmul", [(set rGPR:$Rd, (mulhs rGPR:$Rn,
  2683. rGPR:$Rm))]>;
  2684. def t2SMMULR :
  2685. T2SMMUL<0b0001, "smmulr",
  2686. [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, (i32 0)))]>;
  2687. class T2FourRegSMMLA<bits<3> op22_20, bits<4> op7_4, string opc,
  2688. list<dag> pattern>
  2689. : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
  2690. opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
  2691. Requires<[IsThumb2, HasDSP, UseMulOps]>,
  2692. Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
  2693. let Inst{31-27} = 0b11111;
  2694. let Inst{26-23} = 0b0110;
  2695. let Inst{22-20} = op22_20;
  2696. let Inst{7-4} = op7_4;
  2697. }
  2698. def t2SMMLA : T2FourRegSMMLA<0b101, 0b0000, "smmla",
  2699. [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>;
  2700. def t2SMMLAR: T2FourRegSMMLA<0b101, 0b0001, "smmlar",
  2701. [(set rGPR:$Rd, (ARMsmmlar rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
  2702. def t2SMMLS: T2FourRegSMMLA<0b110, 0b0000, "smmls", []>;
  2703. def t2SMMLSR: T2FourRegSMMLA<0b110, 0b0001, "smmlsr",
  2704. [(set rGPR:$Rd, (ARMsmmlsr rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>;
  2705. class T2ThreeRegSMUL<bits<3> op22_20, bits<2> op5_4, string opc,
  2706. list<dag> pattern>
  2707. : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16, opc,
  2708. "\t$Rd, $Rn, $Rm", pattern>,
  2709. Requires<[IsThumb2, HasDSP]>,
  2710. Sched<[WriteMUL16, ReadMUL, ReadMUL]> {
  2711. let Inst{31-27} = 0b11111;
  2712. let Inst{26-23} = 0b0110;
  2713. let Inst{22-20} = op22_20;
  2714. let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
  2715. let Inst{7-6} = 0b00;
  2716. let Inst{5-4} = op5_4;
  2717. }
  2718. def t2SMULBB : T2ThreeRegSMUL<0b001, 0b00, "smulbb",
  2719. [(set rGPR:$Rd, (bb_mul rGPR:$Rn, rGPR:$Rm))]>;
  2720. def t2SMULBT : T2ThreeRegSMUL<0b001, 0b01, "smulbt",
  2721. [(set rGPR:$Rd, (bt_mul rGPR:$Rn, rGPR:$Rm))]>;
  2722. def t2SMULTB : T2ThreeRegSMUL<0b001, 0b10, "smultb",
  2723. [(set rGPR:$Rd, (tb_mul rGPR:$Rn, rGPR:$Rm))]>;
  2724. def t2SMULTT : T2ThreeRegSMUL<0b001, 0b11, "smultt",
  2725. [(set rGPR:$Rd, (tt_mul rGPR:$Rn, rGPR:$Rm))]>;
  2726. def t2SMULWB : T2ThreeRegSMUL<0b011, 0b00, "smulwb",
  2727. [(set rGPR:$Rd, (ARMsmulwb rGPR:$Rn, rGPR:$Rm))]>;
  2728. def t2SMULWT : T2ThreeRegSMUL<0b011, 0b01, "smulwt",
  2729. [(set rGPR:$Rd, (ARMsmulwt rGPR:$Rn, rGPR:$Rm))]>;
  2730. def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_bottom_16 rGPR:$Rm)),
  2731. (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
  2732. def : Thumb2DSPPat<(mul sext_16_node:$Rn, (sext_top_16 rGPR:$Rm)),
  2733. (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
  2734. def : Thumb2DSPPat<(mul (sext_top_16 rGPR:$Rn), sext_16_node:$Rm),
  2735. (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
  2736. def : Thumb2DSPPat<(int_arm_smulbb rGPR:$Rn, rGPR:$Rm),
  2737. (t2SMULBB rGPR:$Rn, rGPR:$Rm)>;
  2738. def : Thumb2DSPPat<(int_arm_smulbt rGPR:$Rn, rGPR:$Rm),
  2739. (t2SMULBT rGPR:$Rn, rGPR:$Rm)>;
  2740. def : Thumb2DSPPat<(int_arm_smultb rGPR:$Rn, rGPR:$Rm),
  2741. (t2SMULTB rGPR:$Rn, rGPR:$Rm)>;
  2742. def : Thumb2DSPPat<(int_arm_smultt rGPR:$Rn, rGPR:$Rm),
  2743. (t2SMULTT rGPR:$Rn, rGPR:$Rm)>;
  2744. def : Thumb2DSPPat<(int_arm_smulwb rGPR:$Rn, rGPR:$Rm),
  2745. (t2SMULWB rGPR:$Rn, rGPR:$Rm)>;
  2746. def : Thumb2DSPPat<(int_arm_smulwt rGPR:$Rn, rGPR:$Rm),
  2747. (t2SMULWT rGPR:$Rn, rGPR:$Rm)>;
  2748. class T2FourRegSMLA<bits<3> op22_20, bits<2> op5_4, string opc,
  2749. list<dag> pattern>
  2750. : T2FourReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMUL16,
  2751. opc, "\t$Rd, $Rn, $Rm, $Ra", pattern>,
  2752. Requires<[IsThumb2, HasDSP, UseMulOps]>,
  2753. Sched<[WriteMAC16, ReadMUL, ReadMUL, ReadMAC]> {
  2754. let Inst{31-27} = 0b11111;
  2755. let Inst{26-23} = 0b0110;
  2756. let Inst{22-20} = op22_20;
  2757. let Inst{7-6} = 0b00;
  2758. let Inst{5-4} = op5_4;
  2759. }
  2760. def t2SMLABB : T2FourRegSMLA<0b001, 0b00, "smlabb",
  2761. [(set rGPR:$Rd, (add rGPR:$Ra, (bb_mul rGPR:$Rn, rGPR:$Rm)))]>;
  2762. def t2SMLABT : T2FourRegSMLA<0b001, 0b01, "smlabt",
  2763. [(set rGPR:$Rd, (add rGPR:$Ra, (bt_mul rGPR:$Rn, rGPR:$Rm)))]>;
  2764. def t2SMLATB : T2FourRegSMLA<0b001, 0b10, "smlatb",
  2765. [(set rGPR:$Rd, (add rGPR:$Ra, (tb_mul rGPR:$Rn, rGPR:$Rm)))]>;
  2766. def t2SMLATT : T2FourRegSMLA<0b001, 0b11, "smlatt",
  2767. [(set rGPR:$Rd, (add rGPR:$Ra, (tt_mul rGPR:$Rn, rGPR:$Rm)))]>;
  2768. def t2SMLAWB : T2FourRegSMLA<0b011, 0b00, "smlawb",
  2769. [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwb rGPR:$Rn, rGPR:$Rm)))]>;
  2770. def t2SMLAWT : T2FourRegSMLA<0b011, 0b01, "smlawt",
  2771. [(set rGPR:$Rd, (add rGPR:$Ra, (ARMsmulwt rGPR:$Rn, rGPR:$Rm)))]>;
  2772. def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn, sext_16_node:$Rm)),
  2773. (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
  2774. def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
  2775. (sext_bottom_16 rGPR:$Rm))),
  2776. (t2SMLABB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
  2777. def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul sext_16_node:$Rn,
  2778. (sext_top_16 rGPR:$Rm))),
  2779. (t2SMLABT rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
  2780. def : Thumb2DSPMulPat<(add rGPR:$Ra, (mul (sext_top_16 rGPR:$Rn),
  2781. sext_16_node:$Rm)),
  2782. (t2SMLATB rGPR:$Rn, rGPR:$Rm, rGPR:$Ra)>;
  2783. def : Thumb2DSPPat<(int_arm_smlabb GPR:$a, GPR:$b, GPR:$acc),
  2784. (t2SMLABB GPR:$a, GPR:$b, GPR:$acc)>;
  2785. def : Thumb2DSPPat<(int_arm_smlabt GPR:$a, GPR:$b, GPR:$acc),
  2786. (t2SMLABT GPR:$a, GPR:$b, GPR:$acc)>;
  2787. def : Thumb2DSPPat<(int_arm_smlatb GPR:$a, GPR:$b, GPR:$acc),
  2788. (t2SMLATB GPR:$a, GPR:$b, GPR:$acc)>;
  2789. def : Thumb2DSPPat<(int_arm_smlatt GPR:$a, GPR:$b, GPR:$acc),
  2790. (t2SMLATT GPR:$a, GPR:$b, GPR:$acc)>;
  2791. def : Thumb2DSPPat<(int_arm_smlawb GPR:$a, GPR:$b, GPR:$acc),
  2792. (t2SMLAWB GPR:$a, GPR:$b, GPR:$acc)>;
  2793. def : Thumb2DSPPat<(int_arm_smlawt GPR:$a, GPR:$b, GPR:$acc),
  2794. (t2SMLAWT GPR:$a, GPR:$b, GPR:$acc)>;
  2795. // Halfword multiple accumulate long: SMLAL<x><y>
  2796. def t2SMLALBB : T2MlaLong<0b100, 0b1000, "smlalbb">,
  2797. Requires<[IsThumb2, HasDSP]>;
  2798. def t2SMLALBT : T2MlaLong<0b100, 0b1001, "smlalbt">,
  2799. Requires<[IsThumb2, HasDSP]>;
  2800. def t2SMLALTB : T2MlaLong<0b100, 0b1010, "smlaltb">,
  2801. Requires<[IsThumb2, HasDSP]>;
  2802. def t2SMLALTT : T2MlaLong<0b100, 0b1011, "smlaltt">,
  2803. Requires<[IsThumb2, HasDSP]>;
  2804. def : Thumb2DSPPat<(ARMsmlalbb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
  2805. (t2SMLALBB $Rn, $Rm, $RLo, $RHi)>;
  2806. def : Thumb2DSPPat<(ARMsmlalbt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
  2807. (t2SMLALBT $Rn, $Rm, $RLo, $RHi)>;
  2808. def : Thumb2DSPPat<(ARMsmlaltb GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
  2809. (t2SMLALTB $Rn, $Rm, $RLo, $RHi)>;
  2810. def : Thumb2DSPPat<(ARMsmlaltt GPR:$Rn, GPR:$Rm, GPR:$RLo, GPR:$RHi),
  2811. (t2SMLALTT $Rn, $Rm, $RLo, $RHi)>;
  2812. class T2DualHalfMul<bits<3> op22_20, bits<4> op7_4, string opc,
  2813. Intrinsic intrinsic>
  2814. : T2ThreeReg_mac<0, op22_20, op7_4,
  2815. (outs rGPR:$Rd),
  2816. (ins rGPR:$Rn, rGPR:$Rm),
  2817. IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm",
  2818. [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm))]>,
  2819. Requires<[IsThumb2, HasDSP]>,
  2820. Sched<[WriteMAC32, ReadMUL, ReadMUL, ReadMAC]> {
  2821. let Inst{15-12} = 0b1111;
  2822. }
  2823. // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
  2824. def t2SMUAD: T2DualHalfMul<0b010, 0b0000, "smuad", int_arm_smuad>;
  2825. def t2SMUADX: T2DualHalfMul<0b010, 0b0001, "smuadx", int_arm_smuadx>;
  2826. def t2SMUSD: T2DualHalfMul<0b100, 0b0000, "smusd", int_arm_smusd>;
  2827. def t2SMUSDX: T2DualHalfMul<0b100, 0b0001, "smusdx", int_arm_smusdx>;
  2828. class T2DualHalfMulAdd<bits<3> op22_20, bits<4> op7_4, string opc,
  2829. Intrinsic intrinsic>
  2830. : T2FourReg_mac<0, op22_20, op7_4,
  2831. (outs rGPR:$Rd),
  2832. (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra),
  2833. IIC_iMAC32, opc, "\t$Rd, $Rn, $Rm, $Ra",
  2834. [(set rGPR:$Rd, (intrinsic rGPR:$Rn, rGPR:$Rm, rGPR:$Ra))]>,
  2835. Requires<[IsThumb2, HasDSP]>;
  2836. def t2SMLAD : T2DualHalfMulAdd<0b010, 0b0000, "smlad", int_arm_smlad>;
  2837. def t2SMLADX : T2DualHalfMulAdd<0b010, 0b0001, "smladx", int_arm_smladx>;
  2838. def t2SMLSD : T2DualHalfMulAdd<0b100, 0b0000, "smlsd", int_arm_smlsd>;
  2839. def t2SMLSDX : T2DualHalfMulAdd<0b100, 0b0001, "smlsdx", int_arm_smlsdx>;
  2840. class T2DualHalfMulAddLong<bits<3> op22_20, bits<4> op7_4, string opc>
  2841. : T2FourReg_mac<1, op22_20, op7_4,
  2842. (outs rGPR:$Ra, rGPR:$Rd),
  2843. (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
  2844. IIC_iMAC64, opc, "\t$Ra, $Rd, $Rn, $Rm", []>,
  2845. RegConstraint<"$Ra = $RLo, $Rd = $RHi">,
  2846. Requires<[IsThumb2, HasDSP]>,
  2847. Sched<[WriteMAC64Lo, WriteMAC64Hi, ReadMUL, ReadMUL, ReadMAC, ReadMAC]>;
  2848. def t2SMLALD : T2DualHalfMulAddLong<0b100, 0b1100, "smlald">;
  2849. def t2SMLALDX : T2DualHalfMulAddLong<0b100, 0b1101, "smlaldx">;
  2850. def t2SMLSLD : T2DualHalfMulAddLong<0b101, 0b1100, "smlsld">;
  2851. def t2SMLSLDX : T2DualHalfMulAddLong<0b101, 0b1101, "smlsldx">;
  2852. def : Thumb2DSPPat<(ARMSmlald rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
  2853. (t2SMLALD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
  2854. def : Thumb2DSPPat<(ARMSmlaldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
  2855. (t2SMLALDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
  2856. def : Thumb2DSPPat<(ARMSmlsld rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
  2857. (t2SMLSLD rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
  2858. def : Thumb2DSPPat<(ARMSmlsldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
  2859. (t2SMLSLDX rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi)>;
  2860. //===----------------------------------------------------------------------===//
  2861. // Division Instructions.
  2862. // Signed and unsigned division on v7-M
  2863. //
  2864. def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
  2865. "sdiv", "\t$Rd, $Rn, $Rm",
  2866. [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
  2867. Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
  2868. Sched<[WriteDIV]> {
  2869. let Inst{31-27} = 0b11111;
  2870. let Inst{26-21} = 0b011100;
  2871. let Inst{20} = 0b1;
  2872. let Inst{15-12} = 0b1111;
  2873. let Inst{7-4} = 0b1111;
  2874. }
  2875. def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
  2876. "udiv", "\t$Rd, $Rn, $Rm",
  2877. [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
  2878. Requires<[HasDivideInThumb, IsThumb, HasV8MBaseline]>,
  2879. Sched<[WriteDIV]> {
  2880. let Inst{31-27} = 0b11111;
  2881. let Inst{26-21} = 0b011101;
  2882. let Inst{20} = 0b1;
  2883. let Inst{15-12} = 0b1111;
  2884. let Inst{7-4} = 0b1111;
  2885. }
  2886. //===----------------------------------------------------------------------===//
  2887. // Misc. Arithmetic Instructions.
  2888. //
  2889. class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
  2890. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  2891. : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
  2892. let Inst{31-27} = 0b11111;
  2893. let Inst{26-22} = 0b01010;
  2894. let Inst{21-20} = op1;
  2895. let Inst{15-12} = 0b1111;
  2896. let Inst{7-6} = 0b10;
  2897. let Inst{5-4} = op2;
  2898. let Rn{3-0} = Rm;
  2899. }
  2900. def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
  2901. "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>,
  2902. Sched<[WriteALU]>;
  2903. def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
  2904. "rbit", "\t$Rd, $Rm",
  2905. [(set rGPR:$Rd, (bitreverse rGPR:$Rm))]>,
  2906. Sched<[WriteALU]>;
  2907. def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
  2908. "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>,
  2909. Sched<[WriteALU]>;
  2910. def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
  2911. "rev16", ".w\t$Rd, $Rm",
  2912. [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>,
  2913. Sched<[WriteALU]>;
  2914. def : T2Pat<(srl (bswap top16Zero:$Rn), (i32 16)),
  2915. (t2REV16 rGPR:$Rn)>;
  2916. def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
  2917. "revsh", ".w\t$Rd, $Rm",
  2918. [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>,
  2919. Sched<[WriteALU]>;
  2920. def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
  2921. (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
  2922. (t2REVSH rGPR:$Rm)>;
  2923. def t2PKHBT : T2ThreeReg<
  2924. (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
  2925. IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
  2926. [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
  2927. (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
  2928. 0xFFFF0000)))]>,
  2929. Requires<[HasDSP, IsThumb2]>,
  2930. Sched<[WriteALUsi, ReadALU]> {
  2931. let Inst{31-27} = 0b11101;
  2932. let Inst{26-25} = 0b01;
  2933. let Inst{24-20} = 0b01100;
  2934. let Inst{5} = 0; // BT form
  2935. let Inst{4} = 0;
  2936. bits<5> sh;
  2937. let Inst{14-12} = sh{4-2};
  2938. let Inst{7-6} = sh{1-0};
  2939. }
  2940. // Alternate cases for PKHBT where identities eliminate some nodes.
  2941. def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
  2942. (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
  2943. Requires<[HasDSP, IsThumb2]>;
  2944. def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
  2945. (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
  2946. Requires<[HasDSP, IsThumb2]>;
  2947. // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
  2948. // will match the pattern below.
  2949. def t2PKHTB : T2ThreeReg<
  2950. (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
  2951. IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
  2952. [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
  2953. (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
  2954. 0xFFFF)))]>,
  2955. Requires<[HasDSP, IsThumb2]>,
  2956. Sched<[WriteALUsi, ReadALU]> {
  2957. let Inst{31-27} = 0b11101;
  2958. let Inst{26-25} = 0b01;
  2959. let Inst{24-20} = 0b01100;
  2960. let Inst{5} = 1; // TB form
  2961. let Inst{4} = 0;
  2962. bits<5> sh;
  2963. let Inst{14-12} = sh{4-2};
  2964. let Inst{7-6} = sh{1-0};
  2965. }
  2966. // Alternate cases for PKHTB where identities eliminate some nodes. Note that
  2967. // a shift amount of 0 is *not legal* here, it is PKHBT instead.
  2968. // We also can not replace a srl (17..31) by an arithmetic shift we would use in
  2969. // pkhtb src1, src2, asr (17..31).
  2970. def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16:$sh)),
  2971. (t2PKHTB rGPR:$src1, rGPR:$src2, imm16:$sh)>,
  2972. Requires<[HasDSP, IsThumb2]>;
  2973. def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (sra rGPR:$src2, imm16_31:$sh)),
  2974. (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
  2975. Requires<[HasDSP, IsThumb2]>;
  2976. def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
  2977. (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
  2978. (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
  2979. Requires<[HasDSP, IsThumb2]>;
  2980. //===----------------------------------------------------------------------===//
  2981. // CRC32 Instructions
  2982. //
  2983. // Polynomials:
  2984. // + CRC32{B,H,W} 0x04C11DB7
  2985. // + CRC32C{B,H,W} 0x1EDC6F41
  2986. //
  2987. class T2I_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin>
  2988. : T2ThreeRegNoP<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), NoItinerary,
  2989. !strconcat("crc32", suffix, "\t$Rd, $Rn, $Rm"),
  2990. [(set rGPR:$Rd, (builtin rGPR:$Rn, rGPR:$Rm))]>,
  2991. Requires<[IsThumb2, HasV8, HasCRC]> {
  2992. let Inst{31-27} = 0b11111;
  2993. let Inst{26-21} = 0b010110;
  2994. let Inst{20} = C;
  2995. let Inst{15-12} = 0b1111;
  2996. let Inst{7-6} = 0b10;
  2997. let Inst{5-4} = sz;
  2998. }
  2999. def t2CRC32B : T2I_crc32<0, 0b00, "b", int_arm_crc32b>;
  3000. def t2CRC32CB : T2I_crc32<1, 0b00, "cb", int_arm_crc32cb>;
  3001. def t2CRC32H : T2I_crc32<0, 0b01, "h", int_arm_crc32h>;
  3002. def t2CRC32CH : T2I_crc32<1, 0b01, "ch", int_arm_crc32ch>;
  3003. def t2CRC32W : T2I_crc32<0, 0b10, "w", int_arm_crc32w>;
  3004. def t2CRC32CW : T2I_crc32<1, 0b10, "cw", int_arm_crc32cw>;
  3005. //===----------------------------------------------------------------------===//
  3006. // Comparison Instructions...
  3007. //
  3008. defm t2CMP : T2I_cmp_irs<0b1101, "cmp", GPRnopc,
  3009. IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi, ARMcmp>;
  3010. def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_imm:$imm),
  3011. (t2CMPri GPRnopc:$lhs, t2_so_imm:$imm)>;
  3012. def : T2Pat<(ARMcmpZ GPRnopc:$lhs, rGPR:$rhs),
  3013. (t2CMPrr GPRnopc:$lhs, rGPR:$rhs)>;
  3014. def : T2Pat<(ARMcmpZ GPRnopc:$lhs, t2_so_reg_oneuse:$rhs),
  3015. (t2CMPrs GPRnopc:$lhs, t2_so_reg_oneuse:$rhs)>;
  3016. let isCompare = 1, Defs = [CPSR] in {
  3017. // shifted imm
  3018. def t2CMNri : T2OneRegCmpImm<
  3019. (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi,
  3020. "cmn", ".w\t$Rn, $imm",
  3021. [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]>,
  3022. Sched<[WriteCMP, ReadALU]> {
  3023. let Inst{31-27} = 0b11110;
  3024. let Inst{25} = 0;
  3025. let Inst{24-21} = 0b1000;
  3026. let Inst{20} = 1; // The S bit.
  3027. let Inst{15} = 0;
  3028. let Inst{11-8} = 0b1111; // Rd
  3029. }
  3030. // register
  3031. def t2CMNzrr : T2TwoRegCmp<
  3032. (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr,
  3033. "cmn", ".w\t$Rn, $Rm",
  3034. [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
  3035. GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> {
  3036. let Inst{31-27} = 0b11101;
  3037. let Inst{26-25} = 0b01;
  3038. let Inst{24-21} = 0b1000;
  3039. let Inst{20} = 1; // The S bit.
  3040. let Inst{14-12} = 0b000; // imm3
  3041. let Inst{11-8} = 0b1111; // Rd
  3042. let Inst{7-6} = 0b00; // imm2
  3043. let Inst{5-4} = 0b00; // type
  3044. }
  3045. // shifted register
  3046. def t2CMNzrs : T2OneRegCmpShiftedReg<
  3047. (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi,
  3048. "cmn", ".w\t$Rn, $ShiftedRm",
  3049. [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
  3050. GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
  3051. Sched<[WriteCMPsi, ReadALU, ReadALU]> {
  3052. let Inst{31-27} = 0b11101;
  3053. let Inst{26-25} = 0b01;
  3054. let Inst{24-21} = 0b1000;
  3055. let Inst{20} = 1; // The S bit.
  3056. let Inst{11-8} = 0b1111; // Rd
  3057. }
  3058. }
  3059. // Assembler aliases w/o the ".w" suffix.
  3060. // No alias here for 'rr' version as not all instantiations of this multiclass
  3061. // want one (CMP in particular, does not).
  3062. def : t2InstAlias<"cmn${p} $Rn, $imm",
  3063. (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
  3064. def : t2InstAlias<"cmn${p} $Rn, $shift",
  3065. (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
  3066. def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
  3067. (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
  3068. def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm),
  3069. (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>;
  3070. defm t2TST : T2I_cmp_irs<0b0000, "tst", rGPR,
  3071. IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
  3072. BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
  3073. defm t2TEQ : T2I_cmp_irs<0b0100, "teq", rGPR,
  3074. IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
  3075. BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
  3076. // Conditional moves
  3077. let hasSideEffects = 0 in {
  3078. let isCommutable = 1, isSelect = 1 in
  3079. def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
  3080. (ins rGPR:$false, rGPR:$Rm, cmovpred:$p),
  3081. 4, IIC_iCMOVr,
  3082. [(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm,
  3083. cmovpred:$p))]>,
  3084. RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
  3085. let isMoveImm = 1 in
  3086. def t2MOVCCi
  3087. : t2PseudoInst<(outs rGPR:$Rd),
  3088. (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
  3089. 4, IIC_iCMOVi,
  3090. [(set rGPR:$Rd, (ARMcmov rGPR:$false,t2_so_imm:$imm,
  3091. cmovpred:$p))]>,
  3092. RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
  3093. let isCodeGenOnly = 1 in {
  3094. let isMoveImm = 1 in
  3095. def t2MOVCCi16
  3096. : t2PseudoInst<(outs rGPR:$Rd),
  3097. (ins rGPR:$false, imm0_65535_expr:$imm, cmovpred:$p),
  3098. 4, IIC_iCMOVi,
  3099. [(set rGPR:$Rd, (ARMcmov rGPR:$false, imm0_65535:$imm,
  3100. cmovpred:$p))]>,
  3101. RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
  3102. let isMoveImm = 1 in
  3103. def t2MVNCCi
  3104. : t2PseudoInst<(outs rGPR:$Rd),
  3105. (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
  3106. 4, IIC_iCMOVi,
  3107. [(set rGPR:$Rd,
  3108. (ARMcmov rGPR:$false, t2_so_imm_not:$imm,
  3109. cmovpred:$p))]>,
  3110. RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
  3111. class MOVCCShPseudo<SDPatternOperator opnode, Operand ty>
  3112. : t2PseudoInst<(outs rGPR:$Rd),
  3113. (ins rGPR:$false, rGPR:$Rm, i32imm:$imm, cmovpred:$p),
  3114. 4, IIC_iCMOVsi,
  3115. [(set rGPR:$Rd, (ARMcmov rGPR:$false,
  3116. (opnode rGPR:$Rm, (i32 ty:$imm)),
  3117. cmovpred:$p))]>,
  3118. RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
  3119. def t2MOVCClsl : MOVCCShPseudo<shl, imm0_31>;
  3120. def t2MOVCClsr : MOVCCShPseudo<srl, imm_sr>;
  3121. def t2MOVCCasr : MOVCCShPseudo<sra, imm_sr>;
  3122. def t2MOVCCror : MOVCCShPseudo<rotr, imm0_31>;
  3123. let isMoveImm = 1 in
  3124. def t2MOVCCi32imm
  3125. : t2PseudoInst<(outs rGPR:$dst),
  3126. (ins rGPR:$false, i32imm:$src, cmovpred:$p),
  3127. 8, IIC_iCMOVix2,
  3128. [(set rGPR:$dst, (ARMcmov rGPR:$false, imm:$src,
  3129. cmovpred:$p))]>,
  3130. RegConstraint<"$false = $dst">;
  3131. } // isCodeGenOnly = 1
  3132. } // hasSideEffects
  3133. //===----------------------------------------------------------------------===//
  3134. // Atomic operations intrinsics
  3135. //
  3136. // memory barriers protect the atomic sequences
  3137. let hasSideEffects = 1 in {
  3138. def t2DMB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
  3139. "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>,
  3140. Requires<[IsThumb, HasDB]> {
  3141. bits<4> opt;
  3142. let Inst{31-4} = 0xf3bf8f5;
  3143. let Inst{3-0} = opt;
  3144. }
  3145. def t2DSB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
  3146. "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>,
  3147. Requires<[IsThumb, HasDB]> {
  3148. bits<4> opt;
  3149. let Inst{31-4} = 0xf3bf8f4;
  3150. let Inst{3-0} = opt;
  3151. }
  3152. def t2ISB : T2I<(outs), (ins instsyncb_opt:$opt), NoItinerary,
  3153. "isb", "\t$opt", [(int_arm_isb (i32 imm0_15:$opt))]>,
  3154. Requires<[IsThumb, HasDB]> {
  3155. bits<4> opt;
  3156. let Inst{31-4} = 0xf3bf8f6;
  3157. let Inst{3-0} = opt;
  3158. }
  3159. let hasNoSchedulingInfo = 1 in
  3160. def t2TSB : T2I<(outs), (ins tsb_opt:$opt), NoItinerary,
  3161. "tsb", "\t$opt", []>, Requires<[IsThumb, HasV8_4a]> {
  3162. let Inst{31-0} = 0xf3af8012;
  3163. }
  3164. }
  3165. // Armv8.5-A speculation barrier
  3166. def t2SB : Thumb2XI<(outs), (ins), AddrModeNone, 4, NoItinerary, "sb", "", []>,
  3167. Requires<[IsThumb2, HasSB]>, Sched<[]> {
  3168. let Inst{31-0} = 0xf3bf8f70;
  3169. let Unpredictable = 0x000f2f0f;
  3170. let hasSideEffects = 1;
  3171. }
  3172. class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
  3173. InstrItinClass itin, string opc, string asm, string cstr,
  3174. list<dag> pattern, bits<4> rt2 = 0b1111>
  3175. : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
  3176. let Inst{31-27} = 0b11101;
  3177. let Inst{26-20} = 0b0001101;
  3178. let Inst{11-8} = rt2;
  3179. let Inst{7-4} = opcod;
  3180. let Inst{3-0} = 0b1111;
  3181. bits<4> addr;
  3182. bits<4> Rt;
  3183. let Inst{19-16} = addr;
  3184. let Inst{15-12} = Rt;
  3185. }
  3186. class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
  3187. InstrItinClass itin, string opc, string asm, string cstr,
  3188. list<dag> pattern, bits<4> rt2 = 0b1111>
  3189. : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
  3190. let Inst{31-27} = 0b11101;
  3191. let Inst{26-20} = 0b0001100;
  3192. let Inst{11-8} = rt2;
  3193. let Inst{7-4} = opcod;
  3194. bits<4> Rd;
  3195. bits<4> addr;
  3196. bits<4> Rt;
  3197. let Inst{3-0} = Rd;
  3198. let Inst{19-16} = addr;
  3199. let Inst{15-12} = Rt;
  3200. }
  3201. let mayLoad = 1 in {
  3202. def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3203. AddrModeNone, 4, NoItinerary,
  3204. "ldrexb", "\t$Rt, $addr", "",
  3205. [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>,
  3206. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
  3207. def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3208. AddrModeNone, 4, NoItinerary,
  3209. "ldrexh", "\t$Rt, $addr", "",
  3210. [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>,
  3211. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
  3212. def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
  3213. AddrModeT2_ldrex, 4, NoItinerary,
  3214. "ldrex", "\t$Rt, $addr", "",
  3215. [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]>,
  3216. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]> {
  3217. bits<4> Rt;
  3218. bits<12> addr;
  3219. let Inst{31-27} = 0b11101;
  3220. let Inst{26-20} = 0b0000101;
  3221. let Inst{19-16} = addr{11-8};
  3222. let Inst{15-12} = Rt;
  3223. let Inst{11-8} = 0b1111;
  3224. let Inst{7-0} = addr{7-0};
  3225. }
  3226. let hasExtraDefRegAllocReq = 1 in
  3227. def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2),
  3228. (ins addr_offset_none:$addr),
  3229. AddrModeNone, 4, NoItinerary,
  3230. "ldrexd", "\t$Rt, $Rt2, $addr", "",
  3231. [], {?, ?, ?, ?}>,
  3232. Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteLd]> {
  3233. bits<4> Rt2;
  3234. let Inst{11-8} = Rt2;
  3235. }
  3236. def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3237. AddrModeNone, 4, NoItinerary,
  3238. "ldaexb", "\t$Rt, $addr", "",
  3239. [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>,
  3240. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
  3241. def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3242. AddrModeNone, 4, NoItinerary,
  3243. "ldaexh", "\t$Rt, $addr", "",
  3244. [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>,
  3245. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
  3246. def t2LDAEX : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3247. AddrModeNone, 4, NoItinerary,
  3248. "ldaex", "\t$Rt, $addr", "",
  3249. [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>,
  3250. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]> {
  3251. bits<4> Rt;
  3252. bits<4> addr;
  3253. let Inst{31-27} = 0b11101;
  3254. let Inst{26-20} = 0b0001101;
  3255. let Inst{19-16} = addr;
  3256. let Inst{15-12} = Rt;
  3257. let Inst{11-8} = 0b1111;
  3258. let Inst{7-0} = 0b11101111;
  3259. }
  3260. let hasExtraDefRegAllocReq = 1 in
  3261. def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2),
  3262. (ins addr_offset_none:$addr),
  3263. AddrModeNone, 4, NoItinerary,
  3264. "ldaexd", "\t$Rt, $Rt2, $addr", "",
  3265. [], {?, ?, ?, ?}>, Requires<[IsThumb,
  3266. HasAcquireRelease, HasV7Clrex, IsNotMClass]>, Sched<[WriteLd]> {
  3267. bits<4> Rt2;
  3268. let Inst{11-8} = Rt2;
  3269. let Inst{7} = 1;
  3270. }
  3271. }
  3272. let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
  3273. def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd),
  3274. (ins rGPR:$Rt, addr_offset_none:$addr),
  3275. AddrModeNone, 4, NoItinerary,
  3276. "strexb", "\t$Rd, $Rt, $addr", "",
  3277. [(set rGPR:$Rd,
  3278. (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
  3279. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
  3280. def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd),
  3281. (ins rGPR:$Rt, addr_offset_none:$addr),
  3282. AddrModeNone, 4, NoItinerary,
  3283. "strexh", "\t$Rd, $Rt, $addr", "",
  3284. [(set rGPR:$Rd,
  3285. (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
  3286. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
  3287. def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
  3288. t2addrmode_imm0_1020s4:$addr),
  3289. AddrModeT2_ldrex, 4, NoItinerary,
  3290. "strex", "\t$Rd, $Rt, $addr", "",
  3291. [(set rGPR:$Rd,
  3292. (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]>,
  3293. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]> {
  3294. bits<4> Rd;
  3295. bits<4> Rt;
  3296. bits<12> addr;
  3297. let Inst{31-27} = 0b11101;
  3298. let Inst{26-20} = 0b0000100;
  3299. let Inst{19-16} = addr{11-8};
  3300. let Inst{15-12} = Rt;
  3301. let Inst{11-8} = Rd;
  3302. let Inst{7-0} = addr{7-0};
  3303. }
  3304. let hasExtraSrcRegAllocReq = 1 in
  3305. def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd),
  3306. (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
  3307. AddrModeNone, 4, NoItinerary,
  3308. "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
  3309. {?, ?, ?, ?}>,
  3310. Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteST]> {
  3311. bits<4> Rt2;
  3312. let Inst{11-8} = Rt2;
  3313. }
  3314. def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd),
  3315. (ins rGPR:$Rt, addr_offset_none:$addr),
  3316. AddrModeNone, 4, NoItinerary,
  3317. "stlexb", "\t$Rd, $Rt, $addr", "",
  3318. [(set rGPR:$Rd,
  3319. (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
  3320. Requires<[IsThumb, HasAcquireRelease,
  3321. HasV7Clrex]>, Sched<[WriteST]>;
  3322. def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd),
  3323. (ins rGPR:$Rt, addr_offset_none:$addr),
  3324. AddrModeNone, 4, NoItinerary,
  3325. "stlexh", "\t$Rd, $Rt, $addr", "",
  3326. [(set rGPR:$Rd,
  3327. (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
  3328. Requires<[IsThumb, HasAcquireRelease,
  3329. HasV7Clrex]>, Sched<[WriteST]>;
  3330. def t2STLEX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
  3331. addr_offset_none:$addr),
  3332. AddrModeNone, 4, NoItinerary,
  3333. "stlex", "\t$Rd, $Rt, $addr", "",
  3334. [(set rGPR:$Rd,
  3335. (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>,
  3336. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>,
  3337. Sched<[WriteST]> {
  3338. bits<4> Rd;
  3339. bits<4> Rt;
  3340. bits<4> addr;
  3341. let Inst{31-27} = 0b11101;
  3342. let Inst{26-20} = 0b0001100;
  3343. let Inst{19-16} = addr;
  3344. let Inst{15-12} = Rt;
  3345. let Inst{11-4} = 0b11111110;
  3346. let Inst{3-0} = Rd;
  3347. }
  3348. let hasExtraSrcRegAllocReq = 1 in
  3349. def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd),
  3350. (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
  3351. AddrModeNone, 4, NoItinerary,
  3352. "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
  3353. {?, ?, ?, ?}>, Requires<[IsThumb, HasAcquireRelease,
  3354. HasV7Clrex, IsNotMClass]>, Sched<[WriteST]> {
  3355. bits<4> Rt2;
  3356. let Inst{11-8} = Rt2;
  3357. }
  3358. }
  3359. def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>,
  3360. Requires<[IsThumb, HasV7Clrex]> {
  3361. let Inst{31-16} = 0xf3bf;
  3362. let Inst{15-14} = 0b10;
  3363. let Inst{13} = 0;
  3364. let Inst{12} = 0;
  3365. let Inst{11-8} = 0b1111;
  3366. let Inst{7-4} = 0b0010;
  3367. let Inst{3-0} = 0b1111;
  3368. }
  3369. def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
  3370. (t2LDREXB addr_offset_none:$addr)>,
  3371. Requires<[IsThumb, HasV8MBaseline]>;
  3372. def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
  3373. (t2LDREXH addr_offset_none:$addr)>,
  3374. Requires<[IsThumb, HasV8MBaseline]>;
  3375. def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
  3376. (t2STREXB GPR:$Rt, addr_offset_none:$addr)>,
  3377. Requires<[IsThumb, HasV8MBaseline]>;
  3378. def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
  3379. (t2STREXH GPR:$Rt, addr_offset_none:$addr)>,
  3380. Requires<[IsThumb, HasV8MBaseline]>;
  3381. def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff),
  3382. (t2LDAEXB addr_offset_none:$addr)>,
  3383. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3384. def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff),
  3385. (t2LDAEXH addr_offset_none:$addr)>,
  3386. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3387. def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
  3388. (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>,
  3389. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3390. def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
  3391. (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>,
  3392. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3393. //===----------------------------------------------------------------------===//
  3394. // SJLJ Exception handling intrinsics
  3395. // eh_sjlj_setjmp() is an instruction sequence to store the return
  3396. // address and save #0 in R0 for the non-longjmp case.
  3397. // Since by its nature we may be coming from some other function to get
  3398. // here, and we're using the stack frame for the containing function to
  3399. // save/restore registers, we can't keep anything live in regs across
  3400. // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
  3401. // when we get here from a longjmp(). We force everything out of registers
  3402. // except for our own input by listing the relevant registers in Defs. By
  3403. // doing so, we also cause the prologue/epilogue code to actively preserve
  3404. // all of the callee-saved registers, which is exactly what we want.
  3405. // $val is a scratch register for our use.
  3406. // This gets lowered to an instruction sequence of 12 bytes
  3407. let Defs =
  3408. [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
  3409. Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
  3410. hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1, Size = 12,
  3411. usesCustomInserter = 1 in {
  3412. def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
  3413. AddrModeNone, 0, NoItinerary, "", "",
  3414. [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
  3415. Requires<[IsThumb2, HasVFP2]>;
  3416. }
  3417. // This gets lowered to an instruction sequence of 12 bytes
  3418. let Defs =
  3419. [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
  3420. hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1, Size = 12,
  3421. usesCustomInserter = 1 in {
  3422. def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
  3423. AddrModeNone, 0, NoItinerary, "", "",
  3424. [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
  3425. Requires<[IsThumb2, NoVFP]>;
  3426. }
  3427. //===----------------------------------------------------------------------===//
  3428. // Control-Flow Instructions
  3429. //
  3430. // FIXME: remove when we have a way to marking a MI with these properties.
  3431. // FIXME: Should pc be an implicit operand like PICADD, etc?
  3432. let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
  3433. hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
  3434. def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
  3435. reglist:$regs, variable_ops),
  3436. 4, IIC_iLoad_mBr, [],
  3437. (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
  3438. RegConstraint<"$Rn = $wb">;
  3439. let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
  3440. let isPredicable = 1 in
  3441. def t2B : T2I<(outs), (ins thumb_br_target:$target), IIC_Br,
  3442. "b", ".w\t$target",
  3443. [(br bb:$target)]>, Sched<[WriteBr]>,
  3444. Requires<[IsThumb, HasV8MBaseline]> {
  3445. let Inst{31-27} = 0b11110;
  3446. let Inst{15-14} = 0b10;
  3447. let Inst{12} = 1;
  3448. bits<24> target;
  3449. let Inst{26} = target{23};
  3450. let Inst{13} = target{22};
  3451. let Inst{11} = target{21};
  3452. let Inst{25-16} = target{20-11};
  3453. let Inst{10-0} = target{10-0};
  3454. let DecoderMethod = "DecodeT2BInstruction";
  3455. let AsmMatchConverter = "cvtThumbBranches";
  3456. }
  3457. let Size = 4, isNotDuplicable = 1, isBranch = 1, isTerminator = 1,
  3458. isBarrier = 1, isIndirectBranch = 1 in {
  3459. // available in both v8-M.Baseline and Thumb2 targets
  3460. def t2BR_JT : t2basePseudoInst<(outs),
  3461. (ins GPR:$target, GPR:$index, i32imm:$jt),
  3462. 0, IIC_Br,
  3463. [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt)]>,
  3464. Sched<[WriteBr]>;
  3465. // FIXME: Add a case that can be predicated.
  3466. def t2TBB_JT : t2PseudoInst<(outs),
  3467. (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
  3468. Sched<[WriteBr]>;
  3469. def t2TBH_JT : t2PseudoInst<(outs),
  3470. (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
  3471. Sched<[WriteBr]>;
  3472. def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
  3473. "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> {
  3474. bits<4> Rn;
  3475. bits<4> Rm;
  3476. let Inst{31-20} = 0b111010001101;
  3477. let Inst{19-16} = Rn;
  3478. let Inst{15-5} = 0b11110000000;
  3479. let Inst{4} = 0; // B form
  3480. let Inst{3-0} = Rm;
  3481. let DecoderMethod = "DecodeThumbTableBranch";
  3482. }
  3483. def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
  3484. "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> {
  3485. bits<4> Rn;
  3486. bits<4> Rm;
  3487. let Inst{31-20} = 0b111010001101;
  3488. let Inst{19-16} = Rn;
  3489. let Inst{15-5} = 0b11110000000;
  3490. let Inst{4} = 1; // H form
  3491. let Inst{3-0} = Rm;
  3492. let DecoderMethod = "DecodeThumbTableBranch";
  3493. }
  3494. } // isNotDuplicable, isIndirectBranch
  3495. } // isBranch, isTerminator, isBarrier
  3496. // FIXME: should be able to write a pattern for ARMBrcond, but can't use
  3497. // a two-value operand where a dag node expects ", "two operands. :(
  3498. let isBranch = 1, isTerminator = 1 in
  3499. def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
  3500. "b", ".w\t$target",
  3501. [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> {
  3502. let Inst{31-27} = 0b11110;
  3503. let Inst{15-14} = 0b10;
  3504. let Inst{12} = 0;
  3505. bits<4> p;
  3506. let Inst{25-22} = p;
  3507. bits<21> target;
  3508. let Inst{26} = target{20};
  3509. let Inst{11} = target{19};
  3510. let Inst{13} = target{18};
  3511. let Inst{21-16} = target{17-12};
  3512. let Inst{10-0} = target{11-1};
  3513. let DecoderMethod = "DecodeThumb2BCCInstruction";
  3514. let AsmMatchConverter = "cvtThumbBranches";
  3515. }
  3516. // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so
  3517. // it goes here.
  3518. let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
  3519. // IOS version.
  3520. let Uses = [SP] in
  3521. def tTAILJMPd: tPseudoExpand<(outs),
  3522. (ins thumb_br_target:$dst, pred:$p),
  3523. 4, IIC_Br, [],
  3524. (t2B thumb_br_target:$dst, pred:$p)>,
  3525. Requires<[IsThumb2, IsMachO]>, Sched<[WriteBr]>;
  3526. }
  3527. // IT block
  3528. let Defs = [ITSTATE] in
  3529. def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
  3530. AddrModeNone, 2, IIC_iALUx,
  3531. "it$mask\t$cc", "", []>,
  3532. ComplexDeprecationPredicate<"IT"> {
  3533. // 16-bit instruction.
  3534. let Inst{31-16} = 0x0000;
  3535. let Inst{15-8} = 0b10111111;
  3536. bits<4> cc;
  3537. bits<4> mask;
  3538. let Inst{7-4} = cc;
  3539. let Inst{3-0} = mask;
  3540. let DecoderMethod = "DecodeIT";
  3541. }
  3542. // Branch and Exchange Jazelle -- for disassembly only
  3543. // Rm = Inst{19-16}
  3544. let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
  3545. def t2BXJ : T2I<(outs), (ins GPRnopc:$func), NoItinerary, "bxj", "\t$func", []>,
  3546. Sched<[WriteBr]>, Requires<[IsThumb2, IsNotMClass]> {
  3547. bits<4> func;
  3548. let Inst{31-27} = 0b11110;
  3549. let Inst{26} = 0;
  3550. let Inst{25-20} = 0b111100;
  3551. let Inst{19-16} = func;
  3552. let Inst{15-0} = 0b1000111100000000;
  3553. }
  3554. def : t2InstAlias<"bl${p}.w $func", (tBL pred:$p, thumb_bl_target:$func), 0>;
  3555. // Compare and branch on zero / non-zero
  3556. let isBranch = 1, isTerminator = 1 in {
  3557. def tCBZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
  3558. "cbz\t$Rn, $target", []>,
  3559. T1Misc<{0,0,?,1,?,?,?}>,
  3560. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
  3561. // A8.6.27
  3562. bits<6> target;
  3563. bits<3> Rn;
  3564. let Inst{9} = target{5};
  3565. let Inst{7-3} = target{4-0};
  3566. let Inst{2-0} = Rn;
  3567. }
  3568. def tCBNZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
  3569. "cbnz\t$Rn, $target", []>,
  3570. T1Misc<{1,0,?,1,?,?,?}>,
  3571. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
  3572. // A8.6.27
  3573. bits<6> target;
  3574. bits<3> Rn;
  3575. let Inst{9} = target{5};
  3576. let Inst{7-3} = target{4-0};
  3577. let Inst{2-0} = Rn;
  3578. }
  3579. }
  3580. // Change Processor State is a system instruction.
  3581. // FIXME: Since the asm parser has currently no clean way to handle optional
  3582. // operands, create 3 versions of the same instruction. Once there's a clean
  3583. // framework to represent optional operands, change this behavior.
  3584. class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
  3585. !strconcat("cps", asm_op), []>,
  3586. Requires<[IsThumb2, IsNotMClass]> {
  3587. bits<2> imod;
  3588. bits<3> iflags;
  3589. bits<5> mode;
  3590. bit M;
  3591. let Inst{31-11} = 0b111100111010111110000;
  3592. let Inst{10-9} = imod;
  3593. let Inst{8} = M;
  3594. let Inst{7-5} = iflags;
  3595. let Inst{4-0} = mode;
  3596. let DecoderMethod = "DecodeT2CPSInstruction";
  3597. }
  3598. let M = 1 in
  3599. def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
  3600. "$imod\t$iflags, $mode">;
  3601. let mode = 0, M = 0 in
  3602. def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
  3603. "$imod.w\t$iflags">;
  3604. let imod = 0, iflags = 0, M = 1 in
  3605. def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
  3606. def : t2InstAlias<"cps$imod.w $iflags, $mode",
  3607. (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>;
  3608. def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>;
  3609. // A6.3.4 Branches and miscellaneous control
  3610. // Table A6-14 Change Processor State, and hint instructions
  3611. def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm",
  3612. [(int_arm_hint imm0_239:$imm)]> {
  3613. bits<8> imm;
  3614. let Inst{31-3} = 0b11110011101011111000000000000;
  3615. let Inst{7-0} = imm;
  3616. let DecoderMethod = "DecodeT2HintSpaceInstruction";
  3617. }
  3618. def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p), 0>;
  3619. def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p), 1>;
  3620. def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p), 1>;
  3621. def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p), 1>;
  3622. def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p), 1>;
  3623. def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p), 1>;
  3624. def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p), 1> {
  3625. let Predicates = [IsThumb2, HasV8];
  3626. }
  3627. def : t2InstAlias<"esb$p.w", (t2HINT 16, pred:$p), 1> {
  3628. let Predicates = [IsThumb2, HasRAS];
  3629. }
  3630. def : t2InstAlias<"esb$p", (t2HINT 16, pred:$p), 0> {
  3631. let Predicates = [IsThumb2, HasRAS];
  3632. }
  3633. def : t2InstAlias<"csdb$p.w", (t2HINT 20, pred:$p), 0>;
  3634. def : t2InstAlias<"csdb$p", (t2HINT 20, pred:$p), 1>;
  3635. def : t2InstAlias<"pacbti$p r12,lr,sp", (t2HINT 13, pred:$p), 1>;
  3636. def : t2InstAlias<"bti$p", (t2HINT 15, pred:$p), 1>;
  3637. def : t2InstAlias<"pac$p r12,lr,sp", (t2HINT 29, pred:$p), 1>;
  3638. def : t2InstAlias<"aut$p r12,lr,sp", (t2HINT 45, pred:$p), 1>;
  3639. def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
  3640. [(int_arm_dbg imm0_15:$opt)]> {
  3641. bits<4> opt;
  3642. let Inst{31-20} = 0b111100111010;
  3643. let Inst{19-16} = 0b1111;
  3644. let Inst{15-8} = 0b10000000;
  3645. let Inst{7-4} = 0b1111;
  3646. let Inst{3-0} = opt;
  3647. }
  3648. def : t2InstAlias<"dbg${p}.w $opt", (t2DBG imm0_15:$opt, pred:$p), 0>;
  3649. // Secure Monitor Call is a system instruction.
  3650. // Option = Inst{19-16}
  3651. let isCall = 1, Uses = [SP] in
  3652. def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
  3653. []>, Requires<[IsThumb2, HasTrustZone]> {
  3654. let Inst{31-27} = 0b11110;
  3655. let Inst{26-20} = 0b1111111;
  3656. let Inst{15-12} = 0b1000;
  3657. bits<4> opt;
  3658. let Inst{19-16} = opt;
  3659. }
  3660. class T2DCPS<bits<2> opt, string opc>
  3661. : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> {
  3662. let Inst{31-27} = 0b11110;
  3663. let Inst{26-20} = 0b1111000;
  3664. let Inst{19-16} = 0b1111;
  3665. let Inst{15-12} = 0b1000;
  3666. let Inst{11-2} = 0b0000000000;
  3667. let Inst{1-0} = opt;
  3668. }
  3669. def t2DCPS1 : T2DCPS<0b01, "dcps1">;
  3670. def t2DCPS2 : T2DCPS<0b10, "dcps2">;
  3671. def t2DCPS3 : T2DCPS<0b11, "dcps3">;
  3672. class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
  3673. string opc, string asm, list<dag> pattern>
  3674. : T2I<oops, iops, itin, opc, asm, pattern>,
  3675. Requires<[IsThumb2,IsNotMClass]> {
  3676. bits<5> mode;
  3677. let Inst{31-25} = 0b1110100;
  3678. let Inst{24-23} = Op;
  3679. let Inst{22} = 0;
  3680. let Inst{21} = W;
  3681. let Inst{20-16} = 0b01101;
  3682. let Inst{15-5} = 0b11000000000;
  3683. let Inst{4-0} = mode{4-0};
  3684. }
  3685. // Store Return State is a system instruction.
  3686. def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
  3687. "srsdb", "\tsp!, $mode", []>;
  3688. def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
  3689. "srsdb","\tsp, $mode", []>;
  3690. def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
  3691. "srsia","\tsp!, $mode", []>;
  3692. def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
  3693. "srsia","\tsp, $mode", []>;
  3694. def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>;
  3695. def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>;
  3696. def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>;
  3697. def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>;
  3698. // Return From Exception is a system instruction.
  3699. let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
  3700. class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
  3701. string opc, string asm, list<dag> pattern>
  3702. : T2I<oops, iops, itin, opc, asm, pattern>,
  3703. Requires<[IsThumb2,IsNotMClass]> {
  3704. let Inst{31-20} = op31_20{11-0};
  3705. bits<4> Rn;
  3706. let Inst{19-16} = Rn;
  3707. let Inst{15-0} = 0xc000;
  3708. }
  3709. def t2RFEDBW : T2RFE<0b111010000011,
  3710. (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
  3711. [/* For disassembly only; pattern left blank */]>;
  3712. def t2RFEDB : T2RFE<0b111010000001,
  3713. (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
  3714. [/* For disassembly only; pattern left blank */]>;
  3715. def t2RFEIAW : T2RFE<0b111010011011,
  3716. (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
  3717. [/* For disassembly only; pattern left blank */]>;
  3718. def t2RFEIA : T2RFE<0b111010011001,
  3719. (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
  3720. [/* For disassembly only; pattern left blank */]>;
  3721. // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction.
  3722. // Exception return instruction is "subs pc, lr, #imm".
  3723. let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
  3724. def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
  3725. "subs", "\tpc, lr, $imm",
  3726. [(ARMintretflag imm0_255:$imm)]>,
  3727. Requires<[IsThumb2,IsNotMClass]> {
  3728. let Inst{31-8} = 0b111100111101111010001111;
  3729. bits<8> imm;
  3730. let Inst{7-0} = imm;
  3731. }
  3732. // B9.3.19 SUBS PC, LR (Thumb)
  3733. // In the Thumb instruction set, MOVS{<c>}{<q>} PC, LR is a pseudo-instruction
  3734. // for SUBS{<c>}{<q>} PC, LR, #0.
  3735. def : t2InstAlias<"movs${p}\tpc, lr", (t2SUBS_PC_LR 0, pred:$p)>;
  3736. def : t2InstAlias<"movs${p}.w\tpc, lr", (t2SUBS_PC_LR 0, pred:$p)>;
  3737. // ERET - Return from exception in Hypervisor mode.
  3738. // B9.3.3, B9.3.20: ERET is an alias for "SUBS PC, LR, #0" in an implementation that
  3739. // includes virtualization extensions.
  3740. def t2ERET : InstAlias<"eret${p}", (t2SUBS_PC_LR 0, pred:$p), 1>,
  3741. Requires<[IsThumb2, HasVirtualization]>;
  3742. // Hypervisor Call is a system instruction.
  3743. let isCall = 1 in {
  3744. def t2HVC : T2XI <(outs), (ins imm0_65535:$imm16), IIC_Br, "hvc.w\t$imm16", []>,
  3745. Requires<[IsThumb2, HasVirtualization]>, Sched<[WriteBr]> {
  3746. bits<16> imm16;
  3747. let Inst{31-20} = 0b111101111110;
  3748. let Inst{19-16} = imm16{15-12};
  3749. let Inst{15-12} = 0b1000;
  3750. let Inst{11-0} = imm16{11-0};
  3751. }
  3752. }
  3753. // Alias for HVC without the ".w" optional width specifier
  3754. def : t2InstAlias<"hvc\t$imm16", (t2HVC imm0_65535:$imm16)>;
  3755. //===----------------------------------------------------------------------===//
  3756. // Non-Instruction Patterns
  3757. //
  3758. // 32-bit immediate using movw + movt.
  3759. // This is a single pseudo instruction to make it re-materializable.
  3760. // FIXME: Remove this when we can do generalized remat.
  3761. let isReMaterializable = 1, isMoveImm = 1, Size = 8 in
  3762. def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
  3763. [(set rGPR:$dst, (i32 imm:$src))]>,
  3764. Requires<[IsThumb, UseMovt]>;
  3765. // Pseudo instruction that combines movw + movt + add pc (if pic).
  3766. // It also makes it possible to rematerialize the instructions.
  3767. // FIXME: Remove this when we can do generalized remat and when machine licm
  3768. // can properly the instructions.
  3769. let isReMaterializable = 1 in {
  3770. def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
  3771. IIC_iMOVix2addpc,
  3772. [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
  3773. Requires<[IsThumb, HasV8MBaseline, UseMovtInPic]>;
  3774. }
  3775. def : T2Pat<(ARMWrapperPIC tglobaltlsaddr :$dst),
  3776. (t2MOV_ga_pcrel tglobaltlsaddr:$dst)>,
  3777. Requires<[IsThumb2, UseMovtInPic]>;
  3778. def : T2Pat<(ARMWrapper tglobaltlsaddr:$dst),
  3779. (t2MOVi32imm tglobaltlsaddr:$dst)>,
  3780. Requires<[IsThumb2, UseMovt]>;
  3781. // ConstantPool, GlobalAddress, and JumpTable
  3782. def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
  3783. def : T2Pat<(ARMWrapper texternalsym :$dst), (t2MOVi32imm texternalsym :$dst)>,
  3784. Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
  3785. def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
  3786. Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
  3787. def : T2Pat<(ARMWrapperJT tjumptable:$dst), (t2LEApcrelJT tjumptable:$dst)>;
  3788. let hasNoSchedulingInfo = 1 in {
  3789. def t2LDRLIT_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
  3790. IIC_iLoadiALU,
  3791. [(set rGPR:$dst,
  3792. (ARMWrapperPIC tglobaladdr:$addr))]>,
  3793. Requires<[IsThumb, HasV8MBaseline, DontUseMovtInPic]>;
  3794. }
  3795. // TLS globals
  3796. def : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
  3797. (t2LDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
  3798. Requires<[IsThumb, HasV8MBaseline, DontUseMovtInPic]>;
  3799. // Pseudo instruction that combines ldr from constpool and add pc. This should
  3800. // be expanded into two instructions late to allow if-conversion and
  3801. // scheduling.
  3802. let canFoldAsLoad = 1, isReMaterializable = 1 in
  3803. def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
  3804. IIC_iLoadiALU,
  3805. [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
  3806. imm:$cp))]>,
  3807. Requires<[IsThumb2]>;
  3808. // Pseudo instruction that combines movs + predicated rsbmi
  3809. // to implement integer ABS
  3810. let usesCustomInserter = 1, Defs = [CPSR], hasNoSchedulingInfo = 1 in {
  3811. def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
  3812. NoItinerary, []>, Requires<[IsThumb2]>;
  3813. }
  3814. //===----------------------------------------------------------------------===//
  3815. // Coprocessor load/store -- for disassembly only
  3816. //
  3817. class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm,
  3818. list<dag> pattern, AddrMode am = AddrModeNone>
  3819. : T2I<oops, iops, NoItinerary, opc, asm, pattern, am> {
  3820. let Inst{31-28} = op31_28;
  3821. let Inst{27-25} = 0b110;
  3822. }
  3823. multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm, list<dag> pattern> {
  3824. def _OFFSET : T2CI<op31_28,
  3825. (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
  3826. asm, "\t$cop, $CRd, $addr", pattern, AddrMode5> {
  3827. bits<13> addr;
  3828. bits<4> cop;
  3829. bits<4> CRd;
  3830. let Inst{24} = 1; // P = 1
  3831. let Inst{23} = addr{8};
  3832. let Inst{22} = Dbit;
  3833. let Inst{21} = 0; // W = 0
  3834. let Inst{20} = load;
  3835. let Inst{19-16} = addr{12-9};
  3836. let Inst{15-12} = CRd;
  3837. let Inst{11-8} = cop;
  3838. let Inst{7-0} = addr{7-0};
  3839. let DecoderMethod = "DecodeCopMemInstruction";
  3840. }
  3841. def _PRE : T2CI<op31_28,
  3842. (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
  3843. asm, "\t$cop, $CRd, $addr!", []> {
  3844. bits<13> addr;
  3845. bits<4> cop;
  3846. bits<4> CRd;
  3847. let Inst{24} = 1; // P = 1
  3848. let Inst{23} = addr{8};
  3849. let Inst{22} = Dbit;
  3850. let Inst{21} = 1; // W = 1
  3851. let Inst{20} = load;
  3852. let Inst{19-16} = addr{12-9};
  3853. let Inst{15-12} = CRd;
  3854. let Inst{11-8} = cop;
  3855. let Inst{7-0} = addr{7-0};
  3856. let DecoderMethod = "DecodeCopMemInstruction";
  3857. }
  3858. def _POST: T2CI<op31_28,
  3859. (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
  3860. postidx_imm8s4:$offset),
  3861. asm, "\t$cop, $CRd, $addr, $offset", []> {
  3862. bits<9> offset;
  3863. bits<4> addr;
  3864. bits<4> cop;
  3865. bits<4> CRd;
  3866. let Inst{24} = 0; // P = 0
  3867. let Inst{23} = offset{8};
  3868. let Inst{22} = Dbit;
  3869. let Inst{21} = 1; // W = 1
  3870. let Inst{20} = load;
  3871. let Inst{19-16} = addr;
  3872. let Inst{15-12} = CRd;
  3873. let Inst{11-8} = cop;
  3874. let Inst{7-0} = offset{7-0};
  3875. let DecoderMethod = "DecodeCopMemInstruction";
  3876. }
  3877. def _OPTION : T2CI<op31_28, (outs),
  3878. (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
  3879. coproc_option_imm:$option),
  3880. asm, "\t$cop, $CRd, $addr, $option", []> {
  3881. bits<8> option;
  3882. bits<4> addr;
  3883. bits<4> cop;
  3884. bits<4> CRd;
  3885. let Inst{24} = 0; // P = 0
  3886. let Inst{23} = 1; // U = 1
  3887. let Inst{22} = Dbit;
  3888. let Inst{21} = 0; // W = 0
  3889. let Inst{20} = load;
  3890. let Inst{19-16} = addr;
  3891. let Inst{15-12} = CRd;
  3892. let Inst{11-8} = cop;
  3893. let Inst{7-0} = option;
  3894. let DecoderMethod = "DecodeCopMemInstruction";
  3895. }
  3896. }
  3897. let DecoderNamespace = "Thumb2CoProc" in {
  3898. defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc", [(int_arm_ldc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3899. defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl", [(int_arm_ldcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3900. defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2", [(int_arm_ldc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3901. defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l", [(int_arm_ldc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3902. defm t2STC : t2LdStCop<0b1110, 0, 0, "stc", [(int_arm_stc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3903. defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl", [(int_arm_stcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3904. defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2", [(int_arm_stc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3905. defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l", [(int_arm_stc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3906. }
  3907. //===----------------------------------------------------------------------===//
  3908. // Move between special register and ARM core register -- for disassembly only
  3909. //
  3910. // Move to ARM core register from Special Register
  3911. // A/R class MRS.
  3912. //
  3913. // A/R class can only move from CPSR or SPSR.
  3914. def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
  3915. []>, Requires<[IsThumb2,IsNotMClass]> {
  3916. bits<4> Rd;
  3917. let Inst{31-12} = 0b11110011111011111000;
  3918. let Inst{11-8} = Rd;
  3919. let Inst{7-0} = 0b00000000;
  3920. }
  3921. def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
  3922. def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
  3923. []>, Requires<[IsThumb2,IsNotMClass]> {
  3924. bits<4> Rd;
  3925. let Inst{31-12} = 0b11110011111111111000;
  3926. let Inst{11-8} = Rd;
  3927. let Inst{7-0} = 0b00000000;
  3928. }
  3929. def t2MRSbanked : T2I<(outs rGPR:$Rd), (ins banked_reg:$banked),
  3930. NoItinerary, "mrs", "\t$Rd, $banked", []>,
  3931. Requires<[IsThumb, HasVirtualization]> {
  3932. bits<6> banked;
  3933. bits<4> Rd;
  3934. let Inst{31-21} = 0b11110011111;
  3935. let Inst{20} = banked{5}; // R bit
  3936. let Inst{19-16} = banked{3-0};
  3937. let Inst{15-12} = 0b1000;
  3938. let Inst{11-8} = Rd;
  3939. let Inst{7-5} = 0b001;
  3940. let Inst{4} = banked{4};
  3941. let Inst{3-0} = 0b0000;
  3942. }
  3943. // M class MRS.
  3944. //
  3945. // This MRS has a mask field in bits 7-0 and can take more values than
  3946. // the A/R class (a full msr_mask).
  3947. def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$SYSm), NoItinerary,
  3948. "mrs", "\t$Rd, $SYSm", []>,
  3949. Requires<[IsThumb,IsMClass]> {
  3950. bits<4> Rd;
  3951. bits<8> SYSm;
  3952. let Inst{31-12} = 0b11110011111011111000;
  3953. let Inst{11-8} = Rd;
  3954. let Inst{7-0} = SYSm;
  3955. let Unpredictable{20-16} = 0b11111;
  3956. let Unpredictable{13} = 0b1;
  3957. }
  3958. // Move from ARM core register to Special Register
  3959. //
  3960. // A/R class MSR.
  3961. //
  3962. // No need to have both system and application versions, the encodings are the
  3963. // same and the assembly parser has no way to distinguish between them. The mask
  3964. // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
  3965. // the mask with the fields to be accessed in the special register.
  3966. let Defs = [CPSR] in
  3967. def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
  3968. NoItinerary, "msr", "\t$mask, $Rn", []>,
  3969. Requires<[IsThumb2,IsNotMClass]> {
  3970. bits<5> mask;
  3971. bits<4> Rn;
  3972. let Inst{31-21} = 0b11110011100;
  3973. let Inst{20} = mask{4}; // R Bit
  3974. let Inst{19-16} = Rn;
  3975. let Inst{15-12} = 0b1000;
  3976. let Inst{11-8} = mask{3-0};
  3977. let Inst{7-0} = 0;
  3978. }
  3979. // However, the MSR (banked register) system instruction (ARMv7VE) *does* have a
  3980. // separate encoding (distinguished by bit 5.
  3981. def t2MSRbanked : T2I<(outs), (ins banked_reg:$banked, rGPR:$Rn),
  3982. NoItinerary, "msr", "\t$banked, $Rn", []>,
  3983. Requires<[IsThumb, HasVirtualization]> {
  3984. bits<6> banked;
  3985. bits<4> Rn;
  3986. let Inst{31-21} = 0b11110011100;
  3987. let Inst{20} = banked{5}; // R bit
  3988. let Inst{19-16} = Rn;
  3989. let Inst{15-12} = 0b1000;
  3990. let Inst{11-8} = banked{3-0};
  3991. let Inst{7-5} = 0b001;
  3992. let Inst{4} = banked{4};
  3993. let Inst{3-0} = 0b0000;
  3994. }
  3995. // M class MSR.
  3996. //
  3997. // Move from ARM core register to Special Register
  3998. let Defs = [CPSR] in
  3999. def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
  4000. NoItinerary, "msr", "\t$SYSm, $Rn", []>,
  4001. Requires<[IsThumb,IsMClass]> {
  4002. bits<12> SYSm;
  4003. bits<4> Rn;
  4004. let Inst{31-21} = 0b11110011100;
  4005. let Inst{20} = 0b0;
  4006. let Inst{19-16} = Rn;
  4007. let Inst{15-12} = 0b1000;
  4008. let Inst{11-10} = SYSm{11-10};
  4009. let Inst{9-8} = 0b00;
  4010. let Inst{7-0} = SYSm{7-0};
  4011. let Unpredictable{20} = 0b1;
  4012. let Unpredictable{13} = 0b1;
  4013. let Unpredictable{9-8} = 0b11;
  4014. }
  4015. //===----------------------------------------------------------------------===//
  4016. // Move between coprocessor and ARM core register
  4017. //
  4018. class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
  4019. list<dag> pattern>
  4020. : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2",
  4021. pattern> {
  4022. let Inst{27-24} = 0b1110;
  4023. let Inst{20} = direction;
  4024. let Inst{4} = 1;
  4025. bits<4> Rt;
  4026. bits<4> cop;
  4027. bits<3> opc1;
  4028. bits<3> opc2;
  4029. bits<4> CRm;
  4030. bits<4> CRn;
  4031. let Inst{15-12} = Rt;
  4032. let Inst{11-8} = cop;
  4033. let Inst{23-21} = opc1;
  4034. let Inst{7-5} = opc2;
  4035. let Inst{3-0} = CRm;
  4036. let Inst{19-16} = CRn;
  4037. let DecoderNamespace = "Thumb2CoProc";
  4038. }
  4039. class t2MovRRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
  4040. list<dag> pattern = []>
  4041. : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
  4042. let Inst{27-24} = 0b1100;
  4043. let Inst{23-21} = 0b010;
  4044. let Inst{20} = direction;
  4045. bits<4> Rt;
  4046. bits<4> Rt2;
  4047. bits<4> cop;
  4048. bits<4> opc1;
  4049. bits<4> CRm;
  4050. let Inst{15-12} = Rt;
  4051. let Inst{19-16} = Rt2;
  4052. let Inst{11-8} = cop;
  4053. let Inst{7-4} = opc1;
  4054. let Inst{3-0} = CRm;
  4055. let DecoderNamespace = "Thumb2CoProc";
  4056. }
  4057. /* from ARM core register to coprocessor */
  4058. def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
  4059. (outs),
  4060. (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4061. c_imm:$CRm, imm0_7:$opc2),
  4062. [(int_arm_mcr timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
  4063. timm:$CRm, timm:$opc2)]>,
  4064. ComplexDeprecationPredicate<"MCR">;
  4065. def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4066. (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4067. c_imm:$CRm, 0, pred:$p)>;
  4068. def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
  4069. (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4070. c_imm:$CRm, imm0_7:$opc2),
  4071. [(int_arm_mcr2 timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
  4072. timm:$CRm, timm:$opc2)]> {
  4073. let Predicates = [IsThumb2, PreV8];
  4074. }
  4075. def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4076. (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4077. c_imm:$CRm, 0, pred:$p)>;
  4078. /* from coprocessor to ARM core register */
  4079. def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
  4080. (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4081. c_imm:$CRm, imm0_7:$opc2), []>;
  4082. def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4083. (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4084. c_imm:$CRm, 0, pred:$p)>;
  4085. def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
  4086. (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4087. c_imm:$CRm, imm0_7:$opc2), []> {
  4088. let Predicates = [IsThumb2, PreV8];
  4089. }
  4090. def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4091. (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4092. c_imm:$CRm, 0, pred:$p)>;
  4093. def : T2v6Pat<(int_arm_mrc timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
  4094. (t2MRC p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
  4095. def : T2v6Pat<(int_arm_mrc2 timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
  4096. (t2MRC2 p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
  4097. /* from ARM core register to coprocessor */
  4098. def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, (outs),
  4099. (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
  4100. c_imm:$CRm),
  4101. [(int_arm_mcrr timm:$cop, timm:$opc1, GPR:$Rt, GPR:$Rt2,
  4102. timm:$CRm)]>;
  4103. def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, (outs),
  4104. (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
  4105. c_imm:$CRm),
  4106. [(int_arm_mcrr2 timm:$cop, timm:$opc1, GPR:$Rt,
  4107. GPR:$Rt2, timm:$CRm)]> {
  4108. let Predicates = [IsThumb2, PreV8];
  4109. }
  4110. /* from coprocessor to ARM core register */
  4111. def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1, (outs GPR:$Rt, GPR:$Rt2),
  4112. (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)>;
  4113. def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1, (outs GPR:$Rt, GPR:$Rt2),
  4114. (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)> {
  4115. let Predicates = [IsThumb2, PreV8];
  4116. }
  4117. //===----------------------------------------------------------------------===//
  4118. // Other Coprocessor Instructions.
  4119. //
  4120. def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
  4121. c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
  4122. "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
  4123. [(int_arm_cdp timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
  4124. timm:$CRm, timm:$opc2)]> {
  4125. let Inst{27-24} = 0b1110;
  4126. bits<4> opc1;
  4127. bits<4> CRn;
  4128. bits<4> CRd;
  4129. bits<4> cop;
  4130. bits<3> opc2;
  4131. bits<4> CRm;
  4132. let Inst{3-0} = CRm;
  4133. let Inst{4} = 0;
  4134. let Inst{7-5} = opc2;
  4135. let Inst{11-8} = cop;
  4136. let Inst{15-12} = CRd;
  4137. let Inst{19-16} = CRn;
  4138. let Inst{23-20} = opc1;
  4139. let Predicates = [IsThumb2, PreV8];
  4140. let DecoderNamespace = "Thumb2CoProc";
  4141. }
  4142. def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
  4143. c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
  4144. "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
  4145. [(int_arm_cdp2 timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
  4146. timm:$CRm, timm:$opc2)]> {
  4147. let Inst{27-24} = 0b1110;
  4148. bits<4> opc1;
  4149. bits<4> CRn;
  4150. bits<4> CRd;
  4151. bits<4> cop;
  4152. bits<3> opc2;
  4153. bits<4> CRm;
  4154. let Inst{3-0} = CRm;
  4155. let Inst{4} = 0;
  4156. let Inst{7-5} = opc2;
  4157. let Inst{11-8} = cop;
  4158. let Inst{15-12} = CRd;
  4159. let Inst{19-16} = CRn;
  4160. let Inst{23-20} = opc1;
  4161. let Predicates = [IsThumb2, PreV8];
  4162. let DecoderNamespace = "Thumb2CoProc";
  4163. }
  4164. // Reading thread pointer from coprocessor register
  4165. def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
  4166. Requires<[IsThumb2, IsReadTPHard]>;
  4167. //===----------------------------------------------------------------------===//
  4168. // ARMv8.1 Privilege Access Never extension
  4169. //
  4170. // SETPAN #imm1
  4171. def t2SETPAN : T1I<(outs), (ins imm0_1:$imm), NoItinerary, "setpan\t$imm", []>,
  4172. T1Misc<0b0110000>, Requires<[IsThumb2, HasV8, HasV8_1a]> {
  4173. bits<1> imm;
  4174. let Inst{4} = 0b1;
  4175. let Inst{3} = imm;
  4176. let Inst{2-0} = 0b000;
  4177. let Unpredictable{4} = 0b1;
  4178. let Unpredictable{2-0} = 0b111;
  4179. }
  4180. //===----------------------------------------------------------------------===//
  4181. // ARMv8-M Security Extensions instructions
  4182. //
  4183. let hasSideEffects = 1 in
  4184. def t2SG : T2I<(outs), (ins), NoItinerary, "sg", "", []>,
  4185. Requires<[Has8MSecExt]> {
  4186. let Inst = 0xe97fe97f;
  4187. }
  4188. class T2TT<bits<2> at, string asm, list<dag> pattern>
  4189. : T2I<(outs rGPR:$Rt), (ins GPRnopc:$Rn), NoItinerary, asm, "\t$Rt, $Rn",
  4190. pattern> {
  4191. bits<4> Rn;
  4192. bits<4> Rt;
  4193. let Inst{31-20} = 0b111010000100;
  4194. let Inst{19-16} = Rn;
  4195. let Inst{15-12} = 0b1111;
  4196. let Inst{11-8} = Rt;
  4197. let Inst{7-6} = at;
  4198. let Inst{5-0} = 0b000000;
  4199. let Unpredictable{5-0} = 0b111111;
  4200. }
  4201. def t2TT : T2TT<0b00, "tt",
  4202. [(set rGPR:$Rt, (int_arm_cmse_tt GPRnopc:$Rn))]>,
  4203. Requires<[IsThumb, Has8MSecExt]>;
  4204. def t2TTT : T2TT<0b01, "ttt",
  4205. [(set rGPR:$Rt, (int_arm_cmse_ttt GPRnopc:$Rn))]>,
  4206. Requires<[IsThumb, Has8MSecExt]>;
  4207. def t2TTA : T2TT<0b10, "tta",
  4208. [(set rGPR:$Rt, (int_arm_cmse_tta GPRnopc:$Rn))]>,
  4209. Requires<[IsThumb, Has8MSecExt]>;
  4210. def t2TTAT : T2TT<0b11, "ttat",
  4211. [(set rGPR:$Rt, (int_arm_cmse_ttat GPRnopc:$Rn))]>,
  4212. Requires<[IsThumb, Has8MSecExt]>;
  4213. //===----------------------------------------------------------------------===//
  4214. // Non-Instruction Patterns
  4215. //
  4216. // SXT/UXT with no rotate
  4217. let AddedComplexity = 16 in {
  4218. def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
  4219. Requires<[IsThumb2]>;
  4220. def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
  4221. Requires<[IsThumb2]>;
  4222. def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
  4223. Requires<[HasDSP, IsThumb2]>;
  4224. def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
  4225. (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
  4226. Requires<[HasDSP, IsThumb2]>;
  4227. def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
  4228. (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
  4229. Requires<[HasDSP, IsThumb2]>;
  4230. }
  4231. def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
  4232. Requires<[IsThumb2]>;
  4233. def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
  4234. Requires<[IsThumb2]>;
  4235. def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
  4236. (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
  4237. Requires<[HasDSP, IsThumb2]>;
  4238. def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
  4239. (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
  4240. Requires<[HasDSP, IsThumb2]>;
  4241. // Atomic load/store patterns
  4242. def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr),
  4243. (t2LDRBi12 t2addrmode_imm12:$addr)>;
  4244. def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr),
  4245. (t2LDRBi8 t2addrmode_negimm8:$addr)>;
  4246. def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr),
  4247. (t2LDRBs t2addrmode_so_reg:$addr)>;
  4248. def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr),
  4249. (t2LDRHi12 t2addrmode_imm12:$addr)>;
  4250. def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr),
  4251. (t2LDRHi8 t2addrmode_negimm8:$addr)>;
  4252. def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr),
  4253. (t2LDRHs t2addrmode_so_reg:$addr)>;
  4254. def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr),
  4255. (t2LDRi12 t2addrmode_imm12:$addr)>;
  4256. def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr),
  4257. (t2LDRi8 t2addrmode_negimm8:$addr)>;
  4258. def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr),
  4259. (t2LDRs t2addrmode_so_reg:$addr)>;
  4260. def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val),
  4261. (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>;
  4262. def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val),
  4263. (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>;
  4264. def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val),
  4265. (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>;
  4266. def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
  4267. (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>;
  4268. def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
  4269. (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>;
  4270. def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
  4271. (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>;
  4272. def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
  4273. (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>;
  4274. def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
  4275. (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>;
  4276. def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
  4277. (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>;
  4278. let AddedComplexity = 8, Predicates = [IsThumb, HasAcquireRelease, HasV7Clrex] in {
  4279. def : Pat<(atomic_load_acquire_8 addr_offset_none:$addr), (t2LDAB addr_offset_none:$addr)>;
  4280. def : Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>;
  4281. def : Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA addr_offset_none:$addr)>;
  4282. def : Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val), (t2STLB GPR:$val, addr_offset_none:$addr)>;
  4283. def : Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>;
  4284. def : Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL GPR:$val, addr_offset_none:$addr)>;
  4285. }
  4286. //===----------------------------------------------------------------------===//
  4287. // Assembler aliases
  4288. //
  4289. // Aliases for ADC without the ".w" optional width specifier.
  4290. def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
  4291. (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4292. def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
  4293. (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
  4294. pred:$p, cc_out:$s)>;
  4295. // Aliases for SBC without the ".w" optional width specifier.
  4296. def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
  4297. (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4298. def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
  4299. (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
  4300. pred:$p, cc_out:$s)>;
  4301. // Aliases for ADD without the ".w" optional width specifier.
  4302. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
  4303. (t2ADDri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p,
  4304. cc_out:$s)>;
  4305. def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
  4306. (t2ADDri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
  4307. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
  4308. (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4309. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
  4310. (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
  4311. pred:$p, cc_out:$s)>;
  4312. // ... and with the destination and source register combined.
  4313. def : t2InstAlias<"add${s}${p} $Rdn, $imm",
  4314. (t2ADDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4315. def : t2InstAlias<"add${p} $Rdn, $imm",
  4316. (t2ADDri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4317. def : t2InstAlias<"addw${p} $Rdn, $imm",
  4318. (t2ADDri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4319. def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
  4320. (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4321. def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
  4322. (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
  4323. pred:$p, cc_out:$s)>;
  4324. // add w/ negative immediates is just a sub.
  4325. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4326. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4327. cc_out:$s)>;
  4328. def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
  4329. (t2SUBri12 rGPR:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4330. def : t2InstSubst<"add${s}${p} $Rdn, $imm",
  4331. (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4332. cc_out:$s)>;
  4333. def : t2InstSubst<"add${p} $Rdn, $imm",
  4334. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4335. def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
  4336. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4337. cc_out:$s)>;
  4338. def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
  4339. (t2SUBri12 rGPR:$Rd, rGPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4340. def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
  4341. (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4342. cc_out:$s)>;
  4343. def : t2InstSubst<"addw${p} $Rdn, $imm",
  4344. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4345. // Aliases for SUB without the ".w" optional width specifier.
  4346. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
  4347. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4348. def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
  4349. (t2SUBri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
  4350. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
  4351. (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4352. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
  4353. (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
  4354. pred:$p, cc_out:$s)>;
  4355. // ... and with the destination and source register combined.
  4356. def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
  4357. (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4358. def : t2InstAlias<"sub${p} $Rdn, $imm",
  4359. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4360. def : t2InstAlias<"subw${p} $Rdn, $imm",
  4361. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4362. def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
  4363. (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4364. def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
  4365. (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4366. def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
  4367. (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
  4368. pred:$p, cc_out:$s)>;
  4369. // SP to SP alike aliases
  4370. // Aliases for ADD without the ".w" optional width specifier.
  4371. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
  4372. (t2ADDspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm:$imm, pred:$p,
  4373. cc_out:$s)>;
  4374. def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
  4375. (t2ADDspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095:$imm, pred:$p)>;
  4376. // ... and with the destination and source register combined.
  4377. def : t2InstAlias<"add${s}${p} $Rdn, $imm",
  4378. (t2ADDspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4379. def : t2InstAlias<"add${s}${p}.w $Rdn, $imm",
  4380. (t2ADDspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4381. def : t2InstAlias<"add${p} $Rdn, $imm",
  4382. (t2ADDspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4383. def : t2InstAlias<"addw${p} $Rdn, $imm",
  4384. (t2ADDspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4385. // add w/ negative immediates is just a sub.
  4386. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4387. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4388. cc_out:$s)>;
  4389. def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
  4390. (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4391. def : t2InstSubst<"add${s}${p} $Rdn, $imm",
  4392. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4393. cc_out:$s)>;
  4394. def : t2InstSubst<"add${p} $Rdn, $imm",
  4395. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4396. def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
  4397. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4398. cc_out:$s)>;
  4399. def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
  4400. (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4401. def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
  4402. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4403. cc_out:$s)>;
  4404. def : t2InstSubst<"addw${p} $Rdn, $imm",
  4405. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4406. // Aliases for SUB without the ".w" optional width specifier.
  4407. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
  4408. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4409. def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
  4410. (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095:$imm, pred:$p)>;
  4411. // ... and with the destination and source register combined.
  4412. def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
  4413. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4414. def : t2InstAlias<"sub${s}${p}.w $Rdn, $imm",
  4415. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4416. def : t2InstAlias<"sub${p} $Rdn, $imm",
  4417. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4418. def : t2InstAlias<"subw${p} $Rdn, $imm",
  4419. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4420. // Alias for compares without the ".w" optional width specifier.
  4421. def : t2InstAlias<"cmn${p} $Rn, $Rm",
  4422. (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
  4423. def : t2InstAlias<"teq${p} $Rn, $Rm",
  4424. (t2TEQrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
  4425. def : t2InstAlias<"tst${p} $Rn, $Rm",
  4426. (t2TSTrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
  4427. // Memory barriers
  4428. def : InstAlias<"dmb${p}.w\t$opt", (t2DMB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
  4429. def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4430. def : InstAlias<"dmb${p}.w", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4431. def : InstAlias<"dsb${p}.w\t$opt", (t2DSB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
  4432. def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4433. def : InstAlias<"dsb${p}.w", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4434. def : InstAlias<"isb${p}.w\t$opt", (t2ISB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
  4435. def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4436. def : InstAlias<"isb${p}.w", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4437. // Non-predicable aliases of a predicable DSB: the predicate is (14, 0) where
  4438. // 14 = AL (always execute) and 0 = "instruction doesn't read the CPSR".
  4439. def : InstAlias<"ssbb", (t2DSB 0x0, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
  4440. def : InstAlias<"pssbb", (t2DSB 0x4, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
  4441. // Armv8-R 'Data Full Barrier'
  4442. def : InstAlias<"dfb${p}", (t2DSB 0xc, pred:$p), 1>, Requires<[HasDFB]>;
  4443. // SpeculationBarrierEndBB must only be used after an unconditional control
  4444. // flow, i.e. after a terminator for which isBarrier is True.
  4445. let hasSideEffects = 1, isCodeGenOnly = 1, isTerminator = 1, isBarrier = 1 in {
  4446. // This gets lowered to a pair of 4-byte instructions
  4447. let Size = 8 in
  4448. def t2SpeculationBarrierISBDSBEndBB
  4449. : PseudoInst<(outs), (ins), NoItinerary, []>, Sched<[]>;
  4450. // This gets lowered to a single 4-byte instructions
  4451. let Size = 4 in
  4452. def t2SpeculationBarrierSBEndBB
  4453. : PseudoInst<(outs), (ins), NoItinerary, []>, Sched<[]>;
  4454. }
  4455. // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
  4456. // width specifier.
  4457. def : t2InstAlias<"ldr${p} $Rt, $addr",
  4458. (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4459. def : t2InstAlias<"ldrb${p} $Rt, $addr",
  4460. (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4461. def : t2InstAlias<"ldrh${p} $Rt, $addr",
  4462. (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4463. def : t2InstAlias<"ldrsb${p} $Rt, $addr",
  4464. (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4465. def : t2InstAlias<"ldrsh${p} $Rt, $addr",
  4466. (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4467. def : t2InstAlias<"ldr${p} $Rt, $addr",
  4468. (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4469. def : t2InstAlias<"ldrb${p} $Rt, $addr",
  4470. (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4471. def : t2InstAlias<"ldrh${p} $Rt, $addr",
  4472. (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4473. def : t2InstAlias<"ldrsb${p} $Rt, $addr",
  4474. (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4475. def : t2InstAlias<"ldrsh${p} $Rt, $addr",
  4476. (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4477. def : t2InstAlias<"ldr${p} $Rt, $addr",
  4478. (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4479. def : t2InstAlias<"ldrb${p} $Rt, $addr",
  4480. (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4481. def : t2InstAlias<"ldrh${p} $Rt, $addr",
  4482. (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4483. def : t2InstAlias<"ldrsb${p} $Rt, $addr",
  4484. (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4485. def : t2InstAlias<"ldrsh${p} $Rt, $addr",
  4486. (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4487. // Alias for MVN with(out) the ".w" optional width specifier.
  4488. def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
  4489. (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4490. def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
  4491. (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4492. def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
  4493. (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
  4494. // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT with the
  4495. // input operands swapped when the shift amount is zero (i.e., unspecified).
  4496. def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
  4497. (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4498. Requires<[HasDSP, IsThumb2]>;
  4499. def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
  4500. (t2PKHBT rGPR:$Rd, rGPR:$Rm, rGPR:$Rn, 0, pred:$p), 0>,
  4501. Requires<[HasDSP, IsThumb2]>;
  4502. // PUSH/POP aliases for STM/LDM
  4503. def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
  4504. def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
  4505. def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
  4506. def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
  4507. // STMIA/STMIA_UPD aliases w/o the optional .w suffix
  4508. def : t2InstAlias<"stm${p} $Rn, $regs",
  4509. (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
  4510. def : t2InstAlias<"stm${p} $Rn!, $regs",
  4511. (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4512. // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
  4513. def : t2InstAlias<"ldm${p} $Rn, $regs",
  4514. (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
  4515. def : t2InstAlias<"ldm${p} $Rn!, $regs",
  4516. (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4517. // STMDB/STMDB_UPD aliases w/ the optional .w suffix
  4518. def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
  4519. (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
  4520. def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
  4521. (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4522. // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
  4523. def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
  4524. (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
  4525. def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
  4526. (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4527. // Alias for REV/REV16/REVSH without the ".w" optional width specifier.
  4528. def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
  4529. def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
  4530. def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
  4531. // Alias for RSB with and without the ".w" optional width specifier, with and
  4532. // without explicit destination register.
  4533. def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
  4534. (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4535. def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
  4536. (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4537. def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
  4538. (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4539. def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
  4540. (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
  4541. cc_out:$s)>;
  4542. def : t2InstAlias<"rsb${s}${p}.w $Rdn, $Rm",
  4543. (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4544. def : t2InstAlias<"rsb${s}${p}.w $Rd, $Rn, $Rm",
  4545. (t2RSBrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4546. def : t2InstAlias<"rsb${s}${p}.w $Rd, $Rn, $ShiftedRm",
  4547. (t2RSBrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p,
  4548. cc_out:$s)>;
  4549. // SSAT/USAT optional shift operand.
  4550. def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
  4551. (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
  4552. def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
  4553. (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
  4554. // STM w/o the .w suffix.
  4555. def : t2InstAlias<"stm${p} $Rn, $regs",
  4556. (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
  4557. // Alias for STR, STRB, and STRH without the ".w" optional
  4558. // width specifier.
  4559. def : t2InstAlias<"str${p} $Rt, $addr",
  4560. (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4561. def : t2InstAlias<"strb${p} $Rt, $addr",
  4562. (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4563. def : t2InstAlias<"strh${p} $Rt, $addr",
  4564. (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4565. def : t2InstAlias<"str${p} $Rt, $addr",
  4566. (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4567. def : t2InstAlias<"strb${p} $Rt, $addr",
  4568. (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4569. def : t2InstAlias<"strh${p} $Rt, $addr",
  4570. (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4571. // Extend instruction optional rotate operand.
  4572. def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
  4573. (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4574. Requires<[HasDSP, IsThumb2]>;
  4575. def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
  4576. (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4577. Requires<[HasDSP, IsThumb2]>;
  4578. def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
  4579. (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4580. Requires<[HasDSP, IsThumb2]>;
  4581. def : InstAlias<"sxtb16${p} $Rd, $Rm",
  4582. (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
  4583. Requires<[HasDSP, IsThumb2]>;
  4584. def : t2InstAlias<"sxtb${p} $Rd, $Rm",
  4585. (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4586. def : t2InstAlias<"sxth${p} $Rd, $Rm",
  4587. (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4588. def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
  4589. (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4590. def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
  4591. (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4592. def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
  4593. (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4594. Requires<[HasDSP, IsThumb2]>;
  4595. def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
  4596. (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4597. Requires<[HasDSP, IsThumb2]>;
  4598. def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
  4599. (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4600. Requires<[HasDSP, IsThumb2]>;
  4601. def : InstAlias<"uxtb16${p} $Rd, $Rm",
  4602. (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
  4603. Requires<[HasDSP, IsThumb2]>;
  4604. def : t2InstAlias<"uxtb${p} $Rd, $Rm",
  4605. (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4606. def : t2InstAlias<"uxth${p} $Rd, $Rm",
  4607. (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4608. def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
  4609. (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4610. def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
  4611. (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4612. // Extend instruction w/o the ".w" optional width specifier.
  4613. def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
  4614. (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4615. def : InstAlias<"uxtb16${p} $Rd, $Rm$rot",
  4616. (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
  4617. Requires<[HasDSP, IsThumb2]>;
  4618. def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
  4619. (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4620. def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
  4621. (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4622. def : InstAlias<"sxtb16${p} $Rd, $Rm$rot",
  4623. (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
  4624. Requires<[HasDSP, IsThumb2]>;
  4625. def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
  4626. (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4627. // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
  4628. // for isel.
  4629. def : t2InstSubst<"mov${p} $Rd, $imm",
  4630. (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
  4631. def : t2InstSubst<"mvn${s}${p} $Rd, $imm",
  4632. (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
  4633. // Same for AND <--> BIC
  4634. def : t2InstSubst<"bic${s}${p} $Rd, $Rn, $imm",
  4635. (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4636. pred:$p, cc_out:$s)>;
  4637. def : t2InstSubst<"bic${s}${p} $Rdn, $imm",
  4638. (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4639. pred:$p, cc_out:$s)>;
  4640. def : t2InstSubst<"bic${s}${p}.w $Rd, $Rn, $imm",
  4641. (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4642. pred:$p, cc_out:$s)>;
  4643. def : t2InstSubst<"bic${s}${p}.w $Rdn, $imm",
  4644. (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4645. pred:$p, cc_out:$s)>;
  4646. def : t2InstSubst<"and${s}${p} $Rd, $Rn, $imm",
  4647. (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4648. pred:$p, cc_out:$s)>;
  4649. def : t2InstSubst<"and${s}${p} $Rdn, $imm",
  4650. (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4651. pred:$p, cc_out:$s)>;
  4652. def : t2InstSubst<"and${s}${p}.w $Rd, $Rn, $imm",
  4653. (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4654. pred:$p, cc_out:$s)>;
  4655. def : t2InstSubst<"and${s}${p}.w $Rdn, $imm",
  4656. (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4657. pred:$p, cc_out:$s)>;
  4658. // And ORR <--> ORN
  4659. def : t2InstSubst<"orn${s}${p} $Rd, $Rn, $imm",
  4660. (t2ORRri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4661. pred:$p, cc_out:$s)>;
  4662. def : t2InstSubst<"orn${s}${p} $Rdn, $imm",
  4663. (t2ORRri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4664. pred:$p, cc_out:$s)>;
  4665. def : t2InstSubst<"orr${s}${p} $Rd, $Rn, $imm",
  4666. (t2ORNri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4667. pred:$p, cc_out:$s)>;
  4668. def : t2InstSubst<"orr${s}${p} $Rdn, $imm",
  4669. (t2ORNri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4670. pred:$p, cc_out:$s)>;
  4671. // Likewise, "add Rd, t2_so_imm_neg" -> sub
  4672. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4673. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
  4674. pred:$p, cc_out:$s)>;
  4675. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4676. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm,
  4677. pred:$p, cc_out:$s)>;
  4678. def : t2InstSubst<"add${s}${p} $Rd, $imm",
  4679. (t2SUBri rGPR:$Rd, rGPR:$Rd, t2_so_imm_neg:$imm,
  4680. pred:$p, cc_out:$s)>;
  4681. def : t2InstSubst<"add${s}${p} $Rd, $imm",
  4682. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rd, t2_so_imm_neg:$imm,
  4683. pred:$p, cc_out:$s)>;
  4684. // Same for CMP <--> CMN via t2_so_imm_neg
  4685. def : t2InstSubst<"cmp${p} $Rd, $imm",
  4686. (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
  4687. def : t2InstSubst<"cmn${p} $Rd, $imm",
  4688. (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
  4689. // Wide 'mul' encoding can be specified with only two operands.
  4690. def : t2InstAlias<"mul${p} $Rn, $Rm",
  4691. (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
  4692. // "neg" is and alias for "rsb rd, rn, #0"
  4693. def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
  4694. (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
  4695. // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
  4696. // these, unfortunately.
  4697. // FIXME: LSL #0 in the shift should allow SP to be used as either the
  4698. // source or destination (but not both).
  4699. def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
  4700. (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4701. def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
  4702. (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4703. def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
  4704. (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4705. def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
  4706. (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4707. // Aliases for the above with the .w qualifier
  4708. def : t2InstAlias<"mov${p}.w $Rd, $shift",
  4709. (t2MOVsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4710. def : t2InstAlias<"movs${p}.w $Rd, $shift",
  4711. (t2MOVSsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4712. def : t2InstAlias<"mov${p}.w $Rd, $shift",
  4713. (t2MOVsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4714. def : t2InstAlias<"movs${p}.w $Rd, $shift",
  4715. (t2MOVSsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4716. // ADR w/o the .w suffix
  4717. def : t2InstAlias<"adr${p} $Rd, $addr",
  4718. (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
  4719. // LDR(literal) w/ alternate [pc, #imm] syntax.
  4720. def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr",
  4721. (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4722. def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr",
  4723. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4724. def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr",
  4725. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4726. def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
  4727. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4728. def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
  4729. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4730. // Version w/ the .w suffix.
  4731. def : t2InstAlias<"ldr${p}.w $Rt, $addr",
  4732. (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>;
  4733. def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
  4734. (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4735. def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
  4736. (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4737. def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
  4738. (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4739. def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
  4740. (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4741. def : t2InstAlias<"add${p} $Rd, pc, $imm",
  4742. (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;
  4743. // Pseudo instruction ldr Rt, =immediate
  4744. def t2LDRConstPool
  4745. : t2AsmPseudo<"ldr${p} $Rt, $immediate",
  4746. (ins GPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;
  4747. // Version w/ the .w suffix.
  4748. def : t2InstAlias<"ldr${p}.w $Rt, $immediate",
  4749. (t2LDRConstPool GPRnopc:$Rt,
  4750. const_pool_asm_imm:$immediate, pred:$p)>;
  4751. //===----------------------------------------------------------------------===//
  4752. // ARMv8.1m instructions
  4753. //
  4754. class V8_1MI<dag oops, dag iops, AddrMode am, InstrItinClass itin, string asm,
  4755. string ops, string cstr, list<dag> pattern>
  4756. : Thumb2XI<oops, iops, am, 4, itin, !strconcat(asm, "\t", ops), cstr,
  4757. pattern>,
  4758. Requires<[HasV8_1MMainline]>;
  4759. def t2CLRM : V8_1MI<(outs),
  4760. (ins pred:$p, reglist_with_apsr:$regs, variable_ops),
  4761. AddrModeNone, NoItinerary, "clrm${p}", "$regs", "", []> {
  4762. bits<16> regs;
  4763. let Inst{31-16} = 0b1110100010011111;
  4764. let Inst{15-14} = regs{15-14};
  4765. let Inst{13} = 0b0;
  4766. let Inst{12-0} = regs{12-0};
  4767. }
  4768. class t2BF<dag iops, string asm, string ops>
  4769. : V8_1MI<(outs ), iops, AddrModeNone, NoItinerary, asm, ops, "", []> {
  4770. let Inst{31-27} = 0b11110;
  4771. let Inst{15-14} = 0b11;
  4772. let Inst{12} = 0b0;
  4773. let Inst{0} = 0b1;
  4774. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
  4775. }
  4776. def t2BF_LabelPseudo
  4777. : t2PseudoInst<(outs ), (ins pclabel:$cp), 0, NoItinerary, []> {
  4778. let isTerminator = 1;
  4779. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
  4780. let hasNoSchedulingInfo = 1;
  4781. }
  4782. def t2BFi : t2BF<(ins bflabel_u4:$b_label, bflabel_s16:$label, pred:$p),
  4783. !strconcat("bf", "${p}"), "$b_label, $label"> {
  4784. bits<4> b_label;
  4785. bits<16> label;
  4786. let Inst{26-23} = b_label{3-0};
  4787. let Inst{22-21} = 0b10;
  4788. let Inst{20-16} = label{15-11};
  4789. let Inst{13} = 0b1;
  4790. let Inst{11} = label{0};
  4791. let Inst{10-1} = label{10-1};
  4792. }
  4793. def t2BFic : t2BF<(ins bflabel_u4:$b_label, bflabel_s12:$label,
  4794. bfafter_target:$ba_label, pred_noal:$bcond), "bfcsel",
  4795. "$b_label, $label, $ba_label, $bcond"> {
  4796. bits<4> bcond;
  4797. bits<12> label;
  4798. bits<1> ba_label;
  4799. bits<4> b_label;
  4800. let Inst{26-23} = b_label{3-0};
  4801. let Inst{22} = 0b0;
  4802. let Inst{21-18} = bcond{3-0};
  4803. let Inst{17} = ba_label{0};
  4804. let Inst{16} = label{11};
  4805. let Inst{13} = 0b1;
  4806. let Inst{11} = label{0};
  4807. let Inst{10-1} = label{10-1};
  4808. }
  4809. def t2BFr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
  4810. !strconcat("bfx", "${p}"), "$b_label, $Rn"> {
  4811. bits<4> b_label;
  4812. bits<4> Rn;
  4813. let Inst{26-23} = b_label{3-0};
  4814. let Inst{22-20} = 0b110;
  4815. let Inst{19-16} = Rn{3-0};
  4816. let Inst{13-1} = 0b1000000000000;
  4817. }
  4818. def t2BFLi : t2BF<(ins bflabel_u4:$b_label, bflabel_s18:$label, pred:$p),
  4819. !strconcat("bfl", "${p}"), "$b_label, $label"> {
  4820. bits<4> b_label;
  4821. bits<18> label;
  4822. let Inst{26-23} = b_label{3-0};
  4823. let Inst{22-16} = label{17-11};
  4824. let Inst{13} = 0b0;
  4825. let Inst{11} = label{0};
  4826. let Inst{10-1} = label{10-1};
  4827. }
  4828. def t2BFLr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
  4829. !strconcat("bflx", "${p}"), "$b_label, $Rn"> {
  4830. bits<4> b_label;
  4831. bits<4> Rn;
  4832. let Inst{26-23} = b_label{3-0};
  4833. let Inst{22-20} = 0b111;
  4834. let Inst{19-16} = Rn{3-0};
  4835. let Inst{13-1} = 0b1000000000000;
  4836. }
  4837. class t2LOL<dag oops, dag iops, string asm, string ops>
  4838. : V8_1MI<oops, iops, AddrModeNone, NoItinerary, asm, ops, "", [] > {
  4839. let Inst{31-23} = 0b111100000;
  4840. let Inst{15-14} = 0b11;
  4841. let Inst{0} = 0b1;
  4842. let DecoderMethod = "DecodeLOLoop";
  4843. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
  4844. }
  4845. let isNotDuplicable = 1 in {
  4846. def t2WLS : t2LOL<(outs GPRlr:$LR),
  4847. (ins rGPR:$Rn, wlslabel_u11:$label),
  4848. "wls", "$LR, $Rn, $label"> {
  4849. bits<4> Rn;
  4850. bits<11> label;
  4851. let Inst{22-20} = 0b100;
  4852. let Inst{19-16} = Rn{3-0};
  4853. let Inst{13-12} = 0b00;
  4854. let Inst{11} = label{0};
  4855. let Inst{10-1} = label{10-1};
  4856. let usesCustomInserter = 1;
  4857. let isBranch = 1;
  4858. let isTerminator = 1;
  4859. }
  4860. def t2DLS : t2LOL<(outs GPRlr:$LR), (ins rGPR:$Rn),
  4861. "dls", "$LR, $Rn"> {
  4862. bits<4> Rn;
  4863. let Inst{22-20} = 0b100;
  4864. let Inst{19-16} = Rn{3-0};
  4865. let Inst{13-1} = 0b1000000000000;
  4866. let usesCustomInserter = 1;
  4867. }
  4868. def t2LEUpdate : t2LOL<(outs GPRlr:$LRout),
  4869. (ins GPRlr:$LRin, lelabel_u11:$label),
  4870. "le", "$LRin, $label"> {
  4871. bits<11> label;
  4872. let Inst{22-16} = 0b0001111;
  4873. let Inst{13-12} = 0b00;
  4874. let Inst{11} = label{0};
  4875. let Inst{10-1} = label{10-1};
  4876. let usesCustomInserter = 1;
  4877. let isBranch = 1;
  4878. let isTerminator = 1;
  4879. }
  4880. def t2LE : t2LOL<(outs ), (ins lelabel_u11:$label), "le", "$label"> {
  4881. bits<11> label;
  4882. let Inst{22-16} = 0b0101111;
  4883. let Inst{13-12} = 0b00;
  4884. let Inst{11} = label{0};
  4885. let Inst{10-1} = label{10-1};
  4886. let isBranch = 1;
  4887. let isTerminator = 1;
  4888. }
  4889. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB] in {
  4890. // t2DoLoopStart a pseudo for DLS hardware loops. Lowered into a DLS in
  4891. // ARMLowOverheadLoops if possible, or reverted to a Mov if not.
  4892. def t2DoLoopStart :
  4893. t2PseudoInst<(outs GPRlr:$X), (ins rGPR:$tc), 4, IIC_Br,
  4894. [(set GPRlr:$X, (int_start_loop_iterations rGPR:$tc))]>;
  4895. // A pseudo for a DLSTP, created in the MVETPAndVPTOptimizationPass from a
  4896. // t2DoLoopStart if the loops is tail predicated. Holds both the element
  4897. // count and trip count of the loop, picking the correct one during
  4898. // ARMLowOverheadLoops when it is converted to a DLSTP or DLS as required.
  4899. let isTerminator = 1, hasSideEffects = 1 in
  4900. def t2DoLoopStartTP :
  4901. t2PseudoInst<(outs GPRlr:$X), (ins rGPR:$tc, rGPR:$elts), 4, IIC_Br, []>;
  4902. // Setup for a t2WhileLoopStart. A pair of t2WhileLoopSetup and t2WhileLoopStart
  4903. // will be created post-ISel from a llvm.test.start.loop.iterations. This
  4904. // t2WhileLoopSetup to setup LR and t2WhileLoopStart to perform the branch. Not
  4905. // valid after reg alloc, as it should be lowered during MVETPAndVPTOptimisations
  4906. // into a t2WhileLoopStartLR (or expanded).
  4907. def t2WhileLoopSetup :
  4908. t2PseudoInst<(outs GPRlr:$lr), (ins rGPR:$tc), 4, IIC_Br, []>;
  4909. // A pseudo to represent the decrement in a low overhead loop. A t2LoopDec and
  4910. // t2LoopEnd together represent a LE instruction. Ideally these are converted
  4911. // to a t2LoopEndDec which is lowered as a single instruction.
  4912. let hasSideEffects = 0 in
  4913. def t2LoopDec :
  4914. t2PseudoInst<(outs GPRlr:$Rm), (ins GPRlr:$Rn, imm0_7:$size),
  4915. 4, IIC_Br, []>, Sched<[WriteBr]>;
  4916. let isBranch = 1, isTerminator = 1, hasSideEffects = 1, Defs = [CPSR] in {
  4917. // The branch in a t2WhileLoopSetup/t2WhileLoopStart pair, eventually turned
  4918. // into a t2WhileLoopStartLR that does both the LR setup and branch.
  4919. def t2WhileLoopStart :
  4920. t2PseudoInst<(outs),
  4921. (ins GPRlr:$tc, brtarget:$target),
  4922. 4, IIC_Br, []>,
  4923. Sched<[WriteBr]>;
  4924. // WhileLoopStartLR that sets up LR and branches on zero, equivalent to WLS. It
  4925. // is lowered in the ARMLowOverheadLoops pass providing the branches are within
  4926. // range. WhileLoopStartLR and LoopEnd to occupy 8 bytes because they may get
  4927. // converted into t2CMP and t2Bcc.
  4928. def t2WhileLoopStartLR :
  4929. t2PseudoInst<(outs GPRlr:$lr),
  4930. (ins rGPR:$tc, brtarget:$target),
  4931. 8, IIC_Br, []>,
  4932. Sched<[WriteBr]>;
  4933. // Similar to a t2DoLoopStartTP, a t2WhileLoopStartTP is a pseudo for a WLSTP
  4934. // holding both the element count and the tripcount of the loop.
  4935. def t2WhileLoopStartTP :
  4936. t2PseudoInst<(outs GPRlr:$lr),
  4937. (ins rGPR:$tc, rGPR:$elts, brtarget:$target),
  4938. 8, IIC_Br, []>,
  4939. Sched<[WriteBr]>;
  4940. // t2LoopEnd - the branch half of a t2LoopDec/t2LoopEnd pair.
  4941. def t2LoopEnd :
  4942. t2PseudoInst<(outs), (ins GPRlr:$tc, brtarget:$target),
  4943. 8, IIC_Br, []>, Sched<[WriteBr]>;
  4944. // The combination of a t2LoopDec and t2LoopEnd, performing both the LR
  4945. // decrement and branch as a single instruction. Is lowered to a LE or
  4946. // LETP in ARMLowOverheadLoops as appropriate, or converted to t2CMP/t2Bcc
  4947. // if the branches are out of range.
  4948. def t2LoopEndDec :
  4949. t2PseudoInst<(outs GPRlr:$Rm), (ins GPRlr:$tc, brtarget:$target),
  4950. 8, IIC_Br, []>, Sched<[WriteBr]>;
  4951. } // end isBranch, isTerminator, hasSideEffects
  4952. }
  4953. } // end isNotDuplicable
  4954. class CS<string iname, bits<4> opcode, list<dag> pattern=[]>
  4955. : V8_1MI<(outs rGPR:$Rd), (ins GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rm, pred_noal:$fcond),
  4956. AddrModeNone, NoItinerary, iname, "$Rd, $Rn, $Rm, $fcond", "", pattern> {
  4957. bits<4> Rd;
  4958. bits<4> Rm;
  4959. bits<4> Rn;
  4960. bits<4> fcond;
  4961. let Inst{31-20} = 0b111010100101;
  4962. let Inst{19-16} = Rn{3-0};
  4963. let Inst{15-12} = opcode;
  4964. let Inst{11-8} = Rd{3-0};
  4965. let Inst{7-4} = fcond{3-0};
  4966. let Inst{3-0} = Rm{3-0};
  4967. let Uses = [CPSR];
  4968. let hasSideEffects = 0;
  4969. }
  4970. def t2CSEL : CS<"csel", 0b1000>;
  4971. def t2CSINC : CS<"csinc", 0b1001>;
  4972. def t2CSINV : CS<"csinv", 0b1010>;
  4973. def t2CSNEG : CS<"csneg", 0b1011>;
  4974. let Predicates = [HasV8_1MMainline] in {
  4975. multiclass CSPats<SDNode Node, Instruction Insn> {
  4976. def : T2Pat<(Node GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
  4977. (Insn GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
  4978. def : T2Pat<(Node (i32 0), GPRwithZR:$fval, imm0_31:$imm),
  4979. (Insn ZR, GPRwithZR:$fval, imm0_31:$imm)>;
  4980. def : T2Pat<(Node GPRwithZR:$tval, (i32 0), imm0_31:$imm),
  4981. (Insn GPRwithZR:$tval, ZR, imm0_31:$imm)>;
  4982. def : T2Pat<(Node (i32 0), (i32 0), imm0_31:$imm),
  4983. (Insn ZR, ZR, imm0_31:$imm)>;
  4984. }
  4985. defm : CSPats<ARMcsinc, t2CSINC>;
  4986. defm : CSPats<ARMcsinv, t2CSINV>;
  4987. defm : CSPats<ARMcsneg, t2CSNEG>;
  4988. def : T2Pat<(ARMcmov (i32 1), (i32 0), cmovpred:$imm),
  4989. (t2CSINC ZR, ZR, imm0_31:$imm)>;
  4990. def : T2Pat<(ARMcmov (i32 -1), (i32 0), cmovpred:$imm),
  4991. (t2CSINV ZR, ZR, imm0_31:$imm)>;
  4992. def : T2Pat<(ARMcmov (i32 0), (i32 1), cmovpred:$imm),
  4993. (t2CSINC ZR, ZR, (inv_cond_XFORM imm:$imm))>;
  4994. def : T2Pat<(ARMcmov (i32 0), (i32 -1), cmovpred:$imm),
  4995. (t2CSINV ZR, ZR, (inv_cond_XFORM imm:$imm))>;
  4996. multiclass ModifiedV8_1CSEL<Instruction Insn, dag modvalue> {
  4997. def : T2Pat<(ARMcmov modvalue, GPRwithZR:$tval, cmovpred:$imm),
  4998. (Insn GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
  4999. def : T2Pat<(ARMcmov GPRwithZR:$tval, modvalue, cmovpred:$imm),
  5000. (Insn GPRwithZR:$tval, GPRwithZR:$fval,
  5001. (i32 (inv_cond_XFORM imm:$imm)))>;
  5002. }
  5003. defm : ModifiedV8_1CSEL<t2CSINC, (add rGPR:$fval, 1)>;
  5004. defm : ModifiedV8_1CSEL<t2CSINV, (xor rGPR:$fval, -1)>;
  5005. defm : ModifiedV8_1CSEL<t2CSNEG, (sub 0, rGPR:$fval)>;
  5006. }
  5007. // CS aliases.
  5008. let Predicates = [HasV8_1MMainline] in {
  5009. def : InstAlias<"csetm\t$Rd, $fcond",
  5010. (t2CSINV rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
  5011. def : InstAlias<"cset\t$Rd, $fcond",
  5012. (t2CSINC rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
  5013. def : InstAlias<"cinc\t$Rd, $Rn, $fcond",
  5014. (t2CSINC rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
  5015. def : InstAlias<"cinv\t$Rd, $Rn, $fcond",
  5016. (t2CSINV rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
  5017. def : InstAlias<"cneg\t$Rd, $Rn, $fcond",
  5018. (t2CSNEG rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
  5019. }
  5020. // PACBTI
  5021. let Predicates = [IsThumb2, HasV8_1MMainline, HasPACBTI] in {
  5022. def t2PACG : V8_1MI<(outs rGPR:$Rd),
  5023. (ins pred:$p, GPRnopc:$Rn, GPRnopc:$Rm),
  5024. AddrModeNone, NoItinerary, "pacg${p}", "$Rd, $Rn, $Rm", "", []> {
  5025. bits<4> Rd;
  5026. bits<4> Rn;
  5027. bits<4> Rm;
  5028. let Inst{31-20} = 0b111110110110;
  5029. let Inst{19-16} = Rn;
  5030. let Inst{15-12} = 0b1111;
  5031. let Inst{11-8} = Rd;
  5032. let Inst{7-4} = 0b0000;
  5033. let Inst{3-0} = Rm;
  5034. }
  5035. let hasSideEffects = 1 in {
  5036. class PACBTIAut<dag iops, string asm, bit b>
  5037. : V8_1MI<(outs), iops,
  5038. AddrModeNone, NoItinerary, asm, "$Ra, $Rn, $Rm", "", []> {
  5039. bits<4> Ra;
  5040. bits<4> Rn;
  5041. bits<4> Rm;
  5042. let Inst{31-20} = 0b111110110101;
  5043. let Inst{19-16} = Rn;
  5044. let Inst{15-12} = Ra;
  5045. let Inst{11-5} = 0b1111000;
  5046. let Inst{4} = b;
  5047. let Inst{3-0} = Rm;
  5048. }
  5049. }
  5050. def t2AUTG : PACBTIAut<(ins pred:$p, GPRnosp:$Ra, GPRnopc:$Rn, GPRnopc:$Rm),
  5051. "autg${p}", 0>;
  5052. let isBranch = 1, isTerminator = 1, isIndirectBranch = 1 in {
  5053. def t2BXAUT : PACBTIAut<(ins pred:$p, GPRnosp:$Ra, rGPR:$Rn, GPRnopc:$Rm),
  5054. "bxaut${p}", 1>;
  5055. }
  5056. }
  5057. class PACBTIHintSpaceInst<string asm, string ops, bits<8> imm>
  5058. : V8_1MI<(outs), (ins), AddrModeNone, NoItinerary, asm, ops, "", []> {
  5059. let Inst{31-8} = 0b111100111010111110000000;
  5060. let Inst{7-0} = imm;
  5061. let Unpredictable{19-16} = 0b1111;
  5062. let Unpredictable{13-11} = 0b101;
  5063. let DecoderMethod = "DecodeT2HintSpaceInstruction";
  5064. }
  5065. class PACBTIHintSpaceNoOpsInst<string asm, bits<8> imm>
  5066. : PACBTIHintSpaceInst<asm, "", imm>;
  5067. class PACBTIHintSpaceDefInst<string asm, bits<8> imm>
  5068. : PACBTIHintSpaceInst<asm, "r12, lr, sp", imm> {
  5069. let Defs = [R12];
  5070. let Uses = [LR, SP];
  5071. }
  5072. class PACBTIHintSpaceUseInst<string asm, bits<8> imm>
  5073. : PACBTIHintSpaceInst<asm, "r12, lr, sp", imm> {
  5074. let Uses = [R12, LR, SP];
  5075. }
  5076. def t2PAC : PACBTIHintSpaceDefInst<"pac", 0b00011101>;
  5077. def t2PACBTI : PACBTIHintSpaceDefInst<"pacbti", 0b00001101>;
  5078. def t2BTI : PACBTIHintSpaceNoOpsInst<"bti", 0b00001111>;
  5079. def t2AUT : PACBTIHintSpaceUseInst<"aut", 0b00101101> {
  5080. let hasSideEffects = 1;
  5081. }
  5082. def ARMt2CallBTI : SDNode<"ARMISD::t2CALL_BTI", SDT_ARMcall,
  5083. [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue, SDNPVariadic]>;
  5084. def t2CALL_BTI : PseudoInst<(outs), (ins pred:$p, thumb_bl_target:$func),
  5085. IIC_Br, [(ARMt2CallBTI tglobaladdr:$func)]>,
  5086. Requires<[IsThumb2]>, Sched<[WriteBrL]>;