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/MapVector.h"
20 #include "llvm/ADT/OwningPtr.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/StringSwitch.h"
25 #include "llvm/ADT/Twine.h"
26 #include "llvm/MC/MCAsmInfo.h"
27 #include "llvm/MC/MCAssembler.h"
28 #include "llvm/MC/MCContext.h"
29 #include "llvm/MC/MCDisassembler.h"
30 #include "llvm/MC/MCELFStreamer.h"
31 #include "llvm/MC/MCExpr.h"
32 #include "llvm/MC/MCInst.h"
33 #include "llvm/MC/MCInstrDesc.h"
34 #include "llvm/MC/MCInstrInfo.h"
35 #include "llvm/MC/MCSection.h"
36 #include "llvm/MC/MCParser/MCAsmLexer.h"
37 #include "llvm/MC/MCParser/MCAsmParser.h"
38 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
39 #include "llvm/MC/MCRegisterInfo.h"
40 #include "llvm/MC/MCStreamer.h"
41 #include "llvm/MC/MCSubtargetInfo.h"
42 #include "llvm/MC/MCSymbol.h"
43 #include "llvm/Support/Debug.h"
44 #include "llvm/Support/ELF.h"
45 #include "llvm/Support/MathExtras.h"
46 #include "llvm/Support/SourceMgr.h"
47 #include "llvm/Support/TargetRegistry.h"
48 #include "llvm/Support/raw_ostream.h"
56 enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
58 // A class to keep track of assembler-generated constant pools that are use to
59 // implement the ldr-pseudo.
61 typedef SmallVector<std::pair<MCSymbol *, const MCExpr *>, 4> EntryVecTy;
65 // Initialize a new empty constant pool
68 // Add a new entry to the constant pool in the next slot.
69 // \param Value is the new entry to put in the constant pool.
71 // \returns a MCExpr that references the newly inserted value
72 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context) {
73 MCSymbol *CPEntryLabel = Context.CreateTempSymbol();
75 Entries.push_back(std::make_pair(CPEntryLabel, Value));
76 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
79 // Emit the contents of the constant pool using the provided streamer.
80 void emitEntries(MCStreamer &Streamer) {
83 Streamer.EmitCodeAlignment(4); // align to 4-byte address
84 Streamer.EmitDataRegion(MCDR_DataRegion);
85 for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
87 Streamer.EmitLabel(I->first);
88 Streamer.EmitValue(I->second, 4);
90 Streamer.EmitDataRegion(MCDR_DataRegionEnd);
94 // Return true if the constant pool is empty
96 return Entries.empty();
100 // Map type used to keep track of per-Section constant pools used by the
101 // ldr-pseudo opcode. The map associates a section to its constant pool. The
102 // constant pool is a vector of (label, value) pairs. When the ldr
103 // pseudo is parsed we insert a new (label, value) pair into the constant pool
104 // for the current section and add MCSymbolRefExpr to the new label as
105 // an opcode to the ldr. After we have parsed all the user input we
106 // output the (label, value) pairs in each constant pool at the end of the
109 // We use the MapVector for the map type to ensure stable iteration of
110 // the sections at the end of the parse. We need to iterate over the
111 // sections in a stable order to ensure that we have print the
112 // constant pools in a deterministic order when printing an assembly
114 typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
116 class ARMAsmParser : public MCTargetAsmParser {
117 MCSubtargetInfo &STI;
119 const MCInstrInfo &MII;
120 const MCRegisterInfo *MRI;
121 ConstantPoolMapTy ConstantPools;
123 // Assembler created constant pools for ldr pseudo
124 ConstantPool *getConstantPool(const MCSection *Section) {
125 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
126 if (CP == ConstantPools.end())
132 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
133 return ConstantPools[Section];
136 ARMTargetStreamer &getTargetStreamer() {
137 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
138 return static_cast<ARMTargetStreamer &>(TS);
141 // Unwind directives state
144 SMLoc PersonalityLoc;
145 SMLoc HandlerDataLoc;
147 void resetUnwindDirectiveParserState() {
148 FnStartLoc = SMLoc();
149 CantUnwindLoc = SMLoc();
150 PersonalityLoc = SMLoc();
151 HandlerDataLoc = SMLoc();
155 // Map of register aliases registers via the .req directive.
156 StringMap<unsigned> RegisterReqs;
158 bool NextSymbolIsThumb;
161 ARMCC::CondCodes Cond; // Condition for IT block.
162 unsigned Mask:4; // Condition mask for instructions.
163 // Starting at first 1 (from lsb).
164 // '1' condition as indicated in IT.
165 // '0' inverse of condition (else).
166 // Count of instructions in IT block is
167 // 4 - trailingzeroes(mask)
169 bool FirstCond; // Explicit flag for when we're parsing the
170 // First instruction in the IT block. It's
171 // implied in the mask, so needs special
174 unsigned CurPosition; // Current position in parsing of IT
175 // block. In range [0,3]. Initialized
176 // according to count of instructions in block.
177 // ~0U if no active IT block.
179 bool inITBlock() { return ITState.CurPosition != ~0U;}
180 void forwardITPosition() {
181 if (!inITBlock()) return;
182 // Move to the next instruction in the IT block, if there is one. If not,
183 // mark the block as done.
184 unsigned TZ = countTrailingZeros(ITState.Mask);
185 if (++ITState.CurPosition == 5 - TZ)
186 ITState.CurPosition = ~0U; // Done with the IT block after this.
190 MCAsmParser &getParser() const { return Parser; }
191 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
193 bool Warning(SMLoc L, const Twine &Msg,
194 ArrayRef<SMRange> Ranges = None) {
195 return Parser.Warning(L, Msg, Ranges);
197 bool Error(SMLoc L, const Twine &Msg,
198 ArrayRef<SMRange> Ranges = None) {
199 return Parser.Error(L, Msg, Ranges);
202 int tryParseRegister();
203 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
204 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
205 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
206 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
207 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
208 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
209 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
210 unsigned &ShiftAmount);
211 bool parseDirectiveWord(unsigned Size, SMLoc L);
212 bool parseDirectiveThumb(SMLoc L);
213 bool parseDirectiveARM(SMLoc L);
214 bool parseDirectiveThumbFunc(SMLoc L);
215 bool parseDirectiveCode(SMLoc L);
216 bool parseDirectiveSyntax(SMLoc L);
217 bool parseDirectiveReq(StringRef Name, SMLoc L);
218 bool parseDirectiveUnreq(SMLoc L);
219 bool parseDirectiveArch(SMLoc L);
220 bool parseDirectiveEabiAttr(SMLoc L);
221 bool parseDirectiveCPU(SMLoc L);
222 bool parseDirectiveFPU(SMLoc L);
223 bool parseDirectiveFnStart(SMLoc L);
224 bool parseDirectiveFnEnd(SMLoc L);
225 bool parseDirectiveCantUnwind(SMLoc L);
226 bool parseDirectivePersonality(SMLoc L);
227 bool parseDirectiveHandlerData(SMLoc L);
228 bool parseDirectiveSetFP(SMLoc L);
229 bool parseDirectivePad(SMLoc L);
230 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
231 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
232 bool parseDirectiveLtorg(SMLoc L);
233 bool parseDirectiveEven(SMLoc L);
235 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
236 bool &CarrySetting, unsigned &ProcessorIMod,
238 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
239 bool &CanAcceptCarrySet,
240 bool &CanAcceptPredicationCode);
242 bool isThumb() const {
243 // FIXME: Can tablegen auto-generate this?
244 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
246 bool isThumbOne() const {
247 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
249 bool isThumbTwo() const {
250 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
252 bool hasThumb() const {
253 return STI.getFeatureBits() & ARM::HasV4TOps;
255 bool hasV6Ops() const {
256 return STI.getFeatureBits() & ARM::HasV6Ops;
258 bool hasV6MOps() const {
259 return STI.getFeatureBits() & ARM::HasV6MOps;
261 bool hasV7Ops() const {
262 return STI.getFeatureBits() & ARM::HasV7Ops;
264 bool hasV8Ops() const {
265 return STI.getFeatureBits() & ARM::HasV8Ops;
267 bool hasARM() const {
268 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
272 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
273 setAvailableFeatures(FB);
275 bool isMClass() const {
276 return STI.getFeatureBits() & ARM::FeatureMClass;
279 /// @name Auto-generated Match Functions
282 #define GET_ASSEMBLER_HEADER
283 #include "ARMGenAsmMatcher.inc"
287 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
288 OperandMatchResultTy parseCoprocNumOperand(
289 SmallVectorImpl<MCParsedAsmOperand*>&);
290 OperandMatchResultTy parseCoprocRegOperand(
291 SmallVectorImpl<MCParsedAsmOperand*>&);
292 OperandMatchResultTy parseCoprocOptionOperand(
293 SmallVectorImpl<MCParsedAsmOperand*>&);
294 OperandMatchResultTy parseMemBarrierOptOperand(
295 SmallVectorImpl<MCParsedAsmOperand*>&);
296 OperandMatchResultTy parseInstSyncBarrierOptOperand(
297 SmallVectorImpl<MCParsedAsmOperand*>&);
298 OperandMatchResultTy parseProcIFlagsOperand(
299 SmallVectorImpl<MCParsedAsmOperand*>&);
300 OperandMatchResultTy parseMSRMaskOperand(
301 SmallVectorImpl<MCParsedAsmOperand*>&);
302 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
303 StringRef Op, int Low, int High);
304 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
305 return parsePKHImm(O, "lsl", 0, 31);
307 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
308 return parsePKHImm(O, "asr", 1, 32);
310 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
311 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
312 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
313 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
314 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
315 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
316 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
317 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
318 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
321 // Asm Match Converter Methods
322 void cvtThumbMultiply(MCInst &Inst,
323 const SmallVectorImpl<MCParsedAsmOperand*> &);
324 void cvtThumbBranches(MCInst &Inst,
325 const SmallVectorImpl<MCParsedAsmOperand*> &);
327 bool validateInstruction(MCInst &Inst,
328 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
329 bool processInstruction(MCInst &Inst,
330 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
331 bool shouldOmitCCOutOperand(StringRef Mnemonic,
332 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
333 bool shouldOmitPredicateOperand(StringRef Mnemonic,
334 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
336 enum ARMMatchResultTy {
337 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
338 Match_RequiresNotITBlock,
340 Match_RequiresThumb2,
341 #define GET_OPERAND_DIAGNOSTIC_TYPES
342 #include "ARMGenAsmMatcher.inc"
346 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
347 const MCInstrInfo &MII)
348 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
349 MCAsmParserExtension::Initialize(_Parser);
351 // Cache the MCRegisterInfo.
352 MRI = getContext().getRegisterInfo();
354 // Initialize the set of available features.
355 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
357 // Not in an ITBlock to start with.
358 ITState.CurPosition = ~0U;
360 NextSymbolIsThumb = false;
363 // Implementation of the MCTargetAsmParser interface:
364 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
365 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
367 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
368 bool ParseDirective(AsmToken DirectiveID);
370 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
371 unsigned checkTargetMatchPredicate(MCInst &Inst);
373 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
374 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
375 MCStreamer &Out, unsigned &ErrorInfo,
376 bool MatchingInlineAsm);
377 void onLabelParsed(MCSymbol *Symbol);
380 } // end anonymous namespace
384 /// ARMOperand - Instances of this class represent a parsed ARM machine
386 class ARMOperand : public MCParsedAsmOperand {
396 k_InstSyncBarrierOpt,
407 k_VectorListAllLanes,
413 k_BitfieldDescriptor,
417 SMLoc StartLoc, EndLoc;
418 SmallVector<unsigned, 8> Registers;
421 ARMCC::CondCodes Val;
428 struct CoprocOptionOp {
441 ARM_ISB::InstSyncBOpt Val;
445 ARM_PROC::IFlags Val;
461 // A vector register list is a sequential list of 1 to 4 registers.
462 struct VectorListOp {
469 struct VectorIndexOp {
477 /// Combined record for all forms of ARM address expressions.
480 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
482 const MCConstantExpr *OffsetImm; // Offset immediate value
483 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
484 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
485 unsigned ShiftImm; // shift for OffsetReg.
486 unsigned Alignment; // 0 = no alignment specified
487 // n = alignment in bytes (2, 4, 8, 16, or 32)
488 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
491 struct PostIdxRegOp {
494 ARM_AM::ShiftOpc ShiftTy;
498 struct ShifterImmOp {
503 struct RegShiftedRegOp {
504 ARM_AM::ShiftOpc ShiftTy;
510 struct RegShiftedImmOp {
511 ARM_AM::ShiftOpc ShiftTy;
528 struct CoprocOptionOp CoprocOption;
529 struct MBOptOp MBOpt;
530 struct ISBOptOp ISBOpt;
531 struct ITMaskOp ITMask;
532 struct IFlagsOp IFlags;
533 struct MMaskOp MMask;
536 struct VectorListOp VectorList;
537 struct VectorIndexOp VectorIndex;
539 struct MemoryOp Memory;
540 struct PostIdxRegOp PostIdxReg;
541 struct ShifterImmOp ShifterImm;
542 struct RegShiftedRegOp RegShiftedReg;
543 struct RegShiftedImmOp RegShiftedImm;
544 struct RotImmOp RotImm;
545 struct BitfieldOp Bitfield;
548 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
550 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
552 StartLoc = o.StartLoc;
569 case k_DPRRegisterList:
570 case k_SPRRegisterList:
571 Registers = o.Registers;
574 case k_VectorListAllLanes:
575 case k_VectorListIndexed:
576 VectorList = o.VectorList;
583 CoprocOption = o.CoprocOption;
588 case k_MemBarrierOpt:
591 case k_InstSyncBarrierOpt:
596 case k_PostIndexRegister:
597 PostIdxReg = o.PostIdxReg;
605 case k_ShifterImmediate:
606 ShifterImm = o.ShifterImm;
608 case k_ShiftedRegister:
609 RegShiftedReg = o.RegShiftedReg;
611 case k_ShiftedImmediate:
612 RegShiftedImm = o.RegShiftedImm;
614 case k_RotateImmediate:
617 case k_BitfieldDescriptor:
618 Bitfield = o.Bitfield;
621 VectorIndex = o.VectorIndex;
626 /// getStartLoc - Get the location of the first token of this operand.
627 SMLoc getStartLoc() const { return StartLoc; }
628 /// getEndLoc - Get the location of the last token of this operand.
629 SMLoc getEndLoc() const { return EndLoc; }
630 /// getLocRange - Get the range between the first and last token of this
632 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
634 ARMCC::CondCodes getCondCode() const {
635 assert(Kind == k_CondCode && "Invalid access!");
639 unsigned getCoproc() const {
640 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
644 StringRef getToken() const {
645 assert(Kind == k_Token && "Invalid access!");
646 return StringRef(Tok.Data, Tok.Length);
649 unsigned getReg() const {
650 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
654 const SmallVectorImpl<unsigned> &getRegList() const {
655 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
656 Kind == k_SPRRegisterList) && "Invalid access!");
660 const MCExpr *getImm() const {
661 assert(isImm() && "Invalid access!");
665 unsigned getVectorIndex() const {
666 assert(Kind == k_VectorIndex && "Invalid access!");
667 return VectorIndex.Val;
670 ARM_MB::MemBOpt getMemBarrierOpt() const {
671 assert(Kind == k_MemBarrierOpt && "Invalid access!");
675 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
676 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
680 ARM_PROC::IFlags getProcIFlags() const {
681 assert(Kind == k_ProcIFlags && "Invalid access!");
685 unsigned getMSRMask() const {
686 assert(Kind == k_MSRMask && "Invalid access!");
690 bool isCoprocNum() const { return Kind == k_CoprocNum; }
691 bool isCoprocReg() const { return Kind == k_CoprocReg; }
692 bool isCoprocOption() const { return Kind == k_CoprocOption; }
693 bool isCondCode() const { return Kind == k_CondCode; }
694 bool isCCOut() const { return Kind == k_CCOut; }
695 bool isITMask() const { return Kind == k_ITCondMask; }
696 bool isITCondCode() const { return Kind == k_CondCode; }
697 bool isImm() const { return Kind == k_Immediate; }
698 // checks whether this operand is an unsigned offset which fits is a field
699 // of specified width and scaled by a specific number of bits
700 template<unsigned width, unsigned scale>
701 bool isUnsignedOffset() const {
702 if (!isImm()) return false;
703 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
704 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
705 int64_t Val = CE->getValue();
706 int64_t Align = 1LL << scale;
707 int64_t Max = Align * ((1LL << width) - 1);
708 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
712 // checks whether this operand is an signed offset which fits is a field
713 // of specified width and scaled by a specific number of bits
714 template<unsigned width, unsigned scale>
715 bool isSignedOffset() const {
716 if (!isImm()) return false;
717 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
718 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
719 int64_t Val = CE->getValue();
720 int64_t Align = 1LL << scale;
721 int64_t Max = Align * ((1LL << (width-1)) - 1);
722 int64_t Min = -Align * (1LL << (width-1));
723 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
728 // checks whether this operand is a memory operand computed as an offset
729 // applied to PC. the offset may have 8 bits of magnitude and is represented
730 // with two bits of shift. textually it may be either [pc, #imm], #imm or
731 // relocable expression...
732 bool isThumbMemPC() const {
735 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
736 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
737 if (!CE) return false;
738 Val = CE->getValue();
741 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
742 if(Memory.BaseRegNum != ARM::PC) return false;
743 Val = Memory.OffsetImm->getValue();
746 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
748 bool isFPImm() const {
749 if (!isImm()) return false;
750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
751 if (!CE) return false;
752 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
755 bool isFBits16() const {
756 if (!isImm()) return false;
757 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
758 if (!CE) return false;
759 int64_t Value = CE->getValue();
760 return Value >= 0 && Value <= 16;
762 bool isFBits32() const {
763 if (!isImm()) return false;
764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
765 if (!CE) return false;
766 int64_t Value = CE->getValue();
767 return Value >= 1 && Value <= 32;
769 bool isImm8s4() const {
770 if (!isImm()) return false;
771 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
772 if (!CE) return false;
773 int64_t Value = CE->getValue();
774 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
776 bool isImm0_1020s4() const {
777 if (!isImm()) return false;
778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
779 if (!CE) return false;
780 int64_t Value = CE->getValue();
781 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
783 bool isImm0_508s4() 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 & 3) == 0) && Value >= 0 && Value <= 508;
790 bool isImm0_508s4Neg() 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 // explicitly exclude zero. we want that to use the normal 0_508 version.
796 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
798 bool isImm0_239() const {
799 if (!isImm()) return false;
800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
801 if (!CE) return false;
802 int64_t Value = CE->getValue();
803 return Value >= 0 && Value < 240;
805 bool isImm0_255() const {
806 if (!isImm()) return false;
807 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
808 if (!CE) return false;
809 int64_t Value = CE->getValue();
810 return Value >= 0 && Value < 256;
812 bool isImm0_4095() const {
813 if (!isImm()) return false;
814 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
815 if (!CE) return false;
816 int64_t Value = CE->getValue();
817 return Value >= 0 && Value < 4096;
819 bool isImm0_4095Neg() const {
820 if (!isImm()) return false;
821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = -CE->getValue();
824 return Value > 0 && Value < 4096;
826 bool isImm0_1() const {
827 if (!isImm()) return false;
828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
831 return Value >= 0 && Value < 2;
833 bool isImm0_3() const {
834 if (!isImm()) return false;
835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
836 if (!CE) return false;
837 int64_t Value = CE->getValue();
838 return Value >= 0 && Value < 4;
840 bool isImm0_7() const {
841 if (!isImm()) return false;
842 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
843 if (!CE) return false;
844 int64_t Value = CE->getValue();
845 return Value >= 0 && Value < 8;
847 bool isImm0_15() const {
848 if (!isImm()) return false;
849 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
850 if (!CE) return false;
851 int64_t Value = CE->getValue();
852 return Value >= 0 && Value < 16;
854 bool isImm0_31() const {
855 if (!isImm()) return false;
856 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
857 if (!CE) return false;
858 int64_t Value = CE->getValue();
859 return Value >= 0 && Value < 32;
861 bool isImm0_63() const {
862 if (!isImm()) return false;
863 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
864 if (!CE) return false;
865 int64_t Value = CE->getValue();
866 return Value >= 0 && Value < 64;
868 bool isImm8() const {
869 if (!isImm()) return false;
870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
871 if (!CE) return false;
872 int64_t Value = CE->getValue();
875 bool isImm16() const {
876 if (!isImm()) return false;
877 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
878 if (!CE) return false;
879 int64_t Value = CE->getValue();
882 bool isImm32() const {
883 if (!isImm()) return false;
884 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
885 if (!CE) return false;
886 int64_t Value = CE->getValue();
889 bool isShrImm8() const {
890 if (!isImm()) return false;
891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
892 if (!CE) return false;
893 int64_t Value = CE->getValue();
894 return Value > 0 && Value <= 8;
896 bool isShrImm16() const {
897 if (!isImm()) return false;
898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
899 if (!CE) return false;
900 int64_t Value = CE->getValue();
901 return Value > 0 && Value <= 16;
903 bool isShrImm32() const {
904 if (!isImm()) return false;
905 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
906 if (!CE) return false;
907 int64_t Value = CE->getValue();
908 return Value > 0 && Value <= 32;
910 bool isShrImm64() const {
911 if (!isImm()) return false;
912 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
913 if (!CE) return false;
914 int64_t Value = CE->getValue();
915 return Value > 0 && Value <= 64;
917 bool isImm1_7() const {
918 if (!isImm()) return false;
919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
920 if (!CE) return false;
921 int64_t Value = CE->getValue();
922 return Value > 0 && Value < 8;
924 bool isImm1_15() const {
925 if (!isImm()) return false;
926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
927 if (!CE) return false;
928 int64_t Value = CE->getValue();
929 return Value > 0 && Value < 16;
931 bool isImm1_31() const {
932 if (!isImm()) return false;
933 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
934 if (!CE) return false;
935 int64_t Value = CE->getValue();
936 return Value > 0 && Value < 32;
938 bool isImm1_16() const {
939 if (!isImm()) return false;
940 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
941 if (!CE) return false;
942 int64_t Value = CE->getValue();
943 return Value > 0 && Value < 17;
945 bool isImm1_32() const {
946 if (!isImm()) return false;
947 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
948 if (!CE) return false;
949 int64_t Value = CE->getValue();
950 return Value > 0 && Value < 33;
952 bool isImm0_32() const {
953 if (!isImm()) return false;
954 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
955 if (!CE) return false;
956 int64_t Value = CE->getValue();
957 return Value >= 0 && Value < 33;
959 bool isImm0_65535() const {
960 if (!isImm()) return false;
961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
962 if (!CE) return false;
963 int64_t Value = CE->getValue();
964 return Value >= 0 && Value < 65536;
966 bool isImm256_65535Expr() const {
967 if (!isImm()) return false;
968 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
969 // If it's not a constant expression, it'll generate a fixup and be
971 if (!CE) return true;
972 int64_t Value = CE->getValue();
973 return Value >= 256 && Value < 65536;
975 bool isImm0_65535Expr() const {
976 if (!isImm()) return false;
977 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
978 // If it's not a constant expression, it'll generate a fixup and be
980 if (!CE) return true;
981 int64_t Value = CE->getValue();
982 return Value >= 0 && Value < 65536;
984 bool isImm24bit() const {
985 if (!isImm()) return false;
986 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
987 if (!CE) return false;
988 int64_t Value = CE->getValue();
989 return Value >= 0 && Value <= 0xffffff;
991 bool isImmThumbSR() const {
992 if (!isImm()) return false;
993 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
994 if (!CE) return false;
995 int64_t Value = CE->getValue();
996 return Value > 0 && Value < 33;
998 bool isPKHLSLImm() const {
999 if (!isImm()) return false;
1000 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1001 if (!CE) return false;
1002 int64_t Value = CE->getValue();
1003 return Value >= 0 && Value < 32;
1005 bool isPKHASRImm() const {
1006 if (!isImm()) return false;
1007 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1008 if (!CE) return false;
1009 int64_t Value = CE->getValue();
1010 return Value > 0 && Value <= 32;
1012 bool isAdrLabel() const {
1013 // If we have an immediate that's not a constant, treat it as a label
1014 // reference needing a fixup. If it is a constant, but it can't fit
1015 // into shift immediate encoding, we reject it.
1016 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1017 else return (isARMSOImm() || isARMSOImmNeg());
1019 bool isARMSOImm() const {
1020 if (!isImm()) return false;
1021 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1022 if (!CE) return false;
1023 int64_t Value = CE->getValue();
1024 return ARM_AM::getSOImmVal(Value) != -1;
1026 bool isARMSOImmNot() const {
1027 if (!isImm()) return false;
1028 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1029 if (!CE) return false;
1030 int64_t Value = CE->getValue();
1031 return ARM_AM::getSOImmVal(~Value) != -1;
1033 bool isARMSOImmNeg() const {
1034 if (!isImm()) return false;
1035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1036 if (!CE) return false;
1037 int64_t Value = CE->getValue();
1038 // Only use this when not representable as a plain so_imm.
1039 return ARM_AM::getSOImmVal(Value) == -1 &&
1040 ARM_AM::getSOImmVal(-Value) != -1;
1042 bool isT2SOImm() 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 return ARM_AM::getT2SOImmVal(Value) != -1;
1049 bool isT2SOImmNot() const {
1050 if (!isImm()) return false;
1051 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1052 if (!CE) return false;
1053 int64_t Value = CE->getValue();
1054 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1055 ARM_AM::getT2SOImmVal(~Value) != -1;
1057 bool isT2SOImmNeg() const {
1058 if (!isImm()) return false;
1059 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1060 if (!CE) return false;
1061 int64_t Value = CE->getValue();
1062 // Only use this when not representable as a plain so_imm.
1063 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1064 ARM_AM::getT2SOImmVal(-Value) != -1;
1066 bool isSetEndImm() const {
1067 if (!isImm()) return false;
1068 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1069 if (!CE) return false;
1070 int64_t Value = CE->getValue();
1071 return Value == 1 || Value == 0;
1073 bool isReg() const { return Kind == k_Register; }
1074 bool isRegList() const { return Kind == k_RegisterList; }
1075 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1076 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1077 bool isToken() const { return Kind == k_Token; }
1078 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1079 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1080 bool isMem() const { return Kind == k_Memory; }
1081 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1082 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1083 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1084 bool isRotImm() const { return Kind == k_RotateImmediate; }
1085 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1086 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1087 bool isPostIdxReg() const {
1088 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1090 bool isMemNoOffset(bool alignOK = false) const {
1093 // No offset of any kind.
1094 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1095 (alignOK || Memory.Alignment == 0);
1097 bool isMemPCRelImm12() const {
1098 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1100 // Base register must be PC.
1101 if (Memory.BaseRegNum != ARM::PC)
1103 // Immediate offset in range [-4095, 4095].
1104 if (!Memory.OffsetImm) return true;
1105 int64_t Val = Memory.OffsetImm->getValue();
1106 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1108 bool isAlignedMemory() const {
1109 return isMemNoOffset(true);
1111 bool isAddrMode2() const {
1112 if (!isMem() || Memory.Alignment != 0) return false;
1113 // Check for register offset.
1114 if (Memory.OffsetRegNum) return true;
1115 // Immediate offset in range [-4095, 4095].
1116 if (!Memory.OffsetImm) return true;
1117 int64_t Val = Memory.OffsetImm->getValue();
1118 return Val > -4096 && Val < 4096;
1120 bool isAM2OffsetImm() const {
1121 if (!isImm()) return false;
1122 // Immediate offset in range [-4095, 4095].
1123 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1124 if (!CE) return false;
1125 int64_t Val = CE->getValue();
1126 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1128 bool isAddrMode3() const {
1129 // If we have an immediate that's not a constant, treat it as a label
1130 // reference needing a fixup. If it is a constant, it's something else
1131 // and we reject it.
1132 if (isImm() && !isa<MCConstantExpr>(getImm()))
1134 if (!isMem() || Memory.Alignment != 0) return false;
1135 // No shifts are legal for AM3.
1136 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1137 // Check for register offset.
1138 if (Memory.OffsetRegNum) return true;
1139 // Immediate offset in range [-255, 255].
1140 if (!Memory.OffsetImm) return true;
1141 int64_t Val = Memory.OffsetImm->getValue();
1142 // The #-0 offset is encoded as INT32_MIN, and we have to check
1144 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1146 bool isAM3Offset() const {
1147 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1149 if (Kind == k_PostIndexRegister)
1150 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1151 // Immediate offset in range [-255, 255].
1152 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1153 if (!CE) return false;
1154 int64_t Val = CE->getValue();
1155 // Special case, #-0 is INT32_MIN.
1156 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1158 bool isAddrMode5() const {
1159 // If we have an immediate that's not a constant, treat it as a label
1160 // reference needing a fixup. If it is a constant, it's something else
1161 // and we reject it.
1162 if (isImm() && !isa<MCConstantExpr>(getImm()))
1164 if (!isMem() || Memory.Alignment != 0) return false;
1165 // Check for register offset.
1166 if (Memory.OffsetRegNum) return false;
1167 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1168 if (!Memory.OffsetImm) return true;
1169 int64_t Val = Memory.OffsetImm->getValue();
1170 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1173 bool isMemTBB() const {
1174 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1175 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1179 bool isMemTBH() const {
1180 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1181 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1182 Memory.Alignment != 0 )
1186 bool isMemRegOffset() const {
1187 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1191 bool isT2MemRegOffset() const {
1192 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1193 Memory.Alignment != 0)
1195 // Only lsl #{0, 1, 2, 3} allowed.
1196 if (Memory.ShiftType == ARM_AM::no_shift)
1198 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1202 bool isMemThumbRR() const {
1203 // Thumb reg+reg addressing is simple. Just two registers, a base and
1204 // an offset. No shifts, negations or any other complicating factors.
1205 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1206 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1208 return isARMLowRegister(Memory.BaseRegNum) &&
1209 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1211 bool isMemThumbRIs4() const {
1212 if (!isMem() || Memory.OffsetRegNum != 0 ||
1213 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1215 // Immediate offset, multiple of 4 in range [0, 124].
1216 if (!Memory.OffsetImm) return true;
1217 int64_t Val = Memory.OffsetImm->getValue();
1218 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1220 bool isMemThumbRIs2() const {
1221 if (!isMem() || Memory.OffsetRegNum != 0 ||
1222 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1224 // Immediate offset, multiple of 4 in range [0, 62].
1225 if (!Memory.OffsetImm) return true;
1226 int64_t Val = Memory.OffsetImm->getValue();
1227 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1229 bool isMemThumbRIs1() const {
1230 if (!isMem() || Memory.OffsetRegNum != 0 ||
1231 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1233 // Immediate offset in range [0, 31].
1234 if (!Memory.OffsetImm) return true;
1235 int64_t Val = Memory.OffsetImm->getValue();
1236 return Val >= 0 && Val <= 31;
1238 bool isMemThumbSPI() const {
1239 if (!isMem() || Memory.OffsetRegNum != 0 ||
1240 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1242 // Immediate offset, multiple of 4 in range [0, 1020].
1243 if (!Memory.OffsetImm) return true;
1244 int64_t Val = Memory.OffsetImm->getValue();
1245 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1247 bool isMemImm8s4Offset() const {
1248 // If we have an immediate that's not a constant, treat it as a label
1249 // reference needing a fixup. If it is a constant, it's something else
1250 // and we reject it.
1251 if (isImm() && !isa<MCConstantExpr>(getImm()))
1253 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1255 // Immediate offset a multiple of 4 in range [-1020, 1020].
1256 if (!Memory.OffsetImm) return true;
1257 int64_t Val = Memory.OffsetImm->getValue();
1258 // Special case, #-0 is INT32_MIN.
1259 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1261 bool isMemImm0_1020s4Offset() const {
1262 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1264 // Immediate offset a multiple of 4 in range [0, 1020].
1265 if (!Memory.OffsetImm) return true;
1266 int64_t Val = Memory.OffsetImm->getValue();
1267 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1269 bool isMemImm8Offset() const {
1270 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1272 // Base reg of PC isn't allowed for these encodings.
1273 if (Memory.BaseRegNum == ARM::PC) return false;
1274 // Immediate offset in range [-255, 255].
1275 if (!Memory.OffsetImm) return true;
1276 int64_t Val = Memory.OffsetImm->getValue();
1277 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1279 bool isMemPosImm8Offset() const {
1280 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1282 // Immediate offset in range [0, 255].
1283 if (!Memory.OffsetImm) return true;
1284 int64_t Val = Memory.OffsetImm->getValue();
1285 return Val >= 0 && Val < 256;
1287 bool isMemNegImm8Offset() const {
1288 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1290 // Base reg of PC isn't allowed for these encodings.
1291 if (Memory.BaseRegNum == ARM::PC) return false;
1292 // Immediate offset in range [-255, -1].
1293 if (!Memory.OffsetImm) return false;
1294 int64_t Val = Memory.OffsetImm->getValue();
1295 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1297 bool isMemUImm12Offset() const {
1298 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1300 // Immediate offset in range [0, 4095].
1301 if (!Memory.OffsetImm) return true;
1302 int64_t Val = Memory.OffsetImm->getValue();
1303 return (Val >= 0 && Val < 4096);
1305 bool isMemImm12Offset() const {
1306 // If we have an immediate that's not a constant, treat it as a label
1307 // reference needing a fixup. If it is a constant, it's something else
1308 // and we reject it.
1309 if (isImm() && !isa<MCConstantExpr>(getImm()))
1312 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1314 // Immediate offset in range [-4095, 4095].
1315 if (!Memory.OffsetImm) return true;
1316 int64_t Val = Memory.OffsetImm->getValue();
1317 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1319 bool isPostIdxImm8() const {
1320 if (!isImm()) return false;
1321 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1322 if (!CE) return false;
1323 int64_t Val = CE->getValue();
1324 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1326 bool isPostIdxImm8s4() const {
1327 if (!isImm()) return false;
1328 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1329 if (!CE) return false;
1330 int64_t Val = CE->getValue();
1331 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1335 bool isMSRMask() const { return Kind == k_MSRMask; }
1336 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1339 bool isSingleSpacedVectorList() const {
1340 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1342 bool isDoubleSpacedVectorList() const {
1343 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1345 bool isVecListOneD() const {
1346 if (!isSingleSpacedVectorList()) return false;
1347 return VectorList.Count == 1;
1350 bool isVecListDPair() const {
1351 if (!isSingleSpacedVectorList()) return false;
1352 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1353 .contains(VectorList.RegNum));
1356 bool isVecListThreeD() const {
1357 if (!isSingleSpacedVectorList()) return false;
1358 return VectorList.Count == 3;
1361 bool isVecListFourD() const {
1362 if (!isSingleSpacedVectorList()) return false;
1363 return VectorList.Count == 4;
1366 bool isVecListDPairSpaced() const {
1367 if (isSingleSpacedVectorList()) return false;
1368 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1369 .contains(VectorList.RegNum));
1372 bool isVecListThreeQ() const {
1373 if (!isDoubleSpacedVectorList()) return false;
1374 return VectorList.Count == 3;
1377 bool isVecListFourQ() const {
1378 if (!isDoubleSpacedVectorList()) return false;
1379 return VectorList.Count == 4;
1382 bool isSingleSpacedVectorAllLanes() const {
1383 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1385 bool isDoubleSpacedVectorAllLanes() const {
1386 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1388 bool isVecListOneDAllLanes() const {
1389 if (!isSingleSpacedVectorAllLanes()) return false;
1390 return VectorList.Count == 1;
1393 bool isVecListDPairAllLanes() const {
1394 if (!isSingleSpacedVectorAllLanes()) return false;
1395 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1396 .contains(VectorList.RegNum));
1399 bool isVecListDPairSpacedAllLanes() const {
1400 if (!isDoubleSpacedVectorAllLanes()) return false;
1401 return VectorList.Count == 2;
1404 bool isVecListThreeDAllLanes() const {
1405 if (!isSingleSpacedVectorAllLanes()) return false;
1406 return VectorList.Count == 3;
1409 bool isVecListThreeQAllLanes() const {
1410 if (!isDoubleSpacedVectorAllLanes()) return false;
1411 return VectorList.Count == 3;
1414 bool isVecListFourDAllLanes() const {
1415 if (!isSingleSpacedVectorAllLanes()) return false;
1416 return VectorList.Count == 4;
1419 bool isVecListFourQAllLanes() const {
1420 if (!isDoubleSpacedVectorAllLanes()) return false;
1421 return VectorList.Count == 4;
1424 bool isSingleSpacedVectorIndexed() const {
1425 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1427 bool isDoubleSpacedVectorIndexed() const {
1428 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1430 bool isVecListOneDByteIndexed() const {
1431 if (!isSingleSpacedVectorIndexed()) return false;
1432 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1435 bool isVecListOneDHWordIndexed() const {
1436 if (!isSingleSpacedVectorIndexed()) return false;
1437 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1440 bool isVecListOneDWordIndexed() const {
1441 if (!isSingleSpacedVectorIndexed()) return false;
1442 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1445 bool isVecListTwoDByteIndexed() const {
1446 if (!isSingleSpacedVectorIndexed()) return false;
1447 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1450 bool isVecListTwoDHWordIndexed() const {
1451 if (!isSingleSpacedVectorIndexed()) return false;
1452 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1455 bool isVecListTwoQWordIndexed() const {
1456 if (!isDoubleSpacedVectorIndexed()) return false;
1457 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1460 bool isVecListTwoQHWordIndexed() const {
1461 if (!isDoubleSpacedVectorIndexed()) return false;
1462 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1465 bool isVecListTwoDWordIndexed() const {
1466 if (!isSingleSpacedVectorIndexed()) return false;
1467 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1470 bool isVecListThreeDByteIndexed() const {
1471 if (!isSingleSpacedVectorIndexed()) return false;
1472 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1475 bool isVecListThreeDHWordIndexed() const {
1476 if (!isSingleSpacedVectorIndexed()) return false;
1477 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1480 bool isVecListThreeQWordIndexed() const {
1481 if (!isDoubleSpacedVectorIndexed()) return false;
1482 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1485 bool isVecListThreeQHWordIndexed() const {
1486 if (!isDoubleSpacedVectorIndexed()) return false;
1487 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1490 bool isVecListThreeDWordIndexed() const {
1491 if (!isSingleSpacedVectorIndexed()) return false;
1492 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1495 bool isVecListFourDByteIndexed() const {
1496 if (!isSingleSpacedVectorIndexed()) return false;
1497 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1500 bool isVecListFourDHWordIndexed() const {
1501 if (!isSingleSpacedVectorIndexed()) return false;
1502 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1505 bool isVecListFourQWordIndexed() const {
1506 if (!isDoubleSpacedVectorIndexed()) return false;
1507 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1510 bool isVecListFourQHWordIndexed() const {
1511 if (!isDoubleSpacedVectorIndexed()) return false;
1512 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1515 bool isVecListFourDWordIndexed() const {
1516 if (!isSingleSpacedVectorIndexed()) return false;
1517 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1520 bool isVectorIndex8() const {
1521 if (Kind != k_VectorIndex) return false;
1522 return VectorIndex.Val < 8;
1524 bool isVectorIndex16() const {
1525 if (Kind != k_VectorIndex) return false;
1526 return VectorIndex.Val < 4;
1528 bool isVectorIndex32() const {
1529 if (Kind != k_VectorIndex) return false;
1530 return VectorIndex.Val < 2;
1533 bool isNEONi8splat() const {
1534 if (!isImm()) return false;
1535 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1536 // Must be a constant.
1537 if (!CE) return false;
1538 int64_t Value = CE->getValue();
1539 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1541 return Value >= 0 && Value < 256;
1544 bool isNEONi16splat() const {
1545 if (!isImm()) return false;
1546 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1547 // Must be a constant.
1548 if (!CE) return false;
1549 int64_t Value = CE->getValue();
1550 // i16 value in the range [0,255] or [0x0100, 0xff00]
1551 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1554 bool isNEONi32splat() const {
1555 if (!isImm()) return false;
1556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1557 // Must be a constant.
1558 if (!CE) return false;
1559 int64_t Value = CE->getValue();
1560 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1561 return (Value >= 0 && Value < 256) ||
1562 (Value >= 0x0100 && Value <= 0xff00) ||
1563 (Value >= 0x010000 && Value <= 0xff0000) ||
1564 (Value >= 0x01000000 && Value <= 0xff000000);
1567 bool isNEONi32vmov() 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);
1582 bool isNEONi32vmovNeg() const {
1583 if (!isImm()) return false;
1584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1585 // Must be a constant.
1586 if (!CE) return false;
1587 int64_t Value = ~CE->getValue();
1588 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1589 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1590 return (Value >= 0 && Value < 256) ||
1591 (Value >= 0x0100 && Value <= 0xff00) ||
1592 (Value >= 0x010000 && Value <= 0xff0000) ||
1593 (Value >= 0x01000000 && Value <= 0xff000000) ||
1594 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1595 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1598 bool isNEONi64splat() const {
1599 if (!isImm()) return false;
1600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1601 // Must be a constant.
1602 if (!CE) return false;
1603 uint64_t Value = CE->getValue();
1604 // i64 value with each byte being either 0 or 0xff.
1605 for (unsigned i = 0; i < 8; ++i)
1606 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1610 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1611 // Add as immediates when possible. Null MCExpr = 0.
1613 Inst.addOperand(MCOperand::CreateImm(0));
1614 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1615 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1617 Inst.addOperand(MCOperand::CreateExpr(Expr));
1620 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1621 assert(N == 2 && "Invalid number of operands!");
1622 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1623 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1624 Inst.addOperand(MCOperand::CreateReg(RegNum));
1627 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1632 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1633 assert(N == 1 && "Invalid number of operands!");
1634 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1637 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1638 assert(N == 1 && "Invalid number of operands!");
1639 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1642 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1643 assert(N == 1 && "Invalid number of operands!");
1644 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1647 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1648 assert(N == 1 && "Invalid number of operands!");
1649 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1652 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1653 assert(N == 1 && "Invalid number of operands!");
1654 Inst.addOperand(MCOperand::CreateReg(getReg()));
1657 void addRegOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 1 && "Invalid number of operands!");
1659 Inst.addOperand(MCOperand::CreateReg(getReg()));
1662 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1663 assert(N == 3 && "Invalid number of operands!");
1664 assert(isRegShiftedReg() &&
1665 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1666 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1667 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1668 Inst.addOperand(MCOperand::CreateImm(
1669 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1672 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1673 assert(N == 2 && "Invalid number of operands!");
1674 assert(isRegShiftedImm() &&
1675 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1676 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1677 // Shift of #32 is encoded as 0 where permitted
1678 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1679 Inst.addOperand(MCOperand::CreateImm(
1680 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1683 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1684 assert(N == 1 && "Invalid number of operands!");
1685 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1689 void addRegListOperands(MCInst &Inst, unsigned N) const {
1690 assert(N == 1 && "Invalid number of operands!");
1691 const SmallVectorImpl<unsigned> &RegList = getRegList();
1692 for (SmallVectorImpl<unsigned>::const_iterator
1693 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1694 Inst.addOperand(MCOperand::CreateReg(*I));
1697 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1698 addRegListOperands(Inst, N);
1701 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1702 addRegListOperands(Inst, N);
1705 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1706 assert(N == 1 && "Invalid number of operands!");
1707 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1708 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1711 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1712 assert(N == 1 && "Invalid number of operands!");
1713 // Munge the lsb/width into a bitfield mask.
1714 unsigned lsb = Bitfield.LSB;
1715 unsigned width = Bitfield.Width;
1716 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1717 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1718 (32 - (lsb + width)));
1719 Inst.addOperand(MCOperand::CreateImm(Mask));
1722 void addImmOperands(MCInst &Inst, unsigned N) const {
1723 assert(N == 1 && "Invalid number of operands!");
1724 addExpr(Inst, getImm());
1727 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1728 assert(N == 1 && "Invalid number of operands!");
1729 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1730 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1733 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1734 assert(N == 1 && "Invalid number of operands!");
1735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1736 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1739 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1740 assert(N == 1 && "Invalid number of operands!");
1741 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1742 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1743 Inst.addOperand(MCOperand::CreateImm(Val));
1746 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1747 assert(N == 1 && "Invalid number of operands!");
1748 // FIXME: We really want to scale the value here, but the LDRD/STRD
1749 // instruction don't encode operands that way yet.
1750 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1751 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1754 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1755 assert(N == 1 && "Invalid number of operands!");
1756 // The immediate is scaled by four in the encoding and is stored
1757 // in the MCInst as such. Lop off the low two bits here.
1758 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1759 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1762 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1763 assert(N == 1 && "Invalid number of operands!");
1764 // The immediate is scaled by four in the encoding and is stored
1765 // in the MCInst as such. Lop off the low two bits here.
1766 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1767 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1770 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1771 assert(N == 1 && "Invalid number of operands!");
1772 // The immediate is scaled by four in the encoding and is stored
1773 // in the MCInst as such. Lop off the low two bits here.
1774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1775 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1778 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1779 assert(N == 1 && "Invalid number of operands!");
1780 // The constant encodes as the immediate-1, and we store in the instruction
1781 // the bits as encoded, so subtract off one here.
1782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1783 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1786 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1787 assert(N == 1 && "Invalid number of operands!");
1788 // The constant encodes as the immediate-1, and we store in the instruction
1789 // the bits as encoded, so subtract off one here.
1790 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1791 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1794 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 1 && "Invalid number of operands!");
1796 // The constant encodes as the immediate, except for 32, which encodes as
1798 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1799 unsigned Imm = CE->getValue();
1800 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1803 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1804 assert(N == 1 && "Invalid number of operands!");
1805 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1806 // the instruction as well.
1807 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1808 int Val = CE->getValue();
1809 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1812 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1813 assert(N == 1 && "Invalid number of operands!");
1814 // The operand is actually a t2_so_imm, but we have its bitwise
1815 // negation in the assembly source, so twiddle it here.
1816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1817 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1820 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1821 assert(N == 1 && "Invalid number of operands!");
1822 // The operand is actually a t2_so_imm, but we have its
1823 // negation in the assembly source, so twiddle it here.
1824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1825 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1828 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1829 assert(N == 1 && "Invalid number of operands!");
1830 // The operand is actually an imm0_4095, but we have its
1831 // negation in the assembly source, so twiddle it here.
1832 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1833 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1836 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1837 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1838 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1842 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1843 assert(SR && "Unknown value type!");
1844 Inst.addOperand(MCOperand::CreateExpr(SR));
1847 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1848 assert(N == 1 && "Invalid number of operands!");
1850 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1852 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1856 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1857 assert(SR && "Unknown value type!");
1858 Inst.addOperand(MCOperand::CreateExpr(SR));
1862 assert(isMem() && "Unknown value type!");
1863 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1864 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1867 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1868 assert(N == 1 && "Invalid number of operands!");
1869 // The operand is actually a so_imm, but we have its bitwise
1870 // negation in the assembly source, so twiddle it here.
1871 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1872 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1875 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1876 assert(N == 1 && "Invalid number of operands!");
1877 // The operand is actually a so_imm, but we have its
1878 // negation in the assembly source, so twiddle it here.
1879 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1880 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1883 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1884 assert(N == 1 && "Invalid number of operands!");
1885 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1888 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1889 assert(N == 1 && "Invalid number of operands!");
1890 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1893 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1894 assert(N == 1 && "Invalid number of operands!");
1895 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1898 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1899 assert(N == 1 && "Invalid number of operands!");
1900 int32_t Imm = Memory.OffsetImm->getValue();
1901 Inst.addOperand(MCOperand::CreateImm(Imm));
1904 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1905 assert(N == 1 && "Invalid number of operands!");
1906 assert(isImm() && "Not an immediate!");
1908 // If we have an immediate that's not a constant, treat it as a label
1909 // reference needing a fixup.
1910 if (!isa<MCConstantExpr>(getImm())) {
1911 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1916 int Val = CE->getValue();
1917 Inst.addOperand(MCOperand::CreateImm(Val));
1920 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1921 assert(N == 2 && "Invalid number of operands!");
1922 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1923 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1926 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1927 assert(N == 3 && "Invalid number of operands!");
1928 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1929 if (!Memory.OffsetRegNum) {
1930 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1931 // Special case for #-0
1932 if (Val == INT32_MIN) Val = 0;
1933 if (Val < 0) Val = -Val;
1934 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1936 // For register offset, we encode the shift type and negation flag
1938 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1939 Memory.ShiftImm, Memory.ShiftType);
1941 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1942 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1943 Inst.addOperand(MCOperand::CreateImm(Val));
1946 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1947 assert(N == 2 && "Invalid number of operands!");
1948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1949 assert(CE && "non-constant AM2OffsetImm operand!");
1950 int32_t Val = CE->getValue();
1951 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1952 // Special case for #-0
1953 if (Val == INT32_MIN) Val = 0;
1954 if (Val < 0) Val = -Val;
1955 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1956 Inst.addOperand(MCOperand::CreateReg(0));
1957 Inst.addOperand(MCOperand::CreateImm(Val));
1960 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1961 assert(N == 3 && "Invalid number of operands!");
1962 // If we have an immediate that's not a constant, treat it as a label
1963 // reference needing a fixup. If it is a constant, it's something else
1964 // and we reject it.
1966 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1967 Inst.addOperand(MCOperand::CreateReg(0));
1968 Inst.addOperand(MCOperand::CreateImm(0));
1972 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1973 if (!Memory.OffsetRegNum) {
1974 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1975 // Special case for #-0
1976 if (Val == INT32_MIN) Val = 0;
1977 if (Val < 0) Val = -Val;
1978 Val = ARM_AM::getAM3Opc(AddSub, Val);
1980 // For register offset, we encode the shift type and negation flag
1982 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
1984 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1985 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1986 Inst.addOperand(MCOperand::CreateImm(Val));
1989 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1990 assert(N == 2 && "Invalid number of operands!");
1991 if (Kind == k_PostIndexRegister) {
1993 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1994 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1995 Inst.addOperand(MCOperand::CreateImm(Val));
2000 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2001 int32_t Val = CE->getValue();
2002 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2003 // Special case for #-0
2004 if (Val == INT32_MIN) Val = 0;
2005 if (Val < 0) Val = -Val;
2006 Val = ARM_AM::getAM3Opc(AddSub, Val);
2007 Inst.addOperand(MCOperand::CreateReg(0));
2008 Inst.addOperand(MCOperand::CreateImm(Val));
2011 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2012 assert(N == 2 && "Invalid number of operands!");
2013 // If we have an immediate that's not a constant, treat it as a label
2014 // reference needing a fixup. If it is a constant, it's something else
2015 // and we reject it.
2017 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2018 Inst.addOperand(MCOperand::CreateImm(0));
2022 // The lower two bits are always zero and as such are not encoded.
2023 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2024 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2025 // Special case for #-0
2026 if (Val == INT32_MIN) Val = 0;
2027 if (Val < 0) Val = -Val;
2028 Val = ARM_AM::getAM5Opc(AddSub, Val);
2029 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2030 Inst.addOperand(MCOperand::CreateImm(Val));
2033 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2034 assert(N == 2 && "Invalid number of operands!");
2035 // If we have an immediate that's not a constant, treat it as a label
2036 // reference needing a fixup. If it is a constant, it's something else
2037 // and we reject it.
2039 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2040 Inst.addOperand(MCOperand::CreateImm(0));
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 addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2050 assert(N == 2 && "Invalid number of operands!");
2051 // The lower two bits are always zero and as such are not encoded.
2052 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2053 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2054 Inst.addOperand(MCOperand::CreateImm(Val));
2057 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2058 assert(N == 2 && "Invalid number of operands!");
2059 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2060 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2061 Inst.addOperand(MCOperand::CreateImm(Val));
2064 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2065 addMemImm8OffsetOperands(Inst, N);
2068 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2069 addMemImm8OffsetOperands(Inst, N);
2072 void addMemUImm12OffsetOperands(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 addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2088 assert(N == 2 && "Invalid number of operands!");
2089 // If this is an immediate, it's a label reference.
2091 addExpr(Inst, getImm());
2092 Inst.addOperand(MCOperand::CreateImm(0));
2096 // Otherwise, it's a normal memory reg+offset.
2097 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2098 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2099 Inst.addOperand(MCOperand::CreateImm(Val));
2102 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2103 assert(N == 2 && "Invalid number of operands!");
2104 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2105 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2108 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2109 assert(N == 2 && "Invalid number of operands!");
2110 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2111 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2114 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2115 assert(N == 3 && "Invalid number of operands!");
2117 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2118 Memory.ShiftImm, Memory.ShiftType);
2119 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2120 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2121 Inst.addOperand(MCOperand::CreateImm(Val));
2124 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2125 assert(N == 3 && "Invalid number of operands!");
2126 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2127 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2128 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2131 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2132 assert(N == 2 && "Invalid number of operands!");
2133 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2134 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2137 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2138 assert(N == 2 && "Invalid number of operands!");
2139 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2140 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2141 Inst.addOperand(MCOperand::CreateImm(Val));
2144 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2145 assert(N == 2 && "Invalid number of operands!");
2146 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2147 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2148 Inst.addOperand(MCOperand::CreateImm(Val));
2151 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2152 assert(N == 2 && "Invalid number of operands!");
2153 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2154 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2155 Inst.addOperand(MCOperand::CreateImm(Val));
2158 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2159 assert(N == 2 && "Invalid number of operands!");
2160 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2161 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2162 Inst.addOperand(MCOperand::CreateImm(Val));
2165 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2166 assert(N == 1 && "Invalid number of operands!");
2167 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2168 assert(CE && "non-constant post-idx-imm8 operand!");
2169 int Imm = CE->getValue();
2170 bool isAdd = Imm >= 0;
2171 if (Imm == INT32_MIN) Imm = 0;
2172 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2173 Inst.addOperand(MCOperand::CreateImm(Imm));
2176 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2177 assert(N == 1 && "Invalid number of operands!");
2178 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2179 assert(CE && "non-constant post-idx-imm8s4 operand!");
2180 int Imm = CE->getValue();
2181 bool isAdd = Imm >= 0;
2182 if (Imm == INT32_MIN) Imm = 0;
2183 // Immediate is scaled by 4.
2184 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2185 Inst.addOperand(MCOperand::CreateImm(Imm));
2188 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2189 assert(N == 2 && "Invalid number of operands!");
2190 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2191 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2194 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2195 assert(N == 2 && "Invalid number of operands!");
2196 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2197 // The sign, shift type, and shift amount are encoded in a single operand
2198 // using the AM2 encoding helpers.
2199 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2200 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2201 PostIdxReg.ShiftTy);
2202 Inst.addOperand(MCOperand::CreateImm(Imm));
2205 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2206 assert(N == 1 && "Invalid number of operands!");
2207 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2210 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2211 assert(N == 1 && "Invalid number of operands!");
2212 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2215 void addVecListOperands(MCInst &Inst, unsigned N) const {
2216 assert(N == 1 && "Invalid number of operands!");
2217 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2220 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2221 assert(N == 2 && "Invalid number of operands!");
2222 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2223 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2226 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2227 assert(N == 1 && "Invalid number of operands!");
2228 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2231 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2232 assert(N == 1 && "Invalid number of operands!");
2233 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2236 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2237 assert(N == 1 && "Invalid number of operands!");
2238 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2241 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2242 assert(N == 1 && "Invalid number of operands!");
2243 // The immediate encodes the type of constant as well as the value.
2244 // Mask in that this is an i8 splat.
2245 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2246 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2249 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2250 assert(N == 1 && "Invalid number of operands!");
2251 // The immediate encodes the type of constant as well as the value.
2252 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2253 unsigned Value = CE->getValue();
2255 Value = (Value >> 8) | 0xa00;
2258 Inst.addOperand(MCOperand::CreateImm(Value));
2261 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2262 assert(N == 1 && "Invalid number of operands!");
2263 // The immediate encodes the type of constant as well as the value.
2264 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2265 unsigned Value = CE->getValue();
2266 if (Value >= 256 && Value <= 0xff00)
2267 Value = (Value >> 8) | 0x200;
2268 else if (Value > 0xffff && Value <= 0xff0000)
2269 Value = (Value >> 16) | 0x400;
2270 else if (Value > 0xffffff)
2271 Value = (Value >> 24) | 0x600;
2272 Inst.addOperand(MCOperand::CreateImm(Value));
2275 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2276 assert(N == 1 && "Invalid number of operands!");
2277 // The immediate encodes the type of constant as well as the value.
2278 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2279 unsigned Value = CE->getValue();
2280 if (Value >= 256 && Value <= 0xffff)
2281 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2282 else if (Value > 0xffff && Value <= 0xffffff)
2283 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2284 else if (Value > 0xffffff)
2285 Value = (Value >> 24) | 0x600;
2286 Inst.addOperand(MCOperand::CreateImm(Value));
2289 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2290 assert(N == 1 && "Invalid number of operands!");
2291 // The immediate encodes the type of constant as well as the value.
2292 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2293 unsigned Value = ~CE->getValue();
2294 if (Value >= 256 && Value <= 0xffff)
2295 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2296 else if (Value > 0xffff && Value <= 0xffffff)
2297 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2298 else if (Value > 0xffffff)
2299 Value = (Value >> 24) | 0x600;
2300 Inst.addOperand(MCOperand::CreateImm(Value));
2303 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2304 assert(N == 1 && "Invalid number of operands!");
2305 // The immediate encodes the type of constant as well as the value.
2306 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2307 uint64_t Value = CE->getValue();
2309 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2310 Imm |= (Value & 1) << i;
2312 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2315 virtual void print(raw_ostream &OS) const;
2317 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2318 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2319 Op->ITMask.Mask = Mask;
2325 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2326 ARMOperand *Op = new ARMOperand(k_CondCode);
2333 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2334 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2335 Op->Cop.Val = CopVal;
2341 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2342 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2343 Op->Cop.Val = CopVal;
2349 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2350 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2357 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2358 ARMOperand *Op = new ARMOperand(k_CCOut);
2359 Op->Reg.RegNum = RegNum;
2365 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2366 ARMOperand *Op = new ARMOperand(k_Token);
2367 Op->Tok.Data = Str.data();
2368 Op->Tok.Length = Str.size();
2374 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2375 ARMOperand *Op = new ARMOperand(k_Register);
2376 Op->Reg.RegNum = RegNum;
2382 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2387 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2388 Op->RegShiftedReg.ShiftTy = ShTy;
2389 Op->RegShiftedReg.SrcReg = SrcReg;
2390 Op->RegShiftedReg.ShiftReg = ShiftReg;
2391 Op->RegShiftedReg.ShiftImm = ShiftImm;
2397 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2401 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2402 Op->RegShiftedImm.ShiftTy = ShTy;
2403 Op->RegShiftedImm.SrcReg = SrcReg;
2404 Op->RegShiftedImm.ShiftImm = ShiftImm;
2410 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2412 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2413 Op->ShifterImm.isASR = isASR;
2414 Op->ShifterImm.Imm = Imm;
2420 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2421 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2422 Op->RotImm.Imm = Imm;
2428 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2430 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2431 Op->Bitfield.LSB = LSB;
2432 Op->Bitfield.Width = Width;
2439 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2440 SMLoc StartLoc, SMLoc EndLoc) {
2441 assert (Regs.size() > 0 && "RegList contains no registers?");
2442 KindTy Kind = k_RegisterList;
2444 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2445 Kind = k_DPRRegisterList;
2446 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2447 contains(Regs.front().second))
2448 Kind = k_SPRRegisterList;
2450 // Sort based on the register encoding values.
2451 array_pod_sort(Regs.begin(), Regs.end());
2453 ARMOperand *Op = new ARMOperand(Kind);
2454 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2455 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2456 Op->Registers.push_back(I->second);
2457 Op->StartLoc = StartLoc;
2458 Op->EndLoc = EndLoc;
2462 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2463 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2464 ARMOperand *Op = new ARMOperand(k_VectorList);
2465 Op->VectorList.RegNum = RegNum;
2466 Op->VectorList.Count = Count;
2467 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2473 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2474 bool isDoubleSpaced,
2476 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2477 Op->VectorList.RegNum = RegNum;
2478 Op->VectorList.Count = Count;
2479 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2485 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2487 bool isDoubleSpaced,
2489 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2490 Op->VectorList.RegNum = RegNum;
2491 Op->VectorList.Count = Count;
2492 Op->VectorList.LaneIndex = Index;
2493 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2499 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2501 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2502 Op->VectorIndex.Val = Idx;
2508 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2509 ARMOperand *Op = new ARMOperand(k_Immediate);
2516 static ARMOperand *CreateMem(unsigned BaseRegNum,
2517 const MCConstantExpr *OffsetImm,
2518 unsigned OffsetRegNum,
2519 ARM_AM::ShiftOpc ShiftType,
2524 ARMOperand *Op = new ARMOperand(k_Memory);
2525 Op->Memory.BaseRegNum = BaseRegNum;
2526 Op->Memory.OffsetImm = OffsetImm;
2527 Op->Memory.OffsetRegNum = OffsetRegNum;
2528 Op->Memory.ShiftType = ShiftType;
2529 Op->Memory.ShiftImm = ShiftImm;
2530 Op->Memory.Alignment = Alignment;
2531 Op->Memory.isNegative = isNegative;
2537 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2538 ARM_AM::ShiftOpc ShiftTy,
2541 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2542 Op->PostIdxReg.RegNum = RegNum;
2543 Op->PostIdxReg.isAdd = isAdd;
2544 Op->PostIdxReg.ShiftTy = ShiftTy;
2545 Op->PostIdxReg.ShiftImm = ShiftImm;
2551 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2552 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2553 Op->MBOpt.Val = Opt;
2559 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2561 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2562 Op->ISBOpt.Val = Opt;
2568 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2569 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2570 Op->IFlags.Val = IFlags;
2576 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2577 ARMOperand *Op = new ARMOperand(k_MSRMask);
2578 Op->MMask.Val = MMask;
2585 } // end anonymous namespace.
2587 void ARMOperand::print(raw_ostream &OS) const {
2590 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2593 OS << "<ccout " << getReg() << ">";
2595 case k_ITCondMask: {
2596 static const char *const MaskStr[] = {
2597 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2598 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2600 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2601 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2605 OS << "<coprocessor number: " << getCoproc() << ">";
2608 OS << "<coprocessor register: " << getCoproc() << ">";
2610 case k_CoprocOption:
2611 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2614 OS << "<mask: " << getMSRMask() << ">";
2617 getImm()->print(OS);
2619 case k_MemBarrierOpt:
2620 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2622 case k_InstSyncBarrierOpt:
2623 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2627 << " base:" << Memory.BaseRegNum;
2630 case k_PostIndexRegister:
2631 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2632 << PostIdxReg.RegNum;
2633 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2634 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2635 << PostIdxReg.ShiftImm;
2638 case k_ProcIFlags: {
2639 OS << "<ARM_PROC::";
2640 unsigned IFlags = getProcIFlags();
2641 for (int i=2; i >= 0; --i)
2642 if (IFlags & (1 << i))
2643 OS << ARM_PROC::IFlagsToString(1 << i);
2648 OS << "<register " << getReg() << ">";
2650 case k_ShifterImmediate:
2651 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2652 << " #" << ShifterImm.Imm << ">";
2654 case k_ShiftedRegister:
2655 OS << "<so_reg_reg "
2656 << RegShiftedReg.SrcReg << " "
2657 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2658 << " " << RegShiftedReg.ShiftReg << ">";
2660 case k_ShiftedImmediate:
2661 OS << "<so_reg_imm "
2662 << RegShiftedImm.SrcReg << " "
2663 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2664 << " #" << RegShiftedImm.ShiftImm << ">";
2666 case k_RotateImmediate:
2667 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2669 case k_BitfieldDescriptor:
2670 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2671 << ", width: " << Bitfield.Width << ">";
2673 case k_RegisterList:
2674 case k_DPRRegisterList:
2675 case k_SPRRegisterList: {
2676 OS << "<register_list ";
2678 const SmallVectorImpl<unsigned> &RegList = getRegList();
2679 for (SmallVectorImpl<unsigned>::const_iterator
2680 I = RegList.begin(), E = RegList.end(); I != E; ) {
2682 if (++I < E) OS << ", ";
2689 OS << "<vector_list " << VectorList.Count << " * "
2690 << VectorList.RegNum << ">";
2692 case k_VectorListAllLanes:
2693 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2694 << VectorList.RegNum << ">";
2696 case k_VectorListIndexed:
2697 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2698 << VectorList.Count << " * " << VectorList.RegNum << ">";
2701 OS << "'" << getToken() << "'";
2704 OS << "<vectorindex " << getVectorIndex() << ">";
2709 /// @name Auto-generated Match Functions
2712 static unsigned MatchRegisterName(StringRef Name);
2716 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2717 SMLoc &StartLoc, SMLoc &EndLoc) {
2718 StartLoc = Parser.getTok().getLoc();
2719 EndLoc = Parser.getTok().getEndLoc();
2720 RegNo = tryParseRegister();
2722 return (RegNo == (unsigned)-1);
2725 /// Try to parse a register name. The token must be an Identifier when called,
2726 /// and if it is a register name the token is eaten and the register number is
2727 /// returned. Otherwise return -1.
2729 int ARMAsmParser::tryParseRegister() {
2730 const AsmToken &Tok = Parser.getTok();
2731 if (Tok.isNot(AsmToken::Identifier)) return -1;
2733 std::string lowerCase = Tok.getString().lower();
2734 unsigned RegNum = MatchRegisterName(lowerCase);
2736 RegNum = StringSwitch<unsigned>(lowerCase)
2737 .Case("r13", ARM::SP)
2738 .Case("r14", ARM::LR)
2739 .Case("r15", ARM::PC)
2740 .Case("ip", ARM::R12)
2741 // Additional register name aliases for 'gas' compatibility.
2742 .Case("a1", ARM::R0)
2743 .Case("a2", ARM::R1)
2744 .Case("a3", ARM::R2)
2745 .Case("a4", ARM::R3)
2746 .Case("v1", ARM::R4)
2747 .Case("v2", ARM::R5)
2748 .Case("v3", ARM::R6)
2749 .Case("v4", ARM::R7)
2750 .Case("v5", ARM::R8)
2751 .Case("v6", ARM::R9)
2752 .Case("v7", ARM::R10)
2753 .Case("v8", ARM::R11)
2754 .Case("sb", ARM::R9)
2755 .Case("sl", ARM::R10)
2756 .Case("fp", ARM::R11)
2760 // Check for aliases registered via .req. Canonicalize to lower case.
2761 // That's more consistent since register names are case insensitive, and
2762 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2763 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2764 // If no match, return failure.
2765 if (Entry == RegisterReqs.end())
2767 Parser.Lex(); // Eat identifier token.
2768 return Entry->getValue();
2771 Parser.Lex(); // Eat identifier token.
2776 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2777 // If a recoverable error occurs, return 1. If an irrecoverable error
2778 // occurs, return -1. An irrecoverable error is one where tokens have been
2779 // consumed in the process of trying to parse the shifter (i.e., when it is
2780 // indeed a shifter operand, but malformed).
2781 int ARMAsmParser::tryParseShiftRegister(
2782 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2783 SMLoc S = Parser.getTok().getLoc();
2784 const AsmToken &Tok = Parser.getTok();
2785 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2787 std::string lowerCase = Tok.getString().lower();
2788 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2789 .Case("asl", ARM_AM::lsl)
2790 .Case("lsl", ARM_AM::lsl)
2791 .Case("lsr", ARM_AM::lsr)
2792 .Case("asr", ARM_AM::asr)
2793 .Case("ror", ARM_AM::ror)
2794 .Case("rrx", ARM_AM::rrx)
2795 .Default(ARM_AM::no_shift);
2797 if (ShiftTy == ARM_AM::no_shift)
2800 Parser.Lex(); // Eat the operator.
2802 // The source register for the shift has already been added to the
2803 // operand list, so we need to pop it off and combine it into the shifted
2804 // register operand instead.
2805 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2806 if (!PrevOp->isReg())
2807 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2808 int SrcReg = PrevOp->getReg();
2813 if (ShiftTy == ARM_AM::rrx) {
2814 // RRX Doesn't have an explicit shift amount. The encoder expects
2815 // the shift register to be the same as the source register. Seems odd,
2819 // Figure out if this is shifted by a constant or a register (for non-RRX).
2820 if (Parser.getTok().is(AsmToken::Hash) ||
2821 Parser.getTok().is(AsmToken::Dollar)) {
2822 Parser.Lex(); // Eat hash.
2823 SMLoc ImmLoc = Parser.getTok().getLoc();
2824 const MCExpr *ShiftExpr = 0;
2825 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2826 Error(ImmLoc, "invalid immediate shift value");
2829 // The expression must be evaluatable as an immediate.
2830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2832 Error(ImmLoc, "invalid immediate shift value");
2835 // Range check the immediate.
2836 // lsl, ror: 0 <= imm <= 31
2837 // lsr, asr: 0 <= imm <= 32
2838 Imm = CE->getValue();
2840 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2841 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2842 Error(ImmLoc, "immediate shift value out of range");
2845 // shift by zero is a nop. Always send it through as lsl.
2846 // ('as' compatibility)
2848 ShiftTy = ARM_AM::lsl;
2849 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2850 SMLoc L = Parser.getTok().getLoc();
2851 EndLoc = Parser.getTok().getEndLoc();
2852 ShiftReg = tryParseRegister();
2853 if (ShiftReg == -1) {
2854 Error (L, "expected immediate or register in shift operand");
2858 Error (Parser.getTok().getLoc(),
2859 "expected immediate or register in shift operand");
2864 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2865 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2869 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2876 /// Try to parse a register name. The token must be an Identifier when called.
2877 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2878 /// if there is a "writeback". 'true' if it's not a register.
2880 /// TODO this is likely to change to allow different register types and or to
2881 /// parse for a specific register type.
2883 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2884 const AsmToken &RegTok = Parser.getTok();
2885 int RegNo = tryParseRegister();
2889 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2890 RegTok.getEndLoc()));
2892 const AsmToken &ExclaimTok = Parser.getTok();
2893 if (ExclaimTok.is(AsmToken::Exclaim)) {
2894 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2895 ExclaimTok.getLoc()));
2896 Parser.Lex(); // Eat exclaim token
2900 // Also check for an index operand. This is only legal for vector registers,
2901 // but that'll get caught OK in operand matching, so we don't need to
2902 // explicitly filter everything else out here.
2903 if (Parser.getTok().is(AsmToken::LBrac)) {
2904 SMLoc SIdx = Parser.getTok().getLoc();
2905 Parser.Lex(); // Eat left bracket token.
2907 const MCExpr *ImmVal;
2908 if (getParser().parseExpression(ImmVal))
2910 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2912 return TokError("immediate value expected for vector index");
2914 if (Parser.getTok().isNot(AsmToken::RBrac))
2915 return Error(Parser.getTok().getLoc(), "']' expected");
2917 SMLoc E = Parser.getTok().getEndLoc();
2918 Parser.Lex(); // Eat right bracket token.
2920 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2928 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2929 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2931 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2932 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2934 switch (Name.size()) {
2937 if (Name[0] != CoprocOp)
2953 if (Name[0] != CoprocOp || Name[1] != '1')
2957 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2958 case '0': return CoprocOp == 'p'? -1: 10;
2959 case '1': return CoprocOp == 'p'? -1: 11;
2960 case '2': return 12;
2961 case '3': return 13;
2962 case '4': return 14;
2963 case '5': return 15;
2968 /// parseITCondCode - Try to parse a condition code for an IT instruction.
2969 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2970 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2971 SMLoc S = Parser.getTok().getLoc();
2972 const AsmToken &Tok = Parser.getTok();
2973 if (!Tok.is(AsmToken::Identifier))
2974 return MatchOperand_NoMatch;
2975 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
2976 .Case("eq", ARMCC::EQ)
2977 .Case("ne", ARMCC::NE)
2978 .Case("hs", ARMCC::HS)
2979 .Case("cs", ARMCC::HS)
2980 .Case("lo", ARMCC::LO)
2981 .Case("cc", ARMCC::LO)
2982 .Case("mi", ARMCC::MI)
2983 .Case("pl", ARMCC::PL)
2984 .Case("vs", ARMCC::VS)
2985 .Case("vc", ARMCC::VC)
2986 .Case("hi", ARMCC::HI)
2987 .Case("ls", ARMCC::LS)
2988 .Case("ge", ARMCC::GE)
2989 .Case("lt", ARMCC::LT)
2990 .Case("gt", ARMCC::GT)
2991 .Case("le", ARMCC::LE)
2992 .Case("al", ARMCC::AL)
2995 return MatchOperand_NoMatch;
2996 Parser.Lex(); // Eat the token.
2998 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3000 return MatchOperand_Success;
3003 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
3004 /// token must be an Identifier when called, and if it is a coprocessor
3005 /// number, the token is eaten and the operand is added to the operand list.
3006 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3007 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3008 SMLoc S = Parser.getTok().getLoc();
3009 const AsmToken &Tok = Parser.getTok();
3010 if (Tok.isNot(AsmToken::Identifier))
3011 return MatchOperand_NoMatch;
3013 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
3015 return MatchOperand_NoMatch;
3017 Parser.Lex(); // Eat identifier token.
3018 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
3019 return MatchOperand_Success;
3022 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
3023 /// token must be an Identifier when called, and if it is a coprocessor
3024 /// number, the token is eaten and the operand is added to the operand list.
3025 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3026 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3027 SMLoc S = Parser.getTok().getLoc();
3028 const AsmToken &Tok = Parser.getTok();
3029 if (Tok.isNot(AsmToken::Identifier))
3030 return MatchOperand_NoMatch;
3032 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3034 return MatchOperand_NoMatch;
3036 Parser.Lex(); // Eat identifier token.
3037 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
3038 return MatchOperand_Success;
3041 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3042 /// coproc_option : '{' imm0_255 '}'
3043 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3044 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3045 SMLoc S = Parser.getTok().getLoc();
3047 // If this isn't a '{', this isn't a coprocessor immediate operand.
3048 if (Parser.getTok().isNot(AsmToken::LCurly))
3049 return MatchOperand_NoMatch;
3050 Parser.Lex(); // Eat the '{'
3053 SMLoc Loc = Parser.getTok().getLoc();
3054 if (getParser().parseExpression(Expr)) {
3055 Error(Loc, "illegal expression");
3056 return MatchOperand_ParseFail;
3058 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3059 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3060 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3061 return MatchOperand_ParseFail;
3063 int Val = CE->getValue();
3065 // Check for and consume the closing '}'
3066 if (Parser.getTok().isNot(AsmToken::RCurly))
3067 return MatchOperand_ParseFail;
3068 SMLoc E = Parser.getTok().getEndLoc();
3069 Parser.Lex(); // Eat the '}'
3071 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3072 return MatchOperand_Success;
3075 // For register list parsing, we need to map from raw GPR register numbering
3076 // to the enumeration values. The enumeration values aren't sorted by
3077 // register number due to our using "sp", "lr" and "pc" as canonical names.
3078 static unsigned getNextRegister(unsigned Reg) {
3079 // If this is a GPR, we need to do it manually, otherwise we can rely
3080 // on the sort ordering of the enumeration since the other reg-classes
3082 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3085 default: llvm_unreachable("Invalid GPR number!");
3086 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3087 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3088 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3089 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3090 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3091 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3092 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3093 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3097 // Return the low-subreg of a given Q register.
3098 static unsigned getDRegFromQReg(unsigned QReg) {
3100 default: llvm_unreachable("expected a Q register!");
3101 case ARM::Q0: return ARM::D0;
3102 case ARM::Q1: return ARM::D2;
3103 case ARM::Q2: return ARM::D4;
3104 case ARM::Q3: return ARM::D6;
3105 case ARM::Q4: return ARM::D8;
3106 case ARM::Q5: return ARM::D10;
3107 case ARM::Q6: return ARM::D12;
3108 case ARM::Q7: return ARM::D14;
3109 case ARM::Q8: return ARM::D16;
3110 case ARM::Q9: return ARM::D18;
3111 case ARM::Q10: return ARM::D20;
3112 case ARM::Q11: return ARM::D22;
3113 case ARM::Q12: return ARM::D24;
3114 case ARM::Q13: return ARM::D26;
3115 case ARM::Q14: return ARM::D28;
3116 case ARM::Q15: return ARM::D30;
3120 /// Parse a register list.
3122 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3123 assert(Parser.getTok().is(AsmToken::LCurly) &&
3124 "Token is not a Left Curly Brace");
3125 SMLoc S = Parser.getTok().getLoc();
3126 Parser.Lex(); // Eat '{' token.
3127 SMLoc RegLoc = Parser.getTok().getLoc();
3129 // Check the first register in the list to see what register class
3130 // this is a list of.
3131 int Reg = tryParseRegister();
3133 return Error(RegLoc, "register expected");
3135 // The reglist instructions have at most 16 registers, so reserve
3136 // space for that many.
3138 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3140 // Allow Q regs and just interpret them as the two D sub-registers.
3141 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3142 Reg = getDRegFromQReg(Reg);
3143 EReg = MRI->getEncodingValue(Reg);
3144 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3147 const MCRegisterClass *RC;
3148 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3149 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3150 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3151 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3152 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3153 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3155 return Error(RegLoc, "invalid register in register list");
3157 // Store the register.
3158 EReg = MRI->getEncodingValue(Reg);
3159 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3161 // This starts immediately after the first register token in the list,
3162 // so we can see either a comma or a minus (range separator) as a legal
3164 while (Parser.getTok().is(AsmToken::Comma) ||
3165 Parser.getTok().is(AsmToken::Minus)) {
3166 if (Parser.getTok().is(AsmToken::Minus)) {
3167 Parser.Lex(); // Eat the minus.
3168 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3169 int EndReg = tryParseRegister();
3171 return Error(AfterMinusLoc, "register expected");
3172 // Allow Q regs and just interpret them as the two D sub-registers.
3173 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3174 EndReg = getDRegFromQReg(EndReg) + 1;
3175 // If the register is the same as the start reg, there's nothing
3179 // The register must be in the same register class as the first.
3180 if (!RC->contains(EndReg))
3181 return Error(AfterMinusLoc, "invalid register in register list");
3182 // Ranges must go from low to high.
3183 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3184 return Error(AfterMinusLoc, "bad range in register list");
3186 // Add all the registers in the range to the register list.
3187 while (Reg != EndReg) {
3188 Reg = getNextRegister(Reg);
3189 EReg = MRI->getEncodingValue(Reg);
3190 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3194 Parser.Lex(); // Eat the comma.
3195 RegLoc = Parser.getTok().getLoc();
3197 const AsmToken RegTok = Parser.getTok();
3198 Reg = tryParseRegister();
3200 return Error(RegLoc, "register expected");
3201 // Allow Q regs and just interpret them as the two D sub-registers.
3202 bool isQReg = false;
3203 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3204 Reg = getDRegFromQReg(Reg);
3207 // The register must be in the same register class as the first.
3208 if (!RC->contains(Reg))
3209 return Error(RegLoc, "invalid register in register list");
3210 // List must be monotonically increasing.
3211 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3212 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3213 Warning(RegLoc, "register list not in ascending order");
3215 return Error(RegLoc, "register list not in ascending order");
3217 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3218 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3219 ") in register list");
3222 // VFP register lists must also be contiguous.
3223 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3225 return Error(RegLoc, "non-contiguous register range");
3226 EReg = MRI->getEncodingValue(Reg);
3227 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3229 EReg = MRI->getEncodingValue(++Reg);
3230 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3234 if (Parser.getTok().isNot(AsmToken::RCurly))
3235 return Error(Parser.getTok().getLoc(), "'}' expected");
3236 SMLoc E = Parser.getTok().getEndLoc();
3237 Parser.Lex(); // Eat '}' token.
3239 // Push the register list operand.
3240 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3242 // The ARM system instruction variants for LDM/STM have a '^' token here.
3243 if (Parser.getTok().is(AsmToken::Caret)) {
3244 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3245 Parser.Lex(); // Eat '^' token.
3251 // Helper function to parse the lane index for vector lists.
3252 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3253 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3254 Index = 0; // Always return a defined index value.
3255 if (Parser.getTok().is(AsmToken::LBrac)) {
3256 Parser.Lex(); // Eat the '['.
3257 if (Parser.getTok().is(AsmToken::RBrac)) {
3258 // "Dn[]" is the 'all lanes' syntax.
3259 LaneKind = AllLanes;
3260 EndLoc = Parser.getTok().getEndLoc();
3261 Parser.Lex(); // Eat the ']'.
3262 return MatchOperand_Success;
3265 // There's an optional '#' token here. Normally there wouldn't be, but
3266 // inline assemble puts one in, and it's friendly to accept that.
3267 if (Parser.getTok().is(AsmToken::Hash))
3268 Parser.Lex(); // Eat '#' or '$'.
3270 const MCExpr *LaneIndex;
3271 SMLoc Loc = Parser.getTok().getLoc();
3272 if (getParser().parseExpression(LaneIndex)) {
3273 Error(Loc, "illegal expression");
3274 return MatchOperand_ParseFail;
3276 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3278 Error(Loc, "lane index must be empty or an integer");
3279 return MatchOperand_ParseFail;
3281 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3282 Error(Parser.getTok().getLoc(), "']' expected");
3283 return MatchOperand_ParseFail;
3285 EndLoc = Parser.getTok().getEndLoc();
3286 Parser.Lex(); // Eat the ']'.
3287 int64_t Val = CE->getValue();
3289 // FIXME: Make this range check context sensitive for .8, .16, .32.
3290 if (Val < 0 || Val > 7) {
3291 Error(Parser.getTok().getLoc(), "lane index out of range");
3292 return MatchOperand_ParseFail;
3295 LaneKind = IndexedLane;
3296 return MatchOperand_Success;
3299 return MatchOperand_Success;
3302 // parse a vector register list
3303 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3304 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3305 VectorLaneTy LaneKind;
3307 SMLoc S = Parser.getTok().getLoc();
3308 // As an extension (to match gas), support a plain D register or Q register
3309 // (without encosing curly braces) as a single or double entry list,
3311 if (Parser.getTok().is(AsmToken::Identifier)) {
3312 SMLoc E = Parser.getTok().getEndLoc();
3313 int Reg = tryParseRegister();
3315 return MatchOperand_NoMatch;
3316 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3317 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3318 if (Res != MatchOperand_Success)
3322 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3325 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3329 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3334 return MatchOperand_Success;
3336 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3337 Reg = getDRegFromQReg(Reg);
3338 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3339 if (Res != MatchOperand_Success)
3343 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3344 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3345 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3348 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3349 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3350 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3354 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3359 return MatchOperand_Success;
3361 Error(S, "vector register expected");
3362 return MatchOperand_ParseFail;
3365 if (Parser.getTok().isNot(AsmToken::LCurly))
3366 return MatchOperand_NoMatch;
3368 Parser.Lex(); // Eat '{' token.
3369 SMLoc RegLoc = Parser.getTok().getLoc();
3371 int Reg = tryParseRegister();
3373 Error(RegLoc, "register expected");
3374 return MatchOperand_ParseFail;
3378 unsigned FirstReg = Reg;
3379 // The list is of D registers, but we also allow Q regs and just interpret
3380 // them as the two D sub-registers.
3381 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3382 FirstReg = Reg = getDRegFromQReg(Reg);
3383 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3384 // it's ambiguous with four-register single spaced.
3390 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3391 return MatchOperand_ParseFail;
3393 while (Parser.getTok().is(AsmToken::Comma) ||
3394 Parser.getTok().is(AsmToken::Minus)) {
3395 if (Parser.getTok().is(AsmToken::Minus)) {
3397 Spacing = 1; // Register range implies a single spaced list.
3398 else if (Spacing == 2) {
3399 Error(Parser.getTok().getLoc(),
3400 "sequential registers in double spaced list");
3401 return MatchOperand_ParseFail;
3403 Parser.Lex(); // Eat the minus.
3404 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3405 int EndReg = tryParseRegister();
3407 Error(AfterMinusLoc, "register expected");
3408 return MatchOperand_ParseFail;
3410 // Allow Q regs and just interpret them as the two D sub-registers.
3411 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3412 EndReg = getDRegFromQReg(EndReg) + 1;
3413 // If the register is the same as the start reg, there's nothing
3417 // The register must be in the same register class as the first.
3418 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3419 Error(AfterMinusLoc, "invalid register in register list");
3420 return MatchOperand_ParseFail;
3422 // Ranges must go from low to high.
3424 Error(AfterMinusLoc, "bad range in register list");
3425 return MatchOperand_ParseFail;
3427 // Parse the lane specifier if present.
3428 VectorLaneTy NextLaneKind;
3429 unsigned NextLaneIndex;
3430 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3431 MatchOperand_Success)
3432 return MatchOperand_ParseFail;
3433 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3434 Error(AfterMinusLoc, "mismatched lane index in register list");
3435 return MatchOperand_ParseFail;
3438 // Add all the registers in the range to the register list.
3439 Count += EndReg - Reg;
3443 Parser.Lex(); // Eat the comma.
3444 RegLoc = Parser.getTok().getLoc();
3446 Reg = tryParseRegister();
3448 Error(RegLoc, "register expected");
3449 return MatchOperand_ParseFail;
3451 // vector register lists must be contiguous.
3452 // It's OK to use the enumeration values directly here rather, as the
3453 // VFP register classes have the enum sorted properly.
3455 // The list is of D registers, but we also allow Q regs and just interpret
3456 // them as the two D sub-registers.
3457 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3459 Spacing = 1; // Register range implies a single spaced list.
3460 else if (Spacing == 2) {
3462 "invalid register in double-spaced list (must be 'D' register')");
3463 return MatchOperand_ParseFail;
3465 Reg = getDRegFromQReg(Reg);
3466 if (Reg != OldReg + 1) {
3467 Error(RegLoc, "non-contiguous register range");
3468 return MatchOperand_ParseFail;
3472 // Parse the lane specifier if present.
3473 VectorLaneTy NextLaneKind;
3474 unsigned NextLaneIndex;
3475 SMLoc LaneLoc = Parser.getTok().getLoc();
3476 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3477 MatchOperand_Success)
3478 return MatchOperand_ParseFail;
3479 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3480 Error(LaneLoc, "mismatched lane index in register list");
3481 return MatchOperand_ParseFail;
3485 // Normal D register.
3486 // Figure out the register spacing (single or double) of the list if
3487 // we don't know it already.
3489 Spacing = 1 + (Reg == OldReg + 2);
3491 // Just check that it's contiguous and keep going.
3492 if (Reg != OldReg + Spacing) {
3493 Error(RegLoc, "non-contiguous register range");
3494 return MatchOperand_ParseFail;
3497 // Parse the lane specifier if present.
3498 VectorLaneTy NextLaneKind;
3499 unsigned NextLaneIndex;
3500 SMLoc EndLoc = Parser.getTok().getLoc();
3501 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3502 return MatchOperand_ParseFail;
3503 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3504 Error(EndLoc, "mismatched lane index in register list");
3505 return MatchOperand_ParseFail;
3509 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3510 Error(Parser.getTok().getLoc(), "'}' expected");
3511 return MatchOperand_ParseFail;
3513 E = Parser.getTok().getEndLoc();
3514 Parser.Lex(); // Eat '}' token.
3518 // Two-register operands have been converted to the
3519 // composite register classes.
3521 const MCRegisterClass *RC = (Spacing == 1) ?
3522 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3523 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3524 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3527 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3528 (Spacing == 2), S, E));
3531 // Two-register operands have been converted to the
3532 // composite register classes.
3534 const MCRegisterClass *RC = (Spacing == 1) ?
3535 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3536 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3537 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3539 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3544 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3550 return MatchOperand_Success;
3553 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3554 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3555 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3556 SMLoc S = Parser.getTok().getLoc();
3557 const AsmToken &Tok = Parser.getTok();
3560 if (Tok.is(AsmToken::Identifier)) {
3561 StringRef OptStr = Tok.getString();
3563 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3564 .Case("sy", ARM_MB::SY)
3565 .Case("st", ARM_MB::ST)
3566 .Case("ld", ARM_MB::LD)
3567 .Case("sh", ARM_MB::ISH)
3568 .Case("ish", ARM_MB::ISH)
3569 .Case("shst", ARM_MB::ISHST)
3570 .Case("ishst", ARM_MB::ISHST)
3571 .Case("ishld", ARM_MB::ISHLD)
3572 .Case("nsh", ARM_MB::NSH)
3573 .Case("un", ARM_MB::NSH)
3574 .Case("nshst", ARM_MB::NSHST)
3575 .Case("nshld", ARM_MB::NSHLD)
3576 .Case("unst", ARM_MB::NSHST)
3577 .Case("osh", ARM_MB::OSH)
3578 .Case("oshst", ARM_MB::OSHST)
3579 .Case("oshld", ARM_MB::OSHLD)
3582 // ishld, oshld, nshld and ld are only available from ARMv8.
3583 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3584 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3588 return MatchOperand_NoMatch;
3590 Parser.Lex(); // Eat identifier token.
3591 } else if (Tok.is(AsmToken::Hash) ||
3592 Tok.is(AsmToken::Dollar) ||
3593 Tok.is(AsmToken::Integer)) {
3594 if (Parser.getTok().isNot(AsmToken::Integer))
3595 Parser.Lex(); // Eat '#' or '$'.
3596 SMLoc Loc = Parser.getTok().getLoc();
3598 const MCExpr *MemBarrierID;
3599 if (getParser().parseExpression(MemBarrierID)) {
3600 Error(Loc, "illegal expression");
3601 return MatchOperand_ParseFail;
3604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3606 Error(Loc, "constant expression expected");
3607 return MatchOperand_ParseFail;
3610 int Val = CE->getValue();
3612 Error(Loc, "immediate value out of range");
3613 return MatchOperand_ParseFail;
3616 Opt = ARM_MB::RESERVED_0 + Val;
3618 return MatchOperand_ParseFail;
3620 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3621 return MatchOperand_Success;
3624 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3625 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3626 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3627 SMLoc S = Parser.getTok().getLoc();
3628 const AsmToken &Tok = Parser.getTok();
3631 if (Tok.is(AsmToken::Identifier)) {
3632 StringRef OptStr = Tok.getString();
3634 if (OptStr.equals_lower("sy"))
3637 return MatchOperand_NoMatch;
3639 Parser.Lex(); // Eat identifier token.
3640 } else if (Tok.is(AsmToken::Hash) ||
3641 Tok.is(AsmToken::Dollar) ||
3642 Tok.is(AsmToken::Integer)) {
3643 if (Parser.getTok().isNot(AsmToken::Integer))
3644 Parser.Lex(); // Eat '#' or '$'.
3645 SMLoc Loc = Parser.getTok().getLoc();
3647 const MCExpr *ISBarrierID;
3648 if (getParser().parseExpression(ISBarrierID)) {
3649 Error(Loc, "illegal expression");
3650 return MatchOperand_ParseFail;
3653 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3655 Error(Loc, "constant expression expected");
3656 return MatchOperand_ParseFail;
3659 int Val = CE->getValue();
3661 Error(Loc, "immediate value out of range");
3662 return MatchOperand_ParseFail;
3665 Opt = ARM_ISB::RESERVED_0 + Val;
3667 return MatchOperand_ParseFail;
3669 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3670 (ARM_ISB::InstSyncBOpt)Opt, S));
3671 return MatchOperand_Success;
3675 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3676 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3677 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3678 SMLoc S = Parser.getTok().getLoc();
3679 const AsmToken &Tok = Parser.getTok();
3680 if (!Tok.is(AsmToken::Identifier))
3681 return MatchOperand_NoMatch;
3682 StringRef IFlagsStr = Tok.getString();
3684 // An iflags string of "none" is interpreted to mean that none of the AIF
3685 // bits are set. Not a terribly useful instruction, but a valid encoding.
3686 unsigned IFlags = 0;
3687 if (IFlagsStr != "none") {
3688 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3689 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3690 .Case("a", ARM_PROC::A)
3691 .Case("i", ARM_PROC::I)
3692 .Case("f", ARM_PROC::F)
3695 // If some specific iflag is already set, it means that some letter is
3696 // present more than once, this is not acceptable.
3697 if (Flag == ~0U || (IFlags & Flag))
3698 return MatchOperand_NoMatch;
3704 Parser.Lex(); // Eat identifier token.
3705 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3706 return MatchOperand_Success;
3709 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3710 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3711 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3712 SMLoc S = Parser.getTok().getLoc();
3713 const AsmToken &Tok = Parser.getTok();
3714 if (!Tok.is(AsmToken::Identifier))
3715 return MatchOperand_NoMatch;
3716 StringRef Mask = Tok.getString();
3719 // See ARMv6-M 10.1.1
3720 std::string Name = Mask.lower();
3721 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3722 // Note: in the documentation:
3723 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3724 // for MSR APSR_nzcvq.
3725 // but we do make it an alias here. This is so to get the "mask encoding"
3726 // bits correct on MSR APSR writes.
3728 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3729 // should really only be allowed when writing a special register. Note
3730 // they get dropped in the MRS instruction reading a special register as
3731 // the SYSm field is only 8 bits.
3733 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3734 // includes the DSP extension but that is not checked.
3735 .Case("apsr", 0x800)
3736 .Case("apsr_nzcvq", 0x800)
3737 .Case("apsr_g", 0x400)
3738 .Case("apsr_nzcvqg", 0xc00)
3739 .Case("iapsr", 0x801)
3740 .Case("iapsr_nzcvq", 0x801)
3741 .Case("iapsr_g", 0x401)
3742 .Case("iapsr_nzcvqg", 0xc01)
3743 .Case("eapsr", 0x802)
3744 .Case("eapsr_nzcvq", 0x802)
3745 .Case("eapsr_g", 0x402)
3746 .Case("eapsr_nzcvqg", 0xc02)
3747 .Case("xpsr", 0x803)
3748 .Case("xpsr_nzcvq", 0x803)
3749 .Case("xpsr_g", 0x403)
3750 .Case("xpsr_nzcvqg", 0xc03)
3751 .Case("ipsr", 0x805)
3752 .Case("epsr", 0x806)
3753 .Case("iepsr", 0x807)
3756 .Case("primask", 0x810)
3757 .Case("basepri", 0x811)
3758 .Case("basepri_max", 0x812)
3759 .Case("faultmask", 0x813)
3760 .Case("control", 0x814)
3763 if (FlagsVal == ~0U)
3764 return MatchOperand_NoMatch;
3766 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3767 // basepri, basepri_max and faultmask only valid for V7m.
3768 return MatchOperand_NoMatch;
3770 Parser.Lex(); // Eat identifier token.
3771 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3772 return MatchOperand_Success;
3775 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3776 size_t Start = 0, Next = Mask.find('_');
3777 StringRef Flags = "";
3778 std::string SpecReg = Mask.slice(Start, Next).lower();
3779 if (Next != StringRef::npos)
3780 Flags = Mask.slice(Next+1, Mask.size());
3782 // FlagsVal contains the complete mask:
3784 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3785 unsigned FlagsVal = 0;
3787 if (SpecReg == "apsr") {
3788 FlagsVal = StringSwitch<unsigned>(Flags)
3789 .Case("nzcvq", 0x8) // same as CPSR_f
3790 .Case("g", 0x4) // same as CPSR_s
3791 .Case("nzcvqg", 0xc) // same as CPSR_fs
3794 if (FlagsVal == ~0U) {
3796 return MatchOperand_NoMatch;
3798 FlagsVal = 8; // No flag
3800 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3801 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3802 if (Flags == "all" || Flags == "")
3804 for (int i = 0, e = Flags.size(); i != e; ++i) {
3805 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3812 // If some specific flag is already set, it means that some letter is
3813 // present more than once, this is not acceptable.
3814 if (FlagsVal == ~0U || (FlagsVal & Flag))
3815 return MatchOperand_NoMatch;
3818 } else // No match for special register.
3819 return MatchOperand_NoMatch;
3821 // Special register without flags is NOT equivalent to "fc" flags.
3822 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3823 // two lines would enable gas compatibility at the expense of breaking
3829 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3830 if (SpecReg == "spsr")
3833 Parser.Lex(); // Eat identifier token.
3834 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3835 return MatchOperand_Success;
3838 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3839 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3840 int Low, int High) {
3841 const AsmToken &Tok = Parser.getTok();
3842 if (Tok.isNot(AsmToken::Identifier)) {
3843 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3844 return MatchOperand_ParseFail;
3846 StringRef ShiftName = Tok.getString();
3847 std::string LowerOp = Op.lower();
3848 std::string UpperOp = Op.upper();
3849 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3850 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3851 return MatchOperand_ParseFail;
3853 Parser.Lex(); // Eat shift type token.
3855 // There must be a '#' and a shift amount.
3856 if (Parser.getTok().isNot(AsmToken::Hash) &&
3857 Parser.getTok().isNot(AsmToken::Dollar)) {
3858 Error(Parser.getTok().getLoc(), "'#' expected");
3859 return MatchOperand_ParseFail;
3861 Parser.Lex(); // Eat hash token.
3863 const MCExpr *ShiftAmount;
3864 SMLoc Loc = Parser.getTok().getLoc();
3866 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3867 Error(Loc, "illegal expression");
3868 return MatchOperand_ParseFail;
3870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3872 Error(Loc, "constant expression expected");
3873 return MatchOperand_ParseFail;
3875 int Val = CE->getValue();
3876 if (Val < Low || Val > High) {
3877 Error(Loc, "immediate value out of range");
3878 return MatchOperand_ParseFail;
3881 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3883 return MatchOperand_Success;
3886 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3887 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3888 const AsmToken &Tok = Parser.getTok();
3889 SMLoc S = Tok.getLoc();
3890 if (Tok.isNot(AsmToken::Identifier)) {
3891 Error(S, "'be' or 'le' operand expected");
3892 return MatchOperand_ParseFail;
3894 int Val = StringSwitch<int>(Tok.getString().lower())
3898 Parser.Lex(); // Eat the token.
3901 Error(S, "'be' or 'le' operand expected");
3902 return MatchOperand_ParseFail;
3904 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3906 S, Tok.getEndLoc()));
3907 return MatchOperand_Success;
3910 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3911 /// instructions. Legal values are:
3912 /// lsl #n 'n' in [0,31]
3913 /// asr #n 'n' in [1,32]
3914 /// n == 32 encoded as n == 0.
3915 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3916 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3917 const AsmToken &Tok = Parser.getTok();
3918 SMLoc S = Tok.getLoc();
3919 if (Tok.isNot(AsmToken::Identifier)) {
3920 Error(S, "shift operator 'asr' or 'lsl' expected");
3921 return MatchOperand_ParseFail;
3923 StringRef ShiftName = Tok.getString();
3925 if (ShiftName == "lsl" || ShiftName == "LSL")
3927 else if (ShiftName == "asr" || ShiftName == "ASR")
3930 Error(S, "shift operator 'asr' or 'lsl' expected");
3931 return MatchOperand_ParseFail;
3933 Parser.Lex(); // Eat the operator.
3935 // A '#' and a shift amount.
3936 if (Parser.getTok().isNot(AsmToken::Hash) &&
3937 Parser.getTok().isNot(AsmToken::Dollar)) {
3938 Error(Parser.getTok().getLoc(), "'#' expected");
3939 return MatchOperand_ParseFail;
3941 Parser.Lex(); // Eat hash token.
3942 SMLoc ExLoc = Parser.getTok().getLoc();
3944 const MCExpr *ShiftAmount;
3946 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3947 Error(ExLoc, "malformed shift expression");
3948 return MatchOperand_ParseFail;
3950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3952 Error(ExLoc, "shift amount must be an immediate");
3953 return MatchOperand_ParseFail;
3956 int64_t Val = CE->getValue();
3958 // Shift amount must be in [1,32]
3959 if (Val < 1 || Val > 32) {
3960 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3961 return MatchOperand_ParseFail;
3963 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3964 if (isThumb() && Val == 32) {
3965 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
3966 return MatchOperand_ParseFail;
3968 if (Val == 32) Val = 0;
3970 // Shift amount must be in [1,32]
3971 if (Val < 0 || Val > 31) {
3972 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
3973 return MatchOperand_ParseFail;
3977 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
3979 return MatchOperand_Success;
3982 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3983 /// of instructions. Legal values are:
3984 /// ror #n 'n' in {0, 8, 16, 24}
3985 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3986 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3987 const AsmToken &Tok = Parser.getTok();
3988 SMLoc S = Tok.getLoc();
3989 if (Tok.isNot(AsmToken::Identifier))
3990 return MatchOperand_NoMatch;
3991 StringRef ShiftName = Tok.getString();
3992 if (ShiftName != "ror" && ShiftName != "ROR")
3993 return MatchOperand_NoMatch;
3994 Parser.Lex(); // Eat the operator.
3996 // A '#' and a rotate amount.
3997 if (Parser.getTok().isNot(AsmToken::Hash) &&
3998 Parser.getTok().isNot(AsmToken::Dollar)) {
3999 Error(Parser.getTok().getLoc(), "'#' expected");
4000 return MatchOperand_ParseFail;
4002 Parser.Lex(); // Eat hash token.
4003 SMLoc ExLoc = Parser.getTok().getLoc();
4005 const MCExpr *ShiftAmount;
4007 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4008 Error(ExLoc, "malformed rotate expression");
4009 return MatchOperand_ParseFail;
4011 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4013 Error(ExLoc, "rotate amount must be an immediate");
4014 return MatchOperand_ParseFail;
4017 int64_t Val = CE->getValue();
4018 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4019 // normally, zero is represented in asm by omitting the rotate operand
4021 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
4022 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
4023 return MatchOperand_ParseFail;
4026 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
4028 return MatchOperand_Success;
4031 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4032 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4033 SMLoc S = Parser.getTok().getLoc();
4034 // The bitfield descriptor is really two operands, the LSB and the width.
4035 if (Parser.getTok().isNot(AsmToken::Hash) &&
4036 Parser.getTok().isNot(AsmToken::Dollar)) {
4037 Error(Parser.getTok().getLoc(), "'#' expected");
4038 return MatchOperand_ParseFail;
4040 Parser.Lex(); // Eat hash token.
4042 const MCExpr *LSBExpr;
4043 SMLoc E = Parser.getTok().getLoc();
4044 if (getParser().parseExpression(LSBExpr)) {
4045 Error(E, "malformed immediate expression");
4046 return MatchOperand_ParseFail;
4048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4050 Error(E, "'lsb' operand must be an immediate");
4051 return MatchOperand_ParseFail;
4054 int64_t LSB = CE->getValue();
4055 // The LSB must be in the range [0,31]
4056 if (LSB < 0 || LSB > 31) {
4057 Error(E, "'lsb' operand must be in the range [0,31]");
4058 return MatchOperand_ParseFail;
4060 E = Parser.getTok().getLoc();
4062 // Expect another immediate operand.
4063 if (Parser.getTok().isNot(AsmToken::Comma)) {
4064 Error(Parser.getTok().getLoc(), "too few operands");
4065 return MatchOperand_ParseFail;
4067 Parser.Lex(); // Eat hash token.
4068 if (Parser.getTok().isNot(AsmToken::Hash) &&
4069 Parser.getTok().isNot(AsmToken::Dollar)) {
4070 Error(Parser.getTok().getLoc(), "'#' expected");
4071 return MatchOperand_ParseFail;
4073 Parser.Lex(); // Eat hash token.
4075 const MCExpr *WidthExpr;
4077 if (getParser().parseExpression(WidthExpr, EndLoc)) {
4078 Error(E, "malformed immediate expression");
4079 return MatchOperand_ParseFail;
4081 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4083 Error(E, "'width' operand must be an immediate");
4084 return MatchOperand_ParseFail;
4087 int64_t Width = CE->getValue();
4088 // The LSB must be in the range [1,32-lsb]
4089 if (Width < 1 || Width > 32 - LSB) {
4090 Error(E, "'width' operand must be in the range [1,32-lsb]");
4091 return MatchOperand_ParseFail;
4094 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4096 return MatchOperand_Success;
4099 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4100 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4101 // Check for a post-index addressing register operand. Specifically:
4102 // postidx_reg := '+' register {, shift}
4103 // | '-' register {, shift}
4104 // | register {, shift}
4106 // This method must return MatchOperand_NoMatch without consuming any tokens
4107 // in the case where there is no match, as other alternatives take other
4109 AsmToken Tok = Parser.getTok();
4110 SMLoc S = Tok.getLoc();
4111 bool haveEaten = false;
4113 if (Tok.is(AsmToken::Plus)) {
4114 Parser.Lex(); // Eat the '+' token.
4116 } else if (Tok.is(AsmToken::Minus)) {
4117 Parser.Lex(); // Eat the '-' token.
4122 SMLoc E = Parser.getTok().getEndLoc();
4123 int Reg = tryParseRegister();
4126 return MatchOperand_NoMatch;
4127 Error(Parser.getTok().getLoc(), "register expected");
4128 return MatchOperand_ParseFail;
4131 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4132 unsigned ShiftImm = 0;
4133 if (Parser.getTok().is(AsmToken::Comma)) {
4134 Parser.Lex(); // Eat the ','.
4135 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4136 return MatchOperand_ParseFail;
4138 // FIXME: Only approximates end...may include intervening whitespace.
4139 E = Parser.getTok().getLoc();
4142 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4145 return MatchOperand_Success;
4148 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4149 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4150 // Check for a post-index addressing register operand. Specifically:
4151 // am3offset := '+' register
4158 // This method must return MatchOperand_NoMatch without consuming any tokens
4159 // in the case where there is no match, as other alternatives take other
4161 AsmToken Tok = Parser.getTok();
4162 SMLoc S = Tok.getLoc();
4164 // Do immediates first, as we always parse those if we have a '#'.
4165 if (Parser.getTok().is(AsmToken::Hash) ||
4166 Parser.getTok().is(AsmToken::Dollar)) {
4167 Parser.Lex(); // Eat '#' or '$'.
4168 // Explicitly look for a '-', as we need to encode negative zero
4170 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4171 const MCExpr *Offset;
4173 if (getParser().parseExpression(Offset, E))
4174 return MatchOperand_ParseFail;
4175 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4177 Error(S, "constant expression expected");
4178 return MatchOperand_ParseFail;
4180 // Negative zero is encoded as the flag value INT32_MIN.
4181 int32_t Val = CE->getValue();
4182 if (isNegative && Val == 0)
4186 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4188 return MatchOperand_Success;
4192 bool haveEaten = false;
4194 if (Tok.is(AsmToken::Plus)) {
4195 Parser.Lex(); // Eat the '+' token.
4197 } else if (Tok.is(AsmToken::Minus)) {
4198 Parser.Lex(); // Eat the '-' token.
4203 Tok = Parser.getTok();
4204 int Reg = tryParseRegister();
4207 return MatchOperand_NoMatch;
4208 Error(Tok.getLoc(), "register expected");
4209 return MatchOperand_ParseFail;
4212 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4213 0, S, Tok.getEndLoc()));
4215 return MatchOperand_Success;
4218 /// Convert parsed operands to MCInst. Needed here because this instruction
4219 /// only has two register operands, but multiplication is commutative so
4220 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4222 cvtThumbMultiply(MCInst &Inst,
4223 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4224 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4225 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4226 // If we have a three-operand form, make sure to set Rn to be the operand
4227 // that isn't the same as Rd.
4229 if (Operands.size() == 6 &&
4230 ((ARMOperand*)Operands[4])->getReg() ==
4231 ((ARMOperand*)Operands[3])->getReg())
4233 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4234 Inst.addOperand(Inst.getOperand(0));
4235 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4239 cvtThumbBranches(MCInst &Inst,
4240 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4241 int CondOp = -1, ImmOp = -1;
4242 switch(Inst.getOpcode()) {
4244 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4247 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4249 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4251 // first decide whether or not the branch should be conditional
4252 // by looking at it's location relative to an IT block
4254 // inside an IT block we cannot have any conditional branches. any
4255 // such instructions needs to be converted to unconditional form
4256 switch(Inst.getOpcode()) {
4257 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4258 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4261 // outside IT blocks we can only have unconditional branches with AL
4262 // condition code or conditional branches with non-AL condition code
4263 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4264 switch(Inst.getOpcode()) {
4267 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4271 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4276 // now decide on encoding size based on branch target range
4277 switch(Inst.getOpcode()) {
4278 // classify tB as either t2B or t1B based on range of immediate operand
4280 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4281 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4282 Inst.setOpcode(ARM::t2B);
4285 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4287 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4288 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4289 Inst.setOpcode(ARM::t2Bcc);
4293 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4294 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4297 /// Parse an ARM memory expression, return false if successful else return true
4298 /// or an error. The first token must be a '[' when called.
4300 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4302 assert(Parser.getTok().is(AsmToken::LBrac) &&
4303 "Token is not a Left Bracket");
4304 S = Parser.getTok().getLoc();
4305 Parser.Lex(); // Eat left bracket token.
4307 const AsmToken &BaseRegTok = Parser.getTok();
4308 int BaseRegNum = tryParseRegister();
4309 if (BaseRegNum == -1)
4310 return Error(BaseRegTok.getLoc(), "register expected");
4312 // The next token must either be a comma, a colon or a closing bracket.
4313 const AsmToken &Tok = Parser.getTok();
4314 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4315 !Tok.is(AsmToken::RBrac))
4316 return Error(Tok.getLoc(), "malformed memory operand");
4318 if (Tok.is(AsmToken::RBrac)) {
4319 E = Tok.getEndLoc();
4320 Parser.Lex(); // Eat right bracket token.
4322 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4323 0, 0, false, S, E));
4325 // If there's a pre-indexing writeback marker, '!', just add it as a token
4326 // operand. It's rather odd, but syntactically valid.
4327 if (Parser.getTok().is(AsmToken::Exclaim)) {
4328 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4329 Parser.Lex(); // Eat the '!'.
4335 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4336 "Lost colon or comma in memory operand?!");
4337 if (Tok.is(AsmToken::Comma)) {
4338 Parser.Lex(); // Eat the comma.
4341 // If we have a ':', it's an alignment specifier.
4342 if (Parser.getTok().is(AsmToken::Colon)) {
4343 Parser.Lex(); // Eat the ':'.
4344 E = Parser.getTok().getLoc();
4347 if (getParser().parseExpression(Expr))
4350 // The expression has to be a constant. Memory references with relocations
4351 // don't come through here, as they use the <label> forms of the relevant
4353 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4355 return Error (E, "constant expression expected");
4358 switch (CE->getValue()) {
4361 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4362 case 16: Align = 2; break;
4363 case 32: Align = 4; break;
4364 case 64: Align = 8; break;
4365 case 128: Align = 16; break;
4366 case 256: Align = 32; break;
4369 // Now we should have the closing ']'
4370 if (Parser.getTok().isNot(AsmToken::RBrac))
4371 return Error(Parser.getTok().getLoc(), "']' expected");
4372 E = Parser.getTok().getEndLoc();
4373 Parser.Lex(); // Eat right bracket token.
4375 // Don't worry about range checking the value here. That's handled by
4376 // the is*() predicates.
4377 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4378 ARM_AM::no_shift, 0, Align,
4381 // If there's a pre-indexing writeback marker, '!', just add it as a token
4383 if (Parser.getTok().is(AsmToken::Exclaim)) {
4384 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4385 Parser.Lex(); // Eat the '!'.
4391 // If we have a '#', it's an immediate offset, else assume it's a register
4392 // offset. Be friendly and also accept a plain integer (without a leading
4393 // hash) for gas compatibility.
4394 if (Parser.getTok().is(AsmToken::Hash) ||
4395 Parser.getTok().is(AsmToken::Dollar) ||
4396 Parser.getTok().is(AsmToken::Integer)) {
4397 if (Parser.getTok().isNot(AsmToken::Integer))
4398 Parser.Lex(); // Eat '#' or '$'.
4399 E = Parser.getTok().getLoc();
4401 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4402 const MCExpr *Offset;
4403 if (getParser().parseExpression(Offset))
4406 // The expression has to be a constant. Memory references with relocations
4407 // don't come through here, as they use the <label> forms of the relevant
4409 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4411 return Error (E, "constant expression expected");
4413 // If the constant was #-0, represent it as INT32_MIN.
4414 int32_t Val = CE->getValue();
4415 if (isNegative && Val == 0)
4416 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4418 // Now we should have the closing ']'
4419 if (Parser.getTok().isNot(AsmToken::RBrac))
4420 return Error(Parser.getTok().getLoc(), "']' expected");
4421 E = Parser.getTok().getEndLoc();
4422 Parser.Lex(); // Eat right bracket token.
4424 // Don't worry about range checking the value here. That's handled by
4425 // the is*() predicates.
4426 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4427 ARM_AM::no_shift, 0, 0,
4430 // If there's a pre-indexing writeback marker, '!', just add it as a token
4432 if (Parser.getTok().is(AsmToken::Exclaim)) {
4433 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4434 Parser.Lex(); // Eat the '!'.
4440 // The register offset is optionally preceded by a '+' or '-'
4441 bool isNegative = false;
4442 if (Parser.getTok().is(AsmToken::Minus)) {
4444 Parser.Lex(); // Eat the '-'.
4445 } else if (Parser.getTok().is(AsmToken::Plus)) {
4447 Parser.Lex(); // Eat the '+'.
4450 E = Parser.getTok().getLoc();
4451 int OffsetRegNum = tryParseRegister();
4452 if (OffsetRegNum == -1)
4453 return Error(E, "register expected");
4455 // If there's a shift operator, handle it.
4456 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4457 unsigned ShiftImm = 0;
4458 if (Parser.getTok().is(AsmToken::Comma)) {
4459 Parser.Lex(); // Eat the ','.
4460 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4464 // Now we should have the closing ']'
4465 if (Parser.getTok().isNot(AsmToken::RBrac))
4466 return Error(Parser.getTok().getLoc(), "']' expected");
4467 E = Parser.getTok().getEndLoc();
4468 Parser.Lex(); // Eat right bracket token.
4470 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4471 ShiftType, ShiftImm, 0, isNegative,
4474 // If there's a pre-indexing writeback marker, '!', just add it as a token
4476 if (Parser.getTok().is(AsmToken::Exclaim)) {
4477 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4478 Parser.Lex(); // Eat the '!'.
4484 /// parseMemRegOffsetShift - one of these two:
4485 /// ( lsl | lsr | asr | ror ) , # shift_amount
4487 /// return true if it parses a shift otherwise it returns false.
4488 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4490 SMLoc Loc = Parser.getTok().getLoc();
4491 const AsmToken &Tok = Parser.getTok();
4492 if (Tok.isNot(AsmToken::Identifier))
4494 StringRef ShiftName = Tok.getString();
4495 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4496 ShiftName == "asl" || ShiftName == "ASL")
4498 else if (ShiftName == "lsr" || ShiftName == "LSR")
4500 else if (ShiftName == "asr" || ShiftName == "ASR")
4502 else if (ShiftName == "ror" || ShiftName == "ROR")
4504 else if (ShiftName == "rrx" || ShiftName == "RRX")
4507 return Error(Loc, "illegal shift operator");
4508 Parser.Lex(); // Eat shift type token.
4510 // rrx stands alone.
4512 if (St != ARM_AM::rrx) {
4513 Loc = Parser.getTok().getLoc();
4514 // A '#' and a shift amount.
4515 const AsmToken &HashTok = Parser.getTok();
4516 if (HashTok.isNot(AsmToken::Hash) &&
4517 HashTok.isNot(AsmToken::Dollar))
4518 return Error(HashTok.getLoc(), "'#' expected");
4519 Parser.Lex(); // Eat hash token.
4522 if (getParser().parseExpression(Expr))
4524 // Range check the immediate.
4525 // lsl, ror: 0 <= imm <= 31
4526 // lsr, asr: 0 <= imm <= 32
4527 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4529 return Error(Loc, "shift amount must be an immediate");
4530 int64_t Imm = CE->getValue();
4532 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4533 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4534 return Error(Loc, "immediate shift value out of range");
4535 // If <ShiftTy> #0, turn it into a no_shift.
4538 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4547 /// parseFPImm - A floating point immediate expression operand.
4548 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4549 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4550 // Anything that can accept a floating point constant as an operand
4551 // needs to go through here, as the regular parseExpression is
4554 // This routine still creates a generic Immediate operand, containing
4555 // a bitcast of the 64-bit floating point value. The various operands
4556 // that accept floats can check whether the value is valid for them
4557 // via the standard is*() predicates.
4559 SMLoc S = Parser.getTok().getLoc();
4561 if (Parser.getTok().isNot(AsmToken::Hash) &&
4562 Parser.getTok().isNot(AsmToken::Dollar))
4563 return MatchOperand_NoMatch;
4565 // Disambiguate the VMOV forms that can accept an FP immediate.
4566 // vmov.f32 <sreg>, #imm
4567 // vmov.f64 <dreg>, #imm
4568 // vmov.f32 <dreg>, #imm @ vector f32x2
4569 // vmov.f32 <qreg>, #imm @ vector f32x4
4571 // There are also the NEON VMOV instructions which expect an
4572 // integer constant. Make sure we don't try to parse an FPImm
4574 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4575 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4576 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4577 TyOp->getToken() != ".f64"))
4578 return MatchOperand_NoMatch;
4580 Parser.Lex(); // Eat '#' or '$'.
4582 // Handle negation, as that still comes through as a separate token.
4583 bool isNegative = false;
4584 if (Parser.getTok().is(AsmToken::Minus)) {
4588 const AsmToken &Tok = Parser.getTok();
4589 SMLoc Loc = Tok.getLoc();
4590 if (Tok.is(AsmToken::Real)) {
4591 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4592 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4593 // If we had a '-' in front, toggle the sign bit.
4594 IntVal ^= (uint64_t)isNegative << 31;
4595 Parser.Lex(); // Eat the token.
4596 Operands.push_back(ARMOperand::CreateImm(
4597 MCConstantExpr::Create(IntVal, getContext()),
4598 S, Parser.getTok().getLoc()));
4599 return MatchOperand_Success;
4601 // Also handle plain integers. Instructions which allow floating point
4602 // immediates also allow a raw encoded 8-bit value.
4603 if (Tok.is(AsmToken::Integer)) {
4604 int64_t Val = Tok.getIntVal();
4605 Parser.Lex(); // Eat the token.
4606 if (Val > 255 || Val < 0) {
4607 Error(Loc, "encoded floating point value out of range");
4608 return MatchOperand_ParseFail;
4610 double RealVal = ARM_AM::getFPImmFloat(Val);
4611 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4612 Operands.push_back(ARMOperand::CreateImm(
4613 MCConstantExpr::Create(Val, getContext()), S,
4614 Parser.getTok().getLoc()));
4615 return MatchOperand_Success;
4618 Error(Loc, "invalid floating point immediate");
4619 return MatchOperand_ParseFail;
4622 /// Parse a arm instruction operand. For now this parses the operand regardless
4623 /// of the mnemonic.
4624 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4625 StringRef Mnemonic) {
4628 // Check if the current operand has a custom associated parser, if so, try to
4629 // custom parse the operand, or fallback to the general approach.
4630 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4631 if (ResTy == MatchOperand_Success)
4633 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4634 // there was a match, but an error occurred, in which case, just return that
4635 // the operand parsing failed.
4636 if (ResTy == MatchOperand_ParseFail)
4639 switch (getLexer().getKind()) {
4641 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4643 case AsmToken::Identifier: {
4644 // If we've seen a branch mnemonic, the next operand must be a label. This
4645 // is true even if the label is a register name. So "br r1" means branch to
4647 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4649 if (!tryParseRegisterWithWriteBack(Operands))
4651 int Res = tryParseShiftRegister(Operands);
4652 if (Res == 0) // success
4654 else if (Res == -1) // irrecoverable error
4656 // If this is VMRS, check for the apsr_nzcv operand.
4657 if (Mnemonic == "vmrs" &&
4658 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4659 S = Parser.getTok().getLoc();
4661 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4666 // Fall though for the Identifier case that is not a register or a
4669 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4670 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4671 case AsmToken::String: // quoted label names.
4672 case AsmToken::Dot: { // . as a branch target
4673 // This was not a register so parse other operands that start with an
4674 // identifier (like labels) as expressions and create them as immediates.
4675 const MCExpr *IdVal;
4676 S = Parser.getTok().getLoc();
4677 if (getParser().parseExpression(IdVal))
4679 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4680 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4683 case AsmToken::LBrac:
4684 return parseMemory(Operands);
4685 case AsmToken::LCurly:
4686 return parseRegisterList(Operands);
4687 case AsmToken::Dollar:
4688 case AsmToken::Hash: {
4689 // #42 -> immediate.
4690 S = Parser.getTok().getLoc();
4693 if (Parser.getTok().isNot(AsmToken::Colon)) {
4694 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4695 const MCExpr *ImmVal;
4696 if (getParser().parseExpression(ImmVal))
4698 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4700 int32_t Val = CE->getValue();
4701 if (isNegative && Val == 0)
4702 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4704 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4705 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4707 // There can be a trailing '!' on operands that we want as a separate
4708 // '!' Token operand. Handle that here. For example, the compatibility
4709 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4710 if (Parser.getTok().is(AsmToken::Exclaim)) {
4711 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4712 Parser.getTok().getLoc()));
4713 Parser.Lex(); // Eat exclaim token
4717 // w/ a ':' after the '#', it's just like a plain ':'.
4720 case AsmToken::Colon: {
4721 // ":lower16:" and ":upper16:" expression prefixes
4722 // FIXME: Check it's an expression prefix,
4723 // e.g. (FOO - :lower16:BAR) isn't legal.
4724 ARMMCExpr::VariantKind RefKind;
4725 if (parsePrefix(RefKind))
4728 const MCExpr *SubExprVal;
4729 if (getParser().parseExpression(SubExprVal))
4732 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4734 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4735 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4738 case AsmToken::Equal: {
4739 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4740 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4742 const MCSection *Section =
4743 getParser().getStreamer().getCurrentSection().first;
4745 Parser.Lex(); // Eat '='
4746 const MCExpr *SubExprVal;
4747 if (getParser().parseExpression(SubExprVal))
4749 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4751 const MCExpr *CPLoc =
4752 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4753 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4759 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4760 // :lower16: and :upper16:.
4761 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4762 RefKind = ARMMCExpr::VK_ARM_None;
4764 // :lower16: and :upper16: modifiers
4765 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4766 Parser.Lex(); // Eat ':'
4768 if (getLexer().isNot(AsmToken::Identifier)) {
4769 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4773 StringRef IDVal = Parser.getTok().getIdentifier();
4774 if (IDVal == "lower16") {
4775 RefKind = ARMMCExpr::VK_ARM_LO16;
4776 } else if (IDVal == "upper16") {
4777 RefKind = ARMMCExpr::VK_ARM_HI16;
4779 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4784 if (getLexer().isNot(AsmToken::Colon)) {
4785 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4788 Parser.Lex(); // Eat the last ':'
4792 /// \brief Given a mnemonic, split out possible predication code and carry
4793 /// setting letters to form a canonical mnemonic and flags.
4795 // FIXME: Would be nice to autogen this.
4796 // FIXME: This is a bit of a maze of special cases.
4797 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4798 unsigned &PredicationCode,
4800 unsigned &ProcessorIMod,
4801 StringRef &ITMask) {
4802 PredicationCode = ARMCC::AL;
4803 CarrySetting = false;
4806 // Ignore some mnemonics we know aren't predicated forms.
4808 // FIXME: Would be nice to autogen this.
4809 if ((Mnemonic == "movs" && isThumb()) ||
4810 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4811 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4812 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4813 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4814 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4815 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4816 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4817 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4818 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4819 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4820 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4821 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4824 // First, split out any predication code. Ignore mnemonics we know aren't
4825 // predicated but do have a carry-set and so weren't caught above.
4826 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4827 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4828 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4829 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4830 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4831 .Case("eq", ARMCC::EQ)
4832 .Case("ne", ARMCC::NE)
4833 .Case("hs", ARMCC::HS)
4834 .Case("cs", ARMCC::HS)
4835 .Case("lo", ARMCC::LO)
4836 .Case("cc", ARMCC::LO)
4837 .Case("mi", ARMCC::MI)
4838 .Case("pl", ARMCC::PL)
4839 .Case("vs", ARMCC::VS)
4840 .Case("vc", ARMCC::VC)
4841 .Case("hi", ARMCC::HI)
4842 .Case("ls", ARMCC::LS)
4843 .Case("ge", ARMCC::GE)
4844 .Case("lt", ARMCC::LT)
4845 .Case("gt", ARMCC::GT)
4846 .Case("le", ARMCC::LE)
4847 .Case("al", ARMCC::AL)
4850 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4851 PredicationCode = CC;
4855 // Next, determine if we have a carry setting bit. We explicitly ignore all
4856 // the instructions we know end in 's'.
4857 if (Mnemonic.endswith("s") &&
4858 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4859 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4860 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4861 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4862 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4863 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4864 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4865 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4866 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4867 (Mnemonic == "movs" && isThumb()))) {
4868 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4869 CarrySetting = true;
4872 // The "cps" instruction can have a interrupt mode operand which is glued into
4873 // the mnemonic. Check if this is the case, split it and parse the imod op
4874 if (Mnemonic.startswith("cps")) {
4875 // Split out any imod code.
4877 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4878 .Case("ie", ARM_PROC::IE)
4879 .Case("id", ARM_PROC::ID)
4882 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4883 ProcessorIMod = IMod;
4887 // The "it" instruction has the condition mask on the end of the mnemonic.
4888 if (Mnemonic.startswith("it")) {
4889 ITMask = Mnemonic.slice(2, Mnemonic.size());
4890 Mnemonic = Mnemonic.slice(0, 2);
4896 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4897 /// inclusion of carry set or predication code operands.
4899 // FIXME: It would be nice to autogen this.
4901 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4902 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4903 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4904 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4905 Mnemonic == "add" || Mnemonic == "adc" ||
4906 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4907 Mnemonic == "orr" || Mnemonic == "mvn" ||
4908 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4909 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4910 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4911 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4912 Mnemonic == "mla" || Mnemonic == "smlal" ||
4913 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4914 CanAcceptCarrySet = true;
4916 CanAcceptCarrySet = false;
4918 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4919 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4920 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4921 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4922 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4923 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4924 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4925 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4926 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4927 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4928 // These mnemonics are never predicable
4929 CanAcceptPredicationCode = false;
4930 } else if (!isThumb()) {
4931 // Some instructions are only predicable in Thumb mode
4932 CanAcceptPredicationCode
4933 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4934 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4935 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4936 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4937 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4938 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4939 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4940 } else if (isThumbOne()) {
4942 CanAcceptPredicationCode = Mnemonic != "movs";
4944 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4946 CanAcceptPredicationCode = true;
4949 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4950 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4951 // FIXME: This is all horribly hacky. We really need a better way to deal
4952 // with optional operands like this in the matcher table.
4954 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4955 // another does not. Specifically, the MOVW instruction does not. So we
4956 // special case it here and remove the defaulted (non-setting) cc_out
4957 // operand if that's the instruction we're trying to match.
4959 // We do this as post-processing of the explicit operands rather than just
4960 // conditionally adding the cc_out in the first place because we need
4961 // to check the type of the parsed immediate operand.
4962 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
4963 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4964 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4965 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4968 // Register-register 'add' for thumb does not have a cc_out operand
4969 // when there are only two register operands.
4970 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4971 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4972 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4973 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4975 // Register-register 'add' for thumb does not have a cc_out operand
4976 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4977 // have to check the immediate range here since Thumb2 has a variant
4978 // that can handle a different range and has a cc_out operand.
4979 if (((isThumb() && Mnemonic == "add") ||
4980 (isThumbTwo() && Mnemonic == "sub")) &&
4981 Operands.size() == 6 &&
4982 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4983 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4984 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
4985 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4986 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
4987 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
4989 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4990 // imm0_4095 variant. That's the least-preferred variant when
4991 // selecting via the generic "add" mnemonic, so to know that we
4992 // should remove the cc_out operand, we have to explicitly check that
4993 // it's not one of the other variants. Ugh.
4994 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4995 Operands.size() == 6 &&
4996 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4997 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4998 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4999 // Nest conditions rather than one big 'if' statement for readability.
5001 // If both registers are low, we're in an IT block, and the immediate is
5002 // in range, we should use encoding T1 instead, which has a cc_out.
5004 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5005 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5006 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5008 // Check against T3. If the second register is the PC, this is an
5009 // alternate form of ADR, which uses encoding T4, so check for that too.
5010 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5011 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5014 // Otherwise, we use encoding T4, which does not have a cc_out
5019 // The thumb2 multiply instruction doesn't have a CCOut register, so
5020 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5021 // use the 16-bit encoding or not.
5022 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5023 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5024 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5025 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5026 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5027 // If the registers aren't low regs, the destination reg isn't the
5028 // same as one of the source regs, or the cc_out operand is zero
5029 // outside of an IT block, we have to use the 32-bit encoding, so
5030 // remove the cc_out operand.
5031 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5032 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5033 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5035 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5036 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5037 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5038 static_cast<ARMOperand*>(Operands[4])->getReg())))
5041 // Also check the 'mul' syntax variant that doesn't specify an explicit
5042 // destination register.
5043 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5044 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5045 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5046 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5047 // If the registers aren't low regs or the cc_out operand is zero
5048 // outside of an IT block, we have to use the 32-bit encoding, so
5049 // remove the cc_out operand.
5050 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5051 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5057 // Register-register 'add/sub' for thumb does not have a cc_out operand
5058 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5059 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5060 // right, this will result in better diagnostics (which operand is off)
5062 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5063 (Operands.size() == 5 || Operands.size() == 6) &&
5064 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5065 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5066 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5067 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5068 (Operands.size() == 6 &&
5069 static_cast<ARMOperand*>(Operands[5])->isImm())))
5075 bool ARMAsmParser::shouldOmitPredicateOperand(
5076 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5077 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5078 unsigned RegIdx = 3;
5079 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5080 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5081 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5082 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5085 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5086 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5087 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5088 ARMMCRegisterClasses[ARM::QPRRegClassID]
5089 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5095 static bool isDataTypeToken(StringRef Tok) {
5096 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5097 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5098 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5099 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5100 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5101 Tok == ".f" || Tok == ".d";
5104 // FIXME: This bit should probably be handled via an explicit match class
5105 // in the .td files that matches the suffix instead of having it be
5106 // a literal string token the way it is now.
5107 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5108 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5110 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5111 unsigned VariantID);
5113 static bool RequiresVFPRegListValidation(StringRef Inst,
5114 bool &AcceptSinglePrecisionOnly,
5115 bool &AcceptDoublePrecisionOnly) {
5116 if (Inst.size() < 7)
5119 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5120 StringRef AddressingMode = Inst.substr(4, 2);
5121 if (AddressingMode == "ia" || AddressingMode == "db" ||
5122 AddressingMode == "ea" || AddressingMode == "fd") {
5123 AcceptSinglePrecisionOnly = Inst[6] == 's';
5124 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5132 /// Parse an arm instruction mnemonic followed by its operands.
5133 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5135 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5136 // FIXME: Can this be done via tablegen in some fashion?
5137 bool RequireVFPRegisterListCheck;
5138 bool AcceptSinglePrecisionOnly;
5139 bool AcceptDoublePrecisionOnly;
5140 RequireVFPRegisterListCheck =
5141 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5142 AcceptDoublePrecisionOnly);
5144 // Apply mnemonic aliases before doing anything else, as the destination
5145 // mnemonic may include suffices and we want to handle them normally.
5146 // The generic tblgen'erated code does this later, at the start of
5147 // MatchInstructionImpl(), but that's too late for aliases that include
5148 // any sort of suffix.
5149 unsigned AvailableFeatures = getAvailableFeatures();
5150 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5151 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5153 // First check for the ARM-specific .req directive.
5154 if (Parser.getTok().is(AsmToken::Identifier) &&
5155 Parser.getTok().getIdentifier() == ".req") {
5156 parseDirectiveReq(Name, NameLoc);
5157 // We always return 'error' for this, as we're done with this
5158 // statement and don't need to match the 'instruction."
5162 // Create the leading tokens for the mnemonic, split by '.' characters.
5163 size_t Start = 0, Next = Name.find('.');
5164 StringRef Mnemonic = Name.slice(Start, Next);
5166 // Split out the predication code and carry setting flag from the mnemonic.
5167 unsigned PredicationCode;
5168 unsigned ProcessorIMod;
5171 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5172 ProcessorIMod, ITMask);
5174 // In Thumb1, only the branch (B) instruction can be predicated.
5175 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5176 Parser.eatToEndOfStatement();
5177 return Error(NameLoc, "conditional execution not supported in Thumb1");
5180 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5182 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5183 // is the mask as it will be for the IT encoding if the conditional
5184 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5185 // where the conditional bit0 is zero, the instruction post-processing
5186 // will adjust the mask accordingly.
5187 if (Mnemonic == "it") {
5188 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5189 if (ITMask.size() > 3) {
5190 Parser.eatToEndOfStatement();
5191 return Error(Loc, "too many conditions on IT instruction");
5194 for (unsigned i = ITMask.size(); i != 0; --i) {
5195 char pos = ITMask[i - 1];
5196 if (pos != 't' && pos != 'e') {
5197 Parser.eatToEndOfStatement();
5198 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5201 if (ITMask[i - 1] == 't')
5204 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5207 // FIXME: This is all a pretty gross hack. We should automatically handle
5208 // optional operands like this via tblgen.
5210 // Next, add the CCOut and ConditionCode operands, if needed.
5212 // For mnemonics which can ever incorporate a carry setting bit or predication
5213 // code, our matching model involves us always generating CCOut and
5214 // ConditionCode operands to match the mnemonic "as written" and then we let
5215 // the matcher deal with finding the right instruction or generating an
5216 // appropriate error.
5217 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5218 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5220 // If we had a carry-set on an instruction that can't do that, issue an
5222 if (!CanAcceptCarrySet && CarrySetting) {
5223 Parser.eatToEndOfStatement();
5224 return Error(NameLoc, "instruction '" + Mnemonic +
5225 "' can not set flags, but 's' suffix specified");
5227 // If we had a predication code on an instruction that can't do that, issue an
5229 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5230 Parser.eatToEndOfStatement();
5231 return Error(NameLoc, "instruction '" + Mnemonic +
5232 "' is not predicable, but condition code specified");
5235 // Add the carry setting operand, if necessary.
5236 if (CanAcceptCarrySet) {
5237 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5238 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5242 // Add the predication code operand, if necessary.
5243 if (CanAcceptPredicationCode) {
5244 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5246 Operands.push_back(ARMOperand::CreateCondCode(
5247 ARMCC::CondCodes(PredicationCode), Loc));
5250 // Add the processor imod operand, if necessary.
5251 if (ProcessorIMod) {
5252 Operands.push_back(ARMOperand::CreateImm(
5253 MCConstantExpr::Create(ProcessorIMod, getContext()),
5257 // Add the remaining tokens in the mnemonic.
5258 while (Next != StringRef::npos) {
5260 Next = Name.find('.', Start + 1);
5261 StringRef ExtraToken = Name.slice(Start, Next);
5263 // Some NEON instructions have an optional datatype suffix that is
5264 // completely ignored. Check for that.
5265 if (isDataTypeToken(ExtraToken) &&
5266 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5269 // For for ARM mode generate an error if the .n qualifier is used.
5270 if (ExtraToken == ".n" && !isThumb()) {
5271 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5272 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5276 // The .n qualifier is always discarded as that is what the tables
5277 // and matcher expect. In ARM mode the .w qualifier has no effect,
5278 // so discard it to avoid errors that can be caused by the matcher.
5279 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5280 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5281 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5285 // Read the remaining operands.
5286 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5287 // Read the first operand.
5288 if (parseOperand(Operands, Mnemonic)) {
5289 Parser.eatToEndOfStatement();
5293 while (getLexer().is(AsmToken::Comma)) {
5294 Parser.Lex(); // Eat the comma.
5296 // Parse and remember the operand.
5297 if (parseOperand(Operands, Mnemonic)) {
5298 Parser.eatToEndOfStatement();
5304 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5305 SMLoc Loc = getLexer().getLoc();
5306 Parser.eatToEndOfStatement();
5307 return Error(Loc, "unexpected token in argument list");
5310 Parser.Lex(); // Consume the EndOfStatement
5312 if (RequireVFPRegisterListCheck) {
5313 ARMOperand *Op = static_cast<ARMOperand*>(Operands.back());
5314 if (AcceptSinglePrecisionOnly && !Op->isSPRRegList())
5315 return Error(Op->getStartLoc(),
5316 "VFP/Neon single precision register expected");
5317 if (AcceptDoublePrecisionOnly && !Op->isDPRRegList())
5318 return Error(Op->getStartLoc(),
5319 "VFP/Neon double precision register expected");
5322 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5323 // do and don't have a cc_out optional-def operand. With some spot-checks
5324 // of the operand list, we can figure out which variant we're trying to
5325 // parse and adjust accordingly before actually matching. We shouldn't ever
5326 // try to remove a cc_out operand that was explicitly set on the the
5327 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5328 // table driven matcher doesn't fit well with the ARM instruction set.
5329 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5330 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5331 Operands.erase(Operands.begin() + 1);
5335 // Some instructions have the same mnemonic, but don't always
5336 // have a predicate. Distinguish them here and delete the
5337 // predicate if needed.
5338 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5339 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5340 Operands.erase(Operands.begin() + 1);
5344 // ARM mode 'blx' need special handling, as the register operand version
5345 // is predicable, but the label operand version is not. So, we can't rely
5346 // on the Mnemonic based checking to correctly figure out when to put
5347 // a k_CondCode operand in the list. If we're trying to match the label
5348 // version, remove the k_CondCode operand here.
5349 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5350 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5351 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5352 Operands.erase(Operands.begin() + 1);
5356 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5357 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5358 // a single GPRPair reg operand is used in the .td file to replace the two
5359 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5360 // expressed as a GPRPair, so we have to manually merge them.
5361 // FIXME: We would really like to be able to tablegen'erate this.
5362 if (!isThumb() && Operands.size() > 4 &&
5363 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5364 Mnemonic == "stlexd")) {
5365 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5366 unsigned Idx = isLoad ? 2 : 3;
5367 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5368 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5370 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5371 // Adjust only if Op1 and Op2 are GPRs.
5372 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5373 MRC.contains(Op2->getReg())) {
5374 unsigned Reg1 = Op1->getReg();
5375 unsigned Reg2 = Op2->getReg();
5376 unsigned Rt = MRI->getEncodingValue(Reg1);
5377 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5379 // Rt2 must be Rt + 1 and Rt must be even.
5380 if (Rt + 1 != Rt2 || (Rt & 1)) {
5381 Error(Op2->getStartLoc(), isLoad ?
5382 "destination operands must be sequential" :
5383 "source operands must be sequential");
5386 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5387 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5388 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5389 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5390 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5396 // FIXME: As said above, this is all a pretty gross hack. This instruction
5397 // does not fit with other "subs" and tblgen.
5398 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5399 // so the Mnemonic is the original name "subs" and delete the predicate
5400 // operand so it will match the table entry.
5401 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5402 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5403 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5404 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5405 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5406 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5407 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5408 Operands.erase(Operands.begin());
5410 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5412 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5413 Operands.erase(Operands.begin() + 1);
5419 // Validate context-sensitive operand constraints.
5421 // return 'true' if register list contains non-low GPR registers,
5422 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5423 // 'containsReg' to true.
5424 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5425 unsigned HiReg, bool &containsReg) {
5426 containsReg = false;
5427 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5428 unsigned OpReg = Inst.getOperand(i).getReg();
5431 // Anything other than a low register isn't legal here.
5432 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5438 // Check if the specified regisgter is in the register list of the inst,
5439 // starting at the indicated operand number.
5440 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5441 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5442 unsigned OpReg = Inst.getOperand(i).getReg();
5449 // Return true if instruction has the interesting property of being
5450 // allowed in IT blocks, but not being predicable.
5451 static bool instIsBreakpoint(const MCInst &Inst) {
5452 return Inst.getOpcode() == ARM::tBKPT ||
5453 Inst.getOpcode() == ARM::BKPT ||
5454 Inst.getOpcode() == ARM::tHLT ||
5455 Inst.getOpcode() == ARM::HLT;
5459 // FIXME: We would really like to be able to tablegen'erate this.
5461 validateInstruction(MCInst &Inst,
5462 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5463 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5464 SMLoc Loc = Operands[0]->getStartLoc();
5466 // Check the IT block state first.
5467 // NOTE: BKPT and HLT instructions have the interesting property of being
5468 // allowed in IT blocks, but not being predicable. They just always execute.
5469 if (inITBlock() && !instIsBreakpoint(Inst)) {
5471 if (ITState.FirstCond)
5472 ITState.FirstCond = false;
5474 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5475 // The instruction must be predicable.
5476 if (!MCID.isPredicable())
5477 return Error(Loc, "instructions in IT block must be predicable");
5478 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5479 unsigned ITCond = Bit ? ITState.Cond :
5480 ARMCC::getOppositeCondition(ITState.Cond);
5481 if (Cond != ITCond) {
5482 // Find the condition code Operand to get its SMLoc information.
5484 for (unsigned I = 1; I < Operands.size(); ++I)
5485 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5486 CondLoc = Operands[I]->getStartLoc();
5487 return Error(CondLoc, "incorrect condition in IT block; got '" +
5488 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5489 "', but expected '" +
5490 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5492 // Check for non-'al' condition codes outside of the IT block.
5493 } else if (isThumbTwo() && MCID.isPredicable() &&
5494 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5495 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5496 Inst.getOpcode() != ARM::t2Bcc)
5497 return Error(Loc, "predicated instructions must be in IT block");
5499 const unsigned Opcode = Inst.getOpcode();
5503 case ARM::LDRD_POST: {
5504 const unsigned RtReg = Inst.getOperand(0).getReg();
5507 if (RtReg == ARM::LR)
5508 return Error(Operands[3]->getStartLoc(),
5511 const unsigned Rt = MRI->getEncodingValue(RtReg);
5512 // Rt must be even-numbered.
5514 return Error(Operands[3]->getStartLoc(),
5515 "Rt must be even-numbered");
5517 // Rt2 must be Rt + 1.
5518 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5520 return Error(Operands[3]->getStartLoc(),
5521 "destination operands must be sequential");
5523 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5524 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5525 // For addressing modes with writeback, the base register needs to be
5526 // different from the destination registers.
5527 if (Rn == Rt || Rn == Rt2)
5528 return Error(Operands[3]->getStartLoc(),
5529 "base register needs to be different from destination "
5536 case ARM::t2LDRD_PRE:
5537 case ARM::t2LDRD_POST: {
5538 // Rt2 must be different from Rt.
5539 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5540 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5542 return Error(Operands[3]->getStartLoc(),
5543 "destination operands can't be identical");
5547 // Rt2 must be Rt + 1.
5548 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5549 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5551 return Error(Operands[3]->getStartLoc(),
5552 "source operands must be sequential");
5556 case ARM::STRD_POST: {
5557 // Rt2 must be Rt + 1.
5558 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5559 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5561 return Error(Operands[3]->getStartLoc(),
5562 "source operands must be sequential");
5567 // Width must be in range [1, 32-lsb].
5568 unsigned LSB = Inst.getOperand(2).getImm();
5569 unsigned Widthm1 = Inst.getOperand(3).getImm();
5570 if (Widthm1 >= 32 - LSB)
5571 return Error(Operands[5]->getStartLoc(),
5572 "bitfield width must be in range [1,32-lsb]");
5575 // Notionally handles ARM::tLDMIA_UPD too.
5577 // If we're parsing Thumb2, the .w variant is available and handles
5578 // most cases that are normally illegal for a Thumb1 LDM instruction.
5579 // We'll make the transformation in processInstruction() if necessary.
5581 // Thumb LDM instructions are writeback iff the base register is not
5582 // in the register list.
5583 unsigned Rn = Inst.getOperand(0).getReg();
5584 bool HasWritebackToken =
5585 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5586 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5587 bool ListContainsBase;
5588 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5589 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5590 "registers must be in range r0-r7");
5591 // If we should have writeback, then there should be a '!' token.
5592 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5593 return Error(Operands[2]->getStartLoc(),
5594 "writeback operator '!' expected");
5595 // If we should not have writeback, there must not be a '!'. This is
5596 // true even for the 32-bit wide encodings.
5597 if (ListContainsBase && HasWritebackToken)
5598 return Error(Operands[3]->getStartLoc(),
5599 "writeback operator '!' not allowed when base register "
5600 "in register list");
5604 case ARM::LDMIA_UPD:
5605 case ARM::LDMDB_UPD:
5606 case ARM::LDMIB_UPD:
5607 case ARM::LDMDA_UPD:
5608 // ARM variants loading and updating the same register are only officially
5609 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5613 case ARM::t2LDMIA_UPD:
5614 case ARM::t2LDMDB_UPD:
5615 case ARM::t2STMIA_UPD:
5616 case ARM::t2STMDB_UPD: {
5617 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5618 return Error(Operands.back()->getStartLoc(),
5619 "writeback register not allowed in register list");
5622 case ARM::sysLDMIA_UPD:
5623 case ARM::sysLDMDA_UPD:
5624 case ARM::sysLDMDB_UPD:
5625 case ARM::sysLDMIB_UPD:
5626 if (!listContainsReg(Inst, 3, ARM::PC))
5627 return Error(Operands[4]->getStartLoc(),
5628 "writeback register only allowed on system LDM "
5629 "if PC in register-list");
5631 case ARM::sysSTMIA_UPD:
5632 case ARM::sysSTMDA_UPD:
5633 case ARM::sysSTMDB_UPD:
5634 case ARM::sysSTMIB_UPD:
5635 return Error(Operands[2]->getStartLoc(),
5636 "system STM cannot have writeback register");
5639 // The second source operand must be the same register as the destination
5642 // In this case, we must directly check the parsed operands because the
5643 // cvtThumbMultiply() function is written in such a way that it guarantees
5644 // this first statement is always true for the new Inst. Essentially, the
5645 // destination is unconditionally copied into the second source operand
5646 // without checking to see if it matches what we actually parsed.
5647 if (Operands.size() == 6 &&
5648 (((ARMOperand*)Operands[3])->getReg() !=
5649 ((ARMOperand*)Operands[5])->getReg()) &&
5650 (((ARMOperand*)Operands[3])->getReg() !=
5651 ((ARMOperand*)Operands[4])->getReg())) {
5652 return Error(Operands[3]->getStartLoc(),
5653 "destination register must match source register");
5657 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5658 // so only issue a diagnostic for thumb1. The instructions will be
5659 // switched to the t2 encodings in processInstruction() if necessary.
5661 bool ListContainsBase;
5662 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5664 return Error(Operands[2]->getStartLoc(),
5665 "registers must be in range r0-r7 or pc");
5669 bool ListContainsBase;
5670 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5672 return Error(Operands[2]->getStartLoc(),
5673 "registers must be in range r0-r7 or lr");
5676 case ARM::tSTMIA_UPD: {
5677 bool ListContainsBase, InvalidLowList;
5678 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5679 0, ListContainsBase);
5680 if (InvalidLowList && !isThumbTwo())
5681 return Error(Operands[4]->getStartLoc(),
5682 "registers must be in range r0-r7");
5684 // This would be converted to a 32-bit stm, but that's not valid if the
5685 // writeback register is in the list.
5686 if (InvalidLowList && ListContainsBase)
5687 return Error(Operands[4]->getStartLoc(),
5688 "writeback operator '!' not allowed when base register "
5689 "in register list");
5692 case ARM::tADDrSP: {
5693 // If the non-SP source operand and the destination operand are not the
5694 // same, we need thumb2 (for the wide encoding), or we have an error.
5695 if (!isThumbTwo() &&
5696 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5697 return Error(Operands[4]->getStartLoc(),
5698 "source register must be the same as destination");
5702 // Final range checking for Thumb unconditional branch instructions.
5704 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5705 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5708 int op = (Operands[2]->isImm()) ? 2 : 3;
5709 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5710 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5713 // Final range checking for Thumb conditional branch instructions.
5715 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5716 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5719 int Op = (Operands[2]->isImm()) ? 2 : 3;
5720 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5721 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5729 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5731 default: llvm_unreachable("unexpected opcode!");
5733 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5734 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5735 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5736 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5737 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5738 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5739 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5740 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5741 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5744 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5745 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5746 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5747 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5748 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5750 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5751 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5752 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5753 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5754 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5756 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5757 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5758 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5759 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5760 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5763 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5764 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5765 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5766 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5767 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5768 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5769 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5770 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5771 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5772 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5773 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5774 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5775 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5776 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5777 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5780 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5781 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5782 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5783 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5784 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5785 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5786 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5787 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5788 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5789 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5790 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5791 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5792 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5793 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5794 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5795 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5796 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5797 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5800 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5801 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5802 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5803 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5804 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5805 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5806 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5807 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5808 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5809 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5810 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5811 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5812 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5813 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5814 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5817 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5818 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5819 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5820 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5821 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5822 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5823 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5824 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5825 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5826 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5827 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5828 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5829 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5830 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5831 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5832 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5833 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5834 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5838 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5840 default: llvm_unreachable("unexpected opcode!");
5842 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5843 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5844 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5845 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5846 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5847 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5848 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5849 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5850 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5853 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5854 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5855 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5856 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5857 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5858 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5859 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5860 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5861 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5862 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5863 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5864 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5865 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5866 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5867 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5870 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5871 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5872 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5873 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5874 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5875 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5876 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5877 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5878 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5879 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5880 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5881 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5882 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5883 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5884 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5885 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5886 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5887 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5890 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5891 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5892 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5893 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5894 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5895 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5896 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5897 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5898 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5899 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5900 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5901 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5902 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5903 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5904 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5907 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5908 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5909 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5910 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5911 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5912 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5913 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5914 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5915 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5916 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5917 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5918 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5919 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5920 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5921 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5922 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5923 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5924 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5927 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5928 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5929 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5930 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5931 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5932 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5933 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5934 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5935 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5936 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5937 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5938 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5939 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5940 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5941 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5944 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5945 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5946 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5947 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5948 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5949 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5950 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5951 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5952 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5953 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5954 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5955 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5956 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5957 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5958 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5959 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5960 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5961 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5964 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5965 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5966 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5967 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5968 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5969 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5970 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5971 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5972 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5973 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5974 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5975 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5976 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5977 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5978 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5979 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5980 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5981 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
5986 processInstruction(MCInst &Inst,
5987 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5988 switch (Inst.getOpcode()) {
5989 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5991 if (Inst.getOperand(1).getReg() != ARM::PC ||
5992 Inst.getOperand(5).getReg() != 0)
5995 TmpInst.setOpcode(ARM::ADR);
5996 TmpInst.addOperand(Inst.getOperand(0));
5997 TmpInst.addOperand(Inst.getOperand(2));
5998 TmpInst.addOperand(Inst.getOperand(3));
5999 TmpInst.addOperand(Inst.getOperand(4));
6003 // Aliases for alternate PC+imm syntax of LDR instructions.
6004 case ARM::t2LDRpcrel:
6005 // Select the narrow version if the immediate will fit.
6006 if (Inst.getOperand(1).getImm() > 0 &&
6007 Inst.getOperand(1).getImm() <= 0xff &&
6008 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
6009 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
6010 Inst.setOpcode(ARM::tLDRpci);
6012 Inst.setOpcode(ARM::t2LDRpci);
6014 case ARM::t2LDRBpcrel:
6015 Inst.setOpcode(ARM::t2LDRBpci);
6017 case ARM::t2LDRHpcrel:
6018 Inst.setOpcode(ARM::t2LDRHpci);
6020 case ARM::t2LDRSBpcrel:
6021 Inst.setOpcode(ARM::t2LDRSBpci);
6023 case ARM::t2LDRSHpcrel:
6024 Inst.setOpcode(ARM::t2LDRSHpci);
6026 // Handle NEON VST complex aliases.
6027 case ARM::VST1LNdWB_register_Asm_8:
6028 case ARM::VST1LNdWB_register_Asm_16:
6029 case ARM::VST1LNdWB_register_Asm_32: {
6031 // Shuffle the operands around so the lane index operand is in the
6034 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6035 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6036 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6037 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6038 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6039 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6040 TmpInst.addOperand(Inst.getOperand(1)); // lane
6041 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6042 TmpInst.addOperand(Inst.getOperand(6));
6047 case ARM::VST2LNdWB_register_Asm_8:
6048 case ARM::VST2LNdWB_register_Asm_16:
6049 case ARM::VST2LNdWB_register_Asm_32:
6050 case ARM::VST2LNqWB_register_Asm_16:
6051 case ARM::VST2LNqWB_register_Asm_32: {
6053 // Shuffle the operands around so the lane index operand is in the
6056 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6057 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6058 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6059 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6060 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6061 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6062 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6064 TmpInst.addOperand(Inst.getOperand(1)); // lane
6065 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6066 TmpInst.addOperand(Inst.getOperand(6));
6071 case ARM::VST3LNdWB_register_Asm_8:
6072 case ARM::VST3LNdWB_register_Asm_16:
6073 case ARM::VST3LNdWB_register_Asm_32:
6074 case ARM::VST3LNqWB_register_Asm_16:
6075 case ARM::VST3LNqWB_register_Asm_32: {
6077 // Shuffle the operands around so the lane index operand is in the
6080 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6081 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6082 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6083 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6084 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6085 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6086 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6088 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6090 TmpInst.addOperand(Inst.getOperand(1)); // lane
6091 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6092 TmpInst.addOperand(Inst.getOperand(6));
6097 case ARM::VST4LNdWB_register_Asm_8:
6098 case ARM::VST4LNdWB_register_Asm_16:
6099 case ARM::VST4LNdWB_register_Asm_32:
6100 case ARM::VST4LNqWB_register_Asm_16:
6101 case ARM::VST4LNqWB_register_Asm_32: {
6103 // Shuffle the operands around so the lane index operand is in the
6106 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6107 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6108 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6109 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6110 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6111 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6112 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6114 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6116 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6118 TmpInst.addOperand(Inst.getOperand(1)); // lane
6119 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6120 TmpInst.addOperand(Inst.getOperand(6));
6125 case ARM::VST1LNdWB_fixed_Asm_8:
6126 case ARM::VST1LNdWB_fixed_Asm_16:
6127 case ARM::VST1LNdWB_fixed_Asm_32: {
6129 // Shuffle the operands around so the lane index operand is in the
6132 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6133 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6134 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6135 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6136 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6137 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6138 TmpInst.addOperand(Inst.getOperand(1)); // lane
6139 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6140 TmpInst.addOperand(Inst.getOperand(5));
6145 case ARM::VST2LNdWB_fixed_Asm_8:
6146 case ARM::VST2LNdWB_fixed_Asm_16:
6147 case ARM::VST2LNdWB_fixed_Asm_32:
6148 case ARM::VST2LNqWB_fixed_Asm_16:
6149 case ARM::VST2LNqWB_fixed_Asm_32: {
6151 // Shuffle the operands around so the lane index operand is in the
6154 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6155 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6156 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6157 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6158 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6159 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6160 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6162 TmpInst.addOperand(Inst.getOperand(1)); // lane
6163 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6164 TmpInst.addOperand(Inst.getOperand(5));
6169 case ARM::VST3LNdWB_fixed_Asm_8:
6170 case ARM::VST3LNdWB_fixed_Asm_16:
6171 case ARM::VST3LNdWB_fixed_Asm_32:
6172 case ARM::VST3LNqWB_fixed_Asm_16:
6173 case ARM::VST3LNqWB_fixed_Asm_32: {
6175 // Shuffle the operands around so the lane index operand is in the
6178 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6179 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6180 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6181 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6182 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6183 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6188 TmpInst.addOperand(Inst.getOperand(1)); // lane
6189 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6190 TmpInst.addOperand(Inst.getOperand(5));
6195 case ARM::VST4LNdWB_fixed_Asm_8:
6196 case ARM::VST4LNdWB_fixed_Asm_16:
6197 case ARM::VST4LNdWB_fixed_Asm_32:
6198 case ARM::VST4LNqWB_fixed_Asm_16:
6199 case ARM::VST4LNqWB_fixed_Asm_32: {
6201 // Shuffle the operands around so the lane index operand is in the
6204 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6205 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6206 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6207 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6208 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6209 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6210 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6212 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6214 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6216 TmpInst.addOperand(Inst.getOperand(1)); // lane
6217 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6218 TmpInst.addOperand(Inst.getOperand(5));
6223 case ARM::VST1LNdAsm_8:
6224 case ARM::VST1LNdAsm_16:
6225 case ARM::VST1LNdAsm_32: {
6227 // Shuffle the operands around so the lane index operand is in the
6230 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6231 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6232 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6233 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6234 TmpInst.addOperand(Inst.getOperand(1)); // lane
6235 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6236 TmpInst.addOperand(Inst.getOperand(5));
6241 case ARM::VST2LNdAsm_8:
6242 case ARM::VST2LNdAsm_16:
6243 case ARM::VST2LNdAsm_32:
6244 case ARM::VST2LNqAsm_16:
6245 case ARM::VST2LNqAsm_32: {
6247 // Shuffle the operands around so the lane index operand is in the
6250 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6251 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6252 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6253 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6256 TmpInst.addOperand(Inst.getOperand(1)); // lane
6257 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6258 TmpInst.addOperand(Inst.getOperand(5));
6263 case ARM::VST3LNdAsm_8:
6264 case ARM::VST3LNdAsm_16:
6265 case ARM::VST3LNdAsm_32:
6266 case ARM::VST3LNqAsm_16:
6267 case ARM::VST3LNqAsm_32: {
6269 // Shuffle the operands around so the lane index operand is in the
6272 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6273 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6274 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6275 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6276 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6278 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6280 TmpInst.addOperand(Inst.getOperand(1)); // lane
6281 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6282 TmpInst.addOperand(Inst.getOperand(5));
6287 case ARM::VST4LNdAsm_8:
6288 case ARM::VST4LNdAsm_16:
6289 case ARM::VST4LNdAsm_32:
6290 case ARM::VST4LNqAsm_16:
6291 case ARM::VST4LNqAsm_32: {
6293 // Shuffle the operands around so the lane index operand is in the
6296 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6297 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6298 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6299 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6306 TmpInst.addOperand(Inst.getOperand(1)); // lane
6307 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6308 TmpInst.addOperand(Inst.getOperand(5));
6313 // Handle NEON VLD complex aliases.
6314 case ARM::VLD1LNdWB_register_Asm_8:
6315 case ARM::VLD1LNdWB_register_Asm_16:
6316 case ARM::VLD1LNdWB_register_Asm_32: {
6318 // Shuffle the operands around so the lane index operand is in the
6321 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6322 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6323 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6324 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6325 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6326 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6327 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6328 TmpInst.addOperand(Inst.getOperand(1)); // lane
6329 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6330 TmpInst.addOperand(Inst.getOperand(6));
6335 case ARM::VLD2LNdWB_register_Asm_8:
6336 case ARM::VLD2LNdWB_register_Asm_16:
6337 case ARM::VLD2LNdWB_register_Asm_32:
6338 case ARM::VLD2LNqWB_register_Asm_16:
6339 case ARM::VLD2LNqWB_register_Asm_32: {
6341 // Shuffle the operands around so the lane index operand is in the
6344 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6345 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6346 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6349 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6350 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6351 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6352 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6353 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6355 TmpInst.addOperand(Inst.getOperand(1)); // lane
6356 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6357 TmpInst.addOperand(Inst.getOperand(6));
6362 case ARM::VLD3LNdWB_register_Asm_8:
6363 case ARM::VLD3LNdWB_register_Asm_16:
6364 case ARM::VLD3LNdWB_register_Asm_32:
6365 case ARM::VLD3LNqWB_register_Asm_16:
6366 case ARM::VLD3LNqWB_register_Asm_32: {
6368 // Shuffle the operands around so the lane index operand is in the
6371 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6372 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6377 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6378 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6379 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6380 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6381 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6382 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6384 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6386 TmpInst.addOperand(Inst.getOperand(1)); // lane
6387 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6388 TmpInst.addOperand(Inst.getOperand(6));
6393 case ARM::VLD4LNdWB_register_Asm_8:
6394 case ARM::VLD4LNdWB_register_Asm_16:
6395 case ARM::VLD4LNdWB_register_Asm_32:
6396 case ARM::VLD4LNqWB_register_Asm_16:
6397 case ARM::VLD4LNqWB_register_Asm_32: {
6399 // Shuffle the operands around so the lane index operand is in the
6402 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6403 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6408 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6410 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6411 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6412 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6413 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6414 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6415 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6417 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6419 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 TmpInst.addOperand(Inst.getOperand(1)); // lane
6422 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6423 TmpInst.addOperand(Inst.getOperand(6));
6428 case ARM::VLD1LNdWB_fixed_Asm_8:
6429 case ARM::VLD1LNdWB_fixed_Asm_16:
6430 case ARM::VLD1LNdWB_fixed_Asm_32: {
6432 // Shuffle the operands around so the lane index operand is in the
6435 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6436 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6437 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6438 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6439 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6440 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6441 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6442 TmpInst.addOperand(Inst.getOperand(1)); // lane
6443 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6444 TmpInst.addOperand(Inst.getOperand(5));
6449 case ARM::VLD2LNdWB_fixed_Asm_8:
6450 case ARM::VLD2LNdWB_fixed_Asm_16:
6451 case ARM::VLD2LNdWB_fixed_Asm_32:
6452 case ARM::VLD2LNqWB_fixed_Asm_16:
6453 case ARM::VLD2LNqWB_fixed_Asm_32: {
6455 // Shuffle the operands around so the lane index operand is in the
6458 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6459 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6460 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6462 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6463 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6464 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6465 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6466 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6469 TmpInst.addOperand(Inst.getOperand(1)); // lane
6470 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6471 TmpInst.addOperand(Inst.getOperand(5));
6476 case ARM::VLD3LNdWB_fixed_Asm_8:
6477 case ARM::VLD3LNdWB_fixed_Asm_16:
6478 case ARM::VLD3LNdWB_fixed_Asm_32:
6479 case ARM::VLD3LNqWB_fixed_Asm_16:
6480 case ARM::VLD3LNqWB_fixed_Asm_32: {
6482 // Shuffle the operands around so the lane index operand is in the
6485 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6486 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6487 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6489 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6491 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6492 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6493 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6494 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6495 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6496 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6498 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6500 TmpInst.addOperand(Inst.getOperand(1)); // lane
6501 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6502 TmpInst.addOperand(Inst.getOperand(5));
6507 case ARM::VLD4LNdWB_fixed_Asm_8:
6508 case ARM::VLD4LNdWB_fixed_Asm_16:
6509 case ARM::VLD4LNdWB_fixed_Asm_32:
6510 case ARM::VLD4LNqWB_fixed_Asm_16:
6511 case ARM::VLD4LNqWB_fixed_Asm_32: {
6513 // Shuffle the operands around so the lane index operand is in the
6516 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6517 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6524 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6525 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6526 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6527 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6528 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6529 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6533 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6535 TmpInst.addOperand(Inst.getOperand(1)); // lane
6536 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6537 TmpInst.addOperand(Inst.getOperand(5));
6542 case ARM::VLD1LNdAsm_8:
6543 case ARM::VLD1LNdAsm_16:
6544 case ARM::VLD1LNdAsm_32: {
6546 // Shuffle the operands around so the lane index operand is in the
6549 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6550 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6551 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6552 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6553 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6554 TmpInst.addOperand(Inst.getOperand(1)); // lane
6555 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6556 TmpInst.addOperand(Inst.getOperand(5));
6561 case ARM::VLD2LNdAsm_8:
6562 case ARM::VLD2LNdAsm_16:
6563 case ARM::VLD2LNdAsm_32:
6564 case ARM::VLD2LNqAsm_16:
6565 case ARM::VLD2LNqAsm_32: {
6567 // Shuffle the operands around so the lane index operand is in the
6570 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6571 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6574 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6575 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6576 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6577 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 TmpInst.addOperand(Inst.getOperand(1)); // lane
6580 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6581 TmpInst.addOperand(Inst.getOperand(5));
6586 case ARM::VLD3LNdAsm_8:
6587 case ARM::VLD3LNdAsm_16:
6588 case ARM::VLD3LNdAsm_32:
6589 case ARM::VLD3LNqAsm_16:
6590 case ARM::VLD3LNqAsm_32: {
6592 // Shuffle the operands around so the lane index operand is in the
6595 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6596 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6601 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6602 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6603 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6604 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6606 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6608 TmpInst.addOperand(Inst.getOperand(1)); // lane
6609 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6610 TmpInst.addOperand(Inst.getOperand(5));
6615 case ARM::VLD4LNdAsm_8:
6616 case ARM::VLD4LNdAsm_16:
6617 case ARM::VLD4LNdAsm_32:
6618 case ARM::VLD4LNqAsm_16:
6619 case ARM::VLD4LNqAsm_32: {
6621 // Shuffle the operands around so the lane index operand is in the
6624 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6625 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6626 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6628 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6630 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6632 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6633 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6634 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6635 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6637 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6639 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6641 TmpInst.addOperand(Inst.getOperand(1)); // lane
6642 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6643 TmpInst.addOperand(Inst.getOperand(5));
6648 // VLD3DUP single 3-element structure to all lanes instructions.
6649 case ARM::VLD3DUPdAsm_8:
6650 case ARM::VLD3DUPdAsm_16:
6651 case ARM::VLD3DUPdAsm_32:
6652 case ARM::VLD3DUPqAsm_8:
6653 case ARM::VLD3DUPqAsm_16:
6654 case ARM::VLD3DUPqAsm_32: {
6657 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6658 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6659 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6661 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6663 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6664 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6665 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6666 TmpInst.addOperand(Inst.getOperand(4));
6671 case ARM::VLD3DUPdWB_fixed_Asm_8:
6672 case ARM::VLD3DUPdWB_fixed_Asm_16:
6673 case ARM::VLD3DUPdWB_fixed_Asm_32:
6674 case ARM::VLD3DUPqWB_fixed_Asm_8:
6675 case ARM::VLD3DUPqWB_fixed_Asm_16:
6676 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6679 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6680 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6681 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6683 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6685 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6686 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6687 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6688 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6689 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6690 TmpInst.addOperand(Inst.getOperand(4));
6695 case ARM::VLD3DUPdWB_register_Asm_8:
6696 case ARM::VLD3DUPdWB_register_Asm_16:
6697 case ARM::VLD3DUPdWB_register_Asm_32:
6698 case ARM::VLD3DUPqWB_register_Asm_8:
6699 case ARM::VLD3DUPqWB_register_Asm_16:
6700 case ARM::VLD3DUPqWB_register_Asm_32: {
6703 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6704 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6705 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6707 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6709 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6710 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6711 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6712 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6713 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6714 TmpInst.addOperand(Inst.getOperand(5));
6719 // VLD3 multiple 3-element structure instructions.
6720 case ARM::VLD3dAsm_8:
6721 case ARM::VLD3dAsm_16:
6722 case ARM::VLD3dAsm_32:
6723 case ARM::VLD3qAsm_8:
6724 case ARM::VLD3qAsm_16:
6725 case ARM::VLD3qAsm_32: {
6728 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6729 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6730 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6732 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6734 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6735 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6736 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6737 TmpInst.addOperand(Inst.getOperand(4));
6742 case ARM::VLD3dWB_fixed_Asm_8:
6743 case ARM::VLD3dWB_fixed_Asm_16:
6744 case ARM::VLD3dWB_fixed_Asm_32:
6745 case ARM::VLD3qWB_fixed_Asm_8:
6746 case ARM::VLD3qWB_fixed_Asm_16:
6747 case ARM::VLD3qWB_fixed_Asm_32: {
6750 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6751 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6752 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6754 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6756 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6757 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6758 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6759 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6760 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6761 TmpInst.addOperand(Inst.getOperand(4));
6766 case ARM::VLD3dWB_register_Asm_8:
6767 case ARM::VLD3dWB_register_Asm_16:
6768 case ARM::VLD3dWB_register_Asm_32:
6769 case ARM::VLD3qWB_register_Asm_8:
6770 case ARM::VLD3qWB_register_Asm_16:
6771 case ARM::VLD3qWB_register_Asm_32: {
6774 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6775 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6776 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6778 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6780 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6781 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6782 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6783 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6784 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6785 TmpInst.addOperand(Inst.getOperand(5));
6790 // VLD4DUP single 3-element structure to all lanes instructions.
6791 case ARM::VLD4DUPdAsm_8:
6792 case ARM::VLD4DUPdAsm_16:
6793 case ARM::VLD4DUPdAsm_32:
6794 case ARM::VLD4DUPqAsm_8:
6795 case ARM::VLD4DUPqAsm_16:
6796 case ARM::VLD4DUPqAsm_32: {
6799 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6800 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6801 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6803 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6805 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6807 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6808 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6809 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6810 TmpInst.addOperand(Inst.getOperand(4));
6815 case ARM::VLD4DUPdWB_fixed_Asm_8:
6816 case ARM::VLD4DUPdWB_fixed_Asm_16:
6817 case ARM::VLD4DUPdWB_fixed_Asm_32:
6818 case ARM::VLD4DUPqWB_fixed_Asm_8:
6819 case ARM::VLD4DUPqWB_fixed_Asm_16:
6820 case ARM::VLD4DUPqWB_fixed_Asm_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(1)); // Rn_wb == tied Rn
6833 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6834 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6835 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6836 TmpInst.addOperand(Inst.getOperand(4));
6841 case ARM::VLD4DUPdWB_register_Asm_8:
6842 case ARM::VLD4DUPdWB_register_Asm_16:
6843 case ARM::VLD4DUPdWB_register_Asm_32:
6844 case ARM::VLD4DUPqWB_register_Asm_8:
6845 case ARM::VLD4DUPqWB_register_Asm_16:
6846 case ARM::VLD4DUPqWB_register_Asm_32: {
6849 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6850 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6855 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6857 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6858 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6859 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6860 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6861 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6862 TmpInst.addOperand(Inst.getOperand(5));
6867 // VLD4 multiple 4-element structure instructions.
6868 case ARM::VLD4dAsm_8:
6869 case ARM::VLD4dAsm_16:
6870 case ARM::VLD4dAsm_32:
6871 case ARM::VLD4qAsm_8:
6872 case ARM::VLD4qAsm_16:
6873 case ARM::VLD4qAsm_32: {
6876 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6877 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6878 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6885 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6886 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6887 TmpInst.addOperand(Inst.getOperand(4));
6892 case ARM::VLD4dWB_fixed_Asm_8:
6893 case ARM::VLD4dWB_fixed_Asm_16:
6894 case ARM::VLD4dWB_fixed_Asm_32:
6895 case ARM::VLD4qWB_fixed_Asm_8:
6896 case ARM::VLD4qWB_fixed_Asm_16:
6897 case ARM::VLD4qWB_fixed_Asm_32: {
6900 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6901 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6902 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6904 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6906 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6908 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6909 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6910 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6911 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6912 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6913 TmpInst.addOperand(Inst.getOperand(4));
6918 case ARM::VLD4dWB_register_Asm_8:
6919 case ARM::VLD4dWB_register_Asm_16:
6920 case ARM::VLD4dWB_register_Asm_32:
6921 case ARM::VLD4qWB_register_Asm_8:
6922 case ARM::VLD4qWB_register_Asm_16:
6923 case ARM::VLD4qWB_register_Asm_32: {
6926 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
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(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6934 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6935 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6936 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6937 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6938 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6939 TmpInst.addOperand(Inst.getOperand(5));
6944 // VST3 multiple 3-element structure instructions.
6945 case ARM::VST3dAsm_8:
6946 case ARM::VST3dAsm_16:
6947 case ARM::VST3dAsm_32:
6948 case ARM::VST3qAsm_8:
6949 case ARM::VST3qAsm_16:
6950 case ARM::VST3qAsm_32: {
6953 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6954 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6955 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6956 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6957 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6959 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6961 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6962 TmpInst.addOperand(Inst.getOperand(4));
6967 case ARM::VST3dWB_fixed_Asm_8:
6968 case ARM::VST3dWB_fixed_Asm_16:
6969 case ARM::VST3dWB_fixed_Asm_32:
6970 case ARM::VST3qWB_fixed_Asm_8:
6971 case ARM::VST3qWB_fixed_Asm_16:
6972 case ARM::VST3qWB_fixed_Asm_32: {
6975 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6976 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6977 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6978 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6979 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6980 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6983 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6985 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6986 TmpInst.addOperand(Inst.getOperand(4));
6991 case ARM::VST3dWB_register_Asm_8:
6992 case ARM::VST3dWB_register_Asm_16:
6993 case ARM::VST3dWB_register_Asm_32:
6994 case ARM::VST3qWB_register_Asm_8:
6995 case ARM::VST3qWB_register_Asm_16:
6996 case ARM::VST3qWB_register_Asm_32: {
6999 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7000 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7001 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7002 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7003 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7004 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7007 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7009 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7010 TmpInst.addOperand(Inst.getOperand(5));
7015 // VST4 multiple 3-element structure instructions.
7016 case ARM::VST4dAsm_8:
7017 case ARM::VST4dAsm_16:
7018 case ARM::VST4dAsm_32:
7019 case ARM::VST4qAsm_8:
7020 case ARM::VST4qAsm_16:
7021 case ARM::VST4qAsm_32: {
7024 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7025 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7026 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7027 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7028 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7030 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7032 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7034 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7035 TmpInst.addOperand(Inst.getOperand(4));
7040 case ARM::VST4dWB_fixed_Asm_8:
7041 case ARM::VST4dWB_fixed_Asm_16:
7042 case ARM::VST4dWB_fixed_Asm_32:
7043 case ARM::VST4qWB_fixed_Asm_8:
7044 case ARM::VST4qWB_fixed_Asm_16:
7045 case ARM::VST4qWB_fixed_Asm_32: {
7048 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7049 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7050 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7051 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7052 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7053 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7054 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7056 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7058 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7060 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7061 TmpInst.addOperand(Inst.getOperand(4));
7066 case ARM::VST4dWB_register_Asm_8:
7067 case ARM::VST4dWB_register_Asm_16:
7068 case ARM::VST4dWB_register_Asm_32:
7069 case ARM::VST4qWB_register_Asm_8:
7070 case ARM::VST4qWB_register_Asm_16:
7071 case ARM::VST4qWB_register_Asm_32: {
7074 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7075 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7076 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7077 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7078 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7079 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7086 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7087 TmpInst.addOperand(Inst.getOperand(5));
7092 // Handle encoding choice for the shift-immediate instructions.
7095 case ARM::t2ASRri: {
7096 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7097 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7098 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7099 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7100 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7102 switch (Inst.getOpcode()) {
7103 default: llvm_unreachable("unexpected opcode");
7104 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7105 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7106 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7108 // The Thumb1 operands aren't in the same order. Awesome, eh?
7110 TmpInst.setOpcode(NewOpc);
7111 TmpInst.addOperand(Inst.getOperand(0));
7112 TmpInst.addOperand(Inst.getOperand(5));
7113 TmpInst.addOperand(Inst.getOperand(1));
7114 TmpInst.addOperand(Inst.getOperand(2));
7115 TmpInst.addOperand(Inst.getOperand(3));
7116 TmpInst.addOperand(Inst.getOperand(4));
7123 // Handle the Thumb2 mode MOV complex aliases.
7125 case ARM::t2MOVSsr: {
7126 // Which instruction to expand to depends on the CCOut operand and
7127 // whether we're in an IT block if the register operands are low
7129 bool isNarrow = false;
7130 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7131 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7132 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7133 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7134 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7138 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7139 default: llvm_unreachable("unexpected opcode!");
7140 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7141 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7142 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7143 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7145 TmpInst.setOpcode(newOpc);
7146 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7148 TmpInst.addOperand(MCOperand::CreateReg(
7149 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7150 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7151 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7152 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7153 TmpInst.addOperand(Inst.getOperand(5));
7155 TmpInst.addOperand(MCOperand::CreateReg(
7156 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7161 case ARM::t2MOVSsi: {
7162 // Which instruction to expand to depends on the CCOut operand and
7163 // whether we're in an IT block if the register operands are low
7165 bool isNarrow = false;
7166 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7167 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7168 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7172 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7173 default: llvm_unreachable("unexpected opcode!");
7174 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7175 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7176 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7177 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7178 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7180 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7181 if (Amount == 32) Amount = 0;
7182 TmpInst.setOpcode(newOpc);
7183 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7185 TmpInst.addOperand(MCOperand::CreateReg(
7186 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7187 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7188 if (newOpc != ARM::t2RRX)
7189 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7190 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7191 TmpInst.addOperand(Inst.getOperand(4));
7193 TmpInst.addOperand(MCOperand::CreateReg(
7194 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7198 // Handle the ARM mode MOV complex aliases.
7203 ARM_AM::ShiftOpc ShiftTy;
7204 switch(Inst.getOpcode()) {
7205 default: llvm_unreachable("unexpected opcode!");
7206 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7207 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7208 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7209 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7211 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7213 TmpInst.setOpcode(ARM::MOVsr);
7214 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7215 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7216 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7217 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7218 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7219 TmpInst.addOperand(Inst.getOperand(4));
7220 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7228 ARM_AM::ShiftOpc ShiftTy;
7229 switch(Inst.getOpcode()) {
7230 default: llvm_unreachable("unexpected opcode!");
7231 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7232 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7233 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7234 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7236 // A shift by zero is a plain MOVr, not a MOVsi.
7237 unsigned Amt = Inst.getOperand(2).getImm();
7238 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7239 // A shift by 32 should be encoded as 0 when permitted
7240 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7242 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7244 TmpInst.setOpcode(Opc);
7245 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7246 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7247 if (Opc == ARM::MOVsi)
7248 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7249 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7250 TmpInst.addOperand(Inst.getOperand(4));
7251 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7256 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7258 TmpInst.setOpcode(ARM::MOVsi);
7259 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7260 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7261 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7262 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7263 TmpInst.addOperand(Inst.getOperand(3));
7264 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7268 case ARM::t2LDMIA_UPD: {
7269 // If this is a load of a single register, then we should use
7270 // a post-indexed LDR instruction instead, per the ARM ARM.
7271 if (Inst.getNumOperands() != 5)
7274 TmpInst.setOpcode(ARM::t2LDR_POST);
7275 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7276 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7277 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7278 TmpInst.addOperand(MCOperand::CreateImm(4));
7279 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7280 TmpInst.addOperand(Inst.getOperand(3));
7284 case ARM::t2STMDB_UPD: {
7285 // If this is a store of a single register, then we should use
7286 // a pre-indexed STR instruction instead, per the ARM ARM.
7287 if (Inst.getNumOperands() != 5)
7290 TmpInst.setOpcode(ARM::t2STR_PRE);
7291 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7292 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7293 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7294 TmpInst.addOperand(MCOperand::CreateImm(-4));
7295 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7296 TmpInst.addOperand(Inst.getOperand(3));
7300 case ARM::LDMIA_UPD:
7301 // If this is a load of a single register via a 'pop', then we should use
7302 // a post-indexed LDR instruction instead, per the ARM ARM.
7303 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7304 Inst.getNumOperands() == 5) {
7306 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7307 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7308 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7309 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7310 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7311 TmpInst.addOperand(MCOperand::CreateImm(4));
7312 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7313 TmpInst.addOperand(Inst.getOperand(3));
7318 case ARM::STMDB_UPD:
7319 // If this is a store of a single register via a 'push', then we should use
7320 // a pre-indexed STR instruction instead, per the ARM ARM.
7321 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7322 Inst.getNumOperands() == 5) {
7324 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7325 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7326 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7327 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7328 TmpInst.addOperand(MCOperand::CreateImm(-4));
7329 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7330 TmpInst.addOperand(Inst.getOperand(3));
7334 case ARM::t2ADDri12:
7335 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7336 // mnemonic was used (not "addw"), encoding T3 is preferred.
7337 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7338 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7340 Inst.setOpcode(ARM::t2ADDri);
7341 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7343 case ARM::t2SUBri12:
7344 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7345 // mnemonic was used (not "subw"), encoding T3 is preferred.
7346 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7347 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7349 Inst.setOpcode(ARM::t2SUBri);
7350 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7353 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7354 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7355 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7356 // to encoding T1 if <Rd> is omitted."
7357 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7358 Inst.setOpcode(ARM::tADDi3);
7363 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7364 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7365 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7366 // to encoding T1 if <Rd> is omitted."
7367 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7368 Inst.setOpcode(ARM::tSUBi3);
7373 case ARM::t2SUBri: {
7374 // If the destination and first source operand are the same, and
7375 // the flags are compatible with the current IT status, use encoding T2
7376 // instead of T3. For compatibility with the system 'as'. Make sure the
7377 // wide encoding wasn't explicit.
7378 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7379 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7380 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7381 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7382 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7383 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7384 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7387 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7388 ARM::tADDi8 : ARM::tSUBi8);
7389 TmpInst.addOperand(Inst.getOperand(0));
7390 TmpInst.addOperand(Inst.getOperand(5));
7391 TmpInst.addOperand(Inst.getOperand(0));
7392 TmpInst.addOperand(Inst.getOperand(2));
7393 TmpInst.addOperand(Inst.getOperand(3));
7394 TmpInst.addOperand(Inst.getOperand(4));
7398 case ARM::t2ADDrr: {
7399 // If the destination and first source operand are the same, and
7400 // there's no setting of the flags, use encoding T2 instead of T3.
7401 // Note that this is only for ADD, not SUB. This mirrors the system
7402 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7403 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7404 Inst.getOperand(5).getReg() != 0 ||
7405 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7406 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7409 TmpInst.setOpcode(ARM::tADDhirr);
7410 TmpInst.addOperand(Inst.getOperand(0));
7411 TmpInst.addOperand(Inst.getOperand(0));
7412 TmpInst.addOperand(Inst.getOperand(2));
7413 TmpInst.addOperand(Inst.getOperand(3));
7414 TmpInst.addOperand(Inst.getOperand(4));
7418 case ARM::tADDrSP: {
7419 // If the non-SP source operand and the destination operand are not the
7420 // same, we need to use the 32-bit encoding if it's available.
7421 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7422 Inst.setOpcode(ARM::t2ADDrr);
7423 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7429 // A Thumb conditional branch outside of an IT block is a tBcc.
7430 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7431 Inst.setOpcode(ARM::tBcc);
7436 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7437 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7438 Inst.setOpcode(ARM::t2Bcc);
7443 // If the conditional is AL or we're in an IT block, we really want t2B.
7444 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7445 Inst.setOpcode(ARM::t2B);
7450 // If the conditional is AL, we really want tB.
7451 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7452 Inst.setOpcode(ARM::tB);
7457 // If the register list contains any high registers, or if the writeback
7458 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7459 // instead if we're in Thumb2. Otherwise, this should have generated
7460 // an error in validateInstruction().
7461 unsigned Rn = Inst.getOperand(0).getReg();
7462 bool hasWritebackToken =
7463 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7464 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7465 bool listContainsBase;
7466 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7467 (!listContainsBase && !hasWritebackToken) ||
7468 (listContainsBase && hasWritebackToken)) {
7469 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7470 assert (isThumbTwo());
7471 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7472 // If we're switching to the updating version, we need to insert
7473 // the writeback tied operand.
7474 if (hasWritebackToken)
7475 Inst.insert(Inst.begin(),
7476 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7481 case ARM::tSTMIA_UPD: {
7482 // If the register list contains any high registers, we need to use
7483 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7484 // should have generated an error in validateInstruction().
7485 unsigned Rn = Inst.getOperand(0).getReg();
7486 bool listContainsBase;
7487 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7488 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7489 assert (isThumbTwo());
7490 Inst.setOpcode(ARM::t2STMIA_UPD);
7496 bool listContainsBase;
7497 // If the register list contains any high registers, we need to use
7498 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7499 // should have generated an error in validateInstruction().
7500 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7502 assert (isThumbTwo());
7503 Inst.setOpcode(ARM::t2LDMIA_UPD);
7504 // Add the base register and writeback operands.
7505 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7506 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7510 bool listContainsBase;
7511 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7513 assert (isThumbTwo());
7514 Inst.setOpcode(ARM::t2STMDB_UPD);
7515 // Add the base register and writeback operands.
7516 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7517 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7521 // If we can use the 16-bit encoding and the user didn't explicitly
7522 // request the 32-bit variant, transform it here.
7523 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7524 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7525 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7526 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7527 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7528 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7529 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7530 // The operands aren't in the same order for tMOVi8...
7532 TmpInst.setOpcode(ARM::tMOVi8);
7533 TmpInst.addOperand(Inst.getOperand(0));
7534 TmpInst.addOperand(Inst.getOperand(4));
7535 TmpInst.addOperand(Inst.getOperand(1));
7536 TmpInst.addOperand(Inst.getOperand(2));
7537 TmpInst.addOperand(Inst.getOperand(3));
7544 // If we can use the 16-bit encoding and the user didn't explicitly
7545 // request the 32-bit variant, transform it here.
7546 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7547 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7548 Inst.getOperand(2).getImm() == ARMCC::AL &&
7549 Inst.getOperand(4).getReg() == ARM::CPSR &&
7550 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7551 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7552 // The operands aren't the same for tMOV[S]r... (no cc_out)
7554 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7555 TmpInst.addOperand(Inst.getOperand(0));
7556 TmpInst.addOperand(Inst.getOperand(1));
7557 TmpInst.addOperand(Inst.getOperand(2));
7558 TmpInst.addOperand(Inst.getOperand(3));
7568 // If we can use the 16-bit encoding and the user didn't explicitly
7569 // request the 32-bit variant, transform it here.
7570 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7571 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7572 Inst.getOperand(2).getImm() == 0 &&
7573 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7574 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7576 switch (Inst.getOpcode()) {
7577 default: llvm_unreachable("Illegal opcode!");
7578 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7579 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7580 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7581 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7583 // The operands aren't the same for thumb1 (no rotate operand).
7585 TmpInst.setOpcode(NewOpc);
7586 TmpInst.addOperand(Inst.getOperand(0));
7587 TmpInst.addOperand(Inst.getOperand(1));
7588 TmpInst.addOperand(Inst.getOperand(3));
7589 TmpInst.addOperand(Inst.getOperand(4));
7596 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7597 // rrx shifts and asr/lsr of #32 is encoded as 0
7598 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7600 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7601 // Shifting by zero is accepted as a vanilla 'MOVr'
7603 TmpInst.setOpcode(ARM::MOVr);
7604 TmpInst.addOperand(Inst.getOperand(0));
7605 TmpInst.addOperand(Inst.getOperand(1));
7606 TmpInst.addOperand(Inst.getOperand(3));
7607 TmpInst.addOperand(Inst.getOperand(4));
7608 TmpInst.addOperand(Inst.getOperand(5));
7621 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7622 if (SOpc == ARM_AM::rrx) return false;
7623 switch (Inst.getOpcode()) {
7624 default: llvm_unreachable("unexpected opcode!");
7625 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7626 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7627 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7628 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7629 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7630 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7632 // If the shift is by zero, use the non-shifted instruction definition.
7633 // The exception is for right shifts, where 0 == 32
7634 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7635 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7637 TmpInst.setOpcode(newOpc);
7638 TmpInst.addOperand(Inst.getOperand(0));
7639 TmpInst.addOperand(Inst.getOperand(1));
7640 TmpInst.addOperand(Inst.getOperand(2));
7641 TmpInst.addOperand(Inst.getOperand(4));
7642 TmpInst.addOperand(Inst.getOperand(5));
7643 TmpInst.addOperand(Inst.getOperand(6));
7651 // The mask bits for all but the first condition are represented as
7652 // the low bit of the condition code value implies 't'. We currently
7653 // always have 1 implies 't', so XOR toggle the bits if the low bit
7654 // of the condition code is zero.
7655 MCOperand &MO = Inst.getOperand(1);
7656 unsigned Mask = MO.getImm();
7657 unsigned OrigMask = Mask;
7658 unsigned TZ = countTrailingZeros(Mask);
7659 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7660 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7661 Mask ^= (0xE << TZ) & 0xF;
7665 // Set up the IT block state according to the IT instruction we just
7667 assert(!inITBlock() && "nested IT blocks?!");
7668 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7669 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7670 ITState.CurPosition = 0;
7671 ITState.FirstCond = true;
7681 // Assemblers should use the narrow encodings of these instructions when permissible.
7682 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7683 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7684 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7685 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7686 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7687 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7688 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7690 switch (Inst.getOpcode()) {
7691 default: llvm_unreachable("unexpected opcode");
7692 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7693 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7694 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7695 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7696 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7697 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7700 TmpInst.setOpcode(NewOpc);
7701 TmpInst.addOperand(Inst.getOperand(0));
7702 TmpInst.addOperand(Inst.getOperand(5));
7703 TmpInst.addOperand(Inst.getOperand(1));
7704 TmpInst.addOperand(Inst.getOperand(2));
7705 TmpInst.addOperand(Inst.getOperand(3));
7706 TmpInst.addOperand(Inst.getOperand(4));
7717 // Assemblers should use the narrow encodings of these instructions when permissible.
7718 // These instructions are special in that they are commutable, so shorter encodings
7719 // are available more often.
7720 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7721 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7722 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7723 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7724 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7725 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7726 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7727 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7729 switch (Inst.getOpcode()) {
7730 default: llvm_unreachable("unexpected opcode");
7731 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7732 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7733 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7734 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7737 TmpInst.setOpcode(NewOpc);
7738 TmpInst.addOperand(Inst.getOperand(0));
7739 TmpInst.addOperand(Inst.getOperand(5));
7740 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7741 TmpInst.addOperand(Inst.getOperand(1));
7742 TmpInst.addOperand(Inst.getOperand(2));
7744 TmpInst.addOperand(Inst.getOperand(2));
7745 TmpInst.addOperand(Inst.getOperand(1));
7747 TmpInst.addOperand(Inst.getOperand(3));
7748 TmpInst.addOperand(Inst.getOperand(4));
7758 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7759 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7760 // suffix depending on whether they're in an IT block or not.
7761 unsigned Opc = Inst.getOpcode();
7762 const MCInstrDesc &MCID = MII.get(Opc);
7763 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7764 assert(MCID.hasOptionalDef() &&
7765 "optionally flag setting instruction missing optional def operand");
7766 assert(MCID.NumOperands == Inst.getNumOperands() &&
7767 "operand count mismatch!");
7768 // Find the optional-def operand (cc_out).
7771 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7774 // If we're parsing Thumb1, reject it completely.
7775 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7776 return Match_MnemonicFail;
7777 // If we're parsing Thumb2, which form is legal depends on whether we're
7779 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7781 return Match_RequiresITBlock;
7782 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7784 return Match_RequiresNotITBlock;
7786 // Some high-register supporting Thumb1 encodings only allow both registers
7787 // to be from r0-r7 when in Thumb2.
7788 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7789 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7790 isARMLowRegister(Inst.getOperand(2).getReg()))
7791 return Match_RequiresThumb2;
7792 // Others only require ARMv6 or later.
7793 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7794 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7795 isARMLowRegister(Inst.getOperand(1).getReg()))
7796 return Match_RequiresV6;
7797 return Match_Success;
7800 static const char *getSubtargetFeatureName(unsigned Val);
7802 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7803 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7804 MCStreamer &Out, unsigned &ErrorInfo,
7805 bool MatchingInlineAsm) {
7807 unsigned MatchResult;
7809 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7811 switch (MatchResult) {
7814 // Context sensitive operand constraints aren't handled by the matcher,
7815 // so check them here.
7816 if (validateInstruction(Inst, Operands)) {
7817 // Still progress the IT block, otherwise one wrong condition causes
7818 // nasty cascading errors.
7819 forwardITPosition();
7823 { // processInstruction() updates inITBlock state, we need to save it away
7824 bool wasInITBlock = inITBlock();
7826 // Some instructions need post-processing to, for example, tweak which
7827 // encoding is selected. Loop on it while changes happen so the
7828 // individual transformations can chain off each other. E.g.,
7829 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7830 while (processInstruction(Inst, Operands))
7833 // Only after the instruction is fully processed, we can validate it
7834 if (wasInITBlock && hasV8Ops() && isThumb() &&
7835 !isV8EligibleForIT(&Inst, 2)) {
7836 Warning(IDLoc, "deprecated instruction in IT block");
7840 // Only move forward at the very end so that everything in validate
7841 // and process gets a consistent answer about whether we're in an IT
7843 forwardITPosition();
7845 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7846 // doesn't actually encode.
7847 if (Inst.getOpcode() == ARM::ITasm)
7851 Out.EmitInstruction(Inst);
7853 case Match_MissingFeature: {
7854 assert(ErrorInfo && "Unknown missing feature!");
7855 // Special case the error message for the very common case where only
7856 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7857 std::string Msg = "instruction requires:";
7859 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7860 if (ErrorInfo & Mask) {
7862 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7866 return Error(IDLoc, Msg);
7868 case Match_InvalidOperand: {
7869 SMLoc ErrorLoc = IDLoc;
7870 if (ErrorInfo != ~0U) {
7871 if (ErrorInfo >= Operands.size())
7872 return Error(IDLoc, "too few operands for instruction");
7874 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7875 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7878 return Error(ErrorLoc, "invalid operand for instruction");
7880 case Match_MnemonicFail:
7881 return Error(IDLoc, "invalid instruction",
7882 ((ARMOperand*)Operands[0])->getLocRange());
7883 case Match_RequiresNotITBlock:
7884 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7885 case Match_RequiresITBlock:
7886 return Error(IDLoc, "instruction only valid inside IT block");
7887 case Match_RequiresV6:
7888 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7889 case Match_RequiresThumb2:
7890 return Error(IDLoc, "instruction variant requires Thumb2");
7891 case Match_ImmRange0_15: {
7892 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7893 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7894 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7896 case Match_ImmRange0_239: {
7897 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7898 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7899 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7903 llvm_unreachable("Implement any new match types added!");
7906 /// parseDirective parses the arm specific directives
7907 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7908 StringRef IDVal = DirectiveID.getIdentifier();
7909 if (IDVal == ".word")
7910 return parseDirectiveWord(4, DirectiveID.getLoc());
7911 else if (IDVal == ".thumb")
7912 return parseDirectiveThumb(DirectiveID.getLoc());
7913 else if (IDVal == ".arm")
7914 return parseDirectiveARM(DirectiveID.getLoc());
7915 else if (IDVal == ".thumb_func")
7916 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7917 else if (IDVal == ".code")
7918 return parseDirectiveCode(DirectiveID.getLoc());
7919 else if (IDVal == ".syntax")
7920 return parseDirectiveSyntax(DirectiveID.getLoc());
7921 else if (IDVal == ".unreq")
7922 return parseDirectiveUnreq(DirectiveID.getLoc());
7923 else if (IDVal == ".arch")
7924 return parseDirectiveArch(DirectiveID.getLoc());
7925 else if (IDVal == ".eabi_attribute")
7926 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7927 else if (IDVal == ".cpu")
7928 return parseDirectiveCPU(DirectiveID.getLoc());
7929 else if (IDVal == ".fpu")
7930 return parseDirectiveFPU(DirectiveID.getLoc());
7931 else if (IDVal == ".fnstart")
7932 return parseDirectiveFnStart(DirectiveID.getLoc());
7933 else if (IDVal == ".fnend")
7934 return parseDirectiveFnEnd(DirectiveID.getLoc());
7935 else if (IDVal == ".cantunwind")
7936 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7937 else if (IDVal == ".personality")
7938 return parseDirectivePersonality(DirectiveID.getLoc());
7939 else if (IDVal == ".handlerdata")
7940 return parseDirectiveHandlerData(DirectiveID.getLoc());
7941 else if (IDVal == ".setfp")
7942 return parseDirectiveSetFP(DirectiveID.getLoc());
7943 else if (IDVal == ".pad")
7944 return parseDirectivePad(DirectiveID.getLoc());
7945 else if (IDVal == ".save")
7946 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7947 else if (IDVal == ".vsave")
7948 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7949 else if (IDVal == ".inst")
7950 return parseDirectiveInst(DirectiveID.getLoc());
7951 else if (IDVal == ".inst.n")
7952 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7953 else if (IDVal == ".inst.w")
7954 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
7955 else if (IDVal == ".ltorg" || IDVal == ".pool")
7956 return parseDirectiveLtorg(DirectiveID.getLoc());
7957 else if (IDVal == ".even")
7958 return parseDirectiveEven(DirectiveID.getLoc());
7962 /// parseDirectiveWord
7963 /// ::= .word [ expression (, expression)* ]
7964 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
7965 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7967 const MCExpr *Value;
7968 if (getParser().parseExpression(Value))
7971 getParser().getStreamer().EmitValue(Value, Size);
7973 if (getLexer().is(AsmToken::EndOfStatement))
7976 // FIXME: Improve diagnostic.
7977 if (getLexer().isNot(AsmToken::Comma))
7978 return Error(L, "unexpected token in directive");
7987 /// parseDirectiveThumb
7989 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
7990 if (getLexer().isNot(AsmToken::EndOfStatement))
7991 return Error(L, "unexpected token in directive");
7995 return Error(L, "target does not support Thumb mode");
7999 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8003 /// parseDirectiveARM
8005 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
8006 if (getLexer().isNot(AsmToken::EndOfStatement))
8007 return Error(L, "unexpected token in directive");
8011 return Error(L, "target does not support ARM mode");
8015 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8019 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8020 if (NextSymbolIsThumb) {
8021 getParser().getStreamer().EmitThumbFunc(Symbol);
8022 NextSymbolIsThumb = false;
8026 /// parseDirectiveThumbFunc
8027 /// ::= .thumbfunc symbol_name
8028 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
8029 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8030 bool isMachO = MAI->hasSubsectionsViaSymbols();
8032 // Darwin asm has (optionally) function name after .thumb_func direction
8035 const AsmToken &Tok = Parser.getTok();
8036 if (Tok.isNot(AsmToken::EndOfStatement)) {
8037 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
8038 return Error(L, "unexpected token in .thumb_func directive");
8040 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8041 getParser().getStreamer().EmitThumbFunc(Func);
8042 Parser.Lex(); // Consume the identifier token.
8047 if (getLexer().isNot(AsmToken::EndOfStatement))
8048 return Error(L, "unexpected token in directive");
8050 NextSymbolIsThumb = true;
8055 /// parseDirectiveSyntax
8056 /// ::= .syntax unified | divided
8057 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
8058 const AsmToken &Tok = Parser.getTok();
8059 if (Tok.isNot(AsmToken::Identifier))
8060 return Error(L, "unexpected token in .syntax directive");
8061 StringRef Mode = Tok.getString();
8062 if (Mode == "unified" || Mode == "UNIFIED")
8064 else if (Mode == "divided" || Mode == "DIVIDED")
8065 return Error(L, "'.syntax divided' arm asssembly not supported");
8067 return Error(L, "unrecognized syntax mode in .syntax directive");
8069 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8070 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8075 // TODO tell the MC streamer the mode
8076 // getParser().getStreamer().Emit???();
8080 /// parseDirectiveCode
8081 /// ::= .code 16 | 32
8082 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
8083 const AsmToken &Tok = Parser.getTok();
8084 if (Tok.isNot(AsmToken::Integer)) {
8085 Error(L, "unexpected token in .code directive");
8088 int64_t Val = Parser.getTok().getIntVal();
8089 if (Val != 16 && Val != 32) {
8090 Error(L, "invalid operand to .code directive");
8095 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8096 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8103 Error(L, "target does not support Thumb mode");
8109 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8112 Error(L, "target does not support ARM mode");
8118 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8124 /// parseDirectiveReq
8125 /// ::= name .req registername
8126 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8127 Parser.Lex(); // Eat the '.req' token.
8129 SMLoc SRegLoc, ERegLoc;
8130 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
8131 Parser.eatToEndOfStatement();
8132 Error(SRegLoc, "register name expected");
8136 // Shouldn't be anything else.
8137 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
8138 Parser.eatToEndOfStatement();
8139 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8143 Parser.Lex(); // Consume the EndOfStatement
8145 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8146 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8153 /// parseDirectiveUneq
8154 /// ::= .unreq registername
8155 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8156 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8157 Parser.eatToEndOfStatement();
8158 Error(L, "unexpected input in .unreq directive.");
8161 RegisterReqs.erase(Parser.getTok().getIdentifier());
8162 Parser.Lex(); // Eat the identifier.
8166 /// parseDirectiveArch
8168 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8169 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8171 unsigned ID = StringSwitch<unsigned>(Arch)
8172 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8173 .Case(NAME, ARM::ID)
8174 #define ARM_ARCH_ALIAS(NAME, ID) \
8175 .Case(NAME, ARM::ID)
8176 #include "MCTargetDesc/ARMArchName.def"
8177 .Default(ARM::INVALID_ARCH);
8179 if (ID == ARM::INVALID_ARCH) {
8180 Error(L, "Unknown arch name");
8184 getTargetStreamer().emitArch(ID);
8188 /// parseDirectiveEabiAttr
8189 /// ::= .eabi_attribute int, int
8190 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8191 if (Parser.getTok().isNot(AsmToken::Integer)) {
8192 Error(L, "integer expected");
8195 int64_t Tag = Parser.getTok().getIntVal();
8196 Parser.Lex(); // eat tag integer
8198 if (Parser.getTok().isNot(AsmToken::Comma)) {
8199 Error(L, "comma expected");
8202 Parser.Lex(); // skip comma
8204 L = Parser.getTok().getLoc();
8205 if (Parser.getTok().isNot(AsmToken::Integer)) {
8206 Error(L, "integer expected");
8209 int64_t Value = Parser.getTok().getIntVal();
8210 Parser.Lex(); // eat value integer
8212 getTargetStreamer().emitAttribute(Tag, Value);
8216 /// parseDirectiveCPU
8218 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8219 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8220 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8224 /// parseDirectiveFPU
8226 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8227 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8229 unsigned ID = StringSwitch<unsigned>(FPU)
8230 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8231 #include "ARMFPUName.def"
8232 .Default(ARM::INVALID_FPU);
8234 if (ID == ARM::INVALID_FPU) {
8235 Error(L, "Unknown FPU name");
8239 getTargetStreamer().emitFPU(ID);
8243 /// parseDirectiveFnStart
8245 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8246 if (FnStartLoc.isValid()) {
8247 Error(L, ".fnstart starts before the end of previous one");
8248 Error(FnStartLoc, "previous .fnstart starts here");
8253 getTargetStreamer().emitFnStart();
8257 /// parseDirectiveFnEnd
8259 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8260 // Check the ordering of unwind directives
8261 if (!FnStartLoc.isValid()) {
8262 Error(L, ".fnstart must precede .fnend directive");
8266 // Reset the unwind directives parser state
8267 resetUnwindDirectiveParserState();
8268 getTargetStreamer().emitFnEnd();
8272 /// parseDirectiveCantUnwind
8274 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8275 // Check the ordering of unwind directives
8277 if (!FnStartLoc.isValid()) {
8278 Error(L, ".fnstart must precede .cantunwind directive");
8281 if (HandlerDataLoc.isValid()) {
8282 Error(L, ".cantunwind can't be used with .handlerdata directive");
8283 Error(HandlerDataLoc, ".handlerdata was specified here");
8286 if (PersonalityLoc.isValid()) {
8287 Error(L, ".cantunwind can't be used with .personality directive");
8288 Error(PersonalityLoc, ".personality was specified here");
8292 getTargetStreamer().emitCantUnwind();
8296 /// parseDirectivePersonality
8297 /// ::= .personality name
8298 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8299 // Check the ordering of unwind directives
8301 if (!FnStartLoc.isValid()) {
8302 Error(L, ".fnstart must precede .personality directive");
8305 if (CantUnwindLoc.isValid()) {
8306 Error(L, ".personality can't be used with .cantunwind directive");
8307 Error(CantUnwindLoc, ".cantunwind was specified here");
8310 if (HandlerDataLoc.isValid()) {
8311 Error(L, ".personality must precede .handlerdata directive");
8312 Error(HandlerDataLoc, ".handlerdata was specified here");
8316 // Parse the name of the personality routine
8317 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8318 Parser.eatToEndOfStatement();
8319 Error(L, "unexpected input in .personality directive.");
8322 StringRef Name(Parser.getTok().getIdentifier());
8325 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8326 getTargetStreamer().emitPersonality(PR);
8330 /// parseDirectiveHandlerData
8331 /// ::= .handlerdata
8332 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8333 // Check the ordering of unwind directives
8335 if (!FnStartLoc.isValid()) {
8336 Error(L, ".fnstart must precede .personality directive");
8339 if (CantUnwindLoc.isValid()) {
8340 Error(L, ".handlerdata can't be used with .cantunwind directive");
8341 Error(CantUnwindLoc, ".cantunwind was specified here");
8345 getTargetStreamer().emitHandlerData();
8349 /// parseDirectiveSetFP
8350 /// ::= .setfp fpreg, spreg [, offset]
8351 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8352 // Check the ordering of unwind directives
8353 if (!FnStartLoc.isValid()) {
8354 Error(L, ".fnstart must precede .setfp directive");
8357 if (HandlerDataLoc.isValid()) {
8358 Error(L, ".setfp must precede .handlerdata directive");
8363 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8364 int NewFPReg = tryParseRegister();
8365 if (NewFPReg == -1) {
8366 Error(NewFPRegLoc, "frame pointer register expected");
8371 if (!Parser.getTok().is(AsmToken::Comma)) {
8372 Error(Parser.getTok().getLoc(), "comma expected");
8375 Parser.Lex(); // skip comma
8378 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8379 int NewSPReg = tryParseRegister();
8380 if (NewSPReg == -1) {
8381 Error(NewSPRegLoc, "stack pointer register expected");
8385 if (NewSPReg != ARM::SP && NewSPReg != FPReg) {
8387 "register should be either $sp or the latest fp register");
8391 // Update the frame pointer register
8396 if (Parser.getTok().is(AsmToken::Comma)) {
8397 Parser.Lex(); // skip comma
8399 if (Parser.getTok().isNot(AsmToken::Hash) &&
8400 Parser.getTok().isNot(AsmToken::Dollar)) {
8401 Error(Parser.getTok().getLoc(), "'#' expected");
8404 Parser.Lex(); // skip hash token.
8406 const MCExpr *OffsetExpr;
8407 SMLoc ExLoc = Parser.getTok().getLoc();
8409 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8410 Error(ExLoc, "malformed setfp offset");
8413 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8415 Error(ExLoc, "setfp offset must be an immediate");
8419 Offset = CE->getValue();
8422 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8423 static_cast<unsigned>(NewSPReg), Offset);
8429 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8430 // Check the ordering of unwind directives
8431 if (!FnStartLoc.isValid()) {
8432 Error(L, ".fnstart must precede .pad directive");
8435 if (HandlerDataLoc.isValid()) {
8436 Error(L, ".pad must precede .handlerdata directive");
8441 if (Parser.getTok().isNot(AsmToken::Hash) &&
8442 Parser.getTok().isNot(AsmToken::Dollar)) {
8443 Error(Parser.getTok().getLoc(), "'#' expected");
8446 Parser.Lex(); // skip hash token.
8448 const MCExpr *OffsetExpr;
8449 SMLoc ExLoc = Parser.getTok().getLoc();
8451 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8452 Error(ExLoc, "malformed pad offset");
8455 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8457 Error(ExLoc, "pad offset must be an immediate");
8461 getTargetStreamer().emitPad(CE->getValue());
8465 /// parseDirectiveRegSave
8466 /// ::= .save { registers }
8467 /// ::= .vsave { registers }
8468 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8469 // Check the ordering of unwind directives
8470 if (!FnStartLoc.isValid()) {
8471 Error(L, ".fnstart must precede .save or .vsave directives");
8474 if (HandlerDataLoc.isValid()) {
8475 Error(L, ".save or .vsave must precede .handlerdata directive");
8479 // RAII object to make sure parsed operands are deleted.
8480 struct CleanupObject {
8481 SmallVector<MCParsedAsmOperand *, 1> Operands;
8483 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8488 // Parse the register list
8489 if (parseRegisterList(CO.Operands))
8491 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8492 if (!IsVector && !Op->isRegList()) {
8493 Error(L, ".save expects GPR registers");
8496 if (IsVector && !Op->isDPRRegList()) {
8497 Error(L, ".vsave expects DPR registers");
8501 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8505 /// parseDirectiveInst
8506 /// ::= .inst opcode [, ...]
8507 /// ::= .inst.n opcode [, ...]
8508 /// ::= .inst.w opcode [, ...]
8509 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8521 Parser.eatToEndOfStatement();
8522 Error(Loc, "cannot determine Thumb instruction size, "
8523 "use inst.n/inst.w instead");
8528 Parser.eatToEndOfStatement();
8529 Error(Loc, "width suffixes are invalid in ARM mode");
8535 if (getLexer().is(AsmToken::EndOfStatement)) {
8536 Parser.eatToEndOfStatement();
8537 Error(Loc, "expected expression following directive");
8544 if (getParser().parseExpression(Expr)) {
8545 Error(Loc, "expected expression");
8549 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8551 Error(Loc, "expected constant expression");
8557 if (Value->getValue() > 0xffff) {
8558 Error(Loc, "inst.n operand is too big, use inst.w instead");
8563 if (Value->getValue() > 0xffffffff) {
8565 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8570 llvm_unreachable("only supported widths are 2 and 4");
8573 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8575 if (getLexer().is(AsmToken::EndOfStatement))
8578 if (getLexer().isNot(AsmToken::Comma)) {
8579 Error(Loc, "unexpected token in directive");
8590 /// parseDirectiveLtorg
8591 /// ::= .ltorg | .pool
8592 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
8593 MCStreamer &Streamer = getParser().getStreamer();
8594 const MCSection *Section = Streamer.getCurrentSection().first;
8596 if (ConstantPool *CP = getConstantPool(Section)) {
8598 CP->emitEntries(Streamer);
8603 bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
8604 const MCSection *Section = getStreamer().getCurrentSection().first;
8606 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8607 TokError("unexpected token in directive");
8612 getStreamer().InitToTextSection();
8613 Section = getStreamer().getCurrentSection().first;
8616 if (Section->UseCodeAlign())
8617 getStreamer().EmitCodeAlignment(2, 0);
8619 getStreamer().EmitValueToAlignment(2, 0, 1, 0);
8624 /// Force static initialization.
8625 extern "C" void LLVMInitializeARMAsmParser() {
8626 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8627 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8630 #define GET_REGISTER_MATCHER
8631 #define GET_SUBTARGET_FEATURE_NAME
8632 #define GET_MATCHER_IMPLEMENTATION
8633 #include "ARMGenAsmMatcher.inc"
8635 // Define this matcher function after the auto-generated include so we
8636 // have the match class enum definitions.
8637 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8639 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8640 // If the kind is a token for a literal immediate, check if our asm
8641 // operand matches. This is for InstAliases which have a fixed-value
8642 // immediate in the syntax.
8643 if (Kind == MCK__35_0 && Op->isImm()) {
8644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8646 return Match_InvalidOperand;
8647 if (CE->getValue() == 0)
8648 return Match_Success;
8650 return Match_InvalidOperand;
8653 void ARMAsmParser::finishParse() {
8654 // Dump contents of assembler constant pools.
8655 MCStreamer &Streamer = getParser().getStreamer();
8656 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8657 CPE = ConstantPools.end();
8658 CPI != CPE; ++CPI) {
8659 const MCSection *Section = CPI->first;
8660 ConstantPool &CP = CPI->second;
8662 // Dump non-empty assembler constant pools at the end of the section.
8664 Streamer.SwitchSection(Section);
8665 CP.emitEntries(Streamer);