1 //===- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions -------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "ARMBaseInstrInfo.h" 10 #include "ARMFeatures.h" 11 #include "MCTargetDesc/ARMAddressingModes.h" 12 #include "MCTargetDesc/ARMBaseInfo.h" 13 #include "MCTargetDesc/ARMInstPrinter.h" 14 #include "MCTargetDesc/ARMMCExpr.h" 15 #include "MCTargetDesc/ARMMCTargetDesc.h" 16 #include "TargetInfo/ARMTargetInfo.h" 17 #include "Utils/ARMBaseInfo.h" 18 #include "llvm/ADT/APFloat.h" 19 #include "llvm/ADT/APInt.h" 20 #include "llvm/ADT/None.h" 21 #include "llvm/ADT/STLExtras.h" 22 #include "llvm/ADT/SmallSet.h" 23 #include "llvm/ADT/SmallVector.h" 24 #include "llvm/ADT/StringMap.h" 25 #include "llvm/ADT/StringRef.h" 26 #include "llvm/ADT/StringSet.h" 27 #include "llvm/ADT/StringSwitch.h" 28 #include "llvm/ADT/Triple.h" 29 #include "llvm/ADT/Twine.h" 30 #include "llvm/MC/MCContext.h" 31 #include "llvm/MC/MCExpr.h" 32 #include "llvm/MC/MCInst.h" 33 #include "llvm/MC/MCInstrDesc.h" 34 #include "llvm/MC/MCInstrInfo.h" 35 #include "llvm/MC/MCParser/MCAsmLexer.h" 36 #include "llvm/MC/MCParser/MCAsmParser.h" 37 #include "llvm/MC/MCParser/MCAsmParserExtension.h" 38 #include "llvm/MC/MCParser/MCAsmParserUtils.h" 39 #include "llvm/MC/MCParser/MCParsedAsmOperand.h" 40 #include "llvm/MC/MCParser/MCTargetAsmParser.h" 41 #include "llvm/MC/MCRegisterInfo.h" 42 #include "llvm/MC/MCSection.h" 43 #include "llvm/MC/MCStreamer.h" 44 #include "llvm/MC/MCSubtargetInfo.h" 45 #include "llvm/MC/MCSymbol.h" 46 #include "llvm/MC/SubtargetFeature.h" 47 #include "llvm/MC/TargetRegistry.h" 48 #include "llvm/Support/ARMBuildAttributes.h" 49 #include "llvm/Support/ARMEHABI.h" 50 #include "llvm/Support/Casting.h" 51 #include "llvm/Support/CommandLine.h" 52 #include "llvm/Support/Compiler.h" 53 #include "llvm/Support/ErrorHandling.h" 54 #include "llvm/Support/MathExtras.h" 55 #include "llvm/Support/SMLoc.h" 56 #include "llvm/Support/TargetParser.h" 57 #include "llvm/Support/raw_ostream.h" 58 #include <algorithm> 59 #include <cassert> 60 #include <cstddef> 61 #include <cstdint> 62 #include <iterator> 63 #include <limits> 64 #include <memory> 65 #include <string> 66 #include <utility> 67 #include <vector> 68 69 #define DEBUG_TYPE "asm-parser" 70 71 using namespace llvm; 72 73 namespace llvm { 74 extern const MCInstrDesc ARMInsts[]; 75 } // end namespace llvm 76 77 namespace { 78 79 enum class ImplicitItModeTy { Always, Never, ARMOnly, ThumbOnly }; 80 81 static cl::opt<ImplicitItModeTy> ImplicitItMode( 82 "arm-implicit-it", cl::init(ImplicitItModeTy::ARMOnly), 83 cl::desc("Allow conditional instructions outdside of an IT block"), 84 cl::values(clEnumValN(ImplicitItModeTy::Always, "always", 85 "Accept in both ISAs, emit implicit ITs in Thumb"), 86 clEnumValN(ImplicitItModeTy::Never, "never", 87 "Warn in ARM, reject in Thumb"), 88 clEnumValN(ImplicitItModeTy::ARMOnly, "arm", 89 "Accept in ARM, reject in Thumb"), 90 clEnumValN(ImplicitItModeTy::ThumbOnly, "thumb", 91 "Warn in ARM, emit implicit ITs in Thumb"))); 92 93 static cl::opt<bool> AddBuildAttributes("arm-add-build-attributes", 94 cl::init(false)); 95 96 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane }; 97 98 static inline unsigned extractITMaskBit(unsigned Mask, unsigned Position) { 99 // Position==0 means we're not in an IT block at all. Position==1 100 // means we want the first state bit, which is always 0 (Then). 101 // Position==2 means we want the second state bit, stored at bit 3 102 // of Mask, and so on downwards. So (5 - Position) will shift the 103 // right bit down to bit 0, including the always-0 bit at bit 4 for 104 // the mandatory initial Then. 105 return (Mask >> (5 - Position) & 1); 106 } 107 108 class UnwindContext { 109 using Locs = SmallVector<SMLoc, 4>; 110 111 MCAsmParser &Parser; 112 Locs FnStartLocs; 113 Locs CantUnwindLocs; 114 Locs PersonalityLocs; 115 Locs PersonalityIndexLocs; 116 Locs HandlerDataLocs; 117 int FPReg; 118 119 public: 120 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {} 121 122 bool hasFnStart() const { return !FnStartLocs.empty(); } 123 bool cantUnwind() const { return !CantUnwindLocs.empty(); } 124 bool hasHandlerData() const { return !HandlerDataLocs.empty(); } 125 126 bool hasPersonality() const { 127 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty()); 128 } 129 130 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); } 131 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); } 132 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); } 133 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); } 134 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); } 135 136 void saveFPReg(int Reg) { FPReg = Reg; } 137 int getFPReg() const { return FPReg; } 138 139 void emitFnStartLocNotes() const { 140 for (const SMLoc &Loc : FnStartLocs) 141 Parser.Note(Loc, ".fnstart was specified here"); 142 } 143 144 void emitCantUnwindLocNotes() const { 145 for (const SMLoc &Loc : CantUnwindLocs) 146 Parser.Note(Loc, ".cantunwind was specified here"); 147 } 148 149 void emitHandlerDataLocNotes() const { 150 for (const SMLoc &Loc : HandlerDataLocs) 151 Parser.Note(Loc, ".handlerdata was specified here"); 152 } 153 154 void emitPersonalityLocNotes() const { 155 for (Locs::const_iterator PI = PersonalityLocs.begin(), 156 PE = PersonalityLocs.end(), 157 PII = PersonalityIndexLocs.begin(), 158 PIE = PersonalityIndexLocs.end(); 159 PI != PE || PII != PIE;) { 160 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer())) 161 Parser.Note(*PI++, ".personality was specified here"); 162 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer())) 163 Parser.Note(*PII++, ".personalityindex was specified here"); 164 else 165 llvm_unreachable(".personality and .personalityindex cannot be " 166 "at the same location"); 167 } 168 } 169 170 void reset() { 171 FnStartLocs = Locs(); 172 CantUnwindLocs = Locs(); 173 PersonalityLocs = Locs(); 174 HandlerDataLocs = Locs(); 175 PersonalityIndexLocs = Locs(); 176 FPReg = ARM::SP; 177 } 178 }; 179 180 // Various sets of ARM instruction mnemonics which are used by the asm parser 181 class ARMMnemonicSets { 182 StringSet<> CDE; 183 StringSet<> CDEWithVPTSuffix; 184 public: 185 ARMMnemonicSets(const MCSubtargetInfo &STI); 186 187 /// Returns true iff a given mnemonic is a CDE instruction 188 bool isCDEInstr(StringRef Mnemonic) { 189 // Quick check before searching the set 190 if (!Mnemonic.startswith("cx") && !Mnemonic.startswith("vcx")) 191 return false; 192 return CDE.count(Mnemonic); 193 } 194 195 /// Returns true iff a given mnemonic is a VPT-predicable CDE instruction 196 /// (possibly with a predication suffix "e" or "t") 197 bool isVPTPredicableCDEInstr(StringRef Mnemonic) { 198 if (!Mnemonic.startswith("vcx")) 199 return false; 200 return CDEWithVPTSuffix.count(Mnemonic); 201 } 202 203 /// Returns true iff a given mnemonic is an IT-predicable CDE instruction 204 /// (possibly with a condition suffix) 205 bool isITPredicableCDEInstr(StringRef Mnemonic) { 206 if (!Mnemonic.startswith("cx")) 207 return false; 208 return Mnemonic.startswith("cx1a") || Mnemonic.startswith("cx1da") || 209 Mnemonic.startswith("cx2a") || Mnemonic.startswith("cx2da") || 210 Mnemonic.startswith("cx3a") || Mnemonic.startswith("cx3da"); 211 } 212 213 /// Return true iff a given mnemonic is an integer CDE instruction with 214 /// dual-register destination 215 bool isCDEDualRegInstr(StringRef Mnemonic) { 216 if (!Mnemonic.startswith("cx")) 217 return false; 218 return Mnemonic == "cx1d" || Mnemonic == "cx1da" || 219 Mnemonic == "cx2d" || Mnemonic == "cx2da" || 220 Mnemonic == "cx3d" || Mnemonic == "cx3da"; 221 } 222 }; 223 224 ARMMnemonicSets::ARMMnemonicSets(const MCSubtargetInfo &STI) { 225 for (StringRef Mnemonic: { "cx1", "cx1a", "cx1d", "cx1da", 226 "cx2", "cx2a", "cx2d", "cx2da", 227 "cx3", "cx3a", "cx3d", "cx3da", }) 228 CDE.insert(Mnemonic); 229 for (StringRef Mnemonic : 230 {"vcx1", "vcx1a", "vcx2", "vcx2a", "vcx3", "vcx3a"}) { 231 CDE.insert(Mnemonic); 232 CDEWithVPTSuffix.insert(Mnemonic); 233 CDEWithVPTSuffix.insert(std::string(Mnemonic) + "t"); 234 CDEWithVPTSuffix.insert(std::string(Mnemonic) + "e"); 235 } 236 } 237 238 class ARMAsmParser : public MCTargetAsmParser { 239 const MCRegisterInfo *MRI; 240 UnwindContext UC; 241 ARMMnemonicSets MS; 242 243 ARMTargetStreamer &getTargetStreamer() { 244 assert(getParser().getStreamer().getTargetStreamer() && 245 "do not have a target streamer"); 246 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer(); 247 return static_cast<ARMTargetStreamer &>(TS); 248 } 249 250 // Map of register aliases registers via the .req directive. 251 StringMap<unsigned> RegisterReqs; 252 253 bool NextSymbolIsThumb; 254 255 bool useImplicitITThumb() const { 256 return ImplicitItMode == ImplicitItModeTy::Always || 257 ImplicitItMode == ImplicitItModeTy::ThumbOnly; 258 } 259 260 bool useImplicitITARM() const { 261 return ImplicitItMode == ImplicitItModeTy::Always || 262 ImplicitItMode == ImplicitItModeTy::ARMOnly; 263 } 264 265 struct { 266 ARMCC::CondCodes Cond; // Condition for IT block. 267 unsigned Mask:4; // Condition mask for instructions. 268 // Starting at first 1 (from lsb). 269 // '1' condition as indicated in IT. 270 // '0' inverse of condition (else). 271 // Count of instructions in IT block is 272 // 4 - trailingzeroes(mask) 273 // Note that this does not have the same encoding 274 // as in the IT instruction, which also depends 275 // on the low bit of the condition code. 276 277 unsigned CurPosition; // Current position in parsing of IT 278 // block. In range [0,4], with 0 being the IT 279 // instruction itself. Initialized according to 280 // count of instructions in block. ~0U if no 281 // active IT block. 282 283 bool IsExplicit; // true - The IT instruction was present in the 284 // input, we should not modify it. 285 // false - The IT instruction was added 286 // implicitly, we can extend it if that 287 // would be legal. 288 } ITState; 289 290 SmallVector<MCInst, 4> PendingConditionalInsts; 291 292 void flushPendingInstructions(MCStreamer &Out) override { 293 if (!inImplicitITBlock()) { 294 assert(PendingConditionalInsts.size() == 0); 295 return; 296 } 297 298 // Emit the IT instruction 299 MCInst ITInst; 300 ITInst.setOpcode(ARM::t2IT); 301 ITInst.addOperand(MCOperand::createImm(ITState.Cond)); 302 ITInst.addOperand(MCOperand::createImm(ITState.Mask)); 303 Out.emitInstruction(ITInst, getSTI()); 304 305 // Emit the conditonal instructions 306 assert(PendingConditionalInsts.size() <= 4); 307 for (const MCInst &Inst : PendingConditionalInsts) { 308 Out.emitInstruction(Inst, getSTI()); 309 } 310 PendingConditionalInsts.clear(); 311 312 // Clear the IT state 313 ITState.Mask = 0; 314 ITState.CurPosition = ~0U; 315 } 316 317 bool inITBlock() { return ITState.CurPosition != ~0U; } 318 bool inExplicitITBlock() { return inITBlock() && ITState.IsExplicit; } 319 bool inImplicitITBlock() { return inITBlock() && !ITState.IsExplicit; } 320 321 bool lastInITBlock() { 322 return ITState.CurPosition == 4 - countTrailingZeros(ITState.Mask); 323 } 324 325 void forwardITPosition() { 326 if (!inITBlock()) return; 327 // Move to the next instruction in the IT block, if there is one. If not, 328 // mark the block as done, except for implicit IT blocks, which we leave 329 // open until we find an instruction that can't be added to it. 330 unsigned TZ = countTrailingZeros(ITState.Mask); 331 if (++ITState.CurPosition == 5 - TZ && ITState.IsExplicit) 332 ITState.CurPosition = ~0U; // Done with the IT block after this. 333 } 334 335 // Rewind the state of the current IT block, removing the last slot from it. 336 void rewindImplicitITPosition() { 337 assert(inImplicitITBlock()); 338 assert(ITState.CurPosition > 1); 339 ITState.CurPosition--; 340 unsigned TZ = countTrailingZeros(ITState.Mask); 341 unsigned NewMask = 0; 342 NewMask |= ITState.Mask & (0xC << TZ); 343 NewMask |= 0x2 << TZ; 344 ITState.Mask = NewMask; 345 } 346 347 // Rewind the state of the current IT block, removing the last slot from it. 348 // If we were at the first slot, this closes the IT block. 349 void discardImplicitITBlock() { 350 assert(inImplicitITBlock()); 351 assert(ITState.CurPosition == 1); 352 ITState.CurPosition = ~0U; 353 } 354 355 // Return the low-subreg of a given Q register. 356 unsigned getDRegFromQReg(unsigned QReg) const { 357 return MRI->getSubReg(QReg, ARM::dsub_0); 358 } 359 360 // Get the condition code corresponding to the current IT block slot. 361 ARMCC::CondCodes currentITCond() { 362 unsigned MaskBit = extractITMaskBit(ITState.Mask, ITState.CurPosition); 363 return MaskBit ? ARMCC::getOppositeCondition(ITState.Cond) : ITState.Cond; 364 } 365 366 // Invert the condition of the current IT block slot without changing any 367 // other slots in the same block. 368 void invertCurrentITCondition() { 369 if (ITState.CurPosition == 1) { 370 ITState.Cond = ARMCC::getOppositeCondition(ITState.Cond); 371 } else { 372 ITState.Mask ^= 1 << (5 - ITState.CurPosition); 373 } 374 } 375 376 // Returns true if the current IT block is full (all 4 slots used). 377 bool isITBlockFull() { 378 return inITBlock() && (ITState.Mask & 1); 379 } 380 381 // Extend the current implicit IT block to have one more slot with the given 382 // condition code. 383 void extendImplicitITBlock(ARMCC::CondCodes Cond) { 384 assert(inImplicitITBlock()); 385 assert(!isITBlockFull()); 386 assert(Cond == ITState.Cond || 387 Cond == ARMCC::getOppositeCondition(ITState.Cond)); 388 unsigned TZ = countTrailingZeros(ITState.Mask); 389 unsigned NewMask = 0; 390 // Keep any existing condition bits. 391 NewMask |= ITState.Mask & (0xE << TZ); 392 // Insert the new condition bit. 393 NewMask |= (Cond != ITState.Cond) << TZ; 394 // Move the trailing 1 down one bit. 395 NewMask |= 1 << (TZ - 1); 396 ITState.Mask = NewMask; 397 } 398 399 // Create a new implicit IT block with a dummy condition code. 400 void startImplicitITBlock() { 401 assert(!inITBlock()); 402 ITState.Cond = ARMCC::AL; 403 ITState.Mask = 8; 404 ITState.CurPosition = 1; 405 ITState.IsExplicit = false; 406 } 407 408 // Create a new explicit IT block with the given condition and mask. 409 // The mask should be in the format used in ARMOperand and 410 // MCOperand, with a 1 implying 'e', regardless of the low bit of 411 // the condition. 412 void startExplicitITBlock(ARMCC::CondCodes Cond, unsigned Mask) { 413 assert(!inITBlock()); 414 ITState.Cond = Cond; 415 ITState.Mask = Mask; 416 ITState.CurPosition = 0; 417 ITState.IsExplicit = true; 418 } 419 420 struct { 421 unsigned Mask : 4; 422 unsigned CurPosition; 423 } VPTState; 424 bool inVPTBlock() { return VPTState.CurPosition != ~0U; } 425 void forwardVPTPosition() { 426 if (!inVPTBlock()) return; 427 unsigned TZ = countTrailingZeros(VPTState.Mask); 428 if (++VPTState.CurPosition == 5 - TZ) 429 VPTState.CurPosition = ~0U; 430 } 431 432 void Note(SMLoc L, const Twine &Msg, SMRange Range = None) { 433 return getParser().Note(L, Msg, Range); 434 } 435 436 bool Warning(SMLoc L, const Twine &Msg, SMRange Range = None) { 437 return getParser().Warning(L, Msg, Range); 438 } 439 440 bool Error(SMLoc L, const Twine &Msg, SMRange Range = None) { 441 return getParser().Error(L, Msg, Range); 442 } 443 444 bool validatetLDMRegList(const MCInst &Inst, const OperandVector &Operands, 445 unsigned ListNo, bool IsARPop = false); 446 bool validatetSTMRegList(const MCInst &Inst, const OperandVector &Operands, 447 unsigned ListNo); 448 449 int tryParseRegister(); 450 bool tryParseRegisterWithWriteBack(OperandVector &); 451 int tryParseShiftRegister(OperandVector &); 452 bool parseRegisterList(OperandVector &, bool EnforceOrder = true, 453 bool AllowRAAC = false); 454 bool parseMemory(OperandVector &); 455 bool parseOperand(OperandVector &, StringRef Mnemonic); 456 bool parseImmExpr(int64_t &Out); 457 bool parsePrefix(ARMMCExpr::VariantKind &RefKind); 458 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType, 459 unsigned &ShiftAmount); 460 bool parseLiteralValues(unsigned Size, SMLoc L); 461 bool parseDirectiveThumb(SMLoc L); 462 bool parseDirectiveARM(SMLoc L); 463 bool parseDirectiveThumbFunc(SMLoc L); 464 bool parseDirectiveCode(SMLoc L); 465 bool parseDirectiveSyntax(SMLoc L); 466 bool parseDirectiveReq(StringRef Name, SMLoc L); 467 bool parseDirectiveUnreq(SMLoc L); 468 bool parseDirectiveArch(SMLoc L); 469 bool parseDirectiveEabiAttr(SMLoc L); 470 bool parseDirectiveCPU(SMLoc L); 471 bool parseDirectiveFPU(SMLoc L); 472 bool parseDirectiveFnStart(SMLoc L); 473 bool parseDirectiveFnEnd(SMLoc L); 474 bool parseDirectiveCantUnwind(SMLoc L); 475 bool parseDirectivePersonality(SMLoc L); 476 bool parseDirectiveHandlerData(SMLoc L); 477 bool parseDirectiveSetFP(SMLoc L); 478 bool parseDirectivePad(SMLoc L); 479 bool parseDirectiveRegSave(SMLoc L, bool IsVector); 480 bool parseDirectiveInst(SMLoc L, char Suffix = '\0'); 481 bool parseDirectiveLtorg(SMLoc L); 482 bool parseDirectiveEven(SMLoc L); 483 bool parseDirectivePersonalityIndex(SMLoc L); 484 bool parseDirectiveUnwindRaw(SMLoc L); 485 bool parseDirectiveTLSDescSeq(SMLoc L); 486 bool parseDirectiveMovSP(SMLoc L); 487 bool parseDirectiveObjectArch(SMLoc L); 488 bool parseDirectiveArchExtension(SMLoc L); 489 bool parseDirectiveAlign(SMLoc L); 490 bool parseDirectiveThumbSet(SMLoc L); 491 492 bool parseDirectiveSEHAllocStack(SMLoc L, bool Wide); 493 bool parseDirectiveSEHSaveRegs(SMLoc L, bool Wide); 494 bool parseDirectiveSEHSaveSP(SMLoc L); 495 bool parseDirectiveSEHSaveFRegs(SMLoc L); 496 bool parseDirectiveSEHSaveLR(SMLoc L); 497 bool parseDirectiveSEHPrologEnd(SMLoc L, bool Fragment); 498 bool parseDirectiveSEHNop(SMLoc L, bool Wide); 499 bool parseDirectiveSEHEpilogStart(SMLoc L, bool Condition); 500 bool parseDirectiveSEHEpilogEnd(SMLoc L); 501 bool parseDirectiveSEHCustom(SMLoc L); 502 503 bool isMnemonicVPTPredicable(StringRef Mnemonic, StringRef ExtraToken); 504 StringRef splitMnemonic(StringRef Mnemonic, StringRef ExtraToken, 505 unsigned &PredicationCode, 506 unsigned &VPTPredicationCode, bool &CarrySetting, 507 unsigned &ProcessorIMod, StringRef &ITMask); 508 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef ExtraToken, 509 StringRef FullInst, bool &CanAcceptCarrySet, 510 bool &CanAcceptPredicationCode, 511 bool &CanAcceptVPTPredicationCode); 512 bool enableArchExtFeature(StringRef Name, SMLoc &ExtLoc); 513 514 void tryConvertingToTwoOperandForm(StringRef Mnemonic, bool CarrySetting, 515 OperandVector &Operands); 516 bool CDEConvertDualRegOperand(StringRef Mnemonic, OperandVector &Operands); 517 518 bool isThumb() const { 519 // FIXME: Can tablegen auto-generate this? 520 return getSTI().getFeatureBits()[ARM::ModeThumb]; 521 } 522 523 bool isThumbOne() const { 524 return isThumb() && !getSTI().getFeatureBits()[ARM::FeatureThumb2]; 525 } 526 527 bool isThumbTwo() const { 528 return isThumb() && getSTI().getFeatureBits()[ARM::FeatureThumb2]; 529 } 530 531 bool hasThumb() const { 532 return getSTI().getFeatureBits()[ARM::HasV4TOps]; 533 } 534 535 bool hasThumb2() const { 536 return getSTI().getFeatureBits()[ARM::FeatureThumb2]; 537 } 538 539 bool hasV6Ops() const { 540 return getSTI().getFeatureBits()[ARM::HasV6Ops]; 541 } 542 543 bool hasV6T2Ops() const { 544 return getSTI().getFeatureBits()[ARM::HasV6T2Ops]; 545 } 546 547 bool hasV6MOps() const { 548 return getSTI().getFeatureBits()[ARM::HasV6MOps]; 549 } 550 551 bool hasV7Ops() const { 552 return getSTI().getFeatureBits()[ARM::HasV7Ops]; 553 } 554 555 bool hasV8Ops() const { 556 return getSTI().getFeatureBits()[ARM::HasV8Ops]; 557 } 558 559 bool hasV8MBaseline() const { 560 return getSTI().getFeatureBits()[ARM::HasV8MBaselineOps]; 561 } 562 563 bool hasV8MMainline() const { 564 return getSTI().getFeatureBits()[ARM::HasV8MMainlineOps]; 565 } 566 bool hasV8_1MMainline() const { 567 return getSTI().getFeatureBits()[ARM::HasV8_1MMainlineOps]; 568 } 569 bool hasMVE() const { 570 return getSTI().getFeatureBits()[ARM::HasMVEIntegerOps]; 571 } 572 bool hasMVEFloat() const { 573 return getSTI().getFeatureBits()[ARM::HasMVEFloatOps]; 574 } 575 bool hasCDE() const { 576 return getSTI().getFeatureBits()[ARM::HasCDEOps]; 577 } 578 bool has8MSecExt() const { 579 return getSTI().getFeatureBits()[ARM::Feature8MSecExt]; 580 } 581 582 bool hasARM() const { 583 return !getSTI().getFeatureBits()[ARM::FeatureNoARM]; 584 } 585 586 bool hasDSP() const { 587 return getSTI().getFeatureBits()[ARM::FeatureDSP]; 588 } 589 590 bool hasD32() const { 591 return getSTI().getFeatureBits()[ARM::FeatureD32]; 592 } 593 594 bool hasV8_1aOps() const { 595 return getSTI().getFeatureBits()[ARM::HasV8_1aOps]; 596 } 597 598 bool hasRAS() const { 599 return getSTI().getFeatureBits()[ARM::FeatureRAS]; 600 } 601 602 void SwitchMode() { 603 MCSubtargetInfo &STI = copySTI(); 604 auto FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb)); 605 setAvailableFeatures(FB); 606 } 607 608 void FixModeAfterArchChange(bool WasThumb, SMLoc Loc); 609 610 bool isMClass() const { 611 return getSTI().getFeatureBits()[ARM::FeatureMClass]; 612 } 613 614 /// @name Auto-generated Match Functions 615 /// { 616 617 #define GET_ASSEMBLER_HEADER 618 #include "ARMGenAsmMatcher.inc" 619 620 /// } 621 622 OperandMatchResultTy parseITCondCode(OperandVector &); 623 OperandMatchResultTy parseCoprocNumOperand(OperandVector &); 624 OperandMatchResultTy parseCoprocRegOperand(OperandVector &); 625 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &); 626 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &); 627 OperandMatchResultTy parseTraceSyncBarrierOptOperand(OperandVector &); 628 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &); 629 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &); 630 OperandMatchResultTy parseMSRMaskOperand(OperandVector &); 631 OperandMatchResultTy parseBankedRegOperand(OperandVector &); 632 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low, 633 int High); 634 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) { 635 return parsePKHImm(O, "lsl", 0, 31); 636 } 637 OperandMatchResultTy parsePKHASRImm(OperandVector &O) { 638 return parsePKHImm(O, "asr", 1, 32); 639 } 640 OperandMatchResultTy parseSetEndImm(OperandVector &); 641 OperandMatchResultTy parseShifterImm(OperandVector &); 642 OperandMatchResultTy parseRotImm(OperandVector &); 643 OperandMatchResultTy parseModImm(OperandVector &); 644 OperandMatchResultTy parseBitfield(OperandVector &); 645 OperandMatchResultTy parsePostIdxReg(OperandVector &); 646 OperandMatchResultTy parseAM3Offset(OperandVector &); 647 OperandMatchResultTy parseFPImm(OperandVector &); 648 OperandMatchResultTy parseVectorList(OperandVector &); 649 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, 650 SMLoc &EndLoc); 651 652 // Asm Match Converter Methods 653 void cvtThumbMultiply(MCInst &Inst, const OperandVector &); 654 void cvtThumbBranches(MCInst &Inst, const OperandVector &); 655 void cvtMVEVMOVQtoDReg(MCInst &Inst, const OperandVector &); 656 657 bool validateInstruction(MCInst &Inst, const OperandVector &Ops); 658 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out); 659 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands); 660 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands); 661 bool shouldOmitVectorPredicateOperand(StringRef Mnemonic, OperandVector &Operands); 662 bool isITBlockTerminator(MCInst &Inst) const; 663 void fixupGNULDRDAlias(StringRef Mnemonic, OperandVector &Operands); 664 bool validateLDRDSTRD(MCInst &Inst, const OperandVector &Operands, 665 bool Load, bool ARMMode, bool Writeback); 666 667 public: 668 enum ARMMatchResultTy { 669 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY, 670 Match_RequiresNotITBlock, 671 Match_RequiresV6, 672 Match_RequiresThumb2, 673 Match_RequiresV8, 674 Match_RequiresFlagSetting, 675 #define GET_OPERAND_DIAGNOSTIC_TYPES 676 #include "ARMGenAsmMatcher.inc" 677 678 }; 679 680 ARMAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, 681 const MCInstrInfo &MII, const MCTargetOptions &Options) 682 : MCTargetAsmParser(Options, STI, MII), UC(Parser), MS(STI) { 683 MCAsmParserExtension::Initialize(Parser); 684 685 // Cache the MCRegisterInfo. 686 MRI = getContext().getRegisterInfo(); 687 688 // Initialize the set of available features. 689 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 690 691 // Add build attributes based on the selected target. 692 if (AddBuildAttributes) 693 getTargetStreamer().emitTargetAttributes(STI); 694 695 // Not in an ITBlock to start with. 696 ITState.CurPosition = ~0U; 697 698 VPTState.CurPosition = ~0U; 699 700 NextSymbolIsThumb = false; 701 } 702 703 // Implementation of the MCTargetAsmParser interface: 704 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override; 705 OperandMatchResultTy tryParseRegister(unsigned &RegNo, SMLoc &StartLoc, 706 SMLoc &EndLoc) override; 707 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, 708 SMLoc NameLoc, OperandVector &Operands) override; 709 bool ParseDirective(AsmToken DirectiveID) override; 710 711 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, 712 unsigned Kind) override; 713 unsigned checkTargetMatchPredicate(MCInst &Inst) override; 714 715 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, 716 OperandVector &Operands, MCStreamer &Out, 717 uint64_t &ErrorInfo, 718 bool MatchingInlineAsm) override; 719 unsigned MatchInstruction(OperandVector &Operands, MCInst &Inst, 720 SmallVectorImpl<NearMissInfo> &NearMisses, 721 bool MatchingInlineAsm, bool &EmitInITBlock, 722 MCStreamer &Out); 723 724 struct NearMissMessage { 725 SMLoc Loc; 726 SmallString<128> Message; 727 }; 728 729 const char *getCustomOperandDiag(ARMMatchResultTy MatchError); 730 731 void FilterNearMisses(SmallVectorImpl<NearMissInfo> &NearMissesIn, 732 SmallVectorImpl<NearMissMessage> &NearMissesOut, 733 SMLoc IDLoc, OperandVector &Operands); 734 void ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses, SMLoc IDLoc, 735 OperandVector &Operands); 736 737 void doBeforeLabelEmit(MCSymbol *Symbol) override; 738 739 void onLabelParsed(MCSymbol *Symbol) override; 740 }; 741 742 /// ARMOperand - Instances of this class represent a parsed ARM machine 743 /// operand. 744 class ARMOperand : public MCParsedAsmOperand { 745 enum KindTy { 746 k_CondCode, 747 k_VPTPred, 748 k_CCOut, 749 k_ITCondMask, 750 k_CoprocNum, 751 k_CoprocReg, 752 k_CoprocOption, 753 k_Immediate, 754 k_MemBarrierOpt, 755 k_InstSyncBarrierOpt, 756 k_TraceSyncBarrierOpt, 757 k_Memory, 758 k_PostIndexRegister, 759 k_MSRMask, 760 k_BankedReg, 761 k_ProcIFlags, 762 k_VectorIndex, 763 k_Register, 764 k_RegisterList, 765 k_RegisterListWithAPSR, 766 k_DPRRegisterList, 767 k_SPRRegisterList, 768 k_FPSRegisterListWithVPR, 769 k_FPDRegisterListWithVPR, 770 k_VectorList, 771 k_VectorListAllLanes, 772 k_VectorListIndexed, 773 k_ShiftedRegister, 774 k_ShiftedImmediate, 775 k_ShifterImmediate, 776 k_RotateImmediate, 777 k_ModifiedImmediate, 778 k_ConstantPoolImmediate, 779 k_BitfieldDescriptor, 780 k_Token, 781 } Kind; 782 783 SMLoc StartLoc, EndLoc, AlignmentLoc; 784 SmallVector<unsigned, 8> Registers; 785 786 struct CCOp { 787 ARMCC::CondCodes Val; 788 }; 789 790 struct VCCOp { 791 ARMVCC::VPTCodes Val; 792 }; 793 794 struct CopOp { 795 unsigned Val; 796 }; 797 798 struct CoprocOptionOp { 799 unsigned Val; 800 }; 801 802 struct ITMaskOp { 803 unsigned Mask:4; 804 }; 805 806 struct MBOptOp { 807 ARM_MB::MemBOpt Val; 808 }; 809 810 struct ISBOptOp { 811 ARM_ISB::InstSyncBOpt Val; 812 }; 813 814 struct TSBOptOp { 815 ARM_TSB::TraceSyncBOpt Val; 816 }; 817 818 struct IFlagsOp { 819 ARM_PROC::IFlags Val; 820 }; 821 822 struct MMaskOp { 823 unsigned Val; 824 }; 825 826 struct BankedRegOp { 827 unsigned Val; 828 }; 829 830 struct TokOp { 831 const char *Data; 832 unsigned Length; 833 }; 834 835 struct RegOp { 836 unsigned RegNum; 837 }; 838 839 // A vector register list is a sequential list of 1 to 4 registers. 840 struct VectorListOp { 841 unsigned RegNum; 842 unsigned Count; 843 unsigned LaneIndex; 844 bool isDoubleSpaced; 845 }; 846 847 struct VectorIndexOp { 848 unsigned Val; 849 }; 850 851 struct ImmOp { 852 const MCExpr *Val; 853 }; 854 855 /// Combined record for all forms of ARM address expressions. 856 struct MemoryOp { 857 unsigned BaseRegNum; 858 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset 859 // was specified. 860 const MCExpr *OffsetImm; // Offset immediate value 861 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL 862 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg 863 unsigned ShiftImm; // shift for OffsetReg. 864 unsigned Alignment; // 0 = no alignment specified 865 // n = alignment in bytes (2, 4, 8, 16, or 32) 866 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit) 867 }; 868 869 struct PostIdxRegOp { 870 unsigned RegNum; 871 bool isAdd; 872 ARM_AM::ShiftOpc ShiftTy; 873 unsigned ShiftImm; 874 }; 875 876 struct ShifterImmOp { 877 bool isASR; 878 unsigned Imm; 879 }; 880 881 struct RegShiftedRegOp { 882 ARM_AM::ShiftOpc ShiftTy; 883 unsigned SrcReg; 884 unsigned ShiftReg; 885 unsigned ShiftImm; 886 }; 887 888 struct RegShiftedImmOp { 889 ARM_AM::ShiftOpc ShiftTy; 890 unsigned SrcReg; 891 unsigned ShiftImm; 892 }; 893 894 struct RotImmOp { 895 unsigned Imm; 896 }; 897 898 struct ModImmOp { 899 unsigned Bits; 900 unsigned Rot; 901 }; 902 903 struct BitfieldOp { 904 unsigned LSB; 905 unsigned Width; 906 }; 907 908 union { 909 struct CCOp CC; 910 struct VCCOp VCC; 911 struct CopOp Cop; 912 struct CoprocOptionOp CoprocOption; 913 struct MBOptOp MBOpt; 914 struct ISBOptOp ISBOpt; 915 struct TSBOptOp TSBOpt; 916 struct ITMaskOp ITMask; 917 struct IFlagsOp IFlags; 918 struct MMaskOp MMask; 919 struct BankedRegOp BankedReg; 920 struct TokOp Tok; 921 struct RegOp Reg; 922 struct VectorListOp VectorList; 923 struct VectorIndexOp VectorIndex; 924 struct ImmOp Imm; 925 struct MemoryOp Memory; 926 struct PostIdxRegOp PostIdxReg; 927 struct ShifterImmOp ShifterImm; 928 struct RegShiftedRegOp RegShiftedReg; 929 struct RegShiftedImmOp RegShiftedImm; 930 struct RotImmOp RotImm; 931 struct ModImmOp ModImm; 932 struct BitfieldOp Bitfield; 933 }; 934 935 public: 936 ARMOperand(KindTy K) : Kind(K) {} 937 938 /// getStartLoc - Get the location of the first token of this operand. 939 SMLoc getStartLoc() const override { return StartLoc; } 940 941 /// getEndLoc - Get the location of the last token of this operand. 942 SMLoc getEndLoc() const override { return EndLoc; } 943 944 /// getLocRange - Get the range between the first and last token of this 945 /// operand. 946 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); } 947 948 /// getAlignmentLoc - Get the location of the Alignment token of this operand. 949 SMLoc getAlignmentLoc() const { 950 assert(Kind == k_Memory && "Invalid access!"); 951 return AlignmentLoc; 952 } 953 954 ARMCC::CondCodes getCondCode() const { 955 assert(Kind == k_CondCode && "Invalid access!"); 956 return CC.Val; 957 } 958 959 ARMVCC::VPTCodes getVPTPred() const { 960 assert(isVPTPred() && "Invalid access!"); 961 return VCC.Val; 962 } 963 964 unsigned getCoproc() const { 965 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!"); 966 return Cop.Val; 967 } 968 969 StringRef getToken() const { 970 assert(Kind == k_Token && "Invalid access!"); 971 return StringRef(Tok.Data, Tok.Length); 972 } 973 974 unsigned getReg() const override { 975 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!"); 976 return Reg.RegNum; 977 } 978 979 const SmallVectorImpl<unsigned> &getRegList() const { 980 assert((Kind == k_RegisterList || Kind == k_RegisterListWithAPSR || 981 Kind == k_DPRRegisterList || Kind == k_SPRRegisterList || 982 Kind == k_FPSRegisterListWithVPR || 983 Kind == k_FPDRegisterListWithVPR) && 984 "Invalid access!"); 985 return Registers; 986 } 987 988 const MCExpr *getImm() const { 989 assert(isImm() && "Invalid access!"); 990 return Imm.Val; 991 } 992 993 const MCExpr *getConstantPoolImm() const { 994 assert(isConstantPoolImm() && "Invalid access!"); 995 return Imm.Val; 996 } 997 998 unsigned getVectorIndex() const { 999 assert(Kind == k_VectorIndex && "Invalid access!"); 1000 return VectorIndex.Val; 1001 } 1002 1003 ARM_MB::MemBOpt getMemBarrierOpt() const { 1004 assert(Kind == k_MemBarrierOpt && "Invalid access!"); 1005 return MBOpt.Val; 1006 } 1007 1008 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const { 1009 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!"); 1010 return ISBOpt.Val; 1011 } 1012 1013 ARM_TSB::TraceSyncBOpt getTraceSyncBarrierOpt() const { 1014 assert(Kind == k_TraceSyncBarrierOpt && "Invalid access!"); 1015 return TSBOpt.Val; 1016 } 1017 1018 ARM_PROC::IFlags getProcIFlags() const { 1019 assert(Kind == k_ProcIFlags && "Invalid access!"); 1020 return IFlags.Val; 1021 } 1022 1023 unsigned getMSRMask() const { 1024 assert(Kind == k_MSRMask && "Invalid access!"); 1025 return MMask.Val; 1026 } 1027 1028 unsigned getBankedReg() const { 1029 assert(Kind == k_BankedReg && "Invalid access!"); 1030 return BankedReg.Val; 1031 } 1032 1033 bool isCoprocNum() const { return Kind == k_CoprocNum; } 1034 bool isCoprocReg() const { return Kind == k_CoprocReg; } 1035 bool isCoprocOption() const { return Kind == k_CoprocOption; } 1036 bool isCondCode() const { return Kind == k_CondCode; } 1037 bool isVPTPred() const { return Kind == k_VPTPred; } 1038 bool isCCOut() const { return Kind == k_CCOut; } 1039 bool isITMask() const { return Kind == k_ITCondMask; } 1040 bool isITCondCode() const { return Kind == k_CondCode; } 1041 bool isImm() const override { 1042 return Kind == k_Immediate; 1043 } 1044 1045 bool isARMBranchTarget() const { 1046 if (!isImm()) return false; 1047 1048 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) 1049 return CE->getValue() % 4 == 0; 1050 return true; 1051 } 1052 1053 1054 bool isThumbBranchTarget() const { 1055 if (!isImm()) return false; 1056 1057 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) 1058 return CE->getValue() % 2 == 0; 1059 return true; 1060 } 1061 1062 // checks whether this operand is an unsigned offset which fits is a field 1063 // of specified width and scaled by a specific number of bits 1064 template<unsigned width, unsigned scale> 1065 bool isUnsignedOffset() const { 1066 if (!isImm()) return false; 1067 if (isa<MCSymbolRefExpr>(Imm.Val)) return true; 1068 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { 1069 int64_t Val = CE->getValue(); 1070 int64_t Align = 1LL << scale; 1071 int64_t Max = Align * ((1LL << width) - 1); 1072 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max); 1073 } 1074 return false; 1075 } 1076 1077 // checks whether this operand is an signed offset which fits is a field 1078 // of specified width and scaled by a specific number of bits 1079 template<unsigned width, unsigned scale> 1080 bool isSignedOffset() const { 1081 if (!isImm()) return false; 1082 if (isa<MCSymbolRefExpr>(Imm.Val)) return true; 1083 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { 1084 int64_t Val = CE->getValue(); 1085 int64_t Align = 1LL << scale; 1086 int64_t Max = Align * ((1LL << (width-1)) - 1); 1087 int64_t Min = -Align * (1LL << (width-1)); 1088 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max); 1089 } 1090 return false; 1091 } 1092 1093 // checks whether this operand is an offset suitable for the LE / 1094 // LETP instructions in Arm v8.1M 1095 bool isLEOffset() const { 1096 if (!isImm()) return false; 1097 if (isa<MCSymbolRefExpr>(Imm.Val)) return true; 1098 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { 1099 int64_t Val = CE->getValue(); 1100 return Val < 0 && Val >= -4094 && (Val & 1) == 0; 1101 } 1102 return false; 1103 } 1104 1105 // checks whether this operand is a memory operand computed as an offset 1106 // applied to PC. the offset may have 8 bits of magnitude and is represented 1107 // with two bits of shift. textually it may be either [pc, #imm], #imm or 1108 // relocable expression... 1109 bool isThumbMemPC() const { 1110 int64_t Val = 0; 1111 if (isImm()) { 1112 if (isa<MCSymbolRefExpr>(Imm.Val)) return true; 1113 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val); 1114 if (!CE) return false; 1115 Val = CE->getValue(); 1116 } 1117 else if (isGPRMem()) { 1118 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false; 1119 if(Memory.BaseRegNum != ARM::PC) return false; 1120 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) 1121 Val = CE->getValue(); 1122 else 1123 return false; 1124 } 1125 else return false; 1126 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020); 1127 } 1128 1129 bool isFPImm() const { 1130 if (!isImm()) return false; 1131 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1132 if (!CE) return false; 1133 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); 1134 return Val != -1; 1135 } 1136 1137 template<int64_t N, int64_t M> 1138 bool isImmediate() const { 1139 if (!isImm()) return false; 1140 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1141 if (!CE) return false; 1142 int64_t Value = CE->getValue(); 1143 return Value >= N && Value <= M; 1144 } 1145 1146 template<int64_t N, int64_t M> 1147 bool isImmediateS4() const { 1148 if (!isImm()) return false; 1149 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1150 if (!CE) return false; 1151 int64_t Value = CE->getValue(); 1152 return ((Value & 3) == 0) && Value >= N && Value <= M; 1153 } 1154 template<int64_t N, int64_t M> 1155 bool isImmediateS2() const { 1156 if (!isImm()) return false; 1157 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1158 if (!CE) return false; 1159 int64_t Value = CE->getValue(); 1160 return ((Value & 1) == 0) && Value >= N && Value <= M; 1161 } 1162 bool isFBits16() const { 1163 return isImmediate<0, 17>(); 1164 } 1165 bool isFBits32() const { 1166 return isImmediate<1, 33>(); 1167 } 1168 bool isImm8s4() const { 1169 return isImmediateS4<-1020, 1020>(); 1170 } 1171 bool isImm7s4() const { 1172 return isImmediateS4<-508, 508>(); 1173 } 1174 bool isImm7Shift0() const { 1175 return isImmediate<-127, 127>(); 1176 } 1177 bool isImm7Shift1() const { 1178 return isImmediateS2<-255, 255>(); 1179 } 1180 bool isImm7Shift2() const { 1181 return isImmediateS4<-511, 511>(); 1182 } 1183 bool isImm7() const { 1184 return isImmediate<-127, 127>(); 1185 } 1186 bool isImm0_1020s4() const { 1187 return isImmediateS4<0, 1020>(); 1188 } 1189 bool isImm0_508s4() const { 1190 return isImmediateS4<0, 508>(); 1191 } 1192 bool isImm0_508s4Neg() const { 1193 if (!isImm()) return false; 1194 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1195 if (!CE) return false; 1196 int64_t Value = -CE->getValue(); 1197 // explicitly exclude zero. we want that to use the normal 0_508 version. 1198 return ((Value & 3) == 0) && Value > 0 && Value <= 508; 1199 } 1200 1201 bool isImm0_4095Neg() const { 1202 if (!isImm()) return false; 1203 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1204 if (!CE) return false; 1205 // isImm0_4095Neg is used with 32-bit immediates only. 1206 // 32-bit immediates are zero extended to 64-bit when parsed, 1207 // thus simple -CE->getValue() results in a big negative number, 1208 // not a small positive number as intended 1209 if ((CE->getValue() >> 32) > 0) return false; 1210 uint32_t Value = -static_cast<uint32_t>(CE->getValue()); 1211 return Value > 0 && Value < 4096; 1212 } 1213 1214 bool isImm0_7() const { 1215 return isImmediate<0, 7>(); 1216 } 1217 1218 bool isImm1_16() const { 1219 return isImmediate<1, 16>(); 1220 } 1221 1222 bool isImm1_32() const { 1223 return isImmediate<1, 32>(); 1224 } 1225 1226 bool isImm8_255() const { 1227 return isImmediate<8, 255>(); 1228 } 1229 1230 bool isImm256_65535Expr() const { 1231 if (!isImm()) return false; 1232 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1233 // If it's not a constant expression, it'll generate a fixup and be 1234 // handled later. 1235 if (!CE) return true; 1236 int64_t Value = CE->getValue(); 1237 return Value >= 256 && Value < 65536; 1238 } 1239 1240 bool isImm0_65535Expr() const { 1241 if (!isImm()) return false; 1242 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1243 // If it's not a constant expression, it'll generate a fixup and be 1244 // handled later. 1245 if (!CE) return true; 1246 int64_t Value = CE->getValue(); 1247 return Value >= 0 && Value < 65536; 1248 } 1249 1250 bool isImm24bit() const { 1251 return isImmediate<0, 0xffffff + 1>(); 1252 } 1253 1254 bool isImmThumbSR() const { 1255 return isImmediate<1, 33>(); 1256 } 1257 1258 template<int shift> 1259 bool isExpImmValue(uint64_t Value) const { 1260 uint64_t mask = (1 << shift) - 1; 1261 if ((Value & mask) != 0 || (Value >> shift) > 0xff) 1262 return false; 1263 return true; 1264 } 1265 1266 template<int shift> 1267 bool isExpImm() const { 1268 if (!isImm()) return false; 1269 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1270 if (!CE) return false; 1271 1272 return isExpImmValue<shift>(CE->getValue()); 1273 } 1274 1275 template<int shift, int size> 1276 bool isInvertedExpImm() const { 1277 if (!isImm()) return false; 1278 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1279 if (!CE) return false; 1280 1281 uint64_t OriginalValue = CE->getValue(); 1282 uint64_t InvertedValue = OriginalValue ^ (((uint64_t)1 << size) - 1); 1283 return isExpImmValue<shift>(InvertedValue); 1284 } 1285 1286 bool isPKHLSLImm() const { 1287 return isImmediate<0, 32>(); 1288 } 1289 1290 bool isPKHASRImm() const { 1291 return isImmediate<0, 33>(); 1292 } 1293 1294 bool isAdrLabel() const { 1295 // If we have an immediate that's not a constant, treat it as a label 1296 // reference needing a fixup. 1297 if (isImm() && !isa<MCConstantExpr>(getImm())) 1298 return true; 1299 1300 // If it is a constant, it must fit into a modified immediate encoding. 1301 if (!isImm()) return false; 1302 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1303 if (!CE) return false; 1304 int64_t Value = CE->getValue(); 1305 return (ARM_AM::getSOImmVal(Value) != -1 || 1306 ARM_AM::getSOImmVal(-Value) != -1); 1307 } 1308 1309 bool isT2SOImm() const { 1310 // If we have an immediate that's not a constant, treat it as an expression 1311 // needing a fixup. 1312 if (isImm() && !isa<MCConstantExpr>(getImm())) { 1313 // We want to avoid matching :upper16: and :lower16: as we want these 1314 // expressions to match in isImm0_65535Expr() 1315 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(getImm()); 1316 return (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 && 1317 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)); 1318 } 1319 if (!isImm()) return false; 1320 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1321 if (!CE) return false; 1322 int64_t Value = CE->getValue(); 1323 return ARM_AM::getT2SOImmVal(Value) != -1; 1324 } 1325 1326 bool isT2SOImmNot() const { 1327 if (!isImm()) return false; 1328 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1329 if (!CE) return false; 1330 int64_t Value = CE->getValue(); 1331 return ARM_AM::getT2SOImmVal(Value) == -1 && 1332 ARM_AM::getT2SOImmVal(~Value) != -1; 1333 } 1334 1335 bool isT2SOImmNeg() const { 1336 if (!isImm()) return false; 1337 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1338 if (!CE) return false; 1339 int64_t Value = CE->getValue(); 1340 // Only use this when not representable as a plain so_imm. 1341 return ARM_AM::getT2SOImmVal(Value) == -1 && 1342 ARM_AM::getT2SOImmVal(-Value) != -1; 1343 } 1344 1345 bool isSetEndImm() const { 1346 if (!isImm()) return false; 1347 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1348 if (!CE) return false; 1349 int64_t Value = CE->getValue(); 1350 return Value == 1 || Value == 0; 1351 } 1352 1353 bool isReg() const override { return Kind == k_Register; } 1354 bool isRegList() const { return Kind == k_RegisterList; } 1355 bool isRegListWithAPSR() const { 1356 return Kind == k_RegisterListWithAPSR || Kind == k_RegisterList; 1357 } 1358 bool isDPRRegList() const { return Kind == k_DPRRegisterList; } 1359 bool isSPRRegList() const { return Kind == k_SPRRegisterList; } 1360 bool isFPSRegListWithVPR() const { return Kind == k_FPSRegisterListWithVPR; } 1361 bool isFPDRegListWithVPR() const { return Kind == k_FPDRegisterListWithVPR; } 1362 bool isToken() const override { return Kind == k_Token; } 1363 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; } 1364 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; } 1365 bool isTraceSyncBarrierOpt() const { return Kind == k_TraceSyncBarrierOpt; } 1366 bool isMem() const override { 1367 return isGPRMem() || isMVEMem(); 1368 } 1369 bool isMVEMem() const { 1370 if (Kind != k_Memory) 1371 return false; 1372 if (Memory.BaseRegNum && 1373 !ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Memory.BaseRegNum) && 1374 !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(Memory.BaseRegNum)) 1375 return false; 1376 if (Memory.OffsetRegNum && 1377 !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains( 1378 Memory.OffsetRegNum)) 1379 return false; 1380 return true; 1381 } 1382 bool isGPRMem() const { 1383 if (Kind != k_Memory) 1384 return false; 1385 if (Memory.BaseRegNum && 1386 !ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Memory.BaseRegNum)) 1387 return false; 1388 if (Memory.OffsetRegNum && 1389 !ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Memory.OffsetRegNum)) 1390 return false; 1391 return true; 1392 } 1393 bool isShifterImm() const { return Kind == k_ShifterImmediate; } 1394 bool isRegShiftedReg() const { 1395 return Kind == k_ShiftedRegister && 1396 ARMMCRegisterClasses[ARM::GPRRegClassID].contains( 1397 RegShiftedReg.SrcReg) && 1398 ARMMCRegisterClasses[ARM::GPRRegClassID].contains( 1399 RegShiftedReg.ShiftReg); 1400 } 1401 bool isRegShiftedImm() const { 1402 return Kind == k_ShiftedImmediate && 1403 ARMMCRegisterClasses[ARM::GPRRegClassID].contains( 1404 RegShiftedImm.SrcReg); 1405 } 1406 bool isRotImm() const { return Kind == k_RotateImmediate; } 1407 1408 template<unsigned Min, unsigned Max> 1409 bool isPowerTwoInRange() const { 1410 if (!isImm()) return false; 1411 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1412 if (!CE) return false; 1413 int64_t Value = CE->getValue(); 1414 return Value > 0 && countPopulation((uint64_t)Value) == 1 && 1415 Value >= Min && Value <= Max; 1416 } 1417 bool isModImm() const { return Kind == k_ModifiedImmediate; } 1418 1419 bool isModImmNot() const { 1420 if (!isImm()) return false; 1421 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1422 if (!CE) return false; 1423 int64_t Value = CE->getValue(); 1424 return ARM_AM::getSOImmVal(~Value) != -1; 1425 } 1426 1427 bool isModImmNeg() const { 1428 if (!isImm()) return false; 1429 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1430 if (!CE) return false; 1431 int64_t Value = CE->getValue(); 1432 return ARM_AM::getSOImmVal(Value) == -1 && 1433 ARM_AM::getSOImmVal(-Value) != -1; 1434 } 1435 1436 bool isThumbModImmNeg1_7() const { 1437 if (!isImm()) return false; 1438 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1439 if (!CE) return false; 1440 int32_t Value = -(int32_t)CE->getValue(); 1441 return 0 < Value && Value < 8; 1442 } 1443 1444 bool isThumbModImmNeg8_255() const { 1445 if (!isImm()) return false; 1446 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1447 if (!CE) return false; 1448 int32_t Value = -(int32_t)CE->getValue(); 1449 return 7 < Value && Value < 256; 1450 } 1451 1452 bool isConstantPoolImm() const { return Kind == k_ConstantPoolImmediate; } 1453 bool isBitfield() const { return Kind == k_BitfieldDescriptor; } 1454 bool isPostIdxRegShifted() const { 1455 return Kind == k_PostIndexRegister && 1456 ARMMCRegisterClasses[ARM::GPRRegClassID].contains(PostIdxReg.RegNum); 1457 } 1458 bool isPostIdxReg() const { 1459 return isPostIdxRegShifted() && PostIdxReg.ShiftTy == ARM_AM::no_shift; 1460 } 1461 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const { 1462 if (!isGPRMem()) 1463 return false; 1464 // No offset of any kind. 1465 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && 1466 (alignOK || Memory.Alignment == Alignment); 1467 } 1468 bool isMemNoOffsetT2(bool alignOK = false, unsigned Alignment = 0) const { 1469 if (!isGPRMem()) 1470 return false; 1471 1472 if (!ARMMCRegisterClasses[ARM::GPRnopcRegClassID].contains( 1473 Memory.BaseRegNum)) 1474 return false; 1475 1476 // No offset of any kind. 1477 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && 1478 (alignOK || Memory.Alignment == Alignment); 1479 } 1480 bool isMemNoOffsetT2NoSp(bool alignOK = false, unsigned Alignment = 0) const { 1481 if (!isGPRMem()) 1482 return false; 1483 1484 if (!ARMMCRegisterClasses[ARM::rGPRRegClassID].contains( 1485 Memory.BaseRegNum)) 1486 return false; 1487 1488 // No offset of any kind. 1489 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && 1490 (alignOK || Memory.Alignment == Alignment); 1491 } 1492 bool isMemNoOffsetT(bool alignOK = false, unsigned Alignment = 0) const { 1493 if (!isGPRMem()) 1494 return false; 1495 1496 if (!ARMMCRegisterClasses[ARM::tGPRRegClassID].contains( 1497 Memory.BaseRegNum)) 1498 return false; 1499 1500 // No offset of any kind. 1501 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && 1502 (alignOK || Memory.Alignment == Alignment); 1503 } 1504 bool isMemPCRelImm12() const { 1505 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1506 return false; 1507 // Base register must be PC. 1508 if (Memory.BaseRegNum != ARM::PC) 1509 return false; 1510 // Immediate offset in range [-4095, 4095]. 1511 if (!Memory.OffsetImm) return true; 1512 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1513 int64_t Val = CE->getValue(); 1514 return (Val > -4096 && Val < 4096) || 1515 (Val == std::numeric_limits<int32_t>::min()); 1516 } 1517 return false; 1518 } 1519 1520 bool isAlignedMemory() const { 1521 return isMemNoOffset(true); 1522 } 1523 1524 bool isAlignedMemoryNone() const { 1525 return isMemNoOffset(false, 0); 1526 } 1527 1528 bool isDupAlignedMemoryNone() const { 1529 return isMemNoOffset(false, 0); 1530 } 1531 1532 bool isAlignedMemory16() const { 1533 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. 1534 return true; 1535 return isMemNoOffset(false, 0); 1536 } 1537 1538 bool isDupAlignedMemory16() const { 1539 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. 1540 return true; 1541 return isMemNoOffset(false, 0); 1542 } 1543 1544 bool isAlignedMemory32() const { 1545 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. 1546 return true; 1547 return isMemNoOffset(false, 0); 1548 } 1549 1550 bool isDupAlignedMemory32() const { 1551 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. 1552 return true; 1553 return isMemNoOffset(false, 0); 1554 } 1555 1556 bool isAlignedMemory64() const { 1557 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1558 return true; 1559 return isMemNoOffset(false, 0); 1560 } 1561 1562 bool isDupAlignedMemory64() const { 1563 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1564 return true; 1565 return isMemNoOffset(false, 0); 1566 } 1567 1568 bool isAlignedMemory64or128() const { 1569 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1570 return true; 1571 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. 1572 return true; 1573 return isMemNoOffset(false, 0); 1574 } 1575 1576 bool isDupAlignedMemory64or128() const { 1577 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1578 return true; 1579 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. 1580 return true; 1581 return isMemNoOffset(false, 0); 1582 } 1583 1584 bool isAlignedMemory64or128or256() const { 1585 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1586 return true; 1587 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. 1588 return true; 1589 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32. 1590 return true; 1591 return isMemNoOffset(false, 0); 1592 } 1593 1594 bool isAddrMode2() const { 1595 if (!isGPRMem() || Memory.Alignment != 0) return false; 1596 // Check for register offset. 1597 if (Memory.OffsetRegNum) return true; 1598 // Immediate offset in range [-4095, 4095]. 1599 if (!Memory.OffsetImm) return true; 1600 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1601 int64_t Val = CE->getValue(); 1602 return Val > -4096 && Val < 4096; 1603 } 1604 return false; 1605 } 1606 1607 bool isAM2OffsetImm() const { 1608 if (!isImm()) return false; 1609 // Immediate offset in range [-4095, 4095]. 1610 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1611 if (!CE) return false; 1612 int64_t Val = CE->getValue(); 1613 return (Val == std::numeric_limits<int32_t>::min()) || 1614 (Val > -4096 && Val < 4096); 1615 } 1616 1617 bool isAddrMode3() const { 1618 // If we have an immediate that's not a constant, treat it as a label 1619 // reference needing a fixup. If it is a constant, it's something else 1620 // and we reject it. 1621 if (isImm() && !isa<MCConstantExpr>(getImm())) 1622 return true; 1623 if (!isGPRMem() || Memory.Alignment != 0) return false; 1624 // No shifts are legal for AM3. 1625 if (Memory.ShiftType != ARM_AM::no_shift) return false; 1626 // Check for register offset. 1627 if (Memory.OffsetRegNum) return true; 1628 // Immediate offset in range [-255, 255]. 1629 if (!Memory.OffsetImm) return true; 1630 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1631 int64_t Val = CE->getValue(); 1632 // The #-0 offset is encoded as std::numeric_limits<int32_t>::min(), and 1633 // we have to check for this too. 1634 return (Val > -256 && Val < 256) || 1635 Val == std::numeric_limits<int32_t>::min(); 1636 } 1637 return false; 1638 } 1639 1640 bool isAM3Offset() const { 1641 if (isPostIdxReg()) 1642 return true; 1643 if (!isImm()) 1644 return false; 1645 // Immediate offset in range [-255, 255]. 1646 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1647 if (!CE) return false; 1648 int64_t Val = CE->getValue(); 1649 // Special case, #-0 is std::numeric_limits<int32_t>::min(). 1650 return (Val > -256 && Val < 256) || 1651 Val == std::numeric_limits<int32_t>::min(); 1652 } 1653 1654 bool isAddrMode5() const { 1655 // If we have an immediate that's not a constant, treat it as a label 1656 // reference needing a fixup. If it is a constant, it's something else 1657 // and we reject it. 1658 if (isImm() && !isa<MCConstantExpr>(getImm())) 1659 return true; 1660 if (!isGPRMem() || Memory.Alignment != 0) return false; 1661 // Check for register offset. 1662 if (Memory.OffsetRegNum) return false; 1663 // Immediate offset in range [-1020, 1020] and a multiple of 4. 1664 if (!Memory.OffsetImm) return true; 1665 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1666 int64_t Val = CE->getValue(); 1667 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) || 1668 Val == std::numeric_limits<int32_t>::min(); 1669 } 1670 return false; 1671 } 1672 1673 bool isAddrMode5FP16() const { 1674 // If we have an immediate that's not a constant, treat it as a label 1675 // reference needing a fixup. If it is a constant, it's something else 1676 // and we reject it. 1677 if (isImm() && !isa<MCConstantExpr>(getImm())) 1678 return true; 1679 if (!isGPRMem() || Memory.Alignment != 0) return false; 1680 // Check for register offset. 1681 if (Memory.OffsetRegNum) return false; 1682 // Immediate offset in range [-510, 510] and a multiple of 2. 1683 if (!Memory.OffsetImm) return true; 1684 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1685 int64_t Val = CE->getValue(); 1686 return (Val >= -510 && Val <= 510 && ((Val & 1) == 0)) || 1687 Val == std::numeric_limits<int32_t>::min(); 1688 } 1689 return false; 1690 } 1691 1692 bool isMemTBB() const { 1693 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative || 1694 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) 1695 return false; 1696 return true; 1697 } 1698 1699 bool isMemTBH() const { 1700 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative || 1701 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 || 1702 Memory.Alignment != 0 ) 1703 return false; 1704 return true; 1705 } 1706 1707 bool isMemRegOffset() const { 1708 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.Alignment != 0) 1709 return false; 1710 return true; 1711 } 1712 1713 bool isT2MemRegOffset() const { 1714 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative || 1715 Memory.Alignment != 0 || Memory.BaseRegNum == ARM::PC) 1716 return false; 1717 // Only lsl #{0, 1, 2, 3} allowed. 1718 if (Memory.ShiftType == ARM_AM::no_shift) 1719 return true; 1720 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3) 1721 return false; 1722 return true; 1723 } 1724 1725 bool isMemThumbRR() const { 1726 // Thumb reg+reg addressing is simple. Just two registers, a base and 1727 // an offset. No shifts, negations or any other complicating factors. 1728 if (!isGPRMem() || !Memory.OffsetRegNum || Memory.isNegative || 1729 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) 1730 return false; 1731 return isARMLowRegister(Memory.BaseRegNum) && 1732 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum)); 1733 } 1734 1735 bool isMemThumbRIs4() const { 1736 if (!isGPRMem() || Memory.OffsetRegNum != 0 || 1737 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) 1738 return false; 1739 // Immediate offset, multiple of 4 in range [0, 124]. 1740 if (!Memory.OffsetImm) return true; 1741 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1742 int64_t Val = CE->getValue(); 1743 return Val >= 0 && Val <= 124 && (Val % 4) == 0; 1744 } 1745 return false; 1746 } 1747 1748 bool isMemThumbRIs2() const { 1749 if (!isGPRMem() || Memory.OffsetRegNum != 0 || 1750 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) 1751 return false; 1752 // Immediate offset, multiple of 4 in range [0, 62]. 1753 if (!Memory.OffsetImm) return true; 1754 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1755 int64_t Val = CE->getValue(); 1756 return Val >= 0 && Val <= 62 && (Val % 2) == 0; 1757 } 1758 return false; 1759 } 1760 1761 bool isMemThumbRIs1() const { 1762 if (!isGPRMem() || Memory.OffsetRegNum != 0 || 1763 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) 1764 return false; 1765 // Immediate offset in range [0, 31]. 1766 if (!Memory.OffsetImm) return true; 1767 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1768 int64_t Val = CE->getValue(); 1769 return Val >= 0 && Val <= 31; 1770 } 1771 return false; 1772 } 1773 1774 bool isMemThumbSPI() const { 1775 if (!isGPRMem() || Memory.OffsetRegNum != 0 || 1776 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0) 1777 return false; 1778 // Immediate offset, multiple of 4 in range [0, 1020]. 1779 if (!Memory.OffsetImm) return true; 1780 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1781 int64_t Val = CE->getValue(); 1782 return Val >= 0 && Val <= 1020 && (Val % 4) == 0; 1783 } 1784 return false; 1785 } 1786 1787 bool isMemImm8s4Offset() const { 1788 // If we have an immediate that's not a constant, treat it as a label 1789 // reference needing a fixup. If it is a constant, it's something else 1790 // and we reject it. 1791 if (isImm() && !isa<MCConstantExpr>(getImm())) 1792 return true; 1793 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1794 return false; 1795 // Immediate offset a multiple of 4 in range [-1020, 1020]. 1796 if (!Memory.OffsetImm) return true; 1797 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1798 int64_t Val = CE->getValue(); 1799 // Special case, #-0 is std::numeric_limits<int32_t>::min(). 1800 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || 1801 Val == std::numeric_limits<int32_t>::min(); 1802 } 1803 return false; 1804 } 1805 1806 bool isMemImm7s4Offset() const { 1807 // If we have an immediate that's not a constant, treat it as a label 1808 // reference needing a fixup. If it is a constant, it's something else 1809 // and we reject it. 1810 if (isImm() && !isa<MCConstantExpr>(getImm())) 1811 return true; 1812 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0 || 1813 !ARMMCRegisterClasses[ARM::GPRnopcRegClassID].contains( 1814 Memory.BaseRegNum)) 1815 return false; 1816 // Immediate offset a multiple of 4 in range [-508, 508]. 1817 if (!Memory.OffsetImm) return true; 1818 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1819 int64_t Val = CE->getValue(); 1820 // Special case, #-0 is INT32_MIN. 1821 return (Val >= -508 && Val <= 508 && (Val & 3) == 0) || Val == INT32_MIN; 1822 } 1823 return false; 1824 } 1825 1826 bool isMemImm0_1020s4Offset() const { 1827 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1828 return false; 1829 // Immediate offset a multiple of 4 in range [0, 1020]. 1830 if (!Memory.OffsetImm) return true; 1831 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1832 int64_t Val = CE->getValue(); 1833 return Val >= 0 && Val <= 1020 && (Val & 3) == 0; 1834 } 1835 return false; 1836 } 1837 1838 bool isMemImm8Offset() const { 1839 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1840 return false; 1841 // Base reg of PC isn't allowed for these encodings. 1842 if (Memory.BaseRegNum == ARM::PC) return false; 1843 // Immediate offset in range [-255, 255]. 1844 if (!Memory.OffsetImm) return true; 1845 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1846 int64_t Val = CE->getValue(); 1847 return (Val == std::numeric_limits<int32_t>::min()) || 1848 (Val > -256 && Val < 256); 1849 } 1850 return false; 1851 } 1852 1853 template<unsigned Bits, unsigned RegClassID> 1854 bool isMemImm7ShiftedOffset() const { 1855 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0 || 1856 !ARMMCRegisterClasses[RegClassID].contains(Memory.BaseRegNum)) 1857 return false; 1858 1859 // Expect an immediate offset equal to an element of the range 1860 // [-127, 127], shifted left by Bits. 1861 1862 if (!Memory.OffsetImm) return true; 1863 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1864 int64_t Val = CE->getValue(); 1865 1866 // INT32_MIN is a special-case value (indicating the encoding with 1867 // zero offset and the subtract bit set) 1868 if (Val == INT32_MIN) 1869 return true; 1870 1871 unsigned Divisor = 1U << Bits; 1872 1873 // Check that the low bits are zero 1874 if (Val % Divisor != 0) 1875 return false; 1876 1877 // Check that the remaining offset is within range. 1878 Val /= Divisor; 1879 return (Val >= -127 && Val <= 127); 1880 } 1881 return false; 1882 } 1883 1884 template <int shift> bool isMemRegRQOffset() const { 1885 if (!isMVEMem() || Memory.OffsetImm != nullptr || Memory.Alignment != 0) 1886 return false; 1887 1888 if (!ARMMCRegisterClasses[ARM::GPRnopcRegClassID].contains( 1889 Memory.BaseRegNum)) 1890 return false; 1891 if (!ARMMCRegisterClasses[ARM::MQPRRegClassID].contains( 1892 Memory.OffsetRegNum)) 1893 return false; 1894 1895 if (shift == 0 && Memory.ShiftType != ARM_AM::no_shift) 1896 return false; 1897 1898 if (shift > 0 && 1899 (Memory.ShiftType != ARM_AM::uxtw || Memory.ShiftImm != shift)) 1900 return false; 1901 1902 return true; 1903 } 1904 1905 template <int shift> bool isMemRegQOffset() const { 1906 if (!isMVEMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1907 return false; 1908 1909 if (!ARMMCRegisterClasses[ARM::MQPRRegClassID].contains( 1910 Memory.BaseRegNum)) 1911 return false; 1912 1913 if (!Memory.OffsetImm) 1914 return true; 1915 static_assert(shift < 56, 1916 "Such that we dont shift by a value higher than 62"); 1917 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1918 int64_t Val = CE->getValue(); 1919 1920 // The value must be a multiple of (1 << shift) 1921 if ((Val & ((1U << shift) - 1)) != 0) 1922 return false; 1923 1924 // And be in the right range, depending on the amount that it is shifted 1925 // by. Shift 0, is equal to 7 unsigned bits, the sign bit is set 1926 // separately. 1927 int64_t Range = (1U << (7 + shift)) - 1; 1928 return (Val == INT32_MIN) || (Val > -Range && Val < Range); 1929 } 1930 return false; 1931 } 1932 1933 bool isMemPosImm8Offset() const { 1934 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1935 return false; 1936 // Immediate offset in range [0, 255]. 1937 if (!Memory.OffsetImm) return true; 1938 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1939 int64_t Val = CE->getValue(); 1940 return Val >= 0 && Val < 256; 1941 } 1942 return false; 1943 } 1944 1945 bool isMemNegImm8Offset() const { 1946 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1947 return false; 1948 // Base reg of PC isn't allowed for these encodings. 1949 if (Memory.BaseRegNum == ARM::PC) return false; 1950 // Immediate offset in range [-255, -1]. 1951 if (!Memory.OffsetImm) return false; 1952 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1953 int64_t Val = CE->getValue(); 1954 return (Val == std::numeric_limits<int32_t>::min()) || 1955 (Val > -256 && Val < 0); 1956 } 1957 return false; 1958 } 1959 1960 bool isMemUImm12Offset() const { 1961 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1962 return false; 1963 // Immediate offset in range [0, 4095]. 1964 if (!Memory.OffsetImm) return true; 1965 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1966 int64_t Val = CE->getValue(); 1967 return (Val >= 0 && Val < 4096); 1968 } 1969 return false; 1970 } 1971 1972 bool isMemImm12Offset() const { 1973 // If we have an immediate that's not a constant, treat it as a label 1974 // reference needing a fixup. If it is a constant, it's something else 1975 // and we reject it. 1976 1977 if (isImm() && !isa<MCConstantExpr>(getImm())) 1978 return true; 1979 1980 if (!isGPRMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1981 return false; 1982 // Immediate offset in range [-4095, 4095]. 1983 if (!Memory.OffsetImm) return true; 1984 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 1985 int64_t Val = CE->getValue(); 1986 return (Val > -4096 && Val < 4096) || 1987 (Val == std::numeric_limits<int32_t>::min()); 1988 } 1989 // If we have an immediate that's not a constant, treat it as a 1990 // symbolic expression needing a fixup. 1991 return true; 1992 } 1993 1994 bool isConstPoolAsmImm() const { 1995 // Delay processing of Constant Pool Immediate, this will turn into 1996 // a constant. Match no other operand 1997 return (isConstantPoolImm()); 1998 } 1999 2000 bool isPostIdxImm8() const { 2001 if (!isImm()) return false; 2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2003 if (!CE) return false; 2004 int64_t Val = CE->getValue(); 2005 return (Val > -256 && Val < 256) || 2006 (Val == std::numeric_limits<int32_t>::min()); 2007 } 2008 2009 bool isPostIdxImm8s4() const { 2010 if (!isImm()) return false; 2011 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2012 if (!CE) return false; 2013 int64_t Val = CE->getValue(); 2014 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) || 2015 (Val == std::numeric_limits<int32_t>::min()); 2016 } 2017 2018 bool isMSRMask() const { return Kind == k_MSRMask; } 2019 bool isBankedReg() const { return Kind == k_BankedReg; } 2020 bool isProcIFlags() const { return Kind == k_ProcIFlags; } 2021 2022 // NEON operands. 2023 bool isSingleSpacedVectorList() const { 2024 return Kind == k_VectorList && !VectorList.isDoubleSpaced; 2025 } 2026 2027 bool isDoubleSpacedVectorList() const { 2028 return Kind == k_VectorList && VectorList.isDoubleSpaced; 2029 } 2030 2031 bool isVecListOneD() const { 2032 if (!isSingleSpacedVectorList()) return false; 2033 return VectorList.Count == 1; 2034 } 2035 2036 bool isVecListTwoMQ() const { 2037 return isSingleSpacedVectorList() && VectorList.Count == 2 && 2038 ARMMCRegisterClasses[ARM::MQPRRegClassID].contains( 2039 VectorList.RegNum); 2040 } 2041 2042 bool isVecListDPair() const { 2043 if (!isSingleSpacedVectorList()) return false; 2044 return (ARMMCRegisterClasses[ARM::DPairRegClassID] 2045 .contains(VectorList.RegNum)); 2046 } 2047 2048 bool isVecListThreeD() const { 2049 if (!isSingleSpacedVectorList()) return false; 2050 return VectorList.Count == 3; 2051 } 2052 2053 bool isVecListFourD() const { 2054 if (!isSingleSpacedVectorList()) return false; 2055 return VectorList.Count == 4; 2056 } 2057 2058 bool isVecListDPairSpaced() const { 2059 if (Kind != k_VectorList) return false; 2060 if (isSingleSpacedVectorList()) return false; 2061 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID] 2062 .contains(VectorList.RegNum)); 2063 } 2064 2065 bool isVecListThreeQ() const { 2066 if (!isDoubleSpacedVectorList()) return false; 2067 return VectorList.Count == 3; 2068 } 2069 2070 bool isVecListFourQ() const { 2071 if (!isDoubleSpacedVectorList()) return false; 2072 return VectorList.Count == 4; 2073 } 2074 2075 bool isVecListFourMQ() const { 2076 return isSingleSpacedVectorList() && VectorList.Count == 4 && 2077 ARMMCRegisterClasses[ARM::MQPRRegClassID].contains( 2078 VectorList.RegNum); 2079 } 2080 2081 bool isSingleSpacedVectorAllLanes() const { 2082 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced; 2083 } 2084 2085 bool isDoubleSpacedVectorAllLanes() const { 2086 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced; 2087 } 2088 2089 bool isVecListOneDAllLanes() const { 2090 if (!isSingleSpacedVectorAllLanes()) return false; 2091 return VectorList.Count == 1; 2092 } 2093 2094 bool isVecListDPairAllLanes() const { 2095 if (!isSingleSpacedVectorAllLanes()) return false; 2096 return (ARMMCRegisterClasses[ARM::DPairRegClassID] 2097 .contains(VectorList.RegNum)); 2098 } 2099 2100 bool isVecListDPairSpacedAllLanes() const { 2101 if (!isDoubleSpacedVectorAllLanes()) return false; 2102 return VectorList.Count == 2; 2103 } 2104 2105 bool isVecListThreeDAllLanes() const { 2106 if (!isSingleSpacedVectorAllLanes()) return false; 2107 return VectorList.Count == 3; 2108 } 2109 2110 bool isVecListThreeQAllLanes() const { 2111 if (!isDoubleSpacedVectorAllLanes()) return false; 2112 return VectorList.Count == 3; 2113 } 2114 2115 bool isVecListFourDAllLanes() const { 2116 if (!isSingleSpacedVectorAllLanes()) return false; 2117 return VectorList.Count == 4; 2118 } 2119 2120 bool isVecListFourQAllLanes() const { 2121 if (!isDoubleSpacedVectorAllLanes()) return false; 2122 return VectorList.Count == 4; 2123 } 2124 2125 bool isSingleSpacedVectorIndexed() const { 2126 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced; 2127 } 2128 2129 bool isDoubleSpacedVectorIndexed() const { 2130 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced; 2131 } 2132 2133 bool isVecListOneDByteIndexed() const { 2134 if (!isSingleSpacedVectorIndexed()) return false; 2135 return VectorList.Count == 1 && VectorList.LaneIndex <= 7; 2136 } 2137 2138 bool isVecListOneDHWordIndexed() const { 2139 if (!isSingleSpacedVectorIndexed()) return false; 2140 return VectorList.Count == 1 && VectorList.LaneIndex <= 3; 2141 } 2142 2143 bool isVecListOneDWordIndexed() const { 2144 if (!isSingleSpacedVectorIndexed()) return false; 2145 return VectorList.Count == 1 && VectorList.LaneIndex <= 1; 2146 } 2147 2148 bool isVecListTwoDByteIndexed() const { 2149 if (!isSingleSpacedVectorIndexed()) return false; 2150 return VectorList.Count == 2 && VectorList.LaneIndex <= 7; 2151 } 2152 2153 bool isVecListTwoDHWordIndexed() const { 2154 if (!isSingleSpacedVectorIndexed()) return false; 2155 return VectorList.Count == 2 && VectorList.LaneIndex <= 3; 2156 } 2157 2158 bool isVecListTwoQWordIndexed() const { 2159 if (!isDoubleSpacedVectorIndexed()) return false; 2160 return VectorList.Count == 2 && VectorList.LaneIndex <= 1; 2161 } 2162 2163 bool isVecListTwoQHWordIndexed() const { 2164 if (!isDoubleSpacedVectorIndexed()) return false; 2165 return VectorList.Count == 2 && VectorList.LaneIndex <= 3; 2166 } 2167 2168 bool isVecListTwoDWordIndexed() const { 2169 if (!isSingleSpacedVectorIndexed()) return false; 2170 return VectorList.Count == 2 && VectorList.LaneIndex <= 1; 2171 } 2172 2173 bool isVecListThreeDByteIndexed() const { 2174 if (!isSingleSpacedVectorIndexed()) return false; 2175 return VectorList.Count == 3 && VectorList.LaneIndex <= 7; 2176 } 2177 2178 bool isVecListThreeDHWordIndexed() const { 2179 if (!isSingleSpacedVectorIndexed()) return false; 2180 return VectorList.Count == 3 && VectorList.LaneIndex <= 3; 2181 } 2182 2183 bool isVecListThreeQWordIndexed() const { 2184 if (!isDoubleSpacedVectorIndexed()) return false; 2185 return VectorList.Count == 3 && VectorList.LaneIndex <= 1; 2186 } 2187 2188 bool isVecListThreeQHWordIndexed() const { 2189 if (!isDoubleSpacedVectorIndexed()) return false; 2190 return VectorList.Count == 3 && VectorList.LaneIndex <= 3; 2191 } 2192 2193 bool isVecListThreeDWordIndexed() const { 2194 if (!isSingleSpacedVectorIndexed()) return false; 2195 return VectorList.Count == 3 && VectorList.LaneIndex <= 1; 2196 } 2197 2198 bool isVecListFourDByteIndexed() const { 2199 if (!isSingleSpacedVectorIndexed()) return false; 2200 return VectorList.Count == 4 && VectorList.LaneIndex <= 7; 2201 } 2202 2203 bool isVecListFourDHWordIndexed() const { 2204 if (!isSingleSpacedVectorIndexed()) return false; 2205 return VectorList.Count == 4 && VectorList.LaneIndex <= 3; 2206 } 2207 2208 bool isVecListFourQWordIndexed() const { 2209 if (!isDoubleSpacedVectorIndexed()) return false; 2210 return VectorList.Count == 4 && VectorList.LaneIndex <= 1; 2211 } 2212 2213 bool isVecListFourQHWordIndexed() const { 2214 if (!isDoubleSpacedVectorIndexed()) return false; 2215 return VectorList.Count == 4 && VectorList.LaneIndex <= 3; 2216 } 2217 2218 bool isVecListFourDWordIndexed() const { 2219 if (!isSingleSpacedVectorIndexed()) return false; 2220 return VectorList.Count == 4 && VectorList.LaneIndex <= 1; 2221 } 2222 2223 bool isVectorIndex() const { return Kind == k_VectorIndex; } 2224 2225 template <unsigned NumLanes> 2226 bool isVectorIndexInRange() const { 2227 if (Kind != k_VectorIndex) return false; 2228 return VectorIndex.Val < NumLanes; 2229 } 2230 2231 bool isVectorIndex8() const { return isVectorIndexInRange<8>(); } 2232 bool isVectorIndex16() const { return isVectorIndexInRange<4>(); } 2233 bool isVectorIndex32() const { return isVectorIndexInRange<2>(); } 2234 bool isVectorIndex64() const { return isVectorIndexInRange<1>(); } 2235 2236 template<int PermittedValue, int OtherPermittedValue> 2237 bool isMVEPairVectorIndex() const { 2238 if (Kind != k_VectorIndex) return false; 2239 return VectorIndex.Val == PermittedValue || 2240 VectorIndex.Val == OtherPermittedValue; 2241 } 2242 2243 bool isNEONi8splat() const { 2244 if (!isImm()) return false; 2245 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2246 // Must be a constant. 2247 if (!CE) return false; 2248 int64_t Value = CE->getValue(); 2249 // i8 value splatted across 8 bytes. The immediate is just the 8 byte 2250 // value. 2251 return Value >= 0 && Value < 256; 2252 } 2253 2254 bool isNEONi16splat() const { 2255 if (isNEONByteReplicate(2)) 2256 return false; // Leave that for bytes replication and forbid by default. 2257 if (!isImm()) 2258 return false; 2259 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2260 // Must be a constant. 2261 if (!CE) return false; 2262 unsigned Value = CE->getValue(); 2263 return ARM_AM::isNEONi16splat(Value); 2264 } 2265 2266 bool isNEONi16splatNot() const { 2267 if (!isImm()) 2268 return false; 2269 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2270 // Must be a constant. 2271 if (!CE) return false; 2272 unsigned Value = CE->getValue(); 2273 return ARM_AM::isNEONi16splat(~Value & 0xffff); 2274 } 2275 2276 bool isNEONi32splat() const { 2277 if (isNEONByteReplicate(4)) 2278 return false; // Leave that for bytes replication and forbid by default. 2279 if (!isImm()) 2280 return false; 2281 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2282 // Must be a constant. 2283 if (!CE) return false; 2284 unsigned Value = CE->getValue(); 2285 return ARM_AM::isNEONi32splat(Value); 2286 } 2287 2288 bool isNEONi32splatNot() const { 2289 if (!isImm()) 2290 return false; 2291 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2292 // Must be a constant. 2293 if (!CE) return false; 2294 unsigned Value = CE->getValue(); 2295 return ARM_AM::isNEONi32splat(~Value); 2296 } 2297 2298 static bool isValidNEONi32vmovImm(int64_t Value) { 2299 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, 2300 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. 2301 return ((Value & 0xffffffffffffff00) == 0) || 2302 ((Value & 0xffffffffffff00ff) == 0) || 2303 ((Value & 0xffffffffff00ffff) == 0) || 2304 ((Value & 0xffffffff00ffffff) == 0) || 2305 ((Value & 0xffffffffffff00ff) == 0xff) || 2306 ((Value & 0xffffffffff00ffff) == 0xffff); 2307 } 2308 2309 bool isNEONReplicate(unsigned Width, unsigned NumElems, bool Inv) const { 2310 assert((Width == 8 || Width == 16 || Width == 32) && 2311 "Invalid element width"); 2312 assert(NumElems * Width <= 64 && "Invalid result width"); 2313 2314 if (!isImm()) 2315 return false; 2316 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2317 // Must be a constant. 2318 if (!CE) 2319 return false; 2320 int64_t Value = CE->getValue(); 2321 if (!Value) 2322 return false; // Don't bother with zero. 2323 if (Inv) 2324 Value = ~Value; 2325 2326 uint64_t Mask = (1ull << Width) - 1; 2327 uint64_t Elem = Value & Mask; 2328 if (Width == 16 && (Elem & 0x00ff) != 0 && (Elem & 0xff00) != 0) 2329 return false; 2330 if (Width == 32 && !isValidNEONi32vmovImm(Elem)) 2331 return false; 2332 2333 for (unsigned i = 1; i < NumElems; ++i) { 2334 Value >>= Width; 2335 if ((Value & Mask) != Elem) 2336 return false; 2337 } 2338 return true; 2339 } 2340 2341 bool isNEONByteReplicate(unsigned NumBytes) const { 2342 return isNEONReplicate(8, NumBytes, false); 2343 } 2344 2345 static void checkNeonReplicateArgs(unsigned FromW, unsigned ToW) { 2346 assert((FromW == 8 || FromW == 16 || FromW == 32) && 2347 "Invalid source width"); 2348 assert((ToW == 16 || ToW == 32 || ToW == 64) && 2349 "Invalid destination width"); 2350 assert(FromW < ToW && "ToW is not less than FromW"); 2351 } 2352 2353 template<unsigned FromW, unsigned ToW> 2354 bool isNEONmovReplicate() const { 2355 checkNeonReplicateArgs(FromW, ToW); 2356 if (ToW == 64 && isNEONi64splat()) 2357 return false; 2358 return isNEONReplicate(FromW, ToW / FromW, false); 2359 } 2360 2361 template<unsigned FromW, unsigned ToW> 2362 bool isNEONinvReplicate() const { 2363 checkNeonReplicateArgs(FromW, ToW); 2364 return isNEONReplicate(FromW, ToW / FromW, true); 2365 } 2366 2367 bool isNEONi32vmov() const { 2368 if (isNEONByteReplicate(4)) 2369 return false; // Let it to be classified as byte-replicate case. 2370 if (!isImm()) 2371 return false; 2372 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2373 // Must be a constant. 2374 if (!CE) 2375 return false; 2376 return isValidNEONi32vmovImm(CE->getValue()); 2377 } 2378 2379 bool isNEONi32vmovNeg() const { 2380 if (!isImm()) return false; 2381 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2382 // Must be a constant. 2383 if (!CE) return false; 2384 return isValidNEONi32vmovImm(~CE->getValue()); 2385 } 2386 2387 bool isNEONi64splat() const { 2388 if (!isImm()) return false; 2389 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2390 // Must be a constant. 2391 if (!CE) return false; 2392 uint64_t Value = CE->getValue(); 2393 // i64 value with each byte being either 0 or 0xff. 2394 for (unsigned i = 0; i < 8; ++i, Value >>= 8) 2395 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false; 2396 return true; 2397 } 2398 2399 template<int64_t Angle, int64_t Remainder> 2400 bool isComplexRotation() const { 2401 if (!isImm()) return false; 2402 2403 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2404 if (!CE) return false; 2405 uint64_t Value = CE->getValue(); 2406 2407 return (Value % Angle == Remainder && Value <= 270); 2408 } 2409 2410 bool isMVELongShift() const { 2411 if (!isImm()) return false; 2412 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2413 // Must be a constant. 2414 if (!CE) return false; 2415 uint64_t Value = CE->getValue(); 2416 return Value >= 1 && Value <= 32; 2417 } 2418 2419 bool isMveSaturateOp() const { 2420 if (!isImm()) return false; 2421 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2422 if (!CE) return false; 2423 uint64_t Value = CE->getValue(); 2424 return Value == 48 || Value == 64; 2425 } 2426 2427 bool isITCondCodeNoAL() const { 2428 if (!isITCondCode()) return false; 2429 ARMCC::CondCodes CC = getCondCode(); 2430 return CC != ARMCC::AL; 2431 } 2432 2433 bool isITCondCodeRestrictedI() const { 2434 if (!isITCondCode()) 2435 return false; 2436 ARMCC::CondCodes CC = getCondCode(); 2437 return CC == ARMCC::EQ || CC == ARMCC::NE; 2438 } 2439 2440 bool isITCondCodeRestrictedS() const { 2441 if (!isITCondCode()) 2442 return false; 2443 ARMCC::CondCodes CC = getCondCode(); 2444 return CC == ARMCC::LT || CC == ARMCC::GT || CC == ARMCC::LE || 2445 CC == ARMCC::GE; 2446 } 2447 2448 bool isITCondCodeRestrictedU() const { 2449 if (!isITCondCode()) 2450 return false; 2451 ARMCC::CondCodes CC = getCondCode(); 2452 return CC == ARMCC::HS || CC == ARMCC::HI; 2453 } 2454 2455 bool isITCondCodeRestrictedFP() const { 2456 if (!isITCondCode()) 2457 return false; 2458 ARMCC::CondCodes CC = getCondCode(); 2459 return CC == ARMCC::EQ || CC == ARMCC::NE || CC == ARMCC::LT || 2460 CC == ARMCC::GT || CC == ARMCC::LE || CC == ARMCC::GE; 2461 } 2462 2463 void addExpr(MCInst &Inst, const MCExpr *Expr) const { 2464 // Add as immediates when possible. Null MCExpr = 0. 2465 if (!Expr) 2466 Inst.addOperand(MCOperand::createImm(0)); 2467 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) 2468 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2469 else 2470 Inst.addOperand(MCOperand::createExpr(Expr)); 2471 } 2472 2473 void addARMBranchTargetOperands(MCInst &Inst, unsigned N) const { 2474 assert(N == 1 && "Invalid number of operands!"); 2475 addExpr(Inst, getImm()); 2476 } 2477 2478 void addThumbBranchTargetOperands(MCInst &Inst, unsigned N) const { 2479 assert(N == 1 && "Invalid number of operands!"); 2480 addExpr(Inst, getImm()); 2481 } 2482 2483 void addCondCodeOperands(MCInst &Inst, unsigned N) const { 2484 assert(N == 2 && "Invalid number of operands!"); 2485 Inst.addOperand(MCOperand::createImm(unsigned(getCondCode()))); 2486 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR; 2487 Inst.addOperand(MCOperand::createReg(RegNum)); 2488 } 2489 2490 void addVPTPredNOperands(MCInst &Inst, unsigned N) const { 2491 assert(N == 3 && "Invalid number of operands!"); 2492 Inst.addOperand(MCOperand::createImm(unsigned(getVPTPred()))); 2493 unsigned RegNum = getVPTPred() == ARMVCC::None ? 0: ARM::P0; 2494 Inst.addOperand(MCOperand::createReg(RegNum)); 2495 Inst.addOperand(MCOperand::createReg(0)); 2496 } 2497 2498 void addVPTPredROperands(MCInst &Inst, unsigned N) const { 2499 assert(N == 4 && "Invalid number of operands!"); 2500 addVPTPredNOperands(Inst, N-1); 2501 unsigned RegNum; 2502 if (getVPTPred() == ARMVCC::None) { 2503 RegNum = 0; 2504 } else { 2505 unsigned NextOpIndex = Inst.getNumOperands(); 2506 const MCInstrDesc &MCID = ARMInsts[Inst.getOpcode()]; 2507 int TiedOp = MCID.getOperandConstraint(NextOpIndex, MCOI::TIED_TO); 2508 assert(TiedOp >= 0 && 2509 "Inactive register in vpred_r is not tied to an output!"); 2510 RegNum = Inst.getOperand(TiedOp).getReg(); 2511 } 2512 Inst.addOperand(MCOperand::createReg(RegNum)); 2513 } 2514 2515 void addCoprocNumOperands(MCInst &Inst, unsigned N) const { 2516 assert(N == 1 && "Invalid number of operands!"); 2517 Inst.addOperand(MCOperand::createImm(getCoproc())); 2518 } 2519 2520 void addCoprocRegOperands(MCInst &Inst, unsigned N) const { 2521 assert(N == 1 && "Invalid number of operands!"); 2522 Inst.addOperand(MCOperand::createImm(getCoproc())); 2523 } 2524 2525 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const { 2526 assert(N == 1 && "Invalid number of operands!"); 2527 Inst.addOperand(MCOperand::createImm(CoprocOption.Val)); 2528 } 2529 2530 void addITMaskOperands(MCInst &Inst, unsigned N) const { 2531 assert(N == 1 && "Invalid number of operands!"); 2532 Inst.addOperand(MCOperand::createImm(ITMask.Mask)); 2533 } 2534 2535 void addITCondCodeOperands(MCInst &Inst, unsigned N) const { 2536 assert(N == 1 && "Invalid number of operands!"); 2537 Inst.addOperand(MCOperand::createImm(unsigned(getCondCode()))); 2538 } 2539 2540 void addITCondCodeInvOperands(MCInst &Inst, unsigned N) const { 2541 assert(N == 1 && "Invalid number of operands!"); 2542 Inst.addOperand(MCOperand::createImm(unsigned(ARMCC::getOppositeCondition(getCondCode())))); 2543 } 2544 2545 void addCCOutOperands(MCInst &Inst, unsigned N) const { 2546 assert(N == 1 && "Invalid number of operands!"); 2547 Inst.addOperand(MCOperand::createReg(getReg())); 2548 } 2549 2550 void addRegOperands(MCInst &Inst, unsigned N) const { 2551 assert(N == 1 && "Invalid number of operands!"); 2552 Inst.addOperand(MCOperand::createReg(getReg())); 2553 } 2554 2555 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const { 2556 assert(N == 3 && "Invalid number of operands!"); 2557 assert(isRegShiftedReg() && 2558 "addRegShiftedRegOperands() on non-RegShiftedReg!"); 2559 Inst.addOperand(MCOperand::createReg(RegShiftedReg.SrcReg)); 2560 Inst.addOperand(MCOperand::createReg(RegShiftedReg.ShiftReg)); 2561 Inst.addOperand(MCOperand::createImm( 2562 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm))); 2563 } 2564 2565 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const { 2566 assert(N == 2 && "Invalid number of operands!"); 2567 assert(isRegShiftedImm() && 2568 "addRegShiftedImmOperands() on non-RegShiftedImm!"); 2569 Inst.addOperand(MCOperand::createReg(RegShiftedImm.SrcReg)); 2570 // Shift of #32 is encoded as 0 where permitted 2571 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm); 2572 Inst.addOperand(MCOperand::createImm( 2573 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm))); 2574 } 2575 2576 void addShifterImmOperands(MCInst &Inst, unsigned N) const { 2577 assert(N == 1 && "Invalid number of operands!"); 2578 Inst.addOperand(MCOperand::createImm((ShifterImm.isASR << 5) | 2579 ShifterImm.Imm)); 2580 } 2581 2582 void addRegListOperands(MCInst &Inst, unsigned N) const { 2583 assert(N == 1 && "Invalid number of operands!"); 2584 const SmallVectorImpl<unsigned> &RegList = getRegList(); 2585 for (unsigned Reg : RegList) 2586 Inst.addOperand(MCOperand::createReg(Reg)); 2587 } 2588 2589 void addRegListWithAPSROperands(MCInst &Inst, unsigned N) const { 2590 assert(N == 1 && "Invalid number of operands!"); 2591 const SmallVectorImpl<unsigned> &RegList = getRegList(); 2592 for (unsigned Reg : RegList) 2593 Inst.addOperand(MCOperand::createReg(Reg)); 2594 } 2595 2596 void addDPRRegListOperands(MCInst &Inst, unsigned N) const { 2597 addRegListOperands(Inst, N); 2598 } 2599 2600 void addSPRRegListOperands(MCInst &Inst, unsigned N) const { 2601 addRegListOperands(Inst, N); 2602 } 2603 2604 void addFPSRegListWithVPROperands(MCInst &Inst, unsigned N) const { 2605 addRegListOperands(Inst, N); 2606 } 2607 2608 void addFPDRegListWithVPROperands(MCInst &Inst, unsigned N) const { 2609 addRegListOperands(Inst, N); 2610 } 2611 2612 void addRotImmOperands(MCInst &Inst, unsigned N) const { 2613 assert(N == 1 && "Invalid number of operands!"); 2614 // Encoded as val>>3. The printer handles display as 8, 16, 24. 2615 Inst.addOperand(MCOperand::createImm(RotImm.Imm >> 3)); 2616 } 2617 2618 void addModImmOperands(MCInst &Inst, unsigned N) const { 2619 assert(N == 1 && "Invalid number of operands!"); 2620 2621 // Support for fixups (MCFixup) 2622 if (isImm()) 2623 return addImmOperands(Inst, N); 2624 2625 Inst.addOperand(MCOperand::createImm(ModImm.Bits | (ModImm.Rot << 7))); 2626 } 2627 2628 void addModImmNotOperands(MCInst &Inst, unsigned N) const { 2629 assert(N == 1 && "Invalid number of operands!"); 2630 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2631 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue()); 2632 Inst.addOperand(MCOperand::createImm(Enc)); 2633 } 2634 2635 void addModImmNegOperands(MCInst &Inst, unsigned N) const { 2636 assert(N == 1 && "Invalid number of operands!"); 2637 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2638 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue()); 2639 Inst.addOperand(MCOperand::createImm(Enc)); 2640 } 2641 2642 void addThumbModImmNeg8_255Operands(MCInst &Inst, unsigned N) const { 2643 assert(N == 1 && "Invalid number of operands!"); 2644 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2645 uint32_t Val = -CE->getValue(); 2646 Inst.addOperand(MCOperand::createImm(Val)); 2647 } 2648 2649 void addThumbModImmNeg1_7Operands(MCInst &Inst, unsigned N) const { 2650 assert(N == 1 && "Invalid number of operands!"); 2651 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2652 uint32_t Val = -CE->getValue(); 2653 Inst.addOperand(MCOperand::createImm(Val)); 2654 } 2655 2656 void addBitfieldOperands(MCInst &Inst, unsigned N) const { 2657 assert(N == 1 && "Invalid number of operands!"); 2658 // Munge the lsb/width into a bitfield mask. 2659 unsigned lsb = Bitfield.LSB; 2660 unsigned width = Bitfield.Width; 2661 // Make a 32-bit mask w/ the referenced bits clear and all other bits set. 2662 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >> 2663 (32 - (lsb + width))); 2664 Inst.addOperand(MCOperand::createImm(Mask)); 2665 } 2666 2667 void addImmOperands(MCInst &Inst, unsigned N) const { 2668 assert(N == 1 && "Invalid number of operands!"); 2669 addExpr(Inst, getImm()); 2670 } 2671 2672 void addFBits16Operands(MCInst &Inst, unsigned N) const { 2673 assert(N == 1 && "Invalid number of operands!"); 2674 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2675 Inst.addOperand(MCOperand::createImm(16 - CE->getValue())); 2676 } 2677 2678 void addFBits32Operands(MCInst &Inst, unsigned N) const { 2679 assert(N == 1 && "Invalid number of operands!"); 2680 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2681 Inst.addOperand(MCOperand::createImm(32 - CE->getValue())); 2682 } 2683 2684 void addFPImmOperands(MCInst &Inst, unsigned N) const { 2685 assert(N == 1 && "Invalid number of operands!"); 2686 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2687 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); 2688 Inst.addOperand(MCOperand::createImm(Val)); 2689 } 2690 2691 void addImm8s4Operands(MCInst &Inst, unsigned N) const { 2692 assert(N == 1 && "Invalid number of operands!"); 2693 // FIXME: We really want to scale the value here, but the LDRD/STRD 2694 // instruction don't encode operands that way yet. 2695 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2696 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2697 } 2698 2699 void addImm7s4Operands(MCInst &Inst, unsigned N) const { 2700 assert(N == 1 && "Invalid number of operands!"); 2701 // FIXME: We really want to scale the value here, but the VSTR/VLDR_VSYSR 2702 // instruction don't encode operands that way yet. 2703 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2704 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2705 } 2706 2707 void addImm7Shift0Operands(MCInst &Inst, unsigned N) const { 2708 assert(N == 1 && "Invalid number of operands!"); 2709 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2710 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2711 } 2712 2713 void addImm7Shift1Operands(MCInst &Inst, unsigned N) const { 2714 assert(N == 1 && "Invalid number of operands!"); 2715 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2716 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2717 } 2718 2719 void addImm7Shift2Operands(MCInst &Inst, unsigned N) const { 2720 assert(N == 1 && "Invalid number of operands!"); 2721 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2722 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2723 } 2724 2725 void addImm7Operands(MCInst &Inst, unsigned N) const { 2726 assert(N == 1 && "Invalid number of operands!"); 2727 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2728 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2729 } 2730 2731 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const { 2732 assert(N == 1 && "Invalid number of operands!"); 2733 // The immediate is scaled by four in the encoding and is stored 2734 // in the MCInst as such. Lop off the low two bits here. 2735 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2736 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4)); 2737 } 2738 2739 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const { 2740 assert(N == 1 && "Invalid number of operands!"); 2741 // The immediate is scaled by four in the encoding and is stored 2742 // in the MCInst as such. Lop off the low two bits here. 2743 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2744 Inst.addOperand(MCOperand::createImm(-(CE->getValue() / 4))); 2745 } 2746 2747 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const { 2748 assert(N == 1 && "Invalid number of operands!"); 2749 // The immediate is scaled by four in the encoding and is stored 2750 // in the MCInst as such. Lop off the low two bits here. 2751 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2752 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4)); 2753 } 2754 2755 void addImm1_16Operands(MCInst &Inst, unsigned N) const { 2756 assert(N == 1 && "Invalid number of operands!"); 2757 // The constant encodes as the immediate-1, and we store in the instruction 2758 // the bits as encoded, so subtract off one here. 2759 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2760 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1)); 2761 } 2762 2763 void addImm1_32Operands(MCInst &Inst, unsigned N) const { 2764 assert(N == 1 && "Invalid number of operands!"); 2765 // The constant encodes as the immediate-1, and we store in the instruction 2766 // the bits as encoded, so subtract off one here. 2767 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2768 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1)); 2769 } 2770 2771 void addImmThumbSROperands(MCInst &Inst, unsigned N) const { 2772 assert(N == 1 && "Invalid number of operands!"); 2773 // The constant encodes as the immediate, except for 32, which encodes as 2774 // zero. 2775 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2776 unsigned Imm = CE->getValue(); 2777 Inst.addOperand(MCOperand::createImm((Imm == 32 ? 0 : Imm))); 2778 } 2779 2780 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const { 2781 assert(N == 1 && "Invalid number of operands!"); 2782 // An ASR value of 32 encodes as 0, so that's how we want to add it to 2783 // the instruction as well. 2784 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2785 int Val = CE->getValue(); 2786 Inst.addOperand(MCOperand::createImm(Val == 32 ? 0 : Val)); 2787 } 2788 2789 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const { 2790 assert(N == 1 && "Invalid number of operands!"); 2791 // The operand is actually a t2_so_imm, but we have its bitwise 2792 // negation in the assembly source, so twiddle it here. 2793 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2794 Inst.addOperand(MCOperand::createImm(~(uint32_t)CE->getValue())); 2795 } 2796 2797 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const { 2798 assert(N == 1 && "Invalid number of operands!"); 2799 // The operand is actually a t2_so_imm, but we have its 2800 // negation in the assembly source, so twiddle it here. 2801 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2802 Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue())); 2803 } 2804 2805 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const { 2806 assert(N == 1 && "Invalid number of operands!"); 2807 // The operand is actually an imm0_4095, but we have its 2808 // negation in the assembly source, so twiddle it here. 2809 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2810 Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue())); 2811 } 2812 2813 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const { 2814 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) { 2815 Inst.addOperand(MCOperand::createImm(CE->getValue() >> 2)); 2816 return; 2817 } 2818 const MCSymbolRefExpr *SR = cast<MCSymbolRefExpr>(Imm.Val); 2819 Inst.addOperand(MCOperand::createExpr(SR)); 2820 } 2821 2822 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const { 2823 assert(N == 1 && "Invalid number of operands!"); 2824 if (isImm()) { 2825 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2826 if (CE) { 2827 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2828 return; 2829 } 2830 const MCSymbolRefExpr *SR = cast<MCSymbolRefExpr>(Imm.Val); 2831 Inst.addOperand(MCOperand::createExpr(SR)); 2832 return; 2833 } 2834 2835 assert(isGPRMem() && "Unknown value type!"); 2836 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!"); 2837 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) 2838 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2839 else 2840 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 2841 } 2842 2843 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const { 2844 assert(N == 1 && "Invalid number of operands!"); 2845 Inst.addOperand(MCOperand::createImm(unsigned(getMemBarrierOpt()))); 2846 } 2847 2848 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const { 2849 assert(N == 1 && "Invalid number of operands!"); 2850 Inst.addOperand(MCOperand::createImm(unsigned(getInstSyncBarrierOpt()))); 2851 } 2852 2853 void addTraceSyncBarrierOptOperands(MCInst &Inst, unsigned N) const { 2854 assert(N == 1 && "Invalid number of operands!"); 2855 Inst.addOperand(MCOperand::createImm(unsigned(getTraceSyncBarrierOpt()))); 2856 } 2857 2858 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const { 2859 assert(N == 1 && "Invalid number of operands!"); 2860 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2861 } 2862 2863 void addMemNoOffsetT2Operands(MCInst &Inst, unsigned N) const { 2864 assert(N == 1 && "Invalid number of operands!"); 2865 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2866 } 2867 2868 void addMemNoOffsetT2NoSpOperands(MCInst &Inst, unsigned N) const { 2869 assert(N == 1 && "Invalid number of operands!"); 2870 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2871 } 2872 2873 void addMemNoOffsetTOperands(MCInst &Inst, unsigned N) const { 2874 assert(N == 1 && "Invalid number of operands!"); 2875 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2876 } 2877 2878 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const { 2879 assert(N == 1 && "Invalid number of operands!"); 2880 if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) 2881 Inst.addOperand(MCOperand::createImm(CE->getValue())); 2882 else 2883 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 2884 } 2885 2886 void addAdrLabelOperands(MCInst &Inst, unsigned N) const { 2887 assert(N == 1 && "Invalid number of operands!"); 2888 assert(isImm() && "Not an immediate!"); 2889 2890 // If we have an immediate that's not a constant, treat it as a label 2891 // reference needing a fixup. 2892 if (!isa<MCConstantExpr>(getImm())) { 2893 Inst.addOperand(MCOperand::createExpr(getImm())); 2894 return; 2895 } 2896 2897 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 2898 int Val = CE->getValue(); 2899 Inst.addOperand(MCOperand::createImm(Val)); 2900 } 2901 2902 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const { 2903 assert(N == 2 && "Invalid number of operands!"); 2904 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2905 Inst.addOperand(MCOperand::createImm(Memory.Alignment)); 2906 } 2907 2908 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { 2909 addAlignedMemoryOperands(Inst, N); 2910 } 2911 2912 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { 2913 addAlignedMemoryOperands(Inst, N); 2914 } 2915 2916 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const { 2917 addAlignedMemoryOperands(Inst, N); 2918 } 2919 2920 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const { 2921 addAlignedMemoryOperands(Inst, N); 2922 } 2923 2924 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const { 2925 addAlignedMemoryOperands(Inst, N); 2926 } 2927 2928 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const { 2929 addAlignedMemoryOperands(Inst, N); 2930 } 2931 2932 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const { 2933 addAlignedMemoryOperands(Inst, N); 2934 } 2935 2936 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const { 2937 addAlignedMemoryOperands(Inst, N); 2938 } 2939 2940 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { 2941 addAlignedMemoryOperands(Inst, N); 2942 } 2943 2944 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { 2945 addAlignedMemoryOperands(Inst, N); 2946 } 2947 2948 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const { 2949 addAlignedMemoryOperands(Inst, N); 2950 } 2951 2952 void addAddrMode2Operands(MCInst &Inst, unsigned N) const { 2953 assert(N == 3 && "Invalid number of operands!"); 2954 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2955 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2956 if (!Memory.OffsetRegNum) { 2957 if (!Memory.OffsetImm) 2958 Inst.addOperand(MCOperand::createImm(0)); 2959 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 2960 int32_t Val = CE->getValue(); 2961 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2962 // Special case for #-0 2963 if (Val == std::numeric_limits<int32_t>::min()) 2964 Val = 0; 2965 if (Val < 0) 2966 Val = -Val; 2967 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); 2968 Inst.addOperand(MCOperand::createImm(Val)); 2969 } else 2970 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 2971 } else { 2972 // For register offset, we encode the shift type and negation flag 2973 // here. 2974 int32_t Val = 2975 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 2976 Memory.ShiftImm, Memory.ShiftType); 2977 Inst.addOperand(MCOperand::createImm(Val)); 2978 } 2979 } 2980 2981 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const { 2982 assert(N == 2 && "Invalid number of operands!"); 2983 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2984 assert(CE && "non-constant AM2OffsetImm operand!"); 2985 int32_t Val = CE->getValue(); 2986 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2987 // Special case for #-0 2988 if (Val == std::numeric_limits<int32_t>::min()) Val = 0; 2989 if (Val < 0) Val = -Val; 2990 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); 2991 Inst.addOperand(MCOperand::createReg(0)); 2992 Inst.addOperand(MCOperand::createImm(Val)); 2993 } 2994 2995 void addAddrMode3Operands(MCInst &Inst, unsigned N) const { 2996 assert(N == 3 && "Invalid number of operands!"); 2997 // If we have an immediate that's not a constant, treat it as a label 2998 // reference needing a fixup. If it is a constant, it's something else 2999 // and we reject it. 3000 if (isImm()) { 3001 Inst.addOperand(MCOperand::createExpr(getImm())); 3002 Inst.addOperand(MCOperand::createReg(0)); 3003 Inst.addOperand(MCOperand::createImm(0)); 3004 return; 3005 } 3006 3007 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3008 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 3009 if (!Memory.OffsetRegNum) { 3010 if (!Memory.OffsetImm) 3011 Inst.addOperand(MCOperand::createImm(0)); 3012 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 3013 int32_t Val = CE->getValue(); 3014 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 3015 // Special case for #-0 3016 if (Val == std::numeric_limits<int32_t>::min()) 3017 Val = 0; 3018 if (Val < 0) 3019 Val = -Val; 3020 Val = ARM_AM::getAM3Opc(AddSub, Val); 3021 Inst.addOperand(MCOperand::createImm(Val)); 3022 } else 3023 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 3024 } else { 3025 // For register offset, we encode the shift type and negation flag 3026 // here. 3027 int32_t Val = 3028 ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0); 3029 Inst.addOperand(MCOperand::createImm(Val)); 3030 } 3031 } 3032 3033 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const { 3034 assert(N == 2 && "Invalid number of operands!"); 3035 if (Kind == k_PostIndexRegister) { 3036 int32_t Val = 3037 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0); 3038 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum)); 3039 Inst.addOperand(MCOperand::createImm(Val)); 3040 return; 3041 } 3042 3043 // Constant offset. 3044 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm()); 3045 int32_t Val = CE->getValue(); 3046 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 3047 // Special case for #-0 3048 if (Val == std::numeric_limits<int32_t>::min()) Val = 0; 3049 if (Val < 0) Val = -Val; 3050 Val = ARM_AM::getAM3Opc(AddSub, Val); 3051 Inst.addOperand(MCOperand::createReg(0)); 3052 Inst.addOperand(MCOperand::createImm(Val)); 3053 } 3054 3055 void addAddrMode5Operands(MCInst &Inst, unsigned N) const { 3056 assert(N == 2 && "Invalid number of operands!"); 3057 // If we have an immediate that's not a constant, treat it as a label 3058 // reference needing a fixup. If it is a constant, it's something else 3059 // and we reject it. 3060 if (isImm()) { 3061 Inst.addOperand(MCOperand::createExpr(getImm())); 3062 Inst.addOperand(MCOperand::createImm(0)); 3063 return; 3064 } 3065 3066 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3067 if (!Memory.OffsetImm) 3068 Inst.addOperand(MCOperand::createImm(0)); 3069 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 3070 // The lower two bits are always zero and as such are not encoded. 3071 int32_t Val = CE->getValue() / 4; 3072 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 3073 // Special case for #-0 3074 if (Val == std::numeric_limits<int32_t>::min()) 3075 Val = 0; 3076 if (Val < 0) 3077 Val = -Val; 3078 Val = ARM_AM::getAM5Opc(AddSub, Val); 3079 Inst.addOperand(MCOperand::createImm(Val)); 3080 } else 3081 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 3082 } 3083 3084 void addAddrMode5FP16Operands(MCInst &Inst, unsigned N) const { 3085 assert(N == 2 && "Invalid number of operands!"); 3086 // If we have an immediate that's not a constant, treat it as a label 3087 // reference needing a fixup. If it is a constant, it's something else 3088 // and we reject it. 3089 if (isImm()) { 3090 Inst.addOperand(MCOperand::createExpr(getImm())); 3091 Inst.addOperand(MCOperand::createImm(0)); 3092 return; 3093 } 3094 3095 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3096 // The lower bit is always zero and as such is not encoded. 3097 if (!Memory.OffsetImm) 3098 Inst.addOperand(MCOperand::createImm(0)); 3099 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) { 3100 int32_t Val = CE->getValue() / 2; 3101 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 3102 // Special case for #-0 3103 if (Val == std::numeric_limits<int32_t>::min()) 3104 Val = 0; 3105 if (Val < 0) 3106 Val = -Val; 3107 Val = ARM_AM::getAM5FP16Opc(AddSub, Val); 3108 Inst.addOperand(MCOperand::createImm(Val)); 3109 } else 3110 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 3111 } 3112 3113 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const { 3114 assert(N == 2 && "Invalid number of operands!"); 3115 // If we have an immediate that's not a constant, treat it as a label 3116 // reference needing a fixup. If it is a constant, it's something else 3117 // and we reject it. 3118 if (isImm()) { 3119 Inst.addOperand(MCOperand::createExpr(getImm())); 3120 Inst.addOperand(MCOperand::createImm(0)); 3121 return; 3122 } 3123 3124 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3125 addExpr(Inst, Memory.OffsetImm); 3126 } 3127 3128 void addMemImm7s4OffsetOperands(MCInst &Inst, unsigned N) const { 3129 assert(N == 2 && "Invalid number of operands!"); 3130 // If we have an immediate that's not a constant, treat it as a label 3131 // reference needing a fixup. If it is a constant, it's something else 3132 // and we reject it. 3133 if (isImm()) { 3134 Inst.addOperand(MCOperand::createExpr(getImm())); 3135 Inst.addOperand(MCOperand::createImm(0)); 3136 return; 3137 } 3138 3139 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3140 addExpr(Inst, Memory.OffsetImm); 3141 } 3142 3143 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const { 3144 assert(N == 2 && "Invalid number of operands!"); 3145 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3146 if (!Memory.OffsetImm) 3147 Inst.addOperand(MCOperand::createImm(0)); 3148 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) 3149 // The lower two bits are always zero and as such are not encoded. 3150 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4)); 3151 else 3152 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 3153 } 3154 3155 void addMemImmOffsetOperands(MCInst &Inst, unsigned N) const { 3156 assert(N == 2 && "Invalid number of operands!"); 3157 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3158 addExpr(Inst, Memory.OffsetImm); 3159 } 3160 3161 void addMemRegRQOffsetOperands(MCInst &Inst, unsigned N) const { 3162 assert(N == 2 && "Invalid number of operands!"); 3163 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3164 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 3165 } 3166 3167 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const { 3168 assert(N == 2 && "Invalid number of operands!"); 3169 // If this is an immediate, it's a label reference. 3170 if (isImm()) { 3171 addExpr(Inst, getImm()); 3172 Inst.addOperand(MCOperand::createImm(0)); 3173 return; 3174 } 3175 3176 // Otherwise, it's a normal memory reg+offset. 3177 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3178 addExpr(Inst, Memory.OffsetImm); 3179 } 3180 3181 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const { 3182 assert(N == 2 && "Invalid number of operands!"); 3183 // If this is an immediate, it's a label reference. 3184 if (isImm()) { 3185 addExpr(Inst, getImm()); 3186 Inst.addOperand(MCOperand::createImm(0)); 3187 return; 3188 } 3189 3190 // Otherwise, it's a normal memory reg+offset. 3191 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3192 addExpr(Inst, Memory.OffsetImm); 3193 } 3194 3195 void addConstPoolAsmImmOperands(MCInst &Inst, unsigned N) const { 3196 assert(N == 1 && "Invalid number of operands!"); 3197 // This is container for the immediate that we will create the constant 3198 // pool from 3199 addExpr(Inst, getConstantPoolImm()); 3200 } 3201 3202 void addMemTBBOperands(MCInst &Inst, unsigned N) const { 3203 assert(N == 2 && "Invalid number of operands!"); 3204 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3205 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 3206 } 3207 3208 void addMemTBHOperands(MCInst &Inst, unsigned N) const { 3209 assert(N == 2 && "Invalid number of operands!"); 3210 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3211 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 3212 } 3213 3214 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const { 3215 assert(N == 3 && "Invalid number of operands!"); 3216 unsigned Val = 3217 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 3218 Memory.ShiftImm, Memory.ShiftType); 3219 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3220 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 3221 Inst.addOperand(MCOperand::createImm(Val)); 3222 } 3223 3224 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const { 3225 assert(N == 3 && "Invalid number of operands!"); 3226 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3227 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 3228 Inst.addOperand(MCOperand::createImm(Memory.ShiftImm)); 3229 } 3230 3231 void addMemThumbRROperands(MCInst &Inst, unsigned N) const { 3232 assert(N == 2 && "Invalid number of operands!"); 3233 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3234 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 3235 } 3236 3237 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const { 3238 assert(N == 2 && "Invalid number of operands!"); 3239 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3240 if (!Memory.OffsetImm) 3241 Inst.addOperand(MCOperand::createImm(0)); 3242 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) 3243 // The lower two bits are always zero and as such are not encoded. 3244 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4)); 3245 else 3246 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 3247 } 3248 3249 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const { 3250 assert(N == 2 && "Invalid number of operands!"); 3251 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3252 if (!Memory.OffsetImm) 3253 Inst.addOperand(MCOperand::createImm(0)); 3254 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) 3255 Inst.addOperand(MCOperand::createImm(CE->getValue() / 2)); 3256 else 3257 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 3258 } 3259 3260 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const { 3261 assert(N == 2 && "Invalid number of operands!"); 3262 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3263 addExpr(Inst, Memory.OffsetImm); 3264 } 3265 3266 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const { 3267 assert(N == 2 && "Invalid number of operands!"); 3268 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 3269 if (!Memory.OffsetImm) 3270 Inst.addOperand(MCOperand::createImm(0)); 3271 else if (const auto *CE = dyn_cast<MCConstantExpr>(Memory.OffsetImm)) 3272 // The lower two bits are always zero and as such are not encoded. 3273 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4)); 3274 else 3275 Inst.addOperand(MCOperand::createExpr(Memory.OffsetImm)); 3276 } 3277 3278 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const { 3279 assert(N == 1 && "Invalid number of operands!"); 3280 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 3281 assert(CE && "non-constant post-idx-imm8 operand!"); 3282 int Imm = CE->getValue(); 3283 bool isAdd = Imm >= 0; 3284 if (Imm == std::numeric_limits<int32_t>::min()) Imm = 0; 3285 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8; 3286 Inst.addOperand(MCOperand::createImm(Imm)); 3287 } 3288 3289 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const { 3290 assert(N == 1 && "Invalid number of operands!"); 3291 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 3292 assert(CE && "non-constant post-idx-imm8s4 operand!"); 3293 int Imm = CE->getValue(); 3294 bool isAdd = Imm >= 0; 3295 if (Imm == std::numeric_limits<int32_t>::min()) Imm = 0; 3296 // Immediate is scaled by 4. 3297 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8; 3298 Inst.addOperand(MCOperand::createImm(Imm)); 3299 } 3300 3301 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const { 3302 assert(N == 2 && "Invalid number of operands!"); 3303 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum)); 3304 Inst.addOperand(MCOperand::createImm(PostIdxReg.isAdd)); 3305 } 3306 3307 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const { 3308 assert(N == 2 && "Invalid number of operands!"); 3309 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum)); 3310 // The sign, shift type, and shift amount are encoded in a single operand 3311 // using the AM2 encoding helpers. 3312 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub; 3313 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm, 3314 PostIdxReg.ShiftTy); 3315 Inst.addOperand(MCOperand::createImm(Imm)); 3316 } 3317 3318 void addPowerTwoOperands(MCInst &Inst, unsigned N) const { 3319 assert(N == 1 && "Invalid number of operands!"); 3320 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3321 Inst.addOperand(MCOperand::createImm(CE->getValue())); 3322 } 3323 3324 void addMSRMaskOperands(MCInst &Inst, unsigned N) const { 3325 assert(N == 1 && "Invalid number of operands!"); 3326 Inst.addOperand(MCOperand::createImm(unsigned(getMSRMask()))); 3327 } 3328 3329 void addBankedRegOperands(MCInst &Inst, unsigned N) const { 3330 assert(N == 1 && "Invalid number of operands!"); 3331 Inst.addOperand(MCOperand::createImm(unsigned(getBankedReg()))); 3332 } 3333 3334 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const { 3335 assert(N == 1 && "Invalid number of operands!"); 3336 Inst.addOperand(MCOperand::createImm(unsigned(getProcIFlags()))); 3337 } 3338 3339 void addVecListOperands(MCInst &Inst, unsigned N) const { 3340 assert(N == 1 && "Invalid number of operands!"); 3341 Inst.addOperand(MCOperand::createReg(VectorList.RegNum)); 3342 } 3343 3344 void addMVEVecListOperands(MCInst &Inst, unsigned N) const { 3345 assert(N == 1 && "Invalid number of operands!"); 3346 3347 // When we come here, the VectorList field will identify a range 3348 // of q-registers by its base register and length, and it will 3349 // have already been error-checked to be the expected length of 3350 // range and contain only q-regs in the range q0-q7. So we can 3351 // count on the base register being in the range q0-q6 (for 2 3352 // regs) or q0-q4 (for 4) 3353 // 3354 // The MVE instructions taking a register range of this kind will 3355 // need an operand in the MQQPR or MQQQQPR class, representing the 3356 // entire range as a unit. So we must translate into that class, 3357 // by finding the index of the base register in the MQPR reg 3358 // class, and returning the super-register at the corresponding 3359 // index in the target class. 3360 3361 const MCRegisterClass *RC_in = &ARMMCRegisterClasses[ARM::MQPRRegClassID]; 3362 const MCRegisterClass *RC_out = 3363 (VectorList.Count == 2) ? &ARMMCRegisterClasses[ARM::MQQPRRegClassID] 3364 : &ARMMCRegisterClasses[ARM::MQQQQPRRegClassID]; 3365 3366 unsigned I, E = RC_out->getNumRegs(); 3367 for (I = 0; I < E; I++) 3368 if (RC_in->getRegister(I) == VectorList.RegNum) 3369 break; 3370 assert(I < E && "Invalid vector list start register!"); 3371 3372 Inst.addOperand(MCOperand::createReg(RC_out->getRegister(I))); 3373 } 3374 3375 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const { 3376 assert(N == 2 && "Invalid number of operands!"); 3377 Inst.addOperand(MCOperand::createReg(VectorList.RegNum)); 3378 Inst.addOperand(MCOperand::createImm(VectorList.LaneIndex)); 3379 } 3380 3381 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const { 3382 assert(N == 1 && "Invalid number of operands!"); 3383 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 3384 } 3385 3386 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const { 3387 assert(N == 1 && "Invalid number of operands!"); 3388 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 3389 } 3390 3391 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const { 3392 assert(N == 1 && "Invalid number of operands!"); 3393 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 3394 } 3395 3396 void addVectorIndex64Operands(MCInst &Inst, unsigned N) const { 3397 assert(N == 1 && "Invalid number of operands!"); 3398 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 3399 } 3400 3401 void addMVEVectorIndexOperands(MCInst &Inst, unsigned N) const { 3402 assert(N == 1 && "Invalid number of operands!"); 3403 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 3404 } 3405 3406 void addMVEPairVectorIndexOperands(MCInst &Inst, unsigned N) const { 3407 assert(N == 1 && "Invalid number of operands!"); 3408 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 3409 } 3410 3411 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const { 3412 assert(N == 1 && "Invalid number of operands!"); 3413 // The immediate encodes the type of constant as well as the value. 3414 // Mask in that this is an i8 splat. 3415 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3416 Inst.addOperand(MCOperand::createImm(CE->getValue() | 0xe00)); 3417 } 3418 3419 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const { 3420 assert(N == 1 && "Invalid number of operands!"); 3421 // The immediate encodes the type of constant as well as the value. 3422 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3423 unsigned Value = CE->getValue(); 3424 Value = ARM_AM::encodeNEONi16splat(Value); 3425 Inst.addOperand(MCOperand::createImm(Value)); 3426 } 3427 3428 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const { 3429 assert(N == 1 && "Invalid number of operands!"); 3430 // The immediate encodes the type of constant as well as the value. 3431 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3432 unsigned Value = CE->getValue(); 3433 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff); 3434 Inst.addOperand(MCOperand::createImm(Value)); 3435 } 3436 3437 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const { 3438 assert(N == 1 && "Invalid number of operands!"); 3439 // The immediate encodes the type of constant as well as the value. 3440 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3441 unsigned Value = CE->getValue(); 3442 Value = ARM_AM::encodeNEONi32splat(Value); 3443 Inst.addOperand(MCOperand::createImm(Value)); 3444 } 3445 3446 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const { 3447 assert(N == 1 && "Invalid number of operands!"); 3448 // The immediate encodes the type of constant as well as the value. 3449 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3450 unsigned Value = CE->getValue(); 3451 Value = ARM_AM::encodeNEONi32splat(~Value); 3452 Inst.addOperand(MCOperand::createImm(Value)); 3453 } 3454 3455 void addNEONi8ReplicateOperands(MCInst &Inst, bool Inv) const { 3456 // The immediate encodes the type of constant as well as the value. 3457 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3458 assert((Inst.getOpcode() == ARM::VMOVv8i8 || 3459 Inst.getOpcode() == ARM::VMOVv16i8) && 3460 "All instructions that wants to replicate non-zero byte " 3461 "always must be replaced with VMOVv8i8 or VMOVv16i8."); 3462 unsigned Value = CE->getValue(); 3463 if (Inv) 3464 Value = ~Value; 3465 unsigned B = Value & 0xff; 3466 B |= 0xe00; // cmode = 0b1110 3467 Inst.addOperand(MCOperand::createImm(B)); 3468 } 3469 3470 void addNEONinvi8ReplicateOperands(MCInst &Inst, unsigned N) const { 3471 assert(N == 1 && "Invalid number of operands!"); 3472 addNEONi8ReplicateOperands(Inst, true); 3473 } 3474 3475 static unsigned encodeNeonVMOVImmediate(unsigned Value) { 3476 if (Value >= 256 && Value <= 0xffff) 3477 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); 3478 else if (Value > 0xffff && Value <= 0xffffff) 3479 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); 3480 else if (Value > 0xffffff) 3481 Value = (Value >> 24) | 0x600; 3482 return Value; 3483 } 3484 3485 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const { 3486 assert(N == 1 && "Invalid number of operands!"); 3487 // The immediate encodes the type of constant as well as the value. 3488 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3489 unsigned Value = encodeNeonVMOVImmediate(CE->getValue()); 3490 Inst.addOperand(MCOperand::createImm(Value)); 3491 } 3492 3493 void addNEONvmovi8ReplicateOperands(MCInst &Inst, unsigned N) const { 3494 assert(N == 1 && "Invalid number of operands!"); 3495 addNEONi8ReplicateOperands(Inst, false); 3496 } 3497 3498 void addNEONvmovi16ReplicateOperands(MCInst &Inst, unsigned N) const { 3499 assert(N == 1 && "Invalid number of operands!"); 3500 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3501 assert((Inst.getOpcode() == ARM::VMOVv4i16 || 3502 Inst.getOpcode() == ARM::VMOVv8i16 || 3503 Inst.getOpcode() == ARM::VMVNv4i16 || 3504 Inst.getOpcode() == ARM::VMVNv8i16) && 3505 "All instructions that want to replicate non-zero half-word " 3506 "always must be replaced with V{MOV,MVN}v{4,8}i16."); 3507 uint64_t Value = CE->getValue(); 3508 unsigned Elem = Value & 0xffff; 3509 if (Elem >= 256) 3510 Elem = (Elem >> 8) | 0x200; 3511 Inst.addOperand(MCOperand::createImm(Elem)); 3512 } 3513 3514 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const { 3515 assert(N == 1 && "Invalid number of operands!"); 3516 // The immediate encodes the type of constant as well as the value. 3517 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3518 unsigned Value = encodeNeonVMOVImmediate(~CE->getValue()); 3519 Inst.addOperand(MCOperand::createImm(Value)); 3520 } 3521 3522 void addNEONvmovi32ReplicateOperands(MCInst &Inst, unsigned N) const { 3523 assert(N == 1 && "Invalid number of operands!"); 3524 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3525 assert((Inst.getOpcode() == ARM::VMOVv2i32 || 3526 Inst.getOpcode() == ARM::VMOVv4i32 || 3527 Inst.getOpcode() == ARM::VMVNv2i32 || 3528 Inst.getOpcode() == ARM::VMVNv4i32) && 3529 "All instructions that want to replicate non-zero word " 3530 "always must be replaced with V{MOV,MVN}v{2,4}i32."); 3531 uint64_t Value = CE->getValue(); 3532 unsigned Elem = encodeNeonVMOVImmediate(Value & 0xffffffff); 3533 Inst.addOperand(MCOperand::createImm(Elem)); 3534 } 3535 3536 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const { 3537 assert(N == 1 && "Invalid number of operands!"); 3538 // The immediate encodes the type of constant as well as the value. 3539 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3540 uint64_t Value = CE->getValue(); 3541 unsigned Imm = 0; 3542 for (unsigned i = 0; i < 8; ++i, Value >>= 8) { 3543 Imm |= (Value & 1) << i; 3544 } 3545 Inst.addOperand(MCOperand::createImm(Imm | 0x1e00)); 3546 } 3547 3548 void addComplexRotationEvenOperands(MCInst &Inst, unsigned N) const { 3549 assert(N == 1 && "Invalid number of operands!"); 3550 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3551 Inst.addOperand(MCOperand::createImm(CE->getValue() / 90)); 3552 } 3553 3554 void addComplexRotationOddOperands(MCInst &Inst, unsigned N) const { 3555 assert(N == 1 && "Invalid number of operands!"); 3556 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3557 Inst.addOperand(MCOperand::createImm((CE->getValue() - 90) / 180)); 3558 } 3559 3560 void addMveSaturateOperands(MCInst &Inst, unsigned N) const { 3561 assert(N == 1 && "Invalid number of operands!"); 3562 const MCConstantExpr *CE = cast<MCConstantExpr>(getImm()); 3563 unsigned Imm = CE->getValue(); 3564 assert((Imm == 48 || Imm == 64) && "Invalid saturate operand"); 3565 Inst.addOperand(MCOperand::createImm(Imm == 48 ? 1 : 0)); 3566 } 3567 3568 void print(raw_ostream &OS) const override; 3569 3570 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) { 3571 auto Op = std::make_unique<ARMOperand>(k_ITCondMask); 3572 Op->ITMask.Mask = Mask; 3573 Op->StartLoc = S; 3574 Op->EndLoc = S; 3575 return Op; 3576 } 3577 3578 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC, 3579 SMLoc S) { 3580 auto Op = std::make_unique<ARMOperand>(k_CondCode); 3581 Op->CC.Val = CC; 3582 Op->StartLoc = S; 3583 Op->EndLoc = S; 3584 return Op; 3585 } 3586 3587 static std::unique_ptr<ARMOperand> CreateVPTPred(ARMVCC::VPTCodes CC, 3588 SMLoc S) { 3589 auto Op = std::make_unique<ARMOperand>(k_VPTPred); 3590 Op->VCC.Val = CC; 3591 Op->StartLoc = S; 3592 Op->EndLoc = S; 3593 return Op; 3594 } 3595 3596 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) { 3597 auto Op = std::make_unique<ARMOperand>(k_CoprocNum); 3598 Op->Cop.Val = CopVal; 3599 Op->StartLoc = S; 3600 Op->EndLoc = S; 3601 return Op; 3602 } 3603 3604 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) { 3605 auto Op = std::make_unique<ARMOperand>(k_CoprocReg); 3606 Op->Cop.Val = CopVal; 3607 Op->StartLoc = S; 3608 Op->EndLoc = S; 3609 return Op; 3610 } 3611 3612 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S, 3613 SMLoc E) { 3614 auto Op = std::make_unique<ARMOperand>(k_CoprocOption); 3615 Op->Cop.Val = Val; 3616 Op->StartLoc = S; 3617 Op->EndLoc = E; 3618 return Op; 3619 } 3620 3621 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) { 3622 auto Op = std::make_unique<ARMOperand>(k_CCOut); 3623 Op->Reg.RegNum = RegNum; 3624 Op->StartLoc = S; 3625 Op->EndLoc = S; 3626 return Op; 3627 } 3628 3629 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) { 3630 auto Op = std::make_unique<ARMOperand>(k_Token); 3631 Op->Tok.Data = Str.data(); 3632 Op->Tok.Length = Str.size(); 3633 Op->StartLoc = S; 3634 Op->EndLoc = S; 3635 return Op; 3636 } 3637 3638 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S, 3639 SMLoc E) { 3640 auto Op = std::make_unique<ARMOperand>(k_Register); 3641 Op->Reg.RegNum = RegNum; 3642 Op->StartLoc = S; 3643 Op->EndLoc = E; 3644 return Op; 3645 } 3646 3647 static std::unique_ptr<ARMOperand> 3648 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, 3649 unsigned ShiftReg, unsigned ShiftImm, SMLoc S, 3650 SMLoc E) { 3651 auto Op = std::make_unique<ARMOperand>(k_ShiftedRegister); 3652 Op->RegShiftedReg.ShiftTy = ShTy; 3653 Op->RegShiftedReg.SrcReg = SrcReg; 3654 Op->RegShiftedReg.ShiftReg = ShiftReg; 3655 Op->RegShiftedReg.ShiftImm = ShiftImm; 3656 Op->StartLoc = S; 3657 Op->EndLoc = E; 3658 return Op; 3659 } 3660 3661 static std::unique_ptr<ARMOperand> 3662 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, 3663 unsigned ShiftImm, SMLoc S, SMLoc E) { 3664 auto Op = std::make_unique<ARMOperand>(k_ShiftedImmediate); 3665 Op->RegShiftedImm.ShiftTy = ShTy; 3666 Op->RegShiftedImm.SrcReg = SrcReg; 3667 Op->RegShiftedImm.ShiftImm = ShiftImm; 3668 Op->StartLoc = S; 3669 Op->EndLoc = E; 3670 return Op; 3671 } 3672 3673 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm, 3674 SMLoc S, SMLoc E) { 3675 auto Op = std::make_unique<ARMOperand>(k_ShifterImmediate); 3676 Op->ShifterImm.isASR = isASR; 3677 Op->ShifterImm.Imm = Imm; 3678 Op->StartLoc = S; 3679 Op->EndLoc = E; 3680 return Op; 3681 } 3682 3683 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S, 3684 SMLoc E) { 3685 auto Op = std::make_unique<ARMOperand>(k_RotateImmediate); 3686 Op->RotImm.Imm = Imm; 3687 Op->StartLoc = S; 3688 Op->EndLoc = E; 3689 return Op; 3690 } 3691 3692 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot, 3693 SMLoc S, SMLoc E) { 3694 auto Op = std::make_unique<ARMOperand>(k_ModifiedImmediate); 3695 Op->ModImm.Bits = Bits; 3696 Op->ModImm.Rot = Rot; 3697 Op->StartLoc = S; 3698 Op->EndLoc = E; 3699 return Op; 3700 } 3701 3702 static std::unique_ptr<ARMOperand> 3703 CreateConstantPoolImm(const MCExpr *Val, SMLoc S, SMLoc E) { 3704 auto Op = std::make_unique<ARMOperand>(k_ConstantPoolImmediate); 3705 Op->Imm.Val = Val; 3706 Op->StartLoc = S; 3707 Op->EndLoc = E; 3708 return Op; 3709 } 3710 3711 static std::unique_ptr<ARMOperand> 3712 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) { 3713 auto Op = std::make_unique<ARMOperand>(k_BitfieldDescriptor); 3714 Op->Bitfield.LSB = LSB; 3715 Op->Bitfield.Width = Width; 3716 Op->StartLoc = S; 3717 Op->EndLoc = E; 3718 return Op; 3719 } 3720 3721 static std::unique_ptr<ARMOperand> 3722 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs, 3723 SMLoc StartLoc, SMLoc EndLoc) { 3724 assert(Regs.size() > 0 && "RegList contains no registers?"); 3725 KindTy Kind = k_RegisterList; 3726 3727 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains( 3728 Regs.front().second)) { 3729 if (Regs.back().second == ARM::VPR) 3730 Kind = k_FPDRegisterListWithVPR; 3731 else 3732 Kind = k_DPRRegisterList; 3733 } else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains( 3734 Regs.front().second)) { 3735 if (Regs.back().second == ARM::VPR) 3736 Kind = k_FPSRegisterListWithVPR; 3737 else 3738 Kind = k_SPRRegisterList; 3739 } 3740 3741 if (Kind == k_RegisterList && Regs.back().second == ARM::APSR) 3742 Kind = k_RegisterListWithAPSR; 3743 3744 assert(llvm::is_sorted(Regs) && "Register list must be sorted by encoding"); 3745 3746 auto Op = std::make_unique<ARMOperand>(Kind); 3747 for (const auto &P : Regs) 3748 Op->Registers.push_back(P.second); 3749 3750 Op->StartLoc = StartLoc; 3751 Op->EndLoc = EndLoc; 3752 return Op; 3753 } 3754 3755 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum, 3756 unsigned Count, 3757 bool isDoubleSpaced, 3758 SMLoc S, SMLoc E) { 3759 auto Op = std::make_unique<ARMOperand>(k_VectorList); 3760 Op->VectorList.RegNum = RegNum; 3761 Op->VectorList.Count = Count; 3762 Op->VectorList.isDoubleSpaced = isDoubleSpaced; 3763 Op->StartLoc = S; 3764 Op->EndLoc = E; 3765 return Op; 3766 } 3767 3768 static std::unique_ptr<ARMOperand> 3769 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced, 3770 SMLoc S, SMLoc E) { 3771 auto Op = std::make_unique<ARMOperand>(k_VectorListAllLanes); 3772 Op->VectorList.RegNum = RegNum; 3773 Op->VectorList.Count = Count; 3774 Op->VectorList.isDoubleSpaced = isDoubleSpaced; 3775 Op->StartLoc = S; 3776 Op->EndLoc = E; 3777 return Op; 3778 } 3779 3780 static std::unique_ptr<ARMOperand> 3781 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index, 3782 bool isDoubleSpaced, SMLoc S, SMLoc E) { 3783 auto Op = std::make_unique<ARMOperand>(k_VectorListIndexed); 3784 Op->VectorList.RegNum = RegNum; 3785 Op->VectorList.Count = Count; 3786 Op->VectorList.LaneIndex = Index; 3787 Op->VectorList.isDoubleSpaced = isDoubleSpaced; 3788 Op->StartLoc = S; 3789 Op->EndLoc = E; 3790 return Op; 3791 } 3792 3793 static std::unique_ptr<ARMOperand> 3794 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) { 3795 auto Op = std::make_unique<ARMOperand>(k_VectorIndex); 3796 Op->VectorIndex.Val = Idx; 3797 Op->StartLoc = S; 3798 Op->EndLoc = E; 3799 return Op; 3800 } 3801 3802 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S, 3803 SMLoc E) { 3804 auto Op = std::make_unique<ARMOperand>(k_Immediate); 3805 Op->Imm.Val = Val; 3806 Op->StartLoc = S; 3807 Op->EndLoc = E; 3808 return Op; 3809 } 3810 3811 static std::unique_ptr<ARMOperand> 3812 CreateMem(unsigned BaseRegNum, const MCExpr *OffsetImm, unsigned OffsetRegNum, 3813 ARM_AM::ShiftOpc ShiftType, unsigned ShiftImm, unsigned Alignment, 3814 bool isNegative, SMLoc S, SMLoc E, SMLoc AlignmentLoc = SMLoc()) { 3815 auto Op = std::make_unique<ARMOperand>(k_Memory); 3816 Op->Memory.BaseRegNum = BaseRegNum; 3817 Op->Memory.OffsetImm = OffsetImm; 3818 Op->Memory.OffsetRegNum = OffsetRegNum; 3819 Op->Memory.ShiftType = ShiftType; 3820 Op->Memory.ShiftImm = ShiftImm; 3821 Op->Memory.Alignment = Alignment; 3822 Op->Memory.isNegative = isNegative; 3823 Op->StartLoc = S; 3824 Op->EndLoc = E; 3825 Op->AlignmentLoc = AlignmentLoc; 3826 return Op; 3827 } 3828 3829 static std::unique_ptr<ARMOperand> 3830 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy, 3831 unsigned ShiftImm, SMLoc S, SMLoc E) { 3832 auto Op = std::make_unique<ARMOperand>(k_PostIndexRegister); 3833 Op->PostIdxReg.RegNum = RegNum; 3834 Op->PostIdxReg.isAdd = isAdd; 3835 Op->PostIdxReg.ShiftTy = ShiftTy; 3836 Op->PostIdxReg.ShiftImm = ShiftImm; 3837 Op->StartLoc = S; 3838 Op->EndLoc = E; 3839 return Op; 3840 } 3841 3842 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, 3843 SMLoc S) { 3844 auto Op = std::make_unique<ARMOperand>(k_MemBarrierOpt); 3845 Op->MBOpt.Val = Opt; 3846 Op->StartLoc = S; 3847 Op->EndLoc = S; 3848 return Op; 3849 } 3850 3851 static std::unique_ptr<ARMOperand> 3852 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) { 3853 auto Op = std::make_unique<ARMOperand>(k_InstSyncBarrierOpt); 3854 Op->ISBOpt.Val = Opt; 3855 Op->StartLoc = S; 3856 Op->EndLoc = S; 3857 return Op; 3858 } 3859 3860 static std::unique_ptr<ARMOperand> 3861 CreateTraceSyncBarrierOpt(ARM_TSB::TraceSyncBOpt Opt, SMLoc S) { 3862 auto Op = std::make_unique<ARMOperand>(k_TraceSyncBarrierOpt); 3863 Op->TSBOpt.Val = Opt; 3864 Op->StartLoc = S; 3865 Op->EndLoc = S; 3866 return Op; 3867 } 3868 3869 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags, 3870 SMLoc S) { 3871 auto Op = std::make_unique<ARMOperand>(k_ProcIFlags); 3872 Op->IFlags.Val = IFlags; 3873 Op->StartLoc = S; 3874 Op->EndLoc = S; 3875 return Op; 3876 } 3877 3878 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) { 3879 auto Op = std::make_unique<ARMOperand>(k_MSRMask); 3880 Op->MMask.Val = MMask; 3881 Op->StartLoc = S; 3882 Op->EndLoc = S; 3883 return Op; 3884 } 3885 3886 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) { 3887 auto Op = std::make_unique<ARMOperand>(k_BankedReg); 3888 Op->BankedReg.Val = Reg; 3889 Op->StartLoc = S; 3890 Op->EndLoc = S; 3891 return Op; 3892 } 3893 }; 3894 3895 } // end anonymous namespace. 3896 3897 void ARMOperand::print(raw_ostream &OS) const { 3898 auto RegName = [](unsigned Reg) { 3899 if (Reg) 3900 return ARMInstPrinter::getRegisterName(Reg); 3901 else 3902 return "noreg"; 3903 }; 3904 3905 switch (Kind) { 3906 case k_CondCode: 3907 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">"; 3908 break; 3909 case k_VPTPred: 3910 OS << "<ARMVCC::" << ARMVPTPredToString(getVPTPred()) << ">"; 3911 break; 3912 case k_CCOut: 3913 OS << "<ccout " << RegName(getReg()) << ">"; 3914 break; 3915 case k_ITCondMask: { 3916 static const char *const MaskStr[] = { 3917 "(invalid)", "(tttt)", "(ttt)", "(ttte)", 3918 "(tt)", "(ttet)", "(tte)", "(ttee)", 3919 "(t)", "(tett)", "(tet)", "(tete)", 3920 "(te)", "(teet)", "(tee)", "(teee)", 3921 }; 3922 assert((ITMask.Mask & 0xf) == ITMask.Mask); 3923 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">"; 3924 break; 3925 } 3926 case k_CoprocNum: 3927 OS << "<coprocessor number: " << getCoproc() << ">"; 3928 break; 3929 case k_CoprocReg: 3930 OS << "<coprocessor register: " << getCoproc() << ">"; 3931 break; 3932 case k_CoprocOption: 3933 OS << "<coprocessor option: " << CoprocOption.Val << ">"; 3934 break; 3935 case k_MSRMask: 3936 OS << "<mask: " << getMSRMask() << ">"; 3937 break; 3938 case k_BankedReg: 3939 OS << "<banked reg: " << getBankedReg() << ">"; 3940 break; 3941 case k_Immediate: 3942 OS << *getImm(); 3943 break; 3944 case k_MemBarrierOpt: 3945 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">"; 3946 break; 3947 case k_InstSyncBarrierOpt: 3948 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">"; 3949 break; 3950 case k_TraceSyncBarrierOpt: 3951 OS << "<ARM_TSB::" << TraceSyncBOptToString(getTraceSyncBarrierOpt()) << ">"; 3952 break; 3953 case k_Memory: 3954 OS << "<memory"; 3955 if (Memory.BaseRegNum) 3956 OS << " base:" << RegName(Memory.BaseRegNum); 3957 if (Memory.OffsetImm) 3958 OS << " offset-imm:" << *Memory.OffsetImm; 3959 if (Memory.OffsetRegNum) 3960 OS << " offset-reg:" << (Memory.isNegative ? "-" : "") 3961 << RegName(Memory.OffsetRegNum); 3962 if (Memory.ShiftType != ARM_AM::no_shift) { 3963 OS << " shift-type:" << ARM_AM::getShiftOpcStr(Memory.ShiftType); 3964 OS << " shift-imm:" << Memory.ShiftImm; 3965 } 3966 if (Memory.Alignment) 3967 OS << " alignment:" << Memory.Alignment; 3968 OS << ">"; 3969 break; 3970 case k_PostIndexRegister: 3971 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-") 3972 << RegName(PostIdxReg.RegNum); 3973 if (PostIdxReg.ShiftTy != ARM_AM::no_shift) 3974 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " " 3975 << PostIdxReg.ShiftImm; 3976 OS << ">"; 3977 break; 3978 case k_ProcIFlags: { 3979 OS << "<ARM_PROC::"; 3980 unsigned IFlags = getProcIFlags(); 3981 for (int i=2; i >= 0; --i) 3982 if (IFlags & (1 << i)) 3983 OS << ARM_PROC::IFlagsToString(1 << i); 3984 OS << ">"; 3985 break; 3986 } 3987 case k_Register: 3988 OS << "<register " << RegName(getReg()) << ">"; 3989 break; 3990 case k_ShifterImmediate: 3991 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl") 3992 << " #" << ShifterImm.Imm << ">"; 3993 break; 3994 case k_ShiftedRegister: 3995 OS << "<so_reg_reg " << RegName(RegShiftedReg.SrcReg) << " " 3996 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy) << " " 3997 << RegName(RegShiftedReg.ShiftReg) << ">"; 3998 break; 3999 case k_ShiftedImmediate: 4000 OS << "<so_reg_imm " << RegName(RegShiftedImm.SrcReg) << " " 4001 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy) << " #" 4002 << RegShiftedImm.ShiftImm << ">"; 4003 break; 4004 case k_RotateImmediate: 4005 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">"; 4006 break; 4007 case k_ModifiedImmediate: 4008 OS << "<mod_imm #" << ModImm.Bits << ", #" 4009 << ModImm.Rot << ")>"; 4010 break; 4011 case k_ConstantPoolImmediate: 4012 OS << "<constant_pool_imm #" << *getConstantPoolImm(); 4013 break; 4014 case k_BitfieldDescriptor: 4015 OS << "<bitfield " << "lsb: " << Bitfield.LSB 4016 << ", width: " << Bitfield.Width << ">"; 4017 break; 4018 case k_RegisterList: 4019 case k_RegisterListWithAPSR: 4020 case k_DPRRegisterList: 4021 case k_SPRRegisterList: 4022 case k_FPSRegisterListWithVPR: 4023 case k_FPDRegisterListWithVPR: { 4024 OS << "<register_list "; 4025 4026 const SmallVectorImpl<unsigned> &RegList = getRegList(); 4027 for (SmallVectorImpl<unsigned>::const_iterator 4028 I = RegList.begin(), E = RegList.end(); I != E; ) { 4029 OS << RegName(*I); 4030 if (++I < E) OS << ", "; 4031 } 4032 4033 OS << ">"; 4034 break; 4035 } 4036 case k_VectorList: 4037 OS << "<vector_list " << VectorList.Count << " * " 4038 << RegName(VectorList.RegNum) << ">"; 4039 break; 4040 case k_VectorListAllLanes: 4041 OS << "<vector_list(all lanes) " << VectorList.Count << " * " 4042 << RegName(VectorList.RegNum) << ">"; 4043 break; 4044 case k_VectorListIndexed: 4045 OS << "<vector_list(lane " << VectorList.LaneIndex << ") " 4046 << VectorList.Count << " * " << RegName(VectorList.RegNum) << ">"; 4047 break; 4048 case k_Token: 4049 OS << "'" << getToken() << "'"; 4050 break; 4051 case k_VectorIndex: 4052 OS << "<vectorindex " << getVectorIndex() << ">"; 4053 break; 4054 } 4055 } 4056 4057 /// @name Auto-generated Match Functions 4058 /// { 4059 4060 static unsigned MatchRegisterName(StringRef Name); 4061 4062 /// } 4063 4064 bool ARMAsmParser::ParseRegister(unsigned &RegNo, 4065 SMLoc &StartLoc, SMLoc &EndLoc) { 4066 const AsmToken &Tok = getParser().getTok(); 4067 StartLoc = Tok.getLoc(); 4068 EndLoc = Tok.getEndLoc(); 4069 RegNo = tryParseRegister(); 4070 4071 return (RegNo == (unsigned)-1); 4072 } 4073 4074 OperandMatchResultTy ARMAsmParser::tryParseRegister(unsigned &RegNo, 4075 SMLoc &StartLoc, 4076 SMLoc &EndLoc) { 4077 if (ParseRegister(RegNo, StartLoc, EndLoc)) 4078 return MatchOperand_NoMatch; 4079 return MatchOperand_Success; 4080 } 4081 4082 /// Try to parse a register name. The token must be an Identifier when called, 4083 /// and if it is a register name the token is eaten and the register number is 4084 /// returned. Otherwise return -1. 4085 int ARMAsmParser::tryParseRegister() { 4086 MCAsmParser &Parser = getParser(); 4087 const AsmToken &Tok = Parser.getTok(); 4088 if (Tok.isNot(AsmToken::Identifier)) return -1; 4089 4090 std::string lowerCase = Tok.getString().lower(); 4091 unsigned RegNum = MatchRegisterName(lowerCase); 4092 if (!RegNum) { 4093 RegNum = StringSwitch<unsigned>(lowerCase) 4094 .Case("r13", ARM::SP) 4095 .Case("r14", ARM::LR) 4096 .Case("r15", ARM::PC) 4097 .Case("ip", ARM::R12) 4098 // Additional register name aliases for 'gas' compatibility. 4099 .Case("a1", ARM::R0) 4100 .Case("a2", ARM::R1) 4101 .Case("a3", ARM::R2) 4102 .Case("a4", ARM::R3) 4103 .Case("v1", ARM::R4) 4104 .Case("v2", ARM::R5) 4105 .Case("v3", ARM::R6) 4106 .Case("v4", ARM::R7) 4107 .Case("v5", ARM::R8) 4108 .Case("v6", ARM::R9) 4109 .Case("v7", ARM::R10) 4110 .Case("v8", ARM::R11) 4111 .Case("sb", ARM::R9) 4112 .Case("sl", ARM::R10) 4113 .Case("fp", ARM::R11) 4114 .Default(0); 4115 } 4116 if (!RegNum) { 4117 // Check for aliases registered via .req. Canonicalize to lower case. 4118 // That's more consistent since register names are case insensitive, and 4119 // it's how the original entry was passed in from MC/MCParser/AsmParser. 4120 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase); 4121 // If no match, return failure. 4122 if (Entry == RegisterReqs.end()) 4123 return -1; 4124 Parser.Lex(); // Eat identifier token. 4125 return Entry->getValue(); 4126 } 4127 4128 // Some FPUs only have 16 D registers, so D16-D31 are invalid 4129 if (!hasD32() && RegNum >= ARM::D16 && RegNum <= ARM::D31) 4130 return -1; 4131 4132 Parser.Lex(); // Eat identifier token. 4133 4134 return RegNum; 4135 } 4136 4137 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0. 4138 // If a recoverable error occurs, return 1. If an irrecoverable error 4139 // occurs, return -1. An irrecoverable error is one where tokens have been 4140 // consumed in the process of trying to parse the shifter (i.e., when it is 4141 // indeed a shifter operand, but malformed). 4142 int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) { 4143 MCAsmParser &Parser = getParser(); 4144 SMLoc S = Parser.getTok().getLoc(); 4145 const AsmToken &Tok = Parser.getTok(); 4146 if (Tok.isNot(AsmToken::Identifier)) 4147 return -1; 4148 4149 std::string lowerCase = Tok.getString().lower(); 4150 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase) 4151 .Case("asl", ARM_AM::lsl) 4152 .Case("lsl", ARM_AM::lsl) 4153 .Case("lsr", ARM_AM::lsr) 4154 .Case("asr", ARM_AM::asr) 4155 .Case("ror", ARM_AM::ror) 4156 .Case("rrx", ARM_AM::rrx) 4157 .Default(ARM_AM::no_shift); 4158 4159 if (ShiftTy == ARM_AM::no_shift) 4160 return 1; 4161 4162 Parser.Lex(); // Eat the operator. 4163 4164 // The source register for the shift has already been added to the 4165 // operand list, so we need to pop it off and combine it into the shifted 4166 // register operand instead. 4167 std::unique_ptr<ARMOperand> PrevOp( 4168 (ARMOperand *)Operands.pop_back_val().release()); 4169 if (!PrevOp->isReg()) 4170 return Error(PrevOp->getStartLoc(), "shift must be of a register"); 4171 int SrcReg = PrevOp->getReg(); 4172 4173 SMLoc EndLoc; 4174 int64_t Imm = 0; 4175 int ShiftReg = 0; 4176 if (ShiftTy == ARM_AM::rrx) { 4177 // RRX Doesn't have an explicit shift amount. The encoder expects 4178 // the shift register to be the same as the source register. Seems odd, 4179 // but OK. 4180 ShiftReg = SrcReg; 4181 } else { 4182 // Figure out if this is shifted by a constant or a register (for non-RRX). 4183 if (Parser.getTok().is(AsmToken::Hash) || 4184 Parser.getTok().is(AsmToken::Dollar)) { 4185 Parser.Lex(); // Eat hash. 4186 SMLoc ImmLoc = Parser.getTok().getLoc(); 4187 const MCExpr *ShiftExpr = nullptr; 4188 if (getParser().parseExpression(ShiftExpr, EndLoc)) { 4189 Error(ImmLoc, "invalid immediate shift value"); 4190 return -1; 4191 } 4192 // The expression must be evaluatable as an immediate. 4193 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr); 4194 if (!CE) { 4195 Error(ImmLoc, "invalid immediate shift value"); 4196 return -1; 4197 } 4198 // Range check the immediate. 4199 // lsl, ror: 0 <= imm <= 31 4200 // lsr, asr: 0 <= imm <= 32 4201 Imm = CE->getValue(); 4202 if (Imm < 0 || 4203 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) || 4204 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) { 4205 Error(ImmLoc, "immediate shift value out of range"); 4206 return -1; 4207 } 4208 // shift by zero is a nop. Always send it through as lsl. 4209 // ('as' compatibility) 4210 if (Imm == 0) 4211 ShiftTy = ARM_AM::lsl; 4212 } else if (Parser.getTok().is(AsmToken::Identifier)) { 4213 SMLoc L = Parser.getTok().getLoc(); 4214 EndLoc = Parser.getTok().getEndLoc(); 4215 ShiftReg = tryParseRegister(); 4216 if (ShiftReg == -1) { 4217 Error(L, "expected immediate or register in shift operand"); 4218 return -1; 4219 } 4220 } else { 4221 Error(Parser.getTok().getLoc(), 4222 "expected immediate or register in shift operand"); 4223 return -1; 4224 } 4225 } 4226 4227 if (ShiftReg && ShiftTy != ARM_AM::rrx) 4228 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg, 4229 ShiftReg, Imm, 4230 S, EndLoc)); 4231 else 4232 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm, 4233 S, EndLoc)); 4234 4235 return 0; 4236 } 4237 4238 /// Try to parse a register name. The token must be an Identifier when called. 4239 /// If it's a register, an AsmOperand is created. Another AsmOperand is created 4240 /// if there is a "writeback". 'true' if it's not a register. 4241 /// 4242 /// TODO this is likely to change to allow different register types and or to 4243 /// parse for a specific register type. 4244 bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) { 4245 MCAsmParser &Parser = getParser(); 4246 SMLoc RegStartLoc = Parser.getTok().getLoc(); 4247 SMLoc RegEndLoc = Parser.getTok().getEndLoc(); 4248 int RegNo = tryParseRegister(); 4249 if (RegNo == -1) 4250 return true; 4251 4252 Operands.push_back(ARMOperand::CreateReg(RegNo, RegStartLoc, RegEndLoc)); 4253 4254 const AsmToken &ExclaimTok = Parser.getTok(); 4255 if (ExclaimTok.is(AsmToken::Exclaim)) { 4256 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(), 4257 ExclaimTok.getLoc())); 4258 Parser.Lex(); // Eat exclaim token 4259 return false; 4260 } 4261 4262 // Also check for an index operand. This is only legal for vector registers, 4263 // but that'll get caught OK in operand matching, so we don't need to 4264 // explicitly filter everything else out here. 4265 if (Parser.getTok().is(AsmToken::LBrac)) { 4266 SMLoc SIdx = Parser.getTok().getLoc(); 4267 Parser.Lex(); // Eat left bracket token. 4268 4269 const MCExpr *ImmVal; 4270 if (getParser().parseExpression(ImmVal)) 4271 return true; 4272 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal); 4273 if (!MCE) 4274 return TokError("immediate value expected for vector index"); 4275 4276 if (Parser.getTok().isNot(AsmToken::RBrac)) 4277 return Error(Parser.getTok().getLoc(), "']' expected"); 4278 4279 SMLoc E = Parser.getTok().getEndLoc(); 4280 Parser.Lex(); // Eat right bracket token. 4281 4282 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(), 4283 SIdx, E, 4284 getContext())); 4285 } 4286 4287 return false; 4288 } 4289 4290 /// MatchCoprocessorOperandName - Try to parse an coprocessor related 4291 /// instruction with a symbolic operand name. 4292 /// We accept "crN" syntax for GAS compatibility. 4293 /// <operand-name> ::= <prefix><number> 4294 /// If CoprocOp is 'c', then: 4295 /// <prefix> ::= c | cr 4296 /// If CoprocOp is 'p', then : 4297 /// <prefix> ::= p 4298 /// <number> ::= integer in range [0, 15] 4299 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) { 4300 // Use the same layout as the tablegen'erated register name matcher. Ugly, 4301 // but efficient. 4302 if (Name.size() < 2 || Name[0] != CoprocOp) 4303 return -1; 4304 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front(); 4305 4306 switch (Name.size()) { 4307 default: return -1; 4308 case 1: 4309 switch (Name[0]) { 4310 default: return -1; 4311 case '0': return 0; 4312 case '1': return 1; 4313 case '2': return 2; 4314 case '3': return 3; 4315 case '4': return 4; 4316 case '5': return 5; 4317 case '6': return 6; 4318 case '7': return 7; 4319 case '8': return 8; 4320 case '9': return 9; 4321 } 4322 case 2: 4323 if (Name[0] != '1') 4324 return -1; 4325 switch (Name[1]) { 4326 default: return -1; 4327 // CP10 and CP11 are VFP/NEON and so vector instructions should be used. 4328 // However, old cores (v5/v6) did use them in that way. 4329 case '0': return 10; 4330 case '1': return 11; 4331 case '2': return 12; 4332 case '3': return 13; 4333 case '4': return 14; 4334 case '5': return 15; 4335 } 4336 } 4337 } 4338 4339 /// parseITCondCode - Try to parse a condition code for an IT instruction. 4340 OperandMatchResultTy 4341 ARMAsmParser::parseITCondCode(OperandVector &Operands) { 4342 MCAsmParser &Parser = getParser(); 4343 SMLoc S = Parser.getTok().getLoc(); 4344 const AsmToken &Tok = Parser.getTok(); 4345 if (!Tok.is(AsmToken::Identifier)) 4346 return MatchOperand_NoMatch; 4347 unsigned CC = ARMCondCodeFromString(Tok.getString()); 4348 if (CC == ~0U) 4349 return MatchOperand_NoMatch; 4350 Parser.Lex(); // Eat the token. 4351 4352 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S)); 4353 4354 return MatchOperand_Success; 4355 } 4356 4357 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The 4358 /// token must be an Identifier when called, and if it is a coprocessor 4359 /// number, the token is eaten and the operand is added to the operand list. 4360 OperandMatchResultTy 4361 ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) { 4362 MCAsmParser &Parser = getParser(); 4363 SMLoc S = Parser.getTok().getLoc(); 4364 const AsmToken &Tok = Parser.getTok(); 4365 if (Tok.isNot(AsmToken::Identifier)) 4366 return MatchOperand_NoMatch; 4367 4368 int Num = MatchCoprocessorOperandName(Tok.getString().lower(), 'p'); 4369 if (Num == -1) 4370 return MatchOperand_NoMatch; 4371 if (!isValidCoprocessorNumber(Num, getSTI().getFeatureBits())) 4372 return MatchOperand_NoMatch; 4373 4374 Parser.Lex(); // Eat identifier token. 4375 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S)); 4376 return MatchOperand_Success; 4377 } 4378 4379 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The 4380 /// token must be an Identifier when called, and if it is a coprocessor 4381 /// number, the token is eaten and the operand is added to the operand list. 4382 OperandMatchResultTy 4383 ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) { 4384 MCAsmParser &Parser = getParser(); 4385 SMLoc S = Parser.getTok().getLoc(); 4386 const AsmToken &Tok = Parser.getTok(); 4387 if (Tok.isNot(AsmToken::Identifier)) 4388 return MatchOperand_NoMatch; 4389 4390 int Reg = MatchCoprocessorOperandName(Tok.getString().lower(), 'c'); 4391 if (Reg == -1) 4392 return MatchOperand_NoMatch; 4393 4394 Parser.Lex(); // Eat identifier token. 4395 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S)); 4396 return MatchOperand_Success; 4397 } 4398 4399 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand. 4400 /// coproc_option : '{' imm0_255 '}' 4401 OperandMatchResultTy 4402 ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) { 4403 MCAsmParser &Parser = getParser(); 4404 SMLoc S = Parser.getTok().getLoc(); 4405 4406 // If this isn't a '{', this isn't a coprocessor immediate operand. 4407 if (Parser.getTok().isNot(AsmToken::LCurly)) 4408 return MatchOperand_NoMatch; 4409 Parser.Lex(); // Eat the '{' 4410 4411 const MCExpr *Expr; 4412 SMLoc Loc = Parser.getTok().getLoc(); 4413 if (getParser().parseExpression(Expr)) { 4414 Error(Loc, "illegal expression"); 4415 return MatchOperand_ParseFail; 4416 } 4417 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); 4418 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) { 4419 Error(Loc, "coprocessor option must be an immediate in range [0, 255]"); 4420 return MatchOperand_ParseFail; 4421 } 4422 int Val = CE->getValue(); 4423 4424 // Check for and consume the closing '}' 4425 if (Parser.getTok().isNot(AsmToken::RCurly)) 4426 return MatchOperand_ParseFail; 4427 SMLoc E = Parser.getTok().getEndLoc(); 4428 Parser.Lex(); // Eat the '}' 4429 4430 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E)); 4431 return MatchOperand_Success; 4432 } 4433 4434 // For register list parsing, we need to map from raw GPR register numbering 4435 // to the enumeration values. The enumeration values aren't sorted by 4436 // register number due to our using "sp", "lr" and "pc" as canonical names. 4437 static unsigned getNextRegister(unsigned Reg) { 4438 // If this is a GPR, we need to do it manually, otherwise we can rely 4439 // on the sort ordering of the enumeration since the other reg-classes 4440 // are sane. 4441 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) 4442 return Reg + 1; 4443 switch(Reg) { 4444 default: llvm_unreachable("Invalid GPR number!"); 4445 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2; 4446 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4; 4447 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6; 4448 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8; 4449 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10; 4450 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12; 4451 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR; 4452 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0; 4453 } 4454 } 4455 4456 // Insert an <Encoding, Register> pair in an ordered vector. Return true on 4457 // success, or false, if duplicate encoding found. 4458 static bool 4459 insertNoDuplicates(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs, 4460 unsigned Enc, unsigned Reg) { 4461 Regs.emplace_back(Enc, Reg); 4462 for (auto I = Regs.rbegin(), J = I + 1, E = Regs.rend(); J != E; ++I, ++J) { 4463 if (J->first == Enc) { 4464 Regs.erase(J.base()); 4465 return false; 4466 } 4467 if (J->first < Enc) 4468 break; 4469 std::swap(*I, *J); 4470 } 4471 return true; 4472 } 4473 4474 /// Parse a register list. 4475 bool ARMAsmParser::parseRegisterList(OperandVector &Operands, bool EnforceOrder, 4476 bool AllowRAAC) { 4477 MCAsmParser &Parser = getParser(); 4478 if (Parser.getTok().isNot(AsmToken::LCurly)) 4479 return TokError("Token is not a Left Curly Brace"); 4480 SMLoc S = Parser.getTok().getLoc(); 4481 Parser.Lex(); // Eat '{' token. 4482 SMLoc RegLoc = Parser.getTok().getLoc(); 4483 4484 // Check the first register in the list to see what register class 4485 // this is a list of. 4486 int Reg = tryParseRegister(); 4487 if (Reg == -1) 4488 return Error(RegLoc, "register expected"); 4489 if (!AllowRAAC && Reg == ARM::RA_AUTH_CODE) 4490 return Error(RegLoc, "pseudo-register not allowed"); 4491 // The reglist instructions have at most 16 registers, so reserve 4492 // space for that many. 4493 int EReg = 0; 4494 SmallVector<std::pair<unsigned, unsigned>, 16> Registers; 4495 4496 // Allow Q regs and just interpret them as the two D sub-registers. 4497 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 4498 Reg = getDRegFromQReg(Reg); 4499 EReg = MRI->getEncodingValue(Reg); 4500 Registers.emplace_back(EReg, Reg); 4501 ++Reg; 4502 } 4503 const MCRegisterClass *RC; 4504 if (Reg == ARM::RA_AUTH_CODE || 4505 ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) 4506 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID]; 4507 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) 4508 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID]; 4509 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg)) 4510 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID]; 4511 else if (ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains(Reg)) 4512 RC = &ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID]; 4513 else 4514 return Error(RegLoc, "invalid register in register list"); 4515 4516 // Store the register. 4517 EReg = MRI->getEncodingValue(Reg); 4518 Registers.emplace_back(EReg, Reg); 4519 4520 // This starts immediately after the first register token in the list, 4521 // so we can see either a comma or a minus (range separator) as a legal 4522 // next token. 4523 while (Parser.getTok().is(AsmToken::Comma) || 4524 Parser.getTok().is(AsmToken::Minus)) { 4525 if (Parser.getTok().is(AsmToken::Minus)) { 4526 if (Reg == ARM::RA_AUTH_CODE) 4527 return Error(RegLoc, "pseudo-register not allowed"); 4528 Parser.Lex(); // Eat the minus. 4529 SMLoc AfterMinusLoc = Parser.getTok().getLoc(); 4530 int EndReg = tryParseRegister(); 4531 if (EndReg == -1) 4532 return Error(AfterMinusLoc, "register expected"); 4533 if (EndReg == ARM::RA_AUTH_CODE) 4534 return Error(AfterMinusLoc, "pseudo-register not allowed"); 4535 // Allow Q regs and just interpret them as the two D sub-registers. 4536 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) 4537 EndReg = getDRegFromQReg(EndReg) + 1; 4538 // If the register is the same as the start reg, there's nothing 4539 // more to do. 4540 if (Reg == EndReg) 4541 continue; 4542 // The register must be in the same register class as the first. 4543 if (!RC->contains(Reg)) 4544 return Error(AfterMinusLoc, "invalid register in register list"); 4545 // Ranges must go from low to high. 4546 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg)) 4547 return Error(AfterMinusLoc, "bad range in register list"); 4548 4549 // Add all the registers in the range to the register list. 4550 while (Reg != EndReg) { 4551 Reg = getNextRegister(Reg); 4552 EReg = MRI->getEncodingValue(Reg); 4553 if (!insertNoDuplicates(Registers, EReg, Reg)) { 4554 Warning(AfterMinusLoc, StringRef("duplicated register (") + 4555 ARMInstPrinter::getRegisterName(Reg) + 4556 ") in register list"); 4557 } 4558 } 4559 continue; 4560 } 4561 Parser.Lex(); // Eat the comma. 4562 RegLoc = Parser.getTok().getLoc(); 4563 int OldReg = Reg; 4564 const AsmToken RegTok = Parser.getTok(); 4565 Reg = tryParseRegister(); 4566 if (Reg == -1) 4567 return Error(RegLoc, "register expected"); 4568 if (!AllowRAAC && Reg == ARM::RA_AUTH_CODE) 4569 return Error(RegLoc, "pseudo-register not allowed"); 4570 // Allow Q regs and just interpret them as the two D sub-registers. 4571 bool isQReg = false; 4572 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 4573 Reg = getDRegFromQReg(Reg); 4574 isQReg = true; 4575 } 4576 if (Reg != ARM::RA_AUTH_CODE && !RC->contains(Reg) && 4577 RC->getID() == ARMMCRegisterClasses[ARM::GPRRegClassID].getID() && 4578 ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains(Reg)) { 4579 // switch the register classes, as GPRwithAPSRnospRegClassID is a partial 4580 // subset of GPRRegClassId except it contains APSR as well. 4581 RC = &ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID]; 4582 } 4583 if (Reg == ARM::VPR && 4584 (RC == &ARMMCRegisterClasses[ARM::SPRRegClassID] || 4585 RC == &ARMMCRegisterClasses[ARM::DPRRegClassID] || 4586 RC == &ARMMCRegisterClasses[ARM::FPWithVPRRegClassID])) { 4587 RC = &ARMMCRegisterClasses[ARM::FPWithVPRRegClassID]; 4588 EReg = MRI->getEncodingValue(Reg); 4589 if (!insertNoDuplicates(Registers, EReg, Reg)) { 4590 Warning(RegLoc, "duplicated register (" + RegTok.getString() + 4591 ") in register list"); 4592 } 4593 continue; 4594 } 4595 // The register must be in the same register class as the first. 4596 if ((Reg == ARM::RA_AUTH_CODE && 4597 RC != &ARMMCRegisterClasses[ARM::GPRRegClassID]) || 4598 (Reg != ARM::RA_AUTH_CODE && !RC->contains(Reg))) 4599 return Error(RegLoc, "invalid register in register list"); 4600 // In most cases, the list must be monotonically increasing. An 4601 // exception is CLRM, which is order-independent anyway, so 4602 // there's no potential for confusion if you write clrm {r2,r1} 4603 // instead of clrm {r1,r2}. 4604 if (EnforceOrder && 4605 MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) { 4606 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) 4607 Warning(RegLoc, "register list not in ascending order"); 4608 else if (!ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains(Reg)) 4609 return Error(RegLoc, "register list not in ascending order"); 4610 } 4611 // VFP register lists must also be contiguous. 4612 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] && 4613 RC != &ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID] && 4614 Reg != OldReg + 1) 4615 return Error(RegLoc, "non-contiguous register range"); 4616 EReg = MRI->getEncodingValue(Reg); 4617 if (!insertNoDuplicates(Registers, EReg, Reg)) { 4618 Warning(RegLoc, "duplicated register (" + RegTok.getString() + 4619 ") in register list"); 4620 } 4621 if (isQReg) { 4622 EReg = MRI->getEncodingValue(++Reg); 4623 Registers.emplace_back(EReg, Reg); 4624 } 4625 } 4626 4627 if (Parser.getTok().isNot(AsmToken::RCurly)) 4628 return Error(Parser.getTok().getLoc(), "'}' expected"); 4629 SMLoc E = Parser.getTok().getEndLoc(); 4630 Parser.Lex(); // Eat '}' token. 4631 4632 // Push the register list operand. 4633 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E)); 4634 4635 // The ARM system instruction variants for LDM/STM have a '^' token here. 4636 if (Parser.getTok().is(AsmToken::Caret)) { 4637 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc())); 4638 Parser.Lex(); // Eat '^' token. 4639 } 4640 4641 return false; 4642 } 4643 4644 // Helper function to parse the lane index for vector lists. 4645 OperandMatchResultTy ARMAsmParser:: 4646 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) { 4647 MCAsmParser &Parser = getParser(); 4648 Index = 0; // Always return a defined index value. 4649 if (Parser.getTok().is(AsmToken::LBrac)) { 4650 Parser.Lex(); // Eat the '['. 4651 if (Parser.getTok().is(AsmToken::RBrac)) { 4652 // "Dn[]" is the 'all lanes' syntax. 4653 LaneKind = AllLanes; 4654 EndLoc = Parser.getTok().getEndLoc(); 4655 Parser.Lex(); // Eat the ']'. 4656 return MatchOperand_Success; 4657 } 4658 4659 // There's an optional '#' token here. Normally there wouldn't be, but 4660 // inline assemble puts one in, and it's friendly to accept that. 4661 if (Parser.getTok().is(AsmToken::Hash)) 4662 Parser.Lex(); // Eat '#' or '$'. 4663 4664 const MCExpr *LaneIndex; 4665 SMLoc Loc = Parser.getTok().getLoc(); 4666 if (getParser().parseExpression(LaneIndex)) { 4667 Error(Loc, "illegal expression"); 4668 return MatchOperand_ParseFail; 4669 } 4670 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex); 4671 if (!CE) { 4672 Error(Loc, "lane index must be empty or an integer"); 4673 return MatchOperand_ParseFail; 4674 } 4675 if (Parser.getTok().isNot(AsmToken::RBrac)) { 4676 Error(Parser.getTok().getLoc(), "']' expected"); 4677 return MatchOperand_ParseFail; 4678 } 4679 EndLoc = Parser.getTok().getEndLoc(); 4680 Parser.Lex(); // Eat the ']'. 4681 int64_t Val = CE->getValue(); 4682 4683 // FIXME: Make this range check context sensitive for .8, .16, .32. 4684 if (Val < 0 || Val > 7) { 4685 Error(Parser.getTok().getLoc(), "lane index out of range"); 4686 return MatchOperand_ParseFail; 4687 } 4688 Index = Val; 4689 LaneKind = IndexedLane; 4690 return MatchOperand_Success; 4691 } 4692 LaneKind = NoLanes; 4693 return MatchOperand_Success; 4694 } 4695 4696 // parse a vector register list 4697 OperandMatchResultTy 4698 ARMAsmParser::parseVectorList(OperandVector &Operands) { 4699 MCAsmParser &Parser = getParser(); 4700 VectorLaneTy LaneKind; 4701 unsigned LaneIndex; 4702 SMLoc S = Parser.getTok().getLoc(); 4703 // As an extension (to match gas), support a plain D register or Q register 4704 // (without encosing curly braces) as a single or double entry list, 4705 // respectively. 4706 if (!hasMVE() && Parser.getTok().is(AsmToken::Identifier)) { 4707 SMLoc E = Parser.getTok().getEndLoc(); 4708 int Reg = tryParseRegister(); 4709 if (Reg == -1) 4710 return MatchOperand_NoMatch; 4711 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) { 4712 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); 4713 if (Res != MatchOperand_Success) 4714 return Res; 4715 switch (LaneKind) { 4716 case NoLanes: 4717 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E)); 4718 break; 4719 case AllLanes: 4720 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false, 4721 S, E)); 4722 break; 4723 case IndexedLane: 4724 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1, 4725 LaneIndex, 4726 false, S, E)); 4727 break; 4728 } 4729 return MatchOperand_Success; 4730 } 4731 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 4732 Reg = getDRegFromQReg(Reg); 4733 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); 4734 if (Res != MatchOperand_Success) 4735 return Res; 4736 switch (LaneKind) { 4737 case NoLanes: 4738 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, 4739 &ARMMCRegisterClasses[ARM::DPairRegClassID]); 4740 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E)); 4741 break; 4742 case AllLanes: 4743 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, 4744 &ARMMCRegisterClasses[ARM::DPairRegClassID]); 4745 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false, 4746 S, E)); 4747 break; 4748 case IndexedLane: 4749 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2, 4750 LaneIndex, 4751 false, S, E)); 4752 break; 4753 } 4754 return MatchOperand_Success; 4755 } 4756 Error(S, "vector register expected"); 4757 return MatchOperand_ParseFail; 4758 } 4759 4760 if (Parser.getTok().isNot(AsmToken::LCurly)) 4761 return MatchOperand_NoMatch; 4762 4763 Parser.Lex(); // Eat '{' token. 4764 SMLoc RegLoc = Parser.getTok().getLoc(); 4765 4766 int Reg = tryParseRegister(); 4767 if (Reg == -1) { 4768 Error(RegLoc, "register expected"); 4769 return MatchOperand_ParseFail; 4770 } 4771 unsigned Count = 1; 4772 int Spacing = 0; 4773 unsigned FirstReg = Reg; 4774 4775 if (hasMVE() && !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(Reg)) { 4776 Error(Parser.getTok().getLoc(), "vector register in range Q0-Q7 expected"); 4777 return MatchOperand_ParseFail; 4778 } 4779 // The list is of D registers, but we also allow Q regs and just interpret 4780 // them as the two D sub-registers. 4781 else if (!hasMVE() && ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 4782 FirstReg = Reg = getDRegFromQReg(Reg); 4783 Spacing = 1; // double-spacing requires explicit D registers, otherwise 4784 // it's ambiguous with four-register single spaced. 4785 ++Reg; 4786 ++Count; 4787 } 4788 4789 SMLoc E; 4790 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success) 4791 return MatchOperand_ParseFail; 4792 4793 while (Parser.getTok().is(AsmToken::Comma) || 4794 Parser.getTok().is(AsmToken::Minus)) { 4795 if (Parser.getTok().is(AsmToken::Minus)) { 4796 if (!Spacing) 4797 Spacing = 1; // Register range implies a single spaced list. 4798 else if (Spacing == 2) { 4799 Error(Parser.getTok().getLoc(), 4800 "sequential registers in double spaced list"); 4801 return MatchOperand_ParseFail; 4802 } 4803 Parser.Lex(); // Eat the minus. 4804 SMLoc AfterMinusLoc = Parser.getTok().getLoc(); 4805 int EndReg = tryParseRegister(); 4806 if (EndReg == -1) { 4807 Error(AfterMinusLoc, "register expected"); 4808 return MatchOperand_ParseFail; 4809 } 4810 // Allow Q regs and just interpret them as the two D sub-registers. 4811 if (!hasMVE() && ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) 4812 EndReg = getDRegFromQReg(EndReg) + 1; 4813 // If the register is the same as the start reg, there's nothing 4814 // more to do. 4815 if (Reg == EndReg) 4816 continue; 4817 // The register must be in the same register class as the first. 4818 if ((hasMVE() && 4819 !ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(EndReg)) || 4820 (!hasMVE() && 4821 !ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg))) { 4822 Error(AfterMinusLoc, "invalid register in register list"); 4823 return MatchOperand_ParseFail; 4824 } 4825 // Ranges must go from low to high. 4826 if (Reg > EndReg) { 4827 Error(AfterMinusLoc, "bad range in register list"); 4828 return MatchOperand_ParseFail; 4829 } 4830 // Parse the lane specifier if present. 4831 VectorLaneTy NextLaneKind; 4832 unsigned NextLaneIndex; 4833 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != 4834 MatchOperand_Success) 4835 return MatchOperand_ParseFail; 4836 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { 4837 Error(AfterMinusLoc, "mismatched lane index in register list"); 4838 return MatchOperand_ParseFail; 4839 } 4840 4841 // Add all the registers in the range to the register list. 4842 Count += EndReg - Reg; 4843 Reg = EndReg; 4844 continue; 4845 } 4846 Parser.Lex(); // Eat the comma. 4847 RegLoc = Parser.getTok().getLoc(); 4848 int OldReg = Reg; 4849 Reg = tryParseRegister(); 4850 if (Reg == -1) { 4851 Error(RegLoc, "register expected"); 4852 return MatchOperand_ParseFail; 4853 } 4854 4855 if (hasMVE()) { 4856 if (!ARMMCRegisterClasses[ARM::MQPRRegClassID].contains(Reg)) { 4857 Error(RegLoc, "vector register in range Q0-Q7 expected"); 4858 return MatchOperand_ParseFail; 4859 } 4860 Spacing = 1; 4861 } 4862 // vector register lists must be contiguous. 4863 // It's OK to use the enumeration values directly here rather, as the 4864 // VFP register classes have the enum sorted properly. 4865 // 4866 // The list is of D registers, but we also allow Q regs and just interpret 4867 // them as the two D sub-registers. 4868 else if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 4869 if (!Spacing) 4870 Spacing = 1; // Register range implies a single spaced list. 4871 else if (Spacing == 2) { 4872 Error(RegLoc, 4873 "invalid register in double-spaced list (must be 'D' register')"); 4874 return MatchOperand_ParseFail; 4875 } 4876 Reg = getDRegFromQReg(Reg); 4877 if (Reg != OldReg + 1) { 4878 Error(RegLoc, "non-contiguous register range"); 4879 return MatchOperand_ParseFail; 4880 } 4881 ++Reg; 4882 Count += 2; 4883 // Parse the lane specifier if present. 4884 VectorLaneTy NextLaneKind; 4885 unsigned NextLaneIndex; 4886 SMLoc LaneLoc = Parser.getTok().getLoc(); 4887 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != 4888 MatchOperand_Success) 4889 return MatchOperand_ParseFail; 4890 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { 4891 Error(LaneLoc, "mismatched lane index in register list"); 4892 return MatchOperand_ParseFail; 4893 } 4894 continue; 4895 } 4896 // Normal D register. 4897 // Figure out the register spacing (single or double) of the list if 4898 // we don't know it already. 4899 if (!Spacing) 4900 Spacing = 1 + (Reg == OldReg + 2); 4901 4902 // Just check that it's contiguous and keep going. 4903 if (Reg != OldReg + Spacing) { 4904 Error(RegLoc, "non-contiguous register range"); 4905 return MatchOperand_ParseFail; 4906 } 4907 ++Count; 4908 // Parse the lane specifier if present. 4909 VectorLaneTy NextLaneKind; 4910 unsigned NextLaneIndex; 4911 SMLoc EndLoc = Parser.getTok().getLoc(); 4912 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success) 4913 return MatchOperand_ParseFail; 4914 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { 4915 Error(EndLoc, "mismatched lane index in register list"); 4916 return MatchOperand_ParseFail; 4917 } 4918 } 4919 4920 if (Parser.getTok().isNot(AsmToken::RCurly)) { 4921 Error(Parser.getTok().getLoc(), "'}' expected"); 4922 return MatchOperand_ParseFail; 4923 } 4924 E = Parser.getTok().getEndLoc(); 4925 Parser.Lex(); // Eat '}' token. 4926 4927 switch (LaneKind) { 4928 case NoLanes: 4929 case AllLanes: { 4930 // Two-register operands have been converted to the 4931 // composite register classes. 4932 if (Count == 2 && !hasMVE()) { 4933 const MCRegisterClass *RC = (Spacing == 1) ? 4934 &ARMMCRegisterClasses[ARM::DPairRegClassID] : 4935 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; 4936 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); 4937 } 4938 auto Create = (LaneKind == NoLanes ? ARMOperand::CreateVectorList : 4939 ARMOperand::CreateVectorListAllLanes); 4940 Operands.push_back(Create(FirstReg, Count, (Spacing == 2), S, E)); 4941 break; 4942 } 4943 case IndexedLane: 4944 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count, 4945 LaneIndex, 4946 (Spacing == 2), 4947 S, E)); 4948 break; 4949 } 4950 return MatchOperand_Success; 4951 } 4952 4953 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options. 4954 OperandMatchResultTy 4955 ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) { 4956 MCAsmParser &Parser = getParser(); 4957 SMLoc S = Parser.getTok().getLoc(); 4958 const AsmToken &Tok = Parser.getTok(); 4959 unsigned Opt; 4960 4961 if (Tok.is(AsmToken::Identifier)) { 4962 StringRef OptStr = Tok.getString(); 4963 4964 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower()) 4965 .Case("sy", ARM_MB::SY) 4966 .Case("st", ARM_MB::ST) 4967 .Case("ld", ARM_MB::LD) 4968 .Case("sh", ARM_MB::ISH) 4969 .Case("ish", ARM_MB::ISH) 4970 .Case("shst", ARM_MB::ISHST) 4971 .Case("ishst", ARM_MB::ISHST) 4972 .Case("ishld", ARM_MB::ISHLD) 4973 .Case("nsh", ARM_MB::NSH) 4974 .Case("un", ARM_MB::NSH) 4975 .Case("nshst", ARM_MB::NSHST) 4976 .Case("nshld", ARM_MB::NSHLD) 4977 .Case("unst", ARM_MB::NSHST) 4978 .Case("osh", ARM_MB::OSH) 4979 .Case("oshst", ARM_MB::OSHST) 4980 .Case("oshld", ARM_MB::OSHLD) 4981 .Default(~0U); 4982 4983 // ishld, oshld, nshld and ld are only available from ARMv8. 4984 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD || 4985 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD)) 4986 Opt = ~0U; 4987 4988 if (Opt == ~0U) 4989 return MatchOperand_NoMatch; 4990 4991 Parser.Lex(); // Eat identifier token. 4992 } else if (Tok.is(AsmToken::Hash) || 4993 Tok.is(AsmToken::Dollar) || 4994 Tok.is(AsmToken::Integer)) { 4995 if (Parser.getTok().isNot(AsmToken::Integer)) 4996 Parser.Lex(); // Eat '#' or '$'. 4997 SMLoc Loc = Parser.getTok().getLoc(); 4998 4999 const MCExpr *MemBarrierID; 5000 if (getParser().parseExpression(MemBarrierID)) { 5001 Error(Loc, "illegal expression"); 5002 return MatchOperand_ParseFail; 5003 } 5004 5005 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID); 5006 if (!CE) { 5007 Error(Loc, "constant expression expected"); 5008 return MatchOperand_ParseFail; 5009 } 5010 5011 int Val = CE->getValue(); 5012 if (Val & ~0xf) { 5013 Error(Loc, "immediate value out of range"); 5014 return MatchOperand_ParseFail; 5015 } 5016 5017 Opt = ARM_MB::RESERVED_0 + Val; 5018 } else 5019 return MatchOperand_ParseFail; 5020 5021 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S)); 5022 return MatchOperand_Success; 5023 } 5024 5025 OperandMatchResultTy 5026 ARMAsmParser::parseTraceSyncBarrierOptOperand(OperandVector &Operands) { 5027 MCAsmParser &Parser = getParser(); 5028 SMLoc S = Parser.getTok().getLoc(); 5029 const AsmToken &Tok = Parser.getTok(); 5030 5031 if (Tok.isNot(AsmToken::Identifier)) 5032 return MatchOperand_NoMatch; 5033 5034 if (!Tok.getString().equals_insensitive("csync")) 5035 return MatchOperand_NoMatch; 5036 5037 Parser.Lex(); // Eat identifier token. 5038 5039 Operands.push_back(ARMOperand::CreateTraceSyncBarrierOpt(ARM_TSB::CSYNC, S)); 5040 return MatchOperand_Success; 5041 } 5042 5043 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options. 5044 OperandMatchResultTy 5045 ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) { 5046 MCAsmParser &Parser = getParser(); 5047 SMLoc S = Parser.getTok().getLoc(); 5048 const AsmToken &Tok = Parser.getTok(); 5049 unsigned Opt; 5050 5051 if (Tok.is(AsmToken::Identifier)) { 5052 StringRef OptStr = Tok.getString(); 5053 5054 if (OptStr.equals_insensitive("sy")) 5055 Opt = ARM_ISB::SY; 5056 else 5057 return MatchOperand_NoMatch; 5058 5059 Parser.Lex(); // Eat identifier token. 5060 } else if (Tok.is(AsmToken::Hash) || 5061 Tok.is(AsmToken::Dollar) || 5062 Tok.is(AsmToken::Integer)) { 5063 if (Parser.getTok().isNot(AsmToken::Integer)) 5064 Parser.Lex(); // Eat '#' or '$'. 5065 SMLoc Loc = Parser.getTok().getLoc(); 5066 5067 const MCExpr *ISBarrierID; 5068 if (getParser().parseExpression(ISBarrierID)) { 5069 Error(Loc, "illegal expression"); 5070 return MatchOperand_ParseFail; 5071 } 5072 5073 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID); 5074 if (!CE) { 5075 Error(Loc, "constant expression expected"); 5076 return MatchOperand_ParseFail; 5077 } 5078 5079 int Val = CE->getValue(); 5080 if (Val & ~0xf) { 5081 Error(Loc, "immediate value out of range"); 5082 return MatchOperand_ParseFail; 5083 } 5084 5085 Opt = ARM_ISB::RESERVED_0 + Val; 5086 } else 5087 return MatchOperand_ParseFail; 5088 5089 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt( 5090 (ARM_ISB::InstSyncBOpt)Opt, S)); 5091 return MatchOperand_Success; 5092 } 5093 5094 5095 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction. 5096 OperandMatchResultTy 5097 ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) { 5098 MCAsmParser &Parser = getParser(); 5099 SMLoc S = Parser.getTok().getLoc(); 5100 const AsmToken &Tok = Parser.getTok(); 5101 if (!Tok.is(AsmToken::Identifier)) 5102 return MatchOperand_NoMatch; 5103 StringRef IFlagsStr = Tok.getString(); 5104 5105 // An iflags string of "none" is interpreted to mean that none of the AIF 5106 // bits are set. Not a terribly useful instruction, but a valid encoding. 5107 unsigned IFlags = 0; 5108 if (IFlagsStr != "none") { 5109 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) { 5110 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1).lower()) 5111 .Case("a", ARM_PROC::A) 5112 .Case("i", ARM_PROC::I) 5113 .Case("f", ARM_PROC::F) 5114 .Default(~0U); 5115 5116 // If some specific iflag is already set, it means that some letter is 5117 // present more than once, this is not acceptable. 5118 if (Flag == ~0U || (IFlags & Flag)) 5119 return MatchOperand_NoMatch; 5120 5121 IFlags |= Flag; 5122 } 5123 } 5124 5125 Parser.Lex(); // Eat identifier token. 5126 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S)); 5127 return MatchOperand_Success; 5128 } 5129 5130 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction. 5131 OperandMatchResultTy 5132 ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) { 5133 MCAsmParser &Parser = getParser(); 5134 SMLoc S = Parser.getTok().getLoc(); 5135 const AsmToken &Tok = Parser.getTok(); 5136 5137 if (Tok.is(AsmToken::Integer)) { 5138 int64_t Val = Tok.getIntVal(); 5139 if (Val > 255 || Val < 0) { 5140 return MatchOperand_NoMatch; 5141 } 5142 unsigned SYSmvalue = Val & 0xFF; 5143 Parser.Lex(); 5144 Operands.push_back(ARMOperand::CreateMSRMask(SYSmvalue, S)); 5145 return MatchOperand_Success; 5146 } 5147 5148 if (!Tok.is(AsmToken::Identifier)) 5149 return MatchOperand_NoMatch; 5150 StringRef Mask = Tok.getString(); 5151 5152 if (isMClass()) { 5153 auto TheReg = ARMSysReg::lookupMClassSysRegByName(Mask.lower()); 5154 if (!TheReg || !TheReg->hasRequiredFeatures(getSTI().getFeatureBits())) 5155 return MatchOperand_NoMatch; 5156 5157 unsigned SYSmvalue = TheReg->Encoding & 0xFFF; 5158 5159 Parser.Lex(); // Eat identifier token. 5160 Operands.push_back(ARMOperand::CreateMSRMask(SYSmvalue, S)); 5161 return MatchOperand_Success; 5162 } 5163 5164 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf" 5165 size_t Start = 0, Next = Mask.find('_'); 5166 StringRef Flags = ""; 5167 std::string SpecReg = Mask.slice(Start, Next).lower(); 5168 if (Next != StringRef::npos) 5169 Flags = Mask.slice(Next+1, Mask.size()); 5170 5171 // FlagsVal contains the complete mask: 5172 // 3-0: Mask 5173 // 4: Special Reg (cpsr, apsr => 0; spsr => 1) 5174 unsigned FlagsVal = 0; 5175 5176 if (SpecReg == "apsr") { 5177 FlagsVal = StringSwitch<unsigned>(Flags) 5178 .Case("nzcvq", 0x8) // same as CPSR_f 5179 .Case("g", 0x4) // same as CPSR_s 5180 .Case("nzcvqg", 0xc) // same as CPSR_fs 5181 .Default(~0U); 5182 5183 if (FlagsVal == ~0U) { 5184 if (!Flags.empty()) 5185 return MatchOperand_NoMatch; 5186 else 5187 FlagsVal = 8; // No flag 5188 } 5189 } else if (SpecReg == "cpsr" || SpecReg == "spsr") { 5190 // cpsr_all is an alias for cpsr_fc, as is plain cpsr. 5191 if (Flags == "all" || Flags == "") 5192 Flags = "fc"; 5193 for (int i = 0, e = Flags.size(); i != e; ++i) { 5194 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1)) 5195 .Case("c", 1) 5196 .Case("x", 2) 5197 .Case("s", 4) 5198 .Case("f", 8) 5199 .Default(~0U); 5200 5201 // If some specific flag is already set, it means that some letter is 5202 // present more than once, this is not acceptable. 5203 if (Flag == ~0U || (FlagsVal & Flag)) 5204 return MatchOperand_NoMatch; 5205 FlagsVal |= Flag; 5206 } 5207 } else // No match for special register. 5208 return MatchOperand_NoMatch; 5209 5210 // Special register without flags is NOT equivalent to "fc" flags. 5211 // NOTE: This is a divergence from gas' behavior. Uncommenting the following 5212 // two lines would enable gas compatibility at the expense of breaking 5213 // round-tripping. 5214 // 5215 // if (!FlagsVal) 5216 // FlagsVal = 0x9; 5217 5218 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1) 5219 if (SpecReg == "spsr") 5220 FlagsVal |= 16; 5221 5222 Parser.Lex(); // Eat identifier token. 5223 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); 5224 return MatchOperand_Success; 5225 } 5226 5227 /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for 5228 /// use in the MRS/MSR instructions added to support virtualization. 5229 OperandMatchResultTy 5230 ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) { 5231 MCAsmParser &Parser = getParser(); 5232 SMLoc S = Parser.getTok().getLoc(); 5233 const AsmToken &Tok = Parser.getTok(); 5234 if (!Tok.is(AsmToken::Identifier)) 5235 return MatchOperand_NoMatch; 5236 StringRef RegName = Tok.getString(); 5237 5238 auto TheReg = ARMBankedReg::lookupBankedRegByName(RegName.lower()); 5239 if (!TheReg) 5240 return MatchOperand_NoMatch; 5241 unsigned Encoding = TheReg->Encoding; 5242 5243 Parser.Lex(); // Eat identifier token. 5244 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S)); 5245 return MatchOperand_Success; 5246 } 5247 5248 OperandMatchResultTy 5249 ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low, 5250 int High) { 5251 MCAsmParser &Parser = getParser(); 5252 const AsmToken &Tok = Parser.getTok(); 5253 if (Tok.isNot(AsmToken::Identifier)) { 5254 Error(Parser.getTok().getLoc(), Op + " operand expected."); 5255 return MatchOperand_ParseFail; 5256 } 5257 StringRef ShiftName = Tok.getString(); 5258 std::string LowerOp = Op.lower(); 5259 std::string UpperOp = Op.upper(); 5260 if (ShiftName != LowerOp && ShiftName != UpperOp) { 5261 Error(Parser.getTok().getLoc(), Op + " operand expected."); 5262 return MatchOperand_ParseFail; 5263 } 5264 Parser.Lex(); // Eat shift type token. 5265 5266 // There must be a '#' and a shift amount. 5267 if (Parser.getTok().isNot(AsmToken::Hash) && 5268 Parser.getTok().isNot(AsmToken::Dollar)) { 5269 Error(Parser.getTok().getLoc(), "'#' expected"); 5270 return MatchOperand_ParseFail; 5271 } 5272 Parser.Lex(); // Eat hash token. 5273 5274 const MCExpr *ShiftAmount; 5275 SMLoc Loc = Parser.getTok().getLoc(); 5276 SMLoc EndLoc; 5277 if (getParser().parseExpression(ShiftAmount, EndLoc)) { 5278 Error(Loc, "illegal expression"); 5279 return MatchOperand_ParseFail; 5280 } 5281 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); 5282 if (!CE) { 5283 Error(Loc, "constant expression expected"); 5284 return MatchOperand_ParseFail; 5285 } 5286 int Val = CE->getValue(); 5287 if (Val < Low || Val > High) { 5288 Error(Loc, "immediate value out of range"); 5289 return MatchOperand_ParseFail; 5290 } 5291 5292 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc)); 5293 5294 return MatchOperand_Success; 5295 } 5296 5297 OperandMatchResultTy 5298 ARMAsmParser::parseSetEndImm(OperandVector &Operands) { 5299 MCAsmParser &Parser = getParser(); 5300 const AsmToken &Tok = Parser.getTok(); 5301 SMLoc S = Tok.getLoc(); 5302 if (Tok.isNot(AsmToken::Identifier)) { 5303 Error(S, "'be' or 'le' operand expected"); 5304 return MatchOperand_ParseFail; 5305 } 5306 int Val = StringSwitch<int>(Tok.getString().lower()) 5307 .Case("be", 1) 5308 .Case("le", 0) 5309 .Default(-1); 5310 Parser.Lex(); // Eat the token. 5311 5312 if (Val == -1) { 5313 Error(S, "'be' or 'le' operand expected"); 5314 return MatchOperand_ParseFail; 5315 } 5316 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::create(Val, 5317 getContext()), 5318 S, Tok.getEndLoc())); 5319 return MatchOperand_Success; 5320 } 5321 5322 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT 5323 /// instructions. Legal values are: 5324 /// lsl #n 'n' in [0,31] 5325 /// asr #n 'n' in [1,32] 5326 /// n == 32 encoded as n == 0. 5327 OperandMatchResultTy 5328 ARMAsmParser::parseShifterImm(OperandVector &Operands) { 5329 MCAsmParser &Parser = getParser(); 5330 const AsmToken &Tok = Parser.getTok(); 5331 SMLoc S = Tok.getLoc(); 5332 if (Tok.isNot(AsmToken::Identifier)) { 5333 Error(S, "shift operator 'asr' or 'lsl' expected"); 5334 return MatchOperand_ParseFail; 5335 } 5336 StringRef ShiftName = Tok.getString(); 5337 bool isASR; 5338 if (ShiftName == "lsl" || ShiftName == "LSL") 5339 isASR = false; 5340 else if (ShiftName == "asr" || ShiftName == "ASR") 5341 isASR = true; 5342 else { 5343 Error(S, "shift operator 'asr' or 'lsl' expected"); 5344 return MatchOperand_ParseFail; 5345 } 5346 Parser.Lex(); // Eat the operator. 5347 5348 // A '#' and a shift amount. 5349 if (Parser.getTok().isNot(AsmToken::Hash) && 5350 Parser.getTok().isNot(AsmToken::Dollar)) { 5351 Error(Parser.getTok().getLoc(), "'#' expected"); 5352 return MatchOperand_ParseFail; 5353 } 5354 Parser.Lex(); // Eat hash token. 5355 SMLoc ExLoc = Parser.getTok().getLoc(); 5356 5357 const MCExpr *ShiftAmount; 5358 SMLoc EndLoc; 5359 if (getParser().parseExpression(ShiftAmount, EndLoc)) { 5360 Error(ExLoc, "malformed shift expression"); 5361 return MatchOperand_ParseFail; 5362 } 5363 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); 5364 if (!CE) { 5365 Error(ExLoc, "shift amount must be an immediate"); 5366 return MatchOperand_ParseFail; 5367 } 5368 5369 int64_t Val = CE->getValue(); 5370 if (isASR) { 5371 // Shift amount must be in [1,32] 5372 if (Val < 1 || Val > 32) { 5373 Error(ExLoc, "'asr' shift amount must be in range [1,32]"); 5374 return MatchOperand_ParseFail; 5375 } 5376 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode. 5377 if (isThumb() && Val == 32) { 5378 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode"); 5379 return MatchOperand_ParseFail; 5380 } 5381 if (Val == 32) Val = 0; 5382 } else { 5383 // Shift amount must be in [1,32] 5384 if (Val < 0 || Val > 31) { 5385 Error(ExLoc, "'lsr' shift amount must be in range [0,31]"); 5386 return MatchOperand_ParseFail; 5387 } 5388 } 5389 5390 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc)); 5391 5392 return MatchOperand_Success; 5393 } 5394 5395 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family 5396 /// of instructions. Legal values are: 5397 /// ror #n 'n' in {0, 8, 16, 24} 5398 OperandMatchResultTy 5399 ARMAsmParser::parseRotImm(OperandVector &Operands) { 5400 MCAsmParser &Parser = getParser(); 5401 const AsmToken &Tok = Parser.getTok(); 5402 SMLoc S = Tok.getLoc(); 5403 if (Tok.isNot(AsmToken::Identifier)) 5404 return MatchOperand_NoMatch; 5405 StringRef ShiftName = Tok.getString(); 5406 if (ShiftName != "ror" && ShiftName != "ROR") 5407 return MatchOperand_NoMatch; 5408 Parser.Lex(); // Eat the operator. 5409 5410 // A '#' and a rotate amount. 5411 if (Parser.getTok().isNot(AsmToken::Hash) && 5412 Parser.getTok().isNot(AsmToken::Dollar)) { 5413 Error(Parser.getTok().getLoc(), "'#' expected"); 5414 return MatchOperand_ParseFail; 5415 } 5416 Parser.Lex(); // Eat hash token. 5417 SMLoc ExLoc = Parser.getTok().getLoc(); 5418 5419 const MCExpr *ShiftAmount; 5420 SMLoc EndLoc; 5421 if (getParser().parseExpression(ShiftAmount, EndLoc)) { 5422 Error(ExLoc, "malformed rotate expression"); 5423 return MatchOperand_ParseFail; 5424 } 5425 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); 5426 if (!CE) { 5427 Error(ExLoc, "rotate amount must be an immediate"); 5428 return MatchOperand_ParseFail; 5429 } 5430 5431 int64_t Val = CE->getValue(); 5432 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension) 5433 // normally, zero is represented in asm by omitting the rotate operand 5434 // entirely. 5435 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) { 5436 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24"); 5437 return MatchOperand_ParseFail; 5438 } 5439 5440 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc)); 5441 5442 return MatchOperand_Success; 5443 } 5444 5445 OperandMatchResultTy 5446 ARMAsmParser::parseModImm(OperandVector &Operands) { 5447 MCAsmParser &Parser = getParser(); 5448 MCAsmLexer &Lexer = getLexer(); 5449 int64_t Imm1, Imm2; 5450 5451 SMLoc S = Parser.getTok().getLoc(); 5452 5453 // 1) A mod_imm operand can appear in the place of a register name: 5454 // add r0, #mod_imm 5455 // add r0, r0, #mod_imm 5456 // to correctly handle the latter, we bail out as soon as we see an 5457 // identifier. 5458 // 5459 // 2) Similarly, we do not want to parse into complex operands: 5460 // mov r0, #mod_imm 5461 // mov r0, :lower16:(_foo) 5462 if (Parser.getTok().is(AsmToken::Identifier) || 5463 Parser.getTok().is(AsmToken::Colon)) 5464 return MatchOperand_NoMatch; 5465 5466 // Hash (dollar) is optional as per the ARMARM 5467 if (Parser.getTok().is(AsmToken::Hash) || 5468 Parser.getTok().is(AsmToken::Dollar)) { 5469 // Avoid parsing into complex operands (#:) 5470 if (Lexer.peekTok().is(AsmToken::Colon)) 5471 return MatchOperand_NoMatch; 5472 5473 // Eat the hash (dollar) 5474 Parser.Lex(); 5475 } 5476 5477 SMLoc Sx1, Ex1; 5478 Sx1 = Parser.getTok().getLoc(); 5479 const MCExpr *Imm1Exp; 5480 if (getParser().parseExpression(Imm1Exp, Ex1)) { 5481 Error(Sx1, "malformed expression"); 5482 return MatchOperand_ParseFail; 5483 } 5484 5485 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp); 5486 5487 if (CE) { 5488 // Immediate must fit within 32-bits 5489 Imm1 = CE->getValue(); 5490 int Enc = ARM_AM::getSOImmVal(Imm1); 5491 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) { 5492 // We have a match! 5493 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF), 5494 (Enc & 0xF00) >> 7, 5495 Sx1, Ex1)); 5496 return MatchOperand_Success; 5497 } 5498 5499 // We have parsed an immediate which is not for us, fallback to a plain 5500 // immediate. This can happen for instruction aliases. For an example, 5501 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform 5502 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite 5503 // instruction with a mod_imm operand. The alias is defined such that the 5504 // parser method is shared, that's why we have to do this here. 5505 if (Parser.getTok().is(AsmToken::EndOfStatement)) { 5506 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1)); 5507 return MatchOperand_Success; 5508 } 5509 } else { 5510 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an 5511 // MCFixup). Fallback to a plain immediate. 5512 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1)); 5513 return MatchOperand_Success; 5514 } 5515 5516 // From this point onward, we expect the input to be a (#bits, #rot) pair 5517 if (Parser.getTok().isNot(AsmToken::Comma)) { 5518 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]"); 5519 return MatchOperand_ParseFail; 5520 } 5521 5522 if (Imm1 & ~0xFF) { 5523 Error(Sx1, "immediate operand must a number in the range [0, 255]"); 5524 return MatchOperand_ParseFail; 5525 } 5526 5527 // Eat the comma 5528 Parser.Lex(); 5529 5530 // Repeat for #rot 5531 SMLoc Sx2, Ex2; 5532 Sx2 = Parser.getTok().getLoc(); 5533 5534 // Eat the optional hash (dollar) 5535 if (Parser.getTok().is(AsmToken::Hash) || 5536 Parser.getTok().is(AsmToken::Dollar)) 5537 Parser.Lex(); 5538 5539 const MCExpr *Imm2Exp; 5540 if (getParser().parseExpression(Imm2Exp, Ex2)) { 5541 Error(Sx2, "malformed expression"); 5542 return MatchOperand_ParseFail; 5543 } 5544 5545 CE = dyn_cast<MCConstantExpr>(Imm2Exp); 5546 5547 if (CE) { 5548 Imm2 = CE->getValue(); 5549 if (!(Imm2 & ~0x1E)) { 5550 // We have a match! 5551 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2)); 5552 return MatchOperand_Success; 5553 } 5554 Error(Sx2, "immediate operand must an even number in the range [0, 30]"); 5555 return MatchOperand_ParseFail; 5556 } else { 5557 Error(Sx2, "constant expression expected"); 5558 return MatchOperand_ParseFail; 5559 } 5560 } 5561 5562 OperandMatchResultTy 5563 ARMAsmParser::parseBitfield(OperandVector &Operands) { 5564 MCAsmParser &Parser = getParser(); 5565 SMLoc S = Parser.getTok().getLoc(); 5566 // The bitfield descriptor is really two operands, the LSB and the width. 5567 if (Parser.getTok().isNot(AsmToken::Hash) && 5568 Parser.getTok().isNot(AsmToken::Dollar)) { 5569 Error(Parser.getTok().getLoc(), "'#' expected"); 5570 return MatchOperand_ParseFail; 5571 } 5572 Parser.Lex(); // Eat hash token. 5573 5574 const MCExpr *LSBExpr; 5575 SMLoc E = Parser.getTok().getLoc(); 5576 if (getParser().parseExpression(LSBExpr)) { 5577 Error(E, "malformed immediate expression"); 5578 return MatchOperand_ParseFail; 5579 } 5580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr); 5581 if (!CE) { 5582 Error(E, "'lsb' operand must be an immediate"); 5583 return MatchOperand_ParseFail; 5584 } 5585 5586 int64_t LSB = CE->getValue(); 5587 // The LSB must be in the range [0,31] 5588 if (LSB < 0 || LSB > 31) { 5589 Error(E, "'lsb' operand must be in the range [0,31]"); 5590 return MatchOperand_ParseFail; 5591 } 5592 E = Parser.getTok().getLoc(); 5593 5594 // Expect another immediate operand. 5595 if (Parser.getTok().isNot(AsmToken::Comma)) { 5596 Error(Parser.getTok().getLoc(), "too few operands"); 5597 return MatchOperand_ParseFail; 5598 } 5599 Parser.Lex(); // Eat hash token. 5600 if (Parser.getTok().isNot(AsmToken::Hash) && 5601 Parser.getTok().isNot(AsmToken::Dollar)) { 5602 Error(Parser.getTok().getLoc(), "'#' expected"); 5603 return MatchOperand_ParseFail; 5604 } 5605 Parser.Lex(); // Eat hash token. 5606 5607 const MCExpr *WidthExpr; 5608 SMLoc EndLoc; 5609 if (getParser().parseExpression(WidthExpr, EndLoc)) { 5610 Error(E, "malformed immediate expression"); 5611 return MatchOperand_ParseFail; 5612 } 5613 CE = dyn_cast<MCConstantExpr>(WidthExpr); 5614 if (!CE) { 5615 Error(E, "'width' operand must be an immediate"); 5616 return MatchOperand_ParseFail; 5617 } 5618 5619 int64_t Width = CE->getValue(); 5620 // The LSB must be in the range [1,32-lsb] 5621 if (Width < 1 || Width > 32 - LSB) { 5622 Error(E, "'width' operand must be in the range [1,32-lsb]"); 5623 return MatchOperand_ParseFail; 5624 } 5625 5626 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc)); 5627 5628 return MatchOperand_Success; 5629 } 5630 5631 OperandMatchResultTy 5632 ARMAsmParser::parsePostIdxReg(OperandVector &Operands) { 5633 // Check for a post-index addressing register operand. Specifically: 5634 // postidx_reg := '+' register {, shift} 5635 // | '-' register {, shift} 5636 // | register {, shift} 5637 5638 // This method must return MatchOperand_NoMatch without consuming any tokens 5639 // in the case where there is no match, as other alternatives take other 5640 // parse methods. 5641 MCAsmParser &Parser = getParser(); 5642 AsmToken Tok = Parser.getTok(); 5643 SMLoc S = Tok.getLoc(); 5644 bool haveEaten = false; 5645 bool isAdd = true; 5646 if (Tok.is(AsmToken::Plus)) { 5647 Parser.Lex(); // Eat the '+' token. 5648 haveEaten = true; 5649 } else if (Tok.is(AsmToken::Minus)) { 5650 Parser.Lex(); // Eat the '-' token. 5651 isAdd = false; 5652 haveEaten = true; 5653 } 5654 5655 SMLoc E = Parser.getTok().getEndLoc(); 5656 int Reg = tryParseRegister(); 5657 if (Reg == -1) { 5658 if (!haveEaten) 5659 return MatchOperand_NoMatch; 5660 Error(Parser.getTok().getLoc(), "register expected"); 5661 return MatchOperand_ParseFail; 5662 } 5663 5664 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift; 5665 unsigned ShiftImm = 0; 5666 if (Parser.getTok().is(AsmToken::Comma)) { 5667 Parser.Lex(); // Eat the ','. 5668 if (parseMemRegOffsetShift(ShiftTy, ShiftImm)) 5669 return MatchOperand_ParseFail; 5670 5671 // FIXME: Only approximates end...may include intervening whitespace. 5672 E = Parser.getTok().getLoc(); 5673 } 5674 5675 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy, 5676 ShiftImm, S, E)); 5677 5678 return MatchOperand_Success; 5679 } 5680 5681 OperandMatchResultTy 5682 ARMAsmParser::parseAM3Offset(OperandVector &Operands) { 5683 // Check for a post-index addressing register operand. Specifically: 5684 // am3offset := '+' register 5685 // | '-' register 5686 // | register 5687 // | # imm 5688 // | # + imm 5689 // | # - imm 5690 5691 // This method must return MatchOperand_NoMatch without consuming any tokens 5692 // in the case where there is no match, as other alternatives take other 5693 // parse methods. 5694 MCAsmParser &Parser = getParser(); 5695 AsmToken Tok = Parser.getTok(); 5696 SMLoc S = Tok.getLoc(); 5697 5698 // Do immediates first, as we always parse those if we have a '#'. 5699 if (Parser.getTok().is(AsmToken::Hash) || 5700 Parser.getTok().is(AsmToken::Dollar)) { 5701 Parser.Lex(); // Eat '#' or '$'. 5702 // Explicitly look for a '-', as we need to encode negative zero 5703 // differently. 5704 bool isNegative = Parser.getTok().is(AsmToken::Minus); 5705 const MCExpr *Offset; 5706 SMLoc E; 5707 if (getParser().parseExpression(Offset, E)) 5708 return MatchOperand_ParseFail; 5709 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); 5710 if (!CE) { 5711 Error(S, "constant expression expected"); 5712 return MatchOperand_ParseFail; 5713 } 5714 // Negative zero is encoded as the flag value 5715 // std::numeric_limits<int32_t>::min(). 5716 int32_t Val = CE->getValue(); 5717 if (isNegative && Val == 0) 5718 Val = std::numeric_limits<int32_t>::min(); 5719 5720 Operands.push_back( 5721 ARMOperand::CreateImm(MCConstantExpr::create(Val, getContext()), S, E)); 5722 5723 return MatchOperand_Success; 5724 } 5725 5726 bool haveEaten = false; 5727 bool isAdd = true; 5728 if (Tok.is(AsmToken::Plus)) { 5729 Parser.Lex(); // Eat the '+' token. 5730 haveEaten = true; 5731 } else if (Tok.is(AsmToken::Minus)) { 5732 Parser.Lex(); // Eat the '-' token. 5733 isAdd = false; 5734 haveEaten = true; 5735 } 5736 5737 Tok = Parser.getTok(); 5738 int Reg = tryParseRegister(); 5739 if (Reg == -1) { 5740 if (!haveEaten) 5741 return MatchOperand_NoMatch; 5742 Error(Tok.getLoc(), "register expected"); 5743 return MatchOperand_ParseFail; 5744 } 5745 5746 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift, 5747 0, S, Tok.getEndLoc())); 5748 5749 return MatchOperand_Success; 5750 } 5751 5752 /// Convert parsed operands to MCInst. Needed here because this instruction 5753 /// only has two register operands, but multiplication is commutative so 5754 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN". 5755 void ARMAsmParser::cvtThumbMultiply(MCInst &Inst, 5756 const OperandVector &Operands) { 5757 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1); 5758 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1); 5759 // If we have a three-operand form, make sure to set Rn to be the operand 5760 // that isn't the same as Rd. 5761 unsigned RegOp = 4; 5762 if (Operands.size() == 6 && 5763 ((ARMOperand &)*Operands[4]).getReg() == 5764 ((ARMOperand &)*Operands[3]).getReg()) 5765 RegOp = 5; 5766 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1); 5767 Inst.addOperand(Inst.getOperand(0)); 5768 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2); 5769 } 5770 5771 void ARMAsmParser::cvtThumbBranches(MCInst &Inst, 5772 const OperandVector &Operands) { 5773 int CondOp = -1, ImmOp = -1; 5774 switch(Inst.getOpcode()) { 5775 case ARM::tB: 5776 case ARM::tBcc: CondOp = 1; ImmOp = 2; break; 5777 5778 case ARM::t2B: 5779 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break; 5780 5781 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches"); 5782 } 5783 // first decide whether or not the branch should be conditional 5784 // by looking at it's location relative to an IT block 5785 if(inITBlock()) { 5786 // inside an IT block we cannot have any conditional branches. any 5787 // such instructions needs to be converted to unconditional form 5788 switch(Inst.getOpcode()) { 5789 case ARM::tBcc: Inst.setOpcode(ARM::tB); break; 5790 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break; 5791 } 5792 } else { 5793 // outside IT blocks we can only have unconditional branches with AL 5794 // condition code or conditional branches with non-AL condition code 5795 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode(); 5796 switch(Inst.getOpcode()) { 5797 case ARM::tB: 5798 case ARM::tBcc: 5799 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc); 5800 break; 5801 case ARM::t2B: 5802 case ARM::t2Bcc: 5803 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc); 5804 break; 5805 } 5806 } 5807 5808 // now decide on encoding size based on branch target range 5809 switch(Inst.getOpcode()) { 5810 // classify tB as either t2B or t1B based on range of immediate operand 5811 case ARM::tB: { 5812 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); 5813 if (!op.isSignedOffset<11, 1>() && isThumb() && hasV8MBaseline()) 5814 Inst.setOpcode(ARM::t2B); 5815 break; 5816 } 5817 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand 5818 case ARM::tBcc: { 5819 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); 5820 if (!op.isSignedOffset<8, 1>() && isThumb() && hasV8MBaseline()) 5821 Inst.setOpcode(ARM::t2Bcc); 5822 break; 5823 } 5824 } 5825 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1); 5826 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2); 5827 } 5828 5829 void ARMAsmParser::cvtMVEVMOVQtoDReg( 5830 MCInst &Inst, const OperandVector &Operands) { 5831 5832 // mnemonic, condition code, Rt, Rt2, Qd, idx, Qd again, idx2 5833 assert(Operands.size() == 8); 5834 5835 ((ARMOperand &)*Operands[2]).addRegOperands(Inst, 1); // Rt 5836 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1); // Rt2 5837 ((ARMOperand &)*Operands[4]).addRegOperands(Inst, 1); // Qd 5838 ((ARMOperand &)*Operands[5]).addMVEPairVectorIndexOperands(Inst, 1); // idx 5839 // skip second copy of Qd in Operands[6] 5840 ((ARMOperand &)*Operands[7]).addMVEPairVectorIndexOperands(Inst, 1); // idx2 5841 ((ARMOperand &)*Operands[1]).addCondCodeOperands(Inst, 2); // condition code 5842 } 5843 5844 /// Parse an ARM memory expression, return false if successful else return true 5845 /// or an error. The first token must be a '[' when called. 5846 bool ARMAsmParser::parseMemory(OperandVector &Operands) { 5847 MCAsmParser &Parser = getParser(); 5848 SMLoc S, E; 5849 if (Parser.getTok().isNot(AsmToken::LBrac)) 5850 return TokError("Token is not a Left Bracket"); 5851 S = Parser.getTok().getLoc(); 5852 Parser.Lex(); // Eat left bracket token. 5853 5854 const AsmToken &BaseRegTok = Parser.getTok(); 5855 int BaseRegNum = tryParseRegister(); 5856 if (BaseRegNum == -1) 5857 return Error(BaseRegTok.getLoc(), "register expected"); 5858 5859 // The next token must either be a comma, a colon or a closing bracket. 5860 const AsmToken &Tok = Parser.getTok(); 5861 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) && 5862 !Tok.is(AsmToken::RBrac)) 5863 return Error(Tok.getLoc(), "malformed memory operand"); 5864 5865 if (Tok.is(AsmToken::RBrac)) { 5866 E = Tok.getEndLoc(); 5867 Parser.Lex(); // Eat right bracket token. 5868 5869 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, 5870 ARM_AM::no_shift, 0, 0, false, 5871 S, E)); 5872 5873 // If there's a pre-indexing writeback marker, '!', just add it as a token 5874 // operand. It's rather odd, but syntactically valid. 5875 if (Parser.getTok().is(AsmToken::Exclaim)) { 5876 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 5877 Parser.Lex(); // Eat the '!'. 5878 } 5879 5880 return false; 5881 } 5882 5883 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) && 5884 "Lost colon or comma in memory operand?!"); 5885 if (Tok.is(AsmToken::Comma)) { 5886 Parser.Lex(); // Eat the comma. 5887 } 5888 5889 // If we have a ':', it's an alignment specifier. 5890 if (Parser.getTok().is(AsmToken::Colon)) { 5891 Parser.Lex(); // Eat the ':'. 5892 E = Parser.getTok().getLoc(); 5893 SMLoc AlignmentLoc = Tok.getLoc(); 5894 5895 const MCExpr *Expr; 5896 if (getParser().parseExpression(Expr)) 5897 return true; 5898 5899 // The expression has to be a constant. Memory references with relocations 5900 // don't come through here, as they use the <label> forms of the relevant 5901 // instructions. 5902 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); 5903 if (!CE) 5904 return Error (E, "constant expression expected"); 5905 5906 unsigned Align = 0; 5907 switch (CE->getValue()) { 5908 default: 5909 return Error(E, 5910 "alignment specifier must be 16, 32, 64, 128, or 256 bits"); 5911 case 16: Align = 2; break; 5912 case 32: Align = 4; break; 5913 case 64: Align = 8; break; 5914 case 128: Align = 16; break; 5915 case 256: Align = 32; break; 5916 } 5917 5918 // Now we should have the closing ']' 5919 if (Parser.getTok().isNot(AsmToken::RBrac)) 5920 return Error(Parser.getTok().getLoc(), "']' expected"); 5921 E = Parser.getTok().getEndLoc(); 5922 Parser.Lex(); // Eat right bracket token. 5923 5924 // Don't worry about range checking the value here. That's handled by 5925 // the is*() predicates. 5926 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, 5927 ARM_AM::no_shift, 0, Align, 5928 false, S, E, AlignmentLoc)); 5929 5930 // If there's a pre-indexing writeback marker, '!', just add it as a token 5931 // operand. 5932 if (Parser.getTok().is(AsmToken::Exclaim)) { 5933 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 5934 Parser.Lex(); // Eat the '!'. 5935 } 5936 5937 return false; 5938 } 5939 5940 // If we have a '#' or '$', it's an immediate offset, else assume it's a 5941 // register offset. Be friendly and also accept a plain integer or expression 5942 // (without a leading hash) for gas compatibility. 5943 if (Parser.getTok().is(AsmToken::Hash) || 5944 Parser.getTok().is(AsmToken::Dollar) || 5945 Parser.getTok().is(AsmToken::LParen) || 5946 Parser.getTok().is(AsmToken::Integer)) { 5947 if (Parser.getTok().is(AsmToken::Hash) || 5948 Parser.getTok().is(AsmToken::Dollar)) 5949 Parser.Lex(); // Eat '#' or '$' 5950 E = Parser.getTok().getLoc(); 5951 5952 bool isNegative = getParser().getTok().is(AsmToken::Minus); 5953 const MCExpr *Offset, *AdjustedOffset; 5954 if (getParser().parseExpression(Offset)) 5955 return true; 5956 5957 if (const auto *CE = dyn_cast<MCConstantExpr>(Offset)) { 5958 // If the constant was #-0, represent it as 5959 // std::numeric_limits<int32_t>::min(). 5960 int32_t Val = CE->getValue(); 5961 if (isNegative && Val == 0) 5962 CE = MCConstantExpr::create(std::numeric_limits<int32_t>::min(), 5963 getContext()); 5964 // Don't worry about range checking the value here. That's handled by 5965 // the is*() predicates. 5966 AdjustedOffset = CE; 5967 } else 5968 AdjustedOffset = Offset; 5969 Operands.push_back(ARMOperand::CreateMem( 5970 BaseRegNum, AdjustedOffset, 0, ARM_AM::no_shift, 0, 0, false, S, E)); 5971 5972 // Now we should have the closing ']' 5973 if (Parser.getTok().isNot(AsmToken::RBrac)) 5974 return Error(Parser.getTok().getLoc(), "']' expected"); 5975 E = Parser.getTok().getEndLoc(); 5976 Parser.Lex(); // Eat right bracket token. 5977 5978 // If there's a pre-indexing writeback marker, '!', just add it as a token 5979 // operand. 5980 if (Parser.getTok().is(AsmToken::Exclaim)) { 5981 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 5982 Parser.Lex(); // Eat the '!'. 5983 } 5984 5985 return false; 5986 } 5987 5988 // The register offset is optionally preceded by a '+' or '-' 5989 bool isNegative = false; 5990 if (Parser.getTok().is(AsmToken::Minus)) { 5991 isNegative = true; 5992 Parser.Lex(); // Eat the '-'. 5993 } else if (Parser.getTok().is(AsmToken::Plus)) { 5994 // Nothing to do. 5995 Parser.Lex(); // Eat the '+'. 5996 } 5997 5998 E = Parser.getTok().getLoc(); 5999 int OffsetRegNum = tryParseRegister(); 6000 if (OffsetRegNum == -1) 6001 return Error(E, "register expected"); 6002 6003 // If there's a shift operator, handle it. 6004 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift; 6005 unsigned ShiftImm = 0; 6006 if (Parser.getTok().is(AsmToken::Comma)) { 6007 Parser.Lex(); // Eat the ','. 6008 if (parseMemRegOffsetShift(ShiftType, ShiftImm)) 6009 return true; 6010 } 6011 6012 // Now we should have the closing ']' 6013 if (Parser.getTok().isNot(AsmToken::RBrac)) 6014 return Error(Parser.getTok().getLoc(), "']' expected"); 6015 E = Parser.getTok().getEndLoc(); 6016 Parser.Lex(); // Eat right bracket token. 6017 6018 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum, 6019 ShiftType, ShiftImm, 0, isNegative, 6020 S, E)); 6021 6022 // If there's a pre-indexing writeback marker, '!', just add it as a token 6023 // operand. 6024 if (Parser.getTok().is(AsmToken::Exclaim)) { 6025 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 6026 Parser.Lex(); // Eat the '!'. 6027 } 6028 6029 return false; 6030 } 6031 6032 /// parseMemRegOffsetShift - one of these two: 6033 /// ( lsl | lsr | asr | ror ) , # shift_amount 6034 /// rrx 6035 /// return true if it parses a shift otherwise it returns false. 6036 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St, 6037 unsigned &Amount) { 6038 MCAsmParser &Parser = getParser(); 6039 SMLoc Loc = Parser.getTok().getLoc(); 6040 const AsmToken &Tok = Parser.getTok(); 6041 if (Tok.isNot(AsmToken::Identifier)) 6042 return Error(Loc, "illegal shift operator"); 6043 StringRef ShiftName = Tok.getString(); 6044 if (ShiftName == "lsl" || ShiftName == "LSL" || 6045 ShiftName == "asl" || ShiftName == "ASL") 6046 St = ARM_AM::lsl; 6047 else if (ShiftName == "lsr" || ShiftName == "LSR") 6048 St = ARM_AM::lsr; 6049 else if (ShiftName == "asr" || ShiftName == "ASR") 6050 St = ARM_AM::asr; 6051 else if (ShiftName == "ror" || ShiftName == "ROR") 6052 St = ARM_AM::ror; 6053 else if (ShiftName == "rrx" || ShiftName == "RRX") 6054 St = ARM_AM::rrx; 6055 else if (ShiftName == "uxtw" || ShiftName == "UXTW") 6056 St = ARM_AM::uxtw; 6057 else 6058 return Error(Loc, "illegal shift operator"); 6059 Parser.Lex(); // Eat shift type token. 6060 6061 // rrx stands alone. 6062 Amount = 0; 6063 if (St != ARM_AM::rrx) { 6064 Loc = Parser.getTok().getLoc(); 6065 // A '#' and a shift amount. 6066 const AsmToken &HashTok = Parser.getTok(); 6067 if (HashTok.isNot(AsmToken::Hash) && 6068 HashTok.isNot(AsmToken::Dollar)) 6069 return Error(HashTok.getLoc(), "'#' expected"); 6070 Parser.Lex(); // Eat hash token. 6071 6072 const MCExpr *Expr; 6073 if (getParser().parseExpression(Expr)) 6074 return true; 6075 // Range check the immediate. 6076 // lsl, ror: 0 <= imm <= 31 6077 // lsr, asr: 0 <= imm <= 32 6078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); 6079 if (!CE) 6080 return Error(Loc, "shift amount must be an immediate"); 6081 int64_t Imm = CE->getValue(); 6082 if (Imm < 0 || 6083 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) || 6084 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32)) 6085 return Error(Loc, "immediate shift value out of range"); 6086 // If <ShiftTy> #0, turn it into a no_shift. 6087 if (Imm == 0) 6088 St = ARM_AM::lsl; 6089 // For consistency, treat lsr #32 and asr #32 as having immediate value 0. 6090 if (Imm == 32) 6091 Imm = 0; 6092 Amount = Imm; 6093 } 6094 6095 return false; 6096 } 6097 6098 /// parseFPImm - A floating point immediate expression operand. 6099 OperandMatchResultTy 6100 ARMAsmParser::parseFPImm(OperandVector &Operands) { 6101 MCAsmParser &Parser = getParser(); 6102 // Anything that can accept a floating point constant as an operand 6103 // needs to go through here, as the regular parseExpression is 6104 // integer only. 6105 // 6106 // This routine still creates a generic Immediate operand, containing 6107 // a bitcast of the 64-bit floating point value. The various operands 6108 // that accept floats can check whether the value is valid for them 6109 // via the standard is*() predicates. 6110 6111 SMLoc S = Parser.getTok().getLoc(); 6112 6113 if (Parser.getTok().isNot(AsmToken::Hash) && 6114 Parser.getTok().isNot(AsmToken::Dollar)) 6115 return MatchOperand_NoMatch; 6116 6117 // Disambiguate the VMOV forms that can accept an FP immediate. 6118 // vmov.f32 <sreg>, #imm 6119 // vmov.f64 <dreg>, #imm 6120 // vmov.f32 <dreg>, #imm @ vector f32x2 6121 // vmov.f32 <qreg>, #imm @ vector f32x4 6122 // 6123 // There are also the NEON VMOV instructions which expect an 6124 // integer constant. Make sure we don't try to parse an FPImm 6125 // for these: 6126 // vmov.i{8|16|32|64} <dreg|qreg>, #imm 6127 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]); 6128 bool isVmovf = TyOp.isToken() && 6129 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64" || 6130 TyOp.getToken() == ".f16"); 6131 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]); 6132 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" || 6133 Mnemonic.getToken() == "fconsts"); 6134 if (!(isVmovf || isFconst)) 6135 return MatchOperand_NoMatch; 6136 6137 Parser.Lex(); // Eat '#' or '$'. 6138 6139 // Handle negation, as that still comes through as a separate token. 6140 bool isNegative = false; 6141 if (Parser.getTok().is(AsmToken::Minus)) { 6142 isNegative = true; 6143 Parser.Lex(); 6144 } 6145 const AsmToken &Tok = Parser.getTok(); 6146 SMLoc Loc = Tok.getLoc(); 6147 if (Tok.is(AsmToken::Real) && isVmovf) { 6148 APFloat RealVal(APFloat::IEEEsingle(), Tok.getString()); 6149 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue(); 6150 // If we had a '-' in front, toggle the sign bit. 6151 IntVal ^= (uint64_t)isNegative << 31; 6152 Parser.Lex(); // Eat the token. 6153 Operands.push_back(ARMOperand::CreateImm( 6154 MCConstantExpr::create(IntVal, getContext()), 6155 S, Parser.getTok().getLoc())); 6156 return MatchOperand_Success; 6157 } 6158 // Also handle plain integers. Instructions which allow floating point 6159 // immediates also allow a raw encoded 8-bit value. 6160 if (Tok.is(AsmToken::Integer) && isFconst) { 6161 int64_t Val = Tok.getIntVal(); 6162 Parser.Lex(); // Eat the token. 6163 if (Val > 255 || Val < 0) { 6164 Error(Loc, "encoded floating point value out of range"); 6165 return MatchOperand_ParseFail; 6166 } 6167 float RealVal = ARM_AM::getFPImmFloat(Val); 6168 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue(); 6169 6170 Operands.push_back(ARMOperand::CreateImm( 6171 MCConstantExpr::create(Val, getContext()), S, 6172 Parser.getTok().getLoc())); 6173 return MatchOperand_Success; 6174 } 6175 6176 Error(Loc, "invalid floating point immediate"); 6177 return MatchOperand_ParseFail; 6178 } 6179 6180 /// Parse a arm instruction operand. For now this parses the operand regardless 6181 /// of the mnemonic. 6182 bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) { 6183 MCAsmParser &Parser = getParser(); 6184 SMLoc S, E; 6185 6186 // Check if the current operand has a custom associated parser, if so, try to 6187 // custom parse the operand, or fallback to the general approach. 6188 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic); 6189 if (ResTy == MatchOperand_Success) 6190 return false; 6191 // If there wasn't a custom match, try the generic matcher below. Otherwise, 6192 // there was a match, but an error occurred, in which case, just return that 6193 // the operand parsing failed. 6194 if (ResTy == MatchOperand_ParseFail) 6195 return true; 6196 6197 switch (getLexer().getKind()) { 6198 default: 6199 Error(Parser.getTok().getLoc(), "unexpected token in operand"); 6200 return true; 6201 case AsmToken::Identifier: { 6202 // If we've seen a branch mnemonic, the next operand must be a label. This 6203 // is true even if the label is a register name. So "br r1" means branch to 6204 // label "r1". 6205 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl"; 6206 if (!ExpectLabel) { 6207 if (!tryParseRegisterWithWriteBack(Operands)) 6208 return false; 6209 int Res = tryParseShiftRegister(Operands); 6210 if (Res == 0) // success 6211 return false; 6212 else if (Res == -1) // irrecoverable error 6213 return true; 6214 // If this is VMRS, check for the apsr_nzcv operand. 6215 if (Mnemonic == "vmrs" && 6216 Parser.getTok().getString().equals_insensitive("apsr_nzcv")) { 6217 S = Parser.getTok().getLoc(); 6218 Parser.Lex(); 6219 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S)); 6220 return false; 6221 } 6222 } 6223 6224 // Fall though for the Identifier case that is not a register or a 6225 // special name. 6226 LLVM_FALLTHROUGH; 6227 } 6228 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4) 6229 case AsmToken::Integer: // things like 1f and 2b as a branch targets 6230 case AsmToken::String: // quoted label names. 6231 case AsmToken::Dot: { // . as a branch target 6232 // This was not a register so parse other operands that start with an 6233 // identifier (like labels) as expressions and create them as immediates. 6234 const MCExpr *IdVal; 6235 S = Parser.getTok().getLoc(); 6236 if (getParser().parseExpression(IdVal)) 6237 return true; 6238 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 6239 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E)); 6240 return false; 6241 } 6242 case AsmToken::LBrac: 6243 return parseMemory(Operands); 6244 case AsmToken::LCurly: 6245 return parseRegisterList(Operands, !Mnemonic.startswith("clr")); 6246 case AsmToken::Dollar: 6247 case AsmToken::Hash: { 6248 // #42 -> immediate 6249 // $ 42 -> immediate 6250 // $foo -> symbol name 6251 // $42 -> symbol name 6252 S = Parser.getTok().getLoc(); 6253 6254 // Favor the interpretation of $-prefixed operands as symbol names. 6255 // Cases where immediates are explicitly expected are handled by their 6256 // specific ParseMethod implementations. 6257 auto AdjacentToken = getLexer().peekTok(/*ShouldSkipSpace=*/false); 6258 bool ExpectIdentifier = Parser.getTok().is(AsmToken::Dollar) && 6259 (AdjacentToken.is(AsmToken::Identifier) || 6260 AdjacentToken.is(AsmToken::Integer)); 6261 if (!ExpectIdentifier) { 6262 // Token is not part of identifier. Drop leading $ or # before parsing 6263 // expression. 6264 Parser.Lex(); 6265 } 6266 6267 if (Parser.getTok().isNot(AsmToken::Colon)) { 6268 bool IsNegative = Parser.getTok().is(AsmToken::Minus); 6269 const MCExpr *ImmVal; 6270 if (getParser().parseExpression(ImmVal)) 6271 return true; 6272 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal); 6273 if (CE) { 6274 int32_t Val = CE->getValue(); 6275 if (IsNegative && Val == 0) 6276 ImmVal = MCConstantExpr::create(std::numeric_limits<int32_t>::min(), 6277 getContext()); 6278 } 6279 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 6280 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E)); 6281 6282 // There can be a trailing '!' on operands that we want as a separate 6283 // '!' Token operand. Handle that here. For example, the compatibility 6284 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'. 6285 if (Parser.getTok().is(AsmToken::Exclaim)) { 6286 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(), 6287 Parser.getTok().getLoc())); 6288 Parser.Lex(); // Eat exclaim token 6289 } 6290 return false; 6291 } 6292 // w/ a ':' after the '#', it's just like a plain ':'. 6293 LLVM_FALLTHROUGH; 6294 } 6295 case AsmToken::Colon: { 6296 S = Parser.getTok().getLoc(); 6297 // ":lower16:" and ":upper16:" expression prefixes 6298 // FIXME: Check it's an expression prefix, 6299 // e.g. (FOO - :lower16:BAR) isn't legal. 6300 ARMMCExpr::VariantKind RefKind; 6301 if (parsePrefix(RefKind)) 6302 return true; 6303 6304 const MCExpr *SubExprVal; 6305 if (getParser().parseExpression(SubExprVal)) 6306 return true; 6307 6308 const MCExpr *ExprVal = ARMMCExpr::create(RefKind, SubExprVal, 6309 getContext()); 6310 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 6311 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E)); 6312 return false; 6313 } 6314 case AsmToken::Equal: { 6315 S = Parser.getTok().getLoc(); 6316 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val) 6317 return Error(S, "unexpected token in operand"); 6318 Parser.Lex(); // Eat '=' 6319 const MCExpr *SubExprVal; 6320 if (getParser().parseExpression(SubExprVal)) 6321 return true; 6322 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 6323 6324 // execute-only: we assume that assembly programmers know what they are 6325 // doing and allow literal pool creation here 6326 Operands.push_back(ARMOperand::CreateConstantPoolImm(SubExprVal, S, E)); 6327 return false; 6328 } 6329 } 6330 } 6331 6332 bool ARMAsmParser::parseImmExpr(int64_t &Out) { 6333 const MCExpr *Expr = nullptr; 6334 SMLoc L = getParser().getTok().getLoc(); 6335 if (check(getParser().parseExpression(Expr), L, "expected expression")) 6336 return true; 6337 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr); 6338 if (check(!Value, L, "expected constant expression")) 6339 return true; 6340 Out = Value->getValue(); 6341 return false; 6342 } 6343 6344 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e. 6345 // :lower16: and :upper16:. 6346 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) { 6347 MCAsmParser &Parser = getParser(); 6348 RefKind = ARMMCExpr::VK_ARM_None; 6349 6350 // consume an optional '#' (GNU compatibility) 6351 if (getLexer().is(AsmToken::Hash)) 6352 Parser.Lex(); 6353 6354 // :lower16: and :upper16: modifiers 6355 assert(getLexer().is(AsmToken::Colon) && "expected a :"); 6356 Parser.Lex(); // Eat ':' 6357 6358 if (getLexer().isNot(AsmToken::Identifier)) { 6359 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand"); 6360 return true; 6361 } 6362 6363 enum { 6364 COFF = (1 << MCContext::IsCOFF), 6365 ELF = (1 << MCContext::IsELF), 6366 MACHO = (1 << MCContext::IsMachO), 6367 WASM = (1 << MCContext::IsWasm), 6368 }; 6369 static const struct PrefixEntry { 6370 const char *Spelling; 6371 ARMMCExpr::VariantKind VariantKind; 6372 uint8_t SupportedFormats; 6373 } PrefixEntries[] = { 6374 { "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO }, 6375 { "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO }, 6376 }; 6377 6378 StringRef IDVal = Parser.getTok().getIdentifier(); 6379 6380 const auto &Prefix = 6381 llvm::find_if(PrefixEntries, [&IDVal](const PrefixEntry &PE) { 6382 return PE.Spelling == IDVal; 6383 }); 6384 if (Prefix == std::end(PrefixEntries)) { 6385 Error(Parser.getTok().getLoc(), "unexpected prefix in operand"); 6386 return true; 6387 } 6388 6389 uint8_t CurrentFormat; 6390 switch (getContext().getObjectFileType()) { 6391 case MCContext::IsMachO: 6392 CurrentFormat = MACHO; 6393 break; 6394 case MCContext::IsELF: 6395 CurrentFormat = ELF; 6396 break; 6397 case MCContext::IsCOFF: 6398 CurrentFormat = COFF; 6399 break; 6400 case MCContext::IsWasm: 6401 CurrentFormat = WASM; 6402 break; 6403 case MCContext::IsGOFF: 6404 case MCContext::IsSPIRV: 6405 case MCContext::IsXCOFF: 6406 case MCContext::IsDXContainer: 6407 llvm_unreachable("unexpected object format"); 6408 break; 6409 } 6410 6411 if (~Prefix->SupportedFormats & CurrentFormat) { 6412 Error(Parser.getTok().getLoc(), 6413 "cannot represent relocation in the current file format"); 6414 return true; 6415 } 6416 6417 RefKind = Prefix->VariantKind; 6418 Parser.Lex(); 6419 6420 if (getLexer().isNot(AsmToken::Colon)) { 6421 Error(Parser.getTok().getLoc(), "unexpected token after prefix"); 6422 return true; 6423 } 6424 Parser.Lex(); // Eat the last ':' 6425 6426 return false; 6427 } 6428 6429 /// Given a mnemonic, split out possible predication code and carry 6430 /// setting letters to form a canonical mnemonic and flags. 6431 // 6432 // FIXME: Would be nice to autogen this. 6433 // FIXME: This is a bit of a maze of special cases. 6434 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic, 6435 StringRef ExtraToken, 6436 unsigned &PredicationCode, 6437 unsigned &VPTPredicationCode, 6438 bool &CarrySetting, 6439 unsigned &ProcessorIMod, 6440 StringRef &ITMask) { 6441 PredicationCode = ARMCC::AL; 6442 VPTPredicationCode = ARMVCC::None; 6443 CarrySetting = false; 6444 ProcessorIMod = 0; 6445 6446 // Ignore some mnemonics we know aren't predicated forms. 6447 // 6448 // FIXME: Would be nice to autogen this. 6449 if ((Mnemonic == "movs" && isThumb()) || 6450 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" || 6451 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" || 6452 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" || 6453 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" || 6454 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" || 6455 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" || 6456 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" || 6457 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" || 6458 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || 6459 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || 6460 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" || 6461 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" || 6462 Mnemonic.startswith("vsel") || Mnemonic == "vins" || Mnemonic == "vmovx" || 6463 Mnemonic == "bxns" || Mnemonic == "blxns" || 6464 Mnemonic == "vdot" || Mnemonic == "vmmla" || 6465 Mnemonic == "vudot" || Mnemonic == "vsdot" || 6466 Mnemonic == "vcmla" || Mnemonic == "vcadd" || 6467 Mnemonic == "vfmal" || Mnemonic == "vfmsl" || 6468 Mnemonic == "wls" || Mnemonic == "le" || Mnemonic == "dls" || 6469 Mnemonic == "csel" || Mnemonic == "csinc" || 6470 Mnemonic == "csinv" || Mnemonic == "csneg" || Mnemonic == "cinc" || 6471 Mnemonic == "cinv" || Mnemonic == "cneg" || Mnemonic == "cset" || 6472 Mnemonic == "csetm" || 6473 Mnemonic == "aut" || Mnemonic == "pac" || Mnemonic == "pacbti" || 6474 Mnemonic == "bti") 6475 return Mnemonic; 6476 6477 // First, split out any predication code. Ignore mnemonics we know aren't 6478 // predicated but do have a carry-set and so weren't caught above. 6479 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" && 6480 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" && 6481 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" && 6482 Mnemonic != "sbcs" && Mnemonic != "rscs" && 6483 !(hasMVE() && 6484 (Mnemonic == "vmine" || 6485 Mnemonic == "vshle" || Mnemonic == "vshlt" || Mnemonic == "vshllt" || 6486 Mnemonic == "vrshle" || Mnemonic == "vrshlt" || 6487 Mnemonic == "vmvne" || Mnemonic == "vorne" || 6488 Mnemonic == "vnege" || Mnemonic == "vnegt" || 6489 Mnemonic == "vmule" || Mnemonic == "vmult" || 6490 Mnemonic == "vrintne" || 6491 Mnemonic == "vcmult" || Mnemonic == "vcmule" || 6492 Mnemonic == "vpsele" || Mnemonic == "vpselt" || 6493 Mnemonic.startswith("vq")))) { 6494 unsigned CC = ARMCondCodeFromString(Mnemonic.substr(Mnemonic.size()-2)); 6495 if (CC != ~0U) { 6496 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2); 6497 PredicationCode = CC; 6498 } 6499 } 6500 6501 // Next, determine if we have a carry setting bit. We explicitly ignore all 6502 // the instructions we know end in 's'. 6503 if (Mnemonic.endswith("s") && 6504 !(Mnemonic == "cps" || Mnemonic == "mls" || 6505 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" || 6506 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" || 6507 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" || 6508 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" || 6509 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" || 6510 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" || 6511 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" || 6512 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" || 6513 Mnemonic == "bxns" || Mnemonic == "blxns" || Mnemonic == "vfmas" || 6514 Mnemonic == "vmlas" || 6515 (Mnemonic == "movs" && isThumb()))) { 6516 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1); 6517 CarrySetting = true; 6518 } 6519 6520 // The "cps" instruction can have a interrupt mode operand which is glued into 6521 // the mnemonic. Check if this is the case, split it and parse the imod op 6522 if (Mnemonic.startswith("cps")) { 6523 // Split out any imod code. 6524 unsigned IMod = 6525 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2)) 6526 .Case("ie", ARM_PROC::IE) 6527 .Case("id", ARM_PROC::ID) 6528 .Default(~0U); 6529 if (IMod != ~0U) { 6530 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2); 6531 ProcessorIMod = IMod; 6532 } 6533 } 6534 6535 if (isMnemonicVPTPredicable(Mnemonic, ExtraToken) && Mnemonic != "vmovlt" && 6536 Mnemonic != "vshllt" && Mnemonic != "vrshrnt" && Mnemonic != "vshrnt" && 6537 Mnemonic != "vqrshrunt" && Mnemonic != "vqshrunt" && 6538 Mnemonic != "vqrshrnt" && Mnemonic != "vqshrnt" && Mnemonic != "vmullt" && 6539 Mnemonic != "vqmovnt" && Mnemonic != "vqmovunt" && 6540 Mnemonic != "vqmovnt" && Mnemonic != "vmovnt" && Mnemonic != "vqdmullt" && 6541 Mnemonic != "vpnot" && Mnemonic != "vcvtt" && Mnemonic != "vcvt") { 6542 unsigned CC = ARMVectorCondCodeFromString(Mnemonic.substr(Mnemonic.size()-1)); 6543 if (CC != ~0U) { 6544 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-1); 6545 VPTPredicationCode = CC; 6546 } 6547 return Mnemonic; 6548 } 6549 6550 // The "it" instruction has the condition mask on the end of the mnemonic. 6551 if (Mnemonic.startswith("it")) { 6552 ITMask = Mnemonic.slice(2, Mnemonic.size()); 6553 Mnemonic = Mnemonic.slice(0, 2); 6554 } 6555 6556 if (Mnemonic.startswith("vpst")) { 6557 ITMask = Mnemonic.slice(4, Mnemonic.size()); 6558 Mnemonic = Mnemonic.slice(0, 4); 6559 } 6560 else if (Mnemonic.startswith("vpt")) { 6561 ITMask = Mnemonic.slice(3, Mnemonic.size()); 6562 Mnemonic = Mnemonic.slice(0, 3); 6563 } 6564 6565 return Mnemonic; 6566 } 6567 6568 /// Given a canonical mnemonic, determine if the instruction ever allows 6569 /// inclusion of carry set or predication code operands. 6570 // 6571 // FIXME: It would be nice to autogen this. 6572 void ARMAsmParser::getMnemonicAcceptInfo(StringRef Mnemonic, 6573 StringRef ExtraToken, 6574 StringRef FullInst, 6575 bool &CanAcceptCarrySet, 6576 bool &CanAcceptPredicationCode, 6577 bool &CanAcceptVPTPredicationCode) { 6578 CanAcceptVPTPredicationCode = isMnemonicVPTPredicable(Mnemonic, ExtraToken); 6579 6580 CanAcceptCarrySet = 6581 Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" || 6582 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" || 6583 Mnemonic == "add" || Mnemonic == "adc" || Mnemonic == "mul" || 6584 Mnemonic == "bic" || Mnemonic == "asr" || Mnemonic == "orr" || 6585 Mnemonic == "mvn" || Mnemonic == "rsb" || Mnemonic == "rsc" || 6586 Mnemonic == "orn" || Mnemonic == "sbc" || Mnemonic == "eor" || 6587 Mnemonic == "neg" || Mnemonic == "vfm" || Mnemonic == "vfnm" || 6588 (!isThumb() && 6589 (Mnemonic == "smull" || Mnemonic == "mov" || Mnemonic == "mla" || 6590 Mnemonic == "smlal" || Mnemonic == "umlal" || Mnemonic == "umull")); 6591 6592 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" || 6593 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" || 6594 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" || 6595 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") || 6596 Mnemonic.startswith("vsel") || Mnemonic == "vmaxnm" || 6597 Mnemonic == "vminnm" || Mnemonic == "vcvta" || Mnemonic == "vcvtn" || 6598 Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || Mnemonic == "vrinta" || 6599 Mnemonic == "vrintn" || Mnemonic == "vrintp" || Mnemonic == "vrintm" || 6600 Mnemonic.startswith("aes") || Mnemonic == "hvc" || Mnemonic == "setpan" || 6601 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") || 6602 (FullInst.startswith("vmull") && FullInst.endswith(".p64")) || 6603 Mnemonic == "vmovx" || Mnemonic == "vins" || 6604 Mnemonic == "vudot" || Mnemonic == "vsdot" || 6605 Mnemonic == "vcmla" || Mnemonic == "vcadd" || 6606 Mnemonic == "vfmal" || Mnemonic == "vfmsl" || 6607 Mnemonic == "vfmat" || Mnemonic == "vfmab" || 6608 Mnemonic == "vdot" || Mnemonic == "vmmla" || 6609 Mnemonic == "sb" || Mnemonic == "ssbb" || 6610 Mnemonic == "pssbb" || Mnemonic == "vsmmla" || 6611 Mnemonic == "vummla" || Mnemonic == "vusmmla" || 6612 Mnemonic == "vusdot" || Mnemonic == "vsudot" || 6613 Mnemonic == "bfcsel" || Mnemonic == "wls" || 6614 Mnemonic == "dls" || Mnemonic == "le" || Mnemonic == "csel" || 6615 Mnemonic == "csinc" || Mnemonic == "csinv" || Mnemonic == "csneg" || 6616 Mnemonic == "cinc" || Mnemonic == "cinv" || Mnemonic == "cneg" || 6617 Mnemonic == "cset" || Mnemonic == "csetm" || 6618 (hasCDE() && MS.isCDEInstr(Mnemonic) && 6619 !MS.isITPredicableCDEInstr(Mnemonic)) || 6620 Mnemonic.startswith("vpt") || Mnemonic.startswith("vpst") || 6621 Mnemonic == "pac" || Mnemonic == "pacbti" || Mnemonic == "aut" || 6622 Mnemonic == "bti" || 6623 (hasMVE() && 6624 (Mnemonic.startswith("vst2") || Mnemonic.startswith("vld2") || 6625 Mnemonic.startswith("vst4") || Mnemonic.startswith("vld4") || 6626 Mnemonic.startswith("wlstp") || Mnemonic.startswith("dlstp") || 6627 Mnemonic.startswith("letp")))) { 6628 // These mnemonics are never predicable 6629 CanAcceptPredicationCode = false; 6630 } else if (!isThumb()) { 6631 // Some instructions are only predicable in Thumb mode 6632 CanAcceptPredicationCode = 6633 Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" && 6634 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" && 6635 Mnemonic != "dmb" && Mnemonic != "dfb" && Mnemonic != "dsb" && 6636 Mnemonic != "isb" && Mnemonic != "pld" && Mnemonic != "pli" && 6637 Mnemonic != "pldw" && Mnemonic != "ldc2" && Mnemonic != "ldc2l" && 6638 Mnemonic != "stc2" && Mnemonic != "stc2l" && 6639 Mnemonic != "tsb" && 6640 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs"); 6641 } else if (isThumbOne()) { 6642 if (hasV6MOps()) 6643 CanAcceptPredicationCode = Mnemonic != "movs"; 6644 else 6645 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs"; 6646 } else 6647 CanAcceptPredicationCode = true; 6648 } 6649 6650 // Some Thumb instructions have two operand forms that are not 6651 // available as three operand, convert to two operand form if possible. 6652 // 6653 // FIXME: We would really like to be able to tablegen'erate this. 6654 void ARMAsmParser::tryConvertingToTwoOperandForm(StringRef Mnemonic, 6655 bool CarrySetting, 6656 OperandVector &Operands) { 6657 if (Operands.size() != 6) 6658 return; 6659 6660 const auto &Op3 = static_cast<ARMOperand &>(*Operands[3]); 6661 auto &Op4 = static_cast<ARMOperand &>(*Operands[4]); 6662 if (!Op3.isReg() || !Op4.isReg()) 6663 return; 6664 6665 auto Op3Reg = Op3.getReg(); 6666 auto Op4Reg = Op4.getReg(); 6667 6668 // For most Thumb2 cases we just generate the 3 operand form and reduce 6669 // it in processInstruction(), but the 3 operand form of ADD (t2ADDrr) 6670 // won't accept SP or PC so we do the transformation here taking care 6671 // with immediate range in the 'add sp, sp #imm' case. 6672 auto &Op5 = static_cast<ARMOperand &>(*Operands[5]); 6673 if (isThumbTwo()) { 6674 if (Mnemonic != "add") 6675 return; 6676 bool TryTransform = Op3Reg == ARM::PC || Op4Reg == ARM::PC || 6677 (Op5.isReg() && Op5.getReg() == ARM::PC); 6678 if (!TryTransform) { 6679 TryTransform = (Op3Reg == ARM::SP || Op4Reg == ARM::SP || 6680 (Op5.isReg() && Op5.getReg() == ARM::SP)) && 6681 !(Op3Reg == ARM::SP && Op4Reg == ARM::SP && 6682 Op5.isImm() && !Op5.isImm0_508s4()); 6683 } 6684 if (!TryTransform) 6685 return; 6686 } else if (!isThumbOne()) 6687 return; 6688 6689 if (!(Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" || 6690 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" || 6691 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" || 6692 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) 6693 return; 6694 6695 // If first 2 operands of a 3 operand instruction are the same 6696 // then transform to 2 operand version of the same instruction 6697 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1' 6698 bool Transform = Op3Reg == Op4Reg; 6699 6700 // For communtative operations, we might be able to transform if we swap 6701 // Op4 and Op5. The 'ADD Rdm, SP, Rdm' form is already handled specially 6702 // as tADDrsp. 6703 const ARMOperand *LastOp = &Op5; 6704 bool Swap = false; 6705 if (!Transform && Op5.isReg() && Op3Reg == Op5.getReg() && 6706 ((Mnemonic == "add" && Op4Reg != ARM::SP) || 6707 Mnemonic == "and" || Mnemonic == "eor" || 6708 Mnemonic == "adc" || Mnemonic == "orr")) { 6709 Swap = true; 6710 LastOp = &Op4; 6711 Transform = true; 6712 } 6713 6714 // If both registers are the same then remove one of them from 6715 // the operand list, with certain exceptions. 6716 if (Transform) { 6717 // Don't transform 'adds Rd, Rd, Rm' or 'sub{s} Rd, Rd, Rm' because the 6718 // 2 operand forms don't exist. 6719 if (((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub") && 6720 LastOp->isReg()) 6721 Transform = false; 6722 6723 // Don't transform 'add/sub{s} Rd, Rd, #imm' if the immediate fits into 6724 // 3-bits because the ARMARM says not to. 6725 if ((Mnemonic == "add" || Mnemonic == "sub") && LastOp->isImm0_7()) 6726 Transform = false; 6727 } 6728 6729 if (Transform) { 6730 if (Swap) 6731 std::swap(Op4, Op5); 6732 Operands.erase(Operands.begin() + 3); 6733 } 6734 } 6735 6736 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic, 6737 OperandVector &Operands) { 6738 // FIXME: This is all horribly hacky. We really need a better way to deal 6739 // with optional operands like this in the matcher table. 6740 6741 // The 'mov' mnemonic is special. One variant has a cc_out operand, while 6742 // another does not. Specifically, the MOVW instruction does not. So we 6743 // special case it here and remove the defaulted (non-setting) cc_out 6744 // operand if that's the instruction we're trying to match. 6745 // 6746 // We do this as post-processing of the explicit operands rather than just 6747 // conditionally adding the cc_out in the first place because we need 6748 // to check the type of the parsed immediate operand. 6749 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() && 6750 !static_cast<ARMOperand &>(*Operands[4]).isModImm() && 6751 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() && 6752 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) 6753 return true; 6754 6755 // Register-register 'add' for thumb does not have a cc_out operand 6756 // when there are only two register operands. 6757 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 && 6758 static_cast<ARMOperand &>(*Operands[3]).isReg() && 6759 static_cast<ARMOperand &>(*Operands[4]).isReg() && 6760 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) 6761 return true; 6762 // Register-register 'add' for thumb does not have a cc_out operand 6763 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do 6764 // have to check the immediate range here since Thumb2 has a variant 6765 // that can handle a different range and has a cc_out operand. 6766 if (((isThumb() && Mnemonic == "add") || 6767 (isThumbTwo() && Mnemonic == "sub")) && 6768 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && 6769 static_cast<ARMOperand &>(*Operands[4]).isReg() && 6770 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP && 6771 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 6772 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) || 6773 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4())) 6774 return true; 6775 // For Thumb2, add/sub immediate does not have a cc_out operand for the 6776 // imm0_4095 variant. That's the least-preferred variant when 6777 // selecting via the generic "add" mnemonic, so to know that we 6778 // should remove the cc_out operand, we have to explicitly check that 6779 // it's not one of the other variants. Ugh. 6780 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") && 6781 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && 6782 static_cast<ARMOperand &>(*Operands[4]).isReg() && 6783 static_cast<ARMOperand &>(*Operands[5]).isImm()) { 6784 // Nest conditions rather than one big 'if' statement for readability. 6785 // 6786 // If both registers are low, we're in an IT block, and the immediate is 6787 // in range, we should use encoding T1 instead, which has a cc_out. 6788 if (inITBlock() && 6789 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) && 6790 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) && 6791 static_cast<ARMOperand &>(*Operands[5]).isImm0_7()) 6792 return false; 6793 // Check against T3. If the second register is the PC, this is an 6794 // alternate form of ADR, which uses encoding T4, so check for that too. 6795 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC && 6796 (static_cast<ARMOperand &>(*Operands[5]).isT2SOImm() || 6797 static_cast<ARMOperand &>(*Operands[5]).isT2SOImmNeg())) 6798 return false; 6799 6800 // Otherwise, we use encoding T4, which does not have a cc_out 6801 // operand. 6802 return true; 6803 } 6804 6805 // The thumb2 multiply instruction doesn't have a CCOut register, so 6806 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to 6807 // use the 16-bit encoding or not. 6808 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 && 6809 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 6810 static_cast<ARMOperand &>(*Operands[3]).isReg() && 6811 static_cast<ARMOperand &>(*Operands[4]).isReg() && 6812 static_cast<ARMOperand &>(*Operands[5]).isReg() && 6813 // If the registers aren't low regs, the destination reg isn't the 6814 // same as one of the source regs, or the cc_out operand is zero 6815 // outside of an IT block, we have to use the 32-bit encoding, so 6816 // remove the cc_out operand. 6817 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || 6818 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || 6819 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) || 6820 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() != 6821 static_cast<ARMOperand &>(*Operands[5]).getReg() && 6822 static_cast<ARMOperand &>(*Operands[3]).getReg() != 6823 static_cast<ARMOperand &>(*Operands[4]).getReg()))) 6824 return true; 6825 6826 // Also check the 'mul' syntax variant that doesn't specify an explicit 6827 // destination register. 6828 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 && 6829 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 6830 static_cast<ARMOperand &>(*Operands[3]).isReg() && 6831 static_cast<ARMOperand &>(*Operands[4]).isReg() && 6832 // If the registers aren't low regs or the cc_out operand is zero 6833 // outside of an IT block, we have to use the 32-bit encoding, so 6834 // remove the cc_out operand. 6835 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || 6836 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || 6837 !inITBlock())) 6838 return true; 6839 6840 // Register-register 'add/sub' for thumb does not have a cc_out operand 6841 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also 6842 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't 6843 // right, this will result in better diagnostics (which operand is off) 6844 // anyway. 6845 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") && 6846 (Operands.size() == 5 || Operands.size() == 6) && 6847 static_cast<ARMOperand &>(*Operands[3]).isReg() && 6848 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP && 6849 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 6850 (static_cast<ARMOperand &>(*Operands[4]).isImm() || 6851 (Operands.size() == 6 && 6852 static_cast<ARMOperand &>(*Operands[5]).isImm()))) { 6853 // Thumb2 (add|sub){s}{p}.w GPRnopc, sp, #{T2SOImm} has cc_out 6854 return (!(isThumbTwo() && 6855 (static_cast<ARMOperand &>(*Operands[4]).isT2SOImm() || 6856 static_cast<ARMOperand &>(*Operands[4]).isT2SOImmNeg()))); 6857 } 6858 // Fixme: Should join all the thumb+thumb2 (add|sub) in a single if case 6859 // Thumb2 ADD r0, #4095 -> ADDW r0, r0, #4095 (T4) 6860 // Thumb2 SUB r0, #4095 -> SUBW r0, r0, #4095 6861 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") && 6862 (Operands.size() == 5) && 6863 static_cast<ARMOperand &>(*Operands[3]).isReg() && 6864 static_cast<ARMOperand &>(*Operands[3]).getReg() != ARM::SP && 6865 static_cast<ARMOperand &>(*Operands[3]).getReg() != ARM::PC && 6866 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 6867 static_cast<ARMOperand &>(*Operands[4]).isImm()) { 6868 const ARMOperand &IMM = static_cast<ARMOperand &>(*Operands[4]); 6869 if (IMM.isT2SOImm() || IMM.isT2SOImmNeg()) 6870 return false; // add.w / sub.w 6871 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IMM.getImm())) { 6872 const int64_t Value = CE->getValue(); 6873 // Thumb1 imm8 sub / add 6874 if ((Value < ((1 << 7) - 1) << 2) && inITBlock() && (!(Value & 3)) && 6875 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg())) 6876 return false; 6877 return true; // Thumb2 T4 addw / subw 6878 } 6879 } 6880 return false; 6881 } 6882 6883 bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic, 6884 OperandVector &Operands) { 6885 // VRINT{Z, X} have a predicate operand in VFP, but not in NEON 6886 unsigned RegIdx = 3; 6887 if ((((Mnemonic == "vrintz" || Mnemonic == "vrintx") && !hasMVE()) || 6888 Mnemonic == "vrintr") && 6889 (static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32" || 6890 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f16")) { 6891 if (static_cast<ARMOperand &>(*Operands[3]).isToken() && 6892 (static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32" || 6893 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f16")) 6894 RegIdx = 4; 6895 6896 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() && 6897 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains( 6898 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) || 6899 ARMMCRegisterClasses[ARM::QPRRegClassID].contains( 6900 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()))) 6901 return true; 6902 } 6903 return false; 6904 } 6905 6906 bool ARMAsmParser::shouldOmitVectorPredicateOperand(StringRef Mnemonic, 6907 OperandVector &Operands) { 6908 if (!hasMVE() || Operands.size() < 3) 6909 return true; 6910 6911 if (Mnemonic.startswith("vld2") || Mnemonic.startswith("vld4") || 6912 Mnemonic.startswith("vst2") || Mnemonic.startswith("vst4")) 6913 return true; 6914 6915 if (Mnemonic.startswith("vctp") || Mnemonic.startswith("vpnot")) 6916 return false; 6917 6918 if (Mnemonic.startswith("vmov") && 6919 !(Mnemonic.startswith("vmovl") || Mnemonic.startswith("vmovn") || 6920 Mnemonic.startswith("vmovx"))) { 6921 for (auto &Operand : Operands) { 6922 if (static_cast<ARMOperand &>(*Operand).isVectorIndex() || 6923 ((*Operand).isReg() && 6924 (ARMMCRegisterClasses[ARM::SPRRegClassID].contains( 6925 (*Operand).getReg()) || 6926 ARMMCRegisterClasses[ARM::DPRRegClassID].contains( 6927 (*Operand).getReg())))) { 6928 return true; 6929 } 6930 } 6931 return false; 6932 } else { 6933 for (auto &Operand : Operands) { 6934 // We check the larger class QPR instead of just the legal class 6935 // MQPR, to more accurately report errors when using Q registers 6936 // outside of the allowed range. 6937 if (static_cast<ARMOperand &>(*Operand).isVectorIndex() || 6938 (Operand->isReg() && 6939 (ARMMCRegisterClasses[ARM::QPRRegClassID].contains( 6940 Operand->getReg())))) 6941 return false; 6942 } 6943 return true; 6944 } 6945 } 6946 6947 static bool isDataTypeToken(StringRef Tok) { 6948 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" || 6949 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" || 6950 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" || 6951 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" || 6952 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" || 6953 Tok == ".f" || Tok == ".d"; 6954 } 6955 6956 // FIXME: This bit should probably be handled via an explicit match class 6957 // in the .td files that matches the suffix instead of having it be 6958 // a literal string token the way it is now. 6959 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) { 6960 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm"); 6961 } 6962 6963 static void applyMnemonicAliases(StringRef &Mnemonic, 6964 const FeatureBitset &Features, 6965 unsigned VariantID); 6966 6967 // The GNU assembler has aliases of ldrd and strd with the second register 6968 // omitted. We don't have a way to do that in tablegen, so fix it up here. 6969 // 6970 // We have to be careful to not emit an invalid Rt2 here, because the rest of 6971 // the assembly parser could then generate confusing diagnostics refering to 6972 // it. If we do find anything that prevents us from doing the transformation we 6973 // bail out, and let the assembly parser report an error on the instruction as 6974 // it is written. 6975 void ARMAsmParser::fixupGNULDRDAlias(StringRef Mnemonic, 6976 OperandVector &Operands) { 6977 if (Mnemonic != "ldrd" && Mnemonic != "strd") 6978 return; 6979 if (Operands.size() < 4) 6980 return; 6981 6982 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]); 6983 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); 6984 6985 if (!Op2.isReg()) 6986 return; 6987 if (!Op3.isGPRMem()) 6988 return; 6989 6990 const MCRegisterClass &GPR = MRI->getRegClass(ARM::GPRRegClassID); 6991 if (!GPR.contains(Op2.getReg())) 6992 return; 6993 6994 unsigned RtEncoding = MRI->getEncodingValue(Op2.getReg()); 6995 if (!isThumb() && (RtEncoding & 1)) { 6996 // In ARM mode, the registers must be from an aligned pair, this 6997 // restriction does not apply in Thumb mode. 6998 return; 6999 } 7000 if (Op2.getReg() == ARM::PC) 7001 return; 7002 unsigned PairedReg = GPR.getRegister(RtEncoding + 1); 7003 if (!PairedReg || PairedReg == ARM::PC || 7004 (PairedReg == ARM::SP && !hasV8Ops())) 7005 return; 7006 7007 Operands.insert( 7008 Operands.begin() + 3, 7009 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc())); 7010 } 7011 7012 // Dual-register instruction have the following syntax: 7013 // <mnemonic> <predicate>? <coproc>, <Rdest>, <Rdest+1>, <Rsrc>, ..., #imm 7014 // This function tries to remove <Rdest+1> and replace <Rdest> with a pair 7015 // operand. If the conversion fails an error is diagnosed, and the function 7016 // returns true. 7017 bool ARMAsmParser::CDEConvertDualRegOperand(StringRef Mnemonic, 7018 OperandVector &Operands) { 7019 assert(MS.isCDEDualRegInstr(Mnemonic)); 7020 bool isPredicable = 7021 Mnemonic == "cx1da" || Mnemonic == "cx2da" || Mnemonic == "cx3da"; 7022 size_t NumPredOps = isPredicable ? 1 : 0; 7023 7024 if (Operands.size() <= 3 + NumPredOps) 7025 return false; 7026 7027 StringRef Op2Diag( 7028 "operand must be an even-numbered register in the range [r0, r10]"); 7029 7030 const MCParsedAsmOperand &Op2 = *Operands[2 + NumPredOps]; 7031 if (!Op2.isReg()) 7032 return Error(Op2.getStartLoc(), Op2Diag); 7033 7034 unsigned RNext; 7035 unsigned RPair; 7036 switch (Op2.getReg()) { 7037 default: 7038 return Error(Op2.getStartLoc(), Op2Diag); 7039 case ARM::R0: 7040 RNext = ARM::R1; 7041 RPair = ARM::R0_R1; 7042 break; 7043 case ARM::R2: 7044 RNext = ARM::R3; 7045 RPair = ARM::R2_R3; 7046 break; 7047 case ARM::R4: 7048 RNext = ARM::R5; 7049 RPair = ARM::R4_R5; 7050 break; 7051 case ARM::R6: 7052 RNext = ARM::R7; 7053 RPair = ARM::R6_R7; 7054 break; 7055 case ARM::R8: 7056 RNext = ARM::R9; 7057 RPair = ARM::R8_R9; 7058 break; 7059 case ARM::R10: 7060 RNext = ARM::R11; 7061 RPair = ARM::R10_R11; 7062 break; 7063 } 7064 7065 const MCParsedAsmOperand &Op3 = *Operands[3 + NumPredOps]; 7066 if (!Op3.isReg() || Op3.getReg() != RNext) 7067 return Error(Op3.getStartLoc(), "operand must be a consecutive register"); 7068 7069 Operands.erase(Operands.begin() + 3 + NumPredOps); 7070 Operands[2 + NumPredOps] = 7071 ARMOperand::CreateReg(RPair, Op2.getStartLoc(), Op2.getEndLoc()); 7072 return false; 7073 } 7074 7075 /// Parse an arm instruction mnemonic followed by its operands. 7076 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, 7077 SMLoc NameLoc, OperandVector &Operands) { 7078 MCAsmParser &Parser = getParser(); 7079 7080 // Apply mnemonic aliases before doing anything else, as the destination 7081 // mnemonic may include suffices and we want to handle them normally. 7082 // The generic tblgen'erated code does this later, at the start of 7083 // MatchInstructionImpl(), but that's too late for aliases that include 7084 // any sort of suffix. 7085 const FeatureBitset &AvailableFeatures = getAvailableFeatures(); 7086 unsigned AssemblerDialect = getParser().getAssemblerDialect(); 7087 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect); 7088 7089 // First check for the ARM-specific .req directive. 7090 if (Parser.getTok().is(AsmToken::Identifier) && 7091 Parser.getTok().getIdentifier().lower() == ".req") { 7092 parseDirectiveReq(Name, NameLoc); 7093 // We always return 'error' for this, as we're done with this 7094 // statement and don't need to match the 'instruction." 7095 return true; 7096 } 7097 7098 // Create the leading tokens for the mnemonic, split by '.' characters. 7099 size_t Start = 0, Next = Name.find('.'); 7100 StringRef Mnemonic = Name.slice(Start, Next); 7101 StringRef ExtraToken = Name.slice(Next, Name.find(' ', Next + 1)); 7102 7103 // Split out the predication code and carry setting flag from the mnemonic. 7104 unsigned PredicationCode; 7105 unsigned VPTPredicationCode; 7106 unsigned ProcessorIMod; 7107 bool CarrySetting; 7108 StringRef ITMask; 7109 Mnemonic = splitMnemonic(Mnemonic, ExtraToken, PredicationCode, VPTPredicationCode, 7110 CarrySetting, ProcessorIMod, ITMask); 7111 7112 // In Thumb1, only the branch (B) instruction can be predicated. 7113 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") { 7114 return Error(NameLoc, "conditional execution not supported in Thumb1"); 7115 } 7116 7117 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc)); 7118 7119 // Handle the mask for IT and VPT instructions. In ARMOperand and 7120 // MCOperand, this is stored in a format independent of the 7121 // condition code: the lowest set bit indicates the end of the 7122 // encoding, and above that, a 1 bit indicates 'else', and an 0 7123 // indicates 'then'. E.g. 7124 // IT -> 1000 7125 // ITx -> x100 (ITT -> 0100, ITE -> 1100) 7126 // ITxy -> xy10 (e.g. ITET -> 1010) 7127 // ITxyz -> xyz1 (e.g. ITEET -> 1101) 7128 // Note: See the ARM::PredBlockMask enum in 7129 // /lib/Target/ARM/Utils/ARMBaseInfo.h 7130 if (Mnemonic == "it" || Mnemonic.startswith("vpt") || 7131 Mnemonic.startswith("vpst")) { 7132 SMLoc Loc = Mnemonic == "it" ? SMLoc::getFromPointer(NameLoc.getPointer() + 2) : 7133 Mnemonic == "vpt" ? SMLoc::getFromPointer(NameLoc.getPointer() + 3) : 7134 SMLoc::getFromPointer(NameLoc.getPointer() + 4); 7135 if (ITMask.size() > 3) { 7136 if (Mnemonic == "it") 7137 return Error(Loc, "too many conditions on IT instruction"); 7138 return Error(Loc, "too many conditions on VPT instruction"); 7139 } 7140 unsigned Mask = 8; 7141 for (char Pos : llvm::reverse(ITMask)) { 7142 if (Pos != 't' && Pos != 'e') { 7143 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'"); 7144 } 7145 Mask >>= 1; 7146 if (Pos == 'e') 7147 Mask |= 8; 7148 } 7149 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc)); 7150 } 7151 7152 // FIXME: This is all a pretty gross hack. We should automatically handle 7153 // optional operands like this via tblgen. 7154 7155 // Next, add the CCOut and ConditionCode operands, if needed. 7156 // 7157 // For mnemonics which can ever incorporate a carry setting bit or predication 7158 // code, our matching model involves us always generating CCOut and 7159 // ConditionCode operands to match the mnemonic "as written" and then we let 7160 // the matcher deal with finding the right instruction or generating an 7161 // appropriate error. 7162 bool CanAcceptCarrySet, CanAcceptPredicationCode, CanAcceptVPTPredicationCode; 7163 getMnemonicAcceptInfo(Mnemonic, ExtraToken, Name, CanAcceptCarrySet, 7164 CanAcceptPredicationCode, CanAcceptVPTPredicationCode); 7165 7166 // If we had a carry-set on an instruction that can't do that, issue an 7167 // error. 7168 if (!CanAcceptCarrySet && CarrySetting) { 7169 return Error(NameLoc, "instruction '" + Mnemonic + 7170 "' can not set flags, but 's' suffix specified"); 7171 } 7172 // If we had a predication code on an instruction that can't do that, issue an 7173 // error. 7174 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) { 7175 return Error(NameLoc, "instruction '" + Mnemonic + 7176 "' is not predicable, but condition code specified"); 7177 } 7178 7179 // If we had a VPT predication code on an instruction that can't do that, issue an 7180 // error. 7181 if (!CanAcceptVPTPredicationCode && VPTPredicationCode != ARMVCC::None) { 7182 return Error(NameLoc, "instruction '" + Mnemonic + 7183 "' is not VPT predicable, but VPT code T/E is specified"); 7184 } 7185 7186 // Add the carry setting operand, if necessary. 7187 if (CanAcceptCarrySet) { 7188 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size()); 7189 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0, 7190 Loc)); 7191 } 7192 7193 // Add the predication code operand, if necessary. 7194 if (CanAcceptPredicationCode) { 7195 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() + 7196 CarrySetting); 7197 Operands.push_back(ARMOperand::CreateCondCode( 7198 ARMCC::CondCodes(PredicationCode), Loc)); 7199 } 7200 7201 // Add the VPT predication code operand, if necessary. 7202 // FIXME: We don't add them for the instructions filtered below as these can 7203 // have custom operands which need special parsing. This parsing requires 7204 // the operand to be in the same place in the OperandVector as their 7205 // definition in tblgen. Since these instructions may also have the 7206 // scalar predication operand we do not add the vector one and leave until 7207 // now to fix it up. 7208 if (CanAcceptVPTPredicationCode && Mnemonic != "vmov" && 7209 !Mnemonic.startswith("vcmp") && 7210 !(Mnemonic.startswith("vcvt") && Mnemonic != "vcvta" && 7211 Mnemonic != "vcvtn" && Mnemonic != "vcvtp" && Mnemonic != "vcvtm")) { 7212 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() + 7213 CarrySetting); 7214 Operands.push_back(ARMOperand::CreateVPTPred( 7215 ARMVCC::VPTCodes(VPTPredicationCode), Loc)); 7216 } 7217 7218 // Add the processor imod operand, if necessary. 7219 if (ProcessorIMod) { 7220 Operands.push_back(ARMOperand::CreateImm( 7221 MCConstantExpr::create(ProcessorIMod, getContext()), 7222 NameLoc, NameLoc)); 7223 } else if (Mnemonic == "cps" && isMClass()) { 7224 return Error(NameLoc, "instruction 'cps' requires effect for M-class"); 7225 } 7226 7227 // Add the remaining tokens in the mnemonic. 7228 while (Next != StringRef::npos) { 7229 Start = Next; 7230 Next = Name.find('.', Start + 1); 7231 ExtraToken = Name.slice(Start, Next); 7232 7233 // Some NEON instructions have an optional datatype suffix that is 7234 // completely ignored. Check for that. 7235 if (isDataTypeToken(ExtraToken) && 7236 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken)) 7237 continue; 7238 7239 // For for ARM mode generate an error if the .n qualifier is used. 7240 if (ExtraToken == ".n" && !isThumb()) { 7241 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); 7242 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in " 7243 "arm mode"); 7244 } 7245 7246 // The .n qualifier is always discarded as that is what the tables 7247 // and matcher expect. In ARM mode the .w qualifier has no effect, 7248 // so discard it to avoid errors that can be caused by the matcher. 7249 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) { 7250 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); 7251 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc)); 7252 } 7253 } 7254 7255 // Read the remaining operands. 7256 if (getLexer().isNot(AsmToken::EndOfStatement)) { 7257 // Read the first operand. 7258 if (parseOperand(Operands, Mnemonic)) { 7259 return true; 7260 } 7261 7262 while (parseOptionalToken(AsmToken::Comma)) { 7263 // Parse and remember the operand. 7264 if (parseOperand(Operands, Mnemonic)) { 7265 return true; 7266 } 7267 } 7268 } 7269 7270 if (parseToken(AsmToken::EndOfStatement, "unexpected token in argument list")) 7271 return true; 7272 7273 tryConvertingToTwoOperandForm(Mnemonic, CarrySetting, Operands); 7274 7275 if (hasCDE() && MS.isCDEInstr(Mnemonic)) { 7276 // Dual-register instructions use even-odd register pairs as their 7277 // destination operand, in assembly such pair is spelled as two 7278 // consecutive registers, without any special syntax. ConvertDualRegOperand 7279 // tries to convert such operand into register pair, e.g. r2, r3 -> r2_r3. 7280 // It returns true, if an error message has been emitted. If the function 7281 // returns false, the function either succeeded or an error (e.g. missing 7282 // operand) will be diagnosed elsewhere. 7283 if (MS.isCDEDualRegInstr(Mnemonic)) { 7284 bool GotError = CDEConvertDualRegOperand(Mnemonic, Operands); 7285 if (GotError) 7286 return GotError; 7287 } 7288 } 7289 7290 // Some instructions, mostly Thumb, have forms for the same mnemonic that 7291 // do and don't have a cc_out optional-def operand. With some spot-checks 7292 // of the operand list, we can figure out which variant we're trying to 7293 // parse and adjust accordingly before actually matching. We shouldn't ever 7294 // try to remove a cc_out operand that was explicitly set on the 7295 // mnemonic, of course (CarrySetting == true). Reason number #317 the 7296 // table driven matcher doesn't fit well with the ARM instruction set. 7297 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) 7298 Operands.erase(Operands.begin() + 1); 7299 7300 // Some instructions have the same mnemonic, but don't always 7301 // have a predicate. Distinguish them here and delete the 7302 // appropriate predicate if needed. This could be either the scalar 7303 // predication code or the vector predication code. 7304 if (PredicationCode == ARMCC::AL && 7305 shouldOmitPredicateOperand(Mnemonic, Operands)) 7306 Operands.erase(Operands.begin() + 1); 7307 7308 7309 if (hasMVE()) { 7310 if (!shouldOmitVectorPredicateOperand(Mnemonic, Operands) && 7311 Mnemonic == "vmov" && PredicationCode == ARMCC::LT) { 7312 // Very nasty hack to deal with the vector predicated variant of vmovlt 7313 // the scalar predicated vmov with condition 'lt'. We can not tell them 7314 // apart until we have parsed their operands. 7315 Operands.erase(Operands.begin() + 1); 7316 Operands.erase(Operands.begin()); 7317 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer()); 7318 SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() + 7319 Mnemonic.size() - 1 + CarrySetting); 7320 Operands.insert(Operands.begin(), 7321 ARMOperand::CreateVPTPred(ARMVCC::None, PLoc)); 7322 Operands.insert(Operands.begin(), 7323 ARMOperand::CreateToken(StringRef("vmovlt"), MLoc)); 7324 } else if (Mnemonic == "vcvt" && PredicationCode == ARMCC::NE && 7325 !shouldOmitVectorPredicateOperand(Mnemonic, Operands)) { 7326 // Another nasty hack to deal with the ambiguity between vcvt with scalar 7327 // predication 'ne' and vcvtn with vector predication 'e'. As above we 7328 // can only distinguish between the two after we have parsed their 7329 // operands. 7330 Operands.erase(Operands.begin() + 1); 7331 Operands.erase(Operands.begin()); 7332 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer()); 7333 SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() + 7334 Mnemonic.size() - 1 + CarrySetting); 7335 Operands.insert(Operands.begin(), 7336 ARMOperand::CreateVPTPred(ARMVCC::Else, PLoc)); 7337 Operands.insert(Operands.begin(), 7338 ARMOperand::CreateToken(StringRef("vcvtn"), MLoc)); 7339 } else if (Mnemonic == "vmul" && PredicationCode == ARMCC::LT && 7340 !shouldOmitVectorPredicateOperand(Mnemonic, Operands)) { 7341 // Another hack, this time to distinguish between scalar predicated vmul 7342 // with 'lt' predication code and the vector instruction vmullt with 7343 // vector predication code "none" 7344 Operands.erase(Operands.begin() + 1); 7345 Operands.erase(Operands.begin()); 7346 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer()); 7347 Operands.insert(Operands.begin(), 7348 ARMOperand::CreateToken(StringRef("vmullt"), MLoc)); 7349 } 7350 // For vmov and vcmp, as mentioned earlier, we did not add the vector 7351 // predication code, since these may contain operands that require 7352 // special parsing. So now we have to see if they require vector 7353 // predication and replace the scalar one with the vector predication 7354 // operand if that is the case. 7355 else if (Mnemonic == "vmov" || Mnemonic.startswith("vcmp") || 7356 (Mnemonic.startswith("vcvt") && !Mnemonic.startswith("vcvta") && 7357 !Mnemonic.startswith("vcvtn") && !Mnemonic.startswith("vcvtp") && 7358 !Mnemonic.startswith("vcvtm"))) { 7359 if (!shouldOmitVectorPredicateOperand(Mnemonic, Operands)) { 7360 // We could not split the vector predicate off vcvt because it might 7361 // have been the scalar vcvtt instruction. Now we know its a vector 7362 // instruction, we still need to check whether its the vector 7363 // predicated vcvt with 'Then' predication or the vector vcvtt. We can 7364 // distinguish the two based on the suffixes, if it is any of 7365 // ".f16.f32", ".f32.f16", ".f16.f64" or ".f64.f16" then it is the vcvtt. 7366 if (Mnemonic.startswith("vcvtt") && Operands.size() >= 4) { 7367 auto Sz1 = static_cast<ARMOperand &>(*Operands[2]); 7368 auto Sz2 = static_cast<ARMOperand &>(*Operands[3]); 7369 if (!(Sz1.isToken() && Sz1.getToken().startswith(".f") && 7370 Sz2.isToken() && Sz2.getToken().startswith(".f"))) { 7371 Operands.erase(Operands.begin()); 7372 SMLoc MLoc = SMLoc::getFromPointer(NameLoc.getPointer()); 7373 VPTPredicationCode = ARMVCC::Then; 7374 7375 Mnemonic = Mnemonic.substr(0, 4); 7376 Operands.insert(Operands.begin(), 7377 ARMOperand::CreateToken(Mnemonic, MLoc)); 7378 } 7379 } 7380 Operands.erase(Operands.begin() + 1); 7381 SMLoc PLoc = SMLoc::getFromPointer(NameLoc.getPointer() + 7382 Mnemonic.size() + CarrySetting); 7383 Operands.insert(Operands.begin() + 1, 7384 ARMOperand::CreateVPTPred( 7385 ARMVCC::VPTCodes(VPTPredicationCode), PLoc)); 7386 } 7387 } else if (CanAcceptVPTPredicationCode) { 7388 // For all other instructions, make sure only one of the two 7389 // predication operands is left behind, depending on whether we should 7390 // use the vector predication. 7391 if (shouldOmitVectorPredicateOperand(Mnemonic, Operands)) { 7392 if (CanAcceptPredicationCode) 7393 Operands.erase(Operands.begin() + 2); 7394 else 7395 Operands.erase(Operands.begin() + 1); 7396 } else if (CanAcceptPredicationCode && PredicationCode == ARMCC::AL) { 7397 Operands.erase(Operands.begin() + 1); 7398 } 7399 } 7400 } 7401 7402 if (VPTPredicationCode != ARMVCC::None) { 7403 bool usedVPTPredicationCode = false; 7404 for (unsigned I = 1; I < Operands.size(); ++I) 7405 if (static_cast<ARMOperand &>(*Operands[I]).isVPTPred()) 7406 usedVPTPredicationCode = true; 7407 if (!usedVPTPredicationCode) { 7408 // If we have a VPT predication code and we haven't just turned it 7409 // into an operand, then it was a mistake for splitMnemonic to 7410 // separate it from the rest of the mnemonic in the first place, 7411 // and this may lead to wrong disassembly (e.g. scalar floating 7412 // point VCMPE is actually a different instruction from VCMP, so 7413 // we mustn't treat them the same). In that situation, glue it 7414 // back on. 7415 Mnemonic = Name.slice(0, Mnemonic.size() + 1); 7416 Operands.erase(Operands.begin()); 7417 Operands.insert(Operands.begin(), 7418 ARMOperand::CreateToken(Mnemonic, NameLoc)); 7419 } 7420 } 7421 7422 // ARM mode 'blx' need special handling, as the register operand version 7423 // is predicable, but the label operand version is not. So, we can't rely 7424 // on the Mnemonic based checking to correctly figure out when to put 7425 // a k_CondCode operand in the list. If we're trying to match the label 7426 // version, remove the k_CondCode operand here. 7427 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 && 7428 static_cast<ARMOperand &>(*Operands[2]).isImm()) 7429 Operands.erase(Operands.begin() + 1); 7430 7431 // Adjust operands of ldrexd/strexd to MCK_GPRPair. 7432 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint, 7433 // a single GPRPair reg operand is used in the .td file to replace the two 7434 // GPRs. However, when parsing from asm, the two GRPs cannot be 7435 // automatically 7436 // expressed as a GPRPair, so we have to manually merge them. 7437 // FIXME: We would really like to be able to tablegen'erate this. 7438 if (!isThumb() && Operands.size() > 4 && 7439 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" || 7440 Mnemonic == "stlexd")) { 7441 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd"); 7442 unsigned Idx = isLoad ? 2 : 3; 7443 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]); 7444 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]); 7445 7446 const MCRegisterClass &MRC = MRI->getRegClass(ARM::GPRRegClassID); 7447 // Adjust only if Op1 and Op2 are GPRs. 7448 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) && 7449 MRC.contains(Op2.getReg())) { 7450 unsigned Reg1 = Op1.getReg(); 7451 unsigned Reg2 = Op2.getReg(); 7452 unsigned Rt = MRI->getEncodingValue(Reg1); 7453 unsigned Rt2 = MRI->getEncodingValue(Reg2); 7454 7455 // Rt2 must be Rt + 1 and Rt must be even. 7456 if (Rt + 1 != Rt2 || (Rt & 1)) { 7457 return Error(Op2.getStartLoc(), 7458 isLoad ? "destination operands must be sequential" 7459 : "source operands must be sequential"); 7460 } 7461 unsigned NewReg = MRI->getMatchingSuperReg( 7462 Reg1, ARM::gsub_0, &(MRI->getRegClass(ARM::GPRPairRegClassID))); 7463 Operands[Idx] = 7464 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc()); 7465 Operands.erase(Operands.begin() + Idx + 1); 7466 } 7467 } 7468 7469 // GNU Assembler extension (compatibility). 7470 fixupGNULDRDAlias(Mnemonic, Operands); 7471 7472 // FIXME: As said above, this is all a pretty gross hack. This instruction 7473 // does not fit with other "subs" and tblgen. 7474 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction 7475 // so the Mnemonic is the original name "subs" and delete the predicate 7476 // operand so it will match the table entry. 7477 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 && 7478 static_cast<ARMOperand &>(*Operands[3]).isReg() && 7479 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC && 7480 static_cast<ARMOperand &>(*Operands[4]).isReg() && 7481 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR && 7482 static_cast<ARMOperand &>(*Operands[5]).isImm()) { 7483 Operands.front() = ARMOperand::CreateToken(Name, NameLoc); 7484 Operands.erase(Operands.begin() + 1); 7485 } 7486 return false; 7487 } 7488 7489 // Validate context-sensitive operand constraints. 7490 7491 // return 'true' if register list contains non-low GPR registers, 7492 // 'false' otherwise. If Reg is in the register list or is HiReg, set 7493 // 'containsReg' to true. 7494 static bool checkLowRegisterList(const MCInst &Inst, unsigned OpNo, 7495 unsigned Reg, unsigned HiReg, 7496 bool &containsReg) { 7497 containsReg = false; 7498 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { 7499 unsigned OpReg = Inst.getOperand(i).getReg(); 7500 if (OpReg == Reg) 7501 containsReg = true; 7502 // Anything other than a low register isn't legal here. 7503 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg)) 7504 return true; 7505 } 7506 return false; 7507 } 7508 7509 // Check if the specified regisgter is in the register list of the inst, 7510 // starting at the indicated operand number. 7511 static bool listContainsReg(const MCInst &Inst, unsigned OpNo, unsigned Reg) { 7512 for (unsigned i = OpNo, e = Inst.getNumOperands(); i < e; ++i) { 7513 unsigned OpReg = Inst.getOperand(i).getReg(); 7514 if (OpReg == Reg) 7515 return true; 7516 } 7517 return false; 7518 } 7519 7520 // Return true if instruction has the interesting property of being 7521 // allowed in IT blocks, but not being predicable. 7522 static bool instIsBreakpoint(const MCInst &Inst) { 7523 return Inst.getOpcode() == ARM::tBKPT || 7524 Inst.getOpcode() == ARM::BKPT || 7525 Inst.getOpcode() == ARM::tHLT || 7526 Inst.getOpcode() == ARM::HLT; 7527 } 7528 7529 bool ARMAsmParser::validatetLDMRegList(const MCInst &Inst, 7530 const OperandVector &Operands, 7531 unsigned ListNo, bool IsARPop) { 7532 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]); 7533 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!"; 7534 7535 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP); 7536 bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR); 7537 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC); 7538 7539 if (!IsARPop && ListContainsSP) 7540 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 7541 "SP may not be in the register list"); 7542 else if (ListContainsPC && ListContainsLR) 7543 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 7544 "PC and LR may not be in the register list simultaneously"); 7545 return false; 7546 } 7547 7548 bool ARMAsmParser::validatetSTMRegList(const MCInst &Inst, 7549 const OperandVector &Operands, 7550 unsigned ListNo) { 7551 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]); 7552 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!"; 7553 7554 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP); 7555 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC); 7556 7557 if (ListContainsSP && ListContainsPC) 7558 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 7559 "SP and PC may not be in the register list"); 7560 else if (ListContainsSP) 7561 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 7562 "SP may not be in the register list"); 7563 else if (ListContainsPC) 7564 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 7565 "PC may not be in the register list"); 7566 return false; 7567 } 7568 7569 bool ARMAsmParser::validateLDRDSTRD(MCInst &Inst, 7570 const OperandVector &Operands, 7571 bool Load, bool ARMMode, bool Writeback) { 7572 unsigned RtIndex = Load || !Writeback ? 0 : 1; 7573 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(RtIndex).getReg()); 7574 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(RtIndex + 1).getReg()); 7575 7576 if (ARMMode) { 7577 // Rt can't be R14. 7578 if (Rt == 14) 7579 return Error(Operands[3]->getStartLoc(), 7580 "Rt can't be R14"); 7581 7582 // Rt must be even-numbered. 7583 if ((Rt & 1) == 1) 7584 return Error(Operands[3]->getStartLoc(), 7585 "Rt must be even-numbered"); 7586 7587 // Rt2 must be Rt + 1. 7588 if (Rt2 != Rt + 1) { 7589 if (Load) 7590 return Error(Operands[3]->getStartLoc(), 7591 "destination operands must be sequential"); 7592 else 7593 return Error(Operands[3]->getStartLoc(), 7594 "source operands must be sequential"); 7595 } 7596 7597 // FIXME: Diagnose m == 15 7598 // FIXME: Diagnose ldrd with m == t || m == t2. 7599 } 7600 7601 if (!ARMMode && Load) { 7602 if (Rt2 == Rt) 7603 return Error(Operands[3]->getStartLoc(), 7604 "destination operands can't be identical"); 7605 } 7606 7607 if (Writeback) { 7608 unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg()); 7609 7610 if (Rn == Rt || Rn == Rt2) { 7611 if (Load) 7612 return Error(Operands[3]->getStartLoc(), 7613 "base register needs to be different from destination " 7614 "registers"); 7615 else 7616 return Error(Operands[3]->getStartLoc(), 7617 "source register and base register can't be identical"); 7618 } 7619 7620 // FIXME: Diagnose ldrd/strd with writeback and n == 15. 7621 // (Except the immediate form of ldrd?) 7622 } 7623 7624 return false; 7625 } 7626 7627 static int findFirstVectorPredOperandIdx(const MCInstrDesc &MCID) { 7628 for (unsigned i = 0; i < MCID.NumOperands; ++i) { 7629 if (ARM::isVpred(MCID.OpInfo[i].OperandType)) 7630 return i; 7631 } 7632 return -1; 7633 } 7634 7635 static bool isVectorPredicable(const MCInstrDesc &MCID) { 7636 return findFirstVectorPredOperandIdx(MCID) != -1; 7637 } 7638 7639 // FIXME: We would really like to be able to tablegen'erate this. 7640 bool ARMAsmParser::validateInstruction(MCInst &Inst, 7641 const OperandVector &Operands) { 7642 const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); 7643 SMLoc Loc = Operands[0]->getStartLoc(); 7644 7645 // Check the IT block state first. 7646 // NOTE: BKPT and HLT instructions have the interesting property of being 7647 // allowed in IT blocks, but not being predicable. They just always execute. 7648 if (inITBlock() && !instIsBreakpoint(Inst)) { 7649 // The instruction must be predicable. 7650 if (!MCID.isPredicable()) 7651 return Error(Loc, "instructions in IT block must be predicable"); 7652 ARMCC::CondCodes Cond = ARMCC::CondCodes( 7653 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm()); 7654 if (Cond != currentITCond()) { 7655 // Find the condition code Operand to get its SMLoc information. 7656 SMLoc CondLoc; 7657 for (unsigned I = 1; I < Operands.size(); ++I) 7658 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode()) 7659 CondLoc = Operands[I]->getStartLoc(); 7660 return Error(CondLoc, "incorrect condition in IT block; got '" + 7661 StringRef(ARMCondCodeToString(Cond)) + 7662 "', but expected '" + 7663 ARMCondCodeToString(currentITCond()) + "'"); 7664 } 7665 // Check for non-'al' condition codes outside of the IT block. 7666 } else if (isThumbTwo() && MCID.isPredicable() && 7667 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() != 7668 ARMCC::AL && Inst.getOpcode() != ARM::tBcc && 7669 Inst.getOpcode() != ARM::t2Bcc && 7670 Inst.getOpcode() != ARM::t2BFic) { 7671 return Error(Loc, "predicated instructions must be in IT block"); 7672 } else if (!isThumb() && !useImplicitITARM() && MCID.isPredicable() && 7673 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() != 7674 ARMCC::AL) { 7675 return Warning(Loc, "predicated instructions should be in IT block"); 7676 } else if (!MCID.isPredicable()) { 7677 // Check the instruction doesn't have a predicate operand anyway 7678 // that it's not allowed to use. Sometimes this happens in order 7679 // to keep instructions the same shape even though one cannot 7680 // legally be predicated, e.g. vmul.f16 vs vmul.f32. 7681 for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i) { 7682 if (MCID.OpInfo[i].isPredicate()) { 7683 if (Inst.getOperand(i).getImm() != ARMCC::AL) 7684 return Error(Loc, "instruction is not predicable"); 7685 break; 7686 } 7687 } 7688 } 7689 7690 // PC-setting instructions in an IT block, but not the last instruction of 7691 // the block, are UNPREDICTABLE. 7692 if (inExplicitITBlock() && !lastInITBlock() && isITBlockTerminator(Inst)) { 7693 return Error(Loc, "instruction must be outside of IT block or the last instruction in an IT block"); 7694 } 7695 7696 if (inVPTBlock() && !instIsBreakpoint(Inst)) { 7697 unsigned Bit = extractITMaskBit(VPTState.Mask, VPTState.CurPosition); 7698 if (!isVectorPredicable(MCID)) 7699 return Error(Loc, "instruction in VPT block must be predicable"); 7700 unsigned Pred = Inst.getOperand(findFirstVectorPredOperandIdx(MCID)).getImm(); 7701 unsigned VPTPred = Bit ? ARMVCC::Else : ARMVCC::Then; 7702 if (Pred != VPTPred) { 7703 SMLoc PredLoc; 7704 for (unsigned I = 1; I < Operands.size(); ++I) 7705 if (static_cast<ARMOperand &>(*Operands[I]).isVPTPred()) 7706 PredLoc = Operands[I]->getStartLoc(); 7707 return Error(PredLoc, "incorrect predication in VPT block; got '" + 7708 StringRef(ARMVPTPredToString(ARMVCC::VPTCodes(Pred))) + 7709 "', but expected '" + 7710 ARMVPTPredToString(ARMVCC::VPTCodes(VPTPred)) + "'"); 7711 } 7712 } 7713 else if (isVectorPredicable(MCID) && 7714 Inst.getOperand(findFirstVectorPredOperandIdx(MCID)).getImm() != 7715 ARMVCC::None) 7716 return Error(Loc, "VPT predicated instructions must be in VPT block"); 7717 7718 const unsigned Opcode = Inst.getOpcode(); 7719 switch (Opcode) { 7720 case ARM::t2IT: { 7721 // Encoding is unpredictable if it ever results in a notional 'NV' 7722 // predicate. Since we don't parse 'NV' directly this means an 'AL' 7723 // predicate with an "else" mask bit. 7724 unsigned Cond = Inst.getOperand(0).getImm(); 7725 unsigned Mask = Inst.getOperand(1).getImm(); 7726 7727 // Conditions only allowing a 't' are those with no set bit except 7728 // the lowest-order one that indicates the end of the sequence. In 7729 // other words, powers of 2. 7730 if (Cond == ARMCC::AL && countPopulation(Mask) != 1) 7731 return Error(Loc, "unpredictable IT predicate sequence"); 7732 break; 7733 } 7734 case ARM::LDRD: 7735 if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/true, 7736 /*Writeback*/false)) 7737 return true; 7738 break; 7739 case ARM::LDRD_PRE: 7740 case ARM::LDRD_POST: 7741 if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/true, 7742 /*Writeback*/true)) 7743 return true; 7744 break; 7745 case ARM::t2LDRDi8: 7746 if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/false, 7747 /*Writeback*/false)) 7748 return true; 7749 break; 7750 case ARM::t2LDRD_PRE: 7751 case ARM::t2LDRD_POST: 7752 if (validateLDRDSTRD(Inst, Operands, /*Load*/true, /*ARMMode*/false, 7753 /*Writeback*/true)) 7754 return true; 7755 break; 7756 case ARM::t2BXJ: { 7757 const unsigned RmReg = Inst.getOperand(0).getReg(); 7758 // Rm = SP is no longer unpredictable in v8-A 7759 if (RmReg == ARM::SP && !hasV8Ops()) 7760 return Error(Operands[2]->getStartLoc(), 7761 "r13 (SP) is an unpredictable operand to BXJ"); 7762 return false; 7763 } 7764 case ARM::STRD: 7765 if (validateLDRDSTRD(Inst, Operands, /*Load*/false, /*ARMMode*/true, 7766 /*Writeback*/false)) 7767 return true; 7768 break; 7769 case ARM::STRD_PRE: 7770 case ARM::STRD_POST: 7771 if (validateLDRDSTRD(Inst, Operands, /*Load*/false, /*ARMMode*/true, 7772 /*Writeback*/true)) 7773 return true; 7774 break; 7775 case ARM::t2STRD_PRE: 7776 case ARM::t2STRD_POST: 7777 if (validateLDRDSTRD(Inst, Operands, /*Load*/false, /*ARMMode*/false, 7778 /*Writeback*/true)) 7779 return true; 7780 break; 7781 case ARM::STR_PRE_IMM: 7782 case ARM::STR_PRE_REG: 7783 case ARM::t2STR_PRE: 7784 case ARM::STR_POST_IMM: 7785 case ARM::STR_POST_REG: 7786 case ARM::t2STR_POST: 7787 case ARM::STRH_PRE: 7788 case ARM::t2STRH_PRE: 7789 case ARM::STRH_POST: 7790 case ARM::t2STRH_POST: 7791 case ARM::STRB_PRE_IMM: 7792 case ARM::STRB_PRE_REG: 7793 case ARM::t2STRB_PRE: 7794 case ARM::STRB_POST_IMM: 7795 case ARM::STRB_POST_REG: 7796 case ARM::t2STRB_POST: { 7797 // Rt must be different from Rn. 7798 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 7799 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); 7800 7801 if (Rt == Rn) 7802 return Error(Operands[3]->getStartLoc(), 7803 "source register and base register can't be identical"); 7804 return false; 7805 } 7806 case ARM::t2LDR_PRE_imm: 7807 case ARM::t2LDR_POST_imm: 7808 case ARM::t2STR_PRE_imm: 7809 case ARM::t2STR_POST_imm: { 7810 // Rt must be different from Rn. 7811 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); 7812 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 7813 7814 if (Rt == Rn) 7815 return Error(Operands[3]->getStartLoc(), 7816 "destination register and base register can't be identical"); 7817 if (Inst.getOpcode() == ARM::t2LDR_POST_imm || 7818 Inst.getOpcode() == ARM::t2STR_POST_imm) { 7819 int Imm = Inst.getOperand(2).getImm(); 7820 if (Imm > 255 || Imm < -255) 7821 return Error(Operands[5]->getStartLoc(), 7822 "operand must be in range [-255, 255]"); 7823 } 7824 if (Inst.getOpcode() == ARM::t2STR_PRE_imm || 7825 Inst.getOpcode() == ARM::t2STR_POST_imm) { 7826 if (Inst.getOperand(0).getReg() == ARM::PC) { 7827 return Error(Operands[3]->getStartLoc(), 7828 "operand must be a register in range [r0, r14]"); 7829 } 7830 } 7831 return false; 7832 } 7833 case ARM::LDR_PRE_IMM: 7834 case ARM::LDR_PRE_REG: 7835 case ARM::t2LDR_PRE: 7836 case ARM::LDR_POST_IMM: 7837 case ARM::LDR_POST_REG: 7838 case ARM::t2LDR_POST: 7839 case ARM::LDRH_PRE: 7840 case ARM::t2LDRH_PRE: 7841 case ARM::LDRH_POST: 7842 case ARM::t2LDRH_POST: 7843 case ARM::LDRSH_PRE: 7844 case ARM::t2LDRSH_PRE: 7845 case ARM::LDRSH_POST: 7846 case ARM::t2LDRSH_POST: 7847 case ARM::LDRB_PRE_IMM: 7848 case ARM::LDRB_PRE_REG: 7849 case ARM::t2LDRB_PRE: 7850 case ARM::LDRB_POST_IMM: 7851 case ARM::LDRB_POST_REG: 7852 case ARM::t2LDRB_POST: 7853 case ARM::LDRSB_PRE: 7854 case ARM::t2LDRSB_PRE: 7855 case ARM::LDRSB_POST: 7856 case ARM::t2LDRSB_POST: { 7857 // Rt must be different from Rn. 7858 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); 7859 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); 7860 7861 if (Rt == Rn) 7862 return Error(Operands[3]->getStartLoc(), 7863 "destination register and base register can't be identical"); 7864 return false; 7865 } 7866 7867 case ARM::MVE_VLDRBU8_rq: 7868 case ARM::MVE_VLDRBU16_rq: 7869 case ARM::MVE_VLDRBS16_rq: 7870 case ARM::MVE_VLDRBU32_rq: 7871 case ARM::MVE_VLDRBS32_rq: 7872 case ARM::MVE_VLDRHU16_rq: 7873 case ARM::MVE_VLDRHU16_rq_u: 7874 case ARM::MVE_VLDRHU32_rq: 7875 case ARM::MVE_VLDRHU32_rq_u: 7876 case ARM::MVE_VLDRHS32_rq: 7877 case ARM::MVE_VLDRHS32_rq_u: 7878 case ARM::MVE_VLDRWU32_rq: 7879 case ARM::MVE_VLDRWU32_rq_u: 7880 case ARM::MVE_VLDRDU64_rq: 7881 case ARM::MVE_VLDRDU64_rq_u: 7882 case ARM::MVE_VLDRWU32_qi: 7883 case ARM::MVE_VLDRWU32_qi_pre: 7884 case ARM::MVE_VLDRDU64_qi: 7885 case ARM::MVE_VLDRDU64_qi_pre: { 7886 // Qd must be different from Qm. 7887 unsigned QdIdx = 0, QmIdx = 2; 7888 bool QmIsPointer = false; 7889 switch (Opcode) { 7890 case ARM::MVE_VLDRWU32_qi: 7891 case ARM::MVE_VLDRDU64_qi: 7892 QmIdx = 1; 7893 QmIsPointer = true; 7894 break; 7895 case ARM::MVE_VLDRWU32_qi_pre: 7896 case ARM::MVE_VLDRDU64_qi_pre: 7897 QdIdx = 1; 7898 QmIsPointer = true; 7899 break; 7900 } 7901 7902 const unsigned Qd = MRI->getEncodingValue(Inst.getOperand(QdIdx).getReg()); 7903 const unsigned Qm = MRI->getEncodingValue(Inst.getOperand(QmIdx).getReg()); 7904 7905 if (Qd == Qm) { 7906 return Error(Operands[3]->getStartLoc(), 7907 Twine("destination vector register and vector ") + 7908 (QmIsPointer ? "pointer" : "offset") + 7909 " register can't be identical"); 7910 } 7911 return false; 7912 } 7913 7914 case ARM::SBFX: 7915 case ARM::t2SBFX: 7916 case ARM::UBFX: 7917 case ARM::t2UBFX: { 7918 // Width must be in range [1, 32-lsb]. 7919 unsigned LSB = Inst.getOperand(2).getImm(); 7920 unsigned Widthm1 = Inst.getOperand(3).getImm(); 7921 if (Widthm1 >= 32 - LSB) 7922 return Error(Operands[5]->getStartLoc(), 7923 "bitfield width must be in range [1,32-lsb]"); 7924 return false; 7925 } 7926 // Notionally handles ARM::tLDMIA_UPD too. 7927 case ARM::tLDMIA: { 7928 // If we're parsing Thumb2, the .w variant is available and handles 7929 // most cases that are normally illegal for a Thumb1 LDM instruction. 7930 // We'll make the transformation in processInstruction() if necessary. 7931 // 7932 // Thumb LDM instructions are writeback iff the base register is not 7933 // in the register list. 7934 unsigned Rn = Inst.getOperand(0).getReg(); 7935 bool HasWritebackToken = 7936 (static_cast<ARMOperand &>(*Operands[3]).isToken() && 7937 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); 7938 bool ListContainsBase; 7939 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo()) 7940 return Error(Operands[3 + HasWritebackToken]->getStartLoc(), 7941 "registers must be in range r0-r7"); 7942 // If we should have writeback, then there should be a '!' token. 7943 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo()) 7944 return Error(Operands[2]->getStartLoc(), 7945 "writeback operator '!' expected"); 7946 // If we should not have writeback, there must not be a '!'. This is 7947 // true even for the 32-bit wide encodings. 7948 if (ListContainsBase && HasWritebackToken) 7949 return Error(Operands[3]->getStartLoc(), 7950 "writeback operator '!' not allowed when base register " 7951 "in register list"); 7952 7953 if (validatetLDMRegList(Inst, Operands, 3)) 7954 return true; 7955 break; 7956 } 7957 case ARM::LDMIA_UPD: 7958 case ARM::LDMDB_UPD: 7959 case ARM::LDMIB_UPD: 7960 case ARM::LDMDA_UPD: 7961 // ARM variants loading and updating the same register are only officially 7962 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before. 7963 if (!hasV7Ops()) 7964 break; 7965 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) 7966 return Error(Operands.back()->getStartLoc(), 7967 "writeback register not allowed in register list"); 7968 break; 7969 case ARM::t2LDMIA: 7970 case ARM::t2LDMDB: 7971 if (validatetLDMRegList(Inst, Operands, 3)) 7972 return true; 7973 break; 7974 case ARM::t2STMIA: 7975 case ARM::t2STMDB: 7976 if (validatetSTMRegList(Inst, Operands, 3)) 7977 return true; 7978 break; 7979 case ARM::t2LDMIA_UPD: 7980 case ARM::t2LDMDB_UPD: 7981 case ARM::t2STMIA_UPD: 7982 case ARM::t2STMDB_UPD: 7983 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) 7984 return Error(Operands.back()->getStartLoc(), 7985 "writeback register not allowed in register list"); 7986 7987 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) { 7988 if (validatetLDMRegList(Inst, Operands, 3)) 7989 return true; 7990 } else { 7991 if (validatetSTMRegList(Inst, Operands, 3)) 7992 return true; 7993 } 7994 break; 7995 7996 case ARM::sysLDMIA_UPD: 7997 case ARM::sysLDMDA_UPD: 7998 case ARM::sysLDMDB_UPD: 7999 case ARM::sysLDMIB_UPD: 8000 if (!listContainsReg(Inst, 3, ARM::PC)) 8001 return Error(Operands[4]->getStartLoc(), 8002 "writeback register only allowed on system LDM " 8003 "if PC in register-list"); 8004 break; 8005 case ARM::sysSTMIA_UPD: 8006 case ARM::sysSTMDA_UPD: 8007 case ARM::sysSTMDB_UPD: 8008 case ARM::sysSTMIB_UPD: 8009 return Error(Operands[2]->getStartLoc(), 8010 "system STM cannot have writeback register"); 8011 case ARM::tMUL: 8012 // The second source operand must be the same register as the destination 8013 // operand. 8014 // 8015 // In this case, we must directly check the parsed operands because the 8016 // cvtThumbMultiply() function is written in such a way that it guarantees 8017 // this first statement is always true for the new Inst. Essentially, the 8018 // destination is unconditionally copied into the second source operand 8019 // without checking to see if it matches what we actually parsed. 8020 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() != 8021 ((ARMOperand &)*Operands[5]).getReg()) && 8022 (((ARMOperand &)*Operands[3]).getReg() != 8023 ((ARMOperand &)*Operands[4]).getReg())) { 8024 return Error(Operands[3]->getStartLoc(), 8025 "destination register must match source register"); 8026 } 8027 break; 8028 8029 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2, 8030 // so only issue a diagnostic for thumb1. The instructions will be 8031 // switched to the t2 encodings in processInstruction() if necessary. 8032 case ARM::tPOP: { 8033 bool ListContainsBase; 8034 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) && 8035 !isThumbTwo()) 8036 return Error(Operands[2]->getStartLoc(), 8037 "registers must be in range r0-r7 or pc"); 8038 if (validatetLDMRegList(Inst, Operands, 2, !isMClass())) 8039 return true; 8040 break; 8041 } 8042 case ARM::tPUSH: { 8043 bool ListContainsBase; 8044 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) && 8045 !isThumbTwo()) 8046 return Error(Operands[2]->getStartLoc(), 8047 "registers must be in range r0-r7 or lr"); 8048 if (validatetSTMRegList(Inst, Operands, 2)) 8049 return true; 8050 break; 8051 } 8052 case ARM::tSTMIA_UPD: { 8053 bool ListContainsBase, InvalidLowList; 8054 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(), 8055 0, ListContainsBase); 8056 if (InvalidLowList && !isThumbTwo()) 8057 return Error(Operands[4]->getStartLoc(), 8058 "registers must be in range r0-r7"); 8059 8060 // This would be converted to a 32-bit stm, but that's not valid if the 8061 // writeback register is in the list. 8062 if (InvalidLowList && ListContainsBase) 8063 return Error(Operands[4]->getStartLoc(), 8064 "writeback operator '!' not allowed when base register " 8065 "in register list"); 8066 8067 if (validatetSTMRegList(Inst, Operands, 4)) 8068 return true; 8069 break; 8070 } 8071 case ARM::tADDrSP: 8072 // If the non-SP source operand and the destination operand are not the 8073 // same, we need thumb2 (for the wide encoding), or we have an error. 8074 if (!isThumbTwo() && 8075 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { 8076 return Error(Operands[4]->getStartLoc(), 8077 "source register must be the same as destination"); 8078 } 8079 break; 8080 8081 case ARM::t2ADDrr: 8082 case ARM::t2ADDrs: 8083 case ARM::t2SUBrr: 8084 case ARM::t2SUBrs: 8085 if (Inst.getOperand(0).getReg() == ARM::SP && 8086 Inst.getOperand(1).getReg() != ARM::SP) 8087 return Error(Operands[4]->getStartLoc(), 8088 "source register must be sp if destination is sp"); 8089 break; 8090 8091 // Final range checking for Thumb unconditional branch instructions. 8092 case ARM::tB: 8093 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>()) 8094 return Error(Operands[2]->getStartLoc(), "branch target out of range"); 8095 break; 8096 case ARM::t2B: { 8097 int op = (Operands[2]->isImm()) ? 2 : 3; 8098 ARMOperand &Operand = static_cast<ARMOperand &>(*Operands[op]); 8099 // Delay the checks of symbolic expressions until they are resolved. 8100 if (!isa<MCBinaryExpr>(Operand.getImm()) && 8101 !Operand.isSignedOffset<24, 1>()) 8102 return Error(Operands[op]->getStartLoc(), "branch target out of range"); 8103 break; 8104 } 8105 // Final range checking for Thumb conditional branch instructions. 8106 case ARM::tBcc: 8107 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>()) 8108 return Error(Operands[2]->getStartLoc(), "branch target out of range"); 8109 break; 8110 case ARM::t2Bcc: { 8111 int Op = (Operands[2]->isImm()) ? 2 : 3; 8112 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>()) 8113 return Error(Operands[Op]->getStartLoc(), "branch target out of range"); 8114 break; 8115 } 8116 case ARM::tCBZ: 8117 case ARM::tCBNZ: { 8118 if (!static_cast<ARMOperand &>(*Operands[2]).isUnsignedOffset<6, 1>()) 8119 return Error(Operands[2]->getStartLoc(), "branch target out of range"); 8120 break; 8121 } 8122 case ARM::MOVi16: 8123 case ARM::MOVTi16: 8124 case ARM::t2MOVi16: 8125 case ARM::t2MOVTi16: 8126 { 8127 // We want to avoid misleadingly allowing something like "mov r0, <symbol>" 8128 // especially when we turn it into a movw and the expression <symbol> does 8129 // not have a :lower16: or :upper16 as part of the expression. We don't 8130 // want the behavior of silently truncating, which can be unexpected and 8131 // lead to bugs that are difficult to find since this is an easy mistake 8132 // to make. 8133 int i = (Operands[3]->isImm()) ? 3 : 4; 8134 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]); 8135 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()); 8136 if (CE) break; 8137 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm()); 8138 if (!E) break; 8139 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E); 8140 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 && 8141 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)) 8142 return Error( 8143 Op.getStartLoc(), 8144 "immediate expression for mov requires :lower16: or :upper16"); 8145 break; 8146 } 8147 case ARM::HINT: 8148 case ARM::t2HINT: { 8149 unsigned Imm8 = Inst.getOperand(0).getImm(); 8150 unsigned Pred = Inst.getOperand(1).getImm(); 8151 // ESB is not predicable (pred must be AL). Without the RAS extension, this 8152 // behaves as any other unallocated hint. 8153 if (Imm8 == 0x10 && Pred != ARMCC::AL && hasRAS()) 8154 return Error(Operands[1]->getStartLoc(), "instruction 'esb' is not " 8155 "predicable, but condition " 8156 "code specified"); 8157 if (Imm8 == 0x14 && Pred != ARMCC::AL) 8158 return Error(Operands[1]->getStartLoc(), "instruction 'csdb' is not " 8159 "predicable, but condition " 8160 "code specified"); 8161 break; 8162 } 8163 case ARM::t2BFi: 8164 case ARM::t2BFr: 8165 case ARM::t2BFLi: 8166 case ARM::t2BFLr: { 8167 if (!static_cast<ARMOperand &>(*Operands[2]).isUnsignedOffset<4, 1>() || 8168 (Inst.getOperand(0).isImm() && Inst.getOperand(0).getImm() == 0)) 8169 return Error(Operands[2]->getStartLoc(), 8170 "branch location out of range or not a multiple of 2"); 8171 8172 if (Opcode == ARM::t2BFi) { 8173 if (!static_cast<ARMOperand &>(*Operands[3]).isSignedOffset<16, 1>()) 8174 return Error(Operands[3]->getStartLoc(), 8175 "branch target out of range or not a multiple of 2"); 8176 } else if (Opcode == ARM::t2BFLi) { 8177 if (!static_cast<ARMOperand &>(*Operands[3]).isSignedOffset<18, 1>()) 8178 return Error(Operands[3]->getStartLoc(), 8179 "branch target out of range or not a multiple of 2"); 8180 } 8181 break; 8182 } 8183 case ARM::t2BFic: { 8184 if (!static_cast<ARMOperand &>(*Operands[1]).isUnsignedOffset<4, 1>() || 8185 (Inst.getOperand(0).isImm() && Inst.getOperand(0).getImm() == 0)) 8186 return Error(Operands[1]->getStartLoc(), 8187 "branch location out of range or not a multiple of 2"); 8188 8189 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<16, 1>()) 8190 return Error(Operands[2]->getStartLoc(), 8191 "branch target out of range or not a multiple of 2"); 8192 8193 assert(Inst.getOperand(0).isImm() == Inst.getOperand(2).isImm() && 8194 "branch location and else branch target should either both be " 8195 "immediates or both labels"); 8196 8197 if (Inst.getOperand(0).isImm() && Inst.getOperand(2).isImm()) { 8198 int Diff = Inst.getOperand(2).getImm() - Inst.getOperand(0).getImm(); 8199 if (Diff != 4 && Diff != 2) 8200 return Error( 8201 Operands[3]->getStartLoc(), 8202 "else branch target must be 2 or 4 greater than the branch location"); 8203 } 8204 break; 8205 } 8206 case ARM::t2CLRM: { 8207 for (unsigned i = 2; i < Inst.getNumOperands(); i++) { 8208 if (Inst.getOperand(i).isReg() && 8209 !ARMMCRegisterClasses[ARM::GPRwithAPSRnospRegClassID].contains( 8210 Inst.getOperand(i).getReg())) { 8211 return Error(Operands[2]->getStartLoc(), 8212 "invalid register in register list. Valid registers are " 8213 "r0-r12, lr/r14 and APSR."); 8214 } 8215 } 8216 break; 8217 } 8218 case ARM::DSB: 8219 case ARM::t2DSB: { 8220 8221 if (Inst.getNumOperands() < 2) 8222 break; 8223 8224 unsigned Option = Inst.getOperand(0).getImm(); 8225 unsigned Pred = Inst.getOperand(1).getImm(); 8226 8227 // SSBB and PSSBB (DSB #0|#4) are not predicable (pred must be AL). 8228 if (Option == 0 && Pred != ARMCC::AL) 8229 return Error(Operands[1]->getStartLoc(), 8230 "instruction 'ssbb' is not predicable, but condition code " 8231 "specified"); 8232 if (Option == 4 && Pred != ARMCC::AL) 8233 return Error(Operands[1]->getStartLoc(), 8234 "instruction 'pssbb' is not predicable, but condition code " 8235 "specified"); 8236 break; 8237 } 8238 case ARM::VMOVRRS: { 8239 // Source registers must be sequential. 8240 const unsigned Sm = MRI->getEncodingValue(Inst.getOperand(2).getReg()); 8241 const unsigned Sm1 = MRI->getEncodingValue(Inst.getOperand(3).getReg()); 8242 if (Sm1 != Sm + 1) 8243 return Error(Operands[5]->getStartLoc(), 8244 "source operands must be sequential"); 8245 break; 8246 } 8247 case ARM::VMOVSRR: { 8248 // Destination registers must be sequential. 8249 const unsigned Sm = MRI->getEncodingValue(Inst.getOperand(0).getReg()); 8250 const unsigned Sm1 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 8251 if (Sm1 != Sm + 1) 8252 return Error(Operands[3]->getStartLoc(), 8253 "destination operands must be sequential"); 8254 break; 8255 } 8256 case ARM::VLDMDIA: 8257 case ARM::VSTMDIA: { 8258 ARMOperand &Op = static_cast<ARMOperand&>(*Operands[3]); 8259 auto &RegList = Op.getRegList(); 8260 if (RegList.size() < 1 || RegList.size() > 16) 8261 return Error(Operands[3]->getStartLoc(), 8262 "list of registers must be at least 1 and at most 16"); 8263 break; 8264 } 8265 case ARM::MVE_VQDMULLs32bh: 8266 case ARM::MVE_VQDMULLs32th: 8267 case ARM::MVE_VCMULf32: 8268 case ARM::MVE_VMULLBs32: 8269 case ARM::MVE_VMULLTs32: 8270 case ARM::MVE_VMULLBu32: 8271 case ARM::MVE_VMULLTu32: { 8272 if (Operands[3]->getReg() == Operands[4]->getReg()) { 8273 return Error (Operands[3]->getStartLoc(), 8274 "Qd register and Qn register can't be identical"); 8275 } 8276 if (Operands[3]->getReg() == Operands[5]->getReg()) { 8277 return Error (Operands[3]->getStartLoc(), 8278 "Qd register and Qm register can't be identical"); 8279 } 8280 break; 8281 } 8282 case ARM::MVE_VMOV_rr_q: { 8283 if (Operands[4]->getReg() != Operands[6]->getReg()) 8284 return Error (Operands[4]->getStartLoc(), "Q-registers must be the same"); 8285 if (static_cast<ARMOperand &>(*Operands[5]).getVectorIndex() != 8286 static_cast<ARMOperand &>(*Operands[7]).getVectorIndex() + 2) 8287 return Error (Operands[5]->getStartLoc(), "Q-register indexes must be 2 and 0 or 3 and 1"); 8288 break; 8289 } 8290 case ARM::MVE_VMOV_q_rr: { 8291 if (Operands[2]->getReg() != Operands[4]->getReg()) 8292 return Error (Operands[2]->getStartLoc(), "Q-registers must be the same"); 8293 if (static_cast<ARMOperand &>(*Operands[3]).getVectorIndex() != 8294 static_cast<ARMOperand &>(*Operands[5]).getVectorIndex() + 2) 8295 return Error (Operands[3]->getStartLoc(), "Q-register indexes must be 2 and 0 or 3 and 1"); 8296 break; 8297 } 8298 case ARM::UMAAL: 8299 case ARM::UMLAL: 8300 case ARM::UMULL: 8301 case ARM::t2UMAAL: 8302 case ARM::t2UMLAL: 8303 case ARM::t2UMULL: 8304 case ARM::SMLAL: 8305 case ARM::SMLALBB: 8306 case ARM::SMLALBT: 8307 case ARM::SMLALD: 8308 case ARM::SMLALDX: 8309 case ARM::SMLALTB: 8310 case ARM::SMLALTT: 8311 case ARM::SMLSLD: 8312 case ARM::SMLSLDX: 8313 case ARM::SMULL: 8314 case ARM::t2SMLAL: 8315 case ARM::t2SMLALBB: 8316 case ARM::t2SMLALBT: 8317 case ARM::t2SMLALD: 8318 case ARM::t2SMLALDX: 8319 case ARM::t2SMLALTB: 8320 case ARM::t2SMLALTT: 8321 case ARM::t2SMLSLD: 8322 case ARM::t2SMLSLDX: 8323 case ARM::t2SMULL: { 8324 unsigned RdHi = Inst.getOperand(0).getReg(); 8325 unsigned RdLo = Inst.getOperand(1).getReg(); 8326 if(RdHi == RdLo) { 8327 return Error(Loc, 8328 "unpredictable instruction, RdHi and RdLo must be different"); 8329 } 8330 break; 8331 } 8332 8333 case ARM::CDE_CX1: 8334 case ARM::CDE_CX1A: 8335 case ARM::CDE_CX1D: 8336 case ARM::CDE_CX1DA: 8337 case ARM::CDE_CX2: 8338 case ARM::CDE_CX2A: 8339 case ARM::CDE_CX2D: 8340 case ARM::CDE_CX2DA: 8341 case ARM::CDE_CX3: 8342 case ARM::CDE_CX3A: 8343 case ARM::CDE_CX3D: 8344 case ARM::CDE_CX3DA: 8345 case ARM::CDE_VCX1_vec: 8346 case ARM::CDE_VCX1_fpsp: 8347 case ARM::CDE_VCX1_fpdp: 8348 case ARM::CDE_VCX1A_vec: 8349 case ARM::CDE_VCX1A_fpsp: 8350 case ARM::CDE_VCX1A_fpdp: 8351 case ARM::CDE_VCX2_vec: 8352 case ARM::CDE_VCX2_fpsp: 8353 case ARM::CDE_VCX2_fpdp: 8354 case ARM::CDE_VCX2A_vec: 8355 case ARM::CDE_VCX2A_fpsp: 8356 case ARM::CDE_VCX2A_fpdp: 8357 case ARM::CDE_VCX3_vec: 8358 case ARM::CDE_VCX3_fpsp: 8359 case ARM::CDE_VCX3_fpdp: 8360 case ARM::CDE_VCX3A_vec: 8361 case ARM::CDE_VCX3A_fpsp: 8362 case ARM::CDE_VCX3A_fpdp: { 8363 assert(Inst.getOperand(1).isImm() && 8364 "CDE operand 1 must be a coprocessor ID"); 8365 int64_t Coproc = Inst.getOperand(1).getImm(); 8366 if (Coproc < 8 && !ARM::isCDECoproc(Coproc, *STI)) 8367 return Error(Operands[1]->getStartLoc(), 8368 "coprocessor must be configured as CDE"); 8369 else if (Coproc >= 8) 8370 return Error(Operands[1]->getStartLoc(), 8371 "coprocessor must be in the range [p0, p7]"); 8372 break; 8373 } 8374 8375 case ARM::t2CDP: 8376 case ARM::t2CDP2: 8377 case ARM::t2LDC2L_OFFSET: 8378 case ARM::t2LDC2L_OPTION: 8379 case ARM::t2LDC2L_POST: 8380 case ARM::t2LDC2L_PRE: 8381 case ARM::t2LDC2_OFFSET: 8382 case ARM::t2LDC2_OPTION: 8383 case ARM::t2LDC2_POST: 8384 case ARM::t2LDC2_PRE: 8385 case ARM::t2LDCL_OFFSET: 8386 case ARM::t2LDCL_OPTION: 8387 case ARM::t2LDCL_POST: 8388 case ARM::t2LDCL_PRE: 8389 case ARM::t2LDC_OFFSET: 8390 case ARM::t2LDC_OPTION: 8391 case ARM::t2LDC_POST: 8392 case ARM::t2LDC_PRE: 8393 case ARM::t2MCR: 8394 case ARM::t2MCR2: 8395 case ARM::t2MCRR: 8396 case ARM::t2MCRR2: 8397 case ARM::t2MRC: 8398 case ARM::t2MRC2: 8399 case ARM::t2MRRC: 8400 case ARM::t2MRRC2: 8401 case ARM::t2STC2L_OFFSET: 8402 case ARM::t2STC2L_OPTION: 8403 case ARM::t2STC2L_POST: 8404 case ARM::t2STC2L_PRE: 8405 case ARM::t2STC2_OFFSET: 8406 case ARM::t2STC2_OPTION: 8407 case ARM::t2STC2_POST: 8408 case ARM::t2STC2_PRE: 8409 case ARM::t2STCL_OFFSET: 8410 case ARM::t2STCL_OPTION: 8411 case ARM::t2STCL_POST: 8412 case ARM::t2STCL_PRE: 8413 case ARM::t2STC_OFFSET: 8414 case ARM::t2STC_OPTION: 8415 case ARM::t2STC_POST: 8416 case ARM::t2STC_PRE: { 8417 unsigned Opcode = Inst.getOpcode(); 8418 // Inst.getOperand indexes operands in the (oops ...) and (iops ...) dags, 8419 // CopInd is the index of the coprocessor operand. 8420 size_t CopInd = 0; 8421 if (Opcode == ARM::t2MRRC || Opcode == ARM::t2MRRC2) 8422 CopInd = 2; 8423 else if (Opcode == ARM::t2MRC || Opcode == ARM::t2MRC2) 8424 CopInd = 1; 8425 assert(Inst.getOperand(CopInd).isImm() && 8426 "Operand must be a coprocessor ID"); 8427 int64_t Coproc = Inst.getOperand(CopInd).getImm(); 8428 // Operands[2] is the coprocessor operand at syntactic level 8429 if (ARM::isCDECoproc(Coproc, *STI)) 8430 return Error(Operands[2]->getStartLoc(), 8431 "coprocessor must be configured as GCP"); 8432 break; 8433 } 8434 } 8435 8436 return false; 8437 } 8438 8439 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) { 8440 switch(Opc) { 8441 default: llvm_unreachable("unexpected opcode!"); 8442 // VST1LN 8443 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; 8444 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; 8445 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; 8446 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; 8447 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; 8448 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; 8449 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8; 8450 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16; 8451 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32; 8452 8453 // VST2LN 8454 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; 8455 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; 8456 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; 8457 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; 8458 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; 8459 8460 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; 8461 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; 8462 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; 8463 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; 8464 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; 8465 8466 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8; 8467 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16; 8468 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32; 8469 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16; 8470 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32; 8471 8472 // VST3LN 8473 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; 8474 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; 8475 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; 8476 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD; 8477 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; 8478 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; 8479 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; 8480 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; 8481 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD; 8482 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; 8483 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8; 8484 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16; 8485 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32; 8486 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16; 8487 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32; 8488 8489 // VST3 8490 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; 8491 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; 8492 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; 8493 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; 8494 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; 8495 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; 8496 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; 8497 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; 8498 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; 8499 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; 8500 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; 8501 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; 8502 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8; 8503 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16; 8504 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32; 8505 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8; 8506 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16; 8507 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32; 8508 8509 // VST4LN 8510 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; 8511 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; 8512 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; 8513 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD; 8514 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; 8515 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; 8516 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; 8517 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; 8518 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD; 8519 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; 8520 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8; 8521 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16; 8522 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32; 8523 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16; 8524 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32; 8525 8526 // VST4 8527 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; 8528 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; 8529 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; 8530 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; 8531 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; 8532 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; 8533 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; 8534 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; 8535 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; 8536 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; 8537 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; 8538 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; 8539 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8; 8540 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16; 8541 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32; 8542 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8; 8543 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16; 8544 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32; 8545 } 8546 } 8547 8548 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) { 8549 switch(Opc) { 8550 default: llvm_unreachable("unexpected opcode!"); 8551 // VLD1LN 8552 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; 8553 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; 8554 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; 8555 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; 8556 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; 8557 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; 8558 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8; 8559 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16; 8560 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32; 8561 8562 // VLD2LN 8563 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; 8564 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; 8565 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; 8566 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD; 8567 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; 8568 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; 8569 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; 8570 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; 8571 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD; 8572 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; 8573 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8; 8574 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16; 8575 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32; 8576 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16; 8577 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32; 8578 8579 // VLD3DUP 8580 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; 8581 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; 8582 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; 8583 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD; 8584 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; 8585 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; 8586 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; 8587 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; 8588 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; 8589 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD; 8590 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; 8591 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; 8592 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8; 8593 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16; 8594 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32; 8595 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8; 8596 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16; 8597 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32; 8598 8599 // VLD3LN 8600 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; 8601 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; 8602 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; 8603 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD; 8604 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; 8605 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; 8606 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; 8607 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; 8608 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD; 8609 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; 8610 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8; 8611 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16; 8612 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32; 8613 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16; 8614 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32; 8615 8616 // VLD3 8617 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; 8618 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; 8619 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; 8620 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; 8621 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; 8622 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; 8623 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; 8624 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; 8625 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; 8626 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; 8627 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; 8628 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; 8629 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8; 8630 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16; 8631 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32; 8632 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8; 8633 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16; 8634 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32; 8635 8636 // VLD4LN 8637 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; 8638 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; 8639 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; 8640 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; 8641 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; 8642 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; 8643 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; 8644 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; 8645 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; 8646 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; 8647 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8; 8648 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16; 8649 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32; 8650 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16; 8651 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32; 8652 8653 // VLD4DUP 8654 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; 8655 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; 8656 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; 8657 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD; 8658 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD; 8659 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; 8660 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; 8661 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; 8662 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; 8663 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD; 8664 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD; 8665 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; 8666 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8; 8667 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16; 8668 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32; 8669 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8; 8670 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16; 8671 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32; 8672 8673 // VLD4 8674 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; 8675 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; 8676 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; 8677 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; 8678 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; 8679 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; 8680 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; 8681 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; 8682 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; 8683 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; 8684 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; 8685 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; 8686 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8; 8687 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16; 8688 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32; 8689 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8; 8690 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16; 8691 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32; 8692 } 8693 } 8694 8695 bool ARMAsmParser::processInstruction(MCInst &Inst, 8696 const OperandVector &Operands, 8697 MCStreamer &Out) { 8698 // Check if we have the wide qualifier, because if it's present we 8699 // must avoid selecting a 16-bit thumb instruction. 8700 bool HasWideQualifier = false; 8701 for (auto &Op : Operands) { 8702 ARMOperand &ARMOp = static_cast<ARMOperand&>(*Op); 8703 if (ARMOp.isToken() && ARMOp.getToken() == ".w") { 8704 HasWideQualifier = true; 8705 break; 8706 } 8707 } 8708 8709 switch (Inst.getOpcode()) { 8710 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction. 8711 case ARM::LDRT_POST: 8712 case ARM::LDRBT_POST: { 8713 const unsigned Opcode = 8714 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM 8715 : ARM::LDRBT_POST_IMM; 8716 MCInst TmpInst; 8717 TmpInst.setOpcode(Opcode); 8718 TmpInst.addOperand(Inst.getOperand(0)); 8719 TmpInst.addOperand(Inst.getOperand(1)); 8720 TmpInst.addOperand(Inst.getOperand(1)); 8721 TmpInst.addOperand(MCOperand::createReg(0)); 8722 TmpInst.addOperand(MCOperand::createImm(0)); 8723 TmpInst.addOperand(Inst.getOperand(2)); 8724 TmpInst.addOperand(Inst.getOperand(3)); 8725 Inst = TmpInst; 8726 return true; 8727 } 8728 // Alias for 'ldr{sb,h,sh}t Rt, [Rn] {, #imm}' for ommitted immediate. 8729 case ARM::LDRSBTii: 8730 case ARM::LDRHTii: 8731 case ARM::LDRSHTii: { 8732 MCInst TmpInst; 8733 8734 if (Inst.getOpcode() == ARM::LDRSBTii) 8735 TmpInst.setOpcode(ARM::LDRSBTi); 8736 else if (Inst.getOpcode() == ARM::LDRHTii) 8737 TmpInst.setOpcode(ARM::LDRHTi); 8738 else if (Inst.getOpcode() == ARM::LDRSHTii) 8739 TmpInst.setOpcode(ARM::LDRSHTi); 8740 TmpInst.addOperand(Inst.getOperand(0)); 8741 TmpInst.addOperand(Inst.getOperand(1)); 8742 TmpInst.addOperand(Inst.getOperand(1)); 8743 TmpInst.addOperand(MCOperand::createImm(256)); 8744 TmpInst.addOperand(Inst.getOperand(2)); 8745 Inst = TmpInst; 8746 return true; 8747 } 8748 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction. 8749 case ARM::STRT_POST: 8750 case ARM::STRBT_POST: { 8751 const unsigned Opcode = 8752 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM 8753 : ARM::STRBT_POST_IMM; 8754 MCInst TmpInst; 8755 TmpInst.setOpcode(Opcode); 8756 TmpInst.addOperand(Inst.getOperand(1)); 8757 TmpInst.addOperand(Inst.getOperand(0)); 8758 TmpInst.addOperand(Inst.getOperand(1)); 8759 TmpInst.addOperand(MCOperand::createReg(0)); 8760 TmpInst.addOperand(MCOperand::createImm(0)); 8761 TmpInst.addOperand(Inst.getOperand(2)); 8762 TmpInst.addOperand(Inst.getOperand(3)); 8763 Inst = TmpInst; 8764 return true; 8765 } 8766 // Alias for alternate form of 'ADR Rd, #imm' instruction. 8767 case ARM::ADDri: { 8768 if (Inst.getOperand(1).getReg() != ARM::PC || 8769 Inst.getOperand(5).getReg() != 0 || 8770 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm())) 8771 return false; 8772 MCInst TmpInst; 8773 TmpInst.setOpcode(ARM::ADR); 8774 TmpInst.addOperand(Inst.getOperand(0)); 8775 if (Inst.getOperand(2).isImm()) { 8776 // Immediate (mod_imm) will be in its encoded form, we must unencode it 8777 // before passing it to the ADR instruction. 8778 unsigned Enc = Inst.getOperand(2).getImm(); 8779 TmpInst.addOperand(MCOperand::createImm( 8780 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7))); 8781 } else { 8782 // Turn PC-relative expression into absolute expression. 8783 // Reading PC provides the start of the current instruction + 8 and 8784 // the transform to adr is biased by that. 8785 MCSymbol *Dot = getContext().createTempSymbol(); 8786 Out.emitLabel(Dot); 8787 const MCExpr *OpExpr = Inst.getOperand(2).getExpr(); 8788 const MCExpr *InstPC = MCSymbolRefExpr::create(Dot, 8789 MCSymbolRefExpr::VK_None, 8790 getContext()); 8791 const MCExpr *Const8 = MCConstantExpr::create(8, getContext()); 8792 const MCExpr *ReadPC = MCBinaryExpr::createAdd(InstPC, Const8, 8793 getContext()); 8794 const MCExpr *FixupAddr = MCBinaryExpr::createAdd(ReadPC, OpExpr, 8795 getContext()); 8796 TmpInst.addOperand(MCOperand::createExpr(FixupAddr)); 8797 } 8798 TmpInst.addOperand(Inst.getOperand(3)); 8799 TmpInst.addOperand(Inst.getOperand(4)); 8800 Inst = TmpInst; 8801 return true; 8802 } 8803 // Aliases for imm syntax of LDR instructions. 8804 case ARM::t2LDR_PRE_imm: 8805 case ARM::t2LDR_POST_imm: { 8806 MCInst TmpInst; 8807 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2LDR_PRE_imm ? ARM::t2LDR_PRE 8808 : ARM::t2LDR_POST); 8809 TmpInst.addOperand(Inst.getOperand(0)); // Rt 8810 TmpInst.addOperand(Inst.getOperand(4)); // Rt_wb 8811 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8812 TmpInst.addOperand(Inst.getOperand(2)); // imm 8813 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 8814 Inst = TmpInst; 8815 return true; 8816 } 8817 // Aliases for imm syntax of STR instructions. 8818 case ARM::t2STR_PRE_imm: 8819 case ARM::t2STR_POST_imm: { 8820 MCInst TmpInst; 8821 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2STR_PRE_imm ? ARM::t2STR_PRE 8822 : ARM::t2STR_POST); 8823 TmpInst.addOperand(Inst.getOperand(4)); // Rt_wb 8824 TmpInst.addOperand(Inst.getOperand(0)); // Rt 8825 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8826 TmpInst.addOperand(Inst.getOperand(2)); // imm 8827 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 8828 Inst = TmpInst; 8829 return true; 8830 } 8831 // Aliases for alternate PC+imm syntax of LDR instructions. 8832 case ARM::t2LDRpcrel: 8833 // Select the narrow version if the immediate will fit. 8834 if (Inst.getOperand(1).getImm() > 0 && 8835 Inst.getOperand(1).getImm() <= 0xff && 8836 !HasWideQualifier) 8837 Inst.setOpcode(ARM::tLDRpci); 8838 else 8839 Inst.setOpcode(ARM::t2LDRpci); 8840 return true; 8841 case ARM::t2LDRBpcrel: 8842 Inst.setOpcode(ARM::t2LDRBpci); 8843 return true; 8844 case ARM::t2LDRHpcrel: 8845 Inst.setOpcode(ARM::t2LDRHpci); 8846 return true; 8847 case ARM::t2LDRSBpcrel: 8848 Inst.setOpcode(ARM::t2LDRSBpci); 8849 return true; 8850 case ARM::t2LDRSHpcrel: 8851 Inst.setOpcode(ARM::t2LDRSHpci); 8852 return true; 8853 case ARM::LDRConstPool: 8854 case ARM::tLDRConstPool: 8855 case ARM::t2LDRConstPool: { 8856 // Pseudo instruction ldr rt, =immediate is converted to a 8857 // MOV rt, immediate if immediate is known and representable 8858 // otherwise we create a constant pool entry that we load from. 8859 MCInst TmpInst; 8860 if (Inst.getOpcode() == ARM::LDRConstPool) 8861 TmpInst.setOpcode(ARM::LDRi12); 8862 else if (Inst.getOpcode() == ARM::tLDRConstPool) 8863 TmpInst.setOpcode(ARM::tLDRpci); 8864 else if (Inst.getOpcode() == ARM::t2LDRConstPool) 8865 TmpInst.setOpcode(ARM::t2LDRpci); 8866 const ARMOperand &PoolOperand = 8867 (HasWideQualifier ? 8868 static_cast<ARMOperand &>(*Operands[4]) : 8869 static_cast<ARMOperand &>(*Operands[3])); 8870 const MCExpr *SubExprVal = PoolOperand.getConstantPoolImm(); 8871 // If SubExprVal is a constant we may be able to use a MOV 8872 if (isa<MCConstantExpr>(SubExprVal) && 8873 Inst.getOperand(0).getReg() != ARM::PC && 8874 Inst.getOperand(0).getReg() != ARM::SP) { 8875 int64_t Value = 8876 (int64_t) (cast<MCConstantExpr>(SubExprVal))->getValue(); 8877 bool UseMov = true; 8878 bool MovHasS = true; 8879 if (Inst.getOpcode() == ARM::LDRConstPool) { 8880 // ARM Constant 8881 if (ARM_AM::getSOImmVal(Value) != -1) { 8882 Value = ARM_AM::getSOImmVal(Value); 8883 TmpInst.setOpcode(ARM::MOVi); 8884 } 8885 else if (ARM_AM::getSOImmVal(~Value) != -1) { 8886 Value = ARM_AM::getSOImmVal(~Value); 8887 TmpInst.setOpcode(ARM::MVNi); 8888 } 8889 else if (hasV6T2Ops() && 8890 Value >=0 && Value < 65536) { 8891 TmpInst.setOpcode(ARM::MOVi16); 8892 MovHasS = false; 8893 } 8894 else 8895 UseMov = false; 8896 } 8897 else { 8898 // Thumb/Thumb2 Constant 8899 if (hasThumb2() && 8900 ARM_AM::getT2SOImmVal(Value) != -1) 8901 TmpInst.setOpcode(ARM::t2MOVi); 8902 else if (hasThumb2() && 8903 ARM_AM::getT2SOImmVal(~Value) != -1) { 8904 TmpInst.setOpcode(ARM::t2MVNi); 8905 Value = ~Value; 8906 } 8907 else if (hasV8MBaseline() && 8908 Value >=0 && Value < 65536) { 8909 TmpInst.setOpcode(ARM::t2MOVi16); 8910 MovHasS = false; 8911 } 8912 else 8913 UseMov = false; 8914 } 8915 if (UseMov) { 8916 TmpInst.addOperand(Inst.getOperand(0)); // Rt 8917 TmpInst.addOperand(MCOperand::createImm(Value)); // Immediate 8918 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 8919 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 8920 if (MovHasS) 8921 TmpInst.addOperand(MCOperand::createReg(0)); // S 8922 Inst = TmpInst; 8923 return true; 8924 } 8925 } 8926 // No opportunity to use MOV/MVN create constant pool 8927 const MCExpr *CPLoc = 8928 getTargetStreamer().addConstantPoolEntry(SubExprVal, 8929 PoolOperand.getStartLoc()); 8930 TmpInst.addOperand(Inst.getOperand(0)); // Rt 8931 TmpInst.addOperand(MCOperand::createExpr(CPLoc)); // offset to constpool 8932 if (TmpInst.getOpcode() == ARM::LDRi12) 8933 TmpInst.addOperand(MCOperand::createImm(0)); // unused offset 8934 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 8935 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 8936 Inst = TmpInst; 8937 return true; 8938 } 8939 // Handle NEON VST complex aliases. 8940 case ARM::VST1LNdWB_register_Asm_8: 8941 case ARM::VST1LNdWB_register_Asm_16: 8942 case ARM::VST1LNdWB_register_Asm_32: { 8943 MCInst TmpInst; 8944 // Shuffle the operands around so the lane index operand is in the 8945 // right place. 8946 unsigned Spacing; 8947 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 8948 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 8949 TmpInst.addOperand(Inst.getOperand(2)); // Rn 8950 TmpInst.addOperand(Inst.getOperand(3)); // alignment 8951 TmpInst.addOperand(Inst.getOperand(4)); // Rm 8952 TmpInst.addOperand(Inst.getOperand(0)); // Vd 8953 TmpInst.addOperand(Inst.getOperand(1)); // lane 8954 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 8955 TmpInst.addOperand(Inst.getOperand(6)); 8956 Inst = TmpInst; 8957 return true; 8958 } 8959 8960 case ARM::VST2LNdWB_register_Asm_8: 8961 case ARM::VST2LNdWB_register_Asm_16: 8962 case ARM::VST2LNdWB_register_Asm_32: 8963 case ARM::VST2LNqWB_register_Asm_16: 8964 case ARM::VST2LNqWB_register_Asm_32: { 8965 MCInst TmpInst; 8966 // Shuffle the operands around so the lane index operand is in the 8967 // right place. 8968 unsigned Spacing; 8969 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 8970 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 8971 TmpInst.addOperand(Inst.getOperand(2)); // Rn 8972 TmpInst.addOperand(Inst.getOperand(3)); // alignment 8973 TmpInst.addOperand(Inst.getOperand(4)); // Rm 8974 TmpInst.addOperand(Inst.getOperand(0)); // Vd 8975 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 8976 Spacing)); 8977 TmpInst.addOperand(Inst.getOperand(1)); // lane 8978 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 8979 TmpInst.addOperand(Inst.getOperand(6)); 8980 Inst = TmpInst; 8981 return true; 8982 } 8983 8984 case ARM::VST3LNdWB_register_Asm_8: 8985 case ARM::VST3LNdWB_register_Asm_16: 8986 case ARM::VST3LNdWB_register_Asm_32: 8987 case ARM::VST3LNqWB_register_Asm_16: 8988 case ARM::VST3LNqWB_register_Asm_32: { 8989 MCInst TmpInst; 8990 // Shuffle the operands around so the lane index operand is in the 8991 // right place. 8992 unsigned Spacing; 8993 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 8994 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 8995 TmpInst.addOperand(Inst.getOperand(2)); // Rn 8996 TmpInst.addOperand(Inst.getOperand(3)); // alignment 8997 TmpInst.addOperand(Inst.getOperand(4)); // Rm 8998 TmpInst.addOperand(Inst.getOperand(0)); // Vd 8999 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9000 Spacing)); 9001 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9002 Spacing * 2)); 9003 TmpInst.addOperand(Inst.getOperand(1)); // lane 9004 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 9005 TmpInst.addOperand(Inst.getOperand(6)); 9006 Inst = TmpInst; 9007 return true; 9008 } 9009 9010 case ARM::VST4LNdWB_register_Asm_8: 9011 case ARM::VST4LNdWB_register_Asm_16: 9012 case ARM::VST4LNdWB_register_Asm_32: 9013 case ARM::VST4LNqWB_register_Asm_16: 9014 case ARM::VST4LNqWB_register_Asm_32: { 9015 MCInst TmpInst; 9016 // Shuffle the operands around so the lane index operand is in the 9017 // right place. 9018 unsigned Spacing; 9019 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9020 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9021 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9022 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9023 TmpInst.addOperand(Inst.getOperand(4)); // Rm 9024 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9025 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9026 Spacing)); 9027 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9028 Spacing * 2)); 9029 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9030 Spacing * 3)); 9031 TmpInst.addOperand(Inst.getOperand(1)); // lane 9032 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 9033 TmpInst.addOperand(Inst.getOperand(6)); 9034 Inst = TmpInst; 9035 return true; 9036 } 9037 9038 case ARM::VST1LNdWB_fixed_Asm_8: 9039 case ARM::VST1LNdWB_fixed_Asm_16: 9040 case ARM::VST1LNdWB_fixed_Asm_32: { 9041 MCInst TmpInst; 9042 // Shuffle the operands around so the lane index operand is in the 9043 // right place. 9044 unsigned Spacing; 9045 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9046 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9047 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9048 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9049 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9050 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9051 TmpInst.addOperand(Inst.getOperand(1)); // lane 9052 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9053 TmpInst.addOperand(Inst.getOperand(5)); 9054 Inst = TmpInst; 9055 return true; 9056 } 9057 9058 case ARM::VST2LNdWB_fixed_Asm_8: 9059 case ARM::VST2LNdWB_fixed_Asm_16: 9060 case ARM::VST2LNdWB_fixed_Asm_32: 9061 case ARM::VST2LNqWB_fixed_Asm_16: 9062 case ARM::VST2LNqWB_fixed_Asm_32: { 9063 MCInst TmpInst; 9064 // Shuffle the operands around so the lane index operand is in the 9065 // right place. 9066 unsigned Spacing; 9067 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9068 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9069 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9070 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9071 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9072 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9073 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9074 Spacing)); 9075 TmpInst.addOperand(Inst.getOperand(1)); // lane 9076 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9077 TmpInst.addOperand(Inst.getOperand(5)); 9078 Inst = TmpInst; 9079 return true; 9080 } 9081 9082 case ARM::VST3LNdWB_fixed_Asm_8: 9083 case ARM::VST3LNdWB_fixed_Asm_16: 9084 case ARM::VST3LNdWB_fixed_Asm_32: 9085 case ARM::VST3LNqWB_fixed_Asm_16: 9086 case ARM::VST3LNqWB_fixed_Asm_32: { 9087 MCInst TmpInst; 9088 // Shuffle the operands around so the lane index operand is in the 9089 // right place. 9090 unsigned Spacing; 9091 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9092 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9093 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9094 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9095 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9096 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9097 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9098 Spacing)); 9099 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9100 Spacing * 2)); 9101 TmpInst.addOperand(Inst.getOperand(1)); // lane 9102 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9103 TmpInst.addOperand(Inst.getOperand(5)); 9104 Inst = TmpInst; 9105 return true; 9106 } 9107 9108 case ARM::VST4LNdWB_fixed_Asm_8: 9109 case ARM::VST4LNdWB_fixed_Asm_16: 9110 case ARM::VST4LNdWB_fixed_Asm_32: 9111 case ARM::VST4LNqWB_fixed_Asm_16: 9112 case ARM::VST4LNqWB_fixed_Asm_32: { 9113 MCInst TmpInst; 9114 // Shuffle the operands around so the lane index operand is in the 9115 // right place. 9116 unsigned Spacing; 9117 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9118 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9119 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9120 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9121 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9122 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9123 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9124 Spacing)); 9125 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9126 Spacing * 2)); 9127 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9128 Spacing * 3)); 9129 TmpInst.addOperand(Inst.getOperand(1)); // lane 9130 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9131 TmpInst.addOperand(Inst.getOperand(5)); 9132 Inst = TmpInst; 9133 return true; 9134 } 9135 9136 case ARM::VST1LNdAsm_8: 9137 case ARM::VST1LNdAsm_16: 9138 case ARM::VST1LNdAsm_32: { 9139 MCInst TmpInst; 9140 // Shuffle the operands around so the lane index operand is in the 9141 // right place. 9142 unsigned Spacing; 9143 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9144 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9145 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9146 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9147 TmpInst.addOperand(Inst.getOperand(1)); // lane 9148 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9149 TmpInst.addOperand(Inst.getOperand(5)); 9150 Inst = TmpInst; 9151 return true; 9152 } 9153 9154 case ARM::VST2LNdAsm_8: 9155 case ARM::VST2LNdAsm_16: 9156 case ARM::VST2LNdAsm_32: 9157 case ARM::VST2LNqAsm_16: 9158 case ARM::VST2LNqAsm_32: { 9159 MCInst TmpInst; 9160 // Shuffle the operands around so the lane index operand is in the 9161 // right place. 9162 unsigned Spacing; 9163 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9164 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9165 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9166 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9167 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9168 Spacing)); 9169 TmpInst.addOperand(Inst.getOperand(1)); // lane 9170 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9171 TmpInst.addOperand(Inst.getOperand(5)); 9172 Inst = TmpInst; 9173 return true; 9174 } 9175 9176 case ARM::VST3LNdAsm_8: 9177 case ARM::VST3LNdAsm_16: 9178 case ARM::VST3LNdAsm_32: 9179 case ARM::VST3LNqAsm_16: 9180 case ARM::VST3LNqAsm_32: { 9181 MCInst TmpInst; 9182 // Shuffle the operands around so the lane index operand is in the 9183 // right place. 9184 unsigned Spacing; 9185 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9186 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9187 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9188 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9189 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9190 Spacing)); 9191 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9192 Spacing * 2)); 9193 TmpInst.addOperand(Inst.getOperand(1)); // lane 9194 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9195 TmpInst.addOperand(Inst.getOperand(5)); 9196 Inst = TmpInst; 9197 return true; 9198 } 9199 9200 case ARM::VST4LNdAsm_8: 9201 case ARM::VST4LNdAsm_16: 9202 case ARM::VST4LNdAsm_32: 9203 case ARM::VST4LNqAsm_16: 9204 case ARM::VST4LNqAsm_32: { 9205 MCInst TmpInst; 9206 // Shuffle the operands around so the lane index operand is in the 9207 // right place. 9208 unsigned Spacing; 9209 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9210 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9211 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9212 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9213 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9214 Spacing)); 9215 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9216 Spacing * 2)); 9217 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9218 Spacing * 3)); 9219 TmpInst.addOperand(Inst.getOperand(1)); // lane 9220 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9221 TmpInst.addOperand(Inst.getOperand(5)); 9222 Inst = TmpInst; 9223 return true; 9224 } 9225 9226 // Handle NEON VLD complex aliases. 9227 case ARM::VLD1LNdWB_register_Asm_8: 9228 case ARM::VLD1LNdWB_register_Asm_16: 9229 case ARM::VLD1LNdWB_register_Asm_32: { 9230 MCInst TmpInst; 9231 // Shuffle the operands around so the lane index operand is in the 9232 // right place. 9233 unsigned Spacing; 9234 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9235 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9236 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9237 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9238 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9239 TmpInst.addOperand(Inst.getOperand(4)); // Rm 9240 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9241 TmpInst.addOperand(Inst.getOperand(1)); // lane 9242 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 9243 TmpInst.addOperand(Inst.getOperand(6)); 9244 Inst = TmpInst; 9245 return true; 9246 } 9247 9248 case ARM::VLD2LNdWB_register_Asm_8: 9249 case ARM::VLD2LNdWB_register_Asm_16: 9250 case ARM::VLD2LNdWB_register_Asm_32: 9251 case ARM::VLD2LNqWB_register_Asm_16: 9252 case ARM::VLD2LNqWB_register_Asm_32: { 9253 MCInst TmpInst; 9254 // Shuffle the operands around so the lane index operand is in the 9255 // right place. 9256 unsigned Spacing; 9257 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9258 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9259 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9260 Spacing)); 9261 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9262 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9263 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9264 TmpInst.addOperand(Inst.getOperand(4)); // Rm 9265 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9266 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9267 Spacing)); 9268 TmpInst.addOperand(Inst.getOperand(1)); // lane 9269 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 9270 TmpInst.addOperand(Inst.getOperand(6)); 9271 Inst = TmpInst; 9272 return true; 9273 } 9274 9275 case ARM::VLD3LNdWB_register_Asm_8: 9276 case ARM::VLD3LNdWB_register_Asm_16: 9277 case ARM::VLD3LNdWB_register_Asm_32: 9278 case ARM::VLD3LNqWB_register_Asm_16: 9279 case ARM::VLD3LNqWB_register_Asm_32: { 9280 MCInst TmpInst; 9281 // Shuffle the operands around so the lane index operand is in the 9282 // right place. 9283 unsigned Spacing; 9284 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9285 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9286 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9287 Spacing)); 9288 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9289 Spacing * 2)); 9290 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9291 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9292 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9293 TmpInst.addOperand(Inst.getOperand(4)); // Rm 9294 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9295 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9296 Spacing)); 9297 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9298 Spacing * 2)); 9299 TmpInst.addOperand(Inst.getOperand(1)); // lane 9300 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 9301 TmpInst.addOperand(Inst.getOperand(6)); 9302 Inst = TmpInst; 9303 return true; 9304 } 9305 9306 case ARM::VLD4LNdWB_register_Asm_8: 9307 case ARM::VLD4LNdWB_register_Asm_16: 9308 case ARM::VLD4LNdWB_register_Asm_32: 9309 case ARM::VLD4LNqWB_register_Asm_16: 9310 case ARM::VLD4LNqWB_register_Asm_32: { 9311 MCInst TmpInst; 9312 // Shuffle the operands around so the lane index operand is in the 9313 // right place. 9314 unsigned Spacing; 9315 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9316 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9317 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9318 Spacing)); 9319 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9320 Spacing * 2)); 9321 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9322 Spacing * 3)); 9323 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9324 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9325 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9326 TmpInst.addOperand(Inst.getOperand(4)); // Rm 9327 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9328 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9329 Spacing)); 9330 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9331 Spacing * 2)); 9332 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9333 Spacing * 3)); 9334 TmpInst.addOperand(Inst.getOperand(1)); // lane 9335 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 9336 TmpInst.addOperand(Inst.getOperand(6)); 9337 Inst = TmpInst; 9338 return true; 9339 } 9340 9341 case ARM::VLD1LNdWB_fixed_Asm_8: 9342 case ARM::VLD1LNdWB_fixed_Asm_16: 9343 case ARM::VLD1LNdWB_fixed_Asm_32: { 9344 MCInst TmpInst; 9345 // Shuffle the operands around so the lane index operand is in the 9346 // right place. 9347 unsigned Spacing; 9348 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9349 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9350 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9351 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9352 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9353 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9354 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9355 TmpInst.addOperand(Inst.getOperand(1)); // lane 9356 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9357 TmpInst.addOperand(Inst.getOperand(5)); 9358 Inst = TmpInst; 9359 return true; 9360 } 9361 9362 case ARM::VLD2LNdWB_fixed_Asm_8: 9363 case ARM::VLD2LNdWB_fixed_Asm_16: 9364 case ARM::VLD2LNdWB_fixed_Asm_32: 9365 case ARM::VLD2LNqWB_fixed_Asm_16: 9366 case ARM::VLD2LNqWB_fixed_Asm_32: { 9367 MCInst TmpInst; 9368 // Shuffle the operands around so the lane index operand is in the 9369 // right place. 9370 unsigned Spacing; 9371 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9372 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9373 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9374 Spacing)); 9375 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9376 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9377 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9378 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9379 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9380 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9381 Spacing)); 9382 TmpInst.addOperand(Inst.getOperand(1)); // lane 9383 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9384 TmpInst.addOperand(Inst.getOperand(5)); 9385 Inst = TmpInst; 9386 return true; 9387 } 9388 9389 case ARM::VLD3LNdWB_fixed_Asm_8: 9390 case ARM::VLD3LNdWB_fixed_Asm_16: 9391 case ARM::VLD3LNdWB_fixed_Asm_32: 9392 case ARM::VLD3LNqWB_fixed_Asm_16: 9393 case ARM::VLD3LNqWB_fixed_Asm_32: { 9394 MCInst TmpInst; 9395 // Shuffle the operands around so the lane index operand is in the 9396 // right place. 9397 unsigned Spacing; 9398 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9399 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9400 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9401 Spacing)); 9402 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9403 Spacing * 2)); 9404 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9405 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9406 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9407 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9408 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9409 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9410 Spacing)); 9411 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9412 Spacing * 2)); 9413 TmpInst.addOperand(Inst.getOperand(1)); // lane 9414 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9415 TmpInst.addOperand(Inst.getOperand(5)); 9416 Inst = TmpInst; 9417 return true; 9418 } 9419 9420 case ARM::VLD4LNdWB_fixed_Asm_8: 9421 case ARM::VLD4LNdWB_fixed_Asm_16: 9422 case ARM::VLD4LNdWB_fixed_Asm_32: 9423 case ARM::VLD4LNqWB_fixed_Asm_16: 9424 case ARM::VLD4LNqWB_fixed_Asm_32: { 9425 MCInst TmpInst; 9426 // Shuffle the operands around so the lane index operand is in the 9427 // right place. 9428 unsigned Spacing; 9429 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9430 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9431 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9432 Spacing)); 9433 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9434 Spacing * 2)); 9435 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9436 Spacing * 3)); 9437 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 9438 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9439 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9440 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9441 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9442 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9443 Spacing)); 9444 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9445 Spacing * 2)); 9446 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9447 Spacing * 3)); 9448 TmpInst.addOperand(Inst.getOperand(1)); // lane 9449 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9450 TmpInst.addOperand(Inst.getOperand(5)); 9451 Inst = TmpInst; 9452 return true; 9453 } 9454 9455 case ARM::VLD1LNdAsm_8: 9456 case ARM::VLD1LNdAsm_16: 9457 case ARM::VLD1LNdAsm_32: { 9458 MCInst TmpInst; 9459 // Shuffle the operands around so the lane index operand is in the 9460 // right place. 9461 unsigned Spacing; 9462 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9463 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9464 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9465 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9466 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9467 TmpInst.addOperand(Inst.getOperand(1)); // lane 9468 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9469 TmpInst.addOperand(Inst.getOperand(5)); 9470 Inst = TmpInst; 9471 return true; 9472 } 9473 9474 case ARM::VLD2LNdAsm_8: 9475 case ARM::VLD2LNdAsm_16: 9476 case ARM::VLD2LNdAsm_32: 9477 case ARM::VLD2LNqAsm_16: 9478 case ARM::VLD2LNqAsm_32: { 9479 MCInst TmpInst; 9480 // Shuffle the operands around so the lane index operand is in the 9481 // right place. 9482 unsigned Spacing; 9483 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9484 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9485 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9486 Spacing)); 9487 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9488 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9489 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9490 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9491 Spacing)); 9492 TmpInst.addOperand(Inst.getOperand(1)); // lane 9493 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9494 TmpInst.addOperand(Inst.getOperand(5)); 9495 Inst = TmpInst; 9496 return true; 9497 } 9498 9499 case ARM::VLD3LNdAsm_8: 9500 case ARM::VLD3LNdAsm_16: 9501 case ARM::VLD3LNdAsm_32: 9502 case ARM::VLD3LNqAsm_16: 9503 case ARM::VLD3LNqAsm_32: { 9504 MCInst TmpInst; 9505 // Shuffle the operands around so the lane index operand is in the 9506 // right place. 9507 unsigned Spacing; 9508 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9509 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9510 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9511 Spacing)); 9512 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9513 Spacing * 2)); 9514 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9515 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9516 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9517 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9518 Spacing)); 9519 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9520 Spacing * 2)); 9521 TmpInst.addOperand(Inst.getOperand(1)); // lane 9522 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9523 TmpInst.addOperand(Inst.getOperand(5)); 9524 Inst = TmpInst; 9525 return true; 9526 } 9527 9528 case ARM::VLD4LNdAsm_8: 9529 case ARM::VLD4LNdAsm_16: 9530 case ARM::VLD4LNdAsm_32: 9531 case ARM::VLD4LNqAsm_16: 9532 case ARM::VLD4LNqAsm_32: { 9533 MCInst TmpInst; 9534 // Shuffle the operands around so the lane index operand is in the 9535 // right place. 9536 unsigned Spacing; 9537 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9538 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9539 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9540 Spacing)); 9541 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9542 Spacing * 2)); 9543 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9544 Spacing * 3)); 9545 TmpInst.addOperand(Inst.getOperand(2)); // Rn 9546 TmpInst.addOperand(Inst.getOperand(3)); // alignment 9547 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 9548 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9549 Spacing)); 9550 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9551 Spacing * 2)); 9552 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9553 Spacing * 3)); 9554 TmpInst.addOperand(Inst.getOperand(1)); // lane 9555 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9556 TmpInst.addOperand(Inst.getOperand(5)); 9557 Inst = TmpInst; 9558 return true; 9559 } 9560 9561 // VLD3DUP single 3-element structure to all lanes instructions. 9562 case ARM::VLD3DUPdAsm_8: 9563 case ARM::VLD3DUPdAsm_16: 9564 case ARM::VLD3DUPdAsm_32: 9565 case ARM::VLD3DUPqAsm_8: 9566 case ARM::VLD3DUPqAsm_16: 9567 case ARM::VLD3DUPqAsm_32: { 9568 MCInst TmpInst; 9569 unsigned Spacing; 9570 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9571 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9572 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9573 Spacing)); 9574 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9575 Spacing * 2)); 9576 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9577 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9578 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9579 TmpInst.addOperand(Inst.getOperand(4)); 9580 Inst = TmpInst; 9581 return true; 9582 } 9583 9584 case ARM::VLD3DUPdWB_fixed_Asm_8: 9585 case ARM::VLD3DUPdWB_fixed_Asm_16: 9586 case ARM::VLD3DUPdWB_fixed_Asm_32: 9587 case ARM::VLD3DUPqWB_fixed_Asm_8: 9588 case ARM::VLD3DUPqWB_fixed_Asm_16: 9589 case ARM::VLD3DUPqWB_fixed_Asm_32: { 9590 MCInst TmpInst; 9591 unsigned Spacing; 9592 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9593 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9594 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9595 Spacing)); 9596 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9597 Spacing * 2)); 9598 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9599 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9600 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9601 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9602 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9603 TmpInst.addOperand(Inst.getOperand(4)); 9604 Inst = TmpInst; 9605 return true; 9606 } 9607 9608 case ARM::VLD3DUPdWB_register_Asm_8: 9609 case ARM::VLD3DUPdWB_register_Asm_16: 9610 case ARM::VLD3DUPdWB_register_Asm_32: 9611 case ARM::VLD3DUPqWB_register_Asm_8: 9612 case ARM::VLD3DUPqWB_register_Asm_16: 9613 case ARM::VLD3DUPqWB_register_Asm_32: { 9614 MCInst TmpInst; 9615 unsigned Spacing; 9616 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9617 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9618 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9619 Spacing)); 9620 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9621 Spacing * 2)); 9622 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9623 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9624 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9625 TmpInst.addOperand(Inst.getOperand(3)); // Rm 9626 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9627 TmpInst.addOperand(Inst.getOperand(5)); 9628 Inst = TmpInst; 9629 return true; 9630 } 9631 9632 // VLD3 multiple 3-element structure instructions. 9633 case ARM::VLD3dAsm_8: 9634 case ARM::VLD3dAsm_16: 9635 case ARM::VLD3dAsm_32: 9636 case ARM::VLD3qAsm_8: 9637 case ARM::VLD3qAsm_16: 9638 case ARM::VLD3qAsm_32: { 9639 MCInst TmpInst; 9640 unsigned Spacing; 9641 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9642 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9643 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9644 Spacing)); 9645 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9646 Spacing * 2)); 9647 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9648 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9649 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9650 TmpInst.addOperand(Inst.getOperand(4)); 9651 Inst = TmpInst; 9652 return true; 9653 } 9654 9655 case ARM::VLD3dWB_fixed_Asm_8: 9656 case ARM::VLD3dWB_fixed_Asm_16: 9657 case ARM::VLD3dWB_fixed_Asm_32: 9658 case ARM::VLD3qWB_fixed_Asm_8: 9659 case ARM::VLD3qWB_fixed_Asm_16: 9660 case ARM::VLD3qWB_fixed_Asm_32: { 9661 MCInst TmpInst; 9662 unsigned Spacing; 9663 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9664 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9665 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9666 Spacing)); 9667 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9668 Spacing * 2)); 9669 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9670 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9671 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9672 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9673 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9674 TmpInst.addOperand(Inst.getOperand(4)); 9675 Inst = TmpInst; 9676 return true; 9677 } 9678 9679 case ARM::VLD3dWB_register_Asm_8: 9680 case ARM::VLD3dWB_register_Asm_16: 9681 case ARM::VLD3dWB_register_Asm_32: 9682 case ARM::VLD3qWB_register_Asm_8: 9683 case ARM::VLD3qWB_register_Asm_16: 9684 case ARM::VLD3qWB_register_Asm_32: { 9685 MCInst TmpInst; 9686 unsigned Spacing; 9687 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9688 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9689 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9690 Spacing)); 9691 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9692 Spacing * 2)); 9693 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9694 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9695 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9696 TmpInst.addOperand(Inst.getOperand(3)); // Rm 9697 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9698 TmpInst.addOperand(Inst.getOperand(5)); 9699 Inst = TmpInst; 9700 return true; 9701 } 9702 9703 // VLD4DUP single 3-element structure to all lanes instructions. 9704 case ARM::VLD4DUPdAsm_8: 9705 case ARM::VLD4DUPdAsm_16: 9706 case ARM::VLD4DUPdAsm_32: 9707 case ARM::VLD4DUPqAsm_8: 9708 case ARM::VLD4DUPqAsm_16: 9709 case ARM::VLD4DUPqAsm_32: { 9710 MCInst TmpInst; 9711 unsigned Spacing; 9712 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9713 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9714 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9715 Spacing)); 9716 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9717 Spacing * 2)); 9718 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9719 Spacing * 3)); 9720 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9721 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9722 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9723 TmpInst.addOperand(Inst.getOperand(4)); 9724 Inst = TmpInst; 9725 return true; 9726 } 9727 9728 case ARM::VLD4DUPdWB_fixed_Asm_8: 9729 case ARM::VLD4DUPdWB_fixed_Asm_16: 9730 case ARM::VLD4DUPdWB_fixed_Asm_32: 9731 case ARM::VLD4DUPqWB_fixed_Asm_8: 9732 case ARM::VLD4DUPqWB_fixed_Asm_16: 9733 case ARM::VLD4DUPqWB_fixed_Asm_32: { 9734 MCInst TmpInst; 9735 unsigned Spacing; 9736 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9737 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9738 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9739 Spacing)); 9740 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9741 Spacing * 2)); 9742 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9743 Spacing * 3)); 9744 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9745 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9746 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9747 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9748 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9749 TmpInst.addOperand(Inst.getOperand(4)); 9750 Inst = TmpInst; 9751 return true; 9752 } 9753 9754 case ARM::VLD4DUPdWB_register_Asm_8: 9755 case ARM::VLD4DUPdWB_register_Asm_16: 9756 case ARM::VLD4DUPdWB_register_Asm_32: 9757 case ARM::VLD4DUPqWB_register_Asm_8: 9758 case ARM::VLD4DUPqWB_register_Asm_16: 9759 case ARM::VLD4DUPqWB_register_Asm_32: { 9760 MCInst TmpInst; 9761 unsigned Spacing; 9762 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9763 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9764 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9765 Spacing)); 9766 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9767 Spacing * 2)); 9768 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9769 Spacing * 3)); 9770 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9771 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9772 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9773 TmpInst.addOperand(Inst.getOperand(3)); // Rm 9774 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9775 TmpInst.addOperand(Inst.getOperand(5)); 9776 Inst = TmpInst; 9777 return true; 9778 } 9779 9780 // VLD4 multiple 4-element structure instructions. 9781 case ARM::VLD4dAsm_8: 9782 case ARM::VLD4dAsm_16: 9783 case ARM::VLD4dAsm_32: 9784 case ARM::VLD4qAsm_8: 9785 case ARM::VLD4qAsm_16: 9786 case ARM::VLD4qAsm_32: { 9787 MCInst TmpInst; 9788 unsigned Spacing; 9789 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9790 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9791 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9792 Spacing)); 9793 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9794 Spacing * 2)); 9795 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9796 Spacing * 3)); 9797 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9798 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9799 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9800 TmpInst.addOperand(Inst.getOperand(4)); 9801 Inst = TmpInst; 9802 return true; 9803 } 9804 9805 case ARM::VLD4dWB_fixed_Asm_8: 9806 case ARM::VLD4dWB_fixed_Asm_16: 9807 case ARM::VLD4dWB_fixed_Asm_32: 9808 case ARM::VLD4qWB_fixed_Asm_8: 9809 case ARM::VLD4qWB_fixed_Asm_16: 9810 case ARM::VLD4qWB_fixed_Asm_32: { 9811 MCInst TmpInst; 9812 unsigned Spacing; 9813 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9814 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9815 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9816 Spacing)); 9817 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9818 Spacing * 2)); 9819 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9820 Spacing * 3)); 9821 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9822 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9823 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9824 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9825 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9826 TmpInst.addOperand(Inst.getOperand(4)); 9827 Inst = TmpInst; 9828 return true; 9829 } 9830 9831 case ARM::VLD4dWB_register_Asm_8: 9832 case ARM::VLD4dWB_register_Asm_16: 9833 case ARM::VLD4dWB_register_Asm_32: 9834 case ARM::VLD4qWB_register_Asm_8: 9835 case ARM::VLD4qWB_register_Asm_16: 9836 case ARM::VLD4qWB_register_Asm_32: { 9837 MCInst TmpInst; 9838 unsigned Spacing; 9839 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 9840 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9841 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9842 Spacing)); 9843 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9844 Spacing * 2)); 9845 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9846 Spacing * 3)); 9847 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9848 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9849 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9850 TmpInst.addOperand(Inst.getOperand(3)); // Rm 9851 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9852 TmpInst.addOperand(Inst.getOperand(5)); 9853 Inst = TmpInst; 9854 return true; 9855 } 9856 9857 // VST3 multiple 3-element structure instructions. 9858 case ARM::VST3dAsm_8: 9859 case ARM::VST3dAsm_16: 9860 case ARM::VST3dAsm_32: 9861 case ARM::VST3qAsm_8: 9862 case ARM::VST3qAsm_16: 9863 case ARM::VST3qAsm_32: { 9864 MCInst TmpInst; 9865 unsigned Spacing; 9866 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9867 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9868 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9869 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9870 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9871 Spacing)); 9872 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9873 Spacing * 2)); 9874 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9875 TmpInst.addOperand(Inst.getOperand(4)); 9876 Inst = TmpInst; 9877 return true; 9878 } 9879 9880 case ARM::VST3dWB_fixed_Asm_8: 9881 case ARM::VST3dWB_fixed_Asm_16: 9882 case ARM::VST3dWB_fixed_Asm_32: 9883 case ARM::VST3qWB_fixed_Asm_8: 9884 case ARM::VST3qWB_fixed_Asm_16: 9885 case ARM::VST3qWB_fixed_Asm_32: { 9886 MCInst TmpInst; 9887 unsigned Spacing; 9888 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9889 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9890 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9891 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9892 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9893 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9894 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9895 Spacing)); 9896 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9897 Spacing * 2)); 9898 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9899 TmpInst.addOperand(Inst.getOperand(4)); 9900 Inst = TmpInst; 9901 return true; 9902 } 9903 9904 case ARM::VST3dWB_register_Asm_8: 9905 case ARM::VST3dWB_register_Asm_16: 9906 case ARM::VST3dWB_register_Asm_32: 9907 case ARM::VST3qWB_register_Asm_8: 9908 case ARM::VST3qWB_register_Asm_16: 9909 case ARM::VST3qWB_register_Asm_32: { 9910 MCInst TmpInst; 9911 unsigned Spacing; 9912 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9913 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9914 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9915 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9916 TmpInst.addOperand(Inst.getOperand(3)); // Rm 9917 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9918 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9919 Spacing)); 9920 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9921 Spacing * 2)); 9922 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 9923 TmpInst.addOperand(Inst.getOperand(5)); 9924 Inst = TmpInst; 9925 return true; 9926 } 9927 9928 // VST4 multiple 3-element structure instructions. 9929 case ARM::VST4dAsm_8: 9930 case ARM::VST4dAsm_16: 9931 case ARM::VST4dAsm_32: 9932 case ARM::VST4qAsm_8: 9933 case ARM::VST4qAsm_16: 9934 case ARM::VST4qAsm_32: { 9935 MCInst TmpInst; 9936 unsigned Spacing; 9937 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9938 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9939 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9940 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9941 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9942 Spacing)); 9943 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9944 Spacing * 2)); 9945 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9946 Spacing * 3)); 9947 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9948 TmpInst.addOperand(Inst.getOperand(4)); 9949 Inst = TmpInst; 9950 return true; 9951 } 9952 9953 case ARM::VST4dWB_fixed_Asm_8: 9954 case ARM::VST4dWB_fixed_Asm_16: 9955 case ARM::VST4dWB_fixed_Asm_32: 9956 case ARM::VST4qWB_fixed_Asm_8: 9957 case ARM::VST4qWB_fixed_Asm_16: 9958 case ARM::VST4qWB_fixed_Asm_32: { 9959 MCInst TmpInst; 9960 unsigned Spacing; 9961 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9962 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9963 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9964 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9965 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 9966 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9967 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9968 Spacing)); 9969 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9970 Spacing * 2)); 9971 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9972 Spacing * 3)); 9973 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 9974 TmpInst.addOperand(Inst.getOperand(4)); 9975 Inst = TmpInst; 9976 return true; 9977 } 9978 9979 case ARM::VST4dWB_register_Asm_8: 9980 case ARM::VST4dWB_register_Asm_16: 9981 case ARM::VST4dWB_register_Asm_32: 9982 case ARM::VST4qWB_register_Asm_8: 9983 case ARM::VST4qWB_register_Asm_16: 9984 case ARM::VST4qWB_register_Asm_32: { 9985 MCInst TmpInst; 9986 unsigned Spacing; 9987 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 9988 TmpInst.addOperand(Inst.getOperand(1)); // Rn 9989 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 9990 TmpInst.addOperand(Inst.getOperand(2)); // alignment 9991 TmpInst.addOperand(Inst.getOperand(3)); // Rm 9992 TmpInst.addOperand(Inst.getOperand(0)); // Vd 9993 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9994 Spacing)); 9995 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9996 Spacing * 2)); 9997 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 9998 Spacing * 3)); 9999 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 10000 TmpInst.addOperand(Inst.getOperand(5)); 10001 Inst = TmpInst; 10002 return true; 10003 } 10004 10005 // Handle encoding choice for the shift-immediate instructions. 10006 case ARM::t2LSLri: 10007 case ARM::t2LSRri: 10008 case ARM::t2ASRri: 10009 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 10010 isARMLowRegister(Inst.getOperand(1).getReg()) && 10011 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) && 10012 !HasWideQualifier) { 10013 unsigned NewOpc; 10014 switch (Inst.getOpcode()) { 10015 default: llvm_unreachable("unexpected opcode"); 10016 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break; 10017 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break; 10018 case ARM::t2ASRri: NewOpc = ARM::tASRri; break; 10019 } 10020 // The Thumb1 operands aren't in the same order. Awesome, eh? 10021 MCInst TmpInst; 10022 TmpInst.setOpcode(NewOpc); 10023 TmpInst.addOperand(Inst.getOperand(0)); 10024 TmpInst.addOperand(Inst.getOperand(5)); 10025 TmpInst.addOperand(Inst.getOperand(1)); 10026 TmpInst.addOperand(Inst.getOperand(2)); 10027 TmpInst.addOperand(Inst.getOperand(3)); 10028 TmpInst.addOperand(Inst.getOperand(4)); 10029 Inst = TmpInst; 10030 return true; 10031 } 10032 return false; 10033 10034 // Handle the Thumb2 mode MOV complex aliases. 10035 case ARM::t2MOVsr: 10036 case ARM::t2MOVSsr: { 10037 // Which instruction to expand to depends on the CCOut operand and 10038 // whether we're in an IT block if the register operands are low 10039 // registers. 10040 bool isNarrow = false; 10041 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 10042 isARMLowRegister(Inst.getOperand(1).getReg()) && 10043 isARMLowRegister(Inst.getOperand(2).getReg()) && 10044 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && 10045 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr) && 10046 !HasWideQualifier) 10047 isNarrow = true; 10048 MCInst TmpInst; 10049 unsigned newOpc; 10050 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) { 10051 default: llvm_unreachable("unexpected opcode!"); 10052 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break; 10053 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break; 10054 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break; 10055 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break; 10056 } 10057 TmpInst.setOpcode(newOpc); 10058 TmpInst.addOperand(Inst.getOperand(0)); // Rd 10059 if (isNarrow) 10060 TmpInst.addOperand(MCOperand::createReg( 10061 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); 10062 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10063 TmpInst.addOperand(Inst.getOperand(2)); // Rm 10064 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 10065 TmpInst.addOperand(Inst.getOperand(5)); 10066 if (!isNarrow) 10067 TmpInst.addOperand(MCOperand::createReg( 10068 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); 10069 Inst = TmpInst; 10070 return true; 10071 } 10072 case ARM::t2MOVsi: 10073 case ARM::t2MOVSsi: { 10074 // Which instruction to expand to depends on the CCOut operand and 10075 // whether we're in an IT block if the register operands are low 10076 // registers. 10077 bool isNarrow = false; 10078 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 10079 isARMLowRegister(Inst.getOperand(1).getReg()) && 10080 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi) && 10081 !HasWideQualifier) 10082 isNarrow = true; 10083 MCInst TmpInst; 10084 unsigned newOpc; 10085 unsigned Shift = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm()); 10086 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()); 10087 bool isMov = false; 10088 // MOV rd, rm, LSL #0 is actually a MOV instruction 10089 if (Shift == ARM_AM::lsl && Amount == 0) { 10090 isMov = true; 10091 // The 16-bit encoding of MOV rd, rm, LSL #N is explicitly encoding T2 of 10092 // MOV (register) in the ARMv8-A and ARMv8-M manuals, and immediate 0 is 10093 // unpredictable in an IT block so the 32-bit encoding T3 has to be used 10094 // instead. 10095 if (inITBlock()) { 10096 isNarrow = false; 10097 } 10098 newOpc = isNarrow ? ARM::tMOVSr : ARM::t2MOVr; 10099 } else { 10100 switch(Shift) { 10101 default: llvm_unreachable("unexpected opcode!"); 10102 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break; 10103 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break; 10104 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break; 10105 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break; 10106 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break; 10107 } 10108 } 10109 if (Amount == 32) Amount = 0; 10110 TmpInst.setOpcode(newOpc); 10111 TmpInst.addOperand(Inst.getOperand(0)); // Rd 10112 if (isNarrow && !isMov) 10113 TmpInst.addOperand(MCOperand::createReg( 10114 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); 10115 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10116 if (newOpc != ARM::t2RRX && !isMov) 10117 TmpInst.addOperand(MCOperand::createImm(Amount)); 10118 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 10119 TmpInst.addOperand(Inst.getOperand(4)); 10120 if (!isNarrow) 10121 TmpInst.addOperand(MCOperand::createReg( 10122 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); 10123 Inst = TmpInst; 10124 return true; 10125 } 10126 // Handle the ARM mode MOV complex aliases. 10127 case ARM::ASRr: 10128 case ARM::LSRr: 10129 case ARM::LSLr: 10130 case ARM::RORr: { 10131 ARM_AM::ShiftOpc ShiftTy; 10132 switch(Inst.getOpcode()) { 10133 default: llvm_unreachable("unexpected opcode!"); 10134 case ARM::ASRr: ShiftTy = ARM_AM::asr; break; 10135 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break; 10136 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break; 10137 case ARM::RORr: ShiftTy = ARM_AM::ror; break; 10138 } 10139 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0); 10140 MCInst TmpInst; 10141 TmpInst.setOpcode(ARM::MOVsr); 10142 TmpInst.addOperand(Inst.getOperand(0)); // Rd 10143 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10144 TmpInst.addOperand(Inst.getOperand(2)); // Rm 10145 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty 10146 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 10147 TmpInst.addOperand(Inst.getOperand(4)); 10148 TmpInst.addOperand(Inst.getOperand(5)); // cc_out 10149 Inst = TmpInst; 10150 return true; 10151 } 10152 case ARM::ASRi: 10153 case ARM::LSRi: 10154 case ARM::LSLi: 10155 case ARM::RORi: { 10156 ARM_AM::ShiftOpc ShiftTy; 10157 switch(Inst.getOpcode()) { 10158 default: llvm_unreachable("unexpected opcode!"); 10159 case ARM::ASRi: ShiftTy = ARM_AM::asr; break; 10160 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break; 10161 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break; 10162 case ARM::RORi: ShiftTy = ARM_AM::ror; break; 10163 } 10164 // A shift by zero is a plain MOVr, not a MOVsi. 10165 unsigned Amt = Inst.getOperand(2).getImm(); 10166 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi; 10167 // A shift by 32 should be encoded as 0 when permitted 10168 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr)) 10169 Amt = 0; 10170 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt); 10171 MCInst TmpInst; 10172 TmpInst.setOpcode(Opc); 10173 TmpInst.addOperand(Inst.getOperand(0)); // Rd 10174 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10175 if (Opc == ARM::MOVsi) 10176 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty 10177 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 10178 TmpInst.addOperand(Inst.getOperand(4)); 10179 TmpInst.addOperand(Inst.getOperand(5)); // cc_out 10180 Inst = TmpInst; 10181 return true; 10182 } 10183 case ARM::RRXi: { 10184 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0); 10185 MCInst TmpInst; 10186 TmpInst.setOpcode(ARM::MOVsi); 10187 TmpInst.addOperand(Inst.getOperand(0)); // Rd 10188 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10189 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty 10190 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 10191 TmpInst.addOperand(Inst.getOperand(3)); 10192 TmpInst.addOperand(Inst.getOperand(4)); // cc_out 10193 Inst = TmpInst; 10194 return true; 10195 } 10196 case ARM::t2LDMIA_UPD: { 10197 // If this is a load of a single register, then we should use 10198 // a post-indexed LDR instruction instead, per the ARM ARM. 10199 if (Inst.getNumOperands() != 5) 10200 return false; 10201 MCInst TmpInst; 10202 TmpInst.setOpcode(ARM::t2LDR_POST); 10203 TmpInst.addOperand(Inst.getOperand(4)); // Rt 10204 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 10205 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10206 TmpInst.addOperand(MCOperand::createImm(4)); 10207 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 10208 TmpInst.addOperand(Inst.getOperand(3)); 10209 Inst = TmpInst; 10210 return true; 10211 } 10212 case ARM::t2STMDB_UPD: { 10213 // If this is a store of a single register, then we should use 10214 // a pre-indexed STR instruction instead, per the ARM ARM. 10215 if (Inst.getNumOperands() != 5) 10216 return false; 10217 MCInst TmpInst; 10218 TmpInst.setOpcode(ARM::t2STR_PRE); 10219 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 10220 TmpInst.addOperand(Inst.getOperand(4)); // Rt 10221 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10222 TmpInst.addOperand(MCOperand::createImm(-4)); 10223 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 10224 TmpInst.addOperand(Inst.getOperand(3)); 10225 Inst = TmpInst; 10226 return true; 10227 } 10228 case ARM::LDMIA_UPD: 10229 // If this is a load of a single register via a 'pop', then we should use 10230 // a post-indexed LDR instruction instead, per the ARM ARM. 10231 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" && 10232 Inst.getNumOperands() == 5) { 10233 MCInst TmpInst; 10234 TmpInst.setOpcode(ARM::LDR_POST_IMM); 10235 TmpInst.addOperand(Inst.getOperand(4)); // Rt 10236 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 10237 TmpInst.addOperand(Inst.getOperand(1)); // Rn 10238 TmpInst.addOperand(MCOperand::createReg(0)); // am2offset 10239 TmpInst.addOperand(MCOperand::createImm(4)); 10240 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 10241 TmpInst.addOperand(Inst.getOperand(3)); 10242 Inst = TmpInst; 10243 return true; 10244 } 10245 break; 10246 case ARM::STMDB_UPD: 10247 // If this is a store of a single register via a 'push', then we should use 10248 // a pre-indexed STR instruction instead, per the ARM ARM. 10249 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" && 10250 Inst.getNumOperands() == 5) { 10251 MCInst TmpInst; 10252 TmpInst.setOpcode(ARM::STR_PRE_IMM); 10253 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 10254 TmpInst.addOperand(Inst.getOperand(4)); // Rt 10255 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12 10256 TmpInst.addOperand(MCOperand::createImm(-4)); 10257 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 10258 TmpInst.addOperand(Inst.getOperand(3)); 10259 Inst = TmpInst; 10260 } 10261 break; 10262 case ARM::t2ADDri12: 10263 case ARM::t2SUBri12: 10264 case ARM::t2ADDspImm12: 10265 case ARM::t2SUBspImm12: { 10266 // If the immediate fits for encoding T3 and the generic 10267 // mnemonic was used, encoding T3 is preferred. 10268 const StringRef Token = static_cast<ARMOperand &>(*Operands[0]).getToken(); 10269 if ((Token != "add" && Token != "sub") || 10270 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) 10271 break; 10272 switch (Inst.getOpcode()) { 10273 case ARM::t2ADDri12: 10274 Inst.setOpcode(ARM::t2ADDri); 10275 break; 10276 case ARM::t2SUBri12: 10277 Inst.setOpcode(ARM::t2SUBri); 10278 break; 10279 case ARM::t2ADDspImm12: 10280 Inst.setOpcode(ARM::t2ADDspImm); 10281 break; 10282 case ARM::t2SUBspImm12: 10283 Inst.setOpcode(ARM::t2SUBspImm); 10284 break; 10285 } 10286 10287 Inst.addOperand(MCOperand::createReg(0)); // cc_out 10288 return true; 10289 } 10290 case ARM::tADDi8: 10291 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was 10292 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred 10293 // to encoding T2 if <Rd> is specified and encoding T2 is preferred 10294 // to encoding T1 if <Rd> is omitted." 10295 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { 10296 Inst.setOpcode(ARM::tADDi3); 10297 return true; 10298 } 10299 break; 10300 case ARM::tSUBi8: 10301 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was 10302 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred 10303 // to encoding T2 if <Rd> is specified and encoding T2 is preferred 10304 // to encoding T1 if <Rd> is omitted." 10305 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { 10306 Inst.setOpcode(ARM::tSUBi3); 10307 return true; 10308 } 10309 break; 10310 case ARM::t2ADDri: 10311 case ARM::t2SUBri: { 10312 // If the destination and first source operand are the same, and 10313 // the flags are compatible with the current IT status, use encoding T2 10314 // instead of T3. For compatibility with the system 'as'. Make sure the 10315 // wide encoding wasn't explicit. 10316 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || 10317 !isARMLowRegister(Inst.getOperand(0).getReg()) || 10318 (Inst.getOperand(2).isImm() && 10319 (unsigned)Inst.getOperand(2).getImm() > 255) || 10320 Inst.getOperand(5).getReg() != (inITBlock() ? 0 : ARM::CPSR) || 10321 HasWideQualifier) 10322 break; 10323 MCInst TmpInst; 10324 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ? 10325 ARM::tADDi8 : ARM::tSUBi8); 10326 TmpInst.addOperand(Inst.getOperand(0)); 10327 TmpInst.addOperand(Inst.getOperand(5)); 10328 TmpInst.addOperand(Inst.getOperand(0)); 10329 TmpInst.addOperand(Inst.getOperand(2)); 10330 TmpInst.addOperand(Inst.getOperand(3)); 10331 TmpInst.addOperand(Inst.getOperand(4)); 10332 Inst = TmpInst; 10333 return true; 10334 } 10335 case ARM::t2ADDspImm: 10336 case ARM::t2SUBspImm: { 10337 // Prefer T1 encoding if possible 10338 if (Inst.getOperand(5).getReg() != 0 || HasWideQualifier) 10339 break; 10340 unsigned V = Inst.getOperand(2).getImm(); 10341 if (V & 3 || V > ((1 << 7) - 1) << 2) 10342 break; 10343 MCInst TmpInst; 10344 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDspImm ? ARM::tADDspi 10345 : ARM::tSUBspi); 10346 TmpInst.addOperand(MCOperand::createReg(ARM::SP)); // destination reg 10347 TmpInst.addOperand(MCOperand::createReg(ARM::SP)); // source reg 10348 TmpInst.addOperand(MCOperand::createImm(V / 4)); // immediate 10349 TmpInst.addOperand(Inst.getOperand(3)); // pred 10350 TmpInst.addOperand(Inst.getOperand(4)); 10351 Inst = TmpInst; 10352 return true; 10353 } 10354 case ARM::t2ADDrr: { 10355 // If the destination and first source operand are the same, and 10356 // there's no setting of the flags, use encoding T2 instead of T3. 10357 // Note that this is only for ADD, not SUB. This mirrors the system 10358 // 'as' behaviour. Also take advantage of ADD being commutative. 10359 // Make sure the wide encoding wasn't explicit. 10360 bool Swap = false; 10361 auto DestReg = Inst.getOperand(0).getReg(); 10362 bool Transform = DestReg == Inst.getOperand(1).getReg(); 10363 if (!Transform && DestReg == Inst.getOperand(2).getReg()) { 10364 Transform = true; 10365 Swap = true; 10366 } 10367 if (!Transform || 10368 Inst.getOperand(5).getReg() != 0 || 10369 HasWideQualifier) 10370 break; 10371 MCInst TmpInst; 10372 TmpInst.setOpcode(ARM::tADDhirr); 10373 TmpInst.addOperand(Inst.getOperand(0)); 10374 TmpInst.addOperand(Inst.getOperand(0)); 10375 TmpInst.addOperand(Inst.getOperand(Swap ? 1 : 2)); 10376 TmpInst.addOperand(Inst.getOperand(3)); 10377 TmpInst.addOperand(Inst.getOperand(4)); 10378 Inst = TmpInst; 10379 return true; 10380 } 10381 case ARM::tADDrSP: 10382 // If the non-SP source operand and the destination operand are not the 10383 // same, we need to use the 32-bit encoding if it's available. 10384 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { 10385 Inst.setOpcode(ARM::t2ADDrr); 10386 Inst.addOperand(MCOperand::createReg(0)); // cc_out 10387 return true; 10388 } 10389 break; 10390 case ARM::tB: 10391 // A Thumb conditional branch outside of an IT block is a tBcc. 10392 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) { 10393 Inst.setOpcode(ARM::tBcc); 10394 return true; 10395 } 10396 break; 10397 case ARM::t2B: 10398 // A Thumb2 conditional branch outside of an IT block is a t2Bcc. 10399 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){ 10400 Inst.setOpcode(ARM::t2Bcc); 10401 return true; 10402 } 10403 break; 10404 case ARM::t2Bcc: 10405 // If the conditional is AL or we're in an IT block, we really want t2B. 10406 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) { 10407 Inst.setOpcode(ARM::t2B); 10408 return true; 10409 } 10410 break; 10411 case ARM::tBcc: 10412 // If the conditional is AL, we really want tB. 10413 if (Inst.getOperand(1).getImm() == ARMCC::AL) { 10414 Inst.setOpcode(ARM::tB); 10415 return true; 10416 } 10417 break; 10418 case ARM::tLDMIA: { 10419 // If the register list contains any high registers, or if the writeback 10420 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding 10421 // instead if we're in Thumb2. Otherwise, this should have generated 10422 // an error in validateInstruction(). 10423 unsigned Rn = Inst.getOperand(0).getReg(); 10424 bool hasWritebackToken = 10425 (static_cast<ARMOperand &>(*Operands[3]).isToken() && 10426 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); 10427 bool listContainsBase; 10428 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) || 10429 (!listContainsBase && !hasWritebackToken) || 10430 (listContainsBase && hasWritebackToken)) { 10431 // 16-bit encoding isn't sufficient. Switch to the 32-bit version. 10432 assert(isThumbTwo()); 10433 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA); 10434 // If we're switching to the updating version, we need to insert 10435 // the writeback tied operand. 10436 if (hasWritebackToken) 10437 Inst.insert(Inst.begin(), 10438 MCOperand::createReg(Inst.getOperand(0).getReg())); 10439 return true; 10440 } 10441 break; 10442 } 10443 case ARM::tSTMIA_UPD: { 10444 // If the register list contains any high registers, we need to use 10445 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this 10446 // should have generated an error in validateInstruction(). 10447 unsigned Rn = Inst.getOperand(0).getReg(); 10448 bool listContainsBase; 10449 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) { 10450 // 16-bit encoding isn't sufficient. Switch to the 32-bit version. 10451 assert(isThumbTwo()); 10452 Inst.setOpcode(ARM::t2STMIA_UPD); 10453 return true; 10454 } 10455 break; 10456 } 10457 case ARM::tPOP: { 10458 bool listContainsBase; 10459 // If the register list contains any high registers, we need to use 10460 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this 10461 // should have generated an error in validateInstruction(). 10462 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase)) 10463 return false; 10464 assert(isThumbTwo()); 10465 Inst.setOpcode(ARM::t2LDMIA_UPD); 10466 // Add the base register and writeback operands. 10467 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 10468 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 10469 return true; 10470 } 10471 case ARM::tPUSH: { 10472 bool listContainsBase; 10473 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase)) 10474 return false; 10475 assert(isThumbTwo()); 10476 Inst.setOpcode(ARM::t2STMDB_UPD); 10477 // Add the base register and writeback operands. 10478 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 10479 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 10480 return true; 10481 } 10482 case ARM::t2MOVi: 10483 // If we can use the 16-bit encoding and the user didn't explicitly 10484 // request the 32-bit variant, transform it here. 10485 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 10486 (Inst.getOperand(1).isImm() && 10487 (unsigned)Inst.getOperand(1).getImm() <= 255) && 10488 Inst.getOperand(4).getReg() == (inITBlock() ? 0 : ARM::CPSR) && 10489 !HasWideQualifier) { 10490 // The operands aren't in the same order for tMOVi8... 10491 MCInst TmpInst; 10492 TmpInst.setOpcode(ARM::tMOVi8); 10493 TmpInst.addOperand(Inst.getOperand(0)); 10494 TmpInst.addOperand(Inst.getOperand(4)); 10495 TmpInst.addOperand(Inst.getOperand(1)); 10496 TmpInst.addOperand(Inst.getOperand(2)); 10497 TmpInst.addOperand(Inst.getOperand(3)); 10498 Inst = TmpInst; 10499 return true; 10500 } 10501 break; 10502 10503 case ARM::t2MOVr: 10504 // If we can use the 16-bit encoding and the user didn't explicitly 10505 // request the 32-bit variant, transform it here. 10506 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 10507 isARMLowRegister(Inst.getOperand(1).getReg()) && 10508 Inst.getOperand(2).getImm() == ARMCC::AL && 10509 Inst.getOperand(4).getReg() == ARM::CPSR && 10510 !HasWideQualifier) { 10511 // The operands aren't the same for tMOV[S]r... (no cc_out) 10512 MCInst TmpInst; 10513 unsigned Op = Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr; 10514 TmpInst.setOpcode(Op); 10515 TmpInst.addOperand(Inst.getOperand(0)); 10516 TmpInst.addOperand(Inst.getOperand(1)); 10517 if (Op == ARM::tMOVr) { 10518 TmpInst.addOperand(Inst.getOperand(2)); 10519 TmpInst.addOperand(Inst.getOperand(3)); 10520 } 10521 Inst = TmpInst; 10522 return true; 10523 } 10524 break; 10525 10526 case ARM::t2SXTH: 10527 case ARM::t2SXTB: 10528 case ARM::t2UXTH: 10529 case ARM::t2UXTB: 10530 // If we can use the 16-bit encoding and the user didn't explicitly 10531 // request the 32-bit variant, transform it here. 10532 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 10533 isARMLowRegister(Inst.getOperand(1).getReg()) && 10534 Inst.getOperand(2).getImm() == 0 && 10535 !HasWideQualifier) { 10536 unsigned NewOpc; 10537 switch (Inst.getOpcode()) { 10538 default: llvm_unreachable("Illegal opcode!"); 10539 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break; 10540 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break; 10541 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break; 10542 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break; 10543 } 10544 // The operands aren't the same for thumb1 (no rotate operand). 10545 MCInst TmpInst; 10546 TmpInst.setOpcode(NewOpc); 10547 TmpInst.addOperand(Inst.getOperand(0)); 10548 TmpInst.addOperand(Inst.getOperand(1)); 10549 TmpInst.addOperand(Inst.getOperand(3)); 10550 TmpInst.addOperand(Inst.getOperand(4)); 10551 Inst = TmpInst; 10552 return true; 10553 } 10554 break; 10555 10556 case ARM::MOVsi: { 10557 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm()); 10558 // rrx shifts and asr/lsr of #32 is encoded as 0 10559 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr) 10560 return false; 10561 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) { 10562 // Shifting by zero is accepted as a vanilla 'MOVr' 10563 MCInst TmpInst; 10564 TmpInst.setOpcode(ARM::MOVr); 10565 TmpInst.addOperand(Inst.getOperand(0)); 10566 TmpInst.addOperand(Inst.getOperand(1)); 10567 TmpInst.addOperand(Inst.getOperand(3)); 10568 TmpInst.addOperand(Inst.getOperand(4)); 10569 TmpInst.addOperand(Inst.getOperand(5)); 10570 Inst = TmpInst; 10571 return true; 10572 } 10573 return false; 10574 } 10575 case ARM::ANDrsi: 10576 case ARM::ORRrsi: 10577 case ARM::EORrsi: 10578 case ARM::BICrsi: 10579 case ARM::SUBrsi: 10580 case ARM::ADDrsi: { 10581 unsigned newOpc; 10582 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm()); 10583 if (SOpc == ARM_AM::rrx) return false; 10584 switch (Inst.getOpcode()) { 10585 default: llvm_unreachable("unexpected opcode!"); 10586 case ARM::ANDrsi: newOpc = ARM::ANDrr; break; 10587 case ARM::ORRrsi: newOpc = ARM::ORRrr; break; 10588 case ARM::EORrsi: newOpc = ARM::EORrr; break; 10589 case ARM::BICrsi: newOpc = ARM::BICrr; break; 10590 case ARM::SUBrsi: newOpc = ARM::SUBrr; break; 10591 case ARM::ADDrsi: newOpc = ARM::ADDrr; break; 10592 } 10593 // If the shift is by zero, use the non-shifted instruction definition. 10594 // The exception is for right shifts, where 0 == 32 10595 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 && 10596 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) { 10597 MCInst TmpInst; 10598 TmpInst.setOpcode(newOpc); 10599 TmpInst.addOperand(Inst.getOperand(0)); 10600 TmpInst.addOperand(Inst.getOperand(1)); 10601 TmpInst.addOperand(Inst.getOperand(2)); 10602 TmpInst.addOperand(Inst.getOperand(4)); 10603 TmpInst.addOperand(Inst.getOperand(5)); 10604 TmpInst.addOperand(Inst.getOperand(6)); 10605 Inst = TmpInst; 10606 return true; 10607 } 10608 return false; 10609 } 10610 case ARM::ITasm: 10611 case ARM::t2IT: { 10612 // Set up the IT block state according to the IT instruction we just 10613 // matched. 10614 assert(!inITBlock() && "nested IT blocks?!"); 10615 startExplicitITBlock(ARMCC::CondCodes(Inst.getOperand(0).getImm()), 10616 Inst.getOperand(1).getImm()); 10617 break; 10618 } 10619 case ARM::t2LSLrr: 10620 case ARM::t2LSRrr: 10621 case ARM::t2ASRrr: 10622 case ARM::t2SBCrr: 10623 case ARM::t2RORrr: 10624 case ARM::t2BICrr: 10625 // Assemblers should use the narrow encodings of these instructions when permissible. 10626 if ((isARMLowRegister(Inst.getOperand(1).getReg()) && 10627 isARMLowRegister(Inst.getOperand(2).getReg())) && 10628 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && 10629 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) && 10630 !HasWideQualifier) { 10631 unsigned NewOpc; 10632 switch (Inst.getOpcode()) { 10633 default: llvm_unreachable("unexpected opcode"); 10634 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break; 10635 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break; 10636 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break; 10637 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break; 10638 case ARM::t2RORrr: NewOpc = ARM::tROR; break; 10639 case ARM::t2BICrr: NewOpc = ARM::tBIC; break; 10640 } 10641 MCInst TmpInst; 10642 TmpInst.setOpcode(NewOpc); 10643 TmpInst.addOperand(Inst.getOperand(0)); 10644 TmpInst.addOperand(Inst.getOperand(5)); 10645 TmpInst.addOperand(Inst.getOperand(1)); 10646 TmpInst.addOperand(Inst.getOperand(2)); 10647 TmpInst.addOperand(Inst.getOperand(3)); 10648 TmpInst.addOperand(Inst.getOperand(4)); 10649 Inst = TmpInst; 10650 return true; 10651 } 10652 return false; 10653 10654 case ARM::t2ANDrr: 10655 case ARM::t2EORrr: 10656 case ARM::t2ADCrr: 10657 case ARM::t2ORRrr: 10658 // Assemblers should use the narrow encodings of these instructions when permissible. 10659 // These instructions are special in that they are commutable, so shorter encodings 10660 // are available more often. 10661 if ((isARMLowRegister(Inst.getOperand(1).getReg()) && 10662 isARMLowRegister(Inst.getOperand(2).getReg())) && 10663 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() || 10664 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) && 10665 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) && 10666 !HasWideQualifier) { 10667 unsigned NewOpc; 10668 switch (Inst.getOpcode()) { 10669 default: llvm_unreachable("unexpected opcode"); 10670 case ARM::t2ADCrr: NewOpc = ARM::tADC; break; 10671 case ARM::t2ANDrr: NewOpc = ARM::tAND; break; 10672 case ARM::t2EORrr: NewOpc = ARM::tEOR; break; 10673 case ARM::t2ORRrr: NewOpc = ARM::tORR; break; 10674 } 10675 MCInst TmpInst; 10676 TmpInst.setOpcode(NewOpc); 10677 TmpInst.addOperand(Inst.getOperand(0)); 10678 TmpInst.addOperand(Inst.getOperand(5)); 10679 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) { 10680 TmpInst.addOperand(Inst.getOperand(1)); 10681 TmpInst.addOperand(Inst.getOperand(2)); 10682 } else { 10683 TmpInst.addOperand(Inst.getOperand(2)); 10684 TmpInst.addOperand(Inst.getOperand(1)); 10685 } 10686 TmpInst.addOperand(Inst.getOperand(3)); 10687 TmpInst.addOperand(Inst.getOperand(4)); 10688 Inst = TmpInst; 10689 return true; 10690 } 10691 return false; 10692 case ARM::MVE_VPST: 10693 case ARM::MVE_VPTv16i8: 10694 case ARM::MVE_VPTv8i16: 10695 case ARM::MVE_VPTv4i32: 10696 case ARM::MVE_VPTv16u8: 10697 case ARM::MVE_VPTv8u16: 10698 case ARM::MVE_VPTv4u32: 10699 case ARM::MVE_VPTv16s8: 10700 case ARM::MVE_VPTv8s16: 10701 case ARM::MVE_VPTv4s32: 10702 case ARM::MVE_VPTv4f32: 10703 case ARM::MVE_VPTv8f16: 10704 case ARM::MVE_VPTv16i8r: 10705 case ARM::MVE_VPTv8i16r: 10706 case ARM::MVE_VPTv4i32r: 10707 case ARM::MVE_VPTv16u8r: 10708 case ARM::MVE_VPTv8u16r: 10709 case ARM::MVE_VPTv4u32r: 10710 case ARM::MVE_VPTv16s8r: 10711 case ARM::MVE_VPTv8s16r: 10712 case ARM::MVE_VPTv4s32r: 10713 case ARM::MVE_VPTv4f32r: 10714 case ARM::MVE_VPTv8f16r: { 10715 assert(!inVPTBlock() && "Nested VPT blocks are not allowed"); 10716 MCOperand &MO = Inst.getOperand(0); 10717 VPTState.Mask = MO.getImm(); 10718 VPTState.CurPosition = 0; 10719 break; 10720 } 10721 } 10722 return false; 10723 } 10724 10725 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) { 10726 // 16-bit thumb arithmetic instructions either require or preclude the 'S' 10727 // suffix depending on whether they're in an IT block or not. 10728 unsigned Opc = Inst.getOpcode(); 10729 const MCInstrDesc &MCID = MII.get(Opc); 10730 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) { 10731 assert(MCID.hasOptionalDef() && 10732 "optionally flag setting instruction missing optional def operand"); 10733 assert(MCID.NumOperands == Inst.getNumOperands() && 10734 "operand count mismatch!"); 10735 // Find the optional-def operand (cc_out). 10736 unsigned OpNo; 10737 for (OpNo = 0; 10738 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands; 10739 ++OpNo) 10740 ; 10741 // If we're parsing Thumb1, reject it completely. 10742 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR) 10743 return Match_RequiresFlagSetting; 10744 // If we're parsing Thumb2, which form is legal depends on whether we're 10745 // in an IT block. 10746 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR && 10747 !inITBlock()) 10748 return Match_RequiresITBlock; 10749 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR && 10750 inITBlock()) 10751 return Match_RequiresNotITBlock; 10752 // LSL with zero immediate is not allowed in an IT block 10753 if (Opc == ARM::tLSLri && Inst.getOperand(3).getImm() == 0 && inITBlock()) 10754 return Match_RequiresNotITBlock; 10755 } else if (isThumbOne()) { 10756 // Some high-register supporting Thumb1 encodings only allow both registers 10757 // to be from r0-r7 when in Thumb2. 10758 if (Opc == ARM::tADDhirr && !hasV6MOps() && 10759 isARMLowRegister(Inst.getOperand(1).getReg()) && 10760 isARMLowRegister(Inst.getOperand(2).getReg())) 10761 return Match_RequiresThumb2; 10762 // Others only require ARMv6 or later. 10763 else if (Opc == ARM::tMOVr && !hasV6Ops() && 10764 isARMLowRegister(Inst.getOperand(0).getReg()) && 10765 isARMLowRegister(Inst.getOperand(1).getReg())) 10766 return Match_RequiresV6; 10767 } 10768 10769 // Before ARMv8 the rules for when SP is allowed in t2MOVr are more complex 10770 // than the loop below can handle, so it uses the GPRnopc register class and 10771 // we do SP handling here. 10772 if (Opc == ARM::t2MOVr && !hasV8Ops()) 10773 { 10774 // SP as both source and destination is not allowed 10775 if (Inst.getOperand(0).getReg() == ARM::SP && 10776 Inst.getOperand(1).getReg() == ARM::SP) 10777 return Match_RequiresV8; 10778 // When flags-setting SP as either source or destination is not allowed 10779 if (Inst.getOperand(4).getReg() == ARM::CPSR && 10780 (Inst.getOperand(0).getReg() == ARM::SP || 10781 Inst.getOperand(1).getReg() == ARM::SP)) 10782 return Match_RequiresV8; 10783 } 10784 10785 switch (Inst.getOpcode()) { 10786 case ARM::VMRS: 10787 case ARM::VMSR: 10788 case ARM::VMRS_FPCXTS: 10789 case ARM::VMRS_FPCXTNS: 10790 case ARM::VMSR_FPCXTS: 10791 case ARM::VMSR_FPCXTNS: 10792 case ARM::VMRS_FPSCR_NZCVQC: 10793 case ARM::VMSR_FPSCR_NZCVQC: 10794 case ARM::FMSTAT: 10795 case ARM::VMRS_VPR: 10796 case ARM::VMRS_P0: 10797 case ARM::VMSR_VPR: 10798 case ARM::VMSR_P0: 10799 // Use of SP for VMRS/VMSR is only allowed in ARM mode with the exception of 10800 // ARMv8-A. 10801 if (Inst.getOperand(0).isReg() && Inst.getOperand(0).getReg() == ARM::SP && 10802 (isThumb() && !hasV8Ops())) 10803 return Match_InvalidOperand; 10804 break; 10805 case ARM::t2TBB: 10806 case ARM::t2TBH: 10807 // Rn = sp is only allowed with ARMv8-A 10808 if (!hasV8Ops() && (Inst.getOperand(0).getReg() == ARM::SP)) 10809 return Match_RequiresV8; 10810 break; 10811 default: 10812 break; 10813 } 10814 10815 for (unsigned I = 0; I < MCID.NumOperands; ++I) 10816 if (MCID.OpInfo[I].RegClass == ARM::rGPRRegClassID) { 10817 // rGPRRegClass excludes PC, and also excluded SP before ARMv8 10818 const auto &Op = Inst.getOperand(I); 10819 if (!Op.isReg()) { 10820 // This can happen in awkward cases with tied operands, e.g. a 10821 // writeback load/store with a complex addressing mode in 10822 // which there's an output operand corresponding to the 10823 // updated written-back base register: the Tablegen-generated 10824 // AsmMatcher will have written a placeholder operand to that 10825 // slot in the form of an immediate 0, because it can't 10826 // generate the register part of the complex addressing-mode 10827 // operand ahead of time. 10828 continue; 10829 } 10830 10831 unsigned Reg = Op.getReg(); 10832 if ((Reg == ARM::SP) && !hasV8Ops()) 10833 return Match_RequiresV8; 10834 else if (Reg == ARM::PC) 10835 return Match_InvalidOperand; 10836 } 10837 10838 return Match_Success; 10839 } 10840 10841 namespace llvm { 10842 10843 template <> inline bool IsCPSRDead<MCInst>(const MCInst *Instr) { 10844 return true; // In an assembly source, no need to second-guess 10845 } 10846 10847 } // end namespace llvm 10848 10849 // Returns true if Inst is unpredictable if it is in and IT block, but is not 10850 // the last instruction in the block. 10851 bool ARMAsmParser::isITBlockTerminator(MCInst &Inst) const { 10852 const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); 10853 10854 // All branch & call instructions terminate IT blocks with the exception of 10855 // SVC. 10856 if (MCID.isTerminator() || (MCID.isCall() && Inst.getOpcode() != ARM::tSVC) || 10857 MCID.isReturn() || MCID.isBranch() || MCID.isIndirectBranch()) 10858 return true; 10859 10860 // Any arithmetic instruction which writes to the PC also terminates the IT 10861 // block. 10862 if (MCID.hasDefOfPhysReg(Inst, ARM::PC, *MRI)) 10863 return true; 10864 10865 return false; 10866 } 10867 10868 unsigned ARMAsmParser::MatchInstruction(OperandVector &Operands, MCInst &Inst, 10869 SmallVectorImpl<NearMissInfo> &NearMisses, 10870 bool MatchingInlineAsm, 10871 bool &EmitInITBlock, 10872 MCStreamer &Out) { 10873 // If we can't use an implicit IT block here, just match as normal. 10874 if (inExplicitITBlock() || !isThumbTwo() || !useImplicitITThumb()) 10875 return MatchInstructionImpl(Operands, Inst, &NearMisses, MatchingInlineAsm); 10876 10877 // Try to match the instruction in an extension of the current IT block (if 10878 // there is one). 10879 if (inImplicitITBlock()) { 10880 extendImplicitITBlock(ITState.Cond); 10881 if (MatchInstructionImpl(Operands, Inst, nullptr, MatchingInlineAsm) == 10882 Match_Success) { 10883 // The match succeded, but we still have to check that the instruction is 10884 // valid in this implicit IT block. 10885 const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); 10886 if (MCID.isPredicable()) { 10887 ARMCC::CondCodes InstCond = 10888 (ARMCC::CondCodes)Inst.getOperand(MCID.findFirstPredOperandIdx()) 10889 .getImm(); 10890 ARMCC::CondCodes ITCond = currentITCond(); 10891 if (InstCond == ITCond) { 10892 EmitInITBlock = true; 10893 return Match_Success; 10894 } else if (InstCond == ARMCC::getOppositeCondition(ITCond)) { 10895 invertCurrentITCondition(); 10896 EmitInITBlock = true; 10897 return Match_Success; 10898 } 10899 } 10900 } 10901 rewindImplicitITPosition(); 10902 } 10903 10904 // Finish the current IT block, and try to match outside any IT block. 10905 flushPendingInstructions(Out); 10906 unsigned PlainMatchResult = 10907 MatchInstructionImpl(Operands, Inst, &NearMisses, MatchingInlineAsm); 10908 if (PlainMatchResult == Match_Success) { 10909 const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); 10910 if (MCID.isPredicable()) { 10911 ARMCC::CondCodes InstCond = 10912 (ARMCC::CondCodes)Inst.getOperand(MCID.findFirstPredOperandIdx()) 10913 .getImm(); 10914 // Some forms of the branch instruction have their own condition code 10915 // fields, so can be conditionally executed without an IT block. 10916 if (Inst.getOpcode() == ARM::tBcc || Inst.getOpcode() == ARM::t2Bcc) { 10917 EmitInITBlock = false; 10918 return Match_Success; 10919 } 10920 if (InstCond == ARMCC::AL) { 10921 EmitInITBlock = false; 10922 return Match_Success; 10923 } 10924 } else { 10925 EmitInITBlock = false; 10926 return Match_Success; 10927 } 10928 } 10929 10930 // Try to match in a new IT block. The matcher doesn't check the actual 10931 // condition, so we create an IT block with a dummy condition, and fix it up 10932 // once we know the actual condition. 10933 startImplicitITBlock(); 10934 if (MatchInstructionImpl(Operands, Inst, nullptr, MatchingInlineAsm) == 10935 Match_Success) { 10936 const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); 10937 if (MCID.isPredicable()) { 10938 ITState.Cond = 10939 (ARMCC::CondCodes)Inst.getOperand(MCID.findFirstPredOperandIdx()) 10940 .getImm(); 10941 EmitInITBlock = true; 10942 return Match_Success; 10943 } 10944 } 10945 discardImplicitITBlock(); 10946 10947 // If none of these succeed, return the error we got when trying to match 10948 // outside any IT blocks. 10949 EmitInITBlock = false; 10950 return PlainMatchResult; 10951 } 10952 10953 static std::string ARMMnemonicSpellCheck(StringRef S, const FeatureBitset &FBS, 10954 unsigned VariantID = 0); 10955 10956 static const char *getSubtargetFeatureName(uint64_t Val); 10957 bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, 10958 OperandVector &Operands, 10959 MCStreamer &Out, uint64_t &ErrorInfo, 10960 bool MatchingInlineAsm) { 10961 MCInst Inst; 10962 unsigned MatchResult; 10963 bool PendConditionalInstruction = false; 10964 10965 SmallVector<NearMissInfo, 4> NearMisses; 10966 MatchResult = MatchInstruction(Operands, Inst, NearMisses, MatchingInlineAsm, 10967 PendConditionalInstruction, Out); 10968 10969 switch (MatchResult) { 10970 case Match_Success: 10971 LLVM_DEBUG(dbgs() << "Parsed as: "; 10972 Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode())); 10973 dbgs() << "\n"); 10974 10975 // Context sensitive operand constraints aren't handled by the matcher, 10976 // so check them here. 10977 if (validateInstruction(Inst, Operands)) { 10978 // Still progress the IT block, otherwise one wrong condition causes 10979 // nasty cascading errors. 10980 forwardITPosition(); 10981 forwardVPTPosition(); 10982 return true; 10983 } 10984 10985 { 10986 // Some instructions need post-processing to, for example, tweak which 10987 // encoding is selected. Loop on it while changes happen so the 10988 // individual transformations can chain off each other. E.g., 10989 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8) 10990 while (processInstruction(Inst, Operands, Out)) 10991 LLVM_DEBUG(dbgs() << "Changed to: "; 10992 Inst.dump_pretty(dbgs(), MII.getName(Inst.getOpcode())); 10993 dbgs() << "\n"); 10994 } 10995 10996 // Only move forward at the very end so that everything in validate 10997 // and process gets a consistent answer about whether we're in an IT 10998 // block. 10999 forwardITPosition(); 11000 forwardVPTPosition(); 11001 11002 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and 11003 // doesn't actually encode. 11004 if (Inst.getOpcode() == ARM::ITasm) 11005 return false; 11006 11007 Inst.setLoc(IDLoc); 11008 if (PendConditionalInstruction) { 11009 PendingConditionalInsts.push_back(Inst); 11010 if (isITBlockFull() || isITBlockTerminator(Inst)) 11011 flushPendingInstructions(Out); 11012 } else { 11013 Out.emitInstruction(Inst, getSTI()); 11014 } 11015 return false; 11016 case Match_NearMisses: 11017 ReportNearMisses(NearMisses, IDLoc, Operands); 11018 return true; 11019 case Match_MnemonicFail: { 11020 FeatureBitset FBS = ComputeAvailableFeatures(getSTI().getFeatureBits()); 11021 std::string Suggestion = ARMMnemonicSpellCheck( 11022 ((ARMOperand &)*Operands[0]).getToken(), FBS); 11023 return Error(IDLoc, "invalid instruction" + Suggestion, 11024 ((ARMOperand &)*Operands[0]).getLocRange()); 11025 } 11026 } 11027 11028 llvm_unreachable("Implement any new match types added!"); 11029 } 11030 11031 /// parseDirective parses the arm specific directives 11032 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { 11033 const MCContext::Environment Format = getContext().getObjectFileType(); 11034 bool IsMachO = Format == MCContext::IsMachO; 11035 bool IsCOFF = Format == MCContext::IsCOFF; 11036 11037 std::string IDVal = DirectiveID.getIdentifier().lower(); 11038 if (IDVal == ".word") 11039 parseLiteralValues(4, DirectiveID.getLoc()); 11040 else if (IDVal == ".short" || IDVal == ".hword") 11041 parseLiteralValues(2, DirectiveID.getLoc()); 11042 else if (IDVal == ".thumb") 11043 parseDirectiveThumb(DirectiveID.getLoc()); 11044 else if (IDVal == ".arm") 11045 parseDirectiveARM(DirectiveID.getLoc()); 11046 else if (IDVal == ".thumb_func") 11047 parseDirectiveThumbFunc(DirectiveID.getLoc()); 11048 else if (IDVal == ".code") 11049 parseDirectiveCode(DirectiveID.getLoc()); 11050 else if (IDVal == ".syntax") 11051 parseDirectiveSyntax(DirectiveID.getLoc()); 11052 else if (IDVal == ".unreq") 11053 parseDirectiveUnreq(DirectiveID.getLoc()); 11054 else if (IDVal == ".fnend") 11055 parseDirectiveFnEnd(DirectiveID.getLoc()); 11056 else if (IDVal == ".cantunwind") 11057 parseDirectiveCantUnwind(DirectiveID.getLoc()); 11058 else if (IDVal == ".personality") 11059 parseDirectivePersonality(DirectiveID.getLoc()); 11060 else if (IDVal == ".handlerdata") 11061 parseDirectiveHandlerData(DirectiveID.getLoc()); 11062 else if (IDVal == ".setfp") 11063 parseDirectiveSetFP(DirectiveID.getLoc()); 11064 else if (IDVal == ".pad") 11065 parseDirectivePad(DirectiveID.getLoc()); 11066 else if (IDVal == ".save") 11067 parseDirectiveRegSave(DirectiveID.getLoc(), false); 11068 else if (IDVal == ".vsave") 11069 parseDirectiveRegSave(DirectiveID.getLoc(), true); 11070 else if (IDVal == ".ltorg" || IDVal == ".pool") 11071 parseDirectiveLtorg(DirectiveID.getLoc()); 11072 else if (IDVal == ".even") 11073 parseDirectiveEven(DirectiveID.getLoc()); 11074 else if (IDVal == ".personalityindex") 11075 parseDirectivePersonalityIndex(DirectiveID.getLoc()); 11076 else if (IDVal == ".unwind_raw") 11077 parseDirectiveUnwindRaw(DirectiveID.getLoc()); 11078 else if (IDVal == ".movsp") 11079 parseDirectiveMovSP(DirectiveID.getLoc()); 11080 else if (IDVal == ".arch_extension") 11081 parseDirectiveArchExtension(DirectiveID.getLoc()); 11082 else if (IDVal == ".align") 11083 return parseDirectiveAlign(DirectiveID.getLoc()); // Use Generic on failure. 11084 else if (IDVal == ".thumb_set") 11085 parseDirectiveThumbSet(DirectiveID.getLoc()); 11086 else if (IDVal == ".inst") 11087 parseDirectiveInst(DirectiveID.getLoc()); 11088 else if (IDVal == ".inst.n") 11089 parseDirectiveInst(DirectiveID.getLoc(), 'n'); 11090 else if (IDVal == ".inst.w") 11091 parseDirectiveInst(DirectiveID.getLoc(), 'w'); 11092 else if (!IsMachO && !IsCOFF) { 11093 if (IDVal == ".arch") 11094 parseDirectiveArch(DirectiveID.getLoc()); 11095 else if (IDVal == ".cpu") 11096 parseDirectiveCPU(DirectiveID.getLoc()); 11097 else if (IDVal == ".eabi_attribute") 11098 parseDirectiveEabiAttr(DirectiveID.getLoc()); 11099 else if (IDVal == ".fpu") 11100 parseDirectiveFPU(DirectiveID.getLoc()); 11101 else if (IDVal == ".fnstart") 11102 parseDirectiveFnStart(DirectiveID.getLoc()); 11103 else if (IDVal == ".object_arch") 11104 parseDirectiveObjectArch(DirectiveID.getLoc()); 11105 else if (IDVal == ".tlsdescseq") 11106 parseDirectiveTLSDescSeq(DirectiveID.getLoc()); 11107 else 11108 return true; 11109 } else if (IsCOFF) { 11110 if (IDVal == ".seh_stackalloc") 11111 parseDirectiveSEHAllocStack(DirectiveID.getLoc(), /*Wide=*/false); 11112 else if (IDVal == ".seh_stackalloc_w") 11113 parseDirectiveSEHAllocStack(DirectiveID.getLoc(), /*Wide=*/true); 11114 else if (IDVal == ".seh_save_regs") 11115 parseDirectiveSEHSaveRegs(DirectiveID.getLoc(), /*Wide=*/false); 11116 else if (IDVal == ".seh_save_regs_w") 11117 parseDirectiveSEHSaveRegs(DirectiveID.getLoc(), /*Wide=*/true); 11118 else if (IDVal == ".seh_save_sp") 11119 parseDirectiveSEHSaveSP(DirectiveID.getLoc()); 11120 else if (IDVal == ".seh_save_fregs") 11121 parseDirectiveSEHSaveFRegs(DirectiveID.getLoc()); 11122 else if (IDVal == ".seh_save_lr") 11123 parseDirectiveSEHSaveLR(DirectiveID.getLoc()); 11124 else if (IDVal == ".seh_endprologue") 11125 parseDirectiveSEHPrologEnd(DirectiveID.getLoc(), /*Fragment=*/false); 11126 else if (IDVal == ".seh_endprologue_fragment") 11127 parseDirectiveSEHPrologEnd(DirectiveID.getLoc(), /*Fragment=*/true); 11128 else if (IDVal == ".seh_nop") 11129 parseDirectiveSEHNop(DirectiveID.getLoc(), /*Wide=*/false); 11130 else if (IDVal == ".seh_nop_w") 11131 parseDirectiveSEHNop(DirectiveID.getLoc(), /*Wide=*/true); 11132 else if (IDVal == ".seh_startepilogue") 11133 parseDirectiveSEHEpilogStart(DirectiveID.getLoc(), /*Condition=*/false); 11134 else if (IDVal == ".seh_startepilogue_cond") 11135 parseDirectiveSEHEpilogStart(DirectiveID.getLoc(), /*Condition=*/true); 11136 else if (IDVal == ".seh_endepilogue") 11137 parseDirectiveSEHEpilogEnd(DirectiveID.getLoc()); 11138 else if (IDVal == ".seh_custom") 11139 parseDirectiveSEHCustom(DirectiveID.getLoc()); 11140 else 11141 return true; 11142 } else 11143 return true; 11144 return false; 11145 } 11146 11147 /// parseLiteralValues 11148 /// ::= .hword expression [, expression]* 11149 /// ::= .short expression [, expression]* 11150 /// ::= .word expression [, expression]* 11151 bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) { 11152 auto parseOne = [&]() -> bool { 11153 const MCExpr *Value; 11154 if (getParser().parseExpression(Value)) 11155 return true; 11156 getParser().getStreamer().emitValue(Value, Size, L); 11157 return false; 11158 }; 11159 return (parseMany(parseOne)); 11160 } 11161 11162 /// parseDirectiveThumb 11163 /// ::= .thumb 11164 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) { 11165 if (parseEOL() || check(!hasThumb(), L, "target does not support Thumb mode")) 11166 return true; 11167 11168 if (!isThumb()) 11169 SwitchMode(); 11170 11171 getParser().getStreamer().emitAssemblerFlag(MCAF_Code16); 11172 return false; 11173 } 11174 11175 /// parseDirectiveARM 11176 /// ::= .arm 11177 bool ARMAsmParser::parseDirectiveARM(SMLoc L) { 11178 if (parseEOL() || check(!hasARM(), L, "target does not support ARM mode")) 11179 return true; 11180 11181 if (isThumb()) 11182 SwitchMode(); 11183 getParser().getStreamer().emitAssemblerFlag(MCAF_Code32); 11184 return false; 11185 } 11186 11187 void ARMAsmParser::doBeforeLabelEmit(MCSymbol *Symbol) { 11188 // We need to flush the current implicit IT block on a label, because it is 11189 // not legal to branch into an IT block. 11190 flushPendingInstructions(getStreamer()); 11191 } 11192 11193 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) { 11194 if (NextSymbolIsThumb) { 11195 getParser().getStreamer().emitThumbFunc(Symbol); 11196 NextSymbolIsThumb = false; 11197 } 11198 } 11199 11200 /// parseDirectiveThumbFunc 11201 /// ::= .thumbfunc symbol_name 11202 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) { 11203 MCAsmParser &Parser = getParser(); 11204 const auto Format = getContext().getObjectFileType(); 11205 bool IsMachO = Format == MCContext::IsMachO; 11206 11207 // Darwin asm has (optionally) function name after .thumb_func direction 11208 // ELF doesn't 11209 11210 if (IsMachO) { 11211 if (Parser.getTok().is(AsmToken::Identifier) || 11212 Parser.getTok().is(AsmToken::String)) { 11213 MCSymbol *Func = getParser().getContext().getOrCreateSymbol( 11214 Parser.getTok().getIdentifier()); 11215 getParser().getStreamer().emitThumbFunc(Func); 11216 Parser.Lex(); 11217 if (parseEOL()) 11218 return true; 11219 return false; 11220 } 11221 } 11222 11223 if (parseEOL()) 11224 return true; 11225 11226 // .thumb_func implies .thumb 11227 if (!isThumb()) 11228 SwitchMode(); 11229 11230 getParser().getStreamer().emitAssemblerFlag(MCAF_Code16); 11231 11232 NextSymbolIsThumb = true; 11233 return false; 11234 } 11235 11236 /// parseDirectiveSyntax 11237 /// ::= .syntax unified | divided 11238 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) { 11239 MCAsmParser &Parser = getParser(); 11240 const AsmToken &Tok = Parser.getTok(); 11241 if (Tok.isNot(AsmToken::Identifier)) { 11242 Error(L, "unexpected token in .syntax directive"); 11243 return false; 11244 } 11245 11246 StringRef Mode = Tok.getString(); 11247 Parser.Lex(); 11248 if (check(Mode == "divided" || Mode == "DIVIDED", L, 11249 "'.syntax divided' arm assembly not supported") || 11250 check(Mode != "unified" && Mode != "UNIFIED", L, 11251 "unrecognized syntax mode in .syntax directive") || 11252 parseEOL()) 11253 return true; 11254 11255 // TODO tell the MC streamer the mode 11256 // getParser().getStreamer().Emit???(); 11257 return false; 11258 } 11259 11260 /// parseDirectiveCode 11261 /// ::= .code 16 | 32 11262 bool ARMAsmParser::parseDirectiveCode(SMLoc L) { 11263 MCAsmParser &Parser = getParser(); 11264 const AsmToken &Tok = Parser.getTok(); 11265 if (Tok.isNot(AsmToken::Integer)) 11266 return Error(L, "unexpected token in .code directive"); 11267 int64_t Val = Parser.getTok().getIntVal(); 11268 if (Val != 16 && Val != 32) { 11269 Error(L, "invalid operand to .code directive"); 11270 return false; 11271 } 11272 Parser.Lex(); 11273 11274 if (parseEOL()) 11275 return true; 11276 11277 if (Val == 16) { 11278 if (!hasThumb()) 11279 return Error(L, "target does not support Thumb mode"); 11280 11281 if (!isThumb()) 11282 SwitchMode(); 11283 getParser().getStreamer().emitAssemblerFlag(MCAF_Code16); 11284 } else { 11285 if (!hasARM()) 11286 return Error(L, "target does not support ARM mode"); 11287 11288 if (isThumb()) 11289 SwitchMode(); 11290 getParser().getStreamer().emitAssemblerFlag(MCAF_Code32); 11291 } 11292 11293 return false; 11294 } 11295 11296 /// parseDirectiveReq 11297 /// ::= name .req registername 11298 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) { 11299 MCAsmParser &Parser = getParser(); 11300 Parser.Lex(); // Eat the '.req' token. 11301 unsigned Reg; 11302 SMLoc SRegLoc, ERegLoc; 11303 if (check(ParseRegister(Reg, SRegLoc, ERegLoc), SRegLoc, 11304 "register name expected") || 11305 parseEOL()) 11306 return true; 11307 11308 if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg) 11309 return Error(SRegLoc, 11310 "redefinition of '" + Name + "' does not match original."); 11311 11312 return false; 11313 } 11314 11315 /// parseDirectiveUneq 11316 /// ::= .unreq registername 11317 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) { 11318 MCAsmParser &Parser = getParser(); 11319 if (Parser.getTok().isNot(AsmToken::Identifier)) 11320 return Error(L, "unexpected input in .unreq directive."); 11321 RegisterReqs.erase(Parser.getTok().getIdentifier().lower()); 11322 Parser.Lex(); // Eat the identifier. 11323 return parseEOL(); 11324 } 11325 11326 // After changing arch/CPU, try to put the ARM/Thumb mode back to what it was 11327 // before, if supported by the new target, or emit mapping symbols for the mode 11328 // switch. 11329 void ARMAsmParser::FixModeAfterArchChange(bool WasThumb, SMLoc Loc) { 11330 if (WasThumb != isThumb()) { 11331 if (WasThumb && hasThumb()) { 11332 // Stay in Thumb mode 11333 SwitchMode(); 11334 } else if (!WasThumb && hasARM()) { 11335 // Stay in ARM mode 11336 SwitchMode(); 11337 } else { 11338 // Mode switch forced, because the new arch doesn't support the old mode. 11339 getParser().getStreamer().emitAssemblerFlag(isThumb() ? MCAF_Code16 11340 : MCAF_Code32); 11341 // Warn about the implcit mode switch. GAS does not switch modes here, 11342 // but instead stays in the old mode, reporting an error on any following 11343 // instructions as the mode does not exist on the target. 11344 Warning(Loc, Twine("new target does not support ") + 11345 (WasThumb ? "thumb" : "arm") + " mode, switching to " + 11346 (!WasThumb ? "thumb" : "arm") + " mode"); 11347 } 11348 } 11349 } 11350 11351 /// parseDirectiveArch 11352 /// ::= .arch token 11353 bool ARMAsmParser::parseDirectiveArch(SMLoc L) { 11354 StringRef Arch = getParser().parseStringToEndOfStatement().trim(); 11355 ARM::ArchKind ID = ARM::parseArch(Arch); 11356 11357 if (ID == ARM::ArchKind::INVALID) 11358 return Error(L, "Unknown arch name"); 11359 11360 bool WasThumb = isThumb(); 11361 Triple T; 11362 MCSubtargetInfo &STI = copySTI(); 11363 STI.setDefaultFeatures("", /*TuneCPU*/ "", 11364 ("+" + ARM::getArchName(ID)).str()); 11365 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 11366 FixModeAfterArchChange(WasThumb, L); 11367 11368 getTargetStreamer().emitArch(ID); 11369 return false; 11370 } 11371 11372 /// parseDirectiveEabiAttr 11373 /// ::= .eabi_attribute int, int [, "str"] 11374 /// ::= .eabi_attribute Tag_name, int [, "str"] 11375 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) { 11376 MCAsmParser &Parser = getParser(); 11377 int64_t Tag; 11378 SMLoc TagLoc; 11379 TagLoc = Parser.getTok().getLoc(); 11380 if (Parser.getTok().is(AsmToken::Identifier)) { 11381 StringRef Name = Parser.getTok().getIdentifier(); 11382 Optional<unsigned> Ret = ELFAttrs::attrTypeFromString( 11383 Name, ARMBuildAttrs::getARMAttributeTags()); 11384 if (!Ret) { 11385 Error(TagLoc, "attribute name not recognised: " + Name); 11386 return false; 11387 } 11388 Tag = *Ret; 11389 Parser.Lex(); 11390 } else { 11391 const MCExpr *AttrExpr; 11392 11393 TagLoc = Parser.getTok().getLoc(); 11394 if (Parser.parseExpression(AttrExpr)) 11395 return true; 11396 11397 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr); 11398 if (check(!CE, TagLoc, "expected numeric constant")) 11399 return true; 11400 11401 Tag = CE->getValue(); 11402 } 11403 11404 if (Parser.parseToken(AsmToken::Comma, "comma expected")) 11405 return true; 11406 11407 StringRef StringValue = ""; 11408 bool IsStringValue = false; 11409 11410 int64_t IntegerValue = 0; 11411 bool IsIntegerValue = false; 11412 11413 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name) 11414 IsStringValue = true; 11415 else if (Tag == ARMBuildAttrs::compatibility) { 11416 IsStringValue = true; 11417 IsIntegerValue = true; 11418 } else if (Tag < 32 || Tag % 2 == 0) 11419 IsIntegerValue = true; 11420 else if (Tag % 2 == 1) 11421 IsStringValue = true; 11422 else 11423 llvm_unreachable("invalid tag type"); 11424 11425 if (IsIntegerValue) { 11426 const MCExpr *ValueExpr; 11427 SMLoc ValueExprLoc = Parser.getTok().getLoc(); 11428 if (Parser.parseExpression(ValueExpr)) 11429 return true; 11430 11431 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr); 11432 if (!CE) 11433 return Error(ValueExprLoc, "expected numeric constant"); 11434 IntegerValue = CE->getValue(); 11435 } 11436 11437 if (Tag == ARMBuildAttrs::compatibility) { 11438 if (Parser.parseToken(AsmToken::Comma, "comma expected")) 11439 return true; 11440 } 11441 11442 if (IsStringValue) { 11443 if (Parser.getTok().isNot(AsmToken::String)) 11444 return Error(Parser.getTok().getLoc(), "bad string constant"); 11445 11446 StringValue = Parser.getTok().getStringContents(); 11447 Parser.Lex(); 11448 } 11449 11450 if (Parser.parseEOL()) 11451 return true; 11452 11453 if (IsIntegerValue && IsStringValue) { 11454 assert(Tag == ARMBuildAttrs::compatibility); 11455 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue); 11456 } else if (IsIntegerValue) 11457 getTargetStreamer().emitAttribute(Tag, IntegerValue); 11458 else if (IsStringValue) 11459 getTargetStreamer().emitTextAttribute(Tag, StringValue); 11460 return false; 11461 } 11462 11463 /// parseDirectiveCPU 11464 /// ::= .cpu str 11465 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) { 11466 StringRef CPU = getParser().parseStringToEndOfStatement().trim(); 11467 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU); 11468 11469 // FIXME: This is using table-gen data, but should be moved to 11470 // ARMTargetParser once that is table-gen'd. 11471 if (!getSTI().isCPUStringValid(CPU)) 11472 return Error(L, "Unknown CPU name"); 11473 11474 bool WasThumb = isThumb(); 11475 MCSubtargetInfo &STI = copySTI(); 11476 STI.setDefaultFeatures(CPU, /*TuneCPU*/ CPU, ""); 11477 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 11478 FixModeAfterArchChange(WasThumb, L); 11479 11480 return false; 11481 } 11482 11483 /// parseDirectiveFPU 11484 /// ::= .fpu str 11485 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) { 11486 SMLoc FPUNameLoc = getTok().getLoc(); 11487 StringRef FPU = getParser().parseStringToEndOfStatement().trim(); 11488 11489 unsigned ID = ARM::parseFPU(FPU); 11490 std::vector<StringRef> Features; 11491 if (!ARM::getFPUFeatures(ID, Features)) 11492 return Error(FPUNameLoc, "Unknown FPU name"); 11493 11494 MCSubtargetInfo &STI = copySTI(); 11495 for (auto Feature : Features) 11496 STI.ApplyFeatureFlag(Feature); 11497 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 11498 11499 getTargetStreamer().emitFPU(ID); 11500 return false; 11501 } 11502 11503 /// parseDirectiveFnStart 11504 /// ::= .fnstart 11505 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) { 11506 if (parseEOL()) 11507 return true; 11508 11509 if (UC.hasFnStart()) { 11510 Error(L, ".fnstart starts before the end of previous one"); 11511 UC.emitFnStartLocNotes(); 11512 return true; 11513 } 11514 11515 // Reset the unwind directives parser state 11516 UC.reset(); 11517 11518 getTargetStreamer().emitFnStart(); 11519 11520 UC.recordFnStart(L); 11521 return false; 11522 } 11523 11524 /// parseDirectiveFnEnd 11525 /// ::= .fnend 11526 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) { 11527 if (parseEOL()) 11528 return true; 11529 // Check the ordering of unwind directives 11530 if (!UC.hasFnStart()) 11531 return Error(L, ".fnstart must precede .fnend directive"); 11532 11533 // Reset the unwind directives parser state 11534 getTargetStreamer().emitFnEnd(); 11535 11536 UC.reset(); 11537 return false; 11538 } 11539 11540 /// parseDirectiveCantUnwind 11541 /// ::= .cantunwind 11542 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) { 11543 if (parseEOL()) 11544 return true; 11545 11546 UC.recordCantUnwind(L); 11547 // Check the ordering of unwind directives 11548 if (check(!UC.hasFnStart(), L, ".fnstart must precede .cantunwind directive")) 11549 return true; 11550 11551 if (UC.hasHandlerData()) { 11552 Error(L, ".cantunwind can't be used with .handlerdata directive"); 11553 UC.emitHandlerDataLocNotes(); 11554 return true; 11555 } 11556 if (UC.hasPersonality()) { 11557 Error(L, ".cantunwind can't be used with .personality directive"); 11558 UC.emitPersonalityLocNotes(); 11559 return true; 11560 } 11561 11562 getTargetStreamer().emitCantUnwind(); 11563 return false; 11564 } 11565 11566 /// parseDirectivePersonality 11567 /// ::= .personality name 11568 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) { 11569 MCAsmParser &Parser = getParser(); 11570 bool HasExistingPersonality = UC.hasPersonality(); 11571 11572 // Parse the name of the personality routine 11573 if (Parser.getTok().isNot(AsmToken::Identifier)) 11574 return Error(L, "unexpected input in .personality directive."); 11575 StringRef Name(Parser.getTok().getIdentifier()); 11576 Parser.Lex(); 11577 11578 if (parseEOL()) 11579 return true; 11580 11581 UC.recordPersonality(L); 11582 11583 // Check the ordering of unwind directives 11584 if (!UC.hasFnStart()) 11585 return Error(L, ".fnstart must precede .personality directive"); 11586 if (UC.cantUnwind()) { 11587 Error(L, ".personality can't be used with .cantunwind directive"); 11588 UC.emitCantUnwindLocNotes(); 11589 return true; 11590 } 11591 if (UC.hasHandlerData()) { 11592 Error(L, ".personality must precede .handlerdata directive"); 11593 UC.emitHandlerDataLocNotes(); 11594 return true; 11595 } 11596 if (HasExistingPersonality) { 11597 Error(L, "multiple personality directives"); 11598 UC.emitPersonalityLocNotes(); 11599 return true; 11600 } 11601 11602 MCSymbol *PR = getParser().getContext().getOrCreateSymbol(Name); 11603 getTargetStreamer().emitPersonality(PR); 11604 return false; 11605 } 11606 11607 /// parseDirectiveHandlerData 11608 /// ::= .handlerdata 11609 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) { 11610 if (parseEOL()) 11611 return true; 11612 11613 UC.recordHandlerData(L); 11614 // Check the ordering of unwind directives 11615 if (!UC.hasFnStart()) 11616 return Error(L, ".fnstart must precede .personality directive"); 11617 if (UC.cantUnwind()) { 11618 Error(L, ".handlerdata can't be used with .cantunwind directive"); 11619 UC.emitCantUnwindLocNotes(); 11620 return true; 11621 } 11622 11623 getTargetStreamer().emitHandlerData(); 11624 return false; 11625 } 11626 11627 /// parseDirectiveSetFP 11628 /// ::= .setfp fpreg, spreg [, offset] 11629 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) { 11630 MCAsmParser &Parser = getParser(); 11631 // Check the ordering of unwind directives 11632 if (check(!UC.hasFnStart(), L, ".fnstart must precede .setfp directive") || 11633 check(UC.hasHandlerData(), L, 11634 ".setfp must precede .handlerdata directive")) 11635 return true; 11636 11637 // Parse fpreg 11638 SMLoc FPRegLoc = Parser.getTok().getLoc(); 11639 int FPReg = tryParseRegister(); 11640 11641 if (check(FPReg == -1, FPRegLoc, "frame pointer register expected") || 11642 Parser.parseToken(AsmToken::Comma, "comma expected")) 11643 return true; 11644 11645 // Parse spreg 11646 SMLoc SPRegLoc = Parser.getTok().getLoc(); 11647 int SPReg = tryParseRegister(); 11648 if (check(SPReg == -1, SPRegLoc, "stack pointer register expected") || 11649 check(SPReg != ARM::SP && SPReg != UC.getFPReg(), SPRegLoc, 11650 "register should be either $sp or the latest fp register")) 11651 return true; 11652 11653 // Update the frame pointer register 11654 UC.saveFPReg(FPReg); 11655 11656 // Parse offset 11657 int64_t Offset = 0; 11658 if (Parser.parseOptionalToken(AsmToken::Comma)) { 11659 if (Parser.getTok().isNot(AsmToken::Hash) && 11660 Parser.getTok().isNot(AsmToken::Dollar)) 11661 return Error(Parser.getTok().getLoc(), "'#' expected"); 11662 Parser.Lex(); // skip hash token. 11663 11664 const MCExpr *OffsetExpr; 11665 SMLoc ExLoc = Parser.getTok().getLoc(); 11666 SMLoc EndLoc; 11667 if (getParser().parseExpression(OffsetExpr, EndLoc)) 11668 return Error(ExLoc, "malformed setfp offset"); 11669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 11670 if (check(!CE, ExLoc, "setfp offset must be an immediate")) 11671 return true; 11672 Offset = CE->getValue(); 11673 } 11674 11675 if (Parser.parseToken(AsmToken::EndOfStatement)) 11676 return true; 11677 11678 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg), 11679 static_cast<unsigned>(SPReg), Offset); 11680 return false; 11681 } 11682 11683 /// parseDirective 11684 /// ::= .pad offset 11685 bool ARMAsmParser::parseDirectivePad(SMLoc L) { 11686 MCAsmParser &Parser = getParser(); 11687 // Check the ordering of unwind directives 11688 if (!UC.hasFnStart()) 11689 return Error(L, ".fnstart must precede .pad directive"); 11690 if (UC.hasHandlerData()) 11691 return Error(L, ".pad must precede .handlerdata directive"); 11692 11693 // Parse the offset 11694 if (Parser.getTok().isNot(AsmToken::Hash) && 11695 Parser.getTok().isNot(AsmToken::Dollar)) 11696 return Error(Parser.getTok().getLoc(), "'#' expected"); 11697 Parser.Lex(); // skip hash token. 11698 11699 const MCExpr *OffsetExpr; 11700 SMLoc ExLoc = Parser.getTok().getLoc(); 11701 SMLoc EndLoc; 11702 if (getParser().parseExpression(OffsetExpr, EndLoc)) 11703 return Error(ExLoc, "malformed pad offset"); 11704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 11705 if (!CE) 11706 return Error(ExLoc, "pad offset must be an immediate"); 11707 11708 if (parseEOL()) 11709 return true; 11710 11711 getTargetStreamer().emitPad(CE->getValue()); 11712 return false; 11713 } 11714 11715 /// parseDirectiveRegSave 11716 /// ::= .save { registers } 11717 /// ::= .vsave { registers } 11718 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) { 11719 // Check the ordering of unwind directives 11720 if (!UC.hasFnStart()) 11721 return Error(L, ".fnstart must precede .save or .vsave directives"); 11722 if (UC.hasHandlerData()) 11723 return Error(L, ".save or .vsave must precede .handlerdata directive"); 11724 11725 // RAII object to make sure parsed operands are deleted. 11726 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands; 11727 11728 // Parse the register list 11729 if (parseRegisterList(Operands, true, true) || parseEOL()) 11730 return true; 11731 ARMOperand &Op = (ARMOperand &)*Operands[0]; 11732 if (!IsVector && !Op.isRegList()) 11733 return Error(L, ".save expects GPR registers"); 11734 if (IsVector && !Op.isDPRRegList()) 11735 return Error(L, ".vsave expects DPR registers"); 11736 11737 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector); 11738 return false; 11739 } 11740 11741 /// parseDirectiveInst 11742 /// ::= .inst opcode [, ...] 11743 /// ::= .inst.n opcode [, ...] 11744 /// ::= .inst.w opcode [, ...] 11745 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) { 11746 int Width = 4; 11747 11748 if (isThumb()) { 11749 switch (Suffix) { 11750 case 'n': 11751 Width = 2; 11752 break; 11753 case 'w': 11754 break; 11755 default: 11756 Width = 0; 11757 break; 11758 } 11759 } else { 11760 if (Suffix) 11761 return Error(Loc, "width suffixes are invalid in ARM mode"); 11762 } 11763 11764 auto parseOne = [&]() -> bool { 11765 const MCExpr *Expr; 11766 if (getParser().parseExpression(Expr)) 11767 return true; 11768 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr); 11769 if (!Value) { 11770 return Error(Loc, "expected constant expression"); 11771 } 11772 11773 char CurSuffix = Suffix; 11774 switch (Width) { 11775 case 2: 11776 if (Value->getValue() > 0xffff) 11777 return Error(Loc, "inst.n operand is too big, use inst.w instead"); 11778 break; 11779 case 4: 11780 if (Value->getValue() > 0xffffffff) 11781 return Error(Loc, StringRef(Suffix ? "inst.w" : "inst") + 11782 " operand is too big"); 11783 break; 11784 case 0: 11785 // Thumb mode, no width indicated. Guess from the opcode, if possible. 11786 if (Value->getValue() < 0xe800) 11787 CurSuffix = 'n'; 11788 else if (Value->getValue() >= 0xe8000000) 11789 CurSuffix = 'w'; 11790 else 11791 return Error(Loc, "cannot determine Thumb instruction size, " 11792 "use inst.n/inst.w instead"); 11793 break; 11794 default: 11795 llvm_unreachable("only supported widths are 2 and 4"); 11796 } 11797 11798 getTargetStreamer().emitInst(Value->getValue(), CurSuffix); 11799 return false; 11800 }; 11801 11802 if (parseOptionalToken(AsmToken::EndOfStatement)) 11803 return Error(Loc, "expected expression following directive"); 11804 if (parseMany(parseOne)) 11805 return true; 11806 return false; 11807 } 11808 11809 /// parseDirectiveLtorg 11810 /// ::= .ltorg | .pool 11811 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) { 11812 if (parseEOL()) 11813 return true; 11814 getTargetStreamer().emitCurrentConstantPool(); 11815 return false; 11816 } 11817 11818 bool ARMAsmParser::parseDirectiveEven(SMLoc L) { 11819 const MCSection *Section = getStreamer().getCurrentSectionOnly(); 11820 11821 if (parseEOL()) 11822 return true; 11823 11824 if (!Section) { 11825 getStreamer().initSections(false, getSTI()); 11826 Section = getStreamer().getCurrentSectionOnly(); 11827 } 11828 11829 assert(Section && "must have section to emit alignment"); 11830 if (Section->useCodeAlign()) 11831 getStreamer().emitCodeAlignment(2, &getSTI()); 11832 else 11833 getStreamer().emitValueToAlignment(2); 11834 11835 return false; 11836 } 11837 11838 /// parseDirectivePersonalityIndex 11839 /// ::= .personalityindex index 11840 bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) { 11841 MCAsmParser &Parser = getParser(); 11842 bool HasExistingPersonality = UC.hasPersonality(); 11843 11844 const MCExpr *IndexExpression; 11845 SMLoc IndexLoc = Parser.getTok().getLoc(); 11846 if (Parser.parseExpression(IndexExpression) || parseEOL()) { 11847 return true; 11848 } 11849 11850 UC.recordPersonalityIndex(L); 11851 11852 if (!UC.hasFnStart()) { 11853 return Error(L, ".fnstart must precede .personalityindex directive"); 11854 } 11855 if (UC.cantUnwind()) { 11856 Error(L, ".personalityindex cannot be used with .cantunwind"); 11857 UC.emitCantUnwindLocNotes(); 11858 return true; 11859 } 11860 if (UC.hasHandlerData()) { 11861 Error(L, ".personalityindex must precede .handlerdata directive"); 11862 UC.emitHandlerDataLocNotes(); 11863 return true; 11864 } 11865 if (HasExistingPersonality) { 11866 Error(L, "multiple personality directives"); 11867 UC.emitPersonalityLocNotes(); 11868 return true; 11869 } 11870 11871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression); 11872 if (!CE) 11873 return Error(IndexLoc, "index must be a constant number"); 11874 if (CE->getValue() < 0 || CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) 11875 return Error(IndexLoc, 11876 "personality routine index should be in range [0-3]"); 11877 11878 getTargetStreamer().emitPersonalityIndex(CE->getValue()); 11879 return false; 11880 } 11881 11882 /// parseDirectiveUnwindRaw 11883 /// ::= .unwind_raw offset, opcode [, opcode...] 11884 bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) { 11885 MCAsmParser &Parser = getParser(); 11886 int64_t StackOffset; 11887 const MCExpr *OffsetExpr; 11888 SMLoc OffsetLoc = getLexer().getLoc(); 11889 11890 if (!UC.hasFnStart()) 11891 return Error(L, ".fnstart must precede .unwind_raw directives"); 11892 if (getParser().parseExpression(OffsetExpr)) 11893 return Error(OffsetLoc, "expected expression"); 11894 11895 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 11896 if (!CE) 11897 return Error(OffsetLoc, "offset must be a constant"); 11898 11899 StackOffset = CE->getValue(); 11900 11901 if (Parser.parseToken(AsmToken::Comma, "expected comma")) 11902 return true; 11903 11904 SmallVector<uint8_t, 16> Opcodes; 11905 11906 auto parseOne = [&]() -> bool { 11907 const MCExpr *OE = nullptr; 11908 SMLoc OpcodeLoc = getLexer().getLoc(); 11909 if (check(getLexer().is(AsmToken::EndOfStatement) || 11910 Parser.parseExpression(OE), 11911 OpcodeLoc, "expected opcode expression")) 11912 return true; 11913 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE); 11914 if (!OC) 11915 return Error(OpcodeLoc, "opcode value must be a constant"); 11916 const int64_t Opcode = OC->getValue(); 11917 if (Opcode & ~0xff) 11918 return Error(OpcodeLoc, "invalid opcode"); 11919 Opcodes.push_back(uint8_t(Opcode)); 11920 return false; 11921 }; 11922 11923 // Must have at least 1 element 11924 SMLoc OpcodeLoc = getLexer().getLoc(); 11925 if (parseOptionalToken(AsmToken::EndOfStatement)) 11926 return Error(OpcodeLoc, "expected opcode expression"); 11927 if (parseMany(parseOne)) 11928 return true; 11929 11930 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes); 11931 return false; 11932 } 11933 11934 /// parseDirectiveTLSDescSeq 11935 /// ::= .tlsdescseq tls-variable 11936 bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) { 11937 MCAsmParser &Parser = getParser(); 11938 11939 if (getLexer().isNot(AsmToken::Identifier)) 11940 return TokError("expected variable after '.tlsdescseq' directive"); 11941 11942 const MCSymbolRefExpr *SRE = 11943 MCSymbolRefExpr::create(Parser.getTok().getIdentifier(), 11944 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext()); 11945 Lex(); 11946 11947 if (parseEOL()) 11948 return true; 11949 11950 getTargetStreamer().annotateTLSDescriptorSequence(SRE); 11951 return false; 11952 } 11953 11954 /// parseDirectiveMovSP 11955 /// ::= .movsp reg [, #offset] 11956 bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) { 11957 MCAsmParser &Parser = getParser(); 11958 if (!UC.hasFnStart()) 11959 return Error(L, ".fnstart must precede .movsp directives"); 11960 if (UC.getFPReg() != ARM::SP) 11961 return Error(L, "unexpected .movsp directive"); 11962 11963 SMLoc SPRegLoc = Parser.getTok().getLoc(); 11964 int SPReg = tryParseRegister(); 11965 if (SPReg == -1) 11966 return Error(SPRegLoc, "register expected"); 11967 if (SPReg == ARM::SP || SPReg == ARM::PC) 11968 return Error(SPRegLoc, "sp and pc are not permitted in .movsp directive"); 11969 11970 int64_t Offset = 0; 11971 if (Parser.parseOptionalToken(AsmToken::Comma)) { 11972 if (Parser.parseToken(AsmToken::Hash, "expected #constant")) 11973 return true; 11974 11975 const MCExpr *OffsetExpr; 11976 SMLoc OffsetLoc = Parser.getTok().getLoc(); 11977 11978 if (Parser.parseExpression(OffsetExpr)) 11979 return Error(OffsetLoc, "malformed offset expression"); 11980 11981 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 11982 if (!CE) 11983 return Error(OffsetLoc, "offset must be an immediate constant"); 11984 11985 Offset = CE->getValue(); 11986 } 11987 11988 if (parseEOL()) 11989 return true; 11990 11991 getTargetStreamer().emitMovSP(SPReg, Offset); 11992 UC.saveFPReg(SPReg); 11993 11994 return false; 11995 } 11996 11997 /// parseDirectiveObjectArch 11998 /// ::= .object_arch name 11999 bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) { 12000 MCAsmParser &Parser = getParser(); 12001 if (getLexer().isNot(AsmToken::Identifier)) 12002 return Error(getLexer().getLoc(), "unexpected token"); 12003 12004 StringRef Arch = Parser.getTok().getString(); 12005 SMLoc ArchLoc = Parser.getTok().getLoc(); 12006 Lex(); 12007 12008 ARM::ArchKind ID = ARM::parseArch(Arch); 12009 12010 if (ID == ARM::ArchKind::INVALID) 12011 return Error(ArchLoc, "unknown architecture '" + Arch + "'"); 12012 if (parseToken(AsmToken::EndOfStatement)) 12013 return true; 12014 12015 getTargetStreamer().emitObjectArch(ID); 12016 return false; 12017 } 12018 12019 /// parseDirectiveAlign 12020 /// ::= .align 12021 bool ARMAsmParser::parseDirectiveAlign(SMLoc L) { 12022 // NOTE: if this is not the end of the statement, fall back to the target 12023 // agnostic handling for this directive which will correctly handle this. 12024 if (parseOptionalToken(AsmToken::EndOfStatement)) { 12025 // '.align' is target specifically handled to mean 2**2 byte alignment. 12026 const MCSection *Section = getStreamer().getCurrentSectionOnly(); 12027 assert(Section && "must have section to emit alignment"); 12028 if (Section->useCodeAlign()) 12029 getStreamer().emitCodeAlignment(4, &getSTI(), 0); 12030 else 12031 getStreamer().emitValueToAlignment(4, 0, 1, 0); 12032 return false; 12033 } 12034 return true; 12035 } 12036 12037 /// parseDirectiveThumbSet 12038 /// ::= .thumb_set name, value 12039 bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) { 12040 MCAsmParser &Parser = getParser(); 12041 12042 StringRef Name; 12043 if (check(Parser.parseIdentifier(Name), 12044 "expected identifier after '.thumb_set'") || 12045 parseToken(AsmToken::Comma, "expected comma after name '" + Name + "'")) 12046 return true; 12047 12048 MCSymbol *Sym; 12049 const MCExpr *Value; 12050 if (MCParserUtils::parseAssignmentExpression(Name, /* allow_redef */ true, 12051 Parser, Sym, Value)) 12052 return true; 12053 12054 getTargetStreamer().emitThumbSet(Sym, Value); 12055 return false; 12056 } 12057 12058 /// parseDirectiveSEHAllocStack 12059 /// ::= .seh_stackalloc 12060 /// ::= .seh_stackalloc_w 12061 bool ARMAsmParser::parseDirectiveSEHAllocStack(SMLoc L, bool Wide) { 12062 int64_t Size; 12063 if (parseImmExpr(Size)) 12064 return true; 12065 getTargetStreamer().emitARMWinCFIAllocStack(Size, Wide); 12066 return false; 12067 } 12068 12069 /// parseDirectiveSEHSaveRegs 12070 /// ::= .seh_save_regs 12071 /// ::= .seh_save_regs_w 12072 bool ARMAsmParser::parseDirectiveSEHSaveRegs(SMLoc L, bool Wide) { 12073 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands; 12074 12075 if (parseRegisterList(Operands) || parseEOL()) 12076 return true; 12077 ARMOperand &Op = (ARMOperand &)*Operands[0]; 12078 if (!Op.isRegList()) 12079 return Error(L, ".seh_save_regs{_w} expects GPR registers"); 12080 const SmallVectorImpl<unsigned> &RegList = Op.getRegList(); 12081 uint32_t Mask = 0; 12082 for (size_t i = 0; i < RegList.size(); ++i) { 12083 unsigned Reg = MRI->getEncodingValue(RegList[i]); 12084 if (Reg == 15) // pc -> lr 12085 Reg = 14; 12086 if (Reg == 13) 12087 return Error(L, ".seh_save_regs{_w} can't include SP"); 12088 assert(Reg < 16U && "Register out of range"); 12089 unsigned Bit = (1u << Reg); 12090 Mask |= Bit; 12091 } 12092 if (!Wide && (Mask & 0x1f00) != 0) 12093 return Error(L, 12094 ".seh_save_regs cannot save R8-R12, needs .seh_save_regs_w"); 12095 getTargetStreamer().emitARMWinCFISaveRegMask(Mask, Wide); 12096 return false; 12097 } 12098 12099 /// parseDirectiveSEHSaveSP 12100 /// ::= .seh_save_sp 12101 bool ARMAsmParser::parseDirectiveSEHSaveSP(SMLoc L) { 12102 int Reg = tryParseRegister(); 12103 if (Reg == -1 || !MRI->getRegClass(ARM::GPRRegClassID).contains(Reg)) 12104 return Error(L, "expected GPR"); 12105 unsigned Index = MRI->getEncodingValue(Reg); 12106 if (Index > 14 || Index == 13) 12107 return Error(L, "invalid register for .seh_save_sp"); 12108 getTargetStreamer().emitARMWinCFISaveSP(Index); 12109 return false; 12110 } 12111 12112 /// parseDirectiveSEHSaveFRegs 12113 /// ::= .seh_save_fregs 12114 bool ARMAsmParser::parseDirectiveSEHSaveFRegs(SMLoc L) { 12115 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands; 12116 12117 if (parseRegisterList(Operands) || parseEOL()) 12118 return true; 12119 ARMOperand &Op = (ARMOperand &)*Operands[0]; 12120 if (!Op.isDPRRegList()) 12121 return Error(L, ".seh_save_fregs expects DPR registers"); 12122 const SmallVectorImpl<unsigned> &RegList = Op.getRegList(); 12123 uint32_t Mask = 0; 12124 for (size_t i = 0; i < RegList.size(); ++i) { 12125 unsigned Reg = MRI->getEncodingValue(RegList[i]); 12126 assert(Reg < 32U && "Register out of range"); 12127 unsigned Bit = (1u << Reg); 12128 Mask |= Bit; 12129 } 12130 12131 if (Mask == 0) 12132 return Error(L, ".seh_save_fregs missing registers"); 12133 12134 unsigned First = 0; 12135 while ((Mask & 1) == 0) { 12136 First++; 12137 Mask >>= 1; 12138 } 12139 if (((Mask + 1) & Mask) != 0) 12140 return Error(L, 12141 ".seh_save_fregs must take a contiguous range of registers"); 12142 unsigned Last = First; 12143 while ((Mask & 2) != 0) { 12144 Last++; 12145 Mask >>= 1; 12146 } 12147 if (First < 16 && Last >= 16) 12148 return Error(L, ".seh_save_fregs must be all d0-d15 or d16-d31"); 12149 getTargetStreamer().emitARMWinCFISaveFRegs(First, Last); 12150 return false; 12151 } 12152 12153 /// parseDirectiveSEHSaveLR 12154 /// ::= .seh_save_lr 12155 bool ARMAsmParser::parseDirectiveSEHSaveLR(SMLoc L) { 12156 int64_t Offset; 12157 if (parseImmExpr(Offset)) 12158 return true; 12159 getTargetStreamer().emitARMWinCFISaveLR(Offset); 12160 return false; 12161 } 12162 12163 /// parseDirectiveSEHPrologEnd 12164 /// ::= .seh_endprologue 12165 /// ::= .seh_endprologue_fragment 12166 bool ARMAsmParser::parseDirectiveSEHPrologEnd(SMLoc L, bool Fragment) { 12167 getTargetStreamer().emitARMWinCFIPrologEnd(Fragment); 12168 return false; 12169 } 12170 12171 /// parseDirectiveSEHNop 12172 /// ::= .seh_nop 12173 /// ::= .seh_nop_w 12174 bool ARMAsmParser::parseDirectiveSEHNop(SMLoc L, bool Wide) { 12175 getTargetStreamer().emitARMWinCFINop(Wide); 12176 return false; 12177 } 12178 12179 /// parseDirectiveSEHEpilogStart 12180 /// ::= .seh_startepilogue 12181 /// ::= .seh_startepilogue_cond 12182 bool ARMAsmParser::parseDirectiveSEHEpilogStart(SMLoc L, bool Condition) { 12183 unsigned CC = ARMCC::AL; 12184 if (Condition) { 12185 MCAsmParser &Parser = getParser(); 12186 SMLoc S = Parser.getTok().getLoc(); 12187 const AsmToken &Tok = Parser.getTok(); 12188 if (!Tok.is(AsmToken::Identifier)) 12189 return Error(S, ".seh_startepilogue_cond missing condition"); 12190 CC = ARMCondCodeFromString(Tok.getString()); 12191 if (CC == ~0U) 12192 return Error(S, "invalid condition"); 12193 Parser.Lex(); // Eat the token. 12194 } 12195 12196 getTargetStreamer().emitARMWinCFIEpilogStart(CC); 12197 return false; 12198 } 12199 12200 /// parseDirectiveSEHEpilogEnd 12201 /// ::= .seh_endepilogue 12202 bool ARMAsmParser::parseDirectiveSEHEpilogEnd(SMLoc L) { 12203 getTargetStreamer().emitARMWinCFIEpilogEnd(); 12204 return false; 12205 } 12206 12207 /// parseDirectiveSEHCustom 12208 /// ::= .seh_custom 12209 bool ARMAsmParser::parseDirectiveSEHCustom(SMLoc L) { 12210 unsigned Opcode = 0; 12211 do { 12212 int64_t Byte; 12213 if (parseImmExpr(Byte)) 12214 return true; 12215 if (Byte > 0xff || Byte < 0) 12216 return Error(L, "Invalid byte value in .seh_custom"); 12217 if (Opcode > 0x00ffffff) 12218 return Error(L, "Too many bytes in .seh_custom"); 12219 // Store the bytes as one big endian number in Opcode. In a multi byte 12220 // opcode sequence, the first byte can't be zero. 12221 Opcode = (Opcode << 8) | Byte; 12222 } while (parseOptionalToken(AsmToken::Comma)); 12223 getTargetStreamer().emitARMWinCFICustom(Opcode); 12224 return false; 12225 } 12226 12227 /// Force static initialization. 12228 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMAsmParser() { 12229 RegisterMCAsmParser<ARMAsmParser> X(getTheARMLETarget()); 12230 RegisterMCAsmParser<ARMAsmParser> Y(getTheARMBETarget()); 12231 RegisterMCAsmParser<ARMAsmParser> A(getTheThumbLETarget()); 12232 RegisterMCAsmParser<ARMAsmParser> B(getTheThumbBETarget()); 12233 } 12234 12235 #define GET_REGISTER_MATCHER 12236 #define GET_SUBTARGET_FEATURE_NAME 12237 #define GET_MATCHER_IMPLEMENTATION 12238 #define GET_MNEMONIC_SPELL_CHECKER 12239 #include "ARMGenAsmMatcher.inc" 12240 12241 // Some diagnostics need to vary with subtarget features, so they are handled 12242 // here. For example, the DPR class has either 16 or 32 registers, depending 12243 // on the FPU available. 12244 const char * 12245 ARMAsmParser::getCustomOperandDiag(ARMMatchResultTy MatchError) { 12246 switch (MatchError) { 12247 // rGPR contains sp starting with ARMv8. 12248 case Match_rGPR: 12249 return hasV8Ops() ? "operand must be a register in range [r0, r14]" 12250 : "operand must be a register in range [r0, r12] or r14"; 12251 // DPR contains 16 registers for some FPUs, and 32 for others. 12252 case Match_DPR: 12253 return hasD32() ? "operand must be a register in range [d0, d31]" 12254 : "operand must be a register in range [d0, d15]"; 12255 case Match_DPR_RegList: 12256 return hasD32() ? "operand must be a list of registers in range [d0, d31]" 12257 : "operand must be a list of registers in range [d0, d15]"; 12258 12259 // For all other diags, use the static string from tablegen. 12260 default: 12261 return getMatchKindDiag(MatchError); 12262 } 12263 } 12264 12265 // Process the list of near-misses, throwing away ones we don't want to report 12266 // to the user, and converting the rest to a source location and string that 12267 // should be reported. 12268 void 12269 ARMAsmParser::FilterNearMisses(SmallVectorImpl<NearMissInfo> &NearMissesIn, 12270 SmallVectorImpl<NearMissMessage> &NearMissesOut, 12271 SMLoc IDLoc, OperandVector &Operands) { 12272 // TODO: If operand didn't match, sub in a dummy one and run target 12273 // predicate, so that we can avoid reporting near-misses that are invalid? 12274 // TODO: Many operand types dont have SuperClasses set, so we report 12275 // redundant ones. 12276 // TODO: Some operands are superclasses of registers (e.g. 12277 // MCK_RegShiftedImm), we don't have any way to represent that currently. 12278 // TODO: This is not all ARM-specific, can some of it be factored out? 12279 12280 // Record some information about near-misses that we have already seen, so 12281 // that we can avoid reporting redundant ones. For example, if there are 12282 // variants of an instruction that take 8- and 16-bit immediates, we want 12283 // to only report the widest one. 12284 std::multimap<unsigned, unsigned> OperandMissesSeen; 12285 SmallSet<FeatureBitset, 4> FeatureMissesSeen; 12286 bool ReportedTooFewOperands = false; 12287 12288 // Process the near-misses in reverse order, so that we see more general ones 12289 // first, and so can avoid emitting more specific ones. 12290 for (NearMissInfo &I : reverse(NearMissesIn)) { 12291 switch (I.getKind()) { 12292 case NearMissInfo::NearMissOperand: { 12293 SMLoc OperandLoc = 12294 ((ARMOperand &)*Operands[I.getOperandIndex()]).getStartLoc(); 12295 const char *OperandDiag = 12296 getCustomOperandDiag((ARMMatchResultTy)I.getOperandError()); 12297 12298 // If we have already emitted a message for a superclass, don't also report 12299 // the sub-class. We consider all operand classes that we don't have a 12300 // specialised diagnostic for to be equal for the propose of this check, 12301 // so that we don't report the generic error multiple times on the same 12302 // operand. 12303 unsigned DupCheckMatchClass = OperandDiag ? I.getOperandClass() : ~0U; 12304 auto PrevReports = OperandMissesSeen.equal_range(I.getOperandIndex()); 12305 if (std::any_of(PrevReports.first, PrevReports.second, 12306 [DupCheckMatchClass]( 12307 const std::pair<unsigned, unsigned> Pair) { 12308 if (DupCheckMatchClass == ~0U || Pair.second == ~0U) 12309 return Pair.second == DupCheckMatchClass; 12310 else 12311 return isSubclass((MatchClassKind)DupCheckMatchClass, 12312 (MatchClassKind)Pair.second); 12313 })) 12314 break; 12315 OperandMissesSeen.insert( 12316 std::make_pair(I.getOperandIndex(), DupCheckMatchClass)); 12317 12318 NearMissMessage Message; 12319 Message.Loc = OperandLoc; 12320 if (OperandDiag) { 12321 Message.Message = OperandDiag; 12322 } else if (I.getOperandClass() == InvalidMatchClass) { 12323 Message.Message = "too many operands for instruction"; 12324 } else { 12325 Message.Message = "invalid operand for instruction"; 12326 LLVM_DEBUG( 12327 dbgs() << "Missing diagnostic string for operand class " 12328 << getMatchClassName((MatchClassKind)I.getOperandClass()) 12329 << I.getOperandClass() << ", error " << I.getOperandError() 12330 << ", opcode " << MII.getName(I.getOpcode()) << "\n"); 12331 } 12332 NearMissesOut.emplace_back(Message); 12333 break; 12334 } 12335 case NearMissInfo::NearMissFeature: { 12336 const FeatureBitset &MissingFeatures = I.getFeatures(); 12337 // Don't report the same set of features twice. 12338 if (FeatureMissesSeen.count(MissingFeatures)) 12339 break; 12340 FeatureMissesSeen.insert(MissingFeatures); 12341 12342 // Special case: don't report a feature set which includes arm-mode for 12343 // targets that don't have ARM mode. 12344 if (MissingFeatures.test(Feature_IsARMBit) && !hasARM()) 12345 break; 12346 // Don't report any near-misses that both require switching instruction 12347 // set, and adding other subtarget features. 12348 if (isThumb() && MissingFeatures.test(Feature_IsARMBit) && 12349 MissingFeatures.count() > 1) 12350 break; 12351 if (!isThumb() && MissingFeatures.test(Feature_IsThumbBit) && 12352 MissingFeatures.count() > 1) 12353 break; 12354 if (!isThumb() && MissingFeatures.test(Feature_IsThumb2Bit) && 12355 (MissingFeatures & ~FeatureBitset({Feature_IsThumb2Bit, 12356 Feature_IsThumbBit})).any()) 12357 break; 12358 if (isMClass() && MissingFeatures.test(Feature_HasNEONBit)) 12359 break; 12360 12361 NearMissMessage Message; 12362 Message.Loc = IDLoc; 12363 raw_svector_ostream OS(Message.Message); 12364 12365 OS << "instruction requires:"; 12366 for (unsigned i = 0, e = MissingFeatures.size(); i != e; ++i) 12367 if (MissingFeatures.test(i)) 12368 OS << ' ' << getSubtargetFeatureName(i); 12369 12370 NearMissesOut.emplace_back(Message); 12371 12372 break; 12373 } 12374 case NearMissInfo::NearMissPredicate: { 12375 NearMissMessage Message; 12376 Message.Loc = IDLoc; 12377 switch (I.getPredicateError()) { 12378 case Match_RequiresNotITBlock: 12379 Message.Message = "flag setting instruction only valid outside IT block"; 12380 break; 12381 case Match_RequiresITBlock: 12382 Message.Message = "instruction only valid inside IT block"; 12383 break; 12384 case Match_RequiresV6: 12385 Message.Message = "instruction variant requires ARMv6 or later"; 12386 break; 12387 case Match_RequiresThumb2: 12388 Message.Message = "instruction variant requires Thumb2"; 12389 break; 12390 case Match_RequiresV8: 12391 Message.Message = "instruction variant requires ARMv8 or later"; 12392 break; 12393 case Match_RequiresFlagSetting: 12394 Message.Message = "no flag-preserving variant of this instruction available"; 12395 break; 12396 case Match_InvalidOperand: 12397 Message.Message = "invalid operand for instruction"; 12398 break; 12399 default: 12400 llvm_unreachable("Unhandled target predicate error"); 12401 break; 12402 } 12403 NearMissesOut.emplace_back(Message); 12404 break; 12405 } 12406 case NearMissInfo::NearMissTooFewOperands: { 12407 if (!ReportedTooFewOperands) { 12408 SMLoc EndLoc = ((ARMOperand &)*Operands.back()).getEndLoc(); 12409 NearMissesOut.emplace_back(NearMissMessage{ 12410 EndLoc, StringRef("too few operands for instruction")}); 12411 ReportedTooFewOperands = true; 12412 } 12413 break; 12414 } 12415 case NearMissInfo::NoNearMiss: 12416 // This should never leave the matcher. 12417 llvm_unreachable("not a near-miss"); 12418 break; 12419 } 12420 } 12421 } 12422 12423 void ARMAsmParser::ReportNearMisses(SmallVectorImpl<NearMissInfo> &NearMisses, 12424 SMLoc IDLoc, OperandVector &Operands) { 12425 SmallVector<NearMissMessage, 4> Messages; 12426 FilterNearMisses(NearMisses, Messages, IDLoc, Operands); 12427 12428 if (Messages.size() == 0) { 12429 // No near-misses were found, so the best we can do is "invalid 12430 // instruction". 12431 Error(IDLoc, "invalid instruction"); 12432 } else if (Messages.size() == 1) { 12433 // One near miss was found, report it as the sole error. 12434 Error(Messages[0].Loc, Messages[0].Message); 12435 } else { 12436 // More than one near miss, so report a generic "invalid instruction" 12437 // error, followed by notes for each of the near-misses. 12438 Error(IDLoc, "invalid instruction, any one of the following would fix this:"); 12439 for (auto &M : Messages) { 12440 Note(M.Loc, M.Message); 12441 } 12442 } 12443 } 12444 12445 bool ARMAsmParser::enableArchExtFeature(StringRef Name, SMLoc &ExtLoc) { 12446 // FIXME: This structure should be moved inside ARMTargetParser 12447 // when we start to table-generate them, and we can use the ARM 12448 // flags below, that were generated by table-gen. 12449 static const struct { 12450 const uint64_t Kind; 12451 const FeatureBitset ArchCheck; 12452 const FeatureBitset Features; 12453 } Extensions[] = { 12454 {ARM::AEK_CRC, {Feature_HasV8Bit}, {ARM::FeatureCRC}}, 12455 {ARM::AEK_AES, 12456 {Feature_HasV8Bit}, 12457 {ARM::FeatureAES, ARM::FeatureNEON, ARM::FeatureFPARMv8}}, 12458 {ARM::AEK_SHA2, 12459 {Feature_HasV8Bit}, 12460 {ARM::FeatureSHA2, ARM::FeatureNEON, ARM::FeatureFPARMv8}}, 12461 {ARM::AEK_CRYPTO, 12462 {Feature_HasV8Bit}, 12463 {ARM::FeatureCrypto, ARM::FeatureNEON, ARM::FeatureFPARMv8}}, 12464 {ARM::AEK_FP, 12465 {Feature_HasV8Bit}, 12466 {ARM::FeatureVFP2_SP, ARM::FeatureFPARMv8}}, 12467 {(ARM::AEK_HWDIVTHUMB | ARM::AEK_HWDIVARM), 12468 {Feature_HasV7Bit, Feature_IsNotMClassBit}, 12469 {ARM::FeatureHWDivThumb, ARM::FeatureHWDivARM}}, 12470 {ARM::AEK_MP, 12471 {Feature_HasV7Bit, Feature_IsNotMClassBit}, 12472 {ARM::FeatureMP}}, 12473 {ARM::AEK_SIMD, 12474 {Feature_HasV8Bit}, 12475 {ARM::FeatureNEON, ARM::FeatureVFP2_SP, ARM::FeatureFPARMv8}}, 12476 {ARM::AEK_SEC, {Feature_HasV6KBit}, {ARM::FeatureTrustZone}}, 12477 // FIXME: Only available in A-class, isel not predicated 12478 {ARM::AEK_VIRT, {Feature_HasV7Bit}, {ARM::FeatureVirtualization}}, 12479 {ARM::AEK_FP16, 12480 {Feature_HasV8_2aBit}, 12481 {ARM::FeatureFPARMv8, ARM::FeatureFullFP16}}, 12482 {ARM::AEK_RAS, {Feature_HasV8Bit}, {ARM::FeatureRAS}}, 12483 {ARM::AEK_LOB, {Feature_HasV8_1MMainlineBit}, {ARM::FeatureLOB}}, 12484 {ARM::AEK_PACBTI, {Feature_HasV8_1MMainlineBit}, {ARM::FeaturePACBTI}}, 12485 // FIXME: Unsupported extensions. 12486 {ARM::AEK_OS, {}, {}}, 12487 {ARM::AEK_IWMMXT, {}, {}}, 12488 {ARM::AEK_IWMMXT2, {}, {}}, 12489 {ARM::AEK_MAVERICK, {}, {}}, 12490 {ARM::AEK_XSCALE, {}, {}}, 12491 }; 12492 bool EnableFeature = true; 12493 if (Name.startswith_insensitive("no")) { 12494 EnableFeature = false; 12495 Name = Name.substr(2); 12496 } 12497 uint64_t FeatureKind = ARM::parseArchExt(Name); 12498 if (FeatureKind == ARM::AEK_INVALID) 12499 return Error(ExtLoc, "unknown architectural extension: " + Name); 12500 12501 for (const auto &Extension : Extensions) { 12502 if (Extension.Kind != FeatureKind) 12503 continue; 12504 12505 if (Extension.Features.none()) 12506 return Error(ExtLoc, "unsupported architectural extension: " + Name); 12507 12508 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) 12509 return Error(ExtLoc, "architectural extension '" + Name + 12510 "' is not " 12511 "allowed for the current base architecture"); 12512 12513 MCSubtargetInfo &STI = copySTI(); 12514 if (EnableFeature) { 12515 STI.SetFeatureBitsTransitively(Extension.Features); 12516 } else { 12517 STI.ClearFeatureBitsTransitively(Extension.Features); 12518 } 12519 FeatureBitset Features = ComputeAvailableFeatures(STI.getFeatureBits()); 12520 setAvailableFeatures(Features); 12521 return true; 12522 } 12523 return false; 12524 } 12525 12526 /// parseDirectiveArchExtension 12527 /// ::= .arch_extension [no]feature 12528 bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) { 12529 12530 MCAsmParser &Parser = getParser(); 12531 12532 if (getLexer().isNot(AsmToken::Identifier)) 12533 return Error(getLexer().getLoc(), "expected architecture extension name"); 12534 12535 StringRef Name = Parser.getTok().getString(); 12536 SMLoc ExtLoc = Parser.getTok().getLoc(); 12537 Lex(); 12538 12539 if (parseEOL()) 12540 return true; 12541 12542 if (Name == "nocrypto") { 12543 enableArchExtFeature("nosha2", ExtLoc); 12544 enableArchExtFeature("noaes", ExtLoc); 12545 } 12546 12547 if (enableArchExtFeature(Name, ExtLoc)) 12548 return false; 12549 12550 return Error(ExtLoc, "unknown architectural extension: " + Name); 12551 } 12552 12553 // Define this matcher function after the auto-generated include so we 12554 // have the match class enum definitions. 12555 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp, 12556 unsigned Kind) { 12557 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp); 12558 // If the kind is a token for a literal immediate, check if our asm 12559 // operand matches. This is for InstAliases which have a fixed-value 12560 // immediate in the syntax. 12561 switch (Kind) { 12562 default: break; 12563 case MCK__HASH_0: 12564 if (Op.isImm()) 12565 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm())) 12566 if (CE->getValue() == 0) 12567 return Match_Success; 12568 break; 12569 case MCK__HASH_8: 12570 if (Op.isImm()) 12571 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm())) 12572 if (CE->getValue() == 8) 12573 return Match_Success; 12574 break; 12575 case MCK__HASH_16: 12576 if (Op.isImm()) 12577 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm())) 12578 if (CE->getValue() == 16) 12579 return Match_Success; 12580 break; 12581 case MCK_ModImm: 12582 if (Op.isImm()) { 12583 const MCExpr *SOExpr = Op.getImm(); 12584 int64_t Value; 12585 if (!SOExpr->evaluateAsAbsolute(Value)) 12586 return Match_Success; 12587 assert((Value >= std::numeric_limits<int32_t>::min() && 12588 Value <= std::numeric_limits<uint32_t>::max()) && 12589 "expression value must be representable in 32 bits"); 12590 } 12591 break; 12592 case MCK_rGPR: 12593 if (hasV8Ops() && Op.isReg() && Op.getReg() == ARM::SP) 12594 return Match_Success; 12595 return Match_rGPR; 12596 case MCK_GPRPair: 12597 if (Op.isReg() && 12598 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg())) 12599 return Match_Success; 12600 break; 12601 } 12602 return Match_InvalidOperand; 12603 } 12604 12605 bool ARMAsmParser::isMnemonicVPTPredicable(StringRef Mnemonic, 12606 StringRef ExtraToken) { 12607 if (!hasMVE()) 12608 return false; 12609 12610 return Mnemonic.startswith("vabav") || Mnemonic.startswith("vaddv") || 12611 Mnemonic.startswith("vaddlv") || Mnemonic.startswith("vminnmv") || 12612 Mnemonic.startswith("vminnmav") || Mnemonic.startswith("vminv") || 12613 Mnemonic.startswith("vminav") || Mnemonic.startswith("vmaxnmv") || 12614 Mnemonic.startswith("vmaxnmav") || Mnemonic.startswith("vmaxv") || 12615 Mnemonic.startswith("vmaxav") || Mnemonic.startswith("vmladav") || 12616 Mnemonic.startswith("vrmlaldavh") || Mnemonic.startswith("vrmlalvh") || 12617 Mnemonic.startswith("vmlsdav") || Mnemonic.startswith("vmlav") || 12618 Mnemonic.startswith("vmlaldav") || Mnemonic.startswith("vmlalv") || 12619 Mnemonic.startswith("vmaxnm") || Mnemonic.startswith("vminnm") || 12620 Mnemonic.startswith("vmax") || Mnemonic.startswith("vmin") || 12621 Mnemonic.startswith("vshlc") || Mnemonic.startswith("vmovlt") || 12622 Mnemonic.startswith("vmovlb") || Mnemonic.startswith("vshll") || 12623 Mnemonic.startswith("vrshrn") || Mnemonic.startswith("vshrn") || 12624 Mnemonic.startswith("vqrshrun") || Mnemonic.startswith("vqshrun") || 12625 Mnemonic.startswith("vqrshrn") || Mnemonic.startswith("vqshrn") || 12626 Mnemonic.startswith("vbic") || Mnemonic.startswith("vrev64") || 12627 Mnemonic.startswith("vrev32") || Mnemonic.startswith("vrev16") || 12628 Mnemonic.startswith("vmvn") || Mnemonic.startswith("veor") || 12629 Mnemonic.startswith("vorn") || Mnemonic.startswith("vorr") || 12630 Mnemonic.startswith("vand") || Mnemonic.startswith("vmul") || 12631 Mnemonic.startswith("vqrdmulh") || Mnemonic.startswith("vqdmulh") || 12632 Mnemonic.startswith("vsub") || Mnemonic.startswith("vadd") || 12633 Mnemonic.startswith("vqsub") || Mnemonic.startswith("vqadd") || 12634 Mnemonic.startswith("vabd") || Mnemonic.startswith("vrhadd") || 12635 Mnemonic.startswith("vhsub") || Mnemonic.startswith("vhadd") || 12636 Mnemonic.startswith("vdup") || Mnemonic.startswith("vcls") || 12637 Mnemonic.startswith("vclz") || Mnemonic.startswith("vneg") || 12638 Mnemonic.startswith("vabs") || Mnemonic.startswith("vqneg") || 12639 Mnemonic.startswith("vqabs") || 12640 (Mnemonic.startswith("vrint") && Mnemonic != "vrintr") || 12641 Mnemonic.startswith("vcmla") || Mnemonic.startswith("vfma") || 12642 Mnemonic.startswith("vfms") || Mnemonic.startswith("vcadd") || 12643 Mnemonic.startswith("vadd") || Mnemonic.startswith("vsub") || 12644 Mnemonic.startswith("vshl") || Mnemonic.startswith("vqshl") || 12645 Mnemonic.startswith("vqrshl") || Mnemonic.startswith("vrshl") || 12646 Mnemonic.startswith("vsri") || Mnemonic.startswith("vsli") || 12647 Mnemonic.startswith("vrshr") || Mnemonic.startswith("vshr") || 12648 Mnemonic.startswith("vpsel") || Mnemonic.startswith("vcmp") || 12649 Mnemonic.startswith("vqdmladh") || Mnemonic.startswith("vqrdmladh") || 12650 Mnemonic.startswith("vqdmlsdh") || Mnemonic.startswith("vqrdmlsdh") || 12651 Mnemonic.startswith("vcmul") || Mnemonic.startswith("vrmulh") || 12652 Mnemonic.startswith("vqmovn") || Mnemonic.startswith("vqmovun") || 12653 Mnemonic.startswith("vmovnt") || Mnemonic.startswith("vmovnb") || 12654 Mnemonic.startswith("vmaxa") || Mnemonic.startswith("vmaxnma") || 12655 Mnemonic.startswith("vhcadd") || Mnemonic.startswith("vadc") || 12656 Mnemonic.startswith("vsbc") || Mnemonic.startswith("vrshr") || 12657 Mnemonic.startswith("vshr") || Mnemonic.startswith("vstrb") || 12658 Mnemonic.startswith("vldrb") || 12659 (Mnemonic.startswith("vstrh") && Mnemonic != "vstrhi") || 12660 (Mnemonic.startswith("vldrh") && Mnemonic != "vldrhi") || 12661 Mnemonic.startswith("vstrw") || Mnemonic.startswith("vldrw") || 12662 Mnemonic.startswith("vldrd") || Mnemonic.startswith("vstrd") || 12663 Mnemonic.startswith("vqdmull") || Mnemonic.startswith("vbrsr") || 12664 Mnemonic.startswith("vfmas") || Mnemonic.startswith("vmlas") || 12665 Mnemonic.startswith("vmla") || Mnemonic.startswith("vqdmlash") || 12666 Mnemonic.startswith("vqdmlah") || Mnemonic.startswith("vqrdmlash") || 12667 Mnemonic.startswith("vqrdmlah") || Mnemonic.startswith("viwdup") || 12668 Mnemonic.startswith("vdwdup") || Mnemonic.startswith("vidup") || 12669 Mnemonic.startswith("vddup") || Mnemonic.startswith("vctp") || 12670 Mnemonic.startswith("vpnot") || Mnemonic.startswith("vbic") || 12671 Mnemonic.startswith("vrmlsldavh") || Mnemonic.startswith("vmlsldav") || 12672 Mnemonic.startswith("vcvt") || 12673 MS.isVPTPredicableCDEInstr(Mnemonic) || 12674 (Mnemonic.startswith("vmov") && 12675 !(ExtraToken == ".f16" || ExtraToken == ".32" || 12676 ExtraToken == ".16" || ExtraToken == ".8")); 12677 } 12678