ARMInstrThumb2.td 223 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770
  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. let DecoderMethod = "DecodeTSBInstruction";
  3164. }
  3165. }
  3166. // Armv8.5-A speculation barrier
  3167. def t2SB : Thumb2XI<(outs), (ins), AddrModeNone, 4, NoItinerary, "sb", "", []>,
  3168. Requires<[IsThumb2, HasSB]>, Sched<[]> {
  3169. let Inst{31-0} = 0xf3bf8f70;
  3170. let Unpredictable = 0x000f2f0f;
  3171. let hasSideEffects = 1;
  3172. }
  3173. class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
  3174. InstrItinClass itin, string opc, string asm, string cstr,
  3175. list<dag> pattern, bits<4> rt2 = 0b1111>
  3176. : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
  3177. let Inst{31-27} = 0b11101;
  3178. let Inst{26-20} = 0b0001101;
  3179. let Inst{11-8} = rt2;
  3180. let Inst{7-4} = opcod;
  3181. let Inst{3-0} = 0b1111;
  3182. bits<4> addr;
  3183. bits<4> Rt;
  3184. let Inst{19-16} = addr;
  3185. let Inst{15-12} = Rt;
  3186. }
  3187. class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
  3188. InstrItinClass itin, string opc, string asm, string cstr,
  3189. list<dag> pattern, bits<4> rt2 = 0b1111>
  3190. : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
  3191. let Inst{31-27} = 0b11101;
  3192. let Inst{26-20} = 0b0001100;
  3193. let Inst{11-8} = rt2;
  3194. let Inst{7-4} = opcod;
  3195. bits<4> Rd;
  3196. bits<4> addr;
  3197. bits<4> Rt;
  3198. let Inst{3-0} = Rd;
  3199. let Inst{19-16} = addr;
  3200. let Inst{15-12} = Rt;
  3201. }
  3202. let mayLoad = 1 in {
  3203. def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3204. AddrModeNone, 4, NoItinerary,
  3205. "ldrexb", "\t$Rt, $addr", "",
  3206. [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>,
  3207. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
  3208. def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3209. AddrModeNone, 4, NoItinerary,
  3210. "ldrexh", "\t$Rt, $addr", "",
  3211. [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>,
  3212. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]>;
  3213. def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
  3214. AddrModeT2_ldrex, 4, NoItinerary,
  3215. "ldrex", "\t$Rt, $addr", "",
  3216. [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]>,
  3217. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteLd]> {
  3218. bits<4> Rt;
  3219. bits<12> addr;
  3220. let Inst{31-27} = 0b11101;
  3221. let Inst{26-20} = 0b0000101;
  3222. let Inst{19-16} = addr{11-8};
  3223. let Inst{15-12} = Rt;
  3224. let Inst{11-8} = 0b1111;
  3225. let Inst{7-0} = addr{7-0};
  3226. }
  3227. let hasExtraDefRegAllocReq = 1 in
  3228. def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2),
  3229. (ins addr_offset_none:$addr),
  3230. AddrModeNone, 4, NoItinerary,
  3231. "ldrexd", "\t$Rt, $Rt2, $addr", "",
  3232. [], {?, ?, ?, ?}>,
  3233. Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteLd]> {
  3234. bits<4> Rt2;
  3235. let Inst{11-8} = Rt2;
  3236. }
  3237. def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3238. AddrModeNone, 4, NoItinerary,
  3239. "ldaexb", "\t$Rt, $addr", "",
  3240. [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>,
  3241. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
  3242. def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3243. AddrModeNone, 4, NoItinerary,
  3244. "ldaexh", "\t$Rt, $addr", "",
  3245. [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>,
  3246. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]>;
  3247. def t2LDAEX : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr),
  3248. AddrModeNone, 4, NoItinerary,
  3249. "ldaex", "\t$Rt, $addr", "",
  3250. [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>,
  3251. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>, Sched<[WriteLd]> {
  3252. bits<4> Rt;
  3253. bits<4> addr;
  3254. let Inst{31-27} = 0b11101;
  3255. let Inst{26-20} = 0b0001101;
  3256. let Inst{19-16} = addr;
  3257. let Inst{15-12} = Rt;
  3258. let Inst{11-8} = 0b1111;
  3259. let Inst{7-0} = 0b11101111;
  3260. }
  3261. let hasExtraDefRegAllocReq = 1 in
  3262. def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2),
  3263. (ins addr_offset_none:$addr),
  3264. AddrModeNone, 4, NoItinerary,
  3265. "ldaexd", "\t$Rt, $Rt2, $addr", "",
  3266. [], {?, ?, ?, ?}>, Requires<[IsThumb,
  3267. HasAcquireRelease, HasV7Clrex, IsNotMClass]>, Sched<[WriteLd]> {
  3268. bits<4> Rt2;
  3269. let Inst{11-8} = Rt2;
  3270. let Inst{7} = 1;
  3271. }
  3272. }
  3273. let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
  3274. def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd),
  3275. (ins rGPR:$Rt, addr_offset_none:$addr),
  3276. AddrModeNone, 4, NoItinerary,
  3277. "strexb", "\t$Rd, $Rt, $addr", "",
  3278. [(set rGPR:$Rd,
  3279. (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
  3280. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
  3281. def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd),
  3282. (ins rGPR:$Rt, addr_offset_none:$addr),
  3283. AddrModeNone, 4, NoItinerary,
  3284. "strexh", "\t$Rd, $Rt, $addr", "",
  3285. [(set rGPR:$Rd,
  3286. (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
  3287. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]>;
  3288. def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
  3289. t2addrmode_imm0_1020s4:$addr),
  3290. AddrModeT2_ldrex, 4, NoItinerary,
  3291. "strex", "\t$Rd, $Rt, $addr", "",
  3292. [(set rGPR:$Rd,
  3293. (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]>,
  3294. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteST]> {
  3295. bits<4> Rd;
  3296. bits<4> Rt;
  3297. bits<12> addr;
  3298. let Inst{31-27} = 0b11101;
  3299. let Inst{26-20} = 0b0000100;
  3300. let Inst{19-16} = addr{11-8};
  3301. let Inst{15-12} = Rt;
  3302. let Inst{11-8} = Rd;
  3303. let Inst{7-0} = addr{7-0};
  3304. }
  3305. let hasExtraSrcRegAllocReq = 1 in
  3306. def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd),
  3307. (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
  3308. AddrModeNone, 4, NoItinerary,
  3309. "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
  3310. {?, ?, ?, ?}>,
  3311. Requires<[IsThumb2, IsNotMClass]>, Sched<[WriteST]> {
  3312. bits<4> Rt2;
  3313. let Inst{11-8} = Rt2;
  3314. }
  3315. def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd),
  3316. (ins rGPR:$Rt, addr_offset_none:$addr),
  3317. AddrModeNone, 4, NoItinerary,
  3318. "stlexb", "\t$Rd, $Rt, $addr", "",
  3319. [(set rGPR:$Rd,
  3320. (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
  3321. Requires<[IsThumb, HasAcquireRelease,
  3322. HasV7Clrex]>, Sched<[WriteST]>;
  3323. def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd),
  3324. (ins rGPR:$Rt, addr_offset_none:$addr),
  3325. AddrModeNone, 4, NoItinerary,
  3326. "stlexh", "\t$Rd, $Rt, $addr", "",
  3327. [(set rGPR:$Rd,
  3328. (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
  3329. Requires<[IsThumb, HasAcquireRelease,
  3330. HasV7Clrex]>, Sched<[WriteST]>;
  3331. def t2STLEX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
  3332. addr_offset_none:$addr),
  3333. AddrModeNone, 4, NoItinerary,
  3334. "stlex", "\t$Rd, $Rt, $addr", "",
  3335. [(set rGPR:$Rd,
  3336. (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>,
  3337. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>,
  3338. Sched<[WriteST]> {
  3339. bits<4> Rd;
  3340. bits<4> Rt;
  3341. bits<4> addr;
  3342. let Inst{31-27} = 0b11101;
  3343. let Inst{26-20} = 0b0001100;
  3344. let Inst{19-16} = addr;
  3345. let Inst{15-12} = Rt;
  3346. let Inst{11-4} = 0b11111110;
  3347. let Inst{3-0} = Rd;
  3348. }
  3349. let hasExtraSrcRegAllocReq = 1 in
  3350. def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd),
  3351. (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
  3352. AddrModeNone, 4, NoItinerary,
  3353. "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
  3354. {?, ?, ?, ?}>, Requires<[IsThumb, HasAcquireRelease,
  3355. HasV7Clrex, IsNotMClass]>, Sched<[WriteST]> {
  3356. bits<4> Rt2;
  3357. let Inst{11-8} = Rt2;
  3358. }
  3359. }
  3360. def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>,
  3361. Requires<[IsThumb, HasV7Clrex]> {
  3362. let Inst{31-16} = 0xf3bf;
  3363. let Inst{15-14} = 0b10;
  3364. let Inst{13} = 0;
  3365. let Inst{12} = 0;
  3366. let Inst{11-8} = 0b1111;
  3367. let Inst{7-4} = 0b0010;
  3368. let Inst{3-0} = 0b1111;
  3369. }
  3370. def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
  3371. (t2LDREXB addr_offset_none:$addr)>,
  3372. Requires<[IsThumb, HasV8MBaseline]>;
  3373. def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
  3374. (t2LDREXH addr_offset_none:$addr)>,
  3375. Requires<[IsThumb, HasV8MBaseline]>;
  3376. def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
  3377. (t2STREXB GPR:$Rt, addr_offset_none:$addr)>,
  3378. Requires<[IsThumb, HasV8MBaseline]>;
  3379. def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
  3380. (t2STREXH GPR:$Rt, addr_offset_none:$addr)>,
  3381. Requires<[IsThumb, HasV8MBaseline]>;
  3382. def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff),
  3383. (t2LDAEXB addr_offset_none:$addr)>,
  3384. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3385. def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff),
  3386. (t2LDAEXH addr_offset_none:$addr)>,
  3387. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3388. def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
  3389. (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>,
  3390. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3391. def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
  3392. (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>,
  3393. Requires<[IsThumb, HasAcquireRelease, HasV7Clrex]>;
  3394. //===----------------------------------------------------------------------===//
  3395. // SJLJ Exception handling intrinsics
  3396. // eh_sjlj_setjmp() is an instruction sequence to store the return
  3397. // address and save #0 in R0 for the non-longjmp case.
  3398. // Since by its nature we may be coming from some other function to get
  3399. // here, and we're using the stack frame for the containing function to
  3400. // save/restore registers, we can't keep anything live in regs across
  3401. // the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
  3402. // when we get here from a longjmp(). We force everything out of registers
  3403. // except for our own input by listing the relevant registers in Defs. By
  3404. // doing so, we also cause the prologue/epilogue code to actively preserve
  3405. // all of the callee-saved registers, which is exactly what we want.
  3406. // $val is a scratch register for our use.
  3407. // This gets lowered to an instruction sequence of 12 bytes
  3408. let Defs =
  3409. [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
  3410. Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
  3411. hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1, Size = 12,
  3412. usesCustomInserter = 1 in {
  3413. def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
  3414. AddrModeNone, 0, NoItinerary, "", "",
  3415. [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
  3416. Requires<[IsThumb2, HasVFP2]>;
  3417. }
  3418. // This gets lowered to an instruction sequence of 12 bytes
  3419. let Defs =
  3420. [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
  3421. hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1, Size = 12,
  3422. usesCustomInserter = 1 in {
  3423. def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
  3424. AddrModeNone, 0, NoItinerary, "", "",
  3425. [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
  3426. Requires<[IsThumb2, NoVFP]>;
  3427. }
  3428. //===----------------------------------------------------------------------===//
  3429. // Control-Flow Instructions
  3430. //
  3431. // FIXME: remove when we have a way to marking a MI with these properties.
  3432. // FIXME: Should pc be an implicit operand like PICADD, etc?
  3433. let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
  3434. hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
  3435. def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
  3436. reglist:$regs, variable_ops),
  3437. 4, IIC_iLoad_mBr, [],
  3438. (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
  3439. RegConstraint<"$Rn = $wb">;
  3440. let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
  3441. let isPredicable = 1 in
  3442. def t2B : T2I<(outs), (ins thumb_br_target:$target), IIC_Br,
  3443. "b", ".w\t$target",
  3444. [(br bb:$target)]>, Sched<[WriteBr]>,
  3445. Requires<[IsThumb, HasV8MBaseline]> {
  3446. let Inst{31-27} = 0b11110;
  3447. let Inst{15-14} = 0b10;
  3448. let Inst{12} = 1;
  3449. bits<24> target;
  3450. let Inst{26} = target{23};
  3451. let Inst{13} = target{22};
  3452. let Inst{11} = target{21};
  3453. let Inst{25-16} = target{20-11};
  3454. let Inst{10-0} = target{10-0};
  3455. let DecoderMethod = "DecodeT2BInstruction";
  3456. let AsmMatchConverter = "cvtThumbBranches";
  3457. }
  3458. let Size = 4, isNotDuplicable = 1, isBranch = 1, isTerminator = 1,
  3459. isBarrier = 1, isIndirectBranch = 1 in {
  3460. // available in both v8-M.Baseline and Thumb2 targets
  3461. def t2BR_JT : t2basePseudoInst<(outs),
  3462. (ins GPR:$target, GPR:$index, i32imm:$jt),
  3463. 0, IIC_Br,
  3464. [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt)]>,
  3465. Sched<[WriteBr]>;
  3466. // FIXME: Add a case that can be predicated.
  3467. def t2TBB_JT : t2PseudoInst<(outs),
  3468. (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
  3469. Sched<[WriteBr]>;
  3470. def t2TBH_JT : t2PseudoInst<(outs),
  3471. (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
  3472. Sched<[WriteBr]>;
  3473. def t2TBB : T2I<(outs), (ins (addrmode_tbb $Rn, $Rm):$addr), IIC_Br,
  3474. "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> {
  3475. bits<4> Rn;
  3476. bits<4> Rm;
  3477. let Inst{31-20} = 0b111010001101;
  3478. let Inst{19-16} = Rn;
  3479. let Inst{15-5} = 0b11110000000;
  3480. let Inst{4} = 0; // B form
  3481. let Inst{3-0} = Rm;
  3482. let DecoderMethod = "DecodeThumbTableBranch";
  3483. }
  3484. def t2TBH : T2I<(outs), (ins (addrmode_tbh $Rn, $Rm):$addr), IIC_Br,
  3485. "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> {
  3486. bits<4> Rn;
  3487. bits<4> Rm;
  3488. let Inst{31-20} = 0b111010001101;
  3489. let Inst{19-16} = Rn;
  3490. let Inst{15-5} = 0b11110000000;
  3491. let Inst{4} = 1; // H form
  3492. let Inst{3-0} = Rm;
  3493. let DecoderMethod = "DecodeThumbTableBranch";
  3494. }
  3495. } // isNotDuplicable, isIndirectBranch
  3496. } // isBranch, isTerminator, isBarrier
  3497. // FIXME: should be able to write a pattern for ARMBrcond, but can't use
  3498. // a two-value operand where a dag node expects ", "two operands. :(
  3499. let isBranch = 1, isTerminator = 1 in
  3500. def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
  3501. "b", ".w\t$target",
  3502. [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> {
  3503. let Inst{31-27} = 0b11110;
  3504. let Inst{15-14} = 0b10;
  3505. let Inst{12} = 0;
  3506. bits<4> p;
  3507. let Inst{25-22} = p;
  3508. bits<21> target;
  3509. let Inst{26} = target{20};
  3510. let Inst{11} = target{19};
  3511. let Inst{13} = target{18};
  3512. let Inst{21-16} = target{17-12};
  3513. let Inst{10-0} = target{11-1};
  3514. let DecoderMethod = "DecodeThumb2BCCInstruction";
  3515. let AsmMatchConverter = "cvtThumbBranches";
  3516. }
  3517. // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so
  3518. // it goes here.
  3519. // Windows SEH unwinding also needs a strict t2 branch for tail calls.
  3520. let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
  3521. // IOS version.
  3522. let Uses = [SP] in
  3523. def tTAILJMPd: tPseudoExpand<(outs),
  3524. (ins thumb_br_target:$dst, pred:$p),
  3525. 4, IIC_Br, [],
  3526. (t2B thumb_br_target:$dst, pred:$p)>,
  3527. Requires<[IsThumb2]>, Sched<[WriteBr]>;
  3528. }
  3529. // IT block
  3530. let Defs = [ITSTATE] in
  3531. def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
  3532. AddrModeNone, 2, IIC_iALUx,
  3533. "it$mask\t$cc", "", []> {
  3534. // 16-bit instruction.
  3535. let Inst{31-16} = 0x0000;
  3536. let Inst{15-8} = 0b10111111;
  3537. bits<4> cc;
  3538. bits<4> mask;
  3539. let Inst{7-4} = cc;
  3540. let Inst{3-0} = mask;
  3541. let DecoderMethod = "DecodeIT";
  3542. }
  3543. // Branch and Exchange Jazelle -- for disassembly only
  3544. // Rm = Inst{19-16}
  3545. let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
  3546. def t2BXJ : T2I<(outs), (ins GPRnopc:$func), NoItinerary, "bxj", "\t$func", []>,
  3547. Sched<[WriteBr]>, Requires<[IsThumb2, IsNotMClass]> {
  3548. bits<4> func;
  3549. let Inst{31-27} = 0b11110;
  3550. let Inst{26} = 0;
  3551. let Inst{25-20} = 0b111100;
  3552. let Inst{19-16} = func;
  3553. let Inst{15-0} = 0b1000111100000000;
  3554. }
  3555. def : t2InstAlias<"bl${p}.w $func", (tBL pred:$p, thumb_bl_target:$func), 0>;
  3556. // Compare and branch on zero / non-zero
  3557. let isBranch = 1, isTerminator = 1 in {
  3558. def tCBZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
  3559. "cbz\t$Rn, $target", []>,
  3560. T1Misc<{0,0,?,1,?,?,?}>,
  3561. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
  3562. // A8.6.27
  3563. bits<6> target;
  3564. bits<3> Rn;
  3565. let Inst{9} = target{5};
  3566. let Inst{7-3} = target{4-0};
  3567. let Inst{2-0} = Rn;
  3568. }
  3569. def tCBNZ : T1I<(outs), (ins tGPR:$Rn, thumb_cb_target:$target), IIC_Br,
  3570. "cbnz\t$Rn, $target", []>,
  3571. T1Misc<{1,0,?,1,?,?,?}>,
  3572. Requires<[IsThumb, HasV8MBaseline]>, Sched<[WriteBr]> {
  3573. // A8.6.27
  3574. bits<6> target;
  3575. bits<3> Rn;
  3576. let Inst{9} = target{5};
  3577. let Inst{7-3} = target{4-0};
  3578. let Inst{2-0} = Rn;
  3579. }
  3580. }
  3581. // Change Processor State is a system instruction.
  3582. // FIXME: Since the asm parser has currently no clean way to handle optional
  3583. // operands, create 3 versions of the same instruction. Once there's a clean
  3584. // framework to represent optional operands, change this behavior.
  3585. class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
  3586. !strconcat("cps", asm_op), []>,
  3587. Requires<[IsThumb2, IsNotMClass]> {
  3588. bits<2> imod;
  3589. bits<3> iflags;
  3590. bits<5> mode;
  3591. bit M;
  3592. let Inst{31-11} = 0b111100111010111110000;
  3593. let Inst{10-9} = imod;
  3594. let Inst{8} = M;
  3595. let Inst{7-5} = iflags;
  3596. let Inst{4-0} = mode;
  3597. let DecoderMethod = "DecodeT2CPSInstruction";
  3598. }
  3599. let M = 1 in
  3600. def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
  3601. "$imod\t$iflags, $mode">;
  3602. let mode = 0, M = 0 in
  3603. def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
  3604. "$imod.w\t$iflags">;
  3605. let imod = 0, iflags = 0, M = 1 in
  3606. def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
  3607. def : t2InstAlias<"cps$imod.w $iflags, $mode",
  3608. (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>;
  3609. def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>;
  3610. // A6.3.4 Branches and miscellaneous control
  3611. // Table A6-14 Change Processor State, and hint instructions
  3612. def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm",
  3613. [(int_arm_hint imm0_239:$imm)]> {
  3614. bits<8> imm;
  3615. let Inst{31-3} = 0b11110011101011111000000000000;
  3616. let Inst{7-0} = imm;
  3617. let DecoderMethod = "DecodeT2HintSpaceInstruction";
  3618. }
  3619. def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p), 0>;
  3620. def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p), 1>;
  3621. def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p), 1>;
  3622. def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p), 1>;
  3623. def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p), 1>;
  3624. def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p), 1>;
  3625. def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p), 1> {
  3626. let Predicates = [IsThumb2, HasV8];
  3627. }
  3628. def : t2InstAlias<"esb$p.w", (t2HINT 16, pred:$p), 1> {
  3629. let Predicates = [IsThumb2, HasRAS];
  3630. }
  3631. def : t2InstAlias<"esb$p", (t2HINT 16, pred:$p), 0> {
  3632. let Predicates = [IsThumb2, HasRAS];
  3633. }
  3634. def : t2InstAlias<"csdb$p.w", (t2HINT 20, pred:$p), 0>;
  3635. def : t2InstAlias<"csdb$p", (t2HINT 20, pred:$p), 1>;
  3636. def : t2InstAlias<"pacbti$p r12,lr,sp", (t2HINT 13, pred:$p), 1>;
  3637. def : t2InstAlias<"bti$p", (t2HINT 15, pred:$p), 1>;
  3638. def : t2InstAlias<"pac$p r12,lr,sp", (t2HINT 29, pred:$p), 1>;
  3639. def : t2InstAlias<"aut$p r12,lr,sp", (t2HINT 45, pred:$p), 1>;
  3640. // Clear BHB instruction
  3641. def : InstAlias<"clrbhb$p", (t2HINT 22, pred:$p), 0>, Requires<[IsThumb2, HasV8]>;
  3642. def : InstAlias<"clrbhb$p", (t2HINT 22, pred:$p), 1>, Requires<[IsThumb2, HasV8, HasCLRBHB]>;
  3643. def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
  3644. [(int_arm_dbg imm0_15:$opt)]> {
  3645. bits<4> opt;
  3646. let Inst{31-20} = 0b111100111010;
  3647. let Inst{19-16} = 0b1111;
  3648. let Inst{15-8} = 0b10000000;
  3649. let Inst{7-4} = 0b1111;
  3650. let Inst{3-0} = opt;
  3651. }
  3652. def : t2InstAlias<"dbg${p}.w $opt", (t2DBG imm0_15:$opt, pred:$p), 0>;
  3653. // Secure Monitor Call is a system instruction.
  3654. // Option = Inst{19-16}
  3655. let isCall = 1, Uses = [SP] in
  3656. def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
  3657. []>, Requires<[IsThumb2, HasTrustZone]> {
  3658. let Inst{31-27} = 0b11110;
  3659. let Inst{26-20} = 0b1111111;
  3660. let Inst{15-12} = 0b1000;
  3661. bits<4> opt;
  3662. let Inst{19-16} = opt;
  3663. }
  3664. class T2DCPS<bits<2> opt, string opc>
  3665. : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> {
  3666. let Inst{31-27} = 0b11110;
  3667. let Inst{26-20} = 0b1111000;
  3668. let Inst{19-16} = 0b1111;
  3669. let Inst{15-12} = 0b1000;
  3670. let Inst{11-2} = 0b0000000000;
  3671. let Inst{1-0} = opt;
  3672. }
  3673. def t2DCPS1 : T2DCPS<0b01, "dcps1">;
  3674. def t2DCPS2 : T2DCPS<0b10, "dcps2">;
  3675. def t2DCPS3 : T2DCPS<0b11, "dcps3">;
  3676. class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
  3677. string opc, string asm, list<dag> pattern>
  3678. : T2I<oops, iops, itin, opc, asm, pattern>,
  3679. Requires<[IsThumb2,IsNotMClass]> {
  3680. bits<5> mode;
  3681. let Inst{31-25} = 0b1110100;
  3682. let Inst{24-23} = Op;
  3683. let Inst{22} = 0;
  3684. let Inst{21} = W;
  3685. let Inst{20-16} = 0b01101;
  3686. let Inst{15-5} = 0b11000000000;
  3687. let Inst{4-0} = mode{4-0};
  3688. }
  3689. // Store Return State is a system instruction.
  3690. def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
  3691. "srsdb", "\tsp!, $mode", []>;
  3692. def t2SRSDB : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
  3693. "srsdb","\tsp, $mode", []>;
  3694. def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
  3695. "srsia","\tsp!, $mode", []>;
  3696. def t2SRSIA : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
  3697. "srsia","\tsp, $mode", []>;
  3698. def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>;
  3699. def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>;
  3700. def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>;
  3701. def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>;
  3702. // Return From Exception is a system instruction.
  3703. let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
  3704. class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
  3705. string opc, string asm, list<dag> pattern>
  3706. : T2I<oops, iops, itin, opc, asm, pattern>,
  3707. Requires<[IsThumb2,IsNotMClass]> {
  3708. let Inst{31-20} = op31_20{11-0};
  3709. bits<4> Rn;
  3710. let Inst{19-16} = Rn;
  3711. let Inst{15-0} = 0xc000;
  3712. }
  3713. def t2RFEDBW : T2RFE<0b111010000011,
  3714. (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
  3715. [/* For disassembly only; pattern left blank */]>;
  3716. def t2RFEDB : T2RFE<0b111010000001,
  3717. (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
  3718. [/* For disassembly only; pattern left blank */]>;
  3719. def t2RFEIAW : T2RFE<0b111010011011,
  3720. (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
  3721. [/* For disassembly only; pattern left blank */]>;
  3722. def t2RFEIA : T2RFE<0b111010011001,
  3723. (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
  3724. [/* For disassembly only; pattern left blank */]>;
  3725. // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction.
  3726. // Exception return instruction is "subs pc, lr, #imm".
  3727. let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
  3728. def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
  3729. "subs", "\tpc, lr, $imm",
  3730. [(ARMintretflag imm0_255:$imm)]>,
  3731. Requires<[IsThumb2,IsNotMClass]> {
  3732. let Inst{31-8} = 0b111100111101111010001111;
  3733. bits<8> imm;
  3734. let Inst{7-0} = imm;
  3735. }
  3736. // B9.3.19 SUBS PC, LR (Thumb)
  3737. // In the Thumb instruction set, MOVS{<c>}{<q>} PC, LR is a pseudo-instruction
  3738. // for SUBS{<c>}{<q>} PC, LR, #0.
  3739. def : t2InstAlias<"movs${p}\tpc, lr", (t2SUBS_PC_LR 0, pred:$p)>;
  3740. def : t2InstAlias<"movs${p}.w\tpc, lr", (t2SUBS_PC_LR 0, pred:$p)>;
  3741. // ERET - Return from exception in Hypervisor mode.
  3742. // B9.3.3, B9.3.20: ERET is an alias for "SUBS PC, LR, #0" in an implementation that
  3743. // includes virtualization extensions.
  3744. def t2ERET : InstAlias<"eret${p}", (t2SUBS_PC_LR 0, pred:$p), 1>,
  3745. Requires<[IsThumb2, HasVirtualization]>;
  3746. // Hypervisor Call is a system instruction.
  3747. let isCall = 1 in {
  3748. def t2HVC : T2XI <(outs), (ins imm0_65535:$imm16), IIC_Br, "hvc.w\t$imm16", []>,
  3749. Requires<[IsThumb2, HasVirtualization]>, Sched<[WriteBr]> {
  3750. bits<16> imm16;
  3751. let Inst{31-20} = 0b111101111110;
  3752. let Inst{19-16} = imm16{15-12};
  3753. let Inst{15-12} = 0b1000;
  3754. let Inst{11-0} = imm16{11-0};
  3755. }
  3756. }
  3757. // Alias for HVC without the ".w" optional width specifier
  3758. def : t2InstAlias<"hvc\t$imm16", (t2HVC imm0_65535:$imm16)>;
  3759. //===----------------------------------------------------------------------===//
  3760. // Non-Instruction Patterns
  3761. //
  3762. // 32-bit immediate using movw + movt.
  3763. // This is a single pseudo instruction to make it re-materializable.
  3764. // FIXME: Remove this when we can do generalized remat.
  3765. let isReMaterializable = 1, isMoveImm = 1, Size = 8 in
  3766. def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
  3767. [(set rGPR:$dst, (i32 imm:$src))]>,
  3768. Requires<[IsThumb, UseMovt]>;
  3769. // Pseudo instruction that combines movw + movt + add pc (if pic).
  3770. // It also makes it possible to rematerialize the instructions.
  3771. // FIXME: Remove this when we can do generalized remat and when machine licm
  3772. // can properly the instructions.
  3773. let isReMaterializable = 1 in {
  3774. def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
  3775. IIC_iMOVix2addpc,
  3776. [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
  3777. Requires<[IsThumb, HasV8MBaseline, UseMovtInPic]>;
  3778. }
  3779. def : T2Pat<(ARMWrapperPIC tglobaltlsaddr :$dst),
  3780. (t2MOV_ga_pcrel tglobaltlsaddr:$dst)>,
  3781. Requires<[IsThumb2, UseMovtInPic]>;
  3782. def : T2Pat<(ARMWrapper tglobaltlsaddr:$dst),
  3783. (t2MOVi32imm tglobaltlsaddr:$dst)>,
  3784. Requires<[IsThumb2, UseMovt]>;
  3785. // ConstantPool, GlobalAddress, and JumpTable
  3786. def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
  3787. def : T2Pat<(ARMWrapper texternalsym :$dst), (t2MOVi32imm texternalsym :$dst)>,
  3788. Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
  3789. def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
  3790. Requires<[IsThumb, HasV8MBaseline, UseMovt]>;
  3791. def : T2Pat<(ARMWrapperJT tjumptable:$dst), (t2LEApcrelJT tjumptable:$dst)>;
  3792. let hasNoSchedulingInfo = 1 in {
  3793. def t2LDRLIT_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
  3794. IIC_iLoadiALU,
  3795. [(set rGPR:$dst,
  3796. (ARMWrapperPIC tglobaladdr:$addr))]>,
  3797. Requires<[IsThumb, HasV8MBaseline, DontUseMovtInPic]>;
  3798. }
  3799. // TLS globals
  3800. def : Pat<(ARMWrapperPIC tglobaltlsaddr:$addr),
  3801. (t2LDRLIT_ga_pcrel tglobaltlsaddr:$addr)>,
  3802. Requires<[IsThumb, HasV8MBaseline, DontUseMovtInPic]>;
  3803. // Pseudo instruction that combines ldr from constpool and add pc. This should
  3804. // be expanded into two instructions late to allow if-conversion and
  3805. // scheduling.
  3806. let canFoldAsLoad = 1, isReMaterializable = 1 in
  3807. def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
  3808. IIC_iLoadiALU,
  3809. [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
  3810. imm:$cp))]>,
  3811. Requires<[IsThumb2]>;
  3812. // Pseudo instruction that combines movs + predicated rsbmi
  3813. // to implement integer ABS
  3814. let usesCustomInserter = 1, Defs = [CPSR], hasNoSchedulingInfo = 1 in {
  3815. def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
  3816. NoItinerary, []>, Requires<[IsThumb2]>;
  3817. }
  3818. //===----------------------------------------------------------------------===//
  3819. // Coprocessor load/store -- for disassembly only
  3820. //
  3821. class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm,
  3822. list<dag> pattern, AddrMode am = AddrModeNone>
  3823. : T2I<oops, iops, NoItinerary, opc, asm, pattern, am> {
  3824. let Inst{31-28} = op31_28;
  3825. let Inst{27-25} = 0b110;
  3826. }
  3827. multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm, list<dag> pattern> {
  3828. def _OFFSET : T2CI<op31_28,
  3829. (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
  3830. asm, "\t$cop, $CRd, $addr", pattern, AddrMode5> {
  3831. bits<13> addr;
  3832. bits<4> cop;
  3833. bits<4> CRd;
  3834. let Inst{24} = 1; // P = 1
  3835. let Inst{23} = addr{8};
  3836. let Inst{22} = Dbit;
  3837. let Inst{21} = 0; // W = 0
  3838. let Inst{20} = load;
  3839. let Inst{19-16} = addr{12-9};
  3840. let Inst{15-12} = CRd;
  3841. let Inst{11-8} = cop;
  3842. let Inst{7-0} = addr{7-0};
  3843. let DecoderMethod = "DecodeCopMemInstruction";
  3844. }
  3845. def _PRE : T2CI<op31_28,
  3846. (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
  3847. asm, "\t$cop, $CRd, $addr!", []> {
  3848. bits<13> addr;
  3849. bits<4> cop;
  3850. bits<4> CRd;
  3851. let Inst{24} = 1; // P = 1
  3852. let Inst{23} = addr{8};
  3853. let Inst{22} = Dbit;
  3854. let Inst{21} = 1; // W = 1
  3855. let Inst{20} = load;
  3856. let Inst{19-16} = addr{12-9};
  3857. let Inst{15-12} = CRd;
  3858. let Inst{11-8} = cop;
  3859. let Inst{7-0} = addr{7-0};
  3860. let DecoderMethod = "DecodeCopMemInstruction";
  3861. }
  3862. def _POST: T2CI<op31_28,
  3863. (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
  3864. postidx_imm8s4:$offset),
  3865. asm, "\t$cop, $CRd, $addr, $offset", []> {
  3866. bits<9> offset;
  3867. bits<4> addr;
  3868. bits<4> cop;
  3869. bits<4> CRd;
  3870. let Inst{24} = 0; // P = 0
  3871. let Inst{23} = offset{8};
  3872. let Inst{22} = Dbit;
  3873. let Inst{21} = 1; // W = 1
  3874. let Inst{20} = load;
  3875. let Inst{19-16} = addr;
  3876. let Inst{15-12} = CRd;
  3877. let Inst{11-8} = cop;
  3878. let Inst{7-0} = offset{7-0};
  3879. let DecoderMethod = "DecodeCopMemInstruction";
  3880. }
  3881. def _OPTION : T2CI<op31_28, (outs),
  3882. (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
  3883. coproc_option_imm:$option),
  3884. asm, "\t$cop, $CRd, $addr, $option", []> {
  3885. bits<8> option;
  3886. bits<4> addr;
  3887. bits<4> cop;
  3888. bits<4> CRd;
  3889. let Inst{24} = 0; // P = 0
  3890. let Inst{23} = 1; // U = 1
  3891. let Inst{22} = Dbit;
  3892. let Inst{21} = 0; // W = 0
  3893. let Inst{20} = load;
  3894. let Inst{19-16} = addr;
  3895. let Inst{15-12} = CRd;
  3896. let Inst{11-8} = cop;
  3897. let Inst{7-0} = option;
  3898. let DecoderMethod = "DecodeCopMemInstruction";
  3899. }
  3900. }
  3901. let DecoderNamespace = "Thumb2CoProc" in {
  3902. defm t2LDC : t2LdStCop<0b1110, 1, 0, "ldc", [(int_arm_ldc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3903. defm t2LDCL : t2LdStCop<0b1110, 1, 1, "ldcl", [(int_arm_ldcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3904. defm t2LDC2 : t2LdStCop<0b1111, 1, 0, "ldc2", [(int_arm_ldc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3905. defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l", [(int_arm_ldc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3906. defm t2STC : t2LdStCop<0b1110, 0, 0, "stc", [(int_arm_stc timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3907. defm t2STCL : t2LdStCop<0b1110, 0, 1, "stcl", [(int_arm_stcl timm:$cop, timm:$CRd, addrmode5:$addr)]>;
  3908. defm t2STC2 : t2LdStCop<0b1111, 0, 0, "stc2", [(int_arm_stc2 timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3909. defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l", [(int_arm_stc2l timm:$cop, timm:$CRd, addrmode5:$addr)]>, Requires<[PreV8,IsThumb2]>;
  3910. }
  3911. //===----------------------------------------------------------------------===//
  3912. // Move between special register and ARM core register -- for disassembly only
  3913. //
  3914. // Move to ARM core register from Special Register
  3915. // A/R class MRS.
  3916. //
  3917. // A/R class can only move from CPSR or SPSR.
  3918. def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
  3919. []>, Requires<[IsThumb2,IsNotMClass]> {
  3920. bits<4> Rd;
  3921. let Inst{31-12} = 0b11110011111011111000;
  3922. let Inst{11-8} = Rd;
  3923. let Inst{7-0} = 0b00000000;
  3924. }
  3925. def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
  3926. def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
  3927. []>, Requires<[IsThumb2,IsNotMClass]> {
  3928. bits<4> Rd;
  3929. let Inst{31-12} = 0b11110011111111111000;
  3930. let Inst{11-8} = Rd;
  3931. let Inst{7-0} = 0b00000000;
  3932. }
  3933. def t2MRSbanked : T2I<(outs rGPR:$Rd), (ins banked_reg:$banked),
  3934. NoItinerary, "mrs", "\t$Rd, $banked", []>,
  3935. Requires<[IsThumb, HasVirtualization]> {
  3936. bits<6> banked;
  3937. bits<4> Rd;
  3938. let Inst{31-21} = 0b11110011111;
  3939. let Inst{20} = banked{5}; // R bit
  3940. let Inst{19-16} = banked{3-0};
  3941. let Inst{15-12} = 0b1000;
  3942. let Inst{11-8} = Rd;
  3943. let Inst{7-5} = 0b001;
  3944. let Inst{4} = banked{4};
  3945. let Inst{3-0} = 0b0000;
  3946. }
  3947. // M class MRS.
  3948. //
  3949. // This MRS has a mask field in bits 7-0 and can take more values than
  3950. // the A/R class (a full msr_mask).
  3951. def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$SYSm), NoItinerary,
  3952. "mrs", "\t$Rd, $SYSm", []>,
  3953. Requires<[IsThumb,IsMClass]> {
  3954. bits<4> Rd;
  3955. bits<8> SYSm;
  3956. let Inst{31-12} = 0b11110011111011111000;
  3957. let Inst{11-8} = Rd;
  3958. let Inst{7-0} = SYSm;
  3959. let Unpredictable{20-16} = 0b11111;
  3960. let Unpredictable{13} = 0b1;
  3961. }
  3962. // Move from ARM core register to Special Register
  3963. //
  3964. // A/R class MSR.
  3965. //
  3966. // No need to have both system and application versions, the encodings are the
  3967. // same and the assembly parser has no way to distinguish between them. The mask
  3968. // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
  3969. // the mask with the fields to be accessed in the special register.
  3970. let Defs = [CPSR] in
  3971. def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
  3972. NoItinerary, "msr", "\t$mask, $Rn", []>,
  3973. Requires<[IsThumb2,IsNotMClass]> {
  3974. bits<5> mask;
  3975. bits<4> Rn;
  3976. let Inst{31-21} = 0b11110011100;
  3977. let Inst{20} = mask{4}; // R Bit
  3978. let Inst{19-16} = Rn;
  3979. let Inst{15-12} = 0b1000;
  3980. let Inst{11-8} = mask{3-0};
  3981. let Inst{7-0} = 0;
  3982. }
  3983. // However, the MSR (banked register) system instruction (ARMv7VE) *does* have a
  3984. // separate encoding (distinguished by bit 5.
  3985. def t2MSRbanked : T2I<(outs), (ins banked_reg:$banked, rGPR:$Rn),
  3986. NoItinerary, "msr", "\t$banked, $Rn", []>,
  3987. Requires<[IsThumb, HasVirtualization]> {
  3988. bits<6> banked;
  3989. bits<4> Rn;
  3990. let Inst{31-21} = 0b11110011100;
  3991. let Inst{20} = banked{5}; // R bit
  3992. let Inst{19-16} = Rn;
  3993. let Inst{15-12} = 0b1000;
  3994. let Inst{11-8} = banked{3-0};
  3995. let Inst{7-5} = 0b001;
  3996. let Inst{4} = banked{4};
  3997. let Inst{3-0} = 0b0000;
  3998. }
  3999. // M class MSR.
  4000. //
  4001. // Move from ARM core register to Special Register
  4002. let Defs = [CPSR] in
  4003. def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
  4004. NoItinerary, "msr", "\t$SYSm, $Rn", []>,
  4005. Requires<[IsThumb,IsMClass]> {
  4006. bits<12> SYSm;
  4007. bits<4> Rn;
  4008. let Inst{31-21} = 0b11110011100;
  4009. let Inst{20} = 0b0;
  4010. let Inst{19-16} = Rn;
  4011. let Inst{15-12} = 0b1000;
  4012. let Inst{11-10} = SYSm{11-10};
  4013. let Inst{9-8} = 0b00;
  4014. let Inst{7-0} = SYSm{7-0};
  4015. let Unpredictable{20} = 0b1;
  4016. let Unpredictable{13} = 0b1;
  4017. let Unpredictable{9-8} = 0b11;
  4018. }
  4019. //===----------------------------------------------------------------------===//
  4020. // Move between coprocessor and ARM core register
  4021. //
  4022. class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
  4023. list<dag> pattern>
  4024. : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2",
  4025. pattern> {
  4026. let Inst{27-24} = 0b1110;
  4027. let Inst{20} = direction;
  4028. let Inst{4} = 1;
  4029. bits<4> Rt;
  4030. bits<4> cop;
  4031. bits<3> opc1;
  4032. bits<3> opc2;
  4033. bits<4> CRm;
  4034. bits<4> CRn;
  4035. let Inst{15-12} = Rt;
  4036. let Inst{11-8} = cop;
  4037. let Inst{23-21} = opc1;
  4038. let Inst{7-5} = opc2;
  4039. let Inst{3-0} = CRm;
  4040. let Inst{19-16} = CRn;
  4041. let DecoderNamespace = "Thumb2CoProc";
  4042. }
  4043. class t2MovRRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
  4044. list<dag> pattern = []>
  4045. : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
  4046. let Inst{27-24} = 0b1100;
  4047. let Inst{23-21} = 0b010;
  4048. let Inst{20} = direction;
  4049. bits<4> Rt;
  4050. bits<4> Rt2;
  4051. bits<4> cop;
  4052. bits<4> opc1;
  4053. bits<4> CRm;
  4054. let Inst{15-12} = Rt;
  4055. let Inst{19-16} = Rt2;
  4056. let Inst{11-8} = cop;
  4057. let Inst{7-4} = opc1;
  4058. let Inst{3-0} = CRm;
  4059. let DecoderNamespace = "Thumb2CoProc";
  4060. }
  4061. /* from ARM core register to coprocessor */
  4062. def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
  4063. (outs),
  4064. (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4065. c_imm:$CRm, imm0_7:$opc2),
  4066. [(int_arm_mcr timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
  4067. timm:$CRm, timm:$opc2)]>,
  4068. ComplexDeprecationPredicate<"MCR">;
  4069. def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4070. (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4071. c_imm:$CRm, 0, pred:$p)>;
  4072. def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
  4073. (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4074. c_imm:$CRm, imm0_7:$opc2),
  4075. [(int_arm_mcr2 timm:$cop, timm:$opc1, GPR:$Rt, timm:$CRn,
  4076. timm:$CRm, timm:$opc2)]> {
  4077. let Predicates = [IsThumb2, PreV8];
  4078. }
  4079. def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4080. (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
  4081. c_imm:$CRm, 0, pred:$p)>;
  4082. /* from coprocessor to ARM core register */
  4083. def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
  4084. (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4085. c_imm:$CRm, imm0_7:$opc2), []>;
  4086. def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4087. (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4088. c_imm:$CRm, 0, pred:$p)>;
  4089. def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
  4090. (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4091. c_imm:$CRm, imm0_7:$opc2), []> {
  4092. let Predicates = [IsThumb2, PreV8];
  4093. }
  4094. def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm",
  4095. (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
  4096. c_imm:$CRm, 0, pred:$p)>;
  4097. def : T2v6Pat<(int_arm_mrc timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
  4098. (t2MRC p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
  4099. def : T2v6Pat<(int_arm_mrc2 timm:$cop, timm:$opc1, timm:$CRn, timm:$CRm, timm:$opc2),
  4100. (t2MRC2 p_imm:$cop, imm0_7:$opc1, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2)>;
  4101. /* from ARM core register to coprocessor */
  4102. def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, (outs),
  4103. (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
  4104. c_imm:$CRm),
  4105. [(int_arm_mcrr timm:$cop, timm:$opc1, GPR:$Rt, GPR:$Rt2,
  4106. timm:$CRm)]>;
  4107. def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, (outs),
  4108. (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
  4109. c_imm:$CRm),
  4110. [(int_arm_mcrr2 timm:$cop, timm:$opc1, GPR:$Rt,
  4111. GPR:$Rt2, timm:$CRm)]> {
  4112. let Predicates = [IsThumb2, PreV8];
  4113. }
  4114. /* from coprocessor to ARM core register */
  4115. def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1, (outs GPR:$Rt, GPR:$Rt2),
  4116. (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)>;
  4117. def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1, (outs GPR:$Rt, GPR:$Rt2),
  4118. (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)> {
  4119. let Predicates = [IsThumb2, PreV8];
  4120. }
  4121. //===----------------------------------------------------------------------===//
  4122. // Other Coprocessor Instructions.
  4123. //
  4124. def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
  4125. c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
  4126. "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
  4127. [(int_arm_cdp timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
  4128. timm:$CRm, timm:$opc2)]> {
  4129. let Inst{27-24} = 0b1110;
  4130. bits<4> opc1;
  4131. bits<4> CRn;
  4132. bits<4> CRd;
  4133. bits<4> cop;
  4134. bits<3> opc2;
  4135. bits<4> CRm;
  4136. let Inst{3-0} = CRm;
  4137. let Inst{4} = 0;
  4138. let Inst{7-5} = opc2;
  4139. let Inst{11-8} = cop;
  4140. let Inst{15-12} = CRd;
  4141. let Inst{19-16} = CRn;
  4142. let Inst{23-20} = opc1;
  4143. let Predicates = [IsThumb2, PreV8];
  4144. let DecoderNamespace = "Thumb2CoProc";
  4145. }
  4146. def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
  4147. c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
  4148. "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
  4149. [(int_arm_cdp2 timm:$cop, timm:$opc1, timm:$CRd, timm:$CRn,
  4150. timm:$CRm, timm:$opc2)]> {
  4151. let Inst{27-24} = 0b1110;
  4152. bits<4> opc1;
  4153. bits<4> CRn;
  4154. bits<4> CRd;
  4155. bits<4> cop;
  4156. bits<3> opc2;
  4157. bits<4> CRm;
  4158. let Inst{3-0} = CRm;
  4159. let Inst{4} = 0;
  4160. let Inst{7-5} = opc2;
  4161. let Inst{11-8} = cop;
  4162. let Inst{15-12} = CRd;
  4163. let Inst{19-16} = CRn;
  4164. let Inst{23-20} = opc1;
  4165. let Predicates = [IsThumb2, PreV8];
  4166. let DecoderNamespace = "Thumb2CoProc";
  4167. }
  4168. // Reading thread pointer from coprocessor register
  4169. def : T2Pat<(ARMthread_pointer), (t2MRC 15, 0, 13, 0, 3)>,
  4170. Requires<[IsThumb2, IsReadTPHard]>;
  4171. //===----------------------------------------------------------------------===//
  4172. // ARMv8.1 Privilege Access Never extension
  4173. //
  4174. // SETPAN #imm1
  4175. def t2SETPAN : T1I<(outs), (ins imm0_1:$imm), NoItinerary, "setpan\t$imm", []>,
  4176. T1Misc<0b0110000>, Requires<[IsThumb2, HasV8, HasV8_1a]> {
  4177. bits<1> imm;
  4178. let Inst{4} = 0b1;
  4179. let Inst{3} = imm;
  4180. let Inst{2-0} = 0b000;
  4181. let Unpredictable{4} = 0b1;
  4182. let Unpredictable{2-0} = 0b111;
  4183. }
  4184. //===----------------------------------------------------------------------===//
  4185. // ARMv8-M Security Extensions instructions
  4186. //
  4187. let hasSideEffects = 1 in
  4188. def t2SG : T2I<(outs), (ins), NoItinerary, "sg", "", []>,
  4189. Requires<[Has8MSecExt]> {
  4190. let Inst = 0xe97fe97f;
  4191. }
  4192. class T2TT<bits<2> at, string asm, list<dag> pattern>
  4193. : T2I<(outs rGPR:$Rt), (ins GPRnopc:$Rn), NoItinerary, asm, "\t$Rt, $Rn",
  4194. pattern> {
  4195. bits<4> Rn;
  4196. bits<4> Rt;
  4197. let Inst{31-20} = 0b111010000100;
  4198. let Inst{19-16} = Rn;
  4199. let Inst{15-12} = 0b1111;
  4200. let Inst{11-8} = Rt;
  4201. let Inst{7-6} = at;
  4202. let Inst{5-0} = 0b000000;
  4203. let Unpredictable{5-0} = 0b111111;
  4204. }
  4205. def t2TT : T2TT<0b00, "tt",
  4206. [(set rGPR:$Rt, (int_arm_cmse_tt GPRnopc:$Rn))]>,
  4207. Requires<[IsThumb, Has8MSecExt]>;
  4208. def t2TTT : T2TT<0b01, "ttt",
  4209. [(set rGPR:$Rt, (int_arm_cmse_ttt GPRnopc:$Rn))]>,
  4210. Requires<[IsThumb, Has8MSecExt]>;
  4211. def t2TTA : T2TT<0b10, "tta",
  4212. [(set rGPR:$Rt, (int_arm_cmse_tta GPRnopc:$Rn))]>,
  4213. Requires<[IsThumb, Has8MSecExt]>;
  4214. def t2TTAT : T2TT<0b11, "ttat",
  4215. [(set rGPR:$Rt, (int_arm_cmse_ttat GPRnopc:$Rn))]>,
  4216. Requires<[IsThumb, Has8MSecExt]>;
  4217. //===----------------------------------------------------------------------===//
  4218. // Non-Instruction Patterns
  4219. //
  4220. // SXT/UXT with no rotate
  4221. let AddedComplexity = 16 in {
  4222. def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
  4223. Requires<[IsThumb2]>;
  4224. def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
  4225. Requires<[IsThumb2]>;
  4226. def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
  4227. Requires<[HasDSP, IsThumb2]>;
  4228. def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
  4229. (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
  4230. Requires<[HasDSP, IsThumb2]>;
  4231. def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
  4232. (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
  4233. Requires<[HasDSP, IsThumb2]>;
  4234. }
  4235. def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
  4236. Requires<[IsThumb2]>;
  4237. def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
  4238. Requires<[IsThumb2]>;
  4239. def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
  4240. (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
  4241. Requires<[HasDSP, IsThumb2]>;
  4242. def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
  4243. (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
  4244. Requires<[HasDSP, IsThumb2]>;
  4245. // Atomic load/store patterns
  4246. def : T2Pat<(atomic_load_8 t2addrmode_imm12:$addr),
  4247. (t2LDRBi12 t2addrmode_imm12:$addr)>;
  4248. def : T2Pat<(atomic_load_8 t2addrmode_negimm8:$addr),
  4249. (t2LDRBi8 t2addrmode_negimm8:$addr)>;
  4250. def : T2Pat<(atomic_load_8 t2addrmode_so_reg:$addr),
  4251. (t2LDRBs t2addrmode_so_reg:$addr)>;
  4252. def : T2Pat<(atomic_load_16 t2addrmode_imm12:$addr),
  4253. (t2LDRHi12 t2addrmode_imm12:$addr)>;
  4254. def : T2Pat<(atomic_load_16 t2addrmode_negimm8:$addr),
  4255. (t2LDRHi8 t2addrmode_negimm8:$addr)>;
  4256. def : T2Pat<(atomic_load_16 t2addrmode_so_reg:$addr),
  4257. (t2LDRHs t2addrmode_so_reg:$addr)>;
  4258. def : T2Pat<(atomic_load_32 t2addrmode_imm12:$addr),
  4259. (t2LDRi12 t2addrmode_imm12:$addr)>;
  4260. def : T2Pat<(atomic_load_32 t2addrmode_negimm8:$addr),
  4261. (t2LDRi8 t2addrmode_negimm8:$addr)>;
  4262. def : T2Pat<(atomic_load_32 t2addrmode_so_reg:$addr),
  4263. (t2LDRs t2addrmode_so_reg:$addr)>;
  4264. def : T2Pat<(atomic_store_8 t2addrmode_imm12:$addr, GPR:$val),
  4265. (t2STRBi12 GPR:$val, t2addrmode_imm12:$addr)>;
  4266. def : T2Pat<(atomic_store_8 t2addrmode_negimm8:$addr, GPR:$val),
  4267. (t2STRBi8 GPR:$val, t2addrmode_negimm8:$addr)>;
  4268. def : T2Pat<(atomic_store_8 t2addrmode_so_reg:$addr, GPR:$val),
  4269. (t2STRBs GPR:$val, t2addrmode_so_reg:$addr)>;
  4270. def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
  4271. (t2STRHi12 GPR:$val, t2addrmode_imm12:$addr)>;
  4272. def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
  4273. (t2STRHi8 GPR:$val, t2addrmode_negimm8:$addr)>;
  4274. def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
  4275. (t2STRHs GPR:$val, t2addrmode_so_reg:$addr)>;
  4276. def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
  4277. (t2STRi12 GPR:$val, t2addrmode_imm12:$addr)>;
  4278. def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
  4279. (t2STRi8 GPR:$val, t2addrmode_negimm8:$addr)>;
  4280. def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
  4281. (t2STRs GPR:$val, t2addrmode_so_reg:$addr)>;
  4282. let AddedComplexity = 8, Predicates = [IsThumb, HasAcquireRelease, HasV7Clrex] in {
  4283. def : Pat<(atomic_load_acquire_8 addr_offset_none:$addr), (t2LDAB addr_offset_none:$addr)>;
  4284. def : Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>;
  4285. def : Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA addr_offset_none:$addr)>;
  4286. def : Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val), (t2STLB GPR:$val, addr_offset_none:$addr)>;
  4287. def : Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>;
  4288. def : Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL GPR:$val, addr_offset_none:$addr)>;
  4289. }
  4290. //===----------------------------------------------------------------------===//
  4291. // Assembler aliases
  4292. //
  4293. // Aliases for ADC without the ".w" optional width specifier.
  4294. def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
  4295. (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4296. def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
  4297. (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
  4298. pred:$p, cc_out:$s)>;
  4299. // Aliases for SBC without the ".w" optional width specifier.
  4300. def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
  4301. (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4302. def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
  4303. (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
  4304. pred:$p, cc_out:$s)>;
  4305. // Aliases for ADD without the ".w" optional width specifier.
  4306. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
  4307. (t2ADDri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p,
  4308. cc_out:$s)>;
  4309. def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
  4310. (t2ADDri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
  4311. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
  4312. (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4313. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
  4314. (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
  4315. pred:$p, cc_out:$s)>;
  4316. // ... and with the destination and source register combined.
  4317. def : t2InstAlias<"add${s}${p} $Rdn, $imm",
  4318. (t2ADDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4319. def : t2InstAlias<"add${p} $Rdn, $imm",
  4320. (t2ADDri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4321. def : t2InstAlias<"addw${p} $Rdn, $imm",
  4322. (t2ADDri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4323. def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
  4324. (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4325. def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
  4326. (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
  4327. pred:$p, cc_out:$s)>;
  4328. // add w/ negative immediates is just a sub.
  4329. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4330. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4331. cc_out:$s)>;
  4332. def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
  4333. (t2SUBri12 rGPR:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4334. def : t2InstSubst<"add${s}${p} $Rdn, $imm",
  4335. (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4336. cc_out:$s)>;
  4337. def : t2InstSubst<"add${p} $Rdn, $imm",
  4338. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4339. def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
  4340. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4341. cc_out:$s)>;
  4342. def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
  4343. (t2SUBri12 rGPR:$Rd, rGPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4344. def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
  4345. (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4346. cc_out:$s)>;
  4347. def : t2InstSubst<"addw${p} $Rdn, $imm",
  4348. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4349. // Aliases for SUB without the ".w" optional width specifier.
  4350. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
  4351. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4352. def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
  4353. (t2SUBri12 rGPR:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
  4354. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
  4355. (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4356. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
  4357. (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
  4358. pred:$p, cc_out:$s)>;
  4359. // ... and with the destination and source register combined.
  4360. def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
  4361. (t2SUBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4362. def : t2InstAlias<"sub${p} $Rdn, $imm",
  4363. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4364. def : t2InstAlias<"subw${p} $Rdn, $imm",
  4365. (t2SUBri12 rGPR:$Rdn, rGPR:$Rdn, imm0_4095:$imm, pred:$p)>;
  4366. def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
  4367. (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4368. def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
  4369. (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4370. def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
  4371. (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
  4372. pred:$p, cc_out:$s)>;
  4373. // SP to SP alike aliases
  4374. // Aliases for ADD without the ".w" optional width specifier.
  4375. def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
  4376. (t2ADDspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm:$imm, pred:$p,
  4377. cc_out:$s)>;
  4378. def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
  4379. (t2ADDspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095:$imm, pred:$p)>;
  4380. // ... and with the destination and source register combined.
  4381. def : t2InstAlias<"add${s}${p} $Rdn, $imm",
  4382. (t2ADDspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4383. def : t2InstAlias<"add${s}${p}.w $Rdn, $imm",
  4384. (t2ADDspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4385. def : t2InstAlias<"add${p} $Rdn, $imm",
  4386. (t2ADDspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4387. def : t2InstAlias<"addw${p} $Rdn, $imm",
  4388. (t2ADDspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4389. // add w/ negative immediates is just a sub.
  4390. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4391. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4392. cc_out:$s)>;
  4393. def : t2InstSubst<"add${p} $Rd, $Rn, $imm",
  4394. (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4395. def : t2InstSubst<"add${s}${p} $Rdn, $imm",
  4396. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4397. cc_out:$s)>;
  4398. def : t2InstSubst<"add${p} $Rdn, $imm",
  4399. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4400. def : t2InstSubst<"add${s}${p}.w $Rd, $Rn, $imm",
  4401. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm, pred:$p,
  4402. cc_out:$s)>;
  4403. def : t2InstSubst<"addw${p} $Rd, $Rn, $imm",
  4404. (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095_neg:$imm, pred:$p)>;
  4405. def : t2InstSubst<"add${s}${p}.w $Rdn, $imm",
  4406. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm_neg:$imm, pred:$p,
  4407. cc_out:$s)>;
  4408. def : t2InstSubst<"addw${p} $Rdn, $imm",
  4409. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
  4410. // Aliases for SUB without the ".w" optional width specifier.
  4411. def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
  4412. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4413. def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
  4414. (t2SUBspImm12 GPRsp:$Rd, GPRsp:$Rn, imm0_4095:$imm, pred:$p)>;
  4415. // ... and with the destination and source register combined.
  4416. def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
  4417. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4418. def : t2InstAlias<"sub${s}${p}.w $Rdn, $imm",
  4419. (t2SUBspImm GPRsp:$Rdn, GPRsp:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4420. def : t2InstAlias<"sub${p} $Rdn, $imm",
  4421. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4422. def : t2InstAlias<"subw${p} $Rdn, $imm",
  4423. (t2SUBspImm12 GPRsp:$Rdn, GPRsp:$Rdn, imm0_4095:$imm, pred:$p)>;
  4424. // Alias for compares without the ".w" optional width specifier.
  4425. def : t2InstAlias<"cmn${p} $Rn, $Rm",
  4426. (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
  4427. def : t2InstAlias<"teq${p} $Rn, $Rm",
  4428. (t2TEQrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
  4429. def : t2InstAlias<"tst${p} $Rn, $Rm",
  4430. (t2TSTrr rGPR:$Rn, rGPR:$Rm, pred:$p)>;
  4431. // Memory barriers
  4432. def : InstAlias<"dmb${p}.w\t$opt", (t2DMB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
  4433. def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4434. def : InstAlias<"dmb${p}.w", (t2DMB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4435. def : InstAlias<"dsb${p}.w\t$opt", (t2DSB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
  4436. def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4437. def : InstAlias<"dsb${p}.w", (t2DSB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4438. def : InstAlias<"isb${p}.w\t$opt", (t2ISB memb_opt:$opt, pred:$p), 0>, Requires<[HasDB]>;
  4439. def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4440. def : InstAlias<"isb${p}.w", (t2ISB 0xf, pred:$p), 0>, Requires<[HasDB]>;
  4441. // Non-predicable aliases of a predicable DSB: the predicate is (14, 0) where
  4442. // 14 = AL (always execute) and 0 = "instruction doesn't read the CPSR".
  4443. def : InstAlias<"ssbb", (t2DSB 0x0, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
  4444. def : InstAlias<"pssbb", (t2DSB 0x4, 14, 0), 1>, Requires<[HasDB, IsThumb2]>;
  4445. // Armv8-R 'Data Full Barrier'
  4446. def : InstAlias<"dfb${p}", (t2DSB 0xc, pred:$p), 1>, Requires<[HasDFB]>;
  4447. // SpeculationBarrierEndBB must only be used after an unconditional control
  4448. // flow, i.e. after a terminator for which isBarrier is True.
  4449. let hasSideEffects = 1, isCodeGenOnly = 1, isTerminator = 1, isBarrier = 1 in {
  4450. // This gets lowered to a pair of 4-byte instructions
  4451. let Size = 8 in
  4452. def t2SpeculationBarrierISBDSBEndBB
  4453. : PseudoInst<(outs), (ins), NoItinerary, []>, Sched<[]>;
  4454. // This gets lowered to a single 4-byte instructions
  4455. let Size = 4 in
  4456. def t2SpeculationBarrierSBEndBB
  4457. : PseudoInst<(outs), (ins), NoItinerary, []>, Sched<[]>;
  4458. }
  4459. // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
  4460. // width specifier.
  4461. def : t2InstAlias<"ldr${p} $Rt, $addr",
  4462. (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4463. def : t2InstAlias<"ldrb${p} $Rt, $addr",
  4464. (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4465. def : t2InstAlias<"ldrh${p} $Rt, $addr",
  4466. (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4467. def : t2InstAlias<"ldrsb${p} $Rt, $addr",
  4468. (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4469. def : t2InstAlias<"ldrsh${p} $Rt, $addr",
  4470. (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4471. def : t2InstAlias<"ldr${p} $Rt, $addr",
  4472. (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4473. def : t2InstAlias<"ldrb${p} $Rt, $addr",
  4474. (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4475. def : t2InstAlias<"ldrh${p} $Rt, $addr",
  4476. (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4477. def : t2InstAlias<"ldrsb${p} $Rt, $addr",
  4478. (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4479. def : t2InstAlias<"ldrsh${p} $Rt, $addr",
  4480. (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4481. def : t2InstAlias<"ldr${p} $Rt, $addr",
  4482. (t2LDRpci GPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4483. def : t2InstAlias<"ldrb${p} $Rt, $addr",
  4484. (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4485. def : t2InstAlias<"ldrh${p} $Rt, $addr",
  4486. (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4487. def : t2InstAlias<"ldrsb${p} $Rt, $addr",
  4488. (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4489. def : t2InstAlias<"ldrsh${p} $Rt, $addr",
  4490. (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
  4491. // Alias for MVN with(out) the ".w" optional width specifier.
  4492. def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
  4493. (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4494. def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
  4495. (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4496. def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
  4497. (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
  4498. // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT with the
  4499. // input operands swapped when the shift amount is zero (i.e., unspecified).
  4500. def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
  4501. (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4502. Requires<[HasDSP, IsThumb2]>;
  4503. def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
  4504. (t2PKHBT rGPR:$Rd, rGPR:$Rm, rGPR:$Rn, 0, pred:$p), 0>,
  4505. Requires<[HasDSP, IsThumb2]>;
  4506. // PUSH/POP aliases for STM/LDM
  4507. def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
  4508. def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
  4509. def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
  4510. def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
  4511. // STMIA/STMIA_UPD aliases w/o the optional .w suffix
  4512. def : t2InstAlias<"stm${p} $Rn, $regs",
  4513. (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
  4514. def : t2InstAlias<"stm${p} $Rn!, $regs",
  4515. (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4516. // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
  4517. def : t2InstAlias<"ldm${p} $Rn, $regs",
  4518. (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
  4519. def : t2InstAlias<"ldm${p} $Rn!, $regs",
  4520. (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4521. // STMDB/STMDB_UPD aliases w/ the optional .w suffix
  4522. def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
  4523. (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
  4524. def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
  4525. (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4526. // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
  4527. def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
  4528. (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
  4529. def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
  4530. (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
  4531. // Alias for REV/REV16/REVSH without the ".w" optional width specifier.
  4532. def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
  4533. def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
  4534. def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
  4535. // Alias for RSB with and without the ".w" optional width specifier, with and
  4536. // without explicit destination register.
  4537. def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
  4538. (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4539. def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
  4540. (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
  4541. def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
  4542. (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4543. def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
  4544. (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
  4545. cc_out:$s)>;
  4546. def : t2InstAlias<"rsb${s}${p}.w $Rdn, $Rm",
  4547. (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4548. def : t2InstAlias<"rsb${s}${p}.w $Rd, $Rn, $Rm",
  4549. (t2RSBrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
  4550. def : t2InstAlias<"rsb${s}${p}.w $Rd, $Rn, $ShiftedRm",
  4551. (t2RSBrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p,
  4552. cc_out:$s)>;
  4553. // SSAT/USAT optional shift operand.
  4554. def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
  4555. (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
  4556. def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
  4557. (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
  4558. // STM w/o the .w suffix.
  4559. def : t2InstAlias<"stm${p} $Rn, $regs",
  4560. (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
  4561. // Alias for STR, STRB, and STRH without the ".w" optional
  4562. // width specifier.
  4563. def : t2InstAlias<"str${p} $Rt, $addr",
  4564. (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4565. def : t2InstAlias<"strb${p} $Rt, $addr",
  4566. (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4567. def : t2InstAlias<"strh${p} $Rt, $addr",
  4568. (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
  4569. def : t2InstAlias<"str${p} $Rt, $addr",
  4570. (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4571. def : t2InstAlias<"strb${p} $Rt, $addr",
  4572. (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4573. def : t2InstAlias<"strh${p} $Rt, $addr",
  4574. (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
  4575. // Extend instruction optional rotate operand.
  4576. def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
  4577. (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4578. Requires<[HasDSP, IsThumb2]>;
  4579. def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
  4580. (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4581. Requires<[HasDSP, IsThumb2]>;
  4582. def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
  4583. (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4584. Requires<[HasDSP, IsThumb2]>;
  4585. def : InstAlias<"sxtb16${p} $Rd, $Rm",
  4586. (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
  4587. Requires<[HasDSP, IsThumb2]>;
  4588. def : t2InstAlias<"sxtb${p} $Rd, $Rm",
  4589. (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4590. def : t2InstAlias<"sxth${p} $Rd, $Rm",
  4591. (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4592. def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
  4593. (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4594. def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
  4595. (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4596. def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
  4597. (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4598. Requires<[HasDSP, IsThumb2]>;
  4599. def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
  4600. (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4601. Requires<[HasDSP, IsThumb2]>;
  4602. def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
  4603. (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p), 0>,
  4604. Requires<[HasDSP, IsThumb2]>;
  4605. def : InstAlias<"uxtb16${p} $Rd, $Rm",
  4606. (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p), 0>,
  4607. Requires<[HasDSP, IsThumb2]>;
  4608. def : t2InstAlias<"uxtb${p} $Rd, $Rm",
  4609. (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4610. def : t2InstAlias<"uxth${p} $Rd, $Rm",
  4611. (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4612. def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
  4613. (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4614. def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
  4615. (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
  4616. // Extend instruction w/o the ".w" optional width specifier.
  4617. def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
  4618. (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4619. def : InstAlias<"uxtb16${p} $Rd, $Rm$rot",
  4620. (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
  4621. Requires<[HasDSP, IsThumb2]>;
  4622. def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
  4623. (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4624. def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
  4625. (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4626. def : InstAlias<"sxtb16${p} $Rd, $Rm$rot",
  4627. (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p), 0>,
  4628. Requires<[HasDSP, IsThumb2]>;
  4629. def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
  4630. (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
  4631. // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
  4632. // for isel.
  4633. def : t2InstSubst<"mov${p} $Rd, $imm",
  4634. (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
  4635. def : t2InstSubst<"mvn${s}${p} $Rd, $imm",
  4636. (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, s_cc_out:$s)>;
  4637. // Same for AND <--> BIC
  4638. def : t2InstSubst<"bic${s}${p} $Rd, $Rn, $imm",
  4639. (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4640. pred:$p, cc_out:$s)>;
  4641. def : t2InstSubst<"bic${s}${p} $Rdn, $imm",
  4642. (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4643. pred:$p, cc_out:$s)>;
  4644. def : t2InstSubst<"bic${s}${p}.w $Rd, $Rn, $imm",
  4645. (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4646. pred:$p, cc_out:$s)>;
  4647. def : t2InstSubst<"bic${s}${p}.w $Rdn, $imm",
  4648. (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4649. pred:$p, cc_out:$s)>;
  4650. def : t2InstSubst<"and${s}${p} $Rd, $Rn, $imm",
  4651. (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4652. pred:$p, cc_out:$s)>;
  4653. def : t2InstSubst<"and${s}${p} $Rdn, $imm",
  4654. (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4655. pred:$p, cc_out:$s)>;
  4656. def : t2InstSubst<"and${s}${p}.w $Rd, $Rn, $imm",
  4657. (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4658. pred:$p, cc_out:$s)>;
  4659. def : t2InstSubst<"and${s}${p}.w $Rdn, $imm",
  4660. (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4661. pred:$p, cc_out:$s)>;
  4662. // And ORR <--> ORN
  4663. def : t2InstSubst<"orn${s}${p} $Rd, $Rn, $imm",
  4664. (t2ORRri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4665. pred:$p, cc_out:$s)>;
  4666. def : t2InstSubst<"orn${s}${p} $Rdn, $imm",
  4667. (t2ORRri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4668. pred:$p, cc_out:$s)>;
  4669. def : t2InstSubst<"orr${s}${p} $Rd, $Rn, $imm",
  4670. (t2ORNri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
  4671. pred:$p, cc_out:$s)>;
  4672. def : t2InstSubst<"orr${s}${p} $Rdn, $imm",
  4673. (t2ORNri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
  4674. pred:$p, cc_out:$s)>;
  4675. // Likewise, "add Rd, t2_so_imm_neg" -> sub
  4676. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4677. (t2SUBri rGPR:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
  4678. pred:$p, cc_out:$s)>;
  4679. def : t2InstSubst<"add${s}${p} $Rd, $Rn, $imm",
  4680. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rn, t2_so_imm_neg:$imm,
  4681. pred:$p, cc_out:$s)>;
  4682. def : t2InstSubst<"add${s}${p} $Rd, $imm",
  4683. (t2SUBri rGPR:$Rd, rGPR:$Rd, t2_so_imm_neg:$imm,
  4684. pred:$p, cc_out:$s)>;
  4685. def : t2InstSubst<"add${s}${p} $Rd, $imm",
  4686. (t2SUBspImm GPRsp:$Rd, GPRsp:$Rd, t2_so_imm_neg:$imm,
  4687. pred:$p, cc_out:$s)>;
  4688. // Same for CMP <--> CMN via t2_so_imm_neg
  4689. def : t2InstSubst<"cmp${p} $Rd, $imm",
  4690. (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
  4691. def : t2InstSubst<"cmn${p} $Rd, $imm",
  4692. (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
  4693. // Wide 'mul' encoding can be specified with only two operands.
  4694. def : t2InstAlias<"mul${p} $Rn, $Rm",
  4695. (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
  4696. // "neg" is and alias for "rsb rd, rn, #0"
  4697. def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
  4698. (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
  4699. // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
  4700. // these, unfortunately.
  4701. // FIXME: LSL #0 in the shift should allow SP to be used as either the
  4702. // source or destination (but not both).
  4703. def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
  4704. (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4705. def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
  4706. (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4707. def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
  4708. (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4709. def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
  4710. (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4711. // Aliases for the above with the .w qualifier
  4712. def : t2InstAlias<"mov${p}.w $Rd, $shift",
  4713. (t2MOVsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4714. def : t2InstAlias<"movs${p}.w $Rd, $shift",
  4715. (t2MOVSsi rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
  4716. def : t2InstAlias<"mov${p}.w $Rd, $shift",
  4717. (t2MOVsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4718. def : t2InstAlias<"movs${p}.w $Rd, $shift",
  4719. (t2MOVSsr rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
  4720. // ADR w/o the .w suffix
  4721. def : t2InstAlias<"adr${p} $Rd, $addr",
  4722. (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
  4723. // LDR(literal) w/ alternate [pc, #imm] syntax.
  4724. def t2LDRpcrel : t2AsmPseudo<"ldr${p} $Rt, $addr",
  4725. (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4726. def t2LDRBpcrel : t2AsmPseudo<"ldrb${p} $Rt, $addr",
  4727. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4728. def t2LDRHpcrel : t2AsmPseudo<"ldrh${p} $Rt, $addr",
  4729. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4730. def t2LDRSBpcrel : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
  4731. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4732. def t2LDRSHpcrel : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
  4733. (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4734. // Version w/ the .w suffix.
  4735. def : t2InstAlias<"ldr${p}.w $Rt, $addr",
  4736. (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>;
  4737. def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
  4738. (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4739. def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
  4740. (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4741. def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
  4742. (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4743. def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
  4744. (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
  4745. def : t2InstAlias<"add${p} $Rd, pc, $imm",
  4746. (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;
  4747. // Pseudo instruction ldr Rt, =immediate
  4748. def t2LDRConstPool
  4749. : t2AsmPseudo<"ldr${p} $Rt, $immediate",
  4750. (ins GPR:$Rt, const_pool_asm_imm:$immediate, pred:$p)>;
  4751. // Version w/ the .w suffix.
  4752. def : t2InstAlias<"ldr${p}.w $Rt, $immediate",
  4753. (t2LDRConstPool GPRnopc:$Rt,
  4754. const_pool_asm_imm:$immediate, pred:$p)>;
  4755. //===----------------------------------------------------------------------===//
  4756. // ARMv8.1m instructions
  4757. //
  4758. class V8_1MI<dag oops, dag iops, AddrMode am, InstrItinClass itin, string asm,
  4759. string ops, string cstr, list<dag> pattern>
  4760. : Thumb2XI<oops, iops, am, 4, itin, !strconcat(asm, "\t", ops), cstr,
  4761. pattern>,
  4762. Requires<[HasV8_1MMainline]>;
  4763. def t2CLRM : V8_1MI<(outs),
  4764. (ins pred:$p, reglist_with_apsr:$regs, variable_ops),
  4765. AddrModeNone, NoItinerary, "clrm${p}", "$regs", "", []> {
  4766. bits<16> regs;
  4767. let Inst{31-16} = 0b1110100010011111;
  4768. let Inst{15-14} = regs{15-14};
  4769. let Inst{13} = 0b0;
  4770. let Inst{12-0} = regs{12-0};
  4771. }
  4772. class t2BF<dag iops, string asm, string ops>
  4773. : V8_1MI<(outs ), iops, AddrModeNone, NoItinerary, asm, ops, "", []> {
  4774. let Inst{31-27} = 0b11110;
  4775. let Inst{15-14} = 0b11;
  4776. let Inst{12} = 0b0;
  4777. let Inst{0} = 0b1;
  4778. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
  4779. }
  4780. def t2BF_LabelPseudo
  4781. : t2PseudoInst<(outs ), (ins pclabel:$cp), 0, NoItinerary, []> {
  4782. let isTerminator = 1;
  4783. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
  4784. let hasNoSchedulingInfo = 1;
  4785. }
  4786. def t2BFi : t2BF<(ins bflabel_u4:$b_label, bflabel_s16:$label, pred:$p),
  4787. !strconcat("bf", "${p}"), "$b_label, $label"> {
  4788. bits<4> b_label;
  4789. bits<16> label;
  4790. let Inst{26-23} = b_label{3-0};
  4791. let Inst{22-21} = 0b10;
  4792. let Inst{20-16} = label{15-11};
  4793. let Inst{13} = 0b1;
  4794. let Inst{11} = label{0};
  4795. let Inst{10-1} = label{10-1};
  4796. }
  4797. def t2BFic : t2BF<(ins bflabel_u4:$b_label, bflabel_s12:$label,
  4798. bfafter_target:$ba_label, pred_noal:$bcond), "bfcsel",
  4799. "$b_label, $label, $ba_label, $bcond"> {
  4800. bits<4> bcond;
  4801. bits<12> label;
  4802. bits<1> ba_label;
  4803. bits<4> b_label;
  4804. let Inst{26-23} = b_label{3-0};
  4805. let Inst{22} = 0b0;
  4806. let Inst{21-18} = bcond{3-0};
  4807. let Inst{17} = ba_label{0};
  4808. let Inst{16} = label{11};
  4809. let Inst{13} = 0b1;
  4810. let Inst{11} = label{0};
  4811. let Inst{10-1} = label{10-1};
  4812. }
  4813. def t2BFr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
  4814. !strconcat("bfx", "${p}"), "$b_label, $Rn"> {
  4815. bits<4> b_label;
  4816. bits<4> Rn;
  4817. let Inst{26-23} = b_label{3-0};
  4818. let Inst{22-20} = 0b110;
  4819. let Inst{19-16} = Rn{3-0};
  4820. let Inst{13-1} = 0b1000000000000;
  4821. }
  4822. def t2BFLi : t2BF<(ins bflabel_u4:$b_label, bflabel_s18:$label, pred:$p),
  4823. !strconcat("bfl", "${p}"), "$b_label, $label"> {
  4824. bits<4> b_label;
  4825. bits<18> label;
  4826. let Inst{26-23} = b_label{3-0};
  4827. let Inst{22-16} = label{17-11};
  4828. let Inst{13} = 0b0;
  4829. let Inst{11} = label{0};
  4830. let Inst{10-1} = label{10-1};
  4831. }
  4832. def t2BFLr : t2BF<(ins bflabel_u4:$b_label, rGPR:$Rn, pred:$p),
  4833. !strconcat("bflx", "${p}"), "$b_label, $Rn"> {
  4834. bits<4> b_label;
  4835. bits<4> Rn;
  4836. let Inst{26-23} = b_label{3-0};
  4837. let Inst{22-20} = 0b111;
  4838. let Inst{19-16} = Rn{3-0};
  4839. let Inst{13-1} = 0b1000000000000;
  4840. }
  4841. class t2LOL<dag oops, dag iops, string asm, string ops>
  4842. : V8_1MI<oops, iops, AddrModeNone, NoItinerary, asm, ops, "", [] > {
  4843. let Inst{31-23} = 0b111100000;
  4844. let Inst{15-14} = 0b11;
  4845. let Inst{0} = 0b1;
  4846. let DecoderMethod = "DecodeLOLoop";
  4847. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB];
  4848. }
  4849. let isNotDuplicable = 1 in {
  4850. def t2WLS : t2LOL<(outs GPRlr:$LR),
  4851. (ins rGPR:$Rn, wlslabel_u11:$label),
  4852. "wls", "$LR, $Rn, $label"> {
  4853. bits<4> Rn;
  4854. bits<11> label;
  4855. let Inst{22-20} = 0b100;
  4856. let Inst{19-16} = Rn{3-0};
  4857. let Inst{13-12} = 0b00;
  4858. let Inst{11} = label{0};
  4859. let Inst{10-1} = label{10-1};
  4860. let usesCustomInserter = 1;
  4861. let isBranch = 1;
  4862. let isTerminator = 1;
  4863. }
  4864. def t2DLS : t2LOL<(outs GPRlr:$LR), (ins rGPR:$Rn),
  4865. "dls", "$LR, $Rn"> {
  4866. bits<4> Rn;
  4867. let Inst{22-20} = 0b100;
  4868. let Inst{19-16} = Rn{3-0};
  4869. let Inst{13-1} = 0b1000000000000;
  4870. let usesCustomInserter = 1;
  4871. }
  4872. def t2LEUpdate : t2LOL<(outs GPRlr:$LRout),
  4873. (ins GPRlr:$LRin, lelabel_u11:$label),
  4874. "le", "$LRin, $label"> {
  4875. bits<11> label;
  4876. let Inst{22-16} = 0b0001111;
  4877. let Inst{13-12} = 0b00;
  4878. let Inst{11} = label{0};
  4879. let Inst{10-1} = label{10-1};
  4880. let usesCustomInserter = 1;
  4881. let isBranch = 1;
  4882. let isTerminator = 1;
  4883. }
  4884. def t2LE : t2LOL<(outs ), (ins lelabel_u11:$label), "le", "$label"> {
  4885. bits<11> label;
  4886. let Inst{22-16} = 0b0101111;
  4887. let Inst{13-12} = 0b00;
  4888. let Inst{11} = label{0};
  4889. let Inst{10-1} = label{10-1};
  4890. let isBranch = 1;
  4891. let isTerminator = 1;
  4892. }
  4893. let Predicates = [IsThumb2, HasV8_1MMainline, HasLOB] in {
  4894. // t2DoLoopStart a pseudo for DLS hardware loops. Lowered into a DLS in
  4895. // ARMLowOverheadLoops if possible, or reverted to a Mov if not.
  4896. def t2DoLoopStart :
  4897. t2PseudoInst<(outs GPRlr:$X), (ins rGPR:$tc), 4, IIC_Br,
  4898. [(set GPRlr:$X, (int_start_loop_iterations rGPR:$tc))]>;
  4899. // A pseudo for a DLSTP, created in the MVETPAndVPTOptimizationPass from a
  4900. // t2DoLoopStart if the loops is tail predicated. Holds both the element
  4901. // count and trip count of the loop, picking the correct one during
  4902. // ARMLowOverheadLoops when it is converted to a DLSTP or DLS as required.
  4903. let isTerminator = 1, hasSideEffects = 1 in
  4904. def t2DoLoopStartTP :
  4905. t2PseudoInst<(outs GPRlr:$X), (ins rGPR:$tc, rGPR:$elts), 4, IIC_Br, []>;
  4906. // Setup for a t2WhileLoopStart. A pair of t2WhileLoopSetup and t2WhileLoopStart
  4907. // will be created post-ISel from a llvm.test.start.loop.iterations. This
  4908. // t2WhileLoopSetup to setup LR and t2WhileLoopStart to perform the branch. Not
  4909. // valid after reg alloc, as it should be lowered during MVETPAndVPTOptimisations
  4910. // into a t2WhileLoopStartLR (or expanded).
  4911. def t2WhileLoopSetup :
  4912. t2PseudoInst<(outs GPRlr:$lr), (ins rGPR:$tc), 4, IIC_Br, []>;
  4913. // A pseudo to represent the decrement in a low overhead loop. A t2LoopDec and
  4914. // t2LoopEnd together represent a LE instruction. Ideally these are converted
  4915. // to a t2LoopEndDec which is lowered as a single instruction.
  4916. let hasSideEffects = 0 in
  4917. def t2LoopDec :
  4918. t2PseudoInst<(outs GPRlr:$Rm), (ins GPRlr:$Rn, imm0_7:$size),
  4919. 4, IIC_Br, []>, Sched<[WriteBr]>;
  4920. let isBranch = 1, isTerminator = 1, hasSideEffects = 1, Defs = [CPSR] in {
  4921. // The branch in a t2WhileLoopSetup/t2WhileLoopStart pair, eventually turned
  4922. // into a t2WhileLoopStartLR that does both the LR setup and branch.
  4923. def t2WhileLoopStart :
  4924. t2PseudoInst<(outs),
  4925. (ins GPRlr:$tc, brtarget:$target),
  4926. 4, IIC_Br, []>,
  4927. Sched<[WriteBr]>;
  4928. // WhileLoopStartLR that sets up LR and branches on zero, equivalent to WLS. It
  4929. // is lowered in the ARMLowOverheadLoops pass providing the branches are within
  4930. // range. WhileLoopStartLR and LoopEnd to occupy 8 bytes because they may get
  4931. // converted into t2CMP and t2Bcc.
  4932. def t2WhileLoopStartLR :
  4933. t2PseudoInst<(outs GPRlr:$lr),
  4934. (ins rGPR:$tc, brtarget:$target),
  4935. 8, IIC_Br, []>,
  4936. Sched<[WriteBr]>;
  4937. // Similar to a t2DoLoopStartTP, a t2WhileLoopStartTP is a pseudo for a WLSTP
  4938. // holding both the element count and the tripcount of the loop.
  4939. def t2WhileLoopStartTP :
  4940. t2PseudoInst<(outs GPRlr:$lr),
  4941. (ins rGPR:$tc, rGPR:$elts, brtarget:$target),
  4942. 8, IIC_Br, []>,
  4943. Sched<[WriteBr]>;
  4944. // t2LoopEnd - the branch half of a t2LoopDec/t2LoopEnd pair.
  4945. def t2LoopEnd :
  4946. t2PseudoInst<(outs), (ins GPRlr:$tc, brtarget:$target),
  4947. 8, IIC_Br, []>, Sched<[WriteBr]>;
  4948. // The combination of a t2LoopDec and t2LoopEnd, performing both the LR
  4949. // decrement and branch as a single instruction. Is lowered to a LE or
  4950. // LETP in ARMLowOverheadLoops as appropriate, or converted to t2CMP/t2Bcc
  4951. // if the branches are out of range.
  4952. def t2LoopEndDec :
  4953. t2PseudoInst<(outs GPRlr:$Rm), (ins GPRlr:$tc, brtarget:$target),
  4954. 8, IIC_Br, []>, Sched<[WriteBr]>;
  4955. } // end isBranch, isTerminator, hasSideEffects
  4956. }
  4957. } // end isNotDuplicable
  4958. class CS<string iname, bits<4> opcode, list<dag> pattern=[]>
  4959. : V8_1MI<(outs rGPR:$Rd), (ins GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rm, pred_noal:$fcond),
  4960. AddrModeNone, NoItinerary, iname, "$Rd, $Rn, $Rm, $fcond", "", pattern> {
  4961. bits<4> Rd;
  4962. bits<4> Rm;
  4963. bits<4> Rn;
  4964. bits<4> fcond;
  4965. let Inst{31-20} = 0b111010100101;
  4966. let Inst{19-16} = Rn{3-0};
  4967. let Inst{15-12} = opcode;
  4968. let Inst{11-8} = Rd{3-0};
  4969. let Inst{7-4} = fcond{3-0};
  4970. let Inst{3-0} = Rm{3-0};
  4971. let Uses = [CPSR];
  4972. let hasSideEffects = 0;
  4973. }
  4974. def t2CSEL : CS<"csel", 0b1000>;
  4975. def t2CSINC : CS<"csinc", 0b1001>;
  4976. def t2CSINV : CS<"csinv", 0b1010>;
  4977. def t2CSNEG : CS<"csneg", 0b1011>;
  4978. def ARMcsinc_su : PatFrag<(ops node:$lhs, node:$rhs, node:$cond),
  4979. (ARMcsinc node:$lhs, node:$rhs, node:$cond), [{
  4980. return N->hasOneUse();
  4981. }]>;
  4982. let Predicates = [HasV8_1MMainline] in {
  4983. multiclass CSPats<SDNode Node, Instruction Insn> {
  4984. def : T2Pat<(Node GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm),
  4985. (Insn GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
  4986. def : T2Pat<(Node (i32 0), GPRwithZR:$fval, imm0_31:$imm),
  4987. (Insn ZR, GPRwithZR:$fval, imm0_31:$imm)>;
  4988. def : T2Pat<(Node GPRwithZR:$tval, (i32 0), imm0_31:$imm),
  4989. (Insn GPRwithZR:$tval, ZR, imm0_31:$imm)>;
  4990. def : T2Pat<(Node (i32 0), (i32 0), imm0_31:$imm),
  4991. (Insn ZR, ZR, imm0_31:$imm)>;
  4992. }
  4993. defm : CSPats<ARMcsinc, t2CSINC>;
  4994. defm : CSPats<ARMcsinv, t2CSINV>;
  4995. defm : CSPats<ARMcsneg, t2CSNEG>;
  4996. def : T2Pat<(ARMcmov (i32 1), (i32 0), cmovpred:$imm),
  4997. (t2CSINC ZR, ZR, imm0_31:$imm)>;
  4998. def : T2Pat<(ARMcmov (i32 -1), (i32 0), cmovpred:$imm),
  4999. (t2CSINV ZR, ZR, imm0_31:$imm)>;
  5000. def : T2Pat<(ARMcmov (i32 0), (i32 1), cmovpred:$imm),
  5001. (t2CSINC ZR, ZR, (inv_cond_XFORM imm:$imm))>;
  5002. def : T2Pat<(ARMcmov (i32 0), (i32 -1), cmovpred:$imm),
  5003. (t2CSINV ZR, ZR, (inv_cond_XFORM imm:$imm))>;
  5004. multiclass ModifiedV8_1CSEL<Instruction Insn, dag modvalue> {
  5005. def : T2Pat<(ARMcmov modvalue, GPRwithZR:$tval, cmovpred:$imm),
  5006. (Insn GPRwithZR:$tval, GPRwithZR:$fval, imm0_31:$imm)>;
  5007. def : T2Pat<(ARMcmov GPRwithZR:$tval, modvalue, cmovpred:$imm),
  5008. (Insn GPRwithZR:$tval, GPRwithZR:$fval,
  5009. (i32 (inv_cond_XFORM imm:$imm)))>;
  5010. }
  5011. defm : ModifiedV8_1CSEL<t2CSINC, (add rGPR:$fval, 1)>;
  5012. defm : ModifiedV8_1CSEL<t2CSINV, (xor rGPR:$fval, -1)>;
  5013. defm : ModifiedV8_1CSEL<t2CSNEG, (sub 0, rGPR:$fval)>;
  5014. def : T2Pat<(ARMcmov (topbitsallzero32:$Rn), (i32 1), cmovpred:$imm),
  5015. (t2CSINC $Rn, ZR, (inv_cond_XFORM imm:$imm))>;
  5016. def : T2Pat<(and (topbitsallzero32:$Rn), (ARMcsinc_su (i32 0), (i32 0), cmovpred:$imm)),
  5017. (t2CSEL ZR, $Rn, $imm)>;
  5018. }
  5019. // CS aliases.
  5020. let Predicates = [HasV8_1MMainline] in {
  5021. def : InstAlias<"csetm\t$Rd, $fcond",
  5022. (t2CSINV rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
  5023. def : InstAlias<"cset\t$Rd, $fcond",
  5024. (t2CSINC rGPR:$Rd, ZR, ZR, pred_noal_inv:$fcond)>;
  5025. def : InstAlias<"cinc\t$Rd, $Rn, $fcond",
  5026. (t2CSINC rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
  5027. def : InstAlias<"cinv\t$Rd, $Rn, $fcond",
  5028. (t2CSINV rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
  5029. def : InstAlias<"cneg\t$Rd, $Rn, $fcond",
  5030. (t2CSNEG rGPR:$Rd, GPRwithZRnosp:$Rn, GPRwithZRnosp:$Rn, pred_noal_inv:$fcond)>;
  5031. }
  5032. // PACBTI
  5033. let Predicates = [IsThumb2, HasV8_1MMainline, HasPACBTI] in {
  5034. def t2PACG : V8_1MI<(outs rGPR:$Rd),
  5035. (ins pred:$p, GPRnopc:$Rn, GPRnopc:$Rm),
  5036. AddrModeNone, NoItinerary, "pacg${p}", "$Rd, $Rn, $Rm", "", []> {
  5037. bits<4> Rd;
  5038. bits<4> Rn;
  5039. bits<4> Rm;
  5040. let Inst{31-20} = 0b111110110110;
  5041. let Inst{19-16} = Rn;
  5042. let Inst{15-12} = 0b1111;
  5043. let Inst{11-8} = Rd;
  5044. let Inst{7-4} = 0b0000;
  5045. let Inst{3-0} = Rm;
  5046. }
  5047. let hasSideEffects = 1 in {
  5048. class PACBTIAut<dag iops, string asm, bit b>
  5049. : V8_1MI<(outs), iops,
  5050. AddrModeNone, NoItinerary, asm, "$Ra, $Rn, $Rm", "", []> {
  5051. bits<4> Ra;
  5052. bits<4> Rn;
  5053. bits<4> Rm;
  5054. let Inst{31-20} = 0b111110110101;
  5055. let Inst{19-16} = Rn;
  5056. let Inst{15-12} = Ra;
  5057. let Inst{11-5} = 0b1111000;
  5058. let Inst{4} = b;
  5059. let Inst{3-0} = Rm;
  5060. }
  5061. }
  5062. def t2AUTG : PACBTIAut<(ins pred:$p, GPRnosp:$Ra, GPRnopc:$Rn, GPRnopc:$Rm),
  5063. "autg${p}", 0>;
  5064. let isBranch = 1, isTerminator = 1, isIndirectBranch = 1 in {
  5065. def t2BXAUT : PACBTIAut<(ins pred:$p, GPRnosp:$Ra, rGPR:$Rn, GPRnopc:$Rm),
  5066. "bxaut${p}", 1>;
  5067. }
  5068. }
  5069. class PACBTIHintSpaceInst<string asm, string ops, bits<8> imm>
  5070. : Thumb2XI<(outs), (ins), AddrModeNone, 4, NoItinerary, !strconcat(asm, "\t", ops), "", []>,
  5071. Requires<[HasV7, IsMClass]> {
  5072. let Inst{31-8} = 0b111100111010111110000000;
  5073. let Inst{7-0} = imm;
  5074. let Unpredictable{19-16} = 0b1111;
  5075. let Unpredictable{13-11} = 0b101;
  5076. let DecoderMethod = "DecodeT2HintSpaceInstruction";
  5077. }
  5078. class PACBTIHintSpaceNoOpsInst<string asm, bits<8> imm>
  5079. : PACBTIHintSpaceInst<asm, "", imm>;
  5080. class PACBTIHintSpaceDefInst<string asm, bits<8> imm>
  5081. : PACBTIHintSpaceInst<asm, "r12, lr, sp", imm> {
  5082. let Defs = [R12];
  5083. let Uses = [LR, SP];
  5084. }
  5085. class PACBTIHintSpaceUseInst<string asm, bits<8> imm>
  5086. : PACBTIHintSpaceInst<asm, "r12, lr, sp", imm> {
  5087. let Uses = [R12, LR, SP];
  5088. }
  5089. def t2PAC : PACBTIHintSpaceDefInst<"pac", 0b00011101>;
  5090. def t2PACBTI : PACBTIHintSpaceDefInst<"pacbti", 0b00001101>;
  5091. def t2BTI : PACBTIHintSpaceNoOpsInst<"bti", 0b00001111>;
  5092. def t2AUT : PACBTIHintSpaceUseInst<"aut", 0b00101101> {
  5093. let hasSideEffects = 1;
  5094. }
  5095. def ARMt2CallBTI : SDNode<"ARMISD::t2CALL_BTI", SDT_ARMcall,
  5096. [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue, SDNPVariadic]>;
  5097. def t2CALL_BTI : PseudoInst<(outs), (ins pred:$p, thumb_bl_target:$func),
  5098. IIC_Br, [(ARMt2CallBTI tglobaladdr:$func)]>,
  5099. Requires<[IsThumb2]>, Sched<[WriteBrL]>;