1 //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "ARMFeatures.h" 11 #include "MCTargetDesc/ARMAddressingModes.h" 12 #include "MCTargetDesc/ARMBaseInfo.h" 13 #include "MCTargetDesc/ARMMCExpr.h" 14 #include "llvm/ADT/STLExtras.h" 15 #include "llvm/ADT/SmallVector.h" 16 #include "llvm/ADT/StringExtras.h" 17 #include "llvm/ADT/StringSwitch.h" 18 #include "llvm/ADT/Triple.h" 19 #include "llvm/ADT/Twine.h" 20 #include "llvm/MC/MCAsmInfo.h" 21 #include "llvm/MC/MCAssembler.h" 22 #include "llvm/MC/MCContext.h" 23 #include "llvm/MC/MCDisassembler/MCDisassembler.h" 24 #include "llvm/MC/MCELFStreamer.h" 25 #include "llvm/MC/MCExpr.h" 26 #include "llvm/MC/MCInst.h" 27 #include "llvm/MC/MCInstrDesc.h" 28 #include "llvm/MC/MCInstrInfo.h" 29 #include "llvm/MC/MCObjectFileInfo.h" 30 #include "llvm/MC/MCParser/MCAsmLexer.h" 31 #include "llvm/MC/MCParser/MCAsmParser.h" 32 #include "llvm/MC/MCParser/MCAsmParserUtils.h" 33 #include "llvm/MC/MCParser/MCParsedAsmOperand.h" 34 #include "llvm/MC/MCParser/MCTargetAsmParser.h" 35 #include "llvm/MC/MCRegisterInfo.h" 36 #include "llvm/MC/MCSection.h" 37 #include "llvm/MC/MCStreamer.h" 38 #include "llvm/MC/MCSubtargetInfo.h" 39 #include "llvm/MC/MCSymbol.h" 40 #include "llvm/Support/ARMBuildAttributes.h" 41 #include "llvm/Support/ARMEHABI.h" 42 #include "llvm/Support/COFF.h" 43 #include "llvm/Support/Debug.h" 44 #include "llvm/Support/ELF.h" 45 #include "llvm/Support/MathExtras.h" 46 #include "llvm/Support/SourceMgr.h" 47 #include "llvm/Support/TargetParser.h" 48 #include "llvm/Support/TargetRegistry.h" 49 #include "llvm/Support/raw_ostream.h" 50 51 using namespace llvm; 52 53 namespace { 54 55 class ARMOperand; 56 57 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane }; 58 59 class UnwindContext { 60 MCAsmParser &Parser; 61 62 typedef SmallVector<SMLoc, 4> Locs; 63 64 Locs FnStartLocs; 65 Locs CantUnwindLocs; 66 Locs PersonalityLocs; 67 Locs PersonalityIndexLocs; 68 Locs HandlerDataLocs; 69 int FPReg; 70 71 public: 72 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {} 73 74 bool hasFnStart() const { return !FnStartLocs.empty(); } 75 bool cantUnwind() const { return !CantUnwindLocs.empty(); } 76 bool hasHandlerData() const { return !HandlerDataLocs.empty(); } 77 bool hasPersonality() const { 78 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty()); 79 } 80 81 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); } 82 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); } 83 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); } 84 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); } 85 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); } 86 87 void saveFPReg(int Reg) { FPReg = Reg; } 88 int getFPReg() const { return FPReg; } 89 90 void emitFnStartLocNotes() const { 91 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end(); 92 FI != FE; ++FI) 93 Parser.Note(*FI, ".fnstart was specified here"); 94 } 95 void emitCantUnwindLocNotes() const { 96 for (Locs::const_iterator UI = CantUnwindLocs.begin(), 97 UE = CantUnwindLocs.end(); UI != UE; ++UI) 98 Parser.Note(*UI, ".cantunwind was specified here"); 99 } 100 void emitHandlerDataLocNotes() const { 101 for (Locs::const_iterator HI = HandlerDataLocs.begin(), 102 HE = HandlerDataLocs.end(); HI != HE; ++HI) 103 Parser.Note(*HI, ".handlerdata was specified here"); 104 } 105 void emitPersonalityLocNotes() const { 106 for (Locs::const_iterator PI = PersonalityLocs.begin(), 107 PE = PersonalityLocs.end(), 108 PII = PersonalityIndexLocs.begin(), 109 PIE = PersonalityIndexLocs.end(); 110 PI != PE || PII != PIE;) { 111 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer())) 112 Parser.Note(*PI++, ".personality was specified here"); 113 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer())) 114 Parser.Note(*PII++, ".personalityindex was specified here"); 115 else 116 llvm_unreachable(".personality and .personalityindex cannot be " 117 "at the same location"); 118 } 119 } 120 121 void reset() { 122 FnStartLocs = Locs(); 123 CantUnwindLocs = Locs(); 124 PersonalityLocs = Locs(); 125 HandlerDataLocs = Locs(); 126 PersonalityIndexLocs = Locs(); 127 FPReg = ARM::SP; 128 } 129 }; 130 131 class ARMAsmParser : public MCTargetAsmParser { 132 const MCInstrInfo &MII; 133 const MCRegisterInfo *MRI; 134 UnwindContext UC; 135 136 ARMTargetStreamer &getTargetStreamer() { 137 assert(getParser().getStreamer().getTargetStreamer() && 138 "do not have a target streamer"); 139 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer(); 140 return static_cast<ARMTargetStreamer &>(TS); 141 } 142 143 // Map of register aliases registers via the .req directive. 144 StringMap<unsigned> RegisterReqs; 145 146 bool NextSymbolIsThumb; 147 148 struct { 149 ARMCC::CondCodes Cond; // Condition for IT block. 150 unsigned Mask:4; // Condition mask for instructions. 151 // Starting at first 1 (from lsb). 152 // '1' condition as indicated in IT. 153 // '0' inverse of condition (else). 154 // Count of instructions in IT block is 155 // 4 - trailingzeroes(mask) 156 157 bool FirstCond; // Explicit flag for when we're parsing the 158 // First instruction in the IT block. It's 159 // implied in the mask, so needs special 160 // handling. 161 162 unsigned CurPosition; // Current position in parsing of IT 163 // block. In range [0,3]. Initialized 164 // according to count of instructions in block. 165 // ~0U if no active IT block. 166 } ITState; 167 bool inITBlock() { return ITState.CurPosition != ~0U; } 168 bool lastInITBlock() { 169 return ITState.CurPosition == 4 - countTrailingZeros(ITState.Mask); 170 } 171 void forwardITPosition() { 172 if (!inITBlock()) return; 173 // Move to the next instruction in the IT block, if there is one. If not, 174 // mark the block as done. 175 unsigned TZ = countTrailingZeros(ITState.Mask); 176 if (++ITState.CurPosition == 5 - TZ) 177 ITState.CurPosition = ~0U; // Done with the IT block after this. 178 } 179 180 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) { 181 return getParser().Note(L, Msg, Ranges); 182 } 183 bool Warning(SMLoc L, const Twine &Msg, 184 ArrayRef<SMRange> Ranges = None) { 185 return getParser().Warning(L, Msg, Ranges); 186 } 187 bool Error(SMLoc L, const Twine &Msg, 188 ArrayRef<SMRange> Ranges = None) { 189 return getParser().Error(L, Msg, Ranges); 190 } 191 192 bool validatetLDMRegList(const MCInst &Inst, const OperandVector &Operands, 193 unsigned ListNo, bool IsARPop = false); 194 bool validatetSTMRegList(const MCInst &Inst, const OperandVector &Operands, 195 unsigned ListNo); 196 197 int tryParseRegister(); 198 bool tryParseRegisterWithWriteBack(OperandVector &); 199 int tryParseShiftRegister(OperandVector &); 200 bool parseRegisterList(OperandVector &); 201 bool parseMemory(OperandVector &); 202 bool parseOperand(OperandVector &, StringRef Mnemonic); 203 bool parsePrefix(ARMMCExpr::VariantKind &RefKind); 204 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType, 205 unsigned &ShiftAmount); 206 bool parseLiteralValues(unsigned Size, SMLoc L); 207 bool parseDirectiveThumb(SMLoc L); 208 bool parseDirectiveARM(SMLoc L); 209 bool parseDirectiveThumbFunc(SMLoc L); 210 bool parseDirectiveCode(SMLoc L); 211 bool parseDirectiveSyntax(SMLoc L); 212 bool parseDirectiveReq(StringRef Name, SMLoc L); 213 bool parseDirectiveUnreq(SMLoc L); 214 bool parseDirectiveArch(SMLoc L); 215 bool parseDirectiveEabiAttr(SMLoc L); 216 bool parseDirectiveCPU(SMLoc L); 217 bool parseDirectiveFPU(SMLoc L); 218 bool parseDirectiveFnStart(SMLoc L); 219 bool parseDirectiveFnEnd(SMLoc L); 220 bool parseDirectiveCantUnwind(SMLoc L); 221 bool parseDirectivePersonality(SMLoc L); 222 bool parseDirectiveHandlerData(SMLoc L); 223 bool parseDirectiveSetFP(SMLoc L); 224 bool parseDirectivePad(SMLoc L); 225 bool parseDirectiveRegSave(SMLoc L, bool IsVector); 226 bool parseDirectiveInst(SMLoc L, char Suffix = '\0'); 227 bool parseDirectiveLtorg(SMLoc L); 228 bool parseDirectiveEven(SMLoc L); 229 bool parseDirectivePersonalityIndex(SMLoc L); 230 bool parseDirectiveUnwindRaw(SMLoc L); 231 bool parseDirectiveTLSDescSeq(SMLoc L); 232 bool parseDirectiveMovSP(SMLoc L); 233 bool parseDirectiveObjectArch(SMLoc L); 234 bool parseDirectiveArchExtension(SMLoc L); 235 bool parseDirectiveAlign(SMLoc L); 236 bool parseDirectiveThumbSet(SMLoc L); 237 238 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode, 239 bool &CarrySetting, unsigned &ProcessorIMod, 240 StringRef &ITMask); 241 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, 242 bool &CanAcceptCarrySet, 243 bool &CanAcceptPredicationCode); 244 245 void tryConvertingToTwoOperandForm(StringRef Mnemonic, bool CarrySetting, 246 OperandVector &Operands); 247 bool isThumb() const { 248 // FIXME: Can tablegen auto-generate this? 249 return getSTI().getFeatureBits()[ARM::ModeThumb]; 250 } 251 bool isThumbOne() const { 252 return isThumb() && !getSTI().getFeatureBits()[ARM::FeatureThumb2]; 253 } 254 bool isThumbTwo() const { 255 return isThumb() && getSTI().getFeatureBits()[ARM::FeatureThumb2]; 256 } 257 bool hasThumb() const { 258 return getSTI().getFeatureBits()[ARM::HasV4TOps]; 259 } 260 bool hasV6Ops() const { 261 return getSTI().getFeatureBits()[ARM::HasV6Ops]; 262 } 263 bool hasV6MOps() const { 264 return getSTI().getFeatureBits()[ARM::HasV6MOps]; 265 } 266 bool hasV7Ops() const { 267 return getSTI().getFeatureBits()[ARM::HasV7Ops]; 268 } 269 bool hasV8Ops() const { 270 return getSTI().getFeatureBits()[ARM::HasV8Ops]; 271 } 272 bool hasV8MBaseline() const { 273 return getSTI().getFeatureBits()[ARM::HasV8MBaselineOps]; 274 } 275 bool hasV8MMainline() const { 276 return getSTI().getFeatureBits()[ARM::HasV8MMainlineOps]; 277 } 278 bool has8MSecExt() const { 279 return getSTI().getFeatureBits()[ARM::Feature8MSecExt]; 280 } 281 bool hasARM() const { 282 return !getSTI().getFeatureBits()[ARM::FeatureNoARM]; 283 } 284 bool hasDSP() const { 285 return getSTI().getFeatureBits()[ARM::FeatureDSP]; 286 } 287 bool hasD16() const { 288 return getSTI().getFeatureBits()[ARM::FeatureD16]; 289 } 290 bool hasV8_1aOps() const { 291 return getSTI().getFeatureBits()[ARM::HasV8_1aOps]; 292 } 293 294 void SwitchMode() { 295 MCSubtargetInfo &STI = copySTI(); 296 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb)); 297 setAvailableFeatures(FB); 298 } 299 bool isMClass() const { 300 return getSTI().getFeatureBits()[ARM::FeatureMClass]; 301 } 302 303 /// @name Auto-generated Match Functions 304 /// { 305 306 #define GET_ASSEMBLER_HEADER 307 #include "ARMGenAsmMatcher.inc" 308 309 /// } 310 311 OperandMatchResultTy parseITCondCode(OperandVector &); 312 OperandMatchResultTy parseCoprocNumOperand(OperandVector &); 313 OperandMatchResultTy parseCoprocRegOperand(OperandVector &); 314 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &); 315 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &); 316 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &); 317 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &); 318 OperandMatchResultTy parseMSRMaskOperand(OperandVector &); 319 OperandMatchResultTy parseBankedRegOperand(OperandVector &); 320 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low, 321 int High); 322 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) { 323 return parsePKHImm(O, "lsl", 0, 31); 324 } 325 OperandMatchResultTy parsePKHASRImm(OperandVector &O) { 326 return parsePKHImm(O, "asr", 1, 32); 327 } 328 OperandMatchResultTy parseSetEndImm(OperandVector &); 329 OperandMatchResultTy parseShifterImm(OperandVector &); 330 OperandMatchResultTy parseRotImm(OperandVector &); 331 OperandMatchResultTy parseModImm(OperandVector &); 332 OperandMatchResultTy parseBitfield(OperandVector &); 333 OperandMatchResultTy parsePostIdxReg(OperandVector &); 334 OperandMatchResultTy parseAM3Offset(OperandVector &); 335 OperandMatchResultTy parseFPImm(OperandVector &); 336 OperandMatchResultTy parseVectorList(OperandVector &); 337 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, 338 SMLoc &EndLoc); 339 340 // Asm Match Converter Methods 341 void cvtThumbMultiply(MCInst &Inst, const OperandVector &); 342 void cvtThumbBranches(MCInst &Inst, const OperandVector &); 343 344 bool validateInstruction(MCInst &Inst, const OperandVector &Ops); 345 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out); 346 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands); 347 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands); 348 349 public: 350 enum ARMMatchResultTy { 351 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY, 352 Match_RequiresNotITBlock, 353 Match_RequiresV6, 354 Match_RequiresThumb2, 355 Match_RequiresV8, 356 #define GET_OPERAND_DIAGNOSTIC_TYPES 357 #include "ARMGenAsmMatcher.inc" 358 359 }; 360 361 ARMAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, 362 const MCInstrInfo &MII, const MCTargetOptions &Options) 363 : MCTargetAsmParser(Options, STI), MII(MII), UC(Parser) { 364 MCAsmParserExtension::Initialize(Parser); 365 366 // Cache the MCRegisterInfo. 367 MRI = getContext().getRegisterInfo(); 368 369 // Initialize the set of available features. 370 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 371 372 // Not in an ITBlock to start with. 373 ITState.CurPosition = ~0U; 374 375 NextSymbolIsThumb = false; 376 } 377 378 // Implementation of the MCTargetAsmParser interface: 379 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override; 380 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, 381 SMLoc NameLoc, OperandVector &Operands) override; 382 bool ParseDirective(AsmToken DirectiveID) override; 383 384 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, 385 unsigned Kind) override; 386 unsigned checkTargetMatchPredicate(MCInst &Inst) override; 387 388 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, 389 OperandVector &Operands, MCStreamer &Out, 390 uint64_t &ErrorInfo, 391 bool MatchingInlineAsm) override; 392 void onLabelParsed(MCSymbol *Symbol) override; 393 }; 394 } // end anonymous namespace 395 396 namespace { 397 398 /// ARMOperand - Instances of this class represent a parsed ARM machine 399 /// operand. 400 class ARMOperand : public MCParsedAsmOperand { 401 enum KindTy { 402 k_CondCode, 403 k_CCOut, 404 k_ITCondMask, 405 k_CoprocNum, 406 k_CoprocReg, 407 k_CoprocOption, 408 k_Immediate, 409 k_MemBarrierOpt, 410 k_InstSyncBarrierOpt, 411 k_Memory, 412 k_PostIndexRegister, 413 k_MSRMask, 414 k_BankedReg, 415 k_ProcIFlags, 416 k_VectorIndex, 417 k_Register, 418 k_RegisterList, 419 k_DPRRegisterList, 420 k_SPRRegisterList, 421 k_VectorList, 422 k_VectorListAllLanes, 423 k_VectorListIndexed, 424 k_ShiftedRegister, 425 k_ShiftedImmediate, 426 k_ShifterImmediate, 427 k_RotateImmediate, 428 k_ModifiedImmediate, 429 k_BitfieldDescriptor, 430 k_Token 431 } Kind; 432 433 SMLoc StartLoc, EndLoc, AlignmentLoc; 434 SmallVector<unsigned, 8> Registers; 435 436 struct CCOp { 437 ARMCC::CondCodes Val; 438 }; 439 440 struct CopOp { 441 unsigned Val; 442 }; 443 444 struct CoprocOptionOp { 445 unsigned Val; 446 }; 447 448 struct ITMaskOp { 449 unsigned Mask:4; 450 }; 451 452 struct MBOptOp { 453 ARM_MB::MemBOpt Val; 454 }; 455 456 struct ISBOptOp { 457 ARM_ISB::InstSyncBOpt Val; 458 }; 459 460 struct IFlagsOp { 461 ARM_PROC::IFlags Val; 462 }; 463 464 struct MMaskOp { 465 unsigned Val; 466 }; 467 468 struct BankedRegOp { 469 unsigned Val; 470 }; 471 472 struct TokOp { 473 const char *Data; 474 unsigned Length; 475 }; 476 477 struct RegOp { 478 unsigned RegNum; 479 }; 480 481 // A vector register list is a sequential list of 1 to 4 registers. 482 struct VectorListOp { 483 unsigned RegNum; 484 unsigned Count; 485 unsigned LaneIndex; 486 bool isDoubleSpaced; 487 }; 488 489 struct VectorIndexOp { 490 unsigned Val; 491 }; 492 493 struct ImmOp { 494 const MCExpr *Val; 495 }; 496 497 /// Combined record for all forms of ARM address expressions. 498 struct MemoryOp { 499 unsigned BaseRegNum; 500 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset 501 // was specified. 502 const MCConstantExpr *OffsetImm; // Offset immediate value 503 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL 504 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg 505 unsigned ShiftImm; // shift for OffsetReg. 506 unsigned Alignment; // 0 = no alignment specified 507 // n = alignment in bytes (2, 4, 8, 16, or 32) 508 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit) 509 }; 510 511 struct PostIdxRegOp { 512 unsigned RegNum; 513 bool isAdd; 514 ARM_AM::ShiftOpc ShiftTy; 515 unsigned ShiftImm; 516 }; 517 518 struct ShifterImmOp { 519 bool isASR; 520 unsigned Imm; 521 }; 522 523 struct RegShiftedRegOp { 524 ARM_AM::ShiftOpc ShiftTy; 525 unsigned SrcReg; 526 unsigned ShiftReg; 527 unsigned ShiftImm; 528 }; 529 530 struct RegShiftedImmOp { 531 ARM_AM::ShiftOpc ShiftTy; 532 unsigned SrcReg; 533 unsigned ShiftImm; 534 }; 535 536 struct RotImmOp { 537 unsigned Imm; 538 }; 539 540 struct ModImmOp { 541 unsigned Bits; 542 unsigned Rot; 543 }; 544 545 struct BitfieldOp { 546 unsigned LSB; 547 unsigned Width; 548 }; 549 550 union { 551 struct CCOp CC; 552 struct CopOp Cop; 553 struct CoprocOptionOp CoprocOption; 554 struct MBOptOp MBOpt; 555 struct ISBOptOp ISBOpt; 556 struct ITMaskOp ITMask; 557 struct IFlagsOp IFlags; 558 struct MMaskOp MMask; 559 struct BankedRegOp BankedReg; 560 struct TokOp Tok; 561 struct RegOp Reg; 562 struct VectorListOp VectorList; 563 struct VectorIndexOp VectorIndex; 564 struct ImmOp Imm; 565 struct MemoryOp Memory; 566 struct PostIdxRegOp PostIdxReg; 567 struct ShifterImmOp ShifterImm; 568 struct RegShiftedRegOp RegShiftedReg; 569 struct RegShiftedImmOp RegShiftedImm; 570 struct RotImmOp RotImm; 571 struct ModImmOp ModImm; 572 struct BitfieldOp Bitfield; 573 }; 574 575 public: 576 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {} 577 578 /// getStartLoc - Get the location of the first token of this operand. 579 SMLoc getStartLoc() const override { return StartLoc; } 580 /// getEndLoc - Get the location of the last token of this operand. 581 SMLoc getEndLoc() const override { return EndLoc; } 582 /// getLocRange - Get the range between the first and last token of this 583 /// operand. 584 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); } 585 586 /// getAlignmentLoc - Get the location of the Alignment token of this operand. 587 SMLoc getAlignmentLoc() const { 588 assert(Kind == k_Memory && "Invalid access!"); 589 return AlignmentLoc; 590 } 591 592 ARMCC::CondCodes getCondCode() const { 593 assert(Kind == k_CondCode && "Invalid access!"); 594 return CC.Val; 595 } 596 597 unsigned getCoproc() const { 598 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!"); 599 return Cop.Val; 600 } 601 602 StringRef getToken() const { 603 assert(Kind == k_Token && "Invalid access!"); 604 return StringRef(Tok.Data, Tok.Length); 605 } 606 607 unsigned getReg() const override { 608 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!"); 609 return Reg.RegNum; 610 } 611 612 const SmallVectorImpl<unsigned> &getRegList() const { 613 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList || 614 Kind == k_SPRRegisterList) && "Invalid access!"); 615 return Registers; 616 } 617 618 const MCExpr *getImm() const { 619 assert(isImm() && "Invalid access!"); 620 return Imm.Val; 621 } 622 623 unsigned getVectorIndex() const { 624 assert(Kind == k_VectorIndex && "Invalid access!"); 625 return VectorIndex.Val; 626 } 627 628 ARM_MB::MemBOpt getMemBarrierOpt() const { 629 assert(Kind == k_MemBarrierOpt && "Invalid access!"); 630 return MBOpt.Val; 631 } 632 633 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const { 634 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!"); 635 return ISBOpt.Val; 636 } 637 638 ARM_PROC::IFlags getProcIFlags() const { 639 assert(Kind == k_ProcIFlags && "Invalid access!"); 640 return IFlags.Val; 641 } 642 643 unsigned getMSRMask() const { 644 assert(Kind == k_MSRMask && "Invalid access!"); 645 return MMask.Val; 646 } 647 648 unsigned getBankedReg() const { 649 assert(Kind == k_BankedReg && "Invalid access!"); 650 return BankedReg.Val; 651 } 652 653 bool isCoprocNum() const { return Kind == k_CoprocNum; } 654 bool isCoprocReg() const { return Kind == k_CoprocReg; } 655 bool isCoprocOption() const { return Kind == k_CoprocOption; } 656 bool isCondCode() const { return Kind == k_CondCode; } 657 bool isCCOut() const { return Kind == k_CCOut; } 658 bool isITMask() const { return Kind == k_ITCondMask; } 659 bool isITCondCode() const { return Kind == k_CondCode; } 660 bool isImm() const override { return Kind == k_Immediate; } 661 // checks whether this operand is an unsigned offset which fits is a field 662 // of specified width and scaled by a specific number of bits 663 template<unsigned width, unsigned scale> 664 bool isUnsignedOffset() const { 665 if (!isImm()) return false; 666 if (isa<MCSymbolRefExpr>(Imm.Val)) return true; 667 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { 668 int64_t Val = CE->getValue(); 669 int64_t Align = 1LL << scale; 670 int64_t Max = Align * ((1LL << width) - 1); 671 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max); 672 } 673 return false; 674 } 675 // checks whether this operand is an signed offset which fits is a field 676 // of specified width and scaled by a specific number of bits 677 template<unsigned width, unsigned scale> 678 bool isSignedOffset() const { 679 if (!isImm()) return false; 680 if (isa<MCSymbolRefExpr>(Imm.Val)) return true; 681 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { 682 int64_t Val = CE->getValue(); 683 int64_t Align = 1LL << scale; 684 int64_t Max = Align * ((1LL << (width-1)) - 1); 685 int64_t Min = -Align * (1LL << (width-1)); 686 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max); 687 } 688 return false; 689 } 690 691 // checks whether this operand is a memory operand computed as an offset 692 // applied to PC. the offset may have 8 bits of magnitude and is represented 693 // with two bits of shift. textually it may be either [pc, #imm], #imm or 694 // relocable expression... 695 bool isThumbMemPC() const { 696 int64_t Val = 0; 697 if (isImm()) { 698 if (isa<MCSymbolRefExpr>(Imm.Val)) return true; 699 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val); 700 if (!CE) return false; 701 Val = CE->getValue(); 702 } 703 else if (isMem()) { 704 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false; 705 if(Memory.BaseRegNum != ARM::PC) return false; 706 Val = Memory.OffsetImm->getValue(); 707 } 708 else return false; 709 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020); 710 } 711 bool isFPImm() const { 712 if (!isImm()) return false; 713 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 714 if (!CE) return false; 715 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); 716 return Val != -1; 717 } 718 bool isFBits16() const { 719 if (!isImm()) return false; 720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 721 if (!CE) return false; 722 int64_t Value = CE->getValue(); 723 return Value >= 0 && Value <= 16; 724 } 725 bool isFBits32() const { 726 if (!isImm()) return false; 727 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 728 if (!CE) return false; 729 int64_t Value = CE->getValue(); 730 return Value >= 1 && Value <= 32; 731 } 732 bool isImm8s4() const { 733 if (!isImm()) return false; 734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 735 if (!CE) return false; 736 int64_t Value = CE->getValue(); 737 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020; 738 } 739 bool isImm0_1020s4() const { 740 if (!isImm()) return false; 741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 742 if (!CE) return false; 743 int64_t Value = CE->getValue(); 744 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020; 745 } 746 bool isImm0_508s4() const { 747 if (!isImm()) return false; 748 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 749 if (!CE) return false; 750 int64_t Value = CE->getValue(); 751 return ((Value & 3) == 0) && Value >= 0 && Value <= 508; 752 } 753 bool isImm0_508s4Neg() const { 754 if (!isImm()) return false; 755 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 756 if (!CE) return false; 757 int64_t Value = -CE->getValue(); 758 // explicitly exclude zero. we want that to use the normal 0_508 version. 759 return ((Value & 3) == 0) && Value > 0 && Value <= 508; 760 } 761 bool isImm0_239() const { 762 if (!isImm()) return false; 763 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 764 if (!CE) return false; 765 int64_t Value = CE->getValue(); 766 return Value >= 0 && Value < 240; 767 } 768 bool isImm0_255() const { 769 if (!isImm()) return false; 770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 771 if (!CE) return false; 772 int64_t Value = CE->getValue(); 773 return Value >= 0 && Value < 256; 774 } 775 bool isImm0_4095() const { 776 if (!isImm()) return false; 777 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 778 if (!CE) return false; 779 int64_t Value = CE->getValue(); 780 return Value >= 0 && Value < 4096; 781 } 782 bool isImm0_4095Neg() const { 783 if (!isImm()) return false; 784 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 785 if (!CE) return false; 786 int64_t Value = -CE->getValue(); 787 return Value > 0 && Value < 4096; 788 } 789 bool isImm0_1() const { 790 if (!isImm()) return false; 791 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 792 if (!CE) return false; 793 int64_t Value = CE->getValue(); 794 return Value >= 0 && Value < 2; 795 } 796 bool isImm0_3() const { 797 if (!isImm()) return false; 798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 799 if (!CE) return false; 800 int64_t Value = CE->getValue(); 801 return Value >= 0 && Value < 4; 802 } 803 bool isImm0_7() const { 804 if (!isImm()) return false; 805 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 806 if (!CE) return false; 807 int64_t Value = CE->getValue(); 808 return Value >= 0 && Value < 8; 809 } 810 bool isImm0_15() const { 811 if (!isImm()) return false; 812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 813 if (!CE) return false; 814 int64_t Value = CE->getValue(); 815 return Value >= 0 && Value < 16; 816 } 817 bool isImm0_31() const { 818 if (!isImm()) return false; 819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 820 if (!CE) return false; 821 int64_t Value = CE->getValue(); 822 return Value >= 0 && Value < 32; 823 } 824 bool isImm0_63() const { 825 if (!isImm()) return false; 826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 827 if (!CE) return false; 828 int64_t Value = CE->getValue(); 829 return Value >= 0 && Value < 64; 830 } 831 bool isImm8() const { 832 if (!isImm()) return false; 833 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 834 if (!CE) return false; 835 int64_t Value = CE->getValue(); 836 return Value == 8; 837 } 838 bool isImm16() const { 839 if (!isImm()) return false; 840 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 841 if (!CE) return false; 842 int64_t Value = CE->getValue(); 843 return Value == 16; 844 } 845 bool isImm32() const { 846 if (!isImm()) return false; 847 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 848 if (!CE) return false; 849 int64_t Value = CE->getValue(); 850 return Value == 32; 851 } 852 bool isShrImm8() const { 853 if (!isImm()) return false; 854 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 855 if (!CE) return false; 856 int64_t Value = CE->getValue(); 857 return Value > 0 && Value <= 8; 858 } 859 bool isShrImm16() const { 860 if (!isImm()) return false; 861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 862 if (!CE) return false; 863 int64_t Value = CE->getValue(); 864 return Value > 0 && Value <= 16; 865 } 866 bool isShrImm32() const { 867 if (!isImm()) return false; 868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 869 if (!CE) return false; 870 int64_t Value = CE->getValue(); 871 return Value > 0 && Value <= 32; 872 } 873 bool isShrImm64() const { 874 if (!isImm()) return false; 875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 876 if (!CE) return false; 877 int64_t Value = CE->getValue(); 878 return Value > 0 && Value <= 64; 879 } 880 bool isImm1_7() const { 881 if (!isImm()) return false; 882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 883 if (!CE) return false; 884 int64_t Value = CE->getValue(); 885 return Value > 0 && Value < 8; 886 } 887 bool isImm1_15() const { 888 if (!isImm()) return false; 889 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 890 if (!CE) return false; 891 int64_t Value = CE->getValue(); 892 return Value > 0 && Value < 16; 893 } 894 bool isImm1_31() const { 895 if (!isImm()) return false; 896 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 897 if (!CE) return false; 898 int64_t Value = CE->getValue(); 899 return Value > 0 && Value < 32; 900 } 901 bool isImm1_16() const { 902 if (!isImm()) return false; 903 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 904 if (!CE) return false; 905 int64_t Value = CE->getValue(); 906 return Value > 0 && Value < 17; 907 } 908 bool isImm1_32() const { 909 if (!isImm()) return false; 910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 911 if (!CE) return false; 912 int64_t Value = CE->getValue(); 913 return Value > 0 && Value < 33; 914 } 915 bool isImm0_32() const { 916 if (!isImm()) return false; 917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 918 if (!CE) return false; 919 int64_t Value = CE->getValue(); 920 return Value >= 0 && Value < 33; 921 } 922 bool isImm0_65535() const { 923 if (!isImm()) return false; 924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 925 if (!CE) return false; 926 int64_t Value = CE->getValue(); 927 return Value >= 0 && Value < 65536; 928 } 929 bool isImm256_65535Expr() const { 930 if (!isImm()) return false; 931 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 932 // If it's not a constant expression, it'll generate a fixup and be 933 // handled later. 934 if (!CE) return true; 935 int64_t Value = CE->getValue(); 936 return Value >= 256 && Value < 65536; 937 } 938 bool isImm0_65535Expr() const { 939 if (!isImm()) return false; 940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 941 // If it's not a constant expression, it'll generate a fixup and be 942 // handled later. 943 if (!CE) return true; 944 int64_t Value = CE->getValue(); 945 return Value >= 0 && Value < 65536; 946 } 947 bool isImm24bit() const { 948 if (!isImm()) return false; 949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 950 if (!CE) return false; 951 int64_t Value = CE->getValue(); 952 return Value >= 0 && Value <= 0xffffff; 953 } 954 bool isImmThumbSR() const { 955 if (!isImm()) return false; 956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 957 if (!CE) return false; 958 int64_t Value = CE->getValue(); 959 return Value > 0 && Value < 33; 960 } 961 bool isPKHLSLImm() const { 962 if (!isImm()) return false; 963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 964 if (!CE) return false; 965 int64_t Value = CE->getValue(); 966 return Value >= 0 && Value < 32; 967 } 968 bool isPKHASRImm() const { 969 if (!isImm()) return false; 970 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 971 if (!CE) return false; 972 int64_t Value = CE->getValue(); 973 return Value > 0 && Value <= 32; 974 } 975 bool isAdrLabel() const { 976 // If we have an immediate that's not a constant, treat it as a label 977 // reference needing a fixup. 978 if (isImm() && !isa<MCConstantExpr>(getImm())) 979 return true; 980 981 // If it is a constant, it must fit into a modified immediate encoding. 982 if (!isImm()) return false; 983 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 984 if (!CE) return false; 985 int64_t Value = CE->getValue(); 986 return (ARM_AM::getSOImmVal(Value) != -1 || 987 ARM_AM::getSOImmVal(-Value) != -1); 988 } 989 bool isT2SOImm() const { 990 if (!isImm()) return false; 991 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 992 if (!CE) return false; 993 int64_t Value = CE->getValue(); 994 return ARM_AM::getT2SOImmVal(Value) != -1; 995 } 996 bool isT2SOImmNot() const { 997 if (!isImm()) return false; 998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 999 if (!CE) return false; 1000 int64_t Value = CE->getValue(); 1001 return ARM_AM::getT2SOImmVal(Value) == -1 && 1002 ARM_AM::getT2SOImmVal(~Value) != -1; 1003 } 1004 bool isT2SOImmNeg() const { 1005 if (!isImm()) return false; 1006 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1007 if (!CE) return false; 1008 int64_t Value = CE->getValue(); 1009 // Only use this when not representable as a plain so_imm. 1010 return ARM_AM::getT2SOImmVal(Value) == -1 && 1011 ARM_AM::getT2SOImmVal(-Value) != -1; 1012 } 1013 bool isSetEndImm() const { 1014 if (!isImm()) return false; 1015 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1016 if (!CE) return false; 1017 int64_t Value = CE->getValue(); 1018 return Value == 1 || Value == 0; 1019 } 1020 bool isReg() const override { return Kind == k_Register; } 1021 bool isRegList() const { return Kind == k_RegisterList; } 1022 bool isDPRRegList() const { return Kind == k_DPRRegisterList; } 1023 bool isSPRRegList() const { return Kind == k_SPRRegisterList; } 1024 bool isToken() const override { return Kind == k_Token; } 1025 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; } 1026 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; } 1027 bool isMem() const override { return Kind == k_Memory; } 1028 bool isShifterImm() const { return Kind == k_ShifterImmediate; } 1029 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; } 1030 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; } 1031 bool isRotImm() const { return Kind == k_RotateImmediate; } 1032 bool isModImm() const { return Kind == k_ModifiedImmediate; } 1033 bool isModImmNot() const { 1034 if (!isImm()) return false; 1035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1036 if (!CE) return false; 1037 int64_t Value = CE->getValue(); 1038 return ARM_AM::getSOImmVal(~Value) != -1; 1039 } 1040 bool isModImmNeg() const { 1041 if (!isImm()) return false; 1042 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1043 if (!CE) return false; 1044 int64_t Value = CE->getValue(); 1045 return ARM_AM::getSOImmVal(Value) == -1 && 1046 ARM_AM::getSOImmVal(-Value) != -1; 1047 } 1048 bool isBitfield() const { return Kind == k_BitfieldDescriptor; } 1049 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; } 1050 bool isPostIdxReg() const { 1051 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift; 1052 } 1053 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const { 1054 if (!isMem()) 1055 return false; 1056 // No offset of any kind. 1057 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && 1058 (alignOK || Memory.Alignment == Alignment); 1059 } 1060 bool isMemPCRelImm12() const { 1061 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1062 return false; 1063 // Base register must be PC. 1064 if (Memory.BaseRegNum != ARM::PC) 1065 return false; 1066 // Immediate offset in range [-4095, 4095]. 1067 if (!Memory.OffsetImm) return true; 1068 int64_t Val = Memory.OffsetImm->getValue(); 1069 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); 1070 } 1071 bool isAlignedMemory() const { 1072 return isMemNoOffset(true); 1073 } 1074 bool isAlignedMemoryNone() const { 1075 return isMemNoOffset(false, 0); 1076 } 1077 bool isDupAlignedMemoryNone() const { 1078 return isMemNoOffset(false, 0); 1079 } 1080 bool isAlignedMemory16() const { 1081 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. 1082 return true; 1083 return isMemNoOffset(false, 0); 1084 } 1085 bool isDupAlignedMemory16() const { 1086 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. 1087 return true; 1088 return isMemNoOffset(false, 0); 1089 } 1090 bool isAlignedMemory32() const { 1091 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. 1092 return true; 1093 return isMemNoOffset(false, 0); 1094 } 1095 bool isDupAlignedMemory32() const { 1096 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. 1097 return true; 1098 return isMemNoOffset(false, 0); 1099 } 1100 bool isAlignedMemory64() const { 1101 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1102 return true; 1103 return isMemNoOffset(false, 0); 1104 } 1105 bool isDupAlignedMemory64() const { 1106 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1107 return true; 1108 return isMemNoOffset(false, 0); 1109 } 1110 bool isAlignedMemory64or128() const { 1111 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1112 return true; 1113 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. 1114 return true; 1115 return isMemNoOffset(false, 0); 1116 } 1117 bool isDupAlignedMemory64or128() const { 1118 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1119 return true; 1120 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. 1121 return true; 1122 return isMemNoOffset(false, 0); 1123 } 1124 bool isAlignedMemory64or128or256() const { 1125 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. 1126 return true; 1127 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. 1128 return true; 1129 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32. 1130 return true; 1131 return isMemNoOffset(false, 0); 1132 } 1133 bool isAddrMode2() const { 1134 if (!isMem() || Memory.Alignment != 0) return false; 1135 // Check for register offset. 1136 if (Memory.OffsetRegNum) return true; 1137 // Immediate offset in range [-4095, 4095]. 1138 if (!Memory.OffsetImm) return true; 1139 int64_t Val = Memory.OffsetImm->getValue(); 1140 return Val > -4096 && Val < 4096; 1141 } 1142 bool isAM2OffsetImm() const { 1143 if (!isImm()) return false; 1144 // Immediate offset in range [-4095, 4095]. 1145 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1146 if (!CE) return false; 1147 int64_t Val = CE->getValue(); 1148 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096); 1149 } 1150 bool isAddrMode3() const { 1151 // If we have an immediate that's not a constant, treat it as a label 1152 // reference needing a fixup. If it is a constant, it's something else 1153 // and we reject it. 1154 if (isImm() && !isa<MCConstantExpr>(getImm())) 1155 return true; 1156 if (!isMem() || Memory.Alignment != 0) return false; 1157 // No shifts are legal for AM3. 1158 if (Memory.ShiftType != ARM_AM::no_shift) return false; 1159 // Check for register offset. 1160 if (Memory.OffsetRegNum) return true; 1161 // Immediate offset in range [-255, 255]. 1162 if (!Memory.OffsetImm) return true; 1163 int64_t Val = Memory.OffsetImm->getValue(); 1164 // The #-0 offset is encoded as INT32_MIN, and we have to check 1165 // for this too. 1166 return (Val > -256 && Val < 256) || Val == INT32_MIN; 1167 } 1168 bool isAM3Offset() const { 1169 if (Kind != k_Immediate && Kind != k_PostIndexRegister) 1170 return false; 1171 if (Kind == k_PostIndexRegister) 1172 return PostIdxReg.ShiftTy == ARM_AM::no_shift; 1173 // Immediate offset in range [-255, 255]. 1174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1175 if (!CE) return false; 1176 int64_t Val = CE->getValue(); 1177 // Special case, #-0 is INT32_MIN. 1178 return (Val > -256 && Val < 256) || Val == INT32_MIN; 1179 } 1180 bool isAddrMode5() const { 1181 // If we have an immediate that's not a constant, treat it as a label 1182 // reference needing a fixup. If it is a constant, it's something else 1183 // and we reject it. 1184 if (isImm() && !isa<MCConstantExpr>(getImm())) 1185 return true; 1186 if (!isMem() || Memory.Alignment != 0) return false; 1187 // Check for register offset. 1188 if (Memory.OffsetRegNum) return false; 1189 // Immediate offset in range [-1020, 1020] and a multiple of 4. 1190 if (!Memory.OffsetImm) return true; 1191 int64_t Val = Memory.OffsetImm->getValue(); 1192 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) || 1193 Val == INT32_MIN; 1194 } 1195 bool isAddrMode5FP16() const { 1196 // If we have an immediate that's not a constant, treat it as a label 1197 // reference needing a fixup. If it is a constant, it's something else 1198 // and we reject it. 1199 if (isImm() && !isa<MCConstantExpr>(getImm())) 1200 return true; 1201 if (!isMem() || Memory.Alignment != 0) return false; 1202 // Check for register offset. 1203 if (Memory.OffsetRegNum) return false; 1204 // Immediate offset in range [-510, 510] and a multiple of 2. 1205 if (!Memory.OffsetImm) return true; 1206 int64_t Val = Memory.OffsetImm->getValue(); 1207 return (Val >= -510 && Val <= 510 && ((Val & 1) == 0)) || Val == INT32_MIN; 1208 } 1209 bool isMemTBB() const { 1210 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || 1211 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) 1212 return false; 1213 return true; 1214 } 1215 bool isMemTBH() const { 1216 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || 1217 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 || 1218 Memory.Alignment != 0 ) 1219 return false; 1220 return true; 1221 } 1222 bool isMemRegOffset() const { 1223 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0) 1224 return false; 1225 return true; 1226 } 1227 bool isT2MemRegOffset() const { 1228 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || 1229 Memory.Alignment != 0 || Memory.BaseRegNum == ARM::PC) 1230 return false; 1231 // Only lsl #{0, 1, 2, 3} allowed. 1232 if (Memory.ShiftType == ARM_AM::no_shift) 1233 return true; 1234 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3) 1235 return false; 1236 return true; 1237 } 1238 bool isMemThumbRR() const { 1239 // Thumb reg+reg addressing is simple. Just two registers, a base and 1240 // an offset. No shifts, negations or any other complicating factors. 1241 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || 1242 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) 1243 return false; 1244 return isARMLowRegister(Memory.BaseRegNum) && 1245 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum)); 1246 } 1247 bool isMemThumbRIs4() const { 1248 if (!isMem() || Memory.OffsetRegNum != 0 || 1249 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) 1250 return false; 1251 // Immediate offset, multiple of 4 in range [0, 124]. 1252 if (!Memory.OffsetImm) return true; 1253 int64_t Val = Memory.OffsetImm->getValue(); 1254 return Val >= 0 && Val <= 124 && (Val % 4) == 0; 1255 } 1256 bool isMemThumbRIs2() const { 1257 if (!isMem() || Memory.OffsetRegNum != 0 || 1258 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) 1259 return false; 1260 // Immediate offset, multiple of 4 in range [0, 62]. 1261 if (!Memory.OffsetImm) return true; 1262 int64_t Val = Memory.OffsetImm->getValue(); 1263 return Val >= 0 && Val <= 62 && (Val % 2) == 0; 1264 } 1265 bool isMemThumbRIs1() const { 1266 if (!isMem() || Memory.OffsetRegNum != 0 || 1267 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) 1268 return false; 1269 // Immediate offset in range [0, 31]. 1270 if (!Memory.OffsetImm) return true; 1271 int64_t Val = Memory.OffsetImm->getValue(); 1272 return Val >= 0 && Val <= 31; 1273 } 1274 bool isMemThumbSPI() const { 1275 if (!isMem() || Memory.OffsetRegNum != 0 || 1276 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0) 1277 return false; 1278 // Immediate offset, multiple of 4 in range [0, 1020]. 1279 if (!Memory.OffsetImm) return true; 1280 int64_t Val = Memory.OffsetImm->getValue(); 1281 return Val >= 0 && Val <= 1020 && (Val % 4) == 0; 1282 } 1283 bool isMemImm8s4Offset() const { 1284 // If we have an immediate that's not a constant, treat it as a label 1285 // reference needing a fixup. If it is a constant, it's something else 1286 // and we reject it. 1287 if (isImm() && !isa<MCConstantExpr>(getImm())) 1288 return true; 1289 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1290 return false; 1291 // Immediate offset a multiple of 4 in range [-1020, 1020]. 1292 if (!Memory.OffsetImm) return true; 1293 int64_t Val = Memory.OffsetImm->getValue(); 1294 // Special case, #-0 is INT32_MIN. 1295 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN; 1296 } 1297 bool isMemImm0_1020s4Offset() const { 1298 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1299 return false; 1300 // Immediate offset a multiple of 4 in range [0, 1020]. 1301 if (!Memory.OffsetImm) return true; 1302 int64_t Val = Memory.OffsetImm->getValue(); 1303 return Val >= 0 && Val <= 1020 && (Val & 3) == 0; 1304 } 1305 bool isMemImm8Offset() const { 1306 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1307 return false; 1308 // Base reg of PC isn't allowed for these encodings. 1309 if (Memory.BaseRegNum == ARM::PC) return false; 1310 // Immediate offset in range [-255, 255]. 1311 if (!Memory.OffsetImm) return true; 1312 int64_t Val = Memory.OffsetImm->getValue(); 1313 return (Val == INT32_MIN) || (Val > -256 && Val < 256); 1314 } 1315 bool isMemPosImm8Offset() const { 1316 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1317 return false; 1318 // Immediate offset in range [0, 255]. 1319 if (!Memory.OffsetImm) return true; 1320 int64_t Val = Memory.OffsetImm->getValue(); 1321 return Val >= 0 && Val < 256; 1322 } 1323 bool isMemNegImm8Offset() const { 1324 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1325 return false; 1326 // Base reg of PC isn't allowed for these encodings. 1327 if (Memory.BaseRegNum == ARM::PC) return false; 1328 // Immediate offset in range [-255, -1]. 1329 if (!Memory.OffsetImm) return false; 1330 int64_t Val = Memory.OffsetImm->getValue(); 1331 return (Val == INT32_MIN) || (Val > -256 && Val < 0); 1332 } 1333 bool isMemUImm12Offset() const { 1334 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1335 return false; 1336 // Immediate offset in range [0, 4095]. 1337 if (!Memory.OffsetImm) return true; 1338 int64_t Val = Memory.OffsetImm->getValue(); 1339 return (Val >= 0 && Val < 4096); 1340 } 1341 bool isMemImm12Offset() const { 1342 // If we have an immediate that's not a constant, treat it as a label 1343 // reference needing a fixup. If it is a constant, it's something else 1344 // and we reject it. 1345 if (isImm() && !isa<MCConstantExpr>(getImm())) 1346 return true; 1347 1348 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) 1349 return false; 1350 // Immediate offset in range [-4095, 4095]. 1351 if (!Memory.OffsetImm) return true; 1352 int64_t Val = Memory.OffsetImm->getValue(); 1353 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); 1354 } 1355 bool isPostIdxImm8() const { 1356 if (!isImm()) return false; 1357 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1358 if (!CE) return false; 1359 int64_t Val = CE->getValue(); 1360 return (Val > -256 && Val < 256) || (Val == INT32_MIN); 1361 } 1362 bool isPostIdxImm8s4() const { 1363 if (!isImm()) return false; 1364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1365 if (!CE) return false; 1366 int64_t Val = CE->getValue(); 1367 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) || 1368 (Val == INT32_MIN); 1369 } 1370 1371 bool isMSRMask() const { return Kind == k_MSRMask; } 1372 bool isBankedReg() const { return Kind == k_BankedReg; } 1373 bool isProcIFlags() const { return Kind == k_ProcIFlags; } 1374 1375 // NEON operands. 1376 bool isSingleSpacedVectorList() const { 1377 return Kind == k_VectorList && !VectorList.isDoubleSpaced; 1378 } 1379 bool isDoubleSpacedVectorList() const { 1380 return Kind == k_VectorList && VectorList.isDoubleSpaced; 1381 } 1382 bool isVecListOneD() const { 1383 if (!isSingleSpacedVectorList()) return false; 1384 return VectorList.Count == 1; 1385 } 1386 1387 bool isVecListDPair() const { 1388 if (!isSingleSpacedVectorList()) return false; 1389 return (ARMMCRegisterClasses[ARM::DPairRegClassID] 1390 .contains(VectorList.RegNum)); 1391 } 1392 1393 bool isVecListThreeD() const { 1394 if (!isSingleSpacedVectorList()) return false; 1395 return VectorList.Count == 3; 1396 } 1397 1398 bool isVecListFourD() const { 1399 if (!isSingleSpacedVectorList()) return false; 1400 return VectorList.Count == 4; 1401 } 1402 1403 bool isVecListDPairSpaced() const { 1404 if (Kind != k_VectorList) return false; 1405 if (isSingleSpacedVectorList()) return false; 1406 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID] 1407 .contains(VectorList.RegNum)); 1408 } 1409 1410 bool isVecListThreeQ() const { 1411 if (!isDoubleSpacedVectorList()) return false; 1412 return VectorList.Count == 3; 1413 } 1414 1415 bool isVecListFourQ() const { 1416 if (!isDoubleSpacedVectorList()) return false; 1417 return VectorList.Count == 4; 1418 } 1419 1420 bool isSingleSpacedVectorAllLanes() const { 1421 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced; 1422 } 1423 bool isDoubleSpacedVectorAllLanes() const { 1424 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced; 1425 } 1426 bool isVecListOneDAllLanes() const { 1427 if (!isSingleSpacedVectorAllLanes()) return false; 1428 return VectorList.Count == 1; 1429 } 1430 1431 bool isVecListDPairAllLanes() const { 1432 if (!isSingleSpacedVectorAllLanes()) return false; 1433 return (ARMMCRegisterClasses[ARM::DPairRegClassID] 1434 .contains(VectorList.RegNum)); 1435 } 1436 1437 bool isVecListDPairSpacedAllLanes() const { 1438 if (!isDoubleSpacedVectorAllLanes()) return false; 1439 return VectorList.Count == 2; 1440 } 1441 1442 bool isVecListThreeDAllLanes() const { 1443 if (!isSingleSpacedVectorAllLanes()) return false; 1444 return VectorList.Count == 3; 1445 } 1446 1447 bool isVecListThreeQAllLanes() const { 1448 if (!isDoubleSpacedVectorAllLanes()) return false; 1449 return VectorList.Count == 3; 1450 } 1451 1452 bool isVecListFourDAllLanes() const { 1453 if (!isSingleSpacedVectorAllLanes()) return false; 1454 return VectorList.Count == 4; 1455 } 1456 1457 bool isVecListFourQAllLanes() const { 1458 if (!isDoubleSpacedVectorAllLanes()) return false; 1459 return VectorList.Count == 4; 1460 } 1461 1462 bool isSingleSpacedVectorIndexed() const { 1463 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced; 1464 } 1465 bool isDoubleSpacedVectorIndexed() const { 1466 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced; 1467 } 1468 bool isVecListOneDByteIndexed() const { 1469 if (!isSingleSpacedVectorIndexed()) return false; 1470 return VectorList.Count == 1 && VectorList.LaneIndex <= 7; 1471 } 1472 1473 bool isVecListOneDHWordIndexed() const { 1474 if (!isSingleSpacedVectorIndexed()) return false; 1475 return VectorList.Count == 1 && VectorList.LaneIndex <= 3; 1476 } 1477 1478 bool isVecListOneDWordIndexed() const { 1479 if (!isSingleSpacedVectorIndexed()) return false; 1480 return VectorList.Count == 1 && VectorList.LaneIndex <= 1; 1481 } 1482 1483 bool isVecListTwoDByteIndexed() const { 1484 if (!isSingleSpacedVectorIndexed()) return false; 1485 return VectorList.Count == 2 && VectorList.LaneIndex <= 7; 1486 } 1487 1488 bool isVecListTwoDHWordIndexed() const { 1489 if (!isSingleSpacedVectorIndexed()) return false; 1490 return VectorList.Count == 2 && VectorList.LaneIndex <= 3; 1491 } 1492 1493 bool isVecListTwoQWordIndexed() const { 1494 if (!isDoubleSpacedVectorIndexed()) return false; 1495 return VectorList.Count == 2 && VectorList.LaneIndex <= 1; 1496 } 1497 1498 bool isVecListTwoQHWordIndexed() const { 1499 if (!isDoubleSpacedVectorIndexed()) return false; 1500 return VectorList.Count == 2 && VectorList.LaneIndex <= 3; 1501 } 1502 1503 bool isVecListTwoDWordIndexed() const { 1504 if (!isSingleSpacedVectorIndexed()) return false; 1505 return VectorList.Count == 2 && VectorList.LaneIndex <= 1; 1506 } 1507 1508 bool isVecListThreeDByteIndexed() const { 1509 if (!isSingleSpacedVectorIndexed()) return false; 1510 return VectorList.Count == 3 && VectorList.LaneIndex <= 7; 1511 } 1512 1513 bool isVecListThreeDHWordIndexed() const { 1514 if (!isSingleSpacedVectorIndexed()) return false; 1515 return VectorList.Count == 3 && VectorList.LaneIndex <= 3; 1516 } 1517 1518 bool isVecListThreeQWordIndexed() const { 1519 if (!isDoubleSpacedVectorIndexed()) return false; 1520 return VectorList.Count == 3 && VectorList.LaneIndex <= 1; 1521 } 1522 1523 bool isVecListThreeQHWordIndexed() const { 1524 if (!isDoubleSpacedVectorIndexed()) return false; 1525 return VectorList.Count == 3 && VectorList.LaneIndex <= 3; 1526 } 1527 1528 bool isVecListThreeDWordIndexed() const { 1529 if (!isSingleSpacedVectorIndexed()) return false; 1530 return VectorList.Count == 3 && VectorList.LaneIndex <= 1; 1531 } 1532 1533 bool isVecListFourDByteIndexed() const { 1534 if (!isSingleSpacedVectorIndexed()) return false; 1535 return VectorList.Count == 4 && VectorList.LaneIndex <= 7; 1536 } 1537 1538 bool isVecListFourDHWordIndexed() const { 1539 if (!isSingleSpacedVectorIndexed()) return false; 1540 return VectorList.Count == 4 && VectorList.LaneIndex <= 3; 1541 } 1542 1543 bool isVecListFourQWordIndexed() const { 1544 if (!isDoubleSpacedVectorIndexed()) return false; 1545 return VectorList.Count == 4 && VectorList.LaneIndex <= 1; 1546 } 1547 1548 bool isVecListFourQHWordIndexed() const { 1549 if (!isDoubleSpacedVectorIndexed()) return false; 1550 return VectorList.Count == 4 && VectorList.LaneIndex <= 3; 1551 } 1552 1553 bool isVecListFourDWordIndexed() const { 1554 if (!isSingleSpacedVectorIndexed()) return false; 1555 return VectorList.Count == 4 && VectorList.LaneIndex <= 1; 1556 } 1557 1558 bool isVectorIndex8() const { 1559 if (Kind != k_VectorIndex) return false; 1560 return VectorIndex.Val < 8; 1561 } 1562 bool isVectorIndex16() const { 1563 if (Kind != k_VectorIndex) return false; 1564 return VectorIndex.Val < 4; 1565 } 1566 bool isVectorIndex32() const { 1567 if (Kind != k_VectorIndex) return false; 1568 return VectorIndex.Val < 2; 1569 } 1570 1571 bool isNEONi8splat() const { 1572 if (!isImm()) return false; 1573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1574 // Must be a constant. 1575 if (!CE) return false; 1576 int64_t Value = CE->getValue(); 1577 // i8 value splatted across 8 bytes. The immediate is just the 8 byte 1578 // value. 1579 return Value >= 0 && Value < 256; 1580 } 1581 1582 bool isNEONi16splat() const { 1583 if (isNEONByteReplicate(2)) 1584 return false; // Leave that for bytes replication and forbid by default. 1585 if (!isImm()) 1586 return false; 1587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1588 // Must be a constant. 1589 if (!CE) return false; 1590 unsigned Value = CE->getValue(); 1591 return ARM_AM::isNEONi16splat(Value); 1592 } 1593 1594 bool isNEONi16splatNot() const { 1595 if (!isImm()) 1596 return false; 1597 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1598 // Must be a constant. 1599 if (!CE) return false; 1600 unsigned Value = CE->getValue(); 1601 return ARM_AM::isNEONi16splat(~Value & 0xffff); 1602 } 1603 1604 bool isNEONi32splat() const { 1605 if (isNEONByteReplicate(4)) 1606 return false; // Leave that for bytes replication and forbid by default. 1607 if (!isImm()) 1608 return false; 1609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1610 // Must be a constant. 1611 if (!CE) return false; 1612 unsigned Value = CE->getValue(); 1613 return ARM_AM::isNEONi32splat(Value); 1614 } 1615 1616 bool isNEONi32splatNot() const { 1617 if (!isImm()) 1618 return false; 1619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1620 // Must be a constant. 1621 if (!CE) return false; 1622 unsigned Value = CE->getValue(); 1623 return ARM_AM::isNEONi32splat(~Value); 1624 } 1625 1626 bool isNEONByteReplicate(unsigned NumBytes) const { 1627 if (!isImm()) 1628 return false; 1629 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1630 // Must be a constant. 1631 if (!CE) 1632 return false; 1633 int64_t Value = CE->getValue(); 1634 if (!Value) 1635 return false; // Don't bother with zero. 1636 1637 unsigned char B = Value & 0xff; 1638 for (unsigned i = 1; i < NumBytes; ++i) { 1639 Value >>= 8; 1640 if ((Value & 0xff) != B) 1641 return false; 1642 } 1643 return true; 1644 } 1645 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); } 1646 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); } 1647 bool isNEONi32vmov() const { 1648 if (isNEONByteReplicate(4)) 1649 return false; // Let it to be classified as byte-replicate case. 1650 if (!isImm()) 1651 return false; 1652 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1653 // Must be a constant. 1654 if (!CE) 1655 return false; 1656 int64_t Value = CE->getValue(); 1657 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, 1658 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. 1659 // FIXME: This is probably wrong and a copy and paste from previous example 1660 return (Value >= 0 && Value < 256) || 1661 (Value >= 0x0100 && Value <= 0xff00) || 1662 (Value >= 0x010000 && Value <= 0xff0000) || 1663 (Value >= 0x01000000 && Value <= 0xff000000) || 1664 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || 1665 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); 1666 } 1667 bool isNEONi32vmovNeg() const { 1668 if (!isImm()) return false; 1669 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1670 // Must be a constant. 1671 if (!CE) return false; 1672 int64_t Value = ~CE->getValue(); 1673 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, 1674 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. 1675 // FIXME: This is probably wrong and a copy and paste from previous example 1676 return (Value >= 0 && Value < 256) || 1677 (Value >= 0x0100 && Value <= 0xff00) || 1678 (Value >= 0x010000 && Value <= 0xff0000) || 1679 (Value >= 0x01000000 && Value <= 0xff000000) || 1680 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || 1681 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); 1682 } 1683 1684 bool isNEONi64splat() const { 1685 if (!isImm()) return false; 1686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1687 // Must be a constant. 1688 if (!CE) return false; 1689 uint64_t Value = CE->getValue(); 1690 // i64 value with each byte being either 0 or 0xff. 1691 for (unsigned i = 0; i < 8; ++i) 1692 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false; 1693 return true; 1694 } 1695 1696 void addExpr(MCInst &Inst, const MCExpr *Expr) const { 1697 // Add as immediates when possible. Null MCExpr = 0. 1698 if (!Expr) 1699 Inst.addOperand(MCOperand::createImm(0)); 1700 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) 1701 Inst.addOperand(MCOperand::createImm(CE->getValue())); 1702 else 1703 Inst.addOperand(MCOperand::createExpr(Expr)); 1704 } 1705 1706 void addCondCodeOperands(MCInst &Inst, unsigned N) const { 1707 assert(N == 2 && "Invalid number of operands!"); 1708 Inst.addOperand(MCOperand::createImm(unsigned(getCondCode()))); 1709 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR; 1710 Inst.addOperand(MCOperand::createReg(RegNum)); 1711 } 1712 1713 void addCoprocNumOperands(MCInst &Inst, unsigned N) const { 1714 assert(N == 1 && "Invalid number of operands!"); 1715 Inst.addOperand(MCOperand::createImm(getCoproc())); 1716 } 1717 1718 void addCoprocRegOperands(MCInst &Inst, unsigned N) const { 1719 assert(N == 1 && "Invalid number of operands!"); 1720 Inst.addOperand(MCOperand::createImm(getCoproc())); 1721 } 1722 1723 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const { 1724 assert(N == 1 && "Invalid number of operands!"); 1725 Inst.addOperand(MCOperand::createImm(CoprocOption.Val)); 1726 } 1727 1728 void addITMaskOperands(MCInst &Inst, unsigned N) const { 1729 assert(N == 1 && "Invalid number of operands!"); 1730 Inst.addOperand(MCOperand::createImm(ITMask.Mask)); 1731 } 1732 1733 void addITCondCodeOperands(MCInst &Inst, unsigned N) const { 1734 assert(N == 1 && "Invalid number of operands!"); 1735 Inst.addOperand(MCOperand::createImm(unsigned(getCondCode()))); 1736 } 1737 1738 void addCCOutOperands(MCInst &Inst, unsigned N) const { 1739 assert(N == 1 && "Invalid number of operands!"); 1740 Inst.addOperand(MCOperand::createReg(getReg())); 1741 } 1742 1743 void addRegOperands(MCInst &Inst, unsigned N) const { 1744 assert(N == 1 && "Invalid number of operands!"); 1745 Inst.addOperand(MCOperand::createReg(getReg())); 1746 } 1747 1748 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const { 1749 assert(N == 3 && "Invalid number of operands!"); 1750 assert(isRegShiftedReg() && 1751 "addRegShiftedRegOperands() on non-RegShiftedReg!"); 1752 Inst.addOperand(MCOperand::createReg(RegShiftedReg.SrcReg)); 1753 Inst.addOperand(MCOperand::createReg(RegShiftedReg.ShiftReg)); 1754 Inst.addOperand(MCOperand::createImm( 1755 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm))); 1756 } 1757 1758 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const { 1759 assert(N == 2 && "Invalid number of operands!"); 1760 assert(isRegShiftedImm() && 1761 "addRegShiftedImmOperands() on non-RegShiftedImm!"); 1762 Inst.addOperand(MCOperand::createReg(RegShiftedImm.SrcReg)); 1763 // Shift of #32 is encoded as 0 where permitted 1764 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm); 1765 Inst.addOperand(MCOperand::createImm( 1766 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm))); 1767 } 1768 1769 void addShifterImmOperands(MCInst &Inst, unsigned N) const { 1770 assert(N == 1 && "Invalid number of operands!"); 1771 Inst.addOperand(MCOperand::createImm((ShifterImm.isASR << 5) | 1772 ShifterImm.Imm)); 1773 } 1774 1775 void addRegListOperands(MCInst &Inst, unsigned N) const { 1776 assert(N == 1 && "Invalid number of operands!"); 1777 const SmallVectorImpl<unsigned> &RegList = getRegList(); 1778 for (SmallVectorImpl<unsigned>::const_iterator 1779 I = RegList.begin(), E = RegList.end(); I != E; ++I) 1780 Inst.addOperand(MCOperand::createReg(*I)); 1781 } 1782 1783 void addDPRRegListOperands(MCInst &Inst, unsigned N) const { 1784 addRegListOperands(Inst, N); 1785 } 1786 1787 void addSPRRegListOperands(MCInst &Inst, unsigned N) const { 1788 addRegListOperands(Inst, N); 1789 } 1790 1791 void addRotImmOperands(MCInst &Inst, unsigned N) const { 1792 assert(N == 1 && "Invalid number of operands!"); 1793 // Encoded as val>>3. The printer handles display as 8, 16, 24. 1794 Inst.addOperand(MCOperand::createImm(RotImm.Imm >> 3)); 1795 } 1796 1797 void addModImmOperands(MCInst &Inst, unsigned N) const { 1798 assert(N == 1 && "Invalid number of operands!"); 1799 1800 // Support for fixups (MCFixup) 1801 if (isImm()) 1802 return addImmOperands(Inst, N); 1803 1804 Inst.addOperand(MCOperand::createImm(ModImm.Bits | (ModImm.Rot << 7))); 1805 } 1806 1807 void addModImmNotOperands(MCInst &Inst, unsigned N) const { 1808 assert(N == 1 && "Invalid number of operands!"); 1809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1810 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue()); 1811 Inst.addOperand(MCOperand::createImm(Enc)); 1812 } 1813 1814 void addModImmNegOperands(MCInst &Inst, unsigned N) const { 1815 assert(N == 1 && "Invalid number of operands!"); 1816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1817 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue()); 1818 Inst.addOperand(MCOperand::createImm(Enc)); 1819 } 1820 1821 void addBitfieldOperands(MCInst &Inst, unsigned N) const { 1822 assert(N == 1 && "Invalid number of operands!"); 1823 // Munge the lsb/width into a bitfield mask. 1824 unsigned lsb = Bitfield.LSB; 1825 unsigned width = Bitfield.Width; 1826 // Make a 32-bit mask w/ the referenced bits clear and all other bits set. 1827 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >> 1828 (32 - (lsb + width))); 1829 Inst.addOperand(MCOperand::createImm(Mask)); 1830 } 1831 1832 void addImmOperands(MCInst &Inst, unsigned N) const { 1833 assert(N == 1 && "Invalid number of operands!"); 1834 addExpr(Inst, getImm()); 1835 } 1836 1837 void addFBits16Operands(MCInst &Inst, unsigned N) const { 1838 assert(N == 1 && "Invalid number of operands!"); 1839 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1840 Inst.addOperand(MCOperand::createImm(16 - CE->getValue())); 1841 } 1842 1843 void addFBits32Operands(MCInst &Inst, unsigned N) const { 1844 assert(N == 1 && "Invalid number of operands!"); 1845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1846 Inst.addOperand(MCOperand::createImm(32 - CE->getValue())); 1847 } 1848 1849 void addFPImmOperands(MCInst &Inst, unsigned N) const { 1850 assert(N == 1 && "Invalid number of operands!"); 1851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1852 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); 1853 Inst.addOperand(MCOperand::createImm(Val)); 1854 } 1855 1856 void addImm8s4Operands(MCInst &Inst, unsigned N) const { 1857 assert(N == 1 && "Invalid number of operands!"); 1858 // FIXME: We really want to scale the value here, but the LDRD/STRD 1859 // instruction don't encode operands that way yet. 1860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1861 Inst.addOperand(MCOperand::createImm(CE->getValue())); 1862 } 1863 1864 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const { 1865 assert(N == 1 && "Invalid number of operands!"); 1866 // The immediate is scaled by four in the encoding and is stored 1867 // in the MCInst as such. Lop off the low two bits here. 1868 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1869 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4)); 1870 } 1871 1872 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const { 1873 assert(N == 1 && "Invalid number of operands!"); 1874 // The immediate is scaled by four in the encoding and is stored 1875 // in the MCInst as such. Lop off the low two bits here. 1876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1877 Inst.addOperand(MCOperand::createImm(-(CE->getValue() / 4))); 1878 } 1879 1880 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const { 1881 assert(N == 1 && "Invalid number of operands!"); 1882 // The immediate is scaled by four in the encoding and is stored 1883 // in the MCInst as such. Lop off the low two bits here. 1884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1885 Inst.addOperand(MCOperand::createImm(CE->getValue() / 4)); 1886 } 1887 1888 void addImm1_16Operands(MCInst &Inst, unsigned N) const { 1889 assert(N == 1 && "Invalid number of operands!"); 1890 // The constant encodes as the immediate-1, and we store in the instruction 1891 // the bits as encoded, so subtract off one here. 1892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1893 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1)); 1894 } 1895 1896 void addImm1_32Operands(MCInst &Inst, unsigned N) const { 1897 assert(N == 1 && "Invalid number of operands!"); 1898 // The constant encodes as the immediate-1, and we store in the instruction 1899 // the bits as encoded, so subtract off one here. 1900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1901 Inst.addOperand(MCOperand::createImm(CE->getValue() - 1)); 1902 } 1903 1904 void addImmThumbSROperands(MCInst &Inst, unsigned N) const { 1905 assert(N == 1 && "Invalid number of operands!"); 1906 // The constant encodes as the immediate, except for 32, which encodes as 1907 // zero. 1908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1909 unsigned Imm = CE->getValue(); 1910 Inst.addOperand(MCOperand::createImm((Imm == 32 ? 0 : Imm))); 1911 } 1912 1913 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const { 1914 assert(N == 1 && "Invalid number of operands!"); 1915 // An ASR value of 32 encodes as 0, so that's how we want to add it to 1916 // the instruction as well. 1917 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1918 int Val = CE->getValue(); 1919 Inst.addOperand(MCOperand::createImm(Val == 32 ? 0 : Val)); 1920 } 1921 1922 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const { 1923 assert(N == 1 && "Invalid number of operands!"); 1924 // The operand is actually a t2_so_imm, but we have its bitwise 1925 // negation in the assembly source, so twiddle it here. 1926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1927 Inst.addOperand(MCOperand::createImm(~CE->getValue())); 1928 } 1929 1930 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const { 1931 assert(N == 1 && "Invalid number of operands!"); 1932 // The operand is actually a t2_so_imm, but we have its 1933 // negation in the assembly source, so twiddle it here. 1934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1935 Inst.addOperand(MCOperand::createImm(-CE->getValue())); 1936 } 1937 1938 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const { 1939 assert(N == 1 && "Invalid number of operands!"); 1940 // The operand is actually an imm0_4095, but we have its 1941 // negation in the assembly source, so twiddle it here. 1942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1943 Inst.addOperand(MCOperand::createImm(-CE->getValue())); 1944 } 1945 1946 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const { 1947 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) { 1948 Inst.addOperand(MCOperand::createImm(CE->getValue() >> 2)); 1949 return; 1950 } 1951 1952 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); 1953 assert(SR && "Unknown value type!"); 1954 Inst.addOperand(MCOperand::createExpr(SR)); 1955 } 1956 1957 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const { 1958 assert(N == 1 && "Invalid number of operands!"); 1959 if (isImm()) { 1960 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 1961 if (CE) { 1962 Inst.addOperand(MCOperand::createImm(CE->getValue())); 1963 return; 1964 } 1965 1966 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); 1967 assert(SR && "Unknown value type!"); 1968 Inst.addOperand(MCOperand::createExpr(SR)); 1969 return; 1970 } 1971 1972 assert(isMem() && "Unknown value type!"); 1973 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!"); 1974 Inst.addOperand(MCOperand::createImm(Memory.OffsetImm->getValue())); 1975 } 1976 1977 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const { 1978 assert(N == 1 && "Invalid number of operands!"); 1979 Inst.addOperand(MCOperand::createImm(unsigned(getMemBarrierOpt()))); 1980 } 1981 1982 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const { 1983 assert(N == 1 && "Invalid number of operands!"); 1984 Inst.addOperand(MCOperand::createImm(unsigned(getInstSyncBarrierOpt()))); 1985 } 1986 1987 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const { 1988 assert(N == 1 && "Invalid number of operands!"); 1989 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 1990 } 1991 1992 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const { 1993 assert(N == 1 && "Invalid number of operands!"); 1994 int32_t Imm = Memory.OffsetImm->getValue(); 1995 Inst.addOperand(MCOperand::createImm(Imm)); 1996 } 1997 1998 void addAdrLabelOperands(MCInst &Inst, unsigned N) const { 1999 assert(N == 1 && "Invalid number of operands!"); 2000 assert(isImm() && "Not an immediate!"); 2001 2002 // If we have an immediate that's not a constant, treat it as a label 2003 // reference needing a fixup. 2004 if (!isa<MCConstantExpr>(getImm())) { 2005 Inst.addOperand(MCOperand::createExpr(getImm())); 2006 return; 2007 } 2008 2009 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2010 int Val = CE->getValue(); 2011 Inst.addOperand(MCOperand::createImm(Val)); 2012 } 2013 2014 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const { 2015 assert(N == 2 && "Invalid number of operands!"); 2016 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2017 Inst.addOperand(MCOperand::createImm(Memory.Alignment)); 2018 } 2019 2020 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { 2021 addAlignedMemoryOperands(Inst, N); 2022 } 2023 2024 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { 2025 addAlignedMemoryOperands(Inst, N); 2026 } 2027 2028 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const { 2029 addAlignedMemoryOperands(Inst, N); 2030 } 2031 2032 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const { 2033 addAlignedMemoryOperands(Inst, N); 2034 } 2035 2036 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const { 2037 addAlignedMemoryOperands(Inst, N); 2038 } 2039 2040 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const { 2041 addAlignedMemoryOperands(Inst, N); 2042 } 2043 2044 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const { 2045 addAlignedMemoryOperands(Inst, N); 2046 } 2047 2048 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const { 2049 addAlignedMemoryOperands(Inst, N); 2050 } 2051 2052 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { 2053 addAlignedMemoryOperands(Inst, N); 2054 } 2055 2056 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { 2057 addAlignedMemoryOperands(Inst, N); 2058 } 2059 2060 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const { 2061 addAlignedMemoryOperands(Inst, N); 2062 } 2063 2064 void addAddrMode2Operands(MCInst &Inst, unsigned N) const { 2065 assert(N == 3 && "Invalid number of operands!"); 2066 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; 2067 if (!Memory.OffsetRegNum) { 2068 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2069 // Special case for #-0 2070 if (Val == INT32_MIN) Val = 0; 2071 if (Val < 0) Val = -Val; 2072 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); 2073 } else { 2074 // For register offset, we encode the shift type and negation flag 2075 // here. 2076 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 2077 Memory.ShiftImm, Memory.ShiftType); 2078 } 2079 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2080 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2081 Inst.addOperand(MCOperand::createImm(Val)); 2082 } 2083 2084 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const { 2085 assert(N == 2 && "Invalid number of operands!"); 2086 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2087 assert(CE && "non-constant AM2OffsetImm operand!"); 2088 int32_t Val = CE->getValue(); 2089 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2090 // Special case for #-0 2091 if (Val == INT32_MIN) Val = 0; 2092 if (Val < 0) Val = -Val; 2093 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); 2094 Inst.addOperand(MCOperand::createReg(0)); 2095 Inst.addOperand(MCOperand::createImm(Val)); 2096 } 2097 2098 void addAddrMode3Operands(MCInst &Inst, unsigned N) const { 2099 assert(N == 3 && "Invalid number of operands!"); 2100 // If we have an immediate that's not a constant, treat it as a label 2101 // reference needing a fixup. If it is a constant, it's something else 2102 // and we reject it. 2103 if (isImm()) { 2104 Inst.addOperand(MCOperand::createExpr(getImm())); 2105 Inst.addOperand(MCOperand::createReg(0)); 2106 Inst.addOperand(MCOperand::createImm(0)); 2107 return; 2108 } 2109 2110 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; 2111 if (!Memory.OffsetRegNum) { 2112 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2113 // Special case for #-0 2114 if (Val == INT32_MIN) Val = 0; 2115 if (Val < 0) Val = -Val; 2116 Val = ARM_AM::getAM3Opc(AddSub, Val); 2117 } else { 2118 // For register offset, we encode the shift type and negation flag 2119 // here. 2120 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0); 2121 } 2122 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2123 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2124 Inst.addOperand(MCOperand::createImm(Val)); 2125 } 2126 2127 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const { 2128 assert(N == 2 && "Invalid number of operands!"); 2129 if (Kind == k_PostIndexRegister) { 2130 int32_t Val = 2131 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0); 2132 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum)); 2133 Inst.addOperand(MCOperand::createImm(Val)); 2134 return; 2135 } 2136 2137 // Constant offset. 2138 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm()); 2139 int32_t Val = CE->getValue(); 2140 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2141 // Special case for #-0 2142 if (Val == INT32_MIN) Val = 0; 2143 if (Val < 0) Val = -Val; 2144 Val = ARM_AM::getAM3Opc(AddSub, Val); 2145 Inst.addOperand(MCOperand::createReg(0)); 2146 Inst.addOperand(MCOperand::createImm(Val)); 2147 } 2148 2149 void addAddrMode5Operands(MCInst &Inst, unsigned N) const { 2150 assert(N == 2 && "Invalid number of operands!"); 2151 // If we have an immediate that's not a constant, treat it as a label 2152 // reference needing a fixup. If it is a constant, it's something else 2153 // and we reject it. 2154 if (isImm()) { 2155 Inst.addOperand(MCOperand::createExpr(getImm())); 2156 Inst.addOperand(MCOperand::createImm(0)); 2157 return; 2158 } 2159 2160 // The lower two bits are always zero and as such are not encoded. 2161 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; 2162 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2163 // Special case for #-0 2164 if (Val == INT32_MIN) Val = 0; 2165 if (Val < 0) Val = -Val; 2166 Val = ARM_AM::getAM5Opc(AddSub, Val); 2167 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2168 Inst.addOperand(MCOperand::createImm(Val)); 2169 } 2170 2171 void addAddrMode5FP16Operands(MCInst &Inst, unsigned N) const { 2172 assert(N == 2 && "Invalid number of operands!"); 2173 // If we have an immediate that's not a constant, treat it as a label 2174 // reference needing a fixup. If it is a constant, it's something else 2175 // and we reject it. 2176 if (isImm()) { 2177 Inst.addOperand(MCOperand::createExpr(getImm())); 2178 Inst.addOperand(MCOperand::createImm(0)); 2179 return; 2180 } 2181 2182 // The lower bit is always zero and as such is not encoded. 2183 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 2 : 0; 2184 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; 2185 // Special case for #-0 2186 if (Val == INT32_MIN) Val = 0; 2187 if (Val < 0) Val = -Val; 2188 Val = ARM_AM::getAM5FP16Opc(AddSub, Val); 2189 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2190 Inst.addOperand(MCOperand::createImm(Val)); 2191 } 2192 2193 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const { 2194 assert(N == 2 && "Invalid number of operands!"); 2195 // If we have an immediate that's not a constant, treat it as a label 2196 // reference needing a fixup. If it is a constant, it's something else 2197 // and we reject it. 2198 if (isImm()) { 2199 Inst.addOperand(MCOperand::createExpr(getImm())); 2200 Inst.addOperand(MCOperand::createImm(0)); 2201 return; 2202 } 2203 2204 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; 2205 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2206 Inst.addOperand(MCOperand::createImm(Val)); 2207 } 2208 2209 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const { 2210 assert(N == 2 && "Invalid number of operands!"); 2211 // The lower two bits are always zero and as such are not encoded. 2212 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; 2213 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2214 Inst.addOperand(MCOperand::createImm(Val)); 2215 } 2216 2217 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const { 2218 assert(N == 2 && "Invalid number of operands!"); 2219 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; 2220 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2221 Inst.addOperand(MCOperand::createImm(Val)); 2222 } 2223 2224 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const { 2225 addMemImm8OffsetOperands(Inst, N); 2226 } 2227 2228 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const { 2229 addMemImm8OffsetOperands(Inst, N); 2230 } 2231 2232 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const { 2233 assert(N == 2 && "Invalid number of operands!"); 2234 // If this is an immediate, it's a label reference. 2235 if (isImm()) { 2236 addExpr(Inst, getImm()); 2237 Inst.addOperand(MCOperand::createImm(0)); 2238 return; 2239 } 2240 2241 // Otherwise, it's a normal memory reg+offset. 2242 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; 2243 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2244 Inst.addOperand(MCOperand::createImm(Val)); 2245 } 2246 2247 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const { 2248 assert(N == 2 && "Invalid number of operands!"); 2249 // If this is an immediate, it's a label reference. 2250 if (isImm()) { 2251 addExpr(Inst, getImm()); 2252 Inst.addOperand(MCOperand::createImm(0)); 2253 return; 2254 } 2255 2256 // Otherwise, it's a normal memory reg+offset. 2257 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; 2258 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2259 Inst.addOperand(MCOperand::createImm(Val)); 2260 } 2261 2262 void addMemTBBOperands(MCInst &Inst, unsigned N) const { 2263 assert(N == 2 && "Invalid number of operands!"); 2264 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2265 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2266 } 2267 2268 void addMemTBHOperands(MCInst &Inst, unsigned N) const { 2269 assert(N == 2 && "Invalid number of operands!"); 2270 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2271 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2272 } 2273 2274 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const { 2275 assert(N == 3 && "Invalid number of operands!"); 2276 unsigned Val = 2277 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 2278 Memory.ShiftImm, Memory.ShiftType); 2279 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2280 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2281 Inst.addOperand(MCOperand::createImm(Val)); 2282 } 2283 2284 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const { 2285 assert(N == 3 && "Invalid number of operands!"); 2286 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2287 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2288 Inst.addOperand(MCOperand::createImm(Memory.ShiftImm)); 2289 } 2290 2291 void addMemThumbRROperands(MCInst &Inst, unsigned N) const { 2292 assert(N == 2 && "Invalid number of operands!"); 2293 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2294 Inst.addOperand(MCOperand::createReg(Memory.OffsetRegNum)); 2295 } 2296 2297 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const { 2298 assert(N == 2 && "Invalid number of operands!"); 2299 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; 2300 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2301 Inst.addOperand(MCOperand::createImm(Val)); 2302 } 2303 2304 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const { 2305 assert(N == 2 && "Invalid number of operands!"); 2306 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0; 2307 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2308 Inst.addOperand(MCOperand::createImm(Val)); 2309 } 2310 2311 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const { 2312 assert(N == 2 && "Invalid number of operands!"); 2313 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0; 2314 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2315 Inst.addOperand(MCOperand::createImm(Val)); 2316 } 2317 2318 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const { 2319 assert(N == 2 && "Invalid number of operands!"); 2320 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; 2321 Inst.addOperand(MCOperand::createReg(Memory.BaseRegNum)); 2322 Inst.addOperand(MCOperand::createImm(Val)); 2323 } 2324 2325 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const { 2326 assert(N == 1 && "Invalid number of operands!"); 2327 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2328 assert(CE && "non-constant post-idx-imm8 operand!"); 2329 int Imm = CE->getValue(); 2330 bool isAdd = Imm >= 0; 2331 if (Imm == INT32_MIN) Imm = 0; 2332 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8; 2333 Inst.addOperand(MCOperand::createImm(Imm)); 2334 } 2335 2336 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const { 2337 assert(N == 1 && "Invalid number of operands!"); 2338 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2339 assert(CE && "non-constant post-idx-imm8s4 operand!"); 2340 int Imm = CE->getValue(); 2341 bool isAdd = Imm >= 0; 2342 if (Imm == INT32_MIN) Imm = 0; 2343 // Immediate is scaled by 4. 2344 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8; 2345 Inst.addOperand(MCOperand::createImm(Imm)); 2346 } 2347 2348 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const { 2349 assert(N == 2 && "Invalid number of operands!"); 2350 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum)); 2351 Inst.addOperand(MCOperand::createImm(PostIdxReg.isAdd)); 2352 } 2353 2354 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const { 2355 assert(N == 2 && "Invalid number of operands!"); 2356 Inst.addOperand(MCOperand::createReg(PostIdxReg.RegNum)); 2357 // The sign, shift type, and shift amount are encoded in a single operand 2358 // using the AM2 encoding helpers. 2359 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub; 2360 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm, 2361 PostIdxReg.ShiftTy); 2362 Inst.addOperand(MCOperand::createImm(Imm)); 2363 } 2364 2365 void addMSRMaskOperands(MCInst &Inst, unsigned N) const { 2366 assert(N == 1 && "Invalid number of operands!"); 2367 Inst.addOperand(MCOperand::createImm(unsigned(getMSRMask()))); 2368 } 2369 2370 void addBankedRegOperands(MCInst &Inst, unsigned N) const { 2371 assert(N == 1 && "Invalid number of operands!"); 2372 Inst.addOperand(MCOperand::createImm(unsigned(getBankedReg()))); 2373 } 2374 2375 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const { 2376 assert(N == 1 && "Invalid number of operands!"); 2377 Inst.addOperand(MCOperand::createImm(unsigned(getProcIFlags()))); 2378 } 2379 2380 void addVecListOperands(MCInst &Inst, unsigned N) const { 2381 assert(N == 1 && "Invalid number of operands!"); 2382 Inst.addOperand(MCOperand::createReg(VectorList.RegNum)); 2383 } 2384 2385 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const { 2386 assert(N == 2 && "Invalid number of operands!"); 2387 Inst.addOperand(MCOperand::createReg(VectorList.RegNum)); 2388 Inst.addOperand(MCOperand::createImm(VectorList.LaneIndex)); 2389 } 2390 2391 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const { 2392 assert(N == 1 && "Invalid number of operands!"); 2393 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 2394 } 2395 2396 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const { 2397 assert(N == 1 && "Invalid number of operands!"); 2398 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 2399 } 2400 2401 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const { 2402 assert(N == 1 && "Invalid number of operands!"); 2403 Inst.addOperand(MCOperand::createImm(getVectorIndex())); 2404 } 2405 2406 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const { 2407 assert(N == 1 && "Invalid number of operands!"); 2408 // The immediate encodes the type of constant as well as the value. 2409 // Mask in that this is an i8 splat. 2410 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2411 Inst.addOperand(MCOperand::createImm(CE->getValue() | 0xe00)); 2412 } 2413 2414 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const { 2415 assert(N == 1 && "Invalid number of operands!"); 2416 // The immediate encodes the type of constant as well as the value. 2417 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2418 unsigned Value = CE->getValue(); 2419 Value = ARM_AM::encodeNEONi16splat(Value); 2420 Inst.addOperand(MCOperand::createImm(Value)); 2421 } 2422 2423 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const { 2424 assert(N == 1 && "Invalid number of operands!"); 2425 // The immediate encodes the type of constant as well as the value. 2426 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2427 unsigned Value = CE->getValue(); 2428 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff); 2429 Inst.addOperand(MCOperand::createImm(Value)); 2430 } 2431 2432 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const { 2433 assert(N == 1 && "Invalid number of operands!"); 2434 // The immediate encodes the type of constant as well as the value. 2435 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2436 unsigned Value = CE->getValue(); 2437 Value = ARM_AM::encodeNEONi32splat(Value); 2438 Inst.addOperand(MCOperand::createImm(Value)); 2439 } 2440 2441 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const { 2442 assert(N == 1 && "Invalid number of operands!"); 2443 // The immediate encodes the type of constant as well as the value. 2444 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2445 unsigned Value = CE->getValue(); 2446 Value = ARM_AM::encodeNEONi32splat(~Value); 2447 Inst.addOperand(MCOperand::createImm(Value)); 2448 } 2449 2450 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const { 2451 assert(N == 1 && "Invalid number of operands!"); 2452 // The immediate encodes the type of constant as well as the value. 2453 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2454 unsigned Value = CE->getValue(); 2455 assert((Inst.getOpcode() == ARM::VMOVv8i8 || 2456 Inst.getOpcode() == ARM::VMOVv16i8) && 2457 "All vmvn instructions that wants to replicate non-zero byte " 2458 "always must be replaced with VMOVv8i8 or VMOVv16i8."); 2459 unsigned B = ((~Value) & 0xff); 2460 B |= 0xe00; // cmode = 0b1110 2461 Inst.addOperand(MCOperand::createImm(B)); 2462 } 2463 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const { 2464 assert(N == 1 && "Invalid number of operands!"); 2465 // The immediate encodes the type of constant as well as the value. 2466 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2467 unsigned Value = CE->getValue(); 2468 if (Value >= 256 && Value <= 0xffff) 2469 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); 2470 else if (Value > 0xffff && Value <= 0xffffff) 2471 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); 2472 else if (Value > 0xffffff) 2473 Value = (Value >> 24) | 0x600; 2474 Inst.addOperand(MCOperand::createImm(Value)); 2475 } 2476 2477 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const { 2478 assert(N == 1 && "Invalid number of operands!"); 2479 // The immediate encodes the type of constant as well as the value. 2480 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2481 unsigned Value = CE->getValue(); 2482 assert((Inst.getOpcode() == ARM::VMOVv8i8 || 2483 Inst.getOpcode() == ARM::VMOVv16i8) && 2484 "All instructions that wants to replicate non-zero byte " 2485 "always must be replaced with VMOVv8i8 or VMOVv16i8."); 2486 unsigned B = Value & 0xff; 2487 B |= 0xe00; // cmode = 0b1110 2488 Inst.addOperand(MCOperand::createImm(B)); 2489 } 2490 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const { 2491 assert(N == 1 && "Invalid number of operands!"); 2492 // The immediate encodes the type of constant as well as the value. 2493 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2494 unsigned Value = ~CE->getValue(); 2495 if (Value >= 256 && Value <= 0xffff) 2496 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); 2497 else if (Value > 0xffff && Value <= 0xffffff) 2498 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); 2499 else if (Value > 0xffffff) 2500 Value = (Value >> 24) | 0x600; 2501 Inst.addOperand(MCOperand::createImm(Value)); 2502 } 2503 2504 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const { 2505 assert(N == 1 && "Invalid number of operands!"); 2506 // The immediate encodes the type of constant as well as the value. 2507 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); 2508 uint64_t Value = CE->getValue(); 2509 unsigned Imm = 0; 2510 for (unsigned i = 0; i < 8; ++i, Value >>= 8) { 2511 Imm |= (Value & 1) << i; 2512 } 2513 Inst.addOperand(MCOperand::createImm(Imm | 0x1e00)); 2514 } 2515 2516 void print(raw_ostream &OS) const override; 2517 2518 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) { 2519 auto Op = make_unique<ARMOperand>(k_ITCondMask); 2520 Op->ITMask.Mask = Mask; 2521 Op->StartLoc = S; 2522 Op->EndLoc = S; 2523 return Op; 2524 } 2525 2526 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC, 2527 SMLoc S) { 2528 auto Op = make_unique<ARMOperand>(k_CondCode); 2529 Op->CC.Val = CC; 2530 Op->StartLoc = S; 2531 Op->EndLoc = S; 2532 return Op; 2533 } 2534 2535 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) { 2536 auto Op = make_unique<ARMOperand>(k_CoprocNum); 2537 Op->Cop.Val = CopVal; 2538 Op->StartLoc = S; 2539 Op->EndLoc = S; 2540 return Op; 2541 } 2542 2543 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) { 2544 auto Op = make_unique<ARMOperand>(k_CoprocReg); 2545 Op->Cop.Val = CopVal; 2546 Op->StartLoc = S; 2547 Op->EndLoc = S; 2548 return Op; 2549 } 2550 2551 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S, 2552 SMLoc E) { 2553 auto Op = make_unique<ARMOperand>(k_CoprocOption); 2554 Op->Cop.Val = Val; 2555 Op->StartLoc = S; 2556 Op->EndLoc = E; 2557 return Op; 2558 } 2559 2560 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) { 2561 auto Op = make_unique<ARMOperand>(k_CCOut); 2562 Op->Reg.RegNum = RegNum; 2563 Op->StartLoc = S; 2564 Op->EndLoc = S; 2565 return Op; 2566 } 2567 2568 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) { 2569 auto Op = make_unique<ARMOperand>(k_Token); 2570 Op->Tok.Data = Str.data(); 2571 Op->Tok.Length = Str.size(); 2572 Op->StartLoc = S; 2573 Op->EndLoc = S; 2574 return Op; 2575 } 2576 2577 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S, 2578 SMLoc E) { 2579 auto Op = make_unique<ARMOperand>(k_Register); 2580 Op->Reg.RegNum = RegNum; 2581 Op->StartLoc = S; 2582 Op->EndLoc = E; 2583 return Op; 2584 } 2585 2586 static std::unique_ptr<ARMOperand> 2587 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, 2588 unsigned ShiftReg, unsigned ShiftImm, SMLoc S, 2589 SMLoc E) { 2590 auto Op = make_unique<ARMOperand>(k_ShiftedRegister); 2591 Op->RegShiftedReg.ShiftTy = ShTy; 2592 Op->RegShiftedReg.SrcReg = SrcReg; 2593 Op->RegShiftedReg.ShiftReg = ShiftReg; 2594 Op->RegShiftedReg.ShiftImm = ShiftImm; 2595 Op->StartLoc = S; 2596 Op->EndLoc = E; 2597 return Op; 2598 } 2599 2600 static std::unique_ptr<ARMOperand> 2601 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, 2602 unsigned ShiftImm, SMLoc S, SMLoc E) { 2603 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate); 2604 Op->RegShiftedImm.ShiftTy = ShTy; 2605 Op->RegShiftedImm.SrcReg = SrcReg; 2606 Op->RegShiftedImm.ShiftImm = ShiftImm; 2607 Op->StartLoc = S; 2608 Op->EndLoc = E; 2609 return Op; 2610 } 2611 2612 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm, 2613 SMLoc S, SMLoc E) { 2614 auto Op = make_unique<ARMOperand>(k_ShifterImmediate); 2615 Op->ShifterImm.isASR = isASR; 2616 Op->ShifterImm.Imm = Imm; 2617 Op->StartLoc = S; 2618 Op->EndLoc = E; 2619 return Op; 2620 } 2621 2622 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S, 2623 SMLoc E) { 2624 auto Op = make_unique<ARMOperand>(k_RotateImmediate); 2625 Op->RotImm.Imm = Imm; 2626 Op->StartLoc = S; 2627 Op->EndLoc = E; 2628 return Op; 2629 } 2630 2631 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot, 2632 SMLoc S, SMLoc E) { 2633 auto Op = make_unique<ARMOperand>(k_ModifiedImmediate); 2634 Op->ModImm.Bits = Bits; 2635 Op->ModImm.Rot = Rot; 2636 Op->StartLoc = S; 2637 Op->EndLoc = E; 2638 return Op; 2639 } 2640 2641 static std::unique_ptr<ARMOperand> 2642 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) { 2643 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor); 2644 Op->Bitfield.LSB = LSB; 2645 Op->Bitfield.Width = Width; 2646 Op->StartLoc = S; 2647 Op->EndLoc = E; 2648 return Op; 2649 } 2650 2651 static std::unique_ptr<ARMOperand> 2652 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs, 2653 SMLoc StartLoc, SMLoc EndLoc) { 2654 assert (Regs.size() > 0 && "RegList contains no registers?"); 2655 KindTy Kind = k_RegisterList; 2656 2657 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second)) 2658 Kind = k_DPRRegisterList; 2659 else if (ARMMCRegisterClasses[ARM::SPRRegClassID]. 2660 contains(Regs.front().second)) 2661 Kind = k_SPRRegisterList; 2662 2663 // Sort based on the register encoding values. 2664 array_pod_sort(Regs.begin(), Regs.end()); 2665 2666 auto Op = make_unique<ARMOperand>(Kind); 2667 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator 2668 I = Regs.begin(), E = Regs.end(); I != E; ++I) 2669 Op->Registers.push_back(I->second); 2670 Op->StartLoc = StartLoc; 2671 Op->EndLoc = EndLoc; 2672 return Op; 2673 } 2674 2675 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum, 2676 unsigned Count, 2677 bool isDoubleSpaced, 2678 SMLoc S, SMLoc E) { 2679 auto Op = make_unique<ARMOperand>(k_VectorList); 2680 Op->VectorList.RegNum = RegNum; 2681 Op->VectorList.Count = Count; 2682 Op->VectorList.isDoubleSpaced = isDoubleSpaced; 2683 Op->StartLoc = S; 2684 Op->EndLoc = E; 2685 return Op; 2686 } 2687 2688 static std::unique_ptr<ARMOperand> 2689 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced, 2690 SMLoc S, SMLoc E) { 2691 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes); 2692 Op->VectorList.RegNum = RegNum; 2693 Op->VectorList.Count = Count; 2694 Op->VectorList.isDoubleSpaced = isDoubleSpaced; 2695 Op->StartLoc = S; 2696 Op->EndLoc = E; 2697 return Op; 2698 } 2699 2700 static std::unique_ptr<ARMOperand> 2701 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index, 2702 bool isDoubleSpaced, SMLoc S, SMLoc E) { 2703 auto Op = make_unique<ARMOperand>(k_VectorListIndexed); 2704 Op->VectorList.RegNum = RegNum; 2705 Op->VectorList.Count = Count; 2706 Op->VectorList.LaneIndex = Index; 2707 Op->VectorList.isDoubleSpaced = isDoubleSpaced; 2708 Op->StartLoc = S; 2709 Op->EndLoc = E; 2710 return Op; 2711 } 2712 2713 static std::unique_ptr<ARMOperand> 2714 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) { 2715 auto Op = make_unique<ARMOperand>(k_VectorIndex); 2716 Op->VectorIndex.Val = Idx; 2717 Op->StartLoc = S; 2718 Op->EndLoc = E; 2719 return Op; 2720 } 2721 2722 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S, 2723 SMLoc E) { 2724 auto Op = make_unique<ARMOperand>(k_Immediate); 2725 Op->Imm.Val = Val; 2726 Op->StartLoc = S; 2727 Op->EndLoc = E; 2728 return Op; 2729 } 2730 2731 static std::unique_ptr<ARMOperand> 2732 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm, 2733 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType, 2734 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S, 2735 SMLoc E, SMLoc AlignmentLoc = SMLoc()) { 2736 auto Op = make_unique<ARMOperand>(k_Memory); 2737 Op->Memory.BaseRegNum = BaseRegNum; 2738 Op->Memory.OffsetImm = OffsetImm; 2739 Op->Memory.OffsetRegNum = OffsetRegNum; 2740 Op->Memory.ShiftType = ShiftType; 2741 Op->Memory.ShiftImm = ShiftImm; 2742 Op->Memory.Alignment = Alignment; 2743 Op->Memory.isNegative = isNegative; 2744 Op->StartLoc = S; 2745 Op->EndLoc = E; 2746 Op->AlignmentLoc = AlignmentLoc; 2747 return Op; 2748 } 2749 2750 static std::unique_ptr<ARMOperand> 2751 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy, 2752 unsigned ShiftImm, SMLoc S, SMLoc E) { 2753 auto Op = make_unique<ARMOperand>(k_PostIndexRegister); 2754 Op->PostIdxReg.RegNum = RegNum; 2755 Op->PostIdxReg.isAdd = isAdd; 2756 Op->PostIdxReg.ShiftTy = ShiftTy; 2757 Op->PostIdxReg.ShiftImm = ShiftImm; 2758 Op->StartLoc = S; 2759 Op->EndLoc = E; 2760 return Op; 2761 } 2762 2763 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, 2764 SMLoc S) { 2765 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt); 2766 Op->MBOpt.Val = Opt; 2767 Op->StartLoc = S; 2768 Op->EndLoc = S; 2769 return Op; 2770 } 2771 2772 static std::unique_ptr<ARMOperand> 2773 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) { 2774 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt); 2775 Op->ISBOpt.Val = Opt; 2776 Op->StartLoc = S; 2777 Op->EndLoc = S; 2778 return Op; 2779 } 2780 2781 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags, 2782 SMLoc S) { 2783 auto Op = make_unique<ARMOperand>(k_ProcIFlags); 2784 Op->IFlags.Val = IFlags; 2785 Op->StartLoc = S; 2786 Op->EndLoc = S; 2787 return Op; 2788 } 2789 2790 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) { 2791 auto Op = make_unique<ARMOperand>(k_MSRMask); 2792 Op->MMask.Val = MMask; 2793 Op->StartLoc = S; 2794 Op->EndLoc = S; 2795 return Op; 2796 } 2797 2798 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) { 2799 auto Op = make_unique<ARMOperand>(k_BankedReg); 2800 Op->BankedReg.Val = Reg; 2801 Op->StartLoc = S; 2802 Op->EndLoc = S; 2803 return Op; 2804 } 2805 }; 2806 2807 } // end anonymous namespace. 2808 2809 void ARMOperand::print(raw_ostream &OS) const { 2810 switch (Kind) { 2811 case k_CondCode: 2812 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">"; 2813 break; 2814 case k_CCOut: 2815 OS << "<ccout " << getReg() << ">"; 2816 break; 2817 case k_ITCondMask: { 2818 static const char *const MaskStr[] = { 2819 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)", 2820 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)" 2821 }; 2822 assert((ITMask.Mask & 0xf) == ITMask.Mask); 2823 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">"; 2824 break; 2825 } 2826 case k_CoprocNum: 2827 OS << "<coprocessor number: " << getCoproc() << ">"; 2828 break; 2829 case k_CoprocReg: 2830 OS << "<coprocessor register: " << getCoproc() << ">"; 2831 break; 2832 case k_CoprocOption: 2833 OS << "<coprocessor option: " << CoprocOption.Val << ">"; 2834 break; 2835 case k_MSRMask: 2836 OS << "<mask: " << getMSRMask() << ">"; 2837 break; 2838 case k_BankedReg: 2839 OS << "<banked reg: " << getBankedReg() << ">"; 2840 break; 2841 case k_Immediate: 2842 OS << *getImm(); 2843 break; 2844 case k_MemBarrierOpt: 2845 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">"; 2846 break; 2847 case k_InstSyncBarrierOpt: 2848 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">"; 2849 break; 2850 case k_Memory: 2851 OS << "<memory " 2852 << " base:" << Memory.BaseRegNum; 2853 OS << ">"; 2854 break; 2855 case k_PostIndexRegister: 2856 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-") 2857 << PostIdxReg.RegNum; 2858 if (PostIdxReg.ShiftTy != ARM_AM::no_shift) 2859 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " " 2860 << PostIdxReg.ShiftImm; 2861 OS << ">"; 2862 break; 2863 case k_ProcIFlags: { 2864 OS << "<ARM_PROC::"; 2865 unsigned IFlags = getProcIFlags(); 2866 for (int i=2; i >= 0; --i) 2867 if (IFlags & (1 << i)) 2868 OS << ARM_PROC::IFlagsToString(1 << i); 2869 OS << ">"; 2870 break; 2871 } 2872 case k_Register: 2873 OS << "<register " << getReg() << ">"; 2874 break; 2875 case k_ShifterImmediate: 2876 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl") 2877 << " #" << ShifterImm.Imm << ">"; 2878 break; 2879 case k_ShiftedRegister: 2880 OS << "<so_reg_reg " 2881 << RegShiftedReg.SrcReg << " " 2882 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy) 2883 << " " << RegShiftedReg.ShiftReg << ">"; 2884 break; 2885 case k_ShiftedImmediate: 2886 OS << "<so_reg_imm " 2887 << RegShiftedImm.SrcReg << " " 2888 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy) 2889 << " #" << RegShiftedImm.ShiftImm << ">"; 2890 break; 2891 case k_RotateImmediate: 2892 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">"; 2893 break; 2894 case k_ModifiedImmediate: 2895 OS << "<mod_imm #" << ModImm.Bits << ", #" 2896 << ModImm.Rot << ")>"; 2897 break; 2898 case k_BitfieldDescriptor: 2899 OS << "<bitfield " << "lsb: " << Bitfield.LSB 2900 << ", width: " << Bitfield.Width << ">"; 2901 break; 2902 case k_RegisterList: 2903 case k_DPRRegisterList: 2904 case k_SPRRegisterList: { 2905 OS << "<register_list "; 2906 2907 const SmallVectorImpl<unsigned> &RegList = getRegList(); 2908 for (SmallVectorImpl<unsigned>::const_iterator 2909 I = RegList.begin(), E = RegList.end(); I != E; ) { 2910 OS << *I; 2911 if (++I < E) OS << ", "; 2912 } 2913 2914 OS << ">"; 2915 break; 2916 } 2917 case k_VectorList: 2918 OS << "<vector_list " << VectorList.Count << " * " 2919 << VectorList.RegNum << ">"; 2920 break; 2921 case k_VectorListAllLanes: 2922 OS << "<vector_list(all lanes) " << VectorList.Count << " * " 2923 << VectorList.RegNum << ">"; 2924 break; 2925 case k_VectorListIndexed: 2926 OS << "<vector_list(lane " << VectorList.LaneIndex << ") " 2927 << VectorList.Count << " * " << VectorList.RegNum << ">"; 2928 break; 2929 case k_Token: 2930 OS << "'" << getToken() << "'"; 2931 break; 2932 case k_VectorIndex: 2933 OS << "<vectorindex " << getVectorIndex() << ">"; 2934 break; 2935 } 2936 } 2937 2938 /// @name Auto-generated Match Functions 2939 /// { 2940 2941 static unsigned MatchRegisterName(StringRef Name); 2942 2943 /// } 2944 2945 bool ARMAsmParser::ParseRegister(unsigned &RegNo, 2946 SMLoc &StartLoc, SMLoc &EndLoc) { 2947 const AsmToken &Tok = getParser().getTok(); 2948 StartLoc = Tok.getLoc(); 2949 EndLoc = Tok.getEndLoc(); 2950 RegNo = tryParseRegister(); 2951 2952 return (RegNo == (unsigned)-1); 2953 } 2954 2955 /// Try to parse a register name. The token must be an Identifier when called, 2956 /// and if it is a register name the token is eaten and the register number is 2957 /// returned. Otherwise return -1. 2958 /// 2959 int ARMAsmParser::tryParseRegister() { 2960 MCAsmParser &Parser = getParser(); 2961 const AsmToken &Tok = Parser.getTok(); 2962 if (Tok.isNot(AsmToken::Identifier)) return -1; 2963 2964 std::string lowerCase = Tok.getString().lower(); 2965 unsigned RegNum = MatchRegisterName(lowerCase); 2966 if (!RegNum) { 2967 RegNum = StringSwitch<unsigned>(lowerCase) 2968 .Case("r13", ARM::SP) 2969 .Case("r14", ARM::LR) 2970 .Case("r15", ARM::PC) 2971 .Case("ip", ARM::R12) 2972 // Additional register name aliases for 'gas' compatibility. 2973 .Case("a1", ARM::R0) 2974 .Case("a2", ARM::R1) 2975 .Case("a3", ARM::R2) 2976 .Case("a4", ARM::R3) 2977 .Case("v1", ARM::R4) 2978 .Case("v2", ARM::R5) 2979 .Case("v3", ARM::R6) 2980 .Case("v4", ARM::R7) 2981 .Case("v5", ARM::R8) 2982 .Case("v6", ARM::R9) 2983 .Case("v7", ARM::R10) 2984 .Case("v8", ARM::R11) 2985 .Case("sb", ARM::R9) 2986 .Case("sl", ARM::R10) 2987 .Case("fp", ARM::R11) 2988 .Default(0); 2989 } 2990 if (!RegNum) { 2991 // Check for aliases registered via .req. Canonicalize to lower case. 2992 // That's more consistent since register names are case insensitive, and 2993 // it's how the original entry was passed in from MC/MCParser/AsmParser. 2994 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase); 2995 // If no match, return failure. 2996 if (Entry == RegisterReqs.end()) 2997 return -1; 2998 Parser.Lex(); // Eat identifier token. 2999 return Entry->getValue(); 3000 } 3001 3002 // Some FPUs only have 16 D registers, so D16-D31 are invalid 3003 if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31) 3004 return -1; 3005 3006 Parser.Lex(); // Eat identifier token. 3007 3008 return RegNum; 3009 } 3010 3011 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0. 3012 // If a recoverable error occurs, return 1. If an irrecoverable error 3013 // occurs, return -1. An irrecoverable error is one where tokens have been 3014 // consumed in the process of trying to parse the shifter (i.e., when it is 3015 // indeed a shifter operand, but malformed). 3016 int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) { 3017 MCAsmParser &Parser = getParser(); 3018 SMLoc S = Parser.getTok().getLoc(); 3019 const AsmToken &Tok = Parser.getTok(); 3020 if (Tok.isNot(AsmToken::Identifier)) 3021 return -1; 3022 3023 std::string lowerCase = Tok.getString().lower(); 3024 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase) 3025 .Case("asl", ARM_AM::lsl) 3026 .Case("lsl", ARM_AM::lsl) 3027 .Case("lsr", ARM_AM::lsr) 3028 .Case("asr", ARM_AM::asr) 3029 .Case("ror", ARM_AM::ror) 3030 .Case("rrx", ARM_AM::rrx) 3031 .Default(ARM_AM::no_shift); 3032 3033 if (ShiftTy == ARM_AM::no_shift) 3034 return 1; 3035 3036 Parser.Lex(); // Eat the operator. 3037 3038 // The source register for the shift has already been added to the 3039 // operand list, so we need to pop it off and combine it into the shifted 3040 // register operand instead. 3041 std::unique_ptr<ARMOperand> PrevOp( 3042 (ARMOperand *)Operands.pop_back_val().release()); 3043 if (!PrevOp->isReg()) 3044 return Error(PrevOp->getStartLoc(), "shift must be of a register"); 3045 int SrcReg = PrevOp->getReg(); 3046 3047 SMLoc EndLoc; 3048 int64_t Imm = 0; 3049 int ShiftReg = 0; 3050 if (ShiftTy == ARM_AM::rrx) { 3051 // RRX Doesn't have an explicit shift amount. The encoder expects 3052 // the shift register to be the same as the source register. Seems odd, 3053 // but OK. 3054 ShiftReg = SrcReg; 3055 } else { 3056 // Figure out if this is shifted by a constant or a register (for non-RRX). 3057 if (Parser.getTok().is(AsmToken::Hash) || 3058 Parser.getTok().is(AsmToken::Dollar)) { 3059 Parser.Lex(); // Eat hash. 3060 SMLoc ImmLoc = Parser.getTok().getLoc(); 3061 const MCExpr *ShiftExpr = nullptr; 3062 if (getParser().parseExpression(ShiftExpr, EndLoc)) { 3063 Error(ImmLoc, "invalid immediate shift value"); 3064 return -1; 3065 } 3066 // The expression must be evaluatable as an immediate. 3067 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr); 3068 if (!CE) { 3069 Error(ImmLoc, "invalid immediate shift value"); 3070 return -1; 3071 } 3072 // Range check the immediate. 3073 // lsl, ror: 0 <= imm <= 31 3074 // lsr, asr: 0 <= imm <= 32 3075 Imm = CE->getValue(); 3076 if (Imm < 0 || 3077 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) || 3078 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) { 3079 Error(ImmLoc, "immediate shift value out of range"); 3080 return -1; 3081 } 3082 // shift by zero is a nop. Always send it through as lsl. 3083 // ('as' compatibility) 3084 if (Imm == 0) 3085 ShiftTy = ARM_AM::lsl; 3086 } else if (Parser.getTok().is(AsmToken::Identifier)) { 3087 SMLoc L = Parser.getTok().getLoc(); 3088 EndLoc = Parser.getTok().getEndLoc(); 3089 ShiftReg = tryParseRegister(); 3090 if (ShiftReg == -1) { 3091 Error(L, "expected immediate or register in shift operand"); 3092 return -1; 3093 } 3094 } else { 3095 Error(Parser.getTok().getLoc(), 3096 "expected immediate or register in shift operand"); 3097 return -1; 3098 } 3099 } 3100 3101 if (ShiftReg && ShiftTy != ARM_AM::rrx) 3102 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg, 3103 ShiftReg, Imm, 3104 S, EndLoc)); 3105 else 3106 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm, 3107 S, EndLoc)); 3108 3109 return 0; 3110 } 3111 3112 3113 /// Try to parse a register name. The token must be an Identifier when called. 3114 /// If it's a register, an AsmOperand is created. Another AsmOperand is created 3115 /// if there is a "writeback". 'true' if it's not a register. 3116 /// 3117 /// TODO this is likely to change to allow different register types and or to 3118 /// parse for a specific register type. 3119 bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) { 3120 MCAsmParser &Parser = getParser(); 3121 const AsmToken &RegTok = Parser.getTok(); 3122 int RegNo = tryParseRegister(); 3123 if (RegNo == -1) 3124 return true; 3125 3126 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(), 3127 RegTok.getEndLoc())); 3128 3129 const AsmToken &ExclaimTok = Parser.getTok(); 3130 if (ExclaimTok.is(AsmToken::Exclaim)) { 3131 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(), 3132 ExclaimTok.getLoc())); 3133 Parser.Lex(); // Eat exclaim token 3134 return false; 3135 } 3136 3137 // Also check for an index operand. This is only legal for vector registers, 3138 // but that'll get caught OK in operand matching, so we don't need to 3139 // explicitly filter everything else out here. 3140 if (Parser.getTok().is(AsmToken::LBrac)) { 3141 SMLoc SIdx = Parser.getTok().getLoc(); 3142 Parser.Lex(); // Eat left bracket token. 3143 3144 const MCExpr *ImmVal; 3145 if (getParser().parseExpression(ImmVal)) 3146 return true; 3147 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal); 3148 if (!MCE) 3149 return TokError("immediate value expected for vector index"); 3150 3151 if (Parser.getTok().isNot(AsmToken::RBrac)) 3152 return Error(Parser.getTok().getLoc(), "']' expected"); 3153 3154 SMLoc E = Parser.getTok().getEndLoc(); 3155 Parser.Lex(); // Eat right bracket token. 3156 3157 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(), 3158 SIdx, E, 3159 getContext())); 3160 } 3161 3162 return false; 3163 } 3164 3165 /// MatchCoprocessorOperandName - Try to parse an coprocessor related 3166 /// instruction with a symbolic operand name. 3167 /// We accept "crN" syntax for GAS compatibility. 3168 /// <operand-name> ::= <prefix><number> 3169 /// If CoprocOp is 'c', then: 3170 /// <prefix> ::= c | cr 3171 /// If CoprocOp is 'p', then : 3172 /// <prefix> ::= p 3173 /// <number> ::= integer in range [0, 15] 3174 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) { 3175 // Use the same layout as the tablegen'erated register name matcher. Ugly, 3176 // but efficient. 3177 if (Name.size() < 2 || Name[0] != CoprocOp) 3178 return -1; 3179 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front(); 3180 3181 switch (Name.size()) { 3182 default: return -1; 3183 case 1: 3184 switch (Name[0]) { 3185 default: return -1; 3186 case '0': return 0; 3187 case '1': return 1; 3188 case '2': return 2; 3189 case '3': return 3; 3190 case '4': return 4; 3191 case '5': return 5; 3192 case '6': return 6; 3193 case '7': return 7; 3194 case '8': return 8; 3195 case '9': return 9; 3196 } 3197 case 2: 3198 if (Name[0] != '1') 3199 return -1; 3200 switch (Name[1]) { 3201 default: return -1; 3202 // CP10 and CP11 are VFP/NEON and so vector instructions should be used. 3203 // However, old cores (v5/v6) did use them in that way. 3204 case '0': return 10; 3205 case '1': return 11; 3206 case '2': return 12; 3207 case '3': return 13; 3208 case '4': return 14; 3209 case '5': return 15; 3210 } 3211 } 3212 } 3213 3214 /// parseITCondCode - Try to parse a condition code for an IT instruction. 3215 ARMAsmParser::OperandMatchResultTy 3216 ARMAsmParser::parseITCondCode(OperandVector &Operands) { 3217 MCAsmParser &Parser = getParser(); 3218 SMLoc S = Parser.getTok().getLoc(); 3219 const AsmToken &Tok = Parser.getTok(); 3220 if (!Tok.is(AsmToken::Identifier)) 3221 return MatchOperand_NoMatch; 3222 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower()) 3223 .Case("eq", ARMCC::EQ) 3224 .Case("ne", ARMCC::NE) 3225 .Case("hs", ARMCC::HS) 3226 .Case("cs", ARMCC::HS) 3227 .Case("lo", ARMCC::LO) 3228 .Case("cc", ARMCC::LO) 3229 .Case("mi", ARMCC::MI) 3230 .Case("pl", ARMCC::PL) 3231 .Case("vs", ARMCC::VS) 3232 .Case("vc", ARMCC::VC) 3233 .Case("hi", ARMCC::HI) 3234 .Case("ls", ARMCC::LS) 3235 .Case("ge", ARMCC::GE) 3236 .Case("lt", ARMCC::LT) 3237 .Case("gt", ARMCC::GT) 3238 .Case("le", ARMCC::LE) 3239 .Case("al", ARMCC::AL) 3240 .Default(~0U); 3241 if (CC == ~0U) 3242 return MatchOperand_NoMatch; 3243 Parser.Lex(); // Eat the token. 3244 3245 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S)); 3246 3247 return MatchOperand_Success; 3248 } 3249 3250 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The 3251 /// token must be an Identifier when called, and if it is a coprocessor 3252 /// number, the token is eaten and the operand is added to the operand list. 3253 ARMAsmParser::OperandMatchResultTy 3254 ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) { 3255 MCAsmParser &Parser = getParser(); 3256 SMLoc S = Parser.getTok().getLoc(); 3257 const AsmToken &Tok = Parser.getTok(); 3258 if (Tok.isNot(AsmToken::Identifier)) 3259 return MatchOperand_NoMatch; 3260 3261 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p'); 3262 if (Num == -1) 3263 return MatchOperand_NoMatch; 3264 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions 3265 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11)) 3266 return MatchOperand_NoMatch; 3267 3268 Parser.Lex(); // Eat identifier token. 3269 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S)); 3270 return MatchOperand_Success; 3271 } 3272 3273 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The 3274 /// token must be an Identifier when called, and if it is a coprocessor 3275 /// number, the token is eaten and the operand is added to the operand list. 3276 ARMAsmParser::OperandMatchResultTy 3277 ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) { 3278 MCAsmParser &Parser = getParser(); 3279 SMLoc S = Parser.getTok().getLoc(); 3280 const AsmToken &Tok = Parser.getTok(); 3281 if (Tok.isNot(AsmToken::Identifier)) 3282 return MatchOperand_NoMatch; 3283 3284 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c'); 3285 if (Reg == -1) 3286 return MatchOperand_NoMatch; 3287 3288 Parser.Lex(); // Eat identifier token. 3289 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S)); 3290 return MatchOperand_Success; 3291 } 3292 3293 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand. 3294 /// coproc_option : '{' imm0_255 '}' 3295 ARMAsmParser::OperandMatchResultTy 3296 ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) { 3297 MCAsmParser &Parser = getParser(); 3298 SMLoc S = Parser.getTok().getLoc(); 3299 3300 // If this isn't a '{', this isn't a coprocessor immediate operand. 3301 if (Parser.getTok().isNot(AsmToken::LCurly)) 3302 return MatchOperand_NoMatch; 3303 Parser.Lex(); // Eat the '{' 3304 3305 const MCExpr *Expr; 3306 SMLoc Loc = Parser.getTok().getLoc(); 3307 if (getParser().parseExpression(Expr)) { 3308 Error(Loc, "illegal expression"); 3309 return MatchOperand_ParseFail; 3310 } 3311 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); 3312 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) { 3313 Error(Loc, "coprocessor option must be an immediate in range [0, 255]"); 3314 return MatchOperand_ParseFail; 3315 } 3316 int Val = CE->getValue(); 3317 3318 // Check for and consume the closing '}' 3319 if (Parser.getTok().isNot(AsmToken::RCurly)) 3320 return MatchOperand_ParseFail; 3321 SMLoc E = Parser.getTok().getEndLoc(); 3322 Parser.Lex(); // Eat the '}' 3323 3324 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E)); 3325 return MatchOperand_Success; 3326 } 3327 3328 // For register list parsing, we need to map from raw GPR register numbering 3329 // to the enumeration values. The enumeration values aren't sorted by 3330 // register number due to our using "sp", "lr" and "pc" as canonical names. 3331 static unsigned getNextRegister(unsigned Reg) { 3332 // If this is a GPR, we need to do it manually, otherwise we can rely 3333 // on the sort ordering of the enumeration since the other reg-classes 3334 // are sane. 3335 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) 3336 return Reg + 1; 3337 switch(Reg) { 3338 default: llvm_unreachable("Invalid GPR number!"); 3339 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2; 3340 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4; 3341 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6; 3342 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8; 3343 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10; 3344 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12; 3345 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR; 3346 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0; 3347 } 3348 } 3349 3350 // Return the low-subreg of a given Q register. 3351 static unsigned getDRegFromQReg(unsigned QReg) { 3352 switch (QReg) { 3353 default: llvm_unreachable("expected a Q register!"); 3354 case ARM::Q0: return ARM::D0; 3355 case ARM::Q1: return ARM::D2; 3356 case ARM::Q2: return ARM::D4; 3357 case ARM::Q3: return ARM::D6; 3358 case ARM::Q4: return ARM::D8; 3359 case ARM::Q5: return ARM::D10; 3360 case ARM::Q6: return ARM::D12; 3361 case ARM::Q7: return ARM::D14; 3362 case ARM::Q8: return ARM::D16; 3363 case ARM::Q9: return ARM::D18; 3364 case ARM::Q10: return ARM::D20; 3365 case ARM::Q11: return ARM::D22; 3366 case ARM::Q12: return ARM::D24; 3367 case ARM::Q13: return ARM::D26; 3368 case ARM::Q14: return ARM::D28; 3369 case ARM::Q15: return ARM::D30; 3370 } 3371 } 3372 3373 /// Parse a register list. 3374 bool ARMAsmParser::parseRegisterList(OperandVector &Operands) { 3375 MCAsmParser &Parser = getParser(); 3376 assert(Parser.getTok().is(AsmToken::LCurly) && 3377 "Token is not a Left Curly Brace"); 3378 SMLoc S = Parser.getTok().getLoc(); 3379 Parser.Lex(); // Eat '{' token. 3380 SMLoc RegLoc = Parser.getTok().getLoc(); 3381 3382 // Check the first register in the list to see what register class 3383 // this is a list of. 3384 int Reg = tryParseRegister(); 3385 if (Reg == -1) 3386 return Error(RegLoc, "register expected"); 3387 3388 // The reglist instructions have at most 16 registers, so reserve 3389 // space for that many. 3390 int EReg = 0; 3391 SmallVector<std::pair<unsigned, unsigned>, 16> Registers; 3392 3393 // Allow Q regs and just interpret them as the two D sub-registers. 3394 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 3395 Reg = getDRegFromQReg(Reg); 3396 EReg = MRI->getEncodingValue(Reg); 3397 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); 3398 ++Reg; 3399 } 3400 const MCRegisterClass *RC; 3401 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) 3402 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID]; 3403 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) 3404 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID]; 3405 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg)) 3406 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID]; 3407 else 3408 return Error(RegLoc, "invalid register in register list"); 3409 3410 // Store the register. 3411 EReg = MRI->getEncodingValue(Reg); 3412 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); 3413 3414 // This starts immediately after the first register token in the list, 3415 // so we can see either a comma or a minus (range separator) as a legal 3416 // next token. 3417 while (Parser.getTok().is(AsmToken::Comma) || 3418 Parser.getTok().is(AsmToken::Minus)) { 3419 if (Parser.getTok().is(AsmToken::Minus)) { 3420 Parser.Lex(); // Eat the minus. 3421 SMLoc AfterMinusLoc = Parser.getTok().getLoc(); 3422 int EndReg = tryParseRegister(); 3423 if (EndReg == -1) 3424 return Error(AfterMinusLoc, "register expected"); 3425 // Allow Q regs and just interpret them as the two D sub-registers. 3426 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) 3427 EndReg = getDRegFromQReg(EndReg) + 1; 3428 // If the register is the same as the start reg, there's nothing 3429 // more to do. 3430 if (Reg == EndReg) 3431 continue; 3432 // The register must be in the same register class as the first. 3433 if (!RC->contains(EndReg)) 3434 return Error(AfterMinusLoc, "invalid register in register list"); 3435 // Ranges must go from low to high. 3436 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg)) 3437 return Error(AfterMinusLoc, "bad range in register list"); 3438 3439 // Add all the registers in the range to the register list. 3440 while (Reg != EndReg) { 3441 Reg = getNextRegister(Reg); 3442 EReg = MRI->getEncodingValue(Reg); 3443 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); 3444 } 3445 continue; 3446 } 3447 Parser.Lex(); // Eat the comma. 3448 RegLoc = Parser.getTok().getLoc(); 3449 int OldReg = Reg; 3450 const AsmToken RegTok = Parser.getTok(); 3451 Reg = tryParseRegister(); 3452 if (Reg == -1) 3453 return Error(RegLoc, "register expected"); 3454 // Allow Q regs and just interpret them as the two D sub-registers. 3455 bool isQReg = false; 3456 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 3457 Reg = getDRegFromQReg(Reg); 3458 isQReg = true; 3459 } 3460 // The register must be in the same register class as the first. 3461 if (!RC->contains(Reg)) 3462 return Error(RegLoc, "invalid register in register list"); 3463 // List must be monotonically increasing. 3464 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) { 3465 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) 3466 Warning(RegLoc, "register list not in ascending order"); 3467 else 3468 return Error(RegLoc, "register list not in ascending order"); 3469 } 3470 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) { 3471 Warning(RegLoc, "duplicated register (" + RegTok.getString() + 3472 ") in register list"); 3473 continue; 3474 } 3475 // VFP register lists must also be contiguous. 3476 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] && 3477 Reg != OldReg + 1) 3478 return Error(RegLoc, "non-contiguous register range"); 3479 EReg = MRI->getEncodingValue(Reg); 3480 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); 3481 if (isQReg) { 3482 EReg = MRI->getEncodingValue(++Reg); 3483 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); 3484 } 3485 } 3486 3487 if (Parser.getTok().isNot(AsmToken::RCurly)) 3488 return Error(Parser.getTok().getLoc(), "'}' expected"); 3489 SMLoc E = Parser.getTok().getEndLoc(); 3490 Parser.Lex(); // Eat '}' token. 3491 3492 // Push the register list operand. 3493 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E)); 3494 3495 // The ARM system instruction variants for LDM/STM have a '^' token here. 3496 if (Parser.getTok().is(AsmToken::Caret)) { 3497 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc())); 3498 Parser.Lex(); // Eat '^' token. 3499 } 3500 3501 return false; 3502 } 3503 3504 // Helper function to parse the lane index for vector lists. 3505 ARMAsmParser::OperandMatchResultTy ARMAsmParser:: 3506 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) { 3507 MCAsmParser &Parser = getParser(); 3508 Index = 0; // Always return a defined index value. 3509 if (Parser.getTok().is(AsmToken::LBrac)) { 3510 Parser.Lex(); // Eat the '['. 3511 if (Parser.getTok().is(AsmToken::RBrac)) { 3512 // "Dn[]" is the 'all lanes' syntax. 3513 LaneKind = AllLanes; 3514 EndLoc = Parser.getTok().getEndLoc(); 3515 Parser.Lex(); // Eat the ']'. 3516 return MatchOperand_Success; 3517 } 3518 3519 // There's an optional '#' token here. Normally there wouldn't be, but 3520 // inline assemble puts one in, and it's friendly to accept that. 3521 if (Parser.getTok().is(AsmToken::Hash)) 3522 Parser.Lex(); // Eat '#' or '$'. 3523 3524 const MCExpr *LaneIndex; 3525 SMLoc Loc = Parser.getTok().getLoc(); 3526 if (getParser().parseExpression(LaneIndex)) { 3527 Error(Loc, "illegal expression"); 3528 return MatchOperand_ParseFail; 3529 } 3530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex); 3531 if (!CE) { 3532 Error(Loc, "lane index must be empty or an integer"); 3533 return MatchOperand_ParseFail; 3534 } 3535 if (Parser.getTok().isNot(AsmToken::RBrac)) { 3536 Error(Parser.getTok().getLoc(), "']' expected"); 3537 return MatchOperand_ParseFail; 3538 } 3539 EndLoc = Parser.getTok().getEndLoc(); 3540 Parser.Lex(); // Eat the ']'. 3541 int64_t Val = CE->getValue(); 3542 3543 // FIXME: Make this range check context sensitive for .8, .16, .32. 3544 if (Val < 0 || Val > 7) { 3545 Error(Parser.getTok().getLoc(), "lane index out of range"); 3546 return MatchOperand_ParseFail; 3547 } 3548 Index = Val; 3549 LaneKind = IndexedLane; 3550 return MatchOperand_Success; 3551 } 3552 LaneKind = NoLanes; 3553 return MatchOperand_Success; 3554 } 3555 3556 // parse a vector register list 3557 ARMAsmParser::OperandMatchResultTy 3558 ARMAsmParser::parseVectorList(OperandVector &Operands) { 3559 MCAsmParser &Parser = getParser(); 3560 VectorLaneTy LaneKind; 3561 unsigned LaneIndex; 3562 SMLoc S = Parser.getTok().getLoc(); 3563 // As an extension (to match gas), support a plain D register or Q register 3564 // (without encosing curly braces) as a single or double entry list, 3565 // respectively. 3566 if (Parser.getTok().is(AsmToken::Identifier)) { 3567 SMLoc E = Parser.getTok().getEndLoc(); 3568 int Reg = tryParseRegister(); 3569 if (Reg == -1) 3570 return MatchOperand_NoMatch; 3571 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) { 3572 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); 3573 if (Res != MatchOperand_Success) 3574 return Res; 3575 switch (LaneKind) { 3576 case NoLanes: 3577 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E)); 3578 break; 3579 case AllLanes: 3580 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false, 3581 S, E)); 3582 break; 3583 case IndexedLane: 3584 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1, 3585 LaneIndex, 3586 false, S, E)); 3587 break; 3588 } 3589 return MatchOperand_Success; 3590 } 3591 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 3592 Reg = getDRegFromQReg(Reg); 3593 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); 3594 if (Res != MatchOperand_Success) 3595 return Res; 3596 switch (LaneKind) { 3597 case NoLanes: 3598 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, 3599 &ARMMCRegisterClasses[ARM::DPairRegClassID]); 3600 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E)); 3601 break; 3602 case AllLanes: 3603 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, 3604 &ARMMCRegisterClasses[ARM::DPairRegClassID]); 3605 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false, 3606 S, E)); 3607 break; 3608 case IndexedLane: 3609 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2, 3610 LaneIndex, 3611 false, S, E)); 3612 break; 3613 } 3614 return MatchOperand_Success; 3615 } 3616 Error(S, "vector register expected"); 3617 return MatchOperand_ParseFail; 3618 } 3619 3620 if (Parser.getTok().isNot(AsmToken::LCurly)) 3621 return MatchOperand_NoMatch; 3622 3623 Parser.Lex(); // Eat '{' token. 3624 SMLoc RegLoc = Parser.getTok().getLoc(); 3625 3626 int Reg = tryParseRegister(); 3627 if (Reg == -1) { 3628 Error(RegLoc, "register expected"); 3629 return MatchOperand_ParseFail; 3630 } 3631 unsigned Count = 1; 3632 int Spacing = 0; 3633 unsigned FirstReg = Reg; 3634 // The list is of D registers, but we also allow Q regs and just interpret 3635 // them as the two D sub-registers. 3636 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 3637 FirstReg = Reg = getDRegFromQReg(Reg); 3638 Spacing = 1; // double-spacing requires explicit D registers, otherwise 3639 // it's ambiguous with four-register single spaced. 3640 ++Reg; 3641 ++Count; 3642 } 3643 3644 SMLoc E; 3645 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success) 3646 return MatchOperand_ParseFail; 3647 3648 while (Parser.getTok().is(AsmToken::Comma) || 3649 Parser.getTok().is(AsmToken::Minus)) { 3650 if (Parser.getTok().is(AsmToken::Minus)) { 3651 if (!Spacing) 3652 Spacing = 1; // Register range implies a single spaced list. 3653 else if (Spacing == 2) { 3654 Error(Parser.getTok().getLoc(), 3655 "sequential registers in double spaced list"); 3656 return MatchOperand_ParseFail; 3657 } 3658 Parser.Lex(); // Eat the minus. 3659 SMLoc AfterMinusLoc = Parser.getTok().getLoc(); 3660 int EndReg = tryParseRegister(); 3661 if (EndReg == -1) { 3662 Error(AfterMinusLoc, "register expected"); 3663 return MatchOperand_ParseFail; 3664 } 3665 // Allow Q regs and just interpret them as the two D sub-registers. 3666 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) 3667 EndReg = getDRegFromQReg(EndReg) + 1; 3668 // If the register is the same as the start reg, there's nothing 3669 // more to do. 3670 if (Reg == EndReg) 3671 continue; 3672 // The register must be in the same register class as the first. 3673 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) { 3674 Error(AfterMinusLoc, "invalid register in register list"); 3675 return MatchOperand_ParseFail; 3676 } 3677 // Ranges must go from low to high. 3678 if (Reg > EndReg) { 3679 Error(AfterMinusLoc, "bad range in register list"); 3680 return MatchOperand_ParseFail; 3681 } 3682 // Parse the lane specifier if present. 3683 VectorLaneTy NextLaneKind; 3684 unsigned NextLaneIndex; 3685 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != 3686 MatchOperand_Success) 3687 return MatchOperand_ParseFail; 3688 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { 3689 Error(AfterMinusLoc, "mismatched lane index in register list"); 3690 return MatchOperand_ParseFail; 3691 } 3692 3693 // Add all the registers in the range to the register list. 3694 Count += EndReg - Reg; 3695 Reg = EndReg; 3696 continue; 3697 } 3698 Parser.Lex(); // Eat the comma. 3699 RegLoc = Parser.getTok().getLoc(); 3700 int OldReg = Reg; 3701 Reg = tryParseRegister(); 3702 if (Reg == -1) { 3703 Error(RegLoc, "register expected"); 3704 return MatchOperand_ParseFail; 3705 } 3706 // vector register lists must be contiguous. 3707 // It's OK to use the enumeration values directly here rather, as the 3708 // VFP register classes have the enum sorted properly. 3709 // 3710 // The list is of D registers, but we also allow Q regs and just interpret 3711 // them as the two D sub-registers. 3712 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { 3713 if (!Spacing) 3714 Spacing = 1; // Register range implies a single spaced list. 3715 else if (Spacing == 2) { 3716 Error(RegLoc, 3717 "invalid register in double-spaced list (must be 'D' register')"); 3718 return MatchOperand_ParseFail; 3719 } 3720 Reg = getDRegFromQReg(Reg); 3721 if (Reg != OldReg + 1) { 3722 Error(RegLoc, "non-contiguous register range"); 3723 return MatchOperand_ParseFail; 3724 } 3725 ++Reg; 3726 Count += 2; 3727 // Parse the lane specifier if present. 3728 VectorLaneTy NextLaneKind; 3729 unsigned NextLaneIndex; 3730 SMLoc LaneLoc = Parser.getTok().getLoc(); 3731 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != 3732 MatchOperand_Success) 3733 return MatchOperand_ParseFail; 3734 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { 3735 Error(LaneLoc, "mismatched lane index in register list"); 3736 return MatchOperand_ParseFail; 3737 } 3738 continue; 3739 } 3740 // Normal D register. 3741 // Figure out the register spacing (single or double) of the list if 3742 // we don't know it already. 3743 if (!Spacing) 3744 Spacing = 1 + (Reg == OldReg + 2); 3745 3746 // Just check that it's contiguous and keep going. 3747 if (Reg != OldReg + Spacing) { 3748 Error(RegLoc, "non-contiguous register range"); 3749 return MatchOperand_ParseFail; 3750 } 3751 ++Count; 3752 // Parse the lane specifier if present. 3753 VectorLaneTy NextLaneKind; 3754 unsigned NextLaneIndex; 3755 SMLoc EndLoc = Parser.getTok().getLoc(); 3756 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success) 3757 return MatchOperand_ParseFail; 3758 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { 3759 Error(EndLoc, "mismatched lane index in register list"); 3760 return MatchOperand_ParseFail; 3761 } 3762 } 3763 3764 if (Parser.getTok().isNot(AsmToken::RCurly)) { 3765 Error(Parser.getTok().getLoc(), "'}' expected"); 3766 return MatchOperand_ParseFail; 3767 } 3768 E = Parser.getTok().getEndLoc(); 3769 Parser.Lex(); // Eat '}' token. 3770 3771 switch (LaneKind) { 3772 case NoLanes: 3773 // Two-register operands have been converted to the 3774 // composite register classes. 3775 if (Count == 2) { 3776 const MCRegisterClass *RC = (Spacing == 1) ? 3777 &ARMMCRegisterClasses[ARM::DPairRegClassID] : 3778 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; 3779 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); 3780 } 3781 3782 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count, 3783 (Spacing == 2), S, E)); 3784 break; 3785 case AllLanes: 3786 // Two-register operands have been converted to the 3787 // composite register classes. 3788 if (Count == 2) { 3789 const MCRegisterClass *RC = (Spacing == 1) ? 3790 &ARMMCRegisterClasses[ARM::DPairRegClassID] : 3791 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; 3792 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); 3793 } 3794 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count, 3795 (Spacing == 2), 3796 S, E)); 3797 break; 3798 case IndexedLane: 3799 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count, 3800 LaneIndex, 3801 (Spacing == 2), 3802 S, E)); 3803 break; 3804 } 3805 return MatchOperand_Success; 3806 } 3807 3808 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options. 3809 ARMAsmParser::OperandMatchResultTy 3810 ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) { 3811 MCAsmParser &Parser = getParser(); 3812 SMLoc S = Parser.getTok().getLoc(); 3813 const AsmToken &Tok = Parser.getTok(); 3814 unsigned Opt; 3815 3816 if (Tok.is(AsmToken::Identifier)) { 3817 StringRef OptStr = Tok.getString(); 3818 3819 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower()) 3820 .Case("sy", ARM_MB::SY) 3821 .Case("st", ARM_MB::ST) 3822 .Case("ld", ARM_MB::LD) 3823 .Case("sh", ARM_MB::ISH) 3824 .Case("ish", ARM_MB::ISH) 3825 .Case("shst", ARM_MB::ISHST) 3826 .Case("ishst", ARM_MB::ISHST) 3827 .Case("ishld", ARM_MB::ISHLD) 3828 .Case("nsh", ARM_MB::NSH) 3829 .Case("un", ARM_MB::NSH) 3830 .Case("nshst", ARM_MB::NSHST) 3831 .Case("nshld", ARM_MB::NSHLD) 3832 .Case("unst", ARM_MB::NSHST) 3833 .Case("osh", ARM_MB::OSH) 3834 .Case("oshst", ARM_MB::OSHST) 3835 .Case("oshld", ARM_MB::OSHLD) 3836 .Default(~0U); 3837 3838 // ishld, oshld, nshld and ld are only available from ARMv8. 3839 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD || 3840 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD)) 3841 Opt = ~0U; 3842 3843 if (Opt == ~0U) 3844 return MatchOperand_NoMatch; 3845 3846 Parser.Lex(); // Eat identifier token. 3847 } else if (Tok.is(AsmToken::Hash) || 3848 Tok.is(AsmToken::Dollar) || 3849 Tok.is(AsmToken::Integer)) { 3850 if (Parser.getTok().isNot(AsmToken::Integer)) 3851 Parser.Lex(); // Eat '#' or '$'. 3852 SMLoc Loc = Parser.getTok().getLoc(); 3853 3854 const MCExpr *MemBarrierID; 3855 if (getParser().parseExpression(MemBarrierID)) { 3856 Error(Loc, "illegal expression"); 3857 return MatchOperand_ParseFail; 3858 } 3859 3860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID); 3861 if (!CE) { 3862 Error(Loc, "constant expression expected"); 3863 return MatchOperand_ParseFail; 3864 } 3865 3866 int Val = CE->getValue(); 3867 if (Val & ~0xf) { 3868 Error(Loc, "immediate value out of range"); 3869 return MatchOperand_ParseFail; 3870 } 3871 3872 Opt = ARM_MB::RESERVED_0 + Val; 3873 } else 3874 return MatchOperand_ParseFail; 3875 3876 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S)); 3877 return MatchOperand_Success; 3878 } 3879 3880 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options. 3881 ARMAsmParser::OperandMatchResultTy 3882 ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) { 3883 MCAsmParser &Parser = getParser(); 3884 SMLoc S = Parser.getTok().getLoc(); 3885 const AsmToken &Tok = Parser.getTok(); 3886 unsigned Opt; 3887 3888 if (Tok.is(AsmToken::Identifier)) { 3889 StringRef OptStr = Tok.getString(); 3890 3891 if (OptStr.equals_lower("sy")) 3892 Opt = ARM_ISB::SY; 3893 else 3894 return MatchOperand_NoMatch; 3895 3896 Parser.Lex(); // Eat identifier token. 3897 } else if (Tok.is(AsmToken::Hash) || 3898 Tok.is(AsmToken::Dollar) || 3899 Tok.is(AsmToken::Integer)) { 3900 if (Parser.getTok().isNot(AsmToken::Integer)) 3901 Parser.Lex(); // Eat '#' or '$'. 3902 SMLoc Loc = Parser.getTok().getLoc(); 3903 3904 const MCExpr *ISBarrierID; 3905 if (getParser().parseExpression(ISBarrierID)) { 3906 Error(Loc, "illegal expression"); 3907 return MatchOperand_ParseFail; 3908 } 3909 3910 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID); 3911 if (!CE) { 3912 Error(Loc, "constant expression expected"); 3913 return MatchOperand_ParseFail; 3914 } 3915 3916 int Val = CE->getValue(); 3917 if (Val & ~0xf) { 3918 Error(Loc, "immediate value out of range"); 3919 return MatchOperand_ParseFail; 3920 } 3921 3922 Opt = ARM_ISB::RESERVED_0 + Val; 3923 } else 3924 return MatchOperand_ParseFail; 3925 3926 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt( 3927 (ARM_ISB::InstSyncBOpt)Opt, S)); 3928 return MatchOperand_Success; 3929 } 3930 3931 3932 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction. 3933 ARMAsmParser::OperandMatchResultTy 3934 ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) { 3935 MCAsmParser &Parser = getParser(); 3936 SMLoc S = Parser.getTok().getLoc(); 3937 const AsmToken &Tok = Parser.getTok(); 3938 if (!Tok.is(AsmToken::Identifier)) 3939 return MatchOperand_NoMatch; 3940 StringRef IFlagsStr = Tok.getString(); 3941 3942 // An iflags string of "none" is interpreted to mean that none of the AIF 3943 // bits are set. Not a terribly useful instruction, but a valid encoding. 3944 unsigned IFlags = 0; 3945 if (IFlagsStr != "none") { 3946 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) { 3947 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1)) 3948 .Case("a", ARM_PROC::A) 3949 .Case("i", ARM_PROC::I) 3950 .Case("f", ARM_PROC::F) 3951 .Default(~0U); 3952 3953 // If some specific iflag is already set, it means that some letter is 3954 // present more than once, this is not acceptable. 3955 if (Flag == ~0U || (IFlags & Flag)) 3956 return MatchOperand_NoMatch; 3957 3958 IFlags |= Flag; 3959 } 3960 } 3961 3962 Parser.Lex(); // Eat identifier token. 3963 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S)); 3964 return MatchOperand_Success; 3965 } 3966 3967 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction. 3968 ARMAsmParser::OperandMatchResultTy 3969 ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) { 3970 MCAsmParser &Parser = getParser(); 3971 SMLoc S = Parser.getTok().getLoc(); 3972 const AsmToken &Tok = Parser.getTok(); 3973 if (!Tok.is(AsmToken::Identifier)) 3974 return MatchOperand_NoMatch; 3975 StringRef Mask = Tok.getString(); 3976 3977 if (isMClass()) { 3978 // See ARMv6-M 10.1.1 3979 std::string Name = Mask.lower(); 3980 unsigned FlagsVal = StringSwitch<unsigned>(Name) 3981 // Note: in the documentation: 3982 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias 3983 // for MSR APSR_nzcvq. 3984 // but we do make it an alias here. This is so to get the "mask encoding" 3985 // bits correct on MSR APSR writes. 3986 // 3987 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers 3988 // should really only be allowed when writing a special register. Note 3989 // they get dropped in the MRS instruction reading a special register as 3990 // the SYSm field is only 8 bits. 3991 .Case("apsr", 0x800) 3992 .Case("apsr_nzcvq", 0x800) 3993 .Case("apsr_g", 0x400) 3994 .Case("apsr_nzcvqg", 0xc00) 3995 .Case("iapsr", 0x801) 3996 .Case("iapsr_nzcvq", 0x801) 3997 .Case("iapsr_g", 0x401) 3998 .Case("iapsr_nzcvqg", 0xc01) 3999 .Case("eapsr", 0x802) 4000 .Case("eapsr_nzcvq", 0x802) 4001 .Case("eapsr_g", 0x402) 4002 .Case("eapsr_nzcvqg", 0xc02) 4003 .Case("xpsr", 0x803) 4004 .Case("xpsr_nzcvq", 0x803) 4005 .Case("xpsr_g", 0x403) 4006 .Case("xpsr_nzcvqg", 0xc03) 4007 .Case("ipsr", 0x805) 4008 .Case("epsr", 0x806) 4009 .Case("iepsr", 0x807) 4010 .Case("msp", 0x808) 4011 .Case("psp", 0x809) 4012 .Case("primask", 0x810) 4013 .Case("basepri", 0x811) 4014 .Case("basepri_max", 0x812) 4015 .Case("faultmask", 0x813) 4016 .Case("control", 0x814) 4017 .Case("msplim", 0x80a) 4018 .Case("psplim", 0x80b) 4019 .Case("msp_ns", 0x888) 4020 .Case("psp_ns", 0x889) 4021 .Case("msplim_ns", 0x88a) 4022 .Case("psplim_ns", 0x88b) 4023 .Case("primask_ns", 0x890) 4024 .Case("basepri_ns", 0x891) 4025 .Case("basepri_max_ns", 0x892) 4026 .Case("faultmask_ns", 0x893) 4027 .Case("control_ns", 0x894) 4028 .Case("sp_ns", 0x898) 4029 .Default(~0U); 4030 4031 if (FlagsVal == ~0U) 4032 return MatchOperand_NoMatch; 4033 4034 if (!hasDSP() && (FlagsVal & 0x400)) 4035 // The _g and _nzcvqg versions are only valid if the DSP extension is 4036 // available. 4037 return MatchOperand_NoMatch; 4038 4039 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813) 4040 // basepri, basepri_max and faultmask only valid for V7m. 4041 return MatchOperand_NoMatch; 4042 4043 if (!has8MSecExt() && (FlagsVal == 0x80a || FlagsVal == 0x80b || 4044 (FlagsVal > 0x814 && FlagsVal < 0xc00))) 4045 return MatchOperand_NoMatch; 4046 4047 if (!hasV8MMainline() && (FlagsVal == 0x88a || FlagsVal == 0x88b || 4048 (FlagsVal > 0x890 && FlagsVal <= 0x893))) 4049 return MatchOperand_NoMatch; 4050 4051 Parser.Lex(); // Eat identifier token. 4052 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); 4053 return MatchOperand_Success; 4054 } 4055 4056 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf" 4057 size_t Start = 0, Next = Mask.find('_'); 4058 StringRef Flags = ""; 4059 std::string SpecReg = Mask.slice(Start, Next).lower(); 4060 if (Next != StringRef::npos) 4061 Flags = Mask.slice(Next+1, Mask.size()); 4062 4063 // FlagsVal contains the complete mask: 4064 // 3-0: Mask 4065 // 4: Special Reg (cpsr, apsr => 0; spsr => 1) 4066 unsigned FlagsVal = 0; 4067 4068 if (SpecReg == "apsr") { 4069 FlagsVal = StringSwitch<unsigned>(Flags) 4070 .Case("nzcvq", 0x8) // same as CPSR_f 4071 .Case("g", 0x4) // same as CPSR_s 4072 .Case("nzcvqg", 0xc) // same as CPSR_fs 4073 .Default(~0U); 4074 4075 if (FlagsVal == ~0U) { 4076 if (!Flags.empty()) 4077 return MatchOperand_NoMatch; 4078 else 4079 FlagsVal = 8; // No flag 4080 } 4081 } else if (SpecReg == "cpsr" || SpecReg == "spsr") { 4082 // cpsr_all is an alias for cpsr_fc, as is plain cpsr. 4083 if (Flags == "all" || Flags == "") 4084 Flags = "fc"; 4085 for (int i = 0, e = Flags.size(); i != e; ++i) { 4086 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1)) 4087 .Case("c", 1) 4088 .Case("x", 2) 4089 .Case("s", 4) 4090 .Case("f", 8) 4091 .Default(~0U); 4092 4093 // If some specific flag is already set, it means that some letter is 4094 // present more than once, this is not acceptable. 4095 if (FlagsVal == ~0U || (FlagsVal & Flag)) 4096 return MatchOperand_NoMatch; 4097 FlagsVal |= Flag; 4098 } 4099 } else // No match for special register. 4100 return MatchOperand_NoMatch; 4101 4102 // Special register without flags is NOT equivalent to "fc" flags. 4103 // NOTE: This is a divergence from gas' behavior. Uncommenting the following 4104 // two lines would enable gas compatibility at the expense of breaking 4105 // round-tripping. 4106 // 4107 // if (!FlagsVal) 4108 // FlagsVal = 0x9; 4109 4110 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1) 4111 if (SpecReg == "spsr") 4112 FlagsVal |= 16; 4113 4114 Parser.Lex(); // Eat identifier token. 4115 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); 4116 return MatchOperand_Success; 4117 } 4118 4119 /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for 4120 /// use in the MRS/MSR instructions added to support virtualization. 4121 ARMAsmParser::OperandMatchResultTy 4122 ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) { 4123 MCAsmParser &Parser = getParser(); 4124 SMLoc S = Parser.getTok().getLoc(); 4125 const AsmToken &Tok = Parser.getTok(); 4126 if (!Tok.is(AsmToken::Identifier)) 4127 return MatchOperand_NoMatch; 4128 StringRef RegName = Tok.getString(); 4129 4130 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM 4131 // and bit 5 is R. 4132 unsigned Encoding = StringSwitch<unsigned>(RegName.lower()) 4133 .Case("r8_usr", 0x00) 4134 .Case("r9_usr", 0x01) 4135 .Case("r10_usr", 0x02) 4136 .Case("r11_usr", 0x03) 4137 .Case("r12_usr", 0x04) 4138 .Case("sp_usr", 0x05) 4139 .Case("lr_usr", 0x06) 4140 .Case("r8_fiq", 0x08) 4141 .Case("r9_fiq", 0x09) 4142 .Case("r10_fiq", 0x0a) 4143 .Case("r11_fiq", 0x0b) 4144 .Case("r12_fiq", 0x0c) 4145 .Case("sp_fiq", 0x0d) 4146 .Case("lr_fiq", 0x0e) 4147 .Case("lr_irq", 0x10) 4148 .Case("sp_irq", 0x11) 4149 .Case("lr_svc", 0x12) 4150 .Case("sp_svc", 0x13) 4151 .Case("lr_abt", 0x14) 4152 .Case("sp_abt", 0x15) 4153 .Case("lr_und", 0x16) 4154 .Case("sp_und", 0x17) 4155 .Case("lr_mon", 0x1c) 4156 .Case("sp_mon", 0x1d) 4157 .Case("elr_hyp", 0x1e) 4158 .Case("sp_hyp", 0x1f) 4159 .Case("spsr_fiq", 0x2e) 4160 .Case("spsr_irq", 0x30) 4161 .Case("spsr_svc", 0x32) 4162 .Case("spsr_abt", 0x34) 4163 .Case("spsr_und", 0x36) 4164 .Case("spsr_mon", 0x3c) 4165 .Case("spsr_hyp", 0x3e) 4166 .Default(~0U); 4167 4168 if (Encoding == ~0U) 4169 return MatchOperand_NoMatch; 4170 4171 Parser.Lex(); // Eat identifier token. 4172 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S)); 4173 return MatchOperand_Success; 4174 } 4175 4176 ARMAsmParser::OperandMatchResultTy 4177 ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low, 4178 int High) { 4179 MCAsmParser &Parser = getParser(); 4180 const AsmToken &Tok = Parser.getTok(); 4181 if (Tok.isNot(AsmToken::Identifier)) { 4182 Error(Parser.getTok().getLoc(), Op + " operand expected."); 4183 return MatchOperand_ParseFail; 4184 } 4185 StringRef ShiftName = Tok.getString(); 4186 std::string LowerOp = Op.lower(); 4187 std::string UpperOp = Op.upper(); 4188 if (ShiftName != LowerOp && ShiftName != UpperOp) { 4189 Error(Parser.getTok().getLoc(), Op + " operand expected."); 4190 return MatchOperand_ParseFail; 4191 } 4192 Parser.Lex(); // Eat shift type token. 4193 4194 // There must be a '#' and a shift amount. 4195 if (Parser.getTok().isNot(AsmToken::Hash) && 4196 Parser.getTok().isNot(AsmToken::Dollar)) { 4197 Error(Parser.getTok().getLoc(), "'#' expected"); 4198 return MatchOperand_ParseFail; 4199 } 4200 Parser.Lex(); // Eat hash token. 4201 4202 const MCExpr *ShiftAmount; 4203 SMLoc Loc = Parser.getTok().getLoc(); 4204 SMLoc EndLoc; 4205 if (getParser().parseExpression(ShiftAmount, EndLoc)) { 4206 Error(Loc, "illegal expression"); 4207 return MatchOperand_ParseFail; 4208 } 4209 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); 4210 if (!CE) { 4211 Error(Loc, "constant expression expected"); 4212 return MatchOperand_ParseFail; 4213 } 4214 int Val = CE->getValue(); 4215 if (Val < Low || Val > High) { 4216 Error(Loc, "immediate value out of range"); 4217 return MatchOperand_ParseFail; 4218 } 4219 4220 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc)); 4221 4222 return MatchOperand_Success; 4223 } 4224 4225 ARMAsmParser::OperandMatchResultTy 4226 ARMAsmParser::parseSetEndImm(OperandVector &Operands) { 4227 MCAsmParser &Parser = getParser(); 4228 const AsmToken &Tok = Parser.getTok(); 4229 SMLoc S = Tok.getLoc(); 4230 if (Tok.isNot(AsmToken::Identifier)) { 4231 Error(S, "'be' or 'le' operand expected"); 4232 return MatchOperand_ParseFail; 4233 } 4234 int Val = StringSwitch<int>(Tok.getString().lower()) 4235 .Case("be", 1) 4236 .Case("le", 0) 4237 .Default(-1); 4238 Parser.Lex(); // Eat the token. 4239 4240 if (Val == -1) { 4241 Error(S, "'be' or 'le' operand expected"); 4242 return MatchOperand_ParseFail; 4243 } 4244 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::create(Val, 4245 getContext()), 4246 S, Tok.getEndLoc())); 4247 return MatchOperand_Success; 4248 } 4249 4250 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT 4251 /// instructions. Legal values are: 4252 /// lsl #n 'n' in [0,31] 4253 /// asr #n 'n' in [1,32] 4254 /// n == 32 encoded as n == 0. 4255 ARMAsmParser::OperandMatchResultTy 4256 ARMAsmParser::parseShifterImm(OperandVector &Operands) { 4257 MCAsmParser &Parser = getParser(); 4258 const AsmToken &Tok = Parser.getTok(); 4259 SMLoc S = Tok.getLoc(); 4260 if (Tok.isNot(AsmToken::Identifier)) { 4261 Error(S, "shift operator 'asr' or 'lsl' expected"); 4262 return MatchOperand_ParseFail; 4263 } 4264 StringRef ShiftName = Tok.getString(); 4265 bool isASR; 4266 if (ShiftName == "lsl" || ShiftName == "LSL") 4267 isASR = false; 4268 else if (ShiftName == "asr" || ShiftName == "ASR") 4269 isASR = true; 4270 else { 4271 Error(S, "shift operator 'asr' or 'lsl' expected"); 4272 return MatchOperand_ParseFail; 4273 } 4274 Parser.Lex(); // Eat the operator. 4275 4276 // A '#' and a shift amount. 4277 if (Parser.getTok().isNot(AsmToken::Hash) && 4278 Parser.getTok().isNot(AsmToken::Dollar)) { 4279 Error(Parser.getTok().getLoc(), "'#' expected"); 4280 return MatchOperand_ParseFail; 4281 } 4282 Parser.Lex(); // Eat hash token. 4283 SMLoc ExLoc = Parser.getTok().getLoc(); 4284 4285 const MCExpr *ShiftAmount; 4286 SMLoc EndLoc; 4287 if (getParser().parseExpression(ShiftAmount, EndLoc)) { 4288 Error(ExLoc, "malformed shift expression"); 4289 return MatchOperand_ParseFail; 4290 } 4291 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); 4292 if (!CE) { 4293 Error(ExLoc, "shift amount must be an immediate"); 4294 return MatchOperand_ParseFail; 4295 } 4296 4297 int64_t Val = CE->getValue(); 4298 if (isASR) { 4299 // Shift amount must be in [1,32] 4300 if (Val < 1 || Val > 32) { 4301 Error(ExLoc, "'asr' shift amount must be in range [1,32]"); 4302 return MatchOperand_ParseFail; 4303 } 4304 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode. 4305 if (isThumb() && Val == 32) { 4306 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode"); 4307 return MatchOperand_ParseFail; 4308 } 4309 if (Val == 32) Val = 0; 4310 } else { 4311 // Shift amount must be in [1,32] 4312 if (Val < 0 || Val > 31) { 4313 Error(ExLoc, "'lsr' shift amount must be in range [0,31]"); 4314 return MatchOperand_ParseFail; 4315 } 4316 } 4317 4318 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc)); 4319 4320 return MatchOperand_Success; 4321 } 4322 4323 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family 4324 /// of instructions. Legal values are: 4325 /// ror #n 'n' in {0, 8, 16, 24} 4326 ARMAsmParser::OperandMatchResultTy 4327 ARMAsmParser::parseRotImm(OperandVector &Operands) { 4328 MCAsmParser &Parser = getParser(); 4329 const AsmToken &Tok = Parser.getTok(); 4330 SMLoc S = Tok.getLoc(); 4331 if (Tok.isNot(AsmToken::Identifier)) 4332 return MatchOperand_NoMatch; 4333 StringRef ShiftName = Tok.getString(); 4334 if (ShiftName != "ror" && ShiftName != "ROR") 4335 return MatchOperand_NoMatch; 4336 Parser.Lex(); // Eat the operator. 4337 4338 // A '#' and a rotate amount. 4339 if (Parser.getTok().isNot(AsmToken::Hash) && 4340 Parser.getTok().isNot(AsmToken::Dollar)) { 4341 Error(Parser.getTok().getLoc(), "'#' expected"); 4342 return MatchOperand_ParseFail; 4343 } 4344 Parser.Lex(); // Eat hash token. 4345 SMLoc ExLoc = Parser.getTok().getLoc(); 4346 4347 const MCExpr *ShiftAmount; 4348 SMLoc EndLoc; 4349 if (getParser().parseExpression(ShiftAmount, EndLoc)) { 4350 Error(ExLoc, "malformed rotate expression"); 4351 return MatchOperand_ParseFail; 4352 } 4353 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); 4354 if (!CE) { 4355 Error(ExLoc, "rotate amount must be an immediate"); 4356 return MatchOperand_ParseFail; 4357 } 4358 4359 int64_t Val = CE->getValue(); 4360 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension) 4361 // normally, zero is represented in asm by omitting the rotate operand 4362 // entirely. 4363 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) { 4364 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24"); 4365 return MatchOperand_ParseFail; 4366 } 4367 4368 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc)); 4369 4370 return MatchOperand_Success; 4371 } 4372 4373 ARMAsmParser::OperandMatchResultTy 4374 ARMAsmParser::parseModImm(OperandVector &Operands) { 4375 MCAsmParser &Parser = getParser(); 4376 MCAsmLexer &Lexer = getLexer(); 4377 int64_t Imm1, Imm2; 4378 4379 SMLoc S = Parser.getTok().getLoc(); 4380 4381 // 1) A mod_imm operand can appear in the place of a register name: 4382 // add r0, #mod_imm 4383 // add r0, r0, #mod_imm 4384 // to correctly handle the latter, we bail out as soon as we see an 4385 // identifier. 4386 // 4387 // 2) Similarly, we do not want to parse into complex operands: 4388 // mov r0, #mod_imm 4389 // mov r0, :lower16:(_foo) 4390 if (Parser.getTok().is(AsmToken::Identifier) || 4391 Parser.getTok().is(AsmToken::Colon)) 4392 return MatchOperand_NoMatch; 4393 4394 // Hash (dollar) is optional as per the ARMARM 4395 if (Parser.getTok().is(AsmToken::Hash) || 4396 Parser.getTok().is(AsmToken::Dollar)) { 4397 // Avoid parsing into complex operands (#:) 4398 if (Lexer.peekTok().is(AsmToken::Colon)) 4399 return MatchOperand_NoMatch; 4400 4401 // Eat the hash (dollar) 4402 Parser.Lex(); 4403 } 4404 4405 SMLoc Sx1, Ex1; 4406 Sx1 = Parser.getTok().getLoc(); 4407 const MCExpr *Imm1Exp; 4408 if (getParser().parseExpression(Imm1Exp, Ex1)) { 4409 Error(Sx1, "malformed expression"); 4410 return MatchOperand_ParseFail; 4411 } 4412 4413 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp); 4414 4415 if (CE) { 4416 // Immediate must fit within 32-bits 4417 Imm1 = CE->getValue(); 4418 int Enc = ARM_AM::getSOImmVal(Imm1); 4419 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) { 4420 // We have a match! 4421 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF), 4422 (Enc & 0xF00) >> 7, 4423 Sx1, Ex1)); 4424 return MatchOperand_Success; 4425 } 4426 4427 // We have parsed an immediate which is not for us, fallback to a plain 4428 // immediate. This can happen for instruction aliases. For an example, 4429 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform 4430 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite 4431 // instruction with a mod_imm operand. The alias is defined such that the 4432 // parser method is shared, that's why we have to do this here. 4433 if (Parser.getTok().is(AsmToken::EndOfStatement)) { 4434 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1)); 4435 return MatchOperand_Success; 4436 } 4437 } else { 4438 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an 4439 // MCFixup). Fallback to a plain immediate. 4440 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1)); 4441 return MatchOperand_Success; 4442 } 4443 4444 // From this point onward, we expect the input to be a (#bits, #rot) pair 4445 if (Parser.getTok().isNot(AsmToken::Comma)) { 4446 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]"); 4447 return MatchOperand_ParseFail; 4448 } 4449 4450 if (Imm1 & ~0xFF) { 4451 Error(Sx1, "immediate operand must a number in the range [0, 255]"); 4452 return MatchOperand_ParseFail; 4453 } 4454 4455 // Eat the comma 4456 Parser.Lex(); 4457 4458 // Repeat for #rot 4459 SMLoc Sx2, Ex2; 4460 Sx2 = Parser.getTok().getLoc(); 4461 4462 // Eat the optional hash (dollar) 4463 if (Parser.getTok().is(AsmToken::Hash) || 4464 Parser.getTok().is(AsmToken::Dollar)) 4465 Parser.Lex(); 4466 4467 const MCExpr *Imm2Exp; 4468 if (getParser().parseExpression(Imm2Exp, Ex2)) { 4469 Error(Sx2, "malformed expression"); 4470 return MatchOperand_ParseFail; 4471 } 4472 4473 CE = dyn_cast<MCConstantExpr>(Imm2Exp); 4474 4475 if (CE) { 4476 Imm2 = CE->getValue(); 4477 if (!(Imm2 & ~0x1E)) { 4478 // We have a match! 4479 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2)); 4480 return MatchOperand_Success; 4481 } 4482 Error(Sx2, "immediate operand must an even number in the range [0, 30]"); 4483 return MatchOperand_ParseFail; 4484 } else { 4485 Error(Sx2, "constant expression expected"); 4486 return MatchOperand_ParseFail; 4487 } 4488 } 4489 4490 ARMAsmParser::OperandMatchResultTy 4491 ARMAsmParser::parseBitfield(OperandVector &Operands) { 4492 MCAsmParser &Parser = getParser(); 4493 SMLoc S = Parser.getTok().getLoc(); 4494 // The bitfield descriptor is really two operands, the LSB and the width. 4495 if (Parser.getTok().isNot(AsmToken::Hash) && 4496 Parser.getTok().isNot(AsmToken::Dollar)) { 4497 Error(Parser.getTok().getLoc(), "'#' expected"); 4498 return MatchOperand_ParseFail; 4499 } 4500 Parser.Lex(); // Eat hash token. 4501 4502 const MCExpr *LSBExpr; 4503 SMLoc E = Parser.getTok().getLoc(); 4504 if (getParser().parseExpression(LSBExpr)) { 4505 Error(E, "malformed immediate expression"); 4506 return MatchOperand_ParseFail; 4507 } 4508 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr); 4509 if (!CE) { 4510 Error(E, "'lsb' operand must be an immediate"); 4511 return MatchOperand_ParseFail; 4512 } 4513 4514 int64_t LSB = CE->getValue(); 4515 // The LSB must be in the range [0,31] 4516 if (LSB < 0 || LSB > 31) { 4517 Error(E, "'lsb' operand must be in the range [0,31]"); 4518 return MatchOperand_ParseFail; 4519 } 4520 E = Parser.getTok().getLoc(); 4521 4522 // Expect another immediate operand. 4523 if (Parser.getTok().isNot(AsmToken::Comma)) { 4524 Error(Parser.getTok().getLoc(), "too few operands"); 4525 return MatchOperand_ParseFail; 4526 } 4527 Parser.Lex(); // Eat hash token. 4528 if (Parser.getTok().isNot(AsmToken::Hash) && 4529 Parser.getTok().isNot(AsmToken::Dollar)) { 4530 Error(Parser.getTok().getLoc(), "'#' expected"); 4531 return MatchOperand_ParseFail; 4532 } 4533 Parser.Lex(); // Eat hash token. 4534 4535 const MCExpr *WidthExpr; 4536 SMLoc EndLoc; 4537 if (getParser().parseExpression(WidthExpr, EndLoc)) { 4538 Error(E, "malformed immediate expression"); 4539 return MatchOperand_ParseFail; 4540 } 4541 CE = dyn_cast<MCConstantExpr>(WidthExpr); 4542 if (!CE) { 4543 Error(E, "'width' operand must be an immediate"); 4544 return MatchOperand_ParseFail; 4545 } 4546 4547 int64_t Width = CE->getValue(); 4548 // The LSB must be in the range [1,32-lsb] 4549 if (Width < 1 || Width > 32 - LSB) { 4550 Error(E, "'width' operand must be in the range [1,32-lsb]"); 4551 return MatchOperand_ParseFail; 4552 } 4553 4554 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc)); 4555 4556 return MatchOperand_Success; 4557 } 4558 4559 ARMAsmParser::OperandMatchResultTy 4560 ARMAsmParser::parsePostIdxReg(OperandVector &Operands) { 4561 // Check for a post-index addressing register operand. Specifically: 4562 // postidx_reg := '+' register {, shift} 4563 // | '-' register {, shift} 4564 // | register {, shift} 4565 4566 // This method must return MatchOperand_NoMatch without consuming any tokens 4567 // in the case where there is no match, as other alternatives take other 4568 // parse methods. 4569 MCAsmParser &Parser = getParser(); 4570 AsmToken Tok = Parser.getTok(); 4571 SMLoc S = Tok.getLoc(); 4572 bool haveEaten = false; 4573 bool isAdd = true; 4574 if (Tok.is(AsmToken::Plus)) { 4575 Parser.Lex(); // Eat the '+' token. 4576 haveEaten = true; 4577 } else if (Tok.is(AsmToken::Minus)) { 4578 Parser.Lex(); // Eat the '-' token. 4579 isAdd = false; 4580 haveEaten = true; 4581 } 4582 4583 SMLoc E = Parser.getTok().getEndLoc(); 4584 int Reg = tryParseRegister(); 4585 if (Reg == -1) { 4586 if (!haveEaten) 4587 return MatchOperand_NoMatch; 4588 Error(Parser.getTok().getLoc(), "register expected"); 4589 return MatchOperand_ParseFail; 4590 } 4591 4592 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift; 4593 unsigned ShiftImm = 0; 4594 if (Parser.getTok().is(AsmToken::Comma)) { 4595 Parser.Lex(); // Eat the ','. 4596 if (parseMemRegOffsetShift(ShiftTy, ShiftImm)) 4597 return MatchOperand_ParseFail; 4598 4599 // FIXME: Only approximates end...may include intervening whitespace. 4600 E = Parser.getTok().getLoc(); 4601 } 4602 4603 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy, 4604 ShiftImm, S, E)); 4605 4606 return MatchOperand_Success; 4607 } 4608 4609 ARMAsmParser::OperandMatchResultTy 4610 ARMAsmParser::parseAM3Offset(OperandVector &Operands) { 4611 // Check for a post-index addressing register operand. Specifically: 4612 // am3offset := '+' register 4613 // | '-' register 4614 // | register 4615 // | # imm 4616 // | # + imm 4617 // | # - imm 4618 4619 // This method must return MatchOperand_NoMatch without consuming any tokens 4620 // in the case where there is no match, as other alternatives take other 4621 // parse methods. 4622 MCAsmParser &Parser = getParser(); 4623 AsmToken Tok = Parser.getTok(); 4624 SMLoc S = Tok.getLoc(); 4625 4626 // Do immediates first, as we always parse those if we have a '#'. 4627 if (Parser.getTok().is(AsmToken::Hash) || 4628 Parser.getTok().is(AsmToken::Dollar)) { 4629 Parser.Lex(); // Eat '#' or '$'. 4630 // Explicitly look for a '-', as we need to encode negative zero 4631 // differently. 4632 bool isNegative = Parser.getTok().is(AsmToken::Minus); 4633 const MCExpr *Offset; 4634 SMLoc E; 4635 if (getParser().parseExpression(Offset, E)) 4636 return MatchOperand_ParseFail; 4637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); 4638 if (!CE) { 4639 Error(S, "constant expression expected"); 4640 return MatchOperand_ParseFail; 4641 } 4642 // Negative zero is encoded as the flag value INT32_MIN. 4643 int32_t Val = CE->getValue(); 4644 if (isNegative && Val == 0) 4645 Val = INT32_MIN; 4646 4647 Operands.push_back( 4648 ARMOperand::CreateImm(MCConstantExpr::create(Val, getContext()), S, E)); 4649 4650 return MatchOperand_Success; 4651 } 4652 4653 4654 bool haveEaten = false; 4655 bool isAdd = true; 4656 if (Tok.is(AsmToken::Plus)) { 4657 Parser.Lex(); // Eat the '+' token. 4658 haveEaten = true; 4659 } else if (Tok.is(AsmToken::Minus)) { 4660 Parser.Lex(); // Eat the '-' token. 4661 isAdd = false; 4662 haveEaten = true; 4663 } 4664 4665 Tok = Parser.getTok(); 4666 int Reg = tryParseRegister(); 4667 if (Reg == -1) { 4668 if (!haveEaten) 4669 return MatchOperand_NoMatch; 4670 Error(Tok.getLoc(), "register expected"); 4671 return MatchOperand_ParseFail; 4672 } 4673 4674 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift, 4675 0, S, Tok.getEndLoc())); 4676 4677 return MatchOperand_Success; 4678 } 4679 4680 /// Convert parsed operands to MCInst. Needed here because this instruction 4681 /// only has two register operands, but multiplication is commutative so 4682 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN". 4683 void ARMAsmParser::cvtThumbMultiply(MCInst &Inst, 4684 const OperandVector &Operands) { 4685 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1); 4686 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1); 4687 // If we have a three-operand form, make sure to set Rn to be the operand 4688 // that isn't the same as Rd. 4689 unsigned RegOp = 4; 4690 if (Operands.size() == 6 && 4691 ((ARMOperand &)*Operands[4]).getReg() == 4692 ((ARMOperand &)*Operands[3]).getReg()) 4693 RegOp = 5; 4694 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1); 4695 Inst.addOperand(Inst.getOperand(0)); 4696 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2); 4697 } 4698 4699 void ARMAsmParser::cvtThumbBranches(MCInst &Inst, 4700 const OperandVector &Operands) { 4701 int CondOp = -1, ImmOp = -1; 4702 switch(Inst.getOpcode()) { 4703 case ARM::tB: 4704 case ARM::tBcc: CondOp = 1; ImmOp = 2; break; 4705 4706 case ARM::t2B: 4707 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break; 4708 4709 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches"); 4710 } 4711 // first decide whether or not the branch should be conditional 4712 // by looking at it's location relative to an IT block 4713 if(inITBlock()) { 4714 // inside an IT block we cannot have any conditional branches. any 4715 // such instructions needs to be converted to unconditional form 4716 switch(Inst.getOpcode()) { 4717 case ARM::tBcc: Inst.setOpcode(ARM::tB); break; 4718 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break; 4719 } 4720 } else { 4721 // outside IT blocks we can only have unconditional branches with AL 4722 // condition code or conditional branches with non-AL condition code 4723 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode(); 4724 switch(Inst.getOpcode()) { 4725 case ARM::tB: 4726 case ARM::tBcc: 4727 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc); 4728 break; 4729 case ARM::t2B: 4730 case ARM::t2Bcc: 4731 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc); 4732 break; 4733 } 4734 } 4735 4736 // now decide on encoding size based on branch target range 4737 switch(Inst.getOpcode()) { 4738 // classify tB as either t2B or t1B based on range of immediate operand 4739 case ARM::tB: { 4740 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); 4741 if (!op.isSignedOffset<11, 1>() && isThumb() && hasV8MBaseline()) 4742 Inst.setOpcode(ARM::t2B); 4743 break; 4744 } 4745 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand 4746 case ARM::tBcc: { 4747 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); 4748 if (!op.isSignedOffset<8, 1>() && isThumb() && hasV8MBaseline()) 4749 Inst.setOpcode(ARM::t2Bcc); 4750 break; 4751 } 4752 } 4753 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1); 4754 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2); 4755 } 4756 4757 /// Parse an ARM memory expression, return false if successful else return true 4758 /// or an error. The first token must be a '[' when called. 4759 bool ARMAsmParser::parseMemory(OperandVector &Operands) { 4760 MCAsmParser &Parser = getParser(); 4761 SMLoc S, E; 4762 assert(Parser.getTok().is(AsmToken::LBrac) && 4763 "Token is not a Left Bracket"); 4764 S = Parser.getTok().getLoc(); 4765 Parser.Lex(); // Eat left bracket token. 4766 4767 const AsmToken &BaseRegTok = Parser.getTok(); 4768 int BaseRegNum = tryParseRegister(); 4769 if (BaseRegNum == -1) 4770 return Error(BaseRegTok.getLoc(), "register expected"); 4771 4772 // The next token must either be a comma, a colon or a closing bracket. 4773 const AsmToken &Tok = Parser.getTok(); 4774 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) && 4775 !Tok.is(AsmToken::RBrac)) 4776 return Error(Tok.getLoc(), "malformed memory operand"); 4777 4778 if (Tok.is(AsmToken::RBrac)) { 4779 E = Tok.getEndLoc(); 4780 Parser.Lex(); // Eat right bracket token. 4781 4782 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, 4783 ARM_AM::no_shift, 0, 0, false, 4784 S, E)); 4785 4786 // If there's a pre-indexing writeback marker, '!', just add it as a token 4787 // operand. It's rather odd, but syntactically valid. 4788 if (Parser.getTok().is(AsmToken::Exclaim)) { 4789 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 4790 Parser.Lex(); // Eat the '!'. 4791 } 4792 4793 return false; 4794 } 4795 4796 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) && 4797 "Lost colon or comma in memory operand?!"); 4798 if (Tok.is(AsmToken::Comma)) { 4799 Parser.Lex(); // Eat the comma. 4800 } 4801 4802 // If we have a ':', it's an alignment specifier. 4803 if (Parser.getTok().is(AsmToken::Colon)) { 4804 Parser.Lex(); // Eat the ':'. 4805 E = Parser.getTok().getLoc(); 4806 SMLoc AlignmentLoc = Tok.getLoc(); 4807 4808 const MCExpr *Expr; 4809 if (getParser().parseExpression(Expr)) 4810 return true; 4811 4812 // The expression has to be a constant. Memory references with relocations 4813 // don't come through here, as they use the <label> forms of the relevant 4814 // instructions. 4815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); 4816 if (!CE) 4817 return Error (E, "constant expression expected"); 4818 4819 unsigned Align = 0; 4820 switch (CE->getValue()) { 4821 default: 4822 return Error(E, 4823 "alignment specifier must be 16, 32, 64, 128, or 256 bits"); 4824 case 16: Align = 2; break; 4825 case 32: Align = 4; break; 4826 case 64: Align = 8; break; 4827 case 128: Align = 16; break; 4828 case 256: Align = 32; break; 4829 } 4830 4831 // Now we should have the closing ']' 4832 if (Parser.getTok().isNot(AsmToken::RBrac)) 4833 return Error(Parser.getTok().getLoc(), "']' expected"); 4834 E = Parser.getTok().getEndLoc(); 4835 Parser.Lex(); // Eat right bracket token. 4836 4837 // Don't worry about range checking the value here. That's handled by 4838 // the is*() predicates. 4839 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, 4840 ARM_AM::no_shift, 0, Align, 4841 false, S, E, AlignmentLoc)); 4842 4843 // If there's a pre-indexing writeback marker, '!', just add it as a token 4844 // operand. 4845 if (Parser.getTok().is(AsmToken::Exclaim)) { 4846 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 4847 Parser.Lex(); // Eat the '!'. 4848 } 4849 4850 return false; 4851 } 4852 4853 // If we have a '#', it's an immediate offset, else assume it's a register 4854 // offset. Be friendly and also accept a plain integer (without a leading 4855 // hash) for gas compatibility. 4856 if (Parser.getTok().is(AsmToken::Hash) || 4857 Parser.getTok().is(AsmToken::Dollar) || 4858 Parser.getTok().is(AsmToken::Integer)) { 4859 if (Parser.getTok().isNot(AsmToken::Integer)) 4860 Parser.Lex(); // Eat '#' or '$'. 4861 E = Parser.getTok().getLoc(); 4862 4863 bool isNegative = getParser().getTok().is(AsmToken::Minus); 4864 const MCExpr *Offset; 4865 if (getParser().parseExpression(Offset)) 4866 return true; 4867 4868 // The expression has to be a constant. Memory references with relocations 4869 // don't come through here, as they use the <label> forms of the relevant 4870 // instructions. 4871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); 4872 if (!CE) 4873 return Error (E, "constant expression expected"); 4874 4875 // If the constant was #-0, represent it as INT32_MIN. 4876 int32_t Val = CE->getValue(); 4877 if (isNegative && Val == 0) 4878 CE = MCConstantExpr::create(INT32_MIN, getContext()); 4879 4880 // Now we should have the closing ']' 4881 if (Parser.getTok().isNot(AsmToken::RBrac)) 4882 return Error(Parser.getTok().getLoc(), "']' expected"); 4883 E = Parser.getTok().getEndLoc(); 4884 Parser.Lex(); // Eat right bracket token. 4885 4886 // Don't worry about range checking the value here. That's handled by 4887 // the is*() predicates. 4888 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0, 4889 ARM_AM::no_shift, 0, 0, 4890 false, S, E)); 4891 4892 // If there's a pre-indexing writeback marker, '!', just add it as a token 4893 // operand. 4894 if (Parser.getTok().is(AsmToken::Exclaim)) { 4895 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 4896 Parser.Lex(); // Eat the '!'. 4897 } 4898 4899 return false; 4900 } 4901 4902 // The register offset is optionally preceded by a '+' or '-' 4903 bool isNegative = false; 4904 if (Parser.getTok().is(AsmToken::Minus)) { 4905 isNegative = true; 4906 Parser.Lex(); // Eat the '-'. 4907 } else if (Parser.getTok().is(AsmToken::Plus)) { 4908 // Nothing to do. 4909 Parser.Lex(); // Eat the '+'. 4910 } 4911 4912 E = Parser.getTok().getLoc(); 4913 int OffsetRegNum = tryParseRegister(); 4914 if (OffsetRegNum == -1) 4915 return Error(E, "register expected"); 4916 4917 // If there's a shift operator, handle it. 4918 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift; 4919 unsigned ShiftImm = 0; 4920 if (Parser.getTok().is(AsmToken::Comma)) { 4921 Parser.Lex(); // Eat the ','. 4922 if (parseMemRegOffsetShift(ShiftType, ShiftImm)) 4923 return true; 4924 } 4925 4926 // Now we should have the closing ']' 4927 if (Parser.getTok().isNot(AsmToken::RBrac)) 4928 return Error(Parser.getTok().getLoc(), "']' expected"); 4929 E = Parser.getTok().getEndLoc(); 4930 Parser.Lex(); // Eat right bracket token. 4931 4932 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum, 4933 ShiftType, ShiftImm, 0, isNegative, 4934 S, E)); 4935 4936 // If there's a pre-indexing writeback marker, '!', just add it as a token 4937 // operand. 4938 if (Parser.getTok().is(AsmToken::Exclaim)) { 4939 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); 4940 Parser.Lex(); // Eat the '!'. 4941 } 4942 4943 return false; 4944 } 4945 4946 /// parseMemRegOffsetShift - one of these two: 4947 /// ( lsl | lsr | asr | ror ) , # shift_amount 4948 /// rrx 4949 /// return true if it parses a shift otherwise it returns false. 4950 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St, 4951 unsigned &Amount) { 4952 MCAsmParser &Parser = getParser(); 4953 SMLoc Loc = Parser.getTok().getLoc(); 4954 const AsmToken &Tok = Parser.getTok(); 4955 if (Tok.isNot(AsmToken::Identifier)) 4956 return true; 4957 StringRef ShiftName = Tok.getString(); 4958 if (ShiftName == "lsl" || ShiftName == "LSL" || 4959 ShiftName == "asl" || ShiftName == "ASL") 4960 St = ARM_AM::lsl; 4961 else if (ShiftName == "lsr" || ShiftName == "LSR") 4962 St = ARM_AM::lsr; 4963 else if (ShiftName == "asr" || ShiftName == "ASR") 4964 St = ARM_AM::asr; 4965 else if (ShiftName == "ror" || ShiftName == "ROR") 4966 St = ARM_AM::ror; 4967 else if (ShiftName == "rrx" || ShiftName == "RRX") 4968 St = ARM_AM::rrx; 4969 else 4970 return Error(Loc, "illegal shift operator"); 4971 Parser.Lex(); // Eat shift type token. 4972 4973 // rrx stands alone. 4974 Amount = 0; 4975 if (St != ARM_AM::rrx) { 4976 Loc = Parser.getTok().getLoc(); 4977 // A '#' and a shift amount. 4978 const AsmToken &HashTok = Parser.getTok(); 4979 if (HashTok.isNot(AsmToken::Hash) && 4980 HashTok.isNot(AsmToken::Dollar)) 4981 return Error(HashTok.getLoc(), "'#' expected"); 4982 Parser.Lex(); // Eat hash token. 4983 4984 const MCExpr *Expr; 4985 if (getParser().parseExpression(Expr)) 4986 return true; 4987 // Range check the immediate. 4988 // lsl, ror: 0 <= imm <= 31 4989 // lsr, asr: 0 <= imm <= 32 4990 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); 4991 if (!CE) 4992 return Error(Loc, "shift amount must be an immediate"); 4993 int64_t Imm = CE->getValue(); 4994 if (Imm < 0 || 4995 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) || 4996 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32)) 4997 return Error(Loc, "immediate shift value out of range"); 4998 // If <ShiftTy> #0, turn it into a no_shift. 4999 if (Imm == 0) 5000 St = ARM_AM::lsl; 5001 // For consistency, treat lsr #32 and asr #32 as having immediate value 0. 5002 if (Imm == 32) 5003 Imm = 0; 5004 Amount = Imm; 5005 } 5006 5007 return false; 5008 } 5009 5010 /// parseFPImm - A floating point immediate expression operand. 5011 ARMAsmParser::OperandMatchResultTy 5012 ARMAsmParser::parseFPImm(OperandVector &Operands) { 5013 MCAsmParser &Parser = getParser(); 5014 // Anything that can accept a floating point constant as an operand 5015 // needs to go through here, as the regular parseExpression is 5016 // integer only. 5017 // 5018 // This routine still creates a generic Immediate operand, containing 5019 // a bitcast of the 64-bit floating point value. The various operands 5020 // that accept floats can check whether the value is valid for them 5021 // via the standard is*() predicates. 5022 5023 SMLoc S = Parser.getTok().getLoc(); 5024 5025 if (Parser.getTok().isNot(AsmToken::Hash) && 5026 Parser.getTok().isNot(AsmToken::Dollar)) 5027 return MatchOperand_NoMatch; 5028 5029 // Disambiguate the VMOV forms that can accept an FP immediate. 5030 // vmov.f32 <sreg>, #imm 5031 // vmov.f64 <dreg>, #imm 5032 // vmov.f32 <dreg>, #imm @ vector f32x2 5033 // vmov.f32 <qreg>, #imm @ vector f32x4 5034 // 5035 // There are also the NEON VMOV instructions which expect an 5036 // integer constant. Make sure we don't try to parse an FPImm 5037 // for these: 5038 // vmov.i{8|16|32|64} <dreg|qreg>, #imm 5039 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]); 5040 bool isVmovf = TyOp.isToken() && 5041 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64" || 5042 TyOp.getToken() == ".f16"); 5043 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]); 5044 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" || 5045 Mnemonic.getToken() == "fconsts"); 5046 if (!(isVmovf || isFconst)) 5047 return MatchOperand_NoMatch; 5048 5049 Parser.Lex(); // Eat '#' or '$'. 5050 5051 // Handle negation, as that still comes through as a separate token. 5052 bool isNegative = false; 5053 if (Parser.getTok().is(AsmToken::Minus)) { 5054 isNegative = true; 5055 Parser.Lex(); 5056 } 5057 const AsmToken &Tok = Parser.getTok(); 5058 SMLoc Loc = Tok.getLoc(); 5059 if (Tok.is(AsmToken::Real) && isVmovf) { 5060 APFloat RealVal(APFloat::IEEEsingle, Tok.getString()); 5061 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue(); 5062 // If we had a '-' in front, toggle the sign bit. 5063 IntVal ^= (uint64_t)isNegative << 31; 5064 Parser.Lex(); // Eat the token. 5065 Operands.push_back(ARMOperand::CreateImm( 5066 MCConstantExpr::create(IntVal, getContext()), 5067 S, Parser.getTok().getLoc())); 5068 return MatchOperand_Success; 5069 } 5070 // Also handle plain integers. Instructions which allow floating point 5071 // immediates also allow a raw encoded 8-bit value. 5072 if (Tok.is(AsmToken::Integer) && isFconst) { 5073 int64_t Val = Tok.getIntVal(); 5074 Parser.Lex(); // Eat the token. 5075 if (Val > 255 || Val < 0) { 5076 Error(Loc, "encoded floating point value out of range"); 5077 return MatchOperand_ParseFail; 5078 } 5079 float RealVal = ARM_AM::getFPImmFloat(Val); 5080 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue(); 5081 5082 Operands.push_back(ARMOperand::CreateImm( 5083 MCConstantExpr::create(Val, getContext()), S, 5084 Parser.getTok().getLoc())); 5085 return MatchOperand_Success; 5086 } 5087 5088 Error(Loc, "invalid floating point immediate"); 5089 return MatchOperand_ParseFail; 5090 } 5091 5092 /// Parse a arm instruction operand. For now this parses the operand regardless 5093 /// of the mnemonic. 5094 bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) { 5095 MCAsmParser &Parser = getParser(); 5096 SMLoc S, E; 5097 5098 // Check if the current operand has a custom associated parser, if so, try to 5099 // custom parse the operand, or fallback to the general approach. 5100 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic); 5101 if (ResTy == MatchOperand_Success) 5102 return false; 5103 // If there wasn't a custom match, try the generic matcher below. Otherwise, 5104 // there was a match, but an error occurred, in which case, just return that 5105 // the operand parsing failed. 5106 if (ResTy == MatchOperand_ParseFail) 5107 return true; 5108 5109 switch (getLexer().getKind()) { 5110 default: 5111 Error(Parser.getTok().getLoc(), "unexpected token in operand"); 5112 return true; 5113 case AsmToken::Identifier: { 5114 // If we've seen a branch mnemonic, the next operand must be a label. This 5115 // is true even if the label is a register name. So "br r1" means branch to 5116 // label "r1". 5117 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl"; 5118 if (!ExpectLabel) { 5119 if (!tryParseRegisterWithWriteBack(Operands)) 5120 return false; 5121 int Res = tryParseShiftRegister(Operands); 5122 if (Res == 0) // success 5123 return false; 5124 else if (Res == -1) // irrecoverable error 5125 return true; 5126 // If this is VMRS, check for the apsr_nzcv operand. 5127 if (Mnemonic == "vmrs" && 5128 Parser.getTok().getString().equals_lower("apsr_nzcv")) { 5129 S = Parser.getTok().getLoc(); 5130 Parser.Lex(); 5131 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S)); 5132 return false; 5133 } 5134 } 5135 5136 // Fall though for the Identifier case that is not a register or a 5137 // special name. 5138 } 5139 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4) 5140 case AsmToken::Integer: // things like 1f and 2b as a branch targets 5141 case AsmToken::String: // quoted label names. 5142 case AsmToken::Dot: { // . as a branch target 5143 // This was not a register so parse other operands that start with an 5144 // identifier (like labels) as expressions and create them as immediates. 5145 const MCExpr *IdVal; 5146 S = Parser.getTok().getLoc(); 5147 if (getParser().parseExpression(IdVal)) 5148 return true; 5149 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 5150 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E)); 5151 return false; 5152 } 5153 case AsmToken::LBrac: 5154 return parseMemory(Operands); 5155 case AsmToken::LCurly: 5156 return parseRegisterList(Operands); 5157 case AsmToken::Dollar: 5158 case AsmToken::Hash: { 5159 // #42 -> immediate. 5160 S = Parser.getTok().getLoc(); 5161 Parser.Lex(); 5162 5163 if (Parser.getTok().isNot(AsmToken::Colon)) { 5164 bool isNegative = Parser.getTok().is(AsmToken::Minus); 5165 const MCExpr *ImmVal; 5166 if (getParser().parseExpression(ImmVal)) 5167 return true; 5168 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal); 5169 if (CE) { 5170 int32_t Val = CE->getValue(); 5171 if (isNegative && Val == 0) 5172 ImmVal = MCConstantExpr::create(INT32_MIN, getContext()); 5173 } 5174 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 5175 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E)); 5176 5177 // There can be a trailing '!' on operands that we want as a separate 5178 // '!' Token operand. Handle that here. For example, the compatibility 5179 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'. 5180 if (Parser.getTok().is(AsmToken::Exclaim)) { 5181 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(), 5182 Parser.getTok().getLoc())); 5183 Parser.Lex(); // Eat exclaim token 5184 } 5185 return false; 5186 } 5187 // w/ a ':' after the '#', it's just like a plain ':'. 5188 // FALLTHROUGH 5189 } 5190 case AsmToken::Colon: { 5191 S = Parser.getTok().getLoc(); 5192 // ":lower16:" and ":upper16:" expression prefixes 5193 // FIXME: Check it's an expression prefix, 5194 // e.g. (FOO - :lower16:BAR) isn't legal. 5195 ARMMCExpr::VariantKind RefKind; 5196 if (parsePrefix(RefKind)) 5197 return true; 5198 5199 const MCExpr *SubExprVal; 5200 if (getParser().parseExpression(SubExprVal)) 5201 return true; 5202 5203 const MCExpr *ExprVal = ARMMCExpr::create(RefKind, SubExprVal, 5204 getContext()); 5205 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 5206 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E)); 5207 return false; 5208 } 5209 case AsmToken::Equal: { 5210 S = Parser.getTok().getLoc(); 5211 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val) 5212 return Error(S, "unexpected token in operand"); 5213 5214 Parser.Lex(); // Eat '=' 5215 const MCExpr *SubExprVal; 5216 if (getParser().parseExpression(SubExprVal)) 5217 return true; 5218 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); 5219 5220 const MCExpr *CPLoc = 5221 getTargetStreamer().addConstantPoolEntry(SubExprVal, S); 5222 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E)); 5223 return false; 5224 } 5225 } 5226 } 5227 5228 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e. 5229 // :lower16: and :upper16:. 5230 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) { 5231 MCAsmParser &Parser = getParser(); 5232 RefKind = ARMMCExpr::VK_ARM_None; 5233 5234 // consume an optional '#' (GNU compatibility) 5235 if (getLexer().is(AsmToken::Hash)) 5236 Parser.Lex(); 5237 5238 // :lower16: and :upper16: modifiers 5239 assert(getLexer().is(AsmToken::Colon) && "expected a :"); 5240 Parser.Lex(); // Eat ':' 5241 5242 if (getLexer().isNot(AsmToken::Identifier)) { 5243 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand"); 5244 return true; 5245 } 5246 5247 enum { 5248 COFF = (1 << MCObjectFileInfo::IsCOFF), 5249 ELF = (1 << MCObjectFileInfo::IsELF), 5250 MACHO = (1 << MCObjectFileInfo::IsMachO) 5251 }; 5252 static const struct PrefixEntry { 5253 const char *Spelling; 5254 ARMMCExpr::VariantKind VariantKind; 5255 uint8_t SupportedFormats; 5256 } PrefixEntries[] = { 5257 { "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO }, 5258 { "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO }, 5259 }; 5260 5261 StringRef IDVal = Parser.getTok().getIdentifier(); 5262 5263 const auto &Prefix = 5264 std::find_if(std::begin(PrefixEntries), std::end(PrefixEntries), 5265 [&IDVal](const PrefixEntry &PE) { 5266 return PE.Spelling == IDVal; 5267 }); 5268 if (Prefix == std::end(PrefixEntries)) { 5269 Error(Parser.getTok().getLoc(), "unexpected prefix in operand"); 5270 return true; 5271 } 5272 5273 uint8_t CurrentFormat; 5274 switch (getContext().getObjectFileInfo()->getObjectFileType()) { 5275 case MCObjectFileInfo::IsMachO: 5276 CurrentFormat = MACHO; 5277 break; 5278 case MCObjectFileInfo::IsELF: 5279 CurrentFormat = ELF; 5280 break; 5281 case MCObjectFileInfo::IsCOFF: 5282 CurrentFormat = COFF; 5283 break; 5284 } 5285 5286 if (~Prefix->SupportedFormats & CurrentFormat) { 5287 Error(Parser.getTok().getLoc(), 5288 "cannot represent relocation in the current file format"); 5289 return true; 5290 } 5291 5292 RefKind = Prefix->VariantKind; 5293 Parser.Lex(); 5294 5295 if (getLexer().isNot(AsmToken::Colon)) { 5296 Error(Parser.getTok().getLoc(), "unexpected token after prefix"); 5297 return true; 5298 } 5299 Parser.Lex(); // Eat the last ':' 5300 5301 return false; 5302 } 5303 5304 /// \brief Given a mnemonic, split out possible predication code and carry 5305 /// setting letters to form a canonical mnemonic and flags. 5306 // 5307 // FIXME: Would be nice to autogen this. 5308 // FIXME: This is a bit of a maze of special cases. 5309 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic, 5310 unsigned &PredicationCode, 5311 bool &CarrySetting, 5312 unsigned &ProcessorIMod, 5313 StringRef &ITMask) { 5314 PredicationCode = ARMCC::AL; 5315 CarrySetting = false; 5316 ProcessorIMod = 0; 5317 5318 // Ignore some mnemonics we know aren't predicated forms. 5319 // 5320 // FIXME: Would be nice to autogen this. 5321 if ((Mnemonic == "movs" && isThumb()) || 5322 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" || 5323 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" || 5324 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" || 5325 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" || 5326 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" || 5327 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" || 5328 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" || 5329 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" || 5330 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || 5331 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || 5332 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" || 5333 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" || 5334 Mnemonic.startswith("vsel") || Mnemonic == "vins" || Mnemonic == "vmovx" || 5335 Mnemonic == "bxns" || Mnemonic == "blxns") 5336 return Mnemonic; 5337 5338 // First, split out any predication code. Ignore mnemonics we know aren't 5339 // predicated but do have a carry-set and so weren't caught above. 5340 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" && 5341 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" && 5342 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" && 5343 Mnemonic != "sbcs" && Mnemonic != "rscs") { 5344 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2)) 5345 .Case("eq", ARMCC::EQ) 5346 .Case("ne", ARMCC::NE) 5347 .Case("hs", ARMCC::HS) 5348 .Case("cs", ARMCC::HS) 5349 .Case("lo", ARMCC::LO) 5350 .Case("cc", ARMCC::LO) 5351 .Case("mi", ARMCC::MI) 5352 .Case("pl", ARMCC::PL) 5353 .Case("vs", ARMCC::VS) 5354 .Case("vc", ARMCC::VC) 5355 .Case("hi", ARMCC::HI) 5356 .Case("ls", ARMCC::LS) 5357 .Case("ge", ARMCC::GE) 5358 .Case("lt", ARMCC::LT) 5359 .Case("gt", ARMCC::GT) 5360 .Case("le", ARMCC::LE) 5361 .Case("al", ARMCC::AL) 5362 .Default(~0U); 5363 if (CC != ~0U) { 5364 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2); 5365 PredicationCode = CC; 5366 } 5367 } 5368 5369 // Next, determine if we have a carry setting bit. We explicitly ignore all 5370 // the instructions we know end in 's'. 5371 if (Mnemonic.endswith("s") && 5372 !(Mnemonic == "cps" || Mnemonic == "mls" || 5373 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" || 5374 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" || 5375 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" || 5376 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" || 5377 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" || 5378 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" || 5379 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" || 5380 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" || 5381 (Mnemonic == "movs" && isThumb()))) { 5382 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1); 5383 CarrySetting = true; 5384 } 5385 5386 // The "cps" instruction can have a interrupt mode operand which is glued into 5387 // the mnemonic. Check if this is the case, split it and parse the imod op 5388 if (Mnemonic.startswith("cps")) { 5389 // Split out any imod code. 5390 unsigned IMod = 5391 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2)) 5392 .Case("ie", ARM_PROC::IE) 5393 .Case("id", ARM_PROC::ID) 5394 .Default(~0U); 5395 if (IMod != ~0U) { 5396 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2); 5397 ProcessorIMod = IMod; 5398 } 5399 } 5400 5401 // The "it" instruction has the condition mask on the end of the mnemonic. 5402 if (Mnemonic.startswith("it")) { 5403 ITMask = Mnemonic.slice(2, Mnemonic.size()); 5404 Mnemonic = Mnemonic.slice(0, 2); 5405 } 5406 5407 return Mnemonic; 5408 } 5409 5410 /// \brief Given a canonical mnemonic, determine if the instruction ever allows 5411 /// inclusion of carry set or predication code operands. 5412 // 5413 // FIXME: It would be nice to autogen this. 5414 void ARMAsmParser::getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, 5415 bool &CanAcceptCarrySet, 5416 bool &CanAcceptPredicationCode) { 5417 CanAcceptCarrySet = 5418 Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" || 5419 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" || 5420 Mnemonic == "add" || Mnemonic == "adc" || Mnemonic == "mul" || 5421 Mnemonic == "bic" || Mnemonic == "asr" || Mnemonic == "orr" || 5422 Mnemonic == "mvn" || Mnemonic == "rsb" || Mnemonic == "rsc" || 5423 Mnemonic == "orn" || Mnemonic == "sbc" || Mnemonic == "eor" || 5424 Mnemonic == "neg" || Mnemonic == "vfm" || Mnemonic == "vfnm" || 5425 (!isThumb() && 5426 (Mnemonic == "smull" || Mnemonic == "mov" || Mnemonic == "mla" || 5427 Mnemonic == "smlal" || Mnemonic == "umlal" || Mnemonic == "umull")); 5428 5429 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" || 5430 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" || 5431 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" || 5432 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") || 5433 Mnemonic.startswith("vsel") || Mnemonic == "vmaxnm" || 5434 Mnemonic == "vminnm" || Mnemonic == "vcvta" || Mnemonic == "vcvtn" || 5435 Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || Mnemonic == "vrinta" || 5436 Mnemonic == "vrintn" || Mnemonic == "vrintp" || Mnemonic == "vrintm" || 5437 Mnemonic.startswith("aes") || Mnemonic == "hvc" || Mnemonic == "setpan" || 5438 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") || 5439 (FullInst.startswith("vmull") && FullInst.endswith(".p64")) || 5440 Mnemonic == "vmovx" || Mnemonic == "vins") { 5441 // These mnemonics are never predicable 5442 CanAcceptPredicationCode = false; 5443 } else if (!isThumb()) { 5444 // Some instructions are only predicable in Thumb mode 5445 CanAcceptPredicationCode = 5446 Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" && 5447 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" && 5448 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" && 5449 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" && 5450 Mnemonic != "ldc2" && Mnemonic != "ldc2l" && Mnemonic != "stc2" && 5451 Mnemonic != "stc2l" && !Mnemonic.startswith("rfe") && 5452 !Mnemonic.startswith("srs"); 5453 } else if (isThumbOne()) { 5454 if (hasV6MOps()) 5455 CanAcceptPredicationCode = Mnemonic != "movs"; 5456 else 5457 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs"; 5458 } else 5459 CanAcceptPredicationCode = true; 5460 } 5461 5462 // \brief Some Thumb instructions have two operand forms that are not 5463 // available as three operand, convert to two operand form if possible. 5464 // 5465 // FIXME: We would really like to be able to tablegen'erate this. 5466 void ARMAsmParser::tryConvertingToTwoOperandForm(StringRef Mnemonic, 5467 bool CarrySetting, 5468 OperandVector &Operands) { 5469 if (Operands.size() != 6) 5470 return; 5471 5472 const auto &Op3 = static_cast<ARMOperand &>(*Operands[3]); 5473 auto &Op4 = static_cast<ARMOperand &>(*Operands[4]); 5474 if (!Op3.isReg() || !Op4.isReg()) 5475 return; 5476 5477 auto Op3Reg = Op3.getReg(); 5478 auto Op4Reg = Op4.getReg(); 5479 5480 // For most Thumb2 cases we just generate the 3 operand form and reduce 5481 // it in processInstruction(), but the 3 operand form of ADD (t2ADDrr) 5482 // won't accept SP or PC so we do the transformation here taking care 5483 // with immediate range in the 'add sp, sp #imm' case. 5484 auto &Op5 = static_cast<ARMOperand &>(*Operands[5]); 5485 if (isThumbTwo()) { 5486 if (Mnemonic != "add") 5487 return; 5488 bool TryTransform = Op3Reg == ARM::PC || Op4Reg == ARM::PC || 5489 (Op5.isReg() && Op5.getReg() == ARM::PC); 5490 if (!TryTransform) { 5491 TryTransform = (Op3Reg == ARM::SP || Op4Reg == ARM::SP || 5492 (Op5.isReg() && Op5.getReg() == ARM::SP)) && 5493 !(Op3Reg == ARM::SP && Op4Reg == ARM::SP && 5494 Op5.isImm() && !Op5.isImm0_508s4()); 5495 } 5496 if (!TryTransform) 5497 return; 5498 } else if (!isThumbOne()) 5499 return; 5500 5501 if (!(Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" || 5502 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" || 5503 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" || 5504 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) 5505 return; 5506 5507 // If first 2 operands of a 3 operand instruction are the same 5508 // then transform to 2 operand version of the same instruction 5509 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1' 5510 bool Transform = Op3Reg == Op4Reg; 5511 5512 // For communtative operations, we might be able to transform if we swap 5513 // Op4 and Op5. The 'ADD Rdm, SP, Rdm' form is already handled specially 5514 // as tADDrsp. 5515 const ARMOperand *LastOp = &Op5; 5516 bool Swap = false; 5517 if (!Transform && Op5.isReg() && Op3Reg == Op5.getReg() && 5518 ((Mnemonic == "add" && Op4Reg != ARM::SP) || 5519 Mnemonic == "and" || Mnemonic == "eor" || 5520 Mnemonic == "adc" || Mnemonic == "orr")) { 5521 Swap = true; 5522 LastOp = &Op4; 5523 Transform = true; 5524 } 5525 5526 // If both registers are the same then remove one of them from 5527 // the operand list, with certain exceptions. 5528 if (Transform) { 5529 // Don't transform 'adds Rd, Rd, Rm' or 'sub{s} Rd, Rd, Rm' because the 5530 // 2 operand forms don't exist. 5531 if (((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub") && 5532 LastOp->isReg()) 5533 Transform = false; 5534 5535 // Don't transform 'add/sub{s} Rd, Rd, #imm' if the immediate fits into 5536 // 3-bits because the ARMARM says not to. 5537 if ((Mnemonic == "add" || Mnemonic == "sub") && LastOp->isImm0_7()) 5538 Transform = false; 5539 } 5540 5541 if (Transform) { 5542 if (Swap) 5543 std::swap(Op4, Op5); 5544 Operands.erase(Operands.begin() + 3); 5545 } 5546 } 5547 5548 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic, 5549 OperandVector &Operands) { 5550 // FIXME: This is all horribly hacky. We really need a better way to deal 5551 // with optional operands like this in the matcher table. 5552 5553 // The 'mov' mnemonic is special. One variant has a cc_out operand, while 5554 // another does not. Specifically, the MOVW instruction does not. So we 5555 // special case it here and remove the defaulted (non-setting) cc_out 5556 // operand if that's the instruction we're trying to match. 5557 // 5558 // We do this as post-processing of the explicit operands rather than just 5559 // conditionally adding the cc_out in the first place because we need 5560 // to check the type of the parsed immediate operand. 5561 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() && 5562 !static_cast<ARMOperand &>(*Operands[4]).isModImm() && 5563 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() && 5564 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) 5565 return true; 5566 5567 // Register-register 'add' for thumb does not have a cc_out operand 5568 // when there are only two register operands. 5569 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 && 5570 static_cast<ARMOperand &>(*Operands[3]).isReg() && 5571 static_cast<ARMOperand &>(*Operands[4]).isReg() && 5572 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) 5573 return true; 5574 // Register-register 'add' for thumb does not have a cc_out operand 5575 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do 5576 // have to check the immediate range here since Thumb2 has a variant 5577 // that can handle a different range and has a cc_out operand. 5578 if (((isThumb() && Mnemonic == "add") || 5579 (isThumbTwo() && Mnemonic == "sub")) && 5580 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && 5581 static_cast<ARMOperand &>(*Operands[4]).isReg() && 5582 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP && 5583 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 5584 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) || 5585 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4())) 5586 return true; 5587 // For Thumb2, add/sub immediate does not have a cc_out operand for the 5588 // imm0_4095 variant. That's the least-preferred variant when 5589 // selecting via the generic "add" mnemonic, so to know that we 5590 // should remove the cc_out operand, we have to explicitly check that 5591 // it's not one of the other variants. Ugh. 5592 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") && 5593 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && 5594 static_cast<ARMOperand &>(*Operands[4]).isReg() && 5595 static_cast<ARMOperand &>(*Operands[5]).isImm()) { 5596 // Nest conditions rather than one big 'if' statement for readability. 5597 // 5598 // If both registers are low, we're in an IT block, and the immediate is 5599 // in range, we should use encoding T1 instead, which has a cc_out. 5600 if (inITBlock() && 5601 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) && 5602 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) && 5603 static_cast<ARMOperand &>(*Operands[5]).isImm0_7()) 5604 return false; 5605 // Check against T3. If the second register is the PC, this is an 5606 // alternate form of ADR, which uses encoding T4, so check for that too. 5607 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC && 5608 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm()) 5609 return false; 5610 5611 // Otherwise, we use encoding T4, which does not have a cc_out 5612 // operand. 5613 return true; 5614 } 5615 5616 // The thumb2 multiply instruction doesn't have a CCOut register, so 5617 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to 5618 // use the 16-bit encoding or not. 5619 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 && 5620 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 5621 static_cast<ARMOperand &>(*Operands[3]).isReg() && 5622 static_cast<ARMOperand &>(*Operands[4]).isReg() && 5623 static_cast<ARMOperand &>(*Operands[5]).isReg() && 5624 // If the registers aren't low regs, the destination reg isn't the 5625 // same as one of the source regs, or the cc_out operand is zero 5626 // outside of an IT block, we have to use the 32-bit encoding, so 5627 // remove the cc_out operand. 5628 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || 5629 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || 5630 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) || 5631 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() != 5632 static_cast<ARMOperand &>(*Operands[5]).getReg() && 5633 static_cast<ARMOperand &>(*Operands[3]).getReg() != 5634 static_cast<ARMOperand &>(*Operands[4]).getReg()))) 5635 return true; 5636 5637 // Also check the 'mul' syntax variant that doesn't specify an explicit 5638 // destination register. 5639 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 && 5640 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 5641 static_cast<ARMOperand &>(*Operands[3]).isReg() && 5642 static_cast<ARMOperand &>(*Operands[4]).isReg() && 5643 // If the registers aren't low regs or the cc_out operand is zero 5644 // outside of an IT block, we have to use the 32-bit encoding, so 5645 // remove the cc_out operand. 5646 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || 5647 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || 5648 !inITBlock())) 5649 return true; 5650 5651 5652 5653 // Register-register 'add/sub' for thumb does not have a cc_out operand 5654 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also 5655 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't 5656 // right, this will result in better diagnostics (which operand is off) 5657 // anyway. 5658 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") && 5659 (Operands.size() == 5 || Operands.size() == 6) && 5660 static_cast<ARMOperand &>(*Operands[3]).isReg() && 5661 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP && 5662 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && 5663 (static_cast<ARMOperand &>(*Operands[4]).isImm() || 5664 (Operands.size() == 6 && 5665 static_cast<ARMOperand &>(*Operands[5]).isImm()))) 5666 return true; 5667 5668 return false; 5669 } 5670 5671 bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic, 5672 OperandVector &Operands) { 5673 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON 5674 unsigned RegIdx = 3; 5675 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") && 5676 (static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32" || 5677 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f16")) { 5678 if (static_cast<ARMOperand &>(*Operands[3]).isToken() && 5679 (static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32" || 5680 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f16")) 5681 RegIdx = 4; 5682 5683 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() && 5684 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains( 5685 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) || 5686 ARMMCRegisterClasses[ARM::QPRRegClassID].contains( 5687 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()))) 5688 return true; 5689 } 5690 return false; 5691 } 5692 5693 static bool isDataTypeToken(StringRef Tok) { 5694 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" || 5695 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" || 5696 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" || 5697 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" || 5698 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" || 5699 Tok == ".f" || Tok == ".d"; 5700 } 5701 5702 // FIXME: This bit should probably be handled via an explicit match class 5703 // in the .td files that matches the suffix instead of having it be 5704 // a literal string token the way it is now. 5705 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) { 5706 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm"); 5707 } 5708 static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features, 5709 unsigned VariantID); 5710 5711 static bool RequiresVFPRegListValidation(StringRef Inst, 5712 bool &AcceptSinglePrecisionOnly, 5713 bool &AcceptDoublePrecisionOnly) { 5714 if (Inst.size() < 7) 5715 return false; 5716 5717 if (Inst.startswith("fldm") || Inst.startswith("fstm")) { 5718 StringRef AddressingMode = Inst.substr(4, 2); 5719 if (AddressingMode == "ia" || AddressingMode == "db" || 5720 AddressingMode == "ea" || AddressingMode == "fd") { 5721 AcceptSinglePrecisionOnly = Inst[6] == 's'; 5722 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x'; 5723 return true; 5724 } 5725 } 5726 5727 return false; 5728 } 5729 5730 /// Parse an arm instruction mnemonic followed by its operands. 5731 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, 5732 SMLoc NameLoc, OperandVector &Operands) { 5733 MCAsmParser &Parser = getParser(); 5734 // FIXME: Can this be done via tablegen in some fashion? 5735 bool RequireVFPRegisterListCheck; 5736 bool AcceptSinglePrecisionOnly; 5737 bool AcceptDoublePrecisionOnly; 5738 RequireVFPRegisterListCheck = 5739 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly, 5740 AcceptDoublePrecisionOnly); 5741 5742 // Apply mnemonic aliases before doing anything else, as the destination 5743 // mnemonic may include suffices and we want to handle them normally. 5744 // The generic tblgen'erated code does this later, at the start of 5745 // MatchInstructionImpl(), but that's too late for aliases that include 5746 // any sort of suffix. 5747 uint64_t AvailableFeatures = getAvailableFeatures(); 5748 unsigned AssemblerDialect = getParser().getAssemblerDialect(); 5749 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect); 5750 5751 // First check for the ARM-specific .req directive. 5752 if (Parser.getTok().is(AsmToken::Identifier) && 5753 Parser.getTok().getIdentifier() == ".req") { 5754 parseDirectiveReq(Name, NameLoc); 5755 // We always return 'error' for this, as we're done with this 5756 // statement and don't need to match the 'instruction." 5757 return true; 5758 } 5759 5760 // Create the leading tokens for the mnemonic, split by '.' characters. 5761 size_t Start = 0, Next = Name.find('.'); 5762 StringRef Mnemonic = Name.slice(Start, Next); 5763 5764 // Split out the predication code and carry setting flag from the mnemonic. 5765 unsigned PredicationCode; 5766 unsigned ProcessorIMod; 5767 bool CarrySetting; 5768 StringRef ITMask; 5769 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting, 5770 ProcessorIMod, ITMask); 5771 5772 // In Thumb1, only the branch (B) instruction can be predicated. 5773 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") { 5774 Parser.eatToEndOfStatement(); 5775 return Error(NameLoc, "conditional execution not supported in Thumb1"); 5776 } 5777 5778 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc)); 5779 5780 // Handle the IT instruction ITMask. Convert it to a bitmask. This 5781 // is the mask as it will be for the IT encoding if the conditional 5782 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case 5783 // where the conditional bit0 is zero, the instruction post-processing 5784 // will adjust the mask accordingly. 5785 if (Mnemonic == "it") { 5786 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2); 5787 if (ITMask.size() > 3) { 5788 Parser.eatToEndOfStatement(); 5789 return Error(Loc, "too many conditions on IT instruction"); 5790 } 5791 unsigned Mask = 8; 5792 for (unsigned i = ITMask.size(); i != 0; --i) { 5793 char pos = ITMask[i - 1]; 5794 if (pos != 't' && pos != 'e') { 5795 Parser.eatToEndOfStatement(); 5796 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'"); 5797 } 5798 Mask >>= 1; 5799 if (ITMask[i - 1] == 't') 5800 Mask |= 8; 5801 } 5802 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc)); 5803 } 5804 5805 // FIXME: This is all a pretty gross hack. We should automatically handle 5806 // optional operands like this via tblgen. 5807 5808 // Next, add the CCOut and ConditionCode operands, if needed. 5809 // 5810 // For mnemonics which can ever incorporate a carry setting bit or predication 5811 // code, our matching model involves us always generating CCOut and 5812 // ConditionCode operands to match the mnemonic "as written" and then we let 5813 // the matcher deal with finding the right instruction or generating an 5814 // appropriate error. 5815 bool CanAcceptCarrySet, CanAcceptPredicationCode; 5816 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode); 5817 5818 // If we had a carry-set on an instruction that can't do that, issue an 5819 // error. 5820 if (!CanAcceptCarrySet && CarrySetting) { 5821 Parser.eatToEndOfStatement(); 5822 return Error(NameLoc, "instruction '" + Mnemonic + 5823 "' can not set flags, but 's' suffix specified"); 5824 } 5825 // If we had a predication code on an instruction that can't do that, issue an 5826 // error. 5827 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) { 5828 Parser.eatToEndOfStatement(); 5829 return Error(NameLoc, "instruction '" + Mnemonic + 5830 "' is not predicable, but condition code specified"); 5831 } 5832 5833 // Add the carry setting operand, if necessary. 5834 if (CanAcceptCarrySet) { 5835 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size()); 5836 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0, 5837 Loc)); 5838 } 5839 5840 // Add the predication code operand, if necessary. 5841 if (CanAcceptPredicationCode) { 5842 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() + 5843 CarrySetting); 5844 Operands.push_back(ARMOperand::CreateCondCode( 5845 ARMCC::CondCodes(PredicationCode), Loc)); 5846 } 5847 5848 // Add the processor imod operand, if necessary. 5849 if (ProcessorIMod) { 5850 Operands.push_back(ARMOperand::CreateImm( 5851 MCConstantExpr::create(ProcessorIMod, getContext()), 5852 NameLoc, NameLoc)); 5853 } else if (Mnemonic == "cps" && isMClass()) { 5854 return Error(NameLoc, "instruction 'cps' requires effect for M-class"); 5855 } 5856 5857 // Add the remaining tokens in the mnemonic. 5858 while (Next != StringRef::npos) { 5859 Start = Next; 5860 Next = Name.find('.', Start + 1); 5861 StringRef ExtraToken = Name.slice(Start, Next); 5862 5863 // Some NEON instructions have an optional datatype suffix that is 5864 // completely ignored. Check for that. 5865 if (isDataTypeToken(ExtraToken) && 5866 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken)) 5867 continue; 5868 5869 // For for ARM mode generate an error if the .n qualifier is used. 5870 if (ExtraToken == ".n" && !isThumb()) { 5871 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); 5872 Parser.eatToEndOfStatement(); 5873 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in " 5874 "arm mode"); 5875 } 5876 5877 // The .n qualifier is always discarded as that is what the tables 5878 // and matcher expect. In ARM mode the .w qualifier has no effect, 5879 // so discard it to avoid errors that can be caused by the matcher. 5880 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) { 5881 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); 5882 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc)); 5883 } 5884 } 5885 5886 // Read the remaining operands. 5887 if (getLexer().isNot(AsmToken::EndOfStatement)) { 5888 // Read the first operand. 5889 if (parseOperand(Operands, Mnemonic)) { 5890 Parser.eatToEndOfStatement(); 5891 return true; 5892 } 5893 5894 while (getLexer().is(AsmToken::Comma)) { 5895 Parser.Lex(); // Eat the comma. 5896 5897 // Parse and remember the operand. 5898 if (parseOperand(Operands, Mnemonic)) { 5899 Parser.eatToEndOfStatement(); 5900 return true; 5901 } 5902 } 5903 } 5904 5905 if (getLexer().isNot(AsmToken::EndOfStatement)) { 5906 SMLoc Loc = getLexer().getLoc(); 5907 Parser.eatToEndOfStatement(); 5908 return Error(Loc, "unexpected token in argument list"); 5909 } 5910 5911 Parser.Lex(); // Consume the EndOfStatement 5912 5913 if (RequireVFPRegisterListCheck) { 5914 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back()); 5915 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList()) 5916 return Error(Op.getStartLoc(), 5917 "VFP/Neon single precision register expected"); 5918 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList()) 5919 return Error(Op.getStartLoc(), 5920 "VFP/Neon double precision register expected"); 5921 } 5922 5923 tryConvertingToTwoOperandForm(Mnemonic, CarrySetting, Operands); 5924 5925 // Some instructions, mostly Thumb, have forms for the same mnemonic that 5926 // do and don't have a cc_out optional-def operand. With some spot-checks 5927 // of the operand list, we can figure out which variant we're trying to 5928 // parse and adjust accordingly before actually matching. We shouldn't ever 5929 // try to remove a cc_out operand that was explicitly set on the 5930 // mnemonic, of course (CarrySetting == true). Reason number #317 the 5931 // table driven matcher doesn't fit well with the ARM instruction set. 5932 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) 5933 Operands.erase(Operands.begin() + 1); 5934 5935 // Some instructions have the same mnemonic, but don't always 5936 // have a predicate. Distinguish them here and delete the 5937 // predicate if needed. 5938 if (shouldOmitPredicateOperand(Mnemonic, Operands)) 5939 Operands.erase(Operands.begin() + 1); 5940 5941 // ARM mode 'blx' need special handling, as the register operand version 5942 // is predicable, but the label operand version is not. So, we can't rely 5943 // on the Mnemonic based checking to correctly figure out when to put 5944 // a k_CondCode operand in the list. If we're trying to match the label 5945 // version, remove the k_CondCode operand here. 5946 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 && 5947 static_cast<ARMOperand &>(*Operands[2]).isImm()) 5948 Operands.erase(Operands.begin() + 1); 5949 5950 // Adjust operands of ldrexd/strexd to MCK_GPRPair. 5951 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint, 5952 // a single GPRPair reg operand is used in the .td file to replace the two 5953 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically 5954 // expressed as a GPRPair, so we have to manually merge them. 5955 // FIXME: We would really like to be able to tablegen'erate this. 5956 if (!isThumb() && Operands.size() > 4 && 5957 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" || 5958 Mnemonic == "stlexd")) { 5959 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd"); 5960 unsigned Idx = isLoad ? 2 : 3; 5961 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]); 5962 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]); 5963 5964 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID); 5965 // Adjust only if Op1 and Op2 are GPRs. 5966 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) && 5967 MRC.contains(Op2.getReg())) { 5968 unsigned Reg1 = Op1.getReg(); 5969 unsigned Reg2 = Op2.getReg(); 5970 unsigned Rt = MRI->getEncodingValue(Reg1); 5971 unsigned Rt2 = MRI->getEncodingValue(Reg2); 5972 5973 // Rt2 must be Rt + 1 and Rt must be even. 5974 if (Rt + 1 != Rt2 || (Rt & 1)) { 5975 Error(Op2.getStartLoc(), isLoad 5976 ? "destination operands must be sequential" 5977 : "source operands must be sequential"); 5978 return true; 5979 } 5980 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0, 5981 &(MRI->getRegClass(ARM::GPRPairRegClassID))); 5982 Operands[Idx] = 5983 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc()); 5984 Operands.erase(Operands.begin() + Idx + 1); 5985 } 5986 } 5987 5988 // GNU Assembler extension (compatibility) 5989 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) { 5990 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]); 5991 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); 5992 if (Op3.isMem()) { 5993 assert(Op2.isReg() && "expected register argument"); 5994 5995 unsigned SuperReg = MRI->getMatchingSuperReg( 5996 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID)); 5997 5998 assert(SuperReg && "expected register pair"); 5999 6000 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1); 6001 6002 Operands.insert( 6003 Operands.begin() + 3, 6004 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc())); 6005 } 6006 } 6007 6008 // FIXME: As said above, this is all a pretty gross hack. This instruction 6009 // does not fit with other "subs" and tblgen. 6010 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction 6011 // so the Mnemonic is the original name "subs" and delete the predicate 6012 // operand so it will match the table entry. 6013 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 && 6014 static_cast<ARMOperand &>(*Operands[3]).isReg() && 6015 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC && 6016 static_cast<ARMOperand &>(*Operands[4]).isReg() && 6017 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR && 6018 static_cast<ARMOperand &>(*Operands[5]).isImm()) { 6019 Operands.front() = ARMOperand::CreateToken(Name, NameLoc); 6020 Operands.erase(Operands.begin() + 1); 6021 } 6022 return false; 6023 } 6024 6025 // Validate context-sensitive operand constraints. 6026 6027 // return 'true' if register list contains non-low GPR registers, 6028 // 'false' otherwise. If Reg is in the register list or is HiReg, set 6029 // 'containsReg' to true. 6030 static bool checkLowRegisterList(const MCInst &Inst, unsigned OpNo, 6031 unsigned Reg, unsigned HiReg, 6032 bool &containsReg) { 6033 containsReg = false; 6034 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { 6035 unsigned OpReg = Inst.getOperand(i).getReg(); 6036 if (OpReg == Reg) 6037 containsReg = true; 6038 // Anything other than a low register isn't legal here. 6039 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg)) 6040 return true; 6041 } 6042 return false; 6043 } 6044 6045 // Check if the specified regisgter is in the register list of the inst, 6046 // starting at the indicated operand number. 6047 static bool listContainsReg(const MCInst &Inst, unsigned OpNo, unsigned Reg) { 6048 for (unsigned i = OpNo, e = Inst.getNumOperands(); i < e; ++i) { 6049 unsigned OpReg = Inst.getOperand(i).getReg(); 6050 if (OpReg == Reg) 6051 return true; 6052 } 6053 return false; 6054 } 6055 6056 // Return true if instruction has the interesting property of being 6057 // allowed in IT blocks, but not being predicable. 6058 static bool instIsBreakpoint(const MCInst &Inst) { 6059 return Inst.getOpcode() == ARM::tBKPT || 6060 Inst.getOpcode() == ARM::BKPT || 6061 Inst.getOpcode() == ARM::tHLT || 6062 Inst.getOpcode() == ARM::HLT; 6063 6064 } 6065 6066 bool ARMAsmParser::validatetLDMRegList(const MCInst &Inst, 6067 const OperandVector &Operands, 6068 unsigned ListNo, bool IsARPop) { 6069 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]); 6070 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!"; 6071 6072 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP); 6073 bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR); 6074 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC); 6075 6076 if (!IsARPop && ListContainsSP) 6077 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 6078 "SP may not be in the register list"); 6079 else if (ListContainsPC && ListContainsLR) 6080 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 6081 "PC and LR may not be in the register list simultaneously"); 6082 else if (inITBlock() && !lastInITBlock() && ListContainsPC) 6083 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 6084 "instruction must be outside of IT block or the last " 6085 "instruction in an IT block"); 6086 return false; 6087 } 6088 6089 bool ARMAsmParser::validatetSTMRegList(const MCInst &Inst, 6090 const OperandVector &Operands, 6091 unsigned ListNo) { 6092 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]); 6093 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!"; 6094 6095 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP); 6096 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC); 6097 6098 if (ListContainsSP && ListContainsPC) 6099 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 6100 "SP and PC may not be in the register list"); 6101 else if (ListContainsSP) 6102 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 6103 "SP may not be in the register list"); 6104 else if (ListContainsPC) 6105 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(), 6106 "PC may not be in the register list"); 6107 return false; 6108 } 6109 6110 // FIXME: We would really like to be able to tablegen'erate this. 6111 bool ARMAsmParser::validateInstruction(MCInst &Inst, 6112 const OperandVector &Operands) { 6113 const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); 6114 SMLoc Loc = Operands[0]->getStartLoc(); 6115 6116 // Check the IT block state first. 6117 // NOTE: BKPT and HLT instructions have the interesting property of being 6118 // allowed in IT blocks, but not being predicable. They just always execute. 6119 if (inITBlock() && !instIsBreakpoint(Inst)) { 6120 unsigned Bit = 1; 6121 if (ITState.FirstCond) 6122 ITState.FirstCond = false; 6123 else 6124 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1; 6125 // The instruction must be predicable. 6126 if (!MCID.isPredicable()) 6127 return Error(Loc, "instructions in IT block must be predicable"); 6128 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm(); 6129 unsigned ITCond = Bit ? ITState.Cond : 6130 ARMCC::getOppositeCondition(ITState.Cond); 6131 if (Cond != ITCond) { 6132 // Find the condition code Operand to get its SMLoc information. 6133 SMLoc CondLoc; 6134 for (unsigned I = 1; I < Operands.size(); ++I) 6135 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode()) 6136 CondLoc = Operands[I]->getStartLoc(); 6137 return Error(CondLoc, "incorrect condition in IT block; got '" + 6138 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) + 6139 "', but expected '" + 6140 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'"); 6141 } 6142 // Check for non-'al' condition codes outside of the IT block. 6143 } else if (isThumbTwo() && MCID.isPredicable() && 6144 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() != 6145 ARMCC::AL && Inst.getOpcode() != ARM::tBcc && 6146 Inst.getOpcode() != ARM::t2Bcc) 6147 return Error(Loc, "predicated instructions must be in IT block"); 6148 6149 const unsigned Opcode = Inst.getOpcode(); 6150 switch (Opcode) { 6151 case ARM::LDRD: 6152 case ARM::LDRD_PRE: 6153 case ARM::LDRD_POST: { 6154 const unsigned RtReg = Inst.getOperand(0).getReg(); 6155 6156 // Rt can't be R14. 6157 if (RtReg == ARM::LR) 6158 return Error(Operands[3]->getStartLoc(), 6159 "Rt can't be R14"); 6160 6161 const unsigned Rt = MRI->getEncodingValue(RtReg); 6162 // Rt must be even-numbered. 6163 if ((Rt & 1) == 1) 6164 return Error(Operands[3]->getStartLoc(), 6165 "Rt must be even-numbered"); 6166 6167 // Rt2 must be Rt + 1. 6168 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 6169 if (Rt2 != Rt + 1) 6170 return Error(Operands[3]->getStartLoc(), 6171 "destination operands must be sequential"); 6172 6173 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) { 6174 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg()); 6175 // For addressing modes with writeback, the base register needs to be 6176 // different from the destination registers. 6177 if (Rn == Rt || Rn == Rt2) 6178 return Error(Operands[3]->getStartLoc(), 6179 "base register needs to be different from destination " 6180 "registers"); 6181 } 6182 6183 return false; 6184 } 6185 case ARM::t2LDRDi8: 6186 case ARM::t2LDRD_PRE: 6187 case ARM::t2LDRD_POST: { 6188 // Rt2 must be different from Rt. 6189 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); 6190 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 6191 if (Rt2 == Rt) 6192 return Error(Operands[3]->getStartLoc(), 6193 "destination operands can't be identical"); 6194 return false; 6195 } 6196 case ARM::t2BXJ: { 6197 const unsigned RmReg = Inst.getOperand(0).getReg(); 6198 // Rm = SP is no longer unpredictable in v8-A 6199 if (RmReg == ARM::SP && !hasV8Ops()) 6200 return Error(Operands[2]->getStartLoc(), 6201 "r13 (SP) is an unpredictable operand to BXJ"); 6202 return false; 6203 } 6204 case ARM::STRD: { 6205 // Rt2 must be Rt + 1. 6206 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); 6207 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 6208 if (Rt2 != Rt + 1) 6209 return Error(Operands[3]->getStartLoc(), 6210 "source operands must be sequential"); 6211 return false; 6212 } 6213 case ARM::STRD_PRE: 6214 case ARM::STRD_POST: { 6215 // Rt2 must be Rt + 1. 6216 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 6217 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg()); 6218 if (Rt2 != Rt + 1) 6219 return Error(Operands[3]->getStartLoc(), 6220 "source operands must be sequential"); 6221 return false; 6222 } 6223 case ARM::STR_PRE_IMM: 6224 case ARM::STR_PRE_REG: 6225 case ARM::STR_POST_IMM: 6226 case ARM::STR_POST_REG: 6227 case ARM::STRH_PRE: 6228 case ARM::STRH_POST: 6229 case ARM::STRB_PRE_IMM: 6230 case ARM::STRB_PRE_REG: 6231 case ARM::STRB_POST_IMM: 6232 case ARM::STRB_POST_REG: { 6233 // Rt must be different from Rn. 6234 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); 6235 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); 6236 6237 if (Rt == Rn) 6238 return Error(Operands[3]->getStartLoc(), 6239 "source register and base register can't be identical"); 6240 return false; 6241 } 6242 case ARM::LDR_PRE_IMM: 6243 case ARM::LDR_PRE_REG: 6244 case ARM::LDR_POST_IMM: 6245 case ARM::LDR_POST_REG: 6246 case ARM::LDRH_PRE: 6247 case ARM::LDRH_POST: 6248 case ARM::LDRSH_PRE: 6249 case ARM::LDRSH_POST: 6250 case ARM::LDRB_PRE_IMM: 6251 case ARM::LDRB_PRE_REG: 6252 case ARM::LDRB_POST_IMM: 6253 case ARM::LDRB_POST_REG: 6254 case ARM::LDRSB_PRE: 6255 case ARM::LDRSB_POST: { 6256 // Rt must be different from Rn. 6257 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); 6258 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); 6259 6260 if (Rt == Rn) 6261 return Error(Operands[3]->getStartLoc(), 6262 "destination register and base register can't be identical"); 6263 return false; 6264 } 6265 case ARM::SBFX: 6266 case ARM::UBFX: { 6267 // Width must be in range [1, 32-lsb]. 6268 unsigned LSB = Inst.getOperand(2).getImm(); 6269 unsigned Widthm1 = Inst.getOperand(3).getImm(); 6270 if (Widthm1 >= 32 - LSB) 6271 return Error(Operands[5]->getStartLoc(), 6272 "bitfield width must be in range [1,32-lsb]"); 6273 return false; 6274 } 6275 // Notionally handles ARM::tLDMIA_UPD too. 6276 case ARM::tLDMIA: { 6277 // If we're parsing Thumb2, the .w variant is available and handles 6278 // most cases that are normally illegal for a Thumb1 LDM instruction. 6279 // We'll make the transformation in processInstruction() if necessary. 6280 // 6281 // Thumb LDM instructions are writeback iff the base register is not 6282 // in the register list. 6283 unsigned Rn = Inst.getOperand(0).getReg(); 6284 bool HasWritebackToken = 6285 (static_cast<ARMOperand &>(*Operands[3]).isToken() && 6286 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); 6287 bool ListContainsBase; 6288 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo()) 6289 return Error(Operands[3 + HasWritebackToken]->getStartLoc(), 6290 "registers must be in range r0-r7"); 6291 // If we should have writeback, then there should be a '!' token. 6292 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo()) 6293 return Error(Operands[2]->getStartLoc(), 6294 "writeback operator '!' expected"); 6295 // If we should not have writeback, there must not be a '!'. This is 6296 // true even for the 32-bit wide encodings. 6297 if (ListContainsBase && HasWritebackToken) 6298 return Error(Operands[3]->getStartLoc(), 6299 "writeback operator '!' not allowed when base register " 6300 "in register list"); 6301 6302 if (validatetLDMRegList(Inst, Operands, 3)) 6303 return true; 6304 break; 6305 } 6306 case ARM::LDMIA_UPD: 6307 case ARM::LDMDB_UPD: 6308 case ARM::LDMIB_UPD: 6309 case ARM::LDMDA_UPD: 6310 // ARM variants loading and updating the same register are only officially 6311 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before. 6312 if (!hasV7Ops()) 6313 break; 6314 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) 6315 return Error(Operands.back()->getStartLoc(), 6316 "writeback register not allowed in register list"); 6317 break; 6318 case ARM::t2LDMIA: 6319 case ARM::t2LDMDB: 6320 if (validatetLDMRegList(Inst, Operands, 3)) 6321 return true; 6322 break; 6323 case ARM::t2STMIA: 6324 case ARM::t2STMDB: 6325 if (validatetSTMRegList(Inst, Operands, 3)) 6326 return true; 6327 break; 6328 case ARM::t2LDMIA_UPD: 6329 case ARM::t2LDMDB_UPD: 6330 case ARM::t2STMIA_UPD: 6331 case ARM::t2STMDB_UPD: { 6332 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) 6333 return Error(Operands.back()->getStartLoc(), 6334 "writeback register not allowed in register list"); 6335 6336 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) { 6337 if (validatetLDMRegList(Inst, Operands, 3)) 6338 return true; 6339 } else { 6340 if (validatetSTMRegList(Inst, Operands, 3)) 6341 return true; 6342 } 6343 break; 6344 } 6345 case ARM::sysLDMIA_UPD: 6346 case ARM::sysLDMDA_UPD: 6347 case ARM::sysLDMDB_UPD: 6348 case ARM::sysLDMIB_UPD: 6349 if (!listContainsReg(Inst, 3, ARM::PC)) 6350 return Error(Operands[4]->getStartLoc(), 6351 "writeback register only allowed on system LDM " 6352 "if PC in register-list"); 6353 break; 6354 case ARM::sysSTMIA_UPD: 6355 case ARM::sysSTMDA_UPD: 6356 case ARM::sysSTMDB_UPD: 6357 case ARM::sysSTMIB_UPD: 6358 return Error(Operands[2]->getStartLoc(), 6359 "system STM cannot have writeback register"); 6360 case ARM::tMUL: { 6361 // The second source operand must be the same register as the destination 6362 // operand. 6363 // 6364 // In this case, we must directly check the parsed operands because the 6365 // cvtThumbMultiply() function is written in such a way that it guarantees 6366 // this first statement is always true for the new Inst. Essentially, the 6367 // destination is unconditionally copied into the second source operand 6368 // without checking to see if it matches what we actually parsed. 6369 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() != 6370 ((ARMOperand &)*Operands[5]).getReg()) && 6371 (((ARMOperand &)*Operands[3]).getReg() != 6372 ((ARMOperand &)*Operands[4]).getReg())) { 6373 return Error(Operands[3]->getStartLoc(), 6374 "destination register must match source register"); 6375 } 6376 break; 6377 } 6378 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2, 6379 // so only issue a diagnostic for thumb1. The instructions will be 6380 // switched to the t2 encodings in processInstruction() if necessary. 6381 case ARM::tPOP: { 6382 bool ListContainsBase; 6383 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) && 6384 !isThumbTwo()) 6385 return Error(Operands[2]->getStartLoc(), 6386 "registers must be in range r0-r7 or pc"); 6387 if (validatetLDMRegList(Inst, Operands, 2, !isMClass())) 6388 return true; 6389 break; 6390 } 6391 case ARM::tPUSH: { 6392 bool ListContainsBase; 6393 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) && 6394 !isThumbTwo()) 6395 return Error(Operands[2]->getStartLoc(), 6396 "registers must be in range r0-r7 or lr"); 6397 if (validatetSTMRegList(Inst, Operands, 2)) 6398 return true; 6399 break; 6400 } 6401 case ARM::tSTMIA_UPD: { 6402 bool ListContainsBase, InvalidLowList; 6403 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(), 6404 0, ListContainsBase); 6405 if (InvalidLowList && !isThumbTwo()) 6406 return Error(Operands[4]->getStartLoc(), 6407 "registers must be in range r0-r7"); 6408 6409 // This would be converted to a 32-bit stm, but that's not valid if the 6410 // writeback register is in the list. 6411 if (InvalidLowList && ListContainsBase) 6412 return Error(Operands[4]->getStartLoc(), 6413 "writeback operator '!' not allowed when base register " 6414 "in register list"); 6415 6416 if (validatetSTMRegList(Inst, Operands, 4)) 6417 return true; 6418 break; 6419 } 6420 case ARM::tADDrSP: { 6421 // If the non-SP source operand and the destination operand are not the 6422 // same, we need thumb2 (for the wide encoding), or we have an error. 6423 if (!isThumbTwo() && 6424 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { 6425 return Error(Operands[4]->getStartLoc(), 6426 "source register must be the same as destination"); 6427 } 6428 break; 6429 } 6430 // Final range checking for Thumb unconditional branch instructions. 6431 case ARM::tB: 6432 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>()) 6433 return Error(Operands[2]->getStartLoc(), "branch target out of range"); 6434 break; 6435 case ARM::t2B: { 6436 int op = (Operands[2]->isImm()) ? 2 : 3; 6437 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>()) 6438 return Error(Operands[op]->getStartLoc(), "branch target out of range"); 6439 break; 6440 } 6441 // Final range checking for Thumb conditional branch instructions. 6442 case ARM::tBcc: 6443 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>()) 6444 return Error(Operands[2]->getStartLoc(), "branch target out of range"); 6445 break; 6446 case ARM::t2Bcc: { 6447 int Op = (Operands[2]->isImm()) ? 2 : 3; 6448 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>()) 6449 return Error(Operands[Op]->getStartLoc(), "branch target out of range"); 6450 break; 6451 } 6452 case ARM::MOVi16: 6453 case ARM::t2MOVi16: 6454 case ARM::t2MOVTi16: 6455 { 6456 // We want to avoid misleadingly allowing something like "mov r0, <symbol>" 6457 // especially when we turn it into a movw and the expression <symbol> does 6458 // not have a :lower16: or :upper16 as part of the expression. We don't 6459 // want the behavior of silently truncating, which can be unexpected and 6460 // lead to bugs that are difficult to find since this is an easy mistake 6461 // to make. 6462 int i = (Operands[3]->isImm()) ? 3 : 4; 6463 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]); 6464 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()); 6465 if (CE) break; 6466 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm()); 6467 if (!E) break; 6468 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E); 6469 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 && 6470 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)) 6471 return Error( 6472 Op.getStartLoc(), 6473 "immediate expression for mov requires :lower16: or :upper16"); 6474 break; 6475 } 6476 } 6477 6478 return false; 6479 } 6480 6481 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) { 6482 switch(Opc) { 6483 default: llvm_unreachable("unexpected opcode!"); 6484 // VST1LN 6485 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; 6486 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; 6487 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; 6488 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; 6489 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; 6490 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; 6491 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8; 6492 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16; 6493 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32; 6494 6495 // VST2LN 6496 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; 6497 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; 6498 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; 6499 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; 6500 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; 6501 6502 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; 6503 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; 6504 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; 6505 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; 6506 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; 6507 6508 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8; 6509 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16; 6510 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32; 6511 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16; 6512 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32; 6513 6514 // VST3LN 6515 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; 6516 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; 6517 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; 6518 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD; 6519 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; 6520 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; 6521 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; 6522 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; 6523 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD; 6524 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; 6525 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8; 6526 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16; 6527 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32; 6528 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16; 6529 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32; 6530 6531 // VST3 6532 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; 6533 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; 6534 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; 6535 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; 6536 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; 6537 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; 6538 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; 6539 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; 6540 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; 6541 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; 6542 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; 6543 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; 6544 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8; 6545 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16; 6546 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32; 6547 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8; 6548 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16; 6549 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32; 6550 6551 // VST4LN 6552 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; 6553 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; 6554 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; 6555 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD; 6556 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; 6557 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; 6558 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; 6559 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; 6560 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD; 6561 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; 6562 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8; 6563 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16; 6564 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32; 6565 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16; 6566 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32; 6567 6568 // VST4 6569 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; 6570 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; 6571 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; 6572 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; 6573 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; 6574 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; 6575 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; 6576 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; 6577 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; 6578 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; 6579 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; 6580 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; 6581 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8; 6582 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16; 6583 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32; 6584 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8; 6585 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16; 6586 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32; 6587 } 6588 } 6589 6590 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) { 6591 switch(Opc) { 6592 default: llvm_unreachable("unexpected opcode!"); 6593 // VLD1LN 6594 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; 6595 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; 6596 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; 6597 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; 6598 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; 6599 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; 6600 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8; 6601 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16; 6602 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32; 6603 6604 // VLD2LN 6605 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; 6606 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; 6607 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; 6608 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD; 6609 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; 6610 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; 6611 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; 6612 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; 6613 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD; 6614 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; 6615 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8; 6616 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16; 6617 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32; 6618 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16; 6619 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32; 6620 6621 // VLD3DUP 6622 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; 6623 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; 6624 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; 6625 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD; 6626 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; 6627 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; 6628 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; 6629 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; 6630 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; 6631 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD; 6632 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; 6633 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; 6634 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8; 6635 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16; 6636 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32; 6637 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8; 6638 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16; 6639 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32; 6640 6641 // VLD3LN 6642 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; 6643 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; 6644 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; 6645 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD; 6646 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; 6647 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; 6648 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; 6649 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; 6650 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD; 6651 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; 6652 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8; 6653 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16; 6654 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32; 6655 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16; 6656 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32; 6657 6658 // VLD3 6659 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; 6660 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; 6661 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; 6662 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; 6663 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; 6664 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; 6665 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; 6666 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; 6667 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; 6668 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; 6669 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; 6670 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; 6671 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8; 6672 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16; 6673 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32; 6674 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8; 6675 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16; 6676 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32; 6677 6678 // VLD4LN 6679 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; 6680 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; 6681 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; 6682 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; 6683 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; 6684 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; 6685 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; 6686 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; 6687 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; 6688 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; 6689 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8; 6690 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16; 6691 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32; 6692 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16; 6693 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32; 6694 6695 // VLD4DUP 6696 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; 6697 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; 6698 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; 6699 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD; 6700 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD; 6701 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; 6702 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; 6703 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; 6704 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; 6705 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD; 6706 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD; 6707 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; 6708 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8; 6709 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16; 6710 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32; 6711 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8; 6712 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16; 6713 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32; 6714 6715 // VLD4 6716 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; 6717 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; 6718 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; 6719 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; 6720 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; 6721 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; 6722 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; 6723 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; 6724 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; 6725 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; 6726 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; 6727 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; 6728 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8; 6729 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16; 6730 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32; 6731 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8; 6732 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16; 6733 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32; 6734 } 6735 } 6736 6737 bool ARMAsmParser::processInstruction(MCInst &Inst, 6738 const OperandVector &Operands, 6739 MCStreamer &Out) { 6740 switch (Inst.getOpcode()) { 6741 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction. 6742 case ARM::LDRT_POST: 6743 case ARM::LDRBT_POST: { 6744 const unsigned Opcode = 6745 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM 6746 : ARM::LDRBT_POST_IMM; 6747 MCInst TmpInst; 6748 TmpInst.setOpcode(Opcode); 6749 TmpInst.addOperand(Inst.getOperand(0)); 6750 TmpInst.addOperand(Inst.getOperand(1)); 6751 TmpInst.addOperand(Inst.getOperand(1)); 6752 TmpInst.addOperand(MCOperand::createReg(0)); 6753 TmpInst.addOperand(MCOperand::createImm(0)); 6754 TmpInst.addOperand(Inst.getOperand(2)); 6755 TmpInst.addOperand(Inst.getOperand(3)); 6756 Inst = TmpInst; 6757 return true; 6758 } 6759 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction. 6760 case ARM::STRT_POST: 6761 case ARM::STRBT_POST: { 6762 const unsigned Opcode = 6763 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM 6764 : ARM::STRBT_POST_IMM; 6765 MCInst TmpInst; 6766 TmpInst.setOpcode(Opcode); 6767 TmpInst.addOperand(Inst.getOperand(1)); 6768 TmpInst.addOperand(Inst.getOperand(0)); 6769 TmpInst.addOperand(Inst.getOperand(1)); 6770 TmpInst.addOperand(MCOperand::createReg(0)); 6771 TmpInst.addOperand(MCOperand::createImm(0)); 6772 TmpInst.addOperand(Inst.getOperand(2)); 6773 TmpInst.addOperand(Inst.getOperand(3)); 6774 Inst = TmpInst; 6775 return true; 6776 } 6777 // Alias for alternate form of 'ADR Rd, #imm' instruction. 6778 case ARM::ADDri: { 6779 if (Inst.getOperand(1).getReg() != ARM::PC || 6780 Inst.getOperand(5).getReg() != 0 || 6781 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm())) 6782 return false; 6783 MCInst TmpInst; 6784 TmpInst.setOpcode(ARM::ADR); 6785 TmpInst.addOperand(Inst.getOperand(0)); 6786 if (Inst.getOperand(2).isImm()) { 6787 // Immediate (mod_imm) will be in its encoded form, we must unencode it 6788 // before passing it to the ADR instruction. 6789 unsigned Enc = Inst.getOperand(2).getImm(); 6790 TmpInst.addOperand(MCOperand::createImm( 6791 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7))); 6792 } else { 6793 // Turn PC-relative expression into absolute expression. 6794 // Reading PC provides the start of the current instruction + 8 and 6795 // the transform to adr is biased by that. 6796 MCSymbol *Dot = getContext().createTempSymbol(); 6797 Out.EmitLabel(Dot); 6798 const MCExpr *OpExpr = Inst.getOperand(2).getExpr(); 6799 const MCExpr *InstPC = MCSymbolRefExpr::create(Dot, 6800 MCSymbolRefExpr::VK_None, 6801 getContext()); 6802 const MCExpr *Const8 = MCConstantExpr::create(8, getContext()); 6803 const MCExpr *ReadPC = MCBinaryExpr::createAdd(InstPC, Const8, 6804 getContext()); 6805 const MCExpr *FixupAddr = MCBinaryExpr::createAdd(ReadPC, OpExpr, 6806 getContext()); 6807 TmpInst.addOperand(MCOperand::createExpr(FixupAddr)); 6808 } 6809 TmpInst.addOperand(Inst.getOperand(3)); 6810 TmpInst.addOperand(Inst.getOperand(4)); 6811 Inst = TmpInst; 6812 return true; 6813 } 6814 // Aliases for alternate PC+imm syntax of LDR instructions. 6815 case ARM::t2LDRpcrel: 6816 // Select the narrow version if the immediate will fit. 6817 if (Inst.getOperand(1).getImm() > 0 && 6818 Inst.getOperand(1).getImm() <= 0xff && 6819 !(static_cast<ARMOperand &>(*Operands[2]).isToken() && 6820 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w")) 6821 Inst.setOpcode(ARM::tLDRpci); 6822 else 6823 Inst.setOpcode(ARM::t2LDRpci); 6824 return true; 6825 case ARM::t2LDRBpcrel: 6826 Inst.setOpcode(ARM::t2LDRBpci); 6827 return true; 6828 case ARM::t2LDRHpcrel: 6829 Inst.setOpcode(ARM::t2LDRHpci); 6830 return true; 6831 case ARM::t2LDRSBpcrel: 6832 Inst.setOpcode(ARM::t2LDRSBpci); 6833 return true; 6834 case ARM::t2LDRSHpcrel: 6835 Inst.setOpcode(ARM::t2LDRSHpci); 6836 return true; 6837 // Handle NEON VST complex aliases. 6838 case ARM::VST1LNdWB_register_Asm_8: 6839 case ARM::VST1LNdWB_register_Asm_16: 6840 case ARM::VST1LNdWB_register_Asm_32: { 6841 MCInst TmpInst; 6842 // Shuffle the operands around so the lane index operand is in the 6843 // right place. 6844 unsigned Spacing; 6845 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 6846 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 6847 TmpInst.addOperand(Inst.getOperand(2)); // Rn 6848 TmpInst.addOperand(Inst.getOperand(3)); // alignment 6849 TmpInst.addOperand(Inst.getOperand(4)); // Rm 6850 TmpInst.addOperand(Inst.getOperand(0)); // Vd 6851 TmpInst.addOperand(Inst.getOperand(1)); // lane 6852 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 6853 TmpInst.addOperand(Inst.getOperand(6)); 6854 Inst = TmpInst; 6855 return true; 6856 } 6857 6858 case ARM::VST2LNdWB_register_Asm_8: 6859 case ARM::VST2LNdWB_register_Asm_16: 6860 case ARM::VST2LNdWB_register_Asm_32: 6861 case ARM::VST2LNqWB_register_Asm_16: 6862 case ARM::VST2LNqWB_register_Asm_32: { 6863 MCInst TmpInst; 6864 // Shuffle the operands around so the lane index operand is in the 6865 // right place. 6866 unsigned Spacing; 6867 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 6868 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 6869 TmpInst.addOperand(Inst.getOperand(2)); // Rn 6870 TmpInst.addOperand(Inst.getOperand(3)); // alignment 6871 TmpInst.addOperand(Inst.getOperand(4)); // Rm 6872 TmpInst.addOperand(Inst.getOperand(0)); // Vd 6873 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6874 Spacing)); 6875 TmpInst.addOperand(Inst.getOperand(1)); // lane 6876 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 6877 TmpInst.addOperand(Inst.getOperand(6)); 6878 Inst = TmpInst; 6879 return true; 6880 } 6881 6882 case ARM::VST3LNdWB_register_Asm_8: 6883 case ARM::VST3LNdWB_register_Asm_16: 6884 case ARM::VST3LNdWB_register_Asm_32: 6885 case ARM::VST3LNqWB_register_Asm_16: 6886 case ARM::VST3LNqWB_register_Asm_32: { 6887 MCInst TmpInst; 6888 // Shuffle the operands around so the lane index operand is in the 6889 // right place. 6890 unsigned Spacing; 6891 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 6892 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 6893 TmpInst.addOperand(Inst.getOperand(2)); // Rn 6894 TmpInst.addOperand(Inst.getOperand(3)); // alignment 6895 TmpInst.addOperand(Inst.getOperand(4)); // Rm 6896 TmpInst.addOperand(Inst.getOperand(0)); // Vd 6897 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6898 Spacing)); 6899 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6900 Spacing * 2)); 6901 TmpInst.addOperand(Inst.getOperand(1)); // lane 6902 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 6903 TmpInst.addOperand(Inst.getOperand(6)); 6904 Inst = TmpInst; 6905 return true; 6906 } 6907 6908 case ARM::VST4LNdWB_register_Asm_8: 6909 case ARM::VST4LNdWB_register_Asm_16: 6910 case ARM::VST4LNdWB_register_Asm_32: 6911 case ARM::VST4LNqWB_register_Asm_16: 6912 case ARM::VST4LNqWB_register_Asm_32: { 6913 MCInst TmpInst; 6914 // Shuffle the operands around so the lane index operand is in the 6915 // right place. 6916 unsigned Spacing; 6917 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 6918 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 6919 TmpInst.addOperand(Inst.getOperand(2)); // Rn 6920 TmpInst.addOperand(Inst.getOperand(3)); // alignment 6921 TmpInst.addOperand(Inst.getOperand(4)); // Rm 6922 TmpInst.addOperand(Inst.getOperand(0)); // Vd 6923 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6924 Spacing)); 6925 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6926 Spacing * 2)); 6927 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6928 Spacing * 3)); 6929 TmpInst.addOperand(Inst.getOperand(1)); // lane 6930 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 6931 TmpInst.addOperand(Inst.getOperand(6)); 6932 Inst = TmpInst; 6933 return true; 6934 } 6935 6936 case ARM::VST1LNdWB_fixed_Asm_8: 6937 case ARM::VST1LNdWB_fixed_Asm_16: 6938 case ARM::VST1LNdWB_fixed_Asm_32: { 6939 MCInst TmpInst; 6940 // Shuffle the operands around so the lane index operand is in the 6941 // right place. 6942 unsigned Spacing; 6943 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 6944 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 6945 TmpInst.addOperand(Inst.getOperand(2)); // Rn 6946 TmpInst.addOperand(Inst.getOperand(3)); // alignment 6947 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 6948 TmpInst.addOperand(Inst.getOperand(0)); // Vd 6949 TmpInst.addOperand(Inst.getOperand(1)); // lane 6950 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 6951 TmpInst.addOperand(Inst.getOperand(5)); 6952 Inst = TmpInst; 6953 return true; 6954 } 6955 6956 case ARM::VST2LNdWB_fixed_Asm_8: 6957 case ARM::VST2LNdWB_fixed_Asm_16: 6958 case ARM::VST2LNdWB_fixed_Asm_32: 6959 case ARM::VST2LNqWB_fixed_Asm_16: 6960 case ARM::VST2LNqWB_fixed_Asm_32: { 6961 MCInst TmpInst; 6962 // Shuffle the operands around so the lane index operand is in the 6963 // right place. 6964 unsigned Spacing; 6965 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 6966 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 6967 TmpInst.addOperand(Inst.getOperand(2)); // Rn 6968 TmpInst.addOperand(Inst.getOperand(3)); // alignment 6969 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 6970 TmpInst.addOperand(Inst.getOperand(0)); // Vd 6971 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6972 Spacing)); 6973 TmpInst.addOperand(Inst.getOperand(1)); // lane 6974 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 6975 TmpInst.addOperand(Inst.getOperand(5)); 6976 Inst = TmpInst; 6977 return true; 6978 } 6979 6980 case ARM::VST3LNdWB_fixed_Asm_8: 6981 case ARM::VST3LNdWB_fixed_Asm_16: 6982 case ARM::VST3LNdWB_fixed_Asm_32: 6983 case ARM::VST3LNqWB_fixed_Asm_16: 6984 case ARM::VST3LNqWB_fixed_Asm_32: { 6985 MCInst TmpInst; 6986 // Shuffle the operands around so the lane index operand is in the 6987 // right place. 6988 unsigned Spacing; 6989 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 6990 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 6991 TmpInst.addOperand(Inst.getOperand(2)); // Rn 6992 TmpInst.addOperand(Inst.getOperand(3)); // alignment 6993 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 6994 TmpInst.addOperand(Inst.getOperand(0)); // Vd 6995 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6996 Spacing)); 6997 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 6998 Spacing * 2)); 6999 TmpInst.addOperand(Inst.getOperand(1)); // lane 7000 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7001 TmpInst.addOperand(Inst.getOperand(5)); 7002 Inst = TmpInst; 7003 return true; 7004 } 7005 7006 case ARM::VST4LNdWB_fixed_Asm_8: 7007 case ARM::VST4LNdWB_fixed_Asm_16: 7008 case ARM::VST4LNdWB_fixed_Asm_32: 7009 case ARM::VST4LNqWB_fixed_Asm_16: 7010 case ARM::VST4LNqWB_fixed_Asm_32: { 7011 MCInst TmpInst; 7012 // Shuffle the operands around so the lane index operand is in the 7013 // right place. 7014 unsigned Spacing; 7015 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7016 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7017 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7018 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7019 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7020 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7021 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7022 Spacing)); 7023 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7024 Spacing * 2)); 7025 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7026 Spacing * 3)); 7027 TmpInst.addOperand(Inst.getOperand(1)); // lane 7028 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7029 TmpInst.addOperand(Inst.getOperand(5)); 7030 Inst = TmpInst; 7031 return true; 7032 } 7033 7034 case ARM::VST1LNdAsm_8: 7035 case ARM::VST1LNdAsm_16: 7036 case ARM::VST1LNdAsm_32: { 7037 MCInst TmpInst; 7038 // Shuffle the operands around so the lane index operand is in the 7039 // right place. 7040 unsigned Spacing; 7041 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7042 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7043 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7044 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7045 TmpInst.addOperand(Inst.getOperand(1)); // lane 7046 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7047 TmpInst.addOperand(Inst.getOperand(5)); 7048 Inst = TmpInst; 7049 return true; 7050 } 7051 7052 case ARM::VST2LNdAsm_8: 7053 case ARM::VST2LNdAsm_16: 7054 case ARM::VST2LNdAsm_32: 7055 case ARM::VST2LNqAsm_16: 7056 case ARM::VST2LNqAsm_32: { 7057 MCInst TmpInst; 7058 // Shuffle the operands around so the lane index operand is in the 7059 // right place. 7060 unsigned Spacing; 7061 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7062 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7063 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7064 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7065 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7066 Spacing)); 7067 TmpInst.addOperand(Inst.getOperand(1)); // lane 7068 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7069 TmpInst.addOperand(Inst.getOperand(5)); 7070 Inst = TmpInst; 7071 return true; 7072 } 7073 7074 case ARM::VST3LNdAsm_8: 7075 case ARM::VST3LNdAsm_16: 7076 case ARM::VST3LNdAsm_32: 7077 case ARM::VST3LNqAsm_16: 7078 case ARM::VST3LNqAsm_32: { 7079 MCInst TmpInst; 7080 // Shuffle the operands around so the lane index operand is in the 7081 // right place. 7082 unsigned Spacing; 7083 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7084 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7085 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7086 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7087 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7088 Spacing)); 7089 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7090 Spacing * 2)); 7091 TmpInst.addOperand(Inst.getOperand(1)); // lane 7092 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7093 TmpInst.addOperand(Inst.getOperand(5)); 7094 Inst = TmpInst; 7095 return true; 7096 } 7097 7098 case ARM::VST4LNdAsm_8: 7099 case ARM::VST4LNdAsm_16: 7100 case ARM::VST4LNdAsm_32: 7101 case ARM::VST4LNqAsm_16: 7102 case ARM::VST4LNqAsm_32: { 7103 MCInst TmpInst; 7104 // Shuffle the operands around so the lane index operand is in the 7105 // right place. 7106 unsigned Spacing; 7107 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7108 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7109 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7110 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7111 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7112 Spacing)); 7113 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7114 Spacing * 2)); 7115 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7116 Spacing * 3)); 7117 TmpInst.addOperand(Inst.getOperand(1)); // lane 7118 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7119 TmpInst.addOperand(Inst.getOperand(5)); 7120 Inst = TmpInst; 7121 return true; 7122 } 7123 7124 // Handle NEON VLD complex aliases. 7125 case ARM::VLD1LNdWB_register_Asm_8: 7126 case ARM::VLD1LNdWB_register_Asm_16: 7127 case ARM::VLD1LNdWB_register_Asm_32: { 7128 MCInst TmpInst; 7129 // Shuffle the operands around so the lane index operand is in the 7130 // right place. 7131 unsigned Spacing; 7132 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7133 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7134 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7135 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7136 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7137 TmpInst.addOperand(Inst.getOperand(4)); // Rm 7138 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7139 TmpInst.addOperand(Inst.getOperand(1)); // lane 7140 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 7141 TmpInst.addOperand(Inst.getOperand(6)); 7142 Inst = TmpInst; 7143 return true; 7144 } 7145 7146 case ARM::VLD2LNdWB_register_Asm_8: 7147 case ARM::VLD2LNdWB_register_Asm_16: 7148 case ARM::VLD2LNdWB_register_Asm_32: 7149 case ARM::VLD2LNqWB_register_Asm_16: 7150 case ARM::VLD2LNqWB_register_Asm_32: { 7151 MCInst TmpInst; 7152 // Shuffle the operands around so the lane index operand is in the 7153 // right place. 7154 unsigned Spacing; 7155 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7156 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7157 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7158 Spacing)); 7159 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7160 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7161 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7162 TmpInst.addOperand(Inst.getOperand(4)); // Rm 7163 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7164 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7165 Spacing)); 7166 TmpInst.addOperand(Inst.getOperand(1)); // lane 7167 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 7168 TmpInst.addOperand(Inst.getOperand(6)); 7169 Inst = TmpInst; 7170 return true; 7171 } 7172 7173 case ARM::VLD3LNdWB_register_Asm_8: 7174 case ARM::VLD3LNdWB_register_Asm_16: 7175 case ARM::VLD3LNdWB_register_Asm_32: 7176 case ARM::VLD3LNqWB_register_Asm_16: 7177 case ARM::VLD3LNqWB_register_Asm_32: { 7178 MCInst TmpInst; 7179 // Shuffle the operands around so the lane index operand is in the 7180 // right place. 7181 unsigned Spacing; 7182 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7183 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7184 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7185 Spacing)); 7186 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7187 Spacing * 2)); 7188 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7189 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7190 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7191 TmpInst.addOperand(Inst.getOperand(4)); // Rm 7192 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7193 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7194 Spacing)); 7195 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7196 Spacing * 2)); 7197 TmpInst.addOperand(Inst.getOperand(1)); // lane 7198 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 7199 TmpInst.addOperand(Inst.getOperand(6)); 7200 Inst = TmpInst; 7201 return true; 7202 } 7203 7204 case ARM::VLD4LNdWB_register_Asm_8: 7205 case ARM::VLD4LNdWB_register_Asm_16: 7206 case ARM::VLD4LNdWB_register_Asm_32: 7207 case ARM::VLD4LNqWB_register_Asm_16: 7208 case ARM::VLD4LNqWB_register_Asm_32: { 7209 MCInst TmpInst; 7210 // Shuffle the operands around so the lane index operand is in the 7211 // right place. 7212 unsigned Spacing; 7213 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7214 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7215 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7216 Spacing)); 7217 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7218 Spacing * 2)); 7219 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7220 Spacing * 3)); 7221 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7222 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7223 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7224 TmpInst.addOperand(Inst.getOperand(4)); // Rm 7225 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7226 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7227 Spacing)); 7228 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7229 Spacing * 2)); 7230 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7231 Spacing * 3)); 7232 TmpInst.addOperand(Inst.getOperand(1)); // lane 7233 TmpInst.addOperand(Inst.getOperand(5)); // CondCode 7234 TmpInst.addOperand(Inst.getOperand(6)); 7235 Inst = TmpInst; 7236 return true; 7237 } 7238 7239 case ARM::VLD1LNdWB_fixed_Asm_8: 7240 case ARM::VLD1LNdWB_fixed_Asm_16: 7241 case ARM::VLD1LNdWB_fixed_Asm_32: { 7242 MCInst TmpInst; 7243 // Shuffle the operands around so the lane index operand is in the 7244 // right place. 7245 unsigned Spacing; 7246 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7247 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7248 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7249 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7250 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7251 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7252 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7253 TmpInst.addOperand(Inst.getOperand(1)); // lane 7254 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7255 TmpInst.addOperand(Inst.getOperand(5)); 7256 Inst = TmpInst; 7257 return true; 7258 } 7259 7260 case ARM::VLD2LNdWB_fixed_Asm_8: 7261 case ARM::VLD2LNdWB_fixed_Asm_16: 7262 case ARM::VLD2LNdWB_fixed_Asm_32: 7263 case ARM::VLD2LNqWB_fixed_Asm_16: 7264 case ARM::VLD2LNqWB_fixed_Asm_32: { 7265 MCInst TmpInst; 7266 // Shuffle the operands around so the lane index operand is in the 7267 // right place. 7268 unsigned Spacing; 7269 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7270 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7271 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7272 Spacing)); 7273 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7274 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7275 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7276 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7277 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7278 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7279 Spacing)); 7280 TmpInst.addOperand(Inst.getOperand(1)); // lane 7281 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7282 TmpInst.addOperand(Inst.getOperand(5)); 7283 Inst = TmpInst; 7284 return true; 7285 } 7286 7287 case ARM::VLD3LNdWB_fixed_Asm_8: 7288 case ARM::VLD3LNdWB_fixed_Asm_16: 7289 case ARM::VLD3LNdWB_fixed_Asm_32: 7290 case ARM::VLD3LNqWB_fixed_Asm_16: 7291 case ARM::VLD3LNqWB_fixed_Asm_32: { 7292 MCInst TmpInst; 7293 // Shuffle the operands around so the lane index operand is in the 7294 // right place. 7295 unsigned Spacing; 7296 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7297 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7298 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7299 Spacing)); 7300 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7301 Spacing * 2)); 7302 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7303 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7304 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7305 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7306 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7307 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7308 Spacing)); 7309 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7310 Spacing * 2)); 7311 TmpInst.addOperand(Inst.getOperand(1)); // lane 7312 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7313 TmpInst.addOperand(Inst.getOperand(5)); 7314 Inst = TmpInst; 7315 return true; 7316 } 7317 7318 case ARM::VLD4LNdWB_fixed_Asm_8: 7319 case ARM::VLD4LNdWB_fixed_Asm_16: 7320 case ARM::VLD4LNdWB_fixed_Asm_32: 7321 case ARM::VLD4LNqWB_fixed_Asm_16: 7322 case ARM::VLD4LNqWB_fixed_Asm_32: { 7323 MCInst TmpInst; 7324 // Shuffle the operands around so the lane index operand is in the 7325 // right place. 7326 unsigned Spacing; 7327 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7328 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7329 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7330 Spacing)); 7331 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7332 Spacing * 2)); 7333 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7334 Spacing * 3)); 7335 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb 7336 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7337 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7338 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7339 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7340 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7341 Spacing)); 7342 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7343 Spacing * 2)); 7344 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7345 Spacing * 3)); 7346 TmpInst.addOperand(Inst.getOperand(1)); // lane 7347 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7348 TmpInst.addOperand(Inst.getOperand(5)); 7349 Inst = TmpInst; 7350 return true; 7351 } 7352 7353 case ARM::VLD1LNdAsm_8: 7354 case ARM::VLD1LNdAsm_16: 7355 case ARM::VLD1LNdAsm_32: { 7356 MCInst TmpInst; 7357 // Shuffle the operands around so the lane index operand is in the 7358 // right place. 7359 unsigned Spacing; 7360 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7361 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7362 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7363 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7364 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7365 TmpInst.addOperand(Inst.getOperand(1)); // lane 7366 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7367 TmpInst.addOperand(Inst.getOperand(5)); 7368 Inst = TmpInst; 7369 return true; 7370 } 7371 7372 case ARM::VLD2LNdAsm_8: 7373 case ARM::VLD2LNdAsm_16: 7374 case ARM::VLD2LNdAsm_32: 7375 case ARM::VLD2LNqAsm_16: 7376 case ARM::VLD2LNqAsm_32: { 7377 MCInst TmpInst; 7378 // Shuffle the operands around so the lane index operand is in the 7379 // right place. 7380 unsigned Spacing; 7381 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7382 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7383 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7384 Spacing)); 7385 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7386 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7387 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7388 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7389 Spacing)); 7390 TmpInst.addOperand(Inst.getOperand(1)); // lane 7391 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7392 TmpInst.addOperand(Inst.getOperand(5)); 7393 Inst = TmpInst; 7394 return true; 7395 } 7396 7397 case ARM::VLD3LNdAsm_8: 7398 case ARM::VLD3LNdAsm_16: 7399 case ARM::VLD3LNdAsm_32: 7400 case ARM::VLD3LNqAsm_16: 7401 case ARM::VLD3LNqAsm_32: { 7402 MCInst TmpInst; 7403 // Shuffle the operands around so the lane index operand is in the 7404 // right place. 7405 unsigned Spacing; 7406 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7407 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7408 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7409 Spacing)); 7410 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7411 Spacing * 2)); 7412 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7413 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7414 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7415 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7416 Spacing)); 7417 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7418 Spacing * 2)); 7419 TmpInst.addOperand(Inst.getOperand(1)); // lane 7420 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7421 TmpInst.addOperand(Inst.getOperand(5)); 7422 Inst = TmpInst; 7423 return true; 7424 } 7425 7426 case ARM::VLD4LNdAsm_8: 7427 case ARM::VLD4LNdAsm_16: 7428 case ARM::VLD4LNdAsm_32: 7429 case ARM::VLD4LNqAsm_16: 7430 case ARM::VLD4LNqAsm_32: { 7431 MCInst TmpInst; 7432 // Shuffle the operands around so the lane index operand is in the 7433 // right place. 7434 unsigned Spacing; 7435 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7436 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7437 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7438 Spacing)); 7439 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7440 Spacing * 2)); 7441 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7442 Spacing * 3)); 7443 TmpInst.addOperand(Inst.getOperand(2)); // Rn 7444 TmpInst.addOperand(Inst.getOperand(3)); // alignment 7445 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) 7446 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7447 Spacing)); 7448 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7449 Spacing * 2)); 7450 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7451 Spacing * 3)); 7452 TmpInst.addOperand(Inst.getOperand(1)); // lane 7453 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7454 TmpInst.addOperand(Inst.getOperand(5)); 7455 Inst = TmpInst; 7456 return true; 7457 } 7458 7459 // VLD3DUP single 3-element structure to all lanes instructions. 7460 case ARM::VLD3DUPdAsm_8: 7461 case ARM::VLD3DUPdAsm_16: 7462 case ARM::VLD3DUPdAsm_32: 7463 case ARM::VLD3DUPqAsm_8: 7464 case ARM::VLD3DUPqAsm_16: 7465 case ARM::VLD3DUPqAsm_32: { 7466 MCInst TmpInst; 7467 unsigned Spacing; 7468 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7469 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7470 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7471 Spacing)); 7472 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7473 Spacing * 2)); 7474 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7475 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7476 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7477 TmpInst.addOperand(Inst.getOperand(4)); 7478 Inst = TmpInst; 7479 return true; 7480 } 7481 7482 case ARM::VLD3DUPdWB_fixed_Asm_8: 7483 case ARM::VLD3DUPdWB_fixed_Asm_16: 7484 case ARM::VLD3DUPdWB_fixed_Asm_32: 7485 case ARM::VLD3DUPqWB_fixed_Asm_8: 7486 case ARM::VLD3DUPqWB_fixed_Asm_16: 7487 case ARM::VLD3DUPqWB_fixed_Asm_32: { 7488 MCInst TmpInst; 7489 unsigned Spacing; 7490 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7491 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7492 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7493 Spacing)); 7494 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7495 Spacing * 2)); 7496 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7497 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7498 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7499 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7500 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7501 TmpInst.addOperand(Inst.getOperand(4)); 7502 Inst = TmpInst; 7503 return true; 7504 } 7505 7506 case ARM::VLD3DUPdWB_register_Asm_8: 7507 case ARM::VLD3DUPdWB_register_Asm_16: 7508 case ARM::VLD3DUPdWB_register_Asm_32: 7509 case ARM::VLD3DUPqWB_register_Asm_8: 7510 case ARM::VLD3DUPqWB_register_Asm_16: 7511 case ARM::VLD3DUPqWB_register_Asm_32: { 7512 MCInst TmpInst; 7513 unsigned Spacing; 7514 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7515 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7516 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7517 Spacing)); 7518 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7519 Spacing * 2)); 7520 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7521 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7522 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7523 TmpInst.addOperand(Inst.getOperand(3)); // Rm 7524 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7525 TmpInst.addOperand(Inst.getOperand(5)); 7526 Inst = TmpInst; 7527 return true; 7528 } 7529 7530 // VLD3 multiple 3-element structure instructions. 7531 case ARM::VLD3dAsm_8: 7532 case ARM::VLD3dAsm_16: 7533 case ARM::VLD3dAsm_32: 7534 case ARM::VLD3qAsm_8: 7535 case ARM::VLD3qAsm_16: 7536 case ARM::VLD3qAsm_32: { 7537 MCInst TmpInst; 7538 unsigned Spacing; 7539 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7540 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7541 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7542 Spacing)); 7543 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7544 Spacing * 2)); 7545 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7546 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7547 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7548 TmpInst.addOperand(Inst.getOperand(4)); 7549 Inst = TmpInst; 7550 return true; 7551 } 7552 7553 case ARM::VLD3dWB_fixed_Asm_8: 7554 case ARM::VLD3dWB_fixed_Asm_16: 7555 case ARM::VLD3dWB_fixed_Asm_32: 7556 case ARM::VLD3qWB_fixed_Asm_8: 7557 case ARM::VLD3qWB_fixed_Asm_16: 7558 case ARM::VLD3qWB_fixed_Asm_32: { 7559 MCInst TmpInst; 7560 unsigned Spacing; 7561 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7562 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7563 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7564 Spacing)); 7565 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7566 Spacing * 2)); 7567 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7568 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7569 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7570 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7571 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7572 TmpInst.addOperand(Inst.getOperand(4)); 7573 Inst = TmpInst; 7574 return true; 7575 } 7576 7577 case ARM::VLD3dWB_register_Asm_8: 7578 case ARM::VLD3dWB_register_Asm_16: 7579 case ARM::VLD3dWB_register_Asm_32: 7580 case ARM::VLD3qWB_register_Asm_8: 7581 case ARM::VLD3qWB_register_Asm_16: 7582 case ARM::VLD3qWB_register_Asm_32: { 7583 MCInst TmpInst; 7584 unsigned Spacing; 7585 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7586 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7587 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7588 Spacing)); 7589 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7590 Spacing * 2)); 7591 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7592 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7593 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7594 TmpInst.addOperand(Inst.getOperand(3)); // Rm 7595 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7596 TmpInst.addOperand(Inst.getOperand(5)); 7597 Inst = TmpInst; 7598 return true; 7599 } 7600 7601 // VLD4DUP single 3-element structure to all lanes instructions. 7602 case ARM::VLD4DUPdAsm_8: 7603 case ARM::VLD4DUPdAsm_16: 7604 case ARM::VLD4DUPdAsm_32: 7605 case ARM::VLD4DUPqAsm_8: 7606 case ARM::VLD4DUPqAsm_16: 7607 case ARM::VLD4DUPqAsm_32: { 7608 MCInst TmpInst; 7609 unsigned Spacing; 7610 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7611 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7612 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7613 Spacing)); 7614 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7615 Spacing * 2)); 7616 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7617 Spacing * 3)); 7618 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7619 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7620 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7621 TmpInst.addOperand(Inst.getOperand(4)); 7622 Inst = TmpInst; 7623 return true; 7624 } 7625 7626 case ARM::VLD4DUPdWB_fixed_Asm_8: 7627 case ARM::VLD4DUPdWB_fixed_Asm_16: 7628 case ARM::VLD4DUPdWB_fixed_Asm_32: 7629 case ARM::VLD4DUPqWB_fixed_Asm_8: 7630 case ARM::VLD4DUPqWB_fixed_Asm_16: 7631 case ARM::VLD4DUPqWB_fixed_Asm_32: { 7632 MCInst TmpInst; 7633 unsigned Spacing; 7634 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7635 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7636 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7637 Spacing)); 7638 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7639 Spacing * 2)); 7640 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7641 Spacing * 3)); 7642 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7643 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7644 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7645 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7646 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7647 TmpInst.addOperand(Inst.getOperand(4)); 7648 Inst = TmpInst; 7649 return true; 7650 } 7651 7652 case ARM::VLD4DUPdWB_register_Asm_8: 7653 case ARM::VLD4DUPdWB_register_Asm_16: 7654 case ARM::VLD4DUPdWB_register_Asm_32: 7655 case ARM::VLD4DUPqWB_register_Asm_8: 7656 case ARM::VLD4DUPqWB_register_Asm_16: 7657 case ARM::VLD4DUPqWB_register_Asm_32: { 7658 MCInst TmpInst; 7659 unsigned Spacing; 7660 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7661 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7662 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7663 Spacing)); 7664 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7665 Spacing * 2)); 7666 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7667 Spacing * 3)); 7668 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7669 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7670 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7671 TmpInst.addOperand(Inst.getOperand(3)); // Rm 7672 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7673 TmpInst.addOperand(Inst.getOperand(5)); 7674 Inst = TmpInst; 7675 return true; 7676 } 7677 7678 // VLD4 multiple 4-element structure instructions. 7679 case ARM::VLD4dAsm_8: 7680 case ARM::VLD4dAsm_16: 7681 case ARM::VLD4dAsm_32: 7682 case ARM::VLD4qAsm_8: 7683 case ARM::VLD4qAsm_16: 7684 case ARM::VLD4qAsm_32: { 7685 MCInst TmpInst; 7686 unsigned Spacing; 7687 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7688 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7689 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7690 Spacing)); 7691 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7692 Spacing * 2)); 7693 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7694 Spacing * 3)); 7695 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7696 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7697 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7698 TmpInst.addOperand(Inst.getOperand(4)); 7699 Inst = TmpInst; 7700 return true; 7701 } 7702 7703 case ARM::VLD4dWB_fixed_Asm_8: 7704 case ARM::VLD4dWB_fixed_Asm_16: 7705 case ARM::VLD4dWB_fixed_Asm_32: 7706 case ARM::VLD4qWB_fixed_Asm_8: 7707 case ARM::VLD4qWB_fixed_Asm_16: 7708 case ARM::VLD4qWB_fixed_Asm_32: { 7709 MCInst TmpInst; 7710 unsigned Spacing; 7711 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7712 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7713 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7714 Spacing)); 7715 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7716 Spacing * 2)); 7717 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7718 Spacing * 3)); 7719 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7720 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7721 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7722 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7723 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7724 TmpInst.addOperand(Inst.getOperand(4)); 7725 Inst = TmpInst; 7726 return true; 7727 } 7728 7729 case ARM::VLD4dWB_register_Asm_8: 7730 case ARM::VLD4dWB_register_Asm_16: 7731 case ARM::VLD4dWB_register_Asm_32: 7732 case ARM::VLD4qWB_register_Asm_8: 7733 case ARM::VLD4qWB_register_Asm_16: 7734 case ARM::VLD4qWB_register_Asm_32: { 7735 MCInst TmpInst; 7736 unsigned Spacing; 7737 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); 7738 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7739 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7740 Spacing)); 7741 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7742 Spacing * 2)); 7743 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7744 Spacing * 3)); 7745 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7746 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7747 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7748 TmpInst.addOperand(Inst.getOperand(3)); // Rm 7749 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7750 TmpInst.addOperand(Inst.getOperand(5)); 7751 Inst = TmpInst; 7752 return true; 7753 } 7754 7755 // VST3 multiple 3-element structure instructions. 7756 case ARM::VST3dAsm_8: 7757 case ARM::VST3dAsm_16: 7758 case ARM::VST3dAsm_32: 7759 case ARM::VST3qAsm_8: 7760 case ARM::VST3qAsm_16: 7761 case ARM::VST3qAsm_32: { 7762 MCInst TmpInst; 7763 unsigned Spacing; 7764 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7765 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7766 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7767 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7768 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7769 Spacing)); 7770 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7771 Spacing * 2)); 7772 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7773 TmpInst.addOperand(Inst.getOperand(4)); 7774 Inst = TmpInst; 7775 return true; 7776 } 7777 7778 case ARM::VST3dWB_fixed_Asm_8: 7779 case ARM::VST3dWB_fixed_Asm_16: 7780 case ARM::VST3dWB_fixed_Asm_32: 7781 case ARM::VST3qWB_fixed_Asm_8: 7782 case ARM::VST3qWB_fixed_Asm_16: 7783 case ARM::VST3qWB_fixed_Asm_32: { 7784 MCInst TmpInst; 7785 unsigned Spacing; 7786 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7787 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7788 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7789 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7790 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7791 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7792 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7793 Spacing)); 7794 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7795 Spacing * 2)); 7796 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7797 TmpInst.addOperand(Inst.getOperand(4)); 7798 Inst = TmpInst; 7799 return true; 7800 } 7801 7802 case ARM::VST3dWB_register_Asm_8: 7803 case ARM::VST3dWB_register_Asm_16: 7804 case ARM::VST3dWB_register_Asm_32: 7805 case ARM::VST3qWB_register_Asm_8: 7806 case ARM::VST3qWB_register_Asm_16: 7807 case ARM::VST3qWB_register_Asm_32: { 7808 MCInst TmpInst; 7809 unsigned Spacing; 7810 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7811 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7812 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7813 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7814 TmpInst.addOperand(Inst.getOperand(3)); // Rm 7815 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7816 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7817 Spacing)); 7818 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7819 Spacing * 2)); 7820 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7821 TmpInst.addOperand(Inst.getOperand(5)); 7822 Inst = TmpInst; 7823 return true; 7824 } 7825 7826 // VST4 multiple 3-element structure instructions. 7827 case ARM::VST4dAsm_8: 7828 case ARM::VST4dAsm_16: 7829 case ARM::VST4dAsm_32: 7830 case ARM::VST4qAsm_8: 7831 case ARM::VST4qAsm_16: 7832 case ARM::VST4qAsm_32: { 7833 MCInst TmpInst; 7834 unsigned Spacing; 7835 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7836 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7837 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7838 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7839 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7840 Spacing)); 7841 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7842 Spacing * 2)); 7843 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7844 Spacing * 3)); 7845 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7846 TmpInst.addOperand(Inst.getOperand(4)); 7847 Inst = TmpInst; 7848 return true; 7849 } 7850 7851 case ARM::VST4dWB_fixed_Asm_8: 7852 case ARM::VST4dWB_fixed_Asm_16: 7853 case ARM::VST4dWB_fixed_Asm_32: 7854 case ARM::VST4qWB_fixed_Asm_8: 7855 case ARM::VST4qWB_fixed_Asm_16: 7856 case ARM::VST4qWB_fixed_Asm_32: { 7857 MCInst TmpInst; 7858 unsigned Spacing; 7859 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7860 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7861 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7862 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7863 TmpInst.addOperand(MCOperand::createReg(0)); // Rm 7864 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7865 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7866 Spacing)); 7867 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7868 Spacing * 2)); 7869 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7870 Spacing * 3)); 7871 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 7872 TmpInst.addOperand(Inst.getOperand(4)); 7873 Inst = TmpInst; 7874 return true; 7875 } 7876 7877 case ARM::VST4dWB_register_Asm_8: 7878 case ARM::VST4dWB_register_Asm_16: 7879 case ARM::VST4dWB_register_Asm_32: 7880 case ARM::VST4qWB_register_Asm_8: 7881 case ARM::VST4qWB_register_Asm_16: 7882 case ARM::VST4qWB_register_Asm_32: { 7883 MCInst TmpInst; 7884 unsigned Spacing; 7885 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); 7886 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7887 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn 7888 TmpInst.addOperand(Inst.getOperand(2)); // alignment 7889 TmpInst.addOperand(Inst.getOperand(3)); // Rm 7890 TmpInst.addOperand(Inst.getOperand(0)); // Vd 7891 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7892 Spacing)); 7893 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7894 Spacing * 2)); 7895 TmpInst.addOperand(MCOperand::createReg(Inst.getOperand(0).getReg() + 7896 Spacing * 3)); 7897 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7898 TmpInst.addOperand(Inst.getOperand(5)); 7899 Inst = TmpInst; 7900 return true; 7901 } 7902 7903 // Handle encoding choice for the shift-immediate instructions. 7904 case ARM::t2LSLri: 7905 case ARM::t2LSRri: 7906 case ARM::t2ASRri: { 7907 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 7908 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && 7909 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) && 7910 !(static_cast<ARMOperand &>(*Operands[3]).isToken() && 7911 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) { 7912 unsigned NewOpc; 7913 switch (Inst.getOpcode()) { 7914 default: llvm_unreachable("unexpected opcode"); 7915 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break; 7916 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break; 7917 case ARM::t2ASRri: NewOpc = ARM::tASRri; break; 7918 } 7919 // The Thumb1 operands aren't in the same order. Awesome, eh? 7920 MCInst TmpInst; 7921 TmpInst.setOpcode(NewOpc); 7922 TmpInst.addOperand(Inst.getOperand(0)); 7923 TmpInst.addOperand(Inst.getOperand(5)); 7924 TmpInst.addOperand(Inst.getOperand(1)); 7925 TmpInst.addOperand(Inst.getOperand(2)); 7926 TmpInst.addOperand(Inst.getOperand(3)); 7927 TmpInst.addOperand(Inst.getOperand(4)); 7928 Inst = TmpInst; 7929 return true; 7930 } 7931 return false; 7932 } 7933 7934 // Handle the Thumb2 mode MOV complex aliases. 7935 case ARM::t2MOVsr: 7936 case ARM::t2MOVSsr: { 7937 // Which instruction to expand to depends on the CCOut operand and 7938 // whether we're in an IT block if the register operands are low 7939 // registers. 7940 bool isNarrow = false; 7941 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 7942 isARMLowRegister(Inst.getOperand(1).getReg()) && 7943 isARMLowRegister(Inst.getOperand(2).getReg()) && 7944 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && 7945 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr)) 7946 isNarrow = true; 7947 MCInst TmpInst; 7948 unsigned newOpc; 7949 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) { 7950 default: llvm_unreachable("unexpected opcode!"); 7951 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break; 7952 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break; 7953 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break; 7954 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break; 7955 } 7956 TmpInst.setOpcode(newOpc); 7957 TmpInst.addOperand(Inst.getOperand(0)); // Rd 7958 if (isNarrow) 7959 TmpInst.addOperand(MCOperand::createReg( 7960 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); 7961 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7962 TmpInst.addOperand(Inst.getOperand(2)); // Rm 7963 TmpInst.addOperand(Inst.getOperand(4)); // CondCode 7964 TmpInst.addOperand(Inst.getOperand(5)); 7965 if (!isNarrow) 7966 TmpInst.addOperand(MCOperand::createReg( 7967 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); 7968 Inst = TmpInst; 7969 return true; 7970 } 7971 case ARM::t2MOVsi: 7972 case ARM::t2MOVSsi: { 7973 // Which instruction to expand to depends on the CCOut operand and 7974 // whether we're in an IT block if the register operands are low 7975 // registers. 7976 bool isNarrow = false; 7977 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 7978 isARMLowRegister(Inst.getOperand(1).getReg()) && 7979 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi)) 7980 isNarrow = true; 7981 MCInst TmpInst; 7982 unsigned newOpc; 7983 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) { 7984 default: llvm_unreachable("unexpected opcode!"); 7985 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break; 7986 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break; 7987 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break; 7988 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break; 7989 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break; 7990 } 7991 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()); 7992 if (Amount == 32) Amount = 0; 7993 TmpInst.setOpcode(newOpc); 7994 TmpInst.addOperand(Inst.getOperand(0)); // Rd 7995 if (isNarrow) 7996 TmpInst.addOperand(MCOperand::createReg( 7997 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); 7998 TmpInst.addOperand(Inst.getOperand(1)); // Rn 7999 if (newOpc != ARM::t2RRX) 8000 TmpInst.addOperand(MCOperand::createImm(Amount)); 8001 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 8002 TmpInst.addOperand(Inst.getOperand(4)); 8003 if (!isNarrow) 8004 TmpInst.addOperand(MCOperand::createReg( 8005 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); 8006 Inst = TmpInst; 8007 return true; 8008 } 8009 // Handle the ARM mode MOV complex aliases. 8010 case ARM::ASRr: 8011 case ARM::LSRr: 8012 case ARM::LSLr: 8013 case ARM::RORr: { 8014 ARM_AM::ShiftOpc ShiftTy; 8015 switch(Inst.getOpcode()) { 8016 default: llvm_unreachable("unexpected opcode!"); 8017 case ARM::ASRr: ShiftTy = ARM_AM::asr; break; 8018 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break; 8019 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break; 8020 case ARM::RORr: ShiftTy = ARM_AM::ror; break; 8021 } 8022 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0); 8023 MCInst TmpInst; 8024 TmpInst.setOpcode(ARM::MOVsr); 8025 TmpInst.addOperand(Inst.getOperand(0)); // Rd 8026 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8027 TmpInst.addOperand(Inst.getOperand(2)); // Rm 8028 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty 8029 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 8030 TmpInst.addOperand(Inst.getOperand(4)); 8031 TmpInst.addOperand(Inst.getOperand(5)); // cc_out 8032 Inst = TmpInst; 8033 return true; 8034 } 8035 case ARM::ASRi: 8036 case ARM::LSRi: 8037 case ARM::LSLi: 8038 case ARM::RORi: { 8039 ARM_AM::ShiftOpc ShiftTy; 8040 switch(Inst.getOpcode()) { 8041 default: llvm_unreachable("unexpected opcode!"); 8042 case ARM::ASRi: ShiftTy = ARM_AM::asr; break; 8043 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break; 8044 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break; 8045 case ARM::RORi: ShiftTy = ARM_AM::ror; break; 8046 } 8047 // A shift by zero is a plain MOVr, not a MOVsi. 8048 unsigned Amt = Inst.getOperand(2).getImm(); 8049 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi; 8050 // A shift by 32 should be encoded as 0 when permitted 8051 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr)) 8052 Amt = 0; 8053 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt); 8054 MCInst TmpInst; 8055 TmpInst.setOpcode(Opc); 8056 TmpInst.addOperand(Inst.getOperand(0)); // Rd 8057 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8058 if (Opc == ARM::MOVsi) 8059 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty 8060 TmpInst.addOperand(Inst.getOperand(3)); // CondCode 8061 TmpInst.addOperand(Inst.getOperand(4)); 8062 TmpInst.addOperand(Inst.getOperand(5)); // cc_out 8063 Inst = TmpInst; 8064 return true; 8065 } 8066 case ARM::RRXi: { 8067 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0); 8068 MCInst TmpInst; 8069 TmpInst.setOpcode(ARM::MOVsi); 8070 TmpInst.addOperand(Inst.getOperand(0)); // Rd 8071 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8072 TmpInst.addOperand(MCOperand::createImm(Shifter)); // Shift value and ty 8073 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 8074 TmpInst.addOperand(Inst.getOperand(3)); 8075 TmpInst.addOperand(Inst.getOperand(4)); // cc_out 8076 Inst = TmpInst; 8077 return true; 8078 } 8079 case ARM::t2LDMIA_UPD: { 8080 // If this is a load of a single register, then we should use 8081 // a post-indexed LDR instruction instead, per the ARM ARM. 8082 if (Inst.getNumOperands() != 5) 8083 return false; 8084 MCInst TmpInst; 8085 TmpInst.setOpcode(ARM::t2LDR_POST); 8086 TmpInst.addOperand(Inst.getOperand(4)); // Rt 8087 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 8088 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8089 TmpInst.addOperand(MCOperand::createImm(4)); 8090 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 8091 TmpInst.addOperand(Inst.getOperand(3)); 8092 Inst = TmpInst; 8093 return true; 8094 } 8095 case ARM::t2STMDB_UPD: { 8096 // If this is a store of a single register, then we should use 8097 // a pre-indexed STR instruction instead, per the ARM ARM. 8098 if (Inst.getNumOperands() != 5) 8099 return false; 8100 MCInst TmpInst; 8101 TmpInst.setOpcode(ARM::t2STR_PRE); 8102 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 8103 TmpInst.addOperand(Inst.getOperand(4)); // Rt 8104 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8105 TmpInst.addOperand(MCOperand::createImm(-4)); 8106 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 8107 TmpInst.addOperand(Inst.getOperand(3)); 8108 Inst = TmpInst; 8109 return true; 8110 } 8111 case ARM::LDMIA_UPD: 8112 // If this is a load of a single register via a 'pop', then we should use 8113 // a post-indexed LDR instruction instead, per the ARM ARM. 8114 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" && 8115 Inst.getNumOperands() == 5) { 8116 MCInst TmpInst; 8117 TmpInst.setOpcode(ARM::LDR_POST_IMM); 8118 TmpInst.addOperand(Inst.getOperand(4)); // Rt 8119 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 8120 TmpInst.addOperand(Inst.getOperand(1)); // Rn 8121 TmpInst.addOperand(MCOperand::createReg(0)); // am2offset 8122 TmpInst.addOperand(MCOperand::createImm(4)); 8123 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 8124 TmpInst.addOperand(Inst.getOperand(3)); 8125 Inst = TmpInst; 8126 return true; 8127 } 8128 break; 8129 case ARM::STMDB_UPD: 8130 // If this is a store of a single register via a 'push', then we should use 8131 // a pre-indexed STR instruction instead, per the ARM ARM. 8132 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" && 8133 Inst.getNumOperands() == 5) { 8134 MCInst TmpInst; 8135 TmpInst.setOpcode(ARM::STR_PRE_IMM); 8136 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb 8137 TmpInst.addOperand(Inst.getOperand(4)); // Rt 8138 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12 8139 TmpInst.addOperand(MCOperand::createImm(-4)); 8140 TmpInst.addOperand(Inst.getOperand(2)); // CondCode 8141 TmpInst.addOperand(Inst.getOperand(3)); 8142 Inst = TmpInst; 8143 } 8144 break; 8145 case ARM::t2ADDri12: 8146 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add" 8147 // mnemonic was used (not "addw"), encoding T3 is preferred. 8148 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" || 8149 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) 8150 break; 8151 Inst.setOpcode(ARM::t2ADDri); 8152 Inst.addOperand(MCOperand::createReg(0)); // cc_out 8153 break; 8154 case ARM::t2SUBri12: 8155 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub" 8156 // mnemonic was used (not "subw"), encoding T3 is preferred. 8157 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" || 8158 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) 8159 break; 8160 Inst.setOpcode(ARM::t2SUBri); 8161 Inst.addOperand(MCOperand::createReg(0)); // cc_out 8162 break; 8163 case ARM::tADDi8: 8164 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was 8165 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred 8166 // to encoding T2 if <Rd> is specified and encoding T2 is preferred 8167 // to encoding T1 if <Rd> is omitted." 8168 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { 8169 Inst.setOpcode(ARM::tADDi3); 8170 return true; 8171 } 8172 break; 8173 case ARM::tSUBi8: 8174 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was 8175 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred 8176 // to encoding T2 if <Rd> is specified and encoding T2 is preferred 8177 // to encoding T1 if <Rd> is omitted." 8178 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { 8179 Inst.setOpcode(ARM::tSUBi3); 8180 return true; 8181 } 8182 break; 8183 case ARM::t2ADDri: 8184 case ARM::t2SUBri: { 8185 // If the destination and first source operand are the same, and 8186 // the flags are compatible with the current IT status, use encoding T2 8187 // instead of T3. For compatibility with the system 'as'. Make sure the 8188 // wide encoding wasn't explicit. 8189 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || 8190 !isARMLowRegister(Inst.getOperand(0).getReg()) || 8191 (unsigned)Inst.getOperand(2).getImm() > 255 || 8192 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) || 8193 (inITBlock() && Inst.getOperand(5).getReg() != 0)) || 8194 (static_cast<ARMOperand &>(*Operands[3]).isToken() && 8195 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) 8196 break; 8197 MCInst TmpInst; 8198 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ? 8199 ARM::tADDi8 : ARM::tSUBi8); 8200 TmpInst.addOperand(Inst.getOperand(0)); 8201 TmpInst.addOperand(Inst.getOperand(5)); 8202 TmpInst.addOperand(Inst.getOperand(0)); 8203 TmpInst.addOperand(Inst.getOperand(2)); 8204 TmpInst.addOperand(Inst.getOperand(3)); 8205 TmpInst.addOperand(Inst.getOperand(4)); 8206 Inst = TmpInst; 8207 return true; 8208 } 8209 case ARM::t2ADDrr: { 8210 // If the destination and first source operand are the same, and 8211 // there's no setting of the flags, use encoding T2 instead of T3. 8212 // Note that this is only for ADD, not SUB. This mirrors the system 8213 // 'as' behaviour. Also take advantage of ADD being commutative. 8214 // Make sure the wide encoding wasn't explicit. 8215 bool Swap = false; 8216 auto DestReg = Inst.getOperand(0).getReg(); 8217 bool Transform = DestReg == Inst.getOperand(1).getReg(); 8218 if (!Transform && DestReg == Inst.getOperand(2).getReg()) { 8219 Transform = true; 8220 Swap = true; 8221 } 8222 if (!Transform || 8223 Inst.getOperand(5).getReg() != 0 || 8224 (static_cast<ARMOperand &>(*Operands[3]).isToken() && 8225 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) 8226 break; 8227 MCInst TmpInst; 8228 TmpInst.setOpcode(ARM::tADDhirr); 8229 TmpInst.addOperand(Inst.getOperand(0)); 8230 TmpInst.addOperand(Inst.getOperand(0)); 8231 TmpInst.addOperand(Inst.getOperand(Swap ? 1 : 2)); 8232 TmpInst.addOperand(Inst.getOperand(3)); 8233 TmpInst.addOperand(Inst.getOperand(4)); 8234 Inst = TmpInst; 8235 return true; 8236 } 8237 case ARM::tADDrSP: { 8238 // If the non-SP source operand and the destination operand are not the 8239 // same, we need to use the 32-bit encoding if it's available. 8240 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { 8241 Inst.setOpcode(ARM::t2ADDrr); 8242 Inst.addOperand(MCOperand::createReg(0)); // cc_out 8243 return true; 8244 } 8245 break; 8246 } 8247 case ARM::tB: 8248 // A Thumb conditional branch outside of an IT block is a tBcc. 8249 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) { 8250 Inst.setOpcode(ARM::tBcc); 8251 return true; 8252 } 8253 break; 8254 case ARM::t2B: 8255 // A Thumb2 conditional branch outside of an IT block is a t2Bcc. 8256 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){ 8257 Inst.setOpcode(ARM::t2Bcc); 8258 return true; 8259 } 8260 break; 8261 case ARM::t2Bcc: 8262 // If the conditional is AL or we're in an IT block, we really want t2B. 8263 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) { 8264 Inst.setOpcode(ARM::t2B); 8265 return true; 8266 } 8267 break; 8268 case ARM::tBcc: 8269 // If the conditional is AL, we really want tB. 8270 if (Inst.getOperand(1).getImm() == ARMCC::AL) { 8271 Inst.setOpcode(ARM::tB); 8272 return true; 8273 } 8274 break; 8275 case ARM::tLDMIA: { 8276 // If the register list contains any high registers, or if the writeback 8277 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding 8278 // instead if we're in Thumb2. Otherwise, this should have generated 8279 // an error in validateInstruction(). 8280 unsigned Rn = Inst.getOperand(0).getReg(); 8281 bool hasWritebackToken = 8282 (static_cast<ARMOperand &>(*Operands[3]).isToken() && 8283 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); 8284 bool listContainsBase; 8285 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) || 8286 (!listContainsBase && !hasWritebackToken) || 8287 (listContainsBase && hasWritebackToken)) { 8288 // 16-bit encoding isn't sufficient. Switch to the 32-bit version. 8289 assert (isThumbTwo()); 8290 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA); 8291 // If we're switching to the updating version, we need to insert 8292 // the writeback tied operand. 8293 if (hasWritebackToken) 8294 Inst.insert(Inst.begin(), 8295 MCOperand::createReg(Inst.getOperand(0).getReg())); 8296 return true; 8297 } 8298 break; 8299 } 8300 case ARM::tSTMIA_UPD: { 8301 // If the register list contains any high registers, we need to use 8302 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this 8303 // should have generated an error in validateInstruction(). 8304 unsigned Rn = Inst.getOperand(0).getReg(); 8305 bool listContainsBase; 8306 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) { 8307 // 16-bit encoding isn't sufficient. Switch to the 32-bit version. 8308 assert (isThumbTwo()); 8309 Inst.setOpcode(ARM::t2STMIA_UPD); 8310 return true; 8311 } 8312 break; 8313 } 8314 case ARM::tPOP: { 8315 bool listContainsBase; 8316 // If the register list contains any high registers, we need to use 8317 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this 8318 // should have generated an error in validateInstruction(). 8319 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase)) 8320 return false; 8321 assert (isThumbTwo()); 8322 Inst.setOpcode(ARM::t2LDMIA_UPD); 8323 // Add the base register and writeback operands. 8324 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 8325 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 8326 return true; 8327 } 8328 case ARM::tPUSH: { 8329 bool listContainsBase; 8330 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase)) 8331 return false; 8332 assert (isThumbTwo()); 8333 Inst.setOpcode(ARM::t2STMDB_UPD); 8334 // Add the base register and writeback operands. 8335 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 8336 Inst.insert(Inst.begin(), MCOperand::createReg(ARM::SP)); 8337 return true; 8338 } 8339 case ARM::t2MOVi: { 8340 // If we can use the 16-bit encoding and the user didn't explicitly 8341 // request the 32-bit variant, transform it here. 8342 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 8343 (unsigned)Inst.getOperand(1).getImm() <= 255 && 8344 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL && 8345 Inst.getOperand(4).getReg() == ARM::CPSR) || 8346 (inITBlock() && Inst.getOperand(4).getReg() == 0)) && 8347 (!static_cast<ARMOperand &>(*Operands[2]).isToken() || 8348 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { 8349 // The operands aren't in the same order for tMOVi8... 8350 MCInst TmpInst; 8351 TmpInst.setOpcode(ARM::tMOVi8); 8352 TmpInst.addOperand(Inst.getOperand(0)); 8353 TmpInst.addOperand(Inst.getOperand(4)); 8354 TmpInst.addOperand(Inst.getOperand(1)); 8355 TmpInst.addOperand(Inst.getOperand(2)); 8356 TmpInst.addOperand(Inst.getOperand(3)); 8357 Inst = TmpInst; 8358 return true; 8359 } 8360 break; 8361 } 8362 case ARM::t2MOVr: { 8363 // If we can use the 16-bit encoding and the user didn't explicitly 8364 // request the 32-bit variant, transform it here. 8365 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 8366 isARMLowRegister(Inst.getOperand(1).getReg()) && 8367 Inst.getOperand(2).getImm() == ARMCC::AL && 8368 Inst.getOperand(4).getReg() == ARM::CPSR && 8369 (!static_cast<ARMOperand &>(*Operands[2]).isToken() || 8370 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { 8371 // The operands aren't the same for tMOV[S]r... (no cc_out) 8372 MCInst TmpInst; 8373 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr); 8374 TmpInst.addOperand(Inst.getOperand(0)); 8375 TmpInst.addOperand(Inst.getOperand(1)); 8376 TmpInst.addOperand(Inst.getOperand(2)); 8377 TmpInst.addOperand(Inst.getOperand(3)); 8378 Inst = TmpInst; 8379 return true; 8380 } 8381 break; 8382 } 8383 case ARM::t2SXTH: 8384 case ARM::t2SXTB: 8385 case ARM::t2UXTH: 8386 case ARM::t2UXTB: { 8387 // If we can use the 16-bit encoding and the user didn't explicitly 8388 // request the 32-bit variant, transform it here. 8389 if (isARMLowRegister(Inst.getOperand(0).getReg()) && 8390 isARMLowRegister(Inst.getOperand(1).getReg()) && 8391 Inst.getOperand(2).getImm() == 0 && 8392 (!static_cast<ARMOperand &>(*Operands[2]).isToken() || 8393 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { 8394 unsigned NewOpc; 8395 switch (Inst.getOpcode()) { 8396 default: llvm_unreachable("Illegal opcode!"); 8397 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break; 8398 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break; 8399 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break; 8400 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break; 8401 } 8402 // The operands aren't the same for thumb1 (no rotate operand). 8403 MCInst TmpInst; 8404 TmpInst.setOpcode(NewOpc); 8405 TmpInst.addOperand(Inst.getOperand(0)); 8406 TmpInst.addOperand(Inst.getOperand(1)); 8407 TmpInst.addOperand(Inst.getOperand(3)); 8408 TmpInst.addOperand(Inst.getOperand(4)); 8409 Inst = TmpInst; 8410 return true; 8411 } 8412 break; 8413 } 8414 case ARM::MOVsi: { 8415 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm()); 8416 // rrx shifts and asr/lsr of #32 is encoded as 0 8417 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr) 8418 return false; 8419 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) { 8420 // Shifting by zero is accepted as a vanilla 'MOVr' 8421 MCInst TmpInst; 8422 TmpInst.setOpcode(ARM::MOVr); 8423 TmpInst.addOperand(Inst.getOperand(0)); 8424 TmpInst.addOperand(Inst.getOperand(1)); 8425 TmpInst.addOperand(Inst.getOperand(3)); 8426 TmpInst.addOperand(Inst.getOperand(4)); 8427 TmpInst.addOperand(Inst.getOperand(5)); 8428 Inst = TmpInst; 8429 return true; 8430 } 8431 return false; 8432 } 8433 case ARM::ANDrsi: 8434 case ARM::ORRrsi: 8435 case ARM::EORrsi: 8436 case ARM::BICrsi: 8437 case ARM::SUBrsi: 8438 case ARM::ADDrsi: { 8439 unsigned newOpc; 8440 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm()); 8441 if (SOpc == ARM_AM::rrx) return false; 8442 switch (Inst.getOpcode()) { 8443 default: llvm_unreachable("unexpected opcode!"); 8444 case ARM::ANDrsi: newOpc = ARM::ANDrr; break; 8445 case ARM::ORRrsi: newOpc = ARM::ORRrr; break; 8446 case ARM::EORrsi: newOpc = ARM::EORrr; break; 8447 case ARM::BICrsi: newOpc = ARM::BICrr; break; 8448 case ARM::SUBrsi: newOpc = ARM::SUBrr; break; 8449 case ARM::ADDrsi: newOpc = ARM::ADDrr; break; 8450 } 8451 // If the shift is by zero, use the non-shifted instruction definition. 8452 // The exception is for right shifts, where 0 == 32 8453 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 && 8454 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) { 8455 MCInst TmpInst; 8456 TmpInst.setOpcode(newOpc); 8457 TmpInst.addOperand(Inst.getOperand(0)); 8458 TmpInst.addOperand(Inst.getOperand(1)); 8459 TmpInst.addOperand(Inst.getOperand(2)); 8460 TmpInst.addOperand(Inst.getOperand(4)); 8461 TmpInst.addOperand(Inst.getOperand(5)); 8462 TmpInst.addOperand(Inst.getOperand(6)); 8463 Inst = TmpInst; 8464 return true; 8465 } 8466 return false; 8467 } 8468 case ARM::ITasm: 8469 case ARM::t2IT: { 8470 // The mask bits for all but the first condition are represented as 8471 // the low bit of the condition code value implies 't'. We currently 8472 // always have 1 implies 't', so XOR toggle the bits if the low bit 8473 // of the condition code is zero. 8474 MCOperand &MO = Inst.getOperand(1); 8475 unsigned Mask = MO.getImm(); 8476 unsigned OrigMask = Mask; 8477 unsigned TZ = countTrailingZeros(Mask); 8478 if ((Inst.getOperand(0).getImm() & 1) == 0) { 8479 assert(Mask && TZ <= 3 && "illegal IT mask value!"); 8480 Mask ^= (0xE << TZ) & 0xF; 8481 } 8482 MO.setImm(Mask); 8483 8484 // Set up the IT block state according to the IT instruction we just 8485 // matched. 8486 assert(!inITBlock() && "nested IT blocks?!"); 8487 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm()); 8488 ITState.Mask = OrigMask; // Use the original mask, not the updated one. 8489 ITState.CurPosition = 0; 8490 ITState.FirstCond = true; 8491 break; 8492 } 8493 case ARM::t2LSLrr: 8494 case ARM::t2LSRrr: 8495 case ARM::t2ASRrr: 8496 case ARM::t2SBCrr: 8497 case ARM::t2RORrr: 8498 case ARM::t2BICrr: 8499 { 8500 // Assemblers should use the narrow encodings of these instructions when permissible. 8501 if ((isARMLowRegister(Inst.getOperand(1).getReg()) && 8502 isARMLowRegister(Inst.getOperand(2).getReg())) && 8503 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && 8504 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || 8505 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && 8506 (!static_cast<ARMOperand &>(*Operands[3]).isToken() || 8507 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( 8508 ".w"))) { 8509 unsigned NewOpc; 8510 switch (Inst.getOpcode()) { 8511 default: llvm_unreachable("unexpected opcode"); 8512 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break; 8513 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break; 8514 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break; 8515 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break; 8516 case ARM::t2RORrr: NewOpc = ARM::tROR; break; 8517 case ARM::t2BICrr: NewOpc = ARM::tBIC; break; 8518 } 8519 MCInst TmpInst; 8520 TmpInst.setOpcode(NewOpc); 8521 TmpInst.addOperand(Inst.getOperand(0)); 8522 TmpInst.addOperand(Inst.getOperand(5)); 8523 TmpInst.addOperand(Inst.getOperand(1)); 8524 TmpInst.addOperand(Inst.getOperand(2)); 8525 TmpInst.addOperand(Inst.getOperand(3)); 8526 TmpInst.addOperand(Inst.getOperand(4)); 8527 Inst = TmpInst; 8528 return true; 8529 } 8530 return false; 8531 } 8532 case ARM::t2ANDrr: 8533 case ARM::t2EORrr: 8534 case ARM::t2ADCrr: 8535 case ARM::t2ORRrr: 8536 { 8537 // Assemblers should use the narrow encodings of these instructions when permissible. 8538 // These instructions are special in that they are commutable, so shorter encodings 8539 // are available more often. 8540 if ((isARMLowRegister(Inst.getOperand(1).getReg()) && 8541 isARMLowRegister(Inst.getOperand(2).getReg())) && 8542 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() || 8543 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) && 8544 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || 8545 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && 8546 (!static_cast<ARMOperand &>(*Operands[3]).isToken() || 8547 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( 8548 ".w"))) { 8549 unsigned NewOpc; 8550 switch (Inst.getOpcode()) { 8551 default: llvm_unreachable("unexpected opcode"); 8552 case ARM::t2ADCrr: NewOpc = ARM::tADC; break; 8553 case ARM::t2ANDrr: NewOpc = ARM::tAND; break; 8554 case ARM::t2EORrr: NewOpc = ARM::tEOR; break; 8555 case ARM::t2ORRrr: NewOpc = ARM::tORR; break; 8556 } 8557 MCInst TmpInst; 8558 TmpInst.setOpcode(NewOpc); 8559 TmpInst.addOperand(Inst.getOperand(0)); 8560 TmpInst.addOperand(Inst.getOperand(5)); 8561 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) { 8562 TmpInst.addOperand(Inst.getOperand(1)); 8563 TmpInst.addOperand(Inst.getOperand(2)); 8564 } else { 8565 TmpInst.addOperand(Inst.getOperand(2)); 8566 TmpInst.addOperand(Inst.getOperand(1)); 8567 } 8568 TmpInst.addOperand(Inst.getOperand(3)); 8569 TmpInst.addOperand(Inst.getOperand(4)); 8570 Inst = TmpInst; 8571 return true; 8572 } 8573 return false; 8574 } 8575 } 8576 return false; 8577 } 8578 8579 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) { 8580 // 16-bit thumb arithmetic instructions either require or preclude the 'S' 8581 // suffix depending on whether they're in an IT block or not. 8582 unsigned Opc = Inst.getOpcode(); 8583 const MCInstrDesc &MCID = MII.get(Opc); 8584 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) { 8585 assert(MCID.hasOptionalDef() && 8586 "optionally flag setting instruction missing optional def operand"); 8587 assert(MCID.NumOperands == Inst.getNumOperands() && 8588 "operand count mismatch!"); 8589 // Find the optional-def operand (cc_out). 8590 unsigned OpNo; 8591 for (OpNo = 0; 8592 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands; 8593 ++OpNo) 8594 ; 8595 // If we're parsing Thumb1, reject it completely. 8596 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR) 8597 return Match_MnemonicFail; 8598 // If we're parsing Thumb2, which form is legal depends on whether we're 8599 // in an IT block. 8600 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR && 8601 !inITBlock()) 8602 return Match_RequiresITBlock; 8603 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR && 8604 inITBlock()) 8605 return Match_RequiresNotITBlock; 8606 } else if (isThumbOne()) { 8607 // Some high-register supporting Thumb1 encodings only allow both registers 8608 // to be from r0-r7 when in Thumb2. 8609 if (Opc == ARM::tADDhirr && !hasV6MOps() && 8610 isARMLowRegister(Inst.getOperand(1).getReg()) && 8611 isARMLowRegister(Inst.getOperand(2).getReg())) 8612 return Match_RequiresThumb2; 8613 // Others only require ARMv6 or later. 8614 else if (Opc == ARM::tMOVr && !hasV6Ops() && 8615 isARMLowRegister(Inst.getOperand(0).getReg()) && 8616 isARMLowRegister(Inst.getOperand(1).getReg())) 8617 return Match_RequiresV6; 8618 } 8619 8620 for (unsigned I = 0; I < MCID.NumOperands; ++I) 8621 if (MCID.OpInfo[I].RegClass == ARM::rGPRRegClassID) { 8622 // rGPRRegClass excludes PC, and also excluded SP before ARMv8 8623 if ((Inst.getOperand(I).getReg() == ARM::SP) && !hasV8Ops()) 8624 return Match_RequiresV8; 8625 else if (Inst.getOperand(I).getReg() == ARM::PC) 8626 return Match_InvalidOperand; 8627 } 8628 8629 return Match_Success; 8630 } 8631 8632 namespace llvm { 8633 template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) { 8634 return true; // In an assembly source, no need to second-guess 8635 } 8636 } 8637 8638 static const char *getSubtargetFeatureName(uint64_t Val); 8639 bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, 8640 OperandVector &Operands, 8641 MCStreamer &Out, uint64_t &ErrorInfo, 8642 bool MatchingInlineAsm) { 8643 MCInst Inst; 8644 unsigned MatchResult; 8645 8646 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo, 8647 MatchingInlineAsm); 8648 switch (MatchResult) { 8649 case Match_Success: 8650 // Context sensitive operand constraints aren't handled by the matcher, 8651 // so check them here. 8652 if (validateInstruction(Inst, Operands)) { 8653 // Still progress the IT block, otherwise one wrong condition causes 8654 // nasty cascading errors. 8655 forwardITPosition(); 8656 return true; 8657 } 8658 8659 { // processInstruction() updates inITBlock state, we need to save it away 8660 bool wasInITBlock = inITBlock(); 8661 8662 // Some instructions need post-processing to, for example, tweak which 8663 // encoding is selected. Loop on it while changes happen so the 8664 // individual transformations can chain off each other. E.g., 8665 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8) 8666 while (processInstruction(Inst, Operands, Out)) 8667 ; 8668 8669 // Only after the instruction is fully processed, we can validate it 8670 if (wasInITBlock && hasV8Ops() && isThumb() && 8671 !isV8EligibleForIT(&Inst)) { 8672 Warning(IDLoc, "deprecated instruction in IT block"); 8673 } 8674 } 8675 8676 // Only move forward at the very end so that everything in validate 8677 // and process gets a consistent answer about whether we're in an IT 8678 // block. 8679 forwardITPosition(); 8680 8681 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and 8682 // doesn't actually encode. 8683 if (Inst.getOpcode() == ARM::ITasm) 8684 return false; 8685 8686 Inst.setLoc(IDLoc); 8687 Out.EmitInstruction(Inst, getSTI()); 8688 return false; 8689 case Match_MissingFeature: { 8690 assert(ErrorInfo && "Unknown missing feature!"); 8691 // Special case the error message for the very common case where only 8692 // a single subtarget feature is missing (Thumb vs. ARM, e.g.). 8693 std::string Msg = "instruction requires:"; 8694 uint64_t Mask = 1; 8695 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) { 8696 if (ErrorInfo & Mask) { 8697 Msg += " "; 8698 Msg += getSubtargetFeatureName(ErrorInfo & Mask); 8699 } 8700 Mask <<= 1; 8701 } 8702 return Error(IDLoc, Msg); 8703 } 8704 case Match_InvalidOperand: { 8705 SMLoc ErrorLoc = IDLoc; 8706 if (ErrorInfo != ~0ULL) { 8707 if (ErrorInfo >= Operands.size()) 8708 return Error(IDLoc, "too few operands for instruction"); 8709 8710 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); 8711 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; 8712 } 8713 8714 return Error(ErrorLoc, "invalid operand for instruction"); 8715 } 8716 case Match_MnemonicFail: 8717 return Error(IDLoc, "invalid instruction", 8718 ((ARMOperand &)*Operands[0]).getLocRange()); 8719 case Match_RequiresNotITBlock: 8720 return Error(IDLoc, "flag setting instruction only valid outside IT block"); 8721 case Match_RequiresITBlock: 8722 return Error(IDLoc, "instruction only valid inside IT block"); 8723 case Match_RequiresV6: 8724 return Error(IDLoc, "instruction variant requires ARMv6 or later"); 8725 case Match_RequiresThumb2: 8726 return Error(IDLoc, "instruction variant requires Thumb2"); 8727 case Match_RequiresV8: 8728 return Error(IDLoc, "instruction variant requires ARMv8 or later"); 8729 case Match_ImmRange0_15: { 8730 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); 8731 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; 8732 return Error(ErrorLoc, "immediate operand must be in the range [0,15]"); 8733 } 8734 case Match_ImmRange0_239: { 8735 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); 8736 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; 8737 return Error(ErrorLoc, "immediate operand must be in the range [0,239]"); 8738 } 8739 case Match_AlignedMemoryRequiresNone: 8740 case Match_DupAlignedMemoryRequiresNone: 8741 case Match_AlignedMemoryRequires16: 8742 case Match_DupAlignedMemoryRequires16: 8743 case Match_AlignedMemoryRequires32: 8744 case Match_DupAlignedMemoryRequires32: 8745 case Match_AlignedMemoryRequires64: 8746 case Match_DupAlignedMemoryRequires64: 8747 case Match_AlignedMemoryRequires64or128: 8748 case Match_DupAlignedMemoryRequires64or128: 8749 case Match_AlignedMemoryRequires64or128or256: 8750 { 8751 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc(); 8752 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; 8753 switch (MatchResult) { 8754 default: 8755 llvm_unreachable("Missing Match_Aligned type"); 8756 case Match_AlignedMemoryRequiresNone: 8757 case Match_DupAlignedMemoryRequiresNone: 8758 return Error(ErrorLoc, "alignment must be omitted"); 8759 case Match_AlignedMemoryRequires16: 8760 case Match_DupAlignedMemoryRequires16: 8761 return Error(ErrorLoc, "alignment must be 16 or omitted"); 8762 case Match_AlignedMemoryRequires32: 8763 case Match_DupAlignedMemoryRequires32: 8764 return Error(ErrorLoc, "alignment must be 32 or omitted"); 8765 case Match_AlignedMemoryRequires64: 8766 case Match_DupAlignedMemoryRequires64: 8767 return Error(ErrorLoc, "alignment must be 64 or omitted"); 8768 case Match_AlignedMemoryRequires64or128: 8769 case Match_DupAlignedMemoryRequires64or128: 8770 return Error(ErrorLoc, "alignment must be 64, 128 or omitted"); 8771 case Match_AlignedMemoryRequires64or128or256: 8772 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted"); 8773 } 8774 } 8775 } 8776 8777 llvm_unreachable("Implement any new match types added!"); 8778 } 8779 8780 /// parseDirective parses the arm specific directives 8781 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { 8782 const MCObjectFileInfo::Environment Format = 8783 getContext().getObjectFileInfo()->getObjectFileType(); 8784 bool IsMachO = Format == MCObjectFileInfo::IsMachO; 8785 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF; 8786 8787 StringRef IDVal = DirectiveID.getIdentifier(); 8788 if (IDVal == ".word") 8789 return parseLiteralValues(4, DirectiveID.getLoc()); 8790 else if (IDVal == ".short" || IDVal == ".hword") 8791 return parseLiteralValues(2, DirectiveID.getLoc()); 8792 else if (IDVal == ".thumb") 8793 return parseDirectiveThumb(DirectiveID.getLoc()); 8794 else if (IDVal == ".arm") 8795 return parseDirectiveARM(DirectiveID.getLoc()); 8796 else if (IDVal == ".thumb_func") 8797 return parseDirectiveThumbFunc(DirectiveID.getLoc()); 8798 else if (IDVal == ".code") 8799 return parseDirectiveCode(DirectiveID.getLoc()); 8800 else if (IDVal == ".syntax") 8801 return parseDirectiveSyntax(DirectiveID.getLoc()); 8802 else if (IDVal == ".unreq") 8803 return parseDirectiveUnreq(DirectiveID.getLoc()); 8804 else if (IDVal == ".fnend") 8805 return parseDirectiveFnEnd(DirectiveID.getLoc()); 8806 else if (IDVal == ".cantunwind") 8807 return parseDirectiveCantUnwind(DirectiveID.getLoc()); 8808 else if (IDVal == ".personality") 8809 return parseDirectivePersonality(DirectiveID.getLoc()); 8810 else if (IDVal == ".handlerdata") 8811 return parseDirectiveHandlerData(DirectiveID.getLoc()); 8812 else if (IDVal == ".setfp") 8813 return parseDirectiveSetFP(DirectiveID.getLoc()); 8814 else if (IDVal == ".pad") 8815 return parseDirectivePad(DirectiveID.getLoc()); 8816 else if (IDVal == ".save") 8817 return parseDirectiveRegSave(DirectiveID.getLoc(), false); 8818 else if (IDVal == ".vsave") 8819 return parseDirectiveRegSave(DirectiveID.getLoc(), true); 8820 else if (IDVal == ".ltorg" || IDVal == ".pool") 8821 return parseDirectiveLtorg(DirectiveID.getLoc()); 8822 else if (IDVal == ".even") 8823 return parseDirectiveEven(DirectiveID.getLoc()); 8824 else if (IDVal == ".personalityindex") 8825 return parseDirectivePersonalityIndex(DirectiveID.getLoc()); 8826 else if (IDVal == ".unwind_raw") 8827 return parseDirectiveUnwindRaw(DirectiveID.getLoc()); 8828 else if (IDVal == ".movsp") 8829 return parseDirectiveMovSP(DirectiveID.getLoc()); 8830 else if (IDVal == ".arch_extension") 8831 return parseDirectiveArchExtension(DirectiveID.getLoc()); 8832 else if (IDVal == ".align") 8833 return parseDirectiveAlign(DirectiveID.getLoc()); 8834 else if (IDVal == ".thumb_set") 8835 return parseDirectiveThumbSet(DirectiveID.getLoc()); 8836 8837 if (!IsMachO && !IsCOFF) { 8838 if (IDVal == ".arch") 8839 return parseDirectiveArch(DirectiveID.getLoc()); 8840 else if (IDVal == ".cpu") 8841 return parseDirectiveCPU(DirectiveID.getLoc()); 8842 else if (IDVal == ".eabi_attribute") 8843 return parseDirectiveEabiAttr(DirectiveID.getLoc()); 8844 else if (IDVal == ".fpu") 8845 return parseDirectiveFPU(DirectiveID.getLoc()); 8846 else if (IDVal == ".fnstart") 8847 return parseDirectiveFnStart(DirectiveID.getLoc()); 8848 else if (IDVal == ".inst") 8849 return parseDirectiveInst(DirectiveID.getLoc()); 8850 else if (IDVal == ".inst.n") 8851 return parseDirectiveInst(DirectiveID.getLoc(), 'n'); 8852 else if (IDVal == ".inst.w") 8853 return parseDirectiveInst(DirectiveID.getLoc(), 'w'); 8854 else if (IDVal == ".object_arch") 8855 return parseDirectiveObjectArch(DirectiveID.getLoc()); 8856 else if (IDVal == ".tlsdescseq") 8857 return parseDirectiveTLSDescSeq(DirectiveID.getLoc()); 8858 } 8859 8860 return true; 8861 } 8862 8863 /// parseLiteralValues 8864 /// ::= .hword expression [, expression]* 8865 /// ::= .short expression [, expression]* 8866 /// ::= .word expression [, expression]* 8867 bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) { 8868 MCAsmParser &Parser = getParser(); 8869 if (getLexer().isNot(AsmToken::EndOfStatement)) { 8870 for (;;) { 8871 const MCExpr *Value; 8872 if (getParser().parseExpression(Value)) { 8873 Parser.eatToEndOfStatement(); 8874 return false; 8875 } 8876 8877 getParser().getStreamer().EmitValue(Value, Size, L); 8878 8879 if (getLexer().is(AsmToken::EndOfStatement)) 8880 break; 8881 8882 // FIXME: Improve diagnostic. 8883 if (getLexer().isNot(AsmToken::Comma)) { 8884 Error(L, "unexpected token in directive"); 8885 return false; 8886 } 8887 Parser.Lex(); 8888 } 8889 } 8890 8891 Parser.Lex(); 8892 return false; 8893 } 8894 8895 /// parseDirectiveThumb 8896 /// ::= .thumb 8897 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) { 8898 MCAsmParser &Parser = getParser(); 8899 if (getLexer().isNot(AsmToken::EndOfStatement)) { 8900 Error(L, "unexpected token in directive"); 8901 return false; 8902 } 8903 Parser.Lex(); 8904 8905 if (!hasThumb()) { 8906 Error(L, "target does not support Thumb mode"); 8907 return false; 8908 } 8909 8910 if (!isThumb()) 8911 SwitchMode(); 8912 8913 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); 8914 return false; 8915 } 8916 8917 /// parseDirectiveARM 8918 /// ::= .arm 8919 bool ARMAsmParser::parseDirectiveARM(SMLoc L) { 8920 MCAsmParser &Parser = getParser(); 8921 if (getLexer().isNot(AsmToken::EndOfStatement)) { 8922 Error(L, "unexpected token in directive"); 8923 return false; 8924 } 8925 Parser.Lex(); 8926 8927 if (!hasARM()) { 8928 Error(L, "target does not support ARM mode"); 8929 return false; 8930 } 8931 8932 if (isThumb()) 8933 SwitchMode(); 8934 8935 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); 8936 return false; 8937 } 8938 8939 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) { 8940 if (NextSymbolIsThumb) { 8941 getParser().getStreamer().EmitThumbFunc(Symbol); 8942 NextSymbolIsThumb = false; 8943 } 8944 } 8945 8946 /// parseDirectiveThumbFunc 8947 /// ::= .thumbfunc symbol_name 8948 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) { 8949 MCAsmParser &Parser = getParser(); 8950 const auto Format = getContext().getObjectFileInfo()->getObjectFileType(); 8951 bool IsMachO = Format == MCObjectFileInfo::IsMachO; 8952 8953 // Darwin asm has (optionally) function name after .thumb_func direction 8954 // ELF doesn't 8955 if (IsMachO) { 8956 const AsmToken &Tok = Parser.getTok(); 8957 if (Tok.isNot(AsmToken::EndOfStatement)) { 8958 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) { 8959 Error(L, "unexpected token in .thumb_func directive"); 8960 return false; 8961 } 8962 8963 MCSymbol *Func = 8964 getParser().getContext().getOrCreateSymbol(Tok.getIdentifier()); 8965 getParser().getStreamer().EmitThumbFunc(Func); 8966 Parser.Lex(); // Consume the identifier token. 8967 return false; 8968 } 8969 } 8970 8971 if (getLexer().isNot(AsmToken::EndOfStatement)) { 8972 Error(Parser.getTok().getLoc(), "unexpected token in directive"); 8973 Parser.eatToEndOfStatement(); 8974 return false; 8975 } 8976 8977 NextSymbolIsThumb = true; 8978 return false; 8979 } 8980 8981 /// parseDirectiveSyntax 8982 /// ::= .syntax unified | divided 8983 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) { 8984 MCAsmParser &Parser = getParser(); 8985 const AsmToken &Tok = Parser.getTok(); 8986 if (Tok.isNot(AsmToken::Identifier)) { 8987 Error(L, "unexpected token in .syntax directive"); 8988 return false; 8989 } 8990 8991 StringRef Mode = Tok.getString(); 8992 if (Mode == "unified" || Mode == "UNIFIED") { 8993 Parser.Lex(); 8994 } else if (Mode == "divided" || Mode == "DIVIDED") { 8995 Error(L, "'.syntax divided' arm asssembly not supported"); 8996 return false; 8997 } else { 8998 Error(L, "unrecognized syntax mode in .syntax directive"); 8999 return false; 9000 } 9001 9002 if (getLexer().isNot(AsmToken::EndOfStatement)) { 9003 Error(Parser.getTok().getLoc(), "unexpected token in directive"); 9004 return false; 9005 } 9006 Parser.Lex(); 9007 9008 // TODO tell the MC streamer the mode 9009 // getParser().getStreamer().Emit???(); 9010 return false; 9011 } 9012 9013 /// parseDirectiveCode 9014 /// ::= .code 16 | 32 9015 bool ARMAsmParser::parseDirectiveCode(SMLoc L) { 9016 MCAsmParser &Parser = getParser(); 9017 const AsmToken &Tok = Parser.getTok(); 9018 if (Tok.isNot(AsmToken::Integer)) { 9019 Error(L, "unexpected token in .code directive"); 9020 return false; 9021 } 9022 int64_t Val = Parser.getTok().getIntVal(); 9023 if (Val != 16 && Val != 32) { 9024 Error(L, "invalid operand to .code directive"); 9025 return false; 9026 } 9027 Parser.Lex(); 9028 9029 if (getLexer().isNot(AsmToken::EndOfStatement)) { 9030 Error(Parser.getTok().getLoc(), "unexpected token in directive"); 9031 return false; 9032 } 9033 Parser.Lex(); 9034 9035 if (Val == 16) { 9036 if (!hasThumb()) { 9037 Error(L, "target does not support Thumb mode"); 9038 return false; 9039 } 9040 9041 if (!isThumb()) 9042 SwitchMode(); 9043 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); 9044 } else { 9045 if (!hasARM()) { 9046 Error(L, "target does not support ARM mode"); 9047 return false; 9048 } 9049 9050 if (isThumb()) 9051 SwitchMode(); 9052 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); 9053 } 9054 9055 return false; 9056 } 9057 9058 /// parseDirectiveReq 9059 /// ::= name .req registername 9060 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) { 9061 MCAsmParser &Parser = getParser(); 9062 Parser.Lex(); // Eat the '.req' token. 9063 unsigned Reg; 9064 SMLoc SRegLoc, ERegLoc; 9065 if (ParseRegister(Reg, SRegLoc, ERegLoc)) { 9066 Parser.eatToEndOfStatement(); 9067 Error(SRegLoc, "register name expected"); 9068 return false; 9069 } 9070 9071 // Shouldn't be anything else. 9072 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { 9073 Parser.eatToEndOfStatement(); 9074 Error(Parser.getTok().getLoc(), "unexpected input in .req directive."); 9075 return false; 9076 } 9077 9078 Parser.Lex(); // Consume the EndOfStatement 9079 9080 if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg) { 9081 Error(SRegLoc, "redefinition of '" + Name + "' does not match original."); 9082 return false; 9083 } 9084 9085 return false; 9086 } 9087 9088 /// parseDirectiveUneq 9089 /// ::= .unreq registername 9090 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) { 9091 MCAsmParser &Parser = getParser(); 9092 if (Parser.getTok().isNot(AsmToken::Identifier)) { 9093 Parser.eatToEndOfStatement(); 9094 Error(L, "unexpected input in .unreq directive."); 9095 return false; 9096 } 9097 RegisterReqs.erase(Parser.getTok().getIdentifier().lower()); 9098 Parser.Lex(); // Eat the identifier. 9099 return false; 9100 } 9101 9102 /// parseDirectiveArch 9103 /// ::= .arch token 9104 bool ARMAsmParser::parseDirectiveArch(SMLoc L) { 9105 StringRef Arch = getParser().parseStringToEndOfStatement().trim(); 9106 9107 unsigned ID = ARM::parseArch(Arch); 9108 9109 if (ID == ARM::AK_INVALID) { 9110 Error(L, "Unknown arch name"); 9111 return false; 9112 } 9113 9114 Triple T; 9115 MCSubtargetInfo &STI = copySTI(); 9116 STI.setDefaultFeatures("", ("+" + ARM::getArchName(ID)).str()); 9117 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 9118 9119 getTargetStreamer().emitArch(ID); 9120 return false; 9121 } 9122 9123 /// parseDirectiveEabiAttr 9124 /// ::= .eabi_attribute int, int [, "str"] 9125 /// ::= .eabi_attribute Tag_name, int [, "str"] 9126 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) { 9127 MCAsmParser &Parser = getParser(); 9128 int64_t Tag; 9129 SMLoc TagLoc; 9130 TagLoc = Parser.getTok().getLoc(); 9131 if (Parser.getTok().is(AsmToken::Identifier)) { 9132 StringRef Name = Parser.getTok().getIdentifier(); 9133 Tag = ARMBuildAttrs::AttrTypeFromString(Name); 9134 if (Tag == -1) { 9135 Error(TagLoc, "attribute name not recognised: " + Name); 9136 Parser.eatToEndOfStatement(); 9137 return false; 9138 } 9139 Parser.Lex(); 9140 } else { 9141 const MCExpr *AttrExpr; 9142 9143 TagLoc = Parser.getTok().getLoc(); 9144 if (Parser.parseExpression(AttrExpr)) { 9145 Parser.eatToEndOfStatement(); 9146 return false; 9147 } 9148 9149 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr); 9150 if (!CE) { 9151 Error(TagLoc, "expected numeric constant"); 9152 Parser.eatToEndOfStatement(); 9153 return false; 9154 } 9155 9156 Tag = CE->getValue(); 9157 } 9158 9159 if (Parser.getTok().isNot(AsmToken::Comma)) { 9160 Error(Parser.getTok().getLoc(), "comma expected"); 9161 Parser.eatToEndOfStatement(); 9162 return false; 9163 } 9164 Parser.Lex(); // skip comma 9165 9166 StringRef StringValue = ""; 9167 bool IsStringValue = false; 9168 9169 int64_t IntegerValue = 0; 9170 bool IsIntegerValue = false; 9171 9172 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name) 9173 IsStringValue = true; 9174 else if (Tag == ARMBuildAttrs::compatibility) { 9175 IsStringValue = true; 9176 IsIntegerValue = true; 9177 } else if (Tag < 32 || Tag % 2 == 0) 9178 IsIntegerValue = true; 9179 else if (Tag % 2 == 1) 9180 IsStringValue = true; 9181 else 9182 llvm_unreachable("invalid tag type"); 9183 9184 if (IsIntegerValue) { 9185 const MCExpr *ValueExpr; 9186 SMLoc ValueExprLoc = Parser.getTok().getLoc(); 9187 if (Parser.parseExpression(ValueExpr)) { 9188 Parser.eatToEndOfStatement(); 9189 return false; 9190 } 9191 9192 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr); 9193 if (!CE) { 9194 Error(ValueExprLoc, "expected numeric constant"); 9195 Parser.eatToEndOfStatement(); 9196 return false; 9197 } 9198 9199 IntegerValue = CE->getValue(); 9200 } 9201 9202 if (Tag == ARMBuildAttrs::compatibility) { 9203 if (Parser.getTok().isNot(AsmToken::Comma)) 9204 IsStringValue = false; 9205 if (Parser.getTok().isNot(AsmToken::Comma)) { 9206 Error(Parser.getTok().getLoc(), "comma expected"); 9207 Parser.eatToEndOfStatement(); 9208 return false; 9209 } else { 9210 Parser.Lex(); 9211 } 9212 } 9213 9214 if (IsStringValue) { 9215 if (Parser.getTok().isNot(AsmToken::String)) { 9216 Error(Parser.getTok().getLoc(), "bad string constant"); 9217 Parser.eatToEndOfStatement(); 9218 return false; 9219 } 9220 9221 StringValue = Parser.getTok().getStringContents(); 9222 Parser.Lex(); 9223 } 9224 9225 if (IsIntegerValue && IsStringValue) { 9226 assert(Tag == ARMBuildAttrs::compatibility); 9227 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue); 9228 } else if (IsIntegerValue) 9229 getTargetStreamer().emitAttribute(Tag, IntegerValue); 9230 else if (IsStringValue) 9231 getTargetStreamer().emitTextAttribute(Tag, StringValue); 9232 return false; 9233 } 9234 9235 /// parseDirectiveCPU 9236 /// ::= .cpu str 9237 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) { 9238 StringRef CPU = getParser().parseStringToEndOfStatement().trim(); 9239 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU); 9240 9241 // FIXME: This is using table-gen data, but should be moved to 9242 // ARMTargetParser once that is table-gen'd. 9243 if (!getSTI().isCPUStringValid(CPU)) { 9244 Error(L, "Unknown CPU name"); 9245 return false; 9246 } 9247 9248 MCSubtargetInfo &STI = copySTI(); 9249 STI.setDefaultFeatures(CPU, ""); 9250 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 9251 9252 return false; 9253 } 9254 /// parseDirectiveFPU 9255 /// ::= .fpu str 9256 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) { 9257 SMLoc FPUNameLoc = getTok().getLoc(); 9258 StringRef FPU = getParser().parseStringToEndOfStatement().trim(); 9259 9260 unsigned ID = ARM::parseFPU(FPU); 9261 std::vector<const char *> Features; 9262 if (!ARM::getFPUFeatures(ID, Features)) { 9263 Error(FPUNameLoc, "Unknown FPU name"); 9264 return false; 9265 } 9266 9267 MCSubtargetInfo &STI = copySTI(); 9268 for (auto Feature : Features) 9269 STI.ApplyFeatureFlag(Feature); 9270 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); 9271 9272 getTargetStreamer().emitFPU(ID); 9273 return false; 9274 } 9275 9276 /// parseDirectiveFnStart 9277 /// ::= .fnstart 9278 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) { 9279 if (UC.hasFnStart()) { 9280 Error(L, ".fnstart starts before the end of previous one"); 9281 UC.emitFnStartLocNotes(); 9282 return false; 9283 } 9284 9285 // Reset the unwind directives parser state 9286 UC.reset(); 9287 9288 getTargetStreamer().emitFnStart(); 9289 9290 UC.recordFnStart(L); 9291 return false; 9292 } 9293 9294 /// parseDirectiveFnEnd 9295 /// ::= .fnend 9296 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) { 9297 // Check the ordering of unwind directives 9298 if (!UC.hasFnStart()) { 9299 Error(L, ".fnstart must precede .fnend directive"); 9300 return false; 9301 } 9302 9303 // Reset the unwind directives parser state 9304 getTargetStreamer().emitFnEnd(); 9305 9306 UC.reset(); 9307 return false; 9308 } 9309 9310 /// parseDirectiveCantUnwind 9311 /// ::= .cantunwind 9312 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) { 9313 UC.recordCantUnwind(L); 9314 9315 // Check the ordering of unwind directives 9316 if (!UC.hasFnStart()) { 9317 Error(L, ".fnstart must precede .cantunwind directive"); 9318 return false; 9319 } 9320 if (UC.hasHandlerData()) { 9321 Error(L, ".cantunwind can't be used with .handlerdata directive"); 9322 UC.emitHandlerDataLocNotes(); 9323 return false; 9324 } 9325 if (UC.hasPersonality()) { 9326 Error(L, ".cantunwind can't be used with .personality directive"); 9327 UC.emitPersonalityLocNotes(); 9328 return false; 9329 } 9330 9331 getTargetStreamer().emitCantUnwind(); 9332 return false; 9333 } 9334 9335 /// parseDirectivePersonality 9336 /// ::= .personality name 9337 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) { 9338 MCAsmParser &Parser = getParser(); 9339 bool HasExistingPersonality = UC.hasPersonality(); 9340 9341 UC.recordPersonality(L); 9342 9343 // Check the ordering of unwind directives 9344 if (!UC.hasFnStart()) { 9345 Error(L, ".fnstart must precede .personality directive"); 9346 return false; 9347 } 9348 if (UC.cantUnwind()) { 9349 Error(L, ".personality can't be used with .cantunwind directive"); 9350 UC.emitCantUnwindLocNotes(); 9351 return false; 9352 } 9353 if (UC.hasHandlerData()) { 9354 Error(L, ".personality must precede .handlerdata directive"); 9355 UC.emitHandlerDataLocNotes(); 9356 return false; 9357 } 9358 if (HasExistingPersonality) { 9359 Parser.eatToEndOfStatement(); 9360 Error(L, "multiple personality directives"); 9361 UC.emitPersonalityLocNotes(); 9362 return false; 9363 } 9364 9365 // Parse the name of the personality routine 9366 if (Parser.getTok().isNot(AsmToken::Identifier)) { 9367 Parser.eatToEndOfStatement(); 9368 Error(L, "unexpected input in .personality directive."); 9369 return false; 9370 } 9371 StringRef Name(Parser.getTok().getIdentifier()); 9372 Parser.Lex(); 9373 9374 MCSymbol *PR = getParser().getContext().getOrCreateSymbol(Name); 9375 getTargetStreamer().emitPersonality(PR); 9376 return false; 9377 } 9378 9379 /// parseDirectiveHandlerData 9380 /// ::= .handlerdata 9381 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) { 9382 UC.recordHandlerData(L); 9383 9384 // Check the ordering of unwind directives 9385 if (!UC.hasFnStart()) { 9386 Error(L, ".fnstart must precede .personality directive"); 9387 return false; 9388 } 9389 if (UC.cantUnwind()) { 9390 Error(L, ".handlerdata can't be used with .cantunwind directive"); 9391 UC.emitCantUnwindLocNotes(); 9392 return false; 9393 } 9394 9395 getTargetStreamer().emitHandlerData(); 9396 return false; 9397 } 9398 9399 /// parseDirectiveSetFP 9400 /// ::= .setfp fpreg, spreg [, offset] 9401 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) { 9402 MCAsmParser &Parser = getParser(); 9403 // Check the ordering of unwind directives 9404 if (!UC.hasFnStart()) { 9405 Error(L, ".fnstart must precede .setfp directive"); 9406 return false; 9407 } 9408 if (UC.hasHandlerData()) { 9409 Error(L, ".setfp must precede .handlerdata directive"); 9410 return false; 9411 } 9412 9413 // Parse fpreg 9414 SMLoc FPRegLoc = Parser.getTok().getLoc(); 9415 int FPReg = tryParseRegister(); 9416 if (FPReg == -1) { 9417 Error(FPRegLoc, "frame pointer register expected"); 9418 return false; 9419 } 9420 9421 // Consume comma 9422 if (Parser.getTok().isNot(AsmToken::Comma)) { 9423 Error(Parser.getTok().getLoc(), "comma expected"); 9424 return false; 9425 } 9426 Parser.Lex(); // skip comma 9427 9428 // Parse spreg 9429 SMLoc SPRegLoc = Parser.getTok().getLoc(); 9430 int SPReg = tryParseRegister(); 9431 if (SPReg == -1) { 9432 Error(SPRegLoc, "stack pointer register expected"); 9433 return false; 9434 } 9435 9436 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) { 9437 Error(SPRegLoc, "register should be either $sp or the latest fp register"); 9438 return false; 9439 } 9440 9441 // Update the frame pointer register 9442 UC.saveFPReg(FPReg); 9443 9444 // Parse offset 9445 int64_t Offset = 0; 9446 if (Parser.getTok().is(AsmToken::Comma)) { 9447 Parser.Lex(); // skip comma 9448 9449 if (Parser.getTok().isNot(AsmToken::Hash) && 9450 Parser.getTok().isNot(AsmToken::Dollar)) { 9451 Error(Parser.getTok().getLoc(), "'#' expected"); 9452 return false; 9453 } 9454 Parser.Lex(); // skip hash token. 9455 9456 const MCExpr *OffsetExpr; 9457 SMLoc ExLoc = Parser.getTok().getLoc(); 9458 SMLoc EndLoc; 9459 if (getParser().parseExpression(OffsetExpr, EndLoc)) { 9460 Error(ExLoc, "malformed setfp offset"); 9461 return false; 9462 } 9463 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 9464 if (!CE) { 9465 Error(ExLoc, "setfp offset must be an immediate"); 9466 return false; 9467 } 9468 9469 Offset = CE->getValue(); 9470 } 9471 9472 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg), 9473 static_cast<unsigned>(SPReg), Offset); 9474 return false; 9475 } 9476 9477 /// parseDirective 9478 /// ::= .pad offset 9479 bool ARMAsmParser::parseDirectivePad(SMLoc L) { 9480 MCAsmParser &Parser = getParser(); 9481 // Check the ordering of unwind directives 9482 if (!UC.hasFnStart()) { 9483 Error(L, ".fnstart must precede .pad directive"); 9484 return false; 9485 } 9486 if (UC.hasHandlerData()) { 9487 Error(L, ".pad must precede .handlerdata directive"); 9488 return false; 9489 } 9490 9491 // Parse the offset 9492 if (Parser.getTok().isNot(AsmToken::Hash) && 9493 Parser.getTok().isNot(AsmToken::Dollar)) { 9494 Error(Parser.getTok().getLoc(), "'#' expected"); 9495 return false; 9496 } 9497 Parser.Lex(); // skip hash token. 9498 9499 const MCExpr *OffsetExpr; 9500 SMLoc ExLoc = Parser.getTok().getLoc(); 9501 SMLoc EndLoc; 9502 if (getParser().parseExpression(OffsetExpr, EndLoc)) { 9503 Error(ExLoc, "malformed pad offset"); 9504 return false; 9505 } 9506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 9507 if (!CE) { 9508 Error(ExLoc, "pad offset must be an immediate"); 9509 return false; 9510 } 9511 9512 getTargetStreamer().emitPad(CE->getValue()); 9513 return false; 9514 } 9515 9516 /// parseDirectiveRegSave 9517 /// ::= .save { registers } 9518 /// ::= .vsave { registers } 9519 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) { 9520 // Check the ordering of unwind directives 9521 if (!UC.hasFnStart()) { 9522 Error(L, ".fnstart must precede .save or .vsave directives"); 9523 return false; 9524 } 9525 if (UC.hasHandlerData()) { 9526 Error(L, ".save or .vsave must precede .handlerdata directive"); 9527 return false; 9528 } 9529 9530 // RAII object to make sure parsed operands are deleted. 9531 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands; 9532 9533 // Parse the register list 9534 if (parseRegisterList(Operands)) 9535 return false; 9536 ARMOperand &Op = (ARMOperand &)*Operands[0]; 9537 if (!IsVector && !Op.isRegList()) { 9538 Error(L, ".save expects GPR registers"); 9539 return false; 9540 } 9541 if (IsVector && !Op.isDPRRegList()) { 9542 Error(L, ".vsave expects DPR registers"); 9543 return false; 9544 } 9545 9546 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector); 9547 return false; 9548 } 9549 9550 /// parseDirectiveInst 9551 /// ::= .inst opcode [, ...] 9552 /// ::= .inst.n opcode [, ...] 9553 /// ::= .inst.w opcode [, ...] 9554 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) { 9555 MCAsmParser &Parser = getParser(); 9556 int Width; 9557 9558 if (isThumb()) { 9559 switch (Suffix) { 9560 case 'n': 9561 Width = 2; 9562 break; 9563 case 'w': 9564 Width = 4; 9565 break; 9566 default: 9567 Parser.eatToEndOfStatement(); 9568 Error(Loc, "cannot determine Thumb instruction size, " 9569 "use inst.n/inst.w instead"); 9570 return false; 9571 } 9572 } else { 9573 if (Suffix) { 9574 Parser.eatToEndOfStatement(); 9575 Error(Loc, "width suffixes are invalid in ARM mode"); 9576 return false; 9577 } 9578 Width = 4; 9579 } 9580 9581 if (getLexer().is(AsmToken::EndOfStatement)) { 9582 Parser.eatToEndOfStatement(); 9583 Error(Loc, "expected expression following directive"); 9584 return false; 9585 } 9586 9587 for (;;) { 9588 const MCExpr *Expr; 9589 9590 if (getParser().parseExpression(Expr)) { 9591 Error(Loc, "expected expression"); 9592 return false; 9593 } 9594 9595 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr); 9596 if (!Value) { 9597 Error(Loc, "expected constant expression"); 9598 return false; 9599 } 9600 9601 switch (Width) { 9602 case 2: 9603 if (Value->getValue() > 0xffff) { 9604 Error(Loc, "inst.n operand is too big, use inst.w instead"); 9605 return false; 9606 } 9607 break; 9608 case 4: 9609 if (Value->getValue() > 0xffffffff) { 9610 Error(Loc, 9611 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big"); 9612 return false; 9613 } 9614 break; 9615 default: 9616 llvm_unreachable("only supported widths are 2 and 4"); 9617 } 9618 9619 getTargetStreamer().emitInst(Value->getValue(), Suffix); 9620 9621 if (getLexer().is(AsmToken::EndOfStatement)) 9622 break; 9623 9624 if (getLexer().isNot(AsmToken::Comma)) { 9625 Error(Loc, "unexpected token in directive"); 9626 return false; 9627 } 9628 9629 Parser.Lex(); 9630 } 9631 9632 Parser.Lex(); 9633 return false; 9634 } 9635 9636 /// parseDirectiveLtorg 9637 /// ::= .ltorg | .pool 9638 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) { 9639 getTargetStreamer().emitCurrentConstantPool(); 9640 return false; 9641 } 9642 9643 bool ARMAsmParser::parseDirectiveEven(SMLoc L) { 9644 const MCSection *Section = getStreamer().getCurrentSection().first; 9645 9646 if (getLexer().isNot(AsmToken::EndOfStatement)) { 9647 TokError("unexpected token in directive"); 9648 return false; 9649 } 9650 9651 if (!Section) { 9652 getStreamer().InitSections(false); 9653 Section = getStreamer().getCurrentSection().first; 9654 } 9655 9656 assert(Section && "must have section to emit alignment"); 9657 if (Section->UseCodeAlign()) 9658 getStreamer().EmitCodeAlignment(2); 9659 else 9660 getStreamer().EmitValueToAlignment(2); 9661 9662 return false; 9663 } 9664 9665 /// parseDirectivePersonalityIndex 9666 /// ::= .personalityindex index 9667 bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) { 9668 MCAsmParser &Parser = getParser(); 9669 bool HasExistingPersonality = UC.hasPersonality(); 9670 9671 UC.recordPersonalityIndex(L); 9672 9673 if (!UC.hasFnStart()) { 9674 Parser.eatToEndOfStatement(); 9675 Error(L, ".fnstart must precede .personalityindex directive"); 9676 return false; 9677 } 9678 if (UC.cantUnwind()) { 9679 Parser.eatToEndOfStatement(); 9680 Error(L, ".personalityindex cannot be used with .cantunwind"); 9681 UC.emitCantUnwindLocNotes(); 9682 return false; 9683 } 9684 if (UC.hasHandlerData()) { 9685 Parser.eatToEndOfStatement(); 9686 Error(L, ".personalityindex must precede .handlerdata directive"); 9687 UC.emitHandlerDataLocNotes(); 9688 return false; 9689 } 9690 if (HasExistingPersonality) { 9691 Parser.eatToEndOfStatement(); 9692 Error(L, "multiple personality directives"); 9693 UC.emitPersonalityLocNotes(); 9694 return false; 9695 } 9696 9697 const MCExpr *IndexExpression; 9698 SMLoc IndexLoc = Parser.getTok().getLoc(); 9699 if (Parser.parseExpression(IndexExpression)) { 9700 Parser.eatToEndOfStatement(); 9701 return false; 9702 } 9703 9704 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression); 9705 if (!CE) { 9706 Parser.eatToEndOfStatement(); 9707 Error(IndexLoc, "index must be a constant number"); 9708 return false; 9709 } 9710 if (CE->getValue() < 0 || 9711 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) { 9712 Parser.eatToEndOfStatement(); 9713 Error(IndexLoc, "personality routine index should be in range [0-3]"); 9714 return false; 9715 } 9716 9717 getTargetStreamer().emitPersonalityIndex(CE->getValue()); 9718 return false; 9719 } 9720 9721 /// parseDirectiveUnwindRaw 9722 /// ::= .unwind_raw offset, opcode [, opcode...] 9723 bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) { 9724 MCAsmParser &Parser = getParser(); 9725 if (!UC.hasFnStart()) { 9726 Parser.eatToEndOfStatement(); 9727 Error(L, ".fnstart must precede .unwind_raw directives"); 9728 return false; 9729 } 9730 9731 int64_t StackOffset; 9732 9733 const MCExpr *OffsetExpr; 9734 SMLoc OffsetLoc = getLexer().getLoc(); 9735 if (getLexer().is(AsmToken::EndOfStatement) || 9736 getParser().parseExpression(OffsetExpr)) { 9737 Error(OffsetLoc, "expected expression"); 9738 Parser.eatToEndOfStatement(); 9739 return false; 9740 } 9741 9742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 9743 if (!CE) { 9744 Error(OffsetLoc, "offset must be a constant"); 9745 Parser.eatToEndOfStatement(); 9746 return false; 9747 } 9748 9749 StackOffset = CE->getValue(); 9750 9751 if (getLexer().isNot(AsmToken::Comma)) { 9752 Error(getLexer().getLoc(), "expected comma"); 9753 Parser.eatToEndOfStatement(); 9754 return false; 9755 } 9756 Parser.Lex(); 9757 9758 SmallVector<uint8_t, 16> Opcodes; 9759 for (;;) { 9760 const MCExpr *OE; 9761 9762 SMLoc OpcodeLoc = getLexer().getLoc(); 9763 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) { 9764 Error(OpcodeLoc, "expected opcode expression"); 9765 Parser.eatToEndOfStatement(); 9766 return false; 9767 } 9768 9769 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE); 9770 if (!OC) { 9771 Error(OpcodeLoc, "opcode value must be a constant"); 9772 Parser.eatToEndOfStatement(); 9773 return false; 9774 } 9775 9776 const int64_t Opcode = OC->getValue(); 9777 if (Opcode & ~0xff) { 9778 Error(OpcodeLoc, "invalid opcode"); 9779 Parser.eatToEndOfStatement(); 9780 return false; 9781 } 9782 9783 Opcodes.push_back(uint8_t(Opcode)); 9784 9785 if (getLexer().is(AsmToken::EndOfStatement)) 9786 break; 9787 9788 if (getLexer().isNot(AsmToken::Comma)) { 9789 Error(getLexer().getLoc(), "unexpected token in directive"); 9790 Parser.eatToEndOfStatement(); 9791 return false; 9792 } 9793 9794 Parser.Lex(); 9795 } 9796 9797 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes); 9798 9799 Parser.Lex(); 9800 return false; 9801 } 9802 9803 /// parseDirectiveTLSDescSeq 9804 /// ::= .tlsdescseq tls-variable 9805 bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) { 9806 MCAsmParser &Parser = getParser(); 9807 9808 if (getLexer().isNot(AsmToken::Identifier)) { 9809 TokError("expected variable after '.tlsdescseq' directive"); 9810 Parser.eatToEndOfStatement(); 9811 return false; 9812 } 9813 9814 const MCSymbolRefExpr *SRE = 9815 MCSymbolRefExpr::create(Parser.getTok().getIdentifier(), 9816 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext()); 9817 Lex(); 9818 9819 if (getLexer().isNot(AsmToken::EndOfStatement)) { 9820 Error(Parser.getTok().getLoc(), "unexpected token"); 9821 Parser.eatToEndOfStatement(); 9822 return false; 9823 } 9824 9825 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE); 9826 return false; 9827 } 9828 9829 /// parseDirectiveMovSP 9830 /// ::= .movsp reg [, #offset] 9831 bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) { 9832 MCAsmParser &Parser = getParser(); 9833 if (!UC.hasFnStart()) { 9834 Parser.eatToEndOfStatement(); 9835 Error(L, ".fnstart must precede .movsp directives"); 9836 return false; 9837 } 9838 if (UC.getFPReg() != ARM::SP) { 9839 Parser.eatToEndOfStatement(); 9840 Error(L, "unexpected .movsp directive"); 9841 return false; 9842 } 9843 9844 SMLoc SPRegLoc = Parser.getTok().getLoc(); 9845 int SPReg = tryParseRegister(); 9846 if (SPReg == -1) { 9847 Parser.eatToEndOfStatement(); 9848 Error(SPRegLoc, "register expected"); 9849 return false; 9850 } 9851 9852 if (SPReg == ARM::SP || SPReg == ARM::PC) { 9853 Parser.eatToEndOfStatement(); 9854 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive"); 9855 return false; 9856 } 9857 9858 int64_t Offset = 0; 9859 if (Parser.getTok().is(AsmToken::Comma)) { 9860 Parser.Lex(); 9861 9862 if (Parser.getTok().isNot(AsmToken::Hash)) { 9863 Error(Parser.getTok().getLoc(), "expected #constant"); 9864 Parser.eatToEndOfStatement(); 9865 return false; 9866 } 9867 Parser.Lex(); 9868 9869 const MCExpr *OffsetExpr; 9870 SMLoc OffsetLoc = Parser.getTok().getLoc(); 9871 if (Parser.parseExpression(OffsetExpr)) { 9872 Parser.eatToEndOfStatement(); 9873 Error(OffsetLoc, "malformed offset expression"); 9874 return false; 9875 } 9876 9877 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); 9878 if (!CE) { 9879 Parser.eatToEndOfStatement(); 9880 Error(OffsetLoc, "offset must be an immediate constant"); 9881 return false; 9882 } 9883 9884 Offset = CE->getValue(); 9885 } 9886 9887 getTargetStreamer().emitMovSP(SPReg, Offset); 9888 UC.saveFPReg(SPReg); 9889 9890 return false; 9891 } 9892 9893 /// parseDirectiveObjectArch 9894 /// ::= .object_arch name 9895 bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) { 9896 MCAsmParser &Parser = getParser(); 9897 if (getLexer().isNot(AsmToken::Identifier)) { 9898 Error(getLexer().getLoc(), "unexpected token"); 9899 Parser.eatToEndOfStatement(); 9900 return false; 9901 } 9902 9903 StringRef Arch = Parser.getTok().getString(); 9904 SMLoc ArchLoc = Parser.getTok().getLoc(); 9905 getLexer().Lex(); 9906 9907 unsigned ID = ARM::parseArch(Arch); 9908 9909 if (ID == ARM::AK_INVALID) { 9910 Error(ArchLoc, "unknown architecture '" + Arch + "'"); 9911 Parser.eatToEndOfStatement(); 9912 return false; 9913 } 9914 9915 getTargetStreamer().emitObjectArch(ID); 9916 9917 if (getLexer().isNot(AsmToken::EndOfStatement)) { 9918 Error(getLexer().getLoc(), "unexpected token"); 9919 Parser.eatToEndOfStatement(); 9920 } 9921 9922 return false; 9923 } 9924 9925 /// parseDirectiveAlign 9926 /// ::= .align 9927 bool ARMAsmParser::parseDirectiveAlign(SMLoc L) { 9928 // NOTE: if this is not the end of the statement, fall back to the target 9929 // agnostic handling for this directive which will correctly handle this. 9930 if (getLexer().isNot(AsmToken::EndOfStatement)) 9931 return true; 9932 9933 // '.align' is target specifically handled to mean 2**2 byte alignment. 9934 if (getStreamer().getCurrentSection().first->UseCodeAlign()) 9935 getStreamer().EmitCodeAlignment(4, 0); 9936 else 9937 getStreamer().EmitValueToAlignment(4, 0, 1, 0); 9938 9939 return false; 9940 } 9941 9942 /// parseDirectiveThumbSet 9943 /// ::= .thumb_set name, value 9944 bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) { 9945 MCAsmParser &Parser = getParser(); 9946 9947 StringRef Name; 9948 if (Parser.parseIdentifier(Name)) { 9949 TokError("expected identifier after '.thumb_set'"); 9950 Parser.eatToEndOfStatement(); 9951 return false; 9952 } 9953 9954 if (getLexer().isNot(AsmToken::Comma)) { 9955 TokError("expected comma after name '" + Name + "'"); 9956 Parser.eatToEndOfStatement(); 9957 return false; 9958 } 9959 Lex(); 9960 9961 MCSymbol *Sym; 9962 const MCExpr *Value; 9963 if (MCParserUtils::parseAssignmentExpression(Name, /* allow_redef */ true, 9964 Parser, Sym, Value)) 9965 return true; 9966 9967 getTargetStreamer().emitThumbSet(Sym, Value); 9968 return false; 9969 } 9970 9971 /// Force static initialization. 9972 extern "C" void LLVMInitializeARMAsmParser() { 9973 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget); 9974 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget); 9975 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget); 9976 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget); 9977 } 9978 9979 #define GET_REGISTER_MATCHER 9980 #define GET_SUBTARGET_FEATURE_NAME 9981 #define GET_MATCHER_IMPLEMENTATION 9982 #include "ARMGenAsmMatcher.inc" 9983 9984 // FIXME: This structure should be moved inside ARMTargetParser 9985 // when we start to table-generate them, and we can use the ARM 9986 // flags below, that were generated by table-gen. 9987 static const struct { 9988 const unsigned Kind; 9989 const uint64_t ArchCheck; 9990 const FeatureBitset Features; 9991 } Extensions[] = { 9992 { ARM::AEK_CRC, Feature_HasV8, {ARM::FeatureCRC} }, 9993 { ARM::AEK_CRYPTO, Feature_HasV8, 9994 {ARM::FeatureCrypto, ARM::FeatureNEON, ARM::FeatureFPARMv8} }, 9995 { ARM::AEK_FP, Feature_HasV8, {ARM::FeatureFPARMv8} }, 9996 { (ARM::AEK_HWDIV | ARM::AEK_HWDIVARM), Feature_HasV7 | Feature_IsNotMClass, 9997 {ARM::FeatureHWDiv, ARM::FeatureHWDivARM} }, 9998 { ARM::AEK_MP, Feature_HasV7 | Feature_IsNotMClass, {ARM::FeatureMP} }, 9999 { ARM::AEK_SIMD, Feature_HasV8, {ARM::FeatureNEON, ARM::FeatureFPARMv8} }, 10000 { ARM::AEK_SEC, Feature_HasV6K, {ARM::FeatureTrustZone} }, 10001 // FIXME: Only available in A-class, isel not predicated 10002 { ARM::AEK_VIRT, Feature_HasV7, {ARM::FeatureVirtualization} }, 10003 { ARM::AEK_FP16, Feature_HasV8_2a, {ARM::FeatureFPARMv8, ARM::FeatureFullFP16} }, 10004 // FIXME: Unsupported extensions. 10005 { ARM::AEK_OS, Feature_None, {} }, 10006 { ARM::AEK_IWMMXT, Feature_None, {} }, 10007 { ARM::AEK_IWMMXT2, Feature_None, {} }, 10008 { ARM::AEK_MAVERICK, Feature_None, {} }, 10009 { ARM::AEK_XSCALE, Feature_None, {} }, 10010 }; 10011 10012 /// parseDirectiveArchExtension 10013 /// ::= .arch_extension [no]feature 10014 bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) { 10015 MCAsmParser &Parser = getParser(); 10016 10017 if (getLexer().isNot(AsmToken::Identifier)) { 10018 Error(getLexer().getLoc(), "unexpected token"); 10019 Parser.eatToEndOfStatement(); 10020 return false; 10021 } 10022 10023 StringRef Name = Parser.getTok().getString(); 10024 SMLoc ExtLoc = Parser.getTok().getLoc(); 10025 getLexer().Lex(); 10026 10027 bool EnableFeature = true; 10028 if (Name.startswith_lower("no")) { 10029 EnableFeature = false; 10030 Name = Name.substr(2); 10031 } 10032 unsigned FeatureKind = ARM::parseArchExt(Name); 10033 if (FeatureKind == ARM::AEK_INVALID) 10034 Error(ExtLoc, "unknown architectural extension: " + Name); 10035 10036 for (const auto &Extension : Extensions) { 10037 if (Extension.Kind != FeatureKind) 10038 continue; 10039 10040 if (Extension.Features.none()) 10041 report_fatal_error("unsupported architectural extension: " + Name); 10042 10043 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) { 10044 Error(ExtLoc, "architectural extension '" + Name + "' is not " 10045 "allowed for the current base architecture"); 10046 return false; 10047 } 10048 10049 MCSubtargetInfo &STI = copySTI(); 10050 FeatureBitset ToggleFeatures = EnableFeature 10051 ? (~STI.getFeatureBits() & Extension.Features) 10052 : ( STI.getFeatureBits() & Extension.Features); 10053 10054 uint64_t Features = 10055 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures)); 10056 setAvailableFeatures(Features); 10057 return false; 10058 } 10059 10060 Error(ExtLoc, "unknown architectural extension: " + Name); 10061 Parser.eatToEndOfStatement(); 10062 return false; 10063 } 10064 10065 // Define this matcher function after the auto-generated include so we 10066 // have the match class enum definitions. 10067 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp, 10068 unsigned Kind) { 10069 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp); 10070 // If the kind is a token for a literal immediate, check if our asm 10071 // operand matches. This is for InstAliases which have a fixed-value 10072 // immediate in the syntax. 10073 switch (Kind) { 10074 default: break; 10075 case MCK__35_0: 10076 if (Op.isImm()) 10077 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm())) 10078 if (CE->getValue() == 0) 10079 return Match_Success; 10080 break; 10081 case MCK_ModImm: 10082 if (Op.isImm()) { 10083 const MCExpr *SOExpr = Op.getImm(); 10084 int64_t Value; 10085 if (!SOExpr->evaluateAsAbsolute(Value)) 10086 return Match_Success; 10087 assert((Value >= INT32_MIN && Value <= UINT32_MAX) && 10088 "expression value must be representable in 32 bits"); 10089 } 10090 break; 10091 case MCK_rGPR: 10092 if (hasV8Ops() && Op.isReg() && Op.getReg() == ARM::SP) 10093 return Match_Success; 10094 break; 10095 case MCK_GPRPair: 10096 if (Op.isReg() && 10097 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg())) 10098 return Match_Success; 10099 break; 10100 } 10101 return Match_InvalidOperand; 10102 } 10103