ARMInstrFormats.td 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778
  1. //===-- ARMInstrFormats.td - ARM Instruction Formats -------*- 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. //
  10. // ARM Instruction Format Definitions.
  11. //
  12. // Format specifies the encoding used by the instruction. This is part of the
  13. // ad-hoc solution used to emit machine instruction encodings by our machine
  14. // code emitter.
  15. class Format<bits<6> val> {
  16. bits<6> Value = val;
  17. }
  18. def Pseudo : Format<0>;
  19. def MulFrm : Format<1>;
  20. def BrFrm : Format<2>;
  21. def BrMiscFrm : Format<3>;
  22. def DPFrm : Format<4>;
  23. def DPSoRegRegFrm : Format<5>;
  24. def LdFrm : Format<6>;
  25. def StFrm : Format<7>;
  26. def LdMiscFrm : Format<8>;
  27. def StMiscFrm : Format<9>;
  28. def LdStMulFrm : Format<10>;
  29. def LdStExFrm : Format<11>;
  30. def ArithMiscFrm : Format<12>;
  31. def SatFrm : Format<13>;
  32. def ExtFrm : Format<14>;
  33. def VFPUnaryFrm : Format<15>;
  34. def VFPBinaryFrm : Format<16>;
  35. def VFPConv1Frm : Format<17>;
  36. def VFPConv2Frm : Format<18>;
  37. def VFPConv3Frm : Format<19>;
  38. def VFPConv4Frm : Format<20>;
  39. def VFPConv5Frm : Format<21>;
  40. def VFPLdStFrm : Format<22>;
  41. def VFPLdStMulFrm : Format<23>;
  42. def VFPMiscFrm : Format<24>;
  43. def ThumbFrm : Format<25>;
  44. def MiscFrm : Format<26>;
  45. def NGetLnFrm : Format<27>;
  46. def NSetLnFrm : Format<28>;
  47. def NDupFrm : Format<29>;
  48. def NLdStFrm : Format<30>;
  49. def N1RegModImmFrm: Format<31>;
  50. def N2RegFrm : Format<32>;
  51. def NVCVTFrm : Format<33>;
  52. def NVDupLnFrm : Format<34>;
  53. def N2RegVShLFrm : Format<35>;
  54. def N2RegVShRFrm : Format<36>;
  55. def N3RegFrm : Format<37>;
  56. def N3RegVShFrm : Format<38>;
  57. def NVExtFrm : Format<39>;
  58. def NVMulSLFrm : Format<40>;
  59. def NVTBLFrm : Format<41>;
  60. def DPSoRegImmFrm : Format<42>;
  61. def N3RegCplxFrm : Format<43>;
  62. // Misc flags.
  63. // The instruction has an Rn register operand.
  64. // UnaryDP - Indicates this is a unary data processing instruction, i.e.
  65. // it doesn't have a Rn operand.
  66. class UnaryDP { bit isUnaryDataProc = 1; }
  67. // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
  68. // a 16-bit Thumb instruction if certain conditions are met.
  69. class Xform16Bit { bit canXformTo16Bit = 1; }
  70. //===----------------------------------------------------------------------===//
  71. // ARM Instruction flags. These need to match ARMBaseInstrInfo.h.
  72. //
  73. // FIXME: Once the JIT is MC-ized, these can go away.
  74. // Addressing mode.
  75. class AddrMode<bits<5> val> {
  76. bits<5> Value = val;
  77. }
  78. def AddrModeNone : AddrMode<0>;
  79. def AddrMode1 : AddrMode<1>;
  80. def AddrMode2 : AddrMode<2>;
  81. def AddrMode3 : AddrMode<3>;
  82. def AddrMode4 : AddrMode<4>;
  83. def AddrMode5 : AddrMode<5>;
  84. def AddrMode6 : AddrMode<6>;
  85. def AddrModeT1_1 : AddrMode<7>;
  86. def AddrModeT1_2 : AddrMode<8>;
  87. def AddrModeT1_4 : AddrMode<9>;
  88. def AddrModeT1_s : AddrMode<10>;
  89. def AddrModeT2_i12 : AddrMode<11>;
  90. def AddrModeT2_i8 : AddrMode<12>;
  91. def AddrModeT2_so : AddrMode<13>;
  92. def AddrModeT2_pc : AddrMode<14>;
  93. def AddrModeT2_i8s4 : AddrMode<15>;
  94. def AddrMode_i12 : AddrMode<16>;
  95. def AddrMode5FP16 : AddrMode<17>;
  96. def AddrModeT2_ldrex : AddrMode<18>;
  97. def AddrModeT2_i7s4 : AddrMode<19>;
  98. def AddrModeT2_i7s2 : AddrMode<20>;
  99. def AddrModeT2_i7 : AddrMode<21>;
  100. // Load / store index mode.
  101. class IndexMode<bits<2> val> {
  102. bits<2> Value = val;
  103. }
  104. def IndexModeNone : IndexMode<0>;
  105. def IndexModePre : IndexMode<1>;
  106. def IndexModePost : IndexMode<2>;
  107. def IndexModeUpd : IndexMode<3>;
  108. // Instruction execution domain.
  109. class Domain<bits<4> val> {
  110. bits<4> Value = val;
  111. }
  112. def GenericDomain : Domain<0>;
  113. def VFPDomain : Domain<1>; // Instructions in VFP domain only
  114. def NeonDomain : Domain<2>; // Instructions in Neon domain only
  115. def VFPNeonDomain : Domain<3>; // Instructions in both VFP & Neon domains
  116. def VFPNeonA8Domain : Domain<5>; // Instructions in VFP & Neon under A8
  117. def MVEDomain : Domain<8>; // Instructions in MVE and ARMv8.1m
  118. //===----------------------------------------------------------------------===//
  119. // ARM special operands.
  120. //
  121. // ARM imod and iflag operands, used only by the CPS instruction.
  122. def imod_op : Operand<i32> {
  123. let PrintMethod = "printCPSIMod";
  124. }
  125. def ProcIFlagsOperand : AsmOperandClass {
  126. let Name = "ProcIFlags";
  127. let ParserMethod = "parseProcIFlagsOperand";
  128. }
  129. def iflags_op : Operand<i32> {
  130. let PrintMethod = "printCPSIFlag";
  131. let ParserMatchClass = ProcIFlagsOperand;
  132. }
  133. // ARM Predicate operand. Default to 14 = always (AL). Second part is CC
  134. // register whose default is 0 (no register).
  135. def CondCodeOperand : AsmOperandClass { let Name = "CondCode"; }
  136. def pred : PredicateOperand<OtherVT, (ops i32imm, i32imm),
  137. (ops (i32 14), (i32 zero_reg))> {
  138. let PrintMethod = "printPredicateOperand";
  139. let ParserMatchClass = CondCodeOperand;
  140. let DecoderMethod = "DecodePredicateOperand";
  141. }
  142. // Selectable predicate operand for CMOV instructions. We can't use a normal
  143. // predicate because the default values interfere with instruction selection. In
  144. // all other respects it is identical though: pseudo-instruction expansion
  145. // relies on the MachineOperands being compatible.
  146. def cmovpred : Operand<i32>, PredicateOp,
  147. ComplexPattern<i32, 2, "SelectCMOVPred"> {
  148. let MIOperandInfo = (ops i32imm, i32imm);
  149. let PrintMethod = "printPredicateOperand";
  150. }
  151. // Conditional code result for instructions whose 's' bit is set, e.g. subs.
  152. def CCOutOperand : AsmOperandClass { let Name = "CCOut"; }
  153. def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
  154. let EncoderMethod = "getCCOutOpValue";
  155. let PrintMethod = "printSBitModifierOperand";
  156. let ParserMatchClass = CCOutOperand;
  157. let DecoderMethod = "DecodeCCOutOperand";
  158. }
  159. // Same as cc_out except it defaults to setting CPSR.
  160. def s_cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 CPSR))> {
  161. let EncoderMethod = "getCCOutOpValue";
  162. let PrintMethod = "printSBitModifierOperand";
  163. let ParserMatchClass = CCOutOperand;
  164. let DecoderMethod = "DecodeCCOutOperand";
  165. }
  166. // Transform to generate the inverse of a condition code during ISel
  167. def inv_cond_XFORM : SDNodeXForm<imm, [{
  168. ARMCC::CondCodes CC = static_cast<ARMCC::CondCodes>(N->getZExtValue());
  169. return CurDAG->getTargetConstant(ARMCC::getOppositeCondition(CC), SDLoc(N),
  170. MVT::i32);
  171. }]>;
  172. // VPT predicate
  173. def VPTPredNOperand : AsmOperandClass {
  174. let Name = "VPTPredN";
  175. let PredicateMethod = "isVPTPred";
  176. }
  177. def VPTPredROperand : AsmOperandClass {
  178. let Name = "VPTPredR";
  179. let PredicateMethod = "isVPTPred";
  180. }
  181. // Operand classes for the cluster of MC operands describing a
  182. // VPT-predicated MVE instruction.
  183. //
  184. // There are two of these classes. Both of them have the same first
  185. // two options:
  186. //
  187. // $cond (an integer) indicates the instruction's predication status:
  188. // * ARMVCC::None means it's unpredicated
  189. // * ARMVCC::Then means it's in a VPT block and appears with the T suffix
  190. // * ARMVCC::Else means it's in a VPT block and appears with the E suffix.
  191. // During code generation, unpredicated and predicated instructions
  192. // are indicated by setting this parameter to 'None' or to 'Then'; the
  193. // third value 'Else' is only used for assembly and disassembly.
  194. //
  195. // $cond_reg (type VCCR) gives the input predicate register. This is
  196. // always either zero_reg or VPR, but needs to be modelled as an
  197. // explicit operand so that it can be register-allocated and spilled
  198. // when these operands are used in code generation).
  199. //
  200. // For 'vpred_r', there's an extra operand $inactive, which specifies
  201. // the vector register which will supply any lanes of the output
  202. // register that the predication mask prevents from being written by
  203. // this instruction. It's always tied to the actual output register
  204. // (i.e. must be allocated into the same physical reg), but again,
  205. // code generation will need to model it as a separate input value.
  206. //
  207. // 'vpred_n' doesn't have that extra operand: it only has $cond and
  208. // $cond_reg. This variant is used for any instruction that can't, or
  209. // doesn't want to, tie $inactive to the output register. Sometimes
  210. // that's because another input parameter is already tied to it (e.g.
  211. // instructions that both read and write their Qd register even when
  212. // unpredicated, either because they only partially overwrite it like
  213. // a narrowing integer conversion, or simply because the instruction
  214. // encoding doesn't have enough register fields to make the output
  215. // independent of all inputs). It can also be because the instruction
  216. // is defined to set disabled output lanes to zero rather than leaving
  217. // them unchanged (vector loads), or because it doesn't output a
  218. // vector register at all (stores, compares). In any of these
  219. // situations it's unnecessary to have an extra operand tied to the
  220. // output, and inconvenient to leave it there unused.
  221. // Base class for both kinds of vpred.
  222. class vpred_ops<dag extra_op, dag extra_mi> : OperandWithDefaultOps<OtherVT,
  223. !con((ops (i32 0), (i32 zero_reg)), extra_op)> {
  224. let PrintMethod = "printVPTPredicateOperand";
  225. let OperandNamespace = "ARM";
  226. let MIOperandInfo = !con((ops i32imm:$cond, VCCR:$cond_reg), extra_mi);
  227. // For convenience, we provide a string value that can be appended
  228. // to the constraints string. It's empty for vpred_n, and for
  229. // vpred_r it ties the $inactive operand to the output q-register
  230. // (which by convention will be called $Qd).
  231. string vpred_constraint;
  232. }
  233. def vpred_r : vpred_ops<(ops (v4i32 undef_tied_input)), (ops MQPR:$inactive)> {
  234. let ParserMatchClass = VPTPredROperand;
  235. let OperandType = "OPERAND_VPRED_R";
  236. let DecoderMethod = "DecodeVpredROperand";
  237. let vpred_constraint = ",$Qd = $vp.inactive";
  238. }
  239. def vpred_n : vpred_ops<(ops), (ops)> {
  240. let ParserMatchClass = VPTPredNOperand;
  241. let OperandType = "OPERAND_VPRED_N";
  242. let vpred_constraint = "";
  243. }
  244. // ARM special operands for disassembly only.
  245. //
  246. def SetEndAsmOperand : ImmAsmOperand<0,1> {
  247. let Name = "SetEndImm";
  248. let ParserMethod = "parseSetEndImm";
  249. }
  250. def setend_op : Operand<i32> {
  251. let PrintMethod = "printSetendOperand";
  252. let ParserMatchClass = SetEndAsmOperand;
  253. }
  254. def MSRMaskOperand : AsmOperandClass {
  255. let Name = "MSRMask";
  256. let ParserMethod = "parseMSRMaskOperand";
  257. }
  258. def msr_mask : Operand<i32> {
  259. let PrintMethod = "printMSRMaskOperand";
  260. let DecoderMethod = "DecodeMSRMask";
  261. let ParserMatchClass = MSRMaskOperand;
  262. }
  263. def BankedRegOperand : AsmOperandClass {
  264. let Name = "BankedReg";
  265. let ParserMethod = "parseBankedRegOperand";
  266. }
  267. def banked_reg : Operand<i32> {
  268. let PrintMethod = "printBankedRegOperand";
  269. let DecoderMethod = "DecodeBankedReg";
  270. let ParserMatchClass = BankedRegOperand;
  271. }
  272. // Shift Right Immediate - A shift right immediate is encoded differently from
  273. // other shift immediates. The imm6 field is encoded like so:
  274. //
  275. // Offset Encoding
  276. // 8 imm6<5:3> = '001', 8 - <imm> is encoded in imm6<2:0>
  277. // 16 imm6<5:4> = '01', 16 - <imm> is encoded in imm6<3:0>
  278. // 32 imm6<5> = '1', 32 - <imm> is encoded in imm6<4:0>
  279. // 64 64 - <imm> is encoded in imm6<5:0>
  280. def shr_imm8_asm_operand : ImmAsmOperand<1,8> { let Name = "ShrImm8"; }
  281. def shr_imm8 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 8; }]> {
  282. let EncoderMethod = "getShiftRight8Imm";
  283. let DecoderMethod = "DecodeShiftRight8Imm";
  284. let ParserMatchClass = shr_imm8_asm_operand;
  285. }
  286. def shr_imm16_asm_operand : ImmAsmOperand<1,16> { let Name = "ShrImm16"; }
  287. def shr_imm16 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 16; }]> {
  288. let EncoderMethod = "getShiftRight16Imm";
  289. let DecoderMethod = "DecodeShiftRight16Imm";
  290. let ParserMatchClass = shr_imm16_asm_operand;
  291. }
  292. def shr_imm32_asm_operand : ImmAsmOperand<1,32> { let Name = "ShrImm32"; }
  293. def shr_imm32 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]> {
  294. let EncoderMethod = "getShiftRight32Imm";
  295. let DecoderMethod = "DecodeShiftRight32Imm";
  296. let ParserMatchClass = shr_imm32_asm_operand;
  297. }
  298. def shr_imm64_asm_operand : ImmAsmOperand<1,64> { let Name = "ShrImm64"; }
  299. def shr_imm64 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 64; }]> {
  300. let EncoderMethod = "getShiftRight64Imm";
  301. let DecoderMethod = "DecodeShiftRight64Imm";
  302. let ParserMatchClass = shr_imm64_asm_operand;
  303. }
  304. // ARM Assembler operand for ldr Rd, =expression which generates an offset
  305. // to a constant pool entry or a MOV depending on the value of expression
  306. def const_pool_asm_operand : AsmOperandClass { let Name = "ConstPoolAsmImm"; }
  307. def const_pool_asm_imm : Operand<i32> {
  308. let ParserMatchClass = const_pool_asm_operand;
  309. }
  310. //===----------------------------------------------------------------------===//
  311. // ARM Assembler alias templates.
  312. //
  313. // Note: When EmitPriority == 1, the alias will be used for printing
  314. class ARMInstAlias<string Asm, dag Result, bit EmitPriority = 0>
  315. : InstAlias<Asm, Result, EmitPriority>, Requires<[IsARM]>;
  316. class ARMInstSubst<string Asm, dag Result, bit EmitPriority = 0>
  317. : InstAlias<Asm, Result, EmitPriority>,
  318. Requires<[IsARM,UseNegativeImmediates]>;
  319. class tInstAlias<string Asm, dag Result, bit EmitPriority = 0>
  320. : InstAlias<Asm, Result, EmitPriority>, Requires<[IsThumb]>;
  321. class tInstSubst<string Asm, dag Result, bit EmitPriority = 0>
  322. : InstAlias<Asm, Result, EmitPriority>,
  323. Requires<[IsThumb,UseNegativeImmediates]>;
  324. class t2InstAlias<string Asm, dag Result, bit EmitPriority = 0>
  325. : InstAlias<Asm, Result, EmitPriority>, Requires<[IsThumb2]>;
  326. class t2InstSubst<string Asm, dag Result, bit EmitPriority = 0>
  327. : InstAlias<Asm, Result, EmitPriority>,
  328. Requires<[IsThumb2,UseNegativeImmediates]>;
  329. class VFP2InstAlias<string Asm, dag Result, bit EmitPriority = 0>
  330. : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP2]>;
  331. class VFP2DPInstAlias<string Asm, dag Result, bit EmitPriority = 0>
  332. : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP2,HasDPVFP]>;
  333. class VFP3InstAlias<string Asm, dag Result, bit EmitPriority = 0>
  334. : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP3]>;
  335. class NEONInstAlias<string Asm, dag Result, bit EmitPriority = 0>
  336. : InstAlias<Asm, Result, EmitPriority>, Requires<[HasNEON]>;
  337. class MVEInstAlias<string Asm, dag Result, bit EmitPriority = 1>
  338. : InstAlias<Asm, Result, EmitPriority>, Requires<[HasMVEInt, IsThumb]>;
  339. class VFP2MnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
  340. Requires<[HasVFP2]>;
  341. class NEONMnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
  342. Requires<[HasNEON]>;
  343. //===----------------------------------------------------------------------===//
  344. // ARM Instruction templates.
  345. //
  346. class InstTemplate<AddrMode am, int sz, IndexMode im,
  347. Format f, Domain d, string cstr, InstrItinClass itin>
  348. : Instruction {
  349. let Namespace = "ARM";
  350. AddrMode AM = am;
  351. int Size = sz;
  352. IndexMode IM = im;
  353. bits<2> IndexModeBits = IM.Value;
  354. Format F = f;
  355. bits<6> Form = F.Value;
  356. Domain D = d;
  357. bit isUnaryDataProc = 0;
  358. bit canXformTo16Bit = 0;
  359. // The instruction is a 16-bit flag setting Thumb instruction. Used
  360. // by the parser and if-converter to determine whether to require the 'S'
  361. // suffix on the mnemonic (when not in an IT block) or preclude it (when
  362. // in an IT block).
  363. bit thumbArithFlagSetting = 0;
  364. bit validForTailPredication = 0;
  365. bit retainsPreviousHalfElement = 0;
  366. bit horizontalReduction = 0;
  367. bit doubleWidthResult = 0;
  368. // If this is a pseudo instruction, mark it isCodeGenOnly.
  369. let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
  370. // The layout of TSFlags should be kept in sync with ARMBaseInfo.h.
  371. let TSFlags{4-0} = AM.Value;
  372. let TSFlags{6-5} = IndexModeBits;
  373. let TSFlags{12-7} = Form;
  374. let TSFlags{13} = isUnaryDataProc;
  375. let TSFlags{14} = canXformTo16Bit;
  376. let TSFlags{18-15} = D.Value;
  377. let TSFlags{19} = thumbArithFlagSetting;
  378. let TSFlags{20} = validForTailPredication;
  379. let TSFlags{21} = retainsPreviousHalfElement;
  380. let TSFlags{22} = horizontalReduction;
  381. let TSFlags{23} = doubleWidthResult;
  382. let Constraints = cstr;
  383. let Itinerary = itin;
  384. }
  385. class Encoding {
  386. field bits<32> Inst;
  387. // Mask of bits that cause an encoding to be UNPREDICTABLE.
  388. // If a bit is set, then if the corresponding bit in the
  389. // target encoding differs from its value in the "Inst" field,
  390. // the instruction is UNPREDICTABLE (SoftFail in abstract parlance).
  391. field bits<32> Unpredictable = 0;
  392. // SoftFail is the generic name for this field, but we alias it so
  393. // as to make it more obvious what it means in ARM-land.
  394. field bits<32> SoftFail = Unpredictable;
  395. }
  396. class InstARM<AddrMode am, int sz, IndexMode im,
  397. Format f, Domain d, string cstr, InstrItinClass itin>
  398. : InstTemplate<am, sz, im, f, d, cstr, itin>, Encoding {
  399. let DecoderNamespace = "ARM";
  400. }
  401. // This Encoding-less class is used by Thumb1 to specify the encoding bits later
  402. // on by adding flavors to specific instructions.
  403. class InstThumb<AddrMode am, int sz, IndexMode im,
  404. Format f, Domain d, string cstr, InstrItinClass itin>
  405. : InstTemplate<am, sz, im, f, d, cstr, itin> {
  406. let DecoderNamespace = "Thumb";
  407. }
  408. // Pseudo-instructions for alternate assembly syntax (never used by codegen).
  409. // These are aliases that require C++ handling to convert to the target
  410. // instruction, while InstAliases can be handled directly by tblgen.
  411. class AsmPseudoInst<string asm, dag iops, dag oops = (outs)>
  412. : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
  413. "", NoItinerary> {
  414. let OutOperandList = oops;
  415. let InOperandList = iops;
  416. let Pattern = [];
  417. let isCodeGenOnly = 0; // So we get asm matcher for it.
  418. let AsmString = asm;
  419. let isPseudo = 1;
  420. let hasNoSchedulingInfo = 1;
  421. }
  422. class ARMAsmPseudo<string asm, dag iops, dag oops = (outs)>
  423. : AsmPseudoInst<asm, iops, oops>, Requires<[IsARM]>;
  424. class tAsmPseudo<string asm, dag iops, dag oops = (outs)>
  425. : AsmPseudoInst<asm, iops, oops>, Requires<[IsThumb]>;
  426. class t2AsmPseudo<string asm, dag iops, dag oops = (outs)>
  427. : AsmPseudoInst<asm, iops, oops>, Requires<[IsThumb2]>;
  428. class VFP2AsmPseudo<string asm, dag iops, dag oops = (outs)>
  429. : AsmPseudoInst<asm, iops, oops>, Requires<[HasVFP2]>;
  430. class NEONAsmPseudo<string asm, dag iops, dag oops = (outs)>
  431. : AsmPseudoInst<asm, iops, oops>, Requires<[HasNEON]>;
  432. class MVEAsmPseudo<string asm, dag iops, dag oops = (outs)>
  433. : AsmPseudoInst<asm, iops, oops>, Requires<[HasMVEInt]>;
  434. // Pseudo instructions for the code generator.
  435. class PseudoInst<dag oops, dag iops, InstrItinClass itin, list<dag> pattern>
  436. : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo,
  437. GenericDomain, "", itin> {
  438. let OutOperandList = oops;
  439. let InOperandList = iops;
  440. let Pattern = pattern;
  441. let isCodeGenOnly = 1;
  442. let isPseudo = 1;
  443. }
  444. // PseudoInst that's ARM-mode only.
  445. class ARMPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
  446. list<dag> pattern>
  447. : PseudoInst<oops, iops, itin, pattern> {
  448. let Size = sz;
  449. list<Predicate> Predicates = [IsARM];
  450. }
  451. // PseudoInst that's Thumb-mode only.
  452. class tPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
  453. list<dag> pattern>
  454. : PseudoInst<oops, iops, itin, pattern> {
  455. let Size = sz;
  456. list<Predicate> Predicates = [IsThumb];
  457. }
  458. // PseudoInst that's in ARMv8-M baseline (Somewhere between Thumb and Thumb2)
  459. class t2basePseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
  460. list<dag> pattern>
  461. : PseudoInst<oops, iops, itin, pattern> {
  462. let Size = sz;
  463. list<Predicate> Predicates = [IsThumb,HasV8MBaseline];
  464. }
  465. // PseudoInst that's Thumb2-mode only.
  466. class t2PseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
  467. list<dag> pattern>
  468. : PseudoInst<oops, iops, itin, pattern> {
  469. let Size = sz;
  470. list<Predicate> Predicates = [IsThumb2];
  471. }
  472. class ARMPseudoExpand<dag oops, dag iops, int sz,
  473. InstrItinClass itin, list<dag> pattern,
  474. dag Result>
  475. : ARMPseudoInst<oops, iops, sz, itin, pattern>,
  476. PseudoInstExpansion<Result>;
  477. class tPseudoExpand<dag oops, dag iops, int sz,
  478. InstrItinClass itin, list<dag> pattern,
  479. dag Result>
  480. : tPseudoInst<oops, iops, sz, itin, pattern>,
  481. PseudoInstExpansion<Result>;
  482. class t2PseudoExpand<dag oops, dag iops, int sz,
  483. InstrItinClass itin, list<dag> pattern,
  484. dag Result>
  485. : t2PseudoInst<oops, iops, sz, itin, pattern>,
  486. PseudoInstExpansion<Result>;
  487. // Almost all ARM instructions are predicable.
  488. class I<dag oops, dag iops, AddrMode am, int sz,
  489. IndexMode im, Format f, InstrItinClass itin,
  490. string opc, string asm, string cstr,
  491. list<dag> pattern>
  492. : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
  493. bits<4> p;
  494. let Inst{31-28} = p;
  495. let OutOperandList = oops;
  496. let InOperandList = !con(iops, (ins pred:$p));
  497. let AsmString = !strconcat(opc, "${p}", asm);
  498. let Pattern = pattern;
  499. list<Predicate> Predicates = [IsARM];
  500. }
  501. // A few are not predicable
  502. class InoP<dag oops, dag iops, AddrMode am, int sz,
  503. IndexMode im, Format f, InstrItinClass itin,
  504. string opc, string asm, string cstr,
  505. list<dag> pattern>
  506. : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
  507. let OutOperandList = oops;
  508. let InOperandList = iops;
  509. let AsmString = !strconcat(opc, asm);
  510. let Pattern = pattern;
  511. let isPredicable = 0;
  512. list<Predicate> Predicates = [IsARM];
  513. }
  514. // Same as I except it can optionally modify CPSR. Note it's modeled as an input
  515. // operand since by default it's a zero register. It will become an implicit def
  516. // once it's "flipped".
  517. class sI<dag oops, dag iops, AddrMode am, int sz,
  518. IndexMode im, Format f, InstrItinClass itin,
  519. string opc, string asm, string cstr,
  520. list<dag> pattern>
  521. : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
  522. bits<4> p; // Predicate operand
  523. bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
  524. let Inst{31-28} = p;
  525. let Inst{20} = s;
  526. let OutOperandList = oops;
  527. let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
  528. let AsmString = !strconcat(opc, "${s}${p}", asm);
  529. let Pattern = pattern;
  530. list<Predicate> Predicates = [IsARM];
  531. }
  532. // Special cases
  533. class XI<dag oops, dag iops, AddrMode am, int sz,
  534. IndexMode im, Format f, InstrItinClass itin,
  535. string asm, string cstr, list<dag> pattern>
  536. : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
  537. let OutOperandList = oops;
  538. let InOperandList = iops;
  539. let AsmString = asm;
  540. let Pattern = pattern;
  541. list<Predicate> Predicates = [IsARM];
  542. }
  543. class AI<dag oops, dag iops, Format f, InstrItinClass itin,
  544. string opc, string asm, list<dag> pattern>
  545. : I<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
  546. opc, asm, "", pattern>;
  547. class AsI<dag oops, dag iops, Format f, InstrItinClass itin,
  548. string opc, string asm, list<dag> pattern>
  549. : sI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
  550. opc, asm, "", pattern>;
  551. class AXI<dag oops, dag iops, Format f, InstrItinClass itin,
  552. string asm, list<dag> pattern>
  553. : XI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
  554. asm, "", pattern>;
  555. class AXIM<dag oops, dag iops, AddrMode am, Format f, InstrItinClass itin,
  556. string asm, list<dag> pattern>
  557. : XI<oops, iops, am, 4, IndexModeNone, f, itin,
  558. asm, "", pattern>;
  559. class AInoP<dag oops, dag iops, Format f, InstrItinClass itin,
  560. string opc, string asm, list<dag> pattern>
  561. : InoP<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
  562. opc, asm, "", pattern>;
  563. // Ctrl flow instructions
  564. class ABI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
  565. string opc, string asm, list<dag> pattern>
  566. : I<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
  567. opc, asm, "", pattern> {
  568. let Inst{27-24} = opcod;
  569. }
  570. class ABXI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
  571. string asm, list<dag> pattern>
  572. : XI<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
  573. asm, "", pattern> {
  574. let Inst{27-24} = opcod;
  575. }
  576. // BR_JT instructions
  577. class JTI<dag oops, dag iops, InstrItinClass itin,
  578. string asm, list<dag> pattern>
  579. : XI<oops, iops, AddrModeNone, 0, IndexModeNone, BrMiscFrm, itin,
  580. asm, "", pattern>;
  581. class AIldr_ex_or_acq<bits<2> opcod, bits<2> opcod2, dag oops, dag iops, InstrItinClass itin,
  582. string opc, string asm, list<dag> pattern>
  583. : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
  584. opc, asm, "", pattern> {
  585. bits<4> Rt;
  586. bits<4> addr;
  587. let Inst{27-23} = 0b00011;
  588. let Inst{22-21} = opcod;
  589. let Inst{20} = 1;
  590. let Inst{19-16} = addr;
  591. let Inst{15-12} = Rt;
  592. let Inst{11-10} = 0b11;
  593. let Inst{9-8} = opcod2;
  594. let Inst{7-0} = 0b10011111;
  595. }
  596. class AIstr_ex_or_rel<bits<2> opcod, bits<2> opcod2, dag oops, dag iops, InstrItinClass itin,
  597. string opc, string asm, list<dag> pattern>
  598. : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
  599. opc, asm, "", pattern> {
  600. bits<4> Rt;
  601. bits<4> addr;
  602. let Inst{27-23} = 0b00011;
  603. let Inst{22-21} = opcod;
  604. let Inst{20} = 0;
  605. let Inst{19-16} = addr;
  606. let Inst{11-10} = 0b11;
  607. let Inst{9-8} = opcod2;
  608. let Inst{7-4} = 0b1001;
  609. let Inst{3-0} = Rt;
  610. }
  611. // Atomic load/store instructions
  612. class AIldrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
  613. string opc, string asm, list<dag> pattern>
  614. : AIldr_ex_or_acq<opcod, 0b11, oops, iops, itin, opc, asm, pattern>;
  615. class AIstrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
  616. string opc, string asm, list<dag> pattern>
  617. : AIstr_ex_or_rel<opcod, 0b11, oops, iops, itin, opc, asm, pattern> {
  618. bits<4> Rd;
  619. let Inst{15-12} = Rd;
  620. }
  621. // Exclusive load/store instructions
  622. class AIldaex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
  623. string opc, string asm, list<dag> pattern>
  624. : AIldr_ex_or_acq<opcod, 0b10, oops, iops, itin, opc, asm, pattern>,
  625. Requires<[IsARM, HasAcquireRelease, HasV7Clrex]>;
  626. class AIstlex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
  627. string opc, string asm, list<dag> pattern>
  628. : AIstr_ex_or_rel<opcod, 0b10, oops, iops, itin, opc, asm, pattern>,
  629. Requires<[IsARM, HasAcquireRelease, HasV7Clrex]> {
  630. bits<4> Rd;
  631. let Inst{15-12} = Rd;
  632. }
  633. class AIswp<bit b, dag oops, dag iops, string opc, list<dag> pattern>
  634. : AI<oops, iops, MiscFrm, NoItinerary, opc, "\t$Rt, $Rt2, $addr", pattern> {
  635. bits<4> Rt;
  636. bits<4> Rt2;
  637. bits<4> addr;
  638. let Inst{27-23} = 0b00010;
  639. let Inst{22} = b;
  640. let Inst{21-20} = 0b00;
  641. let Inst{19-16} = addr;
  642. let Inst{15-12} = Rt;
  643. let Inst{11-4} = 0b00001001;
  644. let Inst{3-0} = Rt2;
  645. let Unpredictable{11-8} = 0b1111;
  646. let DecoderMethod = "DecodeSwap";
  647. }
  648. // Acquire/Release load/store instructions
  649. class AIldracq<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
  650. string opc, string asm, list<dag> pattern>
  651. : AIldr_ex_or_acq<opcod, 0b00, oops, iops, itin, opc, asm, pattern>,
  652. Requires<[IsARM, HasAcquireRelease]>;
  653. class AIstrrel<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
  654. string opc, string asm, list<dag> pattern>
  655. : AIstr_ex_or_rel<opcod, 0b00, oops, iops, itin, opc, asm, pattern>,
  656. Requires<[IsARM, HasAcquireRelease]> {
  657. let Inst{15-12} = 0b1111;
  658. }
  659. // addrmode1 instructions
  660. class AI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
  661. string opc, string asm, list<dag> pattern>
  662. : I<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
  663. opc, asm, "", pattern> {
  664. let Inst{24-21} = opcod;
  665. let Inst{27-26} = 0b00;
  666. }
  667. class AsI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
  668. string opc, string asm, list<dag> pattern>
  669. : sI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
  670. opc, asm, "", pattern> {
  671. let Inst{24-21} = opcod;
  672. let Inst{27-26} = 0b00;
  673. }
  674. class AXI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
  675. string asm, list<dag> pattern>
  676. : XI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
  677. asm, "", pattern> {
  678. let Inst{24-21} = opcod;
  679. let Inst{27-26} = 0b00;
  680. }
  681. // loads
  682. // LDR/LDRB/STR/STRB/...
  683. class AI2ldst<bits<3> op, bit isLd, bit isByte, dag oops, dag iops, AddrMode am,
  684. Format f, InstrItinClass itin, string opc, string asm,
  685. list<dag> pattern>
  686. : I<oops, iops, am, 4, IndexModeNone, f, itin, opc, asm,
  687. "", pattern> {
  688. let Inst{27-25} = op;
  689. let Inst{24} = 1; // 24 == P
  690. // 23 == U
  691. let Inst{22} = isByte;
  692. let Inst{21} = 0; // 21 == W
  693. let Inst{20} = isLd;
  694. }
  695. // Indexed load/stores
  696. class AI2ldstidx<bit isLd, bit isByte, bit isPre, dag oops, dag iops,
  697. IndexMode im, Format f, InstrItinClass itin, string opc,
  698. string asm, string cstr, list<dag> pattern>
  699. : I<oops, iops, AddrMode2, 4, im, f, itin,
  700. opc, asm, cstr, pattern> {
  701. bits<4> Rt;
  702. let Inst{27-26} = 0b01;
  703. let Inst{24} = isPre; // P bit
  704. let Inst{22} = isByte; // B bit
  705. let Inst{21} = isPre; // W bit
  706. let Inst{20} = isLd; // L bit
  707. let Inst{15-12} = Rt;
  708. }
  709. class AI2stridx_reg<bit isByte, bit isPre, dag oops, dag iops,
  710. IndexMode im, Format f, InstrItinClass itin, string opc,
  711. string asm, string cstr, list<dag> pattern>
  712. : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
  713. pattern> {
  714. // AM2 store w/ two operands: (GPR, am2offset)
  715. // {12} isAdd
  716. // {11-0} imm12/Rm
  717. bits<14> offset;
  718. bits<4> Rn;
  719. let Inst{25} = 1;
  720. let Inst{23} = offset{12};
  721. let Inst{19-16} = Rn;
  722. let Inst{11-5} = offset{11-5};
  723. let Inst{4} = 0;
  724. let Inst{3-0} = offset{3-0};
  725. }
  726. class AI2stridx_imm<bit isByte, bit isPre, dag oops, dag iops,
  727. IndexMode im, Format f, InstrItinClass itin, string opc,
  728. string asm, string cstr, list<dag> pattern>
  729. : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
  730. pattern> {
  731. // AM2 store w/ two operands: (GPR, am2offset)
  732. // {12} isAdd
  733. // {11-0} imm12/Rm
  734. bits<14> offset;
  735. bits<4> Rn;
  736. let Inst{25} = 0;
  737. let Inst{23} = offset{12};
  738. let Inst{19-16} = Rn;
  739. let Inst{11-0} = offset{11-0};
  740. }
  741. // FIXME: Merge with the above class when addrmode2 gets used for STR, STRB
  742. // but for now use this class for STRT and STRBT.
  743. class AI2stridxT<bit isByte, bit isPre, dag oops, dag iops,
  744. IndexMode im, Format f, InstrItinClass itin, string opc,
  745. string asm, string cstr, list<dag> pattern>
  746. : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
  747. pattern> {
  748. // AM2 store w/ two operands: (GPR, am2offset)
  749. // {17-14} Rn
  750. // {13} 1 == Rm, 0 == imm12
  751. // {12} isAdd
  752. // {11-0} imm12/Rm
  753. bits<18> addr;
  754. let Inst{25} = addr{13};
  755. let Inst{23} = addr{12};
  756. let Inst{19-16} = addr{17-14};
  757. let Inst{11-0} = addr{11-0};
  758. }
  759. // addrmode3 instructions
  760. class AI3ld<bits<4> op, bit op20, dag oops, dag iops, Format f,
  761. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  762. : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
  763. opc, asm, "", pattern> {
  764. bits<14> addr;
  765. bits<4> Rt;
  766. let Inst{27-25} = 0b000;
  767. let Inst{24} = 1; // P bit
  768. let Inst{23} = addr{8}; // U bit
  769. let Inst{22} = addr{13}; // 1 == imm8, 0 == Rm
  770. let Inst{21} = 0; // W bit
  771. let Inst{20} = op20; // L bit
  772. let Inst{19-16} = addr{12-9}; // Rn
  773. let Inst{15-12} = Rt; // Rt
  774. let Inst{11-8} = addr{7-4}; // imm7_4/zero
  775. let Inst{7-4} = op;
  776. let Inst{3-0} = addr{3-0}; // imm3_0/Rm
  777. let DecoderMethod = "DecodeAddrMode3Instruction";
  778. }
  779. class AI3ldstidx<bits<4> op, bit op20, bit isPre, dag oops, dag iops,
  780. IndexMode im, Format f, InstrItinClass itin, string opc,
  781. string asm, string cstr, list<dag> pattern>
  782. : I<oops, iops, AddrMode3, 4, im, f, itin,
  783. opc, asm, cstr, pattern> {
  784. bits<4> Rt;
  785. let Inst{27-25} = 0b000;
  786. let Inst{24} = isPre; // P bit
  787. let Inst{21} = isPre; // W bit
  788. let Inst{20} = op20; // L bit
  789. let Inst{15-12} = Rt; // Rt
  790. let Inst{7-4} = op;
  791. }
  792. // FIXME: Merge with the above class when addrmode2 gets used for LDR, LDRB
  793. // but for now use this class for LDRSBT, LDRHT, LDSHT.
  794. class AI3ldstidxT<bits<4> op, bit isLoad, dag oops, dag iops,
  795. IndexMode im, Format f, InstrItinClass itin, string opc,
  796. string asm, string cstr, list<dag> pattern>
  797. : I<oops, iops, AddrMode3, 4, im, f, itin, opc, asm, cstr, pattern> {
  798. // {13} 1 == imm8, 0 == Rm
  799. // {12-9} Rn
  800. // {8} isAdd
  801. // {7-4} imm7_4/zero
  802. // {3-0} imm3_0/Rm
  803. bits<4> addr;
  804. bits<4> Rt;
  805. let Inst{27-25} = 0b000;
  806. let Inst{24} = 0; // P bit
  807. let Inst{21} = 1;
  808. let Inst{20} = isLoad; // L bit
  809. let Inst{19-16} = addr; // Rn
  810. let Inst{15-12} = Rt; // Rt
  811. let Inst{7-4} = op;
  812. }
  813. // stores
  814. class AI3str<bits<4> op, dag oops, dag iops, Format f, InstrItinClass itin,
  815. string opc, string asm, list<dag> pattern>
  816. : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
  817. opc, asm, "", pattern> {
  818. bits<14> addr;
  819. bits<4> Rt;
  820. let Inst{27-25} = 0b000;
  821. let Inst{24} = 1; // P bit
  822. let Inst{23} = addr{8}; // U bit
  823. let Inst{22} = addr{13}; // 1 == imm8, 0 == Rm
  824. let Inst{21} = 0; // W bit
  825. let Inst{20} = 0; // L bit
  826. let Inst{19-16} = addr{12-9}; // Rn
  827. let Inst{15-12} = Rt; // Rt
  828. let Inst{11-8} = addr{7-4}; // imm7_4/zero
  829. let Inst{7-4} = op;
  830. let Inst{3-0} = addr{3-0}; // imm3_0/Rm
  831. let DecoderMethod = "DecodeAddrMode3Instruction";
  832. }
  833. // addrmode4 instructions
  834. class AXI4<dag oops, dag iops, IndexMode im, Format f, InstrItinClass itin,
  835. string asm, string cstr, list<dag> pattern>
  836. : XI<oops, iops, AddrMode4, 4, im, f, itin, asm, cstr, pattern> {
  837. bits<4> p;
  838. bits<16> regs;
  839. bits<4> Rn;
  840. let Inst{31-28} = p;
  841. let Inst{27-25} = 0b100;
  842. let Inst{22} = 0; // S bit
  843. let Inst{19-16} = Rn;
  844. let Inst{15-0} = regs;
  845. }
  846. // Unsigned multiply, multiply-accumulate instructions.
  847. class AMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
  848. string opc, string asm, list<dag> pattern>
  849. : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
  850. opc, asm, "", pattern> {
  851. let Inst{7-4} = 0b1001;
  852. let Inst{20} = 0; // S bit
  853. let Inst{27-21} = opcod;
  854. }
  855. class AsMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
  856. string opc, string asm, list<dag> pattern>
  857. : sI<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
  858. opc, asm, "", pattern> {
  859. let Inst{7-4} = 0b1001;
  860. let Inst{27-21} = opcod;
  861. }
  862. // Most significant word multiply
  863. class AMul2I<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
  864. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  865. : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
  866. opc, asm, "", pattern> {
  867. bits<4> Rd;
  868. bits<4> Rn;
  869. bits<4> Rm;
  870. let Inst{7-4} = opc7_4;
  871. let Inst{20} = 1;
  872. let Inst{27-21} = opcod;
  873. let Inst{19-16} = Rd;
  874. let Inst{11-8} = Rm;
  875. let Inst{3-0} = Rn;
  876. }
  877. // MSW multiple w/ Ra operand
  878. class AMul2Ia<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
  879. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  880. : AMul2I<opcod, opc7_4, oops, iops, itin, opc, asm, pattern> {
  881. bits<4> Ra;
  882. let Inst{15-12} = Ra;
  883. }
  884. // SMUL<x><y> / SMULW<y> / SMLA<x><y> / SMLAW<x><y>
  885. class AMulxyIbase<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
  886. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  887. : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
  888. opc, asm, "", pattern> {
  889. bits<4> Rn;
  890. bits<4> Rm;
  891. let Inst{4} = 0;
  892. let Inst{7} = 1;
  893. let Inst{20} = 0;
  894. let Inst{27-21} = opcod;
  895. let Inst{6-5} = bit6_5;
  896. let Inst{11-8} = Rm;
  897. let Inst{3-0} = Rn;
  898. }
  899. class AMulxyI<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
  900. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  901. : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
  902. bits<4> Rd;
  903. let Inst{19-16} = Rd;
  904. }
  905. // AMulxyI with Ra operand
  906. class AMulxyIa<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
  907. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  908. : AMulxyI<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
  909. bits<4> Ra;
  910. let Inst{15-12} = Ra;
  911. }
  912. // SMLAL*
  913. class AMulxyI64<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
  914. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  915. : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
  916. bits<4> RdLo;
  917. bits<4> RdHi;
  918. let Inst{19-16} = RdHi;
  919. let Inst{15-12} = RdLo;
  920. }
  921. // Extend instructions.
  922. class AExtI<bits<8> opcod, dag oops, dag iops, InstrItinClass itin,
  923. string opc, string asm, list<dag> pattern>
  924. : I<oops, iops, AddrModeNone, 4, IndexModeNone, ExtFrm, itin,
  925. opc, asm, "", pattern> {
  926. // All AExtI instructions have Rd and Rm register operands.
  927. bits<4> Rd;
  928. bits<4> Rm;
  929. let Inst{15-12} = Rd;
  930. let Inst{3-0} = Rm;
  931. let Inst{7-4} = 0b0111;
  932. let Inst{9-8} = 0b00;
  933. let Inst{27-20} = opcod;
  934. let Unpredictable{9-8} = 0b11;
  935. }
  936. // Misc Arithmetic instructions.
  937. class AMiscA1I<bits<8> opcod, bits<4> opc7_4, dag oops, dag iops,
  938. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  939. : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
  940. opc, asm, "", pattern> {
  941. bits<4> Rd;
  942. bits<4> Rm;
  943. let Inst{27-20} = opcod;
  944. let Inst{19-16} = 0b1111;
  945. let Inst{15-12} = Rd;
  946. let Inst{11-8} = 0b1111;
  947. let Inst{7-4} = opc7_4;
  948. let Inst{3-0} = Rm;
  949. }
  950. // Division instructions.
  951. class ADivA1I<bits<3> opcod, dag oops, dag iops,
  952. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  953. : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
  954. opc, asm, "", pattern> {
  955. bits<4> Rd;
  956. bits<4> Rn;
  957. bits<4> Rm;
  958. let Inst{27-23} = 0b01110;
  959. let Inst{22-20} = opcod;
  960. let Inst{19-16} = Rd;
  961. let Inst{15-12} = 0b1111;
  962. let Inst{11-8} = Rm;
  963. let Inst{7-4} = 0b0001;
  964. let Inst{3-0} = Rn;
  965. }
  966. // PKH instructions
  967. def PKHLSLAsmOperand : ImmAsmOperand<0,31> {
  968. let Name = "PKHLSLImm";
  969. let ParserMethod = "parsePKHLSLImm";
  970. }
  971. def pkh_lsl_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 32; }]>{
  972. let PrintMethod = "printPKHLSLShiftImm";
  973. let ParserMatchClass = PKHLSLAsmOperand;
  974. }
  975. def PKHASRAsmOperand : AsmOperandClass {
  976. let Name = "PKHASRImm";
  977. let ParserMethod = "parsePKHASRImm";
  978. }
  979. def pkh_asr_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]>{
  980. let PrintMethod = "printPKHASRShiftImm";
  981. let ParserMatchClass = PKHASRAsmOperand;
  982. }
  983. class APKHI<bits<8> opcod, bit tb, dag oops, dag iops, InstrItinClass itin,
  984. string opc, string asm, list<dag> pattern>
  985. : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
  986. opc, asm, "", pattern> {
  987. bits<4> Rd;
  988. bits<4> Rn;
  989. bits<4> Rm;
  990. bits<5> sh;
  991. let Inst{27-20} = opcod;
  992. let Inst{19-16} = Rn;
  993. let Inst{15-12} = Rd;
  994. let Inst{11-7} = sh;
  995. let Inst{6} = tb;
  996. let Inst{5-4} = 0b01;
  997. let Inst{3-0} = Rm;
  998. }
  999. //===----------------------------------------------------------------------===//
  1000. // ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
  1001. class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
  1002. list<Predicate> Predicates = [IsARM];
  1003. }
  1004. class ARMV5TPat<dag pattern, dag result> : Pat<pattern, result> {
  1005. list<Predicate> Predicates = [IsARM, HasV5T];
  1006. }
  1007. class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
  1008. list<Predicate> Predicates = [IsARM, HasV5TE];
  1009. }
  1010. // ARMV5MOPat - Same as ARMV5TEPat with UseMulOps.
  1011. class ARMV5MOPat<dag pattern, dag result> : Pat<pattern, result> {
  1012. list<Predicate> Predicates = [IsARM, HasV5TE, UseMulOps];
  1013. }
  1014. class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
  1015. list<Predicate> Predicates = [IsARM, HasV6];
  1016. }
  1017. class VFPPat<dag pattern, dag result> : Pat<pattern, result> {
  1018. list<Predicate> Predicates = [HasVFP2];
  1019. }
  1020. class VFPNoNEONPat<dag pattern, dag result> : Pat<pattern, result> {
  1021. list<Predicate> Predicates = [HasVFP2, DontUseNEONForFP];
  1022. }
  1023. class Thumb2DSPPat<dag pattern, dag result> : Pat<pattern, result> {
  1024. list<Predicate> Predicates = [IsThumb2, HasDSP];
  1025. }
  1026. class Thumb2DSPMulPat<dag pattern, dag result> : Pat<pattern, result> {
  1027. list<Predicate> Predicates = [IsThumb2, UseMulOps, HasDSP];
  1028. }
  1029. class FPRegs16Pat<dag pattern, dag result> : Pat<pattern, result> {
  1030. list<Predicate> Predicates = [HasFPRegs16];
  1031. }
  1032. class FP16Pat<dag pattern, dag result> : Pat<pattern, result> {
  1033. list<Predicate> Predicates = [HasFP16];
  1034. }
  1035. class FullFP16Pat<dag pattern, dag result> : Pat<pattern, result> {
  1036. list<Predicate> Predicates = [HasFullFP16];
  1037. }
  1038. //===----------------------------------------------------------------------===//
  1039. // Thumb Instruction Format Definitions.
  1040. //
  1041. class ThumbI<dag oops, dag iops, AddrMode am, int sz,
  1042. InstrItinClass itin, string asm, string cstr, list<dag> pattern>
  1043. : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1044. let OutOperandList = oops;
  1045. let InOperandList = iops;
  1046. let AsmString = asm;
  1047. let Pattern = pattern;
  1048. list<Predicate> Predicates = [IsThumb];
  1049. }
  1050. // TI - Thumb instruction.
  1051. class TI<dag oops, dag iops, InstrItinClass itin, string asm, list<dag> pattern>
  1052. : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
  1053. // Two-address instructions
  1054. class TIt<dag oops, dag iops, InstrItinClass itin, string asm,
  1055. list<dag> pattern>
  1056. : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "$lhs = $dst",
  1057. pattern>;
  1058. // tBL, tBX 32-bit instructions
  1059. class TIx2<bits<5> opcod1, bits<2> opcod2, bit opcod3,
  1060. dag oops, dag iops, InstrItinClass itin, string asm,
  1061. list<dag> pattern>
  1062. : ThumbI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>,
  1063. Encoding {
  1064. let Inst{31-27} = opcod1;
  1065. let Inst{15-14} = opcod2;
  1066. let Inst{12} = opcod3;
  1067. }
  1068. // BR_JT instructions
  1069. class TJTI<dag oops, dag iops, InstrItinClass itin, string asm,
  1070. list<dag> pattern>
  1071. : ThumbI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
  1072. // Thumb1 only
  1073. class Thumb1I<dag oops, dag iops, AddrMode am, int sz,
  1074. InstrItinClass itin, string asm, string cstr, list<dag> pattern>
  1075. : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1076. let OutOperandList = oops;
  1077. let InOperandList = iops;
  1078. let AsmString = asm;
  1079. let Pattern = pattern;
  1080. list<Predicate> Predicates = [IsThumb, IsThumb1Only];
  1081. }
  1082. class T1I<dag oops, dag iops, InstrItinClass itin,
  1083. string asm, list<dag> pattern>
  1084. : Thumb1I<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
  1085. class T1Ix2<dag oops, dag iops, InstrItinClass itin,
  1086. string asm, list<dag> pattern>
  1087. : Thumb1I<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
  1088. // Two-address instructions
  1089. class T1It<dag oops, dag iops, InstrItinClass itin,
  1090. string asm, string cstr, list<dag> pattern>
  1091. : Thumb1I<oops, iops, AddrModeNone, 2, itin,
  1092. asm, cstr, pattern>;
  1093. // Thumb1 instruction that can either be predicated or set CPSR.
  1094. class Thumb1sI<dag oops, dag iops, AddrMode am, int sz,
  1095. InstrItinClass itin,
  1096. string opc, string asm, string cstr, list<dag> pattern>
  1097. : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1098. let OutOperandList = !con(oops, (outs s_cc_out:$s));
  1099. let InOperandList = !con(iops, (ins pred:$p));
  1100. let AsmString = !strconcat(opc, "${s}${p}", asm);
  1101. let Pattern = pattern;
  1102. let thumbArithFlagSetting = 1;
  1103. list<Predicate> Predicates = [IsThumb, IsThumb1Only];
  1104. let DecoderNamespace = "ThumbSBit";
  1105. }
  1106. class T1sI<dag oops, dag iops, InstrItinClass itin,
  1107. string opc, string asm, list<dag> pattern>
  1108. : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
  1109. // Two-address instructions
  1110. class T1sIt<dag oops, dag iops, InstrItinClass itin,
  1111. string opc, string asm, list<dag> pattern>
  1112. : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm,
  1113. "$Rn = $Rdn", pattern>;
  1114. // Thumb1 instruction that can be predicated.
  1115. class Thumb1pI<dag oops, dag iops, AddrMode am, int sz,
  1116. InstrItinClass itin,
  1117. string opc, string asm, string cstr, list<dag> pattern>
  1118. : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1119. let OutOperandList = oops;
  1120. let InOperandList = !con(iops, (ins pred:$p));
  1121. let AsmString = !strconcat(opc, "${p}", asm);
  1122. let Pattern = pattern;
  1123. list<Predicate> Predicates = [IsThumb, IsThumb1Only];
  1124. }
  1125. class T1pI<dag oops, dag iops, InstrItinClass itin,
  1126. string opc, string asm, list<dag> pattern>
  1127. : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
  1128. // Two-address instructions
  1129. class T1pIt<dag oops, dag iops, InstrItinClass itin,
  1130. string opc, string asm, list<dag> pattern>
  1131. : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm,
  1132. "$Rn = $Rdn", pattern>;
  1133. class T1pIs<dag oops, dag iops,
  1134. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  1135. : Thumb1pI<oops, iops, AddrModeT1_s, 2, itin, opc, asm, "", pattern>;
  1136. class Encoding16 : Encoding {
  1137. let Inst{31-16} = 0x0000;
  1138. }
  1139. // A6.2 16-bit Thumb instruction encoding
  1140. class T1Encoding<bits<6> opcode> : Encoding16 {
  1141. let Inst{15-10} = opcode;
  1142. }
  1143. // A6.2.1 Shift (immediate), add, subtract, move, and compare encoding.
  1144. class T1General<bits<5> opcode> : Encoding16 {
  1145. let Inst{15-14} = 0b00;
  1146. let Inst{13-9} = opcode;
  1147. }
  1148. // A6.2.2 Data-processing encoding.
  1149. class T1DataProcessing<bits<4> opcode> : Encoding16 {
  1150. let Inst{15-10} = 0b010000;
  1151. let Inst{9-6} = opcode;
  1152. }
  1153. // A6.2.3 Special data instructions and branch and exchange encoding.
  1154. class T1Special<bits<4> opcode> : Encoding16 {
  1155. let Inst{15-10} = 0b010001;
  1156. let Inst{9-6} = opcode;
  1157. }
  1158. // A6.2.4 Load/store single data item encoding.
  1159. class T1LoadStore<bits<4> opA, bits<3> opB> : Encoding16 {
  1160. let Inst{15-12} = opA;
  1161. let Inst{11-9} = opB;
  1162. }
  1163. class T1LdStSP<bits<3> opB> : T1LoadStore<0b1001, opB>; // SP relative
  1164. class T1BranchCond<bits<4> opcode> : Encoding16 {
  1165. let Inst{15-12} = opcode;
  1166. }
  1167. // Helper classes to encode Thumb1 loads and stores. For immediates, the
  1168. // following bits are used for "opA" (see A6.2.4):
  1169. //
  1170. // 0b0110 => Immediate, 4 bytes
  1171. // 0b1000 => Immediate, 2 bytes
  1172. // 0b0111 => Immediate, 1 byte
  1173. class T1pILdStEncode<bits<3> opcode, dag oops, dag iops, AddrMode am,
  1174. InstrItinClass itin, string opc, string asm,
  1175. list<dag> pattern>
  1176. : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
  1177. T1LoadStore<0b0101, opcode> {
  1178. bits<3> Rt;
  1179. bits<8> addr;
  1180. let Inst{8-6} = addr{5-3}; // Rm
  1181. let Inst{5-3} = addr{2-0}; // Rn
  1182. let Inst{2-0} = Rt;
  1183. }
  1184. class T1pILdStEncodeImm<bits<4> opA, bit opB, dag oops, dag iops, AddrMode am,
  1185. InstrItinClass itin, string opc, string asm,
  1186. list<dag> pattern>
  1187. : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
  1188. T1LoadStore<opA, {opB,?,?}> {
  1189. bits<3> Rt;
  1190. bits<8> addr;
  1191. let Inst{10-6} = addr{7-3}; // imm5
  1192. let Inst{5-3} = addr{2-0}; // Rn
  1193. let Inst{2-0} = Rt;
  1194. }
  1195. // A6.2.5 Miscellaneous 16-bit instructions encoding.
  1196. class T1Misc<bits<7> opcode> : Encoding16 {
  1197. let Inst{15-12} = 0b1011;
  1198. let Inst{11-5} = opcode;
  1199. }
  1200. // Thumb2I - Thumb2 instruction. Almost all Thumb2 instructions are predicable.
  1201. class Thumb2I<dag oops, dag iops, AddrMode am, int sz,
  1202. InstrItinClass itin,
  1203. string opc, string asm, string cstr, list<dag> pattern>
  1204. : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1205. let OutOperandList = oops;
  1206. let InOperandList = !con(iops, (ins pred:$p));
  1207. let AsmString = !strconcat(opc, "${p}", asm);
  1208. let Pattern = pattern;
  1209. list<Predicate> Predicates = [IsThumb2];
  1210. let DecoderNamespace = "Thumb2";
  1211. }
  1212. // Same as Thumb2I except it can optionally modify CPSR. Note it's modeled as an
  1213. // input operand since by default it's a zero register. It will become an
  1214. // implicit def once it's "flipped".
  1215. //
  1216. // FIXME: This uses unified syntax so {s} comes before {p}. We should make it
  1217. // more consistent.
  1218. class Thumb2sI<dag oops, dag iops, AddrMode am, int sz,
  1219. InstrItinClass itin,
  1220. string opc, string asm, string cstr, list<dag> pattern>
  1221. : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1222. bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
  1223. let Inst{20} = s;
  1224. let OutOperandList = oops;
  1225. let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
  1226. let AsmString = !strconcat(opc, "${s}${p}", asm);
  1227. let Pattern = pattern;
  1228. list<Predicate> Predicates = [IsThumb2];
  1229. let DecoderNamespace = "Thumb2";
  1230. }
  1231. // Special cases
  1232. class Thumb2XI<dag oops, dag iops, AddrMode am, int sz,
  1233. InstrItinClass itin,
  1234. string asm, string cstr, list<dag> pattern>
  1235. : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1236. let OutOperandList = oops;
  1237. let InOperandList = iops;
  1238. let AsmString = asm;
  1239. let Pattern = pattern;
  1240. list<Predicate> Predicates = [IsThumb2];
  1241. let DecoderNamespace = "Thumb2";
  1242. }
  1243. class ThumbXI<dag oops, dag iops, AddrMode am, int sz,
  1244. InstrItinClass itin,
  1245. string asm, string cstr, list<dag> pattern>
  1246. : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
  1247. let OutOperandList = oops;
  1248. let InOperandList = iops;
  1249. let AsmString = asm;
  1250. let Pattern = pattern;
  1251. list<Predicate> Predicates = [IsThumb, IsThumb1Only];
  1252. let DecoderNamespace = "Thumb";
  1253. }
  1254. class T2I<dag oops, dag iops, InstrItinClass itin,
  1255. string opc, string asm, list<dag> pattern>
  1256. : Thumb2I<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
  1257. class T2Ii12<dag oops, dag iops, InstrItinClass itin,
  1258. string opc, string asm, list<dag> pattern>
  1259. : Thumb2I<oops, iops, AddrModeT2_i12, 4, itin, opc, asm, "",pattern>;
  1260. class T2Ii8<dag oops, dag iops, InstrItinClass itin,
  1261. string opc, string asm, list<dag> pattern>
  1262. : Thumb2I<oops, iops, AddrModeT2_i8, 4, itin, opc, asm, "", pattern>;
  1263. class T2Iso<dag oops, dag iops, InstrItinClass itin,
  1264. string opc, string asm, list<dag> pattern>
  1265. : Thumb2I<oops, iops, AddrModeT2_so, 4, itin, opc, asm, "", pattern>;
  1266. class T2Ipc<dag oops, dag iops, InstrItinClass itin,
  1267. string opc, string asm, list<dag> pattern>
  1268. : Thumb2I<oops, iops, AddrModeT2_pc, 4, itin, opc, asm, "", pattern>;
  1269. class T2Ii8s4<bit P, bit W, bit isLoad, dag oops, dag iops, InstrItinClass itin,
  1270. string opc, string asm, string cstr, list<dag> pattern>
  1271. : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
  1272. pattern> {
  1273. bits<4> Rt;
  1274. bits<4> Rt2;
  1275. bits<13> addr;
  1276. let Inst{31-25} = 0b1110100;
  1277. let Inst{24} = P;
  1278. let Inst{23} = addr{8};
  1279. let Inst{22} = 1;
  1280. let Inst{21} = W;
  1281. let Inst{20} = isLoad;
  1282. let Inst{19-16} = addr{12-9};
  1283. let Inst{15-12} = Rt{3-0};
  1284. let Inst{11-8} = Rt2{3-0};
  1285. let Inst{7-0} = addr{7-0};
  1286. }
  1287. class T2Ii8s4post<bit P, bit W, bit isLoad, dag oops, dag iops,
  1288. InstrItinClass itin, string opc, string asm, string cstr,
  1289. list<dag> pattern>
  1290. : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
  1291. pattern> {
  1292. bits<4> Rt;
  1293. bits<4> Rt2;
  1294. bits<4> addr;
  1295. bits<9> imm;
  1296. let Inst{31-25} = 0b1110100;
  1297. let Inst{24} = P;
  1298. let Inst{23} = imm{8};
  1299. let Inst{22} = 1;
  1300. let Inst{21} = W;
  1301. let Inst{20} = isLoad;
  1302. let Inst{19-16} = addr;
  1303. let Inst{15-12} = Rt{3-0};
  1304. let Inst{11-8} = Rt2{3-0};
  1305. let Inst{7-0} = imm{7-0};
  1306. }
  1307. class T2sI<dag oops, dag iops, InstrItinClass itin,
  1308. string opc, string asm, list<dag> pattern>
  1309. : Thumb2sI<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
  1310. class T2XI<dag oops, dag iops, InstrItinClass itin,
  1311. string asm, list<dag> pattern>
  1312. : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
  1313. class T2JTI<dag oops, dag iops, InstrItinClass itin,
  1314. string asm, list<dag> pattern>
  1315. : Thumb2XI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
  1316. // Move to/from coprocessor instructions
  1317. class T2Cop<bits<4> opc, dag oops, dag iops, string opcstr, string asm,
  1318. list<dag> pattern>
  1319. : T2I <oops, iops, NoItinerary, opcstr, asm, pattern>, Requires<[IsThumb2]> {
  1320. let Inst{31-28} = opc;
  1321. }
  1322. // Two-address instructions
  1323. class T2XIt<dag oops, dag iops, InstrItinClass itin,
  1324. string asm, string cstr, list<dag> pattern>
  1325. : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, cstr, pattern>;
  1326. // T2Ipreldst - Thumb2 pre-indexed load / store instructions.
  1327. class T2Ipreldst<bit signed, bits<2> opcod, bit load, bit pre,
  1328. dag oops, dag iops,
  1329. AddrMode am, IndexMode im, InstrItinClass itin,
  1330. string opc, string asm, string cstr, list<dag> pattern>
  1331. : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
  1332. let OutOperandList = oops;
  1333. let InOperandList = !con(iops, (ins pred:$p));
  1334. let AsmString = !strconcat(opc, "${p}", asm);
  1335. let Pattern = pattern;
  1336. list<Predicate> Predicates = [IsThumb2];
  1337. let DecoderNamespace = "Thumb2";
  1338. bits<4> Rt;
  1339. bits<13> addr;
  1340. let Inst{31-27} = 0b11111;
  1341. let Inst{26-25} = 0b00;
  1342. let Inst{24} = signed;
  1343. let Inst{23} = 0;
  1344. let Inst{22-21} = opcod;
  1345. let Inst{20} = load;
  1346. let Inst{19-16} = addr{12-9};
  1347. let Inst{15-12} = Rt{3-0};
  1348. let Inst{11} = 1;
  1349. // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
  1350. let Inst{10} = pre; // The P bit.
  1351. let Inst{9} = addr{8}; // Sign bit
  1352. let Inst{8} = 1; // The W bit.
  1353. let Inst{7-0} = addr{7-0};
  1354. let DecoderMethod = "DecodeT2LdStPre";
  1355. }
  1356. // T2Ipostldst - Thumb2 post-indexed load / store instructions.
  1357. class T2Ipostldst<bit signed, bits<2> opcod, bit load, bit pre,
  1358. dag oops, dag iops,
  1359. AddrMode am, IndexMode im, InstrItinClass itin,
  1360. string opc, string asm, string cstr, list<dag> pattern>
  1361. : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
  1362. let OutOperandList = oops;
  1363. let InOperandList = !con(iops, (ins pred:$p));
  1364. let AsmString = !strconcat(opc, "${p}", asm);
  1365. let Pattern = pattern;
  1366. list<Predicate> Predicates = [IsThumb2];
  1367. let DecoderNamespace = "Thumb2";
  1368. bits<4> Rt;
  1369. bits<4> Rn;
  1370. bits<9> offset;
  1371. let Inst{31-27} = 0b11111;
  1372. let Inst{26-25} = 0b00;
  1373. let Inst{24} = signed;
  1374. let Inst{23} = 0;
  1375. let Inst{22-21} = opcod;
  1376. let Inst{20} = load;
  1377. let Inst{19-16} = Rn;
  1378. let Inst{15-12} = Rt{3-0};
  1379. let Inst{11} = 1;
  1380. // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
  1381. let Inst{10} = pre; // The P bit.
  1382. let Inst{9} = offset{8}; // Sign bit
  1383. let Inst{8} = 1; // The W bit.
  1384. let Inst{7-0} = offset{7-0};
  1385. let DecoderMethod = "DecodeT2LdStPre";
  1386. }
  1387. // T1Pat - Same as Pat<>, but requires that the compiler be in Thumb1 mode.
  1388. class T1Pat<dag pattern, dag result> : Pat<pattern, result> {
  1389. list<Predicate> Predicates = [IsThumb, IsThumb1Only];
  1390. }
  1391. // T2v6Pat - Same as Pat<>, but requires V6T2 Thumb2 mode.
  1392. class T2v6Pat<dag pattern, dag result> : Pat<pattern, result> {
  1393. list<Predicate> Predicates = [IsThumb2, HasV6T2];
  1394. }
  1395. // T2Pat - Same as Pat<>, but requires that the compiler be in Thumb2 mode.
  1396. class T2Pat<dag pattern, dag result> : Pat<pattern, result> {
  1397. list<Predicate> Predicates = [IsThumb2];
  1398. }
  1399. //===----------------------------------------------------------------------===//
  1400. //===----------------------------------------------------------------------===//
  1401. // ARM VFP Instruction templates.
  1402. //
  1403. // Almost all VFP instructions are predicable.
  1404. class VFPI<dag oops, dag iops, AddrMode am, int sz,
  1405. IndexMode im, Format f, InstrItinClass itin,
  1406. string opc, string asm, string cstr, list<dag> pattern>
  1407. : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
  1408. bits<4> p;
  1409. let Inst{31-28} = p;
  1410. let OutOperandList = oops;
  1411. let InOperandList = !con(iops, (ins pred:$p));
  1412. let AsmString = !strconcat(opc, "${p}", asm);
  1413. let Pattern = pattern;
  1414. let PostEncoderMethod = "VFPThumb2PostEncoder";
  1415. let DecoderNamespace = "VFP";
  1416. list<Predicate> Predicates = [HasVFP2];
  1417. }
  1418. // Special cases
  1419. class VFPXI<dag oops, dag iops, AddrMode am, int sz,
  1420. IndexMode im, Format f, InstrItinClass itin,
  1421. string asm, string cstr, list<dag> pattern>
  1422. : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
  1423. bits<4> p;
  1424. let Inst{31-28} = p;
  1425. let OutOperandList = oops;
  1426. let InOperandList = iops;
  1427. let AsmString = asm;
  1428. let Pattern = pattern;
  1429. let PostEncoderMethod = "VFPThumb2PostEncoder";
  1430. let DecoderNamespace = "VFP";
  1431. list<Predicate> Predicates = [HasVFP2];
  1432. }
  1433. class VFPAI<dag oops, dag iops, Format f, InstrItinClass itin,
  1434. string opc, string asm, list<dag> pattern>
  1435. : VFPI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
  1436. opc, asm, "", pattern> {
  1437. let PostEncoderMethod = "VFPThumb2PostEncoder";
  1438. }
  1439. // ARM VFP addrmode5 loads and stores
  1440. class ADI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
  1441. InstrItinClass itin,
  1442. string opc, string asm, list<dag> pattern>
  1443. : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
  1444. VFPLdStFrm, itin, opc, asm, "", pattern> {
  1445. // Instruction operands.
  1446. bits<5> Dd;
  1447. bits<13> addr;
  1448. // Encode instruction operands.
  1449. let Inst{23} = addr{8}; // U (add = (U == '1'))
  1450. let Inst{22} = Dd{4};
  1451. let Inst{19-16} = addr{12-9}; // Rn
  1452. let Inst{15-12} = Dd{3-0};
  1453. let Inst{7-0} = addr{7-0}; // imm8
  1454. let Inst{27-24} = opcod1;
  1455. let Inst{21-20} = opcod2;
  1456. let Inst{11-9} = 0b101;
  1457. let Inst{8} = 1; // Double precision
  1458. // Loads & stores operate on both NEON and VFP pipelines.
  1459. let D = VFPNeonDomain;
  1460. }
  1461. class ASI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
  1462. InstrItinClass itin,
  1463. string opc, string asm, list<dag> pattern>
  1464. : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
  1465. VFPLdStFrm, itin, opc, asm, "", pattern> {
  1466. // Instruction operands.
  1467. bits<5> Sd;
  1468. bits<13> addr;
  1469. // Encode instruction operands.
  1470. let Inst{23} = addr{8}; // U (add = (U == '1'))
  1471. let Inst{22} = Sd{0};
  1472. let Inst{19-16} = addr{12-9}; // Rn
  1473. let Inst{15-12} = Sd{4-1};
  1474. let Inst{7-0} = addr{7-0}; // imm8
  1475. let Inst{27-24} = opcod1;
  1476. let Inst{21-20} = opcod2;
  1477. let Inst{11-9} = 0b101;
  1478. let Inst{8} = 0; // Single precision
  1479. // Loads & stores operate on both NEON and VFP pipelines.
  1480. let D = VFPNeonDomain;
  1481. }
  1482. class AHI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
  1483. InstrItinClass itin,
  1484. string opc, string asm, list<dag> pattern>
  1485. : VFPI<oops, iops, AddrMode5FP16, 4, IndexModeNone,
  1486. VFPLdStFrm, itin, opc, asm, "", pattern> {
  1487. list<Predicate> Predicates = [HasFullFP16];
  1488. // Instruction operands.
  1489. bits<5> Sd;
  1490. bits<13> addr;
  1491. // Encode instruction operands.
  1492. let Inst{23} = addr{8}; // U (add = (U == '1'))
  1493. let Inst{22} = Sd{0};
  1494. let Inst{19-16} = addr{12-9}; // Rn
  1495. let Inst{15-12} = Sd{4-1};
  1496. let Inst{7-0} = addr{7-0}; // imm8
  1497. let Inst{27-24} = opcod1;
  1498. let Inst{21-20} = opcod2;
  1499. let Inst{11-8} = 0b1001; // Half precision
  1500. // Loads & stores operate on both NEON and VFP pipelines.
  1501. let D = VFPNeonDomain;
  1502. let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
  1503. }
  1504. // VFP Load / store multiple pseudo instructions.
  1505. class PseudoVFPLdStM<dag oops, dag iops, InstrItinClass itin, string cstr,
  1506. list<dag> pattern>
  1507. : InstARM<AddrMode4, 4, IndexModeNone, Pseudo, VFPNeonDomain,
  1508. cstr, itin> {
  1509. let OutOperandList = oops;
  1510. let InOperandList = !con(iops, (ins pred:$p));
  1511. let Pattern = pattern;
  1512. list<Predicate> Predicates = [HasVFP2];
  1513. }
  1514. // Load / store multiple
  1515. // Unknown precision
  1516. class AXXI4<dag oops, dag iops, IndexMode im,
  1517. string asm, string cstr, list<dag> pattern>
  1518. : VFPXI<oops, iops, AddrMode4, 4, im,
  1519. VFPLdStFrm, NoItinerary, asm, cstr, pattern> {
  1520. // Instruction operands.
  1521. bits<4> Rn;
  1522. bits<13> regs;
  1523. // Encode instruction operands.
  1524. let Inst{19-16} = Rn;
  1525. let Inst{22} = 0;
  1526. let Inst{15-12} = regs{11-8};
  1527. let Inst{7-1} = regs{7-1};
  1528. let Inst{27-25} = 0b110;
  1529. let Inst{11-8} = 0b1011;
  1530. let Inst{0} = 1;
  1531. }
  1532. // Double precision
  1533. class AXDI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
  1534. string asm, string cstr, list<dag> pattern>
  1535. : VFPXI<oops, iops, AddrMode4, 4, im,
  1536. VFPLdStMulFrm, itin, asm, cstr, pattern> {
  1537. // Instruction operands.
  1538. bits<4> Rn;
  1539. bits<13> regs;
  1540. // Encode instruction operands.
  1541. let Inst{19-16} = Rn;
  1542. let Inst{22} = regs{12};
  1543. let Inst{15-12} = regs{11-8};
  1544. let Inst{7-1} = regs{7-1};
  1545. let Inst{27-25} = 0b110;
  1546. let Inst{11-9} = 0b101;
  1547. let Inst{8} = 1; // Double precision
  1548. let Inst{0} = 0;
  1549. }
  1550. // Single Precision
  1551. class AXSI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
  1552. string asm, string cstr, list<dag> pattern>
  1553. : VFPXI<oops, iops, AddrMode4, 4, im,
  1554. VFPLdStMulFrm, itin, asm, cstr, pattern> {
  1555. // Instruction operands.
  1556. bits<4> Rn;
  1557. bits<13> regs;
  1558. // Encode instruction operands.
  1559. let Inst{19-16} = Rn;
  1560. let Inst{22} = regs{8};
  1561. let Inst{15-12} = regs{12-9};
  1562. let Inst{7-0} = regs{7-0};
  1563. let Inst{27-25} = 0b110;
  1564. let Inst{11-9} = 0b101;
  1565. let Inst{8} = 0; // Single precision
  1566. }
  1567. // Double precision, unary
  1568. class ADuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
  1569. bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
  1570. string asm, list<dag> pattern>
  1571. : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
  1572. // Instruction operands.
  1573. bits<5> Dd;
  1574. bits<5> Dm;
  1575. // Encode instruction operands.
  1576. let Inst{3-0} = Dm{3-0};
  1577. let Inst{5} = Dm{4};
  1578. let Inst{15-12} = Dd{3-0};
  1579. let Inst{22} = Dd{4};
  1580. let Inst{27-23} = opcod1;
  1581. let Inst{21-20} = opcod2;
  1582. let Inst{19-16} = opcod3;
  1583. let Inst{11-9} = 0b101;
  1584. let Inst{8} = 1; // Double precision
  1585. let Inst{7-6} = opcod4;
  1586. let Inst{4} = opcod5;
  1587. let Predicates = [HasVFP2, HasDPVFP];
  1588. }
  1589. // Double precision, unary, not-predicated
  1590. class ADuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
  1591. bit opcod5, dag oops, dag iops, InstrItinClass itin,
  1592. string asm, list<dag> pattern>
  1593. : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPUnaryFrm, itin, asm, "", pattern> {
  1594. // Instruction operands.
  1595. bits<5> Dd;
  1596. bits<5> Dm;
  1597. let Inst{31-28} = 0b1111;
  1598. // Encode instruction operands.
  1599. let Inst{3-0} = Dm{3-0};
  1600. let Inst{5} = Dm{4};
  1601. let Inst{15-12} = Dd{3-0};
  1602. let Inst{22} = Dd{4};
  1603. let Inst{27-23} = opcod1;
  1604. let Inst{21-20} = opcod2;
  1605. let Inst{19-16} = opcod3;
  1606. let Inst{11-9} = 0b101;
  1607. let Inst{8} = 1; // Double precision
  1608. let Inst{7-6} = opcod4;
  1609. let Inst{4} = opcod5;
  1610. }
  1611. // Double precision, binary
  1612. class ADbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
  1613. dag iops, InstrItinClass itin, string opc, string asm,
  1614. list<dag> pattern>
  1615. : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
  1616. // Instruction operands.
  1617. bits<5> Dd;
  1618. bits<5> Dn;
  1619. bits<5> Dm;
  1620. // Encode instruction operands.
  1621. let Inst{3-0} = Dm{3-0};
  1622. let Inst{5} = Dm{4};
  1623. let Inst{19-16} = Dn{3-0};
  1624. let Inst{7} = Dn{4};
  1625. let Inst{15-12} = Dd{3-0};
  1626. let Inst{22} = Dd{4};
  1627. let Inst{27-23} = opcod1;
  1628. let Inst{21-20} = opcod2;
  1629. let Inst{11-9} = 0b101;
  1630. let Inst{8} = 1; // Double precision
  1631. let Inst{6} = op6;
  1632. let Inst{4} = op4;
  1633. let Predicates = [HasVFP2, HasDPVFP];
  1634. }
  1635. // FP, binary, not predicated
  1636. class ADbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
  1637. InstrItinClass itin, string asm, list<dag> pattern>
  1638. : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPBinaryFrm, itin,
  1639. asm, "", pattern>
  1640. {
  1641. // Instruction operands.
  1642. bits<5> Dd;
  1643. bits<5> Dn;
  1644. bits<5> Dm;
  1645. let Inst{31-28} = 0b1111;
  1646. // Encode instruction operands.
  1647. let Inst{3-0} = Dm{3-0};
  1648. let Inst{5} = Dm{4};
  1649. let Inst{19-16} = Dn{3-0};
  1650. let Inst{7} = Dn{4};
  1651. let Inst{15-12} = Dd{3-0};
  1652. let Inst{22} = Dd{4};
  1653. let Inst{27-23} = opcod1;
  1654. let Inst{21-20} = opcod2;
  1655. let Inst{11-9} = 0b101;
  1656. let Inst{8} = 1; // double precision
  1657. let Inst{6} = opcod3;
  1658. let Inst{4} = 0;
  1659. let Predicates = [HasVFP2, HasDPVFP];
  1660. }
  1661. // Single precision, unary, predicated
  1662. class ASuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
  1663. bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
  1664. string asm, list<dag> pattern>
  1665. : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
  1666. // Instruction operands.
  1667. bits<5> Sd;
  1668. bits<5> Sm;
  1669. // Encode instruction operands.
  1670. let Inst{3-0} = Sm{4-1};
  1671. let Inst{5} = Sm{0};
  1672. let Inst{15-12} = Sd{4-1};
  1673. let Inst{22} = Sd{0};
  1674. let Inst{27-23} = opcod1;
  1675. let Inst{21-20} = opcod2;
  1676. let Inst{19-16} = opcod3;
  1677. let Inst{11-9} = 0b101;
  1678. let Inst{8} = 0; // Single precision
  1679. let Inst{7-6} = opcod4;
  1680. let Inst{4} = opcod5;
  1681. }
  1682. // Single precision, unary, non-predicated
  1683. class ASuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
  1684. bit opcod5, dag oops, dag iops, InstrItinClass itin,
  1685. string asm, list<dag> pattern>
  1686. : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
  1687. VFPUnaryFrm, itin, asm, "", pattern> {
  1688. // Instruction operands.
  1689. bits<5> Sd;
  1690. bits<5> Sm;
  1691. let Inst{31-28} = 0b1111;
  1692. // Encode instruction operands.
  1693. let Inst{3-0} = Sm{4-1};
  1694. let Inst{5} = Sm{0};
  1695. let Inst{15-12} = Sd{4-1};
  1696. let Inst{22} = Sd{0};
  1697. let Inst{27-23} = opcod1;
  1698. let Inst{21-20} = opcod2;
  1699. let Inst{19-16} = opcod3;
  1700. let Inst{11-9} = 0b101;
  1701. let Inst{8} = 0; // Single precision
  1702. let Inst{7-6} = opcod4;
  1703. let Inst{4} = opcod5;
  1704. }
  1705. // Single precision unary, if no NEON. Same as ASuI except not available if
  1706. // NEON is enabled.
  1707. class ASuIn<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
  1708. bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
  1709. string asm, list<dag> pattern>
  1710. : ASuI<opcod1, opcod2, opcod3, opcod4, opcod5, oops, iops, itin, opc, asm,
  1711. pattern> {
  1712. list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
  1713. }
  1714. // Single precision, binary
  1715. class ASbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
  1716. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  1717. : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
  1718. // Instruction operands.
  1719. bits<5> Sd;
  1720. bits<5> Sn;
  1721. bits<5> Sm;
  1722. // Encode instruction operands.
  1723. let Inst{3-0} = Sm{4-1};
  1724. let Inst{5} = Sm{0};
  1725. let Inst{19-16} = Sn{4-1};
  1726. let Inst{7} = Sn{0};
  1727. let Inst{15-12} = Sd{4-1};
  1728. let Inst{22} = Sd{0};
  1729. let Inst{27-23} = opcod1;
  1730. let Inst{21-20} = opcod2;
  1731. let Inst{11-9} = 0b101;
  1732. let Inst{8} = 0; // Single precision
  1733. let Inst{6} = op6;
  1734. let Inst{4} = op4;
  1735. }
  1736. // Single precision, binary, not predicated
  1737. class ASbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
  1738. InstrItinClass itin, string asm, list<dag> pattern>
  1739. : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
  1740. VFPBinaryFrm, itin, asm, "", pattern>
  1741. {
  1742. // Instruction operands.
  1743. bits<5> Sd;
  1744. bits<5> Sn;
  1745. bits<5> Sm;
  1746. let Inst{31-28} = 0b1111;
  1747. // Encode instruction operands.
  1748. let Inst{3-0} = Sm{4-1};
  1749. let Inst{5} = Sm{0};
  1750. let Inst{19-16} = Sn{4-1};
  1751. let Inst{7} = Sn{0};
  1752. let Inst{15-12} = Sd{4-1};
  1753. let Inst{22} = Sd{0};
  1754. let Inst{27-23} = opcod1;
  1755. let Inst{21-20} = opcod2;
  1756. let Inst{11-9} = 0b101;
  1757. let Inst{8} = 0; // Single precision
  1758. let Inst{6} = opcod3;
  1759. let Inst{4} = 0;
  1760. }
  1761. // Single precision binary, if no NEON. Same as ASbI except not available if
  1762. // NEON is enabled.
  1763. class ASbIn<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
  1764. dag iops, InstrItinClass itin, string opc, string asm,
  1765. list<dag> pattern>
  1766. : ASbI<opcod1, opcod2, op6, op4, oops, iops, itin, opc, asm, pattern> {
  1767. list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
  1768. // Instruction operands.
  1769. bits<5> Sd;
  1770. bits<5> Sn;
  1771. bits<5> Sm;
  1772. // Encode instruction operands.
  1773. let Inst{3-0} = Sm{4-1};
  1774. let Inst{5} = Sm{0};
  1775. let Inst{19-16} = Sn{4-1};
  1776. let Inst{7} = Sn{0};
  1777. let Inst{15-12} = Sd{4-1};
  1778. let Inst{22} = Sd{0};
  1779. }
  1780. // Half precision, unary, predicated
  1781. class AHuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
  1782. bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
  1783. string asm, list<dag> pattern>
  1784. : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
  1785. list<Predicate> Predicates = [HasFullFP16];
  1786. // Instruction operands.
  1787. bits<5> Sd;
  1788. bits<5> Sm;
  1789. // Encode instruction operands.
  1790. let Inst{3-0} = Sm{4-1};
  1791. let Inst{5} = Sm{0};
  1792. let Inst{15-12} = Sd{4-1};
  1793. let Inst{22} = Sd{0};
  1794. let Inst{27-23} = opcod1;
  1795. let Inst{21-20} = opcod2;
  1796. let Inst{19-16} = opcod3;
  1797. let Inst{11-8} = 0b1001; // Half precision
  1798. let Inst{7-6} = opcod4;
  1799. let Inst{4} = opcod5;
  1800. let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
  1801. }
  1802. // Half precision, unary, non-predicated
  1803. class AHuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
  1804. bit opcod5, dag oops, dag iops, InstrItinClass itin,
  1805. string asm, list<dag> pattern>
  1806. : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
  1807. VFPUnaryFrm, itin, asm, "", pattern> {
  1808. list<Predicate> Predicates = [HasFullFP16];
  1809. // Instruction operands.
  1810. bits<5> Sd;
  1811. bits<5> Sm;
  1812. let Inst{31-28} = 0b1111;
  1813. // Encode instruction operands.
  1814. let Inst{3-0} = Sm{4-1};
  1815. let Inst{5} = Sm{0};
  1816. let Inst{15-12} = Sd{4-1};
  1817. let Inst{22} = Sd{0};
  1818. let Inst{27-23} = opcod1;
  1819. let Inst{21-20} = opcod2;
  1820. let Inst{19-16} = opcod3;
  1821. let Inst{11-8} = 0b1001; // Half precision
  1822. let Inst{7-6} = opcod4;
  1823. let Inst{4} = opcod5;
  1824. let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
  1825. }
  1826. // Half precision, binary
  1827. class AHbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
  1828. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  1829. : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
  1830. list<Predicate> Predicates = [HasFullFP16];
  1831. // Instruction operands.
  1832. bits<5> Sd;
  1833. bits<5> Sn;
  1834. bits<5> Sm;
  1835. // Encode instruction operands.
  1836. let Inst{3-0} = Sm{4-1};
  1837. let Inst{5} = Sm{0};
  1838. let Inst{19-16} = Sn{4-1};
  1839. let Inst{7} = Sn{0};
  1840. let Inst{15-12} = Sd{4-1};
  1841. let Inst{22} = Sd{0};
  1842. let Inst{27-23} = opcod1;
  1843. let Inst{21-20} = opcod2;
  1844. let Inst{11-8} = 0b1001; // Half precision
  1845. let Inst{6} = op6;
  1846. let Inst{4} = op4;
  1847. let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
  1848. }
  1849. // Half precision, binary, not predicated
  1850. class AHbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
  1851. InstrItinClass itin, string asm, list<dag> pattern>
  1852. : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
  1853. VFPBinaryFrm, itin, asm, "", pattern> {
  1854. list<Predicate> Predicates = [HasFullFP16];
  1855. // Instruction operands.
  1856. bits<5> Sd;
  1857. bits<5> Sn;
  1858. bits<5> Sm;
  1859. let Inst{31-28} = 0b1111;
  1860. // Encode instruction operands.
  1861. let Inst{3-0} = Sm{4-1};
  1862. let Inst{5} = Sm{0};
  1863. let Inst{19-16} = Sn{4-1};
  1864. let Inst{7} = Sn{0};
  1865. let Inst{15-12} = Sd{4-1};
  1866. let Inst{22} = Sd{0};
  1867. let Inst{27-23} = opcod1;
  1868. let Inst{21-20} = opcod2;
  1869. let Inst{11-8} = 0b1001; // Half precision
  1870. let Inst{6} = opcod3;
  1871. let Inst{4} = 0;
  1872. let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
  1873. }
  1874. // VFP conversion instructions
  1875. class AVConv1I<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
  1876. dag oops, dag iops, InstrItinClass itin, string opc, string asm,
  1877. list<dag> pattern>
  1878. : VFPAI<oops, iops, VFPConv1Frm, itin, opc, asm, pattern> {
  1879. let Inst{27-23} = opcod1;
  1880. let Inst{21-20} = opcod2;
  1881. let Inst{19-16} = opcod3;
  1882. let Inst{11-8} = opcod4;
  1883. let Inst{6} = 1;
  1884. let Inst{4} = 0;
  1885. }
  1886. // VFP conversion between floating-point and fixed-point
  1887. class AVConv1XI<bits<5> op1, bits<2> op2, bits<4> op3, bits<4> op4, bit op5,
  1888. dag oops, dag iops, InstrItinClass itin, string opc, string asm,
  1889. list<dag> pattern>
  1890. : AVConv1I<op1, op2, op3, op4, oops, iops, itin, opc, asm, pattern> {
  1891. bits<5> fbits;
  1892. // size (fixed-point number): sx == 0 ? 16 : 32
  1893. let Inst{7} = op5; // sx
  1894. let Inst{5} = fbits{0};
  1895. let Inst{3-0} = fbits{4-1};
  1896. }
  1897. // VFP conversion instructions, if no NEON
  1898. class AVConv1In<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
  1899. dag oops, dag iops, InstrItinClass itin,
  1900. string opc, string asm, list<dag> pattern>
  1901. : AVConv1I<opcod1, opcod2, opcod3, opcod4, oops, iops, itin, opc, asm,
  1902. pattern> {
  1903. list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
  1904. }
  1905. class AVConvXI<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops, Format f,
  1906. InstrItinClass itin,
  1907. string opc, string asm, list<dag> pattern>
  1908. : VFPAI<oops, iops, f, itin, opc, asm, pattern> {
  1909. let Inst{27-20} = opcod1;
  1910. let Inst{11-8} = opcod2;
  1911. let Inst{4} = 1;
  1912. }
  1913. class AVConv2I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
  1914. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  1915. : AVConvXI<opcod1, opcod2, oops, iops, VFPConv2Frm, itin, opc, asm, pattern>;
  1916. class AVConv3I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
  1917. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  1918. : AVConvXI<opcod1, opcod2, oops, iops, VFPConv3Frm, itin, opc, asm, pattern>;
  1919. class AVConv4I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
  1920. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  1921. : AVConvXI<opcod1, opcod2, oops, iops, VFPConv4Frm, itin, opc, asm, pattern>;
  1922. class AVConv5I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
  1923. InstrItinClass itin, string opc, string asm, list<dag> pattern>
  1924. : AVConvXI<opcod1, opcod2, oops, iops, VFPConv5Frm, itin, opc, asm, pattern>;
  1925. //===----------------------------------------------------------------------===//
  1926. //===----------------------------------------------------------------------===//
  1927. // ARM NEON Instruction templates.
  1928. //
  1929. class NeonI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
  1930. InstrItinClass itin, string opc, string dt, string asm, string cstr,
  1931. list<dag> pattern>
  1932. : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
  1933. let OutOperandList = oops;
  1934. let InOperandList = !con(iops, (ins pred:$p));
  1935. let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
  1936. let Pattern = pattern;
  1937. list<Predicate> Predicates = [HasNEON];
  1938. let DecoderNamespace = "NEON";
  1939. }
  1940. // Same as NeonI except it does not have a "data type" specifier.
  1941. class NeonXI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
  1942. InstrItinClass itin, string opc, string asm, string cstr,
  1943. list<dag> pattern>
  1944. : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
  1945. let OutOperandList = oops;
  1946. let InOperandList = !con(iops, (ins pred:$p));
  1947. let AsmString = !strconcat(opc, "${p}", "\t", asm);
  1948. let Pattern = pattern;
  1949. list<Predicate> Predicates = [HasNEON];
  1950. let DecoderNamespace = "NEON";
  1951. }
  1952. // Same as NeonI except it is not predicated
  1953. class NeonInp<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
  1954. InstrItinClass itin, string opc, string dt, string asm, string cstr,
  1955. list<dag> pattern>
  1956. : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
  1957. let OutOperandList = oops;
  1958. let InOperandList = iops;
  1959. let AsmString = !strconcat(opc, ".", dt, "\t", asm);
  1960. let Pattern = pattern;
  1961. list<Predicate> Predicates = [HasNEON];
  1962. let DecoderNamespace = "NEON";
  1963. let Inst{31-28} = 0b1111;
  1964. }
  1965. class NLdSt<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
  1966. dag oops, dag iops, InstrItinClass itin,
  1967. string opc, string dt, string asm, string cstr, list<dag> pattern>
  1968. : NeonI<oops, iops, AddrMode6, IndexModeNone, NLdStFrm, itin, opc, dt, asm,
  1969. cstr, pattern> {
  1970. let Inst{31-24} = 0b11110100;
  1971. let Inst{23} = op23;
  1972. let Inst{21-20} = op21_20;
  1973. let Inst{11-8} = op11_8;
  1974. let Inst{7-4} = op7_4;
  1975. let PostEncoderMethod = "NEONThumb2LoadStorePostEncoder";
  1976. let DecoderNamespace = "NEONLoadStore";
  1977. bits<5> Vd;
  1978. bits<6> Rn;
  1979. bits<4> Rm;
  1980. let Inst{22} = Vd{4};
  1981. let Inst{15-12} = Vd{3-0};
  1982. let Inst{19-16} = Rn{3-0};
  1983. let Inst{3-0} = Rm{3-0};
  1984. }
  1985. class NLdStLn<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
  1986. dag oops, dag iops, InstrItinClass itin,
  1987. string opc, string dt, string asm, string cstr, list<dag> pattern>
  1988. : NLdSt<op23, op21_20, op11_8, op7_4, oops, iops, itin, opc,
  1989. dt, asm, cstr, pattern> {
  1990. bits<3> lane;
  1991. }
  1992. class PseudoNLdSt<dag oops, dag iops, InstrItinClass itin, string cstr>
  1993. : InstARM<AddrMode6, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
  1994. itin> {
  1995. let OutOperandList = oops;
  1996. let InOperandList = !con(iops, (ins pred:$p));
  1997. list<Predicate> Predicates = [HasNEON];
  1998. }
  1999. class PseudoNeonI<dag oops, dag iops, InstrItinClass itin, string cstr,
  2000. list<dag> pattern>
  2001. : InstARM<AddrModeNone, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
  2002. itin> {
  2003. let OutOperandList = oops;
  2004. let InOperandList = !con(iops, (ins pred:$p));
  2005. let Pattern = pattern;
  2006. list<Predicate> Predicates = [HasNEON];
  2007. }
  2008. class NDataI<dag oops, dag iops, Format f, InstrItinClass itin,
  2009. string opc, string dt, string asm, string cstr, list<dag> pattern>
  2010. : NeonI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, dt, asm, cstr,
  2011. pattern> {
  2012. let Inst{31-25} = 0b1111001;
  2013. let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
  2014. let DecoderNamespace = "NEONData";
  2015. }
  2016. class NDataXI<dag oops, dag iops, Format f, InstrItinClass itin,
  2017. string opc, string asm, string cstr, list<dag> pattern>
  2018. : NeonXI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, asm,
  2019. cstr, pattern> {
  2020. let Inst{31-25} = 0b1111001;
  2021. let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
  2022. let DecoderNamespace = "NEONData";
  2023. }
  2024. // NEON "one register and a modified immediate" format.
  2025. class N1ModImm<bit op23, bits<3> op21_19, bits<4> op11_8, bit op7, bit op6,
  2026. bit op5, bit op4,
  2027. dag oops, dag iops, InstrItinClass itin,
  2028. string opc, string dt, string asm, string cstr,
  2029. list<dag> pattern>
  2030. : NDataI<oops, iops, N1RegModImmFrm, itin, opc, dt, asm, cstr, pattern> {
  2031. let Inst{23} = op23;
  2032. let Inst{21-19} = op21_19;
  2033. let Inst{11-8} = op11_8;
  2034. let Inst{7} = op7;
  2035. let Inst{6} = op6;
  2036. let Inst{5} = op5;
  2037. let Inst{4} = op4;
  2038. // Instruction operands.
  2039. bits<5> Vd;
  2040. bits<13> SIMM;
  2041. let Inst{15-12} = Vd{3-0};
  2042. let Inst{22} = Vd{4};
  2043. let Inst{24} = SIMM{7};
  2044. let Inst{18-16} = SIMM{6-4};
  2045. let Inst{3-0} = SIMM{3-0};
  2046. let DecoderMethod = "DecodeVMOVModImmInstruction";
  2047. }
  2048. // NEON 2 vector register format.
  2049. class N2V<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
  2050. bits<5> op11_7, bit op6, bit op4,
  2051. dag oops, dag iops, InstrItinClass itin,
  2052. string opc, string dt, string asm, string cstr, list<dag> pattern>
  2053. : NDataI<oops, iops, N2RegFrm, itin, opc, dt, asm, cstr, pattern> {
  2054. let Inst{24-23} = op24_23;
  2055. let Inst{21-20} = op21_20;
  2056. let Inst{19-18} = op19_18;
  2057. let Inst{17-16} = op17_16;
  2058. let Inst{11-7} = op11_7;
  2059. let Inst{6} = op6;
  2060. let Inst{4} = op4;
  2061. // Instruction operands.
  2062. bits<5> Vd;
  2063. bits<5> Vm;
  2064. let Inst{15-12} = Vd{3-0};
  2065. let Inst{22} = Vd{4};
  2066. let Inst{3-0} = Vm{3-0};
  2067. let Inst{5} = Vm{4};
  2068. }
  2069. // Same as N2V but not predicated.
  2070. class N2Vnp<bits<2> op19_18, bits<2> op17_16, bits<3> op10_8, bit op7, bit op6,
  2071. dag oops, dag iops, InstrItinClass itin, string OpcodeStr,
  2072. string Dt, list<dag> pattern>
  2073. : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N2RegFrm, itin,
  2074. OpcodeStr, Dt, "$Vd, $Vm", "", pattern> {
  2075. bits<5> Vd;
  2076. bits<5> Vm;
  2077. // Encode instruction operands
  2078. let Inst{22} = Vd{4};
  2079. let Inst{15-12} = Vd{3-0};
  2080. let Inst{5} = Vm{4};
  2081. let Inst{3-0} = Vm{3-0};
  2082. // Encode constant bits
  2083. let Inst{27-23} = 0b00111;
  2084. let Inst{21-20} = 0b11;
  2085. let Inst{19-18} = op19_18;
  2086. let Inst{17-16} = op17_16;
  2087. let Inst{11} = 0;
  2088. let Inst{10-8} = op10_8;
  2089. let Inst{7} = op7;
  2090. let Inst{6} = op6;
  2091. let Inst{4} = 0;
  2092. let DecoderNamespace = "NEON";
  2093. }
  2094. // Same as N2V except it doesn't have a datatype suffix.
  2095. class N2VX<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
  2096. bits<5> op11_7, bit op6, bit op4,
  2097. dag oops, dag iops, InstrItinClass itin,
  2098. string opc, string asm, string cstr, list<dag> pattern>
  2099. : NDataXI<oops, iops, N2RegFrm, itin, opc, asm, cstr, pattern> {
  2100. let Inst{24-23} = op24_23;
  2101. let Inst{21-20} = op21_20;
  2102. let Inst{19-18} = op19_18;
  2103. let Inst{17-16} = op17_16;
  2104. let Inst{11-7} = op11_7;
  2105. let Inst{6} = op6;
  2106. let Inst{4} = op4;
  2107. // Instruction operands.
  2108. bits<5> Vd;
  2109. bits<5> Vm;
  2110. let Inst{15-12} = Vd{3-0};
  2111. let Inst{22} = Vd{4};
  2112. let Inst{3-0} = Vm{3-0};
  2113. let Inst{5} = Vm{4};
  2114. }
  2115. // NEON 2 vector register with immediate.
  2116. class N2VImm<bit op24, bit op23, bits<4> op11_8, bit op7, bit op6, bit op4,
  2117. dag oops, dag iops, Format f, InstrItinClass itin,
  2118. string opc, string dt, string asm, string cstr, list<dag> pattern>
  2119. : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
  2120. let Inst{24} = op24;
  2121. let Inst{23} = op23;
  2122. let Inst{11-8} = op11_8;
  2123. let Inst{7} = op7;
  2124. let Inst{6} = op6;
  2125. let Inst{4} = op4;
  2126. // Instruction operands.
  2127. bits<5> Vd;
  2128. bits<5> Vm;
  2129. bits<6> SIMM;
  2130. let Inst{15-12} = Vd{3-0};
  2131. let Inst{22} = Vd{4};
  2132. let Inst{3-0} = Vm{3-0};
  2133. let Inst{5} = Vm{4};
  2134. let Inst{21-16} = SIMM{5-0};
  2135. }
  2136. // NEON 3 vector register format.
  2137. class N3VCommon<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
  2138. bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
  2139. string opc, string dt, string asm, string cstr,
  2140. list<dag> pattern>
  2141. : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
  2142. let Inst{24} = op24;
  2143. let Inst{23} = op23;
  2144. let Inst{21-20} = op21_20;
  2145. let Inst{11-8} = op11_8;
  2146. let Inst{6} = op6;
  2147. let Inst{4} = op4;
  2148. }
  2149. class N3V<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6, bit op4,
  2150. dag oops, dag iops, Format f, InstrItinClass itin,
  2151. string opc, string dt, string asm, string cstr, list<dag> pattern>
  2152. : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
  2153. oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
  2154. // Instruction operands.
  2155. bits<5> Vd;
  2156. bits<5> Vn;
  2157. bits<5> Vm;
  2158. let Inst{15-12} = Vd{3-0};
  2159. let Inst{22} = Vd{4};
  2160. let Inst{19-16} = Vn{3-0};
  2161. let Inst{7} = Vn{4};
  2162. let Inst{3-0} = Vm{3-0};
  2163. let Inst{5} = Vm{4};
  2164. }
  2165. class N3Vnp<bits<5> op27_23, bits<2> op21_20, bits<4> op11_8, bit op6,
  2166. bit op4, dag oops, dag iops,Format f, InstrItinClass itin,
  2167. string OpcodeStr, string Dt, list<dag> pattern>
  2168. : NeonInp<oops, iops, AddrModeNone, IndexModeNone, f, itin, OpcodeStr,
  2169. Dt, "$Vd, $Vn, $Vm", "", pattern> {
  2170. bits<5> Vd;
  2171. bits<5> Vn;
  2172. bits<5> Vm;
  2173. // Encode instruction operands
  2174. let Inst{22} = Vd{4};
  2175. let Inst{15-12} = Vd{3-0};
  2176. let Inst{19-16} = Vn{3-0};
  2177. let Inst{7} = Vn{4};
  2178. let Inst{5} = Vm{4};
  2179. let Inst{3-0} = Vm{3-0};
  2180. // Encode constant bits
  2181. let Inst{27-23} = op27_23;
  2182. let Inst{21-20} = op21_20;
  2183. let Inst{11-8} = op11_8;
  2184. let Inst{6} = op6;
  2185. let Inst{4} = op4;
  2186. }
  2187. class N3VLane32<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
  2188. bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
  2189. string opc, string dt, string asm, string cstr,
  2190. list<dag> pattern>
  2191. : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
  2192. oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
  2193. // Instruction operands.
  2194. bits<5> Vd;
  2195. bits<5> Vn;
  2196. bits<5> Vm;
  2197. bit lane;
  2198. let Inst{15-12} = Vd{3-0};
  2199. let Inst{22} = Vd{4};
  2200. let Inst{19-16} = Vn{3-0};
  2201. let Inst{7} = Vn{4};
  2202. let Inst{3-0} = Vm{3-0};
  2203. let Inst{5} = lane;
  2204. }
  2205. class N3VLane16<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
  2206. bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
  2207. string opc, string dt, string asm, string cstr,
  2208. list<dag> pattern>
  2209. : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
  2210. oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
  2211. // Instruction operands.
  2212. bits<5> Vd;
  2213. bits<5> Vn;
  2214. bits<5> Vm;
  2215. bits<2> lane;
  2216. let Inst{15-12} = Vd{3-0};
  2217. let Inst{22} = Vd{4};
  2218. let Inst{19-16} = Vn{3-0};
  2219. let Inst{7} = Vn{4};
  2220. let Inst{2-0} = Vm{2-0};
  2221. let Inst{5} = lane{1};
  2222. let Inst{3} = lane{0};
  2223. }
  2224. // Same as N3V except it doesn't have a data type suffix.
  2225. class N3VX<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
  2226. bit op4,
  2227. dag oops, dag iops, Format f, InstrItinClass itin,
  2228. string opc, string asm, string cstr, list<dag> pattern>
  2229. : NDataXI<oops, iops, f, itin, opc, asm, cstr, pattern> {
  2230. let Inst{24} = op24;
  2231. let Inst{23} = op23;
  2232. let Inst{21-20} = op21_20;
  2233. let Inst{11-8} = op11_8;
  2234. let Inst{6} = op6;
  2235. let Inst{4} = op4;
  2236. // Instruction operands.
  2237. bits<5> Vd;
  2238. bits<5> Vn;
  2239. bits<5> Vm;
  2240. let Inst{15-12} = Vd{3-0};
  2241. let Inst{22} = Vd{4};
  2242. let Inst{19-16} = Vn{3-0};
  2243. let Inst{7} = Vn{4};
  2244. let Inst{3-0} = Vm{3-0};
  2245. let Inst{5} = Vm{4};
  2246. }
  2247. // NEON VMOVs between scalar and core registers.
  2248. class NVLaneOp<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
  2249. dag oops, dag iops, Format f, InstrItinClass itin,
  2250. string opc, string dt, string asm, list<dag> pattern>
  2251. : InstARM<AddrModeNone, 4, IndexModeNone, f, NeonDomain,
  2252. "", itin> {
  2253. let Inst{27-20} = opcod1;
  2254. let Inst{11-8} = opcod2;
  2255. let Inst{6-5} = opcod3;
  2256. let Inst{4} = 1;
  2257. // A8.6.303, A8.6.328, A8.6.329
  2258. let Inst{3-0} = 0b0000;
  2259. let OutOperandList = oops;
  2260. let InOperandList = !con(iops, (ins pred:$p));
  2261. let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
  2262. let Pattern = pattern;
  2263. list<Predicate> Predicates = [HasNEON];
  2264. let PostEncoderMethod = "NEONThumb2DupPostEncoder";
  2265. let DecoderNamespace = "NEONDup";
  2266. bits<5> V;
  2267. bits<4> R;
  2268. bits<4> p;
  2269. bits<4> lane;
  2270. let Inst{31-28} = p{3-0};
  2271. let Inst{7} = V{4};
  2272. let Inst{19-16} = V{3-0};
  2273. let Inst{15-12} = R{3-0};
  2274. }
  2275. class NVGetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
  2276. dag oops, dag iops, InstrItinClass itin,
  2277. string opc, string dt, string asm, list<dag> pattern>
  2278. : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NGetLnFrm, itin,
  2279. opc, dt, asm, pattern>;
  2280. class NVSetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
  2281. dag oops, dag iops, InstrItinClass itin,
  2282. string opc, string dt, string asm, list<dag> pattern>
  2283. : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NSetLnFrm, itin,
  2284. opc, dt, asm, pattern>;
  2285. class NVDup<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
  2286. dag oops, dag iops, InstrItinClass itin,
  2287. string opc, string dt, string asm, list<dag> pattern>
  2288. : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NDupFrm, itin,
  2289. opc, dt, asm, pattern>;
  2290. // Vector Duplicate Lane (from scalar to all elements)
  2291. class NVDupLane<bits<4> op19_16, bit op6, dag oops, dag iops,
  2292. InstrItinClass itin, string opc, string dt, string asm,
  2293. list<dag> pattern>
  2294. : NDataI<oops, iops, NVDupLnFrm, itin, opc, dt, asm, "", pattern> {
  2295. let Inst{24-23} = 0b11;
  2296. let Inst{21-20} = 0b11;
  2297. let Inst{19-16} = op19_16;
  2298. let Inst{11-7} = 0b11000;
  2299. let Inst{6} = op6;
  2300. let Inst{4} = 0;
  2301. bits<5> Vd;
  2302. bits<5> Vm;
  2303. let Inst{22} = Vd{4};
  2304. let Inst{15-12} = Vd{3-0};
  2305. let Inst{5} = Vm{4};
  2306. let Inst{3-0} = Vm{3-0};
  2307. }
  2308. // NEONFPPat - Same as Pat<>, but requires that the compiler be using NEON
  2309. // for single-precision FP.
  2310. class NEONFPPat<dag pattern, dag result> : Pat<pattern, result> {
  2311. list<Predicate> Predicates = [HasNEON,UseNEONForFP];
  2312. }
  2313. // VFP/NEON Instruction aliases for type suffices.
  2314. // Note: When EmitPriority == 1, the alias will be used for printing
  2315. class VFPDataTypeInstAlias<string opc, string dt, string asm, dag Result, bit EmitPriority = 0> :
  2316. InstAlias<!strconcat(opc, dt, "\t", asm), Result, EmitPriority>, Requires<[HasFPRegs]>;
  2317. // Note: When EmitPriority == 1, the alias will be used for printing
  2318. multiclass VFPDTAnyInstAlias<string opc, string asm, dag Result, bit EmitPriority = 0> {
  2319. def : VFPDataTypeInstAlias<opc, ".8", asm, Result, EmitPriority>;
  2320. def : VFPDataTypeInstAlias<opc, ".16", asm, Result, EmitPriority>;
  2321. def : VFPDataTypeInstAlias<opc, ".32", asm, Result, EmitPriority>;
  2322. def : VFPDataTypeInstAlias<opc, ".64", asm, Result, EmitPriority>;
  2323. }
  2324. // Note: When EmitPriority == 1, the alias will be used for printing
  2325. multiclass NEONDTAnyInstAlias<string opc, string asm, dag Result, bit EmitPriority = 0> {
  2326. let Predicates = [HasNEON] in {
  2327. def : VFPDataTypeInstAlias<opc, ".8", asm, Result, EmitPriority>;
  2328. def : VFPDataTypeInstAlias<opc, ".16", asm, Result, EmitPriority>;
  2329. def : VFPDataTypeInstAlias<opc, ".32", asm, Result, EmitPriority>;
  2330. def : VFPDataTypeInstAlias<opc, ".64", asm, Result, EmitPriority>;
  2331. }
  2332. }
  2333. // The same alias classes using AsmPseudo instead, for the more complex
  2334. // stuff in NEON that InstAlias can't quite handle.
  2335. // Note that we can't use anonymous defm references here like we can
  2336. // above, as we care about the ultimate instruction enum names generated, unlike
  2337. // for instalias defs.
  2338. class NEONDataTypeAsmPseudoInst<string opc, string dt, string asm, dag iops> :
  2339. AsmPseudoInst<!strconcat(opc, dt, "\t", asm), iops>, Requires<[HasNEON]>;
  2340. // Extension of NEON 3-vector data processing instructions in coprocessor 8
  2341. // encoding space, introduced in ARMv8.3-A.
  2342. class N3VCP8<bits<2> op24_23, bits<2> op21_20, bit op6, bit op4,
  2343. dag oops, dag iops, InstrItinClass itin,
  2344. string opc, string dt, string asm, string cstr, list<dag> pattern>
  2345. : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N3RegCplxFrm, itin, opc,
  2346. dt, asm, cstr, pattern> {
  2347. bits<5> Vd;
  2348. bits<5> Vn;
  2349. bits<5> Vm;
  2350. let DecoderNamespace = "VFPV8";
  2351. // These have the same encodings in ARM and Thumb2
  2352. let PostEncoderMethod = "";
  2353. let Inst{31-25} = 0b1111110;
  2354. let Inst{24-23} = op24_23;
  2355. let Inst{22} = Vd{4};
  2356. let Inst{21-20} = op21_20;
  2357. let Inst{19-16} = Vn{3-0};
  2358. let Inst{15-12} = Vd{3-0};
  2359. let Inst{11-8} = 0b1000;
  2360. let Inst{7} = Vn{4};
  2361. let Inst{6} = op6;
  2362. let Inst{5} = Vm{4};
  2363. let Inst{4} = op4;
  2364. let Inst{3-0} = Vm{3-0};
  2365. }
  2366. // Extension of NEON 2-vector-and-scalar data processing instructions in
  2367. // coprocessor 8 encoding space, introduced in ARMv8.3-A.
  2368. class N3VLaneCP8<bit op23, bits<2> op21_20, bit op6, bit op4,
  2369. dag oops, dag iops, InstrItinClass itin,
  2370. string opc, string dt, string asm, string cstr, list<dag> pattern>
  2371. : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N3RegCplxFrm, itin, opc,
  2372. dt, asm, cstr, pattern> {
  2373. bits<5> Vd;
  2374. bits<5> Vn;
  2375. bits<5> Vm;
  2376. let DecoderNamespace = "VFPV8";
  2377. // These have the same encodings in ARM and Thumb2
  2378. let PostEncoderMethod = "";
  2379. let Inst{31-24} = 0b11111110;
  2380. let Inst{23} = op23;
  2381. let Inst{22} = Vd{4};
  2382. let Inst{21-20} = op21_20;
  2383. let Inst{19-16} = Vn{3-0};
  2384. let Inst{15-12} = Vd{3-0};
  2385. let Inst{11-8} = 0b1000;
  2386. let Inst{7} = Vn{4};
  2387. let Inst{6} = op6;
  2388. // Bit 5 set by sub-classes
  2389. let Inst{4} = op4;
  2390. let Inst{3-0} = Vm{3-0};
  2391. }
  2392. // In Armv8.2-A, some NEON instructions are added that encode Vn and Vm
  2393. // differently:
  2394. // if Q == ‘1’ then UInt(N:Vn) else UInt(Vn:N);
  2395. // if Q == ‘1’ then UInt(M:Vm) else UInt(Vm:M);
  2396. // Class N3VCP8 above describes the Q=1 case, and this class the Q=0 case.
  2397. class N3VCP8Q0<bits<2> op24_23, bits<2> op21_20, bit op6, bit op4,
  2398. dag oops, dag iops, InstrItinClass itin,
  2399. string opc, string dt, string asm, string cstr, list<dag> pattern>
  2400. : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N3RegCplxFrm, itin, opc, dt, asm, cstr, pattern> {
  2401. bits<5> Vd;
  2402. bits<5> Vn;
  2403. bits<5> Vm;
  2404. let DecoderNamespace = "VFPV8";
  2405. // These have the same encodings in ARM and Thumb2
  2406. let PostEncoderMethod = "";
  2407. let Inst{31-25} = 0b1111110;
  2408. let Inst{24-23} = op24_23;
  2409. let Inst{22} = Vd{4};
  2410. let Inst{21-20} = op21_20;
  2411. let Inst{19-16} = Vn{4-1};
  2412. let Inst{15-12} = Vd{3-0};
  2413. let Inst{11-8} = 0b1000;
  2414. let Inst{7} = Vn{0};
  2415. let Inst{6} = op6;
  2416. let Inst{5} = Vm{0};
  2417. let Inst{4} = op4;
  2418. let Inst{3-0} = Vm{4-1};
  2419. }
  2420. // Operand types for complex instructions
  2421. class ComplexRotationOperand<int Angle, int Remainder, string Type, string Diag>
  2422. : AsmOperandClass {
  2423. let PredicateMethod = "isComplexRotation<" # Angle # ", " # Remainder # ">";
  2424. let DiagnosticString = "complex rotation must be " # Diag;
  2425. let Name = "ComplexRotation" # Type;
  2426. }
  2427. def complexrotateop : Operand<i32> {
  2428. let ParserMatchClass = ComplexRotationOperand<90, 0, "Even", "0, 90, 180 or 270">;
  2429. let PrintMethod = "printComplexRotationOp<90, 0>";
  2430. }
  2431. def complexrotateopodd : Operand<i32> {
  2432. let ParserMatchClass = ComplexRotationOperand<180, 90, "Odd", "90 or 270">;
  2433. let PrintMethod = "printComplexRotationOp<180, 90>";
  2434. }
  2435. def MveSaturateOperand : AsmOperandClass {
  2436. let PredicateMethod = "isMveSaturateOp";
  2437. let DiagnosticString = "saturate operand must be 48 or 64";
  2438. let Name = "MveSaturate";
  2439. }
  2440. def saturateop : Operand<i32> {
  2441. let ParserMatchClass = MveSaturateOperand;
  2442. let PrintMethod = "printMveSaturateOp";
  2443. }
  2444. // Data type suffix token aliases. Implements Table A7-3 in the ARM ARM.
  2445. def : TokenAlias<".s8", ".i8">;
  2446. def : TokenAlias<".u8", ".i8">;
  2447. def : TokenAlias<".s16", ".i16">;
  2448. def : TokenAlias<".u16", ".i16">;
  2449. def : TokenAlias<".s32", ".i32">;
  2450. def : TokenAlias<".u32", ".i32">;
  2451. def : TokenAlias<".s64", ".i64">;
  2452. def : TokenAlias<".u64", ".i64">;
  2453. def : TokenAlias<".i8", ".8">;
  2454. def : TokenAlias<".i16", ".16">;
  2455. def : TokenAlias<".i32", ".32">;
  2456. def : TokenAlias<".i64", ".64">;
  2457. def : TokenAlias<".p8", ".8">;
  2458. def : TokenAlias<".p16", ".16">;
  2459. def : TokenAlias<".f32", ".32">;
  2460. def : TokenAlias<".f64", ".64">;
  2461. def : TokenAlias<".f", ".f32">;
  2462. def : TokenAlias<".d", ".f64">;