1 //===- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions -------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "ARMFeatures.h"
10 #include "ARMBaseInstrInfo.h"
11 #include "Utils/ARMBaseInfo.h"
12 #include "MCTargetDesc/ARMAddressingModes.h"
13 #include "MCTargetDesc/ARMBaseInfo.h"
14 #include "MCTargetDesc/ARMInstPrinter.h"
15 #include "MCTargetDesc/ARMMCExpr.h"
16 #include "MCTargetDesc/ARMMCTargetDesc.h"
17 #include "TargetInfo/ARMTargetInfo.h"
18 #include "llvm/ADT/APFloat.h"
19 #include "llvm/ADT/APInt.h"
20 #include "llvm/ADT/None.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallSet.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringMap.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/ADT/StringSwitch.h"
27 #include "llvm/ADT/Triple.h"
28 #include "llvm/ADT/Twine.h"
29 #include "llvm/MC/MCContext.h"
30 #include "llvm/MC/MCExpr.h"
31 #include "llvm/MC/MCInst.h"
32 #include "llvm/MC/MCInstrDesc.h"
33 #include "llvm/MC/MCInstrInfo.h"
34 #include "llvm/MC/MCObjectFileInfo.h"
35 #include "llvm/MC/MCParser/MCAsmLexer.h"
36 #include "llvm/MC/MCParser/MCAsmParser.h"
37 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
38 #include "llvm/MC/MCParser/MCAsmParserUtils.h"
39 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
40 #include "llvm/MC/MCParser/MCTargetAsmParser.h"
41 #include "llvm/MC/MCRegisterInfo.h"
42 #include "llvm/MC/MCSection.h"
43 #include "llvm/MC/MCStreamer.h"
44 #include "llvm/MC/MCSubtargetInfo.h"
45 #include "llvm/MC/MCSymbol.h"
46 #include "llvm/MC/SubtargetFeature.h"
47 #include "llvm/Support/ARMBuildAttributes.h"
48 #include "llvm/Support/ARMEHABI.h"
49 #include "llvm/Support/Casting.h"
50 #include "llvm/Support/CommandLine.h"
51 #include "llvm/Support/Compiler.h"
52 #include "llvm/Support/ErrorHandling.h"
53 #include "llvm/Support/MathExtras.h"
54 #include "llvm/Support/SMLoc.h"
55 #include "llvm/Support/TargetParser.h"
56 #include "llvm/Support/TargetRegistry.h"
57 #include "llvm/Support/raw_ostream.h"
69 #define DEBUG_TYPE "asm-parser"
74 extern const MCInstrDesc ARMInsts
[];
75 } // end namespace llvm
79 enum class ImplicitItModeTy
{ Always
, Never
, ARMOnly
, ThumbOnly
};
81 static cl::opt
<ImplicitItModeTy
> ImplicitItMode(
82 "arm-implicit-it", cl::init(ImplicitItModeTy::ARMOnly
),
83 cl::desc("Allow conditional instructions outdside of an IT block"),
84 cl::values(clEnumValN(ImplicitItModeTy::Always
, "always",
85 "Accept in both ISAs, emit implicit ITs in Thumb"),
86 clEnumValN(ImplicitItModeTy::Never
, "never",
87 "Warn in ARM, reject in Thumb"),
88 clEnumValN(ImplicitItModeTy::ARMOnly
, "arm",
89 "Accept in ARM, reject in Thumb"),
90 clEnumValN(ImplicitItModeTy::ThumbOnly
, "thumb",
91 "Warn in ARM, emit implicit ITs in Thumb")));
93 static cl::opt
<bool> AddBuildAttributes("arm-add-build-attributes",
96 enum VectorLaneTy
{ NoLanes
, AllLanes
, IndexedLane
};
98 static inline unsigned extractITMaskBit(unsigned Mask
, unsigned Position
) {
99 // Position==0 means we're not in an IT block at all. Position==1
100 // means we want the first state bit, which is always 0 (Then).
101 // Position==2 means we want the second state bit, stored at bit 3
102 // of Mask, and so on downwards. So (5 - Position) will shift the
103 // right bit down to bit 0, including the always-0 bit at bit 4 for
104 // the mandatory initial Then.
105 return (Mask
>> (5 - Position
) & 1);
108 class UnwindContext
{
109 using Locs
= SmallVector
<SMLoc
, 4>;
114 Locs PersonalityLocs
;
115 Locs PersonalityIndexLocs
;
116 Locs HandlerDataLocs
;
120 UnwindContext(MCAsmParser
&P
) : Parser(P
), FPReg(ARM::SP
) {}
122 bool hasFnStart() const { return !FnStartLocs
.empty(); }
123 bool cantUnwind() const { return !CantUnwindLocs
.empty(); }
124 bool hasHandlerData() const { return !HandlerDataLocs
.empty(); }
126 bool hasPersonality() const {
127 return !(PersonalityLocs
.empty() && PersonalityIndexLocs
.empty());
130 void recordFnStart(SMLoc L
) { FnStartLocs
.push_back(L
); }
131 void recordCantUnwind(SMLoc L
) { CantUnwindLocs
.push_back(L
); }
132 void recordPersonality(SMLoc L
) { PersonalityLocs
.push_back(L
); }
133 void recordHandlerData(SMLoc L
) { HandlerDataLocs
.push_back(L
); }
134 void recordPersonalityIndex(SMLoc L
) { PersonalityIndexLocs
.push_back(L
); }
136 void saveFPReg(int Reg
) { FPReg
= Reg
; }
137 int getFPReg() const { return FPReg
; }
139 void emitFnStartLocNotes() const {
140 for (Locs::const_iterator FI
= FnStartLocs
.begin(), FE
= FnStartLocs
.end();
142 Parser
.Note(*FI
, ".fnstart was specified here");
145 void emitCantUnwindLocNotes() const {
146 for (Locs::const_iterator UI
= CantUnwindLocs
.begin(),
147 UE
= CantUnwindLocs
.end(); UI
!= UE
; ++UI
)
148 Parser
.Note(*UI
, ".cantunwind was specified here");
151 void emitHandlerDataLocNotes() const {
152 for (Locs::const_iterator HI
= HandlerDataLocs
.begin(),
153 HE
= HandlerDataLocs
.end(); HI
!= HE
; ++HI
)
154 Parser
.Note(*HI
, ".handlerdata was specified here");
157 void emitPersonalityLocNotes() const {
158 for (Locs::const_iterator PI
= PersonalityLocs
.begin(),
159 PE
= PersonalityLocs
.end(),
160 PII
= PersonalityIndexLocs
.begin(),
161 PIE
= PersonalityIndexLocs
.end();
162 PI
!= PE
|| PII
!= PIE
;) {
163 if (PI
!= PE
&& (PII
== PIE
|| PI
->getPointer() < PII
->getPointer()))
164 Parser
.Note(*PI
++, ".personality was specified here");
165 else if (PII
!= PIE
&& (PI
== PE
|| PII
->getPointer() < PI
->getPointer()))
166 Parser
.Note(*PII
++, ".personalityindex was specified here");
168 llvm_unreachable(".personality and .personalityindex cannot be "
169 "at the same location");
174 FnStartLocs
= Locs();
175 CantUnwindLocs
= Locs();
176 PersonalityLocs
= Locs();
177 HandlerDataLocs
= Locs();
178 PersonalityIndexLocs
= Locs();
184 class ARMAsmParser
: public MCTargetAsmParser
{
185 const MCRegisterInfo
*MRI
;
188 ARMTargetStreamer
&getTargetStreamer() {
189 assert(getParser().getStreamer().getTargetStreamer() &&
190 "do not have a target streamer");
191 MCTargetStreamer
&TS
= *getParser().getStreamer().getTargetStreamer();
192 return static_cast<ARMTargetStreamer
&>(TS
);
195 // Map of register aliases registers via the .req directive.
196 StringMap
<unsigned> RegisterReqs
;
198 bool NextSymbolIsThumb
;
200 bool useImplicitITThumb() const {
201 return ImplicitItMode
== ImplicitItModeTy::Always
||
202 ImplicitItMode
== ImplicitItModeTy::ThumbOnly
;
205 bool useImplicitITARM() const {
206 return ImplicitItMode
== ImplicitItModeTy::Always
||
207 ImplicitItMode
== ImplicitItModeTy::ARMOnly
;
211 ARMCC::CondCodes Cond
; // Condition for IT block.
212 unsigned Mask
:4; // Condition mask for instructions.
213 // Starting at first 1 (from lsb).
214 // '1' condition as indicated in IT.
215 // '0' inverse of condition (else).
216 // Count of instructions in IT block is
217 // 4 - trailingzeroes(mask)
218 // Note that this does not have the same encoding
219 // as in the IT instruction, which also depends
220 // on the low bit of the condition code.
222 unsigned CurPosition
; // Current position in parsing of IT
223 // block. In range [0,4], with 0 being the IT
224 // instruction itself. Initialized according to
225 // count of instructions in block. ~0U if no
228 bool IsExplicit
; // true - The IT instruction was present in the
229 // input, we should not modify it.
230 // false - The IT instruction was added
231 // implicitly, we can extend it if that
235 SmallVector
<MCInst
, 4> PendingConditionalInsts
;
237 void flushPendingInstructions(MCStreamer
&Out
) override
{
238 if (!inImplicitITBlock()) {
239 assert(PendingConditionalInsts
.size() == 0);
243 // Emit the IT instruction
245 ITInst
.setOpcode(ARM::t2IT
);
246 ITInst
.addOperand(MCOperand::createImm(ITState
.Cond
));
247 ITInst
.addOperand(MCOperand::createImm(ITState
.Mask
));
248 Out
.EmitInstruction(ITInst
, getSTI());
250 // Emit the conditonal instructions
251 assert(PendingConditionalInsts
.size() <= 4);
252 for (const MCInst
&Inst
: PendingConditionalInsts
) {
253 Out
.EmitInstruction(Inst
, getSTI());
255 PendingConditionalInsts
.clear();
257 // Clear the IT state
259 ITState
.CurPosition
= ~0U;
262 bool inITBlock() { return ITState
.CurPosition
!= ~0U; }
263 bool inExplicitITBlock() { return inITBlock() && ITState
.IsExplicit
; }
264 bool inImplicitITBlock() { return inITBlock() && !ITState
.IsExplicit
; }
266 bool lastInITBlock() {
267 return ITState
.CurPosition
== 4 - countTrailingZeros(ITState
.Mask
);
270 void forwardITPosition() {
271 if (!inITBlock()) return;
272 // Move to the next instruction in the IT block, if there is one. If not,
273 // mark the block as done, except for implicit IT blocks, which we leave
274 // open until we find an instruction that can't be added to it.
275 unsigned TZ
= countTrailingZeros(ITState
.Mask
);
276 if (++ITState
.CurPosition
== 5 - TZ
&& ITState
.IsExplicit
)
277 ITState
.CurPosition
= ~0U; // Done with the IT block after this.
280 // Rewind the state of the current IT block, removing the last slot from it.
281 void rewindImplicitITPosition() {
282 assert(inImplicitITBlock());
283 assert(ITState
.CurPosition
> 1);
284 ITState
.CurPosition
--;
285 unsigned TZ
= countTrailingZeros(ITState
.Mask
);
286 unsigned NewMask
= 0;
287 NewMask
|= ITState
.Mask
& (0xC << TZ
);
288 NewMask
|= 0x2 << TZ
;
289 ITState
.Mask
= NewMask
;
292 // Rewind the state of the current IT block, removing the last slot from it.
293 // If we were at the first slot, this closes the IT block.
294 void discardImplicitITBlock() {
295 assert(inImplicitITBlock());
296 assert(ITState
.CurPosition
== 1);
297 ITState
.CurPosition
= ~0U;
300 // Return the low-subreg of a given Q register.
301 unsigned getDRegFromQReg(unsigned QReg
) const {
302 return MRI
->getSubReg(QReg
, ARM::dsub_0
);
305 // Get the condition code corresponding to the current IT block slot.
306 ARMCC::CondCodes
currentITCond() {
307 unsigned MaskBit
= extractITMaskBit(ITState
.Mask
, ITState
.CurPosition
);
308 return MaskBit
? ARMCC::getOppositeCondition(ITState
.Cond
) : ITState
.Cond
;
311 // Invert the condition of the current IT block slot without changing any
312 // other slots in the same block.
313 void invertCurrentITCondition() {
314 if (ITState
.CurPosition
== 1) {
315 ITState
.Cond
= ARMCC::getOppositeCondition(ITState
.Cond
);
317 ITState
.Mask
^= 1 << (5 - ITState
.CurPosition
);
321 // Returns true if the current IT block is full (all 4 slots used).
322 bool isITBlockFull() {
323 return inITBlock() && (ITState
.Mask
& 1);
326 // Extend the current implicit IT block to have one more slot with the given
328 void extendImplicitITBlock(ARMCC::CondCodes Cond
) {
329 assert(inImplicitITBlock());
330 assert(!isITBlockFull());
331 assert(Cond
== ITState
.Cond
||
332 Cond
== ARMCC::getOppositeCondition(ITState
.Cond
));
333 unsigned TZ
= countTrailingZeros(ITState
.Mask
);
334 unsigned NewMask
= 0;
335 // Keep any existing condition bits.
336 NewMask
|= ITState
.Mask
& (0xE << TZ
);
337 // Insert the new condition bit.
338 NewMask
|= (Cond
!= ITState
.Cond
) << TZ
;
339 // Move the trailing 1 down one bit.
340 NewMask
|= 1 << (TZ
- 1);
341 ITState
.Mask
= NewMask
;
344 // Create a new implicit IT block with a dummy condition code.
345 void startImplicitITBlock() {
346 assert(!inITBlock());
347 ITState
.Cond
= ARMCC::AL
;
349 ITState
.CurPosition
= 1;
350 ITState
.IsExplicit
= false;
353 // Create a new explicit IT block with the given condition and mask.
354 // The mask should be in the format used in ARMOperand and
355 // MCOperand, with a 1 implying 'e', regardless of the low bit of
357 void startExplicitITBlock(ARMCC::CondCodes Cond
, unsigned Mask
) {
358 assert(!inITBlock());
361 ITState
.CurPosition
= 0;
362 ITState
.IsExplicit
= true;
367 unsigned CurPosition
;
369 bool inVPTBlock() { return VPTState
.CurPosition
!= ~0U; }
370 void forwardVPTPosition() {
371 if (!inVPTBlock()) return;
372 unsigned TZ
= countTrailingZeros(VPTState
.Mask
);
373 if (++VPTState
.CurPosition
== 5 - TZ
)
374 VPTState
.CurPosition
= ~0U;
377 void Note(SMLoc L
, const Twine
&Msg
, SMRange Range
= None
) {
378 return getParser().Note(L
, Msg
, Range
);
381 bool Warning(SMLoc L
, const Twine
&Msg
, SMRange Range
= None
) {
382 return getParser().Warning(L
, Msg
, Range
);
385 bool Error(SMLoc L
, const Twine
&Msg
, SMRange Range
= None
) {
386 return getParser().Error(L
, Msg
, Range
);
389 bool validatetLDMRegList(const MCInst
&Inst
, const OperandVector
&Operands
,
390 unsigned ListNo
, bool IsARPop
= false);
391 bool validatetSTMRegList(const MCInst
&Inst
, const OperandVector
&Operands
,
394 int tryParseRegister();
395 bool tryParseRegisterWithWriteBack(OperandVector
&);
396 int tryParseShiftRegister(OperandVector
&);
397 bool parseRegisterList(OperandVector
&, bool EnforceOrder
= true);
398 bool parseMemory(OperandVector
&);
399 bool parseOperand(OperandVector
&, StringRef Mnemonic
);
400 bool parsePrefix(ARMMCExpr::VariantKind
&RefKind
);
401 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc
&ShiftType
,
402 unsigned &ShiftAmount
);
403 bool parseLiteralValues(unsigned Size
, SMLoc L
);
404 bool parseDirectiveThumb(SMLoc L
);
405 bool parseDirectiveARM(SMLoc L
);
406 bool parseDirectiveThumbFunc(SMLoc L
);
407 bool parseDirectiveCode(SMLoc L
);
408 bool parseDirectiveSyntax(SMLoc L
);
409 bool parseDirectiveReq(StringRef Name
, SMLoc L
);
410 bool parseDirectiveUnreq(SMLoc L
);
411 bool parseDirectiveArch(SMLoc L
);
412 bool parseDirectiveEabiAttr(SMLoc L
);
413 bool parseDirectiveCPU(SMLoc L
);
414 bool parseDirectiveFPU(SMLoc L
);
415 bool parseDirectiveFnStart(SMLoc L
);
416 bool parseDirectiveFnEnd(SMLoc L
);
417 bool parseDirectiveCantUnwind(SMLoc L
);
418 bool parseDirectivePersonality(SMLoc L
);
419 bool parseDirectiveHandlerData(SMLoc L
);
420 bool parseDirectiveSetFP(SMLoc L
);
421 bool parseDirectivePad(SMLoc L
);
422 bool parseDirectiveRegSave(SMLoc L
, bool IsVector
);
423 bool parseDirectiveInst(SMLoc L
, char Suffix
= '\0');
424 bool parseDirectiveLtorg(SMLoc L
);
425 bool parseDirectiveEven(SMLoc L
);
426 bool parseDirectivePersonalityIndex(SMLoc L
);
427 bool parseDirectiveUnwindRaw(SMLoc L
);
428 bool parseDirectiveTLSDescSeq(SMLoc L
);
429 bool parseDirectiveMovSP(SMLoc L
);
430 bool parseDirectiveObjectArch(SMLoc L
);
431 bool parseDirectiveArchExtension(SMLoc L
);
432 bool parseDirectiveAlign(SMLoc L
);
433 bool parseDirectiveThumbSet(SMLoc L
);
435 bool isMnemonicVPTPredicable(StringRef Mnemonic
, StringRef ExtraToken
);
436 StringRef
splitMnemonic(StringRef Mnemonic
, StringRef ExtraToken
,
437 unsigned &PredicationCode
,
438 unsigned &VPTPredicationCode
, bool &CarrySetting
,
439 unsigned &ProcessorIMod
, StringRef
&ITMask
);
440 void getMnemonicAcceptInfo(StringRef Mnemonic
, StringRef ExtraToken
,
441 StringRef FullInst
, bool &CanAcceptCarrySet
,
442 bool &CanAcceptPredicationCode
,
443 bool &CanAcceptVPTPredicationCode
);
445 void tryConvertingToTwoOperandForm(StringRef Mnemonic
, bool CarrySetting
,
446 OperandVector
&Operands
);
447 bool isThumb() const {
448 // FIXME: Can tablegen auto-generate this?
449 return getSTI().getFeatureBits()[ARM::ModeThumb
];
452 bool isThumbOne() const {
453 return isThumb() && !getSTI().getFeatureBits()[ARM::FeatureThumb2
];
456 bool isThumbTwo() const {
457 return isThumb() && getSTI().getFeatureBits()[ARM::FeatureThumb2
];
460 bool hasThumb() const {
461 return getSTI().getFeatureBits()[ARM::HasV4TOps
];
464 bool hasThumb2() const {
465 return getSTI().getFeatureBits()[ARM::FeatureThumb2
];
468 bool hasV6Ops() const {
469 return getSTI().getFeatureBits()[ARM::HasV6Ops
];
472 bool hasV6T2Ops() const {
473 return getSTI().getFeatureBits()[ARM::HasV6T2Ops
];
476 bool hasV6MOps() const {
477 return getSTI().getFeatureBits()[ARM::HasV6MOps
];
480 bool hasV7Ops() const {
481 return getSTI().getFeatureBits()[ARM::HasV7Ops
];
484 bool hasV8Ops() const {
485 return getSTI().getFeatureBits()[ARM::HasV8Ops
];
488 bool hasV8MBaseline() const {
489 return getSTI().getFeatureBits()[ARM::HasV8MBaselineOps
];
492 bool hasV8MMainline() const {
493 return getSTI().getFeatureBits()[ARM::HasV8MMainlineOps
];
495 bool hasV8_1MMainline() const {
496 return getSTI().getFeatureBits()[ARM::HasV8_1MMainlineOps
];
498 bool hasMVE() const {
499 return getSTI().getFeatureBits()[ARM::HasMVEIntegerOps
];
501 bool hasMVEFloat() const {
502 return getSTI().getFeatureBits()[ARM::HasMVEFloatOps
];
504 bool has8MSecExt() const {
505 return getSTI().getFeatureBits()[ARM::Feature8MSecExt
];
508 bool hasARM() const {
509 return !getSTI().getFeatureBits()[ARM::FeatureNoARM
];
512 bool hasDSP() const {
513 return getSTI().getFeatureBits()[ARM::FeatureDSP
];
516 bool hasD32() const {
517 return getSTI().getFeatureBits()[ARM::FeatureD32
];
520 bool hasV8_1aOps() const {
521 return getSTI().getFeatureBits()[ARM::HasV8_1aOps
];
524 bool hasRAS() const {
525 return getSTI().getFeatureBits()[ARM::FeatureRAS
];
529 MCSubtargetInfo
&STI
= copySTI();
530 auto FB
= ComputeAvailableFeatures(STI
.ToggleFeature(ARM::ModeThumb
));
531 setAvailableFeatures(FB
);
534 void FixModeAfterArchChange(bool WasThumb
, SMLoc Loc
);
536 bool isMClass() const {
537 return getSTI().getFeatureBits()[ARM::FeatureMClass
];
540 /// @name Auto-generated Match Functions
543 #define GET_ASSEMBLER_HEADER
544 #include "ARMGenAsmMatcher.inc"
548 OperandMatchResultTy
parseITCondCode(OperandVector
&);
549 OperandMatchResultTy
parseCoprocNumOperand(OperandVector
&);
550 OperandMatchResultTy
parseCoprocRegOperand(OperandVector
&);
551 OperandMatchResultTy
parseCoprocOptionOperand(OperandVector
&);
552 OperandMatchResultTy
parseMemBarrierOptOperand(OperandVector
&);
553 OperandMatchResultTy
parseTraceSyncBarrierOptOperand(OperandVector
&);
554 OperandMatchResultTy
parseInstSyncBarrierOptOperand(OperandVector
&);
555 OperandMatchResultTy
parseProcIFlagsOperand(OperandVector
&);
556 OperandMatchResultTy
parseMSRMaskOperand(OperandVector
&);
557 OperandMatchResultTy
parseBankedRegOperand(OperandVector
&);
558 OperandMatchResultTy
parsePKHImm(OperandVector
&O
, StringRef Op
, int Low
,
560 OperandMatchResultTy
parsePKHLSLImm(OperandVector
&O
) {
561 return parsePKHImm(O
, "lsl", 0, 31);
563 OperandMatchResultTy
parsePKHASRImm(OperandVector
&O
) {
564 return parsePKHImm(O
, "asr", 1, 32);
566 OperandMatchResultTy
parseSetEndImm(OperandVector
&);
567 OperandMatchResultTy
parseShifterImm(OperandVector
&);
568 OperandMatchResultTy
parseRotImm(OperandVector
&);
569 OperandMatchResultTy
parseModImm(OperandVector
&);
570 OperandMatchResultTy
parseBitfield(OperandVector
&);
571 OperandMatchResultTy
parsePostIdxReg(OperandVector
&);
572 OperandMatchResultTy
parseAM3Offset(OperandVector
&);
573 OperandMatchResultTy
parseFPImm(OperandVector
&);
574 OperandMatchResultTy
parseVectorList(OperandVector
&);
575 OperandMatchResultTy
parseVectorLane(VectorLaneTy
&LaneKind
, unsigned &Index
,
578 // Asm Match Converter Methods
579 void cvtThumbMultiply(MCInst
&Inst
, const OperandVector
&);
580 void cvtThumbBranches(MCInst
&Inst
, const OperandVector
&);
581 void cvtMVEVMOVQtoDReg(MCInst
&Inst
, const OperandVector
&);
583 bool validateInstruction(MCInst
&Inst
, const OperandVector
&Ops
);
584 bool processInstruction(MCInst
&Inst
, const OperandVector
&Ops
, MCStreamer
&Out
);
585 bool shouldOmitCCOutOperand(StringRef Mnemonic
, OperandVector
&Operands
);
586 bool shouldOmitPredicateOperand(StringRef Mnemonic
, OperandVector
&Operands
);
587 bool shouldOmitVectorPredicateOperand(StringRef Mnemonic
, OperandVector
&Operands
);
588 bool isITBlockTerminator(MCInst
&Inst
) const;
589 void fixupGNULDRDAlias(StringRef Mnemonic
, OperandVector
&Operands
);
590 bool validateLDRDSTRD(MCInst
&Inst
, const OperandVector
&Operands
,
591 bool Load
, bool ARMMode
, bool Writeback
);
594 enum ARMMatchResultTy
{
595 Match_RequiresITBlock
= FIRST_TARGET_MATCH_RESULT_TY
,
596 Match_RequiresNotITBlock
,
598 Match_RequiresThumb2
,
600 Match_RequiresFlagSetting
,
601 #define GET_OPERAND_DIAGNOSTIC_TYPES
602 #include "ARMGenAsmMatcher.inc"
606 ARMAsmParser(const MCSubtargetInfo
&STI
, MCAsmParser
&Parser
,
607 const MCInstrInfo
&MII
, const MCTargetOptions
&Options
)
608 : MCTargetAsmParser(Options
, STI
, MII
), UC(Parser
) {
609 MCAsmParserExtension::Initialize(Parser
);
611 // Cache the MCRegisterInfo.
612 MRI
= getContext().getRegisterInfo();
614 // Initialize the set of available features.
615 setAvailableFeatures(ComputeAvailableFeatures(STI
.getFeatureBits()));
617 // Add build attributes based on the selected target.
618 if (AddBuildAttributes
)
619 getTargetStreamer().emitTargetAttributes(STI
);
621 // Not in an ITBlock to start with.
622 ITState
.CurPosition
= ~0U;
624 VPTState
.CurPosition
= ~0U;
626 NextSymbolIsThumb
= false;
629 // Implementation of the MCTargetAsmParser interface:
630 bool ParseRegister(unsigned &RegNo
, SMLoc
&StartLoc
, SMLoc
&EndLoc
) override
;
631 bool ParseInstruction(ParseInstructionInfo
&Info
, StringRef Name
,
632 SMLoc NameLoc
, OperandVector
&Operands
) override
;
633 bool ParseDirective(AsmToken DirectiveID
) override
;
635 unsigned validateTargetOperandClass(MCParsedAsmOperand
&Op
,
636 unsigned Kind
) override
;
637 unsigned checkTargetMatchPredicate(MCInst
&Inst
) override
;
639 bool MatchAndEmitInstruction(SMLoc IDLoc
, unsigned &Opcode
,
640 OperandVector
&Operands
, MCStreamer
&Out
,
642 bool MatchingInlineAsm
) override
;
643 unsigned MatchInstruction(OperandVector
&Operands
, MCInst
&Inst
,
644 SmallVectorImpl
<NearMissInfo
> &NearMisses
,
645 bool MatchingInlineAsm
, bool &EmitInITBlock
,
648 struct NearMissMessage
{
650 SmallString
<128> Message
;
653 const char *getCustomOperandDiag(ARMMatchResultTy MatchError
);
655 void FilterNearMisses(SmallVectorImpl
<NearMissInfo
> &NearMissesIn
,
656 SmallVectorImpl
<NearMissMessage
> &NearMissesOut
,
657 SMLoc IDLoc
, OperandVector
&Operands
);
658 void ReportNearMisses(SmallVectorImpl
<NearMissInfo
> &NearMisses
, SMLoc IDLoc
,
659 OperandVector
&Operands
);
661 void doBeforeLabelEmit(MCSymbol
*Symbol
) override
;
663 void onLabelParsed(MCSymbol
*Symbol
) override
;
666 /// ARMOperand - Instances of this class represent a parsed ARM machine
668 class ARMOperand
: public MCParsedAsmOperand
{
679 k_InstSyncBarrierOpt
,
680 k_TraceSyncBarrierOpt
,
689 k_RegisterListWithAPSR
,
692 k_FPSRegisterListWithVPR
,
693 k_FPDRegisterListWithVPR
,
695 k_VectorListAllLanes
,
702 k_ConstantPoolImmediate
,
703 k_BitfieldDescriptor
,
707 SMLoc StartLoc
, EndLoc
, AlignmentLoc
;
708 SmallVector
<unsigned, 8> Registers
;
711 ARMCC::CondCodes Val
;
715 ARMVCC::VPTCodes Val
;
722 struct CoprocOptionOp
{
735 ARM_ISB::InstSyncBOpt Val
;
739 ARM_TSB::TraceSyncBOpt Val
;
743 ARM_PROC::IFlags Val
;
763 // A vector register list is a sequential list of 1 to 4 registers.
764 struct VectorListOp
{
771 struct VectorIndexOp
{
779 /// Combined record for all forms of ARM address expressions.
782 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
784 const MCConstantExpr
*OffsetImm
; // Offset immediate value
785 unsigned OffsetRegNum
; // Offset register num, when OffsetImm == NULL
786 ARM_AM::ShiftOpc ShiftType
; // Shift type for OffsetReg
787 unsigned ShiftImm
; // shift for OffsetReg.
788 unsigned Alignment
; // 0 = no alignment specified
789 // n = alignment in bytes (2, 4, 8, 16, or 32)
790 unsigned isNegative
: 1; // Negated OffsetReg? (~'U' bit)
793 struct PostIdxRegOp
{
796 ARM_AM::ShiftOpc ShiftTy
;
800 struct ShifterImmOp
{
805 struct RegShiftedRegOp
{
806 ARM_AM::ShiftOpc ShiftTy
;
812 struct RegShiftedImmOp
{
813 ARM_AM::ShiftOpc ShiftTy
;
836 struct CoprocOptionOp CoprocOption
;
837 struct MBOptOp MBOpt
;
838 struct ISBOptOp ISBOpt
;
839 struct TSBOptOp TSBOpt
;
840 struct ITMaskOp ITMask
;
841 struct IFlagsOp IFlags
;
842 struct MMaskOp MMask
;
843 struct BankedRegOp BankedReg
;
846 struct VectorListOp VectorList
;
847 struct VectorIndexOp VectorIndex
;
849 struct MemoryOp Memory
;
850 struct PostIdxRegOp PostIdxReg
;
851 struct ShifterImmOp ShifterImm
;
852 struct RegShiftedRegOp RegShiftedReg
;
853 struct RegShiftedImmOp RegShiftedImm
;
854 struct RotImmOp RotImm
;
855 struct ModImmOp ModImm
;
856 struct BitfieldOp Bitfield
;
860 ARMOperand(KindTy K
) : MCParsedAsmOperand(), Kind(K
) {}
862 /// getStartLoc - Get the location of the first token of this operand.
863 SMLoc
getStartLoc() const override
{ return StartLoc
; }
865 /// getEndLoc - Get the location of the last token of this operand.
866 SMLoc
getEndLoc() const override
{ return EndLoc
; }
868 /// getLocRange - Get the range between the first and last token of this
870 SMRange
getLocRange() const { return SMRange(StartLoc
, EndLoc
); }
872 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
873 SMLoc
getAlignmentLoc() const {
874 assert(Kind
== k_Memory
&& "Invalid access!");
878 ARMCC::CondCodes
getCondCode() const {
879 assert(Kind
== k_CondCode
&& "Invalid access!");
883 ARMVCC::VPTCodes
getVPTPred() const {
884 assert(isVPTPred() && "Invalid access!");
888 unsigned getCoproc() const {
889 assert((Kind
== k_CoprocNum
|| Kind
== k_CoprocReg
) && "Invalid access!");
893 StringRef
getToken() const {
894 assert(Kind
== k_Token
&& "Invalid access!");
895 return StringRef(Tok
.Data
, Tok
.Length
);
898 unsigned getReg() const override
{
899 assert((Kind
== k_Register
|| Kind
== k_CCOut
) && "Invalid access!");
903 const SmallVectorImpl
<unsigned> &getRegList() const {
904 assert((Kind
== k_RegisterList
|| Kind
== k_RegisterListWithAPSR
||
905 Kind
== k_DPRRegisterList
|| Kind
== k_SPRRegisterList
||
906 Kind
== k_FPSRegisterListWithVPR
||
907 Kind
== k_FPDRegisterListWithVPR
) &&
912 const MCExpr
*getImm() const {
913 assert(isImm() && "Invalid access!");
917 const MCExpr
*getConstantPoolImm() const {
918 assert(isConstantPoolImm() && "Invalid access!");
922 unsigned getVectorIndex() const {
923 assert(Kind
== k_VectorIndex
&& "Invalid access!");
924 return VectorIndex
.Val
;
927 ARM_MB::MemBOpt
getMemBarrierOpt() const {
928 assert(Kind
== k_MemBarrierOpt
&& "Invalid access!");
932 ARM_ISB::InstSyncBOpt
getInstSyncBarrierOpt() const {
933 assert(Kind
== k_InstSyncBarrierOpt
&& "Invalid access!");
937 ARM_TSB::TraceSyncBOpt
getTraceSyncBarrierOpt() const {
938 assert(Kind
== k_TraceSyncBarrierOpt
&& "Invalid access!");
942 ARM_PROC::IFlags
getProcIFlags() const {
943 assert(Kind
== k_ProcIFlags
&& "Invalid access!");
947 unsigned getMSRMask() const {
948 assert(Kind
== k_MSRMask
&& "Invalid access!");
952 unsigned getBankedReg() const {
953 assert(Kind
== k_BankedReg
&& "Invalid access!");
954 return BankedReg
.Val
;
957 bool isCoprocNum() const { return Kind
== k_CoprocNum
; }
958 bool isCoprocReg() const { return Kind
== k_CoprocReg
; }
959 bool isCoprocOption() const { return Kind
== k_CoprocOption
; }
960 bool isCondCode() const { return Kind
== k_CondCode
; }
961 bool isVPTPred() const { return Kind
== k_VPTPred
; }
962 bool isCCOut() const { return Kind
== k_CCOut
; }
963 bool isITMask() const { return Kind
== k_ITCondMask
; }
964 bool isITCondCode() const { return Kind
== k_CondCode
; }
965 bool isImm() const override
{
966 return Kind
== k_Immediate
;
969 bool isARMBranchTarget() const {
970 if (!isImm()) return false;
972 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm()))
973 return CE
->getValue() % 4 == 0;
978 bool isThumbBranchTarget() const {
979 if (!isImm()) return false;
981 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm()))
982 return CE
->getValue() % 2 == 0;
986 // checks whether this operand is an unsigned offset which fits is a field
987 // of specified width and scaled by a specific number of bits
988 template<unsigned width
, unsigned scale
>
989 bool isUnsignedOffset() const {
990 if (!isImm()) return false;
991 if (isa
<MCSymbolRefExpr
>(Imm
.Val
)) return true;
992 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Imm
.Val
)) {
993 int64_t Val
= CE
->getValue();
994 int64_t Align
= 1LL << scale
;
995 int64_t Max
= Align
* ((1LL << width
) - 1);
996 return ((Val
% Align
) == 0) && (Val
>= 0) && (Val
<= Max
);
1001 // checks whether this operand is an signed offset which fits is a field
1002 // of specified width and scaled by a specific number of bits
1003 template<unsigned width
, unsigned scale
>
1004 bool isSignedOffset() const {
1005 if (!isImm()) return false;
1006 if (isa
<MCSymbolRefExpr
>(Imm
.Val
)) return true;
1007 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Imm
.Val
)) {
1008 int64_t Val
= CE
->getValue();
1009 int64_t Align
= 1LL << scale
;
1010 int64_t Max
= Align
* ((1LL << (width
-1)) - 1);
1011 int64_t Min
= -Align
* (1LL << (width
-1));
1012 return ((Val
% Align
) == 0) && (Val
>= Min
) && (Val
<= Max
);
1017 // checks whether this operand is an offset suitable for the LE /
1018 // LETP instructions in Arm v8.1M
1019 bool isLEOffset() const {
1020 if (!isImm()) return false;
1021 if (isa
<MCSymbolRefExpr
>(Imm
.Val
)) return true;
1022 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Imm
.Val
)) {
1023 int64_t Val
= CE
->getValue();
1024 return Val
< 0 && Val
>= -4094 && (Val
& 1) == 0;
1029 // checks whether this operand is a memory operand computed as an offset
1030 // applied to PC. the offset may have 8 bits of magnitude and is represented
1031 // with two bits of shift. textually it may be either [pc, #imm], #imm or
1032 // relocable expression...
1033 bool isThumbMemPC() const {
1036 if (isa
<MCSymbolRefExpr
>(Imm
.Val
)) return true;
1037 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Imm
.Val
);
1038 if (!CE
) return false;
1039 Val
= CE
->getValue();
1041 else if (isGPRMem()) {
1042 if(!Memory
.OffsetImm
|| Memory
.OffsetRegNum
) return false;
1043 if(Memory
.BaseRegNum
!= ARM::PC
) return false;
1044 Val
= Memory
.OffsetImm
->getValue();
1047 return ((Val
% 4) == 0) && (Val
>= 0) && (Val
<= 1020);
1050 bool isFPImm() const {
1051 if (!isImm()) return false;
1052 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1053 if (!CE
) return false;
1054 int Val
= ARM_AM::getFP32Imm(APInt(32, CE
->getValue()));
1058 template<int64_t N
, int64_t M
>
1059 bool isImmediate() const {
1060 if (!isImm()) return false;
1061 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1062 if (!CE
) return false;
1063 int64_t Value
= CE
->getValue();
1064 return Value
>= N
&& Value
<= M
;
1067 template<int64_t N
, int64_t M
>
1068 bool isImmediateS4() const {
1069 if (!isImm()) return false;
1070 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1071 if (!CE
) return false;
1072 int64_t Value
= CE
->getValue();
1073 return ((Value
& 3) == 0) && Value
>= N
&& Value
<= M
;
1075 template<int64_t N
, int64_t M
>
1076 bool isImmediateS2() const {
1077 if (!isImm()) return false;
1078 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1079 if (!CE
) return false;
1080 int64_t Value
= CE
->getValue();
1081 return ((Value
& 1) == 0) && Value
>= N
&& Value
<= M
;
1083 bool isFBits16() const {
1084 return isImmediate
<0, 17>();
1086 bool isFBits32() const {
1087 return isImmediate
<1, 33>();
1089 bool isImm8s4() const {
1090 return isImmediateS4
<-1020, 1020>();
1092 bool isImm7s4() const {
1093 return isImmediateS4
<-508, 508>();
1095 bool isImm7Shift0() const {
1096 return isImmediate
<-127, 127>();
1098 bool isImm7Shift1() const {
1099 return isImmediateS2
<-255, 255>();
1101 bool isImm7Shift2() const {
1102 return isImmediateS4
<-511, 511>();
1104 bool isImm7() const {
1105 return isImmediate
<-127, 127>();
1107 bool isImm0_1020s4() const {
1108 return isImmediateS4
<0, 1020>();
1110 bool isImm0_508s4() const {
1111 return isImmediateS4
<0, 508>();
1113 bool isImm0_508s4Neg() const {
1114 if (!isImm()) return false;
1115 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1116 if (!CE
) return false;
1117 int64_t Value
= -CE
->getValue();
1118 // explicitly exclude zero. we want that to use the normal 0_508 version.
1119 return ((Value
& 3) == 0) && Value
> 0 && Value
<= 508;
1122 bool isImm0_4095Neg() const {
1123 if (!isImm()) return false;
1124 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1125 if (!CE
) return false;
1126 // isImm0_4095Neg is used with 32-bit immediates only.
1127 // 32-bit immediates are zero extended to 64-bit when parsed,
1128 // thus simple -CE->getValue() results in a big negative number,
1129 // not a small positive number as intended
1130 if ((CE
->getValue() >> 32) > 0) return false;
1131 uint32_t Value
= -static_cast<uint32_t>(CE
->getValue());
1132 return Value
> 0 && Value
< 4096;
1135 bool isImm0_7() const {
1136 return isImmediate
<0, 7>();
1139 bool isImm1_16() const {
1140 return isImmediate
<1, 16>();
1143 bool isImm1_32() const {
1144 return isImmediate
<1, 32>();
1147 bool isImm8_255() const {
1148 return isImmediate
<8, 255>();
1151 bool isImm256_65535Expr() const {
1152 if (!isImm()) return false;
1153 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1154 // If it's not a constant expression, it'll generate a fixup and be
1156 if (!CE
) return true;
1157 int64_t Value
= CE
->getValue();
1158 return Value
>= 256 && Value
< 65536;
1161 bool isImm0_65535Expr() const {
1162 if (!isImm()) return false;
1163 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1164 // If it's not a constant expression, it'll generate a fixup and be
1166 if (!CE
) return true;
1167 int64_t Value
= CE
->getValue();
1168 return Value
>= 0 && Value
< 65536;
1171 bool isImm24bit() const {
1172 return isImmediate
<0, 0xffffff + 1>();
1175 bool isImmThumbSR() const {
1176 return isImmediate
<1, 33>();
1180 bool isExpImmValue(uint64_t Value
) const {
1181 uint64_t mask
= (1 << shift
) - 1;
1182 if ((Value
& mask
) != 0 || (Value
>> shift
) > 0xff)
1188 bool isExpImm() const {
1189 if (!isImm()) return false;
1190 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1191 if (!CE
) return false;
1193 return isExpImmValue
<shift
>(CE
->getValue());
1196 template<int shift
, int size
>
1197 bool isInvertedExpImm() const {
1198 if (!isImm()) return false;
1199 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1200 if (!CE
) return false;
1202 uint64_t OriginalValue
= CE
->getValue();
1203 uint64_t InvertedValue
= OriginalValue
^ (((uint64_t)1 << size
) - 1);
1204 return isExpImmValue
<shift
>(InvertedValue
);
1207 bool isPKHLSLImm() const {
1208 return isImmediate
<0, 32>();
1211 bool isPKHASRImm() const {
1212 return isImmediate
<0, 33>();
1215 bool isAdrLabel() const {
1216 // If we have an immediate that's not a constant, treat it as a label
1217 // reference needing a fixup.
1218 if (isImm() && !isa
<MCConstantExpr
>(getImm()))
1221 // If it is a constant, it must fit into a modified immediate encoding.
1222 if (!isImm()) return false;
1223 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1224 if (!CE
) return false;
1225 int64_t Value
= CE
->getValue();
1226 return (ARM_AM::getSOImmVal(Value
) != -1 ||
1227 ARM_AM::getSOImmVal(-Value
) != -1);
1230 bool isT2SOImm() const {
1231 // If we have an immediate that's not a constant, treat it as an expression
1233 if (isImm() && !isa
<MCConstantExpr
>(getImm())) {
1234 // We want to avoid matching :upper16: and :lower16: as we want these
1235 // expressions to match in isImm0_65535Expr()
1236 const ARMMCExpr
*ARM16Expr
= dyn_cast
<ARMMCExpr
>(getImm());
1237 return (!ARM16Expr
|| (ARM16Expr
->getKind() != ARMMCExpr::VK_ARM_HI16
&&
1238 ARM16Expr
->getKind() != ARMMCExpr::VK_ARM_LO16
));
1240 if (!isImm()) return false;
1241 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1242 if (!CE
) return false;
1243 int64_t Value
= CE
->getValue();
1244 return ARM_AM::getT2SOImmVal(Value
) != -1;
1247 bool isT2SOImmNot() const {
1248 if (!isImm()) return false;
1249 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1250 if (!CE
) return false;
1251 int64_t Value
= CE
->getValue();
1252 return ARM_AM::getT2SOImmVal(Value
) == -1 &&
1253 ARM_AM::getT2SOImmVal(~Value
) != -1;
1256 bool isT2SOImmNeg() const {
1257 if (!isImm()) return false;
1258 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1259 if (!CE
) return false;
1260 int64_t Value
= CE
->getValue();
1261 // Only use this when not representable as a plain so_imm.
1262 return ARM_AM::getT2SOImmVal(Value
) == -1 &&
1263 ARM_AM::getT2SOImmVal(-Value
) != -1;
1266 bool isSetEndImm() const {
1267 if (!isImm()) return false;
1268 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1269 if (!CE
) return false;
1270 int64_t Value
= CE
->getValue();
1271 return Value
== 1 || Value
== 0;
1274 bool isReg() const override
{ return Kind
== k_Register
; }
1275 bool isRegList() const { return Kind
== k_RegisterList
; }
1276 bool isRegListWithAPSR() const {
1277 return Kind
== k_RegisterListWithAPSR
|| Kind
== k_RegisterList
;
1279 bool isDPRRegList() const { return Kind
== k_DPRRegisterList
; }
1280 bool isSPRRegList() const { return Kind
== k_SPRRegisterList
; }
1281 bool isFPSRegListWithVPR() const { return Kind
== k_FPSRegisterListWithVPR
; }
1282 bool isFPDRegListWithVPR() const { return Kind
== k_FPDRegisterListWithVPR
; }
1283 bool isToken() const override
{ return Kind
== k_Token
; }
1284 bool isMemBarrierOpt() const { return Kind
== k_MemBarrierOpt
; }
1285 bool isInstSyncBarrierOpt() const { return Kind
== k_InstSyncBarrierOpt
; }
1286 bool isTraceSyncBarrierOpt() const { return Kind
== k_TraceSyncBarrierOpt
; }
1287 bool isMem() const override
{
1288 return isGPRMem() || isMVEMem();
1290 bool isMVEMem() const {
1291 if (Kind
!= k_Memory
)
1293 if (Memory
.BaseRegNum
&&
1294 !ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(Memory
.BaseRegNum
) &&
1295 !ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(Memory
.BaseRegNum
))
1297 if (Memory
.OffsetRegNum
&&
1298 !ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(
1299 Memory
.OffsetRegNum
))
1303 bool isGPRMem() const {
1304 if (Kind
!= k_Memory
)
1306 if (Memory
.BaseRegNum
&&
1307 !ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(Memory
.BaseRegNum
))
1309 if (Memory
.OffsetRegNum
&&
1310 !ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(Memory
.OffsetRegNum
))
1314 bool isShifterImm() const { return Kind
== k_ShifterImmediate
; }
1315 bool isRegShiftedReg() const {
1316 return Kind
== k_ShiftedRegister
&&
1317 ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(
1318 RegShiftedReg
.SrcReg
) &&
1319 ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(
1320 RegShiftedReg
.ShiftReg
);
1322 bool isRegShiftedImm() const {
1323 return Kind
== k_ShiftedImmediate
&&
1324 ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(
1325 RegShiftedImm
.SrcReg
);
1327 bool isRotImm() const { return Kind
== k_RotateImmediate
; }
1329 template<unsigned Min
, unsigned Max
>
1330 bool isPowerTwoInRange() const {
1331 if (!isImm()) return false;
1332 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1333 if (!CE
) return false;
1334 int64_t Value
= CE
->getValue();
1335 return Value
> 0 && countPopulation((uint64_t)Value
) == 1 &&
1336 Value
>= Min
&& Value
<= Max
;
1338 bool isModImm() const { return Kind
== k_ModifiedImmediate
; }
1340 bool isModImmNot() const {
1341 if (!isImm()) return false;
1342 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1343 if (!CE
) return false;
1344 int64_t Value
= CE
->getValue();
1345 return ARM_AM::getSOImmVal(~Value
) != -1;
1348 bool isModImmNeg() const {
1349 if (!isImm()) return false;
1350 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1351 if (!CE
) return false;
1352 int64_t Value
= CE
->getValue();
1353 return ARM_AM::getSOImmVal(Value
) == -1 &&
1354 ARM_AM::getSOImmVal(-Value
) != -1;
1357 bool isThumbModImmNeg1_7() const {
1358 if (!isImm()) return false;
1359 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1360 if (!CE
) return false;
1361 int32_t Value
= -(int32_t)CE
->getValue();
1362 return 0 < Value
&& Value
< 8;
1365 bool isThumbModImmNeg8_255() const {
1366 if (!isImm()) return false;
1367 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1368 if (!CE
) return false;
1369 int32_t Value
= -(int32_t)CE
->getValue();
1370 return 7 < Value
&& Value
< 256;
1373 bool isConstantPoolImm() const { return Kind
== k_ConstantPoolImmediate
; }
1374 bool isBitfield() const { return Kind
== k_BitfieldDescriptor
; }
1375 bool isPostIdxRegShifted() const {
1376 return Kind
== k_PostIndexRegister
&&
1377 ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(PostIdxReg
.RegNum
);
1379 bool isPostIdxReg() const {
1380 return isPostIdxRegShifted() && PostIdxReg
.ShiftTy
== ARM_AM::no_shift
;
1382 bool isMemNoOffset(bool alignOK
= false, unsigned Alignment
= 0) const {
1385 // No offset of any kind.
1386 return Memory
.OffsetRegNum
== 0 && Memory
.OffsetImm
== nullptr &&
1387 (alignOK
|| Memory
.Alignment
== Alignment
);
1389 bool isMemNoOffsetT2(bool alignOK
= false, unsigned Alignment
= 0) const {
1393 if (!ARMMCRegisterClasses
[ARM::GPRnopcRegClassID
].contains(
1397 // No offset of any kind.
1398 return Memory
.OffsetRegNum
== 0 && Memory
.OffsetImm
== nullptr &&
1399 (alignOK
|| Memory
.Alignment
== Alignment
);
1401 bool isMemNoOffsetT2NoSp(bool alignOK
= false, unsigned Alignment
= 0) const {
1405 if (!ARMMCRegisterClasses
[ARM::rGPRRegClassID
].contains(
1409 // No offset of any kind.
1410 return Memory
.OffsetRegNum
== 0 && Memory
.OffsetImm
== nullptr &&
1411 (alignOK
|| Memory
.Alignment
== Alignment
);
1413 bool isMemNoOffsetT(bool alignOK
= false, unsigned Alignment
= 0) const {
1417 if (!ARMMCRegisterClasses
[ARM::tGPRRegClassID
].contains(
1421 // No offset of any kind.
1422 return Memory
.OffsetRegNum
== 0 && Memory
.OffsetImm
== nullptr &&
1423 (alignOK
|| Memory
.Alignment
== Alignment
);
1425 bool isMemPCRelImm12() const {
1426 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1428 // Base register must be PC.
1429 if (Memory
.BaseRegNum
!= ARM::PC
)
1431 // Immediate offset in range [-4095, 4095].
1432 if (!Memory
.OffsetImm
) return true;
1433 int64_t Val
= Memory
.OffsetImm
->getValue();
1434 return (Val
> -4096 && Val
< 4096) ||
1435 (Val
== std::numeric_limits
<int32_t>::min());
1438 bool isAlignedMemory() const {
1439 return isMemNoOffset(true);
1442 bool isAlignedMemoryNone() const {
1443 return isMemNoOffset(false, 0);
1446 bool isDupAlignedMemoryNone() const {
1447 return isMemNoOffset(false, 0);
1450 bool isAlignedMemory16() const {
1451 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1453 return isMemNoOffset(false, 0);
1456 bool isDupAlignedMemory16() const {
1457 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1459 return isMemNoOffset(false, 0);
1462 bool isAlignedMemory32() const {
1463 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1465 return isMemNoOffset(false, 0);
1468 bool isDupAlignedMemory32() const {
1469 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1471 return isMemNoOffset(false, 0);
1474 bool isAlignedMemory64() const {
1475 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1477 return isMemNoOffset(false, 0);
1480 bool isDupAlignedMemory64() const {
1481 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1483 return isMemNoOffset(false, 0);
1486 bool isAlignedMemory64or128() const {
1487 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1489 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1491 return isMemNoOffset(false, 0);
1494 bool isDupAlignedMemory64or128() const {
1495 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1497 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1499 return isMemNoOffset(false, 0);
1502 bool isAlignedMemory64or128or256() const {
1503 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1505 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1507 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1509 return isMemNoOffset(false, 0);
1512 bool isAddrMode2() const {
1513 if (!isGPRMem() || Memory
.Alignment
!= 0) return false;
1514 // Check for register offset.
1515 if (Memory
.OffsetRegNum
) return true;
1516 // Immediate offset in range [-4095, 4095].
1517 if (!Memory
.OffsetImm
) return true;
1518 int64_t Val
= Memory
.OffsetImm
->getValue();
1519 return Val
> -4096 && Val
< 4096;
1522 bool isAM2OffsetImm() const {
1523 if (!isImm()) return false;
1524 // Immediate offset in range [-4095, 4095].
1525 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1526 if (!CE
) return false;
1527 int64_t Val
= CE
->getValue();
1528 return (Val
== std::numeric_limits
<int32_t>::min()) ||
1529 (Val
> -4096 && Val
< 4096);
1532 bool isAddrMode3() const {
1533 // If we have an immediate that's not a constant, treat it as a label
1534 // reference needing a fixup. If it is a constant, it's something else
1535 // and we reject it.
1536 if (isImm() && !isa
<MCConstantExpr
>(getImm()))
1538 if (!isGPRMem() || Memory
.Alignment
!= 0) return false;
1539 // No shifts are legal for AM3.
1540 if (Memory
.ShiftType
!= ARM_AM::no_shift
) return false;
1541 // Check for register offset.
1542 if (Memory
.OffsetRegNum
) return true;
1543 // Immediate offset in range [-255, 255].
1544 if (!Memory
.OffsetImm
) return true;
1545 int64_t Val
= Memory
.OffsetImm
->getValue();
1546 // The #-0 offset is encoded as std::numeric_limits<int32_t>::min(), and we
1547 // have to check for this too.
1548 return (Val
> -256 && Val
< 256) ||
1549 Val
== std::numeric_limits
<int32_t>::min();
1552 bool isAM3Offset() const {
1557 // Immediate offset in range [-255, 255].
1558 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1559 if (!CE
) return false;
1560 int64_t Val
= CE
->getValue();
1561 // Special case, #-0 is std::numeric_limits<int32_t>::min().
1562 return (Val
> -256 && Val
< 256) ||
1563 Val
== std::numeric_limits
<int32_t>::min();
1566 bool isAddrMode5() const {
1567 // If we have an immediate that's not a constant, treat it as a label
1568 // reference needing a fixup. If it is a constant, it's something else
1569 // and we reject it.
1570 if (isImm() && !isa
<MCConstantExpr
>(getImm()))
1572 if (!isGPRMem() || Memory
.Alignment
!= 0) return false;
1573 // Check for register offset.
1574 if (Memory
.OffsetRegNum
) return false;
1575 // Immediate offset in range [-1020, 1020] and a multiple of 4.
1576 if (!Memory
.OffsetImm
) return true;
1577 int64_t Val
= Memory
.OffsetImm
->getValue();
1578 return (Val
>= -1020 && Val
<= 1020 && ((Val
& 3) == 0)) ||
1579 Val
== std::numeric_limits
<int32_t>::min();
1582 bool isAddrMode5FP16() const {
1583 // If we have an immediate that's not a constant, treat it as a label
1584 // reference needing a fixup. If it is a constant, it's something else
1585 // and we reject it.
1586 if (isImm() && !isa
<MCConstantExpr
>(getImm()))
1588 if (!isGPRMem() || Memory
.Alignment
!= 0) return false;
1589 // Check for register offset.
1590 if (Memory
.OffsetRegNum
) return false;
1591 // Immediate offset in range [-510, 510] and a multiple of 2.
1592 if (!Memory
.OffsetImm
) return true;
1593 int64_t Val
= Memory
.OffsetImm
->getValue();
1594 return (Val
>= -510 && Val
<= 510 && ((Val
& 1) == 0)) ||
1595 Val
== std::numeric_limits
<int32_t>::min();
1598 bool isMemTBB() const {
1599 if (!isGPRMem() || !Memory
.OffsetRegNum
|| Memory
.isNegative
||
1600 Memory
.ShiftType
!= ARM_AM::no_shift
|| Memory
.Alignment
!= 0)
1605 bool isMemTBH() const {
1606 if (!isGPRMem() || !Memory
.OffsetRegNum
|| Memory
.isNegative
||
1607 Memory
.ShiftType
!= ARM_AM::lsl
|| Memory
.ShiftImm
!= 1 ||
1608 Memory
.Alignment
!= 0 )
1613 bool isMemRegOffset() const {
1614 if (!isGPRMem() || !Memory
.OffsetRegNum
|| Memory
.Alignment
!= 0)
1619 bool isT2MemRegOffset() const {
1620 if (!isGPRMem() || !Memory
.OffsetRegNum
|| Memory
.isNegative
||
1621 Memory
.Alignment
!= 0 || Memory
.BaseRegNum
== ARM::PC
)
1623 // Only lsl #{0, 1, 2, 3} allowed.
1624 if (Memory
.ShiftType
== ARM_AM::no_shift
)
1626 if (Memory
.ShiftType
!= ARM_AM::lsl
|| Memory
.ShiftImm
> 3)
1631 bool isMemThumbRR() const {
1632 // Thumb reg+reg addressing is simple. Just two registers, a base and
1633 // an offset. No shifts, negations or any other complicating factors.
1634 if (!isGPRMem() || !Memory
.OffsetRegNum
|| Memory
.isNegative
||
1635 Memory
.ShiftType
!= ARM_AM::no_shift
|| Memory
.Alignment
!= 0)
1637 return isARMLowRegister(Memory
.BaseRegNum
) &&
1638 (!Memory
.OffsetRegNum
|| isARMLowRegister(Memory
.OffsetRegNum
));
1641 bool isMemThumbRIs4() const {
1642 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 ||
1643 !isARMLowRegister(Memory
.BaseRegNum
) || Memory
.Alignment
!= 0)
1645 // Immediate offset, multiple of 4 in range [0, 124].
1646 if (!Memory
.OffsetImm
) return true;
1647 int64_t Val
= Memory
.OffsetImm
->getValue();
1648 return Val
>= 0 && Val
<= 124 && (Val
% 4) == 0;
1651 bool isMemThumbRIs2() const {
1652 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 ||
1653 !isARMLowRegister(Memory
.BaseRegNum
) || Memory
.Alignment
!= 0)
1655 // Immediate offset, multiple of 4 in range [0, 62].
1656 if (!Memory
.OffsetImm
) return true;
1657 int64_t Val
= Memory
.OffsetImm
->getValue();
1658 return Val
>= 0 && Val
<= 62 && (Val
% 2) == 0;
1661 bool isMemThumbRIs1() const {
1662 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 ||
1663 !isARMLowRegister(Memory
.BaseRegNum
) || Memory
.Alignment
!= 0)
1665 // Immediate offset in range [0, 31].
1666 if (!Memory
.OffsetImm
) return true;
1667 int64_t Val
= Memory
.OffsetImm
->getValue();
1668 return Val
>= 0 && Val
<= 31;
1671 bool isMemThumbSPI() const {
1672 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 ||
1673 Memory
.BaseRegNum
!= ARM::SP
|| Memory
.Alignment
!= 0)
1675 // Immediate offset, multiple of 4 in range [0, 1020].
1676 if (!Memory
.OffsetImm
) return true;
1677 int64_t Val
= Memory
.OffsetImm
->getValue();
1678 return Val
>= 0 && Val
<= 1020 && (Val
% 4) == 0;
1681 bool isMemImm8s4Offset() const {
1682 // If we have an immediate that's not a constant, treat it as a label
1683 // reference needing a fixup. If it is a constant, it's something else
1684 // and we reject it.
1685 if (isImm() && !isa
<MCConstantExpr
>(getImm()))
1687 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1689 // Immediate offset a multiple of 4 in range [-1020, 1020].
1690 if (!Memory
.OffsetImm
) return true;
1691 int64_t Val
= Memory
.OffsetImm
->getValue();
1692 // Special case, #-0 is std::numeric_limits<int32_t>::min().
1693 return (Val
>= -1020 && Val
<= 1020 && (Val
& 3) == 0) ||
1694 Val
== std::numeric_limits
<int32_t>::min();
1696 bool isMemImm7s4Offset() const {
1697 // If we have an immediate that's not a constant, treat it as a label
1698 // reference needing a fixup. If it is a constant, it's something else
1699 // and we reject it.
1700 if (isImm() && !isa
<MCConstantExpr
>(getImm()))
1702 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0 ||
1703 !ARMMCRegisterClasses
[ARM::GPRnopcRegClassID
].contains(
1706 // Immediate offset a multiple of 4 in range [-508, 508].
1707 if (!Memory
.OffsetImm
) return true;
1708 int64_t Val
= Memory
.OffsetImm
->getValue();
1709 // Special case, #-0 is INT32_MIN.
1710 return (Val
>= -508 && Val
<= 508 && (Val
& 3) == 0) || Val
== INT32_MIN
;
1712 bool isMemImm0_1020s4Offset() const {
1713 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1715 // Immediate offset a multiple of 4 in range [0, 1020].
1716 if (!Memory
.OffsetImm
) return true;
1717 int64_t Val
= Memory
.OffsetImm
->getValue();
1718 return Val
>= 0 && Val
<= 1020 && (Val
& 3) == 0;
1721 bool isMemImm8Offset() const {
1722 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1724 // Base reg of PC isn't allowed for these encodings.
1725 if (Memory
.BaseRegNum
== ARM::PC
) return false;
1726 // Immediate offset in range [-255, 255].
1727 if (!Memory
.OffsetImm
) return true;
1728 int64_t Val
= Memory
.OffsetImm
->getValue();
1729 return (Val
== std::numeric_limits
<int32_t>::min()) ||
1730 (Val
> -256 && Val
< 256);
1733 template<unsigned Bits
, unsigned RegClassID
>
1734 bool isMemImm7ShiftedOffset() const {
1735 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0 ||
1736 !ARMMCRegisterClasses
[RegClassID
].contains(Memory
.BaseRegNum
))
1739 // Expect an immediate offset equal to an element of the range
1740 // [-127, 127], shifted left by Bits.
1742 if (!Memory
.OffsetImm
) return true;
1743 int64_t Val
= Memory
.OffsetImm
->getValue();
1745 // INT32_MIN is a special-case value (indicating the encoding with
1746 // zero offset and the subtract bit set)
1747 if (Val
== INT32_MIN
)
1750 unsigned Divisor
= 1U << Bits
;
1752 // Check that the low bits are zero
1753 if (Val
% Divisor
!= 0)
1756 // Check that the remaining offset is within range.
1758 return (Val
>= -127 && Val
<= 127);
1761 template <int shift
> bool isMemRegRQOffset() const {
1762 if (!isMVEMem() || Memory
.OffsetImm
!= 0 || Memory
.Alignment
!= 0)
1765 if (!ARMMCRegisterClasses
[ARM::GPRnopcRegClassID
].contains(
1768 if (!ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(
1769 Memory
.OffsetRegNum
))
1772 if (shift
== 0 && Memory
.ShiftType
!= ARM_AM::no_shift
)
1776 (Memory
.ShiftType
!= ARM_AM::uxtw
|| Memory
.ShiftImm
!= shift
))
1782 template <int shift
> bool isMemRegQOffset() const {
1783 if (!isMVEMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1786 if (!ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(
1790 if(!Memory
.OffsetImm
) return true;
1791 static_assert(shift
< 56,
1792 "Such that we dont shift by a value higher than 62");
1793 int64_t Val
= Memory
.OffsetImm
->getValue();
1795 // The value must be a multiple of (1 << shift)
1796 if ((Val
& ((1U << shift
) - 1)) != 0)
1799 // And be in the right range, depending on the amount that it is shifted
1800 // by. Shift 0, is equal to 7 unsigned bits, the sign bit is set
1802 int64_t Range
= (1U << (7+shift
)) - 1;
1803 return (Val
== INT32_MIN
) || (Val
> -Range
&& Val
< Range
);
1806 bool isMemPosImm8Offset() const {
1807 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1809 // Immediate offset in range [0, 255].
1810 if (!Memory
.OffsetImm
) return true;
1811 int64_t Val
= Memory
.OffsetImm
->getValue();
1812 return Val
>= 0 && Val
< 256;
1815 bool isMemNegImm8Offset() const {
1816 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1818 // Base reg of PC isn't allowed for these encodings.
1819 if (Memory
.BaseRegNum
== ARM::PC
) return false;
1820 // Immediate offset in range [-255, -1].
1821 if (!Memory
.OffsetImm
) return false;
1822 int64_t Val
= Memory
.OffsetImm
->getValue();
1823 return (Val
== std::numeric_limits
<int32_t>::min()) ||
1824 (Val
> -256 && Val
< 0);
1827 bool isMemUImm12Offset() const {
1828 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1830 // Immediate offset in range [0, 4095].
1831 if (!Memory
.OffsetImm
) return true;
1832 int64_t Val
= Memory
.OffsetImm
->getValue();
1833 return (Val
>= 0 && Val
< 4096);
1836 bool isMemImm12Offset() const {
1837 // If we have an immediate that's not a constant, treat it as a label
1838 // reference needing a fixup. If it is a constant, it's something else
1839 // and we reject it.
1841 if (isImm() && !isa
<MCConstantExpr
>(getImm()))
1844 if (!isGPRMem() || Memory
.OffsetRegNum
!= 0 || Memory
.Alignment
!= 0)
1846 // Immediate offset in range [-4095, 4095].
1847 if (!Memory
.OffsetImm
) return true;
1848 int64_t Val
= Memory
.OffsetImm
->getValue();
1849 return (Val
> -4096 && Val
< 4096) ||
1850 (Val
== std::numeric_limits
<int32_t>::min());
1853 bool isConstPoolAsmImm() const {
1854 // Delay processing of Constant Pool Immediate, this will turn into
1855 // a constant. Match no other operand
1856 return (isConstantPoolImm());
1859 bool isPostIdxImm8() const {
1860 if (!isImm()) return false;
1861 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1862 if (!CE
) return false;
1863 int64_t Val
= CE
->getValue();
1864 return (Val
> -256 && Val
< 256) ||
1865 (Val
== std::numeric_limits
<int32_t>::min());
1868 bool isPostIdxImm8s4() const {
1869 if (!isImm()) return false;
1870 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
1871 if (!CE
) return false;
1872 int64_t Val
= CE
->getValue();
1873 return ((Val
& 3) == 0 && Val
>= -1020 && Val
<= 1020) ||
1874 (Val
== std::numeric_limits
<int32_t>::min());
1877 bool isMSRMask() const { return Kind
== k_MSRMask
; }
1878 bool isBankedReg() const { return Kind
== k_BankedReg
; }
1879 bool isProcIFlags() const { return Kind
== k_ProcIFlags
; }
1882 bool isSingleSpacedVectorList() const {
1883 return Kind
== k_VectorList
&& !VectorList
.isDoubleSpaced
;
1886 bool isDoubleSpacedVectorList() const {
1887 return Kind
== k_VectorList
&& VectorList
.isDoubleSpaced
;
1890 bool isVecListOneD() const {
1891 if (!isSingleSpacedVectorList()) return false;
1892 return VectorList
.Count
== 1;
1895 bool isVecListTwoMQ() const {
1896 return isSingleSpacedVectorList() && VectorList
.Count
== 2 &&
1897 ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(
1901 bool isVecListDPair() const {
1902 if (!isSingleSpacedVectorList()) return false;
1903 return (ARMMCRegisterClasses
[ARM::DPairRegClassID
]
1904 .contains(VectorList
.RegNum
));
1907 bool isVecListThreeD() const {
1908 if (!isSingleSpacedVectorList()) return false;
1909 return VectorList
.Count
== 3;
1912 bool isVecListFourD() const {
1913 if (!isSingleSpacedVectorList()) return false;
1914 return VectorList
.Count
== 4;
1917 bool isVecListDPairSpaced() const {
1918 if (Kind
!= k_VectorList
) return false;
1919 if (isSingleSpacedVectorList()) return false;
1920 return (ARMMCRegisterClasses
[ARM::DPairSpcRegClassID
]
1921 .contains(VectorList
.RegNum
));
1924 bool isVecListThreeQ() const {
1925 if (!isDoubleSpacedVectorList()) return false;
1926 return VectorList
.Count
== 3;
1929 bool isVecListFourQ() const {
1930 if (!isDoubleSpacedVectorList()) return false;
1931 return VectorList
.Count
== 4;
1934 bool isVecListFourMQ() const {
1935 return isSingleSpacedVectorList() && VectorList
.Count
== 4 &&
1936 ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(
1940 bool isSingleSpacedVectorAllLanes() const {
1941 return Kind
== k_VectorListAllLanes
&& !VectorList
.isDoubleSpaced
;
1944 bool isDoubleSpacedVectorAllLanes() const {
1945 return Kind
== k_VectorListAllLanes
&& VectorList
.isDoubleSpaced
;
1948 bool isVecListOneDAllLanes() const {
1949 if (!isSingleSpacedVectorAllLanes()) return false;
1950 return VectorList
.Count
== 1;
1953 bool isVecListDPairAllLanes() const {
1954 if (!isSingleSpacedVectorAllLanes()) return false;
1955 return (ARMMCRegisterClasses
[ARM::DPairRegClassID
]
1956 .contains(VectorList
.RegNum
));
1959 bool isVecListDPairSpacedAllLanes() const {
1960 if (!isDoubleSpacedVectorAllLanes()) return false;
1961 return VectorList
.Count
== 2;
1964 bool isVecListThreeDAllLanes() const {
1965 if (!isSingleSpacedVectorAllLanes()) return false;
1966 return VectorList
.Count
== 3;
1969 bool isVecListThreeQAllLanes() const {
1970 if (!isDoubleSpacedVectorAllLanes()) return false;
1971 return VectorList
.Count
== 3;
1974 bool isVecListFourDAllLanes() const {
1975 if (!isSingleSpacedVectorAllLanes()) return false;
1976 return VectorList
.Count
== 4;
1979 bool isVecListFourQAllLanes() const {
1980 if (!isDoubleSpacedVectorAllLanes()) return false;
1981 return VectorList
.Count
== 4;
1984 bool isSingleSpacedVectorIndexed() const {
1985 return Kind
== k_VectorListIndexed
&& !VectorList
.isDoubleSpaced
;
1988 bool isDoubleSpacedVectorIndexed() const {
1989 return Kind
== k_VectorListIndexed
&& VectorList
.isDoubleSpaced
;
1992 bool isVecListOneDByteIndexed() const {
1993 if (!isSingleSpacedVectorIndexed()) return false;
1994 return VectorList
.Count
== 1 && VectorList
.LaneIndex
<= 7;
1997 bool isVecListOneDHWordIndexed() const {
1998 if (!isSingleSpacedVectorIndexed()) return false;
1999 return VectorList
.Count
== 1 && VectorList
.LaneIndex
<= 3;
2002 bool isVecListOneDWordIndexed() const {
2003 if (!isSingleSpacedVectorIndexed()) return false;
2004 return VectorList
.Count
== 1 && VectorList
.LaneIndex
<= 1;
2007 bool isVecListTwoDByteIndexed() const {
2008 if (!isSingleSpacedVectorIndexed()) return false;
2009 return VectorList
.Count
== 2 && VectorList
.LaneIndex
<= 7;
2012 bool isVecListTwoDHWordIndexed() const {
2013 if (!isSingleSpacedVectorIndexed()) return false;
2014 return VectorList
.Count
== 2 && VectorList
.LaneIndex
<= 3;
2017 bool isVecListTwoQWordIndexed() const {
2018 if (!isDoubleSpacedVectorIndexed()) return false;
2019 return VectorList
.Count
== 2 && VectorList
.LaneIndex
<= 1;
2022 bool isVecListTwoQHWordIndexed() const {
2023 if (!isDoubleSpacedVectorIndexed()) return false;
2024 return VectorList
.Count
== 2 && VectorList
.LaneIndex
<= 3;
2027 bool isVecListTwoDWordIndexed() const {
2028 if (!isSingleSpacedVectorIndexed()) return false;
2029 return VectorList
.Count
== 2 && VectorList
.LaneIndex
<= 1;
2032 bool isVecListThreeDByteIndexed() const {
2033 if (!isSingleSpacedVectorIndexed()) return false;
2034 return VectorList
.Count
== 3 && VectorList
.LaneIndex
<= 7;
2037 bool isVecListThreeDHWordIndexed() const {
2038 if (!isSingleSpacedVectorIndexed()) return false;
2039 return VectorList
.Count
== 3 && VectorList
.LaneIndex
<= 3;
2042 bool isVecListThreeQWordIndexed() const {
2043 if (!isDoubleSpacedVectorIndexed()) return false;
2044 return VectorList
.Count
== 3 && VectorList
.LaneIndex
<= 1;
2047 bool isVecListThreeQHWordIndexed() const {
2048 if (!isDoubleSpacedVectorIndexed()) return false;
2049 return VectorList
.Count
== 3 && VectorList
.LaneIndex
<= 3;
2052 bool isVecListThreeDWordIndexed() const {
2053 if (!isSingleSpacedVectorIndexed()) return false;
2054 return VectorList
.Count
== 3 && VectorList
.LaneIndex
<= 1;
2057 bool isVecListFourDByteIndexed() const {
2058 if (!isSingleSpacedVectorIndexed()) return false;
2059 return VectorList
.Count
== 4 && VectorList
.LaneIndex
<= 7;
2062 bool isVecListFourDHWordIndexed() const {
2063 if (!isSingleSpacedVectorIndexed()) return false;
2064 return VectorList
.Count
== 4 && VectorList
.LaneIndex
<= 3;
2067 bool isVecListFourQWordIndexed() const {
2068 if (!isDoubleSpacedVectorIndexed()) return false;
2069 return VectorList
.Count
== 4 && VectorList
.LaneIndex
<= 1;
2072 bool isVecListFourQHWordIndexed() const {
2073 if (!isDoubleSpacedVectorIndexed()) return false;
2074 return VectorList
.Count
== 4 && VectorList
.LaneIndex
<= 3;
2077 bool isVecListFourDWordIndexed() const {
2078 if (!isSingleSpacedVectorIndexed()) return false;
2079 return VectorList
.Count
== 4 && VectorList
.LaneIndex
<= 1;
2082 bool isVectorIndex() const { return Kind
== k_VectorIndex
; }
2084 template <unsigned NumLanes
>
2085 bool isVectorIndexInRange() const {
2086 if (Kind
!= k_VectorIndex
) return false;
2087 return VectorIndex
.Val
< NumLanes
;
2090 bool isVectorIndex8() const { return isVectorIndexInRange
<8>(); }
2091 bool isVectorIndex16() const { return isVectorIndexInRange
<4>(); }
2092 bool isVectorIndex32() const { return isVectorIndexInRange
<2>(); }
2093 bool isVectorIndex64() const { return isVectorIndexInRange
<1>(); }
2095 template<int PermittedValue
, int OtherPermittedValue
>
2096 bool isMVEPairVectorIndex() const {
2097 if (Kind
!= k_VectorIndex
) return false;
2098 return VectorIndex
.Val
== PermittedValue
||
2099 VectorIndex
.Val
== OtherPermittedValue
;
2102 bool isNEONi8splat() const {
2103 if (!isImm()) return false;
2104 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2105 // Must be a constant.
2106 if (!CE
) return false;
2107 int64_t Value
= CE
->getValue();
2108 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
2110 return Value
>= 0 && Value
< 256;
2113 bool isNEONi16splat() const {
2114 if (isNEONByteReplicate(2))
2115 return false; // Leave that for bytes replication and forbid by default.
2118 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2119 // Must be a constant.
2120 if (!CE
) return false;
2121 unsigned Value
= CE
->getValue();
2122 return ARM_AM::isNEONi16splat(Value
);
2125 bool isNEONi16splatNot() const {
2128 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2129 // Must be a constant.
2130 if (!CE
) return false;
2131 unsigned Value
= CE
->getValue();
2132 return ARM_AM::isNEONi16splat(~Value
& 0xffff);
2135 bool isNEONi32splat() const {
2136 if (isNEONByteReplicate(4))
2137 return false; // Leave that for bytes replication and forbid by default.
2140 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2141 // Must be a constant.
2142 if (!CE
) return false;
2143 unsigned Value
= CE
->getValue();
2144 return ARM_AM::isNEONi32splat(Value
);
2147 bool isNEONi32splatNot() const {
2150 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2151 // Must be a constant.
2152 if (!CE
) return false;
2153 unsigned Value
= CE
->getValue();
2154 return ARM_AM::isNEONi32splat(~Value
);
2157 static bool isValidNEONi32vmovImm(int64_t Value
) {
2158 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
2159 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
2160 return ((Value
& 0xffffffffffffff00) == 0) ||
2161 ((Value
& 0xffffffffffff00ff) == 0) ||
2162 ((Value
& 0xffffffffff00ffff) == 0) ||
2163 ((Value
& 0xffffffff00ffffff) == 0) ||
2164 ((Value
& 0xffffffffffff00ff) == 0xff) ||
2165 ((Value
& 0xffffffffff00ffff) == 0xffff);
2168 bool isNEONReplicate(unsigned Width
, unsigned NumElems
, bool Inv
) const {
2169 assert((Width
== 8 || Width
== 16 || Width
== 32) &&
2170 "Invalid element width");
2171 assert(NumElems
* Width
<= 64 && "Invalid result width");
2175 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2176 // Must be a constant.
2179 int64_t Value
= CE
->getValue();
2181 return false; // Don't bother with zero.
2185 uint64_t Mask
= (1ull << Width
) - 1;
2186 uint64_t Elem
= Value
& Mask
;
2187 if (Width
== 16 && (Elem
& 0x00ff) != 0 && (Elem
& 0xff00) != 0)
2189 if (Width
== 32 && !isValidNEONi32vmovImm(Elem
))
2192 for (unsigned i
= 1; i
< NumElems
; ++i
) {
2194 if ((Value
& Mask
) != Elem
)
2200 bool isNEONByteReplicate(unsigned NumBytes
) const {
2201 return isNEONReplicate(8, NumBytes
, false);
2204 static void checkNeonReplicateArgs(unsigned FromW
, unsigned ToW
) {
2205 assert((FromW
== 8 || FromW
== 16 || FromW
== 32) &&
2206 "Invalid source width");
2207 assert((ToW
== 16 || ToW
== 32 || ToW
== 64) &&
2208 "Invalid destination width");
2209 assert(FromW
< ToW
&& "ToW is not less than FromW");
2212 template<unsigned FromW
, unsigned ToW
>
2213 bool isNEONmovReplicate() const {
2214 checkNeonReplicateArgs(FromW
, ToW
);
2215 if (ToW
== 64 && isNEONi64splat())
2217 return isNEONReplicate(FromW
, ToW
/ FromW
, false);
2220 template<unsigned FromW
, unsigned ToW
>
2221 bool isNEONinvReplicate() const {
2222 checkNeonReplicateArgs(FromW
, ToW
);
2223 return isNEONReplicate(FromW
, ToW
/ FromW
, true);
2226 bool isNEONi32vmov() const {
2227 if (isNEONByteReplicate(4))
2228 return false; // Let it to be classified as byte-replicate case.
2231 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2232 // Must be a constant.
2235 return isValidNEONi32vmovImm(CE
->getValue());
2238 bool isNEONi32vmovNeg() const {
2239 if (!isImm()) return false;
2240 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2241 // Must be a constant.
2242 if (!CE
) return false;
2243 return isValidNEONi32vmovImm(~CE
->getValue());
2246 bool isNEONi64splat() const {
2247 if (!isImm()) return false;
2248 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2249 // Must be a constant.
2250 if (!CE
) return false;
2251 uint64_t Value
= CE
->getValue();
2252 // i64 value with each byte being either 0 or 0xff.
2253 for (unsigned i
= 0; i
< 8; ++i
, Value
>>= 8)
2254 if ((Value
& 0xff) != 0 && (Value
& 0xff) != 0xff) return false;
2258 template<int64_t Angle
, int64_t Remainder
>
2259 bool isComplexRotation() const {
2260 if (!isImm()) return false;
2262 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2263 if (!CE
) return false;
2264 uint64_t Value
= CE
->getValue();
2266 return (Value
% Angle
== Remainder
&& Value
<= 270);
2269 bool isMVELongShift() const {
2270 if (!isImm()) return false;
2271 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2272 // Must be a constant.
2273 if (!CE
) return false;
2274 uint64_t Value
= CE
->getValue();
2275 return Value
>= 1 && Value
<= 32;
2278 bool isMveSaturateOp() const {
2279 if (!isImm()) return false;
2280 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2281 if (!CE
) return false;
2282 uint64_t Value
= CE
->getValue();
2283 return Value
== 48 || Value
== 64;
2286 bool isITCondCodeNoAL() const {
2287 if (!isITCondCode()) return false;
2288 ARMCC::CondCodes CC
= getCondCode();
2289 return CC
!= ARMCC::AL
;
2292 bool isITCondCodeRestrictedI() const {
2293 if (!isITCondCode())
2295 ARMCC::CondCodes CC
= getCondCode();
2296 return CC
== ARMCC::EQ
|| CC
== ARMCC::NE
;
2299 bool isITCondCodeRestrictedS() const {
2300 if (!isITCondCode())
2302 ARMCC::CondCodes CC
= getCondCode();
2303 return CC
== ARMCC::LT
|| CC
== ARMCC::GT
|| CC
== ARMCC::LE
||
2307 bool isITCondCodeRestrictedU() const {
2308 if (!isITCondCode())
2310 ARMCC::CondCodes CC
= getCondCode();
2311 return CC
== ARMCC::HS
|| CC
== ARMCC::HI
;
2314 bool isITCondCodeRestrictedFP() const {
2315 if (!isITCondCode())
2317 ARMCC::CondCodes CC
= getCondCode();
2318 return CC
== ARMCC::EQ
|| CC
== ARMCC::NE
|| CC
== ARMCC::LT
||
2319 CC
== ARMCC::GT
|| CC
== ARMCC::LE
|| CC
== ARMCC::GE
;
2322 void addExpr(MCInst
&Inst
, const MCExpr
*Expr
) const {
2323 // Add as immediates when possible. Null MCExpr = 0.
2325 Inst
.addOperand(MCOperand::createImm(0));
2326 else if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Expr
))
2327 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2329 Inst
.addOperand(MCOperand::createExpr(Expr
));
2332 void addARMBranchTargetOperands(MCInst
&Inst
, unsigned N
) const {
2333 assert(N
== 1 && "Invalid number of operands!");
2334 addExpr(Inst
, getImm());
2337 void addThumbBranchTargetOperands(MCInst
&Inst
, unsigned N
) const {
2338 assert(N
== 1 && "Invalid number of operands!");
2339 addExpr(Inst
, getImm());
2342 void addCondCodeOperands(MCInst
&Inst
, unsigned N
) const {
2343 assert(N
== 2 && "Invalid number of operands!");
2344 Inst
.addOperand(MCOperand::createImm(unsigned(getCondCode())));
2345 unsigned RegNum
= getCondCode() == ARMCC::AL
? 0: ARM::CPSR
;
2346 Inst
.addOperand(MCOperand::createReg(RegNum
));
2349 void addVPTPredNOperands(MCInst
&Inst
, unsigned N
) const {
2350 assert(N
== 2 && "Invalid number of operands!");
2351 Inst
.addOperand(MCOperand::createImm(unsigned(getVPTPred())));
2352 unsigned RegNum
= getVPTPred() == ARMVCC::None
? 0: ARM::P0
;
2353 Inst
.addOperand(MCOperand::createReg(RegNum
));
2356 void addVPTPredROperands(MCInst
&Inst
, unsigned N
) const {
2357 assert(N
== 3 && "Invalid number of operands!");
2358 addVPTPredNOperands(Inst
, N
-1);
2360 if (getVPTPred() == ARMVCC::None
) {
2363 unsigned NextOpIndex
= Inst
.getNumOperands();
2364 const MCInstrDesc
&MCID
= ARMInsts
[Inst
.getOpcode()];
2365 int TiedOp
= MCID
.getOperandConstraint(NextOpIndex
, MCOI::TIED_TO
);
2366 assert(TiedOp
>= 0 &&
2367 "Inactive register in vpred_r is not tied to an output!");
2368 RegNum
= Inst
.getOperand(TiedOp
).getReg();
2370 Inst
.addOperand(MCOperand::createReg(RegNum
));
2373 void addCoprocNumOperands(MCInst
&Inst
, unsigned N
) const {
2374 assert(N
== 1 && "Invalid number of operands!");
2375 Inst
.addOperand(MCOperand::createImm(getCoproc()));
2378 void addCoprocRegOperands(MCInst
&Inst
, unsigned N
) const {
2379 assert(N
== 1 && "Invalid number of operands!");
2380 Inst
.addOperand(MCOperand::createImm(getCoproc()));
2383 void addCoprocOptionOperands(MCInst
&Inst
, unsigned N
) const {
2384 assert(N
== 1 && "Invalid number of operands!");
2385 Inst
.addOperand(MCOperand::createImm(CoprocOption
.Val
));
2388 void addITMaskOperands(MCInst
&Inst
, unsigned N
) const {
2389 assert(N
== 1 && "Invalid number of operands!");
2390 Inst
.addOperand(MCOperand::createImm(ITMask
.Mask
));
2393 void addITCondCodeOperands(MCInst
&Inst
, unsigned N
) const {
2394 assert(N
== 1 && "Invalid number of operands!");
2395 Inst
.addOperand(MCOperand::createImm(unsigned(getCondCode())));
2398 void addITCondCodeInvOperands(MCInst
&Inst
, unsigned N
) const {
2399 assert(N
== 1 && "Invalid number of operands!");
2400 Inst
.addOperand(MCOperand::createImm(unsigned(ARMCC::getOppositeCondition(getCondCode()))));
2403 void addCCOutOperands(MCInst
&Inst
, unsigned N
) const {
2404 assert(N
== 1 && "Invalid number of operands!");
2405 Inst
.addOperand(MCOperand::createReg(getReg()));
2408 void addRegOperands(MCInst
&Inst
, unsigned N
) const {
2409 assert(N
== 1 && "Invalid number of operands!");
2410 Inst
.addOperand(MCOperand::createReg(getReg()));
2413 void addRegShiftedRegOperands(MCInst
&Inst
, unsigned N
) const {
2414 assert(N
== 3 && "Invalid number of operands!");
2415 assert(isRegShiftedReg() &&
2416 "addRegShiftedRegOperands() on non-RegShiftedReg!");
2417 Inst
.addOperand(MCOperand::createReg(RegShiftedReg
.SrcReg
));
2418 Inst
.addOperand(MCOperand::createReg(RegShiftedReg
.ShiftReg
));
2419 Inst
.addOperand(MCOperand::createImm(
2420 ARM_AM::getSORegOpc(RegShiftedReg
.ShiftTy
, RegShiftedReg
.ShiftImm
)));
2423 void addRegShiftedImmOperands(MCInst
&Inst
, unsigned N
) const {
2424 assert(N
== 2 && "Invalid number of operands!");
2425 assert(isRegShiftedImm() &&
2426 "addRegShiftedImmOperands() on non-RegShiftedImm!");
2427 Inst
.addOperand(MCOperand::createReg(RegShiftedImm
.SrcReg
));
2428 // Shift of #32 is encoded as 0 where permitted
2429 unsigned Imm
= (RegShiftedImm
.ShiftImm
== 32 ? 0 : RegShiftedImm
.ShiftImm
);
2430 Inst
.addOperand(MCOperand::createImm(
2431 ARM_AM::getSORegOpc(RegShiftedImm
.ShiftTy
, Imm
)));
2434 void addShifterImmOperands(MCInst
&Inst
, unsigned N
) const {
2435 assert(N
== 1 && "Invalid number of operands!");
2436 Inst
.addOperand(MCOperand::createImm((ShifterImm
.isASR
<< 5) |
2440 void addRegListOperands(MCInst
&Inst
, unsigned N
) const {
2441 assert(N
== 1 && "Invalid number of operands!");
2442 const SmallVectorImpl
<unsigned> &RegList
= getRegList();
2443 for (SmallVectorImpl
<unsigned>::const_iterator
2444 I
= RegList
.begin(), E
= RegList
.end(); I
!= E
; ++I
)
2445 Inst
.addOperand(MCOperand::createReg(*I
));
2448 void addRegListWithAPSROperands(MCInst
&Inst
, unsigned N
) const {
2449 assert(N
== 1 && "Invalid number of operands!");
2450 const SmallVectorImpl
<unsigned> &RegList
= getRegList();
2451 for (SmallVectorImpl
<unsigned>::const_iterator
2452 I
= RegList
.begin(), E
= RegList
.end(); I
!= E
; ++I
)
2453 Inst
.addOperand(MCOperand::createReg(*I
));
2456 void addDPRRegListOperands(MCInst
&Inst
, unsigned N
) const {
2457 addRegListOperands(Inst
, N
);
2460 void addSPRRegListOperands(MCInst
&Inst
, unsigned N
) const {
2461 addRegListOperands(Inst
, N
);
2464 void addFPSRegListWithVPROperands(MCInst
&Inst
, unsigned N
) const {
2465 addRegListOperands(Inst
, N
);
2468 void addFPDRegListWithVPROperands(MCInst
&Inst
, unsigned N
) const {
2469 addRegListOperands(Inst
, N
);
2472 void addRotImmOperands(MCInst
&Inst
, unsigned N
) const {
2473 assert(N
== 1 && "Invalid number of operands!");
2474 // Encoded as val>>3. The printer handles display as 8, 16, 24.
2475 Inst
.addOperand(MCOperand::createImm(RotImm
.Imm
>> 3));
2478 void addModImmOperands(MCInst
&Inst
, unsigned N
) const {
2479 assert(N
== 1 && "Invalid number of operands!");
2481 // Support for fixups (MCFixup)
2483 return addImmOperands(Inst
, N
);
2485 Inst
.addOperand(MCOperand::createImm(ModImm
.Bits
| (ModImm
.Rot
<< 7)));
2488 void addModImmNotOperands(MCInst
&Inst
, unsigned N
) const {
2489 assert(N
== 1 && "Invalid number of operands!");
2490 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2491 uint32_t Enc
= ARM_AM::getSOImmVal(~CE
->getValue());
2492 Inst
.addOperand(MCOperand::createImm(Enc
));
2495 void addModImmNegOperands(MCInst
&Inst
, unsigned N
) const {
2496 assert(N
== 1 && "Invalid number of operands!");
2497 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2498 uint32_t Enc
= ARM_AM::getSOImmVal(-CE
->getValue());
2499 Inst
.addOperand(MCOperand::createImm(Enc
));
2502 void addThumbModImmNeg8_255Operands(MCInst
&Inst
, unsigned N
) const {
2503 assert(N
== 1 && "Invalid number of operands!");
2504 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2505 uint32_t Val
= -CE
->getValue();
2506 Inst
.addOperand(MCOperand::createImm(Val
));
2509 void addThumbModImmNeg1_7Operands(MCInst
&Inst
, unsigned N
) const {
2510 assert(N
== 1 && "Invalid number of operands!");
2511 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2512 uint32_t Val
= -CE
->getValue();
2513 Inst
.addOperand(MCOperand::createImm(Val
));
2516 void addBitfieldOperands(MCInst
&Inst
, unsigned N
) const {
2517 assert(N
== 1 && "Invalid number of operands!");
2518 // Munge the lsb/width into a bitfield mask.
2519 unsigned lsb
= Bitfield
.LSB
;
2520 unsigned width
= Bitfield
.Width
;
2521 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
2522 uint32_t Mask
= ~(((uint32_t)0xffffffff >> lsb
) << (32 - width
) >>
2523 (32 - (lsb
+ width
)));
2524 Inst
.addOperand(MCOperand::createImm(Mask
));
2527 void addImmOperands(MCInst
&Inst
, unsigned N
) const {
2528 assert(N
== 1 && "Invalid number of operands!");
2529 addExpr(Inst
, getImm());
2532 void addFBits16Operands(MCInst
&Inst
, unsigned N
) const {
2533 assert(N
== 1 && "Invalid number of operands!");
2534 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2535 Inst
.addOperand(MCOperand::createImm(16 - CE
->getValue()));
2538 void addFBits32Operands(MCInst
&Inst
, unsigned N
) const {
2539 assert(N
== 1 && "Invalid number of operands!");
2540 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2541 Inst
.addOperand(MCOperand::createImm(32 - CE
->getValue()));
2544 void addFPImmOperands(MCInst
&Inst
, unsigned N
) const {
2545 assert(N
== 1 && "Invalid number of operands!");
2546 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2547 int Val
= ARM_AM::getFP32Imm(APInt(32, CE
->getValue()));
2548 Inst
.addOperand(MCOperand::createImm(Val
));
2551 void addImm8s4Operands(MCInst
&Inst
, unsigned N
) const {
2552 assert(N
== 1 && "Invalid number of operands!");
2553 // FIXME: We really want to scale the value here, but the LDRD/STRD
2554 // instruction don't encode operands that way yet.
2555 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2556 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2559 void addImm7s4Operands(MCInst
&Inst
, unsigned N
) const {
2560 assert(N
== 1 && "Invalid number of operands!");
2561 // FIXME: We really want to scale the value here, but the VSTR/VLDR_VSYSR
2562 // instruction don't encode operands that way yet.
2563 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2564 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2567 void addImm7Shift0Operands(MCInst
&Inst
, unsigned N
) const {
2568 assert(N
== 1 && "Invalid number of operands!");
2569 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2570 assert(CE
!= nullptr && "Invalid operand type!");
2571 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2574 void addImm7Shift1Operands(MCInst
&Inst
, unsigned N
) const {
2575 assert(N
== 1 && "Invalid number of operands!");
2576 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2577 assert(CE
!= nullptr && "Invalid operand type!");
2578 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2581 void addImm7Shift2Operands(MCInst
&Inst
, unsigned N
) const {
2582 assert(N
== 1 && "Invalid number of operands!");
2583 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2584 assert(CE
!= nullptr && "Invalid operand type!");
2585 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2588 void addImm7Operands(MCInst
&Inst
, unsigned N
) const {
2589 assert(N
== 1 && "Invalid number of operands!");
2590 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2591 assert(CE
!= nullptr && "Invalid operand type!");
2592 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2595 void addImm0_1020s4Operands(MCInst
&Inst
, unsigned N
) const {
2596 assert(N
== 1 && "Invalid number of operands!");
2597 // The immediate is scaled by four in the encoding and is stored
2598 // in the MCInst as such. Lop off the low two bits here.
2599 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2600 Inst
.addOperand(MCOperand::createImm(CE
->getValue() / 4));
2603 void addImm0_508s4NegOperands(MCInst
&Inst
, unsigned N
) const {
2604 assert(N
== 1 && "Invalid number of operands!");
2605 // The immediate is scaled by four in the encoding and is stored
2606 // in the MCInst as such. Lop off the low two bits here.
2607 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2608 Inst
.addOperand(MCOperand::createImm(-(CE
->getValue() / 4)));
2611 void addImm0_508s4Operands(MCInst
&Inst
, unsigned N
) const {
2612 assert(N
== 1 && "Invalid number of operands!");
2613 // The immediate is scaled by four in the encoding and is stored
2614 // in the MCInst as such. Lop off the low two bits here.
2615 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2616 Inst
.addOperand(MCOperand::createImm(CE
->getValue() / 4));
2619 void addImm1_16Operands(MCInst
&Inst
, unsigned N
) const {
2620 assert(N
== 1 && "Invalid number of operands!");
2621 // The constant encodes as the immediate-1, and we store in the instruction
2622 // the bits as encoded, so subtract off one here.
2623 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2624 Inst
.addOperand(MCOperand::createImm(CE
->getValue() - 1));
2627 void addImm1_32Operands(MCInst
&Inst
, unsigned N
) const {
2628 assert(N
== 1 && "Invalid number of operands!");
2629 // The constant encodes as the immediate-1, and we store in the instruction
2630 // the bits as encoded, so subtract off one here.
2631 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2632 Inst
.addOperand(MCOperand::createImm(CE
->getValue() - 1));
2635 void addImmThumbSROperands(MCInst
&Inst
, unsigned N
) const {
2636 assert(N
== 1 && "Invalid number of operands!");
2637 // The constant encodes as the immediate, except for 32, which encodes as
2639 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2640 unsigned Imm
= CE
->getValue();
2641 Inst
.addOperand(MCOperand::createImm((Imm
== 32 ? 0 : Imm
)));
2644 void addPKHASRImmOperands(MCInst
&Inst
, unsigned N
) const {
2645 assert(N
== 1 && "Invalid number of operands!");
2646 // An ASR value of 32 encodes as 0, so that's how we want to add it to
2647 // the instruction as well.
2648 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2649 int Val
= CE
->getValue();
2650 Inst
.addOperand(MCOperand::createImm(Val
== 32 ? 0 : Val
));
2653 void addT2SOImmNotOperands(MCInst
&Inst
, unsigned N
) const {
2654 assert(N
== 1 && "Invalid number of operands!");
2655 // The operand is actually a t2_so_imm, but we have its bitwise
2656 // negation in the assembly source, so twiddle it here.
2657 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2658 Inst
.addOperand(MCOperand::createImm(~(uint32_t)CE
->getValue()));
2661 void addT2SOImmNegOperands(MCInst
&Inst
, unsigned N
) const {
2662 assert(N
== 1 && "Invalid number of operands!");
2663 // The operand is actually a t2_so_imm, but we have its
2664 // negation in the assembly source, so twiddle it here.
2665 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2666 Inst
.addOperand(MCOperand::createImm(-(uint32_t)CE
->getValue()));
2669 void addImm0_4095NegOperands(MCInst
&Inst
, unsigned N
) const {
2670 assert(N
== 1 && "Invalid number of operands!");
2671 // The operand is actually an imm0_4095, but we have its
2672 // negation in the assembly source, so twiddle it here.
2673 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2674 Inst
.addOperand(MCOperand::createImm(-(uint32_t)CE
->getValue()));
2677 void addUnsignedOffset_b8s2Operands(MCInst
&Inst
, unsigned N
) const {
2678 if(const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm())) {
2679 Inst
.addOperand(MCOperand::createImm(CE
->getValue() >> 2));
2683 const MCSymbolRefExpr
*SR
= dyn_cast
<MCSymbolRefExpr
>(Imm
.Val
);
2684 assert(SR
&& "Unknown value type!");
2685 Inst
.addOperand(MCOperand::createExpr(SR
));
2688 void addThumbMemPCOperands(MCInst
&Inst
, unsigned N
) const {
2689 assert(N
== 1 && "Invalid number of operands!");
2691 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2693 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
2697 const MCSymbolRefExpr
*SR
= dyn_cast
<MCSymbolRefExpr
>(Imm
.Val
);
2699 assert(SR
&& "Unknown value type!");
2700 Inst
.addOperand(MCOperand::createExpr(SR
));
2704 assert(isGPRMem() && "Unknown value type!");
2705 assert(isa
<MCConstantExpr
>(Memory
.OffsetImm
) && "Unknown value type!");
2706 Inst
.addOperand(MCOperand::createImm(Memory
.OffsetImm
->getValue()));
2709 void addMemBarrierOptOperands(MCInst
&Inst
, unsigned N
) const {
2710 assert(N
== 1 && "Invalid number of operands!");
2711 Inst
.addOperand(MCOperand::createImm(unsigned(getMemBarrierOpt())));
2714 void addInstSyncBarrierOptOperands(MCInst
&Inst
, unsigned N
) const {
2715 assert(N
== 1 && "Invalid number of operands!");
2716 Inst
.addOperand(MCOperand::createImm(unsigned(getInstSyncBarrierOpt())));
2719 void addTraceSyncBarrierOptOperands(MCInst
&Inst
, unsigned N
) const {
2720 assert(N
== 1 && "Invalid number of operands!");
2721 Inst
.addOperand(MCOperand::createImm(unsigned(getTraceSyncBarrierOpt())));
2724 void addMemNoOffsetOperands(MCInst
&Inst
, unsigned N
) const {
2725 assert(N
== 1 && "Invalid number of operands!");
2726 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2729 void addMemNoOffsetT2Operands(MCInst
&Inst
, unsigned N
) const {
2730 assert(N
== 1 && "Invalid number of operands!");
2731 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2734 void addMemNoOffsetT2NoSpOperands(MCInst
&Inst
, unsigned N
) const {
2735 assert(N
== 1 && "Invalid number of operands!");
2736 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2739 void addMemNoOffsetTOperands(MCInst
&Inst
, unsigned N
) const {
2740 assert(N
== 1 && "Invalid number of operands!");
2741 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2744 void addMemPCRelImm12Operands(MCInst
&Inst
, unsigned N
) const {
2745 assert(N
== 1 && "Invalid number of operands!");
2746 int32_t Imm
= Memory
.OffsetImm
->getValue();
2747 Inst
.addOperand(MCOperand::createImm(Imm
));
2750 void addAdrLabelOperands(MCInst
&Inst
, unsigned N
) const {
2751 assert(N
== 1 && "Invalid number of operands!");
2752 assert(isImm() && "Not an immediate!");
2754 // If we have an immediate that's not a constant, treat it as a label
2755 // reference needing a fixup.
2756 if (!isa
<MCConstantExpr
>(getImm())) {
2757 Inst
.addOperand(MCOperand::createExpr(getImm()));
2761 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2762 int Val
= CE
->getValue();
2763 Inst
.addOperand(MCOperand::createImm(Val
));
2766 void addAlignedMemoryOperands(MCInst
&Inst
, unsigned N
) const {
2767 assert(N
== 2 && "Invalid number of operands!");
2768 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2769 Inst
.addOperand(MCOperand::createImm(Memory
.Alignment
));
2772 void addDupAlignedMemoryNoneOperands(MCInst
&Inst
, unsigned N
) const {
2773 addAlignedMemoryOperands(Inst
, N
);
2776 void addAlignedMemoryNoneOperands(MCInst
&Inst
, unsigned N
) const {
2777 addAlignedMemoryOperands(Inst
, N
);
2780 void addAlignedMemory16Operands(MCInst
&Inst
, unsigned N
) const {
2781 addAlignedMemoryOperands(Inst
, N
);
2784 void addDupAlignedMemory16Operands(MCInst
&Inst
, unsigned N
) const {
2785 addAlignedMemoryOperands(Inst
, N
);
2788 void addAlignedMemory32Operands(MCInst
&Inst
, unsigned N
) const {
2789 addAlignedMemoryOperands(Inst
, N
);
2792 void addDupAlignedMemory32Operands(MCInst
&Inst
, unsigned N
) const {
2793 addAlignedMemoryOperands(Inst
, N
);
2796 void addAlignedMemory64Operands(MCInst
&Inst
, unsigned N
) const {
2797 addAlignedMemoryOperands(Inst
, N
);
2800 void addDupAlignedMemory64Operands(MCInst
&Inst
, unsigned N
) const {
2801 addAlignedMemoryOperands(Inst
, N
);
2804 void addAlignedMemory64or128Operands(MCInst
&Inst
, unsigned N
) const {
2805 addAlignedMemoryOperands(Inst
, N
);
2808 void addDupAlignedMemory64or128Operands(MCInst
&Inst
, unsigned N
) const {
2809 addAlignedMemoryOperands(Inst
, N
);
2812 void addAlignedMemory64or128or256Operands(MCInst
&Inst
, unsigned N
) const {
2813 addAlignedMemoryOperands(Inst
, N
);
2816 void addAddrMode2Operands(MCInst
&Inst
, unsigned N
) const {
2817 assert(N
== 3 && "Invalid number of operands!");
2818 int32_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() : 0;
2819 if (!Memory
.OffsetRegNum
) {
2820 ARM_AM::AddrOpc AddSub
= Val
< 0 ? ARM_AM::sub
: ARM_AM::add
;
2821 // Special case for #-0
2822 if (Val
== std::numeric_limits
<int32_t>::min()) Val
= 0;
2823 if (Val
< 0) Val
= -Val
;
2824 Val
= ARM_AM::getAM2Opc(AddSub
, Val
, ARM_AM::no_shift
);
2826 // For register offset, we encode the shift type and negation flag
2828 Val
= ARM_AM::getAM2Opc(Memory
.isNegative
? ARM_AM::sub
: ARM_AM::add
,
2829 Memory
.ShiftImm
, Memory
.ShiftType
);
2831 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2832 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
2833 Inst
.addOperand(MCOperand::createImm(Val
));
2836 void addAM2OffsetImmOperands(MCInst
&Inst
, unsigned N
) const {
2837 assert(N
== 2 && "Invalid number of operands!");
2838 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
2839 assert(CE
&& "non-constant AM2OffsetImm operand!");
2840 int32_t Val
= CE
->getValue();
2841 ARM_AM::AddrOpc AddSub
= Val
< 0 ? ARM_AM::sub
: ARM_AM::add
;
2842 // Special case for #-0
2843 if (Val
== std::numeric_limits
<int32_t>::min()) Val
= 0;
2844 if (Val
< 0) Val
= -Val
;
2845 Val
= ARM_AM::getAM2Opc(AddSub
, Val
, ARM_AM::no_shift
);
2846 Inst
.addOperand(MCOperand::createReg(0));
2847 Inst
.addOperand(MCOperand::createImm(Val
));
2850 void addAddrMode3Operands(MCInst
&Inst
, unsigned N
) const {
2851 assert(N
== 3 && "Invalid number of operands!");
2852 // If we have an immediate that's not a constant, treat it as a label
2853 // reference needing a fixup. If it is a constant, it's something else
2854 // and we reject it.
2856 Inst
.addOperand(MCOperand::createExpr(getImm()));
2857 Inst
.addOperand(MCOperand::createReg(0));
2858 Inst
.addOperand(MCOperand::createImm(0));
2862 int32_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() : 0;
2863 if (!Memory
.OffsetRegNum
) {
2864 ARM_AM::AddrOpc AddSub
= Val
< 0 ? ARM_AM::sub
: ARM_AM::add
;
2865 // Special case for #-0
2866 if (Val
== std::numeric_limits
<int32_t>::min()) Val
= 0;
2867 if (Val
< 0) Val
= -Val
;
2868 Val
= ARM_AM::getAM3Opc(AddSub
, Val
);
2870 // For register offset, we encode the shift type and negation flag
2872 Val
= ARM_AM::getAM3Opc(Memory
.isNegative
? ARM_AM::sub
: ARM_AM::add
, 0);
2874 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2875 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
2876 Inst
.addOperand(MCOperand::createImm(Val
));
2879 void addAM3OffsetOperands(MCInst
&Inst
, unsigned N
) const {
2880 assert(N
== 2 && "Invalid number of operands!");
2881 if (Kind
== k_PostIndexRegister
) {
2883 ARM_AM::getAM3Opc(PostIdxReg
.isAdd
? ARM_AM::add
: ARM_AM::sub
, 0);
2884 Inst
.addOperand(MCOperand::createReg(PostIdxReg
.RegNum
));
2885 Inst
.addOperand(MCOperand::createImm(Val
));
2890 const MCConstantExpr
*CE
= static_cast<const MCConstantExpr
*>(getImm());
2891 int32_t Val
= CE
->getValue();
2892 ARM_AM::AddrOpc AddSub
= Val
< 0 ? ARM_AM::sub
: ARM_AM::add
;
2893 // Special case for #-0
2894 if (Val
== std::numeric_limits
<int32_t>::min()) Val
= 0;
2895 if (Val
< 0) Val
= -Val
;
2896 Val
= ARM_AM::getAM3Opc(AddSub
, Val
);
2897 Inst
.addOperand(MCOperand::createReg(0));
2898 Inst
.addOperand(MCOperand::createImm(Val
));
2901 void addAddrMode5Operands(MCInst
&Inst
, unsigned N
) const {
2902 assert(N
== 2 && "Invalid number of operands!");
2903 // If we have an immediate that's not a constant, treat it as a label
2904 // reference needing a fixup. If it is a constant, it's something else
2905 // and we reject it.
2907 Inst
.addOperand(MCOperand::createExpr(getImm()));
2908 Inst
.addOperand(MCOperand::createImm(0));
2912 // The lower two bits are always zero and as such are not encoded.
2913 int32_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() / 4 : 0;
2914 ARM_AM::AddrOpc AddSub
= Val
< 0 ? ARM_AM::sub
: ARM_AM::add
;
2915 // Special case for #-0
2916 if (Val
== std::numeric_limits
<int32_t>::min()) Val
= 0;
2917 if (Val
< 0) Val
= -Val
;
2918 Val
= ARM_AM::getAM5Opc(AddSub
, Val
);
2919 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2920 Inst
.addOperand(MCOperand::createImm(Val
));
2923 void addAddrMode5FP16Operands(MCInst
&Inst
, unsigned N
) const {
2924 assert(N
== 2 && "Invalid number of operands!");
2925 // If we have an immediate that's not a constant, treat it as a label
2926 // reference needing a fixup. If it is a constant, it's something else
2927 // and we reject it.
2929 Inst
.addOperand(MCOperand::createExpr(getImm()));
2930 Inst
.addOperand(MCOperand::createImm(0));
2934 // The lower bit is always zero and as such is not encoded.
2935 int32_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() / 2 : 0;
2936 ARM_AM::AddrOpc AddSub
= Val
< 0 ? ARM_AM::sub
: ARM_AM::add
;
2937 // Special case for #-0
2938 if (Val
== std::numeric_limits
<int32_t>::min()) Val
= 0;
2939 if (Val
< 0) Val
= -Val
;
2940 Val
= ARM_AM::getAM5FP16Opc(AddSub
, Val
);
2941 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2942 Inst
.addOperand(MCOperand::createImm(Val
));
2945 void addMemImm8s4OffsetOperands(MCInst
&Inst
, unsigned N
) const {
2946 assert(N
== 2 && "Invalid number of operands!");
2947 // If we have an immediate that's not a constant, treat it as a label
2948 // reference needing a fixup. If it is a constant, it's something else
2949 // and we reject it.
2951 Inst
.addOperand(MCOperand::createExpr(getImm()));
2952 Inst
.addOperand(MCOperand::createImm(0));
2956 int64_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() : 0;
2957 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2958 Inst
.addOperand(MCOperand::createImm(Val
));
2961 void addMemImm7s4OffsetOperands(MCInst
&Inst
, unsigned N
) const {
2962 assert(N
== 2 && "Invalid number of operands!");
2963 // If we have an immediate that's not a constant, treat it as a label
2964 // reference needing a fixup. If it is a constant, it's something else
2965 // and we reject it.
2967 Inst
.addOperand(MCOperand::createExpr(getImm()));
2968 Inst
.addOperand(MCOperand::createImm(0));
2972 int64_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() : 0;
2973 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2974 Inst
.addOperand(MCOperand::createImm(Val
));
2977 void addMemImm0_1020s4OffsetOperands(MCInst
&Inst
, unsigned N
) const {
2978 assert(N
== 2 && "Invalid number of operands!");
2979 // The lower two bits are always zero and as such are not encoded.
2980 int32_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() / 4 : 0;
2981 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2982 Inst
.addOperand(MCOperand::createImm(Val
));
2985 void addMemImmOffsetOperands(MCInst
&Inst
, unsigned N
) const {
2986 assert(N
== 2 && "Invalid number of operands!");
2987 int64_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() : 0;
2988 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2989 Inst
.addOperand(MCOperand::createImm(Val
));
2992 void addMemRegRQOffsetOperands(MCInst
&Inst
, unsigned N
) const {
2993 assert(N
== 2 && "Invalid number of operands!");
2994 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
2995 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
2998 void addMemUImm12OffsetOperands(MCInst
&Inst
, unsigned N
) const {
2999 assert(N
== 2 && "Invalid number of operands!");
3000 // If this is an immediate, it's a label reference.
3002 addExpr(Inst
, getImm());
3003 Inst
.addOperand(MCOperand::createImm(0));
3007 // Otherwise, it's a normal memory reg+offset.
3008 int64_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() : 0;
3009 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3010 Inst
.addOperand(MCOperand::createImm(Val
));
3013 void addMemImm12OffsetOperands(MCInst
&Inst
, unsigned N
) const {
3014 assert(N
== 2 && "Invalid number of operands!");
3015 // If this is an immediate, it's a label reference.
3017 addExpr(Inst
, getImm());
3018 Inst
.addOperand(MCOperand::createImm(0));
3022 // Otherwise, it's a normal memory reg+offset.
3023 int64_t Val
= Memory
.OffsetImm
? Memory
.OffsetImm
->getValue() : 0;
3024 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3025 Inst
.addOperand(MCOperand::createImm(Val
));
3028 void addConstPoolAsmImmOperands(MCInst
&Inst
, unsigned N
) const {
3029 assert(N
== 1 && "Invalid number of operands!");
3030 // This is container for the immediate that we will create the constant
3032 addExpr(Inst
, getConstantPoolImm());
3036 void addMemTBBOperands(MCInst
&Inst
, unsigned N
) const {
3037 assert(N
== 2 && "Invalid number of operands!");
3038 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3039 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
3042 void addMemTBHOperands(MCInst
&Inst
, unsigned N
) const {
3043 assert(N
== 2 && "Invalid number of operands!");
3044 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3045 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
3048 void addMemRegOffsetOperands(MCInst
&Inst
, unsigned N
) const {
3049 assert(N
== 3 && "Invalid number of operands!");
3051 ARM_AM::getAM2Opc(Memory
.isNegative
? ARM_AM::sub
: ARM_AM::add
,
3052 Memory
.ShiftImm
, Memory
.ShiftType
);
3053 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3054 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
3055 Inst
.addOperand(MCOperand::createImm(Val
));
3058 void addT2MemRegOffsetOperands(MCInst
&Inst
, unsigned N
) const {
3059 assert(N
== 3 && "Invalid number of operands!");
3060 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3061 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
3062 Inst
.addOperand(MCOperand::createImm(Memory
.ShiftImm
));
3065 void addMemThumbRROperands(MCInst
&Inst
, unsigned N
) const {
3066 assert(N
== 2 && "Invalid number of operands!");
3067 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3068 Inst
.addOperand(MCOperand::createReg(Memory
.OffsetRegNum
));
3071 void addMemThumbRIs4Operands(MCInst
&Inst
, unsigned N
) const {
3072 assert(N
== 2 && "Invalid number of operands!");
3073 int64_t Val
= Memory
.OffsetImm
? (Memory
.OffsetImm
->getValue() / 4) : 0;
3074 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3075 Inst
.addOperand(MCOperand::createImm(Val
));
3078 void addMemThumbRIs2Operands(MCInst
&Inst
, unsigned N
) const {
3079 assert(N
== 2 && "Invalid number of operands!");
3080 int64_t Val
= Memory
.OffsetImm
? (Memory
.OffsetImm
->getValue() / 2) : 0;
3081 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3082 Inst
.addOperand(MCOperand::createImm(Val
));
3085 void addMemThumbRIs1Operands(MCInst
&Inst
, unsigned N
) const {
3086 assert(N
== 2 && "Invalid number of operands!");
3087 int64_t Val
= Memory
.OffsetImm
? (Memory
.OffsetImm
->getValue()) : 0;
3088 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3089 Inst
.addOperand(MCOperand::createImm(Val
));
3092 void addMemThumbSPIOperands(MCInst
&Inst
, unsigned N
) const {
3093 assert(N
== 2 && "Invalid number of operands!");
3094 int64_t Val
= Memory
.OffsetImm
? (Memory
.OffsetImm
->getValue() / 4) : 0;
3095 Inst
.addOperand(MCOperand::createReg(Memory
.BaseRegNum
));
3096 Inst
.addOperand(MCOperand::createImm(Val
));
3099 void addPostIdxImm8Operands(MCInst
&Inst
, unsigned N
) const {
3100 assert(N
== 1 && "Invalid number of operands!");
3101 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3102 assert(CE
&& "non-constant post-idx-imm8 operand!");
3103 int Imm
= CE
->getValue();
3104 bool isAdd
= Imm
>= 0;
3105 if (Imm
== std::numeric_limits
<int32_t>::min()) Imm
= 0;
3106 Imm
= (Imm
< 0 ? -Imm
: Imm
) | (int)isAdd
<< 8;
3107 Inst
.addOperand(MCOperand::createImm(Imm
));
3110 void addPostIdxImm8s4Operands(MCInst
&Inst
, unsigned N
) const {
3111 assert(N
== 1 && "Invalid number of operands!");
3112 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3113 assert(CE
&& "non-constant post-idx-imm8s4 operand!");
3114 int Imm
= CE
->getValue();
3115 bool isAdd
= Imm
>= 0;
3116 if (Imm
== std::numeric_limits
<int32_t>::min()) Imm
= 0;
3117 // Immediate is scaled by 4.
3118 Imm
= ((Imm
< 0 ? -Imm
: Imm
) / 4) | (int)isAdd
<< 8;
3119 Inst
.addOperand(MCOperand::createImm(Imm
));
3122 void addPostIdxRegOperands(MCInst
&Inst
, unsigned N
) const {
3123 assert(N
== 2 && "Invalid number of operands!");
3124 Inst
.addOperand(MCOperand::createReg(PostIdxReg
.RegNum
));
3125 Inst
.addOperand(MCOperand::createImm(PostIdxReg
.isAdd
));
3128 void addPostIdxRegShiftedOperands(MCInst
&Inst
, unsigned N
) const {
3129 assert(N
== 2 && "Invalid number of operands!");
3130 Inst
.addOperand(MCOperand::createReg(PostIdxReg
.RegNum
));
3131 // The sign, shift type, and shift amount are encoded in a single operand
3132 // using the AM2 encoding helpers.
3133 ARM_AM::AddrOpc opc
= PostIdxReg
.isAdd
? ARM_AM::add
: ARM_AM::sub
;
3134 unsigned Imm
= ARM_AM::getAM2Opc(opc
, PostIdxReg
.ShiftImm
,
3135 PostIdxReg
.ShiftTy
);
3136 Inst
.addOperand(MCOperand::createImm(Imm
));
3139 void addPowerTwoOperands(MCInst
&Inst
, unsigned N
) const {
3140 assert(N
== 1 && "Invalid number of operands!");
3141 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3142 Inst
.addOperand(MCOperand::createImm(CE
->getValue()));
3145 void addMSRMaskOperands(MCInst
&Inst
, unsigned N
) const {
3146 assert(N
== 1 && "Invalid number of operands!");
3147 Inst
.addOperand(MCOperand::createImm(unsigned(getMSRMask())));
3150 void addBankedRegOperands(MCInst
&Inst
, unsigned N
) const {
3151 assert(N
== 1 && "Invalid number of operands!");
3152 Inst
.addOperand(MCOperand::createImm(unsigned(getBankedReg())));
3155 void addProcIFlagsOperands(MCInst
&Inst
, unsigned N
) const {
3156 assert(N
== 1 && "Invalid number of operands!");
3157 Inst
.addOperand(MCOperand::createImm(unsigned(getProcIFlags())));
3160 void addVecListOperands(MCInst
&Inst
, unsigned N
) const {
3161 assert(N
== 1 && "Invalid number of operands!");
3162 Inst
.addOperand(MCOperand::createReg(VectorList
.RegNum
));
3165 void addMVEVecListOperands(MCInst
&Inst
, unsigned N
) const {
3166 assert(N
== 1 && "Invalid number of operands!");
3168 // When we come here, the VectorList field will identify a range
3169 // of q-registers by its base register and length, and it will
3170 // have already been error-checked to be the expected length of
3171 // range and contain only q-regs in the range q0-q7. So we can
3172 // count on the base register being in the range q0-q6 (for 2
3173 // regs) or q0-q4 (for 4)
3175 // The MVE instructions taking a register range of this kind will
3176 // need an operand in the QQPR or QQQQPR class, representing the
3177 // entire range as a unit. So we must translate into that class,
3178 // by finding the index of the base register in the MQPR reg
3179 // class, and returning the super-register at the corresponding
3180 // index in the target class.
3182 const MCRegisterClass
*RC_in
= &ARMMCRegisterClasses
[ARM::MQPRRegClassID
];
3183 const MCRegisterClass
*RC_out
= (VectorList
.Count
== 2) ?
3184 &ARMMCRegisterClasses
[ARM::QQPRRegClassID
] :
3185 &ARMMCRegisterClasses
[ARM::QQQQPRRegClassID
];
3187 unsigned I
, E
= RC_out
->getNumRegs();
3188 for (I
= 0; I
< E
; I
++)
3189 if (RC_in
->getRegister(I
) == VectorList
.RegNum
)
3191 assert(I
< E
&& "Invalid vector list start register!");
3193 Inst
.addOperand(MCOperand::createReg(RC_out
->getRegister(I
)));
3196 void addVecListIndexedOperands(MCInst
&Inst
, unsigned N
) const {
3197 assert(N
== 2 && "Invalid number of operands!");
3198 Inst
.addOperand(MCOperand::createReg(VectorList
.RegNum
));
3199 Inst
.addOperand(MCOperand::createImm(VectorList
.LaneIndex
));
3202 void addVectorIndex8Operands(MCInst
&Inst
, unsigned N
) const {
3203 assert(N
== 1 && "Invalid number of operands!");
3204 Inst
.addOperand(MCOperand::createImm(getVectorIndex()));
3207 void addVectorIndex16Operands(MCInst
&Inst
, unsigned N
) const {
3208 assert(N
== 1 && "Invalid number of operands!");
3209 Inst
.addOperand(MCOperand::createImm(getVectorIndex()));
3212 void addVectorIndex32Operands(MCInst
&Inst
, unsigned N
) const {
3213 assert(N
== 1 && "Invalid number of operands!");
3214 Inst
.addOperand(MCOperand::createImm(getVectorIndex()));
3217 void addVectorIndex64Operands(MCInst
&Inst
, unsigned N
) const {
3218 assert(N
== 1 && "Invalid number of operands!");
3219 Inst
.addOperand(MCOperand::createImm(getVectorIndex()));
3222 void addMVEVectorIndexOperands(MCInst
&Inst
, unsigned N
) const {
3223 assert(N
== 1 && "Invalid number of operands!");
3224 Inst
.addOperand(MCOperand::createImm(getVectorIndex()));
3227 void addMVEPairVectorIndexOperands(MCInst
&Inst
, unsigned N
) const {
3228 assert(N
== 1 && "Invalid number of operands!");
3229 Inst
.addOperand(MCOperand::createImm(getVectorIndex()));
3232 void addNEONi8splatOperands(MCInst
&Inst
, unsigned N
) const {
3233 assert(N
== 1 && "Invalid number of operands!");
3234 // The immediate encodes the type of constant as well as the value.
3235 // Mask in that this is an i8 splat.
3236 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3237 Inst
.addOperand(MCOperand::createImm(CE
->getValue() | 0xe00));
3240 void addNEONi16splatOperands(MCInst
&Inst
, unsigned N
) const {
3241 assert(N
== 1 && "Invalid number of operands!");
3242 // The immediate encodes the type of constant as well as the value.
3243 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3244 unsigned Value
= CE
->getValue();
3245 Value
= ARM_AM::encodeNEONi16splat(Value
);
3246 Inst
.addOperand(MCOperand::createImm(Value
));
3249 void addNEONi16splatNotOperands(MCInst
&Inst
, unsigned N
) const {
3250 assert(N
== 1 && "Invalid number of operands!");
3251 // The immediate encodes the type of constant as well as the value.
3252 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3253 unsigned Value
= CE
->getValue();
3254 Value
= ARM_AM::encodeNEONi16splat(~Value
& 0xffff);
3255 Inst
.addOperand(MCOperand::createImm(Value
));
3258 void addNEONi32splatOperands(MCInst
&Inst
, unsigned N
) const {
3259 assert(N
== 1 && "Invalid number of operands!");
3260 // The immediate encodes the type of constant as well as the value.
3261 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3262 unsigned Value
= CE
->getValue();
3263 Value
= ARM_AM::encodeNEONi32splat(Value
);
3264 Inst
.addOperand(MCOperand::createImm(Value
));
3267 void addNEONi32splatNotOperands(MCInst
&Inst
, unsigned N
) const {
3268 assert(N
== 1 && "Invalid number of operands!");
3269 // The immediate encodes the type of constant as well as the value.
3270 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3271 unsigned Value
= CE
->getValue();
3272 Value
= ARM_AM::encodeNEONi32splat(~Value
);
3273 Inst
.addOperand(MCOperand::createImm(Value
));
3276 void addNEONi8ReplicateOperands(MCInst
&Inst
, bool Inv
) const {
3277 // The immediate encodes the type of constant as well as the value.
3278 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3279 assert((Inst
.getOpcode() == ARM::VMOVv8i8
||
3280 Inst
.getOpcode() == ARM::VMOVv16i8
) &&
3281 "All instructions that wants to replicate non-zero byte "
3282 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
3283 unsigned Value
= CE
->getValue();
3286 unsigned B
= Value
& 0xff;
3287 B
|= 0xe00; // cmode = 0b1110
3288 Inst
.addOperand(MCOperand::createImm(B
));
3291 void addNEONinvi8ReplicateOperands(MCInst
&Inst
, unsigned N
) const {
3292 assert(N
== 1 && "Invalid number of operands!");
3293 addNEONi8ReplicateOperands(Inst
, true);
3296 static unsigned encodeNeonVMOVImmediate(unsigned Value
) {
3297 if (Value
>= 256 && Value
<= 0xffff)
3298 Value
= (Value
>> 8) | ((Value
& 0xff) ? 0xc00 : 0x200);
3299 else if (Value
> 0xffff && Value
<= 0xffffff)
3300 Value
= (Value
>> 16) | ((Value
& 0xff) ? 0xd00 : 0x400);
3301 else if (Value
> 0xffffff)
3302 Value
= (Value
>> 24) | 0x600;
3306 void addNEONi32vmovOperands(MCInst
&Inst
, unsigned N
) const {
3307 assert(N
== 1 && "Invalid number of operands!");
3308 // The immediate encodes the type of constant as well as the value.
3309 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3310 unsigned Value
= encodeNeonVMOVImmediate(CE
->getValue());
3311 Inst
.addOperand(MCOperand::createImm(Value
));
3314 void addNEONvmovi8ReplicateOperands(MCInst
&Inst
, unsigned N
) const {
3315 assert(N
== 1 && "Invalid number of operands!");
3316 addNEONi8ReplicateOperands(Inst
, false);
3319 void addNEONvmovi16ReplicateOperands(MCInst
&Inst
, unsigned N
) const {
3320 assert(N
== 1 && "Invalid number of operands!");
3321 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3322 assert((Inst
.getOpcode() == ARM::VMOVv4i16
||
3323 Inst
.getOpcode() == ARM::VMOVv8i16
||
3324 Inst
.getOpcode() == ARM::VMVNv4i16
||
3325 Inst
.getOpcode() == ARM::VMVNv8i16
) &&
3326 "All instructions that want to replicate non-zero half-word "
3327 "always must be replaced with V{MOV,MVN}v{4,8}i16.");
3328 uint64_t Value
= CE
->getValue();
3329 unsigned Elem
= Value
& 0xffff;
3331 Elem
= (Elem
>> 8) | 0x200;
3332 Inst
.addOperand(MCOperand::createImm(Elem
));
3335 void addNEONi32vmovNegOperands(MCInst
&Inst
, unsigned N
) const {
3336 assert(N
== 1 && "Invalid number of operands!");
3337 // The immediate encodes the type of constant as well as the value.
3338 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3339 unsigned Value
= encodeNeonVMOVImmediate(~CE
->getValue());
3340 Inst
.addOperand(MCOperand::createImm(Value
));
3343 void addNEONvmovi32ReplicateOperands(MCInst
&Inst
, unsigned N
) const {
3344 assert(N
== 1 && "Invalid number of operands!");
3345 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3346 assert((Inst
.getOpcode() == ARM::VMOVv2i32
||
3347 Inst
.getOpcode() == ARM::VMOVv4i32
||
3348 Inst
.getOpcode() == ARM::VMVNv2i32
||
3349 Inst
.getOpcode() == ARM::VMVNv4i32
) &&
3350 "All instructions that want to replicate non-zero word "
3351 "always must be replaced with V{MOV,MVN}v{2,4}i32.");
3352 uint64_t Value
= CE
->getValue();
3353 unsigned Elem
= encodeNeonVMOVImmediate(Value
& 0xffffffff);
3354 Inst
.addOperand(MCOperand::createImm(Elem
));
3357 void addNEONi64splatOperands(MCInst
&Inst
, unsigned N
) const {
3358 assert(N
== 1 && "Invalid number of operands!");
3359 // The immediate encodes the type of constant as well as the value.
3360 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3361 uint64_t Value
= CE
->getValue();
3363 for (unsigned i
= 0; i
< 8; ++i
, Value
>>= 8) {
3364 Imm
|= (Value
& 1) << i
;
3366 Inst
.addOperand(MCOperand::createImm(Imm
| 0x1e00));
3369 void addComplexRotationEvenOperands(MCInst
&Inst
, unsigned N
) const {
3370 assert(N
== 1 && "Invalid number of operands!");
3371 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3372 Inst
.addOperand(MCOperand::createImm(CE
->getValue() / 90));
3375 void addComplexRotationOddOperands(MCInst
&Inst
, unsigned N
) const {
3376 assert(N
== 1 && "Invalid number of operands!");
3377 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3378 Inst
.addOperand(MCOperand::createImm((CE
->getValue() - 90) / 180));
3381 void addMveSaturateOperands(MCInst
&Inst
, unsigned N
) const {
3382 assert(N
== 1 && "Invalid number of operands!");
3383 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(getImm());
3384 unsigned Imm
= CE
->getValue();
3385 assert((Imm
== 48 || Imm
== 64) && "Invalid saturate operand");
3386 Inst
.addOperand(MCOperand::createImm(Imm
== 48 ? 1 : 0));
3389 void print(raw_ostream
&OS
) const override
;
3391 static std::unique_ptr
<ARMOperand
> CreateITMask(unsigned Mask
, SMLoc S
) {
3392 auto Op
= std::make_unique
<ARMOperand
>(k_ITCondMask
);
3393 Op
->ITMask
.Mask
= Mask
;
3399 static std::unique_ptr
<ARMOperand
> CreateCondCode(ARMCC::CondCodes CC
,
3401 auto Op
= std::make_unique
<ARMOperand
>(k_CondCode
);
3408 static std::unique_ptr
<ARMOperand
> CreateVPTPred(ARMVCC::VPTCodes CC
,
3410 auto Op
= std::make_unique
<ARMOperand
>(k_VPTPred
);
3417 static std::unique_ptr
<ARMOperand
> CreateCoprocNum(unsigned CopVal
, SMLoc S
) {
3418 auto Op
= std::make_unique
<ARMOperand
>(k_CoprocNum
);
3419 Op
->Cop
.Val
= CopVal
;
3425 static std::unique_ptr
<ARMOperand
> CreateCoprocReg(unsigned CopVal
, SMLoc S
) {
3426 auto Op
= std::make_unique
<ARMOperand
>(k_CoprocReg
);
3427 Op
->Cop
.Val
= CopVal
;
3433 static std::unique_ptr
<ARMOperand
> CreateCoprocOption(unsigned Val
, SMLoc S
,
3435 auto Op
= std::make_unique
<ARMOperand
>(k_CoprocOption
);
3442 static std::unique_ptr
<ARMOperand
> CreateCCOut(unsigned RegNum
, SMLoc S
) {
3443 auto Op
= std::make_unique
<ARMOperand
>(k_CCOut
);
3444 Op
->Reg
.RegNum
= RegNum
;
3450 static std::unique_ptr
<ARMOperand
> CreateToken(StringRef Str
, SMLoc S
) {
3451 auto Op
= std::make_unique
<ARMOperand
>(k_Token
);
3452 Op
->Tok
.Data
= Str
.data();
3453 Op
->Tok
.Length
= Str
.size();
3459 static std::unique_ptr
<ARMOperand
> CreateReg(unsigned RegNum
, SMLoc S
,
3461 auto Op
= std::make_unique
<ARMOperand
>(k_Register
);
3462 Op
->Reg
.RegNum
= RegNum
;
3468 static std::unique_ptr
<ARMOperand
>
3469 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy
, unsigned SrcReg
,
3470 unsigned ShiftReg
, unsigned ShiftImm
, SMLoc S
,
3472 auto Op
= std::make_unique
<ARMOperand
>(k_ShiftedRegister
);
3473 Op
->RegShiftedReg
.ShiftTy
= ShTy
;
3474 Op
->RegShiftedReg
.SrcReg
= SrcReg
;
3475 Op
->RegShiftedReg
.ShiftReg
= ShiftReg
;
3476 Op
->RegShiftedReg
.ShiftImm
= ShiftImm
;
3482 static std::unique_ptr
<ARMOperand
>
3483 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy
, unsigned SrcReg
,
3484 unsigned ShiftImm
, SMLoc S
, SMLoc E
) {
3485 auto Op
= std::make_unique
<ARMOperand
>(k_ShiftedImmediate
);
3486 Op
->RegShiftedImm
.ShiftTy
= ShTy
;
3487 Op
->RegShiftedImm
.SrcReg
= SrcReg
;
3488 Op
->RegShiftedImm
.ShiftImm
= ShiftImm
;
3494 static std::unique_ptr
<ARMOperand
> CreateShifterImm(bool isASR
, unsigned Imm
,
3496 auto Op
= std::make_unique
<ARMOperand
>(k_ShifterImmediate
);
3497 Op
->ShifterImm
.isASR
= isASR
;
3498 Op
->ShifterImm
.Imm
= Imm
;
3504 static std::unique_ptr
<ARMOperand
> CreateRotImm(unsigned Imm
, SMLoc S
,
3506 auto Op
= std::make_unique
<ARMOperand
>(k_RotateImmediate
);
3507 Op
->RotImm
.Imm
= Imm
;
3513 static std::unique_ptr
<ARMOperand
> CreateModImm(unsigned Bits
, unsigned Rot
,
3515 auto Op
= std::make_unique
<ARMOperand
>(k_ModifiedImmediate
);
3516 Op
->ModImm
.Bits
= Bits
;
3517 Op
->ModImm
.Rot
= Rot
;
3523 static std::unique_ptr
<ARMOperand
>
3524 CreateConstantPoolImm(const MCExpr
*Val
, SMLoc S
, SMLoc E
) {
3525 auto Op
= std::make_unique
<ARMOperand
>(k_ConstantPoolImmediate
);
3532 static std::unique_ptr
<ARMOperand
>
3533 CreateBitfield(unsigned LSB
, unsigned Width
, SMLoc S
, SMLoc E
) {
3534 auto Op
= std::make_unique
<ARMOperand
>(k_BitfieldDescriptor
);
3535 Op
->Bitfield
.LSB
= LSB
;
3536 Op
->Bitfield
.Width
= Width
;
3542 static std::unique_ptr
<ARMOperand
>
3543 CreateRegList(SmallVectorImpl
<std::pair
<unsigned, unsigned>> &Regs
,
3544 SMLoc StartLoc
, SMLoc EndLoc
) {
3545 assert(Regs
.size() > 0 && "RegList contains no registers?");
3546 KindTy Kind
= k_RegisterList
;
3548 if (ARMMCRegisterClasses
[ARM::DPRRegClassID
].contains(
3549 Regs
.front().second
)) {
3550 if (Regs
.back().second
== ARM::VPR
)
3551 Kind
= k_FPDRegisterListWithVPR
;
3553 Kind
= k_DPRRegisterList
;
3554 } else if (ARMMCRegisterClasses
[ARM::SPRRegClassID
].contains(
3555 Regs
.front().second
)) {
3556 if (Regs
.back().second
== ARM::VPR
)
3557 Kind
= k_FPSRegisterListWithVPR
;
3559 Kind
= k_SPRRegisterList
;
3562 if (Kind
== k_RegisterList
&& Regs
.back().second
== ARM::APSR
)
3563 Kind
= k_RegisterListWithAPSR
;
3565 assert(std::is_sorted(Regs
.begin(), Regs
.end()) &&
3566 "Register list must be sorted by encoding");
3568 auto Op
= std::make_unique
<ARMOperand
>(Kind
);
3569 for (const auto &P
: Regs
)
3570 Op
->Registers
.push_back(P
.second
);
3572 Op
->StartLoc
= StartLoc
;
3573 Op
->EndLoc
= EndLoc
;
3577 static std::unique_ptr
<ARMOperand
> CreateVectorList(unsigned RegNum
,
3579 bool isDoubleSpaced
,
3581 auto Op
= std::make_unique
<ARMOperand
>(k_VectorList
);
3582 Op
->VectorList
.RegNum
= RegNum
;
3583 Op
->VectorList
.Count
= Count
;
3584 Op
->VectorList
.isDoubleSpaced
= isDoubleSpaced
;
3590 static std::unique_ptr
<ARMOperand
>
3591 CreateVectorListAllLanes(unsigned RegNum
, unsigned Count
, bool isDoubleSpaced
,
3593 auto Op
= std::make_unique
<ARMOperand
>(k_VectorListAllLanes
);
3594 Op
->VectorList
.RegNum
= RegNum
;
3595 Op
->VectorList
.Count
= Count
;
3596 Op
->VectorList
.isDoubleSpaced
= isDoubleSpaced
;
3602 static std::unique_ptr
<ARMOperand
>
3603 CreateVectorListIndexed(unsigned RegNum
, unsigned Count
, unsigned Index
,
3604 bool isDoubleSpaced
, SMLoc S
, SMLoc E
) {
3605 auto Op
= std::make_unique
<ARMOperand
>(k_VectorListIndexed
);
3606 Op
->VectorList
.RegNum
= RegNum
;
3607 Op
->VectorList
.Count
= Count
;
3608 Op
->VectorList
.LaneIndex
= Index
;
3609 Op
->VectorList
.isDoubleSpaced
= isDoubleSpaced
;
3615 static std::unique_ptr
<ARMOperand
>
3616 CreateVectorIndex(unsigned Idx
, SMLoc S
, SMLoc E
, MCContext
&Ctx
) {
3617 auto Op
= std::make_unique
<ARMOperand
>(k_VectorIndex
);
3618 Op
->VectorIndex
.Val
= Idx
;
3624 static std::unique_ptr
<ARMOperand
> CreateImm(const MCExpr
*Val
, SMLoc S
,
3626 auto Op
= std::make_unique
<ARMOperand
>(k_Immediate
);
3633 static std::unique_ptr
<ARMOperand
>
3634 CreateMem(unsigned BaseRegNum
, const MCConstantExpr
*OffsetImm
,
3635 unsigned OffsetRegNum
, ARM_AM::ShiftOpc ShiftType
,
3636 unsigned ShiftImm
, unsigned Alignment
, bool isNegative
, SMLoc S
,
3637 SMLoc E
, SMLoc AlignmentLoc
= SMLoc()) {
3638 auto Op
= std::make_unique
<ARMOperand
>(k_Memory
);
3639 Op
->Memory
.BaseRegNum
= BaseRegNum
;
3640 Op
->Memory
.OffsetImm
= OffsetImm
;
3641 Op
->Memory
.OffsetRegNum
= OffsetRegNum
;
3642 Op
->Memory
.ShiftType
= ShiftType
;
3643 Op
->Memory
.ShiftImm
= ShiftImm
;
3644 Op
->Memory
.Alignment
= Alignment
;
3645 Op
->Memory
.isNegative
= isNegative
;
3648 Op
->AlignmentLoc
= AlignmentLoc
;
3652 static std::unique_ptr
<ARMOperand
>
3653 CreatePostIdxReg(unsigned RegNum
, bool isAdd
, ARM_AM::ShiftOpc ShiftTy
,
3654 unsigned ShiftImm
, SMLoc S
, SMLoc E
) {
3655 auto Op
= std::make_unique
<ARMOperand
>(k_PostIndexRegister
);
3656 Op
->PostIdxReg
.RegNum
= RegNum
;
3657 Op
->PostIdxReg
.isAdd
= isAdd
;
3658 Op
->PostIdxReg
.ShiftTy
= ShiftTy
;
3659 Op
->PostIdxReg
.ShiftImm
= ShiftImm
;
3665 static std::unique_ptr
<ARMOperand
> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt
,
3667 auto Op
= std::make_unique
<ARMOperand
>(k_MemBarrierOpt
);
3668 Op
->MBOpt
.Val
= Opt
;
3674 static std::unique_ptr
<ARMOperand
>
3675 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt
, SMLoc S
) {
3676 auto Op
= std::make_unique
<ARMOperand
>(k_InstSyncBarrierOpt
);
3677 Op
->ISBOpt
.Val
= Opt
;
3683 static std::unique_ptr
<ARMOperand
>
3684 CreateTraceSyncBarrierOpt(ARM_TSB::TraceSyncBOpt Opt
, SMLoc S
) {
3685 auto Op
= std::make_unique
<ARMOperand
>(k_TraceSyncBarrierOpt
);
3686 Op
->TSBOpt
.Val
= Opt
;
3692 static std::unique_ptr
<ARMOperand
> CreateProcIFlags(ARM_PROC::IFlags IFlags
,
3694 auto Op
= std::make_unique
<ARMOperand
>(k_ProcIFlags
);
3695 Op
->IFlags
.Val
= IFlags
;
3701 static std::unique_ptr
<ARMOperand
> CreateMSRMask(unsigned MMask
, SMLoc S
) {
3702 auto Op
= std::make_unique
<ARMOperand
>(k_MSRMask
);
3703 Op
->MMask
.Val
= MMask
;
3709 static std::unique_ptr
<ARMOperand
> CreateBankedReg(unsigned Reg
, SMLoc S
) {
3710 auto Op
= std::make_unique
<ARMOperand
>(k_BankedReg
);
3711 Op
->BankedReg
.Val
= Reg
;
3718 } // end anonymous namespace.
3720 void ARMOperand::print(raw_ostream
&OS
) const {
3721 auto RegName
= [](unsigned Reg
) {
3723 return ARMInstPrinter::getRegisterName(Reg
);
3730 OS
<< "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
3733 OS
<< "<ARMVCC::" << ARMVPTPredToString(getVPTPred()) << ">";
3736 OS
<< "<ccout " << RegName(getReg()) << ">";
3738 case k_ITCondMask
: {
3739 static const char *const MaskStr
[] = {
3740 "(invalid)", "(tttt)", "(ttt)", "(ttte)",
3741 "(tt)", "(ttet)", "(tte)", "(ttee)",
3742 "(t)", "(tett)", "(tet)", "(tete)",
3743 "(te)", "(teet)", "(tee)", "(teee)",
3745 assert((ITMask
.Mask
& 0xf) == ITMask
.Mask
);
3746 OS
<< "<it-mask " << MaskStr
[ITMask
.Mask
] << ">";
3750 OS
<< "<coprocessor number: " << getCoproc() << ">";
3753 OS
<< "<coprocessor register: " << getCoproc() << ">";
3755 case k_CoprocOption
:
3756 OS
<< "<coprocessor option: " << CoprocOption
.Val
<< ">";
3759 OS
<< "<mask: " << getMSRMask() << ">";
3762 OS
<< "<banked reg: " << getBankedReg() << ">";
3767 case k_MemBarrierOpt
:
3768 OS
<< "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
3770 case k_InstSyncBarrierOpt
:
3771 OS
<< "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
3773 case k_TraceSyncBarrierOpt
:
3774 OS
<< "<ARM_TSB::" << TraceSyncBOptToString(getTraceSyncBarrierOpt()) << ">";
3778 if (Memory
.BaseRegNum
)
3779 OS
<< " base:" << RegName(Memory
.BaseRegNum
);
3780 if (Memory
.OffsetImm
)
3781 OS
<< " offset-imm:" << *Memory
.OffsetImm
;
3782 if (Memory
.OffsetRegNum
)
3783 OS
<< " offset-reg:" << (Memory
.isNegative
? "-" : "")
3784 << RegName(Memory
.OffsetRegNum
);
3785 if (Memory
.ShiftType
!= ARM_AM::no_shift
) {
3786 OS
<< " shift-type:" << ARM_AM::getShiftOpcStr(Memory
.ShiftType
);
3787 OS
<< " shift-imm:" << Memory
.ShiftImm
;
3789 if (Memory
.Alignment
)
3790 OS
<< " alignment:" << Memory
.Alignment
;
3793 case k_PostIndexRegister
:
3794 OS
<< "post-idx register " << (PostIdxReg
.isAdd
? "" : "-")
3795 << RegName(PostIdxReg
.RegNum
);
3796 if (PostIdxReg
.ShiftTy
!= ARM_AM::no_shift
)
3797 OS
<< ARM_AM::getShiftOpcStr(PostIdxReg
.ShiftTy
) << " "
3798 << PostIdxReg
.ShiftImm
;
3801 case k_ProcIFlags
: {
3802 OS
<< "<ARM_PROC::";
3803 unsigned IFlags
= getProcIFlags();
3804 for (int i
=2; i
>= 0; --i
)
3805 if (IFlags
& (1 << i
))
3806 OS
<< ARM_PROC::IFlagsToString(1 << i
);
3811 OS
<< "<register " << RegName(getReg()) << ">";
3813 case k_ShifterImmediate
:
3814 OS
<< "<shift " << (ShifterImm
.isASR
? "asr" : "lsl")
3815 << " #" << ShifterImm
.Imm
<< ">";
3817 case k_ShiftedRegister
:
3818 OS
<< "<so_reg_reg " << RegName(RegShiftedReg
.SrcReg
) << " "
3819 << ARM_AM::getShiftOpcStr(RegShiftedReg
.ShiftTy
) << " "
3820 << RegName(RegShiftedReg
.ShiftReg
) << ">";
3822 case k_ShiftedImmediate
:
3823 OS
<< "<so_reg_imm " << RegName(RegShiftedImm
.SrcReg
) << " "
3824 << ARM_AM::getShiftOpcStr(RegShiftedImm
.ShiftTy
) << " #"
3825 << RegShiftedImm
.ShiftImm
<< ">";
3827 case k_RotateImmediate
:
3828 OS
<< "<ror " << " #" << (RotImm
.Imm
* 8) << ">";
3830 case k_ModifiedImmediate
:
3831 OS
<< "<mod_imm #" << ModImm
.Bits
<< ", #"
3832 << ModImm
.Rot
<< ")>";
3834 case k_ConstantPoolImmediate
:
3835 OS
<< "<constant_pool_imm #" << *getConstantPoolImm();
3837 case k_BitfieldDescriptor
:
3838 OS
<< "<bitfield " << "lsb: " << Bitfield
.LSB
3839 << ", width: " << Bitfield
.Width
<< ">";
3841 case k_RegisterList
:
3842 case k_RegisterListWithAPSR
:
3843 case k_DPRRegisterList
:
3844 case k_SPRRegisterList
:
3845 case k_FPSRegisterListWithVPR
:
3846 case k_FPDRegisterListWithVPR
: {
3847 OS
<< "<register_list ";
3849 const SmallVectorImpl
<unsigned> &RegList
= getRegList();
3850 for (SmallVectorImpl
<unsigned>::const_iterator
3851 I
= RegList
.begin(), E
= RegList
.end(); I
!= E
; ) {
3853 if (++I
< E
) OS
<< ", ";
3860 OS
<< "<vector_list " << VectorList
.Count
<< " * "
3861 << RegName(VectorList
.RegNum
) << ">";
3863 case k_VectorListAllLanes
:
3864 OS
<< "<vector_list(all lanes) " << VectorList
.Count
<< " * "
3865 << RegName(VectorList
.RegNum
) << ">";
3867 case k_VectorListIndexed
:
3868 OS
<< "<vector_list(lane " << VectorList
.LaneIndex
<< ") "
3869 << VectorList
.Count
<< " * " << RegName(VectorList
.RegNum
) << ">";
3872 OS
<< "'" << getToken() << "'";
3875 OS
<< "<vectorindex " << getVectorIndex() << ">";
3880 /// @name Auto-generated Match Functions
3883 static unsigned MatchRegisterName(StringRef Name
);
3887 bool ARMAsmParser::ParseRegister(unsigned &RegNo
,
3888 SMLoc
&StartLoc
, SMLoc
&EndLoc
) {
3889 const AsmToken
&Tok
= getParser().getTok();
3890 StartLoc
= Tok
.getLoc();
3891 EndLoc
= Tok
.getEndLoc();
3892 RegNo
= tryParseRegister();
3894 return (RegNo
== (unsigned)-1);
3897 /// Try to parse a register name. The token must be an Identifier when called,
3898 /// and if it is a register name the token is eaten and the register number is
3899 /// returned. Otherwise return -1.
3900 int ARMAsmParser::tryParseRegister() {
3901 MCAsmParser
&Parser
= getParser();
3902 const AsmToken
&Tok
= Parser
.getTok();
3903 if (Tok
.isNot(AsmToken::Identifier
)) return -1;
3905 std::string lowerCase
= Tok
.getString().lower();
3906 unsigned RegNum
= MatchRegisterName(lowerCase
);
3908 RegNum
= StringSwitch
<unsigned>(lowerCase
)
3909 .Case("r13", ARM::SP
)
3910 .Case("r14", ARM::LR
)
3911 .Case("r15", ARM::PC
)
3912 .Case("ip", ARM::R12
)
3913 // Additional register name aliases for 'gas' compatibility.
3914 .Case("a1", ARM::R0
)
3915 .Case("a2", ARM::R1
)
3916 .Case("a3", ARM::R2
)
3917 .Case("a4", ARM::R3
)
3918 .Case("v1", ARM::R4
)
3919 .Case("v2", ARM::R5
)
3920 .Case("v3", ARM::R6
)
3921 .Case("v4", ARM::R7
)
3922 .Case("v5", ARM::R8
)
3923 .Case("v6", ARM::R9
)
3924 .Case("v7", ARM::R10
)
3925 .Case("v8", ARM::R11
)
3926 .Case("sb", ARM::R9
)
3927 .Case("sl", ARM::R10
)
3928 .Case("fp", ARM::R11
)
3932 // Check for aliases registered via .req. Canonicalize to lower case.
3933 // That's more consistent since register names are case insensitive, and
3934 // it's how the original entry was passed in from MC/MCParser/AsmParser.
3935 StringMap
<unsigned>::const_iterator Entry
= RegisterReqs
.find(lowerCase
);
3936 // If no match, return failure.
3937 if (Entry
== RegisterReqs
.end())
3939 Parser
.Lex(); // Eat identifier token.
3940 return Entry
->getValue();
3943 // Some FPUs only have 16 D registers, so D16-D31 are invalid
3944 if (!hasD32() && RegNum
>= ARM::D16
&& RegNum
<= ARM::D31
)
3947 Parser
.Lex(); // Eat identifier token.
3952 // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
3953 // If a recoverable error occurs, return 1. If an irrecoverable error
3954 // occurs, return -1. An irrecoverable error is one where tokens have been
3955 // consumed in the process of trying to parse the shifter (i.e., when it is
3956 // indeed a shifter operand, but malformed).
3957 int ARMAsmParser::tryParseShiftRegister(OperandVector
&Operands
) {
3958 MCAsmParser
&Parser
= getParser();
3959 SMLoc S
= Parser
.getTok().getLoc();
3960 const AsmToken
&Tok
= Parser
.getTok();
3961 if (Tok
.isNot(AsmToken::Identifier
))
3964 std::string lowerCase
= Tok
.getString().lower();
3965 ARM_AM::ShiftOpc ShiftTy
= StringSwitch
<ARM_AM::ShiftOpc
>(lowerCase
)
3966 .Case("asl", ARM_AM::lsl
)
3967 .Case("lsl", ARM_AM::lsl
)
3968 .Case("lsr", ARM_AM::lsr
)
3969 .Case("asr", ARM_AM::asr
)
3970 .Case("ror", ARM_AM::ror
)
3971 .Case("rrx", ARM_AM::rrx
)
3972 .Default(ARM_AM::no_shift
);
3974 if (ShiftTy
== ARM_AM::no_shift
)
3977 Parser
.Lex(); // Eat the operator.
3979 // The source register for the shift has already been added to the
3980 // operand list, so we need to pop it off and combine it into the shifted
3981 // register operand instead.
3982 std::unique_ptr
<ARMOperand
> PrevOp(
3983 (ARMOperand
*)Operands
.pop_back_val().release());
3984 if (!PrevOp
->isReg())
3985 return Error(PrevOp
->getStartLoc(), "shift must be of a register");
3986 int SrcReg
= PrevOp
->getReg();
3991 if (ShiftTy
== ARM_AM::rrx
) {
3992 // RRX Doesn't have an explicit shift amount. The encoder expects
3993 // the shift register to be the same as the source register. Seems odd,
3997 // Figure out if this is shifted by a constant or a register (for non-RRX).
3998 if (Parser
.getTok().is(AsmToken::Hash
) ||
3999 Parser
.getTok().is(AsmToken::Dollar
)) {
4000 Parser
.Lex(); // Eat hash.
4001 SMLoc ImmLoc
= Parser
.getTok().getLoc();
4002 const MCExpr
*ShiftExpr
= nullptr;
4003 if (getParser().parseExpression(ShiftExpr
, EndLoc
)) {
4004 Error(ImmLoc
, "invalid immediate shift value");
4007 // The expression must be evaluatable as an immediate.
4008 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(ShiftExpr
);
4010 Error(ImmLoc
, "invalid immediate shift value");
4013 // Range check the immediate.
4014 // lsl, ror: 0 <= imm <= 31
4015 // lsr, asr: 0 <= imm <= 32
4016 Imm
= CE
->getValue();
4018 ((ShiftTy
== ARM_AM::lsl
|| ShiftTy
== ARM_AM::ror
) && Imm
> 31) ||
4019 ((ShiftTy
== ARM_AM::lsr
|| ShiftTy
== ARM_AM::asr
) && Imm
> 32)) {
4020 Error(ImmLoc
, "immediate shift value out of range");
4023 // shift by zero is a nop. Always send it through as lsl.
4024 // ('as' compatibility)
4026 ShiftTy
= ARM_AM::lsl
;
4027 } else if (Parser
.getTok().is(AsmToken::Identifier
)) {
4028 SMLoc L
= Parser
.getTok().getLoc();
4029 EndLoc
= Parser
.getTok().getEndLoc();
4030 ShiftReg
= tryParseRegister();
4031 if (ShiftReg
== -1) {
4032 Error(L
, "expected immediate or register in shift operand");
4036 Error(Parser
.getTok().getLoc(),
4037 "expected immediate or register in shift operand");
4042 if (ShiftReg
&& ShiftTy
!= ARM_AM::rrx
)
4043 Operands
.push_back(ARMOperand::CreateShiftedRegister(ShiftTy
, SrcReg
,
4047 Operands
.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy
, SrcReg
, Imm
,
4053 /// Try to parse a register name. The token must be an Identifier when called.
4054 /// If it's a register, an AsmOperand is created. Another AsmOperand is created
4055 /// if there is a "writeback". 'true' if it's not a register.
4057 /// TODO this is likely to change to allow different register types and or to
4058 /// parse for a specific register type.
4059 bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector
&Operands
) {
4060 MCAsmParser
&Parser
= getParser();
4061 SMLoc RegStartLoc
= Parser
.getTok().getLoc();
4062 SMLoc RegEndLoc
= Parser
.getTok().getEndLoc();
4063 int RegNo
= tryParseRegister();
4067 Operands
.push_back(ARMOperand::CreateReg(RegNo
, RegStartLoc
, RegEndLoc
));
4069 const AsmToken
&ExclaimTok
= Parser
.getTok();
4070 if (ExclaimTok
.is(AsmToken::Exclaim
)) {
4071 Operands
.push_back(ARMOperand::CreateToken(ExclaimTok
.getString(),
4072 ExclaimTok
.getLoc()));
4073 Parser
.Lex(); // Eat exclaim token
4077 // Also check for an index operand. This is only legal for vector registers,
4078 // but that'll get caught OK in operand matching, so we don't need to
4079 // explicitly filter everything else out here.
4080 if (Parser
.getTok().is(AsmToken::LBrac
)) {
4081 SMLoc SIdx
= Parser
.getTok().getLoc();
4082 Parser
.Lex(); // Eat left bracket token.
4084 const MCExpr
*ImmVal
;
4085 if (getParser().parseExpression(ImmVal
))
4087 const MCConstantExpr
*MCE
= dyn_cast
<MCConstantExpr
>(ImmVal
);
4089 return TokError("immediate value expected for vector index");
4091 if (Parser
.getTok().isNot(AsmToken::RBrac
))
4092 return Error(Parser
.getTok().getLoc(), "']' expected");
4094 SMLoc E
= Parser
.getTok().getEndLoc();
4095 Parser
.Lex(); // Eat right bracket token.
4097 Operands
.push_back(ARMOperand::CreateVectorIndex(MCE
->getValue(),
4105 /// MatchCoprocessorOperandName - Try to parse an coprocessor related
4106 /// instruction with a symbolic operand name.
4107 /// We accept "crN" syntax for GAS compatibility.
4108 /// <operand-name> ::= <prefix><number>
4109 /// If CoprocOp is 'c', then:
4110 /// <prefix> ::= c | cr
4111 /// If CoprocOp is 'p', then :
4113 /// <number> ::= integer in range [0, 15]
4114 static int MatchCoprocessorOperandName(StringRef Name
, char CoprocOp
) {
4115 // Use the same layout as the tablegen'erated register name matcher. Ugly,
4117 if (Name
.size() < 2 || Name
[0] != CoprocOp
)
4119 Name
= (Name
[1] == 'r') ? Name
.drop_front(2) : Name
.drop_front();
4121 switch (Name
.size()) {
4142 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
4143 // However, old cores (v5/v6) did use them in that way.
4144 case '0': return 10;
4145 case '1': return 11;
4146 case '2': return 12;
4147 case '3': return 13;
4148 case '4': return 14;
4149 case '5': return 15;
4154 /// parseITCondCode - Try to parse a condition code for an IT instruction.
4155 OperandMatchResultTy
4156 ARMAsmParser::parseITCondCode(OperandVector
&Operands
) {
4157 MCAsmParser
&Parser
= getParser();
4158 SMLoc S
= Parser
.getTok().getLoc();
4159 const AsmToken
&Tok
= Parser
.getTok();
4160 if (!Tok
.is(AsmToken::Identifier
))
4161 return MatchOperand_NoMatch
;
4162 unsigned CC
= ARMCondCodeFromString(Tok
.getString());
4164 return MatchOperand_NoMatch
;
4165 Parser
.Lex(); // Eat the token.
4167 Operands
.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC
), S
));
4169 return MatchOperand_Success
;
4172 /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
4173 /// token must be an Identifier when called, and if it is a coprocessor
4174 /// number, the token is eaten and the operand is added to the operand list.
4175 OperandMatchResultTy
4176 ARMAsmParser::parseCoprocNumOperand(OperandVector
&Operands
) {
4177 MCAsmParser
&Parser
= getParser();
4178 SMLoc S
= Parser
.getTok().getLoc();
4179 const AsmToken
&Tok
= Parser
.getTok();
4180 if (Tok
.isNot(AsmToken::Identifier
))
4181 return MatchOperand_NoMatch
;
4183 int Num
= MatchCoprocessorOperandName(Tok
.getString().lower(), 'p');
4185 return MatchOperand_NoMatch
;
4186 if (!isValidCoprocessorNumber(Num
, getSTI().getFeatureBits()))
4187 return MatchOperand_NoMatch
;
4189 Parser
.Lex(); // Eat identifier token.
4190 Operands
.push_back(ARMOperand::CreateCoprocNum(Num
, S
));
4191 return MatchOperand_Success
;
4194 /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
4195 /// token must be an Identifier when called, and if it is a coprocessor
4196 /// number, the token is eaten and the operand is added to the operand list.
4197 OperandMatchResultTy
4198 ARMAsmParser::parseCoprocRegOperand(OperandVector
&Operands
) {
4199 MCAsmParser
&Parser
= getParser();
4200 SMLoc S
= Parser
.getTok().getLoc();
4201 const AsmToken
&Tok
= Parser
.getTok();
4202 if (Tok
.isNot(AsmToken::Identifier
))
4203 return MatchOperand_NoMatch
;
4205 int Reg
= MatchCoprocessorOperandName(Tok
.getString().lower(), 'c');
4207 return MatchOperand_NoMatch
;
4209 Parser
.Lex(); // Eat identifier token.
4210 Operands
.push_back(ARMOperand::CreateCoprocReg(Reg
, S
));
4211 return MatchOperand_Success
;
4214 /// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
4215 /// coproc_option : '{' imm0_255 '}'
4216 OperandMatchResultTy
4217 ARMAsmParser::parseCoprocOptionOperand(OperandVector
&Operands
) {
4218 MCAsmParser
&Parser
= getParser();
4219 SMLoc S
= Parser
.getTok().getLoc();
4221 // If this isn't a '{', this isn't a coprocessor immediate operand.
4222 if (Parser
.getTok().isNot(AsmToken::LCurly
))
4223 return MatchOperand_NoMatch
;
4224 Parser
.Lex(); // Eat the '{'
4227 SMLoc Loc
= Parser
.getTok().getLoc();
4228 if (getParser().parseExpression(Expr
)) {
4229 Error(Loc
, "illegal expression");
4230 return MatchOperand_ParseFail
;
4232 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Expr
);
4233 if (!CE
|| CE
->getValue() < 0 || CE
->getValue() > 255) {
4234 Error(Loc
, "coprocessor option must be an immediate in range [0, 255]");
4235 return MatchOperand_ParseFail
;
4237 int Val
= CE
->getValue();
4239 // Check for and consume the closing '}'
4240 if (Parser
.getTok().isNot(AsmToken::RCurly
))
4241 return MatchOperand_ParseFail
;
4242 SMLoc E
= Parser
.getTok().getEndLoc();
4243 Parser
.Lex(); // Eat the '}'
4245 Operands
.push_back(ARMOperand::CreateCoprocOption(Val
, S
, E
));
4246 return MatchOperand_Success
;
4249 // For register list parsing, we need to map from raw GPR register numbering
4250 // to the enumeration values. The enumeration values aren't sorted by
4251 // register number due to our using "sp", "lr" and "pc" as canonical names.
4252 static unsigned getNextRegister(unsigned Reg
) {
4253 // If this is a GPR, we need to do it manually, otherwise we can rely
4254 // on the sort ordering of the enumeration since the other reg-classes
4256 if (!ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(Reg
))
4259 default: llvm_unreachable("Invalid GPR number!");
4260 case ARM::R0
: return ARM::R1
; case ARM::R1
: return ARM::R2
;
4261 case ARM::R2
: return ARM::R3
; case ARM::R3
: return ARM::R4
;
4262 case ARM::R4
: return ARM::R5
; case ARM::R5
: return ARM::R6
;
4263 case ARM::R6
: return ARM::R7
; case ARM::R7
: return ARM::R8
;
4264 case ARM::R8
: return ARM::R9
; case ARM::R9
: return ARM::R10
;
4265 case ARM::R10
: return ARM::R11
; case ARM::R11
: return ARM::R12
;
4266 case ARM::R12
: return ARM::SP
; case ARM::SP
: return ARM::LR
;
4267 case ARM::LR
: return ARM::PC
; case ARM::PC
: return ARM::R0
;
4271 // Insert an <Encoding, Register> pair in an ordered vector. Return true on
4272 // success, or false, if duplicate encoding found.
4274 insertNoDuplicates(SmallVectorImpl
<std::pair
<unsigned, unsigned>> &Regs
,
4275 unsigned Enc
, unsigned Reg
) {
4276 Regs
.emplace_back(Enc
, Reg
);
4277 for (auto I
= Regs
.rbegin(), J
= I
+ 1, E
= Regs
.rend(); J
!= E
; ++I
, ++J
) {
4278 if (J
->first
== Enc
) {
4279 Regs
.erase(J
.base());
4289 /// Parse a register list.
4290 bool ARMAsmParser::parseRegisterList(OperandVector
&Operands
,
4291 bool EnforceOrder
) {
4292 MCAsmParser
&Parser
= getParser();
4293 if (Parser
.getTok().isNot(AsmToken::LCurly
))
4294 return TokError("Token is not a Left Curly Brace");
4295 SMLoc S
= Parser
.getTok().getLoc();
4296 Parser
.Lex(); // Eat '{' token.
4297 SMLoc RegLoc
= Parser
.getTok().getLoc();
4299 // Check the first register in the list to see what register class
4300 // this is a list of.
4301 int Reg
= tryParseRegister();
4303 return Error(RegLoc
, "register expected");
4305 // The reglist instructions have at most 16 registers, so reserve
4306 // space for that many.
4308 SmallVector
<std::pair
<unsigned, unsigned>, 16> Registers
;
4310 // Allow Q regs and just interpret them as the two D sub-registers.
4311 if (ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(Reg
)) {
4312 Reg
= getDRegFromQReg(Reg
);
4313 EReg
= MRI
->getEncodingValue(Reg
);
4314 Registers
.emplace_back(EReg
, Reg
);
4317 const MCRegisterClass
*RC
;
4318 if (ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(Reg
))
4319 RC
= &ARMMCRegisterClasses
[ARM::GPRRegClassID
];
4320 else if (ARMMCRegisterClasses
[ARM::DPRRegClassID
].contains(Reg
))
4321 RC
= &ARMMCRegisterClasses
[ARM::DPRRegClassID
];
4322 else if (ARMMCRegisterClasses
[ARM::SPRRegClassID
].contains(Reg
))
4323 RC
= &ARMMCRegisterClasses
[ARM::SPRRegClassID
];
4324 else if (ARMMCRegisterClasses
[ARM::GPRwithAPSRnospRegClassID
].contains(Reg
))
4325 RC
= &ARMMCRegisterClasses
[ARM::GPRwithAPSRnospRegClassID
];
4327 return Error(RegLoc
, "invalid register in register list");
4329 // Store the register.
4330 EReg
= MRI
->getEncodingValue(Reg
);
4331 Registers
.emplace_back(EReg
, Reg
);
4333 // This starts immediately after the first register token in the list,
4334 // so we can see either a comma or a minus (range separator) as a legal
4336 while (Parser
.getTok().is(AsmToken::Comma
) ||
4337 Parser
.getTok().is(AsmToken::Minus
)) {
4338 if (Parser
.getTok().is(AsmToken::Minus
)) {
4339 Parser
.Lex(); // Eat the minus.
4340 SMLoc AfterMinusLoc
= Parser
.getTok().getLoc();
4341 int EndReg
= tryParseRegister();
4343 return Error(AfterMinusLoc
, "register expected");
4344 // Allow Q regs and just interpret them as the two D sub-registers.
4345 if (ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(EndReg
))
4346 EndReg
= getDRegFromQReg(EndReg
) + 1;
4347 // If the register is the same as the start reg, there's nothing
4351 // The register must be in the same register class as the first.
4352 if (!RC
->contains(EndReg
))
4353 return Error(AfterMinusLoc
, "invalid register in register list");
4354 // Ranges must go from low to high.
4355 if (MRI
->getEncodingValue(Reg
) > MRI
->getEncodingValue(EndReg
))
4356 return Error(AfterMinusLoc
, "bad range in register list");
4358 // Add all the registers in the range to the register list.
4359 while (Reg
!= EndReg
) {
4360 Reg
= getNextRegister(Reg
);
4361 EReg
= MRI
->getEncodingValue(Reg
);
4362 if (!insertNoDuplicates(Registers
, EReg
, Reg
)) {
4363 Warning(AfterMinusLoc
, StringRef("duplicated register (") +
4364 ARMInstPrinter::getRegisterName(Reg
) +
4365 ") in register list");
4370 Parser
.Lex(); // Eat the comma.
4371 RegLoc
= Parser
.getTok().getLoc();
4373 const AsmToken RegTok
= Parser
.getTok();
4374 Reg
= tryParseRegister();
4376 return Error(RegLoc
, "register expected");
4377 // Allow Q regs and just interpret them as the two D sub-registers.
4378 bool isQReg
= false;
4379 if (ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(Reg
)) {
4380 Reg
= getDRegFromQReg(Reg
);
4383 if (!RC
->contains(Reg
) &&
4384 RC
->getID() == ARMMCRegisterClasses
[ARM::GPRRegClassID
].getID() &&
4385 ARMMCRegisterClasses
[ARM::GPRwithAPSRnospRegClassID
].contains(Reg
)) {
4386 // switch the register classes, as GPRwithAPSRnospRegClassID is a partial
4387 // subset of GPRRegClassId except it contains APSR as well.
4388 RC
= &ARMMCRegisterClasses
[ARM::GPRwithAPSRnospRegClassID
];
4390 if (Reg
== ARM::VPR
&&
4391 (RC
== &ARMMCRegisterClasses
[ARM::SPRRegClassID
] ||
4392 RC
== &ARMMCRegisterClasses
[ARM::DPRRegClassID
] ||
4393 RC
== &ARMMCRegisterClasses
[ARM::FPWithVPRRegClassID
])) {
4394 RC
= &ARMMCRegisterClasses
[ARM::FPWithVPRRegClassID
];
4395 EReg
= MRI
->getEncodingValue(Reg
);
4396 if (!insertNoDuplicates(Registers
, EReg
, Reg
)) {
4397 Warning(RegLoc
, "duplicated register (" + RegTok
.getString() +
4398 ") in register list");
4402 // The register must be in the same register class as the first.
4403 if (!RC
->contains(Reg
))
4404 return Error(RegLoc
, "invalid register in register list");
4405 // In most cases, the list must be monotonically increasing. An
4406 // exception is CLRM, which is order-independent anyway, so
4407 // there's no potential for confusion if you write clrm {r2,r1}
4408 // instead of clrm {r1,r2}.
4410 MRI
->getEncodingValue(Reg
) < MRI
->getEncodingValue(OldReg
)) {
4411 if (ARMMCRegisterClasses
[ARM::GPRRegClassID
].contains(Reg
))
4412 Warning(RegLoc
, "register list not in ascending order");
4413 else if (!ARMMCRegisterClasses
[ARM::GPRwithAPSRnospRegClassID
].contains(Reg
))
4414 return Error(RegLoc
, "register list not in ascending order");
4416 // VFP register lists must also be contiguous.
4417 if (RC
!= &ARMMCRegisterClasses
[ARM::GPRRegClassID
] &&
4418 RC
!= &ARMMCRegisterClasses
[ARM::GPRwithAPSRnospRegClassID
] &&
4420 return Error(RegLoc
, "non-contiguous register range");
4421 EReg
= MRI
->getEncodingValue(Reg
);
4422 if (!insertNoDuplicates(Registers
, EReg
, Reg
)) {
4423 Warning(RegLoc
, "duplicated register (" + RegTok
.getString() +
4424 ") in register list");
4427 EReg
= MRI
->getEncodingValue(++Reg
);
4428 Registers
.emplace_back(EReg
, Reg
);
4432 if (Parser
.getTok().isNot(AsmToken::RCurly
))
4433 return Error(Parser
.getTok().getLoc(), "'}' expected");
4434 SMLoc E
= Parser
.getTok().getEndLoc();
4435 Parser
.Lex(); // Eat '}' token.
4437 // Push the register list operand.
4438 Operands
.push_back(ARMOperand::CreateRegList(Registers
, S
, E
));
4440 // The ARM system instruction variants for LDM/STM have a '^' token here.
4441 if (Parser
.getTok().is(AsmToken::Caret
)) {
4442 Operands
.push_back(ARMOperand::CreateToken("^",Parser
.getTok().getLoc()));
4443 Parser
.Lex(); // Eat '^' token.
4449 // Helper function to parse the lane index for vector lists.
4450 OperandMatchResultTy
ARMAsmParser::
4451 parseVectorLane(VectorLaneTy
&LaneKind
, unsigned &Index
, SMLoc
&EndLoc
) {
4452 MCAsmParser
&Parser
= getParser();
4453 Index
= 0; // Always return a defined index value.
4454 if (Parser
.getTok().is(AsmToken::LBrac
)) {
4455 Parser
.Lex(); // Eat the '['.
4456 if (Parser
.getTok().is(AsmToken::RBrac
)) {
4457 // "Dn[]" is the 'all lanes' syntax.
4458 LaneKind
= AllLanes
;
4459 EndLoc
= Parser
.getTok().getEndLoc();
4460 Parser
.Lex(); // Eat the ']'.
4461 return MatchOperand_Success
;
4464 // There's an optional '#' token here. Normally there wouldn't be, but
4465 // inline assemble puts one in, and it's friendly to accept that.
4466 if (Parser
.getTok().is(AsmToken::Hash
))
4467 Parser
.Lex(); // Eat '#' or '$'.
4469 const MCExpr
*LaneIndex
;
4470 SMLoc Loc
= Parser
.getTok().getLoc();
4471 if (getParser().parseExpression(LaneIndex
)) {
4472 Error(Loc
, "illegal expression");
4473 return MatchOperand_ParseFail
;
4475 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(LaneIndex
);
4477 Error(Loc
, "lane index must be empty or an integer");
4478 return MatchOperand_ParseFail
;
4480 if (Parser
.getTok().isNot(AsmToken::RBrac
)) {
4481 Error(Parser
.getTok().getLoc(), "']' expected");
4482 return MatchOperand_ParseFail
;
4484 EndLoc
= Parser
.getTok().getEndLoc();
4485 Parser
.Lex(); // Eat the ']'.
4486 int64_t Val
= CE
->getValue();
4488 // FIXME: Make this range check context sensitive for .8, .16, .32.
4489 if (Val
< 0 || Val
> 7) {
4490 Error(Parser
.getTok().getLoc(), "lane index out of range");
4491 return MatchOperand_ParseFail
;
4494 LaneKind
= IndexedLane
;
4495 return MatchOperand_Success
;
4498 return MatchOperand_Success
;
4501 // parse a vector register list
4502 OperandMatchResultTy
4503 ARMAsmParser::parseVectorList(OperandVector
&Operands
) {
4504 MCAsmParser
&Parser
= getParser();
4505 VectorLaneTy LaneKind
;
4507 SMLoc S
= Parser
.getTok().getLoc();
4508 // As an extension (to match gas), support a plain D register or Q register
4509 // (without encosing curly braces) as a single or double entry list,
4511 if (!hasMVE() && Parser
.getTok().is(AsmToken::Identifier
)) {
4512 SMLoc E
= Parser
.getTok().getEndLoc();
4513 int Reg
= tryParseRegister();
4515 return MatchOperand_NoMatch
;
4516 if (ARMMCRegisterClasses
[ARM::DPRRegClassID
].contains(Reg
)) {
4517 OperandMatchResultTy Res
= parseVectorLane(LaneKind
, LaneIndex
, E
);
4518 if (Res
!= MatchOperand_Success
)
4522 Operands
.push_back(ARMOperand::CreateVectorList(Reg
, 1, false, S
, E
));
4525 Operands
.push_back(ARMOperand::CreateVectorListAllLanes(Reg
, 1, false,
4529 Operands
.push_back(ARMOperand::CreateVectorListIndexed(Reg
, 1,
4534 return MatchOperand_Success
;
4536 if (ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(Reg
)) {
4537 Reg
= getDRegFromQReg(Reg
);
4538 OperandMatchResultTy Res
= parseVectorLane(LaneKind
, LaneIndex
, E
);
4539 if (Res
!= MatchOperand_Success
)
4543 Reg
= MRI
->getMatchingSuperReg(Reg
, ARM::dsub_0
,
4544 &ARMMCRegisterClasses
[ARM::DPairRegClassID
]);
4545 Operands
.push_back(ARMOperand::CreateVectorList(Reg
, 2, false, S
, E
));
4548 Reg
= MRI
->getMatchingSuperReg(Reg
, ARM::dsub_0
,
4549 &ARMMCRegisterClasses
[ARM::DPairRegClassID
]);
4550 Operands
.push_back(ARMOperand::CreateVectorListAllLanes(Reg
, 2, false,
4554 Operands
.push_back(ARMOperand::CreateVectorListIndexed(Reg
, 2,
4559 return MatchOperand_Success
;
4561 Error(S
, "vector register expected");
4562 return MatchOperand_ParseFail
;
4565 if (Parser
.getTok().isNot(AsmToken::LCurly
))
4566 return MatchOperand_NoMatch
;
4568 Parser
.Lex(); // Eat '{' token.
4569 SMLoc RegLoc
= Parser
.getTok().getLoc();
4571 int Reg
= tryParseRegister();
4573 Error(RegLoc
, "register expected");
4574 return MatchOperand_ParseFail
;
4578 unsigned FirstReg
= Reg
;
4580 if (hasMVE() && !ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(Reg
)) {
4581 Error(Parser
.getTok().getLoc(), "vector register in range Q0-Q7 expected");
4582 return MatchOperand_ParseFail
;
4584 // The list is of D registers, but we also allow Q regs and just interpret
4585 // them as the two D sub-registers.
4586 else if (!hasMVE() && ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(Reg
)) {
4587 FirstReg
= Reg
= getDRegFromQReg(Reg
);
4588 Spacing
= 1; // double-spacing requires explicit D registers, otherwise
4589 // it's ambiguous with four-register single spaced.
4595 if (parseVectorLane(LaneKind
, LaneIndex
, E
) != MatchOperand_Success
)
4596 return MatchOperand_ParseFail
;
4598 while (Parser
.getTok().is(AsmToken::Comma
) ||
4599 Parser
.getTok().is(AsmToken::Minus
)) {
4600 if (Parser
.getTok().is(AsmToken::Minus
)) {
4602 Spacing
= 1; // Register range implies a single spaced list.
4603 else if (Spacing
== 2) {
4604 Error(Parser
.getTok().getLoc(),
4605 "sequential registers in double spaced list");
4606 return MatchOperand_ParseFail
;
4608 Parser
.Lex(); // Eat the minus.
4609 SMLoc AfterMinusLoc
= Parser
.getTok().getLoc();
4610 int EndReg
= tryParseRegister();
4612 Error(AfterMinusLoc
, "register expected");
4613 return MatchOperand_ParseFail
;
4615 // Allow Q regs and just interpret them as the two D sub-registers.
4616 if (!hasMVE() && ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(EndReg
))
4617 EndReg
= getDRegFromQReg(EndReg
) + 1;
4618 // If the register is the same as the start reg, there's nothing
4622 // The register must be in the same register class as the first.
4624 !ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(EndReg
)) ||
4626 !ARMMCRegisterClasses
[ARM::DPRRegClassID
].contains(EndReg
))) {
4627 Error(AfterMinusLoc
, "invalid register in register list");
4628 return MatchOperand_ParseFail
;
4630 // Ranges must go from low to high.
4632 Error(AfterMinusLoc
, "bad range in register list");
4633 return MatchOperand_ParseFail
;
4635 // Parse the lane specifier if present.
4636 VectorLaneTy NextLaneKind
;
4637 unsigned NextLaneIndex
;
4638 if (parseVectorLane(NextLaneKind
, NextLaneIndex
, E
) !=
4639 MatchOperand_Success
)
4640 return MatchOperand_ParseFail
;
4641 if (NextLaneKind
!= LaneKind
|| LaneIndex
!= NextLaneIndex
) {
4642 Error(AfterMinusLoc
, "mismatched lane index in register list");
4643 return MatchOperand_ParseFail
;
4646 // Add all the registers in the range to the register list.
4647 Count
+= EndReg
- Reg
;
4651 Parser
.Lex(); // Eat the comma.
4652 RegLoc
= Parser
.getTok().getLoc();
4654 Reg
= tryParseRegister();
4656 Error(RegLoc
, "register expected");
4657 return MatchOperand_ParseFail
;
4661 if (!ARMMCRegisterClasses
[ARM::MQPRRegClassID
].contains(Reg
)) {
4662 Error(RegLoc
, "vector register in range Q0-Q7 expected");
4663 return MatchOperand_ParseFail
;
4667 // vector register lists must be contiguous.
4668 // It's OK to use the enumeration values directly here rather, as the
4669 // VFP register classes have the enum sorted properly.
4671 // The list is of D registers, but we also allow Q regs and just interpret
4672 // them as the two D sub-registers.
4673 else if (ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(Reg
)) {
4675 Spacing
= 1; // Register range implies a single spaced list.
4676 else if (Spacing
== 2) {
4678 "invalid register in double-spaced list (must be 'D' register')");
4679 return MatchOperand_ParseFail
;
4681 Reg
= getDRegFromQReg(Reg
);
4682 if (Reg
!= OldReg
+ 1) {
4683 Error(RegLoc
, "non-contiguous register range");
4684 return MatchOperand_ParseFail
;
4688 // Parse the lane specifier if present.
4689 VectorLaneTy NextLaneKind
;
4690 unsigned NextLaneIndex
;
4691 SMLoc LaneLoc
= Parser
.getTok().getLoc();
4692 if (parseVectorLane(NextLaneKind
, NextLaneIndex
, E
) !=
4693 MatchOperand_Success
)
4694 return MatchOperand_ParseFail
;
4695 if (NextLaneKind
!= LaneKind
|| LaneIndex
!= NextLaneIndex
) {
4696 Error(LaneLoc
, "mismatched lane index in register list");
4697 return MatchOperand_ParseFail
;
4701 // Normal D register.
4702 // Figure out the register spacing (single or double) of the list if
4703 // we don't know it already.
4705 Spacing
= 1 + (Reg
== OldReg
+ 2);
4707 // Just check that it's contiguous and keep going.
4708 if (Reg
!= OldReg
+ Spacing
) {
4709 Error(RegLoc
, "non-contiguous register range");
4710 return MatchOperand_ParseFail
;
4713 // Parse the lane specifier if present.
4714 VectorLaneTy NextLaneKind
;
4715 unsigned NextLaneIndex
;
4716 SMLoc EndLoc
= Parser
.getTok().getLoc();
4717 if (parseVectorLane(NextLaneKind
, NextLaneIndex
, E
) != MatchOperand_Success
)
4718 return MatchOperand_ParseFail
;
4719 if (NextLaneKind
!= LaneKind
|| LaneIndex
!= NextLaneIndex
) {
4720 Error(EndLoc
, "mismatched lane index in register list");
4721 return MatchOperand_ParseFail
;
4725 if (Parser
.getTok().isNot(AsmToken::RCurly
)) {
4726 Error(Parser
.getTok().getLoc(), "'}' expected");
4727 return MatchOperand_ParseFail
;
4729 E
= Parser
.getTok().getEndLoc();
4730 Parser
.Lex(); // Eat '}' token.
4735 // Two-register operands have been converted to the
4736 // composite register classes.
4737 if (Count
== 2 && !hasMVE()) {
4738 const MCRegisterClass
*RC
= (Spacing
== 1) ?
4739 &ARMMCRegisterClasses
[ARM::DPairRegClassID
] :
4740 &ARMMCRegisterClasses
[ARM::DPairSpcRegClassID
];
4741 FirstReg
= MRI
->getMatchingSuperReg(FirstReg
, ARM::dsub_0
, RC
);
4743 auto Create
= (LaneKind
== NoLanes
? ARMOperand::CreateVectorList
:
4744 ARMOperand::CreateVectorListAllLanes
);
4745 Operands
.push_back(Create(FirstReg
, Count
, (Spacing
== 2), S
, E
));
4749 Operands
.push_back(ARMOperand::CreateVectorListIndexed(FirstReg
, Count
,
4755 return MatchOperand_Success
;
4758 /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
4759 OperandMatchResultTy
4760 ARMAsmParser::parseMemBarrierOptOperand(OperandVector
&Operands
) {
4761 MCAsmParser
&Parser
= getParser();
4762 SMLoc S
= Parser
.getTok().getLoc();
4763 const AsmToken
&Tok
= Parser
.getTok();
4766 if (Tok
.is(AsmToken::Identifier
)) {
4767 StringRef OptStr
= Tok
.getString();
4769 Opt
= StringSwitch
<unsigned>(OptStr
.slice(0, OptStr
.size()).lower())
4770 .Case("sy", ARM_MB::SY
)
4771 .Case("st", ARM_MB::ST
)
4772 .Case("ld", ARM_MB::LD
)
4773 .Case("sh", ARM_MB::ISH
)
4774 .Case("ish", ARM_MB::ISH
)
4775 .Case("shst", ARM_MB::ISHST
)
4776 .Case("ishst", ARM_MB::ISHST
)
4777 .Case("ishld", ARM_MB::ISHLD
)
4778 .Case("nsh", ARM_MB::NSH
)
4779 .Case("un", ARM_MB::NSH
)
4780 .Case("nshst", ARM_MB::NSHST
)
4781 .Case("nshld", ARM_MB::NSHLD
)
4782 .Case("unst", ARM_MB::NSHST
)
4783 .Case("osh", ARM_MB::OSH
)
4784 .Case("oshst", ARM_MB::OSHST
)
4785 .Case("oshld", ARM_MB::OSHLD
)
4788 // ishld, oshld, nshld and ld are only available from ARMv8.
4789 if (!hasV8Ops() && (Opt
== ARM_MB::ISHLD
|| Opt
== ARM_MB::OSHLD
||
4790 Opt
== ARM_MB::NSHLD
|| Opt
== ARM_MB::LD
))
4794 return MatchOperand_NoMatch
;
4796 Parser
.Lex(); // Eat identifier token.
4797 } else if (Tok
.is(AsmToken::Hash
) ||
4798 Tok
.is(AsmToken::Dollar
) ||
4799 Tok
.is(AsmToken::Integer
)) {
4800 if (Parser
.getTok().isNot(AsmToken::Integer
))
4801 Parser
.Lex(); // Eat '#' or '$'.
4802 SMLoc Loc
= Parser
.getTok().getLoc();
4804 const MCExpr
*MemBarrierID
;
4805 if (getParser().parseExpression(MemBarrierID
)) {
4806 Error(Loc
, "illegal expression");
4807 return MatchOperand_ParseFail
;
4810 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(MemBarrierID
);
4812 Error(Loc
, "constant expression expected");
4813 return MatchOperand_ParseFail
;
4816 int Val
= CE
->getValue();
4818 Error(Loc
, "immediate value out of range");
4819 return MatchOperand_ParseFail
;
4822 Opt
= ARM_MB::RESERVED_0
+ Val
;
4824 return MatchOperand_ParseFail
;
4826 Operands
.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt
)Opt
, S
));
4827 return MatchOperand_Success
;
4830 OperandMatchResultTy
4831 ARMAsmParser::parseTraceSyncBarrierOptOperand(OperandVector
&Operands
) {
4832 MCAsmParser
&Parser
= getParser();
4833 SMLoc S
= Parser
.getTok().getLoc();
4834 const AsmToken
&Tok
= Parser
.getTok();
4836 if (Tok
.isNot(AsmToken::Identifier
))
4837 return MatchOperand_NoMatch
;
4839 if (!Tok
.getString().equals_lower("csync"))
4840 return MatchOperand_NoMatch
;
4842 Parser
.Lex(); // Eat identifier token.
4844 Operands
.push_back(ARMOperand::CreateTraceSyncBarrierOpt(ARM_TSB::CSYNC
, S
));
4845 return MatchOperand_Success
;
4848 /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
4849 OperandMatchResultTy
4850 ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector
&Operands
) {
4851 MCAsmParser
&Parser
= getParser();
4852 SMLoc S
= Parser
.getTok().getLoc();
4853 const AsmToken
&Tok
= Parser
.getTok();
4856 if (Tok
.is(AsmToken::Identifier
)) {
4857 StringRef OptStr
= Tok
.getString();
4859 if (OptStr
.equals_lower("sy"))
4862 return MatchOperand_NoMatch
;
4864 Parser
.Lex(); // Eat identifier token.
4865 } else if (Tok
.is(AsmToken::Hash
) ||
4866 Tok
.is(AsmToken::Dollar
) ||
4867 Tok
.is(AsmToken::Integer
)) {
4868 if (Parser
.getTok().isNot(AsmToken::Integer
))
4869 Parser
.Lex(); // Eat '#' or '$'.
4870 SMLoc Loc
= Parser
.getTok().getLoc();
4872 const MCExpr
*ISBarrierID
;
4873 if (getParser().parseExpression(ISBarrierID
)) {
4874 Error(Loc
, "illegal expression");
4875 return MatchOperand_ParseFail
;
4878 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(ISBarrierID
);
4880 Error(Loc
, "constant expression expected");
4881 return MatchOperand_ParseFail
;
4884 int Val
= CE
->getValue();
4886 Error(Loc
, "immediate value out of range");
4887 return MatchOperand_ParseFail
;
4890 Opt
= ARM_ISB::RESERVED_0
+ Val
;
4892 return MatchOperand_ParseFail
;
4894 Operands
.push_back(ARMOperand::CreateInstSyncBarrierOpt(
4895 (ARM_ISB::InstSyncBOpt
)Opt
, S
));
4896 return MatchOperand_Success
;
4900 /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
4901 OperandMatchResultTy
4902 ARMAsmParser::parseProcIFlagsOperand(OperandVector
&Operands
) {
4903 MCAsmParser
&Parser
= getParser();
4904 SMLoc S
= Parser
.getTok().getLoc();
4905 const AsmToken
&Tok
= Parser
.getTok();
4906 if (!Tok
.is(AsmToken::Identifier
))
4907 return MatchOperand_NoMatch
;
4908 StringRef IFlagsStr
= Tok
.getString();
4910 // An iflags string of "none" is interpreted to mean that none of the AIF
4911 // bits are set. Not a terribly useful instruction, but a valid encoding.
4912 unsigned IFlags
= 0;
4913 if (IFlagsStr
!= "none") {
4914 for (int i
= 0, e
= IFlagsStr
.size(); i
!= e
; ++i
) {
4915 unsigned Flag
= StringSwitch
<unsigned>(IFlagsStr
.substr(i
, 1).lower())
4916 .Case("a", ARM_PROC::A
)
4917 .Case("i", ARM_PROC::I
)
4918 .Case("f", ARM_PROC::F
)
4921 // If some specific iflag is already set, it means that some letter is
4922 // present more than once, this is not acceptable.
4923 if (Flag
== ~0U || (IFlags
& Flag
))
4924 return MatchOperand_NoMatch
;
4930 Parser
.Lex(); // Eat identifier token.
4931 Operands
.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags
)IFlags
, S
));
4932 return MatchOperand_Success
;
4935 /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
4936 OperandMatchResultTy
4937 ARMAsmParser::parseMSRMaskOperand(OperandVector
&Operands
) {
4938 MCAsmParser
&Parser
= getParser();
4939 SMLoc S
= Parser
.getTok().getLoc();
4940 const AsmToken
&Tok
= Parser
.getTok();
4942 if (Tok
.is(AsmToken::Integer
)) {
4943 int64_t Val
= Tok
.getIntVal();
4944 if (Val
> 255 || Val
< 0) {
4945 return MatchOperand_NoMatch
;
4947 unsigned SYSmvalue
= Val
& 0xFF;
4949 Operands
.push_back(ARMOperand::CreateMSRMask(SYSmvalue
, S
));
4950 return MatchOperand_Success
;
4953 if (!Tok
.is(AsmToken::Identifier
))
4954 return MatchOperand_NoMatch
;
4955 StringRef Mask
= Tok
.getString();
4958 auto TheReg
= ARMSysReg::lookupMClassSysRegByName(Mask
.lower());
4959 if (!TheReg
|| !TheReg
->hasRequiredFeatures(getSTI().getFeatureBits()))
4960 return MatchOperand_NoMatch
;
4962 unsigned SYSmvalue
= TheReg
->Encoding
& 0xFFF;
4964 Parser
.Lex(); // Eat identifier token.
4965 Operands
.push_back(ARMOperand::CreateMSRMask(SYSmvalue
, S
));
4966 return MatchOperand_Success
;
4969 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
4970 size_t Start
= 0, Next
= Mask
.find('_');
4971 StringRef Flags
= "";
4972 std::string SpecReg
= Mask
.slice(Start
, Next
).lower();
4973 if (Next
!= StringRef::npos
)
4974 Flags
= Mask
.slice(Next
+1, Mask
.size());
4976 // FlagsVal contains the complete mask:
4978 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4979 unsigned FlagsVal
= 0;
4981 if (SpecReg
== "apsr") {
4982 FlagsVal
= StringSwitch
<unsigned>(Flags
)
4983 .Case("nzcvq", 0x8) // same as CPSR_f
4984 .Case("g", 0x4) // same as CPSR_s
4985 .Case("nzcvqg", 0xc) // same as CPSR_fs
4988 if (FlagsVal
== ~0U) {
4990 return MatchOperand_NoMatch
;
4992 FlagsVal
= 8; // No flag
4994 } else if (SpecReg
== "cpsr" || SpecReg
== "spsr") {
4995 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4996 if (Flags
== "all" || Flags
== "")
4998 for (int i
= 0, e
= Flags
.size(); i
!= e
; ++i
) {
4999 unsigned Flag
= StringSwitch
<unsigned>(Flags
.substr(i
, 1))
5006 // If some specific flag is already set, it means that some letter is
5007 // present more than once, this is not acceptable.
5008 if (Flag
== ~0U || (FlagsVal
& Flag
))
5009 return MatchOperand_NoMatch
;
5012 } else // No match for special register.
5013 return MatchOperand_NoMatch
;
5015 // Special register without flags is NOT equivalent to "fc" flags.
5016 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
5017 // two lines would enable gas compatibility at the expense of breaking
5023 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
5024 if (SpecReg
== "spsr")
5027 Parser
.Lex(); // Eat identifier token.
5028 Operands
.push_back(ARMOperand::CreateMSRMask(FlagsVal
, S
));
5029 return MatchOperand_Success
;
5032 /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
5033 /// use in the MRS/MSR instructions added to support virtualization.
5034 OperandMatchResultTy
5035 ARMAsmParser::parseBankedRegOperand(OperandVector
&Operands
) {
5036 MCAsmParser
&Parser
= getParser();
5037 SMLoc S
= Parser
.getTok().getLoc();
5038 const AsmToken
&Tok
= Parser
.getTok();
5039 if (!Tok
.is(AsmToken::Identifier
))
5040 return MatchOperand_NoMatch
;
5041 StringRef RegName
= Tok
.getString();
5043 auto TheReg
= ARMBankedReg::lookupBankedRegByName(RegName
.lower());
5045 return MatchOperand_NoMatch
;
5046 unsigned Encoding
= TheReg
->Encoding
;
5048 Parser
.Lex(); // Eat identifier token.
5049 Operands
.push_back(ARMOperand::CreateBankedReg(Encoding
, S
));
5050 return MatchOperand_Success
;
5053 OperandMatchResultTy
5054 ARMAsmParser::parsePKHImm(OperandVector
&Operands
, StringRef Op
, int Low
,
5056 MCAsmParser
&Parser
= getParser();
5057 const AsmToken
&Tok
= Parser
.getTok();
5058 if (Tok
.isNot(AsmToken::Identifier
)) {
5059 Error(Parser
.getTok().getLoc(), Op
+ " operand expected.");
5060 return MatchOperand_ParseFail
;
5062 StringRef ShiftName
= Tok
.getString();
5063 std::string LowerOp
= Op
.lower();
5064 std::string UpperOp
= Op
.upper();
5065 if (ShiftName
!= LowerOp
&& ShiftName
!= UpperOp
) {
5066 Error(Parser
.getTok().getLoc(), Op
+ " operand expected.");
5067 return MatchOperand_ParseFail
;
5069 Parser
.Lex(); // Eat shift type token.
5071 // There must be a '#' and a shift amount.
5072 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
5073 Parser
.getTok().isNot(AsmToken::Dollar
)) {
5074 Error(Parser
.getTok().getLoc(), "'#' expected");
5075 return MatchOperand_ParseFail
;
5077 Parser
.Lex(); // Eat hash token.
5079 const MCExpr
*ShiftAmount
;
5080 SMLoc Loc
= Parser
.getTok().getLoc();
5082 if (getParser().parseExpression(ShiftAmount
, EndLoc
)) {
5083 Error(Loc
, "illegal expression");
5084 return MatchOperand_ParseFail
;
5086 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(ShiftAmount
);
5088 Error(Loc
, "constant expression expected");
5089 return MatchOperand_ParseFail
;
5091 int Val
= CE
->getValue();
5092 if (Val
< Low
|| Val
> High
) {
5093 Error(Loc
, "immediate value out of range");
5094 return MatchOperand_ParseFail
;
5097 Operands
.push_back(ARMOperand::CreateImm(CE
, Loc
, EndLoc
));
5099 return MatchOperand_Success
;
5102 OperandMatchResultTy
5103 ARMAsmParser::parseSetEndImm(OperandVector
&Operands
) {
5104 MCAsmParser
&Parser
= getParser();
5105 const AsmToken
&Tok
= Parser
.getTok();
5106 SMLoc S
= Tok
.getLoc();
5107 if (Tok
.isNot(AsmToken::Identifier
)) {
5108 Error(S
, "'be' or 'le' operand expected");
5109 return MatchOperand_ParseFail
;
5111 int Val
= StringSwitch
<int>(Tok
.getString().lower())
5115 Parser
.Lex(); // Eat the token.
5118 Error(S
, "'be' or 'le' operand expected");
5119 return MatchOperand_ParseFail
;
5121 Operands
.push_back(ARMOperand::CreateImm(MCConstantExpr::create(Val
,
5123 S
, Tok
.getEndLoc()));
5124 return MatchOperand_Success
;
5127 /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
5128 /// instructions. Legal values are:
5129 /// lsl #n 'n' in [0,31]
5130 /// asr #n 'n' in [1,32]
5131 /// n == 32 encoded as n == 0.
5132 OperandMatchResultTy
5133 ARMAsmParser::parseShifterImm(OperandVector
&Operands
) {
5134 MCAsmParser
&Parser
= getParser();
5135 const AsmToken
&Tok
= Parser
.getTok();
5136 SMLoc S
= Tok
.getLoc();
5137 if (Tok
.isNot(AsmToken::Identifier
)) {
5138 Error(S
, "shift operator 'asr' or 'lsl' expected");
5139 return MatchOperand_ParseFail
;
5141 StringRef ShiftName
= Tok
.getString();
5143 if (ShiftName
== "lsl" || ShiftName
== "LSL")
5145 else if (ShiftName
== "asr" || ShiftName
== "ASR")
5148 Error(S
, "shift operator 'asr' or 'lsl' expected");
5149 return MatchOperand_ParseFail
;
5151 Parser
.Lex(); // Eat the operator.
5153 // A '#' and a shift amount.
5154 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
5155 Parser
.getTok().isNot(AsmToken::Dollar
)) {
5156 Error(Parser
.getTok().getLoc(), "'#' expected");
5157 return MatchOperand_ParseFail
;
5159 Parser
.Lex(); // Eat hash token.
5160 SMLoc ExLoc
= Parser
.getTok().getLoc();
5162 const MCExpr
*ShiftAmount
;
5164 if (getParser().parseExpression(ShiftAmount
, EndLoc
)) {
5165 Error(ExLoc
, "malformed shift expression");
5166 return MatchOperand_ParseFail
;
5168 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(ShiftAmount
);
5170 Error(ExLoc
, "shift amount must be an immediate");
5171 return MatchOperand_ParseFail
;
5174 int64_t Val
= CE
->getValue();
5176 // Shift amount must be in [1,32]
5177 if (Val
< 1 || Val
> 32) {
5178 Error(ExLoc
, "'asr' shift amount must be in range [1,32]");
5179 return MatchOperand_ParseFail
;
5181 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
5182 if (isThumb() && Val
== 32) {
5183 Error(ExLoc
, "'asr #32' shift amount not allowed in Thumb mode");
5184 return MatchOperand_ParseFail
;
5186 if (Val
== 32) Val
= 0;
5188 // Shift amount must be in [1,32]
5189 if (Val
< 0 || Val
> 31) {
5190 Error(ExLoc
, "'lsr' shift amount must be in range [0,31]");
5191 return MatchOperand_ParseFail
;
5195 Operands
.push_back(ARMOperand::CreateShifterImm(isASR
, Val
, S
, EndLoc
));
5197 return MatchOperand_Success
;
5200 /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
5201 /// of instructions. Legal values are:
5202 /// ror #n 'n' in {0, 8, 16, 24}
5203 OperandMatchResultTy
5204 ARMAsmParser::parseRotImm(OperandVector
&Operands
) {
5205 MCAsmParser
&Parser
= getParser();
5206 const AsmToken
&Tok
= Parser
.getTok();
5207 SMLoc S
= Tok
.getLoc();
5208 if (Tok
.isNot(AsmToken::Identifier
))
5209 return MatchOperand_NoMatch
;
5210 StringRef ShiftName
= Tok
.getString();
5211 if (ShiftName
!= "ror" && ShiftName
!= "ROR")
5212 return MatchOperand_NoMatch
;
5213 Parser
.Lex(); // Eat the operator.
5215 // A '#' and a rotate amount.
5216 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
5217 Parser
.getTok().isNot(AsmToken::Dollar
)) {
5218 Error(Parser
.getTok().getLoc(), "'#' expected");
5219 return MatchOperand_ParseFail
;
5221 Parser
.Lex(); // Eat hash token.
5222 SMLoc ExLoc
= Parser
.getTok().getLoc();
5224 const MCExpr
*ShiftAmount
;
5226 if (getParser().parseExpression(ShiftAmount
, EndLoc
)) {
5227 Error(ExLoc
, "malformed rotate expression");
5228 return MatchOperand_ParseFail
;
5230 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(ShiftAmount
);
5232 Error(ExLoc
, "rotate amount must be an immediate");
5233 return MatchOperand_ParseFail
;
5236 int64_t Val
= CE
->getValue();
5237 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
5238 // normally, zero is represented in asm by omitting the rotate operand
5240 if (Val
!= 8 && Val
!= 16 && Val
!= 24 && Val
!= 0) {
5241 Error(ExLoc
, "'ror' rotate amount must be 8, 16, or 24");
5242 return MatchOperand_ParseFail
;
5245 Operands
.push_back(ARMOperand::CreateRotImm(Val
, S
, EndLoc
));
5247 return MatchOperand_Success
;
5250 OperandMatchResultTy
5251 ARMAsmParser::parseModImm(OperandVector
&Operands
) {
5252 MCAsmParser
&Parser
= getParser();
5253 MCAsmLexer
&Lexer
= getLexer();
5256 SMLoc S
= Parser
.getTok().getLoc();
5258 // 1) A mod_imm operand can appear in the place of a register name:
5260 // add r0, r0, #mod_imm
5261 // to correctly handle the latter, we bail out as soon as we see an
5264 // 2) Similarly, we do not want to parse into complex operands:
5266 // mov r0, :lower16:(_foo)
5267 if (Parser
.getTok().is(AsmToken::Identifier
) ||
5268 Parser
.getTok().is(AsmToken::Colon
))
5269 return MatchOperand_NoMatch
;
5271 // Hash (dollar) is optional as per the ARMARM
5272 if (Parser
.getTok().is(AsmToken::Hash
) ||
5273 Parser
.getTok().is(AsmToken::Dollar
)) {
5274 // Avoid parsing into complex operands (#:)
5275 if (Lexer
.peekTok().is(AsmToken::Colon
))
5276 return MatchOperand_NoMatch
;
5278 // Eat the hash (dollar)
5283 Sx1
= Parser
.getTok().getLoc();
5284 const MCExpr
*Imm1Exp
;
5285 if (getParser().parseExpression(Imm1Exp
, Ex1
)) {
5286 Error(Sx1
, "malformed expression");
5287 return MatchOperand_ParseFail
;
5290 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Imm1Exp
);
5293 // Immediate must fit within 32-bits
5294 Imm1
= CE
->getValue();
5295 int Enc
= ARM_AM::getSOImmVal(Imm1
);
5296 if (Enc
!= -1 && Parser
.getTok().is(AsmToken::EndOfStatement
)) {
5298 Operands
.push_back(ARMOperand::CreateModImm((Enc
& 0xFF),
5301 return MatchOperand_Success
;
5304 // We have parsed an immediate which is not for us, fallback to a plain
5305 // immediate. This can happen for instruction aliases. For an example,
5306 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
5307 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
5308 // instruction with a mod_imm operand. The alias is defined such that the
5309 // parser method is shared, that's why we have to do this here.
5310 if (Parser
.getTok().is(AsmToken::EndOfStatement
)) {
5311 Operands
.push_back(ARMOperand::CreateImm(Imm1Exp
, Sx1
, Ex1
));
5312 return MatchOperand_Success
;
5315 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
5316 // MCFixup). Fallback to a plain immediate.
5317 Operands
.push_back(ARMOperand::CreateImm(Imm1Exp
, Sx1
, Ex1
));
5318 return MatchOperand_Success
;
5321 // From this point onward, we expect the input to be a (#bits, #rot) pair
5322 if (Parser
.getTok().isNot(AsmToken::Comma
)) {
5323 Error(Sx1
, "expected modified immediate operand: #[0, 255], #even[0-30]");
5324 return MatchOperand_ParseFail
;
5328 Error(Sx1
, "immediate operand must a number in the range [0, 255]");
5329 return MatchOperand_ParseFail
;
5337 Sx2
= Parser
.getTok().getLoc();
5339 // Eat the optional hash (dollar)
5340 if (Parser
.getTok().is(AsmToken::Hash
) ||
5341 Parser
.getTok().is(AsmToken::Dollar
))
5344 const MCExpr
*Imm2Exp
;
5345 if (getParser().parseExpression(Imm2Exp
, Ex2
)) {
5346 Error(Sx2
, "malformed expression");
5347 return MatchOperand_ParseFail
;
5350 CE
= dyn_cast
<MCConstantExpr
>(Imm2Exp
);
5353 Imm2
= CE
->getValue();
5354 if (!(Imm2
& ~0x1E)) {
5356 Operands
.push_back(ARMOperand::CreateModImm(Imm1
, Imm2
, S
, Ex2
));
5357 return MatchOperand_Success
;
5359 Error(Sx2
, "immediate operand must an even number in the range [0, 30]");
5360 return MatchOperand_ParseFail
;
5362 Error(Sx2
, "constant expression expected");
5363 return MatchOperand_ParseFail
;
5367 OperandMatchResultTy
5368 ARMAsmParser::parseBitfield(OperandVector
&Operands
) {
5369 MCAsmParser
&Parser
= getParser();
5370 SMLoc S
= Parser
.getTok().getLoc();
5371 // The bitfield descriptor is really two operands, the LSB and the width.
5372 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
5373 Parser
.getTok().isNot(AsmToken::Dollar
)) {
5374 Error(Parser
.getTok().getLoc(), "'#' expected");
5375 return MatchOperand_ParseFail
;
5377 Parser
.Lex(); // Eat hash token.
5379 const MCExpr
*LSBExpr
;
5380 SMLoc E
= Parser
.getTok().getLoc();
5381 if (getParser().parseExpression(LSBExpr
)) {
5382 Error(E
, "malformed immediate expression");
5383 return MatchOperand_ParseFail
;
5385 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(LSBExpr
);
5387 Error(E
, "'lsb' operand must be an immediate");
5388 return MatchOperand_ParseFail
;
5391 int64_t LSB
= CE
->getValue();
5392 // The LSB must be in the range [0,31]
5393 if (LSB
< 0 || LSB
> 31) {
5394 Error(E
, "'lsb' operand must be in the range [0,31]");
5395 return MatchOperand_ParseFail
;
5397 E
= Parser
.getTok().getLoc();
5399 // Expect another immediate operand.
5400 if (Parser
.getTok().isNot(AsmToken::Comma
)) {
5401 Error(Parser
.getTok().getLoc(), "too few operands");
5402 return MatchOperand_ParseFail
;
5404 Parser
.Lex(); // Eat hash token.
5405 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
5406 Parser
.getTok().isNot(AsmToken::Dollar
)) {
5407 Error(Parser
.getTok().getLoc(), "'#' expected");
5408 return MatchOperand_ParseFail
;
5410 Parser
.Lex(); // Eat hash token.
5412 const MCExpr
*WidthExpr
;
5414 if (getParser().parseExpression(WidthExpr
, EndLoc
)) {
5415 Error(E
, "malformed immediate expression");
5416 return MatchOperand_ParseFail
;
5418 CE
= dyn_cast
<MCConstantExpr
>(WidthExpr
);
5420 Error(E
, "'width' operand must be an immediate");
5421 return MatchOperand_ParseFail
;
5424 int64_t Width
= CE
->getValue();
5425 // The LSB must be in the range [1,32-lsb]
5426 if (Width
< 1 || Width
> 32 - LSB
) {
5427 Error(E
, "'width' operand must be in the range [1,32-lsb]");
5428 return MatchOperand_ParseFail
;
5431 Operands
.push_back(ARMOperand::CreateBitfield(LSB
, Width
, S
, EndLoc
));
5433 return MatchOperand_Success
;
5436 OperandMatchResultTy
5437 ARMAsmParser::parsePostIdxReg(OperandVector
&Operands
) {
5438 // Check for a post-index addressing register operand. Specifically:
5439 // postidx_reg := '+' register {, shift}
5440 // | '-' register {, shift}
5441 // | register {, shift}
5443 // This method must return MatchOperand_NoMatch without consuming any tokens
5444 // in the case where there is no match, as other alternatives take other
5446 MCAsmParser
&Parser
= getParser();
5447 AsmToken Tok
= Parser
.getTok();
5448 SMLoc S
= Tok
.getLoc();
5449 bool haveEaten
= false;
5451 if (Tok
.is(AsmToken::Plus
)) {
5452 Parser
.Lex(); // Eat the '+' token.
5454 } else if (Tok
.is(AsmToken::Minus
)) {
5455 Parser
.Lex(); // Eat the '-' token.
5460 SMLoc E
= Parser
.getTok().getEndLoc();
5461 int Reg
= tryParseRegister();
5464 return MatchOperand_NoMatch
;
5465 Error(Parser
.getTok().getLoc(), "register expected");
5466 return MatchOperand_ParseFail
;
5469 ARM_AM::ShiftOpc ShiftTy
= ARM_AM::no_shift
;
5470 unsigned ShiftImm
= 0;
5471 if (Parser
.getTok().is(AsmToken::Comma
)) {
5472 Parser
.Lex(); // Eat the ','.
5473 if (parseMemRegOffsetShift(ShiftTy
, ShiftImm
))
5474 return MatchOperand_ParseFail
;
5476 // FIXME: Only approximates end...may include intervening whitespace.
5477 E
= Parser
.getTok().getLoc();
5480 Operands
.push_back(ARMOperand::CreatePostIdxReg(Reg
, isAdd
, ShiftTy
,
5483 return MatchOperand_Success
;
5486 OperandMatchResultTy
5487 ARMAsmParser::parseAM3Offset(OperandVector
&Operands
) {
5488 // Check for a post-index addressing register operand. Specifically:
5489 // am3offset := '+' register
5496 // This method must return MatchOperand_NoMatch without consuming any tokens
5497 // in the case where there is no match, as other alternatives take other
5499 MCAsmParser
&Parser
= getParser();
5500 AsmToken Tok
= Parser
.getTok();
5501 SMLoc S
= Tok
.getLoc();
5503 // Do immediates first, as we always parse those if we have a '#'.
5504 if (Parser
.getTok().is(AsmToken::Hash
) ||
5505 Parser
.getTok().is(AsmToken::Dollar
)) {
5506 Parser
.Lex(); // Eat '#' or '$'.
5507 // Explicitly look for a '-', as we need to encode negative zero
5509 bool isNegative
= Parser
.getTok().is(AsmToken::Minus
);
5510 const MCExpr
*Offset
;
5512 if (getParser().parseExpression(Offset
, E
))
5513 return MatchOperand_ParseFail
;
5514 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Offset
);
5516 Error(S
, "constant expression expected");
5517 return MatchOperand_ParseFail
;
5519 // Negative zero is encoded as the flag value
5520 // std::numeric_limits<int32_t>::min().
5521 int32_t Val
= CE
->getValue();
5522 if (isNegative
&& Val
== 0)
5523 Val
= std::numeric_limits
<int32_t>::min();
5526 ARMOperand::CreateImm(MCConstantExpr::create(Val
, getContext()), S
, E
));
5528 return MatchOperand_Success
;
5531 bool haveEaten
= false;
5533 if (Tok
.is(AsmToken::Plus
)) {
5534 Parser
.Lex(); // Eat the '+' token.
5536 } else if (Tok
.is(AsmToken::Minus
)) {
5537 Parser
.Lex(); // Eat the '-' token.
5542 Tok
= Parser
.getTok();
5543 int Reg
= tryParseRegister();
5546 return MatchOperand_NoMatch
;
5547 Error(Tok
.getLoc(), "register expected");
5548 return MatchOperand_ParseFail
;
5551 Operands
.push_back(ARMOperand::CreatePostIdxReg(Reg
, isAdd
, ARM_AM::no_shift
,
5552 0, S
, Tok
.getEndLoc()));
5554 return MatchOperand_Success
;
5557 /// Convert parsed operands to MCInst. Needed here because this instruction
5558 /// only has two register operands, but multiplication is commutative so
5559 /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
5560 void ARMAsmParser::cvtThumbMultiply(MCInst
&Inst
,
5561 const OperandVector
&Operands
) {
5562 ((ARMOperand
&)*Operands
[3]).addRegOperands(Inst
, 1);
5563 ((ARMOperand
&)*Operands
[1]).addCCOutOperands(Inst
, 1);
5564 // If we have a three-operand form, make sure to set Rn to be the operand
5565 // that isn't the same as Rd.
5567 if (Operands
.size() == 6 &&
5568 ((ARMOperand
&)*Operands
[4]).getReg() ==
5569 ((ARMOperand
&)*Operands
[3]).getReg())
5571 ((ARMOperand
&)*Operands
[RegOp
]).addRegOperands(Inst
, 1);
5572 Inst
.addOperand(Inst
.getOperand(0));
5573 ((ARMOperand
&)*Operands
[2]).addCondCodeOperands(Inst
, 2);
5576 void ARMAsmParser::cvtThumbBranches(MCInst
&Inst
,
5577 const OperandVector
&Operands
) {
5578 int CondOp
= -1, ImmOp
= -1;
5579 switch(Inst
.getOpcode()) {
5581 case ARM::tBcc
: CondOp
= 1; ImmOp
= 2; break;
5584 case ARM::t2Bcc
: CondOp
= 1; ImmOp
= 3; break;
5586 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
5588 // first decide whether or not the branch should be conditional
5589 // by looking at it's location relative to an IT block
5591 // inside an IT block we cannot have any conditional branches. any
5592 // such instructions needs to be converted to unconditional form
5593 switch(Inst
.getOpcode()) {
5594 case ARM::tBcc
: Inst
.setOpcode(ARM::tB
); break;
5595 case ARM::t2Bcc
: Inst
.setOpcode(ARM::t2B
); break;
5598 // outside IT blocks we can only have unconditional branches with AL
5599 // condition code or conditional branches with non-AL condition code
5600 unsigned Cond
= static_cast<ARMOperand
&>(*Operands
[CondOp
]).getCondCode();
5601 switch(Inst
.getOpcode()) {
5604 Inst
.setOpcode(Cond
== ARMCC::AL
? ARM::tB
: ARM::tBcc
);
5608 Inst
.setOpcode(Cond
== ARMCC::AL
? ARM::t2B
: ARM::t2Bcc
);
5613 // now decide on encoding size based on branch target range
5614 switch(Inst
.getOpcode()) {
5615 // classify tB as either t2B or t1B based on range of immediate operand
5617 ARMOperand
&op
= static_cast<ARMOperand
&>(*Operands
[ImmOp
]);
5618 if (!op
.isSignedOffset
<11, 1>() && isThumb() && hasV8MBaseline())
5619 Inst
.setOpcode(ARM::t2B
);
5622 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
5624 ARMOperand
&op
= static_cast<ARMOperand
&>(*Operands
[ImmOp
]);
5625 if (!op
.isSignedOffset
<8, 1>() && isThumb() && hasV8MBaseline())
5626 Inst
.setOpcode(ARM::t2Bcc
);
5630 ((ARMOperand
&)*Operands
[ImmOp
]).addImmOperands(Inst
, 1);
5631 ((ARMOperand
&)*Operands
[CondOp
]).addCondCodeOperands(Inst
, 2);
5634 void ARMAsmParser::cvtMVEVMOVQtoDReg(
5635 MCInst
&Inst
, const OperandVector
&Operands
) {
5637 // mnemonic, condition code, Rt, Rt2, Qd, idx, Qd again, idx2
5638 assert(Operands
.size() == 8);
5640 ((ARMOperand
&)*Operands
[2]).addRegOperands(Inst
, 1); // Rt
5641 ((ARMOperand
&)*Operands
[3]).addRegOperands(Inst
, 1); // Rt2
5642 ((ARMOperand
&)*Operands
[4]).addRegOperands(Inst
, 1); // Qd
5643 ((ARMOperand
&)*Operands
[5]).addMVEPairVectorIndexOperands(Inst
, 1); // idx
5644 // skip second copy of Qd in Operands[6]
5645 ((ARMOperand
&)*Operands
[7]).addMVEPairVectorIndexOperands(Inst
, 1); // idx2
5646 ((ARMOperand
&)*Operands
[1]).addCondCodeOperands(Inst
, 2); // condition code
5649 /// Parse an ARM memory expression, return false if successful else return true
5650 /// or an error. The first token must be a '[' when called.
5651 bool ARMAsmParser::parseMemory(OperandVector
&Operands
) {
5652 MCAsmParser
&Parser
= getParser();
5654 if (Parser
.getTok().isNot(AsmToken::LBrac
))
5655 return TokError("Token is not a Left Bracket");
5656 S
= Parser
.getTok().getLoc();
5657 Parser
.Lex(); // Eat left bracket token.
5659 const AsmToken
&BaseRegTok
= Parser
.getTok();
5660 int BaseRegNum
= tryParseRegister();
5661 if (BaseRegNum
== -1)
5662 return Error(BaseRegTok
.getLoc(), "register expected");
5664 // The next token must either be a comma, a colon or a closing bracket.
5665 const AsmToken
&Tok
= Parser
.getTok();
5666 if (!Tok
.is(AsmToken::Colon
) && !Tok
.is(AsmToken::Comma
) &&
5667 !Tok
.is(AsmToken::RBrac
))
5668 return Error(Tok
.getLoc(), "malformed memory operand");
5670 if (Tok
.is(AsmToken::RBrac
)) {
5671 E
= Tok
.getEndLoc();
5672 Parser
.Lex(); // Eat right bracket token.
5674 Operands
.push_back(ARMOperand::CreateMem(BaseRegNum
, nullptr, 0,
5675 ARM_AM::no_shift
, 0, 0, false,
5678 // If there's a pre-indexing writeback marker, '!', just add it as a token
5679 // operand. It's rather odd, but syntactically valid.
5680 if (Parser
.getTok().is(AsmToken::Exclaim
)) {
5681 Operands
.push_back(ARMOperand::CreateToken("!",Parser
.getTok().getLoc()));
5682 Parser
.Lex(); // Eat the '!'.
5688 assert((Tok
.is(AsmToken::Colon
) || Tok
.is(AsmToken::Comma
)) &&
5689 "Lost colon or comma in memory operand?!");
5690 if (Tok
.is(AsmToken::Comma
)) {
5691 Parser
.Lex(); // Eat the comma.
5694 // If we have a ':', it's an alignment specifier.
5695 if (Parser
.getTok().is(AsmToken::Colon
)) {
5696 Parser
.Lex(); // Eat the ':'.
5697 E
= Parser
.getTok().getLoc();
5698 SMLoc AlignmentLoc
= Tok
.getLoc();
5701 if (getParser().parseExpression(Expr
))
5704 // The expression has to be a constant. Memory references with relocations
5705 // don't come through here, as they use the <label> forms of the relevant
5707 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Expr
);
5709 return Error (E
, "constant expression expected");
5712 switch (CE
->getValue()) {
5715 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
5716 case 16: Align
= 2; break;
5717 case 32: Align
= 4; break;
5718 case 64: Align
= 8; break;
5719 case 128: Align
= 16; break;
5720 case 256: Align
= 32; break;
5723 // Now we should have the closing ']'
5724 if (Parser
.getTok().isNot(AsmToken::RBrac
))
5725 return Error(Parser
.getTok().getLoc(), "']' expected");
5726 E
= Parser
.getTok().getEndLoc();
5727 Parser
.Lex(); // Eat right bracket token.
5729 // Don't worry about range checking the value here. That's handled by
5730 // the is*() predicates.
5731 Operands
.push_back(ARMOperand::CreateMem(BaseRegNum
, nullptr, 0,
5732 ARM_AM::no_shift
, 0, Align
,
5733 false, S
, E
, AlignmentLoc
));
5735 // If there's a pre-indexing writeback marker, '!', just add it as a token
5737 if (Parser
.getTok().is(AsmToken::Exclaim
)) {
5738 Operands
.push_back(ARMOperand::CreateToken("!",Parser
.getTok().getLoc()));
5739 Parser
.Lex(); // Eat the '!'.
5745 // If we have a '#', it's an immediate offset, else assume it's a register
5746 // offset. Be friendly and also accept a plain integer (without a leading
5747 // hash) for gas compatibility.
5748 if (Parser
.getTok().is(AsmToken::Hash
) ||
5749 Parser
.getTok().is(AsmToken::Dollar
) ||
5750 Parser
.getTok().is(AsmToken::Integer
)) {
5751 if (Parser
.getTok().isNot(AsmToken::Integer
))
5752 Parser
.Lex(); // Eat '#' or '$'.
5753 E
= Parser
.getTok().getLoc();
5755 bool isNegative
= getParser().getTok().is(AsmToken::Minus
);
5756 const MCExpr
*Offset
;
5757 if (getParser().parseExpression(Offset
))
5760 // The expression has to be a constant. Memory references with relocations
5761 // don't come through here, as they use the <label> forms of the relevant
5763 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Offset
);
5765 return Error (E
, "constant expression expected");
5767 // If the constant was #-0, represent it as
5768 // std::numeric_limits<int32_t>::min().
5769 int32_t Val
= CE
->getValue();
5770 if (isNegative
&& Val
== 0)
5771 CE
= MCConstantExpr::create(std::numeric_limits
<int32_t>::min(),
5774 // Now we should have the closing ']'
5775 if (Parser
.getTok().isNot(AsmToken::RBrac
))
5776 return Error(Parser
.getTok().getLoc(), "']' expected");
5777 E
= Parser
.getTok().getEndLoc();
5778 Parser
.Lex(); // Eat right bracket token.
5780 // Don't worry about range checking the value here. That's handled by
5781 // the is*() predicates.
5782 Operands
.push_back(ARMOperand::CreateMem(BaseRegNum
, CE
, 0,
5783 ARM_AM::no_shift
, 0, 0,
5786 // If there's a pre-indexing writeback marker, '!', just add it as a token
5788 if (Parser
.getTok().is(AsmToken::Exclaim
)) {
5789 Operands
.push_back(ARMOperand::CreateToken("!",Parser
.getTok().getLoc()));
5790 Parser
.Lex(); // Eat the '!'.
5796 // The register offset is optionally preceded by a '+' or '-'
5797 bool isNegative
= false;
5798 if (Parser
.getTok().is(AsmToken::Minus
)) {
5800 Parser
.Lex(); // Eat the '-'.
5801 } else if (Parser
.getTok().is(AsmToken::Plus
)) {
5803 Parser
.Lex(); // Eat the '+'.
5806 E
= Parser
.getTok().getLoc();
5807 int OffsetRegNum
= tryParseRegister();
5808 if (OffsetRegNum
== -1)
5809 return Error(E
, "register expected");
5811 // If there's a shift operator, handle it.
5812 ARM_AM::ShiftOpc ShiftType
= ARM_AM::no_shift
;
5813 unsigned ShiftImm
= 0;
5814 if (Parser
.getTok().is(AsmToken::Comma
)) {
5815 Parser
.Lex(); // Eat the ','.
5816 if (parseMemRegOffsetShift(ShiftType
, ShiftImm
))
5820 // Now we should have the closing ']'
5821 if (Parser
.getTok().isNot(AsmToken::RBrac
))
5822 return Error(Parser
.getTok().getLoc(), "']' expected");
5823 E
= Parser
.getTok().getEndLoc();
5824 Parser
.Lex(); // Eat right bracket token.
5826 Operands
.push_back(ARMOperand::CreateMem(BaseRegNum
, nullptr, OffsetRegNum
,
5827 ShiftType
, ShiftImm
, 0, isNegative
,
5830 // If there's a pre-indexing writeback marker, '!', just add it as a token
5832 if (Parser
.getTok().is(AsmToken::Exclaim
)) {
5833 Operands
.push_back(ARMOperand::CreateToken("!",Parser
.getTok().getLoc()));
5834 Parser
.Lex(); // Eat the '!'.
5840 /// parseMemRegOffsetShift - one of these two:
5841 /// ( lsl | lsr | asr | ror ) , # shift_amount
5843 /// return true if it parses a shift otherwise it returns false.
5844 bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc
&St
,
5846 MCAsmParser
&Parser
= getParser();
5847 SMLoc Loc
= Parser
.getTok().getLoc();
5848 const AsmToken
&Tok
= Parser
.getTok();
5849 if (Tok
.isNot(AsmToken::Identifier
))
5850 return Error(Loc
, "illegal shift operator");
5851 StringRef ShiftName
= Tok
.getString();
5852 if (ShiftName
== "lsl" || ShiftName
== "LSL" ||
5853 ShiftName
== "asl" || ShiftName
== "ASL")
5855 else if (ShiftName
== "lsr" || ShiftName
== "LSR")
5857 else if (ShiftName
== "asr" || ShiftName
== "ASR")
5859 else if (ShiftName
== "ror" || ShiftName
== "ROR")
5861 else if (ShiftName
== "rrx" || ShiftName
== "RRX")
5863 else if (ShiftName
== "uxtw" || ShiftName
== "UXTW")
5866 return Error(Loc
, "illegal shift operator");
5867 Parser
.Lex(); // Eat shift type token.
5869 // rrx stands alone.
5871 if (St
!= ARM_AM::rrx
) {
5872 Loc
= Parser
.getTok().getLoc();
5873 // A '#' and a shift amount.
5874 const AsmToken
&HashTok
= Parser
.getTok();
5875 if (HashTok
.isNot(AsmToken::Hash
) &&
5876 HashTok
.isNot(AsmToken::Dollar
))
5877 return Error(HashTok
.getLoc(), "'#' expected");
5878 Parser
.Lex(); // Eat hash token.
5881 if (getParser().parseExpression(Expr
))
5883 // Range check the immediate.
5884 // lsl, ror: 0 <= imm <= 31
5885 // lsr, asr: 0 <= imm <= 32
5886 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Expr
);
5888 return Error(Loc
, "shift amount must be an immediate");
5889 int64_t Imm
= CE
->getValue();
5891 ((St
== ARM_AM::lsl
|| St
== ARM_AM::ror
) && Imm
> 31) ||
5892 ((St
== ARM_AM::lsr
|| St
== ARM_AM::asr
) && Imm
> 32))
5893 return Error(Loc
, "immediate shift value out of range");
5894 // If <ShiftTy> #0, turn it into a no_shift.
5897 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5906 /// parseFPImm - A floating point immediate expression operand.
5907 OperandMatchResultTy
5908 ARMAsmParser::parseFPImm(OperandVector
&Operands
) {
5909 MCAsmParser
&Parser
= getParser();
5910 // Anything that can accept a floating point constant as an operand
5911 // needs to go through here, as the regular parseExpression is
5914 // This routine still creates a generic Immediate operand, containing
5915 // a bitcast of the 64-bit floating point value. The various operands
5916 // that accept floats can check whether the value is valid for them
5917 // via the standard is*() predicates.
5919 SMLoc S
= Parser
.getTok().getLoc();
5921 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
5922 Parser
.getTok().isNot(AsmToken::Dollar
))
5923 return MatchOperand_NoMatch
;
5925 // Disambiguate the VMOV forms that can accept an FP immediate.
5926 // vmov.f32 <sreg>, #imm
5927 // vmov.f64 <dreg>, #imm
5928 // vmov.f32 <dreg>, #imm @ vector f32x2
5929 // vmov.f32 <qreg>, #imm @ vector f32x4
5931 // There are also the NEON VMOV instructions which expect an
5932 // integer constant. Make sure we don't try to parse an FPImm
5934 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
5935 ARMOperand
&TyOp
= static_cast<ARMOperand
&>(*Operands
[2]);
5936 bool isVmovf
= TyOp
.isToken() &&
5937 (TyOp
.getToken() == ".f32" || TyOp
.getToken() == ".f64" ||
5938 TyOp
.getToken() == ".f16");
5939 ARMOperand
&Mnemonic
= static_cast<ARMOperand
&>(*Operands
[0]);
5940 bool isFconst
= Mnemonic
.isToken() && (Mnemonic
.getToken() == "fconstd" ||
5941 Mnemonic
.getToken() == "fconsts");
5942 if (!(isVmovf
|| isFconst
))
5943 return MatchOperand_NoMatch
;
5945 Parser
.Lex(); // Eat '#' or '$'.
5947 // Handle negation, as that still comes through as a separate token.
5948 bool isNegative
= false;
5949 if (Parser
.getTok().is(AsmToken::Minus
)) {
5953 const AsmToken
&Tok
= Parser
.getTok();
5954 SMLoc Loc
= Tok
.getLoc();
5955 if (Tok
.is(AsmToken::Real
) && isVmovf
) {
5956 APFloat
RealVal(APFloat::IEEEsingle(), Tok
.getString());
5957 uint64_t IntVal
= RealVal
.bitcastToAPInt().getZExtValue();
5958 // If we had a '-' in front, toggle the sign bit.
5959 IntVal
^= (uint64_t)isNegative
<< 31;
5960 Parser
.Lex(); // Eat the token.
5961 Operands
.push_back(ARMOperand::CreateImm(
5962 MCConstantExpr::create(IntVal
, getContext()),
5963 S
, Parser
.getTok().getLoc()));
5964 return MatchOperand_Success
;
5966 // Also handle plain integers. Instructions which allow floating point
5967 // immediates also allow a raw encoded 8-bit value.
5968 if (Tok
.is(AsmToken::Integer
) && isFconst
) {
5969 int64_t Val
= Tok
.getIntVal();
5970 Parser
.Lex(); // Eat the token.
5971 if (Val
> 255 || Val
< 0) {
5972 Error(Loc
, "encoded floating point value out of range");
5973 return MatchOperand_ParseFail
;
5975 float RealVal
= ARM_AM::getFPImmFloat(Val
);
5976 Val
= APFloat(RealVal
).bitcastToAPInt().getZExtValue();
5978 Operands
.push_back(ARMOperand::CreateImm(
5979 MCConstantExpr::create(Val
, getContext()), S
,
5980 Parser
.getTok().getLoc()));
5981 return MatchOperand_Success
;
5984 Error(Loc
, "invalid floating point immediate");
5985 return MatchOperand_ParseFail
;
5988 /// Parse a arm instruction operand. For now this parses the operand regardless
5989 /// of the mnemonic.
5990 bool ARMAsmParser::parseOperand(OperandVector
&Operands
, StringRef Mnemonic
) {
5991 MCAsmParser
&Parser
= getParser();
5994 // Check if the current operand has a custom associated parser, if so, try to
5995 // custom parse the operand, or fallback to the general approach.
5996 OperandMatchResultTy ResTy
= MatchOperandParserImpl(Operands
, Mnemonic
);
5997 if (ResTy
== MatchOperand_Success
)
5999 // If there wasn't a custom match, try the generic matcher below. Otherwise,
6000 // there was a match, but an error occurred, in which case, just return that
6001 // the operand parsing failed.
6002 if (ResTy
== MatchOperand_ParseFail
)
6005 switch (getLexer().getKind()) {
6007 Error(Parser
.getTok().getLoc(), "unexpected token in operand");
6009 case AsmToken::Identifier
: {
6010 // If we've seen a branch mnemonic, the next operand must be a label. This
6011 // is true even if the label is a register name. So "br r1" means branch to
6013 bool ExpectLabel
= Mnemonic
== "b" || Mnemonic
== "bl";
6015 if (!tryParseRegisterWithWriteBack(Operands
))
6017 int Res
= tryParseShiftRegister(Operands
);
6018 if (Res
== 0) // success
6020 else if (Res
== -1) // irrecoverable error
6022 // If this is VMRS, check for the apsr_nzcv operand.
6023 if (Mnemonic
== "vmrs" &&
6024 Parser
.getTok().getString().equals_lower("apsr_nzcv")) {
6025 S
= Parser
.getTok().getLoc();
6027 Operands
.push_back(ARMOperand::CreateToken("APSR_nzcv", S
));
6032 // Fall though for the Identifier case that is not a register or a
6036 case AsmToken::LParen
: // parenthesized expressions like (_strcmp-4)
6037 case AsmToken::Integer
: // things like 1f and 2b as a branch targets
6038 case AsmToken::String
: // quoted label names.
6039 case AsmToken::Dot
: { // . as a branch target
6040 // This was not a register so parse other operands that start with an
6041 // identifier (like labels) as expressions and create them as immediates.
6042 const MCExpr
*IdVal
;
6043 S
= Parser
.getTok().getLoc();
6044 if (getParser().parseExpression(IdVal
))
6046 E
= SMLoc::getFromPointer(Parser
.getTok().getLoc().getPointer() - 1);
6047 Operands
.push_back(ARMOperand::CreateImm(IdVal
, S
, E
));
6050 case AsmToken::LBrac
:
6051 return parseMemory(Operands
);
6052 case AsmToken::LCurly
:
6053 return parseRegisterList(Operands
, !Mnemonic
.startswith("clr"));
6054 case AsmToken::Dollar
:
6055 case AsmToken::Hash
:
6056 // #42 -> immediate.
6057 S
= Parser
.getTok().getLoc();
6060 if (Parser
.getTok().isNot(AsmToken::Colon
)) {
6061 bool isNegative
= Parser
.getTok().is(AsmToken::Minus
);
6062 const MCExpr
*ImmVal
;
6063 if (getParser().parseExpression(ImmVal
))
6065 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(ImmVal
);
6067 int32_t Val
= CE
->getValue();
6068 if (isNegative
&& Val
== 0)
6069 ImmVal
= MCConstantExpr::create(std::numeric_limits
<int32_t>::min(),
6072 E
= SMLoc::getFromPointer(Parser
.getTok().getLoc().getPointer() - 1);
6073 Operands
.push_back(ARMOperand::CreateImm(ImmVal
, S
, E
));
6075 // There can be a trailing '!' on operands that we want as a separate
6076 // '!' Token operand. Handle that here. For example, the compatibility
6077 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
6078 if (Parser
.getTok().is(AsmToken::Exclaim
)) {
6079 Operands
.push_back(ARMOperand::CreateToken(Parser
.getTok().getString(),
6080 Parser
.getTok().getLoc()));
6081 Parser
.Lex(); // Eat exclaim token
6085 // w/ a ':' after the '#', it's just like a plain ':'.
6088 case AsmToken::Colon
: {
6089 S
= Parser
.getTok().getLoc();
6090 // ":lower16:" and ":upper16:" expression prefixes
6091 // FIXME: Check it's an expression prefix,
6092 // e.g. (FOO - :lower16:BAR) isn't legal.
6093 ARMMCExpr::VariantKind RefKind
;
6094 if (parsePrefix(RefKind
))
6097 const MCExpr
*SubExprVal
;
6098 if (getParser().parseExpression(SubExprVal
))
6101 const MCExpr
*ExprVal
= ARMMCExpr::create(RefKind
, SubExprVal
,
6103 E
= SMLoc::getFromPointer(Parser
.getTok().getLoc().getPointer() - 1);
6104 Operands
.push_back(ARMOperand::CreateImm(ExprVal
, S
, E
));
6107 case AsmToken::Equal
: {
6108 S
= Parser
.getTok().getLoc();
6109 if (Mnemonic
!= "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
6110 return Error(S
, "unexpected token in operand");
6111 Parser
.Lex(); // Eat '='
6112 const MCExpr
*SubExprVal
;
6113 if (getParser().parseExpression(SubExprVal
))
6115 E
= SMLoc::getFromPointer(Parser
.getTok().getLoc().getPointer() - 1);
6117 // execute-only: we assume that assembly programmers know what they are
6118 // doing and allow literal pool creation here
6119 Operands
.push_back(ARMOperand::CreateConstantPoolImm(SubExprVal
, S
, E
));
6125 // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
6126 // :lower16: and :upper16:.
6127 bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind
&RefKind
) {
6128 MCAsmParser
&Parser
= getParser();
6129 RefKind
= ARMMCExpr::VK_ARM_None
;
6131 // consume an optional '#' (GNU compatibility)
6132 if (getLexer().is(AsmToken::Hash
))
6135 // :lower16: and :upper16: modifiers
6136 assert(getLexer().is(AsmToken::Colon
) && "expected a :");
6137 Parser
.Lex(); // Eat ':'
6139 if (getLexer().isNot(AsmToken::Identifier
)) {
6140 Error(Parser
.getTok().getLoc(), "expected prefix identifier in operand");
6145 COFF
= (1 << MCObjectFileInfo::IsCOFF
),
6146 ELF
= (1 << MCObjectFileInfo::IsELF
),
6147 MACHO
= (1 << MCObjectFileInfo::IsMachO
),
6148 WASM
= (1 << MCObjectFileInfo::IsWasm
),
6150 static const struct PrefixEntry
{
6151 const char *Spelling
;
6152 ARMMCExpr::VariantKind VariantKind
;
6153 uint8_t SupportedFormats
;
6154 } PrefixEntries
[] = {
6155 { "lower16", ARMMCExpr::VK_ARM_LO16
, COFF
| ELF
| MACHO
},
6156 { "upper16", ARMMCExpr::VK_ARM_HI16
, COFF
| ELF
| MACHO
},
6159 StringRef IDVal
= Parser
.getTok().getIdentifier();
6161 const auto &Prefix
=
6162 std::find_if(std::begin(PrefixEntries
), std::end(PrefixEntries
),
6163 [&IDVal
](const PrefixEntry
&PE
) {
6164 return PE
.Spelling
== IDVal
;
6166 if (Prefix
== std::end(PrefixEntries
)) {
6167 Error(Parser
.getTok().getLoc(), "unexpected prefix in operand");
6171 uint8_t CurrentFormat
;
6172 switch (getContext().getObjectFileInfo()->getObjectFileType()) {
6173 case MCObjectFileInfo::IsMachO
:
6174 CurrentFormat
= MACHO
;
6176 case MCObjectFileInfo::IsELF
:
6177 CurrentFormat
= ELF
;
6179 case MCObjectFileInfo::IsCOFF
:
6180 CurrentFormat
= COFF
;
6182 case MCObjectFileInfo::IsWasm
:
6183 CurrentFormat
= WASM
;
6185 case MCObjectFileInfo::IsXCOFF
:
6186 llvm_unreachable("unexpected object format");
6190 if (~Prefix
->SupportedFormats
& CurrentFormat
) {
6191 Error(Parser
.getTok().getLoc(),
6192 "cannot represent relocation in the current file format");
6196 RefKind
= Prefix
->VariantKind
;
6199 if (getLexer().isNot(AsmToken::Colon
)) {
6200 Error(Parser
.getTok().getLoc(), "unexpected token after prefix");
6203 Parser
.Lex(); // Eat the last ':'
6208 /// Given a mnemonic, split out possible predication code and carry
6209 /// setting letters to form a canonical mnemonic and flags.
6211 // FIXME: Would be nice to autogen this.
6212 // FIXME: This is a bit of a maze of special cases.
6213 StringRef
ARMAsmParser::splitMnemonic(StringRef Mnemonic
,
6214 StringRef ExtraToken
,
6215 unsigned &PredicationCode
,
6216 unsigned &VPTPredicationCode
,
6218 unsigned &ProcessorIMod
,
6219 StringRef
&ITMask
) {
6220 PredicationCode
= ARMCC::AL
;
6221 VPTPredicationCode
= ARMVCC::None
;
6222 CarrySetting
= false;
6225 // Ignore some mnemonics we know aren't predicated forms.
6227 // FIXME: Would be nice to autogen this.
6228 if ((Mnemonic
== "movs" && isThumb()) ||
6229 Mnemonic
== "teq" || Mnemonic
== "vceq" || Mnemonic
== "svc" ||
6230 Mnemonic
== "mls" || Mnemonic
== "smmls" || Mnemonic
== "vcls" ||
6231 Mnemonic
== "vmls" || Mnemonic
== "vnmls" || Mnemonic
== "vacge" ||
6232 Mnemonic
== "vcge" || Mnemonic
== "vclt" || Mnemonic
== "vacgt" ||
6233 Mnemonic
== "vaclt" || Mnemonic
== "vacle" || Mnemonic
== "hlt" ||
6234 Mnemonic
== "vcgt" || Mnemonic
== "vcle" || Mnemonic
== "smlal" ||
6235 Mnemonic
== "umaal" || Mnemonic
== "umlal" || Mnemonic
== "vabal" ||
6236 Mnemonic
== "vmlal" || Mnemonic
== "vpadal" || Mnemonic
== "vqdmlal" ||
6237 Mnemonic
== "fmuls" || Mnemonic
== "vmaxnm" || Mnemonic
== "vminnm" ||
6238 Mnemonic
== "vcvta" || Mnemonic
== "vcvtn" || Mnemonic
== "vcvtp" ||
6239 Mnemonic
== "vcvtm" || Mnemonic
== "vrinta" || Mnemonic
== "vrintn" ||
6240 Mnemonic
== "vrintp" || Mnemonic
== "vrintm" || Mnemonic
== "hvc" ||
6241 Mnemonic
.startswith("vsel") || Mnemonic
== "vins" || Mnemonic
== "vmovx" ||
6242 Mnemonic
== "bxns" || Mnemonic
== "blxns" ||
6243 Mnemonic
== "vudot" || Mnemonic
== "vsdot" ||
6244 Mnemonic
== "vcmla" || Mnemonic
== "vcadd" ||
6245 Mnemonic
== "vfmal" || Mnemonic
== "vfmsl" ||
6246 Mnemonic
== "wls" || Mnemonic
== "le" || Mnemonic
== "dls" ||
6247 Mnemonic
== "csel" || Mnemonic
== "csinc" ||
6248 Mnemonic
== "csinv" || Mnemonic
== "csneg" || Mnemonic
== "cinc" ||
6249 Mnemonic
== "cinv" || Mnemonic
== "cneg" || Mnemonic
== "cset" ||
6250 Mnemonic
== "csetm")
6253 // First, split out any predication code. Ignore mnemonics we know aren't
6254 // predicated but do have a carry-set and so weren't caught above.
6255 if (Mnemonic
!= "adcs" && Mnemonic
!= "bics" && Mnemonic
!= "movs" &&
6256 Mnemonic
!= "muls" && Mnemonic
!= "smlals" && Mnemonic
!= "smulls" &&
6257 Mnemonic
!= "umlals" && Mnemonic
!= "umulls" && Mnemonic
!= "lsls" &&
6258 Mnemonic
!= "sbcs" && Mnemonic
!= "rscs" &&
6260 (Mnemonic
== "vmine" ||
6261 Mnemonic
== "vshle" || Mnemonic
== "vshlt" || Mnemonic
== "vshllt" ||
6262 Mnemonic
== "vrshle" || Mnemonic
== "vrshlt" ||
6263 Mnemonic
== "vmvne" || Mnemonic
== "vorne" ||
6264 Mnemonic
== "vnege" || Mnemonic
== "vnegt" ||
6265 Mnemonic
== "vmule" || Mnemonic
== "vmult" ||
6266 Mnemonic
== "vrintne" ||
6267 Mnemonic
== "vcmult" || Mnemonic
== "vcmule" ||
6268 Mnemonic
== "vpsele" || Mnemonic
== "vpselt" ||
6269 Mnemonic
.startswith("vq")))) {
6270 unsigned CC
= ARMCondCodeFromString(Mnemonic
.substr(Mnemonic
.size()-2));
6272 Mnemonic
= Mnemonic
.slice(0, Mnemonic
.size() - 2);
6273 PredicationCode
= CC
;
6277 // Next, determine if we have a carry setting bit. We explicitly ignore all
6278 // the instructions we know end in 's'.
6279 if (Mnemonic
.endswith("s") &&
6280 !(Mnemonic
== "cps" || Mnemonic
== "mls" ||
6281 Mnemonic
== "mrs" || Mnemonic
== "smmls" || Mnemonic
== "vabs" ||
6282 Mnemonic
== "vcls" || Mnemonic
== "vmls" || Mnemonic
== "vmrs" ||
6283 Mnemonic
== "vnmls" || Mnemonic
== "vqabs" || Mnemonic
== "vrecps" ||
6284 Mnemonic
== "vrsqrts" || Mnemonic
== "srs" || Mnemonic
== "flds" ||
6285 Mnemonic
== "fmrs" || Mnemonic
== "fsqrts" || Mnemonic
== "fsubs" ||
6286 Mnemonic
== "fsts" || Mnemonic
== "fcpys" || Mnemonic
== "fdivs" ||
6287 Mnemonic
== "fmuls" || Mnemonic
== "fcmps" || Mnemonic
== "fcmpzs" ||
6288 Mnemonic
== "vfms" || Mnemonic
== "vfnms" || Mnemonic
== "fconsts" ||
6289 Mnemonic
== "bxns" || Mnemonic
== "blxns" || Mnemonic
== "vfmas" ||
6290 Mnemonic
== "vmlas" ||
6291 (Mnemonic
== "movs" && isThumb()))) {
6292 Mnemonic
= Mnemonic
.slice(0, Mnemonic
.size() - 1);
6293 CarrySetting
= true;
6296 // The "cps" instruction can have a interrupt mode operand which is glued into
6297 // the mnemonic. Check if this is the case, split it and parse the imod op
6298 if (Mnemonic
.startswith("cps")) {
6299 // Split out any imod code.
6301 StringSwitch
<unsigned>(Mnemonic
.substr(Mnemonic
.size()-2, 2))
6302 .Case("ie", ARM_PROC::IE
)
6303 .Case("id", ARM_PROC::ID
)
6306 Mnemonic
= Mnemonic
.slice(0, Mnemonic
.size()-2);
6307 ProcessorIMod
= IMod
;
6311 if (isMnemonicVPTPredicable(Mnemonic
, ExtraToken
) && Mnemonic
!= "vmovlt" &&
6312 Mnemonic
!= "vshllt" && Mnemonic
!= "vrshrnt" && Mnemonic
!= "vshrnt" &&
6313 Mnemonic
!= "vqrshrunt" && Mnemonic
!= "vqshrunt" &&
6314 Mnemonic
!= "vqrshrnt" && Mnemonic
!= "vqshrnt" && Mnemonic
!= "vmullt" &&
6315 Mnemonic
!= "vqmovnt" && Mnemonic
!= "vqmovunt" &&
6316 Mnemonic
!= "vqmovnt" && Mnemonic
!= "vmovnt" && Mnemonic
!= "vqdmullt" &&
6317 Mnemonic
!= "vpnot" && Mnemonic
!= "vcvtt" && Mnemonic
!= "vcvt") {
6318 unsigned CC
= ARMVectorCondCodeFromString(Mnemonic
.substr(Mnemonic
.size()-1));
6320 Mnemonic
= Mnemonic
.slice(0, Mnemonic
.size()-1);
6321 VPTPredicationCode
= CC
;
6326 // The "it" instruction has the condition mask on the end of the mnemonic.
6327 if (Mnemonic
.startswith("it")) {
6328 ITMask
= Mnemonic
.slice(2, Mnemonic
.size());
6329 Mnemonic
= Mnemonic
.slice(0, 2);
6332 if (Mnemonic
.startswith("vpst")) {
6333 ITMask
= Mnemonic
.slice(4, Mnemonic
.size());
6334 Mnemonic
= Mnemonic
.slice(0, 4);
6336 else if (Mnemonic
.startswith("vpt")) {
6337 ITMask
= Mnemonic
.slice(3, Mnemonic
.size());
6338 Mnemonic
= Mnemonic
.slice(0, 3);
6344 /// Given a canonical mnemonic, determine if the instruction ever allows
6345 /// inclusion of carry set or predication code operands.
6347 // FIXME: It would be nice to autogen this.
6348 void ARMAsmParser::getMnemonicAcceptInfo(StringRef Mnemonic
,
6349 StringRef ExtraToken
,
6351 bool &CanAcceptCarrySet
,
6352 bool &CanAcceptPredicationCode
,
6353 bool &CanAcceptVPTPredicationCode
) {
6354 CanAcceptVPTPredicationCode
= isMnemonicVPTPredicable(Mnemonic
, ExtraToken
);
6357 Mnemonic
== "and" || Mnemonic
== "lsl" || Mnemonic
== "lsr" ||
6358 Mnemonic
== "rrx" || Mnemonic
== "ror" || Mnemonic
== "sub" ||
6359 Mnemonic
== "add" || Mnemonic
== "adc" || Mnemonic
== "mul" ||
6360 Mnemonic
== "bic" || Mnemonic
== "asr" || Mnemonic
== "orr" ||
6361 Mnemonic
== "mvn" || Mnemonic
== "rsb" || Mnemonic
== "rsc" ||
6362 Mnemonic
== "orn" || Mnemonic
== "sbc" || Mnemonic
== "eor" ||
6363 Mnemonic
== "neg" || Mnemonic
== "vfm" || Mnemonic
== "vfnm" ||
6365 (Mnemonic
== "smull" || Mnemonic
== "mov" || Mnemonic
== "mla" ||
6366 Mnemonic
== "smlal" || Mnemonic
== "umlal" || Mnemonic
== "umull"));
6368 if (Mnemonic
== "bkpt" || Mnemonic
== "cbnz" || Mnemonic
== "setend" ||
6369 Mnemonic
== "cps" || Mnemonic
== "it" || Mnemonic
== "cbz" ||
6370 Mnemonic
== "trap" || Mnemonic
== "hlt" || Mnemonic
== "udf" ||
6371 Mnemonic
.startswith("crc32") || Mnemonic
.startswith("cps") ||
6372 Mnemonic
.startswith("vsel") || Mnemonic
== "vmaxnm" ||
6373 Mnemonic
== "vminnm" || Mnemonic
== "vcvta" || Mnemonic
== "vcvtn" ||
6374 Mnemonic
== "vcvtp" || Mnemonic
== "vcvtm" || Mnemonic
== "vrinta" ||
6375 Mnemonic
== "vrintn" || Mnemonic
== "vrintp" || Mnemonic
== "vrintm" ||
6376 Mnemonic
.startswith("aes") || Mnemonic
== "hvc" || Mnemonic
== "setpan" ||
6377 Mnemonic
.startswith("sha1") || Mnemonic
.startswith("sha256") ||
6378 (FullInst
.startswith("vmull") && FullInst
.endswith(".p64")) ||
6379 Mnemonic
== "vmovx" || Mnemonic
== "vins" ||
6380 Mnemonic
== "vudot" || Mnemonic
== "vsdot" ||
6381 Mnemonic
== "vcmla" || Mnemonic
== "vcadd" ||
6382 Mnemonic
== "vfmal" || Mnemonic
== "vfmsl" ||
6383 Mnemonic
== "sb" || Mnemonic
== "ssbb" ||
6384 Mnemonic
== "pssbb" ||
6385 Mnemonic
== "bfcsel" || Mnemonic
== "wls" ||
6386 Mnemonic
== "dls" || Mnemonic
== "le" || Mnemonic
== "csel" ||
6387 Mnemonic
== "csinc" || Mnemonic
== "csinv" || Mnemonic
== "csneg" ||
6388 Mnemonic
== "cinc" || Mnemonic
== "cinv" || Mnemonic
== "cneg" ||
6389 Mnemonic
== "cset" || Mnemonic
== "csetm" ||
6390 Mnemonic
.startswith("vpt") || Mnemonic
.startswith("vpst") ||
6392 (Mnemonic
.startswith("vst2") || Mnemonic
.startswith("vld2") ||
6393 Mnemonic
.startswith("vst4") || Mnemonic
.startswith("vld4") ||
6394 Mnemonic
.startswith("wlstp") || Mnemonic
.startswith("dlstp") ||
6395 Mnemonic
.startswith("letp")))) {
6396 // These mnemonics are never predicable
6397 CanAcceptPredicationCode
= false;
6398 } else if (!isThumb()) {
6399 // Some instructions are only predicable in Thumb mode
6400 CanAcceptPredicationCode
=
6401 Mnemonic
!= "cdp2" && Mnemonic
!= "clrex" && Mnemonic
!= "mcr2" &&
6402 Mnemonic
!= "mcrr2" && Mnemonic
!= "mrc2" && Mnemonic
!= "mrrc2" &&
6403 Mnemonic
!= "dmb" && Mnemonic
!= "dfb" && Mnemonic
!= "dsb" &&
6404 Mnemonic
!= "isb" && Mnemonic
!= "pld" && Mnemonic
!= "pli" &&
6405 Mnemonic
!= "pldw" && Mnemonic
!= "ldc2" && Mnemonic
!= "ldc2l" &&
6406 Mnemonic
!= "stc2" && Mnemonic
!= "stc2l" &&
6407 Mnemonic
!= "tsb" &&
6408 !Mnemonic
.startswith("rfe") && !Mnemonic
.startswith("srs");
6409 } else if (isThumbOne()) {
6411 CanAcceptPredicationCode
= Mnemonic
!= "movs";
6413 CanAcceptPredicationCode
= Mnemonic
!= "nop" && Mnemonic
!= "movs";
6415 CanAcceptPredicationCode
= true;
6418 // Some Thumb instructions have two operand forms that are not
6419 // available as three operand, convert to two operand form if possible.
6421 // FIXME: We would really like to be able to tablegen'erate this.
6422 void ARMAsmParser::tryConvertingToTwoOperandForm(StringRef Mnemonic
,
6424 OperandVector
&Operands
) {
6425 if (Operands
.size() != 6)
6428 const auto &Op3
= static_cast<ARMOperand
&>(*Operands
[3]);
6429 auto &Op4
= static_cast<ARMOperand
&>(*Operands
[4]);
6430 if (!Op3
.isReg() || !Op4
.isReg())
6433 auto Op3Reg
= Op3
.getReg();
6434 auto Op4Reg
= Op4
.getReg();
6436 // For most Thumb2 cases we just generate the 3 operand form and reduce
6437 // it in processInstruction(), but the 3 operand form of ADD (t2ADDrr)
6438 // won't accept SP or PC so we do the transformation here taking care
6439 // with immediate range in the 'add sp, sp #imm' case.
6440 auto &Op5
= static_cast<ARMOperand
&>(*Operands
[5]);
6442 if (Mnemonic
!= "add")
6444 bool TryTransform
= Op3Reg
== ARM::PC
|| Op4Reg
== ARM::PC
||
6445 (Op5
.isReg() && Op5
.getReg() == ARM::PC
);
6446 if (!TryTransform
) {
6447 TryTransform
= (Op3Reg
== ARM::SP
|| Op4Reg
== ARM::SP
||
6448 (Op5
.isReg() && Op5
.getReg() == ARM::SP
)) &&
6449 !(Op3Reg
== ARM::SP
&& Op4Reg
== ARM::SP
&&
6450 Op5
.isImm() && !Op5
.isImm0_508s4());
6454 } else if (!isThumbOne())
6457 if (!(Mnemonic
== "add" || Mnemonic
== "sub" || Mnemonic
== "and" ||
6458 Mnemonic
== "eor" || Mnemonic
== "lsl" || Mnemonic
== "lsr" ||
6459 Mnemonic
== "asr" || Mnemonic
== "adc" || Mnemonic
== "sbc" ||
6460 Mnemonic
== "ror" || Mnemonic
== "orr" || Mnemonic
== "bic"))
6463 // If first 2 operands of a 3 operand instruction are the same
6464 // then transform to 2 operand version of the same instruction
6465 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
6466 bool Transform
= Op3Reg
== Op4Reg
;
6468 // For communtative operations, we might be able to transform if we swap
6469 // Op4 and Op5. The 'ADD Rdm, SP, Rdm' form is already handled specially
6471 const ARMOperand
*LastOp
= &Op5
;
6473 if (!Transform
&& Op5
.isReg() && Op3Reg
== Op5
.getReg() &&
6474 ((Mnemonic
== "add" && Op4Reg
!= ARM::SP
) ||
6475 Mnemonic
== "and" || Mnemonic
== "eor" ||
6476 Mnemonic
== "adc" || Mnemonic
== "orr")) {
6482 // If both registers are the same then remove one of them from
6483 // the operand list, with certain exceptions.
6485 // Don't transform 'adds Rd, Rd, Rm' or 'sub{s} Rd, Rd, Rm' because the
6486 // 2 operand forms don't exist.
6487 if (((Mnemonic
== "add" && CarrySetting
) || Mnemonic
== "sub") &&
6491 // Don't transform 'add/sub{s} Rd, Rd, #imm' if the immediate fits into
6492 // 3-bits because the ARMARM says not to.
6493 if ((Mnemonic
== "add" || Mnemonic
== "sub") && LastOp
->isImm0_7())
6499 std::swap(Op4
, Op5
);
6500 Operands
.erase(Operands
.begin() + 3);
6504 bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic
,
6505 OperandVector
&Operands
) {
6506 // FIXME: This is all horribly hacky. We really need a better way to deal
6507 // with optional operands like this in the matcher table.
6509 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
6510 // another does not. Specifically, the MOVW instruction does not. So we
6511 // special case it here and remove the defaulted (non-setting) cc_out
6512 // operand if that's the instruction we're trying to match.
6514 // We do this as post-processing of the explicit operands rather than just
6515 // conditionally adding the cc_out in the first place because we need
6516 // to check the type of the parsed immediate operand.
6517 if (Mnemonic
== "mov" && Operands
.size() > 4 && !isThumb() &&
6518 !static_cast<ARMOperand
&>(*Operands
[4]).isModImm() &&
6519 static_cast<ARMOperand
&>(*Operands
[4]).isImm0_65535Expr() &&
6520 static_cast<ARMOperand
&>(*Operands
[1]).getReg() == 0)
6523 // Register-register 'add' for thumb does not have a cc_out operand
6524 // when there are only two register operands.
6525 if (isThumb() && Mnemonic
== "add" && Operands
.size() == 5 &&
6526 static_cast<ARMOperand
&>(*Operands
[3]).isReg() &&
6527 static_cast<ARMOperand
&>(*Operands
[4]).isReg() &&
6528 static_cast<ARMOperand
&>(*Operands
[1]).getReg() == 0)
6530 // Register-register 'add' for thumb does not have a cc_out operand
6531 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
6532 // have to check the immediate range here since Thumb2 has a variant
6533 // that can handle a different range and has a cc_out operand.
6534 if (((isThumb() && Mnemonic
== "add") ||
6535 (isThumbTwo() && Mnemonic
== "sub")) &&
6536 Operands
.size() == 6 && static_cast<ARMOperand
&>(*Operands
[3]).isReg() &&
6537 static_cast<ARMOperand
&>(*Operands
[4]).isReg() &&
6538 static_cast<ARMOperand
&>(*Operands
[4]).getReg() == ARM::SP
&&
6539 static_cast<ARMOperand
&>(*Operands
[1]).getReg() == 0 &&
6540 ((Mnemonic
== "add" && static_cast<ARMOperand
&>(*Operands
[5]).isReg()) ||
6541 static_cast<ARMOperand
&>(*Operands
[5]).isImm0_1020s4()))
6543 // For Thumb2, add/sub immediate does not have a cc_out operand for the
6544 // imm0_4095 variant. That's the least-preferred variant when
6545 // selecting via the generic "add" mnemonic, so to know that we
6546 // should remove the cc_out operand, we have to explicitly check that
6547 // it's not one of the other variants. Ugh.
6548 if (isThumbTwo() && (Mnemonic
== "add" || Mnemonic
== "sub") &&
6549 Operands
.size() == 6 && static_cast<ARMOperand
&>(*Operands
[3]).isReg() &&
6550 static_cast<ARMOperand
&>(*Operands
[4]).isReg() &&
6551 static_cast<ARMOperand
&>(*Operands
[5]).isImm()) {
6552 // Nest conditions rather than one big 'if' statement for readability.
6554 // If both registers are low, we're in an IT block, and the immediate is
6555 // in range, we should use encoding T1 instead, which has a cc_out.
6557 isARMLowRegister(static_cast<ARMOperand
&>(*Operands
[3]).getReg()) &&
6558 isARMLowRegister(static_cast<ARMOperand
&>(*Operands
[4]).getReg()) &&
6559 static_cast<ARMOperand
&>(*Operands
[5]).isImm0_7())
6561 // Check against T3. If the second register is the PC, this is an
6562 // alternate form of ADR, which uses encoding T4, so check for that too.
6563 if (static_cast<ARMOperand
&>(*Operands
[4]).getReg() != ARM::PC
&&
6564 static_cast<ARMOperand
&>(*Operands
[5]).isT2SOImm())
6567 // Otherwise, we use encoding T4, which does not have a cc_out
6572 // The thumb2 multiply instruction doesn't have a CCOut register, so
6573 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
6574 // use the 16-bit encoding or not.
6575 if (isThumbTwo() && Mnemonic
== "mul" && Operands
.size() == 6 &&
6576 static_cast<ARMOperand
&>(*Operands
[1]).getReg() == 0 &&
6577 static_cast<ARMOperand
&>(*Operands
[3]).isReg() &&
6578 static_cast<ARMOperand
&>(*Operands
[4]).isReg() &&
6579 static_cast<ARMOperand
&>(*Operands
[5]).isReg() &&
6580 // If the registers aren't low regs, the destination reg isn't the
6581 // same as one of the source regs, or the cc_out operand is zero
6582 // outside of an IT block, we have to use the 32-bit encoding, so
6583 // remove the cc_out operand.
6584 (!isARMLowRegister(static_cast<ARMOperand
&>(*Operands
[3]).getReg()) ||
6585 !isARMLowRegister(static_cast<ARMOperand
&>(*Operands
[4]).getReg()) ||
6586 !isARMLowRegister(static_cast<ARMOperand
&>(*Operands
[5]).getReg()) ||
6587 !inITBlock() || (static_cast<ARMOperand
&>(*Operands
[3]).getReg() !=
6588 static_cast<ARMOperand
&>(*Operands
[5]).getReg() &&
6589 static_cast<ARMOperand
&>(*Operands
[3]).getReg() !=
6590 static_cast<ARMOperand
&>(*Operands
[4]).getReg())))
6593 // Also check the 'mul' syntax variant that doesn't specify an explicit
6594 // destination register.
6595 if (isThumbTwo() && Mnemonic
== "mul" && Operands
.size() == 5 &&
6596 static_cast<ARMOperand
&>(*Operands
[1]).getReg() == 0 &&
6597 static_cast<ARMOperand
&>(*Operands
[3]).isReg() &&
6598 static_cast<ARMOperand
&>(*Operands
[4]).isReg() &&
6599 // If the registers aren't low regs or the cc_out operand is zero
6600 // outside of an IT block, we have to use the 32-bit encoding, so
6601 // remove the cc_out operand.
6602 (!isARMLowRegister(static_cast<ARMOperand
&>(*Operands
[3]).getReg()) ||
6603 !isARMLowRegister(static_cast<ARMOperand
&>(*Operands
[4]).getReg()) ||
6607 // Register-register 'add/sub' for thumb does not have a cc_out operand
6608 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
6609 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
6610 // right, this will result in better diagnostics (which operand is off)
6612 if (isThumb() && (Mnemonic
== "add" || Mnemonic
== "sub") &&
6613 (Operands
.size() == 5 || Operands
.size() == 6) &&
6614 static_cast<ARMOperand
&>(*Operands
[3]).isReg() &&
6615 static_cast<ARMOperand
&>(*Operands
[3]).getReg() == ARM::SP
&&
6616 static_cast<ARMOperand
&>(*Operands
[1]).getReg() == 0 &&
6617 (static_cast<ARMOperand
&>(*Operands
[4]).isImm() ||
6618 (Operands
.size() == 6 &&
6619 static_cast<ARMOperand
&>(*Operands
[5]).isImm())))
6625 bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic
,
6626 OperandVector
&Operands
) {
6627 // VRINT{Z, X} have a predicate operand in VFP, but not in NEON
6628 unsigned RegIdx
= 3;
6629 if ((((Mnemonic
== "vrintz" || Mnemonic
== "vrintx") && !hasMVE()) ||
6630 Mnemonic
== "vrintr") &&
6631 (static_cast<ARMOperand
&>(*Operands
[2]).getToken() == ".f32" ||
6632 static_cast<ARMOperand
&>(*Operands
[2]).getToken() == ".f16")) {
6633 if (static_cast<ARMOperand
&>(*Operands
[3]).isToken() &&
6634 (static_cast<ARMOperand
&>(*Operands
[3]).getToken() == ".f32" ||
6635 static_cast<ARMOperand
&>(*Operands
[3]).getToken() == ".f16"))
6638 if (static_cast<ARMOperand
&>(*Operands
[RegIdx
]).isReg() &&
6639 (ARMMCRegisterClasses
[ARM::DPRRegClassID
].contains(
6640 static_cast<ARMOperand
&>(*Operands
[RegIdx
]).getReg()) ||
6641 ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(
6642 static_cast<ARMOperand
&>(*Operands
[RegIdx
]).getReg())))
6648 bool ARMAsmParser::shouldOmitVectorPredicateOperand(StringRef Mnemonic
,
6649 OperandVector
&Operands
) {
6650 if (!hasMVE() || Operands
.size() < 3)
6653 if (Mnemonic
.startswith("vld2") || Mnemonic
.startswith("vld4") ||
6654 Mnemonic
.startswith("vst2") || Mnemonic
.startswith("vst4"))
6657 if (Mnemonic
.startswith("vctp") || Mnemonic
.startswith("vpnot"))
6660 if (Mnemonic
.startswith("vmov") &&
6661 !(Mnemonic
.startswith("vmovl") || Mnemonic
.startswith("vmovn") ||
6662 Mnemonic
.startswith("vmovx"))) {
6663 for (auto &Operand
: Operands
) {
6664 if (static_cast<ARMOperand
&>(*Operand
).isVectorIndex() ||
6665 ((*Operand
).isReg() &&
6666 (ARMMCRegisterClasses
[ARM::SPRRegClassID
].contains(
6667 (*Operand
).getReg()) ||
6668 ARMMCRegisterClasses
[ARM::DPRRegClassID
].contains(
6669 (*Operand
).getReg())))) {
6675 for (auto &Operand
: Operands
) {
6676 // We check the larger class QPR instead of just the legal class
6677 // MQPR, to more accurately report errors when using Q registers
6678 // outside of the allowed range.
6679 if (static_cast<ARMOperand
&>(*Operand
).isVectorIndex() ||
6680 (Operand
->isReg() &&
6681 (ARMMCRegisterClasses
[ARM::QPRRegClassID
].contains(
6682 Operand
->getReg()))))
6689 static bool isDataTypeToken(StringRef Tok
) {
6690 return Tok
== ".8" || Tok
== ".16" || Tok
== ".32" || Tok
== ".64" ||
6691 Tok
== ".i8" || Tok
== ".i16" || Tok
== ".i32" || Tok
== ".i64" ||
6692 Tok
== ".u8" || Tok
== ".u16" || Tok
== ".u32" || Tok
== ".u64" ||
6693 Tok
== ".s8" || Tok
== ".s16" || Tok
== ".s32" || Tok
== ".s64" ||
6694 Tok
== ".p8" || Tok
== ".p16" || Tok
== ".f32" || Tok
== ".f64" ||
6695 Tok
== ".f" || Tok
== ".d";
6698 // FIXME: This bit should probably be handled via an explicit match class
6699 // in the .td files that matches the suffix instead of having it be
6700 // a literal string token the way it is now.
6701 static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic
, StringRef DT
) {
6702 return Mnemonic
.startswith("vldm") || Mnemonic
.startswith("vstm");
6705 static void applyMnemonicAliases(StringRef
&Mnemonic
,
6706 const FeatureBitset
&Features
,
6707 unsigned VariantID
);
6709 // The GNU assembler has aliases of ldrd and strd with the second register
6710 // omitted. We don't have a way to do that in tablegen, so fix it up here.
6712 // We have to be careful to not emit an invalid Rt2 here, because the rest of
6713 // the assmebly parser could then generate confusing diagnostics refering to
6714 // it. If we do find anything that prevents us from doing the transformation we
6715 // bail out, and let the assembly parser report an error on the instruction as
6717 void ARMAsmParser::fixupGNULDRDAlias(StringRef Mnemonic
,
6718 OperandVector
&Operands
) {
6719 if (Mnemonic
!= "ldrd" && Mnemonic
!= "strd")
6721 if (Operands
.size() < 4)
6724 ARMOperand
&Op2
= static_cast<ARMOperand
&>(*Operands
[2]);
6725 ARMOperand
&Op3
= static_cast<ARMOperand
&>(*Operands
[3]);
6729 if (!Op3
.isGPRMem())
6732 const MCRegisterClass
&GPR
= MRI
->getRegClass(ARM::GPRRegClassID
);
6733 if (!GPR
.contains(Op2
.getReg()))
6736 unsigned RtEncoding
= MRI
->getEncodingValue(Op2
.getReg());
6737 if (!isThumb() && (RtEncoding
& 1)) {
6738 // In ARM mode, the registers must be from an aligned pair, this
6739 // restriction does not apply in Thumb mode.
6742 if (Op2
.getReg() == ARM::PC
)
6744 unsigned PairedReg
= GPR
.getRegister(RtEncoding
+ 1);
6745 if (!PairedReg
|| PairedReg
== ARM::PC
||
6746 (PairedReg
== ARM::SP
&& !hasV8Ops()))
6750 Operands
.begin() + 3,
6751 ARMOperand::CreateReg(PairedReg
, Op2
.getStartLoc(), Op2
.getEndLoc()));
6754 /// Parse an arm instruction mnemonic followed by its operands.
6755 bool ARMAsmParser::ParseInstruction(ParseInstructionInfo
&Info
, StringRef Name
,
6756 SMLoc NameLoc
, OperandVector
&Operands
) {
6757 MCAsmParser
&Parser
= getParser();
6759 // Apply mnemonic aliases before doing anything else, as the destination
6760 // mnemonic may include suffices and we want to handle them normally.
6761 // The generic tblgen'erated code does this later, at the start of
6762 // MatchInstructionImpl(), but that's too late for aliases that include
6763 // any sort of suffix.
6764 const FeatureBitset
&AvailableFeatures
= getAvailableFeatures();
6765 unsigned AssemblerDialect
= getParser().getAssemblerDialect();
6766 applyMnemonicAliases(Name
, AvailableFeatures
, AssemblerDialect
);
6768 // First check for the ARM-specific .req directive.
6769 if (Parser
.getTok().is(AsmToken::Identifier
) &&
6770 Parser
.getTok().getIdentifier() == ".req") {
6771 parseDirectiveReq(Name
, NameLoc
);
6772 // We always return 'error' for this, as we're done with this
6773 // statement and don't need to match the 'instruction."
6777 // Create the leading tokens for the mnemonic, split by '.' characters.
6778 size_t Start
= 0, Next
= Name
.find('.');
6779 StringRef Mnemonic
= Name
.slice(Start
, Next
);
6780 StringRef ExtraToken
= Name
.slice(Next
, Name
.find(' ', Next
+ 1));
6782 // Split out the predication code and carry setting flag from the mnemonic.
6783 unsigned PredicationCode
;
6784 unsigned VPTPredicationCode
;
6785 unsigned ProcessorIMod
;
6788 Mnemonic
= splitMnemonic(Mnemonic
, ExtraToken
, PredicationCode
, VPTPredicationCode
,
6789 CarrySetting
, ProcessorIMod
, ITMask
);
6791 // In Thumb1, only the branch (B) instruction can be predicated.
6792 if (isThumbOne() && PredicationCode
!= ARMCC::AL
&& Mnemonic
!= "b") {
6793 return Error(NameLoc
, "conditional execution not supported in Thumb1");
6796 Operands
.push_back(ARMOperand::CreateToken(Mnemonic
, NameLoc
));
6798 // Handle the mask for IT and VPT instructions. In ARMOperand and
6799 // MCOperand, this is stored in a format independent of the
6800 // condition code: the lowest set bit indicates the end of the
6801 // encoding, and above that, a 1 bit indicates 'else', and an 0
6802 // indicates 'then'. E.g.
6804 // ITx -> x100 (ITT -> 0100, ITE -> 1100)
6805 // ITxy -> xy10 (e.g. ITET -> 1010)
6806 // ITxyz -> xyz1 (e.g. ITEET -> 1101)
6807 if (Mnemonic
== "it" || Mnemonic
.startswith("vpt") ||
6808 Mnemonic
.startswith("vpst")) {
6809 SMLoc Loc
= Mnemonic
== "it" ? SMLoc::getFromPointer(NameLoc
.getPointer() + 2) :
6810 Mnemonic
== "vpt" ? SMLoc::getFromPointer(NameLoc
.getPointer() + 3) :
6811 SMLoc::getFromPointer(NameLoc
.getPointer() + 4);
6812 if (ITMask
.size() > 3) {
6813 if (Mnemonic
== "it")
6814 return Error(Loc
, "too many conditions on IT instruction");
6815 return Error(Loc
, "too many conditions on VPT instruction");
6818 for (unsigned i
= ITMask
.size(); i
!= 0; --i
) {
6819 char pos
= ITMask
[i
- 1];
6820 if (pos
!= 't' && pos
!= 'e') {
6821 return Error(Loc
, "illegal IT block condition mask '" + ITMask
+ "'");
6824 if (ITMask
[i
- 1] == 'e')
6827 Operands
.push_back(ARMOperand::CreateITMask(Mask
, Loc
));
6830 // FIXME: This is all a pretty gross hack. We should automatically handle
6831 // optional operands like this via tblgen.
6833 // Next, add the CCOut and ConditionCode operands, if needed.
6835 // For mnemonics which can ever incorporate a carry setting bit or predication
6836 // code, our matching model involves us always generating CCOut and
6837 // ConditionCode operands to match the mnemonic "as written" and then we let
6838 // the matcher deal with finding the right instruction or generating an
6839 // appropriate error.
6840 bool CanAcceptCarrySet
, CanAcceptPredicationCode
, CanAcceptVPTPredicationCode
;
6841 getMnemonicAcceptInfo(Mnemonic
, ExtraToken
, Name
, CanAcceptCarrySet
,
6842 CanAcceptPredicationCode
, CanAcceptVPTPredicationCode
);
6844 // If we had a carry-set on an instruction that can't do that, issue an
6846 if (!CanAcceptCarrySet
&& CarrySetting
) {
6847 return Error(NameLoc
, "instruction '" + Mnemonic
+
6848 "' can not set flags, but 's' suffix specified");
6850 // If we had a predication code on an instruction that can't do that, issue an
6852 if (!CanAcceptPredicationCode
&& PredicationCode
!= ARMCC::AL
) {
6853 return Error(NameLoc
, "instruction '" + Mnemonic
+
6854 "' is not predicable, but condition code specified");
6857 // If we had a VPT predication code on an instruction that can't do that, issue an
6859 if (!CanAcceptVPTPredicationCode
&& VPTPredicationCode
!= ARMVCC::None
) {
6860 return Error(NameLoc
, "instruction '" + Mnemonic
+
6861 "' is not VPT predicable, but VPT code T/E is specified");
6864 // Add the carry setting operand, if necessary.
6865 if (CanAcceptCarrySet
) {
6866 SMLoc Loc
= SMLoc::getFromPointer(NameLoc
.getPointer() + Mnemonic
.size());
6867 Operands
.push_back(ARMOperand::CreateCCOut(CarrySetting
? ARM::CPSR
: 0,
6871 // Add the predication code operand, if necessary.
6872 if (CanAcceptPredicationCode
) {
6873 SMLoc Loc
= SMLoc::getFromPointer(NameLoc
.getPointer() + Mnemonic
.size() +
6875 Operands
.push_back(ARMOperand::CreateCondCode(
6876 ARMCC::CondCodes(PredicationCode
), Loc
));
6879 // Add the VPT predication code operand, if necessary.
6880 // FIXME: We don't add them for the instructions filtered below as these can
6881 // have custom operands which need special parsing. This parsing requires
6882 // the operand to be in the same place in the OperandVector as their
6883 // definition in tblgen. Since these instructions may also have the
6884 // scalar predication operand we do not add the vector one and leave until
6885 // now to fix it up.
6886 if (CanAcceptVPTPredicationCode
&& Mnemonic
!= "vmov" &&
6887 !Mnemonic
.startswith("vcmp") &&
6888 !(Mnemonic
.startswith("vcvt") && Mnemonic
!= "vcvta" &&
6889 Mnemonic
!= "vcvtn" && Mnemonic
!= "vcvtp" && Mnemonic
!= "vcvtm")) {
6890 SMLoc Loc
= SMLoc::getFromPointer(NameLoc
.getPointer() + Mnemonic
.size() +
6892 Operands
.push_back(ARMOperand::CreateVPTPred(
6893 ARMVCC::VPTCodes(VPTPredicationCode
), Loc
));
6896 // Add the processor imod operand, if necessary.
6897 if (ProcessorIMod
) {
6898 Operands
.push_back(ARMOperand::CreateImm(
6899 MCConstantExpr::create(ProcessorIMod
, getContext()),
6901 } else if (Mnemonic
== "cps" && isMClass()) {
6902 return Error(NameLoc
, "instruction 'cps' requires effect for M-class");
6905 // Add the remaining tokens in the mnemonic.
6906 while (Next
!= StringRef::npos
) {
6908 Next
= Name
.find('.', Start
+ 1);
6909 ExtraToken
= Name
.slice(Start
, Next
);
6911 // Some NEON instructions have an optional datatype suffix that is
6912 // completely ignored. Check for that.
6913 if (isDataTypeToken(ExtraToken
) &&
6914 doesIgnoreDataTypeSuffix(Mnemonic
, ExtraToken
))
6917 // For for ARM mode generate an error if the .n qualifier is used.
6918 if (ExtraToken
== ".n" && !isThumb()) {
6919 SMLoc Loc
= SMLoc::getFromPointer(NameLoc
.getPointer() + Start
);
6920 return Error(Loc
, "instruction with .n (narrow) qualifier not allowed in "
6924 // The .n qualifier is always discarded as that is what the tables
6925 // and matcher expect. In ARM mode the .w qualifier has no effect,
6926 // so discard it to avoid errors that can be caused by the matcher.
6927 if (ExtraToken
!= ".n" && (isThumb() || ExtraToken
!= ".w")) {
6928 SMLoc Loc
= SMLoc::getFromPointer(NameLoc
.getPointer() + Start
);
6929 Operands
.push_back(ARMOperand::CreateToken(ExtraToken
, Loc
));
6933 // Read the remaining operands.
6934 if (getLexer().isNot(AsmToken::EndOfStatement
)) {
6935 // Read the first operand.
6936 if (parseOperand(Operands
, Mnemonic
)) {
6940 while (parseOptionalToken(AsmToken::Comma
)) {
6941 // Parse and remember the operand.
6942 if (parseOperand(Operands
, Mnemonic
)) {
6948 if (parseToken(AsmToken::EndOfStatement
, "unexpected token in argument list"))
6951 tryConvertingToTwoOperandForm(Mnemonic
, CarrySetting
, Operands
);
6953 // Some instructions, mostly Thumb, have forms for the same mnemonic that
6954 // do and don't have a cc_out optional-def operand. With some spot-checks
6955 // of the operand list, we can figure out which variant we're trying to
6956 // parse and adjust accordingly before actually matching. We shouldn't ever
6957 // try to remove a cc_out operand that was explicitly set on the
6958 // mnemonic, of course (CarrySetting == true). Reason number #317 the
6959 // table driven matcher doesn't fit well with the ARM instruction set.
6960 if (!CarrySetting
&& shouldOmitCCOutOperand(Mnemonic
, Operands
))
6961 Operands
.erase(Operands
.begin() + 1);
6963 // Some instructions have the same mnemonic, but don't always
6964 // have a predicate. Distinguish them here and delete the
6965 // appropriate predicate if needed. This could be either the scalar
6966 // predication code or the vector predication code.
6967 if (PredicationCode
== ARMCC::AL
&&
6968 shouldOmitPredicateOperand(Mnemonic
, Operands
))
6969 Operands
.erase(Operands
.begin() + 1);
6973 if (!shouldOmitVectorPredicateOperand(Mnemonic
, Operands
) &&
6974 Mnemonic
== "vmov" && PredicationCode
== ARMCC::LT
) {
6975 // Very nasty hack to deal with the vector predicated variant of vmovlt
6976 // the scalar predicated vmov with condition 'lt'. We can not tell them
6977 // apart until we have parsed their operands.
6978 Operands
.erase(Operands
.begin() + 1);
6979 Operands
.erase(Operands
.begin());
6980 SMLoc MLoc
= SMLoc::getFromPointer(NameLoc
.getPointer());
6981 SMLoc PLoc
= SMLoc::getFromPointer(NameLoc
.getPointer() +
6982 Mnemonic
.size() - 1 + CarrySetting
);
6983 Operands
.insert(Operands
.begin(),
6984 ARMOperand::CreateVPTPred(ARMVCC::None
, PLoc
));
6985 Operands
.insert(Operands
.begin(),
6986 ARMOperand::CreateToken(StringRef("vmovlt"), MLoc
));
6987 } else if (Mnemonic
== "vcvt" && PredicationCode
== ARMCC::NE
&&
6988 !shouldOmitVectorPredicateOperand(Mnemonic
, Operands
)) {
6989 // Another nasty hack to deal with the ambiguity between vcvt with scalar
6990 // predication 'ne' and vcvtn with vector predication 'e'. As above we
6991 // can only distinguish between the two after we have parsed their
6993 Operands
.erase(Operands
.begin() + 1);
6994 Operands
.erase(Operands
.begin());
6995 SMLoc MLoc
= SMLoc::getFromPointer(NameLoc
.getPointer());
6996 SMLoc PLoc
= SMLoc::getFromPointer(NameLoc
.getPointer() +
6997 Mnemonic
.size() - 1 + CarrySetting
);
6998 Operands
.insert(Operands
.begin(),
6999 ARMOperand::CreateVPTPred(ARMVCC::Else
, PLoc
));
7000 Operands
.insert(Operands
.begin(),
7001 ARMOperand::CreateToken(StringRef("vcvtn"), MLoc
));
7002 } else if (Mnemonic
== "vmul" && PredicationCode
== ARMCC::LT
&&
7003 !shouldOmitVectorPredicateOperand(Mnemonic
, Operands
)) {
7004 // Another hack, this time to distinguish between scalar predicated vmul
7005 // with 'lt' predication code and the vector instruction vmullt with
7006 // vector predication code "none"
7007 Operands
.erase(Operands
.begin() + 1);
7008 Operands
.erase(Operands
.begin());
7009 SMLoc MLoc
= SMLoc::getFromPointer(NameLoc
.getPointer());
7010 Operands
.insert(Operands
.begin(),
7011 ARMOperand::CreateToken(StringRef("vmullt"), MLoc
));
7013 // For vmov and vcmp, as mentioned earlier, we did not add the vector
7014 // predication code, since these may contain operands that require
7015 // special parsing. So now we have to see if they require vector
7016 // predication and replace the scalar one with the vector predication
7017 // operand if that is the case.
7018 else if (Mnemonic
== "vmov" || Mnemonic
.startswith("vcmp") ||
7019 (Mnemonic
.startswith("vcvt") && !Mnemonic
.startswith("vcvta") &&
7020 !Mnemonic
.startswith("vcvtn") && !Mnemonic
.startswith("vcvtp") &&
7021 !Mnemonic
.startswith("vcvtm"))) {
7022 if (!shouldOmitVectorPredicateOperand(Mnemonic
, Operands
)) {
7023 // We could not split the vector predicate off vcvt because it might
7024 // have been the scalar vcvtt instruction. Now we know its a vector
7025 // instruction, we still need to check whether its the vector
7026 // predicated vcvt with 'Then' predication or the vector vcvtt. We can
7027 // distinguish the two based on the suffixes, if it is any of
7028 // ".f16.f32", ".f32.f16", ".f16.f64" or ".f64.f16" then it is the vcvtt.
7029 if (Mnemonic
.startswith("vcvtt") && Operands
.size() >= 4) {
7030 auto Sz1
= static_cast<ARMOperand
&>(*Operands
[2]);
7031 auto Sz2
= static_cast<ARMOperand
&>(*Operands
[3]);
7032 if (!(Sz1
.isToken() && Sz1
.getToken().startswith(".f") &&
7033 Sz2
.isToken() && Sz2
.getToken().startswith(".f"))) {
7034 Operands
.erase(Operands
.begin());
7035 SMLoc MLoc
= SMLoc::getFromPointer(NameLoc
.getPointer());
7036 VPTPredicationCode
= ARMVCC::Then
;
7038 Mnemonic
= Mnemonic
.substr(0, 4);
7039 Operands
.insert(Operands
.begin(),
7040 ARMOperand::CreateToken(Mnemonic
, MLoc
));
7043 Operands
.erase(Operands
.begin() + 1);
7044 SMLoc PLoc
= SMLoc::getFromPointer(NameLoc
.getPointer() +
7045 Mnemonic
.size() + CarrySetting
);
7046 Operands
.insert(Operands
.begin() + 1,
7047 ARMOperand::CreateVPTPred(
7048 ARMVCC::VPTCodes(VPTPredicationCode
), PLoc
));
7050 } else if (CanAcceptVPTPredicationCode
) {
7051 // For all other instructions, make sure only one of the two
7052 // predication operands is left behind, depending on whether we should
7053 // use the vector predication.
7054 if (shouldOmitVectorPredicateOperand(Mnemonic
, Operands
)) {
7055 if (CanAcceptPredicationCode
)
7056 Operands
.erase(Operands
.begin() + 2);
7058 Operands
.erase(Operands
.begin() + 1);
7059 } else if (CanAcceptPredicationCode
&& PredicationCode
== ARMCC::AL
) {
7060 Operands
.erase(Operands
.begin() + 1);
7065 if (VPTPredicationCode
!= ARMVCC::None
) {
7066 bool usedVPTPredicationCode
= false;
7067 for (unsigned I
= 1; I
< Operands
.size(); ++I
)
7068 if (static_cast<ARMOperand
&>(*Operands
[I
]).isVPTPred())
7069 usedVPTPredicationCode
= true;
7070 if (!usedVPTPredicationCode
) {
7071 // If we have a VPT predication code and we haven't just turned it
7072 // into an operand, then it was a mistake for splitMnemonic to
7073 // separate it from the rest of the mnemonic in the first place,
7074 // and this may lead to wrong disassembly (e.g. scalar floating
7075 // point VCMPE is actually a different instruction from VCMP, so
7076 // we mustn't treat them the same). In that situation, glue it
7078 Mnemonic
= Name
.slice(0, Mnemonic
.size() + 1);
7079 Operands
.erase(Operands
.begin());
7080 Operands
.insert(Operands
.begin(),
7081 ARMOperand::CreateToken(Mnemonic
, NameLoc
));
7085 // ARM mode 'blx' need special handling, as the register operand version
7086 // is predicable, but the label operand version is not. So, we can't rely
7087 // on the Mnemonic based checking to correctly figure out when to put
7088 // a k_CondCode operand in the list. If we're trying to match the label
7089 // version, remove the k_CondCode operand here.
7090 if (!isThumb() && Mnemonic
== "blx" && Operands
.size() == 3 &&
7091 static_cast<ARMOperand
&>(*Operands
[2]).isImm())
7092 Operands
.erase(Operands
.begin() + 1);
7094 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
7095 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
7096 // a single GPRPair reg operand is used in the .td file to replace the two
7097 // GPRs. However, when parsing from asm, the two GRPs cannot be
7099 // expressed as a GPRPair, so we have to manually merge them.
7100 // FIXME: We would really like to be able to tablegen'erate this.
7101 if (!isThumb() && Operands
.size() > 4 &&
7102 (Mnemonic
== "ldrexd" || Mnemonic
== "strexd" || Mnemonic
== "ldaexd" ||
7103 Mnemonic
== "stlexd")) {
7104 bool isLoad
= (Mnemonic
== "ldrexd" || Mnemonic
== "ldaexd");
7105 unsigned Idx
= isLoad
? 2 : 3;
7106 ARMOperand
&Op1
= static_cast<ARMOperand
&>(*Operands
[Idx
]);
7107 ARMOperand
&Op2
= static_cast<ARMOperand
&>(*Operands
[Idx
+ 1]);
7109 const MCRegisterClass
&MRC
= MRI
->getRegClass(ARM::GPRRegClassID
);
7110 // Adjust only if Op1 and Op2 are GPRs.
7111 if (Op1
.isReg() && Op2
.isReg() && MRC
.contains(Op1
.getReg()) &&
7112 MRC
.contains(Op2
.getReg())) {
7113 unsigned Reg1
= Op1
.getReg();
7114 unsigned Reg2
= Op2
.getReg();
7115 unsigned Rt
= MRI
->getEncodingValue(Reg1
);
7116 unsigned Rt2
= MRI
->getEncodingValue(Reg2
);
7118 // Rt2 must be Rt + 1 and Rt must be even.
7119 if (Rt
+ 1 != Rt2
|| (Rt
& 1)) {
7120 return Error(Op2
.getStartLoc(),
7121 isLoad
? "destination operands must be sequential"
7122 : "source operands must be sequential");
7124 unsigned NewReg
= MRI
->getMatchingSuperReg(
7125 Reg1
, ARM::gsub_0
, &(MRI
->getRegClass(ARM::GPRPairRegClassID
)));
7127 ARMOperand::CreateReg(NewReg
, Op1
.getStartLoc(), Op2
.getEndLoc());
7128 Operands
.erase(Operands
.begin() + Idx
+ 1);
7132 // GNU Assembler extension (compatibility).
7133 fixupGNULDRDAlias(Mnemonic
, Operands
);
7135 // FIXME: As said above, this is all a pretty gross hack. This instruction
7136 // does not fit with other "subs" and tblgen.
7137 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
7138 // so the Mnemonic is the original name "subs" and delete the predicate
7139 // operand so it will match the table entry.
7140 if (isThumbTwo() && Mnemonic
== "sub" && Operands
.size() == 6 &&
7141 static_cast<ARMOperand
&>(*Operands
[3]).isReg() &&
7142 static_cast<ARMOperand
&>(*Operands
[3]).getReg() == ARM::PC
&&
7143 static_cast<ARMOperand
&>(*Operands
[4]).isReg() &&
7144 static_cast<ARMOperand
&>(*Operands
[4]).getReg() == ARM::LR
&&
7145 static_cast<ARMOperand
&>(*Operands
[5]).isImm()) {
7146 Operands
.front() = ARMOperand::CreateToken(Name
, NameLoc
);
7147 Operands
.erase(Operands
.begin() + 1);
7152 // Validate context-sensitive operand constraints.
7154 // return 'true' if register list contains non-low GPR registers,
7155 // 'false' otherwise. If Reg is in the register list or is HiReg, set
7156 // 'containsReg' to true.
7157 static bool checkLowRegisterList(const MCInst
&Inst
, unsigned OpNo
,
7158 unsigned Reg
, unsigned HiReg
,
7159 bool &containsReg
) {
7160 containsReg
= false;
7161 for (unsigned i
= OpNo
; i
< Inst
.getNumOperands(); ++i
) {
7162 unsigned OpReg
= Inst
.getOperand(i
).getReg();
7165 // Anything other than a low register isn't legal here.
7166 if (!isARMLowRegister(OpReg
) && (!HiReg
|| OpReg
!= HiReg
))
7172 // Check if the specified regisgter is in the register list of the inst,
7173 // starting at the indicated operand number.
7174 static bool listContainsReg(const MCInst
&Inst
, unsigned OpNo
, unsigned Reg
) {
7175 for (unsigned i
= OpNo
, e
= Inst
.getNumOperands(); i
< e
; ++i
) {
7176 unsigned OpReg
= Inst
.getOperand(i
).getReg();
7183 // Return true if instruction has the interesting property of being
7184 // allowed in IT blocks, but not being predicable.
7185 static bool instIsBreakpoint(const MCInst
&Inst
) {
7186 return Inst
.getOpcode() == ARM::tBKPT
||
7187 Inst
.getOpcode() == ARM::BKPT
||
7188 Inst
.getOpcode() == ARM::tHLT
||
7189 Inst
.getOpcode() == ARM::HLT
;
7192 bool ARMAsmParser::validatetLDMRegList(const MCInst
&Inst
,
7193 const OperandVector
&Operands
,
7194 unsigned ListNo
, bool IsARPop
) {
7195 const ARMOperand
&Op
= static_cast<const ARMOperand
&>(*Operands
[ListNo
]);
7196 bool HasWritebackToken
= Op
.isToken() && Op
.getToken() == "!";
7198 bool ListContainsSP
= listContainsReg(Inst
, ListNo
, ARM::SP
);
7199 bool ListContainsLR
= listContainsReg(Inst
, ListNo
, ARM::LR
);
7200 bool ListContainsPC
= listContainsReg(Inst
, ListNo
, ARM::PC
);
7202 if (!IsARPop
&& ListContainsSP
)
7203 return Error(Operands
[ListNo
+ HasWritebackToken
]->getStartLoc(),
7204 "SP may not be in the register list");
7205 else if (ListContainsPC
&& ListContainsLR
)
7206 return Error(Operands
[ListNo
+ HasWritebackToken
]->getStartLoc(),
7207 "PC and LR may not be in the register list simultaneously");
7211 bool ARMAsmParser::validatetSTMRegList(const MCInst
&Inst
,
7212 const OperandVector
&Operands
,
7214 const ARMOperand
&Op
= static_cast<const ARMOperand
&>(*Operands
[ListNo
]);
7215 bool HasWritebackToken
= Op
.isToken() && Op
.getToken() == "!";
7217 bool ListContainsSP
= listContainsReg(Inst
, ListNo
, ARM::SP
);
7218 bool ListContainsPC
= listContainsReg(Inst
, ListNo
, ARM::PC
);
7220 if (ListContainsSP
&& ListContainsPC
)
7221 return Error(Operands
[ListNo
+ HasWritebackToken
]->getStartLoc(),
7222 "SP and PC may not be in the register list");
7223 else if (ListContainsSP
)
7224 return Error(Operands
[ListNo
+ HasWritebackToken
]->getStartLoc(),
7225 "SP may not be in the register list");
7226 else if (ListContainsPC
)
7227 return Error(Operands
[ListNo
+ HasWritebackToken
]->getStartLoc(),
7228 "PC may not be in the register list");
7232 bool ARMAsmParser::validateLDRDSTRD(MCInst
&Inst
,
7233 const OperandVector
&Operands
,
7234 bool Load
, bool ARMMode
, bool Writeback
) {
7235 unsigned RtIndex
= Load
|| !Writeback
? 0 : 1;
7236 unsigned Rt
= MRI
->getEncodingValue(Inst
.getOperand(RtIndex
).getReg());
7237 unsigned Rt2
= MRI
->getEncodingValue(Inst
.getOperand(RtIndex
+ 1).getReg());
7242 return Error(Operands
[3]->getStartLoc(),
7245 // Rt must be even-numbered.
7247 return Error(Operands
[3]->getStartLoc(),
7248 "Rt must be even-numbered");
7250 // Rt2 must be Rt + 1.
7251 if (Rt2
!= Rt
+ 1) {
7253 return Error(Operands
[3]->getStartLoc(),
7254 "destination operands must be sequential");
7256 return Error(Operands
[3]->getStartLoc(),
7257 "source operands must be sequential");
7260 // FIXME: Diagnose m == 15
7261 // FIXME: Diagnose ldrd with m == t || m == t2.
7264 if (!ARMMode
&& Load
) {
7266 return Error(Operands
[3]->getStartLoc(),
7267 "destination operands can't be identical");
7271 unsigned Rn
= MRI
->getEncodingValue(Inst
.getOperand(3).getReg());
7273 if (Rn
== Rt
|| Rn
== Rt2
) {
7275 return Error(Operands
[3]->getStartLoc(),
7276 "base register needs to be different from destination "
7279 return Error(Operands
[3]->getStartLoc(),
7280 "source register and base register can't be identical");
7283 // FIXME: Diagnose ldrd/strd with writeback and n == 15.
7284 // (Except the immediate form of ldrd?)
7290 static int findFirstVectorPredOperandIdx(const MCInstrDesc
&MCID
) {
7291 for (unsigned i
= 0; i
< MCID
.NumOperands
; ++i
) {
7292 if (ARM::isVpred(MCID
.OpInfo
[i
].OperandType
))
7298 static bool isVectorPredicable(const MCInstrDesc
&MCID
) {
7299 return findFirstVectorPredOperandIdx(MCID
) != -1;
7302 // FIXME: We would really like to be able to tablegen'erate this.
7303 bool ARMAsmParser::validateInstruction(MCInst
&Inst
,
7304 const OperandVector
&Operands
) {
7305 const MCInstrDesc
&MCID
= MII
.get(Inst
.getOpcode());
7306 SMLoc Loc
= Operands
[0]->getStartLoc();
7308 // Check the IT block state first.
7309 // NOTE: BKPT and HLT instructions have the interesting property of being
7310 // allowed in IT blocks, but not being predicable. They just always execute.
7311 if (inITBlock() && !instIsBreakpoint(Inst
)) {
7312 // The instruction must be predicable.
7313 if (!MCID
.isPredicable())
7314 return Error(Loc
, "instructions in IT block must be predicable");
7315 ARMCC::CondCodes Cond
= ARMCC::CondCodes(
7316 Inst
.getOperand(MCID
.findFirstPredOperandIdx()).getImm());
7317 if (Cond
!= currentITCond()) {
7318 // Find the condition code Operand to get its SMLoc information.
7320 for (unsigned I
= 1; I
< Operands
.size(); ++I
)
7321 if (static_cast<ARMOperand
&>(*Operands
[I
]).isCondCode())
7322 CondLoc
= Operands
[I
]->getStartLoc();
7323 return Error(CondLoc
, "incorrect condition in IT block; got '" +
7324 StringRef(ARMCondCodeToString(Cond
)) +
7325 "', but expected '" +
7326 ARMCondCodeToString(currentITCond()) + "'");
7328 // Check for non-'al' condition codes outside of the IT block.
7329 } else if (isThumbTwo() && MCID
.isPredicable() &&
7330 Inst
.getOperand(MCID
.findFirstPredOperandIdx()).getImm() !=
7331 ARMCC::AL
&& Inst
.getOpcode() != ARM::tBcc
&&
7332 Inst
.getOpcode() != ARM::t2Bcc
&&
7333 Inst
.getOpcode() != ARM::t2BFic
) {
7334 return Error(Loc
, "predicated instructions must be in IT block");
7335 } else if (!isThumb() && !useImplicitITARM() && MCID
.isPredicable() &&
7336 Inst
.getOperand(MCID
.findFirstPredOperandIdx()).getImm() !=
7338 return Warning(Loc
, "predicated instructions should be in IT block");
7339 } else if (!MCID
.isPredicable()) {
7340 // Check the instruction doesn't have a predicate operand anyway
7341 // that it's not allowed to use. Sometimes this happens in order
7342 // to keep instructions the same shape even though one cannot
7343 // legally be predicated, e.g. vmul.f16 vs vmul.f32.
7344 for (unsigned i
= 0, e
= MCID
.getNumOperands(); i
!= e
; ++i
) {
7345 if (MCID
.OpInfo
[i
].isPredicate()) {
7346 if (Inst
.getOperand(i
).getImm() != ARMCC::AL
)
7347 return Error(Loc
, "instruction is not predicable");
7353 // PC-setting instructions in an IT block, but not the last instruction of
7354 // the block, are UNPREDICTABLE.
7355 if (inExplicitITBlock() && !lastInITBlock() && isITBlockTerminator(Inst
)) {
7356 return Error(Loc
, "instruction must be outside of IT block or the last instruction in an IT block");
7359 if (inVPTBlock() && !instIsBreakpoint(Inst
)) {
7360 unsigned Bit
= extractITMaskBit(VPTState
.Mask
, VPTState
.CurPosition
);
7361 if (!isVectorPredicable(MCID
))
7362 return Error(Loc
, "instruction in VPT block must be predicable");
7363 unsigned Pred
= Inst
.getOperand(findFirstVectorPredOperandIdx(MCID
)).getImm();
7364 unsigned VPTPred
= Bit
? ARMVCC::Else
: ARMVCC::Then
;
7365 if (Pred
!= VPTPred
) {
7367 for (unsigned I
= 1; I
< Operands
.size(); ++I
)
7368 if (static_cast<ARMOperand
&>(*Operands
[I
]).isVPTPred())
7369 PredLoc
= Operands
[I
]->getStartLoc();
7370 return Error(PredLoc
, "incorrect predication in VPT block; got '" +
7371 StringRef(ARMVPTPredToString(ARMVCC::VPTCodes(Pred
))) +
7372 "', but expected '" +
7373 ARMVPTPredToString(ARMVCC::VPTCodes(VPTPred
)) + "'");
7376 else if (isVectorPredicable(MCID
) &&
7377 Inst
.getOperand(findFirstVectorPredOperandIdx(MCID
)).getImm() !=
7379 return Error(Loc
, "VPT predicated instructions must be in VPT block");
7381 const unsigned Opcode
= Inst
.getOpcode();
7384 // Encoding is unpredictable if it ever results in a notional 'NV'
7385 // predicate. Since we don't parse 'NV' directly this means an 'AL'
7386 // predicate with an "else" mask bit.
7387 unsigned Cond
= Inst
.getOperand(0).getImm();
7388 unsigned Mask
= Inst
.getOperand(1).getImm();
7390 // Conditions only allowing a 't' are those with no set bit except
7391 // the lowest-order one that indicates the end of the sequence. In
7392 // other words, powers of 2.
7393 if (Cond
== ARMCC::AL
&& countPopulation(Mask
) != 1)
7394 return Error(Loc
, "unpredictable IT predicate sequence");
7398 if (validateLDRDSTRD(Inst
, Operands
, /*Load*/true, /*ARMMode*/true,
7399 /*Writeback*/false))
7403 case ARM::LDRD_POST
:
7404 if (validateLDRDSTRD(Inst
, Operands
, /*Load*/true, /*ARMMode*/true,
7409 if (validateLDRDSTRD(Inst
, Operands
, /*Load*/true, /*ARMMode*/false,
7410 /*Writeback*/false))
7413 case ARM::t2LDRD_PRE
:
7414 case ARM::t2LDRD_POST
:
7415 if (validateLDRDSTRD(Inst
, Operands
, /*Load*/true, /*ARMMode*/false,
7420 const unsigned RmReg
= Inst
.getOperand(0).getReg();
7421 // Rm = SP is no longer unpredictable in v8-A
7422 if (RmReg
== ARM::SP
&& !hasV8Ops())
7423 return Error(Operands
[2]->getStartLoc(),
7424 "r13 (SP) is an unpredictable operand to BXJ");
7428 if (validateLDRDSTRD(Inst
, Operands
, /*Load*/false, /*ARMMode*/true,
7429 /*Writeback*/false))
7433 case ARM::STRD_POST
:
7434 if (validateLDRDSTRD(Inst
, Operands
, /*Load*/false, /*ARMMode*/true,
7438 case ARM::t2STRD_PRE
:
7439 case ARM::t2STRD_POST
:
7440 if (validateLDRDSTRD(Inst
, Operands
, /*Load*/false, /*ARMMode*/false,
7444 case ARM::STR_PRE_IMM
:
7445 case ARM::STR_PRE_REG
:
7446 case ARM::t2STR_PRE
:
7447 case ARM::STR_POST_IMM
:
7448 case ARM::STR_POST_REG
:
7449 case ARM::t2STR_POST
:
7451 case ARM::t2STRH_PRE
:
7452 case ARM::STRH_POST
:
7453 case ARM::t2STRH_POST
:
7454 case ARM::STRB_PRE_IMM
:
7455 case ARM::STRB_PRE_REG
:
7456 case ARM::t2STRB_PRE
:
7457 case ARM::STRB_POST_IMM
:
7458 case ARM::STRB_POST_REG
:
7459 case ARM::t2STRB_POST
: {
7460 // Rt must be different from Rn.
7461 const unsigned Rt
= MRI
->getEncodingValue(Inst
.getOperand(1).getReg());
7462 const unsigned Rn
= MRI
->getEncodingValue(Inst
.getOperand(2).getReg());
7465 return Error(Operands
[3]->getStartLoc(),
7466 "source register and base register can't be identical");
7469 case ARM::LDR_PRE_IMM
:
7470 case ARM::LDR_PRE_REG
:
7471 case ARM::t2LDR_PRE
:
7472 case ARM::LDR_POST_IMM
:
7473 case ARM::LDR_POST_REG
:
7474 case ARM::t2LDR_POST
:
7476 case ARM::t2LDRH_PRE
:
7477 case ARM::LDRH_POST
:
7478 case ARM::t2LDRH_POST
:
7479 case ARM::LDRSH_PRE
:
7480 case ARM::t2LDRSH_PRE
:
7481 case ARM::LDRSH_POST
:
7482 case ARM::t2LDRSH_POST
:
7483 case ARM::LDRB_PRE_IMM
:
7484 case ARM::LDRB_PRE_REG
:
7485 case ARM::t2LDRB_PRE
:
7486 case ARM::LDRB_POST_IMM
:
7487 case ARM::LDRB_POST_REG
:
7488 case ARM::t2LDRB_POST
:
7489 case ARM::LDRSB_PRE
:
7490 case ARM::t2LDRSB_PRE
:
7491 case ARM::LDRSB_POST
:
7492 case ARM::t2LDRSB_POST
: {
7493 // Rt must be different from Rn.
7494 const unsigned Rt
= MRI
->getEncodingValue(Inst
.getOperand(0).getReg());
7495 const unsigned Rn
= MRI
->getEncodingValue(Inst
.getOperand(2).getReg());
7498 return Error(Operands
[3]->getStartLoc(),
7499 "destination register and base register can't be identical");
7503 case ARM::MVE_VLDRBU8_rq
:
7504 case ARM::MVE_VLDRBU16_rq
:
7505 case ARM::MVE_VLDRBS16_rq
:
7506 case ARM::MVE_VLDRBU32_rq
:
7507 case ARM::MVE_VLDRBS32_rq
:
7508 case ARM::MVE_VLDRHU16_rq
:
7509 case ARM::MVE_VLDRHU16_rq_u
:
7510 case ARM::MVE_VLDRHU32_rq
:
7511 case ARM::MVE_VLDRHU32_rq_u
:
7512 case ARM::MVE_VLDRHS32_rq
:
7513 case ARM::MVE_VLDRHS32_rq_u
:
7514 case ARM::MVE_VLDRWU32_rq
:
7515 case ARM::MVE_VLDRWU32_rq_u
:
7516 case ARM::MVE_VLDRDU64_rq
:
7517 case ARM::MVE_VLDRDU64_rq_u
:
7518 case ARM::MVE_VLDRWU32_qi
:
7519 case ARM::MVE_VLDRWU32_qi_pre
:
7520 case ARM::MVE_VLDRDU64_qi
:
7521 case ARM::MVE_VLDRDU64_qi_pre
: {
7522 // Qd must be different from Qm.
7523 unsigned QdIdx
= 0, QmIdx
= 2;
7524 bool QmIsPointer
= false;
7526 case ARM::MVE_VLDRWU32_qi
:
7527 case ARM::MVE_VLDRDU64_qi
:
7531 case ARM::MVE_VLDRWU32_qi_pre
:
7532 case ARM::MVE_VLDRDU64_qi_pre
:
7538 const unsigned Qd
= MRI
->getEncodingValue(Inst
.getOperand(QdIdx
).getReg());
7539 const unsigned Qm
= MRI
->getEncodingValue(Inst
.getOperand(QmIdx
).getReg());
7542 return Error(Operands
[3]->getStartLoc(),
7543 Twine("destination vector register and vector ") +
7544 (QmIsPointer
? "pointer" : "offset") +
7545 " register can't be identical");
7554 // Width must be in range [1, 32-lsb].
7555 unsigned LSB
= Inst
.getOperand(2).getImm();
7556 unsigned Widthm1
= Inst
.getOperand(3).getImm();
7557 if (Widthm1
>= 32 - LSB
)
7558 return Error(Operands
[5]->getStartLoc(),
7559 "bitfield width must be in range [1,32-lsb]");
7562 // Notionally handles ARM::tLDMIA_UPD too.
7564 // If we're parsing Thumb2, the .w variant is available and handles
7565 // most cases that are normally illegal for a Thumb1 LDM instruction.
7566 // We'll make the transformation in processInstruction() if necessary.
7568 // Thumb LDM instructions are writeback iff the base register is not
7569 // in the register list.
7570 unsigned Rn
= Inst
.getOperand(0).getReg();
7571 bool HasWritebackToken
=
7572 (static_cast<ARMOperand
&>(*Operands
[3]).isToken() &&
7573 static_cast<ARMOperand
&>(*Operands
[3]).getToken() == "!");
7574 bool ListContainsBase
;
7575 if (checkLowRegisterList(Inst
, 3, Rn
, 0, ListContainsBase
) && !isThumbTwo())
7576 return Error(Operands
[3 + HasWritebackToken
]->getStartLoc(),
7577 "registers must be in range r0-r7");
7578 // If we should have writeback, then there should be a '!' token.
7579 if (!ListContainsBase
&& !HasWritebackToken
&& !isThumbTwo())
7580 return Error(Operands
[2]->getStartLoc(),
7581 "writeback operator '!' expected");
7582 // If we should not have writeback, there must not be a '!'. This is
7583 // true even for the 32-bit wide encodings.
7584 if (ListContainsBase
&& HasWritebackToken
)
7585 return Error(Operands
[3]->getStartLoc(),
7586 "writeback operator '!' not allowed when base register "
7587 "in register list");
7589 if (validatetLDMRegList(Inst
, Operands
, 3))
7593 case ARM::LDMIA_UPD
:
7594 case ARM::LDMDB_UPD
:
7595 case ARM::LDMIB_UPD
:
7596 case ARM::LDMDA_UPD
:
7597 // ARM variants loading and updating the same register are only officially
7598 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
7601 if (listContainsReg(Inst
, 3, Inst
.getOperand(0).getReg()))
7602 return Error(Operands
.back()->getStartLoc(),
7603 "writeback register not allowed in register list");
7607 if (validatetLDMRegList(Inst
, Operands
, 3))
7612 if (validatetSTMRegList(Inst
, Operands
, 3))
7615 case ARM::t2LDMIA_UPD
:
7616 case ARM::t2LDMDB_UPD
:
7617 case ARM::t2STMIA_UPD
:
7618 case ARM::t2STMDB_UPD
:
7619 if (listContainsReg(Inst
, 3, Inst
.getOperand(0).getReg()))
7620 return Error(Operands
.back()->getStartLoc(),
7621 "writeback register not allowed in register list");
7623 if (Opcode
== ARM::t2LDMIA_UPD
|| Opcode
== ARM::t2LDMDB_UPD
) {
7624 if (validatetLDMRegList(Inst
, Operands
, 3))
7627 if (validatetSTMRegList(Inst
, Operands
, 3))
7632 case ARM::sysLDMIA_UPD
:
7633 case ARM::sysLDMDA_UPD
:
7634 case ARM::sysLDMDB_UPD
:
7635 case ARM::sysLDMIB_UPD
:
7636 if (!listContainsReg(Inst
, 3, ARM::PC
))
7637 return Error(Operands
[4]->getStartLoc(),
7638 "writeback register only allowed on system LDM "
7639 "if PC in register-list");
7641 case ARM::sysSTMIA_UPD
:
7642 case ARM::sysSTMDA_UPD
:
7643 case ARM::sysSTMDB_UPD
:
7644 case ARM::sysSTMIB_UPD
:
7645 return Error(Operands
[2]->getStartLoc(),
7646 "system STM cannot have writeback register");
7648 // The second source operand must be the same register as the destination
7651 // In this case, we must directly check the parsed operands because the
7652 // cvtThumbMultiply() function is written in such a way that it guarantees
7653 // this first statement is always true for the new Inst. Essentially, the
7654 // destination is unconditionally copied into the second source operand
7655 // without checking to see if it matches what we actually parsed.
7656 if (Operands
.size() == 6 && (((ARMOperand
&)*Operands
[3]).getReg() !=
7657 ((ARMOperand
&)*Operands
[5]).getReg()) &&
7658 (((ARMOperand
&)*Operands
[3]).getReg() !=
7659 ((ARMOperand
&)*Operands
[4]).getReg())) {
7660 return Error(Operands
[3]->getStartLoc(),
7661 "destination register must match source register");
7665 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
7666 // so only issue a diagnostic for thumb1. The instructions will be
7667 // switched to the t2 encodings in processInstruction() if necessary.
7669 bool ListContainsBase
;
7670 if (checkLowRegisterList(Inst
, 2, 0, ARM::PC
, ListContainsBase
) &&
7672 return Error(Operands
[2]->getStartLoc(),
7673 "registers must be in range r0-r7 or pc");
7674 if (validatetLDMRegList(Inst
, Operands
, 2, !isMClass()))
7679 bool ListContainsBase
;
7680 if (checkLowRegisterList(Inst
, 2, 0, ARM::LR
, ListContainsBase
) &&
7682 return Error(Operands
[2]->getStartLoc(),
7683 "registers must be in range r0-r7 or lr");
7684 if (validatetSTMRegList(Inst
, Operands
, 2))
7688 case ARM::tSTMIA_UPD
: {
7689 bool ListContainsBase
, InvalidLowList
;
7690 InvalidLowList
= checkLowRegisterList(Inst
, 4, Inst
.getOperand(0).getReg(),
7691 0, ListContainsBase
);
7692 if (InvalidLowList
&& !isThumbTwo())
7693 return Error(Operands
[4]->getStartLoc(),
7694 "registers must be in range r0-r7");
7696 // This would be converted to a 32-bit stm, but that's not valid if the
7697 // writeback register is in the list.
7698 if (InvalidLowList
&& ListContainsBase
)
7699 return Error(Operands
[4]->getStartLoc(),
7700 "writeback operator '!' not allowed when base register "
7701 "in register list");
7703 if (validatetSTMRegList(Inst
, Operands
, 4))
7708 // If the non-SP source operand and the destination operand are not the
7709 // same, we need thumb2 (for the wide encoding), or we have an error.
7710 if (!isThumbTwo() &&
7711 Inst
.getOperand(0).getReg() != Inst
.getOperand(2).getReg()) {
7712 return Error(Operands
[4]->getStartLoc(),
7713 "source register must be the same as destination");
7718 case ARM::t2ADDri12
:
7722 case ARM::t2SUBri12
:
7725 if (Inst
.getOperand(0).getReg() == ARM::SP
&&
7726 Inst
.getOperand(1).getReg() != ARM::SP
)
7727 return Error(Operands
[4]->getStartLoc(),
7728 "source register must be sp if destination is sp");
7731 // Final range checking for Thumb unconditional branch instructions.
7733 if (!(static_cast<ARMOperand
&>(*Operands
[2])).isSignedOffset
<11, 1>())
7734 return Error(Operands
[2]->getStartLoc(), "branch target out of range");
7737 int op
= (Operands
[2]->isImm()) ? 2 : 3;
7738 if (!static_cast<ARMOperand
&>(*Operands
[op
]).isSignedOffset
<24, 1>())
7739 return Error(Operands
[op
]->getStartLoc(), "branch target out of range");
7742 // Final range checking for Thumb conditional branch instructions.
7744 if (!static_cast<ARMOperand
&>(*Operands
[2]).isSignedOffset
<8, 1>())
7745 return Error(Operands
[2]->getStartLoc(), "branch target out of range");
7748 int Op
= (Operands
[2]->isImm()) ? 2 : 3;
7749 if (!static_cast<ARMOperand
&>(*Operands
[Op
]).isSignedOffset
<20, 1>())
7750 return Error(Operands
[Op
]->getStartLoc(), "branch target out of range");
7755 if (!static_cast<ARMOperand
&>(*Operands
[2]).isUnsignedOffset
<6, 1>())
7756 return Error(Operands
[2]->getStartLoc(), "branch target out of range");
7762 case ARM::t2MOVTi16
:
7764 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
7765 // especially when we turn it into a movw and the expression <symbol> does
7766 // not have a :lower16: or :upper16 as part of the expression. We don't
7767 // want the behavior of silently truncating, which can be unexpected and
7768 // lead to bugs that are difficult to find since this is an easy mistake
7770 int i
= (Operands
[3]->isImm()) ? 3 : 4;
7771 ARMOperand
&Op
= static_cast<ARMOperand
&>(*Operands
[i
]);
7772 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Op
.getImm());
7774 const MCExpr
*E
= dyn_cast
<MCExpr
>(Op
.getImm());
7776 const ARMMCExpr
*ARM16Expr
= dyn_cast
<ARMMCExpr
>(E
);
7777 if (!ARM16Expr
|| (ARM16Expr
->getKind() != ARMMCExpr::VK_ARM_HI16
&&
7778 ARM16Expr
->getKind() != ARMMCExpr::VK_ARM_LO16
))
7781 "immediate expression for mov requires :lower16: or :upper16");
7786 unsigned Imm8
= Inst
.getOperand(0).getImm();
7787 unsigned Pred
= Inst
.getOperand(1).getImm();
7788 // ESB is not predicable (pred must be AL). Without the RAS extension, this
7789 // behaves as any other unallocated hint.
7790 if (Imm8
== 0x10 && Pred
!= ARMCC::AL
&& hasRAS())
7791 return Error(Operands
[1]->getStartLoc(), "instruction 'esb' is not "
7792 "predicable, but condition "
7794 if (Imm8
== 0x14 && Pred
!= ARMCC::AL
)
7795 return Error(Operands
[1]->getStartLoc(), "instruction 'csdb' is not "
7796 "predicable, but condition "
7804 if (!static_cast<ARMOperand
&>(*Operands
[2]).isUnsignedOffset
<4, 1>() ||
7805 (Inst
.getOperand(0).isImm() && Inst
.getOperand(0).getImm() == 0))
7806 return Error(Operands
[2]->getStartLoc(),
7807 "branch location out of range or not a multiple of 2");
7809 if (Opcode
== ARM::t2BFi
) {
7810 if (!static_cast<ARMOperand
&>(*Operands
[3]).isSignedOffset
<16, 1>())
7811 return Error(Operands
[3]->getStartLoc(),
7812 "branch target out of range or not a multiple of 2");
7813 } else if (Opcode
== ARM::t2BFLi
) {
7814 if (!static_cast<ARMOperand
&>(*Operands
[3]).isSignedOffset
<18, 1>())
7815 return Error(Operands
[3]->getStartLoc(),
7816 "branch target out of range or not a multiple of 2");
7821 if (!static_cast<ARMOperand
&>(*Operands
[1]).isUnsignedOffset
<4, 1>() ||
7822 (Inst
.getOperand(0).isImm() && Inst
.getOperand(0).getImm() == 0))
7823 return Error(Operands
[1]->getStartLoc(),
7824 "branch location out of range or not a multiple of 2");
7826 if (!static_cast<ARMOperand
&>(*Operands
[2]).isSignedOffset
<16, 1>())
7827 return Error(Operands
[2]->getStartLoc(),
7828 "branch target out of range or not a multiple of 2");
7830 assert(Inst
.getOperand(0).isImm() == Inst
.getOperand(2).isImm() &&
7831 "branch location and else branch target should either both be "
7832 "immediates or both labels");
7834 if (Inst
.getOperand(0).isImm() && Inst
.getOperand(2).isImm()) {
7835 int Diff
= Inst
.getOperand(2).getImm() - Inst
.getOperand(0).getImm();
7836 if (Diff
!= 4 && Diff
!= 2)
7838 Operands
[3]->getStartLoc(),
7839 "else branch target must be 2 or 4 greater than the branch location");
7844 for (unsigned i
= 2; i
< Inst
.getNumOperands(); i
++) {
7845 if (Inst
.getOperand(i
).isReg() &&
7846 !ARMMCRegisterClasses
[ARM::GPRwithAPSRnospRegClassID
].contains(
7847 Inst
.getOperand(i
).getReg())) {
7848 return Error(Operands
[2]->getStartLoc(),
7849 "invalid register in register list. Valid registers are "
7850 "r0-r12, lr/r14 and APSR.");
7858 if (Inst
.getNumOperands() < 2)
7861 unsigned Option
= Inst
.getOperand(0).getImm();
7862 unsigned Pred
= Inst
.getOperand(1).getImm();
7864 // SSBB and PSSBB (DSB #0|#4) are not predicable (pred must be AL).
7865 if (Option
== 0 && Pred
!= ARMCC::AL
)
7866 return Error(Operands
[1]->getStartLoc(),
7867 "instruction 'ssbb' is not predicable, but condition code "
7869 if (Option
== 4 && Pred
!= ARMCC::AL
)
7870 return Error(Operands
[1]->getStartLoc(),
7871 "instruction 'pssbb' is not predicable, but condition code "
7875 case ARM::VMOVRRS
: {
7876 // Source registers must be sequential.
7877 const unsigned Sm
= MRI
->getEncodingValue(Inst
.getOperand(2).getReg());
7878 const unsigned Sm1
= MRI
->getEncodingValue(Inst
.getOperand(3).getReg());
7880 return Error(Operands
[5]->getStartLoc(),
7881 "source operands must be sequential");
7884 case ARM::VMOVSRR
: {
7885 // Destination registers must be sequential.
7886 const unsigned Sm
= MRI
->getEncodingValue(Inst
.getOperand(0).getReg());
7887 const unsigned Sm1
= MRI
->getEncodingValue(Inst
.getOperand(1).getReg());
7889 return Error(Operands
[3]->getStartLoc(),
7890 "destination operands must be sequential");
7894 case ARM::VSTMDIA
: {
7895 ARMOperand
&Op
= static_cast<ARMOperand
&>(*Operands
[3]);
7896 auto &RegList
= Op
.getRegList();
7897 if (RegList
.size() < 1 || RegList
.size() > 16)
7898 return Error(Operands
[3]->getStartLoc(),
7899 "list of registers must be at least 1 and at most 16");
7902 case ARM::MVE_VQDMULLs32bh
:
7903 case ARM::MVE_VQDMULLs32th
:
7904 case ARM::MVE_VCMULf32
:
7905 case ARM::MVE_VMULLs32bh
:
7906 case ARM::MVE_VMULLs32th
:
7907 case ARM::MVE_VMULLu32bh
:
7908 case ARM::MVE_VMULLu32th
: {
7909 if (Operands
[3]->getReg() == Operands
[4]->getReg()) {
7910 return Error (Operands
[3]->getStartLoc(),
7911 "Qd register and Qn register can't be identical");
7913 if (Operands
[3]->getReg() == Operands
[5]->getReg()) {
7914 return Error (Operands
[3]->getStartLoc(),
7915 "Qd register and Qm register can't be identical");
7919 case ARM::MVE_VMOV_rr_q
: {
7920 if (Operands
[4]->getReg() != Operands
[6]->getReg())
7921 return Error (Operands
[4]->getStartLoc(), "Q-registers must be the same");
7922 if (static_cast<ARMOperand
&>(*Operands
[5]).getVectorIndex() !=
7923 static_cast<ARMOperand
&>(*Operands
[7]).getVectorIndex() + 2)
7924 return Error (Operands
[5]->getStartLoc(), "Q-register indexes must be 2 and 0 or 3 and 1");
7927 case ARM::MVE_VMOV_q_rr
: {
7928 if (Operands
[2]->getReg() != Operands
[4]->getReg())
7929 return Error (Operands
[2]->getStartLoc(), "Q-registers must be the same");
7930 if (static_cast<ARMOperand
&>(*Operands
[3]).getVectorIndex() !=
7931 static_cast<ARMOperand
&>(*Operands
[5]).getVectorIndex() + 2)
7932 return Error (Operands
[3]->getStartLoc(), "Q-register indexes must be 2 and 0 or 3 and 1");
7940 static unsigned getRealVSTOpcode(unsigned Opc
, unsigned &Spacing
) {
7942 default: llvm_unreachable("unexpected opcode!");
7944 case ARM::VST1LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VST1LNd8_UPD
;
7945 case ARM::VST1LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST1LNd16_UPD
;
7946 case ARM::VST1LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VST1LNd32_UPD
;
7947 case ARM::VST1LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VST1LNd8_UPD
;
7948 case ARM::VST1LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VST1LNd16_UPD
;
7949 case ARM::VST1LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VST1LNd32_UPD
;
7950 case ARM::VST1LNdAsm_8
: Spacing
= 1; return ARM::VST1LNd8
;
7951 case ARM::VST1LNdAsm_16
: Spacing
= 1; return ARM::VST1LNd16
;
7952 case ARM::VST1LNdAsm_32
: Spacing
= 1; return ARM::VST1LNd32
;
7955 case ARM::VST2LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VST2LNd8_UPD
;
7956 case ARM::VST2LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST2LNd16_UPD
;
7957 case ARM::VST2LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VST2LNd32_UPD
;
7958 case ARM::VST2LNqWB_fixed_Asm_16
: Spacing
= 2; return ARM::VST2LNq16_UPD
;
7959 case ARM::VST2LNqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VST2LNq32_UPD
;
7961 case ARM::VST2LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VST2LNd8_UPD
;
7962 case ARM::VST2LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VST2LNd16_UPD
;
7963 case ARM::VST2LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VST2LNd32_UPD
;
7964 case ARM::VST2LNqWB_register_Asm_16
: Spacing
= 2; return ARM::VST2LNq16_UPD
;
7965 case ARM::VST2LNqWB_register_Asm_32
: Spacing
= 2; return ARM::VST2LNq32_UPD
;
7967 case ARM::VST2LNdAsm_8
: Spacing
= 1; return ARM::VST2LNd8
;
7968 case ARM::VST2LNdAsm_16
: Spacing
= 1; return ARM::VST2LNd16
;
7969 case ARM::VST2LNdAsm_32
: Spacing
= 1; return ARM::VST2LNd32
;
7970 case ARM::VST2LNqAsm_16
: Spacing
= 2; return ARM::VST2LNq16
;
7971 case ARM::VST2LNqAsm_32
: Spacing
= 2; return ARM::VST2LNq32
;
7974 case ARM::VST3LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VST3LNd8_UPD
;
7975 case ARM::VST3LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST3LNd16_UPD
;
7976 case ARM::VST3LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VST3LNd32_UPD
;
7977 case ARM::VST3LNqWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST3LNq16_UPD
;
7978 case ARM::VST3LNqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VST3LNq32_UPD
;
7979 case ARM::VST3LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VST3LNd8_UPD
;
7980 case ARM::VST3LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VST3LNd16_UPD
;
7981 case ARM::VST3LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VST3LNd32_UPD
;
7982 case ARM::VST3LNqWB_register_Asm_16
: Spacing
= 2; return ARM::VST3LNq16_UPD
;
7983 case ARM::VST3LNqWB_register_Asm_32
: Spacing
= 2; return ARM::VST3LNq32_UPD
;
7984 case ARM::VST3LNdAsm_8
: Spacing
= 1; return ARM::VST3LNd8
;
7985 case ARM::VST3LNdAsm_16
: Spacing
= 1; return ARM::VST3LNd16
;
7986 case ARM::VST3LNdAsm_32
: Spacing
= 1; return ARM::VST3LNd32
;
7987 case ARM::VST3LNqAsm_16
: Spacing
= 2; return ARM::VST3LNq16
;
7988 case ARM::VST3LNqAsm_32
: Spacing
= 2; return ARM::VST3LNq32
;
7991 case ARM::VST3dWB_fixed_Asm_8
: Spacing
= 1; return ARM::VST3d8_UPD
;
7992 case ARM::VST3dWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST3d16_UPD
;
7993 case ARM::VST3dWB_fixed_Asm_32
: Spacing
= 1; return ARM::VST3d32_UPD
;
7994 case ARM::VST3qWB_fixed_Asm_8
: Spacing
= 2; return ARM::VST3q8_UPD
;
7995 case ARM::VST3qWB_fixed_Asm_16
: Spacing
= 2; return ARM::VST3q16_UPD
;
7996 case ARM::VST3qWB_fixed_Asm_32
: Spacing
= 2; return ARM::VST3q32_UPD
;
7997 case ARM::VST3dWB_register_Asm_8
: Spacing
= 1; return ARM::VST3d8_UPD
;
7998 case ARM::VST3dWB_register_Asm_16
: Spacing
= 1; return ARM::VST3d16_UPD
;
7999 case ARM::VST3dWB_register_Asm_32
: Spacing
= 1; return ARM::VST3d32_UPD
;
8000 case ARM::VST3qWB_register_Asm_8
: Spacing
= 2; return ARM::VST3q8_UPD
;
8001 case ARM::VST3qWB_register_Asm_16
: Spacing
= 2; return ARM::VST3q16_UPD
;
8002 case ARM::VST3qWB_register_Asm_32
: Spacing
= 2; return ARM::VST3q32_UPD
;
8003 case ARM::VST3dAsm_8
: Spacing
= 1; return ARM::VST3d8
;
8004 case ARM::VST3dAsm_16
: Spacing
= 1; return ARM::VST3d16
;
8005 case ARM::VST3dAsm_32
: Spacing
= 1; return ARM::VST3d32
;
8006 case ARM::VST3qAsm_8
: Spacing
= 2; return ARM::VST3q8
;
8007 case ARM::VST3qAsm_16
: Spacing
= 2; return ARM::VST3q16
;
8008 case ARM::VST3qAsm_32
: Spacing
= 2; return ARM::VST3q32
;
8011 case ARM::VST4LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VST4LNd8_UPD
;
8012 case ARM::VST4LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST4LNd16_UPD
;
8013 case ARM::VST4LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VST4LNd32_UPD
;
8014 case ARM::VST4LNqWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST4LNq16_UPD
;
8015 case ARM::VST4LNqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VST4LNq32_UPD
;
8016 case ARM::VST4LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VST4LNd8_UPD
;
8017 case ARM::VST4LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VST4LNd16_UPD
;
8018 case ARM::VST4LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VST4LNd32_UPD
;
8019 case ARM::VST4LNqWB_register_Asm_16
: Spacing
= 2; return ARM::VST4LNq16_UPD
;
8020 case ARM::VST4LNqWB_register_Asm_32
: Spacing
= 2; return ARM::VST4LNq32_UPD
;
8021 case ARM::VST4LNdAsm_8
: Spacing
= 1; return ARM::VST4LNd8
;
8022 case ARM::VST4LNdAsm_16
: Spacing
= 1; return ARM::VST4LNd16
;
8023 case ARM::VST4LNdAsm_32
: Spacing
= 1; return ARM::VST4LNd32
;
8024 case ARM::VST4LNqAsm_16
: Spacing
= 2; return ARM::VST4LNq16
;
8025 case ARM::VST4LNqAsm_32
: Spacing
= 2; return ARM::VST4LNq32
;
8028 case ARM::VST4dWB_fixed_Asm_8
: Spacing
= 1; return ARM::VST4d8_UPD
;
8029 case ARM::VST4dWB_fixed_Asm_16
: Spacing
= 1; return ARM::VST4d16_UPD
;
8030 case ARM::VST4dWB_fixed_Asm_32
: Spacing
= 1; return ARM::VST4d32_UPD
;
8031 case ARM::VST4qWB_fixed_Asm_8
: Spacing
= 2; return ARM::VST4q8_UPD
;
8032 case ARM::VST4qWB_fixed_Asm_16
: Spacing
= 2; return ARM::VST4q16_UPD
;
8033 case ARM::VST4qWB_fixed_Asm_32
: Spacing
= 2; return ARM::VST4q32_UPD
;
8034 case ARM::VST4dWB_register_Asm_8
: Spacing
= 1; return ARM::VST4d8_UPD
;
8035 case ARM::VST4dWB_register_Asm_16
: Spacing
= 1; return ARM::VST4d16_UPD
;
8036 case ARM::VST4dWB_register_Asm_32
: Spacing
= 1; return ARM::VST4d32_UPD
;
8037 case ARM::VST4qWB_register_Asm_8
: Spacing
= 2; return ARM::VST4q8_UPD
;
8038 case ARM::VST4qWB_register_Asm_16
: Spacing
= 2; return ARM::VST4q16_UPD
;
8039 case ARM::VST4qWB_register_Asm_32
: Spacing
= 2; return ARM::VST4q32_UPD
;
8040 case ARM::VST4dAsm_8
: Spacing
= 1; return ARM::VST4d8
;
8041 case ARM::VST4dAsm_16
: Spacing
= 1; return ARM::VST4d16
;
8042 case ARM::VST4dAsm_32
: Spacing
= 1; return ARM::VST4d32
;
8043 case ARM::VST4qAsm_8
: Spacing
= 2; return ARM::VST4q8
;
8044 case ARM::VST4qAsm_16
: Spacing
= 2; return ARM::VST4q16
;
8045 case ARM::VST4qAsm_32
: Spacing
= 2; return ARM::VST4q32
;
8049 static unsigned getRealVLDOpcode(unsigned Opc
, unsigned &Spacing
) {
8051 default: llvm_unreachable("unexpected opcode!");
8053 case ARM::VLD1LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD1LNd8_UPD
;
8054 case ARM::VLD1LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD1LNd16_UPD
;
8055 case ARM::VLD1LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD1LNd32_UPD
;
8056 case ARM::VLD1LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VLD1LNd8_UPD
;
8057 case ARM::VLD1LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VLD1LNd16_UPD
;
8058 case ARM::VLD1LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VLD1LNd32_UPD
;
8059 case ARM::VLD1LNdAsm_8
: Spacing
= 1; return ARM::VLD1LNd8
;
8060 case ARM::VLD1LNdAsm_16
: Spacing
= 1; return ARM::VLD1LNd16
;
8061 case ARM::VLD1LNdAsm_32
: Spacing
= 1; return ARM::VLD1LNd32
;
8064 case ARM::VLD2LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD2LNd8_UPD
;
8065 case ARM::VLD2LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD2LNd16_UPD
;
8066 case ARM::VLD2LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD2LNd32_UPD
;
8067 case ARM::VLD2LNqWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD2LNq16_UPD
;
8068 case ARM::VLD2LNqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VLD2LNq32_UPD
;
8069 case ARM::VLD2LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VLD2LNd8_UPD
;
8070 case ARM::VLD2LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VLD2LNd16_UPD
;
8071 case ARM::VLD2LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VLD2LNd32_UPD
;
8072 case ARM::VLD2LNqWB_register_Asm_16
: Spacing
= 2; return ARM::VLD2LNq16_UPD
;
8073 case ARM::VLD2LNqWB_register_Asm_32
: Spacing
= 2; return ARM::VLD2LNq32_UPD
;
8074 case ARM::VLD2LNdAsm_8
: Spacing
= 1; return ARM::VLD2LNd8
;
8075 case ARM::VLD2LNdAsm_16
: Spacing
= 1; return ARM::VLD2LNd16
;
8076 case ARM::VLD2LNdAsm_32
: Spacing
= 1; return ARM::VLD2LNd32
;
8077 case ARM::VLD2LNqAsm_16
: Spacing
= 2; return ARM::VLD2LNq16
;
8078 case ARM::VLD2LNqAsm_32
: Spacing
= 2; return ARM::VLD2LNq32
;
8081 case ARM::VLD3DUPdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD3DUPd8_UPD
;
8082 case ARM::VLD3DUPdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD3DUPd16_UPD
;
8083 case ARM::VLD3DUPdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD3DUPd32_UPD
;
8084 case ARM::VLD3DUPqWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD3DUPq8_UPD
;
8085 case ARM::VLD3DUPqWB_fixed_Asm_16
: Spacing
= 2; return ARM::VLD3DUPq16_UPD
;
8086 case ARM::VLD3DUPqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VLD3DUPq32_UPD
;
8087 case ARM::VLD3DUPdWB_register_Asm_8
: Spacing
= 1; return ARM::VLD3DUPd8_UPD
;
8088 case ARM::VLD3DUPdWB_register_Asm_16
: Spacing
= 1; return ARM::VLD3DUPd16_UPD
;
8089 case ARM::VLD3DUPdWB_register_Asm_32
: Spacing
= 1; return ARM::VLD3DUPd32_UPD
;
8090 case ARM::VLD3DUPqWB_register_Asm_8
: Spacing
= 2; return ARM::VLD3DUPq8_UPD
;
8091 case ARM::VLD3DUPqWB_register_Asm_16
: Spacing
= 2; return ARM::VLD3DUPq16_UPD
;
8092 case ARM::VLD3DUPqWB_register_Asm_32
: Spacing
= 2; return ARM::VLD3DUPq32_UPD
;
8093 case ARM::VLD3DUPdAsm_8
: Spacing
= 1; return ARM::VLD3DUPd8
;
8094 case ARM::VLD3DUPdAsm_16
: Spacing
= 1; return ARM::VLD3DUPd16
;
8095 case ARM::VLD3DUPdAsm_32
: Spacing
= 1; return ARM::VLD3DUPd32
;
8096 case ARM::VLD3DUPqAsm_8
: Spacing
= 2; return ARM::VLD3DUPq8
;
8097 case ARM::VLD3DUPqAsm_16
: Spacing
= 2; return ARM::VLD3DUPq16
;
8098 case ARM::VLD3DUPqAsm_32
: Spacing
= 2; return ARM::VLD3DUPq32
;
8101 case ARM::VLD3LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD3LNd8_UPD
;
8102 case ARM::VLD3LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD3LNd16_UPD
;
8103 case ARM::VLD3LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD3LNd32_UPD
;
8104 case ARM::VLD3LNqWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD3LNq16_UPD
;
8105 case ARM::VLD3LNqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VLD3LNq32_UPD
;
8106 case ARM::VLD3LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VLD3LNd8_UPD
;
8107 case ARM::VLD3LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VLD3LNd16_UPD
;
8108 case ARM::VLD3LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VLD3LNd32_UPD
;
8109 case ARM::VLD3LNqWB_register_Asm_16
: Spacing
= 2; return ARM::VLD3LNq16_UPD
;
8110 case ARM::VLD3LNqWB_register_Asm_32
: Spacing
= 2; return ARM::VLD3LNq32_UPD
;
8111 case ARM::VLD3LNdAsm_8
: Spacing
= 1; return ARM::VLD3LNd8
;
8112 case ARM::VLD3LNdAsm_16
: Spacing
= 1; return ARM::VLD3LNd16
;
8113 case ARM::VLD3LNdAsm_32
: Spacing
= 1; return ARM::VLD3LNd32
;
8114 case ARM::VLD3LNqAsm_16
: Spacing
= 2; return ARM::VLD3LNq16
;
8115 case ARM::VLD3LNqAsm_32
: Spacing
= 2; return ARM::VLD3LNq32
;
8118 case ARM::VLD3dWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD3d8_UPD
;
8119 case ARM::VLD3dWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD3d16_UPD
;
8120 case ARM::VLD3dWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD3d32_UPD
;
8121 case ARM::VLD3qWB_fixed_Asm_8
: Spacing
= 2; return ARM::VLD3q8_UPD
;
8122 case ARM::VLD3qWB_fixed_Asm_16
: Spacing
= 2; return ARM::VLD3q16_UPD
;
8123 case ARM::VLD3qWB_fixed_Asm_32
: Spacing
= 2; return ARM::VLD3q32_UPD
;
8124 case ARM::VLD3dWB_register_Asm_8
: Spacing
= 1; return ARM::VLD3d8_UPD
;
8125 case ARM::VLD3dWB_register_Asm_16
: Spacing
= 1; return ARM::VLD3d16_UPD
;
8126 case ARM::VLD3dWB_register_Asm_32
: Spacing
= 1; return ARM::VLD3d32_UPD
;
8127 case ARM::VLD3qWB_register_Asm_8
: Spacing
= 2; return ARM::VLD3q8_UPD
;
8128 case ARM::VLD3qWB_register_Asm_16
: Spacing
= 2; return ARM::VLD3q16_UPD
;
8129 case ARM::VLD3qWB_register_Asm_32
: Spacing
= 2; return ARM::VLD3q32_UPD
;
8130 case ARM::VLD3dAsm_8
: Spacing
= 1; return ARM::VLD3d8
;
8131 case ARM::VLD3dAsm_16
: Spacing
= 1; return ARM::VLD3d16
;
8132 case ARM::VLD3dAsm_32
: Spacing
= 1; return ARM::VLD3d32
;
8133 case ARM::VLD3qAsm_8
: Spacing
= 2; return ARM::VLD3q8
;
8134 case ARM::VLD3qAsm_16
: Spacing
= 2; return ARM::VLD3q16
;
8135 case ARM::VLD3qAsm_32
: Spacing
= 2; return ARM::VLD3q32
;
8138 case ARM::VLD4LNdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD4LNd8_UPD
;
8139 case ARM::VLD4LNdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD4LNd16_UPD
;
8140 case ARM::VLD4LNdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD4LNd32_UPD
;
8141 case ARM::VLD4LNqWB_fixed_Asm_16
: Spacing
= 2; return ARM::VLD4LNq16_UPD
;
8142 case ARM::VLD4LNqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VLD4LNq32_UPD
;
8143 case ARM::VLD4LNdWB_register_Asm_8
: Spacing
= 1; return ARM::VLD4LNd8_UPD
;
8144 case ARM::VLD4LNdWB_register_Asm_16
: Spacing
= 1; return ARM::VLD4LNd16_UPD
;
8145 case ARM::VLD4LNdWB_register_Asm_32
: Spacing
= 1; return ARM::VLD4LNd32_UPD
;
8146 case ARM::VLD4LNqWB_register_Asm_16
: Spacing
= 2; return ARM::VLD4LNq16_UPD
;
8147 case ARM::VLD4LNqWB_register_Asm_32
: Spacing
= 2; return ARM::VLD4LNq32_UPD
;
8148 case ARM::VLD4LNdAsm_8
: Spacing
= 1; return ARM::VLD4LNd8
;
8149 case ARM::VLD4LNdAsm_16
: Spacing
= 1; return ARM::VLD4LNd16
;
8150 case ARM::VLD4LNdAsm_32
: Spacing
= 1; return ARM::VLD4LNd32
;
8151 case ARM::VLD4LNqAsm_16
: Spacing
= 2; return ARM::VLD4LNq16
;
8152 case ARM::VLD4LNqAsm_32
: Spacing
= 2; return ARM::VLD4LNq32
;
8155 case ARM::VLD4DUPdWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD4DUPd8_UPD
;
8156 case ARM::VLD4DUPdWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD4DUPd16_UPD
;
8157 case ARM::VLD4DUPdWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD4DUPd32_UPD
;
8158 case ARM::VLD4DUPqWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD4DUPq8_UPD
;
8159 case ARM::VLD4DUPqWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD4DUPq16_UPD
;
8160 case ARM::VLD4DUPqWB_fixed_Asm_32
: Spacing
= 2; return ARM::VLD4DUPq32_UPD
;
8161 case ARM::VLD4DUPdWB_register_Asm_8
: Spacing
= 1; return ARM::VLD4DUPd8_UPD
;
8162 case ARM::VLD4DUPdWB_register_Asm_16
: Spacing
= 1; return ARM::VLD4DUPd16_UPD
;
8163 case ARM::VLD4DUPdWB_register_Asm_32
: Spacing
= 1; return ARM::VLD4DUPd32_UPD
;
8164 case ARM::VLD4DUPqWB_register_Asm_8
: Spacing
= 2; return ARM::VLD4DUPq8_UPD
;
8165 case ARM::VLD4DUPqWB_register_Asm_16
: Spacing
= 2; return ARM::VLD4DUPq16_UPD
;
8166 case ARM::VLD4DUPqWB_register_Asm_32
: Spacing
= 2; return ARM::VLD4DUPq32_UPD
;
8167 case ARM::VLD4DUPdAsm_8
: Spacing
= 1; return ARM::VLD4DUPd8
;
8168 case ARM::VLD4DUPdAsm_16
: Spacing
= 1; return ARM::VLD4DUPd16
;
8169 case ARM::VLD4DUPdAsm_32
: Spacing
= 1; return ARM::VLD4DUPd32
;
8170 case ARM::VLD4DUPqAsm_8
: Spacing
= 2; return ARM::VLD4DUPq8
;
8171 case ARM::VLD4DUPqAsm_16
: Spacing
= 2; return ARM::VLD4DUPq16
;
8172 case ARM::VLD4DUPqAsm_32
: Spacing
= 2; return ARM::VLD4DUPq32
;
8175 case ARM::VLD4dWB_fixed_Asm_8
: Spacing
= 1; return ARM::VLD4d8_UPD
;
8176 case ARM::VLD4dWB_fixed_Asm_16
: Spacing
= 1; return ARM::VLD4d16_UPD
;
8177 case ARM::VLD4dWB_fixed_Asm_32
: Spacing
= 1; return ARM::VLD4d32_UPD
;
8178 case ARM::VLD4qWB_fixed_Asm_8
: Spacing
= 2; return ARM::VLD4q8_UPD
;
8179 case ARM::VLD4qWB_fixed_Asm_16
: Spacing
= 2; return ARM::VLD4q16_UPD
;
8180 case ARM::VLD4qWB_fixed_Asm_32
: Spacing
= 2; return ARM::VLD4q32_UPD
;
8181 case ARM::VLD4dWB_register_Asm_8
: Spacing
= 1; return ARM::VLD4d8_UPD
;
8182 case ARM::VLD4dWB_register_Asm_16
: Spacing
= 1; return ARM::VLD4d16_UPD
;
8183 case ARM::VLD4dWB_register_Asm_32
: Spacing
= 1; return ARM::VLD4d32_UPD
;
8184 case ARM::VLD4qWB_register_Asm_8
: Spacing
= 2; return ARM::VLD4q8_UPD
;
8185 case ARM::VLD4qWB_register_Asm_16
: Spacing
= 2; return ARM::VLD4q16_UPD
;
8186 case ARM::VLD4qWB_register_Asm_32
: Spacing
= 2; return ARM::VLD4q32_UPD
;
8187 case ARM::VLD4dAsm_8
: Spacing
= 1; return ARM::VLD4d8
;
8188 case ARM::VLD4dAsm_16
: Spacing
= 1; return ARM::VLD4d16
;
8189 case ARM::VLD4dAsm_32
: Spacing
= 1; return ARM::VLD4d32
;
8190 case ARM::VLD4qAsm_8
: Spacing
= 2; return ARM::VLD4q8
;
8191 case ARM::VLD4qAsm_16
: Spacing
= 2; return ARM::VLD4q16
;
8192 case ARM::VLD4qAsm_32
: Spacing
= 2; return ARM::VLD4q32
;
8196 bool ARMAsmParser::processInstruction(MCInst
&Inst
,
8197 const OperandVector
&Operands
,
8199 // Check if we have the wide qualifier, because if it's present we
8200 // must avoid selecting a 16-bit thumb instruction.
8201 bool HasWideQualifier
= false;
8202 for (auto &Op
: Operands
) {
8203 ARMOperand
&ARMOp
= static_cast<ARMOperand
&>(*Op
);
8204 if (ARMOp
.isToken() && ARMOp
.getToken() == ".w") {
8205 HasWideQualifier
= true;
8210 switch (Inst
.getOpcode()) {
8211 case ARM::MVE_VORNIZ0v4i32
:
8212 case ARM::MVE_VORNIZ0v8i16
:
8213 case ARM::MVE_VORNIZ8v4i32
:
8214 case ARM::MVE_VORNIZ8v8i16
:
8215 case ARM::MVE_VORNIZ16v4i32
:
8216 case ARM::MVE_VORNIZ24v4i32
:
8217 case ARM::MVE_VANDIZ0v4i32
:
8218 case ARM::MVE_VANDIZ0v8i16
:
8219 case ARM::MVE_VANDIZ8v4i32
:
8220 case ARM::MVE_VANDIZ8v8i16
:
8221 case ARM::MVE_VANDIZ16v4i32
:
8222 case ARM::MVE_VANDIZ24v4i32
: {
8225 switch(Inst
.getOpcode()) {
8226 case ARM::MVE_VORNIZ0v4i32
: Opcode
= ARM::MVE_VORRIZ0v4i32
; break;
8227 case ARM::MVE_VORNIZ0v8i16
: Opcode
= ARM::MVE_VORRIZ0v8i16
; imm16
= true; break;
8228 case ARM::MVE_VORNIZ8v4i32
: Opcode
= ARM::MVE_VORRIZ8v4i32
; break;
8229 case ARM::MVE_VORNIZ8v8i16
: Opcode
= ARM::MVE_VORRIZ8v8i16
; imm16
= true; break;
8230 case ARM::MVE_VORNIZ16v4i32
: Opcode
= ARM::MVE_VORRIZ16v4i32
; break;
8231 case ARM::MVE_VORNIZ24v4i32
: Opcode
= ARM::MVE_VORRIZ24v4i32
; break;
8232 case ARM::MVE_VANDIZ0v4i32
: Opcode
= ARM::MVE_VBICIZ0v4i32
; break;
8233 case ARM::MVE_VANDIZ0v8i16
: Opcode
= ARM::MVE_VBICIZ0v8i16
; imm16
= true; break;
8234 case ARM::MVE_VANDIZ8v4i32
: Opcode
= ARM::MVE_VBICIZ8v4i32
; break;
8235 case ARM::MVE_VANDIZ8v8i16
: Opcode
= ARM::MVE_VBICIZ8v8i16
; imm16
= true; break;
8236 case ARM::MVE_VANDIZ16v4i32
: Opcode
= ARM::MVE_VBICIZ16v4i32
; break;
8237 case ARM::MVE_VANDIZ24v4i32
: Opcode
= ARM::MVE_VBICIZ24v4i32
; break;
8238 default: llvm_unreachable("unexpected opcode");
8242 TmpInst
.setOpcode(Opcode
);
8243 TmpInst
.addOperand(Inst
.getOperand(0));
8244 TmpInst
.addOperand(Inst
.getOperand(1));
8247 unsigned imm
= ~Inst
.getOperand(2).getImm() & (imm16
? 0xffff : 0xffffffff);
8248 TmpInst
.addOperand(MCOperand::createImm(imm
));
8250 TmpInst
.addOperand(Inst
.getOperand(3));
8251 TmpInst
.addOperand(Inst
.getOperand(4));
8255 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
8256 case ARM::LDRT_POST
:
8257 case ARM::LDRBT_POST
: {
8258 const unsigned Opcode
=
8259 (Inst
.getOpcode() == ARM::LDRT_POST
) ? ARM::LDRT_POST_IMM
8260 : ARM::LDRBT_POST_IMM
;
8262 TmpInst
.setOpcode(Opcode
);
8263 TmpInst
.addOperand(Inst
.getOperand(0));
8264 TmpInst
.addOperand(Inst
.getOperand(1));
8265 TmpInst
.addOperand(Inst
.getOperand(1));
8266 TmpInst
.addOperand(MCOperand::createReg(0));
8267 TmpInst
.addOperand(MCOperand::createImm(0));
8268 TmpInst
.addOperand(Inst
.getOperand(2));
8269 TmpInst
.addOperand(Inst
.getOperand(3));
8273 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
8274 case ARM::STRT_POST
:
8275 case ARM::STRBT_POST
: {
8276 const unsigned Opcode
=
8277 (Inst
.getOpcode() == ARM::STRT_POST
) ? ARM::STRT_POST_IMM
8278 : ARM::STRBT_POST_IMM
;
8280 TmpInst
.setOpcode(Opcode
);
8281 TmpInst
.addOperand(Inst
.getOperand(1));
8282 TmpInst
.addOperand(Inst
.getOperand(0));
8283 TmpInst
.addOperand(Inst
.getOperand(1));
8284 TmpInst
.addOperand(MCOperand::createReg(0));
8285 TmpInst
.addOperand(MCOperand::createImm(0));
8286 TmpInst
.addOperand(Inst
.getOperand(2));
8287 TmpInst
.addOperand(Inst
.getOperand(3));
8291 // Alias for alternate form of 'ADR Rd, #imm' instruction.
8293 if (Inst
.getOperand(1).getReg() != ARM::PC
||
8294 Inst
.getOperand(5).getReg() != 0 ||
8295 !(Inst
.getOperand(2).isExpr() || Inst
.getOperand(2).isImm()))
8298 TmpInst
.setOpcode(ARM::ADR
);
8299 TmpInst
.addOperand(Inst
.getOperand(0));
8300 if (Inst
.getOperand(2).isImm()) {
8301 // Immediate (mod_imm) will be in its encoded form, we must unencode it
8302 // before passing it to the ADR instruction.
8303 unsigned Enc
= Inst
.getOperand(2).getImm();
8304 TmpInst
.addOperand(MCOperand::createImm(
8305 ARM_AM::rotr32(Enc
& 0xFF, (Enc
& 0xF00) >> 7)));
8307 // Turn PC-relative expression into absolute expression.
8308 // Reading PC provides the start of the current instruction + 8 and
8309 // the transform to adr is biased by that.
8310 MCSymbol
*Dot
= getContext().createTempSymbol();
8312 const MCExpr
*OpExpr
= Inst
.getOperand(2).getExpr();
8313 const MCExpr
*InstPC
= MCSymbolRefExpr::create(Dot
,
8314 MCSymbolRefExpr::VK_None
,
8316 const MCExpr
*Const8
= MCConstantExpr::create(8, getContext());
8317 const MCExpr
*ReadPC
= MCBinaryExpr::createAdd(InstPC
, Const8
,
8319 const MCExpr
*FixupAddr
= MCBinaryExpr::createAdd(ReadPC
, OpExpr
,
8321 TmpInst
.addOperand(MCOperand::createExpr(FixupAddr
));
8323 TmpInst
.addOperand(Inst
.getOperand(3));
8324 TmpInst
.addOperand(Inst
.getOperand(4));
8328 // Aliases for alternate PC+imm syntax of LDR instructions.
8329 case ARM::t2LDRpcrel
:
8330 // Select the narrow version if the immediate will fit.
8331 if (Inst
.getOperand(1).getImm() > 0 &&
8332 Inst
.getOperand(1).getImm() <= 0xff &&
8334 Inst
.setOpcode(ARM::tLDRpci
);
8336 Inst
.setOpcode(ARM::t2LDRpci
);
8338 case ARM::t2LDRBpcrel
:
8339 Inst
.setOpcode(ARM::t2LDRBpci
);
8341 case ARM::t2LDRHpcrel
:
8342 Inst
.setOpcode(ARM::t2LDRHpci
);
8344 case ARM::t2LDRSBpcrel
:
8345 Inst
.setOpcode(ARM::t2LDRSBpci
);
8347 case ARM::t2LDRSHpcrel
:
8348 Inst
.setOpcode(ARM::t2LDRSHpci
);
8350 case ARM::LDRConstPool
:
8351 case ARM::tLDRConstPool
:
8352 case ARM::t2LDRConstPool
: {
8353 // Pseudo instruction ldr rt, =immediate is converted to a
8354 // MOV rt, immediate if immediate is known and representable
8355 // otherwise we create a constant pool entry that we load from.
8357 if (Inst
.getOpcode() == ARM::LDRConstPool
)
8358 TmpInst
.setOpcode(ARM::LDRi12
);
8359 else if (Inst
.getOpcode() == ARM::tLDRConstPool
)
8360 TmpInst
.setOpcode(ARM::tLDRpci
);
8361 else if (Inst
.getOpcode() == ARM::t2LDRConstPool
)
8362 TmpInst
.setOpcode(ARM::t2LDRpci
);
8363 const ARMOperand
&PoolOperand
=
8365 static_cast<ARMOperand
&>(*Operands
[4]) :
8366 static_cast<ARMOperand
&>(*Operands
[3]));
8367 const MCExpr
*SubExprVal
= PoolOperand
.getConstantPoolImm();
8368 // If SubExprVal is a constant we may be able to use a MOV
8369 if (isa
<MCConstantExpr
>(SubExprVal
) &&
8370 Inst
.getOperand(0).getReg() != ARM::PC
&&
8371 Inst
.getOperand(0).getReg() != ARM::SP
) {
8373 (int64_t) (cast
<MCConstantExpr
>(SubExprVal
))->getValue();
8375 bool MovHasS
= true;
8376 if (Inst
.getOpcode() == ARM::LDRConstPool
) {
8378 if (ARM_AM::getSOImmVal(Value
) != -1) {
8379 Value
= ARM_AM::getSOImmVal(Value
);
8380 TmpInst
.setOpcode(ARM::MOVi
);
8382 else if (ARM_AM::getSOImmVal(~Value
) != -1) {
8383 Value
= ARM_AM::getSOImmVal(~Value
);
8384 TmpInst
.setOpcode(ARM::MVNi
);
8386 else if (hasV6T2Ops() &&
8387 Value
>=0 && Value
< 65536) {
8388 TmpInst
.setOpcode(ARM::MOVi16
);
8395 // Thumb/Thumb2 Constant
8397 ARM_AM::getT2SOImmVal(Value
) != -1)
8398 TmpInst
.setOpcode(ARM::t2MOVi
);
8399 else if (hasThumb2() &&
8400 ARM_AM::getT2SOImmVal(~Value
) != -1) {
8401 TmpInst
.setOpcode(ARM::t2MVNi
);
8404 else if (hasV8MBaseline() &&
8405 Value
>=0 && Value
< 65536) {
8406 TmpInst
.setOpcode(ARM::t2MOVi16
);
8413 TmpInst
.addOperand(Inst
.getOperand(0)); // Rt
8414 TmpInst
.addOperand(MCOperand::createImm(Value
)); // Immediate
8415 TmpInst
.addOperand(Inst
.getOperand(2)); // CondCode
8416 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
8418 TmpInst
.addOperand(MCOperand::createReg(0)); // S
8423 // No opportunity to use MOV/MVN create constant pool
8424 const MCExpr
*CPLoc
=
8425 getTargetStreamer().addConstantPoolEntry(SubExprVal
,
8426 PoolOperand
.getStartLoc());
8427 TmpInst
.addOperand(Inst
.getOperand(0)); // Rt
8428 TmpInst
.addOperand(MCOperand::createExpr(CPLoc
)); // offset to constpool
8429 if (TmpInst
.getOpcode() == ARM::LDRi12
)
8430 TmpInst
.addOperand(MCOperand::createImm(0)); // unused offset
8431 TmpInst
.addOperand(Inst
.getOperand(2)); // CondCode
8432 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
8436 // Handle NEON VST complex aliases.
8437 case ARM::VST1LNdWB_register_Asm_8
:
8438 case ARM::VST1LNdWB_register_Asm_16
:
8439 case ARM::VST1LNdWB_register_Asm_32
: {
8441 // Shuffle the operands around so the lane index operand is in the
8444 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8445 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8446 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8447 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8448 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8449 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8450 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8451 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8452 TmpInst
.addOperand(Inst
.getOperand(6));
8457 case ARM::VST2LNdWB_register_Asm_8
:
8458 case ARM::VST2LNdWB_register_Asm_16
:
8459 case ARM::VST2LNdWB_register_Asm_32
:
8460 case ARM::VST2LNqWB_register_Asm_16
:
8461 case ARM::VST2LNqWB_register_Asm_32
: {
8463 // Shuffle the operands around so the lane index operand is in the
8466 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8467 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8468 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8469 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8470 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8471 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8472 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8474 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8475 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8476 TmpInst
.addOperand(Inst
.getOperand(6));
8481 case ARM::VST3LNdWB_register_Asm_8
:
8482 case ARM::VST3LNdWB_register_Asm_16
:
8483 case ARM::VST3LNdWB_register_Asm_32
:
8484 case ARM::VST3LNqWB_register_Asm_16
:
8485 case ARM::VST3LNqWB_register_Asm_32
: {
8487 // Shuffle the operands around so the lane index operand is in the
8490 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8491 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8492 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8493 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8494 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8495 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8496 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8498 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8500 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8501 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8502 TmpInst
.addOperand(Inst
.getOperand(6));
8507 case ARM::VST4LNdWB_register_Asm_8
:
8508 case ARM::VST4LNdWB_register_Asm_16
:
8509 case ARM::VST4LNdWB_register_Asm_32
:
8510 case ARM::VST4LNqWB_register_Asm_16
:
8511 case ARM::VST4LNqWB_register_Asm_32
: {
8513 // Shuffle the operands around so the lane index operand is in the
8516 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8517 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8518 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8519 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8520 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8521 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8522 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8524 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8526 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8528 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8529 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8530 TmpInst
.addOperand(Inst
.getOperand(6));
8535 case ARM::VST1LNdWB_fixed_Asm_8
:
8536 case ARM::VST1LNdWB_fixed_Asm_16
:
8537 case ARM::VST1LNdWB_fixed_Asm_32
: {
8539 // Shuffle the operands around so the lane index operand is in the
8542 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8543 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8544 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8545 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8546 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8547 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8548 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8549 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8550 TmpInst
.addOperand(Inst
.getOperand(5));
8555 case ARM::VST2LNdWB_fixed_Asm_8
:
8556 case ARM::VST2LNdWB_fixed_Asm_16
:
8557 case ARM::VST2LNdWB_fixed_Asm_32
:
8558 case ARM::VST2LNqWB_fixed_Asm_16
:
8559 case ARM::VST2LNqWB_fixed_Asm_32
: {
8561 // Shuffle the operands around so the lane index operand is in the
8564 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8565 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8566 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8567 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8568 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8569 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8570 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8572 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8573 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8574 TmpInst
.addOperand(Inst
.getOperand(5));
8579 case ARM::VST3LNdWB_fixed_Asm_8
:
8580 case ARM::VST3LNdWB_fixed_Asm_16
:
8581 case ARM::VST3LNdWB_fixed_Asm_32
:
8582 case ARM::VST3LNqWB_fixed_Asm_16
:
8583 case ARM::VST3LNqWB_fixed_Asm_32
: {
8585 // Shuffle the operands around so the lane index operand is in the
8588 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8589 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8590 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8591 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8592 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8593 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8594 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8596 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8598 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8599 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8600 TmpInst
.addOperand(Inst
.getOperand(5));
8605 case ARM::VST4LNdWB_fixed_Asm_8
:
8606 case ARM::VST4LNdWB_fixed_Asm_16
:
8607 case ARM::VST4LNdWB_fixed_Asm_32
:
8608 case ARM::VST4LNqWB_fixed_Asm_16
:
8609 case ARM::VST4LNqWB_fixed_Asm_32
: {
8611 // Shuffle the operands around so the lane index operand is in the
8614 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8615 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8616 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8617 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8618 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8619 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8620 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8622 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8624 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8626 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8627 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8628 TmpInst
.addOperand(Inst
.getOperand(5));
8633 case ARM::VST1LNdAsm_8
:
8634 case ARM::VST1LNdAsm_16
:
8635 case ARM::VST1LNdAsm_32
: {
8637 // Shuffle the operands around so the lane index operand is in the
8640 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8641 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8642 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8643 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8644 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8645 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8646 TmpInst
.addOperand(Inst
.getOperand(5));
8651 case ARM::VST2LNdAsm_8
:
8652 case ARM::VST2LNdAsm_16
:
8653 case ARM::VST2LNdAsm_32
:
8654 case ARM::VST2LNqAsm_16
:
8655 case ARM::VST2LNqAsm_32
: {
8657 // Shuffle the operands around so the lane index operand is in the
8660 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8661 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8662 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8663 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8664 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8666 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8667 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8668 TmpInst
.addOperand(Inst
.getOperand(5));
8673 case ARM::VST3LNdAsm_8
:
8674 case ARM::VST3LNdAsm_16
:
8675 case ARM::VST3LNdAsm_32
:
8676 case ARM::VST3LNqAsm_16
:
8677 case ARM::VST3LNqAsm_32
: {
8679 // Shuffle the operands around so the lane index operand is in the
8682 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8683 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8684 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8685 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8686 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8688 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8690 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8691 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8692 TmpInst
.addOperand(Inst
.getOperand(5));
8697 case ARM::VST4LNdAsm_8
:
8698 case ARM::VST4LNdAsm_16
:
8699 case ARM::VST4LNdAsm_32
:
8700 case ARM::VST4LNqAsm_16
:
8701 case ARM::VST4LNqAsm_32
: {
8703 // Shuffle the operands around so the lane index operand is in the
8706 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
8707 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8708 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8709 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8710 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8712 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8714 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8716 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8717 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8718 TmpInst
.addOperand(Inst
.getOperand(5));
8723 // Handle NEON VLD complex aliases.
8724 case ARM::VLD1LNdWB_register_Asm_8
:
8725 case ARM::VLD1LNdWB_register_Asm_16
:
8726 case ARM::VLD1LNdWB_register_Asm_32
: {
8728 // Shuffle the operands around so the lane index operand is in the
8731 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8732 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8733 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8734 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8735 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8736 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8737 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8738 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8739 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8740 TmpInst
.addOperand(Inst
.getOperand(6));
8745 case ARM::VLD2LNdWB_register_Asm_8
:
8746 case ARM::VLD2LNdWB_register_Asm_16
:
8747 case ARM::VLD2LNdWB_register_Asm_32
:
8748 case ARM::VLD2LNqWB_register_Asm_16
:
8749 case ARM::VLD2LNqWB_register_Asm_32
: {
8751 // Shuffle the operands around so the lane index operand is in the
8754 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8755 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8756 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8758 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8759 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8760 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8761 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8762 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8763 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8765 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8766 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8767 TmpInst
.addOperand(Inst
.getOperand(6));
8772 case ARM::VLD3LNdWB_register_Asm_8
:
8773 case ARM::VLD3LNdWB_register_Asm_16
:
8774 case ARM::VLD3LNdWB_register_Asm_32
:
8775 case ARM::VLD3LNqWB_register_Asm_16
:
8776 case ARM::VLD3LNqWB_register_Asm_32
: {
8778 // Shuffle the operands around so the lane index operand is in the
8781 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8782 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8783 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8785 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8787 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8788 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8789 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8790 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8791 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8792 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8794 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8796 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8797 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8798 TmpInst
.addOperand(Inst
.getOperand(6));
8803 case ARM::VLD4LNdWB_register_Asm_8
:
8804 case ARM::VLD4LNdWB_register_Asm_16
:
8805 case ARM::VLD4LNdWB_register_Asm_32
:
8806 case ARM::VLD4LNqWB_register_Asm_16
:
8807 case ARM::VLD4LNqWB_register_Asm_32
: {
8809 // Shuffle the operands around so the lane index operand is in the
8812 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8813 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8814 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8816 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8818 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8820 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8821 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8822 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8823 TmpInst
.addOperand(Inst
.getOperand(4)); // Rm
8824 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8825 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8827 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8829 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8831 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8832 TmpInst
.addOperand(Inst
.getOperand(5)); // CondCode
8833 TmpInst
.addOperand(Inst
.getOperand(6));
8838 case ARM::VLD1LNdWB_fixed_Asm_8
:
8839 case ARM::VLD1LNdWB_fixed_Asm_16
:
8840 case ARM::VLD1LNdWB_fixed_Asm_32
: {
8842 // Shuffle the operands around so the lane index operand is in the
8845 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8846 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8847 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8848 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8849 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8850 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8851 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8852 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8853 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8854 TmpInst
.addOperand(Inst
.getOperand(5));
8859 case ARM::VLD2LNdWB_fixed_Asm_8
:
8860 case ARM::VLD2LNdWB_fixed_Asm_16
:
8861 case ARM::VLD2LNdWB_fixed_Asm_32
:
8862 case ARM::VLD2LNqWB_fixed_Asm_16
:
8863 case ARM::VLD2LNqWB_fixed_Asm_32
: {
8865 // Shuffle the operands around so the lane index operand is in the
8868 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8869 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8870 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8872 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8873 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8874 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8875 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8876 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8877 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8879 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8880 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8881 TmpInst
.addOperand(Inst
.getOperand(5));
8886 case ARM::VLD3LNdWB_fixed_Asm_8
:
8887 case ARM::VLD3LNdWB_fixed_Asm_16
:
8888 case ARM::VLD3LNdWB_fixed_Asm_32
:
8889 case ARM::VLD3LNqWB_fixed_Asm_16
:
8890 case ARM::VLD3LNqWB_fixed_Asm_32
: {
8892 // Shuffle the operands around so the lane index operand is in the
8895 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8896 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8897 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8899 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8901 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8902 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8903 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8904 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8905 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8906 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8908 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8910 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8911 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8912 TmpInst
.addOperand(Inst
.getOperand(5));
8917 case ARM::VLD4LNdWB_fixed_Asm_8
:
8918 case ARM::VLD4LNdWB_fixed_Asm_16
:
8919 case ARM::VLD4LNdWB_fixed_Asm_32
:
8920 case ARM::VLD4LNqWB_fixed_Asm_16
:
8921 case ARM::VLD4LNqWB_fixed_Asm_32
: {
8923 // Shuffle the operands around so the lane index operand is in the
8926 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8927 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8928 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8930 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8932 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8934 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn_wb
8935 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8936 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8937 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
8938 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8939 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8941 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8943 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8945 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8946 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8947 TmpInst
.addOperand(Inst
.getOperand(5));
8952 case ARM::VLD1LNdAsm_8
:
8953 case ARM::VLD1LNdAsm_16
:
8954 case ARM::VLD1LNdAsm_32
: {
8956 // Shuffle the operands around so the lane index operand is in the
8959 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8960 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8961 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8962 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8963 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8964 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8965 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8966 TmpInst
.addOperand(Inst
.getOperand(5));
8971 case ARM::VLD2LNdAsm_8
:
8972 case ARM::VLD2LNdAsm_16
:
8973 case ARM::VLD2LNdAsm_32
:
8974 case ARM::VLD2LNqAsm_16
:
8975 case ARM::VLD2LNqAsm_32
: {
8977 // Shuffle the operands around so the lane index operand is in the
8980 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
8981 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
8982 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8984 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
8985 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
8986 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
8987 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
8989 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
8990 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
8991 TmpInst
.addOperand(Inst
.getOperand(5));
8996 case ARM::VLD3LNdAsm_8
:
8997 case ARM::VLD3LNdAsm_16
:
8998 case ARM::VLD3LNdAsm_32
:
8999 case ARM::VLD3LNqAsm_16
:
9000 case ARM::VLD3LNqAsm_32
: {
9002 // Shuffle the operands around so the lane index operand is in the
9005 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9006 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9007 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9009 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9011 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
9012 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
9013 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
9014 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9016 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9018 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
9019 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9020 TmpInst
.addOperand(Inst
.getOperand(5));
9025 case ARM::VLD4LNdAsm_8
:
9026 case ARM::VLD4LNdAsm_16
:
9027 case ARM::VLD4LNdAsm_32
:
9028 case ARM::VLD4LNqAsm_16
:
9029 case ARM::VLD4LNqAsm_32
: {
9031 // Shuffle the operands around so the lane index operand is in the
9034 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9035 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9036 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9038 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9040 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9042 TmpInst
.addOperand(Inst
.getOperand(2)); // Rn
9043 TmpInst
.addOperand(Inst
.getOperand(3)); // alignment
9044 TmpInst
.addOperand(Inst
.getOperand(0)); // Tied operand src (== Vd)
9045 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9047 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9049 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9051 TmpInst
.addOperand(Inst
.getOperand(1)); // lane
9052 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9053 TmpInst
.addOperand(Inst
.getOperand(5));
9058 // VLD3DUP single 3-element structure to all lanes instructions.
9059 case ARM::VLD3DUPdAsm_8
:
9060 case ARM::VLD3DUPdAsm_16
:
9061 case ARM::VLD3DUPdAsm_32
:
9062 case ARM::VLD3DUPqAsm_8
:
9063 case ARM::VLD3DUPqAsm_16
:
9064 case ARM::VLD3DUPqAsm_32
: {
9067 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9068 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9069 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9071 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9073 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9074 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9075 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9076 TmpInst
.addOperand(Inst
.getOperand(4));
9081 case ARM::VLD3DUPdWB_fixed_Asm_8
:
9082 case ARM::VLD3DUPdWB_fixed_Asm_16
:
9083 case ARM::VLD3DUPdWB_fixed_Asm_32
:
9084 case ARM::VLD3DUPqWB_fixed_Asm_8
:
9085 case ARM::VLD3DUPqWB_fixed_Asm_16
:
9086 case ARM::VLD3DUPqWB_fixed_Asm_32
: {
9089 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9090 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9091 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9093 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9095 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9096 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9097 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9098 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
9099 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9100 TmpInst
.addOperand(Inst
.getOperand(4));
9105 case ARM::VLD3DUPdWB_register_Asm_8
:
9106 case ARM::VLD3DUPdWB_register_Asm_16
:
9107 case ARM::VLD3DUPdWB_register_Asm_32
:
9108 case ARM::VLD3DUPqWB_register_Asm_8
:
9109 case ARM::VLD3DUPqWB_register_Asm_16
:
9110 case ARM::VLD3DUPqWB_register_Asm_32
: {
9113 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9114 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9115 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9117 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9119 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9120 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9121 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9122 TmpInst
.addOperand(Inst
.getOperand(3)); // Rm
9123 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9124 TmpInst
.addOperand(Inst
.getOperand(5));
9129 // VLD3 multiple 3-element structure instructions.
9130 case ARM::VLD3dAsm_8
:
9131 case ARM::VLD3dAsm_16
:
9132 case ARM::VLD3dAsm_32
:
9133 case ARM::VLD3qAsm_8
:
9134 case ARM::VLD3qAsm_16
:
9135 case ARM::VLD3qAsm_32
: {
9138 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9139 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9140 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9142 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9144 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9145 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9146 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9147 TmpInst
.addOperand(Inst
.getOperand(4));
9152 case ARM::VLD3dWB_fixed_Asm_8
:
9153 case ARM::VLD3dWB_fixed_Asm_16
:
9154 case ARM::VLD3dWB_fixed_Asm_32
:
9155 case ARM::VLD3qWB_fixed_Asm_8
:
9156 case ARM::VLD3qWB_fixed_Asm_16
:
9157 case ARM::VLD3qWB_fixed_Asm_32
: {
9160 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9161 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9162 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9164 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9166 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9167 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9168 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9169 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
9170 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9171 TmpInst
.addOperand(Inst
.getOperand(4));
9176 case ARM::VLD3dWB_register_Asm_8
:
9177 case ARM::VLD3dWB_register_Asm_16
:
9178 case ARM::VLD3dWB_register_Asm_32
:
9179 case ARM::VLD3qWB_register_Asm_8
:
9180 case ARM::VLD3qWB_register_Asm_16
:
9181 case ARM::VLD3qWB_register_Asm_32
: {
9184 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9185 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9186 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9188 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9190 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9191 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9192 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9193 TmpInst
.addOperand(Inst
.getOperand(3)); // Rm
9194 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9195 TmpInst
.addOperand(Inst
.getOperand(5));
9200 // VLD4DUP single 3-element structure to all lanes instructions.
9201 case ARM::VLD4DUPdAsm_8
:
9202 case ARM::VLD4DUPdAsm_16
:
9203 case ARM::VLD4DUPdAsm_32
:
9204 case ARM::VLD4DUPqAsm_8
:
9205 case ARM::VLD4DUPqAsm_16
:
9206 case ARM::VLD4DUPqAsm_32
: {
9209 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9210 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9211 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9213 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9215 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9217 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9218 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9219 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9220 TmpInst
.addOperand(Inst
.getOperand(4));
9225 case ARM::VLD4DUPdWB_fixed_Asm_8
:
9226 case ARM::VLD4DUPdWB_fixed_Asm_16
:
9227 case ARM::VLD4DUPdWB_fixed_Asm_32
:
9228 case ARM::VLD4DUPqWB_fixed_Asm_8
:
9229 case ARM::VLD4DUPqWB_fixed_Asm_16
:
9230 case ARM::VLD4DUPqWB_fixed_Asm_32
: {
9233 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9234 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9235 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9237 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9239 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9241 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9242 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9243 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9244 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
9245 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9246 TmpInst
.addOperand(Inst
.getOperand(4));
9251 case ARM::VLD4DUPdWB_register_Asm_8
:
9252 case ARM::VLD4DUPdWB_register_Asm_16
:
9253 case ARM::VLD4DUPdWB_register_Asm_32
:
9254 case ARM::VLD4DUPqWB_register_Asm_8
:
9255 case ARM::VLD4DUPqWB_register_Asm_16
:
9256 case ARM::VLD4DUPqWB_register_Asm_32
: {
9259 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9260 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9261 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9263 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9265 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9267 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9268 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9269 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9270 TmpInst
.addOperand(Inst
.getOperand(3)); // Rm
9271 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9272 TmpInst
.addOperand(Inst
.getOperand(5));
9277 // VLD4 multiple 4-element structure instructions.
9278 case ARM::VLD4dAsm_8
:
9279 case ARM::VLD4dAsm_16
:
9280 case ARM::VLD4dAsm_32
:
9281 case ARM::VLD4qAsm_8
:
9282 case ARM::VLD4qAsm_16
:
9283 case ARM::VLD4qAsm_32
: {
9286 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9287 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9288 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9290 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9292 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9294 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9295 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9296 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9297 TmpInst
.addOperand(Inst
.getOperand(4));
9302 case ARM::VLD4dWB_fixed_Asm_8
:
9303 case ARM::VLD4dWB_fixed_Asm_16
:
9304 case ARM::VLD4dWB_fixed_Asm_32
:
9305 case ARM::VLD4qWB_fixed_Asm_8
:
9306 case ARM::VLD4qWB_fixed_Asm_16
:
9307 case ARM::VLD4qWB_fixed_Asm_32
: {
9310 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9311 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9312 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9314 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9316 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9318 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9319 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9320 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9321 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
9322 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9323 TmpInst
.addOperand(Inst
.getOperand(4));
9328 case ARM::VLD4dWB_register_Asm_8
:
9329 case ARM::VLD4dWB_register_Asm_16
:
9330 case ARM::VLD4dWB_register_Asm_32
:
9331 case ARM::VLD4qWB_register_Asm_8
:
9332 case ARM::VLD4qWB_register_Asm_16
:
9333 case ARM::VLD4qWB_register_Asm_32
: {
9336 TmpInst
.setOpcode(getRealVLDOpcode(Inst
.getOpcode(), Spacing
));
9337 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9338 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9340 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9342 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9344 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9345 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9346 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9347 TmpInst
.addOperand(Inst
.getOperand(3)); // Rm
9348 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9349 TmpInst
.addOperand(Inst
.getOperand(5));
9354 // VST3 multiple 3-element structure instructions.
9355 case ARM::VST3dAsm_8
:
9356 case ARM::VST3dAsm_16
:
9357 case ARM::VST3dAsm_32
:
9358 case ARM::VST3qAsm_8
:
9359 case ARM::VST3qAsm_16
:
9360 case ARM::VST3qAsm_32
: {
9363 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
9364 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9365 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9366 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9367 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9369 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9371 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9372 TmpInst
.addOperand(Inst
.getOperand(4));
9377 case ARM::VST3dWB_fixed_Asm_8
:
9378 case ARM::VST3dWB_fixed_Asm_16
:
9379 case ARM::VST3dWB_fixed_Asm_32
:
9380 case ARM::VST3qWB_fixed_Asm_8
:
9381 case ARM::VST3qWB_fixed_Asm_16
:
9382 case ARM::VST3qWB_fixed_Asm_32
: {
9385 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
9386 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9387 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9388 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9389 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
9390 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9391 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9393 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9395 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9396 TmpInst
.addOperand(Inst
.getOperand(4));
9401 case ARM::VST3dWB_register_Asm_8
:
9402 case ARM::VST3dWB_register_Asm_16
:
9403 case ARM::VST3dWB_register_Asm_32
:
9404 case ARM::VST3qWB_register_Asm_8
:
9405 case ARM::VST3qWB_register_Asm_16
:
9406 case ARM::VST3qWB_register_Asm_32
: {
9409 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
9410 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9411 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9412 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9413 TmpInst
.addOperand(Inst
.getOperand(3)); // Rm
9414 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9415 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9417 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9419 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9420 TmpInst
.addOperand(Inst
.getOperand(5));
9425 // VST4 multiple 3-element structure instructions.
9426 case ARM::VST4dAsm_8
:
9427 case ARM::VST4dAsm_16
:
9428 case ARM::VST4dAsm_32
:
9429 case ARM::VST4qAsm_8
:
9430 case ARM::VST4qAsm_16
:
9431 case ARM::VST4qAsm_32
: {
9434 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
9435 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9436 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9437 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9438 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9440 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9442 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9444 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9445 TmpInst
.addOperand(Inst
.getOperand(4));
9450 case ARM::VST4dWB_fixed_Asm_8
:
9451 case ARM::VST4dWB_fixed_Asm_16
:
9452 case ARM::VST4dWB_fixed_Asm_32
:
9453 case ARM::VST4qWB_fixed_Asm_8
:
9454 case ARM::VST4qWB_fixed_Asm_16
:
9455 case ARM::VST4qWB_fixed_Asm_32
: {
9458 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
9459 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9460 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9461 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9462 TmpInst
.addOperand(MCOperand::createReg(0)); // Rm
9463 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9464 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9466 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9468 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9470 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9471 TmpInst
.addOperand(Inst
.getOperand(4));
9476 case ARM::VST4dWB_register_Asm_8
:
9477 case ARM::VST4dWB_register_Asm_16
:
9478 case ARM::VST4dWB_register_Asm_32
:
9479 case ARM::VST4qWB_register_Asm_8
:
9480 case ARM::VST4qWB_register_Asm_16
:
9481 case ARM::VST4qWB_register_Asm_32
: {
9484 TmpInst
.setOpcode(getRealVSTOpcode(Inst
.getOpcode(), Spacing
));
9485 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9486 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn_wb == tied Rn
9487 TmpInst
.addOperand(Inst
.getOperand(2)); // alignment
9488 TmpInst
.addOperand(Inst
.getOperand(3)); // Rm
9489 TmpInst
.addOperand(Inst
.getOperand(0)); // Vd
9490 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9492 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9494 TmpInst
.addOperand(MCOperand::createReg(Inst
.getOperand(0).getReg() +
9496 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9497 TmpInst
.addOperand(Inst
.getOperand(5));
9502 // Handle encoding choice for the shift-immediate instructions.
9506 if (isARMLowRegister(Inst
.getOperand(0).getReg()) &&
9507 isARMLowRegister(Inst
.getOperand(1).getReg()) &&
9508 Inst
.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR
) &&
9509 !HasWideQualifier
) {
9511 switch (Inst
.getOpcode()) {
9512 default: llvm_unreachable("unexpected opcode");
9513 case ARM::t2LSLri
: NewOpc
= ARM::tLSLri
; break;
9514 case ARM::t2LSRri
: NewOpc
= ARM::tLSRri
; break;
9515 case ARM::t2ASRri
: NewOpc
= ARM::tASRri
; break;
9517 // The Thumb1 operands aren't in the same order. Awesome, eh?
9519 TmpInst
.setOpcode(NewOpc
);
9520 TmpInst
.addOperand(Inst
.getOperand(0));
9521 TmpInst
.addOperand(Inst
.getOperand(5));
9522 TmpInst
.addOperand(Inst
.getOperand(1));
9523 TmpInst
.addOperand(Inst
.getOperand(2));
9524 TmpInst
.addOperand(Inst
.getOperand(3));
9525 TmpInst
.addOperand(Inst
.getOperand(4));
9531 // Handle the Thumb2 mode MOV complex aliases.
9533 case ARM::t2MOVSsr
: {
9534 // Which instruction to expand to depends on the CCOut operand and
9535 // whether we're in an IT block if the register operands are low
9537 bool isNarrow
= false;
9538 if (isARMLowRegister(Inst
.getOperand(0).getReg()) &&
9539 isARMLowRegister(Inst
.getOperand(1).getReg()) &&
9540 isARMLowRegister(Inst
.getOperand(2).getReg()) &&
9541 Inst
.getOperand(0).getReg() == Inst
.getOperand(1).getReg() &&
9542 inITBlock() == (Inst
.getOpcode() == ARM::t2MOVsr
) &&
9547 switch(ARM_AM::getSORegShOp(Inst
.getOperand(3).getImm())) {
9548 default: llvm_unreachable("unexpected opcode!");
9549 case ARM_AM::asr
: newOpc
= isNarrow
? ARM::tASRrr
: ARM::t2ASRrr
; break;
9550 case ARM_AM::lsr
: newOpc
= isNarrow
? ARM::tLSRrr
: ARM::t2LSRrr
; break;
9551 case ARM_AM::lsl
: newOpc
= isNarrow
? ARM::tLSLrr
: ARM::t2LSLrr
; break;
9552 case ARM_AM::ror
: newOpc
= isNarrow
? ARM::tROR
: ARM::t2RORrr
; break;
9554 TmpInst
.setOpcode(newOpc
);
9555 TmpInst
.addOperand(Inst
.getOperand(0)); // Rd
9557 TmpInst
.addOperand(MCOperand::createReg(
9558 Inst
.getOpcode() == ARM::t2MOVSsr
? ARM::CPSR
: 0));
9559 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9560 TmpInst
.addOperand(Inst
.getOperand(2)); // Rm
9561 TmpInst
.addOperand(Inst
.getOperand(4)); // CondCode
9562 TmpInst
.addOperand(Inst
.getOperand(5));
9564 TmpInst
.addOperand(MCOperand::createReg(
9565 Inst
.getOpcode() == ARM::t2MOVSsr
? ARM::CPSR
: 0));
9570 case ARM::t2MOVSsi
: {
9571 // Which instruction to expand to depends on the CCOut operand and
9572 // whether we're in an IT block if the register operands are low
9574 bool isNarrow
= false;
9575 if (isARMLowRegister(Inst
.getOperand(0).getReg()) &&
9576 isARMLowRegister(Inst
.getOperand(1).getReg()) &&
9577 inITBlock() == (Inst
.getOpcode() == ARM::t2MOVsi
) &&
9582 unsigned Shift
= ARM_AM::getSORegShOp(Inst
.getOperand(2).getImm());
9583 unsigned Amount
= ARM_AM::getSORegOffset(Inst
.getOperand(2).getImm());
9585 // MOV rd, rm, LSL #0 is actually a MOV instruction
9586 if (Shift
== ARM_AM::lsl
&& Amount
== 0) {
9588 // The 16-bit encoding of MOV rd, rm, LSL #N is explicitly encoding T2 of
9589 // MOV (register) in the ARMv8-A and ARMv8-M manuals, and immediate 0 is
9590 // unpredictable in an IT block so the 32-bit encoding T3 has to be used
9595 newOpc
= isNarrow
? ARM::tMOVSr
: ARM::t2MOVr
;
9598 default: llvm_unreachable("unexpected opcode!");
9599 case ARM_AM::asr
: newOpc
= isNarrow
? ARM::tASRri
: ARM::t2ASRri
; break;
9600 case ARM_AM::lsr
: newOpc
= isNarrow
? ARM::tLSRri
: ARM::t2LSRri
; break;
9601 case ARM_AM::lsl
: newOpc
= isNarrow
? ARM::tLSLri
: ARM::t2LSLri
; break;
9602 case ARM_AM::ror
: newOpc
= ARM::t2RORri
; isNarrow
= false; break;
9603 case ARM_AM::rrx
: isNarrow
= false; newOpc
= ARM::t2RRX
; break;
9606 if (Amount
== 32) Amount
= 0;
9607 TmpInst
.setOpcode(newOpc
);
9608 TmpInst
.addOperand(Inst
.getOperand(0)); // Rd
9609 if (isNarrow
&& !isMov
)
9610 TmpInst
.addOperand(MCOperand::createReg(
9611 Inst
.getOpcode() == ARM::t2MOVSsi
? ARM::CPSR
: 0));
9612 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9613 if (newOpc
!= ARM::t2RRX
&& !isMov
)
9614 TmpInst
.addOperand(MCOperand::createImm(Amount
));
9615 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9616 TmpInst
.addOperand(Inst
.getOperand(4));
9618 TmpInst
.addOperand(MCOperand::createReg(
9619 Inst
.getOpcode() == ARM::t2MOVSsi
? ARM::CPSR
: 0));
9623 // Handle the ARM mode MOV complex aliases.
9628 ARM_AM::ShiftOpc ShiftTy
;
9629 switch(Inst
.getOpcode()) {
9630 default: llvm_unreachable("unexpected opcode!");
9631 case ARM::ASRr
: ShiftTy
= ARM_AM::asr
; break;
9632 case ARM::LSRr
: ShiftTy
= ARM_AM::lsr
; break;
9633 case ARM::LSLr
: ShiftTy
= ARM_AM::lsl
; break;
9634 case ARM::RORr
: ShiftTy
= ARM_AM::ror
; break;
9636 unsigned Shifter
= ARM_AM::getSORegOpc(ShiftTy
, 0);
9638 TmpInst
.setOpcode(ARM::MOVsr
);
9639 TmpInst
.addOperand(Inst
.getOperand(0)); // Rd
9640 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9641 TmpInst
.addOperand(Inst
.getOperand(2)); // Rm
9642 TmpInst
.addOperand(MCOperand::createImm(Shifter
)); // Shift value and ty
9643 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9644 TmpInst
.addOperand(Inst
.getOperand(4));
9645 TmpInst
.addOperand(Inst
.getOperand(5)); // cc_out
9653 ARM_AM::ShiftOpc ShiftTy
;
9654 switch(Inst
.getOpcode()) {
9655 default: llvm_unreachable("unexpected opcode!");
9656 case ARM::ASRi
: ShiftTy
= ARM_AM::asr
; break;
9657 case ARM::LSRi
: ShiftTy
= ARM_AM::lsr
; break;
9658 case ARM::LSLi
: ShiftTy
= ARM_AM::lsl
; break;
9659 case ARM::RORi
: ShiftTy
= ARM_AM::ror
; break;
9661 // A shift by zero is a plain MOVr, not a MOVsi.
9662 unsigned Amt
= Inst
.getOperand(2).getImm();
9663 unsigned Opc
= Amt
== 0 ? ARM::MOVr
: ARM::MOVsi
;
9664 // A shift by 32 should be encoded as 0 when permitted
9665 if (Amt
== 32 && (ShiftTy
== ARM_AM::lsr
|| ShiftTy
== ARM_AM::asr
))
9667 unsigned Shifter
= ARM_AM::getSORegOpc(ShiftTy
, Amt
);
9669 TmpInst
.setOpcode(Opc
);
9670 TmpInst
.addOperand(Inst
.getOperand(0)); // Rd
9671 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9672 if (Opc
== ARM::MOVsi
)
9673 TmpInst
.addOperand(MCOperand::createImm(Shifter
)); // Shift value and ty
9674 TmpInst
.addOperand(Inst
.getOperand(3)); // CondCode
9675 TmpInst
.addOperand(Inst
.getOperand(4));
9676 TmpInst
.addOperand(Inst
.getOperand(5)); // cc_out
9681 unsigned Shifter
= ARM_AM::getSORegOpc(ARM_AM::rrx
, 0);
9683 TmpInst
.setOpcode(ARM::MOVsi
);
9684 TmpInst
.addOperand(Inst
.getOperand(0)); // Rd
9685 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9686 TmpInst
.addOperand(MCOperand::createImm(Shifter
)); // Shift value and ty
9687 TmpInst
.addOperand(Inst
.getOperand(2)); // CondCode
9688 TmpInst
.addOperand(Inst
.getOperand(3));
9689 TmpInst
.addOperand(Inst
.getOperand(4)); // cc_out
9693 case ARM::t2LDMIA_UPD
: {
9694 // If this is a load of a single register, then we should use
9695 // a post-indexed LDR instruction instead, per the ARM ARM.
9696 if (Inst
.getNumOperands() != 5)
9699 TmpInst
.setOpcode(ARM::t2LDR_POST
);
9700 TmpInst
.addOperand(Inst
.getOperand(4)); // Rt
9701 TmpInst
.addOperand(Inst
.getOperand(0)); // Rn_wb
9702 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9703 TmpInst
.addOperand(MCOperand::createImm(4));
9704 TmpInst
.addOperand(Inst
.getOperand(2)); // CondCode
9705 TmpInst
.addOperand(Inst
.getOperand(3));
9709 case ARM::t2STMDB_UPD
: {
9710 // If this is a store of a single register, then we should use
9711 // a pre-indexed STR instruction instead, per the ARM ARM.
9712 if (Inst
.getNumOperands() != 5)
9715 TmpInst
.setOpcode(ARM::t2STR_PRE
);
9716 TmpInst
.addOperand(Inst
.getOperand(0)); // Rn_wb
9717 TmpInst
.addOperand(Inst
.getOperand(4)); // Rt
9718 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9719 TmpInst
.addOperand(MCOperand::createImm(-4));
9720 TmpInst
.addOperand(Inst
.getOperand(2)); // CondCode
9721 TmpInst
.addOperand(Inst
.getOperand(3));
9725 case ARM::LDMIA_UPD
:
9726 // If this is a load of a single register via a 'pop', then we should use
9727 // a post-indexed LDR instruction instead, per the ARM ARM.
9728 if (static_cast<ARMOperand
&>(*Operands
[0]).getToken() == "pop" &&
9729 Inst
.getNumOperands() == 5) {
9731 TmpInst
.setOpcode(ARM::LDR_POST_IMM
);
9732 TmpInst
.addOperand(Inst
.getOperand(4)); // Rt
9733 TmpInst
.addOperand(Inst
.getOperand(0)); // Rn_wb
9734 TmpInst
.addOperand(Inst
.getOperand(1)); // Rn
9735 TmpInst
.addOperand(MCOperand::createReg(0)); // am2offset
9736 TmpInst
.addOperand(MCOperand::createImm(4));
9737 TmpInst
.addOperand(Inst
.getOperand(2)); // CondCode
9738 TmpInst
.addOperand(Inst
.getOperand(3));
9743 case ARM::STMDB_UPD
:
9744 // If this is a store of a single register via a 'push', then we should use
9745 // a pre-indexed STR instruction instead, per the ARM ARM.
9746 if (static_cast<ARMOperand
&>(*Operands
[0]).getToken() == "push" &&
9747 Inst
.getNumOperands() == 5) {
9749 TmpInst
.setOpcode(ARM::STR_PRE_IMM
);
9750 TmpInst
.addOperand(Inst
.getOperand(0)); // Rn_wb
9751 TmpInst
.addOperand(Inst
.getOperand(4)); // Rt
9752 TmpInst
.addOperand(Inst
.getOperand(1)); // addrmode_imm12
9753 TmpInst
.addOperand(MCOperand::createImm(-4));
9754 TmpInst
.addOperand(Inst
.getOperand(2)); // CondCode
9755 TmpInst
.addOperand(Inst
.getOperand(3));
9759 case ARM::t2ADDri12
:
9760 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
9761 // mnemonic was used (not "addw"), encoding T3 is preferred.
9762 if (static_cast<ARMOperand
&>(*Operands
[0]).getToken() != "add" ||
9763 ARM_AM::getT2SOImmVal(Inst
.getOperand(2).getImm()) == -1)
9765 Inst
.setOpcode(ARM::t2ADDri
);
9766 Inst
.addOperand(MCOperand::createReg(0)); // cc_out
9768 case ARM::t2SUBri12
:
9769 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
9770 // mnemonic was used (not "subw"), encoding T3 is preferred.
9771 if (static_cast<ARMOperand
&>(*Operands
[0]).getToken() != "sub" ||
9772 ARM_AM::getT2SOImmVal(Inst
.getOperand(2).getImm()) == -1)
9774 Inst
.setOpcode(ARM::t2SUBri
);
9775 Inst
.addOperand(MCOperand::createReg(0)); // cc_out
9778 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
9779 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
9780 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
9781 // to encoding T1 if <Rd> is omitted."
9782 if ((unsigned)Inst
.getOperand(3).getImm() < 8 && Operands
.size() == 6) {
9783 Inst
.setOpcode(ARM::tADDi3
);
9788 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
9789 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
9790 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
9791 // to encoding T1 if <Rd> is omitted."
9792 if ((unsigned)Inst
.getOperand(3).getImm() < 8 && Operands
.size() == 6) {
9793 Inst
.setOpcode(ARM::tSUBi3
);
9798 case ARM::t2SUBri
: {
9799 // If the destination and first source operand are the same, and
9800 // the flags are compatible with the current IT status, use encoding T2
9801 // instead of T3. For compatibility with the system 'as'. Make sure the
9802 // wide encoding wasn't explicit.
9803 if (Inst
.getOperand(0).getReg() != Inst
.getOperand(1).getReg() ||
9804 !isARMLowRegister(Inst
.getOperand(0).getReg()) ||
9805 (Inst
.getOperand(2).isImm() &&
9806 (unsigned)Inst
.getOperand(2).getImm() > 255) ||
9807 Inst
.getOperand(5).getReg() != (inITBlock() ? 0 : ARM::CPSR
) ||
9811 TmpInst
.setOpcode(Inst
.getOpcode() == ARM::t2ADDri
?
9812 ARM::tADDi8
: ARM::tSUBi8
);
9813 TmpInst
.addOperand(Inst
.getOperand(0));
9814 TmpInst
.addOperand(Inst
.getOperand(5));
9815 TmpInst
.addOperand(Inst
.getOperand(0));
9816 TmpInst
.addOperand(Inst
.getOperand(2));
9817 TmpInst
.addOperand(Inst
.getOperand(3));
9818 TmpInst
.addOperand(Inst
.getOperand(4));
9822 case ARM::t2ADDrr
: {
9823 // If the destination and first source operand are the same, and
9824 // there's no setting of the flags, use encoding T2 instead of T3.
9825 // Note that this is only for ADD, not SUB. This mirrors the system
9826 // 'as' behaviour. Also take advantage of ADD being commutative.
9827 // Make sure the wide encoding wasn't explicit.
9829 auto DestReg
= Inst
.getOperand(0).getReg();
9830 bool Transform
= DestReg
== Inst
.getOperand(1).getReg();
9831 if (!Transform
&& DestReg
== Inst
.getOperand(2).getReg()) {
9836 Inst
.getOperand(5).getReg() != 0 ||
9840 TmpInst
.setOpcode(ARM::tADDhirr
);
9841 TmpInst
.addOperand(Inst
.getOperand(0));
9842 TmpInst
.addOperand(Inst
.getOperand(0));
9843 TmpInst
.addOperand(Inst
.getOperand(Swap
? 1 : 2));
9844 TmpInst
.addOperand(Inst
.getOperand(3));
9845 TmpInst
.addOperand(Inst
.getOperand(4));
9850 // If the non-SP source operand and the destination operand are not the
9851 // same, we need to use the 32-bit encoding if it's available.
9852 if (Inst
.getOperand(0).getReg() != Inst
.getOperand(2).getReg()) {
9853 Inst
.setOpcode(ARM::t2ADDrr
);
9854 Inst
.addOperand(MCOperand::createReg(0)); // cc_out
9859 // A Thumb conditional branch outside of an IT block is a tBcc.
9860 if (Inst
.getOperand(1).getImm() != ARMCC::AL
&& !inITBlock()) {
9861 Inst
.setOpcode(ARM::tBcc
);
9866 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
9867 if (Inst
.getOperand(1).getImm() != ARMCC::AL
&& !inITBlock()){
9868 Inst
.setOpcode(ARM::t2Bcc
);
9873 // If the conditional is AL or we're in an IT block, we really want t2B.
9874 if (Inst
.getOperand(1).getImm() == ARMCC::AL
|| inITBlock()) {
9875 Inst
.setOpcode(ARM::t2B
);
9880 // If the conditional is AL, we really want tB.
9881 if (Inst
.getOperand(1).getImm() == ARMCC::AL
) {
9882 Inst
.setOpcode(ARM::tB
);
9887 // If the register list contains any high registers, or if the writeback
9888 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
9889 // instead if we're in Thumb2. Otherwise, this should have generated
9890 // an error in validateInstruction().
9891 unsigned Rn
= Inst
.getOperand(0).getReg();
9892 bool hasWritebackToken
=
9893 (static_cast<ARMOperand
&>(*Operands
[3]).isToken() &&
9894 static_cast<ARMOperand
&>(*Operands
[3]).getToken() == "!");
9895 bool listContainsBase
;
9896 if (checkLowRegisterList(Inst
, 3, Rn
, 0, listContainsBase
) ||
9897 (!listContainsBase
&& !hasWritebackToken
) ||
9898 (listContainsBase
&& hasWritebackToken
)) {
9899 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
9900 assert(isThumbTwo());
9901 Inst
.setOpcode(hasWritebackToken
? ARM::t2LDMIA_UPD
: ARM::t2LDMIA
);
9902 // If we're switching to the updating version, we need to insert
9903 // the writeback tied operand.
9904 if (hasWritebackToken
)
9905 Inst
.insert(Inst
.begin(),
9906 MCOperand::createReg(Inst
.getOperand(0).getReg()));
9911 case ARM::tSTMIA_UPD
: {
9912 // If the register list contains any high registers, we need to use
9913 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
9914 // should have generated an error in validateInstruction().
9915 unsigned Rn
= Inst
.getOperand(0).getReg();
9916 bool listContainsBase
;
9917 if (checkLowRegisterList(Inst
, 4, Rn
, 0, listContainsBase
)) {
9918 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
9919 assert(isThumbTwo());
9920 Inst
.setOpcode(ARM::t2STMIA_UPD
);
9926 bool listContainsBase
;
9927 // If the register list contains any high registers, we need to use
9928 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
9929 // should have generated an error in validateInstruction().
9930 if (!checkLowRegisterList(Inst
, 2, 0, ARM::PC
, listContainsBase
))
9932 assert(isThumbTwo());
9933 Inst
.setOpcode(ARM::t2LDMIA_UPD
);
9934 // Add the base register and writeback operands.
9935 Inst
.insert(Inst
.begin(), MCOperand::createReg(ARM::SP
));
9936 Inst
.insert(Inst
.begin(), MCOperand::createReg(ARM::SP
));
9940 bool listContainsBase
;
9941 if (!checkLowRegisterList(Inst
, 2, 0, ARM::LR
, listContainsBase
))
9943 assert(isThumbTwo());
9944 Inst
.setOpcode(ARM::t2STMDB_UPD
);
9945 // Add the base register and writeback operands.
9946 Inst
.insert(Inst
.begin(), MCOperand::createReg(ARM::SP
));
9947 Inst
.insert(Inst
.begin(), MCOperand::createReg(ARM::SP
));
9951 // If we can use the 16-bit encoding and the user didn't explicitly
9952 // request the 32-bit variant, transform it here.
9953 if (isARMLowRegister(Inst
.getOperand(0).getReg()) &&
9954 (Inst
.getOperand(1).isImm() &&
9955 (unsigned)Inst
.getOperand(1).getImm() <= 255) &&
9956 Inst
.getOperand(4).getReg() == (inITBlock() ? 0 : ARM::CPSR
) &&
9957 !HasWideQualifier
) {
9958 // The operands aren't in the same order for tMOVi8...
9960 TmpInst
.setOpcode(ARM::tMOVi8
);
9961 TmpInst
.addOperand(Inst
.getOperand(0));
9962 TmpInst
.addOperand(Inst
.getOperand(4));
9963 TmpInst
.addOperand(Inst
.getOperand(1));
9964 TmpInst
.addOperand(Inst
.getOperand(2));
9965 TmpInst
.addOperand(Inst
.getOperand(3));
9972 // If we can use the 16-bit encoding and the user didn't explicitly
9973 // request the 32-bit variant, transform it here.
9974 if (isARMLowRegister(Inst
.getOperand(0).getReg()) &&
9975 isARMLowRegister(Inst
.getOperand(1).getReg()) &&
9976 Inst
.getOperand(2).getImm() == ARMCC::AL
&&
9977 Inst
.getOperand(4).getReg() == ARM::CPSR
&&
9978 !HasWideQualifier
) {
9979 // The operands aren't the same for tMOV[S]r... (no cc_out)
9981 TmpInst
.setOpcode(Inst
.getOperand(4).getReg() ? ARM::tMOVSr
: ARM::tMOVr
);
9982 TmpInst
.addOperand(Inst
.getOperand(0));
9983 TmpInst
.addOperand(Inst
.getOperand(1));
9984 TmpInst
.addOperand(Inst
.getOperand(2));
9985 TmpInst
.addOperand(Inst
.getOperand(3));
9995 // If we can use the 16-bit encoding and the user didn't explicitly
9996 // request the 32-bit variant, transform it here.
9997 if (isARMLowRegister(Inst
.getOperand(0).getReg()) &&
9998 isARMLowRegister(Inst
.getOperand(1).getReg()) &&
9999 Inst
.getOperand(2).getImm() == 0 &&
10000 !HasWideQualifier
) {
10002 switch (Inst
.getOpcode()) {
10003 default: llvm_unreachable("Illegal opcode!");
10004 case ARM::t2SXTH
: NewOpc
= ARM::tSXTH
; break;
10005 case ARM::t2SXTB
: NewOpc
= ARM::tSXTB
; break;
10006 case ARM::t2UXTH
: NewOpc
= ARM::tUXTH
; break;
10007 case ARM::t2UXTB
: NewOpc
= ARM::tUXTB
; break;
10009 // The operands aren't the same for thumb1 (no rotate operand).
10011 TmpInst
.setOpcode(NewOpc
);
10012 TmpInst
.addOperand(Inst
.getOperand(0));
10013 TmpInst
.addOperand(Inst
.getOperand(1));
10014 TmpInst
.addOperand(Inst
.getOperand(3));
10015 TmpInst
.addOperand(Inst
.getOperand(4));
10022 ARM_AM::ShiftOpc SOpc
= ARM_AM::getSORegShOp(Inst
.getOperand(2).getImm());
10023 // rrx shifts and asr/lsr of #32 is encoded as 0
10024 if (SOpc
== ARM_AM::rrx
|| SOpc
== ARM_AM::asr
|| SOpc
== ARM_AM::lsr
)
10026 if (ARM_AM::getSORegOffset(Inst
.getOperand(2).getImm()) == 0) {
10027 // Shifting by zero is accepted as a vanilla 'MOVr'
10029 TmpInst
.setOpcode(ARM::MOVr
);
10030 TmpInst
.addOperand(Inst
.getOperand(0));
10031 TmpInst
.addOperand(Inst
.getOperand(1));
10032 TmpInst
.addOperand(Inst
.getOperand(3));
10033 TmpInst
.addOperand(Inst
.getOperand(4));
10034 TmpInst
.addOperand(Inst
.getOperand(5));
10045 case ARM::ADDrsi
: {
10047 ARM_AM::ShiftOpc SOpc
= ARM_AM::getSORegShOp(Inst
.getOperand(3).getImm());
10048 if (SOpc
== ARM_AM::rrx
) return false;
10049 switch (Inst
.getOpcode()) {
10050 default: llvm_unreachable("unexpected opcode!");
10051 case ARM::ANDrsi
: newOpc
= ARM::ANDrr
; break;
10052 case ARM::ORRrsi
: newOpc
= ARM::ORRrr
; break;
10053 case ARM::EORrsi
: newOpc
= ARM::EORrr
; break;
10054 case ARM::BICrsi
: newOpc
= ARM::BICrr
; break;
10055 case ARM::SUBrsi
: newOpc
= ARM::SUBrr
; break;
10056 case ARM::ADDrsi
: newOpc
= ARM::ADDrr
; break;
10058 // If the shift is by zero, use the non-shifted instruction definition.
10059 // The exception is for right shifts, where 0 == 32
10060 if (ARM_AM::getSORegOffset(Inst
.getOperand(3).getImm()) == 0 &&
10061 !(SOpc
== ARM_AM::lsr
|| SOpc
== ARM_AM::asr
)) {
10063 TmpInst
.setOpcode(newOpc
);
10064 TmpInst
.addOperand(Inst
.getOperand(0));
10065 TmpInst
.addOperand(Inst
.getOperand(1));
10066 TmpInst
.addOperand(Inst
.getOperand(2));
10067 TmpInst
.addOperand(Inst
.getOperand(4));
10068 TmpInst
.addOperand(Inst
.getOperand(5));
10069 TmpInst
.addOperand(Inst
.getOperand(6));
10077 // Set up the IT block state according to the IT instruction we just
10079 assert(!inITBlock() && "nested IT blocks?!");
10080 startExplicitITBlock(ARMCC::CondCodes(Inst
.getOperand(0).getImm()),
10081 Inst
.getOperand(1).getImm());
10090 // Assemblers should use the narrow encodings of these instructions when permissible.
10091 if ((isARMLowRegister(Inst
.getOperand(1).getReg()) &&
10092 isARMLowRegister(Inst
.getOperand(2).getReg())) &&
10093 Inst
.getOperand(0).getReg() == Inst
.getOperand(1).getReg() &&
10094 Inst
.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR
) &&
10095 !HasWideQualifier
) {
10097 switch (Inst
.getOpcode()) {
10098 default: llvm_unreachable("unexpected opcode");
10099 case ARM::t2LSLrr
: NewOpc
= ARM::tLSLrr
; break;
10100 case ARM::t2LSRrr
: NewOpc
= ARM::tLSRrr
; break;
10101 case ARM::t2ASRrr
: NewOpc
= ARM::tASRrr
; break;
10102 case ARM::t2SBCrr
: NewOpc
= ARM::tSBC
; break;
10103 case ARM::t2RORrr
: NewOpc
= ARM::tROR
; break;
10104 case ARM::t2BICrr
: NewOpc
= ARM::tBIC
; break;
10107 TmpInst
.setOpcode(NewOpc
);
10108 TmpInst
.addOperand(Inst
.getOperand(0));
10109 TmpInst
.addOperand(Inst
.getOperand(5));
10110 TmpInst
.addOperand(Inst
.getOperand(1));
10111 TmpInst
.addOperand(Inst
.getOperand(2));
10112 TmpInst
.addOperand(Inst
.getOperand(3));
10113 TmpInst
.addOperand(Inst
.getOperand(4));
10123 // Assemblers should use the narrow encodings of these instructions when permissible.
10124 // These instructions are special in that they are commutable, so shorter encodings
10125 // are available more often.
10126 if ((isARMLowRegister(Inst
.getOperand(1).getReg()) &&
10127 isARMLowRegister(Inst
.getOperand(2).getReg())) &&
10128 (Inst
.getOperand(0).getReg() == Inst
.getOperand(1).getReg() ||
10129 Inst
.getOperand(0).getReg() == Inst
.getOperand(2).getReg()) &&
10130 Inst
.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR
) &&
10131 !HasWideQualifier
) {
10133 switch (Inst
.getOpcode()) {
10134 default: llvm_unreachable("unexpected opcode");
10135 case ARM::t2ADCrr
: NewOpc
= ARM::tADC
; break;
10136 case ARM::t2ANDrr
: NewOpc
= ARM::tAND
; break;
10137 case ARM::t2EORrr
: NewOpc
= ARM::tEOR
; break;
10138 case ARM::t2ORRrr
: NewOpc
= ARM::tORR
; break;
10141 TmpInst
.setOpcode(NewOpc
);
10142 TmpInst
.addOperand(Inst
.getOperand(0));
10143 TmpInst
.addOperand(Inst
.getOperand(5));
10144 if (Inst
.getOperand(0).getReg() == Inst
.getOperand(1).getReg()) {
10145 TmpInst
.addOperand(Inst
.getOperand(1));
10146 TmpInst
.addOperand(Inst
.getOperand(2));
10148 TmpInst
.addOperand(Inst
.getOperand(2));
10149 TmpInst
.addOperand(Inst
.getOperand(1));
10151 TmpInst
.addOperand(Inst
.getOperand(3));
10152 TmpInst
.addOperand(Inst
.getOperand(4));
10157 case ARM::MVE_VPST
:
10158 case ARM::MVE_VPTv16i8
:
10159 case ARM::MVE_VPTv8i16
:
10160 case ARM::MVE_VPTv4i32
:
10161 case ARM::MVE_VPTv16u8
:
10162 case ARM::MVE_VPTv8u16
:
10163 case ARM::MVE_VPTv4u32
:
10164 case ARM::MVE_VPTv16s8
:
10165 case ARM::MVE_VPTv8s16
:
10166 case ARM::MVE_VPTv4s32
:
10167 case ARM::MVE_VPTv4f32
:
10168 case ARM::MVE_VPTv8f16
:
10169 case ARM::MVE_VPTv16i8r
:
10170 case ARM::MVE_VPTv8i16r
:
10171 case ARM::MVE_VPTv4i32r
:
10172 case ARM::MVE_VPTv16u8r
:
10173 case ARM::MVE_VPTv8u16r
:
10174 case ARM::MVE_VPTv4u32r
:
10175 case ARM::MVE_VPTv16s8r
:
10176 case ARM::MVE_VPTv8s16r
:
10177 case ARM::MVE_VPTv4s32r
:
10178 case ARM::MVE_VPTv4f32r
:
10179 case ARM::MVE_VPTv8f16r
: {
10180 assert(!inVPTBlock() && "Nested VPT blocks are not allowed");
10181 MCOperand
&MO
= Inst
.getOperand(0);
10182 VPTState
.Mask
= MO
.getImm();
10183 VPTState
.CurPosition
= 0;
10190 unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst
&Inst
) {
10191 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
10192 // suffix depending on whether they're in an IT block or not.
10193 unsigned Opc
= Inst
.getOpcode();
10194 const MCInstrDesc
&MCID
= MII
.get(Opc
);
10195 if (MCID
.TSFlags
& ARMII::ThumbArithFlagSetting
) {
10196 assert(MCID
.hasOptionalDef() &&
10197 "optionally flag setting instruction missing optional def operand");
10198 assert(MCID
.NumOperands
== Inst
.getNumOperands() &&
10199 "operand count mismatch!");
10200 // Find the optional-def operand (cc_out).
10203 !MCID
.OpInfo
[OpNo
].isOptionalDef() && OpNo
< MCID
.NumOperands
;
10206 // If we're parsing Thumb1, reject it completely.
10207 if (isThumbOne() && Inst
.getOperand(OpNo
).getReg() != ARM::CPSR
)
10208 return Match_RequiresFlagSetting
;
10209 // If we're parsing Thumb2, which form is legal depends on whether we're
10211 if (isThumbTwo() && Inst
.getOperand(OpNo
).getReg() != ARM::CPSR
&&
10213 return Match_RequiresITBlock
;
10214 if (isThumbTwo() && Inst
.getOperand(OpNo
).getReg() == ARM::CPSR
&&
10216 return Match_RequiresNotITBlock
;
10217 // LSL with zero immediate is not allowed in an IT block
10218 if (Opc
== ARM::tLSLri
&& Inst
.getOperand(3).getImm() == 0 && inITBlock())
10219 return Match_RequiresNotITBlock
;
10220 } else if (isThumbOne()) {
10221 // Some high-register supporting Thumb1 encodings only allow both registers
10222 // to be from r0-r7 when in Thumb2.
10223 if (Opc
== ARM::tADDhirr
&& !hasV6MOps() &&
10224 isARMLowRegister(Inst
.getOperand(1).getReg()) &&
10225 isARMLowRegister(Inst
.getOperand(2).getReg()))
10226 return Match_RequiresThumb2
;
10227 // Others only require ARMv6 or later.
10228 else if (Opc
== ARM::tMOVr
&& !hasV6Ops() &&
10229 isARMLowRegister(Inst
.getOperand(0).getReg()) &&
10230 isARMLowRegister(Inst
.getOperand(1).getReg()))
10231 return Match_RequiresV6
;
10234 // Before ARMv8 the rules for when SP is allowed in t2MOVr are more complex
10235 // than the loop below can handle, so it uses the GPRnopc register class and
10236 // we do SP handling here.
10237 if (Opc
== ARM::t2MOVr
&& !hasV8Ops())
10239 // SP as both source and destination is not allowed
10240 if (Inst
.getOperand(0).getReg() == ARM::SP
&&
10241 Inst
.getOperand(1).getReg() == ARM::SP
)
10242 return Match_RequiresV8
;
10243 // When flags-setting SP as either source or destination is not allowed
10244 if (Inst
.getOperand(4).getReg() == ARM::CPSR
&&
10245 (Inst
.getOperand(0).getReg() == ARM::SP
||
10246 Inst
.getOperand(1).getReg() == ARM::SP
))
10247 return Match_RequiresV8
;
10250 switch (Inst
.getOpcode()) {
10253 case ARM::VMRS_FPCXTS
:
10254 case ARM::VMRS_FPCXTNS
:
10255 case ARM::VMSR_FPCXTS
:
10256 case ARM::VMSR_FPCXTNS
:
10257 case ARM::VMRS_FPSCR_NZCVQC
:
10258 case ARM::VMSR_FPSCR_NZCVQC
:
10260 case ARM::VMRS_VPR
:
10262 case ARM::VMSR_VPR
:
10264 // Use of SP for VMRS/VMSR is only allowed in ARM mode with the exception of
10266 if (Inst
.getOperand(0).isReg() && Inst
.getOperand(0).getReg() == ARM::SP
&&
10267 (isThumb() && !hasV8Ops()))
10268 return Match_InvalidOperand
;
10274 for (unsigned I
= 0; I
< MCID
.NumOperands
; ++I
)
10275 if (MCID
.OpInfo
[I
].RegClass
== ARM::rGPRRegClassID
) {
10276 // rGPRRegClass excludes PC, and also excluded SP before ARMv8
10277 const auto &Op
= Inst
.getOperand(I
);
10279 // This can happen in awkward cases with tied operands, e.g. a
10280 // writeback load/store with a complex addressing mode in
10281 // which there's an output operand corresponding to the
10282 // updated written-back base register: the Tablegen-generated
10283 // AsmMatcher will have written a placeholder operand to that
10284 // slot in the form of an immediate 0, because it can't
10285 // generate the register part of the complex addressing-mode
10286 // operand ahead of time.
10290 unsigned Reg
= Op
.getReg();
10291 if ((Reg
== ARM::SP
) && !hasV8Ops())
10292 return Match_RequiresV8
;
10293 else if (Reg
== ARM::PC
)
10294 return Match_InvalidOperand
;
10297 return Match_Success
;
10302 template <> inline bool IsCPSRDead
<MCInst
>(const MCInst
*Instr
) {
10303 return true; // In an assembly source, no need to second-guess
10306 } // end namespace llvm
10308 // Returns true if Inst is unpredictable if it is in and IT block, but is not
10309 // the last instruction in the block.
10310 bool ARMAsmParser::isITBlockTerminator(MCInst
&Inst
) const {
10311 const MCInstrDesc
&MCID
= MII
.get(Inst
.getOpcode());
10313 // All branch & call instructions terminate IT blocks with the exception of
10315 if (MCID
.isTerminator() || (MCID
.isCall() && Inst
.getOpcode() != ARM::tSVC
) ||
10316 MCID
.isReturn() || MCID
.isBranch() || MCID
.isIndirectBranch())
10319 // Any arithmetic instruction which writes to the PC also terminates the IT
10321 if (MCID
.hasDefOfPhysReg(Inst
, ARM::PC
, *MRI
))
10327 unsigned ARMAsmParser::MatchInstruction(OperandVector
&Operands
, MCInst
&Inst
,
10328 SmallVectorImpl
<NearMissInfo
> &NearMisses
,
10329 bool MatchingInlineAsm
,
10330 bool &EmitInITBlock
,
10332 // If we can't use an implicit IT block here, just match as normal.
10333 if (inExplicitITBlock() || !isThumbTwo() || !useImplicitITThumb())
10334 return MatchInstructionImpl(Operands
, Inst
, &NearMisses
, MatchingInlineAsm
);
10336 // Try to match the instruction in an extension of the current IT block (if
10338 if (inImplicitITBlock()) {
10339 extendImplicitITBlock(ITState
.Cond
);
10340 if (MatchInstructionImpl(Operands
, Inst
, nullptr, MatchingInlineAsm
) ==
10342 // The match succeded, but we still have to check that the instruction is
10343 // valid in this implicit IT block.
10344 const MCInstrDesc
&MCID
= MII
.get(Inst
.getOpcode());
10345 if (MCID
.isPredicable()) {
10346 ARMCC::CondCodes InstCond
=
10347 (ARMCC::CondCodes
)Inst
.getOperand(MCID
.findFirstPredOperandIdx())
10349 ARMCC::CondCodes ITCond
= currentITCond();
10350 if (InstCond
== ITCond
) {
10351 EmitInITBlock
= true;
10352 return Match_Success
;
10353 } else if (InstCond
== ARMCC::getOppositeCondition(ITCond
)) {
10354 invertCurrentITCondition();
10355 EmitInITBlock
= true;
10356 return Match_Success
;
10360 rewindImplicitITPosition();
10363 // Finish the current IT block, and try to match outside any IT block.
10364 flushPendingInstructions(Out
);
10365 unsigned PlainMatchResult
=
10366 MatchInstructionImpl(Operands
, Inst
, &NearMisses
, MatchingInlineAsm
);
10367 if (PlainMatchResult
== Match_Success
) {
10368 const MCInstrDesc
&MCID
= MII
.get(Inst
.getOpcode());
10369 if (MCID
.isPredicable()) {
10370 ARMCC::CondCodes InstCond
=
10371 (ARMCC::CondCodes
)Inst
.getOperand(MCID
.findFirstPredOperandIdx())
10373 // Some forms of the branch instruction have their own condition code
10374 // fields, so can be conditionally executed without an IT block.
10375 if (Inst
.getOpcode() == ARM::tBcc
|| Inst
.getOpcode() == ARM::t2Bcc
) {
10376 EmitInITBlock
= false;
10377 return Match_Success
;
10379 if (InstCond
== ARMCC::AL
) {
10380 EmitInITBlock
= false;
10381 return Match_Success
;
10384 EmitInITBlock
= false;
10385 return Match_Success
;
10389 // Try to match in a new IT block. The matcher doesn't check the actual
10390 // condition, so we create an IT block with a dummy condition, and fix it up
10391 // once we know the actual condition.
10392 startImplicitITBlock();
10393 if (MatchInstructionImpl(Operands
, Inst
, nullptr, MatchingInlineAsm
) ==
10395 const MCInstrDesc
&MCID
= MII
.get(Inst
.getOpcode());
10396 if (MCID
.isPredicable()) {
10398 (ARMCC::CondCodes
)Inst
.getOperand(MCID
.findFirstPredOperandIdx())
10400 EmitInITBlock
= true;
10401 return Match_Success
;
10404 discardImplicitITBlock();
10406 // If none of these succeed, return the error we got when trying to match
10407 // outside any IT blocks.
10408 EmitInITBlock
= false;
10409 return PlainMatchResult
;
10412 static std::string
ARMMnemonicSpellCheck(StringRef S
, const FeatureBitset
&FBS
,
10413 unsigned VariantID
= 0);
10415 static const char *getSubtargetFeatureName(uint64_t Val
);
10416 bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc
, unsigned &Opcode
,
10417 OperandVector
&Operands
,
10418 MCStreamer
&Out
, uint64_t &ErrorInfo
,
10419 bool MatchingInlineAsm
) {
10421 unsigned MatchResult
;
10422 bool PendConditionalInstruction
= false;
10424 SmallVector
<NearMissInfo
, 4> NearMisses
;
10425 MatchResult
= MatchInstruction(Operands
, Inst
, NearMisses
, MatchingInlineAsm
,
10426 PendConditionalInstruction
, Out
);
10428 switch (MatchResult
) {
10429 case Match_Success
:
10430 LLVM_DEBUG(dbgs() << "Parsed as: ";
10431 Inst
.dump_pretty(dbgs(), MII
.getName(Inst
.getOpcode()));
10434 // Context sensitive operand constraints aren't handled by the matcher,
10435 // so check them here.
10436 if (validateInstruction(Inst
, Operands
)) {
10437 // Still progress the IT block, otherwise one wrong condition causes
10438 // nasty cascading errors.
10439 forwardITPosition();
10440 forwardVPTPosition();
10444 { // processInstruction() updates inITBlock state, we need to save it away
10445 bool wasInITBlock
= inITBlock();
10447 // Some instructions need post-processing to, for example, tweak which
10448 // encoding is selected. Loop on it while changes happen so the
10449 // individual transformations can chain off each other. E.g.,
10450 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
10451 while (processInstruction(Inst
, Operands
, Out
))
10452 LLVM_DEBUG(dbgs() << "Changed to: ";
10453 Inst
.dump_pretty(dbgs(), MII
.getName(Inst
.getOpcode()));
10456 // Only after the instruction is fully processed, we can validate it
10457 if (wasInITBlock
&& hasV8Ops() && isThumb() &&
10458 !isV8EligibleForIT(&Inst
)) {
10459 Warning(IDLoc
, "deprecated instruction in IT block");
10463 // Only move forward at the very end so that everything in validate
10464 // and process gets a consistent answer about whether we're in an IT
10466 forwardITPosition();
10467 forwardVPTPosition();
10469 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
10470 // doesn't actually encode.
10471 if (Inst
.getOpcode() == ARM::ITasm
)
10474 Inst
.setLoc(IDLoc
);
10475 if (PendConditionalInstruction
) {
10476 PendingConditionalInsts
.push_back(Inst
);
10477 if (isITBlockFull() || isITBlockTerminator(Inst
))
10478 flushPendingInstructions(Out
);
10480 Out
.EmitInstruction(Inst
, getSTI());
10483 case Match_NearMisses
:
10484 ReportNearMisses(NearMisses
, IDLoc
, Operands
);
10486 case Match_MnemonicFail
: {
10487 FeatureBitset FBS
= ComputeAvailableFeatures(getSTI().getFeatureBits());
10488 std::string Suggestion
= ARMMnemonicSpellCheck(
10489 ((ARMOperand
&)*Operands
[0]).getToken(), FBS
);
10490 return Error(IDLoc
, "invalid instruction" + Suggestion
,
10491 ((ARMOperand
&)*Operands
[0]).getLocRange());
10495 llvm_unreachable("Implement any new match types added!");
10498 /// parseDirective parses the arm specific directives
10499 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID
) {
10500 const MCObjectFileInfo::Environment Format
=
10501 getContext().getObjectFileInfo()->getObjectFileType();
10502 bool IsMachO
= Format
== MCObjectFileInfo::IsMachO
;
10503 bool IsCOFF
= Format
== MCObjectFileInfo::IsCOFF
;
10505 StringRef IDVal
= DirectiveID
.getIdentifier();
10506 if (IDVal
== ".word")
10507 parseLiteralValues(4, DirectiveID
.getLoc());
10508 else if (IDVal
== ".short" || IDVal
== ".hword")
10509 parseLiteralValues(2, DirectiveID
.getLoc());
10510 else if (IDVal
== ".thumb")
10511 parseDirectiveThumb(DirectiveID
.getLoc());
10512 else if (IDVal
== ".arm")
10513 parseDirectiveARM(DirectiveID
.getLoc());
10514 else if (IDVal
== ".thumb_func")
10515 parseDirectiveThumbFunc(DirectiveID
.getLoc());
10516 else if (IDVal
== ".code")
10517 parseDirectiveCode(DirectiveID
.getLoc());
10518 else if (IDVal
== ".syntax")
10519 parseDirectiveSyntax(DirectiveID
.getLoc());
10520 else if (IDVal
== ".unreq")
10521 parseDirectiveUnreq(DirectiveID
.getLoc());
10522 else if (IDVal
== ".fnend")
10523 parseDirectiveFnEnd(DirectiveID
.getLoc());
10524 else if (IDVal
== ".cantunwind")
10525 parseDirectiveCantUnwind(DirectiveID
.getLoc());
10526 else if (IDVal
== ".personality")
10527 parseDirectivePersonality(DirectiveID
.getLoc());
10528 else if (IDVal
== ".handlerdata")
10529 parseDirectiveHandlerData(DirectiveID
.getLoc());
10530 else if (IDVal
== ".setfp")
10531 parseDirectiveSetFP(DirectiveID
.getLoc());
10532 else if (IDVal
== ".pad")
10533 parseDirectivePad(DirectiveID
.getLoc());
10534 else if (IDVal
== ".save")
10535 parseDirectiveRegSave(DirectiveID
.getLoc(), false);
10536 else if (IDVal
== ".vsave")
10537 parseDirectiveRegSave(DirectiveID
.getLoc(), true);
10538 else if (IDVal
== ".ltorg" || IDVal
== ".pool")
10539 parseDirectiveLtorg(DirectiveID
.getLoc());
10540 else if (IDVal
== ".even")
10541 parseDirectiveEven(DirectiveID
.getLoc());
10542 else if (IDVal
== ".personalityindex")
10543 parseDirectivePersonalityIndex(DirectiveID
.getLoc());
10544 else if (IDVal
== ".unwind_raw")
10545 parseDirectiveUnwindRaw(DirectiveID
.getLoc());
10546 else if (IDVal
== ".movsp")
10547 parseDirectiveMovSP(DirectiveID
.getLoc());
10548 else if (IDVal
== ".arch_extension")
10549 parseDirectiveArchExtension(DirectiveID
.getLoc());
10550 else if (IDVal
== ".align")
10551 return parseDirectiveAlign(DirectiveID
.getLoc()); // Use Generic on failure.
10552 else if (IDVal
== ".thumb_set")
10553 parseDirectiveThumbSet(DirectiveID
.getLoc());
10554 else if (IDVal
== ".inst")
10555 parseDirectiveInst(DirectiveID
.getLoc());
10556 else if (IDVal
== ".inst.n")
10557 parseDirectiveInst(DirectiveID
.getLoc(), 'n');
10558 else if (IDVal
== ".inst.w")
10559 parseDirectiveInst(DirectiveID
.getLoc(), 'w');
10560 else if (!IsMachO
&& !IsCOFF
) {
10561 if (IDVal
== ".arch")
10562 parseDirectiveArch(DirectiveID
.getLoc());
10563 else if (IDVal
== ".cpu")
10564 parseDirectiveCPU(DirectiveID
.getLoc());
10565 else if (IDVal
== ".eabi_attribute")
10566 parseDirectiveEabiAttr(DirectiveID
.getLoc());
10567 else if (IDVal
== ".fpu")
10568 parseDirectiveFPU(DirectiveID
.getLoc());
10569 else if (IDVal
== ".fnstart")
10570 parseDirectiveFnStart(DirectiveID
.getLoc());
10571 else if (IDVal
== ".object_arch")
10572 parseDirectiveObjectArch(DirectiveID
.getLoc());
10573 else if (IDVal
== ".tlsdescseq")
10574 parseDirectiveTLSDescSeq(DirectiveID
.getLoc());
10582 /// parseLiteralValues
10583 /// ::= .hword expression [, expression]*
10584 /// ::= .short expression [, expression]*
10585 /// ::= .word expression [, expression]*
10586 bool ARMAsmParser::parseLiteralValues(unsigned Size
, SMLoc L
) {
10587 auto parseOne
= [&]() -> bool {
10588 const MCExpr
*Value
;
10589 if (getParser().parseExpression(Value
))
10591 getParser().getStreamer().EmitValue(Value
, Size
, L
);
10594 return (parseMany(parseOne
));
10597 /// parseDirectiveThumb
10599 bool ARMAsmParser::parseDirectiveThumb(SMLoc L
) {
10600 if (parseToken(AsmToken::EndOfStatement
, "unexpected token in directive") ||
10601 check(!hasThumb(), L
, "target does not support Thumb mode"))
10607 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16
);
10611 /// parseDirectiveARM
10613 bool ARMAsmParser::parseDirectiveARM(SMLoc L
) {
10614 if (parseToken(AsmToken::EndOfStatement
, "unexpected token in directive") ||
10615 check(!hasARM(), L
, "target does not support ARM mode"))
10620 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32
);
10624 void ARMAsmParser::doBeforeLabelEmit(MCSymbol
*Symbol
) {
10625 // We need to flush the current implicit IT block on a label, because it is
10626 // not legal to branch into an IT block.
10627 flushPendingInstructions(getStreamer());
10630 void ARMAsmParser::onLabelParsed(MCSymbol
*Symbol
) {
10631 if (NextSymbolIsThumb
) {
10632 getParser().getStreamer().EmitThumbFunc(Symbol
);
10633 NextSymbolIsThumb
= false;
10637 /// parseDirectiveThumbFunc
10638 /// ::= .thumbfunc symbol_name
10639 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L
) {
10640 MCAsmParser
&Parser
= getParser();
10641 const auto Format
= getContext().getObjectFileInfo()->getObjectFileType();
10642 bool IsMachO
= Format
== MCObjectFileInfo::IsMachO
;
10644 // Darwin asm has (optionally) function name after .thumb_func direction
10648 if (Parser
.getTok().is(AsmToken::Identifier
) ||
10649 Parser
.getTok().is(AsmToken::String
)) {
10650 MCSymbol
*Func
= getParser().getContext().getOrCreateSymbol(
10651 Parser
.getTok().getIdentifier());
10652 getParser().getStreamer().EmitThumbFunc(Func
);
10654 if (parseToken(AsmToken::EndOfStatement
,
10655 "unexpected token in '.thumb_func' directive"))
10661 if (parseToken(AsmToken::EndOfStatement
,
10662 "unexpected token in '.thumb_func' directive"))
10665 NextSymbolIsThumb
= true;
10669 /// parseDirectiveSyntax
10670 /// ::= .syntax unified | divided
10671 bool ARMAsmParser::parseDirectiveSyntax(SMLoc L
) {
10672 MCAsmParser
&Parser
= getParser();
10673 const AsmToken
&Tok
= Parser
.getTok();
10674 if (Tok
.isNot(AsmToken::Identifier
)) {
10675 Error(L
, "unexpected token in .syntax directive");
10679 StringRef Mode
= Tok
.getString();
10681 if (check(Mode
== "divided" || Mode
== "DIVIDED", L
,
10682 "'.syntax divided' arm assembly not supported") ||
10683 check(Mode
!= "unified" && Mode
!= "UNIFIED", L
,
10684 "unrecognized syntax mode in .syntax directive") ||
10685 parseToken(AsmToken::EndOfStatement
, "unexpected token in directive"))
10688 // TODO tell the MC streamer the mode
10689 // getParser().getStreamer().Emit???();
10693 /// parseDirectiveCode
10694 /// ::= .code 16 | 32
10695 bool ARMAsmParser::parseDirectiveCode(SMLoc L
) {
10696 MCAsmParser
&Parser
= getParser();
10697 const AsmToken
&Tok
= Parser
.getTok();
10698 if (Tok
.isNot(AsmToken::Integer
))
10699 return Error(L
, "unexpected token in .code directive");
10700 int64_t Val
= Parser
.getTok().getIntVal();
10701 if (Val
!= 16 && Val
!= 32) {
10702 Error(L
, "invalid operand to .code directive");
10707 if (parseToken(AsmToken::EndOfStatement
, "unexpected token in directive"))
10712 return Error(L
, "target does not support Thumb mode");
10716 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16
);
10719 return Error(L
, "target does not support ARM mode");
10723 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32
);
10729 /// parseDirectiveReq
10730 /// ::= name .req registername
10731 bool ARMAsmParser::parseDirectiveReq(StringRef Name
, SMLoc L
) {
10732 MCAsmParser
&Parser
= getParser();
10733 Parser
.Lex(); // Eat the '.req' token.
10735 SMLoc SRegLoc
, ERegLoc
;
10736 if (check(ParseRegister(Reg
, SRegLoc
, ERegLoc
), SRegLoc
,
10737 "register name expected") ||
10738 parseToken(AsmToken::EndOfStatement
,
10739 "unexpected input in .req directive."))
10742 if (RegisterReqs
.insert(std::make_pair(Name
, Reg
)).first
->second
!= Reg
)
10743 return Error(SRegLoc
,
10744 "redefinition of '" + Name
+ "' does not match original.");
10749 /// parseDirectiveUneq
10750 /// ::= .unreq registername
10751 bool ARMAsmParser::parseDirectiveUnreq(SMLoc L
) {
10752 MCAsmParser
&Parser
= getParser();
10753 if (Parser
.getTok().isNot(AsmToken::Identifier
))
10754 return Error(L
, "unexpected input in .unreq directive.");
10755 RegisterReqs
.erase(Parser
.getTok().getIdentifier().lower());
10756 Parser
.Lex(); // Eat the identifier.
10757 if (parseToken(AsmToken::EndOfStatement
,
10758 "unexpected input in '.unreq' directive"))
10763 // After changing arch/CPU, try to put the ARM/Thumb mode back to what it was
10764 // before, if supported by the new target, or emit mapping symbols for the mode
10766 void ARMAsmParser::FixModeAfterArchChange(bool WasThumb
, SMLoc Loc
) {
10767 if (WasThumb
!= isThumb()) {
10768 if (WasThumb
&& hasThumb()) {
10769 // Stay in Thumb mode
10771 } else if (!WasThumb
&& hasARM()) {
10772 // Stay in ARM mode
10775 // Mode switch forced, because the new arch doesn't support the old mode.
10776 getParser().getStreamer().EmitAssemblerFlag(isThumb() ? MCAF_Code16
10778 // Warn about the implcit mode switch. GAS does not switch modes here,
10779 // but instead stays in the old mode, reporting an error on any following
10780 // instructions as the mode does not exist on the target.
10781 Warning(Loc
, Twine("new target does not support ") +
10782 (WasThumb
? "thumb" : "arm") + " mode, switching to " +
10783 (!WasThumb
? "thumb" : "arm") + " mode");
10788 /// parseDirectiveArch
10789 /// ::= .arch token
10790 bool ARMAsmParser::parseDirectiveArch(SMLoc L
) {
10791 StringRef Arch
= getParser().parseStringToEndOfStatement().trim();
10792 ARM::ArchKind ID
= ARM::parseArch(Arch
);
10794 if (ID
== ARM::ArchKind::INVALID
)
10795 return Error(L
, "Unknown arch name");
10797 bool WasThumb
= isThumb();
10799 MCSubtargetInfo
&STI
= copySTI();
10800 STI
.setDefaultFeatures("", ("+" + ARM::getArchName(ID
)).str());
10801 setAvailableFeatures(ComputeAvailableFeatures(STI
.getFeatureBits()));
10802 FixModeAfterArchChange(WasThumb
, L
);
10804 getTargetStreamer().emitArch(ID
);
10808 /// parseDirectiveEabiAttr
10809 /// ::= .eabi_attribute int, int [, "str"]
10810 /// ::= .eabi_attribute Tag_name, int [, "str"]
10811 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L
) {
10812 MCAsmParser
&Parser
= getParser();
10815 TagLoc
= Parser
.getTok().getLoc();
10816 if (Parser
.getTok().is(AsmToken::Identifier
)) {
10817 StringRef Name
= Parser
.getTok().getIdentifier();
10818 Tag
= ARMBuildAttrs::AttrTypeFromString(Name
);
10820 Error(TagLoc
, "attribute name not recognised: " + Name
);
10825 const MCExpr
*AttrExpr
;
10827 TagLoc
= Parser
.getTok().getLoc();
10828 if (Parser
.parseExpression(AttrExpr
))
10831 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(AttrExpr
);
10832 if (check(!CE
, TagLoc
, "expected numeric constant"))
10835 Tag
= CE
->getValue();
10838 if (Parser
.parseToken(AsmToken::Comma
, "comma expected"))
10841 StringRef StringValue
= "";
10842 bool IsStringValue
= false;
10844 int64_t IntegerValue
= 0;
10845 bool IsIntegerValue
= false;
10847 if (Tag
== ARMBuildAttrs::CPU_raw_name
|| Tag
== ARMBuildAttrs::CPU_name
)
10848 IsStringValue
= true;
10849 else if (Tag
== ARMBuildAttrs::compatibility
) {
10850 IsStringValue
= true;
10851 IsIntegerValue
= true;
10852 } else if (Tag
< 32 || Tag
% 2 == 0)
10853 IsIntegerValue
= true;
10854 else if (Tag
% 2 == 1)
10855 IsStringValue
= true;
10857 llvm_unreachable("invalid tag type");
10859 if (IsIntegerValue
) {
10860 const MCExpr
*ValueExpr
;
10861 SMLoc ValueExprLoc
= Parser
.getTok().getLoc();
10862 if (Parser
.parseExpression(ValueExpr
))
10865 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(ValueExpr
);
10867 return Error(ValueExprLoc
, "expected numeric constant");
10868 IntegerValue
= CE
->getValue();
10871 if (Tag
== ARMBuildAttrs::compatibility
) {
10872 if (Parser
.parseToken(AsmToken::Comma
, "comma expected"))
10876 if (IsStringValue
) {
10877 if (Parser
.getTok().isNot(AsmToken::String
))
10878 return Error(Parser
.getTok().getLoc(), "bad string constant");
10880 StringValue
= Parser
.getTok().getStringContents();
10884 if (Parser
.parseToken(AsmToken::EndOfStatement
,
10885 "unexpected token in '.eabi_attribute' directive"))
10888 if (IsIntegerValue
&& IsStringValue
) {
10889 assert(Tag
== ARMBuildAttrs::compatibility
);
10890 getTargetStreamer().emitIntTextAttribute(Tag
, IntegerValue
, StringValue
);
10891 } else if (IsIntegerValue
)
10892 getTargetStreamer().emitAttribute(Tag
, IntegerValue
);
10893 else if (IsStringValue
)
10894 getTargetStreamer().emitTextAttribute(Tag
, StringValue
);
10898 /// parseDirectiveCPU
10900 bool ARMAsmParser::parseDirectiveCPU(SMLoc L
) {
10901 StringRef CPU
= getParser().parseStringToEndOfStatement().trim();
10902 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name
, CPU
);
10904 // FIXME: This is using table-gen data, but should be moved to
10905 // ARMTargetParser once that is table-gen'd.
10906 if (!getSTI().isCPUStringValid(CPU
))
10907 return Error(L
, "Unknown CPU name");
10909 bool WasThumb
= isThumb();
10910 MCSubtargetInfo
&STI
= copySTI();
10911 STI
.setDefaultFeatures(CPU
, "");
10912 setAvailableFeatures(ComputeAvailableFeatures(STI
.getFeatureBits()));
10913 FixModeAfterArchChange(WasThumb
, L
);
10918 /// parseDirectiveFPU
10920 bool ARMAsmParser::parseDirectiveFPU(SMLoc L
) {
10921 SMLoc FPUNameLoc
= getTok().getLoc();
10922 StringRef FPU
= getParser().parseStringToEndOfStatement().trim();
10924 unsigned ID
= ARM::parseFPU(FPU
);
10925 std::vector
<StringRef
> Features
;
10926 if (!ARM::getFPUFeatures(ID
, Features
))
10927 return Error(FPUNameLoc
, "Unknown FPU name");
10929 MCSubtargetInfo
&STI
= copySTI();
10930 for (auto Feature
: Features
)
10931 STI
.ApplyFeatureFlag(Feature
);
10932 setAvailableFeatures(ComputeAvailableFeatures(STI
.getFeatureBits()));
10934 getTargetStreamer().emitFPU(ID
);
10938 /// parseDirectiveFnStart
10940 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L
) {
10941 if (parseToken(AsmToken::EndOfStatement
,
10942 "unexpected token in '.fnstart' directive"))
10945 if (UC
.hasFnStart()) {
10946 Error(L
, ".fnstart starts before the end of previous one");
10947 UC
.emitFnStartLocNotes();
10951 // Reset the unwind directives parser state
10954 getTargetStreamer().emitFnStart();
10956 UC
.recordFnStart(L
);
10960 /// parseDirectiveFnEnd
10962 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L
) {
10963 if (parseToken(AsmToken::EndOfStatement
,
10964 "unexpected token in '.fnend' directive"))
10966 // Check the ordering of unwind directives
10967 if (!UC
.hasFnStart())
10968 return Error(L
, ".fnstart must precede .fnend directive");
10970 // Reset the unwind directives parser state
10971 getTargetStreamer().emitFnEnd();
10977 /// parseDirectiveCantUnwind
10978 /// ::= .cantunwind
10979 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L
) {
10980 if (parseToken(AsmToken::EndOfStatement
,
10981 "unexpected token in '.cantunwind' directive"))
10984 UC
.recordCantUnwind(L
);
10985 // Check the ordering of unwind directives
10986 if (check(!UC
.hasFnStart(), L
, ".fnstart must precede .cantunwind directive"))
10989 if (UC
.hasHandlerData()) {
10990 Error(L
, ".cantunwind can't be used with .handlerdata directive");
10991 UC
.emitHandlerDataLocNotes();
10994 if (UC
.hasPersonality()) {
10995 Error(L
, ".cantunwind can't be used with .personality directive");
10996 UC
.emitPersonalityLocNotes();
11000 getTargetStreamer().emitCantUnwind();
11004 /// parseDirectivePersonality
11005 /// ::= .personality name
11006 bool ARMAsmParser::parseDirectivePersonality(SMLoc L
) {
11007 MCAsmParser
&Parser
= getParser();
11008 bool HasExistingPersonality
= UC
.hasPersonality();
11010 // Parse the name of the personality routine
11011 if (Parser
.getTok().isNot(AsmToken::Identifier
))
11012 return Error(L
, "unexpected input in .personality directive.");
11013 StringRef
Name(Parser
.getTok().getIdentifier());
11016 if (parseToken(AsmToken::EndOfStatement
,
11017 "unexpected token in '.personality' directive"))
11020 UC
.recordPersonality(L
);
11022 // Check the ordering of unwind directives
11023 if (!UC
.hasFnStart())
11024 return Error(L
, ".fnstart must precede .personality directive");
11025 if (UC
.cantUnwind()) {
11026 Error(L
, ".personality can't be used with .cantunwind directive");
11027 UC
.emitCantUnwindLocNotes();
11030 if (UC
.hasHandlerData()) {
11031 Error(L
, ".personality must precede .handlerdata directive");
11032 UC
.emitHandlerDataLocNotes();
11035 if (HasExistingPersonality
) {
11036 Error(L
, "multiple personality directives");
11037 UC
.emitPersonalityLocNotes();
11041 MCSymbol
*PR
= getParser().getContext().getOrCreateSymbol(Name
);
11042 getTargetStreamer().emitPersonality(PR
);
11046 /// parseDirectiveHandlerData
11047 /// ::= .handlerdata
11048 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L
) {
11049 if (parseToken(AsmToken::EndOfStatement
,
11050 "unexpected token in '.handlerdata' directive"))
11053 UC
.recordHandlerData(L
);
11054 // Check the ordering of unwind directives
11055 if (!UC
.hasFnStart())
11056 return Error(L
, ".fnstart must precede .personality directive");
11057 if (UC
.cantUnwind()) {
11058 Error(L
, ".handlerdata can't be used with .cantunwind directive");
11059 UC
.emitCantUnwindLocNotes();
11063 getTargetStreamer().emitHandlerData();
11067 /// parseDirectiveSetFP
11068 /// ::= .setfp fpreg, spreg [, offset]
11069 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L
) {
11070 MCAsmParser
&Parser
= getParser();
11071 // Check the ordering of unwind directives
11072 if (check(!UC
.hasFnStart(), L
, ".fnstart must precede .setfp directive") ||
11073 check(UC
.hasHandlerData(), L
,
11074 ".setfp must precede .handlerdata directive"))
11078 SMLoc FPRegLoc
= Parser
.getTok().getLoc();
11079 int FPReg
= tryParseRegister();
11081 if (check(FPReg
== -1, FPRegLoc
, "frame pointer register expected") ||
11082 Parser
.parseToken(AsmToken::Comma
, "comma expected"))
11086 SMLoc SPRegLoc
= Parser
.getTok().getLoc();
11087 int SPReg
= tryParseRegister();
11088 if (check(SPReg
== -1, SPRegLoc
, "stack pointer register expected") ||
11089 check(SPReg
!= ARM::SP
&& SPReg
!= UC
.getFPReg(), SPRegLoc
,
11090 "register should be either $sp or the latest fp register"))
11093 // Update the frame pointer register
11094 UC
.saveFPReg(FPReg
);
11097 int64_t Offset
= 0;
11098 if (Parser
.parseOptionalToken(AsmToken::Comma
)) {
11099 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
11100 Parser
.getTok().isNot(AsmToken::Dollar
))
11101 return Error(Parser
.getTok().getLoc(), "'#' expected");
11102 Parser
.Lex(); // skip hash token.
11104 const MCExpr
*OffsetExpr
;
11105 SMLoc ExLoc
= Parser
.getTok().getLoc();
11107 if (getParser().parseExpression(OffsetExpr
, EndLoc
))
11108 return Error(ExLoc
, "malformed setfp offset");
11109 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(OffsetExpr
);
11110 if (check(!CE
, ExLoc
, "setfp offset must be an immediate"))
11112 Offset
= CE
->getValue();
11115 if (Parser
.parseToken(AsmToken::EndOfStatement
))
11118 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg
),
11119 static_cast<unsigned>(SPReg
), Offset
);
11124 /// ::= .pad offset
11125 bool ARMAsmParser::parseDirectivePad(SMLoc L
) {
11126 MCAsmParser
&Parser
= getParser();
11127 // Check the ordering of unwind directives
11128 if (!UC
.hasFnStart())
11129 return Error(L
, ".fnstart must precede .pad directive");
11130 if (UC
.hasHandlerData())
11131 return Error(L
, ".pad must precede .handlerdata directive");
11133 // Parse the offset
11134 if (Parser
.getTok().isNot(AsmToken::Hash
) &&
11135 Parser
.getTok().isNot(AsmToken::Dollar
))
11136 return Error(Parser
.getTok().getLoc(), "'#' expected");
11137 Parser
.Lex(); // skip hash token.
11139 const MCExpr
*OffsetExpr
;
11140 SMLoc ExLoc
= Parser
.getTok().getLoc();
11142 if (getParser().parseExpression(OffsetExpr
, EndLoc
))
11143 return Error(ExLoc
, "malformed pad offset");
11144 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(OffsetExpr
);
11146 return Error(ExLoc
, "pad offset must be an immediate");
11148 if (parseToken(AsmToken::EndOfStatement
,
11149 "unexpected token in '.pad' directive"))
11152 getTargetStreamer().emitPad(CE
->getValue());
11156 /// parseDirectiveRegSave
11157 /// ::= .save { registers }
11158 /// ::= .vsave { registers }
11159 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L
, bool IsVector
) {
11160 // Check the ordering of unwind directives
11161 if (!UC
.hasFnStart())
11162 return Error(L
, ".fnstart must precede .save or .vsave directives");
11163 if (UC
.hasHandlerData())
11164 return Error(L
, ".save or .vsave must precede .handlerdata directive");
11166 // RAII object to make sure parsed operands are deleted.
11167 SmallVector
<std::unique_ptr
<MCParsedAsmOperand
>, 1> Operands
;
11169 // Parse the register list
11170 if (parseRegisterList(Operands
) ||
11171 parseToken(AsmToken::EndOfStatement
, "unexpected token in directive"))
11173 ARMOperand
&Op
= (ARMOperand
&)*Operands
[0];
11174 if (!IsVector
&& !Op
.isRegList())
11175 return Error(L
, ".save expects GPR registers");
11176 if (IsVector
&& !Op
.isDPRRegList())
11177 return Error(L
, ".vsave expects DPR registers");
11179 getTargetStreamer().emitRegSave(Op
.getRegList(), IsVector
);
11183 /// parseDirectiveInst
11184 /// ::= .inst opcode [, ...]
11185 /// ::= .inst.n opcode [, ...]
11186 /// ::= .inst.w opcode [, ...]
11187 bool ARMAsmParser::parseDirectiveInst(SMLoc Loc
, char Suffix
) {
11203 return Error(Loc
, "width suffixes are invalid in ARM mode");
11206 auto parseOne
= [&]() -> bool {
11207 const MCExpr
*Expr
;
11208 if (getParser().parseExpression(Expr
))
11210 const MCConstantExpr
*Value
= dyn_cast_or_null
<MCConstantExpr
>(Expr
);
11212 return Error(Loc
, "expected constant expression");
11215 char CurSuffix
= Suffix
;
11218 if (Value
->getValue() > 0xffff)
11219 return Error(Loc
, "inst.n operand is too big, use inst.w instead");
11222 if (Value
->getValue() > 0xffffffff)
11223 return Error(Loc
, StringRef(Suffix
? "inst.w" : "inst") +
11224 " operand is too big");
11227 // Thumb mode, no width indicated. Guess from the opcode, if possible.
11228 if (Value
->getValue() < 0xe800)
11230 else if (Value
->getValue() >= 0xe8000000)
11233 return Error(Loc
, "cannot determine Thumb instruction size, "
11234 "use inst.n/inst.w instead");
11237 llvm_unreachable("only supported widths are 2 and 4");
11240 getTargetStreamer().emitInst(Value
->getValue(), CurSuffix
);
11244 if (parseOptionalToken(AsmToken::EndOfStatement
))
11245 return Error(Loc
, "expected expression following directive");
11246 if (parseMany(parseOne
))
11251 /// parseDirectiveLtorg
11252 /// ::= .ltorg | .pool
11253 bool ARMAsmParser::parseDirectiveLtorg(SMLoc L
) {
11254 if (parseToken(AsmToken::EndOfStatement
, "unexpected token in directive"))
11256 getTargetStreamer().emitCurrentConstantPool();
11260 bool ARMAsmParser::parseDirectiveEven(SMLoc L
) {
11261 const MCSection
*Section
= getStreamer().getCurrentSectionOnly();
11263 if (parseToken(AsmToken::EndOfStatement
, "unexpected token in directive"))
11267 getStreamer().InitSections(false);
11268 Section
= getStreamer().getCurrentSectionOnly();
11271 assert(Section
&& "must have section to emit alignment");
11272 if (Section
->UseCodeAlign())
11273 getStreamer().EmitCodeAlignment(2);
11275 getStreamer().EmitValueToAlignment(2);
11280 /// parseDirectivePersonalityIndex
11281 /// ::= .personalityindex index
11282 bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L
) {
11283 MCAsmParser
&Parser
= getParser();
11284 bool HasExistingPersonality
= UC
.hasPersonality();
11286 const MCExpr
*IndexExpression
;
11287 SMLoc IndexLoc
= Parser
.getTok().getLoc();
11288 if (Parser
.parseExpression(IndexExpression
) ||
11289 parseToken(AsmToken::EndOfStatement
,
11290 "unexpected token in '.personalityindex' directive")) {
11294 UC
.recordPersonalityIndex(L
);
11296 if (!UC
.hasFnStart()) {
11297 return Error(L
, ".fnstart must precede .personalityindex directive");
11299 if (UC
.cantUnwind()) {
11300 Error(L
, ".personalityindex cannot be used with .cantunwind");
11301 UC
.emitCantUnwindLocNotes();
11304 if (UC
.hasHandlerData()) {
11305 Error(L
, ".personalityindex must precede .handlerdata directive");
11306 UC
.emitHandlerDataLocNotes();
11309 if (HasExistingPersonality
) {
11310 Error(L
, "multiple personality directives");
11311 UC
.emitPersonalityLocNotes();
11315 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(IndexExpression
);
11317 return Error(IndexLoc
, "index must be a constant number");
11318 if (CE
->getValue() < 0 || CE
->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX
)
11319 return Error(IndexLoc
,
11320 "personality routine index should be in range [0-3]");
11322 getTargetStreamer().emitPersonalityIndex(CE
->getValue());
11326 /// parseDirectiveUnwindRaw
11327 /// ::= .unwind_raw offset, opcode [, opcode...]
11328 bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L
) {
11329 MCAsmParser
&Parser
= getParser();
11330 int64_t StackOffset
;
11331 const MCExpr
*OffsetExpr
;
11332 SMLoc OffsetLoc
= getLexer().getLoc();
11334 if (!UC
.hasFnStart())
11335 return Error(L
, ".fnstart must precede .unwind_raw directives");
11336 if (getParser().parseExpression(OffsetExpr
))
11337 return Error(OffsetLoc
, "expected expression");
11339 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(OffsetExpr
);
11341 return Error(OffsetLoc
, "offset must be a constant");
11343 StackOffset
= CE
->getValue();
11345 if (Parser
.parseToken(AsmToken::Comma
, "expected comma"))
11348 SmallVector
<uint8_t, 16> Opcodes
;
11350 auto parseOne
= [&]() -> bool {
11352 SMLoc OpcodeLoc
= getLexer().getLoc();
11353 if (check(getLexer().is(AsmToken::EndOfStatement
) ||
11354 Parser
.parseExpression(OE
),
11355 OpcodeLoc
, "expected opcode expression"))
11357 const MCConstantExpr
*OC
= dyn_cast
<MCConstantExpr
>(OE
);
11359 return Error(OpcodeLoc
, "opcode value must be a constant");
11360 const int64_t Opcode
= OC
->getValue();
11361 if (Opcode
& ~0xff)
11362 return Error(OpcodeLoc
, "invalid opcode");
11363 Opcodes
.push_back(uint8_t(Opcode
));
11367 // Must have at least 1 element
11368 SMLoc OpcodeLoc
= getLexer().getLoc();
11369 if (parseOptionalToken(AsmToken::EndOfStatement
))
11370 return Error(OpcodeLoc
, "expected opcode expression");
11371 if (parseMany(parseOne
))
11374 getTargetStreamer().emitUnwindRaw(StackOffset
, Opcodes
);
11378 /// parseDirectiveTLSDescSeq
11379 /// ::= .tlsdescseq tls-variable
11380 bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L
) {
11381 MCAsmParser
&Parser
= getParser();
11383 if (getLexer().isNot(AsmToken::Identifier
))
11384 return TokError("expected variable after '.tlsdescseq' directive");
11386 const MCSymbolRefExpr
*SRE
=
11387 MCSymbolRefExpr::create(Parser
.getTok().getIdentifier(),
11388 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ
, getContext());
11391 if (parseToken(AsmToken::EndOfStatement
,
11392 "unexpected token in '.tlsdescseq' directive"))
11395 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE
);
11399 /// parseDirectiveMovSP
11400 /// ::= .movsp reg [, #offset]
11401 bool ARMAsmParser::parseDirectiveMovSP(SMLoc L
) {
11402 MCAsmParser
&Parser
= getParser();
11403 if (!UC
.hasFnStart())
11404 return Error(L
, ".fnstart must precede .movsp directives");
11405 if (UC
.getFPReg() != ARM::SP
)
11406 return Error(L
, "unexpected .movsp directive");
11408 SMLoc SPRegLoc
= Parser
.getTok().getLoc();
11409 int SPReg
= tryParseRegister();
11411 return Error(SPRegLoc
, "register expected");
11412 if (SPReg
== ARM::SP
|| SPReg
== ARM::PC
)
11413 return Error(SPRegLoc
, "sp and pc are not permitted in .movsp directive");
11415 int64_t Offset
= 0;
11416 if (Parser
.parseOptionalToken(AsmToken::Comma
)) {
11417 if (Parser
.parseToken(AsmToken::Hash
, "expected #constant"))
11420 const MCExpr
*OffsetExpr
;
11421 SMLoc OffsetLoc
= Parser
.getTok().getLoc();
11423 if (Parser
.parseExpression(OffsetExpr
))
11424 return Error(OffsetLoc
, "malformed offset expression");
11426 const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(OffsetExpr
);
11428 return Error(OffsetLoc
, "offset must be an immediate constant");
11430 Offset
= CE
->getValue();
11433 if (parseToken(AsmToken::EndOfStatement
,
11434 "unexpected token in '.movsp' directive"))
11437 getTargetStreamer().emitMovSP(SPReg
, Offset
);
11438 UC
.saveFPReg(SPReg
);
11443 /// parseDirectiveObjectArch
11444 /// ::= .object_arch name
11445 bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L
) {
11446 MCAsmParser
&Parser
= getParser();
11447 if (getLexer().isNot(AsmToken::Identifier
))
11448 return Error(getLexer().getLoc(), "unexpected token");
11450 StringRef Arch
= Parser
.getTok().getString();
11451 SMLoc ArchLoc
= Parser
.getTok().getLoc();
11454 ARM::ArchKind ID
= ARM::parseArch(Arch
);
11456 if (ID
== ARM::ArchKind::INVALID
)
11457 return Error(ArchLoc
, "unknown architecture '" + Arch
+ "'");
11458 if (parseToken(AsmToken::EndOfStatement
))
11461 getTargetStreamer().emitObjectArch(ID
);
11465 /// parseDirectiveAlign
11467 bool ARMAsmParser::parseDirectiveAlign(SMLoc L
) {
11468 // NOTE: if this is not the end of the statement, fall back to the target
11469 // agnostic handling for this directive which will correctly handle this.
11470 if (parseOptionalToken(AsmToken::EndOfStatement
)) {
11471 // '.align' is target specifically handled to mean 2**2 byte alignment.
11472 const MCSection
*Section
= getStreamer().getCurrentSectionOnly();
11473 assert(Section
&& "must have section to emit alignment");
11474 if (Section
->UseCodeAlign())
11475 getStreamer().EmitCodeAlignment(4, 0);
11477 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
11483 /// parseDirectiveThumbSet
11484 /// ::= .thumb_set name, value
11485 bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L
) {
11486 MCAsmParser
&Parser
= getParser();
11489 if (check(Parser
.parseIdentifier(Name
),
11490 "expected identifier after '.thumb_set'") ||
11491 parseToken(AsmToken::Comma
, "expected comma after name '" + Name
+ "'"))
11495 const MCExpr
*Value
;
11496 if (MCParserUtils::parseAssignmentExpression(Name
, /* allow_redef */ true,
11497 Parser
, Sym
, Value
))
11500 getTargetStreamer().emitThumbSet(Sym
, Value
);
11504 /// Force static initialization.
11505 extern "C" void LLVMInitializeARMAsmParser() {
11506 RegisterMCAsmParser
<ARMAsmParser
> X(getTheARMLETarget());
11507 RegisterMCAsmParser
<ARMAsmParser
> Y(getTheARMBETarget());
11508 RegisterMCAsmParser
<ARMAsmParser
> A(getTheThumbLETarget());
11509 RegisterMCAsmParser
<ARMAsmParser
> B(getTheThumbBETarget());
11512 #define GET_REGISTER_MATCHER
11513 #define GET_SUBTARGET_FEATURE_NAME
11514 #define GET_MATCHER_IMPLEMENTATION
11515 #define GET_MNEMONIC_SPELL_CHECKER
11516 #include "ARMGenAsmMatcher.inc"
11518 // Some diagnostics need to vary with subtarget features, so they are handled
11519 // here. For example, the DPR class has either 16 or 32 registers, depending
11520 // on the FPU available.
11522 ARMAsmParser::getCustomOperandDiag(ARMMatchResultTy MatchError
) {
11523 switch (MatchError
) {
11524 // rGPR contains sp starting with ARMv8.
11526 return hasV8Ops() ? "operand must be a register in range [r0, r14]"
11527 : "operand must be a register in range [r0, r12] or r14";
11528 // DPR contains 16 registers for some FPUs, and 32 for others.
11530 return hasD32() ? "operand must be a register in range [d0, d31]"
11531 : "operand must be a register in range [d0, d15]";
11532 case Match_DPR_RegList
:
11533 return hasD32() ? "operand must be a list of registers in range [d0, d31]"
11534 : "operand must be a list of registers in range [d0, d15]";
11536 // For all other diags, use the static string from tablegen.
11538 return getMatchKindDiag(MatchError
);
11542 // Process the list of near-misses, throwing away ones we don't want to report
11543 // to the user, and converting the rest to a source location and string that
11544 // should be reported.
11546 ARMAsmParser::FilterNearMisses(SmallVectorImpl
<NearMissInfo
> &NearMissesIn
,
11547 SmallVectorImpl
<NearMissMessage
> &NearMissesOut
,
11548 SMLoc IDLoc
, OperandVector
&Operands
) {
11549 // TODO: If operand didn't match, sub in a dummy one and run target
11550 // predicate, so that we can avoid reporting near-misses that are invalid?
11551 // TODO: Many operand types dont have SuperClasses set, so we report
11553 // TODO: Some operands are superclasses of registers (e.g.
11554 // MCK_RegShiftedImm), we don't have any way to represent that currently.
11555 // TODO: This is not all ARM-specific, can some of it be factored out?
11557 // Record some information about near-misses that we have already seen, so
11558 // that we can avoid reporting redundant ones. For example, if there are
11559 // variants of an instruction that take 8- and 16-bit immediates, we want
11560 // to only report the widest one.
11561 std::multimap
<unsigned, unsigned> OperandMissesSeen
;
11562 SmallSet
<FeatureBitset
, 4> FeatureMissesSeen
;
11563 bool ReportedTooFewOperands
= false;
11565 // Process the near-misses in reverse order, so that we see more general ones
11566 // first, and so can avoid emitting more specific ones.
11567 for (NearMissInfo
&I
: reverse(NearMissesIn
)) {
11568 switch (I
.getKind()) {
11569 case NearMissInfo::NearMissOperand
: {
11571 ((ARMOperand
&)*Operands
[I
.getOperandIndex()]).getStartLoc();
11572 const char *OperandDiag
=
11573 getCustomOperandDiag((ARMMatchResultTy
)I
.getOperandError());
11575 // If we have already emitted a message for a superclass, don't also report
11576 // the sub-class. We consider all operand classes that we don't have a
11577 // specialised diagnostic for to be equal for the propose of this check,
11578 // so that we don't report the generic error multiple times on the same
11580 unsigned DupCheckMatchClass
= OperandDiag
? I
.getOperandClass() : ~0U;
11581 auto PrevReports
= OperandMissesSeen
.equal_range(I
.getOperandIndex());
11582 if (std::any_of(PrevReports
.first
, PrevReports
.second
,
11583 [DupCheckMatchClass
](
11584 const std::pair
<unsigned, unsigned> Pair
) {
11585 if (DupCheckMatchClass
== ~0U || Pair
.second
== ~0U)
11586 return Pair
.second
== DupCheckMatchClass
;
11588 return isSubclass((MatchClassKind
)DupCheckMatchClass
,
11589 (MatchClassKind
)Pair
.second
);
11592 OperandMissesSeen
.insert(
11593 std::make_pair(I
.getOperandIndex(), DupCheckMatchClass
));
11595 NearMissMessage Message
;
11596 Message
.Loc
= OperandLoc
;
11598 Message
.Message
= OperandDiag
;
11599 } else if (I
.getOperandClass() == InvalidMatchClass
) {
11600 Message
.Message
= "too many operands for instruction";
11602 Message
.Message
= "invalid operand for instruction";
11604 dbgs() << "Missing diagnostic string for operand class "
11605 << getMatchClassName((MatchClassKind
)I
.getOperandClass())
11606 << I
.getOperandClass() << ", error " << I
.getOperandError()
11607 << ", opcode " << MII
.getName(I
.getOpcode()) << "\n");
11609 NearMissesOut
.emplace_back(Message
);
11612 case NearMissInfo::NearMissFeature
: {
11613 const FeatureBitset
&MissingFeatures
= I
.getFeatures();
11614 // Don't report the same set of features twice.
11615 if (FeatureMissesSeen
.count(MissingFeatures
))
11617 FeatureMissesSeen
.insert(MissingFeatures
);
11619 // Special case: don't report a feature set which includes arm-mode for
11620 // targets that don't have ARM mode.
11621 if (MissingFeatures
.test(Feature_IsARMBit
) && !hasARM())
11623 // Don't report any near-misses that both require switching instruction
11624 // set, and adding other subtarget features.
11625 if (isThumb() && MissingFeatures
.test(Feature_IsARMBit
) &&
11626 MissingFeatures
.count() > 1)
11628 if (!isThumb() && MissingFeatures
.test(Feature_IsThumbBit
) &&
11629 MissingFeatures
.count() > 1)
11631 if (!isThumb() && MissingFeatures
.test(Feature_IsThumb2Bit
) &&
11632 (MissingFeatures
& ~FeatureBitset({Feature_IsThumb2Bit
,
11633 Feature_IsThumbBit
})).any())
11635 if (isMClass() && MissingFeatures
.test(Feature_HasNEONBit
))
11638 NearMissMessage Message
;
11639 Message
.Loc
= IDLoc
;
11640 raw_svector_ostream
OS(Message
.Message
);
11642 OS
<< "instruction requires:";
11643 for (unsigned i
= 0, e
= MissingFeatures
.size(); i
!= e
; ++i
)
11644 if (MissingFeatures
.test(i
))
11645 OS
<< ' ' << getSubtargetFeatureName(i
);
11647 NearMissesOut
.emplace_back(Message
);
11651 case NearMissInfo::NearMissPredicate
: {
11652 NearMissMessage Message
;
11653 Message
.Loc
= IDLoc
;
11654 switch (I
.getPredicateError()) {
11655 case Match_RequiresNotITBlock
:
11656 Message
.Message
= "flag setting instruction only valid outside IT block";
11658 case Match_RequiresITBlock
:
11659 Message
.Message
= "instruction only valid inside IT block";
11661 case Match_RequiresV6
:
11662 Message
.Message
= "instruction variant requires ARMv6 or later";
11664 case Match_RequiresThumb2
:
11665 Message
.Message
= "instruction variant requires Thumb2";
11667 case Match_RequiresV8
:
11668 Message
.Message
= "instruction variant requires ARMv8 or later";
11670 case Match_RequiresFlagSetting
:
11671 Message
.Message
= "no flag-preserving variant of this instruction available";
11673 case Match_InvalidOperand
:
11674 Message
.Message
= "invalid operand for instruction";
11677 llvm_unreachable("Unhandled target predicate error");
11680 NearMissesOut
.emplace_back(Message
);
11683 case NearMissInfo::NearMissTooFewOperands
: {
11684 if (!ReportedTooFewOperands
) {
11685 SMLoc EndLoc
= ((ARMOperand
&)*Operands
.back()).getEndLoc();
11686 NearMissesOut
.emplace_back(NearMissMessage
{
11687 EndLoc
, StringRef("too few operands for instruction")});
11688 ReportedTooFewOperands
= true;
11692 case NearMissInfo::NoNearMiss
:
11693 // This should never leave the matcher.
11694 llvm_unreachable("not a near-miss");
11700 void ARMAsmParser::ReportNearMisses(SmallVectorImpl
<NearMissInfo
> &NearMisses
,
11701 SMLoc IDLoc
, OperandVector
&Operands
) {
11702 SmallVector
<NearMissMessage
, 4> Messages
;
11703 FilterNearMisses(NearMisses
, Messages
, IDLoc
, Operands
);
11705 if (Messages
.size() == 0) {
11706 // No near-misses were found, so the best we can do is "invalid
11708 Error(IDLoc
, "invalid instruction");
11709 } else if (Messages
.size() == 1) {
11710 // One near miss was found, report it as the sole error.
11711 Error(Messages
[0].Loc
, Messages
[0].Message
);
11713 // More than one near miss, so report a generic "invalid instruction"
11714 // error, followed by notes for each of the near-misses.
11715 Error(IDLoc
, "invalid instruction, any one of the following would fix this:");
11716 for (auto &M
: Messages
) {
11717 Note(M
.Loc
, M
.Message
);
11722 /// parseDirectiveArchExtension
11723 /// ::= .arch_extension [no]feature
11724 bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L
) {
11725 // FIXME: This structure should be moved inside ARMTargetParser
11726 // when we start to table-generate them, and we can use the ARM
11727 // flags below, that were generated by table-gen.
11728 static const struct {
11729 const unsigned Kind
;
11730 const FeatureBitset ArchCheck
;
11731 const FeatureBitset Features
;
11733 { ARM::AEK_CRC
, {Feature_HasV8Bit
}, {ARM::FeatureCRC
} },
11734 { ARM::AEK_CRYPTO
, {Feature_HasV8Bit
},
11735 {ARM::FeatureCrypto
, ARM::FeatureNEON
, ARM::FeatureFPARMv8
} },
11736 { ARM::AEK_FP
, {Feature_HasV8Bit
},
11737 {ARM::FeatureVFP2_D16_SP
, ARM::FeatureFPARMv8
} },
11738 { (ARM::AEK_HWDIVTHUMB
| ARM::AEK_HWDIVARM
),
11739 {Feature_HasV7Bit
, Feature_IsNotMClassBit
},
11740 {ARM::FeatureHWDivThumb
, ARM::FeatureHWDivARM
} },
11741 { ARM::AEK_MP
, {Feature_HasV7Bit
, Feature_IsNotMClassBit
},
11742 {ARM::FeatureMP
} },
11743 { ARM::AEK_SIMD
, {Feature_HasV8Bit
},
11744 {ARM::FeatureNEON
, ARM::FeatureVFP2_D16_SP
, ARM::FeatureFPARMv8
} },
11745 { ARM::AEK_SEC
, {Feature_HasV6KBit
}, {ARM::FeatureTrustZone
} },
11746 // FIXME: Only available in A-class, isel not predicated
11747 { ARM::AEK_VIRT
, {Feature_HasV7Bit
}, {ARM::FeatureVirtualization
} },
11748 { ARM::AEK_FP16
, {Feature_HasV8_2aBit
},
11749 {ARM::FeatureFPARMv8
, ARM::FeatureFullFP16
} },
11750 { ARM::AEK_RAS
, {Feature_HasV8Bit
}, {ARM::FeatureRAS
} },
11751 { ARM::AEK_LOB
, {Feature_HasV8_1MMainlineBit
}, {ARM::FeatureLOB
} },
11752 // FIXME: Unsupported extensions.
11753 { ARM::AEK_OS
, {}, {} },
11754 { ARM::AEK_IWMMXT
, {}, {} },
11755 { ARM::AEK_IWMMXT2
, {}, {} },
11756 { ARM::AEK_MAVERICK
, {}, {} },
11757 { ARM::AEK_XSCALE
, {}, {} },
11760 MCAsmParser
&Parser
= getParser();
11762 if (getLexer().isNot(AsmToken::Identifier
))
11763 return Error(getLexer().getLoc(), "expected architecture extension name");
11765 StringRef Name
= Parser
.getTok().getString();
11766 SMLoc ExtLoc
= Parser
.getTok().getLoc();
11769 if (parseToken(AsmToken::EndOfStatement
,
11770 "unexpected token in '.arch_extension' directive"))
11773 bool EnableFeature
= true;
11774 if (Name
.startswith_lower("no")) {
11775 EnableFeature
= false;
11776 Name
= Name
.substr(2);
11778 unsigned FeatureKind
= ARM::parseArchExt(Name
);
11779 if (FeatureKind
== ARM::AEK_INVALID
)
11780 return Error(ExtLoc
, "unknown architectural extension: " + Name
);
11782 for (const auto &Extension
: Extensions
) {
11783 if (Extension
.Kind
!= FeatureKind
)
11786 if (Extension
.Features
.none())
11787 return Error(ExtLoc
, "unsupported architectural extension: " + Name
);
11789 if ((getAvailableFeatures() & Extension
.ArchCheck
) != Extension
.ArchCheck
)
11790 return Error(ExtLoc
, "architectural extension '" + Name
+
11792 "allowed for the current base architecture");
11794 MCSubtargetInfo
&STI
= copySTI();
11795 if (EnableFeature
) {
11796 STI
.SetFeatureBitsTransitively(Extension
.Features
);
11798 STI
.ClearFeatureBitsTransitively(Extension
.Features
);
11800 FeatureBitset Features
= ComputeAvailableFeatures(STI
.getFeatureBits());
11801 setAvailableFeatures(Features
);
11805 return Error(ExtLoc
, "unknown architectural extension: " + Name
);
11808 // Define this matcher function after the auto-generated include so we
11809 // have the match class enum definitions.
11810 unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand
&AsmOp
,
11812 ARMOperand
&Op
= static_cast<ARMOperand
&>(AsmOp
);
11813 // If the kind is a token for a literal immediate, check if our asm
11814 // operand matches. This is for InstAliases which have a fixed-value
11815 // immediate in the syntax.
11820 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Op
.getImm()))
11821 if (CE
->getValue() == 0)
11822 return Match_Success
;
11826 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Op
.getImm()))
11827 if (CE
->getValue() == 8)
11828 return Match_Success
;
11832 if (const MCConstantExpr
*CE
= dyn_cast
<MCConstantExpr
>(Op
.getImm()))
11833 if (CE
->getValue() == 16)
11834 return Match_Success
;
11838 const MCExpr
*SOExpr
= Op
.getImm();
11840 if (!SOExpr
->evaluateAsAbsolute(Value
))
11841 return Match_Success
;
11842 assert((Value
>= std::numeric_limits
<int32_t>::min() &&
11843 Value
<= std::numeric_limits
<uint32_t>::max()) &&
11844 "expression value must be representable in 32 bits");
11848 if (hasV8Ops() && Op
.isReg() && Op
.getReg() == ARM::SP
)
11849 return Match_Success
;
11853 MRI
->getRegClass(ARM::GPRRegClassID
).contains(Op
.getReg()))
11854 return Match_Success
;
11857 return Match_InvalidOperand
;
11860 bool ARMAsmParser::isMnemonicVPTPredicable(StringRef Mnemonic
,
11861 StringRef ExtraToken
) {
11865 return Mnemonic
.startswith("vabav") || Mnemonic
.startswith("vaddv") ||
11866 Mnemonic
.startswith("vaddlv") || Mnemonic
.startswith("vminnmv") ||
11867 Mnemonic
.startswith("vminnmav") || Mnemonic
.startswith("vminv") ||
11868 Mnemonic
.startswith("vminav") || Mnemonic
.startswith("vmaxnmv") ||
11869 Mnemonic
.startswith("vmaxnmav") || Mnemonic
.startswith("vmaxv") ||
11870 Mnemonic
.startswith("vmaxav") || Mnemonic
.startswith("vmladav") ||
11871 Mnemonic
.startswith("vrmlaldavh") || Mnemonic
.startswith("vrmlalvh") ||
11872 Mnemonic
.startswith("vmlsdav") || Mnemonic
.startswith("vmlav") ||
11873 Mnemonic
.startswith("vmlaldav") || Mnemonic
.startswith("vmlalv") ||
11874 Mnemonic
.startswith("vmaxnm") || Mnemonic
.startswith("vminnm") ||
11875 Mnemonic
.startswith("vmax") || Mnemonic
.startswith("vmin") ||
11876 Mnemonic
.startswith("vshlc") || Mnemonic
.startswith("vmovlt") ||
11877 Mnemonic
.startswith("vmovlb") || Mnemonic
.startswith("vshll") ||
11878 Mnemonic
.startswith("vrshrn") || Mnemonic
.startswith("vshrn") ||
11879 Mnemonic
.startswith("vqrshrun") || Mnemonic
.startswith("vqshrun") ||
11880 Mnemonic
.startswith("vqrshrn") || Mnemonic
.startswith("vqshrn") ||
11881 Mnemonic
.startswith("vbic") || Mnemonic
.startswith("vrev64") ||
11882 Mnemonic
.startswith("vrev32") || Mnemonic
.startswith("vrev16") ||
11883 Mnemonic
.startswith("vmvn") || Mnemonic
.startswith("veor") ||
11884 Mnemonic
.startswith("vorn") || Mnemonic
.startswith("vorr") ||
11885 Mnemonic
.startswith("vand") || Mnemonic
.startswith("vmul") ||
11886 Mnemonic
.startswith("vqrdmulh") || Mnemonic
.startswith("vqdmulh") ||
11887 Mnemonic
.startswith("vsub") || Mnemonic
.startswith("vadd") ||
11888 Mnemonic
.startswith("vqsub") || Mnemonic
.startswith("vqadd") ||
11889 Mnemonic
.startswith("vabd") || Mnemonic
.startswith("vrhadd") ||
11890 Mnemonic
.startswith("vhsub") || Mnemonic
.startswith("vhadd") ||
11891 Mnemonic
.startswith("vdup") || Mnemonic
.startswith("vcls") ||
11892 Mnemonic
.startswith("vclz") || Mnemonic
.startswith("vneg") ||
11893 Mnemonic
.startswith("vabs") || Mnemonic
.startswith("vqneg") ||
11894 Mnemonic
.startswith("vqabs") ||
11895 (Mnemonic
.startswith("vrint") && Mnemonic
!= "vrintr") ||
11896 Mnemonic
.startswith("vcmla") || Mnemonic
.startswith("vfma") ||
11897 Mnemonic
.startswith("vfms") || Mnemonic
.startswith("vcadd") ||
11898 Mnemonic
.startswith("vadd") || Mnemonic
.startswith("vsub") ||
11899 Mnemonic
.startswith("vshl") || Mnemonic
.startswith("vqshl") ||
11900 Mnemonic
.startswith("vqrshl") || Mnemonic
.startswith("vrshl") ||
11901 Mnemonic
.startswith("vsri") || Mnemonic
.startswith("vsli") ||
11902 Mnemonic
.startswith("vrshr") || Mnemonic
.startswith("vshr") ||
11903 Mnemonic
.startswith("vpsel") || Mnemonic
.startswith("vcmp") ||
11904 Mnemonic
.startswith("vqdmladh") || Mnemonic
.startswith("vqrdmladh") ||
11905 Mnemonic
.startswith("vqdmlsdh") || Mnemonic
.startswith("vqrdmlsdh") ||
11906 Mnemonic
.startswith("vcmul") || Mnemonic
.startswith("vrmulh") ||
11907 Mnemonic
.startswith("vqmovn") || Mnemonic
.startswith("vqmovun") ||
11908 Mnemonic
.startswith("vmovnt") || Mnemonic
.startswith("vmovnb") ||
11909 Mnemonic
.startswith("vmaxa") || Mnemonic
.startswith("vmaxnma") ||
11910 Mnemonic
.startswith("vhcadd") || Mnemonic
.startswith("vadc") ||
11911 Mnemonic
.startswith("vsbc") || Mnemonic
.startswith("vrshr") ||
11912 Mnemonic
.startswith("vshr") || Mnemonic
.startswith("vstrb") ||
11913 Mnemonic
.startswith("vldrb") ||
11914 (Mnemonic
.startswith("vstrh") && Mnemonic
!= "vstrhi") ||
11915 (Mnemonic
.startswith("vldrh") && Mnemonic
!= "vldrhi") ||
11916 Mnemonic
.startswith("vstrw") || Mnemonic
.startswith("vldrw") ||
11917 Mnemonic
.startswith("vldrd") || Mnemonic
.startswith("vstrd") ||
11918 Mnemonic
.startswith("vqdmull") || Mnemonic
.startswith("vbrsr") ||
11919 Mnemonic
.startswith("vfmas") || Mnemonic
.startswith("vmlas") ||
11920 Mnemonic
.startswith("vmla") || Mnemonic
.startswith("vqdmlash") ||
11921 Mnemonic
.startswith("vqdmlah") || Mnemonic
.startswith("vqrdmlash") ||
11922 Mnemonic
.startswith("vqrdmlah") || Mnemonic
.startswith("viwdup") ||
11923 Mnemonic
.startswith("vdwdup") || Mnemonic
.startswith("vidup") ||
11924 Mnemonic
.startswith("vddup") || Mnemonic
.startswith("vctp") ||
11925 Mnemonic
.startswith("vpnot") || Mnemonic
.startswith("vbic") ||
11926 Mnemonic
.startswith("vrmlsldavh") || Mnemonic
.startswith("vmlsldav") ||
11927 Mnemonic
.startswith("vcvt") ||
11928 (Mnemonic
.startswith("vmov") &&
11929 !(ExtraToken
== ".f16" || ExtraToken
== ".32" ||
11930 ExtraToken
== ".16" || ExtraToken
== ".8"));