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 "ARMFPUName.h"
11 #include "ARMFeatures.h"
12 #include "llvm/MC/MCTargetAsmParser.h"
13 #include "MCTargetDesc/ARMAddressingModes.h"
14 #include "MCTargetDesc/ARMBuildAttrs.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 UnwindContext {
121 SMLoc PersonalityLoc;
122 SMLoc HandlerDataLoc;
126 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(-1) {}
128 bool hasFnStart() const { return FnStartLoc.isValid(); }
129 bool cantUnwind() const { return CantUnwindLoc.isValid(); }
130 bool hasHandlerData() const { return HandlerDataLoc.isValid(); }
131 bool hasPersonality() const { return PersonalityLoc.isValid(); }
133 void recordFnStart(SMLoc L) { FnStartLoc = L; }
134 void recordCantUnwind(SMLoc L) { CantUnwindLoc = L; }
135 void recordPersonality(SMLoc L) { PersonalityLoc = L; }
136 void recordHandlerData(SMLoc L) { HandlerDataLoc = L; }
138 void saveFPReg(int Reg) { FPReg = Reg; }
139 int getFPReg() const { return FPReg; }
141 void emitFnStartLocNotes() const {
142 Parser.Note(FnStartLoc, ".fnstart was specified here");
144 void emitCantUnwindLocNotes() const {
145 Parser.Note(CantUnwindLoc, ".cantunwind was specified here");
147 void emitHandlerDataLocNotes() const {
148 Parser.Note(HandlerDataLoc, ".handlerdata was specified here");
150 void emitPersonalityLocNotes() const {
151 Parser.Note(PersonalityLoc, ".personality was specified here");
155 FnStartLoc = SMLoc();
156 CantUnwindLoc = SMLoc();
157 PersonalityLoc = SMLoc();
158 HandlerDataLoc = SMLoc();
163 class ARMAsmParser : public MCTargetAsmParser {
164 MCSubtargetInfo &STI;
166 const MCInstrInfo &MII;
167 const MCRegisterInfo *MRI;
168 ConstantPoolMapTy ConstantPools;
171 // Assembler created constant pools for ldr pseudo
172 ConstantPool *getConstantPool(const MCSection *Section) {
173 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
174 if (CP == ConstantPools.end())
180 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
181 return ConstantPools[Section];
184 ARMTargetStreamer &getTargetStreamer() {
185 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
186 return static_cast<ARMTargetStreamer &>(TS);
189 // Map of register aliases registers via the .req directive.
190 StringMap<unsigned> RegisterReqs;
192 bool NextSymbolIsThumb;
195 ARMCC::CondCodes Cond; // Condition for IT block.
196 unsigned Mask:4; // Condition mask for instructions.
197 // Starting at first 1 (from lsb).
198 // '1' condition as indicated in IT.
199 // '0' inverse of condition (else).
200 // Count of instructions in IT block is
201 // 4 - trailingzeroes(mask)
203 bool FirstCond; // Explicit flag for when we're parsing the
204 // First instruction in the IT block. It's
205 // implied in the mask, so needs special
208 unsigned CurPosition; // Current position in parsing of IT
209 // block. In range [0,3]. Initialized
210 // according to count of instructions in block.
211 // ~0U if no active IT block.
213 bool inITBlock() { return ITState.CurPosition != ~0U;}
214 void forwardITPosition() {
215 if (!inITBlock()) return;
216 // Move to the next instruction in the IT block, if there is one. If not,
217 // mark the block as done.
218 unsigned TZ = countTrailingZeros(ITState.Mask);
219 if (++ITState.CurPosition == 5 - TZ)
220 ITState.CurPosition = ~0U; // Done with the IT block after this.
224 MCAsmParser &getParser() const { return Parser; }
225 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
227 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
228 return Parser.Note(L, Msg, Ranges);
230 bool Warning(SMLoc L, const Twine &Msg,
231 ArrayRef<SMRange> Ranges = None) {
232 return Parser.Warning(L, Msg, Ranges);
234 bool Error(SMLoc L, const Twine &Msg,
235 ArrayRef<SMRange> Ranges = None) {
236 return Parser.Error(L, Msg, Ranges);
239 int tryParseRegister();
240 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
241 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
242 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
243 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
244 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
245 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
246 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
247 unsigned &ShiftAmount);
248 bool parseDirectiveWord(unsigned Size, SMLoc L);
249 bool parseDirectiveThumb(SMLoc L);
250 bool parseDirectiveARM(SMLoc L);
251 bool parseDirectiveThumbFunc(SMLoc L);
252 bool parseDirectiveCode(SMLoc L);
253 bool parseDirectiveSyntax(SMLoc L);
254 bool parseDirectiveReq(StringRef Name, SMLoc L);
255 bool parseDirectiveUnreq(SMLoc L);
256 bool parseDirectiveArch(SMLoc L);
257 bool parseDirectiveEabiAttr(SMLoc L);
258 bool parseDirectiveCPU(SMLoc L);
259 bool parseDirectiveFPU(SMLoc L);
260 bool parseDirectiveFnStart(SMLoc L);
261 bool parseDirectiveFnEnd(SMLoc L);
262 bool parseDirectiveCantUnwind(SMLoc L);
263 bool parseDirectivePersonality(SMLoc L);
264 bool parseDirectiveHandlerData(SMLoc L);
265 bool parseDirectiveSetFP(SMLoc L);
266 bool parseDirectivePad(SMLoc L);
267 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
268 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
269 bool parseDirectiveLtorg(SMLoc L);
270 bool parseDirectiveEven(SMLoc L);
272 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
273 bool &CarrySetting, unsigned &ProcessorIMod,
275 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
276 bool &CanAcceptCarrySet,
277 bool &CanAcceptPredicationCode);
279 bool isThumb() const {
280 // FIXME: Can tablegen auto-generate this?
281 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
283 bool isThumbOne() const {
284 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
286 bool isThumbTwo() const {
287 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
289 bool hasThumb() const {
290 return STI.getFeatureBits() & ARM::HasV4TOps;
292 bool hasV6Ops() const {
293 return STI.getFeatureBits() & ARM::HasV6Ops;
295 bool hasV6MOps() const {
296 return STI.getFeatureBits() & ARM::HasV6MOps;
298 bool hasV7Ops() const {
299 return STI.getFeatureBits() & ARM::HasV7Ops;
301 bool hasV8Ops() const {
302 return STI.getFeatureBits() & ARM::HasV8Ops;
304 bool hasARM() const {
305 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
309 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
310 setAvailableFeatures(FB);
312 bool isMClass() const {
313 return STI.getFeatureBits() & ARM::FeatureMClass;
316 /// @name Auto-generated Match Functions
319 #define GET_ASSEMBLER_HEADER
320 #include "ARMGenAsmMatcher.inc"
324 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
325 OperandMatchResultTy parseCoprocNumOperand(
326 SmallVectorImpl<MCParsedAsmOperand*>&);
327 OperandMatchResultTy parseCoprocRegOperand(
328 SmallVectorImpl<MCParsedAsmOperand*>&);
329 OperandMatchResultTy parseCoprocOptionOperand(
330 SmallVectorImpl<MCParsedAsmOperand*>&);
331 OperandMatchResultTy parseMemBarrierOptOperand(
332 SmallVectorImpl<MCParsedAsmOperand*>&);
333 OperandMatchResultTy parseInstSyncBarrierOptOperand(
334 SmallVectorImpl<MCParsedAsmOperand*>&);
335 OperandMatchResultTy parseProcIFlagsOperand(
336 SmallVectorImpl<MCParsedAsmOperand*>&);
337 OperandMatchResultTy parseMSRMaskOperand(
338 SmallVectorImpl<MCParsedAsmOperand*>&);
339 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
340 StringRef Op, int Low, int High);
341 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
342 return parsePKHImm(O, "lsl", 0, 31);
344 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
345 return parsePKHImm(O, "asr", 1, 32);
347 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
348 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
349 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
350 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
351 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
352 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
353 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
354 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
355 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
358 // Asm Match Converter Methods
359 void cvtThumbMultiply(MCInst &Inst,
360 const SmallVectorImpl<MCParsedAsmOperand*> &);
361 void cvtThumbBranches(MCInst &Inst,
362 const SmallVectorImpl<MCParsedAsmOperand*> &);
364 bool validateInstruction(MCInst &Inst,
365 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
366 bool processInstruction(MCInst &Inst,
367 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
368 bool shouldOmitCCOutOperand(StringRef Mnemonic,
369 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
370 bool shouldOmitPredicateOperand(StringRef Mnemonic,
371 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
373 enum ARMMatchResultTy {
374 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
375 Match_RequiresNotITBlock,
377 Match_RequiresThumb2,
378 #define GET_OPERAND_DIAGNOSTIC_TYPES
379 #include "ARMGenAsmMatcher.inc"
383 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
384 const MCInstrInfo &MII)
385 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) {
386 MCAsmParserExtension::Initialize(_Parser);
388 // Cache the MCRegisterInfo.
389 MRI = getContext().getRegisterInfo();
391 // Initialize the set of available features.
392 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
394 // Not in an ITBlock to start with.
395 ITState.CurPosition = ~0U;
397 NextSymbolIsThumb = false;
400 // Implementation of the MCTargetAsmParser interface:
401 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
402 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
404 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
405 bool ParseDirective(AsmToken DirectiveID);
407 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
408 unsigned checkTargetMatchPredicate(MCInst &Inst);
410 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
411 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
412 MCStreamer &Out, unsigned &ErrorInfo,
413 bool MatchingInlineAsm);
414 void onLabelParsed(MCSymbol *Symbol);
417 } // end anonymous namespace
421 /// ARMOperand - Instances of this class represent a parsed ARM machine
423 class ARMOperand : public MCParsedAsmOperand {
433 k_InstSyncBarrierOpt,
444 k_VectorListAllLanes,
450 k_BitfieldDescriptor,
454 SMLoc StartLoc, EndLoc;
455 SmallVector<unsigned, 8> Registers;
458 ARMCC::CondCodes Val;
465 struct CoprocOptionOp {
478 ARM_ISB::InstSyncBOpt Val;
482 ARM_PROC::IFlags Val;
498 // A vector register list is a sequential list of 1 to 4 registers.
499 struct VectorListOp {
506 struct VectorIndexOp {
514 /// Combined record for all forms of ARM address expressions.
517 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
519 const MCConstantExpr *OffsetImm; // Offset immediate value
520 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
521 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
522 unsigned ShiftImm; // shift for OffsetReg.
523 unsigned Alignment; // 0 = no alignment specified
524 // n = alignment in bytes (2, 4, 8, 16, or 32)
525 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
528 struct PostIdxRegOp {
531 ARM_AM::ShiftOpc ShiftTy;
535 struct ShifterImmOp {
540 struct RegShiftedRegOp {
541 ARM_AM::ShiftOpc ShiftTy;
547 struct RegShiftedImmOp {
548 ARM_AM::ShiftOpc ShiftTy;
565 struct CoprocOptionOp CoprocOption;
566 struct MBOptOp MBOpt;
567 struct ISBOptOp ISBOpt;
568 struct ITMaskOp ITMask;
569 struct IFlagsOp IFlags;
570 struct MMaskOp MMask;
573 struct VectorListOp VectorList;
574 struct VectorIndexOp VectorIndex;
576 struct MemoryOp Memory;
577 struct PostIdxRegOp PostIdxReg;
578 struct ShifterImmOp ShifterImm;
579 struct RegShiftedRegOp RegShiftedReg;
580 struct RegShiftedImmOp RegShiftedImm;
581 struct RotImmOp RotImm;
582 struct BitfieldOp Bitfield;
585 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
587 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
589 StartLoc = o.StartLoc;
606 case k_DPRRegisterList:
607 case k_SPRRegisterList:
608 Registers = o.Registers;
611 case k_VectorListAllLanes:
612 case k_VectorListIndexed:
613 VectorList = o.VectorList;
620 CoprocOption = o.CoprocOption;
625 case k_MemBarrierOpt:
628 case k_InstSyncBarrierOpt:
633 case k_PostIndexRegister:
634 PostIdxReg = o.PostIdxReg;
642 case k_ShifterImmediate:
643 ShifterImm = o.ShifterImm;
645 case k_ShiftedRegister:
646 RegShiftedReg = o.RegShiftedReg;
648 case k_ShiftedImmediate:
649 RegShiftedImm = o.RegShiftedImm;
651 case k_RotateImmediate:
654 case k_BitfieldDescriptor:
655 Bitfield = o.Bitfield;
658 VectorIndex = o.VectorIndex;
663 /// getStartLoc - Get the location of the first token of this operand.
664 SMLoc getStartLoc() const { return StartLoc; }
665 /// getEndLoc - Get the location of the last token of this operand.
666 SMLoc getEndLoc() const { return EndLoc; }
667 /// getLocRange - Get the range between the first and last token of this
669 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
671 ARMCC::CondCodes getCondCode() const {
672 assert(Kind == k_CondCode && "Invalid access!");
676 unsigned getCoproc() const {
677 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
681 StringRef getToken() const {
682 assert(Kind == k_Token && "Invalid access!");
683 return StringRef(Tok.Data, Tok.Length);
686 unsigned getReg() const {
687 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
691 const SmallVectorImpl<unsigned> &getRegList() const {
692 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
693 Kind == k_SPRRegisterList) && "Invalid access!");
697 const MCExpr *getImm() const {
698 assert(isImm() && "Invalid access!");
702 unsigned getVectorIndex() const {
703 assert(Kind == k_VectorIndex && "Invalid access!");
704 return VectorIndex.Val;
707 ARM_MB::MemBOpt getMemBarrierOpt() const {
708 assert(Kind == k_MemBarrierOpt && "Invalid access!");
712 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
713 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
717 ARM_PROC::IFlags getProcIFlags() const {
718 assert(Kind == k_ProcIFlags && "Invalid access!");
722 unsigned getMSRMask() const {
723 assert(Kind == k_MSRMask && "Invalid access!");
727 bool isCoprocNum() const { return Kind == k_CoprocNum; }
728 bool isCoprocReg() const { return Kind == k_CoprocReg; }
729 bool isCoprocOption() const { return Kind == k_CoprocOption; }
730 bool isCondCode() const { return Kind == k_CondCode; }
731 bool isCCOut() const { return Kind == k_CCOut; }
732 bool isITMask() const { return Kind == k_ITCondMask; }
733 bool isITCondCode() const { return Kind == k_CondCode; }
734 bool isImm() const { return Kind == k_Immediate; }
735 // checks whether this operand is an unsigned offset which fits is a field
736 // of specified width and scaled by a specific number of bits
737 template<unsigned width, unsigned scale>
738 bool isUnsignedOffset() const {
739 if (!isImm()) return false;
740 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
741 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
742 int64_t Val = CE->getValue();
743 int64_t Align = 1LL << scale;
744 int64_t Max = Align * ((1LL << width) - 1);
745 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
749 // checks whether this operand is an signed offset which fits is a field
750 // of specified width and scaled by a specific number of bits
751 template<unsigned width, unsigned scale>
752 bool isSignedOffset() const {
753 if (!isImm()) return false;
754 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
755 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
756 int64_t Val = CE->getValue();
757 int64_t Align = 1LL << scale;
758 int64_t Max = Align * ((1LL << (width-1)) - 1);
759 int64_t Min = -Align * (1LL << (width-1));
760 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
765 // checks whether this operand is a memory operand computed as an offset
766 // applied to PC. the offset may have 8 bits of magnitude and is represented
767 // with two bits of shift. textually it may be either [pc, #imm], #imm or
768 // relocable expression...
769 bool isThumbMemPC() const {
772 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
773 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
774 if (!CE) return false;
775 Val = CE->getValue();
778 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
779 if(Memory.BaseRegNum != ARM::PC) return false;
780 Val = Memory.OffsetImm->getValue();
783 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
785 bool isFPImm() const {
786 if (!isImm()) return false;
787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
788 if (!CE) return false;
789 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
792 bool isFBits16() const {
793 if (!isImm()) return false;
794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
795 if (!CE) return false;
796 int64_t Value = CE->getValue();
797 return Value >= 0 && Value <= 16;
799 bool isFBits32() const {
800 if (!isImm()) return false;
801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
802 if (!CE) return false;
803 int64_t Value = CE->getValue();
804 return Value >= 1 && Value <= 32;
806 bool isImm8s4() const {
807 if (!isImm()) return false;
808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
809 if (!CE) return false;
810 int64_t Value = CE->getValue();
811 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
813 bool isImm0_1020s4() const {
814 if (!isImm()) return false;
815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
816 if (!CE) return false;
817 int64_t Value = CE->getValue();
818 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
820 bool isImm0_508s4() const {
821 if (!isImm()) return false;
822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
823 if (!CE) return false;
824 int64_t Value = CE->getValue();
825 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
827 bool isImm0_508s4Neg() const {
828 if (!isImm()) return false;
829 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
830 if (!CE) return false;
831 int64_t Value = -CE->getValue();
832 // explicitly exclude zero. we want that to use the normal 0_508 version.
833 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
835 bool isImm0_239() const {
836 if (!isImm()) return false;
837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return Value >= 0 && Value < 240;
842 bool isImm0_255() const {
843 if (!isImm()) return false;
844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value >= 0 && Value < 256;
849 bool isImm0_4095() const {
850 if (!isImm()) return false;
851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
854 return Value >= 0 && Value < 4096;
856 bool isImm0_4095Neg() const {
857 if (!isImm()) return false;
858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = -CE->getValue();
861 return Value > 0 && Value < 4096;
863 bool isImm0_1() const {
864 if (!isImm()) return false;
865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value >= 0 && Value < 2;
870 bool isImm0_3() const {
871 if (!isImm()) return false;
872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 if (!CE) return false;
874 int64_t Value = CE->getValue();
875 return Value >= 0 && Value < 4;
877 bool isImm0_7() const {
878 if (!isImm()) return false;
879 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
880 if (!CE) return false;
881 int64_t Value = CE->getValue();
882 return Value >= 0 && Value < 8;
884 bool isImm0_15() const {
885 if (!isImm()) return false;
886 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
887 if (!CE) return false;
888 int64_t Value = CE->getValue();
889 return Value >= 0 && Value < 16;
891 bool isImm0_31() const {
892 if (!isImm()) return false;
893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
894 if (!CE) return false;
895 int64_t Value = CE->getValue();
896 return Value >= 0 && Value < 32;
898 bool isImm0_63() const {
899 if (!isImm()) return false;
900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
901 if (!CE) return false;
902 int64_t Value = CE->getValue();
903 return Value >= 0 && Value < 64;
905 bool isImm8() const {
906 if (!isImm()) return false;
907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
908 if (!CE) return false;
909 int64_t Value = CE->getValue();
912 bool isImm16() const {
913 if (!isImm()) return false;
914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
915 if (!CE) return false;
916 int64_t Value = CE->getValue();
919 bool isImm32() const {
920 if (!isImm()) return false;
921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
922 if (!CE) return false;
923 int64_t Value = CE->getValue();
926 bool isShrImm8() const {
927 if (!isImm()) return false;
928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
929 if (!CE) return false;
930 int64_t Value = CE->getValue();
931 return Value > 0 && Value <= 8;
933 bool isShrImm16() const {
934 if (!isImm()) return false;
935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
936 if (!CE) return false;
937 int64_t Value = CE->getValue();
938 return Value > 0 && Value <= 16;
940 bool isShrImm32() const {
941 if (!isImm()) return false;
942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
943 if (!CE) return false;
944 int64_t Value = CE->getValue();
945 return Value > 0 && Value <= 32;
947 bool isShrImm64() const {
948 if (!isImm()) return false;
949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
950 if (!CE) return false;
951 int64_t Value = CE->getValue();
952 return Value > 0 && Value <= 64;
954 bool isImm1_7() const {
955 if (!isImm()) return false;
956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
959 return Value > 0 && Value < 8;
961 bool isImm1_15() const {
962 if (!isImm()) return false;
963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
964 if (!CE) return false;
965 int64_t Value = CE->getValue();
966 return Value > 0 && Value < 16;
968 bool isImm1_31() const {
969 if (!isImm()) return false;
970 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
971 if (!CE) return false;
972 int64_t Value = CE->getValue();
973 return Value > 0 && Value < 32;
975 bool isImm1_16() const {
976 if (!isImm()) return false;
977 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
978 if (!CE) return false;
979 int64_t Value = CE->getValue();
980 return Value > 0 && Value < 17;
982 bool isImm1_32() const {
983 if (!isImm()) return false;
984 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
985 if (!CE) return false;
986 int64_t Value = CE->getValue();
987 return Value > 0 && Value < 33;
989 bool isImm0_32() const {
990 if (!isImm()) return false;
991 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
992 if (!CE) return false;
993 int64_t Value = CE->getValue();
994 return Value >= 0 && Value < 33;
996 bool isImm0_65535() const {
997 if (!isImm()) return false;
998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
999 if (!CE) return false;
1000 int64_t Value = CE->getValue();
1001 return Value >= 0 && Value < 65536;
1003 bool isImm256_65535Expr() const {
1004 if (!isImm()) return false;
1005 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1006 // If it's not a constant expression, it'll generate a fixup and be
1008 if (!CE) return true;
1009 int64_t Value = CE->getValue();
1010 return Value >= 256 && Value < 65536;
1012 bool isImm0_65535Expr() const {
1013 if (!isImm()) return false;
1014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1015 // If it's not a constant expression, it'll generate a fixup and be
1017 if (!CE) return true;
1018 int64_t Value = CE->getValue();
1019 return Value >= 0 && Value < 65536;
1021 bool isImm24bit() const {
1022 if (!isImm()) return false;
1023 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1024 if (!CE) return false;
1025 int64_t Value = CE->getValue();
1026 return Value >= 0 && Value <= 0xffffff;
1028 bool isImmThumbSR() const {
1029 if (!isImm()) return false;
1030 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1031 if (!CE) return false;
1032 int64_t Value = CE->getValue();
1033 return Value > 0 && Value < 33;
1035 bool isPKHLSLImm() const {
1036 if (!isImm()) return false;
1037 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1038 if (!CE) return false;
1039 int64_t Value = CE->getValue();
1040 return Value >= 0 && Value < 32;
1042 bool isPKHASRImm() 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 Value > 0 && Value <= 32;
1049 bool isAdrLabel() const {
1050 // If we have an immediate that's not a constant, treat it as a label
1051 // reference needing a fixup. If it is a constant, but it can't fit
1052 // into shift immediate encoding, we reject it.
1053 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1054 else return (isARMSOImm() || isARMSOImmNeg());
1056 bool isARMSOImm() const {
1057 if (!isImm()) return false;
1058 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1059 if (!CE) return false;
1060 int64_t Value = CE->getValue();
1061 return ARM_AM::getSOImmVal(Value) != -1;
1063 bool isARMSOImmNot() const {
1064 if (!isImm()) return false;
1065 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1066 if (!CE) return false;
1067 int64_t Value = CE->getValue();
1068 return ARM_AM::getSOImmVal(~Value) != -1;
1070 bool isARMSOImmNeg() const {
1071 if (!isImm()) return false;
1072 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1073 if (!CE) return false;
1074 int64_t Value = CE->getValue();
1075 // Only use this when not representable as a plain so_imm.
1076 return ARM_AM::getSOImmVal(Value) == -1 &&
1077 ARM_AM::getSOImmVal(-Value) != -1;
1079 bool isT2SOImm() const {
1080 if (!isImm()) return false;
1081 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1082 if (!CE) return false;
1083 int64_t Value = CE->getValue();
1084 return ARM_AM::getT2SOImmVal(Value) != -1;
1086 bool isT2SOImmNot() const {
1087 if (!isImm()) return false;
1088 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1089 if (!CE) return false;
1090 int64_t Value = CE->getValue();
1091 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1092 ARM_AM::getT2SOImmVal(~Value) != -1;
1094 bool isT2SOImmNeg() const {
1095 if (!isImm()) return false;
1096 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1097 if (!CE) return false;
1098 int64_t Value = CE->getValue();
1099 // Only use this when not representable as a plain so_imm.
1100 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1101 ARM_AM::getT2SOImmVal(-Value) != -1;
1103 bool isSetEndImm() const {
1104 if (!isImm()) return false;
1105 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1106 if (!CE) return false;
1107 int64_t Value = CE->getValue();
1108 return Value == 1 || Value == 0;
1110 bool isReg() const { return Kind == k_Register; }
1111 bool isRegList() const { return Kind == k_RegisterList; }
1112 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1113 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1114 bool isToken() const { return Kind == k_Token; }
1115 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
1116 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
1117 bool isMem() const { return Kind == k_Memory; }
1118 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1119 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1120 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1121 bool isRotImm() const { return Kind == k_RotateImmediate; }
1122 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1123 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
1124 bool isPostIdxReg() const {
1125 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
1127 bool isMemNoOffset(bool alignOK = false) const {
1130 // No offset of any kind.
1131 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1132 (alignOK || Memory.Alignment == 0);
1134 bool isMemPCRelImm12() const {
1135 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1137 // Base register must be PC.
1138 if (Memory.BaseRegNum != ARM::PC)
1140 // Immediate offset in range [-4095, 4095].
1141 if (!Memory.OffsetImm) return true;
1142 int64_t Val = Memory.OffsetImm->getValue();
1143 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1145 bool isAlignedMemory() const {
1146 return isMemNoOffset(true);
1148 bool isAddrMode2() const {
1149 if (!isMem() || Memory.Alignment != 0) return false;
1150 // Check for register offset.
1151 if (Memory.OffsetRegNum) return true;
1152 // Immediate offset in range [-4095, 4095].
1153 if (!Memory.OffsetImm) return true;
1154 int64_t Val = Memory.OffsetImm->getValue();
1155 return Val > -4096 && Val < 4096;
1157 bool isAM2OffsetImm() const {
1158 if (!isImm()) return false;
1159 // Immediate offset in range [-4095, 4095].
1160 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1161 if (!CE) return false;
1162 int64_t Val = CE->getValue();
1163 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
1165 bool isAddrMode3() const {
1166 // If we have an immediate that's not a constant, treat it as a label
1167 // reference needing a fixup. If it is a constant, it's something else
1168 // and we reject it.
1169 if (isImm() && !isa<MCConstantExpr>(getImm()))
1171 if (!isMem() || Memory.Alignment != 0) return false;
1172 // No shifts are legal for AM3.
1173 if (Memory.ShiftType != ARM_AM::no_shift) return false;
1174 // Check for register offset.
1175 if (Memory.OffsetRegNum) return true;
1176 // Immediate offset in range [-255, 255].
1177 if (!Memory.OffsetImm) return true;
1178 int64_t Val = Memory.OffsetImm->getValue();
1179 // The #-0 offset is encoded as INT32_MIN, and we have to check
1181 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1183 bool isAM3Offset() const {
1184 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
1186 if (Kind == k_PostIndexRegister)
1187 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1188 // Immediate offset in range [-255, 255].
1189 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1190 if (!CE) return false;
1191 int64_t Val = CE->getValue();
1192 // Special case, #-0 is INT32_MIN.
1193 return (Val > -256 && Val < 256) || Val == INT32_MIN;
1195 bool isAddrMode5() const {
1196 // If we have an immediate that's not a constant, treat it as a label
1197 // reference needing a fixup. If it is a constant, it's something else
1198 // and we reject it.
1199 if (isImm() && !isa<MCConstantExpr>(getImm()))
1201 if (!isMem() || Memory.Alignment != 0) return false;
1202 // Check for register offset.
1203 if (Memory.OffsetRegNum) return false;
1204 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1205 if (!Memory.OffsetImm) return true;
1206 int64_t Val = Memory.OffsetImm->getValue();
1207 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
1210 bool isMemTBB() const {
1211 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1212 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1216 bool isMemTBH() const {
1217 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1218 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1219 Memory.Alignment != 0 )
1223 bool isMemRegOffset() const {
1224 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
1228 bool isT2MemRegOffset() const {
1229 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1230 Memory.Alignment != 0)
1232 // Only lsl #{0, 1, 2, 3} allowed.
1233 if (Memory.ShiftType == ARM_AM::no_shift)
1235 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
1239 bool isMemThumbRR() const {
1240 // Thumb reg+reg addressing is simple. Just two registers, a base and
1241 // an offset. No shifts, negations or any other complicating factors.
1242 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
1243 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
1245 return isARMLowRegister(Memory.BaseRegNum) &&
1246 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
1248 bool isMemThumbRIs4() const {
1249 if (!isMem() || Memory.OffsetRegNum != 0 ||
1250 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1252 // Immediate offset, multiple of 4 in range [0, 124].
1253 if (!Memory.OffsetImm) return true;
1254 int64_t Val = Memory.OffsetImm->getValue();
1255 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1257 bool isMemThumbRIs2() const {
1258 if (!isMem() || Memory.OffsetRegNum != 0 ||
1259 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1261 // Immediate offset, multiple of 4 in range [0, 62].
1262 if (!Memory.OffsetImm) return true;
1263 int64_t Val = Memory.OffsetImm->getValue();
1264 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1266 bool isMemThumbRIs1() const {
1267 if (!isMem() || Memory.OffsetRegNum != 0 ||
1268 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
1270 // Immediate offset in range [0, 31].
1271 if (!Memory.OffsetImm) return true;
1272 int64_t Val = Memory.OffsetImm->getValue();
1273 return Val >= 0 && Val <= 31;
1275 bool isMemThumbSPI() const {
1276 if (!isMem() || Memory.OffsetRegNum != 0 ||
1277 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
1279 // Immediate offset, multiple of 4 in range [0, 1020].
1280 if (!Memory.OffsetImm) return true;
1281 int64_t Val = Memory.OffsetImm->getValue();
1282 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
1284 bool isMemImm8s4Offset() const {
1285 // If we have an immediate that's not a constant, treat it as a label
1286 // reference needing a fixup. If it is a constant, it's something else
1287 // and we reject it.
1288 if (isImm() && !isa<MCConstantExpr>(getImm()))
1290 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1292 // Immediate offset a multiple of 4 in range [-1020, 1020].
1293 if (!Memory.OffsetImm) return true;
1294 int64_t Val = Memory.OffsetImm->getValue();
1295 // Special case, #-0 is INT32_MIN.
1296 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
1298 bool isMemImm0_1020s4Offset() const {
1299 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1301 // Immediate offset a multiple of 4 in range [0, 1020].
1302 if (!Memory.OffsetImm) return true;
1303 int64_t Val = Memory.OffsetImm->getValue();
1304 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1306 bool isMemImm8Offset() const {
1307 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1309 // Base reg of PC isn't allowed for these encodings.
1310 if (Memory.BaseRegNum == ARM::PC) return false;
1311 // Immediate offset in range [-255, 255].
1312 if (!Memory.OffsetImm) return true;
1313 int64_t Val = Memory.OffsetImm->getValue();
1314 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
1316 bool isMemPosImm8Offset() const {
1317 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1319 // Immediate offset in range [0, 255].
1320 if (!Memory.OffsetImm) return true;
1321 int64_t Val = Memory.OffsetImm->getValue();
1322 return Val >= 0 && Val < 256;
1324 bool isMemNegImm8Offset() const {
1325 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1327 // Base reg of PC isn't allowed for these encodings.
1328 if (Memory.BaseRegNum == ARM::PC) return false;
1329 // Immediate offset in range [-255, -1].
1330 if (!Memory.OffsetImm) return false;
1331 int64_t Val = Memory.OffsetImm->getValue();
1332 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
1334 bool isMemUImm12Offset() const {
1335 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1337 // Immediate offset in range [0, 4095].
1338 if (!Memory.OffsetImm) return true;
1339 int64_t Val = Memory.OffsetImm->getValue();
1340 return (Val >= 0 && Val < 4096);
1342 bool isMemImm12Offset() const {
1343 // If we have an immediate that's not a constant, treat it as a label
1344 // reference needing a fixup. If it is a constant, it's something else
1345 // and we reject it.
1346 if (isImm() && !isa<MCConstantExpr>(getImm()))
1349 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
1351 // Immediate offset in range [-4095, 4095].
1352 if (!Memory.OffsetImm) return true;
1353 int64_t Val = Memory.OffsetImm->getValue();
1354 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1356 bool isPostIdxImm8() const {
1357 if (!isImm()) return false;
1358 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1359 if (!CE) return false;
1360 int64_t Val = CE->getValue();
1361 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
1363 bool isPostIdxImm8s4() const {
1364 if (!isImm()) return false;
1365 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1366 if (!CE) return false;
1367 int64_t Val = CE->getValue();
1368 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1372 bool isMSRMask() const { return Kind == k_MSRMask; }
1373 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
1376 bool isSingleSpacedVectorList() const {
1377 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1379 bool isDoubleSpacedVectorList() const {
1380 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1382 bool isVecListOneD() const {
1383 if (!isSingleSpacedVectorList()) return false;
1384 return VectorList.Count == 1;
1387 bool isVecListDPair() const {
1388 if (!isSingleSpacedVectorList()) return false;
1389 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1390 .contains(VectorList.RegNum));
1393 bool isVecListThreeD() const {
1394 if (!isSingleSpacedVectorList()) return false;
1395 return VectorList.Count == 3;
1398 bool isVecListFourD() const {
1399 if (!isSingleSpacedVectorList()) return false;
1400 return VectorList.Count == 4;
1403 bool isVecListDPairSpaced() const {
1404 if (isSingleSpacedVectorList()) return false;
1405 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1406 .contains(VectorList.RegNum));
1409 bool isVecListThreeQ() const {
1410 if (!isDoubleSpacedVectorList()) return false;
1411 return VectorList.Count == 3;
1414 bool isVecListFourQ() const {
1415 if (!isDoubleSpacedVectorList()) return false;
1416 return VectorList.Count == 4;
1419 bool isSingleSpacedVectorAllLanes() const {
1420 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1422 bool isDoubleSpacedVectorAllLanes() const {
1423 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1425 bool isVecListOneDAllLanes() const {
1426 if (!isSingleSpacedVectorAllLanes()) return false;
1427 return VectorList.Count == 1;
1430 bool isVecListDPairAllLanes() const {
1431 if (!isSingleSpacedVectorAllLanes()) return false;
1432 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1433 .contains(VectorList.RegNum));
1436 bool isVecListDPairSpacedAllLanes() const {
1437 if (!isDoubleSpacedVectorAllLanes()) return false;
1438 return VectorList.Count == 2;
1441 bool isVecListThreeDAllLanes() const {
1442 if (!isSingleSpacedVectorAllLanes()) return false;
1443 return VectorList.Count == 3;
1446 bool isVecListThreeQAllLanes() const {
1447 if (!isDoubleSpacedVectorAllLanes()) return false;
1448 return VectorList.Count == 3;
1451 bool isVecListFourDAllLanes() const {
1452 if (!isSingleSpacedVectorAllLanes()) return false;
1453 return VectorList.Count == 4;
1456 bool isVecListFourQAllLanes() const {
1457 if (!isDoubleSpacedVectorAllLanes()) return false;
1458 return VectorList.Count == 4;
1461 bool isSingleSpacedVectorIndexed() const {
1462 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1464 bool isDoubleSpacedVectorIndexed() const {
1465 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1467 bool isVecListOneDByteIndexed() const {
1468 if (!isSingleSpacedVectorIndexed()) return false;
1469 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1472 bool isVecListOneDHWordIndexed() const {
1473 if (!isSingleSpacedVectorIndexed()) return false;
1474 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1477 bool isVecListOneDWordIndexed() const {
1478 if (!isSingleSpacedVectorIndexed()) return false;
1479 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1482 bool isVecListTwoDByteIndexed() const {
1483 if (!isSingleSpacedVectorIndexed()) return false;
1484 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1487 bool isVecListTwoDHWordIndexed() const {
1488 if (!isSingleSpacedVectorIndexed()) return false;
1489 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1492 bool isVecListTwoQWordIndexed() const {
1493 if (!isDoubleSpacedVectorIndexed()) return false;
1494 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1497 bool isVecListTwoQHWordIndexed() const {
1498 if (!isDoubleSpacedVectorIndexed()) return false;
1499 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1502 bool isVecListTwoDWordIndexed() const {
1503 if (!isSingleSpacedVectorIndexed()) return false;
1504 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1507 bool isVecListThreeDByteIndexed() const {
1508 if (!isSingleSpacedVectorIndexed()) return false;
1509 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1512 bool isVecListThreeDHWordIndexed() const {
1513 if (!isSingleSpacedVectorIndexed()) return false;
1514 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1517 bool isVecListThreeQWordIndexed() const {
1518 if (!isDoubleSpacedVectorIndexed()) return false;
1519 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1522 bool isVecListThreeQHWordIndexed() const {
1523 if (!isDoubleSpacedVectorIndexed()) return false;
1524 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1527 bool isVecListThreeDWordIndexed() const {
1528 if (!isSingleSpacedVectorIndexed()) return false;
1529 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1532 bool isVecListFourDByteIndexed() const {
1533 if (!isSingleSpacedVectorIndexed()) return false;
1534 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1537 bool isVecListFourDHWordIndexed() const {
1538 if (!isSingleSpacedVectorIndexed()) return false;
1539 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1542 bool isVecListFourQWordIndexed() const {
1543 if (!isDoubleSpacedVectorIndexed()) return false;
1544 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1547 bool isVecListFourQHWordIndexed() const {
1548 if (!isDoubleSpacedVectorIndexed()) return false;
1549 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1552 bool isVecListFourDWordIndexed() const {
1553 if (!isSingleSpacedVectorIndexed()) return false;
1554 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1557 bool isVectorIndex8() const {
1558 if (Kind != k_VectorIndex) return false;
1559 return VectorIndex.Val < 8;
1561 bool isVectorIndex16() const {
1562 if (Kind != k_VectorIndex) return false;
1563 return VectorIndex.Val < 4;
1565 bool isVectorIndex32() const {
1566 if (Kind != k_VectorIndex) return false;
1567 return VectorIndex.Val < 2;
1570 bool isNEONi8splat() const {
1571 if (!isImm()) return false;
1572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1573 // Must be a constant.
1574 if (!CE) return false;
1575 int64_t Value = CE->getValue();
1576 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1578 return Value >= 0 && Value < 256;
1581 bool isNEONi16splat() const {
1582 if (!isImm()) return false;
1583 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1584 // Must be a constant.
1585 if (!CE) return false;
1586 int64_t Value = CE->getValue();
1587 // i16 value in the range [0,255] or [0x0100, 0xff00]
1588 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1591 bool isNEONi32splat() const {
1592 if (!isImm()) return false;
1593 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1594 // Must be a constant.
1595 if (!CE) return false;
1596 int64_t Value = CE->getValue();
1597 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1598 return (Value >= 0 && Value < 256) ||
1599 (Value >= 0x0100 && Value <= 0xff00) ||
1600 (Value >= 0x010000 && Value <= 0xff0000) ||
1601 (Value >= 0x01000000 && Value <= 0xff000000);
1604 bool isNEONi32vmov() const {
1605 if (!isImm()) return false;
1606 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1607 // Must be a constant.
1608 if (!CE) return false;
1609 int64_t Value = CE->getValue();
1610 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1611 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1612 return (Value >= 0 && Value < 256) ||
1613 (Value >= 0x0100 && Value <= 0xff00) ||
1614 (Value >= 0x010000 && Value <= 0xff0000) ||
1615 (Value >= 0x01000000 && Value <= 0xff000000) ||
1616 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1617 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1619 bool isNEONi32vmovNeg() const {
1620 if (!isImm()) return false;
1621 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1622 // Must be a constant.
1623 if (!CE) return false;
1624 int64_t Value = ~CE->getValue();
1625 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1626 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1627 return (Value >= 0 && Value < 256) ||
1628 (Value >= 0x0100 && Value <= 0xff00) ||
1629 (Value >= 0x010000 && Value <= 0xff0000) ||
1630 (Value >= 0x01000000 && Value <= 0xff000000) ||
1631 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1632 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1635 bool isNEONi64splat() const {
1636 if (!isImm()) return false;
1637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1638 // Must be a constant.
1639 if (!CE) return false;
1640 uint64_t Value = CE->getValue();
1641 // i64 value with each byte being either 0 or 0xff.
1642 for (unsigned i = 0; i < 8; ++i)
1643 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1647 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
1648 // Add as immediates when possible. Null MCExpr = 0.
1650 Inst.addOperand(MCOperand::CreateImm(0));
1651 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
1652 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1654 Inst.addOperand(MCOperand::CreateExpr(Expr));
1657 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
1658 assert(N == 2 && "Invalid number of operands!");
1659 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1660 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1661 Inst.addOperand(MCOperand::CreateReg(RegNum));
1664 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1665 assert(N == 1 && "Invalid number of operands!");
1666 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1669 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1670 assert(N == 1 && "Invalid number of operands!");
1671 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1674 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1675 assert(N == 1 && "Invalid number of operands!");
1676 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1679 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1680 assert(N == 1 && "Invalid number of operands!");
1681 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1684 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1685 assert(N == 1 && "Invalid number of operands!");
1686 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1689 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1690 assert(N == 1 && "Invalid number of operands!");
1691 Inst.addOperand(MCOperand::CreateReg(getReg()));
1694 void addRegOperands(MCInst &Inst, unsigned N) const {
1695 assert(N == 1 && "Invalid number of operands!");
1696 Inst.addOperand(MCOperand::CreateReg(getReg()));
1699 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
1700 assert(N == 3 && "Invalid number of operands!");
1701 assert(isRegShiftedReg() &&
1702 "addRegShiftedRegOperands() on non-RegShiftedReg!");
1703 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1704 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
1705 Inst.addOperand(MCOperand::CreateImm(
1706 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
1709 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
1710 assert(N == 2 && "Invalid number of operands!");
1711 assert(isRegShiftedImm() &&
1712 "addRegShiftedImmOperands() on non-RegShiftedImm!");
1713 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
1714 // Shift of #32 is encoded as 0 where permitted
1715 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
1716 Inst.addOperand(MCOperand::CreateImm(
1717 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
1720 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
1721 assert(N == 1 && "Invalid number of operands!");
1722 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1726 void addRegListOperands(MCInst &Inst, unsigned N) const {
1727 assert(N == 1 && "Invalid number of operands!");
1728 const SmallVectorImpl<unsigned> &RegList = getRegList();
1729 for (SmallVectorImpl<unsigned>::const_iterator
1730 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1731 Inst.addOperand(MCOperand::CreateReg(*I));
1734 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1735 addRegListOperands(Inst, N);
1738 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1739 addRegListOperands(Inst, N);
1742 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
1744 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1745 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1748 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1749 assert(N == 1 && "Invalid number of operands!");
1750 // Munge the lsb/width into a bitfield mask.
1751 unsigned lsb = Bitfield.LSB;
1752 unsigned width = Bitfield.Width;
1753 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1754 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1755 (32 - (lsb + width)));
1756 Inst.addOperand(MCOperand::CreateImm(Mask));
1759 void addImmOperands(MCInst &Inst, unsigned N) const {
1760 assert(N == 1 && "Invalid number of operands!");
1761 addExpr(Inst, getImm());
1764 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1765 assert(N == 1 && "Invalid number of operands!");
1766 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1767 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1770 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1771 assert(N == 1 && "Invalid number of operands!");
1772 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1773 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1776 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1777 assert(N == 1 && "Invalid number of operands!");
1778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1779 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1780 Inst.addOperand(MCOperand::CreateImm(Val));
1783 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1784 assert(N == 1 && "Invalid number of operands!");
1785 // FIXME: We really want to scale the value here, but the LDRD/STRD
1786 // instruction don't encode operands that way yet.
1787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1788 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1791 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1792 assert(N == 1 && "Invalid number of operands!");
1793 // The immediate is scaled by four in the encoding and is stored
1794 // in the MCInst as such. Lop off the low two bits here.
1795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1796 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1799 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 1 && "Invalid number of operands!");
1801 // The immediate is scaled by four in the encoding and is stored
1802 // in the MCInst as such. Lop off the low two bits here.
1803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1804 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1807 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1808 assert(N == 1 && "Invalid number of operands!");
1809 // The immediate is scaled by four in the encoding and is stored
1810 // in the MCInst as such. Lop off the low two bits here.
1811 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1812 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1815 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1816 assert(N == 1 && "Invalid number of operands!");
1817 // The constant encodes as the immediate-1, and we store in the instruction
1818 // the bits as encoded, so subtract off one here.
1819 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1820 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1823 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1824 assert(N == 1 && "Invalid number of operands!");
1825 // The constant encodes as the immediate-1, and we store in the instruction
1826 // the bits as encoded, so subtract off one here.
1827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1828 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1831 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1832 assert(N == 1 && "Invalid number of operands!");
1833 // The constant encodes as the immediate, except for 32, which encodes as
1835 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1836 unsigned Imm = CE->getValue();
1837 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1840 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1841 assert(N == 1 && "Invalid number of operands!");
1842 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1843 // the instruction as well.
1844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1845 int Val = CE->getValue();
1846 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1849 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1850 assert(N == 1 && "Invalid number of operands!");
1851 // The operand is actually a t2_so_imm, but we have its bitwise
1852 // negation in the assembly source, so twiddle it here.
1853 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1854 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1857 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1858 assert(N == 1 && "Invalid number of operands!");
1859 // The operand is actually a t2_so_imm, but we have its
1860 // negation in the assembly source, so twiddle it here.
1861 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1862 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1865 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1866 assert(N == 1 && "Invalid number of operands!");
1867 // The operand is actually an imm0_4095, but we have its
1868 // negation in the assembly source, so twiddle it here.
1869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1870 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1873 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1874 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1875 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1879 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1880 assert(SR && "Unknown value type!");
1881 Inst.addOperand(MCOperand::CreateExpr(SR));
1884 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1885 assert(N == 1 && "Invalid number of operands!");
1887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1889 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1893 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1894 assert(SR && "Unknown value type!");
1895 Inst.addOperand(MCOperand::CreateExpr(SR));
1899 assert(isMem() && "Unknown value type!");
1900 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1901 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1904 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1905 assert(N == 1 && "Invalid number of operands!");
1906 // The operand is actually a so_imm, but we have its bitwise
1907 // negation in the assembly source, so twiddle it here.
1908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1909 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1912 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1913 assert(N == 1 && "Invalid number of operands!");
1914 // The operand is actually a so_imm, but we have its
1915 // negation in the assembly source, so twiddle it here.
1916 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1917 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1920 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1921 assert(N == 1 && "Invalid number of operands!");
1922 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1925 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1926 assert(N == 1 && "Invalid number of operands!");
1927 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1930 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1931 assert(N == 1 && "Invalid number of operands!");
1932 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1935 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1936 assert(N == 1 && "Invalid number of operands!");
1937 int32_t Imm = Memory.OffsetImm->getValue();
1938 Inst.addOperand(MCOperand::CreateImm(Imm));
1941 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1942 assert(N == 1 && "Invalid number of operands!");
1943 assert(isImm() && "Not an immediate!");
1945 // If we have an immediate that's not a constant, treat it as a label
1946 // reference needing a fixup.
1947 if (!isa<MCConstantExpr>(getImm())) {
1948 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1953 int Val = CE->getValue();
1954 Inst.addOperand(MCOperand::CreateImm(Val));
1957 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 2 && "Invalid number of operands!");
1959 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1960 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1963 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1964 assert(N == 3 && "Invalid number of operands!");
1965 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1966 if (!Memory.OffsetRegNum) {
1967 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1968 // Special case for #-0
1969 if (Val == INT32_MIN) Val = 0;
1970 if (Val < 0) Val = -Val;
1971 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1973 // For register offset, we encode the shift type and negation flag
1975 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1976 Memory.ShiftImm, Memory.ShiftType);
1978 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1979 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1980 Inst.addOperand(MCOperand::CreateImm(Val));
1983 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1984 assert(N == 2 && "Invalid number of operands!");
1985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1986 assert(CE && "non-constant AM2OffsetImm operand!");
1987 int32_t Val = CE->getValue();
1988 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1989 // Special case for #-0
1990 if (Val == INT32_MIN) Val = 0;
1991 if (Val < 0) Val = -Val;
1992 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1993 Inst.addOperand(MCOperand::CreateReg(0));
1994 Inst.addOperand(MCOperand::CreateImm(Val));
1997 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1998 assert(N == 3 && "Invalid number of operands!");
1999 // If we have an immediate that's not a constant, treat it as a label
2000 // reference needing a fixup. If it is a constant, it's something else
2001 // and we reject it.
2003 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2004 Inst.addOperand(MCOperand::CreateReg(0));
2005 Inst.addOperand(MCOperand::CreateImm(0));
2009 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2010 if (!Memory.OffsetRegNum) {
2011 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2012 // Special case for #-0
2013 if (Val == INT32_MIN) Val = 0;
2014 if (Val < 0) Val = -Val;
2015 Val = ARM_AM::getAM3Opc(AddSub, Val);
2017 // For register offset, we encode the shift type and negation flag
2019 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
2021 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2022 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2023 Inst.addOperand(MCOperand::CreateImm(Val));
2026 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2027 assert(N == 2 && "Invalid number of operands!");
2028 if (Kind == k_PostIndexRegister) {
2030 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2031 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2032 Inst.addOperand(MCOperand::CreateImm(Val));
2037 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2038 int32_t Val = CE->getValue();
2039 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2040 // Special case for #-0
2041 if (Val == INT32_MIN) Val = 0;
2042 if (Val < 0) Val = -Val;
2043 Val = ARM_AM::getAM3Opc(AddSub, Val);
2044 Inst.addOperand(MCOperand::CreateReg(0));
2045 Inst.addOperand(MCOperand::CreateImm(Val));
2048 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2049 assert(N == 2 && "Invalid number of operands!");
2050 // If we have an immediate that's not a constant, treat it as a label
2051 // reference needing a fixup. If it is a constant, it's something else
2052 // and we reject it.
2054 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2055 Inst.addOperand(MCOperand::CreateImm(0));
2059 // The lower two bits are always zero and as such are not encoded.
2060 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2061 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2062 // Special case for #-0
2063 if (Val == INT32_MIN) Val = 0;
2064 if (Val < 0) Val = -Val;
2065 Val = ARM_AM::getAM5Opc(AddSub, Val);
2066 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2067 Inst.addOperand(MCOperand::CreateImm(Val));
2070 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2071 assert(N == 2 && "Invalid number of operands!");
2072 // If we have an immediate that's not a constant, treat it as a label
2073 // reference needing a fixup. If it is a constant, it's something else
2074 // and we reject it.
2076 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2077 Inst.addOperand(MCOperand::CreateImm(0));
2081 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2082 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2083 Inst.addOperand(MCOperand::CreateImm(Val));
2086 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2087 assert(N == 2 && "Invalid number of operands!");
2088 // The lower two bits are always zero and as such are not encoded.
2089 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2090 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2091 Inst.addOperand(MCOperand::CreateImm(Val));
2094 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2095 assert(N == 2 && "Invalid number of operands!");
2096 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2097 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2098 Inst.addOperand(MCOperand::CreateImm(Val));
2101 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2102 addMemImm8OffsetOperands(Inst, N);
2105 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2106 addMemImm8OffsetOperands(Inst, N);
2109 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2110 assert(N == 2 && "Invalid number of operands!");
2111 // If this is an immediate, it's a label reference.
2113 addExpr(Inst, getImm());
2114 Inst.addOperand(MCOperand::CreateImm(0));
2118 // Otherwise, it's a normal memory reg+offset.
2119 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2120 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2121 Inst.addOperand(MCOperand::CreateImm(Val));
2124 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2125 assert(N == 2 && "Invalid number of operands!");
2126 // If this is an immediate, it's a label reference.
2128 addExpr(Inst, getImm());
2129 Inst.addOperand(MCOperand::CreateImm(0));
2133 // Otherwise, it's a normal memory reg+offset.
2134 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2135 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2136 Inst.addOperand(MCOperand::CreateImm(Val));
2139 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2140 assert(N == 2 && "Invalid number of operands!");
2141 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2142 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2145 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2146 assert(N == 2 && "Invalid number of operands!");
2147 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2148 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2151 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2152 assert(N == 3 && "Invalid number of operands!");
2154 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2155 Memory.ShiftImm, Memory.ShiftType);
2156 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2157 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2158 Inst.addOperand(MCOperand::CreateImm(Val));
2161 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2162 assert(N == 3 && "Invalid number of operands!");
2163 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2164 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2165 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
2168 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2169 assert(N == 2 && "Invalid number of operands!");
2170 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2171 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2174 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2175 assert(N == 2 && "Invalid number of operands!");
2176 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2177 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2178 Inst.addOperand(MCOperand::CreateImm(Val));
2181 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2182 assert(N == 2 && "Invalid number of operands!");
2183 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2184 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2185 Inst.addOperand(MCOperand::CreateImm(Val));
2188 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2189 assert(N == 2 && "Invalid number of operands!");
2190 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2191 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2192 Inst.addOperand(MCOperand::CreateImm(Val));
2195 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2196 assert(N == 2 && "Invalid number of operands!");
2197 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2198 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2199 Inst.addOperand(MCOperand::CreateImm(Val));
2202 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2203 assert(N == 1 && "Invalid number of operands!");
2204 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2205 assert(CE && "non-constant post-idx-imm8 operand!");
2206 int Imm = CE->getValue();
2207 bool isAdd = Imm >= 0;
2208 if (Imm == INT32_MIN) Imm = 0;
2209 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2210 Inst.addOperand(MCOperand::CreateImm(Imm));
2213 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2214 assert(N == 1 && "Invalid number of operands!");
2215 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2216 assert(CE && "non-constant post-idx-imm8s4 operand!");
2217 int Imm = CE->getValue();
2218 bool isAdd = Imm >= 0;
2219 if (Imm == INT32_MIN) Imm = 0;
2220 // Immediate is scaled by 4.
2221 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2222 Inst.addOperand(MCOperand::CreateImm(Imm));
2225 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2226 assert(N == 2 && "Invalid number of operands!");
2227 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2228 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2231 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2232 assert(N == 2 && "Invalid number of operands!");
2233 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2234 // The sign, shift type, and shift amount are encoded in a single operand
2235 // using the AM2 encoding helpers.
2236 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2237 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2238 PostIdxReg.ShiftTy);
2239 Inst.addOperand(MCOperand::CreateImm(Imm));
2242 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2243 assert(N == 1 && "Invalid number of operands!");
2244 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2247 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2248 assert(N == 1 && "Invalid number of operands!");
2249 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2252 void addVecListOperands(MCInst &Inst, unsigned N) const {
2253 assert(N == 1 && "Invalid number of operands!");
2254 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2257 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2258 assert(N == 2 && "Invalid number of operands!");
2259 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2260 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2263 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2264 assert(N == 1 && "Invalid number of operands!");
2265 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2268 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2269 assert(N == 1 && "Invalid number of operands!");
2270 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2273 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2274 assert(N == 1 && "Invalid number of operands!");
2275 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2278 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2279 assert(N == 1 && "Invalid number of operands!");
2280 // The immediate encodes the type of constant as well as the value.
2281 // Mask in that this is an i8 splat.
2282 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2283 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2286 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2287 assert(N == 1 && "Invalid number of operands!");
2288 // The immediate encodes the type of constant as well as the value.
2289 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2290 unsigned Value = CE->getValue();
2292 Value = (Value >> 8) | 0xa00;
2295 Inst.addOperand(MCOperand::CreateImm(Value));
2298 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2299 assert(N == 1 && "Invalid number of operands!");
2300 // The immediate encodes the type of constant as well as the value.
2301 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2302 unsigned Value = CE->getValue();
2303 if (Value >= 256 && Value <= 0xff00)
2304 Value = (Value >> 8) | 0x200;
2305 else if (Value > 0xffff && Value <= 0xff0000)
2306 Value = (Value >> 16) | 0x400;
2307 else if (Value > 0xffffff)
2308 Value = (Value >> 24) | 0x600;
2309 Inst.addOperand(MCOperand::CreateImm(Value));
2312 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2313 assert(N == 1 && "Invalid number of operands!");
2314 // The immediate encodes the type of constant as well as the value.
2315 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2316 unsigned Value = CE->getValue();
2317 if (Value >= 256 && Value <= 0xffff)
2318 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2319 else if (Value > 0xffff && Value <= 0xffffff)
2320 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2321 else if (Value > 0xffffff)
2322 Value = (Value >> 24) | 0x600;
2323 Inst.addOperand(MCOperand::CreateImm(Value));
2326 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2327 assert(N == 1 && "Invalid number of operands!");
2328 // The immediate encodes the type of constant as well as the value.
2329 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2330 unsigned Value = ~CE->getValue();
2331 if (Value >= 256 && Value <= 0xffff)
2332 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2333 else if (Value > 0xffff && Value <= 0xffffff)
2334 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2335 else if (Value > 0xffffff)
2336 Value = (Value >> 24) | 0x600;
2337 Inst.addOperand(MCOperand::CreateImm(Value));
2340 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2341 assert(N == 1 && "Invalid number of operands!");
2342 // The immediate encodes the type of constant as well as the value.
2343 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2344 uint64_t Value = CE->getValue();
2346 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2347 Imm |= (Value & 1) << i;
2349 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2352 virtual void print(raw_ostream &OS) const;
2354 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
2355 ARMOperand *Op = new ARMOperand(k_ITCondMask);
2356 Op->ITMask.Mask = Mask;
2362 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
2363 ARMOperand *Op = new ARMOperand(k_CondCode);
2370 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
2371 ARMOperand *Op = new ARMOperand(k_CoprocNum);
2372 Op->Cop.Val = CopVal;
2378 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
2379 ARMOperand *Op = new ARMOperand(k_CoprocReg);
2380 Op->Cop.Val = CopVal;
2386 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2387 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2394 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
2395 ARMOperand *Op = new ARMOperand(k_CCOut);
2396 Op->Reg.RegNum = RegNum;
2402 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
2403 ARMOperand *Op = new ARMOperand(k_Token);
2404 Op->Tok.Data = Str.data();
2405 Op->Tok.Length = Str.size();
2411 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
2412 ARMOperand *Op = new ARMOperand(k_Register);
2413 Op->Reg.RegNum = RegNum;
2419 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2424 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
2425 Op->RegShiftedReg.ShiftTy = ShTy;
2426 Op->RegShiftedReg.SrcReg = SrcReg;
2427 Op->RegShiftedReg.ShiftReg = ShiftReg;
2428 Op->RegShiftedReg.ShiftImm = ShiftImm;
2434 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2438 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
2439 Op->RegShiftedImm.ShiftTy = ShTy;
2440 Op->RegShiftedImm.SrcReg = SrcReg;
2441 Op->RegShiftedImm.ShiftImm = ShiftImm;
2447 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
2449 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
2450 Op->ShifterImm.isASR = isASR;
2451 Op->ShifterImm.Imm = Imm;
2457 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
2458 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
2459 Op->RotImm.Imm = Imm;
2465 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2467 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
2468 Op->Bitfield.LSB = LSB;
2469 Op->Bitfield.Width = Width;
2476 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
2477 SMLoc StartLoc, SMLoc EndLoc) {
2478 assert (Regs.size() > 0 && "RegList contains no registers?");
2479 KindTy Kind = k_RegisterList;
2481 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
2482 Kind = k_DPRRegisterList;
2483 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
2484 contains(Regs.front().second))
2485 Kind = k_SPRRegisterList;
2487 // Sort based on the register encoding values.
2488 array_pod_sort(Regs.begin(), Regs.end());
2490 ARMOperand *Op = new ARMOperand(Kind);
2491 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
2492 I = Regs.begin(), E = Regs.end(); I != E; ++I)
2493 Op->Registers.push_back(I->second);
2494 Op->StartLoc = StartLoc;
2495 Op->EndLoc = EndLoc;
2499 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
2500 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2501 ARMOperand *Op = new ARMOperand(k_VectorList);
2502 Op->VectorList.RegNum = RegNum;
2503 Op->VectorList.Count = Count;
2504 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2510 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
2511 bool isDoubleSpaced,
2513 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2514 Op->VectorList.RegNum = RegNum;
2515 Op->VectorList.Count = Count;
2516 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2522 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
2524 bool isDoubleSpaced,
2526 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2527 Op->VectorList.RegNum = RegNum;
2528 Op->VectorList.Count = Count;
2529 Op->VectorList.LaneIndex = Index;
2530 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
2536 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2538 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2539 Op->VectorIndex.Val = Idx;
2545 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
2546 ARMOperand *Op = new ARMOperand(k_Immediate);
2553 static ARMOperand *CreateMem(unsigned BaseRegNum,
2554 const MCConstantExpr *OffsetImm,
2555 unsigned OffsetRegNum,
2556 ARM_AM::ShiftOpc ShiftType,
2561 ARMOperand *Op = new ARMOperand(k_Memory);
2562 Op->Memory.BaseRegNum = BaseRegNum;
2563 Op->Memory.OffsetImm = OffsetImm;
2564 Op->Memory.OffsetRegNum = OffsetRegNum;
2565 Op->Memory.ShiftType = ShiftType;
2566 Op->Memory.ShiftImm = ShiftImm;
2567 Op->Memory.Alignment = Alignment;
2568 Op->Memory.isNegative = isNegative;
2574 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2575 ARM_AM::ShiftOpc ShiftTy,
2578 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
2579 Op->PostIdxReg.RegNum = RegNum;
2580 Op->PostIdxReg.isAdd = isAdd;
2581 Op->PostIdxReg.ShiftTy = ShiftTy;
2582 Op->PostIdxReg.ShiftImm = ShiftImm;
2588 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
2589 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
2590 Op->MBOpt.Val = Opt;
2596 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2598 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2599 Op->ISBOpt.Val = Opt;
2605 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
2606 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
2607 Op->IFlags.Val = IFlags;
2613 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
2614 ARMOperand *Op = new ARMOperand(k_MSRMask);
2615 Op->MMask.Val = MMask;
2622 } // end anonymous namespace.
2624 void ARMOperand::print(raw_ostream &OS) const {
2627 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
2630 OS << "<ccout " << getReg() << ">";
2632 case k_ITCondMask: {
2633 static const char *const MaskStr[] = {
2634 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2635 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2637 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2638 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2642 OS << "<coprocessor number: " << getCoproc() << ">";
2645 OS << "<coprocessor register: " << getCoproc() << ">";
2647 case k_CoprocOption:
2648 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2651 OS << "<mask: " << getMSRMask() << ">";
2654 getImm()->print(OS);
2656 case k_MemBarrierOpt:
2657 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
2659 case k_InstSyncBarrierOpt:
2660 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2664 << " base:" << Memory.BaseRegNum;
2667 case k_PostIndexRegister:
2668 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2669 << PostIdxReg.RegNum;
2670 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2671 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2672 << PostIdxReg.ShiftImm;
2675 case k_ProcIFlags: {
2676 OS << "<ARM_PROC::";
2677 unsigned IFlags = getProcIFlags();
2678 for (int i=2; i >= 0; --i)
2679 if (IFlags & (1 << i))
2680 OS << ARM_PROC::IFlagsToString(1 << i);
2685 OS << "<register " << getReg() << ">";
2687 case k_ShifterImmediate:
2688 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2689 << " #" << ShifterImm.Imm << ">";
2691 case k_ShiftedRegister:
2692 OS << "<so_reg_reg "
2693 << RegShiftedReg.SrcReg << " "
2694 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2695 << " " << RegShiftedReg.ShiftReg << ">";
2697 case k_ShiftedImmediate:
2698 OS << "<so_reg_imm "
2699 << RegShiftedImm.SrcReg << " "
2700 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2701 << " #" << RegShiftedImm.ShiftImm << ">";
2703 case k_RotateImmediate:
2704 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2706 case k_BitfieldDescriptor:
2707 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2708 << ", width: " << Bitfield.Width << ">";
2710 case k_RegisterList:
2711 case k_DPRRegisterList:
2712 case k_SPRRegisterList: {
2713 OS << "<register_list ";
2715 const SmallVectorImpl<unsigned> &RegList = getRegList();
2716 for (SmallVectorImpl<unsigned>::const_iterator
2717 I = RegList.begin(), E = RegList.end(); I != E; ) {
2719 if (++I < E) OS << ", ";
2726 OS << "<vector_list " << VectorList.Count << " * "
2727 << VectorList.RegNum << ">";
2729 case k_VectorListAllLanes:
2730 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2731 << VectorList.RegNum << ">";
2733 case k_VectorListIndexed:
2734 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2735 << VectorList.Count << " * " << VectorList.RegNum << ">";
2738 OS << "'" << getToken() << "'";
2741 OS << "<vectorindex " << getVectorIndex() << ">";
2746 /// @name Auto-generated Match Functions
2749 static unsigned MatchRegisterName(StringRef Name);
2753 bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2754 SMLoc &StartLoc, SMLoc &EndLoc) {
2755 StartLoc = Parser.getTok().getLoc();
2756 EndLoc = Parser.getTok().getEndLoc();
2757 RegNo = tryParseRegister();
2759 return (RegNo == (unsigned)-1);
2762 /// Try to parse a register name. The token must be an Identifier when called,
2763 /// and if it is a register name the token is eaten and the register number is
2764 /// returned. Otherwise return -1.
2766 int ARMAsmParser::tryParseRegister() {
2767 const AsmToken &Tok = Parser.getTok();
2768 if (Tok.isNot(AsmToken::Identifier)) return -1;
2770 std::string lowerCase = Tok.getString().lower();
2771 unsigned RegNum = MatchRegisterName(lowerCase);
2773 RegNum = StringSwitch<unsigned>(lowerCase)
2774 .Case("r13", ARM::SP)
2775 .Case("r14", ARM::LR)
2776 .Case("r15", ARM::PC)
2777 .Case("ip", ARM::R12)
2778 // Additional register name aliases for 'gas' compatibility.
2779 .Case("a1", ARM::R0)
2780 .Case("a2", ARM::R1)
2781 .Case("a3", ARM::R2)
2782 .Case("a4", ARM::R3)
2783 .Case("v1", ARM::R4)
2784 .Case("v2", ARM::R5)
2785 .Case("v3", ARM::R6)
2786 .Case("v4", ARM::R7)
2787 .Case("v5", ARM::R8)
2788 .Case("v6", ARM::R9)
2789 .Case("v7", ARM::R10)
2790 .Case("v8", ARM::R11)
2791 .Case("sb", ARM::R9)
2792 .Case("sl", ARM::R10)
2793 .Case("fp", ARM::R11)
2797 // Check for aliases registered via .req. Canonicalize to lower case.
2798 // That's more consistent since register names are case insensitive, and
2799 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2800 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
2801 // If no match, return failure.
2802 if (Entry == RegisterReqs.end())
2804 Parser.Lex(); // Eat identifier token.
2805 return Entry->getValue();
2808 Parser.Lex(); // Eat identifier token.
2813 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2814 // If a recoverable error occurs, return 1. If an irrecoverable error
2815 // occurs, return -1. An irrecoverable error is one where tokens have been
2816 // consumed in the process of trying to parse the shifter (i.e., when it is
2817 // indeed a shifter operand, but malformed).
2818 int ARMAsmParser::tryParseShiftRegister(
2819 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2820 SMLoc S = Parser.getTok().getLoc();
2821 const AsmToken &Tok = Parser.getTok();
2822 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2824 std::string lowerCase = Tok.getString().lower();
2825 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
2826 .Case("asl", ARM_AM::lsl)
2827 .Case("lsl", ARM_AM::lsl)
2828 .Case("lsr", ARM_AM::lsr)
2829 .Case("asr", ARM_AM::asr)
2830 .Case("ror", ARM_AM::ror)
2831 .Case("rrx", ARM_AM::rrx)
2832 .Default(ARM_AM::no_shift);
2834 if (ShiftTy == ARM_AM::no_shift)
2837 Parser.Lex(); // Eat the operator.
2839 // The source register for the shift has already been added to the
2840 // operand list, so we need to pop it off and combine it into the shifted
2841 // register operand instead.
2842 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
2843 if (!PrevOp->isReg())
2844 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2845 int SrcReg = PrevOp->getReg();
2850 if (ShiftTy == ARM_AM::rrx) {
2851 // RRX Doesn't have an explicit shift amount. The encoder expects
2852 // the shift register to be the same as the source register. Seems odd,
2856 // Figure out if this is shifted by a constant or a register (for non-RRX).
2857 if (Parser.getTok().is(AsmToken::Hash) ||
2858 Parser.getTok().is(AsmToken::Dollar)) {
2859 Parser.Lex(); // Eat hash.
2860 SMLoc ImmLoc = Parser.getTok().getLoc();
2861 const MCExpr *ShiftExpr = 0;
2862 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
2863 Error(ImmLoc, "invalid immediate shift value");
2866 // The expression must be evaluatable as an immediate.
2867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
2869 Error(ImmLoc, "invalid immediate shift value");
2872 // Range check the immediate.
2873 // lsl, ror: 0 <= imm <= 31
2874 // lsr, asr: 0 <= imm <= 32
2875 Imm = CE->getValue();
2877 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2878 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
2879 Error(ImmLoc, "immediate shift value out of range");
2882 // shift by zero is a nop. Always send it through as lsl.
2883 // ('as' compatibility)
2885 ShiftTy = ARM_AM::lsl;
2886 } else if (Parser.getTok().is(AsmToken::Identifier)) {
2887 SMLoc L = Parser.getTok().getLoc();
2888 EndLoc = Parser.getTok().getEndLoc();
2889 ShiftReg = tryParseRegister();
2890 if (ShiftReg == -1) {
2891 Error (L, "expected immediate or register in shift operand");
2895 Error (Parser.getTok().getLoc(),
2896 "expected immediate or register in shift operand");
2901 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2902 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
2906 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2913 /// Try to parse a register name. The token must be an Identifier when called.
2914 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
2915 /// if there is a "writeback". 'true' if it's not a register.
2917 /// TODO this is likely to change to allow different register types and or to
2918 /// parse for a specific register type.
2920 tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2921 const AsmToken &RegTok = Parser.getTok();
2922 int RegNo = tryParseRegister();
2926 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2927 RegTok.getEndLoc()));
2929 const AsmToken &ExclaimTok = Parser.getTok();
2930 if (ExclaimTok.is(AsmToken::Exclaim)) {
2931 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2932 ExclaimTok.getLoc()));
2933 Parser.Lex(); // Eat exclaim token
2937 // Also check for an index operand. This is only legal for vector registers,
2938 // but that'll get caught OK in operand matching, so we don't need to
2939 // explicitly filter everything else out here.
2940 if (Parser.getTok().is(AsmToken::LBrac)) {
2941 SMLoc SIdx = Parser.getTok().getLoc();
2942 Parser.Lex(); // Eat left bracket token.
2944 const MCExpr *ImmVal;
2945 if (getParser().parseExpression(ImmVal))
2947 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
2949 return TokError("immediate value expected for vector index");
2951 if (Parser.getTok().isNot(AsmToken::RBrac))
2952 return Error(Parser.getTok().getLoc(), "']' expected");
2954 SMLoc E = Parser.getTok().getEndLoc();
2955 Parser.Lex(); // Eat right bracket token.
2957 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2965 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
2966 /// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2968 static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
2969 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2971 switch (Name.size()) {
2974 if (Name[0] != CoprocOp)
2990 if (Name[0] != CoprocOp || Name[1] != '1')
2994 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2995 case '0': return CoprocOp == 'p'? -1: 10;
2996 case '1': return CoprocOp == 'p'? -1: 11;
2997 case '2': return 12;
2998 case '3': return 13;
2999 case '4': return 14;
3000 case '5': return 15;
3005 /// parseITCondCode - Try to parse a condition code for an IT instruction.
3006 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3007 parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3008 SMLoc S = Parser.getTok().getLoc();
3009 const AsmToken &Tok = Parser.getTok();
3010 if (!Tok.is(AsmToken::Identifier))
3011 return MatchOperand_NoMatch;
3012 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
3013 .Case("eq", ARMCC::EQ)
3014 .Case("ne", ARMCC::NE)
3015 .Case("hs", ARMCC::HS)
3016 .Case("cs", ARMCC::HS)
3017 .Case("lo", ARMCC::LO)
3018 .Case("cc", ARMCC::LO)
3019 .Case("mi", ARMCC::MI)
3020 .Case("pl", ARMCC::PL)
3021 .Case("vs", ARMCC::VS)
3022 .Case("vc", ARMCC::VC)
3023 .Case("hi", ARMCC::HI)
3024 .Case("ls", ARMCC::LS)
3025 .Case("ge", ARMCC::GE)
3026 .Case("lt", ARMCC::LT)
3027 .Case("gt", ARMCC::GT)
3028 .Case("le", ARMCC::LE)
3029 .Case("al", ARMCC::AL)
3032 return MatchOperand_NoMatch;
3033 Parser.Lex(); // Eat the token.
3035 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3037 return MatchOperand_Success;
3040 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
3041 /// token must be an Identifier when called, and if it is a coprocessor
3042 /// number, the token is eaten and the operand is added to the operand list.
3043 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3044 parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3045 SMLoc S = Parser.getTok().getLoc();
3046 const AsmToken &Tok = Parser.getTok();
3047 if (Tok.isNot(AsmToken::Identifier))
3048 return MatchOperand_NoMatch;
3050 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
3052 return MatchOperand_NoMatch;
3054 Parser.Lex(); // Eat identifier token.
3055 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
3056 return MatchOperand_Success;
3059 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
3060 /// token must be an Identifier when called, and if it is a coprocessor
3061 /// number, the token is eaten and the operand is added to the operand list.
3062 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3063 parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3064 SMLoc S = Parser.getTok().getLoc();
3065 const AsmToken &Tok = Parser.getTok();
3066 if (Tok.isNot(AsmToken::Identifier))
3067 return MatchOperand_NoMatch;
3069 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3071 return MatchOperand_NoMatch;
3073 Parser.Lex(); // Eat identifier token.
3074 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
3075 return MatchOperand_Success;
3078 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3079 /// coproc_option : '{' imm0_255 '}'
3080 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3081 parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3082 SMLoc S = Parser.getTok().getLoc();
3084 // If this isn't a '{', this isn't a coprocessor immediate operand.
3085 if (Parser.getTok().isNot(AsmToken::LCurly))
3086 return MatchOperand_NoMatch;
3087 Parser.Lex(); // Eat the '{'
3090 SMLoc Loc = Parser.getTok().getLoc();
3091 if (getParser().parseExpression(Expr)) {
3092 Error(Loc, "illegal expression");
3093 return MatchOperand_ParseFail;
3095 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3096 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3097 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3098 return MatchOperand_ParseFail;
3100 int Val = CE->getValue();
3102 // Check for and consume the closing '}'
3103 if (Parser.getTok().isNot(AsmToken::RCurly))
3104 return MatchOperand_ParseFail;
3105 SMLoc E = Parser.getTok().getEndLoc();
3106 Parser.Lex(); // Eat the '}'
3108 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3109 return MatchOperand_Success;
3112 // For register list parsing, we need to map from raw GPR register numbering
3113 // to the enumeration values. The enumeration values aren't sorted by
3114 // register number due to our using "sp", "lr" and "pc" as canonical names.
3115 static unsigned getNextRegister(unsigned Reg) {
3116 // If this is a GPR, we need to do it manually, otherwise we can rely
3117 // on the sort ordering of the enumeration since the other reg-classes
3119 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3122 default: llvm_unreachable("Invalid GPR number!");
3123 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3124 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3125 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3126 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3127 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3128 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3129 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3130 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3134 // Return the low-subreg of a given Q register.
3135 static unsigned getDRegFromQReg(unsigned QReg) {
3137 default: llvm_unreachable("expected a Q register!");
3138 case ARM::Q0: return ARM::D0;
3139 case ARM::Q1: return ARM::D2;
3140 case ARM::Q2: return ARM::D4;
3141 case ARM::Q3: return ARM::D6;
3142 case ARM::Q4: return ARM::D8;
3143 case ARM::Q5: return ARM::D10;
3144 case ARM::Q6: return ARM::D12;
3145 case ARM::Q7: return ARM::D14;
3146 case ARM::Q8: return ARM::D16;
3147 case ARM::Q9: return ARM::D18;
3148 case ARM::Q10: return ARM::D20;
3149 case ARM::Q11: return ARM::D22;
3150 case ARM::Q12: return ARM::D24;
3151 case ARM::Q13: return ARM::D26;
3152 case ARM::Q14: return ARM::D28;
3153 case ARM::Q15: return ARM::D30;
3157 /// Parse a register list.
3159 parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3160 assert(Parser.getTok().is(AsmToken::LCurly) &&
3161 "Token is not a Left Curly Brace");
3162 SMLoc S = Parser.getTok().getLoc();
3163 Parser.Lex(); // Eat '{' token.
3164 SMLoc RegLoc = Parser.getTok().getLoc();
3166 // Check the first register in the list to see what register class
3167 // this is a list of.
3168 int Reg = tryParseRegister();
3170 return Error(RegLoc, "register expected");
3172 // The reglist instructions have at most 16 registers, so reserve
3173 // space for that many.
3175 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
3177 // Allow Q regs and just interpret them as the two D sub-registers.
3178 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3179 Reg = getDRegFromQReg(Reg);
3180 EReg = MRI->getEncodingValue(Reg);
3181 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3184 const MCRegisterClass *RC;
3185 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3186 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3187 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3188 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3189 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3190 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3192 return Error(RegLoc, "invalid register in register list");
3194 // Store the register.
3195 EReg = MRI->getEncodingValue(Reg);
3196 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3198 // This starts immediately after the first register token in the list,
3199 // so we can see either a comma or a minus (range separator) as a legal
3201 while (Parser.getTok().is(AsmToken::Comma) ||
3202 Parser.getTok().is(AsmToken::Minus)) {
3203 if (Parser.getTok().is(AsmToken::Minus)) {
3204 Parser.Lex(); // Eat the minus.
3205 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3206 int EndReg = tryParseRegister();
3208 return Error(AfterMinusLoc, "register expected");
3209 // Allow Q regs and just interpret them as the two D sub-registers.
3210 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3211 EndReg = getDRegFromQReg(EndReg) + 1;
3212 // If the register is the same as the start reg, there's nothing
3216 // The register must be in the same register class as the first.
3217 if (!RC->contains(EndReg))
3218 return Error(AfterMinusLoc, "invalid register in register list");
3219 // Ranges must go from low to high.
3220 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
3221 return Error(AfterMinusLoc, "bad range in register list");
3223 // Add all the registers in the range to the register list.
3224 while (Reg != EndReg) {
3225 Reg = getNextRegister(Reg);
3226 EReg = MRI->getEncodingValue(Reg);
3227 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3231 Parser.Lex(); // Eat the comma.
3232 RegLoc = Parser.getTok().getLoc();
3234 const AsmToken RegTok = Parser.getTok();
3235 Reg = tryParseRegister();
3237 return Error(RegLoc, "register expected");
3238 // Allow Q regs and just interpret them as the two D sub-registers.
3239 bool isQReg = false;
3240 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3241 Reg = getDRegFromQReg(Reg);
3244 // The register must be in the same register class as the first.
3245 if (!RC->contains(Reg))
3246 return Error(RegLoc, "invalid register in register list");
3247 // List must be monotonically increasing.
3248 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
3249 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3250 Warning(RegLoc, "register list not in ascending order");
3252 return Error(RegLoc, "register list not in ascending order");
3254 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
3255 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3256 ") in register list");
3259 // VFP register lists must also be contiguous.
3260 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3262 return Error(RegLoc, "non-contiguous register range");
3263 EReg = MRI->getEncodingValue(Reg);
3264 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3266 EReg = MRI->getEncodingValue(++Reg);
3267 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3271 if (Parser.getTok().isNot(AsmToken::RCurly))
3272 return Error(Parser.getTok().getLoc(), "'}' expected");
3273 SMLoc E = Parser.getTok().getEndLoc();
3274 Parser.Lex(); // Eat '}' token.
3276 // Push the register list operand.
3277 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
3279 // The ARM system instruction variants for LDM/STM have a '^' token here.
3280 if (Parser.getTok().is(AsmToken::Caret)) {
3281 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3282 Parser.Lex(); // Eat '^' token.
3288 // Helper function to parse the lane index for vector lists.
3289 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3290 parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
3291 Index = 0; // Always return a defined index value.
3292 if (Parser.getTok().is(AsmToken::LBrac)) {
3293 Parser.Lex(); // Eat the '['.
3294 if (Parser.getTok().is(AsmToken::RBrac)) {
3295 // "Dn[]" is the 'all lanes' syntax.
3296 LaneKind = AllLanes;
3297 EndLoc = Parser.getTok().getEndLoc();
3298 Parser.Lex(); // Eat the ']'.
3299 return MatchOperand_Success;
3302 // There's an optional '#' token here. Normally there wouldn't be, but
3303 // inline assemble puts one in, and it's friendly to accept that.
3304 if (Parser.getTok().is(AsmToken::Hash))
3305 Parser.Lex(); // Eat '#' or '$'.
3307 const MCExpr *LaneIndex;
3308 SMLoc Loc = Parser.getTok().getLoc();
3309 if (getParser().parseExpression(LaneIndex)) {
3310 Error(Loc, "illegal expression");
3311 return MatchOperand_ParseFail;
3313 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3315 Error(Loc, "lane index must be empty or an integer");
3316 return MatchOperand_ParseFail;
3318 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3319 Error(Parser.getTok().getLoc(), "']' expected");
3320 return MatchOperand_ParseFail;
3322 EndLoc = Parser.getTok().getEndLoc();
3323 Parser.Lex(); // Eat the ']'.
3324 int64_t Val = CE->getValue();
3326 // FIXME: Make this range check context sensitive for .8, .16, .32.
3327 if (Val < 0 || Val > 7) {
3328 Error(Parser.getTok().getLoc(), "lane index out of range");
3329 return MatchOperand_ParseFail;
3332 LaneKind = IndexedLane;
3333 return MatchOperand_Success;
3336 return MatchOperand_Success;
3339 // parse a vector register list
3340 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3341 parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3342 VectorLaneTy LaneKind;
3344 SMLoc S = Parser.getTok().getLoc();
3345 // As an extension (to match gas), support a plain D register or Q register
3346 // (without encosing curly braces) as a single or double entry list,
3348 if (Parser.getTok().is(AsmToken::Identifier)) {
3349 SMLoc E = Parser.getTok().getEndLoc();
3350 int Reg = tryParseRegister();
3352 return MatchOperand_NoMatch;
3353 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
3354 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3355 if (Res != MatchOperand_Success)
3359 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
3362 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3366 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
3371 return MatchOperand_Success;
3373 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3374 Reg = getDRegFromQReg(Reg);
3375 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
3376 if (Res != MatchOperand_Success)
3380 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3381 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3382 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
3385 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3386 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
3387 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3391 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
3396 return MatchOperand_Success;
3398 Error(S, "vector register expected");
3399 return MatchOperand_ParseFail;
3402 if (Parser.getTok().isNot(AsmToken::LCurly))
3403 return MatchOperand_NoMatch;
3405 Parser.Lex(); // Eat '{' token.
3406 SMLoc RegLoc = Parser.getTok().getLoc();
3408 int Reg = tryParseRegister();
3410 Error(RegLoc, "register expected");
3411 return MatchOperand_ParseFail;
3415 unsigned FirstReg = Reg;
3416 // The list is of D registers, but we also allow Q regs and just interpret
3417 // them as the two D sub-registers.
3418 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3419 FirstReg = Reg = getDRegFromQReg(Reg);
3420 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3421 // it's ambiguous with four-register single spaced.
3427 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
3428 return MatchOperand_ParseFail;
3430 while (Parser.getTok().is(AsmToken::Comma) ||
3431 Parser.getTok().is(AsmToken::Minus)) {
3432 if (Parser.getTok().is(AsmToken::Minus)) {
3434 Spacing = 1; // Register range implies a single spaced list.
3435 else if (Spacing == 2) {
3436 Error(Parser.getTok().getLoc(),
3437 "sequential registers in double spaced list");
3438 return MatchOperand_ParseFail;
3440 Parser.Lex(); // Eat the minus.
3441 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
3442 int EndReg = tryParseRegister();
3444 Error(AfterMinusLoc, "register expected");
3445 return MatchOperand_ParseFail;
3447 // Allow Q regs and just interpret them as the two D sub-registers.
3448 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3449 EndReg = getDRegFromQReg(EndReg) + 1;
3450 // If the register is the same as the start reg, there's nothing
3454 // The register must be in the same register class as the first.
3455 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3456 Error(AfterMinusLoc, "invalid register in register list");
3457 return MatchOperand_ParseFail;
3459 // Ranges must go from low to high.
3461 Error(AfterMinusLoc, "bad range in register list");
3462 return MatchOperand_ParseFail;
3464 // Parse the lane specifier if present.
3465 VectorLaneTy NextLaneKind;
3466 unsigned NextLaneIndex;
3467 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3468 MatchOperand_Success)
3469 return MatchOperand_ParseFail;
3470 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3471 Error(AfterMinusLoc, "mismatched lane index in register list");
3472 return MatchOperand_ParseFail;
3475 // Add all the registers in the range to the register list.
3476 Count += EndReg - Reg;
3480 Parser.Lex(); // Eat the comma.
3481 RegLoc = Parser.getTok().getLoc();
3483 Reg = tryParseRegister();
3485 Error(RegLoc, "register expected");
3486 return MatchOperand_ParseFail;
3488 // vector register lists must be contiguous.
3489 // It's OK to use the enumeration values directly here rather, as the
3490 // VFP register classes have the enum sorted properly.
3492 // The list is of D registers, but we also allow Q regs and just interpret
3493 // them as the two D sub-registers.
3494 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3496 Spacing = 1; // Register range implies a single spaced list.
3497 else if (Spacing == 2) {
3499 "invalid register in double-spaced list (must be 'D' register')");
3500 return MatchOperand_ParseFail;
3502 Reg = getDRegFromQReg(Reg);
3503 if (Reg != OldReg + 1) {
3504 Error(RegLoc, "non-contiguous register range");
3505 return MatchOperand_ParseFail;
3509 // Parse the lane specifier if present.
3510 VectorLaneTy NextLaneKind;
3511 unsigned NextLaneIndex;
3512 SMLoc LaneLoc = Parser.getTok().getLoc();
3513 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3514 MatchOperand_Success)
3515 return MatchOperand_ParseFail;
3516 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3517 Error(LaneLoc, "mismatched lane index in register list");
3518 return MatchOperand_ParseFail;
3522 // Normal D register.
3523 // Figure out the register spacing (single or double) of the list if
3524 // we don't know it already.
3526 Spacing = 1 + (Reg == OldReg + 2);
3528 // Just check that it's contiguous and keep going.
3529 if (Reg != OldReg + Spacing) {
3530 Error(RegLoc, "non-contiguous register range");
3531 return MatchOperand_ParseFail;
3534 // Parse the lane specifier if present.
3535 VectorLaneTy NextLaneKind;
3536 unsigned NextLaneIndex;
3537 SMLoc EndLoc = Parser.getTok().getLoc();
3538 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
3539 return MatchOperand_ParseFail;
3540 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
3541 Error(EndLoc, "mismatched lane index in register list");
3542 return MatchOperand_ParseFail;
3546 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3547 Error(Parser.getTok().getLoc(), "'}' expected");
3548 return MatchOperand_ParseFail;
3550 E = Parser.getTok().getEndLoc();
3551 Parser.Lex(); // Eat '}' token.
3555 // Two-register operands have been converted to the
3556 // composite register classes.
3558 const MCRegisterClass *RC = (Spacing == 1) ?
3559 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3560 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3561 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3564 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3565 (Spacing == 2), S, E));
3568 // Two-register operands have been converted to the
3569 // composite register classes.
3571 const MCRegisterClass *RC = (Spacing == 1) ?
3572 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3573 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3574 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3576 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
3581 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
3587 return MatchOperand_Success;
3590 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
3591 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3592 parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3593 SMLoc S = Parser.getTok().getLoc();
3594 const AsmToken &Tok = Parser.getTok();
3597 if (Tok.is(AsmToken::Identifier)) {
3598 StringRef OptStr = Tok.getString();
3600 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3601 .Case("sy", ARM_MB::SY)
3602 .Case("st", ARM_MB::ST)
3603 .Case("ld", ARM_MB::LD)
3604 .Case("sh", ARM_MB::ISH)
3605 .Case("ish", ARM_MB::ISH)
3606 .Case("shst", ARM_MB::ISHST)
3607 .Case("ishst", ARM_MB::ISHST)
3608 .Case("ishld", ARM_MB::ISHLD)
3609 .Case("nsh", ARM_MB::NSH)
3610 .Case("un", ARM_MB::NSH)
3611 .Case("nshst", ARM_MB::NSHST)
3612 .Case("nshld", ARM_MB::NSHLD)
3613 .Case("unst", ARM_MB::NSHST)
3614 .Case("osh", ARM_MB::OSH)
3615 .Case("oshst", ARM_MB::OSHST)
3616 .Case("oshld", ARM_MB::OSHLD)
3619 // ishld, oshld, nshld and ld are only available from ARMv8.
3620 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3621 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3625 return MatchOperand_NoMatch;
3627 Parser.Lex(); // Eat identifier token.
3628 } else if (Tok.is(AsmToken::Hash) ||
3629 Tok.is(AsmToken::Dollar) ||
3630 Tok.is(AsmToken::Integer)) {
3631 if (Parser.getTok().isNot(AsmToken::Integer))
3632 Parser.Lex(); // Eat '#' or '$'.
3633 SMLoc Loc = Parser.getTok().getLoc();
3635 const MCExpr *MemBarrierID;
3636 if (getParser().parseExpression(MemBarrierID)) {
3637 Error(Loc, "illegal expression");
3638 return MatchOperand_ParseFail;
3641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3643 Error(Loc, "constant expression expected");
3644 return MatchOperand_ParseFail;
3647 int Val = CE->getValue();
3649 Error(Loc, "immediate value out of range");
3650 return MatchOperand_ParseFail;
3653 Opt = ARM_MB::RESERVED_0 + Val;
3655 return MatchOperand_ParseFail;
3657 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
3658 return MatchOperand_Success;
3661 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3662 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3663 parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3664 SMLoc S = Parser.getTok().getLoc();
3665 const AsmToken &Tok = Parser.getTok();
3668 if (Tok.is(AsmToken::Identifier)) {
3669 StringRef OptStr = Tok.getString();
3671 if (OptStr.equals_lower("sy"))
3674 return MatchOperand_NoMatch;
3676 Parser.Lex(); // Eat identifier token.
3677 } else if (Tok.is(AsmToken::Hash) ||
3678 Tok.is(AsmToken::Dollar) ||
3679 Tok.is(AsmToken::Integer)) {
3680 if (Parser.getTok().isNot(AsmToken::Integer))
3681 Parser.Lex(); // Eat '#' or '$'.
3682 SMLoc Loc = Parser.getTok().getLoc();
3684 const MCExpr *ISBarrierID;
3685 if (getParser().parseExpression(ISBarrierID)) {
3686 Error(Loc, "illegal expression");
3687 return MatchOperand_ParseFail;
3690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3692 Error(Loc, "constant expression expected");
3693 return MatchOperand_ParseFail;
3696 int Val = CE->getValue();
3698 Error(Loc, "immediate value out of range");
3699 return MatchOperand_ParseFail;
3702 Opt = ARM_ISB::RESERVED_0 + Val;
3704 return MatchOperand_ParseFail;
3706 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3707 (ARM_ISB::InstSyncBOpt)Opt, S));
3708 return MatchOperand_Success;
3712 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
3713 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3714 parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3715 SMLoc S = Parser.getTok().getLoc();
3716 const AsmToken &Tok = Parser.getTok();
3717 if (!Tok.is(AsmToken::Identifier))
3718 return MatchOperand_NoMatch;
3719 StringRef IFlagsStr = Tok.getString();
3721 // An iflags string of "none" is interpreted to mean that none of the AIF
3722 // bits are set. Not a terribly useful instruction, but a valid encoding.
3723 unsigned IFlags = 0;
3724 if (IFlagsStr != "none") {
3725 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3726 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3727 .Case("a", ARM_PROC::A)
3728 .Case("i", ARM_PROC::I)
3729 .Case("f", ARM_PROC::F)
3732 // If some specific iflag is already set, it means that some letter is
3733 // present more than once, this is not acceptable.
3734 if (Flag == ~0U || (IFlags & Flag))
3735 return MatchOperand_NoMatch;
3741 Parser.Lex(); // Eat identifier token.
3742 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3743 return MatchOperand_Success;
3746 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
3747 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3748 parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3749 SMLoc S = Parser.getTok().getLoc();
3750 const AsmToken &Tok = Parser.getTok();
3751 if (!Tok.is(AsmToken::Identifier))
3752 return MatchOperand_NoMatch;
3753 StringRef Mask = Tok.getString();
3756 // See ARMv6-M 10.1.1
3757 std::string Name = Mask.lower();
3758 unsigned FlagsVal = StringSwitch<unsigned>(Name)
3759 // Note: in the documentation:
3760 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3761 // for MSR APSR_nzcvq.
3762 // but we do make it an alias here. This is so to get the "mask encoding"
3763 // bits correct on MSR APSR writes.
3765 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3766 // should really only be allowed when writing a special register. Note
3767 // they get dropped in the MRS instruction reading a special register as
3768 // the SYSm field is only 8 bits.
3770 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3771 // includes the DSP extension but that is not checked.
3772 .Case("apsr", 0x800)
3773 .Case("apsr_nzcvq", 0x800)
3774 .Case("apsr_g", 0x400)
3775 .Case("apsr_nzcvqg", 0xc00)
3776 .Case("iapsr", 0x801)
3777 .Case("iapsr_nzcvq", 0x801)
3778 .Case("iapsr_g", 0x401)
3779 .Case("iapsr_nzcvqg", 0xc01)
3780 .Case("eapsr", 0x802)
3781 .Case("eapsr_nzcvq", 0x802)
3782 .Case("eapsr_g", 0x402)
3783 .Case("eapsr_nzcvqg", 0xc02)
3784 .Case("xpsr", 0x803)
3785 .Case("xpsr_nzcvq", 0x803)
3786 .Case("xpsr_g", 0x403)
3787 .Case("xpsr_nzcvqg", 0xc03)
3788 .Case("ipsr", 0x805)
3789 .Case("epsr", 0x806)
3790 .Case("iepsr", 0x807)
3793 .Case("primask", 0x810)
3794 .Case("basepri", 0x811)
3795 .Case("basepri_max", 0x812)
3796 .Case("faultmask", 0x813)
3797 .Case("control", 0x814)
3800 if (FlagsVal == ~0U)
3801 return MatchOperand_NoMatch;
3803 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
3804 // basepri, basepri_max and faultmask only valid for V7m.
3805 return MatchOperand_NoMatch;
3807 Parser.Lex(); // Eat identifier token.
3808 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3809 return MatchOperand_Success;
3812 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3813 size_t Start = 0, Next = Mask.find('_');
3814 StringRef Flags = "";
3815 std::string SpecReg = Mask.slice(Start, Next).lower();
3816 if (Next != StringRef::npos)
3817 Flags = Mask.slice(Next+1, Mask.size());
3819 // FlagsVal contains the complete mask:
3821 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3822 unsigned FlagsVal = 0;
3824 if (SpecReg == "apsr") {
3825 FlagsVal = StringSwitch<unsigned>(Flags)
3826 .Case("nzcvq", 0x8) // same as CPSR_f
3827 .Case("g", 0x4) // same as CPSR_s
3828 .Case("nzcvqg", 0xc) // same as CPSR_fs
3831 if (FlagsVal == ~0U) {
3833 return MatchOperand_NoMatch;
3835 FlagsVal = 8; // No flag
3837 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
3838 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3839 if (Flags == "all" || Flags == "")
3841 for (int i = 0, e = Flags.size(); i != e; ++i) {
3842 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3849 // If some specific flag is already set, it means that some letter is
3850 // present more than once, this is not acceptable.
3851 if (FlagsVal == ~0U || (FlagsVal & Flag))
3852 return MatchOperand_NoMatch;
3855 } else // No match for special register.
3856 return MatchOperand_NoMatch;
3858 // Special register without flags is NOT equivalent to "fc" flags.
3859 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3860 // two lines would enable gas compatibility at the expense of breaking
3866 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3867 if (SpecReg == "spsr")
3870 Parser.Lex(); // Eat identifier token.
3871 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3872 return MatchOperand_Success;
3875 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3876 parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3877 int Low, int High) {
3878 const AsmToken &Tok = Parser.getTok();
3879 if (Tok.isNot(AsmToken::Identifier)) {
3880 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3881 return MatchOperand_ParseFail;
3883 StringRef ShiftName = Tok.getString();
3884 std::string LowerOp = Op.lower();
3885 std::string UpperOp = Op.upper();
3886 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3887 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3888 return MatchOperand_ParseFail;
3890 Parser.Lex(); // Eat shift type token.
3892 // There must be a '#' and a shift amount.
3893 if (Parser.getTok().isNot(AsmToken::Hash) &&
3894 Parser.getTok().isNot(AsmToken::Dollar)) {
3895 Error(Parser.getTok().getLoc(), "'#' expected");
3896 return MatchOperand_ParseFail;
3898 Parser.Lex(); // Eat hash token.
3900 const MCExpr *ShiftAmount;
3901 SMLoc Loc = Parser.getTok().getLoc();
3903 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3904 Error(Loc, "illegal expression");
3905 return MatchOperand_ParseFail;
3907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3909 Error(Loc, "constant expression expected");
3910 return MatchOperand_ParseFail;
3912 int Val = CE->getValue();
3913 if (Val < Low || Val > High) {
3914 Error(Loc, "immediate value out of range");
3915 return MatchOperand_ParseFail;
3918 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
3920 return MatchOperand_Success;
3923 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3924 parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3925 const AsmToken &Tok = Parser.getTok();
3926 SMLoc S = Tok.getLoc();
3927 if (Tok.isNot(AsmToken::Identifier)) {
3928 Error(S, "'be' or 'le' operand expected");
3929 return MatchOperand_ParseFail;
3931 int Val = StringSwitch<int>(Tok.getString().lower())
3935 Parser.Lex(); // Eat the token.
3938 Error(S, "'be' or 'le' operand expected");
3939 return MatchOperand_ParseFail;
3941 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3943 S, Tok.getEndLoc()));
3944 return MatchOperand_Success;
3947 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3948 /// instructions. Legal values are:
3949 /// lsl #n 'n' in [0,31]
3950 /// asr #n 'n' in [1,32]
3951 /// n == 32 encoded as n == 0.
3952 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3953 parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3954 const AsmToken &Tok = Parser.getTok();
3955 SMLoc S = Tok.getLoc();
3956 if (Tok.isNot(AsmToken::Identifier)) {
3957 Error(S, "shift operator 'asr' or 'lsl' expected");
3958 return MatchOperand_ParseFail;
3960 StringRef ShiftName = Tok.getString();
3962 if (ShiftName == "lsl" || ShiftName == "LSL")
3964 else if (ShiftName == "asr" || ShiftName == "ASR")
3967 Error(S, "shift operator 'asr' or 'lsl' expected");
3968 return MatchOperand_ParseFail;
3970 Parser.Lex(); // Eat the operator.
3972 // A '#' and a shift amount.
3973 if (Parser.getTok().isNot(AsmToken::Hash) &&
3974 Parser.getTok().isNot(AsmToken::Dollar)) {
3975 Error(Parser.getTok().getLoc(), "'#' expected");
3976 return MatchOperand_ParseFail;
3978 Parser.Lex(); // Eat hash token.
3979 SMLoc ExLoc = Parser.getTok().getLoc();
3981 const MCExpr *ShiftAmount;
3983 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
3984 Error(ExLoc, "malformed shift expression");
3985 return MatchOperand_ParseFail;
3987 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3989 Error(ExLoc, "shift amount must be an immediate");
3990 return MatchOperand_ParseFail;
3993 int64_t Val = CE->getValue();
3995 // Shift amount must be in [1,32]
3996 if (Val < 1 || Val > 32) {
3997 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
3998 return MatchOperand_ParseFail;
4000 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4001 if (isThumb() && Val == 32) {
4002 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
4003 return MatchOperand_ParseFail;
4005 if (Val == 32) Val = 0;
4007 // Shift amount must be in [1,32]
4008 if (Val < 0 || Val > 31) {
4009 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
4010 return MatchOperand_ParseFail;
4014 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
4016 return MatchOperand_Success;
4019 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4020 /// of instructions. Legal values are:
4021 /// ror #n 'n' in {0, 8, 16, 24}
4022 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4023 parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4024 const AsmToken &Tok = Parser.getTok();
4025 SMLoc S = Tok.getLoc();
4026 if (Tok.isNot(AsmToken::Identifier))
4027 return MatchOperand_NoMatch;
4028 StringRef ShiftName = Tok.getString();
4029 if (ShiftName != "ror" && ShiftName != "ROR")
4030 return MatchOperand_NoMatch;
4031 Parser.Lex(); // Eat the operator.
4033 // A '#' and a rotate amount.
4034 if (Parser.getTok().isNot(AsmToken::Hash) &&
4035 Parser.getTok().isNot(AsmToken::Dollar)) {
4036 Error(Parser.getTok().getLoc(), "'#' expected");
4037 return MatchOperand_ParseFail;
4039 Parser.Lex(); // Eat hash token.
4040 SMLoc ExLoc = Parser.getTok().getLoc();
4042 const MCExpr *ShiftAmount;
4044 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
4045 Error(ExLoc, "malformed rotate expression");
4046 return MatchOperand_ParseFail;
4048 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4050 Error(ExLoc, "rotate amount must be an immediate");
4051 return MatchOperand_ParseFail;
4054 int64_t Val = CE->getValue();
4055 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4056 // normally, zero is represented in asm by omitting the rotate operand
4058 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
4059 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
4060 return MatchOperand_ParseFail;
4063 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
4065 return MatchOperand_Success;
4068 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4069 parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4070 SMLoc S = Parser.getTok().getLoc();
4071 // The bitfield descriptor is really two operands, the LSB and the width.
4072 if (Parser.getTok().isNot(AsmToken::Hash) &&
4073 Parser.getTok().isNot(AsmToken::Dollar)) {
4074 Error(Parser.getTok().getLoc(), "'#' expected");
4075 return MatchOperand_ParseFail;
4077 Parser.Lex(); // Eat hash token.
4079 const MCExpr *LSBExpr;
4080 SMLoc E = Parser.getTok().getLoc();
4081 if (getParser().parseExpression(LSBExpr)) {
4082 Error(E, "malformed immediate expression");
4083 return MatchOperand_ParseFail;
4085 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4087 Error(E, "'lsb' operand must be an immediate");
4088 return MatchOperand_ParseFail;
4091 int64_t LSB = CE->getValue();
4092 // The LSB must be in the range [0,31]
4093 if (LSB < 0 || LSB > 31) {
4094 Error(E, "'lsb' operand must be in the range [0,31]");
4095 return MatchOperand_ParseFail;
4097 E = Parser.getTok().getLoc();
4099 // Expect another immediate operand.
4100 if (Parser.getTok().isNot(AsmToken::Comma)) {
4101 Error(Parser.getTok().getLoc(), "too few operands");
4102 return MatchOperand_ParseFail;
4104 Parser.Lex(); // Eat hash token.
4105 if (Parser.getTok().isNot(AsmToken::Hash) &&
4106 Parser.getTok().isNot(AsmToken::Dollar)) {
4107 Error(Parser.getTok().getLoc(), "'#' expected");
4108 return MatchOperand_ParseFail;
4110 Parser.Lex(); // Eat hash token.
4112 const MCExpr *WidthExpr;
4114 if (getParser().parseExpression(WidthExpr, EndLoc)) {
4115 Error(E, "malformed immediate expression");
4116 return MatchOperand_ParseFail;
4118 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4120 Error(E, "'width' operand must be an immediate");
4121 return MatchOperand_ParseFail;
4124 int64_t Width = CE->getValue();
4125 // The LSB must be in the range [1,32-lsb]
4126 if (Width < 1 || Width > 32 - LSB) {
4127 Error(E, "'width' operand must be in the range [1,32-lsb]");
4128 return MatchOperand_ParseFail;
4131 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
4133 return MatchOperand_Success;
4136 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4137 parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4138 // Check for a post-index addressing register operand. Specifically:
4139 // postidx_reg := '+' register {, shift}
4140 // | '-' register {, shift}
4141 // | register {, shift}
4143 // This method must return MatchOperand_NoMatch without consuming any tokens
4144 // in the case where there is no match, as other alternatives take other
4146 AsmToken Tok = Parser.getTok();
4147 SMLoc S = Tok.getLoc();
4148 bool haveEaten = false;
4150 if (Tok.is(AsmToken::Plus)) {
4151 Parser.Lex(); // Eat the '+' token.
4153 } else if (Tok.is(AsmToken::Minus)) {
4154 Parser.Lex(); // Eat the '-' token.
4159 SMLoc E = Parser.getTok().getEndLoc();
4160 int Reg = tryParseRegister();
4163 return MatchOperand_NoMatch;
4164 Error(Parser.getTok().getLoc(), "register expected");
4165 return MatchOperand_ParseFail;
4168 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4169 unsigned ShiftImm = 0;
4170 if (Parser.getTok().is(AsmToken::Comma)) {
4171 Parser.Lex(); // Eat the ','.
4172 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4173 return MatchOperand_ParseFail;
4175 // FIXME: Only approximates end...may include intervening whitespace.
4176 E = Parser.getTok().getLoc();
4179 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4182 return MatchOperand_Success;
4185 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4186 parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4187 // Check for a post-index addressing register operand. Specifically:
4188 // am3offset := '+' register
4195 // This method must return MatchOperand_NoMatch without consuming any tokens
4196 // in the case where there is no match, as other alternatives take other
4198 AsmToken Tok = Parser.getTok();
4199 SMLoc S = Tok.getLoc();
4201 // Do immediates first, as we always parse those if we have a '#'.
4202 if (Parser.getTok().is(AsmToken::Hash) ||
4203 Parser.getTok().is(AsmToken::Dollar)) {
4204 Parser.Lex(); // Eat '#' or '$'.
4205 // Explicitly look for a '-', as we need to encode negative zero
4207 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4208 const MCExpr *Offset;
4210 if (getParser().parseExpression(Offset, E))
4211 return MatchOperand_ParseFail;
4212 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4214 Error(S, "constant expression expected");
4215 return MatchOperand_ParseFail;
4217 // Negative zero is encoded as the flag value INT32_MIN.
4218 int32_t Val = CE->getValue();
4219 if (isNegative && Val == 0)
4223 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4225 return MatchOperand_Success;
4229 bool haveEaten = false;
4231 if (Tok.is(AsmToken::Plus)) {
4232 Parser.Lex(); // Eat the '+' token.
4234 } else if (Tok.is(AsmToken::Minus)) {
4235 Parser.Lex(); // Eat the '-' token.
4240 Tok = Parser.getTok();
4241 int Reg = tryParseRegister();
4244 return MatchOperand_NoMatch;
4245 Error(Tok.getLoc(), "register expected");
4246 return MatchOperand_ParseFail;
4249 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
4250 0, S, Tok.getEndLoc()));
4252 return MatchOperand_Success;
4255 /// Convert parsed operands to MCInst. Needed here because this instruction
4256 /// only has two register operands, but multiplication is commutative so
4257 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
4259 cvtThumbMultiply(MCInst &Inst,
4260 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4261 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4262 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
4263 // If we have a three-operand form, make sure to set Rn to be the operand
4264 // that isn't the same as Rd.
4266 if (Operands.size() == 6 &&
4267 ((ARMOperand*)Operands[4])->getReg() ==
4268 ((ARMOperand*)Operands[3])->getReg())
4270 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4271 Inst.addOperand(Inst.getOperand(0));
4272 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4276 cvtThumbBranches(MCInst &Inst,
4277 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4278 int CondOp = -1, ImmOp = -1;
4279 switch(Inst.getOpcode()) {
4281 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4284 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4286 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4288 // first decide whether or not the branch should be conditional
4289 // by looking at it's location relative to an IT block
4291 // inside an IT block we cannot have any conditional branches. any
4292 // such instructions needs to be converted to unconditional form
4293 switch(Inst.getOpcode()) {
4294 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4295 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4298 // outside IT blocks we can only have unconditional branches with AL
4299 // condition code or conditional branches with non-AL condition code
4300 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4301 switch(Inst.getOpcode()) {
4304 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4308 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4313 // now decide on encoding size based on branch target range
4314 switch(Inst.getOpcode()) {
4315 // classify tB as either t2B or t1B based on range of immediate operand
4317 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4318 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4319 Inst.setOpcode(ARM::t2B);
4322 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4324 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4325 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4326 Inst.setOpcode(ARM::t2Bcc);
4330 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4331 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4334 /// Parse an ARM memory expression, return false if successful else return true
4335 /// or an error. The first token must be a '[' when called.
4337 parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4339 assert(Parser.getTok().is(AsmToken::LBrac) &&
4340 "Token is not a Left Bracket");
4341 S = Parser.getTok().getLoc();
4342 Parser.Lex(); // Eat left bracket token.
4344 const AsmToken &BaseRegTok = Parser.getTok();
4345 int BaseRegNum = tryParseRegister();
4346 if (BaseRegNum == -1)
4347 return Error(BaseRegTok.getLoc(), "register expected");
4349 // The next token must either be a comma, a colon or a closing bracket.
4350 const AsmToken &Tok = Parser.getTok();
4351 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4352 !Tok.is(AsmToken::RBrac))
4353 return Error(Tok.getLoc(), "malformed memory operand");
4355 if (Tok.is(AsmToken::RBrac)) {
4356 E = Tok.getEndLoc();
4357 Parser.Lex(); // Eat right bracket token.
4359 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
4360 0, 0, false, S, E));
4362 // If there's a pre-indexing writeback marker, '!', just add it as a token
4363 // operand. It's rather odd, but syntactically valid.
4364 if (Parser.getTok().is(AsmToken::Exclaim)) {
4365 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4366 Parser.Lex(); // Eat the '!'.
4372 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4373 "Lost colon or comma in memory operand?!");
4374 if (Tok.is(AsmToken::Comma)) {
4375 Parser.Lex(); // Eat the comma.
4378 // If we have a ':', it's an alignment specifier.
4379 if (Parser.getTok().is(AsmToken::Colon)) {
4380 Parser.Lex(); // Eat the ':'.
4381 E = Parser.getTok().getLoc();
4384 if (getParser().parseExpression(Expr))
4387 // The expression has to be a constant. Memory references with relocations
4388 // don't come through here, as they use the <label> forms of the relevant
4390 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4392 return Error (E, "constant expression expected");
4395 switch (CE->getValue()) {
4398 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4399 case 16: Align = 2; break;
4400 case 32: Align = 4; break;
4401 case 64: Align = 8; break;
4402 case 128: Align = 16; break;
4403 case 256: Align = 32; break;
4406 // Now we should have the closing ']'
4407 if (Parser.getTok().isNot(AsmToken::RBrac))
4408 return Error(Parser.getTok().getLoc(), "']' expected");
4409 E = Parser.getTok().getEndLoc();
4410 Parser.Lex(); // Eat right bracket token.
4412 // Don't worry about range checking the value here. That's handled by
4413 // the is*() predicates.
4414 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4415 ARM_AM::no_shift, 0, Align,
4418 // If there's a pre-indexing writeback marker, '!', just add it as a token
4420 if (Parser.getTok().is(AsmToken::Exclaim)) {
4421 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4422 Parser.Lex(); // Eat the '!'.
4428 // If we have a '#', it's an immediate offset, else assume it's a register
4429 // offset. Be friendly and also accept a plain integer (without a leading
4430 // hash) for gas compatibility.
4431 if (Parser.getTok().is(AsmToken::Hash) ||
4432 Parser.getTok().is(AsmToken::Dollar) ||
4433 Parser.getTok().is(AsmToken::Integer)) {
4434 if (Parser.getTok().isNot(AsmToken::Integer))
4435 Parser.Lex(); // Eat '#' or '$'.
4436 E = Parser.getTok().getLoc();
4438 bool isNegative = getParser().getTok().is(AsmToken::Minus);
4439 const MCExpr *Offset;
4440 if (getParser().parseExpression(Offset))
4443 // The expression has to be a constant. Memory references with relocations
4444 // don't come through here, as they use the <label> forms of the relevant
4446 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4448 return Error (E, "constant expression expected");
4450 // If the constant was #-0, represent it as INT32_MIN.
4451 int32_t Val = CE->getValue();
4452 if (isNegative && Val == 0)
4453 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4455 // Now we should have the closing ']'
4456 if (Parser.getTok().isNot(AsmToken::RBrac))
4457 return Error(Parser.getTok().getLoc(), "']' expected");
4458 E = Parser.getTok().getEndLoc();
4459 Parser.Lex(); // Eat right bracket token.
4461 // Don't worry about range checking the value here. That's handled by
4462 // the is*() predicates.
4463 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
4464 ARM_AM::no_shift, 0, 0,
4467 // If there's a pre-indexing writeback marker, '!', just add it as a token
4469 if (Parser.getTok().is(AsmToken::Exclaim)) {
4470 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4471 Parser.Lex(); // Eat the '!'.
4477 // The register offset is optionally preceded by a '+' or '-'
4478 bool isNegative = false;
4479 if (Parser.getTok().is(AsmToken::Minus)) {
4481 Parser.Lex(); // Eat the '-'.
4482 } else if (Parser.getTok().is(AsmToken::Plus)) {
4484 Parser.Lex(); // Eat the '+'.
4487 E = Parser.getTok().getLoc();
4488 int OffsetRegNum = tryParseRegister();
4489 if (OffsetRegNum == -1)
4490 return Error(E, "register expected");
4492 // If there's a shift operator, handle it.
4493 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
4494 unsigned ShiftImm = 0;
4495 if (Parser.getTok().is(AsmToken::Comma)) {
4496 Parser.Lex(); // Eat the ','.
4497 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
4501 // Now we should have the closing ']'
4502 if (Parser.getTok().isNot(AsmToken::RBrac))
4503 return Error(Parser.getTok().getLoc(), "']' expected");
4504 E = Parser.getTok().getEndLoc();
4505 Parser.Lex(); // Eat right bracket token.
4507 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
4508 ShiftType, ShiftImm, 0, isNegative,
4511 // If there's a pre-indexing writeback marker, '!', just add it as a token
4513 if (Parser.getTok().is(AsmToken::Exclaim)) {
4514 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4515 Parser.Lex(); // Eat the '!'.
4521 /// parseMemRegOffsetShift - one of these two:
4522 /// ( lsl | lsr | asr | ror ) , # shift_amount
4524 /// return true if it parses a shift otherwise it returns false.
4525 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4527 SMLoc Loc = Parser.getTok().getLoc();
4528 const AsmToken &Tok = Parser.getTok();
4529 if (Tok.isNot(AsmToken::Identifier))
4531 StringRef ShiftName = Tok.getString();
4532 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4533 ShiftName == "asl" || ShiftName == "ASL")
4535 else if (ShiftName == "lsr" || ShiftName == "LSR")
4537 else if (ShiftName == "asr" || ShiftName == "ASR")
4539 else if (ShiftName == "ror" || ShiftName == "ROR")
4541 else if (ShiftName == "rrx" || ShiftName == "RRX")
4544 return Error(Loc, "illegal shift operator");
4545 Parser.Lex(); // Eat shift type token.
4547 // rrx stands alone.
4549 if (St != ARM_AM::rrx) {
4550 Loc = Parser.getTok().getLoc();
4551 // A '#' and a shift amount.
4552 const AsmToken &HashTok = Parser.getTok();
4553 if (HashTok.isNot(AsmToken::Hash) &&
4554 HashTok.isNot(AsmToken::Dollar))
4555 return Error(HashTok.getLoc(), "'#' expected");
4556 Parser.Lex(); // Eat hash token.
4559 if (getParser().parseExpression(Expr))
4561 // Range check the immediate.
4562 // lsl, ror: 0 <= imm <= 31
4563 // lsr, asr: 0 <= imm <= 32
4564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4566 return Error(Loc, "shift amount must be an immediate");
4567 int64_t Imm = CE->getValue();
4569 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4570 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4571 return Error(Loc, "immediate shift value out of range");
4572 // If <ShiftTy> #0, turn it into a no_shift.
4575 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4584 /// parseFPImm - A floating point immediate expression operand.
4585 ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4586 parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4587 // Anything that can accept a floating point constant as an operand
4588 // needs to go through here, as the regular parseExpression is
4591 // This routine still creates a generic Immediate operand, containing
4592 // a bitcast of the 64-bit floating point value. The various operands
4593 // that accept floats can check whether the value is valid for them
4594 // via the standard is*() predicates.
4596 SMLoc S = Parser.getTok().getLoc();
4598 if (Parser.getTok().isNot(AsmToken::Hash) &&
4599 Parser.getTok().isNot(AsmToken::Dollar))
4600 return MatchOperand_NoMatch;
4602 // Disambiguate the VMOV forms that can accept an FP immediate.
4603 // vmov.f32 <sreg>, #imm
4604 // vmov.f64 <dreg>, #imm
4605 // vmov.f32 <dreg>, #imm @ vector f32x2
4606 // vmov.f32 <qreg>, #imm @ vector f32x4
4608 // There are also the NEON VMOV instructions which expect an
4609 // integer constant. Make sure we don't try to parse an FPImm
4611 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4612 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4613 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4614 TyOp->getToken() != ".f64"))
4615 return MatchOperand_NoMatch;
4617 Parser.Lex(); // Eat '#' or '$'.
4619 // Handle negation, as that still comes through as a separate token.
4620 bool isNegative = false;
4621 if (Parser.getTok().is(AsmToken::Minus)) {
4625 const AsmToken &Tok = Parser.getTok();
4626 SMLoc Loc = Tok.getLoc();
4627 if (Tok.is(AsmToken::Real)) {
4628 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
4629 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4630 // If we had a '-' in front, toggle the sign bit.
4631 IntVal ^= (uint64_t)isNegative << 31;
4632 Parser.Lex(); // Eat the token.
4633 Operands.push_back(ARMOperand::CreateImm(
4634 MCConstantExpr::Create(IntVal, getContext()),
4635 S, Parser.getTok().getLoc()));
4636 return MatchOperand_Success;
4638 // Also handle plain integers. Instructions which allow floating point
4639 // immediates also allow a raw encoded 8-bit value.
4640 if (Tok.is(AsmToken::Integer)) {
4641 int64_t Val = Tok.getIntVal();
4642 Parser.Lex(); // Eat the token.
4643 if (Val > 255 || Val < 0) {
4644 Error(Loc, "encoded floating point value out of range");
4645 return MatchOperand_ParseFail;
4647 double RealVal = ARM_AM::getFPImmFloat(Val);
4648 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4649 Operands.push_back(ARMOperand::CreateImm(
4650 MCConstantExpr::Create(Val, getContext()), S,
4651 Parser.getTok().getLoc()));
4652 return MatchOperand_Success;
4655 Error(Loc, "invalid floating point immediate");
4656 return MatchOperand_ParseFail;
4659 /// Parse a arm instruction operand. For now this parses the operand regardless
4660 /// of the mnemonic.
4661 bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
4662 StringRef Mnemonic) {
4665 // Check if the current operand has a custom associated parser, if so, try to
4666 // custom parse the operand, or fallback to the general approach.
4667 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4668 if (ResTy == MatchOperand_Success)
4670 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4671 // there was a match, but an error occurred, in which case, just return that
4672 // the operand parsing failed.
4673 if (ResTy == MatchOperand_ParseFail)
4676 switch (getLexer().getKind()) {
4678 Error(Parser.getTok().getLoc(), "unexpected token in operand");
4680 case AsmToken::Identifier: {
4681 // If we've seen a branch mnemonic, the next operand must be a label. This
4682 // is true even if the label is a register name. So "br r1" means branch to
4684 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4686 if (!tryParseRegisterWithWriteBack(Operands))
4688 int Res = tryParseShiftRegister(Operands);
4689 if (Res == 0) // success
4691 else if (Res == -1) // irrecoverable error
4693 // If this is VMRS, check for the apsr_nzcv operand.
4694 if (Mnemonic == "vmrs" &&
4695 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4696 S = Parser.getTok().getLoc();
4698 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4703 // Fall though for the Identifier case that is not a register or a
4706 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
4707 case AsmToken::Integer: // things like 1f and 2b as a branch targets
4708 case AsmToken::String: // quoted label names.
4709 case AsmToken::Dot: { // . as a branch target
4710 // This was not a register so parse other operands that start with an
4711 // identifier (like labels) as expressions and create them as immediates.
4712 const MCExpr *IdVal;
4713 S = Parser.getTok().getLoc();
4714 if (getParser().parseExpression(IdVal))
4716 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4717 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4720 case AsmToken::LBrac:
4721 return parseMemory(Operands);
4722 case AsmToken::LCurly:
4723 return parseRegisterList(Operands);
4724 case AsmToken::Dollar:
4725 case AsmToken::Hash: {
4726 // #42 -> immediate.
4727 S = Parser.getTok().getLoc();
4730 if (Parser.getTok().isNot(AsmToken::Colon)) {
4731 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4732 const MCExpr *ImmVal;
4733 if (getParser().parseExpression(ImmVal))
4735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4737 int32_t Val = CE->getValue();
4738 if (isNegative && Val == 0)
4739 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4741 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4742 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4744 // There can be a trailing '!' on operands that we want as a separate
4745 // '!' Token operand. Handle that here. For example, the compatibility
4746 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4747 if (Parser.getTok().is(AsmToken::Exclaim)) {
4748 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4749 Parser.getTok().getLoc()));
4750 Parser.Lex(); // Eat exclaim token
4754 // w/ a ':' after the '#', it's just like a plain ':'.
4757 case AsmToken::Colon: {
4758 // ":lower16:" and ":upper16:" expression prefixes
4759 // FIXME: Check it's an expression prefix,
4760 // e.g. (FOO - :lower16:BAR) isn't legal.
4761 ARMMCExpr::VariantKind RefKind;
4762 if (parsePrefix(RefKind))
4765 const MCExpr *SubExprVal;
4766 if (getParser().parseExpression(SubExprVal))
4769 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4771 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4772 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
4775 case AsmToken::Equal: {
4776 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4777 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4779 const MCSection *Section =
4780 getParser().getStreamer().getCurrentSection().first;
4782 Parser.Lex(); // Eat '='
4783 const MCExpr *SubExprVal;
4784 if (getParser().parseExpression(SubExprVal))
4786 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4788 const MCExpr *CPLoc =
4789 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4790 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4796 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
4797 // :lower16: and :upper16:.
4798 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
4799 RefKind = ARMMCExpr::VK_ARM_None;
4801 // :lower16: and :upper16: modifiers
4802 assert(getLexer().is(AsmToken::Colon) && "expected a :");
4803 Parser.Lex(); // Eat ':'
4805 if (getLexer().isNot(AsmToken::Identifier)) {
4806 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4810 StringRef IDVal = Parser.getTok().getIdentifier();
4811 if (IDVal == "lower16") {
4812 RefKind = ARMMCExpr::VK_ARM_LO16;
4813 } else if (IDVal == "upper16") {
4814 RefKind = ARMMCExpr::VK_ARM_HI16;
4816 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4821 if (getLexer().isNot(AsmToken::Colon)) {
4822 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4825 Parser.Lex(); // Eat the last ':'
4829 /// \brief Given a mnemonic, split out possible predication code and carry
4830 /// setting letters to form a canonical mnemonic and flags.
4832 // FIXME: Would be nice to autogen this.
4833 // FIXME: This is a bit of a maze of special cases.
4834 StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
4835 unsigned &PredicationCode,
4837 unsigned &ProcessorIMod,
4838 StringRef &ITMask) {
4839 PredicationCode = ARMCC::AL;
4840 CarrySetting = false;
4843 // Ignore some mnemonics we know aren't predicated forms.
4845 // FIXME: Would be nice to autogen this.
4846 if ((Mnemonic == "movs" && isThumb()) ||
4847 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4848 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4849 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4850 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4851 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
4852 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4853 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
4854 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4855 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
4856 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4857 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4858 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
4861 // First, split out any predication code. Ignore mnemonics we know aren't
4862 // predicated but do have a carry-set and so weren't caught above.
4863 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
4864 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
4865 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
4866 Mnemonic != "sbcs" && Mnemonic != "rscs") {
4867 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4868 .Case("eq", ARMCC::EQ)
4869 .Case("ne", ARMCC::NE)
4870 .Case("hs", ARMCC::HS)
4871 .Case("cs", ARMCC::HS)
4872 .Case("lo", ARMCC::LO)
4873 .Case("cc", ARMCC::LO)
4874 .Case("mi", ARMCC::MI)
4875 .Case("pl", ARMCC::PL)
4876 .Case("vs", ARMCC::VS)
4877 .Case("vc", ARMCC::VC)
4878 .Case("hi", ARMCC::HI)
4879 .Case("ls", ARMCC::LS)
4880 .Case("ge", ARMCC::GE)
4881 .Case("lt", ARMCC::LT)
4882 .Case("gt", ARMCC::GT)
4883 .Case("le", ARMCC::LE)
4884 .Case("al", ARMCC::AL)
4887 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4888 PredicationCode = CC;
4892 // Next, determine if we have a carry setting bit. We explicitly ignore all
4893 // the instructions we know end in 's'.
4894 if (Mnemonic.endswith("s") &&
4895 !(Mnemonic == "cps" || Mnemonic == "mls" ||
4896 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4897 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4898 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
4899 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
4900 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
4901 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
4902 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
4903 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
4904 (Mnemonic == "movs" && isThumb()))) {
4905 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4906 CarrySetting = true;
4909 // The "cps" instruction can have a interrupt mode operand which is glued into
4910 // the mnemonic. Check if this is the case, split it and parse the imod op
4911 if (Mnemonic.startswith("cps")) {
4912 // Split out any imod code.
4914 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4915 .Case("ie", ARM_PROC::IE)
4916 .Case("id", ARM_PROC::ID)
4919 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4920 ProcessorIMod = IMod;
4924 // The "it" instruction has the condition mask on the end of the mnemonic.
4925 if (Mnemonic.startswith("it")) {
4926 ITMask = Mnemonic.slice(2, Mnemonic.size());
4927 Mnemonic = Mnemonic.slice(0, 2);
4933 /// \brief Given a canonical mnemonic, determine if the instruction ever allows
4934 /// inclusion of carry set or predication code operands.
4936 // FIXME: It would be nice to autogen this.
4938 getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4939 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
4940 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4941 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
4942 Mnemonic == "add" || Mnemonic == "adc" ||
4943 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
4944 Mnemonic == "orr" || Mnemonic == "mvn" ||
4945 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
4946 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
4947 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
4948 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
4949 Mnemonic == "mla" || Mnemonic == "smlal" ||
4950 Mnemonic == "umlal" || Mnemonic == "umull"))) {
4951 CanAcceptCarrySet = true;
4953 CanAcceptCarrySet = false;
4955 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4956 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
4957 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
4958 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4959 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
4960 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4961 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
4962 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4963 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4964 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
4965 // These mnemonics are never predicable
4966 CanAcceptPredicationCode = false;
4967 } else if (!isThumb()) {
4968 // Some instructions are only predicable in Thumb mode
4969 CanAcceptPredicationCode
4970 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4971 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4972 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4973 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4974 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4975 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4976 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4977 } else if (isThumbOne()) {
4979 CanAcceptPredicationCode = Mnemonic != "movs";
4981 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
4983 CanAcceptPredicationCode = true;
4986 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4987 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4988 // FIXME: This is all horribly hacky. We really need a better way to deal
4989 // with optional operands like this in the matcher table.
4991 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4992 // another does not. Specifically, the MOVW instruction does not. So we
4993 // special case it here and remove the defaulted (non-setting) cc_out
4994 // operand if that's the instruction we're trying to match.
4996 // We do this as post-processing of the explicit operands rather than just
4997 // conditionally adding the cc_out in the first place because we need
4998 // to check the type of the parsed immediate operand.
4999 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
5000 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
5001 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
5002 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5005 // Register-register 'add' for thumb does not have a cc_out operand
5006 // when there are only two register operands.
5007 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
5008 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5009 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5010 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
5012 // Register-register 'add' for thumb does not have a cc_out operand
5013 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5014 // have to check the immediate range here since Thumb2 has a variant
5015 // that can handle a different range and has a cc_out operand.
5016 if (((isThumb() && Mnemonic == "add") ||
5017 (isThumbTwo() && Mnemonic == "sub")) &&
5018 Operands.size() == 6 &&
5019 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5020 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5021 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
5022 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5023 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
5024 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
5026 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5027 // imm0_4095 variant. That's the least-preferred variant when
5028 // selecting via the generic "add" mnemonic, so to know that we
5029 // should remove the cc_out operand, we have to explicitly check that
5030 // it's not one of the other variants. Ugh.
5031 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
5032 Operands.size() == 6 &&
5033 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5034 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5035 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5036 // Nest conditions rather than one big 'if' statement for readability.
5038 // If both registers are low, we're in an IT block, and the immediate is
5039 // in range, we should use encoding T1 instead, which has a cc_out.
5041 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
5042 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5043 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5045 // Check against T3. If the second register is the PC, this is an
5046 // alternate form of ADR, which uses encoding T4, so check for that too.
5047 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5048 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5051 // Otherwise, we use encoding T4, which does not have a cc_out
5056 // The thumb2 multiply instruction doesn't have a CCOut register, so
5057 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5058 // use the 16-bit encoding or not.
5059 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5060 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5061 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5062 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5063 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5064 // If the registers aren't low regs, the destination reg isn't the
5065 // same as one of the source regs, or the cc_out operand is zero
5066 // outside of an IT block, we have to use the 32-bit encoding, so
5067 // remove the cc_out operand.
5068 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5069 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5070 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
5072 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5073 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5074 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5075 static_cast<ARMOperand*>(Operands[4])->getReg())))
5078 // Also check the 'mul' syntax variant that doesn't specify an explicit
5079 // destination register.
5080 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5081 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5082 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5083 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5084 // If the registers aren't low regs or the cc_out operand is zero
5085 // outside of an IT block, we have to use the 32-bit encoding, so
5086 // remove the cc_out operand.
5087 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5088 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5094 // Register-register 'add/sub' for thumb does not have a cc_out operand
5095 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5096 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5097 // right, this will result in better diagnostics (which operand is off)
5099 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5100 (Operands.size() == 5 || Operands.size() == 6) &&
5101 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5102 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
5103 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5104 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5105 (Operands.size() == 6 &&
5106 static_cast<ARMOperand*>(Operands[5])->isImm())))
5112 bool ARMAsmParser::shouldOmitPredicateOperand(
5113 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5114 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5115 unsigned RegIdx = 3;
5116 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5117 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5118 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5119 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5122 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5123 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5124 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5125 ARMMCRegisterClasses[ARM::QPRRegClassID]
5126 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5132 static bool isDataTypeToken(StringRef Tok) {
5133 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5134 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5135 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5136 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5137 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5138 Tok == ".f" || Tok == ".d";
5141 // FIXME: This bit should probably be handled via an explicit match class
5142 // in the .td files that matches the suffix instead of having it be
5143 // a literal string token the way it is now.
5144 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5145 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5147 static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5148 unsigned VariantID);
5150 static bool RequiresVFPRegListValidation(StringRef Inst,
5151 bool &AcceptSinglePrecisionOnly,
5152 bool &AcceptDoublePrecisionOnly) {
5153 if (Inst.size() < 7)
5156 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5157 StringRef AddressingMode = Inst.substr(4, 2);
5158 if (AddressingMode == "ia" || AddressingMode == "db" ||
5159 AddressingMode == "ea" || AddressingMode == "fd") {
5160 AcceptSinglePrecisionOnly = Inst[6] == 's';
5161 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5169 /// Parse an arm instruction mnemonic followed by its operands.
5170 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5172 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5173 // FIXME: Can this be done via tablegen in some fashion?
5174 bool RequireVFPRegisterListCheck;
5175 bool AcceptSinglePrecisionOnly;
5176 bool AcceptDoublePrecisionOnly;
5177 RequireVFPRegisterListCheck =
5178 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5179 AcceptDoublePrecisionOnly);
5181 // Apply mnemonic aliases before doing anything else, as the destination
5182 // mnemonic may include suffices and we want to handle them normally.
5183 // The generic tblgen'erated code does this later, at the start of
5184 // MatchInstructionImpl(), but that's too late for aliases that include
5185 // any sort of suffix.
5186 unsigned AvailableFeatures = getAvailableFeatures();
5187 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5188 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
5190 // First check for the ARM-specific .req directive.
5191 if (Parser.getTok().is(AsmToken::Identifier) &&
5192 Parser.getTok().getIdentifier() == ".req") {
5193 parseDirectiveReq(Name, NameLoc);
5194 // We always return 'error' for this, as we're done with this
5195 // statement and don't need to match the 'instruction."
5199 // Create the leading tokens for the mnemonic, split by '.' characters.
5200 size_t Start = 0, Next = Name.find('.');
5201 StringRef Mnemonic = Name.slice(Start, Next);
5203 // Split out the predication code and carry setting flag from the mnemonic.
5204 unsigned PredicationCode;
5205 unsigned ProcessorIMod;
5208 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
5209 ProcessorIMod, ITMask);
5211 // In Thumb1, only the branch (B) instruction can be predicated.
5212 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
5213 Parser.eatToEndOfStatement();
5214 return Error(NameLoc, "conditional execution not supported in Thumb1");
5217 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5219 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5220 // is the mask as it will be for the IT encoding if the conditional
5221 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5222 // where the conditional bit0 is zero, the instruction post-processing
5223 // will adjust the mask accordingly.
5224 if (Mnemonic == "it") {
5225 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5226 if (ITMask.size() > 3) {
5227 Parser.eatToEndOfStatement();
5228 return Error(Loc, "too many conditions on IT instruction");
5231 for (unsigned i = ITMask.size(); i != 0; --i) {
5232 char pos = ITMask[i - 1];
5233 if (pos != 't' && pos != 'e') {
5234 Parser.eatToEndOfStatement();
5235 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
5238 if (ITMask[i - 1] == 't')
5241 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
5244 // FIXME: This is all a pretty gross hack. We should automatically handle
5245 // optional operands like this via tblgen.
5247 // Next, add the CCOut and ConditionCode operands, if needed.
5249 // For mnemonics which can ever incorporate a carry setting bit or predication
5250 // code, our matching model involves us always generating CCOut and
5251 // ConditionCode operands to match the mnemonic "as written" and then we let
5252 // the matcher deal with finding the right instruction or generating an
5253 // appropriate error.
5254 bool CanAcceptCarrySet, CanAcceptPredicationCode;
5255 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
5257 // If we had a carry-set on an instruction that can't do that, issue an
5259 if (!CanAcceptCarrySet && CarrySetting) {
5260 Parser.eatToEndOfStatement();
5261 return Error(NameLoc, "instruction '" + Mnemonic +
5262 "' can not set flags, but 's' suffix specified");
5264 // If we had a predication code on an instruction that can't do that, issue an
5266 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5267 Parser.eatToEndOfStatement();
5268 return Error(NameLoc, "instruction '" + Mnemonic +
5269 "' is not predicable, but condition code specified");
5272 // Add the carry setting operand, if necessary.
5273 if (CanAcceptCarrySet) {
5274 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
5275 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
5279 // Add the predication code operand, if necessary.
5280 if (CanAcceptPredicationCode) {
5281 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5283 Operands.push_back(ARMOperand::CreateCondCode(
5284 ARMCC::CondCodes(PredicationCode), Loc));
5287 // Add the processor imod operand, if necessary.
5288 if (ProcessorIMod) {
5289 Operands.push_back(ARMOperand::CreateImm(
5290 MCConstantExpr::Create(ProcessorIMod, getContext()),
5294 // Add the remaining tokens in the mnemonic.
5295 while (Next != StringRef::npos) {
5297 Next = Name.find('.', Start + 1);
5298 StringRef ExtraToken = Name.slice(Start, Next);
5300 // Some NEON instructions have an optional datatype suffix that is
5301 // completely ignored. Check for that.
5302 if (isDataTypeToken(ExtraToken) &&
5303 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5306 // For for ARM mode generate an error if the .n qualifier is used.
5307 if (ExtraToken == ".n" && !isThumb()) {
5308 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5309 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5313 // The .n qualifier is always discarded as that is what the tables
5314 // and matcher expect. In ARM mode the .w qualifier has no effect,
5315 // so discard it to avoid errors that can be caused by the matcher.
5316 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
5317 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5318 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5322 // Read the remaining operands.
5323 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5324 // Read the first operand.
5325 if (parseOperand(Operands, Mnemonic)) {
5326 Parser.eatToEndOfStatement();
5330 while (getLexer().is(AsmToken::Comma)) {
5331 Parser.Lex(); // Eat the comma.
5333 // Parse and remember the operand.
5334 if (parseOperand(Operands, Mnemonic)) {
5335 Parser.eatToEndOfStatement();
5341 if (getLexer().isNot(AsmToken::EndOfStatement)) {
5342 SMLoc Loc = getLexer().getLoc();
5343 Parser.eatToEndOfStatement();
5344 return Error(Loc, "unexpected token in argument list");
5347 Parser.Lex(); // Consume the EndOfStatement
5349 if (RequireVFPRegisterListCheck) {
5350 ARMOperand *Op = static_cast<ARMOperand*>(Operands.back());
5351 if (AcceptSinglePrecisionOnly && !Op->isSPRRegList())
5352 return Error(Op->getStartLoc(),
5353 "VFP/Neon single precision register expected");
5354 if (AcceptDoublePrecisionOnly && !Op->isDPRRegList())
5355 return Error(Op->getStartLoc(),
5356 "VFP/Neon double precision register expected");
5359 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5360 // do and don't have a cc_out optional-def operand. With some spot-checks
5361 // of the operand list, we can figure out which variant we're trying to
5362 // parse and adjust accordingly before actually matching. We shouldn't ever
5363 // try to remove a cc_out operand that was explicitly set on the the
5364 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5365 // table driven matcher doesn't fit well with the ARM instruction set.
5366 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
5367 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5368 Operands.erase(Operands.begin() + 1);
5372 // Some instructions have the same mnemonic, but don't always
5373 // have a predicate. Distinguish them here and delete the
5374 // predicate if needed.
5375 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5376 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5377 Operands.erase(Operands.begin() + 1);
5381 // ARM mode 'blx' need special handling, as the register operand version
5382 // is predicable, but the label operand version is not. So, we can't rely
5383 // on the Mnemonic based checking to correctly figure out when to put
5384 // a k_CondCode operand in the list. If we're trying to match the label
5385 // version, remove the k_CondCode operand here.
5386 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5387 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5388 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5389 Operands.erase(Operands.begin() + 1);
5393 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5394 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5395 // a single GPRPair reg operand is used in the .td file to replace the two
5396 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5397 // expressed as a GPRPair, so we have to manually merge them.
5398 // FIXME: We would really like to be able to tablegen'erate this.
5399 if (!isThumb() && Operands.size() > 4 &&
5400 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5401 Mnemonic == "stlexd")) {
5402 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
5403 unsigned Idx = isLoad ? 2 : 3;
5404 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5405 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5407 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5408 // Adjust only if Op1 and Op2 are GPRs.
5409 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5410 MRC.contains(Op2->getReg())) {
5411 unsigned Reg1 = Op1->getReg();
5412 unsigned Reg2 = Op2->getReg();
5413 unsigned Rt = MRI->getEncodingValue(Reg1);
5414 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5416 // Rt2 must be Rt + 1 and Rt must be even.
5417 if (Rt + 1 != Rt2 || (Rt & 1)) {
5418 Error(Op2->getStartLoc(), isLoad ?
5419 "destination operands must be sequential" :
5420 "source operands must be sequential");
5423 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5424 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5425 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5426 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5427 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5433 // FIXME: As said above, this is all a pretty gross hack. This instruction
5434 // does not fit with other "subs" and tblgen.
5435 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5436 // so the Mnemonic is the original name "subs" and delete the predicate
5437 // operand so it will match the table entry.
5438 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5439 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5440 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5441 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5442 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5443 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5444 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5445 Operands.erase(Operands.begin());
5447 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5449 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5450 Operands.erase(Operands.begin() + 1);
5456 // Validate context-sensitive operand constraints.
5458 // return 'true' if register list contains non-low GPR registers,
5459 // 'false' otherwise. If Reg is in the register list or is HiReg, set
5460 // 'containsReg' to true.
5461 static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5462 unsigned HiReg, bool &containsReg) {
5463 containsReg = false;
5464 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5465 unsigned OpReg = Inst.getOperand(i).getReg();
5468 // Anything other than a low register isn't legal here.
5469 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5475 // Check if the specified regisgter is in the register list of the inst,
5476 // starting at the indicated operand number.
5477 static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5478 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5479 unsigned OpReg = Inst.getOperand(i).getReg();
5486 // Return true if instruction has the interesting property of being
5487 // allowed in IT blocks, but not being predicable.
5488 static bool instIsBreakpoint(const MCInst &Inst) {
5489 return Inst.getOpcode() == ARM::tBKPT ||
5490 Inst.getOpcode() == ARM::BKPT ||
5491 Inst.getOpcode() == ARM::tHLT ||
5492 Inst.getOpcode() == ARM::HLT;
5496 // FIXME: We would really like to be able to tablegen'erate this.
5498 validateInstruction(MCInst &Inst,
5499 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5500 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
5501 SMLoc Loc = Operands[0]->getStartLoc();
5503 // Check the IT block state first.
5504 // NOTE: BKPT and HLT instructions have the interesting property of being
5505 // allowed in IT blocks, but not being predicable. They just always execute.
5506 if (inITBlock() && !instIsBreakpoint(Inst)) {
5508 if (ITState.FirstCond)
5509 ITState.FirstCond = false;
5511 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
5512 // The instruction must be predicable.
5513 if (!MCID.isPredicable())
5514 return Error(Loc, "instructions in IT block must be predicable");
5515 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5516 unsigned ITCond = Bit ? ITState.Cond :
5517 ARMCC::getOppositeCondition(ITState.Cond);
5518 if (Cond != ITCond) {
5519 // Find the condition code Operand to get its SMLoc information.
5521 for (unsigned I = 1; I < Operands.size(); ++I)
5522 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5523 CondLoc = Operands[I]->getStartLoc();
5524 return Error(CondLoc, "incorrect condition in IT block; got '" +
5525 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5526 "', but expected '" +
5527 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5529 // Check for non-'al' condition codes outside of the IT block.
5530 } else if (isThumbTwo() && MCID.isPredicable() &&
5531 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
5532 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5533 Inst.getOpcode() != ARM::t2Bcc)
5534 return Error(Loc, "predicated instructions must be in IT block");
5536 const unsigned Opcode = Inst.getOpcode();
5540 case ARM::LDRD_POST: {
5541 const unsigned RtReg = Inst.getOperand(0).getReg();
5544 if (RtReg == ARM::LR)
5545 return Error(Operands[3]->getStartLoc(),
5548 const unsigned Rt = MRI->getEncodingValue(RtReg);
5549 // Rt must be even-numbered.
5551 return Error(Operands[3]->getStartLoc(),
5552 "Rt must be even-numbered");
5554 // Rt2 must be Rt + 1.
5555 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5557 return Error(Operands[3]->getStartLoc(),
5558 "destination operands must be sequential");
5560 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5561 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5562 // For addressing modes with writeback, the base register needs to be
5563 // different from the destination registers.
5564 if (Rn == Rt || Rn == Rt2)
5565 return Error(Operands[3]->getStartLoc(),
5566 "base register needs to be different from destination "
5573 case ARM::t2LDRD_PRE:
5574 case ARM::t2LDRD_POST: {
5575 // Rt2 must be different from Rt.
5576 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5577 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5579 return Error(Operands[3]->getStartLoc(),
5580 "destination operands can't be identical");
5584 // Rt2 must be Rt + 1.
5585 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5586 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5588 return Error(Operands[3]->getStartLoc(),
5589 "source operands must be sequential");
5593 case ARM::STRD_POST: {
5594 // Rt2 must be Rt + 1.
5595 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5596 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
5598 return Error(Operands[3]->getStartLoc(),
5599 "source operands must be sequential");
5604 // Width must be in range [1, 32-lsb].
5605 unsigned LSB = Inst.getOperand(2).getImm();
5606 unsigned Widthm1 = Inst.getOperand(3).getImm();
5607 if (Widthm1 >= 32 - LSB)
5608 return Error(Operands[5]->getStartLoc(),
5609 "bitfield width must be in range [1,32-lsb]");
5612 // Notionally handles ARM::tLDMIA_UPD too.
5614 // If we're parsing Thumb2, the .w variant is available and handles
5615 // most cases that are normally illegal for a Thumb1 LDM instruction.
5616 // We'll make the transformation in processInstruction() if necessary.
5618 // Thumb LDM instructions are writeback iff the base register is not
5619 // in the register list.
5620 unsigned Rn = Inst.getOperand(0).getReg();
5621 bool HasWritebackToken =
5622 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5623 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
5624 bool ListContainsBase;
5625 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5626 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
5627 "registers must be in range r0-r7");
5628 // If we should have writeback, then there should be a '!' token.
5629 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
5630 return Error(Operands[2]->getStartLoc(),
5631 "writeback operator '!' expected");
5632 // If we should not have writeback, there must not be a '!'. This is
5633 // true even for the 32-bit wide encodings.
5634 if (ListContainsBase && HasWritebackToken)
5635 return Error(Operands[3]->getStartLoc(),
5636 "writeback operator '!' not allowed when base register "
5637 "in register list");
5641 case ARM::LDMIA_UPD:
5642 case ARM::LDMDB_UPD:
5643 case ARM::LDMIB_UPD:
5644 case ARM::LDMDA_UPD:
5645 // ARM variants loading and updating the same register are only officially
5646 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5650 case ARM::t2LDMIA_UPD:
5651 case ARM::t2LDMDB_UPD:
5652 case ARM::t2STMIA_UPD:
5653 case ARM::t2STMDB_UPD: {
5654 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5655 return Error(Operands.back()->getStartLoc(),
5656 "writeback register not allowed in register list");
5659 case ARM::sysLDMIA_UPD:
5660 case ARM::sysLDMDA_UPD:
5661 case ARM::sysLDMDB_UPD:
5662 case ARM::sysLDMIB_UPD:
5663 if (!listContainsReg(Inst, 3, ARM::PC))
5664 return Error(Operands[4]->getStartLoc(),
5665 "writeback register only allowed on system LDM "
5666 "if PC in register-list");
5668 case ARM::sysSTMIA_UPD:
5669 case ARM::sysSTMDA_UPD:
5670 case ARM::sysSTMDB_UPD:
5671 case ARM::sysSTMIB_UPD:
5672 return Error(Operands[2]->getStartLoc(),
5673 "system STM cannot have writeback register");
5676 // The second source operand must be the same register as the destination
5679 // In this case, we must directly check the parsed operands because the
5680 // cvtThumbMultiply() function is written in such a way that it guarantees
5681 // this first statement is always true for the new Inst. Essentially, the
5682 // destination is unconditionally copied into the second source operand
5683 // without checking to see if it matches what we actually parsed.
5684 if (Operands.size() == 6 &&
5685 (((ARMOperand*)Operands[3])->getReg() !=
5686 ((ARMOperand*)Operands[5])->getReg()) &&
5687 (((ARMOperand*)Operands[3])->getReg() !=
5688 ((ARMOperand*)Operands[4])->getReg())) {
5689 return Error(Operands[3]->getStartLoc(),
5690 "destination register must match source register");
5694 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5695 // so only issue a diagnostic for thumb1. The instructions will be
5696 // switched to the t2 encodings in processInstruction() if necessary.
5698 bool ListContainsBase;
5699 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
5701 return Error(Operands[2]->getStartLoc(),
5702 "registers must be in range r0-r7 or pc");
5706 bool ListContainsBase;
5707 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
5709 return Error(Operands[2]->getStartLoc(),
5710 "registers must be in range r0-r7 or lr");
5713 case ARM::tSTMIA_UPD: {
5714 bool ListContainsBase, InvalidLowList;
5715 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5716 0, ListContainsBase);
5717 if (InvalidLowList && !isThumbTwo())
5718 return Error(Operands[4]->getStartLoc(),
5719 "registers must be in range r0-r7");
5721 // This would be converted to a 32-bit stm, but that's not valid if the
5722 // writeback register is in the list.
5723 if (InvalidLowList && ListContainsBase)
5724 return Error(Operands[4]->getStartLoc(),
5725 "writeback operator '!' not allowed when base register "
5726 "in register list");
5729 case ARM::tADDrSP: {
5730 // If the non-SP source operand and the destination operand are not the
5731 // same, we need thumb2 (for the wide encoding), or we have an error.
5732 if (!isThumbTwo() &&
5733 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5734 return Error(Operands[4]->getStartLoc(),
5735 "source register must be the same as destination");
5739 // Final range checking for Thumb unconditional branch instructions.
5741 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5742 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5745 int op = (Operands[2]->isImm()) ? 2 : 3;
5746 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5747 return Error(Operands[op]->getStartLoc(), "branch target out of range");
5750 // Final range checking for Thumb conditional branch instructions.
5752 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5753 return Error(Operands[2]->getStartLoc(), "branch target out of range");
5756 int Op = (Operands[2]->isImm()) ? 2 : 3;
5757 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5758 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
5766 static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
5768 default: llvm_unreachable("unexpected opcode!");
5770 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5771 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5772 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5773 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5774 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5775 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5776 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5777 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5778 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
5781 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5782 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5783 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5784 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5785 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5787 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5788 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5789 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5790 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5791 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
5793 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5794 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5795 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5796 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5797 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
5800 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5801 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5802 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5803 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5804 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5805 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5806 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5807 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5808 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5809 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5810 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5811 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5812 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5813 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5814 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
5817 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5818 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5819 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5820 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5821 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5822 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5823 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5824 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5825 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5826 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5827 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5828 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5829 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5830 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5831 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5832 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5833 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5834 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
5837 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5838 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5839 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5840 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5841 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5842 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5843 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5844 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5845 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5846 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5847 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5848 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5849 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5850 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5851 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5854 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5855 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5856 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5857 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5858 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5859 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5860 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5861 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5862 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5863 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5864 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5865 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5866 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5867 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5868 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5869 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5870 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5871 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
5875 static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
5877 default: llvm_unreachable("unexpected opcode!");
5879 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5880 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5881 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5882 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5883 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5884 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5885 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5886 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5887 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
5890 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5891 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5892 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5893 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5894 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5895 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5896 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5897 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5898 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5899 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5900 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5901 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5902 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5903 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5904 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
5907 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5908 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5909 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5910 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5911 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5912 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5913 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5914 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5915 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5916 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5917 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5918 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5919 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5920 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5921 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5922 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5923 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5924 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5927 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5928 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5929 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5930 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5931 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5932 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5933 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5934 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5935 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5936 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5937 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5938 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5939 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5940 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5941 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
5944 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5945 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5946 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5947 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5948 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5949 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5950 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5951 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5952 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5953 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5954 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5955 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5956 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5957 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5958 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5959 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5960 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5961 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
5964 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5965 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5966 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5967 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5968 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5969 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5970 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5971 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5972 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5973 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5974 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5975 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5976 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5977 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5978 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5981 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5982 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5983 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5984 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5985 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5986 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5987 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5988 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5989 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5990 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5991 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5992 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5993 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5994 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5995 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5996 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5997 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5998 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6001 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6002 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6003 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6004 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6005 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6006 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6007 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6008 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6009 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6010 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6011 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6012 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6013 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6014 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6015 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6016 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6017 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6018 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
6023 processInstruction(MCInst &Inst,
6024 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
6025 switch (Inst.getOpcode()) {
6026 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6028 if (Inst.getOperand(1).getReg() != ARM::PC ||
6029 Inst.getOperand(5).getReg() != 0)
6032 TmpInst.setOpcode(ARM::ADR);
6033 TmpInst.addOperand(Inst.getOperand(0));
6034 TmpInst.addOperand(Inst.getOperand(2));
6035 TmpInst.addOperand(Inst.getOperand(3));
6036 TmpInst.addOperand(Inst.getOperand(4));
6040 // Aliases for alternate PC+imm syntax of LDR instructions.
6041 case ARM::t2LDRpcrel:
6042 // Select the narrow version if the immediate will fit.
6043 if (Inst.getOperand(1).getImm() > 0 &&
6044 Inst.getOperand(1).getImm() <= 0xff &&
6045 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
6046 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
6047 Inst.setOpcode(ARM::tLDRpci);
6049 Inst.setOpcode(ARM::t2LDRpci);
6051 case ARM::t2LDRBpcrel:
6052 Inst.setOpcode(ARM::t2LDRBpci);
6054 case ARM::t2LDRHpcrel:
6055 Inst.setOpcode(ARM::t2LDRHpci);
6057 case ARM::t2LDRSBpcrel:
6058 Inst.setOpcode(ARM::t2LDRSBpci);
6060 case ARM::t2LDRSHpcrel:
6061 Inst.setOpcode(ARM::t2LDRSHpci);
6063 // Handle NEON VST complex aliases.
6064 case ARM::VST1LNdWB_register_Asm_8:
6065 case ARM::VST1LNdWB_register_Asm_16:
6066 case ARM::VST1LNdWB_register_Asm_32: {
6068 // Shuffle the operands around so the lane index operand is in the
6071 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6072 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6073 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6074 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6075 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6076 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6077 TmpInst.addOperand(Inst.getOperand(1)); // lane
6078 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6079 TmpInst.addOperand(Inst.getOperand(6));
6084 case ARM::VST2LNdWB_register_Asm_8:
6085 case ARM::VST2LNdWB_register_Asm_16:
6086 case ARM::VST2LNdWB_register_Asm_32:
6087 case ARM::VST2LNqWB_register_Asm_16:
6088 case ARM::VST2LNqWB_register_Asm_32: {
6090 // Shuffle the operands around so the lane index operand is in the
6093 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6094 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6095 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6096 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6097 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6098 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6099 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6101 TmpInst.addOperand(Inst.getOperand(1)); // lane
6102 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6103 TmpInst.addOperand(Inst.getOperand(6));
6108 case ARM::VST3LNdWB_register_Asm_8:
6109 case ARM::VST3LNdWB_register_Asm_16:
6110 case ARM::VST3LNdWB_register_Asm_32:
6111 case ARM::VST3LNqWB_register_Asm_16:
6112 case ARM::VST3LNqWB_register_Asm_32: {
6114 // Shuffle the operands around so the lane index operand is in the
6117 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6118 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6119 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6120 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6121 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6122 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6123 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6125 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 TmpInst.addOperand(Inst.getOperand(1)); // lane
6128 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6129 TmpInst.addOperand(Inst.getOperand(6));
6134 case ARM::VST4LNdWB_register_Asm_8:
6135 case ARM::VST4LNdWB_register_Asm_16:
6136 case ARM::VST4LNdWB_register_Asm_32:
6137 case ARM::VST4LNqWB_register_Asm_16:
6138 case ARM::VST4LNqWB_register_Asm_32: {
6140 // Shuffle the operands around so the lane index operand is in the
6143 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6144 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6145 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6146 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6147 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6148 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6153 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6155 TmpInst.addOperand(Inst.getOperand(1)); // lane
6156 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6157 TmpInst.addOperand(Inst.getOperand(6));
6162 case ARM::VST1LNdWB_fixed_Asm_8:
6163 case ARM::VST1LNdWB_fixed_Asm_16:
6164 case ARM::VST1LNdWB_fixed_Asm_32: {
6166 // Shuffle the operands around so the lane index operand is in the
6169 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6170 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6171 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6172 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6173 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6174 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6175 TmpInst.addOperand(Inst.getOperand(1)); // lane
6176 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6177 TmpInst.addOperand(Inst.getOperand(5));
6182 case ARM::VST2LNdWB_fixed_Asm_8:
6183 case ARM::VST2LNdWB_fixed_Asm_16:
6184 case ARM::VST2LNdWB_fixed_Asm_32:
6185 case ARM::VST2LNqWB_fixed_Asm_16:
6186 case ARM::VST2LNqWB_fixed_Asm_32: {
6188 // Shuffle the operands around so the lane index operand is in the
6191 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6192 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6193 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6194 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6195 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6196 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6197 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 TmpInst.addOperand(Inst.getOperand(1)); // lane
6200 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6201 TmpInst.addOperand(Inst.getOperand(5));
6206 case ARM::VST3LNdWB_fixed_Asm_8:
6207 case ARM::VST3LNdWB_fixed_Asm_16:
6208 case ARM::VST3LNdWB_fixed_Asm_32:
6209 case ARM::VST3LNqWB_fixed_Asm_16:
6210 case ARM::VST3LNqWB_fixed_Asm_32: {
6212 // Shuffle the operands around so the lane index operand is in the
6215 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6216 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6217 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6218 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6219 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6220 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6221 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6225 TmpInst.addOperand(Inst.getOperand(1)); // lane
6226 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6227 TmpInst.addOperand(Inst.getOperand(5));
6232 case ARM::VST4LNdWB_fixed_Asm_8:
6233 case ARM::VST4LNdWB_fixed_Asm_16:
6234 case ARM::VST4LNdWB_fixed_Asm_32:
6235 case ARM::VST4LNqWB_fixed_Asm_16:
6236 case ARM::VST4LNqWB_fixed_Asm_32: {
6238 // Shuffle the operands around so the lane index operand is in the
6241 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6242 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6243 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6244 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6245 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6246 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6251 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6253 TmpInst.addOperand(Inst.getOperand(1)); // lane
6254 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6255 TmpInst.addOperand(Inst.getOperand(5));
6260 case ARM::VST1LNdAsm_8:
6261 case ARM::VST1LNdAsm_16:
6262 case ARM::VST1LNdAsm_32: {
6264 // Shuffle the operands around so the lane index operand is in the
6267 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6268 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6269 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6270 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6271 TmpInst.addOperand(Inst.getOperand(1)); // lane
6272 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6273 TmpInst.addOperand(Inst.getOperand(5));
6278 case ARM::VST2LNdAsm_8:
6279 case ARM::VST2LNdAsm_16:
6280 case ARM::VST2LNdAsm_32:
6281 case ARM::VST2LNqAsm_16:
6282 case ARM::VST2LNqAsm_32: {
6284 // Shuffle the operands around so the lane index operand is in the
6287 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6288 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6289 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6290 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6293 TmpInst.addOperand(Inst.getOperand(1)); // lane
6294 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6295 TmpInst.addOperand(Inst.getOperand(5));
6300 case ARM::VST3LNdAsm_8:
6301 case ARM::VST3LNdAsm_16:
6302 case ARM::VST3LNdAsm_32:
6303 case ARM::VST3LNqAsm_16:
6304 case ARM::VST3LNqAsm_32: {
6306 // Shuffle the operands around so the lane index operand is in the
6309 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6310 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6311 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6312 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6313 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6315 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6317 TmpInst.addOperand(Inst.getOperand(1)); // lane
6318 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6319 TmpInst.addOperand(Inst.getOperand(5));
6324 case ARM::VST4LNdAsm_8:
6325 case ARM::VST4LNdAsm_16:
6326 case ARM::VST4LNdAsm_32:
6327 case ARM::VST4LNqAsm_16:
6328 case ARM::VST4LNqAsm_32: {
6330 // Shuffle the operands around so the lane index operand is in the
6333 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6334 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6335 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6336 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6337 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6339 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6341 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6343 TmpInst.addOperand(Inst.getOperand(1)); // lane
6344 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6345 TmpInst.addOperand(Inst.getOperand(5));
6350 // Handle NEON VLD complex aliases.
6351 case ARM::VLD1LNdWB_register_Asm_8:
6352 case ARM::VLD1LNdWB_register_Asm_16:
6353 case ARM::VLD1LNdWB_register_Asm_32: {
6355 // Shuffle the operands around so the lane index operand is in the
6358 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6359 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6360 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6361 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6362 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6363 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6364 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6365 TmpInst.addOperand(Inst.getOperand(1)); // lane
6366 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6367 TmpInst.addOperand(Inst.getOperand(6));
6372 case ARM::VLD2LNdWB_register_Asm_8:
6373 case ARM::VLD2LNdWB_register_Asm_16:
6374 case ARM::VLD2LNdWB_register_Asm_32:
6375 case ARM::VLD2LNqWB_register_Asm_16:
6376 case ARM::VLD2LNqWB_register_Asm_32: {
6378 // Shuffle the operands around so the lane index operand is in the
6381 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6382 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6383 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6385 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6386 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6387 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6388 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6389 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6390 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6392 TmpInst.addOperand(Inst.getOperand(1)); // lane
6393 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6394 TmpInst.addOperand(Inst.getOperand(6));
6399 case ARM::VLD3LNdWB_register_Asm_8:
6400 case ARM::VLD3LNdWB_register_Asm_16:
6401 case ARM::VLD3LNdWB_register_Asm_32:
6402 case ARM::VLD3LNqWB_register_Asm_16:
6403 case ARM::VLD3LNqWB_register_Asm_32: {
6405 // Shuffle the operands around so the lane index operand is in the
6408 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6409 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6410 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6414 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6415 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6416 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6417 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6418 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6419 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6423 TmpInst.addOperand(Inst.getOperand(1)); // lane
6424 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6425 TmpInst.addOperand(Inst.getOperand(6));
6430 case ARM::VLD4LNdWB_register_Asm_8:
6431 case ARM::VLD4LNdWB_register_Asm_16:
6432 case ARM::VLD4LNdWB_register_Asm_32:
6433 case ARM::VLD4LNqWB_register_Asm_16:
6434 case ARM::VLD4LNqWB_register_Asm_32: {
6436 // Shuffle the operands around so the lane index operand is in the
6439 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6440 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6447 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6448 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6449 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6450 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6451 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6452 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6454 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6456 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6458 TmpInst.addOperand(Inst.getOperand(1)); // lane
6459 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6460 TmpInst.addOperand(Inst.getOperand(6));
6465 case ARM::VLD1LNdWB_fixed_Asm_8:
6466 case ARM::VLD1LNdWB_fixed_Asm_16:
6467 case ARM::VLD1LNdWB_fixed_Asm_32: {
6469 // Shuffle the operands around so the lane index operand is in the
6472 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6473 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6474 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6475 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6476 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6477 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6478 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6479 TmpInst.addOperand(Inst.getOperand(1)); // lane
6480 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6481 TmpInst.addOperand(Inst.getOperand(5));
6486 case ARM::VLD2LNdWB_fixed_Asm_8:
6487 case ARM::VLD2LNdWB_fixed_Asm_16:
6488 case ARM::VLD2LNdWB_fixed_Asm_32:
6489 case ARM::VLD2LNqWB_fixed_Asm_16:
6490 case ARM::VLD2LNqWB_fixed_Asm_32: {
6492 // Shuffle the operands around so the lane index operand is in the
6495 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6496 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6499 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6500 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6501 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6502 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6503 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6504 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6506 TmpInst.addOperand(Inst.getOperand(1)); // lane
6507 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6508 TmpInst.addOperand(Inst.getOperand(5));
6513 case ARM::VLD3LNdWB_fixed_Asm_8:
6514 case ARM::VLD3LNdWB_fixed_Asm_16:
6515 case ARM::VLD3LNdWB_fixed_Asm_32:
6516 case ARM::VLD3LNqWB_fixed_Asm_16:
6517 case ARM::VLD3LNqWB_fixed_Asm_32: {
6519 // Shuffle the operands around so the lane index operand is in the
6522 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6523 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6528 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6529 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6530 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6531 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6532 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6533 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6537 TmpInst.addOperand(Inst.getOperand(1)); // lane
6538 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(5));
6544 case ARM::VLD4LNdWB_fixed_Asm_8:
6545 case ARM::VLD4LNdWB_fixed_Asm_16:
6546 case ARM::VLD4LNdWB_fixed_Asm_32:
6547 case ARM::VLD4LNqWB_fixed_Asm_16:
6548 case ARM::VLD4LNqWB_fixed_Asm_32: {
6550 // Shuffle the operands around so the lane index operand is in the
6553 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6554 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6555 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6559 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6561 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6562 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6563 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6564 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6565 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6566 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6572 TmpInst.addOperand(Inst.getOperand(1)); // lane
6573 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6574 TmpInst.addOperand(Inst.getOperand(5));
6579 case ARM::VLD1LNdAsm_8:
6580 case ARM::VLD1LNdAsm_16:
6581 case ARM::VLD1LNdAsm_32: {
6583 // Shuffle the operands around so the lane index operand is in the
6586 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6587 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6588 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6589 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6590 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6591 TmpInst.addOperand(Inst.getOperand(1)); // lane
6592 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6593 TmpInst.addOperand(Inst.getOperand(5));
6598 case ARM::VLD2LNdAsm_8:
6599 case ARM::VLD2LNdAsm_16:
6600 case ARM::VLD2LNdAsm_32:
6601 case ARM::VLD2LNqAsm_16:
6602 case ARM::VLD2LNqAsm_32: {
6604 // Shuffle the operands around so the lane index operand is in the
6607 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6608 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6609 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6611 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6612 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6613 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6614 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6616 TmpInst.addOperand(Inst.getOperand(1)); // lane
6617 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6618 TmpInst.addOperand(Inst.getOperand(5));
6623 case ARM::VLD3LNdAsm_8:
6624 case ARM::VLD3LNdAsm_16:
6625 case ARM::VLD3LNdAsm_32:
6626 case ARM::VLD3LNqAsm_16:
6627 case ARM::VLD3LNqAsm_32: {
6629 // Shuffle the operands around so the lane index operand is in the
6632 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6633 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6634 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6636 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6638 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6639 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6640 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6645 TmpInst.addOperand(Inst.getOperand(1)); // lane
6646 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6647 TmpInst.addOperand(Inst.getOperand(5));
6652 case ARM::VLD4LNdAsm_8:
6653 case ARM::VLD4LNdAsm_16:
6654 case ARM::VLD4LNdAsm_32:
6655 case ARM::VLD4LNqAsm_16:
6656 case ARM::VLD4LNqAsm_32: {
6658 // Shuffle the operands around so the lane index operand is in the
6661 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6662 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6667 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6669 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6670 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6671 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6672 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6678 TmpInst.addOperand(Inst.getOperand(1)); // lane
6679 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6680 TmpInst.addOperand(Inst.getOperand(5));
6685 // VLD3DUP single 3-element structure to all lanes instructions.
6686 case ARM::VLD3DUPdAsm_8:
6687 case ARM::VLD3DUPdAsm_16:
6688 case ARM::VLD3DUPdAsm_32:
6689 case ARM::VLD3DUPqAsm_8:
6690 case ARM::VLD3DUPqAsm_16:
6691 case ARM::VLD3DUPqAsm_32: {
6694 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6695 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6696 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6700 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6701 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6702 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6703 TmpInst.addOperand(Inst.getOperand(4));
6708 case ARM::VLD3DUPdWB_fixed_Asm_8:
6709 case ARM::VLD3DUPdWB_fixed_Asm_16:
6710 case ARM::VLD3DUPdWB_fixed_Asm_32:
6711 case ARM::VLD3DUPqWB_fixed_Asm_8:
6712 case ARM::VLD3DUPqWB_fixed_Asm_16:
6713 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6716 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6717 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6718 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6722 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6723 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6724 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6725 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6726 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6727 TmpInst.addOperand(Inst.getOperand(4));
6732 case ARM::VLD3DUPdWB_register_Asm_8:
6733 case ARM::VLD3DUPdWB_register_Asm_16:
6734 case ARM::VLD3DUPdWB_register_Asm_32:
6735 case ARM::VLD3DUPqWB_register_Asm_8:
6736 case ARM::VLD3DUPqWB_register_Asm_16:
6737 case ARM::VLD3DUPqWB_register_Asm_32: {
6740 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6741 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6742 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6744 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6746 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6747 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6748 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6749 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6750 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6751 TmpInst.addOperand(Inst.getOperand(5));
6756 // VLD3 multiple 3-element structure instructions.
6757 case ARM::VLD3dAsm_8:
6758 case ARM::VLD3dAsm_16:
6759 case ARM::VLD3dAsm_32:
6760 case ARM::VLD3qAsm_8:
6761 case ARM::VLD3qAsm_16:
6762 case ARM::VLD3qAsm_32: {
6765 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6766 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6767 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6769 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6771 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6772 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6773 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6774 TmpInst.addOperand(Inst.getOperand(4));
6779 case ARM::VLD3dWB_fixed_Asm_8:
6780 case ARM::VLD3dWB_fixed_Asm_16:
6781 case ARM::VLD3dWB_fixed_Asm_32:
6782 case ARM::VLD3qWB_fixed_Asm_8:
6783 case ARM::VLD3qWB_fixed_Asm_16:
6784 case ARM::VLD3qWB_fixed_Asm_32: {
6787 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6788 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6789 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6791 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6793 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6794 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6795 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6796 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6797 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6798 TmpInst.addOperand(Inst.getOperand(4));
6803 case ARM::VLD3dWB_register_Asm_8:
6804 case ARM::VLD3dWB_register_Asm_16:
6805 case ARM::VLD3dWB_register_Asm_32:
6806 case ARM::VLD3qWB_register_Asm_8:
6807 case ARM::VLD3qWB_register_Asm_16:
6808 case ARM::VLD3qWB_register_Asm_32: {
6811 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6812 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6813 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6815 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6817 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6818 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6819 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6820 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6821 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6822 TmpInst.addOperand(Inst.getOperand(5));
6827 // VLD4DUP single 3-element structure to all lanes instructions.
6828 case ARM::VLD4DUPdAsm_8:
6829 case ARM::VLD4DUPdAsm_16:
6830 case ARM::VLD4DUPdAsm_32:
6831 case ARM::VLD4DUPqAsm_8:
6832 case ARM::VLD4DUPqAsm_16:
6833 case ARM::VLD4DUPqAsm_32: {
6836 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6837 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6840 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6842 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6844 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6845 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6846 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6847 TmpInst.addOperand(Inst.getOperand(4));
6852 case ARM::VLD4DUPdWB_fixed_Asm_8:
6853 case ARM::VLD4DUPdWB_fixed_Asm_16:
6854 case ARM::VLD4DUPdWB_fixed_Asm_32:
6855 case ARM::VLD4DUPqWB_fixed_Asm_8:
6856 case ARM::VLD4DUPqWB_fixed_Asm_16:
6857 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6860 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6861 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6862 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6866 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6868 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6869 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6870 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6871 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6872 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6873 TmpInst.addOperand(Inst.getOperand(4));
6878 case ARM::VLD4DUPdWB_register_Asm_8:
6879 case ARM::VLD4DUPdWB_register_Asm_16:
6880 case ARM::VLD4DUPdWB_register_Asm_32:
6881 case ARM::VLD4DUPqWB_register_Asm_8:
6882 case ARM::VLD4DUPqWB_register_Asm_16:
6883 case ARM::VLD4DUPqWB_register_Asm_32: {
6886 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6887 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6892 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6894 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6895 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6896 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6897 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6898 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6899 TmpInst.addOperand(Inst.getOperand(5));
6904 // VLD4 multiple 4-element structure instructions.
6905 case ARM::VLD4dAsm_8:
6906 case ARM::VLD4dAsm_16:
6907 case ARM::VLD4dAsm_32:
6908 case ARM::VLD4qAsm_8:
6909 case ARM::VLD4qAsm_16:
6910 case ARM::VLD4qAsm_32: {
6913 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6914 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6915 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6917 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6919 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6922 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6923 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6924 TmpInst.addOperand(Inst.getOperand(4));
6929 case ARM::VLD4dWB_fixed_Asm_8:
6930 case ARM::VLD4dWB_fixed_Asm_16:
6931 case ARM::VLD4dWB_fixed_Asm_32:
6932 case ARM::VLD4qWB_fixed_Asm_8:
6933 case ARM::VLD4qWB_fixed_Asm_16:
6934 case ARM::VLD4qWB_fixed_Asm_32: {
6937 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6938 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6941 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6943 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6945 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6946 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6947 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6948 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6949 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6950 TmpInst.addOperand(Inst.getOperand(4));
6955 case ARM::VLD4dWB_register_Asm_8:
6956 case ARM::VLD4dWB_register_Asm_16:
6957 case ARM::VLD4dWB_register_Asm_32:
6958 case ARM::VLD4qWB_register_Asm_8:
6959 case ARM::VLD4qWB_register_Asm_16:
6960 case ARM::VLD4qWB_register_Asm_32: {
6963 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6964 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6971 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6972 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6973 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6974 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6975 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6976 TmpInst.addOperand(Inst.getOperand(5));
6981 // VST3 multiple 3-element structure instructions.
6982 case ARM::VST3dAsm_8:
6983 case ARM::VST3dAsm_16:
6984 case ARM::VST3dAsm_32:
6985 case ARM::VST3qAsm_8:
6986 case ARM::VST3qAsm_16:
6987 case ARM::VST3qAsm_32: {
6990 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6991 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6992 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6993 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6994 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6996 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6998 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6999 TmpInst.addOperand(Inst.getOperand(4));
7004 case ARM::VST3dWB_fixed_Asm_8:
7005 case ARM::VST3dWB_fixed_Asm_16:
7006 case ARM::VST3dWB_fixed_Asm_32:
7007 case ARM::VST3qWB_fixed_Asm_8:
7008 case ARM::VST3qWB_fixed_Asm_16:
7009 case ARM::VST3qWB_fixed_Asm_32: {
7012 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7013 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7014 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7015 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7016 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7017 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7018 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7022 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7023 TmpInst.addOperand(Inst.getOperand(4));
7028 case ARM::VST3dWB_register_Asm_8:
7029 case ARM::VST3dWB_register_Asm_16:
7030 case ARM::VST3dWB_register_Asm_32:
7031 case ARM::VST3qWB_register_Asm_8:
7032 case ARM::VST3qWB_register_Asm_16:
7033 case ARM::VST3qWB_register_Asm_32: {
7036 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7037 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7038 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7039 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7040 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7041 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7046 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7047 TmpInst.addOperand(Inst.getOperand(5));
7052 // VST4 multiple 3-element structure instructions.
7053 case ARM::VST4dAsm_8:
7054 case ARM::VST4dAsm_16:
7055 case ARM::VST4dAsm_32:
7056 case ARM::VST4qAsm_8:
7057 case ARM::VST4qAsm_16:
7058 case ARM::VST4qAsm_32: {
7061 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7062 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7063 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7064 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7065 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7071 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7072 TmpInst.addOperand(Inst.getOperand(4));
7077 case ARM::VST4dWB_fixed_Asm_8:
7078 case ARM::VST4dWB_fixed_Asm_16:
7079 case ARM::VST4dWB_fixed_Asm_32:
7080 case ARM::VST4qWB_fixed_Asm_8:
7081 case ARM::VST4qWB_fixed_Asm_16:
7082 case ARM::VST4qWB_fixed_Asm_32: {
7085 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7086 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7087 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7088 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7089 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7090 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7091 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7093 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7095 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7097 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7098 TmpInst.addOperand(Inst.getOperand(4));
7103 case ARM::VST4dWB_register_Asm_8:
7104 case ARM::VST4dWB_register_Asm_16:
7105 case ARM::VST4dWB_register_Asm_32:
7106 case ARM::VST4qWB_register_Asm_8:
7107 case ARM::VST4qWB_register_Asm_16:
7108 case ARM::VST4qWB_register_Asm_32: {
7111 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7112 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7113 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7114 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7115 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7116 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7117 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7119 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7121 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7123 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7124 TmpInst.addOperand(Inst.getOperand(5));
7129 // Handle encoding choice for the shift-immediate instructions.
7132 case ARM::t2ASRri: {
7133 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7134 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7135 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7136 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7137 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7139 switch (Inst.getOpcode()) {
7140 default: llvm_unreachable("unexpected opcode");
7141 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7142 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7143 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7145 // The Thumb1 operands aren't in the same order. Awesome, eh?
7147 TmpInst.setOpcode(NewOpc);
7148 TmpInst.addOperand(Inst.getOperand(0));
7149 TmpInst.addOperand(Inst.getOperand(5));
7150 TmpInst.addOperand(Inst.getOperand(1));
7151 TmpInst.addOperand(Inst.getOperand(2));
7152 TmpInst.addOperand(Inst.getOperand(3));
7153 TmpInst.addOperand(Inst.getOperand(4));
7160 // Handle the Thumb2 mode MOV complex aliases.
7162 case ARM::t2MOVSsr: {
7163 // Which instruction to expand to depends on the CCOut operand and
7164 // whether we're in an IT block if the register operands are low
7166 bool isNarrow = false;
7167 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7168 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7169 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7170 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7171 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7175 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7176 default: llvm_unreachable("unexpected opcode!");
7177 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7178 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7179 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7180 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7182 TmpInst.setOpcode(newOpc);
7183 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7185 TmpInst.addOperand(MCOperand::CreateReg(
7186 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7187 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7188 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7189 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7190 TmpInst.addOperand(Inst.getOperand(5));
7192 TmpInst.addOperand(MCOperand::CreateReg(
7193 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7198 case ARM::t2MOVSsi: {
7199 // Which instruction to expand to depends on the CCOut operand and
7200 // whether we're in an IT block if the register operands are low
7202 bool isNarrow = false;
7203 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7204 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7205 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7209 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7210 default: llvm_unreachable("unexpected opcode!");
7211 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7212 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7213 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7214 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
7215 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
7217 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7218 if (Amount == 32) Amount = 0;
7219 TmpInst.setOpcode(newOpc);
7220 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7222 TmpInst.addOperand(MCOperand::CreateReg(
7223 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7224 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7225 if (newOpc != ARM::t2RRX)
7226 TmpInst.addOperand(MCOperand::CreateImm(Amount));
7227 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7228 TmpInst.addOperand(Inst.getOperand(4));
7230 TmpInst.addOperand(MCOperand::CreateReg(
7231 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7235 // Handle the ARM mode MOV complex aliases.
7240 ARM_AM::ShiftOpc ShiftTy;
7241 switch(Inst.getOpcode()) {
7242 default: llvm_unreachable("unexpected opcode!");
7243 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7244 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7245 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7246 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7248 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7250 TmpInst.setOpcode(ARM::MOVsr);
7251 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7252 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7253 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7254 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7255 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7256 TmpInst.addOperand(Inst.getOperand(4));
7257 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7265 ARM_AM::ShiftOpc ShiftTy;
7266 switch(Inst.getOpcode()) {
7267 default: llvm_unreachable("unexpected opcode!");
7268 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7269 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7270 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7271 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7273 // A shift by zero is a plain MOVr, not a MOVsi.
7274 unsigned Amt = Inst.getOperand(2).getImm();
7275 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
7276 // A shift by 32 should be encoded as 0 when permitted
7277 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7279 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
7281 TmpInst.setOpcode(Opc);
7282 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7283 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7284 if (Opc == ARM::MOVsi)
7285 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7286 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7287 TmpInst.addOperand(Inst.getOperand(4));
7288 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7293 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7295 TmpInst.setOpcode(ARM::MOVsi);
7296 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7297 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7298 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7299 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7300 TmpInst.addOperand(Inst.getOperand(3));
7301 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7305 case ARM::t2LDMIA_UPD: {
7306 // If this is a load of a single register, then we should use
7307 // a post-indexed LDR instruction instead, per the ARM ARM.
7308 if (Inst.getNumOperands() != 5)
7311 TmpInst.setOpcode(ARM::t2LDR_POST);
7312 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7313 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7314 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7315 TmpInst.addOperand(MCOperand::CreateImm(4));
7316 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7317 TmpInst.addOperand(Inst.getOperand(3));
7321 case ARM::t2STMDB_UPD: {
7322 // If this is a store of a single register, then we should use
7323 // a pre-indexed STR instruction instead, per the ARM ARM.
7324 if (Inst.getNumOperands() != 5)
7327 TmpInst.setOpcode(ARM::t2STR_PRE);
7328 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7329 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7330 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7331 TmpInst.addOperand(MCOperand::CreateImm(-4));
7332 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7333 TmpInst.addOperand(Inst.getOperand(3));
7337 case ARM::LDMIA_UPD:
7338 // If this is a load of a single register via a 'pop', then we should use
7339 // a post-indexed LDR instruction instead, per the ARM ARM.
7340 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7341 Inst.getNumOperands() == 5) {
7343 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7344 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7345 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7346 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7347 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7348 TmpInst.addOperand(MCOperand::CreateImm(4));
7349 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7350 TmpInst.addOperand(Inst.getOperand(3));
7355 case ARM::STMDB_UPD:
7356 // If this is a store of a single register via a 'push', then we should use
7357 // a pre-indexed STR instruction instead, per the ARM ARM.
7358 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7359 Inst.getNumOperands() == 5) {
7361 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7362 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7363 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7364 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7365 TmpInst.addOperand(MCOperand::CreateImm(-4));
7366 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7367 TmpInst.addOperand(Inst.getOperand(3));
7371 case ARM::t2ADDri12:
7372 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7373 // mnemonic was used (not "addw"), encoding T3 is preferred.
7374 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7375 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7377 Inst.setOpcode(ARM::t2ADDri);
7378 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7380 case ARM::t2SUBri12:
7381 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7382 // mnemonic was used (not "subw"), encoding T3 is preferred.
7383 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7384 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7386 Inst.setOpcode(ARM::t2SUBri);
7387 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7390 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7391 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7392 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7393 // to encoding T1 if <Rd> is omitted."
7394 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7395 Inst.setOpcode(ARM::tADDi3);
7400 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7401 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7402 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7403 // to encoding T1 if <Rd> is omitted."
7404 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
7405 Inst.setOpcode(ARM::tSUBi3);
7410 case ARM::t2SUBri: {
7411 // If the destination and first source operand are the same, and
7412 // the flags are compatible with the current IT status, use encoding T2
7413 // instead of T3. For compatibility with the system 'as'. Make sure the
7414 // wide encoding wasn't explicit.
7415 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7416 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
7417 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7418 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7419 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7420 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7421 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7424 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7425 ARM::tADDi8 : ARM::tSUBi8);
7426 TmpInst.addOperand(Inst.getOperand(0));
7427 TmpInst.addOperand(Inst.getOperand(5));
7428 TmpInst.addOperand(Inst.getOperand(0));
7429 TmpInst.addOperand(Inst.getOperand(2));
7430 TmpInst.addOperand(Inst.getOperand(3));
7431 TmpInst.addOperand(Inst.getOperand(4));
7435 case ARM::t2ADDrr: {
7436 // If the destination and first source operand are the same, and
7437 // there's no setting of the flags, use encoding T2 instead of T3.
7438 // Note that this is only for ADD, not SUB. This mirrors the system
7439 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7440 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7441 Inst.getOperand(5).getReg() != 0 ||
7442 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7443 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7446 TmpInst.setOpcode(ARM::tADDhirr);
7447 TmpInst.addOperand(Inst.getOperand(0));
7448 TmpInst.addOperand(Inst.getOperand(0));
7449 TmpInst.addOperand(Inst.getOperand(2));
7450 TmpInst.addOperand(Inst.getOperand(3));
7451 TmpInst.addOperand(Inst.getOperand(4));
7455 case ARM::tADDrSP: {
7456 // If the non-SP source operand and the destination operand are not the
7457 // same, we need to use the 32-bit encoding if it's available.
7458 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7459 Inst.setOpcode(ARM::t2ADDrr);
7460 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7466 // A Thumb conditional branch outside of an IT block is a tBcc.
7467 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
7468 Inst.setOpcode(ARM::tBcc);
7473 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
7474 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
7475 Inst.setOpcode(ARM::t2Bcc);
7480 // If the conditional is AL or we're in an IT block, we really want t2B.
7481 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
7482 Inst.setOpcode(ARM::t2B);
7487 // If the conditional is AL, we really want tB.
7488 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
7489 Inst.setOpcode(ARM::tB);
7494 // If the register list contains any high registers, or if the writeback
7495 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7496 // instead if we're in Thumb2. Otherwise, this should have generated
7497 // an error in validateInstruction().
7498 unsigned Rn = Inst.getOperand(0).getReg();
7499 bool hasWritebackToken =
7500 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7501 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7502 bool listContainsBase;
7503 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7504 (!listContainsBase && !hasWritebackToken) ||
7505 (listContainsBase && hasWritebackToken)) {
7506 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7507 assert (isThumbTwo());
7508 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7509 // If we're switching to the updating version, we need to insert
7510 // the writeback tied operand.
7511 if (hasWritebackToken)
7512 Inst.insert(Inst.begin(),
7513 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
7518 case ARM::tSTMIA_UPD: {
7519 // If the register list contains any high registers, we need to use
7520 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7521 // should have generated an error in validateInstruction().
7522 unsigned Rn = Inst.getOperand(0).getReg();
7523 bool listContainsBase;
7524 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7525 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7526 assert (isThumbTwo());
7527 Inst.setOpcode(ARM::t2STMIA_UPD);
7533 bool listContainsBase;
7534 // If the register list contains any high registers, we need to use
7535 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7536 // should have generated an error in validateInstruction().
7537 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
7539 assert (isThumbTwo());
7540 Inst.setOpcode(ARM::t2LDMIA_UPD);
7541 // Add the base register and writeback operands.
7542 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7543 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7547 bool listContainsBase;
7548 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
7550 assert (isThumbTwo());
7551 Inst.setOpcode(ARM::t2STMDB_UPD);
7552 // Add the base register and writeback operands.
7553 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7554 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7558 // If we can use the 16-bit encoding and the user didn't explicitly
7559 // request the 32-bit variant, transform it here.
7560 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7561 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
7562 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7563 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7564 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
7565 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7566 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7567 // The operands aren't in the same order for tMOVi8...
7569 TmpInst.setOpcode(ARM::tMOVi8);
7570 TmpInst.addOperand(Inst.getOperand(0));
7571 TmpInst.addOperand(Inst.getOperand(4));
7572 TmpInst.addOperand(Inst.getOperand(1));
7573 TmpInst.addOperand(Inst.getOperand(2));
7574 TmpInst.addOperand(Inst.getOperand(3));
7581 // If we can use the 16-bit encoding and the user didn't explicitly
7582 // request the 32-bit variant, transform it here.
7583 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7584 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7585 Inst.getOperand(2).getImm() == ARMCC::AL &&
7586 Inst.getOperand(4).getReg() == ARM::CPSR &&
7587 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7588 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7589 // The operands aren't the same for tMOV[S]r... (no cc_out)
7591 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7592 TmpInst.addOperand(Inst.getOperand(0));
7593 TmpInst.addOperand(Inst.getOperand(1));
7594 TmpInst.addOperand(Inst.getOperand(2));
7595 TmpInst.addOperand(Inst.getOperand(3));
7605 // If we can use the 16-bit encoding and the user didn't explicitly
7606 // request the 32-bit variant, transform it here.
7607 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7608 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7609 Inst.getOperand(2).getImm() == 0 &&
7610 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7611 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7613 switch (Inst.getOpcode()) {
7614 default: llvm_unreachable("Illegal opcode!");
7615 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7616 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7617 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7618 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7620 // The operands aren't the same for thumb1 (no rotate operand).
7622 TmpInst.setOpcode(NewOpc);
7623 TmpInst.addOperand(Inst.getOperand(0));
7624 TmpInst.addOperand(Inst.getOperand(1));
7625 TmpInst.addOperand(Inst.getOperand(3));
7626 TmpInst.addOperand(Inst.getOperand(4));
7633 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7634 // rrx shifts and asr/lsr of #32 is encoded as 0
7635 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7637 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7638 // Shifting by zero is accepted as a vanilla 'MOVr'
7640 TmpInst.setOpcode(ARM::MOVr);
7641 TmpInst.addOperand(Inst.getOperand(0));
7642 TmpInst.addOperand(Inst.getOperand(1));
7643 TmpInst.addOperand(Inst.getOperand(3));
7644 TmpInst.addOperand(Inst.getOperand(4));
7645 TmpInst.addOperand(Inst.getOperand(5));
7658 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7659 if (SOpc == ARM_AM::rrx) return false;
7660 switch (Inst.getOpcode()) {
7661 default: llvm_unreachable("unexpected opcode!");
7662 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7663 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7664 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7665 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7666 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7667 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7669 // If the shift is by zero, use the non-shifted instruction definition.
7670 // The exception is for right shifts, where 0 == 32
7671 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7672 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
7674 TmpInst.setOpcode(newOpc);
7675 TmpInst.addOperand(Inst.getOperand(0));
7676 TmpInst.addOperand(Inst.getOperand(1));
7677 TmpInst.addOperand(Inst.getOperand(2));
7678 TmpInst.addOperand(Inst.getOperand(4));
7679 TmpInst.addOperand(Inst.getOperand(5));
7680 TmpInst.addOperand(Inst.getOperand(6));
7688 // The mask bits for all but the first condition are represented as
7689 // the low bit of the condition code value implies 't'. We currently
7690 // always have 1 implies 't', so XOR toggle the bits if the low bit
7691 // of the condition code is zero.
7692 MCOperand &MO = Inst.getOperand(1);
7693 unsigned Mask = MO.getImm();
7694 unsigned OrigMask = Mask;
7695 unsigned TZ = countTrailingZeros(Mask);
7696 if ((Inst.getOperand(0).getImm() & 1) == 0) {
7697 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7698 Mask ^= (0xE << TZ) & 0xF;
7702 // Set up the IT block state according to the IT instruction we just
7704 assert(!inITBlock() && "nested IT blocks?!");
7705 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7706 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7707 ITState.CurPosition = 0;
7708 ITState.FirstCond = true;
7718 // Assemblers should use the narrow encodings of these instructions when permissible.
7719 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7720 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7721 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7722 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7723 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7724 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7725 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7727 switch (Inst.getOpcode()) {
7728 default: llvm_unreachable("unexpected opcode");
7729 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7730 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7731 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7732 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7733 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7734 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7737 TmpInst.setOpcode(NewOpc);
7738 TmpInst.addOperand(Inst.getOperand(0));
7739 TmpInst.addOperand(Inst.getOperand(5));
7740 TmpInst.addOperand(Inst.getOperand(1));
7741 TmpInst.addOperand(Inst.getOperand(2));
7742 TmpInst.addOperand(Inst.getOperand(3));
7743 TmpInst.addOperand(Inst.getOperand(4));
7754 // Assemblers should use the narrow encodings of these instructions when permissible.
7755 // These instructions are special in that they are commutable, so shorter encodings
7756 // are available more often.
7757 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7758 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7759 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7760 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
7761 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7762 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
7763 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7764 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7766 switch (Inst.getOpcode()) {
7767 default: llvm_unreachable("unexpected opcode");
7768 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7769 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7770 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7771 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7774 TmpInst.setOpcode(NewOpc);
7775 TmpInst.addOperand(Inst.getOperand(0));
7776 TmpInst.addOperand(Inst.getOperand(5));
7777 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7778 TmpInst.addOperand(Inst.getOperand(1));
7779 TmpInst.addOperand(Inst.getOperand(2));
7781 TmpInst.addOperand(Inst.getOperand(2));
7782 TmpInst.addOperand(Inst.getOperand(1));
7784 TmpInst.addOperand(Inst.getOperand(3));
7785 TmpInst.addOperand(Inst.getOperand(4));
7795 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7796 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7797 // suffix depending on whether they're in an IT block or not.
7798 unsigned Opc = Inst.getOpcode();
7799 const MCInstrDesc &MCID = MII.get(Opc);
7800 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7801 assert(MCID.hasOptionalDef() &&
7802 "optionally flag setting instruction missing optional def operand");
7803 assert(MCID.NumOperands == Inst.getNumOperands() &&
7804 "operand count mismatch!");
7805 // Find the optional-def operand (cc_out).
7808 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7811 // If we're parsing Thumb1, reject it completely.
7812 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7813 return Match_MnemonicFail;
7814 // If we're parsing Thumb2, which form is legal depends on whether we're
7816 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7818 return Match_RequiresITBlock;
7819 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7821 return Match_RequiresNotITBlock;
7823 // Some high-register supporting Thumb1 encodings only allow both registers
7824 // to be from r0-r7 when in Thumb2.
7825 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7826 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7827 isARMLowRegister(Inst.getOperand(2).getReg()))
7828 return Match_RequiresThumb2;
7829 // Others only require ARMv6 or later.
7830 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
7831 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7832 isARMLowRegister(Inst.getOperand(1).getReg()))
7833 return Match_RequiresV6;
7834 return Match_Success;
7837 static const char *getSubtargetFeatureName(unsigned Val);
7839 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
7840 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7841 MCStreamer &Out, unsigned &ErrorInfo,
7842 bool MatchingInlineAsm) {
7844 unsigned MatchResult;
7846 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
7848 switch (MatchResult) {
7851 // Context sensitive operand constraints aren't handled by the matcher,
7852 // so check them here.
7853 if (validateInstruction(Inst, Operands)) {
7854 // Still progress the IT block, otherwise one wrong condition causes
7855 // nasty cascading errors.
7856 forwardITPosition();
7860 { // processInstruction() updates inITBlock state, we need to save it away
7861 bool wasInITBlock = inITBlock();
7863 // Some instructions need post-processing to, for example, tweak which
7864 // encoding is selected. Loop on it while changes happen so the
7865 // individual transformations can chain off each other. E.g.,
7866 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7867 while (processInstruction(Inst, Operands))
7870 // Only after the instruction is fully processed, we can validate it
7871 if (wasInITBlock && hasV8Ops() && isThumb() &&
7872 !isV8EligibleForIT(&Inst, 2)) {
7873 Warning(IDLoc, "deprecated instruction in IT block");
7877 // Only move forward at the very end so that everything in validate
7878 // and process gets a consistent answer about whether we're in an IT
7880 forwardITPosition();
7882 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7883 // doesn't actually encode.
7884 if (Inst.getOpcode() == ARM::ITasm)
7888 Out.EmitInstruction(Inst);
7890 case Match_MissingFeature: {
7891 assert(ErrorInfo && "Unknown missing feature!");
7892 // Special case the error message for the very common case where only
7893 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7894 std::string Msg = "instruction requires:";
7896 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7897 if (ErrorInfo & Mask) {
7899 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7903 return Error(IDLoc, Msg);
7905 case Match_InvalidOperand: {
7906 SMLoc ErrorLoc = IDLoc;
7907 if (ErrorInfo != ~0U) {
7908 if (ErrorInfo >= Operands.size())
7909 return Error(IDLoc, "too few operands for instruction");
7911 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7912 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7915 return Error(ErrorLoc, "invalid operand for instruction");
7917 case Match_MnemonicFail:
7918 return Error(IDLoc, "invalid instruction",
7919 ((ARMOperand*)Operands[0])->getLocRange());
7920 case Match_RequiresNotITBlock:
7921 return Error(IDLoc, "flag setting instruction only valid outside IT block");
7922 case Match_RequiresITBlock:
7923 return Error(IDLoc, "instruction only valid inside IT block");
7924 case Match_RequiresV6:
7925 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7926 case Match_RequiresThumb2:
7927 return Error(IDLoc, "instruction variant requires Thumb2");
7928 case Match_ImmRange0_15: {
7929 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7930 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7931 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7933 case Match_ImmRange0_239: {
7934 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7935 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7936 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7940 llvm_unreachable("Implement any new match types added!");
7943 /// parseDirective parses the arm specific directives
7944 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7945 StringRef IDVal = DirectiveID.getIdentifier();
7946 if (IDVal == ".word")
7947 return parseDirectiveWord(4, DirectiveID.getLoc());
7948 else if (IDVal == ".thumb")
7949 return parseDirectiveThumb(DirectiveID.getLoc());
7950 else if (IDVal == ".arm")
7951 return parseDirectiveARM(DirectiveID.getLoc());
7952 else if (IDVal == ".thumb_func")
7953 return parseDirectiveThumbFunc(DirectiveID.getLoc());
7954 else if (IDVal == ".code")
7955 return parseDirectiveCode(DirectiveID.getLoc());
7956 else if (IDVal == ".syntax")
7957 return parseDirectiveSyntax(DirectiveID.getLoc());
7958 else if (IDVal == ".unreq")
7959 return parseDirectiveUnreq(DirectiveID.getLoc());
7960 else if (IDVal == ".arch")
7961 return parseDirectiveArch(DirectiveID.getLoc());
7962 else if (IDVal == ".eabi_attribute")
7963 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7964 else if (IDVal == ".cpu")
7965 return parseDirectiveCPU(DirectiveID.getLoc());
7966 else if (IDVal == ".fpu")
7967 return parseDirectiveFPU(DirectiveID.getLoc());
7968 else if (IDVal == ".fnstart")
7969 return parseDirectiveFnStart(DirectiveID.getLoc());
7970 else if (IDVal == ".fnend")
7971 return parseDirectiveFnEnd(DirectiveID.getLoc());
7972 else if (IDVal == ".cantunwind")
7973 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7974 else if (IDVal == ".personality")
7975 return parseDirectivePersonality(DirectiveID.getLoc());
7976 else if (IDVal == ".handlerdata")
7977 return parseDirectiveHandlerData(DirectiveID.getLoc());
7978 else if (IDVal == ".setfp")
7979 return parseDirectiveSetFP(DirectiveID.getLoc());
7980 else if (IDVal == ".pad")
7981 return parseDirectivePad(DirectiveID.getLoc());
7982 else if (IDVal == ".save")
7983 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7984 else if (IDVal == ".vsave")
7985 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
7986 else if (IDVal == ".inst")
7987 return parseDirectiveInst(DirectiveID.getLoc());
7988 else if (IDVal == ".inst.n")
7989 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7990 else if (IDVal == ".inst.w")
7991 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
7992 else if (IDVal == ".ltorg" || IDVal == ".pool")
7993 return parseDirectiveLtorg(DirectiveID.getLoc());
7994 else if (IDVal == ".even")
7995 return parseDirectiveEven(DirectiveID.getLoc());
7999 /// parseDirectiveWord
8000 /// ::= .word [ expression (, expression)* ]
8001 bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
8002 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8004 const MCExpr *Value;
8005 if (getParser().parseExpression(Value))
8008 getParser().getStreamer().EmitValue(Value, Size);
8010 if (getLexer().is(AsmToken::EndOfStatement))
8013 // FIXME: Improve diagnostic.
8014 if (getLexer().isNot(AsmToken::Comma))
8015 return Error(L, "unexpected token in directive");
8024 /// parseDirectiveThumb
8026 bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
8027 if (getLexer().isNot(AsmToken::EndOfStatement))
8028 return Error(L, "unexpected token in directive");
8032 return Error(L, "target does not support Thumb mode");
8036 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8040 /// parseDirectiveARM
8042 bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
8043 if (getLexer().isNot(AsmToken::EndOfStatement))
8044 return Error(L, "unexpected token in directive");
8048 return Error(L, "target does not support ARM mode");
8052 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8056 void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8057 if (NextSymbolIsThumb) {
8058 getParser().getStreamer().EmitThumbFunc(Symbol);
8059 NextSymbolIsThumb = false;
8063 /// parseDirectiveThumbFunc
8064 /// ::= .thumbfunc symbol_name
8065 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
8066 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
8067 bool isMachO = MAI->hasSubsectionsViaSymbols();
8069 // Darwin asm has (optionally) function name after .thumb_func direction
8072 const AsmToken &Tok = Parser.getTok();
8073 if (Tok.isNot(AsmToken::EndOfStatement)) {
8074 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
8075 return Error(L, "unexpected token in .thumb_func directive");
8077 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8078 getParser().getStreamer().EmitThumbFunc(Func);
8079 Parser.Lex(); // Consume the identifier token.
8084 if (getLexer().isNot(AsmToken::EndOfStatement))
8085 return Error(L, "unexpected token in directive");
8087 NextSymbolIsThumb = true;
8092 /// parseDirectiveSyntax
8093 /// ::= .syntax unified | divided
8094 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
8095 const AsmToken &Tok = Parser.getTok();
8096 if (Tok.isNot(AsmToken::Identifier))
8097 return Error(L, "unexpected token in .syntax directive");
8098 StringRef Mode = Tok.getString();
8099 if (Mode == "unified" || Mode == "UNIFIED")
8101 else if (Mode == "divided" || Mode == "DIVIDED")
8102 return Error(L, "'.syntax divided' arm asssembly not supported");
8104 return Error(L, "unrecognized syntax mode in .syntax directive");
8106 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8107 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8112 // TODO tell the MC streamer the mode
8113 // getParser().getStreamer().Emit???();
8117 /// parseDirectiveCode
8118 /// ::= .code 16 | 32
8119 bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
8120 const AsmToken &Tok = Parser.getTok();
8121 if (Tok.isNot(AsmToken::Integer)) {
8122 Error(L, "unexpected token in .code directive");
8125 int64_t Val = Parser.getTok().getIntVal();
8126 if (Val != 16 && Val != 32) {
8127 Error(L, "invalid operand to .code directive");
8132 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8133 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8140 Error(L, "target does not support Thumb mode");
8146 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8149 Error(L, "target does not support ARM mode");
8155 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
8161 /// parseDirectiveReq
8162 /// ::= name .req registername
8163 bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8164 Parser.Lex(); // Eat the '.req' token.
8166 SMLoc SRegLoc, ERegLoc;
8167 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
8168 Parser.eatToEndOfStatement();
8169 Error(SRegLoc, "register name expected");
8173 // Shouldn't be anything else.
8174 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
8175 Parser.eatToEndOfStatement();
8176 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
8180 Parser.Lex(); // Consume the EndOfStatement
8182 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) {
8183 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
8190 /// parseDirectiveUneq
8191 /// ::= .unreq registername
8192 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8193 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8194 Parser.eatToEndOfStatement();
8195 Error(L, "unexpected input in .unreq directive.");
8198 RegisterReqs.erase(Parser.getTok().getIdentifier());
8199 Parser.Lex(); // Eat the identifier.
8203 /// parseDirectiveArch
8205 bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
8206 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8208 unsigned ID = StringSwitch<unsigned>(Arch)
8209 #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8210 .Case(NAME, ARM::ID)
8211 #define ARM_ARCH_ALIAS(NAME, ID) \
8212 .Case(NAME, ARM::ID)
8213 #include "MCTargetDesc/ARMArchName.def"
8214 .Default(ARM::INVALID_ARCH);
8216 if (ID == ARM::INVALID_ARCH) {
8217 Error(L, "Unknown arch name");
8221 getTargetStreamer().emitArch(ID);
8225 /// parseDirectiveEabiAttr
8226 /// ::= .eabi_attribute int, int [, "str"]
8227 /// ::= .eabi_attribute Tag_name, int [, "str"]
8228 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
8232 TagLoc = Parser.getTok().getLoc();
8233 if (Parser.getTok().is(AsmToken::Identifier)) {
8234 StringRef Name = Parser.getTok().getIdentifier();
8235 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
8237 Error(TagLoc, "attribute name not recognised: " + Name);
8238 Parser.eatToEndOfStatement();
8243 const MCExpr *AttrExpr;
8245 TagLoc = Parser.getTok().getLoc();
8246 if (Parser.parseExpression(AttrExpr)) {
8247 Parser.eatToEndOfStatement();
8251 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
8253 Error(TagLoc, "expected numeric constant");
8254 Parser.eatToEndOfStatement();
8258 Tag = CE->getValue();
8261 if (Parser.getTok().isNot(AsmToken::Comma)) {
8262 Error(Parser.getTok().getLoc(), "comma expected");
8263 Parser.eatToEndOfStatement();
8266 Parser.Lex(); // skip comma
8268 StringRef StringValue = "";
8269 bool IsStringValue = false;
8271 int64_t IntegerValue = 0;
8272 bool IsIntegerValue = false;
8274 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
8275 IsStringValue = true;
8276 else if (Tag == ARMBuildAttrs::compatibility) {
8277 IsStringValue = true;
8278 IsIntegerValue = true;
8279 } else if (Tag == ARMBuildAttrs::nodefaults || Tag < 32 || Tag % 2 == 0)
8280 IsIntegerValue = true;
8281 else if (Tag % 2 == 1)
8282 IsStringValue = true;
8284 llvm_unreachable("invalid tag type");
8286 if (IsIntegerValue) {
8287 const MCExpr *ValueExpr;
8288 SMLoc ValueExprLoc = Parser.getTok().getLoc();
8289 if (Parser.parseExpression(ValueExpr)) {
8290 Parser.eatToEndOfStatement();
8294 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
8296 Error(ValueExprLoc, "expected numeric constant");
8297 Parser.eatToEndOfStatement();
8301 IntegerValue = CE->getValue();
8304 if (Tag == ARMBuildAttrs::compatibility) {
8305 if (Parser.getTok().isNot(AsmToken::Comma))
8306 IsStringValue = false;
8311 if (IsStringValue) {
8312 if (Parser.getTok().isNot(AsmToken::String)) {
8313 Error(Parser.getTok().getLoc(), "bad string constant");
8314 Parser.eatToEndOfStatement();
8318 StringValue = Parser.getTok().getStringContents();
8322 if (IsIntegerValue && IsStringValue) {
8323 assert(Tag == ARMBuildAttrs::compatibility);
8324 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
8325 } else if (IsIntegerValue)
8326 getTargetStreamer().emitAttribute(Tag, IntegerValue);
8327 else if (IsStringValue)
8328 getTargetStreamer().emitTextAttribute(Tag, StringValue);
8332 /// parseDirectiveCPU
8334 bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8335 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8336 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8340 /// parseDirectiveFPU
8342 bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8343 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8345 unsigned ID = StringSwitch<unsigned>(FPU)
8346 #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8347 #include "ARMFPUName.def"
8348 .Default(ARM::INVALID_FPU);
8350 if (ID == ARM::INVALID_FPU) {
8351 Error(L, "Unknown FPU name");
8355 getTargetStreamer().emitFPU(ID);
8359 /// parseDirectiveFnStart
8361 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8362 if (UC.hasFnStart()) {
8363 Error(L, ".fnstart starts before the end of previous one");
8364 UC.emitFnStartLocNotes();
8368 getTargetStreamer().emitFnStart();
8370 UC.recordFnStart(L);
8374 /// parseDirectiveFnEnd
8376 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8377 // Check the ordering of unwind directives
8378 if (!UC.hasFnStart()) {
8379 Error(L, ".fnstart must precede .fnend directive");
8383 // Reset the unwind directives parser state
8384 getTargetStreamer().emitFnEnd();
8390 /// parseDirectiveCantUnwind
8392 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8393 UC.recordCantUnwind(L);
8395 // Check the ordering of unwind directives
8396 if (!UC.hasFnStart()) {
8397 Error(L, ".fnstart must precede .cantunwind directive");
8400 if (UC.hasHandlerData()) {
8401 Error(L, ".cantunwind can't be used with .handlerdata directive");
8402 UC.emitHandlerDataLocNotes();
8405 if (UC.hasPersonality()) {
8406 Error(L, ".cantunwind can't be used with .personality directive");
8407 UC.emitPersonalityLocNotes();
8411 getTargetStreamer().emitCantUnwind();
8415 /// parseDirectivePersonality
8416 /// ::= .personality name
8417 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8418 UC.recordPersonality(L);
8420 // Check the ordering of unwind directives
8421 if (!UC.hasFnStart()) {
8422 Error(L, ".fnstart must precede .personality directive");
8425 if (UC.cantUnwind()) {
8426 Error(L, ".personality can't be used with .cantunwind directive");
8427 UC.emitCantUnwindLocNotes();
8430 if (UC.hasHandlerData()) {
8431 Error(L, ".personality must precede .handlerdata directive");
8432 UC.emitHandlerDataLocNotes();
8436 // Parse the name of the personality routine
8437 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8438 Parser.eatToEndOfStatement();
8439 Error(L, "unexpected input in .personality directive.");
8442 StringRef Name(Parser.getTok().getIdentifier());
8445 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
8446 getTargetStreamer().emitPersonality(PR);
8450 /// parseDirectiveHandlerData
8451 /// ::= .handlerdata
8452 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8453 UC.recordHandlerData(L);
8455 // Check the ordering of unwind directives
8456 if (!UC.hasFnStart()) {
8457 Error(L, ".fnstart must precede .personality directive");
8460 if (UC.cantUnwind()) {
8461 Error(L, ".handlerdata can't be used with .cantunwind directive");
8462 UC.emitCantUnwindLocNotes();
8466 getTargetStreamer().emitHandlerData();
8470 /// parseDirectiveSetFP
8471 /// ::= .setfp fpreg, spreg [, offset]
8472 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8473 // Check the ordering of unwind directives
8474 if (!UC.hasFnStart()) {
8475 Error(L, ".fnstart must precede .setfp directive");
8478 if (UC.hasHandlerData()) {
8479 Error(L, ".setfp must precede .handlerdata directive");
8484 SMLoc FPRegLoc = Parser.getTok().getLoc();
8485 int FPReg = tryParseRegister();
8487 Error(FPRegLoc, "frame pointer register expected");
8492 if (!Parser.getTok().is(AsmToken::Comma)) {
8493 Error(Parser.getTok().getLoc(), "comma expected");
8496 Parser.Lex(); // skip comma
8499 SMLoc SPRegLoc = Parser.getTok().getLoc();
8500 int SPReg = tryParseRegister();
8502 Error(SPRegLoc, "stack pointer register expected");
8506 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
8507 Error(SPRegLoc, "register should be either $sp or the latest fp register");
8511 // Update the frame pointer register
8512 UC.saveFPReg(FPReg);
8516 if (Parser.getTok().is(AsmToken::Comma)) {
8517 Parser.Lex(); // skip comma
8519 if (Parser.getTok().isNot(AsmToken::Hash) &&
8520 Parser.getTok().isNot(AsmToken::Dollar)) {
8521 Error(Parser.getTok().getLoc(), "'#' expected");
8524 Parser.Lex(); // skip hash token.
8526 const MCExpr *OffsetExpr;
8527 SMLoc ExLoc = Parser.getTok().getLoc();
8529 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8530 Error(ExLoc, "malformed setfp offset");
8533 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8535 Error(ExLoc, "setfp offset must be an immediate");
8539 Offset = CE->getValue();
8542 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
8543 static_cast<unsigned>(SPReg), Offset);
8549 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8550 // Check the ordering of unwind directives
8551 if (!UC.hasFnStart()) {
8552 Error(L, ".fnstart must precede .pad directive");
8555 if (UC.hasHandlerData()) {
8556 Error(L, ".pad must precede .handlerdata directive");
8561 if (Parser.getTok().isNot(AsmToken::Hash) &&
8562 Parser.getTok().isNot(AsmToken::Dollar)) {
8563 Error(Parser.getTok().getLoc(), "'#' expected");
8566 Parser.Lex(); // skip hash token.
8568 const MCExpr *OffsetExpr;
8569 SMLoc ExLoc = Parser.getTok().getLoc();
8571 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
8572 Error(ExLoc, "malformed pad offset");
8575 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8577 Error(ExLoc, "pad offset must be an immediate");
8581 getTargetStreamer().emitPad(CE->getValue());
8585 /// parseDirectiveRegSave
8586 /// ::= .save { registers }
8587 /// ::= .vsave { registers }
8588 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8589 // Check the ordering of unwind directives
8590 if (!UC.hasFnStart()) {
8591 Error(L, ".fnstart must precede .save or .vsave directives");
8594 if (UC.hasHandlerData()) {
8595 Error(L, ".save or .vsave must precede .handlerdata directive");
8599 // RAII object to make sure parsed operands are deleted.
8600 struct CleanupObject {
8601 SmallVector<MCParsedAsmOperand *, 1> Operands;
8603 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8608 // Parse the register list
8609 if (parseRegisterList(CO.Operands))
8611 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
8612 if (!IsVector && !Op->isRegList()) {
8613 Error(L, ".save expects GPR registers");
8616 if (IsVector && !Op->isDPRRegList()) {
8617 Error(L, ".vsave expects DPR registers");
8621 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
8625 /// parseDirectiveInst
8626 /// ::= .inst opcode [, ...]
8627 /// ::= .inst.n opcode [, ...]
8628 /// ::= .inst.w opcode [, ...]
8629 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8641 Parser.eatToEndOfStatement();
8642 Error(Loc, "cannot determine Thumb instruction size, "
8643 "use inst.n/inst.w instead");
8648 Parser.eatToEndOfStatement();
8649 Error(Loc, "width suffixes are invalid in ARM mode");
8655 if (getLexer().is(AsmToken::EndOfStatement)) {
8656 Parser.eatToEndOfStatement();
8657 Error(Loc, "expected expression following directive");
8664 if (getParser().parseExpression(Expr)) {
8665 Error(Loc, "expected expression");
8669 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8671 Error(Loc, "expected constant expression");
8677 if (Value->getValue() > 0xffff) {
8678 Error(Loc, "inst.n operand is too big, use inst.w instead");
8683 if (Value->getValue() > 0xffffffff) {
8685 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8690 llvm_unreachable("only supported widths are 2 and 4");
8693 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8695 if (getLexer().is(AsmToken::EndOfStatement))
8698 if (getLexer().isNot(AsmToken::Comma)) {
8699 Error(Loc, "unexpected token in directive");
8710 /// parseDirectiveLtorg
8711 /// ::= .ltorg | .pool
8712 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
8713 MCStreamer &Streamer = getParser().getStreamer();
8714 const MCSection *Section = Streamer.getCurrentSection().first;
8716 if (ConstantPool *CP = getConstantPool(Section)) {
8718 CP->emitEntries(Streamer);
8723 bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
8724 const MCSection *Section = getStreamer().getCurrentSection().first;
8726 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8727 TokError("unexpected token in directive");
8732 getStreamer().InitToTextSection();
8733 Section = getStreamer().getCurrentSection().first;
8736 if (Section->UseCodeAlign())
8737 getStreamer().EmitCodeAlignment(2, 0);
8739 getStreamer().EmitValueToAlignment(2, 0, 1, 0);
8744 /// Force static initialization.
8745 extern "C" void LLVMInitializeARMAsmParser() {
8746 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8747 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
8750 #define GET_REGISTER_MATCHER
8751 #define GET_SUBTARGET_FEATURE_NAME
8752 #define GET_MATCHER_IMPLEMENTATION
8753 #include "ARMGenAsmMatcher.inc"
8755 // Define this matcher function after the auto-generated include so we
8756 // have the match class enum definitions.
8757 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8759 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8760 // If the kind is a token for a literal immediate, check if our asm
8761 // operand matches. This is for InstAliases which have a fixed-value
8762 // immediate in the syntax.
8763 if (Kind == MCK__35_0 && Op->isImm()) {
8764 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8766 return Match_InvalidOperand;
8767 if (CE->getValue() == 0)
8768 return Match_Success;
8770 return Match_InvalidOperand;
8773 void ARMAsmParser::finishParse() {
8774 // Dump contents of assembler constant pools.
8775 MCStreamer &Streamer = getParser().getStreamer();
8776 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8777 CPE = ConstantPools.end();
8778 CPI != CPE; ++CPI) {
8779 const MCSection *Section = CPI->first;
8780 ConstantPool &CP = CPI->second;
8782 // Dump non-empty assembler constant pools at the end of the section.
8784 Streamer.SwitchSection(Section);
8785 CP.emitEntries(Streamer);