1 //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "ARMBuildAttrs.h"
11 #include "ARMFPUName.h"
12 #include "ARMFeatures.h"
13 #include "llvm/MC/MCTargetAsmParser.h"
14 #include "MCTargetDesc/ARMAddressingModes.h"
15 #include "MCTargetDesc/ARMArchName.h"
16 #include "MCTargetDesc/ARMBaseInfo.h"
17 #include "MCTargetDesc/ARMMCExpr.h"
18 #include "llvm/ADT/BitVector.h"
19 #include "llvm/ADT/OwningPtr.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/ADT/StringSwitch.h"
24 #include "llvm/ADT/Twine.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCAssembler.h"
27 #include "llvm/MC/MCContext.h"
28 #include "llvm/MC/MCELFStreamer.h"
29 #include "llvm/MC/MCExpr.h"
30 #include "llvm/MC/MCInst.h"
31 #include "llvm/MC/MCInstrDesc.h"
32 #include "llvm/MC/MCInstrInfo.h"
33 #include "llvm/MC/MCParser/MCAsmLexer.h"
34 #include "llvm/MC/MCParser/MCAsmParser.h"
35 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
36 #include "llvm/MC/MCRegisterInfo.h"
37 #include "llvm/MC/MCStreamer.h"
38 #include "llvm/MC/MCSubtargetInfo.h"
39 #include "llvm/MC/MCSymbol.h"
40 #include "llvm/Support/ELF.h"
41 #include "llvm/Support/MathExtras.h"
42 #include "llvm/Support/SourceMgr.h"
43 #include "llvm/Support/TargetRegistry.h"
44 #include "llvm/Support/raw_ostream.h"
52 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
54 // A class to keep track of assembler-generated constant pools that are use to
55 // implement the ldr-pseudo.
57 typedef SmallVector<std::pair<MCSymbol *, const MCExpr *>, 4> EntryVecTy;
61 // Initialize a new empty constant pool
64 // Add a new entry to the constant pool in the next slot.
65 // \param Value is the new entry to put in the constant pool.
67 // \returns a MCExpr that references the newly inserted value
68 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context) {
69 MCSymbol *CPEntryLabel = Context.CreateTempSymbol();
71 Entries.push_back(std::make_pair(CPEntryLabel, Value));
72 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
75 // Emit the contents of the constant pool using the provided streamer.
76 void emitEntries(MCStreamer &Streamer) const {
77 Streamer.EmitCodeAlignment(4); // align to 4-byte address
78 Streamer.EmitDataRegion(MCDR_DataRegion);
79 for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
81 Streamer.EmitLabel(I->first);
82 Streamer.EmitValue(I->second, 4);
84 Streamer.EmitDataRegion(MCDR_DataRegionEnd);
88 // Map type used to keep track of per-Section constant pools used by the
89 // ldr-pseudo opcode. The map associates a section to its constant pool. The
90 // constant pool is a vector of (label, value) pairs. When the ldr
91 // pseudo is parsed we insert a new (label, value) pair into the constant pool
92 // for the current section and add MCSymbolRefExpr to the new label as
93 // an opcode to the ldr. After we have parsed all the user input we
94 // output the (label, value) pairs in each constant pool at the end of the
96 typedef std::map<const MCSection *, ConstantPool> ConstantPoolMapTy;
98 class ARMAsmParser : public MCTargetAsmParser {
101 const MCInstrInfo &MII;
102 const MCRegisterInfo *MRI;
103 ConstantPoolMapTy ConstantPools;
105 // Assembler created constant pools for ldr pseudo
106 ConstantPool *getConstantPool(const MCSection *Section) {
107 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
108 if (CP == ConstantPools.end())
114 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
115 return ConstantPools[Section];
118 void destroyConstantPool(const MCSection *Section) {
119 ConstantPools.erase(Section);
122 ARMTargetStreamer &getTargetStreamer() {
123 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
124 return static_cast<ARMTargetStreamer &>(TS);
127 // Unwind directives state
130 SMLoc PersonalityLoc;
131 SMLoc HandlerDataLoc;
133 void resetUnwindDirectiveParserState() {
134 FnStartLoc = SMLoc();
135 CantUnwindLoc = SMLoc();
136 PersonalityLoc = SMLoc();
137 HandlerDataLoc = SMLoc();
141 // Map of register aliases registers via the .req directive.
142 StringMap<unsigned> RegisterReqs;
144 bool NextSymbolIsThumb;
147 ARMCC::CondCodes Cond; // Condition for IT block.
148 unsigned Mask:4; // Condition mask for instructions.
149 // Starting at first 1 (from lsb).
150 // '1' condition as indicated in IT.
151 // '0' inverse of condition (else).
152 // Count of instructions in IT block is
153 // 4 - trailingzeroes(mask)
155 bool FirstCond; // Explicit flag for when we're parsing the
156 // First instruction in the IT block. It's
157 // implied in the mask, so needs special
160 unsigned CurPosition; // Current position in parsing of IT
161 // block. In range [0,3]. Initialized
162 // according to count of instructions in block.
163 // ~0U if no active IT block.
165 bool inITBlock() { return ITState.CurPosition != ~0U;}
166 void forwardITPosition() {
167 if (!inITBlock()) return;
168 // Move to the next instruction in the IT block, if there is one. If not,
169 // mark the block as done.
170 unsigned TZ = countTrailingZeros(ITState.Mask);
171 if (++ITState.CurPosition == 5 - TZ)
172 ITState.CurPosition = ~0U; // Done with the IT block after this.
176 MCAsmParser &getParser() const { return Parser; }
177 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
179 bool Warning(SMLoc L, const Twine &Msg,
180 ArrayRef<SMRange> Ranges = None) {
181 return Parser.Warning(L, Msg, Ranges);
183 bool Error(SMLoc L, const Twine &Msg,
184 ArrayRef<SMRange> Ranges = None) {
185 return Parser.Error(L, Msg, Ranges);
188 int tryParseRegister();
189 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
190 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
191 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
192 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
193 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
194 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
195 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
196 unsigned &ShiftAmount);
197 bool parseDirectiveWord(unsigned Size, SMLoc L);
198 bool parseDirectiveThumb(SMLoc L);
199 bool parseDirectiveARM(SMLoc L);
200 bool parseDirectiveThumbFunc(SMLoc L);
201 bool parseDirectiveCode(SMLoc L);
202 bool parseDirectiveSyntax(SMLoc L);
203 bool parseDirectiveReq(StringRef Name, SMLoc L);
204 bool parseDirectiveUnreq(SMLoc L);
205 bool parseDirectiveArch(SMLoc L);
206 bool parseDirectiveEabiAttr(SMLoc L);
207 bool parseDirectiveCPU(SMLoc L);
208 bool parseDirectiveFPU(SMLoc L);
209 bool parseDirectiveFnStart(SMLoc L);
210 bool parseDirectiveFnEnd(SMLoc L);
211 bool parseDirectiveCantUnwind(SMLoc L);
212 bool parseDirectivePersonality(SMLoc L);
213 bool parseDirectiveHandlerData(SMLoc L);
214 bool parseDirectiveSetFP(SMLoc L);
215 bool parseDirectivePad(SMLoc L);
216 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
217 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
218 bool parseDirectiveLtorg(SMLoc L);
220 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
221 bool &CarrySetting, unsigned &ProcessorIMod,
223 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
224 bool &CanAcceptCarrySet,
225 bool &CanAcceptPredicationCode);
227 bool isThumb() const {
228 // FIXME: Can tablegen auto-generate this?
229 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
231 bool isThumbOne() const {
232 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
234 bool isThumbTwo() const {
235 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
237 bool hasThumb() const {
238 return STI.getFeatureBits() & ARM::HasV4TOps;
240 bool hasV6Ops() const {
241 return STI.getFeatureBits() & ARM::HasV6Ops;
243 bool hasV6MOps() const {
244 return STI.getFeatureBits() & ARM::HasV6MOps;
246 bool hasV7Ops() const {
247 return STI.getFeatureBits() & ARM::HasV7Ops;
249 bool hasV8Ops() const {
250 return STI.getFeatureBits() & ARM::HasV8Ops;
252 bool hasARM() const {
253 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
257 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
258 setAvailableFeatures(FB);
260 bool isMClass() const {
261 return STI.getFeatureBits() & ARM::FeatureMClass;
264 /// @name Auto-generated Match Functions
267 #define GET_ASSEMBLER_HEADER
268 #include "ARMGenAsmMatcher.inc"
272 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
273 OperandMatchResultTy parseCoprocNumOperand(
274 SmallVectorImpl<MCParsedAsmOperand*>&);
275 OperandMatchResultTy parseCoprocRegOperand(
276 SmallVectorImpl<MCParsedAsmOperand*>&);
277 OperandMatchResultTy parseCoprocOptionOperand(
278 SmallVectorImpl<MCParsedAsmOperand*>&);
279 OperandMatchResultTy parseMemBarrierOptOperand(
280 SmallVectorImpl<MCParsedAsmOperand*>&);
281 OperandMatchResultTy parseInstSyncBarrierOptOperand(
282 SmallVectorImpl<MCParsedAsmOperand*>&);
283 OperandMatchResultTy parseProcIFlagsOperand(
284 SmallVectorImpl<MCParsedAsmOperand*>&);
285 OperandMatchResultTy parseMSRMaskOperand(
286 SmallVectorImpl<MCParsedAsmOperand*>&);
287 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
288 StringRef Op, int Low, int High);
289 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
290 return parsePKHImm(O, "lsl", 0, 31);
292 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
293 return parsePKHImm(O, "asr", 1, 32);
295 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
296 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
297 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
298 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
299 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
300 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
301 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
302 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
303 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
306 // Asm Match Converter Methods
307 void cvtThumbMultiply(MCInst &Inst,
308 const SmallVectorImpl<MCParsedAsmOperand*> &);
309 void cvtThumbBranches(MCInst &Inst,
310 const SmallVectorImpl<MCParsedAsmOperand*> &);
312 bool validateInstruction(MCInst &Inst,
313 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
314 bool processInstruction(MCInst &Inst,
315 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
316 bool shouldOmitCCOutOperand(StringRef Mnemonic,
317 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
318 bool shouldOmitPredicateOperand(StringRef Mnemonic,
319 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
321 enum ARMMatchResultTy {
322 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
323 Match_RequiresNotITBlock,
325 Match_RequiresThumb2,
326 #define GET_OPERAND_DIAGNOSTIC_TYPES
327 #include "ARMGenAsmMatcher.inc"
331 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
332 const MCInstrInfo &MII)
333 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
334 MCAsmParserExtension::Initialize(_Parser);
336 // Cache the MCRegisterInfo.
337 MRI = getContext().getRegisterInfo();
339 // Initialize the set of available features.
340 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
342 // Not in an ITBlock to start with.
343 ITState.CurPosition = ~0U;
345 NextSymbolIsThumb = false;
348 // Implementation of the MCTargetAsmParser interface:
349 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
350 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
352 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
353 bool ParseDirective(AsmToken DirectiveID);
355 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
356 unsigned checkTargetMatchPredicate(MCInst &Inst);
358 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
359 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
360 MCStreamer &Out, unsigned &ErrorInfo,
361 bool MatchingInlineAsm);
362 void onLabelParsed(MCSymbol *Symbol);
365 } // end anonymous namespace
369 /// ARMOperand - Instances of this class represent a parsed ARM machine
371 class ARMOperand : public MCParsedAsmOperand {
381 k_InstSyncBarrierOpt,
392 k_VectorListAllLanes,
398 k_BitfieldDescriptor,
402 SMLoc StartLoc, EndLoc;
403 SmallVector<unsigned, 8> Registers;
406 ARMCC::CondCodes Val;
413 struct CoprocOptionOp {
426 ARM_ISB::InstSyncBOpt Val;
430 ARM_PROC::IFlags Val;
446 // A vector register list is a sequential list of 1 to 4 registers.
447 struct VectorListOp {
454 struct VectorIndexOp {
462 /// Combined record for all forms of ARM address expressions.
465 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
467 const MCConstantExpr *OffsetImm; // Offset immediate value
468 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
469 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
470 unsigned ShiftImm; // shift for OffsetReg.
471 unsigned Alignment; // 0 = no alignment specified
472 // n = alignment in bytes (2, 4, 8, 16, or 32)
473 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
476 struct PostIdxRegOp {
479 ARM_AM::ShiftOpc ShiftTy;
483 struct ShifterImmOp {
488 struct RegShiftedRegOp {
489 ARM_AM::ShiftOpc ShiftTy;
495 struct RegShiftedImmOp {
496 ARM_AM::ShiftOpc ShiftTy;
513 struct CoprocOptionOp CoprocOption;
514 struct MBOptOp MBOpt;
515 struct ISBOptOp ISBOpt;
516 struct ITMaskOp ITMask;
517 struct IFlagsOp IFlags;
518 struct MMaskOp MMask;
521 struct VectorListOp VectorList;
522 struct VectorIndexOp VectorIndex;
524 struct MemoryOp Memory;
525 struct PostIdxRegOp PostIdxReg;
526 struct ShifterImmOp ShifterImm;
527 struct RegShiftedRegOp RegShiftedReg;
528 struct RegShiftedImmOp RegShiftedImm;
529 struct RotImmOp RotImm;
530 struct BitfieldOp Bitfield;
533 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
535 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
537 StartLoc = o.StartLoc;
554 case k_DPRRegisterList:
555 case k_SPRRegisterList:
556 Registers = o.Registers;
559 case k_VectorListAllLanes:
560 case k_VectorListIndexed:
561 VectorList = o.VectorList;
568 CoprocOption = o.CoprocOption;
573 case k_MemBarrierOpt:
576 case k_InstSyncBarrierOpt:
581 case k_PostIndexRegister:
582 PostIdxReg = o.PostIdxReg;
590 case k_ShifterImmediate:
591 ShifterImm = o.ShifterImm;
593 case k_ShiftedRegister:
594 RegShiftedReg = o.RegShiftedReg;
596 case k_ShiftedImmediate:
597 RegShiftedImm = o.RegShiftedImm;
599 case k_RotateImmediate:
602 case k_BitfieldDescriptor:
603 Bitfield = o.Bitfield;
606 VectorIndex = o.VectorIndex;
611 /// getStartLoc - Get the location of the first token of this operand.
612 SMLoc getStartLoc() const { return StartLoc; }
613 /// getEndLoc - Get the location of the last token of this operand.
614 SMLoc getEndLoc() const { return EndLoc; }
615 /// getLocRange - Get the range between the first and last token of this
617 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
619 ARMCC::CondCodes getCondCode() const {
620 assert(Kind == k_CondCode && "Invalid access!");
624 unsigned getCoproc() const {
625 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
629 StringRef getToken() const {
630 assert(Kind == k_Token && "Invalid access!");
631 return StringRef(Tok.Data, Tok.Length);
634 unsigned getReg() const {
635 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
639 const SmallVectorImpl<unsigned> &getRegList() const {
640 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
641 Kind == k_SPRRegisterList) && "Invalid access!");
645 const MCExpr *getImm() const {
646 assert(isImm() && "Invalid access!");
650 unsigned getVectorIndex() const {
651 assert(Kind == k_VectorIndex && "Invalid access!");
652 return VectorIndex.Val;
655 ARM_MB::MemBOpt getMemBarrierOpt() const {
656 assert(Kind == k_MemBarrierOpt && "Invalid access!");
660 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
661 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
665 ARM_PROC::IFlags getProcIFlags() const {
666 assert(Kind == k_ProcIFlags && "Invalid access!");
670 unsigned getMSRMask() const {
671 assert(Kind == k_MSRMask && "Invalid access!");
675 bool isCoprocNum() const { return Kind == k_CoprocNum; }
676 bool isCoprocReg() const { return Kind == k_CoprocReg; }
677 bool isCoprocOption() const { return Kind == k_CoprocOption; }
678 bool isCondCode() const { return Kind == k_CondCode; }
679 bool isCCOut() const { return Kind == k_CCOut; }
680 bool isITMask() const { return Kind == k_ITCondMask; }
681 bool isITCondCode() const { return Kind == k_CondCode; }
682 bool isImm() const { return Kind == k_Immediate; }
683 // checks whether this operand is an unsigned offset which fits is a field
684 // of specified width and scaled by a specific number of bits
685 template<unsigned width, unsigned scale>
686 bool isUnsignedOffset() const {
687 if (!isImm()) return false;
688 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
689 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
690 int64_t Val = CE->getValue();
691 int64_t Align = 1LL << scale;
692 int64_t Max = Align * ((1LL << width) - 1);
693 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
697 // checks whether this operand is an signed offset which fits is a field
698 // of specified width and scaled by a specific number of bits
699 template<unsigned width, unsigned scale>
700 bool isSignedOffset() const {
701 if (!isImm()) return false;
702 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
703 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
704 int64_t Val = CE->getValue();
705 int64_t Align = 1LL << scale;
706 int64_t Max = Align * ((1LL << (width-1)) - 1);
707 int64_t Min = -Align * (1LL << (width-1));
708 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
713 // checks whether this operand is a memory operand computed as an offset
714 // applied to PC. the offset may have 8 bits of magnitude and is represented
715 // with two bits of shift. textually it may be either [pc, #imm], #imm or
716 // relocable expression...
717 bool isThumbMemPC() const {
720 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
721 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
722 if (!CE) return false;
723 Val = CE->getValue();
726 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
727 if(Memory.BaseRegNum != ARM::PC) return false;
728 Val = Memory.OffsetImm->getValue();
731 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
733 bool isFPImm() const {
734 if (!isImm()) return false;
735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
736 if (!CE) return false;
737 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
740 bool isFBits16() const {
741 if (!isImm()) return false;
742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
743 if (!CE) return false;
744 int64_t Value = CE->getValue();
745 return Value >= 0 && Value <= 16;
747 bool isFBits32() const {
748 if (!isImm()) return false;
749 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
750 if (!CE) return false;
751 int64_t Value = CE->getValue();
752 return Value >= 1 && Value <= 32;
754 bool isImm8s4() const {
755 if (!isImm()) return false;
756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
757 if (!CE) return false;
758 int64_t Value = CE->getValue();
759 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
761 bool isImm0_1020s4() 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 & 3) == 0) && Value >= 0 && Value <= 1020;
768 bool isImm0_508s4() 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 & 3) == 0) && Value >= 0 && Value <= 508;
775 bool isImm0_508s4Neg() 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 // explicitly exclude zero. we want that to use the normal 0_508 version.
781 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
783 bool isImm0_239() const {
784 if (!isImm()) return false;
785 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
786 if (!CE) return false;
787 int64_t Value = CE->getValue();
788 return Value >= 0 && Value < 240;
790 bool isImm0_255() const {
791 if (!isImm()) return false;
792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
793 if (!CE) return false;
794 int64_t Value = CE->getValue();
795 return Value >= 0 && Value < 256;
797 bool isImm0_4095() const {
798 if (!isImm()) return false;
799 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
800 if (!CE) return false;
801 int64_t Value = CE->getValue();
802 return Value >= 0 && Value < 4096;
804 bool isImm0_4095Neg() const {
805 if (!isImm()) return false;
806 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
807 if (!CE) return false;
808 int64_t Value = -CE->getValue();
809 return Value > 0 && Value < 4096;
811 bool isImm0_1() const {
812 if (!isImm()) return false;
813 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
814 if (!CE) return false;
815 int64_t Value = CE->getValue();
816 return Value >= 0 && Value < 2;
818 bool isImm0_3() const {
819 if (!isImm()) return false;
820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
821 if (!CE) return false;
822 int64_t Value = CE->getValue();
823 return Value >= 0 && Value < 4;
825 bool isImm0_7() const {
826 if (!isImm()) return false;
827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
828 if (!CE) return false;
829 int64_t Value = CE->getValue();
830 return Value >= 0 && Value < 8;
832 bool isImm0_15() const {
833 if (!isImm()) return false;
834 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
835 if (!CE) return false;
836 int64_t Value = CE->getValue();
837 return Value >= 0 && Value < 16;
839 bool isImm0_31() const {
840 if (!isImm()) return false;
841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
842 if (!CE) return false;
843 int64_t Value = CE->getValue();
844 return Value >= 0 && Value < 32;
846 bool isImm0_63() const {
847 if (!isImm()) return false;
848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
849 if (!CE) return false;
850 int64_t Value = CE->getValue();
851 return Value >= 0 && Value < 64;
853 bool isImm8() const {
854 if (!isImm()) return false;
855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
856 if (!CE) return false;
857 int64_t Value = CE->getValue();
860 bool isImm16() const {
861 if (!isImm()) return false;
862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
863 if (!CE) return false;
864 int64_t Value = CE->getValue();
867 bool isImm32() const {
868 if (!isImm()) return false;
869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
870 if (!CE) return false;
871 int64_t Value = CE->getValue();
874 bool isShrImm8() const {
875 if (!isImm()) return false;
876 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
877 if (!CE) return false;
878 int64_t Value = CE->getValue();
879 return Value > 0 && Value <= 8;
881 bool isShrImm16() const {
882 if (!isImm()) return false;
883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
884 if (!CE) return false;
885 int64_t Value = CE->getValue();
886 return Value > 0 && Value <= 16;
888 bool isShrImm32() const {
889 if (!isImm()) return false;
890 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
891 if (!CE) return false;
892 int64_t Value = CE->getValue();
893 return Value > 0 && Value <= 32;
895 bool isShrImm64() const {
896 if (!isImm()) return false;
897 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
898 if (!CE) return false;
899 int64_t Value = CE->getValue();
900 return Value > 0 && Value <= 64;
902 bool isImm1_7() const {
903 if (!isImm()) return false;
904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
905 if (!CE) return false;
906 int64_t Value = CE->getValue();
907 return Value > 0 && Value < 8;
909 bool isImm1_15() const {
910 if (!isImm()) return false;
911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
912 if (!CE) return false;
913 int64_t Value = CE->getValue();
914 return Value > 0 && Value < 16;
916 bool isImm1_31() const {
917 if (!isImm()) return false;
918 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
919 if (!CE) return false;
920 int64_t Value = CE->getValue();
921 return Value > 0 && Value < 32;
923 bool isImm1_16() const {
924 if (!isImm()) return false;
925 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
926 if (!CE) return false;
927 int64_t Value = CE->getValue();
928 return Value > 0 && Value < 17;
930 bool isImm1_32() const {
931 if (!isImm()) return false;
932 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
933 if (!CE) return false;
934 int64_t Value = CE->getValue();
935 return Value > 0 && Value < 33;
937 bool isImm0_32() const {
938 if (!isImm()) return false;
939 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
940 if (!CE) return false;
941 int64_t Value = CE->getValue();
942 return Value >= 0 && Value < 33;
944 bool isImm0_65535() const {
945 if (!isImm()) return false;
946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
947 if (!CE) return false;
948 int64_t Value = CE->getValue();
949 return Value >= 0 && Value < 65536;
951 bool isImm256_65535Expr() const {
952 if (!isImm()) return false;
953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
954 // If it's not a constant expression, it'll generate a fixup and be
956 if (!CE) return true;
957 int64_t Value = CE->getValue();
958 return Value >= 256 && Value < 65536;
960 bool isImm0_65535Expr() const {
961 if (!isImm()) return false;
962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
963 // If it's not a constant expression, it'll generate a fixup and be
965 if (!CE) return true;
966 int64_t Value = CE->getValue();
967 return Value >= 0 && Value < 65536;
969 bool isImm24bit() const {
970 if (!isImm()) return false;
971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
972 if (!CE) return false;
973 int64_t Value = CE->getValue();
974 return Value >= 0 && Value <= 0xffffff;
976 bool isImmThumbSR() const {
977 if (!isImm()) return false;
978 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
979 if (!CE) return false;
980 int64_t Value = CE->getValue();
981 return Value > 0 && Value < 33;
983 bool isPKHLSLImm() const {
984 if (!isImm()) return false;
985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
986 if (!CE) return false;
987 int64_t Value = CE->getValue();
988 return Value >= 0 && Value < 32;
990 bool isPKHASRImm() const {
991 if (!isImm()) return false;
992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
993 if (!CE) return false;
994 int64_t Value = CE->getValue();
995 return Value > 0 && Value <= 32;
997 bool isAdrLabel() const {
998 // If we have an immediate that's not a constant, treat it as a label
999 // reference needing a fixup. If it is a constant, but it can't fit
1000 // into shift immediate encoding, we reject it.
1001 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1002 else return (isARMSOImm() || isARMSOImmNeg());
1004 bool isARMSOImm() 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 return ARM_AM::getSOImmVal(Value) != -1;
1011 bool isARMSOImmNot() const {
1012 if (!isImm()) return false;
1013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1014 if (!CE) return false;
1015 int64_t Value = CE->getValue();
1016 return ARM_AM::getSOImmVal(~Value) != -1;
1018 bool isARMSOImmNeg() const {
1019 if (!isImm()) return false;
1020 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1021 if (!CE) return false;
1022 int64_t Value = CE->getValue();
1023 // Only use this when not representable as a plain so_imm.
1024 return ARM_AM::getSOImmVal(Value) == -1 &&
1025 ARM_AM::getSOImmVal(-Value) != -1;
1027 bool isT2SOImm() const {
1028 if (!isImm()) return false;
1029 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1030 if (!CE) return false;
1031 int64_t Value = CE->getValue();
1032 return ARM_AM::getT2SOImmVal(Value) != -1;
1034 bool isT2SOImmNot() const {
1035 if (!isImm()) return false;
1036 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1037 if (!CE) return false;
1038 int64_t Value = CE->getValue();
1039 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1040 ARM_AM::getT2SOImmVal(~Value) != -1;
1042 bool isT2SOImmNeg() const {
1043 if (!isImm()) return false;
1044 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1045 if (!CE) return false;
1046 int64_t Value = CE->getValue();
1047 // Only use this when not representable as a plain so_imm.
1048 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1049 ARM_AM::getT2SOImmVal(-Value) != -1;
1051 bool isSetEndImm() const {
1052 if (!isImm()) return false;
1053 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1054 if (!CE) return false;
1055 int64_t Value = CE->getValue();
1056 return Value == 1 || Value == 0;
1058 bool isReg() const { return Kind == k_Register; }
1059 bool isRegList() const { return Kind == k_RegisterList; }
1060 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1061 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1062 bool isToken() const { return Kind == k_Token; }
1063 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1064 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1065 bool isMem() const { return Kind == k_Memory; }
1066 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1067 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1068 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1069 bool isRotImm() const { return Kind == k_RotateImmediate; }
1070 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1071 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1072 bool isPostIdxReg() const {
1073 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1075 bool isMemNoOffset(bool alignOK = false) const {
1078 // No offset of any kind.
1079 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1080 (alignOK || Memory.Alignment == 0);
1082 bool isMemPCRelImm12() const {
1083 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1085 // Base register must be PC.
1086 if (Memory.BaseRegNum != ARM::PC)
1088 // Immediate offset in range [-4095, 4095].
1089 if (!Memory.OffsetImm) return true;
1090 int64_t Val = Memory.OffsetImm->getValue();
1091 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1093 bool isAlignedMemory() const {
1094 return isMemNoOffset(true);
1096 bool isAddrMode2() const {
1097 if (!isMem() || Memory.Alignment != 0) return false;
1098 // Check for register offset.
1099 if (Memory.OffsetRegNum) return true;
1100 // Immediate offset in range [-4095, 4095].
1101 if (!Memory.OffsetImm) return true;
1102 int64_t Val = Memory.OffsetImm->getValue();
1103 return Val > -4096 && Val < 4096;
1105 bool isAM2OffsetImm() const {
1106 if (!isImm()) return false;
1107 // Immediate offset in range [-4095, 4095].
1108 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1109 if (!CE) return false;
1110 int64_t Val = CE->getValue();
1111 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1113 bool isAddrMode3() const {
1114 // If we have an immediate that's not a constant, treat it as a label
1115 // reference needing a fixup. If it is a constant, it's something else
1116 // and we reject it.
1117 if (isImm() && !isa<MCConstantExpr>(getImm()))
1119 if (!isMem() || Memory.Alignment != 0) return false;
1120 // No shifts are legal for AM3.
1121 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1122 // Check for register offset.
1123 if (Memory.OffsetRegNum) return true;
1124 // Immediate offset in range [-255, 255].
1125 if (!Memory.OffsetImm) return true;
1126 int64_t Val = Memory.OffsetImm->getValue();
1127 // The #-0 offset is encoded as INT32_MIN, and we have to check
1129 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1131 bool isAM3Offset() const {
1132 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1134 if (Kind == k_PostIndexRegister)
1135 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1136 // Immediate offset in range [-255, 255].
1137 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1138 if (!CE) return false;
1139 int64_t Val = CE->getValue();
1140 // Special case, #-0 is INT32_MIN.
1141 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1143 bool isAddrMode5() const {
1144 // If we have an immediate that's not a constant, treat it as a label
1145 // reference needing a fixup. If it is a constant, it's something else
1146 // and we reject it.
1147 if (isImm() && !isa<MCConstantExpr>(getImm()))
1149 if (!isMem() || Memory.Alignment != 0) return false;
1150 // Check for register offset.
1151 if (Memory.OffsetRegNum) return false;
1152 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1153 if (!Memory.OffsetImm) return true;
1154 int64_t Val = Memory.OffsetImm->getValue();
1155 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1158 bool isMemTBB() const {
1159 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1160 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1164 bool isMemTBH() const {
1165 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1166 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1167 Memory.Alignment != 0 )
1171 bool isMemRegOffset() const {
1172 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1176 bool isT2MemRegOffset() const {
1177 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1178 Memory.Alignment != 0)
1180 // Only lsl #{0, 1, 2, 3} allowed.
1181 if (Memory.ShiftType == ARM_AM::no_shift)
1183 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1187 bool isMemThumbRR() const {
1188 // Thumb reg+reg addressing is simple. Just two registers, a base and
1189 // an offset. No shifts, negations or any other complicating factors.
1190 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1191 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1193 return isARMLowRegister(Memory.BaseRegNum) &&
1194 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1196 bool isMemThumbRIs4() const {
1197 if (!isMem() || Memory.OffsetRegNum != 0 ||
1198 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1200 // Immediate offset, multiple of 4 in range [0, 124].
1201 if (!Memory.OffsetImm) return true;
1202 int64_t Val = Memory.OffsetImm->getValue();
1203 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1205 bool isMemThumbRIs2() const {
1206 if (!isMem() || Memory.OffsetRegNum != 0 ||
1207 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1209 // Immediate offset, multiple of 4 in range [0, 62].
1210 if (!Memory.OffsetImm) return true;
1211 int64_t Val = Memory.OffsetImm->getValue();
1212 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1214 bool isMemThumbRIs1() const {
1215 if (!isMem() || Memory.OffsetRegNum != 0 ||
1216 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1218 // Immediate offset in range [0, 31].
1219 if (!Memory.OffsetImm) return true;
1220 int64_t Val = Memory.OffsetImm->getValue();
1221 return Val >= 0 && Val <= 31;
1223 bool isMemThumbSPI() const {
1224 if (!isMem() || Memory.OffsetRegNum != 0 ||
1225 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1227 // Immediate offset, multiple of 4 in range [0, 1020].
1228 if (!Memory.OffsetImm) return true;
1229 int64_t Val = Memory.OffsetImm->getValue();
1230 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1232 bool isMemImm8s4Offset() const {
1233 // If we have an immediate that's not a constant, treat it as a label
1234 // reference needing a fixup. If it is a constant, it's something else
1235 // and we reject it.
1236 if (isImm() && !isa<MCConstantExpr>(getImm()))
1238 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1240 // Immediate offset a multiple of 4 in range [-1020, 1020].
1241 if (!Memory.OffsetImm) return true;
1242 int64_t Val = Memory.OffsetImm->getValue();
1243 // Special case, #-0 is INT32_MIN.
1244 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1246 bool isMemImm0_1020s4Offset() const {
1247 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1249 // Immediate offset a multiple of 4 in range [0, 1020].
1250 if (!Memory.OffsetImm) return true;
1251 int64_t Val = Memory.OffsetImm->getValue();
1252 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1254 bool isMemImm8Offset() const {
1255 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1257 // Base reg of PC isn't allowed for these encodings.
1258 if (Memory.BaseRegNum == ARM::PC) return false;
1259 // Immediate offset in range [-255, 255].
1260 if (!Memory.OffsetImm) return true;
1261 int64_t Val = Memory.OffsetImm->getValue();
1262 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1264 bool isMemPosImm8Offset() const {
1265 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1267 // Immediate offset in range [0, 255].
1268 if (!Memory.OffsetImm) return true;
1269 int64_t Val = Memory.OffsetImm->getValue();
1270 return Val >= 0 && Val < 256;
1272 bool isMemNegImm8Offset() const {
1273 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1275 // Base reg of PC isn't allowed for these encodings.
1276 if (Memory.BaseRegNum == ARM::PC) return false;
1277 // Immediate offset in range [-255, -1].
1278 if (!Memory.OffsetImm) return false;
1279 int64_t Val = Memory.OffsetImm->getValue();
1280 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1282 bool isMemUImm12Offset() const {
1283 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1285 // Immediate offset in range [0, 4095].
1286 if (!Memory.OffsetImm) return true;
1287 int64_t Val = Memory.OffsetImm->getValue();
1288 return (Val >= 0 && Val < 4096);
1290 bool isMemImm12Offset() const {
1291 // If we have an immediate that's not a constant, treat it as a label
1292 // reference needing a fixup. If it is a constant, it's something else
1293 // and we reject it.
1294 if (isImm() && !isa<MCConstantExpr>(getImm()))
1297 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1299 // Immediate offset in range [-4095, 4095].
1300 if (!Memory.OffsetImm) return true;
1301 int64_t Val = Memory.OffsetImm->getValue();
1302 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1304 bool isPostIdxImm8() const {
1305 if (!isImm()) return false;
1306 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1307 if (!CE) return false;
1308 int64_t Val = CE->getValue();
1309 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1311 bool isPostIdxImm8s4() const {
1312 if (!isImm()) return false;
1313 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1314 if (!CE) return false;
1315 int64_t Val = CE->getValue();
1316 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1320 bool isMSRMask() const { return Kind == k_MSRMask; }
1321 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1324 bool isSingleSpacedVectorList() const {
1325 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1327 bool isDoubleSpacedVectorList() const {
1328 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1330 bool isVecListOneD() const {
1331 if (!isSingleSpacedVectorList()) return false;
1332 return VectorList.Count == 1;
1335 bool isVecListDPair() const {
1336 if (!isSingleSpacedVectorList()) return false;
1337 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1338 .contains(VectorList.RegNum));
1341 bool isVecListThreeD() const {
1342 if (!isSingleSpacedVectorList()) return false;
1343 return VectorList.Count == 3;
1346 bool isVecListFourD() const {
1347 if (!isSingleSpacedVectorList()) return false;
1348 return VectorList.Count == 4;
1351 bool isVecListDPairSpaced() const {
1352 if (isSingleSpacedVectorList()) return false;
1353 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1354 .contains(VectorList.RegNum));
1357 bool isVecListThreeQ() const {
1358 if (!isDoubleSpacedVectorList()) return false;
1359 return VectorList.Count == 3;
1362 bool isVecListFourQ() const {
1363 if (!isDoubleSpacedVectorList()) return false;
1364 return VectorList.Count == 4;
1367 bool isSingleSpacedVectorAllLanes() const {
1368 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1370 bool isDoubleSpacedVectorAllLanes() const {
1371 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1373 bool isVecListOneDAllLanes() const {
1374 if (!isSingleSpacedVectorAllLanes()) return false;
1375 return VectorList.Count == 1;
1378 bool isVecListDPairAllLanes() const {
1379 if (!isSingleSpacedVectorAllLanes()) return false;
1380 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1381 .contains(VectorList.RegNum));
1384 bool isVecListDPairSpacedAllLanes() const {
1385 if (!isDoubleSpacedVectorAllLanes()) return false;
1386 return VectorList.Count == 2;
1389 bool isVecListThreeDAllLanes() const {
1390 if (!isSingleSpacedVectorAllLanes()) return false;
1391 return VectorList.Count == 3;
1394 bool isVecListThreeQAllLanes() const {
1395 if (!isDoubleSpacedVectorAllLanes()) return false;
1396 return VectorList.Count == 3;
1399 bool isVecListFourDAllLanes() const {
1400 if (!isSingleSpacedVectorAllLanes()) return false;
1401 return VectorList.Count == 4;
1404 bool isVecListFourQAllLanes() const {
1405 if (!isDoubleSpacedVectorAllLanes()) return false;
1406 return VectorList.Count == 4;
1409 bool isSingleSpacedVectorIndexed() const {
1410 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1412 bool isDoubleSpacedVectorIndexed() const {
1413 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1415 bool isVecListOneDByteIndexed() const {
1416 if (!isSingleSpacedVectorIndexed()) return false;
1417 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1420 bool isVecListOneDHWordIndexed() const {
1421 if (!isSingleSpacedVectorIndexed()) return false;
1422 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1425 bool isVecListOneDWordIndexed() const {
1426 if (!isSingleSpacedVectorIndexed()) return false;
1427 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1430 bool isVecListTwoDByteIndexed() const {
1431 if (!isSingleSpacedVectorIndexed()) return false;
1432 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1435 bool isVecListTwoDHWordIndexed() const {
1436 if (!isSingleSpacedVectorIndexed()) return false;
1437 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1440 bool isVecListTwoQWordIndexed() const {
1441 if (!isDoubleSpacedVectorIndexed()) return false;
1442 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1445 bool isVecListTwoQHWordIndexed() const {
1446 if (!isDoubleSpacedVectorIndexed()) return false;
1447 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1450 bool isVecListTwoDWordIndexed() const {
1451 if (!isSingleSpacedVectorIndexed()) return false;
1452 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1455 bool isVecListThreeDByteIndexed() const {
1456 if (!isSingleSpacedVectorIndexed()) return false;
1457 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1460 bool isVecListThreeDHWordIndexed() const {
1461 if (!isSingleSpacedVectorIndexed()) return false;
1462 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1465 bool isVecListThreeQWordIndexed() const {
1466 if (!isDoubleSpacedVectorIndexed()) return false;
1467 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1470 bool isVecListThreeQHWordIndexed() const {
1471 if (!isDoubleSpacedVectorIndexed()) return false;
1472 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1475 bool isVecListThreeDWordIndexed() const {
1476 if (!isSingleSpacedVectorIndexed()) return false;
1477 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1480 bool isVecListFourDByteIndexed() const {
1481 if (!isSingleSpacedVectorIndexed()) return false;
1482 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1485 bool isVecListFourDHWordIndexed() const {
1486 if (!isSingleSpacedVectorIndexed()) return false;
1487 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1490 bool isVecListFourQWordIndexed() const {
1491 if (!isDoubleSpacedVectorIndexed()) return false;
1492 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1495 bool isVecListFourQHWordIndexed() const {
1496 if (!isDoubleSpacedVectorIndexed()) return false;
1497 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1500 bool isVecListFourDWordIndexed() const {
1501 if (!isSingleSpacedVectorIndexed()) return false;
1502 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1505 bool isVectorIndex8() const {
1506 if (Kind != k_VectorIndex) return false;
1507 return VectorIndex.Val < 8;
1509 bool isVectorIndex16() const {
1510 if (Kind != k_VectorIndex) return false;
1511 return VectorIndex.Val < 4;
1513 bool isVectorIndex32() const {
1514 if (Kind != k_VectorIndex) return false;
1515 return VectorIndex.Val < 2;
1518 bool isNEONi8splat() const {
1519 if (!isImm()) return false;
1520 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1521 // Must be a constant.
1522 if (!CE) return false;
1523 int64_t Value = CE->getValue();
1524 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1526 return Value >= 0 && Value < 256;
1529 bool isNEONi16splat() const {
1530 if (!isImm()) return false;
1531 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1532 // Must be a constant.
1533 if (!CE) return false;
1534 int64_t Value = CE->getValue();
1535 // i16 value in the range [0,255] or [0x0100, 0xff00]
1536 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1539 bool isNEONi32splat() const {
1540 if (!isImm()) return false;
1541 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1542 // Must be a constant.
1543 if (!CE) return false;
1544 int64_t Value = CE->getValue();
1545 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1546 return (Value >= 0 && Value < 256) ||
1547 (Value >= 0x0100 && Value <= 0xff00) ||
1548 (Value >= 0x010000 && Value <= 0xff0000) ||
1549 (Value >= 0x01000000 && Value <= 0xff000000);
1552 bool isNEONi32vmov() const {
1553 if (!isImm()) return false;
1554 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1555 // Must be a constant.
1556 if (!CE) return false;
1557 int64_t Value = CE->getValue();
1558 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1559 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1560 return (Value >= 0 && Value < 256) ||
1561 (Value >= 0x0100 && Value <= 0xff00) ||
1562 (Value >= 0x010000 && Value <= 0xff0000) ||
1563 (Value >= 0x01000000 && Value <= 0xff000000) ||
1564 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1565 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1567 bool isNEONi32vmovNeg() const {
1568 if (!isImm()) return false;
1569 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1570 // Must be a constant.
1571 if (!CE) return false;
1572 int64_t Value = ~CE->getValue();
1573 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1574 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1575 return (Value >= 0 && Value < 256) ||
1576 (Value >= 0x0100 && Value <= 0xff00) ||
1577 (Value >= 0x010000 && Value <= 0xff0000) ||
1578 (Value >= 0x01000000 && Value <= 0xff000000) ||
1579 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1580 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1583 bool isNEONi64splat() const {
1584 if (!isImm()) return false;
1585 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1586 // Must be a constant.
1587 if (!CE) return false;
1588 uint64_t Value = CE->getValue();
1589 // i64 value with each byte being either 0 or 0xff.
1590 for (unsigned i = 0; i < 8; ++i)
1591 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1595 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1596 // Add as immediates when possible. Null MCExpr = 0.
1598 Inst.addOperand(MCOperand::CreateImm(0));
1599 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1600 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1602 Inst.addOperand(MCOperand::CreateExpr(Expr));
1605 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1606 assert(N == 2 && "Invalid number of operands!");
1607 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1608 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1609 Inst.addOperand(MCOperand::CreateReg(RegNum));
1612 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1613 assert(N == 1 && "Invalid number of operands!");
1614 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1617 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1618 assert(N == 1 && "Invalid number of operands!");
1619 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1622 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1623 assert(N == 1 && "Invalid number of operands!");
1624 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1627 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1632 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1637 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
1639 Inst.addOperand(MCOperand::CreateReg(getReg()));
1642 void addRegOperands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 Inst.addOperand(MCOperand::CreateReg(getReg()));
1647 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1648 assert(N == 3 && "Invalid number of operands!");
1649 assert(isRegShiftedReg() &&
1650 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1651 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1652 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1653 Inst.addOperand(MCOperand::CreateImm(
1654 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1657 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 2 && "Invalid number of operands!");
1659 assert(isRegShiftedImm() &&
1660 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1661 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1662 // Shift of #32 is encoded as 0 where permitted
1663 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1664 Inst.addOperand(MCOperand::CreateImm(
1665 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1668 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1669 assert(N == 1 && "Invalid number of operands!");
1670 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1674 void addRegListOperands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 const SmallVectorImpl<unsigned> &RegList = getRegList();
1677 for (SmallVectorImpl<unsigned>::const_iterator
1678 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1679 Inst.addOperand(MCOperand::CreateReg(*I));
1682 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1683 addRegListOperands(Inst, N);
1686 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1687 addRegListOperands(Inst, N);
1690 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1691 assert(N == 1 && "Invalid number of operands!");
1692 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1693 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1696 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1697 assert(N == 1 && "Invalid number of operands!");
1698 // Munge the lsb/width into a bitfield mask.
1699 unsigned lsb = Bitfield.LSB;
1700 unsigned width = Bitfield.Width;
1701 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1702 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1703 (32 - (lsb + width)));
1704 Inst.addOperand(MCOperand::CreateImm(Mask));
1707 void addImmOperands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 addExpr(Inst, getImm());
1712 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1713 assert(N == 1 && "Invalid number of operands!");
1714 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1715 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1718 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1721 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1724 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1725 assert(N == 1 && "Invalid number of operands!");
1726 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1727 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1728 Inst.addOperand(MCOperand::CreateImm(Val));
1731 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1732 assert(N == 1 && "Invalid number of operands!");
1733 // FIXME: We really want to scale the value here, but the LDRD/STRD
1734 // instruction don't encode operands that way yet.
1735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1736 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1739 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1740 assert(N == 1 && "Invalid number of operands!");
1741 // The immediate is scaled by four in the encoding and is stored
1742 // in the MCInst as such. Lop off the low two bits here.
1743 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1744 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1747 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1748 assert(N == 1 && "Invalid number of operands!");
1749 // The immediate is scaled by four in the encoding and is stored
1750 // in the MCInst as such. Lop off the low two bits here.
1751 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1752 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1755 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1756 assert(N == 1 && "Invalid number of operands!");
1757 // The immediate is scaled by four in the encoding and is stored
1758 // in the MCInst as such. Lop off the low two bits here.
1759 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1760 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1763 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1764 assert(N == 1 && "Invalid number of operands!");
1765 // The constant encodes as the immediate-1, and we store in the instruction
1766 // the bits as encoded, so subtract off one here.
1767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1768 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1771 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1772 assert(N == 1 && "Invalid number of operands!");
1773 // The constant encodes as the immediate-1, and we store in the instruction
1774 // the bits as encoded, so subtract off one here.
1775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1776 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1779 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1780 assert(N == 1 && "Invalid number of operands!");
1781 // The constant encodes as the immediate, except for 32, which encodes as
1783 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1784 unsigned Imm = CE->getValue();
1785 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1788 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1789 assert(N == 1 && "Invalid number of operands!");
1790 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1791 // the instruction as well.
1792 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1793 int Val = CE->getValue();
1794 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1797 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 1 && "Invalid number of operands!");
1799 // The operand is actually a t2_so_imm, but we have its bitwise
1800 // negation in the assembly source, so twiddle it here.
1801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1802 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1805 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1806 assert(N == 1 && "Invalid number of operands!");
1807 // The operand is actually a t2_so_imm, but we have its
1808 // negation in the assembly source, so twiddle it here.
1809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1810 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1813 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1814 assert(N == 1 && "Invalid number of operands!");
1815 // The operand is actually an imm0_4095, but we have its
1816 // negation in the assembly source, so twiddle it here.
1817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1818 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1821 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1822 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1823 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1827 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1828 assert(SR && "Unknown value type!");
1829 Inst.addOperand(MCOperand::CreateExpr(SR));
1832 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1833 assert(N == 1 && "Invalid number of operands!");
1835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1837 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1841 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1842 assert(SR && "Unknown value type!");
1843 Inst.addOperand(MCOperand::CreateExpr(SR));
1847 assert(isMem() && "Unknown value type!");
1848 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1849 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1852 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1853 assert(N == 1 && "Invalid number of operands!");
1854 // The operand is actually a so_imm, but we have its bitwise
1855 // negation in the assembly source, so twiddle it here.
1856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1857 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1860 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1861 assert(N == 1 && "Invalid number of operands!");
1862 // The operand is actually a so_imm, but we have its
1863 // negation in the assembly source, so twiddle it here.
1864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1865 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1868 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1869 assert(N == 1 && "Invalid number of operands!");
1870 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1873 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1874 assert(N == 1 && "Invalid number of operands!");
1875 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1878 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1879 assert(N == 1 && "Invalid number of operands!");
1880 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1883 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1884 assert(N == 1 && "Invalid number of operands!");
1885 int32_t Imm = Memory.OffsetImm->getValue();
1886 Inst.addOperand(MCOperand::CreateImm(Imm));
1889 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1890 assert(N == 1 && "Invalid number of operands!");
1891 assert(isImm() && "Not an immediate!");
1893 // If we have an immediate that's not a constant, treat it as a label
1894 // reference needing a fixup.
1895 if (!isa<MCConstantExpr>(getImm())) {
1896 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1901 int Val = CE->getValue();
1902 Inst.addOperand(MCOperand::CreateImm(Val));
1905 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1906 assert(N == 2 && "Invalid number of operands!");
1907 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1908 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1911 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1912 assert(N == 3 && "Invalid number of operands!");
1913 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1914 if (!Memory.OffsetRegNum) {
1915 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1916 // Special case for #-0
1917 if (Val == INT32_MIN) Val = 0;
1918 if (Val < 0) Val = -Val;
1919 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1921 // For register offset, we encode the shift type and negation flag
1923 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1924 Memory.ShiftImm, Memory.ShiftType);
1926 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1927 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1928 Inst.addOperand(MCOperand::CreateImm(Val));
1931 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1932 assert(N == 2 && "Invalid number of operands!");
1933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1934 assert(CE && "non-constant AM2OffsetImm operand!");
1935 int32_t Val = CE->getValue();
1936 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1937 // Special case for #-0
1938 if (Val == INT32_MIN) Val = 0;
1939 if (Val < 0) Val = -Val;
1940 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1941 Inst.addOperand(MCOperand::CreateReg(0));
1942 Inst.addOperand(MCOperand::CreateImm(Val));
1945 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1946 assert(N == 3 && "Invalid number of operands!");
1947 // If we have an immediate that's not a constant, treat it as a label
1948 // reference needing a fixup. If it is a constant, it's something else
1949 // and we reject it.
1951 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1952 Inst.addOperand(MCOperand::CreateReg(0));
1953 Inst.addOperand(MCOperand::CreateImm(0));
1957 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1958 if (!Memory.OffsetRegNum) {
1959 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1960 // Special case for #-0
1961 if (Val == INT32_MIN) Val = 0;
1962 if (Val < 0) Val = -Val;
1963 Val = ARM_AM::getAM3Opc(AddSub, Val);
1965 // For register offset, we encode the shift type and negation flag
1967 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1969 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1970 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1971 Inst.addOperand(MCOperand::CreateImm(Val));
1974 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1975 assert(N == 2 && "Invalid number of operands!");
1976 if (Kind == k_PostIndexRegister) {
1978 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1979 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1980 Inst.addOperand(MCOperand::CreateImm(Val));
1985 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1986 int32_t Val = CE->getValue();
1987 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1988 // Special case for #-0
1989 if (Val == INT32_MIN) Val = 0;
1990 if (Val < 0) Val = -Val;
1991 Val = ARM_AM::getAM3Opc(AddSub, Val);
1992 Inst.addOperand(MCOperand::CreateReg(0));
1993 Inst.addOperand(MCOperand::CreateImm(Val));
1996 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1997 assert(N == 2 && "Invalid number of operands!");
1998 // If we have an immediate that's not a constant, treat it as a label
1999 // reference needing a fixup. If it is a constant, it's something else
2000 // and we reject it.
2002 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2003 Inst.addOperand(MCOperand::CreateImm(0));
2007 // The lower two bits are always zero and as such are not encoded.
2008 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2009 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2010 // Special case for #-0
2011 if (Val == INT32_MIN) Val = 0;
2012 if (Val < 0) Val = -Val;
2013 Val = ARM_AM::getAM5Opc(AddSub, Val);
2014 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2015 Inst.addOperand(MCOperand::CreateImm(Val));
2018 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2019 assert(N == 2 && "Invalid number of operands!");
2020 // If we have an immediate that's not a constant, treat it as a label
2021 // reference needing a fixup. If it is a constant, it's something else
2022 // and we reject it.
2024 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2025 Inst.addOperand(MCOperand::CreateImm(0));
2029 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2030 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2031 Inst.addOperand(MCOperand::CreateImm(Val));
2034 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2035 assert(N == 2 && "Invalid number of operands!");
2036 // The lower two bits are always zero and as such are not encoded.
2037 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2038 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2039 Inst.addOperand(MCOperand::CreateImm(Val));
2042 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2043 assert(N == 2 && "Invalid number of operands!");
2044 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2045 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2046 Inst.addOperand(MCOperand::CreateImm(Val));
2049 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2050 addMemImm8OffsetOperands(Inst, N);
2053 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2054 addMemImm8OffsetOperands(Inst, N);
2057 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2058 assert(N == 2 && "Invalid number of operands!");
2059 // If this is an immediate, it's a label reference.
2061 addExpr(Inst, getImm());
2062 Inst.addOperand(MCOperand::CreateImm(0));
2066 // Otherwise, it's a normal memory reg+offset.
2067 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2068 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2069 Inst.addOperand(MCOperand::CreateImm(Val));
2072 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2073 assert(N == 2 && "Invalid number of operands!");
2074 // If this is an immediate, it's a label reference.
2076 addExpr(Inst, getImm());
2077 Inst.addOperand(MCOperand::CreateImm(0));
2081 // Otherwise, it's a normal memory reg+offset.
2082 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2083 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2084 Inst.addOperand(MCOperand::CreateImm(Val));
2087 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2088 assert(N == 2 && "Invalid number of operands!");
2089 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2090 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2093 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2094 assert(N == 2 && "Invalid number of operands!");
2095 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2096 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2099 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2100 assert(N == 3 && "Invalid number of operands!");
2102 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2103 Memory.ShiftImm, Memory.ShiftType);
2104 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2105 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2106 Inst.addOperand(MCOperand::CreateImm(Val));
2109 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2110 assert(N == 3 && "Invalid number of operands!");
2111 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2112 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2113 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2116 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2117 assert(N == 2 && "Invalid number of operands!");
2118 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2119 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2122 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2123 assert(N == 2 && "Invalid number of operands!");
2124 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2125 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2126 Inst.addOperand(MCOperand::CreateImm(Val));
2129 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2130 assert(N == 2 && "Invalid number of operands!");
2131 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2132 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2133 Inst.addOperand(MCOperand::CreateImm(Val));
2136 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2137 assert(N == 2 && "Invalid number of operands!");
2138 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2139 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2140 Inst.addOperand(MCOperand::CreateImm(Val));
2143 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2144 assert(N == 2 && "Invalid number of operands!");
2145 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2146 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2147 Inst.addOperand(MCOperand::CreateImm(Val));
2150 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2151 assert(N == 1 && "Invalid number of operands!");
2152 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2153 assert(CE && "non-constant post-idx-imm8 operand!");
2154 int Imm = CE->getValue();
2155 bool isAdd = Imm >= 0;
2156 if (Imm == INT32_MIN) Imm = 0;
2157 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2158 Inst.addOperand(MCOperand::CreateImm(Imm));
2161 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2162 assert(N == 1 && "Invalid number of operands!");
2163 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2164 assert(CE && "non-constant post-idx-imm8s4 operand!");
2165 int Imm = CE->getValue();
2166 bool isAdd = Imm >= 0;
2167 if (Imm == INT32_MIN) Imm = 0;
2168 // Immediate is scaled by 4.
2169 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2170 Inst.addOperand(MCOperand::CreateImm(Imm));
2173 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2174 assert(N == 2 && "Invalid number of operands!");
2175 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2176 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2179 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2180 assert(N == 2 && "Invalid number of operands!");
2181 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2182 // The sign, shift type, and shift amount are encoded in a single operand
2183 // using the AM2 encoding helpers.
2184 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2185 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2186 PostIdxReg.ShiftTy);
2187 Inst.addOperand(MCOperand::CreateImm(Imm));
2190 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2191 assert(N == 1 && "Invalid number of operands!");
2192 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2195 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2196 assert(N == 1 && "Invalid number of operands!");
2197 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2200 void addVecListOperands(MCInst &Inst, unsigned N) const {
2201 assert(N == 1 && "Invalid number of operands!");
2202 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2205 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2206 assert(N == 2 && "Invalid number of operands!");
2207 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2208 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2211 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2212 assert(N == 1 && "Invalid number of operands!");
2213 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2216 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2217 assert(N == 1 && "Invalid number of operands!");
2218 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2221 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2222 assert(N == 1 && "Invalid number of operands!");
2223 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2226 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2227 assert(N == 1 && "Invalid number of operands!");
2228 // The immediate encodes the type of constant as well as the value.
2229 // Mask in that this is an i8 splat.
2230 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2231 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2234 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2235 assert(N == 1 && "Invalid number of operands!");
2236 // The immediate encodes the type of constant as well as the value.
2237 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2238 unsigned Value = CE->getValue();
2240 Value = (Value >> 8) | 0xa00;
2243 Inst.addOperand(MCOperand::CreateImm(Value));
2246 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2247 assert(N == 1 && "Invalid number of operands!");
2248 // The immediate encodes the type of constant as well as the value.
2249 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2250 unsigned Value = CE->getValue();
2251 if (Value >= 256 && Value <= 0xff00)
2252 Value = (Value >> 8) | 0x200;
2253 else if (Value > 0xffff && Value <= 0xff0000)
2254 Value = (Value >> 16) | 0x400;
2255 else if (Value > 0xffffff)
2256 Value = (Value >> 24) | 0x600;
2257 Inst.addOperand(MCOperand::CreateImm(Value));
2260 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2261 assert(N == 1 && "Invalid number of operands!");
2262 // The immediate encodes the type of constant as well as the value.
2263 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2264 unsigned Value = CE->getValue();
2265 if (Value >= 256 && Value <= 0xffff)
2266 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2267 else if (Value > 0xffff && Value <= 0xffffff)
2268 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2269 else if (Value > 0xffffff)
2270 Value = (Value >> 24) | 0x600;
2271 Inst.addOperand(MCOperand::CreateImm(Value));
2274 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2275 assert(N == 1 && "Invalid number of operands!");
2276 // The immediate encodes the type of constant as well as the value.
2277 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2278 unsigned Value = ~CE->getValue();
2279 if (Value >= 256 && Value <= 0xffff)
2280 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2281 else if (Value > 0xffff && Value <= 0xffffff)
2282 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2283 else if (Value > 0xffffff)
2284 Value = (Value >> 24) | 0x600;
2285 Inst.addOperand(MCOperand::CreateImm(Value));
2288 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2289 assert(N == 1 && "Invalid number of operands!");
2290 // The immediate encodes the type of constant as well as the value.
2291 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2292 uint64_t Value = CE->getValue();
2294 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2295 Imm |= (Value & 1) << i;
2297 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2300 virtual void print(raw_ostream &OS) const;
2302 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2303 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2304 Op->ITMask.Mask = Mask;
2310 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2311 ARMOperand *Op = new ARMOperand(k_CondCode);
2318 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2319 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2320 Op->Cop.Val = CopVal;
2326 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2327 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2328 Op->Cop.Val = CopVal;
2334 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2335 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2342 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2343 ARMOperand *Op = new ARMOperand(k_CCOut);
2344 Op->Reg.RegNum = RegNum;
2350 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2351 ARMOperand *Op = new ARMOperand(k_Token);
2352 Op->Tok.Data = Str.data();
2353 Op->Tok.Length = Str.size();
2359 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2360 ARMOperand *Op = new ARMOperand(k_Register);
2361 Op->Reg.RegNum = RegNum;
2367 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2372 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2373 Op->RegShiftedReg.ShiftTy = ShTy;
2374 Op->RegShiftedReg.SrcReg = SrcReg;
2375 Op->RegShiftedReg.ShiftReg = ShiftReg;
2376 Op->RegShiftedReg.ShiftImm = ShiftImm;
2382 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2386 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2387 Op->RegShiftedImm.ShiftTy = ShTy;
2388 Op->RegShiftedImm.SrcReg = SrcReg;
2389 Op->RegShiftedImm.ShiftImm = ShiftImm;
2395 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2397 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2398 Op->ShifterImm.isASR = isASR;
2399 Op->ShifterImm.Imm = Imm;
2405 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2406 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2407 Op->RotImm.Imm = Imm;
2413 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2415 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2416 Op->Bitfield.LSB = LSB;
2417 Op->Bitfield.Width = Width;
2424 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2425 SMLoc StartLoc, SMLoc EndLoc) {
2426 assert (Regs.size() > 0 && "RegList contains no registers?");
2427 KindTy Kind = k_RegisterList;
2429 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2430 Kind = k_DPRRegisterList;
2431 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2432 contains(Regs.front().second))
2433 Kind = k_SPRRegisterList;
2435 // Sort based on the register encoding values.
2436 array_pod_sort(Regs.begin(), Regs.end());
2438 ARMOperand *Op = new ARMOperand(Kind);
2439 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2440 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2441 Op->Registers.push_back(I->second);
2442 Op->StartLoc = StartLoc;
2443 Op->EndLoc = EndLoc;
2447 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2448 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2449 ARMOperand *Op = new ARMOperand(k_VectorList);
2450 Op->VectorList.RegNum = RegNum;
2451 Op->VectorList.Count = Count;
2452 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2458 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2459 bool isDoubleSpaced,
2461 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2462 Op->VectorList.RegNum = RegNum;
2463 Op->VectorList.Count = Count;
2464 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2470 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2472 bool isDoubleSpaced,
2474 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2475 Op->VectorList.RegNum = RegNum;
2476 Op->VectorList.Count = Count;
2477 Op->VectorList.LaneIndex = Index;
2478 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2484 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2486 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2487 Op->VectorIndex.Val = Idx;
2493 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2494 ARMOperand *Op = new ARMOperand(k_Immediate);
2501 static ARMOperand *CreateMem(unsigned BaseRegNum,
2502 const MCConstantExpr *OffsetImm,
2503 unsigned OffsetRegNum,
2504 ARM_AM::ShiftOpc ShiftType,
2509 ARMOperand *Op = new ARMOperand(k_Memory);
2510 Op->Memory.BaseRegNum = BaseRegNum;
2511 Op->Memory.OffsetImm = OffsetImm;
2512 Op->Memory.OffsetRegNum = OffsetRegNum;
2513 Op->Memory.ShiftType = ShiftType;
2514 Op->Memory.ShiftImm = ShiftImm;
2515 Op->Memory.Alignment = Alignment;
2516 Op->Memory.isNegative = isNegative;
2522 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2523 ARM_AM::ShiftOpc ShiftTy,
2526 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2527 Op->PostIdxReg.RegNum = RegNum;
2528 Op->PostIdxReg.isAdd = isAdd;
2529 Op->PostIdxReg.ShiftTy = ShiftTy;
2530 Op->PostIdxReg.ShiftImm = ShiftImm;
2536 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2537 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2538 Op->MBOpt.Val = Opt;
2544 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2546 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2547 Op->ISBOpt.Val = Opt;
2553 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2554 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2555 Op->IFlags.Val = IFlags;
2561 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2562 ARMOperand *Op = new ARMOperand(k_MSRMask);
2563 Op->MMask.Val = MMask;
2570 } // end anonymous namespace.
2572 void ARMOperand::print(raw_ostream &OS) const {
2575 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2578 OS << "<ccout " << getReg() << ">";
2580 case k_ITCondMask: {
2581 static const char *const MaskStr[] = {
2582 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2583 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2585 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2586 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2590 OS << "<coprocessor number: " << getCoproc() << ">";
2593 OS << "<coprocessor register: " << getCoproc() << ">";
2595 case k_CoprocOption:
2596 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2599 OS << "<mask: " << getMSRMask() << ">";
2602 getImm()->print(OS);
2604 case k_MemBarrierOpt:
2605 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2607 case k_InstSyncBarrierOpt:
2608 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2612 << " base:" << Memory.BaseRegNum;
2615 case k_PostIndexRegister:
2616 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2617 << PostIdxReg.RegNum;
2618 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2619 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2620 << PostIdxReg.ShiftImm;
2623 case k_ProcIFlags: {
2624 OS << "<ARM_PROC::";
2625 unsigned IFlags = getProcIFlags();
2626 for (int i=2; i >= 0; --i)
2627 if (IFlags & (1 << i))
2628 OS << ARM_PROC::IFlagsToString(1 << i);
2633 OS << "<register " << getReg() << ">";
2635 case k_ShifterImmediate:
2636 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2637 << " #" << ShifterImm.Imm << ">";
2639 case k_ShiftedRegister:
2640 OS << "<so_reg_reg "
2641 << RegShiftedReg.SrcReg << " "
2642 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2643 << " " << RegShiftedReg.ShiftReg << ">";
2645 case k_ShiftedImmediate:
2646 OS << "<so_reg_imm "
2647 << RegShiftedImm.SrcReg << " "
2648 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2649 << " #" << RegShiftedImm.ShiftImm << ">";
2651 case k_RotateImmediate:
2652 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2654 case k_BitfieldDescriptor:
2655 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2656 << ", width: " << Bitfield.Width << ">";
2658 case k_RegisterList:
2659 case k_DPRRegisterList:
2660 case k_SPRRegisterList: {
2661 OS << "<register_list ";
2663 const SmallVectorImpl<unsigned> &RegList = getRegList();
2664 for (SmallVectorImpl<unsigned>::const_iterator
2665 I = RegList.begin(), E = RegList.end(); I != E; ) {
2667 if (++I < E) OS << ", ";
2674 OS << "<vector_list " << VectorList.Count << " * "
2675 << VectorList.RegNum << ">";
2677 case k_VectorListAllLanes:
2678 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2679 << VectorList.RegNum << ">";
2681 case k_VectorListIndexed:
2682 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2683 << VectorList.Count << " * " << VectorList.RegNum << ">";
2686 OS << "'" << getToken() << "'";
2689 OS << "<vectorindex " << getVectorIndex() << ">";
2694 /// @name Auto-generated Match Functions
2697 static unsigned MatchRegisterName(StringRef Name);
2701 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2702 SMLoc &StartLoc, SMLoc &EndLoc) {
2703 StartLoc = Parser.getTok().getLoc();
2704 EndLoc = Parser.getTok().getEndLoc();
2705 RegNo = tryParseRegister();
2707 return (RegNo == (unsigned)-1);
2710 /// Try to parse a register name. The token must be an Identifier when called,
2711 /// and if it is a register name the token is eaten and the register number is
2712 /// returned. Otherwise return -1.
2714 int ARMAsmParser::tryParseRegister() {
2715 const AsmToken &Tok = Parser.getTok();
2716 if (Tok.isNot(AsmToken::Identifier)) return -1;
2718 std::string lowerCase = Tok.getString().lower();
2719 unsigned RegNum = MatchRegisterName(lowerCase);
2721 RegNum = StringSwitch<unsigned>(lowerCase)
2722 .Case("r13", ARM::SP)
2723 .Case("r14", ARM::LR)
2724 .Case("r15", ARM::PC)
2725 .Case("ip", ARM::R12)
2726 // Additional register name aliases for 'gas' compatibility.
2727 .Case("a1", ARM::R0)
2728 .Case("a2", ARM::R1)
2729 .Case("a3", ARM::R2)
2730 .Case("a4", ARM::R3)
2731 .Case("v1", ARM::R4)
2732 .Case("v2", ARM::R5)
2733 .Case("v3", ARM::R6)
2734 .Case("v4", ARM::R7)
2735 .Case("v5", ARM::R8)
2736 .Case("v6", ARM::R9)
2737 .Case("v7", ARM::R10)
2738 .Case("v8", ARM::R11)
2739 .Case("sb", ARM::R9)
2740 .Case("sl", ARM::R10)
2741 .Case("fp", ARM::R11)
2745 // Check for aliases registered via .req. Canonicalize to lower case.
2746 // That's more consistent since register names are case insensitive, and
2747 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2748 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2749 // If no match, return failure.
2750 if (Entry == RegisterReqs.end())
2752 Parser.Lex(); // Eat identifier token.
2753 return Entry->getValue();
2756 Parser.Lex(); // Eat identifier token.
2761 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2762 // If a recoverable error occurs, return 1. If an irrecoverable error
2763 // occurs, return -1. An irrecoverable error is one where tokens have been
2764 // consumed in the process of trying to parse the shifter (i.e., when it is
2765 // indeed a shifter operand, but malformed).
2766 int ARMAsmParser::tryParseShiftRegister(
2767 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2768 SMLoc S = Parser.getTok().getLoc();
2769 const AsmToken &Tok = Parser.getTok();
2770 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2772 std::string lowerCase = Tok.getString().lower();
2773 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2774 .Case("asl", ARM_AM::lsl)
2775 .Case("lsl", ARM_AM::lsl)
2776 .Case("lsr", ARM_AM::lsr)
2777 .Case("asr", ARM_AM::asr)
2778 .Case("ror", ARM_AM::ror)
2779 .Case("rrx", ARM_AM::rrx)
2780 .Default(ARM_AM::no_shift);
2782 if (ShiftTy == ARM_AM::no_shift)
2785 Parser.Lex(); // Eat the operator.
2787 // The source register for the shift has already been added to the
2788 // operand list, so we need to pop it off and combine it into the shifted
2789 // register operand instead.
2790 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2791 if (!PrevOp->isReg())
2792 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2793 int SrcReg = PrevOp->getReg();
2798 if (ShiftTy == ARM_AM::rrx) {
2799 // RRX Doesn't have an explicit shift amount. The encoder expects
2800 // the shift register to be the same as the source register. Seems odd,
2804 // Figure out if this is shifted by a constant or a register (for non-RRX).
2805 if (Parser.getTok().is(AsmToken::Hash) ||
2806 Parser.getTok().is(AsmToken::Dollar)) {
2807 Parser.Lex(); // Eat hash.
2808 SMLoc ImmLoc = Parser.getTok().getLoc();
2809 const MCExpr *ShiftExpr = 0;
2810 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2811 Error(ImmLoc, "invalid immediate shift value");
2814 // The expression must be evaluatable as an immediate.
2815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2817 Error(ImmLoc, "invalid immediate shift value");
2820 // Range check the immediate.
2821 // lsl, ror: 0 <= imm <= 31
2822 // lsr, asr: 0 <= imm <= 32
2823 Imm = CE->getValue();
2825 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2826 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2827 Error(ImmLoc, "immediate shift value out of range");
2830 // shift by zero is a nop. Always send it through as lsl.
2831 // ('as' compatibility)
2833 ShiftTy = ARM_AM::lsl;
2834 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2835 SMLoc L = Parser.getTok().getLoc();
2836 EndLoc = Parser.getTok().getEndLoc();
2837 ShiftReg = tryParseRegister();
2838 if (ShiftReg == -1) {
2839 Error (L, "expected immediate or register in shift operand");
2843 Error (Parser.getTok().getLoc(),
2844 "expected immediate or register in shift operand");
2849 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2850 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2854 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2861 /// Try to parse a register name. The token must be an Identifier when called.
2862 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2863 /// if there is a "writeback". 'true' if it's not a register.
2865 /// TODO this is likely to change to allow different register types and or to
2866 /// parse for a specific register type.
2868 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2869 const AsmToken &RegTok = Parser.getTok();
2870 int RegNo = tryParseRegister();
2874 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2875 RegTok.getEndLoc()));
2877 const AsmToken &ExclaimTok = Parser.getTok();
2878 if (ExclaimTok.is(AsmToken::Exclaim)) {
2879 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2880 ExclaimTok.getLoc()));
2881 Parser.Lex(); // Eat exclaim token
2885 // Also check for an index operand. This is only legal for vector registers,
2886 // but that'll get caught OK in operand matching, so we don't need to
2887 // explicitly filter everything else out here.
2888 if (Parser.getTok().is(AsmToken::LBrac)) {
2889 SMLoc SIdx = Parser.getTok().getLoc();
2890 Parser.Lex(); // Eat left bracket token.
2892 const MCExpr *ImmVal;
2893 if (getParser().parseExpression(ImmVal))
2895 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2897 return TokError("immediate value expected for vector index");
2899 if (Parser.getTok().isNot(AsmToken::RBrac))
2900 return Error(Parser.getTok().getLoc(), "']' expected");
2902 SMLoc E = Parser.getTok().getEndLoc();
2903 Parser.Lex(); // Eat right bracket token.
2905 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2913 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2914 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2916 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2917 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2919 switch (Name.size()) {
2922 if (Name[0] != CoprocOp)
2938 if (Name[0] != CoprocOp || Name[1] != '1')
2942 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2943 case '0': return CoprocOp == 'p'? -1: 10;
2944 case '1': return CoprocOp == 'p'? -1: 11;
2945 case '2': return 12;
2946 case '3': return 13;
2947 case '4': return 14;
2948 case '5': return 15;
2953 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2954 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2955 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2956 SMLoc S = Parser.getTok().getLoc();
2957 const AsmToken &Tok = Parser.getTok();
2958 if (!Tok.is(AsmToken::Identifier))
2959 return MatchOperand_NoMatch;
2960 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2961 .Case("eq", ARMCC::EQ)
2962 .Case("ne", ARMCC::NE)
2963 .Case("hs", ARMCC::HS)
2964 .Case("cs", ARMCC::HS)
2965 .Case("lo", ARMCC::LO)
2966 .Case("cc", ARMCC::LO)
2967 .Case("mi", ARMCC::MI)
2968 .Case("pl", ARMCC::PL)
2969 .Case("vs", ARMCC::VS)
2970 .Case("vc", ARMCC::VC)
2971 .Case("hi", ARMCC::HI)
2972 .Case("ls", ARMCC::LS)
2973 .Case("ge", ARMCC::GE)
2974 .Case("lt", ARMCC::LT)
2975 .Case("gt", ARMCC::GT)
2976 .Case("le", ARMCC::LE)
2977 .Case("al", ARMCC::AL)
2980 return MatchOperand_NoMatch;
2981 Parser.Lex(); // Eat the token.
2983 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2985 return MatchOperand_Success;
2988 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
2989 /// token must be an Identifier when called, and if it is a coprocessor
2990 /// number, the token is eaten and the operand is added to the operand list.
2991 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2992 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2993 SMLoc S = Parser.getTok().getLoc();
2994 const AsmToken &Tok = Parser.getTok();
2995 if (Tok.isNot(AsmToken::Identifier))
2996 return MatchOperand_NoMatch;
2998 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
3000 return MatchOperand_NoMatch;
3002 Parser.Lex(); // Eat identifier token.
3003 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
3004 return MatchOperand_Success;
3007 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
3008 /// token must be an Identifier when called, and if it is a coprocessor
3009 /// number, the token is eaten and the operand is added to the operand list.
3010 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3011 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3012 SMLoc S = Parser.getTok().getLoc();
3013 const AsmToken &Tok = Parser.getTok();
3014 if (Tok.isNot(AsmToken::Identifier))
3015 return MatchOperand_NoMatch;
3017 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3019 return MatchOperand_NoMatch;
3021 Parser.Lex(); // Eat identifier token.
3022 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
3023 return MatchOperand_Success;
3026 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3027 /// coproc_option : '{' imm0_255 '}'
3028 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3029 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3030 SMLoc S = Parser.getTok().getLoc();
3032 // If this isn't a '{', this isn't a coprocessor immediate operand.
3033 if (Parser.getTok().isNot(AsmToken::LCurly))
3034 return MatchOperand_NoMatch;
3035 Parser.Lex(); // Eat the '{'
3038 SMLoc Loc = Parser.getTok().getLoc();
3039 if (getParser().parseExpression(Expr)) {
3040 Error(Loc, "illegal expression");
3041 return MatchOperand_ParseFail;
3043 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3044 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3045 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3046 return MatchOperand_ParseFail;
3048 int Val = CE->getValue();
3050 // Check for and consume the closing '}'
3051 if (Parser.getTok().isNot(AsmToken::RCurly))
3052 return MatchOperand_ParseFail;
3053 SMLoc E = Parser.getTok().getEndLoc();
3054 Parser.Lex(); // Eat the '}'
3056 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3057 return MatchOperand_Success;
3060 // For register list parsing, we need to map from raw GPR register numbering
3061 // to the enumeration values. The enumeration values aren't sorted by
3062 // register number due to our using "sp", "lr" and "pc" as canonical names.
3063 static unsigned getNextRegister(unsigned Reg) {
3064 // If this is a GPR, we need to do it manually, otherwise we can rely
3065 // on the sort ordering of the enumeration since the other reg-classes
3067 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3070 default: llvm_unreachable("Invalid GPR number!");
3071 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3072 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3073 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3074 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3075 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3076 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3077 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3078 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3082 // Return the low-subreg of a given Q register.
3083 static unsigned getDRegFromQReg(unsigned QReg) {
3085 default: llvm_unreachable("expected a Q register!");
3086 case ARM::Q0: return ARM::D0;
3087 case ARM::Q1: return ARM::D2;
3088 case ARM::Q2: return ARM::D4;
3089 case ARM::Q3: return ARM::D6;
3090 case ARM::Q4: return ARM::D8;
3091 case ARM::Q5: return ARM::D10;
3092 case ARM::Q6: return ARM::D12;
3093 case ARM::Q7: return ARM::D14;
3094 case ARM::Q8: return ARM::D16;
3095 case ARM::Q9: return ARM::D18;
3096 case ARM::Q10: return ARM::D20;
3097 case ARM::Q11: return ARM::D22;
3098 case ARM::Q12: return ARM::D24;
3099 case ARM::Q13: return ARM::D26;
3100 case ARM::Q14: return ARM::D28;
3101 case ARM::Q15: return ARM::D30;
3105 /// Parse a register list.
3107 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3108 assert(Parser.getTok().is(AsmToken::LCurly) &&
3109 "Token is not a Left Curly Brace");
3110 SMLoc S = Parser.getTok().getLoc();
3111 Parser.Lex(); // Eat '{' token.
3112 SMLoc RegLoc = Parser.getTok().getLoc();
3114 // Check the first register in the list to see what register class
3115 // this is a list of.
3116 int Reg = tryParseRegister();
3118 return Error(RegLoc, "register expected");
3120 // The reglist instructions have at most 16 registers, so reserve
3121 // space for that many.
3123 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3125 // Allow Q regs and just interpret them as the two D sub-registers.
3126 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3127 Reg = getDRegFromQReg(Reg);
3128 EReg = MRI->getEncodingValue(Reg);
3129 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3132 const MCRegisterClass *RC;
3133 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3134 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3135 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3136 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3137 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3138 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3140 return Error(RegLoc, "invalid register in register list");
3142 // Store the register.
3143 EReg = MRI->getEncodingValue(Reg);
3144 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3146 // This starts immediately after the first register token in the list,
3147 // so we can see either a comma or a minus (range separator) as a legal
3149 while (Parser.getTok().is(AsmToken::Comma) ||
3150 Parser.getTok().is(AsmToken::Minus)) {
3151 if (Parser.getTok().is(AsmToken::Minus)) {
3152 Parser.Lex(); // Eat the minus.
3153 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3154 int EndReg = tryParseRegister();
3156 return Error(AfterMinusLoc, "register expected");
3157 // Allow Q regs and just interpret them as the two D sub-registers.
3158 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3159 EndReg = getDRegFromQReg(EndReg) + 1;
3160 // If the register is the same as the start reg, there's nothing
3164 // The register must be in the same register class as the first.
3165 if (!RC->contains(EndReg))
3166 return Error(AfterMinusLoc, "invalid register in register list");
3167 // Ranges must go from low to high.
3168 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3169 return Error(AfterMinusLoc, "bad range in register list");
3171 // Add all the registers in the range to the register list.
3172 while (Reg != EndReg) {
3173 Reg = getNextRegister(Reg);
3174 EReg = MRI->getEncodingValue(Reg);
3175 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3179 Parser.Lex(); // Eat the comma.
3180 RegLoc = Parser.getTok().getLoc();
3182 const AsmToken RegTok = Parser.getTok();
3183 Reg = tryParseRegister();
3185 return Error(RegLoc, "register expected");
3186 // Allow Q regs and just interpret them as the two D sub-registers.
3187 bool isQReg = false;
3188 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3189 Reg = getDRegFromQReg(Reg);
3192 // The register must be in the same register class as the first.
3193 if (!RC->contains(Reg))
3194 return Error(RegLoc, "invalid register in register list");
3195 // List must be monotonically increasing.
3196 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3197 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3198 Warning(RegLoc, "register list not in ascending order");
3200 return Error(RegLoc, "register list not in ascending order");
3202 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3203 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3204 ") in register list");
3207 // VFP register lists must also be contiguous.
3208 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3210 return Error(RegLoc, "non-contiguous register range");
3211 EReg = MRI->getEncodingValue(Reg);
3212 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3214 EReg = MRI->getEncodingValue(++Reg);
3215 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3219 if (Parser.getTok().isNot(AsmToken::RCurly))
3220 return Error(Parser.getTok().getLoc(), "'}' expected");
3221 SMLoc E = Parser.getTok().getEndLoc();
3222 Parser.Lex(); // Eat '}' token.
3224 // Push the register list operand.
3225 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3227 // The ARM system instruction variants for LDM/STM have a '^' token here.
3228 if (Parser.getTok().is(AsmToken::Caret)) {
3229 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3230 Parser.Lex(); // Eat '^' token.
3236 // Helper function to parse the lane index for vector lists.
3237 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3238 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3239 Index = 0; // Always return a defined index value.
3240 if (Parser.getTok().is(AsmToken::LBrac)) {
3241 Parser.Lex(); // Eat the '['.
3242 if (Parser.getTok().is(AsmToken::RBrac)) {
3243 // "Dn[]" is the 'all lanes' syntax.
3244 LaneKind = AllLanes;
3245 EndLoc = Parser.getTok().getEndLoc();
3246 Parser.Lex(); // Eat the ']'.
3247 return MatchOperand_Success;
3250 // There's an optional '#' token here. Normally there wouldn't be, but
3251 // inline assemble puts one in, and it's friendly to accept that.
3252 if (Parser.getTok().is(AsmToken::Hash))
3253 Parser.Lex(); // Eat '#' or '$'.
3255 const MCExpr *LaneIndex;
3256 SMLoc Loc = Parser.getTok().getLoc();
3257 if (getParser().parseExpression(LaneIndex)) {
3258 Error(Loc, "illegal expression");
3259 return MatchOperand_ParseFail;
3261 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3263 Error(Loc, "lane index must be empty or an integer");
3264 return MatchOperand_ParseFail;
3266 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3267 Error(Parser.getTok().getLoc(), "']' expected");
3268 return MatchOperand_ParseFail;
3270 EndLoc = Parser.getTok().getEndLoc();
3271 Parser.Lex(); // Eat the ']'.
3272 int64_t Val = CE->getValue();
3274 // FIXME: Make this range check context sensitive for .8, .16, .32.
3275 if (Val < 0 || Val > 7) {
3276 Error(Parser.getTok().getLoc(), "lane index out of range");
3277 return MatchOperand_ParseFail;
3280 LaneKind = IndexedLane;
3281 return MatchOperand_Success;
3284 return MatchOperand_Success;
3287 // parse a vector register list
3288 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3289 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3290 VectorLaneTy LaneKind;
3292 SMLoc S = Parser.getTok().getLoc();
3293 // As an extension (to match gas), support a plain D register or Q register
3294 // (without encosing curly braces) as a single or double entry list,
3296 if (Parser.getTok().is(AsmToken::Identifier)) {
3297 SMLoc E = Parser.getTok().getEndLoc();
3298 int Reg = tryParseRegister();
3300 return MatchOperand_NoMatch;
3301 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3302 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3303 if (Res != MatchOperand_Success)
3307 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3310 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3314 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3319 return MatchOperand_Success;
3321 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3322 Reg = getDRegFromQReg(Reg);
3323 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3324 if (Res != MatchOperand_Success)
3328 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3329 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3330 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3333 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3334 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3335 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3339 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3344 return MatchOperand_Success;
3346 Error(S, "vector register expected");
3347 return MatchOperand_ParseFail;
3350 if (Parser.getTok().isNot(AsmToken::LCurly))
3351 return MatchOperand_NoMatch;
3353 Parser.Lex(); // Eat '{' token.
3354 SMLoc RegLoc = Parser.getTok().getLoc();
3356 int Reg = tryParseRegister();
3358 Error(RegLoc, "register expected");
3359 return MatchOperand_ParseFail;
3363 unsigned FirstReg = Reg;
3364 // The list is of D registers, but we also allow Q regs and just interpret
3365 // them as the two D sub-registers.
3366 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3367 FirstReg = Reg = getDRegFromQReg(Reg);
3368 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3369 // it's ambiguous with four-register single spaced.
3375 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3376 return MatchOperand_ParseFail;
3378 while (Parser.getTok().is(AsmToken::Comma) ||
3379 Parser.getTok().is(AsmToken::Minus)) {
3380 if (Parser.getTok().is(AsmToken::Minus)) {
3382 Spacing = 1; // Register range implies a single spaced list.
3383 else if (Spacing == 2) {
3384 Error(Parser.getTok().getLoc(),
3385 "sequential registers in double spaced list");
3386 return MatchOperand_ParseFail;
3388 Parser.Lex(); // Eat the minus.
3389 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3390 int EndReg = tryParseRegister();
3392 Error(AfterMinusLoc, "register expected");
3393 return MatchOperand_ParseFail;
3395 // Allow Q regs and just interpret them as the two D sub-registers.
3396 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3397 EndReg = getDRegFromQReg(EndReg) + 1;
3398 // If the register is the same as the start reg, there's nothing
3402 // The register must be in the same register class as the first.
3403 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3404 Error(AfterMinusLoc, "invalid register in register list");
3405 return MatchOperand_ParseFail;
3407 // Ranges must go from low to high.
3409 Error(AfterMinusLoc, "bad range in register list");
3410 return MatchOperand_ParseFail;
3412 // Parse the lane specifier if present.
3413 VectorLaneTy NextLaneKind;
3414 unsigned NextLaneIndex;
3415 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3416 MatchOperand_Success)
3417 return MatchOperand_ParseFail;
3418 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3419 Error(AfterMinusLoc, "mismatched lane index in register list");
3420 return MatchOperand_ParseFail;
3423 // Add all the registers in the range to the register list.
3424 Count += EndReg - Reg;
3428 Parser.Lex(); // Eat the comma.
3429 RegLoc = Parser.getTok().getLoc();
3431 Reg = tryParseRegister();
3433 Error(RegLoc, "register expected");
3434 return MatchOperand_ParseFail;
3436 // vector register lists must be contiguous.
3437 // It's OK to use the enumeration values directly here rather, as the
3438 // VFP register classes have the enum sorted properly.
3440 // The list is of D registers, but we also allow Q regs and just interpret
3441 // them as the two D sub-registers.
3442 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3444 Spacing = 1; // Register range implies a single spaced list.
3445 else if (Spacing == 2) {
3447 "invalid register in double-spaced list (must be 'D' register')");
3448 return MatchOperand_ParseFail;
3450 Reg = getDRegFromQReg(Reg);
3451 if (Reg != OldReg + 1) {
3452 Error(RegLoc, "non-contiguous register range");
3453 return MatchOperand_ParseFail;
3457 // Parse the lane specifier if present.
3458 VectorLaneTy NextLaneKind;
3459 unsigned NextLaneIndex;
3460 SMLoc LaneLoc = Parser.getTok().getLoc();
3461 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3462 MatchOperand_Success)
3463 return MatchOperand_ParseFail;
3464 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3465 Error(LaneLoc, "mismatched lane index in register list");
3466 return MatchOperand_ParseFail;
3470 // Normal D register.
3471 // Figure out the register spacing (single or double) of the list if
3472 // we don't know it already.
3474 Spacing = 1 + (Reg == OldReg + 2);
3476 // Just check that it's contiguous and keep going.
3477 if (Reg != OldReg + Spacing) {
3478 Error(RegLoc, "non-contiguous register range");
3479 return MatchOperand_ParseFail;
3482 // Parse the lane specifier if present.
3483 VectorLaneTy NextLaneKind;
3484 unsigned NextLaneIndex;
3485 SMLoc EndLoc = Parser.getTok().getLoc();
3486 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3487 return MatchOperand_ParseFail;
3488 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3489 Error(EndLoc, "mismatched lane index in register list");
3490 return MatchOperand_ParseFail;
3494 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3495 Error(Parser.getTok().getLoc(), "'}' expected");
3496 return MatchOperand_ParseFail;
3498 E = Parser.getTok().getEndLoc();
3499 Parser.Lex(); // Eat '}' token.
3503 // Two-register operands have been converted to the
3504 // composite register classes.
3506 const MCRegisterClass *RC = (Spacing == 1) ?
3507 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3508 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3509 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3512 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3513 (Spacing == 2), S, E));
3516 // Two-register operands have been converted to the
3517 // composite register classes.
3519 const MCRegisterClass *RC = (Spacing == 1) ?
3520 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3521 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3522 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3524 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3529 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3535 return MatchOperand_Success;
3538 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3539 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3540 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3541 SMLoc S = Parser.getTok().getLoc();
3542 const AsmToken &Tok = Parser.getTok();
3545 if (Tok.is(AsmToken::Identifier)) {
3546 StringRef OptStr = Tok.getString();
3548 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3549 .Case("sy", ARM_MB::SY)
3550 .Case("st", ARM_MB::ST)
3551 .Case("ld", ARM_MB::LD)
3552 .Case("sh", ARM_MB::ISH)
3553 .Case("ish", ARM_MB::ISH)
3554 .Case("shst", ARM_MB::ISHST)
3555 .Case("ishst", ARM_MB::ISHST)
3556 .Case("ishld", ARM_MB::ISHLD)
3557 .Case("nsh", ARM_MB::NSH)
3558 .Case("un", ARM_MB::NSH)
3559 .Case("nshst", ARM_MB::NSHST)
3560 .Case("nshld", ARM_MB::NSHLD)
3561 .Case("unst", ARM_MB::NSHST)
3562 .Case("osh", ARM_MB::OSH)
3563 .Case("oshst", ARM_MB::OSHST)
3564 .Case("oshld", ARM_MB::OSHLD)
3567 // ishld, oshld, nshld and ld are only available from ARMv8.
3568 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3569 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3573 return MatchOperand_NoMatch;
3575 Parser.Lex(); // Eat identifier token.
3576 } else if (Tok.is(AsmToken::Hash) ||
3577 Tok.is(AsmToken::Dollar) ||
3578 Tok.is(AsmToken::Integer)) {
3579 if (Parser.getTok().isNot(AsmToken::Integer))
3580 Parser.Lex(); // Eat '#' or '$'.
3581 SMLoc Loc = Parser.getTok().getLoc();
3583 const MCExpr *MemBarrierID;
3584 if (getParser().parseExpression(MemBarrierID)) {
3585 Error(Loc, "illegal expression");
3586 return MatchOperand_ParseFail;
3589 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3591 Error(Loc, "constant expression expected");
3592 return MatchOperand_ParseFail;
3595 int Val = CE->getValue();
3597 Error(Loc, "immediate value out of range");
3598 return MatchOperand_ParseFail;
3601 Opt = ARM_MB::RESERVED_0 + Val;
3603 return MatchOperand_ParseFail;
3605 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3606 return MatchOperand_Success;
3609 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3610 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3611 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3612 SMLoc S = Parser.getTok().getLoc();
3613 const AsmToken &Tok = Parser.getTok();
3616 if (Tok.is(AsmToken::Identifier)) {
3617 StringRef OptStr = Tok.getString();
3619 if (OptStr.equals_lower("sy"))
3622 return MatchOperand_NoMatch;
3624 Parser.Lex(); // Eat identifier token.
3625 } else if (Tok.is(AsmToken::Hash) ||
3626 Tok.is(AsmToken::Dollar) ||
3627 Tok.is(AsmToken::Integer)) {
3628 if (Parser.getTok().isNot(AsmToken::Integer))
3629 Parser.Lex(); // Eat '#' or '$'.
3630 SMLoc Loc = Parser.getTok().getLoc();
3632 const MCExpr *ISBarrierID;
3633 if (getParser().parseExpression(ISBarrierID)) {
3634 Error(Loc, "illegal expression");
3635 return MatchOperand_ParseFail;
3638 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3640 Error(Loc, "constant expression expected");
3641 return MatchOperand_ParseFail;
3644 int Val = CE->getValue();
3646 Error(Loc, "immediate value out of range");
3647 return MatchOperand_ParseFail;
3650 Opt = ARM_ISB::RESERVED_0 + Val;
3652 return MatchOperand_ParseFail;
3654 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3655 (ARM_ISB::InstSyncBOpt)Opt, S));
3656 return MatchOperand_Success;
3660 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3661 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3662 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3663 SMLoc S = Parser.getTok().getLoc();
3664 const AsmToken &Tok = Parser.getTok();
3665 if (!Tok.is(AsmToken::Identifier))
3666 return MatchOperand_NoMatch;
3667 StringRef IFlagsStr = Tok.getString();
3669 // An iflags string of "none" is interpreted to mean that none of the AIF
3670 // bits are set. Not a terribly useful instruction, but a valid encoding.
3671 unsigned IFlags = 0;
3672 if (IFlagsStr != "none") {
3673 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3674 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3675 .Case("a", ARM_PROC::A)
3676 .Case("i", ARM_PROC::I)
3677 .Case("f", ARM_PROC::F)
3680 // If some specific iflag is already set, it means that some letter is
3681 // present more than once, this is not acceptable.
3682 if (Flag == ~0U || (IFlags & Flag))
3683 return MatchOperand_NoMatch;
3689 Parser.Lex(); // Eat identifier token.
3690 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3691 return MatchOperand_Success;
3694 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3695 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3696 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3697 SMLoc S = Parser.getTok().getLoc();
3698 const AsmToken &Tok = Parser.getTok();
3699 if (!Tok.is(AsmToken::Identifier))
3700 return MatchOperand_NoMatch;
3701 StringRef Mask = Tok.getString();
3704 // See ARMv6-M 10.1.1
3705 std::string Name = Mask.lower();
3706 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3707 // Note: in the documentation:
3708 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3709 // for MSR APSR_nzcvq.
3710 // but we do make it an alias here. This is so to get the "mask encoding"
3711 // bits correct on MSR APSR writes.
3713 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3714 // should really only be allowed when writing a special register. Note
3715 // they get dropped in the MRS instruction reading a special register as
3716 // the SYSm field is only 8 bits.
3718 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3719 // includes the DSP extension but that is not checked.
3720 .Case("apsr", 0x800)
3721 .Case("apsr_nzcvq", 0x800)
3722 .Case("apsr_g", 0x400)
3723 .Case("apsr_nzcvqg", 0xc00)
3724 .Case("iapsr", 0x801)
3725 .Case("iapsr_nzcvq", 0x801)
3726 .Case("iapsr_g", 0x401)
3727 .Case("iapsr_nzcvqg", 0xc01)
3728 .Case("eapsr", 0x802)
3729 .Case("eapsr_nzcvq", 0x802)
3730 .Case("eapsr_g", 0x402)
3731 .Case("eapsr_nzcvqg", 0xc02)
3732 .Case("xpsr", 0x803)
3733 .Case("xpsr_nzcvq", 0x803)
3734 .Case("xpsr_g", 0x403)
3735 .Case("xpsr_nzcvqg", 0xc03)
3736 .Case("ipsr", 0x805)
3737 .Case("epsr", 0x806)
3738 .Case("iepsr", 0x807)
3741 .Case("primask", 0x810)
3742 .Case("basepri", 0x811)
3743 .Case("basepri_max", 0x812)
3744 .Case("faultmask", 0x813)
3745 .Case("control", 0x814)
3748 if (FlagsVal == ~0U)
3749 return MatchOperand_NoMatch;
3751 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3752 // basepri, basepri_max and faultmask only valid for V7m.
3753 return MatchOperand_NoMatch;
3755 Parser.Lex(); // Eat identifier token.
3756 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3757 return MatchOperand_Success;
3760 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3761 size_t Start = 0, Next = Mask.find('_');
3762 StringRef Flags = "";
3763 std::string SpecReg = Mask.slice(Start, Next).lower();
3764 if (Next != StringRef::npos)
3765 Flags = Mask.slice(Next+1, Mask.size());
3767 // FlagsVal contains the complete mask:
3769 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3770 unsigned FlagsVal = 0;
3772 if (SpecReg == "apsr") {
3773 FlagsVal = StringSwitch<unsigned>(Flags)
3774 .Case("nzcvq", 0x8) // same as CPSR_f
3775 .Case("g", 0x4) // same as CPSR_s
3776 .Case("nzcvqg", 0xc) // same as CPSR_fs
3779 if (FlagsVal == ~0U) {
3781 return MatchOperand_NoMatch;
3783 FlagsVal = 8; // No flag
3785 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3786 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3787 if (Flags == "all" || Flags == "")
3789 for (int i = 0, e = Flags.size(); i != e; ++i) {
3790 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3797 // If some specific flag is already set, it means that some letter is
3798 // present more than once, this is not acceptable.
3799 if (FlagsVal == ~0U || (FlagsVal & Flag))
3800 return MatchOperand_NoMatch;
3803 } else // No match for special register.
3804 return MatchOperand_NoMatch;
3806 // Special register without flags is NOT equivalent to "fc" flags.
3807 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3808 // two lines would enable gas compatibility at the expense of breaking
3814 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3815 if (SpecReg == "spsr")
3818 Parser.Lex(); // Eat identifier token.
3819 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3820 return MatchOperand_Success;
3823 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3824 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3825 int Low, int High) {
3826 const AsmToken &Tok = Parser.getTok();
3827 if (Tok.isNot(AsmToken::Identifier)) {
3828 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3829 return MatchOperand_ParseFail;
3831 StringRef ShiftName = Tok.getString();
3832 std::string LowerOp = Op.lower();
3833 std::string UpperOp = Op.upper();
3834 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3835 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3836 return MatchOperand_ParseFail;
3838 Parser.Lex(); // Eat shift type token.
3840 // There must be a '#' and a shift amount.
3841 if (Parser.getTok().isNot(AsmToken::Hash) &&
3842 Parser.getTok().isNot(AsmToken::Dollar)) {
3843 Error(Parser.getTok().getLoc(), "'#' expected");
3844 return MatchOperand_ParseFail;
3846 Parser.Lex(); // Eat hash token.
3848 const MCExpr *ShiftAmount;
3849 SMLoc Loc = Parser.getTok().getLoc();
3851 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3852 Error(Loc, "illegal expression");
3853 return MatchOperand_ParseFail;
3855 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3857 Error(Loc, "constant expression expected");
3858 return MatchOperand_ParseFail;
3860 int Val = CE->getValue();
3861 if (Val < Low || Val > High) {
3862 Error(Loc, "immediate value out of range");
3863 return MatchOperand_ParseFail;
3866 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3868 return MatchOperand_Success;
3871 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3872 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3873 const AsmToken &Tok = Parser.getTok();
3874 SMLoc S = Tok.getLoc();
3875 if (Tok.isNot(AsmToken::Identifier)) {
3876 Error(S, "'be' or 'le' operand expected");
3877 return MatchOperand_ParseFail;
3879 int Val = StringSwitch<int>(Tok.getString().lower())
3883 Parser.Lex(); // Eat the token.
3886 Error(S, "'be' or 'le' operand expected");
3887 return MatchOperand_ParseFail;
3889 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3891 S, Tok.getEndLoc()));
3892 return MatchOperand_Success;
3895 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3896 /// instructions. Legal values are:
3897 /// lsl #n 'n' in [0,31]
3898 /// asr #n 'n' in [1,32]
3899 /// n == 32 encoded as n == 0.
3900 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3901 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3902 const AsmToken &Tok = Parser.getTok();
3903 SMLoc S = Tok.getLoc();
3904 if (Tok.isNot(AsmToken::Identifier)) {
3905 Error(S, "shift operator 'asr' or 'lsl' expected");
3906 return MatchOperand_ParseFail;
3908 StringRef ShiftName = Tok.getString();
3910 if (ShiftName == "lsl" || ShiftName == "LSL")
3912 else if (ShiftName == "asr" || ShiftName == "ASR")
3915 Error(S, "shift operator 'asr' or 'lsl' expected");
3916 return MatchOperand_ParseFail;
3918 Parser.Lex(); // Eat the operator.
3920 // A '#' and a shift amount.
3921 if (Parser.getTok().isNot(AsmToken::Hash) &&
3922 Parser.getTok().isNot(AsmToken::Dollar)) {
3923 Error(Parser.getTok().getLoc(), "'#' expected");
3924 return MatchOperand_ParseFail;
3926 Parser.Lex(); // Eat hash token.
3927 SMLoc ExLoc = Parser.getTok().getLoc();
3929 const MCExpr *ShiftAmount;
3931 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3932 Error(ExLoc, "malformed shift expression");
3933 return MatchOperand_ParseFail;
3935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3937 Error(ExLoc, "shift amount must be an immediate");
3938 return MatchOperand_ParseFail;
3941 int64_t Val = CE->getValue();
3943 // Shift amount must be in [1,32]
3944 if (Val < 1 || Val > 32) {
3945 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3946 return MatchOperand_ParseFail;
3948 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3949 if (isThumb() && Val == 32) {
3950 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3951 return MatchOperand_ParseFail;
3953 if (Val == 32) Val = 0;
3955 // Shift amount must be in [1,32]
3956 if (Val < 0 || Val > 31) {
3957 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3958 return MatchOperand_ParseFail;
3962 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3964 return MatchOperand_Success;
3967 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3968 /// of instructions. Legal values are:
3969 /// ror #n 'n' in {0, 8, 16, 24}
3970 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3971 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3972 const AsmToken &Tok = Parser.getTok();
3973 SMLoc S = Tok.getLoc();
3974 if (Tok.isNot(AsmToken::Identifier))
3975 return MatchOperand_NoMatch;
3976 StringRef ShiftName = Tok.getString();
3977 if (ShiftName != "ror" && ShiftName != "ROR")
3978 return MatchOperand_NoMatch;
3979 Parser.Lex(); // Eat the operator.
3981 // A '#' and a rotate amount.
3982 if (Parser.getTok().isNot(AsmToken::Hash) &&
3983 Parser.getTok().isNot(AsmToken::Dollar)) {
3984 Error(Parser.getTok().getLoc(), "'#' expected");
3985 return MatchOperand_ParseFail;
3987 Parser.Lex(); // Eat hash token.
3988 SMLoc ExLoc = Parser.getTok().getLoc();
3990 const MCExpr *ShiftAmount;
3992 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3993 Error(ExLoc, "malformed rotate expression");
3994 return MatchOperand_ParseFail;
3996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3998 Error(ExLoc, "rotate amount must be an immediate");
3999 return MatchOperand_ParseFail;
4002 int64_t Val = CE->getValue();
4003 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4004 // normally, zero is represented in asm by omitting the rotate operand
4006 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
4007 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
4008 return MatchOperand_ParseFail;
4011 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
4013 return MatchOperand_Success;
4016 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4017 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4018 SMLoc S = Parser.getTok().getLoc();
4019 // The bitfield descriptor is really two operands, the LSB and the width.
4020 if (Parser.getTok().isNot(AsmToken::Hash) &&
4021 Parser.getTok().isNot(AsmToken::Dollar)) {
4022 Error(Parser.getTok().getLoc(), "'#' expected");
4023 return MatchOperand_ParseFail;
4025 Parser.Lex(); // Eat hash token.
4027 const MCExpr *LSBExpr;
4028 SMLoc E = Parser.getTok().getLoc();
4029 if (getParser().parseExpression(LSBExpr)) {
4030 Error(E, "malformed immediate expression");
4031 return MatchOperand_ParseFail;
4033 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4035 Error(E, "'lsb' operand must be an immediate");
4036 return MatchOperand_ParseFail;
4039 int64_t LSB = CE->getValue();
4040 // The LSB must be in the range [0,31]
4041 if (LSB < 0 || LSB > 31) {
4042 Error(E, "'lsb' operand must be in the range [0,31]");
4043 return MatchOperand_ParseFail;
4045 E = Parser.getTok().getLoc();
4047 // Expect another immediate operand.
4048 if (Parser.getTok().isNot(AsmToken::Comma)) {
4049 Error(Parser.getTok().getLoc(), "too few operands");
4050 return MatchOperand_ParseFail;
4052 Parser.Lex(); // Eat hash token.
4053 if (Parser.getTok().isNot(AsmToken::Hash) &&
4054 Parser.getTok().isNot(AsmToken::Dollar)) {
4055 Error(Parser.getTok().getLoc(), "'#' expected");
4056 return MatchOperand_ParseFail;
4058 Parser.Lex(); // Eat hash token.
4060 const MCExpr *WidthExpr;
4062 if (getParser().parseExpression(WidthExpr, EndLoc)) {
4063 Error(E, "malformed immediate expression");
4064 return MatchOperand_ParseFail;
4066 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4068 Error(E, "'width' operand must be an immediate");
4069 return MatchOperand_ParseFail;
4072 int64_t Width = CE->getValue();
4073 // The LSB must be in the range [1,32-lsb]
4074 if (Width < 1 || Width > 32 - LSB) {
4075 Error(E, "'width' operand must be in the range [1,32-lsb]");
4076 return MatchOperand_ParseFail;
4079 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4081 return MatchOperand_Success;
4084 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4085 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4086 // Check for a post-index addressing register operand. Specifically:
4087 // postidx_reg := '+' register {, shift}
4088 // | '-' register {, shift}
4089 // | register {, shift}
4091 // This method must return MatchOperand_NoMatch without consuming any tokens
4092 // in the case where there is no match, as other alternatives take other
4094 AsmToken Tok = Parser.getTok();
4095 SMLoc S = Tok.getLoc();
4096 bool haveEaten = false;
4098 if (Tok.is(AsmToken::Plus)) {
4099 Parser.Lex(); // Eat the '+' token.
4101 } else if (Tok.is(AsmToken::Minus)) {
4102 Parser.Lex(); // Eat the '-' token.
4107 SMLoc E = Parser.getTok().getEndLoc();
4108 int Reg = tryParseRegister();
4111 return MatchOperand_NoMatch;
4112 Error(Parser.getTok().getLoc(), "register expected");
4113 return MatchOperand_ParseFail;
4116 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4117 unsigned ShiftImm = 0;
4118 if (Parser.getTok().is(AsmToken::Comma)) {
4119 Parser.Lex(); // Eat the ','.
4120 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4121 return MatchOperand_ParseFail;
4123 // FIXME: Only approximates end...may include intervening whitespace.
4124 E = Parser.getTok().getLoc();
4127 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4130 return MatchOperand_Success;
4133 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4134 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4135 // Check for a post-index addressing register operand. Specifically:
4136 // am3offset := '+' register
4143 // This method must return MatchOperand_NoMatch without consuming any tokens
4144 // in the case where there is no match, as other alternatives take other
4146 AsmToken Tok = Parser.getTok();
4147 SMLoc S = Tok.getLoc();
4149 // Do immediates first, as we always parse those if we have a '#'.
4150 if (Parser.getTok().is(AsmToken::Hash) ||
4151 Parser.getTok().is(AsmToken::Dollar)) {
4152 Parser.Lex(); // Eat '#' or '$'.
4153 // Explicitly look for a '-', as we need to encode negative zero
4155 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4156 const MCExpr *Offset;
4158 if (getParser().parseExpression(Offset, E))
4159 return MatchOperand_ParseFail;
4160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4162 Error(S, "constant expression expected");
4163 return MatchOperand_ParseFail;
4165 // Negative zero is encoded as the flag value INT32_MIN.
4166 int32_t Val = CE->getValue();
4167 if (isNegative && Val == 0)
4171 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4173 return MatchOperand_Success;
4177 bool haveEaten = false;
4179 if (Tok.is(AsmToken::Plus)) {
4180 Parser.Lex(); // Eat the '+' token.
4182 } else if (Tok.is(AsmToken::Minus)) {
4183 Parser.Lex(); // Eat the '-' token.
4188 Tok = Parser.getTok();
4189 int Reg = tryParseRegister();
4192 return MatchOperand_NoMatch;
4193 Error(Tok.getLoc(), "register expected");
4194 return MatchOperand_ParseFail;
4197 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4198 0, S, Tok.getEndLoc()));
4200 return MatchOperand_Success;
4203 /// Convert parsed operands to MCInst. Needed here because this instruction
4204 /// only has two register operands, but multiplication is commutative so
4205 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4207 cvtThumbMultiply(MCInst &Inst,
4208 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4209 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4210 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4211 // If we have a three-operand form, make sure to set Rn to be the operand
4212 // that isn't the same as Rd.
4214 if (Operands.size() == 6 &&
4215 ((ARMOperand*)Operands[4])->getReg() ==
4216 ((ARMOperand*)Operands[3])->getReg())
4218 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4219 Inst.addOperand(Inst.getOperand(0));
4220 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4224 cvtThumbBranches(MCInst &Inst,
4225 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4226 int CondOp = -1, ImmOp = -1;
4227 switch(Inst.getOpcode()) {
4229 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4232 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4234 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4236 // first decide whether or not the branch should be conditional
4237 // by looking at it's location relative to an IT block
4239 // inside an IT block we cannot have any conditional branches. any
4240 // such instructions needs to be converted to unconditional form
4241 switch(Inst.getOpcode()) {
4242 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4243 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4246 // outside IT blocks we can only have unconditional branches with AL
4247 // condition code or conditional branches with non-AL condition code
4248 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4249 switch(Inst.getOpcode()) {
4252 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4256 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4261 // now decide on encoding size based on branch target range
4262 switch(Inst.getOpcode()) {
4263 // classify tB as either t2B or t1B based on range of immediate operand
4265 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4266 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4267 Inst.setOpcode(ARM::t2B);
4270 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4272 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4273 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4274 Inst.setOpcode(ARM::t2Bcc);
4278 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4279 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4282 /// Parse an ARM memory expression, return false if successful else return true
4283 /// or an error. The first token must be a '[' when called.
4285 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4287 assert(Parser.getTok().is(AsmToken::LBrac) &&
4288 "Token is not a Left Bracket");
4289 S = Parser.getTok().getLoc();
4290 Parser.Lex(); // Eat left bracket token.
4292 const AsmToken &BaseRegTok = Parser.getTok();
4293 int BaseRegNum = tryParseRegister();
4294 if (BaseRegNum == -1)
4295 return Error(BaseRegTok.getLoc(), "register expected");
4297 // The next token must either be a comma, a colon or a closing bracket.
4298 const AsmToken &Tok = Parser.getTok();
4299 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4300 !Tok.is(AsmToken::RBrac))
4301 return Error(Tok.getLoc(), "malformed memory operand");
4303 if (Tok.is(AsmToken::RBrac)) {
4304 E = Tok.getEndLoc();
4305 Parser.Lex(); // Eat right bracket token.
4307 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4308 0, 0, false, S, E));
4310 // If there's a pre-indexing writeback marker, '!', just add it as a token
4311 // operand. It's rather odd, but syntactically valid.
4312 if (Parser.getTok().is(AsmToken::Exclaim)) {
4313 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4314 Parser.Lex(); // Eat the '!'.
4320 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4321 "Lost colon or comma in memory operand?!");
4322 if (Tok.is(AsmToken::Comma)) {
4323 Parser.Lex(); // Eat the comma.
4326 // If we have a ':', it's an alignment specifier.
4327 if (Parser.getTok().is(AsmToken::Colon)) {
4328 Parser.Lex(); // Eat the ':'.
4329 E = Parser.getTok().getLoc();
4332 if (getParser().parseExpression(Expr))
4335 // The expression has to be a constant. Memory references with relocations
4336 // don't come through here, as they use the <label> forms of the relevant
4338 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4340 return Error (E, "constant expression expected");
4343 switch (CE->getValue()) {
4346 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4347 case 16: Align = 2; break;
4348 case 32: Align = 4; break;
4349 case 64: Align = 8; break;
4350 case 128: Align = 16; break;
4351 case 256: Align = 32; break;
4354 // Now we should have the closing ']'
4355 if (Parser.getTok().isNot(AsmToken::RBrac))
4356 return Error(Parser.getTok().getLoc(), "']' expected");
4357 E = Parser.getTok().getEndLoc();
4358 Parser.Lex(); // Eat right bracket token.
4360 // Don't worry about range checking the value here. That's handled by
4361 // the is*() predicates.
4362 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4363 ARM_AM::no_shift, 0, Align,
4366 // If there's a pre-indexing writeback marker, '!', just add it as a token
4368 if (Parser.getTok().is(AsmToken::Exclaim)) {
4369 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4370 Parser.Lex(); // Eat the '!'.
4376 // If we have a '#', it's an immediate offset, else assume it's a register
4377 // offset. Be friendly and also accept a plain integer (without a leading
4378 // hash) for gas compatibility.
4379 if (Parser.getTok().is(AsmToken::Hash) ||
4380 Parser.getTok().is(AsmToken::Dollar) ||
4381 Parser.getTok().is(AsmToken::Integer)) {
4382 if (Parser.getTok().isNot(AsmToken::Integer))
4383 Parser.Lex(); // Eat '#' or '$'.
4384 E = Parser.getTok().getLoc();
4386 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4387 const MCExpr *Offset;
4388 if (getParser().parseExpression(Offset))
4391 // The expression has to be a constant. Memory references with relocations
4392 // don't come through here, as they use the <label> forms of the relevant
4394 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4396 return Error (E, "constant expression expected");
4398 // If the constant was #-0, represent it as INT32_MIN.
4399 int32_t Val = CE->getValue();
4400 if (isNegative && Val == 0)
4401 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4403 // Now we should have the closing ']'
4404 if (Parser.getTok().isNot(AsmToken::RBrac))
4405 return Error(Parser.getTok().getLoc(), "']' expected");
4406 E = Parser.getTok().getEndLoc();
4407 Parser.Lex(); // Eat right bracket token.
4409 // Don't worry about range checking the value here. That's handled by
4410 // the is*() predicates.
4411 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4412 ARM_AM::no_shift, 0, 0,
4415 // If there's a pre-indexing writeback marker, '!', just add it as a token
4417 if (Parser.getTok().is(AsmToken::Exclaim)) {
4418 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4419 Parser.Lex(); // Eat the '!'.
4425 // The register offset is optionally preceded by a '+' or '-'
4426 bool isNegative = false;
4427 if (Parser.getTok().is(AsmToken::Minus)) {
4429 Parser.Lex(); // Eat the '-'.
4430 } else if (Parser.getTok().is(AsmToken::Plus)) {
4432 Parser.Lex(); // Eat the '+'.
4435 E = Parser.getTok().getLoc();
4436 int OffsetRegNum = tryParseRegister();
4437 if (OffsetRegNum == -1)
4438 return Error(E, "register expected");
4440 // If there's a shift operator, handle it.
4441 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4442 unsigned ShiftImm = 0;
4443 if (Parser.getTok().is(AsmToken::Comma)) {
4444 Parser.Lex(); // Eat the ','.
4445 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4449 // Now we should have the closing ']'
4450 if (Parser.getTok().isNot(AsmToken::RBrac))
4451 return Error(Parser.getTok().getLoc(), "']' expected");
4452 E = Parser.getTok().getEndLoc();
4453 Parser.Lex(); // Eat right bracket token.
4455 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4456 ShiftType, ShiftImm, 0, isNegative,
4459 // If there's a pre-indexing writeback marker, '!', just add it as a token
4461 if (Parser.getTok().is(AsmToken::Exclaim)) {
4462 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4463 Parser.Lex(); // Eat the '!'.
4469 /// parseMemRegOffsetShift - one of these two:
4470 /// ( lsl | lsr | asr | ror ) , # shift_amount
4472 /// return true if it parses a shift otherwise it returns false.
4473 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4475 SMLoc Loc = Parser.getTok().getLoc();
4476 const AsmToken &Tok = Parser.getTok();
4477 if (Tok.isNot(AsmToken::Identifier))
4479 StringRef ShiftName = Tok.getString();
4480 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4481 ShiftName == "asl" || ShiftName == "ASL")
4483 else if (ShiftName == "lsr" || ShiftName == "LSR")
4485 else if (ShiftName == "asr" || ShiftName == "ASR")
4487 else if (ShiftName == "ror" || ShiftName == "ROR")
4489 else if (ShiftName == "rrx" || ShiftName == "RRX")
4492 return Error(Loc, "illegal shift operator");
4493 Parser.Lex(); // Eat shift type token.
4495 // rrx stands alone.
4497 if (St != ARM_AM::rrx) {
4498 Loc = Parser.getTok().getLoc();
4499 // A '#' and a shift amount.
4500 const AsmToken &HashTok = Parser.getTok();
4501 if (HashTok.isNot(AsmToken::Hash) &&
4502 HashTok.isNot(AsmToken::Dollar))
4503 return Error(HashTok.getLoc(), "'#' expected");
4504 Parser.Lex(); // Eat hash token.
4507 if (getParser().parseExpression(Expr))
4509 // Range check the immediate.
4510 // lsl, ror: 0 <= imm <= 31
4511 // lsr, asr: 0 <= imm <= 32
4512 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4514 return Error(Loc, "shift amount must be an immediate");
4515 int64_t Imm = CE->getValue();
4517 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4518 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4519 return Error(Loc, "immediate shift value out of range");
4520 // If <ShiftTy> #0, turn it into a no_shift.
4523 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4532 /// parseFPImm - A floating point immediate expression operand.
4533 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4534 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4535 // Anything that can accept a floating point constant as an operand
4536 // needs to go through here, as the regular parseExpression is
4539 // This routine still creates a generic Immediate operand, containing
4540 // a bitcast of the 64-bit floating point value. The various operands
4541 // that accept floats can check whether the value is valid for them
4542 // via the standard is*() predicates.
4544 SMLoc S = Parser.getTok().getLoc();
4546 if (Parser.getTok().isNot(AsmToken::Hash) &&
4547 Parser.getTok().isNot(AsmToken::Dollar))
4548 return MatchOperand_NoMatch;
4550 // Disambiguate the VMOV forms that can accept an FP immediate.
4551 // vmov.f32 <sreg>, #imm
4552 // vmov.f64 <dreg>, #imm
4553 // vmov.f32 <dreg>, #imm @ vector f32x2
4554 // vmov.f32 <qreg>, #imm @ vector f32x4
4556 // There are also the NEON VMOV instructions which expect an
4557 // integer constant. Make sure we don't try to parse an FPImm
4559 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4560 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4561 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4562 TyOp->getToken() != ".f64"))
4563 return MatchOperand_NoMatch;
4565 Parser.Lex(); // Eat '#' or '$'.
4567 // Handle negation, as that still comes through as a separate token.
4568 bool isNegative = false;
4569 if (Parser.getTok().is(AsmToken::Minus)) {
4573 const AsmToken &Tok = Parser.getTok();
4574 SMLoc Loc = Tok.getLoc();
4575 if (Tok.is(AsmToken::Real)) {
4576 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4577 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4578 // If we had a '-' in front, toggle the sign bit.
4579 IntVal ^= (uint64_t)isNegative << 31;
4580 Parser.Lex(); // Eat the token.
4581 Operands.push_back(ARMOperand::CreateImm(
4582 MCConstantExpr::Create(IntVal, getContext()),
4583 S, Parser.getTok().getLoc()));
4584 return MatchOperand_Success;
4586 // Also handle plain integers. Instructions which allow floating point
4587 // immediates also allow a raw encoded 8-bit value.
4588 if (Tok.is(AsmToken::Integer)) {
4589 int64_t Val = Tok.getIntVal();
4590 Parser.Lex(); // Eat the token.
4591 if (Val > 255 || Val < 0) {
4592 Error(Loc, "encoded floating point value out of range");
4593 return MatchOperand_ParseFail;
4595 double RealVal = ARM_AM::getFPImmFloat(Val);
4596 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4597 Operands.push_back(ARMOperand::CreateImm(
4598 MCConstantExpr::Create(Val, getContext()), S,
4599 Parser.getTok().getLoc()));
4600 return MatchOperand_Success;
4603 Error(Loc, "invalid floating point immediate");
4604 return MatchOperand_ParseFail;
4607 /// Parse a arm instruction operand. For now this parses the operand regardless
4608 /// of the mnemonic.
4609 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4610 StringRef Mnemonic) {
4613 // Check if the current operand has a custom associated parser, if so, try to
4614 // custom parse the operand, or fallback to the general approach.
4615 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4616 if (ResTy == MatchOperand_Success)
4618 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4619 // there was a match, but an error occurred, in which case, just return that
4620 // the operand parsing failed.
4621 if (ResTy == MatchOperand_ParseFail)
4624 switch (getLexer().getKind()) {
4626 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4628 case AsmToken::Identifier: {
4629 // If we've seen a branch mnemonic, the next operand must be a label. This
4630 // is true even if the label is a register name. So "br r1" means branch to
4632 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4634 if (!tryParseRegisterWithWriteBack(Operands))
4636 int Res = tryParseShiftRegister(Operands);
4637 if (Res == 0) // success
4639 else if (Res == -1) // irrecoverable error
4641 // If this is VMRS, check for the apsr_nzcv operand.
4642 if (Mnemonic == "vmrs" &&
4643 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4644 S = Parser.getTok().getLoc();
4646 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4651 // Fall though for the Identifier case that is not a register or a
4654 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4655 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4656 case AsmToken::String: // quoted label names.
4657 case AsmToken::Dot: { // . as a branch target
4658 // This was not a register so parse other operands that start with an
4659 // identifier (like labels) as expressions and create them as immediates.
4660 const MCExpr *IdVal;
4661 S = Parser.getTok().getLoc();
4662 if (getParser().parseExpression(IdVal))
4664 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4665 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4668 case AsmToken::LBrac:
4669 return parseMemory(Operands);
4670 case AsmToken::LCurly:
4671 return parseRegisterList(Operands);
4672 case AsmToken::Dollar:
4673 case AsmToken::Hash: {
4674 // #42 -> immediate.
4675 S = Parser.getTok().getLoc();
4678 if (Parser.getTok().isNot(AsmToken::Colon)) {
4679 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4680 const MCExpr *ImmVal;
4681 if (getParser().parseExpression(ImmVal))
4683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4685 int32_t Val = CE->getValue();
4686 if (isNegative && Val == 0)
4687 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4689 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4690 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4692 // There can be a trailing '!' on operands that we want as a separate
4693 // '!' Token operand. Handle that here. For example, the compatibilty
4694 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4695 if (Parser.getTok().is(AsmToken::Exclaim)) {
4696 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4697 Parser.getTok().getLoc()));
4698 Parser.Lex(); // Eat exclaim token
4702 // w/ a ':' after the '#', it's just like a plain ':'.
4705 case AsmToken::Colon: {
4706 // ":lower16:" and ":upper16:" expression prefixes
4707 // FIXME: Check it's an expression prefix,
4708 // e.g. (FOO - :lower16:BAR) isn't legal.
4709 ARMMCExpr::VariantKind RefKind;
4710 if (parsePrefix(RefKind))
4713 const MCExpr *SubExprVal;
4714 if (getParser().parseExpression(SubExprVal))
4717 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4719 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4720 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4723 case AsmToken::Equal: {
4724 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4725 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4727 const MCSection *Section =
4728 getParser().getStreamer().getCurrentSection().first;
4730 Parser.Lex(); // Eat '='
4731 const MCExpr *SubExprVal;
4732 if (getParser().parseExpression(SubExprVal))
4734 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4736 const MCExpr *CPLoc =
4737 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4738 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4744 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4745 // :lower16: and :upper16:.
4746 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4747 RefKind = ARMMCExpr::VK_ARM_None;
4749 // :lower16: and :upper16: modifiers
4750 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4751 Parser.Lex(); // Eat ':'
4753 if (getLexer().isNot(AsmToken::Identifier)) {
4754 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4758 StringRef IDVal = Parser.getTok().getIdentifier();
4759 if (IDVal == "lower16") {
4760 RefKind = ARMMCExpr::VK_ARM_LO16;
4761 } else if (IDVal == "upper16") {
4762 RefKind = ARMMCExpr::VK_ARM_HI16;
4764 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4769 if (getLexer().isNot(AsmToken::Colon)) {
4770 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4773 Parser.Lex(); // Eat the last ':'
4777 /// \brief Given a mnemonic, split out possible predication code and carry
4778 /// setting letters to form a canonical mnemonic and flags.
4780 // FIXME: Would be nice to autogen this.
4781 // FIXME: This is a bit of a maze of special cases.
4782 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4783 unsigned &PredicationCode,
4785 unsigned &ProcessorIMod,
4786 StringRef &ITMask) {
4787 PredicationCode = ARMCC::AL;
4788 CarrySetting = false;
4791 // Ignore some mnemonics we know aren't predicated forms.
4793 // FIXME: Would be nice to autogen this.
4794 if ((Mnemonic == "movs" && isThumb()) ||
4795 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4796 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4797 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4798 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4799 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4800 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4801 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4802 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4803 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4804 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4805 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4806 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4809 // First, split out any predication code. Ignore mnemonics we know aren't
4810 // predicated but do have a carry-set and so weren't caught above.
4811 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4812 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4813 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4814 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4815 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4816 .Case("eq", ARMCC::EQ)
4817 .Case("ne", ARMCC::NE)
4818 .Case("hs", ARMCC::HS)
4819 .Case("cs", ARMCC::HS)
4820 .Case("lo", ARMCC::LO)
4821 .Case("cc", ARMCC::LO)
4822 .Case("mi", ARMCC::MI)
4823 .Case("pl", ARMCC::PL)
4824 .Case("vs", ARMCC::VS)
4825 .Case("vc", ARMCC::VC)
4826 .Case("hi", ARMCC::HI)
4827 .Case("ls", ARMCC::LS)
4828 .Case("ge", ARMCC::GE)
4829 .Case("lt", ARMCC::LT)
4830 .Case("gt", ARMCC::GT)
4831 .Case("le", ARMCC::LE)
4832 .Case("al", ARMCC::AL)
4835 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4836 PredicationCode = CC;
4840 // Next, determine if we have a carry setting bit. We explicitly ignore all
4841 // the instructions we know end in 's'.
4842 if (Mnemonic.endswith("s") &&
4843 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4844 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4845 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4846 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4847 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4848 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4849 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4850 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4851 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4852 (Mnemonic == "movs" && isThumb()))) {
4853 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4854 CarrySetting = true;
4857 // The "cps" instruction can have a interrupt mode operand which is glued into
4858 // the mnemonic. Check if this is the case, split it and parse the imod op
4859 if (Mnemonic.startswith("cps")) {
4860 // Split out any imod code.
4862 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4863 .Case("ie", ARM_PROC::IE)
4864 .Case("id", ARM_PROC::ID)
4867 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4868 ProcessorIMod = IMod;
4872 // The "it" instruction has the condition mask on the end of the mnemonic.
4873 if (Mnemonic.startswith("it")) {
4874 ITMask = Mnemonic.slice(2, Mnemonic.size());
4875 Mnemonic = Mnemonic.slice(0, 2);
4881 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4882 /// inclusion of carry set or predication code operands.
4884 // FIXME: It would be nice to autogen this.
4886 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4887 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4888 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4889 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4890 Mnemonic == "add" || Mnemonic == "adc" ||
4891 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4892 Mnemonic == "orr" || Mnemonic == "mvn" ||
4893 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4894 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4895 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4896 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4897 Mnemonic == "mla" || Mnemonic == "smlal" ||
4898 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4899 CanAcceptCarrySet = true;
4901 CanAcceptCarrySet = false;
4903 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4904 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4905 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4906 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4907 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4908 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4909 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4910 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4911 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4912 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4913 // These mnemonics are never predicable
4914 CanAcceptPredicationCode = false;
4915 } else if (!isThumb()) {
4916 // Some instructions are only predicable in Thumb mode
4917 CanAcceptPredicationCode
4918 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4919 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4920 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4921 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4922 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4923 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4924 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4925 } else if (isThumbOne()) {
4927 CanAcceptPredicationCode = Mnemonic != "movs";
4929 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4931 CanAcceptPredicationCode = true;
4934 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4935 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4936 // FIXME: This is all horribly hacky. We really need a better way to deal
4937 // with optional operands like this in the matcher table.
4939 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4940 // another does not. Specifically, the MOVW instruction does not. So we
4941 // special case it here and remove the defaulted (non-setting) cc_out
4942 // operand if that's the instruction we're trying to match.
4944 // We do this as post-processing of the explicit operands rather than just
4945 // conditionally adding the cc_out in the first place because we need
4946 // to check the type of the parsed immediate operand.
4947 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4948 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4949 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4950 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4953 // Register-register 'add' for thumb does not have a cc_out operand
4954 // when there are only two register operands.
4955 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4956 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4957 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4958 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4960 // Register-register 'add' for thumb does not have a cc_out operand
4961 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4962 // have to check the immediate range here since Thumb2 has a variant
4963 // that can handle a different range and has a cc_out operand.
4964 if (((isThumb() && Mnemonic == "add") ||
4965 (isThumbTwo() && Mnemonic == "sub")) &&
4966 Operands.size() == 6 &&
4967 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4968 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4969 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4970 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4971 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4972 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4974 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4975 // imm0_4095 variant. That's the least-preferred variant when
4976 // selecting via the generic "add" mnemonic, so to know that we
4977 // should remove the cc_out operand, we have to explicitly check that
4978 // it's not one of the other variants. Ugh.
4979 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4980 Operands.size() == 6 &&
4981 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4982 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4983 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4984 // Nest conditions rather than one big 'if' statement for readability.
4986 // If both registers are low, we're in an IT block, and the immediate is
4987 // in range, we should use encoding T1 instead, which has a cc_out.
4989 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
4990 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4991 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4993 // Check against T3. If the second register is the PC, this is an
4994 // alternate form of ADR, which uses encoding T4, so check for that too.
4995 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
4996 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4999 // Otherwise, we use encoding T4, which does not have a cc_out
5004 // The thumb2 multiply instruction doesn't have a CCOut register, so
5005 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5006 // use the 16-bit encoding or not.
5007 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5008 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5009 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5010 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5011 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5012 // If the registers aren't low regs, the destination reg isn't the
5013 // same as one of the source regs, or the cc_out operand is zero
5014 // outside of an IT block, we have to use the 32-bit encoding, so
5015 // remove the cc_out operand.
5016 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5017 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5018 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5020 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5021 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5022 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5023 static_cast<ARMOperand*>(Operands[4])->getReg())))
5026 // Also check the 'mul' syntax variant that doesn't specify an explicit
5027 // destination register.
5028 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5029 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5030 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5031 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5032 // If the registers aren't low regs or the cc_out operand is zero
5033 // outside of an IT block, we have to use the 32-bit encoding, so
5034 // remove the cc_out operand.
5035 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5036 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5042 // Register-register 'add/sub' for thumb does not have a cc_out operand
5043 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5044 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5045 // right, this will result in better diagnostics (which operand is off)
5047 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5048 (Operands.size() == 5 || Operands.size() == 6) &&
5049 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5050 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5051 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5052 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5053 (Operands.size() == 6 &&
5054 static_cast<ARMOperand*>(Operands[5])->isImm())))
5060 bool ARMAsmParser::shouldOmitPredicateOperand(
5061 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5062 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5063 unsigned RegIdx = 3;
5064 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5065 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5066 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5067 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5070 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5071 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5072 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5073 ARMMCRegisterClasses[ARM::QPRRegClassID]
5074 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5080 static bool isDataTypeToken(StringRef Tok) {
5081 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5082 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5083 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5084 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5085 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5086 Tok == ".f" || Tok == ".d";
5089 // FIXME: This bit should probably be handled via an explicit match class
5090 // in the .td files that matches the suffix instead of having it be
5091 // a literal string token the way it is now.
5092 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5093 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5095 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5096 unsigned VariantID);
5097 /// Parse an arm instruction mnemonic followed by its operands.
5098 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5100 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5101 // Apply mnemonic aliases before doing anything else, as the destination
5102 // mnemnonic may include suffices and we want to handle them normally.
5103 // The generic tblgen'erated code does this later, at the start of
5104 // MatchInstructionImpl(), but that's too late for aliases that include
5105 // any sort of suffix.
5106 unsigned AvailableFeatures = getAvailableFeatures();
5107 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5108 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5110 // First check for the ARM-specific .req directive.
5111 if (Parser.getTok().is(AsmToken::Identifier) &&
5112 Parser.getTok().getIdentifier() == ".req") {
5113 parseDirectiveReq(Name, NameLoc);
5114 // We always return 'error' for this, as we're done with this
5115 // statement and don't need to match the 'instruction."
5119 // Create the leading tokens for the mnemonic, split by '.' characters.
5120 size_t Start = 0, Next = Name.find('.');
5121 StringRef Mnemonic = Name.slice(Start, Next);
5123 // Split out the predication code and carry setting flag from the mnemonic.
5124 unsigned PredicationCode;
5125 unsigned ProcessorIMod;
5128 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5129 ProcessorIMod, ITMask);
5131 // In Thumb1, only the branch (B) instruction can be predicated.
5132 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5133 Parser.eatToEndOfStatement();
5134 return Error(NameLoc, "conditional execution not supported in Thumb1");
5137 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5139 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5140 // is the mask as it will be for the IT encoding if the conditional
5141 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5142 // where the conditional bit0 is zero, the instruction post-processing
5143 // will adjust the mask accordingly.
5144 if (Mnemonic == "it") {
5145 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5146 if (ITMask.size() > 3) {
5147 Parser.eatToEndOfStatement();
5148 return Error(Loc, "too many conditions on IT instruction");
5151 for (unsigned i = ITMask.size(); i != 0; --i) {
5152 char pos = ITMask[i - 1];
5153 if (pos != 't' && pos != 'e') {
5154 Parser.eatToEndOfStatement();
5155 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5158 if (ITMask[i - 1] == 't')
5161 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5164 // FIXME: This is all a pretty gross hack. We should automatically handle
5165 // optional operands like this via tblgen.
5167 // Next, add the CCOut and ConditionCode operands, if needed.
5169 // For mnemonics which can ever incorporate a carry setting bit or predication
5170 // code, our matching model involves us always generating CCOut and
5171 // ConditionCode operands to match the mnemonic "as written" and then we let
5172 // the matcher deal with finding the right instruction or generating an
5173 // appropriate error.
5174 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5175 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5177 // If we had a carry-set on an instruction that can't do that, issue an
5179 if (!CanAcceptCarrySet && CarrySetting) {
5180 Parser.eatToEndOfStatement();
5181 return Error(NameLoc, "instruction '" + Mnemonic +
5182 "' can not set flags, but 's' suffix specified");
5184 // If we had a predication code on an instruction that can't do that, issue an
5186 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5187 Parser.eatToEndOfStatement();
5188 return Error(NameLoc, "instruction '" + Mnemonic +
5189 "' is not predicable, but condition code specified");
5192 // Add the carry setting operand, if necessary.
5193 if (CanAcceptCarrySet) {
5194 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5195 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5199 // Add the predication code operand, if necessary.
5200 if (CanAcceptPredicationCode) {
5201 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5203 Operands.push_back(ARMOperand::CreateCondCode(
5204 ARMCC::CondCodes(PredicationCode), Loc));
5207 // Add the processor imod operand, if necessary.
5208 if (ProcessorIMod) {
5209 Operands.push_back(ARMOperand::CreateImm(
5210 MCConstantExpr::Create(ProcessorIMod, getContext()),
5214 // Add the remaining tokens in the mnemonic.
5215 while (Next != StringRef::npos) {
5217 Next = Name.find('.', Start + 1);
5218 StringRef ExtraToken = Name.slice(Start, Next);
5220 // Some NEON instructions have an optional datatype suffix that is
5221 // completely ignored. Check for that.
5222 if (isDataTypeToken(ExtraToken) &&
5223 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5226 // For for ARM mode generate an error if the .n qualifier is used.
5227 if (ExtraToken == ".n" && !isThumb()) {
5228 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5229 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5233 // The .n qualifier is always discarded as that is what the tables
5234 // and matcher expect. In ARM mode the .w qualifier has no effect,
5235 // so discard it to avoid errors that can be caused by the matcher.
5236 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5237 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5238 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5242 // Read the remaining operands.
5243 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5244 // Read the first operand.
5245 if (parseOperand(Operands, Mnemonic)) {
5246 Parser.eatToEndOfStatement();
5250 while (getLexer().is(AsmToken::Comma)) {
5251 Parser.Lex(); // Eat the comma.
5253 // Parse and remember the operand.
5254 if (parseOperand(Operands, Mnemonic)) {
5255 Parser.eatToEndOfStatement();
5261 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5262 SMLoc Loc = getLexer().getLoc();
5263 Parser.eatToEndOfStatement();
5264 return Error(Loc, "unexpected token in argument list");
5267 Parser.Lex(); // Consume the EndOfStatement
5269 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5270 // do and don't have a cc_out optional-def operand. With some spot-checks
5271 // of the operand list, we can figure out which variant we're trying to
5272 // parse and adjust accordingly before actually matching. We shouldn't ever
5273 // try to remove a cc_out operand that was explicitly set on the the
5274 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5275 // table driven matcher doesn't fit well with the ARM instruction set.
5276 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5277 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5278 Operands.erase(Operands.begin() + 1);
5282 // Some instructions have the same mnemonic, but don't always
5283 // have a predicate. Distinguish them here and delete the
5284 // predicate if needed.
5285 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5286 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5287 Operands.erase(Operands.begin() + 1);
5291 // ARM mode 'blx' need special handling, as the register operand version
5292 // is predicable, but the label operand version is not. So, we can't rely
5293 // on the Mnemonic based checking to correctly figure out when to put
5294 // a k_CondCode operand in the list. If we're trying to match the label
5295 // version, remove the k_CondCode operand here.
5296 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5297 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5298 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5299 Operands.erase(Operands.begin() + 1);
5303 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5304 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5305 // a single GPRPair reg operand is used in the .td file to replace the two
5306 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5307 // expressed as a GPRPair, so we have to manually merge them.
5308 // FIXME: We would really like to be able to tablegen'erate this.
5309 if (!isThumb() && Operands.size() > 4 &&
5310 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5311 Mnemonic == "stlexd")) {
5312 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5313 unsigned Idx = isLoad ? 2 : 3;
5314 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5315 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5317 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5318 // Adjust only if Op1 and Op2 are GPRs.
5319 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5320 MRC.contains(Op2->getReg())) {
5321 unsigned Reg1 = Op1->getReg();
5322 unsigned Reg2 = Op2->getReg();
5323 unsigned Rt = MRI->getEncodingValue(Reg1);
5324 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5326 // Rt2 must be Rt + 1 and Rt must be even.
5327 if (Rt + 1 != Rt2 || (Rt & 1)) {
5328 Error(Op2->getStartLoc(), isLoad ?
5329 "destination operands must be sequential" :
5330 "source operands must be sequential");
5333 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5334 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5335 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5336 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5337 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5343 // FIXME: As said above, this is all a pretty gross hack. This instruction
5344 // does not fit with other "subs" and tblgen.
5345 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5346 // so the Mnemonic is the original name "subs" and delete the predicate
5347 // operand so it will match the table entry.
5348 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5349 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5350 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5351 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5352 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5353 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5354 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5355 Operands.erase(Operands.begin());
5357 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5359 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5360 Operands.erase(Operands.begin() + 1);
5366 // Validate context-sensitive operand constraints.
5368 // return 'true' if register list contains non-low GPR registers,
5369 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5370 // 'containsReg' to true.
5371 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5372 unsigned HiReg, bool &containsReg) {
5373 containsReg = false;
5374 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5375 unsigned OpReg = Inst.getOperand(i).getReg();
5378 // Anything other than a low register isn't legal here.
5379 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5385 // Check if the specified regisgter is in the register list of the inst,
5386 // starting at the indicated operand number.
5387 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5388 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5389 unsigned OpReg = Inst.getOperand(i).getReg();
5396 // Return true if instruction has the interesting property of being
5397 // allowed in IT blocks, but not being predicable.
5398 static bool instIsBreakpoint(const MCInst &Inst) {
5399 return Inst.getOpcode() == ARM::tBKPT ||
5400 Inst.getOpcode() == ARM::BKPT ||
5401 Inst.getOpcode() == ARM::tHLT ||
5402 Inst.getOpcode() == ARM::HLT;
5406 // FIXME: We would really like to be able to tablegen'erate this.
5408 validateInstruction(MCInst &Inst,
5409 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5410 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5411 SMLoc Loc = Operands[0]->getStartLoc();
5413 // Check the IT block state first.
5414 // NOTE: BKPT and HLT instructions have the interesting property of being
5415 // allowed in IT blocks, but not being predicable. They just always execute.
5416 if (inITBlock() && !instIsBreakpoint(Inst)) {
5418 if (ITState.FirstCond)
5419 ITState.FirstCond = false;
5421 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5422 // The instruction must be predicable.
5423 if (!MCID.isPredicable())
5424 return Error(Loc, "instructions in IT block must be predicable");
5425 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5426 unsigned ITCond = Bit ? ITState.Cond :
5427 ARMCC::getOppositeCondition(ITState.Cond);
5428 if (Cond != ITCond) {
5429 // Find the condition code Operand to get its SMLoc information.
5431 for (unsigned I = 1; I < Operands.size(); ++I)
5432 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5433 CondLoc = Operands[I]->getStartLoc();
5434 return Error(CondLoc, "incorrect condition in IT block; got '" +
5435 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5436 "', but expected '" +
5437 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5439 // Check for non-'al' condition codes outside of the IT block.
5440 } else if (isThumbTwo() && MCID.isPredicable() &&
5441 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5442 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5443 Inst.getOpcode() != ARM::t2Bcc)
5444 return Error(Loc, "predicated instructions must be in IT block");
5446 const unsigned Opcode = Inst.getOpcode();
5450 case ARM::LDRD_POST: {
5451 const unsigned RtReg = Inst.getOperand(0).getReg();
5454 if (RtReg == ARM::LR)
5455 return Error(Operands[3]->getStartLoc(),
5458 const unsigned Rt = MRI->getEncodingValue(RtReg);
5459 // Rt must be even-numbered.
5461 return Error(Operands[3]->getStartLoc(),
5462 "Rt must be even-numbered");
5464 // Rt2 must be Rt + 1.
5465 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5467 return Error(Operands[3]->getStartLoc(),
5468 "destination operands must be sequential");
5470 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5471 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5472 // For addressing modes with writeback, the base register needs to be
5473 // different from the destination registers.
5474 if (Rn == Rt || Rn == Rt2)
5475 return Error(Operands[3]->getStartLoc(),
5476 "base register needs to be different from destination "
5483 case ARM::t2LDRD_PRE:
5484 case ARM::t2LDRD_POST: {
5485 // Rt2 must be different from Rt.
5486 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5487 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5489 return Error(Operands[3]->getStartLoc(),
5490 "destination operands can't be identical");
5494 // Rt2 must be Rt + 1.
5495 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5496 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5498 return Error(Operands[3]->getStartLoc(),
5499 "source operands must be sequential");
5503 case ARM::STRD_POST: {
5504 // Rt2 must be Rt + 1.
5505 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5506 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5508 return Error(Operands[3]->getStartLoc(),
5509 "source operands must be sequential");
5514 // Width must be in range [1, 32-lsb].
5515 unsigned LSB = Inst.getOperand(2).getImm();
5516 unsigned Widthm1 = Inst.getOperand(3).getImm();
5517 if (Widthm1 >= 32 - LSB)
5518 return Error(Operands[5]->getStartLoc(),
5519 "bitfield width must be in range [1,32-lsb]");
5522 // Notionally handles ARM::tLDMIA_UPD too.
5524 // If we're parsing Thumb2, the .w variant is available and handles
5525 // most cases that are normally illegal for a Thumb1 LDM instruction.
5526 // We'll make the transformation in processInstruction() if necessary.
5528 // Thumb LDM instructions are writeback iff the base register is not
5529 // in the register list.
5530 unsigned Rn = Inst.getOperand(0).getReg();
5531 bool HasWritebackToken =
5532 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5533 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5534 bool ListContainsBase;
5535 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5536 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5537 "registers must be in range r0-r7");
5538 // If we should have writeback, then there should be a '!' token.
5539 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5540 return Error(Operands[2]->getStartLoc(),
5541 "writeback operator '!' expected");
5542 // If we should not have writeback, there must not be a '!'. This is
5543 // true even for the 32-bit wide encodings.
5544 if (ListContainsBase && HasWritebackToken)
5545 return Error(Operands[3]->getStartLoc(),
5546 "writeback operator '!' not allowed when base register "
5547 "in register list");
5551 case ARM::LDMIA_UPD:
5552 case ARM::LDMDB_UPD:
5553 case ARM::LDMIB_UPD:
5554 case ARM::LDMDA_UPD:
5555 // ARM variants loading and updating the same register are only officially
5556 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5560 case ARM::t2LDMIA_UPD:
5561 case ARM::t2LDMDB_UPD:
5562 case ARM::t2STMIA_UPD:
5563 case ARM::t2STMDB_UPD: {
5564 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5565 return Error(Operands.back()->getStartLoc(),
5566 "writeback register not allowed in register list");
5569 case ARM::sysLDMIA_UPD:
5570 case ARM::sysLDMDA_UPD:
5571 case ARM::sysLDMDB_UPD:
5572 case ARM::sysLDMIB_UPD:
5573 if (!listContainsReg(Inst, 3, ARM::PC))
5574 return Error(Operands[4]->getStartLoc(),
5575 "writeback register only allowed on system LDM "
5576 "if PC in register-list");
5578 case ARM::sysSTMIA_UPD:
5579 case ARM::sysSTMDA_UPD:
5580 case ARM::sysSTMDB_UPD:
5581 case ARM::sysSTMIB_UPD:
5582 return Error(Operands[2]->getStartLoc(),
5583 "system STM cannot have writeback register");
5586 // The second source operand must be the same register as the destination
5589 // In this case, we must directly check the parsed operands because the
5590 // cvtThumbMultiply() function is written in such a way that it guarantees
5591 // this first statement is always true for the new Inst. Essentially, the
5592 // destination is unconditionally copied into the second source operand
5593 // without checking to see if it matches what we actually parsed.
5594 if (Operands.size() == 6 &&
5595 (((ARMOperand*)Operands[3])->getReg() !=
5596 ((ARMOperand*)Operands[5])->getReg()) &&
5597 (((ARMOperand*)Operands[3])->getReg() !=
5598 ((ARMOperand*)Operands[4])->getReg())) {
5599 return Error(Operands[3]->getStartLoc(),
5600 "destination register must match source register");
5604 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5605 // so only issue a diagnostic for thumb1. The instructions will be
5606 // switched to the t2 encodings in processInstruction() if necessary.
5608 bool ListContainsBase;
5609 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5611 return Error(Operands[2]->getStartLoc(),
5612 "registers must be in range r0-r7 or pc");
5616 bool ListContainsBase;
5617 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5619 return Error(Operands[2]->getStartLoc(),
5620 "registers must be in range r0-r7 or lr");
5623 case ARM::tSTMIA_UPD: {
5624 bool ListContainsBase, InvalidLowList;
5625 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5626 0, ListContainsBase);
5627 if (InvalidLowList && !isThumbTwo())
5628 return Error(Operands[4]->getStartLoc(),
5629 "registers must be in range r0-r7");
5631 // This would be converted to a 32-bit stm, but that's not valid if the
5632 // writeback register is in the list.
5633 if (InvalidLowList && ListContainsBase)
5634 return Error(Operands[4]->getStartLoc(),
5635 "writeback operator '!' not allowed when base register "
5636 "in register list");
5639 case ARM::tADDrSP: {
5640 // If the non-SP source operand and the destination operand are not the
5641 // same, we need thumb2 (for the wide encoding), or we have an error.
5642 if (!isThumbTwo() &&
5643 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5644 return Error(Operands[4]->getStartLoc(),
5645 "source register must be the same as destination");
5649 // Final range checking for Thumb unconditional branch instructions.
5651 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5652 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5655 int op = (Operands[2]->isImm()) ? 2 : 3;
5656 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5657 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5660 // Final range checking for Thumb conditional branch instructions.
5662 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5663 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5666 int Op = (Operands[2]->isImm()) ? 2 : 3;
5667 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5668 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5676 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5678 default: llvm_unreachable("unexpected opcode!");
5680 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5681 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5682 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5683 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5684 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5685 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5686 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5687 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5688 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5691 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5692 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5693 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5694 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5695 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5697 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5698 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5699 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5700 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5701 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5703 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5704 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5705 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5706 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5707 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5710 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5711 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5712 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5713 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5714 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5715 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5716 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5717 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5718 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5719 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5720 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5721 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5722 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5723 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5724 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5727 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5728 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5729 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5730 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5731 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5732 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5733 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5734 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5735 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5736 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5737 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5738 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5739 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5740 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5741 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5742 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5743 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5744 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5747 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5748 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5749 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5750 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5751 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5752 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5753 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5754 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5755 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5756 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5757 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5758 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5759 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5760 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5761 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5764 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5765 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5766 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5767 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5768 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5769 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5770 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5771 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5772 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5773 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5774 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5775 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5776 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5777 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5778 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5779 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5780 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5781 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5785 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5787 default: llvm_unreachable("unexpected opcode!");
5789 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5790 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5791 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5792 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5793 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5794 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5795 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5796 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5797 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5800 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5801 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5802 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5803 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5804 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5805 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5806 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5807 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5808 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5809 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5810 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5811 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5812 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5813 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5814 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5817 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5818 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5819 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5820 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5821 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5822 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5823 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5824 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5825 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5826 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5827 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5828 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5829 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5830 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5831 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5832 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5833 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5834 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5837 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5838 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5839 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5840 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5841 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5842 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5843 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5844 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5845 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5846 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5847 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5848 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5849 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5850 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5851 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5854 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5855 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5856 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5857 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5858 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5859 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5860 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5861 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5862 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5863 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5864 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5865 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5866 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5867 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5868 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5869 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5870 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5871 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5874 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5875 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5876 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5877 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5878 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5879 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5880 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5881 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5882 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5883 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5884 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5885 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5886 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5887 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5888 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5891 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5892 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5893 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5894 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5895 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5896 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5897 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5898 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5899 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5900 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5901 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5902 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5903 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5904 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5905 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5906 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5907 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5908 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5911 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5912 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5913 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5914 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5915 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5916 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5917 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5918 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5919 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5920 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5921 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5922 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5923 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5924 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5925 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5926 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5927 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5928 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5933 processInstruction(MCInst &Inst,
5934 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5935 switch (Inst.getOpcode()) {
5936 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5938 if (Inst.getOperand(1).getReg() != ARM::PC ||
5939 Inst.getOperand(5).getReg() != 0)
5942 TmpInst.setOpcode(ARM::ADR);
5943 TmpInst.addOperand(Inst.getOperand(0));
5944 TmpInst.addOperand(Inst.getOperand(2));
5945 TmpInst.addOperand(Inst.getOperand(3));
5946 TmpInst.addOperand(Inst.getOperand(4));
5950 // Aliases for alternate PC+imm syntax of LDR instructions.
5951 case ARM::t2LDRpcrel:
5952 // Select the narrow version if the immediate will fit.
5953 if (Inst.getOperand(1).getImm() > 0 &&
5954 Inst.getOperand(1).getImm() <= 0xff &&
5955 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5956 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
5957 Inst.setOpcode(ARM::tLDRpci);
5959 Inst.setOpcode(ARM::t2LDRpci);
5961 case ARM::t2LDRBpcrel:
5962 Inst.setOpcode(ARM::t2LDRBpci);
5964 case ARM::t2LDRHpcrel:
5965 Inst.setOpcode(ARM::t2LDRHpci);
5967 case ARM::t2LDRSBpcrel:
5968 Inst.setOpcode(ARM::t2LDRSBpci);
5970 case ARM::t2LDRSHpcrel:
5971 Inst.setOpcode(ARM::t2LDRSHpci);
5973 // Handle NEON VST complex aliases.
5974 case ARM::VST1LNdWB_register_Asm_8:
5975 case ARM::VST1LNdWB_register_Asm_16:
5976 case ARM::VST1LNdWB_register_Asm_32: {
5978 // Shuffle the operands around so the lane index operand is in the
5981 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5982 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5983 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5984 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5985 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5986 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5987 TmpInst.addOperand(Inst.getOperand(1)); // lane
5988 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5989 TmpInst.addOperand(Inst.getOperand(6));
5994 case ARM::VST2LNdWB_register_Asm_8:
5995 case ARM::VST2LNdWB_register_Asm_16:
5996 case ARM::VST2LNdWB_register_Asm_32:
5997 case ARM::VST2LNqWB_register_Asm_16:
5998 case ARM::VST2LNqWB_register_Asm_32: {
6000 // Shuffle the operands around so the lane index operand is in the
6003 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6004 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6005 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6006 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6007 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6008 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6009 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6011 TmpInst.addOperand(Inst.getOperand(1)); // lane
6012 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6013 TmpInst.addOperand(Inst.getOperand(6));
6018 case ARM::VST3LNdWB_register_Asm_8:
6019 case ARM::VST3LNdWB_register_Asm_16:
6020 case ARM::VST3LNdWB_register_Asm_32:
6021 case ARM::VST3LNqWB_register_Asm_16:
6022 case ARM::VST3LNqWB_register_Asm_32: {
6024 // Shuffle the operands around so the lane index operand is in the
6027 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6028 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6029 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6030 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6031 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6032 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6033 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6035 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6037 TmpInst.addOperand(Inst.getOperand(1)); // lane
6038 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6039 TmpInst.addOperand(Inst.getOperand(6));
6044 case ARM::VST4LNdWB_register_Asm_8:
6045 case ARM::VST4LNdWB_register_Asm_16:
6046 case ARM::VST4LNdWB_register_Asm_32:
6047 case ARM::VST4LNqWB_register_Asm_16:
6048 case ARM::VST4LNqWB_register_Asm_32: {
6050 // Shuffle the operands around so the lane index operand is in the
6053 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6054 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6055 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6056 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6057 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6058 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6059 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6061 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6063 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6065 TmpInst.addOperand(Inst.getOperand(1)); // lane
6066 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6067 TmpInst.addOperand(Inst.getOperand(6));
6072 case ARM::VST1LNdWB_fixed_Asm_8:
6073 case ARM::VST1LNdWB_fixed_Asm_16:
6074 case ARM::VST1LNdWB_fixed_Asm_32: {
6076 // Shuffle the operands around so the lane index operand is in the
6079 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6080 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6081 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6082 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6083 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6084 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6085 TmpInst.addOperand(Inst.getOperand(1)); // lane
6086 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6087 TmpInst.addOperand(Inst.getOperand(5));
6092 case ARM::VST2LNdWB_fixed_Asm_8:
6093 case ARM::VST2LNdWB_fixed_Asm_16:
6094 case ARM::VST2LNdWB_fixed_Asm_32:
6095 case ARM::VST2LNqWB_fixed_Asm_16:
6096 case ARM::VST2LNqWB_fixed_Asm_32: {
6098 // Shuffle the operands around so the lane index operand is in the
6101 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6102 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6103 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6104 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6105 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6106 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6107 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6109 TmpInst.addOperand(Inst.getOperand(1)); // lane
6110 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6111 TmpInst.addOperand(Inst.getOperand(5));
6116 case ARM::VST3LNdWB_fixed_Asm_8:
6117 case ARM::VST3LNdWB_fixed_Asm_16:
6118 case ARM::VST3LNdWB_fixed_Asm_32:
6119 case ARM::VST3LNqWB_fixed_Asm_16:
6120 case ARM::VST3LNqWB_fixed_Asm_32: {
6122 // Shuffle the operands around so the lane index operand is in the
6125 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6126 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6127 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6128 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6129 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6130 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6131 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6135 TmpInst.addOperand(Inst.getOperand(1)); // lane
6136 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6137 TmpInst.addOperand(Inst.getOperand(5));
6142 case ARM::VST4LNdWB_fixed_Asm_8:
6143 case ARM::VST4LNdWB_fixed_Asm_16:
6144 case ARM::VST4LNdWB_fixed_Asm_32:
6145 case ARM::VST4LNqWB_fixed_Asm_16:
6146 case ARM::VST4LNqWB_fixed_Asm_32: {
6148 // Shuffle the operands around so the lane index operand is in the
6151 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6152 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6153 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6154 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6155 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6156 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6157 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6159 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6163 TmpInst.addOperand(Inst.getOperand(1)); // lane
6164 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6165 TmpInst.addOperand(Inst.getOperand(5));
6170 case ARM::VST1LNdAsm_8:
6171 case ARM::VST1LNdAsm_16:
6172 case ARM::VST1LNdAsm_32: {
6174 // Shuffle the operands around so the lane index operand is in the
6177 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6178 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6179 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6180 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6181 TmpInst.addOperand(Inst.getOperand(1)); // lane
6182 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6183 TmpInst.addOperand(Inst.getOperand(5));
6188 case ARM::VST2LNdAsm_8:
6189 case ARM::VST2LNdAsm_16:
6190 case ARM::VST2LNdAsm_32:
6191 case ARM::VST2LNqAsm_16:
6192 case ARM::VST2LNqAsm_32: {
6194 // Shuffle the operands around so the lane index operand is in the
6197 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6198 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6199 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6200 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6201 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 TmpInst.addOperand(Inst.getOperand(1)); // lane
6204 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6205 TmpInst.addOperand(Inst.getOperand(5));
6210 case ARM::VST3LNdAsm_8:
6211 case ARM::VST3LNdAsm_16:
6212 case ARM::VST3LNdAsm_32:
6213 case ARM::VST3LNqAsm_16:
6214 case ARM::VST3LNqAsm_32: {
6216 // Shuffle the operands around so the lane index operand is in the
6219 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6220 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6221 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6222 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6225 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6227 TmpInst.addOperand(Inst.getOperand(1)); // lane
6228 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6229 TmpInst.addOperand(Inst.getOperand(5));
6234 case ARM::VST4LNdAsm_8:
6235 case ARM::VST4LNdAsm_16:
6236 case ARM::VST4LNdAsm_32:
6237 case ARM::VST4LNqAsm_16:
6238 case ARM::VST4LNqAsm_32: {
6240 // Shuffle the operands around so the lane index operand is in the
6243 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6244 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6245 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6246 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 TmpInst.addOperand(Inst.getOperand(1)); // lane
6254 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6255 TmpInst.addOperand(Inst.getOperand(5));
6260 // Handle NEON VLD complex aliases.
6261 case ARM::VLD1LNdWB_register_Asm_8:
6262 case ARM::VLD1LNdWB_register_Asm_16:
6263 case ARM::VLD1LNdWB_register_Asm_32: {
6265 // Shuffle the operands around so the lane index operand is in the
6268 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6269 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6270 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6271 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6272 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6273 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6274 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6275 TmpInst.addOperand(Inst.getOperand(1)); // lane
6276 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6277 TmpInst.addOperand(Inst.getOperand(6));
6282 case ARM::VLD2LNdWB_register_Asm_8:
6283 case ARM::VLD2LNdWB_register_Asm_16:
6284 case ARM::VLD2LNdWB_register_Asm_32:
6285 case ARM::VLD2LNqWB_register_Asm_16:
6286 case ARM::VLD2LNqWB_register_Asm_32: {
6288 // Shuffle the operands around so the lane index operand is in the
6291 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6292 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6295 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6296 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6297 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6298 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6299 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 TmpInst.addOperand(Inst.getOperand(1)); // lane
6303 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6304 TmpInst.addOperand(Inst.getOperand(6));
6309 case ARM::VLD3LNdWB_register_Asm_8:
6310 case ARM::VLD3LNdWB_register_Asm_16:
6311 case ARM::VLD3LNdWB_register_Asm_32:
6312 case ARM::VLD3LNqWB_register_Asm_16:
6313 case ARM::VLD3LNqWB_register_Asm_32: {
6315 // Shuffle the operands around so the lane index operand is in the
6318 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6319 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6320 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6325 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6326 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6327 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6328 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6329 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6333 TmpInst.addOperand(Inst.getOperand(1)); // lane
6334 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6335 TmpInst.addOperand(Inst.getOperand(6));
6340 case ARM::VLD4LNdWB_register_Asm_8:
6341 case ARM::VLD4LNdWB_register_Asm_16:
6342 case ARM::VLD4LNdWB_register_Asm_32:
6343 case ARM::VLD4LNqWB_register_Asm_16:
6344 case ARM::VLD4LNqWB_register_Asm_32: {
6346 // Shuffle the operands around so the lane index operand is in the
6349 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6350 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6351 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6353 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6355 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6357 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6358 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6359 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6360 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6361 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6368 TmpInst.addOperand(Inst.getOperand(1)); // lane
6369 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6370 TmpInst.addOperand(Inst.getOperand(6));
6375 case ARM::VLD1LNdWB_fixed_Asm_8:
6376 case ARM::VLD1LNdWB_fixed_Asm_16:
6377 case ARM::VLD1LNdWB_fixed_Asm_32: {
6379 // Shuffle the operands around so the lane index operand is in the
6382 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6383 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6384 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6385 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6386 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6387 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6388 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6389 TmpInst.addOperand(Inst.getOperand(1)); // lane
6390 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6391 TmpInst.addOperand(Inst.getOperand(5));
6396 case ARM::VLD2LNdWB_fixed_Asm_8:
6397 case ARM::VLD2LNdWB_fixed_Asm_16:
6398 case ARM::VLD2LNdWB_fixed_Asm_32:
6399 case ARM::VLD2LNqWB_fixed_Asm_16:
6400 case ARM::VLD2LNqWB_fixed_Asm_32: {
6402 // Shuffle the operands around so the lane index operand is in the
6405 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6406 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6407 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6409 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6410 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6411 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6412 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6413 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6414 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6416 TmpInst.addOperand(Inst.getOperand(1)); // lane
6417 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6418 TmpInst.addOperand(Inst.getOperand(5));
6423 case ARM::VLD3LNdWB_fixed_Asm_8:
6424 case ARM::VLD3LNdWB_fixed_Asm_16:
6425 case ARM::VLD3LNdWB_fixed_Asm_32:
6426 case ARM::VLD3LNqWB_fixed_Asm_16:
6427 case ARM::VLD3LNqWB_fixed_Asm_32: {
6429 // Shuffle the operands around so the lane index operand is in the
6432 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6433 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6434 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6436 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6439 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6440 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6441 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6442 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 TmpInst.addOperand(Inst.getOperand(1)); // lane
6448 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6449 TmpInst.addOperand(Inst.getOperand(5));
6454 case ARM::VLD4LNdWB_fixed_Asm_8:
6455 case ARM::VLD4LNdWB_fixed_Asm_16:
6456 case ARM::VLD4LNdWB_fixed_Asm_32:
6457 case ARM::VLD4LNqWB_fixed_Asm_16:
6458 case ARM::VLD4LNqWB_fixed_Asm_32: {
6460 // Shuffle the operands around so the lane index operand is in the
6463 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6464 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6465 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6469 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6471 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6472 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6473 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6474 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6475 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6482 TmpInst.addOperand(Inst.getOperand(1)); // lane
6483 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6484 TmpInst.addOperand(Inst.getOperand(5));
6489 case ARM::VLD1LNdAsm_8:
6490 case ARM::VLD1LNdAsm_16:
6491 case ARM::VLD1LNdAsm_32: {
6493 // Shuffle the operands around so the lane index operand is in the
6496 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6497 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6498 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6499 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6500 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6501 TmpInst.addOperand(Inst.getOperand(1)); // lane
6502 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6503 TmpInst.addOperand(Inst.getOperand(5));
6508 case ARM::VLD2LNdAsm_8:
6509 case ARM::VLD2LNdAsm_16:
6510 case ARM::VLD2LNdAsm_32:
6511 case ARM::VLD2LNqAsm_16:
6512 case ARM::VLD2LNqAsm_32: {
6514 // Shuffle the operands around so the lane index operand is in the
6517 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6518 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6521 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6522 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6523 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 TmpInst.addOperand(Inst.getOperand(1)); // lane
6527 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6528 TmpInst.addOperand(Inst.getOperand(5));
6533 case ARM::VLD3LNdAsm_8:
6534 case ARM::VLD3LNdAsm_16:
6535 case ARM::VLD3LNdAsm_32:
6536 case ARM::VLD3LNqAsm_16:
6537 case ARM::VLD3LNqAsm_32: {
6539 // Shuffle the operands around so the lane index operand is in the
6542 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6543 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6544 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6546 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6548 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6549 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6550 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6551 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 TmpInst.addOperand(Inst.getOperand(1)); // lane
6556 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6557 TmpInst.addOperand(Inst.getOperand(5));
6562 case ARM::VLD4LNdAsm_8:
6563 case ARM::VLD4LNdAsm_16:
6564 case ARM::VLD4LNdAsm_32:
6565 case ARM::VLD4LNqAsm_16:
6566 case ARM::VLD4LNqAsm_32: {
6568 // Shuffle the operands around so the lane index operand is in the
6571 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6572 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6573 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6575 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6580 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6581 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6582 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6586 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6588 TmpInst.addOperand(Inst.getOperand(1)); // lane
6589 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6590 TmpInst.addOperand(Inst.getOperand(5));
6595 // VLD3DUP single 3-element structure to all lanes instructions.
6596 case ARM::VLD3DUPdAsm_8:
6597 case ARM::VLD3DUPdAsm_16:
6598 case ARM::VLD3DUPdAsm_32:
6599 case ARM::VLD3DUPqAsm_8:
6600 case ARM::VLD3DUPqAsm_16:
6601 case ARM::VLD3DUPqAsm_32: {
6604 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6605 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6606 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6608 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6610 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6611 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6612 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6613 TmpInst.addOperand(Inst.getOperand(4));
6618 case ARM::VLD3DUPdWB_fixed_Asm_8:
6619 case ARM::VLD3DUPdWB_fixed_Asm_16:
6620 case ARM::VLD3DUPdWB_fixed_Asm_32:
6621 case ARM::VLD3DUPqWB_fixed_Asm_8:
6622 case ARM::VLD3DUPqWB_fixed_Asm_16:
6623 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6626 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6627 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6628 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6630 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6632 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6633 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6634 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6635 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6636 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6637 TmpInst.addOperand(Inst.getOperand(4));
6642 case ARM::VLD3DUPdWB_register_Asm_8:
6643 case ARM::VLD3DUPdWB_register_Asm_16:
6644 case ARM::VLD3DUPdWB_register_Asm_32:
6645 case ARM::VLD3DUPqWB_register_Asm_8:
6646 case ARM::VLD3DUPqWB_register_Asm_16:
6647 case ARM::VLD3DUPqWB_register_Asm_32: {
6650 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6651 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6652 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6654 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6656 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6657 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6658 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6659 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6660 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6661 TmpInst.addOperand(Inst.getOperand(5));
6666 // VLD3 multiple 3-element structure instructions.
6667 case ARM::VLD3dAsm_8:
6668 case ARM::VLD3dAsm_16:
6669 case ARM::VLD3dAsm_32:
6670 case ARM::VLD3qAsm_8:
6671 case ARM::VLD3qAsm_16:
6672 case ARM::VLD3qAsm_32: {
6675 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6676 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6677 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6679 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6681 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6682 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6683 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6684 TmpInst.addOperand(Inst.getOperand(4));
6689 case ARM::VLD3dWB_fixed_Asm_8:
6690 case ARM::VLD3dWB_fixed_Asm_16:
6691 case ARM::VLD3dWB_fixed_Asm_32:
6692 case ARM::VLD3qWB_fixed_Asm_8:
6693 case ARM::VLD3qWB_fixed_Asm_16:
6694 case ARM::VLD3qWB_fixed_Asm_32: {
6697 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6698 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6699 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6701 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6703 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6704 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6705 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6706 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6707 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6708 TmpInst.addOperand(Inst.getOperand(4));
6713 case ARM::VLD3dWB_register_Asm_8:
6714 case ARM::VLD3dWB_register_Asm_16:
6715 case ARM::VLD3dWB_register_Asm_32:
6716 case ARM::VLD3qWB_register_Asm_8:
6717 case ARM::VLD3qWB_register_Asm_16:
6718 case ARM::VLD3qWB_register_Asm_32: {
6721 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6722 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6725 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6727 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6728 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6729 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6730 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6731 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6732 TmpInst.addOperand(Inst.getOperand(5));
6737 // VLD4DUP single 3-element structure to all lanes instructions.
6738 case ARM::VLD4DUPdAsm_8:
6739 case ARM::VLD4DUPdAsm_16:
6740 case ARM::VLD4DUPdAsm_32:
6741 case ARM::VLD4DUPqAsm_8:
6742 case ARM::VLD4DUPqAsm_16:
6743 case ARM::VLD4DUPqAsm_32: {
6746 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6747 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6750 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6752 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6754 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6755 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6756 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6757 TmpInst.addOperand(Inst.getOperand(4));
6762 case ARM::VLD4DUPdWB_fixed_Asm_8:
6763 case ARM::VLD4DUPdWB_fixed_Asm_16:
6764 case ARM::VLD4DUPdWB_fixed_Asm_32:
6765 case ARM::VLD4DUPqWB_fixed_Asm_8:
6766 case ARM::VLD4DUPqWB_fixed_Asm_16:
6767 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6770 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6771 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6772 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6774 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6776 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6778 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6779 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6780 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6781 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6782 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6783 TmpInst.addOperand(Inst.getOperand(4));
6788 case ARM::VLD4DUPdWB_register_Asm_8:
6789 case ARM::VLD4DUPdWB_register_Asm_16:
6790 case ARM::VLD4DUPdWB_register_Asm_32:
6791 case ARM::VLD4DUPqWB_register_Asm_8:
6792 case ARM::VLD4DUPqWB_register_Asm_16:
6793 case ARM::VLD4DUPqWB_register_Asm_32: {
6796 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6797 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6798 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6800 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6802 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6804 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6805 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6806 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6807 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6808 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6809 TmpInst.addOperand(Inst.getOperand(5));
6814 // VLD4 multiple 4-element structure instructions.
6815 case ARM::VLD4dAsm_8:
6816 case ARM::VLD4dAsm_16:
6817 case ARM::VLD4dAsm_32:
6818 case ARM::VLD4qAsm_8:
6819 case ARM::VLD4qAsm_16:
6820 case ARM::VLD4qAsm_32: {
6823 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6824 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6825 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6827 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6831 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6832 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6833 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6834 TmpInst.addOperand(Inst.getOperand(4));
6839 case ARM::VLD4dWB_fixed_Asm_8:
6840 case ARM::VLD4dWB_fixed_Asm_16:
6841 case ARM::VLD4dWB_fixed_Asm_32:
6842 case ARM::VLD4qWB_fixed_Asm_8:
6843 case ARM::VLD4qWB_fixed_Asm_16:
6844 case ARM::VLD4qWB_fixed_Asm_32: {
6847 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6848 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6855 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6856 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6857 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6858 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6859 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6860 TmpInst.addOperand(Inst.getOperand(4));
6865 case ARM::VLD4dWB_register_Asm_8:
6866 case ARM::VLD4dWB_register_Asm_16:
6867 case ARM::VLD4dWB_register_Asm_32:
6868 case ARM::VLD4qWB_register_Asm_8:
6869 case ARM::VLD4qWB_register_Asm_16:
6870 case ARM::VLD4qWB_register_Asm_32: {
6873 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6874 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6881 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6882 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6883 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6884 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6885 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6886 TmpInst.addOperand(Inst.getOperand(5));
6891 // VST3 multiple 3-element structure instructions.
6892 case ARM::VST3dAsm_8:
6893 case ARM::VST3dAsm_16:
6894 case ARM::VST3dAsm_32:
6895 case ARM::VST3qAsm_8:
6896 case ARM::VST3qAsm_16:
6897 case ARM::VST3qAsm_32: {
6900 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6901 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6902 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6903 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6904 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6906 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6908 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6909 TmpInst.addOperand(Inst.getOperand(4));
6914 case ARM::VST3dWB_fixed_Asm_8:
6915 case ARM::VST3dWB_fixed_Asm_16:
6916 case ARM::VST3dWB_fixed_Asm_32:
6917 case ARM::VST3qWB_fixed_Asm_8:
6918 case ARM::VST3qWB_fixed_Asm_16:
6919 case ARM::VST3qWB_fixed_Asm_32: {
6922 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6923 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6924 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6925 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6926 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6927 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6928 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6930 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6932 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6933 TmpInst.addOperand(Inst.getOperand(4));
6938 case ARM::VST3dWB_register_Asm_8:
6939 case ARM::VST3dWB_register_Asm_16:
6940 case ARM::VST3dWB_register_Asm_32:
6941 case ARM::VST3qWB_register_Asm_8:
6942 case ARM::VST3qWB_register_Asm_16:
6943 case ARM::VST3qWB_register_Asm_32: {
6946 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6947 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6948 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6949 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6950 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6951 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6952 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6954 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6956 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6957 TmpInst.addOperand(Inst.getOperand(5));
6962 // VST4 multiple 3-element structure instructions.
6963 case ARM::VST4dAsm_8:
6964 case ARM::VST4dAsm_16:
6965 case ARM::VST4dAsm_32:
6966 case ARM::VST4qAsm_8:
6967 case ARM::VST4qAsm_16:
6968 case ARM::VST4qAsm_32: {
6971 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6972 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6973 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6974 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6975 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6981 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6982 TmpInst.addOperand(Inst.getOperand(4));
6987 case ARM::VST4dWB_fixed_Asm_8:
6988 case ARM::VST4dWB_fixed_Asm_16:
6989 case ARM::VST4dWB_fixed_Asm_32:
6990 case ARM::VST4qWB_fixed_Asm_8:
6991 case ARM::VST4qWB_fixed_Asm_16:
6992 case ARM::VST4qWB_fixed_Asm_32: {
6995 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6996 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6997 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6998 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6999 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7000 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7001 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7003 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7007 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7008 TmpInst.addOperand(Inst.getOperand(4));
7013 case ARM::VST4dWB_register_Asm_8:
7014 case ARM::VST4dWB_register_Asm_16:
7015 case ARM::VST4dWB_register_Asm_32:
7016 case ARM::VST4qWB_register_Asm_8:
7017 case ARM::VST4qWB_register_Asm_16:
7018 case ARM::VST4qWB_register_Asm_32: {
7021 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7022 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7023 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7024 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7025 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7026 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7029 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7031 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7033 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7034 TmpInst.addOperand(Inst.getOperand(5));
7039 // Handle encoding choice for the shift-immediate instructions.
7042 case ARM::t2ASRri: {
7043 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7044 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7045 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7046 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7047 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7049 switch (Inst.getOpcode()) {
7050 default: llvm_unreachable("unexpected opcode");
7051 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7052 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7053 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7055 // The Thumb1 operands aren't in the same order. Awesome, eh?
7057 TmpInst.setOpcode(NewOpc);
7058 TmpInst.addOperand(Inst.getOperand(0));
7059 TmpInst.addOperand(Inst.getOperand(5));
7060 TmpInst.addOperand(Inst.getOperand(1));
7061 TmpInst.addOperand(Inst.getOperand(2));
7062 TmpInst.addOperand(Inst.getOperand(3));
7063 TmpInst.addOperand(Inst.getOperand(4));
7070 // Handle the Thumb2 mode MOV complex aliases.
7072 case ARM::t2MOVSsr: {
7073 // Which instruction to expand to depends on the CCOut operand and
7074 // whether we're in an IT block if the register operands are low
7076 bool isNarrow = false;
7077 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7078 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7079 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7080 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7081 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7085 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7086 default: llvm_unreachable("unexpected opcode!");
7087 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7088 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7089 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7090 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7092 TmpInst.setOpcode(newOpc);
7093 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7095 TmpInst.addOperand(MCOperand::CreateReg(
7096 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7097 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7098 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7099 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7100 TmpInst.addOperand(Inst.getOperand(5));
7102 TmpInst.addOperand(MCOperand::CreateReg(
7103 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7108 case ARM::t2MOVSsi: {
7109 // Which instruction to expand to depends on the CCOut operand and
7110 // whether we're in an IT block if the register operands are low
7112 bool isNarrow = false;
7113 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7114 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7115 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7119 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7120 default: llvm_unreachable("unexpected opcode!");
7121 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7122 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7123 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7124 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7125 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7127 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7128 if (Amount == 32) Amount = 0;
7129 TmpInst.setOpcode(newOpc);
7130 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7132 TmpInst.addOperand(MCOperand::CreateReg(
7133 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7134 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7135 if (newOpc != ARM::t2RRX)
7136 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7137 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7138 TmpInst.addOperand(Inst.getOperand(4));
7140 TmpInst.addOperand(MCOperand::CreateReg(
7141 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7145 // Handle the ARM mode MOV complex aliases.
7150 ARM_AM::ShiftOpc ShiftTy;
7151 switch(Inst.getOpcode()) {
7152 default: llvm_unreachable("unexpected opcode!");
7153 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7154 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7155 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7156 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7158 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7160 TmpInst.setOpcode(ARM::MOVsr);
7161 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7162 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7163 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7164 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7165 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7166 TmpInst.addOperand(Inst.getOperand(4));
7167 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7175 ARM_AM::ShiftOpc ShiftTy;
7176 switch(Inst.getOpcode()) {
7177 default: llvm_unreachable("unexpected opcode!");
7178 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7179 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7180 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7181 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7183 // A shift by zero is a plain MOVr, not a MOVsi.
7184 unsigned Amt = Inst.getOperand(2).getImm();
7185 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7186 // A shift by 32 should be encoded as 0 when permitted
7187 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7189 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7191 TmpInst.setOpcode(Opc);
7192 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7193 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7194 if (Opc == ARM::MOVsi)
7195 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7196 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7197 TmpInst.addOperand(Inst.getOperand(4));
7198 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7203 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7205 TmpInst.setOpcode(ARM::MOVsi);
7206 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7207 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7208 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7209 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7210 TmpInst.addOperand(Inst.getOperand(3));
7211 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7215 case ARM::t2LDMIA_UPD: {
7216 // If this is a load of a single register, then we should use
7217 // a post-indexed LDR instruction instead, per the ARM ARM.
7218 if (Inst.getNumOperands() != 5)
7221 TmpInst.setOpcode(ARM::t2LDR_POST);
7222 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7223 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7224 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7225 TmpInst.addOperand(MCOperand::CreateImm(4));
7226 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7227 TmpInst.addOperand(Inst.getOperand(3));
7231 case ARM::t2STMDB_UPD: {
7232 // If this is a store of a single register, then we should use
7233 // a pre-indexed STR instruction instead, per the ARM ARM.
7234 if (Inst.getNumOperands() != 5)
7237 TmpInst.setOpcode(ARM::t2STR_PRE);
7238 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7239 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7240 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7241 TmpInst.addOperand(MCOperand::CreateImm(-4));
7242 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7243 TmpInst.addOperand(Inst.getOperand(3));
7247 case ARM::LDMIA_UPD:
7248 // If this is a load of a single register via a 'pop', then we should use
7249 // a post-indexed LDR instruction instead, per the ARM ARM.
7250 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7251 Inst.getNumOperands() == 5) {
7253 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7254 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7255 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7256 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7257 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7258 TmpInst.addOperand(MCOperand::CreateImm(4));
7259 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7260 TmpInst.addOperand(Inst.getOperand(3));
7265 case ARM::STMDB_UPD:
7266 // If this is a store of a single register via a 'push', then we should use
7267 // a pre-indexed STR instruction instead, per the ARM ARM.
7268 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7269 Inst.getNumOperands() == 5) {
7271 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7272 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7273 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7274 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7275 TmpInst.addOperand(MCOperand::CreateImm(-4));
7276 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7277 TmpInst.addOperand(Inst.getOperand(3));
7281 case ARM::t2ADDri12:
7282 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7283 // mnemonic was used (not "addw"), encoding T3 is preferred.
7284 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7285 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7287 Inst.setOpcode(ARM::t2ADDri);
7288 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7290 case ARM::t2SUBri12:
7291 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7292 // mnemonic was used (not "subw"), encoding T3 is preferred.
7293 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7294 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7296 Inst.setOpcode(ARM::t2SUBri);
7297 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7300 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7301 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7302 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7303 // to encoding T1 if <Rd> is omitted."
7304 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7305 Inst.setOpcode(ARM::tADDi3);
7310 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7311 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7312 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7313 // to encoding T1 if <Rd> is omitted."
7314 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7315 Inst.setOpcode(ARM::tSUBi3);
7320 case ARM::t2SUBri: {
7321 // If the destination and first source operand are the same, and
7322 // the flags are compatible with the current IT status, use encoding T2
7323 // instead of T3. For compatibility with the system 'as'. Make sure the
7324 // wide encoding wasn't explicit.
7325 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7326 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7327 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7328 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7329 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7330 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7331 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7334 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7335 ARM::tADDi8 : ARM::tSUBi8);
7336 TmpInst.addOperand(Inst.getOperand(0));
7337 TmpInst.addOperand(Inst.getOperand(5));
7338 TmpInst.addOperand(Inst.getOperand(0));
7339 TmpInst.addOperand(Inst.getOperand(2));
7340 TmpInst.addOperand(Inst.getOperand(3));
7341 TmpInst.addOperand(Inst.getOperand(4));
7345 case ARM::t2ADDrr: {
7346 // If the destination and first source operand are the same, and
7347 // there's no setting of the flags, use encoding T2 instead of T3.
7348 // Note that this is only for ADD, not SUB. This mirrors the system
7349 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7350 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7351 Inst.getOperand(5).getReg() != 0 ||
7352 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7353 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7356 TmpInst.setOpcode(ARM::tADDhirr);
7357 TmpInst.addOperand(Inst.getOperand(0));
7358 TmpInst.addOperand(Inst.getOperand(0));
7359 TmpInst.addOperand(Inst.getOperand(2));
7360 TmpInst.addOperand(Inst.getOperand(3));
7361 TmpInst.addOperand(Inst.getOperand(4));
7365 case ARM::tADDrSP: {
7366 // If the non-SP source operand and the destination operand are not the
7367 // same, we need to use the 32-bit encoding if it's available.
7368 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7369 Inst.setOpcode(ARM::t2ADDrr);
7370 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7376 // A Thumb conditional branch outside of an IT block is a tBcc.
7377 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7378 Inst.setOpcode(ARM::tBcc);
7383 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7384 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7385 Inst.setOpcode(ARM::t2Bcc);
7390 // If the conditional is AL or we're in an IT block, we really want t2B.
7391 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7392 Inst.setOpcode(ARM::t2B);
7397 // If the conditional is AL, we really want tB.
7398 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7399 Inst.setOpcode(ARM::tB);
7404 // If the register list contains any high registers, or if the writeback
7405 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7406 // instead if we're in Thumb2. Otherwise, this should have generated
7407 // an error in validateInstruction().
7408 unsigned Rn = Inst.getOperand(0).getReg();
7409 bool hasWritebackToken =
7410 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7411 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7412 bool listContainsBase;
7413 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7414 (!listContainsBase && !hasWritebackToken) ||
7415 (listContainsBase && hasWritebackToken)) {
7416 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7417 assert (isThumbTwo());
7418 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7419 // If we're switching to the updating version, we need to insert
7420 // the writeback tied operand.
7421 if (hasWritebackToken)
7422 Inst.insert(Inst.begin(),
7423 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7428 case ARM::tSTMIA_UPD: {
7429 // If the register list contains any high registers, we need to use
7430 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7431 // should have generated an error in validateInstruction().
7432 unsigned Rn = Inst.getOperand(0).getReg();
7433 bool listContainsBase;
7434 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7435 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7436 assert (isThumbTwo());
7437 Inst.setOpcode(ARM::t2STMIA_UPD);
7443 bool listContainsBase;
7444 // If the register list contains any high registers, we need to use
7445 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7446 // should have generated an error in validateInstruction().
7447 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7449 assert (isThumbTwo());
7450 Inst.setOpcode(ARM::t2LDMIA_UPD);
7451 // Add the base register and writeback operands.
7452 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7453 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7457 bool listContainsBase;
7458 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7460 assert (isThumbTwo());
7461 Inst.setOpcode(ARM::t2STMDB_UPD);
7462 // Add the base register and writeback operands.
7463 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7464 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7468 // If we can use the 16-bit encoding and the user didn't explicitly
7469 // request the 32-bit variant, transform it here.
7470 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7471 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7472 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7473 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7474 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7475 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7476 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7477 // The operands aren't in the same order for tMOVi8...
7479 TmpInst.setOpcode(ARM::tMOVi8);
7480 TmpInst.addOperand(Inst.getOperand(0));
7481 TmpInst.addOperand(Inst.getOperand(4));
7482 TmpInst.addOperand(Inst.getOperand(1));
7483 TmpInst.addOperand(Inst.getOperand(2));
7484 TmpInst.addOperand(Inst.getOperand(3));
7491 // If we can use the 16-bit encoding and the user didn't explicitly
7492 // request the 32-bit variant, transform it here.
7493 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7494 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7495 Inst.getOperand(2).getImm() == ARMCC::AL &&
7496 Inst.getOperand(4).getReg() == ARM::CPSR &&
7497 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7498 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7499 // The operands aren't the same for tMOV[S]r... (no cc_out)
7501 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7502 TmpInst.addOperand(Inst.getOperand(0));
7503 TmpInst.addOperand(Inst.getOperand(1));
7504 TmpInst.addOperand(Inst.getOperand(2));
7505 TmpInst.addOperand(Inst.getOperand(3));
7515 // If we can use the 16-bit encoding and the user didn't explicitly
7516 // request the 32-bit variant, transform it here.
7517 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7518 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7519 Inst.getOperand(2).getImm() == 0 &&
7520 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7521 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7523 switch (Inst.getOpcode()) {
7524 default: llvm_unreachable("Illegal opcode!");
7525 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7526 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7527 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7528 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7530 // The operands aren't the same for thumb1 (no rotate operand).
7532 TmpInst.setOpcode(NewOpc);
7533 TmpInst.addOperand(Inst.getOperand(0));
7534 TmpInst.addOperand(Inst.getOperand(1));
7535 TmpInst.addOperand(Inst.getOperand(3));
7536 TmpInst.addOperand(Inst.getOperand(4));
7543 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7544 // rrx shifts and asr/lsr of #32 is encoded as 0
7545 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7547 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7548 // Shifting by zero is accepted as a vanilla 'MOVr'
7550 TmpInst.setOpcode(ARM::MOVr);
7551 TmpInst.addOperand(Inst.getOperand(0));
7552 TmpInst.addOperand(Inst.getOperand(1));
7553 TmpInst.addOperand(Inst.getOperand(3));
7554 TmpInst.addOperand(Inst.getOperand(4));
7555 TmpInst.addOperand(Inst.getOperand(5));
7568 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7569 if (SOpc == ARM_AM::rrx) return false;
7570 switch (Inst.getOpcode()) {
7571 default: llvm_unreachable("unexpected opcode!");
7572 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7573 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7574 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7575 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7576 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7577 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7579 // If the shift is by zero, use the non-shifted instruction definition.
7580 // The exception is for right shifts, where 0 == 32
7581 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7582 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7584 TmpInst.setOpcode(newOpc);
7585 TmpInst.addOperand(Inst.getOperand(0));
7586 TmpInst.addOperand(Inst.getOperand(1));
7587 TmpInst.addOperand(Inst.getOperand(2));
7588 TmpInst.addOperand(Inst.getOperand(4));
7589 TmpInst.addOperand(Inst.getOperand(5));
7590 TmpInst.addOperand(Inst.getOperand(6));
7598 // The mask bits for all but the first condition are represented as
7599 // the low bit of the condition code value implies 't'. We currently
7600 // always have 1 implies 't', so XOR toggle the bits if the low bit
7601 // of the condition code is zero.
7602 MCOperand &MO = Inst.getOperand(1);
7603 unsigned Mask = MO.getImm();
7604 unsigned OrigMask = Mask;
7605 unsigned TZ = countTrailingZeros(Mask);
7606 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7607 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7608 Mask ^= (0xE << TZ) & 0xF;
7612 // Set up the IT block state according to the IT instruction we just
7614 assert(!inITBlock() && "nested IT blocks?!");
7615 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7616 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7617 ITState.CurPosition = 0;
7618 ITState.FirstCond = true;
7628 // Assemblers should use the narrow encodings of these instructions when permissible.
7629 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7630 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7631 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7632 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7633 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7634 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7635 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7637 switch (Inst.getOpcode()) {
7638 default: llvm_unreachable("unexpected opcode");
7639 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7640 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7641 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7642 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7643 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7644 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7647 TmpInst.setOpcode(NewOpc);
7648 TmpInst.addOperand(Inst.getOperand(0));
7649 TmpInst.addOperand(Inst.getOperand(5));
7650 TmpInst.addOperand(Inst.getOperand(1));
7651 TmpInst.addOperand(Inst.getOperand(2));
7652 TmpInst.addOperand(Inst.getOperand(3));
7653 TmpInst.addOperand(Inst.getOperand(4));
7664 // Assemblers should use the narrow encodings of these instructions when permissible.
7665 // These instructions are special in that they are commutable, so shorter encodings
7666 // are available more often.
7667 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7668 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7669 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7670 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7671 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7672 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7673 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7674 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7676 switch (Inst.getOpcode()) {
7677 default: llvm_unreachable("unexpected opcode");
7678 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7679 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7680 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7681 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7684 TmpInst.setOpcode(NewOpc);
7685 TmpInst.addOperand(Inst.getOperand(0));
7686 TmpInst.addOperand(Inst.getOperand(5));
7687 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7688 TmpInst.addOperand(Inst.getOperand(1));
7689 TmpInst.addOperand(Inst.getOperand(2));
7691 TmpInst.addOperand(Inst.getOperand(2));
7692 TmpInst.addOperand(Inst.getOperand(1));
7694 TmpInst.addOperand(Inst.getOperand(3));
7695 TmpInst.addOperand(Inst.getOperand(4));
7705 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7706 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7707 // suffix depending on whether they're in an IT block or not.
7708 unsigned Opc = Inst.getOpcode();
7709 const MCInstrDesc &MCID = MII.get(Opc);
7710 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7711 assert(MCID.hasOptionalDef() &&
7712 "optionally flag setting instruction missing optional def operand");
7713 assert(MCID.NumOperands == Inst.getNumOperands() &&
7714 "operand count mismatch!");
7715 // Find the optional-def operand (cc_out).
7718 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7721 // If we're parsing Thumb1, reject it completely.
7722 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7723 return Match_MnemonicFail;
7724 // If we're parsing Thumb2, which form is legal depends on whether we're
7726 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7728 return Match_RequiresITBlock;
7729 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7731 return Match_RequiresNotITBlock;
7733 // Some high-register supporting Thumb1 encodings only allow both registers
7734 // to be from r0-r7 when in Thumb2.
7735 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7736 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7737 isARMLowRegister(Inst.getOperand(2).getReg()))
7738 return Match_RequiresThumb2;
7739 // Others only require ARMv6 or later.
7740 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7741 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7742 isARMLowRegister(Inst.getOperand(1).getReg()))
7743 return Match_RequiresV6;
7744 return Match_Success;
7747 static const char *getSubtargetFeatureName(unsigned Val);
7749 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7750 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7751 MCStreamer &Out, unsigned &ErrorInfo,
7752 bool MatchingInlineAsm) {
7754 unsigned MatchResult;
7756 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7758 switch (MatchResult) {
7761 // Context sensitive operand constraints aren't handled by the matcher,
7762 // so check them here.
7763 if (validateInstruction(Inst, Operands)) {
7764 // Still progress the IT block, otherwise one wrong condition causes
7765 // nasty cascading errors.
7766 forwardITPosition();
7770 { // processInstruction() updates inITBlock state, we need to save it away
7771 bool wasInITBlock = inITBlock();
7773 // Some instructions need post-processing to, for example, tweak which
7774 // encoding is selected. Loop on it while changes happen so the
7775 // individual transformations can chain off each other. E.g.,
7776 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7777 while (processInstruction(Inst, Operands))
7780 // Only after the instruction is fully processed, we can validate it
7781 if (wasInITBlock && hasV8Ops() && isThumb() &&
7782 !isV8EligibleForIT(&Inst, 2)) {
7783 Warning(IDLoc, "deprecated instruction in IT block");
7787 // Only move forward at the very end so that everything in validate
7788 // and process gets a consistent answer about whether we're in an IT
7790 forwardITPosition();
7792 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7793 // doesn't actually encode.
7794 if (Inst.getOpcode() == ARM::ITasm)
7798 Out.EmitInstruction(Inst);
7800 case Match_MissingFeature: {
7801 assert(ErrorInfo && "Unknown missing feature!");
7802 // Special case the error message for the very common case where only
7803 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7804 std::string Msg = "instruction requires:";
7806 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7807 if (ErrorInfo & Mask) {
7809 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7813 return Error(IDLoc, Msg);
7815 case Match_InvalidOperand: {
7816 SMLoc ErrorLoc = IDLoc;
7817 if (ErrorInfo != ~0U) {
7818 if (ErrorInfo >= Operands.size())
7819 return Error(IDLoc, "too few operands for instruction");
7821 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7822 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7825 return Error(ErrorLoc, "invalid operand for instruction");
7827 case Match_MnemonicFail:
7828 return Error(IDLoc, "invalid instruction",
7829 ((ARMOperand*)Operands[0])->getLocRange());
7830 case Match_RequiresNotITBlock:
7831 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7832 case Match_RequiresITBlock:
7833 return Error(IDLoc, "instruction only valid inside IT block");
7834 case Match_RequiresV6:
7835 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7836 case Match_RequiresThumb2:
7837 return Error(IDLoc, "instruction variant requires Thumb2");
7838 case Match_ImmRange0_15: {
7839 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7840 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7841 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7843 case Match_ImmRange0_239: {
7844 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7845 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7846 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7850 llvm_unreachable("Implement any new match types added!");
7853 /// parseDirective parses the arm specific directives
7854 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7855 StringRef IDVal = DirectiveID.getIdentifier();
7856 if (IDVal == ".word")
7857 return parseDirectiveWord(4, DirectiveID.getLoc());
7858 else if (IDVal == ".thumb")
7859 return parseDirectiveThumb(DirectiveID.getLoc());
7860 else if (IDVal == ".arm")
7861 return parseDirectiveARM(DirectiveID.getLoc());
7862 else if (IDVal == ".thumb_func")
7863 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7864 else if (IDVal == ".code")
7865 return parseDirectiveCode(DirectiveID.getLoc());
7866 else if (IDVal == ".syntax")
7867 return parseDirectiveSyntax(DirectiveID.getLoc());
7868 else if (IDVal == ".unreq")
7869 return parseDirectiveUnreq(DirectiveID.getLoc());
7870 else if (IDVal == ".arch")
7871 return parseDirectiveArch(DirectiveID.getLoc());
7872 else if (IDVal == ".eabi_attribute")
7873 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7874 else if (IDVal == ".cpu")
7875 return parseDirectiveCPU(DirectiveID.getLoc());
7876 else if (IDVal == ".fpu")
7877 return parseDirectiveFPU(DirectiveID.getLoc());
7878 else if (IDVal == ".fnstart")
7879 return parseDirectiveFnStart(DirectiveID.getLoc());
7880 else if (IDVal == ".fnend")
7881 return parseDirectiveFnEnd(DirectiveID.getLoc());
7882 else if (IDVal == ".cantunwind")
7883 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7884 else if (IDVal == ".personality")
7885 return parseDirectivePersonality(DirectiveID.getLoc());
7886 else if (IDVal == ".handlerdata")
7887 return parseDirectiveHandlerData(DirectiveID.getLoc());
7888 else if (IDVal == ".setfp")
7889 return parseDirectiveSetFP(DirectiveID.getLoc());
7890 else if (IDVal == ".pad")
7891 return parseDirectivePad(DirectiveID.getLoc());
7892 else if (IDVal == ".save")
7893 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7894 else if (IDVal == ".vsave")
7895 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7896 else if (IDVal == ".inst")
7897 return parseDirectiveInst(DirectiveID.getLoc());
7898 else if (IDVal == ".inst.n")
7899 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7900 else if (IDVal == ".inst.w")
7901 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
7902 else if (IDVal == ".ltorg")
7903 return parseDirectiveLtorg(DirectiveID.getLoc());
7907 /// parseDirectiveWord
7908 /// ::= .word [ expression (, expression)* ]
7909 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7910 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7912 const MCExpr *Value;
7913 if (getParser().parseExpression(Value))
7916 getParser().getStreamer().EmitValue(Value, Size);
7918 if (getLexer().is(AsmToken::EndOfStatement))
7921 // FIXME: Improve diagnostic.
7922 if (getLexer().isNot(AsmToken::Comma))
7923 return Error(L, "unexpected token in directive");
7932 /// parseDirectiveThumb
7934 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7935 if (getLexer().isNot(AsmToken::EndOfStatement))
7936 return Error(L, "unexpected token in directive");
7940 return Error(L, "target does not support Thumb mode");
7944 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7948 /// parseDirectiveARM
7950 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7951 if (getLexer().isNot(AsmToken::EndOfStatement))
7952 return Error(L, "unexpected token in directive");
7956 return Error(L, "target does not support ARM mode");
7960 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
7964 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7965 if (NextSymbolIsThumb) {
7966 getParser().getStreamer().EmitThumbFunc(Symbol);
7967 NextSymbolIsThumb = false;
7971 /// parseDirectiveThumbFunc
7972 /// ::= .thumbfunc symbol_name
7973 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
7974 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7975 bool isMachO = MAI->hasSubsectionsViaSymbols();
7977 // Darwin asm has (optionally) function name after .thumb_func direction
7980 const AsmToken &Tok = Parser.getTok();
7981 if (Tok.isNot(AsmToken::EndOfStatement)) {
7982 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7983 return Error(L, "unexpected token in .thumb_func directive");
7985 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
7986 getParser().getStreamer().EmitThumbFunc(Func);
7987 Parser.Lex(); // Consume the identifier token.
7992 if (getLexer().isNot(AsmToken::EndOfStatement))
7993 return Error(L, "unexpected token in directive");
7995 NextSymbolIsThumb = true;
8000 /// parseDirectiveSyntax
8001 /// ::= .syntax unified | divided
8002 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
8003 const AsmToken &Tok = Parser.getTok();
8004 if (Tok.isNot(AsmToken::Identifier))
8005 return Error(L, "unexpected token in .syntax directive");
8006 StringRef Mode = Tok.getString();
8007 if (Mode == "unified" || Mode == "UNIFIED")
8009 else if (Mode == "divided" || Mode == "DIVIDED")
8010 return Error(L, "'.syntax divided' arm asssembly not supported");
8012 return Error(L, "unrecognized syntax mode in .syntax directive");
8014 if (getLexer().isNot(AsmToken::EndOfStatement))
8015 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
8018 // TODO tell the MC streamer the mode
8019 // getParser().getStreamer().Emit???();
8023 /// parseDirectiveCode
8024 /// ::= .code 16 | 32
8025 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
8026 const AsmToken &Tok = Parser.getTok();
8027 if (Tok.isNot(AsmToken::Integer))
8028 return Error(L, "unexpected token in .code directive");
8029 int64_t Val = Parser.getTok().getIntVal();
8035 return Error(L, "invalid operand to .code directive");
8037 if (getLexer().isNot(AsmToken::EndOfStatement))
8038 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
8043 return Error(L, "target does not support Thumb mode");
8047 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8050 return Error(L, "target does not support ARM mode");
8054 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8060 /// parseDirectiveReq
8061 /// ::= name .req registername
8062 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8063 Parser.Lex(); // Eat the '.req' token.
8065 SMLoc SRegLoc, ERegLoc;
8066 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
8067 Parser.eatToEndOfStatement();
8068 return Error(SRegLoc, "register name expected");
8071 // Shouldn't be anything else.
8072 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
8073 Parser.eatToEndOfStatement();
8074 return Error(Parser.getTok().getLoc(),
8075 "unexpected input in .req directive.");
8078 Parser.Lex(); // Consume the EndOfStatement
8080 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
8081 return Error(SRegLoc, "redefinition of '" + Name +
8082 "' does not match original.");
8087 /// parseDirectiveUneq
8088 /// ::= .unreq registername
8089 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8090 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8091 Parser.eatToEndOfStatement();
8092 return Error(L, "unexpected input in .unreq directive.");
8094 RegisterReqs.erase(Parser.getTok().getIdentifier());
8095 Parser.Lex(); // Eat the identifier.
8099 /// parseDirectiveArch
8101 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8102 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8104 unsigned ID = StringSwitch<unsigned>(Arch)
8105 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8106 .Case(NAME, ARM::ID)
8107 #include "MCTargetDesc/ARMArchName.def"
8108 .Default(ARM::INVALID_ARCH);
8110 if (ID == ARM::INVALID_ARCH)
8111 return Error(L, "Unknown arch name");
8113 getTargetStreamer().emitArch(ID);
8117 /// parseDirectiveEabiAttr
8118 /// ::= .eabi_attribute int, int
8119 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8120 if (Parser.getTok().isNot(AsmToken::Integer))
8121 return Error(L, "integer expected");
8122 int64_t Tag = Parser.getTok().getIntVal();
8123 Parser.Lex(); // eat tag integer
8125 if (Parser.getTok().isNot(AsmToken::Comma))
8126 return Error(L, "comma expected");
8127 Parser.Lex(); // skip comma
8129 L = Parser.getTok().getLoc();
8130 if (Parser.getTok().isNot(AsmToken::Integer))
8131 return Error(L, "integer expected");
8132 int64_t Value = Parser.getTok().getIntVal();
8133 Parser.Lex(); // eat value integer
8135 getTargetStreamer().emitAttribute(Tag, Value);
8139 /// parseDirectiveCPU
8141 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8142 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8143 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8147 /// parseDirectiveFPU
8149 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8150 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8152 unsigned ID = StringSwitch<unsigned>(FPU)
8153 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8154 #include "ARMFPUName.def"
8155 .Default(ARM::INVALID_FPU);
8157 if (ID == ARM::INVALID_FPU)
8158 return Error(L, "Unknown FPU name");
8160 getTargetStreamer().emitFPU(ID);
8164 /// parseDirectiveFnStart
8166 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8167 if (FnStartLoc.isValid()) {
8168 Error(L, ".fnstart starts before the end of previous one");
8169 Error(FnStartLoc, "previous .fnstart starts here");
8174 getTargetStreamer().emitFnStart();
8178 /// parseDirectiveFnEnd
8180 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8181 // Check the ordering of unwind directives
8182 if (!FnStartLoc.isValid())
8183 return Error(L, ".fnstart must precede .fnend directive");
8185 // Reset the unwind directives parser state
8186 resetUnwindDirectiveParserState();
8187 getTargetStreamer().emitFnEnd();
8191 /// parseDirectiveCantUnwind
8193 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8194 // Check the ordering of unwind directives
8196 if (!FnStartLoc.isValid())
8197 return Error(L, ".fnstart must precede .cantunwind directive");
8198 if (HandlerDataLoc.isValid()) {
8199 Error(L, ".cantunwind can't be used with .handlerdata directive");
8200 Error(HandlerDataLoc, ".handlerdata was specified here");
8203 if (PersonalityLoc.isValid()) {
8204 Error(L, ".cantunwind can't be used with .personality directive");
8205 Error(PersonalityLoc, ".personality was specified here");
8209 getTargetStreamer().emitCantUnwind();
8213 /// parseDirectivePersonality
8214 /// ::= .personality name
8215 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8216 // Check the ordering of unwind directives
8218 if (!FnStartLoc.isValid())
8219 return Error(L, ".fnstart must precede .personality directive");
8220 if (CantUnwindLoc.isValid()) {
8221 Error(L, ".personality can't be used with .cantunwind directive");
8222 Error(CantUnwindLoc, ".cantunwind was specified here");
8225 if (HandlerDataLoc.isValid()) {
8226 Error(L, ".personality must precede .handlerdata directive");
8227 Error(HandlerDataLoc, ".handlerdata was specified here");
8231 // Parse the name of the personality routine
8232 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8233 Parser.eatToEndOfStatement();
8234 return Error(L, "unexpected input in .personality directive.");
8236 StringRef Name(Parser.getTok().getIdentifier());
8239 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8240 getTargetStreamer().emitPersonality(PR);
8244 /// parseDirectiveHandlerData
8245 /// ::= .handlerdata
8246 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8247 // Check the ordering of unwind directives
8249 if (!FnStartLoc.isValid())
8250 return Error(L, ".fnstart must precede .personality directive");
8251 if (CantUnwindLoc.isValid()) {
8252 Error(L, ".handlerdata can't be used with .cantunwind directive");
8253 Error(CantUnwindLoc, ".cantunwind was specified here");
8257 getTargetStreamer().emitHandlerData();
8261 /// parseDirectiveSetFP
8262 /// ::= .setfp fpreg, spreg [, offset]
8263 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8264 // Check the ordering of unwind directives
8265 if (!FnStartLoc.isValid())
8266 return Error(L, ".fnstart must precede .setfp directive");
8267 if (HandlerDataLoc.isValid())
8268 return Error(L, ".setfp must precede .handlerdata directive");
8271 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8272 int NewFPReg = tryParseRegister();
8274 return Error(NewFPRegLoc, "frame pointer register expected");
8277 if (!Parser.getTok().is(AsmToken::Comma))
8278 return Error(Parser.getTok().getLoc(), "comma expected");
8279 Parser.Lex(); // skip comma
8282 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8283 int NewSPReg = tryParseRegister();
8285 return Error(NewSPRegLoc, "stack pointer register expected");
8287 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8288 return Error(NewSPRegLoc,
8289 "register should be either $sp or the latest fp register");
8291 // Update the frame pointer register
8296 if (Parser.getTok().is(AsmToken::Comma)) {
8297 Parser.Lex(); // skip comma
8299 if (Parser.getTok().isNot(AsmToken::Hash) &&
8300 Parser.getTok().isNot(AsmToken::Dollar)) {
8301 return Error(Parser.getTok().getLoc(), "'#' expected");
8303 Parser.Lex(); // skip hash token.
8305 const MCExpr *OffsetExpr;
8306 SMLoc ExLoc = Parser.getTok().getLoc();
8308 if (getParser().parseExpression(OffsetExpr, EndLoc))
8309 return Error(ExLoc, "malformed setfp offset");
8310 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8312 return Error(ExLoc, "setfp offset must be an immediate");
8314 Offset = CE->getValue();
8317 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8318 static_cast<unsigned>(NewSPReg), Offset);
8324 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8325 // Check the ordering of unwind directives
8326 if (!FnStartLoc.isValid())
8327 return Error(L, ".fnstart must precede .pad directive");
8328 if (HandlerDataLoc.isValid())
8329 return Error(L, ".pad must precede .handlerdata directive");
8332 if (Parser.getTok().isNot(AsmToken::Hash) &&
8333 Parser.getTok().isNot(AsmToken::Dollar)) {
8334 return Error(Parser.getTok().getLoc(), "'#' expected");
8336 Parser.Lex(); // skip hash token.
8338 const MCExpr *OffsetExpr;
8339 SMLoc ExLoc = Parser.getTok().getLoc();
8341 if (getParser().parseExpression(OffsetExpr, EndLoc))
8342 return Error(ExLoc, "malformed pad offset");
8343 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8345 return Error(ExLoc, "pad offset must be an immediate");
8347 getTargetStreamer().emitPad(CE->getValue());
8351 /// parseDirectiveRegSave
8352 /// ::= .save { registers }
8353 /// ::= .vsave { registers }
8354 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8355 // Check the ordering of unwind directives
8356 if (!FnStartLoc.isValid())
8357 return Error(L, ".fnstart must precede .save or .vsave directives");
8358 if (HandlerDataLoc.isValid())
8359 return Error(L, ".save or .vsave must precede .handlerdata directive");
8361 // RAII object to make sure parsed operands are deleted.
8362 struct CleanupObject {
8363 SmallVector<MCParsedAsmOperand *, 1> Operands;
8365 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8370 // Parse the register list
8371 if (parseRegisterList(CO.Operands))
8373 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8374 if (!IsVector && !Op->isRegList())
8375 return Error(L, ".save expects GPR registers");
8376 if (IsVector && !Op->isDPRRegList())
8377 return Error(L, ".vsave expects DPR registers");
8379 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8383 /// parseDirectiveInst
8384 /// ::= .inst opcode [, ...]
8385 /// ::= .inst.n opcode [, ...]
8386 /// ::= .inst.w opcode [, ...]
8387 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8399 Parser.eatToEndOfStatement();
8400 return Error(Loc, "cannot determine Thumb instruction size, "
8401 "use inst.n/inst.w instead");
8405 Parser.eatToEndOfStatement();
8406 return Error(Loc, "width suffixes are invalid in ARM mode");
8411 if (getLexer().is(AsmToken::EndOfStatement)) {
8412 Parser.eatToEndOfStatement();
8413 return Error(Loc, "expected expression following directive");
8419 if (getParser().parseExpression(Expr))
8420 return Error(Loc, "expected expression");
8422 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8424 return Error(Loc, "expected constant expression");
8428 if (Value->getValue() > 0xffff)
8429 return Error(Loc, "inst.n operand is too big, use inst.w instead");
8432 if (Value->getValue() > 0xffffffff)
8434 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8437 llvm_unreachable("only supported widths are 2 and 4");
8440 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8442 if (getLexer().is(AsmToken::EndOfStatement))
8445 if (getLexer().isNot(AsmToken::Comma))
8446 return Error(Loc, "unexpected token in directive");
8455 /// parseDirectiveLtorg
8457 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
8458 MCStreamer &Streamer = getParser().getStreamer();
8459 const MCSection *Section = Streamer.getCurrentSection().first;
8461 if (ConstantPool *CP = getConstantPool(Section)) {
8462 CP->emitEntries(Streamer);
8464 destroyConstantPool(Section);
8469 /// Force static initialization.
8470 extern "C" void LLVMInitializeARMAsmParser() {
8471 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8472 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8475 #define GET_REGISTER_MATCHER
8476 #define GET_SUBTARGET_FEATURE_NAME
8477 #define GET_MATCHER_IMPLEMENTATION
8478 #include "ARMGenAsmMatcher.inc"
8480 // Define this matcher function after the auto-generated include so we
8481 // have the match class enum definitions.
8482 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8484 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8485 // If the kind is a token for a literal immediate, check if our asm
8486 // operand matches. This is for InstAliases which have a fixed-value
8487 // immediate in the syntax.
8488 if (Kind == MCK__35_0 && Op->isImm()) {
8489 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8491 return Match_InvalidOperand;
8492 if (CE->getValue() == 0)
8493 return Match_Success;
8495 return Match_InvalidOperand;
8498 void ARMAsmParser::finishParse() {
8499 // Dump contents of assembler constant pools.
8500 MCStreamer &Streamer = getParser().getStreamer();
8501 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8502 CPE = ConstantPools.end();
8503 CPI != CPE; ++CPI) {
8504 const MCSection *Section = CPI->first;
8505 ConstantPool &CP = CPI->second;
8507 // Dump assembler constant pools at the end of the section.
8508 Streamer.SwitchSection(Section);
8509 CP.emitEntries(Streamer);